110110//#define PICO_CLOCK_PLL 1512000000 // 302.4MHz - standard voltage
111111//#define PICO_CLOCK_PLL_DIV1 5
112112
113- // #define PICO_CLOCK_PLL 1308000000 // 327MHz - 1.15v
114- // #define PICO_CLOCK_PLL_DIV1 4
113+ #define PICO_CLOCK_PLL 1308000000 // 327MHz - 1.15v
114+ #define PICO_CLOCK_PLL_DIV1 4
115115
116116//#define PICO_CLOCK_PLL 984000000 // 328MHz - 1.15v
117117//#define PICO_CLOCK_PLL_DIV1 3
118118
119119//#define PICO_CLOCK_PLL 1056000000 // 352MHz - 1.3v
120120//#define PICO_CLOCK_PLL_DIV1 3
121121
122- #define PICO_CLOCK_PLL 1128000000 // 376MHz - 1.3v
123- #define PICO_CLOCK_PLL_DIV1 3
122+ // #define PICO_CLOCK_PLL 1128000000 // 376MHz - 1.3v
123+ // #define PICO_CLOCK_PLL_DIV1 3
124124
125125//#define PICO_CLOCK_PLL 1512000000 // 378MHz - 1.3v
126126//#define PICO_CLOCK_PLL_DIV1 4
@@ -160,9 +160,9 @@ static uint8_t nextValue = 0; /* TMS9918A read-ahead value */
160160static bool currentInt = false; /* current interrupt state */
161161static uint8_t currentStatus = 0x1f ; /* current status register value */
162162
163- static __attribute__((section (".scratch_y.buffer" ))) uint32_t __aligned ( 4 ) bg ;
163+ static __attribute__((section (".scratch_y.buffer" ))) uint32_t bg ;
164164
165- static __attribute__((section (".scratch_x.buffer" ))) uint8_t __aligned (4 ) tmsScanlineBuffer [TMS9918_PIXELS_X + 8 ];
165+ static __attribute__((section (".scratch_x.buffer" ))) uint8_t __aligned (8 ) tmsScanlineBuffer [TMS9918_PIXELS_X + 8 ];
166166
167167const uint tmsWriteSm = 0 ;
168168const uint tmsReadSm = 1 ;
@@ -210,7 +210,6 @@ void __not_in_flash_func(pio_irq_handler)()
210210 else if ((TMS_PIO -> fstat & (1u << (PIO_FSTAT_RXEMPTY_LSB + tmsReadSm ))) == 0 ) // read?
211211 {
212212 uint32_t readVal = TMS_PIO -> rxf [tmsReadSm ];
213- uint32_t readDat = TMS_PIO -> rxf [tmsReadSm ]; // What was read?
214213
215214 if ((readVal & 0x04 ) == 0 ) // read data
216215 {
@@ -219,18 +218,25 @@ void __not_in_flash_func(pio_irq_handler)()
219218 }
220219 else // read status
221220 {
221+ readVal >>= (3 + 16 ); // What status was read?
222222 tms9918 -> regWriteStage = 0 ;
223223 switch (tms9918 -> registers [0x0F ] & 0x0F )
224224 {
225225 case 0 :
226- currentStatus &= ~(readDat >> 16 ); // Switch off any 3 high bits which have just been read
227- currentStatus |= 0x1f ;
226+ readVal &= (STATUS_INT | STATUS_5S | STATUS_COL );
227+ currentStatus &= ~readVal ; // Switch off any 3 high bits which have just been read
228+ if (readVal & STATUS_5S ) // Was 5th Sprite read?
229+ currentStatus |= 0x1f ;
228230 vrEmuTms9918SetStatusImpl (currentStatus );
229- currentInt = false;
230- gpio_put (GPIO_INT , !currentInt );
231+ if (readVal & STATUS_INT ) // Was Interrupt read?
232+ {
233+ currentInt = false;
234+ gpio_put (GPIO_INT , !currentInt );
235+ }
231236 break ;
232237 case 1 :
233- tms9918 -> status [0x01 ] &= ~0x01 ;
238+ if ((readVal << 31 ) >> 31 ) // & 0x01
239+ tms9918 -> status [0x01 ] &= ~0x01 ;
234240 break ;
235241 }
236242 }
@@ -266,11 +272,13 @@ void __not_in_flash_func(gpioIrqHandler)()
266272 disableTmsPioInterrupts ();
267273 vrEmuTms9918Reset ();
268274
275+ * ((io_rw_32 * )(PPB_BASE + M0PLUS_NVIC_ICPR_OFFSET )) = 1u << TMS_IRQ ;
269276 pio_sm_clear_fifos (TMS_PIO , tmsReadSm );
270277 pio_sm_clear_fifos (TMS_PIO , tmsWriteSm );
271278
272279 nextValue = 0 ;
273280 currentStatus = 0x1f ;
281+ vrEmuTms9918SetStatusImpl (currentStatus );
274282 currentInt = false;
275283 doneInt = true;
276284 updateTmsReadAhead ();
0 commit comments