fasmarm来编译并运行gba实例

需要下载安装fasmarm(编译器)与VisualBoyAdvance(gba模拟器), bimbo1_3(将图片转为bin文件的程序)

 

下载fasmarm:http://arm.flatassembler.net

ubuntu安装VisualBoyAdvance:sudo apt-get install VisualBoyAdvance

bimbo1:http://gbadev.org/tools.php?showinfo=167

 

源码里面的pic.bin文件是用bimbo转换得来的,用任一 240*160的bmp图片经bimbo得来

 

下面的代码显示了用fasmarm来编译并运行在gba上面的例子,显示一张图片

 

源码 test.asm

-------------------------------------------------------------------------------------

;编译 fasmarm test.asm test.gba

;运行 VisualBoyAdvance test.gba

 

format binary
org   0         ; code starts at offset 0.
use32            ; use 32-bit code.

    b    rom_start



NintendoLogo:
    db    0,0,0,0,0,0,0,0,0,0   ; Nintendo Logo space(156 bytes).
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0,0,0,0,0
    db    0,0,0,0,0,0
GameTitle:
    db    "TEAM DEXOS  "        ; Game Title (12 bytes).
GameCode:
    db    "1234"                ; Game Code (4 bytes).
MakerCode:
    db    "_$"                  ; Maker Code (2 bytes).
FixedValue:
    db    0x96                  ; Fixed value (1 byte).
MainUnit:
    db    0                     ; Main unit code (1 byte).
DeviceType:
    db    0                     ; Device Type (1 byte).
ReservedBytes:
    db    0,0,0,0,0,0,0         ; Reserved (7 bytes)
SoftwareVersion:
    db    0                     ; Software version (1 byte).
ComplementCheck:
    db    0                     ; Complement check (1 byte).
Reserved2:
    db    0,0                   ; Reserved (2 bytes).

BG_affine_src:
    dw 25600    ; I got these values by trial and error.
    dw 25600
    dh 0x6F
    dh 0x45
    dh 0x280
    dh 0x280
    db 0,0


align 4


;********************************;
; Rom start.                     ;
;********************************;

rom_start:
    mov r0, 0x4000000
    mov r1, 0x400
    add r1, r1, 3
    strh r1, [r0]

    ; this is the load code from Chapter 4
    mov r0, 0x6000000
    adr r1, pic     
    mov r2, 0x960
loop1:
    ldmia r1!, { r3,r4,r5,r6,r7,r8,r9,r10 }
    stmia r0!, { r3,r4,r5,r6,r7,r8,r9,r10 }
    subs r2, r2, 1
    bne loop1 

    mov r4, 0x4000000  ; I'll use indexed addressing modes to access
                ; the I/O.
    adr r0, BG_affine_src  ; r0 will be a pointer to the start of the struct.

    mov r1, 0x4000000
    add r1, r1, 0x20   ; r1 will be a pointer to where the BIOS should
                ; write the result of the calculations, I'm going
                ; to have it write directly to the hardware registers.

    mov r2, 1
    eor r3, r3, r3
infin:
wait1:
    ldrh r5, [r4, 6]
    cmp r5, 161         ; wait for vblank.
    bne wait1

    strh r3, [r0, 16]  ; write the angle to the struct
    add r3, r3, 40     ; the angle is a 8:8 fixed point number.

    stmia sp, { r0,r1,r2,r3,r4,r5 }  ; save some registers
    swi 0xE0000    ; call the BIOS routine.
    ldmia sp, { r0,r1,r2,r3,r4,r5 }  ; restore registers

    b infin  ; you'll see a lot of infinite loops


pic:
    file "pic.bin"  ; let's reuse that mode 3 picture data
-----------------------------------------------------------------------------------

 

 

你可能感兴趣的:(gba_dev)