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 > Beginner pixel plotting problem

#5674 - bakery2k - Mon May 05, 2003 8:34 pm

I am currently taking my first steps into GBA assembly, using gbaguy's tutorials. I have performed a small modification to tutorial 1, in order to get it to display a line of pixels, rather than just a single one.

However, I do not get 32 consecutive pixels lit, rather 17 with a gap between each. On changing the address increment value to 4, I get the 32 pixels, with a gap between each. What have I done wrong?

Here is my code:

@include screen.h
@textarea

;Set mode 3, enabling BG2
ldr r1,=REG_DISPCNT
ldr r2,=(BG2_ENABLE|MODE_3)
str r2,[r1]

;Load color (green) into r1
ldr r1,=(0x1F << 5)

;Load address into r2
ldr r2,=vram+2410

;Load number of pixels to fill into r3
ldr r3,=0x20


startloop:

;Paint pixel
str r1,[r2]

;update position
add r2, r2, 2

;Update loop
subs r3, r3, 1

;branch if non-zero
bne startloop


;Infinite loop
label1
B label1

@pool
@endarea

Thanks for your help.

#5675 - niltsair - Mon May 05, 2003 8:46 pm

As you could read on the Beginer Forum Faq, video memory is only accessible in 16/32bits. Which mean that you need to write 2/4pixel at a time.

So write 2 pixels at a time and increment your pointer by 2.

#5677 - bakery2k - Mon May 05, 2003 9:10 pm

As far as I was aware, I was accessing video memory 16bits at a time, i.e. a pixel at a time.
It seems I was actually accessing it 32 bits at a time, since the following works:

;Load color (green) into r1
ldr r1,=((0x1F << 5) | (0x1F << 21))

...

startloop:

;Paint pixel
str r1,[r2]

;update position
add r2, r2, 4

;Update loop
subs r3, r3, 1

;branch if non-zero
bne startloop

How do I access vram a pixel at a time?

#5679 - niltsair - Mon May 05, 2003 9:38 pm

Ah, yes.

I think the problem is, you're using 32bits registers with 32bits command.

Look for a 'Ldr' that only works on 16bits. I don't know the exact name for it.

#5683 - Touchstone - Mon May 05, 2003 10:45 pm

LDRH (Load register halfword, 16bit)
LDRB (Load register byte, 8bit)
_________________
You can't beat our meat

#5698 - bakery2k - Tue May 06, 2003 11:32 am

Thanks.

What I actually needed was STRH, i.e. send a 16 bit value to vram, rather than loading the register with a 16 bit value.