;Zeewolf Scroll Mildred Example.
;
;Programmed by : Mikkel Loekke, aka. FlameDuck.
;
;Please read the README file.
;

Fil$="RAM:M2P.ILBM"


WBStartup
NoCli

DEFTYPE.l

MCPU Processor                        ; Tell Mildred which CPU it should use.
Mc2pCPUmode Processor                 ; Tell Mildred which CPU it should us for c2p.

MReserveBitmaps 1                     ; Tell Mildred that we're going to use 2 chunky bitmaps.
MReservec2pWindows 1                  ; Tell it we only need one c2p display.

MBitmap 0,640,512                     ; This will contain our chunky buffer.

*pbb.l=AllocMem(640*512,#MEMF_PUBLIC) ; Get us a large block of any memory.
If *pbb                               ; if we succeed
  CludgeBitMap 0,640,512,8,*pbb       ; make it a bitmap (bitmaps can be in fast memory, aslong as we don't display them).
  LoadBitMap 0,Fil$,0                 ; Load the logo.
  MPlanar16ToBitmap 0,*pbb            ; convert it to a chunky bitmap
  Free BitMap 0                       ; Free the bitmap structure. (We don't need it anymore
  FreeMem *pbb,640*512                ; Free up our memory.
Else End
EndIf


Mc2pWindow 0,320,256,640,320,256                 ; Define our c2p operation.

Dim bmppnt.l(1)                                  ; Create two bitmap pointers.

bmppnt(0)=AllocMem(320*256,#MEMF_CHIP)           ; Get some free CHIP memory.
If bmppnt(0)                                     ; and if we succeed
  CludgeBitMap 0,320,256,8,bmppnt(0)             ; make it a planar bitmap.
Else End
EndIf

bmppnt(1)=AllocMem(320*256,#MEMF_CHIP)           ; Get some more free CHIP memory.
If bmppnt(1)                                     ; and if we succeed
  CludgeBitMap 1,320,256,8,bmppnt(1)             ; make it our second planar bitmap. (For a double buffered display)
Else End
EndIf

Dim scrtaglst.TagItem(7)            ; All this stuff sets up our
scrtaglst(0)\ti_Tag = #SA_Left      ; Taglist for the screen we
scrtaglst(0)\ti_Data = 0            ; want.
scrtaglst(1)\ti_Tag = #SA_Depth
scrtaglst(1)\ti_Data = 8
scrtaglst(2)\ti_Tag = #SA_Width
scrtaglst(2)\ti_Data = 320
scrtaglst(3)\ti_Tag = #SA_Height
scrtaglst(3)\ti_Data = 256
scrtaglst(4)\ti_Tag = #SA_BitMap
scrtaglst(4)\ti_Data = Addr BitMap (0)
scrtaglst(5)\ti_Tag = #SA_ShowTitle
scrtaglst(5)\ti_Data = 0
scrtaglst(6)\ti_Tag = #SA_Draggable
scrtaglst(6)\ti_Data = 0
scrtaglst(7)\ti_Tag = #TAG_END      ; The most important tag of them all.


ScreenTags 0,"MildredDEMO",&scrtaglst(0) ; Open our intuition screen
ShowPalette 0                               ; and show our palette.

x.w=160:y.w=128:xa.b=1:ya.b=1:act.b=0:rel.b=1 ; Initialize variables.

Repeat                                      ; Repeat our mainloop ....
  ResetTimer
  Mc2p 0,MBitmapPtr(x,y,0),bmppnt(rel)      ; Convert our chunky buffer to out the relative bitmap.

  If Timer <1 Then  WaitTOF_                ; Wait for refresh display, if the c2p took less than one frame.
  ShowBitMap rel                            ; And show it.

  x+xa:y+ya                                 ; Jump arround on the display.
  If x=319 OR x=1 Then xa=-xa               ; If we hit one edge of the bitmap, bounce the other way.
  If y=255 OR y=1 Then ya=-ya               ; If we hit the top or bottom of the bitmap, bounce the other way.
  If act=0 Then act=1:rel=0:Else act=0:rel=1 ; Swap relative and actual buffers (or bitmaps) the double buffering bit.
Until RawStatus($45)                        ; .... Until we press Escape.

End                                         ; End our nice program.

