Printing Text

From WikiPrizm
Revision as of 02:33, 31 July 2012 by Ahelper (talk | contribs) (Initial)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Printing text to the Prizm's screen isn't too easy and straight-forward. This tutorial will show you the ways (that are known) to print information to the screen.

Printing a String

As seen in the Hello World tutorial, PrintXY is used to print text to the LCD. This is only one way to print text on the Prizm. I will go over different methods to print out text below.


PrintXY is useful if you want to print out text to a specific location and you don't mind the limitation on the string parameter. A common usage for PrintXY is for printing static text, like


If you want to use a non-static string, you can get around the string limitation by doing

char buffer[128];
buffer[0] = ' ';
buffer[1] = ' ';

// Do stuff with buffer+2
strcpy(buffer+2, "Hi there");

PrintXY(1,3,buffer,0,0); // ...,0,0); is the same as ...,TEXT_MODE_NORMAL, TEXT_COLOR_BLACK);


PrintXY gives you two ways to customize the printed text, int display_mode and int text_color. Display mode as 0 will set the display to the printed text with a white background. 1 will invert the text, flipping foreground (text_color) with the background (white) colors. 0x20 will OR the text to the screen (the background color is transparent). If you do

PrintXY(1,1,"  Hello",0,TEXT_COLOR_RED);
PrintXY(1,1,"  World",0x20,TEXT_COLOR_BLUE);

You will see the word 'World' printed on top of the word 'Hello'. Lastly, you can have 0x21 as the display mode. This will work as an AND to the screen. If both pixels (what would be drawn and what is already draw) are 'on', or have a color other than white, then the pixel on the screen isn't changed. Otherwise, the pixel on the screen will become white. You can test it yourself by doing

PrintXY(1,1,"  Hello",0,0);
PrintXY(1,1,"  World",0x21,TEXT_COLOR_RED);

You have already seen me using colors when using PrintXY. You can get a list of all colors in the color.h file in the include folder in the PrizmSDK. Note that you can only use the TEXT_COLOR_* ones.

Print_OS and locate_OS

Print_OS works by printing text that starts at a text cursor. the text cursor can be set with locate_OS. Here is an example:

Print_OS("Hello ",0,0);

You will note that the text appears together. This is because Print_OS moves the text cursor when it prints.

This command can have the mode changed just like PrintXY, but not the color.

Printing in Small font

Todo - Find Merth's stuff

Working with Numbers

One thing that is great for debugging, scores for games, etc., is being able to print out numbers. You can use itoa to convert a number to text. Note that itoa is located in the CONVERT_syscalls.h header and to also watch out for the PrintXY string limitation. Here is an example on printing out a number:

#include <display.h>
#include <keyboard.h>
#include <CONVERT_syscalls.h>

int main()
  int number = 12345;
  unsigned char buffer[20]; // Be careful about the size. don't make it too small
  itoa(number, buffer);
  int key;
  while(1) GetKey(&key);

This example uses Print_OS because Print_OS doesn't require 2 garbage characters. This example also uses an unsigned char* buffer rather than a char* buffer. To use PrintXY instead, you can use this:

char buffer[20];
buffer[0] = ' '; // Make garbage bytes
buffer[1] = ' '; 

itoa(number,(unsigned char*)buffer+2); // Leave the garbage bytes alone