forked from scotws/TaliForth2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assembler.asm
1073 lines (857 loc) · 24.4 KB
/
assembler.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
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; Assembler for Tali Forth 2
; Scot W. Stevenson <scot.stevenson@gmail.com>
; First version: 07. Nov 2014 (as tasm65c02)
; This version: 03. Jan 2019
; This is the built-in assembler for Tali Forth 2. Once the assembler wordlist
; is included with
; assembler-wordlist >order
; the opcodes are available as normal Forth words. The format is Simpler
; Assembler Notation (SAN) which separates the opcode completely from the
; operand (see https://github.com/scotws/SAN). In this case, the operand is
; entered before the opcode in the postfix Forth notation (for example, "2000
; lda.#"). See the assembler documenation in the manual for more detail.
; The code here was originally used in A Typist's Assembler for the 65c02
; (tasm65c02), see https://github.com/scotws/tasm65c02 for the standalone
; version. Tasm65c02 is in the public domain.
; This code makes use of the opcode tables stored as part of the disassembler.
; ==========================================================
; MNEMONICS
; The assembler instructions are realized as individual Forth words with
; entries in the assembler wordlist (see header.asm). We pass the opcode in A.
; An alterantive method would have been along the lines of
; jsr asm_common
; .byte $EA
; where the asm_common then uses the address on the Return Stack to pick up the
; opcode and the length. Though this uses fewer resources, the current version
; makes up for this by simplifying the code of asm_common.
; The routines are organized alphabetically by SAN mnemonic, not by opcode. The
; SAN and traditional mnemonics are listed after the opcode load instruction.
; This list was generated by a Python script in the tools folder, see there for
; more detail.
assembler: ; used to calculate size of assembler code
xt_asm_adc_h: ; adc.# \ ADC #nn
lda #$69
jmp asm_common
z_asm_adc_h:
xt_asm_adc_x: ; adc.x \ ADC nnnn,X
lda #$7D
jmp asm_common
z_asm_adc_x:
xt_asm_adc_y: ; adc.y \ ADC nnnn,Y
lda #$79
jmp asm_common
z_asm_adc_y:
xt_asm_adc_z: ; adc.z \ ADC nn
lda #$65
jmp asm_common
z_asm_adc_z:
xt_asm_adc_zi: ; adc.zi \ ADC (nn)
lda #$72
jmp asm_common
z_asm_adc_zi:
xt_asm_adc_ziy: ; adc.ziy \ ADC (nn),Y
lda #$71
jmp asm_common
z_asm_adc_ziy:
xt_asm_adc_zx: ; adc.zx \ ADC nn,X
lda #$75
jmp asm_common
z_asm_adc_zx:
xt_asm_adc_zxi: ; adc.zxi \ ADC (nn,X)
lda #$61
jmp asm_common
z_asm_adc_zxi:
xt_asm_and: ; and. \ AND nnnn
lda #$2D
jmp asm_common
z_asm_and:
xt_asm_and_h: ; and.# \ AND #nn
lda #$29
jmp asm_common
z_asm_and_h:
xt_asm_and_x: ; and.x \ AND nnnn,X
lda #$3D
jmp asm_common
z_asm_and_x:
xt_asm_and_y: ; and.y \ AND nnnn,Y
lda #$39
jmp asm_common
z_asm_and_y:
xt_asm_and_z: ; and.z \ AND nn
lda #$25
jmp asm_common
z_asm_and_z:
xt_asm_and_zi: ; and.zi \ AND (nn)
lda #$32
jmp asm_common
z_asm_and_zi:
xt_asm_and_ziy: ; and.ziy \ AND (nn),Y
lda #$31
jmp asm_common
z_asm_and_ziy:
xt_asm_and_zx: ; and.zx \ AND nn,X
lda #$35
jmp asm_common
z_asm_and_zx:
xt_asm_and_zxi: ; and.zxi \ AND (nn,X)
lda #$21
jmp asm_common
z_asm_and_zxi:
xt_asm_asl: ; asl \ ASL nnnn
lda #$0E
jmp asm_common
z_asm_asl:
xt_asm_asl_a: ; asl.a \ ASL
lda #$0A
jmp asm_common
z_asm_asl_a:
xt_asm_asl_x: ; asl.x \ ASL nnnn,X
lda #$1E
jmp asm_common
z_asm_asl_x:
xt_asm_asl_z: ; asl.z \ ASL nn
lda #$06
jmp asm_common
z_asm_asl_z:
xt_asm_asl_zx: ; asl.zx \ ASL nn,X
lda #$16
jmp asm_common
z_asm_asl_zx:
xt_asm_bcc: ; bcc \ BCC
lda #$90
jmp asm_common
z_asm_bcc:
xt_asm_bcs: ; bcs \ BCS
lda #$B0
ldy #2
jmp asm_common
z_asm_bcs:
xt_asm_beq: ; beq \ BEQ
lda #$F0
jmp asm_common
z_asm_beq:
xt_asm_bit: ; bit \ BIT nnnn
lda #$2C
jmp asm_common
z_asm_bit:
xt_asm_bit_h: ; bit.# \ BIT #nn
lda #$89
jmp asm_common
z_asm_bit_h:
xt_asm_bit_x: ; bit.x \ BIT nnnn,X
lda #$3C
jmp asm_common
z_asm_bit_x:
xt_asm_bit_z: ; bit.z \ BIT nn
lda #$24
jmp asm_common
z_asm_bit_z:
xt_asm_bit_zx: ; bit.zx \ BIT nn,X
lda #$34
jmp asm_common
z_asm_bit_zx:
xt_asm_bmi: ; bmi \ BMI
lda #$30
jmp asm_common
z_asm_bmi:
xt_asm_bne: ; bne \ BNE
lda #$D0
jmp asm_common
z_asm_bne:
xt_asm_bpl: ; bpl \ BPL
lda #$10
jmp asm_common
z_asm_bpl:
xt_asm_bra: ; bra \ BRA
lda #$80
jmp asm_common
z_asm_bra:
xt_asm_brk: ; brk \ BRK
lda #$00
jmp asm_common
z_asm_brk:
xt_asm_bvc: ; bvc \ BVC
lda #$50
jmp asm_common
z_asm_bvc:
xt_asm_bvs: ; bvs \ BVS
lda #$70
jmp asm_common
z_asm_bvs:
xt_asm_clc: ; clc \ CLC
lda #$18
jmp asm_common
z_asm_clc:
xt_asm_cld: ; cld \ CLD
lda #$D8
jmp asm_common
z_asm_cld:
xt_asm_cli: ; cli \ CLI
lda #$58
jmp asm_common
z_asm_cli:
xt_asm_clv: ; clv \ CLV
lda #$B8
jmp asm_common
z_asm_clv:
xt_asm_cmp: ; cmp \ CMP nnnn
lda #$CD
jmp asm_common
z_asm_cmp:
xt_asm_cmp_h: ; cmp.# \ CMP #nn
lda #$C9
jmp asm_common
z_asm_cmp_h:
xt_asm_cmp_x: ; cmp.x \ CMP nnnn,X
lda #$DD
jmp asm_common
z_asm_cmp_x:
xt_asm_cmp_y: ; cmp.y \ CMP nnnn,Y
lda #$D9
jmp asm_common
z_asm_cmp_y:
xt_asm_cmp_z: ; cmp.z \ CMP nn
lda #$C5
jmp asm_common
z_asm_cmp_z:
xt_asm_cmp_zi: ; cmp.zi \ CMP (nn)
lda #$D2
jmp asm_common
z_asm_cmp_zi:
xt_asm_cmp_ziy: ; cmp.ziy \ CMP (nn),Y
lda #$D1
jmp asm_common
z_asm_cmp_ziy:
xt_asm_cmp_zx: ; cmp.zx \ CMP nn,X
lda #$D5
jmp asm_common
z_asm_cmp_zx:
xt_asm_cmp_zxi: ; cmp.zxi \ CMP (nn,X)
lda #$C1
jmp asm_common
z_asm_cmp_zxi:
xt_asm_cpx: ; cpx \ CPX nnnn
lda #$EC
jmp asm_common
z_asm_cpx:
xt_asm_cpx_h: ; cpx.# \ CPX #nn
lda #$E0
jmp asm_common
z_asm_cpx_h:
xt_asm_cpx_z: ; cpx.z \ CPX nn
lda #$E4
jmp asm_common
z_asm_cpx_z:
xt_asm_cpy: ; cpy \ CPY
lda #$CC
ldy #3
jmp asm_common
z_asm_cpy:
xt_asm_cpy_h: ; cpy.# \ CPY #nn
lda #$C0
jmp asm_common
z_asm_cpy_h:
xt_asm_cpy_z: ; cpy.z \ CPY nn
lda #$C4
jmp asm_common
z_asm_cpy_z:
xt_asm_dec: ; dec \ DEC nnnn
lda #$CE
jmp asm_common
z_asm_dec:
xt_asm_dec_a: ; dec.a \ DEC
lda #$3A
jmp asm_common
z_asm_dec_a:
xt_asm_dec_x: ; dec.x \ DEC nnnn,X
lda #$DE
jmp asm_common
z_asm_dec_x:
xt_asm_dec_z: ; dec.z \ DEC nn
lda #$C6
jmp asm_common
z_asm_dec_z:
xt_asm_dec_zx: ; dec.zx \ DEC nn,X
lda #$D6
jmp asm_common
z_asm_dec_zx:
xt_asm_dex: ; dex \ DEX
lda #$CA
jmp asm_common
z_asm_dex:
xt_asm_dey: ; dey \ DEY
lda #$88
jmp asm_common
z_asm_dey:
xt_asm_eor: ; eor \ EOR nnnn
lda #$4D
jmp asm_common
z_asm_eor:
xt_asm_eor_h: ; eor.# \ EOR #nn
lda #$49
jmp asm_common
z_asm_eor_h:
xt_asm_eor_x: ; eor.x \ EOR nnnn,X
lda #$5D
jmp asm_common
z_asm_eor_x:
xt_asm_eor_y: ; eor.y \ EOR nnnn,Y
lda #$59
jmp asm_common
z_asm_eor_y:
xt_asm_eor_z: ; eor.z \ EOR nn
lda #$45
jmp asm_common
z_asm_eor_z:
xt_asm_eor_zi: ; eor.zi \ EOR (nn)
lda #$52
jmp asm_common
z_asm_eor_zi:
xt_asm_eor_ziy: ; eor.ziy \ EOR (nn),Y
lda #$51
jmp asm_common
z_asm_eor_ziy:
xt_asm_eor_zx: ; eor.zx \ EOR nn,X
lda #$55
jmp asm_common
z_asm_eor_zx:
xt_asm_eor_zxi: ; eor.zxi \ EOR (nn,X)
lda #$41
jmp asm_common
z_asm_eor_zxi:
xt_asm_inc: ; inc \ INC nnnn
lda #$EE
jmp asm_common
z_asm_inc:
xt_asm_inc_a: ; inc.a \ INC
lda #$1A
jmp asm_common
z_asm_inc_a:
xt_asm_inc_x: ; inc.x \ INC nnnn,X
lda #$FE
jmp asm_common
z_asm_inc_x:
xt_asm_inc_z: ; inc.z \ INC nn
lda #$E6
jmp asm_common
z_asm_inc_z:
xt_asm_inc_zx: ; inc.zx \ INC nn,X
lda #$F6
jmp asm_common
z_asm_inc_zx:
xt_asm_inx: ; inx \ INX
lda #$E8
jmp asm_common
z_asm_inx:
xt_asm_iny: ; iny \ INY
lda #$C8
jmp asm_common
z_asm_iny:
xt_asm_jmp: ; jmp \ JMP nnnn
lda #$4C
jmp asm_common
z_asm_jmp:
xt_asm_jmp_i: ; jmp.i \ JMP (nnnn)
lda #$6C
jmp asm_common
z_asm_jmp_i:
xt_asm_jmp_xi: ; jmp.xi \ JMP (nnnn,X)
lda #$7C
jmp asm_common
z_asm_jmp_xi:
xt_asm_jsr: ; jsr \ JSR nnnn
lda #$20
jmp asm_common
z_asm_jsr:
xt_asm_lda: ; lda \ LDA nnnn
lda #$AD
jmp asm_common
z_asm_lda:
xt_asm_lda_h: ; lda.# \ LDA #nn
lda #$A9
jmp asm_common
z_asm_lda_h:
xt_asm_lda_x: ; lda.x \ LDA nnnn,X
lda #$BD
jmp asm_common
z_asm_lda_x:
xt_asm_lda_y: ; lda.y \ LDA nnnn,Y
lda #$B9
jmp asm_common
z_asm_lda_y:
xt_asm_lda_z: ; lda.z \ LDA nn
lda #$A5
jmp asm_common
z_asm_lda_z:
xt_asm_lda_zi: ; lda.zi \ LDA (nn)
lda #$B2
jmp asm_common
z_asm_lda_zi:
xt_asm_lda_ziy: ; lda.ziy \ LDA (nn),Y
lda #$B1
jmp asm_common
z_asm_lda_ziy:
xt_asm_lda_zx: ; lda.zx \ LDA nn,X
lda #$B5
jmp asm_common
z_asm_lda_zx:
xt_asm_lda_zxi: ; lda.zxi \ LDA (nn,X)
lda #$A1
jmp asm_common
z_asm_lda_zxi:
xt_asm_ldx: ; ldx \ LDX nnnn
lda #$AE
jmp asm_common
z_asm_ldx:
xt_asm_ldx_h: ; ldx.# \ LDX #nn
lda #$A2
jmp asm_common
z_asm_ldx_h:
xt_asm_ldx_y: ; ldx.y \ LDX nnnn,Y
lda #$BE
jmp asm_common
z_asm_ldx_y:
xt_asm_ldx_z: ; ldx.z \ LDX nn
lda #$A6
jmp asm_common
z_asm_ldx_z:
xt_asm_ldx_zy: ; ldx.zy \ LDX nn,Y
lda #$B6
jmp asm_common
z_asm_ldx_zy:
xt_asm_ldy: ; ldy \ LDY nnnn
lda #$AC
jmp asm_common
z_asm_ldy:
xt_asm_ldy_h: ; ldy.# \ LDY #nn
lda #$A0
jmp asm_common
z_asm_ldy_h:
xt_asm_ldy_x: ; ldy.x \ LDY nnnn,X
lda #$BC
jmp asm_common
z_asm_ldy_x:
xt_asm_ldy_z: ; ldy.z \ LDY nn
lda #$A4
jmp asm_common
z_asm_ldy_z:
xt_asm_ldy_zx: ; ldy.zx \ LDY nn,X
lda #$B4
jmp asm_common
z_asm_ldy_zx:
xt_asm_lsr: ; lsr \ LSR nnnn
lda #$4E
jmp asm_common
z_asm_lsr:
xt_asm_lsr_a: ; lsr.a \ LSR
lda #$4A
jmp asm_common
z_asm_lsr_a:
xt_asm_lsr_x: ; lsr.x \ LSR nnnn,X
lda #$5E
jmp asm_common
z_asm_lsr_x:
xt_asm_lsr_z: ; lsr.z \ LSR nn
lda #$46
jmp asm_common
z_asm_lsr_z:
xt_asm_lsr_zx: ; lsr.zx \ LSR nn,X
lda #$56
jmp asm_common
z_asm_lsr_zx:
xt_asm_nop: ; nop \ NOP
lda #$EA
jmp asm_common
z_asm_nop:
xt_asm_ora: ; ora \ ORA nnnn
lda #$0D
jmp asm_common
z_asm_ora:
xt_asm_ora_h: ; ora.# \ ORA #nn
lda #$09
jmp asm_common
z_asm_ora_h:
xt_asm_ora_x: ; ora.x \ ORA nnnn,X
lda #$1D
jmp asm_common
z_asm_ora_x:
xt_asm_ora_y: ; ora.y \ ORA nnnn,Y
lda #$19
jmp asm_common
z_asm_ora_y:
xt_asm_ora_z: ; ora.z \ ORA nn
lda #$05
jmp asm_common
z_asm_ora_z:
xt_asm_ora_zi: ; ora.zi \ ORA.ZI
lda #$12
ldy #2
jmp asm_common
z_asm_ora_zi:
xt_asm_ora_ziy: ; ora.ziy \ ORA (nn),Y
lda #$11
jmp asm_common
z_asm_ora_ziy:
xt_asm_ora_zx: ; ora.zx \ ORA nn,X
lda #$15
jmp asm_common
z_asm_ora_zx:
xt_asm_ora_zxi: ; ora.zxi \ ORA (nn,X)
lda #$01
jmp asm_common
z_asm_ora_zxi:
xt_asm_pha: ; pha \ PHA
lda #$48
jmp asm_common
z_asm_pha:
xt_asm_php: ; php \ PHP
lda #$08
jmp asm_common
z_asm_php:
xt_asm_phx: ; phx \ PHX
lda #$DA
jmp asm_common
z_asm_phx:
xt_asm_phy: ; phy \ PHY
lda #$5A
jmp asm_common
z_asm_phy:
xt_asm_pla: ; pla \ PLA
lda #$68
jmp asm_common
z_asm_pla:
xt_asm_plp: ; plp \ PLP
lda #$28
jmp asm_common
z_asm_plp:
xt_asm_plx: ; plx \ PLX
lda #$FA
jmp asm_common
z_asm_plx:
xt_asm_ply: ; ply \ PLY
lda #$7A
jmp asm_common
z_asm_ply:
xt_asm_rol: ; rol \ ROL nnnn
lda #$2E
jmp asm_common
z_asm_rol:
xt_asm_rol_a: ; rol.a \ ROL
lda #$2A
jmp asm_common
z_asm_rol_a:
xt_asm_rol_x: ; rol.x \ ROL nnnn,X
lda #$3E
jmp asm_common
z_asm_rol_x:
xt_asm_rol_z: ; rol.z \ ROL nn
lda #$26
jmp asm_common
z_asm_rol_z:
xt_asm_rol_zx: ; rol.zx \ ROL nn,X
lda #$36
jmp asm_common
z_asm_rol_zx:
xt_asm_ror: ; ror \ ROR nnnn
lda #$6E
jmp asm_common
z_asm_ror:
xt_asm_ror_a: ; ror.a \ ROR
lda #$6A
jmp asm_common
z_asm_ror_a:
xt_asm_ror_x: ; ror.x \ ROR nnnn,X
lda #$7E
jmp asm_common
z_asm_ror_x:
xt_asm_ror_z: ; ror.z \ ROR nn
lda #$66
jmp asm_common
z_asm_ror_z:
xt_asm_ror_zx: ; ror.zx \ ROR nn,X
lda #$76
jmp asm_common
z_asm_ror_zx:
xt_asm_rti: ; rti \ RTI
lda #$40
jmp asm_common
z_asm_rti:
xt_asm_rts: ; rts \ RTS
lda #$60
jmp asm_common
z_asm_rts:
xt_asm_sbc: ; sbc \ SBC nnnn
lda #$ED
jmp asm_common
z_asm_sbc:
xt_asm_sbc_h: ; sbc.# \ SBC #nn
lda #$E9
jmp asm_common
z_asm_sbc_h:
xt_asm_sbc_x: ; sbc.x \ SBC nnnn,X
lda #$FD
jmp asm_common
z_asm_sbc_x:
xt_asm_sbc_y: ; sbc.y \ SBC nnnn,Y
lda #$F9
jmp asm_common
z_asm_sbc_y:
xt_asm_sbc_z: ; sbc.z \ SBC nn
lda #$E5
jmp asm_common
z_asm_sbc_z:
xt_asm_sbc_zi: ; sbc.zi \ SBC (nn)
lda #$F2
jmp asm_common
z_asm_sbc_zi:
xt_asm_sbc_ziy: ; sbc.ziy \ SBC (nn),Y
lda #$F1
jmp asm_common
z_asm_sbc_ziy:
xt_asm_sbc_zx: ; sbc.zx \ SBC nn,X
lda #$F5
jmp asm_common
z_asm_sbc_zx:
xt_asm_sbc_zxi: ; sbc.zxi \ SBC (nn,X)
lda #$E1
bra asm_common ; <-- limit for BRA instead of JMP
z_asm_sbc_zxi:
xt_asm_sec: ; sec \ SEC
lda #$38
bra asm_common
z_asm_sec:
xt_asm_sed: ; sed \ SED
lda #$F8
bra asm_common
z_asm_sed:
xt_asm_sei: ; sei \ SEI
lda #$78
bra asm_common
z_asm_sei:
xt_asm_sta: ; sta \ STA nnnn
lda #$8D
bra asm_common
z_asm_sta:
xt_asm_sta_x: ; sta.x \ STA nnnn,X
lda #$9D
bra asm_common
z_asm_sta_x:
xt_asm_sta_y: ; sta.y \ STA nnnn,Y
lda #$99
bra asm_common
z_asm_sta_y:
xt_asm_sta_z: ; sta.z \ STA nn
lda #$85
bra asm_common
z_asm_sta_z:
xt_asm_sta_zi: ; sta.zi \ STA (nn)
lda #$92
bra asm_common
z_asm_sta_zi:
xt_asm_sta_ziy: ; sta.ziy \ STA (nn),Y
lda #$91
bra asm_common
z_asm_sta_ziy:
xt_asm_sta_zx: ; sta.zx \ STA nn,X
lda #$95
bra asm_common
z_asm_sta_zx:
xt_asm_sta_zxi: ; sta.zxi \ STA (nn,X)
lda #$81
bra asm_common
z_asm_sta_zxi:
xt_asm_stx: ; stx \ STX nnnn
lda #$8E
bra asm_common
z_asm_stx:
xt_asm_stx_z: ; stx.z \ STX nn
lda #$86
bra asm_common
z_asm_stx_z:
xt_asm_stx_zy: ; stx.zy \ STX nn,Y
lda #$96
bra asm_common
z_asm_stx_zy:
xt_asm_sty: ; sty \ STY nnnn
lda #$8C
bra asm_common
z_asm_sty:
xt_asm_sty_z: ; sty.z \ STY nn
lda #$84
bra asm_common
z_asm_sty_z:
xt_asm_sty_zx: ; sty.zx \ STY nn,X
lda #$94
bra asm_common
z_asm_sty_zx:
xt_asm_stz: ; stz \ STZ nnnn
lda #$9C
bra asm_common
z_asm_stz:
xt_asm_stz_x: ; stz.x \ STZ nnnn,X
lda #$9E
bra asm_common
z_asm_stz_x:
xt_asm_stz_z: ; stz.z \ STZ nn
lda #$64
bra asm_common
z_asm_stz_z:
xt_asm_stz_zx: ; stz.zx \ STZ nn,X
lda #$74
bra asm_common
z_asm_stz_zx:
xt_asm_tax: ; tax \ TAX
lda #$AA
bra asm_common
z_asm_tax:
xt_asm_tay: ; tay \ TAY
lda #$A8
bra asm_common
z_asm_tay:
xt_asm_trb: ; trb \ TRB nnnn
lda #$1C
bra asm_common
z_asm_trb:
xt_asm_trb_z: ; trb.z \ TRB nn
lda #$14
bra asm_common
z_asm_trb_z:
xt_asm_tsb: ; tsb \ TSB nnnn
lda #$0C
bra asm_common
z_asm_tsb:
xt_asm_tsb_z: ; tsb.z \ TSB nn
lda #$04
bra asm_common
z_asm_tsb_z:
xt_asm_tsx: ; tsx \ TSX
lda #$BA
bra asm_common
z_asm_tsx:
xt_asm_txa: ; txa \ TXA
lda #$8A
bra asm_common
z_asm_txa:
xt_asm_txs: ; txs \ TXS
lda #$9A
bra asm_common
z_asm_txs:
xt_asm_tya: ; tya \ TYA
lda #$98
bra asm_common
z_asm_tya:
; ==========================================================
; ASSEMBLER HELPER FUNCTIONS
asm_common:
.scope
; """Common routine for all opcodes. We arrive here with the opcode in
; A. We do not need to check for the correct values because we are
; coming from the assembler Dictionary and trust our external test
; suite.
; """
; Compile opcode. Note cmpl_a does not use Y
tay
jsr cmpl_a
; We get the length of the opcode from the table included in
; the disassembler. We use the opcode value as the offset in
; the oc_index_table. We have 256 entries, each two bytes
; long, so we can't just use an index with Y. We use tmp2 for
; this.
lda #<oc_index_table
sta tmp2
lda #>oc_index_table
sta tmp2+1
tya ; retrieve opcode
asl ; times two for offset
bcc+
inc tmp2+1
*
tay ; use Y as the index
; Get address of the entry in the opcode table. We put it in
; tmp3 and push a copy of it to the stack to be able to print
; the opcode later
lda (tmp2),y ; LSB
sta tmp3
iny
lda (tmp2),y ; MSB
sta tmp3+1
lda (tmp3) ; get "lengths byte"
; The length of the instruction is stored in bits 7 and 6.
; Rotate them through the carry flag and mask the rest
rol
rol
rol ; Three times because we go through Carry
and #%00000011
tay
; One byte means no operand, we're done. Use DEY as CPY #1
dey
beq _done
; We have an operand which must be TOS
jsr underflow_1
; We compile the LSB of TOS as the operand we definitely have
; before we even test if this is a two- or three-byte
; instruction. Little endian CPU means we store this byte first
lda 0,x
jsr cmpl_a ; does not use Y
; If this is a two-byte instruction, we're done. If we landed
; here, we've already decremented Y by one, so this is
; the equivalent to CPY #2