• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# 256 color QBASIC

## Recommended Posts

Iron Eye    122
I remember hearing something about loading 256 color bitmaps in qbasic on the forums here; however, the search seems to be dysfunctional again. I was wonder if anyone could point me to some articles on this. All I seem to find are 16 color things. I would like to dodge 16 colors on my final qbasic app in my programming class if possible. Help appreciated, Kris

krez    443

##### Share on other sites
falkone    444
Hehe, the expansion of possible colors isn''t often talked about. THe only two solutions i have seen is to use the palette command, or use seperate assembler modules

##### Share on other sites
RPGeezus    216
My QBASIC is a little rusty, but if I recall correctly:

When you load the 256 Color bitmap there will be a palette consisting of 256 3 byte entries.

The first entry corresponds to color 0, the second to color 1, the third to color 2, etc... luckily the ''COLOR'' command for QBASIC works the same way: COLOR 0, COLOR 1, COLOR 2, etc..

As you are read each palette entry from the bitmap issue the PALETTE command in QBASIC. I think the syntax is PALETTE , where n is the color index used in the COLOR command, and is a 3-byte RGB color. ie: RGB. In QBASIC the order may be reversed (BGR).. You''ll know if the colors come out funny...

To set color 1 to purple we would say: PALETTE 1, (65536*255) + 255

After you have set the palette, load your bitmap in (read a 1 byte pixel value from the file and use PSET or whatever method you want) and it should come up with the correct colors.

Just remember that bitmaps (windows .BMP) files want to have a 4-byte boundry for every line of pixels. What that means is that if your image has a width of 30, the file will contain 32 bytes for each row of pixels: the last two bytes are filler. Bitmaps are also stored upside down (but down backwards).

If you need a detailed breakdown of the windows BMP format check out msdn.microsoft.com, or google it.

Hope this helps,
Will

##### Share on other sites
My QBasic is a bit rusty, and I typed this out in this window without testing.. but here's the jist of it

Type BMPInfoHeader Sig as string *2 'Always BM FileSize as long Reserved as long DataOffset as long InfoHeaderSize as long 'Normally 40 Width as long Height as long Planes as integer BitCount as short Compression as long '0=none, 1=8-bit, 2=24-bit ImageSize as long   'size of image, set to 0 if compression=0 XPixelsPerM as long 'Horizontale pixels per meter YPixelsPerM as long 'Vertical pixels per meter ColorsUsed as long  'Number of actual colors used ColorsImportant as long 'Colors that are important, 0=allend typeSub SetPalEntry(Index as integer, r as byte, g as byte, b as byte) out &h3c8, Index out &h3c9, r/4 out &h3c9, g/4 out &h3c9, b/4end subsub LoadBitmap(bName as string) Dim tmpHeader as BMPInfoHeader Dim Ctr as integer, x as integer, y as integer Dim r as byte, g as byte, b as byte, tmpByte as byte open nName for binary as #1 Get #1, , tmpHeader 'Read in our info! if not (tmpHeader.BitDepth = 8) 'Something other than 8-bit??  close #1  exit sub end if for Ctr = 0 to 255'Windows stores them b,g,r instead of r,g,b for some reason!  get #1,,b  get #1,,r  get #1,,g  get #1,,tmpByte  call SetPalEntry(ctr, r,g,b) 'Setup the pallete! next ctr'And they're stored upside down!! for y = tmpHeader.Height to 0 step -1  for x = 0 to tmpHeader.Width   get #1,, tmpByte   pset (x,y),tmpByte 'Put our pixel!  next x next y close #1end sub'***** Program starts here *****Screen 13 '320x200x256 colorsDim tmpStr as stringCall LoadBitmap("Test.bmp")input tmpStr 'Input some crap for nowScreen 3

If you need any help with this, I can always put QBasic on my machine and test it out, and fix it up a bit .

--- Edit ---
As mentioned, they are always on a 4byte boundry, which my code isn't checking for (mostly laziness), but if it becomes an issue, and you need help, email me and i can add that in (I haven't touched QBasic in like 3-4 years now)

[edited by - Ready4Dis on September 26, 2003 4:13:33 PM]

##### Share on other sites
quasar3d    814
my qbasic is also a bit rusty, but I know that if you want to use 256 colours, you can use screen 13, or with some libraries you can get higher resolutions with 256 colours. but libraries won''t work in qbasic, only in quickbasic, which is the professional edition of qbasic.

My Site

##### Share on other sites
quote:
Original post by quasar3d
my qbasic is also a bit rusty, but I know that if you want to use 256 colours, you can use screen 13, or with some libraries you can get higher resolutions with 256 colours. but libraries won't work in qbasic, only in quickbasic, which is the professional edition of qbasic.

My Site

Note: My program uses mode 13, I have used/written QBasic with ModeX and achieved 320x400 screen resolutions with 256 colors, works like a charm (especially for true color emulation, but that's a bit out of scope for this I think).

--- Edit ---
Also, I am not sure if he wanted to actually LOAD bitmaps, or just use sprites (and called them bitmaps), but my code was to load a 256 color bitmap and display it to screen . You could easily modify my code to load multiple bitmaps and a sprite drawing routine .

[edited by - Ready4Dis on September 26, 2003 9:41:15 PM]

##### Share on other sites
RPGeezus    216
If you''re not interested in loading MS Windows Bitmaps, you can always use the BLOAD and BSAVE functions. If my memory serves me correctly the address of video memory with be 0xB800... I could be wrong though.

Cheers,
Will

##### Share on other sites
Jolle    178
I think &HB800 is the "text"-segment... &HA000 is the video-segment (at least for mode 13)

##### Share on other sites
Iron Eye    122
Thanks for the help guys!

Yes I did intend on using the bitmaps as sprites, but I thought it would be fairly easy to modify the bitmap loading/displaying code to work as I want.

I''ve been sifting through the qbasic help file to try to understand that sample code provided. I''ve never actually had to deal with bitmaps so rawly before so it makes it all the harder.

##### Share on other sites
Iron Eye    122
Alright I''ve got a pretty good idea of whats happening in your code. But why do you loop 255 times? Are you just assuming its a bitmap thats 253 (theres 2 extra ones right?) pixels wide?

##### Share on other sites
quote:
Original post by Iron Eye
Alright I''ve got a pretty good idea of whats happening in your code. But why do you loop 255 times? Are you just assuming its a bitmap thats 253 (theres 2 extra ones right?) pixels wide?

The for loop (for ctr = 0 to 255) is to read in the pallete information... there are 256 color values that you need to read in .

After this, I loop through the Width and Height of the bitmap and read it in value by value, plotting the pixel using pset. If you want a more generic method of rendering sprites (in QBasic anyways), you can either look at bload and bsave, or extend my method to support sprites as well.

##### Share on other sites
Iron Eye    122
quote:
Original post by Ready4Dis
If you want a more generic method of rendering sprites (in QBasic anyways), you can either look at bload and bsave, or extend my method to support sprites as well.

Would it be a lot speedier to switch to bload and bsave?

Your method is really simple and easy to understand...which usually means speed is not of the essence....