summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2006-08-15 23:44:02 +0000
committerIan C <ianc@noddybox.co.uk>2006-08-15 23:44:02 +0000
commit9ef67264f5ed15b2bbf8ac4f18228b7d47ef0ccc (patch)
tree43d7bc74070023969fc961b7482e9ddf2f3eabe5
parentec585ef29cdbb8d8d5ddb4cbfdecb9111678d138 (diff)
Development checkin
-rw-r--r--.cvsignore5
-rw-r--r--Makefile136
-rw-r--r--arm9/Makefile136
-rw-r--r--arm9/data/keyb.binbin0 -> 19175 bytes
-rw-r--r--arm9/data/maze.binbin0 -> 10553 bytes
-rw-r--r--arm9/data/splashimg.binbin0 -> 26722 bytes
-rw-r--r--arm9/data/zx81.binbin0 -> 8192 bytes
-rw-r--r--arm9/include/framebuffer.h36
-rw-r--r--arm9/include/gui.h27
-rw-r--r--arm9/include/kbd81.h76
-rw-r--r--arm9/source/framebuffer.c255
-rw-r--r--arm9/source/gui.c118
-rw-r--r--arm9/source/main.c137
-rw-r--r--data/keyb.binbin0 -> 19175 bytes
-rw-r--r--data/maze.binbin0 -> 10553 bytes
-rw-r--r--data/splashimg.binbin0 -> 26722 bytes
-rw-r--r--data/zx81.binbin0 -> 8192 bytes
-rw-r--r--include/framebuffer.h36
-rw-r--r--include/gui.h27
-rw-r--r--include/kbd81.h76
-rw-r--r--source/framebuffer.c255
-rw-r--r--source/gui.c118
-rw-r--r--source/main.c137
23 files changed, 1575 insertions, 0 deletions
diff --git a/.cvsignore b/.cvsignore
new file mode 100644
index 0000000..6b59bb1
--- /dev/null
+++ b/.cvsignore
@@ -0,0 +1,5 @@
+build
+ds81.arm9
+ds81.ds.gba
+ds81.elf
+ds81.nds \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..93d2484
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,136 @@
+# This is a generic DS makefile, as taken from the libnds example programs.
+#
+
+#-------------------------------------------------------------------------------
+.SUFFIXES:
+#-------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
+endif
+
+include $(DEVKITARM)/ds_rules
+
+#-------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing extra header files
+#-------------------------------------------------------------------------------
+TARGET := $(shell basename $(CURDIR))
+BUILD := build
+SOURCES := source gbagfx
+DATA := data
+INCLUDES := include gbagfx
+
+#-------------------------------------------------------------------------------
+# options for code generation
+#-------------------------------------------------------------------------------
+ARCH := -mthumb -mthumb-interwork
+
+# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
+# *insists* it has a FPU or VFP, and it won't take no for an answer!
+CFLAGS := -g -Wall -O2\
+ -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer\
+ -ffast-math \
+ $(ARCH)
+
+CFLAGS += $(INCLUDE) -DARM9
+CXXFLAGS := $(CFLAGS)
+
+ASFLAGS := -g $(ARCH)
+LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
+
+#-------------------------------------------------------------------------------
+# any extra libraries we wish to link with the project
+#-------------------------------------------------------------------------------
+LIBS := -lfat -lnds9
+
+
+#-------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#-------------------------------------------------------------------------------
+LIBDIRS := $(LIBNDS)
+
+#-------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add
+# additional rules for different file extensions
+#-------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#-------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+ export LD := $(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+ export LD := $(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+export OFILES := $(addsuffix .o,$(BINFILES)) \
+ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+
+export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD)
+
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+.PHONY: $(BUILD) clean
+
+#---------------------------------------------------------------------------------
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+clean:
+ @echo clean ...
+ @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba
+
+
+#---------------------------------------------------------------------------------
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(OUTPUT).ds.gba : $(OUTPUT).nds
+$(OUTPUT).nds : $(OUTPUT).arm9
+$(OUTPUT).arm9 : $(OUTPUT).elf
+$(OUTPUT).elf : $(OFILES)
+
+#---------------------------------------------------------------------------------
+%.bin.o : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ @$(bin2o)
+
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
diff --git a/arm9/Makefile b/arm9/Makefile
new file mode 100644
index 0000000..93d2484
--- /dev/null
+++ b/arm9/Makefile
@@ -0,0 +1,136 @@
+# This is a generic DS makefile, as taken from the libnds example programs.
+#
+
+#-------------------------------------------------------------------------------
+.SUFFIXES:
+#-------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
+endif
+
+include $(DEVKITARM)/ds_rules
+
+#-------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing extra header files
+#-------------------------------------------------------------------------------
+TARGET := $(shell basename $(CURDIR))
+BUILD := build
+SOURCES := source gbagfx
+DATA := data
+INCLUDES := include gbagfx
+
+#-------------------------------------------------------------------------------
+# options for code generation
+#-------------------------------------------------------------------------------
+ARCH := -mthumb -mthumb-interwork
+
+# note: arm9tdmi isn't the correct CPU arch, but anything newer and LD
+# *insists* it has a FPU or VFP, and it won't take no for an answer!
+CFLAGS := -g -Wall -O2\
+ -mcpu=arm9tdmi -mtune=arm9tdmi -fomit-frame-pointer\
+ -ffast-math \
+ $(ARCH)
+
+CFLAGS += $(INCLUDE) -DARM9
+CXXFLAGS := $(CFLAGS)
+
+ASFLAGS := -g $(ARCH)
+LDFLAGS = -specs=ds_arm9.specs -g $(ARCH) -mno-fpu -Wl,-Map,$(notdir $*.map)
+
+#-------------------------------------------------------------------------------
+# any extra libraries we wish to link with the project
+#-------------------------------------------------------------------------------
+LIBS := -lfat -lnds9
+
+
+#-------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#-------------------------------------------------------------------------------
+LIBDIRS := $(LIBNDS)
+
+#-------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add
+# additional rules for different file extensions
+#-------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#-------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+ export LD := $(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+ export LD := $(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+export OFILES := $(addsuffix .o,$(BINFILES)) \
+ $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+
+export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD)
+
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+.PHONY: $(BUILD) clean
+
+#---------------------------------------------------------------------------------
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+clean:
+ @echo clean ...
+ @rm -fr $(BUILD) $(TARGET).elf $(TARGET).nds $(TARGET).arm9 $(TARGET).ds.gba
+
+
+#---------------------------------------------------------------------------------
+else
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(OUTPUT).ds.gba : $(OUTPUT).nds
+$(OUTPUT).nds : $(OUTPUT).arm9
+$(OUTPUT).arm9 : $(OUTPUT).elf
+$(OUTPUT).elf : $(OFILES)
+
+#---------------------------------------------------------------------------------
+%.bin.o : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ @$(bin2o)
+
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
diff --git a/arm9/data/keyb.bin b/arm9/data/keyb.bin
new file mode 100644
index 0000000..4f993fa
--- /dev/null
+++ b/arm9/data/keyb.bin
Binary files differ
diff --git a/arm9/data/maze.bin b/arm9/data/maze.bin
new file mode 100644
index 0000000..2882186
--- /dev/null
+++ b/arm9/data/maze.bin
Binary files differ
diff --git a/arm9/data/splashimg.bin b/arm9/data/splashimg.bin
new file mode 100644
index 0000000..910f64b
--- /dev/null
+++ b/arm9/data/splashimg.bin
Binary files differ
diff --git a/arm9/data/zx81.bin b/arm9/data/zx81.bin
new file mode 100644
index 0000000..557ddcb
--- /dev/null
+++ b/arm9/data/zx81.bin
Binary files differ
diff --git a/arm9/include/framebuffer.h b/arm9/include/framebuffer.h
new file mode 100644
index 0000000..80a9469
--- /dev/null
+++ b/arm9/include/framebuffer.h
@@ -0,0 +1,36 @@
+/*
+ ds81 - Nintendo DS ZX81 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$
+*/
+#ifndef DS81_FRAMEBUFFER_H
+#define DS81_FRAMEBUFFER_H
+
+#define FB_RGB(r,g,b) ((RGB15(r,g,b))|0x8000)
+
+void FB_Init(uint16 *vram);
+void FB_Print(const char *text, int x, int y, int colour, int paper);
+void FB_Centre(const char *text, int y, int colour, int paper);
+void FB_HLine(int x1, int x2, int y, int colour);
+void FB_VLine(int x, int y1, int y2, int colour);
+void FB_Box(int x, int y, int w, int h, int colour);
+void FB_FillBox(int x, int y, int w, int h, int colour);
+void FB_Clear(void);
+
+#endif /* DS81_FRAMEBUFFER_H */
diff --git a/arm9/include/gui.h b/arm9/include/gui.h
new file mode 100644
index 0000000..b9363ca
--- /dev/null
+++ b/arm9/include/gui.h
@@ -0,0 +1,27 @@
+/*
+ ds81 - Nintendo DS ZX81 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$
+*/
+#ifndef DS81_GUI_H
+#define DS81_GUI_H
+
+int GUI_Menu(const char *opts[]);
+
+#endif /* DS81_GUI_H */
diff --git a/arm9/include/kbd81.h b/arm9/include/kbd81.h
new file mode 100644
index 0000000..b4e3d62
--- /dev/null
+++ b/arm9/include/kbd81.h
@@ -0,0 +1,76 @@
+/*
+ ds81 - Nintendo DS ZX81 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$
+*/
+#ifndef DS81_KBD81_H
+#define DS81_KBD81_H
+
+typedef enum
+{
+ KBD_1,
+ KBD_2,
+ KBD_3,
+ KBD_4,
+ KBD_5,
+ KBD_6,
+ KBD_7,
+ KBD_8,
+ KBD_9,
+ KBD_0,
+ KBD_Q,
+ KBD_W,
+ KBD_E,
+ KBD_R,
+ KBD_T,
+ KBD_Y,
+ KBD_U,
+ KBD_I,
+ KBD_O,
+ KBD_P,
+ KBD_A,
+ KBD_S,
+ KBD_D,
+ KBD_F,
+ KBD_G,
+ KBD_H,
+ KBD_J,
+ KBD_K,
+ KBD_L,
+ KBD_NEWLINE,
+ KBD_SHIFT,
+ KBD_Z,
+ KBD_X,
+ KBD_C,
+ KBD_V,
+ KBD_B,
+ KBD_N,
+ KBD_M,
+ KBD_PERIOD,
+ KBD_SPACE
+} ZX81_Key;
+
+void KBD_Reset(void);
+void KBD_Display(const char *text);
+void KBD_Scan(void);
+ZX81_Key KBD_GetKey(void);
+void KBD_MapKey(KEYPAD_BITS pad, ZX81_Key key);
+void KBD_Probe(int scan);
+
+#endif /* DS81_KBD81_H */
diff --git a/arm9/source/framebuffer.c b/arm9/source/framebuffer.c
new file mode 100644
index 0000000..26b95de
--- /dev/null
+++ b/arm9/source/framebuffer.c
@@ -0,0 +1,255 @@
+/*
+ ds81 - Nintendo DS ZX81 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/arm9/source/gui.c b/arm9/source/gui.c
new file mode 100644
index 0000000..45b0817
--- /dev/null
+++ b/arm9/source/gui.c
@@ -0,0 +1,118 @@
+/*
+ ds81 - Nintendo DS ZX81 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/arm9/source/main.c b/arm9/source/main.c
new file mode 100644
index 0000000..a5f5035
--- /dev/null
+++ b/arm9/source/main.c
@@ -0,0 +1,137 @@
+/*
+ ds81 - Nintendo DS ZX81 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[]=
+ {
+ "DS81 \177 2006 Ian C",
+ " ",
+ "ZX81 ROM \177 1981",
+ "Nine Tiles Networks LTD",
+ " ",
+ "3D MONSTER MAZE \177 1983",
+ "Malcom E. Evans",
+ " ",
+ "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],40+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;
+}
diff --git a/data/keyb.bin b/data/keyb.bin
new file mode 100644
index 0000000..4f993fa
--- /dev/null
+++ b/data/keyb.bin
Binary files differ
diff --git a/data/maze.bin b/data/maze.bin
new file mode 100644
index 0000000..2882186
--- /dev/null
+++ b/data/maze.bin
Binary files differ
diff --git a/data/splashimg.bin b/data/splashimg.bin
new file mode 100644
index 0000000..910f64b
--- /dev/null
+++ b/data/splashimg.bin
Binary files differ
diff --git a/data/zx81.bin b/data/zx81.bin
new file mode 100644
index 0000000..557ddcb
--- /dev/null
+++ b/data/zx81.bin
Binary files differ
diff --git a/include/framebuffer.h b/include/framebuffer.h
new file mode 100644
index 0000000..80a9469
--- /dev/null
+++ b/include/framebuffer.h
@@ -0,0 +1,36 @@
+/*
+ ds81 - Nintendo DS ZX81 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$
+*/
+#ifndef DS81_FRAMEBUFFER_H
+#define DS81_FRAMEBUFFER_H
+
+#define FB_RGB(r,g,b) ((RGB15(r,g,b))|0x8000)
+
+void FB_Init(uint16 *vram);
+void FB_Print(const char *text, int x, int y, int colour, int paper);
+void FB_Centre(const char *text, int y, int colour, int paper);
+void FB_HLine(int x1, int x2, int y, int colour);
+void FB_VLine(int x, int y1, int y2, int colour);
+void FB_Box(int x, int y, int w, int h, int colour);
+void FB_FillBox(int x, int y, int w, int h, int colour);
+void FB_Clear(void);
+
+#endif /* DS81_FRAMEBUFFER_H */
diff --git a/include/gui.h b/include/gui.h
new file mode 100644
index 0000000..b9363ca
--- /dev/null
+++ b/include/gui.h
@@ -0,0 +1,27 @@
+/*
+ ds81 - Nintendo DS ZX81 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$
+*/
+#ifndef DS81_GUI_H
+#define DS81_GUI_H
+
+int GUI_Menu(const char *opts[]);
+
+#endif /* DS81_GUI_H */
diff --git a/include/kbd81.h b/include/kbd81.h
new file mode 100644
index 0000000..b4e3d62
--- /dev/null
+++ b/include/kbd81.h
@@ -0,0 +1,76 @@
+/*
+ ds81 - Nintendo DS ZX81 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$
+*/
+#ifndef DS81_KBD81_H
+#define DS81_KBD81_H
+
+typedef enum
+{
+ KBD_1,
+ KBD_2,
+ KBD_3,
+ KBD_4,
+ KBD_5,
+ KBD_6,
+ KBD_7,
+ KBD_8,
+ KBD_9,
+ KBD_0,
+ KBD_Q,
+ KBD_W,
+ KBD_E,
+ KBD_R,
+ KBD_T,
+ KBD_Y,
+ KBD_U,
+ KBD_I,
+ KBD_O,
+ KBD_P,
+ KBD_A,
+ KBD_S,
+ KBD_D,
+ KBD_F,
+ KBD_G,
+ KBD_H,
+ KBD_J,
+ KBD_K,
+ KBD_L,
+ KBD_NEWLINE,
+ KBD_SHIFT,
+ KBD_Z,
+ KBD_X,
+ KBD_C,
+ KBD_V,
+ KBD_B,
+ KBD_N,
+ KBD_M,
+ KBD_PERIOD,
+ KBD_SPACE
+} ZX81_Key;
+
+void KBD_Reset(void);
+void KBD_Display(const char *text);
+void KBD_Scan(void);
+ZX81_Key KBD_GetKey(void);
+void KBD_MapKey(KEYPAD_BITS pad, ZX81_Key key);
+void KBD_Probe(int scan);
+
+#endif /* DS81_KBD81_H */
diff --git a/source/framebuffer.c b/source/framebuffer.c
new file mode 100644
index 0000000..26b95de
--- /dev/null
+++ b/source/framebuffer.c
@@ -0,0 +1,255 @@
+/*
+ ds81 - Nintendo DS ZX81 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..45b0817
--- /dev/null
+++ b/source/gui.c
@@ -0,0 +1,118 @@
+/*
+ ds81 - Nintendo DS ZX81 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..a5f5035
--- /dev/null
+++ b/source/main.c
@@ -0,0 +1,137 @@
+/*
+ ds81 - Nintendo DS ZX81 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[]=
+ {
+ "DS81 \177 2006 Ian C",
+ " ",
+ "ZX81 ROM \177 1981",
+ "Nine Tiles Networks LTD",
+ " ",
+ "3D MONSTER MAZE \177 1983",
+ "Malcom E. Evans",
+ " ",
+ "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],40+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;
+}