-
-/* Modify memory.
- *
- * Syntax:
- * mm {addr}
- * nm {addr}
- */
-static int
-mod_mem(cmd_tbl_t *cmdtp, int incrflag, int flag, int argc, char * const argv[])
-{
- uint32_t addr;
- uint8_t data;
- int nbytes;
-
- (void) cmdtp;
-
- if (argc != 2)
- return CMD_RET_USAGE;
-
- /* We use the last specified parameters, unless new ones are
- * entered.
- */
- addr = mm_last_addr;
-
- if ((flag & CMD_FLAG_REPEAT) == 0) {
- /* New command specified.
- */
-
- /* Address is specified since argc > 1
- */
- addr = strtoul(argv[1], NULL, 16);
- addr += base_address;
- }
-
- /* Print the address, followed by value. Then accept input for
- * the next value. A non-converted value exits.
- */
- do {
- zstate_t state = z80_request_bus_save();
- data = z80_read(addr);
- printf("%05lx: %02x", addr, data);
- z80_release_bus_save(state);
-
- nbytes = cli_readline(PSTR(" ? "));
- if (nbytes == 0 || (nbytes == 1 && console_buffer[0] == '-')) {
- /* <CR> pressed as only input, don't modify current
- * location and move to next. "-" pressed will go back.
- */
- if (incrflag)
- addr += nbytes ? -1 : 1;
- nbytes = 1;
- }
- else {
- char *endp;
- data = strtoul(console_buffer, &endp, 16);
- nbytes = endp - console_buffer;
- if (nbytes) {
- zstate_t state = z80_request_bus_save();
- z80_write(addr, data);
- z80_release_bus_save(state);
- if (incrflag)
- addr++;
- }
- }
- } while (nbytes);
-
- mm_last_addr = addr;
- return 0;
-}
-