Actions

Editing IC10

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 1: Line 1:
[[Category:IC10 Programming]]
+
[[Category:MIPS Programming]]
=Scripting language for IC10 housings / chips=
+
=MIPS scripting language for IC10 housings / chips=
MIPS is [[Stationeers]]' inspiration for the in-game scripting language called IC10. It runs on [[Integrated Circuit (IC10)|IC10 chips]] crafted at the [[Electronics Printer]].  
+
MIPS is [[Stationeers]]' in-game scripting language. It runs on [[Integrated Circuit (IC10)|IC10 chips]] crafted at the [[Electronics Printer]].  
  
 
==Registers==
 
==Registers==
 
Internal registers '''r?''': The IC contains 16 CPU registers, numbered '''r0''' to '''r15'''. From now on referred to as '''r?'''.
 
Internal registers '''r?''': The IC contains 16 CPU registers, numbered '''r0''' to '''r15'''. From now on referred to as '''r?'''.
  
Device registers '''d? logicType''': Device registers are written to and from the IC. A device register is numbered '''d0''' to '''d5''' (select via screw), or '''db''' (connected device). From now on referred to as '''d?'''.
+
Device registers '''d? logicType''': Device registers are written to and from the IC. A device register is numbered '''d0''' to '''d6''' (select via screw), or '''db''' (connected device). From now on referred to as '''d?'''.
  
=== Logic and algorithmic with '''Internal registers''' ===
+
=== Logic and algoritmic with '''Internal registers''' ===
All calculations are exclusively performed to and from '''r?''' registers, or generally more understood as variables in programming. You can use aliases to give convenient names with the <code>alias string r?|d?</code>command (see below).  
+
All calculations are exclusively performed to and from '''r?''' registers, or generally more understood as variables in programming. You can use aliases to give convinent names with the <code>alias string r?|d?</code>command (see below).  
  
 
Internal registers can be manipulated in various ways.  
 
Internal registers can be manipulated in various ways.  
Line 21: Line 21:
 
You can also read/write to the device where the IC is planted in using device '''db'''.
 
You can also read/write to the device where the IC is planted in using device '''db'''.
  
Generally, there are up to 6 devices which can be set using the screwdriver '''d0''' to '''d5'''. A special device register '''db''' is the device wherever the IC is mounted upon. Very convenient for atmospheric devices where no separate IC socket is required.
+
Generally, there are up to 6 devices which can be set using the screwdriver '''d0''' to '''d5'''. A specical decice register '''db''' is the device wherever the IC is mounted upon. Very convinent for atmospheric devices where no seperate IC socket is reguired.
  
Note, the IC is completely unaware where d? is actually connected to. So if you get a logicType error, check d? number, or check if the screw has been set opn the socket. An alias is only convenient to convey what is expected to be set on the d? screw, it does not actually set or program the screq.
+
Note, the IC is completely unaware where d? is actually connected to. So if you get a logicType error, check d? number, or check if the screw has been set opn the socket. An allias is only convinent to convey what is expected to be set on the d? screw, it does not actually set or program the screq.
  
* Read from device (load) <code>l r? d? logicType</code>: Reads logicType, like Pressure from a [[Sensors|gas sensor]], from device d? to register r?. Values can be read from connected devices and put into the register using the '''l''' (load) command. For example, if you want to load the state of a door. <br> Example: <code>l r0 Door Open</code> reads the 'Open' field of an object named 'Door', that would be connected to the IC housing of the chip.
+
* Read from devive (load) <code>l d? logicType r?</code>: Reads logicType, like Pressure from a [[Sensors|gas sensor]], from device d? to register r?. Values can be read from connected devices and put into the register using the '''l''' (load) command. For example, if you want to load the state of a door. <br> Example: <code>l r0 Door Open</code> reads the 'Open' field of an object named 'Door', that would be connected to the IC housing of the chip.
* Write to a device (set) <code>s d? logicType r?</code>: Write a value from a register back to a device using the command <code>s d? logicType r?</code>. For example, if d0 is set to a door using the screwdriver, <code>s d0 Open 0</code> sets the 'Open' status of the d0 (a door) to 0, effectively closing the door.
+
* Write to a divice (set) <code>s d? logicType r?</code>: Write a value from a register back to a device using the command <code>s d? logicType r?</code>. For example, if d0 is set to a door using the screwdriver, <code>s d0 Open 0</code> sets the 'Open' status of the d0 (a door) to 0, effectively closing the door.
  
 
=== batch IO to - '''Device registers''' ===
 
=== batch IO to - '''Device registers''' ===
 
'''Batch writing''' needs to be done to a specific '''deviceHash''' instead of d?. Is unique per device type, which you can find in the [[Stationpedia]] entries.
 
'''Batch writing''' needs to be done to a specific '''deviceHash''' instead of d?. Is unique per device type, which you can find in the [[Stationpedia]] entries.
* <code>lb r? deviceHash logicType batchMode</code>  
+
* <code>lb deviceHash logicType r?</code>  
 
* <code>sb deviceHash logicType r?</code>
 
* <code>sb deviceHash logicType r?</code>
Additionally, using the following batch commands, a '''nameHash''' can be provided to only modify devices with a certain name.
 
* <code>lbn r? deviceHash nameHash logicType batchMode </code>
 
* <code>sbn deviceHash nameHash logicType r?</code>
 
 
'''batchMode''' is a parameter equal to 0, 1, 2, or 3. These are also defined as the constants '''Average''', '''Sum''', '''Minimum''', and '''Maximum''' respectively. The word or number can be used.
 
 
Combining one of these functions with the <code>HASH()</code> function can be advantageous:
 
 
<code>lbn r0 HASH("StructureGasSensor") HASH("Sensor 1") Temperature Average</code>
 
 
This code will load the average temperature of all gas sensors on the network named "Sensor 1" onto register '''r0'''
 
 
If the batch read (lb/lbn) is done on a network without any matching devices the results will be as specified in the table:
 
{| class="wikitable"
 
|+ Batch read with no devices
 
|-
 
! Batch Mode !! Result
 
|-
 
| Average (0) || nan
 
|-
 
| Sum (1) || 0
 
|-
 
| Minimum (2) || 0
 
|-
 
| Maximum (3) || ninf
 
|}
 
 
=== Examples ===
 
  
 
Here are some examples demonstrating all three operations:
 
Here are some examples demonstrating all three operations:
  
<code>move r0 10</code><br>Sets register '''r0''' to the value 10
+
<code>move r0 10</code><br>Sets register r0 to the value 10
  
<code>move r0 r1</code><br>Copies the value of register '''r1''' to register '''r0'''
+
<code>move r0 r1</code><br>Copies the value of register r1 to register r0
  
<code>l r0 d0 Temperature</code><br>Reads the Temperature parameter from device '''d0''' and places the value in register '''r0'''.
+
<code>l r0 d0 Temperature</code><br>Reads the Temperature parameter from device d0 and places the value in register r0.
 
Note: not all devices have a Temperature parameter, check the in-game stationpedia.
 
Note: not all devices have a Temperature parameter, check the in-game stationpedia.
  
To set a device specific value (like '''On'''), you can write into this value.
+
To set a device specific value (like "On"), you can write into this value.
  
<code>s d0 On r0</code><br>Writes the value from register '''r0''' out to '''On''' parameter of device '''d0'''. In this example the device will be turned On, if valve of register r0 equals 1, otherwise (register r0 equals 0) it will turned off. See section [[IC10#Device_Variables|Device Variables]].
+
<code>s d0 On r0</code><br>Writes the value from register '''r0''' out to '''On''' parameter of device '''d0'''. In this example the device will be turned On, if valve of register r0 equals 1, otherwise (register r0 equals 0) it will turned off. See section [[MIPS#Device_Variables|Device Variables]].
  
It's recommended to use labels (like: ''someVariable'') instead of a direct reference to the register. See '''alias''' in section [[IC10#Instructions|Instructions]].
+
It's recommended to use labels (like: ''someVariable'') instead of a direct reference to the register. See '''alias''' in section [[MIPS#Instructions|Instructions]].
  
 
=== Special registers ===
 
=== Special registers ===
 
There are two more registers. One called '''ra''' (return address) and one called '''sp''' (stack pointer). The '''ra''' is used by certain jump and branching instructions (those ending with '''-al''') to remember which line in the script it should return to. The '''sp''' tracks the next index within the stack (a memory that can store up to 512 values) to be pushed (written) to or popped (read) from. Neither '''ra''' or '''sp''' is protected, their values can be changed by instructions like any other register.
 
There are two more registers. One called '''ra''' (return address) and one called '''sp''' (stack pointer). The '''ra''' is used by certain jump and branching instructions (those ending with '''-al''') to remember which line in the script it should return to. The '''sp''' tracks the next index within the stack (a memory that can store up to 512 values) to be pushed (written) to or popped (read) from. Neither '''ra''' or '''sp''' is protected, their values can be changed by instructions like any other register.
 
==Stack Memory==
 
;push r?: adds the value  '''r?''' and increments the '''sp''' by 1.
 
;pop r?: loads the value in the stack memory at index <code>sp-1</code> into register '''r?''' and decrements the '''sp''' by 1.
 
;peek r?: loads the value in the stack memory at index <code>sp-1</code> into register '''r?'''.
 
;get r? d? address(r?|num): loads the value in the stack memory at index <code>address</code> on provided device into register '''r?'''.
 
;getd r? id(r?|num) address(r?|num): loads the value in the stack memory at index <code>address</code> on provided device id into register '''r?'''.
 
;put d? address(r?|num) value(r?|num): adds the value to the stack memory off the provided device at index <code>address</code>.
 
;putd id(r?|num) address(r?|num) value(r?|num) : adds the value to the stack memory off the provided device id at index <code>address</code>.
 
 
As mentioned previously, '''sp''' can be both written to and read from any time. When reading ('''peek''' or '''pop'''), '''sp''' must be between 1 and 512, inclusive. While writing ('''push'''), '''sp''' must be between 0 and 511, inclusive.
 
 
Stack memory is persistent on logic chips. This means that if you have a logic chip and push values to the stack, the code that pushes those values can be removed and the stack will retain those values.
 
 
Note that this does not carry over to any other logic chips which receive the program of the original; They will need to have their stack memories programmed individually.
 
 
'''Stack Traversing'''
 
 
Traversing the stack can be done similarly to how an array would be traversed in some other languages:
 
{{ICCode|
 
#this will traverse indices {min value} through {max value}-1
 
move sp {min value}
 
loop:
 
add sp sp 1
 
peek r0
 
 
#do something here with your stack values (loaded into r0)
 
 
blt sp {max value} loop
 
 
#continue on
 
}}
 
 
Alternatively, you can use the pop function's decrementing to make a more efficient loop:
 
{{ICCode|
 
move sp {max value}
 
add sp sp 1
 
loop:
 
pop r0
 
 
#do something here with your stack values (loaded into r0)
 
 
bgt sp {min value} loop
 
 
#continue on
 
 
}}
 
  
 
==Device Ports==
 
==Device Ports==
Line 132: Line 57:
  
 
The '''l''' (load) or '''s''' (set) instructions you have to read or set these values to your device. Examples:
 
The '''l''' (load) or '''s''' (set) instructions you have to read or set these values to your device. Examples:
{{ICCode|
+
 
#Reads the 'Temperature' from an atmosphere sensor
+
<code>l r0 d0 Temperature</code> #Reads the '''Temperature''' from an atmosphere sensor at device port '''d0''' into register '''r0'''.
# at device port 'd0' into register 'r0'.
+
 
l r0 d0 Temperature
+
<code>s d1 Setting r0 </code> # Writes the value of the register '''r0''' to the device on port '''d1''' into the variable '''Setting'''.
}}
 
{{ICCode|
 
# Writes the value of the register 'r0' to the
 
# device on port 'd1' into the variable 'Setting'.
 
s d1 Setting r0
 
}}
 
  
 
==Labels==
 
==Labels==
 
Labels are used to make it easier to jump between lines in the script. The label will have a numerical value that is the same as its line number. Even though it's possible to use a labels value for calculations, doing so is a bad idea since any changes to the code can change the line numbers of the labels.
 
Labels are used to make it easier to jump between lines in the script. The label will have a numerical value that is the same as its line number. Even though it's possible to use a labels value for calculations, doing so is a bad idea since any changes to the code can change the line numbers of the labels.
{{ICCode|
+
 
main: # define a jump mark with label 'main'
+
<br><code>main:</code> # define a jump mark with label '''main'''
j main # jumps back to 'main'
+
<br><code>j main</code> # jumps back to '''main'''
}}
+
 
 
==Constants==
 
==Constants==
 
Instead of using a register to store a fixed value, a constant can be made. Using this name will refer to the assigned value. With the help of Constants you can save register places.
 
Instead of using a register to store a fixed value, a constant can be made. Using this name will refer to the assigned value. With the help of Constants you can save register places.
{{ICCode|
+
<br><code>define pi 3.14159</code> # defines a Constant with name '''pi''' and set it's value to 3.14159
# defines a Constant with name 'pi'
 
# and set its value to 3.14159
 
define pi 3.14159
 
}}
 
  
You can use these constants like any other variables (see: alias in section [[IC10#Instructions|Instructions]]). Example:
+
You can use these constants like any other variables (see: alias in section [[MIPS#Instructions|Instructions]]). Example:
{{ICCode|
+
<br><code>move r0 pi</code> # set the value of register '''r0''' to the value of constant named '''pi'''.
# set the value of register 'r0' to the value of constant named 'pi'.
 
move r0 pi
 
}}
 
  
 
==Numeric values==
 
==Numeric values==
Line 178: Line 90:
  
 
==Indirect referencing==
 
==Indirect referencing==
This is a way of accessing a register by using another register as a pointer. Adding an additional r in front of the register turns on this behaviour. The value stored in the register being used as the pointer must be between 0 to 15, this will then point to a register from r0 to r15, higher or lower values will cause an error.
+
This is a way of accessing a register by using another register as a pointer. Adding an additional r infront of the register turns on this behaviour. The value stored in the register being used as the pointer must be between 0 to 15, this will then point to a register from r0 to r15, higher or lower values will cause an error.
{{ICCode|
+
 
move r0 5 # stores the value 5 in r0
+
<code>move r0 5</code> stores the value 5 in r0
move rr0 10  
+
<br><code>move rr0 10</code> is now the same as <code>move r5 10</code> since r0 has the value 5, rr0 points at the register r5
# is now the same as 'move r5 10'
 
# since r0 has the value 5, rr0 points at the register r5
 
}}
 
  
 
Additional r's can be added to do indirect referencing multiple times in a row.
 
Additional r's can be added to do indirect referencing multiple times in a row.
{{ICCode|
+
<br><code>move r1 2</code>
move r1 2
+
<br><code>move r2 3</code>
move r2 3
+
<br><code>move rrr1 4</code> is now the same as <code>move r3 4</code> since r1 points at r2 which points at r3
move rrr1 4
 
# is now the same as 'move r3 4'
 
# since r1 points at r2 which points at r3
 
}}
 
  
 
This also works with devices
 
This also works with devices
{{ICCode|
+
<br><code>move r0 2</code> stores the value 2 in r0
move r0 2 # stores the value 2 in r0
+
<br><code>s dr0 On 1</code> is now the same as <code>s d2 On 1</code>, r0 has the value 2 so dr0 points at d2
s dr0 On 1  
 
# is now the same as 's d2 On 1'
 
# r0 has the value 2 so dr0 points at d2
 
}}
 
 
 
==Network Referencing / Channels==
 
 
 
All cable networks have 8 Channels which can have data loaded from/stored to via a device and connection reference. Connections for each supported device are listed in the stationpedia. All 'connections' a device can make are a connection (pipe, chute, cable), but only cable networks have channels.
 
 
 
The 8 channels (Channel0 to Channel7) are however volatile, in that data is destroyed if any part of the cable network is changed, removed, or added to, and also whenever the world is exited. All these channels default to NaN. Strictly speaking, they default to what we would call "quiet NaN", in that its not an error it simply means its not a number yet. Recommend you use these channels for reading and writing between networks, rather than as a data store. This effectively means an IC can read all the networks for all devices to connected to it, so not just their own local network, but any networks any device they can reference is connected to.
 
{{ICCode|
 
# d0 is device zero, and the :0 refers
 
# to that device's 0 connection
 
l r0 d0:0 Channel0}}
 
 
 
For example: on an IC Housing, the 0 connection is the data port and 1 is power, so you could write out r0 to Channel0 of the power network of the Housing using <code>s db:1 Channel0 r0</code>
 
  
 
==Comments==
 
==Comments==
 
Comments can be placed using a '''#''' symbol. All comments are ignored by the game when it reads commands. Below is an example of valid code with two comments.
 
Comments can be placed using a '''#''' symbol. All comments are ignored by the game when it reads commands. Below is an example of valid code with two comments.
{{ICCode|
+
 
alias MyAlias r0 # Text after the hash tag will be ignored to the end of the line.
+
<code> alias MyAlias r0 # Text after the hash tag will be ignored to the end of the line. </code> <br>
# You can also write comments on their own lines, like this.
+
<code> # You can also write comments on their own lines, like this. </code>
}}
 
  
 
==Debugging advices==
 
==Debugging advices==
Line 229: Line 117:
 
<code>s db Setting 137</code>  # sets/writes the number 137 into the parameter '''Setting''' of the IC Housing('''db''')
 
<code>s db Setting 137</code>  # sets/writes the number 137 into the parameter '''Setting''' of the IC Housing('''db''')
  
Always use unique names for labels. When a label is named after a IC10 keyword like "Temperature:" or "Setting:" the original meaning of the keyword is overwritten, so when an instruction tries to use it an error will occur.
+
Always use unique names for labels. When a label is named after a MIPS keyword like "Temperature:" or "Setting:" the original meaning of the keyword is overwritten, so when an instruction tries to use it an error will occur.
  
 
A [[Cartridge#Configuration|configuration cartridge]] installed in a [[Handheld_Tablet|tablet]]  can be used to see all available values and configuration parameter for all devices you focus on.
 
A [[Cartridge#Configuration|configuration cartridge]] installed in a [[Handheld_Tablet|tablet]]  can be used to see all available values and configuration parameter for all devices you focus on.
  
==Learning IC10==
+
==Learning MIPS==
IC10 can be difficult to get started with. So here is a list of instructions that are useful for beginners. These can be used to write many different scripts.
+
MIPS can be difficult to get started with. So here is a list of instructions that are useful for beginners. These can be used to write many different scripts.
  
 
General:
 
General:
Line 285: Line 173:
  
 
<br>Notes:
 
<br>Notes:
<br>-All instructions and variables can be seen in-game in the IC editor window by clicking the "f", "x" and "s(x)" buttons on the top right.
+
<br>-All instructions and variables can be seen in-game in the MIPS editor window by clicking the "f", "x" and "s(x)" buttons on the top right.
 
<br>-The stationpedia is the best source to see which variables are available to each device.
 
<br>-The stationpedia is the best source to see which variables are available to each device.
 
<br>-Most scripts are loops, they end with a jump instruction that leads back up to the start. Otherwise they will just run once and then stop.
 
<br>-Most scripts are loops, they end with a jump instruction that leads back up to the start. Otherwise they will just run once and then stop.
Line 291: Line 179:
 
Two practice scripts:
 
Two practice scripts:
 
<br>Automatic Night Light: Load "Activate" from a Daylight sensor, flip the value with a NOT-gate, store the value to the "On" variable of one or more lights.
 
<br>Automatic Night Light: Load "Activate" from a Daylight sensor, flip the value with a NOT-gate, store the value to the "On" variable of one or more lights.
<br>Automatic Wall Cooler: Read "Temperature" from a Gas Sensor. Branch if the value is greater than X, turn on the cooler. Branch if the value is less than Y, turn off the cooler. (Wall coolers need a minimum of 12.5 kPa pressure in the connected pipe)
+
<br>Automatic Wall Cooler: Read "Temperature" from a Gas Sensor. Branch if the value is greater than X, turn on the cooler. Branch if the value is less than Y, turn off the cooler. (Wall coolers need a minumum of 12.5 kPa pressure in the connected pipe)
  
  
Line 346: Line 234:
 
----
 
----
  
See [[IC10/instructions]]
+
<div id="alias"></div>
 +
;alias
 +
:alias str r? d? # labels register or device reference with name.  When alias is applied to a device, it will affect what shows on the screws in the IC base.  (housing)
 +
<code>alias vTemperature r0</code>
 +
<br>
 +
<code>alias dAutoHydro1 d0</code>
 +
 
 +
<div id="move"></div>
 +
;move   
 +
:d s    # stores the value of s in d
 +
<code>move r0 42 # Store 42 in register 0</code>
 +
 
 +
<div id="l"></div>
 +
<div id="load"></div>
 +
;l (load)
 +
:l r# d# parameter
 +
Reads from a device (d#) and stores the value in a register (r#)
 +
 
 +
<code>l r0 d0 Setting</code><br>Read from the device on d0 into register 0
 +
 
 +
<code>l r1 d5 Pressure</code><br>Read the pressure from a sensor
 +
 
 +
This also works with aliases. For example:<br/>
 +
<code>
 +
alias Sensor d0 <br/>
 +
l r0 Sensor Temperature
 +
</code>
  
{{:IC10/instructions}}
+
<div id="ls"></div>
 +
<div id="load slot"></div>
 +
;ls (load slot)
 +
:ls r# d# slotNum parameter
 +
Reads from a slot (slotNum) of a device (d#)  and stores the value in a register (r#)
 +
 
 +
<code>ls r0 d0 2 Occupied</code><br>Read from the second slot of device on d0, stores 1 in r0 if it's occupied, 0 otherwise.
 +
 
 +
And here is the code to read the charge of an AIMeE:<br/>
 +
<code>
 +
alias robot d0 <br/>
 +
alias charge r0 <br/>
 +
ls charge robot 0 Charge
 +
</code>
 +
 
 +
 
 +
<div id="s"></div>
 +
<div id="set"></div>
 +
;s (set)
 +
:s d# parameter r#
 +
Writes a setting to a device.
 +
 
 +
<code>s d0 Setting r0</code>
 +
 
 +
 
 +
<div id="add"></div>
 +
;add   
 +
:d s t  # calculates s + t and stores the result in d
 +
<code>add r0 r1 1 # add 1 to r1 and store the result as r0</code>
 +
<br>
 +
<code>add r0 r0 1 # increment r0 by one</code>
 +
<div id="sub"></div>
 +
;sub   
 +
:d s t  # calculates s - t and stores the result in d
 +
<div id="mul"></div>
 +
;mul   
 +
:d s t  # calculates s * t and stores the result in d
 +
<div id="div"></div>
 +
;div   
 +
:d s t  # calculates s / t and stores the result in d
 +
<div id="mod"></div>
 +
;mod   
 +
:d s t 
 +
::# calculates s mod t and stores the result in d. Note this
 +
::# doesn't behave like the % operator - the result will be
 +
::# positive even if the either of the operands are negative
 +
 
 +
<div id="slt"></div>
 +
;slt   
 +
:d s t  # stores 1 in d if s < t, 0 otherwise
 +
 
 +
<div id="sqrt"></div>
 +
;sqrt   
 +
:d s    # calculates sqrt(s) and stores the result in d
 +
<div id="round"></div>
 +
;round 
 +
:d s    # finds the rounded value of s and stores the result in d
 +
<div id="trunc"></div>
 +
;trunc 
 +
:d s    # finds the truncated value of s and stores the result in d
 +
<div id="ceil"></div>
 +
;ceil 
 +
: d s    # calculates the ceiling of s and stores the result in d
 +
<div id="floor"></div>
 +
;floor 
 +
: d s    # calculates the floor of s and stores the result in d
 +
 
 +
<div id="max"></div>
 +
;max   
 +
: d s t  # calculates the maximum of s and t and stores the result in d
 +
<div id="min"></div>
 +
;min   
 +
: d s t  # calculates the minimum of s and t and stores the result in d
 +
<div id="abs"></div>
 +
;abs   
 +
: d s    # calculates the absolute value of s and stores the result in d
 +
<div id="log"></div>
 +
;log   
 +
: d s    # calculates the natural logarithm of s and stores the result
 +
::# in d
 +
<div id="exp"></div>
 +
;exp   
 +
: d s    # calculates the exponential of s and stores the result in d
 +
<div id="rand"></div>
 +
;rand 
 +
: d      # selects a random number uniformly at random between 0 and 1
 +
::# inclusive and stores the result in d
 +
 
 +
::# boolean arithmetic uses the C convention that 0 is false and any non-zero
 +
::# value is true.
 +
<div id="and"></div>
 +
;and   
 +
: d s t  # stores 1 in d if both s and t have non-zero values,
 +
::# 0 otherwise
 +
<div id="or"></div>
 +
;or   
 +
: d s t  # stores 1 in d if either s or t have non-zero values,
 +
::# 0 otherwise
 +
<div id="xor"></div>
 +
;xor   
 +
: d s t  # stores 1 in d if exactly one of s and t are non-zero,
 +
::# 0 otherwise
 +
<div id="nor"></div>
 +
;nor
 +
:    d s t  # stores 1 in d if both s and t equal zero, 0 otherwise
 +
::# Lines are numbered starting at zero
 +
<div id="j"></div>
 +
;j
 +
:            a # jumps to line a.
 +
<div id="bltz"></div>
 +
;bltz
 +
:      s  a # jumps to line a if s <  0
 +
<div id="blez"></div>
 +
;blez
 +
:    s  a # jumps to line a if s <= 0
 +
 
 +
<div id="bgez"></div>
 +
;bgez
 +
:    s  a # jumps to line a if s >= 0
 +
<div id="bgtz"></div>
 +
;bgtz
 +
:      s  a # jumps to line a if s >  0
 +
<div id="beq"></div>
 +
;beq
 +
:      s t a # jumps to line a if s == t
 +
<div id="bne"></div>
 +
;bne
 +
:      s t a # jumps to line a if s != t
 +
<div id="bdseal"></div>
 +
;bdseal
 +
:    d? a(r?|num) # Jump execution to line a and store current line number if device d? is set.
 +
<code>bdseal d0 32 #Store line number and jump to line 32 if d0 is assigned.</code>
 +
<BR>
 +
<code>bdseal dThisVictim HarvestCrop #Store line in ra and jump to sub HarvestCrop if device dThisVictim is assigned.</code>
 +
 
 +
<div id="yield"></div>
 +
;yield         
 +
: # ceases code execution for this power tick
 +
 
 +
<div id="lb"></div>
 +
;lb
 +
:      r? typeHash var batchMode # Loads var from all output network devices with provided typeHash  using provided batchMode: Average(0), Sum (1), Minimum (2), Maximum (3). Can be used word or number. Result store into r?
 +
 
 +
<div id="sb"></div>
 +
;sb
 +
:      typeHash var r? # Store register r? to var on all output network devices with provided typeHash
 +
 
 +
<div id="#"></div>
 +
; #
 +
:    # The following text will be ignored during compiling; use this to create comments.
  
 
[https://www.cs.tufts.edu/comp/140/lectures/Day_3/mips_summary.pdf Other examples]
 
[https://www.cs.tufts.edu/comp/140/lectures/Day_3/mips_summary.pdf Other examples]
Line 384: Line 447:
 
|-
 
|-
 
| -nez || if a != 0 || bnez || bnezal || brnez || snez
 
| -nez || if a != 0 || bnez || bnezal || brnez || snez
|-
 
| -nan || if a == NaN || bnan ||  || brnan || snan
 
|-
 
| -nanz || if a != NaN ||  ||  || || snanz
 
 
|-
 
|-
 
| -dns || if device d is not set          || bdns || bdnsal || brdns || sdns
 
| -dns || if device d is not set          || bdns || bdnsal || brdns || sdns
Line 446: Line 505:
 
<div id="Color"></div>
 
<div id="Color"></div>
 
;Color
 
;Color
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#212AA5;"></div>&nbsp;0 (or lower) = Blue
+
:    <span style="color:blue;">▇▇▇</span>&nbsp; 0 (or lower) = Blue
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#7B7B7B;"></div>&nbsp;1 = Grey  
+
:    <span style="color:grey;">▇▇▇</span>&nbsp;1 = Grey  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#3F9B39;"></div>&nbsp;2 = Green  
+
:    <span style="color:green;">▇▇▇</span>&nbsp;2 = Green  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#FF662B;"></div>&nbsp;3 = Orange  
+
:    <span style="color:orange;">▇▇▇</span>&nbsp;3 = Orange  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#E70200;"></div>&nbsp;4 = Red  
+
:    <span style="color:red;">▇▇▇</span>&nbsp;4 = Red  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#FFBC1B;"></div>&nbsp;5 = Yellow  
+
:    <span style="color:yellow;">▇▇▇</span>&nbsp;5 = Yellow  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#E7E7E7;"></div>&nbsp;6 = White  
+
:    <span style="color:white;">▇▇▇</span>&nbsp;6 = White  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#080908;"></div>&nbsp;7 = Black  
+
:    <span style="color:black;">▇▇▇</span>&nbsp;7 = Black  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#633C2B;"></div>&nbsp;8 = Brown  
+
:    <span style="color:brown;">▇▇▇</span>&nbsp;8 = Brown  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#63633F;"></div>&nbsp;9 = Khaki  
+
:    <span style="color:khaki;">▇▇▇</span>&nbsp;9 = Khaki  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#E41C99;"></div>&nbsp;10 = Pink  
+
:    <span style="color:pink;">▇▇▇</span>&nbsp;10 = Pink  
:    <div style="display: inline-block; vertical-align: top; height: 20px; width: 20px; border: 1px solid black; margin-right: 5px; background-color:#732CA7;"></div>&nbsp;11 (or higher) = Purple  
+
:    <span style="color:purple;">▇▇▇</span>&nbsp;11 (or higher) = Purple  
 
<div id="CompletionRatio"></div>
 
<div id="CompletionRatio"></div>
 
;CompletionRatio
 
;CompletionRatio
Line 551: Line 610:
 
;RecipeHash
 
;RecipeHash
 
<div id="RequestHash"></div>
 
<div id="RequestHash"></div>
;ReferenceId
 
:    Unique Identifier of a Device, this value is different for every device in a save.
 
<div id="ReferenceId"></div>
 
 
;RequestHash
 
;RequestHash
 
<div id="RequiredPower"></div>
 
<div id="RequiredPower"></div>
Line 633: Line 689:
 
:<code>ls r0 d0 0 Mature # Store 1 in r0 if d0 has a mature crop</code>
 
:<code>ls r0 d0 0 Mature # Store 1 in r0 if d0 has a mature crop</code>
 
:<code>ls vMature dThisVictim 0 Mature # Store 1 in vMature if dThisVictim has a mature crop</code>
 
:<code>ls vMature dThisVictim 0 Mature # Store 1 in vMature if dThisVictim has a mature crop</code>
;ReferenceId
+
 
:    Unique Identifier of a Device, this value is different for every device in a save.
 
<div id="ReferenceId"></div>
 
 
----
 
----
 
 
=Examples=
 
=Examples=
 
Previous examples were obsolete due to game changes, or confusing, they have been moved into the Discussions section
 
Previous examples were obsolete due to game changes, or confusing, they have been moved into the Discussions section
Line 646: Line 699:
  
 
<div class="mw-collapsible mw-collapsed" data-expandtext="{{int:Expand, Automated Harvie Script}}" data-collapsetext="{{int:Collapse, Automated Harvie Script}}">
 
<div class="mw-collapsible mw-collapsed" data-expandtext="{{int:Expand, Automated Harvie Script}}" data-collapsetext="{{int:Collapse, Automated Harvie Script}}">
{{ICCode|
+
<pre>
 
alias dHarvie d0
 
alias dHarvie d0
 
alias dTray d1
 
alias dTray d1
Line 657: Line 710:
 
main:
 
main:
 
yield
 
yield
#read plant data from the Tray
+
#read plant data from the Tray
 
ls r0 dTray 0 Mature
 
ls r0 dTray 0 Mature
#harvestable plants return 1, young plants return 0
+
#harvestable plants return 1, young plants return 0
#nothing planted returns -1
+
#nothing planted returns -1
 
beq r0 -1 plantCrop
 
beq r0 -1 plantCrop
 
beq r0 1 harvestCrop
 
beq r0 1 harvestCrop
 
ls r0 dTray 0 Seeding
 
ls r0 dTray 0 Seeding
#seeds available returns 1, all seeds picked returns 0
+
#seeds available returns 1, all seeds picked returns 0
#plants too young or old for seeds returns -1
+
#plants too young or old for seeds returns -1
 
beq r0 1 harvestCrop
 
beq r0 1 harvestCrop
 
j main
 
j main
  
 
plantCrop:
 
plantCrop:
#stop the planting if no seeds available
+
#stop the planting if no seeds available
#otherwise it will plant nothing repeatedly
+
#otherwise it will plant nothing repeatedly
 
ls r0 dHarvie 0 Occupied
 
ls r0 dHarvie 0 Occupied
 
beq r0 0 main
 
beq r0 0 main
Line 683: Line 736:
 
### End Script ###
 
### End Script ###
  
}}
+
</pre>
 
</div>
 
</div>
 
<br>
 
<br>
Line 689: Line 742:
  
 
===Solar Panel 2-axis tracking===
 
===Solar Panel 2-axis tracking===
 +
This script was copied from the [[Solar_Logic_Circuits_Guide]] (code provided by bti, comments and readability changes by Fudd79)
 
<div class="mw-collapsible mw-collapsed" data-expandtext="{{int:Expand, Solar Panel 2-axis tracking}}" data-collapsetext="{{int:Collapse, Solar Panel 2-axis tracking}}">
 
<div class="mw-collapsible mw-collapsed" data-expandtext="{{int:Expand, Solar Panel 2-axis tracking}}" data-collapsetext="{{int:Collapse, Solar Panel 2-axis tracking}}">
{{ICCode|
+
<pre>
#2 Axis Solar Tracking adapted from CowsAreEvil.
+
# This code assumes the following:
#Place all panels in uniform manner.
+
# Daylight Sensor data-port points north
#Set one to 15 Vertical(Min value). 0 Horizontal.
+
# Solar Panel data-port points east
#Take note direction panel faces.
 
#Place daylight sensor flat pointing in the direction
 
#the panel now faces. (Cable port facing opposite)
 
  
#Alias the sensor to d0
 
 
alias sensor d0
 
alias sensor d0
 +
alias v_angle r0
 +
alias h_angle r1
 +
alias sun_up r2
  
# define the Panel variants
+
define solar_panel_hash -539224550
define Heavy -934345724
+
define heavy_solar_panel_hash -1545574413
define HeavyDual -1545574413
 
define Solar -2045627372
 
define SolarDual -539224550
 
  
 
start:
 
start:
 +
# Check to see if sun is up
 +
l sun_up sensor Activate
 +
# Go to reset if it's not
 +
beqz sun_up reset
 +
 +
# Calculate vertical angle
 +
l v_angle sensor Vertical
 +
div v_angle v_angle 1.5
 +
sub v_angle 50 v_angle
 +
 +
# Write vertical angle to all solar panels
 +
sb solar_panel_hash Vertical v_angle
 +
sb heavy_solar_panel_hash Vertical v_angle
 +
 +
# Obtain horizontal angle
 +
l h_angle sensor Horizontal
 +
 +
# Write vertical angle to all solar panels
 +
sb solar_panel_hash Horizontal h_angle
 +
sb heavy_solar_panel_hash Horizontal h_angle
 +
 +
# Go to start again
 
yield
 
yield
#Check for daylight.
 
l r0 sensor Activate
 
beqz r0 reset
 
#Read the Horizontal data.
 
l r0 sensor Horizontal
 
#Set batch to the panels.
 
sb Heavy Horizontal r0
 
sb HeavyDual Horizontal r0
 
sb Solar Horizontal r0
 
sb SolarDual Horizontal r0
 
#Read the Vertical data and subtract 90
 
l r0 sensor Vertical
 
sub r0 90 r0
 
#Set batch to the panels.
 
sb Heavy Vertical r0
 
sb HeavyDual Vertical r0
 
sb Solar Vertical r0
 
sb SolarDual Vertical r0
 
 
j start
 
j start
  
 
reset:
 
reset:
yield
+
# Park solar panels vertically facing sunrise
sb Heavy Horizontal 270 #Edit this to face sunrise.
+
sb solar_panel_hash Vertical 0
sb HeavyDual Horizontal 270 #Edit this
+
sb heavy_solar_panel_hash Vertical 0
sb Solar Horizontal 270 #Edit this
+
# Park solar panels horizontally facing sunrise
sb SolarDual Horizontal 270 #Edit this
+
sb solar_panel_hash Horizontal -90
sb Heavy Vertical 0
+
sb heavy_solar_panel_hash Horizontal -90
sb HeavyDual Vertical 0
+
# Wait 10 seconds
sb Solar Vertical 0
 
sb SolarDual Vertical 0
 
 
sleep 10
 
sleep 10
 +
# Go to start again
 
j start
 
j start
}}
+
 
 +
### End Script ###
 +
 
 +
</pre>
 
</div>
 
</div>
 
<br>
 
<br>
Line 748: Line 804:
 
===Example experiment: how many lines of code are executed each tick?===
 
===Example experiment: how many lines of code are executed each tick?===
 
To determine this, a script without <code>yield</code> will be used. It should have as few lines as possible (so no labels are used, but a reset value at the top will be needed) and count the number of lines, the IC Housing will be used to display the result.
 
To determine this, a script without <code>yield</code> will be used. It should have as few lines as possible (so no labels are used, but a reset value at the top will be needed) and count the number of lines, the IC Housing will be used to display the result.
{{ICCode|
+
 
 +
<pre>
 
move r0 1  #the first line has number 0
 
move r0 1  #the first line has number 0
 
add r0 r0 3
 
add r0 r0 3
 
s db Setting r0
 
s db Setting r0
 
j 1
 
j 1
}}
+
</pre>
  
  
Line 810: Line 867:
 
=Links=
 
=Links=
 
----
 
----
* Stationeers online IC10 Emulators so you can develop your code without repeatedly dying in game
+
* [https://stationeering.com/tools/ic] Stationeering.com offers a programmable circuits simulator so you can develop your code without repeatedly dying in game!
** [https://ic10.dev/] Stationeers Code Simulator
 
** [https://ic10emu.dev] Stationeers IC10 Editor & Emulator - A feature packed code editor for Stationeers IC10 code, paired with a robust debugger and emulator. Edit, test, and share code.
 
** [https://stationeering.com/tools/ic] Stationeering provides a simulation of the IC10 chip inside Stationeers. IDE with error checking, full visibility of stack and registers.
 
 
* [http://www.easy68k.com/] EASy68K is a 68000 Structured Assembly Language IDE.
 
* [http://www.easy68k.com/] EASy68K is a 68000 Structured Assembly Language IDE.
 
* [https://marketplace.visualstudio.com/items?itemName=Traineratwot.stationeers-ic10] syntax highlighting for IC10 MIPS for Visual Studio Code (updated Feb 10th 2022)
 
* [https://marketplace.visualstudio.com/items?itemName=Traineratwot.stationeers-ic10] syntax highlighting for IC10 MIPS for Visual Studio Code (updated Feb 10th 2022)
 
* [https://pastebin.com/6Uw1KSRN] syntax highlighting for IC10 MIPS for KDE kwrite/kate text editor
 
* [https://pastebin.com/6Uw1KSRN] syntax highlighting for IC10 MIPS for KDE kwrite/kate text editor
 
* [https://drive.google.com/file/d/1yEsJ-u94OkuMQ8K6fY7Ja1HNpLcAdjo_/view] syntax highlighting for IC10 MIPS for Notepad++
 
* [https://drive.google.com/file/d/1yEsJ-u94OkuMQ8K6fY7Ja1HNpLcAdjo_/view] syntax highlighting for IC10 MIPS for Notepad++
 +
* [https://pastebin.com/3kmGy0NN] syntax highlighting for IC10 MIPS for Notepad++ (updated: 05/05/2021)
 
* [https://drive.google.com/file/d/1Xrv5U0ZI5jDcPv7yX7EAAxaGk5hKP0xO/view?usp=sharing] syntax highlighting for IC10 MIPS for Notepad++ (updated: 11/08/2022)
 
* [https://drive.google.com/file/d/1Xrv5U0ZI5jDcPv7yX7EAAxaGk5hKP0xO/view?usp=sharing] syntax highlighting for IC10 MIPS for Notepad++ (updated: 11/08/2022)
* [https://pastebin.com/3kmGy0NN] syntax highlighting for IC10 MIPS for Notepad++ (updated: 23/03/2024)
 
  
 
----
 
----

Please note that all contributions to Unofficial Stationeers Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Unofficial Stationeers Wiki:Copyrights for details). Do not submit copyrighted work without permission!

To edit this page, please answer the question that appears below (more info):

Cancel | Editing help (opens in new window)