mgba_write16
Write a 16-bit unsigned value to emulated memory at a system bus address. Use for cheats and pokes (HP, score, coordinates). Overwrites two bytes with no undo.
Instructions
PURPOSE: Write an unsigned 16-bit little-endian value to emulated memory at the given system bus address. USAGE: Use for 16-bit cheats and pokes (HP, score, coordinates). For single bytes use mgba_write8; for 32-bit use mgba_write32; for big-endian fields, byteswap and use mgba_write_range; for cart save RAM seeding with proper MBC semantics, use mgba_save_state / mgba_load_state. BEHAVIOR: DESTRUCTIVE: overwrites two bytes (low byte at address, high byte at address+1) with no undo. Debug-direct memory write — no MBC/mapper/DMA mediation, see mgba_write8 notes for the cartridge-bus bypass details. Returns an error if the address is unmapped, address+2 crosses an unmapped boundary, value < 0 or > 65535, or the bridge method is missing. RETURNS: Single line 'Wrote VAL_DEC (0xVAL_HEX) → ADDR_HEX'.
NOTE: writes use mGBA's debug-direct memory access, which bypasses the cartridge bus model. On Game Boy with an MBC cartridge, this means writes to ROM region (0x0000-0x7FFF) won't trigger MBC bank-switch / RAM-enable commands, and writes to SRAM (0xA000-0xBFFF) hit the underlying buffer regardless of MBC enable state. To seed cartridge SRAM cleanly, use mgba_save_state / mgba_load_state with a pre-prepared state file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | System bus address to overwrite. Same address-space conventions as the read tools — full 32-bit for GBA (EWRAM 0x02000000, IWRAM 0x03000000, ROM 0x08000000), 16-bit for GB/GBC (WRAM 0xC000, SRAM 0xA000). Should be 2-byte aligned (multiple of 2); misaligned writes on ARM-class regions may corrupt adjacent bytes or be silently dropped. Writes go through mGBA's debug-direct memory access, so they ignore MBC enable state and bus protections — to seed cartridge SRAM with proper hardware semantics, use mgba_save_state / mgba_load_state instead. | |
| value | Yes | 16-bit value to write. Must be 0-65535 (0x0000-0xFFFF). LSB is written to `address`, MSB to `address+1`. Values outside this range return an error before the write is attempted. |