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

Subversion Repositories rf6809

[/] [rf6809/] [trunk/] [software/] [boot/] [boot_rom.asm] - Diff between revs 13 and 14

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 13 Rev 14
; ============================================================================
; ============================================================================
;        __
;        __
;   \\__/ o\    (C) 2013-2022  Robert Finch, Waterloo
;   \\__/ o\    (C) 2013-2022  Robert Finch, Waterloo
;    \  __ /    All rights reserved.
;    \  __ /    All rights reserved.
;     \/_//     robfinch@opencores.org
;     \/_//     robfinch@opencores.org
;       ||
;       ||
;
;
;
;
; BSD 3-Clause License
; BSD 3-Clause License
; Redistribution and use in source and binary forms, with or without
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions are met:
; modification, are permitted provided that the following conditions are met:
;
;
; 1. Redistributions of source code must retain the above copyright notice, this
; 1. Redistributions of source code must retain the above copyright notice, this
;    list of conditions and the following disclaimer.
;    list of conditions and the following disclaimer.
;
;
; 2. Redistributions in binary form must reproduce the above copyright notice,
; 2. Redistributions in binary form must reproduce the above copyright notice,
;    this list of conditions and the following disclaimer in the documentation
;    this list of conditions and the following disclaimer in the documentation
;    and/or other materials provided with the distribution.
;    and/or other materials provided with the distribution.
;
;
; 3. Neither the name of the copyright holder nor the names of its
; 3. Neither the name of the copyright holder nor the names of its
;    contributors may be used to endorse or promote products derived from
;    contributors may be used to endorse or promote products derived from
;    this software without specific prior written permission.
;    this software without specific prior written permission.
;
;
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;
; ============================================================================
; ============================================================================
;
;
CR      EQU     $0D             ;ASCII equates
CR      EQU     $0D             ;ASCII equates
LF      EQU     $0A
LF      EQU     $0A
TAB     EQU     $09
TAB     EQU     $09
CTRLC   EQU     $03
CTRLC   EQU     $03
CTRLH   EQU     $08
CTRLH   EQU     $08
CTRLI   EQU     $09
CTRLI   EQU     $09
CTRLJ   EQU     $0A
CTRLJ   EQU     $0A
CTRLK   EQU     $0B
CTRLK   EQU     $0B
CTRLM   EQU $0D
CTRLM   EQU $0D
CTRLS   EQU     $13
CTRLS   EQU     $13
CTRLT EQU $14
CTRLT EQU $14
CTRLX   EQU     $18
CTRLX   EQU     $18
XON             EQU     $11
XON             EQU     $11
XOFF    EQU     $13
XOFF    EQU     $13
FIRST_CORE      EQU     1
FIRST_CORE      EQU     1
MAX_TASKNO      EQU 63
MAX_TASKNO      EQU 63
DRAM_BASE       EQU $10000000
DRAM_BASE       EQU $10000000
ScreenLocation          EQU             $10
ScreenLocation          EQU             $10
ColorCodeLocation       EQU             $14
ColorCodeLocation       EQU             $14
ScreenLocation2         EQU             $18
ScreenLocation2         EQU             $18
BlkcpySrc                       EQU             $1C
BlkcpySrc                       EQU             $1C
BlkcpyDst                       EQU             $20
BlkcpyDst                       EQU             $20
Strptr                          EQU             $24
Strptr                          EQU             $24
PICptr                          EQU             $28
PICptr                          EQU             $28
; Forth Area
; Forth Area
; 0x30-0x60
; 0x30-0x60
RunningID                       EQU             $800000
RunningID                       EQU             $800000
; Task control blocks, room for 256 tasks
; Task control blocks, room for 256 tasks
TCB_NxtRdy              EQU             $00     ; next task on ready / timeout list
TCB_NxtRdy              EQU             $00     ; next task on ready / timeout list
TCB_PrvRdy              EQU             $04     ; previous task on ready / timeout list
TCB_PrvRdy              EQU             $04     ; previous task on ready / timeout list
TCB_NxtTCB              EQU             $08
TCB_NxtTCB              EQU             $08
TCB_Timeout             EQU             $0C
TCB_Timeout             EQU             $0C
TCB_Priority    EQU             $10
TCB_Priority    EQU             $10
TCB_MSGPTR_D1   EQU             $14
TCB_MSGPTR_D1   EQU             $14
TCB_MSGPTR_D2   EQU             $18
TCB_MSGPTR_D2   EQU             $18
TCB_hJCB                        EQU             $1C
TCB_hJCB                        EQU             $1C
TCB_Status              EQU             $1E
TCB_Status              EQU             $1E
TCB_CursorRow   EQU             $20
TCB_CursorRow   EQU             $20
TCB_CursorCol   EQU             $21
TCB_CursorCol   EQU             $21
TCB_hWaitMbx    EQU             $22     ; handle of mailbox task is waiting at
TCB_hWaitMbx    EQU             $22     ; handle of mailbox task is waiting at
TCB_mbq_next    EQU             $24     ; mailbox queue next
TCB_mbq_next    EQU             $24     ; mailbox queue next
TCB_mbq_prev    EQU             $28     ; mailbox queue previous
TCB_mbq_prev    EQU             $28     ; mailbox queue previous
TCB_iof_next    EQU             $2C
TCB_iof_next    EQU             $2C
TCB_iof_prev    EQU             $30
TCB_iof_prev    EQU             $30
TCB_SPSave              EQU             $34     ; TCB_SPSave area
TCB_SPSave              EQU             $34     ; TCB_SPSave area
TCB_mmu_map             EQU             $38
TCB_mmu_map             EQU             $38
KeybdHead               EQU             $FFFFFC800
KeybdHead               EQU             $FFFFFC800
KeybdTail               EQU             $FFFFFC900
KeybdTail               EQU             $FFFFFC900
KeybdEcho               EQU             $FFFFFCA00
KeybdEcho               EQU             $FFFFFCA00
KeybdBad                EQU             $FFFFFCB00
KeybdBad                EQU             $FFFFFCB00
KeybdAck                EQU             $FFFFFCC00
KeybdAck                EQU             $FFFFFCC00
KeybdLocks              EQU             $FFFFFCD00
KeybdLocks              EQU             $FFFFFCD00
KeybdBuffer             EQU             $FFFFFC000      ; buffer is 16 chars
KeybdBuffer             EQU             $FFFFFC000      ; buffer is 16 chars
COREID  EQU             $FFFFFFFE0
COREID  EQU             $FFFFFFFE0
MSCOUNT EQU             $FFFFFFFE4
MSCOUNT EQU             $FFFFFFFE4
LEDS            EQU             $FFFE60001
LEDS            EQU             $FFFE60001
VIA                     EQU             $FFFE60000
VIA                     EQU             $FFFE60000
VIA_PA          EQU             1
VIA_PA          EQU             1
VIA_DDRA        EQU             3
VIA_DDRA        EQU             3
VIA_ACR                 EQU             11
VIA_ACR                 EQU             11
VIA_IFR                 EQU             13
VIA_IFR                 EQU             13
VIA_IER                 EQU             14
VIA_IER                 EQU             14
VIA_T3LL                EQU             18
VIA_T3LL                EQU             18
VIA_T3LH                EQU             19
VIA_T3LH                EQU             19
VIA_T3CMPL      EQU             20
VIA_T3CMPL      EQU             20
VIA_T3CMPH      EQU             21
VIA_T3CMPH      EQU             21
TEXTSCR         EQU             $FFFE00000
TEXTSCR         EQU             $FFFE00000
TEXTREG         EQU             $FFFE0DF00
TEXTREG         EQU             $FFFE0DF00
TEXT_COLS       EQU             0
TEXT_COLS       EQU             0
TEXT_ROWS       EQU             1
TEXT_ROWS       EQU             1
TEXT_CURPOS     EQU             34
TEXT_CURPOS     EQU             34
ACIA            EQU             $FFFE30100
ACIA            EQU             $FFFE30100
ACIA_TX         EQU             0
ACIA_TX         EQU             0
ACIA_RX         EQU             0
ACIA_RX         EQU             0
ACIA_STAT       EQU             1
ACIA_STAT       EQU             1
ACIA_CMD        EQU             2
ACIA_CMD        EQU             2
ACIA_CTRL       EQU             3
ACIA_CTRL       EQU             3
ACIA_CTRL2      EQU             11
ACIA_CTRL2      EQU             11
RTC                             EQU             $FFFE30500      ; I2C
RTC                             EQU             $FFFE30500      ; I2C
RTCBuf          EQU             $7FC0
RTCBuf          EQU             $7FC0
KEYBD           EQU             $FFFE30400
KEYBD           EQU             $FFFE30400
KEYBDCLR        EQU             $FFFE30402
KEYBDCLR        EQU             $FFFE30402
PIC                     EQU             $FFFE3F000
PIC                     EQU             $FFFE3F000
SPRITE_CTRL             EQU             $FFFE10000
SPRITE_CTRL             EQU             $FFFE10000
SPRITE_EN                       EQU             $3C0
SPRITE_EN                       EQU             $3C0
OUTSEMA EQU     $EF0000
OUTSEMA EQU     $EF0000
SEMAABS EQU     $1000
SEMAABS EQU     $1000
OSSEMA  EQU     $EF0010
OSSEMA  EQU     $EF0010
BIOS_SCREENS    EQU     $17000000       ; $17000000 to $171FFFFF
BIOS_SCREENS    EQU     $17000000       ; $17000000 to $171FFFFF
; EhBASIC vars:
; EhBASIC vars:
;
;
NmiBase         EQU             $FF0013
NmiBase         EQU             $FF0013
IrqBase         EQU             $FF0014
IrqBase         EQU             $FF0014
IOFocusNdx      EQU             $100
IOFocusNdx      EQU             $100
; These variables in global OS storage area
; These variables in global OS storage area
IOFocusList     EQU             $FF0000 ; to $FF000F
IOFocusList     EQU             $FF0000 ; to $FF000F
IOFocusID               EQU             $FF0010
IOFocusID               EQU             $FF0010
IrqSource               EQU             $FF0011
IrqSource               EQU             $FF0011
IRQFlag                 EQU             $FF0012
IRQFlag                 EQU             $FF0012
; These variables use direct page access
; These variables use direct page access
CursorRow       EQU             $110
CursorRow       EQU             $110
CursorCol       EQU             $111
CursorCol       EQU             $111
CharColor       EQU             $112
CharColor       EQU             $112
ScreenColor     EQU             $113
ScreenColor     EQU             $113
CursorFlash     EQU             $114
CursorFlash     EQU             $114
KeyState1       EQU     $120
KeyState1       EQU     $120
KeyState2       EQU     $121
KeyState2       EQU     $121
KeyLED          EQU     $122
KeyLED          EQU     $122
KeybdID         EQU     $124
KeybdID         EQU     $124
KeybdBlock      EQU     $126
KeybdBlock      EQU     $126
kbdHeadRcv      EQU     $127
kbdHeadRcv      EQU     $127
kbdTailRcv      EQU     $128
kbdTailRcv      EQU     $128
kbdFifo                 EQU     $40                             ; in local RAM
kbdFifo                 EQU     $40                             ; in local RAM
kbdFifoAlias    EQU     $C00040 ; to $C0007F    ; alias for $40 to $7F
kbdFifoAlias    EQU     $C00040 ; to $C0007F    ; alias for $40 to $7F
SerhZero                EQU     $130
SerhZero                EQU     $130
SerHeadRcv      EQU     $131
SerHeadRcv      EQU     $131
SertZero                EQU     $132
SertZero                EQU     $132
SerTailRcv      EQU     $133
SerTailRcv      EQU     $133
SerHeadXmit     EQU     $136
SerHeadXmit     EQU     $136
SerTailXmit     EQU     $138
SerTailXmit     EQU     $138
SerRcvXon               EQU     $139
SerRcvXon               EQU     $139
SerRcvXoff      EQU     $140
SerRcvXoff      EQU     $140
SerRcvBuf               EQU     $BFF000 ; 4kB serial recieve buffer
SerRcvBuf               EQU     $BFF000 ; 4kB serial recieve buffer
 
 
 
farflag EQU             $15F
asmbuf  EQU             $160    ; to $17F
asmbuf  EQU             $160    ; to $17F
QNdx0           EQU             $780
QNdx0           EQU             $780
QNdx1           EQU             QNdx0+2
QNdx1           EQU             QNdx0+2
QNdx2           EQU             QNdx1+2
QNdx2           EQU             QNdx1+2
QNdx3           EQU             QNdx2+2
QNdx3           EQU             QNdx2+2
QNdx4           EQU             QNdx3+2
QNdx4           EQU             QNdx3+2
FreeTCB         EQU             QNdx4+2
FreeTCB         EQU             QNdx4+2
TimeoutList     EQU             FreeTCB+2
TimeoutList     EQU             FreeTCB+2
FreeMbx         EQU             RunningTCB + 2
FreeMbx         EQU             RunningTCB + 2
nMailbox        EQU             FreeMbx + 2
nMailbox        EQU             FreeMbx + 2
FreeMsg         EQU             nMailbox + 2
FreeMsg         EQU             nMailbox + 2
nMsgBlk         EQU             FreeMsg + 2
nMsgBlk         EQU             FreeMsg + 2
CharOutVec      EQU             $800
CharOutVec      EQU             $800
CharInVec       EQU             $804
CharInVec       EQU             $804
CmdPromptJI     EQU     $808
CmdPromptJI     EQU     $808
 
MonErrVec       EQU             $80C
 
 
; Register save area for monitor
; Register save area for monitor
mon_DSAVE       EQU             $900
mon_DSAVE       EQU             $900
mon_XSAVE       EQU             $902
mon_XSAVE       EQU             $902
mon_YSAVE       EQU             $904
mon_YSAVE       EQU             $904
mon_USAVE       EQU             $906
mon_USAVE       EQU             $906
mon_SSAVE       EQU             $908
mon_SSAVE       EQU             $908
mon_PCSAVE      EQU             $90A
mon_PCSAVE      EQU             $90A
mon_DPRSAVE     EQU             $90E
mon_DPRSAVE     EQU             $90E
mon_CCRSAVE     EQU             $90F
mon_CCRSAVE     EQU             $90F
mon_numwka      EQU             $910
mon_numwka      EQU             $910
mon_r1          EQU             $920
mon_r1          EQU             $920
mon_r2          EQU             $924
mon_r2          EQU             $924
; The ORG directive must set an address a multiple of 4 in order for the Verilog
; The ORG directive must set an address a multiple of 4 in order for the Verilog
; output to work correctly.
; output to work correctly.
        org             $FFD0AC
        org             $FFD0AC
        nop
        nop
        nop
        nop
        nop
        nop
XBLANK
XBLANK
        ldb             #' '
        ldb             #' '
        lbsr    OUTCH
        lbsr    OUTCH
        rts
        rts
        org             $FFD0D0
        org             $FFD0D0
        nop
        nop
        nop
        nop
CRLF
CRLF
CRLF1:
CRLF1:
        ldb             #CR
        ldb             #CR
        lbsr    OUTCH
        lbsr    OUTCH
        ldb             #LF
        ldb             #LF
        lbsr    OUTCH
        lbsr    OUTCH
        rts
        rts
        org             $FFD0F0
        org             $FFD0F0
        nop
        nop
        bra             CRLF1
        bra             CRLF1
        org             $FFD1DC
        org             $FFD1DC
ONEKEY
ONEKEY
        jmp             [CharInVec]
        jmp             [CharInVec]
        org             $FFD2C0
        org             $FFD2C0
        nop
        nop
LETTER
LETTER
        lbsr    OUTCH
        lbsr    OUTCH
        rts
        rts
        org             $FFD2CC
        org             $FFD2CC
        nop
        nop
        nop
        nop
HEX2
HEX2
        lbsr    DispByteAsHex
        lbsr    DispByteAsHex
        rts
        rts
HEX4
HEX4
        lbsr    DispWordAsHex
        lbsr    DispWordAsHex
        rts
        rts
        org             $FFD300
        org             $FFD300
ClearScreenJmp
ClearScreenJmp
        lbra    ClearScreen
        lbra    ClearScreen
        org             $FFD308
        org             $FFD308
HomeCursorJmp
HomeCursorJmp
        lbra    HomeCursor
        lbra    HomeCursor
        org             $FFD400
        org             $FFD400
; Local RAM test routine
; Local RAM test routine
; Checkerboard testing.
; Checkerboard testing.
; There is 70kB of local RAM
; There is 70kB of local RAM
; Does not use any RAM including no stack
; Does not use any RAM including no stack
ramtest:
ramtest:
        ldy             #0
        ldy             #0
        lda             #1
        lda             #1
        sta             LEDS
        sta             LEDS
        ldd             #$AAA555
        ldd             #$AAA555
ramtest1:
ramtest1:
        std             ,y++
        std             ,y++
        cmpy    #$8000
        cmpy    #$8000
        blo             ramtest1
        blo             ramtest1
        ; now readback values and compare
        ; now readback values and compare
        ldy             #0
        ldy             #0
ramtest3:
ramtest3:
        ldd             ,y++
        ldd             ,y++
        cmpd    #$AAA555
        cmpd    #$AAA555
        bne             ramerr
        bne             ramerr
        cmpy    #$8000
        cmpy    #$8000
        blo             ramtest3
        blo             ramtest3
        lda             #2
        lda             #2
        sta             LEDS
        sta             LEDS
        jmp             ,u
        jmp             ,u
ramerr:
ramerr:
        lda             #$80
        lda             #$80
        sta             LEDS
        sta             LEDS
        ldx             #TEXTSCR
        ldx             #TEXTSCR
        ldb             COREID
        ldb             COREID
        abx
        abx
        lda             #'F'
        lda             #'F'
        sta             ,x
        sta             ,x
        sync
        sync
        jmp             ,u
        jmp             ,u
        org             $FFE000
        org             $FFE000
        FDB Monitor
        FDB Monitor
        FDB DumRts      ;       NEXTCMD
        FDB DumRts      ;       NEXTCMD
        FDB INCH
        FDB INCH
        FDB INCHE
        FDB INCHE
        FDB INCHEK
        FDB INCHEK
        FDB OUTCH
        FDB OUTCH
        FDB PDATA
        FDB PDATA
        FDB PCRLF
        FDB PCRLF
        FDB PSTRNG
        FDB PSTRNG
        FDB DumRts                      ; LRA
        FDB DumRts                      ; LRA
        FDB DumRts
        FDB DumRts
        FDB DumRts
        FDB DumRts
        FDB DumRts
        FDB DumRts
        FDB DumRts                      ; VINIZ
        FDB DumRts                      ; VINIZ
        FDB DisplayChar ;       VOUTCH
        FDB DisplayChar ;       VOUTCH
        FDB DumRts                      ; ACINIZ
        FDB DumRts                      ; ACINIZ
        FDB DumRts                      ; AOUTCH
        FDB DumRts                      ; AOUTCH
DumRts:
DumRts:
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
start:
start:
        lda             #$FFF                   ; all cores can do this
        lda             #$FFF                   ; all cores can do this
        sta             VIA+VIA_DDRA
        sta             VIA+VIA_DDRA
        lda             #$55                    ; see if we can at least set LEDs
        lda             #$55                    ; see if we can at least set LEDs
        sta             LEDS
        sta             LEDS
        lda             #1                              ; prime OS semaphore
        lda             #1                              ; prime OS semaphore
        sta             OSSEMA+$1000
        sta             OSSEMA+$1000
        ldu             #st6                    ; U = return address
        ldu             #st6                    ; U = return address
        jmp             ramtest         ; JMP dont JSR
        jmp             ramtest         ; JMP dont JSR
st6:
st6:
        lds             #$6FFF          ; boot up stack area
        lds             #$6FFF          ; boot up stack area
        lda             COREID
        lda             COREID
        cmpa    #FIRST_CORE
        cmpa    #FIRST_CORE
;       beq             st8
;       beq             st8
;       sync                                            ; halt cores other than 2
;       sync                                            ; halt cores other than 2
st8:
st8:
;       bne             skip_init
;       bne             skip_init
;       bsr             romToRam
;       bsr             romToRam
;       ldd             #st7 & $FFFF
;       ldd             #st7 & $FFFF
;       tfr             d,x
;       tfr             d,x
;       jmp             ,x                              ; jump to the BIOS now in local RAM
;       jmp             ,x                              ; jump to the BIOS now in local RAM
st7:
st7:
        bsr             Delay3s         ; give some time for devices to reset
        bsr             Delay3s         ; give some time for devices to reset
        lda             #$AA
        lda             #$AA
        sta             LEDS
        sta             LEDS
        lda             #FIRST_CORE
        lda             #FIRST_CORE
        sta             IOFocusID       ; core #2 has focus
        sta             IOFocusID       ; core #2 has focus
        sta             RunningID
        sta             RunningID
 
        ; Clear IO focus list
 
        ldx             #0
 
st9:
 
        clr             IOFocusList,x
 
        inx
 
        cmpx    #16
 
        blo             st9
 
        lda             #24
 
        sta             IOFocusList+FIRST_CORE
 
 
        lda             #$0CE
        lda             #$0CE
        sta             ScreenColor
        sta             ScreenColor
        sta             CharColor
        sta             CharColor
        bsr             ClearScreen
        bsr             ClearScreen
        ldd             #DisplayChar
        ldd             #DisplayChar
        std             CharOutVec
        std             CharOutVec
        ldd             #SerialPeekCharDirect
        ldd             #SerialPeekCharDirect
        std             CharInVec
        std             CharInVec
        ldb             #24                             ; request IO focus
        ldb             #24                             ; request IO focus
        lbsr    OSCall
        lbsr    OSCall
        ldb             COREID
        ldb             COREID
        cmpb    #FIRST_CORE
        cmpb    #FIRST_CORE
        beq             init
        beq             init
        bra             skip_init
        bra             skip_init
        bra             multi_sieve
        bra             multi_sieve
st3:
st3:
        lda             #$FF
        lda             #$FF
        sta             LEDS
        sta             LEDS
        bra             st3
        bra             st3
        ; initialize interrupt controller
        ; initialize interrupt controller
        ; first, zero out all the vectors
        ; first, zero out all the vectors
init:
init:
        lbsr    rtc_read        ; get clock values
        lbsr    rtc_read        ; get clock values
        ldx             #kbdHeadRcv
        ldx             #kbdHeadRcv
        ldb             #32                             ; number of bytes to zero out
        ldb             #32                             ; number of bytes to zero out
init1:
init1:
        clr             ,x+
        clr             ,x+
        decb
        decb
        bne             init1
        bne             init1
        lbsr    TimerInit
        lbsr    TimerInit
        lbsr    InitSerial
        lbsr    InitSerial
        ldx             #128
        ldx             #128
        lda             #1                      ; set irq(bit0), clear firq (bit1), disable int (bit 6), clear edge sense(bit 7)
        lda             #1                      ; set irq(bit0), clear firq (bit1), disable int (bit 6), clear edge sense(bit 7)
        ldb             #FIRST_CORE                     ; serving core id
        ldb             #FIRST_CORE                     ; serving core id
st1:
st1:
        clr             PIC,x                   ; cause code
        clr             PIC,x                   ; cause code
        sta             PIC+1,x
        sta             PIC+1,x
        stb             PIC+2,x
        stb             PIC+2,x
        leax    4,x
        leax    4,x
        cmpx    #256
        cmpx    #256
        blo             st1
        blo             st1
;       lda             #4                              ; make the timer interrupt edge sensitive
;       lda             #4                              ; make the timer interrupt edge sensitive
;       sta             PIC+4                   ; reg #4 is the edge sensitivity setting
;       sta             PIC+4                   ; reg #4 is the edge sensitivity setting
;       sta             PIC                             ; reg #0 is interrupt enable
;       sta             PIC                             ; reg #0 is interrupt enable
        lda             #$81                    ; make irq edge sensitive
        lda             #$81                    ; make irq edge sensitive
        sta             PIC+$FD
        sta             PIC+$FD
        lda             #31                             ; enable timer interrupt
        lda             #31                             ; enable timer interrupt
;       sta             PIC+9
;       sta             PIC+9
        ldb             #1
        ldb             #1
        stb             OUTSEMA+SEMAABS ; set semaphore to 1 available slot
        stb             OUTSEMA+SEMAABS ; set semaphore to 1 available slot
skip_init:
skip_init:
        andcc   #$EF                    ; unmask irq
        andcc   #$EF                    ; unmask irq
        lda             #56
        lda             #56
        sta             TEXTREG+TEXT_COLS
        sta             TEXTREG+TEXT_COLS
        lda             #29
        lda             #29
        sta             TEXTREG+TEXT_ROWS
        sta             TEXTREG+TEXT_ROWS
        bsr             ClearScreen
        bsr             ClearScreen
        bsr             HomeCursor
        bsr             HomeCursor
        lda             #5
        lda             #5
        sta             LEDS
        sta             LEDS
        ldd             #msgStartup
        ldd             #msgStartup
        bsr             DisplayString
        bsr             DisplayString
        ldx             #0
        ldx             #0
        ldd             #0
        ldd             #0
        lbsr    ShowSprites
        lbsr    ShowSprites
        lbsr    KeybdInit
        lbsr    KeybdInit
        ldd             KeybdID
        ldd             KeybdID
        bsr             DispWordAsHex
        bsr             DispWordAsHex
        jmp             MonitorStart
        jmp             MonitorStart
msgStartup
msgStartup
        fcb             "rf6809 12-bit System Starting.",CR,LF,0
        fcb             "rf6809 12-bit System Starting.",CR,LF,0
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; The checkpoint register must be cleared within 1 second or a NMI interrupt
; The checkpoint register must be cleared within 1 second or a NMI interrupt
; will occur. checkpoint should be called with a JSR so that the global ROM
; will occur. checkpoint should be called with a JSR so that the global ROM
; routine is called.
; routine is called.
;
;
; Modifies:
; Modifies:
;               none
;               none
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
checkpoint:
checkpoint:
        clr             $FFFFFFFE1      ; writing any value will do
        clr             $FFFFFFFE1      ; writing any value will do
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Copy the system ROM to local RAM
; Copy the system ROM to local RAM
; Running the code from local RAM is probably an order of magnitude faster
; Running the code from local RAM is probably an order of magnitude faster
; then running from the global ROM. It also reduces the network traffic to
; then running from the global ROM. It also reduces the network traffic to
; run from local RAM.
; run from local RAM.
;
;
; Modifies:
; Modifies:
;               d,x,y
;               d,x,y
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
romToRam:
romToRam:
        ldx             #$FFC000
        ldx             #$FFC000
        ldy             #$00C000
        ldy             #$00C000
romToRam1:
romToRam1:
        ldd             ,x++
        ldd             ,x++
        std             ,y++
        std             ,y++
        cmpx    #0
        cmpx    #0
        bne             romToRam1
        bne             romToRam1
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Multi-core sieve program.
; Multi-core sieve program.
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; First fill screen chars with 'P' indicating prime positions
; First fill screen chars with 'P' indicating prime positions
; Each core is responsible for the Nth position where N is the
; Each core is responsible for the Nth position where N is the
; core number minus two.
; core number minus two.
;
;
multi_sieve:
multi_sieve:
        lda             #'P'                                    ; indicate prime
        lda             #'P'                                    ; indicate prime
        ldb             COREID                          ; find out which core we are
        ldb             COREID                          ; find out which core we are
        subb    #FIRST_CORE
        subb    #FIRST_CORE
        ldx             #0                                              ; start at first char of screen
        ldx             #0                                              ; start at first char of screen
        abx
        abx
multi_sieve3:
multi_sieve3:
        sta             TEXTSCR,x                       ; store 'P'
        sta             TEXTSCR,x                       ; store 'P'
        leax    8,x                                             ; advance to next position
        leax    8,x                                             ; advance to next position
        cmpx    #4095
        cmpx    #4095
        blo             multi_sieve3
        blo             multi_sieve3
        jsr             checkpoint
        jsr             checkpoint
        addb    #2                                              ; start sieve at 2 (core id)
        addb    #2                                              ; start sieve at 2 (core id)
        lda             #'N'                                    ; flag position value of 'N' for non-prime
        lda             #'N'                                    ; flag position value of 'N' for non-prime
multi_sieve2:
multi_sieve2:
        ldx             #0
        ldx             #0
        abx                                                                     ; skip the first position - might be prime
        abx                                                                     ; skip the first position - might be prime
multi_sieve1:
multi_sieve1:
        abx                                                                     ; increment
        abx                                                                     ; increment
        sta             TEXTSCR,x
        sta             TEXTSCR,x
        cmpx    #4095
        cmpx    #4095
        blo             multi_sieve1
        blo             multi_sieve1
        jsr             checkpoint
        jsr             checkpoint
        addb    #8                                              ; number of cores working on it
        addb    #8                                              ; number of cores working on it
        cmpb    #4080
        cmpb    #4080
        blo             multi_sieve2
        blo             multi_sieve2
multi_sieve4:                                   ; hang machine
multi_sieve4:                                   ; hang machine
        sync
        sync
        lbra    Monitor
        lbra    Monitor
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Single core sieve.
; Single core sieve.
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
sieve:
sieve:
        lda             #'P'                                    ; indicate prime
        lda             #'P'                                    ; indicate prime
        ldx             #0                                              ; start at first char of screen
        ldx             #0                                              ; start at first char of screen
sieve3:
sieve3:
        sta             TEXTSCR,x                       ; store 'P'
        sta             TEXTSCR,x                       ; store 'P'
        inx                                                                     ; advance to next position
        inx                                                                     ; advance to next position
        cmpx    #4095
        cmpx    #4095
        blo             sieve3
        blo             sieve3
        ldb             #2                                              ; start sieve at 2
        ldb             #2                                              ; start sieve at 2
        lda             #'N'                                    ; flag position value of 'N' for non-prime
        lda             #'N'                                    ; flag position value of 'N' for non-prime
sieve2:
sieve2:
        ldx             #0
        ldx             #0
        abx                                                                     ; skip the first position - might be prime
        abx                                                                     ; skip the first position - might be prime
sieve1:
sieve1:
        abx                                                                     ; increment
        abx                                                                     ; increment
        sta             TEXTSCR,x
        sta             TEXTSCR,x
        cmpx    #4095
        cmpx    #4095
        blo             multi_sieve1
        blo             multi_sieve1
        incb                                                            ; number of cores working on it
        incb                                                            ; number of cores working on it
        cmpb    #4080
        cmpb    #4080
        blo             sieve2
        blo             sieve2
sieve4:                                                         ; hang machine
sieve4:                                                         ; hang machine
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Three second delay for user convenience and to allow some devices time to
; Three second delay for user convenience and to allow some devices time to
; reset.
; reset.
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
Delay3s:
Delay3s:
        ldd             #9000000
        ldd             #9000000
dly3s1:
dly3s1:
        cmpb    #$FF
        cmpb    #$FF
        bne             dly3s2
        bne             dly3s2
dly3s2:
dly3s2:
        sta             LEDS
        sta             LEDS
        subd    #1
        subd    #1
        bne             dly3s1
        bne             dly3s1
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
ShiftLeft5:
ShiftLeft5:
        aslb
        aslb
        rola
        rola
        aslb
        aslb
        rola
        rola
        aslb
        aslb
        rola
        rola
        aslb
        aslb
        rola
        rola
        aslb
        aslb
        rola
        rola
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Parameters:
; Parameters:
;               b = core id of core to copy
;               b = core id of core to copy
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
CopyVirtualScreenToScreen:
CopyVirtualScreenToScreen:
        pshs    d,x,y,u
        pshs    d,x,y,u
        ; Compute virtual screen location for core passed in accb.
        ; Compute virtual screen location for core passed in accb.
        tfr             b,a
        tfr             b,a
        asla
        asla
        asla
        asla
        asla
        asla
        asla
        asla
        ora             #$C00
        ora             #$C00
        clrb
        clrb
        tfr             d,x
        tfr             d,x
        pshs    d
        pshs    d
        ldy             #TEXTSCR
        ldy             #TEXTSCR
        ldu             #56*29/2
        ldu             #56*29/2
cv2s1:
cv2s1:
        ldd             ,x++
        ldd             ,x++
        std             ,y++
        std             ,y++
        leau    -1,u
        leau    -1,u
        cmpu    #0
        cmpu    #0
        bne             cv2s1
        bne             cv2s1
        ; reset the cursor position in the text controller
        ; reset the cursor position in the text controller
        puls    x
        puls    x
        ldb             CursorRow,x
        ldb             CursorRow,x
        lda             #56
        lda             #56
        mul
        mul
        tfr             d,y
        tfr             d,y
        ldb             CursorCol,x
        ldb             CursorCol,x
        tfr             y,x
        tfr             y,x
        abx
        abx
        stx             TEXTREG+TEXT_CURPOS
        stx             TEXTREG+TEXT_CURPOS
        puls    d,x,y,u,pc
        puls    d,x,y,u,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
CopyScreenToVirtualScreen:
CopyScreenToVirtualScreen:
        pshs    d,x,y,u
        pshs    d,x,y,u
        bsr             GetScreenLocation
        bsr             GetScreenLocation
        tfr             d,y
        tfr             d,y
        ldx             #TEXTSCR
        ldx             #TEXTSCR
        ldu             #56*29/2
        ldu             #56*29/2
cs2v1:
cs2v1:
        ldd             ,x++
        ldd             ,x++
        std             ,y++
        std             ,y++
        leau    -1,u
        leau    -1,u
        cmpu    #0
        cmpu    #0
        bne             cs2v1
        bne             cs2v1
        puls    d,x,y,u,pc
        puls    d,x,y,u,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
        fcb             "TEXTSCR "
        fcb             "TEXTSCR "
        fcw             TextOpen
        fcw             TextOpen
        fcw             TextClose
        fcw             TextClose
        fcw             TextRead
        fcw             TextRead
        fcw             TextWrite
        fcw             TextWrite
        fcw             TextSeek
        fcw             TextSeek
TextOpen:
TextOpen:
        rts
        rts
TextClose:
TextClose:
        rts
        rts
TextRead:
TextRead:
        rts
        rts
TextWrite:
TextWrite:
        rts
        rts
TextSeek:
TextSeek:
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Clear the screen and the screen color memory
; Clear the screen and the screen color memory
; We clear the screen to give a visual indication that the system
; We clear the screen to give a visual indication that the system
; is working at all.
; is working at all.
;
;
; Modifies:
; Modifies:
;               none
;               none
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
ClearScreen:
ClearScreen:
        pshs    d,x,y,u
        pshs    d,x,y,u
        ldx             #56*29
        ldx             #56*29
        tfr             x,u
        tfr             x,u
        bsr             GetScreenLocation
        bsr             GetScreenLocation
        tfr             d,y
        tfr             d,y
        ldb             #' '                            ; space char
        ldb             #' '                            ; space char
cs1:
cs1:
        stb             ,y+                                     ; set text to space
        stb             ,y+                                     ; set text to space
        leax    -1,x                            ; decrement x
        leax    -1,x                            ; decrement x
        bne             cs1
        bne             cs1
        ldb             COREID                  ; update colors only if we have focus
        ldb             COREID                  ; update colors only if we have focus
        cmpb    IOFocusID
        cmpb    IOFocusID
        bra             cs3
        bra             cs3
        ldy             #TEXTSCR+$2000
        ldy             #TEXTSCR+$2000
;       lda             CharColor
;       lda             CharColor
        lda             #$0CE
        lda             #$0CE
        tfr             u,x                                     ; get back count
        tfr             u,x                                     ; get back count
cs2:
cs2:
        sta             ,y+
        sta             ,y+
        dex                                                             ; decrement x
        dex                                                             ; decrement x
        bne             cs2
        bne             cs2
cs3:
cs3:
        puls    d,x,y,u,pc
        puls    d,x,y,u,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Scroll text on the screen upwards
; Scroll text on the screen upwards
;
;
; Modifies:
; Modifies:
;               none
;               none
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
ScrollUp:
ScrollUp:
        pshs    d,x,y,u
        pshs    d,x,y,u
        ldy             #(56*29-1)/2    ; y = num chars/2 to move
        ldy             #(56*29-1)/2    ; y = num chars/2 to move
        bsr             GetScreenLocation
        bsr             GetScreenLocation
        tfr             d,x
        tfr             d,x
        tfr             d,u
        tfr             d,u
        leax    56,x                    ; x = index to source row
        leax    56,x                    ; x = index to source row
scrup1:
scrup1:
        ldd             ,x++                    ; move 2 characters
        ldd             ,x++                    ; move 2 characters
        std             ,u++
        std             ,u++
        dey
        dey
        bne             scrup1
        bne             scrup1
        lda             #29
        lda             #29
        bsr             BlankLine
        bsr             BlankLine
        puls    d,x,y,u,pc
        puls    d,x,y,u,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Blank out a line on the display
; Blank out a line on the display
;
;
; Modifies:
; Modifies:
;               none
;               none
; Parameters:
; Parameters:
;       acca = line number to blank
;       acca = line number to blank
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
BlankLine:
BlankLine:
        pshs    d,x
        pshs    d,x
        pshs    a
        pshs    a
        bsr             GetScreenLocation
        bsr             GetScreenLocation
        tfr             d,x
        tfr             d,x
        puls    a
        puls    a
        ldb             #56             ; b = # chars to blank out from video controller
        ldb             #56             ; b = # chars to blank out from video controller
        mul                                     ; d = screen index (row# * #cols)
        mul                                     ; d = screen index (row# * #cols)
        leax    d,x
        leax    d,x
        lda             #' '
        lda             #' '
        ldb             #56             ; b = # chars to blank out from video controller
        ldb             #56             ; b = # chars to blank out from video controller
blnkln1:
blnkln1:
        sta             ,x+
        sta             ,x+
        decb
        decb
        bne             blnkln1
        bne             blnkln1
        puls    d,x,pc
        puls    d,x,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Get the location of the screen memory. The location
; Get the location of the screen memory. The location
; depends on whether or not the task has the output focus.
; depends on whether or not the task has the output focus.
;
;
; Modifies:
; Modifies:
;               d
;               d
; Retuns:
; Retuns:
;               d = screen location
;               d = screen location
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
GetScreenLocation:
GetScreenLocation:
        lda             COREID                  ; which core are we?
        lda             COREID                  ; which core are we?
        cmpa    IOFocusID               ; do we have the IO focus
        cmpa    IOFocusID               ; do we have the IO focus
        bne             gsl1                            ; no, go pick virtual screen address
        bne             gsl1                            ; no, go pick virtual screen address
        ldd             #TEXTSCR                ; yes, we update the real screen
        ldd             #TEXTSCR                ; yes, we update the real screen
        rts
        rts
gsl1:
gsl1:
        ldd             #$7800
        ldd             #$7800
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; HomeCursor
; HomeCursor
; Set the cursor location to the top left of the screen.
; Set the cursor location to the top left of the screen.
;
;
; Modifies:
; Modifies:
;               none
;               none
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
HomeCursor:
HomeCursor:
        pshs    d,x
        pshs    d,x
        clr             CursorRow
        clr             CursorRow
        clr             CursorCol
        clr             CursorCol
        ldb             COREID
        ldb             COREID
        cmpb    IOFocusID
        cmpb    IOFocusID
        bne             hc1
        bne             hc1
        clra
        clra
        sta             TEXTREG+TEXT_CURPOS
        sta             TEXTREG+TEXT_CURPOS
hc1:
hc1:
        puls    d,x,pc
        puls    d,x,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Update the cursor position in the text controller based on the
; Update the cursor position in the text controller based on the
;  CursorRow,CursorCol.
;  CursorRow,CursorCol.
;
;
; Modifies:
; Modifies:
;               none
;               none
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
UpdateCursorPos:
UpdateCursorPos:
        pshs    d,x
        pshs    d,x
        ldb             COREID                          ; update cursor position in text controller
        ldb             COREID                          ; update cursor position in text controller
        cmpb    IOFocusID                       ; only for the task with the output focus
        cmpb    IOFocusID                       ; only for the task with the output focus
        bne             ucp1
        bne             ucp1
        lda             CursorRow
        lda             CursorRow
        anda    #$3F                                    ; limit of 63 rows
        anda    #$3F                                    ; limit of 63 rows
        ldb             TEXTREG+TEXT_COLS
        ldb             TEXTREG+TEXT_COLS
        mul
        mul
        tfr             d,x
        tfr             d,x
        ldb             CursorCol
        ldb             CursorCol
        abx
        abx
        stx             TEXTREG+TEXT_CURPOS
        stx             TEXTREG+TEXT_CURPOS
ucp1:
ucp1:
        puls    d,x,pc
        puls    d,x,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Calculate screen memory location from CursorRow,CursorCol.
; Calculate screen memory location from CursorRow,CursorCol.
; Also refreshes the cursor location.
; Also refreshes the cursor location.
;
;
; Modifies:
; Modifies:
;               d
;               d
; Returns:
; Returns:
;       d = screen location
;       d = screen location
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
CalcScreenLoc:
CalcScreenLoc:
        pshs    x
        pshs    x
        lda             CursorRow
        lda             CursorRow
        ldb             #56
        ldb             #56
        mul
        mul
        tfr             d,x
        tfr             d,x
        ldb             CursorCol
        ldb             CursorCol
        abx
        abx
        ldb             COREID                          ; update cursor position in text controller
        ldb             COREID                          ; update cursor position in text controller
        cmpb    IOFocusID                       ; only for the task with the output focus
        cmpb    IOFocusID                       ; only for the task with the output focus
        bne             csl1
        bne             csl1
        stx             TEXTREG+TEXT_CURPOS
        stx             TEXTREG+TEXT_CURPOS
csl1:
csl1:
        bsr             GetScreenLocation
        bsr             GetScreenLocation
        leax    d,x
        leax    d,x
        tfr             x,d
        tfr             x,d
        puls    x,pc
        puls    x,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Display a character on the screen.
; Display a character on the screen.
; If the task doesn't have the I/O focus then the character is written to
; If the task doesn't have the I/O focus then the character is written to
; the virtual screen.
; the virtual screen.
;
;
; Modifies:
; Modifies:
;               none
;               none
; Parameters:
; Parameters:
;       accb = char to display
;       accb = char to display
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
DisplayChar:
DisplayChar:
        lbsr    SerialPutChar
        lbsr    SerialPutChar
        pshs    d,x
        pshs    d,x
        cmpb    #CR                                     ; carriage return ?
        cmpb    #CR                                     ; carriage return ?
        bne             dccr
        bne             dccr
        clr             CursorCol               ; just set cursor column to zero on a CR
        clr             CursorCol               ; just set cursor column to zero on a CR
        bsr             UpdateCursorPos
        bsr             UpdateCursorPos
dcx14:
dcx14:
        lbra            dcx4
        lbra            dcx4
dccr:
dccr:
        cmpb    #$91                            ; cursor right ?
        cmpb    #$91                            ; cursor right ?
        bne             dcx6
        bne             dcx6
        lda             CursorCol
        lda             CursorCol
        cmpa    #56
        cmpa    #56
        bhs             dcx7
        bhs             dcx7
        inca
        inca
        sta             CursorCol
        sta             CursorCol
dcx7:
dcx7:
        bsr             UpdateCursorPos
        bsr             UpdateCursorPos
        puls    d,x,pc
        puls    d,x,pc
dcx6:
dcx6:
        cmpb    #$90                            ; cursor up ?
        cmpb    #$90                            ; cursor up ?
        bne             dcx8
        bne             dcx8
        lda             CursorRow
        lda             CursorRow
        beq             dcx7
        beq             dcx7
        deca
        deca
        sta             CursorRow
        sta             CursorRow
        bra             dcx7
        bra             dcx7
dcx8:
dcx8:
        cmpb    #$93                            ; cursor left ?
        cmpb    #$93                            ; cursor left ?
        bne             dcx9
        bne             dcx9
        lda             CursorCol
        lda             CursorCol
        beq             dcx7
        beq             dcx7
        deca
        deca
        sta             CursorCol
        sta             CursorCol
        bra             dcx7
        bra             dcx7
dcx9:
dcx9:
        cmpb    #$92                            ; cursor down ?
        cmpb    #$92                            ; cursor down ?
        bne             dcx10
        bne             dcx10
        lda             CursorRow
        lda             CursorRow
        cmpa    #29
        cmpa    #29
        beq             dcx7
        beq             dcx7
        inca
        inca
        sta             CursorRow
        sta             CursorRow
        bra             dcx7
        bra             dcx7
dcx10:
dcx10:
        cmpb    #$94                            ; cursor home ?
        cmpb    #$94                            ; cursor home ?
        bne             dcx11
        bne             dcx11
        lda             CursorCol
        lda             CursorCol
        beq             dcx12
        beq             dcx12
        clr             CursorCol
        clr             CursorCol
        bra             dcx7
        bra             dcx7
dcx12:
dcx12:
        clr             CursorRow
        clr             CursorRow
        bra             dcx7
        bra             dcx7
dcx11:
dcx11:
        cmpb    #$99                            ; delete ?
        cmpb    #$99                            ; delete ?
        bne             dcx13
        bne             dcx13
        bsr             CalcScreenLoc
        bsr             CalcScreenLoc
        tfr             d,x
        tfr             d,x
        lda             CursorCol               ; acc = cursor column
        lda             CursorCol               ; acc = cursor column
        bra             dcx5
        bra             dcx5
dcx13
dcx13
        cmpb    #CTRLH                  ; backspace ?
        cmpb    #CTRLH                  ; backspace ?
        bne             dcx3
        bne             dcx3
        lda             CursorCol
        lda             CursorCol
        beq             dcx4
        beq             dcx4
        deca
        deca
        sta             CursorCol
        sta             CursorCol
        bsr             CalcScreenLoc
        bsr             CalcScreenLoc
        tfr             d,x
        tfr             d,x
        lda             CursorCol
        lda             CursorCol
dcx5:
dcx5:
        ldb             1,x
        ldb             1,x
        stb             ,x++
        stb             ,x++
        inca
        inca
        cmpa    #56
        cmpa    #56
        blo             dcx5
        blo             dcx5
        ldb             #' '
        ldb             #' '
        dex
        dex
        stb             ,x
        stb             ,x
        bra             dcx4
        bra             dcx4
dcx3:
dcx3:
        cmpb    #LF                             ; linefeed ?
        cmpb    #LF                             ; linefeed ?
        beq             dclf
        beq             dclf
        pshs    b
        pshs    b
        bsr     CalcScreenLoc
        bsr     CalcScreenLoc
        tfr             d,x
        tfr             d,x
        puls    b
        puls    b
        stb             ,x
        stb             ,x
        ; ToDo character color
        ; ToDo character color
;       lda             CharColor
;       lda             CharColor
;       sta             $2000,x
;       sta             $2000,x
        bsr             IncCursorPos
        bsr             IncCursorPos
        bra             dcx4
        bra             dcx4
dclf:
dclf:
        bsr             IncCursorRow
        bsr             IncCursorRow
dcx4:
dcx4:
        puls    d,x,pc
        puls    d,x,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Increment the cursor position, scroll the screen if needed.
; Increment the cursor position, scroll the screen if needed.
;
;
; Modifies:
; Modifies:
;               none
;               none
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
IncCursorPos:
IncCursorPos:
        pshs    d,x
        pshs    d,x
        lda             CursorCol
        lda             CursorCol
        inca
        inca
        sta             CursorCol
        sta             CursorCol
        cmpa    #56
        cmpa    #56
        blo             icc1
        blo             icc1
        clr             CursorCol               ; column = 0
        clr             CursorCol               ; column = 0
        bra             icr1
        bra             icr1
IncCursorRow:
IncCursorRow:
        pshs    d,x
        pshs    d,x
icr1:
icr1:
        lda             CursorRow
        lda             CursorRow
        inca
        inca
        sta             CursorRow
        sta             CursorRow
        cmpa    #29
        cmpa    #29
        blo             icc1
        blo             icc1
        deca                                                    ; backup the cursor row, we are scrolling up
        deca                                                    ; backup the cursor row, we are scrolling up
        sta             CursorRow
        sta             CursorRow
        bsr             ScrollUp
        bsr             ScrollUp
icc1:
icc1:
        bsr             UpdateCursorPos
        bsr             UpdateCursorPos
icc2:
icc2:
        puls    d,x,pc
        puls    d,x,pc
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Display a string on the screen.
; Display a string on the screen.
;
;
; Modifies:
; Modifies:
;               none
;               none
; Parameters:
; Parameters:
;               d = pointer to string
;               d = pointer to string
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
DisplayString:
DisplayString:
        pshs    d,x
        pshs    d,x
        tfr             d,x
        tfr             d,x
dspj2:                                          ; lock semaphore for access
dspj2:                                          ; lock semaphore for access
        lda             OUTSEMA+1
        lda             OUTSEMA+1
        beq             dspj2
        beq             dspj2
dspj1B:
dspj1B:
        ldb             ,x+                             ; move string char into acc
        ldb             ,x+                             ; move string char into acc
        beq             dsretB          ; is it end of string ?
        beq             dsretB          ; is it end of string ?
        lbsr    OUTCH                   ; display character
        lbsr    OUTCH                   ; display character
        bra             dspj1B
        bra             dspj1B
dsretB:
dsretB:
        clr             OUTSEMA+1       ; unlock semaphore
        clr             OUTSEMA+1       ; unlock semaphore
        puls    d,x,pc
        puls    d,x,pc
DisplayStringCRLF:
DisplayStringCRLF:
        pshs    d
        pshs    d
        bsr             DisplayString
        bsr             DisplayString
        ldb             #CR
        ldb             #CR
        lbsr    OUTCH
        lbsr    OUTCH
        ldb             #LF
        ldb             #LF
        lbsr    OUTCH
        lbsr    OUTCH
        puls    d,pc
        puls    d,pc
;
;
; PRINT CR, LF, STRING
; PRINT CR, LF, STRING
;
;
PSTRNG
PSTRNG
        BSR             PCRLF
        BSR             PCRLF
        BRA             PDATA
        BRA             PDATA
PCRLF
PCRLF
        PSHS    X
        PSHS    X
        LDX             #CRLFST
        LDX             #CRLFST
        BSR             PDATA
        BSR             PDATA
        PULS    X
        PULS    X
        RTS
        RTS
PRINT
PRINT
        JSR             OUTCH
        JSR             OUTCH
PDATA
PDATA
        LDB             ,X+
        LDB             ,X+
        CMPB    #$04
        CMPB    #$04
        BNE             PRINT
        BNE             PRINT
        RTS
        RTS
CRLFST
CRLFST
        fcb     CR,LF,4
        fcb     CR,LF,4
DispDWordAsHex:
DispDWordAsHex:
        bsr             DispWordAsHex
        bsr             DispWordAsHex
        exg             d,x
        exg             d,x
        bsr             DispWordAsHex
        bsr             DispWordAsHex
        exg             d,x
        exg             d,x
        rts
        rts
DispWordAsHex:
DispWordAsHex:
        exg             a,b
        exg             a,b
        bsr             DispByteAsHex
        bsr             DispByteAsHex
        exg             a,b
        exg             a,b
        bsr             DispByteAsHex
        bsr             DispByteAsHex
        rts
        rts
DispByteAsHex:
DispByteAsHex:
  pshs  b
  pshs  b
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        bsr             DispNyb
        bsr             DispNyb
        puls    b
        puls    b
        pshs    b
        pshs    b
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        lsrb
        bsr             DispNyb
        bsr             DispNyb
        puls    b
        puls    b
DispNyb
DispNyb
        pshs    b
        pshs    b
        andb    #$0F
        andb    #$0F
        cmpb    #10
        cmpb    #10
        blo             DispNyb1
        blo             DispNyb1
        addb    #'A'-10
        addb    #'A'-10
        lbsr    OUTCH
        lbsr    OUTCH
        puls    b,pc
        puls    b,pc
DispNyb1
DispNyb1
        addb    #'0'
        addb    #'0'
        lbsr    OUTCH
        lbsr    OUTCH
        puls    b,pc
        puls    b,pc
;==============================================================================
;==============================================================================
; Timer
; Timer
;==============================================================================
;==============================================================================
OPT INCLUDE "d:\cores2022\rf6809\software\boot\timer.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\timer.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\i2c.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\i2c.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\rtc_driver.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\rtc_driver.asm"
;==============================================================================
;==============================================================================
; Keyboard I/O
; Keyboard I/O
;==============================================================================
;==============================================================================
OPT INCLUDE "d:\cores2022\rf6809\software\boot\scancodes.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\scancodes.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\keyboard.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\keyboard.asm"
        fcb             "KEYBOARD"
        fcb             "KEYBOARD"
        fcw             KeybdOpen
        fcw             KeybdOpen
        fcw             KeybdClose
        fcw             KeybdClose
        fcw             KeybdRead
        fcw             KeybdRead
        fcw             KeybdWrite
        fcw             KeybdWrite
        fcw             KeybdSeek
        fcw             KeybdSeek
; Keyboard Open:
; Keyboard Open:
; Initialize the keyboard buffer head and tail indexes
; Initialize the keyboard buffer head and tail indexes
;
;
KeybdOpen:
KeybdOpen:
        rts
        rts
; Keyboard Close:
; Keyboard Close:
; Nothing to do except maybe clear the keyboard buffer
; Nothing to do except maybe clear the keyboard buffer
;
;
KeybdClose:
KeybdClose:
        rts
        rts
;
;
KeybdRead:
KeybdRead:
        rts
        rts
;
;
KeybdWrite:
KeybdWrite:
        rts
        rts
KeybdSeek:
KeybdSeek:
        rts
        rts
;==============================================================================
;==============================================================================
; Serial I/O
; Serial I/O
;==============================================================================
;==============================================================================
OPT INCLUDE "d:\cores2022\rf6809\software\boot\serial.asm"
OPT INCLUDE "d:\cores2022\rf6809\software\boot\serial.asm"
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Check if there is a keyboard character available. If so return true (<0)
; Check if there is a keyboard character available. If so return true (<0)
; otherwise return false (0) in accb.
; otherwise return false (0) in accb.
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
KeybdCheckForKeyDirect:
KeybdCheckForKeyDirect:
        bra             DBGCheckForKey
        bra             DBGCheckForKey
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
INCH:
INCH:
        pshs    b
        pshs    b
INCH2:
INCH2:
        ldb             COREID
        ldb             COREID
        cmpb    IOFocusID       ; if we do not have focus, block
        cmpb    IOFocusID       ; if we do not have focus, block
        bne             INCH2
        bne             INCH2
;       ldb             #$800                   ; block if no key available, get scancode directly
;       ldb             #$800                   ; block if no key available, get scancode directly
;       bra             GetKey
;       bra             GetKey
;       jsr             [CharInVec]     ; vector is being overwritten somehow
;       jsr             [CharInVec]     ; vector is being overwritten somehow
        lbsr    SerialPeekCharDirect
        lbsr    SerialPeekCharDirect
        tsta
        tsta
        bmi             INCH1                   ; block if no key available
        bmi             INCH1                   ; block if no key available
        leas    1,s                             ; get rid of blocking status
        leas    1,s                             ; get rid of blocking status
        rts
        rts
INCH1:
INCH1:
        puls    b                                       ; check blocking status
        puls    b                                       ; check blocking status
        tstb
        tstb
        bmi     INCH                    ; if blocking, loop
        bmi     INCH                    ; if blocking, loop
        ldd             #-1                             ; return -1 if no char available
        ldd             #-1                             ; return -1 if no char available
        rts
        rts
INCHE:
INCHE:
        bsr             INCH
        bsr             INCH
        bra             INCHEK3
        bra             INCHEK3
INCHEK:
INCHEK:
        bsr             INCH
        bsr             INCH
        tst             KeybdEcho
        tst             KeybdEcho
        beq             INCHEK1
        beq             INCHEK1
INCHEK3:
INCHEK3:
        cmpa    #CR
        cmpa    #CR
        bne             INCHEK2
        bne             INCHEK2
        lbsr            CRLF
        lbsr            CRLF
        bra             INCHEK1
        bra             INCHEK1
INCHEK2:
INCHEK2:
        lbsr    DisplayChar
        lbsr    DisplayChar
INCHEK1:
INCHEK1:
        rts
        rts
OUTCH:
OUTCH:
        jmp             [CharOutVec]
        jmp             [CharOutVec]
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; r1 0=echo off, non-zero = echo on
; r1 0=echo off, non-zero = echo on
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
SetKeyboardEcho:
SetKeyboardEcho:
        stb             KeybdEcho
        stb             KeybdEcho
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Parameters:
; Parameters:
;               x,d     bitmap of sprites to enable
;               x,d     bitmap of sprites to enable
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
ShowSprites:
ShowSprites:
        stx             SPRITE_CTRL+SPRITE_EN
        stx             SPRITE_CTRL+SPRITE_EN
        std             SPRITE_CTRL+SPRITE_EN+2
        std             SPRITE_CTRL+SPRITE_EN+2
        rts
        rts
;==============================================================================
;==============================================================================
; Femtiki Operating System.
; Femtiki Operating System.
;==============================================================================
;==============================================================================
OSCallTbl:
OSCallTbl:
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             0
        fcw             ReleaseIOFocus
        fcw             ReleaseIOFocus
        fcw             0
        fcw             0
        fcw             RequestIOFocus
        fcw             RequestIOFocus
OSCall:
OSCall:
        ; wait for availability
        ; wait for availability
osc1:
osc1:
        tst             OSSEMA+1
        tst             OSSEMA+1
        beq             osc1
        beq             osc1
        aslb
        aslb
        ldx             #OSCallTbl
        ldx             #OSCallTbl
        abx
        abx
        tst             ,x
        tst             ,x
        beq             oscx
        beq             oscx
        jmp             [,x]
        jmp             [,x]
oscx:
oscx:
        clr             OSSEMA+1
        clr             OSSEMA+1
        rts
        rts
RequestIOFocus:
RequestIOFocus:
        ldb             COREID
        ldb             COREID
        ldx             #IOFocusList
        ldx             #IOFocusList
        abx
        abx
        sta             ,x
        sta             ,x
        tst             IOFocusID
        tst             IOFocusID
        lbne    oscx
        lbne    oscx
        stb             IOFocusID
        stb             IOFocusID
        lbra    oscx
        lbra    oscx
ReleaseIOFocus:
ReleaseIOFocus:
        ldb             COREID
        ldb             COREID
        ldx             #IOFocusList
        ldx             #IOFocusList
        abx
        abx
        clr             ,x                                              ; clear the request indicator
        clr             ,x                                              ; clear the request indicator
        lbsr    CopyScreenToVirtualScreen
        lbsr    CopyScreenToVirtualScreen
        cmpb    IOFocusID                       ; are we the one with the focus?
        cmpb    IOFocusID                       ; are we the one with the focus?
        lbne    oscx
        lbne    oscx
        ; We had the focus, so now a new core needs the focus.
        ; We had the focus, so now a new core needs the focus.
        ; Search the focus list for a requestor. If no requester
        ; Search the focus list for a requestor. If no requester
        ; is found, give focus to core #1.
        ; is found, give focus to core #1.
        lda             #15
        lda             #15
riof2:
riof2:
        incb
        incb
        andb    #15
        andb    #15
        abx
        abx
        tst             ,x
        tst             ,x
        bne             riof1
        bne             riof1
        deca
        deca
        bne             riof2
        bne             riof2
        ; If no focus is requested by anyone, give to core #1
        ; If no focus is requested by anyone, give to core #1
        ldb             #1
        ldb             #1
        lda             #24
        lda             #24
        sta             ,x
        sta             ,x
riof1:
riof1:
        stb             IOFocusID
        stb             IOFocusID
        lbsr    CopyVirtualScreenToScreen
        lbsr    CopyVirtualScreenToScreen
        lbra    oscx
        lbra    oscx
;==============================================================================
;==============================================================================
; Disassembler
; Disassembler
;==============================================================================
;==============================================================================
OPT     include "d:\cores2022\rf6809\software\boot\disassem.asm"
OPT     include "d:\cores2022\rf6809\software\boot\disassem.asm"
;==============================================================================
;==============================================================================
; System Monitor
; System Monitor
;==============================================================================
;==============================================================================
CmdPrompt:
CmdPrompt:
        lbsr    CRLF
        lbsr    CRLF
        ldb             #'$'
        ldb             #'$'
        lbsr    OUTCH
        lbsr    OUTCH
        lbra    OUTCH
        lbra    OUTCH
msgF09Starting:
msgF09Starting:
        fcb             "Femtiki F09 Multi-core OS Starting",CR,LF,0
        fcb             "Femtiki F09 Multi-core OS Starting",CR,LF,0
MonitorStart:
MonitorStart:
        ldd             #msgF09Starting
        ldd             #msgF09Starting
        lbsr    DisplayString
        lbsr    DisplayString
        ldd             #HelpMsg
        ldd             #HelpMsg
        lbsr    DisplayString
        lbsr    DisplayString
        ldd             #CmdPrompt
        ldd             #CmdPrompt
        std             CmdPromptJI
        std             CmdPromptJI
 
        ldd             #DisplayErr
 
        std             MonErrVec
 
        ldd             #$63FF                  ; default app stack
 
        std             mon_SSAVE
Monitor:
Monitor:
        leas    $6FFF                           ; reset stack pointer
        leas    $6FFF                           ; reset stack pointer
        clrb                                                    ; turn off keyboard echo
        clrb                                                    ; turn off keyboard echo
        lbsr    SetKeyboardEcho
        lbsr    SetKeyboardEcho
        ; Reset IO vectors
        ; Reset IO vectors
        ldd             #SerialPeekCharDirect
        ldd             #SerialPeekCharDirect
        std             CharInVec
        std             CharInVec
        ldd             #DisplayChar
        ldd             #DisplayChar
        std             CharOutVec
        std             CharOutVec
        ldd             #CmdPrompt
        ldd             #CmdPrompt
        std             CmdPromptJI
        std             CmdPromptJI
;       jsr             RequestIOFocus
;       jsr             RequestIOFocus
PromptLn:
PromptLn:
        jsr             [CmdPromptJI]
        jsr             [CmdPromptJI]
; Get characters until a CR is keyed
; Get characters until a CR is keyed
Prompt3:
Prompt3:
        ldd             #-1                                     ; block until key present
        ldd             #-1                                     ; block until key present
        lbsr    INCH
        lbsr    INCH
        cmpb    #CR
        cmpb    #CR
        beq             Prompt1
        beq             Prompt1
        lbsr    OUTCH
        lbsr    OUTCH
        bra             Prompt3
        bra             Prompt3
; Process the screen line that the CR was keyed on
; Process the screen line that the CR was keyed on
;
;
Prompt1:
Prompt1:
        ldd             #$5050
        ldd             #$5050
        std             LEDS
        std             LEDS
;       ldb             RunningID
;       ldb             RunningID
;       cmpb    #61
;       cmpb    #61
;       bhi             Prompt3
;       bhi             Prompt3
        ldd             #$5151
        ldd             #$5151
        std             LEDS
        std             LEDS
        clr             CursorCol                       ; go back to the start of the line
        clr             CursorCol                       ; go back to the start of the line
        lbsr    CalcScreenLoc   ; calc screen memory location
        lbsr    CalcScreenLoc   ; calc screen memory location
        tfr             d,y
        tfr             d,y
        ldd             #$5252
        ldd             #$5252
        std             LEDS
        std             LEDS
skipDollar:
skipDollar:
        bsr             MonGetNonSpace
        bsr             MonGetNonSpace
        cmpb    #'$'
        cmpb    #'$'
        beq             skipDollar              ; skip over '$' prompt character
        beq             skipDollar              ; skip over '$' prompt character
        lda             #$5353
        lda             #$5353
        std             LEDS
        std             LEDS
; Dispatch based on command character
; Dispatch based on command character
;
;
Prompt2:
Prompt2:
        cmpb    #'<'
        cmpb    #'<'
        bne             PromptHelp
        bne             PromptHelp
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'>'
        cmpb    #'>'
        bne             Monitor
        bne             Monitor
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'s'
        cmpb    #'s'
        bne             Prompt2a
        bne             Prompt2a
        ldd             #SerialPeekCharDirect
        ldd             #SerialPeekCharDirect
        std             CharInVec
        std             CharInVec
        ldd             #SerialPutChar
        ldd             #SerialPutChar
        std             CharOutVec
        std             CharOutVec
        bra             Monitor
        bra             Monitor
Prompt2a:
Prompt2a:
        cmpb    #'c'
        cmpb    #'c'
        bne             Monitor
        bne             Monitor
        ldd             #GetKey
        ldd             #GetKey
        std             CharInVec
        std             CharInVec
        ldd             #DisplayChar
        ldd             #DisplayChar
        std             CharOutVec
        std             CharOutVec
        bra             Monitor
        bra             Monitor
PromptHelp:
PromptHelp:
        cmpb    #'?'                    ; $? - display help
        cmpb    #'?'                    ; $? - display help
        bne             PromptC
        bne             PromptC
        ldd             #HelpMsg
        ldd             #HelpMsg
        lbsr    DisplayString
        lbsr    DisplayString
        bra             Monitor
        bra             Monitor
PromptC:
PromptC:
        cmpb    #'C'
        cmpb    #'C'
        bne             PromptD
        bne             PromptD
        lbsr    ClearScreen
        lbsr    ClearScreen
        lbsr    HomeCursor
        lbsr    HomeCursor
        bra             Monitor
        bra             Monitor
PromptD:
PromptD:
        cmpb    #'D'
        cmpb    #'D'
        bne             PromptF
        bne             PromptColon
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'R'
        cmpb    #'R'
        bne             DumpMemory
        bne             DumpMemory
        bra             DumpRegs
        bra             DumpRegs
 
PromptColon:
 
        cmpb    #':'
 
        bne             PromptF
 
        lbra    EditMemory
PromptF:
PromptF:
        cmpb    #'F'
        cmpb    #'F'
        bne             PromptJ
        bne             PromptJ
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'I'
        cmpb    #'I'
        bne             Monitor
        bne             PromptFL
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'G'
        cmpb    #'G'
        bne             Monitor
        bne             Monitor
        jmp             $FE0000
        jmp             $FE0000
 
PromptFL:
 
        cmpb    #'L'
 
        bne             Monitor
 
        lbra    DumpIOFocusList
PromptJ:
PromptJ:
        cmpb    #'J'
        cmpb    #'J'
        lbeq    jump_to_code
        lbeq    jump_to_code
PromptR:
PromptR:
        cmpb    #'R'
        cmpb    #'R'
        bne             Prompt_s
        bne             Prompt_s
        ldu             #Monitor
        ldu             #Monitor
        lbra    ramtest
        lbra    ramtest
Prompt_s:
Prompt_s:
        cmpb    #'s'
        cmpb    #'s'
        bne             PromptT
        bne             PromptT
        lbsr    SerialOutputTest
        lbsr    SerialOutputTest
        bra             Monitor
        bra             Monitor
PromptT:
PromptT:
        cmpb    #'T'
        cmpb    #'T'
        bne             PromptU
        bne             PromptU
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'I'
        cmpb    #'I'
        bne             Monitor
        bne             Monitor
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #'R'
        cmpb    #'R'
        bne             Monitor
        bne             Monitor
        lbsr    rtc_read
        lbsr    rtc_read
        bra             Monitor
        bra             Monitor
PromptU:
PromptU:
        cmpb    #'U'
        cmpb    #'U'
        bne             Monitor
        bne             Monitor
        lbra    disassem
        lbra    disassem
MonGetch:
MonGetch:
        ldb             ,y
        ldb             ,y
        iny
        iny
        rts
        rts
MonGetNonSpace:
MonGetNonSpace:
        bsr             MonGetCh
        bsr             MonGetCh
        cmpb    #' '
        cmpb    #' '
        beq             MonGetNonSpace
        beq             MonGetNonSpace
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Ignore blanks in the input
; Ignore blanks in the input
; Y = text pointer
; Y = text pointer
; D destroyed
; D destroyed
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
ignBlanks:
ignBlanks:
ignBlanks1:
ignBlanks1:
        bsr             MonGetch
        bsr             MonGetch
        cmpb    #' '
        cmpb    #' '
        beq             ignBlanks1
        beq             ignBlanks1
        dey
        dey
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
GetTwoParams:
GetTwoParams:
        bsr             ignBlanks
        bsr             ignBlanks
        bsr             GetHexNumber    ; get start address of dump
        bsr             GetHexNumber    ; get start address of dump
        ldd             mon_numwka
        ldd             mon_numwka
        std             mon_r1
        std             mon_r1
        ldd             mon_numwka+2
        ldd             mon_numwka+2
        std             mon_r1+2
        std             mon_r1+2
        bsr             ignBlanks
        bsr             ignBlanks
        bsr             GetHexNumber    ; get end address of dump
        bsr             GetHexNumber    ; get end address of dump
        ldd             mon_numwka
        ldd             mon_numwka
        std             mon_r2
        std             mon_r2
        ldd             mon_numwka+2
        ldd             mon_numwka+2
        std             mon_r2+2
        std             mon_r2+2
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Get a range, the end must be greater or equal to the start.
; Get a range, the end must be greater or equal to the start.
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
GetRange:
GetRange:
        bsr             GetTwoParams
        bsr             GetTwoParams
        ldd             mon_r2+2
        ldd             mon_r2+2
        subd    mon_r1+2
        subd    mon_r1+2
        ldd             mon_r2
        ldd             mon_r2
        sbcb    mon_r1+1
        sbcb    mon_r1+1
        sbca    mon_r1
        sbca    mon_r1
        lbcs    DisplayErr
        lbcc    grng1
 
        jsr             [MonErrVec]
 
        lbra    Monitor
 
grng1:
        rts
        rts
shl_numwka:
shl_numwka:
        asl             mon_numwka+3
        asl             mon_numwka+3
        rol             mon_numwka+2
        rol             mon_numwka+2
        rol             mon_numwka+1
        rol             mon_numwka+1
        rol             mon_numwka
        rol             mon_numwka
        rts
        rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Get a hexidecimal number. Maximum of twelve digits.
; Get a hexidecimal number. Maximum of twelve digits.
;
;
; Modifies:
; Modifies:
;       Y = text pointer (updated)
;       Y = text pointer (updated)
;       D = number of digits
;       D = number of digits
;       mon_numwka contains number
;       mon_numwka contains number
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
GetHexNumber:
GetHexNumber:
        clrd
        clrd
        std             mon_numwka      ; zero out work area
        std             mon_numwka      ; zero out work area
        std             mon_numwka+2
        std             mon_numwka+2
        pshs    x
        pshs    x
        ldx             #0                                      ; max 12 eight digits
        ldx             #0                                      ; max 12 eight digits
gthxn2:
gthxn2:
        bsr             MonGetch
        bsr             MonGetch
        bsr             AsciiToHexNybble
        bsr             AsciiToHexNybble
        cmpb    #-1
        cmpb    #-1
        beq             gthxn1
        beq             gthxn1
        bsr             shl_numwka
        bsr             shl_numwka
        bsr             shl_numwka
        bsr             shl_numwka
        bsr             shl_numwka
        bsr             shl_numwka
        bsr             shl_numwka
        bsr             shl_numwka
        andb    #$0f
        andb    #$0f
        orb             mon_numwka+3
        orb             mon_numwka+3
        stb             mon_numwka+3
        stb             mon_numwka+3
        inx
        inx
        cmpx    #12
        cmpx    #12
        blo             gthxn2
        blo             gthxn2
gthxn1:
gthxn1:
        tfr             x,d
        tfr             x,d
        puls    x,pc
        puls    x,pc
;GetDecNumber:
;GetDecNumber:
;       phx
;       phx
;       push    r4
;       push    r4
;       push    r5
;       push    r5
;       ldx             #0
;       ldx             #0
;       ld              r4,#10
;       ld              r4,#10
;       ld              r5,#10
;       ld              r5,#10
;gtdcn2:
;gtdcn2:
;       jsr             MonGetch
;       jsr             MonGetch
;       jsr             AsciiToDecNybble
;       jsr             AsciiToDecNybble
;       cmp             #-1
;       cmp             #-1
;       beq             gtdcn1
;       beq             gtdcn1
;       mul             r2,r2,r5
;       mul             r2,r2,r5
;       add             r2,r1
;       add             r2,r1
;       dec             r4
;       dec             r4
;       bne             gtdcn2
;       bne             gtdcn2
;gtdcn1:
;gtdcn1:
;       txa
;       txa
;       pop             r5
;       pop             r5
;       pop             r4
;       pop             r4
;       plx
;       plx
;       rts
;       rts
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Convert ASCII character in the range '0' to '9', 'a' to 'f' or 'A' to 'F'
; Convert ASCII character in the range '0' to '9', 'a' to 'f' or 'A' to 'F'
; to a hex nybble.
; to a hex nybble.
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;
;
AsciiToHexNybble:
AsciiToHexNybble:
        cmpb    #'0'
        cmpb    #'0'
        blo             gthx3
        blo             gthx3
        cmpb    #'9'
        cmpb    #'9'
        bhi             gthx5
        bhi             gthx5
        subb    #'0'
        subb    #'0'
        rts
        rts
gthx5:
gthx5:
        cmpb    #'A'
        cmpb    #'A'
        blo             gthx3
        blo             gthx3
        cmpb    #'F'
        cmpb    #'F'
        bhi             gthx6
        bhi             gthx6
        subb    #'A'
        subb    #'A'
        addb    #10
        addb    #10
        rts
        rts
gthx6:
gthx6:
        cmpb    #'a'
        cmpb    #'a'
        blo             gthx3
        blo             gthx3
        cmpb    #'z'
        cmpb    #'z'
        bhi             gthx3
        bhi             gthx3
        subb    #'a'
        subb    #'a'
        addb    #10
        addb    #10
        rts
        rts
gthx3:
gthx3:
        ldb             #-1             ; not a hex number
        ldb             #-1             ; not a hex number
        rts
        rts
AsciiToDecNybble:
AsciiToDecNybble:
        cmpb    #'0'
        cmpb    #'0'
        bcc             gtdc3
        bcc             gtdc3
        cmpb    #'9'+1
        cmpb    #'9'+1
        bcs             gtdc3
        bcs             gtdc3
        subb    #'0'
        subb    #'0'
        rts
        rts
gtdc3:
gtdc3:
        ldb             #-1
        ldb             #-1
        rts
        rts
DisplayErr:
DisplayErr:
        ldx             #msgErr
        ldd             #msgErr
        clrd
        lbsr    DisplayString
        bsr             DisplayStringDX
 
        jmp             Monitor
        jmp             Monitor
DisplayStringDX
DisplayStringDX
        std             Strptr
        std             Strptr
        stx             Strptr+2
        stx             Strptr+2
        jsr             DisplayString
        jsr             DisplayString
        rts
        rts
msgErr:
msgErr:
        fcb     "**Err",CR,LF,0
        fcb     "**Err",CR,LF,0
HelpMsg:
HelpMsg:
        fcb             "? = Display help",CR,LF
        fcb             "? = Display help",CR,LF
        fcb     "CLS = clear screen",CR,LF
        fcb     "CLS = clear screen",CR,LF
;       db      "S = Boot from SD Card",CR,LF
;       db      "S = Boot from SD Card",CR,LF
;       db      ": = Edit memory bytes",CR,LF
        fcb     ": = Edit memory bytes",CR,LF
;       db      "L = Load sector",CR,LF
;       db      "L = Load sector",CR,LF
;       db      "W = Write sector",CR,LF
;       db      "W = Write sector",CR,LF
        fcb "DR = Dump registers",CR,LF
        fcb "DR = Dump registers",CR,LF
        fcb     "D = Dump memory",CR,LF
        fcb     "D = Dump memory",CR,LF
;       db      "F = Fill memory",CR,LF
;       db      "F = Fill memory",CR,LF
;       db  "FL = Dump I/O Focus List",CR,LF
        fcb "FL = Dump I/O Focus List",CR,LF
        fcb "FIG = start FIG Forth",CR,LF
        fcb "FIG = start FIG Forth",CR,LF
;       db      "KILL n = kill task #n",CR,LF
;       db      "KILL n = kill task #n",CR,LF
;       db      "B = start tiny basic",CR,LF
;       db      "B = start tiny basic",CR,LF
;       db      "b = start EhBasic 6502",CR,LF
;       db      "b = start EhBasic 6502",CR,LF
        fcb     "J = Jump to code",CR,LF
        fcb     "J = Jump to code",CR,LF
        fcb "RAM = test RAM",CR,LF
        fcb "RAM = test RAM",CR,LF
;       db      "R[n] = Set register value",CR,LF
;       db      "R[n] = Set register value",CR,LF
;       db      "r = random lines - test bitmap",CR,LF
;       db      "r = random lines - test bitmap",CR,LF
;       db      "e = ethernet test",CR,LF
;       db      "e = ethernet test",CR,LF
        fcb     "s = serial output test",CR,LF
        fcb     "s = serial output test",CR,LF
;       db      "T = Dump task list",CR,LF
;       db      "T = Dump task list",CR,LF
;       db      "TO = Dump timeout list",CR,LF
;       db      "TO = Dump timeout list",CR,LF
        fcb     "TI = display date/time",CR,LF
        fcb     "TI = display date/time",CR,LF
;       db      "TEMP = display temperature",CR,LF
;       db      "TEMP = display temperature",CR,LF
 
        fcb     "U = unassemble",CR,LF
;       db      "P = Piano",CR,LF,0
;       db      "P = Piano",CR,LF,0
        fcb             0
        fcb             0
msgRegHeadings
msgRegHeadings
        fcb     CR,LF,"  D/AB     X      Y      U      S       PC    DP  CCR",CR,LF,0
        fcb     CR,LF,"  D/AB     X      Y      U      S       PC    DP  CCR",CR,LF,0
nHEX4:
nHEX4:
        jsr             HEX4
        jsr             HEX4
        rts
        rts
nXBLANK:
nXBLANK:
        ldb             #' '
        ldb             #' '
        lbra    OUTCH
        lbra    OUTCH
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Dump Memory
; Dump Memory
;
;
; Usage:
; Usage:
;       $D FFFC12 8
;       $D FFFC12 FFFC20
;
;
; Dump formatted to look like:
; Dump formatted to look like:
;               :FFFC12 012 012 012 012 555 666 777 888
;               :FFFC12 012 012 012 012 555 666 777 888
;
;
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
DumpMemory:
DumpMemory:
        bsr             GetTwoParams
        bsr             GetRange
        ldy             #0
        ldy             #0
        ldy             mon_r1+2
        ldy             mon_r1+2
dmpm2:
dmpm2:
        lbsr    CRLF
        lbsr    CRLF
        ldb             #':'
        ldb             #':'
        lbsr    OUTCH
        lbsr    OUTCH
        tfr             y,d
        tfr             y,d
        ;addd   mon_r1+2                                        ; output the address
        ;addd   mon_r1+2                                        ; output the address
        lbsr    DispWordAsHex
        lbsr    DispWordAsHex
        ldb             #' '
        ldb             #' '
        lbsr    OUTCH
        lbsr    OUTCH
        ldx             #8                                                              ; number of bytes to display
        ldx             #8                                                              ; number of bytes to display
dmpm1:
dmpm1:
;       ldb             far [mon_r1+1],y
;       ldb             far [mon_r1+1],y
        ;ldb            [mon_r1+2],y
        ;ldb            [mon_r1+2],y
        ldb             ,y
        ldb             ,y
        iny
        iny
        lbsr    DispByteAsHex                   ; display byte
        lbsr    DispByteAsHex                   ; display byte
        ldb             #' '                                                    ; followed by a space
        ldb             #' '                                                    ; followed by a space
        lbsr    OUTCH
        lbsr    OUTCH
        clrb
        clrb
        clra
        clra
        lbsr    INCH
        lbsr    INCH
        cmpb    #CTRLC
        cmpb    #CTRLC
        beq             dmpm3
        beq             dmpm3
        dex
        dex
        bne             dmpm1
        bne             dmpm1
        ; Now output ascii
        ; Now output ascii
        ldb             #' '
        ldb             #' '
        lbsr    OUTCH
        lbsr    OUTCH
        ldx             #8                                                              ; 8 chars to output
        ldx             #8                                                              ; 8 chars to output
        leay    -8,y                                                    ; backup pointer
        leay    -8,y                                                    ; backup pointer
dmpm5:
dmpm5:
;       ldb             far [mon_r1+1],y        ; get the char
;       ldb             far [mon_r1+1],y        ; get the char
;       ldb             [mon_r1+2],y                    ; get the char
;       ldb             [mon_r1+2],y                    ; get the char
        ldb             ,y
        ldb             ,y
        cmpb    #$20                                                    ; is it a control char?
        cmpb    #$20                                                    ; is it a control char?
        bhs             dmpm4
        bhs             dmpm4
        ldb             #'.'
        ldb             #'.'
dmpm4:
dmpm4:
        lbsr    OUTCH
        lbsr    OUTCH
        iny
        iny
        dex
        dex
        bne             dmpm5
        bne             dmpm5
        cmpy    mon_r2+2
        cmpy    mon_r2+2
        blo             dmpm2
        blo             dmpm2
dmpm3:
dmpm3:
        lbsr    CRLF
        lbsr    CRLF
        lbra    Monitor
        lbra    Monitor
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
 
; Edit Memory
 
;
 
; Usage:
 
;       $$:FFFC12 8 "Hello World!" 0
 
;
 
; Dump formatted to look like:
 
;               :FFFC12 012 012 012 012 555 666 777 888
 
;
 
;------------------------------------------------------------------------------
 
 
 
EditMemory:
 
        ldu             #8                                              ; set max byte count
 
        lbsr    GetHexNumber    ; get the start address
 
        ldx             mon_numwka+2
 
EditMem2:
 
        lbsr    ignBlanks                       ; skip over blanks
 
        lbsr    GetHexNumber    ; get the byte value
 
        tstb                                                            ; check for valid value
 
        bmi             EditMem1                        ; if invalid, quit
 
        ldb             mon_numwka+3    ; get value
 
        stb             ,x+                                             ; update memory at address
 
        leau    -1,u                                    ; decremeent byte count
 
        cmpu    #0
 
        bne             EditMem2                        ; go back for annother byte
 
EditMem1:
 
        lbsr    MonGetch                        ; see if a string is being entered
 
        cmpb    #'"'
 
        bne             EditMem3                        ; no string, we're done
 
        ldu             #40                                             ; string must be less than 40 chars
 
EditMem4:
 
        lbsr    MonGetch                        ; look for close quote
 
        cmpb    #'"'
 
        bne             EditMem6                        ; end of string?
 
        ldu             #8                                              ; reset the byte count
 
        bra             EditMem2
 
EditMem6:
 
        stb             ,x+                                             ; store the character in memory
 
        leau    -1,u                                    ; decrement byte count
 
        cmpu    #0
 
        bhi             EditMem4                        ; max 40 chars
 
EditMem3:
 
        lbra    Monitor
 
 
 
 
 
;------------------------------------------------------------------------------
; Dump Registers
; Dump Registers
;
;
;       Usage:
;       Usage:
;               $DR
;               $DR
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
DumpRegs:
DumpRegs:
        ldd             #msgRegHeadings
        ldd             #msgRegHeadings
        lbsr    DisplayString
        lbsr    DisplayString
        bsr             nXBLANK
        bsr             nXBLANK
        ldd             mon_DSAVE
        ldd             mon_DSAVE
        bsr             nHEX4
        bsr             nHEX4
        bsr             nXBLANK
        bsr             nXBLANK
        ldd             mon_XSAVE
        ldd             mon_XSAVE
        bsr             nHEX4
        bsr             nHEX4
        bsr             nXBLANK
        bsr             nXBLANK
        ldd             mon_YSAVE
        ldd             mon_YSAVE
        bsr             nHEX4
        bsr             nHEX4
        bsr             nXBLANK
        bsr             nXBLANK
        ldd             mon_USAVE
        ldd             mon_USAVE
        bsr             nHEX4
        bsr             nHEX4
        bsr             nXBLANK
        bsr             nXBLANK
        ldd             mon_SSAVE
        ldd             mon_SSAVE
        bsr             nHEX4
        bsr             nHEX4
        bsr             nXBLANK
        bsr             nXBLANK
        ldb             mon_PCSAVE+1
        ldb             mon_PCSAVE+1
        lbsr    DispByteAsHex
        lbsr    DispByteAsHex
        ldd             mon_PCSAVE+2
        ldd             mon_PCSAVE+2
        bsr             nHEX4
        bsr             nHEX4
        bsr             nXBLANK
        bsr             nXBLANK
        ldd             mon_DPRSAVE
        ldd             mon_DPRSAVE
        jsr             HEX2
        jsr             HEX2
        bsr             nXBLANK
        bsr             nXBLANK
        lda             mon_CCRSAVE
        lda             mon_CCRSAVE
        lbsr    HEX2
        lbsr    HEX2
        bsr             nXBLANK
        bsr             nXBLANK
        lbra    Monitor
        lbra    Monitor
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
; Jump to code
; Jump to code
;
;
; Registers are loaded with values from the monitor register save area before
; Registers are loaded with values from the monitor register save area before
; the code is jumped to.
; the code is jumped to.
;
;
; J 
; J 
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
jump_to_code:
jump_to_code:
        bsr             GetHexNumber
        bsr             GetHexNumber
        sei
        sei
        lds             mon_SSAVE
        lds             mon_SSAVE
        ldd             #
        ldd             #
        pshs    d
        pshs    d
        ldb             #>jtc_exit
        ldb             #>jtc_exit
        pshs    b
        pshs    b
        ldd             mon_numwka+2
        ldd             mon_numwka+2    ; get the address parameter
        pshs    d
        pshs    d
        ldb             mon_numwka+1
        ldb             mon_numwka+1
        pshs    b
        pshs    b
        ldd             mon_USAVE
        ldd             mon_USAVE
        pshs    d
        pshs    d
        ldd             mon_YSAVE
        ldd             mon_YSAVE
        pshs    d
        pshs    d
        ldd             mon_XSAVE
        ldd             mon_XSAVE
        pshs    d
        pshs    d
        lda             mon_DPRSave
        lda             mon_DPRSave
        pshs    a
        pshs    a
        ldd             mon_DSAVE
        ldd             mon_DSAVE
        pshs    d
        pshs    d
        lda             mon_CCRSAVE
        lda             mon_CCRSAVE
        pshs    a
        pshs    a
        puls    far ccr,d,dpr,x,y,u,pc
        puls    far ccr,d,dpr,x,y,u,pc
jtc_exit:
jtc_exit:
        sts             >mon_SSAVE              ; need to use extended addressing, no direct page setting
        sts             >mon_SSAVE              ; need to use extended addressing, no direct page setting
        leas    $6FFF                                   ; reset stack to system area, dont modify flags register!
        leas    $6FFF                                   ; reset stack to system area, dont modify flags register!
        pshs    ccr                                             ; now the stack can be used
        pshs    ccr                                             ; now the stack can be used
        pshs    a                                                       ; save acca register so we can use it
        pshs    a                                                       ; save acca register so we can use it
        tfr             dpr,a                                   ; a = outgoing dpr value
        tfr             dpr,a                                   ; a = outgoing dpr value
        sta             >mon_DPRSAVE    ; force extended addressing mode usage here dpr is not set
        sta             >mon_DPRSAVE    ; force extended addressing mode usage here dpr is not set
        clra                                                            ; dpg register must be set to zero before values are
        clra                                                            ; dpg register must be set to zero before values are
        tfr             a,dpr                                   ; saved in the monitor register save area.
        tfr             a,dpr                                   ; saved in the monitor register save area.
        puls    a                                                       ; get back acca
        puls    a                                                       ; get back acca
        std             mon_DSAVE                       ; save regsters, can use direct addressing now
        std             mon_DSAVE                       ; save regsters, can use direct addressing now
        stx             mon_XSAVE
        stx             mon_XSAVE
        sty             mon_YSAVE
        sty             mon_YSAVE
        stu             mon_USAVE
        stu             mon_USAVE
        puls    a                                                       ; get back ccr
        puls    a                                                       ; get back ccr
        sta             mon_CCRSAVE             ; and save it too
        sta             mon_CCRSAVE             ; and save it too
        ; Reset vectors in case they got toasted.
        ; Reset vectors in case they got toasted.
        ldd             #SerialPeekCharDirect
        ldd             #SerialPeekCharDirect
        std             CharInVec
        std             CharInVec
        ldd             #DisplayChar
        ldd             #DisplayChar
        std             CharOutVec
        std             CharOutVec
 
        ldd             DisplayErr
 
        std             MonErrVec
        ; todo set according to coreid
        ; todo set according to coreid
        lbra    DumpRegs                        ; now go do a register dump
        lbra    DumpRegs                        ; now go do a register dump
 
 
 
;------------------------------------------------------------------------------
 
;------------------------------------------------------------------------------
 
 
 
DumpIOFocusList:
 
        ldx             #0
 
dfl2:
 
        ldb             IOFocusList,x
 
        cmpb    #24
 
        bne             dfl1
 
        tfr             x,d
 
        lbsr    DispByteAsHex
 
        ldb             #' '
 
        lbsr    OUTCH
 
dfl1:
 
        inx
 
        cmpx    #16
 
        blo             dfl2
 
        lbsr    CRLF
 
        lbra    Monitor
 
 
 
 
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
swi3_rout:
swi3_rout:
        sei
        sei
        puls    a
        puls    a
        sta             mon_CCRSAVE
        sta             mon_CCRSAVE
        puls    D,DPR,X,Y,U
        puls    D,DPR,X,Y,U
        std             mon_DSAVE
        std             mon_DSAVE
        stx             mon_XSAVE
        stx             mon_XSAVE
        sty             mon_YSAVE
        sty             mon_YSAVE
        stu             mon_USAVE
        stu             mon_USAVE
        tfr             dpr,a
        tfr             dpr,a
        sta             mon_DPRSAVE
        sta             mon_DPRSAVE
        puls    a
        puls    a
        sta             mon_PCSAVE
        sta             mon_PCSAVE
        puls    D
        puls    D
        std             mon_PCSAVE+1
        std             mon_PCSAVE+1
        sts             mon_SSAVE
        sts             mon_SSAVE
        lds             #$3FFF
        lds             #$3FFF
        cli
        cli
        jmp             DumpRegs
        jmp             DumpRegs
swi3_exit:
swi3_exit:
        sei
        sei
        lds             mon_SSAVE
        lds             mon_SSAVE
        ldd             mon_PCSAVE+1
        ldd             mon_PCSAVE+1
        pshs    d
        pshs    d
        lda             mon_PCSAVE
        lda             mon_PCSAVE
        pshs    a
        pshs    a
        ldu             mon_USAVE
        ldu             mon_USAVE
        ldy             mon_YSAVE
        ldy             mon_YSAVE
        ldx             mon_XSAVE
        ldx             mon_XSAVE
        pshs    x,y,u
        pshs    x,y,u
        lda             mon_DPRSAVE
        lda             mon_DPRSAVE
        pshs    a
        pshs    a
        ldd             mon_DSAVE
        ldd             mon_DSAVE
        pshs    d
        pshs    d
        lda             mon_CCRSAVE
        lda             mon_CCRSAVE
        pshs    a
        pshs    a
        tfr             a,ccr
        tfr             a,ccr
        cli
        cli
        rti
        rti
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
firq_rout:
firq_rout:
        rti
        rti
irq_rout:
irq_rout:
;       lbsr    SerialIRQ       ; check for recieved character
;       lbsr    SerialIRQ       ; check for recieved character
;       lbsr    TimerIRQ
;       lbsr    TimerIRQ
        ; Reset the edge sense circuit in the PIC
        ; Reset the edge sense circuit in the PIC
        lda             #31                                                     ; Timer is IRQ #31
        lda             #31                                                     ; Timer is IRQ #31
        sta             IrqSource               ; stuff a byte indicating the IRQ source for PEEK()
        sta             IrqSource               ; stuff a byte indicating the IRQ source for PEEK()
        sta             PIC+16                                  ; register 16 is edge sense reset reg
        sta             PIC+16                                  ; register 16 is edge sense reset reg
        lda             VIA+VIA_IFR
        lda             VIA+VIA_IFR
        bpl             notTimerIRQ2
        bpl             notTimerIRQ2
        bita    #$800
        bita    #$800
        beq             notTimerIRQ2
        beq             notTimerIRQ2
        clr             VIA+VIA_T3LL
        clr             VIA+VIA_T3LL
        clr             VIA+VIA_T3LH
        clr             VIA+VIA_T3LH
        inc             $E00037                                 ; update timer IRQ screen flag
        inc             $E00037                                 ; update timer IRQ screen flag
notTimerIRQ2:
notTimerIRQ2:
        lda             IrqBase                 ; get the IRQ flag byte
        lda             IrqBase                 ; get the IRQ flag byte
        lsra
        lsra
        ora             IrqBase
        ora             IrqBase
        anda    #$E0
        anda    #$E0
        sta             IrqBase
        sta             IrqBase
;       inc             TEXTSCR+54              ; update IRQ live indicator on screen
;       inc             TEXTSCR+54              ; update IRQ live indicator on screen
        ; flash the cursor
        ; flash the cursor
        ; only bother to flash the cursor for the task with the IO focus.
        ; only bother to flash the cursor for the task with the IO focus.
;       lda             COREID
;       lda             COREID
;       cmpa    IOFocusID
;       cmpa    IOFocusID
;       bne             tr1a
;       bne             tr1a
;       lda             CursorFlash             ; test if we want a flashing cursor
;       lda             CursorFlash             ; test if we want a flashing cursor
;       beq             tr1a
;       beq             tr1a
;       lbsr    CalcScreenLoc   ; compute cursor location in memory
;       lbsr    CalcScreenLoc   ; compute cursor location in memory
;       tfr             d,y
;       tfr             d,y
;       lda             $2000,y                 ; get color code $2000 higher in memory
;       lda             $2000,y                 ; get color code $2000 higher in memory
;       ldb             IRQFlag                 ; get counter
;       ldb             IRQFlag                 ; get counter
;       lsrb
;       lsrb
;       lsra
;       lsra
;       lsra
;       lsra
;       lsra
;       lsra
;       lsra
;       lsra
;       lsrb
;       lsrb
;       rola
;       rola
;       lsrb
;       lsrb
;       rola
;       rola
;       lsrb
;       lsrb
;       rola
;       rola
;       lsrb
;       lsrb
;       rola
;       rola
;       sta             $E00000,y               ; store the color code back to memory
;       sta             $E00000,y               ; store the color code back to memory
tr1a:
tr1a:
        rti
        rti
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
;------------------------------------------------------------------------------
nmi_rout:
nmi_rout:
        ldb             COREID
        ldb             COREID
        lda             #'I'
        lda             #'I'
        ldx             #TEXTSCR+40
        ldx             #TEXTSCR+40
        sta             b,x
        sta             b,x
rti_insn:
rti_insn:
        rti
        rti
; Special Register Area
; Special Register Area
        org             $FFFFE0
        org             $FFFFE0
; Interrupt vector table
; Interrupt vector table
        org             $FFFFF0
        org             $FFFFF0
        fcw             rti_insn                ; reserved
        fcw             rti_insn                ; reserved
        fcw             swi3_rout               ; SWI3
        fcw             swi3_rout               ; SWI3
        fcw             rti_insn                ; SWI2
        fcw             rti_insn                ; SWI2
        fcw             firq_rout               ; FIRQ
        fcw             firq_rout               ; FIRQ
        fcw             irq_rout                ; IRQ
        fcw             irq_rout                ; IRQ
        fcw             start                           ; SWI
        fcw             start                           ; SWI
        fcw             nmi_rout                ; NMI
        fcw             nmi_rout                ; NMI
        fcw             start                           ; RST
        fcw             start                           ; RST
 
 

powered by: WebSVN 2.1.0

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