-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvwas6502.asm
450 lines (411 loc) · 10.1 KB
/
vwas6502.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
;; vwas6502.asm - interactive console 6502 assembler
;;
;; >>> STATUS: work in progress, ported for use with wozmon_cbm <<<
;;
;; INSTRUCTIONS
;; LOAD"WOZMON SYS5120",8,1
;; LOAD"VWAS6502",8,1
;; SYS 5120
;; 1500 R 1500
;;
;; Use WozMon run command to run disassembler with an address as an argument
;; The first 20 statements at that address will be disassembled
;; Repeat with other desired addresses.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MIT License
;;
;; Copyright (c) 2024 David R. Van Wagner
;; davevw.com
;;
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
;; The above copyright notice and this permission notice shall be included in all
;; copies or substantial portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; global
inputbuf=$0200
; zeropage
ptr1=$fb ; and $fc
ptr3=$fd ; and $fe
tmp=$ff
opidx=$22
inidx=$23
admode=$28
size=$29
counter=$2A
*=$1500
start:
jmp disassemble
charout:
jmp $ffd2 ; allow patching
disassemble:
lda #0
sta counter ; assume parse failed
jsr ignorespc
bcs ++
+ jsr inputhexword ; parse input to address word in ptr1
bcs ++
inc counter ; parse succeeded!
++ lda #<copyright
ldx #>copyright
jsr strout
lda counter ; bool whether parsed input correctly or not
beq ++ ; branch if zero
lda #20
sta counter ; setup to display 20 lines of disassembly
- ldy #0
lda (ptr1),y
jsr find_opcode
jsr disp_current
lda size
bpl +
lda #1
+ clc
adc ptr1
sta ptr1
bcc +
inc ptr1+1
+ dec counter
bne -
++ jmp $1400 ; return to wozmon
find_opcode: ; INPUT: .A opcode byte, OUTPUT: C flag set if found, .A instruction index, .X opcode index, .Y admode, otherwise C clear, and .A/.X/.Y all $FF
; and properties updated in ZP globals size,inidx,opidx,admode
ldy #1
sty size
ldy #nopcodes
ldx #nopcodes-1
- cmp opcodes,x
beq +
dex
dey
bne -
clc
lda #$FF
tax
tay
bcc ++
+ lda instidx, x
ldy modeidx, x
cpy #2 // Immediate
bcc +
inc size
cpy #9 // Absolute
bcc +
inc size
+ sec
++ sta inidx
stx opidx
sty admode
rts
disp_opcode: ; .A opcode byte
jsr find_opcode
txa
; fall through to display instruction
dispinst: ; .A instruction index 0..55
tax
cpx #ninst
bcs +
lda inst0, x
jsr charout
lda inst1, x
jsr charout
lda inst2, x
jmp charout
+ lda #'?'
jsr charout
jsr charout
jsr charout
rts
disp_current:
lda ptr1
ldx ptr1+1
jsr disphexword
jsr spaceout
ldy #0
ldx size
- lda (ptr1),y
jsr disphexbyte
jsr spaceout
iny
dex
bne -
- cpy #3
beq +
lda #0
sta 199
jsr spaceout
lda #0
sta 199
lda #$20
jsr charout
jsr charout
iny
bne -
+ lda inidx
jsr dispinst
lda #$20
jsr charout
jsr disp_mode
lda #13
jmp charout
disp_mode
lda admode
cmp #13
bcs +
asl
tax
lda mode_jmptable+1,x
pha
lda mode_jmptable,x
pha
+ rts
dispModeAcc:
lda #'A'
jmp charout
dispModeNone:
rts
dispModeImm:
lda #'#'
jsr charout
dispModeZP:
lda #'$'
jsr charout
ldy #1
lda (ptr1),y
jmp disphexbyte
dispModeIndX:
lda #'('
jsr charout
lda #'$'
jsr charout
ldy #1
lda (ptr1),y
jsr disphexbyte
lda #','
jsr charout
lda #'X'
jsr charout
lda #')'
jmp charout
dispModeIndY:
lda #'('
jsr charout
lda #'$'
jsr charout
ldy #1
lda (ptr1),y
jsr disphexbyte
lda #')'
jsr charout
lda #','
jsr charout
lda #'Y'
jmp charout
dispModeRel:
lda #'$'
jsr charout
clc
lda ptr1
adc #2
sta ptr3
lda ptr1+1
adc #0
sta ptr3+1
ldy #1
lda (ptr1),y
bpl +
; I'm not sure how to successfully navigate page boundries adding signed byte to unsigned byte, so I'm subtracting unsigned bytes instead
eor #$FF ; inverse
clc
adc #1 ; complete getting absolute value from two's complement
sta tmp
sec
lda ptr3
sbc tmp
sta ptr3
bcs ++
dec ptr3+1
bcc ++
+ clc ; simple case of adding
adc ptr3
sta ptr3
bcc ++
inc ptr3+1
++ lda ptr3
ldx ptr3+1
jmp disphexword
dispModeZPX:
jsr dispModeZP
lda #','
jsr charout
lda #'X'
jmp charout
dispModeZPY:
jsr dispModeZP
lda #','
jsr charout
lda #'Y'
jmp charout
dispModeAbs:
lda #'$'
jsr charout
ldy #1
lda (ptr1),y
pha
iny
lda (ptr1),y
tax
pla
jmp disphexword
dispModeAbsX:
jsr dispModeAbs
lda #','
jsr charout
lda #'X'
jmp charout
dispModeAbsY:
jsr dispModeAbs
lda #','
jsr charout
lda #'Y'
jmp charout
dispModeInd:
lda #'('
jsr charout
jsr dispModeAbs
lda #')'
jmp charout
disphexword: ; .A low, .X high, 0000..FFFF
pha
txa
jsr disphexbyte
pla
;fall through to call again
disphexbyte: ; .A 00..FF
pha
lsr
lsr
lsr
lsr
jsr disphexnybble
pla
;fall through to call again
disphexnybble: ; .A 0..F
and #$0F
ora #$30
cmp #$3A
bcc +
adc #$06
+ jmp charout
ignorespc:
; input pointer first points to R when execution comes from wozmon
-- iny ; advance input pointer
beq + ; way too far
lda inputbuf,y
and #$7F
bne +
- sec ; error
rts
+ cmp #$20
beq --
clc ; okay
rts
inputhexword:
jsr inputhexbyte
bcs ++
sta ptr1 ; assume one byte
lda #0
sta ptr1+1 ; extend to 16 bits
jsr inputhexbyte
bcs +
ldx ptr1 ; two bytes so shift the bytes
stx ptr1+1
sta ptr1
+ clc
++ rts
inputhexbyte:
jsr inputhexnybble
bcs +
sta tmp
jsr inputhexnybble
bcs +
asl tmp
asl tmp
asl tmp
asl tmp
ora tmp
+ rts
inputhexnybble:
lda $0200,y
and #$7F
sec
sbc #$30
bcc ++
cmp #10
bcc +
sbc #7
bcc ++
cmp #10
bcc ++
cmp #16
bcs ++
+ iny
rts
++ sec
rts
strout:
sta ptr3
stx ptr3+1
ldy #0
- lda (ptr3),y
beq +
jsr charout
iny
bne -
+ rts
spaceout:
jsr $14ed ; wozmon_cbm space out, use reverse for Vic-20 due to column constraints
lda #$20
rts
end: brk
; instruction textual mnuemonic first, second, third letters (read down in source)
ninst = 56
inst0 !text "AAABBBBBBBBBBCCCCCCCDDDEIIIJJLLLLNOPPPPRRRRSSSSSSSTTTTTT"
inst1 !text "DNSCCEIMNPRVVLLLLMPPEEEONNNMSDDDSORHHLLOOTTBEEETTTAASXXY"
inst2 !text "CDLCSQTIELKCSCDIVPXYCXYRCXYPRAXYRPAAPAPLRISCCDIAXYXYXASA"
; 6502 addressing modes by index number and number of bytes per instruction shown at end of comment
mode_jmptable:
!word dispModeAcc-1; 0 Accumulator 1
!word dispModeNone-1 ; 1 None 1
!word dispModeImm-1 ; 2 Immediate 2
!word dispModeIndX-1 ; 3 IndirectX 2
!word dispModeIndY-1 ; 4 IndirectY 2
!word dispModeRel-1 ; 5 Relative 2
!word dispModeZP-1 ; 6 ZeroPage 2
!word dispModeZPX-1 ; 7 ZeroPageX 2
!word dispModeZPY-1 ; 8 ZeroPageY 2
!word dispModeAbs-1 ; 9 Absolute 3
!word dispModeAbsX-1 ; 10 AbsoluteX 3
!word dispModeAbsY-1 ; 11 AbsoluteY 3
!word dispModeInd-1 ; 12 Indirect 3
; opcode table of byte values (opcodes), instructions, and addressing modes
nopcodes = 151
opcodes !byte $00,$01,$05,$06,$08,$09,$0A,$0D,$0E,$10,$11,$15,$16,$18,$19,$1D,$1E,$20,$21,$24,$25,$26,$28,$29,$2A,$2C,$2D,$2E,$30,$31,$35,$36,$38,$39,$3D,$3E,$40,$41,$45,$46,$48,$49,$4A,$4C,$4D,$4E,$50,$51,$55,$56,$58,$59,$5D,$5E,$60,$61,$65,$66,$68,$69,$6A,$6C,$6D,$6E,$70,$71,$75,$76,$78,$79,$7D,$7E,$81,$84,$85,$86,$88,$8A,$8C,$8D,$8E,$90,$91,$94,$95,$96,$98,$99,$9A,$9D,$A0,$A1,$A2,$A4,$A5,$A6,$A8,$A9,$AA,$AC,$AD,$AE,$B0,$B1,$B4,$B5,$B6,$B8,$B9,$BA,$BC,$BD,$BE,$C0,$C1,$C4,$C5,$C6,$C8,$C9,$CA,$CC,$CD,$CE,$D0,$D1,$D5,$D6,$D8,$D9,$DD,$DE,$E0,$E1,$E4,$E5,$E6,$E8,$E9,$EA,$EC,$ED,$EE,$F0,$F1,$F5,$F6,$F8,$F9,$FD,$FE
instidx !byte $0A,$22,$22,$02,$24,$22,$02,$22,$02,$09,$22,$22,$02,$0D,$22,$22,$02,$1C,$01,$06,$01,$27,$26,$01,$27,$06,$01,$27,$07,$01,$01,$27,$2C,$01,$01,$27,$29,$17,$17,$20,$23,$17,$20,$1B,$17,$20,$0B,$17,$17,$20,$0F,$17,$17,$20,$2A,$00,$00,$28,$25,$00,$28,$1B,$00,$28,$0C,$00,$00,$28,$2E,$00,$00,$28,$2F,$31,$2F,$30,$16,$35,$31,$2F,$30,$03,$2F,$31,$2F,$30,$37,$2F,$36,$2F,$1F,$1D,$1E,$1F,$1D,$1E,$33,$1D,$32,$1F,$1D,$1E,$04,$1D,$1F,$1D,$1E,$10,$1D,$34,$1F,$1D,$1E,$13,$11,$13,$11,$14,$1A,$11,$15,$13,$11,$14,$08,$11,$11,$14,$0E,$11,$11,$14,$12,$2B,$12,$2B,$18,$19,$2B,$21,$12,$2B,$18,$05,$2B,$2B,$18,$2D,$2B,$2B,$18
modeidx !byte $01,$03,$06,$06,$01,$02,$00,$09,$09,$05,$04,$07,$07,$01,$0B,$0A,$0A,$09,$03,$06,$06,$06,$01,$02,$00,$09,$09,$09,$05,$04,$07,$07,$01,$0B,$0A,$0A,$01,$03,$06,$06,$01,$02,$00,$09,$09,$09,$05,$04,$07,$07,$01,$0B,$0A,$0A,$01,$03,$06,$06,$01,$02,$00,$0C,$09,$09,$05,$04,$07,$07,$01,$0B,$0A,$0A,$03,$06,$06,$06,$01,$01,$09,$09,$09,$05,$04,$07,$07,$08,$01,$0B,$01,$0A,$02,$03,$02,$06,$06,$06,$01,$02,$01,$09,$09,$09,$05,$04,$07,$07,$08,$01,$0B,$01,$0A,$0A,$0B,$02,$03,$06,$06,$06,$01,$02,$01,$09,$09,$09,$05,$04,$07,$07,$01,$0B,$0A,$0A,$02,$03,$06,$06,$06,$01,$02,$01,$09,$09,$09,$05,$04,$07,$07,$01,$0B,$0A,$0A
copyright !text 13,145,"VWAS2024 (C) 2024 DAVID R. VAN WAGNER", 13, "MIT LICENSE DAVEVW.COM", 157, 13, 0
finish = *