Keep joystick movement until rendering was performed.
authorAndreas Eversberg <jolly@eversberg.eu>
Thu, 11 Oct 2018 16:05:18 +0000 (18:05 +0200)
committerAndreas Eversberg <jolly@eversberg.eu>
Thu, 11 Oct 2018 16:05:18 +0000 (18:05 +0200)
This prevents short presses to get lost between two frames.

src/libjoystick/joystick.c
src/libjoystick/joystick.h
src/mercenary/main.c

index 12abea5..e004d69 100644 (file)
@@ -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_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
 
 #define CIAAPRA                0xbfe000
 #define JOYDAT1                0xdff00c
@@ -68,18 +73,39 @@ uint16_t emulate_joystick_read(uint32_t address)
 }
 
 /* use -1 to keep state unchanged */
 }
 
 /* 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)
 {
 void set_joystick(int left, int right, int up, int down, int fire)
 {
+       if (left == 1)
+               joystick_left = 1;
        if (left >= 0)
        if (left >= 0)
-               joystick_left = left;
+               joystick_left_reset = left;
+       if (right == 1)
+               joystick_right = 1;
        if (right >= 0)
        if (right >= 0)
-               joystick_right = right;
+               joystick_right_reset = right;
+       if (up == 1)
+               joystick_up = 1;
        if (up >= 0)
        if (up >= 0)
-               joystick_up = up;
+               joystick_up_reset = up;
+       if (down == 1)
+               joystick_down = 1;
        if (down >= 0)
        if (down >= 0)
-               joystick_down = down;
+               joystick_down_reset = down;
+       if (fire == 1)
+               joystick_fire = 1;
        if (fire >= 0)
        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;
+}
 
 
index ec80a30..a269d33 100644 (file)
@@ -1,4 +1,5 @@
 
 uint16_t emulate_joystick_read(uint32_t address);
 void set_joystick(int left, int right, int up, int down, int fire);
 
 uint16_t emulate_joystick_read(uint32_t address);
 void set_joystick(int left, int right, int up, int down, int fire);
+void reset_joystick(void);
 
 
index 1fa655a..f944dd0 100644 (file)
@@ -765,6 +765,8 @@ static void main_loop(void)
                        /* for amiga speed: set delay by the number of cycles */
                        if (config_amiga_speed)
                                render_delay += (double)cycle_count / CPU_SPEED;
                        /* for amiga speed: set delay by the number of cycles */
                        if (config_amiga_speed)
                                render_delay += (double)cycle_count / CPU_SPEED;
+                       /* reset joystick after rendering */
+                       reset_joystick();
                }
 
                /* STEP 2: transfer legacy image (or just benson) in memory to OpenGL texture */
                }
 
                /* STEP 2: transfer legacy image (or just benson) in memory to OpenGL texture */