summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile2
-rw-r--r--src/config.h2
-rw-r--r--src/exit.h2
-rw-r--r--src/expr.h2
-rw-r--r--src/font.h2
-rw-r--r--src/gfx.h2
-rw-r--r--src/gui.c92
-rw-r--r--src/gui.h2
-rw-r--r--src/kbbmp.h2
-rw-r--r--src/memmenu.h2
-rw-r--r--src/snap.h2
-rw-r--r--src/spec.h2
-rw-r--r--src/symtochar.c99
-rw-r--r--src/symtochar.h42
-rw-r--r--src/tape.h2
-rw-r--r--src/util.c16
-rw-r--r--src/util.h9
-rw-r--r--src/z80.h2
-rw-r--r--src/z80_private.h2
19 files changed, 249 insertions, 37 deletions
diff --git a/src/Makefile b/src/Makefile
index 96193fe..0e42bba 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -41,6 +41,7 @@ SOURCE = main.c \
kbbmp.c \
exit.c \
tape.c \
+ symtochar.c \
expr.c \
z80.c \
z80_decode.c \
@@ -57,6 +58,7 @@ OBJECTS = main.o \
kbbmp.o \
exit.o \
tape.o \
+ symtochar.o \
expr.o \
z80.o \
z80_decode.o \
diff --git a/src/config.h b/src/config.h
index 4115460..56444f7 100644
--- a/src/config.h
+++ b/src/config.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_CONFIG_H
-#define ESPEC_CONFIG_H "$Id$"
+#define ESPEC_CONFIG_H
/* Integer settings
diff --git a/src/exit.h b/src/exit.h
index 084fc78..61c09d1 100644
--- a/src/exit.h
+++ b/src/exit.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_EXIT_H
-#define ESPEC_EXIT_H "$Id$"
+#define ESPEC_EXIT_H
/* Exit
diff --git a/src/expr.h b/src/expr.h
index 2c77897..e1194bc 100644
--- a/src/expr.h
+++ b/src/expr.h
@@ -28,7 +28,7 @@
*/
#ifndef EXPR_H
-#define EXPR_H "$Id$"
+#define EXPR_H
/* ---------------------------------------- INTERFACES
*/
diff --git a/src/font.h b/src/font.h
index f4a6925..17add55 100644
--- a/src/font.h
+++ b/src/font.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_FONT_H
-#define ESPEC_FONT_H "$Id$"
+#define ESPEC_FONT_H
typedef unsigned char FontChar[64];
diff --git a/src/gfx.h b/src/gfx.h
index 8166b2c..6f8f0dc 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_GFX_H
-#define ESPEC_GFX_H "$Id$"
+#define ESPEC_GFX_H
#include "SDL.h"
diff --git a/src/gui.c b/src/gui.c
index 6904d33..b5c3b98 100644
--- a/src/gui.c
+++ b/src/gui.c
@@ -37,6 +37,7 @@
#include "gui.h"
#include "gfx.h"
#include "exit.h"
+#include "symtochar.h"
#include "util.h"
@@ -57,6 +58,8 @@
#define LOGREY GFXRGB(100,100,100)
#define GREEN GFXRGB(100,255,100)
+#define MAX_MATCH 20
+
/* ---------------------------------------- TYPES
*/
@@ -118,6 +121,7 @@ static int DoList(const char *title, int no, char * const list[], int *option)
int cur;
int done;
int f;
+ char match[MAX_MATCH + 1] = {0};
if (no==0)
return -1;
@@ -180,29 +184,6 @@ static int DoList(const char *title, int no, char * const list[], int *option)
done=TRUE;
break;
- case SDLK_SPACE:
- if (option)
- option[cur]=!option[cur];
- break;
-
- case SDLK_i:
- if (option)
- for(f=0;f<no;f++)
- option[f]=!option[f];
- break;
-
- case SDLK_s:
- if (option)
- for(f=0;f<no;f++)
- option[f]=TRUE;
- break;
-
- case SDLK_c:
- if (option)
- for(f=0;f<no;f++)
- option[f]=FALSE;
- break;
-
case SDLK_ESCAPE:
cur=-1;
done=TRUE;
@@ -254,9 +235,74 @@ static int DoList(const char *title, int no, char * const list[], int *option)
}
break;
+ case SDLK_BACKSPACE:
+ match[0] = 0;
+ break;
+
default:
break;
}
+
+ if (option)
+ {
+ switch(e->key.keysym.sym)
+ {
+ case SDLK_SPACE:
+ option[cur]=!option[cur];
+ break;
+
+ case SDLK_i:
+ for(f=0;f<no;f++)
+ option[f]=!option[f];
+ break;
+
+ case SDLK_s:
+ for(f=0;f<no;f++)
+ option[f]=TRUE;
+ break;
+
+ case SDLK_c:
+ for(f=0;f<no;f++)
+ option[f]=FALSE;
+ break;
+
+ default:
+ break;
+ }
+ }
+ else
+ {
+ char c = SYMToChar(e->key.keysym.sym);
+ size_t l = strlen(match);
+
+ if (c && l < MAX_MATCH)
+ {
+ int found = FALSE;
+
+ match[l++] = c;
+ match[l] = 0;
+
+ for(f = 0; f < no && !found; f++)
+ {
+ if (StartsWith(list[f], match, l))
+ {
+ found = TRUE;
+
+ cur = f;
+
+ if (cur < top)
+ {
+ top = cur;
+ }
+
+ if (cur > top + max - 2)
+ {
+ top = cur - max + 2;
+ }
+ }
+ }
+ }
+ }
}
return cur;
diff --git a/src/gui.h b/src/gui.h
index efbb40c..0377b9b 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_GUI_H
-#define ESPEC_GUI_H "$Id$"
+#define ESPEC_GUI_H
/* ---------------------------------------- INTERFACES
diff --git a/src/kbbmp.h b/src/kbbmp.h
index 58a4331..6bed49e 100644
--- a/src/kbbmp.h
+++ b/src/kbbmp.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_KBBMP_H
-#define ESPEC_KBBMP_H "$Id$"
+#define ESPEC_KBBMP_H
#define KBBMP_WIDTH 256
diff --git a/src/memmenu.h b/src/memmenu.h
index 4b818fd..73222c6 100644
--- a/src/memmenu.h
+++ b/src/memmenu.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_MEMMENU_H
-#define ESPEC_MEMMENU_H "$Id$"
+#define ESPEC_MEMMENU_H
#include "z80.h"
diff --git a/src/snap.h b/src/snap.h
index d1978b6..4a0b444 100644
--- a/src/snap.h
+++ b/src/snap.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_SNAP_H
-#define ESPEC_SNAP_H "$Id$"
+#define ESPEC_SNAP_H
#include <stdlib.h>
#include <stdio.h>
diff --git a/src/spec.h b/src/spec.h
index 261429c..28c89fd 100644
--- a/src/spec.h
+++ b/src/spec.h
@@ -24,7 +24,7 @@
*/
#ifndef ESPEC_SPECH
-#define ESPEC_SPECH "$Id$"
+#define ESPEC_SPECH
#include "z80.h"
#include "SDL.h"
diff --git a/src/symtochar.c b/src/symtochar.c
new file mode 100644
index 0000000..3817f5a
--- /dev/null
+++ b/src/symtochar.c
@@ -0,0 +1,99 @@
+/*
+
+ espec - Sinclair Spectrum emulator
+
+ Copyright (C) 2026 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
+ 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
+
+ -------------------------------------------------------------------------
+
+ Convert an SDL keysym into a char
+
+*/
+#include "symtochar.h"
+
+
+/* ---------------------------------------- GLOBALS
+*/
+static struct
+{
+ SDL_Keycode sym;
+ char c;
+} map[] =
+{
+ {SDLK_1, '1'},
+ {SDLK_2, '2'},
+ {SDLK_3, '3'},
+ {SDLK_4, '4'},
+ {SDLK_5, '5'},
+ {SDLK_6, '6'},
+ {SDLK_7, '7'},
+ {SDLK_8, '8'},
+ {SDLK_9, '9'},
+ {SDLK_0, '0'},
+
+ {SDLK_a, 'a'},
+ {SDLK_b, 'b'},
+ {SDLK_c, 'c'},
+ {SDLK_d, 'd'},
+ {SDLK_e, 'e'},
+ {SDLK_f, 'f'},
+ {SDLK_g, 'g'},
+ {SDLK_h, 'h'},
+ {SDLK_i, 'i'},
+ {SDLK_j, 'j'},
+ {SDLK_k, 'k'},
+ {SDLK_l, 'l'},
+ {SDLK_m, 'm'},
+ {SDLK_n, 'n'},
+ {SDLK_o, 'o'},
+ {SDLK_p, 'p'},
+ {SDLK_q, 'q'},
+ {SDLK_r, 'r'},
+ {SDLK_s, 's'},
+ {SDLK_t, 't'},
+ {SDLK_u, 'u'},
+ {SDLK_v, 'v'},
+ {SDLK_w, 'w'},
+ {SDLK_x, 'x'},
+ {SDLK_y, 'y'},
+ {SDLK_z, 'z'},
+
+ {SDLK_SPACE, ' '},
+
+ {SDLK_UNKNOWN, 0}
+};
+
+/* ---------------------------------------- INTERFACES
+*/
+
+char SYMToChar(SDL_Keycode keysym)
+{
+ int f;
+
+ for(f = 0; map[f].sym != SDLK_UNKNOWN; f++)
+ {
+ if (map[f].sym == keysym)
+ {
+ return map[f].c;
+ }
+ }
+
+ return 0;
+}
+
+
+/* END OF FILE */
diff --git a/src/symtochar.h b/src/symtochar.h
new file mode 100644
index 0000000..136b146
--- /dev/null
+++ b/src/symtochar.h
@@ -0,0 +1,42 @@
+/*
+
+ espec - Sinclair Spectrum emulator
+
+ Copyright (C) 2026 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
+ 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
+
+ -------------------------------------------------------------------------
+
+ Convert an SDL keysym into a char
+
+*/
+
+#ifndef ESPEC_SYMTOCHAR_H
+#define ESPEC_SYMTOCHAR_H
+
+#include <SDL_keyboard.h>
+
+/* ---------------------------------------- INTERFACES
+*/
+
+/* Convert a SDL keysym to a char. Returns 0 if there is no mapping.
+*/
+char SYMToChar(SDL_Keycode keysym);
+
+#endif
+
+
+/* END OF FILE */
diff --git a/src/tape.h b/src/tape.h
index 05e09e9..5f69598 100644
--- a/src/tape.h
+++ b/src/tape.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_TAPE_H
-#define ESPEC_TAPE_H "$Id$"
+#define ESPEC_TAPE_H
#include <stdio.h>
diff --git a/src/util.c b/src/util.c
index c16584c..b49b780 100644
--- a/src/util.c
+++ b/src/util.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
+#include <ctype.h>
#include <sys/param.h>
#include "util.h"
@@ -138,4 +139,19 @@ void Debug(const char *format, ...)
va_end(ap);
}
+
+int StartsWith(const char *a, const char *b, size_t len)
+{
+ while(len && *a && *b &&
+ tolower((unsigned char)*a) == tolower((unsigned char)*b))
+ {
+ len--;
+ a++;
+ b++;
+ }
+
+ return len == 0;
+}
+
+
/* END OF FILE */
diff --git a/src/util.h b/src/util.h
index c82169e..2262332 100644
--- a/src/util.h
+++ b/src/util.h
@@ -25,7 +25,7 @@
*/
#ifndef ESPEC_UTIL_H
-#define ESPEC_UTIL_H "$Id$"
+#define ESPEC_UTIL_H
#include <stdlib.h>
@@ -74,6 +74,13 @@ const char *Dirname(const char *path);
void Debug(const char *format,...);
+/* See if the passed strings match, case insensitive, up to the passed length.
+ Returns TRUE if they match, otherwise FALSE. If nul is hit before the
+ length then just up to that is checked.
+*/
+int StartsWith(const char *a, const char *b, size_t len);
+
+
#endif
diff --git a/src/z80.h b/src/z80.h
index 0b7424b..66385e7 100644
--- a/src/z80.h
+++ b/src/z80.h
@@ -25,7 +25,7 @@
*/
#ifndef Z80_H
-#define Z80_H "$Id$"
+#define Z80_H
/* ---------------------------------------- TYPES
*/
diff --git a/src/z80_private.h b/src/z80_private.h
index 1df307b..628e23d 100644
--- a/src/z80_private.h
+++ b/src/z80_private.h
@@ -27,7 +27,7 @@
*/
#ifndef Z80_PRIVATE_H
-#define Z80_PRIVATE_H "$Id$"
+#define Z80_PRIVATE_H
#ifndef TRUE
#define TRUE 1