-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnv_branch16_macs.asm
541 lines (485 loc) · 17 KB
/
nv_branch16_macs.asm
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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
//////////////////////////////////////////////////////////////////////////////
// nv_branch16_macs.asm
// Copyright(c) 2021 Neal Smith.
// License: MIT. See LICENSE file in root directory.
//////////////////////////////////////////////////////////////////////////////
// This file contains macros to branch based on 16 bit values
#importonce
#if !NV_C64_UTIL_DATA
.error "Error - nv_branch16_macs.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"
//////////////////////////////////////////////////////////////////////////////
// compare the contents of two 16 bit words and set flags accordingly.
// full name is nv_cmp16u_mem16u_mem16u
// params are:
// addr1: 16 bit address of op1
// addr2: 16 bit address of op2
// Carry Flag Set if addr1 >= addr2
// Zero Flag Set if addr1 == addr2
// Negative Flag is undefined
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_cmp16(addr1, addr2)
{
// first compare the MSBs
lda addr1+1
cmp addr2+1
bne Done
// MSBs are equal so need to compare LSBs
lda addr1
cmp addr2
Done:
}
//////////////////////////////////////////////////////////////////////////////
// compare the contents of two 16 bit words and set flags accordingly.
// full name is nv_cmp16u_mem16u_immed16u
// params are:
// addr1: 16 bit address of op1
// addr2: 16 bit address of op2
// Carry Flag Set if addr1 >= addr2
// Zero Flag Set if addr1 == addr2
// Negative Flag is undefined
// Accum: changes
// X Reg: no change
// Y Reg: no change
.macro nv_cmp16_immed(addr1, num)
{
// first compare the MSBs
lda addr1+1
cmp #((num >> 8) & $00FF)
bne Done
// MSBs are equal so need to compare LSBs
lda addr1
cmp #(num & $00FF)
Done:
}
//////////////////////////////////////////////////////////////////////////////
// branch if two words in memory have the same contents
// branch if addr1 == addr2
// full name is nv_beq16u_mem16u_mem16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// addr2: is the address of LSB of the other word (addr2+1 is MSB)
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_beq16(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
beq label
}
//////////////////////////////////////////////////////////////////////////////
// branch if two words in memory have the same contents.
// branch if addr1 == addr2
// full name is nv_beq16u_mem16u_mem16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// addr2: is the address of LSB of the other word (addr2+1 is MSB)
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_beq16_far(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
bne Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory has the same content as
// an immediate 16 bit value.
// branch if addr1 == num
// full name is nv_beq16u_mem16u_immed16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_beq16_immed(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
beq label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory has the same content as
// an immediate 16 bit value.
// branch if addr1 == num
// full name is nv_beq16u_mem16u_immed16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_beq16_immed_far(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
bne Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// branch if two words in memory have the different contents
// branch if addr1 != addr2
// full name is nv_bne16u_mem16u_mem16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// addr2: is the address of LSB of the other word (addr2+1 is MSB)
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bne16(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
bne label
}
//////////////////////////////////////////////////////////////////////////////
// branch if two words in memory have the different contents.
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// addr2: is the address of LSB of the other word (addr2+1 is MSB)
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bne16_far(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
beq Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory has different content than
// an immediate 16 bit value.
// branch if addr1 != num
// full name is nv_bne16u_mem16u_num16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bne16_immed(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
bne label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory has different contents than
// an immediate 16 bit value.
// branch if addr1 != num
// full name is nv_bne16u_mem16u_num16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bne16_immed_far(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
beq Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are less than the contents in another memory location .
// branch if addr1 < addr2
// full name is nv_blt16u_mem16u_mem16u
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 < word2
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_blt16(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
bcc label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to jump to a label if the contents of a word at one
// memory location are less than the contents in another memory location.
// branch if addr1 < addr2
// full name is nv_blt16u_mem16u_mem16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 < word2
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_blt16_far(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
bcs Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is less than
// an immediate 16 bit value.
// branch if addr1 < num
// full name is nv_blt16u_mem16u_immed16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_blt16_immed(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
bcc label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is less than
// an immediate 16 bit value
// branch if addr1 < num
// full name is nv_blt16u_mem16u_immed16u far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_blt16_immed_far(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
bcs Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are less than or equal to the contents in another memory location.
// branch if addr1 <= addr2
// full name is nv_ble16u_mem16u_mem16u
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 < word2
// Accum: changes
// X Reg: remains unchanged
// Y Reg: remains unchanged
.macro nv_ble16(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
// Carry Flag Set if addr1 >= addr2
// Zero Flag Set if addr1 == addr2
bcc label
beq label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are less than or equal to the contents in another memory location.
// branch if addr1 <= addr2
// full name is nv_ble16u_mem16u_mem16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 < word2
// Accum: changes
// X Reg: remains unchanged
// Y Reg: remains unchanged
.macro nv_ble16_far(addr1, addr2, label)
{
nv_bgt16(addr1, addr2, Done)
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is less than or equal to
// an immediate 16 bit value.
// branch if addr1 <= num
// full name is nv_ble16u_mem16u_immed16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: remains unchanged
// Y Reg: remains unchanged
.macro nv_ble16_immed(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
// Carry Flag Set if addr1 >= addr2
// Zero Flag Set if addr1 == addr2
bcc label
beq label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is less than or equal to
// an immediate 16 bit value.
// branch if addr1 <= num
// full name is nv_ble16u_mem16u_immed16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// Accum: changes
// X Reg: remains unchanged
// Y Reg: remains unchanged
.macro nv_ble16_immed_far(addr1, num, label)
{
nv_bgt16_immed(addr1, num, Done)
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are greater than the contents in another memory location.
// branch if addr1 > addr2
// full name is nv_bgt16u_mem16u_mem16u
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 > word2
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bgt16(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
// Carry Flag Set if addr1 >= addr2
// Zero Flag Set if addr1 == addr2
beq Done // equal so not greater than, we're done
bcs label // >= but we already tested for == so must be greater than
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are greater than the contents in another memory location.
// branch if addr1 > addr2
// full name is nv_bgt16u_mem16u_mem16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 > word2
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bgt16_far(addr1, addr2, label)
{
nv_ble16(addr1, addr2, Done)
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is greater than
// an immediate 16 bit value.
// branch if addr1 > num
// full name is nv_bgt16u_mem16u_immed16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// todo print macro
// Accum: changes
// X Reg: no change
// Y Reg: no change
.macro nv_bgt16_immed(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
// Carry Flag Set if addr1 >= addr2
// Zero Flag Set if addr1 == addr2
beq Done // equal so not greater than, we're done
bcs label // >= but we already tested for == so must be greater than
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is greater than
// an immediate 16 bit value.
// branch if addr1 > num
// full name is nv_bgt16u_mem16u_immed16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// todo print macro
// Accum: changes
// X Reg: no change
// Y Reg: no change
.macro nv_bgt16_immed_far(addr1, num, label)
{
nv_ble16_immed(addr1, num, Done)
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are greater than or equal to the contents in another memory location.
// branch if addr1 >= addr2
// full name is nv_bge16u_mem16u_mem16u
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 >= word2
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bge16(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
// Carry Flag Set if addr1 >= addr2
bcs label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if the contents of a word at one memory location
// are greater than or equal to the contents in another memory location.
// branch if addr1 >= addr2
// full name is nv_bge16u_mem16u_mem16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: the address of the LSB of the word1
// addr2: the address of the LSB of the word2
// label: the label to branch to if word1 >= word2
// Accum: changes
// X Reg: unchanged
// Y Reg: unchanged
.macro nv_bge16_far(addr1, addr2, label)
{
nv_cmp16(addr1, addr2)
// Carry Flag Set if addr1 >= addr2
bcc Done
jmp label
Done:
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is greater or equal tothan
// an immediate 16 bit value.
// branch if addr1 >= num
// full name is nv_bge16u_mem16u_immed16u
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// todo print macro
.macro nv_bge16_immed(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
// Carry Flag Set if addr1 >= num
bcs label
}
//////////////////////////////////////////////////////////////////////////////
// inline macro to branch if one word in memory is greater or equal tothan
// an immediate 16 bit value.
// branch if addr1 >= num
// full name is nv_bge16u_mem16u_immed16u_far
// The branch label's address can be farther than +127/-128 bytes away
// addr1: is the address of LSB of one word (addr1+1 is MSB)
// num: is the immediate 16 bit value to compare with the contents of addr1
// label: is the label to branch to
// todo print macro
.macro nv_bge16_immed_far(addr1, num, label)
{
nv_cmp16_immed(addr1, num)
// Carry Flag Set if addr1 >= num
bcc Done
jmp label
Done:
}