BSAVE-BLOAD?

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

BSAVE-BLOAD?

Post 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: .
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} »

I think that you need to use SADD() instead of VARSEG() :lol:
Image
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post 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))
Guest

Post 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. :)
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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,. :)
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User name

about that code

Post by User name »

Hi, I'm learning this method too, could some explain a lit more?
User name

about that code

Post by User name »

Hi, I'm learning this method too, could someone explain a lit more?
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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....
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Or, use the QB standard extension: .PUT
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

excuse me?
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

I was talking about the .PUT which you didn't put in there, no pun intended.
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Ya I knew that looked familiar... :lol:

So you say use .put instead of .gfx? right?
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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..
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Guest

Post 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]
Post Reply