/*
 * SPDX-FileCopyrightText: 2024-2026 Zayn Otley
 * SPDX-License-Identifier: MIT
 * See LICENSES/MIT.txt.
 */

#ifndef INTUITIONENGINE_H
#define INTUITIONENGINE_H

/*
 * Intuition Engine's freestanding hardware interface.  Include the selected
 * compiler's <stdint.h> before this file. The bundled IE64 toolchain ships
 * its freestanding standard headers; external toolchains provide their own.
 */
#include <stdint.h>

#if (defined(IE_TARGET_IE64) + defined(IE_TARGET_M68K) + defined(IE_TARGET_Z80) + defined(IE_TARGET_6502) + defined(IE_TARGET_X86) + defined(IE_TARGET_PPC)) != 1
#error "define exactly one IE_TARGET_IE64, IE_TARGET_M68K, IE_TARGET_Z80, IE_TARGET_6502, IE_TARGET_X86 or IE_TARGET_PPC"
#endif

#if defined(IE_TARGET_IE64)
# if !defined(__ie64__)
#  error "IE_TARGET_IE64 requires ie64-cproc"
# endif
# define IE_HAS_BANK_WINDOWS 0
# define IE_HAS_X86_PORT_IO 0
# define IE_HAS_IE64_CONTROL_REGISTERS 1
# define IE_HAS_IE64_ATOMICS 1
# define IE_HAS_IE64_FPU 1
# define IE_HAS_TRAP_WINDOWS 0
# define IE_ADDRESS_BITS 64
# define IE_BIG_ENDIAN 0
#elif defined(IE_TARGET_M68K)
# if !defined(__GNUC__) && !defined(__VBCC__)
#  error "IE_TARGET_M68K requires GCC or VBCC"
# endif
# define IE_HAS_BANK_WINDOWS 0
# define IE_HAS_X86_PORT_IO 0
# define IE_HAS_IE64_CONTROL_REGISTERS 0
# define IE_HAS_IE64_ATOMICS 0
# define IE_HAS_IE64_FPU 0
# define IE_HAS_TRAP_WINDOWS 1
# define IE_ADDRESS_BITS 32
# define IE_BIG_ENDIAN 1
#elif defined(IE_TARGET_PPC)
# if !defined(__GNUC__) && !defined(__VBCC__)
#  error "IE_TARGET_PPC requires GCC or VBCC"
# endif
# define IE_HAS_BANK_WINDOWS 0
# define IE_HAS_X86_PORT_IO 0
# define IE_HAS_IE64_CONTROL_REGISTERS 0
# define IE_HAS_IE64_ATOMICS 0
# define IE_HAS_IE64_FPU 0
# define IE_HAS_TRAP_WINDOWS 0
# define IE_ADDRESS_BITS 32
# define IE_BIG_ENDIAN 1
#elif defined(IE_TARGET_Z80)
# if !defined(__VBCC__)
#  error "IE_TARGET_Z80 requires VBCC"
# endif
# define IE_HAS_BANK_WINDOWS 1
# define IE_HAS_X86_PORT_IO 0
# define IE_HAS_IE64_CONTROL_REGISTERS 0
# define IE_HAS_IE64_ATOMICS 0
# define IE_HAS_IE64_FPU 0
# define IE_HAS_TRAP_WINDOWS 0
# define IE_ADDRESS_BITS 16
# define IE_BIG_ENDIAN 0
#elif defined(IE_TARGET_6502)
# if !defined(__VBCC__) && !defined(__SDCC)
#  error "IE_TARGET_6502 requires VBCC or SDCC"
# endif
# define IE_HAS_BANK_WINDOWS 1
# define IE_HAS_X86_PORT_IO 0
# define IE_HAS_IE64_CONTROL_REGISTERS 0
# define IE_HAS_IE64_ATOMICS 0
# define IE_HAS_IE64_FPU 0
# define IE_HAS_TRAP_WINDOWS 0
# define IE_ADDRESS_BITS 16
# define IE_BIG_ENDIAN 0
#elif defined(IE_TARGET_X86)
# if !defined(__GNUC__)
#  error "IE_TARGET_X86 requires GCC"
# endif
# define IE_HAS_BANK_WINDOWS 0
# define IE_HAS_X86_PORT_IO 1
# define IE_HAS_IE64_CONTROL_REGISTERS 0
# define IE_HAS_IE64_ATOMICS 0
# define IE_HAS_IE64_FPU 0
# define IE_HAS_TRAP_WINDOWS 0
# define IE_ADDRESS_BITS 32
# define IE_BIG_ENDIAN 0
#endif

#if !defined(UINT8_MAX) || !defined(UINT16_MAX) || !defined(UINT32_MAX)
#error "the selected compiler must provide uint8_t, uint16_t and uint32_t"
#endif
#if IE_HAS_IE64_CONTROL_REGISTERS && !defined(UINT64_MAX)
#error "ie64-cproc must provide uint64_t"
#endif

#define IE_REG8(address)  (*(volatile uint8_t *)(uintptr_t)(address))
#define IE_REG16(address) (*(volatile uint16_t *)(uintptr_t)(address))
#define IE_REG32(address) (*(volatile uint32_t *)(uintptr_t)(address))

/* Where this processor reaches a register named below by its bus address.
 * The names are bus addresses, which a 6502 or Z80 cannot use as they are:
 * both reach bus $F0000-$F0FFF as $F000-$FFFF, except the $F700 page, which
 * holds their bank registers, and everything else through bank 1 ($2000)
 * with IE_TARGET_BANK(address) selected (IE_BANK1_REG_LO/HI). Where a block
 * has a faster route of its own (ports, the Voodoo window, the TED alias
 * page), its *_TARGET_* names give it. Elsewhere these are the address.
 * IE_TARGET_DIRECT says whether a bank has to be selected first. */
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_TARGET_DIRECT(address) \
	((address) >= 0x0f0000u && (address) <= 0x0f0fffu && ((address) & 0xff00u) != 0x0700u)
# define IE_TARGET_BANK(address) ((uint16_t)((address) >> 13))
# define IE_TARGET_ADDR(address) \
	(IE_TARGET_DIRECT(address) ? (uint16_t)(0xf000u + ((address) & 0x0fffu)) \
	                           : (uint16_t)(0x2000u + ((address) & 0x1fffu)))
#else
# define IE_TARGET_DIRECT(address) 1
# define IE_TARGET_BANK(address) 0u
# define IE_TARGET_ADDR(address) (address)
#endif

/* Common, target-normalised hardware map.  See architecture.md for access semantics. */
#if defined(IE_TARGET_PPC)
#define IE_PROGRAM_START 0x004000u
#else
#define IE_PROGRAM_START 0x001000u
#endif
/* The engine's peripheral aperture: the byte range every register below sits
 * in, and the size of the window a profile's mirror republishes. */
#define IE_IO_APERTURE_BASE 0x0f0000u
#define IE_IO_APERTURE_SIZE 0x010000u
#define IE_VIDEO_CTRL 0x0f0000u
/* VIDEO_CTRL bits. Bit 1 retains the completed framebuffer until it is cleared. */
#define IE_VIDEO_CTRL_ENABLE 0x01u
#define IE_VIDEO_CTRL_PRESENT_HOLD 0x02u
#define IE_VIDEO_MODE 0x0f0004u

/* What to write into IE_VIDEO_MODE. The mode carries the geometry; the
 * pixel size is IE_VIDEO_COLOR_MODE and the pixels themselves are
 * wherever IE_VIDEO_FB_BASE points. */
#define IE_MODE_640x480 0x00u
#define IE_MODE_800x600 0x01u
#define IE_MODE_1024x768 0x02u
#define IE_MODE_1280x960 0x03u
#define IE_MODE_320x200 0x04u
#define IE_MODE_320x240 0x05u
#define IE_MODE_1920x1080 0x06u
#define IE_MODE_960x540 0x07u
#define IE_VIDEO_STATUS 0x0f0008u
#define IE_VIDEO_STATUS_VBLANK 0x02u
#define IE_VIDEO_STATUS_FB_ERROR 0x04u
#define IE_VIDEO_COPPER_CTRL 0x0f000cu
#define IE_VIDEO_COPPER_PTR 0x0f0010u
#define IE_VIDEO_COPPER_PC 0x0f0014u
#define IE_VIDEO_COPPER_STATUS 0x0f0018u
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_VIDEO_COPPER_CTRL_TARGET 0xf00cu
# define IE_VIDEO_COPPER_PTR0_TARGET 0xf010u
# define IE_VIDEO_COPPER_PTR1_TARGET 0xf011u
# define IE_VIDEO_COPPER_PTR2_TARGET 0xf012u
# define IE_VIDEO_COPPER_PTR3_TARGET 0xf013u
#else
# define IE_VIDEO_COPPER_CTRL_TARGET IE_VIDEO_COPPER_CTRL
# define IE_VIDEO_COPPER_PTR_TARGET IE_VIDEO_COPPER_PTR
#endif
#define IE_VIDEO_BLITTER_CTRL 0x0f001cu
#define IE_VIDEO_BLITTER_OP 0x0f0020u
#define IE_VIDEO_BLITTER_SRC 0x0f0024u
#define IE_VIDEO_BLITTER_DST 0x0f0028u
#define IE_VIDEO_BLITTER_WIDTH 0x0f002cu
#define IE_VIDEO_BLITTER_HEIGHT 0x0f0030u
#define IE_VIDEO_BLITTER_SOURCE_STRIDE 0x0f0034u
#define IE_VIDEO_BLITTER_DESTINATION_STRIDE 0x0f0038u
#define IE_VIDEO_BLITTER_COLOUR 0x0f003cu
#define IE_VIDEO_BLITTER_MASK 0x0f0040u
#define IE_VIDEO_BLITTER_STATUS 0x0f0044u
#define IE_VIDEO_RASTER_Y 0x0f0048u
#define IE_VIDEO_RASTER_HEIGHT 0x0f004cu
#define IE_VIDEO_RASTER_COLOUR 0x0f0050u
#define IE_VIDEO_RASTER_CONTROL 0x0f0054u
#define IE_VIDEO_MODE7_U0 0x0f0058u
#define IE_VIDEO_MODE7_V0 0x0f005cu
#define IE_VIDEO_MODE7_DU_COLUMN 0x0f0060u
#define IE_VIDEO_MODE7_DV_COLUMN 0x0f0064u
#define IE_VIDEO_MODE7_DU_ROW 0x0f0068u
#define IE_VIDEO_MODE7_DV_ROW 0x0f006cu
#define IE_VIDEO_MODE7_TEXTURE_WIDTH 0x0f0070u
#define IE_VIDEO_MODE7_TEXTURE_HEIGHT 0x0f0074u
#define IE_VIDEO_BLITTER_OP_COPY 0x00u
#define IE_VIDEO_BLITTER_OP_FILL 0x01u
#define IE_VIDEO_BLITTER_OP_LINE 0x02u
#define IE_VIDEO_BLITTER_OP_MASKED 0x03u
#define IE_VIDEO_BLITTER_OP_ALPHA 0x04u
#define IE_VIDEO_BLITTER_OP_MODE7 0x05u
#define IE_VIDEO_BLITTER_OP_COLOUR_EXPAND 0x06u
#define IE_VIDEO_BLITTER_CTRL_START 0x01u
#define IE_VIDEO_BLITTER_CTRL_BUSY 0x02u
#define IE_VIDEO_BLITTER_CTRL_IRQ 0x04u
#define IE_BLT_CTRL IE_VIDEO_BLITTER_CTRL
#define IE_BLT_OP IE_VIDEO_BLITTER_OP
#define IE_BLT_SRC IE_VIDEO_BLITTER_SRC
#define IE_BLT_DST IE_VIDEO_BLITTER_DST
#define IE_BLT_WIDTH IE_VIDEO_BLITTER_WIDTH
#define IE_BLT_HEIGHT IE_VIDEO_BLITTER_HEIGHT
#define IE_BLT_SRC_STRIDE IE_VIDEO_BLITTER_SOURCE_STRIDE
#define IE_BLT_DST_STRIDE IE_VIDEO_BLITTER_DESTINATION_STRIDE
#define IE_BLT_COLOR IE_VIDEO_BLITTER_COLOUR
#define IE_BLT_MASK IE_VIDEO_BLITTER_MASK
#define IE_BLT_STATUS IE_VIDEO_BLITTER_STATUS
#define IE_BLT_MODE7_U0 IE_VIDEO_MODE7_U0
#define IE_BLT_MODE7_V0 IE_VIDEO_MODE7_V0
#define IE_BLT_MODE7_DU_COL IE_VIDEO_MODE7_DU_COLUMN
#define IE_BLT_MODE7_DV_COL IE_VIDEO_MODE7_DV_COLUMN
#define IE_BLT_MODE7_DU_ROW IE_VIDEO_MODE7_DU_ROW
#define IE_BLT_MODE7_DV_ROW IE_VIDEO_MODE7_DV_ROW
#define IE_BLT_MODE7_TEX_W IE_VIDEO_MODE7_TEXTURE_WIDTH
#define IE_BLT_MODE7_TEX_H IE_VIDEO_MODE7_TEXTURE_HEIGHT
#define IE_BLT_OP_COPY IE_VIDEO_BLITTER_OP_COPY
#define IE_BLT_OP_FILL IE_VIDEO_BLITTER_OP_FILL
#define IE_BLT_OP_LINE IE_VIDEO_BLITTER_OP_LINE
#define IE_BLT_OP_MODE7 IE_VIDEO_BLITTER_OP_MODE7
#define IE_BLT_CTRL_START IE_VIDEO_BLITTER_CTRL_START
#define IE_BLT_CTRL_BUSY IE_VIDEO_BLITTER_CTRL_BUSY
#define IE_BLT_OP_MASKED IE_VIDEO_BLITTER_OP_MASKED
#define IE_BLT_OP_ALPHA IE_VIDEO_BLITTER_OP_ALPHA
#define IE_BLT_OP_COLOUR_EXPAND IE_VIDEO_BLITTER_OP_COLOUR_EXPAND

/* Nearest-neighbour scale blit. BLT_COLOR carries the destination rectangle
 * rather than a colour under this op: the low half is the destination width
 * and the high half its height. The register is consumed as a plain numeric
 * value at every bpp, so the byte reversal an RGBA32 fill colour needs must
 * not be applied to it. */
#define IE_BLT_OP_SCALE 0x07u

/* Linear byte copy. BLT_WIDTH carries a byte length under this op rather than
 * a rectangle width, and BLT_HEIGHT is unused. A driver that reads the
 * register as a width sends a copy the wrong size. */
#define IE_BLT_OP_MEMCOPY 0x08u

/* The extended blitter registers. */
#define IE_VIDEO_BLITTER_FLAGS 0x0f0488u
#define IE_VIDEO_BLITTER_FG 0x0f048cu
#define IE_VIDEO_BLITTER_BG 0x0f0490u
#define IE_VIDEO_BLITTER_MASK_MODULO 0x0f0494u
#define IE_VIDEO_BLITTER_MASK_SOURCE_X 0x0f0498u
#define IE_BLT_FLAGS IE_VIDEO_BLITTER_FLAGS
#define IE_BLT_FG IE_VIDEO_BLITTER_FG
#define IE_BLT_BG IE_VIDEO_BLITTER_BG
#define IE_BLT_MASK_MOD IE_VIDEO_BLITTER_MASK_MODULO
#define IE_BLT_MASK_SRCX IE_VIDEO_BLITTER_MASK_SOURCE_X

/* BLT_FLAGS. Bits 0 and 1 select the pixel size, bits 4 to 7 the raster draw
 * mode, and the rest are the template and mask conventions the Amiga uses:
 * JAM1 skips background pixels, MASK_MSB samples a mask MSB first the way a
 * PLANEPTR is laid out, and ALPHA_TMPL turns an alpha copy into a blend of
 * BLT_FG over the destination. */
#define IE_BLT_FLAGS_BPP_MASK 0x03u
#define IE_BLT_FLAGS_BPP_RGBA32 0x00u
#define IE_BLT_FLAGS_BPP_CLUT8 0x01u
#define IE_BLT_FLAGS_DRAWMODE_MASK 0xf0u
#define IE_BLT_FLAGS_DRAWMODE_SHIFT 4u
/*
 * The draw mode is a raster operation, and 0 in those bits is Clear
 * rather than Copy: a flags word that sets only the pixel size asks
 * for a rectangle of zeroes and gets one. A flags word of zero
 * altogether is read as the legacy default and means Copy.
 */
#define IE_BLT_FLAGS_JAM1 0x0100u
#define IE_BLT_FLAGS_INVERT_TMPL 0x0200u
#define IE_BLT_FLAGS_INVERT_MODE 0x0400u
#define IE_BLT_FLAGS_MASK_MSB 0x0800u
#define IE_BLT_FLAGS_ALPHA_TMPL 0x1000u
#define IE_VIDEO_PALETTE_INDEX 0x0f0078u
#define IE_VIDEO_PALETTE_DATA 0x0f007cu

/* The 256-entry palette aperture. Entry n is the longword at
 * IE_VIDEO_PAL_TABLE + n * 4, carrying 0x00RRGGBB as a plain numeric value:
 * the register aperture is decoded natively, so nothing here is pre-swapped.
 * The index and data port pair above reaches the same table one entry at a
 * time. */
#define IE_VIDEO_PAL_TABLE 0x0f0088u
#define IE_VIDEO_PAL_END 0x0f0487u
#define IE_VIDEO_REG_END 0x0f049bu
#define IE_VIDEO_COLOR_MODE 0x0f0080u
/* What to write into IE_VIDEO_COLOR_MODE: what one framebuffer pixel is.
 * The sixteen-bit layouts are little-endian, the low byte of a pixel
 * first in memory, as a PCI card's are. */
#define IE_VIDEO_COLOR_MODE_RGBA32 0x00u /* four bytes, red first */
#define IE_VIDEO_COLOR_MODE_CLUT8 0x01u  /* one byte, a palette index */
#define IE_VIDEO_COLOR_MODE_R5G6B5 0x02u /* red 15-11, green 10-5, blue 4-0 */
#define IE_VIDEO_COLOR_MODE_R5G5B5 0x03u /* red 14-10, green 9-5, blue 4-0 */
#define IE_VIDEO_FB_BASE 0x0f0084u
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_VIDEO_CTRL_TARGET 0xf000u
# define IE_VIDEO_MODE_TARGET 0xf004u
# define IE_VIDEO_STATUS_TARGET 0xf008u
# define IE_VIDEO_PALETTE_INDEX_TARGET 0xf078u
# define IE_VIDEO_PALETTE_DATA_TARGET 0xf07cu
# define IE_VIDEO_FB_BASE_TARGET 0xf084u
#else
# define IE_VIDEO_CTRL_TARGET IE_VIDEO_CTRL
# define IE_VIDEO_MODE_TARGET IE_VIDEO_MODE
# define IE_VIDEO_STATUS_TARGET IE_VIDEO_STATUS
# define IE_VIDEO_PALETTE_INDEX_TARGET IE_VIDEO_PALETTE_INDEX
# define IE_VIDEO_PALETTE_DATA_TARGET IE_VIDEO_PALETTE_DATA
# define IE_VIDEO_FB_BASE_TARGET IE_VIDEO_FB_BASE
#endif

/* ZX Spectrum ULA. The paged data register transfers one byte at a time. */
#define IE_ULA_MMIO_BASE 0x0f2000u
#define IE_ULA_MMIO_END 0x0f2017u
#define IE_ULA_CTRL_ENABLE 0x01u
#define IE_ULA_CTRL_VBLANK_IRQ_ENABLE 0x02u
#define IE_ULA_CTRL_AUTO_INCREMENT 0x04u
#define IE_ULA_STATUS_VBLANK 0x01u
#define IE_ULA_BITMAP_SIZE 0x1800u
#define IE_ULA_ATTRIBUTE_OFFSET 0x1800u
#define IE_ULA_ATTRIBUTE_SIZE 0x0300u
#define IE_ULA_VRAM_SIZE 0x1b00u
#define IE_ULA_DISPLAY_WIDTH 0x0100u
#define IE_ULA_DISPLAY_HEIGHT 0x00c0u
#define IE_ULA_BORDER_SIZE 0x0020u
#define IE_ULA_FRAME_WIDTH 0x0140u
#define IE_ULA_FRAME_HEIGHT 0x0100u
#define IE_ULA_CELLS_X 0x0020u
#define IE_ULA_CELLS_Y 0x0018u
#define IE_ULA_VRAM_APERTURE 0x0fa000u
#define IE_ULA_VRAM_APERTURE_END 0x0fbaffu
#define IE_6502_ULA_BASE 0x00d800u
#define IE_6502_ULA_DATA 0x00d814u
#define IE_Z80_ULA_PORT_BORDER 0x00feu
#define IE_Z80_ULA_PORT_CONTROL 0x00fdu
#define IE_Z80_ULA_PORT_STATUS 0x00beu
#define IE_Z80_ULA_PORT_ADDRESS_LOW 0x00fau
#define IE_Z80_ULA_PORT_ADDRESS_HIGH 0x00fbu
#define IE_Z80_ULA_PORT_DATA 0x00fcu

#if defined(IE_TARGET_6502)
# define IE_ULA_BASE 0xd800u
# define IE_ULA_BORDER 0xd800u
# define IE_ULA_CONTROL 0xd804u
# define IE_ULA_STATUS 0xd808u
# define IE_ULA_ADDRESS_LOW 0xd80cu
# define IE_ULA_ADDRESS_HIGH 0xd810u
# define IE_ULA_DATA 0xd814u
#elif defined(IE_TARGET_Z80)
# define IE_ULA_PORT_BORDER IE_Z80_ULA_PORT_BORDER
# define IE_ULA_PORT_CONTROL IE_Z80_ULA_PORT_CONTROL
# define IE_ULA_PORT_STATUS IE_Z80_ULA_PORT_STATUS
# define IE_ULA_PORT_ADDRESS_LOW IE_Z80_ULA_PORT_ADDRESS_LOW
# define IE_ULA_PORT_ADDRESS_HIGH IE_Z80_ULA_PORT_ADDRESS_HIGH
# define IE_ULA_PORT_DATA IE_Z80_ULA_PORT_DATA
# define IE_ULA_PORT IE_ULA_PORT_BORDER
#else
# define IE_ULA_BASE IE_ULA_MMIO_BASE
# define IE_ULA_BORDER 0x0f2000u
# define IE_ULA_CONTROL 0x0f2004u
# define IE_ULA_STATUS 0x0f2008u
# define IE_ULA_ADDRESS_LOW 0x0f200cu
# define IE_ULA_ADDRESS_HIGH 0x0f2010u
# define IE_ULA_DATA 0x0f2014u
#endif

#if !defined(IE_TARGET_Z80)
# define IE_ULA_CTRL IE_ULA_CONTROL
# define IE_ULA_ADDR_LO IE_ULA_ADDRESS_LOW
# define IE_ULA_ADDR_HI IE_ULA_ADDRESS_HIGH
#endif
#define IE_ULA_CTRL_VBLANK_IRQ_EN IE_ULA_CTRL_VBLANK_IRQ_ENABLE
#define IE_ULA_CTRL_AUTO_INC IE_ULA_CTRL_AUTO_INCREMENT
#define IE_ULA_VRAM_AP IE_ULA_VRAM_APERTURE
#define IE_ULA_VRAM_AP_END IE_ULA_VRAM_APERTURE_END
#define IE_ULA_VRAM IE_ULA_VRAM_APERTURE
#define IE_ULA_ATTR_OFFSET IE_ULA_ATTRIBUTE_OFFSET
#define IE_ULA_ATTR_SIZE IE_ULA_ATTRIBUTE_SIZE
#define IE_ULA_DISPLAY_W IE_ULA_DISPLAY_WIDTH
#define IE_ULA_DISPLAY_H IE_ULA_DISPLAY_HEIGHT
#define IE_ULA_FRAME_W IE_ULA_FRAME_WIDTH
#define IE_ULA_FRAME_H IE_ULA_FRAME_HEIGHT

/* Atari ANTIC and GTIA video register maps. */
#define IE_ANTIC_BASE_DIRECT 0x0f2100u
#define IE_ANTIC_END_DIRECT 0x0f213fu
#define IE_ANTIC_DMA_CONTROL 0x0f2100u
#define IE_ANTIC_CHARACTER_CONTROL 0x0f2104u
#define IE_ANTIC_DISPLAY_LIST_LOW 0x0f2108u
#define IE_ANTIC_DISPLAY_LIST_HIGH 0x0f210cu
#define IE_ANTIC_HORIZONTAL_SCROLL 0x0f2110u
#define IE_ANTIC_VERTICAL_SCROLL 0x0f2114u
#define IE_ANTIC_PLAYER_MISSILE_BASE 0x0f2118u
#define IE_ANTIC_CHARACTER_BASE 0x0f211cu
#define IE_ANTIC_WAIT_SYNC 0x0f2120u
#define IE_ANTIC_VERTICAL_COUNT 0x0f2124u
#define IE_ANTIC_LIGHT_PEN_H 0x0f2128u
#define IE_ANTIC_LIGHT_PEN_V 0x0f212cu
#define IE_ANTIC_NMI_ENABLE 0x0f2130u
#define IE_ANTIC_NMI_STATUS 0x0f2134u
#define IE_ANTIC_ENABLE 0x0f2138u
#define IE_ANTIC_STATUS 0x0f213cu
#define IE_ANTIC_DMA_NARROW 0x01u
#define IE_ANTIC_DMA_NORMAL 0x02u
#define IE_ANTIC_DMA_WIDE 0x03u
#define IE_ANTIC_DMA_MISSILE 0x04u
#define IE_ANTIC_DMA_PLAYER 0x08u
#define IE_ANTIC_DMA_PLAYER_MISSILE_RESOLUTION 0x10u
#define IE_ANTIC_DMA_DISPLAY_LIST 0x20u
#define IE_ANTIC_NMI_DISPLAY_LIST 0x80u
#define IE_ANTIC_NMI_VERTICAL_BLANK 0x40u
#define IE_ANTIC_STATUS_VBLANK 0x01u
#define IE_GTIA_BASE_DIRECT 0x0f2140u
#define IE_GTIA_END_DIRECT 0x0f21fbu
#define IE_GTIA_PLAYFIELD_COLOUR0 0x0f2140u
#define IE_GTIA_PLAYFIELD_COLOUR1 0x0f2144u
#define IE_GTIA_PLAYFIELD_COLOUR2 0x0f2148u
#define IE_GTIA_PLAYFIELD_COLOUR3 0x0f214cu
#define IE_GTIA_BACKGROUND_COLOUR 0x0f2150u
#define IE_GTIA_PLAYER_COLOUR0 0x0f2154u
#define IE_GTIA_PLAYER_COLOUR1 0x0f2158u
#define IE_GTIA_PLAYER_COLOUR2 0x0f215cu
#define IE_GTIA_PLAYER_COLOUR3 0x0f2160u
#define IE_GTIA_PRIORITY 0x0f2164u
#define IE_GTIA_GRAPHICS_CONTROL 0x0f2168u
#define IE_GTIA_CONSOLE 0x0f216cu
#define IE_GTIA_HPOS_PLAYER0 0x0f2170u
#define IE_GTIA_HPOS_PLAYER1 0x0f2174u
#define IE_GTIA_HPOS_PLAYER2 0x0f2178u
#define IE_GTIA_HPOS_PLAYER3 0x0f217cu
#define IE_GTIA_HPOS_MISSILE0 0x0f2180u
#define IE_GTIA_HPOS_MISSILE1 0x0f2184u
#define IE_GTIA_HPOS_MISSILE2 0x0f2188u
#define IE_GTIA_HPOS_MISSILE3 0x0f218cu
#define IE_GTIA_SIZE_PLAYER0 0x0f2190u
#define IE_GTIA_SIZE_PLAYER1 0x0f2194u
#define IE_GTIA_SIZE_PLAYER2 0x0f2198u
#define IE_GTIA_SIZE_PLAYER3 0x0f219cu
#define IE_GTIA_SIZE_MISSILES 0x0f21a0u
#define IE_GTIA_GRAPHICS_PLAYER0 0x0f21a4u
#define IE_GTIA_GRAPHICS_PLAYER1 0x0f21a8u
#define IE_GTIA_GRAPHICS_PLAYER2 0x0f21acu
#define IE_GTIA_GRAPHICS_PLAYER3 0x0f21b0u
#define IE_GTIA_GRAPHICS_MISSILES 0x0f21b4u
#define IE_GTIA_COLLISION_CLEAR 0x0f21f8u
#define IE_Z80_ANTIC_PORT_SELECT 0xd4u
#define IE_Z80_ANTIC_PORT_DATA 0xd5u
#define IE_Z80_GTIA_PORT_SELECT 0xd6u
#define IE_Z80_GTIA_PORT_DATA 0xd7u

/* Assembly-compatible short spellings for the direct ANTIC/GTIA map. */
#define IE_ANTIC_BASE IE_ANTIC_BASE_DIRECT
#define IE_ANTIC_DMACTL IE_ANTIC_DMA_CONTROL
#define IE_ANTIC_CHACTL IE_ANTIC_CHARACTER_CONTROL
#define IE_ANTIC_DLISTL IE_ANTIC_DISPLAY_LIST_LOW
#define IE_ANTIC_DLISTH IE_ANTIC_DISPLAY_LIST_HIGH
#define IE_ANTIC_HSCROL IE_ANTIC_HORIZONTAL_SCROLL
#define IE_ANTIC_VSCROL IE_ANTIC_VERTICAL_SCROLL
#define IE_ANTIC_PMBASE IE_ANTIC_PLAYER_MISSILE_BASE
#define IE_ANTIC_CHBASE IE_ANTIC_CHARACTER_BASE
#define IE_ANTIC_WSYNC IE_ANTIC_WAIT_SYNC
#define IE_ANTIC_VCOUNT IE_ANTIC_VERTICAL_COUNT
#define IE_ANTIC_PENH IE_ANTIC_LIGHT_PEN_H
#define IE_ANTIC_PENV IE_ANTIC_LIGHT_PEN_V
#define IE_ANTIC_NMIEN IE_ANTIC_NMI_ENABLE
#define IE_ANTIC_NMIST IE_ANTIC_NMI_STATUS
#define IE_ANTIC_ENABLE_VIDEO IE_ANTIC_ENABLE
#define IE_ANTIC_FRAME_W 384u
#define IE_ANTIC_FRAME_H 240u
#define IE_ANTIC_DISPLAY_W 320u
#define IE_ANTIC_DISPLAY_H 192u
#define IE_ANTIC_CHACTL_BLANK 0x01u
#define IE_ANTIC_CHACTL_INVERT 0x02u
#define IE_ANTIC_CHACTL_REFLECT 0x04u
#define IE_ANTIC_DMA_PMRES IE_ANTIC_DMA_PLAYER_MISSILE_RESOLUTION
#define IE_ANTIC_DMA_DL IE_ANTIC_DMA_DISPLAY_LIST
#define IE_ANTIC_NMIEN_DLI IE_ANTIC_NMI_DISPLAY_LIST
#define IE_ANTIC_NMIEN_VBI IE_ANTIC_NMI_VERTICAL_BLANK
#define IE_GTIA_BASE IE_GTIA_BASE_DIRECT
#define IE_GTIA_END IE_GTIA_END_DIRECT
#define IE_GTIA_COLPF0 IE_GTIA_PLAYFIELD_COLOUR0
#define IE_GTIA_COLPF1 IE_GTIA_PLAYFIELD_COLOUR1
#define IE_GTIA_COLPF2 IE_GTIA_PLAYFIELD_COLOUR2
#define IE_GTIA_COLPF3 IE_GTIA_PLAYFIELD_COLOUR3
#define IE_GTIA_COLBK IE_GTIA_BACKGROUND_COLOUR
#define IE_GTIA_COLPM0 IE_GTIA_PLAYER_COLOUR0
#define IE_GTIA_COLPM1 IE_GTIA_PLAYER_COLOUR1
#define IE_GTIA_COLPM2 IE_GTIA_PLAYER_COLOUR2
#define IE_GTIA_COLPM3 IE_GTIA_PLAYER_COLOUR3
#define IE_GTIA_PRIOR IE_GTIA_PRIORITY
#define IE_GTIA_GRACTL IE_GTIA_GRAPHICS_CONTROL
#define IE_GTIA_CONSOL IE_GTIA_CONSOLE
#define IE_GTIA_HPOSP0 IE_GTIA_HPOS_PLAYER0
#define IE_GTIA_HPOSP1 IE_GTIA_HPOS_PLAYER1
#define IE_GTIA_HPOSP2 IE_GTIA_HPOS_PLAYER2
#define IE_GTIA_HPOSP3 IE_GTIA_HPOS_PLAYER3
#define IE_GTIA_HPOSM0 IE_GTIA_HPOS_MISSILE0
#define IE_GTIA_HPOSM1 IE_GTIA_HPOS_MISSILE1
#define IE_GTIA_HPOSM2 IE_GTIA_HPOS_MISSILE2
#define IE_GTIA_HPOSM3 IE_GTIA_HPOS_MISSILE3
#define IE_GTIA_SIZEP0 IE_GTIA_SIZE_PLAYER0
#define IE_GTIA_SIZEP1 IE_GTIA_SIZE_PLAYER1
#define IE_GTIA_SIZEP2 IE_GTIA_SIZE_PLAYER2
#define IE_GTIA_SIZEP3 IE_GTIA_SIZE_PLAYER3
#define IE_GTIA_SIZEM IE_GTIA_SIZE_MISSILES
#define IE_GTIA_GRAFP0 IE_GTIA_GRAPHICS_PLAYER0
#define IE_GTIA_GRAFP1 IE_GTIA_GRAPHICS_PLAYER1
#define IE_GTIA_GRAFP2 IE_GTIA_GRAPHICS_PLAYER2
#define IE_GTIA_GRAFP3 IE_GTIA_GRAPHICS_PLAYER3
#define IE_GTIA_GRAFM IE_GTIA_GRAPHICS_MISSILES
#define IE_GTIA_HITCLR IE_GTIA_COLLISION_CLEAR
#define IE_GTIA_M0PF 0x0f21b8u
#define IE_GTIA_M1PF 0x0f21bcu
#define IE_GTIA_M2PF 0x0f21c0u
#define IE_GTIA_M3PF 0x0f21c4u
#define IE_GTIA_P0PF 0x0f21c8u
#define IE_GTIA_P1PF 0x0f21ccu
#define IE_GTIA_P2PF 0x0f21d0u
#define IE_GTIA_P3PF 0x0f21d4u
#define IE_GTIA_M0PL 0x0f21d8u
#define IE_GTIA_M1PL 0x0f21dcu
#define IE_GTIA_M2PL 0x0f21e0u
#define IE_GTIA_M3PL 0x0f21e4u
#define IE_GTIA_P0PL 0x0f21e8u
#define IE_GTIA_P1PL 0x0f21ecu
#define IE_GTIA_P2PL 0x0f21f0u
#define IE_GTIA_P3PL 0x0f21f4u
#define IE_GTIA_PRIOR_P03 0x01u
#define IE_GTIA_PRIOR_P01 0x02u
#define IE_GTIA_PRIOR_P23 0x04u
#define IE_GTIA_PRIOR_MULTI 0x10u
#define IE_GTIA_PRIOR_FIFTH 0x20u
#define IE_GTIA_PRIOR_GTIA1 0x40u
#define IE_GTIA_PRIOR_GTIA2 0x80u
#define IE_GTIA_GRACTL_MISSLE 0x01u
#define IE_GTIA_GRACTL_PLAYER 0x02u
#define IE_GTIA_GRACTL_LATCH 0x04u

/* IBM VGA memory registers and target access routes. */
#define IE_VGA_BASE_DIRECT 0x0f1000u
#define IE_VGA_END_DIRECT 0x0f13ffu
#define IE_VGA_MODE 0x0f1000u
#define IE_VGA_STATUS 0x0f1004u
#define IE_VGA_CONTROL 0x0f1008u
#define IE_VGA_SEQUENCER_INDEX 0x0f1010u
#define IE_VGA_SEQUENCER_DATA 0x0f1014u
#define IE_VGA_SEQUENCER_MAP_MASK 0x0f1018u
#define IE_VGA_CRTC_INDEX 0x0f1020u
#define IE_VGA_CRTC_DATA 0x0f1024u
#define IE_VGA_CRTC_START_HIGH 0x0f1028u
#define IE_VGA_CRTC_START_LOW 0x0f102cu
#define IE_VGA_GRAPHICS_INDEX 0x0f1030u
#define IE_VGA_GRAPHICS_DATA 0x0f1034u
#define IE_VGA_GRAPHICS_READ_MAP 0x0f1038u
#define IE_VGA_GRAPHICS_BIT_MASK 0x0f103cu
#define IE_VGA_ATTRIBUTE_INDEX 0x0f1040u
#define IE_VGA_ATTRIBUTE_DATA 0x0f1044u
#define IE_VGA_DAC_MASK 0x0f1050u
#define IE_VGA_DAC_READ_INDEX 0x0f1054u
#define IE_VGA_DAC_WRITE_INDEX 0x0f1058u
#define IE_VGA_DAC_DATA 0x0f105cu
#define IE_VGA_PALETTE 0x0f1100u
#define IE_VGA_PALETTE_END 0x0f13ffu
#define IE_VGA_VRAM_WINDOW 0x0a0000u
#define IE_VGA_VRAM_SIZE 0x10000u
#define IE_VGA_TEXT_WINDOW 0x0b8000u
#define IE_VGA_TEXT_SIZE 0x8000u
#define IE_VGA_MODE_TEXT 0x03u
#define IE_VGA_MODE_12H 0x12u
#define IE_VGA_MODE_13H 0x13u
#define IE_VGA_MODE_X 0x14u
#define IE_VGA_STATUS_VSYNC 0x01u
#define IE_VGA_STATUS_RETRACE 0x08u
#define IE_VGA_CONTROL_ENABLE 0x01u
#define IE_Z80_VGA_PORT_MODE 0xa0u
#define IE_Z80_VGA_PORT_STATUS 0xa1u
#define IE_Z80_VGA_PORT_CONTROL 0xa2u
#define IE_Z80_VGA_PORT_SEQUENCER_INDEX 0xa3u
#define IE_Z80_VGA_PORT_SEQUENCER_DATA 0xa4u
#define IE_Z80_VGA_PORT_CRTC_INDEX 0xa5u
#define IE_Z80_VGA_PORT_CRTC_DATA 0xa6u
#define IE_Z80_VGA_PORT_GRAPHICS_INDEX 0xa7u
#define IE_Z80_VGA_PORT_GRAPHICS_DATA 0xa8u
#define IE_Z80_VGA_PORT_DAC_WRITE_INDEX 0xa9u
#define IE_Z80_VGA_PORT_DAC_DATA 0xaau
#define IE_Z80_VGA_PORT_DAC_READ_INDEX 0xabu
#define IE_Z80_VGA_PORT_DAC_MASK 0xacu
#define IE_Z80_VGA_PORT_VRAM_BANK 0xadu
#define IE_6502_VGA_BASE 0xd700u
#define IE_6502_VGA_MODE 0xd700u
#define IE_6502_VGA_STATUS 0xd701u
#define IE_6502_VGA_CONTROL 0xd702u

/* Full direct VGA register block. */
#define IE_VGA_BASE 0x0f1000u
#define IE_VGA_SEQ_INDEX 0x0f1010u
#define IE_VGA_SEQ_DATA 0x0f1014u
#define IE_VGA_SEQ_MAPMASK 0x0f1018u
#define IE_VGA_CRTC_STARTHI 0x0f1028u
#define IE_VGA_CRTC_STARTLO 0x0f102cu
#define IE_VGA_GC_INDEX 0x0f1030u
#define IE_VGA_GC_DATA 0x0f1034u
#define IE_VGA_GC_READMAP 0x0f1038u
#define IE_VGA_GC_BITMASK 0x0f103cu
#define IE_VGA_ATTR_INDEX 0x0f1040u
#define IE_VGA_ATTR_DATA 0x0f1044u
#define IE_VGA_DAC_RINDEX 0x0f1054u
#define IE_VGA_DAC_WINDEX 0x0f1058u
#define IE_VGA_VRAM 0x0a0000u

#if defined(IE_TARGET_6502)
# define IE_VGA_TARGET_MODE IE_6502_VGA_MODE
# define IE_VGA_TARGET_STATUS IE_6502_VGA_STATUS
# define IE_VGA_TARGET_CONTROL IE_6502_VGA_CONTROL
#elif defined(IE_TARGET_Z80)
# define IE_VGA_TARGET_MODE IE_Z80_VGA_PORT_MODE
# define IE_VGA_TARGET_STATUS IE_Z80_VGA_PORT_STATUS
# define IE_VGA_TARGET_CONTROL IE_Z80_VGA_PORT_CONTROL
#else
# define IE_VGA_TARGET_MODE IE_VGA_MODE
# define IE_VGA_TARGET_STATUS IE_VGA_STATUS
# define IE_VGA_TARGET_CONTROL IE_VGA_CONTROL
#endif

/* TED video register block.  6502 uses the documented stride-one aliases. */
#define IE_TED_VIDEO_BASE_DIRECT 0x0f0f20u
#define IE_TED_VIDEO_END_DIRECT 0x0f0f6bu
#define IE_TED_VIDEO_CONTROL1 0x0f0f20u
#define IE_TED_VIDEO_CONTROL2 0x0f0f24u
#define IE_TED_VIDEO_CHARACTER_BASE 0x0f0f28u
#define IE_TED_VIDEO_MATRIX_BASE 0x0f0f2cu
#define IE_TED_VIDEO_BACKGROUND0 0x0f0f30u
#define IE_TED_VIDEO_BACKGROUND1 0x0f0f34u
#define IE_TED_VIDEO_BACKGROUND2 0x0f0f38u
#define IE_TED_VIDEO_BACKGROUND3 0x0f0f3cu
#define IE_TED_VIDEO_BORDER 0x0f0f40u
#define IE_TED_VIDEO_CURSOR_HIGH 0x0f0f44u
#define IE_TED_VIDEO_CURSOR_LOW 0x0f0f48u
#define IE_TED_VIDEO_CURSOR_COLOUR 0x0f0f4cu
#define IE_TED_VIDEO_RASTER_LOW 0x0f0f50u
#define IE_TED_VIDEO_RASTER_HIGH 0x0f0f54u
#define IE_TED_VIDEO_ENABLE 0x0f0f58u
#define IE_TED_VIDEO_STATUS 0x0f0f5cu
#define IE_TED_VIDEO_RASTER_COMPARE_LOW 0x0f0f60u
#define IE_TED_VIDEO_RASTER_COMPARE_HIGH 0x0f0f64u
#define IE_TED_VIDEO_RASTER_STATUS 0x0f0f68u
#define IE_TED_VIDEO_VRAM_BASE 0x0f3000u
#define IE_TED_VIDEO_VRAM_SIZE 0x4000u
#define IE_TED_VIDEO_CONTROL1_ECM 0x40u
#define IE_TED_VIDEO_CONTROL1_BMM 0x20u
#define IE_TED_VIDEO_CONTROL1_ENABLE 0x10u
#define IE_TED_VIDEO_CONTROL1_ROW_SELECT 0x08u
#define IE_TED_VIDEO_CONTROL1_SCROLL_MASK 0x07u
#define IE_TED_VIDEO_CONTROL2_RESET 0x20u
#define IE_TED_VIDEO_CONTROL2_MULTICOLOUR 0x10u
#define IE_TED_VIDEO_CONTROL2_COLUMN_SELECT 0x08u
#define IE_TED_VIDEO_CONTROL2_SCROLL_MASK 0x07u
#define IE_TED_VIDEO_STATUS_VBLANK 0x01u
#define IE_TED_VIDEO_RASTER_PENDING 0x80u
#define IE_6502_TED_VIDEO_BASE 0xd620u
#define IE_Z80_TED_VIDEO_PORT_SELECT 0xf2u
#define IE_Z80_TED_VIDEO_PORT_DATA 0xf3u
#if defined(IE_TARGET_6502)
# define IE_TED_VIDEO_TARGET_CONTROL1 0xd620u
# define IE_TED_VIDEO_TARGET_CONTROL2 0xd621u
# define IE_TED_VIDEO_TARGET_CHARACTER_BASE 0xd622u
# define IE_TED_VIDEO_TARGET_MATRIX_BASE 0xd623u
# define IE_TED_VIDEO_TARGET_BACKGROUND0 0xd624u
# define IE_TED_VIDEO_TARGET_BACKGROUND1 0xd625u
# define IE_TED_VIDEO_TARGET_BACKGROUND2 0xd626u
# define IE_TED_VIDEO_TARGET_BACKGROUND3 0xd627u
# define IE_TED_VIDEO_TARGET_BORDER 0xd628u
# define IE_TED_VIDEO_TARGET_CURSOR_HIGH 0xd629u
# define IE_TED_VIDEO_TARGET_CURSOR_LOW 0xd62au
# define IE_TED_VIDEO_TARGET_CURSOR_COLOUR 0xd62bu
# define IE_TED_VIDEO_TARGET_RASTER_LOW 0xd62cu
# define IE_TED_VIDEO_TARGET_RASTER_HIGH 0xd62du
# define IE_TED_VIDEO_TARGET_ENABLE 0xd62eu
# define IE_TED_VIDEO_TARGET_STATUS 0xd62fu
# define IE_TED_VIDEO_TARGET_RASTER_COMPARE_LOW 0xd630u
# define IE_TED_VIDEO_TARGET_RASTER_COMPARE_HIGH 0xd631u
# define IE_TED_VIDEO_TARGET_RASTER_STATUS 0xd632u
#elif defined(IE_TARGET_Z80)
# define IE_TED_VIDEO_TARGET_CONTROL1 0x20u
# define IE_TED_VIDEO_TARGET_CONTROL2 0x21u
# define IE_TED_VIDEO_TARGET_CHARACTER_BASE 0x22u
# define IE_TED_VIDEO_TARGET_MATRIX_BASE 0x23u
# define IE_TED_VIDEO_TARGET_BACKGROUND0 0x24u
# define IE_TED_VIDEO_TARGET_BACKGROUND1 0x25u
# define IE_TED_VIDEO_TARGET_BACKGROUND2 0x26u
# define IE_TED_VIDEO_TARGET_BACKGROUND3 0x27u
# define IE_TED_VIDEO_TARGET_BORDER 0x28u
# define IE_TED_VIDEO_TARGET_CURSOR_HIGH 0x29u
# define IE_TED_VIDEO_TARGET_CURSOR_LOW 0x2au
# define IE_TED_VIDEO_TARGET_CURSOR_COLOUR 0x2bu
# define IE_TED_VIDEO_TARGET_RASTER_LOW 0x2cu
# define IE_TED_VIDEO_TARGET_RASTER_HIGH 0x2du
# define IE_TED_VIDEO_TARGET_ENABLE 0x2eu
# define IE_TED_VIDEO_TARGET_STATUS 0x2fu
# define IE_TED_VIDEO_TARGET_RASTER_COMPARE_LOW 0x30u
# define IE_TED_VIDEO_TARGET_RASTER_COMPARE_HIGH 0x31u
# define IE_TED_VIDEO_TARGET_RASTER_STATUS 0x32u
#else
# define IE_TED_VIDEO_TARGET_CONTROL1 IE_TED_VIDEO_CONTROL1
# define IE_TED_VIDEO_TARGET_CONTROL2 IE_TED_VIDEO_CONTROL2
# define IE_TED_VIDEO_TARGET_CHARACTER_BASE IE_TED_VIDEO_CHARACTER_BASE
# define IE_TED_VIDEO_TARGET_MATRIX_BASE IE_TED_VIDEO_MATRIX_BASE
# define IE_TED_VIDEO_TARGET_BACKGROUND0 IE_TED_VIDEO_BACKGROUND0
# define IE_TED_VIDEO_TARGET_BACKGROUND1 IE_TED_VIDEO_BACKGROUND1
# define IE_TED_VIDEO_TARGET_BACKGROUND2 IE_TED_VIDEO_BACKGROUND2
# define IE_TED_VIDEO_TARGET_BACKGROUND3 IE_TED_VIDEO_BACKGROUND3
# define IE_TED_VIDEO_TARGET_BORDER IE_TED_VIDEO_BORDER
# define IE_TED_VIDEO_TARGET_CURSOR_HIGH IE_TED_VIDEO_CURSOR_HIGH
# define IE_TED_VIDEO_TARGET_CURSOR_LOW IE_TED_VIDEO_CURSOR_LOW
# define IE_TED_VIDEO_TARGET_CURSOR_COLOUR IE_TED_VIDEO_CURSOR_COLOUR
# define IE_TED_VIDEO_TARGET_RASTER_LOW IE_TED_VIDEO_RASTER_LOW
# define IE_TED_VIDEO_TARGET_RASTER_HIGH IE_TED_VIDEO_RASTER_HIGH
# define IE_TED_VIDEO_TARGET_ENABLE IE_TED_VIDEO_ENABLE
# define IE_TED_VIDEO_TARGET_STATUS IE_TED_VIDEO_STATUS
# define IE_TED_VIDEO_TARGET_RASTER_COMPARE_LOW IE_TED_VIDEO_RASTER_COMPARE_LOW
# define IE_TED_VIDEO_TARGET_RASTER_COMPARE_HIGH IE_TED_VIDEO_RASTER_COMPARE_HIGH
# define IE_TED_VIDEO_TARGET_RASTER_STATUS IE_TED_VIDEO_RASTER_STATUS
#endif
#define IE_INPUT_TERM_OUT 0x0f0700u

/* Assembly-compatible TED video spellings. */
#define IE_TED_VIDEO_BASE IE_TED_VIDEO_BASE_DIRECT
#define IE_TED_V_CTRL1 IE_TED_VIDEO_CONTROL1
#define IE_TED_V_CTRL2 IE_TED_VIDEO_CONTROL2
#define IE_TED_V_CHAR_BASE IE_TED_VIDEO_CHARACTER_BASE
#define IE_TED_V_VIDEO_BASE IE_TED_VIDEO_MATRIX_BASE
#define IE_TED_V_BG_COLOR0 IE_TED_VIDEO_BACKGROUND0
#define IE_TED_V_BG_COLOR1 IE_TED_VIDEO_BACKGROUND1
#define IE_TED_V_BG_COLOR2 IE_TED_VIDEO_BACKGROUND2
#define IE_TED_V_BG_COLOR3 IE_TED_VIDEO_BACKGROUND3
#define IE_TED_V_BORDER IE_TED_VIDEO_BORDER
#define IE_TED_V_CURSOR_HI IE_TED_VIDEO_CURSOR_HIGH
#define IE_TED_V_CURSOR_LO IE_TED_VIDEO_CURSOR_LOW
#define IE_TED_V_CURSOR_CLR IE_TED_VIDEO_CURSOR_COLOUR
#define IE_TED_V_RASTER_LO IE_TED_VIDEO_RASTER_LOW
#define IE_TED_V_RASTER_HI IE_TED_VIDEO_RASTER_HIGH
#define IE_TED_V_ENABLE IE_TED_VIDEO_ENABLE
#define IE_TED_V_STATUS IE_TED_VIDEO_STATUS
#define IE_TED_V_CTRL1_ECM IE_TED_VIDEO_CONTROL1_ECM
#define IE_TED_V_CTRL1_BMM IE_TED_VIDEO_CONTROL1_BMM
#define IE_TED_V_CTRL1_DEN IE_TED_VIDEO_CONTROL1_ENABLE
#define IE_TED_V_CTRL1_RSEL IE_TED_VIDEO_CONTROL1_ROW_SELECT
#define IE_TED_V_CTRL1_YSCROLL IE_TED_VIDEO_CONTROL1_SCROLL_MASK
#define IE_TED_V_CTRL2_RES IE_TED_VIDEO_CONTROL2_RESET
#define IE_TED_V_CTRL2_MCM IE_TED_VIDEO_CONTROL2_MULTICOLOUR
#define IE_TED_V_CTRL2_CSEL IE_TED_VIDEO_CONTROL2_COLUMN_SELECT
#define IE_TED_V_CTRL2_XSCROLL IE_TED_VIDEO_CONTROL2_SCROLL_MASK
#define IE_TED_V_STATUS_VBLANK IE_TED_VIDEO_STATUS_VBLANK

#define IE_VIDEO_PAL_INDEX IE_VIDEO_PALETTE_INDEX
#define IE_VIDEO_PAL_DATA IE_VIDEO_PALETTE_DATA
#define IE_VIDEO_RASTER_COLOR IE_VIDEO_RASTER_COLOUR
#define IE_VIDEO_RASTER_CTRL IE_VIDEO_RASTER_CONTROL
#define IE_INPUT_TERM_STATUS 0x0f0704u
#define IE_INPUT_TERM_IN 0x0f0708u
#define IE_INPUT_TERM_LINE_STATUS 0x0f070cu
#define IE_INPUT_TERM_ECHO 0x0f0710u
#define IE_INPUT_TERM_CTRL 0x0f0724u
#define IE_INPUT_TERM_KEY_IN 0x0f0728u
#define IE_INPUT_TERM_KEY_STATUS 0x0f072cu
#define IE_INPUT_MOUSE_X 0x0f0730u
#define IE_INPUT_MOUSE_Y 0x0f0734u
#define IE_INPUT_MOUSE_BUTTONS 0x0f0738u
#define IE_INPUT_MOUSE_STATUS 0x0f073cu
#define IE_INPUT_SCAN_CODE 0x0f0740u
#define IE_INPUT_SCAN_STATUS 0x0f0744u
#define IE_INPUT_SCAN_MODIFIERS 0x0f0748u
#define IE_INPUT_MOUSE_CTRL 0x0f074cu
#define IE_INPUT_MOUSE_DX 0x0f0754u
#define IE_INPUT_MOUSE_DY 0x0f0758u
#define IE_SYSTEM_RTC_EPOCH 0x0f0750u
#define IE_SYSTEM_RTC_MONO_USEC_LO 0x0f075cu
#define IE_SYSTEM_RTC_MONO_USEC_HI 0x0f0760u
/* The wheel: signed steps that clear on read, positive up and right, and
 * a status bit that a read does not clear. MOUSE_BUTTONS bit 3 is the
 * fourth button. */
#define IE_INPUT_MOUSE_WHEEL 0x0f0764u
#define IE_INPUT_MOUSE_HWHEEL 0x0f0768u
#define IE_INPUT_MOUSE_WHEEL_STATUS 0x0f076cu
#define IE_INPUT_MOUSE_WHEEL_PENDING 0x01u
#define IE_INPUT_MOUSE_BUTTON_FOURTH 0x08u
#define IE_SYSTEM_WAIT_VBLANK 0x0f2580u

/* The deadline park. The guest writes the host monotonic microsecond deadline
 * into the LO and HI pair and then writes IE_SYSTEM_WAIT_UNTIL_GO, which parks
 * the CPU rather than spinning it. A park is bounded by a host-side safety
 * timeout and cannot report why it ended, so a guest re-reads
 * IE_SYSTEM_RTC_MONO_USEC_LO and _HI on wake and parks again while the
 * deadline is still in the future. IE_SYSTEM_WAIT_VBLANK is the same shape
 * against the next field edge. */
#define IE_SYSTEM_WAIT_UNTIL_LO 0x0f2584u
#define IE_SYSTEM_WAIT_UNTIL_HI 0x0f2588u
#define IE_SYSTEM_WAIT_UNTIL_GO 0x0f258cu

/* SYSINFO. What the machine reports about itself: the host-derived total guest
 * RAM, the smaller figure the running CPU and profile can actually see, the
 * dense low window, and a feature bitmap. Exec is given the active figure
 * rather than the total, because the total includes RAM the profile clamp
 * withheld. */
#define IE_SYSINFO_REGION_BASE 0x0f2400u
#define IE_SYSINFO_REGION_END 0x0f24ffu
#define IE_SYSINFO_TOTAL_RAM_LO 0x0f2400u
#define IE_SYSINFO_TOTAL_RAM_HI 0x0f2404u
#define IE_SYSINFO_ACTIVE_RAM_LO 0x0f2408u
#define IE_SYSINFO_ACTIVE_RAM_HI 0x0f240cu
#define IE_SYSINFO_FEATURES 0x0f2410u
#define IE_SYSINFO_LOW_WINDOW_LO 0x0f2414u
#define IE_SYSINFO_LOW_WINDOW_HI 0x0f2418u

/* Machine exit. A 32-bit write here from any core records the value written
 * as a signed exit status, 0 being a clean exit. In a run with no window and
 * no script the engine then stops every core and exits with that status, of
 * which the host keeps the low 8 bits. With a window or a script the machine
 * keeps running and only the status is recorded. Only the first write counts
 * until the machine is reset; a read returns its status, or 0 before one. The
 * write does not stop the core that made it, so follow it with a halt. Test
 * IE_SYSINFO_FEATURE_EXIT first: an engine without the register ignores the
 * write. */
#define IE_SYSINFO_EXIT 0x0f241cu

/* The feature bits. IE_SYSINFO_FEATURE_WAIT reads as set wherever the SYSINFO
 * block exists rather than being probed, so it says the machine has the wait
 * registers in its register map, not that this build mapped them. */
#define IE_SYSINFO_FEATURE_WAIT 0x01u
#define IE_SYSINFO_FEATURE_VOODOO_CMD_STREAM 0x02u
#define IE_SYSINFO_FEATURE_MMIO_STATS 0x04u
#define IE_SYSINFO_FEATURE_VOODOO_TEX_SLOTS 0x08u
#define IE_SYSINFO_FEATURE_ENTROPY 0x10u
#define IE_SYSINFO_FEATURE_EXIT 0x20u
#define IE_SYSINFO_FEATURE_GPIO 0x40u

/* Host entropy block. Every read anywhere in the region returns fresh bytes
 * from the host's cryptographic random source, at any access width and any
 * offset inside the region; writes are ignored. Nothing else lives in the
 * region, so a 64-bit read, which the bus serves as two 32-bit reads, gets
 * fresh bytes for both halves.
 *
 * Test IE_SYSINFO_FEATURE_ENTROPY in IE_SYSINFO_FEATURES before reading. That
 * bit is probed rather than assumed: it is set only whilst the block is really
 * mapped, so it stays clear on a machine that publishes SYSINFO without it. On
 * an engine without the block these addresses are ordinary RAM and read as
 * zero, which a guest cannot tell apart from a device that returned zero.
 * Eight-bit targets reach the block through bank 1, as they do the gamepad. */
#define IE_ENTROPY_REGION_BASE 0x0f2a00u
#define IE_ENTROPY_REGION_END 0x0f2a0fu
#define IE_ENTROPY_DATA 0x0f2a00u
#define IE_ENTROPY_IO_BANK 0x79u
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_ENTROPY_DATA_TARGET 0x2a00u
#else
# define IE_ENTROPY_DATA_TARGET IE_ENTROPY_DATA
#endif

/* General purpose I/O block (gpio_mmio.go). Up to 64 host lines, every one
 * an input until the host's allow-list lets a guest drive it. Registers are
 * 32-bit words that answer at any width; SET, CLR and TGL change their pins
 * in one host operation. Test IE_SYSINFO_FEATURE_GPIO in IE_SYSINFO_FEATURES
 * first: without a host back end IE_GPIO_COUNT reads zero and writes are
 * ignored. Eight-bit targets reach the block through bank 1 and use the
 * _TARGET addresses. */
#define IE_GPIO_REGION_BASE 0x0f2a10u
#define IE_GPIO_REGION_END 0x0f2a7fu
#define IE_GPIO_IO_BANK 0x79u
#define IE_GPIO_COUNT 0x0f2a10u
#define IE_GPIO_CTRL 0x0f2a14u
#define IE_GPIO_IN_LO 0x0f2a18u
#define IE_GPIO_IN_HI 0x0f2a1cu
#define IE_GPIO_OUT_LO 0x0f2a20u
#define IE_GPIO_OUT_HI 0x0f2a24u
#define IE_GPIO_SET_LO 0x0f2a28u
#define IE_GPIO_SET_HI 0x0f2a2cu
#define IE_GPIO_CLR_LO 0x0f2a30u
#define IE_GPIO_CLR_HI 0x0f2a34u
#define IE_GPIO_TGL_LO 0x0f2a38u
#define IE_GPIO_TGL_HI 0x0f2a3cu
#define IE_GPIO_DIR_LO 0x0f2a40u
#define IE_GPIO_DIR_HI 0x0f2a44u
#define IE_GPIO_RISE_LO 0x0f2a48u
#define IE_GPIO_RISE_HI 0x0f2a4cu
#define IE_GPIO_FALL_LO 0x0f2a50u
#define IE_GPIO_FALL_HI 0x0f2a54u
#define IE_GPIO_EDGE_LO 0x0f2a58u
#define IE_GPIO_EDGE_HI 0x0f2a5cu
#define IE_GPIO_ALLOW_LO 0x0f2a60u
#define IE_GPIO_ALLOW_HI 0x0f2a64u
#define IE_GPIO_PIN 0x0f2a68u
#define IE_GPIO_VALUE 0x0f2a6cu
#define IE_GPIO_PINCFG 0x0f2a70u
#define IE_GPIO_PINEDGE 0x0f2a74u
#define IE_GPIO_DENIED 0x0f2a78u
#define IE_GPIO_STATUS 0x0f2a7cu
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_GPIO_TARGET(reg) (0x2000u + ((reg) & 0x1fffu))
#else
# define IE_GPIO_TARGET(reg) (reg)
#endif
#define IE_GPIO_CTRL_RELEASE 0x01u
#define IE_GPIO_PINCFG_OUT 0x01u
#define IE_GPIO_PINCFG_RISE 0x02u
#define IE_GPIO_PINCFG_FALL 0x04u
#define IE_GPIO_PINCFG_ALLOWED 0x100u
#define IE_GPIO_PINCFG_EDGE 0x200u
#define IE_GPIO_STATUS_PRESENT 0x01u
#define IE_GPIO_STATUS_HOST_FAIL 0x02u

/* DOS bridge. The guest writes the ARG registers, then writes a command code
 * to IE_DOS_CMD, which runs the operation synchronously; RESULT1 and RESULT2
 * are readable immediately after. The command codes and error values are the
 * AmigaDOS ones and are not repeated here. */
#define IE_DOS_BASE 0x0f2220u
#define IE_DOS_CMD 0x0f2220u
#define IE_DOS_ARG1 0x0f2224u
#define IE_DOS_ARG2 0x0f2228u
#define IE_DOS_ARG3 0x0f222cu
#define IE_DOS_ARG4 0x0f2230u
#define IE_DOS_RESULT1 0x0f2234u
#define IE_DOS_RESULT2 0x0f2238u
#define IE_DOS_STATUS 0x0f223cu
#define IE_DOS_END 0x0f225fu
#define IE_AUDIO_BASE 0x0f0800u
#define IE_AUDIO_CONTROL 0x0f0800u
#define IE_AUDIO_ENVELOPE_SHAPE 0x0f0804u
#define IE_AUDIO_ENVELOPE_SHAPE_CH_BASE 0x0f0860u
#define IE_AUDIO_FILTER_CUTOFF 0x0f0820u
#define IE_AUDIO_FILTER_RESONANCE 0x0f0824u
#define IE_AUDIO_FILTER_TYPE 0x0f0828u
#define IE_AUDIO_FILTER_MOD_SOURCE 0x0f082cu
#define IE_AUDIO_FILTER_MOD_AMOUNT 0x0f0830u
#define IE_AUDIO_FILTER_OFF 0u
#define IE_AUDIO_FILTER_LOWPASS 1u
#define IE_AUDIO_FILTER_HIGHPASS 2u
#define IE_AUDIO_FILTER_BANDPASS 3u
#define IE_AUDIO_SQUARE_FREQUENCY 0x0f0900u
#define IE_AUDIO_SQUARE_VOLUME 0x0f0904u
#define IE_AUDIO_SQUARE_CONTROL 0x0f0908u
#define IE_AUDIO_TRIANGLE_FREQUENCY 0x0f0940u
#define IE_AUDIO_TRIANGLE_VOLUME 0x0f0944u
#define IE_AUDIO_TRIANGLE_CONTROL 0x0f0948u
#define IE_AUDIO_SINE_FREQUENCY 0x0f0980u
#define IE_AUDIO_SINE_VOLUME 0x0f0984u
#define IE_AUDIO_SINE_CONTROL 0x0f0988u
#define IE_AUDIO_NOISE_FREQUENCY 0x0f09c0u
#define IE_AUDIO_NOISE_VOLUME 0x0f09c4u
#define IE_AUDIO_NOISE_CONTROL 0x0f09c8u
#define IE_AUDIO_SQUARE_DUTY 0x0f090cu
#define IE_AUDIO_SQUARE_SWEEP 0x0f0910u
#define IE_AUDIO_SQUARE_PWM_CONTROL 0x0f0922u
#define IE_AUDIO_SQUARE_ATTACK 0x0f0930u
#define IE_AUDIO_SQUARE_DECAY 0x0f0934u
#define IE_AUDIO_SQUARE_SUSTAIN 0x0f0938u
#define IE_AUDIO_SQUARE_RELEASE 0x0f093cu
#define IE_AUDIO_TRIANGLE_SWEEP 0x0f0914u
#define IE_AUDIO_TRIANGLE_ATTACK 0x0f0960u
#define IE_AUDIO_TRIANGLE_DECAY 0x0f0964u
#define IE_AUDIO_TRIANGLE_SUSTAIN 0x0f0968u
#define IE_AUDIO_TRIANGLE_RELEASE 0x0f096cu
#define IE_AUDIO_SINE_SWEEP 0x0f0918u
#define IE_AUDIO_SINE_ATTACK 0x0f0990u
#define IE_AUDIO_SINE_DECAY 0x0f0994u
#define IE_AUDIO_SINE_SUSTAIN 0x0f0998u
#define IE_AUDIO_SINE_RELEASE 0x0f099cu
#define IE_AUDIO_NOISE_ATTACK 0x0f09d0u
#define IE_AUDIO_NOISE_DECAY 0x0f09d4u
#define IE_AUDIO_NOISE_SUSTAIN 0x0f09d8u
#define IE_AUDIO_NOISE_RELEASE 0x0f09dcu
#define IE_AUDIO_NOISE_MODE 0x0f09e0u
#define IE_AUDIO_SYNC_SOURCE_CH0 0x0f0a00u
#define IE_AUDIO_SYNC_SOURCE_CH1 0x0f0a04u
#define IE_AUDIO_SYNC_SOURCE_CH2 0x0f0a08u
#define IE_AUDIO_SYNC_SOURCE_CH3 0x0f0a0cu
#define IE_AUDIO_RING_MOD_SOURCE_CH0 0x0f0a10u
#define IE_AUDIO_RING_MOD_SOURCE_CH1 0x0f0a14u
#define IE_AUDIO_RING_MOD_SOURCE_CH2 0x0f0a18u
#define IE_AUDIO_RING_MOD_SOURCE_CH3 0x0f0a1cu
#define IE_AUDIO_SAW_FREQUENCY 0x0f0a20u
#define IE_AUDIO_SAW_VOLUME 0x0f0a24u
#define IE_AUDIO_SAW_CONTROL 0x0f0a28u
#define IE_AUDIO_SAW_SWEEP 0x0f0a2cu
#define IE_AUDIO_SAW_ATTACK 0x0f0a30u
#define IE_AUDIO_SAW_DECAY 0x0f0a34u
#define IE_AUDIO_SAW_SUSTAIN 0x0f0a38u
#define IE_AUDIO_SAW_RELEASE 0x0f0a3cu
#define IE_AUDIO_OVERDRIVE_CONTROL 0x0f0a40u
#define IE_AUDIO_SAW_SYNC_SOURCE 0x0f0a60u
#define IE_AUDIO_SAW_RING_MOD_SOURCE 0x0f0a64u
#define IE_AUDIO_NOISE_WHITE 0u
#define IE_AUDIO_NOISE_PERIODIC 1u
#define IE_AUDIO_NOISE_METALLIC 2u
#define IE_AUDIO_NOISE_PSG 3u

/* Custom synthesiser effects and flexible channels. */
#define IE_FLEX_STRIDE 0x40u
#define IE_FLEX_OFFSET_FREQUENCY 0x00u
#define IE_FLEX_OFFSET_VOLUME 0x04u
#define IE_FLEX_OFFSET_CONTROL 0x08u
#define IE_FLEX_OFFSET_DUTY 0x0cu
#define IE_FLEX_OFFSET_SWEEP 0x10u
#define IE_FLEX_OFFSET_ATTACK 0x14u
#define IE_FLEX_OFFSET_DECAY 0x18u
#define IE_FLEX_OFFSET_SUSTAIN 0x1cu
#define IE_FLEX_OFFSET_RELEASE 0x20u
#define IE_FLEX_OFFSET_WAVE_TYPE 0x24u
#define IE_FLEX_OFFSET_PWM_CONTROL 0x28u
#define IE_FLEX_OFFSET_NOISE_MODE 0x2cu
#define IE_FLEX_OFFSET_PHASE 0x30u
#define IE_FLEX_OFFSET_RING_MODULATION 0x34u
#define IE_FLEX_OFFSET_SYNC 0x38u
#define IE_FLEX_OFFSET_DAC 0x3cu
#define IE_FLEX_CH_BASE IE_FLEX_BASE
#define IE_FLEX_CH_STRIDE IE_FLEX_STRIDE
#define IE_FLEX_WAVE_SQUARE 0x00u
#define IE_FLEX_WAVE_TRIANGLE 0x01u
#define IE_FLEX_WAVE_SINE 0x02u
#define IE_FLEX_WAVE_NOISE 0x03u
#define IE_FLEX_WAVE_SAWTOOTH 0x04u
#define IE_AUDIO_CONTROL_ENABLE 0x01u
#define IE_AUDIO_CONTROL_FREEZE 0x02u
#define IE_AUDIO_CTRL IE_AUDIO_CONTROL
#define IE_AUDIO_ENABLE IE_AUDIO_CONTROL_ENABLE
#define IE_AUDIO_FREEZE IE_AUDIO_CONTROL_FREEZE
#define IE_FLEX_CONTROL_GATE 0x02u
#define IE_FLEX_CONTROL_ENABLE_GATE 0x03u
#define IE_FLEX_PWM_ENABLE 0x80u
#define IE_FLEX_PWM_RATE_MASK 0x7fu
#define IE_FLEX_SWEEP_ENABLE 0x80u
#define IE_FLEX_SWEEP_DIRECTION_UP 0x08u
#define IE_FLEX_SWEEP_DIRECTION_DOWN 0x00u
#define IE_FLEX_SWEEP_PERIOD_MASK 0x70u
#define IE_FLEX_SWEEP_SHIFT_MASK 0x07u

#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_REVERB_MIX 0xfa50u
# define IE_REVERB_DECAY 0xfa54u
# define IE_FLEX_BASE 0xfa80u
# define IE_FLEX_END 0xfb7fu
# define IE_FLEX_CH0_BASE 0xfa80u
# define IE_FLEX_CH1_BASE 0xfac0u
# define IE_FLEX_CH2_BASE 0xfb00u
# define IE_FLEX_CH3_BASE 0xfb40u
# define IE_SID2_FLEX_BASE 0xfc40u
# define IE_SID3_FLEX_BASE 0xfd40u
# define IE_MIDI_PLAY_POINTER 0xfba0u
# define IE_MIDI_PLAY_LENGTH 0xfba4u
# define IE_MIDI_PLAY_CONTROL 0xfba8u
# define IE_MIDI_PLAY_STATUS 0xfbacu
# define IE_MIDI_POSITION 0xfbb0u
# define IE_MIDI_VOLUME 0xfbb4u
# define IE_MIDI_TEMPO_BPM 0xfbb8u
# define IE_MIDI_END 0xfbbfu
# define IE_MIDI_LIVE_DATA 0xfbf4u
# define IE_MIDI_LIVE_STATUS 0xfbf5u
# define IE_MIDI_LIVE_CONTROL 0xfbf6u
# define IE_MIDI_LIVE_END 0xfbf6u
#else
# define IE_REVERB_MIX 0x0f0a50u
# define IE_REVERB_DECAY 0x0f0a54u
# define IE_FLEX_BASE 0x0f0a80u
# define IE_FLEX_END 0x0f0b7fu
# define IE_FLEX_CH0_BASE 0x0f0a80u
# define IE_FLEX_CH1_BASE 0x0f0ac0u
# define IE_FLEX_CH2_BASE 0x0f0b00u
# define IE_FLEX_CH3_BASE 0x0f0b40u
# define IE_SID2_FLEX_BASE 0x0f0c40u
# define IE_SID3_FLEX_BASE 0x0f0d40u
# define IE_MIDI_PLAY_POINTER 0x0f0ba0u
# define IE_MIDI_PLAY_LENGTH 0x0f0ba4u
# define IE_MIDI_PLAY_CONTROL 0x0f0ba8u
# define IE_MIDI_PLAY_STATUS 0x0f0bacu
# define IE_MIDI_POSITION 0x0f0bb0u
# define IE_MIDI_VOLUME 0x0f0bb4u
# define IE_MIDI_TEMPO_BPM 0x0f0bb8u
# define IE_MIDI_END 0x0f0bbfu
# define IE_MIDI_LIVE_DATA 0x0f0bf4u
# define IE_MIDI_LIVE_STATUS 0x0f0bf5u
# define IE_MIDI_LIVE_CONTROL 0x0f0bf6u
# define IE_MIDI_LIVE_END 0x0f0bf6u
/* MIDI input: what a host MIDI device plays (midi_rx.go). Longword
 * registers, out of reach of the eight-bit processors. */
# define IE_MIDI_RX_BASE 0x0f1540u
# define IE_MIDI_RX_DATA 0x0f1540u
# define IE_MIDI_RX_STATUS 0x0f1544u
# define IE_MIDI_RX_CONTROL 0x0f1548u
# define IE_MIDI_RX_LOST 0x0f154cu
# define IE_MIDI_RX_END 0x0f155fu
#endif

#define IE_FLEX_OFF_FREQ IE_FLEX_OFFSET_FREQUENCY
#define IE_FLEX_OFF_VOL IE_FLEX_OFFSET_VOLUME
#define IE_FLEX_OFF_CTRL IE_FLEX_OFFSET_CONTROL
#define IE_FLEX_OFF_DUTY IE_FLEX_OFFSET_DUTY
#define IE_FLEX_OFF_SWEEP IE_FLEX_OFFSET_SWEEP
#define IE_FLEX_OFF_ATK IE_FLEX_OFFSET_ATTACK
#define IE_FLEX_OFF_DEC IE_FLEX_OFFSET_DECAY
#define IE_FLEX_OFF_SUS IE_FLEX_OFFSET_SUSTAIN
#define IE_FLEX_OFF_REL IE_FLEX_OFFSET_RELEASE
#define IE_FLEX_OFF_WAVE_TYPE IE_FLEX_OFFSET_WAVE_TYPE
#define IE_FLEX_OFF_PWM_CTRL IE_FLEX_OFFSET_PWM_CONTROL
#define IE_FLEX_OFF_NOISEMODE IE_FLEX_OFFSET_NOISE_MODE
#define IE_FLEX_OFF_PHASE IE_FLEX_OFFSET_PHASE
#define IE_FLEX_OFF_RINGMOD IE_FLEX_OFFSET_RING_MODULATION
#define IE_FLEX_OFF_SYNC IE_FLEX_OFFSET_SYNC
#define IE_FLEX_OFF_DAC IE_FLEX_OFFSET_DAC
#define IE_MIDI_PLAY_PTR IE_MIDI_PLAY_POINTER
#define IE_MIDI_PLAY_LEN IE_MIDI_PLAY_LENGTH
#define IE_MIDI_PLAY_CTRL IE_MIDI_PLAY_CONTROL
#define IE_MIDI_STATUS_BUSY 0x01u
#define IE_MIDI_STATUS_ERROR 0x02u
#define IE_MIDI_STATUS_PAUSED 0x04u
#define IE_MIDI_STATUS_LOADING 0x08u
#define IE_MIDI_CONTROL_START 0x01u
#define IE_MIDI_CONTROL_STOP 0x02u
#define IE_MIDI_CONTROL_LOOP 0x04u
#define IE_MIDI_CONTROL_PAUSE 0x08u
#define IE_MIDI_CONTROL_START_LOOP 0x05u
#define IE_MIDI_LIVE_STATUS_ACTIVE 0x01u
#define IE_MIDI_LIVE_CONTROL_RESET 0x01u
#define IE_MIDI_LIVE_CTRL IE_MIDI_LIVE_CONTROL
#define IE_MIDI_LIVE_CTRL_RESET IE_MIDI_LIVE_CONTROL_RESET
#define IE_MIDI_RX_DATA_VALID 0x0100u
#define IE_MIDI_RX_DATA_LOST 0x8000u
#define IE_MIDI_RX_STATUS_WAITING 0x01u
#define IE_MIDI_RX_STATUS_LOST 0x02u
#define IE_MIDI_RX_STATUS_HOST 0x04u
#define IE_MIDI_RX_CONTROL_RECEIVE 0x01u
#define IE_MIDI_RX_CONTROL_INTERRUPT 0x02u
#define IE_MIDI_RX_CONTROL_FLUSH 0x80u

/* Additional media players and dedicated sound chips. */
#define IE_AHX_BASE 0x0f0b80u
#define IE_AHX_PLUS_CONTROL 0x0f0b80u
#define IE_AHX_PLAY_POINTER 0x0f0b84u
#define IE_AHX_PLAY_LENGTH 0x0f0b88u
#define IE_AHX_PLAY_CONTROL 0x0f0b8cu
#define IE_AHX_PLAY_STATUS 0x0f0b90u
#define IE_AHX_SUBSONG 0x0f0b91u
#define IE_MOD_PLAY_POINTER 0x0f0bc0u
#define IE_MOD_PLAY_LENGTH 0x0f0bc4u
#define IE_MOD_PLAY_CONTROL 0x0f0bc8u
#define IE_MOD_PLAY_STATUS 0x0f0bccu
#define IE_MOD_FILTER_MODEL 0x0f0bd0u
#define IE_MOD_POSITION 0x0f0bd4u
#define IE_MOD_END 0x0f0bd7u
#define IE_WAV_PLAY_POINTER 0x0f0bd8u
#define IE_WAV_PLAY_LENGTH 0x0f0bdcu
#define IE_WAV_PLAY_CONTROL 0x0f0be0u
#define IE_WAV_PLAY_STATUS 0x0f0be4u
#define IE_WAV_POSITION 0x0f0be8u
#define IE_WAV_PLAY_POINTER_HIGH 0x0f0becu
#define IE_WAV_CHANNEL_BASE 0x0f0bf0u
#define IE_WAV_VOLUME_LEFT 0x0f0bf1u
#define IE_WAV_VOLUME_RIGHT 0x0f0bf2u
#define IE_WAV_FLAGS 0x0f0bf3u
#define IE_WAV_END 0x0f0bf3u
#define IE_PSG_BASE 0x0f0c00u
#define IE_PSG_END 0x0f0c0fu
#define IE_PSG_PLAY_POINTER 0x0f0c10u
#define IE_PSG_PLAY_LENGTH 0x0f0c14u
#define IE_PSG_PLAY_CONTROL 0x0f0c18u
#define IE_PSG_PLAY_STATUS 0x0f0c1cu
#define IE_PSG_PLUS_CONTROL 0x0f0c20u
#define IE_POKEY_BASE 0x0f0d00u
#define IE_POKEY_CHANNEL1_FREQUENCY 0x0f0d00u
#define IE_POKEY_CHANNEL1_CONTROL 0x0f0d01u
#define IE_POKEY_CHANNEL2_FREQUENCY 0x0f0d02u
#define IE_POKEY_CHANNEL2_CONTROL 0x0f0d03u
#define IE_POKEY_CHANNEL3_FREQUENCY 0x0f0d04u
#define IE_POKEY_CHANNEL3_CONTROL 0x0f0d05u
#define IE_POKEY_CHANNEL4_FREQUENCY 0x0f0d06u
#define IE_POKEY_CHANNEL4_CONTROL 0x0f0d07u
#define IE_POKEY_AUDIO_CONTROL 0x0f0d08u
#define IE_POKEY_PLUS_CONTROL 0x0f0d09u
#define IE_POKEY_RANDOM 0x0f0d0au

/* Paula: four DMA sound channels at 0x0f0f80.
 *
 * A channel plays signed eight-bit samples out of guest RAM at the
 * Paula clock over its period, and raises its interrupt at the end of
 * every buffer. Registers are little-endian and readable back.
 *
 * The request bit is set whether or not anything is listening: read the
 * interrupt request register and the buffer ends are there, and writing
 * the bits back clears them. The interrupt enable register decides
 * delivery, not whether the bit is set, and delivery means a CPU
 * interrupt only where the runtime has given the chip somewhere to send
 * one - which today is the Amiga payload alone. Every other guest polls,
 * and polling is a complete way to use the chip rather than a fallback.
 *
 * The usual sequence is location, length, period, volume, then the
 * channel's bit in the DMA control word together with the master
 * enable.
 *
 * One access, one register. The registers are packed two bytes apart,
 * so a longword covers a pair of them - length with period, DMA
 * control with the modulation word, the interrupt request with the
 * interrupt enable - but a longword write sets only the register it
 * names and drops the bits above it. Set a pair with a pair of
 * sixteen-bit writes rather than one thirty-two bit write over both. A
 * longword read likewise answers with the named register alone,
 * counted from the byte addressed, so the high half of a location
 * register reads back at LOCATION+2. */
/* Native CIA and Paula peripheral blocks. Registers use four-byte slots. */
/* Amiga custom words and board controls. */
#define IE_AMIGA_CUSTOM_BASE 0x0f7200u
#define IE_AMIGA_CUSTOM_REG(off) (IE_AMIGA_CUSTOM_BASE + (off))
#define IE_AMIGA_BOARD_BASE 0x0f7f00u
#define IE_AMIGA_BOARD_RESET 0x0f7f00u
#define IE_AMIGA_BOARD_TIME 0x0f7f04u
#define IE_AMIGA_BOARD_FIELDS 0x0f7f08u
#define IE_AMIGA_BOARD_TICK 0x0f7f0cu
#define IE_AMIGA_BOARD_H_WINDOW 0x0f7f10u
#define IE_AMIGA_BOARD_V_WINDOW 0x0f7f14u
#define IE_AMIGA_BOARD_MODE 0x0f7f18u
#define IE_AMIGA_BOARD_RASTER 0x0f7f1cu
#define IE_AMIGA_BOARD_PIXELS 0x0f7f20u
#define IE_AMIGA_BOARD_DETERMINISTIC 0x0f7f28u
#define IE_AMIGA_BOARD_ACCESS 0x0f7f2cu
#define IE_AMIGA_BOARD_CUSTOM_BYTE 0x0f7f30u
#define IE_AMIGA_BOARD_EVENTS 0x0f7f34u
#define IE_AMIGA_BOARD_PUBLISH 0x0f7f38u
#define IE_AMIGA_BOARD_EVENT_ACK 0x0f7f3cu
#define IE_AMIGA_BOARD_DROP_RTG 0x0f7f40u
#define IE_AMIGA_BOARD_GUEST_ACTIVE 0x0f7f44u
#define IE_AMIGA_BOARD_RENDER_US 0x0f7f48u
#define IE_AMIGA_BOARD_RENDER_TOTAL_US 0x0f7f4cu
/* The extended ROM's registers on the board (sdk/amiga/rom/ie_rom.i). */
#define IE_AMIGA_BOARD_ROM_STAGE 0x0f7f50u
#define IE_AMIGA_BOARD_ROM_PROBE 0x0f7f54u
#define IE_AMIGA_BOARD_ROM_PROBE2 0x0f7f58u
#define IE_AMIGA_BOARD_MEDIA_TABLE 0x0f7f5cu
#define IE_AMIGA_BOARD_FASTRAM_BASE 0x0f7f60u
#define IE_AMIGA_BOARD_FASTRAM_SIZE 0x0f7f64u
#define IE_AMIGA_BOARD_BOOT_NODES 0x0f7f68u
#define IE_AMIGA_BOARD_BOOT_STAGE 0x0f7f6cu
#define IE_AMIGA_BOARD_HD_REQUESTS 0x0f7f70u
#define IE_AMIGA_BOARD_DV_PACKETS 0x0f7f74u
#define IE_AMIGA_BOARD_BRIDGE_GUARD 0x0f7f78u
#define IE_AMIGA_BOARD_DV_ROOT_NODE 0x0f7f7cu
#define IE_AMIGA_ROM_STAGE_READY 0x524f4d31u
/* Native Gayle IDE registers. DATA transfers one 16-bit PIO word. */
#define IE_GAYLE_BASE 0x0f7640u
#define IE_GAYLE_DATA 0x0f7640u
#define IE_GAYLE_ERROR 0x0f7644u
#define IE_GAYLE_COUNT 0x0f7648u
#define IE_GAYLE_SECTOR 0x0f764cu
#define IE_GAYLE_CYL_LOW 0x0f7650u
#define IE_GAYLE_CYL_HIGH 0x0f7654u
#define IE_GAYLE_SELECT 0x0f7658u
#define IE_GAYLE_STATUS 0x0f765cu
#define IE_GAYLE_ALT_STATUS 0x0f7660u
#define IE_GAYLE_DRIVE_ADDRESS 0x0f7664u
#define IE_GAYLE_CARD_STATUS 0x0f7668u
#define IE_GAYLE_IRQ 0x0f766cu
#define IE_GAYLE_INT_ENABLE 0x0f7670u
#define IE_GAYLE_CONFIG 0x0f7674u
#define IE_GAYLE_RESET 0x0f7678u
#define IE_GAYLE_END 0x0f767fu

#define IE_AMIGA_RTC_BASE 0x0f7f80u
#define IE_AMIGA_RTC_REG(n) (IE_AMIGA_RTC_BASE + (n) * 4u)
#define IE_AMIGA_RTC_EPOCH 0x0f7fc0u
#define IE_AMIGA_RTC_RESET 0x0f7fc4u
#define IE_AMIGA_RTC_READS 0x0f7fc8u
#define IE_AMIGA_RTC_TIME_READS 0x0f7fccu
#define IE_AMIGA_RTC_BANK1_WRITES 0x0f7fd0u
#define IE_AMIGA_RTC_WRITES 0x0f7fd4u
#define IE_AMIGA_RTC_UTC_OFFSET 0x0f7fd8u
#define IE_AMIGA_RTC_PEEK(n) (0x0f7fe0u + (n))

#define IE_CIA_BASE 0x0f7c00u
#define IE_CIA_CHIP_STRIDE 0x40u
#define IE_CIA_REGISTER(chip, reg) (IE_CIA_BASE + (chip) * IE_CIA_CHIP_STRIDE + (reg) * 4u)
#define IE_CIA_TIME 0x0f7c80u
#define IE_CIA_ECLOCK 0x0f7c84u
#define IE_CIA_TODA 0x0f7c88u
#define IE_CIA_TODB 0x0f7c8cu
#define IE_CIA_RESET 0x0f7c90u
#define IE_CIA_IRQ 0x0f7c94u
#define IE_CIA_INPUTA 0x0f7c98u
#define IE_CIA_INPUTB 0x0f7c9cu
#define IE_CIA_PINSA 0x0f7ca0u
#define IE_CIA_PINSB 0x0f7ca4u
#define IE_CIA_COMPAT 0x0f7ca8u
#define IE_CIA_KEYRAW 0x0f7cb0u
#define IE_CIA_KEYSEND 0x0f7cb4u
#define IE_CIA_KEYSTATE 0x0f7cb8u
#define IE_CIA_KEYCONTROL 0x0f7cbcu
#define IE_CIA_PEEK 0x0f7cc0u
#define IE_CIA_MASKA 0x0f7ce0u
#define IE_CIA_MASKB 0x0f7ce4u
#define IE_CIA_TODLATCHED 0x0f7ce8u
#define IE_CIA_TODLIVEA 0x0f7cecu
#define IE_CIA_TODLIVEB 0x0f7cf0u
#define IE_CIA_KEYCOUNT 0x0f7cf4u
#define IE_CIA_CONNECTIONS 0x0f7cf8u

#define IE_PAULA_DISK_MEDIA_KIND 0x0f7d88u
#define IE_PAULA_DISK_MEDIA_BASE 0x0f7d8cu
#define IE_PAULA_DISK_SERVICE 0x0f7d90u
#define IE_PAULA_DISK_MOUNT 0x0f7d94u
#define IE_PAULA_DISK_POINTER_HIGH 0x0f7d98u
#define IE_PAULA_DISK_POINTER_LOW 0x0f7d9cu
#define IE_PAULA_DISK_DMA_SETCLR 0x0f7da0u
#define IE_PAULA_DISK_TIME 0x0f7da4u
#define IE_PAULA_DISK_PACE 0x0f7da8u
#define IE_PAULA_DISK_BASE 0x0f7d00u
#define IE_PAULA_DISK_PTR 0x0f7d00u
#define IE_PAULA_DISK_LEN 0x0f7d04u
#define IE_PAULA_DISK_SYNC 0x0f7d08u
#define IE_PAULA_DISK_BYTR 0x0f7d0cu
#define IE_PAULA_DISK_DMA 0x0f7d10u
#define IE_PAULA_DISK_ADK 0x0f7d14u
#define IE_PAULA_DISK_IRQ 0x0f7d18u
#define IE_PAULA_DISK_MASK 0x0f7d1cu
#define IE_PAULA_DISK_CTRL 0x0f7d20u
#define IE_PAULA_DISK_FEED 0x0f7d24u
#define IE_PAULA_DISK_WRITE 0x0f7d28u
#define IE_PAULA_DISK_RESET 0x0f7d2cu
#define IE_PAULA_DISK_STATE 0x0f7d30u
#define IE_PAULA_DISK_COMMAND 0x0f7d40u
#define IE_PAULA_DISK_SECTOR_BASE 0x0f7d44u
#define IE_PAULA_DISK_MFM_BASE 0x0f7d48u
#define IE_PAULA_DISK_TRACK 0x0f7d4cu
#define IE_PAULA_DISK_WORDS 0x0f7d50u
#define IE_PAULA_DISK_RESULT 0x0f7d54u
#define IE_PAULA_DISK_BAD 0x0f7d58u
#define IE_PAULA_DISK_SECTOR_MASK 0x0f7d5cu
#define IE_PAULA_DISK_SECTORS 0x0f7d60u
#define IE_PAULA_DISK_STATUS 0x0f7d64u
#define IE_PAULA_DISK_PORT 0x0f7d70u
#define IE_PAULA_DISK_LINES 0x0f7d74u
#define IE_PAULA_DISK_UNIT 0x0f7d78u
#define IE_PAULA_DISK_CYLINDERS 0x0f7d7cu
#define IE_PAULA_DISK_MEDIA 0x0f7d80u
#define IE_PAULA_DISK_DRIVE 0x0f7d84u

#define IE_PAULA_IO_BASE 0x0f7e00u
#define IE_PAULA_IO_INTREQ 0x0f7e00u
#define IE_PAULA_IO_INTENA 0x0f7e04u
#define IE_PAULA_IO_LEVEL 0x0f7e08u
#define IE_PAULA_IO_RESET 0x0f7e0cu
#define IE_PAULA_IO_SERDAT 0x0f7e10u
#define IE_PAULA_IO_SERPER 0x0f7e14u
#define IE_PAULA_IO_SERDATR 0x0f7e18u
#define IE_PAULA_IO_CLOCK 0x0f7e1cu
#define IE_PAULA_IO_RX 0x0f7e20u
#define IE_PAULA_IO_TX 0x0f7e24u
#define IE_PAULA_IO_TIME 0x0f7e28u
#define IE_PAULA_IO_ADKCON 0x0f7e2cu
#define IE_PAULA_IO_JOY0 0x0f7e30u
#define IE_PAULA_IO_JOY1 0x0f7e34u
#define IE_PAULA_IO_POT0 0x0f7e38u
#define IE_PAULA_IO_POT1 0x0f7e3cu
#define IE_PAULA_IO_POTGO 0x0f7e40u
#define IE_PAULA_IO_POTGOR 0x0f7e44u
#define IE_PAULA_IO_CIAOUT 0x0f7e48u
#define IE_PAULA_IO_CIABUTTONS 0x0f7e4cu
#define IE_PAULA_IO_PORTCONFIG 0x0f7e50u
#define IE_PAULA_IO_MOUSEX 0x0f7e54u
#define IE_PAULA_IO_MOUSEY 0x0f7e58u
#define IE_PAULA_IO_MOUSEDX 0x0f7e5cu
#define IE_PAULA_IO_MOUSEDY 0x0f7e60u
#define IE_PAULA_IO_MOUSEBUTTONS 0x0f7e64u
#define IE_PAULA_IO_PADSTATUS 0x0f7e68u
#define IE_PAULA_IO_PAD0BUTTONS 0x0f7e6cu
#define IE_PAULA_IO_PAD0AXES 0x0f7e70u
#define IE_PAULA_IO_PAD1BUTTONS 0x0f7e74u
#define IE_PAULA_IO_PAD1AXES 0x0f7e78u
#define IE_PAULA_IO_POLL 0x0f7e7cu
#define IE_PAULA_IO_SHIFTERS 0x0f7e80u
#define IE_PAULA_IO_PORTRESET 0x0f7e84u
#define IE_PAULA_IO_SERVICE 0x0f7e88u
#define IE_PAULA_IO_HOSTPOLL 0x0f7e8cu
#define IE_PAULA_IO_IRQCOUNT0 0x0f7e90u
#define IE_PAULA_IO_TRACE_CTRL 0x0f7ea0u
#define IE_PAULA_IO_TRACE_SEL 0x0f7ea4u
#define IE_PAULA_IO_TRACE_WHAT 0x0f7ea8u
#define IE_PAULA_IO_TRACE_VALUE 0x0f7eacu
#define IE_PAULA_IO_TRACE_RUNNING 0x504f5254u
#define IE_PAULA_IO_TRACE_ENTRIES 160u

#define IE_PAULA_BASE 0x0f0f80u
#define IE_PAULA_CHANNELS 4u
#define IE_PAULA_CHANNEL_STRIDE 0x10u
#define IE_PAULA_CHANNEL0_LOCATION 0x0f0f80u
#define IE_PAULA_CHANNEL0_LENGTH 0x0f0f84u
#define IE_PAULA_CHANNEL0_PERIOD 0x0f0f86u
#define IE_PAULA_CHANNEL0_VOLUME 0x0f0f88u
#define IE_PAULA_CHANNEL0_DATA 0x0f0f8au
#define IE_PAULA_CHANNEL1_LOCATION 0x0f0f90u
#define IE_PAULA_CHANNEL1_LENGTH 0x0f0f94u
#define IE_PAULA_CHANNEL1_PERIOD 0x0f0f96u
#define IE_PAULA_CHANNEL1_VOLUME 0x0f0f98u
#define IE_PAULA_CHANNEL1_DATA 0x0f0f9au
#define IE_PAULA_CHANNEL2_LOCATION 0x0f0fa0u
#define IE_PAULA_CHANNEL2_LENGTH 0x0f0fa4u
#define IE_PAULA_CHANNEL2_PERIOD 0x0f0fa6u
#define IE_PAULA_CHANNEL2_VOLUME 0x0f0fa8u
#define IE_PAULA_CHANNEL2_DATA 0x0f0faau
#define IE_PAULA_CHANNEL3_LOCATION 0x0f0fb0u
#define IE_PAULA_CHANNEL3_LENGTH 0x0f0fb4u
#define IE_PAULA_CHANNEL3_PERIOD 0x0f0fb6u
#define IE_PAULA_CHANNEL3_VOLUME 0x0f0fb8u
#define IE_PAULA_CHANNEL3_DATA 0x0f0fbau
#define IE_PAULA_DMA_CONTROL 0x0f0fc0u
#define IE_PAULA_MODULATION_CONTROL 0x0f0fc2u
#define IE_PAULA_INTERRUPT_REQUEST 0x0f0fc4u
#define IE_PAULA_INTERRUPT_ENABLE 0x0f0fc6u
#define IE_PAULA_CONTROL 0x0f0fc8u
#define IE_PAULA_DMA_CHANNEL0 0x1u
#define IE_PAULA_DMA_CHANNEL1 0x2u
#define IE_PAULA_DMA_CHANNEL2 0x4u
#define IE_PAULA_DMA_CHANNEL3 0x8u
#define IE_PAULA_DMA_ALL_CHANNELS 0xfu
#define IE_PAULA_DMA_MASTER_ENABLE 0x200u
#define IE_PAULA_MODULATION_PERIOD 0xfu
#define IE_PAULA_MODULATION_VOLUME 0xf0u
#define IE_PAULA_INTERRUPT_CHANNEL0 0x80u
#define IE_PAULA_INTERRUPT_CHANNEL1 0x100u
#define IE_PAULA_INTERRUPT_CHANNEL2 0x200u
#define IE_PAULA_INTERRUPT_CHANNEL3 0x400u
#define IE_PAULA_INTERRUPT_ALL 0x780u
#define IE_PAULA_CONTROL_FILTER 0x1u
#define IE_PAULA_CONTROL_NTSC 0x2u
#define IE_PAULA_VOLUME_MAX 64u
#define IE_PAULA_CLOCK_PAL 3546895u
#define IE_PAULA_CLOCK_NTSC 3579545u

/* --- ALICE BLOCK (generated from alice_constants.go) --- */
/* Alice: the Amiga blitter, copper and display DMA as a chip on the
 * bus at 0xF7000. Registers are little-endian and readable back, each
 * at its own address; a pointer is one 32-bit register and DMACON is
 * a plain read/write word. One access, one register: a longword write
 * sets only the register it names. A blit starts on the write that
 * covers the high byte of BLTSIZE or BLTSIZH. IE_ALICE_CTRL_WORDS_BE
 * makes the DMA words big-endian in guest RAM; IE_ALICE_DMA_MASK is
 * ANDed into every DMA address, and every masked address at or above
 * IE_ALICE_DMA_MARK (zero for none) counts in IE_ALICE_DMA_MARKED. */
#define IE_ALICE_BASE 0x0f7000u
#define IE_ALICE_REGION_END 0x0f71ffu
#define IE_ALICE_BLTCON0 0x0f7000u
#define IE_ALICE_BLTCON1 0x0f7002u
#define IE_ALICE_BLTAFWM 0x0f7004u
#define IE_ALICE_BLTALWM 0x0f7006u
#define IE_ALICE_BLTAPT 0x0f7008u
#define IE_ALICE_BLTBPT 0x0f700cu
#define IE_ALICE_BLTCPT 0x0f7010u
#define IE_ALICE_BLTDPT 0x0f7014u
#define IE_ALICE_BLTAMOD 0x0f7018u
#define IE_ALICE_BLTBMOD 0x0f701au
#define IE_ALICE_BLTCMOD 0x0f701cu
#define IE_ALICE_BLTDMOD 0x0f701eu
#define IE_ALICE_BLTADAT 0x0f7020u
#define IE_ALICE_BLTBDAT 0x0f7022u
#define IE_ALICE_BLTCDAT 0x0f7024u
#define IE_ALICE_BLTSIZE 0x0f7026u
#define IE_ALICE_BLTSIZV 0x0f7028u
#define IE_ALICE_BLTSIZH 0x0f702au
#define IE_ALICE_BLTCON0L 0x0f702cu
#define IE_ALICE_BLT_COUNT 0x0f7030u
#define IE_ALICE_BLT_REFUSED 0x0f7034u
#define IE_ALICE_BLT_LINES 0x0f7038u
#define IE_ALICE_CTRL 0x0f7080u
#define IE_ALICE_DMACON 0x0f7082u
#define IE_ALICE_INTREQ 0x0f7084u
#define IE_ALICE_INTENA 0x0f7086u
#define IE_ALICE_DMA_MASK 0x0f7088u
#define IE_ALICE_DMA_MARK 0x0f708cu
#define IE_ALICE_DMA_MARKED 0x0f7090u
#define IE_ALICE_SEL 0x0f70f8u
#define IE_ALICE_DATA 0x0f70fau
#define IE_ALICE_COP1LC 0x0f7100u
#define IE_ALICE_COP2LC 0x0f7104u
#define IE_ALICE_COPCON 0x0f7108u
#define IE_ALICE_COPJMP1 0x0f710au
#define IE_ALICE_COPJMP2 0x0f710cu
#define IE_ALICE_COP_STATE 0x0f710eu
#define IE_ALICE_COPPC 0x0f7110u
#define IE_ALICE_COP_IR 0x0f7114u
#define IE_ALICE_COP_RUN 0x0f7118u
#define IE_ALICE_COP_LINE 0x0f711cu
#define IE_ALICE_COP_BUDGET 0x0f711eu
#define IE_ALICE_COP_MOVES 0x0f7120u
#define IE_ALICE_COP_SKIPS 0x0f7124u
#define IE_ALICE_COP_JMP2S 0x0f7128u
#define IE_ALICE_COP_LAST 0x0f712cu
#define IE_ALICE_EV_COUNT 0x0f7130u
#define IE_ALICE_EV_SEL 0x0f7132u
#define IE_ALICE_EV_HPOS 0x0f7134u
#define IE_ALICE_EV_REG 0x0f7136u
#define IE_ALICE_EV_OLD 0x0f7138u
#define IE_ALICE_EV_NEW 0x0f713au
#define IE_ALICE_UNCL_POP 0x0f713cu
#define IE_ALICE_BPL1PT 0x0f7140u
#define IE_ALICE_BPL1MOD 0x0f7160u
#define IE_ALICE_BPL2MOD 0x0f7162u
#define IE_ALICE_DDFSTRT 0x0f7164u
#define IE_ALICE_DDFSTOP 0x0f7166u
#define IE_ALICE_FMODE 0x0f7168u
#define IE_ALICE_SPR0PT 0x0f7170u
#define IE_ALICE_BEAMCON0 0x0f7190u
#define IE_ALICE_VTOTAL 0x0f7192u
#define IE_ALICE_HTOTAL 0x0f7194u
#define IE_ALICE_VPOS 0x0f7196u
#define IE_ALICE_FIELD_LINES 0x0f7198u
#define IE_ALICE_LINE_CLKS 0x0f719au
#define IE_ALICE_FIELD_US 0x0f719cu
#define IE_ALICE_BEAM_FLAGS 0x0f71a0u
#define IE_ALICE_FIELD 0x0f71a2u
#define IE_ALICE_LINE 0x0f71a4u
#define IE_ALICE_FIELDS 0x0f71a8u
#define IE_ALICE_FETCH_LINES 0x0f71acu
#define IE_ALICE_FETCH_PIXELS 0x0f71b0u
#define IE_ALICE_SPR_FETCHES 0x0f71b4u
#define IE_ALICE_UNCL_COUNT 0x0f71b8u
#define IE_ALICE_CTRL_WORDS_BE 0x1u
#define IE_ALICE_DMACON_SPREN 0x20u
#define IE_ALICE_DMACON_BLTEN 0x40u
#define IE_ALICE_DMACON_COPEN 0x80u
#define IE_ALICE_DMACON_BPLEN 0x100u
#define IE_ALICE_DMACON_DMAEN 0x200u
#define IE_ALICE_DMACON_BLTPRI 0x400u
#define IE_ALICE_INT_COPER 0x10u
#define IE_ALICE_INT_VERTB 0x20u
#define IE_ALICE_INT_BLIT 0x40u
#define IE_ALICE_INT_ALL 0x70u
#define IE_ALICE_COP_WAITING 0x1u
#define IE_ALICE_COP_BLITWAIT 0x2u
#define IE_ALICE_COP_STOPPED 0x4u
#define IE_ALICE_COP_BUSY 0x8000u
#define IE_ALICE_BEAM_DOUBLED 0x1u
#define IE_ALICE_BEAM_NTSC 0x2u
/* --- END ALICE BLOCK --- */

/* --- LISA BLOCK (generated from lisa_constants.go) --- */
/* Lisa: the Amiga palette, playfield decode and sprites as a chip on
 * the bus at 0xF7400, the palette at 0xF7800. No DMA: the plane words
 * are written to the data ports, BPL1DAT last, and that write
 * serialises them at the lores position IE_LISA_BEAM holds; a line
 * is composed when it closes, and at FIELD_END the field goes to
 * the screen as Lisa's own, at the geometry it was composed at. */
#define IE_LISA_BASE 0x0f7400u
#define IE_LISA_PAL_BASE 0x0f7800u
#define IE_LISA_REGION_END 0x0f7bffu
#define IE_LISA_BPLCON0 0x0f7402u
#define IE_LISA_BPLCON1 0x0f7404u
#define IE_LISA_BPLCON2 0x0f7406u
#define IE_LISA_BPLCON3 0x0f7408u
#define IE_LISA_BPLCON4 0x0f740au
#define IE_LISA_DIWSTRT 0x0f740cu
#define IE_LISA_DIWSTOP 0x0f740eu
#define IE_LISA_DIWHIGH 0x0f7410u
#define IE_LISA_FMODE 0x0f7412u
#define IE_LISA_CLXCON 0x0f7414u
#define IE_LISA_CLXDAT 0x0f7416u
#define IE_LISA_BEAM 0x0f7418u
#define IE_LISA_STROBE 0x0f741cu
#define IE_LISA_LINE_LEN 0x0f741eu
#define IE_LISA_STATUS 0x0f7420u
#define IE_LISA_OUT_CTRL 0x0f7424u
#define IE_LISA_OUT_FIRST_LINE 0x0f7426u
#define IE_LISA_OUT_WIDTH 0x0f7428u
#define IE_LISA_OUT_HEIGHT 0x0f742au
#define IE_LISA_OVL_POS 0x0f742cu
#define IE_LISA_OVL_SIZE 0x0f7430u
#define IE_LISA_OVL_BASE 0x0f7434u
#define IE_LISA_FIELDS 0x0f7438u
#define IE_LISA_LINES 0x0f743cu
#define IE_LISA_PORT_WRITES 0x0f7440u
#define IE_LISA_LINE_WIDTH 0x0f7444u
#define IE_LISA_LINE_FETCHED 0x0f7448u
#define IE_LISA_SEL 0x0f744cu
#define IE_LISA_DATA 0x0f744eu
#define IE_LISA_BPL1DAT 0x0f7450u
#define IE_LISA_BPL2DAT 0x0f7454u
#define IE_LISA_BPL3DAT 0x0f7458u
#define IE_LISA_BPL4DAT 0x0f745cu
#define IE_LISA_BPL5DAT 0x0f7460u
#define IE_LISA_BPL6DAT 0x0f7464u
#define IE_LISA_BPL7DAT 0x0f7468u
#define IE_LISA_BPL8DAT 0x0f746cu
#define IE_LISA_SPR0POS 0x0f7470u
#define IE_LISA_SPR0CTL 0x0f7472u
#define IE_LISA_SPR0DATA 0x0f7474u
#define IE_LISA_SPR0DATB 0x0f7478u
#define IE_LISA_COLOR00 0x0f74d0u
#define IE_LISA_CLXCON2 0x0f7510u
#define IE_LISA_IDENT 0x0f7512u
#define IE_LISA_SPR_STRIDE 0xcu
#define IE_LISA_STROBE_LINE_END 0x1u
#define IE_LISA_STROBE_FIELD_BEGIN 0x2u
#define IE_LISA_STROBE_FIELD_END 0x3u
#define IE_LISA_OUT_PUBLISH 0x1u
#define IE_LISA_OUT_DOUBLED 0x2u
#define IE_LISA_OUT_OVERLAY 0x4u
#define IE_LISA_OUT_GENLOCK 0x8u
#define IE_LISA_LAYER 0xeu
#define IE_LISA_STATUS_INDEXABLE 0x1u
#define IE_LISA_STATUS_EHB 0x2u
#define IE_LISA_STATUS_COLOURS_MOVED 0x4u
#define IE_LISA_STATUS_LINE_OPEN 0x8u
#define IE_LISA_IDENT_AGA 0xf8u
#define IE_LISA_IDENT_ECS 0xfcu
#define IE_LISA_IDENT_OCS 0xffu
#define IE_LISA_PAL_KEY 0x80000000u
/* --- END LISA BLOCK --- */

#define IE_SID_BASE 0x0f0e00u
#define IE_SID_VOICE1_FREQUENCY_LOW 0x0f0e00u
#define IE_SID_VOICE1_CONTROL 0x0f0e04u
#define IE_SID_VOICE2_FREQUENCY_LOW 0x0f0e07u
#define IE_SID_VOICE2_CONTROL 0x0f0e0bu
#define IE_SID_VOICE3_FREQUENCY_LOW 0x0f0e0eu
#define IE_SID_VOICE3_CONTROL 0x0f0e12u
#define IE_SID_VOICE1_FREQUENCY_HIGH 0x0f0e01u
#define IE_SID_VOICE1_PULSE_WIDTH_LOW 0x0f0e02u
#define IE_SID_VOICE1_PULSE_WIDTH_HIGH 0x0f0e03u
#define IE_SID_VOICE1_ATTACK_DECAY 0x0f0e05u
#define IE_SID_VOICE1_SUSTAIN_RELEASE 0x0f0e06u
#define IE_SID_VOICE2_FREQUENCY_HIGH 0x0f0e08u
#define IE_SID_VOICE2_PULSE_WIDTH_LOW 0x0f0e09u
#define IE_SID_VOICE2_PULSE_WIDTH_HIGH 0x0f0e0au
#define IE_SID_VOICE2_ATTACK_DECAY 0x0f0e0cu
#define IE_SID_VOICE2_SUSTAIN_RELEASE 0x0f0e0du
#define IE_SID_VOICE3_FREQUENCY_HIGH 0x0f0e0fu
#define IE_SID_VOICE3_PULSE_WIDTH_LOW 0x0f0e10u
#define IE_SID_VOICE3_PULSE_WIDTH_HIGH 0x0f0e11u
#define IE_SID_VOICE3_ATTACK_DECAY 0x0f0e13u
#define IE_SID_VOICE3_SUSTAIN_RELEASE 0x0f0e14u
#define IE_SID_FILTER_CUTOFF_LOW 0x0f0e15u
#define IE_SID_FILTER_CUTOFF_HIGH 0x0f0e16u
#define IE_SID_FILTER_RESONANCE 0x0f0e17u
#define IE_SID_FILTER_MODE_VOLUME 0x0f0e18u
/* The four registers after the filter. Earlier headers named these as
 * modulation and mode controls, which they are not: SID+ is the enhanced
 * mode switch, the potentiometer is a backing register, and the last two
 * are the chip's read-only voice 3 taps. */
#define IE_SID_PLUS_CONTROL 0x0f0e19u
#define IE_SID_POT_Y 0x0f0e1au
#define IE_SID_OSC3 0x0f0e1bu
#define IE_SID_ENV3 0x0f0e1cu
#define IE_SID_END 0x0f0e1cu
/* The SID player: PTR, LEN, CTRL and STATUS as four longwords, the
 * protocol every register-mapped player shares, and a subsong byte. */
#define IE_SID_PLAY_POINTER 0x0f0e20u
#define IE_SID_PLAY_LENGTH 0x0f0e24u
#define IE_SID_PLAY_CONTROL 0x0f0e28u
#define IE_SID_PLAY_STATUS 0x0f0e2cu
#define IE_SID_SUBSONG 0x0f0e2du
/* SID2 and SID3: the same register layout as the first SID from each
 * base, on flex channels 4 to 6 and 7 to 9. */
#define IE_SID2_BASE 0x0f0e30u
#define IE_SID2_END 0x0f0e4cu
#define IE_SID3_BASE 0x0f0e50u
#define IE_SID3_END 0x0f0e6cu
#define IE_TED_AUDIO_BASE 0x0f0f00u
#define IE_TED_AUDIO_FREQUENCY1_LOW 0x0f0f00u
#define IE_TED_AUDIO_FREQUENCY2_LOW 0x0f0f01u
#define IE_TED_AUDIO_FREQUENCY2_HIGH 0x0f0f02u
#define IE_TED_AUDIO_CONTROL 0x0f0f03u
#define IE_TED_AUDIO_FREQUENCY1_HIGH 0x0f0f04u
#define IE_TED_AUDIO_PLUS_CONTROL 0x0f0f05u
/* The TED player, on the shared PTR, LEN, CTRL and STATUS protocol. */
#define IE_TED_PLAY_POINTER 0x0f0f10u
#define IE_TED_PLAY_LENGTH 0x0f0f14u
#define IE_TED_PLAY_CONTROL 0x0f0f18u
#define IE_TED_PLAY_STATUS 0x0f0f1cu
#define IE_TED_AUDIO_CONTROL_DIRECT_DAC 0x80u
#define IE_TED_AUDIO_CONTROL_VOICE2_NOISE 0x40u
#define IE_TED_AUDIO_CONTROL_VOICE2_ENABLE 0x20u
#define IE_TED_AUDIO_CONTROL_VOICE1_ENABLE 0x10u
#define IE_TED_AUDIO_CONTROL_VOLUME_MASK 0x0fu
#define IE_Z80_PSG_PORT_SELECT 0xf0u
#define IE_Z80_PSG_PORT_DATA 0xf1u
#define IE_Z80_POKEY_PORT_SELECT 0xd0u
#define IE_Z80_POKEY_PORT_DATA 0xd1u
#define IE_Z80_TED_AUDIO_PORT_SELECT 0xf2u
#define IE_Z80_TED_AUDIO_PORT_DATA 0xf3u
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_AHX_TARGET_BASE 0xfb80u
# define IE_MOD_TARGET_BASE 0xfbc0u
# define IE_WAV_TARGET_BASE 0xfbd8u
# define IE_PSG_TARGET_BASE 0xfc00u
# define IE_POKEY_TARGET_BASE 0xfd00u
# define IE_SID_TARGET_BASE 0xfe00u
# define IE_TED_AUDIO_TARGET_BASE 0xff00u
#else
# define IE_AHX_TARGET_BASE IE_AHX_BASE
# define IE_MOD_TARGET_BASE IE_MOD_PLAY_POINTER
# define IE_WAV_TARGET_BASE IE_WAV_PLAY_POINTER
# define IE_PSG_TARGET_BASE IE_PSG_BASE
# define IE_POKEY_TARGET_BASE IE_POKEY_BASE
# define IE_SID_TARGET_BASE IE_SID_BASE
# define IE_TED_AUDIO_TARGET_BASE IE_TED_AUDIO_BASE
#endif

/* Target access aliases for the player control blocks. */
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_AHX_TARGET_PLUS_CONTROL 0xfb80u
# define IE_AHX_TARGET_PLAY_POINTER 0xfb84u
# define IE_AHX_TARGET_PLAY_LENGTH 0xfb88u
# define IE_AHX_TARGET_PLAY_CONTROL 0xfb8cu
# define IE_AHX_TARGET_PLAY_STATUS 0xfb90u
# define IE_AHX_TARGET_SUBSONG 0xfb91u
# define IE_MOD_TARGET_PLAY_POINTER 0xfbc0u
# define IE_MOD_TARGET_PLAY_LENGTH 0xfbc4u
# define IE_MOD_TARGET_PLAY_CONTROL 0xfbc8u
# define IE_MOD_TARGET_PLAY_STATUS 0xfbccu
# define IE_MOD_TARGET_FILTER_MODEL 0xfbd0u
# define IE_MOD_TARGET_POSITION 0xfbd4u
# define IE_WAV_TARGET_PLAY_POINTER 0xfbd8u
# define IE_WAV_TARGET_PLAY_LENGTH 0xfbdcu
# define IE_WAV_TARGET_PLAY_CONTROL 0xfbe0u
# define IE_WAV_TARGET_PLAY_STATUS 0xfbe4u
# define IE_WAV_TARGET_CHANNEL_BASE 0xfbf0u
# define IE_WAV_TARGET_FLAGS 0xfbf3u
# define IE_PSG_TARGET_PLAY_POINTER 0xfc10u
# define IE_PSG_TARGET_PLAY_LENGTH 0xfc14u
# define IE_PSG_TARGET_PLAY_CONTROL 0xfc18u
# define IE_PSG_TARGET_PLUS_CONTROL 0xfc20u
#else
# define IE_AHX_TARGET_PLUS_CONTROL IE_AHX_PLUS_CONTROL
# define IE_AHX_TARGET_PLAY_POINTER IE_AHX_PLAY_POINTER
# define IE_AHX_TARGET_PLAY_LENGTH IE_AHX_PLAY_LENGTH
# define IE_AHX_TARGET_PLAY_CONTROL IE_AHX_PLAY_CONTROL
# define IE_AHX_TARGET_PLAY_STATUS IE_AHX_PLAY_STATUS
# define IE_AHX_TARGET_SUBSONG IE_AHX_SUBSONG
# define IE_MOD_TARGET_PLAY_POINTER IE_MOD_PLAY_POINTER
# define IE_MOD_TARGET_PLAY_LENGTH IE_MOD_PLAY_LENGTH
# define IE_MOD_TARGET_PLAY_CONTROL IE_MOD_PLAY_CONTROL
# define IE_MOD_TARGET_PLAY_STATUS IE_MOD_PLAY_STATUS
# define IE_MOD_TARGET_FILTER_MODEL IE_MOD_FILTER_MODEL
# define IE_MOD_TARGET_POSITION IE_MOD_POSITION
# define IE_WAV_TARGET_PLAY_POINTER IE_WAV_PLAY_POINTER
# define IE_WAV_TARGET_PLAY_LENGTH IE_WAV_PLAY_LENGTH
# define IE_WAV_TARGET_PLAY_CONTROL IE_WAV_PLAY_CONTROL
# define IE_WAV_TARGET_PLAY_STATUS IE_WAV_PLAY_STATUS
# define IE_WAV_TARGET_CHANNEL_BASE IE_WAV_CHANNEL_BASE
# define IE_WAV_TARGET_FLAGS IE_WAV_FLAGS
# define IE_PSG_TARGET_PLAY_POINTER IE_PSG_PLAY_POINTER
# define IE_PSG_TARGET_PLAY_LENGTH IE_PSG_PLAY_LENGTH
# define IE_PSG_TARGET_PLAY_CONTROL IE_PSG_PLAY_CONTROL
# define IE_PSG_TARGET_PLUS_CONTROL IE_PSG_PLUS_CONTROL
#endif

/* SFX trigger channels and SAP player controls. */
#define IE_SFX_CH_BASE 0x0f0e80u
#define IE_SFX_CH_STRIDE 0x20u
#define IE_SFX_LEGACY_CHANNELS 4u
#define IE_SFX_CHANNELS 32u
#define IE_SFX_CH0_BASE 0x0f0e80u
#define IE_SFX_CH1_BASE 0x0f0ea0u
#define IE_SFX_CH2_BASE 0x0f0ec0u
#define IE_SFX_CH3_BASE 0x0f0ee0u
#define IE_SFX_EXT_REGION_BASE 0x0f2600u
#define IE_SFX_EXT_REGION_END 0x0f29ffu
#define IE_SFX_EXT_CH_BASE 0x0f2600u
#define IE_SFX_EXT_CH0_BASE 0x0f2600u
#define IE_SFX_EXT_CH31_BASE 0x0f29e0u
#define IE_SFX_PTR 0x00u
#define IE_SFX_LEN 0x04u
#define IE_SFX_LOOP_PTR 0x08u
#define IE_SFX_LOOP_LEN 0x0cu
#define IE_SFX_FREQ 0x10u
#define IE_SFX_VOL 0x14u
#define IE_SFX_PAN_RESERVED 0x16u
#define IE_SFX_FORMAT 0x18u
#define IE_SFX_CTRL 0x1cu
#define IE_SFX_FORMAT_SIGNED8 0u
#define IE_SFX_FORMAT_UNSIGNED8 1u
#define IE_SFX_FORMAT_SIGNED16 2u
#define IE_SFX_CTRL_TRIGGER 0x01u
#define IE_SFX_CTRL_STOP 0x02u
#define IE_SFX_CTRL_LOOP_EN 0x04u
#define IE_SFX_STATUS_PLAYING 0x01u
#define IE_SFX_STATUS_ERROR 0x02u
#define IE_SAP_PLAY_PTR 0x0f0d10u
#define IE_SAP_PLAY_LEN 0x0f0d14u
#define IE_SAP_PLAY_CTRL 0x0f0d18u
#define IE_SAP_PLAY_STATUS 0x0f0d1cu
#define IE_SAP_SUBSONG 0x0f0d20u
#define IE_SN_BASE 0x0f0c30u
#define IE_SN_END 0x0f0c3fu
#define IE_SN_PORT_WRITE 0x0f0c30u
#define IE_SN_PORT_READY 0x0f0c31u
#define IE_SN_PORT_MODE 0x0f0c32u
#define IE_SN76489_MODE_LFSR_15 0u
#define IE_SN76489_MODE_LFSR_16 1u

/* --- SOUND ENGINE BLOCK ---
 * The engines share ten flex channels on fixed assignments, and two
 * engines told to play on the same channel overwrite each other's
 * registers. This is the table a guest arbitrates from: one index per
 * block, and the channels it drives as a mask over the ten. Paula holds
 * channels 0 to 3 while any of its channel bits is set in
 * IE_PAULA_DMA_CONTROL; an engine whose mask overlaps them is not
 * claimable until they clear. The SN76489 has voices of its own and the
 * MIDI synth mixes into the output, so both drive none of the ten. The
 * Go table these follow is amigaSoundEngines in amiga_sound.go. */
#define IE_SOUND_ENGINE_PSG 0u
#define IE_SOUND_ENGINE_SN 1u
#define IE_SOUND_ENGINE_SID1 2u
#define IE_SOUND_ENGINE_SID2 3u
#define IE_SOUND_ENGINE_SID3 4u
#define IE_SOUND_ENGINE_POKEY 5u
#define IE_SOUND_ENGINE_TED 6u
#define IE_SOUND_ENGINE_AHX 7u
#define IE_SOUND_ENGINE_MIDI 8u
#define IE_SOUND_ENGINE_MOD 9u
#define IE_SOUND_ENGINE_WAV 10u
#define IE_SOUND_ENGINE_COUNT 11u
#define IE_SOUND_CHANNELS_PSG 0x00fu
#define IE_SOUND_CHANNELS_SN 0x000u
#define IE_SOUND_CHANNELS_SID1 0x007u
#define IE_SOUND_CHANNELS_SID2 0x070u
#define IE_SOUND_CHANNELS_SID3 0x380u
#define IE_SOUND_CHANNELS_POKEY 0x00fu
#define IE_SOUND_CHANNELS_TED 0x003u
#define IE_SOUND_CHANNELS_AHX 0x00fu
#define IE_SOUND_CHANNELS_MIDI 0x000u
#define IE_SOUND_CHANNELS_MOD 0x00fu
#define IE_SOUND_CHANNELS_WAV 0x003u
#define IE_SOUND_CHANNELS_PAULA 0x00fu
/* The player protocol: from a block's PLAY_POINTER, four longwords. */
#define IE_SOUND_PLAY_POINTER_OFFSET 0x0u
#define IE_SOUND_PLAY_LENGTH_OFFSET 0x4u
#define IE_SOUND_PLAY_CONTROL_OFFSET 0x8u
#define IE_SOUND_PLAY_STATUS_OFFSET 0xcu
#define IE_SOUND_PLAY_CONTROL_START 0x1u
#define IE_SOUND_PLAY_CONTROL_STOP 0x2u
#define IE_SOUND_PLAY_CONTROL_LOOP 0x4u
#define IE_SOUND_PLAY_STATUS_BUSY 0x1u
#define IE_SOUND_PLAY_STATUS_ERROR 0x2u
/* --- END SOUND ENGINE BLOCK --- */

/* --- DISPLAY LAYER BLOCK ---
 * The compositor draws the displays in Z order, higher over lower.
 * Lisa publishes the Amiga field at 14 as an opaque frame, so the
 * layers under her show only while she is not publishing or has a
 * genlock attached; the ones over her show always. This is the table a
 * guest reads the stack from: one index per display, its Z, and flags
 * saying whether ielayers.library will hand it over, whether it is
 * over Lisa, and whether its memory is inside the aperture the Amiga's
 * register mirror republishes. VGA draws from a VRAM at $0A0000 that
 * the Amiga launch takes out of chip RAM, so it is not claimable; the
 * Voodoo's texture memory at $0D0000 is out of reach too, but it draws
 * flat triangles without it. The Go table these follow is
 * amigaDisplayLayers in amiga_layers.go. */
#define IE_DISPLAY_LAYER_VIDEO 0u
#define IE_DISPLAY_LAYER_VGA 1u
#define IE_DISPLAY_LAYER_TED 2u
#define IE_DISPLAY_LAYER_ANTIC 3u
#define IE_DISPLAY_LAYER_LISA 4u
#define IE_DISPLAY_LAYER_ULA 5u
#define IE_DISPLAY_LAYER_VOODOO 6u
#define IE_DISPLAY_LAYER_COUNT 7u
#define IE_DISPLAY_Z_VIDEO 0u
#define IE_DISPLAY_Z_VGA 10u
#define IE_DISPLAY_Z_TED 12u
#define IE_DISPLAY_Z_ANTIC 13u
#define IE_DISPLAY_Z_LISA 14u
#define IE_DISPLAY_Z_ULA 15u
#define IE_DISPLAY_Z_VOODOO 20u
#define IE_DISPLAY_FLAG_CLAIMABLE 0x1u
#define IE_DISPLAY_FLAG_ABOVE_LISA 0x2u
#define IE_DISPLAY_FLAG_MEMORY_REACHABLE 0x4u
#define IE_DISPLAY_FLAGS_VIDEO 0x0u
#define IE_DISPLAY_FLAGS_VGA 0x0u
#define IE_DISPLAY_FLAGS_TED 0x5u
#define IE_DISPLAY_FLAGS_ANTIC 0x1u
#define IE_DISPLAY_FLAGS_LISA 0x0u
#define IE_DISPLAY_FLAGS_ULA 0x7u
#define IE_DISPLAY_FLAGS_VOODOO 0x3u
/* --- END DISPLAY LAYER BLOCK --- */
#define IE_Z80_SN_PORT_DATA 0xe4u
#define IE_Z80_SN_PORT_STATUS 0xe5u
#if defined(IE_TARGET_6502)
# define IE_SFX_TARGET_CH_BASE 0xfe80u
# define IE_SFX_TARGET_EXT_BANK 0x79u
# define IE_SFX_TARGET_EXT_WINDOW_BASE 0x2600u
# define IE_SFX_TARGET_EXT_WINDOW_END 0x29ffu
# define IE_SN_TARGET_PORT_WRITE 0xfc30u
# define IE_SN_TARGET_PORT_READY 0xfc31u
# define IE_SN_TARGET_PORT_MODE 0xfc32u
#elif defined(IE_TARGET_Z80)
# define IE_SFX_TARGET_CH_BASE IE_SFX_CH_BASE
# define IE_SFX_TARGET_EXT_BANK 0x79u
# define IE_SFX_TARGET_EXT_WINDOW_BASE 0x2600u
# define IE_SFX_TARGET_EXT_WINDOW_END 0x29ffu
# define IE_SN_TARGET_PORT_WRITE IE_SN_PORT_WRITE
# define IE_SN_TARGET_PORT_READY IE_SN_PORT_READY
# define IE_SN_TARGET_PORT_MODE IE_SN_PORT_MODE
#else
# define IE_SFX_TARGET_CH_BASE IE_SFX_CH_BASE
# define IE_SN_TARGET_PORT_WRITE IE_SN_PORT_WRITE
# define IE_SN_TARGET_PORT_READY IE_SN_PORT_READY
# define IE_SN_TARGET_PORT_MODE IE_SN_PORT_MODE
#endif

/* Input, clock and gamepad blocks. Eight-bit targets use bank 1 aliases. */
#define IE_GAMEPAD_REGION_BASE 0x0f25c0u
#define IE_GAMEPAD_REGION_END 0x0f25ffu
#define IE_GAMEPAD_STATUS 0x0f25c0u
#define IE_GAMEPAD_PAD0_BASE 0x0f25d0u
#define IE_GAMEPAD_PAD_STRIDE 0x0cu
#define IE_GAMEPAD_BUTTONS_OFFSET 0x00u
#define IE_GAMEPAD_LEFT_AXIS_OFFSET 0x04u
#define IE_GAMEPAD_RIGHT_AXIS_OFFSET 0x08u
#define IE_GAMEPAD_IO_BANK 0x79u
#define IE_JOY_UP 0x00000001u
#define IE_JOY_DOWN 0x00000002u
#define IE_JOY_LEFT 0x00000004u
#define IE_JOY_RIGHT 0x00000008u
#define IE_JOY_A 0x00000010u
#define IE_JOY_B 0x00000020u
#define IE_JOY_X 0x00000040u
#define IE_JOY_Y 0x00000080u
#define IE_JOY_LB 0x00000100u
#define IE_JOY_RB 0x00000200u
#define IE_JOY_LT 0x00000400u
#define IE_JOY_RT 0x00000800u
#define IE_JOY_SELECT 0x00001000u
#define IE_JOY_START 0x00002000u
#define IE_JOY_L3 0x00004000u
#define IE_JOY_R3 0x00008000u
#define IE_JOY_HOME 0x00010000u
#define IE_GAMEPAD_BUTTONS_OFF IE_GAMEPAD_BUTTONS_OFFSET
#define IE_GAMEPAD_AXIS_LXY_OFF IE_GAMEPAD_LEFT_AXIS_OFFSET
#define IE_GAMEPAD_AXIS_RXY_OFF IE_GAMEPAD_RIGHT_AXIS_OFFSET
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_TERM_IO_BANK 0x78u
# define IE_HOST_SOCKET_BANK 0x79u
# define IE_INPUT_TERM_OUT_TARGET 0x2700u
# define IE_INPUT_TERM_STATUS_TARGET 0x2704u
# define IE_INPUT_TERM_IN_TARGET 0x2708u
# define IE_INPUT_SCAN_CODE_TARGET 0x2740u
# define IE_INPUT_SCAN_STATUS_TARGET 0x2744u
# define IE_INPUT_SCAN_MODIFIERS_TARGET 0x2748u
# define IE_INPUT_RTC_EPOCH_TARGET 0x2750u
# define IE_GAMEPAD_STATUS_TARGET 0x25c0u
# define IE_GAMEPAD_PAD0_TARGET 0x25d0u
#else
# define IE_INPUT_TERM_OUT_TARGET IE_INPUT_TERM_OUT
# define IE_INPUT_TERM_STATUS_TARGET IE_INPUT_TERM_STATUS
# define IE_INPUT_TERM_IN_TARGET IE_INPUT_TERM_IN
# define IE_INPUT_SCAN_CODE_TARGET IE_INPUT_SCAN_CODE
# define IE_INPUT_SCAN_STATUS_TARGET IE_INPUT_SCAN_STATUS
# define IE_INPUT_SCAN_MODIFIERS_TARGET IE_INPUT_SCAN_MODIFIERS
# define IE_INPUT_RTC_EPOCH_TARGET IE_SYSTEM_RTC_EPOCH
# define IE_GAMEPAD_STATUS_TARGET IE_GAMEPAD_STATUS
# define IE_GAMEPAD_PAD0_TARGET IE_GAMEPAD_PAD0_BASE
#endif
#define IE_FILE_BASE 0x0f2200u
#define IE_FILE_END 0x0f221fu
#define IE_FILE_NAME_POINTER 0x0f2200u
#define IE_FILE_DATA_POINTER 0x0f2204u
#define IE_FILE_DATA_LENGTH 0x0f2208u
#define IE_FILE_CONTROL 0x0f220cu
#define IE_FILE_STATUS 0x0f2210u
#define IE_FILE_RESULT_LENGTH 0x0f2214u
#define IE_FILE_ERROR_CODE 0x0f2218u
#define IE_FILE_READ_MAX 0x0f221cu
#define IE_FILE_DATA_POINTER64 0x0f22b0u
#define IE_FILE_DATA_POINTER64_END 0x0f22b7u
#define IE_FILE_OP_READ 0x01u
#define IE_FILE_OP_WRITE 0x02u
#define IE_FILE_OP_LIST 0x03u
#define IE_FILE_ERROR_OK 0x00u
#define IE_FILE_ERROR_NOT_FOUND 0x01u
#define IE_FILE_ERROR_PERMISSION 0x02u
#define IE_FILE_ERROR_PATH_TRAVERSAL 0x03u
#define IE_FILE_ERROR_RANGE 0x04u
#define IE_FILE_NAME_PTR IE_FILE_NAME_POINTER
#define IE_FILE_DATA_PTR IE_FILE_DATA_POINTER
#define IE_FILE_DATA_LEN IE_FILE_DATA_LENGTH
#define IE_FILE_CTRL IE_FILE_CONTROL
#define IE_FILE_RESULT_LEN IE_FILE_RESULT_LENGTH
#define IE_FILE_ERROR IE_FILE_ERROR_CODE
#define IE_COPROC_BASE 0x0f2340u
#define IE_COPROC_END 0x0f238fu
#define IE_COPROC_COMMAND 0x0f2340u
#define IE_COPROC_CPU_TYPE 0x0f2344u
#define IE_COPROC_COMMAND_STATUS 0x0f2348u
#define IE_COPROC_COMMAND_ERROR 0x0f234cu
#define IE_COPROC_TICKET 0x0f2350u
#define IE_COPROC_TICKET_STATUS 0x0f2354u
#define IE_COPROC_OPERATION 0x0f2358u
#define IE_COPROC_REQUEST_POINTER 0x0f235cu
#define IE_COPROC_REQUEST_LENGTH 0x0f2360u
#define IE_COPROC_RESPONSE_POINTER 0x0f2364u
#define IE_COPROC_RESPONSE_CAPACITY 0x0f2368u
#define IE_COPROC_TIMEOUT 0x0f236cu
#define IE_COPROC_NAME_POINTER 0x0f2370u
#define IE_COPROC_WORKER_STATE 0x0f2374u
#define IE_COPROC_STATS_OPERATIONS 0x0f2378u
#define IE_COPROC_STATS_BYTES 0x0f237cu
#define IE_COPROC_IRQ_CONTROL 0x0f2380u
#define IE_COPROC_DISPATCH_OVERHEAD 0x0f2384u
#define IE_COPROC_COMPLETED_TICKET 0x0f2388u
#define IE_COPROC_INSTANCE 0x0f238cu
#define IE_COPROC_EXT_BASE 0x0f23b0u
#define IE_COPROC_RING_DEPTH 0x0f23b0u
#define IE_COPROC_WORKER_UPTIME 0x0f23b4u
#define IE_COPROC_STATS_RESET 0x0f23b8u
#define IE_COPROC_BUSY_PERCENT 0x0f23bcu
#define IE_COPROC_EXT_END 0x0f23bfu
#define IE_COPROC_EXT2_BASE 0x0f25a0u
#define IE_COPROC_INSTANCE_LIMIT 0x0f25a0u
#define IE_COPROC_SELECTED_STATE 0x0f25a4u
#define IE_COPROC_MAILBOX_VERSION 0x0f25a8u
#define IE_COPROC_WORKER_BASE 0x0f25acu
#define IE_COPROC_WORKER_END 0x0f25b0u
#define IE_COPROC_WORKER_RING 0x0f25b4u
#define IE_COPROC_INSTANCE_STATE 0x0f25b8u
#define IE_COPROC_DATA_DESC 0x0f25bcu
#define IE_COPROC_DATA_ORDER_NONE 0x00u
#define IE_COPROC_DATA_ORDER_LE 0x01u
#define IE_COPROC_DATA_ORDER_BE 0x02u
#define IE_COPROC_EXT2_END 0x0f25bfu
#define IE_COPROC_COMMAND_START 0x01u
#define IE_COPROC_COMMAND_STOP 0x02u
#define IE_COPROC_COMMAND_ENQUEUE 0x03u
#define IE_COPROC_COMMAND_POLL 0x04u
#define IE_COPROC_COMMAND_WAIT 0x05u
#define IE_COPROC_COMMAND_START_MEMORY 0x06u
#define IE_COPROC_CMD IE_COPROC_COMMAND
#define IE_COPROC_OP IE_COPROC_OPERATION
#define IE_COPROC_REQ_PTR IE_COPROC_REQUEST_POINTER
#define IE_COPROC_REQ_LEN IE_COPROC_REQUEST_LENGTH
#define IE_COPROC_RESP_PTR IE_COPROC_RESPONSE_POINTER
#define IE_COPROC_RESP_CAP IE_COPROC_RESPONSE_CAPACITY
#define IE_COPROC_STATUS_OK 0x00u
#define IE_COPROC_STATUS_ERROR 0x01u
#define IE_COPROC_TICKET_PENDING 0x00u
#define IE_COPROC_TICKET_RUNNING 0x01u
#define IE_COPROC_TICKET_OK 0x02u
#define IE_COPROC_TICKET_ERROR 0x03u
#define IE_COPROC_TICKET_TIMEOUT 0x04u
#define IE_COPROC_TICKET_WORKER_DOWN 0x05u
#define IE_COPROC_IRQ_ENABLE 0x01u
#define IE_COPROC_IRQ_PENDING 0x02u
#define IE_COPROC_GATEWAY_BASE 0xf200u
#define IE_COPROC_GATEWAY_END 0xf24fu
#define IE_EXEC_NAME_POINTER 0x0f2320u
#define IE_EXEC_CONTROL 0x0f2324u
#define IE_EXEC_STATUS 0x0f2328u
#define IE_EXEC_TYPE 0x0f232cu
#define IE_EXEC_ERROR 0x0f2330u
#define IE_EXEC_SESSION 0x0f2334u
#define IE_EXEC_END 0x0f233fu
#define IE_EXEC_OP_EXECUTE 0x01u
#define IE_EXEC_OP_EMUTOS 0x02u
#define IE_EXEC_OP_AROS 0x03u
#define IE_EXEC_OP_IEXEC 0x04u
#define IE_EXEC_OP_HARD_RESET 0x05u
#define IE_EXEC_OP_AMIGA 0x06u
#define IE_EXEC_STATUS_IDLE 0x00u
#define IE_EXEC_STATUS_LOADING 0x01u
#define IE_EXEC_STATUS_RUNNING 0x02u
#define IE_EXEC_STATUS_ERROR 0x03u
#define IE_EXEC_TYPE_NONE 0x00u
#define IE_EXEC_TYPE_IE32 0x01u
#define IE_EXEC_TYPE_IE64 0x02u
#define IE_EXEC_TYPE_6502 0x03u
#define IE_EXEC_TYPE_M68K 0x04u
#define IE_EXEC_TYPE_Z80 0x05u
#define IE_EXEC_TYPE_X86 0x06u
#define IE_EXEC_TYPE_EMUTOS 0x07u
#define IE_EXEC_TYPE_SCRIPT 0x08u
#define IE_EXEC_TYPE_AROS 0x09u
#define IE_EXEC_TYPE_IEXEC 0x0au
#define IE_EXEC_TYPE_AMIGA 0x0bu
#define IE_EXEC_TYPE_PPC 0x0cu
#define IE_EXEC_ERROR_OK 0x00u
#define IE_EXEC_ERROR_NOT_FOUND 0x01u
#define IE_EXEC_ERROR_UNSUPPORTED 0x02u
#define IE_EXEC_ERROR_PATH_INVALID 0x03u
#define IE_EXEC_ERROR_LOAD_FAILED 0x04u
#define IE_EXEC_NAME_PTR IE_EXEC_NAME_POINTER
#define IE_EXEC_CTRL IE_EXEC_CONTROL
#define IE_EXEC_ERR IE_EXEC_ERROR
#define IE_EXEC_ERR_OK IE_EXEC_ERROR_OK
#define IE_EXEC_ERR_NOT_FOUND IE_EXEC_ERROR_NOT_FOUND
#define IE_EXEC_ERR_UNSUPPORTED IE_EXEC_ERROR_UNSUPPORTED
#define IE_EXEC_ERR_PATH_INVALID IE_EXEC_ERROR_PATH_INVALID
#define IE_EXEC_ERR_LOAD_FAILED IE_EXEC_ERROR_LOAD_FAILED
#define IE_VOODOO_BASE 0x0f8000u
#define IE_VOODOO_END 0x0f87ffu
#define IE_VOODOO_STATUS 0x0f8000u
#define IE_VOODOO_ENABLE 0x0f8004u
#define IE_VOODOO_VERTEX_AX 0x0f8008u
#define IE_VOODOO_VERTEX_AY 0x0f800cu
#define IE_VOODOO_VERTEX_BX 0x0f8010u
#define IE_VOODOO_VERTEX_BY 0x0f8014u
#define IE_VOODOO_VERTEX_CX 0x0f8018u
#define IE_VOODOO_VERTEX_CY 0x0f801cu
#define IE_VOODOO_TRIANGLE_COMMAND 0x0f8080u
#define IE_VOODOO_FAST_FILL_COMMAND 0x0f8124u
#define IE_VOODOO_SWAP_BUFFER_COMMAND 0x0f8128u
#define IE_VOODOO_TEXTURE_MODE 0x0f8300u
#define IE_VOODOO_TEXTURE_BASE0 0x0f830cu
#define IE_VOODOO_TEXTURE_WIDTH 0x0f8330u
#define IE_VOODOO_TEXTURE_HEIGHT 0x0f8334u
#define IE_VOODOO_TRIANGLE_CMD IE_VOODOO_TRIANGLE_COMMAND
#define IE_VOODOO_FAST_FILL_CMD IE_VOODOO_FAST_FILL_COMMAND
#define IE_VOODOO_SWAP_BUFFER_CMD IE_VOODOO_SWAP_BUFFER_COMMAND
#define IE_VOODOO_TEX_MODE IE_VOODOO_TEXTURE_MODE
#define IE_VOODOO_TEX_BASE0 IE_VOODOO_TEXTURE_BASE0
#define IE_VOODOO_COLOR_SELECT 0x0f8088u
#define IE_VOODOO_FBZCOLOR_PATH 0x0f8104u
#define IE_VOODOO_NOP_CMD 0x0f8120u
#define IE_VOODOO_VIDEO_DIM 0x0f8214u
#define IE_VOODOO_TEX_SRC_PTR 0x0f8348u
#define IE_VOODOO_TEX_SRC_BYTES 0x0f834cu
#define IE_VOODOO_TEX_SLOT 0x0f8350u
#define IE_VOODOO_TEX_BIND 0x0f8354u
#define IE_VOODOO_TEX_SLOT_NONE 0xffffffffu
#define IE_VOODOO_COMMAND_POINTER 0x0f833cu
#define IE_VOODOO_COMMAND_COUNT 0x0f8340u
#define IE_VOODOO_COMMAND_SUBMIT 0x0f8344u
#define IE_VOODOO_COMMAND_SUBMIT_REPLAY 0x00000001u
#define IE_VOODOO_COMMAND_SUBMIT_REPLAY_LE 0x00000002u
#define IE_VOODOO_STATUS_FBI_BUSY 0x01u
#define IE_VOODOO_STATUS_TMU_BUSY 0x02u
#define IE_VOODOO_STATUS_SST_BUSY 0x04u
#define IE_VOODOO_STATUS_VRETRACE 0x40u
#define IE_VOODOO_STATUS_SWAPBUF 0x80u
#define IE_VOODOO_FBZ_CLIPPING 0x0001u
#define IE_VOODOO_FBZ_CHROMAKEY 0x0002u
#define IE_VOODOO_FBZ_DEPTH_ENABLE 0x0010u
#define IE_VOODOO_FBZ_DEPTH_FUNC 0x00e0u
#define IE_VOODOO_FBZ_RGB_WRITE 0x0200u
#define IE_VOODOO_FBZ_DEPTH_WRITE 0x0400u
#define IE_VOODOO_ALPHA_TEST_EN 0x0001u
#define IE_VOODOO_ALPHA_FUNC_MASK 0x000eu
#define IE_VOODOO_ALPHA_FUNC_SHIFT 1u
#define IE_VOODOO_ALPHA_BLEND_EN 0x0010u
#define IE_VOODOO_ALPHA_SRC_RGB 0x0f00u
#define IE_VOODOO_ALPHA_DST_RGB 0xf000u
#define IE_VOODOO_ALPHA_REF_SHIFT 24u
#define IE_VOODOO_SWAP_VSYNC 0x01u
#define IE_VOODOO_SWAP_CLEAR 0x02u
#define IE_VOODOO_TEX_ENABLE 0x0001u
#define IE_VOODOO_TEX_MINIFY 0x000eu
#define IE_VOODOO_TEX_MAGNIFY 0x0010u
#define IE_VOODOO_TEX_CLAMP_S 0x0020u
#define IE_VOODOO_TEX_CLAMP_T 0x0040u
#define IE_VOODOO_TEX_PERSPECTIVE 0x4000u
#define IE_VOODOO_TEX_MIN_LINEAR 0x0002u
#define IE_VOODOO_TEX_MIPMAP 0x0004u
#define IE_VOODOO_TEX_TRILINEAR 0x2000u
#define IE_VOODOO_TEX_FORMAT 0x0f00u
#define IE_VOODOO_TEX_FORMAT_SHIFT 0x08u
#define IE_VOODOO_TEX_FMT_PALETTE 0u
#define IE_VOODOO_TEX_FMT_P8 5u
#define IE_VOODOO_TEX_FMT_ARGB1555 8u
#define IE_VOODOO_TEX_FMT_ARGB4444 9u
#define IE_VOODOO_TEX_FMT_ARGB8888 10u
#define IE_VOODOO_COMBINE_TEXTURE 0x01u
#define IE_VOODOO_COMBINE_MODULATE 0x61u
#define IE_VOODOO_COMBINE_DECAL 0x41u
#define IE_VOODOO_COMBINE_BLEND 0x91u
#define IE_VOODOO_CLIP_MASK 0xffffu
#define IE_VOODOO_FIXED_12_4 4u
#define IE_VOODOO_FIXED_12_12 12u
#define IE_VOODOO_START_R 0x0f8020u
#define IE_VOODOO_START_G 0x0f8024u
#define IE_VOODOO_START_B 0x0f8028u
#define IE_VOODOO_START_Z 0x0f802cu
#define IE_VOODOO_START_A 0x0f8030u
#define IE_VOODOO_START_S 0x0f8034u
#define IE_VOODOO_START_T 0x0f8038u
#define IE_VOODOO_START_W 0x0f803cu
#define IE_VOODOO_DRDX 0x0f8040u
#define IE_VOODOO_DGDX 0x0f8044u
#define IE_VOODOO_DBDX 0x0f8048u
#define IE_VOODOO_DZDX 0x0f804cu
#define IE_VOODOO_DADX 0x0f8050u
#define IE_VOODOO_DSDX 0x0f8054u
#define IE_VOODOO_DTDX 0x0f8058u
#define IE_VOODOO_DWDX 0x0f805cu
#define IE_VOODOO_DRDY 0x0f8060u
#define IE_VOODOO_DGDY 0x0f8064u
#define IE_VOODOO_DBDY 0x0f8068u
#define IE_VOODOO_DZDY 0x0f806cu
#define IE_VOODOO_DADY 0x0f8070u
#define IE_VOODOO_DSDY 0x0f8074u
#define IE_VOODOO_DTDY 0x0f8078u
#define IE_VOODOO_DWDY 0x0f807cu
#define IE_VOODOO_FTRIANGLE_COMMAND 0x0f8084u
#define IE_VOODOO_COLOUR_SELECT 0x0f8088u
#define IE_VOODOO_FBZ_COLOUR_PATH 0x0f8104u
#define IE_VOODOO_FOG_MODE 0x0f8108u
#define IE_VOODOO_ALPHA_MODE 0x0f810cu
#define IE_VOODOO_FBZ_MODE 0x0f8110u
#define IE_VOODOO_LFB_MODE 0x0f8114u
#define IE_VOODOO_CLIP_LEFT_RIGHT 0x0f8118u
#define IE_VOODOO_CLIP_LOW_Y_HIGH 0x0f811cu
#define IE_VOODOO_NOP_COMMAND 0x0f8120u
#define IE_VOODOO_FOG_TABLE_BASE 0x0f8140u
#define IE_VOODOO_FOG_COLOUR 0x0f81c4u
#define IE_VOODOO_ZA_COLOUR 0x0f81c8u
#define IE_VOODOO_CHROMA_KEY 0x0f81ccu
#define IE_VOODOO_CHROMA_RANGE 0x0f81d0u
#define IE_VOODOO_STIPPLE 0x0f81d4u
#define IE_VOODOO_COLOUR0 0x0f81d8u
#define IE_VOODOO_COLOUR1 0x0f81dcu
#define IE_VOODOO_FBI_INIT0 0x0f8200u
#define IE_VOODOO_FBI_INIT1 0x0f8204u
#define IE_VOODOO_FBI_INIT2 0x0f8208u
#define IE_VOODOO_FBI_INIT3 0x0f820cu
#define IE_VOODOO_FBI_INIT4 0x0f8210u
#define IE_VOODOO_VIDEO_DIMENSIONS 0x0f8214u
#define IE_VOODOO_BACK_PORCH 0x0f8218u
#define IE_VOODOO_VIDEO_DIMENSIONS_VERTICAL 0x0f821cu
#define IE_VOODOO_H_SYNC 0x0f8220u
#define IE_VOODOO_V_SYNC 0x0f8224u
#define IE_VOODOO_DAC_DATA 0x0f822cu
#define IE_VOODOO_TLOD 0x0f8304u
#define IE_VOODOO_TDETAIL 0x0f8308u
#define IE_VOODOO_TEXTURE_BASE1 0x0f8310u
#define IE_VOODOO_TEXTURE_BASE2 0x0f8314u
#define IE_VOODOO_TEXTURE_BASE3 0x0f8318u
#define IE_VOODOO_TEXTURE_BASE4 0x0f831cu
#define IE_VOODOO_TEXTURE_BASE5 0x0f8320u
#define IE_VOODOO_TEXTURE_BASE6 0x0f8324u
#define IE_VOODOO_TEXTURE_BASE7 0x0f8328u
#define IE_VOODOO_TEXTURE_BASE8 0x0f832cu
#define IE_VOODOO_TEXTURE_UPLOAD 0x0f8338u
#define IE_VOODOO_TEXTURE_SOURCE_POINTER 0x0f8348u
#define IE_VOODOO_TEXTURE_SOURCE_BYTES 0x0f834cu
#define IE_VOODOO_TEXTURE_SLOT 0x0f8350u
#define IE_VOODOO_TEXTURE_BIND 0x0f8354u
#define IE_VOODOO_SWAP_HASH_SEQUENCE 0x0f8358u
#define IE_VOODOO_SWAP_HASH_QUERY 0x0f835cu
#define IE_VOODOO_SWAP_HASH_VALUE 0x0f8360u
/* The guest draw target.
 *
 * The chip's own output is a compositor layer, which is the whole
 * display. A retargetable graphics system is the other case: the
 * application allocates a bitmap out of the graphics board's memory,
 * hands it to the 3D library, and the graphics system displays that
 * bitmap wherever the window is. Nothing on the layer path can serve
 * that, because the frame never reaches anywhere the guest can address.
 *
 * With a target enabled, every presented frame is also written to
 * IE_VOODOO_DRAW_BASE, one row at a time at IE_VOODOO_DRAW_STRIDE, so a
 * bitmap whose rows are padded is written correctly. A target that runs
 * off the end of guest memory writes nothing at all rather than the
 * part that fitted.
 *
 * IE_VOODOO_DRAW_FMT_R8G8B8A8 is the four bytes red, green, blue, alpha
 * at increasing addresses. That is what the rasteriser produces and
 * what the board driver offers, so the copy is bytes as they stand and
 * nothing here is byte-swapped on any host.
 */
#define IE_VOODOO_DRAW_BASE 0x0f8370u
#define IE_VOODOO_DRAW_STRIDE 0x0f8374u
#define IE_VOODOO_DRAW_FORMAT 0x0f8378u
#define IE_VOODOO_DRAW_CTRL 0x0f837cu
#define IE_VOODOO_DRAW_CTRL_ENABLE 0x1u
#define IE_VOODOO_DRAW_CTRL_LOAD 0x2u
#define IE_VOODOO_DRAW_FMT_R8G8B8A8 0x0u
/* The sixteen-bit layouts, low byte first as on a PCI bus; the same as
 * IE_VIDEO_COLOR_MODE_R5G6B5 and _R5G5B5. */
#define IE_VOODOO_DRAW_FMT_R5G6B5 0x1u
#define IE_VOODOO_DRAW_FMT_R5G5B5 0x2u
/* Per-vertex fog: written per vertex like the colour (COLOUR_SELECT picks
 * the vertex), 12.12 with 1.0 all fog, used when the fog mode has
 * IE_VOODOO_FOG_ITERATED. */
#define IE_VOODOO_START_FOG 0x0f8380u
#define IE_VOODOO_FOG_ENABLE 0x01u
#define IE_VOODOO_FOG_ZONES 0x40u
#define IE_VOODOO_FOG_ITERATED 0x80u
/* The constant colour, ARGB, that the CONST_* blend factors read. */
#define IE_VOODOO_BLEND_CONST 0x0f8384u
#define IE_VOODOO_BLEND_CONST_COLOUR 8u
#define IE_VOODOO_BLEND_INV_CONST_COLOUR 9u
#define IE_VOODOO_BLEND_CONST_ALPHA 10u
#define IE_VOODOO_BLEND_INV_CONST_ALPHA 11u
/* The chip lock, for drivers on two processors programming the chip at
 * once. An owner is any value from 1 to 0x7FFFFFFF. Writing an owner to
 * IE_VOODOO_LOCK takes the lock if it is free and is ignored while
 * another owner holds it, so the writer reads it back to learn whether
 * it won; writing the holder with IE_VOODOO_LOCK_RELEASE set gives it
 * up, and a release naming anyone else is ignored. IE_VOODOO_LOCK reads
 * as the holder, 0 while free. IE_VOODOO_LOCK_LAST reads as the owner
 * that held the lock before the current one (the last holder while it
 * is free, 0 since a chip reset), and ignores writes. A chip reset frees
 * the lock. */
#define IE_VOODOO_LOCK 0x0f8388u
#define IE_VOODOO_LOCK_LAST 0x0f838cu
#define IE_VOODOO_LOCK_RELEASE 0x80000000u
/* fbzMode: depth from W (eye distance 1/W over 65536), and the signed
 * 12-bit depth offset in bits 31:20, in steps of 1/65536. */
#define IE_VOODOO_FBZ_WBUFFER 0x0008u
#define IE_VOODOO_FBZ_DEPTH_OFFSET_SHIFT 20u
/* TLOD: minimum, maximum and signed bias of the level of detail, six bits
 * each counting quarter levels. */
#define IE_VOODOO_TLOD_MIN_SHIFT 0u
#define IE_VOODOO_TLOD_MAX_SHIFT 6u
#define IE_VOODOO_TLOD_BIAS_SHIFT 12u
/* IE_VOODOO_TEXTURE_UPLOAD's bits 11:8: the mipmap level uploaded, 0 the
 * texture itself. TEXTURE_WIDTH and HEIGHT are that level's size. */
#define IE_VOODOO_TEX_UPLOAD_LEVEL_SHIFT 8u
/* The rest of the chip's constants, as voodoo_constants.go has them:
 * comparison functions, blend factors, the colour combine fields, the
 * fbzMode, fog and texture bits, the texture formats and the fixed-point
 * shifts. sdk_header_parity_test.go holds every IE_VOODOO_ name here to the
 * engine. */
#define IE_VOODOO_DEFAULT_WIDTH 0x280u
#define IE_VOODOO_DEFAULT_HEIGHT 0x1e0u
#define IE_VOODOO_MAX_WIDTH 0x320u
#define IE_VOODOO_MAX_HEIGHT 0x258u
#define IE_VOODOO_STATUS_MEMFIFO 0xff000u
#define IE_VOODOO_STATUS_PCIFIFO 0x1f00000u
#define IE_VOODOO_PALETTE_SIZE 0x100u
#define IE_VOODOO_CMD_STREAM_MAX_WRITES 0x10000u
#define IE_VOODOO_FBZ_STIPPLE 0x4u
#define IE_VOODOO_FBZ_DITHER 0x100u
#define IE_VOODOO_FBZ_DITHER_2X2 0x800u
#define IE_VOODOO_FBZ_ALPHA_WRITE 0x1000u
#define IE_VOODOO_FBZ_DRAW_FRONT 0x4000u
#define IE_VOODOO_FBZ_DRAW_BACK 0x8000u
#define IE_VOODOO_FBZ_DEPTH_SOURCE 0x10000u
#define IE_VOODOO_FBZ_Y_ORIGIN 0x20000u
#define IE_VOODOO_FBZ_ALPHA_PLANES 0x40000u
#define IE_VOODOO_FBZ_ALPHA_DITHER 0x80000u
#define IE_VOODOO_FBZ_DEPTH_OFFSET 0xfff00000u
#define IE_VOODOO_DEPTH_NEVER 0x0u
#define IE_VOODOO_DEPTH_LESS 0x1u
#define IE_VOODOO_DEPTH_EQUAL 0x2u
#define IE_VOODOO_DEPTH_LESSEQUAL 0x3u
#define IE_VOODOO_DEPTH_GREATER 0x4u
#define IE_VOODOO_DEPTH_NOTEQUAL 0x5u
#define IE_VOODOO_DEPTH_GREATEREQUAL 0x6u
#define IE_VOODOO_DEPTH_ALWAYS 0x7u
#define IE_VOODOO_ALPHA_TEST_FUNC 0xeu
#define IE_VOODOO_ALPHA_ANTIALIAS 0x20u
#define IE_VOODOO_ALPHA_SRC_A 0xf0000u
#define IE_VOODOO_ALPHA_DST_A 0xf00000u
#define IE_VOODOO_ALPHA_REF 0xff000000u
#define IE_VOODOO_BLEND_ZERO 0x0u
#define IE_VOODOO_BLEND_SRC_ALPHA 0x1u
#define IE_VOODOO_BLEND_COLOUR 0x2u
#define IE_VOODOO_BLEND_DST_ALPHA 0x3u
#define IE_VOODOO_BLEND_ONE 0x4u
#define IE_VOODOO_BLEND_INV_SRC_A 0x5u
#define IE_VOODOO_BLEND_INV_COLOUR 0x6u
#define IE_VOODOO_BLEND_INV_DST_A 0x7u
#define IE_VOODOO_BLEND_SATURATE 0xfu
#define IE_VOODOO_ALPHA_NEVER 0x0u
#define IE_VOODOO_ALPHA_LESS 0x1u
#define IE_VOODOO_ALPHA_EQUAL 0x2u
#define IE_VOODOO_ALPHA_LESSEQUAL 0x3u
#define IE_VOODOO_ALPHA_GREATER 0x4u
#define IE_VOODOO_ALPHA_NOTEQUAL 0x5u
#define IE_VOODOO_ALPHA_GREATEREQUAL 0x6u
#define IE_VOODOO_ALPHA_ALWAYS 0x7u
#define IE_VOODOO_TEX_CHROMA 0x1000u
#define IE_VOODOO_TEX_DETAIL 0x8000u
#define IE_VOODOO_TEX_SEQUENCE 0x10000u
#define IE_VOODOO_TLOD_FIELD 0x3fu
#define IE_VOODOO_TEX_UPLOAD_LEVEL_MASK 0xfu
#define IE_VOODOO_TEX_MAX_LEVELS 0x9u
#define IE_VOODOO_TEX_FMT_YIQ 0x1u
#define IE_VOODOO_TEX_FMT_A8 0x2u
#define IE_VOODOO_TEX_FMT_I8 0x3u
#define IE_VOODOO_TEX_FMT_AI44 0x4u
#define IE_VOODOO_TEX_FMT_ARGB8332 0x6u
#define IE_VOODOO_TEX_FMT_AI88 0x7u
#define IE_VOODOO_FCP_RGB_SELECT_MASK 0x3u
#define IE_VOODOO_FCP_RGB_SELECT_SHIFT 0x0u
#define IE_VOODOO_FCP_A_SELECT_MASK 0xcu
#define IE_VOODOO_FCP_A_SELECT_SHIFT 0x2u
#define IE_VOODOO_FCP_CC_MSELECT_MASK 0x70u
#define IE_VOODOO_FCP_CC_MSELECT_SHIFT 0x4u
#define IE_VOODOO_FCP_TEXTURE_ENABLE 0x8000000u
#define IE_VOODOO_CC_ITERATED 0x0u
#define IE_VOODOO_CC_TEXTURE 0x1u
#define IE_VOODOO_CC_COLOUR1 0x2u
#define IE_VOODOO_CC_LFB 0x3u
#define IE_VOODOO_CC_ZERO 0x0u
#define IE_VOODOO_CC_CSUB_CL 0x1u
#define IE_VOODOO_CC_ALOCAL 0x2u
#define IE_VOODOO_CC_AOTHER 0x3u
#define IE_VOODOO_CC_CLOCAL 0x4u
#define IE_VOODOO_CC_ALOCAL_T 0x5u
#define IE_VOODOO_CC_CLOC_MUL 0x6u
#define IE_VOODOO_CC_AOTHER_T 0x7u
#define IE_VOODOO_COMBINE_UNSET 0xffffffffu
#define IE_VOODOO_COMBINE_ITERATED 0x0u
#define IE_VOODOO_COMBINE_ADD 0x81u
#define IE_VOODOO_FOG_ADD 0x2u
#define IE_VOODOO_FOG_MULT 0x4u
#define IE_VOODOO_FOG_ZALPHA 0x8u
#define IE_VOODOO_FOG_CONSTANT 0x10u
#define IE_VOODOO_FOG_DITHER 0x20u
#define IE_VOODOO_FOG_TABLE_SHIFT 0x8u
#define IE_VOODOO_FOG_TABLE_MASK 0x3fu
/* 64 fog entries, four to a register: entry n is bits 8*(n&3) to
 * 8*(n&3)+7 of the register at IE_VOODOO_FOG_TABLE_BASE + 4*(n>>2), so the
 * table is the 16 registers 0xf8140 to 0xf817c. */
#define IE_VOODOO_FOG_TABLE_SIZE 0x40u
#define IE_VOODOO_FOG_TABLE_PER_WORD 0x4u
#define IE_VOODOO_FOG_TABLE_WORDS 0x10u
#define IE_VOODOO_FOG_TABLE_STRIDE 0x4u
#define IE_VOODOO_FOG_TABLE_END 0xf8180u
#define IE_VOODOO_FIXED_14_18_SHIFT 0x12u
#define IE_VOODOO_FIXED_20_12_SHIFT 0xcu
#define IE_VOODOO_FIXED_2_30_SHIFT 0x1eu
#define IE_VOODOO_PALETTE_BASE 0x0f8400u
#define IE_VOODOO_TEXTURE_MEMORY_BASE 0x0d0000u
#define IE_VOODOO_TEXTURE_MEMORY_SIZE 0x10000u
#define IE_6502_VOODOO_WINDOW_BASE 0xe000u
#define IE_6502_VOODOO_WINDOW_SIZE 0x1000u
#define IE_6502_VOODOO_BANK_HIGH 0xf7f2u
#define IE_6502_VOODOO_BANK_PAGE_HIGH 0xf7f3u
#define IE_Z80_VOODOO_PORT_ADDRESS_LOW 0xb0u
#define IE_Z80_VOODOO_PORT_ADDRESS_HIGH 0xb1u
#define IE_EXEC_BASE 0x0f2320u
#define IE_FILE_OPEN_READ 0x01u
#define IE_FILE_OPEN_WRITE 0x02u
#define IE_FILE_OPEN_CREATE 0x04u
#define IE_FILE_OPEN_TRUNCATE 0x08u
#define IE_FILE_OPEN_APPEND 0x10u
#define IE_FILE_OPEN_EXCLUSIVE 0x20u
#define IE_FILE_SEEK_SET 0
#define IE_FILE_SEEK_CUR 1
#define IE_FILE_SEEK_END 2
/* Legacy IE64 spellings retained for source compatibility. */
#define IE64_OPEN_READ IE_FILE_OPEN_READ
#define IE64_OPEN_WRITE IE_FILE_OPEN_WRITE
#define IE64_OPEN_CREATE IE_FILE_OPEN_CREATE
#define IE64_OPEN_TRUNCATE IE_FILE_OPEN_TRUNCATE
#define IE64_OPEN_APPEND IE_FILE_OPEN_APPEND
#define IE64_OPEN_EXCLUSIVE IE_FILE_OPEN_EXCLUSIVE
#define IE64_SEEK_SET IE_FILE_SEEK_SET
#define IE64_SEEK_CUR IE_FILE_SEEK_CUR
#define IE64_SEEK_END IE_FILE_SEEK_END
/* Media loader. Control registers are write-only; status, type and error are read-only. */
#define IE_MEDIA_BASE 0x0f2300u
#define IE_MEDIA_END 0x0f231fu
#define IE_MEDIA_NAME_PTR 0x0f2300u
#define IE_MEDIA_SUBSONG 0x0f2304u
#define IE_MEDIA_CTRL 0x0f2308u
#define IE_MEDIA_STATUS 0x0f230cu
#define IE_MEDIA_TYPE 0x0f2310u
#define IE_MEDIA_ERROR 0x0f2314u
#define IE_MEDIA_OP_PLAY 0x01u
#define IE_MEDIA_OP_STOP 0x02u
#define IE_MEDIA_STATUS_IDLE 0x00u
#define IE_MEDIA_STATUS_LOADING 0x01u
#define IE_MEDIA_STATUS_PLAYING 0x02u
#define IE_MEDIA_STATUS_ERROR 0x03u
#define IE_MEDIA_TYPE_NONE 0x00u
#define IE_MEDIA_TYPE_SID 0x01u
#define IE_MEDIA_TYPE_PSG 0x02u
#define IE_MEDIA_TYPE_TED 0x03u
#define IE_MEDIA_TYPE_AHX 0x04u
#define IE_MEDIA_TYPE_POKEY 0x05u
#define IE_MEDIA_TYPE_MOD 0x06u
#define IE_MEDIA_TYPE_WAV 0x07u
#define IE_MEDIA_TYPE_MIDI 0x08u
#define IE_MEDIA_ERROR_OK 0x00u
#define IE_MEDIA_ERROR_NOT_FOUND 0x01u
#define IE_MEDIA_ERROR_BAD_FORMAT 0x02u
#define IE_MEDIA_ERROR_UNSUPPORTED 0x03u
#define IE_MEDIA_ERROR_PATH_INVALID 0x04u
#define IE_MEDIA_ERROR_TOO_LARGE 0x05u
/* The host desktop's clipboard, which every mode with a guest in it can
 * reach: a pointer and a length in, a command, and a status and a
 * result length out. The bytes are plain text in both directions; an
 * operating system that wraps its clipboard in something of its own
 * does that wrapping on its side of these registers.
 *
 * Eight-bit targets reach the block through bank 3, the way they reach
 * the socket block, and store its registers a byte at a time, most
 * significant first. A command is obeyed when the last of its four
 * bytes arrives, so the pointer and the length are safe to write in any
 * order before it and the command runs once rather than three times. */
#define IE_CLIP_BASE 0x0f2390u
#define IE_CLIP_END 0x0f23afu
#define IE_CLIP_DATA_PTR (IE_CLIP_BASE + 0x00u)
#define IE_CLIP_DATA_LEN (IE_CLIP_BASE + 0x04u)
#define IE_CLIP_CTRL (IE_CLIP_BASE + 0x08u)
#define IE_CLIP_STATUS (IE_CLIP_BASE + 0x0cu)
#define IE_CLIP_RESULT_LEN (IE_CLIP_BASE + 0x10u)
#define IE_CLIP_FORMAT (IE_CLIP_BASE + 0x14u)
#define IE_CLIP_IO_BANK 0x79u
#if defined(IE_TARGET_6502) || defined(IE_TARGET_Z80)
# define IE_CLIP_BASE_TARGET 0x6390u
#else
# define IE_CLIP_BASE_TARGET IE_CLIP_BASE
#endif
#define IE_CLIP_DATA_PTR_TARGET (IE_CLIP_BASE_TARGET + 0x00u)
#define IE_CLIP_DATA_LEN_TARGET (IE_CLIP_BASE_TARGET + 0x04u)
#define IE_CLIP_CTRL_TARGET (IE_CLIP_BASE_TARGET + 0x08u)
#define IE_CLIP_STATUS_TARGET (IE_CLIP_BASE_TARGET + 0x0cu)
#define IE_CLIP_RESULT_LEN_TARGET (IE_CLIP_BASE_TARGET + 0x10u)
#define IE_CLIP_FORMAT_TARGET (IE_CLIP_BASE_TARGET + 0x14u)
#define IE_CLIP_CMD_READ 0x01u
#define IE_CLIP_CMD_WRITE 0x02u
#define IE_CLIP_STATUS_READY 0x00u
#define IE_CLIP_STATUS_BUSY 0x01u
#define IE_CLIP_STATUS_EMPTY 0x02u
#define IE_CLIP_STATUS_ERROR 0x03u
#define IE_NET_SOCKET_BASE 0x0f2500u
#define IE_NET_SOCKET_COMMAND (IE_NET_SOCKET_BASE + 0x00u)
#define IE_NET_SOCKET_REQUEST (IE_NET_SOCKET_BASE + 0x04u)
#define IE_NET_SOCKET_REQUEST_LENGTH (IE_NET_SOCKET_BASE + 0x08u)
#define IE_NET_SOCKET_RESULT1 (IE_NET_SOCKET_BASE + 0x0cu)
#define IE_NET_SOCKET_RESULT2 (IE_NET_SOCKET_BASE + 0x10u)
#define IE_NET_SOCKET_ERRNO (IE_NET_SOCKET_BASE + 0x14u)
#define IE_NET_SOCKET_HOSTERRNO (IE_NET_SOCKET_BASE + 0x18u)
#define IE_NET_SOCKET_STATUS (IE_NET_SOCKET_BASE + 0x1cu)
#define IE_NET_SOCKET_EVENTS (IE_NET_SOCKET_BASE + 0x20u)
#define IE_NET_CMD_SOCKET 1u
#define IE_NET_CMD_BIND 2u
#define IE_NET_CMD_LISTEN 3u
#define IE_NET_CMD_ACCEPT 4u
#define IE_NET_CMD_CONNECT 5u
#define IE_NET_CMD_SENDTO 6u
#define IE_NET_CMD_RECVFROM 7u
#define IE_NET_CMD_SHUTDOWN 8u
#define IE_NET_CMD_SETSOCKOPT 9u
#define IE_NET_CMD_GETSOCKOPT 10u
#define IE_NET_CMD_GETSOCKNAME 11u
#define IE_NET_CMD_GETPEERNAME 12u
#define IE_NET_CMD_IOCTL 13u
#define IE_NET_CMD_CLOSE 14u
#define IE_NET_CMD_WAITSELECT 15u
#define IE_NET_CMD_GETHOSTBYNAME 16u
#define IE_NET_CMD_GETHOSTBYADDR 17u
#define IE_NET_CMD_GETHOSTNAME 18u
#define IE_NET_CMD_DUP2 19u
#define IE_NET_CMD_GETEVENTS 20u
#define IE_NET_CMD_RELEASE 21u
#define IE_NET_CMD_RELEASECOPY 22u
#define IE_NET_CMD_OBTAIN 23u
#define IE_NET_REQ_DOMAIN 0u
#define IE_NET_REQ_TYPE 4u
#define IE_NET_REQ_PROTOCOL 8u
#define IE_NET_REQ_DATA_PTR 12u
#define IE_NET_REQ_DATA_LEN 16u
#define IE_NET_REQ_ADDR_PTR 20u
#define IE_NET_REQ_ADDR_LEN 24u
#define IE_NET_REQ_FLAGS 28u
#define IE_NET_REQ_LEVEL 32u
#define IE_NET_REQ_OPTNAME 36u
#define IE_NET_REQ_TIMEOUT_PTR 40u
#define IE_NET_REQ_SIGMASK_PTR 44u
#define IE_NET_REQ_ARG1 48u
#define IE_NET_REQ_ARG2 52u
#define IE_NET_REQ_EXCEPT_PTR 56u
#define IE_NET_REQ_HOSTENT_NAME_PTR 64u
#define IE_NET_REQ_HOSTENT_NAME_CAP 68u
#define IE_NET_REQ_HOSTENT_ADDRS_PTR 72u
#define IE_NET_REQ_HOSTENT_ADDRS_MAX 76u
#define IE_NET_REQ_WORDS 24u
#define IE_NET_REQ_SIZE 96u
#define IE_NET_MAX_IO 65536u
#define IE_NET_MAX_ADDR 128u
#define IE_NET_DTABLE 64u
#define IE_NET_FDSET_LEN 8u
#define IE_NET_SOCKET_CMD IE_NET_SOCKET_COMMAND
#define IE_NET_SOCKET_REQ_PTR IE_NET_SOCKET_REQUEST
#define IE_NET_SOCKET_REQ_LEN IE_NET_SOCKET_REQUEST_LENGTH
#define IE_NET_SOCKET_RES1 IE_NET_SOCKET_RESULT1
#define IE_NET_SOCKET_RES2 IE_NET_SOCKET_RESULT2
#define IE_NET_SOCKET_HERRNO IE_NET_SOCKET_HOSTERRNO
#define IE_NET_SOCKET_REQ_DOMAIN 0u
#define IE_NET_SOCKET_REQ_TYPE IE_NET_REQ_TYPE
#define IE_NET_SOCKET_REQ_PROTOCOL IE_NET_REQ_PROTOCOL
#define IE_NET_SOCKET_REQ_DATA_PTR 12u
#define IE_NET_SOCKET_REQ_DATA_LEN IE_NET_REQ_DATA_LEN
#define IE_NET_SOCKET_REQ_ADDR_PTR IE_NET_REQ_ADDR_PTR
#define IE_NET_SOCKET_REQ_ADDR_LEN IE_NET_REQ_ADDR_LEN
#define IE_NET_SOCKET_REQ_FLAGS IE_NET_REQ_FLAGS
#define IE_NET_SOCKET_REQ_LEVEL IE_NET_REQ_LEVEL
#define IE_NET_SOCKET_REQ_OPTNAME IE_NET_REQ_OPTNAME
#define IE_NET_SOCKET_REQ_TIMEOUT_PTR IE_NET_REQ_TIMEOUT_PTR
#define IE_NET_SOCKET_REQ_SIGMASK_PTR IE_NET_REQ_SIGMASK_PTR
#define IE_NET_SOCKET_REQ_ARG1 IE_NET_REQ_ARG1
#define IE_NET_SOCKET_REQ_ARG2 IE_NET_REQ_ARG2
#define IE_NET_SOCKET_REQ_EXCEPT_PTR IE_NET_REQ_EXCEPT_PTR
#define IE_NET_SOCKET_REQ_HOSTENT_NAME_PTR IE_NET_REQ_HOSTENT_NAME_PTR
#define IE_NET_SOCKET_REQ_HOSTENT_NAME_CAP IE_NET_REQ_HOSTENT_NAME_CAP
#define IE_NET_SOCKET_REQ_HOSTENT_ADDRS_PTR IE_NET_REQ_HOSTENT_ADDRS_PTR
#define IE_NET_SOCKET_REQ_HOSTENT_ADDRS_MAX 76u
#define IE_HOST_SOCKET_BASE IE_NET_SOCKET_BASE
#define IE_HOST_SOCKET_CMD IE_NET_SOCKET_COMMAND
#define IE_HOST_SOCKET_REQ_PTR IE_NET_SOCKET_REQUEST
#define IE_HOST_SOCKET_REQ_LEN IE_NET_SOCKET_REQUEST_LENGTH
#define IE_HOST_SOCKET_RES1 IE_NET_SOCKET_RESULT1
#define IE_HOST_SOCKET_RES2 IE_NET_SOCKET_RESULT2
#define IE_HOST_SOCKET_ERRNO IE_NET_SOCKET_ERRNO
#define IE_HOST_SOCKET_HERRNO IE_NET_SOCKET_HOSTERRNO
#define IE_HOST_SOCKET_STATUS IE_NET_SOCKET_STATUS
#define IE_HOST_SOCKET_EVENTS IE_NET_SOCKET_EVENTS
#define IE_HOST_SOCKET_CMD_SOCKET IE_NET_CMD_SOCKET
#define IE_HOST_SOCKET_CMD_BIND IE_NET_CMD_BIND
#define IE_HOST_SOCKET_CMD_LISTEN IE_NET_CMD_LISTEN
#define IE_HOST_SOCKET_CMD_ACCEPT IE_NET_CMD_ACCEPT
#define IE_HOST_SOCKET_CMD_CONNECT IE_NET_CMD_CONNECT
#define IE_HOST_SOCKET_CMD_SENDTO IE_NET_CMD_SENDTO
#define IE_HOST_SOCKET_CMD_RECVFROM IE_NET_CMD_RECVFROM
#define IE_HOST_SOCKET_CMD_SHUTDOWN IE_NET_CMD_SHUTDOWN
#define IE_HOST_SOCKET_CMD_SETSOCKOPT IE_NET_CMD_SETSOCKOPT
#define IE_HOST_SOCKET_CMD_GETSOCKOPT IE_NET_CMD_GETSOCKOPT
#define IE_HOST_SOCKET_CMD_GETSOCKNAME IE_NET_CMD_GETSOCKNAME
#define IE_HOST_SOCKET_CMD_GETPEERNAME IE_NET_CMD_GETPEERNAME
#define IE_HOST_SOCKET_CMD_IOCTL IE_NET_CMD_IOCTL
#define IE_HOST_SOCKET_CMD_CLOSE IE_NET_CMD_CLOSE
#define IE_HOST_SOCKET_CMD_WAITSELECT IE_NET_CMD_WAITSELECT
#define IE_HOST_SOCKET_CMD_GETEVENTS IE_NET_CMD_GETEVENTS
#define IE_HOST_SOCKET_CMD_RELEASE IE_NET_CMD_RELEASE
#define IE_HOST_SOCKET_CMD_RELEASECOPY IE_NET_CMD_RELEASECOPY
#define IE_HOST_SOCKET_CMD_OBTAIN IE_NET_CMD_OBTAIN

/* Assembly-compatible names for Copper, host control and coprocessor values. */
#define IE_COPPER_CTRL IE_VIDEO_COPPER_CTRL
#define IE_COPPER_PTR IE_VIDEO_COPPER_PTR
#define IE_HOST_MMIO_BASE 0x0f1400u
#define IE_HOST_MMIO_CMD 0x0f1400u
#define IE_HOST_MMIO_TRIGGER 0x0f1404u
#define IE_HOST_MMIO_STATUS 0x0f1408u
#define IE_HOST_MMIO_EXIT 0x0f140cu
#define IE_HOST_CMD_NET 1u
#define IE_HOST_CMD_UPDATE 2u
#define IE_HOST_CMD_REBOOT 3u
#define IE_HOST_CMD_POWEROFF 4u
#define IE_HOST_STATUS_RUNNING 0u
#define IE_HOST_STATUS_OK 1u
#define IE_HOST_STATUS_ERR 2u
#define IE_HOST_STATUS_CANCEL 3u
#define IE_HOST_STATUS_DISABLED 4u
#define IE_HOST_STATUS_IDLE 5u

#if IE_HAS_TRAP_WINDOWS
/* M68K trap-window control ($0f1480-$0f148f).  The block is registered on the
 * flat M68K launch path only.  Arming makes every unmapped guest access inside
 * the fixed window set - Amiga custom chips at $dff000 and both CIA blocks at
 * $bfd000/$bfe000 - fault as a bus error, which the payload's fault handler
 * services (provision backing, disarm, retry).  Read STATUS and test
 * IE_TRAP_WINDOW_STATUS_SUPPORTED before arming: where the block is absent the
 * addresses are plain RAM and neither bit reads back.  Any 16-bit write arms or
 * disarms; the value written is ignored. */
#define IE_TRAP_WINDOW_ENABLE 0x0f1480u
/* Arms the fixed window set and the RAM ceiling together. A payload that
 * emulates the chipset for itself disarms the windows around each
 * emulated access and arms them again afterwards; through the two
 * separate registers that republishes the composed window list twice for
 * a state change that happens once. */
#define IE_TRAP_WINDOW_ENABLE_ALL 0x0f1482u
#define IE_TRAP_WINDOW_DISABLE 0x0f1484u
#define IE_TRAP_WINDOW_STATUS 0x0f1488u
#define IE_TRAP_WINDOW_STATUS_ARMED 0x01u
#define IE_TRAP_WINDOW_STATUS_SUPPORTED 0x02u

/*
 * Which of the Amiga payload's optional paths the launch turned on.
 *
 * A register rather than a word in guest memory: a payload that clears
 * its own storage on the way up loses anything deposited there before
 * the machine started. M68K launch path only.
 */
#define IE_AMIGA_FEATURES 0x0f14a0u

#define IE_AMIGA_FEATURE_IRQ_SERVED   4u /* the engine holds INTENA/INTREQ */
#define IE_AMIGA_FEATURE_HOST_SOCKETS_OFF 128u /* the ROM's bsdsocket.library stands aside */

/* The Amiga system controller's registers (amiga_controller.go): the
 * doorbell event word, the release word the launch waits on (1 working,
 * 2 released, bit 31 an error with the code below it), the disk menu's
 * state word (bit 0 open, bits 8-15 opens, bits 16-23 mounts, bits
 * 24-27 the drive), the count of host keys taken, and the overlay
 * drop word: a guest giving up a Lisa overlay rectangle while the menu
 * holds the registers writes its base here, and the controller writes
 * zero back once it has agreed not to restore it. */
#define IE_AMIGA_CONTROLLER_EVENT   0x0f14a4u
#define IE_AMIGA_CONTROLLER_RELEASE 0x0f14a8u
#define IE_AMIGA_CONTROLLER_MENU    0x0f14acu
#define IE_AMIGA_CONTROLLER_KEYS    0x0f14b0u
#define IE_AMIGA_CONTROLLER_DROP    0x0f14b4u
/* The class word after the controller's USB mailbox: which kind of host
 * device the menu's mailbox answers for (0, the reset value, USB; 1
 * serial; 2 MIDI out; 3 MIDI in; 4 disks; 5 parallel; 6 the CD drive;
 * 7 PCI). */
#define IE_AMIGA_CONTROLLER_HOST_CLASS 0x0f1508u
/* The hardfile change register (amiga_hd_change.go): bit n (0-3) is set
 * when hardfile unit n's device has been taken out or put back.  EXTER is
 * held up while a bit is set, once a server has written the listen bit.
 * Reading clears nothing; writing a one to bit n clears it.  Long
 * access. */
#define IE_AMIGA_HD_CHANGE 0x0f15a0u
#define IE_AMIGA_HD_CHANGE_LISTEN 0x80000000u
/* The RAM-ceiling windows cover segments above chip RAM (from $800000),
 * excluding decoded holes and the Kickstart ROM socket at $00f80000.
 * The Amiga launch selects absent-memory responses; the generic controls
 * can select faults instead. The ceiling composes with the fixed window
 * set, and DISABLE clears only the ceiling. */
#define IE_TRAP_CEILING_ENABLE 0x0f148cu
#define IE_TRAP_CEILING_DISABLE 0x0f148eu

/* The Amiga profile republishes the whole register aperture at a high base,
 * far above the 24-bit space that machine presents, so nothing the guest sizes
 * or scans can reach the registers in place.  A payload running with the
 * mirror active reaches any register through IE_MIRRORED_REG: pass the
 * register's ordinary address and the mirror base the profile installed.
 * With the mirror off, the register addresses are used directly. */
#define IE_AMIGA_IO_MIRROR_BASE 0x01f00000u
#define IE_MIRRORED_REG(base, address) ((base) + ((address) - IE_IO_APERTURE_BASE))
#endif
#define IE_COPROC_CMD_ENQUEUE IE_COPROC_COMMAND_ENQUEUE
#define IE_COPROC_CMD_ERROR IE_COPROC_COMMAND_ERROR
#define IE_COPROC_CMD_STATUS IE_COPROC_COMMAND_STATUS
#define IE_COPROC_CMD_START IE_COPROC_COMMAND_START
#define IE_COPROC_CMD_STOP IE_COPROC_COMMAND_STOP
#define IE_COPROC_CMD_POLL IE_COPROC_COMMAND_POLL
#define IE_COPROC_CMD_WAIT_CMD IE_COPROC_COMMAND_WAIT
#define IE_COPROC_BUSY_PCT IE_COPROC_BUSY_PERCENT
#define IE_COPROC_IRQ_CTRL IE_COPROC_IRQ_CONTROL
#define IE_COPROC_NAME_PTR IE_COPROC_NAME_POINTER
#define IE_COPROC_ST_PENDING IE_COPROC_TICKET_PENDING
#define IE_COPROC_ST_RUNNING IE_COPROC_TICKET_RUNNING
#define IE_COPROC_ST_OK IE_COPROC_TICKET_OK
#define IE_COPROC_ST_ERROR IE_COPROC_TICKET_ERROR
#define IE_COPROC_ST_TIMEOUT IE_COPROC_TICKET_TIMEOUT
#define IE_COPROC_ST_WORKER_DOWN IE_COPROC_TICKET_WORKER_DOWN
#define IE_FILE_DATA_PTR64 IE_FILE_DATA_POINTER64
#define IE_COPROC_LAYOUT_VERSION 1u
#define IE_COPROC_ERR_NONE 0u
#define IE_COPROC_ERR_INVALID_CPU 1u
#define IE_COPROC_ERR_NOT_FOUND 2u
#define IE_COPROC_ERR_PATH_INVALID 3u
#define IE_COPROC_ERR_LOAD_FAILED 4u
#define IE_COPROC_ERR_QUEUE_FULL 5u
#define IE_COPROC_ERR_NO_WORKER 6u
#define IE_COPROC_ERR_STALE_TICKET 7u
#define IE_COPROC_ERR_INVALID_INSTANCE 8u
#define IE_COPROC_ERR_STALE_WORKER 9u
#define IE_COPROC_ERR_INVALID_DESCRIPTOR 10u
#define IE_COPROC_ERR_RESERVED 11u
#define IE_COPROC_CPU_IE32 1u
#define IE_COPROC_CPU_IE64 2u
#define IE_COPROC_CPU_6502 3u
#define IE_COPROC_CPU_M68K 4u
#define IE_COPROC_CPU_Z80 5u
#define IE_COPROC_CPU_X86 6u
#define IE_COPROC_CPU_PPC 12u

#if IE_HAS_BANK_WINDOWS
# define IE_BANK1_WINDOW 0x2000u
# define IE_BANK2_WINDOW 0x4000u
# define IE_BANK3_WINDOW 0x6000u
# define IE_VRAM_WINDOW 0x8000u
# define IE_BANK_SIZE 0x2000u
# define IE_VRAM_BANK_SIZE 0x4000u
# define IE_BANK1_REG_LO 0xf700u
# define IE_BANK1_REG_HI 0xf701u
# define IE_BANK2_REG_LO 0xf702u
# define IE_BANK2_REG_HI 0xf703u
# define IE_BANK3_REG_LO 0xf704u
# define IE_BANK3_REG_HI 0xf705u
# define IE_VRAM_BANK_REG 0xf7f0u
static void ie_bank_select(volatile uint8_t *low, volatile uint8_t *high, uint16_t bank) {
	*low = (uint8_t)bank; *high = (uint8_t)(bank >> 8);
}
#endif

#if IE_HAS_X86_PORT_IO
static inline uint8_t ie_x86_in8(uint16_t port) { uint8_t value; __asm__ volatile ("inb %1, %0" : "=a"(value) : "d"(port)); return value; }
static inline void ie_x86_out8(uint16_t port, uint8_t value) { __asm__ volatile ("outb %0, %1" : : "a"(value), "d"(port)); }
# define IE_X86_PORT_PSG_SELECT 0xf0u
# define IE_X86_PORT_PSG_DATA 0xf1u
# define IE_X86_PORT_SID_SELECT 0xe0u
# define IE_X86_PORT_SID_DATA 0xe1u
# define IE_X86_PORT_POKEY_BASE 0x60u
# define IE_X86_PORT_TED_SELECT 0xf2u
# define IE_X86_PORT_TED_DATA 0xf3u
# define IE_X86_PORT_ANTIC_SELECT 0xd4u
# define IE_X86_PORT_ANTIC_DATA 0xd5u
# define IE_X86_PORT_GTIA_SELECT 0xd6u
# define IE_X86_PORT_GTIA_DATA 0xd7u
# define IE_X86_PORT_VOODOO_ADDRESS_LOW 0xb0u
# define IE_X86_PORT_VOODOO_ADDRESS_HIGH 0xb1u
# define IE_X86_PORT_VOODOO_DATA0 0xb2u
# define IE_X86_PORT_VOODOO_DATA1 0xb3u
# define IE_X86_PORT_VOODOO_DATA2 0xb4u
# define IE_X86_PORT_VOODOO_DATA3 0xb5u
#endif

#if IE_HAS_IE64_CONTROL_REGISTERS
enum ie64_control_register {
	IE64_CR_PTBR = 0, IE64_CR_FAULT_ADDR = 1, IE64_CR_FAULT_CAUSE = 2,
	IE64_CR_FAULT_PC = 3, IE64_CR_TRAP_VEC = 4, IE64_CR_MMU_CTRL = 5,
	IE64_CR_TP = 6, IE64_CR_INTR_VEC = 7, IE64_CR_KSP = 8,
	IE64_CR_TIMER_PERIOD = 9, IE64_CR_TIMER_COUNT = 10,
	IE64_CR_TIMER_CTRL = 11, IE64_CR_USP = 12, IE64_CR_PREV_MODE = 13,
	IE64_CR_SAVED_SUA = 14, IE64_CR_RAM_SIZE_BYTES = 15
};
uint64_t __builtin_ie64_mfcr(unsigned int); void __builtin_ie64_mtcr(unsigned int, uint64_t);
void __builtin_ie64_tlbinval(uint64_t); void __builtin_ie64_tlbflush(void); void __builtin_ie64_suaen(void); void __builtin_ie64_suadis(void);
_Noreturn void __builtin_ie64_eret(void); _Noreturn void __builtin_ie64_rti(void); _Noreturn void __builtin_ie64_halt(void);
void __builtin_ie64_nop(void); void __builtin_ie64_sei(void); void __builtin_ie64_cli(void); void __builtin_ie64_wait(unsigned int); uint64_t __builtin_ie64_syscall(unsigned int); uint64_t __builtin_ie64_smode(void);
#endif

#if IE_HAS_IE64_ATOMICS
uint64_t __builtin_ie64_cas(volatile uint64_t *, uint64_t, uint64_t); uint64_t __builtin_ie64_xchg(volatile uint64_t *, uint64_t);
uint64_t __builtin_ie64_faa(volatile uint64_t *, uint64_t); uint64_t __builtin_ie64_fand(volatile uint64_t *, uint64_t); uint64_t __builtin_ie64_for(volatile uint64_t *, uint64_t); uint64_t __builtin_ie64_fxor(volatile uint64_t *, uint64_t);
static uint64_t ie64_atomic_compare_exchange(volatile uint64_t *p, uint64_t a, uint64_t b) { return __builtin_ie64_cas(p, a, b); }
static uint64_t ie64_atomic_exchange(volatile uint64_t *p, uint64_t a) { return __builtin_ie64_xchg(p, a); }
static uint64_t ie64_atomic_fetch_add(volatile uint64_t *p, uint64_t a) { return __builtin_ie64_faa(p, a); }
static uint64_t ie64_atomic_fetch_and(volatile uint64_t *p, uint64_t a) { return __builtin_ie64_fand(p, a); }
static uint64_t ie64_atomic_fetch_or(volatile uint64_t *p, uint64_t a) { return __builtin_ie64_for(p, a); }
static uint64_t ie64_atomic_fetch_xor(volatile uint64_t *p, uint64_t a) { return __builtin_ie64_fxor(p, a); }
#endif

#if IE_HAS_IE64_FPU
float __builtin_ie64_fmovecr(unsigned int); double __builtin_ie64_dmovecr(unsigned int); float __builtin_ie64_fmod(float, float); double __builtin_ie64_dmod(double, double);
float __builtin_ie64_fabs(float); double __builtin_ie64_dabs(double); float __builtin_ie64_fint(float); double __builtin_ie64_dint(double); float __builtin_ie64_fcvtds(double); double __builtin_ie64_fcvtsd(float);
float __builtin_ie64_fsin(float); float __builtin_ie64_fcos(float); float __builtin_ie64_ftan(float); float __builtin_ie64_fatan(float); float __builtin_ie64_flog(float); float __builtin_ie64_fexp(float); float __builtin_ie64_fpow(float, float); float __builtin_ie64_fsqrt(float);
double __builtin_ie64_dsin(double); double __builtin_ie64_dcos(double); double __builtin_ie64_dtan(double); double __builtin_ie64_datan(double); double __builtin_ie64_dlog(double); double __builtin_ie64_dexp(double); double __builtin_ie64_dpow(double, double); double __builtin_ie64_dsqrt(double);
uint64_t __builtin_ie64_fmovsr(void); uint64_t __builtin_ie64_fmovcr(void);
void __builtin_ie64_fmovsc(unsigned int); void __builtin_ie64_fmovcc(unsigned int);
#endif

#if defined(IE_TARGET_IE64)
int __ie64_console_read(void *, unsigned long, unsigned long *); int __ie64_console_write(const void *, unsigned long, unsigned long *);
int __ie64_file_open(const char *, unsigned int, uint64_t *); int __ie64_file_read(uint64_t, void *, unsigned long, unsigned long *); int __ie64_file_write(uint64_t, const void *, unsigned long, unsigned long *);
int __ie64_file_seek(uint64_t, int64_t, int, int64_t *); int __ie64_file_close(uint64_t); int __ie64_file_remove(const char *); int __ie64_file_rename(const char *, const char *); int __ie64_file_tmp(uint64_t *); int __ie64_monotonic_ticks(uint64_t *); _Noreturn void __ie64_terminate(int);
static void ie64_nop(void) { __builtin_ie64_nop(); } static void ie64_enable_interrupts(void) { __builtin_ie64_sei(); } static void ie64_disable_interrupts(void) { __builtin_ie64_cli(); } static _Noreturn void __ie64_assert_fail(void) { __builtin_ie64_halt(); }
#endif

#if defined(IE_TARGET_M68K)
/* Amithlon compatibility control, supplied by the AmigaOS profile only.
 * The extended ROM owns this protocol and its arena. Native applications use
 * emulator.library and AmigaOS APIs. These ordinary bus addresses can be
 * translated with IE_MIRRORED_REG for the Amiga I/O mirror. */
#define IE_AMITHLON_BASE 0xf1510u
#define IE_AMITHLON_COMMAND 0xf1510u
#define IE_AMITHLON_STATUS 0xf1514u
#define IE_AMITHLON_ARENA_BASE 0xf1518u
#define IE_AMITHLON_ARENA_SIZE 0xf151cu
#define IE_AMITHLON_TASK 0xf1520u
#define IE_AMITHLON_GENERATION 0xf1524u
#define IE_AMITHLON_EXEC_BASE 0xf1528u
#define IE_AMITHLON_ENTRY 0xf152cu
#define IE_AMITHLON_RESULT 0xf1530u
#define IE_AMITHLON_INPUT 0xf1534u
#define IE_AMITHLON_INPUT_SIZE 0xf1538u
#define IE_AMITHLON_OBJECT 0xf153cu
#define IE_AMITHLON_CMD_CONFIGURE_ARENA 0x1u
#define IE_AMITHLON_CMD_REGISTER_TASK 0x2u
#define IE_AMITHLON_CMD_TERMINATE_TASK 0x3u
#define IE_AMITHLON_CMD_REGISTER_ENTRY 0x4u
#define IE_AMITHLON_CMD_LOAD_ELF 0x5u
#define IE_AMITHLON_CMD_UNLOAD_ELF 0x6u
#define IE_AMITHLON_CMD_REGISTER_SHARED_ENTRY 0x7u
#define IE_AMITHLON_CMD_REGISTER_SHARED_TABLE 0x8u
#define IE_AMITHLON_CMD_UNREGISTER_SHARED_TABLE 0x9u
#define IE_AMITHLON_CMD_REGISTER_RESIDENT_INIT 0xau
#define IE_AMITHLON_CMD_LOOKUP_SYMBOL 0xbu
#define IE_AMITHLON_CMD_REGISTER_ROM_SERVICE 0xcu
#define IE_AMITHLON_CMD_ACTIVATE_LEGACY_PROBES 0xdu
#define IE_AMITHLON_CMD_PREPARE_PROCESS 0xeu
#define IE_AMITHLON_CMD_BIND_PROCESS 0xfu
#define IE_AMITHLON_CMD_CANCEL_PROCESS 0x10u
#define IE_AMITHLON_CMD_REGISTER_OBJECT_ENTRY 0x11u
#define IE_AMITHLON_CMD_TRACK_FUNCTION_VECTOR 0x12u
#define IE_AMITHLON_CMD_FREE_FUNCTION_VECTORS 0x13u
#define IE_AMITHLON_CMD_PREPARE_FUNCTION_VECTOR 0x14u
#define IE_AMITHLON_CMD_FINISH_FUNCTION_VECTOR 0x15u
#define IE_AMITHLON_CMD_BIND_COMMAND_OBJECT 0x16u
#define IE_AMITHLON_CMD_END_COMMAND 0x17u
#define IE_AMITHLON_CMD_RETAIN_AUDIO_HOOK 0x18u
#define IE_AMITHLON_CMD_RELEASE_AUDIO_HOOK 0x19u
/* Retain: INPUT=code, ENTRY=server node, INPUT_SIZE=interrupt number.
 * Release: INPUT=server node, INPUT_SIZE=interrupt number. */
#define IE_AMITHLON_CMD_RETAIN_INTERRUPT_SERVER 0x1au
#define IE_AMITHLON_CMD_RELEASE_INTERRUPT_SERVER 0x1bu
#define IE_AMITHLON_CMD_PREPARE_TASK 0x1cu /* ENTRY initial, INPUT final; BIND/CANCEL_PROCESS use returned handle. */
/* ENTRY=ROM gateway. A task that reads the legacy probes is then activated. */
#define IE_AMITHLON_CMD_ENABLE_AUTO_ACTIVATION 0x1du
/* INPUT=segment list (BPTR) from LoadSeg or NewLoadSeg, ENTRY=its name.
 * The monitor names the program's hunks. The ROM sends it; non-blocking. */
#define IE_AMITHLON_CMD_NOTE_SEGMENT 0x1fu
/* INPUT=segment list (BPTR) UnLoadSeg is about to free. */
#define IE_AMITHLON_CMD_DROP_SEGMENT 0x20u
#define IE_AMITHLON_STATUS_IDLE 0x0u
#define IE_AMITHLON_STATUS_OK 0x1u
#define IE_AMITHLON_STATUS_INVALID 0x2u
#define IE_AMITHLON_STATUS_UNAVAILABLE 0x3u
#endif

#if defined(IE_TARGET_M68K)
/* The Amiga CD drive's SCSI command block, Amiga profile only. iecd.device
 * in the extended ROM passes HD_SCSICMD through it to a host optical drive
 * (-amiga-cd naming one); IE_AMIGA_FEATURES bit 8 says such a drive is
 * there. Write the command, then IE_AMIGA_CD_SCSI_START to CTRL, then read
 * CTRL until BUSY clears. The command bytes are four longs, the first byte
 * in bits 31-24 of the first. These ordinary bus addresses can be
 * translated with IE_MIRRORED_REG for the Amiga I/O mirror. */
#define IE_AMIGA_FEATURE_CD_PASSTHROUGH 0x100u
#define IE_AMIGA_CD_SCSI_BASE 0xf1560u
#define IE_AMIGA_CD_SCSI_CDB 0xf1560u
#define IE_AMIGA_CD_SCSI_CDB_LEN 0xf1570u
#define IE_AMIGA_CD_SCSI_DIRECTION 0xf1574u
#define IE_AMIGA_CD_SCSI_DATA 0xf1578u
#define IE_AMIGA_CD_SCSI_DATA_LEN 0xf157cu
#define IE_AMIGA_CD_SCSI_SENSE 0xf1580u
#define IE_AMIGA_CD_SCSI_SENSE_LEN 0xf1584u
#define IE_AMIGA_CD_SCSI_DATA_ACTUAL 0xf1588u
#define IE_AMIGA_CD_SCSI_SENSE_ACTUAL 0xf158cu
#define IE_AMIGA_CD_SCSI_STATUS 0xf1590u
#define IE_AMIGA_CD_SCSI_RESULT 0xf1594u
#define IE_AMIGA_CD_SCSI_CTRL 0xf1598u
#define IE_AMIGA_CD_SCSI_ID 0xf159cu
#define IE_AMIGA_CD_SCSI_DIR_NONE 0x0u
#define IE_AMIGA_CD_SCSI_DIR_IN 0x1u
#define IE_AMIGA_CD_SCSI_DIR_OUT 0x2u
#define IE_AMIGA_CD_SCSI_START 0x1u
#define IE_AMIGA_CD_SCSI_BUSY 0x1u
#define IE_AMIGA_CD_SCSI_RESULT_OK 0x0u /* the drive answered: see STATUS */
#define IE_AMIGA_CD_SCSI_RESULT_NO_DRIVE 0x1u
#define IE_AMIGA_CD_SCSI_RESULT_BAD_BUFFER 0x2u
#define IE_AMIGA_CD_SCSI_RESULT_BAD_COMMAND 0x3u
#define IE_AMIGA_CD_SCSI_RESULT_HOST_ERROR 0x4u
#define IE_AMIGA_CD_SCSI_RESULT_BUSY 0x5u
#define IE_AMIGA_CD_SCSI_RESULT_ABORTED 0x6u
#endif

#if defined(IE_TARGET_M68K)
/* The Amiga PCI bridge, Amiga profile only (the extended ROM's
 * openpci.library is its client). Configuration space through the ADDR
 * and DATA pair; every memory BAR in the memory window; every I/O BAR as
 * a port in the I/O window, reached at IE_AMIGA_PCI_IO_WINDOW + port with
 * values as numbers and at IE_AMIGA_PCI_IO_SWAPPED + port with 16-bit and
 * 32-bit values byte-reversed. Each access there is one port access of
 * the same width. The register addresses can be translated with
 * IE_MIRRORED_REG for the Amiga I/O mirror. */
#define IE_AMIGA_PCI_CFG_ADDR 0xf2b00u /* rw: devfn << 8 | register */
#define IE_AMIGA_PCI_CFG_DATA32 0xf2b04u /* rw: the long at register & ~3 */
#define IE_AMIGA_PCI_CFG_DATA16 0xf2b08u /* rw: the word at register & ~1 */
#define IE_AMIGA_PCI_CFG_DATA8 0xf2b0cu /* rw: the byte at register */
#define IE_AMIGA_PCI_ID 0xf2b10u /* r: 'IPCI' */
#define IE_AMIGA_PCI_COUNT 0xf2b14u /* r: functions on the bus */
#define IE_AMIGA_PCI_WIN_BASE 0xf2b18u /* r: the memory window */
#define IE_AMIGA_PCI_WIN_SIZE 0xf2b1cu /* r: its size */
#define IE_AMIGA_PCI_INT_PENDING 0xf2b20u /* r: bit n, slot n asserts */
#define IE_AMIGA_PCI_DEVFN_AT 0xf2b24u /* rw: index in, devfn out */
#define IE_AMIGA_PCI_SWAP 0xf2b28u /* rw: memory BAR byte swap */
#define IE_AMIGA_PCI_IO_BASE 0xf2b2cu /* r: the I/O window */
#define IE_AMIGA_PCI_IO_WINDOW 0x1f60000u
#define IE_AMIGA_PCI_IO_SWAPPED 0x1f70000u
#define IE_AMIGA_PCI_IO_WINDOW_SIZE 0x10000u
#define IE_AMIGA_PCI_MEM_WINDOW 0x1f80000u
#define IE_AMIGA_PCI_MEM_WINDOW_SIZE 0x80000u
#endif

#endif
