// production code //!! case of 0 output cargo? - probably a different template... -1 * 0 02 0A 01 //production cb, 1 output cargo 01 //version 07 08 09 // 0A 0B // 00 //number of register containing repeat (register contains 0 = don't repeat) -1 * 0 02 0A 00 //store a value for the number of times to repeat the cb (typically 0) 89 // 1A 20 \dx00 // create 0 \2sto 1A 20 \dx00 //store in register 0F // renum gets sad about passing 0 to the range check, so create 1 and pass that instead 1A 00 \d01 //create value 1 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) 01 00 00 00 00 00 00 00 00 00 01 00 //default -1 * 0 02 0A AD //no cargo produced, register 0A and 0B zeroed 89 // 1A 20 \dx00 // create 0 10 1A 20 \dx0B //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 20 \dx0B //store in register 10 1A 20 \dx0A //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 20 \dx0A //store in register 0F // renum gets sad about passing 0 to the range check, so create 1 and pass that instead 1A 00 \d01 //create value 1 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) 00 00 00 00 00 00 00 00 00 00 00 00 //default -1 * 0 02 0A AC //where one cargo produced, all of production goes in register 0A, register 0B is zeroed 89 // 1A 20 \dx00 // create 0 10 1A 20 \dx0B //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 20 \dx0B //store in register 0F 7D 0A 20 \dxFFFFFFFF //get stored amount for total cargo output 10 1A 20 \dx0A //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 00 \dx0A //store in register \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) 00 00 00 00 00 00 00 00 00 00 00 00 //default -1 * 0 02 0A AB //where two cargos produced, industry output is split 50:50 89 // 7D 0A 20 \dxFFFFFFFF //get stored amount for total cargo output \2/ 1A 20 \d02 \2> 1A 20 \d01 // take max(cargo output result, 1) - to make sure that low amounts of cargo not lost 10 1A 20 \dx0A //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 20 \dx0A //store in register 10 1A 20 \dx0B //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 00 \dx0B //store in register \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) 00 00 00 00 00 00 00 00 00 00 00 00 //default -1 * 0 02 0A AA //how many output cargos do we have? branch accordingly (branching easier than advanced varaction 2 here) 89 // 1A 00 \d02 \b1 //range AB 00 \d02 \d02 AC 00 //default -1 * 0 02 0A A9 //add up total cargo produced and store in register 89 // 7C 04 20 \dxFFFFFFFF //get stored amount for production from cargo 1 \2+ 7C 05 20 \dxFFFFFFFF //get stored amount for production from cargo 2 \2+ 7C 06 20 \dxFFFFFFFF //get stored amount for production from cargo 3 \2sto 1A 00 \dx0A //store in register \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) AD 00 00 00 00 00 00 00 00 00 //no cargo produced AA 00 //default -1 * 0 02 0A A8 //calculate amount of input cargo actually processed 89 // 7C 06 20 \dxFFFFFFFF //get stored amount for production from cargo 3 \2/ 7C 0C 20 \dxFFFFFFFF //divide production amount by production ratio \2* 1A 20 \d08 // multiply result by 8 \2sto 1A 20 \dx09 //store in register 0F 42 20 \dxFFFFFFFF //get cargo 3 waiting \2- 7D 09 20 \dxFFFFFFFF //subtract cargo waiting from amount to be used (is any remaindered?) \2+ 7D 09 20 \dxFFFFFFFF //add result to amount to be used (to clear any remainder) 10 1A 20 \dx09 //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 00 \dx09 //store in register \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A9 00 00 00 00 00 00 00 00 00 A9 00 //default -1 * 0 02 0A A7 //calculate amount of input cargo actually processed 89 // 7C 05 20 \dxFFFFFFFF //get stored amount for production from cargo 2 \2/ 7C 0C 20 \dxFFFFFFFF //divide production amount by production ratio \2* 1A 20 \d08 // multiply result by 8 \2sto 1A 20 \dx08 //store in register 0F 41 20 \dxFFFFFFFF //get cargo 2 waiting \2- 7D 08 20 \dxFFFFFFFF //subtract cargo waiting from amount to be used (is any remaindered?) \2+ 7D 08 20 \dxFFFFFFFF //add result to amount to be used (to clear any remainder) 10 1A 20 \dx08 //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 00 \dx08 //store in register \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A8 00 00 00 00 00 00 00 00 00 A8 00 //default -1 * 0 02 0A A6 //calculate amount of input cargo actually processed 89 // 7C 04 20 \dxFFFFFFFF //get stored amount for production from cargo 1 \2/ 7C 0C 20 \dxFFFFFFFF //divide production amount by production ratio \2* 1A 20 \d08 // multiply result by 8 \2sto 1A 20 \dx07 //store in register 0F 40 20 \dxFFFFFFFF //get cargo 1 waiting \2- 7D 07 20 \dxFFFFFFFF //subtract cargo waiting from amount to be used (is any remaindered?) \2+ 7D 07 20 \dxFFFFFFFF //add result to amount to be used (to clear any remainder) 10 1A 20 \dx07 //store in persistent storage (for debug only, can be commented if not in use) \2sto 1A 00 \dx07 //store in register \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A7 00 00 00 00 00 00 00 00 00 A7 00 //default -1 * 0 02 0A A5 //store min(cargo waiting divided by prod ratio for cargo) or (output limit for produced cargo) 89 // 42 20 \dxFFFFFFFF //get cargo waiting \2/ 1A 20 \d08 //divide cargo waiting by 8 \2* 7C 0C 20 \dxFFFFFFFF //multiply cargo waiting by production ratio to get calculated production value \2< 7C 00 20 \dxFFFFFFFF //result = min(calculated production value, output limit for produced cargo) \2> 1A 20 \d01 //take max(calculated production, 1) to prevent lost production for small values of delivered cargo (e.g. small trucks etc) 10 1A 00 \dx06 //store in persistent storage (could use ordinary register, but this is easier to debug) \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A6 00 00 00 00 00 00 00 00 00 A6 00 //default //next ID repeated from calculation varact 2 above...reusing ID easier than shuffling all IDs in chain when inserting a new varact 2 -1 * 0 02 0A A5 //is there cargo waiting? If so, calculate production, otherwise go to next cargo. Also cleanup some registers here. 89 // 1A 20 \d00 //create constant 0 10 1A 20 \dx06 //use 0 to zero persistent storage register for cargo production from this cargo \2r 42 00 \dxFFFFFFFF //discard previous results; check cargo waiting \b1 //range A6 00 \d00 \d00 // no cargo waiting A5 00 // default -1 * 0 02 0A A4 //store min(cargo waiting divided by prod ratio for cargo) or (output limit for produced cargo) 89 // 41 20 \dxFFFFFFFF //get cargo waiting \2/ 1A 20 \d08 //divide cargo waiting by 8 \2* 7C 0C 20 \dxFFFFFFFF //multiply cargo waiting by production ratio to get calculated production value \2< 7C 00 20 \dxFFFFFFFF //result = min(calculated production value, output limit for produced cargo) \2> 1A 20 \d01 //take max(calculated production, 1) to prevent lost production for small values of delivered cargo (e.g. small trucks etc) 10 1A 00 \dx05 //store in persistent storage (could use ordinary register, but this is easier to debug) \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A5 00 00 00 00 00 00 00 00 00 A5 00 //default //next ID repeated from calculation varact 2 above...reusing ID easier than shuffling all IDs in chain when inserting a new varact 2 -1 * 0 02 0A A4 //is there cargo waiting? If so, calculate production, otherwise go to next cargo. Also cleanup some registers here. 89 // 1A 20 \d00 //create constant 0 10 1A 20 \dx05 //use 0 to zero persistent storage register for cargo production from this cargo \2r 41 00 \dxFFFFFFFF //discard previous results; check cargo waiting \b1 //range A5 00 \d00 \d00 // no cargo waiting A4 00 // default -1 * 0 02 0A A3 //store min(cargo waiting divided by prod ratio for cargo) or (output limit for produced cargo) 89 // 40 20 \dxFFFFFFFF //get cargo waiting \2/ 1A 20 \d08 //divide cargo waiting by 8 \2* 7C 0C 20 \dxFFFFFFFF //multiply cargo waiting by production ratio to get calculated production value \2< 7C 00 20 \dxFFFFFFFF //result = min(calculated production value, output limit for produced cargo) \2> 1A 20 \d01 //take max(calculated production, 1) to prevent lost production for small values of delivered cargo (e.g. small trucks etc) 10 1A 00 \dx04 //store in persistent storage (could use ordinary register, but this is easier to debug) \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A4 00 00 00 00 00 00 00 00 00 A4 00 //default //next ID repeated from calculation varact 2 above...reusing ID easier than shuffling all IDs in chain when inserting a new varact 2 -1 * 0 02 0A A3 //is there cargo waiting? If so, calculate production, otherwise go to next cargo. Also cleanup some registers here. 89 // 1A 20 \d00 //create constant 0 10 1A 20 \dx04 //use 0 to zero persistent storage register for cargo production from this cargo \2r 40 00 \dxFFFFFFFF //discard previous results; check cargo waiting \b1 //range A4 00 \d00 \d00 // no cargo waiting A3 00 // default -1 * 0 02 0A A2 // set total production ratio 89 // 1A 20 \d00 // create 00 \2+ 7C 01 20 \dxFFFFFFFF //add prod ratio for cargo 1 \2+ 7C 02 20 \dxFFFFFFFF //add prod ratio for cargos 2 and 3 10 1A 00 \dx0C //store in persistent storage (could use ordinary register, but this is easier to debug) \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A3 00 00 00 00 00 00 00 00 00 A3 00 -1 * 0 02 0A B9 //case no cargo 2 or 3 delivered recently 89 // using type 89 because register IDs are better specified as double words 1A 20 \d00 //set 0 for production ratio cargo 2_3 10 1A 20 \dx02 // store in persistent storage 0F // renum gets sad about passing 0 to the range check, so create 1 and pass that instead 1A 00 \d01 //create value 1 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A2 00 00 00 00 00 00 00 00 00 A2 00 -1 * 0 02 0A B8 //case some cargo 2 delivered recently 89 // using type 89 because register IDs are better specified as double words 1A 20 \d04 //set positive value for production ratio cargo 2_3 10 1A 20 \dx02 // store in persistent storage 0F 1A 20 \d01 //create value 1 \2+ 7C 0E 20 \dxFFFFFFFF //add to 'combinatory production ticker' for cargo 2_3 10 1A 00 \dx0E // store in persistent storage \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A2 00 00 00 00 00 00 00 00 00 A2 00 -1 * 0 02 0A B7 //check if some cargo 2 or 3 delivered recently - in last 8(?check?) production cycles 89 // 7c 0E 00 \dxFFFFFFFF //get 'combinatory production ticker' value from storage. \b1 //range B8 00 \d00 \d07 B9 00 //default -1 * 0 02 0A B6 //case some cargo 2 or 3 waiting 89 // using type 89 because register IDs are better specified as double words 1A 20 \d00 //set 0 for 'combinatory production ticker' cargo 2_3 10 1A 20 \dx0E //store in persistent storage 0F // renum gets sad about passing 0 to the range check, so create 1 and pass that instead 1A 00 \d01 //create value 1 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) B8 00 00 00 00 00 00 00 00 00 B8 00 -1 * 0 02 0A B5 //check cargo waiting 2 and 3 85 // 41 20 \wxFFFF \2+ 42 00 \wxFFFF \b1 //range B7 00 \w00 \w00 //no cargo waiting B6 00 //some cargo waiting -1 * 0 02 0A B4 //case no cargo 1 delivered recently 89 // using type 89 because register IDs are better specified as double words 1A 20 \d00 //set 0 for production ratio cargo 1 10 1A 20 \dx01 // store in persistent storage 0F // renum gets sad about passing 0 to the range check, so create 1 and pass that instead 1A 00 \d01 //create value 1 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) B5 00 00 00 00 00 00 00 00 00 B5 00 -1 * 0 02 0A B3 //case some cargo 1 delivered recently 89 // using type 89 because register IDs are better specified as double words 1A 20 \d04 //set positive value for production ratio cargo 1 10 1A 20 \dx01 // store in persistent storage 0F 1A 20 \d01 //create value 1 \2+ 7C 0D 20 \dxFFFFFFFF //add to 'combinatory production ticker' for cargo 1 10 1A 00 \dx0D // store in persistent storage \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) B5 00 00 00 00 00 00 00 00 00 B5 00 -1 * 0 02 0A B2 //check if some cargo 1 delivered recently - in last 8(?check?) production cycles 89 // 7c 0D 00 \dxFFFFFFFF \b1 //range B3 00 \d00 \d07 B4 00 //default -1 * 0 02 0A B1 //case some cargo 1 waiting 89 // using type 89 because register IDs are better specified as double words 1A 20 \d00 //set 0 for 'combinatory production ticker' cargo 1 10 1A 20 \dx0D //store in persistent storage 0F // renum gets sad about passing 0 to the range check, so create 1 and pass that instead 1A 00 \d01 //create value 1 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) B3 00 00 00 00 00 00 00 00 00 B3 00 -1 * 0 02 0A B0 //check cargo waiting 1 85 // 40 00 \wxFFFF \b1 //range B2 00 \w00 \w00 //no cargo waiting B1 00 //some cargo waiting // PROVIDE DEBUG INFO TO INDUSTRY WINDOW //Remember text stack is LIFO (like array.pop) - put values to render first in highest registers -1 * 0 02 0A FF //store one values to text stack for debugging 89 // 7c 0F 20 \dxffff \2ror 1a 20 \d16 \2| 7c 0E 20 \dxffff \2sto 1a 00 \dx105 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) A3 80 00 00 00 00 00 00 00 00 A3 80 //default -1 * 0 02 0A FE //store two values to text stack for debugging 89 // 7c 0D 20 \dxffff \2ror 1a 20 \d16 \2| 7c 0C 20 \dxffff \2sto 1a 00 \dx104 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) FF 00 00 00 00 00 00 00 00 00 FF 00 //default -1 * 0 02 0A FD //store two values to text stack for debugging 89 // 7c 0B 20 \dxffff \2ror 1a 20 \d16 \2| 7c 0A 20 \dxffff \2sto 1a 00 \dx103 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) FE 00 00 00 00 00 00 00 00 00 FE 00 //default -1 * 0 02 0A FC //store two values to text stack for debugging 89 // 7c 09 20 \dxffff \2ror 1a 20 \d16 \2| 7c 08 20 \dxffff \2sto 1a 00 \dx102 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) FD 00 00 00 00 00 00 00 00 00 FD 00 //default -1 * 0 02 0A FB //store two values to text stack for debugging 89 // 7c 07 20 \dxffff \2ror 1a 20 \d16 \2| 7c 03 20 \dxffff \2sto 1a 00 \dx101 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) FC 00 00 00 00 00 00 00 00 00 FC 00 //default -1 * 0 02 0A FA //store two values to text stack for debugging 89 7c 02 20 \dxffff \2ror 1a 20 \d16 \2| 7c 01 20 \dxffff \2sto 1a 00 \dx100 \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) FB 00 00 00 00 00 00 00 00 00 FB 00 //default -1 * 0 02 0A F0 // 81 // 7F \b03 00 \b01 // check if first bit is set for debug parameter \b1 //range FA 00 \b01 \b01 01 80 //default // !! the logic for output limit is flawed. This assumes limit is FF FF; when 2 output cargos are split 50:50, output limit before split is 2 * FF FF // TTDPatch wiki for production callback: "results are clamped to the allowed range (0..32767 for incoming cargo amounts, 0..65535 for outgoing cargo amounts)." -1 * 0 02 0A C1 //store output limit for produced cargo (as units of output cargo) to use when processing each input cargo 89 // using type 89 because register IDs are better specified as double words 1A 20 \dxFFFF // create a value (constant 1A); total production limit is FF FF per output cargo \2/ 1a 20 \d02 // divide by number of input cargos for this industry (exclude production-boosting cargos from input cargo count) 10 1A 00 \dx00 // store in persistent storage \b1 //range (stay out of the nvar=0 bear pit by checking one range, but returning same for both) B0 00 00 00 00 00 00 00 00 00 B0 00