summaryrefslogtreecommitdiff
path: root/arm9
diff options
context:
space:
mode:
Diffstat (limited to 'arm9')
-rw-r--r--arm9/data/rom_font.binbin0 -> 16384 bytes
-rw-r--r--arm9/include/zx81.h21
-rw-r--r--arm9/source/keyboard.c6
-rw-r--r--arm9/source/main.c125
-rw-r--r--arm9/source/zx81.c336
5 files changed, 160 insertions, 328 deletions
diff --git a/arm9/data/rom_font.bin b/arm9/data/rom_font.bin
new file mode 100644
index 0000000..be1518e
--- /dev/null
+++ b/arm9/data/rom_font.bin
Binary files 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<<b))
- {
- *ch_data = 1;
- *(ch_data+4096) = 0;
- }
- else
- {
- *ch_data = 0;
- *(ch_data+4096) = 1;
- }
-
- ch_data++;
- }
- }
- }
-
- {
- uint16 *tiles;
- tiles = (uint16*)BG_MAP_RAM(31);
- for(ch=0;ch<128;ch++)
- {
- *(tiles+(ch%32)+(ch/32)*32)=ch;
- }
- }
+ dmaCopy(rom_font_bin,(void *)BG_TILE_RAM(1),rom_font_bin_size);
/* Set up the sub-screen for rotation (basically for use as a framebuffer)
*/
@@ -167,13 +149,64 @@ int main(int argc, char *argv[])
Splash();
+ z80 = Z80Init(ZX81ReadMem,
+ ZX81WriteMem,
+ ZX81ReadPort,
+ ZX81WritePort,
+ NULL);
+
+ if (!z80)
+ {
+ return EXIT_FAILURE;
+ }
+
+ ZX81Init((uint16*)SCREEN_BASE_BLOCK(0), z80);
+
+ SK_DisplayKeyboard(BG_GFX_SUB);
+
+ SK_SetSticky(SK_SHIFT,1);
+
while(1)
{
- static const char *menu[]={"Option #1","A longer option","Short","Wibble Sticks!",NULL};
- char buff[32];
+ SoftKeyEvent ev;
- sprintf(buff,"sel=%d",GUI_Menu(menu));
- FB_Centre(buff,SCREEN_HEIGHT-10,FB_RGB(31,31,31),FB_RGB(0,0,15));
+ Z80Exec(z80);
+
+ while(SK_GetEvent(&ev))
+ {
+ switch(ev.key)
+ {
+ case SK_ABOUT:
+ case SK_CONFIG:
+ if (ev.pressed)
+ {
+ switch(GUI_Menu(main_menu))
+ {
+ case MenuReset:
+ ZX81Reset(z80);
+ break;
+
+ case MenuStickyOn:
+ SK_SetSticky(SK_SHIFT,1);
+ break;
+
+ case MenuStickyOff:
+ SK_SetSticky(SK_SHIFT,0);
+ break;
+
+ case MenuDefineJoystick:
+ break;
+ }
+
+ SK_DisplayKeyboard(BG_GFX_SUB);
+ }
+ break;
+
+ default:
+ ZX81HandleKey(ev.key,ev.pressed);
+ break;
+ }
+ }
}
return 0;
diff --git a/arm9/source/zx81.c b/arm9/source/zx81.c
index df30dd7..b0ec963 100644
--- a/arm9/source/zx81.c
+++ b/arm9/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 <stdlib.h>
#include <stdio.h>
#include <string.h>
+#include <nds.h>
+
#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<<b,-1,-1
-#define KY2(m1,b1,m2,b2) m1,1<<b1,m2,1<<b2
-
-static const MatrixMap keymap[]=
+static struct
{
- {SDLK_1, KY1(3,0)},
- {SDLK_2, KY1(3,1)},
- {SDLK_3, KY1(3,2)},
- {SDLK_4, KY1(3,3)},
- {SDLK_5, KY1(3,4)},
- {SDLK_6, KY1(4,4)},
- {SDLK_7, KY1(4,3)},
- {SDLK_8, KY1(4,2)},
- {SDLK_9, KY1(4,1)},
- {SDLK_0, KY1(4,0)},
-
- {SDLK_a, KY1(1,0)},
- {SDLK_b, KY1(7,4)},
- {SDLK_c, KY1(0,3)},
- {SDLK_d, KY1(1,2)},
- {SDLK_e, KY1(2,2)},
- {SDLK_f, KY1(1,3)},
- {SDLK_g, KY1(1,4)},
- {SDLK_h, KY1(6,4)},
- {SDLK_i, KY1(5,2)},
- {SDLK_j, KY1(6,3)},
- {SDLK_k, KY1(6,2)},
- {SDLK_l, KY1(6,1)},
- {SDLK_m, KY1(7,2)},
- {SDLK_n, KY1(7,3)},
- {SDLK_o, KY1(5,1)},
- {SDLK_p, KY1(5,0)},
- {SDLK_q, KY1(2,0)},
- {SDLK_r, KY1(2,3)},
- {SDLK_s, KY1(1,1)},
- {SDLK_t, KY1(2,4)},
- {SDLK_u, KY1(5,3)},
- {SDLK_v, KY1(0,4)},
- {SDLK_w, KY1(2,1)},
- {SDLK_x, KY1(0,2)},
- {SDLK_y, KY1(5,4)},
- {SDLK_z, KY1(0,1)},
-
- {SDLK_RETURN, KY1(6,0)},
- {SDLK_SPACE, KY1(7,0)},
-
- {SDLK_COMMA, KY1(7,1)}, /* In the right place... */
- {SDLK_PERIOD, KY1(7,1)}, /* ...or the right key... */
-
- {SDLK_BACKSPACE, KY2(0,0,4,0)},
- {SDLK_DELETE, KY2(0,0,4,0)},
- {SDLK_UP, KY2(0,0,4,3)},
- {SDLK_DOWN, KY2(0,0,4,4)},
- {SDLK_LEFT, KY2(0,0,3,4)},
- {SDLK_RIGHT, KY2(0,0,4,2)},
-
- {SDLK_RSHIFT, KY1(0,0)},
- {SDLK_LSHIFT, KY1(0,0)},
-
- {SDLK_UNKNOWN, 0,0,0,0},
-};
+ int row;
+ int bit;
+} key_matrix[]=
+ {
+ {3,0x01}, {3,0x02}, {3,0x04}, {3,0x08}, {3,0x10}, /* 1 - 5 */
+ {4,0x10}, {4,0x08}, {4,0x04}, {4,0x02}, {4,0x01}, /* 6 - 0 */
+ {2,0x01}, {2,0x02}, {2,0x04}, {2,0x08}, {2,0x10}, /* Q - T */
+ {5,0x10}, {5,0x08}, {5,0x04}, {5,0x02}, {5,0x01}, /* Y - P */
+ {1,0x01}, {1,0x02}, {1,0x04}, {1,0x08}, {1,0x10}, /* A - G */
+ {6,0x10}, {6,0x08}, {6,0x04}, {6,0x02}, {6,0x01}, /* H - NL */
+ {0,0x01}, {0,0x02}, {0,0x04}, {0,0x08}, {0,0x10}, /* CAPS - V */
+ {7,0x10}, {7,0x08}, {7,0x04}, {7,0x02}, {7,0x01} /* B - SPACE */
+ };
/* ---------------------------------------- PRIVATE FUNCTIONS
@@ -312,102 +250,12 @@ static const char *ConvertFilename(Z80Word addr)
static void LoadTape(Z80 *z80)
{
- const char *p=ConvertFilename(z80->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)&&(x<TXT_W))
{
- PrintZX81Char(x,y,*scr++,z80->I);
+ 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;x<SCR_W;x++)
+ for(f=0;f<TXT_W*TXT_H;f++)
{
- for(y=0;y<SCR_H;y++)
- {
- GFXFastPlot(OFF_X+x,OFF_Y+y,rand()&1 ? white:black);
- }
+ *s++=8;
}
}
@@ -537,8 +392,6 @@ static int CheckTimers(Z80 *z80, Z80Val val)
{
Z80ResetCycles(z80,val-FRAME_TSTATES);
- GFXLock();
-
if (started && ((mem[CDFLAG] & 0x80) || waitkey))
{
DrawScreen(z80);
@@ -546,7 +399,8 @@ static int CheckTimers(Z80 *z80, Z80Val val)
}
else
{
- DrawSnow(z80);
+ /*DrawSnow(z80);*/
+ DrawScreen(z80);
FRAME_TSTATES=FAST_TSTATES;
}
@@ -559,12 +413,14 @@ static int CheckTimers(Z80 *z80, Z80Val val)
ZX81HouseKeeping(z80);
}
- GFXUnlock();
- GFXEndFrame(TRUE);
- GFXStartFrame();
- }
+ swiWaitForVBlank();
- return TRUE;
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
}
@@ -599,13 +455,11 @@ static int EDCallback(Z80 *z80, Z80Val data)
while(pause-- && !(mem[CDFLAG]&1))
{
- SDL_Event *e;
+ SoftKeyEvent ev;
- e=GFXGetKey();
-
- if (e)
+ while (SK_GetEvent(&ev))
{
- ZX81KeyEvent(e);
+ ZX81HandleKey(ev.key,ev.pressed);
}
CheckTimers(z80,FRAME_TSTATES);
@@ -624,25 +478,15 @@ static int EDCallback(Z80 *z80, Z80Val data)
/* ---------------------------------------- EXPORTED INTERFACES
*/
-void ZX81Init(Z80 *z80)
+void ZX81Init(uint16 *vram, Z80 *z80)
{
- FILE *fp;
Z80Word f;
- if (!(fp=fopen(SConfig(CONF_ROMFILE),"rb")))
- {
- GUIMessage(eMessageBox,
- "ERROR","Failed to open ZX81 ROM\n%s",SConfig(CONF_ROMFILE));
- Exit("");
- }
+ screen = vram;
- if (fread(mem,1,ROMLEN,fp)!=ROMLEN)
- {
- fclose(fp);
- GUIMessage(eMessageBox,
- "ERROR","ROM file must be %d bytes long\n",ROMLEN);
- Exit("");
- }
+ /* Load the ROM
+ */
+ memcpy(mem,zx81_bin,ROMLEN);
/* Patch the ROM
*/
@@ -654,15 +498,11 @@ void ZX81Init(Z80 *z80)
*/
memcpy(mem+ROMLEN,mem,ROMLEN);
- RAMBOT=0x4000;
- /* Memory size (1 or 16K)
+ /* Memory size (16K)
*/
- if (IConfig(CONF_MEMSIZE)==16)
- RAMLEN=0x4000;
- else
- RAMLEN=0x400;
-
+ RAMBOT=0x4000;
+ RAMLEN=0x4000;
RAMTOP=RAMBOT+RAMLEN;
for(f=RAMBOT;f<=RAMTOP;f++)
@@ -670,41 +510,25 @@ void ZX81Init(Z80 *z80)
for(f=0;f<8;f++)
matrix[f]=0x1f;
-
- white=GFXRGB(230,230,230);
- black=GFXRGB(0,0,0);
-
- GFXStartFrame();
}
-void ZX81KeyEvent(SDL_Event *e)
+void ZX81HandleKey(SoftKey key, int is_pressed)
{
- const MatrixMap *m;
-
- m=keymap;
-
- while(m->key!=SDLK_UNKNOWN)
+ if (key<SK_CONFIG)
{
- if (e->key.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 */