Mercurial > repos > blastem
annotate zdis.c @ 666:b68039895627
In theory, the Z80 core should work on 32-bit builds now; however, I suspect there is some code that cannot deal with most of the Z80 registers not having a native register so more work will be needed
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 02 Jan 2015 13:47:34 -0800 |
parents | 140af5509ce7 |
children | 3eced113081c |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
314
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
314
diff
changeset
|
2 Copyright 2013 Michael Pavone |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
314
diff
changeset
|
3 This file is part of BlastEm. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
314
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
314
diff
changeset
|
5 */ |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "z80inst.h" |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include <stdio.h> |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <stdlib.h> |
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 uint8_t visited[(64*1024)/8]; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 uint8_t label[(64*1024)/8]; |
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 visit(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 visited[address/8] |= 1 << (address % 8); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 } |
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 void reference(uint16_t address) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 //printf("referenced: %X\n", address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 label[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_visited(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 visited[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 uint8_t is_label(uint16_t address) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 return label[address/8] & (1 << (address % 8)); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 } |
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 typedef struct deferred { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 uint16_t address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 struct deferred *next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } deferred; |
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 deferred * defer(uint16_t address, deferred * next) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 if (is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 return next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 //printf("deferring %X\n", address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 deferred * d = malloc(sizeof(deferred)); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 d->address = address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 d->next = next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 return d; |
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 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 uint8_t labels = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 uint8_t addr = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 uint8_t only = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 int main(int argc, char ** argv) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 long filesize; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 uint8_t *filebuf; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 char disbuf[1024]; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 z80inst instbuf; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 uint8_t * cur; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 FILE * f = fopen(argv[1], "rb"); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 fseek(f, 0, SEEK_END); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 filesize = ftell(f); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 fseek(f, 0, SEEK_SET); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 filebuf = malloc(filesize); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 fread(filebuf, 1, filesize, f); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 fclose(f); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 deferred *def = NULL, *tmpd; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 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
|
71 if (argv[opt][0] == '-') { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 FILE * address_log; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 switch (argv[opt][1]) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 case 'l': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 labels = 1; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 case 'a': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 addr = 1; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 case 'o': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 only = 1; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 case 'f': |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 opt++; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 if (opt >= argc) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 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
|
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 address_log = fopen(argv[opt], "r"); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 if (!address_log) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 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
|
93 exit(1); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 while (fgets(disbuf, sizeof(disbuf), address_log)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 if (disbuf[0]) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 uint16_t address = strtol(disbuf, NULL, 16); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 if (address) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 def = defer(address, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 reference(address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 } |
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 } else { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 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
|
107 def = defer(address, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 reference(address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 uint16_t start = 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 uint8_t *encoded, *next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 uint32_t size; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 if (!def || !only) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 def = defer(start, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 uint16_t address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 while(def) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 do { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 encoded = NULL; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 address = def->address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 if (!is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 tmpd = def; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 def = def->next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 free(tmpd); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } while(def && encoded == NULL); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 if (!encoded) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 for(;;) { |
258
852b8765bba6
Fix infinite loop in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
199
diff
changeset
|
133 if (address > filesize || is_visited(address)) { |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 break; |
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 visit(address); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 next = z80_decode(encoded, &instbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 address += (next-encoded); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 encoded = next; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 |
258
852b8765bba6
Fix infinite loop in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
199
diff
changeset
|
141 //z80_disasm(&instbuf, disbuf); |
852b8765bba6
Fix infinite loop in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
199
diff
changeset
|
142 //printf("%X: %s\n", address, disbuf); |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 switch (instbuf.op) |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 case Z80_JR: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 address += instbuf.immed; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 case Z80_JRCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 reference(address + instbuf.immed); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 def = defer(address + instbuf.immed, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 case Z80_JP: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 address = instbuf.immed; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 break; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 case Z80_JPCC: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 case Z80_CALL: |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 case Z80_CALLCC: |
313
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
160 case Z80_RST: |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 reference(instbuf.immed); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 def = defer(instbuf.immed, def); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 break; |
313
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
164 default: |
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
165 if (z80_is_terminal(&instbuf)) { |
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
166 address = filesize + 1; |
a13329645ea3
Fix terminal instruction detection in disassembler
Mike Pavone <pavone@retrodev.com>
parents:
258
diff
changeset
|
167 } |
199
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 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 if (labels) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 for (address = filesize; address < (64*1024); address++) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 if (is_label(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 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
|
175 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 puts(""); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 for (address = 0; address < filesize; address++) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 if (is_visited(address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 encoded = filebuf + address; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 z80_decode(encoded, &instbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 if (labels) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 /*m68k_disasm_labels(&instbuf, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 if (is_label(instbuf.address)) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 printf("ADR_%X:\n", instbuf.address); |
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 if (addr) { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 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
|
190 } else { |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 printf("\t%s\n", disbuf); |
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 } else { |
314
54c0e5f22198
Show absolute addresses for JR, JRCC and DJNZ in Z80 disassembler
Mike Pavone <pavone@retrodev.com>
parents:
313
diff
changeset
|
194 z80_disasm(&instbuf, disbuf, address); |
199
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 printf("%X: %s\n", address, disbuf); |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 } |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 return 0; |
69585e7d474f
Add initial stab at Z80 decoder and disassembler
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 } |