SCUMM/Arrays and Strings

From ScummVM :: Wiki
Jump to navigation Jump to search

Introduction

Arrays are used for storing arbitrary blocks of data. They are accessible by the scripts, and so can be used for storing anything that might be useful; however, the contents of an array is not stored in the data file and can only be set at run time. Arrays can be dynamically allocated and freed as desired, but only a limited number are available. See the section on Arrays in the Scripts chapter for more information.

The way Arrays work was redesigned completely between V5 and V6.

V5 chunk Format

V5 Arrays are not stored in the data file. 32 Arrays are available for access using the arrayOps opcode. V5 Arrays (sometimes also referred to as Strings) are one-dimensional.

V6 chunk Format

 Size    Type             Description
 ====    ====             ===========
 8       chunk tag        AARY chunk tag
for each array {
 2       word LE          array resource number
 2       word LE          X size minus one
 2       word LE          Y size minus one
 2       word LE          array type
}
 2       word LE          zero

The X and Y size fields are set to one less than the actual size; an entry of 0 means a size of 1. Arrays are always two-dimensional.

The type field can be one of:

Value Meaning
1 Array of bits
2 Array of nibbles (half bytes)
3 Array of bytes
4 Array of chars (= a string)
5 Array of integers

V8 chunk Format

 Size    Type             Description
 ====    ====             ===========
 8       chunk tag        AARY chunk tag
for each array {
 4       dword LE         array resource number
 4       dword LE         X size minus one
 4       dword LE         Y size minus one
}
 4       dword LE         zero

The X and Y size fields are set to one less than the actual size; an entry of 0 means a size of 1. One dimensional arrays are simply a special case, where one dimension has size 1.