25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Payments   Humor   Music

Simple ping pong simulator program for the Heathkit H-89 computer, Microsoft MBASIC

PINGDEMO (ping as in Ping Pong)

The accompanying program demonstrates a method of using Microsoft MBASIC to produce a paddle and ball game simulation using the Heathkit H-89's H-19 terminal commands.

The direction of paddle movement is controlled by the Home and arrow keys on the H-89 terminal.

Probably the most interesting feature of the program is that by the use of the INP statement, it simulates the operation of a joystick. Once you have struck one key, the paddle will continue to move in the chosen direction until you either stop it with the Home key or change its direction with an arrow key.

If your terminal does not have arrow keys, then the ASCII codes that are referenced in lines 130-210 can be changed to relate to regular letter keys on your terminal. The ASCII codes are the numbers from 65 to 72. The number 232 is the input port (terminal) at which the value is tested.

While keeping an unaltered version of the program handy, I have learned a lot about the operation of my H-19 terminal (especially the direct cursor addressing feature) by playing with the step values and the "THEN" clauses that determine what happens when the ball hits the walls (lines 230 and 250). You could also alter the "THEN" clauses regarding paddle movement for some really weird results.

Interesting patterns can be produced by not clearing the screen in line 270.

An interesting note:

When using direct cursor addressing, watch out when you print on the terminal's line 24. After printing, a line feed is automatically printed; this scrolls the page, ruining whatever you previously put at the top of the page. One way to get around this is to put an ESC H command (...;CHR$(27)"H") after the plotted point. This will send the cursor home, and the line feed will be produced there, instead of at the bottom of the page.

PINGDEMO.BAS

5 'PINGDEMO.BAS 
6 'Copyright (C)1982 Steven Whitney.
7 'Initially published by http://25yearsofprogramming.com.
8 'Published under GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY.
10 PRINT CHR$(27)"t": REM SHIFT KEYPAD
20 PRINT CHR$(27)"x5" : REM TURN OFF CURSOR
30 PRINT CHR$(27)"F" : REM GRAPHICS MODE
40 PRINT CHR$(27)"E" : REM CLEAR SCREEN
50 DEFINT A-Z
60 REM INITIAL POSITION SETTINGS
70 REM R=BALL ROW POSITION, C=BALL COLUMN POSITION
80 REM M=ROW POSITION OF LEFTMOST SIDE OF PADDLE, N=COLUMN POSITION
90 REM I AND J ARE STEP VALUES FOR BALL; HIGHER NUMBERS MOVE BALL FASTER.
100 REM STEP VALUES FOR PADDLE ARE INHERENT IN PADDLE MOVEMENT ROUTINES.
110 R=11 : C=11 : I=1 : J=1 : M=1 : N=1
120 REM PADDLE CONTROL VIA SHIFTED KEYPAD (ARROWS)
130 IF INP(232)=32 THEN 330 : REM END GAME
140 REM PADDLE STAYS STATIONARY
150 IF INP(232)=72 THEN M=M : N=N : REM NOT NEEDED, FOR CLARITY ONLY
160 REM MOVE PADDLE VERTICALLY
170 IF INP(232)=65 THEN M=M-1: IF M<1 THEN M=1
180 IF INP(232)=66 THEN M=M+1: IF M>23 THEN M=23
190 REM MOVE PADDLE HORIZONTALLY
200 IF INP(232)=68 THEN N=N-2: IF N<1 THEN N=1
210 IF INP(232)=67 THEN N=N+2: IF N>76 THEN N=76
220 REM BOUNCE OFF LEFT AND RIGHT SIDES
230 C=C+I: IF C>=80 OR C<=1 THEN I=-I
240 REM BOUNCE OFF TOP AND BOTTOM
250 R=R+J: IF R>=24 OR R<=1 THEN J=-J
260 REM PLOT PADDLE POSITION AND PRINT
270 PRINT CHR$(27)"E"CHR$(27)"Y";CHR$(31+M);CHR$(31+N);"aaaaa"
280 REM PLOT BALL POSITION AND PRINT
290 PRINT CHR$(27)"Y";CHR$(31+R);CHR$(31+C);"p";
300 REM BALL AND ANY PART OF PADDLE INTERSECT?
310 IF (R-M)=0 AND C-N<5 AND C-N>-1 THEN  J=-J:PRINT CHR$(7)
320 GOTO 130
330 REM EXIT VARIOUS TERMINAL MODES AND END
340 PRINT CHR$(27)"u" : REM EXIT KEYPAD SHIFT
350 PRINT CHR$(27)"G" : REM EXIT GRAPHICS MODE
360 PRINT CHR$(27)"y5" : REM TURN CURSOR ON
370 END

ANOTHER VERSION:

5 'PINGDEM2.BAS 
6 'Copyright (C)1982 Steven Whitney.
7 'Initially published by http://25yearsofprogramming.com.
8 'Published under GNU GPL (General Public License) Version 3, with ABSOLUTELY NO WARRANTY.
10 PRINT CHR$(27)"t": REM SHIFT KEYPAD
20 PRINT CHR$(27)"x5" : REM TURN OFF CURSOR
30 PRINT CHR$(27)"F" : REM GRAPHICS MODE
40 PRINT CHR$(27)"E" : REM CLEAR SCREEN
50 DEFINT A-Z
60 REM INITIAL POSITION SETTINGS
70 REM R=BALL ROW POSITION, C=BALL COLUMN POSITION
80 REM M=ROW POSITION OF LEFTMOST SIDE OF PADDLE, N=COLUMN POSITION
90 REM I AND J ARE STEP VALUES FOR BALL; HIGHER NUMBERS MOVE BALL FASTER.
100 REM STEP VALUES FOR PADDLE ARE INHERENT IN PADDLE MOVEMENT ROUTINES.
110 R=11 : C=11 : I=1 : J=1 : M=1 : N=1
120 REM PADDLE CONTROL VIA SHIFTED KEYPAD (ARROWS)
130 IF INP(232)=32 THEN 330 
150 IF INP(232)=72 THEN M=M : N=N 
170 IF INP(232)=65 THEN M=M-1: IF M<1 THEN M=1
180 IF INP(232)=66 THEN M=M+1: IF M>23 THEN M=23
200 IF INP(232)=68 THEN N=N-2: IF N<1 THEN N=1
210 IF INP(232)=67 THEN N=N+2: IF N>76 THEN N=76
230 C=C+I: IF C>=80 OR C<=1 THEN I=-I
250 R=R+J: IF R>=24 OR R<=1 THEN J=-J
270 PRINT CHR$(27)"E"CHR$(27)"Y";CHR$(31+M);CHR$(31+N);"aaaaa"
290 PRINT CHR$(27)"Y";CHR$(31+R);CHR$(31+C);"p";
310 IF (R-M)=0 AND C-N<5 AND C-N>-1 THEN  J=-J:PRINT CHR$(7)
320 GOTO 130
330 REM EXIT VARIOUS TERMINAL MODES AND END
340 PRINT CHR$(27)"u" : REM EXIT KEYPAD SHIFT
350 PRINT CHR$(27)"G" : REM EXIT GRAPHICS MODE
360 PRINT CHR$(27)"y5" : REM TURN CURSOR ON
370 END

 

Valid HTML 4.01 Transitional Valid CSS
Yahoo! Search
Search the web Search this site
View content labeling at ICRA.