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

Subversion Repositories rf6809

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

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

Line No. Rev Author Line
1 4 robfinch
; ============================================================================
2
;        __
3
;   \\__/ o\    (C) 2013-2022  Robert Finch, Stratford
4
;    \  __ /    All rights reserved.
5
;     \/_//     robfinch@opencores.org
6
;       ||
7
;
8
;
9
; This source file is free software: you can redistribute it and/or modify
10
; it under the terms of the GNU Lesser General Public License as published
11
; by the Free Software Foundation, either version 3 of the License, or
12
; (at your option) any later version.
13
;
14
; This source file is distributed in the hope that it will be useful,
15
; but WITHOUT ANY WARRANTY; without even the implied warranty of
16
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
; GNU General Public License for more details.
18
;
19
; You should have received a copy of the GNU General Public License
20
; along with this program.  If not, see .
21
;
22
; ============================================================================
23
;
24
CR      EQU     $0D             ;ASCII equates
25
LF      EQU     $0A
26
TAB     EQU     $09
27
CTRLC   EQU     $03
28
CTRLH   EQU     $08
29
CTRLI   EQU     $09
30
CTRLJ   EQU     $0A
31
CTRLK   EQU     $0B
32
CTRLM   EQU $0D
33
CTRLS   EQU     $13
34
CTRLX   EQU     $18
35
XON             EQU     $11
36
XOFF    EQU     $13
37
 
38
FIRST_CORE      EQU     1
39
MAX_TASKNO      EQU 63
40
DRAM_BASE       EQU $10000000
41
 
42
ScreenLocation          EQU             $10
43
ColorCodeLocation       EQU             $14
44
ScreenLocation2         EQU             $18
45
BlkcpySrc                       EQU             $1C
46
BlkcpyDst                       EQU             $20
47
Strptr                          EQU             $24
48
PICptr                          EQU             $28
49
; Forth Area
50
; 0x30-0x60
51
 
52
RunningID                       EQU             $800000
53
 
54
; Task control blocks, room for 256 tasks
55
TCB_NxtRdy              EQU             $00     ; next task on ready / timeout list
56
TCB_PrvRdy              EQU             $04     ; previous task on ready / timeout list
57
TCB_NxtTCB              EQU             $08
58
TCB_Timeout             EQU             $0C
59
TCB_Priority    EQU             $10
60
TCB_MSGPTR_D1   EQU             $14
61
TCB_MSGPTR_D2   EQU             $18
62
TCB_hJCB                        EQU             $1C
63
TCB_Status              EQU             $1E
64
TCB_CursorRow   EQU             $20
65
TCB_CursorCol   EQU             $21
66
TCB_hWaitMbx    EQU             $22     ; handle of mailbox task is waiting at
67
TCB_mbq_next    EQU             $24     ; mailbox queue next
68
TCB_mbq_prev    EQU             $28     ; mailbox queue previous
69
TCB_iof_next    EQU             $2C
70
TCB_iof_prev    EQU             $30
71
TCB_SPSave              EQU             $34     ; TCB_SPSave area
72
TCB_mmu_map             EQU             $38
73
 
74
KeybdHead               EQU             $FFFFFC800
75
KeybdTail               EQU             $FFFFFC900
76
KeybdEcho               EQU             $FFFFFCA00
77
KeybdBad                EQU             $FFFFFCB00
78
KeybdAck                EQU             $FFFFFCC00
79
KeybdLocks              EQU             $FFFFFCD00
80
KeybdBuffer             EQU             $FFFFFC000      ; buffer is 16 chars
81
 
82
COREID  EQU             $FFFFFFFE0
83
MSCOUNT EQU             $FFFFFFFE4
84
LEDS            EQU             $FFFE60000
85
TEXTSCR         EQU             $FFFE00000
86
TEXTREG         EQU             $FFFE0DF00
87
TEXT_COLS       EQU             0
88
TEXT_ROWS       EQU             1
89
TEXT_CURPOS     EQU             34
90
KEYBD           EQU             $FFFE30400
91
KEYBDCLR        EQU             $FFFE30402
92
PIC                     EQU             $FFFE3F000
93
SPRITE_CTRL             EQU             $FFFE10000
94
SPRITE_EN                       EQU             $3C0
95
 
96
BIOS_SCREENS    EQU     $17000000       ; $17000000 to $171FFFFF
97
 
98
; EhBASIC vars:
99
;
100
NmiBase         EQU             $DC
101
IrqBase         EQU             $DF
102
 
103
; The IO focus list is a doubly linked list formed into a ring.
104
;
105
IOFocusNdx      EQU             $100
106
IOFocusID               EQU             $100
107
 
108
; These variables use direct page access
109
CursorRow       EQU             $110
110
CursorCol       EQU             $111
111
CharColor       EQU             $112
112
ScreenColor     EQU             $113
113
CursorFlash     EQU             $114
114
KeyState1       EQU     $120
115
KeyState2       EQU     $121
116
KeyLED          EQU     $122
117
KeybdID         EQU     $124
118
 
119
QNdx0           EQU             $780
120
QNdx1           EQU             QNdx0+2
121
QNdx2           EQU             QNdx1+2
122
QNdx3           EQU             QNdx2+2
123
QNdx4           EQU             QNdx3+2
124
FreeTCB         EQU             QNdx4+2
125
TimeoutList     EQU             FreeTCB+2
126
FreeMbx         EQU             RunningTCB + 2
127
nMailbox        EQU             FreeMbx + 2
128
FreeMsg         EQU             nMailbox + 2
129
nMsgBlk         EQU             FreeMsg + 2
130
 
131
IrqSource       EQU             $79A
132
 
133
IRQFlag         EQU             $7C6
134
 
135
CharOutVec      EQU             $800
136
CharInVec       EQU             $804
137
 
138
; Register save area for monitor
139
mon_DSAVE       EQU             $900
140
mon_XSAVE       EQU             $902
141
mon_YSAVE       EQU             $904
142
mon_USAVE       EQU             $906
143
mon_SSAVE       EQU             $908
144
mon_PCSAVE      EQU             $90A
145
mon_DPRSAVE     EQU             $90E
146
mon_CCRSAVE     EQU             $90F
147
 
148
mon_numwka      EQU             $910
149
mon_r1          EQU             $920
150
mon_r2          EQU             $922
151
 
152
; The ORG directive must set an address a multiple of 4 in order for the Verilog
153
; output to work correctly.
154
 
155
        org             $FFD0AC
156
        nop
157
        nop
158
        nop
159
XBLANK
160
        ldb             #' '
161
        lbsr    OUTCH
162
        rts
163
 
164
        org             $FFD0D0
165
        nop
166
        nop
167
CRLF
168
CRLF1:
169
        ldb             #CR
170
        lbsr    OUTCH
171
        ldb             #LF
172
        lbsr    OUTCH
173
        rts
174
 
175
        org             $FFD0F0
176
        nop
177
        bra             CRLF1
178
 
179
        org             $FFD1DC
180
ONEKEY
181
        jmp             [CharInVec]
182
 
183
        org             $FFD2C0
184
        nop
185
LETTER
186
        lbsr    OUTCH
187
        rts
188
 
189
        org             $FFD2CC
190
        nop
191
        nop
192
HEX2
193
        lbsr    DispByteAsHex
194
        rts
195
HEX4
196
        lbsr    DispWordAsHex
197
        rts
198
 
199
        org             $FFD300
200
ClearScreenJmp
201
        lbra    ClearScreen
202
        org             $FFD308
203
HomeCursorJmp
204
        lbra    HomeCursor
205
 
206
        org             $FFE000
207
 
208
; Local RAM test routine
209
; Checkerboard testing.
210
; There is 70kB of local RAM
211
; Does not use any RAM including no stack
212
 
213
ramtest:
214
        ldy             #0
215
        lda             #1
216
        sta             LEDS
217
        ldd             #$AAA555
218
ramtest1:
219
        std             ,y++
220
        cmpy    #$C00000
221
        blo             ramtest1
222
        ; now readback values and compare
223
        ldy             #0
224
ramtest3:
225
        ldd             ,y++
226
        cmpd    #$AAA555
227
        bne             ramerr
228
        cmpy    #$C00000
229
        blo             ramtest3
230
        lda             #2
231
        sta             LEDS
232
        jmp             ,u
233
ramerr:
234
        lda             #$80
235
        sta             LEDS
236
        ldx             #TEXTSCR
237
        ldb             COREID
238
        abx
239
        lda             #'F'
240
        sta             ,x
241
        sync
242
        jmp             ,u
243
 
244
        org             $FFF000
245
        FDB Monitor
246
        FDB DumRts      ;       NEXTCMD
247
        FDB INCH
248
        FDB INCHE
249
        FDB INCHEK
250
        FDB OUTCH
251
        FDB PDATA
252
        FDB PCRLF
253
        FDB PSTRNG
254
        FDB DumRts                      ; LRA
255
        FDB DumRts
256
        FDB DumRts
257
        FDB DumRts
258
        FDB DumRts                      ; VINIZ
259
        FDB DisplayChar ;       VOUTCH
260
        FDB DumRts                      ; ACINIZ
261
        FDB DumRts                      ; AOUTCH
262
 
263
DumRts:
264
        rts
265
 
266
;------------------------------------------------------------------------------
267
;------------------------------------------------------------------------------
268
 
269
start:
270
        lda             #$55                    ; see if we can at least set LEDs
271
        sta             LEDS
272
        ldu             #st6                    ; U = return address
273
        jmp             ramtest         ; JMP dont JSR
274
st6:
275
        lds             #$3FFF          ; boot up stack area
276
        lda             COREID
277
        cmpa    #FIRST_CORE
278
;       beq             st8
279
;       sync                                            ; halt cores other than 2
280
st8:
281
;       bne             skip_init
282
;       bsr             romToRam
283
;       ldd             #st7 & $FFFF
284
;       tfr             d,x
285
;       jmp             ,x                              ; jump to the BIOS now in local RAM
286
st7:
287
        bsr             Delay3s         ; give some time for devices to reset
288
        lda             #$AA
289
        sta             LEDS
290
        lda             #2
291
        sta             IOFocusID       ; core #2 has focus
292
        sta             RunningID
293
        lda             #$0CE
294
        sta             ScreenColor
295
        sta             CharColor
296
        bsr             ClearScreen
297
        ldd             #DisplayChar
298
        std             CharOutVec
299
        ldd             #DBGGetKey
300
        std             CharInVec
301
        ldb             COREID
302
        cmpb    #FIRST_CORE
303
        beq             init
304
        bra             skip_init
305
        bra             multi_sieve
306
st3:
307
        lda             #$FF
308
        sta             LEDS
309
        bra             st3
310
 
311
        ; initialize interrupt controller
312
        ; first, zero out all the vectors
313
init:
314
        ldx             #128
315
        lda             #1                      ; set irq(bit0), clear firq (bit1), disable int (bit 6), clear edge sense(bit 7)
316
        ldb             #FIRST_CORE                     ; serving core id
317
st1:
318
        clr             PIC,x           ; cause code
319
        sta             PIC+1,x
320
        stb             PIC+2,x
321
        leax    4,x
322
        cmpx    #256
323
        blo             st1
324
;       lda             #4                              ; make the timer interrupt edge sensitive
325
;       sta             PIC+4                   ; reg #4 is the edge sensitivity setting
326
;       sta             PIC                             ; reg #0 is interrupt enable
327
 
328
skip_init:
329
        andcc   #$EF                    ; unmask irq
330
        lda             #56
331
        sta             TEXTREG+TEXT_COLS
332
        lda             #29
333
        sta             TEXTREG+TEXT_ROWS
334
        bsr             ClearScreen
335
        bsr             HomeCursor
336
        lda             #5
337
        sta             LEDS
338
        ldd             #msgStartup
339
        bsr             DisplayString
340
        ldx             #0
341
        ldd             #0
342
        lbsr    ShowSprites
343
        lbsr    KeybdInit
344
        ldd             KeybdID
345
        bsr             DispWordAsHex
346
        jmp             MonitorStart
347
 
348
msgStartup
349
        fcb             "rf6809 12-bit System Starting.",CR,LF,0
350
 
351
;------------------------------------------------------------------------------
352
; The checkpoint register must be cleared within 1 second or a NMI interrupt
353
; will occur. checkpoint should be called with a JSR so that the global ROM
354
; routine is called.
355
;
356
; Modifies:
357
;               none
358
;------------------------------------------------------------------------------
359
 
360
checkpoint:
361
        clr             $FFFFFFFE1      ; writing any value will do
362
        rts
363
 
364
;------------------------------------------------------------------------------
365
; Copy the system ROM to local RAM
366
; Running the code from local RAM is probably an order of magnitude faster
367
; then running from the global ROM. It also reduces the network traffic to
368
; run from local RAM.
369
;
370
; Modifies:
371
;               d,x,y
372
;------------------------------------------------------------------------------
373
 
374
romToRam:
375
        ldx             #$FFC000
376
        ldy             #$00C000
377
romToRam1:
378
        ldd             ,x++
379
        std             ,y++
380
        cmpx    #0
381
        bne             romToRam1
382
        rts
383
 
384
;------------------------------------------------------------------------------
385
; Multi-core sieve program.
386
;------------------------------------------------------------------------------
387
 
388
; First fill screen chars with 'P' indicating prime positions
389
; Each core is responsible for the Nth position where N is the
390
; core number minus two.
391
;
392
multi_sieve:
393
        lda             #'P'                                    ; indicate prime
394
        ldb             COREID                          ; find out which core we are
395
        subb    #FIRST_CORE
396
        ldx             #0                                              ; start at first char of screen
397
        abx
398
multi_sieve3:
399
        sta             TEXTSCR,x                       ; store 'P'
400
        leax    8,x                                             ; advance to next position
401
        cmpx    #4095
402
        blo             multi_sieve3
403
        jsr             checkpoint
404
        addb    #2                                              ; start sieve at 2 (core id)
405
        lda             #'N'                                    ; flag position value of 'N' for non-prime
406
multi_sieve2:
407
        ldx             #0
408
        abx                                                                     ; skip the first position - might be prime
409
multi_sieve1:
410
        abx                                                                     ; increment
411
        sta             TEXTSCR,x
412
        cmpx    #4095
413
        blo             multi_sieve1
414
        jsr             checkpoint
415
        addb    #8                                              ; number of cores working on it
416
        cmpb    #4080
417
        blo             multi_sieve2
418
multi_sieve4:                                   ; hang machine
419
        sync
420
        lbra    Monitor
421
 
422
sieve:
423
        lda             #'P'                                    ; indicate prime
424
        ldx             #0                                              ; start at first char of screen
425
sieve3:
426
        sta             TEXTSCR,x                       ; store 'P'
427
        inx                                                                     ; advance to next position
428
        cmpx    #4095
429
        blo             sieve3
430
        ldb             #2                                              ; start sieve at 2
431
        lda             #'N'                                    ; flag position value of 'N' for non-prime
432
sieve2:
433
        ldx             #0
434
        abx                                                                     ; skip the first position - might be prime
435
sieve1:
436
        abx                                                                     ; increment
437
        sta             TEXTSCR,x
438
        cmpx    #4095
439
        blo             multi_sieve1
440
        incb                                                            ; number of cores working on it
441
        cmpb    #4080
442
        blo             sieve2
443
sieve4:                                                         ; hang machine
444
        sync
445
        lbra    MonitorStart
446
 
447
;------------------------------------------------------------------------------
448
; Three second delay for user convenience and to allow some devices time to
449
; reset.
450
;------------------------------------------------------------------------------
451
 
452
Delay3s:
453
        ldd             #9000000
454
dly3s1:
455
        cmpb    #$FF
456
        bne             dly3s2
457
dly3s2:
458
        sta             LEDS
459
        subd    #1
460
        bne             dly3s1
461
        rts
462
 
463
;------------------------------------------------------------------------------
464
;------------------------------------------------------------------------------
465
ShiftLeft5:
466
        aslb
467
        rola
468
        aslb
469
        rola
470
        aslb
471
        rola
472
        aslb
473
        rola
474
        aslb
475
        rola
476
        rts
477
 
478
;------------------------------------------------------------------------------
479
;------------------------------------------------------------------------------
480
;
481
CopyVirtualScreenToScreen:
482
        pshs    d,x,y,u
483
        bsr             GetScreenLocation
484
        tfr             d,x
485
        ldy             #TEXTSCR
486
        ldu             #56*29/2
487
cv2s1:
488
        ldd             ,x++
489
        std             ,y++
490
        leau    -1,u
491
        cmpu    #0
492
        bne             cv2s1
493
        ; reset the cursor position in the text controller
494
        ldb             CursorRow
495
        lda             #56
496
        mul
497
        tfr             d,x
498
        ldb             CursorCol
499
        abx
500
        stx             TEXTREG+TEXT_CURPOS
501
        puls    d,x,y,u,pc
502
 
503
;------------------------------------------------------------------------------
504
;------------------------------------------------------------------------------
505
;
506
CopyScreenToVirtualScreen:
507
        pshs    d,x,y,u
508
        bsr             GetScreenLocation
509
        tfr             d,y
510
        ldx             #TEXTSCR
511
        ldu             #56*29/2
512
cs2v1:
513
        ldd             ,x++
514
        std             ,y++
515
        leau    -1,u
516
        cmpu    #0
517
        bne             cs2v1
518
        puls    d,x,y,u,pc
519
 
520
;------------------------------------------------------------------------------
521
;------------------------------------------------------------------------------
522
        fcb             "TEXTSCR "
523
        fcw             TextOpen
524
        fcw             TextClose
525
        fcw             TextRead
526
        fcw             TextWrite
527
        fcw             TextSeek
528
 
529
TextOpen:
530
        rts
531
TextClose:
532
        rts
533
TextRead:
534
        rts
535
TextWrite:
536
        rts
537
TextSeek:
538
        rts
539
 
540
;------------------------------------------------------------------------------
541
; Clear the screen and the screen color memory
542
; We clear the screen to give a visual indication that the system
543
; is working at all.
544
;
545
; Modifies:
546
;               none
547
;------------------------------------------------------------------------------
548
 
549
ClearScreen:
550
        pshs    d,x,y,u
551
        ldx             #56*29
552
        tfr             x,u
553
        bsr             GetScreenLocation
554
        tfr             d,y
555
        ldb             #' '                            ; space char
556
cs1:
557
        stb             ,y+                                     ; set text to space
558
        leax    -1,x                            ; decrement x
559
        bne             cs1
560
        ldb             COREID                  ; update colors only if we have focus
561
        cmpb    IOFocusID
562
        bra             cs3
563
        ldy             #TEXTSCR+$2000
564
;       lda             CharColor
565
        lda             #$0CE
566
        tfr             u,x                                     ; get back count
567
cs2:
568
        sta             ,y+
569
        leax    -1,x                            ; decrement x
570
        bne             cs2
571
cs3:
572
        puls    d,x,y,u,pc
573
 
574
;------------------------------------------------------------------------------
575
; Scroll text on the screen upwards
576
;
577
; Modifies:
578
;               none
579
;------------------------------------------------------------------------------
580
 
581
ScrollUp:
582
        pshs    d,x,y,u
583
        ldy             #(56*29-1)/2    ; y = num chars/2 to move
584
        bsr             GetScreenLocation
585
        tfr             d,x
586
        tfr             d,u
587
        leax    56,x                    ; x = index to source row
588
scrup1:
589
        ldd             ,x++                    ; move 2 characters
590
        std             ,u++
591
        leay    -1,y
592
        bne             scrup1
593
        lda             #30
594
        bsr             BlankLine
595
        puls    d,x,y,u,pc
596
 
597
;------------------------------------------------------------------------------
598
; Blank out a line on the display
599
;
600
; Modifies:
601
;               none
602
; Parameters:
603
;       acca = line number to blank
604
;------------------------------------------------------------------------------
605
 
606
BlankLine:
607
        pshs    d,x
608
        pshs    a
609
        bsr             GetScreenLocation
610
        tfr             d,x
611
        puls    a
612
        ldb             #56             ; b = # chars to blank out from video controller
613
        mul                                     ; d = screen index (row# * #cols)
614
        leax    d,x
615
        lda             #' '
616
        ldb             #56             ; b = # chars to blank out from video controller
617
blnkln1:
618
        sta             ,x+
619
        decb
620
        bne             blnkln1
621
        puls    d,x,pc
622
 
623
;------------------------------------------------------------------------------
624
; Get the location of the screen memory. The location
625
; depends on whether or not the task has the output focus.
626
;
627
; Modifies:
628
;               d
629
; Retuns:
630
;               d = screen location
631
;------------------------------------------------------------------------------
632
 
633
GetScreenLocation:
634
        lda             COREID                  ; which core are we?
635
        cmpa    IOFocusID               ; do we have the IO focus
636
        bne             gsl1                            ; no, go pick virtual screen address
637
        ldd             #TEXTSCR                ; yes, we update the real screen
638
        rts
639
gsl1:
640
        ldd             #$7800
641
        rts
642
 
643
;------------------------------------------------------------------------------
644
; HomeCursor
645
; Set the cursor location to the top left of the screen.
646
;
647
; Modifies:
648
;               none
649
;------------------------------------------------------------------------------
650
 
651
HomeCursor:
652
        pshs    d,x
653
        clr             CursorRow
654
        clr             CursorCol
655
        ldb             COREID
656
        cmpb    IOFocusID
657
        bne             hc1
658
        clra
659
        sta             TEXTREG+TEXT_CURPOS
660
hc1:
661
        puls    d,x,pc
662
 
663
;------------------------------------------------------------------------------
664
; Update the cursor position in the text controller based on the
665
;  CursorRow,CursorCol.
666
;
667
; Modifies:
668
;               none
669
;------------------------------------------------------------------------------
670
;
671
UpdateCursorPos:
672
        pshs    d,x
673
        ldb             COREID                          ; update cursor position in text controller
674
        cmpb    IOFocusID                       ; only for the task with the output focus
675
        bne             ucp1
676
        lda             CursorRow
677
        anda    #$3F                                    ; limit of 63 rows
678
        ldb             TEXTREG+TEXT_COLS
679
        mul
680
        tfr             d,x
681
        ldb             CursorCol
682
        abx
683
        stx             TEXTREG+TEXT_CURPOS
684
ucp1:
685
        puls    d,x,pc
686
 
687
;------------------------------------------------------------------------------
688
; Calculate screen memory location from CursorRow,CursorCol.
689
; Also refreshes the cursor location.
690
;
691
; Modifies:
692
;               d
693
; Returns:
694
;       d = screen location
695
;------------------------------------------------------------------------------
696
;
697
CalcScreenLoc:
698
        pshs    x
699
        lda             CursorRow
700
        ldb             #56
701
        mul
702
        tfr             d,x
703
        ldb             CursorCol
704
        abx
705
        ldb             COREID                          ; update cursor position in text controller
706
        cmpb    IOFocusID                       ; only for the task with the output focus
707
        bne             csl1
708
        stx             TEXTREG+TEXT_CURPOS
709
csl1:
710
        bsr             GetScreenLocation
711
        leax    d,x
712
        tfr             x,d
713
        puls    x,pc
714
 
715
;------------------------------------------------------------------------------
716
; Display a character on the screen.
717
; If the task doesn't have the I/O focus then the character is written to
718
; the virtual screen.
719
;
720
; Modifies:
721
;               none
722
; Parameters:
723
;       accb = char to display
724
;------------------------------------------------------------------------------
725
;
726
DisplayChar:
727
        pshs    d,x
728
        cmpb    #CR                                     ; carriage return ?
729
        bne             dccr
730
        clr             CursorCol               ; just set cursor column to zero on a CR
731
        bsr             UpdateCursorPos
732
dcx14:
733
        puls    d,x,pc
734
dccr:
735
        cmpb    #$91                            ; cursor right ?
736
        bne             dcx6
737
        lda             CursorCol
738
        cmpa    #56
739
        bhs             dcx7
740
        inca
741
        sta             CursorCol
742
dcx7:
743
        bsr             UpdateCursorPos
744
        puls    d,x,pc
745
dcx6:
746
        cmpb    #$90                            ; cursor up ?
747
        bne             dcx8
748
        lda             CursorRow
749
        beq             dcx7
750
        deca
751
        sta             CursorRow
752
        bra             dcx7
753
dcx8:
754
        cmpb    #$93                            ; cursor left ?
755
        bne             dcx9
756
        lda             CursorCol
757
        beq             dcx7
758
        deca
759
        sta             CursorCol
760
        bra             dcx7
761
dcx9:
762
        cmpb    #$92                            ; cursor down ?
763
        bne             dcx10
764
        lda             CursorRow
765
        cmpa    #29
766
        beq             dcx7
767
        inca
768
        sta             CursorRow
769
        bra             dcx7
770
dcx10:
771
        cmpb    #$94                            ; cursor home ?
772
        bne             dcx11
773
        lda             CursorCol
774
        beq             dcx12
775
        clr             CursorCol
776
        bra             dcx7
777
dcx12:
778
        clr             CursorRow
779
        bra             dcx7
780
dcx11:
781
        cmpb    #$99                            ; delete ?
782
        bne             dcx13
783
        bsr             CalcScreenLoc
784
        tfr             d,x
785
        lda             CursorCol               ; acc = cursor column
786
        bra             dcx5
787
dcx13
788
        cmpb    #CTRLH                  ; backspace ?
789
        bne             dcx3
790
        lda             CursorCol
791
        beq             dcx4
792
        deca
793
        sta             CursorCol
794
        bsr             CalcScreenLoc
795
dcx5:
796
        ldb             1,x
797
        stb             ,x++
798
        inca
799
        cmpa    #56
800
        blo             dcx5
801
        ldb             #' '
802
        leax    -1,x
803
        stb             ,x
804
        puls    d,x,dp,pc
805
dcx3:
806
        cmpb    #LF                             ; linefeed ?
807
        beq             dclf
808
        pshs    b
809
        bsr     CalcScreenLoc
810
        tfr             d,x
811
        puls    b
812
        stb             ,x
813
        ; ToDo character color
814
;       lda             CharColor
815
;       sta             $2000,x
816
        bsr             IncCursorPos
817
        puls    d,x,pc
818
dclf:
819
        bsr             IncCursorRow
820
dcx4:
821
        puls    d,x,pc
822
 
823
;------------------------------------------------------------------------------
824
; Increment the cursor position, scroll the screen if needed.
825
;
826
; Modifies:
827
;               none
828
;------------------------------------------------------------------------------
829
 
830
IncCursorPos:
831
        pshs    d,x
832
        lda             CursorCol
833
        inca
834
        sta             CursorCol
835
        cmpa    #56
836
        blo             icc1
837
        clr             CursorCol               ; column = 0
838
        bra             icr1
839
IncCursorRow:
840
        pshs    d,x
841
icr1:
842
        lda             CursorRow
843
        inca
844
        sta             CursorRow
845
        cmpa    #29
846
        blo             icc1
847
        deca                                                    ; backup the cursor row, we are scrolling up
848
        sta             CursorRow
849
        bsr             ScrollUp
850
icc1:
851
        bsr             UpdateCursorPos
852
icc2:
853
        puls    d,x,pc
854
 
855
;------------------------------------------------------------------------------
856
; Display a string on the screen.
857
;
858
; Modifies:
859
;               none
860
; Parameters:
861
;               d = pointer to string
862
;------------------------------------------------------------------------------
863
;
864
DisplayString:
865
        pshs    d,x
866
        tfr             d,x
867
dspj1B:
868
        ldb             ,x+                             ; move string char into acc
869
        beq             dsretB          ; is it end of string ?
870
        bsr             OUTCH                   ; display character
871
        bra             dspj1B
872
dsretB:
873
        puls    d,x,pc
874
 
875
DisplayStringCRLF:
876
        pshs    d
877
        bsr             DisplayString
878
        ldb             #CR
879
        bsr             OUTCH
880
        ldb             #LF
881
        bsr             OUTCH
882
        puls    d,pc
883
 
884
;
885
; PRINT CR, LF, STRING
886
;
887
PSTRNG
888
        BSR             PCRLF
889
        BRA             PDATA
890
PCRLF
891
        PSHS    X
892
        LDX             #CRLFST
893
        BSR             PDATA
894
        PULS    X
895
        RTS
896
 
897
PRINT
898
        JSR             OUTCH
899
PDATA
900
        LDB             ,X+
901
        CMPB    #$04
902
        BNE             PRINT
903
        RTS
904
 
905
CRLFST
906
        fcb     CR,LF,4
907
 
908
DispDWordAsHex:
909
        bsr             DispWordAsHex
910
        exg             d,x
911
        bsr             DispWordAsHex
912
        exg             d,x
913
        rts
914
 
915
DispWordAsHex:
916
        exg             a,b
917
        bsr             DispByteAsHex
918
        exg             a,b
919
        bsr             DispByteAsHex
920
        rts
921
 
922
DispByteAsHex:
923
  pshs  b
924
        lsrb
925
        lsrb
926
        lsrb
927
        lsrb
928
        lsrb
929
        lsrb
930
        lsrb
931
        lsrb
932
        bsr             DispNyb
933
        puls    b
934
        pshs    b
935
        lsrb
936
        lsrb
937
        lsrb
938
        lsrb
939
        bsr             DispNyb
940
        puls    b
941
 
942
DispNyb
943
        pshs    b
944
        andb    #$0F
945
        cmpb    #10
946
        blo             DispNyb1
947
        addb    #'A'-10
948
        bsr             OUTCH
949
        puls    b,pc
950
DispNyb1
951
        addb    #'0'
952
        bsr             OUTCH
953
        puls    b,pc
954
 
955
;==============================================================================
956
; Keyboard I/O
957
;==============================================================================
958
 
959
OPT INCLUDE "d:\cores2022\rf6809\software\boot\scancodes.asm"
960
OPT INCLUDE "d:\cores2022\rf6809\software\boot\keyboard.asm"
961
 
962
        fcb             "KEYBOARD"
963
        fcw             KeybdOpen
964
        fcw             KeybdClose
965
        fcw             KeybdRead
966
        fcw             KeybdWrite
967
        fcw             KeybdSeek
968
 
969
; Keyboard Open:
970
; Initialize the keyboard buffer head and tail indexes
971
;
972
KeybdOpen:
973
        rts
974
 
975
; Keyboard Close:
976
; Nothing to do except maybe clear the keyboard buffer
977
;
978
KeybdClose:
979
        rts
980
;
981
KeybdRead:
982
        rts
983
;
984
KeybdWrite:
985
        rts
986
 
987
KeybdSeek:
988
        rts
989
 
990
;------------------------------------------------------------------------------
991
; Check if there is a keyboard character available. If so return true (<0)
992
; otherwise return false (0) in accb.
993
;------------------------------------------------------------------------------
994
;
995
KeybdCheckForKeyDirect:
996
        bra             DBGCheckForKey
997
 
998
;------------------------------------------------------------------------------
999
;------------------------------------------------------------------------------
1000
INCH:
1001
        ldd             #-1                             ; block if no key available
1002
        bra             DBGGetKey
1003
 
1004
INCHE:
1005
        bsr             INCH
1006
        bra             INCHEK3
1007
 
1008
INCHEK:
1009
        bsr             INCH
1010
        tst             KeybdEcho
1011
        beq             INCHEK1
1012
INCHEK3:
1013
        cmpa    #CR
1014
        bne             INCHEK2
1015
        lbsr            CRLF
1016
        bra             INCHEK1
1017
INCHEK2:
1018
        bsr             DisplayChar
1019
INCHEK1:
1020
        rts
1021
 
1022
OUTCH:
1023
        jmp             [CharOutVec]
1024
 
1025
;------------------------------------------------------------------------------
1026
; r1 0=echo off, non-zero = echo on
1027
;------------------------------------------------------------------------------
1028
;
1029
SetKeyboardEcho:
1030
        stb             KeybdEcho
1031
        rts
1032
 
1033
 
1034
;------------------------------------------------------------------------------
1035
; Parameters:
1036
;               x,d     bitmap of sprites to enable
1037
;------------------------------------------------------------------------------
1038
 
1039
ShowSprites:
1040
        stx             SPRITE_CTRL+SPRITE_EN
1041
        std             SPRITE_CTRL+SPRITE_EN+2
1042
        rts
1043
 
1044
;==============================================================================
1045
; System Monitor
1046
;==============================================================================
1047
;
1048
MonitorStart:
1049
        ldd             #HelpMsg
1050
        bsr             DisplayString
1051
Monitor:
1052
        leas    $3FFF                           ; reset stack pointer
1053
        clrb                                                    ; turn off keyboard echo
1054
        bsr             SetKeyboardEcho
1055
;       jsr             RequestIOFocus
1056
PromptLn:
1057
        lbsr    CRLF
1058
        ldb             #'$'
1059
        bsr             OUTCH
1060
 
1061
; Get characters until a CR is keyed
1062
 
1063
Prompt3:
1064
        ldd             #-1                                     ; block until key present
1065
        bsr             DBGGetKey
1066
        cmpb    #CR
1067
        beq             Prompt1
1068
        bsr             OUTCH
1069
        bra             Prompt3
1070
 
1071
; Process the screen line that the CR was keyed on
1072
;
1073
Prompt1:
1074
        ldd             #$5050
1075
        std             LEDS
1076
        ldb             RunningID
1077
        cmpb    #61
1078
        bhi             Prompt3
1079
        ldd             #$5151
1080
        std             LEDS
1081
        clr             CursorCol                       ; go back to the start of the line
1082
        bsr             CalcScreenLoc   ; calc screen memory location
1083
        tfr             d,y
1084
        ldd             #$5252
1085
        std             LEDS
1086
        bsr             MonGetNonSpace
1087
        cmpb    #'$'
1088
        bne             Prompt2                 ; skip over '$' prompt character
1089
        lda             #$5353
1090
        std             LEDS
1091
        bsr             MonGetNonSpace
1092
 
1093
; Dispatch based on command character
1094
;
1095
Prompt2:
1096
        cmpb    #'?'                    ; $? - display help
1097
        bne             PromptC
1098
        ldd             #HelpMsg
1099
        bsr             DisplayString
1100
        bra             Monitor
1101
PromptC:
1102
        cmpb    #'C'
1103
        bne             PromptD
1104
        lbsr            ClearScreen
1105
        bsr             HomeCursor
1106
        bra             Monitor
1107
PromptD:
1108
        cmpb    #'D'
1109
        bne             PromptF
1110
        bsr             MonGetch
1111
        cmpb    #'R'
1112
        bne             Prompt3
1113
        bra             DumpRegs
1114
PromptF:
1115
        cmpb    #'F'
1116
        bne             PromptJ
1117
        bsr             MonGetch
1118
        cmpb    #'I'
1119
        bne             Monitor
1120
        bsr             MonGetch
1121
        cmpb    #'G'
1122
        bne             Monitor
1123
        jmp             $FE0000
1124
PromptJ:
1125
        cmpb    #'J'
1126
        lbeq    jump_to_code
1127
PromptR:
1128
        cmpb    #'R'
1129
        bne             Monitor
1130
        lbsr    ramtest
1131
        bra             Monitor
1132
 
1133
MonGetch:
1134
        ldb             ,y
1135
        leay    1,y
1136
        rts
1137
 
1138
MonGetNonSpace:
1139
        bsr             MonGetCh
1140
        cmpb    #' '
1141
        beq             MonGetNonSpace
1142
        cmpb    #9              ; tab
1143
        beq             MonGetNonSpace
1144
        rts
1145
 
1146
;------------------------------------------------------------------------------
1147
; Ignore blanks in the input
1148
; Y = text pointer
1149
; D destroyed
1150
;------------------------------------------------------------------------------
1151
;
1152
ignBlanks:
1153
ignBlanks1:
1154
        bsr             MonGetch
1155
        cmpb    #' '
1156
        beq             ignBlanks1
1157
        leay    -1,y
1158
        rts
1159
 
1160
;------------------------------------------------------------------------------
1161
;------------------------------------------------------------------------------
1162
GetTwoParams:
1163
        bsr             ignBlanks
1164
        bsr             GetHexNumber    ; get start address of dump
1165
        ldd             mon_numwka
1166
        std             mon_r1
1167
        ldd             mon_numwka+2
1168
        std             mon_r1+2
1169
        bsr             ignBlanks
1170
        bsr             GetHexNumber    ; get end address of dump
1171
        ldd             mon_numwka
1172
        std             mon_r2
1173
        ldd             mon_numwka+2
1174
        std             mon_r2+2
1175
        rts
1176
 
1177
;------------------------------------------------------------------------------
1178
; Get a range, the end must be greater or equal to the start.
1179
;------------------------------------------------------------------------------
1180
GetRange:
1181
        bsr             GetTwoParams
1182
        ldd             mon_r2+2
1183
        subd    mon_r1+2
1184
        ldd             mon_r2
1185
        sbcb    mon_r1+1
1186
        sbca    mon_r1
1187
        lbcs    DisplayErr
1188
        rts
1189
 
1190
shl_numwka:
1191
        asl             mon_numwka+3
1192
        rol             mon_numwka+2
1193
        rol             mon_numwka+1
1194
        rol             mon_numwka
1195
        rts
1196
 
1197
;------------------------------------------------------------------------------
1198
; Get a hexidecimal number. Maximum of nine digits.
1199
; Y = text pointer (updated)
1200
; D = number of digits
1201
; mon_numwka contains number
1202
;------------------------------------------------------------------------------
1203
;
1204
GetHexNumber:
1205
        clrd
1206
        std             mon_numwka
1207
        std             mon_numwka+2
1208
        pshs    x
1209
        ldx             #0                                      ; max 9 eight digits
1210
gthxn2:
1211
        bsr             MonGetch
1212
        bsr             AsciiToHexNybble
1213
        cmpb    #-1
1214
        beq             gthxn1
1215
        bsr             shl_numwka
1216
        bsr             shl_numwka
1217
        bsr             shl_numwka
1218
        bsr             shl_numwka
1219
        andb    #$0f
1220
        orb             mon_numwka+3
1221
        stb             mon_numwka+3
1222
        inx
1223
        cmpx    #9
1224
        blo             gthxn2
1225
gthxn1:
1226
        tfr             x,d
1227
        puls    x,pc
1228
 
1229
;GetDecNumber:
1230
;       phx
1231
;       push    r4
1232
;       push    r5
1233
;       ldx             #0
1234
;       ld              r4,#10
1235
;       ld              r5,#10
1236
;gtdcn2:
1237
;       jsr             MonGetch
1238
;       jsr             AsciiToDecNybble
1239
;       cmp             #-1
1240
;       beq             gtdcn1
1241
;       mul             r2,r2,r5
1242
;       add             r2,r1
1243
;       dec             r4
1244
;       bne             gtdcn2
1245
;gtdcn1:
1246
;       txa
1247
;       pop             r5
1248
;       pop             r4
1249
;       plx
1250
;       rts
1251
 
1252
;------------------------------------------------------------------------------
1253
; Convert ASCII character in the range '0' to '9', 'a' to 'f' or 'A' to 'F'
1254
; to a hex nybble.
1255
;------------------------------------------------------------------------------
1256
;
1257
AsciiToHexNybble:
1258
        cmpb    #'0'
1259
        bcc             gthx3
1260
        cmpb    #'9'+1
1261
        bcs             gthx5
1262
        subb    #'0'
1263
        rts
1264
gthx5:
1265
        cmpb    #'A'
1266
        bcc             gthx3
1267
        cmpb    #'F'+1
1268
        bcs             gthx6
1269
        subb    #'A'
1270
        addb    #10
1271
        rts
1272
gthx6:
1273
        cmpb    #'a'
1274
        bcc             gthx3
1275
        cmpb    #'z'+1
1276
        bcs             gthx3
1277
        subb    #'a'
1278
        addb    #10
1279
        rts
1280
gthx3:
1281
        ldb             #-1             ; not a hex number
1282
        rts
1283
 
1284
AsciiToDecNybble:
1285
        cmpb    #'0'
1286
        bcc             gtdc3
1287
        cmpb    #'9'+1
1288
        bcs             gtdc3
1289
        subb    #'0'
1290
        rts
1291
gtdc3:
1292
        ldb             #-1
1293
        rts
1294
 
1295
DisplayErr:
1296
        ldx             #msgErr
1297
        clrd
1298
        bsr             DisplayStringDX
1299
        jmp             Monitor
1300
 
1301
DisplayStringDX
1302
        std             Strptr
1303
        stx             Strptr+2
1304
        jsr             DisplayString
1305
        rts
1306
 
1307
msgErr:
1308
        fcb     "**Err",CR,LF,0
1309
 
1310
HelpMsg:
1311
        fcb             "? = Display help",CR,LF
1312
        fcb     "CLS = clear screen",CR,LF
1313
;       db      "S = Boot from SD Card",CR,LF
1314
;       db      ": = Edit memory bytes",CR,LF
1315
;       db      "L = Load sector",CR,LF
1316
;       db      "W = Write sector",CR,LF
1317
        fcb "DR = Dump registers",CR,LF
1318
;       db      "D = Dump memory",CR,LF
1319
;       db      "F = Fill memory",CR,LF
1320
;       db  "FL = Dump I/O Focus List",CR,LF
1321
        fcb "FIG = start FIG Forth",CR,LF
1322
;       db      "KILL n = kill task #n",CR,LF
1323
;       db      "B = start tiny basic",CR,LF
1324
;       db      "b = start EhBasic 6502",CR,LF
1325
        fcb     "J = Jump to code",CR,LF
1326
        fcb "RAM = test RAM",CR,LF
1327
;       db      "R[n] = Set register value",CR,LF
1328
;       db      "r = random lines - test bitmap",CR,LF
1329
;       db      "e = ethernet test",CR,LF
1330
;       db      "T = Dump task list",CR,LF
1331
;       db      "TO = Dump timeout list",CR,LF
1332
;       db      "TI = display date/time",CR,LF
1333
;       db      "TEMP = display temperature",CR,LF
1334
;       db      "P = Piano",CR,LF,0
1335
        fcb             0
1336
 
1337
msgRegHeadings
1338
        fcb     CR,LF," D/AB   X    Y    U    S     PC    DP CCR",CR,LF,0
1339
 
1340
nHEX4:
1341
        jsr             HEX4
1342
        rts
1343
 
1344
nXBLANK:
1345
        ldb             #' '
1346
        bra             OUTCH
1347
 
1348
DumpRegs
1349
        ldx             #msgRegHeadings
1350
        ldd             #msgRegHeadings>>16
1351
        jsr             DisplayStringDX
1352
        bsr             nXBLANK
1353
        ldd             mon_DSAVE
1354
        bsr             nHEX4
1355
        bsr             nXBLANK
1356
        ldd             mon_XSAVE
1357
        bsr             nHEX4
1358
        bsr             nXBLANK
1359
        ldd             mon_YSAVE
1360
        bsr             nHEX4
1361
        bsr             nXBLANK
1362
        ldd             mon_USAVE
1363
        bsr             nHEX4
1364
        bsr             nXBLANK
1365
        ldd             mon_SSAVE
1366
        bsr             nHEX4
1367
        bsr             nXBLANK
1368
        ldd             mon_PCSAVE
1369
        bsr             nHEX4
1370
        ldd             mon_PCSAVE+2
1371
        bsr             nHEX4
1372
        bsr             nXBLANK
1373
        ldd             mon_DPRSAVE
1374
        jsr             HEX2
1375
        bsr             nXBLANK
1376
        lda             mon_CCRSAVE
1377
        jsr             HEX2
1378
        bsr             nXBLANK
1379
        jmp             Monitor
1380
 
1381
; Jump to code
1382
jump_to_code:
1383
        bsr             GetHexNumber
1384
        sei
1385
        lds             mon_SSAVE
1386
        ldd             #
1387
        pshs    d
1388
        ldd             #>jtc_exit
1389
        pshs    b
1390
        ldd             mon_numwka+2
1391
        pshs    d
1392
        ldd             mon_numwka
1393
        pshs    d
1394
        ldd             mon_USAVE
1395
        pshs    d
1396
        ldd             mon_YSAVE
1397
        pshs    d
1398
        ldd             mon_XSAVE
1399
        pshs    d
1400
        lda             mon_DPRSave
1401
        pshs    a
1402
        ldd             mon_DSAVE
1403
        pshs    d
1404
        lda             mon_CCRSAVE
1405
        pshs    a
1406
        puls    far ccr,d,dpr,x,y,u,pc
1407
jtc_exit:
1408
        pshs    ccr
1409
        std             mon_DSAVE
1410
        stx             mon_XSAVE
1411
        sty             mon_YSAVE
1412
        stu             mon_USAVE
1413
        tfr             dpr,a
1414
        sta             mon_DPRSAVE
1415
        puls    a
1416
        sta             mon_CCRSAVE
1417
        sts             mon_SSAVE
1418
        lds             #$3FFF
1419
        ; todo set according to coreid
1420
        jmp             DumpRegs
1421
 
1422
;------------------------------------------------------------------------------
1423
;------------------------------------------------------------------------------
1424
swi3_rout:
1425
        sei
1426
        puls    a
1427
        sta             mon_CCRSAVE
1428
        puls    D,DPR,X,Y,U
1429
        std             mon_DSAVE
1430
        stx             mon_XSAVE
1431
        sty             mon_YSAVE
1432
        stu             mon_USAVE
1433
        tfr             dpr,a
1434
        sta             mon_DPRSAVE
1435
        puls    D
1436
        std             mon_PCSAVE
1437
        puls    D
1438
        std             mon_PCSAVE+2
1439
        sts             mon_SSAVE
1440
        lds             #$3FFF
1441
        cli
1442
        jmp             DumpRegs
1443
swi3_exit:
1444
        sei
1445
        lds             mon_SSAVE
1446
        ldd             mon_PCSAVE+2
1447
        pshs    d
1448
        ldd             mon_PCSAVE
1449
        pshs    d
1450
        ldu             mon_USAVE
1451
        ldy             mon_YSAVE
1452
        ldx             mon_XSAVE
1453
        pshs    x,y,u
1454
        lda             mon_DPRSAVE
1455
        pshs    a
1456
        ldd             mon_DSAVE
1457
        pshs    d
1458
        lda             mon_CCRSAVE
1459
        pshs    a
1460
        tfr             a,ccr
1461
        cli
1462
        rti
1463
 
1464
;------------------------------------------------------------------------------
1465
;------------------------------------------------------------------------------
1466
irq_rout:
1467
        ; Reset the edge sense circuit in the PIC
1468
        lda             #2                              ; Timer is IRQ #2
1469
        sta             PIC+6                   ; register 6 is edge sense reset reg
1470
 
1471
        sta             IrqSource               ; stuff a byte indicating the IRQ source for PEEK()
1472
        lda             IrqBase                 ; get the IRQ flag byte
1473
        lsra
1474
        ora             IrqBase
1475
        anda    #$E0
1476
        sta             IrqBase
1477
 
1478
        inc             TEXTSCR+110             ; update IRQ live indicator on screen
1479
 
1480
        ; flash the cursor
1481
        ; only bother to flash the cursor for the task with the IO focus.
1482
        lda             COREID
1483
        cmpa    IOFocusID
1484
        bne             tr1a
1485
        lda             CursorFlash             ; test if we want a flashing cursor
1486
        beq             tr1a
1487
        lbsr    CalcScreenLoc   ; compute cursor location in memory
1488
        tfr             d,y
1489
        lda             $2000,y                 ; get color code $2000 higher in memory
1490
        ldb             IRQFlag                 ; get counter
1491
        lsrb
1492
        lsra
1493
        lsra
1494
        lsra
1495
        lsra
1496
        lsrb
1497
        rola
1498
        lsrb
1499
        rola
1500
        lsrb
1501
        rola
1502
        lsrb
1503
        rola
1504
        sta             $E00000,y               ; store the color code back to memory
1505
tr1a
1506
        rti
1507
 
1508
;------------------------------------------------------------------------------
1509
;------------------------------------------------------------------------------
1510
nmi_rout:
1511
        ldb             COREID
1512
        lda             #'I'
1513
        ldx             #TEXTSCR+40
1514
        abx
1515
        sta             ,x
1516
        rti
1517
 
1518
        org             $FFFFF0
1519
        nop
1520
        nop
1521
        fcw             swi3_rout
1522
 
1523
        org             $FFFFF8
1524
        fcw             irq_rout
1525
        fcw             start                           ; SWI
1526
        fcw             nmi_rout                ; NMI
1527
        fcw             start                           ; RST

powered by: WebSVN 2.1.0

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