finish egg hatch, clean up headers

This commit is contained in:
DizzyEggg 2017-09-19 14:27:46 +02:00
parent f255cbd7dc
commit 148b995189
17 changed files with 3370 additions and 3212 deletions

View File

@ -2175,7 +2175,7 @@ _08070B34:
lsrs r0, 24
cmp r0, 0xFF
bne _08070BC0
bl sub_807228C
bl GetEggStepsToSubtract
lsls r0, 24
lsrs r6, r0, 24
movs r5, 0

View File

@ -1,74 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start sub_807228C
sub_807228C: @ 807228C
push {r4-r6,lr}
bl CalculatePlayerPartyCount
lsls r0, 24
lsrs r6, r0, 24
movs r5, 0
cmp r5, r6
bcs _080722D6
_0807229C:
movs r0, 0x64
adds r1, r5, 0
muls r1, r0
ldr r0, =gPlayerParty
adds r4, r1, r0
adds r0, r4, 0
movs r1, 0x6
bl GetMonData
cmp r0, 0
bne _080722CC
adds r0, r4, 0
bl GetMonAbility
lsls r0, 24
lsrs r0, 24
cmp r0, 0x28
beq _080722C4
cmp r0, 0x31
bne _080722CC
_080722C4:
movs r0, 0x2
b _080722D8
.pool
_080722CC:
adds r0, r5, 0x1
lsls r0, 24
lsrs r5, r0, 24
cmp r5, r6
bcc _0807229C
_080722D6:
movs r0, 0x1
_080722D8:
pop {r4-r6}
pop {r1}
bx r1
thumb_func_end sub_807228C
thumb_func_start sub_80722E0
sub_80722E0: @ 80722E0
push {r4,lr}
bl sub_80D22D0
adds r4, r0, 0
lsls r4, 16
lsrs r4, 16
movs r0, 0x6
bl sub_80C7050
lsls r0, 24
lsrs r0, 24
adds r4, r0
lsls r4, 16
lsrs r4, 16
adds r0, r4, 0
pop {r4}
pop {r1}
bx r1
thumb_func_end sub_80722E0
.align 2, 0 @ Don't pad with nop.

BIN
data/data3 Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

2848
data/data3_a0.s Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,17 +15,35 @@ enum
struct BgTemplate
{
u32 bg:2;
u32 charBaseIndex:2;
u32 mapBaseIndex:5;
u32 screenSize:2;
u32 paletteMode:1;
u32 priority:2;
u32 bg:2; // 0x1, 0x2 -> 0x3
u32 charBaseIndex:2; // 0x4, 0x8 -> 0xC
u32 mapBaseIndex:5; // 0x10, 0x20, 0x40, 0x80, 0x100 -> 0x1F0
u32 screenSize:2; // 0x200, 0x400 -> 0x600
u32 paletteMode:1; // 0x800
u32 priority:2; // 0x1000, 0x2000 > 0x3000
u32 baseTile:10;
};
void ResetBgs(void);
u8 GetBgMode(void);
void ResetBgControlStructs(void);
void Unused_ResetBgControlStruct(u8 bg);
void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenSize, u8 paletteMode, u8 priority, u8 mosaic, u8 wraparound);
u16 GetBgControlAttribute(u8 bg, u8 attributeId);
u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode);
void SetTextModeAndHideBgs(void);
bool8 IsInvalidBg(u8 bg);
int DummiedOutFireRedLeafGreenTileAllocFunc(int a1, int a2, int a3, int a4);
void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable);
void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numTemplates);
void InitBgFromTemplate(const struct BgTemplate *template);
void SetBgMode(u8 bgMode);
u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset);
u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset);
u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset);
bool8 IsDma3ManagerBusyWithBgCopy(void);
void ShowBg(u8 bg);
void HideBg(u8 bg);
void SetBgAttribute(u8 bg, u8 attributeId, u8 value);
u16 GetBgAttribute(u8 bg, u8 attributeId);
u32 ChangeBgX(u8 bg, u32 value, u8 op);
@ -34,12 +52,24 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op);
u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op);
u32 GetBgY(u8 bg);
void SetBgAffine(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle);
u8 Unused_AdjustBgMosaic(u8 a1, u8 a2);
void SetBgTilemapBuffer(u8 bg, void *tilemap);
void UnsetBgTilemapBuffer(u8 bg);
void* GetBgTilemapBuffer(u8 bg);
void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset);
void CopyBgTilemapBufferToVram(u8 bg);
u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset);
void ShowBg(u8 bg);
void HideBg(u8 bg);
void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u8 height);
void CopyToBgTilemapBufferRect_ChangePalette(u8 bg, void *src, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette);
void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWidth, u8 srcHeight, u8 destX, u8 destY, u8 rectWidth, u8 rectHeight, u8 palette1, u16 tileOffset, u16 palette2);
void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height);
void FillBgTilemapBufferRect(u8 bg, u16 tileNum, u8 x, u8 y, u8 width, u8 height, u8 palette);
void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 width, u8 height, u8 paletteSlot, s16 tileNumDelta);
u16 GetBgMetricTextMode(u8 bg, u8 whichMetric);
u32 GetBgMetricAffineMode(u8 bg, u8 whichMetric);
u32 GetTileMapIndexFromCoords(s32 x, s32 y, s32 screenSize, u32 screenWidth, u32 screenHeight);
void CopyTileMapEntry(u16 *src, u16 *dest, s32 palette1, u32 tileOffset, u32 palette2);
u32 GetBgType(u8 bg);
bool32 IsInvalidBg32(u8 bg);
bool32 IsTileMapOutsideWram(u8 bg);
#endif // GUARD_BG_H

View File

@ -19,5 +19,6 @@ void ClearDma3Requests(void);
void ProcessDma3Requests(void);
int RequestDma3Copy(const void *src, void *dest, u16 size, u8 mode);
int RequestDma3Fill(s32 value, void *dest, u16 size, u8 mode);
int CheckForSpaceForDma3Request(s16 index);
#endif
#endif // GUARD_DMA3_H

View File

@ -1,6 +1,8 @@
#ifndef GUARD_GPU_REGS_H
#define GUARD_GPU_REGS_H
void InitGpuRegManager(void);
void CopyBufferedValuesToGpuRegs(void);
void SetGpuReg(u8 regOffset, u16 value);
void SetGpuReg_ForcedBlank(u8 regOffset, u16 value);
u16 GetGpuReg(u8 regOffset);

View File

@ -1,6 +1,9 @@
#ifndef GUARD_TRIG_H
#define GUARD_TRIG_H
// Converts a number to Q8.8 fixed-point format
#define Q_8_8(n) ((s16)((n) * 256))
extern const s16 gSineTable[];
s16 Sin(s16 index, s16 amplitude);

View File

@ -24,6 +24,17 @@ struct WindowTemplate
u16 baseBlock;
};
#define DUMMY_WIN_TEMPLATE \
{ \
0xFF, \
0, \
0, \
0, \
0, \
0, \
0, \
}
struct Window
{
struct WindowTemplate window;

View File

@ -81,7 +81,6 @@ SECTIONS {
src/blend_palette.o(.text);
asm/daycare.o(.text);
src/egg_hatch.o(.text);
asm/egg_hatch.o(.text);
asm/battle_interface.o(.text);
asm/smokescreen.o(.text);
asm/pokeball.o(.text);
@ -341,6 +340,8 @@ SECTIONS {
src/trig.o(.rodata);
src/util.o(.rodata);
data/data3.o(.rodata);
src/egg_hatch.o(.rodata);
data/data3_a0.o(.rodata);
src/berry.o(.rodata);
data/data3_a1.o(.rodata);
src/pokemon_size_record.o(.rodata)

297
src/bg.c
View File

@ -1,10 +1,12 @@
#include "global.h"
#include "bg.h"
#include "dma3.h"
#include "gpu_regs.h"
#define DISPCNT_ALL_BG_AND_MODE_BITS 0x0F07
#define DISPCNT_ALL_BG_AND_MODE_BITS (DISPCNT_BG_ALL_ON | 0x7)
struct BgControl {
struct BgControl
{
struct BgConfig {
u16 visible:1;
u16 unknown_1:1;
@ -24,7 +26,8 @@ struct BgControl {
u16 bgVisibilityAndMode;
};
struct BgConfig2 {
struct BgConfig2
{
u32 baseTile:10;
u32 basePalette:4;
u32 unk_3:18;
@ -34,54 +37,36 @@ struct BgConfig2 {
u32 bg_y;
};
static struct BgControl gGpuBgConfigs;
static struct BgConfig2 gGpuBgConfigs2[4];
static u32 gDmaBusyBitfield[4];
static IWRAM_DATA struct BgControl sGpuBgConfigs;
static IWRAM_DATA struct BgConfig2 sGpuBgConfigs2[4];
static IWRAM_DATA u32 sDmaBusyBitfield[4];
u32 gUnneededFireRedVariable;
static const struct BgConfig gZeroedBgControlStruct = { 0 };
extern void SetGpuReg(u8 regOffset, u16 value);
extern void SetGpuReg_ForcedBlank(u8 regOffset, u16 value);
extern u16 GetGpuReg(u8 regOffset);
extern int CheckForSpaceForDma3Request(s16 index);
bool32 IsInvalidBg32(u8);
void ResetBgControlStructs();
u16 GetBgMetricTextMode(u8, u8);
u32 GetBgMetricAffineMode(u8, u8);
u32 GetBgType(u8);
void SetTextModeAndHideBgs();
bool8 IsInvalidBg(u8);
bool32 IsTileMapOutsideWram(u8);
void CopyRectToBgTilemapBufferRect(u8, void*, u8, u8, u8, u8, u8, u8, u8, u8, u8, u16, u16);
void CopyTileMapEntry(u16*, u16*, s32, u32, u32);
u32 GetTileMapIndexFromCoords(s32, s32, s32, u32, u32);
void WriteSequenceToBgTilemapBuffer(u8, u16, u8, u8, u8, u8, u8, s16);
static const struct BgConfig sZeroedBgControlStruct = { 0 };
void ResetBgs(void)
{
ResetBgControlStructs();
gGpuBgConfigs.bgVisibilityAndMode = 0;
sGpuBgConfigs.bgVisibilityAndMode = 0;
SetTextModeAndHideBgs();
}
void SetBgModeInternal(u8 bgMode)
static void SetBgModeInternal(u8 bgMode)
{
gGpuBgConfigs.bgVisibilityAndMode &= 0xFFF8;
gGpuBgConfigs.bgVisibilityAndMode |= bgMode;
sGpuBgConfigs.bgVisibilityAndMode &= 0xFFF8;
sGpuBgConfigs.bgVisibilityAndMode |= bgMode;
}
u8 GetBgMode(void)
{
return gGpuBgConfigs.bgVisibilityAndMode & 0x7;
return sGpuBgConfigs.bgVisibilityAndMode & 0x7;
}
void ResetBgControlStructs(void)
{
struct BgConfig* bgConfigs = &gGpuBgConfigs.configs[0];
struct BgConfig zeroedConfig = gZeroedBgControlStruct;
struct BgConfig* bgConfigs = &sGpuBgConfigs.configs[0];
struct BgConfig zeroedConfig = sZeroedBgControlStruct;
int i;
for (i = 0; i < 4; i++)
@ -94,7 +79,7 @@ void Unused_ResetBgControlStruct(u8 bg)
{
if (IsInvalidBg(bg) == FALSE)
{
gGpuBgConfigs.configs[bg] = gZeroedBgControlStruct;
sGpuBgConfigs.configs[bg] = sZeroedBgControlStruct;
}
}
@ -104,68 +89,68 @@ void SetBgControlAttributes(u8 bg, u8 charBaseIndex, u8 mapBaseIndex, u8 screenS
{
if (charBaseIndex != 0xFF)
{
gGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3;
sGpuBgConfigs.configs[bg].charBaseIndex = charBaseIndex & 0x3;
}
if (mapBaseIndex != 0xFF)
{
gGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F;
sGpuBgConfigs.configs[bg].mapBaseIndex = mapBaseIndex & 0x1F;
}
if (screenSize != 0xFF)
{
gGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3;
sGpuBgConfigs.configs[bg].screenSize = screenSize & 0x3;
}
if (paletteMode != 0xFF)
{
gGpuBgConfigs.configs[bg].paletteMode = paletteMode;
sGpuBgConfigs.configs[bg].paletteMode = paletteMode;
}
if (priority != 0xFF)
{
gGpuBgConfigs.configs[bg].priority = priority & 0x3;
sGpuBgConfigs.configs[bg].priority = priority & 0x3;
}
if (mosaic != 0xFF)
{
gGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1;
sGpuBgConfigs.configs[bg].mosaic = mosaic & 0x1;
}
if (wraparound != 0xFF)
{
gGpuBgConfigs.configs[bg].wraparound = wraparound;
sGpuBgConfigs.configs[bg].wraparound = wraparound;
}
gGpuBgConfigs.configs[bg].unknown_2 = 0;
gGpuBgConfigs.configs[bg].unknown_3 = 0;
sGpuBgConfigs.configs[bg].unknown_2 = 0;
sGpuBgConfigs.configs[bg].unknown_3 = 0;
gGpuBgConfigs.configs[bg].visible = 1;
sGpuBgConfigs.configs[bg].visible = 1;
}
}
u16 GetBgControlAttribute(u8 bg, u8 attributeId)
{
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE)
{
switch (attributeId)
{
case BG_CTRL_ATTR_VISIBLE:
return gGpuBgConfigs.configs[bg].visible;
return sGpuBgConfigs.configs[bg].visible;
case BG_CTRL_ATTR_CHARBASEINDEX:
return gGpuBgConfigs.configs[bg].charBaseIndex;
return sGpuBgConfigs.configs[bg].charBaseIndex;
case BG_CTRL_ATTR_MAPBASEINDEX:
return gGpuBgConfigs.configs[bg].mapBaseIndex;
return sGpuBgConfigs.configs[bg].mapBaseIndex;
case BG_CTRL_ATTR_SCREENSIZE:
return gGpuBgConfigs.configs[bg].screenSize;
return sGpuBgConfigs.configs[bg].screenSize;
case BG_CTRL_ATTR_PALETTEMODE:
return gGpuBgConfigs.configs[bg].paletteMode;
return sGpuBgConfigs.configs[bg].paletteMode;
case BG_CTRL_ATTR_PRIORITY:
return gGpuBgConfigs.configs[bg].priority;
return sGpuBgConfigs.configs[bg].priority;
case BG_CTRL_ATTR_MOSAIC:
return gGpuBgConfigs.configs[bg].mosaic;
return sGpuBgConfigs.configs[bg].mosaic;
case BG_CTRL_ATTR_WRAPAROUND:
return gGpuBgConfigs.configs[bg].wraparound;
return sGpuBgConfigs.configs[bg].wraparound;
}
}
@ -177,15 +162,15 @@ u8 LoadBgVram(u8 bg, const void *src, u16 size, u16 destOffset, u8 mode)
u16 offset;
s8 cursor;
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE)
{
switch (mode)
{
case 0x1:
offset = gGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE;
offset = sGpuBgConfigs.configs[bg].charBaseIndex * BG_CHAR_SIZE;
break;
case 0x2:
offset = gGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE;
offset = sGpuBgConfigs.configs[bg].mapBaseIndex * BG_SCREEN_SIZE;
break;
default:
cursor = -1;
@ -210,51 +195,51 @@ end:
return cursor;
}
void ShowBgInternal(u8 bg)
static void ShowBgInternal(u8 bg)
{
u16 value;
if (IsInvalidBg(bg) == FALSE && gGpuBgConfigs.configs[bg].visible != FALSE)
if (IsInvalidBg(bg) == FALSE && sGpuBgConfigs.configs[bg].visible != FALSE)
{
value = gGpuBgConfigs.configs[bg].priority |
(gGpuBgConfigs.configs[bg].charBaseIndex << 2) |
(gGpuBgConfigs.configs[bg].mosaic << 6) |
(gGpuBgConfigs.configs[bg].paletteMode << 7) |
(gGpuBgConfigs.configs[bg].mapBaseIndex << 8) |
(gGpuBgConfigs.configs[bg].wraparound << 13) |
(gGpuBgConfigs.configs[bg].screenSize << 14);
value = sGpuBgConfigs.configs[bg].priority |
(sGpuBgConfigs.configs[bg].charBaseIndex << 2) |
(sGpuBgConfigs.configs[bg].mosaic << 6) |
(sGpuBgConfigs.configs[bg].paletteMode << 7) |
(sGpuBgConfigs.configs[bg].mapBaseIndex << 8) |
(sGpuBgConfigs.configs[bg].wraparound << 13) |
(sGpuBgConfigs.configs[bg].screenSize << 14);
SetGpuReg((bg << 1) + 0x8, value);
gGpuBgConfigs.bgVisibilityAndMode |= 1 << (bg + 8);
gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
sGpuBgConfigs.bgVisibilityAndMode |= 1 << (bg + 8);
sGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
}
}
void HideBgInternal(u8 bg)
static void HideBgInternal(u8 bg)
{
if (IsInvalidBg(bg) == FALSE)
{
gGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8));
gGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
sGpuBgConfigs.bgVisibilityAndMode &= ~(1 << (bg + 8));
sGpuBgConfigs.bgVisibilityAndMode &= DISPCNT_ALL_BG_AND_MODE_BITS;
}
}
void SyncBgVisibilityAndMode()
static void SyncBgVisibilityAndMode(void)
{
SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | gGpuBgConfigs.bgVisibilityAndMode);
SetGpuReg(0, (GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS) | sGpuBgConfigs.bgVisibilityAndMode);
}
void SetTextModeAndHideBgs()
void SetTextModeAndHideBgs(void)
{
SetGpuReg(0, GetGpuReg(0) & ~DISPCNT_ALL_BG_AND_MODE_BITS);
}
void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle)
static void SetBgAffineInternal(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle)
{
struct BgAffineSrcData src;
struct BgAffineDstData dest;
switch (gGpuBgConfigs.bgVisibilityAndMode & 0x7)
switch (sGpuBgConfigs.bgVisibilityAndMode & 0x7)
{
case 1:
if (bg != 2)
@ -309,7 +294,7 @@ void ResetBgsAndClearDma3BusyFlags(u32 leftoverFireRedLeafGreenVariable)
for (i = 0; i < 4; i++)
{
gDmaBusyBitfield[i] = 0;
sDmaBusyBitfield[i] = 0;
}
gUnneededFireRedVariable = leftoverFireRedLeafGreenVariable;
@ -336,18 +321,18 @@ void InitBgsFromTemplates(u8 bgMode, const struct BgTemplate *templates, u8 numT
0,
0);
gGpuBgConfigs2[bg].baseTile = templates[i].baseTile;
gGpuBgConfigs2[bg].basePalette = 0;
gGpuBgConfigs2[bg].unk_3 = 0;
sGpuBgConfigs2[bg].baseTile = templates[i].baseTile;
sGpuBgConfigs2[bg].basePalette = 0;
sGpuBgConfigs2[bg].unk_3 = 0;
gGpuBgConfigs2[bg].tilemap = NULL;
gGpuBgConfigs2[bg].bg_x = 0;
gGpuBgConfigs2[bg].bg_y = 0;
sGpuBgConfigs2[bg].tilemap = NULL;
sGpuBgConfigs2[bg].bg_x = 0;
sGpuBgConfigs2[bg].bg_y = 0;
}
}
}
void InitBgFromTemplate(struct BgTemplate *template)
void InitBgFromTemplate(const struct BgTemplate *template)
{
u8 bg = template->bg;
@ -362,13 +347,13 @@ void InitBgFromTemplate(struct BgTemplate *template)
0,
0);
gGpuBgConfigs2[bg].baseTile = template->baseTile;
gGpuBgConfigs2[bg].basePalette = 0;
gGpuBgConfigs2[bg].unk_3 = 0;
sGpuBgConfigs2[bg].baseTile = template->baseTile;
sGpuBgConfigs2[bg].basePalette = 0;
sGpuBgConfigs2[bg].unk_3 = 0;
gGpuBgConfigs2[bg].tilemap = NULL;
gGpuBgConfigs2[bg].bg_x = 0;
gGpuBgConfigs2[bg].bg_y = 0;
sGpuBgConfigs2[bg].tilemap = NULL;
sGpuBgConfigs2[bg].bg_x = 0;
sGpuBgConfigs2[bg].bg_y = 0;
}
}
@ -384,11 +369,11 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_PALETTEMODE) == 0)
{
tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x20;
tileOffset = (sGpuBgConfigs2[bg].baseTile + destOffset) * 0x20;
}
else
{
tileOffset = (gGpuBgConfigs2[bg].baseTile + destOffset) * 0x40;
tileOffset = (sGpuBgConfigs2[bg].baseTile + destOffset) * 0x40;
}
cursor = LoadBgVram(bg, src, size, tileOffset, DISPCNT_MODE_1);
@ -398,7 +383,7 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
return -1;
}
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
if (gUnneededFireRedVariable == 1)
{
@ -408,7 +393,7 @@ u16 LoadBgTiles(u8 bg, const void* src, u16 size, u16 destOffset)
return cursor;
}
u16 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset)
u16 LoadBgTilemap(u8 bg, const void *src, u16 size, u16 destOffset)
{
u8 cursor;
@ -419,19 +404,19 @@ u16 LoadBgTilemap(u8 bg, void *src, u16 size, u16 destOffset)
return -1;
}
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
return cursor;
}
u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset)
u16 Unused_LoadBgPalette(u8 bg, const void *src, u16 size, u16 destOffset)
{
u16 paletteOffset;
s8 cursor;
if (IsInvalidBg32(bg) == FALSE)
{
paletteOffset = (gGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2);
paletteOffset = (sGpuBgConfigs2[bg].basePalette * 0x20) + (destOffset * 2);
cursor = RequestDma3Copy(src, (void*)(paletteOffset + BG_PLTT), size, 0);
if (cursor == -1)
@ -444,7 +429,7 @@ u16 Unused_LoadBgPalette(u8 bg, void *src, u16 size, u16 destOffset)
return -1;
}
gDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
sDmaBusyBitfield[cursor / 0x20] |= (1 << (cursor % 0x20));
return (u8)cursor;
}
@ -463,7 +448,7 @@ bool8 IsDma3ManagerBusyWithBgCopy(void)
div = i / 0x20;
mod = i % 0x20;
if ((gDmaBusyBitfield[div] & (1 << mod)) != FALSE)
if ((sDmaBusyBitfield[div] & (1 << mod)) != FALSE)
{
reqSpace = CheckForSpaceForDma3Request(i);
if (reqSpace == -1)
@ -471,7 +456,7 @@ bool8 IsDma3ManagerBusyWithBgCopy(void)
return TRUE;
}
gDmaBusyBitfield[div] &= ~(1 << mod);
sDmaBusyBitfield[div] &= ~(1 << mod);
}
}
@ -497,7 +482,7 @@ _08001AE4:\n\
sub r0, r5, r0\n\
lsl r0, #24\n\
lsr r0, #24\n\
ldr r1, =gDmaBusyBitfield\n\
ldr r1, =sDmaBusyBitfield\n\
lsr r2, #22\n\
add r4, r2, r1\n\
mov r6, #0x1\n\
@ -603,7 +588,7 @@ u16 GetBgAttribute(u8 bg, u8 attributeId)
case 9:
return GetBgType(bg);
case 10:
return gGpuBgConfigs2[bg].baseTile;
return sGpuBgConfigs2[bg].baseTile;
default:
return -1;
}
@ -624,13 +609,13 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
{
case 0:
default:
gGpuBgConfigs2[bg].bg_x = value;
sGpuBgConfigs2[bg].bg_x = value;
break;
case 1:
gGpuBgConfigs2[bg].bg_x += value;
sGpuBgConfigs2[bg].bg_x += value;
break;
case 2:
gGpuBgConfigs2[bg].bg_x -= value;
sGpuBgConfigs2[bg].bg_x -= value;
break;
}
@ -639,23 +624,23 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
switch (bg)
{
case 0:
temp1 = gGpuBgConfigs2[0].bg_x >> 0x8;
temp1 = sGpuBgConfigs2[0].bg_x >> 0x8;
SetGpuReg(REG_OFFSET_BG0HOFS, temp1);
break;
case 1:
temp1 = gGpuBgConfigs2[1].bg_x >> 0x8;
temp1 = sGpuBgConfigs2[1].bg_x >> 0x8;
SetGpuReg(REG_OFFSET_BG1HOFS, temp1);
break;
case 2:
if (mode == 0)
{
temp1 = gGpuBgConfigs2[2].bg_x >> 0x8;
temp1 = sGpuBgConfigs2[2].bg_x >> 0x8;
SetGpuReg(REG_OFFSET_BG2HOFS, temp1);
}
else
{
temp1 = gGpuBgConfigs2[2].bg_x >> 0x10;
temp2 = gGpuBgConfigs2[2].bg_x & 0xFFFF;
temp1 = sGpuBgConfigs2[2].bg_x >> 0x10;
temp2 = sGpuBgConfigs2[2].bg_x & 0xFFFF;
SetGpuReg(REG_OFFSET_BG2X_H, temp1);
SetGpuReg(REG_OFFSET_BG2X_L, temp2);
}
@ -663,20 +648,20 @@ u32 ChangeBgX(u8 bg, u32 value, u8 op)
case 3:
if (mode == 0)
{
temp1 = gGpuBgConfigs2[3].bg_x >> 0x8;
temp1 = sGpuBgConfigs2[3].bg_x >> 0x8;
SetGpuReg(REG_OFFSET_BG3HOFS, temp1);
}
else if (mode == 2)
{
temp1 = gGpuBgConfigs2[3].bg_x >> 0x10;
temp2 = gGpuBgConfigs2[3].bg_x & 0xFFFF;
temp1 = sGpuBgConfigs2[3].bg_x >> 0x10;
temp2 = sGpuBgConfigs2[3].bg_x & 0xFFFF;
SetGpuReg(REG_OFFSET_BG3X_H, temp1);
SetGpuReg(REG_OFFSET_BG3X_L, temp2);
}
break;
}
return gGpuBgConfigs2[bg].bg_x;
return sGpuBgConfigs2[bg].bg_x;
}
u32 GetBgX(u8 bg)
@ -685,7 +670,7 @@ u32 GetBgX(u8 bg)
return -1;
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
return -1;
return gGpuBgConfigs2[bg].bg_x;
return sGpuBgConfigs2[bg].bg_x;
}
u32 ChangeBgY(u8 bg, u32 value, u8 op)
@ -703,13 +688,13 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
{
case 0:
default:
gGpuBgConfigs2[bg].bg_y = value;
sGpuBgConfigs2[bg].bg_y = value;
break;
case 1:
gGpuBgConfigs2[bg].bg_y += value;
sGpuBgConfigs2[bg].bg_y += value;
break;
case 2:
gGpuBgConfigs2[bg].bg_y -= value;
sGpuBgConfigs2[bg].bg_y -= value;
break;
}
@ -718,23 +703,23 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
switch (bg)
{
case 0:
temp1 = gGpuBgConfigs2[0].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[0].bg_y >> 0x8;
SetGpuReg(REG_OFFSET_BG0VOFS, temp1);
break;
case 1:
temp1 = gGpuBgConfigs2[1].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[1].bg_y >> 0x8;
SetGpuReg(REG_OFFSET_BG1VOFS, temp1);
break;
case 2:
if (mode == 0)
{
temp1 = gGpuBgConfigs2[2].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[2].bg_y >> 0x8;
SetGpuReg(REG_OFFSET_BG2VOFS, temp1);
}
else
{
temp1 = gGpuBgConfigs2[2].bg_y >> 0x10;
temp2 = gGpuBgConfigs2[2].bg_y & 0xFFFF;
temp1 = sGpuBgConfigs2[2].bg_y >> 0x10;
temp2 = sGpuBgConfigs2[2].bg_y & 0xFFFF;
SetGpuReg(REG_OFFSET_BG2Y_H, temp1);
SetGpuReg(REG_OFFSET_BG2Y_L, temp2);
}
@ -742,20 +727,20 @@ u32 ChangeBgY(u8 bg, u32 value, u8 op)
case 3:
if (mode == 0)
{
temp1 = gGpuBgConfigs2[3].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[3].bg_y >> 0x8;
SetGpuReg(REG_OFFSET_BG3VOFS, temp1);
}
else if (mode == 2)
{
temp1 = gGpuBgConfigs2[3].bg_y >> 0x10;
temp2 = gGpuBgConfigs2[3].bg_y & 0xFFFF;
temp1 = sGpuBgConfigs2[3].bg_y >> 0x10;
temp2 = sGpuBgConfigs2[3].bg_y & 0xFFFF;
SetGpuReg(REG_OFFSET_BG3Y_H, temp1);
SetGpuReg(REG_OFFSET_BG3Y_L, temp2);
}
break;
}
return gGpuBgConfigs2[bg].bg_y;
return sGpuBgConfigs2[bg].bg_y;
}
u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
@ -773,13 +758,13 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
{
case 0:
default:
gGpuBgConfigs2[bg].bg_y = value;
sGpuBgConfigs2[bg].bg_y = value;
break;
case 1:
gGpuBgConfigs2[bg].bg_y += value;
sGpuBgConfigs2[bg].bg_y += value;
break;
case 2:
gGpuBgConfigs2[bg].bg_y -= value;
sGpuBgConfigs2[bg].bg_y -= value;
break;
}
@ -788,24 +773,24 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
switch (bg)
{
case 0:
temp1 = gGpuBgConfigs2[0].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[0].bg_y >> 0x8;
SetGpuReg_ForcedBlank(REG_OFFSET_BG0VOFS, temp1);
break;
case 1:
temp1 = gGpuBgConfigs2[1].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[1].bg_y >> 0x8;
SetGpuReg_ForcedBlank(REG_OFFSET_BG1VOFS, temp1);
break;
case 2:
if (mode == 0)
{
temp1 = gGpuBgConfigs2[2].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[2].bg_y >> 0x8;
SetGpuReg_ForcedBlank(REG_OFFSET_BG2VOFS, temp1);
}
else
{
temp1 = gGpuBgConfigs2[2].bg_y >> 0x10;
temp2 = gGpuBgConfigs2[2].bg_y & 0xFFFF;
temp1 = sGpuBgConfigs2[2].bg_y >> 0x10;
temp2 = sGpuBgConfigs2[2].bg_y & 0xFFFF;
SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_H, temp1);
SetGpuReg_ForcedBlank(REG_OFFSET_BG2Y_L, temp2);
}
@ -813,20 +798,20 @@ u32 ChangeBgY_ScreenOff(u8 bg, u32 value, u8 op)
case 3:
if (mode == 0)
{
temp1 = gGpuBgConfigs2[3].bg_y >> 0x8;
temp1 = sGpuBgConfigs2[3].bg_y >> 0x8;
SetGpuReg_ForcedBlank(REG_OFFSET_BG3VOFS, temp1);
}
else if (mode == 2)
{
temp1 = gGpuBgConfigs2[3].bg_y >> 0x10;
temp2 = gGpuBgConfigs2[3].bg_y & 0xFFFF;
temp1 = sGpuBgConfigs2[3].bg_y >> 0x10;
temp2 = sGpuBgConfigs2[3].bg_y & 0xFFFF;
SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_H, temp1);
SetGpuReg_ForcedBlank(REG_OFFSET_BG3Y_L, temp2);
}
break;
}
return gGpuBgConfigs2[bg].bg_y;
return sGpuBgConfigs2[bg].bg_y;
}
u32 GetBgY(u8 bg)
@ -835,7 +820,7 @@ u32 GetBgY(u8 bg)
return -1;
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
return -1;
return gGpuBgConfigs2[bg].bg_y;
return sGpuBgConfigs2[bg].bg_y;
}
void SetBgAffine(u8 bg, u32 srcCenterX, u32 srcCenterY, s16 dispCenterX, s16 dispCenterY, s16 scaleX, s16 scaleY, u16 rotationAngle)
@ -922,7 +907,7 @@ void SetBgTilemapBuffer(u8 bg, void *tilemap)
{
if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0)
{
gGpuBgConfigs2[bg].tilemap = tilemap;
sGpuBgConfigs2[bg].tilemap = tilemap;
}
}
@ -930,7 +915,7 @@ void UnsetBgTilemapBuffer(u8 bg)
{
if (IsInvalidBg32(bg) == FALSE && GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) != 0x0)
{
gGpuBgConfigs2[bg].tilemap = NULL;
sGpuBgConfigs2[bg].tilemap = NULL;
}
}
@ -940,7 +925,7 @@ void* GetBgTilemapBuffer(u8 bg)
return NULL;
if (GetBgControlAttribute(bg, BG_CTRL_ATTR_VISIBLE) == 0)
return NULL;
return gGpuBgConfigs2[bg].tilemap;
return sGpuBgConfigs2[bg].tilemap;
}
void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset)
@ -949,11 +934,11 @@ void CopyToBgTilemapBuffer(u8 bg, const void *src, u16 mode, u16 destOffset)
{
if (mode != 0)
{
CpuCopy16(src, (void *)(gGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode);
CpuCopy16(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)), mode);
}
else
{
LZ77UnCompWram(src, (void *)(gGpuBgConfigs2[bg].tilemap + (destOffset * 2)));
LZ77UnCompWram(src, (void *)(sGpuBgConfigs2[bg].tilemap + (destOffset * 2)));
}
}
}
@ -976,7 +961,7 @@ void CopyBgTilemapBufferToVram(u8 bg)
sizeToLoad = 0;
break;
}
LoadBgVram(bg, gGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2);
LoadBgVram(bg, sGpuBgConfigs2[bg].tilemap, sizeToLoad, 0, 2);
}
}
@ -997,7 +982,7 @@ void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u
{
for (destX16 = destX; destX16 < (destX + width); destX16++)
{
((u16*)gGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *((u16*)srcCopy)++;
((u16*)sGpuBgConfigs2[bg].tilemap)[((destY16 * 0x20) + destX16)] = *((u16*)srcCopy)++;
}
}
break;
@ -1008,7 +993,7 @@ void CopyToBgTilemapBufferRect(u8 bg, void* src, u8 destX, u8 destY, u8 width, u
{
for (destX16 = destX; destX16 < (destX + width); destX16++)
{
((u8*)gGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *((u8*)srcCopy)++;
((u8*)sGpuBgConfigs2[bg].tilemap)[((destY16 * mode) + destX16)] = *((u8*)srcCopy)++;
}
}
break;
@ -1045,7 +1030,7 @@ void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWid
{
for (destX16 = destX; destX16 < (destX + rectWidth); destX16++)
{
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)gGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)sGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
}
}
break;
@ -1056,7 +1041,7 @@ void CopyRectToBgTilemapBufferRect(u8 bg, void* src, u8 srcX, u8 srcY, u8 srcWid
{
for (destX16 = destX; destX16 < (destX + rectWidth); destX16++)
{
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)gGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
CopyTileMapEntry(&((u16*)srcCopy)[(srcY * rectWidth) + srcX], &((u16*)sGpuBgConfigs2[bg].tilemap)[GetTileMapIndexFromCoords(destX16, destY16, attribute, mode, mode2)], palette1, tileOffset, palette2);
}
}
break;
@ -1184,7 +1169,7 @@ _080025F8:\n\
bge _0800265A\n\
ldr r2, [sp, #0x4]\n\
lsl r0, r2, #4\n\
ldr r1, =gGpuBgConfigs2+4\n\
ldr r1, =sGpuBgConfigs2+4\n\
add r0, r1\n\
mov r10, r0\n\
ldr r7, [sp, #0x20]\n\
@ -1256,7 +1241,7 @@ _08002674:\n\
sub r2, r7, r2\n\
str r2, [sp, #0x34]\n\
str r0, [sp, #0x38]\n\
ldr r7, =gGpuBgConfigs2+4\n\
ldr r7, =sGpuBgConfigs2+4\n\
mov r10, r7\n\
ldr r0, [sp, #0x4]\n\
lsl r0, #4\n\
@ -1326,7 +1311,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
{
for (x16 = x; x16 < (x + width); x16++)
{
((u16*)gGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum;
((u16*)sGpuBgConfigs2[bg].tilemap)[((y16 * 0x20) + x16)] = tileNum;
}
}
break;
@ -1336,7 +1321,7 @@ void FillBgTilemapBufferRect_Palette0(u8 bg, u16 tileNum, u8 x, u8 y, u8 width,
{
for (x16 = x; x16 < (x + width); x16++)
{
((u8*)gGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum;
((u8*)sGpuBgConfigs2[bg].tilemap)[((y16 * mode) + x16)] = tileNum;
}
}
break;
@ -1371,7 +1356,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
{
for (x16 = x; x16 < (x + width); x16++)
{
CopyTileMapEntry(&firstTileNum, &((u16*)gGpuBgConfigs2[bg].tilemap)[(u16)GetTileMapIndexFromCoords(x16, y16, attribute, mode, mode2)], paletteSlot, 0, 0);
CopyTileMapEntry(&firstTileNum, &((u16*)sGpuBgConfigs2[bg].tilemap)[(u16)GetTileMapIndexFromCoords(x16, y16, attribute, mode, mode2)], paletteSlot, 0, 0);
firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF);
}
}
@ -1382,7 +1367,7 @@ void WriteSequenceToBgTilemapBuffer(u8 bg, u16 firstTileNum, u8 x, u8 y, u8 widt
{
for (x16 = x; x16 < (x + width); x16++)
{
((u8*)gGpuBgConfigs2[bg].tilemap)[(y16 * mode3) + x16] = firstTileNum;
((u8*)sGpuBgConfigs2[bg].tilemap)[(y16 * mode3) + x16] = firstTileNum;
firstTileNum = (firstTileNum & 0xFC00) + ((firstTileNum + tileNumDelta) & 0x3FF);
}
}
@ -1614,9 +1599,9 @@ bool32 IsInvalidBg32(u8 bg)
bool32 IsTileMapOutsideWram(u8 bg)
{
if (gGpuBgConfigs2[bg].tilemap > (void*)IWRAM_END)
if (sGpuBgConfigs2[bg].tilemap > (void*)IWRAM_END)
return TRUE;
if (gGpuBgConfigs2[bg].tilemap == 0x0)
if (sGpuBgConfigs2[bg].tilemap == 0x0)
return TRUE;
return FALSE;
}

View File

@ -91,8 +91,8 @@ void ProcessDma3Requests(void)
DmaFill16(3, gDma3Requests[gDma3RequestCursor].value, gDma3Requests[gDma3RequestCursor].dest, gDma3Requests[gDma3RequestCursor].size);
break;
}
gDma3Requests[gDma3RequestCursor].src = 0;
gDma3Requests[gDma3RequestCursor].dest = 0;
gDma3Requests[gDma3RequestCursor].src = NULL;
gDma3Requests[gDma3RequestCursor].dest = NULL;
gDma3Requests[gDma3RequestCursor].size = 0;
gDma3Requests[gDma3RequestCursor].mode = 0;
gDma3Requests[gDma3RequestCursor].value = 0;

View File

@ -22,6 +22,7 @@
#include "bg.h"
#include "m4a.h"
#include "window.h"
#include "abilities.h"
#include "battle.h" // to get rid of later
struct EggHatchData
@ -41,23 +42,18 @@ struct EggHatchData
struct TextColor textColor;
};
extern struct EggHatchData* gEggHatchData;
extern struct SpriteTemplate gUnknown_0202499C;
extern void (*gFieldCallback)(void);
extern const struct CompressedSpriteSheet gMonFrontPicTable[];
extern const struct BgTemplate gUnknown_0832C064[2];
extern const struct WindowTemplate gUnknown_0832C06C[2];
extern const u8 gUnknown_08C00000[];
extern const u8 gUnknown_08C00524[];
extern const u8 gUnknown_08C004E0[];
extern const struct SpriteSheet gUnknown_0832BFE4; // hatching egg
extern const struct SpriteSheet gUnknown_0832BFEC; // egg shell
extern const struct SpritePalette gUnknown_0832BFF4; // hatching egg
extern const u16 gUnknown_08DD7300[]; // palette, gameboy advance
extern const u32 gUnknown_08DD7360[]; // tileset gameboy advance
extern const u32 gUnknown_08331F60[]; // tilemap gameboy circle
extern const u8 gOtherText_HatchedFromEgg[];
extern const u8 gOtherText_NickHatchPrompt[];
extern u8* GetMonNick(struct Pokemon* mon, u8* dst);
extern u8* GetBoxMonNick(struct BoxPokemon* boxMon, u8* dst);
@ -75,9 +71,11 @@ extern void reset_temp_tile_data_buffers(void);
extern void c2_exit_to_overworld_2_switch(void);
extern void play_some_sound(void);
extern void copy_decompressed_tile_data_to_vram_autofree(u8 bg_id, const void* src, u16 size, u16 offset, u8 mode);
extern void CreateYesNoMenu(const u8*, u16, u8, u8);
extern void CreateYesNoMenu(const struct WindowTemplate*, u16, u8, u8);
extern void DoNamingScreen(u8, const u8*, u16, u8, u32, MainCallback);
extern void AddTextPrinterParametrized2(u8 windowId, u8 fontId, u8 x, u8 y, u8 letterSpacing, u8 lineSpacing, struct TextColor* colors, s8 speed, u8 *str);
extern u16 sub_80D22D0(void);
extern u8 sub_80C7050(u8);
static void Task_EggHatch(u8 taskID);
static void CB2_EggHatch_0(void);
@ -93,6 +91,213 @@ static void EggHatchPrintMessage(u8 windowId, u8* string, u8 x, u8 y, u8 speed);
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;
// rom data
static const u16 sEggPalette[] = INCBIN_U16("graphics/pokemon/palettes/egg_palette.gbapal");
static const u8 sEggHatchTiles[] = INCBIN_U8("graphics/misc/egg_hatch.4bpp");
static const u8 sEggShardTiles[] = INCBIN_U8("graphics/misc/egg_shard.4bpp");
static const struct OamData sOamData_EggHatch =
{
.y = 0,
.affineMode = 0,
.objMode = 0,
.mosaic = 0,
.bpp = 0,
.shape = 0,
.x = 0,
.matrixNum = 0,
.size = 2,
.tileNum = 0,
.priority = 1,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sSpriteAnim_EggHatch0[] =
{
ANIMCMD_FRAME(0, 5),
ANIMCMD_END
};
static const union AnimCmd sSpriteAnim_EggHatch1[] =
{
ANIMCMD_FRAME(16, 5),
ANIMCMD_END
};
static const union AnimCmd sSpriteAnim_EggHatch2[] =
{
ANIMCMD_FRAME(32, 5),
ANIMCMD_END
};
static const union AnimCmd sSpriteAnim_EggHatch3[] =
{
ANIMCMD_FRAME(48, 5),
ANIMCMD_END
};
static const union AnimCmd *const sSpriteAnimTable_EggHatch[] =
{
sSpriteAnim_EggHatch0,
sSpriteAnim_EggHatch1,
sSpriteAnim_EggHatch2,
sSpriteAnim_EggHatch3,
};
static const struct SpriteSheet sEggHatch_Sheet =
{
.data = sEggHatchTiles,
.size = 2048,
.tag = 12345,
};
static const struct SpriteSheet sEggShards_Sheet =
{
.data = sEggShardTiles,
.size = 128,
.tag = 23456,
};
static const struct SpritePalette sEgg_SpritePalette =
{
.data = sEggPalette,
.tag = 54321
};
static const struct SpriteTemplate sSpriteTemplate_EggHatch =
{
.tileTag = 12345,
.paletteTag = 54321,
.oam = &sOamData_EggHatch,
.anims = sSpriteAnimTable_EggHatch,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCallbackDummy
};
static const struct OamData sOamData_EggShard =
{
.y = 0,
.affineMode = 0,
.objMode = 0,
.mosaic = 0,
.bpp = 0,
.shape = 0,
.x = 0,
.matrixNum = 0,
.size = 0,
.tileNum = 0,
.priority = 2,
.paletteNum = 0,
.affineParam = 0,
};
static const union AnimCmd sSpriteAnim_EggShard0[] =
{
ANIMCMD_FRAME(0, 5),
ANIMCMD_END
};
static const union AnimCmd sSpriteAnim_EggShard1[] =
{
ANIMCMD_FRAME(1, 5),
ANIMCMD_END
};
static const union AnimCmd sSpriteAnim_EggShard2[] =
{
ANIMCMD_FRAME(2, 5),
ANIMCMD_END
};
static const union AnimCmd sSpriteAnim_EggShard3[] =
{
ANIMCMD_FRAME(3, 5),
ANIMCMD_END
};
static const union AnimCmd *const sSpriteAnimTable_EggShard[] =
{
sSpriteAnim_EggShard0,
sSpriteAnim_EggShard1,
sSpriteAnim_EggShard2,
sSpriteAnim_EggShard3,
};
static const struct SpriteTemplate sSpriteTemplate_EggShard =
{
.tileTag = 23456,
.paletteTag = 54321,
.oam = &sOamData_EggShard,
.anims = sSpriteAnimTable_EggShard,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_EggShard
};
static const struct BgTemplate sBgTemplates_EggHatch[2] =
{
{
.bg = 0,
.charBaseIndex = 2,
.mapBaseIndex = 24,
.screenSize = 3,
.paletteMode = 0,
.priority = 0,
.baseTile = 0
},
{
.bg = 1,
.charBaseIndex = 0,
.mapBaseIndex = 8,
.screenSize = 1,
.paletteMode = 0,
.priority = 2,
.baseTile = 0
},
};
static const struct WindowTemplate sWinTemplates_EggHatch[2] =
{
{0, 2, 0xF, 0x1A, 4, 0, 0x40},
DUMMY_WIN_TEMPLATE
};
static const struct WindowTemplate sYesNoWinTemplate =
{
0, 0x15, 9, 5, 4, 0xF, 0x1A8
};
static const s16 sEggShardVelocities[][2] =
{
{Q_8_8(-1.5), Q_8_8(-3.75)},
{Q_8_8(-5), Q_8_8(-3)},
{Q_8_8(3.5), Q_8_8(-3)},
{Q_8_8(-4), Q_8_8(-3.75)},
{Q_8_8(2), Q_8_8(-1.5)},
{Q_8_8(-0.5), Q_8_8(-6.75)},
{Q_8_8(5), Q_8_8(-2.25)},
{Q_8_8(-1.5), Q_8_8(-3.75)},
{Q_8_8(4.5), Q_8_8(-1.5)},
{Q_8_8(-1), Q_8_8(-6.75)},
{Q_8_8(4), Q_8_8(-2.25)},
{Q_8_8(-3.5), Q_8_8(-3.75)},
{Q_8_8(1), Q_8_8(-1.5)},
{Q_8_8(-3.515625), Q_8_8(-6.75)},
{Q_8_8(4.5), Q_8_8(-2.25)},
{Q_8_8(-0.5), Q_8_8(-7.5)},
{Q_8_8(1), Q_8_8(-4.5)},
{Q_8_8(-2.5), Q_8_8(-2.25)},
{Q_8_8(2.5), Q_8_8(-7.5)},
};
// code
static void CreatedHatchedMon(struct Pokemon *egg, struct Pokemon *temp)
{
u16 species;
@ -282,17 +487,17 @@ static void CB2_EggHatch_0(void)
case 0:
SetGpuReg(REG_OFFSET_DISPCNT, 0);
gEggHatchData = Alloc(sizeof(struct EggHatchData));
sEggHatchData = Alloc(sizeof(struct EggHatchData));
init_uns_table_pokemon_copy();
gEggHatchData->eggPartyID = gSpecialVar_0x8004;
gEggHatchData->eggShardVelocityID = 0;
sEggHatchData->eggPartyID = gSpecialVar_0x8004;
sEggHatchData->eggShardVelocityID = 0;
SetVBlankCallback(VBlankCB_EggHatch);
gSpecialVar_0x8005 = GetCurrentMapMusic();
reset_temp_tile_data_buffers();
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, gUnknown_0832C064, 2);
InitBgsFromTemplates(0, sBgTemplates_EggHatch, ARRAY_COUNT(sBgTemplates_EggHatch));
ChangeBgX(1, 0, 0);
ChangeBgY(1, 0, 0);
@ -313,8 +518,8 @@ static void CB2_EggHatch_0(void)
gMain.state++;
break;
case 1:
InitWindows(gUnknown_0832C06C);
gEggHatchData->windowId = 0;
InitWindows(sWinTemplates_EggHatch);
sEggHatchData->windowId = 0;
gMain.state++;
break;
case 2:
@ -324,22 +529,22 @@ static void CB2_EggHatch_0(void)
gMain.state++;
break;
case 3:
LoadSpriteSheet(&gUnknown_0832BFE4);
LoadSpriteSheet(&gUnknown_0832BFEC);
LoadSpritePalette(&gUnknown_0832BFF4);
LoadSpriteSheet(&sEggHatch_Sheet);
LoadSpriteSheet(&sEggShards_Sheet);
LoadSpritePalette(&sEgg_SpritePalette);
gMain.state++;
break;
case 4:
CopyBgTilemapBufferToVram(0);
AddHatchedMonToParty(gEggHatchData->eggPartyID);
AddHatchedMonToParty(sEggHatchData->eggPartyID);
gMain.state++;
break;
case 5:
EggHatchCreateMonSprite(0, 0, gEggHatchData->eggPartyID, &gEggHatchData->species);
EggHatchCreateMonSprite(0, 0, sEggHatchData->eggPartyID, &sEggHatchData->species);
gMain.state++;
break;
case 6:
gEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, gEggHatchData->eggPartyID, &gEggHatchData->species);
sEggHatchData->pokeSpriteID = EggHatchCreateMonSprite(0, 1, sEggHatchData->eggPartyID, &sEggHatchData->species);
gMain.state++;
break;
case 7:
@ -352,7 +557,7 @@ static void CB2_EggHatch_0(void)
break;
case 8:
SetMainCallback2(CB2_EggHatch_1);
gEggHatchData->CB2_state = 0;
sEggHatchData->CB2_state = 0;
break;
}
RunTasks();
@ -366,7 +571,7 @@ static void EggHatchSetMonNickname(void)
{
SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_NICKNAME, gStringVar3);
sub_805F094();
Free(gEggHatchData);
Free(sEggHatchData);
SetMainCallback2(c2_exit_to_overworld_2_switch);
}
@ -388,114 +593,109 @@ static void Task_EggHatchPlayBGM(u8 taskID)
gTasks[taskID].data[0]++;
}
extern const struct SpriteTemplate gUnknown_0832BFFC;
extern const u8 gUnknown_0832C07C[];
extern const u8 gOtherText_HatchedFromEgg[];
extern const u8 gOtherText_NickHatchPrompt[];
static void CB2_EggHatch_1(void)
{
u16 species;
u8 gender;
u32 personality;
switch (gEggHatchData->CB2_state)
switch (sEggHatchData->CB2_state)
{
case 0:
BeginNormalPaletteFade(-1, 0, 0x10, 0, 0);
gEggHatchData->eggSpriteID = CreateSprite(&gUnknown_0832BFFC, 120, 75, 5);
sEggHatchData->eggSpriteID = CreateSprite(&sSpriteTemplate_EggHatch, 120, 75, 5);
ShowBg(0);
ShowBg(1);
gEggHatchData->CB2_state++;
sEggHatchData->CB2_state++;
CreateTask(Task_EggHatchPlayBGM, 5);
break;
case 1:
if (!gPaletteFade.active)
{
FillWindowPixelBuffer(gEggHatchData->windowId, 0);
gEggHatchData->CB2_PalCounter = 0;
gEggHatchData->CB2_state++;
FillWindowPixelBuffer(sEggHatchData->windowId, 0);
sEggHatchData->CB2_PalCounter = 0;
sEggHatchData->CB2_state++;
}
break;
case 2:
if (++gEggHatchData->CB2_PalCounter > 30)
if (++sEggHatchData->CB2_PalCounter > 30)
{
gEggHatchData->CB2_state++;
gSprites[gEggHatchData->eggSpriteID].callback = SpriteCB_Egg_0;
sEggHatchData->CB2_state++;
gSprites[sEggHatchData->eggSpriteID].callback = SpriteCB_Egg_0;
}
break;
case 3:
if (gSprites[gEggHatchData->eggSpriteID].callback == SpriteCallbackDummy)
if (gSprites[sEggHatchData->eggSpriteID].callback == SpriteCallbackDummy)
{
species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES);
DoMonFrontSpriteAnimation(&gSprites[gEggHatchData->pokeSpriteID], species, FALSE, 1);
gEggHatchData->CB2_state++;
species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES);
DoMonFrontSpriteAnimation(&gSprites[sEggHatchData->pokeSpriteID], species, FALSE, 1);
sEggHatchData->CB2_state++;
}
break;
case 4:
if (gSprites[gEggHatchData->pokeSpriteID].callback == SpriteCallbackDummy)
if (gSprites[sEggHatchData->pokeSpriteID].callback == SpriteCallbackDummy)
{
gEggHatchData->CB2_state++;
sEggHatchData->CB2_state++;
}
break;
case 5:
GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar1);
GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar1);
StringExpandPlaceholders(gStringVar4, gOtherText_HatchedFromEgg);
EggHatchPrintMessage(gEggHatchData->windowId, gStringVar4, 0, 3, 0xFF);
EggHatchPrintMessage(sEggHatchData->windowId, gStringVar4, 0, 3, 0xFF);
PlayFanfare(371);
gEggHatchData->CB2_state++;
PutWindowTilemap(gEggHatchData->windowId);
CopyWindowToVram(gEggHatchData->windowId, 3);
sEggHatchData->CB2_state++;
PutWindowTilemap(sEggHatchData->windowId);
CopyWindowToVram(sEggHatchData->windowId, 3);
break;
case 6:
if (IsFanfareTaskInactive())
gEggHatchData->CB2_state++;
sEggHatchData->CB2_state++;
break;
case 7:
if (IsFanfareTaskInactive())
gEggHatchData->CB2_state++;
sEggHatchData->CB2_state++;
break;
case 8:
GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar1);
GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar1);
StringExpandPlaceholders(gStringVar4, gOtherText_NickHatchPrompt);
EggHatchPrintMessage(gEggHatchData->windowId, gStringVar4, 0, 2, 1);
gEggHatchData->CB2_state++;
EggHatchPrintMessage(sEggHatchData->windowId, gStringVar4, 0, 2, 1);
sEggHatchData->CB2_state++;
break;
case 9:
if (!IsTextPrinterActive(gEggHatchData->windowId))
if (!IsTextPrinterActive(sEggHatchData->windowId))
{
sub_809882C(gEggHatchData->windowId, 0x140, 0xE0);
CreateYesNoMenu(gUnknown_0832C07C, 0x140, 0xE, 0);
gEggHatchData->CB2_state++;
sub_809882C(sEggHatchData->windowId, 0x140, 0xE0);
CreateYesNoMenu(&sYesNoWinTemplate, 0x140, 0xE, 0);
sEggHatchData->CB2_state++;
}
break;
case 10:
switch (sub_8198C58())
{
case 0:
GetMonNick(&gPlayerParty[gEggHatchData->eggPartyID], gStringVar3);
species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES);
gender = GetMonGender(&gPlayerParty[gEggHatchData->eggPartyID]);
personality = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0);
GetMonNick(&gPlayerParty[sEggHatchData->eggPartyID], gStringVar3);
species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES);
gender = GetMonGender(&gPlayerParty[sEggHatchData->eggPartyID]);
personality = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_PERSONALITY, 0);
DoNamingScreen(3, gStringVar3, species, gender, personality, EggHatchSetMonNickname);
break;
case 1:
case -1:
gEggHatchData->CB2_state++;
sEggHatchData->CB2_state++;
}
break;
case 11:
BeginNormalPaletteFade(-1, 0, 0, 0x10, 0);
gEggHatchData->CB2_state++;
sEggHatchData->CB2_state++;
break;
case 12:
if (!gPaletteFade.active)
{
sub_805F094();
RemoveWindow(gEggHatchData->windowId);
RemoveWindow(sEggHatchData->windowId);
UnsetBgTilemapBuffer(0);
UnsetBgTilemapBuffer(1);
Free(gEggHatchData);
Free(sEggHatchData);
SetMainCallback2(c2_exit_to_overworld_2_switch);
}
break;
@ -561,9 +761,9 @@ static void SpriteCB_Egg_2(struct Sprite* sprite)
sprite->callback = SpriteCB_Egg_3;
sprite->data0 = 0;
species = GetMonData(&gPlayerParty[gEggHatchData->eggPartyID], MON_DATA_SPECIES);
gSprites[gEggHatchData->pokeSpriteID].pos2.x = 0;
gSprites[gEggHatchData->pokeSpriteID].pos2.y = 0;
species = GetMonData(&gPlayerParty[sEggHatchData->eggPartyID], MON_DATA_SPECIES);
gSprites[sEggHatchData->pokeSpriteID].pos2.x = 0;
gSprites[sEggHatchData->pokeSpriteID].pos2.y = 0;
}
else
{
@ -615,13 +815,13 @@ static void SpriteCB_Egg_5(struct Sprite* sprite)
{
if (sprite->data0 == 0)
{
gSprites[gEggHatchData->pokeSpriteID].invisible = 0;
StartSpriteAffineAnim(&gSprites[gEggHatchData->pokeSpriteID], 1);
gSprites[sEggHatchData->pokeSpriteID].invisible = 0;
StartSpriteAffineAnim(&gSprites[sEggHatchData->pokeSpriteID], 1);
}
if (sprite->data0 == 8)
BeginNormalPaletteFade(-1, -1, 0x10, 0, 0xFFFF);
if (sprite->data0 <= 9)
gSprites[gEggHatchData->pokeSpriteID].pos1.y -= 1;
gSprites[sEggHatchData->pokeSpriteID].pos1.y -= 1;
if (sprite->data0 > 40)
sprite->callback = SpriteCallbackDummy;
sprite->data0++;
@ -641,24 +841,20 @@ static void SpriteCB_EggShard(struct Sprite* sprite)
DestroySprite(sprite);
}
extern const s16 sEggShardVelocities[][2];
static void CreateRandomEggShardSprite(void)
{
u16 spriteAnimIndex;
s16 velocity1 = sEggShardVelocities[gEggHatchData->eggShardVelocityID][0];
s16 velocity2 = sEggShardVelocities[gEggHatchData->eggShardVelocityID][1];
gEggHatchData->eggShardVelocityID++;
s16 velocity1 = sEggShardVelocities[sEggHatchData->eggShardVelocityID][0];
s16 velocity2 = sEggShardVelocities[sEggHatchData->eggShardVelocityID][1];
sEggHatchData->eggShardVelocityID++;
spriteAnimIndex = Random() % 4;
CreateEggShardSprite(120, 60, velocity1, velocity2, 100, spriteAnimIndex);
}
extern const struct SpriteTemplate gUnknown_0832C04C;
static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8 spriteAnimIndex)
{
u8 spriteID = CreateSprite(&gUnknown_0832C04C, x, y, 4);
u8 spriteID = CreateSprite(&sSpriteTemplate_EggShard, x, y, 4);
gSprites[spriteID].data1 = data1;
gSprites[spriteID].data2 = data2;
gSprites[spriteID].data3 = data3;
@ -668,8 +864,30 @@ static void CreateEggShardSprite(u8 x, u8 y, s16 data1, s16 data2, s16 data3, u8
static void EggHatchPrintMessage(u8 windowId, u8* string, u8 x, u8 y, u8 speed)
{
FillWindowPixelBuffer(windowId, 0xFF);
gEggHatchData->textColor.fgColor = 0;
gEggHatchData->textColor.bgColor = 5;
gEggHatchData->textColor.shadowColor = 6;
AddTextPrinterParametrized2(windowId, 1, x, y, 0, 0, &gEggHatchData->textColor, speed, string);
sEggHatchData->textColor.fgColor = 0;
sEggHatchData->textColor.bgColor = 5;
sEggHatchData->textColor.shadowColor = 6;
AddTextPrinterParametrized2(windowId, 1, x, y, 0, 0, &sEggHatchData->textColor, speed, string);
}
u8 GetEggStepsToSubtract(void)
{
u8 count, i;
for (count = CalculatePlayerPartyCount(), i = 0; i < count; i++)
{
if (!GetMonData(&gPlayerParty[i], MON_DATA_SANITY_BIT3))
{
u8 ability = GetMonAbility(&gPlayerParty[i]);
if (ability == ABILITY_MAGMA_ARMOR || ability == ABILITY_FLAME_BODY)
return 2;
}
}
return 1;
}
u16 sub_80722E0(void)
{
u16 value = sub_80D22D0();
value += sub_80C7050(6);
return value;
}

View File

@ -1,4 +1,5 @@
#include "global.h"
#include "gpu_regs.h"
#define GPU_REG_BUF_SIZE 0x60
@ -14,14 +15,15 @@ static bool8 sShouldSyncRegIE;
static u16 sRegIE;
static void CopyBufferedValueToGpuReg(u8 regOffset);
static void SyncRegIE();
static void SyncRegIE(void);
static void UpdateRegDispstatIntrBits(u16 regIE);
void InitGpuRegManager()
void InitGpuRegManager(void)
{
s32 i;
for (i = 0; i < GPU_REG_BUF_SIZE; i++) {
for (i = 0; i < GPU_REG_BUF_SIZE; i++)
{
sGpuRegBuffer[i] = 0;
sGpuRegWaitingList[i] = EMPTY_SLOT;
}
@ -33,20 +35,25 @@ void InitGpuRegManager()
static void CopyBufferedValueToGpuReg(u8 regOffset)
{
if (regOffset == REG_OFFSET_DISPSTAT) {
if (regOffset == REG_OFFSET_DISPSTAT)
{
REG_DISPSTAT &= ~(DISPSTAT_HBLANK_INTR | DISPSTAT_VBLANK_INTR);
REG_DISPSTAT |= GPU_REG_BUF(REG_OFFSET_DISPSTAT);
} else {
}
else
{
GPU_REG(regOffset) = GPU_REG_BUF(regOffset);
}
}
void CopyBufferedValuesToGpuRegs()
void CopyBufferedValuesToGpuRegs(void)
{
if (!sGpuRegBufferLocked) {
if (!sGpuRegBufferLocked)
{
s32 i;
for (i = 0; i < GPU_REG_BUF_SIZE; i++) {
for (i = 0; i < GPU_REG_BUF_SIZE; i++)
{
u8 regOffset = sGpuRegWaitingList[i];
if (regOffset == EMPTY_SLOT)
return;
@ -135,7 +142,7 @@ void ClearGpuRegBits(u8 regOffset, u16 mask)
SetGpuReg(regOffset, regValue & ~mask);
}
static void SyncRegIE()
static void SyncRegIE(void)
{
if (sShouldSyncRegIE) {
u16 temp = REG_IME;

View File

@ -1,9 +1,6 @@
#include "global.h"
#include "trig.h"
// Converts a number to Q8.8 fixed-point format
#define Q_8_8(n) ((s16)((n) * 256))
// Converts a number to Q4.12 fixed-point format
#define Q_4_12(n) ((s16)((n) * 4096))

View File

@ -113,8 +113,9 @@ gUnknown_03000DD8: @ 3000DD8
gUnknown_03000DDC: @ 3000DDC
.space 0x4
gEggHatchData: @ 3000DE0
.space 0x8
.include "src/egg_hatch.o"
.space 0x4 @ why the gap?
gUnknown_03000DE8: @ 3000DE8
.space 0x10