summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYamaArashi <shadow962@live.com>2016-05-15 16:43:56 -0700
committerYamaArashi <shadow962@live.com>2016-05-15 16:43:56 -0700
commit147c8672c3be861fa9229c775c37933a39900b9c (patch)
tree9b99fe61d63633717fb2682bcf3eb81442824bad
parent91b1aab02668e4671a01854db28e093d9cacc1c8 (diff)
new macros for declaring uninitialized IWRAM data
-rw-r--r--include/gba/gba.h22
-rw-r--r--include/gba/io_reg.h1
-rw-r--r--include/gba/macro.h8
-rw-r--r--include/gba/syscall.h18
-rw-r--r--src/m4a_2.c15
5 files changed, 53 insertions, 11 deletions
diff --git a/include/gba/gba.h b/include/gba/gba.h
index 9cacbfee0..06067dacf 100644
--- a/include/gba/gba.h
+++ b/include/gba/gba.h
@@ -32,12 +32,32 @@ typedef u32 bool32;
#define ALIGNED(n) __attribute__((aligned(n)))
+// The original build process placed COMMON data (i.e. uninitialized globals)
+// in IWRAM after the static variables.
+// When ld places COMMON variables in the output, it aligns the variable
+// according to the size of the variable, with a maximum alignment of 16. This
+// results in large alignment values.
+// Initialized variables are aligned according to the size of the largest
+// primitive type in the object, so their alignment will often be smaller.
+// However, we cannot use COMMON data in pokeruby because the order of COMMON
+// data in the output is not reliable. Instead, we need to initialize the
+// variables so that their order in the source file is preserved in the output.
+// But using initialized variables brings us into conflict with those large
+// alignment values.
+// These macros allow us to get around this by manually specifying what the
+// alignment would be if the variable were uninitialized.
+#define COMM(decl, n) IWRAM_DATA ALIGNED(1 << n) decl = {0};
+#define COMM_0(decl) COMM(decl, 0)
+#define COMM_1(decl) COMM(decl, 1)
+#define COMM_2(decl) COMM(decl, 2)
+#define COMM_4(decl) COMM(decl, 4)
+
#include "gba/io_reg.h"
#include "gba/syscall.h"
#include "gba/macro.h"
#define SOUND_INFO_PTR (*(struct SoundInfo **)0x3007FF0)
#define INTR_CHECK (*(u16 *)0x3007FF8)
-#define INTR_VECTOR (*(u32 *)0x3007FFC)
+#define INTR_VECTOR (*(void **)0x3007FFC)
#endif // GUARD_GBA_GBA_H
diff --git a/include/gba/io_reg.h b/include/gba/io_reg.h
index e29441f19..9673cd0ef 100644
--- a/include/gba/io_reg.h
+++ b/include/gba/io_reg.h
@@ -490,6 +490,7 @@
#define DMA_START_VBLANK 0x1000
#define DMA_START_HBLANK 0x2000
#define DMA_START_SPECIAL 0x3000
+#define DMA_START_MASK 0x3000
#define DMA_INTR_ENABLE 0x4000
#define DMA_ENABLE 0x8000
diff --git a/include/gba/macro.h b/include/gba/macro.h
index 1a778ef84..a886d12d4 100644
--- a/include/gba/macro.h
+++ b/include/gba/macro.h
@@ -49,4 +49,12 @@
#define DmaCopy16(dmaNum, src, dest, size) DMA_COPY(dmaNum, src, dest, size, 16)
#define DmaCopy32(dmaNum, src, dest, size) DMA_COPY(dmaNum, src, dest, size, 32)
+#define DmaStop(dmaNum) \
+{ \
+ vu16 *dmaRegs = (vu16 *)REG_ADDR_DMA##dmaNum; \
+ dmaRegs[5] &= ~(DMA_START_MASK | DMA_DREQ_ON | DMA_REPEAT); \
+ dmaRegs[5] &= ~DMA_ENABLE; \
+ dmaRegs[5]; \
+}
+
#endif // GUARD_GBA_MACRO_H
diff --git a/include/gba/syscall.h b/include/gba/syscall.h
index 4d69907ee..9b2b81311 100644
--- a/include/gba/syscall.h
+++ b/include/gba/syscall.h
@@ -1,12 +1,26 @@
#ifndef GUARD_GBA_SYSCALL_H
#define GUARD_GBA_SYSCALL_H
+#define RESET_EWRAM 0x01
+#define RESET_IWRAM 0x02
+#define RESET_PALETTE 0x04
+#define RESET_VRAM 0x08
+#define RESET_OAM 0x10
+#define RESET_SIO_REGS 0x20
+#define RESET_SOUND_REGS 0x40
+#define RESET_REGS 0x80
+#define RESET_ALL 0xFF
+
+void SoftReset(u32 resetFlags);
+
+void RegisterRamReset(u32 resetFlags);
+
#define CPU_SET_SRC_FIXED 0x01000000
#define CPU_SET_16BIT 0x00000000
#define CPU_SET_32BIT 0x04000000
-extern void CpuSet(void *src, void *dest, u32 control);
+void CpuSet(void *src, void *dest, u32 control);
-extern void VBlankIntrWait(void);
+void VBlankIntrWait(void);
#endif // GUARD_GBA_SYSCALL_H
diff --git a/src/m4a_2.c b/src/m4a_2.c
index 56487808c..2056f805a 100644
--- a/src/m4a_2.c
+++ b/src/m4a_2.c
@@ -4,14 +4,13 @@
BSS_CODE ALIGNED(4) char SoundMainRAM_Buffer[0x800] = {0};
-IWRAM_DATA struct SoundInfo gSoundInfo = {0};
-IWRAM_DATA struct PokemonCrySong gPokemonCrySongs[MAX_POKEMON_CRIES] = {0};
-IWRAM_DATA u8 gUnused_3006FE8[8] = {0}; // padding for alignment
-IWRAM_DATA struct MusicPlayerInfo gPokemonCryMusicPlayers[MAX_POKEMON_CRIES] = {0};
-IWRAM_DATA void *gMPlayJumpTable[36] = {0};
-IWRAM_DATA struct CgbChannel gCgbChans[4] = {0};
-IWRAM_DATA struct MusicPlayerTrack gPokemonCryTracks[MAX_POKEMON_CRIES * 2] = {0};
-IWRAM_DATA struct PokemonCrySong gPokemonCrySong = {0};
+COMM_4(struct SoundInfo gSoundInfo)
+COMM_4(struct PokemonCrySong gPokemonCrySongs[MAX_POKEMON_CRIES])
+COMM_4(struct MusicPlayerInfo gPokemonCryMusicPlayers[MAX_POKEMON_CRIES])
+COMM_4(void *gMPlayJumpTable[36])
+COMM_4(struct CgbChannel gCgbChans[4])
+COMM_4(struct MusicPlayerTrack gPokemonCryTracks[MAX_POKEMON_CRIES * 2])
+COMM_4(struct PokemonCrySong gPokemonCrySong)
u32 MidiKeyToFreq(struct WaveData *wav, u8 key, u8 fineAdjust)
{