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.

Beginners > Line drawer

#18874 - anoneem - Wed Apr 07, 2004 5:48 pm

Hi! I'm learning asm from gbaguy's tutorial and finished Day 2. I tried to write a program wich is drawing a line (i don't know is that way of drawing okay, becaouse i had never read how to do it). Here's code:

;start
@include screen.h
@textarea

program ;label

ldr r4,=2410 ;x

ldr r5,=100 ;line 100px

ldr r3,=0 ;counter

ldr r1,=REG_DISPCNT ;r1=0x04000000

ldr r2,=(BG2_ENABLE|MODE_3) ;r2=0x403

str r2,[r1] ;Mode3 on

ldr r1,=0x0FF ;colour in r1

ldr r2,=vram+r4 ;pixel position

str r1,[r2] ;draw point

ADD r3,r3,1 ;add 1 to r3

CMP r3, r5 ;cmp r3 with r5

BLT rysuj ;go to rysuj

BEQ koniec ;go to koniec

rysuj ;label draw

ADD r4,r4,1 ;add 1 to r4

str r1,[r2] ;draw point

B program ;go to program

koniec ;label koniec

@pool ;asm shits
@endarea ;koniec

Compiler pointed only one error, but I'm sure there are more of them :).

#18875 - anoneem - Wed Apr 07, 2004 5:54 pm

Ofcourse i shown that code to hear from You what's bad in it.

#18878 - poslundc - Wed Apr 07, 2004 6:46 pm

anoneem wrote:
Compiler pointed only one error, but I'm sure there are more of them :).


So are you planning on telling us what the compiler pointed out?

Dan.

#18881 - sajiimori - Wed Apr 07, 2004 7:12 pm

You need to put colons after labels.

#18922 - anoneem - Thu Apr 08, 2004 10:13 am

No, problem is elswere...

ldr r2,=vram+r4 ;pixel position
expression not constant

So such thing as adding register to memory addres is bad? How would I do that to make a working program?

#18932 - Lupin - Thu Apr 08, 2004 1:11 pm

you first need to load vram into a register and then index it with r4, i think it is like this:

Code:

ldr r2,=vram
ldr r2,[r2,r4]


this will load the memory address of vram into r2 and then it will load "vram[r4]". Note: r4 got to be a byte offset!

This is because the arm instructions are not able to load a 32 bit address and also add a register to it in one instructions because the instructions themself are only 32 bit long.
_________________
Team Pokeme
My blog and PM ASM tutorials

#18935 - poslundc - Thu Apr 08, 2004 2:12 pm

You really shouldn't have stopped at day 2 of the tutorial.

Dan.

#18936 - Lupin - Thu Apr 08, 2004 2:18 pm

Oh, i forgot about the fact that ldr or str is always loading/storing a 32 bit value, for vram writes/reads you will most likely want to use ldrh and strh, they only write/read 16 bits (You can write 32 bits into vram though, but that way you'd draw 2 pixels in mode 3/5 and 4 pixels in mode 4). If you use mode4, be aware that you have to write 2 pixels at once (you can't write 8 bit values to vbuffer because the memory only supports 16/32 bit writes).

I agree with poslundc, you should really read the rest of the tutorial (reading a "day" of the tutorial doesn't mean it should take you a day to read it :P)
_________________
Team Pokeme
My blog and PM ASM tutorials

#18952 - anoneem - Thu Apr 08, 2004 4:49 pm

Than You for informations. I will try to understand them, when I get vocabulary (my poor english :P) :).

"you should really read the rest of the tutorial"

Ofcourse, that stopping on the beginning of tutorial isn't the way to became a programmer. All I want to do is to check, what I have learned :). Just a test.