Loader for QBASIC sprites in 16 color modes

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Loader for QBASIC sprites in 16 color modes

Post by angros47 »

I looked in the forum, and I can't believe that I couldn't find a single way to load a sprite saved from a QBASIC program (using GET and then BSAVE). FreeBasic can read .BMP files, it can also read QBASIC files, but not pictures saved in QBASIC.
Actually, QBASIC could store a sprite in different (and incompatible) formats, depending on color depth: this means that a picture captured with GET on SCREEN 2 could work only in other monochrome modes, a picture captured in SCREEN 1 works only in that mode, and a picture captured in a 16 color mode (SCREEN 7,8,9,12) works in all these screen.

FreeBasic might be able to understand more or less a picture taken in SCREEN 13 (the only 8 bit mode of QBASIC), but nothing else.

Just for fun, I made a simple converter that loads sprites made in QBASIC in 16 colors modes (for example, in SCREEN 12)

Code: Select all

screenres 640,480,8
dim buffer(65536) as ubyte

bload command,@buffer(0)

dim w as integer= buffer(0)+buffer(1)shl 8
dim h as integer= buffer(2)+buffer(3)shl 8

dim p as integer=3

dim loffset as integer=w/8 


for y as integer=1 to h
	dim x as integer
	do
		p=p+1
		for offset as integer = 7 to 0 step -1

			dim as integer red=(buffer(p) shr offset) and 1
			dim as integer green=(buffer(p+loffset+1) shr offset) and 1
			dim as integer blue=(buffer(p+loffset*2+2) shr offset) and 1
			dim as integer bright=(buffer(p+loffset*3+3) shr offset) and 1

			dim c as integer=red+green*2+blue*4+bright*8

			pset (x,y),c

			x+=1: if x>=w then exit do
		next
	loop 
	p+=loffset*3 +3

next
sleep
Post Reply