diff options
author | PikalaxALT <PikalaxALT@gmail.com> | 2020-04-04 12:58:08 -0400 |
---|---|---|
committer | PikalaxALT <PikalaxALT@gmail.com> | 2020-04-04 12:58:08 -0400 |
commit | cc3419eff7c7139f4b4a92a31bbb6255e3dba1dd (patch) | |
tree | 73a4d8c2e5c34feb46ca9ada6b1668b3d95cd3ac | |
parent | c47eca8a182a2a202cd65e2af93e9ef322d8674c (diff) |
Get pokefirered_modern to build
-rw-r--r-- | Makefile | 92 | ||||
-rw-r--r-- | include/battle.h | 1 | ||||
-rw-r--r-- | include/config.h | 12 | ||||
-rw-r--r-- | include/field_specials.h | 2 | ||||
-rw-r--r-- | include/fieldmap.h | 6 | ||||
-rw-r--r-- | include/gba/defines.h | 6 | ||||
-rw-r--r-- | include/global.h | 4 | ||||
-rw-r--r-- | include/overworld.h | 4 | ||||
-rw-r--r-- | include/vs_seeker.h | 2 | ||||
-rw-r--r-- | ld_script_modern.txt | 91 | ||||
-rw-r--r-- | src/battle_anim.c | 2 | ||||
-rw-r--r-- | src/daycare.c | 2 | ||||
-rw-r--r-- | src/field_door.c | 2 | ||||
-rw-r--r-- | src/intro.c | 464 | ||||
-rw-r--r-- | src/link_rfu_2.c | 2 | ||||
-rw-r--r-- | src/main.c | 20 | ||||
-rw-r--r-- | src/multiboot.c | 4 | ||||
-rw-r--r-- | src/play_time.c | 2 |
18 files changed, 604 insertions, 114 deletions
@@ -1,12 +1,56 @@ -include $(DEVKITARM)/base_tools - +TOOLCHAIN := $(DEVKITARM) COMPARE ?= 0 -CPP := $(CC) -E -LD := $(DEVKITARM)/bin/arm-none-eabi-ld +ifeq ($(CC),) +HOSTCC := gcc +else +HOSTCC := $(CC) +endif + +ifeq ($(CXX),) +HOSTCXX := g++ +else +HOSTCXX := $(CXX) +endif + +ifneq (,$(wildcard $(TOOLCHAIN)/base_tools)) +include $(TOOLCHAIN)/base_tools +else +export PATH := $(TOOLCHAIN)/bin:$(PATH) +PREFIX := arm-none-eabi- +OBJCOPY := $(PREFIX)objcopy +export CC := $(PREFIX)gcc +export AS := $(PREFIX)as +endif +export CPP := $(PREFIX)cpp +export LD := $(PREFIX)ld + +ifeq ($(OS),Windows_NT) +EXE := .exe +else +EXE := +endif include config.mk +GCC_VER = $(shell $(CC) -dumpversion) + +ifeq ($(MODERN),0) +CC1 := tools/agbcc/bin/agbcc +override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm +LIBPATH := -L ../../tools/agbcc/lib +else +CC1 := $(shell $(CC) --print-prog-name=cc1) -quiet +override CFLAGS += -mthumb -mthumb-interwork -O2 -mtune=arm7tdmi -march=armv4t -mabi=apcs-gnu -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast +#LIBPATH := -L $(TOOLCHAIN)/lib/gcc/arm-none-eabi/$(GCC_VER)/thumb -L $(TOOLCHAIN)/arm-none-eabi/lib/thumb +LIBPATH := -L ../../tools/agbcc/lib +endif + +CPPFLAGS := -iquote include -D$(GAME_VERSION) -DREVISION=$(GAME_REVISION) -D$(GAME_LANGUAGE) -DMODERN=$(MODERN) +ifeq ($(MODERN),0) +CPPFLAGS += -I tools/agbcc -I tools/agbcc/include -nostdinc -undef +endif + SHELL := /bin/bash -o pipefail ROM := poke$(BUILD_NAME).gba @@ -28,16 +72,14 @@ DATA_ASM_BUILDDIR = $(OBJ_DIR)/$(DATA_ASM_SUBDIR) SONG_BUILDDIR = $(OBJ_DIR)/$(SONG_SUBDIR) MID_BUILDDIR = $(OBJ_DIR)/$(MID_SUBDIR) -ASFLAGS := -mcpu=arm7tdmi --defsym $(GAME_VERSION)=1 --defsym REVISION=$(GAME_REVISION) --defsym $(GAME_LANGUAGE)=1 - -CC1 := tools/agbcc/bin/agbcc -override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm - -CPPFLAGS := -I tools/agbcc -I tools/agbcc/include -iquote include -nostdinc -undef -D$(GAME_VERSION) -DREVISION=$(GAME_REVISION) -D$(GAME_LANGUAGE) +ASFLAGS := -mcpu=arm7tdmi --defsym $(GAME_VERSION)=1 --defsym REVISION=$(GAME_REVISION) --defsym $(GAME_LANGUAGE)=1 --defsym MODERN=$(MODERN) LDFLAGS = -Map ../../$(MAP) -LIB := -L ../../tools/agbcc/lib -lgcc -lc +LIB := $(LIBPATH) -lgcc -lc +#ifneq ($(MODERN),0) +#LIB += -lsysbase +#endif SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c GFX := tools/gbagfx/gbagfx @@ -96,7 +138,7 @@ TOOLS = $(foreach tool,$(TOOLBASE),tools/$(tool)/$(tool)$(EXE)) ALL_BUILDS := firered firered_rev1 leafgreen leafgreen_rev1 -.PHONY: all rom tools clean-tools mostlyclean clean compare tidy berry_fix $(TOOLDIRS) $(ALL_BUILDS) $(ALL_BUILDS:%=compare_%) +.PHONY: all rom tools clean-tools mostlyclean clean compare tidy berry_fix $(TOOLDIRS) $(ALL_BUILDS) $(ALL_BUILDS:%=compare_%) $(ALL_BUILDS:%=%_modern) modern MAKEFLAGS += --no-print-directory @@ -162,6 +204,7 @@ sound/%.bin: sound/%.aif ; $(AIF) $< $@ sound/songs/%.s: sound/songs/%.mid cd $(@D) && ../../$(MID) $(<F) +ifeq ($(MODERN),0) $(C_BUILDDIR)/agb_flash.o: CFLAGS := -O -mthumb-interwork $(C_BUILDDIR)/agb_flash_1m.o: CFLAGS := -O -mthumb-interwork $(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork @@ -176,6 +219,12 @@ $(C_BUILDDIR)/flying.o: CFLAGS += -ffreestanding $(C_BUILDDIR)/librfu_intr.o: CC1 := tools/agbcc/bin/agbcc_arm $(C_BUILDDIR)/librfu_intr.o: CFLAGS := -O2 -mthumb-interwork -quiet +else +$(C_BUILDDIR)/berry_crush_2.o: CFLAGS += -Wno-address-of-packed-member +$(C_BUILDDIR)/text.o: CFLAGS += -Wno-address-of-packed-member +$(C_BUILDDIR)/battle_tower.o: CFLAGS += -Wno-div-by-zero +$(C_BUILDDIR)/librfu_intr.o: override CFLAGS += -marm -mthumb-interwork -O2 -mtune=arm7tdmi -march=armv4t -mabi=apcs-gnu -fno-toplevel-reorder -fno-aggressive-loop-optimizations -Wno-pointer-to-int-cast +endif ifeq ($(NODEP),1) $(C_BUILDDIR)/%.o: c_dep := @@ -224,11 +273,19 @@ $(OBJ_DIR)/sym_common.ld: sym_common.txt $(C_OBJS) $(wildcard common_syms/*.txt) $(OBJ_DIR)/sym_ewram.ld: sym_ewram.txt $(RAMSCRGEN) ewram_data $< ENGLISH > $@ -$(OBJ_DIR)/ld_script.ld: ld_script.txt $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld +ifeq ($(MODERN),0) +LD_SCRIPT := ld_script.txt +LD_SCRIPT_DEPS := $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld +else +LD_SCRIPT := ld_script_modern.txt +LD_SCRIPT_DEPS := +endif + +$(OBJ_DIR)/ld_script.ld: $(LD_SCRIPT) $(LD_SCRIPT_DEPS) cd $(OBJ_DIR) && sed -f ../../ld_script.sed ../../$< | sed "s#tools/#../../tools/#g" > ld_script.ld $(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS) - cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(LIB) + cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) $(LIB) $(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent $(ROM): $(ELF) @@ -244,3 +301,10 @@ compare_firered: ; @$(MAKE) GAME_VERSION=FIRERED COMPARE=1 compare_firered_rev1: ; @$(MAKE) GAME_VERSION=FIRERED GAME_REVISION=1 COMPARE=1 compare_leafgreen: ; @$(MAKE) GAME_VERSION=LEAFGREEN COMPARE=1 compare_leafgreen_rev1: ; @$(MAKE) GAME_VERSION=LEAFGREEN GAME_REVISION=1 COMPARE=1 + +firered_modern: ; @$(MAKE) GAME_VERSION=FIRERED MODERN=1 +firered_rev1_modern: ; @$(MAKE) GAME_VERSION=FIRERED GAME_REVISION=1 MODERN=1 +leafgreen_modern: ; @$(MAKE) GAME_VERSION=LEAFGREEN MODERN=1 +leafgreen_rev1_modern: ; @$(MAKE) GAME_VERSION=LEAFGREEN GAME_REVISION=1 MODERN=1 + +modern: ; @$(MAKE) MODERN=1 diff --git a/include/battle.h b/include/battle.h index c9534745d..5144ed38d 100644 --- a/include/battle.h +++ b/include/battle.h @@ -1,6 +1,7 @@ #ifndef GUARD_BATTLE_H #define GUARD_BATTLE_H +#include <limits.h> #include "global.h" #include "constants/battle.h" #include "battle_util.h" diff --git a/include/config.h b/include/config.h index 4577f1b60..bdad6bb28 100644 --- a/include/config.h +++ b/include/config.h @@ -18,14 +18,14 @@ #define GAME_VERSION VERSION_FIRE_RED #else // Default version seems to be LeafGreen #define GAME_VERSION VERSION_LEAF_GREEN -#endif +#endif // GAME_VERSION // rev1 renamed the source folder for reasons #if REVISION == 0 #define CODE_ROOT "C:/WORK/POKeFRLG/src/pm_lgfr_ose/source/" #else #define CODE_ROOT "C:/WORK/POKeFRLG/Src/pm_lgfr_ose/source/" -#endif +#endif // REVISION #define ABSPATH(x) (CODE_ROOT x) @@ -33,6 +33,12 @@ #define UNITS_IMPERIAL #else #define UNITS_METRIC -#endif +#endif // ENGLISH + +// Crashes may occur due to section reordering in the modern build, +// so we force BUGFIX here. +#if MODERN +#define BUGFIX +#endif // MODERN #endif // GUARD_CONFIG_H diff --git a/include/field_specials.h b/include/field_specials.h index 5beeba928..0a4ea7bce 100644 --- a/include/field_specials.h +++ b/include/field_specials.h @@ -13,7 +13,7 @@ enum HiddenItemAttr u8 GetLeadMonIndex(void); s32 CountDigits(s32 number); -void TV_PrintIntToStringVar(u8, int); +void TV_PrintIntToStringVar(u8 varidx, s32 number); u16 GetStarterSpecies(void); void StopPokemonLeagueLightingEffectTask(void); void nullsub_60(void); diff --git a/include/fieldmap.h b/include/fieldmap.h index 40aa1c916..c12dea340 100644 --- a/include/fieldmap.h +++ b/include/fieldmap.h @@ -14,11 +14,11 @@ extern struct BackupMapLayout VMap; extern const struct MapLayout Route1_Layout; -u32 MapGridGetMetatileIdAt(int, int); +u32 MapGridGetMetatileIdAt(s32, s32); u32 MapGridGetMetatileBehaviorAt(s16, s16); u8 MapGridGetMetatileLayerTypeAt(s16 x, s16 y); -void MapGridSetMetatileIdAt(int, int, u16); -void MapGridSetMetatileEntryAt(int, int, u16); +void MapGridSetMetatileIdAt(s32, s32, u16); +void MapGridSetMetatileEntryAt(s32, s32, u16); u8 MapGridGetZCoordAt(s32 x, s32 y); void GetCameraCoords(u16*, u16*); bool8 MapGridIsImpassableAt(s32, s32); diff --git a/include/gba/defines.h b/include/gba/defines.h index 9e822358a..28f804dff 100644 --- a/include/gba/defines.h +++ b/include/gba/defines.h @@ -14,6 +14,12 @@ #define EWRAM_DATA __attribute__((section("ewram_data"))) #endif +#if MODERN +#define NOINLINE __attribute__((noinline)) +#else +#define NOINLINE +#endif + #define ALIGNED(n) __attribute__((aligned(n))) #define SOUND_INFO_PTR (*(struct SoundInfo **)0x3007FF0) diff --git a/include/global.h b/include/global.h index aa60be994..4a636957b 100644 --- a/include/global.h +++ b/include/global.h @@ -50,6 +50,10 @@ #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) >= (b) ? (a) : (b)) +#if MODERN +#define abs(x) (((x) < 0) ? -(x) : (x)) +#endif + // There are many quirks in the source code which have overarching behavioral differences from // a number of other files. For example, diploma.c seems to declare rodata before each use while // other files declare out of order and must be at the beginning. There are also a number of diff --git a/include/overworld.h b/include/overworld.h index f5cb1987e..c2fb8db2c 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -71,8 +71,8 @@ void Overworld_SetObjEventTemplateMovementType(u8, u8); void SetWarpDestination(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); -void SetDynamicWarp(int unused, s8 mapGroup, s8 mapNum, s8 warpId); -void SetDynamicWarpWithCoords(int unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); +void SetDynamicWarp(s32 unused, s8 mapGroup, s8 mapNum, s8 warpId); +void SetDynamicWarpWithCoords(s32 unused, s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void SetFixedDiveWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void SetFixedHoleWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); void SetEscapeWarp(s8 mapGroup, s8 mapNum, s8 warpId, s8 x, s8 y); diff --git a/include/vs_seeker.h b/include/vs_seeker.h index 6668cc6b4..d0f589866 100644 --- a/include/vs_seeker.h +++ b/include/vs_seeker.h @@ -6,7 +6,7 @@ void Task_VsSeeker_0(u8 taskId); void sub_810CB90(void); void sub_810CDE8(void); -int GetRematchTrainerId(u16 a0); +s32 GetRematchTrainerId(u16 a0); bool8 sub_810CF04(u8 a0); void sub_810D0D0(void); void sub_810CB90(void); diff --git a/ld_script_modern.txt b/ld_script_modern.txt new file mode 100644 index 000000000..68d704109 --- /dev/null +++ b/ld_script_modern.txt @@ -0,0 +1,91 @@ +gNumMusicPlayers = 4; +gMaxLines = 0; + +SECTIONS { + . = 0x2000000; + + ewram (NOLOAD) : + ALIGN(4) + { + gHeap = .; + + . = 0x1C000; + + *(ewram_data); + /* pokemon_summary_screen.o */ + gUnknown_203B140 = .; . += 0x4; + gUnknown_203B144 = .; . += 0x4; + gUnknown_203B148 = .; . += 0x10; + gUnknown_203B158 = .; . += 0x4; + gUnknown_203B15C = .; . += 0x4; + gUnknown_203B160 = .; . += 0x4; + gUnknown_203B164 = .; . += 0x4; + gUnknown_203B168 = .; . += 0x4; + gLastViewedMonIndex = .; . += 0x1; + gUnknown_203B16D = .; . += 0x1; + gUnknown_203B16E = .; . += 0x2; + gUnknown_203B170 = .; . += 0x4; + + . = 0x40000; +} + + . = 0x3000000; + + iwram (NOLOAD) : + ALIGN(4) + { + /* .bss starts at 0x3000000 */ + *(.bss*); + /* .bss.code starts at 0x3001AA8 */ + src/m4a.o(.bss.code); + + /* COMMON starts at 0x30022A8 */ + *(COMMON); + end = .; + . = 0x8000; + } + + . = 0x8000000; + + .text : + ALIGN(4) + { + asm/crt0.o(.text); + *(.text*); + } =0 + + script_data : + ALIGN(4) + { + *(script_data); + } =0 + + .data : + ALIGN(4) + { + *(.data*); + } =0 + + .rodata : + ALIGN(4) + { + *(.rodata*); + } =0 + + /* DWARF 2 sections */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + .debug_info 0 : { *(.debug_info) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + + /* Discard everything not specifically mentioned above. */ + /DISCARD/ : + { + *(*); + } +} diff --git a/src/battle_anim.c b/src/battle_anim.c index 1132b5725..b070766aa 100644 --- a/src/battle_anim.c +++ b/src/battle_anim.c @@ -2840,7 +2840,7 @@ s8 BattleAnimAdjustPanning2(s8 pan) return pan; } -s16 KeepPanInRange(s16 panArg, int oldPan) +s16 KeepPanInRange(s16 panArg, s32 oldPan) { s16 pan = panArg; diff --git a/src/daycare.c b/src/daycare.c index 1e50a7c09..5285abfb6 100644 --- a/src/daycare.c +++ b/src/daycare.c @@ -70,7 +70,7 @@ static void CreateRandomEggShardSprite(void); static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex); // IWRAM bss -static IWRAM_DATA struct EggHatchData *sEggHatchData; +static struct EggHatchData *sEggHatchData; // RAM buffers used to assist with BuildEggMoveset() EWRAM_DATA static u16 sHatchedEggLevelUpMoves[EGG_LVL_UP_MOVES_ARRAY_COUNT] = {0}; diff --git a/src/field_door.c b/src/field_door.c index e17ef0d5a..59b72f3ab 100644 --- a/src/field_door.c +++ b/src/field_door.c @@ -470,7 +470,7 @@ bool8 FieldIsDoorAnimationRunning(void) return FuncIsActiveTask(Task_AnimateDoor); } -u16 GetDoorSoundEffect(x, y) +u16 GetDoorSoundEffect(int x, int y) { if (GetDoorSoundType(sDoorGraphics, x, y) == DOOR_SOUND_NORMAL) return MUS_W_DOOR; diff --git a/src/intro.c b/src/intro.c index ec15d7473..7e1030090 100644 --- a/src/intro.c +++ b/src/intro.c @@ -47,18 +47,18 @@ static EWRAM_DATA u16 gUnknown_203AB06 = 0; static EWRAM_DATA u16 gUnknown_203AB08 = 0; static EWRAM_DATA u16 gUnknown_203AB0A = 0; static EWRAM_DATA u16 gUnknown_203AB0C = 0; -static EWRAM_DATA u16 gUnknown_203AB0E = 0; -static EWRAM_DATA u16 gUnknown_203AB10 = 0; -static EWRAM_DATA u16 gUnknown_203AB12 = 0; -static EWRAM_DATA u16 gUnknown_203AB14 = 0; -static EWRAM_DATA u16 gUnknown_203AB16 = 0; -static EWRAM_DATA u16 gUnknown_203AB18 = 0; -static EWRAM_DATA u16 gUnknown_203AB1A = 0; -static EWRAM_DATA u16 gUnknown_203AB1C = 0; -static EWRAM_DATA u16 gUnknown_203AB1E = 0; -static EWRAM_DATA u16 gUnknown_203AB20 = 0; -static EWRAM_DATA u16 gUnknown_203AB22 = 0; -static EWRAM_DATA u16 gUnknown_203AB24 = 0; +static EWRAM_DATA u16 sLargeStarXSpeed = 0; +static EWRAM_DATA u16 sLargeStarYSpeed = 0; +static EWRAM_DATA u16 sTrailingSparklesXmodMask = 0; +static EWRAM_DATA u16 sUnusedVarRelatedToGameFreakStars = 0; +static EWRAM_DATA u16 sTrailingSparklesSpawnRate = 0; +static EWRAM_DATA u16 sTrailingSparklesFlickerStartTime = 0; +static EWRAM_DATA u16 sTrailingSparklesDestroySpriteTime = 0; +static EWRAM_DATA u16 sTrailingSparklesGravityShift = 0; +static EWRAM_DATA u16 sTrailingSparklesXspeed = 0; +static EWRAM_DATA u16 sTrailingSparklesYspeed = 0; +static EWRAM_DATA u16 sTrailingSparklesXprecision = 0; +static EWRAM_DATA u16 sTrailingSparklesYprecision = 0; static void CB2_SetUpIntro(void); static void CB2_Intro(void); @@ -181,30 +181,111 @@ static const u32 sSpriteTiles_GengarSwipe[] = INCBIN_U32("graphics/intro/unk_840 static const u32 sSpriteTiles_NidorinoRecoilDust[] = INCBIN_U32("graphics/intro/unk_840BAE0.4bpp.lz"); static const struct BgTemplate sBgTemplates_GameFreakScene[] = { - { 3, 3, 31, 0, 0, 3, 0x000 }, - { 2, 3, 30, 0, 0, 2, 0x010 } + { + .bg = 3, + .charBaseIndex = 3, + .mapBaseIndex = 31, + .screenSize = 0, + .paletteMode = 0, + .priority = 3, + .baseTile = 0x000 + }, { + .bg = 2, + .charBaseIndex = 3, + .mapBaseIndex = 30, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0x010 + } }; static const struct BgTemplate sBgTemplates_FightScene1[] = { - { 0, 0, 28, 2, 0, 0, 0x000 }, - { 1, 1, 30, 2, 0, 0, 0x000 } + { + .bg = 0, + .charBaseIndex = 0, + .mapBaseIndex = 28, + .screenSize = 2, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + }, { + .bg = 1, + .charBaseIndex = 1, + .mapBaseIndex = 30, + .screenSize = 2, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + } }; static const struct BgTemplate sBgTemplates_FightScene2[] = { - { 3, 1, 30, 2, 0, 3, 0x000 }, - { 0, 0, 29, 0, 0, 0, 0x000 }, - { 2, 3, 27, 0, 0, 2, 0x000 }, - { 1, 2, 28, 0, 0, 1, 0x000 } + { + .bg = 3, + .charBaseIndex = 1, + .mapBaseIndex = 30, + .screenSize = 2, + .paletteMode = 0, + .priority = 3, + .baseTile = 0x000 + }, { + .bg = 0, + .charBaseIndex = 0, + .mapBaseIndex = 29, + .screenSize = 0, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + }, { + .bg = 2, + .charBaseIndex = 3, + .mapBaseIndex = 27, + .screenSize = 0, + .paletteMode = 0, + .priority = 2, + .baseTile = 0x000 + }, { + .bg = 1, + .charBaseIndex = 2, + .mapBaseIndex = 28, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0x000 + } }; static const struct BgTemplate sBgTemplates_FightScene3[] = { - { 1, 0, 29, 0, 0, 1, 0x000 }, - { 0, 1, 30, 2, 0, 0, 0x000 } + { + .bg = 1, + .charBaseIndex = 0, + .mapBaseIndex = 29, + .screenSize = 0, + .paletteMode = 0, + .priority = 1, + .baseTile = 0x000 + }, { + .bg = 0, + .charBaseIndex = 1, + .mapBaseIndex = 30, + .screenSize = 2, + .paletteMode = 0, + .priority = 0, + .baseTile = 0x000 + } }; static const struct WindowTemplate sWindowTemplate[] = { - { 2, 6, 4, 18, 9, 0xD, 0x000 }, - DUMMY_WIN_TEMPLATE + { + .bg = 2, + .tilemapLeft = 6, + .tilemapTop = 4, + .width = 18, + .height = 9, + .paletteNum = 0xD, + .baseBlock = 0x000 + }, DUMMY_WIN_TEMPLATE }; static const u8 sGengarBackSpritePos2UpdateMods[][2] = { @@ -241,9 +322,31 @@ static const struct Coords16 sTrailingSparkleCoords[] = { {0x0098, 0x0056} }; -static const struct OamData gOamData_840BC2C = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_1, .tileNum = 0x000, .priority = 2, .paletteNum = 0 }; +static const struct OamData gOamData_840BC2C = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_1, + .tileNum = 0x000, + .priority = 2, + .paletteNum = 0 +}; -static const struct OamData gOamData_840BC34 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_0, .tileNum = 0x000, .priority = 2, .paletteNum = 0 }; +static const struct OamData gOamData_840BC34 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_0, + .tileNum = 0x000, + .priority = 2, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmd_840BC3C[] = { ANIMCMD_FRAME(0, 4), @@ -266,11 +369,38 @@ static const union AnimCmd *const gAnimCmdTable_840BC64[] = { gAnimCmd_840BC50 }; -static const struct SpriteTemplate sSpriteTemplate_LargeStar = {0, 0, &gOamData_840BC2C, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCB_LargeStar}; +static const struct SpriteTemplate sSpriteTemplate_LargeStar = { + .tileTag = 0, + .paletteTag = 0, + .oam = &gOamData_840BC2C, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_LargeStar +}; -static const struct SpriteTemplate sSpriteTemplate_TrailingSparkles = {1, 1, &gOamData_840BC34, gAnimCmdTable_840BC64, NULL, gDummySpriteAffineAnimTable, SpriteCB_TrailingSparkles}; +static const struct SpriteTemplate sSpriteTemplate_TrailingSparkles = { + .tileTag = 1, + .paletteTag = 1, + .oam = &gOamData_840BC34, + .anims = gAnimCmdTable_840BC64, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_TrailingSparkles +}; -static const struct OamData gOamData_840BC9C = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_2, .tileNum = 0x000, .priority = 2, .paletteNum = 0 }; +static const struct OamData gOamData_840BC9C = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_2, + .tileNum = 0x000, + .priority = 2, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmd_840BCA4[] = { ANIMCMD_FRAME(0, 8), @@ -284,17 +414,74 @@ static const union AnimCmd *const gAnimCmdTable_840BCB8[] = { gAnimCmd_840BCA4 }; -static const struct SpriteTemplate sSpriteTemplate_RevealGameFreakTextSparkles = {2, 1, &gOamData_840BC9C, gAnimCmdTable_840BCB8, NULL, gDummySpriteAffineAnimTable, SpriteCB_RevealGameFreakTextSparkles}; +static const struct SpriteTemplate sSpriteTemplate_RevealGameFreakTextSparkles = { + .tileTag = 2, + .paletteTag = 1, + .oam = &gOamData_840BC9C, + .anims = gAnimCmdTable_840BCB8, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_RevealGameFreakTextSparkles +}; -static const struct OamData gOamData_840BCD4 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_BLEND, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_V_RECTANGLE, .matrixNum = 0, .size = ST_OAM_SIZE_3, .tileNum = 0x000, .priority = 3, .paletteNum = 0 }; +static const struct OamData gOamData_840BCD4 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_BLEND, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_V_RECTANGLE, + .matrixNum = 0, + .size = ST_OAM_SIZE_3, + .tileNum = 0x000, + .priority = 3, + .paletteNum = 0 +}; -static const struct SpriteTemplate sSpriteTemplate_GameFreakLogoArt = {3, 3, &gOamData_840BCD4, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_GameFreakLogoArt = { + .tileTag = 3, + .paletteTag = 3, + .oam = &gOamData_840BCD4, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; -static const struct OamData gOamData_840BCF4 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_BLEND, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_H_RECTANGLE, .matrixNum = 0, .size = ST_OAM_SIZE_1, .tileNum = 0x000, .priority = 3, .paletteNum = 0 }; +static const struct OamData gOamData_840BCF4 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_BLEND, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_H_RECTANGLE, + .matrixNum = 0, + .size = ST_OAM_SIZE_1, + .tileNum = 0x000, + .priority = 3, + .paletteNum = 0 +}; -static const struct SpriteTemplate sSpriteTemplate_PresentsText = {4, 3, &gOamData_840BCF4, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_PresentsText = { + .tileTag = 4, + .paletteTag = 3, + .oam = &gOamData_840BCF4, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; -static const struct OamData gOamData_840BD14 = { .affineMode = ST_OAM_AFFINE_DOUBLE, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_3, .tileNum = 0x000, .priority = 1, .paletteNum = 0 }; +static const struct OamData gOamData_840BD14 = { + .affineMode = ST_OAM_AFFINE_DOUBLE, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_3, + .tileNum = 0x000, + .priority = 1, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmd_840BD1C[] = { ANIMCMD_FRAME(0, 1), @@ -345,15 +532,61 @@ static const union AffineAnimCmd *const sAffineAnimTable_NidorinoAnim[] = { gAffineAnimCmd_840BD68 }; -static const struct SpriteTemplate sSpriteTemplate_NidorinoAnim = {5, 7, &gOamData_840BD14, sAnimTable_NidorinoAnim, NULL, sAffineAnimTable_NidorinoAnim, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_NidorinoAnim = { + .tileTag = 5, + .paletteTag = 7, + .oam = &gOamData_840BD14, + .anims = sAnimTable_NidorinoAnim, + .images = NULL, + .affineAnims = sAffineAnimTable_NidorinoAnim, + .callback = SpriteCallbackDummy +}; -static const struct OamData gOamData_840BDA0 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_3, .tileNum = 0x000, .priority = 1, .paletteNum = 0 }; +static const struct OamData gOamData_840BDA0 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_3, + .tileNum = 0x000, + .priority = 1, + .paletteNum = 0 +}; -static const struct SpriteTemplate sSpriteTemplate_NidorinoStatic = {7, 7, &gOamData_840BDA0, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_NidorinoStatic = { + .tileTag = 7, + .paletteTag = 7, + .oam = &gOamData_840BDA0, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; -static const struct SpriteTemplate sSpriteTemplate_GengarStatic = {6, 6, &gOamData_840BDA0, gDummySpriteAnimTable, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_GengarStatic = { + .tileTag = 6, + .paletteTag = 6, + .oam = &gOamData_840BDA0, + .anims = gDummySpriteAnimTable, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; -static const struct OamData gOamData_840BDD8 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_H_RECTANGLE, .matrixNum = 0, .size = ST_OAM_SIZE_3, .tileNum = 0x000, .priority = 0, .paletteNum = 0 }; +static const struct OamData gOamData_840BDD8 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_H_RECTANGLE, + .matrixNum = 0, + .size = ST_OAM_SIZE_3, + .tileNum = 0x000, + .priority = 0, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmds_840BDE0[] = { ANIMCMD_FRAME(0, 0), @@ -371,9 +604,28 @@ static const union AnimCmd *const gAnimCmdTable_840BDF4[] = { gAnimCmds_840BDE8 }; -static const struct SpriteTemplate sSpriteTemplate_Grass = {8, 8, &gOamData_840BDD8, gAnimCmdTable_840BDF4, NULL, gDummySpriteAffineAnimTable, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_Grass = { + .tileTag = 8, + .paletteTag = 8, + .oam = &gOamData_840BDD8, + .anims = gAnimCmdTable_840BDF4, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCallbackDummy +}; -static const struct OamData gOamData_840BE14 = { .affineMode = ST_OAM_AFFINE_DOUBLE, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_3, .tileNum = 0x000, .priority = 1, .paletteNum = 0 }; +static const struct OamData gOamData_840BE14 = { + .affineMode = ST_OAM_AFFINE_DOUBLE, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_3, + .tileNum = 0x000, + .priority = 1, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmd_840BE1C[] = { ANIMCMD_FRAME(0, 0), @@ -402,9 +654,28 @@ static const union AnimCmd *const gAnimCmdTable_840BE3C[] = { gAnimCmd_840BE34 }; -static const struct SpriteTemplate sSpriteTemplate_GengarBack = {9, 6, &gOamData_840BE14, gAnimCmdTable_840BE3C, NULL, sAffineAnimTable_NidorinoAnim, SpriteCallbackDummy}; +static const struct SpriteTemplate sSpriteTemplate_GengarBack = { + .tileTag = 9, + .paletteTag = 6, + .oam = &gOamData_840BE14, + .anims = gAnimCmdTable_840BE3C, + .images = NULL, + .affineAnims = sAffineAnimTable_NidorinoAnim, + .callback = SpriteCallbackDummy +}; -static const struct OamData gOamData_840BE64 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_V_RECTANGLE, .matrixNum = 0, .size = ST_OAM_SIZE_3, .tileNum = 0x000, .priority = 1, .paletteNum = 0 }; +static const struct OamData gOamData_840BE64 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_V_RECTANGLE, + .matrixNum = 0, + .size = ST_OAM_SIZE_3, + .tileNum = 0x000, + .priority = 1, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmd_840BE6C[] = { ANIMCMD_FRAME(0, 8), @@ -423,9 +694,28 @@ static const union AnimCmd *const gAnimCmdTable_840BE84[] = { gAnimCmd_840BE78 }; -static const struct SpriteTemplate sSpriteTemplate_GengarSwipe = {10, 10, &gOamData_840BE64, gAnimCmdTable_840BE84, NULL, gDummySpriteAffineAnimTable, SpriteCB_GengarSwipe}; +static const struct SpriteTemplate sSpriteTemplate_GengarSwipe = { + .tileTag = 10, + .paletteTag = 10, + .oam = &gOamData_840BE64, + .anims = gAnimCmdTable_840BE84, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_GengarSwipe +}; -static const struct OamData gOamData_840BEA4 = { .affineMode = ST_OAM_AFFINE_OFF, .objMode = ST_OAM_OBJ_NORMAL, .mosaic = FALSE, .bpp = ST_OAM_4BPP, .shape = ST_OAM_SQUARE, .matrixNum = 0, .size = ST_OAM_SIZE_1, .tileNum = 0x000, .priority = 1, .paletteNum = 0 }; +static const struct OamData gOamData_840BEA4 = { + .affineMode = ST_OAM_AFFINE_OFF, + .objMode = ST_OAM_OBJ_NORMAL, + .mosaic = FALSE, + .bpp = ST_OAM_4BPP, + .shape = ST_OAM_SQUARE, + .matrixNum = 0, + .size = ST_OAM_SIZE_1, + .tileNum = 0x000, + .priority = 1, + .paletteNum = 0 +}; static const union AnimCmd gAnimCmd_840BEAC[] = { ANIMCMD_FRAME(0, 10), @@ -439,7 +729,15 @@ static const union AnimCmd *const gAnimCmdTable_840BEC0[] = { gAnimCmd_840BEAC }; -static const struct SpriteTemplate sSpriteTemplate_NidorinoRecoilDust = {11, 11, &gOamData_840BEA4, gAnimCmdTable_840BEC0, NULL, gDummySpriteAffineAnimTable, SpriteCB_NidorinoRecoilDust}; +static const struct SpriteTemplate sSpriteTemplate_NidorinoRecoilDust = { + .tileTag = 11, + .paletteTag = 11, + .oam = &gOamData_840BEA4, + .anims = gAnimCmdTable_840BEC0, + .images = NULL, + .affineAnims = gDummySpriteAffineAnimTable, + .callback = SpriteCB_NidorinoRecoilDust +}; static const struct CompressedSpriteSheet sFightSceneSpriteSheets[] = { {sSpriteTiles_GengarStatic, 0x0800, 6}, @@ -1473,58 +1771,58 @@ static void GameFreakScene_LoadGfxCreateStar(void) { int i; u8 spriteId; - static EWRAM_DATA u32 gUnknown_203AB28 = 0; + static EWRAM_DATA u32 sTrailingSparklesRngSeed = 0; for (i = 0; i < NELEMS(sSpriteSheets_GameFreakScene); i++) { LoadCompressedSpriteSheet(&sSpriteSheets_GameFreakScene[i]); } LoadSpritePalettes(sSpritePalettes_GameFreakScene); - gUnknown_203AB0E = 0x60; - gUnknown_203AB10 = 0x10; - gUnknown_203AB12 = 0x07; - gUnknown_203AB14 = 0x05; - gUnknown_203AB16 = 0x08; - gUnknown_203AB18 = 0x5A; - gUnknown_203AB1A = 0x78; - gUnknown_203AB1E = 0x01; - gUnknown_203AB20 = 0x01; - gUnknown_203AB22 = 0x05; - gUnknown_203AB24 = 0x05; - if (gUnknown_203AB28 == 0) - gUnknown_203AB28 = 354128453; + sLargeStarXSpeed = 0x60; + sLargeStarYSpeed = 0x10; + sTrailingSparklesXmodMask = 0x07; + sUnusedVarRelatedToGameFreakStars = 5; + sTrailingSparklesSpawnRate = 8; + sTrailingSparklesFlickerStartTime = 90; + sTrailingSparklesDestroySpriteTime = 120; + sTrailingSparklesXspeed = 1; + sTrailingSparklesYspeed = 1; + sTrailingSparklesXprecision = 5; + sTrailingSparklesYprecision = 5; + if (sTrailingSparklesRngSeed == 0) + sTrailingSparklesRngSeed = 354128453; spriteId = CreateSprite(&sSpriteTemplate_LargeStar, 0xF8, 0x37, 0); if (spriteId != MAX_SPRITES) { gSprites[spriteId].data[0] = 0xF80; gSprites[spriteId].data[1] = 0x370; - gSprites[spriteId].data[2] = gUnknown_203AB0E; - gSprites[spriteId].data[3] = gUnknown_203AB10; - StoreWordInTwoHalfwords((u16 *)&gSprites[spriteId].data[6], gUnknown_203AB28); + gSprites[spriteId].data[2] = sLargeStarXSpeed; + gSprites[spriteId].data[3] = sLargeStarYSpeed; + StoreWordInTwoHalfwords((u16 *)&gSprites[spriteId].data[6], sTrailingSparklesRngSeed); } } static void GameFreakScene_TrailingSparklesGen(s16 x, s16 y, u16 a2) { - static EWRAM_DATA s16 gUnknown_203AB2C = 0; + static EWRAM_DATA s16 sYmod = 0; u8 spriteId; - s16 r4 = (a2 & gUnknown_203AB12) + 2; - s16 r2 = gUnknown_203AB2C; - gUnknown_203AB2C++; - if (gUnknown_203AB2C > 3) - gUnknown_203AB2C = -3; - x += r4; - y += r2; + s16 xMod = (a2 & sTrailingSparklesXmodMask) + 2; + s16 yMod = sYmod; + sYmod++; + if (sYmod > 3) + sYmod = -3; + x += xMod; + y += yMod; if (x >= 1 && x <= 0xEF) { spriteId = CreateSprite(&sSpriteTemplate_TrailingSparkles, x, y, 1); if (spriteId != MAX_SPRITES) { - gSprites[spriteId].data[0] = x << gUnknown_203AB22; - gSprites[spriteId].data[1] = y << gUnknown_203AB24; - gSprites[spriteId].data[2] = gUnknown_203AB1E * r4; - gSprites[spriteId].data[3] = gUnknown_203AB20 * r2; + gSprites[spriteId].data[0] = x << sTrailingSparklesXprecision; + gSprites[spriteId].data[1] = y << sTrailingSparklesYprecision; + gSprites[spriteId].data[2] = sTrailingSparklesXspeed * xMod; + gSprites[spriteId].data[3] = sTrailingSparklesYspeed * yMod; } } } @@ -1755,7 +2053,7 @@ static void SpriteCB_LargeStar(struct Sprite * sprite) sprite->pos1.y = sprite->data[1] >> 4; sprite->pos2.y = gSineTable[(sprite->data[4] >> 4) + 0x40] >> 5; sprite->data[5]++; - if (sprite->data[5] % gUnknown_203AB16) + if (sprite->data[5] % sTrailingSparklesSpawnRate) { LoadWordFromTwoHalfwords(&sprite->data[6], &v); v = v * 1103515245 + 24691; @@ -1776,14 +2074,14 @@ static void SpriteCB_TrailingSparkles(struct Sprite * sprite) sprite->data[4]++; sprite->data[5] += sprite->data[4]; sprite->data[7]++; - sprite->pos1.x = (u16)sprite->data[0] >> gUnknown_203AB22; - sprite->pos1.y = sprite->data[1] >> gUnknown_203AB24; - if (gUnknown_203AB1C && sprite->data[3] < 0) - sprite->pos2.y = sprite->data[5] >> gUnknown_203AB1C; - if (sprite->data[7] > gUnknown_203AB18) + sprite->pos1.x = (u16)sprite->data[0] >> sTrailingSparklesXprecision; + sprite->pos1.y = sprite->data[1] >> sTrailingSparklesYprecision; + if (sTrailingSparklesGravityShift && sprite->data[3] < 0) + sprite->pos2.y = sprite->data[5] >> sTrailingSparklesGravityShift; + if (sprite->data[7] > sTrailingSparklesFlickerStartTime) { sprite->invisible = !sprite->invisible; - if (sprite->data[7] > gUnknown_203AB1A) + if (sprite->data[7] > sTrailingSparklesDestroySpriteTime) DestroySprite(sprite); } if (sprite->pos1.y + sprite->pos2.y < 0 || sprite->pos1.y + sprite->pos2.y > 160) diff --git a/src/link_rfu_2.c b/src/link_rfu_2.c index 15ffb4813..77153f943 100644 --- a/src/link_rfu_2.c +++ b/src/link_rfu_2.c @@ -47,7 +47,7 @@ static void RfuFunc_SendNextBlock(void); static void RfuFunc_SendLastBlock(void); static void CallRfuFunc(void); static void sub_80FA738(void); -static int sub_80FA788(void); +static s32 sub_80FA788(void); static void sub_80FA834(u8 taskId); static void sub_80FA9D0(u16 a0); static void ValidateAndReceivePokemonSioInfo(void * a0); diff --git a/src/main.c b/src/main.c index 77f668e6f..367b7943d 100644 --- a/src/main.c +++ b/src/main.c @@ -90,7 +90,27 @@ void EnableVCountIntrAtLine150(void); void AgbMain() { +#if MODERN + // Modern compilers are liberal with the stack on entry to this function, + // so RegisterRamReset may crash if it resets IWRAM. + RegisterRamReset(RESET_ALL & ~RESET_IWRAM); + asm("mov\tr1, #0xC0\n" + "\tlsl\tr1, r1, #0x12\n" + "\tmov r2, #0xFC\n" + "\tlsl r2, r2, #0x7\n" + "\tadd\tr2, r1, r2\n" + "\tmov\tr0, #0\n" + "\tmov\tr3, r0\n" + "\tmov\tr4, r0\n" + "\tmov\tr5, r0\n" + ".LCU0:\n" + "\tstmia r1!, {r0, r3, r4, r5}\n" + "\tcmp\tr1, r2\n" + "\tbcc\t.LCU0\n" + ); +#else RegisterRamReset(RESET_ALL); +#endif //MODERN *(vu16 *)BG_PLTT = RGB_WHITE; InitGpuRegManager(); REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3; diff --git a/src/multiboot.c b/src/multiboot.c index cfc9821d2..b44c421dc 100644 --- a/src/multiboot.c +++ b/src/multiboot.c @@ -1,7 +1,7 @@ #include "global.h" #include "multiboot.h" -static IWRAM_DATA u16 MultiBoot_required_data[MULTIBOOT_NCHILD]; +static u16 MultiBoot_required_data[MULTIBOOT_NCHILD]; static int MultiBootSend(struct MultiBootParam *mp, u16 data); static int MultiBootHandShake(struct MultiBootParam *mp); @@ -390,7 +390,7 @@ static int MultiBootHandShake(struct MultiBootParam *mp) #undef must_data } -static void MultiBootWaitCycles(u32 cycles) +static NOINLINE void MultiBootWaitCycles(u32 cycles) { asm("mov r2, pc"); asm("lsr r2, #24"); diff --git a/src/play_time.c b/src/play_time.c index 04f4b2040..966840505 100644 --- a/src/play_time.c +++ b/src/play_time.c @@ -1,6 +1,6 @@ #include "play_time.h" -static IWRAM_DATA u8 sPlayTimeCounterState; +static u8 sPlayTimeCounterState; enum { |