Alchemy
Loading...
Searching...
No Matches

text_tiles.c

Go to the documentation of this file.
1/// @file
2/// Text drawn as tiles, text tile ownership and divider lines.
3/// Part of window.c, the window object, compiled only through it.
4
6
7/// Draws window tile pattern over the tile of tilemap entry *entry, with its
8/// colours mapped through remap (0 leaves a pixel as it was). A shared tile
9/// first gets a free tile of its own, which entry and mirror then point to.
10/// Only nonzero remap entries replace pixels; shared tiles become private
11/// before upload. Nothing calls it.
12UNUSED void UiWindow_OverlayTilePattern(u16 *entry, u16 *mirror, s32 pattern,
13 u8 *remap) {
14 struct UiRenderWork *work = UI_WORK;
15 u8 pixels[128];
17 u32 tile = *(u8 *)entry;
18 u8 *src;
19 u8 *dst;
20 u32 n;
21 u32 i;
22
23 dst = pixels;
24 src = BG_CHAR_BLOCK(0) + TILE_SIZE_4BPP * tile;
25 for (i = 0; i < 32; i++) {
26 n = *src++;
27 *dst++ = n & 15;
28 *dst++ = n >> 4;
29 }
30
31 dst = pixels;
32 src = sheet + pattern * 32;
33 for (i = 0; i < 32; i++) {
34 u32 value = *src++;
35 u32 color = remap[value & 15];
36
37 if (color != 0)
38 *dst = color;
39 dst++;
40 color = remap[value >> 4];
41 if (color != 0)
42 *dst = color;
43 dst++;
44 }
45
46 {
47 u8 *p;
48
49 dst = pixels;
50 for (i = 0, p = dst; i < 32; i++) {
51 u32 value = p[0] | p[1] << 4;
52
53 p += 2;
54 *dst++ = value;
55 }
56 }
57
58 if ((s8)tile >= 0) {
59 for (n = 0; n < 128; n++) {
60 u32 value = work->tileCursor;
61 u32 following = (value + 1) % 128;
62
63 tile = (u8)value;
64 work->tileCursor = following;
65 if (work->tileAttributes[tile] == 0)
66 break;
67 }
68 work->tileAttributes[tile] = 1;
69 tile |= 0x80;
70 *entry = tile | 0xf000;
71 *mirror = tile | 0xf000;
72 }
73 Dma_Set(pixels, BG_CHAR_BLOCK(0) + tile * TILE_SIZE_4BPP, DMA_COPY32(8),
74 REG_DMA3);
75}
76
77/// Draws a string of 16-bit character codes with the window font into tiles
78/// of their own, starting x pixels into the first tile, and points tiles (and
79/// the same entries in mirror) at them. Colour codes change the text colour.
80/// Returns how many tiles the text covers.
81/// The canvas is eight rows of 256 pixels; the pen must stay within each row.
82s32 UiText_RenderStringTiles(u16 *text, u16 *tiles, u16 *mirror, s32 x) {
83 /* FAKEMATCH: needed to match: an unread 32-byte reserve, the native frame's
84 * extra bytes (the frame is 36 bytes without it). */
85 UNUSED u32 reserve[8];
86 u8 pens[16];
87 struct UiRenderWork *work;
88 u8 *canvas;
89 u8 *glyphs;
90 u32 paletteBits;
91 u32 *src;
92 u8 *dst;
93 u32 glyphCode;
94 u32 code;
95 s32 tileCount;
96 u32 glyphWidth;
97 s32 index;
98 s32 column;
99 u32 bits;
100
101 work = UI_WORK;
102 canvas = MemAlloc(0x800);
104 paletteBits = work->level << 12;
105 Iwram_ClearWords(pens, 16);
106 if (paletteBits == 0xF000) {
107 pens[1] = gUiText_ColourPens[work->colour & 15];
108 pens[3] = 3;
109 Iwram_FillWords(canvas, 0x800, 0x04040404);
110 } else {
111 pens[1] = (u8)work->colour & 15;
112 pens[3] = 1;
113 Iwram_FillWords(canvas, 0x800, 0x0E0E0E0E);
114 }
115 // Expand glyph pixels and control-code colour changes into a byte canvas.
116 if (text != 0) {
117 for (;;) {
118 glyphCode = *text++;
119 code = glyphCode;
120 if (glyphCode == 0)
121 break;
122 if (glyphCode <= 30) {
123 switch (glyphCode) {
124 case 8:
125 work->colour = *text++;
126 pens[1] = gUiText_ColourPens[work->colour & 15];
127 break;
128 case 7:
129 case 9:
130 case 10:
131 work->colour = 15;
132 pens[1] = gUiText_ColourPens[work->colour];
133 break;
134 case 3:
135#if (LANGUAGE != LANGUAGE_JAPANESE)
136 x += gUiText_GlyphWidths[0];
137#else
138 x += 8;
139#endif
140 break;
141 case 14:
142 case 15:
143 case 28:
144 text++;
145 // Skip the second operand too.
146 // Fall through.
147 case 11:
148 case 12:
149 case 17:
150#if (LANGUAGE != LANGUAGE_JAPANESE)
151 case 29:
152#endif
153 text++;
154 break;
155 }
156 } else {
157 glyphCode &= 0xFF;
158#if (LANGUAGE == LANGUAGE_JAPANESE)
159 if (glyphCode == 222 || glyphCode == 223) {
160 x -= 3;
161 glyphCode += 32;
162 }
163#endif
164 src = (u32 *)(glyphs + glyphCode * 32);
165 dst = canvas + x;
166 for (index = 0; index < 8; index++) {
167 bits = *src++;
168 for (column = 0; column < 4; column++) {
169 u8 pen = pens[bits & 15];
170
171 if (pen != 0)
172 *dst = pen;
173 dst++;
174 bits >>= 4;
175 pen = pens[bits & 15];
176 if (pen != 0)
177 *dst = pen;
178 dst++;
179 bits >>= 4;
180 }
181 dst += 248;
182 }
183 if (code == 0xF01D || code == 0xF01F)
184 x += 8;
185#if (LANGUAGE == LANGUAGE_SPANISH) || (LANGUAGE == LANGUAGE_FRENCH) || \
186 (LANGUAGE == LANGUAGE_ITALIAN)
187 else if (code == 0xF01E || code == 0xF005)
188#else
189 else if (code == 0xF01E)
190#endif
191 x += 3;
192 else {
193#if (LANGUAGE == LANGUAGE_JAPANESE)
194 if (glyphCode > 128) {
195 if (glyphCode == 254 || glyphCode == 255)
196 glyphWidth = 3;
197 else
198 glyphWidth = 8;
199 } else
200#endif
201 if (glyphCode > 31)
202 glyphWidth = gUiText_GlyphWidths[glyphCode - 32];
203 else
204 glyphWidth = 1;
205 x += glyphWidth;
206 }
207 }
208 }
209 }
210
211 // Pack each eight-pixel span back into the tile's four-bit colour fields.
212 tileCount = (u32)(x + 7) >> 3;
213 src = (u32 *)canvas;
214 dst = canvas;
215 for (index = 0; index < 8; index++) {
216 for (column = 0; column < tileCount; column++) {
217 glyphCode = src[0];
218 bits = src[1];
219 glyphCode |= glyphCode << 4;
220 bits |= bits >> 4;
221 glyphCode &= 0x0FF00FF0;
222 bits &= 0x00FF00FF;
223 glyphCode |= glyphCode << 8;
224 bits |= bits >> 8;
225 src += 2;
226 *(u32 *)dst = (glyphCode << 4) >> 16 | bits << 16;
227 dst += 4;
228 }
229 dst = dst - tileCount * 4 + 0x100;
230 src = (u32 *)((u8 *)src - tileCount * 8 + 0x100);
231 }
232
233 // Reuse private text tiles, allocate any new ones, then upload each tile.
234 for (index = 0; index < tileCount; index++) {
235 u32 mask = 127;
236 u32 tile;
237 u32 *vramTile;
238
239 if (work->alt != 0)
240 mask = 255;
241 tile = *tiles & 0x3FF;
242 if ((tile < 0x80 || tile > 0xFF) &&
243 (work->alt == 0 || tile < 0x200 || tile > 0x27F)) {
244 tile = work->tileCursor & mask;
245 for (column = 0; column <= mask && work->tileAttributes[tile] != 0;
246 column++)
247 tile = (tile + 1) & mask;
248 work->tileCursor = (tile + 1) & mask;
249 work->tileAttributes[tile] = 1;
250 if (tile > 127)
251 tile += 0x180;
252 else
253 tile |= 0x80;
254 *tiles = paletteBits | tile;
255 *mirror = paletteBits | tile;
256 }
257 vramTile = (u32 *)(BG_CHAR_BLOCK(0) + tile * TILE_SIZE_4BPP);
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];
266 tiles++;
267 mirror++;
268 }
269 MemFree(canvas);
270 return tileCount;
271}
272
273/// Marks the text tiles under a tilemap rectangle (x, y, width and height in
274/// tiles) as no longer shown, for reuse.
275/// Only the dynamic text-tile ranges have allocation attributes to clear.
277 u8 *base = gWindowWork[0];
278 u16 *cursor = (u16 *)((y * 32 + x) * 2 + (u32)base);
279 u32 alternateTiles = ((struct UiRenderWork *)base)->alt;
280 u32 row;
281
282 for (row = 0; row < height; row++) {
283 u32 column;
284
285 for (column = 0; column < width; column++) {
286 u32 tileId = *cursor++ & 0x3FF;
287
288 if ((tileId - 0x80) <= 0x7F ||
289 (alternateTiles != 0 && tileId > 0x1FF && tileId <= 0x27F)) {
290 u32 attributeIndex = ((tileId & 0xFF) ^ 0x80);
291 ((struct UiRenderWork *)base)->tileAttributes[attributeIndex] &= 0xFC;
292 }
293 }
294 cursor += 32 - width;
295 }
296}
297
298/// Marks the text tiles the tilemap shows, and frees those it no longer shows.
300 u8 *base = gWindowWork[0];
301 u16 *cursor = (u16 *)base;
302 s32 width = 30;
303 u32 alternateTiles = ((struct UiRenderWork *)base)->alt;
304 s32 row;
305 s32 x;
306
307 for (row = 20; row != 0; row--) {
308 for (x = 0; x < width; x++) {
309 u32 tileId = *cursor++ & 0x3ff;
310
311 if ((tileId - 0x80) <= 0x7f ||
312 (alternateTiles != 0 && tileId > 0x1ff && tileId <= 0x27f)) {
313 u32 attributeIndex = ((tileId & 0xff) ^ 0x80);
314
315 ((struct UiRenderWork *)base)->tileAttributes[attributeIndex] |= 2;
316 }
317 }
318 }
319
320 for (row = 0; row < 256; row++, base++) {
321 if (((struct UiRenderWork *)base)->tileAttributes[0] == 1)
322 ((struct UiRenderWork *)base)->tileAttributes[0] = 0;
323 }
324}
325
326/// Frees every text tile, and with flag set lets text tiles take the second
327/// tile range (0x200 to 0x27f) too.
328/// The second range extends text capacity from 128 to 256 tiles.
329void UiWork_SetAltFlagAndClearTable(s32 allowAlternateTiles) {
330 s32 i;
331 s32 j;
332 s8 *attributes;
334 u8 *work;
335
336 work = gWindowWork[0];
337 if (allowAlternateTiles != 0) {
338 ((struct UiRenderWork *)work)->alt = 1;
339 allowAlternateTiles = 0;
340 for (i = 0x80,
341 attributes = (s8 *)((struct UiRenderWork *)work)->tileAttributes + 0x80;
342 i <= 0xFF; i += 1) {
343 *attributes = allowAlternateTiles;
344 attributes += 1;
345 }
346 return;
347 }
348 ((struct UiRenderWork *)work)->alt = 0;
349 allowAlternateTiles = 0;
350 tileAttributes = (s8 *)((struct UiRenderWork *)work)->tileAttributes + 0x80;
351 j = 0x7F;
352 do {
353 j -= 1;
354 *tileAttributes = allowAlternateTiles;
355 tileAttributes += 1;
356 } while (j >= 0);
357}
358
359/// Nothing calls it.
361
362/// Draws a straight divider line inside a window from tile (x1, y1) to
363/// (x2, y2), horizontal or vertical: its ends join the frame or the lines they
364/// meet, and it crosses the lines it passes over.
365void UiWindow_DrawDividerLine(struct UiWindow *win, u32 x1, u32 y1, u32 x2,
366 u32 y2) {
367 struct UiRenderWork *work = UI_WORK;
368 u16 *cursor;
369 u32 pos;
370 u32 tile;
371
372 if (x1 == x2) {
373 if (y1 == y2)
374 return;
375 if (y1 > y2) {
376 pos = y1;
377 y1 = y2;
378 y2 = pos;
379 }
380 UiWindow_ClearTileAttributesInRect(win->x + x2, win->y + y1, 1, y2 - y1);
381 cursor =
382 (u16 *)((((win->y + y1) << 5) + win->x + x2) * 2 + (u32)work->tilemap);
383 for (pos = y1; pos <= y2; pos++) {
384 tile = *cursor;
385 if (pos == y1) {
386 switch (tile) {
392 break;
395 break;
398 break;
401 break;
402 default:
404 break;
405 }
406 } else if (pos == y2) {
407 switch (tile) {
413 break;
416 break;
419 break;
422 break;
423 default:
425 break;
426 }
427 } else {
428 switch (tile) {
432 break;
437 break;
438 default:
440 break;
441 }
442 }
443 *cursor = tile;
444 cursor += 32;
445 }
446 } else if (y1 == y2) {
447 if (x1 == x2)
448 return;
449 if (x1 > x2) {
450 pos = x1;
451 x1 = x2;
452 x2 = pos;
453 }
454 UiWindow_ClearTileAttributesInRect(win->x + x1, win->y + y1, x2 - x1, 1);
455 cursor =
456 (u16 *)((((win->y + y1) << 5) + win->x + x1) * 2 + (u32)work->tilemap);
457 for (pos = x1; pos <= x2; pos++) {
458 tile = *cursor;
459 if (pos == x1) {
460 switch (tile) {
466 break;
469 break;
472 break;
475 break;
476 default:
478 break;
479 }
480 } else if (pos == x2) {
481 switch (tile) {
487 break;
490 break;
493 break;
496 break;
497 default:
499 break;
500 }
501 } else {
502 switch (tile) {
506 break;
511 break;
512 default:
514 break;
515 }
516 }
517 *cursor = tile;
518 cursor++;
519 }
520 }
521}
522
523/// Sets the text colour (0 to 15) of drawn text.
525 struct UiRenderWork *work = UI_WORK;
526
527 work->colour = param & 15;
528}
529
530/// Sets the text style (UiRenderWork.outline) of drawn text.
532 struct UiRenderWork *work = UI_WORK;
533
534 work->outline = value;
535}
536
537/// Decodes a message and draws it into a text canvas window at pixel (x, y).
538void UiText_DrawResource(s32 message, struct UiWindow *window, s32 x, s32 y) {
539 struct UiRenderWork *canvas = UI_WORK;
540 u16 *counter = &canvas->count;
541 s32 zero = 0;
542
543 *counter = zero;
544 UiText_BuildRenderEntries(message, 1);
545 canvas->entries[*counter] = zero;
546 *counter = (*counter + 1) & RENDER_ENTRY_MASK;
547 UiText_RenderWideStringAtOffset(canvas->entries, window, x, y);
548}
549
550/// Decodes a message and draws it as tiles in a window at pixel (offsetX,
551/// offsetY) of its interior.
552void UiText_DrawCharacterAtOffset(s32 message, const struct UiWindow *window,
553 u32 offsetX, u32 offsetY) {
554 s32 byteOffset;
555 s32 vramAddress;
556 u16 *text;
557 s32 zero;
558 u32 cell;
559 struct UiRenderWork *canvas;
560 u16 *counter;
561
562 canvas = UI_WORK;
563 counter = &canvas->count;
564 zero = 0;
565 *counter = zero;
566 UiText_BuildRenderEntries(message, 1);
567
568 canvas->entries[*counter] = zero;
569 *counter = (*counter + 1) & RENDER_ENTRY_MASK;
570
571 cell = ((window->y + (offsetY >> 3) + 1) << 5) +
572 (window->x + (offsetX >> 3)) + 1;
573 if (cell < 32 * 20) {
574 // Inside the tilemap.
575 byteOffset = cell * 2;
576 vramAddress = byteOffset + (s32)UI_TILEMAP_VRAM;
577 text = canvas->entries;
578 UiText_RenderStringTiles(text, (u16 *)((u8 *)canvas->tilemap + byteOffset),
579 (u16 *)vramAddress, 7 & offsetX);
580 }
581}
582
583/// Copies a zero-terminated byte string into the text renderer's halfwords.
584/// The destination needs one halfword per input byte, including the terminator.
585static __inline__ void UiText_WidenByteString(const u8 *input, u16 *output) {
586 if (*input != 0) {
587 do {
588 *output = *input;
589 input++;
590 output++;
591 } while (*input != 0);
592 }
593 *output = 0;
594}
595
596/// Draws a byte string into a text canvas window at pixel (x, y).
597/// The 256-halfword scratch requires at most 255 input bytes before the
598/// terminator.
599void UiText_DrawString(const u8 *text, struct UiWindow *window, s32 x, s32 y) {
600 s16 *buffer;
601 const u8 *input;
602
603 input = text;
605 UiText_WidenByteString(input, (u16 *)buffer);
606 UiText_RenderWideStringAtOffset((u16 *)buffer, window, x, y);
607 MemFree(buffer);
608}
609
610/// Draws a byte string as tiles in window work at pixel (offsetX, offsetY) of
611/// its interior.
612/// The conversion scratch has the same 255-byte input limit as
613/// UiText_DrawString.
614void UiText_DrawStringAtOffset(const u8 *text, const struct UiWindow *work,
615 s32 offsetX, s32 offsetY) {
616 s16 *buffer;
617 struct UiRenderWork *canvas;
618 u32 cell;
619 s32 vram;
620 s32 src;
621 s32 dst;
622 s32 phase;
623
625 canvas = UI_WORK;
626 UiText_WidenByteString(text, (u16 *)buffer);
627
628 cell = ((work->y + ((u32)offsetY >> 3) + 1) << 5) +
629 (work->x + ((u32)offsetX >> 3)) + 1;
630 if (cell < 32 * 20) {
631 // Inside the tilemap.
632 vram = (s32)UI_TILEMAP_VRAM;
633 cell *= 2;
634 dst = vram + cell;
635 src = (s32)canvas->tilemap + cell;
636 phase = offsetX & 7;
637 UiText_RenderStringTiles((u16 *)buffer, (u16 *)src, (u16 *)dst, phase);
638 MemFree(buffer);
639 }
640}
641
642/// Draws a byte string into a window's tilemap at pixel (x, y) of its
643/// interior, rounded down to tiles.
644/// Bytes widen to character codes; pixel coordinates round down to tile
645/// coordinates.
646void UiText_DrawStringInWindow(const u8 *text, struct UiWindow *window, u32 x,
647 u32 y) {
649 UiText_WidenByteString(text, buffer);
650 x >>= 3;
651 y >>= 3;
652 UiText_RenderWideStringInWindow((s16 *)buffer, window, x, y);
653 MemFree(buffer);
654}
655
656/// Draws a number (width as UiText_FormatNumber) into a text canvas window at
657/// pixel (x, y).
658void UiText_DrawNumber(s32 value, s32 width, struct UiWindow *window, s32 x,
659 s32 y) {
660 u8 numberText[UI_NUMBER_BUFFER_SIZE];
661
662 UiText_DrawString(UiText_FormatNumber(numberText, value, width), window, x,
663 y);
664}
665
666/// Draws a number (width as UiText_FormatNumber) as tiles in a window at pixel
667/// (x, y) of its interior.
669 const struct UiWindow *window, s32 x, s32 y) {
670 u8 numberText[UI_NUMBER_BUFFER_SIZE];
671
672 UiText_DrawStringAtOffset(UiText_FormatNumber(numberText, value, width),
673 window, x, y);
674}
675
676/// Draws a number (width as UiText_FormatNumber) into a window's tilemap at
677/// pixel (x, y) of its interior.
678void UiText_DrawNumberInWindow(s32 value, s32 width, struct UiWindow *window,
679 s32 x, s32 y) {
680 u8 numberText[UI_NUMBER_BUFFER_SIZE];
681
682 UiText_DrawStringInWindow(UiText_FormatNumber(numberText, value, width),
683 window, x, y);
684}
685
686/// Draws a four-digit number after a two-glyph sign (window tiles 0x1d and
687/// 0x1e, or 0x1f and 0x1e with variant set) as tiles in window work at pixel
688/// (offsetX, offsetY) of its interior.
689void UiText_DrawPrefixedNumberAtOffset(s32 value, const struct UiWindow *work,
690 s32 offsetX, s32 offsetY, s32 variant) {
691 u8 formatted[UI_NUMBER_BUFFER_SIZE];
692 s16 output[8];
693 u8 *text;
694 s32 index;
695 u32 cell;
696 struct UiRenderWork *canvas;
697 s32 vram;
698 s32 src;
699 s32 dst;
700 s32 phase;
701
702 canvas = UI_WORK;
703 text = UiText_FormatNumber(formatted, value, 4);
704#if (LANGUAGE == LANGUAGE_SPANISH) || (LANGUAGE == LANGUAGE_FRENCH) || \
705 (LANGUAGE == LANGUAGE_ITALIAN)
706 if (variant == 0) {
707 output[0] = 0xf01d;
708 output[1] = 0xf01e;
709 } else {
710 output[0] = 0xf01f;
711 output[1] = 0xf005;
712 }
713#else
714 if (variant == 0) {
715 output[0] = 0xf01d;
716 } else {
717 output[0] = 0xf01f;
718 }
719 output[1] = 0xf01e;
720#endif
721 for (index = 0; index <= 4; index++) {
722 output[index + 2] = text[index];
723 }
724 output[6] = 0;
725
726 cell = ((work->y + ((u32)offsetY >> 3) + 1) << 5) +
727 (work->x + ((u32)offsetX >> 3)) + 1;
728 if (cell < 32 * 20) {
729 // Inside the tilemap.
730 vram = (s32)UI_TILEMAP_VRAM;
731 cell *= 2;
732 dst = vram + cell;
733 src = (s32)canvas->tilemap + cell;
734 phase = offsetX & 7;
735 UiText_RenderStringTiles((u16 *)output, (u16 *)src, (u16 *)dst, phase);
736 }
737}
s32 UiText_BuildRenderEntries(s32 script, s32 clear)
Decodes message script into the ring of decoded text (UiRenderWork.entries) and returns where it star...
Definition decode.c:276
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
u8 * UiText_FormatNumber(u8 *buffer, s32 input, s32 width)
Writes value as decimal text into buffer (14 bytes) and returns where the text starts.
Definition glyphs.c:470
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,...
Definition glyphs.c:409
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,...
Definition glyphs.c:258
const u8 gUiText_GlyphWidths[]
const u8 gUiText_ColourPens[]
void * Runtime_BumpAllocateAlternatePool(s32 size)
As MemAlloc, but tries EWRAM first.
Definition heap.c:140
void * MemAlloc(s32 size)
Allocates size bytes (rounded up to words) with no slot, from IWRAM when they fit and EWRAM otherwise...
Definition heap.c:115
#define BG_CHAR_BLOCK(n)
Definition io_reg.h:166
#define TILE_SIZE_4BPP
Definition io_reg.h:168
#define REG_DMA3
Definition io_reg.h:153
static s32 Iwram_FillWords(void *destination, s32 size, u32 value)
Definition iwram_call.h:59
static s32 Iwram_ClearWords(void *destination, s32 size)
Definition iwram_call.h:55
void MemFree(void *buffer)
char ResourceId_WindowTiles
u8 gWindowWork[]
The window system's work: the windows' tilemap, the windows, the three text channels,...
Definition window.h:19
u16 tilemap[640]
the windows' BG tilemap, 32 by 20 tiles
Definition window.h:20
u8 alt
1 lets text use 256 tiles, adding tiles 0x200 to 0x27F
Definition window.h:30
u8 level
text tiles' palette; 15 by default, 14 or 5 for low HP
Definition window.h:41
u16 entries[RENDER_ENTRY_MASK+1]
decoded text, a ring of codes
Definition window.h:46
u16 tileCursor
the text tile the next search for a free one starts at
Definition window.h:29
u16 count
where the next code goes in entries
Definition window.h:48
u16 colour
the current channel's, copied in to draw
Definition window.h:45
u16 outline
the current channel's, copied in to draw
Definition window.h:44
u8 tileAttributes[256]
Per text tile (tiles 0x80 to 0xFF, then 0x200 to 0x27F): bit 0 once allocated, bit 1 while the tilema...
Definition window.h:28
A window: a framed rectangle of the tilemap with its sprite outputs, its opening or closing animation...
Definition uiwindow.h:11
u16 y
tiles
Definition uiwindow.h:16
u16 x
tiles
Definition uiwindow.h:15
void * Resource_GetTableEntry(s32 index)
Returns the ROM address of resource index from the resource directory.
Definition system.c:150
#define RENDER_ENTRY_MASK
Definition tbs_edition.h:68
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.
Definition text_tiles.c:646
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).
Definition text_tiles.c:538
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...
Definition text_tiles.c:689
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).
Definition text_tiles.c:599
void UiWork_SetRenderWord(u16 value)
Sets the text style (UiRenderWork.outline) of drawn text.
Definition text_tiles.c:531
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:...
Definition text_tiles.c:365
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.
Definition text_tiles.c:614
void UiWork_SetAltFlagAndClearTable(s32 allowAlternateTiles)
Frees every text tile, and with flag set lets text tiles take the second tile range (0x200 to 0x27f) ...
Definition text_tiles.c:329
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,...
Definition text_tiles.c:678
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,...
Definition text_tiles.c:276
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.
Definition text_tiles.c:668
static __inline__ void UiText_WidenByteString(const u8 *input, u16 *output)
Copies a zero-terminated byte string into the text renderer's halfwords.
Definition text_tiles.c:585
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...
Definition text_tiles.c:12
void UiWindow_MarkVisibleTileAttributes(void)
Marks the text tiles the tilemap shows, and frees those it no longer shows.
Definition text_tiles.c:299
UNUSED void UiRender_ReservedNoOp(void)
Nothing calls it.
Definition text_tiles.c:360
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,...
Definition text_tiles.c:82
void UiWork_SetParamNibble(s32 param)
Sets the text colour (0 to 15) of drawn text.
Definition text_tiles.c:524
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.
Definition text_tiles.c:552
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,...
Definition text_tiles.c:658
signed int s32
Definition types.h:14
unsigned int u32
Definition types.h:15
signed char s8
Definition types.h:10
signed short s16
Definition types.h:12
unsigned short u16
Definition types.h:13
#define UNUSED
Definition types.h:22
unsigned char u8
Definition types.h:11
#define UI_TILEMAP_VRAM
The UI tilemap in VRAM (BG screen block 4), which UiWork_UploadDirtyBlocks copies the work block's ti...
Definition window.h:51
#define UI_WORK
Definition window.h:267
#define DMA_COPY32(count)
The DMA control word that copies count words.
Definition window.h:112
@ UI_TILE_FRAME_RIGHT_TEE
the right edge meeting a line
Definition window.h:96
@ UI_TILE_DIVIDER_HORIZONTAL
Definition window.h:91
@ UI_TILE_FRAME_LEFT_TEE
the left edge meeting a line
Definition window.h:95
@ UI_TILE_FRAME_BOTTOM_TEE
the bottom edge meeting a line
Definition window.h:94
@ UI_TILE_FRAME_LEFT
Definition window.h:80
@ UI_TILE_FRAME_RIGHT
Definition window.h:81
@ UI_TILE_FRAME_BOTTOM
Definition window.h:78
@ UI_TILE_FRAME_TOP
Definition window.h:75
@ UI_TILE_DIVIDER_TEE_LEFT
a horizontal line leaving left
Definition window.h:89
@ UI_TILE_FRAME_TOP_TEE
the top edge meeting a line
Definition window.h:93
@ UI_TILE_DIVIDER_CROSS
Definition window.h:90
@ UI_TILE_DIVIDER_TEE_DOWN
a vertical line leaving below
Definition window.h:85
@ UI_TILE_DIVIDER_TEE_RIGHT
a horizontal line leaving right
Definition window.h:88
@ UI_TILE_DIVIDER_TEE_UP
a vertical line leaving above
Definition window.h:86
@ UI_TILE_DIVIDER_VERTICAL
Definition window.h:92
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