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 > Need a ASM Draw PlotPixel function

#17438 - Gordon - Mon Mar 08, 2004 5:16 am

Need a ASM Draw Plot Pixel function in Mode3

#17440 - DekuTree64 - Mon Mar 08, 2004 6:02 am

As you may have seen, there was a nice post going on about plotting pixels in mode4. Mode3 is much simpler, I'll have a go at doing a fast one.
Code:
@r0 = x
@r1 = y
@r2 = color
.global PlotPixel
.arm
.align 2
.section .iwram, "ax", %progbits
PlotPixel:
rsb   r1, r1, r1, LSL #4    @r1 = y*15
add   r1, r0, r1, LSL #5    @r1 = x+y*15*32 = x+y*480
add   r0, r0, #0x6000000  @r0 = x+VRAM base
strh   r2, [r0, r1]            @this comes out to VRAM base+x*2+y*480
bx     lr

What do you think? Aside from inlining to get rid of the bx, I don't see how you could do it any faster.
As for your horizontal line post, you might want to try doing that one yourself. I'd be happy to give it a try later, but it's a pretty simple problem and could be optimized quite nicely. A very good chance to practice. A few tips: First, get your base address similar to this pixel plotter. Then store with writeback on the first pixel before going into a loop. That way you can use strh r2, [r0, #2]! for each consecutive pixel.
Or you can orr the color into the upper 16 bits and store 2 pixels at a time. You'll have to check for odd endpoints though.
Also, unroll your loop a few times to save a lot of comparing.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku