-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz80disassembler.cpp
More file actions
949 lines (927 loc) · 34.3 KB
/
Copy pathz80disassembler.cpp
File metadata and controls
949 lines (927 loc) · 34.3 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
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
#include <stdio.h>
#include "z80disassembler.h"
#define CODESIZE 8192L // 8K Programmcode
#define FUTURA_189 1 // Sprungtabellen-Sprünge für Futura Aquariencomputer ROM V1.89
#define DEBUGGER 0 // wenn 1, dann landet man bei berechneten
// Speicher für den Programmcode
//UBYTE Opcodes[CODESIZE];
extern UBYTE Opcodes[65536];
// Flag pro Speicherstelle, ob Opcode, Operand, Daten
// Bit 4 = 1, d.h. hier wird per JR o.ä. hingesprungen.
enum {
Opcode,
Operand,
Data
} DataType;
UBYTE OpcodesFlags[CODESIZE];
// Länge eines Opcodes in Bytes ermitteln
UBYTE OpcodeLen(ULONG p)
{
UBYTE len = 1;
switch(Opcodes[p]) {// Opcode
case 0x06: // LD B,n
case 0x0E: // LD C,n
case 0x10: // DJNZ e
case 0x16: // LD D,n
case 0x18: // JR e
case 0x1E: // LD E,n
case 0x20: // JR NZ,e
case 0x26: // LD H,n
case 0x28: // JR Z,e
case 0x2E: // LD L,n
case 0x30: // JR NC,e
case 0x36: // LD (HL),n
case 0x38: // JR C,e
case 0x3E: // LD A,n
case 0xC6: // ADD A,n
case 0xCE: // ADC A,n
case 0xD3: // OUT (n),A
case 0xD6: // SUB n
case 0xDB: // IN A,(n)
case 0xDE: // SBC A,n
case 0xE6: // AND n
case 0xEE: // XOR n
case 0xF6: // OR n
case 0xFE: // CP n
case 0xCB: // Shift-,Rotate-,Bit-Befehle
len = 2;
break;
case 0x01: // LD BC,nn'
case 0x11: // LD DE,nn'
case 0x21: // LD HL,nn'
case 0x22: // LD (nn'),HL
case 0x2A: // LD HL,(nn')
case 0x31: // LD SP,(nn')
case 0x32: // LD (nn'),A
case 0x3A: // LD A,(nn')
case 0xC2: // JP NZ,nn'
case 0xC3: // JP nn'
case 0xC4: // CALL NZ,nn'
case 0xCA: // JP Z,nn'
case 0xCC: // CALL Z,nn'
case 0xCD: // CALL nn'
case 0xD2: // JP NC,nn'
case 0xD4: // CALL NC,nn'
case 0xDA: // JP C,nn'
case 0xDC: // CALL C,nn'
case 0xE2: // JP PO,nn'
case 0xE4: // CALL PO,nn'
case 0xEA: // JP PE,nn'
case 0xEC: // CALL PE,nn'
case 0xF2: // JP P,nn'
case 0xF4: // CALL P,nn'
case 0xFA: // JP M,nn'
case 0xFC: // CALL M,nn'
len = 3;
break;
case 0xDD: len = 2;
switch(Opcodes[p+1]) {// 2.Teil des Opcodes
case 0x34: // INC (IX+d)
case 0x35: // DEC (IX+d)
case 0x46: // LD B,(IX+d)
case 0x4E: // LD C,(IX+d)
case 0x56: // LD D,(IX+d)
case 0x5E: // LD E,(IX+d)
case 0x66: // LD H,(IX+d)
case 0x6E: // LD L,(IX+d)
case 0x70: // LD (IX+d),B
case 0x71: // LD (IX+d),C
case 0x72: // LD (IX+d),D
case 0x73: // LD (IX+d),E
case 0x74: // LD (IX+d),H
case 0x75: // LD (IX+d),L
case 0x77: // LD (IX+d),A
case 0x7E: // LD A,(IX+d)
case 0x86: // ADD A,(IX+d)
case 0x8E: // ADC A,(IX+d)
case 0x96: // SUB A,(IX+d)
case 0x9E: // SBC A,(IX+d)
case 0xA6: // AND (IX+d)
case 0xAE: // XOR (IX+d)
case 0xB6: // OR (IX+d)
case 0xBE: // CP (IX+d)
len = 3;
break;
case 0x21: // LD IX,nn'
case 0x22: // LD (nn'),IX
case 0x2A: // LD IX,(nn')
case 0x36: // LD (IX+d),n
case 0xCB: // Rotation (IX+d)
len = 4;
break;
}
break;
case 0xED: len = 2;
switch(Opcodes[p+1]) {// 2.Teil des Opcodes
case 0x43: // LD (nn'),BC
case 0x4B: // LD BC,(nn')
case 0x53: // LD (nn'),DE
case 0x5B: // LD DE,(nn')
case 0x73: // LD (nn'),SP
case 0x7B: // LD SP,(nn')
len = 4;
break;
}
break;
case 0xFD: len = 2;
switch(Opcodes[p+1]) {// 2.Teil des Opcodes
case 0x34: // INC (IY+d)
case 0x35: // DEC (IY+d)
case 0x46: // LD B,(IY+d)
case 0x4E: // LD C,(IY+d)
case 0x56: // LD D,(IY+d)
case 0x5E: // LD E,(IY+d)
case 0x66: // LD H,(IY+d)
case 0x6E: // LD L,(IY+d)
case 0x70: // LD (IY+d),B
case 0x71: // LD (IY+d),C
case 0x72: // LD (IY+d),D
case 0x73: // LD (IY+d),E
case 0x74: // LD (IY+d),H
case 0x75: // LD (IY+d),L
case 0x77: // LD (IY+d),A
case 0x7E: // LD A,(IY+d)
case 0x86: // ADD A,(IY+d)
case 0x8E: // ADC A,(IY+d)
case 0x96: // SUB A,(IY+d)
case 0x9E: // SBC A,(IY+d)
case 0xA6: // AND (IY+d)
case 0xAE: // XOR (IY+d)
case 0xB6: // OR (IY+d)
case 0xBE: // CP (IY+d)
len = 3;
break;
case 0x21: // LD IY,nn'
case 0x22: // LD (nn'),IY
case 0x2A: // LD IY,(nn')
case 0x36: // LD (IY+d),n
case 0xCB: // Rotation,Bitop (IY+d)
len = 4;
break;
}
break;
}
return(len);
}
void ParseOpcodes(ULONG adr)
{
WORD i,len;
ULONG next;
Boolean label = true;
do {
if(label) // ein Label setzen?
OpcodesFlags[adr] |= 0x10; // Label setzen
if((OpcodesFlags[adr] & 0x0F) == Opcode) break; // Schleife erkannt!
if((OpcodesFlags[adr] & 0x0F) == Operand) {
//DebugStr("\pIllegaler Sprung?!?");
return;
}
len = OpcodeLen(adr); // Länge vom Opcode ermitteln
for(i=0;i<len;i++)
OpcodesFlags[adr+i] = Operand; // Opcode eintragen
OpcodesFlags[adr] = Opcode; // Start des Opcodes markieren
if(label) { // ein Label setzen?
OpcodesFlags[adr] |= 0x10; // Label setzen
label = false; // Label-Flag zurücksetzen
}
next = adr + len; // Ptr auf den Folgeopcode
switch(Opcodes[adr]) { // Opcode holen
case 0xCA: // JP c,????
case 0xC2:
case 0xDA:
case 0xD2:
case 0xEA:
case 0xE2:
case 0xFA:
case 0xF2:
ParseOpcodes((Opcodes[adr+2]<<8) + Opcodes[adr+1]);
break;
case 0x28: // JR c,??
case 0x20:
case 0x38:
case 0x30:
ParseOpcodes(adr + 2 + (BYTE)Opcodes[adr+1]);
break;
case 0xCC: // CALL c,????
case 0xC4:
case 0xDC:
case 0xD4:
case 0xEC:
case 0xE4:
case 0xFC:
case 0xF4:
ParseOpcodes((Opcodes[adr+2]<<8) + Opcodes[adr+1]);
break;
case 0xC8: // RET c
case 0xC0:
case 0xD8:
case 0xD0:
case 0xE8:
case 0xE0:
case 0xF8:
case 0xF0:
break;
case 0xC7: // RST 0
case 0xCF: // RST 8
case 0xD7: // RST 10
case 0xDF: // RST 18
case 0xE7: // RST 20
case 0xEF: // RST 28
case 0xF7: // RST 30
case 0xFF: // RST 38
ParseOpcodes(Opcodes[adr] & 0x38);
break;
case 0x10: // DJNZ ??
ParseOpcodes(adr + 2 + (BYTE)Opcodes[adr+1]);
break;
case 0xC3: // JP ????
next = (Opcodes[adr+2]<<8) + Opcodes[adr+1];
label = true;
break;
case 0x18: // JR ??
next = adr + 2 + (BYTE)Opcodes[adr+1];
label = true;
break;
case 0xCD: // CALL ????
ParseOpcodes((Opcodes[adr+2]<<8) + Opcodes[adr+1]);
break;
case 0xC9: // RET
return;
case 0xE9:
#if DEBUGGER
DebugStr("\pJP (HL) gefunden"); // JP (HL)
#endif
break;
case 0xDD:
#if DEBUGGER
if(Opcodes[adr+1] == 0xE9) { // JP (IX)
DebugStr("\pJP (IX) gefunden");
}
#endif
break;
case 0xFD:
#if DEBUGGER
if(Opcodes[adr+1] == 0xE9) { // JP (IY)
DebugStr("\pJP (IY) gefunden");
}
#endif
break;
case 0xED:
if(Opcodes[adr+1] == 0x4D) { // RTI
return;
} else if(Opcodes[adr+1] == 0x45) { // RETN
return;
}
break;
}
adr = next;
} while(1);
}
// Disassemblieren
VOID Disassemble(UWORD adr,STR s)
{
UBYTE a = Opcodes[adr];
UBYTE d = (a >> 3) & 7;
UBYTE e = a & 7;
static STR reg[8] = {"B","C","D","E","H","L","(HL)","A"};
static STR dreg[4] = {"BC","DE","HL","SP"};
static STR cond[8] = {"NZ","Z","NC","C","PO","PE","P","M"};
static STR arith[8] = {"ADD A,","ADC A,","SUB ","SBC A,","AND ","XOR ","OR ","CP "};
CHAR stemp[80]; // temp.String für sprintf()
CHAR ireg[3]; // temp.Indexregister
switch(a & 0xC0) {
case 0x00:
switch(e) {
case 0x00:
switch(d) {
case 0x00:
strcpy(s,"NOP");
break;
case 0x01:
strcpy(s,"EX AF,AF'");
break;
case 0x02:
strcpy(s,"DJNZ ");
sprintf(stemp,"#%4.4X",adr+2+(signed char)Opcodes[adr+1]);strcat(s,stemp);
break;
case 0x03:
strcpy(s,"JR ");
sprintf(stemp,"#%4.4X",adr+2+(signed char)Opcodes[adr+1]);strcat(s,stemp);
break;
default:
strcpy(s,"JR ");
strcat(s,cond[d & 3]);
strcat(s,",");
sprintf(stemp,"#%4.4X",adr+2+(signed char)Opcodes[adr+1]);strcat(s,stemp);
break;
}
break;
case 0x01:
if(a & 0x08) {
strcpy(s,"ADD HL,");
strcat(s,dreg[d >> 1]);
} else {
strcpy(s,"LD ");
strcat(s,dreg[d >> 1]);
strcat(s,",");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
}
break;
case 0x02:
switch(d) {
case 0x00:
strcpy(s,"LD (BC),A");
break;
case 0x01:
strcpy(s,"LD A,(BC)");
break;
case 0x02:
strcpy(s,"LD (DE),A");
break;
case 0x03:
strcpy(s,"LD A,(DE)");
break;
case 0x04:
strcpy(s,"LD (");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,"),HL");
break;
case 0x05:
strcpy(s,"LD HL,(");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,")");
break;
case 0x06:
strcpy(s,"LD (");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,"),A");
break;
case 0x07:
strcpy(s,"LD A,(");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,")");
break;
}
break;
case 0x03:
if(a & 0x08)
strcpy(s,"DEC ");
else
strcpy(s,"INC ");
strcat(s,dreg[d >> 1]);
break;
case 0x04:
strcpy(s,"INC ");
strcat(s,reg[d]);
break;
case 0x05:
strcpy(s,"DEC ");
strcat(s,reg[d]);
break;
case 0x06: // LD d,n
strcpy(s,"LD ");
strcat(s,reg[d]);
strcat(s,",");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
break;
case 0x07:
{
static STR str[8] = {"RLCA","RRCA","RLA","RRA","DAA","CPL","SCF","CCF"};
strcpy(s,str[d]);
}
break;
}
break;
case 0x40: // LD d,s
if(d == e) {
strcpy(s,"HALT");
} else {
strcpy(s,"LD ");
strcat(s,reg[d]);
strcat(s,",");
strcat(s,reg[e]);
}
break;
case 0x80:
strcpy(s,arith[d]);
strcat(s,reg[e]);
break;
case 0xC0:
switch(e) {
case 0x00:
strcpy(s,"RET ");
strcat(s,cond[d]);
break;
case 0x01:
if(d & 1) {
switch(d >> 1) {
case 0x00:
strcpy(s,"RET");
break;
case 0x01:
strcpy(s,"EXX");
break;
case 0x02:
strcpy(s,"JP (HL)");
break;
case 0x03:
strcpy(s,"LD SP,HL");
break;
}
} else {
strcpy(s,"POP ");
if((d >> 1)==3)
strcat(s,"AF");
else
strcat(s,dreg[d >> 1]);
}
break;
case 0x02:
strcpy(s,"JP ");
strcat(s,cond[d]);
strcat(s,",");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
break;
case 0x03:
switch(d) {
case 0x00:
strcpy(s,"JP ");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
break;
case 0x01: // 0xCB
a = Opcodes[++adr]; // Erweiterungsopcode holen
d = (a >> 3) & 7;
e = a & 7;
stemp[1] = 0; // temp.String = 1 Zeichen
switch(a & 0xC0) {
case 0x00:
{
static STR str[8] = {"RLC","RRC","RL","RR","SLA","SRA","???","SRL"};
strcpy(s,str[d]);
}
strcat(s," ");
strcat(s,reg[e]);
break;
case 0x40:
strcpy(s,"BIT ");
stemp[0] = d+'0';strcat(s,stemp);
strcat(s,",");
strcat(s,reg[e]);
break;
case 0x80:
strcpy(s,"RES ");
stemp[0] = d+'0';strcat(s,stemp);
strcat(s,",");
strcat(s,reg[e]);
break;
case 0xC0:
strcpy(s,"SET ");
stemp[0] = d+'0';strcat(s,stemp);
strcat(s,",");
strcat(s,reg[e]);
break;
}
break;
case 0x02:
strcpy(s,"OUT (");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,"),A");
break;
case 0x03:
strcpy(s,"IN A,(");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x04:
strcpy(s,"EX (SP),HL");
break;
case 0x05:
strcpy(s,"EX DE,HL");
break;
case 0x06:
strcpy(s,"DI");
break;
case 0x07:
strcpy(s,"EI");
break;
}
break;
case 0x04:
strcpy(s,"CALL ");
strcat(s,cond[d]);
strcat(s,",");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
break;
case 0x05:
if(d & 1) {
switch(d >> 1) {
case 0x00:
strcpy(s,"CALL ");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
break;
case 0x02: // 0xED
a = Opcodes[++adr]; // Erweiterungsopcode holen
d = (a >> 3) & 7;
e = a & 7;
switch(a & 0xC0) {
case 0x40:
switch(e) {
case 0x00:
strcpy(s,"IN ");
strcat(s,reg[d]);
strcat(s,",(C)");
break;
case 0x01:
strcpy(s,"OUT (C),");
strcat(s,reg[d]);
break;
case 0x02:
if(d & 1)
strcpy(s,"ADC");
else
strcpy(s,"SBC");
strcat(s," HL,");
strcat(s,dreg[d >> 1]);
break;
case 0x03:
if(d & 1) {
strcpy(s,"LD ");
strcat(s,dreg[d >> 1]);
strcat(s,",(");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,")");
} else {
strcpy(s,"LD (");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,"),");
strcat(s,dreg[d >> 1]);
}
break;
case 0x04:
{
static STR str[8] = {"NEG","???","???","???","???","???","???","???"};
strcpy(s,str[d]);
}
break;
case 0x05:
{
static STR str[8] = {"RETN","RETI","???","???","???","???","???","???"};
strcpy(s,str[d]);
}
break;
case 0x06:
strcpy(s,"IM ");
stemp[0] = d + '0' - 1; stemp[1] = 0;
strcat(s,stemp);
break;
case 0x07:
{
static STR str[8] = {"LD I,A","???","LD A,I","???","RRD","RLD","???","???"};
strcpy(s,str[d]);
}
break;
}
break;
case 0x80:
{
static STR str[32] = {"LDI","CPI","INI","OUTI","???","???","???","???",
"LDD","CPD","IND","OUTD","???","???","???","???",
"LDIR","CPIR","INIR","OTIR","???","???","???","???",
"LDDR","CPDR","INDR","OTDR","???","???","???","???"};
strcpy(s,str[a & 0x1F]);
}
break;
}
break;
default: // 0x01 (0xDD) = IX, 0x03 (0xFD) = IY
strcpy(ireg,(a & 0x20)?"IY":"IX");
a = Opcodes[++adr]; // Erweiterungsopcode holen
switch(a) {
case 0x09:
strcpy(s,"ADD ");
strcat(s,ireg);
strcat(s,",BC");
break;
case 0x19:
strcpy(s,"ADD ");
strcat(s,ireg);
strcat(s,",DE");
break;
case 0x21:
strcpy(s,"LD ");
strcat(s,ireg);
strcat(s,",");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
break;
case 0x22:
strcpy(s,"LD (");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,"),");
strcat(s,ireg);
break;
case 0x23:
strcpy(s,"INC ");
strcat(s,ireg);
break;
case 0x29:
strcpy(s,"ADD ");
strcat(s,ireg);
strcat(s,",");
strcat(s,ireg);
break;
case 0x2A:
strcpy(s,"LD ");
strcat(s,ireg);
strcat(s,",(");
sprintf(stemp,"#%4.4X",Opcodes[adr+1]+(Opcodes[adr+2]<<8));strcat(s,stemp);
strcat(s,")");
break;
case 0x2B:
strcpy(s,"DEC ");
strcat(s,ireg);
break;
case 0x34:
strcpy(s,"INC (");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x35:
strcpy(s,"DEC (");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x36:
strcpy(s,"LD (");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,"),");
sprintf(stemp,"#%2.2X",Opcodes[adr+2]);strcat(s,stemp);
break;
case 0x39:
strcpy(s,"ADD ");
strcat(s,ireg);
strcat(s,",SP");
break;
case 0x46:
case 0x4E:
case 0x56:
case 0x5E:
case 0x66:
case 0x6E:
strcpy(s,"LD ");
strcat(s,reg[(a>>3)&7]);
strcat(s,",(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x70:
case 0x71:
case 0x72:
case 0x73:
case 0x74:
case 0x75:
case 0x77:
strcpy(s,"LD (");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,"),");
strcat(s,reg[a & 7]);
break;
case 0x7E:
strcpy(s,"LD A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x86:
strcpy(s,"ADD A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x8E:
strcpy(s,"ADC A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x96:
strcpy(s,"SUB (");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0x9E:
strcpy(s,"SBC A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0xA6:
strcpy(s,"AND A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0xAE:
strcpy(s,"XOR A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0xB6:
strcpy(s,"OR A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0xBE:
strcpy(s,"CP A,(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
case 0xE1:
strcpy(s,"POP ");
strcat(s,ireg);
break;
case 0xE3:
strcpy(s,"EX (SP),");
strcat(s,ireg);
break;
case 0xE5:
strcpy(s,"PUSH ");
strcat(s,ireg);
break;
case 0xE9:
strcpy(s,"JP (");
strcat(s,ireg);
strcat(s,")");
break;
case 0xF9:
strcpy(s,"LD SP,");
strcat(s,ireg);
break;
case 0xCB:
a = Opcodes[adr+2]; // weiteren Unteropcode
d = (a >> 3) & 7;
stemp[1] = 0;
switch(a & 0xC0) {
case 0x00:
{
static STR str[8] = {"RLC","RRC","RL","RR","SLA","SRA","???","SRL"};
strcpy(s,str[d]);
}
strcat(s," ");
break;
case 0x40:
strcpy(s,"BIT ");
stemp[0] = d + '0';
strcat(s,stemp);
strcat(s,",");
break;
case 0x80:
strcpy(s,"RES ");
stemp[0] = d + '0';
strcat(s,stemp);
strcat(s,",");
break;
case 0xC0:
strcpy(s,"SET ");
stemp[0] = d + '0';
strcat(s,stemp);
strcat(s,",");
break;
}
strcat(s,"(");
strcat(s,ireg);
strcat(s,"+");
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
strcat(s,")");
break;
}
break;
}
} else {
strcpy(s,"PUSH ");
if((d >> 1)==3)
strcat(s,"AF");
else
strcat(s,dreg[d >> 1]);
}
break;
case 0x06:
strcpy(s,arith[d]);
sprintf(stemp,"#%2.2X",Opcodes[adr+1]);strcat(s,stemp);
break;
case 0x07:
strcpy(s,"RST ");
sprintf(stemp,"#%2.2X",a & 0x38);strcat(s,stemp);
break;
}
break;
}
}
// Einlesen, Parsen, Disassemblieren und Ausgeben
/*
void main(void)
{
WORD i;
FILE *f;
UWORD adr = 0;
CHAR s[80]; // Ausgabestring
f = fopen("EPROM","rb");
if(!f) return;
fread(Opcodes,CODESIZE,1,f); // EPROM einlesen
fclose(f);
for(i=0;i<CODESIZE;i++) // alles Daten…
OpcodesFlags[i] = Data;
for(i=0;i<0x40;i+=0x08)
if((OpcodesFlags[i] & 0x0F) == Data)
ParseOpcodes(i); // RST-Vektoren parsen (wenn nötig)
if((OpcodesFlags[i] & 0x0F) == Data)
ParseOpcodes(0x66); // NMI-Vektor auch parsen (wenn nötig)
#if FUTURA_189
ParseOpcodes(0xA41);
ParseOpcodes(0xDB6); // Meßwerte darstellen
ParseOpcodes(0xF5D);
ParseOpcodes(0xE83);
ParseOpcodes(0x0978);
ParseOpcodes(0x0933);
ParseOpcodes(0x11D3);
ParseOpcodes(0x1292);
ParseOpcodes(0x0AF8);
ParseOpcodes(0x098F);
ParseOpcodes(0x0B99);
ParseOpcodes(0x0BB3);
ParseOpcodes(0x0B4A); // Tastenfeld
ParseOpcodes(0x0B12);
ParseOpcodes(0x08FF);
ParseOpcodes(0x08F0);
ParseOpcodes(0x0BDA);
ParseOpcodes(0x0BCD);
ParseOpcodes(0x0A7E);
ParseOpcodes(0x0C2D);
ParseOpcodes(0x0AA6);
ParseOpcodes(0x0848);
ParseOpcodes(0x1660);
ParseOpcodes(0x166E);
ParseOpcodes(0x167C); // Spezielle Tastenkombinationen
ParseOpcodes(0x168A);
ParseOpcodes(0x1698);
ParseOpcodes(0x16A6);
ParseOpcodes(0x16CF);
#endif
f = stdout;
f = fopen("OUTPUT","w");
if(!f) return;
while(adr < CODESIZE) {
WORD len,i;
if((OpcodesFlags[adr] & 0x0F) == Data) {
fprintf(f,"L%4.4X: DEFB",(UWORD)adr);
for(i=0;i<16;i++) {
if((OpcodesFlags[adr+i] & 0x0F) != Data) break;
fprintf(f,"%c#%2.2X",(i)?',':' ',Opcodes[adr+i]);
}
fprintf(f,"\n");
adr += i;
} else {
len = OpcodeLen(adr); // Länge vom Opcode ermitteln
#if 1
if(OpcodesFlags[adr] & 0x10)
fprintf(f,"L%4.4X: ",adr);
else
fprintf(f," ");
#else
fprintf(f,"%4.4X: ",(UWORD)adr);
for(i=0;i<len;i++)
fprintf(f,"#%2.2X ",Opcodes[adr+i]);
for(i=4;i>len;i--)
fprintf(f," ");
fprintf(f," ");
#endif
Disassemble(adr,s);
fprintf(f,"%s\n",s);
adr += len;
}
}
fclose(f);
}
*/