mgba_read16
Read a 16-bit unsigned integer from emulated GBA or GB/GBC memory at a given bus address, returning the value in decimal and hex. Use for game state fields like HP, score, or coordinates.
Instructions
PURPOSE: Read an unsigned 16-bit little-endian value from emulated memory at the given system bus address. USAGE: Use for 16-bit fields (most game-state values: HP, score, coordinates on 16-bit-flavoured layouts). For single bytes use mgba_read8; for 32-bit values use mgba_read32; for non-aligned spans, big-endian fields, or arbitrary structures use mgba_read_range and decode the bytes yourself (this tool always interprets bytes as little-endian, which matches both GBA and GB/GBC native endianness). BEHAVIOR: No side effects — pure read. Reads two consecutive bytes (low byte at address, high byte at address+1) and combines them as little-endian. Returns an error if the address is unmapped, the read straddles a region boundary, or the bridge method is missing on this build. RETURNS: Single line 'ADDR_HEX: VAL_DEC (0xVAL_HEX)'.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | System bus address. On GBA pass full 32-bit addresses (e.g. 0x02000000 for EWRAM start, 0x03000000 for IWRAM, 0x08000000 for ROM); on GB/GBC pass 16-bit addresses (e.g. 0xC000 for WRAM, 0xA000 for cartridge SRAM). Reads 2 consecutive bytes starting here. Should be 2-byte aligned (multiple of 2); misaligned reads on ARM-class regions can return zero or stale bus values without raising an error. Returns an error if the address is outside the platform's mapped regions or if the named bridge method is missing on this mGBA build (check mgba_get_info → capabilities). |