256 color QBASIC

Started by
12 comments, last by Iron Eye 20 years, 6 months ago
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
---
ConPong _//_ Google _//_ Chaos Forge - quick and easy file hosting for developers

"Games usually keep me from making my own..."
-Me
---



find your elementat mutedfaith.com.
Advertisement
here
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])
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
Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"
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
------------------http://www.nentari.com
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 .

Email - Ready4Dis@PIQSoftware.com

--- 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]
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.

click here for the libraries

My Site
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.

click here for the libraries

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]
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
------------------http://www.nentari.com
I think &HB800 is the "text"-segment... &HA000 is the video-segment (at least for mode 13)
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.
---
ConPong _//_ Google _//_ Chaos Forge - quick and easy file hosting for developers

"Games usually keep me from making my own..."
-Me
---



find your elementat mutedfaith.com.

This topic is closed to new replies.

Advertisement