'===========================================================================
' Subject: WRITE 640X480X16 .BMP FILES        Date: 03-28-96 (17:45)       
'  Author: Mathew Robertson                   Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: EGAVGA.ABC
'===========================================================================
'Programed by: Mathew Robertson    '1994
'This Is a very easy example of how to write 640x480x16 windows
'Bitmap files. It should not be that hard to change to make it
'accept other sizes. The code is not commented to well so to
'make such changes it will reguire abit of knowledge on the
'subject and the time to make the changes, Unfortunaly I do
'not have the time to do so. Other possible changes would be
'to use direct memory access to read the screen instead of point
'which is rather slow. This type of change would make it work
'faster on slower systems.
'Anyone who does want to make the changes and has the time
'to do so, go ahead. The one Restriction is if you improve on
'the code that I get a copy of the modified code.
'This code is slow so if it looks like it has stopped its still going
'just after the original screen draw there is no more visual output.
'when finished running pop into your favorite graphics viewer that
'supports this format (most do support windows bitmaps)
'--------------------------------<cut here>----------------------------------
'Set the screen mode clear screen
SCREEN 12: CLS
'Set up variables
DIM B(1345), a&(16): kur = 0
'the name of the file to use to save the screen two
file$ = "test2.bmp"
'well this one is sort of self explainitory
RANDOMIZE TIMER
'Get some new colors
FOR i = 0 TO 15
a&(i) = INT(RND * 64) + INT(RND * 64) * 256 + INT(RND * 64) * 65536
NEXT
'Change the palette
PALETTE USING a&(0)
'Draw something pretty on the screen
FOR i = 20 TO 400: CIRCLE (320, 240), i, i AND 15: NEXT
'Well since we like are picture so much lets save it as a Windows Bitmap
GOSUB SAVEASwBMP
'end the program
END
SAVEASwBMP: 'the main save routines
'open the file up to save to.
OPEN file$ FOR OUTPUT AS #1
'Select the Windows Bitmap data
RESTORE wbmpdata
'place the Windows Bitmap data into the file header
FOR i = 0 TO 53: READ a: PRINT #1, CHR$(a); : NEXT
'Place the colors used in the picture into the file header
FOR i = 0 TO 15
PRINT #1, CHR$(((a&(kur + i) AND 65536 * 63) / 65536) * 4);
PRINT #1, CHR$(((a&(kur + i) AND 256 * 63) / 256) * 4);
PRINT #1, CHR$((a&(kur + i) AND 63) * 4);
PRINT #1, CHR$(0);
NEXT
'make sure the variable point$ has nothing in it
point$ = ""
'start a loop for the y value
FOR i = 479 TO 0 STEP -1
'start a loop for the x value
FOR j = 0 TO 639 STEP 2
'collect and store color data
point$ = point$ + CHR$(POINT(j, i) * 16 + POINT(j + 1, i))
NEXT
'write color data to file
PRINT #1, point$; : point$ = ""
NEXT
'close file
CLOSE : RETURN
'information for the file header of a windows 16 color bitmap
wbmpdata:
DATA 66,77,118,88,2,0,0,0 : DATA 0,0,118,0,0,0,40,0
DATA 0,0,128,2,0,0,224,1,0 : DATA 0,1,0,4,0,0,0,0,0,0
DATA 88,2,0,132,61,0,0,132 : DATA 61,0,0,0,0,0,0,0,0,0: DATA 0,0,0,0

