small typo and formatting fixes

Kurausukun 2021-05-23 18:18:30 -04:00
parent d3cc143cb5
commit 4f23f963ef
1 changed files with 2 additions and 4 deletions

@ -93,16 +93,14 @@ Note that this section only applies if you have both increased the engine rate i
```
Now all that we need to do is replace the definitions of the buffers. This must be done in the following two locations:
1. In [constants/m4a_constants.inc](https://github.com/pret/pokeemerald/blob/master/constants/m4a_constants.inc), `PCM_DMA_BUF_SIZE` is set on line 3; change it there.
2. In [include/gba/m4a_internal.h](https://github.com/pret/pokeemerald/blob/master/include/gba/m4a_internal.h), PCM_DMA_BUF_SIZE is set on line 169; change it there.
2. In [include/gba/m4a_internal.h](https://github.com/pret/pokeemerald/blob/master/include/gba/m4a_internal.h), `PCM_DMA_BUF_SIZE` is set on line 169; change it there.
### Making DMA transfers atomic
Because the new sound engine uses DMA3 (by default, see Mixer Config below), which the game does not expect, we have to make some adjustments to prevent game crashes. The reason we have to do this is that pokeemerald writes the DMA registers value by value which leaves a very small chance for interrupts inbetween those register writes. If we interrupt those writes before the DMA transfer is enabled (which is done by the last write) we will corrupt the register state and once the interrupt returns, a DMA transfer is initiated with the wrong values.
We can fix this very easily by using the `STMIA` instruction for DMA register writes, which cannot be interrupted. If we do that we can make sure the registers are always in a well defined state. Either a transfer is initialized and comleted or it is has not begun yet. See the following patch which makes the game write to DMA by using `STMIA`:
We can fix this very easily by using the `STMIA` instruction for DMA register writes, which cannot be interrupted. If we do that we can make sure the registers are always in a well defined state. Either a transfer is initialized and completed or it is has not begun yet. See the following patch which makes the game write to DMA by using `STMIA` in [include/gba/macro.h](https://github.com/pret/pokeemerald/blob/master/include/gba/macro.h):
```diff
--- pokeemerald/include/gba/macro.h
+++ pokeemerald/include/gba/macro.h
#define DmaSet(dmaNum, src, dest, control) \
{ \
vu32 *dmaRegs = (vu32 *)REG_ADDR_DMA##dmaNum; \