Firmware/CLI: add memory write commands (w8/w16)

This commit is contained in:
ikari 2011-10-16 13:46:59 +02:00
parent 1887036e86
commit 7dc5860b4d

View File

@ -58,8 +58,8 @@ static char *curchar;
/* Word lists */ /* Word lists */
static char command_words[] = static char command_words[] =
"cd\0reset\0sreset\0dir\0ls\0test\0resume\0loadrom\0loadraw\0saveraw\0put\0d4\0vmode\0mapper\0settime\0time\0setfeature\0hexdump\0"; "cd\0reset\0sreset\0dir\0ls\0test\0resume\0loadrom\0loadraw\0saveraw\0put\0d4\0vmode\0mapper\0settime\0time\0setfeature\0hexdump\0w8\0w16\0";
enum { CMD_CD = 0, CMD_RESET, CMD_SRESET, CMD_DIR, CMD_LS, CMD_TEST, CMD_RESUME, CMD_LOADROM, CMD_LOADRAW, CMD_SAVERAW, CMD_PUT, CMD_D4, CMD_VMODE, CMD_MAPPER, CMD_SETTIME, CMD_TIME, CMD_SETFEATURE, CMD_HEXDUMP }; enum { CMD_CD = 0, CMD_RESET, CMD_SRESET, CMD_DIR, CMD_LS, CMD_TEST, CMD_RESUME, CMD_LOADROM, CMD_LOADRAW, CMD_SAVERAW, CMD_PUT, CMD_D4, CMD_VMODE, CMD_MAPPER, CMD_SETTIME, CMD_TIME, CMD_SETFEATURE, CMD_HEXDUMP, CMD_W8, CMD_W16 };
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* Parse functions */ /* Parse functions */
@ -76,7 +76,7 @@ static uint8_t skip_spaces(void) {
} }
/* Parse the string in curchar for an integer with bounds [lower,upper] */ /* Parse the string in curchar for an integer with bounds [lower,upper] */
static int32_t parse_unsigned(uint32_t lower, uint32_t upper) { static int32_t parse_unsigned(uint32_t lower, uint32_t upper, uint8_t base) {
char *end; char *end;
uint32_t result; uint32_t result;
@ -85,7 +85,7 @@ static int32_t parse_unsigned(uint32_t lower, uint32_t upper) {
return -2; return -2;
} }
result = strtoul(curchar, &end, 10); result = strtoul(curchar, &end, base);
if ((*end != ' ' && *end != 0) || errno != 0) { if ((*end != ' ' && *end != 0) || errno != 0) {
printf("Invalid numeric argument\n"); printf("Invalid numeric argument\n");
return -1; return -1;
@ -287,13 +287,13 @@ static void cmd_loadrom(void) {
} }
static void cmd_loadraw(void) { static void cmd_loadraw(void) {
uint32_t address = parse_unsigned(0,16777216); uint32_t address = parse_unsigned(0,16777216,16);
load_sram((uint8_t*)curchar, address); load_sram((uint8_t*)curchar, address);
} }
static void cmd_saveraw(void) { static void cmd_saveraw(void) {
uint32_t address = parse_unsigned(0,16777216); uint32_t address = parse_unsigned(0,16777216,16);
uint32_t length = parse_unsigned(0,16777216); uint32_t length = parse_unsigned(0,16777216,16);
save_sram((uint8_t*)curchar, length, address); save_sram((uint8_t*)curchar, length, address);
} }
@ -303,7 +303,7 @@ static void cmd_d4(void) {
if(get_cic_state() != CIC_PAIR) { if(get_cic_state() != CIC_PAIR) {
printf("not in pair mode\n"); printf("not in pair mode\n");
} else { } else {
hz = parse_unsigned(50,60); hz = parse_unsigned(50,60,10);
if(hz==50) { if(hz==50) {
cic_d4(CIC_PAL); cic_d4(CIC_PAL);
} else { } else {
@ -318,7 +318,7 @@ static void cmd_vmode(void) {
if(get_cic_state() != CIC_PAIR) { if(get_cic_state() != CIC_PAIR) {
printf("not in pair mode\n"); printf("not in pair mode\n");
} else { } else {
hz = parse_unsigned(50,60); hz = parse_unsigned(50,60,10);
if(hz==50) { if(hz==50) {
cic_videomode(CIC_PAL); cic_videomode(CIC_PAL);
} else { } else {
@ -345,7 +345,7 @@ void cmd_put(void) {
void cmd_mapper(void) { void cmd_mapper(void) {
int32_t mapper; int32_t mapper;
mapper = parse_unsigned(0,7); mapper = parse_unsigned(0,7,10);
set_mapper((uint8_t)mapper & 0x7); set_mapper((uint8_t)mapper & 0x7);
printf("mapper set to %ld\n", mapper); printf("mapper set to %ld\n", mapper);
} }
@ -353,7 +353,7 @@ void cmd_mapper(void) {
void cmd_sreset(void) { void cmd_sreset(void) {
if(*curchar != 0) { if(*curchar != 0) {
int32_t resetstate; int32_t resetstate;
resetstate = parse_unsigned(0,1); resetstate = parse_unsigned(0,1,10);
snes_reset(resetstate); snes_reset(resetstate);
} else { } else {
snes_reset(1); snes_reset(1);
@ -389,15 +389,28 @@ void cmd_time(void) {
} }
void cmd_setfeature(void) { void cmd_setfeature(void) {
uint8_t feat = parse_unsigned(0, 255); uint8_t feat = parse_unsigned(0, 255, 16);
fpga_set_features(feat); fpga_set_features(feat);
} }
void cmd_hexdump(void) { void cmd_hexdump(void) {
uint32_t offset = parse_unsigned(0, 16777215); uint32_t offset = parse_unsigned(0, 16777215, 16);
uint32_t len = parse_unsigned(0, 16777216); uint32_t len = parse_unsigned(0, 16777216, 16);
sram_hexdump(offset, len); sram_hexdump(offset, len);
} }
void cmd_w8(void) {
uint32_t offset = parse_unsigned(0, 16777215, 16);
uint8_t val = parse_unsigned(0, 255, 16);
sram_writebyte(val, offset);
}
void cmd_w16(void) {
uint32_t offset = parse_unsigned(0, 16777215, 16);
uint16_t val = parse_unsigned(0, 65535, 16);
sram_writeshort(val, offset);
}
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* CLI interface functions */ /* CLI interface functions */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
@ -531,6 +544,15 @@ void cli_loop(void) {
case CMD_HEXDUMP: case CMD_HEXDUMP:
cmd_hexdump(); cmd_hexdump();
break; break;
case CMD_W8:
cmd_w8();
break;
case CMD_W16:
cmd_w16();
break;
} }
} }
} }