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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [software/] [boot/] [boot_rom.asm] - Blame information for rev 15

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

Line No. Rev Author Line
1 4 robfinch
; ============================================================================
2
;        __
3 13 robfinch
;   \\__/ o\    (C) 2013-2022  Robert Finch, Waterloo
4 4 robfinch
;    \  __ /    All rights reserved.
5
;     \/_//     robfinch@opencores.org
6
;       ||
7
;
8
;
9 13 robfinch
; BSD 3-Clause License
10
; Redistribution and use in source and binary forms, with or without
11
; modification, are permitted provided that the following conditions are met:
12
;
13
; 1. Redistributions of source code must retain the above copyright notice, this
14
;    list of conditions and the following disclaimer.
15
;
16
; 2. Redistributions in binary form must reproduce the above copyright notice,
17
;    this list of conditions and the following disclaimer in the documentation
18
;    and/or other materials provided with the distribution.
19
;
20
; 3. Neither the name of the copyright holder nor the names of its
21
;    contributors may be used to endorse or promote products derived from
22
;    this software without specific prior written permission.
23
;
24
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 4 robfinch
;
35
; ============================================================================
36
;
37 15 robfinch
OPT include "d:\cores2022\rf6809\software\boot\mon_equates.asm"
38
OPT include "d:\cores2022\rf6809\software\boot\io_equates.asm"
39 4 robfinch
 
40 15 robfinch
OPC_SWI                         EQU             $03F
41 4 robfinch
ScreenLocation          EQU             $10
42
ColorCodeLocation       EQU             $14
43
ScreenLocation2         EQU             $18
44
BlkcpySrc                       EQU             $1C
45
BlkcpyDst                       EQU             $20
46
Strptr                          EQU             $24
47
PICptr                          EQU             $28
48
; Forth Area
49
; 0x30-0x60
50
 
51
; Task control blocks, room for 256 tasks
52
TCB_NxtRdy              EQU             $00     ; next task on ready / timeout list
53
TCB_PrvRdy              EQU             $04     ; previous task on ready / timeout list
54
TCB_NxtTCB              EQU             $08
55
TCB_Timeout             EQU             $0C
56
TCB_Priority    EQU             $10
57
TCB_MSGPTR_D1   EQU             $14
58
TCB_MSGPTR_D2   EQU             $18
59
TCB_hJCB                        EQU             $1C
60
TCB_Status              EQU             $1E
61
TCB_CursorRow   EQU             $20
62
TCB_CursorCol   EQU             $21
63
TCB_hWaitMbx    EQU             $22     ; handle of mailbox task is waiting at
64
TCB_mbq_next    EQU             $24     ; mailbox queue next
65
TCB_mbq_prev    EQU             $28     ; mailbox queue previous
66
TCB_iof_next    EQU             $2C
67
TCB_iof_prev    EQU             $30
68
TCB_SPSave              EQU             $34     ; TCB_SPSave area
69
TCB_mmu_map             EQU             $38
70
 
71
KeybdHead               EQU             $FFFFFC800
72
KeybdTail               EQU             $FFFFFC900
73
KeybdEcho               EQU             $FFFFFCA00
74
KeybdBad                EQU             $FFFFFCB00
75
KeybdAck                EQU             $FFFFFCC00
76
KeybdLocks              EQU             $FFFFFCD00
77
KeybdBuffer             EQU             $FFFFFC000      ; buffer is 16 chars
78
 
79
BIOS_SCREENS    EQU     $17000000       ; $17000000 to $171FFFFF
80
 
81
; EhBASIC vars:
82
;
83 15 robfinch
NmiBase         EQU             $FFC013
84
IrqBase         EQU             $FFC014
85 4 robfinch
 
86
IOFocusNdx      EQU             $100
87
 
88 13 robfinch
; These variables in global OS storage area
89
 
90 15 robfinch
IOFocusList     EQU             $FFC000 ; to $FF000F
91
IOFocusID               EQU             $FFC010
92
IrqSource               EQU             $FFC011
93
IRQFlag                 EQU             $FFC012
94
RunningID               EQU             $FFC013
95 13 robfinch
 
96 4 robfinch
; These variables use direct page access
97
CursorRow       EQU             $110
98
CursorCol       EQU             $111
99
CharColor       EQU             $112
100
ScreenColor     EQU             $113
101
CursorFlash     EQU             $114
102
KeyState1       EQU     $120
103
KeyState2       EQU     $121
104
KeyLED          EQU     $122
105
KeybdID         EQU     $124
106 13 robfinch
KeybdBlock      EQU     $126
107
kbdHeadRcv      EQU     $127
108
kbdTailRcv      EQU     $128
109
kbdFifo                 EQU     $40                             ; in local RAM
110
kbdFifoAlias    EQU     $C00040 ; to $C0007F    ; alias for $40 to $7F
111
SerhZero                EQU     $130
112
SerHeadRcv      EQU     $131
113
SertZero                EQU     $132
114
SerTailRcv      EQU     $133
115
SerHeadXmit     EQU     $136
116
SerTailXmit     EQU     $138
117
SerRcvXon               EQU     $139
118
SerRcvXoff      EQU     $140
119
SerRcvBuf               EQU     $BFF000 ; 4kB serial recieve buffer
120 4 robfinch
 
121 14 robfinch
farflag EQU             $15F
122 13 robfinch
asmbuf  EQU             $160    ; to $17F
123
 
124 4 robfinch
QNdx0           EQU             $780
125
QNdx1           EQU             QNdx0+2
126
QNdx2           EQU             QNdx1+2
127
QNdx3           EQU             QNdx2+2
128
QNdx4           EQU             QNdx3+2
129
FreeTCB         EQU             QNdx4+2
130
TimeoutList     EQU             FreeTCB+2
131
FreeMbx         EQU             RunningTCB + 2
132
nMailbox        EQU             FreeMbx + 2
133
FreeMsg         EQU             nMailbox + 2
134
nMsgBlk         EQU             FreeMsg + 2
135
 
136
 
137
CharOutVec      EQU             $800
138
CharInVec       EQU             $804
139 13 robfinch
CmdPromptJI     EQU     $808
140 14 robfinch
MonErrVec       EQU             $80C
141 15 robfinch
BreakpointFlag  EQU             $810
142
NumSetBreakpoints       EQU     $811
143
Breakpoints                     EQU             $820    ; to $82F
144
BreakpointBytes EQU             $830    ; to $83F
145
mon_vectb                               EQU             $880
146 4 robfinch
 
147
; Register save area for monitor
148
mon_DSAVE       EQU             $900
149
mon_XSAVE       EQU             $902
150
mon_YSAVE       EQU             $904
151
mon_USAVE       EQU             $906
152
mon_SSAVE       EQU             $908
153
mon_PCSAVE      EQU             $90A
154
mon_DPRSAVE     EQU             $90E
155
mon_CCRSAVE     EQU             $90F
156
 
157
mon_numwka      EQU             $910
158
mon_r1          EQU             $920
159 13 robfinch
mon_r2          EQU             $924
160 15 robfinch
jmpvec          EQU             $928
161 4 robfinch
 
162
; The ORG directive must set an address a multiple of 4 in order for the Verilog
163
; output to work correctly.
164
 
165
        org             $FFD0AC
166
        nop
167
        nop
168
        nop
169
XBLANK
170
        ldb             #' '
171
        lbsr    OUTCH
172
        rts
173
 
174
        org             $FFD0D0
175
        nop
176
        nop
177
CRLF
178
CRLF1:
179
        ldb             #CR
180
        lbsr    OUTCH
181
        ldb             #LF
182
        lbsr    OUTCH
183
        rts
184
 
185
        org             $FFD0F0
186
        nop
187
        bra             CRLF1
188
 
189
        org             $FFD1DC
190
ONEKEY
191
        jmp             [CharInVec]
192
 
193
        org             $FFD2C0
194
        nop
195
LETTER
196
        lbsr    OUTCH
197
        rts
198
 
199
        org             $FFD2CC
200
        nop
201
        nop
202
HEX2
203
        lbsr    DispByteAsHex
204
        rts
205
HEX4
206
        lbsr    DispWordAsHex
207
        rts
208
 
209
        org             $FFD300
210
ClearScreenJmp
211
        lbra    ClearScreen
212
        org             $FFD308
213
HomeCursorJmp
214
        lbra    HomeCursor
215
 
216 13 robfinch
        org             $FFD400
217 4 robfinch
 
218
; Local RAM test routine
219
; Checkerboard testing.
220
; There is 70kB of local RAM
221
; Does not use any RAM including no stack
222
 
223
ramtest:
224
        ldy             #0
225
        lda             #1
226
        sta             LEDS
227
        ldd             #$AAA555
228
ramtest1:
229
        std             ,y++
230 13 robfinch
        cmpy    #$8000
231 4 robfinch
        blo             ramtest1
232
        ; now readback values and compare
233
        ldy             #0
234
ramtest3:
235
        ldd             ,y++
236
        cmpd    #$AAA555
237
        bne             ramerr
238 13 robfinch
        cmpy    #$8000
239 4 robfinch
        blo             ramtest3
240
        lda             #2
241
        sta             LEDS
242
        jmp             ,u
243
ramerr:
244
        lda             #$80
245
        sta             LEDS
246
        ldx             #TEXTSCR
247
        ldb             COREID
248
        abx
249
        lda             #'F'
250
        sta             ,x
251
        sync
252
        jmp             ,u
253
 
254 15 robfinch
dramtest:
255
        ldy             #$10000                 ; DRAM starts here
256
        lda             #1
257
        sta             LEDS
258
        ldu             #$AAA555
259
        lbsr    CRLF
260
dramtest1:
261
        deca
262
        bne             dramtest4
263
        tfr             y,d
264
        lbsr    DispWordAsHex
265
        ldb             #CR
266
        lbsr    OUTCH
267
dramtest4:
268
        stu             ,y++
269
        cmpy    #$E00000                ; DRAM ends here
270
        blo             dramtest1
271
        ; now readback values and compare
272
        ldy             #$10000
273
        lda             #1
274
        lbsr    CRLF
275
dramtest3:
276
        deca
277
        bne             dramtest5
278
        tfr             y,d
279
        lbsr    DispWordAsHex
280
        ldb             #CR
281
        lbsr    OUTCH
282
dramtest5:
283
        cmpu    ,y++
284
        bne             dramerr
285
        cmpy    #$E00000
286
        blo             dramtest3
287
        lda             #2
288
        sta             LEDS
289
        lbra    Monitor
290
dramerr:
291
        lda             #$80
292
        sta             LEDS
293
        ldx             #TEXTSCR
294
        ldb             COREID
295
        abx
296
        lda             #'F'
297
        sta             ,x
298
        lbra    Monitor
299
 
300 13 robfinch
        org             $FFE000
301 4 robfinch
        FDB Monitor
302
        FDB DumRts      ;       NEXTCMD
303
        FDB INCH
304
        FDB INCHE
305
        FDB INCHEK
306
        FDB OUTCH
307
        FDB PDATA
308
        FDB PCRLF
309
        FDB PSTRNG
310
        FDB DumRts                      ; LRA
311
        FDB DumRts
312
        FDB DumRts
313
        FDB DumRts
314
        FDB DumRts                      ; VINIZ
315
        FDB DisplayChar ;       VOUTCH
316
        FDB DumRts                      ; ACINIZ
317
        FDB DumRts                      ; AOUTCH
318
 
319
DumRts:
320
        rts
321
 
322
;------------------------------------------------------------------------------
323
;------------------------------------------------------------------------------
324
 
325
start:
326 13 robfinch
        lda             #$FFF                   ; all cores can do this
327
        sta             VIA+VIA_DDRA
328 4 robfinch
        lda             #$55                    ; see if we can at least set LEDs
329
        sta             LEDS
330 13 robfinch
        lda             #1                              ; prime OS semaphore
331
        sta             OSSEMA+$1000
332 15 robfinch
        sta             OUTSEMA+$1000
333 4 robfinch
        ldu             #st6                    ; U = return address
334
        jmp             ramtest         ; JMP dont JSR
335
st6:
336 13 robfinch
        lds             #$6FFF          ; boot up stack area
337 4 robfinch
        lda             COREID
338
        cmpa    #FIRST_CORE
339
;       beq             st8
340
;       sync                                            ; halt cores other than 2
341
st8:
342
;       bne             skip_init
343
;       bsr             romToRam
344
;       ldd             #st7 & $FFFF
345
;       tfr             d,x
346
;       jmp             ,x                              ; jump to the BIOS now in local RAM
347
st7:
348
        bsr             Delay3s         ; give some time for devices to reset
349 15 robfinch
        clr             BreakpointFlag
350
        clr             NumSetBreakpoints
351 4 robfinch
        lda             #$AA
352
        sta             LEDS
353 13 robfinch
        lda             #FIRST_CORE
354 4 robfinch
        sta             IOFocusID       ; core #2 has focus
355
        sta             RunningID
356 14 robfinch
        ; Clear IO focus list
357
        ldx             #0
358
st9:
359
        clr             IOFocusList,x
360
        inx
361
        cmpx    #16
362
        blo             st9
363
        lda             #24
364
        sta             IOFocusList+FIRST_CORE
365
 
366 4 robfinch
        lda             #$0CE
367
        sta             ScreenColor
368
        sta             CharColor
369
        bsr             ClearScreen
370
        ldd             #DisplayChar
371
        std             CharOutVec
372 13 robfinch
        ldd             #SerialPeekCharDirect
373 4 robfinch
        std             CharInVec
374 15 robfinch
;       swi
375
;       fcb             MF_OSCALL
376
;       fcb             24                                      ; request IO focus
377 4 robfinch
        ldb             COREID
378
        cmpb    #FIRST_CORE
379
        beq             init
380
        bra             skip_init
381
        bra             multi_sieve
382
st3:
383
        lda             #$FF
384
        sta             LEDS
385
        bra             st3
386
 
387
        ; initialize interrupt controller
388
        ; first, zero out all the vectors
389
init:
390 13 robfinch
        lbsr    rtc_read        ; get clock values
391
        ldx             #kbdHeadRcv
392
        ldb             #32                             ; number of bytes to zero out
393
init1:
394
        clr             ,x+
395
        decb
396
        bne             init1
397
        lbsr    TimerInit
398
        lbsr    InitSerial
399 4 robfinch
        ldx             #128
400
        lda             #1                      ; set irq(bit0), clear firq (bit1), disable int (bit 6), clear edge sense(bit 7)
401
        ldb             #FIRST_CORE                     ; serving core id
402
st1:
403 13 robfinch
        clr             PIC,x                   ; cause code
404 4 robfinch
        sta             PIC+1,x
405
        stb             PIC+2,x
406
        leax    4,x
407
        cmpx    #256
408
        blo             st1
409
;       lda             #4                              ; make the timer interrupt edge sensitive
410
;       sta             PIC+4                   ; reg #4 is the edge sensitivity setting
411
;       sta             PIC                             ; reg #0 is interrupt enable
412 13 robfinch
        lda             #$81                    ; make irq edge sensitive
413
        sta             PIC+$FD
414
        lda             #31                             ; enable timer interrupt
415 15 robfinch
        sta             PIC+9
416 13 robfinch
        ldb             #1
417
        stb             OUTSEMA+SEMAABS ; set semaphore to 1 available slot
418 4 robfinch
skip_init:
419
        andcc   #$EF                    ; unmask irq
420 15 robfinch
        lda             #COLS
421 4 robfinch
        sta             TEXTREG+TEXT_COLS
422 15 robfinch
        lda             #ROWS
423 4 robfinch
        sta             TEXTREG+TEXT_ROWS
424
        bsr             ClearScreen
425
        bsr             HomeCursor
426
        lda             #5
427
        sta             LEDS
428
        ldd             #msgStartup
429
        bsr             DisplayString
430
        ldx             #0
431
        ldd             #0
432
        lbsr    ShowSprites
433
        lbsr    KeybdInit
434
        ldd             KeybdID
435
        bsr             DispWordAsHex
436
        jmp             MonitorStart
437
 
438
msgStartup
439
        fcb             "rf6809 12-bit System Starting.",CR,LF,0
440
 
441
;------------------------------------------------------------------------------
442
; The checkpoint register must be cleared within 1 second or a NMI interrupt
443
; will occur. checkpoint should be called with a JSR so that the global ROM
444
; routine is called.
445
;
446
; Modifies:
447
;               none
448
;------------------------------------------------------------------------------
449
 
450
checkpoint:
451
        clr             $FFFFFFFE1      ; writing any value will do
452
        rts
453
 
454
;------------------------------------------------------------------------------
455
; Copy the system ROM to local RAM
456
; Running the code from local RAM is probably an order of magnitude faster
457
; then running from the global ROM. It also reduces the network traffic to
458
; run from local RAM.
459
;
460
; Modifies:
461
;               d,x,y
462
;------------------------------------------------------------------------------
463
 
464
romToRam:
465
        ldx             #$FFC000
466
        ldy             #$00C000
467
romToRam1:
468
        ldd             ,x++
469
        std             ,y++
470
        cmpx    #0
471
        bne             romToRam1
472
        rts
473
 
474
;------------------------------------------------------------------------------
475
; Multi-core sieve program.
476
;------------------------------------------------------------------------------
477
 
478
; First fill screen chars with 'P' indicating prime positions
479
; Each core is responsible for the Nth position where N is the
480
; core number minus two.
481
;
482
multi_sieve:
483
        lda             #'P'                                    ; indicate prime
484
        ldb             COREID                          ; find out which core we are
485
        subb    #FIRST_CORE
486
        ldx             #0                                              ; start at first char of screen
487
        abx
488
multi_sieve3:
489
        sta             TEXTSCR,x                       ; store 'P'
490
        leax    8,x                                             ; advance to next position
491
        cmpx    #4095
492
        blo             multi_sieve3
493
        jsr             checkpoint
494
        addb    #2                                              ; start sieve at 2 (core id)
495
        lda             #'N'                                    ; flag position value of 'N' for non-prime
496
multi_sieve2:
497
        ldx             #0
498
        abx                                                                     ; skip the first position - might be prime
499
multi_sieve1:
500
        abx                                                                     ; increment
501
        sta             TEXTSCR,x
502
        cmpx    #4095
503
        blo             multi_sieve1
504
        jsr             checkpoint
505
        addb    #8                                              ; number of cores working on it
506
        cmpb    #4080
507
        blo             multi_sieve2
508
multi_sieve4:                                   ; hang machine
509
        sync
510
        lbra    Monitor
511
 
512 13 robfinch
;------------------------------------------------------------------------------
513
; Single core sieve.
514
;------------------------------------------------------------------------------
515
 
516 4 robfinch
sieve:
517
        lda             #'P'                                    ; indicate prime
518
        ldx             #0                                              ; start at first char of screen
519
sieve3:
520
        sta             TEXTSCR,x                       ; store 'P'
521
        inx                                                                     ; advance to next position
522
        cmpx    #4095
523
        blo             sieve3
524
        ldb             #2                                              ; start sieve at 2
525
        lda             #'N'                                    ; flag position value of 'N' for non-prime
526
sieve2:
527
        ldx             #0
528
        abx                                                                     ; skip the first position - might be prime
529
sieve1:
530
        abx                                                                     ; increment
531
        sta             TEXTSCR,x
532
        cmpx    #4095
533
        blo             multi_sieve1
534
        incb                                                            ; number of cores working on it
535
        cmpb    #4080
536
        blo             sieve2
537
sieve4:                                                         ; hang machine
538 13 robfinch
        rts
539 4 robfinch
 
540
;------------------------------------------------------------------------------
541
; Three second delay for user convenience and to allow some devices time to
542
; reset.
543
;------------------------------------------------------------------------------
544
 
545
Delay3s:
546
        ldd             #9000000
547
dly3s1:
548
        cmpb    #$FF
549
        bne             dly3s2
550
dly3s2:
551
        sta             LEDS
552
        subd    #1
553
        bne             dly3s1
554
        rts
555
 
556
;------------------------------------------------------------------------------
557
;------------------------------------------------------------------------------
558
ShiftLeft5:
559
        aslb
560
        rola
561
        aslb
562
        rola
563
        aslb
564
        rola
565
        aslb
566
        rola
567
        aslb
568
        rola
569
        rts
570
 
571
;------------------------------------------------------------------------------
572 13 robfinch
; Parameters:
573
;               b = core id of core to copy
574 4 robfinch
;------------------------------------------------------------------------------
575
;
576
CopyVirtualScreenToScreen:
577
        pshs    d,x,y,u
578 13 robfinch
        ; Compute virtual screen location for core passed in accb.
579
        tfr             b,a
580
        asla
581
        asla
582
        asla
583
        asla
584
        ora             #$C00
585
        clrb
586 4 robfinch
        tfr             d,x
587 13 robfinch
        pshs    d
588 4 robfinch
        ldy             #TEXTSCR
589 15 robfinch
        ldu             #COLS*ROWS/2
590 4 robfinch
cv2s1:
591
        ldd             ,x++
592
        std             ,y++
593
        leau    -1,u
594
        cmpu    #0
595
        bne             cv2s1
596
        ; reset the cursor position in the text controller
597 13 robfinch
        puls    x
598
        ldb             CursorRow,x
599 15 robfinch
        lda             #COLS
600 4 robfinch
        mul
601 13 robfinch
        tfr             d,y
602
        ldb             CursorCol,x
603
        tfr             y,x
604 4 robfinch
        abx
605
        stx             TEXTREG+TEXT_CURPOS
606
        puls    d,x,y,u,pc
607
 
608
;------------------------------------------------------------------------------
609
;------------------------------------------------------------------------------
610
;
611
CopyScreenToVirtualScreen:
612
        pshs    d,x,y,u
613
        bsr             GetScreenLocation
614
        tfr             d,y
615
        ldx             #TEXTSCR
616 15 robfinch
        ldu             #COLS*ROWS/2
617 4 robfinch
cs2v1:
618
        ldd             ,x++
619
        std             ,y++
620
        leau    -1,u
621
        cmpu    #0
622
        bne             cs2v1
623
        puls    d,x,y,u,pc
624
 
625
;------------------------------------------------------------------------------
626
;------------------------------------------------------------------------------
627
        fcb             "TEXTSCR "
628
        fcw             TextOpen
629
        fcw             TextClose
630
        fcw             TextRead
631
        fcw             TextWrite
632
        fcw             TextSeek
633
 
634
TextOpen:
635
        rts
636
TextClose:
637
        rts
638
TextRead:
639
        rts
640
TextWrite:
641
        rts
642
TextSeek:
643
        rts
644
 
645
;------------------------------------------------------------------------------
646
; Clear the screen and the screen color memory
647
; We clear the screen to give a visual indication that the system
648
; is working at all.
649
;
650
; Modifies:
651
;               none
652
;------------------------------------------------------------------------------
653
 
654
ClearScreen:
655
        pshs    d,x,y,u
656 15 robfinch
        ldx             #COLS*ROWS
657 4 robfinch
        tfr             x,u
658
        bsr             GetScreenLocation
659
        tfr             d,y
660
        ldb             #' '                            ; space char
661
cs1:
662
        stb             ,y+                                     ; set text to space
663
        leax    -1,x                            ; decrement x
664
        bne             cs1
665
        ldb             COREID                  ; update colors only if we have focus
666
        cmpb    IOFocusID
667
        bra             cs3
668
        ldy             #TEXTSCR+$2000
669
;       lda             CharColor
670
        lda             #$0CE
671
        tfr             u,x                                     ; get back count
672
cs2:
673
        sta             ,y+
674 13 robfinch
        dex                                                             ; decrement x
675 4 robfinch
        bne             cs2
676
cs3:
677
        puls    d,x,y,u,pc
678
 
679
;------------------------------------------------------------------------------
680
; Scroll text on the screen upwards
681
;
682
; Modifies:
683
;               none
684
;------------------------------------------------------------------------------
685
 
686
ScrollUp:
687
        pshs    d,x,y,u
688 15 robfinch
        ldy             #(COLS*ROWS-1)/2        ; y = num chars/2 to move
689 4 robfinch
        bsr             GetScreenLocation
690
        tfr             d,x
691
        tfr             d,u
692 15 robfinch
        leax    COLS,x          ; x = index to source row
693 4 robfinch
scrup1:
694
        ldd             ,x++                    ; move 2 characters
695
        std             ,u++
696 13 robfinch
        dey
697 4 robfinch
        bne             scrup1
698 15 robfinch
        lda             #ROWS-1
699 4 robfinch
        bsr             BlankLine
700
        puls    d,x,y,u,pc
701
 
702
;------------------------------------------------------------------------------
703
; Blank out a line on the display
704
;
705
; Modifies:
706
;               none
707
; Parameters:
708
;       acca = line number to blank
709
;------------------------------------------------------------------------------
710
 
711
BlankLine:
712
        pshs    d,x
713
        pshs    a
714
        bsr             GetScreenLocation
715
        tfr             d,x
716
        puls    a
717 15 robfinch
        ldb             #COLS   ; b = # chars to blank out from video controller
718 4 robfinch
        mul                                     ; d = screen index (row# * #cols)
719
        leax    d,x
720
        lda             #' '
721 15 robfinch
        ldb             #COLS   ; b = # chars to blank out from video controller
722 4 robfinch
blnkln1:
723
        sta             ,x+
724
        decb
725
        bne             blnkln1
726
        puls    d,x,pc
727
 
728
;------------------------------------------------------------------------------
729
; Get the location of the screen memory. The location
730
; depends on whether or not the task has the output focus.
731
;
732
; Modifies:
733
;               d
734
; Retuns:
735
;               d = screen location
736
;------------------------------------------------------------------------------
737
 
738
GetScreenLocation:
739
        lda             COREID                  ; which core are we?
740
        cmpa    IOFocusID               ; do we have the IO focus
741
        bne             gsl1                            ; no, go pick virtual screen address
742
        ldd             #TEXTSCR                ; yes, we update the real screen
743
        rts
744
gsl1:
745
        ldd             #$7800
746
        rts
747
 
748
;------------------------------------------------------------------------------
749
; HomeCursor
750
; Set the cursor location to the top left of the screen.
751
;
752
; Modifies:
753
;               none
754
;------------------------------------------------------------------------------
755
 
756
HomeCursor:
757
        pshs    d,x
758
        clr             CursorRow
759
        clr             CursorCol
760
        ldb             COREID
761
        cmpb    IOFocusID
762
        bne             hc1
763
        clra
764
        sta             TEXTREG+TEXT_CURPOS
765
hc1:
766
        puls    d,x,pc
767
 
768
;------------------------------------------------------------------------------
769
; Update the cursor position in the text controller based on the
770
;  CursorRow,CursorCol.
771
;
772
; Modifies:
773
;               none
774
;------------------------------------------------------------------------------
775
;
776
UpdateCursorPos:
777
        pshs    d,x
778
        ldb             COREID                          ; update cursor position in text controller
779
        cmpb    IOFocusID                       ; only for the task with the output focus
780
        bne             ucp1
781
        lda             CursorRow
782
        anda    #$3F                                    ; limit of 63 rows
783
        ldb             TEXTREG+TEXT_COLS
784
        mul
785
        tfr             d,x
786
        ldb             CursorCol
787
        abx
788
        stx             TEXTREG+TEXT_CURPOS
789
ucp1:
790
        puls    d,x,pc
791
 
792
;------------------------------------------------------------------------------
793
; Calculate screen memory location from CursorRow,CursorCol.
794
; Also refreshes the cursor location.
795
;
796
; Modifies:
797
;               d
798
; Returns:
799
;       d = screen location
800
;------------------------------------------------------------------------------
801
;
802
CalcScreenLoc:
803
        pshs    x
804
        lda             CursorRow
805 15 robfinch
        ldb             #COLS
806 4 robfinch
        mul
807
        tfr             d,x
808
        ldb             CursorCol
809
        abx
810
        ldb             COREID                          ; update cursor position in text controller
811
        cmpb    IOFocusID                       ; only for the task with the output focus
812
        bne             csl1
813
        stx             TEXTREG+TEXT_CURPOS
814
csl1:
815
        bsr             GetScreenLocation
816
        leax    d,x
817
        tfr             x,d
818
        puls    x,pc
819
 
820
;------------------------------------------------------------------------------
821
; Display a character on the screen.
822
; If the task doesn't have the I/O focus then the character is written to
823
; the virtual screen.
824
;
825
; Modifies:
826
;               none
827
; Parameters:
828
;       accb = char to display
829
;------------------------------------------------------------------------------
830
;
831
DisplayChar:
832 13 robfinch
        lbsr    SerialPutChar
833 4 robfinch
        pshs    d,x
834
        cmpb    #CR                                     ; carriage return ?
835
        bne             dccr
836
        clr             CursorCol               ; just set cursor column to zero on a CR
837
        bsr             UpdateCursorPos
838
dcx14:
839 13 robfinch
        lbra            dcx4
840 4 robfinch
dccr:
841
        cmpb    #$91                            ; cursor right ?
842
        bne             dcx6
843
        lda             CursorCol
844 15 robfinch
        cmpa    #COLS
845 4 robfinch
        bhs             dcx7
846
        inca
847
        sta             CursorCol
848
dcx7:
849
        bsr             UpdateCursorPos
850
        puls    d,x,pc
851
dcx6:
852
        cmpb    #$90                            ; cursor up ?
853
        bne             dcx8
854
        lda             CursorRow
855
        beq             dcx7
856
        deca
857
        sta             CursorRow
858
        bra             dcx7
859
dcx8:
860
        cmpb    #$93                            ; cursor left ?
861
        bne             dcx9
862
        lda             CursorCol
863
        beq             dcx7
864
        deca
865
        sta             CursorCol
866
        bra             dcx7
867
dcx9:
868
        cmpb    #$92                            ; cursor down ?
869
        bne             dcx10
870
        lda             CursorRow
871 15 robfinch
        cmpa    #ROWS
872 4 robfinch
        beq             dcx7
873
        inca
874
        sta             CursorRow
875
        bra             dcx7
876
dcx10:
877
        cmpb    #$94                            ; cursor home ?
878
        bne             dcx11
879
        lda             CursorCol
880
        beq             dcx12
881
        clr             CursorCol
882
        bra             dcx7
883
dcx12:
884
        clr             CursorRow
885
        bra             dcx7
886
dcx11:
887
        cmpb    #$99                            ; delete ?
888
        bne             dcx13
889
        bsr             CalcScreenLoc
890
        tfr             d,x
891
        lda             CursorCol               ; acc = cursor column
892
        bra             dcx5
893
dcx13
894
        cmpb    #CTRLH                  ; backspace ?
895
        bne             dcx3
896
        lda             CursorCol
897
        beq             dcx4
898
        deca
899
        sta             CursorCol
900
        bsr             CalcScreenLoc
901 13 robfinch
        tfr             d,x
902
        lda             CursorCol
903 4 robfinch
dcx5:
904
        ldb             1,x
905
        stb             ,x++
906
        inca
907 15 robfinch
        cmpa    #COLS
908 4 robfinch
        blo             dcx5
909
        ldb             #' '
910 13 robfinch
        dex
911 4 robfinch
        stb             ,x
912 13 robfinch
        bra             dcx4
913 4 robfinch
dcx3:
914
        cmpb    #LF                             ; linefeed ?
915
        beq             dclf
916
        pshs    b
917
        bsr     CalcScreenLoc
918
        tfr             d,x
919
        puls    b
920
        stb             ,x
921
        ; ToDo character color
922
;       lda             CharColor
923
;       sta             $2000,x
924
        bsr             IncCursorPos
925 13 robfinch
        bra             dcx4
926 4 robfinch
dclf:
927
        bsr             IncCursorRow
928
dcx4:
929
        puls    d,x,pc
930
 
931
;------------------------------------------------------------------------------
932
; Increment the cursor position, scroll the screen if needed.
933
;
934
; Modifies:
935
;               none
936
;------------------------------------------------------------------------------
937
 
938
IncCursorPos:
939
        pshs    d,x
940
        lda             CursorCol
941
        inca
942
        sta             CursorCol
943 15 robfinch
        cmpa    #COLS
944 4 robfinch
        blo             icc1
945
        clr             CursorCol               ; column = 0
946
        bra             icr1
947
IncCursorRow:
948
        pshs    d,x
949
icr1:
950
        lda             CursorRow
951
        inca
952
        sta             CursorRow
953 15 robfinch
        cmpa    #ROWS
954 4 robfinch
        blo             icc1
955
        deca                                                    ; backup the cursor row, we are scrolling up
956
        sta             CursorRow
957
        bsr             ScrollUp
958
icc1:
959
        bsr             UpdateCursorPos
960
icc2:
961
        puls    d,x,pc
962
 
963
;------------------------------------------------------------------------------
964
; Display a string on the screen.
965
;
966
; Modifies:
967
;               none
968
; Parameters:
969
;               d = pointer to string
970
;------------------------------------------------------------------------------
971
;
972
DisplayString:
973
        pshs    d,x
974
        tfr             d,x
975 13 robfinch
dspj2:                                          ; lock semaphore for access
976
        lda             OUTSEMA+1
977
        beq             dspj2
978 4 robfinch
dspj1B:
979
        ldb             ,x+                             ; move string char into acc
980
        beq             dsretB          ; is it end of string ?
981 13 robfinch
        lbsr    OUTCH                   ; display character
982 4 robfinch
        bra             dspj1B
983
dsretB:
984 13 robfinch
        clr             OUTSEMA+1       ; unlock semaphore
985 4 robfinch
        puls    d,x,pc
986
 
987
DisplayStringCRLF:
988
        pshs    d
989
        bsr             DisplayString
990
        ldb             #CR
991 13 robfinch
        lbsr    OUTCH
992 4 robfinch
        ldb             #LF
993 13 robfinch
        lbsr    OUTCH
994 4 robfinch
        puls    d,pc
995
 
996
;
997
; PRINT CR, LF, STRING
998
;
999
PSTRNG
1000
        BSR             PCRLF
1001
        BRA             PDATA
1002
PCRLF
1003
        PSHS    X
1004
        LDX             #CRLFST
1005
        BSR             PDATA
1006
        PULS    X
1007
        RTS
1008
 
1009
PRINT
1010
        JSR             OUTCH
1011
PDATA
1012
        LDB             ,X+
1013
        CMPB    #$04
1014
        BNE             PRINT
1015
        RTS
1016
 
1017
CRLFST
1018
        fcb     CR,LF,4
1019
 
1020
DispDWordAsHex:
1021
        bsr             DispWordAsHex
1022
        exg             d,x
1023
        bsr             DispWordAsHex
1024
        exg             d,x
1025
        rts
1026
 
1027
DispWordAsHex:
1028
        exg             a,b
1029
        bsr             DispByteAsHex
1030
        exg             a,b
1031
        bsr             DispByteAsHex
1032
        rts
1033
 
1034
DispByteAsHex:
1035
  pshs  b
1036
        lsrb
1037
        lsrb
1038
        lsrb
1039
        lsrb
1040
        lsrb
1041
        lsrb
1042
        lsrb
1043
        lsrb
1044
        bsr             DispNyb
1045
        puls    b
1046
        pshs    b
1047
        lsrb
1048
        lsrb
1049
        lsrb
1050
        lsrb
1051
        bsr             DispNyb
1052
        puls    b
1053
 
1054
DispNyb
1055
        pshs    b
1056
        andb    #$0F
1057
        cmpb    #10
1058
        blo             DispNyb1
1059
        addb    #'A'-10
1060 13 robfinch
        lbsr    OUTCH
1061 4 robfinch
        puls    b,pc
1062
DispNyb1
1063
        addb    #'0'
1064 13 robfinch
        lbsr    OUTCH
1065 4 robfinch
        puls    b,pc
1066
 
1067
;==============================================================================
1068 13 robfinch
; Timer
1069
;==============================================================================
1070
 
1071
OPT INCLUDE "d:\cores2022\rf6809\software\boot\timer.asm"
1072
OPT INCLUDE "d:\cores2022\rf6809\software\boot\i2c.asm"
1073
OPT INCLUDE "d:\cores2022\rf6809\software\boot\rtc_driver.asm"
1074
 
1075
;==============================================================================
1076 4 robfinch
; Keyboard I/O
1077
;==============================================================================
1078
 
1079
OPT INCLUDE "d:\cores2022\rf6809\software\boot\scancodes.asm"
1080
OPT INCLUDE "d:\cores2022\rf6809\software\boot\keyboard.asm"
1081
 
1082
        fcb             "KEYBOARD"
1083
        fcw             KeybdOpen
1084
        fcw             KeybdClose
1085
        fcw             KeybdRead
1086
        fcw             KeybdWrite
1087
        fcw             KeybdSeek
1088
 
1089
; Keyboard Open:
1090
; Initialize the keyboard buffer head and tail indexes
1091
;
1092
KeybdOpen:
1093
        rts
1094
 
1095
; Keyboard Close:
1096
; Nothing to do except maybe clear the keyboard buffer
1097
;
1098
KeybdClose:
1099
        rts
1100
;
1101
KeybdRead:
1102
        rts
1103
;
1104
KeybdWrite:
1105
        rts
1106
 
1107
KeybdSeek:
1108
        rts
1109
 
1110 13 robfinch
;==============================================================================
1111
; Serial I/O
1112
;==============================================================================
1113
 
1114
OPT INCLUDE "d:\cores2022\rf6809\software\boot\serial.asm"
1115
 
1116 4 robfinch
;------------------------------------------------------------------------------
1117
; Check if there is a keyboard character available. If so return true (<0)
1118
; otherwise return false (0) in accb.
1119
;------------------------------------------------------------------------------
1120
;
1121
KeybdCheckForKeyDirect:
1122
        bra             DBGCheckForKey
1123
 
1124
;------------------------------------------------------------------------------
1125
;------------------------------------------------------------------------------
1126
INCH:
1127 13 robfinch
        pshs    b
1128
INCH2:
1129
        ldb             COREID
1130
        cmpb    IOFocusID       ; if we do not have focus, block
1131
        bne             INCH2
1132
;       ldb             #$800                   ; block if no key available, get scancode directly
1133
;       bra             GetKey
1134
;       jsr             [CharInVec]     ; vector is being overwritten somehow
1135
        lbsr    SerialPeekCharDirect
1136
        tsta
1137
        bmi             INCH1                   ; block if no key available
1138
        leas    1,s                             ; get rid of blocking status
1139
        rts
1140
INCH1:
1141
        puls    b                                       ; check blocking status
1142
        tstb
1143
        bmi     INCH                    ; if blocking, loop
1144
        ldd             #-1                             ; return -1 if no char available
1145
        rts
1146 4 robfinch
 
1147
INCHE:
1148
        bsr             INCH
1149
        bra             INCHEK3
1150
 
1151
INCHEK:
1152
        bsr             INCH
1153
        tst             KeybdEcho
1154
        beq             INCHEK1
1155
INCHEK3:
1156
        cmpa    #CR
1157
        bne             INCHEK2
1158
        lbsr            CRLF
1159
        bra             INCHEK1
1160
INCHEK2:
1161 13 robfinch
        lbsr    DisplayChar
1162 4 robfinch
INCHEK1:
1163
        rts
1164
 
1165
OUTCH:
1166
        jmp             [CharOutVec]
1167
 
1168
;------------------------------------------------------------------------------
1169
; r1 0=echo off, non-zero = echo on
1170
;------------------------------------------------------------------------------
1171
;
1172
SetKeyboardEcho:
1173
        stb             KeybdEcho
1174
        rts
1175
 
1176
 
1177
;------------------------------------------------------------------------------
1178
; Parameters:
1179
;               x,d     bitmap of sprites to enable
1180
;------------------------------------------------------------------------------
1181
 
1182
ShowSprites:
1183
        stx             SPRITE_CTRL+SPRITE_EN
1184
        std             SPRITE_CTRL+SPRITE_EN+2
1185
        rts
1186
 
1187
;==============================================================================
1188 13 robfinch
; Femtiki Operating System.
1189
;==============================================================================
1190
 
1191
OSCallTbl:
1192
        fcw             0
1193
        fcw             0
1194
        fcw             0
1195
        fcw             0
1196
        fcw             0
1197
        fcw             0
1198
        fcw             0
1199
        fcw             0
1200
        fcw             0
1201
        fcw             0
1202
        fcw             0
1203
        fcw             0
1204
        fcw             0
1205
        fcw             0
1206
        fcw             0
1207
        fcw             0
1208
        fcw             0
1209
        fcw             0
1210
        fcw             0
1211
        fcw             0
1212
        fcw             0
1213
        fcw             0
1214
        fcw             ReleaseIOFocus
1215
        fcw             0
1216
        fcw             RequestIOFocus
1217
 
1218 15 robfinch
NumOSFuncs      EQU     (*-OSCallTbl)/2
1219 13 robfinch
 
1220
RequestIOFocus:
1221
        ldb             COREID
1222
        ldx             #IOFocusList
1223
        abx
1224
        sta             ,x
1225
        tst             IOFocusID
1226
        lbne    oscx
1227
        stb             IOFocusID
1228
        lbra    oscx
1229
 
1230
ReleaseIOFocus:
1231
        ldb             COREID
1232
        ldx             #IOFocusList
1233
        abx
1234
        clr             ,x                                              ; clear the request indicator
1235
        lbsr    CopyScreenToVirtualScreen
1236
        cmpb    IOFocusID                       ; are we the one with the focus?
1237
        lbne    oscx
1238
        ; We had the focus, so now a new core needs the focus.
1239
        ; Search the focus list for a requestor. If no requester
1240
        ; is found, give focus to core #1.
1241
        lda             #15
1242
riof2:
1243
        incb
1244
        andb    #15
1245
        abx
1246
        tst             ,x
1247
        bne             riof1
1248
        deca
1249
        bne             riof2
1250
        ; If no focus is requested by anyone, give to core #1
1251
        ldb             #1
1252
        lda             #24
1253
        sta             ,x
1254
riof1:
1255
        stb             IOFocusID
1256
        lbsr    CopyVirtualScreenToScreen
1257
        lbra    oscx
1258
 
1259
 
1260
;==============================================================================
1261
;==============================================================================
1262
 
1263 15 robfinch
;------------------------------------------------------------------------------
1264
; Seed the random number generator. All channels are seeded with the same
1265
; value.
1266
;
1267
; Parameters:
1268
;               d = 'z' part of seed
1269
;               x = 'w' part of seed
1270
; Returns:
1271
;               none
1272
;------------------------------------------------------------------------------
1273
 
1274
mon_srand:
1275
        ldy     #0
1276
mon_srand1:
1277
        sty     PRNG+4                          ; select channel
1278
        clr     PRNG+8
1279
        clr PRNG+9
1280
        std     PRNG+10                         ; update low half of value
1281
        clr PRNG+12
1282
        clr PRNG+13
1283
        stx     PRNG+14                         ; update low half of value
1284
        iny
1285
        cmpy    #$400                           ; 1k channels
1286
        blo             mon_srand1
1287
        rts
1288
 
1289
;------------------------------------------------------------------------------
1290
; Get a random number and generate the next one.
1291
;
1292
; Parameters:
1293
;               d = channel to use
1294
; Returns:
1295
;               x,d = 36 bit random value
1296
;------------------------------------------------------------------------------
1297
 
1298
mon_rand:
1299
        std     PRNG+4                          ; select channel
1300
        ldx     PRNG+0
1301
        ldd     PRNG+2
1302
        stb     PRNG+3                          ; trigger calc of next number
1303
        rts
1304
 
1305 13 robfinch
;==============================================================================
1306 4 robfinch
; System Monitor
1307
;==============================================================================
1308 13 robfinch
 
1309 15 robfinch
; Command Tables
1310
 
1311
cmdTable1:
1312
        fcb             '<','>'+$800
1313
        fcb             'b','s'+$800
1314
        fcb             'b','c'+$800
1315
        fcb             'D','R'+$800
1316
        fcb             'D'+$800
1317
        fcb             ':'+$800
1318
        fcb             "FI",'G'+$800
1319
        fcb             "FI",'L'+$800
1320
        fcb             'F','L'+$800
1321
        fcb             'J'+$800
1322
        fcb             "RAMTES",'T'+$800
1323
        fcb             "SP",'D'+$800
1324
        fcb             "TI",'R'+$800
1325
        fcb             'U'+$800
1326
        fcb             "exi",'t'+$800
1327
        fcb             '?'+$800
1328
        fcb             "CL",'S'+$800
1329
        fcw             0
1330
 
1331
cmdTable2:
1332
        fcw             Redirect
1333
        fcw             ArmBreakpoint
1334
        fcw             DisarmBreakpoint
1335
        fcw             DumpRegs
1336
        fcw             DumpMemory
1337
        fcw             EditMemory
1338
        fcw             $FE0000                                 ; FIG forth
1339
        fcw             FillMemory
1340
        fcw             DumpIOFocusList
1341
        fcw             jump_to_code
1342
        fcw             dramtest
1343
        fcw             $FF8000                                 ; sprite demo
1344
        fcw             rtc_read
1345
        fcw             $FF8003                                 ; unassembler
1346
        fcw             xitMonitor
1347
        fcw             PromptHelp
1348
        fcw             PromptClearscreen
1349
 
1350 13 robfinch
CmdPrompt:
1351
        lbsr    CRLF
1352
        ldb             #'$'
1353
        lbsr    OUTCH
1354
        lbra    OUTCH
1355
 
1356
msgF09Starting:
1357
        fcb             "Femtiki F09 Multi-core OS Starting",CR,LF,0
1358
 
1359 4 robfinch
MonitorStart:
1360 15 robfinch
        clr             BreakpointFlag
1361
        clr             NumSetBreakpoints
1362
        ldd             #123
1363
        ldx             #654
1364
        lbsr    mon_srand
1365 13 robfinch
        ldd             #msgF09Starting
1366
        lbsr    DisplayString
1367 4 robfinch
        ldd             #HelpMsg
1368 13 robfinch
        lbsr    DisplayString
1369
        ldd             #CmdPrompt
1370
        std             CmdPromptJI
1371 14 robfinch
        ldd             #DisplayErr
1372
        std             MonErrVec
1373
        ldd             #$63FF                  ; default app stack
1374
        std             mon_SSAVE
1375 15 robfinch
        clr             mon_DPRSAVE     ;
1376
        tfr             ccr,a
1377
        sta             mon_CCRSAVE
1378
        clr             mon_PCSAVE
1379
        ldd             #Monitor
1380
        std             mon_PCSAVE+1
1381
        clr             mon_XSAVE
1382
        clr             mon_YSAVE
1383
        clr             mon_USAVE
1384 4 robfinch
Monitor:
1385 13 robfinch
        leas    $6FFF                           ; reset stack pointer
1386 4 robfinch
        clrb                                                    ; turn off keyboard echo
1387 13 robfinch
        lbsr    SetKeyboardEcho
1388
        ; Reset IO vectors
1389
        ldd             #SerialPeekCharDirect
1390
        std             CharInVec
1391
        ldd             #DisplayChar
1392
        std             CharOutVec
1393
        ldd             #CmdPrompt
1394
        std             CmdPromptJI
1395 4 robfinch
;       jsr             RequestIOFocus
1396
PromptLn:
1397 13 robfinch
        jsr             [CmdPromptJI]
1398 4 robfinch
 
1399
; Get characters until a CR is keyed
1400
 
1401
Prompt3:
1402
        ldd             #-1                                     ; block until key present
1403 13 robfinch
        lbsr    INCH
1404 15 robfinch
        cmpb    #CR                                     ; carriage return?
1405
        beq             Prompt1
1406
        lbsr    OUTCH                           ; spit out the character
1407
        bra             Prompt3                 ; and keep going
1408 4 robfinch
 
1409
; Process the screen line that the CR was keyed on
1410
;
1411
Prompt1:
1412
        ldd             #$5050
1413
        std             LEDS
1414 13 robfinch
;       ldb             RunningID
1415
;       cmpb    #61
1416
;       bhi             Prompt3
1417 4 robfinch
        clr             CursorCol                       ; go back to the start of the line
1418 13 robfinch
        lbsr    CalcScreenLoc   ; calc screen memory location
1419 4 robfinch
        tfr             d,y
1420 13 robfinch
skipDollar:
1421 4 robfinch
        bsr             MonGetNonSpace
1422
        cmpb    #'$'
1423 13 robfinch
        beq             skipDollar              ; skip over '$' prompt character
1424 4 robfinch
 
1425 15 robfinch
; Dispatch based on command
1426 4 robfinch
;
1427 15 robfinch
        dey
1428
        tfr             y,u                                                     ; save off input position
1429
        clrb
1430
        ldx             #cmdTable1
1431
parseCmd1:
1432
        lda             ,y+                                                     ; get input character
1433
        tst             ,x                                                      ; test for end of command
1434
        bmi             endOfWord                               ;
1435
        cmpa    ,x+                                                     ; does input match command?
1436
        beq             parseCmd1
1437
scanNextWord:
1438
        tst             ,x+
1439
        beq             Monitor                                 ; if end of table reached, not a command
1440
        bpl             scanNextWord
1441
        incb
1442
        tfr             u,y                                                     ; reset input pointer
1443
        bra             parseCmd1                               ; try again
1444
endOfWord:
1445
        eora    ,x
1446
        asla
1447
        bne             scanNextWord
1448
        ; we found the command in the table
1449
        aslb                                                                    ; b = word index
1450
        ldx             #cmdTable2
1451
        jmp             [b,x]                                           ; execute command
1452
 
1453
Redirect:
1454 13 robfinch
        bsr             MonGetch
1455
        cmpb    #'s'
1456
        bne             Prompt2a
1457
        ldd             #SerialPeekCharDirect
1458
        std             CharInVec
1459
        ldd             #SerialPutChar
1460
        std             CharOutVec
1461
        bra             Monitor
1462
Prompt2a:
1463
        cmpb    #'c'
1464
        bne             Monitor
1465
        ldd             #GetKey
1466
        std             CharInVec
1467
        ldd             #DisplayChar
1468
        std             CharOutVec
1469
        bra             Monitor
1470 15 robfinch
 
1471 13 robfinch
PromptHelp:
1472 4 robfinch
        ldd             #HelpMsg
1473 13 robfinch
        lbsr    DisplayString
1474 4 robfinch
        bra             Monitor
1475 15 robfinch
 
1476
PromptClearscreen:
1477 13 robfinch
        lbsr    ClearScreen
1478
        lbsr    HomeCursor
1479 4 robfinch
        bra             Monitor
1480
 
1481
MonGetch:
1482
        ldb             ,y
1483 13 robfinch
        iny
1484 4 robfinch
        rts
1485
 
1486
MonGetNonSpace:
1487
        bsr             MonGetCh
1488
        cmpb    #' '
1489
        beq             MonGetNonSpace
1490
        rts
1491
 
1492
;------------------------------------------------------------------------------
1493
; Ignore blanks in the input
1494
; Y = text pointer
1495
; D destroyed
1496
;------------------------------------------------------------------------------
1497
;
1498
ignBlanks:
1499
ignBlanks1:
1500
        bsr             MonGetch
1501
        cmpb    #' '
1502
        beq             ignBlanks1
1503 13 robfinch
        dey
1504 4 robfinch
        rts
1505
 
1506
;------------------------------------------------------------------------------
1507 15 robfinch
; Multiply number in work area by 10.
1508 4 robfinch
;------------------------------------------------------------------------------
1509 15 robfinch
Times10:
1510
        ldd             mon_numwka              ; make a copy of the number
1511
        std             mon_numwka+8
1512
        ldd             mon_numwka+2
1513
        std             mon_numwka+10
1514
        asl             mon_numwka+3    ; shift left = *2
1515
        rol             mon_numwka+2
1516
        rol             mon_numwka+1
1517
        rol             mon_numwka+0
1518
        asl             mon_numwka+3    ; shift left = *4
1519
        rol             mon_numwka+2
1520
        rol             mon_numwka+1
1521
        rol             mon_numwka+0
1522
        ldd             mon_numwka+2    ; add in original value
1523
        addd    mon_numwka+10   ; = *5
1524
        ldb             mon_numwka+1
1525
        adcb    mon_numwka+9
1526
        stb             mon_numwka+1
1527
        lda             mon_numwka+0
1528
        adca    mon_numwka+8
1529
        sta             mon_numwka+0
1530
        asl             mon_numwka+3    ; shift left = * 10
1531
        rol             mon_numwka+2
1532
        rol             mon_numwka+1
1533
        rol             mon_numwka+0
1534
        rts
1535
 
1536
;------------------------------------------------------------------------------
1537
;------------------------------------------------------------------------------
1538 4 robfinch
GetTwoParams:
1539
        bsr             ignBlanks
1540
        bsr             GetHexNumber    ; get start address of dump
1541
        ldd             mon_numwka
1542
        std             mon_r1
1543
        ldd             mon_numwka+2
1544
        std             mon_r1+2
1545
        bsr             ignBlanks
1546
        bsr             GetHexNumber    ; get end address of dump
1547
        ldd             mon_numwka
1548
        std             mon_r2
1549
        ldd             mon_numwka+2
1550
        std             mon_r2+2
1551
        rts
1552
 
1553
;------------------------------------------------------------------------------
1554
; Get a range, the end must be greater or equal to the start.
1555
;------------------------------------------------------------------------------
1556
GetRange:
1557
        bsr             GetTwoParams
1558
        ldd             mon_r2+2
1559
        subd    mon_r1+2
1560
        ldd             mon_r2
1561
        sbcb    mon_r1+1
1562
        sbca    mon_r1
1563 14 robfinch
        lbcc    grng1
1564
        jsr             [MonErrVec]
1565
        lbra    Monitor
1566
grng1:
1567 4 robfinch
        rts
1568
 
1569
shl_numwka:
1570
        asl             mon_numwka+3
1571
        rol             mon_numwka+2
1572
        rol             mon_numwka+1
1573
        rol             mon_numwka
1574
        rts
1575
 
1576
;------------------------------------------------------------------------------
1577 13 robfinch
; Get a hexidecimal number. Maximum of twelve digits.
1578
;
1579
; Modifies:
1580
;       Y = text pointer (updated)
1581
;       D = number of digits
1582
;       mon_numwka contains number
1583 4 robfinch
;------------------------------------------------------------------------------
1584
;
1585
GetHexNumber:
1586
        clrd
1587 13 robfinch
        std             mon_numwka      ; zero out work area
1588 4 robfinch
        std             mon_numwka+2
1589
        pshs    x
1590 13 robfinch
        ldx             #0                                      ; max 12 eight digits
1591 4 robfinch
gthxn2:
1592
        bsr             MonGetch
1593
        bsr             AsciiToHexNybble
1594
        cmpb    #-1
1595
        beq             gthxn1
1596
        bsr             shl_numwka
1597
        bsr             shl_numwka
1598
        bsr             shl_numwka
1599
        bsr             shl_numwka
1600
        andb    #$0f
1601
        orb             mon_numwka+3
1602
        stb             mon_numwka+3
1603
        inx
1604 13 robfinch
        cmpx    #12
1605 4 robfinch
        blo             gthxn2
1606
gthxn1:
1607
        tfr             x,d
1608
        puls    x,pc
1609
 
1610
;GetDecNumber:
1611
;       phx
1612
;       push    r4
1613
;       push    r5
1614
;       ldx             #0
1615
;       ld              r4,#10
1616
;       ld              r5,#10
1617
;gtdcn2:
1618
;       jsr             MonGetch
1619
;       jsr             AsciiToDecNybble
1620
;       cmp             #-1
1621
;       beq             gtdcn1
1622
;       mul             r2,r2,r5
1623
;       add             r2,r1
1624
;       dec             r4
1625
;       bne             gtdcn2
1626
;gtdcn1:
1627
;       txa
1628
;       pop             r5
1629
;       pop             r4
1630
;       plx
1631
;       rts
1632
 
1633
;------------------------------------------------------------------------------
1634
; Convert ASCII character in the range '0' to '9', 'a' to 'f' or 'A' to 'F'
1635
; to a hex nybble.
1636
;------------------------------------------------------------------------------
1637
;
1638
AsciiToHexNybble:
1639
        cmpb    #'0'
1640 13 robfinch
        blo             gthx3
1641
        cmpb    #'9'
1642
        bhi             gthx5
1643 4 robfinch
        subb    #'0'
1644
        rts
1645
gthx5:
1646
        cmpb    #'A'
1647 13 robfinch
        blo             gthx3
1648
        cmpb    #'F'
1649
        bhi             gthx6
1650 4 robfinch
        subb    #'A'
1651
        addb    #10
1652
        rts
1653
gthx6:
1654
        cmpb    #'a'
1655 13 robfinch
        blo             gthx3
1656
        cmpb    #'z'
1657
        bhi             gthx3
1658 4 robfinch
        subb    #'a'
1659
        addb    #10
1660
        rts
1661
gthx3:
1662
        ldb             #-1             ; not a hex number
1663
        rts
1664
 
1665
AsciiToDecNybble:
1666
        cmpb    #'0'
1667
        bcc             gtdc3
1668
        cmpb    #'9'+1
1669
        bcs             gtdc3
1670
        subb    #'0'
1671
        rts
1672
gtdc3:
1673
        ldb             #-1
1674
        rts
1675
 
1676
DisplayErr:
1677 14 robfinch
        ldd             #msgErr
1678
        lbsr    DisplayString
1679 4 robfinch
        jmp             Monitor
1680
 
1681
DisplayStringDX
1682
        std             Strptr
1683
        stx             Strptr+2
1684
        jsr             DisplayString
1685
        rts
1686
 
1687
msgErr:
1688
        fcb     "**Err",CR,LF,0
1689
 
1690
HelpMsg:
1691
        fcb             "? = Display help",CR,LF
1692
        fcb     "CLS = clear screen",CR,LF
1693 15 robfinch
        fcb     "bs = set breakpoint",CR,LF
1694
        fcb     "bc = clear breakpoint",CR,LF
1695 4 robfinch
;       db      "S = Boot from SD Card",CR,LF
1696 14 robfinch
        fcb     ": = Edit memory bytes",CR,LF
1697 4 robfinch
;       db      "L = Load sector",CR,LF
1698
;       db      "W = Write sector",CR,LF
1699
        fcb "DR = Dump registers",CR,LF
1700 13 robfinch
        fcb     "D = Dump memory",CR,LF
1701 15 robfinch
        fcb     "F = Fill memory",CR,LF
1702 14 robfinch
        fcb "FL = Dump I/O Focus List",CR,LF
1703 4 robfinch
        fcb "FIG = start FIG Forth",CR,LF
1704
;       db      "KILL n = kill task #n",CR,LF
1705
;       db      "B = start tiny basic",CR,LF
1706
;       db      "b = start EhBasic 6502",CR,LF
1707
        fcb     "J = Jump to code",CR,LF
1708
        fcb "RAM = test RAM",CR,LF
1709
;       db      "R[n] = Set register value",CR,LF
1710
;       db      "r = random lines - test bitmap",CR,LF
1711
;       db      "e = ethernet test",CR,LF
1712 13 robfinch
        fcb     "s = serial output test",CR,LF
1713 15 robfinch
        fcb     "SP = sprite demo",CR,LF
1714 4 robfinch
;       db      "T = Dump task list",CR,LF
1715
;       db      "TO = Dump timeout list",CR,LF
1716 13 robfinch
        fcb     "TI = display date/time",CR,LF
1717 4 robfinch
;       db      "TEMP = display temperature",CR,LF
1718 14 robfinch
        fcb     "U = unassemble",CR,LF
1719 15 robfinch
;       db      "P = Piano",CR,LF
1720
        fcb     "x = exit monitor",CR,LF
1721 4 robfinch
        fcb             0
1722
 
1723
msgRegHeadings
1724 13 robfinch
        fcb     CR,LF,"  D/AB     X      Y      U      S       PC    DP  CCR",CR,LF,0
1725 4 robfinch
 
1726
nHEX4:
1727
        jsr             HEX4
1728
        rts
1729
 
1730
nXBLANK:
1731
        ldb             #' '
1732 13 robfinch
        lbra    OUTCH
1733 4 robfinch
 
1734 13 robfinch
;------------------------------------------------------------------------------
1735
; Dump Memory
1736
;
1737
; Usage:
1738 14 robfinch
;       $D FFFC12 FFFC20
1739 13 robfinch
;
1740
; Dump formatted to look like:
1741
;               :FFFC12 012 012 012 012 555 666 777 888
1742
;
1743
;------------------------------------------------------------------------------
1744
 
1745
DumpMemory:
1746 14 robfinch
        bsr             GetRange
1747 13 robfinch
        ldy             #0
1748
        ldy             mon_r1+2
1749
dmpm2:
1750
        lbsr    CRLF
1751
        ldb             #':'
1752
        lbsr    OUTCH
1753
        tfr             y,d
1754
        ;addd   mon_r1+2                                        ; output the address
1755
        lbsr    DispWordAsHex
1756
        ldb             #' '
1757
        lbsr    OUTCH
1758
        ldx             #8                                                              ; number of bytes to display
1759
dmpm1:
1760
;       ldb             far [mon_r1+1],y
1761
        ;ldb            [mon_r1+2],y
1762
        ldb             ,y
1763
        iny
1764
        lbsr    DispByteAsHex                   ; display byte
1765
        ldb             #' '                                                    ; followed by a space
1766
        lbsr    OUTCH
1767
        clrb
1768
        clra
1769
        lbsr    INCH
1770
        cmpb    #CTRLC
1771
        beq             dmpm3
1772
        dex
1773
        bne             dmpm1
1774
        ; Now output ascii
1775
        ldb             #' '
1776
        lbsr    OUTCH
1777
        ldx             #8                                                              ; 8 chars to output
1778
        leay    -8,y                                                    ; backup pointer
1779
dmpm5:
1780
;       ldb             far [mon_r1+1],y        ; get the char
1781
;       ldb             [mon_r1+2],y                    ; get the char
1782
        ldb             ,y
1783
        cmpb    #$20                                                    ; is it a control char?
1784
        bhs             dmpm4
1785
        ldb             #'.'
1786
dmpm4:
1787
        lbsr    OUTCH
1788
        iny
1789
        dex
1790
        bne             dmpm5
1791
        cmpy    mon_r2+2
1792
        blo             dmpm2
1793
dmpm3:
1794
        lbsr    CRLF
1795
        lbra    Monitor
1796
 
1797
;------------------------------------------------------------------------------
1798 14 robfinch
; Edit Memory
1799
;
1800
; Usage:
1801
;       $$:FFFC12 8 "Hello World!" 0
1802
;
1803
; Dump formatted to look like:
1804
;               :FFFC12 012 012 012 012 555 666 777 888
1805
;
1806
;------------------------------------------------------------------------------
1807
 
1808
EditMemory:
1809
        ldu             #8                                              ; set max byte count
1810
        lbsr    GetHexNumber    ; get the start address
1811
        ldx             mon_numwka+2
1812
EditMem2:
1813
        lbsr    ignBlanks                       ; skip over blanks
1814
        lbsr    GetHexNumber    ; get the byte value
1815
        tstb                                                            ; check for valid value
1816 15 robfinch
        beq             EditMem1                        ; if invalid, quit
1817 14 robfinch
        ldb             mon_numwka+3    ; get value
1818
        stb             ,x+                                             ; update memory at address
1819
        leau    -1,u                                    ; decremeent byte count
1820
        cmpu    #0
1821
        bne             EditMem2                        ; go back for annother byte
1822
EditMem1:
1823
        lbsr    MonGetch                        ; see if a string is being entered
1824
        cmpb    #'"'
1825
        bne             EditMem3                        ; no string, we're done
1826
        ldu             #40                                             ; string must be less than 40 chars
1827
EditMem4:
1828
        lbsr    MonGetch                        ; look for close quote
1829
        cmpb    #'"'
1830
        bne             EditMem6                        ; end of string?
1831
        ldu             #8                                              ; reset the byte count
1832
        bra             EditMem2
1833
EditMem6:
1834
        stb             ,x+                                             ; store the character in memory
1835
        leau    -1,u                                    ; decrement byte count
1836
        cmpu    #0
1837
        bhi             EditMem4                        ; max 40 chars
1838
EditMem3:
1839
        lbra    Monitor
1840
 
1841
 
1842
;------------------------------------------------------------------------------
1843 15 robfinch
; Fill Memory
1844
;
1845
; Usage:
1846
;       $$F FFFC12 FFFC30 89F
1847
;
1848
;------------------------------------------------------------------------------
1849
 
1850
FillMemory:
1851
        lbsr    GetRange                        ; get address range to fill
1852
        lbsr    ignBlanks
1853
        lbsr    GetHexNumber    ; get target byte to write
1854
        ldb             mon_numwka+3
1855
        ldx             mon_r1+2
1856
        clra
1857
fillm1:                                                         ; Check for a CTRL-C every page of memory
1858
        tsta
1859
        bne             fillm2
1860
        clrb                                                            ; we want a non-blocking check
1861
        clra
1862
        lbsr    INCH
1863
        cmpb    #CTRLC
1864
        lbeq    Monitor
1865
        ldb             mon_numwka+3    ; reset target byte
1866
fillm2:
1867
        stb             ,x+
1868
        cmpx    mon_r2+2
1869
        bls             fillm1
1870
fillm3:
1871
        lbra    Monitor
1872
 
1873
;------------------------------------------------------------------------------
1874 13 robfinch
; Dump Registers
1875
;
1876
;       Usage:
1877
;               $DR
1878
;------------------------------------------------------------------------------
1879
 
1880
DumpRegs:
1881
        ldd             #msgRegHeadings
1882
        lbsr    DisplayString
1883 4 robfinch
        bsr             nXBLANK
1884
        ldd             mon_DSAVE
1885
        bsr             nHEX4
1886
        bsr             nXBLANK
1887
        ldd             mon_XSAVE
1888
        bsr             nHEX4
1889
        bsr             nXBLANK
1890
        ldd             mon_YSAVE
1891
        bsr             nHEX4
1892
        bsr             nXBLANK
1893
        ldd             mon_USAVE
1894
        bsr             nHEX4
1895
        bsr             nXBLANK
1896
        ldd             mon_SSAVE
1897
        bsr             nHEX4
1898
        bsr             nXBLANK
1899 13 robfinch
        ldb             mon_PCSAVE+1
1900
        lbsr    DispByteAsHex
1901 4 robfinch
        ldd             mon_PCSAVE+2
1902
        bsr             nHEX4
1903
        bsr             nXBLANK
1904
        ldd             mon_DPRSAVE
1905
        jsr             HEX2
1906
        bsr             nXBLANK
1907
        lda             mon_CCRSAVE
1908 13 robfinch
        lbsr    HEX2
1909 4 robfinch
        bsr             nXBLANK
1910 13 robfinch
        lbra    Monitor
1911 4 robfinch
 
1912 13 robfinch
;------------------------------------------------------------------------------
1913 4 robfinch
; Jump to code
1914 13 robfinch
;
1915
; Registers are loaded with values from the monitor register save area before
1916
; the code is jumped to.
1917
;
1918
; J 
1919
;------------------------------------------------------------------------------
1920
 
1921 4 robfinch
jump_to_code:
1922
        bsr             GetHexNumber
1923
        sei
1924
        lds             mon_SSAVE
1925 14 robfinch
        ldd             #
1926 4 robfinch
        pshs    d
1927 13 robfinch
        ldb             #>jtc_exit
1928 4 robfinch
        pshs    b
1929 14 robfinch
        ldd             mon_numwka+2    ; get the address parameter
1930 4 robfinch
        pshs    d
1931 13 robfinch
        ldb             mon_numwka+1
1932
        pshs    b
1933 4 robfinch
        ldd             mon_USAVE
1934
        pshs    d
1935
        ldd             mon_YSAVE
1936
        pshs    d
1937
        ldd             mon_XSAVE
1938
        pshs    d
1939 15 robfinch
        lda             mon_DPRSAVE
1940 4 robfinch
        pshs    a
1941
        ldd             mon_DSAVE
1942
        pshs    d
1943
        lda             mon_CCRSAVE
1944
        pshs    a
1945
        puls    far ccr,d,dpr,x,y,u,pc
1946
jtc_exit:
1947 13 robfinch
        sts             >mon_SSAVE              ; need to use extended addressing, no direct page setting
1948
        leas    $6FFF                                   ; reset stack to system area, dont modify flags register!
1949
        pshs    ccr                                             ; now the stack can be used
1950
        pshs    a                                                       ; save acca register so we can use it
1951
        tfr             dpr,a                                   ; a = outgoing dpr value
1952
        sta             >mon_DPRSAVE    ; force extended addressing mode usage here dpr is not set
1953
        clra                                                            ; dpg register must be set to zero before values are
1954
        tfr             a,dpr                                   ; saved in the monitor register save area.
1955
        puls    a                                                       ; get back acca
1956
        std             mon_DSAVE                       ; save regsters, can use direct addressing now
1957 4 robfinch
        stx             mon_XSAVE
1958
        sty             mon_YSAVE
1959
        stu             mon_USAVE
1960 13 robfinch
        puls    a                                                       ; get back ccr
1961
        sta             mon_CCRSAVE             ; and save it too
1962
        ; Reset vectors in case they got toasted.
1963
        ldd             #SerialPeekCharDirect
1964
        std             CharInVec
1965
        ldd             #DisplayChar
1966
        std             CharOutVec
1967 14 robfinch
        ldd             DisplayErr
1968
        std             MonErrVec
1969 4 robfinch
        ; todo set according to coreid
1970 13 robfinch
        lbra    DumpRegs                        ; now go do a register dump
1971 4 robfinch
 
1972
;------------------------------------------------------------------------------
1973
;------------------------------------------------------------------------------
1974 14 robfinch
 
1975
DumpIOFocusList:
1976
        ldx             #0
1977
dfl2:
1978
        ldb             IOFocusList,x
1979
        cmpb    #24
1980
        bne             dfl1
1981
        tfr             x,d
1982
        lbsr    DispByteAsHex
1983
        ldb             #' '
1984
        lbsr    OUTCH
1985
dfl1:
1986
        inx
1987
        cmpx    #16
1988
        blo             dfl2
1989
        lbsr    CRLF
1990
        lbra    Monitor
1991
 
1992 15 robfinch
bootpg:
1993
        fcb             $000
1994
boot_stack:
1995
        fcw             $006FFF
1996
numBreakpoints:
1997
        fcb             8
1998
mon_rom_vectab:
1999
        fcw             mon_rom_vecs
2000
mon_rom_vecs:
2001
        fcw             Monitor                                         ; enter monitor program
2002
        fcw             INCH                                                    ; input a character
2003
        fcw             OUTCH                                                   ; output a character
2004
        fcw             CRLF                                                    ; output carriage-return, line feed
2005
        fcw             DisplayString
2006
        fcw             DispByteAsHex
2007
        fcw             DispWordAsHex
2008
        fcw             ShowSprites
2009
        fcw             mon_srand
2010
        fcw             mon_rand
2011
        fcw             0                                                                        ; operating system call
2012
        fcw             GetRange
2013 14 robfinch
 
2014 15 robfinch
NumFuncs        EQU     (*-mon_rom_vectab)/2
2015
 
2016 14 robfinch
;------------------------------------------------------------------------------
2017 15 robfinch
; SWI routine.
2018
;
2019
; SWI is used to call ROM monitor routines and process breakpoints.
2020
;
2021
;       swi
2022
;       fcb 
2023 14 robfinch
;------------------------------------------------------------------------------
2024 15 robfinch
 
2025
swi_rout:
2026
        ldb             bootpg,pcr                      ; reset direct page
2027
        tfr             b,dp
2028
swi_rout1:
2029
        ldu             11,s                                            ; get program counter (low order 2 bytes)
2030
        leau    -1,u                                            ; backup a byte
2031
        tst             BreakpointFlag  ; are we in breakpoint mode?
2032
        beq             swiNotBkpt
2033
        ldu             #Breakpoints
2034
        ldb             NumSetBreakpoints
2035
        beq             swiNotBkpt
2036
swi_rout2:
2037
        cmpu    ,y++
2038
        beq             processBreakpoint
2039
        decb
2040
        bne             swi_rout2
2041
swiNotBkpt:
2042
        clr             BreakpointFlag
2043
        pulu    d                                                               ; get function #, increment PC
2044
        cmpb    #NumFuncs
2045
        lbhi    DisplayErr
2046
        stu             11,s                                            ; save updated PC on stack
2047
        cmpb    #MF_OSCALL
2048
        beq             swiCallOS
2049
        aslb                                                                    ; 2 bytes per vector
2050
        ldx             mon_rom_vectab,pcr
2051
        abx
2052
        ldx             ,x
2053
        stx             jmpvec
2054
        sts             mon_SSAVE                               ; save the stack pointer
2055
        ldd             1,s                                                     ; get back D
2056
        ldx             4,s                                                     ; get back X
2057
        ldy             6,s                                                     ; get back Y
2058
        ldu             8,s                                                     ; get back U
2059
        lds             boot_stack,pcr  ; and use our own stack
2060
        jsr             [jmpvec]                                ; call the routine
2061
swi_rout3:
2062
        lds             mon_SSAVE                               ; restore stack
2063
        rti
2064
 
2065
processBreakpoint:
2066
        lda             ,s
2067
        sta             mon_CCRSAVE
2068
        ldd             1,s
2069
        std             mon_DSAVE
2070
        ldb             3,s
2071
        stb             mon_DPRSAVE
2072
        ldd             4,s
2073
        std             mon_XSAVE
2074
        ldd             6,s
2075
        std             mon_YSAVE
2076
        ldd             8,s
2077
        std             mon_USAVE
2078
        sts             mon_SSAVE
2079
        ldd             11,s
2080
        std             mon_PCSAVE
2081
        lds             boot_stack,pcr
2082
        ldd             #swi_rout3                      ; setup so monitor can return
2083
        pshs    d
2084
        bsr             DisarmAllBreakpoints
2085
        lbra    DumpRegs
2086
 
2087
xitMonitor:
2088
        bsr             ArmAllBreakpoints
2089
        rts
2090
 
2091
swiCallOS:
2092
        leau    1,u                                                     ; next byte is func number
2093
        ldb             ,u+
2094
        cmpb    #NumOSFuncs                     ; check for valid range
2095
        lbhi    DisplayErr
2096
        stu             11,s                                            ; save updateed PC on stack
2097
        aslb                                                                    ; compute vector address
2098
        ldx             #OSCallTbl
2099
        tst             b,x                                                     ; check for non-zero vector
2100
        beq             swi_rout3
2101
osc1:
2102
;       tst             OSSEMA+1                                ; wait for availability
2103
;       beq             osc1
2104
        jsr             [b,x]                                           ; call the OS routine
2105
oscx:
2106
        clr             OSSEMA+1
2107
        bra             swi_rout3
2108
 
2109
DisarmAllBreakpoints:
2110
        pshs    d,x,y
2111
        ldy             #0
2112
        clrb
2113
        ldx             #BreakpointBytes        ; x = breakpoint byte table address
2114
disarm2:
2115
        cmpb    #numBreakpoints         ; safety check
2116
        bhs             disarm1
2117
        cmpb    NumSetBreakpoints
2118
        bhs             disarm1
2119
        lda             b,x                                                             ; get memory byte
2120
        sta             [Breakpoints,y]         ; and store it back to memory
2121
        leay    2,y                                                             ; increment for next address
2122
        incb                                                                            ; increment to next byte
2123
        bra             disarm2                                         ; loop back
2124
disarm1:
2125
        puls    d,x,y,pc
2126
 
2127
ArmAllBreakpoints:
2128
        pshs    d,x,y
2129
        ldy             #0
2130
        clrb
2131
        ldx             #BreakpointBytes        ; x = breakpoint byte table address
2132
arm2:
2133
        cmpb    numBreakpoints          ; safety check
2134
        bhs             arm1
2135
        cmpb    NumSetBreakpoints
2136
        bhs             arm1
2137
        lda             [Breakpoints,y]         ; load byte at memory address
2138
        sta             b,x                                                             ; save in table
2139
        leay    2,y                                                             ; increment for next address
2140
        incb                                                                            ; increment to next byte
2141
        bra             arm2                                                    ; loop back
2142
arm1:
2143
        puls    d,x,y,pc
2144
 
2145
ArmBreakpoint:
2146
        pshs    d,x,y
2147
        lda             NumSetBreakpoints               ; check if too many breakpoints set
2148
        cmpa    numBreakpoints
2149
        lbhs    DisplayErr
2150
        lbsr    GetHexNumber                            ; get address parameter
2151
        ldb             NumSetBreakpoints               ; bv= number of set breakpoints
2152
        ldy             mon_numwka+2                            ; get address
2153
        lda             ,y                                                                      ; get byte at address
2154
        ldx             #BreakpointBytes                ; and store byte in a table
2155
        lda             #OPC_SWI                                                ; put a SWI instruction in place
2156
        sta             ,y
2157
        sta             b,x
2158
        ldx             #Breakpoints                            ; also store the address in a table
2159
        aslb                                                                                    ; index for 2 byte values
2160
        sty             b,x
2161
        lsrb                                                                                    ; size back to single byte
2162
        incb
2163
        stb             NumSetBreakpoints
2164
        puls    d,x,y,pc
2165
 
2166
DisarmBreakpoint:
2167
        pshs    d,x,y,u
2168
        lbsr    GetHexNumber
2169
        clrb
2170
        clrb
2171
        tfr             d,x                                                                     ; x = zero too
2172
disarm6:
2173
        cmpb    numBreakpoints                  ; no more than this many may be set
2174
        bhs             disarm4
2175
        cmpb    NumSetBreakpoints               ; number actually set
2176
        bhs             disarm4
2177
        ldy             Breakpoints,x                           ; y = breakpoint address
2178
        cmpy    mon_numwka+2                            ; is it the one we want?
2179
        bne             disarm3                                                 ; if not, go increment to next
2180
        ldx             mon_numwka+2                            ; x = memory address
2181
        ldy             #BreakpointBytes
2182
        lda             b,y                                                                     ; get saved byte from table
2183
        sta             ,x                                                                      ; set the byte at the memory address
2184
        ; compress breakpoint table by removing breakpoint
2185
        dec             NumSetBreakpoints               ; set the new number of set breakpoints
2186
        pshs    b                                                                               ; save the position we're removing from
2187
disarm7:
2188
        incb                                                                                    ; set index for next byte
2189
        lda             b,y                                                                     ; get byte
2190
        decb                                                                                    ; and store it back
2191
        sta             b,y
2192
        incb                                                                                    ; move to next position
2193
        cmpb    numBreakpoints                  ; hit end of table?
2194
        blo             disarm7
2195
        puls    b                                                                               ; get back position
2196
        aslb                                                                                    ; times two for word index
2197
        clra
2198
        tfr             d,y
2199
        lsrb                                                                                    ; back to byte index value
2200
disarm8:
2201
        ldu             2,y                                                                     ; get next breakpoint address
2202
        stu             ,y++                                                            ; store in current pos, increment
2203
        incb                                                                                    ; increment count
2204
        cmpb    numBreakpoints                  ; hit end of table?
2205
        blo             disarm8
2206
        puls    d,x,y,u,pc
2207
disarm3:
2208
        leax    2,x
2209
        incb
2210
        bra             disarm6
2211
disarm4:
2212
        puls    d,x,y,u,pc
2213
 
2214
;------------------------------------------------------------------------------
2215
;------------------------------------------------------------------------------
2216 4 robfinch
swi3_rout:
2217
        sei
2218 15 robfinch
        lda             ,s
2219 4 robfinch
        sta             mon_CCRSAVE
2220 15 robfinch
        ldd             1,s
2221 4 robfinch
        std             mon_DSAVE
2222 15 robfinch
        ldb             3,s
2223
        stb             mon_DPRSAVE
2224
        ldd             4,s
2225
        std             mon_XSAVE
2226
        ldd             6,s
2227
        std             mon_YSAVE
2228
        ldd             8,s
2229
        std             mon_USAVE
2230 4 robfinch
        sts             mon_SSAVE
2231 15 robfinch
        ldd             11,s
2232
        std             mon_PCSAVE
2233
        sts             mon_SSAVE
2234 4 robfinch
        lds             #$3FFF
2235 15 robfinch
        ldd             #swi3_exit
2236
        pshs    d
2237 4 robfinch
        cli
2238
        jmp             DumpRegs
2239
swi3_exit:
2240
        lds             mon_SSAVE
2241
        rti
2242
 
2243
;------------------------------------------------------------------------------
2244
;------------------------------------------------------------------------------
2245 13 robfinch
firq_rout:
2246
        rti
2247
 
2248 4 robfinch
irq_rout:
2249 13 robfinch
;       lbsr    SerialIRQ       ; check for recieved character
2250 15 robfinch
        lbsr    TimerIRQ
2251 13 robfinch
 
2252 4 robfinch
        ; Reset the edge sense circuit in the PIC
2253 15 robfinch
;       lda             #31                                                     ; Timer is IRQ #31
2254
;       sta             IrqSource               ; stuff a byte indicating the IRQ source for PEEK()
2255
;       sta             PIC+16                                  ; register 16 is edge sense reset reg
2256
;       lda             VIA+VIA_IFR
2257
;       bpl             notTimerIRQ2
2258
;       bita    #$800
2259
;       beq             notTimerIRQ2
2260
;       clr             VIA+VIA_T3LL
2261
;       clr             VIA+VIA_T3LH
2262
;       inc             $E00037                                 ; update timer IRQ screen flag
2263
;notTimerIRQ2:
2264 4 robfinch
 
2265
        lda             IrqBase                 ; get the IRQ flag byte
2266
        lsra
2267
        ora             IrqBase
2268 15 robfinch
        anda    #$FE0
2269 4 robfinch
        sta             IrqBase
2270
 
2271 13 robfinch
;       inc             TEXTSCR+54              ; update IRQ live indicator on screen
2272 4 robfinch
 
2273
        ; flash the cursor
2274
        ; only bother to flash the cursor for the task with the IO focus.
2275 13 robfinch
;       lda             COREID
2276
;       cmpa    IOFocusID
2277
;       bne             tr1a
2278
;       lda             CursorFlash             ; test if we want a flashing cursor
2279
;       beq             tr1a
2280
;       lbsr    CalcScreenLoc   ; compute cursor location in memory
2281
;       tfr             d,y
2282
;       lda             $2000,y                 ; get color code $2000 higher in memory
2283
;       ldb             IRQFlag                 ; get counter
2284
;       lsrb
2285
;       lsra
2286
;       lsra
2287
;       lsra
2288
;       lsra
2289
;       lsrb
2290
;       rola
2291
;       lsrb
2292
;       rola
2293
;       lsrb
2294
;       rola
2295
;       lsrb
2296
;       rola
2297
;       sta             $E00000,y               ; store the color code back to memory
2298
tr1a:
2299 4 robfinch
        rti
2300
 
2301
;------------------------------------------------------------------------------
2302
;------------------------------------------------------------------------------
2303
nmi_rout:
2304
        ldb             COREID
2305
        lda             #'I'
2306
        ldx             #TEXTSCR+40
2307 13 robfinch
        sta             b,x
2308
rti_insn:
2309 4 robfinch
        rti
2310
 
2311 13 robfinch
; Special Register Area
2312
        org             $FFFFE0
2313
 
2314
; Interrupt vector table
2315
 
2316 4 robfinch
        org             $FFFFF0
2317 13 robfinch
        fcw             rti_insn                ; reserved
2318
        fcw             swi3_rout               ; SWI3
2319
        fcw             rti_insn                ; SWI2
2320
        fcw             firq_rout               ; FIRQ
2321
        fcw             irq_rout                ; IRQ
2322 15 robfinch
        fcw             swi_rout                ; SWI
2323 4 robfinch
        fcw             nmi_rout                ; NMI
2324
        fcw             start                           ; RST

powered by: WebSVN 2.1.0

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