summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/unidasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/unidasm.c')
-rw-r--r--src/tools/unidasm.c31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/tools/unidasm.c b/src/tools/unidasm.c
index 1326266c4de..8884d664d96 100644
--- a/src/tools/unidasm.c
+++ b/src/tools/unidasm.c
@@ -53,6 +53,7 @@ struct _options
UINT8 norawbytes;
UINT8 lower;
UINT8 upper;
+ int mode;
const dasm_table_entry *dasm;
};
@@ -329,6 +330,7 @@ int parse_options(int argc, char *argv[], options *opts)
{
int pending_base = FALSE;
int pending_arch = FALSE;
+ int pending_mode = FALSE;
int curarch;
int numrows;
int arg;
@@ -343,7 +345,7 @@ int parse_options(int argc, char *argv[], options *opts)
// is it a switch?
if (curarg[0] == '-')
{
- if (pending_base || pending_arch)
+ if (pending_base || pending_arch || pending_mode)
goto usage;
if (tolower((UINT8)curarg[1]) == 'a')
@@ -352,6 +354,8 @@ int parse_options(int argc, char *argv[], options *opts)
pending_base = TRUE;
else if (tolower((UINT8)curarg[1]) == 'l')
opts->lower = TRUE;
+ else if (tolower((UINT8)curarg[1]) == 'm')
+ pending_mode = TRUE;
else if (tolower((UINT8)curarg[1]) == 'n')
opts->norawbytes = TRUE;
else if (tolower((UINT8)curarg[1]) == 'u')
@@ -363,15 +367,26 @@ int parse_options(int argc, char *argv[], options *opts)
// base PC
else if (pending_base)
{
+ int result;
if (curarg[0] == '0' && curarg[1] == 'x')
- sscanf(&curarg[2], "%x", &opts->basepc);
+ result = sscanf(&curarg[2], "%x", &opts->basepc);
else if (curarg[0] == '$')
- sscanf(&curarg[1], "%x", &opts->basepc);
+ result = sscanf(&curarg[1], "%x", &opts->basepc);
else
- sscanf(&curarg[0], "%x", &opts->basepc);
+ result = sscanf(&curarg[0], "%x", &opts->basepc);
+ if (result != 1)
+ goto usage;
pending_base = FALSE;
}
+ // mode
+ else if (pending_mode)
+ {
+ if (sscanf(curarg, "%d", &opts->mode) != 1)
+ goto usage;
+ pending_mode = FALSE;
+ }
+
// architecture
else if (pending_arch)
{
@@ -393,13 +408,17 @@ int parse_options(int argc, char *argv[], options *opts)
goto usage;
}
+ // if we have a dangling option, error
+ if (pending_base || pending_arch || pending_mode)
+ goto usage;
+
// if no file or no architecture, fail
if (opts->filename == NULL || opts->dasm == NULL)
goto usage;
return 0;
usage:
- printf("Usage: %s <filename> -arch <architecture> [-basepc <pc>] [-norawbytes] [-upper] [-lower]\n", argv[0]);
+ printf("Usage: %s <filename> -arch <architecture> [-basepc <pc>] [-mode <n>] [-norawbytes] [-upper] [-lower]\n", argv[0]);
printf("\n");
printf("Supported architectures:");
numrows = (ARRAY_LENGTH(dasm_table) + 6) / 7;
@@ -463,7 +482,7 @@ int main(int argc, char *argv[])
int numchunks;
// disassemble
- pcdelta = (*opts.dasm->func)(NULL, buffer, curpc, oprom, oprom) & DASMFLAG_LENGTHMASK;
+ pcdelta = (*opts.dasm->func)(NULL, buffer, curpc, oprom, oprom, opts.mode) & DASMFLAG_LENGTHMASK;
if (opts.dasm->pcshift < 0)
numbytes = pcdelta << -opts.dasm->pcshift;
else