• Welcome to Dark Bit Factory & Gravity.
 

Simple Bank To Dim Conversion

Started by Clyde, July 13, 2006

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Clyde

I thought this might be of benefit to some of you, especially people like me who are just getting accustomed to using banked arrays from along time of using the good old Dim(x,y) ways of storing and manipulating info. Especially usefull with imagary antics.


For Y=0 to Height-1
        For X=0 to Width-1
           
            DimData(X,Y)=BankData( X + ( Y * Width ))
       
      Next
Next


Hope it's of some use,
Cheers Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won:

Shockwave

#1
Mmmm.. It might be a little tiny bit unclear what you are referring to there clyde so for less experienced coders, basically Clyde is showing a technique used for array access, usually this technique will apply to a screen.

You may be used to doing;


Dim SCREEN_ARRAY ( XRES , YRES )


In something like Blitz.

Let's suppose that you wanted to put a dot into screen pos 100,100;


SCREEN_ARRAY ( 100 , 100 ) = 1


Or whatever value you want to write into there.

you could then update your screen like this;

for y=0 to yres-1
for x=0 to xres-1

plot x,y , SCREEN_ARRAY ( X , Y )

next
next


Nice and simple.
However, Banks are faster and also in Freebasic the tinyptc library updates it's screen from a sequential buffer (one dimensional array), this is how you'd do it;

CONST WIDTH  = 640
CONST HEIGHT = 480
DIM SHARED AS INTEGER SCREEN_ARRAY ( WIDTH * HEIGHT )


And to access position 100,100 on the screen you need to do this;


X=100
Y=100
POSITION = ( X + ( Y * WIDTH) )
SCREEN_ARRAY ( POSITION ) = 1


PTC_UPDATE@SCREEN_ARRAY(0)  :P

So you can use a 1 dimensional array to simulate a 2 dimensional array like that.
Thanks for the snippet Clyde, most useful and I hope you don't mind me explaining it a little more in depth.
Shockwave ^ Codigos
Challenge Trophies Won:

Clyde

No worries dude, and thank you kindly for explaining it more.

Cheers,
Clyde.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.


Challenge Trophies Won: