17 u32 tile = *(
u8 *)entry;
25 for (i = 0; i < 32; i++) {
32 src = sheet + pattern * 32;
33 for (i = 0; i < 32; i++) {
35 u32 color = remap[value & 15];
40 color = remap[value >> 4];
50 for (i = 0, p = dst; i < 32; i++) {
51 u32 value = p[0] | p[1] << 4;
59 for (n = 0; n < 128; n++) {
61 u32 following = (value + 1) % 128;
70 *entry = tile | 0xf000;
71 *mirror = tile | 0xf000;
104 paletteBits = work->
level << 12;
106 if (paletteBits == 0xF000) {
122 if (glyphCode <= 30) {
135#if (LANGUAGE != LANGUAGE_JAPANESE)
150#if (LANGUAGE != LANGUAGE_JAPANESE)
158#if (LANGUAGE == LANGUAGE_JAPANESE)
159 if (glyphCode == 222 || glyphCode == 223) {
164 src = (
u32 *)(glyphs + glyphCode * 32);
166 for (index = 0; index < 8; index++) {
168 for (column = 0; column < 4; column++) {
169 u8 pen = pens[bits & 15];
175 pen = pens[bits & 15];
183 if (code == 0xF01D || code == 0xF01F)
185#if (LANGUAGE == LANGUAGE_SPANISH) || (LANGUAGE == LANGUAGE_FRENCH) || \
186 (LANGUAGE == LANGUAGE_ITALIAN)
187 else if (code == 0xF01E || code == 0xF005)
189 else if (code == 0xF01E)
193#if (LANGUAGE == LANGUAGE_JAPANESE)
194 if (glyphCode > 128) {
195 if (glyphCode == 254 || glyphCode == 255)
212 tileCount = (
u32)(x + 7) >> 3;
215 for (index = 0; index < 8; index++) {
216 for (column = 0; column < tileCount; column++) {
219 glyphCode |= glyphCode << 4;
221 glyphCode &= 0x0FF00FF0;
223 glyphCode |= glyphCode << 8;
226 *(
u32 *)dst = (glyphCode << 4) >> 16 | bits << 16;
229 dst = dst - tileCount * 4 + 0x100;
230 src = (
u32 *)((
u8 *)src - tileCount * 8 + 0x100);
234 for (index = 0; index < tileCount; index++) {
241 tile = *tiles & 0x3FF;
242 if ((tile < 0x80 || tile > 0xFF) &&
243 (work->
alt == 0 || tile < 0x200 || tile > 0x27F)) {
245 for (column = 0; column <= mask && work->
tileAttributes[tile] != 0;
247 tile = (tile + 1) & mask;
254 *tiles = paletteBits | tile;
255 *mirror = paletteBits | tile;
258 *vramTile++ = ((
u32 *)canvas)[index];
259 *vramTile++ = ((
u32 *)canvas)[index + 0x40];
260 *vramTile++ = ((
u32 *)canvas)[index + 0x80];
261 *vramTile++ = ((
u32 *)canvas)[index + 0xC0];
262 *vramTile++ = ((
u32 *)canvas)[index + 0x100];
263 *vramTile++ = ((
u32 *)canvas)[index + 0x140];
264 *vramTile++ = ((
u32 *)canvas)[index + 0x180];
265 *vramTile++ = ((
u32 *)canvas)[index + 0x1C0];
278 u16 *cursor = (
u16 *)((y * 32 + x) * 2 + (
u32)base);
282 for (row = 0; row < height; row++) {
285 for (column = 0; column < width; column++) {
286 u32 tileId = *cursor++ & 0x3FF;
288 if ((tileId - 0x80) <= 0x7F ||
289 (alternateTiles != 0 && tileId > 0x1FF && tileId <= 0x27F)) {
290 u32 attributeIndex = ((tileId & 0xFF) ^ 0x80);
294 cursor += 32 - width;
301 u16 *cursor = (
u16 *)base;
307 for (row = 20; row != 0; row--) {
308 for (x = 0; x < width; x++) {
309 u32 tileId = *cursor++ & 0x3ff;
311 if ((tileId - 0x80) <= 0x7f ||
312 (alternateTiles != 0 && tileId > 0x1ff && tileId <= 0x27f)) {
313 u32 attributeIndex = ((tileId & 0xff) ^ 0x80);
320 for (row = 0; row < 256; row++, base++) {
337 if (allowAlternateTiles != 0) {
339 allowAlternateTiles = 0;
343 *attributes = allowAlternateTiles;
349 allowAlternateTiles = 0;
382 (
u16 *)((((win->
y + y1) << 5) + win->
x + x2) * 2 + (
u32)work->
tilemap);
383 for (pos = y1; pos <= y2; pos++) {
406 }
else if (pos == y2) {
446 }
else if (y1 == y2) {
456 (
u16 *)((((win->
y + y1) << 5) + win->
x + x1) * 2 + (
u32)work->
tilemap);
457 for (pos = x1; pos <= x2; pos++) {
480 }
else if (pos == x2) {
527 work->
colour = param & 15;
545 canvas->
entries[*counter] = zero;
553 u32 offsetX,
u32 offsetY) {
563 counter = &canvas->
count;
568 canvas->
entries[*counter] = zero;
571 cell = ((window->
y + (offsetY >> 3) + 1) << 5) +
572 (window->
x + (offsetX >> 3)) + 1;
573 if (cell < 32 * 20) {
575 byteOffset = cell * 2;
579 (
u16 *)vramAddress, 7 & offsetX);
591 }
while (*input != 0);
615 s32 offsetX,
s32 offsetY) {
628 cell = ((work->
y + ((
u32)offsetY >> 3) + 1) << 5) +
629 (work->
x + ((
u32)offsetX >> 3)) + 1;
630 if (cell < 32 * 20) {
704#if (LANGUAGE == LANGUAGE_SPANISH) || (LANGUAGE == LANGUAGE_FRENCH) || \
705 (LANGUAGE == LANGUAGE_ITALIAN)
721 for (index = 0; index <= 4; index++) {
722 output[index + 2] = text[index];
726 cell = ((work->
y + ((
u32)offsetY >> 3) + 1) << 5) +
727 (work->
x + ((
u32)offsetX >> 3)) + 1;
728 if (cell < 32 * 20) {
s32 UiText_BuildRenderEntries(s32 script, s32 clear)
Decodes message script into the ring of decoded text (UiRenderWork.entries) and returns where it star...
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...
u8 * UiText_FormatNumber(u8 *buffer, s32 input, s32 width)
Writes value as decimal text into buffer (14 bytes) and returns where the text starts.
void UiText_RenderWideStringInWindow(s16 *text, struct UiWindow *window, s32 x, s32 y)
Draws a zero-terminated string of 16-bit character codes into a window's tilemap at tile (x,...
void UiText_RenderWideStringAtOffset(u16 *text, struct UiWindow *window, s32 x, s32 y)
Draws a zero-terminated string of 16-bit character codes into a text canvas window at pixel (x,...
const u8 gUiText_GlyphWidths[]
const u8 gUiText_ColourPens[]
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
void * MemAlloc(s32 size)
Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise...
static s32 Iwram_FillWords(void *destination, s32 size, u32 value)
static s32 Iwram_ClearWords(void *destination, s32 size)
void MemFree(void *buffer)
char ResourceId_WindowTiles
The window system's work: the windows' tilemap, the windows, the three text channels,...
u16 tilemap[640]
the windows' BG tilemap, 32 by 20 tiles
u8 alt
1 lets text use 256 tiles, adding tiles 0x200 to 0x27F
u8 level
text tiles' palette; 15 by default, 14 or 5 for low HP
u16 entries[RENDER_ENTRY_MASK+1]
decoded text, a ring of codes
u16 tileCursor
the text tile the next search for a free one starts at
u16 count
where the next code goes in entries
u16 colour
the current channel's, copied in to draw
u16 outline
the current channel's, copied in to draw
u8 tileAttributes[256]
Per text tile (tiles 0x80 to 0xFF, then 0x200 to 0x27F): bit 0 once allocated, bit 1 while the tilema...
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
#define RENDER_ENTRY_MASK
void UiText_DrawStringInWindow(const u8 *text, struct UiWindow *window, u32 x, u32 y)
Draws a byte string into a window's tilemap at pixel (x, y) of its interior, rounded down to tiles.
void UiText_DrawResource(s32 message, struct UiWindow *window, s32 x, s32 y)
Decodes a message and draws it into a text canvas window at pixel (x, y).
void UiText_DrawPrefixedNumberAtOffset(s32 value, const struct UiWindow *work, s32 offsetX, s32 offsetY, s32 variant)
Draws a four-digit number after a two-glyph sign (window tiles 0x1d and 0x1e, or 0x1f and 0x1e with v...
void UiText_DrawString(const u8 *text, struct UiWindow *window, s32 x, s32 y)
Draws a byte string into a text canvas window at pixel (x, y).
void UiWork_SetRenderWord(u16 value)
Sets the text style (UiRenderWork.outline) of drawn text.
void UiWindow_DrawDividerLine(struct UiWindow *win, u32 x1, u32 y1, u32 x2, u32 y2)
Draws a straight divider line inside a window from tile (x1, y1) to (x2, y2), horizontal or vertical:...
void UiText_DrawStringAtOffset(const u8 *text, const struct UiWindow *work, s32 offsetX, s32 offsetY)
Draws a byte string as tiles in window work at pixel (offsetX, offsetY) of its interior.
void UiWork_SetAltFlagAndClearTable(s32 allowAlternateTiles)
Frees every text tile, and with flag set lets text tiles take the second tile range (0x200 to 0x27f) ...
void UiText_DrawNumberInWindow(s32 value, s32 width, struct UiWindow *window, s32 x, s32 y)
Draws a number (width as UiText_FormatNumber) into a window's tilemap at pixel (x,...
void UiWindow_ClearTileAttributesInRect(s32 x, s32 y, u32 width, u32 height)
Marks the text tiles under a tilemap rectangle (x, y, width and height in tiles) as no longer shown,...
void UiText_DrawNumberAtOffset(s32 value, s32 width, const struct UiWindow *window, s32 x, s32 y)
Draws a number (width as UiText_FormatNumber) as tiles in a window at pixel (x, y) of its interior.
static __inline__ void UiText_WidenByteString(const u8 *input, u16 *output)
Copies a zero-terminated byte string into the text renderer's halfwords.
UNUSED void UiWindow_OverlayTilePattern(u16 *entry, u16 *mirror, s32 pattern, u8 *remap)
Draws window tile pattern over the tile of tilemap entry *entry, with its colours mapped through rema...
void UiWindow_MarkVisibleTileAttributes(void)
Marks the text tiles the tilemap shows, and frees those it no longer shows.
UNUSED void UiRender_ReservedNoOp(void)
Nothing calls it.
s32 UiText_RenderStringTiles(u16 *text, u16 *tiles, u16 *mirror, s32 x)
Draws a string of 16-bit character codes with the window font into tiles of their own,...
void UiWork_SetParamNibble(s32 param)
Sets the text colour (0 to 15) of drawn text.
void UiText_DrawCharacterAtOffset(s32 message, const struct UiWindow *window, u32 offsetX, u32 offsetY)
Decodes a message and draws it as tiles in a window at pixel (offsetX, offsetY) of its interior.
void UiText_DrawNumber(s32 value, s32 width, struct UiWindow *window, s32 x, s32 y)
Draws a number (width as UiText_FormatNumber) into a text canvas window at pixel (x,...
#define UI_TILEMAP_VRAM
The UI tilemap in VRAM (BG screen block 4), which UiWork_UploadDirtyBlocks copies the work block's ti...
#define DMA_COPY32(count)
The DMA control word that copies count words.
@ UI_TILE_FRAME_RIGHT_TEE
the right edge meeting a line
@ UI_TILE_DIVIDER_HORIZONTAL
@ UI_TILE_FRAME_LEFT_TEE
the left edge meeting a line
@ UI_TILE_FRAME_BOTTOM_TEE
the bottom edge meeting a line
@ UI_TILE_DIVIDER_TEE_LEFT
a horizontal line leaving left
@ UI_TILE_FRAME_TOP_TEE
the top edge meeting a line
@ UI_TILE_DIVIDER_TEE_DOWN
a vertical line leaving below
@ UI_TILE_DIVIDER_TEE_RIGHT
a horizontal line leaving right
@ UI_TILE_DIVIDER_TEE_UP
a vertical line leaving above
@ UI_TILE_DIVIDER_VERTICAL
What every part of the window object shares: its includes, edition values, macros and the codes of de...
#define UI_NUMBER_BUFFER_SIZE
#define UI_BYTE_STRING_BUFFER_SIZE