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

Subversion Repositories rf6809

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

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

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

powered by: WebSVN 2.1.0

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