Game Boy Advance >> Assembly

BG Mode 0(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 DataBG 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每一個點使用2Bytes表示,用來指定BG Character Data的索引


Palette有兩種方式可以選擇:
1. 16個Palette(每個Palette有16個顏色可以配置)
2. 1個Palette(有256個顏色可以配置)


每個顏色由15bits組成(RGB各別使用5bits表示)


DISPCNT,BG0~3是代表要使用哪個BGxCNT暫存器(BG0CNT~BG3CNT),在此次練習,設定成BG Mode 0、BG0


BG Mode對應的解析度


BG Mode 0可以使用BG0~BG3,全部都是text模式(也就是一般的tile顯示方式)


BG0CNT,在此次練習,設定成Character Base Block(0),Color Mode(256 colors x 1 palette),Screen Base Block(1)


Screen Size


main.s

    .equ DISPCNT,     0x4000000
    .equ BG0CNT,      0x4000008
    .equ PALETTE_RAM, 0x5000000
    .equ VRAM,        0x6000000

    .global main
      
    .arm
    .text
main:
    ldr r0, =DISPCNT
    ldr r1, =0x100
    strh r1, [r0]

    ldr r0, =BG0CNT
    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, =0x0001
    strh 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

完成


返回上一頁