111111
112112static uint8_t nextValue = 0 ; /* TMS9918A read-ahead value */
113113static bool currentInt = false; /* current interrupt state */
114- static uint8_t currentStatus = 0 ; /* current status register value */
114+ static uint8_t currentStatus = 0x1f ; /* current status register value */
115115
116116static uint8_t __aligned (4 ) tmsScanlineBuffer [TMS9918_PIXELS_X ];
117117
@@ -164,7 +164,7 @@ void __not_in_flash_func(pio_irq_handler)()
164164 }
165165 else // read status
166166 {
167- currentStatus = 0 ;
167+ currentStatus = 0x1f ;
168168 vrEmuTms9918SetStatusImpl (currentStatus );
169169 currentInt = false;
170170 gpio_put (GPIO_INT , !currentInt );
@@ -269,12 +269,6 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
269269
270270 y -= vBorder ;
271271
272- /*** left border ***/
273- for (int x = 0 ; x < hBorder ; ++ x )
274- {
275- pixels [x ] = bg ;
276- }
277-
278272 /*** main display region ***/
279273
280274 /* generate the scanline */
@@ -286,6 +280,25 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
286280 tempStatus |= STATUS_INT ;
287281 }
288282
283+ disableTmsPioInterrupts ();
284+ if ((currentStatus & STATUS_INT ) == 0 )
285+ {
286+ currentStatus = (currentStatus & 0xe0 ) | tempStatus ;
287+
288+ vrEmuTms9918SetStatusImpl (currentStatus );
289+ updateTmsReadAhead ();
290+
291+ currentInt = vrEmuTms9918InterruptStatusImpl ();
292+ gpio_put (GPIO_INT , !currentInt );
293+ }
294+ enableTmsPioInterrupts ();
295+
296+ /*** left border ***/
297+ for (int x = 0 ; x < hBorder ; ++ x )
298+ {
299+ pixels [x ] = bg ;
300+ }
301+
289302 /* convert from palette to bgr12 */
290303 int tmsX = 0 ;
291304 if (tmsScanlineBuffer [0 ] & 0xf0 )
@@ -305,31 +318,13 @@ static void __time_critical_func(tmsScanline)(uint16_t y, VgaParams* params, uin
305318 }
306319 }
307320
321+
308322 /*** right border ***/
309323 for (int x = hBorder + TMS9918_PIXELS_X * 2 ; x < VIRTUAL_PIXELS_X ; ++ x )
310324 {
311325 pixels [x ] = bg ;
312326 }
313327
314- disableTmsPioInterrupts ();
315- if ((currentStatus & STATUS_INT ) == 0 )
316- {
317- if ((currentStatus & STATUS_5S ) != 0 )
318- {
319- currentStatus |= tempStatus & 0xe0 ;
320- }
321- else
322- {
323- currentStatus |= tempStatus ;
324- }
325-
326- vrEmuTms9918SetStatusImpl (currentStatus );
327- updateTmsReadAhead ();
328-
329- currentInt = vrEmuTms9918InterruptStatusImpl ();
330- gpio_put (GPIO_INT , !currentInt );
331- }
332- enableTmsPioInterrupts ();
333328}
334329
335330/*
0 commit comments