-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTeamVisualBasic_OP_Decoder.X68
More file actions
922 lines (707 loc) · 36 KB
/
TeamVisualBasic_OP_Decoder.X68
File metadata and controls
922 lines (707 loc) · 36 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
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
*-----------------------------------------------------------
* Title : Team Visual Basic's Disassembler
* Written by : Henry Hong, Dylan Desmond, Austin Abeyta
* Date : 3/4/2018
* Description: CSS422 Final Project
* Machine code to Motorola 68000 Assembly
* OP Decoder File
* Using different opcode type, deconstructs the op code
* prints the register or addr
*-----------------------------------------------------------
*-----------------------------------------------------------
*-Starting Point: Branch into one of many OPCODE Types
*-Size bits are not handled here, that is handled in the jump table
*-
*-Bit Format:
*-15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
*-Most Significant Least Significant
*-----------------------------------------------------------
*-OPCODE Decode Type A--------------------------------------
*-OPCODEs: MOVE,MOVEA,
*-xxxx Dest Reg(3) Dest Mode(3) Src Mode(3) Src Reg(3)
DECODE_A MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2 *Copy OPCODE into D2
JSR GRABx5_3 *Grab source mode
MOVE.W D5,D2 *put source mode in D2
JSR GET_SRCMODE *Append SRC string to (A4)
MOVE.B #',',(A4)+
MOVE.W (A5),D2 *Recopy OPCODE into D2
JSR GRABx8_6 *grab dest mode bits
MOVE.W D5,D2 *Move dest mode into D2
JSR GET_DSTMODE *Append DST string to (A4)
RTS *Return back to jump table
*-OPCODE Decode Type B--------------------------------------
*-OPCODEs: LSL/LSR,ASL/ASR,ROL/ROR
*-xxxx Register(3) OP Mode(3) EA Mode(3) EA Reg(3)
DECODE_B MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2 *reload op code
JSR GRABx7_6 *grab SIZE bits and put them in D2
CMP.W #3,D2
BEQ B_ADDMODE *this shift is an address variant
MOVE.W (A5),D5 *otherwise this shift is a register variant
LSR.W #5,D5 *logical shift left to get i/r
AND.W #$0001,D5
CMP.W #0,D5 *if i/r bit is 0, bits are COUNT
BEQ B_SCOUNT
CMP.W #1,D5 *if i/r bit is 1, bits are REGISTER
BEQ B_DATAREG
RTS
*-OPCODE Decode Type C--------------------------------------
*-OPCODEs: ADDI, SUBI, NEG, ORI, CMPI,
*-xxxxxxxx Size2, Ea mode(3) Ea Reg(3)
*STILL NEED TO PRINT DATA THAT FOLLOWS FIRST
DECODE_C MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
JSR IMMEDIATE_D *Append immediate data to string
MOVE.B #',',(A4)+
MOVE.W (A5),D2
ASR.L #3,D2
ANDI.L #$00000007,D2
JSR GET_SRCMODE *Append ,D(reg num) to string
RTS
*-OPCODE Decode Type D--------------------------------------
*-OPCODEs: EOR, CMP, BCLR (immediate and register)
*-xxxx Register(3) x Size(2) EA Mode(3) EA Reg(3)
DECODE_D MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2
JSR GRABX5_3
MOVE.W D5,D2
JSR GET_SRCMODE
MOVE.B #',',(A4)+
MOVE.B #'D',(A4)+
MOVE.W (A5),D2
JSR GRABx11_9
JSR PrintD5Num
MOVE.W (A5),D2
RTS
*-OPCODE Decode Type E--------------------------------------
*-OPCODEs: BCC (BCC, BLT, BGE, BCS, BVC), BRA
*-xxxx Condition(4) 8 Bit Displacement
DECODE_E MOVE.B #9,(A4)+ *tab after op code
MOVE.B #9,(A4)+ *2tabs since bra is short
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2
*--What source mode bits is it grabbing and why? Condition is only for figuring out
*what type of branch it is (BCS, BLT, BGE, etc.). Only thing that matters in DECODE_E
*is the 8 bit displacement because that is where the branch is suppose to be connected to
LSR.W #8,D2 *GRAB condition bits
AND.W #$000F,D2 *Mask out other bits
CMP.W #0,D2 *CHECK IF BRA
JSR D_BRA *Go to decode BRA sub routine
RTS
D_BRA MOVE.W (A5),D2 *Load op and store in D2
AND.W #$00FF,D2 *Get displacement bits by masking
CMP.W #$00,D2
BGT BRA_BYTE_
MOVE.W (A5),D2 *Load op and store in D2
AND.W #$00FF,D2 *Get displacement bits by masking
CMP.W #$0000,D2
BEQ BRA_WORD
*branch word displacement sub
MOVE.W (A5),D2 *Load op and store in D2
AND.W #$00FF,D2 *Get displacement bits by masking
CMP.W #$00FF,D2
BEQ BRA_LONG *branch long displacement
RTS
BRA_WORD JSR WORD_DATA
RTS
BRA_LONG JSR LONG_DATA
RTS
BRA_BYTE_ CMP.W #$FF,D2
BLT BRA_BYTE
RTS
BRA_BYTE MOVE.W (A5),D0
AND.W #$00FF,D0
ROR.L #8,D0
MOVE.W #2,D2
;ADDI.B #2,D6
MOVE.B #'$',(A4)+
JSR GD_LOOP
RTS
*-----------displacement sub routines---------------------
*-OPCODE Decode Type F--------------------------------------
*-OPCODEs: ADD, MULS, OR, DIVS, SUB, AND, DIVU
*-xxxx Reg(3) OPMode(3) EAMode(3) EAReg(3)
DECODE_F MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.B #9,(A4)+ *tab after op cod
MOVE.W (A5),D2 *Copy opcode into d2
LSR.W #6,D2 *Shift to grab op mode
AND.W #$0007,D2 *Mask other bits
JSR F_OPMODE
MOVE.B #',',(A4)+ *Move comma into string
MOVE.B #'D',(A4)+
MOVE.W (A5),D2 *Recopy OPCODE into D2
JSR GRABx11_9 *grab dest reg
JSR PrintD5Num *pritn register number
RTS
* MOVE.W #2,D6 *Initilize opcode length to 2
* MOVE.W (A5),D2 *Copy opcode into d2
* LSR.W #6,D2 *Shift to grab op mode
* AND.W #$0007,D2 *Mask other bits
* JSR F_OPMODE
* MOVE.W (A5),D2 *Recopy OPCODE into D2
* LSR.W #6,D2 *Shift right 6 - isolate Dest Mode
* AND.W #$0007,D2 *Mask out other bits
* JSR GET_DSTMODE *Append DST string to (A4)
*-----------------------------------------------------------
*-OPTYPE_F HELPER FUNCTIONS
*Helps determine the OPTYPE
*-----------------------------------------------------------
F_OPMODE CMP.W #7,D2 *Check if opcode type falls into the opmode 11 ,divs,mul
BEQ F_111_MODE *Branch to handle 111 Modes
CMP.W #7,D2
BLT F_OPMODE2
RTS
F_OPMODE2 MOVE.W (A5),D2 *Reload opcode into D2
LSR.W #8,D2
AND.W #$0001,D2 *Shift to get opmode bits into the final 3 LSB
CMP.W #1,D2
BEQ F_DN_EA *Branch to handle when op codes are Dn+<ea> -- Dn
CMP.W #0,D2
BEQ F_EA_DN *Branch to handle when op code are Dn + <ea - <Ea>
RTS
F_DN_EA MOVE.W (A5),D2 *Reload opcode into D2
JSR GRABX8_6 *GRAB BITS 8_5 plce into D5
AND #$0003,D5
CMP.W #0,D5
BEQ BYTE_DATA
CMP.W #1,D5
BEQ WORD_DATA
CMP.W #2,D5
BEQ LONG_DATA
*---------------PRINT DESTINATION REG---------------
MOVE.B #'D',(A4)+ *Must be a data register for dest
MOVE.W (A5),D2 *Re load op code
JSR GRABx11_9 *grab register bits and store in d5
JSR PrintD5Num
RTS
F_EA_DN ;MOVE.B #'D',(A4)+ *Must be a data register for dest
MOVE.W (A5),D2 *Re load op code
JSR GRABx5_3 *grab register bits and store in d5
MOVE.B D5,D2
JSR GET_SRCMODE
RTS
*------------------------------------------------------------
*Handles when op mode bits are 111
F_111_MODE MOVE.W (A5),D2
JSR GRABx5_3
MOVE.W D5,D2
JSR GET_SRCMODE
RTS
*-----------------------------------------------------------
*-OPTYPE_B HELPER FUNCTIONS
*Helps determine the size of shifts or registers
*-----------------------------------------------------------
*-------------------------------------------------------
*Shift on address is occuring
*print address by using EA Mode and EA Reg bits at end of op
*DECODE TYPE SPECIFIC FUNCTION
B_ADDMODE
MOVE.W (A5),D2
LSR.W #3,D2
AND.W #$0007,D2
JSR GET_DSTMODE
MOVE.W (A5),D2
AND.W #$0007,D2
MOVE.W D2,D5
JSR PrintD5Num
RTS GET_SRC_MODE
*-----------------------------------------------------------
*Value stored in cont/reg is a number of bits to shift
*Display as #number
*DECODE TYPE SPECIFIC FUNCTION
B_SCOUNT MOVE.W (A5),D2
LSR.L #6,D2
LSR.L #3,D2
AND.W #$0007,D2
MOVE.W D2,D5
MOVE.B #'#',(A4)+
JSR PrintD5Num
JSR B_SRC_DMODE
RTS
*------------------------------------------------------------
*Display proper register number found at the 12 - 9 bits
*DECODE TYPE SPECIFIC FUNCTION
B_DATAREG MOVE.B #'D',(A4)+
MOVE.W (A5),D2
LSR.W #6,D2
LSR.W #3,D2
AND.W #$0007,D2
MOVE.W D2,D5
JSR PrintD5Num
JSR B_SRC_DMODE
RTS
*---------------------------------------------------------
*display the register number that's in bits 2-1-0
*DECODE TYPE SPECIFIC(?) FUNCTION
B_SRC_DMODE MOVE.W (A5),D2 *reload op
MOVE.B #',',(A4)+ *add comma to printer
MOVE.B #'D',(A4)+ *D for data register
AND.W #0007,D2 *mask out other bits
MOVE.W D2,D5 *move register number to d5
JSR Printd5Num *print register numebr
RTS
*-OPS WITHOUT TYPE------------------------------------------
*-OPCODES: MOVEQ
D_EOR MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.B #'D',(A4)+
MOVE.W (A5),D2
JSR GRABx11_9
JSR PrintD5Num
MOVE.B #',',(A4)+
MOVE.W (A5),D2
JSR GRABX5_3
MOVE.W D5,D2
JSR GET_SRCMODE
RTS
D_BCLR MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.B #'D',(A4)+
MOVE.W (A5),D2
JSR GRABx11_9
JSR PrintD5Num
MOVE.B #',',(A4)+
MOVE.W (A5),D2
JSR GRABX5_3
CMP.L #7,D5
BEQ BCLR_SIZE
MOVE.W D5,D2
JSR GET_DSTMODE
RTS
BCLR_SIZE MOVE.W (A5),D2
JSR GRABx2_0
CMP.W #1,D5
BEQ LONG_DATA
MOVE.W (A5),D2
JSR GRABx2_0
CMP.W #0,D5
BEQ WORD_DATA
RTS
D_BCLRI MOVE.B #9,(A4)+ *tab after op code
MOVE.W #4,D6 *Initilize opcode length to 2
MOVE.W (A5),D2
MOVE.L A5,A3
ADDA.L #2,A3
MOVE.B #'#',(A4)+
MOVE.L (A3),D0
ROR.L #8,D0
MOVE.L #2,D2
JSR GD_LOOP
MOVE.B #',',(A4)+
JSR GRABx5_3
MOVE.L D5,D2
JSR GET_DSTMODE
RTS
RTS
D_MOVEQ MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D0 *grab op code from a5
MOVE.B #09,(A4)+ *Insert tab character
MOVE.B #'#',(A4)+ *preload source string for literal
MOVE.B #'$',(A4)+ *preload source string for hex
JSR P_MOVEQ_B
MOVE.B #',',(A4)+
MOVE.B #'D',(A4)+
JSR GRABx11_9
JSR PrintD5Num
RTS
P_MOVEQ_B MOVE.W (A5),D0
AND.W #$00FF,D0
ROR.L #8,D0
MOVE.W #2,D2
JSR GD_LOOP
RTS
D_ADDQ MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D0 *grab op code from a5
MOVE.B #'#',(A4)+ *preload source string for literal
MOVE.B #'$',(A4)+ *preload source string for hex
MOVE.W #1,D2 *move counter to 1 since only 1 bit is used
LSL.W #2,D2 *set up data for printer
ADD.W #$C000,D2 *mask out first bits
JSR GD_LOOP *print hex the 2 bits
MOVE.W (A5),D2 *reload op code from a5
LSL.W #3,D2 *shift so source mode is in LSBs
AND.W #$0007,D2 *mask out other bits
JSR GET_SRCMODE *print source mode
RTS
D_NEG MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2 *reload op code from a5
LSR.L #3,D2 *isolate EA mode
ANDI.L #$00000007,D2
CMP.B #0,D2 *if == 0, Dn
BEQ SregMode
CMP.B #2,D2 *if == 2, (An)
BEQ SaddINMode
CMP.B #3,D2 *if == 3, (An)+
BEQ SaddINpost
CMP.B #4,D2 *if == 4, -(An)
BEQ SaddINpre
CMP.B #7,D2 *if == 7, -(An)
BEQ NEG_PRINT
BRA RTS_BACK
NEG_PRINT MOVE.W (A5),D2 *reload op code from a5
ANDI.L #$00000007,D2 *isolate register bits
CMP.B #0,D2 *If == 0, its (xxx).W
BEQ WORD_DATA
CMP.B #1,D2 *If == 1, its (xxx).W
BEQ LONG_DATA
RTS
D_ADDA MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2 *reload opcode in D2
JSR GRABx5_3 *grab bits index 5_3
MOVE.W D5,D2 *Move bits grabbed into D2
JSR GET_SRCMODE *get destination mode
MOVE.W (A5),D2 *reload opcode into D5
MOVE.B #',',(A4)+ *load comma into string
MOVE.B #'A',(A4)+ *print a for address
JSR GRABx11_9 *grab bits
JSR PrintD5Num *print d5 number
RTS
D_LEA MOVE.B #9,(A4)+ *tab after op code
MOVE.B #9,(A4)+ *2nd tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2 *reload opcode in D2
JSR GRABx2_0
CMP.W #$0001,D5
BEQ LONG_DATA
CMP.W #$0000,D5
BEQ WORD_DATA
MOVE.W (A5),D2 *reload opcode into D5
MOVE.B #',',(A4)+ *load comma into string
MOVE.B #'A',(A4)+ *print a for address
JSR GRABx11_9 *grab bits
JSR PrintD5Num *print d5 number
RTS
D_JSR MOVE.B #9,(A4)+ *tab after op code
MOVE.B #9,(A4)+ *2nd tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D2 *reload opcode in D2
JSR GRABx2_0
CMP.W #$0001,D5
BEQ LONG_DATA
CMP.W #$0000,D5
BEQ WORD_DATA
D_SUBQ MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
MOVE.W (A5),D0 *grab op code from a5
MOVE.B #'#',(A4)+ *preload source string for literal
MOVE.B #'$',(A4)+ *preload source string for hex
JSR GRABx11_9 *grab bits at index 11_9
CMP.B #0,D5
BEQ D_SUBQ_1
BRA D_SUBQ_2
D_SUBQ_1 MOVE.B #8,D5
D_SUBQ_2 JSR PrintD5num *Print number in D5
MOVE.B #',',(A4)+ *Print comma
MOVE.W (A5),D2 *reload op code from a5
LSR.W #3,D2 *shift so source mode is in LSBs
AND.W #$0007,D2 *mask out other bits
JSR GET_SRCMODE *print source mode
RTS
D_MOVEM MOVE.B #9,(A4)+ *tab after op code
MOVE.W #2,D6 *Initilize opcode length to 2
;JSR MM_FLAG *If -(An), set D4 to 1. Otherwise[(An), (An)+}], set D4 to 0
;MOVE.W (A5),D2 *reload op code from a5
;ROL.L #6,D2 *get dr bit on the LSB position
;ANDI.L #$00000001,D2 *isolate dr bit
;CMP.B #0,D2 *if bit is 0
;BEQ MM_R2M *branch to register to memory
;BRA MM_M2R *otherwise, branch to memory to register
*Before this line is the MOVEM Implementation Attempt
*--------------------------------------------------------------------
*Immediately after up to MM_LONG is the quick fix for turn-in
MOVE.W (A5),D2 *reload op code from a5
ASR.L #3,D2 *get dr bit on the LSB position
ANDI.L #$00000007,D2 *isolate EA mode bit
CMP.B #7,D2 *is there (xxx).W (xxx).L extra data?
BEQ MM_DATA
RTS
MM_DATA CMP.B #6,D7 *If D7 signifies MOVEM.W, Set D6 to 4
BEQ MM_WORD
BRA MM_LONG
MM_WORD MOVE.L #6,D6
RTS
MM_LONG MOVE.L #8,D6
RTS
*-SRC_MODE--------------------------------------------------
*-Assumption is that the SRC Mode bits are pre-isolated in D2
*DECODE TYPE SPECIFIC FUNCTION
GET_SRCMODE CMP.W #0,D2
BEQ SregMode *register mode: Dn
CMP.W #1,D2
BEQ SaddMode *address mode ---An
CMP.W #2,D2
BEQ SaddINmode *addres indirect mode ---(An)
CMP.W #3,D2
BEQ SaddINpost *addess indirect pre dec --- (An)+
CMP.W #4,D2
BEQ SaddINpre *address indirect post inc --- -(An)
CMP.W #5,D2
BEQ S16An *source number of word size --- (d16,An)
CMP.W #6,D2
BEQ S8AnXn *source number byte size --- (d8,An,Xn)
CMP.W #7,D2
BEQ S_DATA_MODE *immediate data
*-DST_MODE--------------------------------------------------
*-Assumption is that the DST Mode bits are pre-isolated in D2
*DECODE TYPE SPECIFIC FUNCTION
GET_DSTMODE CMP.W #0,D2
BEQ DregMode *register mode ---Dn
CMP.W #1,D2
BEQ DaddMode *address mode ---An
CMP.W #2,D2
BEQ DaddINmode *addres indirect mode ---(An)
CMP.W #3,D2
BEQ DaddINpost *addess indirect post inc --- (An)+
CMP.W #4,D2
BEQ DaddINpre *address indirect post inc --- -(An)
CMP.W #5,D2
BEQ D16An *source number of word size --- (d16,An)
CMP.W #6,D2
BEQ D8AnXn *source number byte size --- (d8,An,Xn)
CMP.W #7,D2
BEQ D_DATA_MODE *Source is immediate data following the opcode
*-EA_MODE----------------------------------------------------
*-Assumption is that the EA Mode bits are pre-isolated in D2
GET_EAMODE
*-----------------------------------------------------------
*-Source Helper Functions
*-Adds Source Register numbers to (A4) string
*-----------------------------------------------------------
SregMode MOVE.B #'D',(A4)+
JSR GRABx2_0
JSR PrintD5Num
RTS
SaddMode MOVE.B #'A',(A4)+
JSR GRABx2_0
JSR PrintD5Num
RTS
SaddInMode MOVE.B #'(',(A4)+
MOVE.B #'A',(A4)+
JSR GRABx2_0 *put reg num into D5
JSR A7toSP *if reg num is 7, replace w/ SP
MOVE.B #')',(A4)+
RTS
SaddINpre MOVE.B #'-',(A4)+
MOVE.B #'(',(A4)+
MOVE.B #'A',(A4)+
JSR GRABx2_0 *put reg num into D5
JSR A7toSP *if reg num is 7, replace w/ SP
MOVE.B #')',(A4)+
RTS
SaddINpost MOVE.B #'(',(A4)+
MOVE.B #'A',(A4)+
JSR GRABx2_0 *put reg num into D5
JSR A7toSP *if reg num is 7, replace w/ SP
MOVE.B #')',(A4)+
MOVE.B #'+',(A4)+
RTS
S16An RTS
*BRA DATA
S8AnXn RTS
*BRA DATA
S_DATA_MODE JSR GRABx2_0 *get least sig 3 bits
CMPI.W #1,D5
BEQ LONG_DATA
CMP.W #0,D5
BEQ D_SIZE
CMP.W #4,D5 *This branch is invalid in the case of DECODE_C. Probably okay tho
BEQ IMMEDIATE_D
*-----------------------------------------------------------
*-Destination Helper Functions
*-Adds Destination Register numbers to (A4) string
*-----------------------------------------------------------
DregMode MOVE.B #'D',(A4)+
JSR GRABx11_9
JSR PrintD5Num
RTS
DaddMode MOVE.B #'A',(A4)+
JSR GRABx11_9
JSR PrintD5Num
RTS
DaddInMode MOVE.B #'(',(A4)+
MOVE.B #'A',(A4)+
JSR GRABx11_9 *put reg num into D5
JSR A7toSP *if reg num is 7, replace w/ SP
MOVE.B #')',(A4)+
RTS
DaddINpre MOVE.B #'-',(A4)+
MOVE.B #'(',(A4)+
MOVE.B #'A',(A4)+
JSR GRABx11_9 *put reg num into D5
JSR A7toSP *if reg num is 7, replace w/ SP
MOVE.B #')',(A4)+
RTS
DaddINpost MOVE.B #'(',(A4)+
MOVE.B #'A',(A4)+
JSR GRABx11_9 *put reg num into D5
JSR A7toSP *if reg num is 7, replace w/ SP
MOVE.B #')',(A4)+
MOVE.B #'+',(A4)+
RTS
D16An BRA DATA
D8AnXn BRA DATA
D_DATA_MODE JSR GRABx11_9
CMPI.W #1,D5
BEQ LONG_DATA
CMPI.W #0,D5
BEQ D_SIZE *Determine if we gotta branch to WORD_DATA or BYTE_DATA off of D7
D_SIZE CMP.B #6,D7
BEQ WORD_DATA
CMP.B #4,D7
BEQ BYTE_DATA
*-----------------------------------------------------------
*-Assorted(?) Helper Functions
*-add Description here
*-----------------------------------------------------------
*---------------IMMEDIATE_DATA-------------------------
*Reached when an opcode has immediate data afterwards
*The length of this immedite data depends on the opcode length
*That value is stored in the d7 register by the jump table
*DECODE TYPE AGNOSTIC FUNCTION
IMMEDIATE_D MOVE.B #'#',(A4)+ *add the # to data string to immediate data
BRA PRINT_DATA
*----------------------------------------------------------
*Grab bits found at indes 2 to 0 and stores values into D5
GRABx2_0 MOVE.W (A5),D2 *recopy op code
ANDI.W #$0007,D2 *mask other bits
MOVE.W D2,D5 *copy D2 to D5
RTS
*----------------------------------------------------------
*Grab bits found at indes 5 to 3 and stores values into D5
GRABx5_3 MOVE.W (A5),D2 *recopy op code
LSR.W #3,D2 *shift so 5 to 3 bits are the LSB
AND.W #$0007,D2 *mask other bits
MOVE.W D2,D5 *copy D2 to D5
RTS
*----------------------------------------------------------
*Grab bits found at indes 8 to 6 and stores values into D5
GRABx8_6 MOVE.W (A5),D2 *recopy op code
LSR.W #3,D2 *shift so 8 to 6 bits are the LSB
LSR.W #3,D2 *shift so 8 to 6 bits are the LSB
AND.W #$0007,D2 *mask other bits
MOVE.W D2,D5 *copy D2 to D5
RTS
*----------------------------------------------------------
*Grab bits found at indes 7 to 6 and stores values into D5
GRABx7_6 MOVE.W (A5),D2 *recopy op code
LSR.W #3,D2 *shift so 8 to 6 bits are the LSB
LSR.W #3,D2 *shift so 8 to 6 bits are the LSB
AND.W #$0003,D2 *mask other bits
MOVE.W D2,D5 *copy D2 to D5
RTS
*----------------------------------------------------------------
*Grab bits found at index 11 throu 9 and stores values into D5
GRABx11_9 MOVE.W (A5),D2 *type one grab register bits
LSR.W #6,D2 *shift bits over
LSR.W #3,D2
AND.W #$0007,D2 *mask so only relevent bits left
MOVE.W D2,D5 *move to d5 for printing
RTS
*-A7 to SP special case-------------------------------------
*DECODE TYPE AGNOSTIC FUNCTION
A7toSP CMP.B #7,D5 *If Address register (num stored in D5) is A7
BEQ A7toSP_repl *then branch to subroutine that replaces A7 string with SP
BRA A7toSP_nA7 *else, branch normally and print A0-A6
A7toSP_nA7 JSR PrintD5Num
RTS
A7toSP_repl SUBA #1,A4 *move the A4 string back by a digit
MOVE.B #'S',(A4)+ *replace string with SP
MOVE.B #'P',(A4)+
RTS
*-Size helper------------------------------------------------
*DECODE TYPE AGNOSTIC FUNCTION
PRINT_DATA CMP.B #2,D7 *If there is no additional data, go back
BEQ RTS_BACK
CMP.B #4,D7
BEQ BYTE_DATA
CMP.B #6,D7
BEQ WORD_DATA
CMP.B #10,D7
BEQ LONG_DATA
BRA DATA *Base case: catastrophic failure
BYTE_DATA MOVE.B #'$',(A4)+ *prepare the string for a long hex value
MOVE.L A5,A3
ADD.L D6,A3 *Add opcode data length to incement past opcode and data
MOVE.L (A3),D0 *Add correct data into d0 register for printing
MOVE.W #2,D2 *move 2 to counter since this is byte data 2 hex values are required
LSL.L #8,D0 *shift data over 4 bits so beginning of byte is in the highest order
JSR GD_LOOP
ADD.W #2,D6 *since it is byte data increment the address by 4 bits *d6 is opcode length counter
RTS
WORD_DATA MOVE.B #'$',(A4)+ *prepare the string for a long hex value
MOVE.L A5,A3
ADD.L D6,A3 *Add opcode data length to incement past opcode and data
MOVE.L (A3),D0 *Add correct data into d0 register for printing
MOVE.W #4,D2 *move 4 to counter since this it word data 4 hex values are required
JSR GD_LOOP
ADD.W #2,D6 *since it is word data increment the address by 4 bits *d6 is opcode length counter
RTS
LONG_DATA MOVE.B #'$',(A4)+ *prepare the string for a long hex value
MOVE.L A5,A3
ADD.L D6,A3 *Add opcode data length this increments the address past the op code and existing data
MOVE.L (A3),D0
MOVE.W #8,D2 *move 8 to counter since this si long data 8 hex values are required
JSR GD_LOOP
ADD.W #4,D6 *since it is long data increment the address by 4 bits *d6 is opcode length counter
RTS
RTS_BACK RTS *GO BACK
*----------------------------------------------------------
*DECODE TYPE AGNOSTIC FUNCTION
PrintD5Num CMP.B #0,D5 *print the numeber in d5
BEQ PRINT0
CMP.B #1,D5
BEQ PRINT1
CMP.B #2,D5
BEQ PRINT2
CMP.B #3,D5
BEQ PRINT3
CMP.B #4,D5
BEQ PRINT4
CMP.B #5,D5
BEQ PRINT5
CMP.B #6,D5
BEQ PRINT6
CMP.B #7,D5
BEQ PRINT7
CMP.B #8,D5
BEQ PRINT8
*Used to print data to a hex value from bits
*----Requires a preload---------------------------------------------------------------
*D0 = must be loaded with bits to be printed, starts from highest order bit
*D2 = how many bits it will convert to hex starting with the highest order bit in d0
*Therefore bits wanting to be printed should be shifter or rotated to the highest order in d0
*HEX_2_ASCII exists in the Print builder file
*------------------------------------------------------------------------------------------
GD_LOOP JSR HEX_2_ASCII
SUBI #1,D2
CMP.B #0,D2
BGT GD_LOOP
RTS
PRINT0 MOVE.B #'0',(A4)+
RTS
PRINT1 MOVE.B #'1',(A4)+
RTS
PRINT2 MOVE.B #'2',(A4)+
RTS
PRINT3 MOVE.B #'3',(A4)+
RTS
PRINT4 MOVE.B #'4',(A4)+
RTS
PRINT5 MOVE.B #'5',(A4)+
RTS
PRINT6 MOVE.B #'6',(A4)+
RTS
PRINT7 MOVE.B #'7',(A4)+
RTS
PRINT8 MOVE.B #'8',(A4)+
RTS
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~4~