-
Notifications
You must be signed in to change notification settings - Fork 0
/
Disassembler.X68
782 lines (559 loc) · 14 KB
/
Disassembler.X68
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
*------------------------------------------------------------------------------
* Title : Disassembler
* Description: Handles the iteration through memory, the user input, the
* display of memory locations, and invalid opcodes.
*------------------------------------------------------------------------------
INCLUDE demo_test.X68
INCLUDE TestCode.X68
INCLUDE MOVEM.X68
INCLUDE LogicalShift.X68
INCLUDE Bcc_BRA.X68
INCLUDE MOVEQ.X68
INCLUDE MISC_CODE.X68
INCLUDE DIVU_OR.X68
INCLUDE MOVE_MOVEA.X68
INCLUDE ADD_ADDA.X68
INCLUDE SUB.X68
INCLUDE ADDQ.X68
INCLUDE MULS_AND.X68
START ORG $1000
LEA INTRO1,A1
MOVE.B #14,D0
TRAP #15
LEA INTRO2,A1
MOVE.B #14,D0
TRAP #15
LEA INTRO1,A1
MOVE.B #14,D0
TRAP #15
LEA INTRO3,A1
MOVE.B #14,D0
TRAP #15
LEA INTRO4,A1
MOVE.B #14,D0
TRAP #15
MOVE.L #0,D7
MOVE.L #0,D1
MOVE.L #0,D2
MOVE.L #0,A4
MOVE.L #9,A3
LEA RESET_TEXT,A1
MOVE.B #14,D0
TRAP #15
LEA EXIT_TEXT,A1
MOVE.B #14,D0
TRAP #15
LEA INPUT1_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BRA GET_INPUT1
MOVE.L #$60B0,A3
BRA COMPARE
GET_INPUT1
ADDQ.L #1,A4
CMP.L A4,A3
BEQ LOAD_INPUT1
MOVE.B #5,D0
TRAP #15
BSR GET_NUMBER
BRA GET_INPUT1
LOAD_INPUT1
MOVE.L D2,A2
MOVE.L #$0,A4
LEA INPUT2_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BRA GET_INPUT2
GET_INPUT2
ADDQ.L #1,A4
CMP.L A4,A3
BEQ LOAD_INPUT2
MOVE.B #5,D0
TRAP #15
BSR GET_NUMBER
BRA GET_INPUT2
LOAD_INPUT2
MOVE.L D2,A3
MOVE.L #$0000FF00,D1
MOVE.B #11,D0
TRAP #15
LEA NEWLINE,A1
MOVE.B #14,D0
TRAP #15
BRA PARSE_SIMPLE
;Parses Simple Commands, such as NOP
PARSE_SIMPLE
BSR LOAD_0s_FOR_MEM_LOCATION
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.L A2,D1
TRAP #15
MOVE.B #HT,D1
MOVE.B #6,D0
TRAP #15
MOVE.W (A2),A4
CMP.W #NOP_CODE,A4
BEQ IF_NOP
CMP.W #RTS_CODE,A4
BEQ IF_RTS
BRA PARSE_COMPLEX
; For parsing more complex commands
PARSE_COMPLEX
MOVE.W A4,A5
MOVE.W A4,D3
AND.W #$F000,D3
CMP.W #MOVE_B_CODE,D3
BEQ IF_MOVE_B
CMP.W #MOVE_W_CODE,D3
BEQ IF_MOVE_W
CMP.W #MOVE_L_CODE,D3
BEQ IF_MOVE_L
CMP.W #ADD_CODE,D3
BEQ IF_ADD_ADDA
CMP.W #SUB_CODE,D3
BEQ IF_SUB
CMP.W #ADDQ_CODE,D3
BEQ IF_ADDQ
CMP.W #MULS_AND_CODE,D3
BEQ IF_MULS_AND
CMP.W #DIVU_OR_CODE,D3
BEQ IF_DIVU_OR
CMP.W #MISC_CODE,D3
BEQ IF_MISC
CMP.W #MOVEQ_CODE,D3
BEQ IF_MOVEQ
CMP.W #Bcc_BRA_CODE,D3
BEQ IF_Bcc_BRA
CMP.W #LS_CODE,D3
BEQ IF_LS_CODE
BRA IF_INVALID_OP
IF_NOP
LEA NOP_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
IF_RTS
LEA RTS_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
IF_MOVE_B
MOVE.W #MOVE_B_CODE,D5
BRA PARSE_MOVE
IF_MOVE_W
MOVE.W #MOVE_W_CODE,D5
BRA PARSE_MOVE
IF_MOVE_L
MOVE.W #MOVE_L_CODE,D5
BRA PARSE_MOVE
IF_INVALID_OP
LEA ERROR_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BSR LOAD_0s_FOR_DATA
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.W (A2),D1
TRAP #15
BRA ITERATE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
IF_INVALID_OP_EA
LEA ERROR_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BSR LOAD_0s_FOR_DATA
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.W (A2),D1
TRAP #15
LEA BAD_EA,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
IF_INVALID_OPMODE
MOVE.B #SPACE,D1
MOVE.B #6,D0
TRAP #15
LEA ERROR_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BSR LOAD_0s_FOR_DATA
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.W (A2),D1
TRAP #15
LEA BAD_OPMODE,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
IF_INVALID_SIZE
MOVE.B #SPACE,D1
MOVE.B #6,D0
TRAP #15
LEA ERROR_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BSR LOAD_0s_FOR_DATA
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.W (A2),D1
TRAP #15
LEA BAD_SIZE,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
IF_INVALID_SRC_DEST
MOVE.B #SPACE,D1
MOVE.B #6,D0
TRAP #15
LEA ERROR_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BSR LOAD_0s_FOR_DATA
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.W (A2),D1
TRAP #15
LEA BAD_SRC_DEST,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
IF_INVALID_MASK
MOVE.B #SPACE,D1
MOVE.B #6,D0
TRAP #15
LEA ERROR_OUTPUT,A1
MOVE.B #14,D0
TRAP #15
BSR LOAD_0s_FOR_DATA
MOVE.B #16,D2
MOVE.B #15,D0
MOVE.W (A2),D1
TRAP #15
LEA BAD_MASK,A1
MOVE.B #14,D0
TRAP #15
BRA ITERATE
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ITERATE
ADDQ.L #2,A2
ADDQ.L #1,D7
LEA NEWLINE,A1
MOVE.B #14,D0
TRAP #15
BSR SHOULD_PAUSE_PARSER
BRA COMPARE
COMPARE
CMP.L A2,A3
BLT SHOULD_RUN_AGAIN
BRA PARSE_SIMPLE
DONE
LEA DONE_TEXT,A1
MOVE.B #14,D0
TRAP #15
MOVE.B #9,D0
TRAP #15
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GET_NUMBER
CMP.B #R_LOWER,D1
BEQ RESET
CMP.B #R_UPPER,D1
BEQ RESET
CMP.B #ESC,D1
BEQ DONE
IS_0
SUB.B #$30,D1
LSL.L #4,D2
CMP.B #$0,D1
BEQ ADD_NUM
IS_1
CMP.B #$1,D1
BEQ ADD_NUM
IS_2
CMP.B #$2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Q CONTINUE
CMP.B #R_LOWER,D1
BEQ RESET
CMP.B #R_UPPER,D1
BEQ RESET
CMP.B #ESC,D1
BEQ DONE
BRA SHOULD_CONTINUE
CONTINUE
MOVE.W #$FF00,D1
MOVE.B #11,D0
TRAP #15
LEA NEWLINE,A1
MOVE.B #14,D0
TRAP #15
MOVE.L #0,D7
RTS
RESET
MOVE.L #$0000FF00,D1
MOVE.B #11,D0
TRAP #15
BRA START
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SHOULD_RUN_AGAIN
LEA NEWLINE,A1
MOVE.B #14,D0
TRAP #15
LEA RESET_TEXT,A1
MOVE.B #14,D0
TRAP #15
LEA EXIT_TEXT,A1
MOVE.B #14,D0
TRAP #15
BRA RUN_AGAIN_CHECK
RUN_AGAIN_CHECK
MOVE.B #5,D0
TRAP #15
CMP.B #R_LOWER,D1
BEQ RESET
CMP.B #R_UPPER,D1
BEQ RESET
CMP.B #ESC,D1
BEQ DONE
BRA RUN_AGAIN_CHECK
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LOAD_0s_FOR_DATA
MOVE.W (A2),D5
AND.L #$0000FFFF,D5
MOVE.B #$30,D1
MOVE.B #6,D0
CMP.L #$0000000F,D5
BLE DISPLAY_ZERO_3
CMP.L #$000000FF,D5
BLE DISPLAY_ZERO_2
CMP.L #$00000FFF,D5
BLE DISPLAY_ZERO_1
BRA DISPLAY_NO_ZERO
LOAD_0s_FOR_MEM_LOCATION
MOVE.B #$30,D1
MOVE.B #6,D0
CMP.L #$0000000F,A2
BLE DISPLAY_ZERO_7
CMP.L #$000000FF,A2
BLE DISPLAY_ZERO_6
CMP.L #$00000FFF,A2
BLE DISPLAY_ZERO_5
CMP.L #$0000FFFF,A2
BLE DISPLAY_ZERO_4
CMP.L #$000FFFFF,A2
BLE DISPLAY_ZERO_3
CMP.L #$00FFFFFF,A2
BLE DISPLAY_ZERO_2
CMP.L #$0FFFFFFF,A2
BLE DISPLAY_ZERO_1
BRA DISPLAY_NO_ZERO
DISPLAY_ZERO_7
TRAP #15
DISPLAY_ZERO_6
TRAP #15
DISPLAY_ZERO_5
TRAP #15
DISPLAY_ZERO_4
TRAP #15
DISPLAY_ZERO_3
TRAP #15
DISPLAY_ZERO_2
TRAP #15
DISPLAY_ZERO_1
TRAP #15
DISPLAY_NO_ZERO
RTS
* Put variables and constants here
CR EQU $0D
LF EQU $0A
LEFT_PAR EQU $28
RIGHT_PAR EQU $29
A EQU $41
D EQU $44
PLUS EQU $2B
MINUS EQU $2D
NUM EQU $23
HEX EQU $24
COMMA EQU $2C
SPACE EQU $20
SLASH EQU $2F
HT EQU $09
ESC EQU $1B
C_LOWER EQU $63
C_UPPER EQU $43
R_LOWER EQU $72
R_UPPER EQU $52
ZERO EQU $30
;Codes to be parsed
NOP_CODE EQU $4E71
RTS_CODE EQU $4E75
MOVE_B_CODE EQU $1000 ; MOVE.B, MOVEA.B (done)
MOVE_W_CODE EQU $3000 ; MOVE.W, MOVEA.W (done)
MOVE_L_CODE EQU $2000 ; MOVE.L, MOVEA.L (done)
MOVEQ_CODE EQU $7000 ; MOVEQ (done)
DIVU_OR_CODE EQU $8000 ; [DIVU], OR (done)
SUB_CODE EQU $9000 ; SUB (done)
MULS_AND_CODE EQU $C000 ; [MULS], AND (done)
ADD_CODE EQU $D000 ; ADD, ADDA (done)
LS_CODE EQU $E000 ; LOGICAL SHIFTS (done)
ADDQ_CODE EQU $5000 ; ADDQ (done)
Bcc_BRA_CODE EQU $6000 ; Bcc (BGT, BLE, BEQ), BRA
MISC_CODE EQU $4000 ; LEA, NOT, JSR, MOVEM (done)
LSR_ADDRESS EQU $E2C0
LSL_ADDRESS EQU $E3C0
ASR_ADDRESS EQU $E0C0
ASL_ADDRESS EQU $E1C0
ROR_ADDRESS EQU $E6C0
ROL_ADDRESS EQU $E7C0
LSR_REGISTER EQU $E008
LSL_REGISTER EQU $E108
ASR_REGISTER EQU $E000
ASL_REGISTER EQU $E100
ROR_REGISTER EQU $E018
ROL_REGISTER EQU $E118
;Sample outputs
NOP_OUTPUT DC.B 'NOP',0
RTS_OUTPUT DC.B 'RTS',0
MOVEA_OUTPUT DC.B 'MOVEA',0
MOVE_OUTPUT DC.B 'MOVE',0
ADDA_OUTPUT DC.B 'ADDA',0
ADD_OUTPUT DC.B 'ADD',0
SUB_OUTPUT DC.B 'SUB',0
ADDQ_OUTPUT DC.B 'ADDQ',0
AND_OUTPUT DC.B 'AND',0
MULS_OUTPUT DC.B 'MULS',0
OR_OUTPUT DC.B 'OR',0
DIVU_OUTPUT DC.B 'DIVU',0
NOT_OUTPUT DC.B 'NOT',0
JSR_OUTPUT DC.B 'JSR ',0
LEA_OUTPUT DC.B 'LEA ',0
MOVEQ_OUTPUT DC.B 'MOVEQ ',0
MOVEM_OUTPUT DC.B 'MOVEM',0
BRA_OUTPUT DC.B 'BRA',0
BGT_OUTPUT DC.B 'BGE',0
BLE_OUTPUT DC.B 'BLE',0
BEQ_OUTPUT DC.B 'BEQ',0
LSR_OUTPUT DC.B 'LSR',0
LSL_OUTPUT DC.B 'LSL',0
ASR_OUTPUT DC.B 'ASR',0
ASL_OUTPUT DC.B 'ASL',0
ROR_OUTPUT DC.B 'ROR',0
ROL_OUTPUT DC.B 'ROL',0
B_OUTPUT DC.B '.B ',0
W_OUTPUT DC.B '.W ',0
L_OUTPUT DC.B '.L ',0
INPUT1_OUTPUT DC.B CR,LF,'Please enter the starting address: ',0
INPUT2_OUTPUT DC.B CR,LF,'Please enter the end address: ',0
CONTINUTE_TEXT DC.B CR,LF,'Press [c] or [enter] to continue disassembler',CR,LF,0
RESET_TEXT DC.B 'Press [r] to reset disassembler',CR,LF,0
EXIT_TEXT DC.B 'Press [esc] to end disassembler',CR,LF,0
DONE_TEXT DC.B CR,LF,'[Disassembler exited]',CR,LF,0
BAD_SIZE DC.B CR,LF,HT,HT,' *Invalid size argument*',0
BAD_EA DC.B CR,LF,HT,HT,' *Invalid effective address argument*',0
BAD_OPMODE DC.B CR,LF,HT,HT,' *Invalid opmode argument*',0
BAD_SRC_DEST DC.B CR,LF,HT,HT,' *Invalid source/destination argument*',0
BAD_MASK DC.B CR,LF,HT,HT,' *Invalid mask*',0
INTRO1 DC.B '**************************************************',CR,LF,0
INTRO2 DC.B '---------- The A-Team 68k Disassembler -----------',CR,LF,0
INTRO3 DC.B CR,LF,'[Please note that backspace is not implemented]',CR,LF,0
INTRO4 DC.B '[To undo your input, please reset the Disassembler]',CR,LF,CR,LF,0
INVALID_OUTPUT DC.B 'Invalid operation!',0
ERROR_OUTPUT DC.B 'DATA ',0
NEWLINE DC.B CR,LF,0
END START ; last line of source
*~Font name~Courier New~
*~Font size~10~
*~Tab type~1~
*~Tab size~4~