Actions

Difference between revisions of "Vending Machine Export IC10"

From Unofficial Stationeers Wiki

m
m (Category:MIPS Programming)
 
Line 1: Line 1:
 +
[[Category:MIPS Programming]]
 
This solution will export a given quantity of the specified item from a vending machine.
 
This solution will export a given quantity of the specified item from a vending machine.
 
[[File:VendingExporterSetup.png|thumb|right|Connect the three devices with chutes as shown in the diagram.]]
 
[[File:VendingExporterSetup.png|thumb|right|Connect the three devices with chutes as shown in the diagram.]]

Latest revision as of 15:45, 18 June 2020

This solution will export a given quantity of the specified item from a vending machine.

Connect the three devices with chutes as shown in the diagram.

Required Items[edit]

Source code:

#Vending machine item exporter alias rTemp r0 alias rTemp2 r1 alias rBusy r2 alias rReqHash r9 alias rReqCount r10 alias rMaxUnitStack r11 alias rStackerCount r12 alias rStackerSetting r13 alias dVender d0 alias dStacker d1 alias dSorter d2 alias dMemHash d3 alias dMemCount d4 #alias dStartExport d5 main: yield l rBusy dMemCount Setting beqz rBusy main l rBusy dMemHash Setting beqz rBusy main jal _Configuration l rReqCount dMemCount Setting l rReqHash dMemHash Setting s dMemCount Setting 0 jal _ExportItem j main _Configuration: s dSorter Mode 0 s dStacker Mode 1 s dStacker ClearMemory 1 s dSorter ClearMemory 1 s dVender ClearMemory 1 j ra _ExportItem: push ra ExportItemLoop: ls rTemp dStacker 2 Quantity s dVender RequestHash rReqHash #wait for item to arrive ls rTemp2 dStacker 2 Quantity breq rTemp rTemp2 -1 ls rStackerCount dStacker 2 Quantity ls rMaxUnitStack dStacker 2 MaxQuantity jal _WaitForDevices min rStackerSetting rReqCount rMaxUnitStack min rStackerSetting rStackerSetting rStackerCount breq rStackerCount rMaxUnitStack 2 bgt rReqCount rStackerCount ExportItemLoop s dStacker Setting rStackerSetting s dSorter Output 0 jal _RunStacker ls rStackerCount dStacker 2 Quantity sub rReqCount rReqCount rStackerSetting bgtz rReqCount ExportItemLoop #done, route any leftovers to the vender beqz rStackerCount ExportItemExit s dStacker Setting rStackerCount s dSorter Output 1 jal _RunStacker ExportItemExit: pop ra j ra _RunStacker: push ra l rTemp dSorter ImportCount s dStacker Output 1 #wait for item to arrive l rTemp2 dSorter ImportCount breq rTemp rTemp2 -1 jal _WaitForDevices pop ra j ra _WaitForDevices: yield ls rBusy dSorter 0 Occupied bgtz rBusy _WaitForDevices ls rBusy dSorter 1 Occupied bgtz rBusy _WaitForDevices ls rBusy dSorter 2 Occupied bgtz rBusy _WaitForDevices ls rBusy dVender 0 Occupied bgtz rBusy _WaitForDevices ls rBusy dVender 1 Occupied bgtz rBusy _WaitForDevices #if the stacker is full so we skip it beq rStackerCount rMaxUnitStack WaitEnd ls rBusy dStacker 0 Occupied bgtz rBusy _WaitForDevices ls rBusy dStacker 1 Occupied bgtz rBusy _WaitForDevices WaitEnd: j ra


Setup[edit]

  • Place all components listed above and connect them using Cables and Chutes as shown in the picture. (For cables just connect everything)
  • Load the code into the IC and turn everything on
  • You may want to put a junction and an inlet to the import of the vending machine so you can restock it.

Usage[edit]

  1. Set the two memory modules with the quantity and the hash of the item.
  2. Unless busy, the IC will set the quantity memory to zero and start the export process.
  3. Excess items will be routed back into the vending machine.

NOTE: The IC can handle split stacks of small quantities in the vending machine or exporting more than one stack. It does NOT handle having insufficient items in the vending machine and will halt until you fill it and export it manually (or reset the whole process)

How It Works[edit]

Main loop[edit]

  • Wait until both memory modules have a non-zero value.
  • Run device configuration.
  • Store request hash and quantity.
  • Reset the memory for quantity to indicate the start of the export (and so we don't keep exporting the same item)
  • Run the item export function.

_Configuration[edit]

  • Configure the sorter for default mode, and the stacker for manual.

_ExportItem[edit]

  • Request the item from the vender and wait for it to arrive into the stacker, then run _WaitForDevices​ to make sure nothing is busy.
  • Calculate the setting for the stacker depending on the remaining items, the quantity inside the stacker and the maximum stacking size (in manual mode, it won't do anything until the Output parameter is set to 1)
  • Either make another request from the vender, or flush the stacker if it's full.
  • Make more requests if there are remaining items, or empty the stacker and route any excess items back into the vender.

_RunStacker[edit]

  • Set the output of the sorter, run the stacker and wait for the item to arrive in the sorter.

_WaitForDevices[edit]

  • Makes sure none of the devices have occupied import/export slots - the exception being the stacker, since it may have a full processing slot and items stuck in the import slot (for example when the vender exports 30 coal twice in a row. 50 will be in the processing slot and 10 in import.)