Page 1 of 2

BSAVE-BLOAD?

Posted: Sat Jan 15, 2005 8:03 pm
by Rattrapmax6
Right, I learned this trick on QB1.1, but I don't know if its 7.1, or if I doing it wrong, but after I BSAVE my pic, I get a Error when I go to BLOAD. I'm not sure what it is, I just get :

QuickBasic Extended has preformed illegial task...

This is what I'm using:

Code: Select all

SCREEN 13
DIM pic(100)
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
DATA 0,0,0,0,0,0,0,0,0,0 
FOR y = 1 TO 10
    FOR x = 1 TO 10
       READ z
       PSET (x, y),z
    NEXT
NEXT
GET (1, 1)-(10, 10), pic
DEF SEG = VARSEG(pic(0))
BSAVE "Pic.gfx", 0, 10000
DEF SEG
Now heres what I put n my other program to load it...

Code: Select all

SCREEN 13
DIM pic(100)
DEF SEG = VARSEG(pic(0))
BLOAD "Pic.gfx", 0
DEF SEG
Then I'll CLS n PUT it on the screen, but when I exit n run again, I get the message like above... :roll: It really doesn't matter, I was going to try to use this to cut down on Program Lines so I don't have to make many chains. But, if any one knows what might be the problem, post a reply, :wink: .

Posted: Sat Jan 15, 2005 8:29 pm
by {Nathan}
I think that you need to use SADD() instead of VARSEG() :lol:

Posted: Sun Jan 16, 2005 7:12 am
by Nodtveidt
SADD is for String ADDress and isn't the solution here. The real problem here is that you're overwriting memory. First of all, you're BSAVEing 10000 bytes, and trying to load those 10000 bytes into a 202 byte array...that is assuming you're using Integer arrays (whicih you should be). You need to save the amount of data you're actually going to use, not just a big number.

Code: Select all

arraySize = SpriteWidth * SpriteHeight / 2 + 1
Dim mySprite(arraySize) As Integer
To properly use BSAVE, you use a similar formula:

Code: Select all

bsaveSize = SpriteWidth * SpriteHeight + 4
Def Seg = VarSeg(mySprite(0))
Bsave "mysprite.gfx", VarPtr(mySprite(0)), bsaveSize
That should work fine. To load it, you've almost got it right, but you're forgetting a minor detail:

Code: Select all

Def Seg = VarSeg(mySprite(0))
Bload "mysprite.gfx", VarPtr(mySprite(0))

Posted: Sun Jan 16, 2005 8:34 am
by Guest
Right, I picked this out a example from, either Mallard, or Vic... :roll: , N thanks Nekrophidius, I'll try it! :wink: Hopefully this will cut down on MB. :)

Posted: Sun Jan 16, 2005 8:47 am
by Rattrapmax6
Uggh, lol, I forgot to log in :lol: , I might go back 2 bed 2day, oh well, I'll wake up sooner or later,. :roll: ZZzz.. Ne way, thats my post above

Posted: Sun Jan 16, 2005 12:12 pm
by Rattrapmax6
:D Got it!,.. Just loaded (bout 4 hours ago) my 20x20 Spaceship in 6 lines of code unscrach and with out a "illegial" message,. :wink: Thanks 4 the help,. :)

about that code

Posted: Fri Feb 18, 2005 2:56 pm
by User name
Hi, I'm learning this method too, could some explain a lit more?

about that code

Posted: Fri Feb 18, 2005 2:57 pm
by User name
Hi, I'm learning this method too, could someone explain a lit more?

Posted: Fri Feb 18, 2005 3:26 pm
by Mitth'raw'nuruodo
What he's doing he is Taking the DATA paragraph in his program and transferring it to the screen...DATA 02,00,01,00,02 would output: a row of 5 pixels the first green, the second balck, third blue, fourth black, and fifth green....

Next he's using the GET statement to load the image on the screen between the pixels descibed in the GET statement to an image array, which is an INTEGER array between 0 and PixelRow*PixelHeight.

Next he loads it to memory with the BSAVE command...
The array is saved to the file specified with the .gfx exstention.

Then in his main program. He loads from the file with the BLOAD command to another array. Man I got to do that in my program soon...

He the uses the PUT command with that array to output the sprite to the screen. There you go....

Posted: Fri Feb 18, 2005 4:39 pm
by Rattrapmax6
:) Okay,.. here is part of the code I asked this for...

Code: Select all

'Create a 20x20 picture

'Get the array size for GET
arraySize = 20 * 20 / 2 + 1
'DIM the array as a interger
DIM ship1(arraySize) AS INTEGER
'Max X & Y of picture
xl = 20: yl = 20
'Put the picture on the screen
FOR y = 1 TO yl
   FOR x = 1 TO xl
      READ z
      PSET (x, y), z
   NEXT
NEXT
'Capture the picture
GET (1, 1)-(20, 20), ship1
'Get array size for BSAVE
BsaveSize = 20 * 20 + 4
DEF SEG = VARSEG(ship1(0))
'Save the picture on the harddrive
BSAVE "Ship1.xtr", VARPTR(ship1(0)), BsaveSize
DEF SEG
There are REMlines in the code that explain that part, now for loading,.

Code: Select all

'Collect sprite's Max X & Y
SpriteWidth = 20
SpriteHight = 20
'Get the array size
arraysize = SpriteWidth * SpriteHight / 2 + 1
'Put the sprite into a array
DIM SHARED ship1(arraysize) AS INTEGER
DEF SEG = VARSEG(ship1(0))
'Now load it
BLOAD "Ship1.xtr", VARPTR(ship1(0))
And thats all what Mitth said in code form,. hope this helps.. :wink: Read the REMs, they tell you what's going on.. :)

PS: Don't use ".xtr" on your files like I did, use ".gfx" or something that you like thats not already a file extention like ".BMP", ".JPG", or what ever, they would cause a error... stick with ".gfx" to be safe.. :wink:

Posted: Fri Feb 18, 2005 5:58 pm
by Nodtveidt
Or, use the QB standard extension: .PUT

Posted: Fri Feb 18, 2005 6:10 pm
by Mitth'raw'nuruodo
excuse me?

Posted: Fri Feb 18, 2005 6:13 pm
by Rattrapmax6
Oh yeah, thanks Nek,.. .PUT,.. yeah, wy didn't I remeber that, oh well,..

Read the REMs, Mitth, I put em in the code.. :wink:

Posted: Fri Feb 18, 2005 6:15 pm
by Mitth'raw'nuruodo
I was talking about the .PUT which you didn't put in there, no pun intended.

Posted: Fri Feb 18, 2005 6:20 pm
by Rattrapmax6
Yeah, I was really on you can use any you want that are not all ready used by other systems like, well, if you saved under ".BMP", it get messed up I think... I use ".xtr" as you can guess, x.t.r.GRAPHICS.. :wink:

Posted: Fri Feb 18, 2005 6:28 pm
by Mitth'raw'nuruodo
Ya I knew that looked familiar... :lol:

So you say use .put instead of .gfx? right?

Posted: Fri Feb 18, 2005 6:33 pm
by Rattrapmax6
Umm, no, b4 Nek reminded me of PUT,.. I was telling the other dude to use ".gfx" or something else since really,. ".xtr" is for mine... just noting that since in the example I didn't remove it, save I make a mistake in it..

Posted: Fri Feb 18, 2005 6:39 pm
by Mitth'raw'nuruodo
:shock: SO WHAT"S THE .PUT FOR!?!?!?!?!?!? GA!!!! No please continue with your suspense! I can wait....No no, not really SPILL IT OUT!!! AHHH!!! :x

Posted: Fri Feb 18, 2005 6:53 pm
by Rattrapmax6
:shock: DUDE! Mitth, calm down, deep breaths, cont to 10,.. .PUT is just a file extention that MS used for QB as a example I think.. you can use anything you want,. .gfx , .xtr , .bas , .txt , any thing almost, it reads it just the same... I think .BMP and those others "JPG" ect... will mess it up a lil, it might not... :wink: You could use ".mit" if you wanted.. :D

Posted: Fri Feb 18, 2005 8:53 pm
by Guest
Ok I get it better now, see I was wondering because this seem to work with the code I have and I was wondering what might be going on that is diffrent. From what I've got, it's close to what you had setup....

Code: Select all

SCREEN 13
DIM image(0 TO 100) AS INTEGER
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7
DATA 7,7,8,8,8,8,8,8,7,7


FOR Y = 1 TO 10
FOR X = 1 TO 10
READ Z
PSET (X, Y), Z
NEXT
NEXT

GET (1, 1)-(10, 10), image
DEF SEG = VARSEG(image(O))
BSAVE "image.imx", 0, 104
then I did this to load

Code: Select all

SCREEN 13
CLS

DEF SEG = VARSEG(image(0))
BLOAD "image.imx", 0
DEF SEG
PUT (100, 100), image.imx, PSET
DO
LOOP UNTIL INKEY$ <> ""
CLEAR
END

So why is the other way better?[/code]