#Early Game Power Systems Control
# by SemlerPDX Dec2025
define Generators 813146305
define Batteries -400115994
define SolarPanels -539224550 #basic
#define SolarPanels -1545574413 #heavy
define DaylightSensors 1076425094
# Threshold for "dark"
define IrradianceMin 1
define RelativeTolerance 0.067 # approx. +/-1
define SensorOffset 90 # 0, 90, 180, 270
define DawnVertical 165
define DawnHorizontal 180
define ChargeMin 0.10 # 10%
define ChargeMax 0.50 # 50%
define TopOfStack 2
alias Counter r15
push 0
push 0
begin:
move sp TopOfStack
brgtz Counter 2
move Counter 5
start:
beqz sp begin
yield
#Gather Power Data
lb r0 Batteries PowerPotential Maximum
get r1 db 0
brlt r0 r1 2
put db 0 r0 #maximum historic production
lb r0 Batteries PowerActual Maximum
mul r1 r0 2
sub r0 r0 r1 #Invert to Negative
get r1 db 1
brgt r0 r1 2
put db 1 r0 #maximum historic power draw
#Display
sub Counter Counter 1
and r0 Counter 1
breqz r0 3
pop r0
s db Setting r0
#Backup Power Toggle
lb r0 Batteries Charge Average
lb r1 Generators On Maximum
select r1 r1 ChargeMax ChargeMin
slt r0 r0 r1
sb Generators On r0
#Check Time of Day
lb r0 DaylightSensors SolarIrradiance Maximum
blt r0 IrradianceMin nightSleep
#Follow Sun (in daytime only)
lb r0 DaylightSensors Vertical Maximum
lb r1 DaylightSensors Horizontal Maximum
add r0 r0 SensorOffset
add r1 r1 SensorOffset
sb SolarPanels Vertical r0
sb SolarPanels Horizontal r1
j start
nightSleep:
lb r0 SolarPanels Vertical Maximum
bap r0 DawnVertical RelativeTolerance start
#Point array at dawn sun
sb SolarPanels Vertical DawnVertical
sb SolarPanels Horizontal DawnHorizontal
j start