Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

NovicePgmr

Programmer
Aug 4, 2011
2
CA
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
 
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[red](0)[/red])
Bsave "tile.gfx", varptr(GfxTile[red](0)[/red])

def seg = varseg(GfxTile[red](0)[/red])
Bload "tile.gfx", varptr(GfxTile[red](0)[/red])

-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
 
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

 
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


-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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top