~ubuntu-branches/ubuntu/lucid/sdlmame/lucid

« back to all changes in this revision

Viewing changes to src/tools/unidasm.c

  • Committer: Bazaar Package Importer
  • Author(s): Cesare Falco
  • Date: 2009-11-03 17:10:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20091103171015-6hop4ory5lxnumpn
Tags: 0.135-0ubuntu1
* New upstream release - Closes (LP: #403212)
* debian/watch: unstable releases are no longer detected
* mame.ini: added the cheat subdirectories to cheatpath so zipped
  cheatfiles will be searched too
* renamed crsshair subdirectory to crosshair to reflect upstream change
* mame.ini: renamed references to crosshair subdirectory (see above)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 
 
3
    mamedasm.c
 
4
 
 
5
    Generic MAME disassembler.
 
6
 
 
7
****************************************************************************
 
8
 
 
9
    Copyright Aaron Giles
 
10
    All rights reserved.
 
11
 
 
12
    Redistribution and use in source and binary forms, with or without
 
13
    modification, are permitted provided that the following conditions are
 
14
    met:
 
15
 
 
16
        * Redistributions of source code must retain the above copyright
 
17
          notice, this list of conditions and the following disclaimer.
 
18
        * Redistributions in binary form must reproduce the above copyright
 
19
          notice, this list of conditions and the following disclaimer in
 
20
          the documentation and/or other materials provided with the
 
21
          distribution.
 
22
        * Neither the name 'MAME' nor the names of its contributors may be
 
23
          used to endorse or promote products derived from this software
 
24
          without specific prior written permission.
 
25
 
 
26
    THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
 
27
    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
28
    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
29
    DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
 
30
    INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
31
    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
32
    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
33
    HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
34
    STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 
35
    IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
36
    POSSIBILITY OF SUCH DAMAGE.
 
37
 
 
38
****************************************************************************/
 
39
 
 
40
#include "cpuintrf.h"
 
41
#include <ctype.h>
 
42
 
 
43
 
 
44
enum _display_type
 
45
{
 
46
        _8bit,
 
47
        _8bitx,
 
48
        _16be,
 
49
        _16le,
 
50
        _24be,
 
51
        _24le,
 
52
        _32be,
 
53
        _32le,
 
54
        _40be,
 
55
        _40le,
 
56
        _48be,
 
57
        _48le,
 
58
        _56be,
 
59
        _56le,
 
60
        _64be,
 
61
        _64le
 
62
};
 
63
typedef enum _display_type display_type;
 
64
 
 
65
 
 
66
typedef struct _dasm_table_entry dasm_table_entry;
 
67
struct _dasm_table_entry
 
68
{
 
69
        const char *                    name;
 
70
        display_type                    display;
 
71
        INT8                                    pcshift;
 
72
        cpu_disassemble_func    func;
 
73
};
 
74
 
 
75
 
 
76
typedef struct _options options;
 
77
struct _options
 
78
{
 
79
        const char *                    filename;
 
80
        offs_t                                  basepc;
 
81
        UINT8                                   norawbytes;
 
82
        UINT8                                   lower;
 
83
        UINT8                                   upper;
 
84
        UINT8                                   flipped;
 
85
        int                                             mode;
 
86
        const dasm_table_entry *dasm;
 
87
};
 
88
 
 
89
 
 
90
CPU_DISASSEMBLE( adsp21xx );
 
91
CPU_DISASSEMBLE( alpha8201 );
 
92
CPU_DISASSEMBLE( arm );
 
93
CPU_DISASSEMBLE( arm7arm );
 
94
CPU_DISASSEMBLE( arm7thumb );
 
95
CPU_DISASSEMBLE( asap );
 
96
CPU_DISASSEMBLE( avr8 );
 
97
CPU_DISASSEMBLE( ccpu );
 
98
CPU_DISASSEMBLE( cdp1802 );
 
99
CPU_DISASSEMBLE( cop410 );
 
100
CPU_DISASSEMBLE( cop420 );
 
101
CPU_DISASSEMBLE( cop444 );
 
102
CPU_DISASSEMBLE( cp1610 );
 
103
CPU_DISASSEMBLE( cquestsnd );
 
104
CPU_DISASSEMBLE( cquestrot );
 
105
CPU_DISASSEMBLE( cquestlin );
 
106
CPU_DISASSEMBLE( dsp32c );
 
107
CPU_DISASSEMBLE( dsp56k );
 
108
CPU_DISASSEMBLE( hyperstone_generic );
 
109
CPU_DISASSEMBLE( esrip );
 
110
CPU_DISASSEMBLE( f8 );
 
111
CPU_DISASSEMBLE( g65816_generic );
 
112
CPU_DISASSEMBLE( h6280 );
 
113
CPU_DISASSEMBLE( h8 );
 
114
CPU_DISASSEMBLE( hd6309 );
 
115
CPU_DISASSEMBLE( i4004 );
 
116
CPU_DISASSEMBLE( i8085 );
 
117
CPU_DISASSEMBLE( x86_16 );
 
118
CPU_DISASSEMBLE( x86_32 );
 
119
CPU_DISASSEMBLE( x86_64 );
 
120
CPU_DISASSEMBLE( i960 );
 
121
CPU_DISASSEMBLE( jaguargpu );
 
122
CPU_DISASSEMBLE( jaguardsp );
 
123
CPU_DISASSEMBLE( konami );
 
124
CPU_DISASSEMBLE( lh5801 );
 
125
CPU_DISASSEMBLE( lr35902 );
 
126
CPU_DISASSEMBLE( m37710_generic );
 
127
CPU_DISASSEMBLE( m6502 );
 
128
CPU_DISASSEMBLE( m65sc02 );
 
129
CPU_DISASSEMBLE( m65c02 );
 
130
CPU_DISASSEMBLE( m65ce02 );
 
131
CPU_DISASSEMBLE( m6510 );
 
132
CPU_DISASSEMBLE( deco16 );
 
133
CPU_DISASSEMBLE( m4510 );
 
134
CPU_DISASSEMBLE( m6800 );
 
135
CPU_DISASSEMBLE( m6801 );
 
136
CPU_DISASSEMBLE( m6802 );
 
137
CPU_DISASSEMBLE( m6803 );
 
138
CPU_DISASSEMBLE( hd63701 );
 
139
CPU_DISASSEMBLE( nsc8105 );
 
140
CPU_DISASSEMBLE( m68000 );
 
141
CPU_DISASSEMBLE( m68008 );
 
142
CPU_DISASSEMBLE( m68010 );
 
143
CPU_DISASSEMBLE( m68020 );
 
144
CPU_DISASSEMBLE( m68030 );
 
145
CPU_DISASSEMBLE( m68040 );
 
146
CPU_DISASSEMBLE( m6805 );
 
147
CPU_DISASSEMBLE( m6809 );
 
148
CPU_DISASSEMBLE( mb86233 );
 
149
CPU_DISASSEMBLE( mb88 );
 
150
CPU_DISASSEMBLE( mcs48 );
 
151
CPU_DISASSEMBLE( upi41 );
 
152
CPU_DISASSEMBLE( i8051 );
 
153
CPU_DISASSEMBLE( i8052 );
 
154
CPU_DISASSEMBLE( i80c51 );
 
155
CPU_DISASSEMBLE( i80c52 );
 
156
CPU_DISASSEMBLE( ds5002fp );
 
157
CPU_DISASSEMBLE( minx );
 
158
CPU_DISASSEMBLE( mips3be );
 
159
CPU_DISASSEMBLE( mips3le );
 
160
CPU_DISASSEMBLE( psxcpu_generic );
 
161
CPU_DISASSEMBLE( r3000be );
 
162
CPU_DISASSEMBLE( r3000le );
 
163
CPU_DISASSEMBLE( nec_generic );
 
164
CPU_DISASSEMBLE( pdp1 );
 
165
CPU_DISASSEMBLE( tx0_64kw );
 
166
CPU_DISASSEMBLE( tx0_8kw );
 
167
CPU_DISASSEMBLE( pic16c5x );
 
168
CPU_DISASSEMBLE( powerpc );
 
169
CPU_DISASSEMBLE( rsp );
 
170
CPU_DISASSEMBLE( s2650 );
 
171
CPU_DISASSEMBLE( saturn );
 
172
CPU_DISASSEMBLE( sc61860 );
 
173
CPU_DISASSEMBLE( se3208 );
 
174
CPU_DISASSEMBLE( sh2 );
 
175
CPU_DISASSEMBLE( sh4 );
 
176
CPU_DISASSEMBLE( sharc );
 
177
CPU_DISASSEMBLE( sm8500 );
 
178
CPU_DISASSEMBLE( spc700 );
 
179
CPU_DISASSEMBLE( ssem );
 
180
CPU_DISASSEMBLE( ssp1601 );
 
181
CPU_DISASSEMBLE( t11 );
 
182
CPU_DISASSEMBLE( t90 );
 
183
CPU_DISASSEMBLE( tlcs900 );
 
184
CPU_DISASSEMBLE( tms0980 );
 
185
CPU_DISASSEMBLE( tms1000 );
 
186
CPU_DISASSEMBLE( tms1100 );
 
187
CPU_DISASSEMBLE( tms32010 );
 
188
CPU_DISASSEMBLE( tms32025 );
 
189
CPU_DISASSEMBLE( tms32031 );
 
190
CPU_DISASSEMBLE( tms32051 );
 
191
CPU_DISASSEMBLE( tms34010 );
 
192
CPU_DISASSEMBLE( tms34020 );
 
193
CPU_DISASSEMBLE( tms57002 );
 
194
CPU_DISASSEMBLE( tms7000 );
 
195
CPU_DISASSEMBLE( upd7810 );
 
196
CPU_DISASSEMBLE( upd7807 );
 
197
CPU_DISASSEMBLE( upd7801 );
 
198
CPU_DISASSEMBLE( upd78c05 );
 
199
CPU_DISASSEMBLE( v60 );
 
200
CPU_DISASSEMBLE( v70 );
 
201
CPU_DISASSEMBLE( v810 );
 
202
CPU_DISASSEMBLE( z180 );
 
203
CPU_DISASSEMBLE( z8000 );
 
204
CPU_DISASSEMBLE( z80 );
 
205
CPU_DISASSEMBLE( z8 );
 
206
 
 
207
 
 
208
static const dasm_table_entry dasm_table[] =
 
209
{
 
210
        { "adsp21xx",   _24le, -2, CPU_DISASSEMBLE_NAME(adsp21xx) },
 
211
        { "alpha8201",  _8bit,  0, CPU_DISASSEMBLE_NAME(alpha8201) },
 
212
        { "arm",                _32le,  0, CPU_DISASSEMBLE_NAME(arm) },
 
213
        { "arm7",               _32le,  0, CPU_DISASSEMBLE_NAME(arm7arm) },
 
214
        { "arm7thumb",  _16le,  0, CPU_DISASSEMBLE_NAME(arm7thumb) },
 
215
        { "asap",               _32le,  0, CPU_DISASSEMBLE_NAME(asap) },
 
216
        { "avr8",               _16le,  0, CPU_DISASSEMBLE_NAME(avr8) },
 
217
        { "ccpu",               _8bit,  0, CPU_DISASSEMBLE_NAME(ccpu) },
 
218
        { "cdp1802",    _8bit,  0, CPU_DISASSEMBLE_NAME(cdp1802) },
 
219
        { "cop410",             _8bit,  0, CPU_DISASSEMBLE_NAME(cop410) },
 
220
        { "cop420",             _8bit,  0, CPU_DISASSEMBLE_NAME(cop420) },
 
221
        { "cop444",             _8bit,  0, CPU_DISASSEMBLE_NAME(cop444) },
 
222
        { "cp1610",             _16be, -1, CPU_DISASSEMBLE_NAME(cp1610) },
 
223
        { "cquestsnd",  _64be, -3, CPU_DISASSEMBLE_NAME(cquestsnd) },
 
224
        { "cquestrot",  _64be, -3, CPU_DISASSEMBLE_NAME(cquestrot) },
 
225
        { "cquestlin",  _64be, -3, CPU_DISASSEMBLE_NAME(cquestlin) },
 
226
        { "dsp32c",             _32le,  0, CPU_DISASSEMBLE_NAME(dsp32c) },
 
227
        { "dsp56k",             _16le, -1, CPU_DISASSEMBLE_NAME(dsp56k) },
 
228
        { "hyperstone", _16be,  0, CPU_DISASSEMBLE_NAME(hyperstone_generic) },
 
229
        { "esrip",              _64be,  0, CPU_DISASSEMBLE_NAME(esrip) },
 
230
        { "f8",                 _8bit,  0, CPU_DISASSEMBLE_NAME(f8) },
 
231
        { "g65816",             _8bit,  0, CPU_DISASSEMBLE_NAME(g65816_generic) },
 
232
        { "h6280",              _8bit,  0, CPU_DISASSEMBLE_NAME(h6280) },
 
233
        { "h8",                 _16be,  0, CPU_DISASSEMBLE_NAME(h8) },
 
234
        { "hd6309",             _8bit,  0, CPU_DISASSEMBLE_NAME(hd6309) },
 
235
        { "i386",               _8bit,  0, CPU_DISASSEMBLE_NAME(x86_32) },
 
236
        { "i4004",              _8bit,  0, CPU_DISASSEMBLE_NAME(i4004) },
 
237
        { "i8085",              _8bit,  0, CPU_DISASSEMBLE_NAME(i8085) },
 
238
        { "i80286",             _8bit,  0, CPU_DISASSEMBLE_NAME(x86_16) },
 
239
        { "i8086",              _8bit,  0, CPU_DISASSEMBLE_NAME(x86_16) },
 
240
        { "i960",               _32le,  0, CPU_DISASSEMBLE_NAME(i960) },
 
241
        { "jaguargpu",  _16be,  0, CPU_DISASSEMBLE_NAME(jaguargpu) },
 
242
        { "jaguardsp",  _16be,  0, CPU_DISASSEMBLE_NAME(jaguardsp) },
 
243
        { "x86_16",             _8bit,  0, CPU_DISASSEMBLE_NAME(x86_16) },
 
244
        { "x86_32",             _8bit,  0, CPU_DISASSEMBLE_NAME(x86_32) },
 
245
        { "x86_64",             _8bit,  0, CPU_DISASSEMBLE_NAME(x86_64) },
 
246
        { "konami",     _8bit,  0, CPU_DISASSEMBLE_NAME(konami) },
 
247
        { "lh5801",     _8bit,  0, CPU_DISASSEMBLE_NAME(lh5801) },
 
248
        { "lr35902",    _8bit,  0, CPU_DISASSEMBLE_NAME(lr35902) },
 
249
        { "m37710",     _8bit,  0, CPU_DISASSEMBLE_NAME(m37710_generic) },
 
250
        { "m6502",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6502) },
 
251
        { "m65sc02",    _8bit,  0, CPU_DISASSEMBLE_NAME(m65sc02) },
 
252
        { "m65c02",     _8bit,  0, CPU_DISASSEMBLE_NAME(m65c02) },
 
253
        { "m65ce02",    _8bit,  0, CPU_DISASSEMBLE_NAME(m65ce02) },
 
254
        { "m6510",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6510) },
 
255
        { "deco16",     _8bit,  0, CPU_DISASSEMBLE_NAME(deco16) },
 
256
        { "m4510",      _8bit,  0, CPU_DISASSEMBLE_NAME(m4510) },
 
257
        { "m6800",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6800) },
 
258
        { "m6801",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6801) },
 
259
        { "m6802",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6802) },
 
260
        { "m6803",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6803) },
 
261
        { "hd63701",    _8bit,  0, CPU_DISASSEMBLE_NAME(hd63701) },
 
262
        { "nsc8105",    _8bit,  0, CPU_DISASSEMBLE_NAME(nsc8105) },
 
263
        { "m68000",     _16be,  0, CPU_DISASSEMBLE_NAME(m68000) },
 
264
        { "m68008",     _16be,  0, CPU_DISASSEMBLE_NAME(m68008) },
 
265
        { "m68010",     _16be,  0, CPU_DISASSEMBLE_NAME(m68010) },
 
266
        { "m68020",     _16be,  0, CPU_DISASSEMBLE_NAME(m68020) },
 
267
        { "m68030",     _16be,  0, CPU_DISASSEMBLE_NAME(m68030) },
 
268
        { "m68040",     _16be,  0, CPU_DISASSEMBLE_NAME(m68040) },
 
269
        { "m6805",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6805) },
 
270
        { "m6809",      _8bit,  0, CPU_DISASSEMBLE_NAME(m6809) },
 
271
        { "mb86233",    _32le, -2, CPU_DISASSEMBLE_NAME(mb86233) },
 
272
        { "mb88xx",     _8bit,  0, CPU_DISASSEMBLE_NAME(mb88) },
 
273
        { "mcs48",      _8bit,  0, CPU_DISASSEMBLE_NAME(mcs48) },
 
274
        { "upi41",      _8bit,  0, CPU_DISASSEMBLE_NAME(upi41) },
 
275
        { "i8051",      _8bit,  0, CPU_DISASSEMBLE_NAME(i8051) },
 
276
        { "i8052",      _8bit,  0, CPU_DISASSEMBLE_NAME(i8052) },
 
277
        { "i80c51",     _8bit,  0, CPU_DISASSEMBLE_NAME(i80c51) },
 
278
        { "i80c52",     _8bit,  0, CPU_DISASSEMBLE_NAME(i80c52) },
 
279
        { "ds5002fp",   _8bit,  0, CPU_DISASSEMBLE_NAME(ds5002fp) },
 
280
        { "minx",       _8bit,  0, CPU_DISASSEMBLE_NAME(minx) },
 
281
        { "mips3be",    _32be,  0, CPU_DISASSEMBLE_NAME(mips3be) },
 
282
        { "mips3le",    _32le,  0, CPU_DISASSEMBLE_NAME(mips3le) },
 
283
        { "psxcpu",     _32le,  0, CPU_DISASSEMBLE_NAME(psxcpu_generic) },
 
284
        { "r3000be",    _32be,  0, CPU_DISASSEMBLE_NAME(r3000be) },
 
285
        { "r3000le",    _32le,  0, CPU_DISASSEMBLE_NAME(r3000le) },
 
286
        { "nec",        _8bit,  0, CPU_DISASSEMBLE_NAME(nec_generic) },
 
287
        { "pdp1",       _32be,  0, CPU_DISASSEMBLE_NAME(pdp1) },
 
288
        { "tx0_64kw",   _32be, -2, CPU_DISASSEMBLE_NAME(tx0_64kw) },
 
289
        { "tx0_8kw",    _32be, -2, CPU_DISASSEMBLE_NAME(tx0_8kw) },
 
290
        { "pic16c5x",   _16le, -1, CPU_DISASSEMBLE_NAME(pic16c5x) },
 
291
        { "powerpc",    _32be,  0, CPU_DISASSEMBLE_NAME(powerpc) },
 
292
        { "rsp",        _32le,  0, CPU_DISASSEMBLE_NAME(rsp) },
 
293
        { "s2650",      _8bit,  0, CPU_DISASSEMBLE_NAME(s2650) },
 
294
        { "saturn",     _8bit,  0, CPU_DISASSEMBLE_NAME(saturn) },
 
295
        { "sc61860",    _8bit,  0, CPU_DISASSEMBLE_NAME(sc61860) },
 
296
        { "se3208",     _16le,  0, CPU_DISASSEMBLE_NAME(se3208) },
 
297
        { "sh2",        _16be,  0, CPU_DISASSEMBLE_NAME(sh2) },
 
298
        { "sh4",        _16le,  0, CPU_DISASSEMBLE_NAME(sh4) },
 
299
        { "sharc",      _64le, -3, CPU_DISASSEMBLE_NAME(sharc) },
 
300
        { "sm8500",     _8bit,  0, CPU_DISASSEMBLE_NAME(sm8500) },
 
301
        { "spc700",     _8bit,  0, CPU_DISASSEMBLE_NAME(spc700) },
 
302
        { "ssem",       _32le,  0, CPU_DISASSEMBLE_NAME(ssem) },
 
303
        { "ssp1601",    _16be, -1, CPU_DISASSEMBLE_NAME(ssp1601) },
 
304
        { "t11",        _16le,  0, CPU_DISASSEMBLE_NAME(t11) },
 
305
//  { "t90",        _8bit,  0, CPU_DISASSEMBLE_NAME(t90) },
 
306
        { "tlcs900",    _8bit,  0, CPU_DISASSEMBLE_NAME(tlcs900) },
 
307
        { "tms0980",    _16be,  0, CPU_DISASSEMBLE_NAME(tms0980) },
 
308
        { "tms1000",    _8bit,  0, CPU_DISASSEMBLE_NAME(tms1000) },
 
309
        { "tms1100",    _8bit,  0, CPU_DISASSEMBLE_NAME(tms1100) },
 
310
        { "tms32010",   _16be, -1, CPU_DISASSEMBLE_NAME(tms32010) },
 
311
        { "tms32025",   _16be, -1, CPU_DISASSEMBLE_NAME(tms32025) },
 
312
        { "tms32031",   _32le, -2, CPU_DISASSEMBLE_NAME(tms32031) },
 
313
        { "tms32051",   _16le, -1, CPU_DISASSEMBLE_NAME(tms32051) },
 
314
        { "tms34010",   _8bit,  3, CPU_DISASSEMBLE_NAME(tms34010) },
 
315
        { "tms34020",   _8bit,  3, CPU_DISASSEMBLE_NAME(tms34020) },
 
316
        { "tms57002",   _32le, -2, CPU_DISASSEMBLE_NAME(tms57002) },
 
317
        { "tms7000",    _8bit,  0, CPU_DISASSEMBLE_NAME(tms7000) },
 
318
        { "upd7810",    _8bit,  0, CPU_DISASSEMBLE_NAME(upd7810) },
 
319
        { "upd7807",    _8bit,  0, CPU_DISASSEMBLE_NAME(upd7807) },
 
320
        { "upd7801",    _8bit,  0, CPU_DISASSEMBLE_NAME(upd7801) },
 
321
        { "upd78c05",   _8bit,  0, CPU_DISASSEMBLE_NAME(upd78c05) },
 
322
        { "v60",        _8bit,  0, CPU_DISASSEMBLE_NAME(v60) },
 
323
        { "v70",        _8bit,  0, CPU_DISASSEMBLE_NAME(v70) },
 
324
        { "v810",       _16le,  0, CPU_DISASSEMBLE_NAME(v810) },
 
325
        { "z180",       _8bit,  0, CPU_DISASSEMBLE_NAME(z180) },
 
326
//  { "z8000",      _16be,  0, CPU_DISASSEMBLE_NAME(z8000) },
 
327
        { "z80",                _8bit,  0, CPU_DISASSEMBLE_NAME(z80) },
 
328
        { "z8",                 _8bit,  0, CPU_DISASSEMBLE_NAME(z8) },
 
329
};
 
330
 
 
331
 
 
332
void CLIB_DECL fatalerror(const char *text, ...)
 
333
{
 
334
        va_list arg;
 
335
 
 
336
        /* dump to the buffer; assume no one writes >2k lines this way */
 
337
        va_start(arg, text);
 
338
        vfprintf(stderr, text, arg);
 
339
        va_end(arg);
 
340
 
 
341
        exit(1);
 
342
}
 
343
 
 
344
 
 
345
void CLIB_DECL logerror(const char *format, ...)
 
346
{
 
347
        /* silent logerrors are allowed in disassemblers */
 
348
}
 
349
 
 
350
 
 
351
void CLIB_DECL mame_printf_debug(const char *format, ...)
 
352
{
 
353
        /* silent mame_printf_debugs are allowed in disassemblers */
 
354
}
 
355
 
 
356
 
 
357
static int parse_options(int argc, char *argv[], options *opts)
 
358
{
 
359
        int pending_base = FALSE;
 
360
        int pending_arch = FALSE;
 
361
        int pending_mode = FALSE;
 
362
        int curarch;
 
363
        int numrows;
 
364
        int arg;
 
365
 
 
366
        memset(opts, 0, sizeof(*opts));
 
367
 
 
368
        // loop through arguments
 
369
        for (arg = 1; arg < argc; arg++)
 
370
        {
 
371
                char *curarg = argv[arg];
 
372
 
 
373
                // is it a switch?
 
374
                if (curarg[0] == '-')
 
375
                {
 
376
                        if (pending_base || pending_arch || pending_mode)
 
377
                                goto usage;
 
378
 
 
379
                        if (tolower((UINT8)curarg[1]) == 'a')
 
380
                                pending_arch = TRUE;
 
381
                        else if (tolower((UINT8)curarg[1]) == 'b')
 
382
                                pending_base = TRUE;
 
383
                        else if (tolower((UINT8)curarg[1]) == 'f')
 
384
                                opts->flipped = TRUE;
 
385
                        else if (tolower((UINT8)curarg[1]) == 'l')
 
386
                                opts->lower = TRUE;
 
387
                        else if (tolower((UINT8)curarg[1]) == 'm')
 
388
                                pending_mode = TRUE;
 
389
                        else if (tolower((UINT8)curarg[1]) == 'n')
 
390
                                opts->norawbytes = TRUE;
 
391
                        else if (tolower((UINT8)curarg[1]) == 'u')
 
392
                                opts->upper = TRUE;
 
393
                        else
 
394
                                goto usage;
 
395
                }
 
396
 
 
397
                // base PC
 
398
                else if (pending_base)
 
399
                {
 
400
                        int result;
 
401
                        if (curarg[0] == '0' && curarg[1] == 'x')
 
402
                                result = sscanf(&curarg[2], "%x", &opts->basepc);
 
403
                        else if (curarg[0] == '$')
 
404
                                result = sscanf(&curarg[1], "%x", &opts->basepc);
 
405
                        else
 
406
                                result = sscanf(&curarg[0], "%x", &opts->basepc);
 
407
                        if (result != 1)
 
408
                                goto usage;
 
409
                        pending_base = FALSE;
 
410
                }
 
411
 
 
412
                // mode
 
413
                else if (pending_mode)
 
414
                {
 
415
                        if (sscanf(curarg, "%d", &opts->mode) != 1)
 
416
                                goto usage;
 
417
                        pending_mode = FALSE;
 
418
                }
 
419
 
 
420
                // architecture
 
421
                else if (pending_arch)
 
422
                {
 
423
                        for (curarch = 0; curarch < ARRAY_LENGTH(dasm_table); curarch++)
 
424
                                if (core_stricmp(curarg, dasm_table[curarch].name) == 0)
 
425
                                        break;
 
426
                        if (curarch == ARRAY_LENGTH(dasm_table))
 
427
                                goto usage;
 
428
                        opts->dasm = &dasm_table[curarch];
 
429
                        pending_arch = FALSE;
 
430
                }
 
431
 
 
432
                // filename
 
433
                else if (opts->filename == NULL)
 
434
                        opts->filename = curarg;
 
435
 
 
436
                // fail
 
437
                else
 
438
                        goto usage;
 
439
        }
 
440
 
 
441
        // if we have a dangling option, error
 
442
        if (pending_base || pending_arch || pending_mode)
 
443
                goto usage;
 
444
 
 
445
        // if no file or no architecture, fail
 
446
        if (opts->filename == NULL || opts->dasm == NULL)
 
447
                goto usage;
 
448
        return 0;
 
449
 
 
450
usage:
 
451
        printf("Usage: %s <filename> -arch <architecture> [-basepc <pc>] \n", argv[0]);
 
452
        printf("   [-mode <n>] [-norawbytes] [-flipped] [-upper] [-lower]\n");
 
453
        printf("\n");
 
454
        printf("Supported architectures:");
 
455
        numrows = (ARRAY_LENGTH(dasm_table) + 6) / 7;
 
456
        for (curarch = 0; curarch < numrows * 7; curarch++)
 
457
        {
 
458
                int row = curarch / 7;
 
459
                int col = curarch % 7;
 
460
                int index = col * numrows + row;
 
461
                if (col == 0)
 
462
                        printf("\n  ");
 
463
                printf("%-11s", (index < ARRAY_LENGTH(dasm_table)) ? dasm_table[index].name : "");
 
464
        }
 
465
        printf("\n");
 
466
        return 1;
 
467
};
 
468
 
 
469
 
 
470
int main(int argc, char *argv[])
 
471
{
 
472
        file_error filerr;
 
473
        int displayendian;
 
474
        int displaychunk;
 
475
        UINT32 curbyte;
 
476
        UINT32 length;
 
477
        int maxchunks;
 
478
        UINT32 curpc;
 
479
        options opts;
 
480
        int numbytes;
 
481
        void *data;
 
482
        char *p;
 
483
 
 
484
        // parse options first
 
485
        if (parse_options(argc, argv, &opts))
 
486
                return 1;
 
487
 
 
488
        // load the file
 
489
        filerr = core_fload(opts.filename, &data, &length);
 
490
        if (filerr != FILERR_NONE)
 
491
        {
 
492
                fprintf(stderr, "Error opening file '%s'\n", opts.filename);
 
493
                return 1;
 
494
        }
 
495
 
 
496
        // precompute parameters
 
497
        displaychunk = (opts.dasm->display / 2) + 1;
 
498
        displayendian = opts.dasm->display % 2;
 
499
        switch (displaychunk)
 
500
        {
 
501
                case 1:         maxchunks = 6;  break;
 
502
                case 2:         maxchunks = 3;  break;
 
503
                default:        maxchunks = 1;  break;
 
504
        }
 
505
 
 
506
        // run it
 
507
        curpc = opts.basepc;
 
508
        for (curbyte = 0; curbyte < length; curbyte += numbytes)
 
509
        {
 
510
                UINT8 *oprom = (UINT8 *)data + curbyte;
 
511
                char buffer[1024];
 
512
                UINT32 pcdelta;
 
513
                int numchunks;
 
514
 
 
515
                // disassemble
 
516
                pcdelta = (*opts.dasm->func)(NULL, buffer, curpc, oprom, oprom, opts.mode) & DASMFLAG_LENGTHMASK;
 
517
                if (opts.dasm->pcshift < 0)
 
518
                        numbytes = pcdelta << -opts.dasm->pcshift;
 
519
                else
 
520
                        numbytes = pcdelta >> opts.dasm->pcshift;
 
521
 
 
522
                // force upper or lower
 
523
                if (opts.lower)
 
524
                {
 
525
                        for (p = buffer; *p != 0; p++)
 
526
                                *p = tolower((UINT8)*p);
 
527
                }
 
528
                else if (opts.upper)
 
529
                {
 
530
                        for (p = buffer; *p != 0; p++)
 
531
                                *p = toupper((UINT8)*p);
 
532
                }
 
533
 
 
534
                // round to the nearest display chunk
 
535
                numbytes = ((numbytes + displaychunk - 1) / displaychunk) * displaychunk;
 
536
                if (numbytes == 0)
 
537
                        numbytes = displaychunk;
 
538
                numchunks = numbytes / displaychunk;
 
539
 
 
540
                // non-flipped case
 
541
                if (!opts.flipped)
 
542
                {
 
543
                        // output the address
 
544
                        printf("%08X: ", curpc);
 
545
 
 
546
                        // output the raw bytes
 
547
                        if (!opts.norawbytes)
 
548
                        {
 
549
                                int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks;
 
550
                                int chunknum, bytenum;
 
551
                                for (chunknum = 0; chunknum < firstchunks; chunknum++)
 
552
                                {
 
553
                                        for (bytenum = 0; bytenum < displaychunk; bytenum++)
 
554
                                                printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]);
 
555
                                        printf(" ");
 
556
                                        oprom += displaychunk;
 
557
                                }
 
558
                                for ( ; chunknum < maxchunks; chunknum++)
 
559
                                        printf("%*s ", displaychunk * 2, "");
 
560
                                printf(" ");
 
561
                        }
 
562
 
 
563
                        // output the disassembly
 
564
                        printf("%s\n", buffer);
 
565
 
 
566
                        // output additional raw bytes
 
567
                        if (!opts.norawbytes && numchunks > maxchunks)
 
568
                        {
 
569
                                for (numchunks -= maxchunks; numchunks > 0; numchunks -= maxchunks)
 
570
                                {
 
571
                                        int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks;
 
572
                                        int chunknum, bytenum;
 
573
                                        printf("          ");
 
574
                                        for (chunknum = 0; chunknum < firstchunks; chunknum++)
 
575
                                        {
 
576
                                                for (bytenum = 0; bytenum < displaychunk; bytenum++)
 
577
                                                        printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]);
 
578
                                                printf(" ");
 
579
                                                oprom += displaychunk;
 
580
                                        }
 
581
                                        printf("\n");
 
582
                                }
 
583
                        }
 
584
                }
 
585
 
 
586
                // flipped case
 
587
                else
 
588
                {
 
589
                        // output the disassembly and address
 
590
                        printf("\t%-40s ; %08X", buffer, curpc);
 
591
 
 
592
                        // output the raw bytes
 
593
                        if (!opts.norawbytes)
 
594
                        {
 
595
                                int chunknum, bytenum;
 
596
                                printf(": ");
 
597
                                for (chunknum = 0; chunknum < numchunks; chunknum++)
 
598
                                {
 
599
                                        for (bytenum = 0; bytenum < displaychunk; bytenum++)
 
600
                                                printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]);
 
601
                                        printf(" ");
 
602
                                        oprom += displaychunk;
 
603
                                }
 
604
                        }
 
605
                        printf("\n");
 
606
                }
 
607
 
 
608
                // advance
 
609
                curpc += pcdelta;
 
610
        }
 
611
 
 
612
        return 0;
 
613
}