-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathopcode.src
813 lines (810 loc) · 19.3 KB
/
opcode.src
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
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
.page
.subttl "Opcode Definition & Evaluation"
;
; opcodes.
; 0 1 2 3 4 5 6 7 8 9 a b c d e f
; type imm abs zp acc imp (x) (y) z,x a,x a,y rel (a) z,y (z) (a,x)
; mnem imm abs zpg acc imp izx izy zpx abx aby rel iab zpy izp iax
; #bytes 2 3 2 1 1 2 2 2 3 3 2 3 2 2 3
;
;
bit_mode_imm = %0000000000000001
bit_mode_abs = %0000000000000010
bit_mode_zpg = %0000000000000100
bit_mode_acc = %0000000000001000
bit_mode_imp = %0000000000010000
bit_mode_izx = %0000000000100000
bit_mode_izy = %0000000001000000
bit_mode_zpx = %0000000010000000
bit_mode_abx = %0000000100000000
bit_mode_aby = %0000001000000000
bit_mode_rel = %0000010000000000
bit_mode_iab = %0000100000000000
bit_mode_zpy = %0001000000000000
bit_mode_izp = %0010000000000000
bit_mode_iax = %0100000000000000
bit_mode_write = %1000000000000000 ; this is a flag for xref only
;
;
mode_imm = 0
mode_abs = 1
mode_zpg = 2
mode_acc = 3
mode_imp = 4
mode_izx = 5
mode_izy = 6
mode_zpx = 7
mode_abx = 8
mode_aby = 9
mode_rel = 10
mode_iab = 11
mode_zpy = 12
mode_izp = 13
mode_iax = 14
;
;imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
;
;
;opcode_strcuture
; <pntr><name><mode><....>
; <pntr> = single byte pntr to next opcode
; <name) = 2 byte hashed opcode name
; <mode> = sixteeen bit addressing mode flag
; <....> = 1-16 bytes of opcode values.
; ( only those that exsist according to <mode> are present ).
;
opstruct_name_offset = 1
opstruct_mode_offset = 3
opstruct_op_offset = 5
;
add_mode .macro %mode,%arg
.ifge %arg
defop_mode = defop_mode+%mode
defop_count = defop_count+1
.endif
.endm
;
;
;
defop .macro %name,^wri,^imm,^abs,^zpg,^acc,^imp,^izx,^izy,^zpx,^abx,^aby,^rel,^iab,^zpy,^izp,^iax
.ife ^wri
defop_mode = 0
.else
defop_mode = bit_mode_write
.endif
defop_count = 0
; 1 2 3 4 5 6 7 8 9 a b c d e f
; imm abs zp acc imp (x) (y) z,x a,x a,y rel (a) z,y (z) write
add_mode bit_mode_imm,^imm
add_mode bit_mode_abs,^abs
add_mode bit_mode_zpg,^zpg
add_mode bit_mode_acc,^acc
add_mode bit_mode_imp,^imp
add_mode bit_mode_izx,^izx
add_mode bit_mode_izy,^izy
add_mode bit_mode_zpx,^zpx
add_mode bit_mode_abx,^abx
add_mode bit_mode_aby,^aby
add_mode bit_mode_rel,^rel
add_mode bit_mode_iab,^iab
add_mode bit_mode_zpy,^zpy
add_mode bit_mode_izp,^izp
add_mode bit_mode_iax,^iax
;
opcode_hash_value = 0
.irpc %char,%name
opcode_hash_value = %00100000*opcode_hash_value+%00011111!.'%char'
.endr
;
.byte defop_count+5
.word opcode_hash_value
.word defop_mode
;
.ifge ^imm
.byte ^imm
.endif
.ifge ^abs
.byte ^abs
.endif
.ifge ^zpg
.byte ^zpg
.endif
.ifge ^acc
.byte ^acc
.endif
.ifge ^imp
.byte ^imp
.endif
.ifge ^izx
.byte ^izx
.endif
.ifge ^izy
.byte ^izy
.endif
.ifge ^zpx
.byte ^zpx
.endif
.ifge ^abx
.byte ^abx
.endif
.ifge ^aby
.byte ^aby
.endif
.ifge ^rel
.byte ^rel
.endif
.ifge ^iab
.byte ^iab
.endif
.ifge ^zpy
.byte ^zpy
.endif
.ifge ^izp
.byte ^izp
.endif
.ifge ^iax
.byte ^iax
.endif
;
.endm
; imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
opcode_table
defop lda,0,$a9,$ad,$a5,-01,-01,$a1,$b1,$b5,$bd,$b9,-01,-01,-01,-01,-01
defop sta,1,-01,$8d,$85,-01,-01,$81,$91,$95,$9d,$99,-01,-01,-01,-01,-01
defop jsr,0,-01,$20,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop adc,0,$69,$6d,$65,-01,-01,$61,$71,$75,$7d,$79,-01,-01,-01,-01,-01
defop and,0,$29,$2d,$25,-01,-01,$21,$31,$35,$3d,$39,-01,-01,-01,-01,-01
defop asl,1,-01,$0e,$06,$0a,-01,-01,-01,$16,$1e,-01,-01,-01,-01,-01,-01
; imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
defop bcc,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$90,-01,-01,-01,-01
defop bcs,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$b0,-01,-01,-01,-01
defop beq,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$f0,-01,-01,-01,-01
defop bit,0,-01,$2c,$24,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop bmi,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$30,-01,-01,-01,-01
defop bne,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$d0,-01,-01,-01,-01
defop bpl,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$10,-01,-01,-01,-01
defop brk,0,-01,-01,-01,-01,$00,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop bvc,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$50,-01,-01,-01,-01
defop bvs,0,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,$70,-01,-01,-01,-01
; 0,imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
defop clc,0,-01,-01,-01,-01,$18,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop cld,0,-01,-01,-01,-01,$d8,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop cli,0,-01,-01,-01,-01,$58,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop clv,0,-01,-01,-01,-01,$b8,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop cmp,0,$c9,$cd,$c5,-01,-01,$c1,$d1,$d5,$dd,$d9,-01,-01,-01,-01,-01
defop cpx,0,$e0,$ec,$e4,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop cpy,0,$c0,$cc,$c4,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
; imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
defop dec,1,-01,$ce,$c6,-01,-01,-01,-01,$d6,$de,-01,-01,-01,-01,-01,-01
defop dex,1,-01,-01,-01,-01,$ca,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop dey,1,-01,-01,-01,-01,$88,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop eor,0,$49,$4d,$45,-01,-01,$41,$51,$55,$5d,$59,-01,-01,-01,-01,-01
defop inc,1,-01,$ee,$e6,-01,-01,-01,-01,$f6,$fe,-01,-01,-01,-01,-01,-01
defop inx,1,-01,-01,-01,-01,$e8,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop iny,1,-01,-01,-01,-01,$c8,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
; imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
defop jmp,0,-01,$4c,-01,-01,-01,-01,-01,-01,-01,-01,-01,$6c,-01,-01,-01
defop ldx,0,$a2,$ae,$a6,-01,-01,-01,-01,-01,-01,$be,-01,-01,$b6,-01,-01
defop ldy,0,$a0,$ac,$a4,-01,-01,-01,-01,$b4,$bc,-01,-01,-01,-01,-01,-01
defop lsr,1,-01,$4e,$46,$4a,-01,-01,-01,$56,$5e,-01,-01,-01,-01,-01,-01
defop nop,0,-01,-01,-01,-01,$ea,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop ora,0,$09,$0d,$05,-01,-01,$01,$11,$15,$1d,$19,-01,-01,-01,-01,-01
defop pha,0,-01,-01,-01,-01,$48,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop php,0,-01,-01,-01,-01,$08,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop pla,0,-01,-01,-01,-01,$68,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop plp,0,-01,-01,-01,-01,$28,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
; imm abs zpg acc imp izx izy zpx abx aby rel ind zpy izp iax
defop rol,1,-01,$2e,$26,$2a,-01,-01,-01,$36,$3e,-01,-01,-01,-01,-01,-01
defop ror,1,-01,$6e,$66,$6a,-01,-01,-01,$76,$7e,-01,-01,-01,-01,-01,-01
defop rti,0,-01,-01,-01,-01,$40,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop rts,0,-01,-01,-01,-01,$60,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop sbc,0,$e9,$ed,$e5,-01,-01,$e1,$f1,$f5,$fd,$f9,-01,-01,-01,-01,-01
defop sec,0,-01,-01,-01,-01,$38,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop sed,0,-01,-01,-01,-01,$f8,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop sei,0,-01,-01,-01,-01,$78,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop stx,1,-01,$8e,$86,-01,-01,-01,-01,-01,-01,-01,-01,-01,$96,-01,-01
defop sty,1,-01,$8c,$84,-01,-01,-01,-01,$94,-01,-01,-01,-01,-01,-01,-01
defop tax,0,-01,-01,-01,-01,$aa,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop tay,0,-01,-01,-01,-01,$a8,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop tsx,0,-01,-01,-01,-01,$ba,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop txa,0,-01,-01,-01,-01,$8a,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop txs,0,-01,-01,-01,-01,$9a,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
defop tya,0,-01,-01,-01,-01,$98,-01,-01,-01,-01,-01,-01,-01,-01,-01,-01
.byte 0
end_opcode_table
;
;
ram opcode_hash,2 two byte area for hash of opcode name
opcode_temp = opcode_hash two byte temp area
zpage opcode_pntr,2
ram opcode_flags syntax flags for features found in arg to opcode
;
; opcode_flags = flag values for argument features
flag_inx = %00000001 ; index x ,x
flag_iny = %00000010 ; index y ,y
flag_ind = %00000100 ; indirect )
flag_opp = %00001000 ; opening paren (
flag_imm = %00010000 ; immediate #
flag_acc = %00100000 ; accumilator mode "A"
flag_noarg = %01000000 ; no argument flag
;
;
ram opcode_modes,16 legality flags for opcodes ( 0 = not opcode )
ram opcodes,16 opcodes in each addressing mode.
;
; find_opcode finds opcode list
; entry: oper point to 3 byte of mnumonic
; exit: c=1 .a = 'O'
; opcode not found; c=0 opcode found
; opcode_modes ( b7 ) set for legal modes
; opcodes contains opcodes for modes
; marked as legal.
;
find_opcode
lda #0 opcode_hash <= hash value for opcode
sta opcode_hash
tay
10$ lda (oper),y
jsr isalpha
bcc 15$
;
90$ sec puke if non alpha char
lda #'O
rts
;
15$ jsr 100$
iny
cpy #3
bne 10$
;
lda (oper),y puke iff > 3 chars
bne 90$
;
ldi opcode_table opcode_pntr <= base of opcode_table
std opcode_pntr
;
20$ ldy #0 do if (opcode_pntr) == null
lda (opcode_pntr),y
beq 90$ go puke
ldy #opstruct_name_offset
lda (opcode_pntr),y if this name matches
cmp opcode_hash
bne 30$
iny
lda (opcode_pntr),y
cmp opcode_hash+1
beq 50$ goto 50$
;
;
30$ ldy #0 opcode_pntr += (opcode_pntr)
lda (opcode_pntr),y
clc
adc opcode_pntr
sta opcode_pntr
bcc 20$
inc opcode_pntr+1
jmp 20$ forever
;
50$ ldy #opstruct_mode_offset+1 opcode_tempo <= legal modes
lda (opcode_pntr),y
sta opcode_temp+1
dey
lda (opcode_pntr),y
sta opcode_temp
;
ldy #opstruct_op_offset y <= offset in structure to opcode storage
ldx #0 x <= 0
;
60$ lsr opcode_temp+1 do shift bit out of legal modes
ror opcode_temp
bcc 65$ if bit set
;
lda (opcode_pntr),y opcodes,x <= next byte in struct
sta opcodes,x
iny y ++
;
65$ ror opcode_modes,x shift carry high order modes byte
inx inx
cpx #16 until x = 16
bne 60$
clc return happy
rts
;
;
100$ asl a
asl a
asl a
ldx #4
110$ asl a
rol opcode_hash
rol opcode_hash+1
dex
bpl 110$
rts
;
;
;
.ifn 0
;
;
; opcode_analyze_arg
;
; looks at (arg)
; termiates at first non quoted space or semi colon
; sets flag
;
;
opcode_analyze_arg
lda #0 opcode_flags <= 00
sta opcode_flags
;
10$ jsr delimit_single_arg delimit the arg ( commas not relevant )
bcs 110$ if error go set no arg bits.
;
; trailing spaces, semicolon or EOS have now resulted in
; the ARG being terminated.
;
;
jsr 150$ x,a <= last two chars in string
;
cpx #'Y if arg ends in ",Y"
bne 30$
cmp #',
bne 30$
;
lda #flag_iny set flags and terminate arg
jsr 100$
jsr 150$ x,a <= last two chars in string
;
30$ cpx #') if last char is )
bne 40$
iny y ++ ( point to last char )
lda #flag_ind set flags and terminate arg
jsr 100$
jsr 150$ x,a <= last two chars in string
;
40$ cpx #'X if arg ends in ",X"
bne 60$
cmp #',
bne 60$
;
lda #flag_inx set flags and terminate arg
jsr 100$
;
;
60$ ldy #0 if string starts with immediatte sign
lda (arg),y
cmp #'#
bne 70$
;
incd arg skip immediate sign
;
lda #flag_imm set immediate flag
jsr 120$
;
70$ lda (arg),y if string starts with open paren
cmp #'(
bne 80$
;
incd arg skip open paren
;
lda #flag_opp set open paren flag
jsr 120$
;
80$ lda (arg),y if string is now a single A
jsr toupper
cmp #'A
bne 90$
iny
lda (arg),y
bne 90$
lda #flag_acc set accumilator flag
jsr 120$
ldy #0 nullify string
tya
sta (arg),y
rts
;
90$ ldy #0 if arg is null
lda (arg),y
beq 110$ go set no arg flag and return
99$ rts return
;
;
100$ jsr 120$ set bits in opcode flags
lda #0 terminate arg at yth char
sta (arg),y
rts return
;
110$ lda #flag_noarg set no argumnet flag
120$ ora opcode_flags set bits in opcode flags
sta opcode_flags
rts return
;
; 150$
; if (arg) > 2 chars
; x <= last char
; a <= next to last char
; y <= pointer to next to last char
; else
; x,a <= 0
;
;
150$ ldy #$ff y <= pointer to last char in .arg
ldx #0 ( .a,.x = 0 )
160$ iny
lda (arg),y
bne 160$
;
cpy #2 if y < 2
bcc 170$ go return
;
dey x <= last char ( upper case please )
lda (arg),y
jsr toupper
tax
dey y <= pointer to next to last char
lda (arg),y .a <= next to last char
170$ rts
;
;
.else
;
;
; opcode_analyze_arg
;
; looks at (arg)
; termiates at first non quoted space or semi colon
; sets flag
;
;
opcode_analyze_arg
lda #0 opcode_flags <= 00
sta opcode_flags
;
10$ jsr delimit_single_arg delimit the arg ( commas not relevant )
bcs 110$ if error go set no arg bits.
;
; trailing spaces, semicolon or EOS have now resulted in
; the ARG being terminated.
;
ldy #0 if string starts with immediatte sign
lda (arg),y
cmp #'#
bne 20$
lda #flag_imm set immediate flag & skip
jsr 105$
jmp 80$ check for null arg and return
;
;
20$ cmp #'( if string starts with open paren
bne 25$
;
lda #flag_opp set open paren flag & skip
jsr 105$
;
25$ jsr 150$ x,a <= last two chars in string
;
cpx #'Y if arg ends in ",Y"
bne 30$
cmp #',
bne 30$
;
lda #flag_iny set flags and terminate arg
jsr 100$
jsr 150$ x,a <= last two chars in string
;
30$ cpx #') if last char is )
bne 40$
lda #flag_opp if no open paren
bit opcode_flags
beq 80$ go exit
;
iny y ++ ( point to last char )
lda #flag_ind set flags and terminate arg
jsr 100$
jsr 150$ x,a <= last two chars in string
;
40$ cpx #'X if arg ends in ",X"
bne 80$
cmp #',
bne 80$
;
lda #flag_inx set flags and terminate arg
jsr 100$
;
80$ ldy #0
lda (arg),y if string is now null
beq 110$ go set no arg and return
jsr toupper if its a single .a
cmp #'A
bne 90$
iny
lda (arg),y
bne 90$
lda #flag_acc set accumilator flag
jsr 120$
ldy #0 nullify string
tya
sta (arg),y
90$ rts return
;
;
;
100$ jsr 120$ set bits in opcode flags
lda #0 terminate arg at yth char
sta (arg),y
rts return
;
105$ incd arg inc arg
.byte $2c
;
110$ lda #flag_noarg set no argumnet flag
;
120$ ora opcode_flags set bits in opcode flags
sta opcode_flags
rts return
;
; 150$
; if (arg) > 2 chars
; x <= last char
; a <= next to last char
; y <= pointer to next to last char
; else
; x,a <= 0
;
;
150$ ldy #$ff y <= pointer to last char in .arg
ldx #0 ( .a,.x = 0 )
160$ iny
lda (arg),y
bne 160$
;
cpy #2 if y < 2
bcc 170$ go return
;
dey x <= last char ( upper case please )
lda (arg),y
jsr toupper
tax
dey y <= pointer to next to last char
lda (arg),y .a <= next to last char
170$ rts
;
;
.endif
;
;******************************************************************************
; EVAL_OPCODE
;******************************************************************************
;
;
; this routine parses opcode and arg.
; it checks for errors.
; it calls outbyte to emit object code bytes
; it calls eval to check the value of the argument
; it calls outerr for various errors
; it return the number of object code bytes created.
;
;
; the software first searches for the opcode in the opcode
; tables, and also checks the arguement for various syntactical
; features expected by 6502 assemeblers.
;
; if then combines information about the addressing mode with
; the syntactical features found and the results of any arguement
; evalautation to produce lots of errors except in the special case
; where in the input line is correct.
;
; ram value 16 bit flag
; ram valerr = 0 ok
; = 1 undefined
; = 2 forward reference
eval_opcode
jsr find_opcode find the opcode
bcc 1$
rts
; if implied operation
1$ lda opcode_modes+mode_imp
bpl 10$
lda opcodes+mode_imp .a <= opcode
81$ ldy #0 output at pc
jsr outbyte
lda #1 return happy one byte used
clc
rts
;
10$ jsr opcode_analyze_arg examine the arg for syntactical features
lda opcode_flags if no arg or 'A' addressing selected
and #flag_noarg+flag_acc
beq 20$
;
ldx opcode_modes+mode_acc if acc addressing allowed
bpl 17$
lda opcode_flags if any other flags set
cmp #flag_acc
beq 15$
jsr outerr_q ???
15$ lda opcodes+mode_acc output the acc mode byte
jmp 81$ & return happy
; else
17$ and #flag_noarg if no arg
beq 18$ dreaded 'E' error
jmp 90$
;
18$ and #255-flag_acc clear noarg flag
sta opcode_flags
;
lda #$a value <= $000a
sta value
lda #0
sta value+1
sta valflg valflg <= no errors
jsr outerr_q output a ??
jmp 30$ else
;
20$ asl opcode_modes+15 c <= b7 of write mode opcade flag
jsr xref_write_if_carry
ldd arg go evaluate the arguement
jsr eval ( user gets the errors )
clc
jsr xref_write_if_carry
;
;
; at this point
; implied and accumilator modes have been eliminated.
; the arguement has been evaluated, and any evaluation
; errors have been reported.
;
;
;
30$ lda opcode_modes+mode_rel
; if relative mode opcode
bpl 40$
lda opcode_flags if any flags set
beq 31$
;
jsr outerr_q ?
;
31$ ldi $FFFE value <= -2 + value - pc
add value
sbd pc
std value
;
asl a spit 'A' error if out of range
txa
bcc 32$
eor #$ff
32$ beq 35$
jsr outerr_a
;
35$ lda opcodes+mode_rel a <= relative mode opcode
;
82$ ldy #0 output .a as opcode
jsr outbyte
lda value output low order value
ldy #1
jsr outbyte
lda #2 .a <= 2 bytes used
clc return happy
rts
;
40$ lda opcode_flags
and #flag_imm if immediate mode selected
beq 50$
cmp opcode_flags if others selected
beq 47$
jsr outerr_q outerr a q
47$ ldx #mode_imp x <= known illegal mode
ldy #mode_imm y <= immeditate mode
jmp 100$ go select one
;
50$ lda opcode_flags
and #flag_ind+flag_opp if any parens found
beq 70$
cmp #flag_ind+flag_opp if both not found
beq 55$
jsr outerr_q output a 'Q' error
;
55$ lda opcode_flags if no indexing
and #flag_iny+flag_inx
bne 60$
ldx #mode_iab x,a <= abs,zpg indirect modes
ldy #mode_izp
jmp 100$ go perform decision
;
60$ cmp #flag_inx if by x only
bne 65$
;
ldx #mode_iax x,a <= abs,zpg indirect indexed modes
ldy #mode_izx
jmp 100$
;
65$ cmp #flag_iny if not by y only
beq 67$
jsr outerr_q ??
;
67$ ldx #mode_imp x <= known illegal opcode mode
ldy #mode_izy
jmp 100$ go decide
;
;
; have eliminated implied, acc immediate,relative and
; all indirect forms of addressing. therefore it must be
; indexing by x, ort y or no indexing at all
;
70$ lda opcode_flags if not index by x
cmp #flag_inx
beq 85$ if not index by y
cmp #flag_iny
beq 80$
cmp #0
beq 75$ if any flags set...
jsr outerr_q question that
;
75$ ldx #mode_abs x,y <= abs,zero page modes
ldy #mode_zpg
jmp 100$ go perform decision
;
80$ ldx #mode_aby x,y <= abs,zpg y indexed modes
ldy #mode_zpy
jmp 100$ go decide
;
;
85$ ldx #mode_abx x,y <= abs,zpg x indexed modes
ldy #mode_zpx
;
;
;100$ at this point, the zero page and absolute modes
; for this the addresing mode are in x and y.
; examine the legality of these modes and make a selection
; based on the legality of the modes, and the result of
; instructiin evaluation.
;
100$ lda opcode_modes,y if zero page mode legal
bpl 140$
;
lda value+1 if >8bit result
beq 110$
;
lda opcode_modes,x if abs legal
bmi 140$ go use abs
;
lda opcodes,y .a <= opcode to use
pha .save .a
jsr outerr_v outerr 'v'
pla reacll opcode to use
jmp 82$ go spit it out
;
110$ lda valflg if forward_reference
and #value_forward
beq 120$
lda opcode_modes,x if abs legal
bpl 120$
lda opcodes,x .a <= opcode to use
pha stack .a
jsr outerr_w wasted byte warning
pla recall .a
jmp 83$ go spit it out
;
120$ lda opcodes,y .a <= zero page opcode
jmp 82$ go spit it out.....
;
;
140$ lda opcode_modes,x if abs opcode illegal
bmi 150$
90$ jsr outerr_question I'm confused...
lda #0 return no bytes used
clc
rts
;
150$ lda opcodes,x output the opcode
83$ ldy #0
jsr outbyte
ldd value output the value
ldy #1
jsr outword
lda #3 return 3 bytes used
clc
rts
;