home *** CD-ROM | disk | FTP | other *** search
- ZERO PAGE - P R O F E S S O R B I N G O
-
- by Fender Tucker
-
- This is my first foray into the 80-column wilderness of the VDC chip
- and I've got to say in my most Teutonic voice, "I'll be back." The wide
- screen is a stylist's dream and a real boon to programming. As a BASIC 2.0
- programmer, I have been a little leery of the quirks of the 80-column mode,
- but Jon Mattson's CONTROL 80 gave me the utilities I've come to rely on in
- my 64 programs, such as PEEKing, POKEing, screen saving, custom fonting,
- etc. Jon says he automatically installs CONTROL 80 before every 80-column
- programming session, and I second his policy.
-
- The program is not a complicated one, so I thought it might be
- instructional for me to annotate it for those of you who have ideas for
- 80-column programs, but haven't started programming yet. But first, the
- game itself.
-
- I got the idea for a mathematical bingo game from some flash cards for
- youngsters. Instead of the bingo caller simply calling out numbers, how
- about if he called out mathematical expressions that the players had to
- evaluate before they could mark their cards? The rules of bingo stay the
- same: the first player to get five squares in a row, horizontally,
- vertically or diagonally, wins.
-
- My first concern was logistics. Getting two cards on a 40-column
- screen would have been a nightmare, but the huge screen is perfect for it.
- So I began the program by installing CONTROL 80 and drawing the screen. I
- knew I'd need a font so I made one up using a font making program and
- installed it with CONTROL 80's FCOPY command. The font 'evolved' as the
- program progressed and I found I wanted new characters and shapes.
-
- If you look at my code, however, you won't find any screen drawing
- routine. I took the code out after I had the screen as I wanted, AFTER I
- had saved the screen with a simple BSAVE. Now line 101 loads the screen,
- saving code and time (if you have JiffyDOS), at the expense of disk space
- for the 17-block 'scrn' file. This wasn't necessary; I just felt like
- experimenting.
-
- Some of the screen drawing routines still remain as subroutines (lines
- 20-30). I needed these for the square cursors and rectangles.
-
- I wanted the numbers on the cards to follow the standard bingo format:
- under the B, 1 through 15; under the I, 16 through 30, etc. Lines 250-280
- do the job. It's basically a triple-nested loop to generate the array
- d(player,column,row).
-
- Then I worked on the interface (lines 300-390). This is the only
- complicated part of the program and it's complicated only because I wanted
- the keyboard and joystick to work simultaneously. It's not a foolproof
- system and if either player insists on keeping his cursor moving (in other
- words, being an ass) the other player has a sluggish cursor. I originally
- had the keyboard use the CRSR keys but I encountered anomalies when the
- SHIFT key is pressed and the joystick is moved. One of them caused a "break
- in 302" which I've never figured out. So I changed the keyboard interface
- so it uses the number keypad. The 4-5-6-8-ENTER 'diamond' is similar to the
- IBM cursor or the old Apple I-J-K-L diamonds.
-
- About this time I decided that I wanted the game to have levels, so
- that players could make the game as easy or as difficult as they wanted.
- The interface for choosing the level was placed at 900-985. It's a standard
- highlight bar menu except that when you choose a level, all lower levels are
- chosen too. I placed the levels in a natural hierarchy -- at least, to me.
-
- The number of seconds between calls creates what I call a 'frantic
- factor'. Since there are only four expressions showing at a time, if you
- choose a ridiculously short period of time like 2 seconds, each expression
- is shown only for 8 seconds. I find 5 seconds to be about right for a tense
- game; 9 is a much more leisurely pace. Note that the expressions are
- displayed in order from left to right, EXCEPT when a player uses one. Then
- that expression is replaced and the cycle is continued from that rectangle.
- Part of the strategy is to evaluate the expressions that have short lives
- before expressions that will live longer. Once an expression is used, it
- goes away, so if both players can use the expression, it becomes a race.
-
- Finally I came to the algorithms that generate the random expressions
- that appear at the top of the screen. I wanted them to be fast so I put
- them in subroutines with low numbers. Just about all of my programs start
- with some setup lines then GOTO 100, reserving line numbers 20-99 for
- subroutines. The algorithms were a lot of fun; sort of like little logic
- problems. The trick was to insure that numbers from 1 through 75 were
- chosen RANDOMLY, without favoritism for numbers under the B or I over
- numbers under the G or O. Did I do it? I think so; you tell me. The line
- numbers for each algorithm are:
-
- 60 - addition
-
- 62, 63 - subtraction
-
- 64, 65 - multiplication
-
- 66, 67 - division
-
- 68 - hex numbers
-
- 70, 71 - numbers raised to a power
-
- 72-80 - trig functions
-
- One number is u, the other is q, u$ is the expression and v is the value of
- the expression.
-
- Note that LEVEL FIVE (hexadecimal numbers) does not choose an
- expression as the others do. I figured it's tough enough to translate $4A
- to decimal; doing something like $2B + $1C would tax even a Scott Resh or a
- Rick Nash. I think.
-
- Also note that the expressions generated by LEVEL SIX (numbers raised
- to a power) are pared down for speed. I didn't want the program to hang up
- trying numbers like 34^56 hoping to find one whose value was less than 75,
- so I made the first number be 8 or less and the exponent be 3 or less.
-
- LEVEL SEVEN (trig functions) was an afterthought. No one knows the
- value of sin53 but there are are a few identities that are worth
- remembering. Hint: all of the trig functions equal 0, 1/2 or 1.
-
- The last things I did were the bingo check at 400 and the help display
- routine at 500 (after it's initially drawn at 800). There is room below
- BASIC for two stored screens - one at 8192 and another at 12288. Once the
- help screen is drawn, it's STOREd at 12288 and RECALLed when needed, rather
- than redrawn. The current screen is STOREd at 8192. Obviously I'm not a
- renumberer. I use the decimal system to keep track of my routines and
- squash line numbers in as needed, occasionally renumbering by hand. Maybe
- not the best method, but it's mine.
-
- Here are a few lines that merit mention:
-
- 3 : peek(186) is the last I/O device used. Please use this in all LOADSTAR
- programs.
-
- 5 : frees up memory from $1c00 to $4000 for CONTROL 80, screens, ML, etc.
-
- 10-13 : install CONTROL 80 and font
-
- 40-44 : nifty way of changing the tile background. Note that 80-column font
- characters are 16 'wide', unlike 40-column font characters that are 8 wide.
- The background consists of nothing but @ signs, which is defined by the
- first eight bytes of the font at 8192-8199. This routine POSTs (CONTROL
- 80's version of POKE) the data for five other tiles into those bytes
- whenever an expression is evaluated correctly.
-
- 90-92 : my favorite way of drawing dialog boxes. Define top, middle and
- bottom strings (lines 106-109) and use a FOR-NEXT loop for the middae
- string. Then a W=7:GOSUB90 command will draw a box 7 rows high.
-
- 101 : this BLOADS the saved screen into normal RAM and the STORE command
- moves it into placeain the VDC chip. Jon Mattson's memory map of the VDC
- from his CONTROL 80 docs is the most succinct I've seen.
-
- $0000 - 07FF 0 - 2047 Screen
- $0800 - 0FFF 2048 - 4095 Attributes
- $1000 - 1FFF 4096 - 8191 Unused
- $2000 - 2FFF 8192 - 12287 Uppercase/Graphic font
- $3000 - 3FFF 12288 - 16383 Lower/Uppercase font
-
- 102 : I got tired of typing U=INT(RND(1)*75)+1 so I defined a function to
- make life easier. With this function, U=FNR(75) does the same thing. The
- number in parentheses defines the limits of the random numbers generated, 1
- through 75 in this case.
-
- 115 : easy screen swap. Remember the commands STORE 4096,0,8192,0 and
- RECALL 4096,0,8192,0 and you've got windows under control.
-
- 307 : I really like the INSTR function. Define a string of all the hot keys
- and GETKEYA$:K=INSTR(C$,A$):ONKGOTO... does the trick. C$ was defined up in
- line 112.
-
- I hope this annotation helps you get started in 80-column programming.
- If you've done some BASIC 7.0 work you'll notice that I cling to a lot of my
- old BASIC 2.0 ways. If you've done 80-column programming, you're probably
- way ahead of me, although CONTROL-80 gives me a giant leap forward over many
- of the tricky areas. My appreciation of the C-128 grows every issue.
- Commodore has made a colossal blunder in not supporting this machine because
- it's one that will satisfy users and programmers for years to come.
- LOADSTAR 128 will not make that mistake.
-
- FT
- **** End of Text ****