BAS:
/* DEMO ANIMATION (MAIN) **
   must be loaded from a CpcAlive command file.
   files INC\MAINJUMP.BAS and INC\IBMP.BAS must be loaded first.*/   

	MEMORY &7FFF
	clock1$="HH:MM:SS":clock2$="HH:MM:SS":|clock,@clock1$
	dim tmp(256*3):'temporary table
	ScreenMode=1:MODE ScreenMode
	gosub WaitMesDisplay:'	display "wait" message

        SpriteStar0=0
       	SpriteStar1=1
        SpriteStar2=2
        SpriteStar3=3
        gosub STAR_LOAD:'** STAR LOADER **

//** MAIN IMAGE **
//record pixels outputs (end of COPY with |FRAMEOUT or |PASTE)
        SpriteImage=4
        |COPY,SpriteImage:'Create Sprite
        ImgName$="EX\ICONE"
        ximg=0:yimg=0:'    image coordinates
        BackGround=-1:'    not transparent background
        FirstInk=4:'       first ink use in palette
        gosub BMPDISPLAY:' ** DISPLAY BMP IMAGES 16/256 COLORS NOT COMPRESSED **
        if er%<>0 then IbmpEr
		
	|clock,@clock2$:gosub CpuSpeedAsk

/* create sprites caracters from bmp images *************************************************
        for SpriteCar=&20 to &EB
        '|COPY,SpriteCar:' 				Create Sprite number
	|COPY,"ex\message\Car"+hex$(SpriteCar,2):'	Create Sprite file
	ImgName$="ex\message\Car"+hex$(SpriteCar,2)
        ximg=0:yimg=0:' 		image coordinates
        BackGround=15:' 		transparent background (pen 15)
        FirstInk=4:' 			first ink use in palette
        gosub BMPDISPLAY:' 		** DISPLAY BMP IMAGES 16/256 COLORS NOT COMPRESSED **
	gosub WaitMesDisplay:'	display "wait" message		
	next
	stop
*********************************************************************************************/

//create output file
        er%=0:|ANICREA,"DEMO.FLI",@er%
        if er%<>0 then PRINT"ERROR":END

//speed animation
        |ANISPEED,1

        imgx=0:imgy=0

//OpenScreen
	cls
	if CpuSpeed<990 then caract=asc("X")-2:goto NotOpenScreen:'(loop 3 time)
        |PASTE,imgx,imgy,SpriteImage
	OpenScreenSpeed=10:FirstInk=4:LastInk=20:gosub OpenScreen

NotOpenScreen:
	for i=0 to 46
        	imgx=imgx+4:imgy=imgy+2
                gosub FRAMEOUT:'output frame
        next        
	for i=0 to 20
                imgx=imgx+2
                gosub FRAMEOUT:'output frame
        next
	CarWith=32
	LineFrPtr=1:LineXFr=0
	LineEnPtr=1:LineXEn=0
	AdrFrMes=himem+1
	AdrEnMes=AdrFrMes+&300
        |INPUT,"ex\message\mes_fr.txt"+":D,&300,0,&"+hex$(AdrFrMes),@er%:'block_lenght,adr_block_in_file,adr_in_memory,@error_code
        if er%<>0 then ?"error":end
        |INPUT,"ex\message\mes_en.txt"+":D,&300,0,&"+hex$(AdrEnMes),@er%:'block_lenght,adr_block_in_file,adr_in_memory,@error_code
        if er%<>0 then ?"error":end
	while caract<>asc("X")
               	starx=imgx+30:stary=imgy+150
               	gosub STAR_AFFI
               	starx=imgx+60:stary=imgy+160
               	gosub STAR_AFFI
                starx=imgx+50:stary=imgy+175
                gosub STAR_AFFI
                starx=imgx+90:stary=imgy+155
                gosub STAR_AFFI
		if CpuSpeed<990 then caract=caract+1
	wend

//CloseScreen
	if CpuSpeed<990 then NotCloseScreen
        |PASTE,imgx,imgy,SpriteImage
	gosub MesDisplay:' 	display message
	CloseScreenSpeed=10:FirstInk=4:LastInk=20:gosub CloseScreen
NotCloseScreen:

//close output file
        |ANICLOSE,@er%:gosub ErAsk

//exit the emulator with message
        |exit,"type <fli2gif demo.fli> to display the animation"
		
//<movx,imgy=coordinates
STAR_AFFI:
        SpriteStar=SpriteStar0
        gosub FrameOutWithStars:'output frame with star
        SpriteStar=SpriteStar1
        gosub FrameOutWithStars:'output frame with star
        SpriteStar=SpriteStar2
        gosub FrameOutWithStars:'output frame with star
        SpriteStar=SpriteStar3
        gosub FrameOutWithStars:'output frame with star
        SpriteStar=SpriteStar2
        gosub FrameOutWithStars:'output frame with star
        SpriteStar=SpriteStar1
        gosub FrameOutWithStars:'output frame with star
        SpriteStar=SpriteStar0
        gosub FrameOutWithStars:'output frame with star
        return

//display message
MesDisPlay:
	'english message
	CarX=LineXEn-CarWith
	for i=1 to 14
		Caract=peek(AdrEnMes+i+LineEnPtr)
		if caract=asc("X") then MesDisPlay02
		CarY=CarWith/2
		tmp(0)=CarX
		gosub CarCor:'	character position correction
		if i=1 then FirstCarWithEn=CarWith-(tmp(0)-CarX)
		|PASTE,CarX,CarY,"ex\message\Car"+hex$(Caract,2):'	display Sprite file
		CarX=CarX+CarWith*2
MesDisPlay02:
	next

	if caract=asc("X") then return

	'french message
	CarX=LineXFr-CarWith
	for i=1 to 14
		Caract=peek(AdrFrMes+i+LineFrPtr)
		if caract=asc("X") then MesDisPlay04
		CarY=400-CarWith*2
		tmp(0)=CarX
		gosub CarCor:'	character position correction
		if i=1 then FirstCarWithFr=CarWith-(tmp(0)-CarX)
		|PASTE,CarX,CarY,"ex\message\Car"+hex$(Caract,2):'	display Sprite file
		CarX=CarX+CarWith*2
MesDisPlay04:
	next		
	return

//character position correction
CarCor:
	if Caract=asc("!") or Caract=asc("I") then CarX=CarX-20		
	if Caract=asc("M") or Caract=asc("H") or Caract=asc("W") then CarX=CarX+10
	if Caract>=asc("a") and Caract<=asc("z") then CarX=CarX-10
	if Caract=asc("m") or Caract=asc("w") then CarX=CarX+20
	if Caract=asc("i") or Caract=asc("l") then CarX=CarX-10
	if Caract=asc(",") or Caract=asc(".") or Caract=&92 then CarX=CarX-30:'(&92="'")
	if Caract=asc(",") then CarY=CarY-6
	if Caract=asc("g") then CarY=CarY-10
	if Caract=asc("j") then CarY=CarY-10
	if Caract=asc("p") then CarY=CarY-10
	if Caract=asc("q") then CarY=CarY-10
	if Caract=asc("y") then CarY=CarY-10
	return

//display "wait" message
WaitMesDisplay:
	cls:locate 1,1:?"wait during animation building...":return

//set all colors
OpenScreen:'<pal=palet table,OpenScreenSpeed,FirstInk,LastInk
	gosub ClearTmpTable:'	raz temporary table
OpenScreenCont:
	flag=0
	for i=FirstInk to LastInk
		if tmp(i*3)+OpenScreenSpeed<pal(i*3) then tmp(i*3)=tmp(i*3)+OpenScreenSpeed:flag=1 else tmp(i*3)=pal(i*3)
		if tmp(i*3+1)+OpenScreenSpeed<pal(i*3+1) then tmp(i*3+1)=tmp(i*3+1)+OpenScreenSpeed:flag=1 else tmp(i*3+1)=pal(i*3+1)
		if tmp(i*3+2)+OpenScreenSpeed<pal(i*3+2) then tmp(i*3+2)=tmp(i*3+2)+OpenScreenSpeed:flag=1 else tmp(i*3+2)=pal(i*3+2)
		|INK,i,tmp(i*3),tmp(i*3+1),tmp(i*3+2)
	next
	|FRAMEOUT
	if flag then OpenScreenCont:'continue
	return

//raz all colors
CloseScreen:'<pal=palet table,CloseScreenSpeed,FirstInk,LastInk
	flag=0
	for i=FirstInk to LastInk
		if pal(i*3)>=CloseScreenSpeed then pal(i*3)=pal(i*3)-CloseScreenSpeed:flag=1 else pal(i*3)=0
		if pal(i*3+1)>=CloseScreenSpeed then pal(i*3+1)=pal(i*3+1)-CloseScreenSpeed:flag=1 else pal(i*3+1)=0
		if pal(i*3+2)>=CloseScreenSpeed then pal(i*3+2)=pal(i*3+2)-CloseScreenSpeed:flag=1 else pal(i*3+2)=0
		|INK,i,pal(i*3),pal(i*3+1),pal(i*3+2)
	next
	|FRAMEOUT
	if flag then CloseScreen
	return

//raz inks and temporary table
//<FirstInk,LastInk
ClearTmpTable:
	for i=FirstInk to LastInk:|ink,i,0,0,0:next
	for i=FirstInk*3 to LastInk*3:tmp(i)=0:next
	return

//output frame with stars
FrameOutWithStars:
        |PASTE,imgx,imgy,SpriteImage
        |PASTE,starx,stary,SpriteStar
	if CpuSpeed<990 then FrameOut2
	gosub MesDisplay:' 	display message
	LineXFr=LineXFr-CarWith/4:if LineXFr<=-CarWith then LineXFr=FirstCarWithFr:LineFrPtr=LineFrPtr+1
	LineXEn=LineXEn-CarWith/4:if LineXEn<=-CarWith then LineXEn=FirstCarWithEn:LineEnPtr=LineEnPtr+1
	goto FrameOut2

//output frame without stars
FrameOut:
        |PASTE,imgx,imgy,SpriteImage
FrameOut2:
        |FRAMEOUT,@er%
        cls
ErAsk:
        IF er%<>0 then PRINT "ERROR":END else return

//<Clock1$,Clock2$
//>CpuSpeed
CpuSpeedAsk:
	tmp(0)=val(mid$(Clock1$,4,2))*60+val(mid$(Clock1$,7,2)):'nbrseconds1
	tmp(1)=val(mid$(Clock2$,4,2))*60+val(mid$(Clock2$,7,2)):'nbrseconds2
	CpuSpeed=tmp(1)-tmp(0)
	if CpuSpeed<0 then run
	CpuSpeed=1000-CpuSpeed
	return
