Separate crt0, rom_header, and rom_header_gf

This commit is contained in:
GriffinR
2022-06-21 20:10:07 -04:00
parent 0ef7307040
commit 2eb1c9664e
9 changed files with 253 additions and 150 deletions
-35
View File
@@ -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
+2
View File
@@ -52,4 +52,6 @@ struct Decoration
const u16 *tiles;
};
extern const struct Decoration gDecorations[];
#endif //GUARD_DECORATION_H
+1
View File
@@ -29,6 +29,7 @@ struct BagPocket
u8 capacity;
};
extern const struct Item gItems[];
extern struct BagPocket gBagPockets[];
void GetBerryCountString(u8* dst, const u8* berryName, u32 quantity);
+2
View File
@@ -20,6 +20,8 @@ enum
POKEBALL_COUNT
};
extern const struct CompressedSpriteSheet gBallSpriteSheets[POKEBALL_COUNT];
extern const struct CompressedSpritePalette gBallSpritePalettes[POKEBALL_COUNT];
extern const struct SpriteTemplate gBallSpriteTemplates[];
#define POKEBALL_PLAYER_SENDOUT 0xFF
+2
View File
@@ -3,6 +3,8 @@
#include "global.h"
extern const u8 *const gMonIconTable[];
extern const struct SpritePalette gMonIconPaletteTable[];
extern const u16 gMonIconPalettes[][16];
extern const u8 gMonIconPaletteIndices[];
+3 -1
View File
@@ -44,7 +44,9 @@ SECTIONS {
.text :
ALIGN(4)
{
src/crt0.o(.text);
src/rom_header.o(.text);
src/rom_header_gf.o(.text*);
src/crt0.o(.text);
src/main.o(.text);
src/gpu_regs.o(.text);
src/dma3_manager.o(.text);
-114
View File
@@ -4,120 +4,6 @@
.syntax unified
.global Start
.text
.arm
_start: @ 8000000
b start_vector
.include "asm/rom_header.inc"
@ 80000C0
.word 0
.global GPIOPortData
GPIOPortData: @ 80000C4
.hword 0
.global GPIOPortDirection
GPIOPortDirection: @ 80000C6
.hword 0
.global GPIOPortReadEnable
GPIOPortReadEnable: @ 80000C8
.hword 0
.space 6
@ 80000D0
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
@ 8000100
.global CartIdent
CartIdent:
.4byte GAME_VERSION
.4byte GAME_LANGUAGE
.game_name:
.ifdef FIRERED
.ascii "pokemon red version"
.else
.ifdef LEAFGREEN
.ascii "pokemon green version"
.endif
.endif
.space .game_name+0x20-.
.4byte gMonFrontPicTable
.4byte gMonBackPicTable
.4byte gMonPaletteTable
.4byte gMonShinyPaletteTable
.4byte gMonIconTable
.4byte gMonIconPaletteIndices
.4byte gMonIconPaletteTable
.4byte gSpeciesNames
.4byte gMoveNames
.4byte gDecorations
.4byte 0xEE0 @ offsetof(struct SaveBlock1, flags)
.4byte 0x1000 @ offsetof(struct SaveBlock1, vars)
.4byte 0x18 @ offsetof(struct SaveBlock2, pokedex)
.4byte 0x5F8 @ offsetof(struct SaveBlock1, seen1)
.4byte 0x3A18 @ offsetof(struct SaveBlock1, seen2)
.4byte 0x3C
.4byte 0x838
.4byte 0x839
.4byte 0x182
.byte 7, 10, 10, 10, 12, 12, 6, 12
.byte 6, 16, 18, 12, 15, 11, 1, 8
.byte 12
.align 2, 0
.4byte 0xF24 @ sizeof(struct SaveBlock2) /* 88 */
.4byte 0x3D68 @ sizeof(struct SaveBlock1)
.4byte 0x34 @ offsetof(struct SaveBlock1, playerPartyCount)
.4byte 0x38 @ offsetof(struct SaveBlock1, playerParty)
.4byte 9 @ offsetof(struct SaveBlock2, specialSaveWarp)
.4byte 0xA @ offsetof(struct SaveBlock2, playerTrainerId)
.4byte 0 @ offsetof(struct SaveBlock2, playerName)
.4byte 8 @ offsetof(struct SaveBlock2, playerGender)
.4byte 0xAD @ offsetof(struct SaveBlock2, ?????? (0xAD))
.4byte 0xAD @ offsetof(struct SaveBlock2, ?????? (0xAD))
.4byte 0x30BB @ offsetof(struct SaveBlock1, externalEventFlags)
.4byte 0x30A7 @ offsetof(struct SaveBlock1, externalEventData)
.byte 0
.align 2, 0
.4byte gBaseStats
.4byte gAbilityNames
.4byte gAbilityDescriptionPointers
.4byte gItems
.4byte gBattleMoves
.4byte gBallSpriteSheets
.4byte gBallSpritePalettes
.4byte 0xA8 @ offsetof(struct SaveBlock2,gcnLinkFlags)
.4byte 0x82C @ FLAG_SYS_GAME_CLEAR
.4byte 0x83B @ FLAG_SYS_RIBBON_GET
.4byte 0x3A0D1E2A
.4byte 0x1E2B
.4byte 0x298 @ offsetof(struct SaveBlock1, pcItems) // maybe all items were in a struct together?
.4byte 0x309C @ offsetof(struct SaveBlock1, giftRibbons)
.4byte 0x30EC @ offsetof(struct SaveBlock1, enigmaBerry)
.4byte 0x34 @ size of SaveBlock1 map header reconstruction data?
.4byte 0
.4byte 0xFFFFFFFF
.arm
.align 2, 0
.global start_vector
+72
View File
@@ -0,0 +1,72 @@
@ Note: ROM header data is empty space here.
@ It's populated by gbafix using data provided in the Makefile.
.global Start
Start: @ 8000000
b start_vector
.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
.hword 0
.global GPIOPortDirection
GPIOPortDirection: @ 80000C6
.hword 0
.global GPIOPortReadEnable
GPIOPortReadEnable: @ 80000C8
.hword 0
.space 6
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
.4byte 0xFFFFFFFF
+171
View File
@@ -0,0 +1,171 @@
#include "global.h"
#include "data.h"
#include "pokemon_icon.h"
#include "decoration.h"
#include "battle_main.h"
#include "item.h"
#include "pokeball.h"
#include "pokedex.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 mysteryGiftFlag;
u32 pokedexCount;
u8 playerNameLength;
u8 unk2;
u8 pokemonNameLength1;
u8 pokemonNameLength2;
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 unkFlagOffset;
u32 unkFlagOffset2;
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 enigmaBerrySize;
const u8 * moveDescriptions;
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,
#ifdef FIRERED
.gameName = "pokemon red version",
#else
.gameName = "pokemon green version",
#endif
.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_0x403C - VARS_START,
.pokedexFlag = FLAG_0x838,
.mysteryGiftFlag = FLAG_SYS_MYSTERY_GIFT_ENABLED,
.pokedexCount = NATIONAL_DEX_COUNT,
.playerNameLength = PLAYER_NAME_LENGTH,
.unk2 = 10,
.pokemonNameLength1 = POKEMON_NAME_LENGTH,
.pokemonNameLength2 = POKEMON_NAME_LENGTH,
// Two of the below 12s are likely move/ability name length, given their presence in this header
.unk5 = 12,
.unk6 = 12,
.unk7 = 6,
.unk8 = 12,
.unk9 = 6,
.unk10 = 16,
.unk11 = 18,
.unk12 = 12,
.unk13 = 15,
.unk14 = 11,
.unk15 = 1,
.unk16 = 8,
.unk17 = 12,
.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),
.unkFlagOffset = offsetof(struct SaveBlock2, unkFlag2),
.unkFlagOffset2 = offsetof(struct SaveBlock2, unkFlag2),
.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),
.enigmaBerrySize = sizeof(struct EnigmaBerry),
.moveDescriptions = NULL,
.unk20 = 0xFFFFFFFF, // 0x00000000 in Emerald
};