Files
mu808/examples/lunar.mu8a
T

77 lines
4.0 KiB
Plaintext

; Lunar Lander game in MU8A for mu808 VM
; On each turn, the following parameters are displayed in this order:
; altitude (meters), speed (m/s) and remaining fuel (kg)
; Your goal is to apply (or not apply) thrust
; (values that make any sense are 0 to 2000) every 10 seconds of flight
; and get the lunar module to land safely without running out of fuel.
; At the end, the game shows one of the following statuses:
; 4444 is a disaster landing with no survivors,
; 5555 is a crash landing with the crew surviving the impact,
; 6666 is a hard landing with some damage to the pod,
; 7777 is a good landing,
; 8888 is a perfect landing.
; Created by Luxferre in 2025, released into public domain
set 10 0 52 ; altitude threshold AND time period into loc 52
set 16 2500 53 ; freefall speed delta into loc 53
set 7480 0 54 ; capsule weight (in kg) into loc 54
set 3 4483 55 ; fuel burn rate (3.4483) into loc 55
set 2900 0 56 ; exhaust velocity (m/s) into loc 56
set 1930 0 40 ; starting altitude (m) into loc 40
set 100 0 57 ; store 100 into loc 57
mul 57 40 ; multiply this altitude value by 100
set 1609 0 41 ; starting speed (m/s) into loc 41
set 7260 0 42 ; starting fuel (in kg) into loc 42
set 4444 0 30 ; disaster code into loc 30
set 5555 0 31 ; crash landing code into loc 31
set 6666 0 32 ; damage landing code into loc 32
set 7777 0 33 ; good landing code into loc 33
set 8888 0 34 ; perfect landing code into loc 34
set 26 6667 0 36 ; criterion for crash landing into loc 36
set 9 7300 0 37 ; criterion for damage landing into loc 37
set 4 4445 0 38 ; criterion for good landing into loc 38
set 0 4500 0 39 ; criterion for perfect landing into loc 39
:lp out 40 42 0 ; loop start; print altitude, speed and fuel
set 0 0 2 ; set fuel loss in loc 2 to 0
jle 42 :cnt ; skip prompting for thrust if already out of fuel
inp 1 1 0 ; prompt for thrust into loc 1
dva 1 2 ; copy thrust into loc 2
mul 55 2 ; multiply thrust by fuel burn rate to get fuel loss in loc 2
dva 42 3 ; copy fuel weight into loc 3
:cnt fma 54 127 3 ; add capsule weight and fuel weight to get m0 in loc 3
sub 3 2 4 ; subtract m0 and fuel loss value to get m1 in loc 4
div 3 4 1 ; divide m0 by m1 and rewrite the result into loc 1
log 1 1 ; calculate natural logarithm of the previous result
mul 56 1 ; multiply the result by the exhaust velocity to get thrust speed delta
sub 41 1 41 ; subtract the thrust speed delta from the current speed
fma 53 127 41 ; add the freefall speed delta to the current speed
dva 41 3 ; copy the speed value into loc 3
mul 52 3 ; multiply speed by time period into loc 3
sub 40 3 40 ; decrease the altitude by the result of this operation
sub 42 2 42 ; decrease the amount of fuel by fuel loss value still at loc 2
jgt 42 :flc ; skip the next instruction if the amount of fuel is positive
set 0 0 42 ; just set the amount of fuel to zero if it's negative
:flc jgt 40 :al ; do the same for altitude
set 0 0 40 ; set it to zero if negative
:al sub 40 52 1 ; subtract the threshold from the altitude
jgt 1 :lp ; go to the loop start if the altitude is above the threshold
out 40 42 0 ; print the final altitude/speed/fuel
sub 41 39 1 ; subtract the perfect speed
jgt 1 :good ; skip if > 0
out 34 34 0 ; output the perfect score
juc :end ; go to end
:good sub 41 38 1 ; subtract the good speed
jgt 1 :dmg ; skip if > 0
out 33 33 0 ; output the good score
juc :end ; go to end
:dmg sub 41 37 1 ; subtract the damage speed
jgt 1 :crsh ; skip if > 0
out 32 32 0 ; output the damage score
juc :end ; go to end
:crsh sub 41 36 1 ; subtract the crash speed
jgt 1 :disa ; skip if > 0
out 31 31 0 ; output the crash score
juc :end ; go to end
:disa out 30 30 0 ; output the disaster score
:end nnn ; program end label