Offset index

From Sega Retro

In the Motorola 68000 assembly language, pointers may be stored in an array called an offset index. When you want to refer to data, or jump to another piece of code, it is more efficient to use a simple list of pointers than to hard-code a series of comparison instructions.

A few lines of code are used to check a variable (which zone you're in, for example) and then based on that variable, one of the pointers in the array is used. This is very efficient compared to "if the zone number is 1, jump to offset X", followed by "if the zone number is 2, jump to offset Y" and so on.

There are two types of commonly used offset indices - relative and absolute.

Relative pointers are two bytes (one word) long. The value in the offset index is added to the program counter (i.e. the current position in the ROM) to give the target offset. Pointers are "signed", meaning they can be negative as well as positive, so the maximum range of a pointer is $7FFF bytes (values $8001 to $FFFF are read as -$7FFF to -$0001).

Absolute pointers are four bytes (one double-word) long. The value of the pointer is read simply as a location in the ROM.