Make unidasm compile and link again. Make exception-aware (hopefully).

Note kludge of defining osd_break_into_debugger() since it is referenced from emu_fatalerror.
This commit is contained in:
Paul Priest 2010-01-06 12:37:59 +00:00
parent 40b9b17009
commit fb8599a36c

View File

@ -39,7 +39,7 @@
#include "cpuintrf.h" #include "cpuintrf.h"
#include <ctype.h> #include <ctype.h>
#include <iostream>
enum _display_type enum _display_type
{ {
@ -335,16 +335,9 @@ static const dasm_table_entry dasm_table[] =
}; };
void CLIB_DECL fatalerror(const char *text, ...) void osd_break_into_debugger(const char *text)
{ {
va_list arg; /* we don't have a complete debugger to break in */
/* dump to the buffer; assume no one writes >2k lines this way */
va_start(arg, text);
vfprintf(stderr, text, arg);
va_end(arg);
exit(1);
} }
@ -486,6 +479,7 @@ int main(int argc, char *argv[])
int numbytes; int numbytes;
void *data; void *data;
char *p; char *p;
int result = 0;
// parse options first // parse options first
if (parse_options(argc, argv, &opts)) if (parse_options(argc, argv, &opts))
@ -510,73 +504,53 @@ int main(int argc, char *argv[])
} }
// run it // run it
curpc = opts.basepc; try
for (curbyte = 0; curbyte < length; curbyte += numbytes)
{ {
UINT8 *oprom = (UINT8 *)data + curbyte; curpc = opts.basepc;
char buffer[1024]; for (curbyte = 0; curbyte < length; curbyte += numbytes)
UINT32 pcdelta;
int numchunks;
// disassemble
pcdelta = (*opts.dasm->func)(NULL, buffer, curpc, oprom, oprom, opts.mode) & DASMFLAG_LENGTHMASK;
if (opts.dasm->pcshift < 0)
numbytes = pcdelta << -opts.dasm->pcshift;
else
numbytes = pcdelta >> opts.dasm->pcshift;
// force upper or lower
if (opts.lower)
{ {
for (p = buffer; *p != 0; p++) UINT8 *oprom = (UINT8 *)data + curbyte;
*p = tolower((UINT8)*p); char buffer[1024];
} UINT32 pcdelta;
else if (opts.upper) int numchunks;
{
for (p = buffer; *p != 0; p++)
*p = toupper((UINT8)*p);
}
// round to the nearest display chunk // disassemble
numbytes = ((numbytes + displaychunk - 1) / displaychunk) * displaychunk; pcdelta = (*opts.dasm->func)(NULL, buffer, curpc, oprom, oprom, opts.mode) & DASMFLAG_LENGTHMASK;
if (numbytes == 0)
numbytes = displaychunk;
numchunks = numbytes / displaychunk;
// non-flipped case if (opts.dasm->pcshift < 0)
if (!opts.flipped) numbytes = pcdelta << -opts.dasm->pcshift;
{ else
// output the address numbytes = pcdelta >> opts.dasm->pcshift;
printf("%08X: ", curpc);
// output the raw bytes // force upper or lower
if (!opts.norawbytes) if (opts.lower)
{ {
int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks; for (p = buffer; *p != 0; p++)
int chunknum, bytenum; *p = tolower((UINT8)*p);
for (chunknum = 0; chunknum < firstchunks; chunknum++) }
{ else if (opts.upper)
for (bytenum = 0; bytenum < displaychunk; bytenum++) {
printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]); for (p = buffer; *p != 0; p++)
printf(" "); *p = toupper((UINT8)*p);
oprom += displaychunk;
}
for ( ; chunknum < maxchunks; chunknum++)
printf("%*s ", displaychunk * 2, "");
printf(" ");
} }
// output the disassembly // round to the nearest display chunk
printf("%s\n", buffer); numbytes = ((numbytes + displaychunk - 1) / displaychunk) * displaychunk;
if (numbytes == 0)
numbytes = displaychunk;
numchunks = numbytes / displaychunk;
// output additional raw bytes // non-flipped case
if (!opts.norawbytes && numchunks > maxchunks) if (!opts.flipped)
{ {
for (numchunks -= maxchunks; numchunks > 0; numchunks -= maxchunks) // output the address
printf("%08X: ", curpc);
// output the raw bytes
if (!opts.norawbytes)
{ {
int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks; int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks;
int chunknum, bytenum; int chunknum, bytenum;
printf(" ");
for (chunknum = 0; chunknum < firstchunks; chunknum++) for (chunknum = 0; chunknum < firstchunks; chunknum++)
{ {
for (bytenum = 0; bytenum < displaychunk; bytenum++) for (bytenum = 0; bytenum < displaychunk; bytenum++)
@ -584,36 +558,78 @@ int main(int argc, char *argv[])
printf(" "); printf(" ");
oprom += displaychunk; oprom += displaychunk;
} }
printf("\n"); for ( ; chunknum < maxchunks; chunknum++)
} printf("%*s ", displaychunk * 2, "");
}
}
// flipped case
else
{
// output the disassembly and address
printf("\t%-40s ; %08X", buffer, curpc);
// output the raw bytes
if (!opts.norawbytes)
{
int chunknum, bytenum;
printf(": ");
for (chunknum = 0; chunknum < numchunks; chunknum++)
{
for (bytenum = 0; bytenum < displaychunk; bytenum++)
printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]);
printf(" "); printf(" ");
oprom += displaychunk; }
// output the disassembly
printf("%s\n", buffer);
// output additional raw bytes
if (!opts.norawbytes && numchunks > maxchunks)
{
for (numchunks -= maxchunks; numchunks > 0; numchunks -= maxchunks)
{
int firstchunks = (numchunks < maxchunks) ? numchunks : maxchunks;
int chunknum, bytenum;
printf(" ");
for (chunknum = 0; chunknum < firstchunks; chunknum++)
{
for (bytenum = 0; bytenum < displaychunk; bytenum++)
printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]);
printf(" ");
oprom += displaychunk;
}
printf("\n");
}
} }
} }
printf("\n");
}
// advance // flipped case
curpc += pcdelta; else
{
// output the disassembly and address
printf("\t%-40s ; %08X", buffer, curpc);
// output the raw bytes
if (!opts.norawbytes)
{
int chunknum, bytenum;
printf(": ");
for (chunknum = 0; chunknum < numchunks; chunknum++)
{
for (bytenum = 0; bytenum < displaychunk; bytenum++)
printf("%02X", oprom[displayendian ? (displaychunk - 1 - bytenum) : bytenum]);
printf(" ");
oprom += displaychunk;
}
}
printf("\n");
}
// advance
curpc += pcdelta;
}
}
catch (emu_fatalerror &fatal)
{
fprintf(stderr, "%s\n", fatal.string());
if (fatal.exitcode() != 0)
result = fatal.exitcode();
}
catch (emu_exception &exception)
{
fprintf(stderr, "Caught unhandled emulator exception\n");
}
catch (std::bad_alloc &)
{
fprintf(stderr, "Out of memory!\n");
}
catch (...)
{
fprintf(stderr, "Caught unhandled exception\n");
} }
return 0; return result;
} }