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: | + | [[Category:MIPS Programming]] |
− | = | + | =MIPS scripting language for IC10 housings / chips= |
− | + | ||
+ | <pre> | ||
+ | # Text after a # will be ignored to the end of the line. The amount of white | ||
+ | # space between arguments isn't important, but new lines start a new command. | ||
+ | </pre> | ||
==Registers== | ==Registers== | ||
− | + | The IC contains 16 registers, numbered r0-r15. Think of these as variables in other programming languages. In fact, you can name them with the alias command (see below). | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | To set a register directly (such as r0=2), use the <b>move</b> command. To read a value from a device, use <b>l</b> (load). To write a value back to a device, use <b>s</b> (set). Note that | |
− | + | like most machine languages, the <i>destination</i> goes first, so instructions always look like: action destination source. | |
− | + | Here are some examples set a register, reading a value from a device and writing a value to device: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <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>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 | ||
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 | + | 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 '''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 | ||
− | It's recommended to use labels (like: ''someVariable'') instead of a direct reference to the register. See ''' | + | It's recommended to use labels (like: ''someVariable'') instead of a direct reference to the register. See section '''Labels'''. |
− | |||
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. | ||
− | == | + | ==Device Ports== |
− | + | ICs can interact with up to 6 other devices via d0 - d5, as well as the device it's attached to via db. To change or set a device, use a screwdriver and adjust the device in the IC housing. You can read or set any of the device's properties, so it is possible to do things like read the pressure and oxygen content of a room on the same Device port. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | The l (load) and s (set) instructions let you read and set values on a device. | |
− | + | <code>l r0 d0 Temperature</code> #Reads the temperature from an atmosphere sensor into r0. | |
− | + | <code>s d1 Setting r0 </code> # Writes r0 to the device on port 1 to the Setting variable. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | # | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==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. | ||
− | + | <br><code>main:</code> | |
− | main: | + | <br><code>j main</code> |
− | j 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 | + | Instead of using a register to store a fixed value, a constant can be made. Using this name will refer to the assigned value. |
− | + | <br><code>define pi 3.14159</code> | |
− | + | <br><code>move r0 pi</code> | |
− | |||
− | |||
− | |||
− | + | ==Indirect referencing== | |
− | + | 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. | |
− | |||
− | |||
− | |||
− | + | <code>move r0 5</code> stores the value 5 in r0 | |
− | + | <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 | |
− | |||
− | move r0 5 | ||
− | move rr0 10 | ||
− | |||
− | |||
− | |||
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. | ||
− | + | <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 | ||
− | |||
− | |||
− | |||
This also works with devices | This also works with devices | ||
− | + | <br><code>move r0 2</code> stores the value 2 in r0 | |
− | move r0 2 | + | <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 | ||
− | |||
− | |||
− | |||
− | == | + | ==Debugging advice== |
+ | The value stored in a register can easily be seen by writing it to the Setting parameter of the IC housing, this has no sideeffects, too see the value just stand close and look directly at the housing (<code>s db Setting r0</code>). | ||
+ | <br>To check if a certain block of code is executed, use the above trick but with a number that you choose, like the line number (<code>s db Setting 137</code>). | ||
+ | <br>The configuration card can be used to manually check the data values stored in all connected devices. | ||
− | + | ==Learning MIPS== | |
− | + | 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. | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | ==Learning | ||
− | |||
General: | General: | ||
− | + | <pre> | |
− | + | alias (make the script easier to read by assigning a name to a register or device, example: alias rTemperature r15) | |
− | + | label: (where "label" can be replaced with almost any word, jump and branch instructions will go to these, example: start:) | |
− | + | yield (pause for 1-tick and then resume, if not used the script will automatically pause for 1-tick after 128 lines) | |
+ | </pre> | ||
<br>Jumps: | <br>Jumps: | ||
− | + | <pre> | |
− | + | j label | |
− | + | jal label (stores the next line number into the "return address"-register and then jump to label) | |
+ | j ra (jump to the "return address") | ||
+ | </pre> | ||
− | + | <br>Branching (jump-if): | |
− | <br>Branching (jump-if):< | + | <pre> |
− | + | beq (branch if equal) | |
− | + | bne (branch if not-equal) | |
− | + | bgt (branch if greater than) | |
− | + | blt (branch if less than) | |
− | The suffix -al can be added to each of these (example: beqal) to save the | + | The suffix -al can be added to each of these (example: beqal) to save the next line number into the "return address" register |
+ | </pre> | ||
<br>Device interactions: | <br>Device interactions: | ||
<pre> | <pre> | ||
l (load) | l (load) | ||
− | lb (load batch, requires one of the following: | + | lb (load batch, requires one of the following: Average / Sum / Minimum / Maximum) |
ls (load slot) | ls (load slot) | ||
s (store) | s (store) | ||
Line 266: | Line 119: | ||
Setting (meaning varies between devices, example: a LED display(console) will show this value) | Setting (meaning varies between devices, example: a LED display(console) will show this value) | ||
Activate (1 usually means running, example: a Daylight sensor is 1 when the sun shines on it) | Activate (1 usually means running, example: a Daylight sensor is 1 when the sun shines on it) | ||
− | Temperature (in Kelvin, Celsius | + | Temperature (in Kelvin, Celsius + 273.15) |
Pressure (in kPa) | Pressure (in kPa) | ||
</pre> | </pre> | ||
<br>Notes: | <br>Notes: | ||
− | <br>-All instructions and variables can be seen in-game in the | + | <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 277: | Line 130: | ||
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 | + | <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) |
---- | ---- | ||
− | |||
=Instructions= | =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> | ||
+ | |||
+ | <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 323: | Line 350: | ||
|- | |- | ||
| -nez || if a != 0 || bnez || bnezal || brnez || snez | | -nez || if a != 0 || bnez || bnezal || brnez || snez | ||
− | |||
− | |||
− | |||
− | |||
|- | |- | ||
| -dns || if device d is not set || bdns || bdnsal || brdns || sdns | | -dns || if device d is not set || bdns || bdnsal || brdns || sdns | ||
Line 344: | Line 367: | ||
All approximate functions require additional argument denoting how close two numbers need to be considered equal. E.g.: <code>sap r0 100 101 0.01</code> will consider 100 and 101 almost equal (not more than 1%=0.01 different) and will set r0 to 1. The exact formula is <code>if abs(a - b) <= max(c * max(abs(a), abs(b)), float.epsilon * 8)</code> for <code>-ap</code> and is similar for other approximate functions. | All approximate functions require additional argument denoting how close two numbers need to be considered equal. E.g.: <code>sap r0 100 101 0.01</code> will consider 100 and 101 almost equal (not more than 1%=0.01 different) and will set r0 to 1. The exact formula is <code>if abs(a - b) <= max(c * max(abs(a), abs(b)), float.epsilon * 8)</code> for <code>-ap</code> and is similar for other approximate functions. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Device Variables== | ==Device Variables== | ||
Line 381: | Line 382: | ||
: The current charge the device has. | : The current charge the device has. | ||
<div id="CLearMemory"></div> | <div id="CLearMemory"></div> | ||
− | ; | + | ;CLearMemory |
: When set to 1, clears the counter memory (e.g. ExportCount). Will set itself back to 0 when triggered. | : When set to 1, clears the counter memory (e.g. ExportCount). Will set itself back to 0 when triggered. | ||
<div id="Color"></div> | <div id="Color"></div> | ||
;Color | ;Color | ||
− | : | + | : 0 (or lower) = Blue |
− | : | + | : 1 = Grey |
− | : | + | : 2 = Green |
− | : | + | : 3 = Orange |
− | : | + | : 4 = Red |
− | : | + | : 5 = Yellow |
− | : | + | : 6 = White |
− | : | + | : 7 = Black |
− | : | + | : 8 = Brown |
− | : | + | : 9 = Khaki |
− | : | + | : 10 = Pink |
− | : | + | : 11 (or higher) = Purple |
<div id="CompletionRatio"></div> | <div id="CompletionRatio"></div> | ||
;CompletionRatio | ;CompletionRatio | ||
Line 490: | Line 491: | ||
;RecipeHash | ;RecipeHash | ||
<div id="RequestHash"></div> | <div id="RequestHash"></div> | ||
− | |||
− | |||
− | |||
;RequestHash | ;RequestHash | ||
<div id="RequiredPower"></div> | <div id="RequiredPower"></div> | ||
Line 572: | Line 570: | ||
:<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> | ||
− | + | ||
− | |||
− | |||
---- | ---- | ||
− | |||
=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 585: | Line 580: | ||
<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}}"> | ||
− | + | <pre> | |
alias dHarvie d0 | alias dHarvie d0 | ||
alias dTray d1 | alias dTray d1 | ||
Line 596: | Line 591: | ||
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 622: | Line 617: | ||
### End Script ### | ### End Script ### | ||
− | + | </pre> | |
</div> | </div> | ||
<br> | <br> | ||
Line 628: | Line 623: | ||
===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}}"> | ||
− | + | <pre> | |
− | # | + | # This code assumes the following: |
− | # | + | # Daylight Sensor data-port points north |
− | # | + | # Solar Panel data-port points east |
− | |||
− | |||
− | |||
− | |||
alias sensor d0 | alias sensor d0 | ||
+ | alias v_angle r0 | ||
+ | alias h_angle r1 | ||
+ | alias sun_up r2 | ||
− | + | define solar_panel_hash -539224550 | |
− | + | define heavy_solar_panel_hash -1545574413 | |
− | define | ||
− | |||
− | |||
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 | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
j start | j start | ||
reset: | reset: | ||
− | + | # Park solar panels vertically facing sunrise | |
− | + | sb solar_panel_hash Vertical 0 | |
− | + | sb heavy_solar_panel_hash Vertical 0 | |
− | + | # Park solar panels horizontally facing sunrise | |
− | + | sb solar_panel_hash Horizontal -90 | |
− | sb | + | sb heavy_solar_panel_hash Horizontal -90 |
− | sb | + | # Wait 10 seconds |
− | sb | ||
− | sb | ||
sleep 10 | sleep 10 | ||
+ | # Go to start again | ||
j start | j start | ||
− | + | ||
+ | ### End Script ### | ||
+ | |||
+ | </pre> | ||
</div> | </div> | ||
<br> | <br> | ||
Line 687: | Line 685: | ||
===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. | ||
− | + | ||
+ | <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 711: | Line 710: | ||
=Links= | =Links= | ||
---- | ---- | ||
− | + | * [https://stationeering.com/tools/ic] Stationeering.com offers a programmable circuits simulator so you can develop your code without repeatedly dying in game! | |
− | |||
− | |||
− | |||
* [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://pastebin.com/3kmGy0NN] syntax highlighting for IC10 MIPS for Notepad++ (updated: | + | |
---- | ---- |