X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=mercenary-reloaded.git;a=blobdiff_plain;f=src%2Flibjoystick%2Fjoystick.c;h=e004d6966cdcf0407c2d8d4184ced015055de59d;hp=12abea5c60951a8ff03e4576e1f679dce0af8b98;hb=b4d06ff78ae4d481ee517f82b6008a17943c8bbe;hpb=34f84414002dd02f04785726700a8a77df4efd62 diff --git a/src/libjoystick/joystick.c b/src/libjoystick/joystick.c index 12abea5..e004d69 100644 --- a/src/libjoystick/joystick.c +++ b/src/libjoystick/joystick.c @@ -27,6 +27,11 @@ static int joystick_right = 0; static int joystick_up = 0; static int joystick_down = 0; static int joystick_fire = 0; +static int joystick_left_reset = 0; +static int joystick_right_reset = 0; +static int joystick_up_reset = 0; +static int joystick_down_reset = 0; +static int joystick_fire_reset = 0; #define CIAAPRA 0xbfe000 #define JOYDAT1 0xdff00c @@ -68,18 +73,39 @@ uint16_t emulate_joystick_read(uint32_t address) } /* use -1 to keep state unchanged */ +/* NOTE: a pressed and then released button/stick will sustain until reset_joystick() is called after rendering was done. + * this ensures that a short press (during rendering one frame) will not get lost. + */ void set_joystick(int left, int right, int up, int down, int fire) { + if (left == 1) + joystick_left = 1; if (left >= 0) - joystick_left = left; + joystick_left_reset = left; + if (right == 1) + joystick_right = 1; if (right >= 0) - joystick_right = right; + joystick_right_reset = right; + if (up == 1) + joystick_up = 1; if (up >= 0) - joystick_up = up; + joystick_up_reset = up; + if (down == 1) + joystick_down = 1; if (down >= 0) - joystick_down = down; + joystick_down_reset = down; + if (fire == 1) + joystick_fire = 1; if (fire >= 0) - joystick_fire = fire; + joystick_fire_reset = fire; } +void reset_joystick(void) +{ + joystick_left = joystick_left_reset; + joystick_right = joystick_right_reset; + joystick_up = joystick_up_reset; + joystick_down = joystick_down_reset; + joystick_fire = joystick_fire_reset; +}