From fcaec358f688bba6760cc44421b35e6b3d90a853 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 7 Oct 2006 00:21:12 +0000 Subject: First working version (3D Monster Maze playable!) --- source/zx81.c | 336 +++++++++++++--------------------------------------------- 1 file changed, 71 insertions(+), 265 deletions(-) (limited to 'source/zx81.c') diff --git a/source/zx81.c b/source/zx81.c index df30dd7..b0ec963 100644 --- a/source/zx81.c +++ b/source/zx81.c @@ -1,7 +1,7 @@ /* - ezx81 - X11 ZX81 emulator + ds81 - Nintendo DS ZX81 emulator - Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk) + Copyright (C) 2006 Ian Cowburn (ianc@noddybox.demon.co.uk) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -22,20 +22,15 @@ Provides the emulation for the ZX81 */ -static const char ident[]="$Id$"; - -#if 0 #include #include #include +#include + #include "zx81.h" -#include "gfx.h" -#include "gui.h" -#include "config.h" -#include "util.h" -#include "exit.h" -static const char ident_h[]=EZX81_ZX81H; +#include "zx81_bin.h" +#include "maze_bin.h" #ifndef TRUE #define TRUE 1 @@ -79,9 +74,6 @@ static int started=FALSE; #define TXT_W 32 #define TXT_H 24 -#define OFF_X (GFX_WIDTH-SCR_W)/2 -#define OFF_Y (GFX_HEIGHT-SCR_H)/2 - static Z80Byte mem[0x10000]; static Z80Word RAMBOT=0; @@ -94,81 +86,27 @@ static Z80Word RAMLEN=0; /* GFX vars */ -static Uint32 white; -static Uint32 black; - +static uint16 *screen; /* The keyboard */ static Z80Byte matrix[8]; -typedef struct -{ - SDLKey key; - int m1,b1,m2,b2; -} MatrixMap; - -#define KY1(m,b) m,1<DE.w); - char path[FILENAME_MAX]; - FILE *fp; - - if (strlen(p)==0) - { - GUIMessage(eMessageBox,"ERROR","Can't load empty filename"); - return; - } - - strcpy(path,SConfig(CONF_TAPEDIR)); - strcat(path,"/"); - strcat(path,p); - strcat(path,".p"); - - if (!(fp=fopen(path,"rb"))) - { - GUIMessage(eMessageBox,"ERROR","Can't load file:\n%s",path); - return; - } - - fread(mem+0x4009,1,0x4000,fp); - fclose(fp); + memcpy(mem+0x4009,maze_bin,maze_bin_size); } static void SaveTape(Z80 *z80) { - const char *p=ConvertFilename(z80->DE.w); - char path[FILENAME_MAX]; - FILE *fp; - Z80Word start; - Z80Word end; - - if (strlen(p)==0) - { - GUIMessage(eMessageBox,"ERROR","Can't save empty filename"); - return; - } - - strcpy(path,SConfig(CONF_TAPEDIR)); - strcat(path,"/"); - strcat(path,p); - strcat(path,".p"); - - if (!(fp=fopen(path,"wb"))) - { - GUIMessage(eMessageBox,"ERROR","Can't write file:\n%s",path); - return; - } - - start=0x4009; - end=(Z80Word)mem[0x4014]|(Z80Word)mem[0x4015]<<8; - - while(start<=end) - putc(mem[start++],fp); - - fclose(fp); -} - - -static void PrintZX81Char(int x,int y,int code,int base) -{ - int cx,cy; - Uint32 fg,bg; - - x*=8; - y*=8; - - if (code&0x80) - { - fg=white; - bg=black; - code-=0x80; - } - else - { - fg=black; - bg=white; - } - - base=base<<8; - base+=code*8; - - for(cy=0;cy<8;cy++) - { - for(cx=0;cx<8;cx++) - { - if (mem[base]&(1<<(7-cx))) - GFXFastPlot(OFF_X+x+cx,OFF_Y+y+cy,fg); - else - GFXFastPlot(OFF_X+x+cx,OFF_Y+y+cy,bg); - } - - base++; - } } @@ -426,7 +274,17 @@ static void DrawScreen(Z80 *z80) while((*scr!=118)&&(xI); + Z80Byte ch = *scr++; + + if (ch&0x80) + { + screen[x+y*32]=(ch&0x3f)|0x40; + } + else + { + screen[x+y*32]=(ch&0x3f); + } + x++; } @@ -437,17 +295,14 @@ static void DrawScreen(Z80 *z80) static void DrawSnow(Z80 *z80) { - int x,y; + uint16 *s; + int f; - x=0; - y=0; + s = screen; - for(x=0;xkey!=SDLK_UNKNOWN) + if (keykey.keysym.sym==m->key) + if (is_pressed) { - if (e->key.state==SDL_PRESSED) - { - matrix[m->m1]&=~m->b1; - - if (m->m2!=-1) - matrix[m->m2]&=~m->b2; - } - else - { - matrix[m->m1]|=m->b1; - - if (m->m2!=-1) - matrix[m->m2]|=m->b2; - } + matrix[key_matrix[key].row]&=~key_matrix[key].bit; } - - m++; + else + { + matrix[key_matrix[key].row]|=key_matrix[key].bit; + } + } + else + { + /* TODO: Joysticks? */ } } @@ -793,21 +617,6 @@ void ZX81WritePort(Z80 *z80, Z80Word port, Z80Byte val) } -Z80Byte ZX81ReadForDisassem(Z80 *z80, Z80Word addr) -{ - return mem[addr&0x7fff]; -} - - -const char *ZX81Info(Z80 *z80) -{ - static char buff[80]; - - sprintf(buff,"T-State/frame: %lu",FRAME_TSTATES); - return buff; -} - - void ZX81Reset(Z80 *z80) { int f; @@ -815,14 +624,11 @@ void ZX81Reset(Z80 *z80) for(f=0;f<8;f++) matrix[f]=0x1f; + Z80Reset(z80); Z80ResetCycles(z80,0); started=FALSE; - - GFXStartFrame(); } -#endif - /* END OF FILE */ -- cgit v1.2.3