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

Subversion Repositories rf6809

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

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

powered by: WebSVN 2.1.0

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