@@ -30,9 +30,8 @@ static inline pio_sm_config nespad_program_get_default_config(uint offset) {
3030
3131static PIO pio = pio1;
3232static uint8_t sm = -1 ;
33- uint8_t nespad_state = 0 ; // Joystick 1
34- uint8_t nespad_state2 = 0 ; // Joystick 2
35- uint8_t snespad_state = 0 ; // SNES Joystick
33+ uint32_t nespad_state = 0 ; // Joystick 1
34+ uint32_t nespad_state2 = 0 ; // Joystick 2
3635
3736bool nespad_begin (uint32_t cpu_khz, uint8_t clkPin, uint8_t dataPin,uint8_t latPin) {
3837 if (pio_can_add_program (pio, &nespad_program) &&
@@ -88,42 +87,10 @@ void nespad_read()
8887
8988 // Right-shift was used in sm config so bit order matches NES controller
9089 // bits used elsewhere in picones, but does require shifting down...
91- uint32_t temp16=((pio->rxf [sm]))^ 0xFFFFFFFF ;
92- snespad_state = (temp16 >> 16 ) & 0xFF ;
93-
90+ uint32_t temp=pio->rxf [sm]^ 0xFFFFFFFF ;
9491 pio->txf [sm]=0 ;
95- uint16_t temp1, temp2;
96- // temp1 = temp16 & 0x5555; // 08070605.04030201
97- // temp2 = temp16 & 0xAAAA; // 80706050.40302010
98- // nespad_state=temp1|(temp1>>7); //84736251
99- // nespad_state2=(temp2|(temp2<<7))>>8;//84736251
100- // return;
101-
102-
103- // 1 -------------------------------------------------------
104- temp1 = temp16 & 0x5555 ; // 08070605.04030201
105- temp2 = temp16 & 0xAAAA ; // 80706050.40302010
106- temp16 = temp16 & 0xAA55 ; // 80706050.04030201
107- temp1 = temp1 >> 7 ; // 00000000.80706050
108- temp2 = temp2 << 7 ; // 04030201.00000000
109- temp16 = temp16 | temp1 | temp2; // 84736251.84736251
110- // 2 -------------------------------------------------------
111- temp1 = temp16 & 0x5050 ; // 04030000.04030000
112- temp2 = temp16 & 0x0A0A ; // 00006050.00006050
113- temp16 = temp16 & 0xA5A5 ; // 80700201.80700201
114- temp1 = temp1 >> 3 ; // 00004030.00004030
115- temp2 = temp2 << 3 ; // 06050000.06050000
116- temp16 = temp16 | temp1 | temp2; // 86754231.86754231
117- // 3 -------------------------------------------------------
118- temp1 = temp16 & 0x4444 ; // 06000200.06000200
119- temp2 = temp16 & 0x2222 ; // 00700030.00700030
120- temp16 = temp16 & 0x9999 ; // 80054001.80054001
121- temp1 = temp1 >> 1 ; // 00600020.00600020
122- temp2 = temp2 << 1 ; // 07000300.07000300
123- temp16 = temp16 | temp1 | temp2; // 87654321.87654321
124- // ----------------------------------------------------------
125- nespad_state = temp16; // 00000000.87654321 Joy1
126- nespad_state2 = temp16 >> 8 ; // 00000000.87654321 Joy2
92+ nespad_state = temp & 0x555555 ; // Joy1
93+ nespad_state2 = temp >> 1 & 0x555555 ; // Joy2
12794}
12895
12996
0 commit comments