GB101:Introduction to the Gameboy Advance
|GB101 Class Notes|
The GBA uses a 16mhz 32bit ARM7TDMI processor. The CPU is RISC, so instructions are simple and generally take one cycle. The processor has a 16bit and 32bit instruction mode, and you have to switch from one to the other. We'll be telling our compiler to use both and handle these switches automatically.
There are three primary segments of general use memory.
Internal Working RAM (iwram)
32KB of fast RAM. 8, 16, 32 bit reads/writes allowed. Single cycle access. Starts at 0x30000000.
External Working RAM (ewram)
256KB of RAM. 8, 16, 32 bit reads/writes allowed. Two cycle access. Starts at 0x20000000.
Up to 32MB. This is where the code lives. Three cycles for random access, a single cycle for sequential access. It's actually faster to load images out of ROM than ewram. Starts at 0x80000000.
The register space starts at 0x40000000 and is where we'll be communicating between various components (CPU, DMA, etc).
Access to the video is done via a memory mapped area. There are various modes that change the locations and behaviors of video memory. The main video memory area starts at 0x6000000.
This is the easiest mode. Each 16-bit value in the memory area starting at 0x60000000 represents a pixel. You can just write color values to memory like an array.
This is similar to mode 3, except we use 8-bit indexes into a 256 color palette instead of 16-bit color values. If you've ever done any VGA graphics coding in MS-DOS then you'll be familiar with this. Because you're only using 8-bits you can have two screens in memory at the same time and switch between them. This allows you do to drawing off-screen and switch once you're done. This is called double buffering.
This is just like Mode 3, but at half resolution so you can do double buffering.
These are the tiled modes. In tiled modes each value in the memory represents a 8x8, 16x16 or 32x32 tile. The number of tiles you can have varies depending on their size and the mode you're using. The tiles live in one area of video memory, and the map of which tiles go where live in another. These tiles are used to make up the background. You get to have various layers of background each of which can be scrolled, stretched and/or rotated depending on the specific mode you're in.
All modes also get sprites. These sprites have a separate 256-color palette, giving you access to 512 total colors. The amount of memory available for sprites varies depending on the mode (16KB in 3,4,5 and 32KB in 0,1,2). You can have 128 sprites on-screen at a time. Sprite graphics are stored at 0x6010000, and the sprite locations and data are stored at 0x7000000.