Blog

Relearning MSX #39: Graphic characters and additional quoted symbols

Posted by in How-to, MSX, Retro, Technology | December 16, 2015

relearningMSX39cover

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).

The GRAPH key on a Japanese MSX computer

The GRAPH key on a Japanese MSX computer

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:

Graphic characters on an European MSX (Click to enlarge)

Graphic characters on an European MSX (Click to enlarge)

Graphic characters on an Japanese MSX (Click to enlarge)

Graphic characters on an Japanese MSX (Click to enlarge)

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.

MSX graphic characters

MSX graphic characters

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:

Click to enlarge

Click to enlarge

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:

Click to enlarge

Click to enlarge

One way to print these would be to use the character code:

Click to enlarge

Click to enlarge

However, this impacts readability. It’s easier to just use a backslash followed by the quote character:

Click to enlarge

Click to enlarge

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():

Click to enlarge

Click to enlarge

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).

Summary

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.

Javi Lavandeira’s Patreon page

Leave a Reply

Your email address will not be published. Required fields are marked *


Warning: Illegal string offset 'share_counts' in /www/javi_lavandeira/lavandeira.net/ftproot/htdocs/wp-content/plugins/simple-social-buttons/simple-social-buttons.php on line 477