mgba_write_range
Write up to 4096 bytes of debug-direct memory to a GBA, GB, or GBC emulator at a specified address. Overwrites target memory sequentially with no undo; bytes must be 0-255.
Instructions
PURPOSE: Write a contiguous byte sequence to emulated memory starting at the given system bus address. USAGE: Use whenever you're seeding more than ~4 bytes — one round-trip vs N frame-latency hops compared to looping mgba_write8. Maximum 4096 bytes per call (bridge serialization limit); for larger writes, batch in 4 KiB chunks. Useful for installing cheat tables, patching code blocks, restoring a captured byte window after experiments, and writing big-endian multi-byte values (byteswap them yourself first). For cart save RAM seeding with proper MBC semantics on Game Boy, use mgba_save_state / mgba_load_state instead — those go through the cartridge bus model. BEHAVIOR: DESTRUCTIVE: overwrites N bytes starting at address with no undo. Debug-direct memory write — bypasses MBC/mapper/DMA, see mgba_write8 notes for the cartridge-bus bypass details. Bytes are written sequentially address, address+1, ..., address+N-1. Returns an error if the address is unmapped, address+N crosses an unmapped boundary, the array contains a value outside 0-255, the array length is < 1 or > 4096, or the bridge method is missing. RETURNS: Single line 'Wrote N bytes → 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 | Starting system bus address. Same address-space conventions as the single-width write tools: full 32-bit for GBA (EWRAM 0x02000000, IWRAM 0x03000000), 16-bit for GB/GBC (WRAM 0xC000, SRAM 0xA000). The N bytes [address, address+len) are written. Writes use debug-direct memory access — bypasses MBC; for cart save RAM seeding use mgba_save_state / mgba_load_state instead. | |
| bytes | Yes | Byte values to write, one per element (each 0-255). Length 1-4096 (hard cap from the bridge's serialization limit). Written sequentially from `address` in declaration order. |