mgba_read32
Read a 32-bit unsigned value from emulated GBA/GB memory at a specified address. Returns the value in decimal and hexadecimal, handling flaky native reads by reassembling from 4 bytes.
Instructions
PURPOSE: Read an unsigned 32-bit little-endian value from emulated memory at the given system bus address. USAGE: Use for 32-bit fields (timestamps, large counters, pointers on GBA, RGBA colours). For 8/16-bit reads use mgba_read8/read16; for big-endian or unaligned multi-word reads use mgba_read_range and decode yourself. BEHAVIOR: No side effects — pure read. mGBA's native emu.read32 is intermittently flaky when called via pcall on certain builds, so the bridge transparently routes 32-bit reads through readRange(addr, 4) and reassembles them little-endian — you get a stable answer either way. Returns an error only if the address is unmapped or the underlying readRange itself fails. 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 4 consecutive bytes starting here. Should be 4-byte aligned (multiple of 4); 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). |