# Lunar Lander for the TI-95 # only integer increments of fuel? # register 000 is position # register 001 is velocity # register 002 is fuel # register 003 is acceleration # initialize CMS # starting conditions 500 STO 000 # 500 ft above moon is starting position +/-50 STO 001 # -50 ft/sec is starting velocity 60 STO 002 # 60 units fuel # opening message "Lunar Lander" PAU CLR # prompt for fuel LBL A # set acceleration before each prompt +/-5 STO 003 # -5 ft/sec2 acceleration due to gravity "Burn?" BRK # is burn more than fuel? IF> 002 RCL 002 # burn up remaining fuel NOP # if not, just continue # update parameters # assume t-step of 1 in each case # update acceleration ST- 002 # else remove burn from fuel ST+ 003 # add (burn) ft/sec2 to acceleration # update position # x = x0 + v + a/2 RCL 000 + RCL 001 + RCL 003 / 2 = STO 000 # update velocity RCL 003 # recall acceleration ST+ 001 # v = v0 + a # add acceleration (*1 sec) to velocity # did you crash 0 # 0 is greater than position? IF> 000 SBL D # if so print crash velocity # if not # report conditions SBL B # check if landed 0 IF= 000 # is position 0? SBL E # if so, print closing message 0 # if not, check if fuel used up IF= 002 # is fuel 0? SBL C # if so, free fall GTL A # otherwise, go back to prompt HLT # end program # print conditions after fuel input LBL B "Velocity:" COL 16 MRG 001 PAU CLR "Position:" COL 16 MRG 000 PAU CLR "Fuel:" COL 16 MRG 002 PAU CLR RTN # free fall subroutine LBL C # calculate terminal velocity based purely from gravitational acceleration # v = (v0^2 + 2gX)^(1/2) ( RCL 001 x^2 + 10 * RCL 000 ) SQR INT +/- STO 001 "No fuel!" PAU CLR "Free fall" PAU CLR SBL D RTN # print crash message followed by velocity and position before crash LBL D "Crash!" PAU CLR "Velocity:" COL 16 MRG 001 PAU CLR "Position:" COL 16 MRG 000 PAU CLR HLT # end program if crash # print winning message LBL E "You landed!" PAU CLR RTN