Created
August 23, 2023 14:45
-
-
Save jonpovey/b7527d8d014d9bc52d98db245bcdf671 to your computer and use it in GitHub Desktop.
Better auto airlock IC10 code for Stationeers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
alias extDoor d0 # blueshift trick airlock | |
alias intDoor d1 | |
alias extVent d2 | |
alias intVent d3 | |
alias gasSense d4 | |
define doorsHash HASH("StructureCompositeDoor") | |
define tankMaxPressure 58000 # option: allow burst! | |
define tankRebalanceDelay 2 | |
move r10 2.5 # ext atmos target repressure, kPa | |
move r11 20.0 # int atmos target repressure | |
move r12 1000 # ext tank empty balance pressure | |
move r13 1000 # int tank "" (can probably share) | |
sb doorsHash On 1 | |
sb doorsHash Lock 0 | |
sb doorsHash Mode 0 | |
s extVent On 0 | |
s intVent On 0 | |
sleep 2 # boot wait! | |
init: | |
l r14 extDoor Open # init: ensure exactly one door | |
l r15 intDoor Open # is open | |
brne r14 r15 5 | |
s extDoor Open 0 # did not find exactly 1 door open | |
s intDoor Open 1 | |
sleep 1 # time for doors to move | |
j init # jump back to reload r14,15 | |
sb doorsHash Mode 1 # set logic mode. need yield? | |
s extDoor Setting r14 # force consistent initial | |
s intDoor Setting r15 # Setting = Open for doors | |
s db Setting 1 | |
add r8 r15 2 # device index of vent for open door | |
add r9 r15 12 # register index for tank pressure | |
s dr8 Mode 0 # empty tank | |
yield | |
s dr8 PressureExternal tankMaxPressure | |
s dr8 PressureInternal rr9 | |
s dr8 On 1 | |
s db Setting 2 | |
jal rebalanceWaitFunc | |
beq r0 1 startCycle # door click during empty | |
s dr8 Mode 1 # fill tank a little | |
yield | |
s dr8 PressureExternal 0 # set pressures after mode! | |
s dr8 PressureInternal rr9 # must set again? | |
jal rebalanceWaitFunc | |
beq r0 1 startCycle # door click during fill | |
s dr8 On 0 # turn off vent, enter snooze state | |
s db Setting 6 | |
jal samplePressureFunc # try to sample ambient | |
beq r0 1 startCycle # failed to sample: door clicked. | |
add r2 r15 10 # calc address of pressure memory reg | |
move rr2 r1 # store this door's external pressure | |
jal waitDoorClickFunc | |
startCycle: # a door clicked somewhere above | |
s db Setting 7 | |
s dr15 Open 0 # close door that is open (Setting..?) | |
s dr8 Mode 1 # evac using was-open door's vent | |
yield | |
s dr8 PressureExternal 0 | |
s dr8 PressureInternal tankMaxPressure | |
s dr8 On 1 # fill tank for door just closed | |
yield | |
l r1 gasSense Pressure | |
brne r1 0 -2 # wait for vacuum | |
s dr8 On 0 # turn off entry vent evac | |
add r8 r14 2 # device index of vent for exit door | |
add r9 r14 10 # register for exit airlock pressure | |
move r0 rr9 # load exit pressure | |
s dr8 Mode 0 # set exit vent to blow | |
yield # vent needs a moment to accept new pressures | |
s dr8 PressureExternal r0 # should add +margin? | |
s dr8 PressureInternal 0 | |
s dr8 On 1 # start exit vent pressurising | |
jal samplePressureFunc # repress cycle | |
s db Setting 10 | |
s dr8 On 0 # turn off exit vent | |
s dr14 Open 1 # open exit door. write Setting too? | |
s db Setting 11 | |
sleep 1 # done, allow a second for door to open | |
j init # back to reload Open states, rebalance | |
# -- End of main. Functions below -- | |
doorClickedFunc: # return 1 in r0 if any door clicked | |
move r2 0 # check d0 first (ext door) | |
l r0 dr2 Setting | |
l r1 dr2 Open | |
xor r0 r0 r1 | |
breq r0 0 3 # jump if no click | |
s dr2 Setting r1 # got clicked. set it back. | |
j ra # return with r0 = 1 | |
beq r2 1 ra # return with r0 = 0 if second door done | |
add r2 r2 1 | |
jr -8 # end doorClickedFunc | |
waitDoorClickFunc: | |
move r4 ra # about to call another function | |
yield | |
jal doorClickedFunc | |
breq r0 0 -2 # no click, wait again | |
j r4 # end waitDoorClickFunc | |
rebalanceWaitFunc: # wait for time or until door btn | |
move r4 ra # saves a pop vs. push ra | |
mul r3 tankRebalanceDelay 2 # seconds to ticks | |
jal doorClickedFunc | |
bne r0 0 r4 # return if either door clicked | |
yield | |
sub r3 r3 1 # count down | |
beq r3 0 r4 # timer expired | |
jr -5 # back to call doorClickedFunc | |
samplePressureFunc: | |
move r4 ra | |
move r1 -100 # impossible initial pressure reading | |
move r3 r1 # store reading to compare next time | |
jal doorClickedFunc | |
beq r0 1 r4 # give up, door got clicked by user | |
yield | |
l r1 gasSense Pressure | |
brna r1 r3 0.001 -5 # retry until readings within .1% | |
s db Setting r1 # show detected pressure on IC housing | |
j r4 # return with r0 still = 0, not clicked |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment