From 43503cfa510a7f7e650efccaac266d7cc6657a5d Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 11 Aug 2023 21:04:54 +0100 Subject: Better koystick support --- src/game.c | 9 ++++++++- src/joy.c | 20 ++++++++++++-------- src/main.c | 2 +- src/menu.c | 12 +++++++++++- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/game.c b/src/game.c index c2420ca..67c6ffe 100644 --- a/src/game.c +++ b/src/game.c @@ -382,8 +382,15 @@ update_menu: goto update_menu; } - if (keys[KEY_ENTER]) + if (keys[KEY_ENTER] || (ctl & CTL_FIRE1)) + { + while (keys[KEY_ENTER] || (ctl & CTL_FIRE1)) + { + ctl = control_read(); + wait_vsync(); + } break; + } } wait_vsync(); diff --git a/src/joy.c b/src/joy.c index cda2fcf..4910f16 100644 --- a/src/joy.c +++ b/src/joy.c @@ -66,6 +66,10 @@ uint8_t joy_detect() printf("Joystick detected!\n"); + uint16_t cx, cy; + printf("Please center the joystick and press BUTTON 1 (ESC to abort)\n"); + if (!calibrate(&cy, &cx)) + return 0; printf("Please move UP + LEFT and press BUTTON 1 (ESC to abort)\n"); if (!calibrate(&j_up, &j_left)) return 0; @@ -78,10 +82,10 @@ uint8_t joy_detect() j_up, j_down, j_left, j_right); #endif - j_up += j_up >> 4; - j_down -= j_down >> 4; - j_left += j_left >> 4; - j_right -= j_right >> 4; + j_up = cy - ((cy - j_up) / 2); + j_down = cy + ((j_down - cy) / 2); + j_left = cx - ((cx - j_left) / 2); + j_right = cx + ((j_right - cx) / 2); #ifdef DEBUG printf(" Adjusted: up=%04d, down=%04d, left=%04d, right=%04d\n", @@ -108,15 +112,15 @@ uint8_t joy_read() r |= CTL_FIRE2; v = read_axis(AXISY); - if (v <= j_up) + if (v < j_up) r |= CTL_UP; - if (v >= j_down) + if (v > j_down) r |= CTL_DOWN; v = read_axis(AXISX); - if (v <= j_left) + if (v < j_left) r |= CTL_LEFT; - if (v >= j_right) + if (v > j_right) r |= CTL_RIGHT; return r; diff --git a/src/main.c b/src/main.c index 9e1a678..9140bdf 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ #include "game.h" #define GAME_NAME "Gold Mine Run!" -#define GAME_VERSION "1.1 (2023-08-10)" +#define GAME_VERSION "1.2 (2023-08-11)" #define GAME_URL "https://www.usebox.net/jjm/gold-mine-run/" /* disable paging because our int handlers are written in C */ diff --git a/src/menu.c b/src/menu.c index 77b9f2b..5a459e8 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2,6 +2,7 @@ #include #include "keyb.h" +#include "control.h" #include "vga.h" #include "sound.h" #include "text.h" @@ -77,15 +78,24 @@ uint8_t run_menu() uint16_t count = 0; uint8_t cast = 0; uint8_t wait; + uint8_t ctl; blit_target(TARGET_SCREEN); while (1) { + ctl = control_read(); + if (keys[KEY_ESC]) return 0; - if (keys[KEY_SPACE]) + if (keys[KEY_SPACE] || (ctl & CTL_FIRE1)) { + while (keys[KEY_SPACE] || (ctl & CTL_FIRE1)) + { + ctl = control_read(); + wait_vsync(); + } + sound_play_efx(EFX_ONEUP); for (uint8_t i = 0; i < 32; i++) -- cgit v1.2.3