Commodore Ascii Codes

For the rest of this book, ASCII will mean Commodore ASCII—the codes that are actually used by your computer.

Table 6-1 shows the effect of ASCII codes 0-255 when the upper-case-and-graphics mode has been selected. Table 6-2 shows the effect of codes 0-255 when the upper-and-lower-case mode has been selected.

By comparing these tables, you will see that more graphics characters are available in the upper-case-and-graphics mode because lower-case letters are not available in that mode. The upper-and-lower-case mode has fewer graphics characters because both upper- and lower-case letters are available.

In this book, and in most programming, the upper-case-and-graphics mode is used unless the program requires upper- and lower-case letters to. be displayed on the screen.

Table 6-1 shows that the ASCII code for letter A is 65. To send that code number from the keyboard to the computer, you must indicate that it is an ASCII code, not the number 65. That is done by the BASIC word CHR$(). CHR$ is pronounced character string.

The ASCII code number is placed inside the parentheses. For example, CHR$(65) tells the computer that it has received ASCII code number 65. It doesn't tell the computer what to do with that code.

The BASIC word PRINT is used with ASCII codes to tell the computer to do whatever the code represents. If the code represents a printable character, it will be displayed on the screen. If the code represents some other action, such as a carriage return, that will be done. Earlier, I said that the word PRINT really means do it. This is another example of that meaning.

With the computer in the upper-case and graphics mode, enter

PRINT CHR$(65)

The computer interprets that statement to mean print the character represented by ASCII code 65. In the upper-case-and-graphics mode, that displays a capital letter A on the screen.

Press Commodore-SHIFT to change character sets. The letter A changes to a lower-case a. All characters on the screen change to the upper-and-lower-case mode.

Switch back to upper-case-and-graphics mode. Enter

It prints a list of two items. Both are the letter A. You are displaying the letter without actually pressing its key. Enter

The computer printed an A, performed a carriage return, and then printed another A. Table 6-1 shows that CHR$(13) is a carriage return. ASCII code 13 is one of the control codes.

WHY ARE THERE SO MANY WAYS TO DISPLAY CHARACTERS?

You can display a character by pressing that key on the keyboard, in the immediate mode. That is done so you can see what you typed and correct it if necessary before entering it.

You can display one or more characters by a PRINT statement that includes the characters to be displayed, such as PRINT "A" or PRINT 123. That's an essential part of programming.

If a distant computer tells your computer to PRINT CHR$(65), it will display an A. If you tell your computer to do that, it will make the same response.

You can display graphics symbols, such as a circle, by a PRINT statement that prints that graphics symbol or a PRINT statement that prints the ASCII code number for that symbol, such as CHR$(209).

You can produce a carriage return by pressing the RETURN key on the keyboard, by printing a control symbol or printing CHR$(13).

You can display one or more characters by assigning the characters to a variable name and then printing the variable name. For example: X=7: PRINT X. This method is also an essential part of programming.

All of these methods exist for logical reasons. You can write better and more powerful programs by knowing and using these methods. Use the best method for whatever you want the program to do. If it is not clear that one is best, use the method you prefer.

0 0

Post a comment

  • Receive news updates via email from this site