X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Femuconsole.c;h=9d76976b4fc2538c7cf333ab6c587dcf3fbb3e1e;hb=47a60dcfbfdb7a29bd933a850292b752970f2af0;hp=48ae43ecff735ee01eb168a58c71e5a9563a7463;hpb=a78a174393ff9c8dbc0d5212576507f25d7e9bf1;p=emu8051.git diff --git a/src/emuconsole.c b/src/emuconsole.c index 48ae43e..9d76976 100644 --- a/src/emuconsole.c +++ b/src/emuconsole.c @@ -33,15 +33,6 @@ #include "hexfile.h" #include "keyboard.h" -/* Maximum number of BreakPoints */ -#define MAXBP 32 - -#define ENDLINE "\n" - -static int RunningState; -static int NbBreakpoints; -static unsigned int Breakpoints[MAXBP]; - /* Capitalize all letters in buffer */ static void Capitalize(char *buffer) @@ -65,55 +56,10 @@ RemoveSpaces(char *buffer) strcpy(buffer, &buffer[k]); } -/* Is the a breakpoint at Address */ -static int -IsBreakpoint(unsigned int Address) -{ - int Index = 0; - while (Index < NbBreakpoints && (Breakpoints[Index] != Address)) - Index++; - - return ((Breakpoints[Index] == Address) && (Index < NbBreakpoints)); -} - -/* Show Breakpoints list */ -static void -ShowBreakpoints(void) -{ - int Index; - - for (Index = 0; Index < NbBreakpoints ; Index++) - printf("Breakpoint at Address = %.4X\n", Breakpoints[Index]); -} - -/* Clear Breakpoint at Address from list */ -static void -ClearBreakpoint(unsigned int Address) -{ - int Index = 0; - while ((Index < NbBreakpoints) && (Breakpoints[Index] != Address)) - Index++; - if (Breakpoints[Index] != Address) - return; - Breakpoints[Index] = Breakpoints[NbBreakpoints - 1]; - NbBreakpoints--; -} - -/* Set Breakpoint at Address from list */ -static void -SetBreakpoint(unsigned int Address) -{ - if (IsBreakpoint(Address)) - return; - if (NbBreakpoints < MAXBP) - Breakpoints[NbBreakpoints++] = Address; -} - /* CPU exec and Console UI update */ static void console_exec(char *Address, char *NumberInst) { - char dummy; int NbInst = -1; /* -1 is infinity */ if (strlen(Address) == 0) { printf("Invalid address\n"); @@ -136,7 +82,7 @@ console_exec(char *Address, char *NumberInst) NbInst--; } while (!IsBreakpoint(cpu8051.pc) && (NbInst != 0) && !kbhit()); if (kbhit()) { - dummy = getch(); /* Flush key */ + (void) getch(); /* Flush key */ printf("Caught break signal!\n"); } if (NbInst == 0) @@ -177,46 +123,6 @@ Disasm(char *Address, char *NumberInst) DisasmN(MemAddress, NbInst); } -/* Dump memory */ -static void -DumpMem(char *Address, int memory_id) -{ - unsigned int MemAddress; - int Offset, Column; - int size = 256; - - if (strlen(Address) != 0) { - if (STREQ(Address, "PC")) - MemAddress = cpu8051.pc; - else - MemAddress = Ascii2Hex(Address, strlen(Address)); - } else { - MemAddress = 0; - } - - for (Offset = 0; Offset < size; Offset += 16) { - unsigned char data[16]; - - printf("%.4X ", MemAddress + Offset); - for (Column = 0; Column < 16; Column++) { - data[Column] = memory_read8(memory_id, MemAddress + - Offset + Column); - printf(" %.2X", (int) data[Column]); - } - printf(" "); - - /* Display any ASCII characters */ - for (Column = 0; Column < 16; Column++) { - if ((int) data[Column] >= 32 && - (int) data[Column] <= 126) - printf("%c", data[Column]); - else - printf("."); - } - printf("\n"); - } -} - /* Set NewValue to Register */ static void SetRegister(char *Register, char *NewValue) @@ -230,7 +136,7 @@ SetRegister(char *Register, char *NewValue) else if (STREQ(Register, "SP")) cpu8051_WriteD(_SP_, Ascii2Hex(NewValue, 2)); else { - printf("%sInvalid register name!%s", ENDLINE, ENDLINE); + printf("\nInvalid register name!\n"); printf("Valid registers are A, B, PC and SP.\n"); } } @@ -317,9 +223,9 @@ console_main(void) " Set Breakpoint.............. SB [address]", " Remove Breakpoint........... RB [address]", " Display Breakpoint(s)....... DB", - " Dump External Data Memory... DE [address]", - " Dump Internal Data Memory... DI [address]", - " Dump Program Memory......... DP [address]", + " Dump External Data Memory... DE [address] [size]", + " Dump Internal Data Memory... DI [address] [size]", + " Dump Program Memory......... DP [address] [size]", " Display Registers content... DR", " Execute..................... EM [address" " [number of instructions]]", @@ -336,11 +242,11 @@ console_main(void) Index = 0; while (Title[Index] != 0) - printf("%s%s", Title[Index++], ENDLINE); + printf("%s\n", Title[Index++]); Index = 0; while (Menu[Index] != 0) - printf("%s%s", Menu[Index++], ENDLINE); + printf("%s\n", Menu[Index++]); console_reset(); @@ -418,24 +324,21 @@ console_main(void) switch (Command[0]) { case 'D': - if (strlen(Parameter2) == 0) { - if (STREQ(Command, "DB") && - (strlen(Parameter1) == 0)) - ShowBreakpoints(); - else if (STREQ(Command, "DE")) - DumpMem(Parameter1, EXT_MEM_ID); - else if (STREQ(Command, "DI")) - DumpMem(Parameter1, INT_MEM_ID); - else if (STREQ(Command, "DP")) { - if ((strlen(Parameter1) == 0)) - strcpy(Parameter1, "PC"); - DumpMem(Parameter1, PGM_MEM_ID); - } else if (STREQ(Command, "DR") && - (strlen(Parameter1) == 0)) - console_show_registers(); - else - goto syntax_error; - } else + if (STREQ(Command, "DB") && + (strlen(Parameter1) == 0)) + ShowBreakpoints(); + else if (STREQ(Command, "DE")) + DumpMem(Parameter1, Parameter2, EXT_MEM_ID); + else if (STREQ(Command, "DI")) + DumpMem(Parameter1, Parameter2, INT_MEM_ID); + else if (STREQ(Command, "DP")) { + if ((strlen(Parameter1) == 0)) + strcpy(Parameter1, "PC"); + DumpMem(Parameter1, Parameter2, PGM_MEM_ID); + } else if (STREQ(Command, "DR") && + (strlen(Parameter1) == 0)) + console_show_registers(); + else goto syntax_error; break; case 'E': @@ -555,16 +458,16 @@ main(int argc, char **argv) cpu8051_init(); - RunningState = 0; - NbBreakpoints = 0; - hex_file = get_hex_filename(); if (hex_file != NULL) LoadHexFile(hex_file); console_main(); + +#ifdef EMU8051_DEBUG printf("End of program.\n"); +#endif return 0; }