132 lines
5.9 KiB
Plaintext
132 lines
5.9 KiB
Plaintext
; Lunar Lander game in N8A for n808 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
|
||
|
|
|
||
|
|
; constant/variable area
|
||
|
|
|
||
|
|
#30 code_dis ; disaster code
|
||
|
|
#31 code_crsh ; crash landing code
|
||
|
|
#32 code_dmg ; damage landing code
|
||
|
|
#33 code_good ; good landing code
|
||
|
|
#34 code_perf ; perfect landing code
|
||
|
|
#36 crit_crsh ; criterion for crash landing
|
||
|
|
#37 crit_dmg ; criterion for damage landing
|
||
|
|
#38 crit_good ; criterion for good landing
|
||
|
|
#39 crit_perf ; criterion for perfect landing
|
||
|
|
#40 alt ; module altitude
|
||
|
|
#41 speed ; module fall speed (m/s)
|
||
|
|
#42 fuel ; fuel (in kg)
|
||
|
|
#52 athr ; altitude threshold AND time period
|
||
|
|
#53 ffsd ; freefall speed delta
|
||
|
|
#54 capw ; capsule weight (in kg)
|
||
|
|
#55 burnrate ; fuel burn rate
|
||
|
|
#56 exvel ; exhaust velocity
|
||
|
|
#57 c100 ; constant 100
|
||
|
|
#1 buf ; buffer variable
|
||
|
|
#2 floss ; fuel loss value
|
||
|
|
#3 m0 ; m0 variable in the equation
|
||
|
|
#4 m1 ; m1 variable in the equation
|
||
|
|
|
||
|
|
; memory initialization part
|
||
|
|
|
||
|
|
; zero out the memory (first 57 cells)
|
||
|
|
dca 57 1 ; set the counter to 57
|
||
|
|
:clp ica 0 1 ; assign 0 to the cell from the counter
|
||
|
|
dec 1
|
||
|
|
jgt 1 :clp
|
||
|
|
|
||
|
|
; set constants and initial variable values
|
||
|
|
|
||
|
|
dca 10 @athr ; altitude threshold / time period
|
||
|
|
dca 25 @ffsd ; set 16.25 as freefall speed delta
|
||
|
|
set 0 16 @ffsd
|
||
|
|
set 74 80 @capw ; set 7480 as capsule weight
|
||
|
|
dca 45 @burnrate ; set 3.45 as fuel burn rate
|
||
|
|
set 0 3 @burnrate
|
||
|
|
set 29 0 @exvel ; set 2900 as exhaust velocity
|
||
|
|
set 19 30 @alt ; set 1930 as starting altitude
|
||
|
|
dca 100 @c100 ; set constant 100
|
||
|
|
mul @c100 @alt ; multiply this altitude value by 100
|
||
|
|
set 16 9 @speed ; set 1609 as starting speed
|
||
|
|
set 72 60 @fuel ; set 7260 as fuel
|
||
|
|
set 44 44 @code_dis ; set 4444 as disaster code
|
||
|
|
set 55 55 @code_crsh ; set 5555 as crash landing code
|
||
|
|
set 66 66 @code_dmg ; set 6666 as damage landing code
|
||
|
|
set 77 77 @code_good ; set 7777 as good landing code
|
||
|
|
set 88 88 @code_perf ; set 8888 as perfect landing code
|
||
|
|
dca 67 @crit_crsh ; set 26.67 as the criterion for crash landing
|
||
|
|
set 0 26 @crit_crsh
|
||
|
|
dca 73 @crit_dmg ; set 9.73 as the criterion for damage landing
|
||
|
|
set 0 9 @crit_dmg
|
||
|
|
dca 45 @crit_good ; set 4.45 as the criterion for good landing
|
||
|
|
set 0 4 @crit_good
|
||
|
|
dca 45 @crit_perf ; set 0.45 as the criterion for perfect landing
|
||
|
|
set 0 0 @crit_perf
|
||
|
|
|
||
|
|
; main action/logic part
|
||
|
|
|
||
|
|
:lp out @alt @fuel ; loop start; print altitude, speed and fuel
|
||
|
|
dca 0 @floss ; set fuel loss to 0
|
||
|
|
jle @fuel :cnt ; skip prompting for thrust if already out of fuel
|
||
|
|
inp @floss @floss ; prompt for thrust into the fuel loss location
|
||
|
|
mul @burnrate @floss ; multiply thrust by fuel burn rate to get fuel loss
|
||
|
|
:cnt dva @fuel @m0 ; copy fuel weight into m0
|
||
|
|
add @capw @m0 ; add capsule weight and fuel weight to get m0
|
||
|
|
dva @floss @m1 ; prepare m1
|
||
|
|
sub @m0 @m1 ; m0 - floss => m1
|
||
|
|
div @m0 @m1 ; m0 / m1 => m1
|
||
|
|
log @m1 @buf ; ln (m0 / (m0 - floss)) => buf
|
||
|
|
mul @exvel @buf ; multiply the result by the exhaust velocity to get thrust speed delta
|
||
|
|
sub @speed @buf ; subtract the thrust speed delta from the current speed
|
||
|
|
add @ffsd @buf ; add the freefall speed delta to the current speed
|
||
|
|
dva @buf @speed ; copy the resulting speed value back to the holding variable
|
||
|
|
mul @athr @buf ; multiply speed by time period into the buffer variable
|
||
|
|
sub @alt @buf ; decrease the altitude by the result of this operation
|
||
|
|
dva @buf @alt ; restore the altitude variable
|
||
|
|
sub @fuel @floss ; decrease the amount of fuel by the fuel loss value
|
||
|
|
dva @floss @fuel ; restore the fuel variable
|
||
|
|
jgt @fuel :flc ; skip the next instruction if the amount of fuel is positive
|
||
|
|
dca 0 @fuel ; just set the amount of fuel to zero if it's negative
|
||
|
|
:flc jgt @alt :al ; do the same for altitude
|
||
|
|
dca 0 @alt ; set it to zero if negative
|
||
|
|
:al dva @athr @buf ; copy altitude threshold to the buffer
|
||
|
|
sub @alt @buf ; subtract the threshold from the altitude
|
||
|
|
jgt @buf :lp ; go to the loop start if the altitude is above the threshold
|
||
|
|
|
||
|
|
; game finalization/scoring part
|
||
|
|
|
||
|
|
out @alt @fuel ; print the final altitude/speed/fuel
|
||
|
|
dva @crit_perf @buf ; buffer the perfect speed
|
||
|
|
sub @speed @buf ; subtract the perfect speed
|
||
|
|
jgt @buf :good ; skip if > 0
|
||
|
|
out @code_perf @code_perf ; output the perfect score
|
||
|
|
juc :end ; go to end
|
||
|
|
:good dva @crit_good @buf ; buffer the good speed
|
||
|
|
sub @speed @buf ; subtract the good speed
|
||
|
|
jgt @buf :dmg ; skip if > 0
|
||
|
|
out @code_good @code_good ; output the good score
|
||
|
|
juc :end ; go to end
|
||
|
|
:dmg dva @crit_dmg @buf ; buffer the damage speed
|
||
|
|
sub @speed @buf ; subtract the damage speed
|
||
|
|
jgt @buf :crsh ; skip if > 0
|
||
|
|
out @code_dmg @code_dmg ; output the damage score
|
||
|
|
juc :end ; go to end
|
||
|
|
:crsh dva @crit_crsh @buf ; buffer the crash speed
|
||
|
|
sub @speed @buf ; subtract the crash speed
|
||
|
|
jgt @buf :disa ; skip if > 0
|
||
|
|
out @code_crsh @code_crsh ; output the crash score
|
||
|
|
juc :end ; go to end
|
||
|
|
:disa out @code_dis @code_dis ; output the disaster score
|
||
|
|
:end nnn ; program end label
|
||
|
|
|