;FastGfx (FGfx) V0.3a By David Newton (dave@nbsamiga.demon.co.uk) ; ;Please read the docs include on how to use this include. ; ;bb2objtypes.res must be resident in compiler options/resident ;(that file should be in the blitzlibs: assign!)   END_OF_FastGfx  ;#FGFX_COMPACT=0        ;- this should be in your main source file  ;My FGfx setups  ;Include these parts #FGFXDRAW=1             ;include 2d drawing functions?? #FGFXFILE=1             ;include save+load functions?? #FGFXBLIT=1             ;include blit/block/scroll functions  ;FGfx file types #IFF_FILE=0 #FGFX_FILE=1 #FORMCHECK=$464F524D    ;FORM file type #FGFXCHECK=$46476678    ;FGfx file type  ;Shape data #FastShapeShift=5     ;2^n=sizeof .fastshape   .fastshape    ;Sizeof 32   ebwidth.w     ;even byte width of shape   height.w      ;height in lines of shape   _depth.w      ;depth of shape   flags.w       ;shape attributes   planes.l      ;pointer to planes   cookie.l      ;pointer to cookie   planesize.l   ;size of a single bitplane of shape   pad.b[12]     ;pad     ;Do some heavy Macro Magic.........:))))   CpuBlitPlanesMacro   ~.l (a5),d4:B.l d5,d4:.l #0,d6   ~.w (a1)+,d6:|.l d0,d6:.l d6,d4:~.l d4,(a5):=.l a3,a5    `1>1:!CpuBlitPlanesMacro{`1-1}:     CpuBlitMacro CpuBlit1_`1: ~.w a6,d2 CpuBlit2_`1: ~.l a2,a5:.l #0,d5:~.w (a0)+,d5:|.l d0,d5:.l d5   !CpuBlitPlanesMacro{`1}   @.w  #2,a2:o d2,CpuBlit2_`1   =.l a4,a2:o d3,CpuBlit1_`1:X CpuBlitExit     CpuBlockPlanesMacro   ~.w (a0)+,(a3):=.l d7,a3    `1>1:!CpuBlockPlanesMacro{`1-1}:     CpuBlockMacro CpuBlock1_`1: ~.w d0,d5 CpuBlock2_`1: ~.l a2,a3   !CpuBlockPlanesMacro{`1}   @.w #2,a2:o d5,CpuBlock2_`1   =.w d4,a2:o d1,CpuBlock1_`1:X CpuBlockExit     CpuBlockScrollPlusMacro1 CpuBlockScrollPlus1_`1: ~.w d3,d0:~.l a2,a0:~.l a3,a1   ;height-1 into d0 CpuBlockScrollPlus2_`1: ~.w d2,d1:X CpuBlockScrollPlus4_`1     ;width into d1 CpuBlockScrollPlus3_`1: ~.l (a0)+,(a1)+ CpuBlockScrollPlus4_`1: o d1,CpuBlockScrollPlus3_`1    `1=2:~.w (a0)+,(a1)+:   =.w d6,a0:=.w d7,a1   o d0,CpuBlockScrollPlus2_`1   =.l a4,a2:=.l a5,a3   o d4,CpuBlockScrollPlus1_`1   X CpuBlockScrollExit     CpuBlockScrollMinusMacro1 CpuBlockScrollMinus1_`1: ~.w d3,d0:~.l a2,a0:~.l a3,a1   ;height-1 into d0 CpuBlockScrollMinus2_`1: ~.w d2,d1:X CpuBlockScrollMinus4_`1     ;width into d1 CpuBlockScrollMinus3_`1: ~.l -(a0),-(a1) CpuBlockScrollMinus4_`1: o d1,CpuBlockScrollMinus3_`1    `1=2:~.w -(a0),-(a1):   .w d6,a0:.w d7,a1   o d0,CpuBlockScrollMinus2_`1   =.l a4,a2:=.l a5,a3   o d4,CpuBlockScrollMinus1_`1   X CpuBlockScrollExit     ;FGfx Internal routines....don't call them directly.......   FGfx_LeavedCopy{src.l,dest.l,ebsize.l,leaved.l}   ;ebsize must be even bytes, leaved= the number of words to interleave   ~.l d0,a0    ;src into a0   ~.l d1,a1    ;dest into a1   ~.l d2,a3    ;total size into a3   =.l  a1,a3    ;end of dest in a3   ~.w d3,d4   .w #1,d4   |.w #1,d3     ;skip into words (number of words*2) FGfx_LeavedCopy1:   ~.l a1,a2    ;dest into a2   @.w #2,a1    ;move to next leaved dest offset FGfx_LeavedCopy2:   ~.w (a0)+,(a2):=.w d3,a2:\.l a2,a3:J FGfx_LeavedCopy2    ;copy then do rest until end of dest   o d4,FGfx_LeavedCopy1        GrabFastShape{FastShape.w,x.w,y.w}   .l a4-a6,-(a7)   ~.l FastShapeBase(pc),a0:v.l d0:|.l #FastShapeShift,d0:=.l d0,a0:~.l FastGfxBitmap(pc),a1   ~.w d1,d0:B.w #15,d0:}.w #3,d1:U.w #0,d1   ~.w (a1),d4: d4,d2:~.l d2,a4:=.w d1,a4:z.l 8(a1),a3   ~.w (a0),d6:.w d6,d4:~.w d4,a6   }.w #1,d6:.w #1,d6:~.w 2(a0),d7:.w #1,d7   ~.w 4(a0),d3:~.w d3,d4:|.w #1,d4:~.w d4,a5   .w #1,d3:.l #2,d4:~.l 8(a0),a0 GrabFastShape1: ~.l a0,a1:~.l (a3)+,a2:=.l a4,a2:~.w  d7,d2 GrabFastShape2: ~.w d6,d1 GrabFastShape3: ~.l (a2),d5:|.l d0,d5: d5:~.w d5,(a1):=.w a5,a1:=.w d4,a2   o d1,GrabFastShape3   =.l a6,a2:o d2,GrabFastShape2   @.w  #2,a0:o d3,GrabFastShape1   .l (a7)+,a4-a6        SetFastGfxBitmap{bmapaddr.l}   z.l FastGfxBitmap(pc),a0:~.l d0,(a0)   ~.l d0,a0:~.w  (a0),d0: 2(a0),d0   z.l FastGfxBitmapAdd(pc),a0:~.l d0,(a0)       	.l GetFastGfxBitmap{}   ~.l FastGfxBitmap(pc),d0        SetFastGfxScrollBitmap{bmapaddr.l}   z.l FastGfxScrollBitmap(pc),a0:~.l d0,(a0)   ~.l d0,a0:~.w  (a0),d0: 2(a0),d0   z.l FastGfxScrollBitmapAdd(pc),a0:~.l d0,(a0)       	.l GetFastGfxScrollBitmap{}   ~.l FastGfxScrollBitmap(pc),d0        SetFastShapeBase{FastShapeBase.l}   z.l   FastShapeBase(pc),a0:~.l d0,(a0)       	.l GetFastShapeBase{}   ~.l  FastShapeBase(pc),d0     	   SetFastShapeMax{FastShapeMax.w}   z.l   FastShapeMax(pc),a0:~.w d0,(a0)       	.w GetFastShapeMax{}   ~.w FastShapeMax(pc),d0     	  	.l GetFastShapeOffset{FastShape.w}   v.l d0:~.l  FastShapeBase(pc),d1:|.l #FastShapeShift,d0:=.l d1,d0     	  ;FGfx User Functions.................   FreeFastShape{FastShape.w}   *tmpfs.fastshape=GetFastShapeOffset{FastShape}    *tmpfs\ebwidth>0      *tmpfs\planes<>0 ! 	 *tmpfs\planes,*tmpfs\planesize*(*tmpfs\_depth)      *tmpfs\cookie<>0 ! 	 *tmpfs\cookie,*tmpfs\planesize     *tmpfs\ebwidth=0        RemoveFastShapes{}   fsbase.l=GetFastShapeBase{}    fsbase<>0     fsmax.w=GetFastShapeMax{}      loop.w=0  fsmax-1:FreeFastShape{loop}: loop     	 fsbase,fsmax*/ .fastshape     SetFastShapeBase{0}:SetFastShapeMax{0}       	.b InitFastShapes{FastShapeMax.w}   fsbase.l=GetFastShapeBase{}: fsbase<>0 ! RemoveFastShapes{}   fsadr.l=(FastShapeMax*/ .fastshape,$10001)    fsadr<>0     SetFastShapeBase{fsadr}:SetFastShapeMax{FastShapeMax}     	     "     	       	  	.b TestCpuBitmap{bmap.w}   bmapokay.b=:*testbmap.bitmap= (bmap)    *testbmap<>0      (*testbmap\_flags=0)&(*testbmap_bitplanemod<>0)       bmapokay=           	  bmapokay  	   SetCpuBitmap{bmap.w}   SetFastGfxBitmap{ (bmap)}     SetCpuScrollBitmap{bmap.w}   SetFastGfxScrollBitmap{ (bmap)}    	.b MakeBitmap{bmap.w,bwidth.w,bheight.w,bdepth.w,bmemtype.l}   bmemadr.l=((bwidth/8)*bdepth*bheight,bmemtype)    bmemadr<>0      bmap,bwidth,bheight,bdepth,bmemadr     	     "     	       	  ;Function.b SaveCpuBitmap{bmap.w,filename$,filetype.w,key.w} ;  If WriteFile(0,filename$) ;    Select filetype ;      Case #IFF_FILE:checktype=#ILBMCHECK:WriteMem 0,&checktype,4:CpuEncodeILBM{bmap} ;      Case #FGFX_FILE:checktype=#FBMPCHECK:WriteMem 0,&checktype,4:CpuEncodeFBMP{bmap,key} ;    End Select ;    Function Return True ;  Else ;    Function Return False ;  EndIf ;End Statement  ;Function.b LoadCpuBitmap{bmap.w,filename$,key.w} ;  ;automatically check for iff, or FGfx type, then load accordingly ;  bmapokay.b=False:checktype.l=0 ;  If ReadFile(0,filename$) ;    ReadMem 0,&checktype,4 ;    Select checktype ;      Case #ILBMCHECK:bmapokay=CpuDecodeILBM{bmap} ;      Case #FBMPCHECK:bmapokay=CpuDecodeFBMP{bmap,key} ;    End Select ;    CloseFile 0 ;  EndIf ;  Function Return bmapokay ;End Function   FreeFastCookie{FastShape.w}   *tmpfs.fastshape=GetFastShapeOffset{FastShape}    *tmpfs\ebwidth>0      *tmpfs\cookie<>0 ! 	 *tmpfs\cookie,*tmpfs\planesize:*tmpfs\cookie=0        MakeFastCookie{FastShape.w}   ~.l FastShapeBase(pc),a0:v.l d0:|.l #FastShapeShift,d0:=.l d0,a0   ~.w (a0),d0:}.w #1,d0:.w #1,d0:~.w 2(a0),d1:.w #1,d1   ~.w 4(a0),d2:.w #1,d2:~.l 12(a0),a1:~.l 8(a0),a0 MakeFastCookie1: ~.w d0,d3 MakeFastCookie2: ~.w d2,d4:.l #0,d5 MakeFastCookie3: .w (a0)+,d5   o  d4,MakeFastCookie3    ;do all planes (single word)   ~.w d5,(a1)+   o  d3,MakeFastCookie2    ;do single line (all planes)   o  d1,MakeFastCookie1     ;do all lines        GetFastShape{FastShape.w,x.w,y.w,width.w,height.w}   *tmpfs.fastshape=GetFastShapeOffset{FastShape}    *tmpfs\ebwidth>0 ! FreeFastShape{FastShape}   ebwidth.w=width/8: (ebwidth*8)<width ! ebwidth+1    ebwidth&1 ! ebwidth+1   *bmap.bitmap=GetFastGfxBitmap{}   planes.w=*bmap\_depth:planesize.l=ebwidth*height   *tmpfs\planes=(planesize*planes,$1)    *tmpfs\planes<>0     *tmpfs\ebwidth=ebwidth:*tmpfs\height=height     *tmpfs\planesize=planesize:*tmpfs\_depth=planes     GrabFastShape{FastShape,x,y}     *tmpfs\cookie=(planesize,$1)      *tmpfs\cookie<>0 ! MakeFastCookie{FastShape}        ShapeToFastShape{numshape.w,FastShape.w}   *shp.shape= (numshape)   *tmpfs.fastshape=GetFastShapeOffset{FastShape}    *tmpfs\ebwidth>0 ! FreeFastShape{FastShape}    *shp   *tmpfs\ebwidth=\_ebwidth,\_pixheight,\_depth,0,0,0,\_onebpmem   singleplane.l=*tmpfs\planesize:totalplanes.l=singleplane*\_depth    \_data<>0     *tmpfs\planes=(totalplanes,$1)      *tmpfs\planes<>0 ! FGfx_LeavedCopy{\_data,*tmpfs\planes,totalplanes,\_depth}       \_cookie<>0     *tmpfs\cookie=(singleplane,$1)      *tmpfs\cookie<>0 ! MakeFastCookie{FastShape}        #FGFX_COMPACT=1   CpuBlit{FastShape.w,x.w,y.w}   .l a4-a6,-(a7)   ~.l FastShapeBase(pc),a0:v.l d0:|.l #FastShapeShift,d0:=.l d0,a0   ~.l FastGfxBitmap(pc),a1:~.l FastGfxBitmapAdd(pc),a3:~.w d1,d0   B.w #15,d0:}.w #3,d1:U.w #0,d1:~.w (a1),d4: d4,d2:~.l d2,a2   =.w d1,a2:=.l 8(a1),a2:.l #16,d1:.w d0,d1:~.l d1,d0:~.w (a0),d6   .w d6,d4:~.w d4,a4:}.w #1,d6:.w #1,d6:~.w d6,a6:~.w 2(a0),d3   .w #1,d3:~.l 8(a0),a1:~.w 4(a0),d7:.w #1,d7:~.l 12(a0),a0 CpuBlit1: ~.w a6,d2 CpuBlit2: ~.l a2,a5:~.w d7,d1:.l #0,d5   ~.w (a0)+,d5:|.l d0,d5:.l d5 CpuBlit3: ~.l (a5),d4:B.l d5,d4:.l #0,d6   ~.w (a1)+,d6:|.l d0,d6:.l d6,d4:~.l d4,(a5)   =.l a3,a5:o d1,CpuBlit3   @.w  #2,a2:o d2,CpuBlit2   =.l a4,a2:o d3,CpuBlit1   .l (a7)+,a4-a6        CpuBlock{FastShape.w,x.w,y.w}   ~.l FastShapeBase(pc),a0:v.l d0:|.l #FastShapeShift,d0:=.l d0,a0   ~.l FastGfxBitmap(pc),a1:~.l FastGfxBitmapAdd(pc),d7   }.w #3,d1:U.w #0,d1:~.w (a1),d4: d4,d2:~.l d2,a2:=.w d1,a2   =.l 8(a1),a2:~.w (a0),d0:.w d0,d4:}.w #1,d0:.w #1,d0   ~.w 2(a0),d1:.w #1,d1:~.w 4(a0),d2:.w #1,d2:~.l 8(a0),a0 CpuBlock1:  ~.w d0,d5 CpuBlock2:  ~.l a2,a3:~.w d2,d6 CpuBlock3: ~.w (a0)+,(a3):=.l d7,a3   o d6,CpuBlock3   @.w #2,a2:o d5,CpuBlock2   =.w d4,a2:o d1,CpuBlock1          CpuBlit{FastShape.w,x.w,y.w}   .l a4-a6,-(a7)   ~.l FastShapeBase(pc),a0:v.l d0:|.l #FastShapeShift,d0:=.l d0,a0   ~.l FastGfxBitmap(pc),a1:~.l FastGfxBitmapAdd(pc),a3:~.w d1,d0   B.w #15,d0:}.w #3,d1:U.w #0,d1:~.w (a1),d4: d4,d2:~.l d2,a2   =.w d1,a2:=.l 8(a1),a2:.l #16,d1:.w d0,d1:~.l d1,d0   ~.w (a0),d6:.w d6,d4:~.w d4,a4:}.w #1,d6:.w #1,d6:~.w d6,a6   ~.w 2(a0),d3:.w #1,d3:~.l 8(a0),a1:~.w 4(a0),d7:~.l 12(a0),a0   |.w #2,d7:z.l CpuBlitJumpTable(pc),a5:=.w d7,a5:~.l (a5),a5:x (a5) CpuBlitExit:   .l (a7)+,a4-a6      ' CpuBlitJumpTable:   %.l CpuBlitExit,CpuBlit1_1,CpuBlit1_2,CpuBlit1_3,CpuBlit1_4   %.l CpuBlit1_5,CpuBlit1_6,CpuBlit1_7,CpuBlit1_8   !CpuBlitMacro{1}:!CpuBlitMacro{2}:!CpuBlitMacro{3}:!CpuBlitMacro{4}   !CpuBlitMacro{5}:!CpuBlitMacro{6}:!CpuBlitMacro{7}:!CpuBlitMacro{8}     CpuBlock{FastShape.w,x.w,y.w}   ~.l FastShapeBase(pc),a0:v.l d0:|.l #FastShapeShift,d0:=.l d0,a0   ~.l FastGfxBitmap(pc),a1:~.l FastGfxBitmapAdd(pc),d7   }.w #3,d1:U.w #0,d1:~.w (a1),d4: d4,d2:~.l d2,a2:=.w d1,a2   =.l 8(a1),a2:~.w (a0),d0:.w d0,d4:}.w #1,d0:.w #1,d0   ~.w 2(a0),d1:.w #1,d1:~.w 4(a0),d2:~.l 8(a0),a0   |.w #2,d2:z.l CpuBlockJumpTable(pc),a1:=.w d2,a1:~.l (a1),a1:x (a1) CpuBlockExit:      ' CpuBlockJumpTable:   %.l CpuBlockExit,CpuBlock1_1,CpuBlock1_2,CpuBlock1_3,CpuBlock1_4   %.l CpuBlock1_5,CpuBlock1_6,CpuBlock1_7,CpuBlock1_8   !CpuBlockMacro{1}:!CpuBlockMacro{2}:!CpuBlockMacro{3}:!CpuBlockMacro{4}   !CpuBlockMacro{5}:!CpuBlockMacro{6}:!CpuBlockMacro{7}:!CpuBlockMacro{8}       CpuBlockScroll{srcx.w,srcy.w,width.w,height.w,destx.w,desty.w}   .l a4-a5,-(a7)   ~.l FastGfxScrollBitmap(pc),a0:~.l FastGfxBitmap(pc),a1   ~.l FastGfxScrollBitmapAdd(pc),a4:~.l FastGfxBitmapAdd(pc),a5   \.l a0,a1:P CpuBlockScrollPlus   \.w d1,d5:N CpuBlockScrollPlus:J CpuBlockScrollMinus   \.w d0,d4:N CpuBlockScrollPlus:J CpuBlockScrollMinus CpuBlockScrollExit:   .l (a7)+,a4-a5      ' CpuBlockScrollPlus:   ;scroll from the bitmap in a0, to the bitmap in a1, going left-right, top to bottom   ~.w (a0),d6: d6,d1:}.w #3,d0:U.w #0,d0:~.l d1,a2:=.w d0,a2:=.l 8(a0),a2   ;src offset in a2  (plane1)   ~.w (a1),d7: d7,d5:}.w #3,d4:U.w #0,d4:~.l d5,a3:=.w d4,a3:=.l 8(a1),a3   ;dest offset in a3 (plane1)   }.w #3,d2:U.w #0,d2:.w d2,d6:.w d2,d7   ~.w 4(a0),d4:~.w 4(a1),d5:\.w d5,d4:N CpuBlockScrollPlusSkip:~.w d5,d4 CpuBlockScrollPlusSkip:   .w #1,d4:.w #1,d3:~.w d2,d0:}.w #2,d2:W.w #1,d0:P CpuBlockScrollPlus1_2   !CpuBlockScrollPlusMacro1{1}   !CpuBlockScrollPlusMacro1{2} CpuBlockScrollMinus:   ;scroll from the bitmap in a0, to the bitmap in a1, going right-left, bottom to top   ~.w (a0),d6: d6,d1:}.w #3,d0:U.w #0,d0:~.l d1,a2:=.w d0,a2:=.l 8(a0),a2   ;src offset in a2  (plane1)   ~.w (a1),d7: d7,d5:}.w #3,d4:U.w #0,d4:~.l d5,a3:=.w d4,a3:=.l 8(a1),a3   ;dest offset in a3 (plane1)   .w #1,d3:~.w d3,d0: d6,d0:=.l d0,a2:~.w d3,d0: d7,d0:=.l d0,a3   }.w #3,d2:U.w #0,d2:.w d2,d6:.w d2,d7:=.w d2,a2:=.w d2,a3   ~.w 4(a0),d4:~.w 4(a1),d5:\.w d5,d4:N CpuBlockScrollMinusSkip:~.w d5,d4 CpuBlockScrollMinusSkip:   .w #1,d4:~.w d2,d0:}.w #2,d2:W.w #1,d0:P CpuBlockScrollMinus1_2   !CpuBlockScrollMinusMacro1{1}   !CpuBlockScrollMinusMacro1{2}   X CpuBlockScrollExit     FastGfxBitmap:  %.l  0 FastGfxBitmapAdd: %.l  0 FastGfxScrollBitmap:  %.l 0 FastGfxScrollBitmapAdd: %.l 0 FastShapeBase:  %.l  0 FastShapeMax:   %.w  0  FastShapeVer: %.b "$FVER: FGfxV0.3a By David Newton - NBSAmiga'98",$A               %.b "You are free to use these routines, aslong as",$A               %.b "this version info is left intact, and some credit",$A               %.b "for these routines is given in the software.",$A  #FGFX_COMPACT=1               %.b "FastGfx Compact Version",$A,$0,$0                %.b "FastGfx Non-Compact Version",$A,$0,$0     ' END_OF_FastGfx:  