gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Plotting a Pixel

#19858 - dagamer34 - Mon Apr 26, 2004 11:26 pm

I have decided to learn some ARM assebly so the first thing I wrote was a mode 3 pixel plotter (since it's supposed to be simple) but it doesn't seem to work exactly like it's supposed to. Somewhere my multiplication is off, and I get a pixel in the totally wrong place. Here's the code:

Code:

@Asm file

@ As declared in a C++ file
@ extern "C" { void func (u32 x, u32 y, u32 color); }

@ Plots a pixel in mode 3
     .global func
     .section .iwram
     .arm
     .align 2
func:
    mov r1, r1, lsl #8     @ Multiply the Y address by 240
    sub r1, r1, r1, lsr #8
    mov r3, #0x6000000     @ Load the VRAM address
    add r1, r3, r1         @ Add the VRAM address to the Y address
    add r1, r0, r1         @ Add the X offset to the Y address
    strh r2, [r1]          @ Store the pixel
    bx lr

_________________
Little kids and Playstation 2's don't mix. :(

#19862 - sajiimori - Tue Apr 27, 2004 12:27 am

The VRAM offset you computed is measured in half-words. Before you add it to the VRAM address, shift it left a bit to get the offset in bytes.

#19865 - dagamer34 - Tue Apr 27, 2004 12:45 am

No difference.

Code:

@ Plots a pixel in mode 3
     .global func
     .section .iwram
     .arm
     .align 2
func:
    mov r1, r1, lsl #8     @ Multiply the Y address by 240
    sub r1, r1, r1, lsr #8
    mov r3, #0x6000000     @ Load the VRAM address
    mov r12, r3, lsl #1   @ Shift left the VRAM address to get it measured in bytes
    add r1, r12, r1         @ Add the VRAM address to the Y address
    add r1, r0, r1         @ Add the X offset to the Y address
    strh r2, [r1]          @ Store the pixel
    bx lr

_________________
Little kids and Playstation 2's don't mix. :(

#19868 - Miked0801 - Tue Apr 27, 2004 1:29 am

Code:

func:
    mov r3, r1, lsl #9      @ Multiply the Y address by 512
    sub r3, r1, r1, lsl #5  @ - 32 * Y  == 480 * y (240 * 2)
    add r3, r3, r0, lsl #1  @ Add the X offset (*2) to the Y address
    add r3, r3, #0x6000000  @ Add the VRAM address
    strh r2, [r3]           @ Store the pixel
    bx lr


Same idea, but making sure to mul both X and Y components by 2. I believe the original problem is with your mul by 240 though I may be incorrect. Untested as I'm at home, but I think mine will do the job quickly. Too bad we're in half-word mode or we could get rid of 1 more instruction by using addressing to do an add or shift. A double pixel plotter might be in order to do that and be a bit faster perhaps.

Mike

#19869 - dagamer34 - Tue Apr 27, 2004 1:45 am

Still nothing...

I'm not sure what's the problem.
_________________
Little kids and Playstation 2's don't mix. :(

#19873 - sajiimori - Tue Apr 27, 2004 2:42 am

You multiplied the VRAM base address by 2, which makes no sense -- VRAM really is at 0x6000000, not 0xC000000. I was talking about the offset.

#19883 - FluBBa - Tue Apr 27, 2004 10:57 am

I think this thread has it right.
_________________
I probably suck, my not is a programmer.