X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/1e5609bf0dfb390b0d62651cbd979e0ee21184fe..64db7d7a152ab5677faf83a4ea8370019993b1b5:/avr/cmd_mem.c?ds=sidebyside diff --git a/avr/cmd_mem.c b/avr/cmd_mem.c index d641410..85b5a44 100644 --- a/avr/cmd_mem.c +++ b/avr/cmd_mem.c @@ -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: @@ -204,9 +252,6 @@ command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * co (void) cmdtp; (void) flag; - /* reset getopt() */ - optind = 0; - int opt; while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1) { switch (opt) { @@ -261,7 +306,6 @@ command_ret_t do_mem_mdc ( cmd_tbl_t *cmdtp, uint_fast8_t flag, int argc, char * (void) cmdtp; (void) flag; - optind = 0; if (argv[0][1] != 'd') { int opt; while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1)