Author Topic: Simple Bank To Dim Conversion  (Read 3507 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Simple Bank To Dim Conversion
« on: July 13, 2006 »
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.

Code: [Select]
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:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17407
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Simple Bank To Dim Conversion
« Reply #1 on: July 14, 2006 »
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;

Code: [Select]
Dim SCREEN_ARRAY ( XRES , YRES )

In something like Blitz.

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

Code: [Select]
SCREEN_ARRAY ( 100 , 100 ) = 1

Or whatever value you want to write into there.

you could then update your screen like this;
Code: [Select]
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;
Code: [Select]
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;

Code: [Select]
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.
« Last Edit: July 14, 2006 by Shockwave »
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: Simple Bank To Dim Conversion
« Reply #2 on: July 14, 2006 »
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: