diff --git a/mini-asm.md b/mini-asm.md new file mode 100644 index 0000000..1b5e953 --- /dev/null +++ b/mini-asm.md @@ -0,0 +1,43 @@ +GS+ Pro Extreme Max HD Performance Edition includes a sweet-16 mini assembler as well as a 65816 mini assembler. + +## Sweet-16 +From the Debug shell, enter `!!` to enter the sweet-16 mini asembler. + +Enter `^D` or a blank line to exit back to the debug shell. + +Lines consist of an optional address, an opcode, and operands. + +All numbers are hexadecimal. +The `*` operand is the current address/PC. +/- offsets may also be applied. + +Registers are named `R0`-`R15` (decimal). `ACC`, `PC` and `SR` aliases are also valid for `R0`, `R15`, and `R14`, respectively. + +### Examples + +0300: set R1, #0300 + ld @R1 + br *-3 + +## 65816 +From the Debug shell, enter `!` to enter the sweet-16 mini asembler. + +Enter `^D` or a blank line to exit back to the debug shell. + +Lines consist of an optional address, an opcode, and operands. + +All numbers are hexadecimal. +The `*` operand is the current address/PC. +/- offsets may also be applied. + +The M/X bits are automatically set via `REP`/`SEP` instructions. Additionally, the `long` and `short` directives +may be used to set them explicitly. + + long mx + short m + +Toolbox, GS/OS, ProDOS-16, and P8 MLI macros are auto generated from the NiftyList.Data file. + + _NewHandle + _OpenGS 123456 + + + diff --git a/src/debug_shell.re2c b/src/debug_shell.re2c index ac24bfd..1507225 100644 --- a/src/debug_shell.re2c +++ b/src/debug_shell.re2c @@ -50,7 +50,7 @@ static int g_templates_loaded = 0; extern void debug_load_templates(const char *path); extern word32 debug_apply_template(word32 address, const char *name); extern void debug_load_nifty(const char *path); -extern const char *debug_tool_name(unsigned, unsigned vector); +extern const char *debug_tool_name(unsigned number, unsigned vector, unsigned full); @@ -240,6 +240,57 @@ static void do_handle(word32 value, int action) { } +word32 tool_lookup(unsigned tool) { + enum { + TPtr = 0xe103c0, + UTPtr = 0xe103c4, + }; + + unsigned tn = tool & 0xff; + unsigned ix = (tool >> 8) & 0xff; + word32 ptr; + word32 count; + + ptr = get_memory32_c(TPtr, 0); + if (ptr == 0 || ptr > 0xffffff) return 0; + + count = get_memory32_c(ptr, 0); + if (count == 0 || count > 255 || count < tn) return 0; + ptr = get_memory32_c(ptr + tn * 4, 0); + if (ptr == 0 || ptr > 0xffffff) return 0; + + count = get_memory32_c(ptr, 0); + if (count == 0 || count > 255) return 0; + if (ix && ix > count) return 0; + + /* if ix == 0, list all tool calls in the set */ + /* otherwise, just the specific tool call */ + + /* todo -- also lookup tool name */ + word32 addr = 0; + const char *cp; + if (ix) { + unsigned n = tn + (ix << 8); + addr = get_memory24_c(ptr + ix * 4, 0); + if (addr) ++addr; + cp = debug_tool_name(n, 0xe10000, 1); + if (!cp) cp = "---unknown---"; + printf("%04x (%06x) %s\n", n, addr, cp); + } else { + for(ix = 1; ix < count; ++ix) { + unsigned n = tn + (ix << 8); + + addr = get_memory24_c(ptr + ix * 4, 0); + if (addr) ++addr; + cp = debug_tool_name(n, 0xe10000, 1); + if (!cp) cp = "---unknown---"; + printf("%04x (%06x) %s\n", n, addr, cp); + } + } + + return addr; +} + word32 do_hexdump(word32 address, int lines) { static char hex[] = "0123456789abcdef"; @@ -624,7 +675,7 @@ word32 do_list(word32 address, int lines) { if (!comment) { bank = pc >> 16; if (bank == 0xe0 || bank == 0xe1 || bank == 0x01 || bank == 0xff) - comment = debug_tool_name(pc & 0xffff, bank); + comment = debug_tool_name(pc & 0xffff, bank, 1); } switch (opcode) { @@ -640,7 +691,7 @@ word32 do_list(word32 address, int lines) { case 0xa2: /* ldx # */ if (is_jsl_e10000(address)) { /* tool call ... */ - const char *name = debug_tool_name(operand, 0xe10000); + const char *name = debug_tool_name(operand, 0xe10000, 0); if (name) { opcode_string = name; buffer[0] = 0; @@ -668,7 +719,7 @@ word32 do_list(word32 address, int lines) { if (operand == 0xe100a8) { /* inline GS/OS call? */ unsigned num = get_memory16_c(address, 0); - const char *name = debug_tool_name(num, operand); + const char *name = debug_tool_name(num, operand, 0); if (name) { comment = NULL; opcode_string = name; @@ -685,7 +736,7 @@ word32 do_list(word32 address, int lines) { ea = (operand | (address & 0xff0000)); if (ea == 0x00bf00) { unsigned num = get_memory_c(address, 0); - const char *name = debug_tool_name(num, operand); + const char *name = debug_tool_name(num, operand, 0); if (name) { opcode_string = name; unsigned parms = get_memory16_c(address + 1, 0); @@ -1666,6 +1717,11 @@ command: return 0; } + "t" { + g_prev_address = tool_lookup(addr & 0xffff); + return 0; + } + */ } diff --git a/src/debug_template.re2c b/src/debug_template.re2c index 80fb97d..350e004 100644 --- a/src/debug_template.re2c +++ b/src/debug_template.re2c @@ -401,6 +401,7 @@ word32 debug_apply_template(word32 address, const char *name) { struct tool { char *name; + char *fullname; unsigned number; unsigned vector; }; @@ -426,6 +427,7 @@ static void add_tool(struct tool *t) { tools[tool_count++] = *t; } + static word32 to_hex(const char *iter, const char *end) { word32 rv = 0; while(iter != end) { @@ -513,7 +515,7 @@ void debug_load_nifty(const char *path) { for (line = 1;;++line) { const char *start; const char *end; - struct tool tool = { 0, 0, vector }; + struct tool tool = { 0, 0, 0, vector }; const char *cp = fgets(buffer, sizeof(buffer), f); if (!cp) break; @@ -566,12 +568,15 @@ prefix: if (end > start) { int l = end - start; + + tool.fullname = NULL; if (vector > 0x0100) { /* add a leading _ */ tool.name = malloc(l + 2); tool.name[0] = '_'; strncpy(tool.name + 1, start, l); tool.name[l + 1] = 0; + tool.fullname = strdup(start); } else tool.name = strndup(start, l); add_tool(&tool); @@ -606,14 +611,15 @@ prefix: qsort(tool_names, tool_name_count, sizeof(struct tool), tool_name_compare); } -const char *debug_tool_name(unsigned number, unsigned vector) { +const char *debug_tool_name(unsigned number, unsigned vector, unsigned full) { if (!tool_count) return NULL; - struct tool tmp = { 0, number, vector }; + struct tool tmp = { 0, 0, number, vector }; struct tool *t = bsearch(&tmp, tools, tool_count, sizeof(struct tool), tool_compare); - if (t) return t->name; - return NULL; + if (!t) return NULL; + if (full && t->fullname) return t->fullname; + return t->name; } @@ -621,9 +627,8 @@ int lookup_tool_number(const char *name, unsigned vector) { if (!tool_name_count) return 0; - struct tool tmp = { (char *)name, 0, vector}; + struct tool tmp = { (char *)name, 0, 0, vector}; struct tool *t = bsearch(&tmp, tool_names, tool_name_count, sizeof(struct tool), tool_name_compare); if (!t) return 0; return t->number; } -