diff --git a/asm/rom_header.inc b/asm/rom_header.inc deleted file mode 100644 index 6730efae2..000000000 --- a/asm/rom_header.inc +++ /dev/null @@ -1,35 +0,0 @@ - .global RomHeaderNintendoLogo -RomHeaderNintendoLogo: - .space 156 - -RomHeaderGameTitle: - .space 12 - - .global RomHeaderGameCode -RomHeaderGameCode: - .space 4 - -RomHeaderMakerCode: - .space 2 - -RomHeaderMagic: - .byte 0 - -RomHeaderMainUnitCode: - .byte 0 - -RomHeaderDeviceType: - .byte 0 - -RomHeaderReserved1: - .space 7 - - .global RomHeaderSoftwareVersion -RomHeaderSoftwareVersion: - .byte 0 - -RomHeaderChecksum: - .byte 0 - -RomHeaderReserved2: - .space 2 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/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/ld_script.txt b/ld_script.txt index e310bf717..cecb8f23c 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/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*); diff --git a/src/crt0.s b/src/crt0.s index 672fc94f2..7c679c13b 100644 --- a/src/crt0.s +++ b/src/crt0.s @@ -1,108 +1,9 @@ -#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 Init: @ 8000204 diff --git a/src/rom_header.s b/src/rom_header.s new file mode 100644 index 000000000..5ed45124d --- /dev/null +++ b/src/rom_header.s @@ -0,0 +1,63 @@ +@ 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 + +RomHeaderGameTitle: + .space 12 + + .global RomHeaderGameCode +RomHeaderGameCode: + .space 4 + +RomHeaderMakerCode: + .space 2 + +RomHeaderMagic: + .byte 0 + +RomHeaderMainUnitCode: + .byte 0 + +RomHeaderDeviceType: + .byte 0 + +RomHeaderReserved1: + .space 7 + + .global RomHeaderSoftwareVersion +RomHeaderSoftwareVersion: + .byte 0 + +RomHeaderChecksum: + .byte 0 + +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..782a05c75 --- /dev/null +++ b/src/rom_header_gf.c @@ -0,0 +1,165 @@ +#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 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; + u32 partyOffset; + u32 warpFlagsOffset; + u32 trainerIdOffset; + u32 playerNameOffset; + u32 playerGenderOffset; + u32 frontierStatusOffset; + u32 frontierStatusOffset2; + u32 externalEventFlagsOffset; + u32 externalEventDataOffset; + u32 unk18; + 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 gameClearFlag; + u32 ribbonFlag; + u8 bagCountItems; + u8 bagCountKeyItems; + u8 bagCountPokeballs; + u8 bagCountTMHMs; + u8 bagCountBerries; + u8 pcItemsCount; + u32 pcItemsOffset; + u32 giftRibbonsOffset; + u32 enigmaBerryOffset; + u32 mapViewOffset; + u32 unk19; + u32 unk20; +}; + +// This seems to need to be in the text section for some reason. +// 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, + .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), + .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), + .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), + .unk18 = 0x00000000, + .baseStats = gBaseStats, + .abilityNames = gAbilityNames, + .abilityDescriptions = gAbilityDescriptionPointers, + .items = gItems, + .moves = gBattleMoves, + .ballGfx = gBallSpriteSheets, + .ballPalettes = gBallSpritePalettes, + .gcnLinkFlagsOffset = offsetof(struct SaveBlock2, gcnLinkFlags), + .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), + .unk19 = 0x00000000, + .unk20 = 0x00000000, // 0xFFFFFFFF in FRLG +};