Skip to content

Commit 03fba99

Browse files
committed
Fix memory corruption issue in joystick code
The values for offset0 and offset1 were coming out to 63 when they should be no more than 3. I think the devide should have beena modulus? I wrote out the code with more vars to figure ouit what was going on joystock.c Fix uint8 logical compare 0xFF to 0xF Signed-off-by: Joseph Mattello <[email protected]>
1 parent 390c44d commit 03fba99

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

src/joystick.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ uint16_t JoystickReadWord(uint32_t offset)
6666
uint8_t offset0, offset1;
6767
uint16_t data = 0xFFFF;
6868

69-
if (!joysticksEnabled)
69+
if (!joysticksEnabled) {
7070
return 0xFFFF;
71+
}
7172

7273
// Joystick data returns active low for buttons pressed, high for non-
7374
// pressed.
@@ -119,14 +120,14 @@ uint16_t JoystickReadWord(uint32_t offset)
119120
if (offset0 != 0xFF)
120121
{
121122
data &= (joypad0Buttons[mask[offset0][0]] ? 0xFFFD : 0xFFFF);
122-
if (mask[offset0][1] != 0xFF)
123+
if (mask[offset0][1] != 0xF)
123124
data &= (joypad0Buttons[mask[offset0][1]] ? 0xFFFE : 0xFFFF);
124125
}
125126

126127
if (offset1 != 0xFF)
127128
{
128129
data &= (joypad1Buttons[mask[offset1][0]] ? 0xFFF7 : 0xFFFF);
129-
if (mask[offset1][1] != 0xFF)
130+
if (mask[offset1][1] != 0xF)
130131
data &= (joypad1Buttons[mask[offset1][1]] ? 0xFFFB : 0xFFFF);
131132
}
132133

0 commit comments

Comments
 (0)