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!) --- arm9/data/rom_font.bin | Bin 0 -> 16384 bytes arm9/include/zx81.h | 21 ++-- arm9/source/keyboard.c | 6 +- arm9/source/main.c | 125 +++++++++++------- arm9/source/zx81.c | 336 +++++++++++-------------------------------------- data/rom_font.bin | Bin 0 -> 16384 bytes include/zx81.h | 21 ++-- source/keyboard.c | 6 +- source/main.c | 125 +++++++++++------- source/zx81.c | 336 +++++++++++-------------------------------------- 10 files changed, 320 insertions(+), 656 deletions(-) create mode 100644 arm9/data/rom_font.bin create mode 100644 data/rom_font.bin diff --git a/arm9/data/rom_font.bin b/arm9/data/rom_font.bin new file mode 100644 index 0000000..be1518e Binary files /dev/null and b/arm9/data/rom_font.bin differ diff --git a/arm9/include/zx81.h b/arm9/include/zx81.h index 5f097bf..c1364d1 100644 --- a/arm9/include/zx81.h +++ b/arm9/include/zx81.h @@ -1,8 +1,8 @@ /* - 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 @@ -24,20 +24,20 @@ */ -#ifndef EZX81_ZX81H -#define EZX81_ZX81H "$Id$" +#ifndef DS81_ZX81_H +#define DS81_ZX81_H #include "z80.h" -#include "SDL.h" +#include "keyboard.h" /* Initialise the ZX81 */ -void ZX81Init(Z80 *z80); +void ZX81Init(uint16 *vram, Z80 *z80); /* Handle keypresses */ -void ZX81KeyEvent(SDL_Event *e); +void ZX81HandleKey(SoftKey k, int is_pressed); /* Interfaces for the Z80 */ @@ -45,13 +45,6 @@ Z80Byte ZX81ReadMem(Z80 *z80, Z80Word addr); void ZX81WriteMem(Z80 *z80, Z80Word addr, Z80Byte val); Z80Byte ZX81ReadPort(Z80 *z80, Z80Word port); void ZX81WritePort(Z80 *z80, Z80Word port, Z80Byte val); -Z80Byte ZX81ReadForDisassem(Z80 *z80, Z80Word addr); - -/* Interfaces for memory menu -*/ -const char *ZX81Info(Z80 *z80); -void ZX81Reset(Z80 *z80); - #endif diff --git a/arm9/source/keyboard.c b/arm9/source/keyboard.c index d33346d..31b39a1 100644 --- a/arm9/source/keyboard.c +++ b/arm9/source/keyboard.c @@ -202,10 +202,10 @@ int SK_GetEvent(SoftKeyEvent *ev) { int x,y; - x = 2 + (f % 10) * 25; - y = 36 + (f / 10) * 30; + x = 3 + (f % 10) * 25; + y = 37 + (f / 10) * 30; - FB_Box(x, y, 26, 19, key_state[f].new_state ? white:black); + FB_Box(x, y, 25, 18, key_state[f].new_state ? white:black); } } } diff --git a/arm9/source/main.c b/arm9/source/main.c index a2b0565..43c8993 100644 --- a/arm9/source/main.c +++ b/arm9/source/main.c @@ -26,12 +26,32 @@ #include "framebuffer.h" #include "gui.h" +#include "keyboard.h" +#include "z80.h" +#include "zx81.h" #include "splashimg_bin.h" -#include "zx81_bin.h" +#include "rom_font_bin.h" /* ---------------------------------------- STATIC DATA */ +static const char *main_menu[]= + { + "Reset ZX81", + "Sticky Keys On", + "Sticky Keys Off", + "Define Joystick", + "Cancel", + NULL + }; + +typedef enum +{ + MenuReset, + MenuStickyOn, + MenuStickyOff, + MenuDefineJoystick +} MenuOpt; /* ---------------------------------------- DISPLAY FUNCS @@ -87,8 +107,7 @@ static void Splash(void) */ int main(int argc, char *argv[]) { - int ch; - uint8 *ch_data; + Z80 *z80; powerON(POWER_ALL_2D); @@ -99,51 +118,14 @@ int main(int argc, char *argv[]) vramSetBankA(VRAM_A_MAIN_BG_0x6000000); vramSetBankB(VRAM_B_MAIN_BG_0x6020000); - BG0_CR = BG_COLOR_256|BG_MAP_BASE(31)|BG_TILE_BASE(0); + BG0_CR = BG_COLOR_256|BG_MAP_BASE(0)|BG_TILE_BASE(1); BG0_X0 = 0; BG0_Y0 = 0; BG_PALETTE[0] = RGB15(31,31,31); BG_PALETTE[1] = RGB15(0,0,0); - ch_data = (uint8*)BG_TILE_RAM(0); - - for(ch=0;ch<64;ch++) - { - int r; - - for(r=0;r<8;r++) - { - int b; - int rd; - - rd=zx81_bin[0x1e00+ch*8+r]; - for(b=7;b>=0;b--) - { - if (rd&(1< #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 */ diff --git a/data/rom_font.bin b/data/rom_font.bin new file mode 100644 index 0000000..be1518e Binary files /dev/null and b/data/rom_font.bin differ diff --git a/include/zx81.h b/include/zx81.h index 5f097bf..c1364d1 100644 --- a/include/zx81.h +++ b/include/zx81.h @@ -1,8 +1,8 @@ /* - 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 @@ -24,20 +24,20 @@ */ -#ifndef EZX81_ZX81H -#define EZX81_ZX81H "$Id$" +#ifndef DS81_ZX81_H +#define DS81_ZX81_H #include "z80.h" -#include "SDL.h" +#include "keyboard.h" /* Initialise the ZX81 */ -void ZX81Init(Z80 *z80); +void ZX81Init(uint16 *vram, Z80 *z80); /* Handle keypresses */ -void ZX81KeyEvent(SDL_Event *e); +void ZX81HandleKey(SoftKey k, int is_pressed); /* Interfaces for the Z80 */ @@ -45,13 +45,6 @@ Z80Byte ZX81ReadMem(Z80 *z80, Z80Word addr); void ZX81WriteMem(Z80 *z80, Z80Word addr, Z80Byte val); Z80Byte ZX81ReadPort(Z80 *z80, Z80Word port); void ZX81WritePort(Z80 *z80, Z80Word port, Z80Byte val); -Z80Byte ZX81ReadForDisassem(Z80 *z80, Z80Word addr); - -/* Interfaces for memory menu -*/ -const char *ZX81Info(Z80 *z80); -void ZX81Reset(Z80 *z80); - #endif diff --git a/source/keyboard.c b/source/keyboard.c index d33346d..31b39a1 100644 --- a/source/keyboard.c +++ b/source/keyboard.c @@ -202,10 +202,10 @@ int SK_GetEvent(SoftKeyEvent *ev) { int x,y; - x = 2 + (f % 10) * 25; - y = 36 + (f / 10) * 30; + x = 3 + (f % 10) * 25; + y = 37 + (f / 10) * 30; - FB_Box(x, y, 26, 19, key_state[f].new_state ? white:black); + FB_Box(x, y, 25, 18, key_state[f].new_state ? white:black); } } } diff --git a/source/main.c b/source/main.c index a2b0565..43c8993 100644 --- a/source/main.c +++ b/source/main.c @@ -26,12 +26,32 @@ #include "framebuffer.h" #include "gui.h" +#include "keyboard.h" +#include "z80.h" +#include "zx81.h" #include "splashimg_bin.h" -#include "zx81_bin.h" +#include "rom_font_bin.h" /* ---------------------------------------- STATIC DATA */ +static const char *main_menu[]= + { + "Reset ZX81", + "Sticky Keys On", + "Sticky Keys Off", + "Define Joystick", + "Cancel", + NULL + }; + +typedef enum +{ + MenuReset, + MenuStickyOn, + MenuStickyOff, + MenuDefineJoystick +} MenuOpt; /* ---------------------------------------- DISPLAY FUNCS @@ -87,8 +107,7 @@ static void Splash(void) */ int main(int argc, char *argv[]) { - int ch; - uint8 *ch_data; + Z80 *z80; powerON(POWER_ALL_2D); @@ -99,51 +118,14 @@ int main(int argc, char *argv[]) vramSetBankA(VRAM_A_MAIN_BG_0x6000000); vramSetBankB(VRAM_B_MAIN_BG_0x6020000); - BG0_CR = BG_COLOR_256|BG_MAP_BASE(31)|BG_TILE_BASE(0); + BG0_CR = BG_COLOR_256|BG_MAP_BASE(0)|BG_TILE_BASE(1); BG0_X0 = 0; BG0_Y0 = 0; BG_PALETTE[0] = RGB15(31,31,31); BG_PALETTE[1] = RGB15(0,0,0); - ch_data = (uint8*)BG_TILE_RAM(0); - - for(ch=0;ch<64;ch++) - { - int r; - - for(r=0;r<8;r++) - { - int b; - int rd; - - rd=zx81_bin[0x1e00+ch*8+r]; - for(b=7;b>=0;b--) - { - if (rd&(1< #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