]> git.sur5r.net Git - cc65/blob - libsrc/dbg/dbgsupp.s
Fixed _textcolor definition.
[cc65] / libsrc / dbg / dbgsupp.s
1 ;
2 ; Ullrich von Bassewitz, 08.08.1998
3 ;
4 ; Support routines for the debugger
5 ;
6
7         .export         _DbgInit
8         .export         _DbgSP, _DbgCS, _DbgHI
9         .import         popptr1, return0, _DbgEntry, _set_brk, _end_brk
10         .import         _DbgBreaks
11         .import         _brk_pc
12         .import         __ZP_START__            ; Linker generated
13
14         .include        "zeropage.inc"
15
16
17 ; C callable function, will install the debugger
18
19 _DbgInit:
20         lda     #<DbgBreak
21         ldx     #>DbgBreak
22         jmp     _set_brk
23
24
25 ; Entry for the break vector.
26
27 DbgBreak:
28         pla
29         sta     retsav
30         pla
31         sta     retsav+1
32
33         cli
34         tsx                     ; Stack pointer
35         stx     _DbgSP
36
37         jsr     DbgSwapZP       ; Swap stuff
38         lda     #<DbgStack      ; Set new stack
39         sta     sp
40         lda     #>DbgStack
41         sta     sp+1
42         jsr     ResetDbgBreaks  ; Reset temporary breakpoints
43         jsr     _DbgEntry       ; Call C code
44         jsr     SetDbgBreaks    ; Set temporary breakpoints
45         jsr     DbgSwapZP       ; Swap stuff back
46
47         lda     retsav+1
48         pha
49         lda     retsav
50         pha
51         rts
52
53
54
55 ; Stack used when in debugger mode
56
57 .bss
58         .res    256
59 DbgStack:
60
61 ; Swap space for the the C temporaries
62
63 CTemp:
64 _DbgCS: .res    2               ; sp
65 _DbgHI: .res    2               ; sreg
66         .res    (zpsavespace-4) ; Other stuff
67
68 _DbgSP: .res    1
69 retsav: .res    2               ; Save buffer for return address
70
71 .code
72
73 ; Swap the C temporaries
74
75 DbgSwapZP:
76         ldy     #zpsavespace-1
77 Swap1:  ldx     CTemp,y
78         lda     <__ZP_START__,y
79         sta     CTemp,y
80         txa
81         sta     sp,y
82         dey
83         bpl     Swap1
84         rts
85
86 ; ----------------------------------------------------------------------------
87 ; Utility functions
88
89
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
93 ; source
94
95 MaxBreaks       = 48            ; 4*12
96
97 ResetDbgBreaks:
98         ldy     #0
99         ldx     #0
100 L4:     lda     _DbgBreaks+3,x  ; Get bk_use
101         beq     L6              ; Jump if not set
102         bpl     L5              ; Jump if user breakpoint
103         lda     #0
104         sta     _DbgBreaks+3,x  ; Clear if temp breakpoint
105 L5:     lda     _DbgBreaks+1,x  ; PC hi
106         sta     ptr1+1
107         lda     _DbgBreaks,x    ; PC lo
108         sta     ptr1
109         lda     _DbgBreaks+2,x  ; Old OPC
110         sta     (ptr1),y        ; Reset the breakpoint
111 L6:     inx
112         inx
113         inx
114         inx
115         cpx     #MaxBreaks      ; Done?
116         bne     L4
117         rts
118
119 SetDbgBreaks:
120         ldx     #0
121         ldy     #0
122 L7:     lda     _DbgBreaks+3,x  ; Get bk_use
123         beq     L8              ; Jump if not set
124         lda     _DbgBreaks+1,x  ; PC hi
125         sta     ptr1+1
126         lda     _DbgBreaks,x    ; PC lo
127         sta     ptr1
128         lda     (ptr1),y        ; Get the breakpoint OPC...
129         sta     _DbgBreaks+2,x  ; ...and save it
130         lda     #$00            ; Load BRK opcode
131         sta     (ptr1),y
132 L8:     inx
133         inx
134         inx
135         inx
136         cpx     #MaxBreaks      ; Done?
137         bne     L7
138         rts
139
140 ; Get a free breakpoint slot or return 0
141
142         .export         _DbgGetBreakSlot
143
144 _DbgGetBreakSlot:
145         ldx     #0
146 L10:    lda     _DbgBreaks+3,x  ; Get bk_use
147         beq     L11             ; Jump if not set
148         inx
149         inx
150         inx
151         inx
152         cpx     #MaxBreaks      ; Done?
153         bne     L10
154         jmp     return0         ; No free slot
155
156 L11:    stx     tmp1
157         lda     #<_DbgBreaks
158         ldx     #>_DbgBreaks
159         clc
160         adc     tmp1
161         bcc     L12
162         inx
163 L12:    ldy     #1              ; Force != 0
164         rts
165
166
167 ; Check if a given address has a user breakpoint set, if found, return the
168 ; slot, otherwise return 0.
169
170         .export         _DbgIsBreak
171
172 _DbgIsBreak:
173         jsr     popptr1         ; Get address
174         ldx     #0
175 L20:    lda     _DbgBreaks+3,x  ; Get bk_use
176         beq     L21             ; Jump if not set
177         bmi     L21             ; Jump if temp breakpoint
178         lda     _DbgBreaks,x    ; Low byte of address
179         cmp     ptr1
180         bne     L21
181         lda     _DbgBreaks+1,x  ; High byte of address
182         cmp     ptr1+1
183         beq     L22
184 L21:    inx
185         inx
186         inx
187         inx
188         cpx     #MaxBreaks      ; Done?
189         bne     L20
190         jmp     return0         ; Not found
191
192 L22:    stx     tmp1
193         lda     #<_DbgBreaks
194         ldx     #>_DbgBreaks
195         clc
196         adc     tmp1
197         bcc     L23
198         inx
199 L23:    ldy     #1              ; Force != 0
200         rts
201
202
203