using System;
using System.Runtime.InteropServices;
namespace pkNX.Structures
{
[StructLayout(LayoutKind.Sequential)]
public class AmxHeader
{
// Cell Size magic verification
public const ushort MAGIC_32 = 0xf1e0;
public const ushort MAGIC_64 = 0xf1e1;
public const ushort MAGIC_16 = 0xf1e2;
/// Size of the "file"
public int Size; // 0x00
/// Signature
public ushort Magic; // 0x04
/// File format version
public byte FileVersion; // 0x06
/// Required version of the AMX
public byte AMXVersion; // 0x07
/// Feature flags
public AmxFlags Flags; // 0x08
/// Size of a definition record
public short DefinitionSize; // 0x0A
/// Initial value of COD - code block
public int COD; // 0x0C
/// initial value of DAT - data block
public int Data; // 0x10
/// Initial value of HEA - start of the heap
public int Heap; // 0x14
/// Initial value of STP - stack top
public int StackTop; // 0x18
/// Initial value of CIP - the instruction pointer
public int CurrentInstructionPointer; // 0x20
/// Offset to the "public functions" table
public int Publics; // 0x24
/// Offset to the "native functions" table
public int Natives; // 0x28
/// Offset to the table of libraries
public int Libraries; // 0x2C
/// Offset to the "public variables" table
public int PublicVars; // 0x30
/// Offset to the "public tagnames" table
public int Tags; // 0x34
/// Offset to the name table
public int NameTable; // 0x38
/// Offset to the overlay table
public int Overlays; // 0x3C
public int CellSize
{
get
{
switch (Magic)
{
case MAGIC_16: return 16;
case MAGIC_32: return 32;
case MAGIC_64: return 64;
default:
throw new ArgumentException("Invalid Magic identifier.");
}
}
}
}
/* File format version
* 0 original version
* 1 opcodes JUMP.pri, SWITCH and CASETBL
* 2 compressed files
* 3 public variables
* 4 opcodes SWAP.pri/alt and PUSHADDR
* 5 tagnames table
* 6 reformatted header
* 7 name table, opcodes SYMTAG & SYSREQ.D
* 8 opcode BREAK, renewed debug interface
* 9 macro opcodes
* 10 position-independent code, overlays, packed instructions
* 11 relocating instructions for the native interface, reorganized instruction set
*/
}