From dac4192fd3b875706a7f1ce8bfb97c813ea503de Mon Sep 17 00:00:00 2001 From: GriffinR Date: Sun, 31 Oct 2021 16:36:31 -0400 Subject: [PATCH 1/5] Split headers from crt0 --- ld_script.txt | 4 + src/crt0.s | 100 ------------------------- asm/rom_header.inc => src/rom_header.s | 7 ++ src/rom_header_gf.s | 89 ++++++++++++++++++++++ 4 files changed, 100 insertions(+), 100 deletions(-) rename asm/rom_header.inc => src/rom_header.s (73%) create mode 100644 src/rom_header_gf.s diff --git a/ld_script.txt b/ld_script.txt index 3c1a25094..10abd8810 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -47,6 +47,8 @@ SECTIONS { .text : ALIGN(4) { + src/rom_header.o(.text); + src/rom_header_gf.o(.text); src/crt0.o(.text); src/main.o(.text); gflib/malloc.o(.text); @@ -435,6 +437,8 @@ SECTIONS { .rodata : ALIGN(4) { + src/rom_header.o(.rodata); + src/rom_header_gf.o(.rodata); src/main.o(.rodata); gflib/bg.o(.rodata); gflib/window.o(.rodata); diff --git a/src/crt0.s b/src/crt0.s index 672fc94f2..6e3b86a72 100644 --- a/src/crt0.s +++ b/src/crt0.s @@ -1,107 +1,7 @@ -#include "constants/global.h" .include "constants/gba_constants.inc" .syntax unified - .global Start - - .text - - .arm - -Start: @ 8000000 - b Init - - .include "asm/rom_header.inc" - -@ 80000C0 - .word 0 - - .global GPIOPortData -GPIOPortData: @ 80000C4 - .2byte 0 - - .global GPIOPortDirection -GPIOPortDirection: @ 80000C6 - .2byte 0 - - .global GPIOPortReadEnable -GPIOPortReadEnable: @ 80000C8 - .2byte 0 - -@ 80000CA - .2byte 0 - -@ 80000CC - .space 0x34 - - .4byte GAME_VERSION - .4byte GAME_LANGUAGE - - .ascii "pokemon emerald version" - .space 9 - - .4byte gMonFrontPicTable - .4byte gMonBackPicTable - .4byte gMonPaletteTable - .4byte gMonShinyPaletteTable - .4byte gMonIconTable - .4byte gMonIconPaletteIndices - .4byte gMonIconPaletteTable - .4byte gSpeciesNames - .4byte gMoveNames - .4byte gDecorations - - .4byte 0x00001270 @ offsetof(struct SaveBlock1, flags) - .4byte 0x0000139c @ offsetof(struct SaveBlock1, vars) - .4byte 0x00000018 @ offsetof(struct SaveBlock2, pokedex) - .4byte 0x00000988 @ offsetof(struct SaveBlock1, seen1) - .4byte 0x00003b24 @ offsetof(struct SaveBlock1, seen2) - .4byte 0x00000046 @ ? - .4byte 0x000008e4 @ ? - .4byte 0x000008ac @ ? - .4byte 0x00000182 @ NATIONAL_DEX_COUNT? - - .byte 0x07, 0x0a, 0x0a, 0x0a, 0x0c, 0x0c, 0x06, 0x0c - .byte 0x06, 0x10, 0x12, 0x0c, 0x0f, 0x0b, 0x01, 0x08 - - .4byte 0x0000000c @ ? - .4byte 0x00000f2c @ sizeof(struct SaveBlock2) - .4byte 0x00003d88 @ sizeof(struct SaveBlock1) - .4byte 0x00000234 @ offsetof(struct SaveBlock1, playerPartyCount) - .4byte 0x00000238 @ offsetof(struct SaveBlock1, playerParty) - .4byte 0x00000009 @ offsetof(struct SaveBlock2, specialSaveWarpFlags) - .4byte 0x0000000a @ offsetof(struct SaveBlock2, playerTrainerId) - .4byte 0x00000000 @ offsetof(struct SaveBlock2, playerName) - .4byte 0x00000008 @ offsetof(struct SaveBlock2, playerGender) - .4byte 0x00000ca8 @ offsetof(struct SaveBlock2, frontier.challengeStatus) - .4byte 0x00000ca8 @ offsetof(struct SaveBlock2, frontier.challengeStatus) - .4byte 0x000031c7 @ offsetof(struct SaveBlock1, externalEventFlags) - .4byte 0x000031b3 @ offsetof(struct SaveBlock1, externalEventData) - .4byte 0x00000000 - - .4byte gBaseStats - .4byte gAbilityNames - .4byte gAbilityDescriptionPointers - .4byte gItems - .4byte gBattleMoves - .4byte gBallSpriteSheets - .4byte gBallSpritePalettes - - .4byte 0x000000a8 @ offsetof(struct SaveBlock2, gcnLinkFlags) - .4byte 0x00000864 @ ? - .4byte 0x0000089b @ ? - - .byte 0x1e, 0x1e, 0x10, 0x40 - - .4byte 0x0000322e @ offsetof(struct SaveBlock1, ? part-way into mysteryGift) - .4byte 0x00000498 @ offsetof(struct SaveBlock1, pcItems) - .4byte 0x000031a8 @ offsetof(struct SaveBlock1, giftRibbons) - .4byte 0x000031f8 @ offsetof(struct SaveBlock1, enigmaBerry) - .4byte 0x00000034 @ offsetof(struct SaveBlock1, mapView) - .4byte 0x00000000 - .4byte 0x00000000 - .arm .align 2, 0 .global Init diff --git a/asm/rom_header.inc b/src/rom_header.s similarity index 73% rename from asm/rom_header.inc rename to src/rom_header.s index 6730efae2..596fd379f 100644 --- a/asm/rom_header.inc +++ b/src/rom_header.s @@ -1,3 +1,10 @@ +@ Note: ROM header data is empty space here. +@ It's populated by gbafix using data provided in the Makefile. + + .global Start +Start: @ 8000000 + b Init + .global RomHeaderNintendoLogo RomHeaderNintendoLogo: .space 156 diff --git a/src/rom_header_gf.s b/src/rom_header_gf.s new file mode 100644 index 000000000..b021158f5 --- /dev/null +++ b/src/rom_header_gf.s @@ -0,0 +1,89 @@ +#include "constants/global.h" + +@ 80000C0 + .word 0 + + .global GPIOPortData +GPIOPortData: @ 80000C4 + .2byte 0 + + .global GPIOPortDirection +GPIOPortDirection: @ 80000C6 + .2byte 0 + + .global GPIOPortReadEnable +GPIOPortReadEnable: @ 80000C8 + .2byte 0 + +@ 80000CA + .2byte 0 + +@ 80000CC + .space 0x34 + + .4byte GAME_VERSION + .4byte GAME_LANGUAGE + + .ascii "pokemon emerald version" + .space 9 + + .4byte gMonFrontPicTable + .4byte gMonBackPicTable + .4byte gMonPaletteTable + .4byte gMonShinyPaletteTable + .4byte gMonIconTable + .4byte gMonIconPaletteIndices + .4byte gMonIconPaletteTable + .4byte gSpeciesNames + .4byte gMoveNames + .4byte gDecorations + + .4byte 0x00001270 @ offsetof(struct SaveBlock1, flags) + .4byte 0x0000139c @ offsetof(struct SaveBlock1, vars) + .4byte 0x00000018 @ offsetof(struct SaveBlock2, pokedex) + .4byte 0x00000988 @ offsetof(struct SaveBlock1, seen1) + .4byte 0x00003b24 @ offsetof(struct SaveBlock1, seen2) + .4byte 0x00000046 @ ? + .4byte 0x000008e4 @ ? + .4byte 0x000008ac @ ? + .4byte 0x00000182 @ NATIONAL_DEX_COUNT? + + .byte 0x07, 0x0a, 0x0a, 0x0a, 0x0c, 0x0c, 0x06, 0x0c + .byte 0x06, 0x10, 0x12, 0x0c, 0x0f, 0x0b, 0x01, 0x08 + + .4byte 0x0000000c @ ? + .4byte 0x00000f2c @ sizeof(struct SaveBlock2) + .4byte 0x00003d88 @ sizeof(struct SaveBlock1) + .4byte 0x00000234 @ offsetof(struct SaveBlock1, playerPartyCount) + .4byte 0x00000238 @ offsetof(struct SaveBlock1, playerParty) + .4byte 0x00000009 @ offsetof(struct SaveBlock2, specialSaveWarpFlags) + .4byte 0x0000000a @ offsetof(struct SaveBlock2, playerTrainerId) + .4byte 0x00000000 @ offsetof(struct SaveBlock2, playerName) + .4byte 0x00000008 @ offsetof(struct SaveBlock2, playerGender) + .4byte 0x00000ca8 @ offsetof(struct SaveBlock2, frontier.challengeStatus) + .4byte 0x00000ca8 @ offsetof(struct SaveBlock2, frontier.challengeStatus) + .4byte 0x000031c7 @ offsetof(struct SaveBlock1, externalEventFlags) + .4byte 0x000031b3 @ offsetof(struct SaveBlock1, externalEventData) + .4byte 0x00000000 + + .4byte gBaseStats + .4byte gAbilityNames + .4byte gAbilityDescriptionPointers + .4byte gItems + .4byte gBattleMoves + .4byte gBallSpriteSheets + .4byte gBallSpritePalettes + + .4byte 0x000000a8 @ offsetof(struct SaveBlock2, gcnLinkFlags) + .4byte 0x00000864 @ ? + .4byte 0x0000089b @ ? + + .byte 0x1e, 0x1e, 0x10, 0x40 + + .4byte 0x0000322e @ offsetof(struct SaveBlock1, ? part-way into mysteryGift) + .4byte 0x00000498 @ offsetof(struct SaveBlock1, pcItems) + .4byte 0x000031a8 @ offsetof(struct SaveBlock1, giftRibbons) + .4byte 0x000031f8 @ offsetof(struct SaveBlock1, enigmaBerry) + .4byte 0x00000034 @ offsetof(struct SaveBlock1, mapView) + .4byte 0x00000000 + .4byte 0x00000000 From ef2971d8dcc0768265d9b8c0eec40ea55251db8b Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 1 Nov 2021 01:42:02 -0400 Subject: [PATCH 2/5] Convert GF ROM header to C --- include/item.h | 1 + include/pokeball.h | 2 + include/pokemon_icon.h | 2 + src/crt0.s | 1 + src/rom_header.s | 21 ++++++ src/rom_header_gf.c | 162 +++++++++++++++++++++++++++++++++++++++++ src/rom_header_gf.s | 89 ---------------------- 7 files changed, 189 insertions(+), 89 deletions(-) create mode 100644 src/rom_header_gf.c delete mode 100644 src/rom_header_gf.s diff --git a/include/item.h b/include/item.h index 87ff57bc7..ceca83bd5 100644 --- a/include/item.h +++ b/include/item.h @@ -29,6 +29,7 @@ struct BagPocket u8 capacity; }; +extern const struct Item gItems[]; extern struct BagPocket gBagPockets[]; void ApplyNewEncryptionKeyToBagItems(u32 newKey); diff --git a/include/pokeball.h b/include/pokeball.h index d88e80173..297788db1 100644 --- a/include/pokeball.h +++ b/include/pokeball.h @@ -26,6 +26,8 @@ enum { BALL_AFFINE_ANIM_4 }; +extern const struct CompressedSpriteSheet gBallSpriteSheets[]; +extern const struct CompressedSpritePalette gBallSpritePalettes[]; extern const struct SpriteTemplate gBallSpriteTemplates[]; #define POKEBALL_PLAYER_SENDOUT 0xFF diff --git a/include/pokemon_icon.h b/include/pokemon_icon.h index 4731da90e..9b917c3bf 100644 --- a/include/pokemon_icon.h +++ b/include/pokemon_icon.h @@ -2,6 +2,8 @@ #define GUARD_POKEMON_ICON_H extern const u8 gMonIconPaletteIndices[]; +extern const u8 *const gMonIconTable[]; +extern const struct SpritePalette gMonIconPaletteTable[]; const u8 *GetMonIconTiles(u16 species, bool32); void TryLoadAllMonIconPalettesAtOffset(u16 offset); diff --git a/src/crt0.s b/src/crt0.s index 6e3b86a72..7c679c13b 100644 --- a/src/crt0.s +++ b/src/crt0.s @@ -3,6 +3,7 @@ .syntax unified .arm + .align 2, 0 .global Init Init: @ 8000204 diff --git a/src/rom_header.s b/src/rom_header.s index 596fd379f..5ed45124d 100644 --- a/src/rom_header.s +++ b/src/rom_header.s @@ -40,3 +40,24 @@ RomHeaderChecksum: RomHeaderReserved2: .space 2 + +@ 80000C0 + .word 0 + + .global GPIOPortData +GPIOPortData: @ 80000C4 + .2byte 0 + + .global GPIOPortDirection +GPIOPortDirection: @ 80000C6 + .2byte 0 + + .global GPIOPortReadEnable +GPIOPortReadEnable: @ 80000C8 + .2byte 0 + +@ 80000CA + .2byte 0 + +@ 80000CC + .space 0x34 diff --git a/src/rom_header_gf.c b/src/rom_header_gf.c new file mode 100644 index 000000000..dc61fa1e3 --- /dev/null +++ b/src/rom_header_gf.c @@ -0,0 +1,162 @@ +#include "global.h" +#include "data.h" +#include "pokemon_icon.h" +#include "decoration.h" +#include "battle_main.h" +#include "item.h" +#include "pokeball.h" + +struct GFRomHeader +{ + u32 version; + u32 language; + u8 gameName[32]; + const struct CompressedSpriteSheet * monFrontPics; + const struct CompressedSpriteSheet * monBackPics; + const struct CompressedSpritePalette * monNormalPalettes; + const struct CompressedSpritePalette * monShinyPalettes; + const u8 * const * monIcons; + const u8 * monIconPaletteIds; + const struct SpritePalette * monIconPalettes; + const u8 (* monSpeciesNames)[]; + const u8 (* moveNames)[]; + const struct Decoration * decorations; + u32 flagsOffset; + u32 varsOffset; + u32 pokedexOffset; + u32 seen1Offset; + u32 seen2Offset; + u32 unk_01; + u32 unk_02; + u32 unk_03; + u32 dexCount; + u8 unk_04; + u8 unk_05; + u8 unk_06; + u8 unk_07; + u8 unk_08; + u8 unk_09; + u8 unk_0A; + u8 unk_0B; + u8 unk_0C; + u8 unk_0D; + u8 unk_0E; + u8 unk_0F; + u8 unk_10; + u8 unk_11; + u8 unk_12; + u8 unk_13; + u8 unk_14; + u32 saveBlock2Size; + u32 saveBlock1Size; + u32 partyCountOffset; + u32 partyOffset; + u32 warpFlagsOffset; + u32 trainerIdOffset; + u32 playerNameOffset; + u32 playerGenderOffset; + u32 frontierStatusOffset; + u32 frontierStatusOffset2; + u32 externalEventFlagsOffset; + u32 externalEventDataOffset; + u32 unk_15; + const struct BaseStats * baseStats; + const u8 (* abilityNames)[]; + const u8 * const * abilityDescriptions; + const struct Item * items; + const struct BattleMove * moves; + const struct CompressedSpriteSheet * ballGfx; + const struct CompressedSpritePalette * ballPalettes; + u32 gcnLinkFlagsOffset; + u32 unk_16; + u32 unk_17; + u8 unk_18; + u8 unk_19; + u8 unk_1A; + u8 unk_1B; + u32 unk_1C; + u32 pcItemsOffset; + u32 giftRibbonsOffset; + u32 enigmaBerryOffset; + u32 mapViewOffset; + u32 unk_1D; + u32 unk_1E; +}; + +__attribute__((section(".text"))) +static const struct GFRomHeader sGFRomHeader = { + .version = GAME_VERSION, + .language = GAME_LANGUAGE, + .gameName = "pokemon emerald version", + .monFrontPics = gMonFrontPicTable, + .monBackPics = gMonBackPicTable, + .monNormalPalettes = gMonPaletteTable, + .monShinyPalettes = gMonShinyPaletteTable, + .monIcons = gMonIconTable, + .monIconPaletteIds = gMonIconPaletteIndices, + .monIconPalettes = gMonIconPaletteTable, + .monSpeciesNames = gSpeciesNames, + .moveNames = gMoveNames, + .decorations = gDecorations, + .flagsOffset = offsetof(struct SaveBlock1, flags), + .varsOffset = offsetof(struct SaveBlock1, vars), + .pokedexOffset = offsetof(struct SaveBlock2, pokedex), + .seen1Offset = offsetof(struct SaveBlock1, seen1), + .seen2Offset = offsetof(struct SaveBlock1, seen2), + .unk_01 = 0x00000046, + .unk_02 = 0x000008e4, + .unk_03 = 0x000008ac, + .dexCount = NATIONAL_DEX_COUNT, + .unk_04 = 0x07, + .unk_05 = 0x0a, + .unk_06 = 0x0a, + .unk_07 = 0x0a, + .unk_08 = 0x0c, + .unk_09 = 0x0c, + .unk_0A = 0x06, + .unk_0B = 0x0c, + .unk_0C = 0x06, + .unk_0D = 0x10, + .unk_0E = 0x12, + .unk_0F = 0x0c, + .unk_10 = 0x0f, + .unk_11 = 0x0b, + .unk_12 = 0x01, + .unk_13 = 0x08, + .unk_14 = 0x0c, + .saveBlock2Size = sizeof(struct SaveBlock2), + .saveBlock1Size = sizeof(struct SaveBlock1), + .partyCountOffset = offsetof(struct SaveBlock1, playerPartyCount), + .partyOffset = offsetof(struct SaveBlock1, playerParty), + .warpFlagsOffset = offsetof(struct SaveBlock2, specialSaveWarpFlags), + .trainerIdOffset = offsetof(struct SaveBlock2, playerTrainerId), + .playerNameOffset = offsetof(struct SaveBlock2, playerName), + .playerGenderOffset = offsetof(struct SaveBlock2, playerGender), + .frontierStatusOffset = offsetof(struct SaveBlock2, frontier.challengeStatus), + .frontierStatusOffset2 = offsetof(struct SaveBlock2, frontier.challengeStatus), + .externalEventFlagsOffset = offsetof(struct SaveBlock1, externalEventFlags), + .externalEventDataOffset = offsetof(struct SaveBlock1, externalEventData), + .unk_15 = 0x00000000, + .baseStats = gBaseStats, + .abilityNames = gAbilityNames, + .abilityDescriptions = gAbilityDescriptionPointers, + .items = gItems, + .moves = gBattleMoves, + .ballGfx = gBallSpriteSheets, + .ballPalettes = gBallSpritePalettes, + .gcnLinkFlagsOffset = offsetof(struct SaveBlock2, gcnLinkFlags), + .unk_16 = 0x00000864, + .unk_17 = 0x0000089b, + .unk_18 = 0x1e, + .unk_19 = 0x1e, + .unk_1A = 0x10, + .unk_1B = 0x40, + .unk_1C = 0x0000322e, // offsetof(struct SaveBlock1, ? part-way into mysteryGift) + .pcItemsOffset = offsetof(struct SaveBlock1, pcItems), + .giftRibbonsOffset = offsetof(struct SaveBlock1, giftRibbons), + .enigmaBerryOffset = offsetof(struct SaveBlock1, enigmaBerry), + .mapViewOffset = offsetof(struct SaveBlock1, mapView), + .unk_1D = 0x00000000, + .unk_1E = 0x00000000, +}; + diff --git a/src/rom_header_gf.s b/src/rom_header_gf.s deleted file mode 100644 index b021158f5..000000000 --- a/src/rom_header_gf.s +++ /dev/null @@ -1,89 +0,0 @@ -#include "constants/global.h" - -@ 80000C0 - .word 0 - - .global GPIOPortData -GPIOPortData: @ 80000C4 - .2byte 0 - - .global GPIOPortDirection -GPIOPortDirection: @ 80000C6 - .2byte 0 - - .global GPIOPortReadEnable -GPIOPortReadEnable: @ 80000C8 - .2byte 0 - -@ 80000CA - .2byte 0 - -@ 80000CC - .space 0x34 - - .4byte GAME_VERSION - .4byte GAME_LANGUAGE - - .ascii "pokemon emerald version" - .space 9 - - .4byte gMonFrontPicTable - .4byte gMonBackPicTable - .4byte gMonPaletteTable - .4byte gMonShinyPaletteTable - .4byte gMonIconTable - .4byte gMonIconPaletteIndices - .4byte gMonIconPaletteTable - .4byte gSpeciesNames - .4byte gMoveNames - .4byte gDecorations - - .4byte 0x00001270 @ offsetof(struct SaveBlock1, flags) - .4byte 0x0000139c @ offsetof(struct SaveBlock1, vars) - .4byte 0x00000018 @ offsetof(struct SaveBlock2, pokedex) - .4byte 0x00000988 @ offsetof(struct SaveBlock1, seen1) - .4byte 0x00003b24 @ offsetof(struct SaveBlock1, seen2) - .4byte 0x00000046 @ ? - .4byte 0x000008e4 @ ? - .4byte 0x000008ac @ ? - .4byte 0x00000182 @ NATIONAL_DEX_COUNT? - - .byte 0x07, 0x0a, 0x0a, 0x0a, 0x0c, 0x0c, 0x06, 0x0c - .byte 0x06, 0x10, 0x12, 0x0c, 0x0f, 0x0b, 0x01, 0x08 - - .4byte 0x0000000c @ ? - .4byte 0x00000f2c @ sizeof(struct SaveBlock2) - .4byte 0x00003d88 @ sizeof(struct SaveBlock1) - .4byte 0x00000234 @ offsetof(struct SaveBlock1, playerPartyCount) - .4byte 0x00000238 @ offsetof(struct SaveBlock1, playerParty) - .4byte 0x00000009 @ offsetof(struct SaveBlock2, specialSaveWarpFlags) - .4byte 0x0000000a @ offsetof(struct SaveBlock2, playerTrainerId) - .4byte 0x00000000 @ offsetof(struct SaveBlock2, playerName) - .4byte 0x00000008 @ offsetof(struct SaveBlock2, playerGender) - .4byte 0x00000ca8 @ offsetof(struct SaveBlock2, frontier.challengeStatus) - .4byte 0x00000ca8 @ offsetof(struct SaveBlock2, frontier.challengeStatus) - .4byte 0x000031c7 @ offsetof(struct SaveBlock1, externalEventFlags) - .4byte 0x000031b3 @ offsetof(struct SaveBlock1, externalEventData) - .4byte 0x00000000 - - .4byte gBaseStats - .4byte gAbilityNames - .4byte gAbilityDescriptionPointers - .4byte gItems - .4byte gBattleMoves - .4byte gBallSpriteSheets - .4byte gBallSpritePalettes - - .4byte 0x000000a8 @ offsetof(struct SaveBlock2, gcnLinkFlags) - .4byte 0x00000864 @ ? - .4byte 0x0000089b @ ? - - .byte 0x1e, 0x1e, 0x10, 0x40 - - .4byte 0x0000322e @ offsetof(struct SaveBlock1, ? part-way into mysteryGift) - .4byte 0x00000498 @ offsetof(struct SaveBlock1, pcItems) - .4byte 0x000031a8 @ offsetof(struct SaveBlock1, giftRibbons) - .4byte 0x000031f8 @ offsetof(struct SaveBlock1, enigmaBerry) - .4byte 0x00000034 @ offsetof(struct SaveBlock1, mapView) - .4byte 0x00000000 - .4byte 0x00000000 From e0e2212db300566d17468fc237a2708455ed3034 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 1 Nov 2021 01:47:38 -0400 Subject: [PATCH 3/5] Avoid changed section warning --- ld_script.txt | 2 +- src/rom_header_gf.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ld_script.txt b/ld_script.txt index 10abd8810..9c81f1da9 100644 --- a/ld_script.txt +++ b/ld_script.txt @@ -48,7 +48,7 @@ SECTIONS { ALIGN(4) { src/rom_header.o(.text); - src/rom_header_gf.o(.text); + src/rom_header_gf.o(.text.*); src/crt0.o(.text); src/main.o(.text); gflib/malloc.o(.text); diff --git a/src/rom_header_gf.c b/src/rom_header_gf.c index dc61fa1e3..5e78e3a93 100644 --- a/src/rom_header_gf.c +++ b/src/rom_header_gf.c @@ -83,7 +83,9 @@ struct GFRomHeader u32 unk_1E; }; -__attribute__((section(".text"))) +// This seems to need to be in the text section for some reason. +// To avoid a changed section warning it's put in a special .text.consts section instead of .text. +__attribute__((section(".text.consts"))) static const struct GFRomHeader sGFRomHeader = { .version = GAME_VERSION, .language = GAME_LANGUAGE, From 9b2038a9a55f49969a2c7f650865ed47bea9b99d Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 1 Nov 2021 02:34:38 -0400 Subject: [PATCH 4/5] Additional GF ROM header doc --- src/rom_header_gf.c | 129 ++++++++++++++++++++++---------------------- 1 file changed, 65 insertions(+), 64 deletions(-) diff --git a/src/rom_header_gf.c b/src/rom_header_gf.c index 5e78e3a93..782a05c75 100644 --- a/src/rom_header_gf.c +++ b/src/rom_header_gf.c @@ -26,27 +26,27 @@ struct GFRomHeader u32 pokedexOffset; u32 seen1Offset; u32 seen2Offset; - u32 unk_01; - u32 unk_02; - u32 unk_03; - u32 dexCount; - u8 unk_04; - u8 unk_05; - u8 unk_06; - u8 unk_07; - u8 unk_08; - u8 unk_09; - u8 unk_0A; - u8 unk_0B; - u8 unk_0C; - u8 unk_0D; - u8 unk_0E; - u8 unk_0F; - u8 unk_10; - u8 unk_11; - u8 unk_12; - u8 unk_13; - u8 unk_14; + u32 pokedexVar; + u32 pokedexFlag; + u32 mysteryEventFlag; + u32 pokedexCount; + u8 unk1; + u8 unk2; + u8 unk3; + u8 unk4; + u8 unk5; + u8 unk6; + u8 unk7; + u8 unk8; + u8 unk9; + u8 unk10; + u8 unk11; + u8 unk12; + u8 unk13; + u8 unk14; + u8 unk15; + u8 unk16; + u8 unk17; u32 saveBlock2Size; u32 saveBlock1Size; u32 partyCountOffset; @@ -59,7 +59,7 @@ struct GFRomHeader u32 frontierStatusOffset2; u32 externalEventFlagsOffset; u32 externalEventDataOffset; - u32 unk_15; + u32 unk18; const struct BaseStats * baseStats; const u8 (* abilityNames)[]; const u8 * const * abilityDescriptions; @@ -68,23 +68,24 @@ struct GFRomHeader const struct CompressedSpriteSheet * ballGfx; const struct CompressedSpritePalette * ballPalettes; u32 gcnLinkFlagsOffset; - u32 unk_16; - u32 unk_17; - u8 unk_18; - u8 unk_19; - u8 unk_1A; - u8 unk_1B; - u32 unk_1C; + u32 gameClearFlag; + u32 ribbonFlag; + u8 bagCountItems; + u8 bagCountKeyItems; + u8 bagCountPokeballs; + u8 bagCountTMHMs; + u8 bagCountBerries; + u8 pcItemsCount; u32 pcItemsOffset; u32 giftRibbonsOffset; u32 enigmaBerryOffset; u32 mapViewOffset; - u32 unk_1D; - u32 unk_1E; + u32 unk19; + u32 unk20; }; // This seems to need to be in the text section for some reason. -// To avoid a changed section warning it's put in a special .text.consts section instead of .text. +// To avoid a changed section attributes warning it's put in a special .text.consts section. __attribute__((section(".text.consts"))) static const struct GFRomHeader sGFRomHeader = { .version = GAME_VERSION, @@ -105,27 +106,27 @@ static const struct GFRomHeader sGFRomHeader = { .pokedexOffset = offsetof(struct SaveBlock2, pokedex), .seen1Offset = offsetof(struct SaveBlock1, seen1), .seen2Offset = offsetof(struct SaveBlock1, seen2), - .unk_01 = 0x00000046, - .unk_02 = 0x000008e4, - .unk_03 = 0x000008ac, - .dexCount = NATIONAL_DEX_COUNT, - .unk_04 = 0x07, - .unk_05 = 0x0a, - .unk_06 = 0x0a, - .unk_07 = 0x0a, - .unk_08 = 0x0c, - .unk_09 = 0x0c, - .unk_0A = 0x06, - .unk_0B = 0x0c, - .unk_0C = 0x06, - .unk_0D = 0x10, - .unk_0E = 0x12, - .unk_0F = 0x0c, - .unk_10 = 0x0f, - .unk_11 = 0x0b, - .unk_12 = 0x01, - .unk_13 = 0x08, - .unk_14 = 0x0c, + .pokedexVar = VAR_NATIONAL_DEX - VARS_START, + .pokedexFlag = FLAG_RECEIVED_POKEDEX_FROM_BIRCH, + .mysteryEventFlag = FLAG_SYS_MYSTERY_EVENT_ENABLE, + .pokedexCount = NATIONAL_DEX_COUNT, + .unk1 = 0x07, + .unk2 = 0x0a, + .unk3 = 0x0a, + .unk4 = 0x0a, + .unk5 = 0x0c, + .unk6 = 0x0c, + .unk7 = 0x06, + .unk8 = 0x0c, + .unk9 = 0x06, + .unk10 = 0x10, + .unk11 = 0x12, + .unk12 = 0x0c, + .unk13 = 0x0f, + .unk14 = 0x0b, + .unk15 = 0x01, + .unk16 = 0x08, + .unk17 = 0x0c, .saveBlock2Size = sizeof(struct SaveBlock2), .saveBlock1Size = sizeof(struct SaveBlock1), .partyCountOffset = offsetof(struct SaveBlock1, playerPartyCount), @@ -138,7 +139,7 @@ static const struct GFRomHeader sGFRomHeader = { .frontierStatusOffset2 = offsetof(struct SaveBlock2, frontier.challengeStatus), .externalEventFlagsOffset = offsetof(struct SaveBlock1, externalEventFlags), .externalEventDataOffset = offsetof(struct SaveBlock1, externalEventData), - .unk_15 = 0x00000000, + .unk18 = 0x00000000, .baseStats = gBaseStats, .abilityNames = gAbilityNames, .abilityDescriptions = gAbilityDescriptionPointers, @@ -147,18 +148,18 @@ static const struct GFRomHeader sGFRomHeader = { .ballGfx = gBallSpriteSheets, .ballPalettes = gBallSpritePalettes, .gcnLinkFlagsOffset = offsetof(struct SaveBlock2, gcnLinkFlags), - .unk_16 = 0x00000864, - .unk_17 = 0x0000089b, - .unk_18 = 0x1e, - .unk_19 = 0x1e, - .unk_1A = 0x10, - .unk_1B = 0x40, - .unk_1C = 0x0000322e, // offsetof(struct SaveBlock1, ? part-way into mysteryGift) + .gameClearFlag = FLAG_SYS_GAME_CLEAR, + .ribbonFlag = FLAG_SYS_RIBBON_GET, + .bagCountItems = BAG_ITEMS_COUNT, + .bagCountKeyItems = BAG_KEYITEMS_COUNT, + .bagCountPokeballs = BAG_POKEBALLS_COUNT, + .bagCountTMHMs = BAG_TMHM_COUNT, + .bagCountBerries = BAG_BERRIES_COUNT, + .pcItemsCount = PC_ITEMS_COUNT, .pcItemsOffset = offsetof(struct SaveBlock1, pcItems), .giftRibbonsOffset = offsetof(struct SaveBlock1, giftRibbons), .enigmaBerryOffset = offsetof(struct SaveBlock1, enigmaBerry), .mapViewOffset = offsetof(struct SaveBlock1, mapView), - .unk_1D = 0x00000000, - .unk_1E = 0x00000000, + .unk19 = 0x00000000, + .unk20 = 0x00000000, // 0xFFFFFFFF in FRLG }; - From e65677c944b786c8f94adc8c962b7ee180bfe548 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Thu, 4 Nov 2021 17:28:41 -0400 Subject: [PATCH 5/5] Update modern linker script --- include/crt0.h | 5 ----- ld_script_modern.txt | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/crt0.h b/include/crt0.h index 3121eeaed..a4a5c7f79 100644 --- a/include/crt0.h +++ b/include/crt0.h @@ -1,11 +1,6 @@ #ifndef GUARD_CRT0_H #define GUARD_CRT0_H -// Exported type declarations - -// Exported RAM declarations - -// Exported ROM declarations extern u32 IntrMain[]; #endif //GUARD_CRT0_H diff --git a/ld_script_modern.txt b/ld_script_modern.txt index c5c711bfd..ac62abe27 100644 --- a/ld_script_modern.txt +++ b/ld_script_modern.txt @@ -47,7 +47,7 @@ SECTIONS { .text : ALIGN(4) { - src/crt0.o(.text*); + src/rom_header.o(.text*); src/*.o(.text*); gflib/*.o(.text*); asm/*.o(.text*);