From: Hugo Villeneuve Date: Sun, 24 Nov 2013 18:15:00 +0000 (-0500) Subject: Add option to automatically run and stop CLI emulator X-Git-Tag: v2.0.0~68 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=dd92f3969f3537fc1dd13926e7ae1014d27513ab;p=emu8051.git Add option to automatically run and stop CLI emulator --- diff --git a/src/cpu8051.c b/src/cpu8051.c index 55e761a..30c8cca 100644 --- a/src/cpu8051.c +++ b/src/cpu8051.c @@ -30,8 +30,11 @@ #include "memory.h" #include "psw.h" #include "disasm.h" +#include "options.h" #include "instructions_8051.h" +extern struct options_t options; + /* Check if the address is a breakpoint */ int IsBreakpoint(unsigned int address) @@ -47,6 +50,16 @@ IsBreakpoint(unsigned int address) return 0; } +/* Check if the address is a stop point */ +int +IsStoppoint(unsigned int address) +{ + if ((options.stop_address != 0) && (options.stop_address == address)) + return 1; + else + return 0; +} + /* Show Breakpoints list */ void ShowBreakpoints(void) diff --git a/src/cpu8051.h b/src/cpu8051.h index 52e710d..4d77690 100644 --- a/src/cpu8051.h +++ b/src/cpu8051.h @@ -48,6 +48,9 @@ _SCOPE_ struct cpu8051_t cpu8051; int IsBreakpoint(unsigned int Address); +int +IsStoppoint(unsigned int address); + void ShowBreakpoints(void); diff --git a/src/emuconsole.c b/src/emuconsole.c index c068095..19fa194 100644 --- a/src/emuconsole.c +++ b/src/emuconsole.c @@ -71,8 +71,9 @@ console_exec(char *Address, char *NumberInst) if (STREQ(Address, "PC")) cpu8051.pc = Ascii2Hex(Address, strlen(Address)); - if (strlen(NumberInst) != 0) - NbInst = Ascii2Hex(NumberInst, strlen(NumberInst)); + if (NumberInst) + if (strlen(NumberInst) != 0) + NbInst = Ascii2Hex(NumberInst, strlen(NumberInst)); InitUnixKB(); @@ -82,7 +83,8 @@ console_exec(char *Address, char *NumberInst) cpu8051_Exec(); if (NbInst > 0) NbInst--; - } while (!IsBreakpoint(cpu8051.pc) && (NbInst != 0) && !kbhit()); + } while (!IsBreakpoint(cpu8051.pc) && !IsStoppoint(cpu8051.pc) && + (NbInst != 0) && !kbhit()); if (kbhit()) { (void) getch(); /* Flush key */ log_info("Caught break signal!"); @@ -91,6 +93,8 @@ console_exec(char *Address, char *NumberInst) log_info("Number of instructions reached! Stopping!"); if (IsBreakpoint(cpu8051.pc)) log_info("Breakpoint hit at %.4X! Stopping!", cpu8051.pc); + if (IsStoppoint(cpu8051.pc)) + log_info("Stoppoint hit at %.4X! Stopping!", cpu8051.pc); ResetUnixKB(); } @@ -191,7 +195,6 @@ console_reset(void) log_info("Resetting..."); cpu8051_Reset(); log_info("Done"); - console_show_registers(); } /* CPU trace and Console UI update */ @@ -242,16 +245,25 @@ console_main(void) " [number of instructions]", " Reset processor............. Z", 0 }; - Index = 0; - while (Title[Index] != 0) - printf("%s\n", Title[Index++]); - - Index = 0; - while (Menu[Index] != 0) - printf("%s\n", Menu[Index++]); - console_reset(); + if (options.stop_address != 0) { + /* Automatically run program and stop at specified address. */ + console_exec("0x0000", NULL); + console_show_registers(); + QuitRequest = 1; + } else { + Index = 0; + while (Title[Index] != 0) + printf("%s\n", Title[Index++]); + + Index = 0; + while (Menu[Index] != 0) + printf("%s\n", Menu[Index++]); + + console_show_registers(); + } + while (!QuitRequest) { int slen; size_t len = 0; diff --git a/src/options.c b/src/options.c index 39efd57..fb78714 100644 --- a/src/options.c +++ b/src/options.c @@ -48,6 +48,7 @@ static struct argp_option argp_options[] = { {"iram", 'i', "size", 0, "Set internal ram size" }, {"pram", 'p', "size", 0, "Set program memory size" }, {"xram", 'x', "size", 0, "Set external ram size (default is 1024)" }, + {"stop", 's', "addr", 0, "Automatically run program and stop at address" }, { 0 } }; @@ -107,6 +108,19 @@ decode_memory_size(char *arg, struct argp_state *state, int memid) } } +static void +decode_address(char *arg, struct argp_state *state, uint16_t *dest) +{ + char *endptr; + + *dest = strtol(arg, &endptr, 0); + + if (*endptr != '\0') { + log_err("Invalid address"); + argp_usage(state); + } +} + /* Parse a single option. */ static error_t parse_opt(int key, char *arg, struct argp_state *state) @@ -121,6 +135,9 @@ parse_opt(int key, char *arg, struct argp_state *state) case 'p': decode_memory_size(arg, state, PGM_MEM_ID); break; + case 's': + decode_address(arg, state, &options.stop_address); + break; case 'x': decode_memory_size(arg, state, EXT_MEM_ID); break; @@ -161,6 +178,7 @@ parse_command_line_options(int argc, char *argv[]) options.iram_size = INT_MEM_MAX_SIZE; options.xram_size = EXT_MEM_DEFAULT_SIZE; options.log = LOG_LEVEL_ERR; + options.stop_address = 0; /* 0 means stop address is disabled. */ /* Parse our arguments. */ argp_parse(&argp, argc, argv, 0, 0, NULL); diff --git a/src/options.h b/src/options.h index a03173e..589c2d5 100644 --- a/src/options.h +++ b/src/options.h @@ -33,6 +33,7 @@ struct options_t { int xram_size; /* Maximum external ram size. */ char *filename; int log; + uint16_t stop_address; /* Run program up to that adress and exit. */ } options_t; void