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 .importzp sp, sreg, ptr1, tmp1, zpspace
14 ; C callable function, will install the debugger
22 ; Entry for the break vector.
34 jsr DbgSwapZP ; Swap stuff
35 lda #<DbgStack ; Set new stack
39 jsr ResetDbgBreaks ; Reset temporary breakpoints
40 jsr _DbgEntry ; Call C code
41 jsr SetDbgBreaks ; Set temporary breakpoints
42 jsr DbgSwapZP ; Swap stuff back
52 ; Stack used when in debugger mode
58 ; Swap space for the the C temporaries
65 retsav: .res 2 ; Save buffer for return address
69 ; Swap the C temporaries
82 ; ----------------------------------------------------------------------------
86 ; Set/reset the breakpoints. We must do that here since the breakpoints
87 ; may be in the runtime stuff, causing the C part to fail before it has
88 ; reset the breakpoints. See declaration of struct breakpoint in the C
96 L4: lda _DbgBreaks+3,x ; Get bk_use
97 beq L6 ; Jump if not set
98 bpl L5 ; Jump if user breakpoint
100 sta _DbgBreaks+3,x ; Clear if temp breakpoint
101 L5: lda _DbgBreaks+1,x ; PC hi
103 lda _DbgBreaks,x ; PC lo
105 lda _DbgBreaks+2,x ; Old OPC
106 sta (ptr1),y ; Reset the breakpoint
111 cpx #MaxBreaks ; Done?
118 L7: lda _DbgBreaks+3,x ; Get bk_use
119 beq L8 ; Jump if not set
120 lda _DbgBreaks+1,x ; PC hi
122 lda _DbgBreaks,x ; PC lo
124 lda (ptr1),y ; Get the breakpoint OPC...
125 sta _DbgBreaks+2,x ; ...and save it
126 lda #$00 ; Load BRK opcode
132 cpx #MaxBreaks ; Done?
136 ; Get a free breakpoint slot or return 0
138 .export _DbgGetBreakSlot
142 L10: lda _DbgBreaks+3,x ; Get bk_use
143 beq L11 ; Jump if not set
148 cpx #MaxBreaks ; Done?
150 jmp return0 ; No free slot
159 L12: ldy #1 ; Force != 0
163 ; Check if a given address has a user breakpoint set, if found, return the
164 ; slot, otherwise return 0.
169 jsr popax ; Get address
173 L20: lda _DbgBreaks+3,x ; Get bk_use
174 beq L21 ; Jump if not set
175 bmi L21 ; Jump if temp breakpoint
176 lda _DbgBreaks,x ; Low byte of address
179 lda _DbgBreaks+1,x ; High byte of address
186 cpx #MaxBreaks ; Done?
188 jmp return0 ; Not found
197 L23: ldy #1 ; Force != 0