📄 s12sermon2r1.dbg
字号:
bne WriteNext
ldaa #ErrNone ;code for no errors ($E0)
bra xPrompt ;then back to prompt
SkipBytes: jsr GetChar ;read remaining bytes
WriteError: decb ;
bne SkipBytes
ldaa #ErrFlash ;code for Flash error ($E6)
WriteDone: bra xPrompt ;then back to prompt
;*********************************************************************
;* Read Next Command - IX=IX+2; read m(IX,IX=1) and return the data
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data sent back to host through SCI0 TxD
;* uses current value of IX from user CPU regs stack frame
;*********************************************************************
RdNextCmd: brclr flagReg,RunFlag,notRun ;do command if not run
clra ;data = $00 (can't read real data)
jsr PutChar ;send $00 instead of read_next data
jsr PutChar ;send $00 instead of read_next data
ldaa #ErrRun ;code for run mode error
xCmnd: jmp Prompt ;back to prompt; run error
notRun: bsr preInc ;get, pre-inc, & update user IX
jmp sendExit ;get data, send it, & back to prompt
;*********************************************************************
;* Write Byte Command - write specified address with specified data
;* 8-bit command code from host to SCI0 RxD
;* 16-bit address (high byte first) from host to SCI0 RxD
;* 8-bit data from host to SCI0 RxD
;*********************************************************************
WtByteCmd: jsr getX ;get address to write to
WriteNext2: jsr GetChar ;get data to write
jsr CheckModule
beq isRAMbyte
bra WriteByteNVM ;deny access (byte NVM access)
isRAMbyte: staa 0,x ;write to RAM or register
clra ;force Z=1 to indicate OK
WriteExit: ldaa #ErrNone ;code for no errors ($E0)
jmp Prompt ;ready for next command
WriteByteNVM: ldaa #ErrByteNVM ;code for byte NVM error ($E5)
jmp Prompt ;ready for next command
;*********************************************************************
;* Write Word Command - write word of data
;* 8-bit command code from host to SCI0 RxD
;* 16-bit address (high byte first) from host to SCI0 RxD
;* 16-bit value to write
;*********************************************************************
WtWordCmd: jsr getX ;get address to write to
ldab #02 ;one word +1
pshb ;save it on stack
bra WriteWord ;get & write data, & back to prompt
;*********************************************************************
;* Write Next Command - IX=IX+1; write specified data to m(IX)
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data from host to SCI0 RxD
;*
;* uses current value of IX from user CPU regs stack frame
;*********************************************************************
WtNextCmd: brclr flagReg,RunFlag,notRunW ;do command if not run
jsr getX ;clear data
ldaa #ErrRun ;code for run mode error
xCmndW: jmp Prompt ;back to prompt; run error
notRunW: bsr preInc ;get, pre-inc, & update user IX
ldab #02 ;one word +1
pshb ;save it on stack
bra WriteWord ;get & write data, & back to prompt
;*********************************************************************
;* utility to get IX from stack frame and pre increment it by 2
;* assumes interrupts are blocked while in monitor
;*********************************************************************
preInc: leas 2,sp
ldx UXreg,sp ;get user X
inx ;pre-increment
inx ;pre-increment
stx UXreg,sp ;put adjusted user X back on stack
leas -2,sp
rts ;pre-incremented IX still in IX
;*********************************************************************
;* Read Registers Command - read user's CPU register values
;*
;* 16-bit SP value (high byte first) sent to host through SCI0 TxD
;* 16-bit PC value (high byte first) sent to host through SCI0 TxD
;* 16-bit IY value (high byte first) sent to host through SCI0 TxD
;* 16-bit IX value (high byte first) sent to host through SCI0 TxD
;* 16-bit D value (high byte first) sent to host through SCI0 TxD
;* 8-bit CCR value sent to host through SCI0 TxD
;*
;* User CPU registers stack frame...
;*
;* +0 UCcr <- Monitor's SP
;* +1 UDreg (B:A)
;* +3 UXreg
;* +5 UYreg
;* +7 UPc
;* +9 --- <- User's SP
;*********************************************************************
RdRegsCmd: tsx ;IX = Monitor SP +2
leax SPOffset,x ;correct SP value
jsr put16 ;send user SP out SCI0
ldx UPc,sp ;user PC to IX
jsr put16 ;send user PC out SCI0
ldx UYreg,sp ;user IY to IX
jsr put16 ;send user IY out SCI0
ldx UXreg,sp ;user IX to IX
jsr put16 ;send user IX out SCI0
ldx UDreg,sp ;user D to IX
exg d,x
exg a,b ;flip as D is stacked B:A
exg d,x
jsr put16 ;send user D out SCI0
ldaa UCcr,sp ;user CCR to A
jsr PutChar ;send user CCR out SCI0
jmp CommandOK ;back to prompt
;*********************************************************************
;* Write CCR Command - write user's CCR register value
;* 8-bit command code from host to SCI0 RxD
;* 8-bit data for CCR from host to SCI0 RxD
;*********************************************************************
WriteCcrCmd: jsr GetChar ;read new CCR value
staa UCcr,sp ;replace user CCR value
jmp CommandOK ;back to no error and prompt
;*********************************************************************
;* Write D Command - write user's D register value
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data (high byte first) for D from host to SCI0 RxD
;*********************************************************************
WriteDCmd: jsr getX ;read new D value
exg d,x
exg a,b ;flip as D is stacked B:A
exg d,x
stx UDreg,sp ;replace user D value
jmp CommandOK ;back to no error and prompt
;*********************************************************************
;* Write IX Command - write user's IX register value
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data (high byte first) for IX from host to SCI0 RxD
;*********************************************************************
WriteIXCmd: jsr getX ;read new IX value
stx UXreg,sp ;replace user IX value
jmp CommandOK ;back to no error and prompt
;*********************************************************************
;* Write IY Command - write user's IY register value
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data (high byte first) for IY from host to SCI0 RxD
;*********************************************************************
WriteIYCmd: jsr getX ;read new IY value
stx UYreg,sp ;replace user IY value
jmp CommandOK ;back to no error and prompt
;*********************************************************************
;* Write PC Command - write user's PC register value
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data (high byte first) for PC from host to SCI0 RxD
;*********************************************************************
WritePcCmd: jsr getX ;read new PC thru SCI0 to IX
stx UPc,sp ;replace user PC value
jmp CommandOK ;back to no error and prompt
;*********************************************************************
;* Write SP Command - write user's SP register value
;* 8-bit command code from host to SCI0 RxD
;* 16-bit data (high byte first) for SP from host to SCI0 RxD
;*
;* Since other user CPU register values are stored on the stack, the
;* host will need to re-write the other user registers after SP is
;* changed. This routine just changes SP itself.
;*
;* SP value is user's SP & it is adjusted (-10) to accommodate the
;* user CPU register stack frame.
;*
;* If the host attempts to set the user SP value <RamStart or >RamLast
;* then the change is ignored, because such values would not support
;* proper execution of the monitor firmware.
;*********************************************************************
WriteSpCmd: bsr getX ;new SP value now in IX
leax -SPOffset,x ;correct SP value
cpx #LowSPLimit ;check against lower limit
blo spBad
cpx #HighSPLimit ;check against upper limit
bhi spBad
txs ;IX -> SP
jmp CommandOK ;back to no error and prompt
spBad: ldaa #ErrWriteSP ;error code for stack errors
; bsr PutChar ;send error code
jmp Prompt ;send status and >
;*********************************************************************
;* Trace 1 Command - trace one user instruction starting at current PC
;* 8-bit command code from host to SCI0 RxD
;*
;* if an interrupt was already pending, the user PC will point at the
;* ISR after the trace and the opcode at the original address will
;* not have been executed. (because the interrupt response is
;* considered to be an instruction to the CPU)
;*********************************************************************
;
pagebits: fcb $3D ;$0000-$3FFF is PPAGE $3D
fcb $3E ;$4000-$7FFF is PPAGE $3E
fcb $3F ;$C000-$FFFF is PPAGE $3F
pagebitsaddr:
fdb pagebits ;$0000-$3FFF : Use constant $3D
fdb pagebits+1 ;$4000-$7FFF : Use constant $3E (2nd last page)
fdb $0030 ;$8000-$BFFF : Use window PPAGE
fdb pagebits+2 ;$C000-$FFFF : Use constant $3F (last page)
Trace1Cmd:
bset flagReg,TraceFlag ;so at SWI we know it was Trace
ldx UPc,sp ;PC of go address
inx ;IX points at go opcode +1
inx ;IX points at go opcode +2
xgdx
andb #$FE
std DBGACH ;(BKP0H) debugger trigger address
std DBGBCH ;(BKP1H) same for second address to have it initialized
rola
rolb
rola
rolb ;get ready to search pagebits table
andb #$03 ;what range 0-3FFF,4000-7FFF,8000-BFFF,or C000-FFFF?
clra
lsld
xgdx
ldx pagebitsaddr,x
ldaa 0,x
staa DBGACX ;(BKP0X) set page byte of address
staa DBGBCX ;(BKP1X) same for second address to have it initialized
ldaa #traceOne ; enable, arm, CPU force
staa DBGC2 ;(BKPCT0) arm DBG to trigger after 1 instr.
rti ; restore regs and go to user code
;*********************************************************************
;* Go Command - go to user's program at current PC address
;* 8-bit command code from host to SCI0 RxD
;* - no promt is issued
;* typically, an SWI will cause control to pass back to the monitor
;*********************************************************************
GoCmd: bset SCI0CR2,RIE ;need to enable SCI0 Rx interrupts to
; enter monitor on any char received
bclr flagReg,TraceFlag ; run flag clr
rti ;restore regs and exit
;*********************************************************************
;* Utility to send a 16-bit value out X through SCI0
;*********************************************************************
put16: exg d,x ;move IX to A
bsr PutChar ;send high byte
tba ;move B to A
bsr PutChar ;send low byte
rts
;*********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -