From f295f65db435ab7cb384e44e1dd74dc6d7a34853 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sun, 20 Aug 2006 22:31:42 +0000 Subject: Initial compilable version --- emma.c | 156 ++++++++++++++++++++++++----------------------------------------- 1 file changed, 57 insertions(+), 99 deletions(-) (limited to 'emma.c') diff --git a/emma.c b/emma.c index f2ae2c2..41bdb1a 100644 --- a/emma.c +++ b/emma.c @@ -31,7 +31,6 @@ static const char id[]="$Id$"; #include #include "z80.h" -#include "expr.h" #define TRUE 1 @@ -41,10 +40,17 @@ static const char id[]="$Id$"; #define LO(w) ((w)&0xff) #define MK(h,l) (((Z80Word)(h))<<8|(l)) +typedef struct +{ + Z80Word address; + const char *label; +} Z80Label; + /* ---------------------------------------- GLOBALS */ static Z80 *z80; static Z80Byte mem[0x10000]; +static int memctl[256]; static sig_atomic_t stop=FALSE; static int quit=FALSE; @@ -68,6 +74,7 @@ static void Log(const char *format, ...); static void Run(char *p); static Z80Word Address(const char *p); static const char *GetLabel(Z80 *z80, Z80Word addr); +static const char *Disassemble(Z80Word *addr); /* ---------------------------------------- SIGNALS @@ -176,7 +183,7 @@ static void DisplayState(void) Log("I=%2.2x IM=%2.2x R=%2.2x ",s.I,s.IM,s.R); Log("IFF1=%2.2x IFF2=%2.2x\n",s.IFF1,s.IFF2); Log("%4.4x: ",s.PC); - Log("%s\n",Z80Disassemble(z80,&s.PC)); + Log("%s\n",Disassemble(&s.PC)); } @@ -195,12 +202,12 @@ static int StrEq(const char *a, const char *b) } -static int Expand(void *client, const char *p, long *res) +static int Expand(const char *p, long *res) { Z80State s; int ok=TRUE; - Z80GetState((Z80 *)client,&s); + Z80GetState(z80,&s); if (StrEq(p,"AF")) *res=s.AF; @@ -280,21 +287,21 @@ static int Expand(void *client, const char *p, long *res) n=Address(p+1); *res=MK(mem[n+1],mem[n]); } - else /* Check for labels */ + else /* Check for labels */ { - int f; - - ok=FALSE; - - for(f=0;label && label[f].label;f++) - { - if (StrEq(p,label[f].label)) - { - *res=label[f].address; - ok=TRUE; - break; - } - } + int f; + + ok=FALSE; + + for(f=0;label && label[f].label;f++) + { + if (StrEq(p,label[f].label)) + { + *res=label[f].address; + ok=TRUE; + break; + } + } } return ok; @@ -305,19 +312,29 @@ static Z80Word Address(const char *p) { long e=0; - if (!ExprEval(p,&e,Expand,z80)) - Log("%s\n",ExprError()); + if (!Expand(p,&e)) + { + e=strtol(p,NULL,0); + } return (Z80Word)e; } +static const char *Disassemble(Z80Word *addr) +{ + return Z80Disassemble(z80,addr); +} + + static Z80Val Val(const char *p) { long e=0; - if (!ExprEval(p,&e,Expand,z80)) - Log("%s\n",ExprError()); + if (!Expand(p,&e)) + { + e=strtol(p,NULL,0); + } return (Z80Val)e; } @@ -527,7 +544,7 @@ static void DoDis(int no, const char *arg[]) if ((l=GetLabel(z80,orig))) Log("*** %s ***\n",l); - Log("%4.4x: %s\n",orig,Z80Disassemble(z80,&addr)); + Log("%4.4x: %s\n",orig,Disassemble(&addr)); prev=len; len-=(addr-orig); } @@ -707,6 +724,8 @@ static void DoRun(int no, const char *arg[]) static void DoUntil(int no, const char *arg[]) { + Log("No supported\n"); +#if 0 if (no<2) { Log("Missing arguments\n"); @@ -744,6 +763,7 @@ static void DoUntil(int no, const char *arg[]) } stop=FALSE; +#endif } @@ -766,16 +786,23 @@ static void DoSilent(int no, const char *arg[]) static void DoRange(int no, const char *arg[]) { + int f; + if (no<3) { Log("Missing arguments\n"); return; } - bottom=Address(arg[1]); - top=Address(arg[2]); + bottom=(Address(arg[1]))/256; + top=Address(arg[2])/256; + + for(f=0;f<256;f++) + { + memctl[f]=(f>=bottom && f<=top); + } - Log("Writable memory between 0x%4.4x and 0x%4.4x\n",bottom,top); + Log("Writable memory between 0x%4.4x and 0x%4.4x\n",bottom*256,top*256); } @@ -921,77 +948,6 @@ static void Run(char *cmd) /* ---------------------------------------- MEMORY */ -static Z80Byte ReadMem(Z80 *z80, Z80Word addr) -{ - if (mem_trace) - Log("PEEK(0x%4.4x)=0x%2.2x\n",addr,mem[addr]); - - return mem[addr]; -} - - -static Z80Word ReadMemWord(Z80 *z80, Z80Word addr) -{ - Z80Word w; - - w=MK(mem[addr+1],mem[addr]); - - if (mem_trace) - Log("PEEKW(0x%4.4x)=0x%4.4x\n",addr,w); - - return w; -} - - -static Z80Byte ReadMemDis(Z80 *z80, Z80Word addr) -{ - return mem[addr]; -} - - -static void WriteMem(Z80 *z80, Z80Word addr, Z80Byte val) -{ - if (addr>=bottom && addr<=top) - { - mem[addr]=val; - - if (mem_trace) - Log("POKE(0x%4.4x)=0x%2.2x\n",addr,mem[addr]); - } - else - { - if (mem_trace) - Log("POKE(0x%4.4x)=0x%2.2x [BLOCKED]\n",addr,mem[addr]); - } -} - - -static void WriteMemWord(Z80 *z80, Z80Word addr, Z80Word val) -{ - static const char *block_str[3]={""," [ONE BYTE BLOCKED]"," [BLOCKED]"}; - Z80Byte lo,hi; - int block=0; - - lo=LO(val); - hi=HI(val); - - if (addr>=bottom && addr<=top) - mem[addr]=lo; - else - block++; - - addr++; - - if (addr>=bottom && addr<=top) - mem[addr]=hi; - else - block++; - - if (mem_trace) - Log("POKEW(0x%4.4x)=0x%4.4x%s\n",addr,val,block_str[block]); -} - - static Z80Byte ReadPort(Z80 *z80, Z80Word addr) { Z80Byte b=0xff; @@ -1131,9 +1087,11 @@ int main(int argc, char *argv[]) { const char *autoarg[2]={".","auto"}; char buff[1024]; + int f; + + for(f=0;f<256;f++) memctl[f]=1; - z80=Z80Init(WriteMem,ReadMem,WriteMemWord,ReadMemWord, - WritePort,ReadPort,ReadMemDis); + z80=Z80Init(mem,memctl,WritePort,ReadPort); if (!z80) { -- cgit v1.2.3