Game Boy Advance >> Assembly

BG Mode 4(bitmap)


參考資訊:
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 Mode 4支援bitmap(每一個像素點的顏色,由使用者指定),固定使用BG2CNT


每一個像素點的顏色由1Byte表示(256種顏色的索引),像素填充的起始位址是0x6000000


2 frame buffers


BG Mode對應的解析度


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, =0x404
    strh r1, [r0]

    ldr r0, =BG2CNT
    ldr r1, =0x0000
    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, =0x03020100
    str r1, [r0]
2:
    b 2b
   
palette:
    .2byte 0x0000, 0x001f, 0x03e0, 0x7c00

完成


返回上一頁