Printing Text

From WikiPrizm
Revision as of 21:14, 2 August 2012 by Ahelper (talk | contribs) (Added two new functions)
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 Mini font

The Prizm doesn't just let you print 8 lines of giant letters, it also lets you print in the Mini font using PrintMini. This function is a bit more complex, but has its advantages. Here is an example of how to print in the Mini font:

int x = 0; // This function uses pixels
int y = 0;
PrintMini(&x, &y, "abcdEFGH1234!@#$.,;'", 0, 0xffffffff, 0,0,COLOR_DARKGREEN, COLOR_GRAY, 1,0);

As you can see, this function uses pointers. This is because PrintMini will update the position to after the last printed character. The second thing to note is that the string doesn't need garbage letters. Now, this function doesn't have complete documentation, but enough exists to use it. Also note that this function doesn't use TEXT_COLOR_* colors, but instead RGB565 colors.

Printing in MiniMini font

NOTE: This function doesn't exist in libfxcg yet! If you liked the Mini font because it is small, you should know that there is an even smaller 10 pixel high font. This can be drawn using PrintMiniMini. It is a mix of PrintMini and PrintXY for the parameters. Here is a sample:

 int x = 0;
 int y = 0;
 PrintMiniMini(&x, &y, "abcdEFGH1234!@#$.,;'", 0b00010000, TEXT_COLOR_CYAN, 0);
 x = 0;
 y = 12;
 PrintMiniMini(&x, &y, "abcdEFGH1234!@#$.,;'", 0, TEXT_COLOR_CYAN, 0);

You may wonder why I have it executing twice. This is simply to show off the fact that the MiniMini font can be styled as bold at the same height. You should be familiar to the position pointers and the string. Unlike PrintMini, this function uses the 3 bit colors.

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