Half-Byte Tiny Basic – Sample Code

Kaliedoscope, v3
This code will display a randomly changing pattern while randomly exploding the middle.
100 CLS
110 X=RND(79)
120 Y=RND(47)
130 P=RND(79)
140 Q=RND(47)
150 SET X,Y
160 SET 79-X,Y
170 SET 79-X,47-Y
180 SET X,47-Y
190 RESET P,Q
200 RESET 79-P,Q
210 RESET 79-P,47-Q
220 RESET P,47-Q
230 Z=RND(100)
240 R=RND(20)
250 IF Z>92 CIRCLE 40,24,R,1
260 IF Z>92 FOR I=1 TO R
270 IF Z>92 CIRCLE 40,24,I,0
280 IF Z>92 NEXT I
290 GOTO 110

Letter Drop Code
This code shows how you can cause letters to drop from the top of the screen. Lines 200 to 270 assign the ASCII value of the letter to drop to the A variable and then calls the subroutine (at line 900) to actually make it fall.
200 X=7:CLS
210 A=67:GOSUB 900
220 A=79:GOSUB 900
230 A=78:GOSUB 900
240 A=83:GOSUB 900
250 A=79:GOSUB 900
260 A=76:GOSUB 900
270 A=69:GOSUB 900
400 STOP

890 #This is what makes the letters fall
900 FOR Y=0 TO 6
910 CURSOR X,Y
920 PRINT CHR(A);
930 DELAY 500
940 CURSOR X,Y
950 PRINT ” “;
960 NEXT Y
970 CURSOR X,7
980 PRINT CHR(A);
985 X=X+1
990 RETURN

Dice roll
This code, converted from Sinclair ZX81 Basic, shows a dice roll
100 CLS
110 X=1
120 Y=39
130 T=X+X
140 F=T+T
150 D=RND(6)+X
160 CLS
170 GOSUB 1000
180 DELAY 2000
190 GOTO 150
1000 IF D=2 SET X,Y
1005 IF D>=4 SET X,Y
1010 IF D=6 SET X,Y+T
1020 IF D>=3 SET X,Y+F
1030 IF D=1 SET X+T,Y+T
1032 IF D=3 SET X+T,Y+T
1034 IF D=5 SET X+T,Y+T
1040 IF D>=3 SET X+F,Y
1050 IF D=6 SET X+F,Y+T
1060 IF D=2 SET X+F,Y+F
1062 IF D>=4 SET X+F,Y+F
1070 RETURN

Hurkle
This is the classic game from the 1970’s
10 ?”HURKLE”
20 ?”FOR Half-Byte Tiny BASIC”
99 # Converted to TINY BASIC by George Gray
100 # HURKLE – PEOPLE’S COMPUTER COMPANY, MENLO PARK CA
110 N=5
120 G=10
210 ?
220 ? “A hurkle is hiding on a”;G;”by”;G;”grid. Homebase”
230 ? “on the grid is 0,0 and any gridpoint is a”
240 ? “pair of whole numbers separated by a comma. Try to”
250 ? “guess the hurkle’s gridpoint. You get”;N;”tries.”
260 ? “After each try, I will tell you the approximate”
270 ? “direction to go to look for the hurkle.”
280 ?
285 A=RND(G)
286 B=RND(G)
310 FOR K=1 TO N
320 ? “Guess #”,K;
330 INPUT X
335 INPUT Y
340 IF ABS(X-A)+ABS(Y-B)=0 GOTO 500
350 # ? INFO
360 GOSUB 610
370 ?
380 NEXT K
410 ?
420 ? “Sorry, that’s “,N,” guesses.”
430 ? “The hurkle is at “,A,”,”,B
440 ?
450 ? “Let’s play again. Hurkle is hiding.”
460 ?
470 GOTO 285
500 #
510 ?
520 ? “You found him in “,K,” guesses!”
530 FOR I=1 TO 10
532 TONE 1000,75
534 NEXT I
535 ?
540 GOTO 440
610 ? “Go “;
620 IF Y=B GOTO 670
630 IF Y 640 ? “south”;
650 GOTO 670
660 ? “north”;
670 IF X=A GOTO 720
680 IF X 690 ? “west”;
700 GOTO 720
710 ? “east”;
720 ?
730 RETURN

Hurkle is a classic Basic game from the 1970’s. It is basically a ‘guess the number’ game, only there are two numbers to guess instead of one. There is a variation called Hunt the Wumpus and many others. It is fun little game. This version was adapted from the Creative Computing Magazine collection of games called 101 Computer Games in Basic. It has a few techniques that you should notice: using PRINT’s formatting features, using the question mark for the word PRINT, computing the direction for the two numbers and, finally, the subroutine. Some enhancements you could make include displaying the 10,10 grid, either graphically or textually; doing away with text only nature and use the Nunchuck to decide where to move; make it realtime…have the Hurkle move. There are many ways to enhance the game. Memory and imagination are the only boundaries. As is, there are about 200 bytes free, if you leave out the text (lines 220 to 270). You can change the size of the grid by changing the value of ‘G’ at the beginning (line 120) and the number of turns by changing the value of N (line 110).

Advertisements

One thought on “Half-Byte Tiny Basic – Sample Code

  1. Pingback: Half-Byte Console, now available | ye old Half Byte blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s