From 44ffbe36a8e7eaab7d7851bb79f229c4383c6545 Mon Sep 17 00:00:00 2001 From: Ian C Date: Tue, 13 Jan 2004 02:21:06 +0000 Subject: Added breakpoints to memory menu and added extra GUI items. Plus general fixes. --- src/memmenu.c | 300 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 228 insertions(+), 72 deletions(-) (limited to 'src/memmenu.c') diff --git a/src/memmenu.c b/src/memmenu.c index 50b9acb..60e2c03 100644 --- a/src/memmenu.c +++ b/src/memmenu.c @@ -34,6 +34,7 @@ static const char ident[]="$Id$"; #include "spec.h" #include "gfx.h" #include "gui.h" +#include "util.h" #include @@ -56,13 +57,43 @@ static const char ident_h[]=ESPEC_MEMMENU_H; #define TRACE "trace" +/* ---------------------------------------- TYPES +*/ +typedef struct +{ + int no; + char **expr; +} Breakpoint; + + /* ---------------------------------------- STATIC DATA */ -FILE *trace=NULL; +static FILE *trace=NULL; +static Breakpoint bpoint={NULL,0}; +static const char *brk=NULL; + + +/* ---------------------------------------- PROTOS +*/ +static int Instruction(Z80 *z80, Z80Val data); /* ---------------------------------------- PRIVATE FUNCTIONS */ +static void SetCallback(Z80 *z80) +{ + if (trace || bpoint.no) + Z80LodgeCallback(z80,eZ80_Instruction,Instruction); +} + + +static void ClearCallback(Z80 *z80) +{ + if (!trace && !bpoint.no) + Z80RemoveCallback(z80,eZ80_Instruction,Instruction); +} + + static void Centre(const char *p, int y, Uint32 col) { GFXPrint((320-strlen(p)*8)/2,y,col,"%s",p); @@ -73,11 +104,15 @@ static void DisplayMenu(void) { static const char *menu[]= { - "1. Disassemble/Hex dump", - "2. Disassemble to file ", - "3. Start/Stop trace log", - "4. Playback trace log ", - "5. Return ", + "1. Disassemble/Hex dump ", + "2. Disassemble to file ", + "3. Start/Stop trace log ", + "4. Playback trace log ", + "5. Add a new breakpoint ", + "6. Clear a breakpoint ", + "7. Display breakpoints ", + "8. Clear all breakpoints", + "9. Return ", NULL }; @@ -138,66 +173,26 @@ void DisplayZ80State(Z80State *s, int y, Uint32 col) } -static int StrEq(const char *a, const char *b) -{ - while(*a && *b && tolower(*a)==tolower(*b)) - { - a++; - b++; - } - - if (*a || *b) - return FALSE; - else - return TRUE; -} - - -static Z80Word Address(Z80 *z80, const char *p) -{ - Z80State s; - - Z80GetState(z80,&s); - - if (StrEq(p,"AF")) - return s.AF; - else if (StrEq(p,"BC")) - return s.BC; - else if (StrEq(p,"DE")) - return s.DE; - else if (StrEq(p,"HL")) - return s.HL; - else if (StrEq(p,"IX")) - return s.IX; - else if (StrEq(p,"IY")) - return s.IY; - else if (StrEq(p,"SP")) - return s.SP; - else if (StrEq(p,"PC")) - return s.PC; - - return (Z80Word)strtoul(p,NULL,0); -} - - static int EnterAddress(const char *prompt, Z80 *z80, Z80Word *w) { - unsigned long ul; const char *p; + char *error; + long l; p=GUIInputString(prompt ? prompt : "Address?",""); if (*p) { - ul=Address(z80,p); - - if (ul>0xffff) + if (!Z80Expression(z80,p,&l,&error)) { - GUIMessage("ERROR","Bad address"); + GUIMessage(eMessageBox, + "ERROR","%s",error ? error:"Invalid expression"); + + free(error); } else { - *w=(Z80Word)ul; + *w=(Z80Word)l; return TRUE; } } @@ -237,7 +232,7 @@ static void DoDisassem(Z80 *z80, const Z80State *s) curr=pc; - for(f=0;f<21;f++) + for(f=0;f