Storages

From GRFSpecs
Revision as of 17:51, 27 December 2011 by Michi cc (talk | contribs) (→‎Persistent storage accessed by GRFID: OTTD source says 7C)
Jump to navigationJump to search

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)

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