Tv

Sound Counter, copy the first three lines of the BASIC program. You may change the amount of string space CLEARed and the variables which are defined as integers. The variable Z must be an integer for disk users (see disk modifications at the end of the program). Remember not to reuse A$ in your program. The first three lines pack the machine language routine into a string and make the USR definition.

If you want the program to wait for sound input, put the USR statement in a loop like this:

When the loop falls through, X will contain the number of distinct sounds.

The cassette player will take a little preparation for sounds to be registered through the microphone. If you have the early model cassette players (CTR-41), simply unplug the dummy plug in the microphone jack. For newer models, unplug the auxiliary cable. For both models, take the cassette tape out of the player, hold down the write protect sensor lever (the lever on the left inside of the cassette cartridge area), and press the record and play buttons. If the motor control plug is still in, nothing will happen. The program will turn the cassette player on when it needs to hear something. It is wise to unplug the smaller grey plug to keep the capstan roller from getting a dimple.

Let's look at how to use the BASIC program that I gave you. Imagine that you invited friends over for a game of Scrabble. There are four of you and you are going to play in the room with your computer. Obviously, moving the computer to the card table would be trouble enough, but there would also be little room left for the four of you. Therefore, instead of nasty pencil and paper, you will impress your friends with the remote control sound scoring program. After deciding the order of play, you casually walk over to the computer and type RUN. (Always have your program loaded before your guests arrive. No one is favorably impressed by program loading problems.) The program asks for the number of players. You answer four (the program will handle 10 without modification). Next, enter the names of the players in the order they will play. (Be sure to use cutesy nicknames—that always gives a more personal touch.) The program will display the screen which gives the codes used to clap in the scores, one digit at a time. (0 is 10 claps and a negative sign is 11 claps. The negative sign may occur before, after or between digits.) You should quickly pass over this screen. Make them think you know what you are doing. Prepare your cassette player to receive sounds (see above).

Take your seat now and play the game. After the first person scores, clap your hands three times to get the computer's attention. It should respond with the player's name (in double width characters, so you can read it from across the room). Clap in the first digit of his score. After a slight delay, the computer will respond with the correct digit. Clap in the second digit if his score is more than one digit long. After his score is in, wait for a bit and the computer will respond, "CLAP 3 TIMES TO CONFIRM." If the score is correct, clap three times and the cumulative scores of all the players will be shown. If the score is not correct, don't clap at all. A "NOT CONFIRMED" message will be shown and the program will loop back and wait for the score to be reentered (after three claps). Play may be continued indefinitely and each player's score will be updated and displayed.

If your Scrabble games are like ours, the extraneous noise level can get pretty high at times—high enough to make the computer think that you may be talking to it. This is the reason three claps are used to get into the scoring routine and three claps to confirm the score. Of course, a carefully disguised, "Ha ha ha, ha ha, ha ha, ha ha ha" could be used to better your score by 22. (Use only if necessary.)

For those who are interested, let me give some more details about the BASIC program.

The first POKE in line 10 is the famous READ error fix. Without it, some Model I computers will READ in the first DATA statement value repeatedly if the computer has not performed an INPUT statement since power up.

The machine language program is stored in string space. Because of the way I built the string, you must CLEAR at least twice as many bytes as the machine language routine contains. The "X=FRE(A$)" statement is a very important one that is often left out of discussions of string packing. If you wish to set the USR branch address only once, it is imperative that your machine language string not move around after the definition has been made. It must be packed into the very top of string space. Building the string fills the string space with garbage (each reassignment of A$ in the READ loop becomes garbage). The "X=FRE(A$)" statement forces garbage collecting and puts A$ at the very top of the string space. If this statement was left out and string packing was forced after the USR assignment in line 15, the machine language string would move and the USR definition would no longer be valid.

To understand the POKE statements in line 15, you must understand the VARPTR format of strings. The first byte is the length and the last two bytes define the address in the string space area. The POKE statements simply assign that address to the USR branch. Because the disk USR branches are located elsewhere in memory (in the disk version), I first assign the address to a variable, then use disk BASIC's DEFUSR command with that variable (see lines 180 to 220).

Line 30 prints the title and requests the number of players.

Line 40 reads in each player's name and assigns it to the array N$().

Line 50 prints directions for data entry.

Line 60 sets up the master FOR... NEXT loop for the number of players.

Line 70 clears the screen, sets double width mode and prints each player's name and score (the scores are in array S(), an array parallel to the name array).

Line 80 prints the "CLAP 3 TIMES" prompt with the player's name.

The first part of line 90 loops until three claps are registered. It sets this score (T!) to zero and sets the sign flag (S) positive.

Line 100 sets the timer variable (U) to zero.

Line 110 loops until a sound is registered or the timer variable U reaches 150. If U reaches 150, it is assumed that the score is zero and a branch is made to the "confirm routine" in 140.

Line 120 checks for validity of the digit (less than 12). If it is not valid, it branches back to the score display routine (line 70). If the digit is valid, it checks to see if it is the sign (code 11). If so, the sign flag is set negative and the minus sign is displayed; otherwise it checks for the zero (code 10), and sets the variable to zero if true.

Line 130 accumulates the digits and stores them in real value in T! It prints the digit itself (ignoring leading and trailing spaces). Finally, it loops back for another digit (line 100).

Lines 140-160 are the confirm routine. If three claps are not registered in a certain amount of time, the datum is considered invalid and the program loops back to try again.

If the datum is confirmed, the player's score is updated and the next player is set. (If the master FOR . . . NEXT loop runs out, it is reset to player 1.)

If you've hung in there this long, then you must be ready for the discussion of the machine language routine.

The code is completely relocatable. This is necessary for any routine that is to be packed. The routine does not take any parameters from BASIC (hence no CALL 0A7FH at the beginning of

0 0

Post a comment