### Author Topic: EXTREMELY n00b question...  (Read 1730 times)

0 Members and 1 Guest are viewing this topic.

#### donvito

• n00bzor
• ZX 81
• Posts: 15
• Karma: 1
• programming <3
##### EXTREMELY n00b question...
« on: February 29, 2008 »
Hey guys!

First off, GREAT SITE, I've been looking into learning to code old-school style demos for a long long time, and this site is a great resource.

Basically, I'm sure that my question is going to be ridiculously noobish, but I have to ask.

Essentially, I am trying to modify the "line-drawing" code from the second FB tutorial to make a crosshair in the center of the window.

So far, I've got it centered, and the "left" and "right" of the crosshair, but I cannot get the vertical lines for some reason, I figured it would involve just using Y in place of X and some tweaking, but I can't figure it out.

I know that it writes from left to right, and I think this is my problem.  I feel like such a n00b, but I've never really done any graphics programming before.

heres the code...

Quote
WHILE(1)
X = 320
Y = 240

FOR A = 0 TO 49
BUFFER (X + A +(Y*XRES)) = &HFFFFFF
NEXT

FOR A = 0 TO 49
BUFFER (X - A +(Y*XRES)) = &HFFFFFF
NEXT

FOR A = 0 TO 49
BUFFER (Y + A +(X*YRES)) = &HFFFFFF
NEXT

I know that the framework can do this for me, but I like to learn the dirty, long way to do things purely because then I fully understand it.

Thanks for your help guys, I'm happy to be a new member to this community.

« Last Edit: February 29, 2008 by donvito »

#### zawran

• Pentium
• Posts: 909
• Karma: 67
##### Re: EXTREMELY n00b question...
« Reply #1 on: February 29, 2008 »
Code: [Select]
`FOR A = 0 TO 49    BUFFER (X+(Y+A)*YRES) = &HFFFFFFNEXT`

#### ninogenio

• Pentium
• Posts: 1666
• Karma: 133
##### Re: EXTREMELY n00b question...
« Reply #2 on: February 29, 2008 »
first of welcome to our comunity donvito, stick around you will learn loads of stuff as i have.

secondly thats not a stupid question at all. it's a bit tricky to learn to work with 1d buffers at first i remember doing my head in trying to learn them at first. the way they work is like so.

imagine your screen not as in x,y but just as in x. say you have a 640*480 size screen that would give you a 1d buffer of 307200 pixels. now comes the problem of getting to exact x ,y places in the buffer. well here is a little algo that you have probably seen quite a lot.

Buffer( x + ( Y*ScreenX ) )

now if you want to get too the first pixel in the second row its.

1 + 1*640 = 641

or the first pixel of the second row.

1 + 2*640 = 1281

the thing to remember with 1d buffers is when you come to the end of your screen ie 640 it will wrap around and go down a line so 641 is the first pixel on the second row.

hope that makes sense as im not very good at explaining things
Challenge Trophies Won:

#### donvito

• n00bzor
• ZX 81
• Posts: 15
• Karma: 1
• programming <3
##### Re: EXTREMELY n00b question...
« Reply #3 on: February 29, 2008 »
Hey guys,

Thanks a lot for both replies, that makes things a lot easier to understand!

Thanks again,
donvito

#### donvito

• n00bzor
• ZX 81
• Posts: 15
• Karma: 1
• programming <3
##### Re: EXTREMELY n00b question...
« Reply #4 on: February 29, 2008 »
Code: [Select]
`FOR A = 0 TO 49    BUFFER (X+(Y+A)*YRES) = &HFFFFFFNEXT`

sorry for double post but just wanted to say this works, but the yres needs to be xres

thanks,
donvito

#### zawran

• Pentium
• Posts: 909
• Karma: 67
##### Re: EXTREMELY n00b question...
« Reply #5 on: February 29, 2008 »
I might have switched things around, it was typed on my way to work, so I might have been tired

#### Shockwave

• good/evil
• Founder Member
• Posts: 17376
• Karma: 497
• evil/good
##### Re: EXTREMELY n00b question...
« Reply #6 on: February 29, 2008 »
Welcome Donvito

What you are doing is a great way to get used to the screen buffer. It will just click into place with you the way that a continuous sequence of numbers gets plotted into lines that forms the screen.

The maths for this is pretty simple and what you are making is fine for drawing simple straight lines, there are many many things that can be done to boost the speed for you when you have learned how the screen buffer works.

And please don't apologise for posting any programming question here, they are all welcome.
Shockwave ^ Codigos
Challenge Trophies Won:

#### donvito

• n00bzor
• ZX 81
• Posts: 15
• Karma: 1
• programming <3
##### Re: EXTREMELY n00b question...
« Reply #7 on: March 01, 2008 »
Welcome Donvito

What you are doing is a great way to get used to the screen buffer. It will just click into place with you the way that a continuous sequence of numbers gets plotted into lines that forms the screen.

The maths for this is pretty simple and what you are making is fine for drawing simple straight lines, there are many many things that can be done to boost the speed for you when you have learned how the screen buffer works.

And please don't apologise for posting any programming question here, they are all welcome.

thanks for the welcome.

Yea, it was kinda like DUH when I saw it in action, and now I have a perfectly centered crosshair haha, cool, maybe...  useless? definitely.

I plan on dissecting the scroller tutorial soon.

i love this stuff, very fun.

donvito