diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Makefile | 2 | ||||
| -rw-r--r-- | src/config.h | 2 | ||||
| -rw-r--r-- | src/exit.h | 2 | ||||
| -rw-r--r-- | src/expr.h | 2 | ||||
| -rw-r--r-- | src/font.h | 2 | ||||
| -rw-r--r-- | src/gfx.h | 2 | ||||
| -rw-r--r-- | src/gui.c | 92 | ||||
| -rw-r--r-- | src/gui.h | 2 | ||||
| -rw-r--r-- | src/kbbmp.h | 2 | ||||
| -rw-r--r-- | src/memmenu.h | 2 | ||||
| -rw-r--r-- | src/snap.h | 2 | ||||
| -rw-r--r-- | src/spec.h | 2 | ||||
| -rw-r--r-- | src/symtochar.c | 99 | ||||
| -rw-r--r-- | src/symtochar.h | 42 | ||||
| -rw-r--r-- | src/tape.h | 2 | ||||
| -rw-r--r-- | src/util.c | 16 | ||||
| -rw-r--r-- | src/util.h | 9 | ||||
| -rw-r--r-- | src/z80.h | 2 | ||||
| -rw-r--r-- | src/z80_private.h | 2 |
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 @@ -25,7 +25,7 @@ */ #ifndef ESPEC_EXIT_H -#define ESPEC_EXIT_H "$Id$" +#define ESPEC_EXIT_H /* Exit @@ -28,7 +28,7 @@ */ #ifndef EXPR_H -#define EXPR_H "$Id$" +#define EXPR_H /* ---------------------------------------- INTERFACES */ @@ -25,7 +25,7 @@ */ #ifndef ESPEC_FONT_H -#define ESPEC_FONT_H "$Id$" +#define ESPEC_FONT_H typedef unsigned char FontChar[64]; @@ -25,7 +25,7 @@ */ #ifndef ESPEC_GFX_H -#define ESPEC_GFX_H "$Id$" +#define ESPEC_GFX_H #include "SDL.h" @@ -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; @@ -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" @@ -25,7 +25,7 @@ */ #ifndef ESPEC_SNAP_H -#define ESPEC_SNAP_H "$Id$" +#define ESPEC_SNAP_H #include <stdlib.h> #include <stdio.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 */ @@ -25,7 +25,7 @@ */ #ifndef ESPEC_TAPE_H -#define ESPEC_TAPE_H "$Id$" +#define ESPEC_TAPE_H #include <stdio.h> @@ -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 */ @@ -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 @@ -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 |
