Uzebox / uzebox

A retro-minimalist game console engine for the ATMega644
http://uzebox.org
126 stars 43 forks source link

Soft reset with CONTROLLERS_VSYNC_READ set may be unstable #81

Closed Jubatian closed 7 years ago

Jubatian commented 7 years ago

When you try to soft-reset the Uzebox with the SELECT + START + B + Y button combination, it attempts this using the watchdog. The watchdog is set to the shortest timeout which is around 16ms, and since it includes a "wdr" as well (the wdt_enable() routine used inserts one), it will be 16ms. After setting up the watchdog, it enters an infinite loop. This reset is performed in the ReadButtons() routine, called from ReadControllers().

If CONTROLLERS_VSYNC_READ is set, then this is called from interrupt, specifically the VSync. This interrupt happens about once in 16.67ms (60Hz), which is very near the watchdog's timeout. Since interrupts are not disabled in the soft reset routine, this could well cause the apparent pausing of the game so long it repeatedely resets the watchdog just before it could time out, worse, the same time piling up garbage in the stack (as the repeated resets happen within the Vsync routine which so never returns).

With some games this can end up in deadlocking the Uzebox (experienced on real hardware), possibly within a loop which keeps resetting the watchdog.

One possible obvious fix could be adding a "cli" to the routine, however that turns off display (not such a big deal, just that it would be less likely that a TV set loses sync during the restart if display off time is minimized).

Jubatian commented 7 years ago

Fixed. Testing on real hardware shows significant difference, the new soft reset is reliable and fast with games having CONTROLLERS_VSYNC_READ set.