]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
mw command: add word and longword options
authorLeo C <erbl259-lmu@yahoo.de>
Mon, 23 May 2016 09:23:12 +0000 (11:23 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Mon, 23 May 2016 09:23:12 +0000 (11:23 +0200)
avr/cmd_mem.c
avr/command_tbl.c

index a725c612056b956fb68a05121abba015fc9a7b68..9adee72e7cace6501cf89341c083df8010b5970d 100644 (file)
@@ -22,6 +22,7 @@
 #include "cli_readline.h"
 #include "print-utils.h"
 #include "con-utils.h"
+#include "getopt-min.h"
 #include "timer.h"
 #include "z80-if.h"
 #include "debug.h"
@@ -193,36 +194,60 @@ command_ret_t do_mem_nm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[
 
 command_ret_t do_mem_mw(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       uint8_t writeval;
-       uint32_t addr, count;
+       uint32_t writeval;
+       uint32_t addr;
+       uint32_t count = 1;
+       uint_fast8_t width = 1;
 
-       (void) cmdtp;
-       (void) flag;
+       (void) cmdtp; (void) flag;
 
-       if ((argc < 3) || (argc > 4))
+       /* reset getopt() */
+       optind = 1;
+
+       int opt;
+       while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1) {
+               switch (opt) {
+               case 'b':
+                       width = 1;
+                       break;
+               case 'w':
+                       width = 2;
+                       break;
+               case 'l':
+                       width = 4;
+                       break;
+               default: /* '?' */
+                       return CMD_RET_USAGE;
+               }
+       }
+
+       /* remaining arguments */
+       argc -= optind;
+       if ((argc < 2) || (argc > 3))
                return CMD_RET_USAGE;
 
-       /* Address is specified since argc > 1
-       */
-       addr = strtoul(argv[1], NULL, 16);
+       /* Address and value are specified since (adjusted) argc >= 2 */
+       addr = strtoul(argv[optind++], NULL, 16);
        addr += base_address;
-
-       /* Get the value to write.
-       */
-       writeval = (uint8_t) strtoul(argv[2], NULL, 16);
+       writeval = strtoul(argv[optind++], NULL, 16);
 
        /* Count ? */
-       if (argc == 4) {
-               count = strtoul(argv[3], NULL, 16);
-       } else {
-               count = 1;
-       }
+       if (argc == 3)
+               count = strtoul(argv[optind], NULL, 16);
 
        if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
                my_puts_P(PSTR("Bus timeout\n"));
                return  CMD_RET_FAILURE;
        }
-       z80_memset(addr, writeval, count);
+
+       if (width == 1)
+               z80_memset(addr, writeval, count);
+       else {
+               while (count--) {
+                       z80_write_block((const uint8_t *) &writeval, addr, width);
+                       addr += width;
+               }
+       }
        z80_bus_cmd(Release);
 
        return CMD_RET_SUCCESS;
index 1731b833ff8678f0d0154936526c4a3e6eae14ad..2c9135502ae5b66c0fcd64ffb1d64bb9fb2c323a 100644 (file)
@@ -98,8 +98,8 @@ CMD_TBL_ITEM(
        echo,   CONFIG_SYS_MAXARGS,     1,      do_echo,
        "display a line of text",
        "[-n] [argument ...]\n"
-       "     - echo the argument(s) to console.\n"
-       "       -n  do not output the trailing newline"
+       "- echo the argument(s) to console.\n"
+       "  -n  do not output the trailing newline"
 ),
 CMD_TBL_ITEM(
        sleep ,    2,    1,     do_sleep,
@@ -249,9 +249,12 @@ CMD_TBL_ITEM(
        "address"
 ),
 CMD_TBL_ITEM(
-       mw,     4,      1,      do_mem_mw,
+       mw,     CONFIG_SYS_MAXARGS,     1,      do_mem_mw,
        "memory write (fill)",
-       "address value [count]"
+       "[-bwl] address value [count]\n"
+       "   -b  write value as byte (8 bit, default)\n"
+       "   -w  write value as word (16 bit)\n"
+       "   -l  write value as long (32 bit)\n"
 ),
 CMD_TBL_ITEM(
        cp,     4,      1,      do_mem_cp,