📄 s12sermon2r1.dbg
字号:
;
; set baud rate to 115.2 kbaud and turn on Rx and Tx
;
movb #baud115200,SCI0BDL ;..BDH=0 so baud = 115.2 K
movb #initSCI0CR2,SCI0CR2 ;Rx and Tx on
;
; if warm start, skip break. A is a flag to indicate cold vs warm start.
; Avoid using A above here *****
;
ChkCold: tsta ;0=cold start, non-zero=warm start
beq coldBrk ;if cold send break
;
; Send a warm start prompt and wait for new commands
;
ldaa #ErrSP ;error code for bad SP
jsr PutChar ;send error code (1st prompt char)
ldaa #StatWarm ;status code for warm start
bra EndPrompt ;finish warm start prompt
;
; Cold start so Generate long break to host
;
coldBrk: brclr SCI0SR1,TDRE,* ;wait for Tx (preamble) empty
bset SCI0CR2,SBK ;start sending break after preamble
ldx #longBreak ;at least 30 bit times for Windows
BrkLoop: cpx #0 ;[2]done?
dbne x,BrkLoop ;[3]
bclr SCI0CR2,SBK ;stop sending breaks
waitforCR: jsr GetChar ;should be asciiCR or $00 with FE=1
cmpa #asciiCR ;.eq. if 115.2K baud OK
bne waitforCR
;*********************************************************************
;* end of reset initialization, begin body of program
;*********************************************************************
;
; Send a cold start prompt and wait for new commands
;
ldaa #ErrNone ;code for no errors ($E0)
jsr PutChar ;send error code (1st prompt char)
ldaa #StatCold ;status code for cold start ($08)
bra EndPrompt ;finish warm start prompt
;
; normal entry point after a good command
; Prompt is an alt entry point if an error occurred during a command
; endPrompt is an alternate entry for Trace1, Break (SWI), Halt,
; or warm/cold resets so an alternate status value can be sent
; with the prompt
;
CommandOK: ldaa #ErrNone ;code for no errors ($E0)
Prompt: jsr PutChar ;send error code
ldaa flagReg ;0 means monitor active mode
anda #RunFlag ;mask for run/monitor flag (SCI WAKE)
lsra ;shift flag to LSB
lsra ; for output as status
lsra ;$00=monitor active, $01=run
EndPrompt: jsr PutChar ;send status code
ldaa #'>'
jsr PutChar ;send 3rd character of prompt seq
;test flagReg for run / DBG arm status.
brclr flagReg,RunFlag,Prompt1 ;no exit if run flag clr
brclr flagReg,ArmFlag,PromptRun ;If DBG was not armed just run
bset DBGC1,ARM ;re-arm DBG module
PromptRun: jmp GoCmd ;run mode so return to user program
Prompt1: jsr GetChar ;get command code character
ldx #commandTbl ;point at first command entry
CmdLoop: cmpa ,x ;does command match table entry?
beq DoCmd ;branch if command found
leax 3,x
cpx #tableEnd ;see if past end of table
bne CmdLoop ;if not, try next entry
ldaa #ErrCmnd ;code for unrecognized command
bra Prompt ;back to prompt; command error
DoCmd: ldx 1,x ;get pointer to command routine
jmp ,x ;go process command
;
; all commands except GO, Trace_1, and Reset to user code - jump to
; Prompt after done. Trace_1 returns indirectly via a SWI.
;
;*********************************************************************
;* Command table for bootloader/monitor commands
;* each entry consists of an 8-bit command code + the address of the
;* routine to be executed for that command.
;*********************************************************************
commandTbl: fcb $A1
fdb RdByteCmd ;read byte
fcb $A2
fdb WtByteCmd ;write byte
fcb $A3
fdb RdWordCmd ;read word of data
fcb $A4
fdb WtWordCmd ;write word of data
fcb $A5
fdb RdNextCmd ;read next word
fcb $A6
fdb WtNextCmd ;write next word
fcb $A7
fdb ReadCmd ;read n bytes of data
fcb $A8
fdb WriteCmd ;write n bytes of data
fcb $A9
fdb RdRegsCmd ;read CPU registers
fcb $AA
fdb WriteSpCmd ;write SP
fcb $AB
fdb WritePcCmd ;write PC
fcb $AC
fdb WriteIYCmd ;write IY
fcb $AD
fdb WriteIXCmd ;write IX
fcb $AE
fdb WriteDCmd ;write D
fcb $AF
fdb WriteCcrCmd ;write CCR
fcb $B1
fdb GoCmd ;go
fcb $B2
fdb Trace1Cmd ;trace 1
fcb $B3
fdb HaltCmd ;halt
fcb $B4
fdb ResetCmd ;reset - to user vector or monitor
; $B5 - Command not implemented
fcb $B6 ;code - erase flash command
fdb EraseAllCmd ;erase all flash and eeprom command routine
fcb $B7 ;return device ID
fdb DeviceCmd
fcb $B8 ;erase current flash bank selected in PPAGE
fdb ErsPage
fcb $B9 ;Bulk erase eeprom if available
fdb EraseEECmd ;
tableEnd: equ * ;end of command table marker
;*********************************************************************
;* Device ID Command - Ouputs hex word from device ID register
;*********************************************************************
DeviceCmd: ldaa #$DC ;get part HCS12 descripter
jsr PutChar ;out to term
ldaa PARTIDH ;get part ID high byte
jsr PutChar ;out to term
ldaa PARTIDL ;get part ID low byte
jsr PutChar ;out to term
ldaa #ErrNone ;error code for no errors
jmp Prompt ;ready for next command
;*********************************************************************
;* Halt Command - halts user application and enters Monitor
;* This command is normally sent by the debugger while the user
;* application is running. It changes the state variable in order
;* to stay in the monitor
;*********************************************************************
HaltCmd: bclr flagReg,RunFlag ;run/mon flag = 0; monitor active
ldaa #ErrNone ;error code for no errors
jsr PutChar ;send error code
ldaa #StatHalt ;status code for Halt command
jmp EndPrompt ;send status and >
;*********************************************************************
;* Halt or continue user code by Rx interrupt of SCI. User code will
;* continue if Run load switch is in run position and a resonable
;* Sci user vector is found.
;*********************************************************************
SciIsr: brclr DBGC1,ARM,SciIsr1 ;Arm not set so continue
;above must be brclr as COF will be
;Stored in trace buffer
bset flagReg,ArmFlag ;Save ARM flag
bclr DBGC1,ARM ;Arm bit in Dbgc1 cleared to stop DBG
SciIsr1: bset SwPullup,mSwPullup ;enable pullup on monitor sw
bset flagReg,RunFlag ;set run/mon flag (run mode)
ldab #AllowSci0 ; defined in the .def file
cmpb #$01 ; is it set?
bne SciIsrExit ; if AllowSci0 is set
; Test run switch to allow user
; Sci0 function to run
;**********************************************************************
;* Force monitor if SwPort bit SWITCH = 0
;* Note: this port is configured after reset as input with pull-up
;* if this pin in not connect sci0 will be directed to user sci0
;**********************************************************************
ldab SwPort ;get port value
bitb #Switch ;test the sw bit
beq SciIsrExit
;*********************************************************************
;* This routine checks for an unprogrammed SCI0 user interrupt
;* vector and returns to monitor if execution of an unprogrammed
;* user SCI0 vector is attempted
;*********************************************************************
ldy $F000+(vector20-BootStart) ; Get user SCI vector
cpy #$FFFF ;is it programmed?
beq SciIsrExit ; if not exit
jmp 0,Y ;if programmed the go there.
SciIsrExit: bclr SwPullup,mSwPullup ;restore reset state
jmp Prompt1
;* unlike most ISRs, this one does not end in an RTI. If/when we
;* return to running the user program, we will re-enable Rx interrupts
;*********************************************************************
;* Reset Command - forces a reset - if user pseudo-vector is not blank
;* (or some other conditions are met - see ColdStart:) processing will
;* start at the user-specified reset pseudo-vector location and the
;* user has full control of all write-once registers. Otherwise reset
;* causes the bootloader/monitor program to cold start.
;*********************************************************************
ResetCmd: ldaa #RSBCK|!CR2|!CR1|CR0 ;Cop disabled in BDM
staa COPCTL ; turn on cop monitor
cmpa COPCTL ; load to see if user touched it
beq CopLock ; wait for COP reset
jmp ColdStart ; can't use COP just start over
CopLock: orcc #$10 ; disable interrupts
bra *
;*********************************************************************
;* SWI service routine - trace1 or breakpoint from user code
;* SWI saves user CPU registers on stack and returns to monitor
;* control at a new command prompt.
;* User CPU registers stack frame...
;*
;* +0 UCcr <- SP after SWI stacking and on entry to this ISR
;* +1 UDreg (B:A)
;* +3 UXreg
;* +5 UYreg
;* +7 UPc
;* +9 --- <- User's SP
;*********************************************************************
Breakpoint: clr DBGC2 ;Bkpct0 cleared to disabled
clr DBGC1 ;Dbgc1 cleared to disarm DBG
bclr flagReg,RunFlag ;run/mon flag = monitor active
ldab #StatTrace ;set status to Trace (SWI) -> B
;and enter monitor
;*********************************************************************
;* This is the entrypoint to the monitor from the user application
;* A contains the status value that reflects run status
;*
;* If SP isn't within valid RAM, it can't support the monitor so the
;* monitor is forced to initialize the SP and user registers.
;*********************************************************************
ReenterMon:
cps #LowSPLimit+1 ;check against lower limit
blo badSP ; note: +1 => A is not pushed yet
cps #HighSPLimit+1 ;check against upper limit
bhi badSP
ldaa #ErrNone ;error code for no errors
jsr PutChar ;send error code
tba ;status code from B to A
brclr flagReg,TraceFlag,SWIdone ;0 indicates not Trace
bclr flagReg,TraceFlag ;acknowledge trace flag
ldaa #StatTrace ;status code for Trace1 return
SWIdone: jmp EndPrompt ;send status and >
badSP: ldaa #ErrSP ;set error code to bad stack pointer
jmp stackInit
bclr flagReg,ArmFlag ;Save ARM flag
;*********************************************************************
;* Erase EE Command - mass
;* erase all EEPROM locations
;*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -