From 1d6afc5473ca7c649b59e37ff4cd424e78c15d43 Mon Sep 17 00:00:00 2001 From: Godzil Date: Fri, 6 Dec 2019 12:34:11 +0000 Subject: [PATCH] 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 --- src/include/paddle.h | 4 ++-- src/paddle.c | 51 ++++++++++++++++++++------------------------ 2 files changed, 25 insertions(+), 30 deletions(-) diff --git a/src/include/paddle.h b/src/include/paddle.h index 9607924..17b79db 100755 --- a/src/include/paddle.h +++ b/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); diff --git a/src/paddle.c b/src/paddle.c index ed147ef..ea5e407 100755 --- a/src/paddle.c +++ b/src/paddle.c @@ -6,99 +6,94 @@ * Copyright (c) 2002-2019 986-Studio. * */ - +#include #include #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; } - return 0x40; + if ((pdl->strobeState == 0) && (pdl->bitPos <= 9)) + { + pdl->bitPos++; + } + + return ret; }