INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Bsave and Bload pixel tiles... String Space Corrupt?

Bsave and Bload pixel tiles... String Space Corrupt?

Bsave and Bload pixel tiles... String Space Corrupt?

(OP)
I am trying to save a series of tiles for a game in one or more Bsave files so that my main program can use Bload to grab the tiles without having to clutter up the program with excessive DATA statements.

I can draw place the tiles easily enough using DATA, READ, GET, and PUT but when I try to save a tile with one program and load it with another a get the "String Space Corrupt" error.

Here's the code I'm using:
_____________

screen 9

dim GxfTile(400)

data 0,0,0,...  'a DATA block 20x20 characters big to produce
                 tile graphic

for y 1 to 20: for x 1 to 20
  read NextPixel  
  pset (x,y), NextPixel
next x: next y

get (1,1)-(20,20), GfxTile

def seg = varseg(GfxTile)
Bsave "tile1.gfx", varptr(GfxTile),400

----------------

This much works, at least to the Get statement, the tile is drawn and I can redraw the tile with Put as I please. Is there something wrong with the Def Seg and Bsave portion?
Maybe the Dim, or do I need $Static or $Dynamic? Or is it in how I'm loading it here:


----------------------
'Second, seperate program ment to Bload and Put the tile on screen

screen 9

dim GfxTile(400)

def seg = varseg(GfxTile)
Bload "tile.gfx", varptr(GfxTile)
'<<-- It breaks here (or the line above I suppose) with String Space Corrupt.

Put(1,1), GfxTile

____________________

Is it something simple I'm missing? Any help would be  greatly appreacted.

I made a game years ago with dozens of tiles like the 20x20 block above and I'm fairly sure I used Bload to load them into the main program.

Thanks in advance,
CJ

RE: Bsave and Bload pixel tiles... String Space Corrupt?

It's been a LONG time but I think I see the error.

A) I assume it's just a typo in the post but program1 BSAVEs "tile1.gfx" and program2 BLOADs "tile.gfx"

OR

B) What is the size of you .gfx file.  Is it zero?  Your varseg and varptr need to reference an element in the GfxTile array.  Otherwise, the memory pointers won't point to an address in which to start loading the image, thus causing an error.  I THINK!

set the memory pointers to the beginning of the GfxTile array by reference the first element.  Do this for both BSAVE and BLOAD.  

CODE

def seg = varseg(GfxTile(0))
Bsave "tile.gfx", varptr(GfxTile(0))

def seg = varseg(GfxTile(0))
Bload "tile.gfx", varptr(GfxTile(0))

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again.  Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 

RE: Bsave and Bload pixel tiles... String Space Corrupt?

(OP)
Ah, that was it!

The typo was just that, it was the (0) I was missing. I think I see how it works in a larger framework as well with other statements, and I suppose I could Bload several tiles into GfxTile if I use something like this..?
--------------
def seg = varseg(GfxTile(0))
Bload "tile1.gfx", varptr(GfxTile(0))

def seg = varseg(GfxTile(1))
Bload "tile2.gfx", varptr(GfxTile(1))

ect...

-------------
If not I'm sure a work around would be possible, at least this is a great start. Thanks, Geates, for your help!

CJ

 

RE: Bsave and Bload pixel tiles... String Space Corrupt?

Yes, if your tiles were 1x1 pixels.  In you example, you are loading tile1.gfx at memory location 1 of GfxTile.  Then loading tile2.gfx at memory location 2 of GfxTile.  So the 2nd tile will overwrite the data loaded by the first.

Because your tiles are 20x20, each tile will need 400 addresses in memory (x * y). Furthermore, in SCREEN 9, a pixel is only 4 bits.  Each index in an array is 1 byte (8 bits).  Therefore, each index in your GfxTile array can hold 2 pixels per index ((x * y) / 2). And whats more, is because indexing starts at zero and not one, unless explicitly defined otherwise, the size of your gfxTiles is ((x * y) / 2) - 1.  

Follow this formula when dimensioning array for graphics.
(((x-pixels * y-pixels) / 2) * numOfTiles) - 1

DIM OneTile(199) '(((20 x 20) / 2) * 1) - 1
DIM TwoTiles(399) '(((20 x 20) / 2) * 2) - 1
DIM OneTile(1999) '(((20 x 20) / 2) * 10) - 1

CODE

DIM GfxTile(399)

def seg = varseg(GfxTile(0))
Bload "tile1.gfx", varptr(GfxTile(0))

def seg = varseg(GfxTile(200))
Bload "tile2.gfx", varptr(GfxTile(200))


Better yet, dim your GfxTile as a 2-dimensional array.  DIM GfxTiles (numOfTile, sizeOfTile) AS INTEGER and then load each tile.

CODE

DIM GfxTiles (9, 199) AS INTEGER

def seg = varseg(GfxTiles(0, 0))
Bload "tile0.gfx", varptr(GfxTiles(0, 0))

def seg = varseg(GfxTile(1, 0))
Bload "tile1.gfx", varptr(GfxTile(1, 0))

def seg = varseg(GfxTile(2, 0))
Bload "tile2.gfx", varptr(GfxTile(2, 0))

...

def seg = varseg(GfxTile(9, 0))
Bload "tile10.gfx", varptr(GfxTile(9, 0))

Even better, loop it.

CODE


DIM GfxTiles (9, 199) AS INTEGER

for i = 0 to 9
    def seg = varseg(GfxTiles(i, 0))
    fileName$ = "tile" + i + ".gfx"
    bload fileName$, varptr(GfxTiles(i, 0))
loop

http://www.angelfire.com/scifi/nightcode/prglang/qbasic/function/devices/bsave_bload.html

-Geates

"I hope I can feel and see the change - stop the bleed inside a feel again.  Cut the chain of lies you've been feeding my veins; I've got nothing to say to you!"
-Infected Mushroom

"I do not offer answers, only considerations."
- Geates's Disclaimer
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close