Mercurial > repos > blastem
annotate zdis.c @ 418:dbf4e1c86f3c
Implement basic joystick support
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 23 Jun 2013 22:27:12 -0700 |
parents | 54c0e5f22198 |
children | 140af5509ce7 |
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(;;) { |
258
852b8765bba6
Fix infinite loop in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
199
diff
changeset
|
128 if (address > filesize || is_visited(address)) { |
199
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 |
258
852b8765bba6
Fix infinite loop in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
199
diff
changeset
|
136 //z80_disasm(&instbuf, disbuf); |
852b8765bba6
Fix infinite loop in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
199
diff
changeset
|
137 //printf("%X: %s\n", address, disbuf); |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 switch (instbuf.op) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 case Z80_JR: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 address += instbuf.immed; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 case Z80_JRCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 reference(address + instbuf.immed); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 def = defer(address + instbuf.immed, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 case Z80_JP: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 address = instbuf.immed; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 case Z80_JPCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 case Z80_CALL: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 case Z80_CALLCC: |
313
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
155 case Z80_RST: |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 reference(instbuf.immed); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 def = defer(instbuf.immed, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 break; |
313
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
159 default: |
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
160 if (z80_is_terminal(&instbuf)) { |
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
161 address = filesize + 1; |
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
162 } |
199
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 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 if (labels) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 for (address = filesize; address < (64*1024); address++) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 if (is_label(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 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
|
170 } |
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 puts(""); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 for (address = 0; address < filesize; address++) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 if (is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 z80_decode(encoded, &instbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 if (labels) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 /*m68k_disasm_labels(&instbuf, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 if (is_label(instbuf.address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 printf("ADR_%X:\n", instbuf.address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 if (addr) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 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
|
185 } else { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 printf("\t%s\n", disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 }*/ |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } else { |
314
54c0e5f22198
Show absolute addresses for JR, JRCC and DJNZ in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
313
diff
changeset
|
189 z80_disasm(&instbuf, disbuf, address); |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 printf("%X: %s\n", address, disbuf); |
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 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 return 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 } |