Graphics


Card Games In Graphic Modes 1 and 2

William D. Seivert

With this subroutine, you can mix the four suit symbols with letters and numbers in graphics modes 1 or 2, [=heart, ]=club, /=diamond, and V=spade.

Have you ever wanted to design a card game to play in Graphics Mode 1 or 2, only to find that you couldn't get the suit characters (heart, spade, diamond, and club) to appear on the screen at the same time as the characters A, K, Q, J, and the digits 0 through 9?

Graphics modes 1 and 2 use the character base pointer (CHBAS, location 756) to point to the table defining the character sets. When location 756 contains 224, you get uppercase letters and the digits and normal punctuation. When you set it to 226, you get small letters and the graphics characters, including the characters for the suits. Since only 64 characters are available in these modes, you can't have both at the same time!

Try this in Direct Mode:

GRAPHICS 2: PUT #6,ASC(")"):POKE 756,226

When the POKE takes effect, the right bracket changes to its graphics equivalent. (So does the rest of the graphics window!) The table to look at is in the BASIC Reference Manual, Table 9.6.

The 224 or 226 that you POKE into location 756 is the Most Significant Byte (MSB) of the start address of the character set table. Since these tables are in ROM, they cannot be changed directly. Also, since only the MSB of the address is used, the table must begin on a page boundary.

It takes a lot of work and space in BASIC to hold the table and ensure that it is on a page boundary. However, there is an easier way!

The following BASIC subroutine will do the job.

Now I'll explain what this does by line number.

25000,25001 Just some documentation (Remember that GOSUB 25000 will work; BASIC will skip the REMs).

25010 Location 106 contains RAMTOP, the number of pages of RAM. Subtracting 8 leaves enough room for graphics modes 0, 1, and 2, and allows space for the new character set table. Thus, J is the address where the table will start.

25020 Locations 144 and 145 contain MEMTOP which is BASIC's current top of memory. If, at the time the subroutine is called, the program is already too big to allow for the new table, we won't do it and leave. This implies that all arrays should be DIMensioned and variables defined before calling the subroutine.

25030,25040 This loop moves the original table (57344 = 224*256) from ROM to the location in RAM.

25050 Each character uses 8 bytes (1 byte per TV scan line) to define which pixels should be on for the given character. Adding 472 (= 59*8) to the starting address gives the address of the left bracket ([) character.

25060 The TRAP is used so that if the subroutine is called more than once in a run, we won't get ERROR 9 (String DIM Error). We need 32 bytes for string ST$ (4 characters times 8 bytes per character). Then we cancel the TRAP so other errors don't come to this routine.

25070 Now we define the bytes for the four suit characters. The keying sequence after ST$ =" is: CTRL comma, 6, ESC TAB, ESC TAB, greater-than ESC CTRL minus, CTRL H, CTRL comma, CTRL comma, CTRL X, less-than, ESC BACK-S, ESC BACK-S, less-than, CTRL-X, CTRL comma, CTRL comma, ESC CTRL minus, ESC CTRL minus, lowercase W, lowercase W, CTRL H, ESC CTRL minus, CTRL comma, CTRL comma, CTRL X, less-than, ESC BACK-S, ESC BACK-S, CTRL X, less-than, CTRL comma, and the closing double quotes.

25080 Start the loop to put the bytes.

25090 Convert one character at a time to its ATASCII value and POKE it in the appropriate location.

25100 Finish the loop.

25110 Put the address of the new table in CHBAS (location 756).

25120 Return to the caller.

That's all there is to it! Of course this method will work for any characters you want to redefine. All you have to do is decide which characters you can do without, and the bit patterns of the characters you want.

With the above routine as it is, if you want a heart, use the left bracket, etc. Use PUTs to the screen for the characters you want. Remember that you can use inverse-video and/or add values to change colors.

For example, without using any SETCOLOR statements, try

GRAPHICS 2: GOSUB 25000
PUT #6,ASC("inverse video of right bracket")

to get a blue Club, or

PUT #6,ASC("inverse video of left bracket") + 32

to get a red Heart.

A Few Words of Warning

Every time you change graphics modes (even GRAPHICS n + 32 which doesn't change the screen), the Operating System resets location 756 to 224, pointing to the normal character set. If you want the suit characters back again, just GOSUB 25110.

Also, if you use a graphics mode greater than 2, you might destroy the table. So you will probably want to GOSUB 25000 after coming out of graphics mode 3 or above.

Of course you do not have to use the same line numbers, and you might want to remove the memory overlap check at line 25020, but that's up to you.

Try it! You'll like it!

Listing: Display card symbols in graphics 1 and 2

Download / View (Listed BASIC)


Return to Table of Contents | Previous Section | Next Section