Compiling your first GBA asm binary

headkaze · 11064

Offline headkaze

  • Administrator
  • Blue Gene Super Computer
  • **********
    • Posts: 7838
on: December 19, 2008, 11:05:22 pm
1. If you haven't already followed the Setting up the compiler I suggest you do that first
2. Create a folder called devkitPro\source\gba\asmtest

Code: [Select]
.arm
.text
.global main
main:
mov r0, #0x4000000
mov r1, #0x400
add r1, r1, #3
str r1, [r0]

mov r0, #0x6000000
mov r1, #0xFF
mov r2, #0x9600
loop1:
strh r1, [r0], #2
subs r2, r2, #1
bne loop1

infin:
b infin

3. Run make
4. Open Visualboy Advanced emulator and open asmtest_mb.gba you should see the attached image
5. Congrats you have just created your first gba binary in assembly!

This code is from GBAGuy's GBA asm tutorial
« Last Edit: December 21, 2008, 06:58:06 pm by headkaze »



Offline headkaze

  • Administrator
  • Blue Gene Super Computer
  • **********
    • Posts: 7838
Reply #1 on: December 21, 2008, 06:59:57 pm
Next example we will display a picture on screen

Code: [Select]
.arm
.text
.global main
main:
mov r0, #0x4000000
mov r1, #0x400
add r1, r1, #3
str r1, [r0]

mov r0, #0x6000000
ldr r1,=picBitmap
mov r3, #0x4B00
loop:
ldr r2,[r1],#4
str r2,[r0],#4
subs r3,r3,#1
bne loop

infin:
b infin



Offline headkaze

  • Administrator
  • Blue Gene Super Computer
  • **********
    • Posts: 7838
Reply #2 on: December 21, 2008, 09:01:28 pm
An example from GBAGuy's GBA asm tutorial is a simple demo to play sound

Code: [Select]
#include "sound.h"

.arm
.text
.global main

main:
    SoundOn                                                   @ Step 1: My macro that turns the sound circut on in REG_SOUNDCNT_X
                                                                   @ note no 'x' for sound channel number. REG_SOUNDCNT_X controls entire circut.

    S1_Enable                                                 @ Step 2: My macro to enable Sound Channel 1. S2_Enable is channel 2... to 4.

    ldr r1,=REG_SOUND1CNT_L                           @ in these two lines I do steps 3&4 at once. since these
    ldr r0,=0xf7800056                                     @ registers are 16bit, we can do both at once.
    str r0,[r1]                                                 @ store data for steps 3&4.

    ldr r1,=REG_SOUND1CNT_X                          @ Step 5: Load the register. 
    ldr r0,=0x8400   @ This register has something to do with choosing
    str r0,[r1]                                                 @ between the different stuff a channel can do such as Square wave or

loop:
    b loop
« Last Edit: December 21, 2008, 09:03:03 pm by headkaze »