Here is a sub that saves the SCREEN 13 screen or any portion of it.
SUB SaveBMP (FileName$, MinX, MinY, MaxX, MaxY)
WidthInPixels = (MaxX - MinX) + 1: LengthInPixels = (MaxY - MinY) + 1: a& = 1
OPEN FileName$ FOR BINARY AS #1
IF LOF(1) <> 0 THEN
CLOSE #1
KILL FileName$
OPEN FileName$ FOR BINARY AS #1
END IF
ValidBMP$ = "BM": Empty$ = MKL$(0): PictureDataOffset$ = MKL$(1078)
PUT #1, , ValidBMP$ '/* Valid BMP's have 'BM' as the first two char's'
PUT #1, , Empty$ '/* Reserved until file size is calculated'
PUT #1, , Empty$ '/* Used to make the bytes in the file empty'
PUT #1, , PictureDataOffset$ '/* Offset of the Picture Data'
'/* Header Variables */'
WinOrOS2$ = MKL$(40): WidthInPixels$ = MKL$(WidthInPixels)
LengthInPixels$ = MKL$(LengthInPixels): NoOfPlanes$ = MKI$(1)
NoOfBits$ = MKI$(8): NoCompression$ = MKL$(0): AllColors$ = MKL$(0)
IF (4 - (WidthInPixels MOD 4)) = 4 THEN
SizeOfImageInBytes$ = MKL$((WidthInPixels * LengthInPixels))
ELSE
SizeOfImageInBytes$ = MKL$(((WidthInPixels + (4 - (WidthInPixels MOD 4))) * LengthInPixels))
END IF
PUT #1, , WinOrOS2$ '/* Defining if this is a Windows or OS/2 BMP'
PUT #1, , WidthInPixels$ '/* The Width of the Image in Pixels'
PUT #1, , LengthInPixels$ '/* The Length of the Image in Pixels'
PUT #1, , NoOfPlanes$ '/* Number of Planes. Shoule be 1'
PUT #1, , NoOfBits$ '/* Number of Bits. Should be 8'
PUT #1, , NoCompression$ '/* There is No Compression'
PUT #1, , SizeOfImageInBytes$ '/* Size of the picture data in bytes'
PUT #1, , Empty$ '/* Using this variable to keep the place blank in file'
PUT #1, , Empty$ '/* Using this variable to keep the place blank in file'
PUT #1, , AllColors$ '/* Number of Colors Used
PUT #1, , AllColors$ '/* Important Colors
'/* Palette Info */'
Empty$ = SPACE$(1)
FOR Colors = 0 TO 255
'/* Extracts the Palette of each of the 256 colors into a red, green and */'
'/* blue sections and places them into their corresponding variables */'
OUT &H3C6, &HFF
OUT &H3C7, Colors
Red$ = CHR$(INP(&H3C9) * 4): Green$ = CHR$(INP(&H3C9) * 4): Blue$ = CHR$(INP(&H3C9) * 4)
'/* Places the extracted colors into the given file */'
PUT #1, , Blue$
PUT #1, , Green$
PUT #1, , Red$
PUT #1, , Empty$
NEXT Colors
SCREEN 13
'/* Saves the screen portion into BSAVE format */'
DIM Image%(1 TO 32767)
GET (MinX, MinY)-(MaxX, MaxY), Image%
ImageVarSeg = VARSEG(Image%(1))
ImageVarOffset = VARPTR(Image%(1))
DEF SEG = ImageVarSeg
BSAVE "temp.fil", ImageOffset, WidthInPixels * LengthInPixels
LineOfBytes$ = SPACE$(WidthInPixels): Padding$ = SPACE$(0)
IF (4 - (WidthInPixels MOD 4)) <> 4 THEN Padding$ = SPACE$((4 - (WidthInPixels MOD 4)))
Empty$ = SPACE$(11)
OPEN "temp.fil" FOR BINARY AS #2
'/* Extracts the unnecessary BSAVE format info */'
GET #2, , Empty$
FOR Loops = LengthInPixels - 1 TO 0 STEP -1
'/* Extracts the bytes from the BSAVE file and places it into the BMP file */'
GET #2, 12 + (WidthInPixels * Loops), LineOfBytes$
PUT #1, , LineOfBytes$
LINE (MinX, Loops)-(MaxX, Loops), 0
'/* Puts extra padding into BMP if any is needed */'
PUT #1, , Padding$
NEXT Loops
CLOSE #2: KILL "temp.fil"
'/* Places the size of the file into the file */'
SizeOfFile$ = MKL$(LOC(1))
PUT #1, 3, SizeOfFile$
END SUB