RetroBytes Portal
Programming => Gameboy Advance & Nintendo DS Coding => Topic started by: headkaze on December 19, 2008, 11:05:22 pm
-
1. If you haven't already followed the Setting up the compiler (https://retrobytesportal.gameex.com/index.php?topic=65.0) I suggest you do that first
2. Create a folder called devkitPro\source\gba\asmtest
.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 (http://patater.com/gbaguy/gbaasm.htm)
-
Next example we will display a picture on screen
.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
-
An example from GBAGuy's GBA asm tutorial (http://patater.com/gbaguy/gbaasm.htm) is a simple demo to play sound
#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