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 (zpspace-4) ; Other stuff
68 retsav: .res 2 ; Save buffer for return address
72 ; Swap the C temporaries
85 ; ----------------------------------------------------------------------------
89 ; Set/reset the breakpoints. We must do that here since the breakpoints
90 ; may be in the runtime stuff, causing the C part to fail before it has
91 ; reset the breakpoints. See declaration of struct breakpoint in the C
99 L4: lda _DbgBreaks+3,x ; Get bk_use
100 beq L6 ; Jump if not set
101 bpl L5 ; Jump if user breakpoint
103 sta _DbgBreaks+3,x ; Clear if temp breakpoint
104 L5: lda _DbgBreaks+1,x ; PC hi
106 lda _DbgBreaks,x ; PC lo
108 lda _DbgBreaks+2,x ; Old OPC
109 sta (ptr1),y ; Reset the breakpoint
114 cpx #MaxBreaks ; Done?
121 L7: lda _DbgBreaks+3,x ; Get bk_use
122 beq L8 ; Jump if not set
123 lda _DbgBreaks+1,x ; PC hi
125 lda _DbgBreaks,x ; PC lo
127 lda (ptr1),y ; Get the breakpoint OPC...
128 sta _DbgBreaks+2,x ; ...and save it
129 lda #$00 ; Load BRK opcode
135 cpx #MaxBreaks ; Done?
139 ; Get a free breakpoint slot or return 0
141 .export _DbgGetBreakSlot
145 L10: lda _DbgBreaks+3,x ; Get bk_use
146 beq L11 ; Jump if not set
151 cpx #MaxBreaks ; Done?
153 jmp return0 ; No free slot
162 L12: ldy #1 ; Force != 0
166 ; Check if a given address has a user breakpoint set, if found, return the
167 ; slot, otherwise return 0.
172 jsr popax ; Get address
176 L20: lda _DbgBreaks+3,x ; Get bk_use
177 beq L21 ; Jump if not set
178 bmi L21 ; Jump if temp breakpoint
179 lda _DbgBreaks,x ; Low byte of address
182 lda _DbgBreaks+1,x ; High byte of address
189 cpx #MaxBreaks ; Done?
191 jmp return0 ; Not found
200 L23: ldy #1 ; Force != 0