furnace
advanced-furnace.mips
arc-furnace-room-control.mips
furnace-calc-pre.mips
furnace-ingot-recipe.mips
furnace-operate.mips
furnace-room-vacuum-pump.mips
hot-cold-waste-tank-manager.mips
hot-tank-filler.mips
pressurize-furnace.mips
waste-tank-to-cold-tank-with-chiller.mips
furnace-waste-chiller.mips

manufacturing
vend-ingots-to-printer.mips
vending-ore-counter-omni-fast.mips
vending-ore-counter-omni-slow.mips
vending-ore-counter-single.mipsr
vending-ore-counter-triple.mips

greenhouse
greenhouse-ac.mips
greenhouse-o2-pressure-display.mips
greenhouse-oxygen-harvest.mips
greenhouse-temperature.mips
harvie-triple.mips
seed-distributer.mips
seed-sorter-old.mips
seed-sorter.mips
stacker-vending-button.mips

atmospherics
base-atmosphere-control.mips
battery-room-atmosphere.mips
battery-room-vent-setter.mips
harvest-cold-atmosphere.mips
harvest-liquid-from-atmosphere.mips
refrigeration-room.mips

mining rocket
rocket-driving.mips
rocket-miner-readout.mips

ore warehousing
ore-sorter-multi.mips
ore-sorter2-multi.mips
gas-rock-sorter.mips
centrifuge-ore.mips

gas handling
gas-filter-chain.mips
co2-tank-pressure-management.mips
fuel-mixer.mips
gas-harvester.mips
gas-mixer-nitrous.mips
n2o-heater.mips
pump-feed-nitrolyzer.mips
show-gas-pressure-triple.mips
manage-coolant-from-atmosphere.mips

doors
weather-gate.mips
door-switch-logic.mips

solar
solar-old.mips
1-axis-solar-panel-control.mips
2-axis-solar-panel-control.mips

biomass fuel
biomass-generator-pipeline.mips
biomass-generator-silo.mips
biomass-recycler.mips
charcoal-stockpile-display.mips

AIMeE
aimee-old.mips
aimee-position-display.mips
aimee.mips


airlock-tank-accelerator-mgmt.mips
batch-solar-control.mips
centrifuge-miner-manager.mips
chamber-liquification-mgr.mips
cooling-gas-buffer-room.mips
cooling-gas-buffer.mips
display-avionics.mips
exhaust-gas-cooler-control.mips
fuel-mixer-n2o.mips
fuel-mixer-o2.mips
larre-config-1.mips
larre-farming-hardcoded.mips
larre-farming-stack.mips
light-console.manager.mips
light-manager.mips
loulan-airlock.mips
loulan-arc-furnace-room.mips
loulan-greenhouse.mips
measure-condensation-rate.mips
nitrolyzer-battery-threshold.mips
nitrous-warmer.mips
power-consumption-triple.mips
radiator-control.mips
simpler-gate.mips
sorter-feeding-autooven.mips
trader-scanner.mips
vend-ingots-to-printer-2.mips

alias printer d0
alias sorter d1
alias vend d2
alias button d3

alias ingothash r9

define INGOTCLASS 19

setup:

s printer ClearMemory 1
move ingothash -1
j scan #scan required materials and update ingothash for what is required.

start:
yield
s db Setting ingothash

l r0 printer ImportCount
select ingothash r0 -1 ingothash # if something got imported, clear ingothash
l r0 button Setting
select ingothash r0 -1 ingothash # if the reset button got pushed, clear ingothash
yield

bne ingothash -1 start # if ingothash is not clear, we are still waiting, so loop around for another check

scan:
# we must figure out what is required by the recipe
s db Setting -1

l r0 printer Open
bgtz r0 start # if the printer is Open, then it is ejecting all ingots, so we should not load anything until it is closed.
s db Setting 0

lr r0 printer Required HASH("Astroloy")
select ingothash r0 412924554 ingothash
lr r0 printer Required HASH("Constantan")
select ingothash r0 1058547521 ingothash
lr r0 printer Required HASH("Copper")
select ingothash r0 -404336834 ingothash
lr r0 printer Required HASH("Gold")
select ingothash r0 226410516 ingothash
lr r0 printer Required HASH("Inconel")
select ingothash r0 -787796599 ingothash
lr r0 printer Required HASH("Iron")
select ingothash r0 -1301215609 ingothash
lr r0 printer Required HASH("Nickel")
select ingothash r0 -1406385572 ingothash
lr r0 printer Required HASH("Silicon")
select ingothash r0 -290196476 ingothash
lr r0 printer Required HASH("Silver")
select ingothash r0 -929742000 ingothash
lr r0 printer Required HASH("Steel")
select ingothash r0 -654790771 ingothash
lr r0 printer Required HASH("Solder")
select ingothash r0 -82508479 ingothash
lr r0 printer Required HASH("Electrum")
select ingothash r0 502280180 ingothash
lr r0 printer Required HASH("Invar")
select ingothash r0 -297990285 ingothash
lr r0 printer Required HASH("Stellite")
select ingothash r0 -1897868623 ingothash
lr r0 printer Required HASH("Hastelloy")
select ingothash r0 1579842814 ingothash

# if nothing is required, then ingothash will be -1; otherwise it will be the has of the ingot.

beq ingothash -1 start

# need something, request it
s printer ClearMemory 1 # so we can detect when it gets loaded into the printer

# rig the sorter
clr sorter
s sorter Mode 1
put sorter 0 262 # (1<<8) | 6  means LimitNextExecutionByCount 1
sll r0 ingothash 8
or r0 r0 SorterInstruction.FilterPrefabHashEquals
put sorter 1 r0

s vend RequestHash ingothash

yield
j start

# This script examines the recipe selected in a printer/fabricator and
# queries the ingots required.  If any are not satisfied by the
# internal inventory, it requests those ingots from a venting machine,
# and configurs a sorter to route one ingot stack to the printer.

MIPS is the programming language used by IC (integrated circuits) in the game Stationeers. Stationeering web site has a MIPS emulator with syntax highlighting and error detection.