In the last few posts we’ve learnt how to control what’s being printed on the screen. Soon we’ll move on to something else (functions!), but first we’re going to see how to handle graphical characters and how to print any character inside a double-quoted string.
The MSX graphic characters
MSX computers have a set of 32 special characters known as graphic characters. These only occupy one position on the screen and one byte in the video RAM, but in order to display them we have to print a 2-byte sequence.
We can type all of these characters by pressing the GRAPH key together with normal alphanumeric characters on the keyboard, but not all the characters generated with GRAPH are 2-byte codes: some are normal characters from the ASCII table (we’ll see these in the future).
Also, it’s important to remember that most of these graphic characters will be different from one MSX to another depending on the country of origin of the computer. For example, a Japanese MSX computer would display several commonly used kanji characters, while an European MSX would display several other useful symbols:
The table below shows the whole list of graphic sequences. The column VRAM code shows the byte written in the computer’s video RAM in the position where the character appears (we’ll see more about this when we start discussing the MSX screen modes), along with the characters themselves for Japanese and European MSX computers. Note that computers from other regions such as Russia, Korea or the Middle East will have their own graphical characters as well.
As you can see, all these sequences consist on the character \1 followed by another character. Because they’re two-byte sequences we can’t use a single call to putchar() to print them on the screen. For example, the following line won’t work (even if we somehow managed to type the graphic character in our program:
putchar('π'); /* Wrong, π is a two-byte sequence */
However, we can output each of the two characters in the sequence using a call to putchar() for each one, or just use a single puts() or printf() call:
Displaying the backslash and quote characters
During the last few posts we’ve learnt that we can display several things using the backslash (or ¥ in Japanese computers) followed by another character:
- C escape sequences (\a, \b, \t, \n, \v, \f, \r)
- Character codes in hexadecimal notation (\x followed by hexadecimal digits)
- Character codes in octal notation (\ followed by octal digits)
There’s one more thing to add to this list:
- Besides the three cases above, a backslash followed by any character outputs the character following the backslash
For example, the sequence ‘\Z’ prints a ‘Z’ on the screen.
This may not seem very interesting until one day we need to print a literal ‘\’ or a double quote (“) on the screen:
One way to print these would be to use the character code:
However, this impacts readability. It’s easier to just use a backslash followed by the quote character:
This technique is known as escaping the quotes (or other characters we want to print). It works in the same way when printing a backslash (or ¥) or single quotes with putchar():
With this there’s no character in the MSX that we can’t print from MSX-C (leaving aside multibyte kanji characters, that we’ll probably leave aside for a while).
In this post we’ve learnt about the MSX graphic characters and we’ve seen that they’re represented as 2-byte codes even though they use a single byte on the video RAM. We’ve seen the character sequences to print each of them and we’ve seen their shapes for both Japanese and European MSX computers. We’ve also learnt how to print backslashes and single/double quotes using puts()/printf()/putchar().
In the next post…
Get ready for some action and lots of fun. The next few posts will be about one of the most powerful features of the C programming language: functions!
This series of articles is supported by your donations. If you’re willing and able to donate, please visit the link below to register a small pledge. Every little amount helps.