High-Res Blackjack for the ZX81/TS1000/TS1500

Author(s): Fred Nachbaur
Pub Details: Time Designs Magazine v3 n4 (Volume 3, Issue 4)
Date: May/June 1987
Pages: 23-27
Card drawings: ace, five and jack
Card drawings: ace, five and jack
Card drawings: queen and three face-down cards
Card drawings: queen and three face-down cards

For many years now, we ZX81/TS1000/TS1500 users have had to contend with VVLR (Very Very Low Resolution) graphics. Not any more! With nothing more than a suitable static memory, mapped from 8-16k, we now have true high-resolution graphics for our machines!

By “suitable” I only mean that the static RAM’s data must be accessible during refresh time. If you have a HUNTER Board, you can make a very simple modification to meet this requirement. Simply cut the line between the RAM chips pins 20 and edge connector pin 16A (RD*); bridge the resulting gap with a 4.7k resistor. Now connect a diode with its cathode (banded) end to edge connector 23A (RFSH*), and the other end to the RAM side of the new resistor. Alternately, contact SILICON MNT. COMPUTERS about our “SCRAM” board, which will do the job with no modifications.

Silicon Mountain also has “SCRAM HI*RES EXTENDED BASIC”, which gives you 38 new high-resolution commands from BASIC. The prupose of this series of articles is to give a tutorial on the use of SRAM HI*RES, demonstrating how these new commands can be used to write spectacular graphics software…entirely from BASIC.

Editor’s Note: You can contact Silicon Mountain Computers by writing to: C-12, Mtn. Stn. Group Box, Nelson, B.C., V1L 5P1, Canada. A complete line of interesting products are available for the Sinclair ZX81, TS1000 and TS1500. The “SCRAM” NVM Board is priced at $39.95 postage paid; the “SCRAM HI*RES EXTENDED BASIC” software package is priced at $24.95 ppd.; and other high-resolution graphics programs are available including the games DUNGEON OF YMIR and HIGH-RES CHESS.

Since this article presupposes that you have SRAM HI*RES EXTENDED BASIC, I can already hear charges of “vested interest” in publishing a program that makes use of it. I must plead “no contest”, but also point out that it is common practise for manufacturers in other fields to provide after-sale support via their trade magazines (like TIME DESIGNS). Granted, the SRAM HI*RES manual gives all the basic info on this new operating system, much as your computer manual gives “all you need to know” about your ROM operating system. Still, many users will find it necessary to get additional explanation in the way of articles and sample listings. This article, and the accompanying BLACKJACK listing, will attempt to get you familiar with the use of some of the new SRAM HI*RES commands.

THE DOCUMENTATION

Before we get on with it, here is the documentation for the BLACKJACK program published here. Look over the artwork for this article for an idea of the displays you will be seeing; these are all ACTUAL screen dumps of in-progress games!

Casino signs at night
Casino signs at night

The game of BLACKJACK is one of the most popular casino games, and for a good reason; it is one of the very few casino games where you can actually have odds over the house. A skilled Blackjack player can actually (in the long run) come out ahead, because of an estimated 2% advantage. Compare this to horse racing, with an estimated 25% loss, or lotteries with a typical 50% loss!

GETTING STARTED

Start by hooking up your ZX81, TS1000 or TS1500 (with 8k static RAM and a Timex 16k RAM pack). Note #1: Larger RAMs will work, but you will still need the static RAM in the 8-16k region. Many 64k RAMs WILL NOT work on the 1500, however. Note #2: If you’re using a TS1500, you’ll still need the Timex 16k pack in addition to the internal 16k. This is for the hardware reasons unique to the TS1500.

The first thing we’ll do is enter a program that actually will be run only once! This is because there isn’t enough room in 16k if we include it in the main listing. The purpose of this is to set up a dimensioned string array to hold the character codes for the UDG’s used to print the images of the cards. Incidentally, this little “trick” demonstrates a use for your static RAM even in non-high res programs; use it anytime you need to import or export data (variables) between programs.

Enter LISTING 1. You don’t have to enter the REM lines, they are only provided to help with the graphic characters. Proof the listing, save it to tape just in case you “mess up” later, and run it. This dimensions C$(4,13,7,5), then proceeds to fill it. The characters it is filled with correspond to the UDG (User Defined Graphic) characters that will be set up in the main program. Note the significance of the dimension numbers: “4” (number of suits), “13” (number of cards in each suit), “7” (number of lines in each card image) and “5” (number of columns). Once the array is filled, the contents of the array is POKEd into your static RAM.

Now enter NEW, LOAD the SRAM HI*RES core program, and delete the extraneous lines 3-9999. Now type in line 2 of LISTING 2. Note that this also deletes the 64-column PRINT driver routine, which we won’t be needing in this program. Just for safety’s sake, enter the following POKEs, which prevent accidentally calling the deleted 64 column routine:

POKE 18080,208
POKE 18081,75

Then, LIST 2 and POKE 16419,2. This prevents your listing from getting stuck at line 0. Henceforth, using only LIST (number greater than 2) instead of LIST (only) then, enter the program lines starting at 9900.

Now comes the nice part. Enter RUN 9900. The C$ array will be re-created, and filled with the proper contents from your 8k static RAM board! While we’re at it, we define a few of the important variables that won’t change throughout the program. You can now delete lines 9900 onwards, leaving you only with the line 2 REM and of course the line G000 REM. Henceforth, NEVER USE RUN OR CLEAR, or you will destroy these variables! Though this seems restrictive, look at how much memory we have saved with this approach; the entire contents of LISTING 1!!

ENTERING THE PROGRAM

Now we’re finally set up to enter the program. For your convenience, we’re publishing the entire program in this issue, reserving the detailed tutorials for subsequent issues. This will give you an actual, running program, even if you may not understand how it all works.

I suggest using FAST mode for program entry. The most laborious aspect is entering all the UDG and sprite definitions starting at line 9000, so I suggest you do this first to get it out of the way. If this seems like a lot of work, consider this: you don’t have to design the pictures, break them into individual UDG’s, translate them to hex, debug, modify, and debug again. I already did all that. All you have to do is type in the numbers, proofing and correcting as required.

I should note that the separator characters (or commas) between the hex numbers can be anything you wish; I like commas, but you may prefer spaces, or whatever. Similarly, I used other characters between each UDG (group of 8 numbers) to aid in entering the numbers originally; this merely indicates which character the subsequent UDG defifiniton relates to, and made it easier for me to perfect the images. They have no other significance. Again, you might prefer to replace these with spaces, asterisks, or whatever.

Remember, once you start entering the program you must NEVER use RUN or CLEAR. To guard against disaster, save to tape frequently. A few minutes spent saving, while you go get another cup of coffee or stretch your legs, will be well worth it if your kids stumble over your power cord or your cat jumps onto the RAM pack. After entering each group of lines (e.g. every 100) proof your work. Errors will be easier to spot if you are dealing only with a small group of lines. Be careful to type in the listing exactly; at some points, even an omitted semicolon or space will cause improper program operation.

When you’re all done, and have saved to tape, get ready for the show. Make a final save to tape using GOTO 8900; this will then autorun after the SAVE (or subsequent LOAD). The program initializes all the UDGs and sprites at line 9000, jumping to the actual program start at line 2000 when complete. (Though it looks like it would take a long time to execute all those definitions, i.e., 128 UDGs and 26 sprites, it actually happens in less than a second!)

Next time we’ll dissect the program, explaining why some of those weird commands are there and how they work. Meanwhile, have fun! Don’t spend all your money in one casino!

BLACKJACK

This program simulates the casino game very closely even though it doesn’t allow refinements like doubling bets or splitting aces, but it does have the capability of using multiple decks. Also, it deals from a “true” deck, making it possible for you to practice “counting cards”, a skill which will dramatically improve your odds in an actual game. (Be forewarned however, if you do count cards…do it discreetly since a casino will bounce you if it even suspects you of counting!) Also on that note, I must add the following disclaimer: “High-resolution BLACKJACK is intended for amusement purposes only. It is NOT to be used for actual gambling.”

On loading, the program will start by itself and ask for your “bankroll”. This is how much money you have when you walk into the casino. Enter the amount you’re comfortable with ($100 if you’re conservative, $1000 if you’re a high-roller, etc.). Then enter how many decks you wish the dealer to use. This can be one-deck (makes it easier to count cards, keeping track of how many face cards are still in the deck), or more. According to reports, most casinos use three to five.

After shuffling the cards, the dealer asks how much you wish to bet. The “house limit” is $2000, though you can of course change this by modifying the program. The dealer now deals two cards to himself and to you. His first card is face-up, subsequent cards will be face-down. Your cards will, of course, all be face-up.

Presuming that neither of you got Blackjack (ace and a 10-valued card), you are now asked “HIT?”. If you want another card, press “Y”. If you wish to stay, press “N”. The idea is to get your hand as close to 21 as possible, without going over (“busting”). Face cards count 10, aces count as either 1 or 11. All others count as their face value.

The dealer’s rules follow the convention used in most casinos. If he has less than 17, he must take another card. If he has 17 or more, he must stay. The exception is a “soft 17” (ace plus cards totalling 6), in which case he must take another card. After each hand, the dealer reveals his cards. Press P to play the next hand. (If you don’t want to wait until all the cards have been turned up, simply hold down “P” and the program will go on to the next hand between cards.)

If you get Blackjack, the house pays 2:1. (This is actually a little generous, but I’m a generous kind of guy…) On the other hand, it’s obviously impossible for your computer to “pay off” if you do well, so the game will continue to play until you blow your wad, at which time it will insult you. (Isn’t that a lot like life?) At the end of the game, you can press “P” to play again from the beginning, or “Q” to quit to the normal operating system.

LISTING 1: CARD PATTERN GENERATOR/DOWNLOADER, lines 5-760
LISTING 1: CARD PATTERN GENERATOR/DOWNLOADER, lines 5-760
LISTING 1 continued, lines 770-1151
LISTING 1 continued, lines 770-1151
LISTING 1 continued, lines 1160-2050
LISTING 1 continued, lines 1160-2050
LISTING 1 continued, lines 2060-9010, and LISTING 2: HIGH-RES BLACKJACK, lines 2-130
LISTING 1 continued, lines 2060-9010, and LISTING 2: HIGH-RES BLACKJACK, lines 2-130
Actual screen samples from "BLACKJACK": card hands, "PRESS P TO PLAY", the dealer "Vegas Bob" and the title screen
Actual screen samples from "BLACKJACK": card hands, "PRESS P TO PLAY", the dealer "Vegas Bob" and the title screen
LISTING 2 continued, lines 200-2290
LISTING 2 continued, lines 200-2290
LISTING 2 continued, lines 2300-3410
LISTING 2 continued, lines 2300-3410
LISTING 2 continued, lines 3420-9013
LISTING 2 continued, lines 3420-9013
LISTING 2 continued, lines 9014-9020
LISTING 2 continued, lines 9014-9020
LISTING 2 continued, lines 9021-9120
LISTING 2 continued, lines 9021-9120
LISTING 2 continued, lines 9130-G000 ("DELETE AFTER RUNNING" lines 9900-9980)
LISTING 2 continued, lines 9130-G000 ("DELETE AFTER RUNNING" lines 9900-9980)