Difference between revisions of "Storages"

From GRFSpecs
Jump to navigationJump to search
(Larger persistent storage for OTTD.)
 
Line 19: Line 19:
 
{{ottdp|0.6|2.6}}
 
{{ottdp|0.6|2.6}}
   
'''Size:''' 00 - 0F (16)
+
'''Size:''' 00 - 0F (16) or 00 - FF (256) (since {{ottd|1.9|6391d49}})
   
 
'''Data storage:''' [[VarAction2Advanced#operator|Operator \2psto (10)]] allows to store values inside the registers of this storage.
 
'''Data storage:''' [[VarAction2Advanced#operator|Operator \2psto (10)]] allows to store values inside the registers of this storage.
Line 33: Line 33:
 
{{ottdp|1.2|ottdrev=r22569}}
 
{{ottdp|1.2|ottdrev=r22569}}
   
'''Size:''' 00 - 0F (16) for each GRFID
+
'''Size:''' 00 - 0F (16) or 00 - FF (256) (since {{ottd|1.9|6391d49}}) for each GRFID
   
 
'''Data storage:''' [[VarAction2Advanced#operator|Operator \2psto (10)]] allows to store values inside the registers of this storage. The GRFID to access must be stored in temporary register 0x100 before using Operator 10. 0xFFFFFFFF can be used to access the GRFID of the item using the current [[VariationalAction2]] chain.
 
'''Data storage:''' [[VarAction2Advanced#operator|Operator \2psto (10)]] allows to store values inside the registers of this storage. The GRFID to access must be stored in temporary register 0x100 before using Operator 10. 0xFFFFFFFF can be used to access the GRFID of the item using the current [[VariationalAction2]] chain.

Latest revision as of 19:50, 2 September 2018

Introduction

Storages are arrays of registers that can be accessed when using VariationalAction2. Registers (temporary and persistent alike) always have a size of 4 bytes. If you're writing them using smaller sizes (anything but type 89/8A), the given value will be sign-extended to 4 bytes. Therefore, be careful when you read a register using a bigger size than it was written with. This also applies to registers read by TTDPatch; if not indicated specifically, TTDPatch reads all 4 bytes of the register.

Description

Temporary storage

Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.62.6

Size: 00 - FF (256) (from TTDPatch r1246 to r1301) or 00 - 10F (272) (since TTDPatch r1301 and OpenTTD r9707)

Data storage: Operator \2sto (0E) allows to store values inside the registers of this storage.

Data access: The first 256 registers 00 to FF can be read using variable 7D. The rest of the values (100 to 10F) are write only: they are used to pass extra data to some 4x and 6x variables, as well as for returning extra data from callbacks.


Temporary storage contains values local to the current VariationalAction2 chain. When a new chain starts, the values inside the temporary storage are undefined. Therefore, they should not be used unless they have been properly initialized. During the execution of a chain, only that chain can modify the values in the temporary storage.

Persistent storage

Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.62.6

Size: 00 - 0F (16) or 00 - FF (256) (since Supported by OpenTTD 1.9 (6391d49)1.9)

Data storage: Operator \2psto (10) allows to store values inside the registers of this storage.

Data access: The registers can be read using variable 7C. Note that it is possible to access the persistent storage of related objects (see VariationalAction2#Type).

Features that support it: Industries (0A)


Persistent storage is associated to a single item. When the item is created, all of the values of the persistent storage are set to zero. Persistent storage values cannot be accessed or modified by items that are being created. Persistent storage should not be read if the current feature doesn't support it.

Persistent storage accessed by GRFID

Supported by OpenTTD 1.2 (r22569)1.2 Not supported by TTDPatch

Size: 00 - 0F (16) or 00 - FF (256) (since Supported by OpenTTD 1.9 (6391d49)1.9) for each GRFID

Data storage: Operator \2psto (10) allows to store values inside the registers of this storage. The GRFID to access must be stored in temporary register 0x100 before using Operator 10. 0xFFFFFFFF can be used to access the GRFID of the item using the current VariationalAction2 chain.

Data access: The registers can be read using variable 7C. Note that it is possible to access the persistent storage of related objects (see VariationalAction2#Type). The GRFID to access must be stored in temporary register 0x100 before checking variable 7C. 0xFFFFFFFF can be used to access the GRFID of the item using the current VariationalAction2 chain.

Features that support it: Towns (since OpenTTD r22569)


Features supporting persistent storage accessed by GRFID are not restricted to a single persistent storage; there is a persistent storage associated to every GRFID. An item only has write access to the persistent storage associated to its own GRFID, but it can read the registers of any GRFID. Persistent storage values cannot be accessed or modified by items that are being created. Persistent storage should not be read if the current feature doesn't support it.