2 ; Ullrich von Bassewitz, 08.08.1998
4 ; Support routines for the debugger
8 .export _DbgSP, _DbgCS, _DbgHI
9 .import popax, return0, _DbgEntry, _set_brk, _end_brk
12 .import __ZP_START__ ; Linker generated
14 .include "zeropage.inc"
17 ; C callable function, will install the debugger
25 ; Entry for the break vector.
37 jsr DbgSwapZP ; Swap stuff
38 lda #<DbgStack ; Set new stack
42 jsr ResetDbgBreaks ; Reset temporary breakpoints
43 jsr _DbgEntry ; Call C code
44 jsr SetDbgBreaks ; Set temporary breakpoints
45 jsr DbgSwapZP ; Swap stuff back
55 ; Stack used when in debugger mode
61 ; Swap space for the the C temporaries
66 .res (zpsavespace-4) ; Other stuff
69 retsav: .res 2 ; Save buffer for return address
73 ; Swap the C temporaries
86 ; ----------------------------------------------------------------------------
90 ; Set/reset the breakpoints. We must do that here since the breakpoints
91 ; may be in the runtime stuff, causing the C part to fail before it has
92 ; reset the breakpoints. See declaration of struct breakpoint in the C
100 L4: lda _DbgBreaks+3,x ; Get bk_use
101 beq L6 ; Jump if not set
102 bpl L5 ; Jump if user breakpoint
104 sta _DbgBreaks+3,x ; Clear if temp breakpoint
105 L5: lda _DbgBreaks+1,x ; PC hi
107 lda _DbgBreaks,x ; PC lo
109 lda _DbgBreaks+2,x ; Old OPC
110 sta (ptr1),y ; Reset the breakpoint
115 cpx #MaxBreaks ; Done?
122 L7: lda _DbgBreaks+3,x ; Get bk_use
123 beq L8 ; Jump if not set
124 lda _DbgBreaks+1,x ; PC hi
126 lda _DbgBreaks,x ; PC lo
128 lda (ptr1),y ; Get the breakpoint OPC...
129 sta _DbgBreaks+2,x ; ...and save it
130 lda #$00 ; Load BRK opcode
136 cpx #MaxBreaks ; Done?
140 ; Get a free breakpoint slot or return 0
142 .export _DbgGetBreakSlot
146 L10: lda _DbgBreaks+3,x ; Get bk_use
147 beq L11 ; Jump if not set
152 cpx #MaxBreaks ; Done?
154 jmp return0 ; No free slot
163 L12: ldy #1 ; Force != 0
167 ; Check if a given address has a user breakpoint set, if found, return the
168 ; slot, otherwise return 0.
173 jsr popax ; Get address
177 L20: lda _DbgBreaks+3,x ; Get bk_use
178 beq L21 ; Jump if not set
179 bmi L21 ; Jump if temp breakpoint
180 lda _DbgBreaks,x ; Low byte of address
183 lda _DbgBreaks+1,x ; High byte of address
190 cpx #MaxBreaks ; Done?
192 jmp return0 ; Not found
201 L23: ldy #1 ; Force != 0