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

Subversion Repositories rf6809

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

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

powered by: WebSVN 2.1.0

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