Modernize code

Can compile with arm-none-eabi-gcc 8.3.0
gbafix correctly handles ELF input
This commit is contained in:
PikalaxALT 2019-06-26 08:13:38 -04:00
parent 3f43523352
commit fb06e4a3c9
36 changed files with 3552 additions and 308 deletions

View File

@ -12,12 +12,10 @@ TITLE := POKEMON EMER
GAME_CODE := BPEE
MAKER_CODE := 01
REVISION := 0
MODERN ?= 0
SHELL := /bin/bash -o pipefail
ROM := pokeemerald.gba
OBJ_DIR := build/emerald
ELF = $(ROM:.gba=.elf)
MAP = $(ROM:.gba=.map)
@ -34,12 +32,21 @@ DATA_ASM_BUILDDIR = $(OBJ_DIR)/$(DATA_ASM_SUBDIR)
SONG_BUILDDIR = $(OBJ_DIR)/$(SONG_SUBDIR)
MID_BUILDDIR = $(OBJ_DIR)/$(MID_SUBDIR)
ASFLAGS := -mcpu=arm7tdmi
ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=$(MODERN)
ifeq ($(MODERN),0)
CC1 := tools/agbcc/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm
ROM := pokeemerald.gba
OBJ_DIR := build/emerald
else
CC1 := $(shell $(PREFIX)gcc --print-prog-name=cc1)
override CFLAGS += -mthumb -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -quiet -fno-toplevel-reorder -Wno-aggressive-loop-optimizations
ROM := pokeemerald_modern.gba
OBJ_DIR := build/modern
endif
CPPFLAGS := -I tools/agbcc/include -I tools/agbcc -iquote include -Wno-trigraphs
CPPFLAGS := -I tools/agbcc/include -I tools/agbcc -iquote include -Wno-trigraphs -DMODERN=$(MODERN)
LDFLAGS = -Map ../../$(MAP)
@ -109,7 +116,10 @@ clean: tidy
tidy:
rm -f $(ROM) $(ELF) $(MAP)
ifeq ($(MODERN),0)
@$(MAKE) tidy MODERN=1
rm -r build/*
endif
include graphics_file_rules.mk
include map_data_rules.mk
@ -133,6 +143,7 @@ sound/direct_sound_samples/cry_%.bin: sound/direct_sound_samples/cry_%.aif ; $(A
sound/%.bin: sound/%.aif ; $(AIF) $< $@
ifeq ($(MODERN),0)
$(C_BUILDDIR)/libc.o: CC1 := tools/agbcc/bin/old_agbcc
$(C_BUILDDIR)/libc.o: CFLAGS := -O2
@ -145,6 +156,7 @@ $(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/m4a.o: CC1 := tools/agbcc/bin/old_agbcc
$(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding
endif
ifeq ($(NODEP),1)
$(C_BUILDDIR)/%.o: c_dep :=
@ -197,7 +209,9 @@ $(OBJ_DIR)/ld_script.ld: ld_script.txt $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_comm
$(ELF): $(OBJ_DIR)/ld_script.ld $(OBJS)
cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ld_script.ld -o ../../$@ $(OBJS_REL) $(LIB)
$(FIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
$(ROM): $(ELF)
$(OBJCOPY) -O binary $< $@
$(FIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@
modern: ; @$(MAKE) MODERN=1

View File

@ -6,9 +6,20 @@
#define TRUE 1
#define FALSE 0
#define BSS_DATA __attribute__((section(".bss")))
#if MODERN
#define IWRAM_DATA
#else
#define IWRAM_DATA __attribute__((section("iwram_data")))
#endif
#define EWRAM_DATA __attribute__((section("ewram_data")))
#if MODERN
#define NOINLINE __attribute__((noinline))
#else
#define NOINLINE
#endif
#define ALIGNED(n) __attribute__((aligned(n)))
#define SOUND_INFO_PTR (*(struct SoundInfo **)0x3007FF0)

View File

@ -192,4 +192,29 @@
REG_IME = imeTemp; \
} \
#if MODERN
#define FLOAT_UNS(x, bit) ({ \
s##bit sx = x; \
float fx = (float)sx; \
if (sx < 0) fx += (1 << (bit - 1)) * 2.0f; \
fx; \
})
#define DOUBLE_UNS(x, bit) ({ \
s##bit sx = x; \
double dx = (double)sx; \
if (sx < 0) dx += (1 << (bit - 1)) * 2.0; \
dx; \
})
#else
#define FLOAT_UNS(x, bit) ((float)(x))
#define DOUBLE_UNS(x, bit) ((double)(x))
#endif //MODERN
#define FLOAT_U8(x) FLOAT_UNS(x, 8)
#define FLOAT_U16(x) FLOAT_UNS(x, 16)
#define FLOAT_U32(x) FLOAT_UNS(x, 32)
#define DOUBLE_U8(x) DOUBLE_UNS(x, 8)
#define DOUBLE_U16(x) DOUBLE_UNS(x, 16)
#define DOUBLE_U32(x) DOUBLE_UNS(x, 32)
#endif // GUARD_GBA_MACRO_H

View File

@ -62,6 +62,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
// Extracts the upper 16 bits of a 32-bit number
#define HIHALF(n) (((n) & 0xFFFF0000) >> 16)

View File

@ -4005,9 +4005,6 @@ extern const u32 gBerryPalette_Starf[];
extern const u32 gBerryPic_Enigma[];
extern const u32 gBerryPalette_Enigma[];
//credits
extern const u32 gCreditsCopyrightEnd_Gfx[];
//pokenav
extern const u8 gPokenavConditionMarker_Gfx[];
extern const u16 gPokenavConditionMarker_Pal[];

View File

@ -1,6 +1,8 @@
#ifndef GUARD_PLAYER_PC_H
#define GUARD_PLAYER_PC_H
#include "menu.h"
// local task defines
#define PAGE_INDEX data[0]
#define ITEMS_ABOVE_TOP data[1]

View File

@ -485,7 +485,6 @@ extern const u8 gText_CryOf[];
extern const u8 gText_SizeComparedTo[];
extern const u8 gText_PokedexRegistration[];
extern const u8 gText_UnkCtrlF908Clear01[];
extern const u8 sText_TenDashes2[];
extern const u8 gText_5MarksPokemon[];
extern const u8 gText_UnkHeight[];
extern const u8 gText_UnkWeight[];

View File

@ -423,7 +423,9 @@ SECTIONS {
data/io_reg.o(.rodata);
src/string_util.o(.rodata);
src/link.o(.rodata);
src/link.o(.rodata.str1.4);
src/link_rfu.o(.rodata);
src/link_rfu.o(.rodata.str1.4);
src/union_room.o(.rodata);
src/mystery_gift.o(.rodata);
src/union_room_player_avatar.o(.rodata);
@ -434,6 +436,7 @@ SECTIONS {
src/mevent_client.o(.rodata);
src/mevent_scripts.o(.rodata);
src/union_room_chat.o(.rodata);
src/berry_crush.o(.rodata);
data/berry_crush.o(.rodata);
data/berry_powder.o(.rodata);
src/dodrio_berry_picking.o(.rodata);
@ -442,6 +445,7 @@ SECTIONS {
data/pokemon_jump.o(.rodata);
src/rtc.o(.rodata);
src/main_menu.o(.rodata);
src/battle_controllers.o(.rodata);
src/rom_8034C54.o(.rodata);
src/data.o(.rodata);
src/battle_bg.o(.rodata);
@ -451,6 +455,7 @@ SECTIONS {
src/battle_controller_player.o(.rodata);
data/smokescreen.o(.rodata);
src/battle_controller_opponent.o(.rodata);
src/battle_ai_switch_items.o(.rodata);
src/battle_controller_link_opponent.o(.rodata);
src/pokemon.o(.rodata);
src/trig.o(.rodata);
@ -473,6 +478,7 @@ SECTIONS {
src/event_object_movement.o(.rodata);
src/text_window.o(.rodata);
src/scrcmd.o(.rodata);
src/field_control_avatar.o(.rodata);
src/coord_event_weather.o(.rodata);
src/field_tasks.o(.rodata);
src/reset_rtc_screen.o(.rodata);
@ -483,6 +489,7 @@ SECTIONS {
src/battle_anim.o(.rodata);
src/battle_anim_mons.o(.rodata);
data/map_events.o(.rodata);
src/reshow_battle_screen.o(.rodata);
src/battle_anim_status_effects.o(.rodata);
src/title_screen.o(.rodata);
src/field_weather.o(.rodata);
@ -493,6 +500,7 @@ SECTIONS {
src/trainer_see.o(.rodata);
src/wild_encounter.o(.rodata);
src/field_effect.o(.rodata);
src/scanline_effect.o(.rodata);
src/option_menu.o(.rodata);
src/pokedex.o(.rodata);
src/trainer_card.o(.rodata);
@ -515,12 +523,14 @@ SECTIONS {
src/record_mixing.o(.rodata);
src/secret_base.o(.rodata);
src/tv.o(.rodata);
src/contest_link_80F57C4.o(.rodata);
data/contest_link_80F57C4.o(.rodata);
src/script_pokemon_util_80F87D8.o(.rodata);
src/pokemon_size_record.o(.rodata)
src/fldeff_misc.o(.rodata);
src/field_special_scene.o(.rodata);
src/rotating_gate.o(.rodata);
src/contest_link_80FC4F4.o(.rodata);
src/item_use.o(.rodata);
src/battle_anim_effects_1.o(.rodata);
src/battle_anim_effects_2.o(.rodata);
@ -549,6 +559,7 @@ SECTIONS {
src/menu_helpers.o(.rodata);
src/heal_location.o(.rodata);
src/region_map.o(.rodata);
src/contest_painting_effects.o(.rodata);
data/contest_painting_effects.o(.rodata);
src/decoration.o(.rodata);
src/slot_machine.o(.rodata);
@ -575,6 +586,7 @@ SECTIONS {
src/save.o(.rodata);
src/field_effect_helpers.o(.rodata);
src/contest_ai.o(.rodata);
src/battle_anim_sound_tasks.o(.rodata);
src/battle_controller_safari.o(.rodata);
src/battle_anim_effects_3.o(.rodata);
src/move_relearner.o(.rodata);
@ -617,6 +629,7 @@ SECTIONS {
src/battle_arena.o(.rodata);
src/battle_factory.o(.rodata);
src/battle_pike.o(.rodata);
src/mossdeep_gym.o(.rodata);
data/mossdeep_gym.o(.rodata);
src/battle_pyramid.o(.rodata);
src/item_menu.o(.rodata);
@ -626,6 +639,7 @@ SECTIONS {
src/party_menu.o(.rodata);
src/battle_tent.o(.rodata);
src/unk_text_util_2.o(.rodata);
src/multiboot.o(.rodata);
src/unk_81BAD84.o(.rodata);
src/battle_controller_player_partner.o(.rodata);
src/mirage_tower.o(.rodata);
@ -638,11 +652,16 @@ SECTIONS {
src/pokenav_match_call_ui.o(.rodata);
src/pokenav_unk_1.o(.rodata);
data/pokenav.o(.rodata);
src/pokenav_unk_3.o(.rodata);
src/pokenav_unk_4.o(.rodata);
src/pokenav_unk_5.o(.rodata);
src/pokenav_unk_10.o(.rodata);
src/pokenav_match_call_data.o(.rodata);
src/menu_specialized.o(.rodata);
src/ereader_helpers.o(.rodata);
data/ereader_helpers.o(.rodata);
src/faraway_island.o(.rodata);
src/ereader_screen.o(.rodata);
data/ereader_screen.o(.rodata);
src/trainer_hill.o(.rodata);
src/rayquaza_scene.o(.rodata);
@ -1195,6 +1214,7 @@ SECTIONS {
lib_rodata :
SUBALIGN(4)
{
src/m4a.o(.rodata);
src/agb_flash.o(.rodata);
src/agb_flash_1m.o(.rodata);
src/agb_flash_mx.o(.rodata);

View File

@ -5354,7 +5354,7 @@ void sub_8102EB0(struct Sprite* sprite)
if (GetBattlerSide(gBattleAnimAttacker) == B_SIDE_OPPONENT)
{
a = gBattleAnimArgs[1];
(u16)gBattleAnimArgs[1] = -a;
*(u16 *)&gBattleAnimArgs[1] = -a;
}
sprite->pos1.x = GetBattlerSpriteCoord(gBattleAnimAttacker, 2) + gBattleAnimArgs[1];

View File

@ -1024,13 +1024,13 @@ static const union AnimCmd gUnknown_0860D020[] =
static const union AnimCmd gUnknown_0860D028[] =
{
ANIMCMD_FRAME(18, 129, .vFlip = TRUE),
ANIMCMD_FRAME(18, 1, .vFlip = TRUE),
ANIMCMD_END,
};
static const union AnimCmd gUnknown_0860D030[] =
{
ANIMCMD_FRAME(16, 65, .hFlip = TRUE),
ANIMCMD_FRAME(16, 1, .hFlip = TRUE),
ANIMCMD_END,
};

View File

@ -914,7 +914,6 @@ void CopyBgTilemapBufferToVram(u8 bg)
void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 width, u8 height)
{
const void *srcCopy;
u16 destX16;
u16 destY16;
u16 mode;
@ -924,29 +923,33 @@ void CopyToBgTilemapBufferRect(u8 bg, const void* src, u8 destX, u8 destY, u8 wi
switch (GetBgType(bg))
{
case 0:
srcCopy = src;
{
const u16 * srcCopy = src;
for (destY16 = destY; destY16 < (destY + height); destY16++)
{
for (destX16 = destX; destX16 < (destX + width); destX16++)
{
((u16*)sGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *((u16*)srcCopy)++;
((u16*)sGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *srcCopy++;
}
}
break;
}
case 1:
srcCopy = src;
{
const u8 * srcCopy = src;
mode = GetBgMetricAffineMode(bg, 0x1);
for (destY16 = destY; destY16 < (destY + height); destY16++)
{
for (destX16 = destX; destX16 < (destX + width); destX16++)
{
((u8*)sGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *((u8*)srcCopy)++;
((u8*)sGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *srcCopy++;
}
}
break;
}
}
}
}
void CopyToBgTilemapBufferRect_ChangePalette(u8 bg, const void *src, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette)
{

View File

@ -269,8 +269,6 @@ extern const u8 gText_Contest_Fear[];
extern const u8 gText_BDot[];
extern const u8 gText_CDot[];
extern const u8 *const gUnknown_08587E10[];
extern const struct SpriteTemplate gSpriteTemplate_8587AD0;
extern const struct SpriteTemplate gSpriteTemplate_8587B18[];
extern void (*const gContestEffectFuncs[])(void);
static const u8 gUnknown_08587A6C[] =
@ -1268,7 +1266,7 @@ static void sub_80D8108(u8 taskId)
gTasks[taskId].data[0]++;
break;
case 1:
(s16)gBattle_BG1_Y += 7;
*(s16*)&gBattle_BG1_Y += 7;
if ((s16)gBattle_BG1_Y <= 160)
break;
gTasks[taskId].data[0]++;

View File

@ -28,11 +28,11 @@ struct ContestWinner *gUnknown_030061C0;
u16 *gContestPaintingMonPalette;
// IWRAM bss
IWRAM_DATA u8 gContestPaintingState;
IWRAM_DATA u16 gContestPaintingMosaicVal;
IWRAM_DATA u16 gContestPaintingFadeCounter;
IWRAM_DATA bool8 gUnknown_030011F6;
IWRAM_DATA u8 gContestPaintingWindowId;
static u8 gContestPaintingState;
static u16 gContestPaintingMosaicVal;
static u16 gContestPaintingFadeCounter;
static bool8 gUnknown_030011F6;
static u8 gContestPaintingWindowId;
static void ShowContestPainting(void);
static void HoldContestPainting(void);

View File

@ -8,7 +8,7 @@
#define DMA_REQUEST_COPY16 3
#define DMA_REQUEST_FILL16 4
IWRAM_DATA struct
BSS_DATA struct
{
const u8 *src;
u8 *dest;

View File

@ -145,7 +145,7 @@ EWRAM_DATA u16 * gUnknown_02022CE4[4] = {NULL};
EWRAM_DATA struct DodrioBerryPickingStruct_2022CF4 * gUnknown_02022CF4 = NULL;
EWRAM_DATA struct DodrioBerryPickingSubstruct_0160 * gUnknown_02022CF8 = NULL;
IWRAM_DATA bool32 gUnknown_03000DB0;
static bool32 gUnknown_03000DB0;
void sub_8024A1C(void);
void sub_8024A30(struct DodrioBerryPickingStruct *);

View File

@ -26,17 +26,17 @@ static void sub_81D414C(void);
static void sub_81D3F1C(u32, u32*, u32*);
static void sub_81D3F68(void);
IWRAM_DATA struct Unknown030012C8 gUnknown_030012C8;
IWRAM_DATA u16 gUnknown_030012E0;
IWRAM_DATA u16 gUnknown_030012E2;
IWRAM_DATA u16 gUnknown_030012E4;
IWRAM_DATA u16 gUnknown_030012E6;
IWRAM_DATA u32 gUnknown_030012E8;
IWRAM_DATA u16 gUnknown_030012EC;
IWRAM_DATA u16 gUnknown_030012EE;
IWRAM_DATA u16 gUnknown_030012F0;
IWRAM_DATA u16 gUnknown_030012F2;
IWRAM_DATA u16 gUnknown_030012F4;
static struct Unknown030012C8 gUnknown_030012C8;
static u16 gUnknown_030012E0;
static u16 gUnknown_030012E2;
static u16 gUnknown_030012E4;
static u16 gUnknown_030012E6;
static u32 gUnknown_030012E8;
static u16 gUnknown_030012EC;
static u16 gUnknown_030012EE;
static u16 gUnknown_030012F0;
static u16 gUnknown_030012F2;
static u16 gUnknown_030012F4;
extern const u8 gUnknown_08625B6C[][0x148];

View File

@ -891,6 +891,7 @@ static void sub_81094D0(u8 taskId) // animate Move_ERUPTION?
break;
default:
break;
}
}

View File

@ -1148,7 +1148,8 @@ static void sub_8112B78(struct Sprite *sprite)
if (++coeffB > 16)
coeffB = 16;
if (--(s16)coeffA < 0)
--coeffA;
if ((s16)coeffA < 0)
coeffA = 0;
SetGpuReg(REG_OFFSET_BLDALPHA, BLDALPHA_BLEND(coeffA, coeffB));

View File

@ -52,22 +52,21 @@ struct LinkTestBGInfo
// Static RAM declarations
IWRAM_DATA struct BlockTransfer sBlockSend;
IWRAM_DATA u32 link_c_unused_03000d1c;
IWRAM_DATA struct BlockTransfer sBlockRecv[MAX_LINK_PLAYERS];
IWRAM_DATA u32 sBlockSendDelayCounter;
IWRAM_DATA u32 gUnknown_03000D54;
IWRAM_DATA u8 gUnknown_03000D58;
IWRAM_DATA u32 sPlayerDataExchangeStatus;
IWRAM_DATA u32 gUnknown_03000D60;
IWRAM_DATA u8 sLinkTestLastBlockSendPos;
ALIGNED() IWRAM_DATA u8 sLinkTestLastBlockRecvPos[MAX_LINK_PLAYERS];
IWRAM_DATA u8 sNumVBlanksWithoutSerialIntr;
IWRAM_DATA bool8 sSendBufferEmpty;
IWRAM_DATA u16 sSendNonzeroCheck;
IWRAM_DATA u16 sRecvNonzeroCheck;
IWRAM_DATA u8 sChecksumAvailable;
IWRAM_DATA u8 sHandshakePlayerCount;
static struct BlockTransfer sBlockSend;
static struct BlockTransfer sBlockRecv[MAX_LINK_PLAYERS];
static u32 sBlockSendDelayCounter;
static u32 gUnknown_03000D54;
static u8 gUnknown_03000D58;
static u32 sPlayerDataExchangeStatus;
static u32 gUnknown_03000D60;
static u8 sLinkTestLastBlockSendPos;
static u8 sLinkTestLastBlockRecvPos[MAX_LINK_PLAYERS];
static u8 sNumVBlanksWithoutSerialIntr;
static bool8 sSendBufferEmpty;
static u16 sSendNonzeroCheck;
static u16 sRecvNonzeroCheck;
static u8 sChecksumAvailable;
static u8 sHandshakePlayerCount;
u16 gLinkPartnersHeldKeys[6];
u32 gLinkDebugSeed;

View File

@ -24,10 +24,10 @@ extern u16 gHeldKeyCodeToSend;
struct UnkRfuStruct_1 gUnknown_03004140;
struct UnkRfuStruct_2 gUnknown_03005000;
IWRAM_DATA u8 gUnknown_03000D74;
ALIGNED(4) IWRAM_DATA u8 gUnknown_03000D78[8];
IWRAM_DATA u8 gUnknown_03000D80[16];
IWRAM_DATA u16 gUnknown_03000D90[8];
BSS_DATA u8 gUnknown_03000D74;
ALIGNED(4) BSS_DATA u8 gUnknown_03000D78[8];
BSS_DATA u8 gUnknown_03000D80[16];
BSS_DATA u16 gUnknown_03000D90[8];
EWRAM_DATA u8 gWirelessStatusIndicatorSpriteId = 0;
EWRAM_DATA ALIGNED(4) struct UnkLinkRfuStruct_02022B14 gUnknown_02022B14 = {};
@ -2021,6 +2021,8 @@ void sub_800DBF8(u8 *q1, u8 mode)
}
}
// File boundary here maybe?
void PkmnStrToASCII(u8 *q1, const u8 *q2)
{
s32 i;
@ -5191,4 +5193,3 @@ u32 GetRfuRecvQueueLength(void)
{
return gUnknown_03005000.unk_124.unk_8c2;
}

View File

@ -1,3 +1,4 @@
#include <string.h>
#include "gba/m4a_internal.h"
extern const u8 gCgb3Vol[];

View File

@ -85,7 +85,7 @@ void EnableVCountIntrAtLine150(void);
void AgbMain()
{
RegisterRamReset(RESET_ALL);
RegisterRamReset(MODERN ? RESET_ALL & ~RESET_IWRAM : RESET_ALL);
*(vu16 *)BG_PLTT = 0x7FFF;
InitGpuRegManager();
REG_WAITCNT = WAITCNT_PREFETCH_ENABLE | WAITCNT_WS0_S_1 | WAITCNT_WS0_N_3;

View File

@ -33,7 +33,7 @@ static void Task_BardSong(u8 taskId);
static void StorytellerSetup(void);
static void Storyteller_ResetFlag(void);
IWRAM_DATA u8 sSelectedStory;
static u8 sSelectedStory;
struct BardSong gBardSong;

View File

@ -435,7 +435,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");

View File

@ -97,7 +97,7 @@ static void FormatMonSizeRecord(u8 *string, u32 size)
{
#ifdef UNITS_IMPERIAL
//Convert size from centimeters to inches
size = (double)(size * 10) / (CM_PER_INCH * 10);
size = DOUBLE_U32(size * 10) / (CM_PER_INCH * 10);
#endif
string = ConvertIntToDecimalStringN(string, size / 10, 0, 8);

View File

@ -142,7 +142,7 @@ static const union AnimCmd sSpriteAnim_85104CC[] =
static const union AnimCmd sSpriteAnim_85104D4[] =
{
ANIMCMD_FRAME(0, 158, .vFlip = TRUE),
ANIMCMD_FRAME(0, 30, .vFlip = TRUE),
ANIMCMD_JUMP(0),
};

View File

@ -3969,7 +3969,7 @@ static void sub_8144410(struct Sprite *sprite)
if (!sub_8143B48(sprite))
{
gUnknown_0203AB88->var90 = 0.0f;
gUnknown_0203AB88->var8C -= (float)(gUnknown_085B6348[gUnknown_0203AB88->var04_0].var03)
gUnknown_0203AB88->var8C -= FLOAT_U8(gUnknown_085B6348[gUnknown_0203AB88->var04_0].var03)
/ (gUnknown_085B6348[gUnknown_0203AB88->var04_0].var04 + 1);
sprite->data[1] = 4;
sprite->callback = sub_8144264;
@ -3994,8 +3994,8 @@ static void sub_8144514(struct Sprite *sprite)
if (gUnknown_0203AB88->var94 > 40.f)
return;
gUnknown_0203AB88->var98 = -(4.0f / (float)gUnknown_0203AB88->var86);
gUnknown_0203AB88->var90 = -(gUnknown_0203AB88->var8C / (float)gUnknown_0203AB88->var86);
gUnknown_0203AB88->var98 = -(4.0f / FLOAT_U16(gUnknown_0203AB88->var86));
gUnknown_0203AB88->var90 = -(gUnknown_0203AB88->var8C / FLOAT_U16(gUnknown_0203AB88->var86));
sprite->animNum = 2;
sprite->animBeginning = TRUE;
sprite->animEnded = FALSE;
@ -4010,8 +4010,8 @@ static void sub_81445D8(struct Sprite *sprite)
return;
m4aSongNumStartOrChange(SE_TAMAKORO_E);
gUnknown_0203AB88->var98 = -(20.0f / (float)gUnknown_0203AB88->var84);
gUnknown_0203AB88->var90 = ((1.0f - gUnknown_0203AB88->var8C) / (float)gUnknown_0203AB88->var84);
gUnknown_0203AB88->var98 = -(20.0f / FLOAT_U16(gUnknown_0203AB88->var84));
gUnknown_0203AB88->var90 = ((1.0f - gUnknown_0203AB88->var8C) / FLOAT_U16(gUnknown_0203AB88->var84));
sprite->animNum = 1;
sprite->animBeginning = TRUE;
sprite->animEnded = FALSE;

View File

@ -409,6 +409,7 @@ void UpdatePulseBlend(struct PulseBlend *pulseBlend)
}
break;
case 2: // Flip back and forth
// This code is never reached
if (pulseBlendPalette->fadeDirection)
pulseBlendPalette->blendCoeff = 0;
else

View File

@ -626,7 +626,10 @@ static u16 CalculateChecksum(void *data, u16 size)
u32 checksum = 0;
for (i = 0; i < (size / 4); i++)
checksum += *((u32 *)data)++;
{
checksum += *((u32 *)data);
data += sizeof(u32);
}
return ((checksum >> 16) + checksum);
}

View File

@ -62,7 +62,7 @@ static EWRAM_DATA u16 sMovingNpcMapBank = 0;
static EWRAM_DATA u16 sMovingNpcMapId = 0;
static EWRAM_DATA u16 sFieldEffectScriptId = 0;
IWRAM_DATA u8 gUnknown_03000F30;
static u8 gUnknown_03000F30;
extern const SpecialFunc gSpecials[];
extern const u8 *gStdScripts[];

View File

@ -1017,8 +1017,8 @@ const u8 *const gUnknown_0858BBEC[] =
EWRAM_DATA u8 gUnknown_02039F90 = 0;
IWRAM_DATA u8 gUnknown_03001124[7];
IWRAM_DATA u32 filler_0300112c;
static u8 gUnknown_03001124[7];
static u32 filler_0300112c;
static void Task_HandleMultichoiceInput(u8);
static void Task_HandleYesNoInput(u8);

View File

@ -56,9 +56,9 @@ struct {
u16 move;
} sTV_SecretBaseVisitMonsTemp[10];
IWRAM_DATA u8 sTVShowMixingNumPlayers;
IWRAM_DATA u8 sTVShowNewsMixingNumPlayers;
IWRAM_DATA s8 sTVShowMixingCurSlot;
static u8 sTVShowMixingNumPlayers;
static u8 sTVShowNewsMixingNumPlayers;
static s8 sTVShowMixingCurSlot;
EWRAM_DATA u16 sPokemonAnglerSpecies = 0;
EWRAM_DATA u16 sPokemonAnglerAttemptCounters = 0;
@ -70,9 +70,6 @@ EWRAM_DATA u8 sTVSecretBaseSecretsRandomValues[3] = {};
// Static ROM declarations
extern const u8 *const sTVBravoTrainerTextGroup[];
extern const u8 *const sTVBravoTrainerBattleTowerTextGroup[];
void ClearPokemonNews(void);
u8 GetTVChannelByShowType(u8 kind);
u8 FindFirstActiveTVShowThatIsNotAMassOutbreak(void);

View File

@ -60,9 +60,9 @@ EWRAM_DATA u8 gUnknown_02022C3E = 0;
EWRAM_DATA struct TradeUnkStruct gUnknown_02022C40 = {};
// IWRAM vars
IWRAM_DATA struct UnkStruct_Leader *gUnknown_03000DA0;
IWRAM_DATA struct UnkStruct_Group *gUnknown_03000DA4;
IWRAM_DATA struct UnkStruct_URoom *gUnknown_03000DA8;
static struct UnkStruct_Leader *gUnknown_03000DA0;
static struct UnkStruct_Group *gUnknown_03000DA4;
static struct UnkStruct_URoom *gUnknown_03000DA8;
// this file's functions
void sub_80173E0(u8 windowId, u8 arg1, const u8 *str, u8 arg3, u8 arg4, u8 arg5);

View File

@ -40,7 +40,7 @@ struct UnkStruct_2022C6C
s16 a0;
};
IWRAM_DATA struct UnkStruct_3000DAC * gUnknown_03000DAC;
static struct UnkStruct_3000DAC * gUnknown_03000DAC;
EWRAM_DATA struct UnkStruct_2022C6C * gUnknown_02022C6C = NULL;

3147
tools/gbafix/elf.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -48,6 +48,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "elf.h"
#define VER "1.06"
#define ARGV argv[arg]
@ -177,6 +178,25 @@ int main(int argc, char *argv[])
fseek(infile, 0, SEEK_SET);
fread(&header, sizeof(header), 1, infile);
// elf check
uint32_t sh_offset = 0;
if (memcmp(&header, ELFMAG, 4) == 0) {
Elf32_Ehdr *elfHeader = (Elf32_Ehdr *)&header;
fseek(infile, elfHeader->e_shoff, SEEK_SET);
int i;
for (i = 0; i < elfHeader->e_shnum; i++) {
Elf32_Shdr secHeader;
fread(&secHeader, sizeof(Elf32_Shdr), 1, infile);
if (secHeader.sh_type == SHT_PROGBITS && secHeader.sh_addr == elfHeader->e_entry) {
fseek(infile, secHeader.sh_offset, SEEK_SET);
sh_offset = secHeader.sh_offset;
break;
}
}
if (i == elfHeader->e_shnum) { fprintf(stderr, "Error finding entry point!\n"); return 1; }
fread(&header, sizeof(header), 1, infile);
}
// fix some data
memcpy(header.logo, good_header.logo, sizeof(header.logo));
memcpy(&header.fixed, &good_header.fixed, sizeof(header.fixed));
@ -279,7 +299,7 @@ int main(int argc, char *argv[])
header.complement = HeaderComplement();
//header.checksum = checksum_without_header + HeaderChecksum();
fseek(infile, 0, SEEK_SET);
fseek(infile, sh_offset, SEEK_SET);
fwrite(&header, sizeof(header), 1, infile);
fclose(infile);