Skip to content

Instantly share code, notes, and snippets.

@awmc000
Last active February 28, 2025 21:48
Show Gist options
  • Save awmc000/f234e13a73ce1e4557d667a2cce24d3e to your computer and use it in GitHub Desktop.
Save awmc000/f234e13a73ce1e4557d667a2cce24d3e to your computer and use it in GitHub Desktop.
Plotting a pixel on the GameBoy Advance with the GVASM assembler for ARM
// ==================================================================
// ============== Pixel Plotting on GBA with GVASM ==================
// ==================================================================
.stdlib
.def MODE_3 = 0x3
.def BG2_ENABLE = 0x400
.def VRAM = 0x06000000
.def COLOUR = rgb(0, 15, 31)
// Header: Required for ROM to be executed
.begin
.arm
b main
.logo
.title "PLOTPIXEL"
.str "CUNE77"
.i16 150, 0, 0, 0, 0
.i8 0 // version
.crc
.i16 0
.end
.begin main
.arm
.regs r0-r3, x, y, r6-r11
// Set display mode 3 and enable BG2
ldr r0, =REG_DISPCNT
ldr r1, =(MODE_3 | BG2_ENABLE)
strh r1, [r0]
// Set coordinates (x = 120, y = 80)
ldr x, =80
ldr y, =80
// Calculate pixel address: VRAM + (y * 240 + x) * 2
mov r2, #240 // Screen width in pixels
mul r3, y, r2 // y * 240
add r3, r3, x // y * 240 + x
lsl r3, r3, #1 // Multiply by 2 (16 bits per pixel)
ldr x, =VRAM
add r3, x, r3 // VRAM + offset
// Plot the pixel
ldr y, =COLOUR
strh y, [r3]
// Plot some pixels in a line
mov r7, #0
plot:
add r3, #240
add r7, #1
strh y, [r3]
cmp r7, #0x10
blt plot
// Infinite loop
- b -
.pool
.end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment