CpcAlive is a
programming
environment
Amstrad CPC

compatible
for graphics
 animations
creation.







Cpc basic key words
( English - Español )

Cpc basic error messages

The memory

The Cpc system vectors

Diskettes management

Z80 processor opcodes and
operation

CpcAlive installer for
Windows and DosBox

CpcAlive Documentation

SmallAsm is a Z80 assembler
for Dos







Français

** CpcAlive Basic program example **
DISPLAY BMP IMAGES 16/256 COLORS NOT COMPRESSED
(images generated for example by the program "Paint" in windows 7 accessories)


BAS: <- file header for the emulator CpcAlive

        MEMORY &8FFF
        ScreenMode=1:MODE ScreenMode
        ImgName$="IMAGE.BMP":' <<<<<<<<<<<<< IMAGE NAME HERE >>>>>>
        ximg=0:yimg=0:'    image coordinates
        BackGround=-1:'    not transparent background
        FirstInk=0:'       first ink use in palette
        gosub BMPDISPLAY:' ** DISPLAY BMP IMAGES 16/256 COLORS NOT COMPRESSED **
        end


/******************************************
 DISPLAY BMP IMAGES 16/256 COLORS NOT COMPRESSED
<ImgName$   =  image name
 ScreenMode =  screen mode
 FirstInk   =      first ink use in palette for 16 colors images
 BackGround =   background pen (-1 if not transparent)
*******************************************/

BMPDISPLAY:

        er%=0:adr=himem+1:'buffer
        |INPUT,ImgName$+":D,&500,0,&"+HEX$(adr),@er%:'block_lenght,adr_block_source_in_file,adr_in_Cpc_memory,@error_code
        if er%<>0 then FileInputEr
        adrline=PEEK(adr+&A)+256*PEEK(adr+&B):'adr img line in file
        adrimg=adr+adrline:'adr img in file
        largeur=PEEK(adr+&12)+256*PEEK(adr+&13):'image with
        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
        hauteur=PEEK(adr+&14)+256*PEEK(adr+&15):'image hight
        IF x=8 THEN BITMAPCOREHEADER_256:'256 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=FirstInk:'first pen in color palette
        FOR i=0 TO 15*3 STEP 3
                |INK,x,PEEK(adr+&1C+i),PEEK(adr+&1B+i),PEEK(adr+&1A+i)
                x=x+1
        NEXT

DISPLAY16:
        reste=largeur MOD 2:x=INT(largeur/2)+reste
        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 hauteur*incry STEP incry
                x=0
                |INPUT,ImgName$+":D,&"+HEX$(larbloc)+","+DEC$(adrline,"########")+",&"+HEX$(adr)
                FOR j=adr TO adr+INT(largeur/2)
                        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
        RETURN

//** READ BITMAPFILEHEADER 16 COLORS **
BITMAPFILEHEADER_16:

        GOSUB cpc_inks_ordering
        x=FirstInk:'first pen in color palette
        FOR i=0 TO 15*4 STEP 4
                |INK,x,PEEK(adr+&38+i),PEEK(adr+&37+i),PEEK(adr+&36+i):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):x=x+1
        NEXT
        GOTO DISPLAY256

//** BITMAPFILEHEADER **
READ_BITMAPFILEHEADER:

        hauteur=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):x=x+1
        NEXT

DISPLAY256:

        IF largeur MOD 4<>0 THEN larbloc=largeur+(4-(largeur MOD 4)) ELSE larbloc=largeur
        incry=2:incrx=2:' (MODE 1)
        FOR i=0 TO hauteur*incry STEP incry
                x=0
                |INPUT,ImgName$+":D,&"+HEX$(larbloc)+","+DEC$(adrline,"########")+",&"+HEX$(adr)
                        FOR j=adr TO adr+largeur-1
                                pencil=PEEK(j):gosub PLOT_STEP:'plot with step
                        NEXT j
                adrline=adrline+larbloc
        NEXT i
        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


FileInputEr:

        mode 2
        if er%=1 then ? "|INPUT:"+ImgName$+" parameters error":end
        if er%=2 then ? ImgName$+" not found":end
        ? "|INPUT:"+ImgName$+" error":end