Browse Source

Fix a 17 year old bug: paddle were not properly handled, funny I never got issues before Twin Dragons with that!

Though Twin Dragon way of writing to 4016 is nasty! ;P
Godzil 4 years ago
parent
commit
1d6afc5473
2 changed files with 25 additions and 30 deletions
  1. 2 2
      src/include/paddle.h
  2. 23 28
      src/paddle.c

+ 2 - 2
src/include/paddle.h

@@ -12,8 +12,8 @@
 
 typedef struct Paddle_
 {
-    uint8_t Bit;
-    uint8_t LastWrite;
+    uint8_t bitPos;
+    uint8_t strobeState;
 } Paddle;
 
 uint8_t ReadPaddle(Paddle *pdl);

+ 23 - 28
src/paddle.c

@@ -6,99 +6,94 @@
  *  Copyright (c) 2002-2019 986-Studio.
  *
  */
-
+#include <stdio.h>
 #include <os_dependent.h>
 
 #include "paddle.h"
 
 void InitPaddle(Paddle *pdl)
 {
-    pdl->Bit = 1;
-    pdl->LastWrite = 0;
+    pdl->bitPos = 1;
+    pdl->strobeState = 0;
 }
 
 
 void WritePaddle(Paddle *pdl, uint8_t val)
 {
-    if ((pdl->LastWrite == 1) && (val == 0))
-    {
-        InitPaddle(pdl);
-    }
-
-    pdl->LastWrite = val;
+    pdl->strobeState = val & 1;
+    pdl->bitPos = 1;
 }
 
 uint8_t ReadPaddle(Paddle *pdl)
 {
-    switch (pdl->Bit++)
-    {
+    uint8_t ret = 0x40;
 
+    switch (pdl->bitPos)
+    {
     case 1:
         if (getKeyStatus('O'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 2:
         if (getKeyStatus('P'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 3:
         if (getKeyStatus('I'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 4:
         if (getKeyStatus('U'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 5:
         if (getKeyStatus('W'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 6:
         if (getKeyStatus('S'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 7:
         if (getKeyStatus('A'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
     case 8:
         if (getKeyStatus('D'))
         {
-            return 0x41;
+            ret = 0x41;
         }
         break;
 
-    case 20:
-        return 0x40;
-
-    case 24:
-        pdl->Bit = 1;
-        return 0x40;
-
     default:
-        return 0x40;
+        ret = 0x41;
+    }
+
+    if ((pdl->strobeState == 0) && (pdl->bitPos <= 9))
+    {
+        pdl->bitPos++;
     }
 
-    return 0x40;
+    return ret;
 }