BAS:
/************************************************************
 AFFICHE IMAGES AU FORMAT BMP NON COMPRESSE 16/256 COULEURS *
 DISPLAY BMP IMAGES 16/256 COLORS NOT COMPRESSED	    *
<---INPUTS
ImgName$   	= nom image sans extension
                  image name without extension
ScreenMode 	= mode ecran
                  screen mode
ximg,yimg  	= coordonnees coin inferieur gauche
                  bottom left image coordinates
FirstInk   	= numero 1er crayon pour images 16 couleurs
                  first ink use in palette for 16 colors images
BackGround 	= crayon de fond (-1 si non transparent)
                  background pen (-1 if not transparent)
--->OUTPUTS
ImgWith    	= largeur image
                  image with
ImgHight   	= hauteur image
                  image hight
PalSize    	= nombre de couleurs image
              	  number of inks of image
Pal        	= tableau palette 256 couleurs
		= palet 256 colors table
er%		= 0 ok
		  2or3 directory or file not found
		  4 no more Dos handle
		  5 refused access
*************************************************************/
BmpDisplay:
        if IniPalFlag<>-1 then dim pal(257*3):IniPalFlag=-1
        er%=0
        adr=himem+1:'buffer
        'load header and palet
        |INPUT,ImgName$+".BMP"+":D,&500,0,&"+HEX$(adr),@er%:'block_lenght,adr_block_in_file,adr_in_memory,@error_code
        if er%<>0 then return
        adrline=PEEK(adr+&A)+256*PEEK(adr+&B):'adresse ligne a traiter dans fichier/address img line in file
        adrimg=adr+adrline:'adresse image dans fichier/address img in file
        ImgWith=PEEK(adr+&12)+256*PEEK(adr+&13):'largeur/with image
        IF PEEK(adr+&E)+256*PEEK(adr+&F)<>12 THEN READ_BITMAPFILEHEADER:'header type

' ** READ BITMAPCOREHEADER **

        x=PEEK(adr+&18)+256*PEEK(adr+&19):'nbr bits/pixel
        ImgHight=PEEK(adr+&14)+256*PEEK(adr+&15):'hauteur/hight image
        IF x=8 THEN BITMAPCOREHEADER_256:'256 couleurs/colors
        IF x<>4 THEN MODE 2:PRINT"16 or 256 colors in image only accepted.":END

'** DISPLAY IMAGE 16 COULEURS/COLORS **

        GOSUB cpc_inks_ordering
	x=0
        FOR i=0 TO 15*3 STEP 3
                |INK,FirstInk+x,PEEK(adr+&1C+i),PEEK(adr+&1B+i),PEEK(adr+&1A+i)
                pal((FirstInk+x)*3)=PEEK(adr+&1C+i):  'R
                pal((FirstInk+x)*3+1)=PEEK(adr+&1B+i):'G
                pal((FirstInk+x)*3+2)=PEEK(adr+&1A+i):'B
                x=x+1
        NEXT

DISPLAY16:
		
	x=int(ImgWith/2):if x<>ImgWith/2 then x=x+1:NotMod=0 else NotMod=1
	WHILE x MOD 4 <> 0:x=x+1:WEND
        larbloc=x
        incry=2
        if ScreenMode=0 then incrx=4 else if ScreenMode=1 then incrx=2 else incrx=1
        FOR i=0 TO ImgHight*incry STEP incry
                x=0
                |INPUT,ImgName$+".BMP"+":D,&"+HEX$(larbloc)+","+DEC$(adrline,"########")+",&"+HEX$(adr)
		FOR j=adr TO adr+INT(ImgWith/2)-NotMod
                        pencil=FirstInk+(PEEK(j) AND &F0)/16:gosub PLOT_STEP:'plot with step
                        pencil=FirstInk+(PEEK(j) AND &F):gosub PLOT_STEP:'plot with step
                NEXT j
                adrline=adrline+larbloc
        NEXT i
        PalSize=16
        RETURN

'** READ BITMAPFILEHEADER 16 COLORS **
BITMAPFILEHEADER_16:

        GOSUB cpc_inks_ordering
        x=0
        FOR i=0 TO 15*4 STEP 4
                |INK,FirstInk+x,PEEK(adr+&38+i),PEEK(adr+&37+i),PEEK(adr+&36+i)
                pal((FirstInk+x)*3)=PEEK(adr+&38+i):  'R
                pal((FirstInk+x)*3+1)=PEEK(adr+&37+i):'G
                pal((FirstInk+x)*3+2)=PEEK(adr+&36+i):'B
                x=x+1
        NEXT
        GOTO DISPLAY16

'** BITMAPCOREHEADER 256 COULEURS/COLORS **
BITMAPCOREHEADER_256:

        x=0
        FOR i=0 TO 255*3 STEP 3
                |INK,x,PEEK(adr+&1C+i),PEEK(adr+&1B+i),PEEK(adr+&1A+i)
                pal(i)=PEEK(adr+&1C+i):  'R
                pal(i+1)=PEEK(adr+&1B+i):'G
                pal(i+2)=PEEK(adr+&1A+i):'B
                x=x+1
        NEXT
        GOTO DISPLAY256

'** BITMAPFILEHEADER **
READ_BITMAPFILEHEADER:

        ImgHight=PEEK(adr+&16)+256*PEEK(adr+&17)

        IF PEEK(adr+&E)+256*PEEK(adr+&F)<>40 THEN MODE 2:PRINT"Bitmap header error":END
        IF PEEK(adr+&1E)+256*PEEK(adr+&1F)<>0 THEN MODE 2:PRINT"Uncompressed bitmap only accepted":END
        IF PEEK(adr+&1C)+256*PEEK(adr+&1D)=4 THEN BITMAPFILEHEADER_16
        IF PEEK(adr+&1C)+256*PEEK(adr+&1D)<>8 THEN MODE 2:PRINT"256 or 16 colors only accepted":END

'** BITMAPFILEHEADER 256 COLORS **
        GOSUB cpc_inks_ordering
        x=0
        FOR i=0 TO 255*4 STEP 4
                |INK,x,PEEK(adr+&38+i),PEEK(adr+&37+i),PEEK(adr+&36+i)
                pal(x*3)=PEEK(adr+&38+i):  'R
                pal(x*3+1)=PEEK(adr+&37+i):'G
                pal(x*3+2)=PEEK(adr+&36+i):'B
                x=x+1
        NEXT

DISPLAY256:

        IF ImgWith MOD 4<>0 THEN larbloc=ImgWith+(4-(ImgWith MOD 4)) ELSE larbloc=ImgWith
        incry=2:incrx=2:' (MODE 1)
        FOR i=0 TO ImgHight*incry STEP incry
                x=0
                |INPUT,ImgName$+".BMP"+":D,&"+HEX$(larbloc)+","+DEC$(adrline,"########")+",&"+HEX$(adr)
                FOR j=adr TO adr+ImgWith-1
                        pencil=PEEK(j):gosub PLOT_STEP:'plot with step
                NEXT j
                adrline=adrline+larbloc
        NEXT i
        PalSize=256
        RETURN

'** PLOT WITH STEP ** if BackGround<>-1 then transparent background
PLOT_STEP:

        if BackGround=-1 or pencil-FirstInk<>BackGround THEN PLOT ximg+x,yimg+i,pencil
        x=x+incrx
        RETURN

'** cpc inks ordering **
cpc_inks_ordering:

        FOR i=0 TO 15
                INK i,i
        NEXT
        RETURN

'** I/O error messages **
IBmpEr:
	mode 2:|ink,0,0,0,0:|ink,1,&C0,&C0,&C0:pen 1
	if er%=1 then ? "|INPUT:"+ImgName$+".BMP"+" parameters error":end
        if er%=2 then ? ImgName$+".BMP"+" not found":end
        if er%=3 then ? ImgName$+": directory or file not found":end
        if er%=4 then ? "|INPUT,"+ImgName$+": no more Dos handle":end
	if er%=5 then ? ImgName$+": refused access":end
        ? "|INPUT:"+ImgName$+".BMP"+" error":end
		



