-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnv_debug_code.asm
More file actions
360 lines (297 loc) · 10.5 KB
/
Copy pathnv_debug_code.asm
File metadata and controls
360 lines (297 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
//////////////////////////////////////////////////////////////////////////////
// nv_debug_code.asm
// Copyright(c) 2021 Neal Smith.
// License: MIT. See LICENSE file in root directory.
//////////////////////////////////////////////////////////////////////////////
// Some debug routines that print information but save state of registers
#importonce
#if !NV_C64_UTIL_DATA
.error "Error - nv_debug_code.asm: NV_C64_UTIL_DATA not defined. Import nv_c64_util_data.asm"
#endif
// the #if above doesn't seem to always work so..
// if data hasn't been imported yet, import it into default location
#importif !NV_C64_UTIL_DATA "nv_c64_util_default_data.asm"
#import "nv_debug_macs.asm"
#import "nv_screen_macs.asm"
#import "nv_screen_code.asm"
//////////////////////////////////////////////////////////////////////////////
// subroutine macro to print labeled value of a byte from memory
// on the screen at a specified position. Will look like this on screen:
// LABEL: $03
// macro params:
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// nv_e8: pass true to wait for a key after printing
.macro nv_debug_print_str_sr()
{
nv_debug_save_state()
// note that parameters are already set as follows
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of string.
// this string must be zero terminated.
jsr NvScreenPokeStr
lda nv_e8
beq NoWait
Wait:
//nv_key_wait_any_key()
jsr NvKeyWaitAnyKey
NoWait:
nv_debug_restore_state()
rts
}
//////////////////////////////////////////////////////////////////////////////
// Subroutine macro to print the hex value of a byte in a particular
// memory location to the screen.
// Subroutine Parameters
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_c8: the byte to print.
// nv_d8: set to 1 to include dollar sign
// nv_e8: pass true to wait for a key after printing
.macro nv_debug_print_byte_sr()
{
nv_debug_save_state()
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_c8: the byte to print should be loaded here
// nv_d8: set to 1 to include dollar sign
jsr NvScreenPokeHexByte
lda nv_e8
beq NoWait
Wait:
//nv_key_wait_any_key()
jsr NvKeyWaitAnyKey
NoWait:
nv_debug_restore_state()
rts
}
//////////////////////////////////////////////////////////////////////////////
// Subroutine macro to print the hex value of a byte in a particular
// memory location to the screen.
// Subroutine Parameters
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_c16: the word to print.
// nv_d8: set to 1 to include dollar sign
// nv_e8: pass true to wait for a key after printing
.macro nv_debug_print_word_sr()
{
nv_debug_save_state()
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_c16: the word to print should be loaded here
// nv_d8: set to 1 to include dollar sign
jsr NvScreenPokeHexWord
lda nv_e8
beq NoWait
Wait:
//nv_key_wait_any_key()
jsr NvKeyWaitAnyKey
NoWait:
nv_debug_restore_state()
rts
}
//////////////////////////////////////////////////////////////////////////////
// subroutine macro to print labeled value of a byte from memory
// on the screen at a specified position. Will look like this on screen:
// LABEL $03
// macro params:
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// nv_c8: The byte to print
// nv_d8: pass 1 for preceding '$'
// nv_e8: pass true to wait for a key after printing
.macro nv_debug_print_labeled_byte_sr()
{
nv_debug_save_state()
lda nv_b8
sta save_b8
// gets the length of null terminated string pointed to by
// nv_a16 and puts it in Y register
jsr NvStringGetLen
sty label_len
// setup and call routine to print the label
// note that parameters are already set as follows
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of string.
// this string must be zero terminated.
jsr NvScreenPokeStr
// setup and call routine to print the byte value
// nv_a8: row position, already set
// nv_b8: col position, add label_len to it
// nv_c8: the byte to print, already set
// nv_d8: set to 1 to include dollar sign, already set
lda label_len
sec
adc nv_b8
sta nv_b8
jsr NvScreenPokeHexByte
lda nv_e8
beq NoWait
Wait:
//nv_key_wait_any_key()
jsr NvKeyWaitAnyKey
NoWait:
lda save_b8
sta nv_b8
nv_debug_restore_state()
rts
// subroutine variables
label_len: .byte 0
// save nv_b8
save_b8: .byte 0
}
//////////////////////////////////////////////////////////////////////////////
// subroutine macro to print labeled value of a byte from memory
// on the screen at a specified position. Will look like this on screen:
// LABEL $03
// macro params:
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// nv_c8: The byte to print
// nv_d8: pass 1 for preceding '$'
// nv_e8: pass true to wait for a key after printing
.macro nv_debug_print_labeled_word_sr()
{
nv_debug_save_state()
// save col because we need to modify it
lda nv_b8
sta save_b8
// gets the length of null terminated string pointed to by
// nv_a16 and puts it in Y register
jsr NvStringGetLen
sty label_len
// setup and call routine to print the label
// note that parameters are already set as follows
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of string.
// this string must be zero terminated.
jsr NvScreenPokeStr
// setup and call routine to print the byte value
// nv_a8: row position, already set
// nv_b8: col position, add label_len to it
// nv_c16: the word to print, already set
// nv_d8: set to 1 to include dollar sign, already set
lda label_len
sec
adc nv_b8
sta nv_b8
jsr NvScreenPokeHexWord
lda nv_e8
beq NoWait
Wait:
//nv_key_wait_any_key()
jsr NvKeyWaitAnyKey
NoWait:
lda save_b8
sta nv_b8
nv_debug_restore_state()
rts
// subroutine variables
label_len: .byte 0
// save nv_b8
save_b8: .byte 0
}
//////////////////////////////////////////////////////////////////////////////
// subroutine macro to get number of chars in zero terminated string
// params:
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// Y Reg: will hold the length of the string upon return.
.macro nv_string_get_len_sr()
{
// two zero page bytes to use as a pointer
.const ZERO_PAGE_LO = $FB
.const ZERO_PAGE_HI = $FC
// save the zero page bytes that we use
lda ZERO_PAGE_LO
sta save_zero_lo
lda ZERO_PAGE_HI
sta save_zero_hi
// load pointer to string base
lda nv_a16
sta ZERO_PAGE_LO
lda nv_a16+1
sta ZERO_PAGE_HI
ldy #0
Loop:
lda (ZERO_PAGE_LO),y
beq Done
iny
jmp Loop
Done:
// restore the zero page bytes that we used
lda save_zero_hi
sta ZERO_PAGE_HI
lda save_zero_lo
sta ZERO_PAGE_LO
rts
// routine variables
save_zero_lo: .byte 0
save_zero_hi: .byte 0
}
//////////////////////////////////////////////////////////////////////////////
// instantiated subroutines below here
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// Y Reg: will hold the length of the string upon return.
NvStringGetLen:
nv_string_get_len_sr()
//////////////////////////////////////////////////////////////////////////////
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// nv_c8: The byte to print
// nv_d8: pass 1 for preceding '$'
// nv_e8: pass true to wait for a key after printing
NvDebugPrintLabeledByte:
nv_debug_print_labeled_byte_sr()
//////////////////////////////////////////////////////////////////////////////
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// nv_c16: The LSB of the word to print
// nv_d8: pass 1 for preceding '$'
// nv_e8: pass true to wait for a key after printing
NvDebugPrintLabeledWord:
nv_debug_print_labeled_word_sr()
//////////////////////////////////////////////////////////////////////////////
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_a16: the address of the first char of label string.
// this string must be zero terminated.
// nv_e8: pass true to wait for a key after printing
NvDebugPrintStr:
nv_debug_print_str_sr()
//////////////////////////////////////////////////////////////////////////////
// Subroutine to print the hex value of a byte in memory to the screen
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_c8: the byte in memory to print.
// nv_d8: set to 1 to include dollar sign
// nv_e8: pass true to wait for a key after printing
NvDebugPrintByte:
nv_debug_print_byte_sr()
//////////////////////////////////////////////////////////////////////////////
// Subroutine to print the hex value of a byte in memory to the screen
// nv_a8: row position on screen to print at
// nv_b8: col position on screen to print at
// nv_c16: the word in memory to print.
// nv_d8: set to 1 to include dollar sign
// nv_e8: pass true to wait for a key after printing
NvDebugPrintWord:
nv_debug_print_word_sr()
#import "nv_keyboard_code.asm"