Alchemy
Loading...
Searching...
No Matches

title.c

Go to the documentation of this file.
1/// @file
2/// The title overlay: the Golden Sun logo and its sprites revealed over the
3/// title screen.
4
5#include "game_state.h"
6#include "vram_tab.h"
7#include "unit/menu/title.h"
10#include "unit/game/game.h"
12#include "unit/window/window.h"
15#include "battle.h"
16#include "keystate.h"
17#include "debug.h"
18#include "field.h"
19#include "game.h"
20#include "graphics.h"
21#include "menu.h"
22#include "minigame.h"
23#include "sound.h"
24#include "system.h"
25#include "callback_scheduler.h"
26#include "resource.h"
27#include "global_cells.h"
28#include "types.h"
29#include "save_state.h"
30#include "mem.h"
31#include "field_event.h"
32#include "field_service.h"
33#include "scene_ids.h"
34#include "resource_ids.h"
35#include "title.h"
36#include "dma.h"
37#include "io_write_queue.h"
38#include "io_reg.h"
39#include "vram_block.h"
40#include "ram_buffer.h"
41#include "field_scene.h"
42#include "map_scroll.h"
43#include "songs.h"
44
45static void Title_RevealScreen(s32 unused);
46static void Title_LoadBackground(void);
47
49
50s32 SceneData_ReturnZero(void) { return 0; }
51
52u8 *Title_GetExits(void) { return (u8 *)gTitleExits; }
53
54/// The title overlay has no placed field actors.
56
57/// The title overlay has no field events.
58u8 *Title_GetEvents(void) { return (u8 *)gTitleEvents; }
59
60/// Routes the logo, completion presentation and new-game title entrances.
62 s32 waitFrames;
63
64 // Play the logo entrance until input or the one-minute timeout.
65 if (gGameState.entrance == 10) {
69 Engine_TaskWait(120);
70 waitFrames = 0;
71 if (gKeysPressed == 0) {
72 do {
74 if (++waitFrames > 3599)
75 break;
76 } while (gKeysPressed == 0);
77 }
79 return 0;
80 }
81 // Finish the completion presentation before entering the clear overlay.
82 if (gGameState.entrance == 9) {
86 Fade_ToBlack(60);
87 Fade_Wait();
91 return 0;
92 }
94 // Returning from the logo may repeat the splash and save-selection flow.
95 if (gGameState.entrance == 2) {
96 for (;;) {
100 if (SaveState_ScanRecordFlags() > 0) {
102 if (PaletteFar_Entry00(1) == 0) {
104 Fade_ToBlack(30);
105 Fade_Wait();
106 waitFrames = 0;
107 if (gKeysHeld == 0) {
108 do {
110 if (++waitFrames > 119)
111 break;
112 } while (gKeysHeld == 0);
113 }
114 continue;
115 }
116 }
117 break;
118 }
120 } else {
126 }
128 Fade_ToBlack(30);
129 Fade_Wait();
132 return 0;
133}
134
135/// Decodes the language-specific title sprites and uploads their palette and
136/// tiles.
137static void Title_LoadSprites(s32 unused) {
138 u8 *decodedSprites;
139 volatile u32 *dma3;
140#if (LANGUAGE == LANGUAGE_GERMAN) || (LANGUAGE == LANGUAGE_SPANISH) || \
141 (LANGUAGE == LANGUAGE_FRENCH) || (LANGUAGE == LANGUAGE_ITALIAN)
142 u8 *encodedGraphics;
143
144 decodedSprites = Runtime_BumpAllocateAlternatePool(0x9600);
146 if (gTitleVramBlock == -1)
148 Dma_Set(encodedGraphics, (void *)OBJ_PLTT,
149 (DMA_ENABLE | DMA_32BIT) << 16 | 0x70, REG_DMA3);
150 encodedGraphics += 0x1c0;
151 FieldResource_DecodeType01(encodedGraphics, decodedSprites);
152 Vram_Load(gTitleVramBlock, 0x1e00, decodedSprites + 0x7800);
153#else
154 decodedSprites = Runtime_BumpAllocateAlternatePool(0x520);
155 if (gTitleVramBlock == -1)
159 Dma_Set(decodedSprites, (void *)&OBJ_PLTT_COLOR(15, 0),
160 (DMA_ENABLE | DMA_32BIT) << 16 | 8, REG_DMA3);
161 Vram_Load(gTitleVramBlock, 0x500, decodedSprites + 32);
162#endif
163 // Wait for the final DMA transfer before releasing the decode buffer.
164 dma3 = REG_DMA3;
165 while (dma3[2] & (DMA_ENABLE << 16))
166 ;
167 MemFree(decodedSprites);
168}
169
170/// Reveals successive sprite columns, flickering each newly reached column.
171static void Title_UpdateSpriteReveal(void) {
172 u32 *attributes;
173 struct TitleSprite *sprite;
174 s32 tileIndex;
175 s32 column;
176 s32 revealAge;
177 s32 screenY;
178#if (LANGUAGE == LANGUAGE_JAPANESE) || (LANGUAGE == LANGUAGE_ENGLISH)
179 s32 screenX;
180#endif
181#if (LANGUAGE == LANGUAGE_GERMAN) || (LANGUAGE == LANGUAGE_SPANISH) || \
182 (LANGUAGE == LANGUAGE_FRENCH) || (LANGUAGE == LANGUAGE_ITALIAN)
183 s32 row;
184
185 sprite = gTitleSprites;
186 attributes = gTitleSprites[0].attr;
187 tileIndex = gVramBlockCache[gTitleVramBlock].offset >> 5;
188 row = 0;
189 screenY = 128;
190 for (; row <= 3; row++) {
191 for (column = 0; column <= 29; column++) {
192#ifdef UBFIX
193 // Stay inside each sprite's three-word array instead of walking into
194 // the next struct. The English indexed form adds four native bytes.
195 attributes = sprite->attr;
196#endif
197 *attributes++ = 0;
198 *attributes++ = (column * 8 << 16) | screenY | 0x2400;
199 *attributes++ = tileIndex;
200 revealAge = gTitleRevealFrame / 2 - column;
201 if (revealAge < 0)
202 revealAge = 0;
203 if (revealAge <= 2 && (gFrameCount & 1))
204 revealAge = 0;
205 if (revealAge != 0)
206 Runtime_PushSlotEntry(sprite, 255);
207 sprite++;
208 tileIndex += 2;
209 }
210 screenY += 8;
211 }
212#else
213
214 sprite = gTitleSprites;
215 attributes = gTitleSprites[0].attr;
216 tileIndex = gVramBlockCache[gTitleVramBlock].offset >> 5;
217 column = 0;
218 screenY = 0x88;
219 do {
220 screenX = 232 - (18 - column) * 8;
221#ifdef UBFIX
222 attributes = gTitleSprites[column].attr;
223#endif
224 *attributes++ = 0;
225 *attributes++ = (screenX << 16) | screenY | 0x8400;
226 *attributes++ = 0xf000 | tileIndex;
227 revealAge = gTitleRevealFrame / 2 - column;
228 if (revealAge < 0)
229 revealAge = 0;
230 if (revealAge <= 2 && (gFrameCount & 1))
231 revealAge = 0;
232 if (revealAge != 0)
233 Runtime_PushSlotEntry(sprite++, 255);
234 tileIndex += 2;
235 } while (++column <= 17);
236#endif
238}
239
240/// Prepares the logo, reveals its sprites and then opens the screen transition.
241static void Title_RevealScreen(s32 unused) {
242 s32 brightnessStep;
243
244 // Load while dark, then let the sprite callback reveal the lettering.
250 // Show BG0, BG2 and the sprites, with BG1 to BG3 darkened to black over
251 // the other layers and the backdrop.
255 0x20000);
261 0x20000);
262 IO_WRITE_QUEUE_PUSH((u32)&REG_BLDY, 16, 0x20000);
263 IO_WRITE_QUEUE_PUSH((u32)&REG_BLDALPHA, BLEND_ALPHA(16, 16), 0x20000);
264 Engine_EventWait(120);
265 // Remove the darkening in three-frame steps.
266 for (brightnessStep = 0; brightnessStep <= 16; brightnessStep++) {
267 IO_WRITE_QUEUE_PUSH((u32)&REG_BLDY, 16 - brightnessStep, 0x20000);
269 }
270 // Open immediately here and restore the normal transition duration.
276}
277
278/// Loads the logo palette and tiles, builds its tilemap and resets scrolling.
279static void Title_LoadBackground(void) {
280 u8 *encodedGraphics;
281 s32 resourceId;
282 u16 *tilemap;
283 u32 screenX;
284 u32 screenY;
285 u16 tileIndex;
286 struct ScrollPair *bgScroll;
287 s32 blankTile;
288
289 resourceId = (s32)&ResourceId_GoldenSunLogo;
290 Fade_ToBlack(0);
292 gBgScroll[2].y = 0;
293 blankTile = LOGO_BLANK_TILE;
294 encodedGraphics = Resource_GetTableEntry(resourceId);
295 Dma_Set(encodedGraphics, (void *)BG_PLTT,
296 (DMA_ENABLE | DMA_32BIT) << 16 | 0x70, REG_DMA3);
297 encodedGraphics += 0x1c0;
300 (DMA_ENABLE | DMA_32BIT) << 16 | 0x2580, REG_DMA3);
301 // Fill the visible 30 columns and pad each 32-entry tilemap row.
302 tilemap = LOGO_MAP;
303 tileIndex = LOGO_FIRST_TILE;
304 for (screenY = 0; screenY <= 19; screenY++) {
305 for (screenX = 0; screenX <= 29; screenX++)
306 *tilemap++ = tileIndex++;
307 *tilemap++ = blankTile;
308 *tilemap++ = blankTile;
309 }
310 // Reset all four background scroll pairs before enabling BG2 and sprites.
311 bgScroll = (struct ScrollPair *)gBgScroll;
312 for (screenY = 0; screenY <= 3; screenY++) {
313 bgScroll->y = 0;
314 bgScroll->x = 0;
315 bgScroll++;
316 }
318 ((struct MapScrollWork *)gMapWork[0])->flags =
320}
321
323 {0, CONDITION_ALWAYS, 0, 0, 0, FACING_SOUTH, 0, -1, -1, -1, -1, 0},
325};
326
328 SCENE_EXITS(511),
329};
330
333};
334
337};
338
struct FieldActor * Object_GetById(s32 actor)
Returns an actor, or NULL if it does not exist.
The task scheduler: tasks, their order and the scheduler's state.
The engine calls the debug menus import, and their palette swatch tiles.
DMA channel registers, and the DMA and CPU fills.
static __inline__ void Dma_Set(const volatile void *source, volatile void *destination, u32 control, volatile u32 *channel)
Starts a DMA transfer: stores the source, destination and control words into channel's registers with...
Definition dma.h:62
static s32 FieldScheduler_AddCallback(SchedulerCallback callback, s32 priority)
Registers a main-image scheduler callback.
Definition engine_call.h:36
static s32 FieldResource_DecodeType01(const void *source, void *destination)
Decodes type-01 compressed data.
Definition engine_call.h:90
void Fade_ToBlack(s32 frames)
Fades out to black.
Definition fade.c:76
void Fade_Wait(void)
Waits a frame at a time until the running fade has finished.
Definition fade.c:108
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
void Engine_EventWaitForScreen(void)
void Engine_EventOpenScreen(void)
void Engine_EventWait(s32 frames)
The scene table formats: entrances, exits, placements and events, and the macros that write them.
#define SCENE_EVENTS_END
#define SCENE_EXITS(scene)
Definition field_scene.h:72
@ SCENE_TABLE_END
Definition field_scene.h:43
@ CONDITION_ALWAYS
Definition field_scene.h:44
@ FACING_SOUTH
Definition field_scene.h:28
The scene service layer: one typed inline for each engine service a scene calls by its own name,...
static s32 Vram_Load(s32 block, s32 size, const void *data)
volatile u32 gFrameCount
Frames WaitFrames has finished.
GameState, the game's state: play time, coins, the scene and the leader's position,...
struct GameState gGameState
The work slots of gWorkSlot, read through their own names.
void * gMapWork[]
The screen blend's globals and the graphics routines.
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
Definition heap.c:140
s32 Title_ShowSplashScreen(s32 mode)
Shows the Nintendo logo with its jingle.
Definition intro.c:517
The hardware's I/O registers and their bits, as pret names them.
#define BLDCNT_TGT2_BG2
Definition io_reg.h:136
#define BLDCNT_TGT1_BG3
Definition io_reg.h:126
#define OBJ_PLTT
Definition io_reg.h:159
#define REG_BG0HOFS
Definition io_reg.h:149
#define BLDCNT_TGT1_BG2
Definition io_reg.h:125
#define BLDCNT_EFFECT_DARKEN
towards black by REG_BLDY
Definition io_reg.h:133
#define REG_BLDY
Definition io_reg.h:146
@ DISPCNT_OBJ_ON
Definition io_reg.h:44
@ DISPCNT_BG0_ON
Definition io_reg.h:40
@ DISPCNT_OBJ_1D_MAP
Definition io_reg.h:39
@ DISPCNT_BG2_ON
Definition io_reg.h:42
#define DMA_32BIT
Definition io_reg.h:210
#define REG_DISPCNT
Definition io_reg.h:9
#define BLDCNT_TGT2_BG0
Definition io_reg.h:134
#define OBJ_PLTT_COLOR(palette, color)
Definition io_reg.h:160
#define BLDCNT_TGT2_BG1
Definition io_reg.h:135
#define REG_DMA3
Definition io_reg.h:153
#define BLDCNT_TGT2_BG3
Definition io_reg.h:137
#define BLEND_ALPHA(top, bottom)
A REG_BLDALPHA value: top and bottom are the two targets' weights, out of 16.
Definition io_reg.h:145
#define BLDCNT_TGT1_BG1
Definition io_reg.h:124
#define REG_BG2CNT
Definition io_reg.h:21
#define REG_BLDALPHA
Definition io_reg.h:142
#define BG_PLTT
Definition io_reg.h:157
#define REG_BLDCNT
Definition io_reg.h:119
#define DMA_ENABLE
Definition io_reg.h:217
#define BLDCNT_TGT2_BD
Definition io_reg.h:139
The register write queue that VBlank carries out after each finished frame.
#define IO_WRITE_QUEUE_PUSH(address, value, control)
Disables interrupts to add one register write or DMA to the queue; a write to a full queue is dropped...
The keypad state the VBlank interrupt keeps.
volatile u32 gKeysHeld
Keys down now.
volatile u32 gKeysPressed
Keys that went down this frame.
s32 SceneData_ReturnZero(void)
Definition level.c:51
The map layers' scroll work and the background scroll values.
struct BgScroll gBgScroll[]
The heaps: allocating and freeing blocks.
void MemFree(void *buffer)
void PaletteFar_Entry20(s32 mode)
s32 PaletteFar_Entry00(s32 mode)
void ScrollFar_Entry00(s32 mode)
The reel game's title lettering.
void Event_SetDestination(s32 scene, s32 entrance)
Makes the event leave for the given entrance of the given scene: raises the exit request 999 and writ...
Definition events.c:517
The work pointers in the gWorkSlot table, by name.
#define Ram_MapCellBuffer
Definition ram_buffer.h:10
void Runtime_PushSlotEntry(void *slotEntry, s32 slot)
Links a sprite entry into depth slot slot (clamped to 0..255) for this frame.
Definition render.c:79
Resource numbers, named where their contents are known.
char ResourceId_GoldenSunLogo
char ResourceId_PaletteFarCalls
char ResourceId_IntroTilesB
The save workspace: slot headers and summaries.
Scene numbers, named after their places.
char SceneId_Title
char SceneId_Clear
char SceneId_Vale
Song and sound effect ids, indices into gSound_SongTable.
#define MUS_064
Definition songs.h:68
#define MUS_017
Definition songs.h:27
#define MUS_075
Definition songs.h:77
#define MUS_019
Definition songs.h:29
#define MUS_067
Definition songs.h:70
#define MUS_070
Definition songs.h:72
struct EventWork * gEventWork
void Engine_AudioPlayCue()
void Engine_TaskWait()
#define LOGO_MAP
Definition title.h:18
s16 gTitleRevealFrame
struct TitleSprite gTitleSprites[]
#define LOGO_FIRST_TILE
Definition title.h:19
#define LOGO_BLANK_TILE
The map entry after each row's 30 visible tiles.
Definition title.h:22
#define LOGO_BGCNT
Definition title.h:17
#define LOGO_TILES
Definition title.h:20
u16 y
pixels
Definition map_scroll.h:65
s32 startTransition
SCENE_TRANSITION(style, variant).
Definition event_work.h:43
s32 transitionFrames
frames
Definition event_work.h:45
u8 motionFlags
ActorMotionFlag bits; zero is free flight in 3D, and 3 is set on creation.
Definition field_obj.h:83
s16 entrance
Definition game_state.h:37
s32 selectedActor
the leader: its unit and its actor
Definition game_state.h:59
The field map's work: the followed position, screen shake, tile animations, blend script,...
Definition map_scroll.h:27
u16 flags
REG_DISPCNT bits: objects and the BG1 to BG3 shown.
Definition map_scroll.h:35
A scene entrance: where and facing which way the party arrives, and the camera's bounds there (-1 for...
Definition field_scene.h:54
A scene event: its kind and detail, the trigger it answers, its condition and its value (a message or...
An actor a scene places: its sprite, the condition for placing it, how it behaves,...
Definition field_scene.h:81
A background's horizontal and vertical scroll offsets.
Definition menu.h:39
u16 x
pixels
Definition menu.h:40
u16 y
pixels
Definition menu.h:41
The title overlay's sprite records, three OAM words each.
Definition title.h:7
u32 attr[3]
Definition title.h:8
u16 offset
bytes from the start of OBJ VRAM
Definition vram_tab.h:25
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
Definition system.c:150
void RuntimeDispatch_NoOpHook(s32 unused)
An exported stub that does nothing with its argument.
Definition system.c:146
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
u8 * Title_GetExits(void)
Definition title.c:52
u8 * Title_GetEntrances(void)
Definition title.c:48
struct SceneEntrance gTitleEntrances[]
Definition title.c:322
s32 Title_Run(void)
Routes the logo, completion presentation and new-game title entrances.
Definition title.c:61
static void Title_LoadSprites(s32 unused)
Decodes the language-specific title sprites and uploads their palette and tiles.
Definition title.c:137
struct SceneEvent gTitleEvents[]
Definition title.c:335
s16 gTitleVramBlock
Definition title.c:339
u8 * Title_GetPlacements(void)
The title overlay has no placed field actors.
Definition title.c:55
u8 * Title_GetEvents(void)
The title overlay has no field events.
Definition title.c:58
static void Title_UpdateSpriteReveal(void)
Reveals successive sprite columns, flickering each newly reached column.
Definition title.c:171
static void Title_LoadBackground(void)
Loads the logo palette and tiles, builds its tilemap and resets scrolling.
Definition title.c:279
static void Title_RevealScreen(s32 unused)
Prepares the logo, reveals its sprites and then opens the screen transition.
Definition title.c:241
u32 gTitleExits[]
Definition title.c:327
struct ScenePlacement gTitlePlacements[]
Definition title.c:331
The integer types, TRUE, UNUSED and the fixed-address macros.
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
unsigned char u8
Definition types.h:11
void Party_EndChildhood(void)
The party set-up after the prologue: flags, Jenna recomputed, Isaac and Garet healed with the Machete...
Definition units.c:619
Declares nothing of its own: it only includes the window, battle command, resource and VRAM table hea...
s32 Resource_FindFreeEntry(void)
Returns the number of the first free cache entry, or VRAM_CACHE_ENTRY_COUNT when all are taken.
Definition vram_cache.c:211
The sprite VRAM block cache and its owners.
struct VramBlockCacheEntry gVramBlockCache[]
s32 SaveState_ScanRecordFlags(void)
Loads the save file summaries for the title menu and returns how many files there are: plus 100 when ...
Definition save.c:111