OpenCores
URL https://opencores.org/ocsvn/raptor64/raptor64/trunk

Subversion Repositories raptor64

[/] [raptor64/] [trunk/] [software/] [sample code/] [bootrom.s] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 robfinch
; ============================================================================
2
; (C) 2012 Robert Finch
3
; All Rights Reserved.
4
; robfinch<remove>@opencores.org
5
;
6
; This source file is free software: you can redistribute it and/or modify 
7
; it under the terms of the GNU Lesser General Public License as published 
8
; by the Free Software Foundation, either version 3 of the License, or     
9
; (at your option) any later version.                                      
10
;                                                                          
11
; This source file is distributed in the hope that it will be useful,      
12
; but WITHOUT ANY WARRANTY; without even the implied warranty of           
13
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
14
; GNU General Public License for more details.                             
15
;                                                                          
16
; You should have received a copy of the GNU General Public License        
17
; along with this program.  If not, see <http://www.gnu.org/licenses/>.    
18
;                                                                          
19
; ============================================================================
20
;
21
CR      EQU     0x0D            ;ASCII equates
22
LF      EQU     0x0A
23
TAB     EQU     0x09
24
CTRLC   EQU     0x03
25
CTRLH   EQU     0x08
26
CTRLS   EQU     0x13
27
CTRLX   EQU     0x18
28 10 robfinch
 
29 27 robfinch
STACKTOP        EQU             0xFFFF_FFFF_FFFE_FFF8
30
Milliseconds    EQU             0x400
31
Lastloc                 EQU             0x408
32
ScreenColor     EQU             0x414
33
CursorRow       EQU             0x416
34
CursorCol       EQU             0x418
35
KeybdEcho       EQU             0x41A
36
KeybdBuffer     EQU             0x440
37
KeybdHead       EQU             0x450
38
KeybdTail       EQU             0x451
39
TEXTSCR         EQU             0xFFFF_FFFF_FFD0_0000
40
COLORSCR        EQU             0xFFFF_FFFF_FFD1_0000
41
TEXTREG         EQU             0xFFFFFFFF_FFDA0000
42
TEXT_COLS       EQU             0x0
43
TEXT_ROWS       EQU             0x2
44
TEXT_CURPOS     EQU             0x16
45
KEYBD           EQU             0xFFFF_FFFF_FFDC_0000
46
KEYBDCLR        EQU             0xFFFF_FFFF_FFDC_0002
47
UART    EQU             0xFFFF_FFFF_FFDC_0A00
48
UART_LS         EQU     0xFFFF_FFFF_FFDC_0A01
49
PIC             EQU             0xFFFF_FFFF_FFDC_0FF0
50
PSG                     EQU             0xFFFF_FFFF_FFD5_0000
51
AC97            EQU             0xFFFF_FFFF_FFDC_1000
52
BOOT_STACK      EQU             0xFFFF_FFFF_FFFE_FFF8
53
BITMAPSCR       EQU             0x00000001_00200000
54
 
55
txempty EQU             0x40
56
rxfull  EQU             0x01
57
 
58
;       org 0x070
59
;       iret
60
;       nop
61
;       nop
62
;       nop
63
;       nop
64
;       nop
65
;       nop
66
;       nop
67
;
68
        code
69
        org 0xFFFF_FFFF_FFFF_E800
70
 
71
; jump table
72
;
73
        jmp             SerialGetChar
74
        jmp             SerialPutChar
75
        jmp             SetKeyboardEcho
76
        jmp             KeybdCheckForKey
77
        jmp             KeybdGetChar
78
        jmp             DisplayChar
79
        jmp             DisplayString
80
 
81 10 robfinch
start:
82 27 robfinch
;       lea             MSGRAM,a1
83
;       jsr             DisplayString
84
 
85
ColdStart:
86
        icache_on                               ; turn on the ICache
87
        dcache_on                               ; turn on the DCache
88
        setlo   sp,#STACKTOP    ; top of stack
89
        call    KeybdInit
90
        call    PICInit
91
        cli                                             ; enable interrupts
92
        setlo   r3,#0xCE                ; blue on blue
93
        sc              r3,ScreenColor
94
        lc              r3,0x414
95
        setlo   r3,#32
96
        sc              r3,0x416                ; we do a store, then a load through the dcache
97
        lc              r2,0x416                ;
98
        lc              r2,0x416                ;
99
        beq             r2,r3,dcokay
100
        dcache_off                              ; data cache failed
101
dcokay:
102
        lc              r3,ScreenColor
103
        call    ClearScreen
104
        call    ClearBmpScreen
105
        sc              r0,CursorRow
106
        sc              r0,CursorCol
107
        setlo   r1,#<MSGSTART
108
        sethi   r1,#>MSGSTART
109
        call    DisplayString
110
;       call    SetupAC97               ; and Beep
111
 
112
; Allow some other contexts to start up
113
; equal processing time for sixteen contexts
114
;
115
        mfspr   r1,AXC                  ; which context am I
116
        bne             r1,r0,j4
117
        setlo   r1,#0x76543210
118
        mtspr   EP0,r1
119
        mtspr   EP2,r1
120
        setlo   r1,#0xFEDCBA98
121
        mtspr   EP1,r1
122
        mtspr   EP3,r1
123
j4:
124
        jmp             Monitor
125
        bra             j4
126
 
127
;       call    ramtest
128
 
129
;-----------------------------------------
130
; Hello World!
131
;-----------------------------------------
132
HelloWorld:
133
        subui   r30,r30,#24
134
        sm              [r30],r1/r2/r31
135
        setlo   r2,#MSG
136
j3:
137
        lb              r1,[r2]
138
        beq             r1,r0,j2
139
        call    SerialPutChar
140
        addui   r2,r2,#1
141
        bra             j3
142
j2:
143
        lm              [r30],r1/r2/r31
144
        ret             #24
145
 
146
 
147
        align   16
148
MSG:
149
        DB      "Hello World!",0,0,0,0
150
        align   16
151
MSGSTART:
152
        db      "Raptor64 system starting....",CR,LF,0,0
153
 
154
        align 16
155
 
156
;----------------------------------------------------------
157
; Initialize programmable interrupt controller (PIC)
158
;  0 = nmi
159
;  1 = keyboard reset
160
;  2 = 1000Hz pulse (cursor flash)
161
; 15 = keyboard char
162
;----------------------------------------------------------
163
PICInit:
164
        setlo   r1,#0x8007      ; enable nmi,kbd_rst,and kbd_irq
165
        outc    r1,PIC+2
166
        ret
167
 
168
;-----------------------------------------
169
; Get character from serial port
170
;-----------------------------------------
171
SerialGetChar:
172
        subui   r30,r30,#8
173
        sw              r3,[r30]
174
        setlo   r1,#UART
175
sgc1:
176
        inb             r3,1[r1]                ; uart status
177
        andi    r3,r3,#rxfull   ; is there a char available ?
178
        beq             r3,r0,sgc1
179
        lw              r3,[r30]
180
        inb             r1,[r1]
181
        ret             #8
182
 
183
;-----------------------------------------
184
; Put character to serial port
185
;-----------------------------------------
186
SerialPutChar:
187
        subui   r30,r30,#16
188
        sw              r2,8[r30]
189
        sw              r3,[r30]
190
        setlo   r3,#UART
191
spc1:
192
        inb             r2,1[r3]                ; uart status
193
        andi    r2,r2,#txempty  ; is there a char available ?
194
        beq             r2,r0,spc1
195
        outb    r1,[r3]
196
        lw              r3,[r30]
197
        lw              r2,8[r30]
198
        ret             #16
199
 
200
;==============================================================================
201
; Keyboard
202
;==============================================================================
203
;------------------------------------------------------------------------------
204
; Initialize keyboard
205
;------------------------------------------------------------------------------
206
KeybdInit:
207
        sb              r0,KeybdHead
208
        sb              r0,KeybdTail
209
        setlo   r1,#1                   ; turn on keyboard echo
210
        sb              r1,KeybdEcho
211
        ret
212
 
213
;------------------------------------------------------------------------------
214
; Normal keyboard interrupt, the lowest priority interrupt in the system.
215
; Grab the character from the keyboard device and store it in a buffer.
216
;------------------------------------------------------------------------------
217
;
218
KeybdIRQ:
219
        subui   sp,sp,#24
220
        sm              [sp],r1/r2/r3
221
        lbu             r1,KeybdHead
222
        andi    r1,r1,#0x0f                             ; r1 = index into buffer
223
        setlo   r3,#<KeybdBuffer
224
        sethi   r3,#>KeybdBuffer
225
KeybdIRQa:
226
        inch    r2,KEYBD                                ; get keyboard character
227
        outc    r0,KEYBD+2                              ; clear keyboard strobe (turns off the IRQ)
228
        sb              r2,[r3+r1]                              ; store character in buffer
229
        addui   r1,r1,#1                                ; increment head index
230
        andi    r1,r1,#0x0f
231
        sb              r1,KeybdHead
232
KeybdIRQb:
233
        lbu             r2,KeybdTail                    ; check to see if we've collided
234
        bne             r1,r2,KeybdIRQc                 ; with the tail
235
        addui   r2,r2,#1                                ; if so, increment the tail index
236
        andi    r2,r2,#0x0f                             ; the oldest character will be lost
237
        sb              r2,KeybdTail
238
KeybdIRQc:
239
        lm              [sp],r1/r2/r3
240
        addui   sp,sp,#24
241
        ret
242
 
243
;------------------------------------------------------------------------------
244
; r1 0=echo off, non-zero = echo on
245
;------------------------------------------------------------------------------
246
SetKeyboardEcho:
247
        sb              r1,KeybdEcho
248
        ret
249
 
250
;-----------------------------------------
251
; Get character from keyboard buffer
252
;-----------------------------------------
253
KeybdGetChar:
254
        subui   sp,sp,#16
255
        sm              [sp],r2/r3
256
        lbu             r2,KeybdTail
257
        lbu             r1,KeybdHead
258
        beq             r1,r2,nochar
259
        setlo   r3,#KeybdBuffer
260
        lbu             r1,[r3+r2]
261
        addui   r2,r2,#1
262
        andi    r2,r2,#0x0f
263
        sb              r2,KeybdTail
264
        lm              [sp],r2/r3
265
        ret             #16
266
nochar:
267
        setlo   r1,#-1
268
        lm              [sp],r2/r3
269
        ret             #16
270
 
271
;------------------------------------------------------------------------------
272
; Check if there is a keyboard character available in the keyboard buffer.
273
;------------------------------------------------------------------------------
274
;
275
KeybdCheckForKey:
276
        lbu             r1,KeybdTail
277
        lbu             r2,KeybdHead
278
        beq             r1,r2,kck1
279
        setlo   r1,#1
280
        ret
281
kck1:
282
        xor             r1,r1,r1                ; return zero
283
        ret
284
 
285
;------------------------------------------------------------------------------
286
; Check if there is a keyboard character available. If so return true (1)
287
; otherwise return false (0) in r1.
288
;------------------------------------------------------------------------------
289
;
290
KeybdCheckForKeyDirect:
291
        inch    r1,KEYBD
292
        bge             r1,r0,cfkd1
293
        setlo   r1,#1
294
        ret
295
cfkd1:
296
        xor             r1,r1,r1        ; return 0 in r1
297
        ret
298
 
299
;------------------------------------------------------------------------------
300
; Get character directly from keyboard. This routine blocks until a key is
301
; available.
302
;------------------------------------------------------------------------------
303
;
304
KeybdGetCharDirect:
305
        subui   sp,sp,#16
306
        sm              [sp],r2/r31
307
        setlo   r2,KEYBD
308
kgc1:
309
        inch    r1,KEYBD
310
        bge             r1,r0,kgc1
311
        outc    r0,KEYBD+2              ; clear keyboard strobe
312
        andi    r1,r1,#0xff             ; remove strobe bit
313
        lb              r2,KeybdEcho    ; is keyboard echo on ?
314
        beq             r2,r0,gk1
315
        bnei    r1,#'\r',gk2    ; convert CR keystroke into CRLF
316
        call    CRLF
317
        bra             gk1
318
gk2:
319
        call    DisplayChar
320
gk1:
321
        lm              [sp],r2/r31
322
        ret             #16
323
 
324
;==============================================================================
325
;==============================================================================
326
;------------------------------------------------------------------------------
327
; 1000 Hz interrupt
328
; - takes care of "flashing" the cursor
329
;------------------------------------------------------------------------------
330
;
331
Pulse1000:
332
        subui   sp,sp,#24
333
        sm              [sp],r1/r2/lr
334
        lw              r1,Milliseconds
335
        addui   r1,r1,#1
336
        sw              r1,Milliseconds
337
        setlo   r2,TEXTSCR
338
        lc              r1,222[r2]
339
        addui   r1,r1,#1
340
        sc              r1,222[r2]
341
        lc              r0,0xFFFF_FFFF_FFFF_0000        ; clear interrupt
342
        lw              r1,Milliseconds
343
        andi    r1,r1,#0x7f
344
        bnei    r1,#64,p10001
345
        call    FlashCursor
346
p10001:
347
        lm              [sp],r1/r2/lr
348
        ret             #24
349
 
350
;------------------------------------------------------------------------------
351
; Flash Cursor
352
;------------------------------------------------------------------------------
353
;
354
FlashCursor:
355
        subui   sp,sp,#32
356
        sm              [sp],r1/r2/r3/r31
357
        call    CalcScreenLoc
358
        addui   r1,r1,#0x10000
359
        ; causes screen colors to flip around
360
        lc              r2,[r1]
361
        addui   r2,r2,#1
362 10 robfinch
        sc              r2,[r1]
363 27 robfinch
        lw              r2,Lastloc
364
        beq             r1,r2,flshcrsr1
365
        ; restore the screen colors of the previous cursor location
366
        lc              r3,ScreenColor
367
        sc              r3,[r2]
368
        sw              r1,Lastloc
369
flshcrsr1:
370
        lm              [sp],r1/r2/r3/r31
371
        ret             #32
372
 
373
;------------------------------------------------------------------------------
374
;------------------------------------------------------------------------------
375
ClearBmpScreen:
376
        subui   sp,sp,#40
377
        sm              [sp],r1/r2/r3/r4/r31
378
        setlo   r1,#1364                        ; calc number to clear
379
        setlo   r2,#768
380
        mulu    r2,r1,r2                        ; r2 = # pixels to clear
381
        or              r4,r0,r2                        ; r4 = # pixels to clear
382
        setlo   r1,#0x29292929          ;
383
        setlo   r3,#<BITMAPSCR          ; screen address
384
        sethi   r3,#>BITMAPSCR
385
csj4:
386
        sh              r1,[r3]
387
        addui   r3,r3,#4
388
        loop    r2,csj4
389
        lm              [sp],r1/r2/r3/r4/r31
390
        ret             #40
391
 
392
;------------------------------------------------------------------------------
393
; Clear the screen and the screen color memory
394
; We clear the screen to give a visual indication that the system
395
; is working at all.
396
;------------------------------------------------------------------------------
397
;
398
ClearScreen:
399
        subui   sp,sp,#40
400
        sm              [sp],r1/r2/r3/r4/r31
401
        setlo   r3,#TEXTREG
402
        lc              r1,TEXT_COLS[r3]        ; calc number to clear
403
        lc              r2,TEXT_ROWS[r3]
404
        mulu    r2,r1,r2                        ; r2 = # chars to clear
405
        setlo   r1,#32                  ; space char
406
        lc              r4,ScreenColor
407
        call    AsciiToScreen
408
        setlo   r3,#TEXTSCR             ; text screen address
409
csj4:
410
        sc              r1,[r3]
411
        sc              r4,0x10000[r3]  ; color screen is 0x10000 higher
412
        addu    r3,r3,#2
413
        loop    r2,csj4
414
        lm              [sp],r1/r2/r3/r4/r31
415
        ret             #40
416
 
417
;------------------------------------------------------------------------------
418
; Scroll text on the screen upwards
419
;------------------------------------------------------------------------------
420
;
421
ScrollUp:
422
        subui   sp,sp,#40
423
        sm              [sp],r1/r2/r3/r4/r31
424
        setlo   r3,#TEXTREG
425
        lc              r1,TEXT_COLS[r3]        ; r1 = # text columns
426
        lc              r2,TEXT_ROWS[r3]
427
        mulu    r2,r1,r2                        ; calc number of chars to scroll
428
        subu    r2,r2,r1                        ; one less row
429
        setlo   r3,#TEXTSCR
430
scrup1:
431
        lc              r4,[r3+r1]                      ; indexed addressing example
432
        sc              r4,[r3]
433
        addui   r3,r3,#2
434
        loop    r2,scrup1
435
 
436
        setlo   r3,#TEXTREG
437
        lc              r1,TEXT_ROWS[r3]
438
        subui   r1,r1,#1
439
        call    BlankLine
440
        lm              [sp],r1/r2/r3/r4/r31
441
        ret             #40
442
 
443
;------------------------------------------------------------------------------
444
; Blank out a line on the display
445
; line number to blank is in r1
446
;------------------------------------------------------------------------------
447
;
448
BlankLine:
449
        subui   sp,sp,#24
450
        sm              [sp],r1/r2/r3
451
        setlo   r3,TEXTREG                      ; r3 = text register address
452
        lc              r2,TEXT_COLS[r3]        ; r2 = # chars to blank out
453
        mulu    r3,r2,r1
454
        shli    r3,r3,#1
455
        addui   r3,r3,#TEXTSCR          ; r3 = screen address
456
        setlo   r1,#' '
457
blnkln1:
458
        sc              r1,[r3]
459
        addui   r3,r3,#2
460
        loop    r2,blnkln1
461
        lm              [sp],r1/r2/r3
462
        ret             #24
463
 
464
;------------------------------------------------------------------------------
465
; Convert ASCII character to screen display character.
466
;------------------------------------------------------------------------------
467
;
468
AsciiToScreen:
469
        andi    r1,r1,#0x00ff
470
        bltui   r1,#'A',atoscr1
471
        bleui   r1,#'Z',atoscr1
472
        bgtui   r1,#'z',atoscr1
473
        bltui   r1,#'a',atoscr1
474
        subi    r1,r1,#0x60
475
atoscr1:
476
        ori             r1,r1,#0x100
477
        ret
478
 
479
;------------------------------------------------------------------------------
480
; Convert screen character to ascii character
481
;------------------------------------------------------------------------------
482
;
483
ScreenToAscii:
484
        andi    r1,r1,#0xff
485
        bgtui   r1,#26,stasc1
486
        addui   r1,r1,#60
487
stasc1:
488
        ret
489
 
490
;------------------------------------------------------------------------------
491
; Calculate screen memory location from CursorRow,CursorCol.
492
; Also refreshes the cursor location.
493
; Destroys r1,r2,r3
494
; r1 = screen location
495
;------------------------------------------------------------------------------
496
;
497
CalcScreenLoc:
498
        lc              r1,CursorRow
499
        andi    r1,r1,#0x7f
500
        setlo   r3,TEXTREG
501
        inch    r2,TEXT_COLS[r3]
502
        mulu    r2,r2,r1
503
        lc              r1,CursorCol
504
        andi    r1,r1,#0x7f
505
        addu    r2,r2,r1
506
        outc    r2,TEXT_CURPOS[r3]
507
        shli    r2,r2,#1
508
        addui   r1,r2,#TEXTSCR                  ; r1 = screen location
509
        ret
510
 
511
;------------------------------------------------------------------------------
512
; Display a character on the screen
513
; d1.b = char to display
514
;------------------------------------------------------------------------------
515
;
516
DisplayChar:
517
        bnei    r1,#'\r',dccr           ; carriage return ?
518
        subui   sp,sp,#32
519
        sm              [sp],r1/r2/r3/lr
520
        sc              r0,CursorCol            ; just set cursor column to zero on a CR
521
        bra             dcx7
522
dccr:
523
        bnei    r1,#0x91,dcx6           ; cursor right ?
524
        subui   sp,sp,#32
525
        sm              [sp],r1/r2/r3/lr
526
        lc              r2,CursorCol
527
        beqi    r2,#56,dcx7
528
        addui   r2,r2,#1
529
        sc              r2,CursorCol
530
dcx7:
531
        call    CalcScreenLoc
532
        lm              [sp],r1/r2/r3/lr
533
        ret             #32
534
dcx6:
535
        bnei    r1,#0x90,dcx8           ; cursor up ?
536
        subui   sp,sp,#32
537
        sm              [sp],r1/r2/r3/lr
538
        lc              r2,CursorRow
539
        beqi    r2,#0,dcx7
540
        subui   r2,r2,#1
541
        sc              r2,CursorRow
542
        bra             dcx7
543
dcx8:
544
        bnei    r1,#0x93,dcx9           ; cursor left ?
545
        subui   sp,sp,#32
546
        sm              [sp],r1/r2/r3/lr
547
        lc              r2,CursorCol
548
        beqi    r2,#0,dcx7
549
        subui   r2,r2,#1
550
        sc              r2,CursorCol
551
        bra             dcx7
552
dcx9:
553
        bnei    r1,#0x92,dcx10          ; cursor down ?
554
        subui   sp,sp,#32
555
        sm              [sp],r1/r2/r3/lr
556
        lc              r2,CursorRow
557
        beqi    r2,#30,dcx7
558
        addui   r2,r2,#1
559
        sc              r2,CursorRow
560
        bra             dcx7
561
dcx10:
562
        bnei    r1,#0x94,dcx11                  ; cursor home ?
563
        subui   sp,sp,#32
564
        sm              [sp],r1/r2/r3/lr
565
        lc              r2,CursorCol
566
        beq             r2,r0,dcx12
567
        sc              r0,CursorCol
568
        bra             dcx7
569
dcx12:
570
        sc              r0,CursorRow
571
        bra             dcx7
572
dcx11:
573
        subui   sp,sp,#48
574
        sm              [sp],r1/r2/r3/r4/r5/r31
575
        bnei    r1,#0x99,dcx13          ; delete ?
576
        call    CalcScreenLoc
577
        or              r3,r0,r1                        ; r3 = screen location
578
        lc              r1,CursorCol            ; r1 = cursor column
579
        bra             dcx5
580
dcx13:
581
        bnei    r1,#CTRLH,dcx3          ; backspace ?
582
        lc              r2,CursorCol
583
        beq             r2,r0,dcx4
584
        subui   r2,r2,#1
585
        sc              r2,CursorCol
586
        call    CalcScreenLoc           ; a0 = screen location
587
        or              r3,r0,r1                        ; r3 = screen location
588
        lc              r1,CursorCol
589
dcx5:
590
        lc              r2,2[r3]
591
        sc              r2,[r3]
592
        addui   r3,r3,#2
593
        addui   r1,r1,#1
594
        setlo   r4,#TEXTREG
595
        inch    r5,TEXT_COLS[r4]
596
        bltu    r1,r5,dcx5
597
        setlo   r2,#' '
598
        sc              r2,-2[r3]
599
        bra             dcx4
600
dcx3:
601
        beqi    r1,#'\n',dclf   ; linefeed ?
602
        or              r4,r0,r1                ; save r1 in r4
603
        call    CalcScreenLoc   ; r1 = screen location
604
        or              r3,r0,r1                ; r3 = screen location
605
        or              r1,r0,r4                ; restore r1
606
        call    AsciiToScreen   ; convert ascii char to screen char
607
        sc              r1,[r3]
608
        call    IncCursorPos
609
        lm              [sp],r1/r2/r3/r4/r5/r31
610
        ret             #48
611
dclf:
612
        call    IncCursorRow
613
dcx4:
614
        lm              [sp],r1/r2/r3/r4/r5/r31
615
        ret             #48
616
 
617
 
618
;------------------------------------------------------------------------------
619
; Increment the cursor position, scroll the screen if needed.
620
;------------------------------------------------------------------------------
621
;
622
IncCursorPos:
623
        subui   sp,sp,#32
624
        sm              [r30],r1/r2/r3/r31
625
        lc              r1,CursorCol
626
        addui   r1,r1,#1
627
        sc              r1,CursorCol
628
        inch    r2,TEXTREG+TEXT_COLS
629
        bleu    r1,r2,icc1
630
        sc              r0,CursorCol            ; column = 0
631
        bra             icr1
632
IncCursorRow:
633
        subui   sp,sp,#32
634
        sm              [sp],r1/r2/r3/r31
635
icr1:
636
        lc              r1,CursorRow
637
        addui   r1,r1,#1
638
        sc              r1,CursorRow
639
        inch    r2,TEXTREG+TEXT_ROWS
640
        bleu    r1,r2,icc1
641
        subui   r2,r2,#1                        ; backup the cursor row, we are scrolling up
642
        sc              r2,CursorRow
643
        call    ScrollUp
644
icc1:
645
        call    CalcScreenLoc
646
        lm              [sp],r1/r2/r3/r31
647
        ret             #32
648
 
649
;------------------------------------------------------------------------------
650
; Display a string on the screen.
651
;------------------------------------------------------------------------------
652
;
653
DisplayString:
654
        subi    sp,sp,#24
655
        sm              [sp],r1/r2/r31
656
        or              r2,r1,r0                ; r2 = pointer to string
657
dspj1:
658
        lbu             r1,[r2]                 ; move string char into r1
659
        addui   r2,r2,#1                ; increment pointer
660
        beq             r1,r0,dsret             ; is it end of string ?
661
        call    DisplayChar             ; display character
662
        bra             dspj1                   ; go back for next character
663
dsret:
664
        lm              [r30],r1/r2/r31
665
        ret             #24
666
 
667
DisplayStringCRLF:
668
        subui   r30,r30,#8
669
        sw              r31,[r30]
670
        call    DisplayString
671
        lw              r31,[r30]
672
        addui   r30,r30,#8
673
 
674
CRLF:
675
        subui   r30,r30,#16
676
        sw              r1,[r30]
677
        sw              r31,8[r30]
678
        setlo   r1,#'\r'
679
        call    DisplayChar
680
        setlo   r1,#'\n'
681
        call    DisplayChar
682
        lw              r1,[r30]
683
        lw              r31,8[r30]
684
        ret             #16
685
 
686
;------------------------------------------------------------------------------
687
; Display nybble in r1
688
;------------------------------------------------------------------------------
689
;
690
DisplayNybble:
691
        subui   r30,r30,#16
692
        sw              r31,8[r30]
693
        sw              r1,[r30]
694
        andi    r1,r1,#0x0F
695
        addui   r1,r1,#'0'
696
        bleui   r1,#'9',dispnyb1
697
        addui   r1,r1,#7
698
dispnyb1:
699
        call    DisplayChar
700
        lw              r1,[r30]
701
        lw              r31,8[r30]
702
        ret             #16
703
 
704
;------------------------------------------------------------------------------
705
; Display the byte in r1
706
;------------------------------------------------------------------------------
707
;
708
DisplayByte:
709
        subui   sp,sp,#16
710
        sm              [sp],r1/r31
711
        rori    r1,r1,#4
712
        call    DisplayNybble
713
        roli    r1,r1,#4
714
        call    DisplayNybble
715
        lm              [sp],r1/r31
716
        ret             #16
717
 
718
;------------------------------------------------------------------------------
719
; Display the 64 bit word in r1
720
;------------------------------------------------------------------------------
721
;
722
DisplayWord:
723
        subui   sp,sp,#24
724
        sm              [sp],r1/r3/r31
725
        setlo   r3,#7
726
dspwd1:
727
        roli    r1,r1,#8
728
        call    DisplayByte
729
        loop    r3,dspwd1
730
        lm              [sp],r1/r3/r31
731
        ret             #24
732
 
733
;------------------------------------------------------------------------------
734
; Display memory pointed to by r2.
735
; destroys r1,r3
736
;------------------------------------------------------------------------------
737
;
738
DisplayMem:
739
        subui   sp,sp,#8
740
        sw              lr,[sp]
741
        setlo   r1,#':'
742
        call    DisplayChar
743
        or              r1,r2,r0
744
        call    DisplayWord
745
        setlo   r3,#7
746
dspmem1:
747
        setlo   r1,#' '
748
        call    DisplayChar
749
        lb              r1,[r2]
750
        call    DisplayByte
751
        addui   r2,r2,#1
752
        loop    r3,dspmem1
753
        call    CRLF
754
        lw              lr,[sp]
755
        ret             #8
756
 
757
;------------------------------------------------------------------------------
758
; Converts binary number in r1 into BCD number in r2 and r1.
759
;------------------------------------------------------------------------------
760
;
761
BinToBCD:
762
        subui   sp,sp,#48
763
        sm              [sp],r3/r4/r5/r6/r7/r8
764
        setlo   r2,#10
765
        setlo   r8,#19          ; number of digits to produce - 1
766
bta1:
767
        mod             r3,r1,r2
768
        shli    r3,r3,#60       ; shift result to uppermost bits
769
        shli    r7,r5,#60       ; copy low order nybble of r5 to r4 topmost nybble
770
        shrui   r4,r4,#4
771
        or              r4,r4,r7
772
        shrui   r5,r5,#4
773
        or              r5,r5,r3        ; copy new bcd digit into uppermost bits of r5
774
        divui   r1,r1,r2        ; r1=r1/10
775
        loop    r8,bta1
776
        shrui   r4,r4,#48       ; right align number in register
777
        shli    r6,r5,#16
778
        or              r4,r4,r6        ; copy bits into r4
779
        shrui   r5,r5,#48
780
        or              r1,r0,r4
781
        or              r2,r0,r5
782
        lm              [sp],r3/r4/r5/r6/r7/r8
783
        ret             #48
784
 
785
;------------------------------------------------------------------------------
786
; Converts BCD number in r1 into Ascii number in r2 and r1.
787
;------------------------------------------------------------------------------
788
;
789
BCDToAscii:
790
        subui   sp,sp,#32
791
        sm              [sp],r3/r4/r5/r8
792
        setlo   r8,#15
793
bta2:
794
        andi    r2,r1,#0x0F
795
        ori             r2,r2,#0x30
796
        shli    r2,r2,#56
797
        shrui   r4,r4,#8
798
        shli    r5,r3,#56
799
        or              r4,r4,r5
800
        shrui   r3,r3,#8
801
        or              r3,r3,r2
802
        shrui   r1,r1,#4
803
        loop    r8,bta2
804
        or              r1,r0,r4
805
        or              r2,r0,r3
806
        lm              [sp],r3/r4/r5/r8
807
        ret             #32
808
 
809
;------------------------------------------------------------------------------
810
; Convert a binary number into a 20 character ascii string.
811
; r1 = number to convert
812
; r2 = address of string buffer
813
;------------------------------------------------------------------------------
814
;
815
BinToStr:
816
        subui   sp,sp,#56
817
        sm              [sp],r3/r7/r8/r9/r10/r11/r31
818
        or              r11,r0,r2
819
        call    BinToBCD
820
        or              r10,r0,r2       ; save off r2
821
        call    BCDToAscii
822
        setlo   r9,#1
823
btos3:
824
        setlo   r8,#7
825
btos1:
826
        shli    r7,r9,#3
827
        addui   r7,r7,r8
828
        addui   r7,r7,#4
829
        andi    r3,r1,#0xff
830
        sb              r3,[r7+r11]
831
        shrui   r1,r1,#8
832
        loop    r8,btos1
833
        or              r1,r0,r2
834
        loop    r9,btos3
835
; the last four digits
836
        or              r1,r0,r10       ; get back r2
837
        call    BCDToAscii
838
        setlo   r8,#3
839
btos2:
840
        andi    r3,r1,#0xff
841
        sb              r3,[r8+r11]
842
        shrui   r1,r1,#8
843
        loop    r8,btos2
844
        sb              r0,20[r11]      ; null terminate
845
        lm              [sp],r3/r7/r8/r9/r10/r11/r31
846
        ret             #56
847
 
848
 
849
;==============================================================================
850
;==============================================================================
851
Monitor:
852
        setlo   sp,#STACKTOP    ; top of stack; reset the stack pointer
853
        sb              r0,KeybdEcho    ; turn off keyboard echo
854
PromptLn:
855
        call    CRLF
856
        setlo   r1,#'$'
857
        call    DisplayChar
858
 
859
; Get characters until a CR is keyed
860
;
861
Prompt3:
862
        call    KeybdGetChar
863
        beqi    r1,#-1,Prompt3  ; wait for a character
864
        beqi    r1,#CR,Prompt1
865
        call    DisplayChar
866
        bra             Prompt3
867
 
868
; Process the screen line that the CR was keyed on
869
;
870
Prompt1:
871
        sc              r0,CursorCol    ; go back to the start of the line
872
        call    CalcScreenLoc   ; r1 = screen memory location
873
        or              r3,r1,r0
874
        lc              r1,[r3]
875
        addui   r3,r3,#2
876
        call    ScreenToAscii
877
        bnei    r1,#'$',Prompt2 ; skip over '$' prompt character
878
        lc              r1,[r3]
879
        addui   r3,r3,#2
880
        call    ScreenToAscii
881
 
882
; Dispatch based on command character
883
;
884
Prompt2:
885
        beqi    r1,#':',Editmem         ; $: - edit memory
886
        beqi    r1,#'D',Dumpmem         ; $D - dump memory
887
        beqi    r1,#'B',START           ; $B - start tiny basic
888
        beqi    r1,#'J',ExecuteCode     ; $J - execute code
889
        beqi    r1,#'L',LoadS19         ; $L - load S19 file
890
        beqi    r1,#'?',DisplayHelp     ; $? - display help
891
        beqi    r1,#'C',TestCLS         ; $C - clear screen
892
        bra             Monitor
893
 
894
TestCLS:
895
        lc              r1,[r3]
896
        addui   r3,r3,#2
897
        call    ScreenToAscii
898
        bnei    r1,#'L',Monitor
899
        lc              r1,[r3]
900
        addui   r3,r3,#2
901
        call    ScreenToAscii
902
        bnei    r1,#'S',Monitor
903
        call    ClearScreen
904
        sb              r0,CursorCol
905
        sb              r0,CursorRow
906
        call    CalcScreenLoc
907
        bra             Monitor
908 10 robfinch
 
909 27 robfinch
DisplayHelp:
910
        setlo   r1,HelpMsg
911
        call    DisplayString
912
        bra             Monitor
913
 
914
        align   16
915
HelpMsg:
916
        db      "? = Display help",CR,LF
917
        db      "CLS = clear screen",CR,LF
918
        db      ": = Edit memory bytes",CR,LF
919
        db      "L = Load S19 file",CR,LF
920
        db      "D = Dump memory",CR,LF
921
        db      "B = start tiny basic",CR,LF
922
        db      "J = Jump to code",CR,LF,0
923
        align   16
924
 
925
;------------------------------------------------------------------------------
926
; Ignore blanks in the input
927
; r3 = text pointer
928
; r1 destroyed
929
;------------------------------------------------------------------------------
930
;
931
ignBlanks:
932
        subui   sp,sp,#8
933
        sw              r31,[sp]
934
ignBlanks1:
935
        lc              r1,[r3]
936
        addui   r3,r3,#2
937
        call    ScreenToAscii
938
        beqi    r1,#' ',ignBlanks1
939
        subui   r3,r3,#2
940
        lw              r31,[sp]
941
        ret             #8
942
 
943
;------------------------------------------------------------------------------
944
; Edit memory byte(s).
945
;------------------------------------------------------------------------------
946
;
947
EditMem:
948
        call    ignBlanks
949
        call    GetHexNumber
950
        or              r5,r1,r0
951
        setlo   r4,#7
952
edtmem1:
953
        call    ignBlanks
954
        call    GetHexNumber
955
        sb              r1,[r5]
956
        addui   r5,r5,#1
957
        loop    r4,edtmem1
958
        bra             Monitor
959
 
960
;------------------------------------------------------------------------------
961
; Execute code at the specified address.
962
;------------------------------------------------------------------------------
963
;
964
ExecuteCode:
965
        call    ignBlanks
966
        call    GetHexNumber
967
        or              r3,r1,r0
968
        jal             r31,[r3]
969
        bra     Monitor
970
 
971
;------------------------------------------------------------------------------
972
; Do a memory dump of the requested location.
973
;------------------------------------------------------------------------------
974
;
975
DumpMem:
976
        call    ignBlanks
977
        call    GetHexNumber
978
        or              r2,r1,r0
979
        call    CRLF
980
        call    DisplayMem
981
        call    DisplayMem
982
        call    DisplayMem
983
        call    DisplayMem
984
        call    DisplayMem
985
        call    DisplayMem
986
        call    DisplayMem
987
        call    DisplayMem
988
        bra             Monitor
989
 
990
;------------------------------------------------------------------------------
991
; Get a hexidecimal number. Maximum of sixteen digits.
992
; R3 = text pointer (updated)
993
;------------------------------------------------------------------------------
994
;
995
GetHexNumber:
996
        subui   sp,sp,#24
997
        sm              [sp],r2/r4/r31
998
        setlo   r2,#0
999
        setlo   r4,#15
1000
gthxn2:
1001
        lc              r1,[r3]
1002
        addui   r3,r3,#2
1003
        call    ScreenToAscii
1004
        call    AsciiToHexNybble
1005
        beqi    r1,#-1,gthxn1
1006
        shli    r2,r2,#4
1007
        andi    r1,r1,#0x0f
1008
        or              r2,r2,r1
1009
        loop    r4,gthxn2
1010
gthxn1:
1011
        or              r1,r2,r0
1012
        lm              [sp],r2/r4/r31
1013
        ret             #24
1014
 
1015
;------------------------------------------------------------------------------
1016
; Convert ASCII character in the range '0' to '9', 'a' to 'f' or 'A' to 'F'
1017
; to a hex nybble.
1018
;------------------------------------------------------------------------------
1019
;
1020
AsciiToHexNybble:
1021
        bltui   r1,#'0',gthx3
1022
        bgtui   r1,#'9',gthx5
1023
        subui   r1,r1,#'0'
1024 10 robfinch
        ret
1025 27 robfinch
gthx5:
1026
        bltui   r1,#'A',gthx3
1027
        bgtui   r1,#'F',gthx6
1028
        subui   r1,r1,#'A'
1029
        addui   r1,r1,#10
1030
        ret
1031
gthx6:
1032
        bltui   r1,#'a',gthx3
1033
        bgtui   r1,#'f',gthx3
1034
        subui   r1,r1,#'a'
1035
        addui   r1,r1,#10
1036
        ret
1037
gthx3:
1038
        setlo   r1,#-1          ; not a hex number
1039
        ret
1040 10 robfinch
 
1041
;==============================================================================
1042 27 robfinch
; Load an S19 format file
1043
;==============================================================================
1044
;
1045
LoadS19:
1046
        bra             ProcessRec
1047
NextRec:
1048
        call    sGetChar
1049
        bne             r1,#LF,NextRec
1050
ProcessRec:
1051
        call    sGetChar
1052
        beqi    r1,#26,Monitor  ; CTRL-Z ?
1053
        bnei    r1,#'S',NextRec
1054
        call    sGetChar
1055
        blt             r1,#'0',NextRec
1056
        bgt             r1,#'9',NextRec
1057
        or              r4,r1,r0                ; r4 = record type
1058
        call    sGetChar
1059
        call    AsciiToHexNybble
1060
        or              r2,r1,r0
1061
        call    sGetChar
1062
        call    AsciiToHexNybble
1063
        shli    r2,r2,#4
1064
        or              r2,r2,r1                ; r2 = byte count
1065
        or              r3,r2,r1                ; r3 = byte count
1066
        beqi    r4,#'0',NextRec ; manufacturer ID record, ignore
1067
        beqi    r4,#'1',ProcessS1
1068
        beqi    r4,#'2',ProcessS2
1069
        beqi    r4,#'3',ProcessS3
1070
        beqi    r4,#'5',NextRec ; record count record, ignore
1071
        beqi    r4,#'7',ProcessS7
1072
        beqi    r4,#'8',ProcessS8
1073
        beqi    r4,#'9',ProcessS9
1074
        bra             NextRec
1075
 
1076
pcssxa:
1077
        andi    r3,r3,#0xff
1078
        subui   r3,r3,#1                ; one less for loop
1079
pcss1a:
1080
        call    sGetChar
1081
        call    AsciiToHexNybble
1082
        shli    r2,r2,#4
1083
        or              r2,r2,r1
1084
        call    sGetChar
1085
        call    AsciiToHexNybble
1086
        shli    r2,r2,#4
1087
        or              r2,r2,r1
1088
        sb              r2,[r5]
1089
        addui   r5,r5,#1
1090
        loop    r3,pcss1a
1091
; Get the checksum byte
1092
        call    sGetChar
1093
        call    AsciiToHexNybble
1094
        shli    r2,r2,#4
1095
        or              r2,r2,r1
1096
        call    sGetChar
1097
        call    AsciiToHexNybble
1098
        shli    r2,r2,#4
1099
        or              r2,r2,r1
1100
        bra             NextRec
1101
 
1102
ProcessS1:
1103
        call    S19Get16BitAddress
1104
        bra             pcssxa
1105
ProcessS2:
1106
        call    S19Get24BitAddress
1107
        bra             pcssxa
1108
ProcessS3:
1109
        call    S19Get32BitAddress
1110
        bra             pcssxa
1111
ProcessS7:
1112
        call    S19Get32BitAddress
1113
        sw              r5,S19StartAddress
1114
        bra             Monitor
1115
ProcessS8:
1116
        call    S19Get24BitAddress
1117
        sw              r5,S19StartAddress
1118
        bra             Monitor
1119
ProcessS9:
1120
        call    S19Get16BitAddress
1121
        sw              r5,S19StartAddress
1122
        bra             Monitor
1123
 
1124
S19Get16BitAddress:
1125
        subui   sp,sp,#8
1126
        sw              r31,[sp]
1127
        call    sGetChar
1128
        call    AsciiToHexNybble
1129
        or              r2,r1,r0
1130
        bra             S1932b
1131
 
1132
S19Get24BitAddress:
1133
        subui   sp,sp,#8
1134
        sw              r31,[sp]
1135
        call    sGetChar
1136
        call    AsciiToHexNybble
1137
        or              r2,r1,r0
1138
        bra             S1932a
1139
 
1140
S19Get32BitAddress:
1141
        subui   sp,sp,#8
1142
        sw              r31,[sp]
1143
        call    sGetChar
1144
        call    AsciiToHexNybble
1145
        or              r2,r1,r0
1146
        call    sGetChar
1147
        call    AsciiToHexNybble
1148
        shli    r2,r2,#4
1149
        or              r2,r1,r2
1150
        call    sGetChar
1151
        call    AsciiToHexNybble
1152
        shli    r2,r2,#4
1153
        or              r2,r2,r1
1154
S1932a:
1155
        call    sGetChar
1156
        call    AsciiToHexNybble
1157
        shli    r2,r2,#4
1158
        or              r2,r2,r1
1159
        call    sGetChar
1160
        call    AsciiToHexNybble
1161
        shli    r2,r2,#4
1162
        or              r2,r2,r1
1163
S1932b:
1164
        call    sGetChar
1165
        call    AsciiToHexNybble
1166
        shli    r2,r2,#4
1167
        or              r2,r2,r1
1168
        call    sGetChar
1169
        call    AsciiToHexNybble
1170
        shli    r2,r2,#4
1171
        or              r2,r2,r1
1172
        call    sGetChar
1173
        call    AsciiToHexNybble
1174
        shli    r2,r2,#4
1175
        or              r2,r2,r1
1176
        xor             r4,r4,r4
1177
        or              r5,r2,r0
1178
        lw              r31,[sp]
1179
        addui   sp,sp,#8
1180
        ret
1181
 
1182
;------------------------------------------------------------------------------
1183
; Get a character from auxillary input, checking the keyboard status for a
1184
; CTRL-C
1185
;------------------------------------------------------------------------------
1186
;
1187
sGetChar:
1188
        subui   sp,sp,#8
1189
        sw              r31,[sp]
1190
sgc2:
1191
        call    KeybdCheckForKey
1192
        beq             r1,r0,sgc1
1193
        call    KeybdGetchar
1194
        beqi    r1,#CRTLC,Monitor
1195
sgc1:
1196
        call    AUXIN
1197
        beq             r1,r0,sgc2
1198
        lw              r31,[sp]
1199
        addui   sp,sp,#8
1200
        ret
1201
 
1202
;--------------------------------------------------------------------------
1203
; Sound a 800 Hz beep
1204
;--------------------------------------------------------------------------
1205
;
1206
SetupAC97:
1207
        ori             r1,r0,#0         ; trigger a read of register 26
1208
        sc              r1,AC97+0x26
1209
sac971:                                         ; wait for status to register 0xF (all ready)
1210
        lc              r1,AC97+0x26
1211
        bnei    r1,#0x0F,sac971
1212
        ori             r1,r0,#0         ; master volume, 0db attenuation, mute off
1213
        sc              r1,AC97+2
1214
        sc              r1,AC97+4               ; headphone volume, 0db attenuation, mute off
1215
        ori             r1,r0,#8000             ; wait a while for the settings to take effect
1216
sac972:
1217
        loop    r1,sac972
1218
 
1219
Beep:
1220
        ori             r1,r0,#15               ; master volume to max
1221
        sc              r1,PSG+128
1222
        ori             r1,r0,#13422    ; 800Hz
1223
        sc              r1,PSG
1224
        ori             r1,r0,#32               ; attack (8.192 ms)
1225
        sc              r1,PSG+8
1226
        ori             r1,r0,#64               ; decay  (16.384 ms)
1227
        sc              r1,PSG+10
1228
        ori             r1,r0,#0xC0             ; sustain level
1229
        sc              r1,PSG+12
1230
        ori             r1,r0,#4000             ; release (1.024 s)
1231
        sc              r1,PSG+14
1232
        ori             r1,r0,#0x1104   ; gate, output enable, triangle waveform
1233
        sc              r1,PSG+4
1234
        ori             r1,r0,#25000000 ; delay about 1s
1235
beep1:
1236
        loop    r1,beep1
1237
        ori             r1,r0,#0x0000   ; gate off, output enable off, no waveform
1238
        ret
1239
 
1240
;*
1241
;* ===== Input a character from the host into register D0 (or
1242
;*      return Zero status if there's no character available).
1243
;*
1244
AUXIN:
1245
        inb             r1,UART_LS              ; is character ready ?
1246
        andi    r1,r1,#rxfull
1247
        beq             r1,r0,AXIRET    ;if not, return Zero status
1248
        inb             r1,UART                 ; else get the character
1249
        andi    r1,r1,#0x7f             ;zero out the high bit
1250
AXIRET:
1251
        ret
1252
 
1253
;*
1254
;* ===== Return to the resident monitor, operating system, etc.
1255
;*
1256
BYEBYE:
1257
        jmp             Monitor
1258
;    MOVE.B     #228,D7         ;return to Tutor
1259
;       TRAP    #14
1260
 
1261
        align 16
1262
msgInit db      CR,LF,"Raptor64 Tiny BASIC v1.0",CR,LF,"(C) 2012  Robert Finch",CR,LF,LF,0
1263
OKMSG   db      CR,LF,"OK",CR,LF,0
1264
msgWhat db      "What?",CR,LF,0
1265
SRYMSG  db      "Sorry."
1266
CLMSG   db      CR,LF,0
1267
msgReadError    db      "Compact FLASH read error",CR,LF,0
1268
msgNumTooBig    db      "Number is too big",CR,LF,0
1269
msgDivZero              db      "Division by zero",CR,LF,0
1270
msgVarSpace     db  "Out of variable space",CR,LF,0
1271
msgBytesFree    db      " bytes free",CR,LF,0
1272
msgReady                db      CR,LF,"Ready",CR,LF,0
1273
msgComma                db      "Expecting a comma",CR,LF,0
1274
msgLineRange    db      "Line number too big",CR,LF,0
1275
msgVar                  db      "Expecting a variable",CR,LF,0
1276
msgRNDBad               db      "RND bad parameter",CR,LF,0
1277
msgSYSBad               db      "SYS bad address",CR,LF,0
1278
msgInputVar             db      "INPUT expecting a variable",CR,LF,0
1279
msgNextFor              db      "NEXT without FOR",CR,LF,0
1280
msgNextVar              db      "NEXT expecting a defined variable",CR,LF,0
1281
msgBadGotoGosub db      "GOTO/GOSUB bad line number",CR,LF,0
1282
msgRetWoGosub   db      "RETURN without GOSUB",CR,LF,0
1283
msgTooBig               db      "Program is too big",CR,LF,0
1284
msgExtraChars   db      "Extra characters on line ignored",CR,LF,0
1285
 
1286
INITMSG:
1287
        db              CR,LF,'Raptor64 Tiny BASIC, v1.0',CR,LF,LF,0
1288
OKMSG:
1289
        db              CR,LF,'OK',CR,LF,0
1290
HOWMSG:
1291
        db              'How?',CR,LF,0
1292
WHTMSG:
1293
        db              'What?',CR,LF,0
1294
SRYMSG:
1295
        db              'Sorry.'
1296
CLMSG:
1297
        db              CR,LF,0
1298
;       DC.B    0        ;<- for aligning on a word boundary
1299
        align   16
1300
 
1301
LSTROM  EQU             $
1302
        ;       end of possible ROM area
1303
 
1304
        bss
1305
        align   16
1306
 
1307
                org             0x0080
1308
typef   db      0   ; variable / expression type
1309
        align   8
1310
OSSP    dw      1       ; OS value of sp
1311
CURRNT  dw      1       ;       Current line pointer
1312
STKGOS  dw      1       ;       Saves stack pointer in 'GOSUB'
1313
STKINP  dw      1       ;       Saves stack pointer during 'INPUT'
1314
LOPVAR  dw      1       ;       'FOR' loop save area
1315
LOPINC  dw      1       ;       increment
1316
LOPLMT  dw      1       ;       limit
1317
LOPLN   dw      1       ;       line number
1318
LOPPT   dw      1       ;       text pointer
1319
TXTUNF  dw      1       ;       points to unfilled text area
1320
VARBGN  dw      1       ;       points to variable area
1321
IVARBGN dw  1   ;   points to integer variable area
1322
SVARBGN dw  1   ;   points to string variable area
1323
FVARBGN dw  1   ;   points to float variable area
1324
STKBOT  dw      1       ;       holds lower limit for stack growth
1325
NUMWKA  fill.b  12,0                     ; numeric work area
1326
BUFFER  fill.b  BUFLEN,0x00             ;               Keyboard input buffer
1327
 
1328
 
1329
;==============================================================================
1330 10 robfinch
; Checkerboard RAM tester
1331
;==============================================================================
1332
;
1333 27 robfinch
        code
1334
        align   16
1335 10 robfinch
ramtest:
1336
        or              r8,r0,r0                ; r8 = 0
1337
        ori             r1,r0,#0xAAAA5555AAAA5555       ; checkerboard pattern
1338
ramtest2:
1339
        sw              r1,[r8]                 ; save the checkerboard to memory
1340
        lw              r2,[r8]                 ; read it back
1341
        cmp             r3,r1,r2                ; is it the same ?
1342 27 robfinch
        bne     r3,r0,ramtest1
1343
        addui   r8,r8,#8                ; increment RAM pointer
1344
        cmpi    r3,r8,#0x0000_0000_0400_0000
1345
        blt             r3,r0,ramtest2
1346 10 robfinch
ramtest1:
1347
        or              r10,r8,r0               ; r10 = max ram address
1348
        ; readback the checkerboard pattern
1349
        or              r8,r0,r0                ; r8 = 0
1350
ramtest4:
1351
        lw              r2,[r8]
1352
        cmpi    r3,r2,#0xAAAA5555AAAA5555
1353 27 robfinch
        bne             r3,r0,ramtest3
1354 10 robfinch
        addi    r8,r8,#8
1355
        cmpi    r3,r8,#0x0000_0000_0100_0000
1356 27 robfinch
        blt     r3,r0,ramtest4
1357 10 robfinch
ramtest3:
1358
        bne             r8,r10,ramtest8 ; check for equal maximum address
1359
 
1360
        ; perform ramtest again with inverted checkerboard
1361
        or              r8,r0,r0                ; r8 = 0
1362
        ori             r1,r0,#0x5555AAAA5555AAAA
1363
ramtest5:
1364
        sw              r1,[r8]
1365
        lw              r2,[r8]
1366
        cmp             r3,r1,r2
1367 27 robfinch
        bne             r3,r0,ramtest6
1368 10 robfinch
        addi    r8,r8,#8
1369
        cmpi    r3,r8,#0x0000_0000_0100_0000
1370 27 robfinch
        blt             r3,r0,ramtest5
1371 10 robfinch
ramtest6:
1372
        or              r11,r8,r0               ; r11 = max ram address
1373
        ; readback checkerboard
1374
        or              r8,r0,r0
1375
ramtest7:
1376
        lw              r2,[r8]
1377
        cmpi    r3,r2,#0x5555AAAA5555AAAA
1378 27 robfinch
        bne             r3,r0,ramtest8
1379 10 robfinch
        addi    r8,r8,#8
1380
        cmpi    r3,r8,#0x0000_0000_0100_0000
1381 27 robfinch
        blt             r3,r0,ramtest7
1382 10 robfinch
ramtest8:
1383
        beq             r8,r11,ramtest9
1384
        min             r8,r8,r11
1385
ramtest9:
1386
        beq             r8,r10,ramtest10
1387
        min             r8,r8,r10
1388
ramtest10:
1389
        sw              r8,0x00000400   ;memend
1390 27 robfinch
        ret
1391
 
1392
;-------------------------------------------
1393
; IRQ routine
1394
;-------------------------------------------
1395
irqrout:
1396
        subui   sp,sp,#16
1397
        sm              [sp],r1/lr
1398
        inch    r1,PIC
1399
        beqi    r1,#1,ColdStart
1400
irqrout3:
1401
        bnei    r1,#2,irqrout2
1402
        call    Pulse1000
1403
        bra             irqrout1
1404
irqrout2:
1405
        bnei    r1,#15,irqrout1
1406
        call    KeybdIRQ
1407
irqrout1:
1408
        lm              [sp],r1/lr
1409
        addui   sp,sp,#16
1410
        iret
1411
 
1412
;-------------------------------------------
1413
; NMI routine
1414
;-------------------------------------------
1415
nmirout:
1416
        iret
1417
 
1418
;-------------------------------------------
1419
; Handle miss on Data TLB
1420
;-------------------------------------------
1421
DTLBHandler:
1422
        sw              r1,0xFFFF_FFFF_FFFF_0000
1423
        sw              r2,0xFFFF_FFFF_FFFF_0008
1424
dh1:
1425
        omgi    r1,#0            ; try open mutex gate #0 (TLB protector)
1426
        bne             r1,r0,dh1       ; spinlock if gate is closed
1427
        mfspr   r1,PTA          ; get the page table address
1428
        mfspr   r2,BadVAddr     ; get the bad virtual address
1429
        mtspr   TLBVirtPage,r2  ; which virtual address to update
1430
        shrui   r2,r2,#13       ; turn va into index
1431
        addu    r1,r1,r2
1432
        lw              r2,[r1]         ; get the physical address from the table
1433
        and             r2,r2,#FFFF_FFFF_FFFF_E000      ; mask off lower bits
1434
        mtspr   TLBPhysPage0,r2 ;
1435
        lw              r2,8[r1]        ; get the physical address from the table
1436
        and             r2,r2,#FFFF_FFFF_FFFF_E000      ; mask off lower bits
1437
        mtspr   TLBPhysPage1,r2 ;
1438
        tlbwr                           ; update a random entry in the TLB
1439
        cmgi    #0                       ; close the mutex gate
1440
        lw              r1,0xFFFF_FFFF_FFFF_0000
1441
        lw              r2,0xFFFF_FFFF_FFFF_0008
1442
        iret
1443
        nop
1444
        nop
1445 10 robfinch
 
1446 27 robfinch
        org             0xFFFF_FFFF_FFFF_FFB0
1447
        jmp             DTLBHandler
1448 10 robfinch
        nop
1449
        nop
1450 27 robfinch
        org             0xFFFF_FFFF_FFFF_FFC0
1451
        jmp             DTLBHandler
1452 10 robfinch
        nop
1453
        nop
1454 27 robfinch
        org     0xFFFF_FFFF_FFFF_FFD0
1455
        jmp             irqrout
1456 10 robfinch
        nop
1457
        nop
1458 27 robfinch
        org     0xFFFF_FFFF_FFFF_FFE0
1459
        jmp             nmirout
1460 10 robfinch
        nop
1461
        nop
1462
        org             0xFFFF_FFFF_FFFF_FFF0
1463
        jmp             start
1464 27 robfinch
        nop
1465
        nop
1466
 
1467
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.