Stationeers MIPS - Niilo007/Stationeers-Research GitHub Wiki


Stationeers MIPS

Pins

Pin Name Pin
Device Base db
d0
d1
d2
d3
d4
d5

Registers

Registers Name Register
Return Adress ra
Stack Pointer sp
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r13
r14
r15

Basics

Comments

Examples:

# This is a comment about stuff
# And so is this
s d0 r0 Setting # This is a comment after a command

Sleep

Examples:

Main:
  add r0 r0 1
  s db Setting r0
  sleep 1 #Sleep for 1 second
j Main

Yield

Examples:

Main:
  add r0 r0 1
  s db Setting r0
  yield
j Main

Define

Examples:

define DOutputDirector -810874728
define DVENDERS -1577831321
define cPlanterCount 12
define cMinimumPipePressure 500

Alias

Examples:

alias dWaterTank d0
alias rWaterTank.TemperatureC r15
alias rWaterTank.Pressure r14
Main:
  l r0 dWaterTank Temperature
  sub rWaterTank.TemperatureC r0 273.15
  l rWaterTank.Pressure dWaterTank Pressure
  yield
j Main

Move

Examples:

move r0 1 #r0=1
s db Setting r0
move r0 r2 #r0=r2

Labels

Examples:

Main:
  yield
j Main
Loop:
  yield
j Loop
Reset:
move r0 0
Loop:
  add r0 r0 1
  bgt r0 99 Reset
  yield
j Loop

I/O

Save

Command Name Save To Device This Variable From This Register
Save s d₁ Variable r₁
Save Batch sb HASH("") Variable r₁
Save Batch Named sbn HASH("") HASH("") Variable r₁
Save Slot ss d₁ Slot Variable r₁
Save Batch Slot sbs HASH("") Slot Variable r₁

Examples:

s d0 On r0
sb HASH("StructureActiveVent") Mode r1
sbn HASH("StructureDigitalValve") HASH("Digital Valve (Safety Valve)") On 0
ss d1 0 Open r3
sbs 1632165346 0 Open 1

Load

Command Name Load To Register From Device This Variable Batch Mode
Load l r₁ d₁ Variable
Load Batch lb r₁ HASH("") Variable BatchMode
Load Batch Named lbn r₁ HASH("") HASH("") Variable BatchMode
Load Slot ls r₁ d₁ Slot Variable
Load Batch Slot lbs r₁ HASH("") Slot Variable BatchMode
Load Batch Named Slot lbns r₁ HASH("") HASH("") Slot Variable BatchMode

Examples:

l r0 d0 Pressure
lb r1 HASH("StructureGasSensor") Temperature Average
lbn r2 1013514688 HASH("Small Tank (O2)") Pressure Maximum
ls r3 d2 1 Quantity
lbs r4 HASH("StructureFiltration") 0 Quantity Sum
lbns r5 HASH("StructureFiltration") HASH("Filtration (CO2)") 0 Quantity Minimum

Conditionals

Command Name Set True If
Set Equal seq r₁ r₂ = r₃
Set Not Equal sne r₁ r₂r₃
Set Greater Than sgt r₁ r₂ > r₃
Set Greater or Equal sge r₁ r₂r₃
Set Less Than slt r₁ r₂ < r₃
Set Less or Equal sle r₁ r₂r₃
Set Equal to Zero seqz r₁ r₂ = 0
Set Not Equal to Zero snez r₁ r₂ ≠ 0
Set Greater Than Zero sgtz r₁ r₂ > 0
Set Greater or Equal to Zero sgez r₁ r₂ ≥ 0
Set Less Than Zero sltz r₁ r₂ < 0
Set Less or Equal to Zero slez r₁ r₂ ≤ 0
Set Device Set sdse r₁ d₁ Is set
Set Device Not Set sdns r₁ d₁ Is not set
Set Not A Number snan r₁ r₂ Is NaN
Set Not A Number Zero snanz r₁ r₂ Is Not NaN

Examples:

alias dTempSensor d0
alias dCooler d1
Main:
  l r0 dTempSensor Temperature
  sub r0 r0 273.15 #Convert r0 from K to C
  sgt r1 r0 30 #r1 = true, if temperature greater than 30C
  s dCooler On r1
  yield
j Main
alias dTempSensor d0
alias dHeater d1
Main:
  l r0 dTempSensor Temperature
  sub r0 r0 273.15 #Convert r0 from K to C
  slt r1 r0 20 #r1 = true, if temperature less than 20C
  s dHeater On r1
  yield
j Main

Jumping

Command Name Jump To
Jump j Line number or label
Jump & Store Return Address Line jal Line number or label
Jump Relative jr Number / r₁

Examples:

#line 0
  #program loop
j 0 #Jump to line 0
Main:
  #Program Main loop.
j Main
Main:
  #Program Main loop.
  jal Function.A #Execute Function.A
  jal Function.B #Execute Function.B
j Main
Function.A:
  #Function 1
j ra #Continue main loop.
Function.B:
  #Function 2
j ra #Continue main loop.
#Line 0
#line 1
jr -2 #Jump "up" 2 lines (To line 0).

Branching

Command Name Branch If To
Branch Equal beq r₁ = r₂ Line number or label
Branch Equal & store return Address Line beqal r₁ = r₂ Line number or label
Branch Relative Equal breq r₁ = r₂ Number / r₁
Branch Not Equal bne r₁r₂ Line number or label
Branch Not Equal & store return Address Line bneal r₁r₂ Line number or label
Branch Relative Not Equal brne r₁r₂ Number / r₁
Branch Greater Than bgt r₁ > r₂ Line number or label
Branch Greater Than & store return Address Line bgtal r₁ > r₂ Line number or label
Branch Relative Greater Than brgt r₁ > r₂ Number / r₁
Branch Greater or Equal bge r₁r₂ Line number or label
Branch Greater or Equal & store return Address Line bgeal r₁r₂ Line number or label
Branch Relative Greater or Equal brge r₁r₂ Number / r₁
Branch Less Than blt r₁ < r₂ Line number or label
Branch Less Than & store return Address Line bltal r₁ < r₂ Line number or label
Branch Relative Less Than brlt r₁ < r₂ Number / r₁
Branch Less or Equal ble r₁r₂ Line number or label
Branch Less or Equal & store return Address Line bleal r₁r₂ Line number or label
Branch Relative Less or Equal brle r₁r₂ Number / r₁
Branch Equal to Zero beqz r₁ = 0 Line number or label
Branch Equal to Zero & store return Address Line beqzal r₁ = 0 Line number or label
Branch Relative Equal to Zero breqz r₁ = 0 Number / r₁
Branch Not Equal to Zero bnez r₁ ≠ 0 Line number or label
Branch Not Equal to Zero & store return Address Line bnezal r₁ ≠ 0 Line number or label
Branch Relative Not Equal to Zero brnez r₁ ≠ 0 Number / r₁
Branch Greater Than Zero bgtz r₁ > 0 Line number or label
Branch Greater Than Zero & store return Address Line bgtzal r₁ > 0 Line number or label
Branch Relative Greater Than Zero brgtz r₁ > 0 Number / r₁
Branch Greater or Equal to Zero bgez r₁ ≥ 0 Line number or label
Branch Greater or Equal to Zero & store return Address Line bgezal r₁ ≥ 0 Line number or label
Branch Relative Greater or Equal to Zero brgez r₁ ≥ 0 Number / r₁
Branch Less Than Zero bltz r₁ < 0 Line number or label
Branch Less Than Zero & store return Address Line bltzal r₁ < 0 Line number or label
Branch Relative Less Than Zero brltz r₁ < 0 Number / r₁
Branch Less or Equal to Zero blez r₁ ≤ 0 Line number or label
Branch Less or Equal to Zero & store return Address Line blezal r₁ ≤ 0 Line number or label
Branch Relative Less or Equal to Zero brlez r₁ ≤ 0 Number / r₁
Branch Device Set bdse d₁ Is set Line number or label
Branch Device Set & store return Address Line bdseal d₁ Is set Line number or label
Branch Relative Device Set brdse d₁ Is set Number / r₁
Branch Device Not Set bdns d₁ Is not set Line number or label
Branch Device Not Set & store return Address Line bdnsal d₁ Is not set Line number or label
Branch Relative Device Not Set brdns d₁ Is not set Number / r₁
Branch Not A Number bnan r₁ Is NaN Line number or label
Branch Relative Not A Number brnan r₁ Is NaN Number / r₁

Examples:

Main:
  #Program Main loop.
  beq r0 r1 TurnPumpsOn
  bne r0 r1 TurnPumpsOff
j Main
TurnPumpsOn:
  #Function
j Main
TurnPumpsOff:
  #Function
j Main
Main:
  #Program Main loop.
  brdns d0 2 #Skip load command if device is not set
    l r0 d0 Pressure #Load pressure from a device
j Main

Math

Command Name Command Math
Add add r₁ = r₂ + r₃
Subtract sub r₁ = r₂ - r₃
Multiply mul r₁ = r₂ * r₃
Divide div r₁ = r₂ / r₃
Square Root sqrt r₁ = √r₂

Examples:

add r0 1 1 #r0 = 1 + 1
sub r3 1 1 #r3 = 1 - 1
mul r4 5 r0 #r4 = 5 * r0
div r7 r0 r8 #r7 = r0 / r8
sqrt r0 5 #r0 = √5

Bitwise Operations

Command Name Command
And and r₁ = r₂ & r₃
Or or r₁ = r₂ | r₃
Not not r₁ ~ r₂
Nor nor r₁ ~ r₂ | r₃
Xor xor r₁ = r₂ ^ r₃

Examples:

and r0 %0101 %0110 #r0 = %0100 = 4
and r1 5 6         #r1 = %0100 = 4
or r0 %0101 %0110 #r0 = %0111 = 7
or r1 5 6         #r1 = %0111 = 7
not r0 %0101 #r0 = %1010 = -6
not r1 5     #r1 = %1010 = -6
xor r0 %0101 %0110 #r0 = %0011 = 3
xor r1 5 6         #r1 = %0011 = 3

Bit Shifting

Command Name Command
Shift Left Arithmetic sla r₁ = r₂ << r₃
Shift Left Logical sll r₁ = r₂ << r₃
Shift Right Arithmetic sra r₁ = r₂ >> r₃
Shift Right Logical srl r₁ = r₂ >> r₃

Examples:

#TBA

Constants

Constant Name Constant Value
Not A Number nan NaN
Positive Infinity pinf +∞
Negative Infinity ninf -∞
Pi pi 3.14159265358979
Degrees To Radians deg2rad 0.0174532923847437
Radians To Degrees rad2deg 57.2957801818848
Epsilon epsilon -1.7976931348623157E+308

Macros

Macro Name Macro
HASH("") Convert string to hash
% Convert binary to int
$ Convert hex to int

Examples:

move r0 $FF     #r0=255
s db Setting r0 #r0=255
s db Setting $FF #FF=255
s db Setting %1111 #1111=15
lbns r5 HASH("StructureFiltration") HASH("Filtration (CO2)") 0 Quantity Minimum

Stack

Command Name Command
peek r₁
pop r₁
push r₁

Examples:

move sp 5
push 500
#push 500 to position 5

Channels

Command Name Save To Device : Port This Variable From This Register
Save s d₁:0 Variable r₁

Examples:

s d0:0 Channel0 r0
Command Name Load To Register From Device : Port This Variable Batch Mode
Load l r₁ d₁:0 Variable

Examples:

l r0 d0:0 Channel0

Indirect Addressing

Examples:

move r15 10
move r5 0
move r6 15
s dr5 Setting rr6
#s d0 Setting r15
#s d0 Setting 10
move r1 3
move r2 14
move r3 0
move r14 15
move r15 1000
s drr1 Setting rrr2
#s dr3 Setting rr14
#s d0 Setting r15
#s d0 Setting 1000
Reset:
  move r9 0
  Main:
    l r0 dr9 Setting
    add r0 r0 1
    s dr9 Setting r0
    add r9 r9 1
    yield
    bgt r9 5 Reset
  j Main
j Reset

Other Constants

Color

Constant Value
Color.Blue 0
Color.Gray 1
Color.Green 2
Color.Orange 3
Color.Red 4
Color.Yellow 5
Color.White 6
Color.Black 7
Color.Brown 8
Color.Khaki 9
Color.Pink 10
Color.Purple 11
Constant Value
LogicType.Color 38

GasType

Constant Value
GasType.Undefined 0
GasType.Oxygen 1
GasType.Nitrogen 2
GasType.CarbonDioxide 4
GasType.Volatiles 8
GasType.Pollutant 16
GasType.Water 32
GasType.NitrousOxide 64
GasType.LiquidNitrogen 128
GasType.LiquidOxygen 256
GasType.LiquidVolatiles 512
GasType.Steam 1024
GasType.LiquidCarbonDioxide 2048
GasType.LiquidPollutant 4096
GasType.LiquidNitrousOxide 8192

SlotClass

Constant Value
TBA

SortingClass

Constant Value
TBA

Sound

Constant Value
Sound.None 0
Sound.Alarm2 1
Sound.Alarm3 2
Sound.Alarm4 3
Sound.Alarm5 4
Sound.Alarm6 5
Sound.Alarm7 6
Sound.Music1 7
Sound.Music2 8
Sound.Music3 9
Sound.Alarm8 10
Sound.Alarm9 11
Sound.Alarm10 12
Sound.Alarm11 13
Sound.Alarm12 14
Sound.Danger 15
Sound.Warning 16
Sound.Alert 17
Sound.StormIncoming 18
Sound.IntruderAlert 19
Sound.Depressurising 20
Sound.Pressurising 21
Sound.AirlockCycling 22
Sound.PowerLow 23
Sound.SystemFailure 24
Sound.Welcome 25
Sound.MalfunctionDetected 26
Sound.HaltWhoGoesThere 27
Sound.FireFireFire 28
Sound.One 29
Sound.Two 30
Sound.Three 31
Sound.Four 32
Sound.Five 33
Sound.Floor 34
Sound.RocketLaunching 35
Sound.LiftOff 36
Sound.TraderIncoming 37
Sound.TraderLanded 38
Sound.PressureHigh 39
Sound.PressureLow 40
Sound.TemperatureHigh 41
Sound.TemperatureLow 42
Sound.PollutantsDetected 43
Sound.HighCarbonDioxide 44
Sound.Alarm1 45

Vent

Constant Value
Vent.Outward 0
Vent.Inward 1

RobotMode

Constant Value
RobotMode.None 0
RobotMode.Follow 1
RobotMode.MoveToTarget 2
RobotMode.Roam 3
RobotMode.Unload 4
RobotMode.PathToTarget 5
RobotMode.StorageFull 6

PowerMode

Constant Value
TBA