summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile13
-rw-r--r--src/memmenu.c142
-rw-r--r--src/spec.c13
-rw-r--r--src/spec.h4
-rw-r--r--src/util.c17
-rw-r--r--src/util.h7
6 files changed, 158 insertions, 38 deletions
diff --git a/src/Makefile b/src/Makefile
index 5d98ed7..ffb9c8f 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -18,7 +18,7 @@
#
# -------------------------------------------------------------------------
#
-# $Id: Makefile,v 1.6 2004-01-14 01:50:20 ianc Exp $
+# $Id: Makefile,v 1.7 2004-01-15 18:53:51 ianc Exp $
#
@@ -56,7 +56,6 @@ CFLAGS += -Iz80 `sdl-config --cflags`
LIBS = $(Z80LIB) `sdl-config --libs`
-
$(TARGET): $(OBJECTS) $(Z80LIB)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) $(LIBS)
@@ -117,7 +116,7 @@ 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 snap.h gfx.h gui.h config.h
-spec.o: exit.h
+spec.o: exit.h util.h
snap.o: snap.h /usr/include/stdlib.h /usr/include/sys/cdefs.h
snap.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
snap.o: /usr/include/stdio.h z80/z80.h
@@ -163,7 +162,7 @@ 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: exit.h
+gui.o: exit.h util.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/stdio.h /usr/include/string.h /usr/include/strings.h
@@ -189,11 +188,11 @@ 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
+memmenu.o: /usr/local/include/SDL/SDL_version.h gfx.h gui.h util.h
util.o: /usr/include/stdio.h /usr/include/sys/cdefs.h
util.o: /usr/include/sys/_types.h /usr/include/machine/_types.h
-util.o: /usr/include/string.h /usr/include/strings.h util.h
-util.o: /usr/include/stdlib.h exit.h
+util.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdarg.h
+util.o: util.h /usr/include/stdlib.h exit.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
diff --git a/src/memmenu.c b/src/memmenu.c
index dfce66d..41a18b3 100644
--- a/src/memmenu.c
+++ b/src/memmenu.c
@@ -41,20 +41,21 @@ static const char ident[]="$Id$";
static const char ident_h[]=ESPEC_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 TRACE "trace"
+#define TRACE "trace"
+#define TRACEMEM_WIN 10
/* ---------------------------------------- TYPES
@@ -66,10 +67,26 @@ typedef struct
} 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={NULL,0};
+static Breakpoint bpoint={0,NULL};
static const char *brk=NULL;
static int lodged=FALSE;
@@ -111,15 +128,16 @@ 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. Add a new breakpoint ",
- "6. Clear a breakpoint ",
- "7. Display breakpoints ",
- "8. Clear all breakpoints",
- "9. 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",
+ "R - Reset ",
+ "ESC - Return ",
NULL
};
@@ -171,6 +189,10 @@ void DisplayZ80State(Z80State *s, int y, Uint32 col)
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;
@@ -396,17 +418,43 @@ static void DoDisassemFile(Z80 *z80, const Z80State *s)
}
+static void GetMemTrace(Z80 *z80, MemTrace *t, Z80Word from, int count)
+{
+ int f;
+
+ f=0;
+
+ while(f<count)
+ {
+ Z80Word w;
+
+ w=(Z80Word)SPECReadForDisassem(z80,from)|
+ (Z80Word)SPECReadForDisassem(z80,from+1)<<8;
+
+ t[f].addr=from;
+ t[f].val=w;
+
+ from+=2;
+ f++;
+ }
+}
+
+
static int Instruction(Z80 *z80, Z80Val data)
{
int f;
if (trace)
{
- Z80State s;
+ Trace t;
- Z80GetState(z80,&s);
+ Z80GetState(z80,&t.s);
- fwrite(&s,sizeof s,1,trace);
+ GetMemTrace(z80,t.hl,t.s.HL-(TRACEMEM_WIN/2+1),TRACEMEM_WIN);
+ GetMemTrace(z80,t.de,t.s.DE-(TRACEMEM_WIN/2+1),TRACEMEM_WIN);
+ GetMemTrace(z80,t.sp,t.s.SP-(TRACEMEM_WIN/2+1),TRACEMEM_WIN);
+
+ fwrite(&t,sizeof t,1,trace);
}
for(f=0;f<bpoint.no;f++)
@@ -455,6 +503,27 @@ static void DisableTrace(Z80 *z80)
}
+static void DisplayTraceMem(int x, int y, const char *name,
+ MemTrace *m, Z80Word expect)
+{
+ int f;
+
+ GFXPrint(x,y,GREEN,"%s",name);
+
+ for(f=0;f<TRACEMEM_WIN;f++)
+ {
+ Uint32 paper;
+
+ if (m[f].addr==expect)
+ paper=RED;
+ else
+ paper=BLACK;
+
+ GFXPrintPaper(x,y+f*8+12,GREEN,paper,"%4.4x",m[f].addr);
+ GFXPrintPaper(x+32,y+f*8+12,WHITE,paper," %4.4x",m[f].val);
+ }
+}
+
static void PlaybackTrace(Z80 *z80)
{
FILE *fp;
@@ -463,7 +532,7 @@ static void PlaybackTrace(Z80 *z80)
long pos;
long max_pos;
Z80Word pc;
- Z80State s;
+ Trace t;
fp=fopen(TRACE,"rb");
@@ -475,7 +544,7 @@ static void PlaybackTrace(Z80 *z80)
fseek(fp,0,SEEK_END);
- max_pos=ftell(fp)/sizeof s;
+ max_pos=ftell(fp)/sizeof t;
if (max_pos==0)
{
@@ -500,10 +569,14 @@ static void PlaybackTrace(Z80 *z80)
Centre("TRACE PLAYBACK",0,WHITE);
Centre("Press F1 for help",9,RED);
- fseek(fp,pos*sizeof s,SEEK_SET);
- fread(&s,sizeof s,1,fp);
+ fseek(fp,pos*sizeof t,SEEK_SET);
+ fread(&t,sizeof t,1,fp);
- DisplayZ80State(&s,136,WHITE);
+ DisplayZ80State(&t.s,136,WHITE);
+
+ DisplayTraceMem(0,192,"MEM (SP)",t.sp,t.s.SP);
+ DisplayTraceMem(100,192,"MEM (HL)",t.hl,t.s.HL);
+ DisplayTraceMem(200,192,"MEM (DE)",t.de,t.s.DE);
for(f=0;f<10;f++)
{
@@ -519,9 +592,9 @@ static void PlaybackTrace(Z80 *z80)
else
paper=BLACK;
- GFXPrintPaper(0,y,GREEN,paper,"%4.4x ",s.PC);
+ GFXPrintPaper(0,y,GREEN,paper,"%4.4x ",t.s.PC);
- strcpy(str,Z80Disassemble(z80,&s.PC));
+ strcpy(str,Z80Disassemble(z80,&t.s.PC));
p=strtok(str,";");
GFXPrintPaper(40,y,WHITE,paper,"%s",str);
}
@@ -565,10 +638,10 @@ static void PlaybackTrace(Z80 *z80)
case SDLK_p:
if (EnterAddress("PC to search for?",z80,&pc))
{
- while((rd=fread(&s,sizeof s,1,fp))==1)
+ while((rd=fread(&t,sizeof t,1,fp))==1)
{
pos++;
- if (s.PC==pc)
+ if (t.s.PC==pc)
break;
}
@@ -783,8 +856,15 @@ void MemoryMenu(Z80 *z80)
DoClearBreakpoint(z80);
break;
+ case SDLK_r:
+ if (GUIMessage(eYesNoBox,"RESET","Sure?"))
+ {
+ Z80Reset(z80);
+ SPECReset(z80);
+ }
+ break;
+
case SDLK_ESCAPE:
- case SDLK_9:
quit=TRUE;
break;
diff --git a/src/spec.c b/src/spec.c
index 1cfa2ba..b0dc155 100644
--- a/src/spec.c
+++ b/src/spec.c
@@ -34,6 +34,7 @@ static const char ident[]="$Id$";
#include "gui.h"
#include "config.h"
#include "exit.h"
+#include "util.h"
static const char ident_h[]=ESPEC_SPECH;
@@ -545,6 +546,13 @@ Z80Word SPECReadWord(Z80 *z80, Z80Word addr)
void SPECWriteWord(Z80 *z80, Z80Word addr, Z80Word val)
{
+ if (addr==0xff4e && val==0)
+ {
+ Z80State s;
+ Z80GetState(z80,&s);
+ Debug("Wrote %4.4x to %4.4x @%4.4x\n",val,addr,s.PC);
+ }
+
if (addr>=ROMLEN)
mem[addr]=val&0xff;
@@ -822,6 +830,11 @@ const char *SPECInfo(Z80 *z80)
}
+void SPECReset(Z80 *z80)
+{
+}
+
+
void SPECMount(SPECMountType type, const char *path)
{
switch(type)
diff --git a/src/spec.h b/src/spec.h
index 0dae7e7..69a19d1 100644
--- a/src/spec.h
+++ b/src/spec.h
@@ -57,6 +57,10 @@ const Z80Label *SPECGetLabel(void);
*/
const char *SPECInfo(Z80 *z80);
+/* Called when the machine is reset
+*/
+void SPECReset(Z80 *z80);
+
/* Interfaces for snapshot and device control
*/
diff --git a/src/util.c b/src/util.c
index a8a037d..49b4e2d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,6 +27,7 @@ static const char ident[]="$Id$";
#include <stdio.h>
#include <string.h>
+#include <stdarg.h>
#include "util.h"
#include "exit.h"
@@ -108,4 +109,20 @@ const char *Dirname(const char *path)
}
+void Debug(const char *format, ...)
+{
+ static FILE *fp=NULL;
+ va_list ap;
+
+ if (!fp)
+ fp=fopen("debug.txt","w");
+
+ if (!fp)
+ return;
+
+ va_start(ap,format);
+ vfprintf(fp,format,ap);
+ va_end(ap);
+}
+
/* END OF FILE */
diff --git a/src/util.h b/src/util.h
index 6930b8a..922f641 100644
--- a/src/util.h
+++ b/src/util.h
@@ -60,6 +60,13 @@ const char *Basename(const char *path);
const char *Dirname(const char *path);
+/* Writes the passed text to debug.txt. Note this is interface is not
+ able to be switched on/off, so debug is only used in a transient way
+ (once the bug is fixed, calls to this should be removed).
+*/
+void Debug(const char *format,...);
+
+
#endif