ARM programming for Gameboy Advance

Following the Gameboy Color, the Gameboy Advance was the first hand-held console to bring Super-Nintendo Quality to handhelds...

Rather than using the Gameboy's GBZ80, or the Super Nintendo's 65816, the Gameboy Advance uses an ARM processor.

In fact, the GBA is pretty much the simplest system to develop ARM for!

There were multiple generations of the Gameboy Advance, but they were essentially functionally identical... the later NDS was also backwards compatible with the GBA

Tech Specs
Cpu 16.7 MHZ ARM7TDMI
Memory 384k
Resolution 240x160 (30x20 tiles)
256 or 32K colors
Sprites 128 @ 64x64
Sound 4 channel + 2xDMA
The 3 generations of the GBA

If you want to learn ARM get the Cheatsheet! it has all the ARM7 commands, it covers the commands, and options like Bitshifts and conditions as well as the bytecode structure of the commands!

Technical Resources
GBATEK - complete documentation on the GBA and NDS

ARM Hello World Series

Hello World on the GameBoy Advance - ARM Assembly Lesson H2
Hello World on the GameBoy Advance with ARM Thumb Assembly - Lesson H4 [GBA]

ARM Platform Specific Lessons

Lesson P2 - Bitmap graphics and Palette definitions on GameBoy Advance (16 bit - 32768 colors) [GBA]
Lesson P3 - Bitmap graphics and Palette definitions on GameBoy Advance (8 bit - 256 colors) [GBA]
Lesson P5 - Joypad & Pen on the GBA / NDS ... Key reading on Risc OS [NDS] [GBA] [ROS]
Lesson P6 - Sound on the Gameboy Advance [GBA]
Lesson P8 - 16 color Tilemap on the Gameboy Advance and Nintendo DS! [GBA] [NDS]
Lesson P9 - Hardware Sprites on the Gameboy Advance and Nintendo DS! [GBA] [NDS]

ARM Simple Samples

Moving a sprite on RiscOS - Simple ARM Assembly Lesson S1
Sprite moving on the GameBoy Advance - Arm Assembly Lesson S2
Lesson S4 - Sprite moving on the GameBoy Advance (Thumb) [GBA]



Screen Display
In these tutorials we're going to use mode 4 - this effectively has 2 bitmap layers of 256 colors each, they are NOT PLANAR - they are linear bitmap format.
Note, it is not possible to write in bytes to the screen, We must write in WORDS... if we write a byte, both bytes of the word will be set the same - effectively halving the horizontal resolution

Memory Map
From To Purpose
0x00000000 
0x00003FFF 
BIOS - System ROM (16 KBytes)
0x00004000 0x01FFFFFF Not used
0x02000000 0x0203FFFF WRAM - On-board Work RAM (256 KBytes) 2 Wait
0x02040000 0x02FFFFFF Not used
0x03000000 0x03007FFF WRAM - On-chip Work RAM (32 KBytes)
0x03008000 0x03FFFFFF Not used
0x04000000 0x040003FE I/O Registers
0x04000400 0x04FFFFFF Not used
0x05000000 0x050003FF BG/OBJ Palette RAM (1 Kbyte)
0x05000400 0x05FFFFFF Not used
0x06000000 0x06017FFF VRAM - Video RAM (96 KBytes)
0x06018000 0x06FFFFFF Not used
0x07000000 0x070003FF OAM - OBJ Attributes (1 Kbyte)
0x07000400 0x07FFFFFF Not used
0x08000000 0x09FFFFFF Game Pak ROM/FlashROM (max 32MB) - Wait State 0
0x0A000000 0x0BFFFFFF Game Pak ROM/FlashROM (max 32MB) - Wait State 1
0x0C000000 0x0DFFFFFF Game Pak ROM/FlashROM (max 32MB) - Wait State 2
0x0E000000 0x0E00FFFF Game Pak SRAM (max 64 KBytes) - 8bit Bus width
0x0E010000 0x0FFFFFFF Not used
0x10000000 0xFFFFFFFF Not used (upper 4bits of address bus unused)


Sound
Port Name Description Bits Details
0x4000060 
SOUND1CNT_L Channel 1 Sweep register ---------TTTDSSS S=sweep shift D=direction T=Time
0x4000062 SOUND1CNT_H Channel 1 Duty/Length/Envelope (NR11 VVVVDSSSWWLLLLLL L=length W=wave pattern duty S=envelope Step D= env direction V=Volume
0x4000064 SOUND1CNT_X Channel 1 Frequency/Control IL---FFFFFFFFFFF I=Init sound L=no loop F=Frequency
0x4000068 SOUND2CNT_L Channel 2 Duty/Length/Envelope (NR21 VVVVDSSSWWLLLLLL L=length W=wave pattern duty S=envelope Step D= env direction V=Volume
0x400006C SOUND2CNT_H Channel 2 Frequency/Control IL---FFFFFFFFFFF I=Init sound L=no loop F=Frequency
0x4000070 SOUND3CNT_L Channel 3 Stop/Wave RAM select (NR30) -------PBD----- D=Dimension B=Bank P=Play (1=on 0=off)
0x4000072 SOUND3CNT_H Channel 3 Length/Volume FVV-----LLLLLLLL L=sound Length V=volume F=Force
0x4000074 SOUND3CNT_X Channel 3 Frequency/Control IL---FFFFFFFFFFF I=Init sound L=no loop F=Frequency
0x4000078 SOUND4CNT_L Channel 4 Length/Envelope VVVVDSSS--LLLLLL L=length S=envelope Step D= env direction V=Volume
0x400007C SOUND4CNT_H Channel 4 Frequency/Control IL------SSSSCRRR R=dividing Ration, C=Counter S=shify clock freq L+no Loop I=Init sound
0x4000080 SOUNDCNT_L Control Stereo/Volume/Enable LLLLRRRR-lll-rrr LR=Channel on lr=master vol(7=max)
0x4000082 SOUNDCNT_H Control Mixing/DMA Control BBBBAAAA-ba-VV
0x4000084 SOUNDCNT_X Control Sound on/off M---4321 M=Master ON 1234 (Read) = Sound on flag
0x4000088 BIOS SOUNDBIAS Sound PWM Control AA----BBBBBBBBB- A=Amplitude B=Bios
0x4000090 WAVE_RAM 16 Bytes 1111222233334444 4 bit sample data
0x40000A0 FIFO_A Channel A FIFO ----DDDD----DDDD D=Wawave Data
0x40000A4 FIFO_B Channel B FIFO ----DDDD----DDDD D=Wawave Data



Ports
Port Name Description Bits Details
0x4000000 DISPCNT LCD Control
Owwddddd Bmhfcbbb
0x4000002 - Undocumented - Green Swap

0x4000004 DISPSTAT General LCD Status (STAT LYC)
0x4000006 VCOUNT Vertical Counter (LY)

0x4000008 BG0CNT BG0 Control

0x400000A BG1CNT BG1 Control

0x400000C BG2CNT BG2 Control

0x400000E BG3CNT BG3 Control

0x4000010 BG0HOFS BG0 X-Offset

0x4000012 BG0VOFS BG0 Y-Offset

0x4000014 BG1HOFS BG1 X-Offset

0x4000016 BG1VOFS BG1 Y-Offset

0x4000018 BG2HOFS BG2 X-Offset

0x400001A BG2VOFS BG2 Y-Offset

0x400001C BG3HOFS BG3 X-Offset

0x400001E BG3VOFS BG3 Y-Offset

0x4000020 BG2PA BG2 Rotation/Scaling Parameter A (dx)

0x4000022 BG2PB BG2 Rotation/Scaling Parameter B (dmx)

0x4000024 BG2PC BG2 Rotation/Scaling Parameter C (dy)

0x4000026 BG2PD BG2 Rotation/Scaling Parameter D (dmy)

0x4000028 BG2X BG2 Reference Point X-Coordinate

0x400002C BG2Y BG2 Reference Point Y-Coordinate

0x4000030 BG3PA BG3 Rotation/Scaling Parameter A (dx)

0x4000032 BG3PB BG3 Rotation/Scaling Parameter B (dmx)

0x4000034 BG3PC BG3 Rotation/Scaling Parameter C (dy)

0x4000036 BG3PD BG3 Rotation/Scaling Parameter D (dmy)

0x4000038 BG3X BG3 Reference Point X-Coordinate

0x400003C BG3Y BG3 Reference Point Y-Coordinate

0x4000040 WIN0H Window 0 Horizontal Dimensions

0x4000042 WIN1H Window 1 Horizontal Dimensions

0x4000044 WIN0V Window 0 Vertical Dimensions

0x4000046 WIN1V Window 1 Vertical Dimensions

0x4000048 WININ Inside of Window 0 and 1

0x400004A WINOUT Inside of OBJ Window & Outside of Windows

0x400004C MOSAIC Mosaic Size

0x400004E Not used


0x4000050 BLDCNT Color Special Effects Selection

0x4000052 BLDALPHA Alpha Blending Coefficients

0x4000054 BLDY Brightness (Fade-In/Out) Coefficient

0x4000056 Not used


0x40000B0 DMA0SAD DMA 0 Source Address

0x40000B4 DMA0DAD DMA 0 Destination Address

0x40000B8 DMA0CNT_L DMA 0 Word Count

0x40000BA DMA0CNT_H DMA 0 Control

0x40000BC DMA1SAD DMA 1 Source Address

0x40000C0 DMA1DAD DMA 1 Destination Address

0x40000C4 DMA1CNT_L DMA 1 Word Count

0x40000C6 DMA1CNT_H DMA 1 Control

0x40000C8 DMA2SAD DMA 2 Source Address

0x40000CC DMA2DAD DMA 2 Destination Address

0x40000D0 DMA2CNT_L DMA 2 Word Count

0x40000D2 DMA2CNT_H DMA 2 Control

0x40000D4 DMA3SAD DMA 3 Source Address

0x40000D8 DMA3DAD DMA 3 Destination Address

0x40000DC DMA3CNT_L DMA 3 Word Count

0x40000DE DMA3CNT_H DMA 3 Control

0x40000E0 Not used


0x4000100 TM0CNT_L Timer 0 Counter/Reload

0x4000102 TM0CNT_H Timer 0 Control

0x4000104 TM1CNT_L Timer 1 Counter/Reload

0x4000106 TM1CNT_H Timer 1 Control

0x4000108 TM2CNT_L Timer 2 Counter/Reload

0x400010A TM2CNT_H Timer 2 Control

0x400010C TM3CNT_L Timer 3 Counter/Reload

0x400010E TM3CNT_H Timer 3 Control

0x4000110 Not used


0x4000120 SIODATA32 SIO Data (Normal-32bit Mode; shared with below)

0x4000120 SIOMULTI0 SIO Data 0 (Parent) (Multi-Player Mode)

0x4000122 SIOMULTI1 SIO Data 1 (1st Child) (Multi-Player Mode)

0x4000124 SIOMULTI2 SIO Data 2 (2nd Child) (Multi-Player Mode)

0x4000126 SIOMULTI3 SIO Data 3 (3rd Child) (Multi-Player Mode)

0x4000128 SIOCNT SIO Control Register

0x400012A SIOMLT_SEND SIO Data (Local of MultiPlayer; shared below)

0x400012A SIODATA8 SIO Data (Normal-8bit and UART Mode)

0x400012C Not used


0x4000130 KEYINPUT Key Status

0x4000132 KEYCNT Key Interrupt Control

0x4000134 RCNT SIO Mode Select/General Purpose Data

0x4000136 IR Ancient - Infrared Register (Prototypes only)

0x4000138 Not used


0x4000140 JOYCNT SIO JOY Bus Control

0x4000142 Not used


0x4000150 JOY_RECV SIO JOY Bus Receive Data

0x4000154 JOY_TRANS SIO JOY Bus Transmit Data

0x4000158 JOYSTAT SIO JOY Bus Receive Status

0x400015A Not used


0x4000200 IE Interrupt Enable Register

0x4000202 IF Interrupt Request Flags / IRQ Acknowledge

0x4000204 WAITCNT Game Pak Waitstate Control

0x4000206 Not used


0x4000208 IME Interrupt Master Enable Register

0x400020A Not used


0x4000300 POSTFLG Undocumented - Post Boot Flag

0x4000301 HALTCNT Undocumented - Power Down Control

0x4000302 Not used


0x4000410 ? Undocumented - Purpose Unknown / Bug ??? 0FFh

0x4000411 Not used


0x4000800 ? Undocumented - Internal Memory Control (R/W)

0x4000804 Not used


0x4xx0800 ? Mirrors of 0x4000800 (repeated each 64K)


Sprites

In Tilemap mode, Sprite patterns are defined by by VRAM addresses 0x06010000+
In Bitmap mode, Sprite patterns are defined by by VRAM addresses 0x06014000+, Due to the size of the bitmap screen ram, only tile numbers 512+ are usable

Sprites use the 256 colors in the OBJ palette from address 0x05000200+

Sprites are made up of 8x8 patterns with either 16 colors (4bpp) or 256 colors (8bpp) defined by the color bit in the first parameter.

Sprite XY pos 0,0 is the top left corner of the screen.


H Byte L Byte
VRAM Address F E D C B A 9 8 7 6 5 4 3 2 1 0 Details
7000000h S S C M T T D R Y Y Y Y Y Y Y Y Y=Ypos S=Shape (Square /HRect / Vrect) C=Colors(16/256) M=Mosiac
T=Transparent D=Disable/Doublesize R=Rotation
7000002h S S V H R R R X X X X X X X X X X=Xpos S=Obj Size (8x8,16x16,32x32,64x64) VH=V/HFlip
R=Rotation parameter
7000004h C C C C P P T T T T T T T T T T T=Tile Number
C=Color palette (16 color mode) P=Priority
7000006h Unused by sprite

Rotation and Scaling

On the GBA and NDS In some modes, Layers BG2 and BG3 can be rotated and scaled. The control of this is performed by registers 4001020h-400103Ch

For the mathematically challenged (Like me) I've created a spreadsheet which helps calculate the correct values for the effect you want... get it Here

NDS Example:

Bit Meanings: S=Sign I=Integer F=Float

Address Function 
Name Bits Default
0x4001020 
BG2PA BG2 Rotation/Scaling Parameter A (dx) SIIIIIIIFFFFFFFF 0x0100
0x4001022 BG2PB BG2 Rotation/Scaling Parameter B (dmx) SIIIIIIIFFFFFFFF 0x0000
0x4001024 BG2PC BG2 Rotation/Scaling Parameter C (dy) SIIIIIIIFFFFFFFF 0x0000
0x4001026 BG2PD BG2 Rotation/Scaling Parameter D (dmy) SIIIIIIIFFFFFFFF 0x0100
0x4001028 BG2X BG2 Reference Point X-Coordinate ----SIIIIIIIIIIIIIIIIIIIFFFFFFFF  0x00000000
0x400102C BG2Y BG2 Reference Point Y-Coordinate ----SIIIIIIIIIIIIIIIIIIIFFFFFFFF 0x00000000
0x4001030 BG3PA BG3 Rotation/Scaling Parameter A (dx) SIIIIIIIFFFFFFFF 0x0100
0x4001032 BG3PB BG3 Rotation/Scaling Parameter B (dmx) SIIIIIIIFFFFFFFF 0x0000
0x4001034 BG3PC BG3 Rotation/Scaling Parameter C (dy) SIIIIIIIFFFFFFFF 0x0000
0x4001036 BG3PD BG3 Rotation/Scaling Parameter D (dmy) SIIIIIIIFFFFFFFF 0x0100
0x4001038 BG3X BG3 Reference Point X-Coordinate ----SIIIIIIIIIIIIIIIIIIIFFFFFFFF 0x00000000
0x400103C BG3Y BG3 Reference Point Y-Coordinate ----SIIIIIIIIIIIIIIIIIIIFFFFFFFF 0x00000000






Learn Assembly for the Greatest Classic Processors:  Z80 - 6502 - 68000 - 8086 - ARM
Visit www.ChibiAkumas.com and www.ChibiAliens.com to get my games and their source code! | Support me on patreon

 

View Options
Default Dark
Simple (Hide this menu)
Print Mode (white background)

Top Menu
***Main Menu***
Youtube channel
Patreon
Introduction to Assembly (Basics for absolute beginners)
Amazon Affiliate Link
AkuSprite Editor
ChibiTracker
Dec/Bin/Hex/Oct/Ascii Table

Alt Tech
Archive.org
Bitchute
Odysee
Rumble
DailyMotion
Please note: I wlll upload more content to these alt platforms based on the views they bring in

Z80 Content
***Z80 Tutorial List***
Learn Z80 Assembly (2021)
Learn Z80 Assembly (old)
Hello World
Simple Samples
Advanced Series
Multiplatform Series
Platform Specific Series
ChibiAkumas Series
Grime Z80
Z80 Downloads
Z80 Cheatsheet
Sources.7z
DevTools kit
Z80 Platforms
Amstrad CPC
Elan Enterprise
Gameboy & Gameboy Color
Master System & GameGear
MSX & MSX2
Sam Coupe
TI-83
ZX Spectrum
Spectrum NEXT
Camputers Lynx

6502 Content
***6502 Tutorial List***
Learn 6502 Assembly
Advanced Series
Platform Specific Series
Hello World Series
Simple Samples
Grime 6502
6502 Downloads
6502 Cheatsheet
Sources.7z
DevTools kit
6502 Platforms
Apple IIe
Atari 800 and 5200
Atari Lynx
BBC Micro
Commodore 64
Commodore PET
Commander x16
Super Nintendo (SNES)
Nintendo NES / Famicom
PC Engine (Turbografx-16)
Vic 20

68000 Content
***68000 Tutorial List***
Learn 68000 Assembly
Hello World Series
Platform Specific Series
Simple Samples
Grime 68000
68000 Downloads
68000 Cheatsheet
Sources.7z
DevTools kit
68000 Platforms
Amiga 500
Atari ST
Neo Geo
Sega Genesis / Mega Drive
Sinclair QL
X68000 (Sharp x68k)

8086 Content
Learn 8086 Assembly
Platform Specific Series
Hello World Series
Simple Samples
8086 Downloads
8086 Cheatsheet
Sources.7z
DevTools kit
8086 Platforms
Wonderswan
MsDos

ARM Content
Learn ARM Assembly
Learn ARM Thumb Assembly
Platform Specific Series
Hello World
Simple Samples
ARM Downloads
ARM Cheatsheet
Sources.7z
DevTools kit
ARM Platforms
Gameboy Advance
Nintendo DS
Risc Os

Risc-V Content
Learn Risc-V Assembly
Risc-V Downloads
Risc-V Cheatsheet
Sources.7z
DevTools kit

MIPS Content
Learn Risc-V Assembly
Platform Specific Series
Hello World
Simple Samples
MIPS Downloads
MIPS Cheatsheet
Sources.7z
DevTools kit
MIPS Platforms
Playstation
N64

PDP-11 Content
Learn PDP-11 Assembly
Platform Specific Series
Simple Samples
PDP-11 Downloads
PDP-11 Cheatsheet
Sources.7z
DevTools kit
PDP-11 Platforms
PDP-11
UKNC

TMS9900 Content
Learn TMS9900 Assembly
Platform Specific Series
Hello World
TMS9900 Downloads
TMS9900 Cheatsheet
Sources.7z
DevTools kit
TMS9900 Platforms
Ti 99

6809 Content
Learn 6809 Assembly
Learn 6309 Assembly
Platform Specific Series
Hello World Series
Simple Samples
6809 Downloads
6809/6309 Cheatsheet
Sources.7z
DevTools kit
6809 Platforms
Dragon 32/Tandy Coco
Fujitsu FM7
TRS-80 Coco 3
Vectrex

65816 Content
Learn 65816 Assembly
Hello World
Simple Samples
65816 Downloads
65816 Cheatsheet
Sources.7z
DevTools kit
65816 Platforms
SNES

eZ80 Content
Learn eZ80 Assembly
Platform Specific Series
eZ80 Downloads
eZ80 Cheatsheet
Sources.7z
DevTools kit
eZ80 Platforms
Ti84 PCE

IBM370 Content
Learn IBM370 Assembly
Simple Samples
IBM370 Downloads
IBM370 Cheatsheet
Sources.7z
DevTools kit

Super-H Content
Learn SH2 Assembly
Hello World Series
Simple Samples
SH2 Downloads
SH2 Cheatsheet
Sources.7z
DevTools kit
SH2 Platforms
32x
Saturn

PowerPC Content
Learn PowerPC Assembly
Hello World Series
Simple Samples
PowerPC Downloads
PowerPC Cheatsheet
Sources.7z
DevTools kit
PowerPC Platforms
Gamecube

Work in Progress
ChibiAndroids

Misc bits
Ruby programming









Buy my Assembly programming book
on Amazon in Print or Kindle!


Buy my Assembly programming book





Available worldwide!
Search 'ChibiAkumas' on
your local Amazon website!
Click here for more info!


























































































Buy my Assembly programming book
on Amazon in Print or Kindle!


Buy my Assembly programming book





Available worldwide!
Search 'ChibiAkumas' on
your local Amazon website!
Click here for more info!


























































































Buy my Assembly programming book
on Amazon in Print or Kindle!


Buy my Assembly programming book





Available worldwide!
Search 'ChibiAkumas' on
your local Amazon website!
Click here for more info!