DragonMinded / libdragon

Open source library for N64 development.
https://libdragon.dev
The Unlicense
748 stars 108 forks source link

dma: rewrite dma_read_async to handle newly discovered hardware bugs #524

Closed rasky closed 7 months ago

rasky commented 7 months ago

dma_read_async supports transfers to misaligned RDRAM addresses, working around several hardware bugs in the process (since they were never officially supported by RCP).

Recently, more bugs have been discovered when the misaligned transfers cross RDRAM pages (on a 2 KiB boundary). These behaviors have been documented in n64brew (https://n64brew.dev/wiki/Peripheral_Interface#DMA_Transfers) and emulated in Ares (https://github.com/ares-emulator/ares/commit/4c15ed753eda971567e208c658ef69ae4cf77de7).

The previous version of dma_read_async wasn't aware of this behavior and transfers might produce corrupted data near to 2 KiB boundaries. This was causing random corruption bugs, especially visible as random assertions while decompressing assets.

This commit fixes dma_read_async to behave correctly also when crossing RDRAM pages, and updates the testsuite to exercise this corner case.

Until next hardware bug...