summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-09-12 00:12:53 +0000
committerIan C <ianc@noddybox.co.uk>2006-09-12 00:12:53 +0000
commitf7c8435b666daac5a30c88e462727a6c3dbf584d (patch)
treea7b40b5de80b7d28d974b34b33dd03d05ebba174 /source
parentc79c385129225bd04ae15eaac8b6f1cb07d98af1 (diff)
Initial checkin
Diffstat (limited to 'source')
-rw-r--r--source/framebuffer.c255
-rw-r--r--source/gui.c118
-rw-r--r--source/main.c146
3 files changed, 519 insertions, 0 deletions
diff --git a/source/framebuffer.c b/source/framebuffer.c
new file mode 100644
index 0000000..2003e58
--- /dev/null
+++ b/source/framebuffer.c
@@ -0,0 +1,255 @@
+/*
+ dsspec - Nintendo DS Sinclair Spectrum 48K emulator.
+
+ Copyright (C) 2006 Ian Cowburn
+
+ 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 the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id$
+*/
+
+#include <nds.h>
+#include <string.h>
+
+/* ---------------------------------------- STATIC DATA
+*/
+#define WIDTH 256
+#define HEIGHT 192
+
+static uint16 *buff=0;
+
+static uint8 font[]=
+{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x08, 0x08, 0x08, 0x08, 0x00, 0x08, 0x00,
+ 0x00, 0x24, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x24, 0x7e, 0x24, 0x24, 0x7e, 0x24, 0x00,
+ 0x00, 0x10, 0x7c, 0x14, 0x7c, 0x50, 0x7c, 0x10,
+ 0x00, 0x46, 0x26, 0x10, 0x08, 0x64, 0x62, 0x00,
+ 0x00, 0x08, 0x14, 0x08, 0x54, 0x22, 0x5c, 0x00,
+ 0x00, 0x10, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x20, 0x10, 0x10, 0x10, 0x10, 0x20, 0x00,
+ 0x00, 0x04, 0x08, 0x08, 0x08, 0x08, 0x04, 0x00,
+ 0x00, 0x00, 0x28, 0x10, 0x7c, 0x10, 0x28, 0x00,
+ 0x00, 0x00, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x08,
+ 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00,
+ 0x00, 0x00, 0x40, 0x20, 0x10, 0x08, 0x04, 0x00,
+ 0x00, 0x3c, 0x62, 0x52, 0x4a, 0x46, 0x3c, 0x00,
+ 0x00, 0x18, 0x14, 0x10, 0x10, 0x10, 0x7c, 0x00,
+ 0x00, 0x3c, 0x42, 0x40, 0x3c, 0x02, 0x7e, 0x00,
+ 0x00, 0x3c, 0x42, 0x30, 0x40, 0x42, 0x3c, 0x00,
+ 0x00, 0x10, 0x18, 0x14, 0x12, 0x7e, 0x10, 0x00,
+ 0x00, 0x7e, 0x02, 0x3e, 0x40, 0x42, 0x3c, 0x00,
+ 0x00, 0x3c, 0x02, 0x3e, 0x42, 0x42, 0x3c, 0x00,
+ 0x00, 0x7e, 0x40, 0x20, 0x10, 0x08, 0x08, 0x00,
+ 0x00, 0x3c, 0x42, 0x3c, 0x42, 0x42, 0x3c, 0x00,
+ 0x00, 0x3c, 0x42, 0x42, 0x7c, 0x40, 0x3c, 0x00,
+ 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x00,
+ 0x00, 0x00, 0x08, 0x00, 0x00, 0x08, 0x08, 0x04,
+ 0x00, 0x00, 0x20, 0x10, 0x08, 0x10, 0x20, 0x00,
+ 0x00, 0x00, 0x00, 0x7c, 0x00, 0x7c, 0x00, 0x00,
+ 0x00, 0x00, 0x08, 0x10, 0x20, 0x10, 0x08, 0x00,
+ 0x00, 0x3c, 0x42, 0x20, 0x10, 0x00, 0x10, 0x00,
+ 0x00, 0x3c, 0x52, 0x6a, 0x7a, 0x02, 0x3c, 0x00,
+ 0x00, 0x3c, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x00,
+ 0x00, 0x3e, 0x42, 0x3e, 0x42, 0x42, 0x3e, 0x00,
+ 0x00, 0x3c, 0x42, 0x02, 0x02, 0x42, 0x3c, 0x00,
+ 0x00, 0x1e, 0x22, 0x42, 0x42, 0x22, 0x1e, 0x00,
+ 0x00, 0x7e, 0x02, 0x3e, 0x02, 0x02, 0x7e, 0x00,
+ 0x00, 0x7e, 0x02, 0x3e, 0x02, 0x02, 0x02, 0x00,
+ 0x00, 0x3c, 0x42, 0x02, 0x72, 0x42, 0x3c, 0x00,
+ 0x00, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x00,
+ 0x00, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00,
+ 0x00, 0x40, 0x40, 0x40, 0x42, 0x42, 0x3c, 0x00,
+ 0x00, 0x22, 0x12, 0x0e, 0x12, 0x22, 0x42, 0x00,
+ 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x7e, 0x00,
+ 0x00, 0x42, 0x66, 0x5a, 0x42, 0x42, 0x42, 0x00,
+ 0x00, 0x42, 0x46, 0x4a, 0x52, 0x62, 0x42, 0x00,
+ 0x00, 0x3c, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00,
+ 0x00, 0x3e, 0x42, 0x42, 0x3e, 0x02, 0x02, 0x00,
+ 0x00, 0x3c, 0x42, 0x42, 0x4a, 0x52, 0x3c, 0x00,
+ 0x00, 0x3e, 0x42, 0x42, 0x3e, 0x22, 0x42, 0x00,
+ 0x00, 0x3c, 0x02, 0x3c, 0x40, 0x42, 0x3c, 0x00,
+ 0x00, 0x7f, 0x08, 0x08, 0x08, 0x08, 0x08, 0x00,
+ 0x00, 0x42, 0x42, 0x42, 0x42, 0x42, 0x3c, 0x00,
+ 0x00, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00,
+ 0x00, 0x42, 0x42, 0x42, 0x42, 0x5a, 0x24, 0x00,
+ 0x00, 0x42, 0x24, 0x18, 0x18, 0x24, 0x42, 0x00,
+ 0x00, 0x41, 0x22, 0x14, 0x08, 0x08, 0x08, 0x00,
+ 0x00, 0x7e, 0x20, 0x10, 0x08, 0x04, 0x7e, 0x00,
+ 0x00, 0x70, 0x10, 0x10, 0x10, 0x10, 0x70, 0x00,
+ 0x00, 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x00,
+ 0x00, 0x0e, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x00,
+ 0x00, 0x08, 0x1c, 0x2a, 0x08, 0x08, 0x08, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
+ 0x00, 0x38, 0x44, 0x1e, 0x04, 0x04, 0x7e, 0x00,
+ 0x00, 0x00, 0x1c, 0x20, 0x3c, 0x22, 0x3c, 0x00,
+ 0x00, 0x04, 0x04, 0x3c, 0x44, 0x44, 0x3c, 0x00,
+ 0x00, 0x00, 0x38, 0x04, 0x04, 0x04, 0x38, 0x00,
+ 0x00, 0x20, 0x20, 0x3c, 0x22, 0x22, 0x3c, 0x00,
+ 0x00, 0x00, 0x1c, 0x22, 0x1e, 0x02, 0x3c, 0x00,
+ 0x00, 0x30, 0x08, 0x18, 0x08, 0x08, 0x08, 0x00,
+ 0x00, 0x00, 0x3c, 0x22, 0x22, 0x3c, 0x20, 0x1c,
+ 0x00, 0x02, 0x02, 0x1e, 0x22, 0x22, 0x22, 0x00,
+ 0x00, 0x08, 0x00, 0x0c, 0x08, 0x08, 0x1c, 0x00,
+ 0x00, 0x20, 0x00, 0x20, 0x20, 0x20, 0x24, 0x18,
+ 0x00, 0x04, 0x14, 0x0c, 0x0c, 0x14, 0x24, 0x00,
+ 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x30, 0x00,
+ 0x00, 0x00, 0x16, 0x2a, 0x2a, 0x2a, 0x2a, 0x00,
+ 0x00, 0x00, 0x1e, 0x22, 0x22, 0x22, 0x22, 0x00,
+ 0x00, 0x00, 0x1c, 0x22, 0x22, 0x22, 0x1c, 0x00,
+ 0x00, 0x00, 0x1e, 0x22, 0x22, 0x1e, 0x02, 0x02,
+ 0x00, 0x00, 0x3c, 0x22, 0x22, 0x3c, 0x20, 0x60,
+ 0x00, 0x00, 0x38, 0x04, 0x04, 0x04, 0x04, 0x00,
+ 0x00, 0x00, 0x1c, 0x02, 0x1c, 0x20, 0x1e, 0x00,
+ 0x00, 0x08, 0x1c, 0x08, 0x08, 0x08, 0x30, 0x00,
+ 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x1c, 0x00,
+ 0x00, 0x00, 0x22, 0x22, 0x14, 0x14, 0x08, 0x00,
+ 0x00, 0x00, 0x22, 0x2a, 0x2a, 0x2a, 0x14, 0x00,
+ 0x00, 0x00, 0x22, 0x14, 0x08, 0x14, 0x22, 0x00,
+ 0x00, 0x00, 0x22, 0x22, 0x22, 0x3c, 0x20, 0x1c,
+ 0x00, 0x00, 0x3e, 0x10, 0x08, 0x04, 0x3e, 0x00,
+ 0x00, 0x70, 0x10, 0x0c, 0x10, 0x10, 0x70, 0x00,
+ 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
+ 0x00, 0x0e, 0x08, 0x30, 0x08, 0x08, 0x0e, 0x00,
+ 0x00, 0x28, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x3c, 0x42, 0x99, 0x85, 0x85, 0x99, 0x42, 0x3c
+};
+
+/* ---------------------------------------- PUBLIC INTERFACES
+*/
+void FB_Init(uint16 *vram)
+{
+ buff=vram;
+}
+
+
+void FB_Print(const char *text, int x, int y, int colour, int paper)
+{
+ uint16 *base;
+
+ base=buff+y*WIDTH+x;
+
+ while(*text)
+ {
+ int x,y;
+ int ch;
+
+ ch=((*text)-32)*8;
+
+ for(y=0;y<8;y++)
+ {
+ for(x=0;x<8;x++)
+ {
+ if (font[ch]&(1<<x))
+ {
+ *(base+x+y*WIDTH)=colour;
+ }
+ else
+ {
+ if (paper!=-1)
+ {
+ *(base+x+y*WIDTH)=paper;
+ }
+ }
+ }
+
+ ch++;
+ }
+
+ base+=8;
+ text++;
+ }
+}
+
+
+void FB_Centre(const char *text, int y, int colour, int paper)
+{
+ FB_Print(text,WIDTH/2-strlen(text)*4,y,colour,paper);
+}
+
+
+void FB_HLine(int x1, int x2, int y, int colour)
+{
+ uint16 *line;
+
+ line=buff+y*WIDTH+x1;
+
+ while(x1<=x2)
+ {
+ *line++=colour;
+ x1++;
+ }
+}
+
+
+void FB_VLine(int x, int y1, int y2, int colour)
+{
+ uint16 *line;
+
+ line=buff+y1*WIDTH+x;
+
+ while(y1<=y2)
+ {
+ *line=colour;
+ line+=WIDTH;
+ y1++;
+ }
+}
+
+
+void FB_Box(int x, int y, int w, int h, int colour)
+{
+ FB_HLine(x,x+w-1,y,colour);
+ FB_HLine(x,x+w-1,y+h-1,colour);
+ FB_VLine(x,y,y+h-1,colour);
+ FB_VLine(x+w-1,y,y+h-1,colour);
+}
+
+
+void FB_FillBox(int x, int y, int w, int h, int colour)
+{
+ int f;
+ uint16 *base;
+
+ base=buff+x+y*WIDTH;
+
+ while(h--)
+ {
+ for(f=0;f<w;f++)
+ {
+ *(base+f)=colour;
+ }
+
+ base+=WIDTH;
+ }
+}
+
+
+void FB_Clear(void)
+{
+ uint16 *p;
+ int f;
+
+ f=WIDTH*HEIGHT;
+ p=buff;
+
+ while(f--)
+ {
+ *p++=0x8000;
+ }
+}
diff --git a/source/gui.c b/source/gui.c
new file mode 100644
index 0000000..c91f846
--- /dev/null
+++ b/source/gui.c
@@ -0,0 +1,118 @@
+/*
+ dsspec - Nintendo DS Sinclair Spectrum 48K emulator.
+
+ Copyright (C) 2006 Ian Cowburn
+
+ 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 the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id$
+*/
+
+#include <nds.h>
+#include <string.h>
+
+#include "framebuffer.h"
+
+
+/* ---------------------------------------- PUBLIC INTERFACES
+*/
+int GUI_Menu(const char *opts[])
+{
+ int x,y;
+ int h;
+ int w;
+ int no;
+ int sel;
+ int f;
+ bool done;
+ bool defer;
+
+ w=0;
+ h=0;
+ sel=0;
+ done=false;
+ defer=false;
+
+ for(no=0;opts[no];no++)
+ {
+ h+=16;
+
+ if (strlen(opts[no])>w)
+ {
+ w=strlen(opts[no]);
+ }
+ }
+
+ w=w*8+16;
+
+ x=SCREEN_WIDTH/2-w/2;
+ y=SCREEN_HEIGHT/2-h/2;
+
+ while(!done)
+ {
+ uint32 key=0;
+
+ FB_FillBox(x,y,w,h,FB_RGB(0,0,0));
+ FB_Box(x,y,w,h,FB_RGB(31,31,31));
+ FB_FillBox(x+1,y+sel*16+1,w-2,14,FB_RGB(8,8,31));
+
+ for(f=0;f<no;f++)
+ {
+ FB_Centre(opts[f],y+4+f*16,FB_RGB(31,31,31),-1);
+ }
+
+ do
+ {
+ swiWaitForVBlank();
+ } while(!defer && !(key=keysDownRepeat()));
+
+ if (defer)
+ {
+ do
+ {
+ swiWaitForVBlank();
+ } while (keysHeld()&KEY_TOUCH);
+ done=true;
+ }
+ else
+ {
+ if (key & (KEY_A|KEY_B|KEY_X|KEY_Y))
+ {
+ done=true;
+ }
+ else if ((key & KEY_UP) && sel)
+ {
+ sel--;
+ }
+ else if ((key & KEY_DOWN) && sel<no-1)
+ {
+ sel++;
+ }
+ else if (key & KEY_TOUCH)
+ {
+ touchPosition tp=touchReadXY();
+
+ if (tp.px>=x && tp.px<(w+w) && tp.py>=y && tp.py<(y+h))
+ {
+ defer=true;
+ sel=(tp.py-y)/16;
+ }
+ }
+ }
+ }
+
+ return sel;
+}
+
diff --git a/source/main.c b/source/main.c
new file mode 100644
index 0000000..2cf5579
--- /dev/null
+++ b/source/main.c
@@ -0,0 +1,146 @@
+/*
+ dsspec - Nintendo DS Sinclair Spectrum 48K emulator.
+
+ Copyright (C) 2006 Ian Cowburn
+
+ 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 the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id$
+*/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <nds.h>
+
+#include "framebuffer.h"
+#include "gui.h"
+
+#include "splashimg_bin.h"
+
+/* ---------------------------------------- STATIC DATA
+*/
+
+
+/* ---------------------------------------- DISPLAY FUNCS
+*/
+static void VBlankFunc(void)
+{
+ scanKeys();
+}
+
+static void Splash(void)
+{
+ static const char *text[]=
+ {
+ "DS-SPEC",
+ "\177 2006 Ian C",
+ " ",
+ "SPECTRUM ROM",
+ "\177 Amstrad PLC",
+ " ",
+ "Manic Miner",
+ "by Matthew Smith",
+ " ",
+ "Ant Attack by",
+ "Sandy White/Angela Sutherland",
+ " ",
+ "Thrust by",
+ "Jeremy Smith and D.Lowe",
+ " ",
+ "Only play these images if",
+ "you legallly own a copy.",
+ " ",
+ "PRESS A TO CONTINUE",
+ " ",
+ "http://www.noddybox.co.uk/",
+ NULL
+ };
+
+ sImage img;
+ int f;
+
+ loadPCX(splashimg_bin,&img);
+ image8to16(&img);
+ dmaCopy(img.data8,BG_GFX,SCREEN_WIDTH*SCREEN_HEIGHT*2);
+
+ FB_Clear();
+
+ for(f=0;f<SCREEN_HEIGHT;f++)
+ {
+ FB_HLine(0,SCREEN_WIDTH-1,f,FB_RGB(f/8,0,0));
+ }
+
+ FB_Box(0,0,SCREEN_WIDTH,SCREEN_HEIGHT,FB_RGB(31,31,31));
+
+ for(f=0;text[f];f++)
+ {
+ FB_Centre(text[f],10+f*8,FB_RGB(31,31,31),-1);
+ }
+
+ while(!(keysDown() & KEY_A))
+ {
+ swiWaitForVBlank();
+ }
+}
+
+
+/* ---------------------------------------- MAIN
+*/
+int main(int argc, char *argv[])
+{
+ powerON(POWER_ALL_2D);
+
+ videoSetMode(MODE_5_2D | DISPLAY_BG2_ACTIVE);
+
+ vramSetBankA(VRAM_A_MAIN_BG_0x6000000);
+ BG2_CR = BG_BMP16_256x256;
+ BG2_XDX = 0x100;
+ BG2_XDY = 0;
+ BG2_YDX = 0;
+ BG2_YDY = 0x100;
+ BG2_CX = 0;
+ BG2_CY = 0;
+
+ videoSetModeSub(MODE_5_2D | DISPLAY_BG2_ACTIVE);
+
+ vramSetBankC(VRAM_C_SUB_BG_0x6200000);
+ SUB_BG2_CR = BG_BMP16_256x256;
+ SUB_BG2_XDX = 0x100;
+ SUB_BG2_XDY = 0;
+ SUB_BG2_YDX = 0;
+ SUB_BG2_YDY = 0x100;
+ SUB_BG2_CX = 0;
+ SUB_BG2_CY = 0;
+
+ irqInit();
+ irqSet(IRQ_VBLANK,VBlankFunc);
+
+ keysSetRepeat(30,15);
+
+ FB_Init(BG_GFX_SUB);
+
+ Splash();
+
+ while(1)
+ {
+ static const char *menu[]={"Option #1","A longer option","Short","Wibble Sticks!",NULL};
+ char buff[32];
+
+ sprintf(buff,"sel=%d",GUI_Menu(menu));
+ FB_Centre(buff,SCREEN_HEIGHT-10,FB_RGB(31,31,31),FB_RGB(0,0,15));
+ }
+
+ return 0;
+}