Difference between revisions of "Storages"

From GRFSpecs
Jump to navigationJump to search
(hex and dec sizes)
(obiwan is even here)
Line 11: Line 11:
 
'''Data storage:''' [[VarAction2Advanced#operator|Operator \2sto (0E)]] allows to store values inside the registers of this storage.
 
'''Data storage:''' [[VarAction2Advanced#operator|Operator \2sto (0E)]] allows to store values inside the registers of this storage.
   
'''Data access:''' The first FF registers can be read using [[VariationalAction2#Variable|variable 7C]]. The rest of the values 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.
+
'''Data access:''' The first 256 registers 00 to FF can be read using [[VariationalAction2#Variable|variable 7C]]. 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.
   
   

Revision as of 19:37, 25 July 2011

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 7C. 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.

Persistent storage

Supported by OpenTTD 0.60.6 Supported by TTDPatch 2.62.6

Size: 00 - 0F (16)

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

Data access: The registers can be read using variable 7D. 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 - FF (16) 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 7D. 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.