Author Topic: BSAVEing a Bitmap  (Read 794 times)

0 Members and 1 Guest are viewing this topic.

mikeebean

  • Guest
BSAVEing a Bitmap
« on: January 11, 2009, 08:19 AM »
I'm writing a simple program to plot colored squares on the bitmap screen, and I had so much trouble figuring out how to save and load the files afterwards, and using a variable for a filename, that I wanted to post here how I did it. Mostly so that in a year when I want to know again, I can just Google it!

It seems to work fine, but please let me know if my procedures are wrong.

To save the bitmap screen, with A$ = filename:

BSAVE ""+A$+".BT",B15,P8192 TO P16181:REM BITMAP DATA
BSAVE ""+A$+".CO",B15,P7168 TO P8167:REM COLOR DATA

To load the bitmap screen, with A$ = filename:

BLOAD ""+A$+".BT"
BLOAD ""+A$+".CO"

Maybe this'll be useful to others too!
« Last Edit: January 11, 2009, 08:34 AM by mikeebean »

Offline ruthven

  • KIM-1 user
  • **
  • Posts: 13
  • Activity:
    0%
  • Reputation: 0
  • With us since: 21/05/2012
    Years
    • View Profile
Re: BSAVEing a Bitmap
« Reply #1 on: May 30, 2012, 07:48 AM »
Sorry for resurrecting such an old post...  I gave this a shot and actually found it quite useful in reloading graphics I had drawn with a series of DRAW and BOX statements.  The GUI interface I've drawn is so complex that it takes at least 10-15 seconds to render on FAST mode.  But since I've BSAVEd the result of that tedious program, I can BLOAD it back in a split second which is MUCH BETTER!  :)  (not to mention it takes 2 lines of code instead of hundreds)

Now maybe this is a long shot or just a ridiculous question, but is there any way to load this bitmap data in BASIC 2.0 (on a C64)?   I ask because I'd ultimately like to make my program compatible on both machines.  Actually, the only reason I started it in BASIC 7 was for the simplified graphic commands and now that I've got the graphical data stored, I was hoping it might be possible...(?)  though I could not find any mention of BLOAD in the C64 User's Guide...

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: BSAVEing a Bitmap
« Reply #2 on: May 30, 2012, 11:31 PM »
Well the easy way would be to change the load-address in the header of the files to make them compatible with the C64.  A good place for a bitmap on the C64 is bitmap at $e000 (57344) and color at $cc00 (52224).  Then on the C64 you can just LOAD A$+X$,U,1.  The ,1 tells the C64 the file is not BASIC and it will load into the address specified by the file header.
 
This method is because the C64 does not have BSAVE nor BLOAD commands.
 
If you do that, then you will need to change the BLOAD command in your C128 version to specify the correct address (different from C64), like this: BLOAD (A$+".BT"),P8192 and BLOAD (A$+".CO"),P7168.
 
The different address is because the C64 always sees ROM at $1000~$1fff (where the color is stored on the C128) when generating the video display.
 
Of course there are other places you could store the bitmap in C64 mode.  I guess it depends on the compiler you use (assuming you use one).
 
There is another method that does not require changing the load-address of the files.  It involves calling the KERNAL and specifying a custom load address on the C64 (which is how BLOAD on the C128 works).  It involves a bunch of POKE and SYS statements.  Not something I could say how to do off the top of my head.
I'm kupo for kupo nuts!

Offline ruthven

  • KIM-1 user
  • **
  • Posts: 13
  • Activity:
    0%
  • Reputation: 0
  • With us since: 21/05/2012
    Years
    • View Profile
Re: BSAVEing a Bitmap
« Reply #3 on: June 01, 2012, 10:48 AM »
Thanks for pointing me in the right direction--I had a look at some web article about BLOADing on the C64 that was totally beyond me...  but unfortunately I still seem to be in over my head.  Bear with me...  I should start by saying that I really don't understand the above code for BSAVEing/BLOADing--I just plugged it in at the end of my code verbatim and it worked.  In particular, I don't know what the P8192 TO P16181 is referring to--I just assumed it was the screen data.  When you suggest using 57344, do you mean I should type the command:

BSAVE (filename),B15,P57344 TO P65333

I got the second number (65333) by adding 7989 to 57344 (this is the difference between 16181 and 8192, the addresses used in the above example)--is this correct?--perhaps this shows just how little I know about what I'm trying to do here  ::)

Also I should mention that it seems I don't need to BSAVE/BLOAD the color data--my program is in standard bitmap mode and after BLOADing the graphics, they get drawn in whatever color I have set to the foreground.

Oh, and on the C64 end--do I need to be in a certain graphical mode (as the C128 program that creates the picture and BSAVEs it goes to bitmap mode (GRAPHIC 1))?  Sorry...  didn't realize quite what I was getting in to here--forgot how cryptic BASIC 2.0 can be when you take some of those simple BASIC 7 commands (like GRAPHIC) for granted.

So here's what I ended up doing: I had my BASIC 7 program BSAVE the graphics to "(filename)",B15,P57344 TO P65333.  Then in BASIC 2, I setup my program to first clear the screen, then change the background/border and foreground colors to the proper ones by POKEing the appropriate addresses.  Then I attempted to have it load the graphics by having the next line of code go: LOAD "filename",U,1.  The computer then tries to load the file, but the drive just spins endlessly, like it's stuck in a loop.  So I've definitely got something wrong--probably a bunch of things, huh?  ::)

Offline Hydrophilic

  • 128D user
  • *******
  • Posts: 1225
  • Age: 41
  • Location: Earth... still!
  • Activity:
    2.2%
  • Reputation: 232
  • Gender: Male
  • With us since: 25/01/2007
    YearsYearsYearsYearsYearsYears
    • View Profile
    • H2Obsesson
Re: BSAVEing a Bitmap
« Reply #4 on: June 02, 2012, 12:47 AM »
You should not have to re-save your bitmap.  I was referring to changing the load address in the file header.  There is a utility on the 1541, 1571, and 1581 test/demo disks called something like "FIND/CHANGE LOAD ADDRESS".  Well that's over 16 characters so that obviously is wrong.  Sorry I don't have any of them on this PC to examine and say for sure.
 
Anyway, just run the program and give it the name of your original (working) bitmap.  It will tell you the current load address in the file (for example 8192 for bitmap) and ask if you want to change it.  Say yes, and it will ask for the new load address.  Then enter whatever value you need for C64 mode.  For example 57344 if you put your bitmap at $e000 in C64 mode.
 
Because the load address in the file header has been changed, you need to update your C128 program to load to the correct address.  For example BLOAD "PICT.BT",P8192.  This tells it to load to the correct address in the C128 and ignore the address in the file header.
 
Yeah, you are in for a lot of working getting a bitmap program working on the C64.  In my opinion, the only practical ways to do this are with a BASIC language extension or by writing the program in assembly language.  Assmbly is more work for the programmer, while the BASIC extension requires more of the user.
 
Quote from: ruthven
BSAVE (filename),B15,P57344 TO P65333
That will only save garbage onto disk (actually part of the KERNAL ROM).
 
If everything has the same color in your bitmap, then you are correct, you don't need the color data file.  BASIC 7 will automatically set the color memory if your clear the bitmap (GRAPHIC 1,1 for example) before loading your bitmap data.  On the C64, you will need to POKE the correct color value into all 1000 addresses.  Or you can load the color data file.  Considering the (lack of) speed of the 1541, it should be much faster to POKE in the color.
 
If you created your bitmap with GRAPHIC 1 in C128 mode, then you need to set the VIC to hi-res graphics in C64 mode.
 
You should post the code you are using in C64 mode to setup the graphics mode.  That way we can see if things are right.
 
The drive should not spin endlessly loading the bitmap, but it will take several seconds to load the 8K bitmap file in 64 mode (unless you have JiffyDOS or a warp cartridge).
 
Note that BASIC will re-start the program whenever you use LOAD.  You need to set some variable(s) so BASIC does not go into an endless loop.  See the example in the wiki.
 
 
I'm kupo for kupo nuts!

Offline ruthven

  • KIM-1 user
  • **
  • Posts: 13
  • Activity:
    0%
  • Reputation: 0
  • With us since: 21/05/2012
    Years
    • View Profile
Re: BSAVEing a Bitmap
« Reply #5 on: June 02, 2012, 02:01 AM »
Ok, guess I was WAY OFF--no surprise really!  Thanks for taking the time to explain it all.  That really clears things up.

Quote
Yeah, you are in for a lot of working getting a bitmap program working on the C64.  In my opinion, the only practical ways to do this are with a BASIC language extension or by writing the program in assembly language.
Hmm, I'm starting to see that now...  didn't think it would be this hard comparitively.  Now I know why I got a C128 in the first place!  Maybe I should just stick with BASIC 7 for now...

Quote
BSAVE (filename),B15,P57344 TO P65333

That will only save garbage onto disk (actually part of the KERNAL ROM).
Yeah, that's about what it looked like when I tried BLOADing it back in BASIC 7!

Quote
If you created your bitmap with GRAPHIC 1 in C128 mode, then you need to set the VIC to hi-res graphics in C64 mode.
 
You should post the code you are using in C64 mode to setup the graphics mode.  That way we can see if things are right.
Yeah, I thought I'd have to set the graphics mode in BASIC 2, only I have no idea how to do it--I merely got the background, border and foreground colors set with POKE statements.  So I don't really have any code worth posting in this regard.  It's okay though--I'm thinking now maybe I should just forget about doing this in BASIC 2 and concentrate on the C128 version.  My BASIC is just not up to snuff for this.  And I had a look at sprite programming in the C64 manual and it was not encouraging!  :-\


 



Back to top