--- heroes-0.21.orig/src/const.c
+++ heroes-0.21/src/const.c
@@ -45,9 +45,6 @@
 /* int error; */
 char in_jokebox;
 
-char kbjoy[6] = { 0, 0, 0, 0, 0, 0 };
-char kbjoyold[6] = { 0, 0, 0, 0, 0, 0 };
-
 a_pixel *(render_buffer[2]);		/* xbuf * ybuf */
 
 a_pixel glenz[8][256];		/* glenz lines */
@@ -88,6 +85,15 @@
 
 char demo_ready = 0;
 
+/*
+ * An array of joystick buttons.  KBJOYOLD is the previous state.
+ * Button N has been pressed is KBJOY[N] && !KBJOYOLD[N].  Initially
+ * we assume that all buttons are down, so any button down before the
+ * first call to get_key_or_joy() is ignored.
+ */
+static bool kbjoy[6] = { true, true, true, true, true, true };
+static bool kbjoyold[6];
+
 char
 key_or_joy_ready (void)
 {
@@ -108,7 +114,7 @@
 
   if (key_ready ()) {
     reset_htimer (demo_trigger_htimer);
-    return (1);
+    return 1;
   }
   if ((joystick_detected & 1) && (opt.ctrl_one == 1 || opt.ctrl_two == 1)) {
     for (i = 0; i < 6; i++)
@@ -127,10 +133,10 @@
 	|| (kbjoy[4] && !kbjoyold[4])
 	|| (kbjoy[5] && !kbjoyold[5])) {
       reset_htimer (demo_trigger_htimer);
-      return (1);
+      return 1;
     }
   }
-  return (0);
+  return 0;
 }
 
 a_keycode
@@ -151,7 +157,17 @@
   if (kbjoy[5] && !kbjoyold[5])
     return (HK_Escape);
   printf ("get_key_or_joy(): no event.");
-  return (0);
+  return 0;
+}
+
+void
+key_or_joy_reset (void)
+{
+  /* Assume that all joystick buttons were down, so that
+     get_key_or_joy will not detect buttons that are already down.  */
+  int i;
+  for (i = 0; i < 6; i++)
+    kbjoy[i] = true;
 }
 
 void
@@ -165,5 +181,4 @@
       *dest = glenzligne[*dest];
     dest += xbuf - xt;
   }
-
 }
