Document wallclock data

This commit is contained in:
GriffinR 2020-08-29 15:50:23 -04:00
parent 09cfed64b5
commit 778bdb4d30
10 changed files with 249 additions and 280 deletions

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 204 B

After

Width:  |  Height:  |  Size: 204 B

View File

@ -3180,11 +3180,12 @@ extern const u32 gDecorIconPalette_RegiceDoll[];
extern const u32 gDecorIcon_RegisteelDoll[];
extern const u32 gDecorIconPalette_RegisteelDoll[];
extern const u32 gWallclock_Gfx[];
extern const u16 gWallclockMale_Pal[];
extern const u16 gWallclockFemale_Pal[];
extern const u32 gUnknown_08DCC648[];
extern const u32 gUnknown_08DCC908[];
extern const u32 gWallClock_Gfx[];
extern const u16 gWallClockMale_Pal[];
extern const u16 gWallClockFemale_Pal[];
extern const u32 gWallClockStart_Tilemap[];
extern const u32 gWallClockView_Tilemap[];
extern const u32 gBerryFixGameboy_Gfx[];
extern const u32 gBerryFixGameboy_Tilemap[];
extern const u16 gBerryFixGameboy_Pal[];

View File

@ -1385,11 +1385,11 @@ const u16 gEasyChatMode_Pal[] = INCBIN_U16("graphics/easy_chat/mode.gbapal");
const u32 gEasyChatWindow_Gfx[] = INCBIN_U32("graphics/easy_chat/window.4bpp.lz"); // uses mode pal
const u32 gEasyChatWindow_Tilemap[] = INCBIN_U32("graphics/easy_chat/window.bin.lz");
const u16 gWallclockMale_Pal[] = INCBIN_U16("graphics/interface/wallclock_male.gbapal");
const u16 gWallclockFemale_Pal[] = INCBIN_U16("graphics/interface/wallclock_female.gbapal");
const u32 gWallclock_Gfx[] = INCBIN_U32("graphics/interface/wallclock.4bpp.lz");
const u32 gUnknown_08DCC648[] = INCBIN_U32("graphics/interface/wallclock1.bin.lz");
const u32 gUnknown_08DCC908[] = INCBIN_U32("graphics/interface/wallclock2.bin.lz");
const u16 gWallClockMale_Pal[] = INCBIN_U16("graphics/wallclock/male.gbapal");
const u16 gWallClockFemale_Pal[] = INCBIN_U16("graphics/wallclock/female.gbapal");
const u32 gWallClock_Gfx[] = INCBIN_U32("graphics/wallclock/clock.4bpp.lz");
const u32 gWallClockStart_Tilemap[] = INCBIN_U32("graphics/wallclock/clock_start.bin.lz");
const u32 gWallClockView_Tilemap[] = INCBIN_U32("graphics/wallclock/clock_view.bin.lz");
const u16 gUsePokeblockCondition_Pal[] = INCBIN_U16("graphics/pokeblock/use_screen/condition.gbapal");
const u32 gUsePokeblockCondition_Gfx[] = INCBIN_U32("graphics/pokeblock/use_screen/condition.4bpp.lz");

View File

@ -21,38 +21,37 @@
#include "constants/rgb.h"
#include "constants/songs.h"
// static declarations
static void WallClockMainCallback(void);
static void Task_SetClock1(u8 taskId);
static void Task_SetClock2(u8 taskId);
static void Task_SetClock3(u8 taskId);
static void Task_SetClock4(u8 taskId);
static void Task_SetClock5(u8 taskId);
static void Task_SetClock6(u8 taskId);
static void Task_ViewClock1(u8 taskId);
static void Task_ViewClock2(u8 taskId);
static void Task_ViewClock3(u8 taskId);
static void Task_ViewClock4(u8 taskId);
static void CB2_WallClock(void);
static void Task_SetClock_WaitFadeIn(u8 taskId);
static void Task_SetClock_HandleInput(u8 taskId);
static void Task_SetClock_AskConfirm(u8 taskId);
static void Task_SetClock_HandleConfirmInput(u8 taskId);
static void Task_SetClock_Confirmed(u8 taskId);
static void Task_SetClock_Exit(u8 taskId);
static void Task_ViewClock_WaitFadeIn(u8 taskId);
static void Task_ViewClock_HandleInput(u8 taskId);
static void Task_ViewClock_FadeOut(u8 taskId);
static void Task_ViewClock_Exit(u8 taskId);
static u16 CalcNewMinHandAngle(u16 angle, u8 direction, u8 speed);
static bool32 AdvanceClock(u8 taskId, u8 direction);
static void UpdateClockPeriod(u8 taskId, u8 direction);
static void InitClockWithRtc(u8 taskId);
static void SpriteCB_MinuteHand(struct Sprite *sprite);
static void SpriteCB_HourHand(struct Sprite *sprite);
static void SpriteCB_AMIndicator(struct Sprite *sprite);
static void SpriteCB_PMIndicator(struct Sprite *sprite);
static void SpriteCB_AMIndicator(struct Sprite *sprite);
#define tMinuteHandAngle data[0]
#define tHourHandAngle data[1]
#define tHours data[2]
#define tMinutes data[3]
#define tMvmtDir data[4]
#define tMoveDir data[4]
#define tPeriod data[5]
#define tMvmtSpeed data[6]
#define tMoveSpeed data[6]
#define TAG_GFX_WALL_CLOCK_HAND 0x1000
#define TAG_PAL_WALL_CLOCK_HAND 0x1000
#define GFXTAG_WALL_CLOCK_HAND 0x1000
#define PALTAG_WALL_CLOCK_MALE 0x1000
#define PALTAG_WALL_CLOCK_FEMALE 0x1001
enum
{
@ -62,17 +61,15 @@ enum
enum
{
MVMT_NONE,
MVMT_BACKWARD,
MVMT_FORWARD,
MOVE_NONE,
MOVE_BACKWARD,
MOVE_FORWARD,
};
// rodata
static const u32 sHand_Gfx[] = INCBIN_U32("graphics/wallclock/hand.4bpp.lz");
static const u16 sTextPrompt_Pal[] = INCBIN_U16("graphics/wallclock/text_prompt.gbapal"); // for "Cancel" or "Confirm"
static const u32 sUnknown_085B1F58[] = INCBIN_U32("graphics/wallclock/graphics_85b1f58.4bpp.lz");
static const u16 sUnknown_085B21D4[] = INCBIN_U16("graphics/wallclock/palette_85b21d4.gbapal");
static const struct WindowTemplate gUnknown_085B21DC[] =
static const struct WindowTemplate sWindowTemplates[] =
{
{
.bg = 0,
@ -95,7 +92,7 @@ static const struct WindowTemplate gUnknown_085B21DC[] =
DUMMY_WIN_TEMPLATE
};
static const struct WindowTemplate gUnknown_085B21F4 =
static const struct WindowTemplate sWindowTemplate_ConfirmYesNo =
{
.bg = 0,
.tilemapLeft = 24,
@ -106,7 +103,7 @@ static const struct WindowTemplate gUnknown_085B21F4 =
.baseBlock = 572
};
static const struct BgTemplate gUnknown_085B21FC[] =
static const struct BgTemplate sBgTemplates[] =
{
{
.bg = 0,
@ -128,27 +125,27 @@ static const struct BgTemplate gUnknown_085B21FC[] =
}
};
static const struct CompressedSpriteSheet gUnknown_085B2208 =
static const struct CompressedSpriteSheet sSpriteSheet_ClockHand =
{
sUnknown_085B1F58, 0x2000, TAG_GFX_WALL_CLOCK_HAND
sHand_Gfx, 0x2000, GFXTAG_WALL_CLOCK_HAND
};
static const u8 filler_85B2210[8] = {0};
static const u8 sUnused[8] = {0};
static const struct SpritePalette gUnknown_085B2218[] =
static const struct SpritePalette sSpritePalettes_Clock[] =
{
{
.data = gWallclockMale_Pal,
.tag = TAG_PAL_WALL_CLOCK_HAND
.data = gWallClockMale_Pal,
.tag = PALTAG_WALL_CLOCK_MALE
},
{
.data = gWallclockFemale_Pal,
.tag = 0x1001
.data = gWallClockFemale_Pal,
.tag = PALTAG_WALL_CLOCK_FEMALE
},
{}
};
static const struct OamData Unknown_085B2230 =
static const struct OamData sOam_ClockHand =
{
.y = 160,
.shape = SPRITE_SHAPE(64x64),
@ -156,51 +153,51 @@ static const struct OamData Unknown_085B2230 =
.priority = 1,
};
static const union AnimCmd Unknown_085B2238[] =
static const union AnimCmd sAnim_MinuteHand[] =
{
ANIMCMD_FRAME(0, 30),
ANIMCMD_END,
};
static const union AnimCmd Unknown_085B2240[] =
static const union AnimCmd sAnim_HourHand[] =
{
ANIMCMD_FRAME(64, 30),
ANIMCMD_END,
};
static const union AnimCmd *const gUnknown_085B2248[] =
static const union AnimCmd *const sAnims_MinuteHand[] =
{
Unknown_085B2238
sAnim_MinuteHand
};
static const union AnimCmd *const gUnknown_085B224C[] =
static const union AnimCmd *const sAnims_HourHand[] =
{
Unknown_085B2240
sAnim_HourHand
};
static const struct SpriteTemplate gUnknown_085B2250 =
static const struct SpriteTemplate sSpriteTemplate_MinuteHand =
{
.tileTag = TAG_GFX_WALL_CLOCK_HAND,
.paletteTag = TAG_PAL_WALL_CLOCK_HAND,
.oam = &Unknown_085B2230,
.anims = gUnknown_085B2248,
.tileTag = GFXTAG_WALL_CLOCK_HAND,
.paletteTag = PALTAG_WALL_CLOCK_MALE,
.oam = &sOam_ClockHand,
.anims = sAnims_MinuteHand,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_MinuteHand,
};
static const struct SpriteTemplate gUnknown_085B2268 =
static const struct SpriteTemplate sSpriteTemplate_HourHand =
{
.tileTag = TAG_GFX_WALL_CLOCK_HAND,
.paletteTag = TAG_PAL_WALL_CLOCK_HAND,
.oam = &Unknown_085B2230,
.anims = gUnknown_085B224C,
.tileTag = GFXTAG_WALL_CLOCK_HAND,
.paletteTag = PALTAG_WALL_CLOCK_MALE,
.oam = &sOam_ClockHand,
.anims = sAnims_HourHand,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_HourHand,
};
static const struct OamData Unknown_085B2280 =
static const struct OamData sOam_PeriodIndicator =
{
.y = 160,
.shape = SPRITE_SHAPE(16x16),
@ -208,50 +205,50 @@ static const struct OamData Unknown_085B2280 =
.priority = 3,
};
static const union AnimCmd Unknown_085B2288[] =
static const union AnimCmd sAnim_PM[] =
{
ANIMCMD_FRAME(132, 30),
ANIMCMD_END,
};
static const union AnimCmd Unknown_085B2290[] =
static const union AnimCmd sAnim_AM[] =
{
ANIMCMD_FRAME(128, 30),
ANIMCMD_END,
};
static const union AnimCmd *const gUnknown_085B2298[] =
static const union AnimCmd *const sAnims_PM[] =
{
Unknown_085B2288
sAnim_PM
};
static const union AnimCmd *const gUnknown_085B229C[] =
static const union AnimCmd *const sAnims_AM[] =
{
Unknown_085B2290
sAnim_AM
};
static const struct SpriteTemplate gUnknown_085B22A0 =
static const struct SpriteTemplate sSpriteTemplate_PM =
{
.tileTag = TAG_GFX_WALL_CLOCK_HAND,
.paletteTag = TAG_PAL_WALL_CLOCK_HAND,
.oam = &Unknown_085B2280,
.anims = gUnknown_085B2298,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_AMIndicator
};
static const struct SpriteTemplate gUnknown_085B22B8 =
{
.tileTag = TAG_GFX_WALL_CLOCK_HAND,
.paletteTag = TAG_PAL_WALL_CLOCK_HAND,
.oam = &Unknown_085B2280,
.anims = gUnknown_085B229C,
.tileTag = GFXTAG_WALL_CLOCK_HAND,
.paletteTag = PALTAG_WALL_CLOCK_MALE,
.oam = &sOam_PeriodIndicator,
.anims = sAnims_PM,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_PMIndicator
};
static const struct SpriteTemplate sSpriteTemplate_AM =
{
.tileTag = GFXTAG_WALL_CLOCK_HAND,
.paletteTag = PALTAG_WALL_CLOCK_MALE,
.oam = &sOam_PeriodIndicator,
.anims = sAnims_AM,
.images = NULL,
.affineAnims = gDummySpriteAffineAnimTable,
.callback = SpriteCB_AMIndicator
};
static const s8 sClockHandCoords[][2] =
{
{ 0x00, -0x18},
@ -616,9 +613,7 @@ static const s8 sClockHandCoords[][2] =
{ 0x00, -0x19}
};
// text
static void WallClockVblankCallback(void)
static void VBlankCB_WallClock(void)
{
LoadOam();
ProcessSpriteCopyRequests();
@ -644,20 +639,18 @@ static void LoadWallClockGraphics(void)
DmaFillLarge16(3, 0, (void *)VRAM, VRAM_SIZE, 0x1000);
DmaClear32(3, (void *)OAM, OAM_SIZE);
DmaClear16(3, (void *)PLTT, PLTT_SIZE);
LZ77UnCompVram(gWallclock_Gfx, (void *)VRAM);
if (gSpecialVar_0x8004 == 0)
{
LoadPalette(gWallclockMale_Pal, 0x00, 0x20);
}
LZ77UnCompVram(gWallClock_Gfx, (void *)VRAM);
if (gSpecialVar_0x8004 == MALE)
LoadPalette(gWallClockMale_Pal, 0, 32);
else
{
LoadPalette(gWallclockFemale_Pal, 0x00, 0x20);
}
LoadPalette(GetOverworldTextboxPalettePtr(), 0xe0, 0x20);
LoadPalette(sUnknown_085B21D4, 0xc0, 0x08);
LoadPalette(gWallClockFemale_Pal, 0, 32);
LoadPalette(GetOverworldTextboxPalettePtr(), 0xe0, 32);
LoadPalette(sTextPrompt_Pal, 0xc0, 8);
ResetBgsAndClearDma3BusyFlags(0);
InitBgsFromTemplates(0, gUnknown_085B21FC, 3);
InitWindows(gUnknown_085B21DC);
InitBgsFromTemplates(0, sBgTemplates, ARRAY_COUNT(sBgTemplates));
InitWindows(sWindowTemplates);
DeactivateAllTextPrinters();
LoadUserWindowBorderGfx(0, 0x250, 0xd0);
ClearScheduledBgCopiesToVram();
@ -666,16 +659,16 @@ static void LoadWallClockGraphics(void)
ResetSpriteData();
ResetPaletteFade();
FreeAllSpritePalettes();
LoadCompressedSpriteSheet(&gUnknown_085B2208);
LoadSpritePalettes(gUnknown_085B2218);
LoadCompressedSpriteSheet(&sSpriteSheet_ClockHand);
LoadSpritePalettes(sSpritePalettes_Clock);
}
static void WallClockInit(void)
{
BeginNormalPaletteFade(0xFFFFFFFF, 0, 16, 0, RGB_BLACK);
EnableInterrupts(INTR_FLAG_VBLANK);
SetVBlankCallback(WallClockVblankCallback);
SetMainCallback2(WallClockMainCallback);
SetVBlankCallback(VBlankCB_WallClock);
SetMainCallback2(CB2_WallClock);
SetGpuReg(REG_OFFSET_BLDCNT, 0);
SetGpuReg(REG_OFFSET_BLDALPHA, 0);
SetGpuReg(REG_OFFSET_BLDY, 0);
@ -691,32 +684,32 @@ void CB2_StartWallClock(void)
u8 spriteId;
LoadWallClockGraphics();
LZ77UnCompVram(gUnknown_08DCC648, (u16 *)BG_SCREEN_ADDR(7));
LZ77UnCompVram(gWallClockStart_Tilemap, (u16 *)BG_SCREEN_ADDR(7));
taskId = CreateTask(Task_SetClock1, 0);
taskId = CreateTask(Task_SetClock_WaitFadeIn, 0);
gTasks[taskId].tHours = 10;
gTasks[taskId].tMinutes = 0;
gTasks[taskId].tMvmtDir = 0;
gTasks[taskId].tMoveDir = 0;
gTasks[taskId].tPeriod = 0;
gTasks[taskId].tMvmtSpeed = 0;
gTasks[taskId].tMoveSpeed = 0;
gTasks[taskId].tMinuteHandAngle = 0;
gTasks[taskId].tHourHandAngle = 300;
spriteId = CreateSprite(&gUnknown_085B2250, 120, 80, 1);
spriteId = CreateSprite(&sSpriteTemplate_MinuteHand, 120, 80, 1);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
gSprites[spriteId].oam.matrixNum = 0;
spriteId = CreateSprite(&gUnknown_085B2268, 120, 80, 0);
spriteId = CreateSprite(&sSpriteTemplate_HourHand, 120, 80, 0);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
gSprites[spriteId].oam.matrixNum = 1;
spriteId = CreateSprite(&gUnknown_085B22A0, 120, 80, 2);
spriteId = CreateSprite(&sSpriteTemplate_PM, 120, 80, 2);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].data[1] = 45;
spriteId = CreateSprite(&gUnknown_085B22B8, 120, 80, 2);
spriteId = CreateSprite(&sSpriteTemplate_AM, 120, 80, 2);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].data[1] = 90;
@ -735,11 +728,11 @@ void CB2_ViewWallClock(void)
u8 angle2;
LoadWallClockGraphics();
LZ77UnCompVram(gUnknown_08DCC908, (u16 *)BG_SCREEN_ADDR(7));
LZ77UnCompVram(gWallClockView_Tilemap, (u16 *)BG_SCREEN_ADDR(7));
taskId = CreateTask(Task_ViewClock1, 0);
taskId = CreateTask(Task_ViewClock_WaitFadeIn, 0);
InitClockWithRtc(taskId);
if (gTasks[taskId].tPeriod == 0)
if (gTasks[taskId].tPeriod == PERIOD_AM)
{
angle1 = 45;
angle2 = 90;
@ -750,21 +743,21 @@ void CB2_ViewWallClock(void)
angle2 = 135;
}
spriteId = CreateSprite(&gUnknown_085B2250, 120, 80, 1);
spriteId = CreateSprite(&sSpriteTemplate_MinuteHand, 120, 80, 1);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
gSprites[spriteId].oam.matrixNum = 0;
spriteId = CreateSprite(&gUnknown_085B2268, 120, 80, 0);
spriteId = CreateSprite(&sSpriteTemplate_HourHand, 120, 80, 0);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].oam.affineMode = ST_OAM_AFFINE_NORMAL;
gSprites[spriteId].oam.matrixNum = 1;
spriteId = CreateSprite(&gUnknown_085B22A0, 120, 80, 2);
spriteId = CreateSprite(&sSpriteTemplate_PM, 120, 80, 2);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].data[1] = angle1;
spriteId = CreateSprite(&gUnknown_085B22B8, 120, 80, 2);
spriteId = CreateSprite(&sSpriteTemplate_AM, 120, 80, 2);
gSprites[spriteId].data[0] = taskId;
gSprites[spriteId].data[1] = angle2;
@ -775,7 +768,7 @@ void CB2_ViewWallClock(void)
ScheduleBgCopyTilemapToVram(2);
}
static void WallClockMainCallback(void)
static void CB2_WallClock(void)
{
RunTasks();
AnimateSprites();
@ -784,19 +777,19 @@ static void WallClockMainCallback(void)
UpdatePaletteFade();
}
static void Task_SetClock1(u8 taskId)
static void Task_SetClock_WaitFadeIn(u8 taskId)
{
if (!gPaletteFade.active)
{
gTasks[taskId].func = Task_SetClock2;
gTasks[taskId].func = Task_SetClock_HandleInput;
}
}
static void Task_SetClock2(u8 taskId)
static void Task_SetClock_HandleInput(u8 taskId)
{
if (gTasks[taskId].tMinuteHandAngle % 6)
{
gTasks[taskId].tMinuteHandAngle = CalcNewMinHandAngle(gTasks[taskId].tMinuteHandAngle, gTasks[taskId].tMvmtDir, gTasks[taskId].tMvmtSpeed);
gTasks[taskId].tMinuteHandAngle = CalcNewMinHandAngle(gTasks[taskId].tMinuteHandAngle, gTasks[taskId].tMoveDir, gTasks[taskId].tMoveSpeed);
}
else
{
@ -804,72 +797,70 @@ static void Task_SetClock2(u8 taskId)
gTasks[taskId].tHourHandAngle = (gTasks[taskId].tHours % 12) * 30 + (gTasks[taskId].tMinutes / 10) * 5;
if (gMain.newKeys & A_BUTTON)
{
gTasks[taskId].func = Task_SetClock3;
gTasks[taskId].func = Task_SetClock_AskConfirm;
}
else
{
gTasks[taskId].tMvmtDir = 0;
gTasks[taskId].tMoveDir = MOVE_NONE;
if (gMain.heldKeys & DPAD_LEFT)
{
gTasks[taskId].tMvmtDir = MVMT_BACKWARD;
}
gTasks[taskId].tMoveDir = MOVE_BACKWARD;
if (gMain.heldKeys & DPAD_RIGHT)
gTasks[taskId].tMoveDir = MOVE_FORWARD;
if (gTasks[taskId].tMoveDir != MOVE_NONE)
{
gTasks[taskId].tMvmtDir = MVMT_FORWARD;
}
if (gTasks[taskId].tMvmtDir != 0)
{
if (gTasks[taskId].tMvmtSpeed < 0xFF)
{
gTasks[taskId].tMvmtSpeed++;
}
gTasks[taskId].tMinuteHandAngle = CalcNewMinHandAngle(gTasks[taskId].tMinuteHandAngle, gTasks[taskId].tMvmtDir, gTasks[taskId].tMvmtSpeed);
AdvanceClock(taskId, gTasks[taskId].tMvmtDir);
if (gTasks[taskId].tMoveSpeed < 0xFF)
gTasks[taskId].tMoveSpeed++;
gTasks[taskId].tMinuteHandAngle = CalcNewMinHandAngle(gTasks[taskId].tMinuteHandAngle, gTasks[taskId].tMoveDir, gTasks[taskId].tMoveSpeed);
AdvanceClock(taskId, gTasks[taskId].tMoveDir);
}
else
{
gTasks[taskId].tMvmtSpeed = 0;
gTasks[taskId].tMoveSpeed = 0;
}
}
}
}
static void Task_SetClock3(u8 taskId)
static void Task_SetClock_AskConfirm(u8 taskId)
{
DrawStdFrameWithCustomTileAndPalette(0, FALSE, 0x250, 0x0d);
AddTextPrinterParameterized(0, 1, gText_IsThisTheCorrectTime, 0, 1, 0, NULL);
PutWindowTilemap(0);
ScheduleBgCopyTilemapToVram(0);
CreateYesNoMenu(&gUnknown_085B21F4, 0x250, 0x0d, 1);
gTasks[taskId].func = Task_SetClock4;
CreateYesNoMenu(&sWindowTemplate_ConfirmYesNo, 0x250, 0x0d, 1);
gTasks[taskId].func = Task_SetClock_HandleConfirmInput;
}
static void Task_SetClock4(u8 taskId)
static void Task_SetClock_HandleConfirmInput(u8 taskId)
{
switch (Menu_ProcessInputNoWrapClearOnChoose())
{
case 0: //YES
case 0: // YES
PlaySE(SE_SELECT);
gTasks[taskId].func = Task_SetClock5;
gTasks[taskId].func = Task_SetClock_Confirmed;
break;
case 1: //B button
case -1: //NO
case 1: // NO
case MENU_B_PRESSED:
PlaySE(SE_SELECT);
ClearStdWindowAndFrameToTransparent(0, FALSE);
ClearWindowTilemap(0);
gTasks[taskId].func = Task_SetClock2;
gTasks[taskId].func = Task_SetClock_HandleInput;
break;
}
}
static void Task_SetClock5(u8 taskId)
static void Task_SetClock_Confirmed(u8 taskId)
{
RtcInitLocalTimeOffset(gTasks[taskId].tHours, gTasks[taskId].tMinutes);
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = Task_SetClock6;
gTasks[taskId].func = Task_SetClock_Exit;
}
static void Task_SetClock6(u8 taskId)
static void Task_SetClock_Exit(u8 taskId)
{
if (!gPaletteFade.active)
{
@ -878,51 +869,40 @@ static void Task_SetClock6(u8 taskId)
}
}
static void Task_ViewClock1(u8 taskId)
static void Task_ViewClock_WaitFadeIn(u8 taskId)
{
if (!gPaletteFade.active)
{
gTasks[taskId].func = Task_ViewClock2;
}
gTasks[taskId].func = Task_ViewClock_HandleInput;
}
static void Task_ViewClock2(u8 taskId)
static void Task_ViewClock_HandleInput(u8 taskId)
{
InitClockWithRtc(taskId);
if (gMain.newKeys & (A_BUTTON | B_BUTTON))
{
gTasks[taskId].func = Task_ViewClock3;
}
gTasks[taskId].func = Task_ViewClock_FadeOut;
}
static void Task_ViewClock3(u8 taskId)
static void Task_ViewClock_FadeOut(u8 taskId)
{
BeginNormalPaletteFade(0xFFFFFFFF, 0, 0, 16, RGB_BLACK);
gTasks[taskId].func = Task_ViewClock4;
gTasks[taskId].func = Task_ViewClock_Exit;
}
static void Task_ViewClock4(u8 taskId)
static void Task_ViewClock_Exit(u8 taskId)
{
if (!gPaletteFade.active)
{
SetMainCallback2(gMain.savedCallback);
}
}
static u8 CalcMinHandDelta(u16 speed)
{
if (speed > 60)
{
return 6;
}
if (speed > 30)
{
return 3;
}
if (speed > 10)
{
return 2;
}
return 1;
}
@ -931,13 +911,13 @@ static u16 CalcNewMinHandAngle(u16 angle, u8 direction, u8 speed)
u8 delta = CalcMinHandDelta(speed);
switch (direction)
{
case MVMT_BACKWARD:
case MOVE_BACKWARD:
if (angle)
angle -= delta;
else
angle = 360 - delta;
break;
case MVMT_FORWARD:
case MOVE_FORWARD:
if (angle < 360 - delta)
angle += delta;
else
@ -951,7 +931,7 @@ static bool32 AdvanceClock(u8 taskId, u8 direction)
{
switch (direction)
{
case MVMT_BACKWARD:
case MOVE_BACKWARD:
if (gTasks[taskId].tMinutes > 0)
{
gTasks[taskId].tMinutes--;
@ -959,18 +939,16 @@ static bool32 AdvanceClock(u8 taskId, u8 direction)
else
{
gTasks[taskId].tMinutes = 59;
if (gTasks[taskId].tHours > 0)
{
gTasks[taskId].tHours--;
}
else
{
gTasks[taskId].tHours = 23;
}
UpdateClockPeriod(taskId, direction);
}
break;
case MVMT_FORWARD:
case MOVE_FORWARD:
if (gTasks[taskId].tMinutes < 59)
{
gTasks[taskId].tMinutes++;
@ -978,14 +956,12 @@ static bool32 AdvanceClock(u8 taskId, u8 direction)
else
{
gTasks[taskId].tMinutes = 0;
if (gTasks[taskId].tHours < 23)
{
gTasks[taskId].tHours++;
}
else
{
gTasks[taskId].tHours = 0;
}
UpdateClockPeriod(taskId, direction);
}
break;
@ -998,7 +974,7 @@ static void UpdateClockPeriod(u8 taskId, u8 direction)
u8 hours = gTasks[taskId].tHours;
switch (direction)
{
case MVMT_BACKWARD:
case MOVE_BACKWARD:
switch (hours)
{
case 11:
@ -1009,7 +985,7 @@ static void UpdateClockPeriod(u8 taskId, u8 direction)
break;
}
break;
case MVMT_FORWARD:
case MOVE_FORWARD:
switch (hours)
{
case 0:
@ -1030,14 +1006,11 @@ static void InitClockWithRtc(u8 taskId)
gTasks[taskId].tMinutes = gLocalTime.minutes;
gTasks[taskId].tMinuteHandAngle = gTasks[taskId].tMinutes * 6;
gTasks[taskId].tHourHandAngle = (gTasks[taskId].tHours % 12) * 30 + (gTasks[taskId].tMinutes / 10) * 5;
if (gLocalTime.hours < 12)
{
gTasks[taskId].tPeriod = PERIOD_AM;
}
else
{
gTasks[taskId].tPeriod = PERIOD_PM;
}
}
static void SpriteCB_MinuteHand(struct Sprite *sprite)
@ -1045,22 +1018,19 @@ static void SpriteCB_MinuteHand(struct Sprite *sprite)
u16 angle = gTasks[sprite->data[0]].tMinuteHandAngle;
s16 sin = Sin2(angle) / 16;
s16 cos = Cos2(angle) / 16;
u16 xhat, yhat;
u16 x, y;
SetOamMatrix(0, cos, sin, -sin, cos);
xhat = sClockHandCoords[angle][0];
yhat = sClockHandCoords[angle][1];
x = sClockHandCoords[angle][0];
y = sClockHandCoords[angle][1];
if (xhat > 0x80)
{
xhat |= 0xff00;
}
if (yhat > 0x80)
{
yhat |= 0xff00;
}
sprite->pos2.x = xhat;
sprite->pos2.y = yhat;
if (x > 128)
x |= 0xff00;
if (y > 128)
y |= 0xff00;
sprite->pos2.x = x;
sprite->pos2.y = y;
}
static void SpriteCB_HourHand(struct Sprite *sprite)
@ -1068,26 +1038,24 @@ static void SpriteCB_HourHand(struct Sprite *sprite)
u16 angle = gTasks[sprite->data[0]].tHourHandAngle;
s16 sin = Sin2(angle) / 16;
s16 cos = Cos2(angle) / 16;
u16 xhat, yhat;
u16 x, y;
SetOamMatrix(1, cos, sin, -sin, cos);
xhat = sClockHandCoords[angle][0];
yhat = sClockHandCoords[angle][1];
if (xhat > 0x80)
{
xhat |= 0xff00;
}
if (yhat > 0x80)
{
yhat |= 0xff00;
}
sprite->pos2.x = xhat;
sprite->pos2.y = yhat;
x = sClockHandCoords[angle][0];
y = sClockHandCoords[angle][1];
if (x > 128)
x |= 0xff00;
if (y > 128)
y |= 0xff00;
sprite->pos2.x = x;
sprite->pos2.y = y;
}
static void SpriteCB_AMIndicator(struct Sprite *sprite)
static void SpriteCB_PMIndicator(struct Sprite *sprite)
{
if (gTasks[sprite->data[0]].tPeriod)
if (gTasks[sprite->data[0]].tPeriod != PERIOD_AM)
{
if (sprite->data[1] >= 60 && sprite->data[1] < 90)
{
@ -1113,9 +1081,9 @@ static void SpriteCB_AMIndicator(struct Sprite *sprite)
sprite->pos2.y = Sin2(sprite->data[1]) * 30 / 0x1000;
}
static void SpriteCB_PMIndicator(struct Sprite *sprite)
static void SpriteCB_AMIndicator(struct Sprite *sprite)
{
if (gTasks[sprite->data[0]].tPeriod)
if (gTasks[sprite->data[0]].tPeriod != PERIOD_AM)
{
if (sprite->data[1] >= 105 && sprite->data[1] < 135)
{