User Tools


HUD Rendering

The HUD is rendered using function RenderHud: 802E3D2C/09ED2C. This function reads state to determine which HUD elements to display and calls several other subroutines and makes use of the PrintStr() and PrintInt() functions.

Functions

Lives

RenderHudMarioLives: 802E3744/09E744

PrintStr(0x16, 0xD1, 0x80338380); // "," = Mario
PrintStr(0x26, 0xD1, 0x80338384); // "*" = X
PrintInt(0x36, 0xD1, 0x80338388, *0x8033b260); // "%d"

Coins

RenderHudCoins: 802E37A8/09E7A8

PrintStr(0xA8, 0xD1, 0x8033838C); // "+" = coin
PrintStr(0xB8, 0xD1, 0x80338390); // "*" = X
PrintInt(0xC6, 0xD1, 0x80338394, *0x8033b262); // "%d"

Stars

RenderHudStars: 802E380C/09E80C

int showX = 0; // 0x1F($SP)
if ((*0x803316d4 == 1) || (*0x8032d5d4 & 0x8 == 0)) {
   if (*0x8033b264 < 100) {
      showX = 1;
   }
   PrintStr(0xF2, 0xD1, 0x80338398); // "-" = star
   if (showX) {
      PrintStr(0x102, 0xD1, 0x8033839C); // "*" = X
   }
   PrintInt(0x102+14*showX, 0xD1, 0x803383A0, *0x8033B264); // "%d"
}

Health

RenderHudHp: 802E3654/09E654

Camera

ShowCameraStatus: 802E3B3C/09EB3C

Timer

RenderHudTimer: 802E395C/09E95C

Printing Functions

The two commonly used printing functions PrintStr and PrintInt accept null-terminated ASCII strings as input. It then uses a lookup table to determine which letter to display. This table is located in segment 02 alongside the letters. It notably contains missing entries for the letters J,Q,X,Z.

PrintStr

PrintStr: 802D6554/091554

void PrintStr(int X, int Y, char *string);

PrintInt

PrintInt: 802D62D8/0912D8 This is more of a generic printf() style function that accepts a format and variable arguments.

void PrintInt(int X, int Y, char *format, ...);

Lookup Table

The lookup table for each of the ASCII characters is located at segment address 0x02007700 (80A856 in extended ROM) and contains entries for each 16×16 RGBA texture. The default table has null entries for J,Q,X,Z and uses some symbols for HUD characters.

Before referencing the lookup table, the character in ASCII is converted to an offset within this table by the function at 802D6858/091858.

int convertchar(int ascii)
{
   if (ascii >= 0x41 && ascii < 0x5B) { // 'A' <= ascii <= 'Z'
      return ascii - 0x37;
   } else if (ascii >= 0x61 && ascii < 0x7B) { // 'a' <= ascii <= 'z'
      return ascii - 0x57;
   } else if (ascii >= 0x30 && ascii < 0x3A) { // '0' <= ascii <= '9'
      return ascii - 0x30;
   } else {
      switch (ascii) {
         case 0x20: return -1; break;   // ' '
         case 0x21: return 0x24; break; // '!'
         case 0x23: return 0x25; break; // '#'
         case 0x3F: return 0x26; break; // '?'
         case 0x26: return 0x27; break; // '&'
         case 0x25: return 0x28; break; // '%'
         case 0x2A: return 0x32; break; // '*'
         case 0x2B: return 0x33; break; // '+'
         case 0x2C: return 0x34; break; // ','
         case 0x2D: return 0x35; break; // '-'
         case 0x2E: return 0x36; break; // '.'
         case 0x2F: return 0x37; break; // '/'
      }
   }
   return -1;
}
Hex A Index Seg Addr T Hex A Index Seg Addr T Hex A Index Seg Addr T
20 - - 40 @ - - 60 ` - -
21 ! 24 00000000 41 A 0A 02001400 61 a 0A 02001400
22 - - 42 B 0B 02001600 62 b 0B 02001600
23 # 25 00000000 43 C 0C 02001800 63 c 0C 02001800
24 $ - - 44 D 0D 02001A00 64 d 0D 02001A00
25 % 28 00000000 45 E 0E 02001C00 65 e 0E 02001C00
26 & 27 00000000 46 F 0F 02001E00 66 f 0F 02001E00
27 ' - - 47 G 10 02002000 67 g 10 02002000
28 ( - - 48 H 11 02002200 68 h 11 02002200
29 ) - - 49 I 12 02002400 69 i 12 02002400
2A * 32 02004200 4A J 13 00000000 6A j 13 00000000
2B + 33 02004400 4B K 14 02002600 6B k 14 02002600
2C , 34 02004600 4C L 15 02002800 6C l 15 02002800
2D - 35 02004800 4D M 16 02002A00 6D m 16 02002A00
2E . 36 00000000 4E N 17 02002C00 6E n 17 02002C00
2F / 37 00000000 4F O 18 02002E00 6F o 18 02002E00
30 0 00 02000000 50 P 19 02003000 70 p 19 02003000
31 1 01 02000200 51 Q 1A 00000000 71 q 1A 00000000
32 2 02 02000400 52 R 1B 02003200 72 r 1B 02003200
33 3 03 02000600 53 S 1C 02003400 73 s 1C 02003400
34 4 04 02000800 54 T 1D 02003600 74 t 1D 02003600
35 5 05 02000A00 55 U 1E 02003800 75 u 1E 02003800
36 6 06 02000C00 56 V 1F 00000000 76 v 1F 00000000
37 7 07 02000E00 57 W 20 02003A00 77 w 20 02003A00
38 8 08 02001000 58 X 21 00000000 78 x 21 00000000
39 9 09 02001200 59 Y 22 02003C00 79 y 22 02003C00
3A : - - 5A Z 23 00000000 7A z 23 00000000
3B ; - - 5B [ - - 7B { - -
3C < - - 5C \ - - 7C | - -
3D = - - 5D ] - - 7D } - -
3E > - - 5E ^ - - 7E ~ - -
3F ? 26 00000000 5F _ - - 7F - -

References