#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#include "common.h"
#include "cpu8051.h"
}
}
+/* 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 */
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> NUMBER
+%token <string> 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
;
command:
- pc_set
- |
breakpoint_clr
|
breakpoint_set
|
breakpoint_display
|
- dump_ext_mem
- |
- dump_int_mem
- |
- dump_prog_mem
+ dump_mem
|
display_regs
|
breakpoint_set:
TOK_SB TOK_ENTER
{
- log_debug(" Set breakpoint at current PC");
+ log_debug(" Set breakpoint at PC");
SetBreakpoint(cpu8051.pc);
}
|
}
;
-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);
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);
}
;
}
;
-pc_set:
- TOK_PC NUMBER TOK_ENTER
- {
- cpu8051.pc = $2;
- }
- ;
-
help:
TOK_HELP TOK_ENTER
{
%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;
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;
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]; }
%%