PrintXY

From WikiPrizm
Revision as of 09:51, 15 May 2014 by Tari (talk | contribs)
Jump to navigationJump to search

Synopsis

Syscall: PrintXY(int x, int y, char* string, int display_mode, int text_color)

Draws a line of homescreen-style text in VRAM.

Inputs

  • int x - The "homescreen" column of the first character of the string, 1 to 20
  • int y - The "homescreen" row, 0 to 7
  • char* string - The string to display (see note 1 below)
  • int display_mode - Bitmask (note 2 below)
  • int text_color - The color of the characters (see note 3 below)

Outputs

Text displayed to the screen

Examples

PrintXY(1, 1, "XXHello World!", TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);
char buffer[] = "XXHello World!";
PrintXY(1, 4, buffer, TEXT_MODE_INVERT, TEXT_COLOR_RED);

PrintXY(1, 2, "Hello World!"-2, TEXT_MODE_INVERT, TEXT_COLOR_YELLOW);
char buf[] = "Hello World!";
PrintXY(1, 5, buf-2, TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);

Comments

Note 1: The first two bytes of the string appear to be ignored. It will always work to pad the beginning of your string with characters which will be ignored as in the first set of examples. You may wish to optimize your binary size a little bit by instead subtracting two bytes from the actual string address as in the second set of examples, but there may be certain rare situations where this scheme will cause a crash (see note 5). In most cases this is a safe optimization, and the values of the leading bytes appear to be completely ignored.

Note 2: Display mode 0 is normal, overwrite mode. The rectangle containing each character is cleared. Setting bit 5 (0x20) makes the background not be erased. Setting bit 0 (0x01) makes the text be written in inverse mode. If you want both, bitwise OR the modes together.

You may also use the following, defined in color.h:

  • TEXT_MODE_NORMAL (0)
  • TEXT_MODE_INVERT (1)

When using 0x21 (0x20 | 0x01), the effect isn't the expected where the inverted text is drawn on top of the screen. Instead, it acts like an AND operation where the printed text is used to mask what is currently on the screen (color doesn't matter), printing white elsewhere.

Note 3: Valid colors are defined in color.h and are listed below:

  • TEXT_COLOR_BLACK (0) - Black
  • TEXT_COLOR_BLUE (1) - Blue
  • TEXT_COLOR_GREEN (2) - Green
  • TEXT_COLOR_CYAN (3) - Cyan
  • TEXT_COLOR_RED (4) - Red
  • TEXT_COLOR_PURPLE (5) - Purple
  • TEXT_COLOR_YELLOW (6) - Yellow
  • TEXT_COLOR_WHITE (7) - White

Note 4: Row 0:

A valid input to PrintXY's y parameter is 0, but this is usually not rendered because row 0 is located under the status bar the top of the screen.

Note 5: If the system attempts to read an invalid address you pass to it as a parameter, this will fail. If your program is laid out in memory such that your parameter is less than two bytes after an unmapped memory region, reading the first two bytes will cause a fault. Given the memory map for addon execution these situations should be very rare, but for strict correctness always provide the leading bytes.