Z88 Basic Lander
I tell you, it was no mean feat working out how to get a BASIC program off the Z88. The normal link program I have been using to pull down plain text blog entries is useless because basic programs on the Z88 are saved in binary format. I still haven't managed to get a basic program uploaded to the Z88 either.
The Z88 can control a printer via the serial port and ultimately this is how I did it - you can turn printing on, LIST the program, and then turn listing off. I used minicom on the X60 to capture the output, then edited the start and finish with a little 'vi'.
When running it produces a screen shot
(I've captured this from 'brandy' the open-source BBC Basic Emulator, which the
code loaded and ran happily in without any modifications)
I will explain all in my next post. For now here is the delightful source code (those with a keen BASIC eye will no doubt be able to follow some of my code, although it did rapidly start looking like my mate Charlie's version of Yatzee on the BBC, with colourful single-character variable naming abound...
I will pen a description of this fiendish piece of logic tomorrow, in preparation for a rewrite (I really should be using DEF PROC and DEF FN more) followed hopefully with some extensions both in the output department and possibly an ascent stage (although the thing is very tricky indeed to coax a landing out of!)
90 @%=&0102020A 100 CLS 105 REM LA IS LANDER ANGLE (0=VERTICAL) 110 LA=60 115 REM BR IS BURN RATE 120 BR=0 125 REM F IS TOTAL FUEL/KG 130 F=35000 135 REM X IS RANGE TO LANDING SITE 140 X=-30000 145 REM Y IS HEIGHT/METRES 150 Y=10000 155 REM DX IS HORIZONAL VELOCITY 160 DX=500 165 REM DY IS VERTICAL VELOCITY 170 DY=0.0 175 REM G IS GRAVITY 180 G=10/2 184 REM VT IS VERTICAL THRUST 185 VT = 0 186 REM HT IS HORIZONTAL THRUST 187 HT = 0 190 TIME=0 193 GOSUB 1000 195 REM GET CURRENT KEY BEING PRESSED 200 C$=INKEY$(90) 210 GOSUB 2000 220 GOSUB 3000 230 GOSUB 4000 240 GOSUB 6000 250 GOTO 190 999 REM DISPLAY CURRENT SIMULATION PARAMETERS 1000 REM DISPLAY 1005 PRINT TAB(1,0) "F=" F 1006 PRINT TAB(15,0) "X=" X 1010 PRINT TAB(29,0) "Y=" Y 1020 PRINT TAB(0,1) "DX=" DX 1030 PRINT TAB(14,1) "DY=" DY 1040 PRINT TAB(28,1) "BR=" BR 1050 PRINT TAB(0,2) "LA=" LA 1060 PRINT TAB(14,2) "VT=" VT 1070 PRINT TAB(28,2) "HT=" HT 1999 REM UPDATE SIMULATION PARAMETERS 2000 HT = LA/90*BR/10 2001 VT = (1-(LA/90))*BR/10 2009 DY=DY-G+(VT) 2010 Y = Y + DY 2015 DX=DX-HT 2020 X = X + DX 2030 IF F-BR<0 THEN BR=F 2040 IF F>0 THEN F=F-BR 2050 RETURN 2999 REM PROCESS KEYBOARD INPUT 3000 IF C$="]" AND BR<100 THEN BR=BR+10 3010 IF C$="[" AND BR>0 THEN BR=BR-10 3020 IF C$="=" AND LA>-60 THEN LA=LA-10 3030 IF C$="-" AND LA<60 THEN LA=LA+10 3040 IF C$="R" THEN GOTO 90 3050 IF C$="1" THEN BR=20 3060 IF C$="2" THEN BR=40 3070 IF C$="3" THEN BR=60 3080 IF C$="4" THEN BR=80 3090 IF C$="5" THEN BR=100 3100 IF C$="0" THEN BR=0 3102 IF C$="'" AND BR>=2 THEN BR=BR#" AND BR<=98 THEN BR=BR+2 3110 IF C$="V" THEN LA=0 3120 IF C$="B" THEN LA=60 3130 IF C$="C" THEN LA=-60 3140 IF C$=" " THEN PRINT TAB(0,4) "PAUSE": INPUT Z: PRINT TAB(0,4) " ":PRINT TAB(0,5) " " 3150 RETURN 3999 REM TEST LANDING CONDITION 4000 IF Y < 0.0 THEN GOTO 5000 4010 RETURN 4999 REM DISPLAY LANDING STATUS AND SCORE 5000 REM TEST END CONDITIONS 5005 IF DX < 0 THEN DX = -DX 5010 IF DY>-6.0 AND DX<6.0 AND ABS(X)<500 THEN PRINT "SUCCESS" 5020 IF DX<6 AND DY<-3 AND DY>-6 THEN PRINT "BOUNCE" 5030 IF DY<-6 OR DX>6 THEN PRINT "CRASH" 5035 @%=&00000000 5038 IF ABS(X)>500 THEN PRINT "YOU LANDED " ABS(X) " METRES AWAY FROM THELANDING SITE" 5040 SCORE%=100/(ABS(DX)*ABS(DY)) 5050 IF ABS(X)<500 THEN PRINT "YOUR SCORE IS: " SCORE% 5060 STOP 6000 REM DELAY THE SIMULATION 6020 REPEAT T=TIME 6030 UNTIL T > 100 6040 RETURN |