Game Boy Advance >> Assembly
BG Mode 2(text)
參考資訊:
1. doc
2. tonc
3. gbaasm
3. devkitPro
4. devkitarm-crtls
5. GBA-By-Example-3
6. devkitPro website
7. Compiling GBA programs on Linux with GCC
BG Character Data和BG Screen Data共用同一份記憶體
BG Character Data:Base Block 0~3共4塊(大小:0x4000),使用哪一塊記憶體,由BGxCNT的bit3~bit2決定
BG Screen Data:Base Block 0~31共32塊(大小:0x800),使用哪一塊記憶體,由BGxCNT的bit12~bit8決定
BG Character Data固定為8x8(64Bytes),每個Byte用來指定Palette的顏色索引
BG Screen Data每一個點使用1Byte表示,用來指定BG Character Data的索引
Palette有兩種方式可以選擇:
1. 16個Palette(每個Palette有16個顏色可以配置)
2. 1個Palette(有256個顏色可以配置)
每個顏色由15bits組成(RGB各別使用5bits表示)
DISPCNT,BG0~3是代表要使用哪個BGxCNT暫存器(BG0CNT~BG3CNT),在此次練習,設定成BG Mode 2、BG2
BG Mode對應的解析度
BG Mode 2可以使用BG2~BG3,支援text/rotation/scaling
BG2CNT,在此次練習,設定成Character Base Block(0),Color Mode(256 colors x 1 palette),Screen Base Block(1)
Screen Size
main.s
.equ DISPCNT, 0x4000000 .equ BG2CNT, 0x400000c .equ PALETTE_RAM, 0x5000000 .equ VRAM, 0x6000000 .global main .arm .text main: ldr r0, =DISPCNT ldr r1, =0x402 strh r1, [r0] ldr r0, =BG2CNT ldr r1, =0x180 strh r1, [r0] ldr r0, =PALETTE_RAM ldr r1, =palette ldr r2, =4 1: ldrh r3, [r1], #2 strh r3, [r0], #2 subs r2, r2, #1 bne 1b ldr r0, =VRAM ldr r1, =tile ldr r2, =(64 * 2) 1: ldrb r3, [r1], #1 strb r3, [r0], #1 subs r2, r2, #1 bne 1b ldr r0, =(VRAM + 2048) ldr r1, =0x00010001 str r1, [r0] 2: b 2b palette: .2byte 0x0000, 0x001f, 0x03e0, 0x7c00 tile: .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 .byte 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 .byte 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03 .byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 .byte 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 .byte 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02 .byte 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03
P.S. tile指的就是BG Character Data
完成