Is there a way to load BSAVEd images (the basic image format) into a bitmap using allegro?
If you have the definition of the format, you should be able to convert that struct into a bitmap. However, load_bitmap by itself cannot do that.
You can load anything in almost any language (in all serious language) if you know the format of it.
RB
The first 7 bytes are junk - they are only useful for the BASIC interpreter. They contain some segment information, etc. All the bytes aferwards are the raw dump of what you saved using BSAVE.
I would guess that the first 4 bytes are the width and height (2 bytes each). The rest should be the raw pixel data, or a palette of some sort.
I doubt that there is a palette. QBASIC is older than VGA
*shocked*
someone still use grandfather's method to make games,and Bob still remember this super-old format!;D
..anyway you should use Paint/sprite editor or somthing to draw PCX image,then grab these .PCX file by Allegro Grabber,to make games
MUAHAHAHAHAHAHAH!!!
I CAN'T BELIEVE YOU THINK YOU CAN USE THE BLOAD FORMAT IN C/ALLEGRO!
afaik there's no way to know the proper width/heigth of a bsave'd file. byte 6&7 of the header (raw data starts at byte 8) only indicate the total size of data, the programmer has to make sure of proper width by himself!
converting (if you know the correct dimensions) an 8 bit (mode 13 in qbasic) bsaved data into a BITMAP structure, which is 8 bpp (i.e. run the program in 8bpp colour depth, or use create_bitmap_ex();) assume you've loaded the whole bsaved file to memory using fread() to an array of unsigned char with proper dimension:
for(int h=0;h<BSAVED_H;h++) { for(int w=0;w<BSAVED_W;w++) { putpixel(bitmap,w,h,bsaved[(h*BSAVED_W)+w+8]); } }
should do the trick then.
as for palletes I have no clue...
katman: you can read any type of file from c...whatever silly format it is.
I'll try it. Anyways someone asked if people still make games in QB. yep, here is one I have been working on for a long time. It is way better than you would expect (it being coded in QB and all).
http://typosoft.qbasicnews.com/pedxing.put
or no sound version
http://typosoft.qbasicnews.com/pedlite.zip
Heh, time to show my QB backgrounds 
Ga Bhonga, that's not completely true... it depends from what source you bsaved your image.
Bsave stands for Binary Save and AFAIK it was meant as a general way to save blocks of memory to a file. Images came later. Normally QB people use BSAVE to save the entire VGA (mode 13h) screen, doing
def seg=&ha000 bsave "image.bsv", 0, 64000
IIRC that'll save 64000 bytes from address 0xA000:0 (mode 13h framebuffer address in real mode), that's an entire 320x200x8 screen. So no size info is saved, as there's no way to guess it from QB.
When you bsave a GETed sprite though, things are different, as QB stores sprite size information together with the actual bitmap data when GETing a sprite into a buffer...
I think the first word is the width/8 (don't ask me why /8), followed by the height in the next word.
So the format of a bsave file is as follows:
byte desc 0 Identification byte. Must be 0xFD 1-2 Source segment from where the data was saved 3-4 Source offset 5-6 Length of saved data in bytes 7-... the actual data
So if the bsaved data was saved from a GET buffer, you'll also have:
7-8 Width of image / 8 9-10 Height of the image 11-... Image data
Hope it helps coding your own C loading routines
aah, didn't remember GET and PUT at all...::)
How do you use fread to read a whole file and store every byte from that file into an array? Here is what I have so far...
I'm working with a 100x100 sprite bsaved with QB.
int w, h, BH, BW;
int bsaved[5001]; // ((gfxX * gfxY) / 2) + 1
BW = 100;
BH = 100;
FILE *fptr;
fptr = fopen("c:/qbasic/pp/images/cpp.put", "r");
fread(bsaved, 7, 7, fptr);
while (!feof(fptr)) { fread(bsaved, 486, 486, fptr); }
fclose(fptr);
for(int h=0;h<BH;h++)
{ for(int w=0;w<BW;w++)
{ putpixel(screen,h,w,bsaved[(h*BW)+w+8]); }
}
readkey();
This puts garbled pixels on the screen, but they are the right colors!
Obviosly I don't much C or how to use fread.
I had trouble with fread, and the other file stuff, and I still do, heh.
def seg=&ha000
bsave"image.bsv",0,64000
it sucks! ah my eyes!
i hate do ugly(!)lowlevel thing in a Highlevel(kids)interpreter!>:(
GAME MAKERS USE C!:P
it sucks! ah my eyes!
i hate do ugly(!)lowlevel thing in a Highlevel(kids)interpreter!
GAME MAKERS USE C!

Oh yeah, let's start one of these discussions
But that info is kinda cool. It would allow us to write an importer / exporter for QB. There're some nice tools written in QB (mainly RPG related), and allowing to import / export data in that format might be very helpful (if you're doing a sprite editor for example).
It would allow you to adopt the complete QB userbase, which is still rather larger. It would also give some of the QB guys a nicer start in C coding (and maybe even enough motivation to switch).
To be honest, I never thought the BLOAD/ BSAVE format was specified... or has somebody reverse engineered it?
Here's an (untested) little function that should work like the other Allegro load_* image loading functions; if it finds additional data appended to the file it'll store it as palette data into the palette parameter, otherwise palette will remain unchanged.
I'm assuming you only need to load GETed images saved with bsave. I'll also assume your images are mode 13h sprites, so 8bit only.
Another thing: I suspect the width/8 stored into a bsaved sprite file like I said was wrong; IIRC it was width*8, so you have to divide the saved word by 8 to get the original width...
| 1 | BITMAP *load_bsv(char *filename, RGB *palette) |
| 2 | { |
| 3 | PACKFILE *f; |
| 4 | BITMAP *bmp = NULL; |
| 5 | char temp[6]; |
| 6 | int w, h, i; |
| 7 | |
| 8 | if (!(f = pack_fopen(filename, F_READ))) |
| 9 | return NULL; |
| 10 | |
| 11 | /* check if it's a bsaved file */ |
| 12 | if (pack_getc(f) != 0xfd) |
| 13 | goto error; |
| 14 | |
| 15 | /* skip source seg:off and length */ |
| 16 | pack_fread(temp, 6, f); |
| 17 | if (pack_feof(f)) |
| 18 | goto error; |
| 19 | |
| 20 | /* get sprite dimensions */ |
| 21 | w = pack_igetw(f) / 8; |
| 22 | h = pack_igetw(f); |
| 23 | |
| 24 | bmp = create_bitmap_ex(8, w, h); |
| 25 | if (!bmp) |
| 26 | goto error; |
| 27 | |
| 28 | /* load the sprite data */ |
| 29 | for (i=0; i<h; i++) |
| 30 | pack_fread(bmp->line<i>, w, f); |
| 31 | |
| 32 | /* check if there's an appended palette */ |
| 33 | if ((!pack_feof(f)) && (palette)) { |
| 34 | /* load appended data as palette data */ |
| 35 | for (i=0; i<256; i++) { |
| 36 | pack_fread(palette<i>, 3, f); |
| 37 | if (pack_feof(f)) |
| 38 | break; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | error: |
| 43 | pack_fclose(f); |
| 44 | return bmp; |
| 45 | } |
heh, cool
That just might bring over a lot of QB programmers....that and my "How to program C++ for QB programmers" tutorial. Mayhaps you should upload that source code somplace permemenant where people can download it?
DUDE! that worked! Thank you sooo much.
Wow. BLOADed graphics. That was my first brush with file-based sprites, too. I even figured out a way to make a (partially) clipping PUT drawing routine.
It only worked vertically...if the sprite was clipped horizontally it'd do strange things. I didn't know enough about how EGA video RAM was structured to make it more intelligent than that. (in 4 4-bit planes, like the old VGA modes, in case you wonder.
)
I haven't seen that in ages. I've even still got a few of my old GWBASIC games around...