Alchemy
Loading...
Searching...
No Matches

colosso_task.h

Go to the documentation of this file.
1#include "battle.h"
2#include "debug.h"
3#include "field.h"
4#include "game.h"
5#include "graphics.h"
6#include "menu.h"
7#include "minigame.h"
8#include "sound.h"
9#include "system.h"
10#include "affine.h"
11#include "vram_block.h"
12#include "callback_scheduler.h"
13#include "resource.h"
14#include "tbs_edition.h"
15#include "mem.h"
16#include "field_event.h"
17#include "field_service.h"
18#include "dma.h"
19#include "resource_ids.h"
20#include "call.h"
21#include "types.h"
22#include "io_reg.h"
23#include "io_write_queue.h"
24
25/// The Colosso finals' three courses (Colosso Log, River and Wall): the large
26/// lettering a race starts with. It reads "Match 1", "3", "2", "1", "Go!", from
27/// the pictures of games/tbs/src/graphics/colosso/lettering.tsv, in this order:
28/// 0 Lend a Hand, 1 to 3 Match 1 to 3, 4 Won and Lose, 5 the 3 and the 2,
29/// 6 the 1 and 7 Go. Each picture is 0x400 bytes of tiles after the palettes.
30///
31/// The lettering moves by a script of 16-bit words, a command and its values:
33 /// x, speed: put the lettering at x pixels from the centre, moving at speed
34 /// 256ths of a pixel a frame
36 /// speed, frames: change the speed over that many frames
38 /// scale, frames: grow or shrink to scale (256 is its own size)
40 /// weight, frames: fade to weight sixteenths over the screen
42 /// frames: run the moves for that many frames before the next command
44 /// remove the lettering and free its VRAM block
46};
47
48static __inline__ void Dma_Wait(volatile u32 *dma) {
49 while (dma[2] & 0x80000000)
50 ;
51}
52
53/// One lettering piece as queued for drawing: a header word, then its OAM
54/// attributes.
55struct Sprite {
57};
58
66
67/// Loads lettering picture id into the lettering's VRAM block (taken once) and
68/// its palette into sprite palette 15. Picture 8 is picture 4 in another
69/// palette.
70static void Colosso_LoadLettering(s32 id) {
71 u8 *buf;
72 s32 off;
73
75 if (gColosso_LetteringSlot == -1)
78 if (id == 8)
79 id = 4;
81 buf);
82 Dma_Set(buf + off, (void *)&OBJ_PLTT_COLOR(15, 0),
83 (DMA_ENABLE | DMA_32BIT) << 16 | 8, REG_DMA3);
85 (u8 *)((id << 10) + (s32)buf + COLOSSO_PALETTE_BYTES));
88}
89
90/// The lettering's scene callback: run its script, move, scale and fade it, and
91/// draw it as double-size affine sprites blended over the screen, in the shape
92/// of gColosso_LetteringMode (gColosso_LetteringParam picks the second half of
93/// a picture): 1: four 32x16 pieces in a row (Match 1 to 3, Lend a Hand); 2:
94/// one 32x32 piece (3, 2, 1); 3: two 32x16 pieces (Won or Lose); 4: Go!, one
95/// 64x32 piece, or two 32x16 in French.
96static void Colosso_UpdateLettering(void) {
98 struct Sprite *sprite = (struct Sprite *)write;
100 u32 flags;
101 s32 scale, blend, pos;
102 s32 matrix, i, x, y, left;
103 struct AffineTransform work;
104
105commands:
106 if (gColosso_LetteringTimer == 0) {
107 {
108 switch (*gColosso_LetteringScript++) {
113 break;
119 break;
125 break;
131 break;
134 break;
138 return;
139 }
140 }
141 goto commands;
142 }
146 } else {
147 s32 duration, start, progress, target;
151 progress = ++gColosso_ModeScaleStep;
152 scale = start + (target - start) * progress / duration;
153 if (progress >= duration)
155 }
158 } else {
159 s32 duration, start, progress, target;
163 progress = ++gColosso_ModeBlendStep;
164 blend = start + (target - start) * progress / duration;
165 if (progress >= duration)
167 }
168 if (gColosso_ModeMoveDuration == 0) {
170 } else {
171 s32 duration, start, progress, target;
172 duration = gColosso_ModeMoveDuration;
175 progress = ++gColosso_ModeMoveStep;
176 pos = start + (target - start) * progress / duration;
177 if (progress >= duration)
179 }
180 work.angle = 0;
181 work.scaleX = scale;
182 work.scaleY = scale;
183 matrix = (s16)AffineMatrix_BuildForEffect(&work);
185 pos = gColosso_LetteringPosition / 256;
186 switch (gColosso_LetteringMode) {
187 case 1: {
188 u32 attr;
189 i = 0;
190 y = 56;
191 flags = 0x80004000;
192 attr = matrix << 25;
193 for (; i < 4; i++) {
194 x = pos + scale * (i * 32 - 48) / 256;
195 left = x + 88;
196 if ((u32)(x + 152) < 304) {
197 x = left & 511;
198 *write++ = 0;
199 *write++ = (x << 16) | y | flags | attr | 0x700;
200 *write++ = 0xf400 | tile;
201 Runtime_PushSlotEntry(sprite++, 236);
202 }
203 tile += 8;
204 }
205 break;
206 }
207 case 3: {
208 u32 attr;
209 i = 0;
210 y = 48;
211 flags = 0x80004000;
212 attr = matrix << 25;
213 for (; i < 2; i++) {
214 x = pos + scale * (i * 32 - 16) / 256;
215 left = x + 88;
216 if ((u32)(x + 152) < 304) {
217 x = left & 511;
218 *write++ = 0;
219 *write++ = (x << 16) | y | flags | attr | 0x700;
220 *write++ = 0xf400 | (tile + gColosso_LetteringParam);
221 Runtime_PushSlotEntry(sprite++, 236);
222 }
223 tile += 8;
224 }
225 break;
226 }
227#if LANGUAGE == LANGUAGE_FRENCH
228 case 4: {
229 u32 attr;
230 i = 0;
231 y = 64;
232 flags = 0x80004000;
233 attr = matrix << 25;
234 for (; i < 2; i++) {
235 x = pos + scale * (i * 32 - 16) / 256;
236 left = x + 88;
237 if ((u32)(x + 152) < 304) {
238 x = left & 511;
239 *write++ = 0;
240 *write++ = (x << 16) | y | flags | attr | 0x700;
241 *write++ = 0xf400 | (tile + gColosso_LetteringParam);
242 Runtime_PushSlotEntry(sprite++, 236);
243 }
244 tile += 8;
245 }
246 break;
247 }
248#else
249 case 4:
250 y = 48;
251 flags = 0xc0004000;
252 left = pos + 56;
253 if ((u32)(pos + 120) < 304) {
254 x = left & 511;
255 *write++ = 0;
256 *write++ = (x << 16) | y | flags | (matrix << 25) | 0x700;
257 *write++ = 0xf400 | (tile + gColosso_LetteringParam);
258 Runtime_PushSlotEntry(sprite, 236);
259 }
260 break;
261#endif
262 case 2:
263 y = 48;
264 flags = 0x80000000;
265 left = pos + 88;
266 if ((u32)(pos + 152) < 304) {
267 x = left & 511;
268 *write++ = 0;
269 *write++ = (x << 16) | y | flags | (matrix << 25) | 0x700;
270 *write++ = 0xf400 | (tile + gColosso_LetteringParam);
271 Runtime_PushSlotEntry(sprite, 236);
272 }
273 break;
274 }
275 IO_WRITE_QUEUE_PUSH((u32)&REG_BLDCNT, 0x3f00, 0x20000);
276 IO_WRITE_QUEUE_PUSH((u32)&REG_BLDALPHA, ((16 - blend) << 8) | blend, 0x20000);
277}
Sprite rotation and scale, and the affine matrices handed out each frame.
Calls through a function pointer, by argument count.
The task scheduler: tasks, their order and the scheduler's state.
const u8 gColosso_LetteringPaletteOffsets[]
s16 gColosso_LetteringSlot
static void Colosso_UpdateLettering(void)
The lettering's scene callback: run its script, move, scale and fade it, and draw it as double-size a...
s16 gColosso_ModeMoveTarget
s16 * gColosso_LetteringScript
static void Colosso_LoadLettering(s32 id)
Loads lettering picture id into the lettering's VRAM block (taken once) and its palette into sprite p...
s16 gColosso_LetteringTimer
ColossoLetteringCommand
The Colosso finals' three courses (Colosso Log, River and Wall): the large lettering a race starts wi...
@ COLOSSO_LETTERING_SCALE
scale, frames: grow or shrink to scale (256 is its own size)
@ COLOSSO_LETTERING_PLACE
x, speed: put the lettering at x pixels from the centre, moving at speed 256ths of a pixel a frame
@ COLOSSO_LETTERING_WAIT
frames: run the moves for that many frames before the next command
@ COLOSSO_LETTERING_END
remove the lettering and free its VRAM block
@ COLOSSO_LETTERING_ACCELERATE
speed, frames: change the speed over that many frames
@ COLOSSO_LETTERING_FADE
weight, frames: fade to weight sixteenths over the screen
s32 gColosso_LetteringPosition
s16 gColosso_ModeMoveDuration
s16 gColosso_LetteringParam
static __inline__ void Dma_Wait(volatile u32 *dma)
s16 gColosso_LetteringMode
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 FieldResource_DecodeType01(const void *source, void *destination)
Decodes type-01 compressed data.
Definition engine_call.h:90
s16 gColosso_ModeBlendTarget
s16 gColosso_ModeScaleStep
s16 gColosso_ModeBlendStep
s16 gColosso_ModeBlendDuration
s16 gColosso_ModeMoveStart
s16 gColosso_ModeBlendStart
s16 gColosso_ModeScaleStart
s16 gColosso_ModeMoveStep
u32 gColosso_LetteringSprites[]
s16 gColosso_ModeScaleDuration
s16 gColosso_ModeScaleTarget
The scene script layer: the engine services a scene's events call, declared once (Engine_EventBegin,...
s32 Engine_TaskRemoveCallback(void(*callback)(void))
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)
The screen blend's globals and the graphics routines.
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
Definition heap.c:140
The hardware's I/O registers and their bits, as pret names them.
#define DMA_32BIT
Definition io_reg.h:210
#define OBJ_PLTT_COLOR(palette, color)
Definition io_reg.h:160
#define REG_DMA3
Definition io_reg.h:153
#define REG_BLDALPHA
Definition io_reg.h:142
#define REG_BLDCNT
Definition io_reg.h:119
#define DMA_ENABLE
Definition io_reg.h:217
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 heaps: allocating and freeing blocks.
void Runtime_BumpFree(void *buffer)
The reel game's title lettering.
s32 AffineMatrix_BuildForEffect(struct AffineTransform *source)
Hands out the next OAM affine matrix for a sprite drawn with source's scale and rotation and fills it...
Definition render.c:27
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_Lettering
A sprite's rotation and scale: scales in 8.8 fixed point (0x100 is full size), the angle in 1/65536 t...
Definition affine.h:13
u16 angle
1/65536 turns
Definition affine.h:16
u16 scaleY
8.8 fixed point, read signed
Definition affine.h:15
u16 scaleX
8.8 fixed point, read signed: negative mirrors the sprite
Definition affine.h:14
One lettering piece as queued for drawing: a header word, then its OAM attributes.
u32 words[3]
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
The system's routines and globals: interrupts, BIOS sound bias, random numbers and sleep.
Values that differ by patch level or language, chosen once for their code.
#define COLOSSO_PALETTE_BYTES
Definition tbs_edition.h:90
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 char u8
Definition types.h:11
Declares nothing of its own: it only includes the window, battle command, resource and VRAM table hea...
s32 Resource_ResetEntry(u32 no)
Frees cache entry no: its blocks go back and the entry is marked free (offset 0xffff).
Definition vram_cache.c:106
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
struct VramBlockCacheEntry gVramBlockCache[]