-
-
Notifications
You must be signed in to change notification settings - Fork 92
PVSneslib and Mesen2
As described on github, Mesen is a multi-system emulator (NES, SNES, Game Boy, Game Boy Advance, PC Engine, SMS/Game Gear, WonderSwan) for Windows, Linux and macOS.
It is the tool we recommend to use with PVSneslib on any operating system to test your developments and debug them.
First, please download the version corresponding to your system then install it and validate that the emulator works correctly.
Show the end of logic as a point in the Mesen Event Viewer and then wait for NMI. The gap between this point and NMI shows remaining CPU time before VBlank.
Custom asm WaitForVBlank Method:
WFVBlank:
LDA.l $004210 ; read REG_RDNMI produces point in Event Viewer
WAI ; wait for NMI
rtl
.ends
LDA reads REG_RDNMI. Mesen displays this read as a point in the Event Viewer. WAI stops the CPU until NMI occurs. RTL returns to the caller afterward.
Your NMI handler must read or clear REG_RDNMI. If not cleared WAI may return immediately which removes the wait and invalidates the measurement.
Gameloop pattern:
while(1) {
do_logic();
WFVBlank();
do_vblank_dma();
}
The REG_RDNMI point marks the end of logic. The NMI event marks the start of VBlank. The gap between both events is headroom. If there is no gap logic is at the limit. If NMI occurs while logic is still running frame time is exceeded.
The screenshot shows that only a few scanlines remain before VBlank. This indicates that an overrun is close. Consider optimizing the logic or spreading work across multiple frames. If the number of free scanlines continues to shrink a real overrun will occur.
