Code:
DEFINT A-Z
TYPE BMPHeaderType
ID AS STRING * 2
Size AS LONG
RSV1 AS INTEGER
RSV2 AS INTEGER
offset AS LONG
HORZ AS LONG
WID AS LONG
HEI AS LONG
PLANES AS INTEGER
BPP AS INTEGER
COMPRESSION AS LONG
IMAGESIZE AS LONG
xRes AS LONG
yRes AS LONG
CLRUSED AS LONG
CLRIMPORT AS LONG
Pal AS STRING * 1024
END TYPE
DECLARE SUB LoadBMP (DestSeg%, SegxRes%, SegyRes%, File$, sX%, sY%, SwitchPal%, Trans%)
CLS : SCREEN 13
LoadBMP &HA000, 320, 200, "MyPic.BMP", 0, 0, 1, -1
'&HA000 = Video Segment, the segment of the screen
'320 and 200 is the resolution of the videosegment, in screen 13
'"MyPic.BMP" is just a BMP file, must be 256 color
'0, 0 is the top, left location to start drawing the image from
'1 is if it should change the palette to that in the BMP (0 is no)
'-1 is the color to treat as transperent, -1 means all will be drawn
SUB LoadBMP (DestSeg%, SegxRes%, SegyRes%, File$, sX, sY, SwitchPal%, Trans%)
DIM bmp AS BMPHeaderType
f% = FREEFILE
OPEN File$ FOR BINARY AS #f%
GET #f%, , bmp
IF SwitchPal% THEN
pall$ = bmp.Pal
IF LEN(pall$) = 1024 THEN
OUT &H3C8, 0
FOR I% = 1 TO 1024 STEP 4
b% = ASC(MID$(pall$, I%, 1)) \ 4
g% = ASC(MID$(pall$, I% + 1, 1)) \ 4
r% = ASC(MID$(pall$, I% + 2, 1)) \ 4
OUT &H3C9, r%
OUT &H3C9, g%
OUT &H3C9, b%
NEXT I%
END IF
END IF
Byte$ = SPACE$(bmp.WID)
DEF SEG = DestSeg%
wide% = bmp.WID - 1
Hite% = bmp.HEI - 1
offs& = LOC(f) + 1
FOR y% = Hite% TO 0 STEP -1
IF sY + y >= 0 AND sY + y < SegyRes THEN
GET #f%, offs&, Byte$
FOR x% = 0 TO wide%
IF sX + x >= 0 AND sX + x < SegxRes THEN
c% = ASC(MID$(Byte$, x% + 1, 1))
IF c% <> Trans% THEN
POKE (sX% + x%) + (sY% + y%) * (SegxRes + 0&), c%
END IF
END IF
NEXT x%
END IF
offs& = offs& + bmp.WID
NEXT y%
CLOSE #f
DEF SEG
END SUB