From f08256be0fb69083175408e9d87173a5107c9977 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 30 Oct 2006 23:50:04 +0000 Subject: Completed FAT loading, custom keypad definitions and fixed keyboard hang bug --- source/keyboard.c | 108 +++++++++++++++++++++++++++++++++++------------------- source/main.c | 86 ++++++++++++++++++++++++++++++++++++------- source/zx81.c | 6 +-- 3 files changed, 146 insertions(+), 54 deletions(-) (limited to 'source') diff --git a/source/keyboard.c b/source/keyboard.c index 8db8d34..04ae120 100644 --- a/source/keyboard.c +++ b/source/keyboard.c @@ -61,11 +61,11 @@ static SoftKey pad_select_key = NUM_SOFT_KEYS; } \ } while(0) -#define CHECK_STATE(KEYS,BIT,CODE,SHORTCUT) \ +#define CHECK_STATE(KEYS,BIT,CODE,SHORTCUT,USE_SHORTCUT) \ do \ { \ key_state[CODE].new_state = (KEYS & BIT); \ - if (SHORTCUT != NUM_SOFT_KEYS && \ + if (USE_SHORTCUT && SHORTCUT != NUM_SOFT_KEYS && \ !key_state[SHORTCUT].handled && (KEYS & BIT)) \ { \ key_state[SHORTCUT].new_state = TRUE; \ @@ -73,6 +73,33 @@ static SoftKey pad_select_key = NUM_SOFT_KEYS; } while(0) +static const char *keynames[]= +{ + "1", "2", "3", "4", "5", + "6", "7", "8", "9", "0", + "Q", "W", "E", "R", "T", + "Y", "U", "I", "O", "P", + "A", "S", "D", "F", "G", + "H", "J", "K", "L", "NEWLINE", + "SHIFT", "Z", "X", "C", "V", + "B", "N", "M", "PERIOD", "SPACE", + + "ABOUT", + "CONFIG", + "JOYPAD UP", + "JOYPAD DOWN", + "JOYPAD LEFT", + "JOYPAD RIGHT", + "A BUTTON", + "B BUTTON", + "X BUTTON", + "Y BUTTON", + "RIGHT SHOULDER BUTTON", + "LEFT SHOULDER BUTTON", + "START BUTTON", + "SELECT BUTTON" +}; + /* ---------------------------------------- PRIVATE INTERFACES */ static SoftKey LocatePress(const touchPosition *p) @@ -99,19 +126,7 @@ static SoftKey LocatePress(const touchPosition *p) } -/* ---------------------------------------- PUBLIC INTERFACES -*/ -void SK_DisplayKeyboard(uint16 *vram) -{ - sImage img; - - loadPCX(keyb_bin,&img); - image8to16(&img); - dmaCopy(img.data8,vram,SCREEN_WIDTH*SCREEN_HEIGHT*2); -} - - -int SK_GetEvent(SoftKeyEvent *ev) +static int GetEvent(SoftKeyEvent *ev, int map) { static SoftKey last = NUM_SOFT_KEYS; static int poll_index = -1; @@ -187,18 +202,18 @@ int SK_GetEvent(SoftKeyEvent *ev) /* Check non soft-keyboard controls */ - CHECK_STATE(keys, KEY_A, SK_PAD_A, pad_A_key); - CHECK_STATE(keys, KEY_B, SK_PAD_B, pad_B_key); - CHECK_STATE(keys, KEY_X, SK_PAD_X, pad_X_key); - CHECK_STATE(keys, KEY_Y, SK_PAD_Y, pad_Y_key); - CHECK_STATE(keys, KEY_R, SK_PAD_R, pad_R_key); - CHECK_STATE(keys, KEY_L, SK_PAD_L, pad_L_key); - CHECK_STATE(keys, KEY_START, SK_PAD_START, pad_start_key); - CHECK_STATE(keys, KEY_SELECT, SK_PAD_SELECT, pad_select_key); - CHECK_STATE(keys, KEY_UP, SK_PAD_UP, pad_up_key); - CHECK_STATE(keys, KEY_DOWN, SK_PAD_DOWN, pad_down_key); - CHECK_STATE(keys, KEY_LEFT, SK_PAD_LEFT, pad_left_key); - CHECK_STATE(keys, KEY_RIGHT, SK_PAD_RIGHT, pad_right_key); + CHECK_STATE(keys, KEY_A, SK_PAD_A, pad_A_key, map); + CHECK_STATE(keys, KEY_B, SK_PAD_B, pad_B_key, map); + CHECK_STATE(keys, KEY_X, SK_PAD_X, pad_X_key, map); + CHECK_STATE(keys, KEY_Y, SK_PAD_Y, pad_Y_key, map); + CHECK_STATE(keys, KEY_R, SK_PAD_R, pad_R_key, map); + CHECK_STATE(keys, KEY_L, SK_PAD_L, pad_L_key, map); + CHECK_STATE(keys, KEY_START, SK_PAD_START, pad_start_key, map); + CHECK_STATE(keys, KEY_SELECT, SK_PAD_SELECT, pad_select_key, map); + CHECK_STATE(keys, KEY_UP, SK_PAD_UP, pad_up_key, map); + CHECK_STATE(keys, KEY_DOWN, SK_PAD_DOWN, pad_down_key, map); + CHECK_STATE(keys, KEY_LEFT, SK_PAD_LEFT, pad_left_key, map); + CHECK_STATE(keys, KEY_RIGHT, SK_PAD_RIGHT, pad_right_key, map); /* Reset key event poll index */ @@ -243,24 +258,37 @@ int SK_GetEvent(SoftKeyEvent *ev) } -void SK_SetSticky(SoftKey key, int is_sticky) +/* ---------------------------------------- PUBLIC INTERFACES +*/ +void SK_DisplayKeyboard(uint16 *vram) { - key_state[key].is_sticky = is_sticky; + sImage img; - if (!is_sticky) - { - key_state[key].new_state = FALSE; - } + loadPCX(keyb_bin,&img); + image8to16(&img); + dmaCopy(img.data8,vram,SCREEN_WIDTH*SCREEN_HEIGHT*2); } -void SK_ClearKeys(void) +int SK_GetEvent(SoftKeyEvent *ev) +{ + return GetEvent(ev,TRUE); +} + + +int SK_GetBareEvent(SoftKeyEvent *ev) { - int f; + return GetEvent(ev,FALSE); +} - for(f=0; f < NUM_SOFT_KEYS; f++) + +void SK_SetSticky(SoftKey key, int is_sticky) +{ + key_state[key].is_sticky = is_sticky; + + if (!is_sticky) { - key_state[f].state = FALSE; + key_state[key].new_state = FALSE; } } @@ -311,3 +339,9 @@ void SK_DefinePad(SoftKey pad, SoftKey key) } +const char *SK_KeyName(SoftKey k) +{ + return keynames[k]; +} + + diff --git a/source/main.c b/source/main.c index 83bc543..38c28f1 100644 --- a/source/main.c +++ b/source/main.c @@ -99,53 +99,53 @@ static void Splash(void) FB_Blit(&img,0,0); - y=10; + y = 10; for(f=0;text[f];f++) { FB_Centre(text[f],y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; } - y+=8; + y += 8; if (fatInitialise(32,true)) { ZX81EnableFileSystem(TRUE); FB_Centre("Found a FAT device.",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("If you place .P tape files in",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("the top directory or ZX81TAPE",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("then you should be able to load",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("GAME.P with the command",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("LOAD \"GAME\"",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; } else { ZX81EnableFileSystem(FALSE); FB_Centre("Sorry, but you don't have a",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("supported FAT device.",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("Only the internal tape",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; FB_Centre("files can be used.",y,FB_RGB(31,31,31),-1); - y+=8; + y += 8; } while(!(keysDown() & KEY_A)) @@ -155,6 +155,64 @@ static void Splash(void) } +/* ---------------------------------------- JOYPAD MAPPING +*/ +static void MapJoypad(void) +{ + SoftKeyEvent ev; + SoftKey pad = NUM_SOFT_KEYS; + int done = FALSE; + char text[256]; + + SK_DisplayKeyboard(BG_GFX_SUB); + + ZX81DisplayString("press the joypad button you want\n" + "to define and then the ZX81 key\n" + "you want to use.\n\n" + "press on the config banner to\n" + "finish."); + + while(!done) + { + while(SK_GetBareEvent(&ev)) + { + if (ev.pressed) + { + if (ev.key==SK_ABOUT || ev.key==SK_CONFIG) + { + done = true; + } + } + else + { + if (ev.key>=SK_PAD_UP && ev.key<=SK_PAD_SELECT) + { + pad = ev.key; + + /* Now, just how dumb was making % the inverse on/off... + */ + sprintf(text,"defining\n %%%s%%",SK_KeyName(pad)); + ZX81DisplayString(text); + } + + if (ev.key<=SK_SPACE && pad!=NUM_SOFT_KEYS) + { + sprintf(text,"mapped\n %%%s%%\nto\n %%%s%%", + SK_KeyName(pad),SK_KeyName(ev.key)); + ZX81DisplayString(text); + + SK_DefinePad(pad,ev.key); + + pad = NUM_SOFT_KEYS; + } + } + } + + swiWaitForVBlank(); + } +} + + /* ---------------------------------------- MAIN */ int main(int argc, char *argv[]) @@ -251,7 +309,7 @@ int main(int argc, char *argv[]) break; case MenuMapJoypad: - SK_DisplayKeyboard(BG_GFX_SUB); + MapJoypad(); break; } diff --git a/source/zx81.c b/source/zx81.c index 6173701..533c382 100644 --- a/source/zx81.c +++ b/source/zx81.c @@ -446,13 +446,13 @@ static void ZX81HouseKeeping(Z80 *z80) if (lastk1 && (lastk1!=prev_lk1 || lastk2!=prev_lk2)) { mem[CDFLAG]|=1; + + mem[LASTK1]=lastk1^0xff; + mem[LASTK2]=lastk2^0xff; } prev_lk1=lastk1; prev_lk2=lastk2; - - mem[LASTK1]=lastk1^0xff; - mem[LASTK2]=lastk2^0xff; } -- cgit v1.2.3