]> cloudbase.mooo.com Git - z180-stamp.git/blobdiff - avr/cmd_mem.c
new command: dissassemle - Disassemble Z180 code from memory
[z180-stamp.git] / avr / cmd_mem.c
index 3e187701bb19e66968dc49caadbcd1186fe409df..85b5a44b1b149beca230c674cab2d98bf2dc600d 100644 (file)
@@ -23,6 +23,7 @@
 #include "eval_arg.h"
 #include "timer.h"
 #include "z80-if.h"
+#include "disas_z180.h"
 #include "debug.h"
 
 
@@ -33,6 +34,7 @@
 /* Display values from last command.
  * Memory modify remembered values are different from display memory.
  */
+static uint32_t        disas_last_addr;
 static uint32_t        dp_last_addr;
 static uint32_t        dp_last_length = 0x100;
 static uint32_t        mm_last_addr;
@@ -66,6 +68,52 @@ command_ret_t do_mem_size(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
        return CMD_RET_SUCCESS;
 }
 
+/*
+* Disassemble code from memory
+*
+* Usage:
+*      disassemble address [# of lines]
+*
+ */
+command_ret_t do_disas(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * const argv[])
+{
+       (void) cmdtp;
+
+       /* We use the last specified parameters, unless new ones are
+        * entered.
+        */
+       uint32_t addr = disas_last_addr;
+       int length = 16;
+       int ret = CMD_RET_SUCCESS;
+
+       if (argc < 2)
+               return CMD_RET_USAGE;
+
+       if ((flag & CMD_FLAG_REPEAT) == 0) {
+               /* Address is specified since argc > 1 */
+               addr = eval_arg(argv[1], NULL);
+               addr += base_address;
+
+               /* If another parameter, it is the length (Number of lines) to display. */
+               if (argc > 2)
+                       length = (int) eval_arg(argv[2], NULL);
+       }
+
+       z80_bus_request_or_exit();
+       clear_ctrlc();                                  /* forget any previous Control-C */
+       for (; length > 0; --length) {
+               addr = dis_decode(addr);
+               if (had_ctrlc() || ctrlc()) {
+                       ret = CMD_RET_FAILURE;
+                       break;
+               }
+       }
+       z80_bus_cmd(Release);
+       disas_last_addr = addr;
+
+       return ret;
+}
+
 /* Memory Display
  *
  * Syntax: