summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2021-08-09 18:50:11 +0000
committerIan C <ianc@noddybox.co.uk>2021-08-09 18:50:11 +0000
commit37236919c76ed4b5a8a7c98950257e3626e268c4 (patch)
tree22bdc153fc4e30a18a8d4f180ab5a19cfbbb3999 /source
parent0d08766ccc80cacfe0690cb8a1ea8f13038e404b (diff)
Changed initial directory and added joystick emulation.
Diffstat (limited to 'source')
-rw-r--r--source/gui.c20
-rw-r--r--source/main.c1
-rw-r--r--source/spec.c80
3 files changed, 95 insertions, 6 deletions
diff --git a/source/gui.c b/source/gui.c
index 375fc74..c3b402d 100644
--- a/source/gui.c
+++ b/source/gui.c
@@ -54,12 +54,11 @@ typedef struct
{
char name[FSEL_FILENAME_LEN+1];
int is_dir;
- int size;
} FSEL_File;
static FSEL_File fsel[FSEL_MAX_FILES];
-char last_dir[FILENAME_MAX] = "sdmc:/";
+char last_dir[FILENAME_MAX] = "sdmc:/SPECTRUM/";
static void CheckPath(char *path)
@@ -185,7 +184,6 @@ static int LoadDir(const char *path, const char *filter)
{
strcpy(fsel[no].name, "..");
fsel[no].is_dir = TRUE;
- fsel[no].size = 0;
no++;
}
@@ -199,7 +197,6 @@ static int LoadDir(const char *path, const char *filter)
{
strcpy(fsel[no].name,ent->d_name);
fsel[no].is_dir = ent->d_type & DT_DIR;
- fsel[no].size = 0;
no++;
}
}
@@ -215,6 +212,21 @@ static int LoadDir(const char *path, const char *filter)
/* ---------------------------------------- PUBLIC INTERFACES
*/
+void GUI_Init(void)
+{
+ DIR *dir;
+
+ if ((dir = opendir(last_dir)))
+ {
+ closedir(dir);
+ }
+ else
+ {
+ strcpy(last_dir, "sdmc:/");
+ }
+}
+
+
int GUI_Menu(const char *opts[])
{
int x,y;
diff --git a/source/main.c b/source/main.c
index d78a910..36f3791 100644
--- a/source/main.c
+++ b/source/main.c
@@ -247,6 +247,7 @@ int main(int argc, char *argv[])
ndspChnSetMix(0, mix);
FB_Init();
+ GUI_Init();
z80 = Z80Init(SPECReadPort, SPECWritePort);
diff --git a/source/spec.c b/source/spec.c
index 1a5eba2..0dc753f 100644
--- a/source/spec.c
+++ b/source/spec.c
@@ -134,9 +134,16 @@ static struct
};
-/* The keyboard
+/* The keyboard and joystick
*/
static Z80Byte matrix[8];
+static Z80Byte joystick;
+
+#define JOY_FIRE 0x10
+#define JOY_UP 0x08
+#define JOY_DOWN 0x04
+#define JOY_LEFT 0x02
+#define JOY_RIGHT 0x01
static struct
{
@@ -424,7 +431,66 @@ void SPECHandleKey(SoftKey key, int is_pressed)
}
else
{
- /* TODO: Joysticks? */
+ switch(key)
+ {
+ case SK_PAD_UP:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_UP;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_UP;
+ }
+ break;
+
+ case SK_PAD_DOWN:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_DOWN;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_DOWN;
+ }
+ break;
+
+ case SK_PAD_LEFT:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_LEFT;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_LEFT;
+ }
+ break;
+
+ case SK_PAD_RIGHT:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_RIGHT;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_RIGHT;
+ }
+ break;
+
+ case SK_PAD_A:
+ if (is_pressed)
+ {
+ joystick = joystick | JOY_FIRE;
+ }
+ else
+ {
+ joystick = joystick & ~JOY_FIRE;
+ }
+ break;
+
+ default:
+ break;
+ }
}
}
@@ -448,9 +514,19 @@ Z80Byte SPECReadPort(Z80 *z80, Z80Word port)
switch(lo)
{
case 0x1f: /* Kempston joystick */
+ b = joystick;
break;
case 0x7f: /* Fuller joystick */
+ b = ~joystick;
+ if (b & JOY_FIRE)
+ {
+ b |= 0x80;
+ }
+ else
+ {
+ b &= 0x7f;
+ }
break;
case 0xfb: /* ZX Printer */