MODULE 'intuition/screens', 'graphics/rastport', 'graphics/gfx',
			 'exec/memory'

DEF tbitmap:PTR TO bitmap

PROC main()
DEF scr:PTR TO screen,rast:PTR TO rastport,myrast:rastport,text[512]:STRING,num=0,
		sin=0,cos=0,floatcnt=1.0,tcnt=0,burp[1024]:ARRAY OF CHAR,barp[1024]:ARRAY  OF CHAR

	FOR tcnt:=0 TO 1023
		burp[tcnt]:=0
		barp[tcnt]:=0
	ENDFOR
	
	IF scr:=OpenS(640,256,3,$8000,'Bludiblei',NIL)
		rast:=scr.rastport
		IF tbitmap:=createbitmap(320,256,3,BMF_CLEAR,rast.bitmap)
			InitRastPort(myrast)
			myrast.bitmap:=tbitmap

			Box(09,19,320,140,1)

			SetStdRast(myrast)
			SetAPen(stdrast,1)

			-> SetTaskPri(FindTask(NIL),100)
			
			FOR num:=0 TO 20
				StringF(text,'\z\d[2]|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_',num)
				-> TextF(20,30+(num*8),text)
			ENDFOR
		

			FOR num:=0 TO 2850

				floatcnt:=floatcnt+1.2           -> Speed
				sin:=Fsin(floatcnt*3.14/112.0)
				cos:=Fcos(floatcnt*3.14/125.0)
				sin:=sin*50.0+30.0
				cos:=cos*50.0+30.0
				-> StringF(text,'Sin value: \l\d[4] Cos value: \l\d[4]',!sin!,!cos!)
				sin:=!sin!
				cos:=!cos!

				-> TextF(20,30,text)

				Plot(110+cos,50+sin,1)

				burp[120]:=110+cos
				barp[120]:=50+sin

				FOR tcnt:=1 TO 120
					burp[tcnt-1]:=burp[tcnt]
					barp[tcnt-1]:=barp[tcnt]
				ENDFOR

				Plot(burp[2],barp[2],0)

				WaitBlit()
				BTST #6,$BFE001
				BEQ exit

				BltBitMap(tbitmap,10+cos,20+sin,scr.bitmap,10,20,310,120,$0C0,$1,NIL)
			ENDFOR
exit:
			-> Delay(50*2)
			
			WriteF('All nice and done!!!\n')			

			deletebitmap(tbitmap)
		ENDIF
		CloseS(scr)
	ENDIF

 CleanUp(0)
ENDPROC




PROC createbitmap(width,height,depth,flags,friend:PTR TO bitmap)
  DEF bm:PTR TO bitmap,memflags,pl:PTR TO LONG,i
  IF KickVersion(39)
    bm:=AllocBitMap(width,height,depth,flags,friend)
  ELSE
    memflags:=MEMF_CHIP OR MEMF_CLEAR
    IF bm:=New(SIZEOF bitmap)
      InitBitMap(bm,depth,width,height)
      pl:=bm.planes
      IF flags AND BMF_CLEAR THEN memflags:=memflags OR MEMF_CLEAR
      pl[0]:=AllocVec(depth*rassize(width,height),memflags)
      IF pl[0]
        FOR i:=1 TO depth-1 DO pl[i]:=pl[i-1]+rassize(width,height)
      ELSE
        Dispose(bm)
      ENDIF
    ENDIF
  ENDIF
ENDPROC bm

PROC deletebitmap(bm:PTR TO bitmap)
  IF bm
    IF KickVersion(39)
      FreeBitMap(bm)
     ELSE
       FreeVec(Long(bm.planes))
       Dispose(bm)
     ENDIF
  ENDIF
ENDPROC

PROC rassize(w,h) IS Shr(w+15,3) AND $FFFE * h