*/
#include "common.h"
-#include <stdlib.h>
#include <ctype.h>
#include <avr/interrupt.h>
#include "cli_readline.h"
#include "print-utils.h"
#include "con-utils.h"
+#include "getopt-min.h"
+#include "eval_arg.h"
#include "timer.h"
#include "z80-if.h"
#include "debug.h"
if ((flag & CMD_FLAG_REPEAT) == 0) {
/* Address is specified since argc > 1 */
- addr = strtoul(argv[1], NULL, 16);
+ addr = eval_arg(argv[1], NULL);
addr += base_address;
/* If another parameter, it is the length to display. */
if (argc > 2)
- length = strtoul(argv[2], NULL, 16);
+ length = eval_arg(argv[2], NULL);
}
/* Print the lines. */
/* Address is specified since argc > 1
*/
- addr = strtoul(argv[1], NULL, 16);
+ addr = eval_arg(argv[1], NULL);
addr += base_address;
}
} else {
char *endp;
- data = strtoul(console_buffer, &endp, 16);
+ data = eval_arg(console_buffer, &endp);
nbytes = endp - console_buffer;
if (nbytes) {
if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
addr++;
}
}
- } while (nbytes);
+ } while (nbytes > 0);
mm_last_addr = addr;
return CMD_RET_SUCCESS;
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;
+
+ /* reset getopt() */
+ optind = 0;
+
+ 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;
+ }
+ }
- if ((argc < 3) || (argc > 4))
+ /* 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 = eval_arg(argv[optind++], NULL);
addr += base_address;
-
- /* Get the value to write.
- */
- writeval = (uint8_t) strtoul(argv[2], NULL, 16);
+ writeval = eval_arg(argv[optind++], NULL);
/* Count ? */
- if (argc == 4) {
- count = strtoul(argv[3], NULL, 16);
- } else {
- count = 1;
- }
+ if (argc == 3)
+ count = eval_arg(argv[optind], NULL);
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;
(void) cmdtp;
(void) flag;
- if (argc < 4)
+ optind = 0;
+ if (argv[0][1] != 'd') {
+ int opt;
+ while ((opt = getopt(argc, argv, PSTR("bwl"))) != -1)
+ if (opt == '?')
+ return CMD_RET_USAGE;
+ --optind;
+ }
+
+ if (argc-optind != 4)
return CMD_RET_USAGE;
- count = strtoul(argv[3], NULL, 10);
+ count = eval_arg(argv[optind + 3], NULL);
clear_ctrlc(); /* forget any previous Control C */
for (;;) {
if (argv[0][1] == 'd')
- do_mem_md (NULL, 0, 3, argv);
+ do_mem_md (NULL, 0, argc-1, argv); /* memory display */
else
- do_mem_mw (NULL, 0, 3, argv);
+ do_mem_mw (NULL, 0, argc-1, argv); /* memory write */
/* delay for <count> ms... */
return CMD_RET_USAGE;
- addr1 = strtoul(argv[1], NULL, 16);
+ addr1 = eval_arg(argv[1], NULL);
addr1 += base_address;
- addr2 = strtoul(argv[2], NULL, 16);
+ addr2 = eval_arg(argv[2], NULL);
addr2 += base_address;
- count = strtoul(argv[3], NULL, 16);
+ count = eval_arg(argv[3], NULL);
for (ngood = 0; ngood < count; ++ngood) {
if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
if (argc != 4)
return CMD_RET_USAGE;
- src = strtoul(argv[1], NULL, 16);
+ src = eval_arg(argv[1], NULL);
src += base_address;
- dest = strtoul(argv[2], NULL, 16);
+ dest = eval_arg(argv[2], NULL);
dest += base_address;
- count = strtoul(argv[3], NULL, 16);
+ count = eval_arg(argv[3], NULL);
if (count == 0) {
my_puts_P(PSTR("Zero length?\n"));
if (argc > 1) {
/* Set new base address. */
- base_address = strtoul(argv[1], NULL, 16);
+ base_address = eval_arg(argv[1], NULL);
}
/* Print the current base address. */
printf_P(PSTR("Base Address: 0x%05lx\n"), base_address);
return CMD_RET_USAGE;
/* Address is always specified. */
- addr = strtoul(argv[1], NULL, 16);
+ addr = eval_arg(argv[1], NULL);
/* Length is the number of bytes. */
- length = strtoul(argv[2], NULL, 16);
+ length = eval_arg(argv[2], NULL);
/* We want to optimize the loops to run as fast as possible.
return CMD_RET_USAGE;
/* Address is always specified. */
- addr = strtoul(argv[1], NULL, 16);
+ addr = eval_arg(argv[1], NULL);
/* Length is the number of bytes. */
- length = strtoul(argv[2], NULL, 16);
+ length = eval_arg(argv[2], NULL);
- data = strtoul(argv[3], NULL, 16);
+ data = eval_arg(argv[3], NULL);
/*
* We want to optimize the loops to run as fast as possible.
(void) flag;
if (argc > 1)
- start = strtoul(argv[1], NULL, 16);
+ start = eval_arg(argv[1], NULL);
if (argc > 2)
- end = strtoul(argv[2], NULL, 16);
+ end = eval_arg(argv[2], NULL);
else
end = CONFIG_SYS_RAMSIZE_MAX - 1;
if (argc > 3)
- iteration_limit = (unsigned int) strtoul(argv[3], NULL, 16);
+ iteration_limit = (unsigned int) eval_arg(argv[3], NULL);
printf_P(PSTR("Testing %05lx ... %05lx:\n"), start, end);
// debug("## %s:%d: start %#05lx end %#05lx\n", __func__, __LINE__, start, end);