From: Hugo Villeneuve Date: Thu, 6 Feb 2014 03:24:19 +0000 (-0500) Subject: Allow to set all SFR registers in CLI version X-Git-Tag: v2.0.1~27 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=7c267c5882bec6fc37b52009b2ae27b63c93c13a;p=emu8051.git Allow to set all SFR registers in CLI version --- diff --git a/src/cli/menu.c b/src/cli/menu.c index 478fe2b..d57cbb1 100644 --- a/src/cli/menu.c +++ b/src/cli/menu.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "common.h" #include "cpu8051.h" @@ -90,22 +91,34 @@ DisasmN(unsigned int Address, int NumberInst) } } +/* Capitalize all letters in buffer */ +static void +Capitalize(char *buffer) +{ + size_t k; + + for (k = 0; k < strlen(buffer); k++) + buffer[k] = toupper(buffer[k]); +} + /* Set NewValue to Register */ void -SetRegister(char *Register, int NewValue) +SetRegister(char *register_name, int new) { - if (STREQ(Register, "PC")) - cpu8051.pc = NewValue; - else if (STREQ(Register, "A")) - cpu8051_WriteD(_ACC_, NewValue); - else if (STREQ(Register, "B")) - cpu8051_WriteD(_B_, NewValue); - else if (STREQ(Register, "SP")) - cpu8051_WriteD(_SP_, NewValue); - else { - printf("\nInvalid register name!\n"); - printf("Valid registers are A, B, PC and SP.\n"); + struct regwin_infos_t *regwin_infos; + + Capitalize(register_name); + + log_debug(" Modify register %s to $%04X", register_name, new); + + regwin_infos = sfr_get_infos(register_name); + + if (regwin_infos == NULL) { + printf("Invalid register name\n"); + return; } + + regwin_write(regwin_infos, new); } /* CPU reset and Console UI update */ diff --git a/src/cli/parser.y b/src/cli/parser.y index 00338b3..1cb282c 100644 --- a/src/cli/parser.y +++ b/src/cli/parser.y @@ -18,16 +18,23 @@ int yylex(); int yyerror(const char *str) { - fprintf(stderr,"error: %s\n", str); + fprintf(stderr,"error: %s\n", str); return 0; } %} -%token NUMBER TOK_ENTER TOK_ALL +%union +{ + int number; + char *string; +} + +%token NUMBER +%token WORD +%token TOK_ENTER TOK_ALL %token TOK_SB TOK_RB TOK_DB %token TOK_DE TOK_DI TOK_DP TOK_DR -%token TOK_PC %token TOK_HELP %token TOK_RUN %token TOK_RST TOK_RST_TIMER @@ -49,19 +56,13 @@ start : start command { menu_prompt(); } ; command: - pc_set - | breakpoint_clr | breakpoint_set | breakpoint_display | - dump_ext_mem - | - dump_int_mem - | - dump_prog_mem + dump_mem | display_regs | @@ -103,7 +104,7 @@ breakpoint_clr: breakpoint_set: TOK_SB TOK_ENTER { - log_debug(" Set breakpoint at current PC"); + log_debug(" Set breakpoint at PC"); SetBreakpoint(cpu8051.pc); } | @@ -123,23 +124,19 @@ breakpoint_display: } ; -dump_ext_mem: +dump_mem: TOK_DE NUMBER NUMBER TOK_ENTER { log_debug(" Dump External Data Memory at $%04X, len %d", $2, $3); DumpMem($2, $3, EXT_MEM_ID); } - ; - -dump_int_mem: + | TOK_DI NUMBER NUMBER TOK_ENTER { log_debug(" Dump Internal Data Memory at $%04X, len %d", $2, $3); DumpMem($2, $3, INT_MEM_ID); } - ; - -dump_prog_mem: + | TOK_DP NUMBER NUMBER TOK_ENTER { log_debug(" Dump Program Memory at $%04X, len %d", $2, $3); @@ -174,10 +171,9 @@ modify: memory_write8(PGM_MEM_ID, $2, $3); } | - TOK_MOD_REG "pc" NUMBER TOK_ENTER + TOK_MOD_REG WORD NUMBER TOK_ENTER { - log_debug(" Modify register"); - SetRegister("PC", $2); + SetRegister($2, $3); } ; @@ -203,13 +199,6 @@ run: } ; -pc_set: - TOK_PC NUMBER TOK_ENTER - { - cpu8051.pc = $2; - } - ; - help: TOK_HELP TOK_ENTER { diff --git a/src/cli/scanner.l b/src/cli/scanner.l index 757376e..2839f83 100644 --- a/src/cli/scanner.l +++ b/src/cli/scanner.l @@ -3,9 +3,10 @@ %option nounput %{ #include "parser.h" + #include "hexfile.h" %} %% -[0-9]+ { yylval = atoi(yytext); return NUMBER;} +[0-9]+ { yylval.number = asciihex2int(yytext); return NUMBER; } [h?] return TOK_HELP; sb return TOK_SB; rb return TOK_RB; @@ -15,8 +16,6 @@ di return TOK_DI; dp return TOK_DP; dr return TOK_DR; r return TOK_RUN; -pc return TOK_PC; -all return TOK_ALL; me return TOK_MOD_EXT; mi return TOK_MOD_INT; mp return TOK_MOD_PROG; @@ -26,7 +25,9 @@ s return TOK_STEP; u return TOK_UNASM; z return TOK_RST; zt return TOK_RST_TIMER; +all return TOK_ALL; +[a-z0-9]+ { yylval.string = strdup(yytext); return WORD; } [\n] return TOK_ENTER; [ \t]+ { /* ignore whitespace */ } -. { return yytext[0];} +. { return yytext[0]; } %%