From a08ee7dc825192d933d836514252e09bbcf313dc Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 4 Jan 2004 23:28:26 +0000 Subject: Devel snapshot - still doesn't work --- src/Makefile | 132 +----------------------- src/gfx.c | 2 + src/main.c | 16 ++- src/memmenu.c | 56 ++++++++++- src/spec.c | 315 +++++++++++++++++++++++++++++++++++++++++++++++++++++----- src/spec.h | 15 +-- 6 files changed, 358 insertions(+), 178 deletions(-) diff --git a/src/Makefile b/src/Makefile index 347c5d0..179602c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,7 +18,7 @@ # # ------------------------------------------------------------------------- # -# $Id: Makefile,v 1.2 2003-12-24 18:19:00 ianc Exp $ +# $Id: Makefile,v 1.3 2004-01-04 23:28:26 ianc Exp $ # @@ -69,133 +69,3 @@ depend: cd z80; make depend ; cd .. # DO NOT DELETE THIS LINE -- make depend depends on it - -main.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -main.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -main.o: /usr/include/stdio.h /usr/local/include/SDL/SDL.h -main.o: /usr/local/include/SDL/SDL_main.h /usr/local/include/SDL/SDL_types.h -main.o: /usr/local/include/SDL/SDL_getenv.h -main.o: /usr/local/include/SDL/SDL_error.h -main.o: /usr/local/include/SDL/begin_code.h -main.o: /usr/local/include/SDL/close_code.h -main.o: /usr/local/include/SDL/SDL_rwops.h /usr/local/include/SDL/SDL_timer.h -main.o: /usr/local/include/SDL/SDL_audio.h -main.o: /usr/local/include/SDL/SDL_byteorder.h -main.o: /usr/local/include/SDL/SDL_cdrom.h -main.o: /usr/local/include/SDL/SDL_joystick.h -main.o: /usr/local/include/SDL/SDL_events.h -main.o: /usr/local/include/SDL/SDL_active.h -main.o: /usr/local/include/SDL/SDL_keyboard.h -main.o: /usr/local/include/SDL/SDL_keysym.h -main.o: /usr/local/include/SDL/SDL_mouse.h /usr/local/include/SDL/SDL_video.h -main.o: /usr/local/include/SDL/SDL_mutex.h /usr/local/include/SDL/SDL_quit.h -main.o: /usr/local/include/SDL/SDL_version.h z80/z80.h spec.h gfx.h gui.h -main.o: memmenu.h config.h exit.h -spec.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -spec.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -spec.o: /usr/include/stdio.h /usr/include/string.h /usr/include/strings.h -spec.o: spec.h z80/z80.h /usr/local/include/SDL/SDL.h -spec.o: /usr/local/include/SDL/SDL_main.h /usr/local/include/SDL/SDL_types.h -spec.o: /usr/local/include/SDL/SDL_getenv.h -spec.o: /usr/local/include/SDL/SDL_error.h -spec.o: /usr/local/include/SDL/begin_code.h -spec.o: /usr/local/include/SDL/close_code.h -spec.o: /usr/local/include/SDL/SDL_rwops.h /usr/local/include/SDL/SDL_timer.h -spec.o: /usr/local/include/SDL/SDL_audio.h -spec.o: /usr/local/include/SDL/SDL_byteorder.h -spec.o: /usr/local/include/SDL/SDL_cdrom.h -spec.o: /usr/local/include/SDL/SDL_joystick.h -spec.o: /usr/local/include/SDL/SDL_events.h -spec.o: /usr/local/include/SDL/SDL_active.h -spec.o: /usr/local/include/SDL/SDL_keyboard.h -spec.o: /usr/local/include/SDL/SDL_keysym.h -spec.o: /usr/local/include/SDL/SDL_mouse.h /usr/local/include/SDL/SDL_video.h -spec.o: /usr/local/include/SDL/SDL_mutex.h /usr/local/include/SDL/SDL_quit.h -spec.o: /usr/local/include/SDL/SDL_version.h gfx.h gui.h config.h exit.h -config.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -config.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -config.o: /usr/include/stdio.h /usr/include/string.h /usr/include/strings.h -config.o: exit.h config.h -gfx.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -gfx.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -gfx.o: /usr/include/stdio.h /usr/include/string.h /usr/include/strings.h -gfx.o: /usr/include/stdarg.h gfx.h /usr/local/include/SDL/SDL.h -gfx.o: /usr/local/include/SDL/SDL_main.h /usr/local/include/SDL/SDL_types.h -gfx.o: /usr/local/include/SDL/SDL_getenv.h /usr/local/include/SDL/SDL_error.h -gfx.o: /usr/local/include/SDL/begin_code.h -gfx.o: /usr/local/include/SDL/close_code.h /usr/local/include/SDL/SDL_rwops.h -gfx.o: /usr/local/include/SDL/SDL_timer.h /usr/local/include/SDL/SDL_audio.h -gfx.o: /usr/local/include/SDL/SDL_byteorder.h -gfx.o: /usr/local/include/SDL/SDL_cdrom.h -gfx.o: /usr/local/include/SDL/SDL_joystick.h -gfx.o: /usr/local/include/SDL/SDL_events.h -gfx.o: /usr/local/include/SDL/SDL_active.h -gfx.o: /usr/local/include/SDL/SDL_keyboard.h -gfx.o: /usr/local/include/SDL/SDL_keysym.h /usr/local/include/SDL/SDL_mouse.h -gfx.o: /usr/local/include/SDL/SDL_video.h /usr/local/include/SDL/SDL_mutex.h -gfx.o: /usr/local/include/SDL/SDL_quit.h /usr/local/include/SDL/SDL_version.h -gfx.o: exit.h config.h font.h -gui.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -gui.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -gui.o: /usr/include/stdio.h /usr/include/string.h /usr/include/strings.h -gui.o: /usr/include/stdarg.h /usr/include/ctype.h /usr/include/runetype.h -gui.o: gui.h /usr/local/include/SDL/SDL.h /usr/local/include/SDL/SDL_main.h -gui.o: /usr/local/include/SDL/SDL_types.h /usr/local/include/SDL/SDL_getenv.h -gui.o: /usr/local/include/SDL/SDL_error.h /usr/local/include/SDL/begin_code.h -gui.o: /usr/local/include/SDL/close_code.h /usr/local/include/SDL/SDL_rwops.h -gui.o: /usr/local/include/SDL/SDL_timer.h /usr/local/include/SDL/SDL_audio.h -gui.o: /usr/local/include/SDL/SDL_byteorder.h -gui.o: /usr/local/include/SDL/SDL_cdrom.h -gui.o: /usr/local/include/SDL/SDL_joystick.h -gui.o: /usr/local/include/SDL/SDL_events.h -gui.o: /usr/local/include/SDL/SDL_active.h -gui.o: /usr/local/include/SDL/SDL_keyboard.h -gui.o: /usr/local/include/SDL/SDL_keysym.h /usr/local/include/SDL/SDL_mouse.h -gui.o: /usr/local/include/SDL/SDL_video.h /usr/local/include/SDL/SDL_mutex.h -gui.o: /usr/local/include/SDL/SDL_quit.h /usr/local/include/SDL/SDL_version.h -gui.o: gfx.h exit.h -memmenu.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -memmenu.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -memmenu.o: /usr/include/string.h /usr/include/strings.h memmenu.h z80/z80.h -memmenu.o: spec.h /usr/local/include/SDL/SDL.h -memmenu.o: /usr/local/include/SDL/SDL_main.h -memmenu.o: /usr/local/include/SDL/SDL_types.h -memmenu.o: /usr/local/include/SDL/SDL_getenv.h -memmenu.o: /usr/local/include/SDL/SDL_error.h -memmenu.o: /usr/local/include/SDL/begin_code.h -memmenu.o: /usr/local/include/SDL/close_code.h -memmenu.o: /usr/local/include/SDL/SDL_rwops.h /usr/include/stdio.h -memmenu.o: /usr/local/include/SDL/SDL_timer.h -memmenu.o: /usr/local/include/SDL/SDL_audio.h -memmenu.o: /usr/local/include/SDL/SDL_byteorder.h -memmenu.o: /usr/local/include/SDL/SDL_cdrom.h -memmenu.o: /usr/local/include/SDL/SDL_joystick.h -memmenu.o: /usr/local/include/SDL/SDL_events.h -memmenu.o: /usr/local/include/SDL/SDL_active.h -memmenu.o: /usr/local/include/SDL/SDL_keyboard.h -memmenu.o: /usr/local/include/SDL/SDL_keysym.h -memmenu.o: /usr/local/include/SDL/SDL_mouse.h -memmenu.o: /usr/local/include/SDL/SDL_video.h -memmenu.o: /usr/local/include/SDL/SDL_mutex.h -memmenu.o: /usr/local/include/SDL/SDL_quit.h -memmenu.o: /usr/local/include/SDL/SDL_version.h gfx.h gui.h -exit.o: /usr/include/stdlib.h /usr/include/sys/cdefs.h -exit.o: /usr/include/sys/_types.h /usr/include/machine/_types.h -exit.o: /usr/include/stdarg.h exit.h /usr/local/include/SDL/SDL.h -exit.o: /usr/local/include/SDL/SDL_main.h /usr/local/include/SDL/SDL_types.h -exit.o: /usr/local/include/SDL/SDL_getenv.h -exit.o: /usr/local/include/SDL/SDL_error.h -exit.o: /usr/local/include/SDL/begin_code.h -exit.o: /usr/local/include/SDL/close_code.h -exit.o: /usr/local/include/SDL/SDL_rwops.h /usr/include/stdio.h -exit.o: /usr/local/include/SDL/SDL_timer.h /usr/local/include/SDL/SDL_audio.h -exit.o: /usr/local/include/SDL/SDL_byteorder.h -exit.o: /usr/local/include/SDL/SDL_cdrom.h -exit.o: /usr/local/include/SDL/SDL_joystick.h -exit.o: /usr/local/include/SDL/SDL_events.h -exit.o: /usr/local/include/SDL/SDL_active.h -exit.o: /usr/local/include/SDL/SDL_keyboard.h -exit.o: /usr/local/include/SDL/SDL_keysym.h -exit.o: /usr/local/include/SDL/SDL_mouse.h /usr/local/include/SDL/SDL_video.h -exit.o: /usr/local/include/SDL/SDL_mutex.h /usr/local/include/SDL/SDL_quit.h -exit.o: /usr/local/include/SDL/SDL_version.h diff --git a/src/gfx.c b/src/gfx.c index 739b876..a2d1623 100644 --- a/src/gfx.c +++ b/src/gfx.c @@ -190,6 +190,8 @@ void GFXInit(void) SDL_ShowCursor(SDL_DISABLE); SDL_WM_SetCaption("eSPEC","eSPEC"); + + atexit(SDL_Quit); } diff --git a/src/main.c b/src/main.c index c97aab3..ce331f5 100644 --- a/src/main.c +++ b/src/main.c @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) SPECWritePort, SPECReadPort, SPECReadForDisassem, - NULL); + SPECGetLabel); GFXInit(); @@ -95,13 +95,11 @@ int main(int argc, char *argv[]) Z80GetState(z80,&s1); Z80SingleStep(z80); - Z80GetState(z80,&s2); - if (s2.PC>0x3fff) + if (s2.PC==0) { - printf("PC > 0x3fff - from 0x%4.4x\n",s1.PC); - return 0; + printf("PC zero - prev %4.4x\n",s1.PC); } if (trace) @@ -115,17 +113,17 @@ int main(int argc, char *argv[]) switch (e->key.keysym.sym) { case SDLK_ESCAPE: - if (e->key.state==SDL_RELEASED) + if (e->key.state==SDL_PRESSED) quit=TRUE; break; case SDLK_F11: - if (e->key.state==SDL_RELEASED) + if (e->key.state==SDL_PRESSED) MemoryMenu(z80); break; case SDLK_F12: - if (e->key.state==SDL_RELEASED) + if (e->key.state==SDL_PRESSED) trace=!trace; break; @@ -136,8 +134,6 @@ int main(int argc, char *argv[]) } } - SDL_Quit(); - return EXIT_SUCCESS; } diff --git a/src/memmenu.c b/src/memmenu.c index 516bd36..9e1726b 100644 --- a/src/memmenu.c +++ b/src/memmenu.c @@ -26,6 +26,7 @@ static const char ident[]="$Id$"; #include +#include #include #include @@ -66,7 +67,8 @@ static void DisplayMenu(void) static const char *menu[]= { "1. Disassemble/Hex dump", - "2. Return ", + "2. Disassemble to file ", + "3. Return ", NULL }; @@ -145,12 +147,12 @@ static Z80Word Address(Z80 *z80, const char *p) } -static int EnterAddress(Z80 *z80, Z80Word *w) +static int EnterAddress(const char *prompt, Z80 *z80, Z80Word *w) { unsigned long ul; const char *p; - p=GUIInputString("Address?",""); + p=GUIInputString(prompt ? prompt : "Address?",""); if (*p) { @@ -254,7 +256,7 @@ static void DoDisassem(Z80 *z80, const Z80State *s) case SDLK_RETURN: case SDLK_KP_ENTER: - EnterAddress(z80,&pc); + EnterAddress(NULL,z80,&pc); break; case SDLK_UP: @@ -294,6 +296,46 @@ static void DoDisassem(Z80 *z80, const Z80State *s) } +static void DoDisassemFile(Z80 *z80, const Z80State *s) +{ + static char fname[FILENAME_MAX]=""; + FILE *fp; + Z80Word start; + Z80Word len; + Z80Word prev; + const char *p; + + EnterAddress("Disassemble from?",z80,&start); + EnterAddress("For how many bytes?",z80,&len); + + p=GUIInputString("To file?",fname); + + if (!strlen(p)) + return; + + strcpy(fname,p); + + if (!(fp=fopen(fname,"w"))) + { + GUIMessage("ERROR","Couldn't create file:\n%s",fname); + return; + } + + prev=len; + + while(len<=prev) + { + Z80Word orig=start; + + fprintf(fp,"%4.4x: %s\n",orig,Z80Disassemble(z80,&start)); + prev=len; + len-=(start-orig); + } + + fclose(fp); +} + + /* ---------------------------------------- EXPORTED INTERFACES */ void MemoryMenu(Z80 *z80) @@ -320,8 +362,12 @@ void MemoryMenu(Z80 *z80) DoDisassem(z80,&s); break; - case SDLK_ESCAPE: case SDLK_2: + DoDisassemFile(z80,&s); + break; + + case SDLK_ESCAPE: + case SDLK_3: quit=TRUE; break; diff --git a/src/spec.c b/src/spec.c index a8cb9eb..6ace002 100644 --- a/src/spec.c +++ b/src/spec.c @@ -20,7 +20,7 @@ ------------------------------------------------------------------------- - Provides the emulation for the SPEC + Provides the emulation for the Spectrum */ static const char ident[]="$Id$"; @@ -51,6 +51,9 @@ static const int ROMLEN=0x4000; static const int ROM_SAVE=0x4c6; static const int ROM_LOAD=0x562; +#define LOAD_PATCH 0xf0 +#define SAVE_PATCH 0xf1 + /* The SPEC screen */ #define GFX_W 320 @@ -95,6 +98,8 @@ static int border=0; #define NVAL 235 /* Normal RGB intensity */ #define BVAL 255 /* Bright RGB intensity */ +static Z80Byte *line[SCRL]; /* Accelerators to screen data */ + static struct { Uint32 col; @@ -197,6 +202,40 @@ static const MatrixMap keymap[]= }; +/* ---------------------------------------- DEBUG FUNCTIONS +static const char *FlagString(Z80Byte flag) +{ + static char s[]="76543210"; + static char c[]="SZ5H3PNC"; + int f; + + for(f=0;f<8;f++) + if (flag&(1<<(7-f))) + s[f]=c[f]; + else + s[f]='-'; + + return s; +} + + +static void DumpZ80(Z80 *z80) +{ + Z80State s; + + Z80GetState(z80,&s); + + printf("---------------------------------\n"); + printf("PC=%4.4x A=%2.2x F=%s\n",s.PC,s.AF>>8,FlagString(s.AF&0xff)); + printf("BC=%4.4x DE=%4.4x HL=%4.4x\n",s.BC,s.DE,s.HL); + printf("IX=%4.4x IY=%4.4x SP=%4.4x\n",s.IX,s.IY,s.SP); + printf("I=%2.2x IM=%2.2x R=%2.2x\n",s.I,s.IM,s.R); + printf("IFF1=%2.2x IFF2=%2.2x\n",s.IFF1,s.IFF2); + printf("%s\n",Z80Disassemble(z80,&s.PC)); +} +*/ + + /* ---------------------------------------- PRIVATE FUNCTIONS */ void DrawScanline(int y) @@ -216,7 +255,7 @@ void DrawScanline(int y) { GFXLock(); - scr=mem+SCRDATA+aline*TXT_W; + scr=line[aline]; for(f=0;f=0;r--) - if (b&(1<