From 2fc6cc22a29a53dc5127eafa2719d11e9bb38c42 Mon Sep 17 00:00:00 2001 From: Ian C Date: Thu, 22 Jan 2004 02:38:13 +0000 Subject: Updated with various bits from espec (memory menu, GUI, etc) --- src/memmenu.c | 949 ++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 851 insertions(+), 98 deletions(-) (limited to 'src/memmenu.c') diff --git a/src/memmenu.c b/src/memmenu.c index 3bb800c..95429f9 100644 --- a/src/memmenu.c +++ b/src/memmenu.c @@ -26,6 +26,7 @@ static const char ident[]="$Id$"; #include +#include #include #include @@ -33,33 +34,112 @@ static const char ident[]="$Id$"; #include "zx81.h" #include "gfx.h" #include "gui.h" +#include "util.h" #include static const char ident_h[]=EZX81_MEMMENU_H; #ifndef TRUE -#define TRUE 1 +#define TRUE 1 #endif #ifndef FALSE -#define FALSE 0 +#define FALSE 0 #endif -#define WHITE GFXRGB(255,255,255) -#define BLACK GFXRGB(0,0,0) -#define RED GFXRGB(255,100,100) -#define GREEN GFXRGB(100,255,100) -#define BLUE GFXRGB(100,100,255) +#define WHITE GFXRGB(255,255,255) +#define BLACK GFXRGB(0,0,0) +#define RED GFXRGB(255,100,100) +#define GREEN GFXRGB(100,255,100) +#define BLUE GFXRGB(100,100,255) -#define MENU +#define TRACE "trace" +#define TRACEMEM_WIN 6 + + +/* ---------------------------------------- TYPES +*/ +typedef struct +{ + int no; + int *active; + char **expr; +} Breakpoint; + + +typedef struct +{ + Z80Word addr; + Z80Word val; +} MemTrace; + + +typedef struct +{ + Z80State s; + MemTrace hl[TRACEMEM_WIN]; + MemTrace de[TRACEMEM_WIN]; + MemTrace sp[TRACEMEM_WIN]; +} Trace; + + +/* ---------------------------------------- STATIC DATA +*/ +static FILE *trace=NULL; +static Breakpoint bpoint={0,NULL,NULL}; +static const char *brk=NULL; +static int lodged=FALSE; + + +/* ---------------------------------------- PROTOS +*/ +static int Instruction(Z80 *z80, Z80Val data); /* ---------------------------------------- PRIVATE FUNCTIONS */ +static int BreaksActive(void) +{ + int f; + int ret=FALSE; + + for(f=0;fPC,s->AF>>8,FlagString(s->AF&0xff)); + y+=8; + GFXPrintPaper(0,y,col,BLACK, + "BC=%4.4x DE=%4.4x HL=%4.4x", + s->BC,s->DE,s->HL); + y+=8; + GFXPrintPaper(0,y,col,BLACK, + "IX=%4.4x IY=%4.4x SP=%4.4x", + s->IX,s->IY,s->SP); + y+=8; + GFXPrintPaper(0,y,col,BLACK, + "AF'=%4.4x BC'=%4.4x DE'=%4.4x HL'=%4.4x", + s->AF_,s->BC_,s->DE_,s->HL_); + y+=8; + GFXPrintPaper(0,y,col,BLACK, + "I=%2.2x IM=%2.2x R=%2.2x", + s->I,s->IM,s->R); + y+=8; + GFXPrintPaper(0,y,col,BLACK, + "IFF1=%2.2x IFF2=%2.2x", + s->IFF1,s->IFF2); - 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); + return y+8; } -static int EnterAddress(Z80 *z80, Z80Word *w) +static int EnterAddress(const char *prompt, Z80 *z80, Z80Word *w) { - unsigned long ul; const char *p; + char *error; + long l; - p=GUIInputString("Address?",""); + 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; } } @@ -173,6 +254,17 @@ static int EnterAddress(Z80 *z80, Z80Word *w) } +static void EnterLong(const char *prompt, long *l) +{ + const char *p; + + p=GUIInputString(prompt ? prompt : "Value?",""); + + if (*p) + *l=strtol(p,NULL,0); +} + + static void DoDisassem(Z80 *z80, const Z80State *s) { static int hexmode=FALSE; @@ -188,31 +280,45 @@ static void DoDisassem(Z80 *z80, const Z80State *s) GFXClear(BLACK); - Centre("Press F1 for help",0,RED); + Centre("DISASSEMBLY",0,WHITE); + Centre("Press F1 for help",9,RED); curr=pc; - for(f=0;f<21;f++) + for(f=0;fkey.keysym.sym) + { + case SDLK_F1: + GUIMessage + (eMessageBox,"PLAYBACK HELP","%s", + "ESC - Exit \n" + "Enter - Step number \n" + "P - Search for PC \n" + "M - Toggle CPU state/memory \n" + "Up - Prev step \n" + "Down - Next step \n" + "Page Up - Back 50 steps \n" + "Page Down - Forward 50 steps \n" + "Left - Back 1000 steps \n" + "Right - Forward 1000 steps \n \n" + "NOTE: Disassembly is as memory is NOW"); + break; + + case SDLK_ESCAPE: + quit=TRUE; + break; + + case SDLK_RETURN: + case SDLK_KP_ENTER: + EnterLong("Step number?",&pos); + pos--; + break; + + case SDLK_p: + if (EnterAddress("PC to search for?",z80,&pc)) + { + while((rd=fread(&t,sizeof t,1,fp))==1) + { + pos++; + if (t.s.PC==pc) + break; + } + + if (rd!=1) + { + GUIMessage(eMessageBox,"NOTICE","Address not found"); + pos=prev_pos; + } + } + break; + + case SDLK_m: + showmem=!showmem; + break; + + case SDLK_UP: + pos--; + break; + + case SDLK_DOWN: + pos++; + break; + + case SDLK_PAGEUP: + pos-=50; + break; + + case SDLK_PAGEDOWN: + pos+=50; + break; + + case SDLK_LEFT: + pos-=1000; + break; + + case SDLK_RIGHT: + pos+=1000; + break; + + default: + break; + } + + /* Check position before next loop + */ + if (pos<0) + pos=0; + + if (pos>=max_pos) + pos=max_pos-1; + } + + fclose(fp); +} + + +static void DoAddBreakpoint(Z80 *z80) +{ + const char *expr; + char *error; + long l; + + expr=GUIInputString("Expression?",""); + + if (!*expr) + return; + + if (!Z80Expression(z80,expr,&l,&error)) + { + if (error) + { + GUIMessage(eMessageBox,"INVALID EXPRESSION","%s",error); + free(error); + } + else + { + GUIMessage(eMessageBox,"ERROR","Expression is invalid"); + free(error); + } + } + else + { + bpoint.no++; + bpoint.expr=Realloc(bpoint.expr,bpoint.no * sizeof(*bpoint.expr)); + bpoint.active=Realloc(bpoint.active,bpoint.no * sizeof(*bpoint.active)); + + bpoint.expr[bpoint.no-1]=StrCopy(expr); + bpoint.active[bpoint.no-1]=TRUE; + + SetCallback(z80); + } +} + + +static void DoActiveBreakpoint(Z80 *z80) +{ + if (bpoint.no==0) + { + GUIMessage(eMessageBox,"NOTICE","No breakpoints to set"); + return; + } + + GFXClear(BLACK); + + GUIListOption("SELECT ACTIVE BREAKPOINTS", + bpoint.no,bpoint.expr,bpoint.active); +} + + +static void DoRemoveBreakpoint(Z80 *z80) +{ + int sel; + + if (bpoint.no==0) + { + GUIMessage(eMessageBox,"NOTICE","No breakpoints to delete"); + return; + } + + GFXClear(BLACK); + + sel=GUIListSelect("BREAKPOINT TO DELETE",bpoint.no,bpoint.expr); + + while (sel!=-1) + { + int f; + + free(bpoint.expr[sel]); + + for(f=sel;fkey.state!=SDL_PRESSED) + e=NULL; + } + else + e=GFXWaitKey(); + + if (e) + { + switch(e->key.keysym.sym) + { + case SDLK_F1: + GUIMessage + (eMessageBox,"PLAYBACK HELP","%s", + "ESC - Exit \n" + "ENTER - Single step processor \n" + "R - Run till break or stop \n" + "SPACE - Stop running \n" + "M - Toggle CPU state/memory \n" + "5 - Add a new breakpoint \n" + "6 - Set active breakpoints \n" + "7 - Remove a breakpoint \n" + "8 - Clear all breakpoints "); + break; + + case SDLK_RETURN: + case SDLK_KP_ENTER: + step=TRUE; + break; + + case SDLK_ESCAPE: + quit=TRUE; + break; + + case SDLK_r: + running=TRUE; + break; + + case SDLK_SPACE: + running=FALSE; + break; + + case SDLK_m: + showmem=!showmem; + break; + + case SDLK_5: + DoAddBreakpoint(z80); + break; + + case SDLK_6: + DoActiveBreakpoint(z80); + break; + + case SDLK_7: + DoRemoveBreakpoint(z80); + break; + + case SDLK_8: + DoClearBreakpoint(z80); + break; + + default: + break; + } + } + + if (running || step) + Z80SingleStep(z80); + + if (running && (brk=Break())) + { + GUIMessage(eMessageBox,"BREAKPOINT","%s",brk); + running=FALSE; + } + } + + ZX81EnableScreen(TRUE); +} + + /* ---------------------------------------- EXPORTED INTERFACES */ -void MemoryMenu(Z80 *z80) +int MemoryMenu(Z80 *z80) { SDL_Event *e; + int done=FALSE; int quit=FALSE; Z80State s; + int y; Z80GetState(z80,&s); GFXKeyRepeat(TRUE); - while(!quit) + while(!done) { DisplayMenu(); - DisplayState(z80); GFXEndFrame(FALSE); e=GFXWaitKey(); @@ -322,17 +1025,78 @@ void MemoryMenu(Z80 *z80) DoDisassem(z80,&s); break; - case SDLK_ESCAPE: case SDLK_2: + DoDisassemFile(z80,&s); + break; + + case SDLK_3: + if (!trace) + EnableTrace(z80,&s); + else + DisableTrace(z80); + break; + + case SDLK_4: + DisableTrace(z80); + PlaybackTrace(z80); + break; + + case SDLK_5: + DoAddBreakpoint(z80); + break; + + case SDLK_6: + DoActiveBreakpoint(z80); + break; + + case SDLK_7: + DoRemoveBreakpoint(z80); + break; + + case SDLK_8: + DoClearBreakpoint(z80); + break; + + case SDLK_9: + DoMonitor(z80); + break; + + case SDLK_r: + if (GUIMessage(eYesNoBox,"RESET","Sure?")) + { + Z80Reset(z80); + ZX81Reset(z80); + } + break; + + case SDLK_x: + done=TRUE; quit=TRUE; break; + case SDLK_s: + GFXClear(BLACK); + Centre("CURRENT STATE",0,WHITE); + Centre("Press a key",9,RED); + y=DisplayZ80State(&s,20,WHITE); + GFXPrint(0,y,GREEN,"%s",ZX81Info(z80)); + GFXEndFrame(FALSE); + GFXWaitKey(); + break; + + case SDLK_ESCAPE: + done=TRUE; + break; + default: break; } } GFXKeyRepeat(FALSE); + + GFXClear(BLACK); + return quit; } @@ -342,31 +1106,20 @@ void DisplayState(Z80 *z80) int y; Z80GetState(z80,&s); + y=DisplayZ80State(&s,GFX_HEIGHT/2,RED); + GFXPrintPaper(0,y,GREEN,BLACK,"%s",ZX81Info(z80)); +} - y=136; - - GFXPrintPaper(0,y,RED,BLACK,"PC=%4.4x A=%2.2x F=%s", - s.PC,s.AF>>8,FlagString(s.AF&0xff)); - y+=8; - - GFXPrintPaper(0,y,RED,BLACK,"BC=%4.4x DE=%4.4x HL=%4.4x",s.BC,s.DE,s.HL); - y+=8; - - GFXPrintPaper(0,y,RED,BLACK,"IX=%4.4x IY=%4.4x SP=%4.4x",s.IX,s.IY,s.SP); - y+=8; - GFXPrintPaper(0,y,RED,BLACK,"I=%2.2x IM=%2.2x R=%2.2x",s.I,s.IM,s.R); - y+=8; +const char *Break(void) +{ + const char *ret; - GFXPrintPaper(0,y,RED,BLACK,"IFF1=%2.2x IFF2=%2.2x",s.IFF1,s.IFF2); - y+=8; + ret=brk; + brk=NULL; - y+=8; - GFXPrintPaper(0,y,RED,BLACK,"%s\n",ZX81Info(z80)); - y+=8; + return ret; } - - /* END OF FILE */ -- cgit v1.2.3