Jump to content

  • Log In with Google      Sign In   
  • Create Account

256 color QBASIC


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
13 replies to this topic

#1 Iron Eye   Members   -  Reputation: 122

Like
Likes
Like

Posted 25 September 2003 - 12:01 PM

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

Sponsor:

#2 krez   GDNet+   -  Reputation: 443

Like
Likes
Like

Posted 25 September 2003 - 01:27 PM

here

#3 falkone   Members   -  Reputation: 444

Like
Likes
Like

Posted 25 September 2003 - 01:36 PM

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

#4 RPGeezus   Members   -  Reputation: 216

Like
Likes
Like

Posted 26 September 2003 - 08:18 AM

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


#5 Ready4Dis   Members   -  Reputation: 180

Like
Likes
Like

Posted 26 September 2003 - 09:12 AM

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=all
end type

Sub 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/4
end sub

sub 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 #1
end sub

'***** Program starts here *****
Screen 13 '320x200x256 colors
Dim tmpStr as string
Call LoadBitmap("Test.bmp")
input tmpStr 'Input some crap for now
Screen 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]

#6 quasar3d   Members   -  Reputation: 694

Like
Likes
Like

Posted 26 September 2003 - 09:27 AM

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

#7 Ready4Dis   Members   -  Reputation: 180

Like
Likes
Like

Posted 26 September 2003 - 02:40 PM

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]

#8 RPGeezus   Members   -  Reputation: 216

Like
Likes
Like

Posted 27 September 2003 - 04:22 AM

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

#9 Jolle   Members   -  Reputation: 178

Like
Likes
Like

Posted 27 September 2003 - 04:43 AM

I think &HB800 is the "text"-segment... &HA000 is the video-segment (at least for mode 13)

#10 Iron Eye   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 September 2003 - 02:26 PM

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.

#11 Iron Eye   Members   -  Reputation: 122

Like
Likes
Like

Posted 27 September 2003 - 02:44 PM

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?

#12 Ready4Dis   Members   -  Reputation: 180

Like
Likes
Like

Posted 27 September 2003 - 03:31 PM

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.


#13 Iron Eye   Members   -  Reputation: 122

Like
Likes
Like

Posted 28 September 2003 - 11:05 AM

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


#14 Ready4Dis   Members   -  Reputation: 180

Like
Likes
Like

Posted 28 September 2003 - 03:24 PM

Heh, yes... bsave and bload or some other way is probably much faster . I used to have a bunch of old QB code, but I wiped my drive clean of QB stuff (I even had a 3d software engine with texture mapping that I wrote way back on my 386).




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS