Skip to content

Elementary memory access

This part of Ikarus makes it possible to read and write memory as different data types - integers, strings, arrays of integers or strings and bytes.

If address <= 0, an error is thrown. Otherwise, an attempt is made to read or write at this address. If the address falls into invalid range, for example in a code segment, access violation will occur (Gothic crashes). In the case of string operations, it is also necessary that at the specified position a valid zString already exists.

Initialization

The best way to initialize all Ikarus functions is to call MEM_InitAll() in the Init_Global() initialization function.

Warning

If you want to use Ikarus in Gothic 1, it is best to define your own Init_Global() function and call it from every world initialization function.

MEM_InitAll();

Implementation

Ikarus.d on GitHub

Read functions

MEM_ReadInt

MEM_ReadInt

Reads int from the address.

func int MEM_ReadInt(var int address)
Parameters
  • var int address
    Memory address to read from

Return value

The function returns an integer value if the address is correct.

MEM_ReadString

MEM_ReadString

Reads string from the address.

func string MEM_ReadString(var int address)
Parameters
  • var int address
    Memory address to read from

Return value

The function returns string if the address is correct.

MEM_ReadByte

MEM_ReadByte

Reads byte from the address.

func int MEM_ReadByte(var int address)
Parameters
  • var int address
    Memory address to read from

Return value

The function returns byte value if the address is correct.

MEM_ReadIntArray

MEM_ReadIntArray

Reads int from the array at the arrayAddress.

func int MEM_ReadIntArray(var int arrayAddress, var int offset)
Parameters
  • var int arrayAddress
    Memory address of array
  • var int offset
    Array offset (array index)

Return value

The function returns integer value from the array if the address is correct.

MEM_ReadStringArray

Info

MEM_ReadStringArray has been already moved to the LeGo PermMem package.

MEM_ReadByteArray

MEM_ReadByteArray

Reads byte from the array at the arrayAddress.

func int MEM_ReadByteArray(var int arrayAddress, var int offset)
Parameters
  • var int arrayAddress
    Memory address of array
  • var int offset
    Array offset (array index)

Return value

The function returns byte from the array if the address is correct.

Write functions

MEM_WriteInt

MEM_WriteInt

Writes int value in the address.

func void MEM_WriteInt(var int address, var int value)
Parameters
  • var int address
    Memory address to write into
  • var int value
    Integer value to write
Example

An example of using this function is the following Ikarus function, which turns debugging messages on and off:

1
2
3
4
func void MEM_SetShowDebug(var int on)
{
    MEM_WriteInt(showDebugAddress, on);
};

MEM_WriteString

MEM_WriteString

Writes string in the address.

func void MEM_WriteString(var int address, var string value)
Parameters
  • var int address
    Memory address to write into
  • var int value
    String to write

MEM_WriteByte

MEM_WriteByte

Only the byte at address address is changed here, not a whole four-byte word. That is, the three subsequent bytes remain untouched. If 0 <= val < 256 does not apply in MEM_WriteByte, a warning is issued and val is trimmed accordingly. In particular, shouldn't be negative numbers are passed.

func void MEM_WriteByte(var int address, var int value)
Parameters
  • var int address
    Memory address to write into
  • var int value
    Byte to write

MEM_WriteIntArray

MEM_WriteIntArray

Writes int value in the array at arrayAddress.

func void MEM_WriteIntArray(var int arrayAddress, var int offset, var int value)
Parameters
  • var int arrayAddress
    Memory address of array
  • var int offset
    Array offset (array index)
  • var int value
    Integer value to write

MEM_WriteStringArray

MEM_WriteStringArray

Writes string value in the array at arrayAddress.

func void MEM_WriteStringArray(var int arrayAddress, var int offset, var string value)
Parameters
  • var int arrayAddress
    Memory address of array
  • var int offset
    Array offset (array index)
  • var string value
    String to write

MEM_WriteByteArray

MEM_WriteByteArray

Writes byte value in the array at arrayAddress.

func void MEM_WriteByteArray(var int arrayAddress, var int offset, var int value)
Parameters
  • var int arrayAddress
    Memory address of array
  • var int offset
    Array offset (array index)
  • var int value
    Byte to write