Mercurial > repos > blastem
annotate zdis.c @ 226:28a6697e847b
Implement CHK instruction (not fully tested).
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 21 Apr 2013 13:00:34 -0700 |
parents | 69585e7d474f |
children | 852b8765bba6 |
rev | line source |
---|---|
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include "z80inst.h" |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdio.h> |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stdlib.h> |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 uint8_t visited[(64*1024)/8]; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 uint8_t label[(64*1024)/8]; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 void visit(uint16_t address) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 visited[address/8] |= 1 << (address % 8); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 void reference(uint16_t address) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 //printf("referenced: %X\n", address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 label[address/8] |= 1 << (address % 8); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 uint8_t is_visited(uint16_t address) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 return visited[address/8] & (1 << (address % 8)); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 uint8_t is_label(uint16_t address) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 return label[address/8] & (1 << (address % 8)); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 typedef struct deferred { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 uint16_t address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 struct deferred *next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 } deferred; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 deferred * defer(uint16_t address, deferred * next) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 if (is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 return next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 //printf("deferring %X\n", address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 deferred * d = malloc(sizeof(deferred)); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 d->address = address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 d->next = next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 return d; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 uint8_t labels = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 uint8_t addr = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 uint8_t only = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 int main(int argc, char ** argv) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 long filesize; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 uint8_t *filebuf; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 char disbuf[1024]; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 z80inst instbuf; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 uint8_t * cur; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 FILE * f = fopen(argv[1], "rb"); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 fseek(f, 0, SEEK_END); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 filesize = ftell(f); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 fseek(f, 0, SEEK_SET); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 filebuf = malloc(filesize); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 fread(filebuf, 1, filesize, f); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 fclose(f); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 deferred *def = NULL, *tmpd; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 for(uint8_t opt = 2; opt < argc; ++opt) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 if (argv[opt][0] == '-') { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 FILE * address_log; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 switch (argv[opt][1]) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 case 'l': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 labels = 1; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 case 'a': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 addr = 1; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 case 'o': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 only = 1; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 case 'f': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 opt++; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 if (opt >= argc) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 fputs("-f must be followed by a filename\n", stderr); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 exit(1); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 address_log = fopen(argv[opt], "r"); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 if (!address_log) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 fprintf(stderr, "Failed to open %s for reading\n", argv[opt]); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 exit(1); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 while (fgets(disbuf, sizeof(disbuf), address_log)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 if (disbuf[0]) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 uint16_t address = strtol(disbuf, NULL, 16); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 if (address) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 def = defer(address, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 reference(address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 } else { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 uint16_t address = strtol(argv[opt], NULL, 16); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 def = defer(address, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 reference(address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 uint16_t start = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 uint8_t *encoded, *next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 uint32_t size; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 if (!def || !only) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 def = defer(start, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 uint16_t address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 while(def) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 do { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 encoded = NULL; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 address = def->address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 if (!is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 tmpd = def; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 def = def->next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 free(tmpd); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } while(def && encoded == NULL); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 if (!encoded) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 for(;;) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 if (address > filesize) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 visit(address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 next = z80_decode(encoded, &instbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 address += (next-encoded); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 encoded = next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 //m68k_disasm(&instbuf, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 //printf("%X: %s\n", instbuf.address, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 if (instbuf.op == Z80_HALT || instbuf.op == Z80_RET || instbuf.op == Z80_RETI || instbuf.op == Z80_RETN || instbuf.op == Z80_RST) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 switch (instbuf.op) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 case Z80_JR: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 address += instbuf.immed; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 case Z80_JRCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 reference(address + instbuf.immed); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 def = defer(address + instbuf.immed, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 case Z80_JP: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 address = instbuf.immed; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 case Z80_JPCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 case Z80_CALL: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 case Z80_CALLCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 reference(instbuf.immed); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 def = defer(instbuf.immed, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 if (labels) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 for (address = filesize; address < (64*1024); address++) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 if (is_label(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 printf("ADR_%X equ $%X\n", address, address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 puts(""); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 for (address = 0; address < filesize; address++) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 if (is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 z80_decode(encoded, &instbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 if (labels) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 /*m68k_disasm_labels(&instbuf, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 if (is_label(instbuf.address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 printf("ADR_%X:\n", instbuf.address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 if (addr) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 printf("\t%s\t;%X\n", disbuf, instbuf.address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 } else { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 printf("\t%s\n", disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 }*/ |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 } else { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 z80_disasm(&instbuf, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 printf("%X: %s\n", address, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 return 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |