Browse Source

tigcclib: overhaul Sprite8/16/32: add SPRT_RPLC mode while making the routines smaller (Joey Adams, Lionel Debroux).

git-svn-id: file:///var/svn/tigccpp/trunk@1344 9552661e-59e3-4036-b4f2-dbe53926924f
debrouxl 15 years ago
parent
commit
b0b0c9ec43

+ 0 - 18
tigcc/archive/sprite16.c

@@ -1,18 +0,0 @@
-#include <sprites.h>
-
-__ATTR_LIB_C__ void Sprite16(short x, short y, short h, const unsigned short *sprite, void *buff, short mode)
-{
-  long addr=(long)buff+30*y+((x>>3)&0xfffe),d1;
-  unsigned short cnt=16-(x&15),data;
-  for(;h--;addr+=30)
-    {
-      data=*sprite++;
-      if(mode==SPRT_AND) *(long*)addr&=~((long)~data<<cnt);
-      else
-        {
-          d1=(long)data<<cnt;
-          if(mode==SPRT_XOR) *(long*)addr^=d1;
-          else *(long*)addr|=d1;
-        }
-    }
-}

+ 69 - 0
tigcc/archive/sprite16.s

@@ -0,0 +1,69 @@
+
+.globl Sprite16
+.text
+.even
+Sprite16:
+| Compute offset from beginning of plane.
+	mulu.w #30,%d1 | 4
+	adda.l %d1,%a1 | 2
+	move.w %d0,%d1 | 2
+	lsr.w #4,%d1 | 2
+	add.w %d1,%d1 | 2
+	adda.w %d1,%a1 | 2
+| d0: shift count.
+	not.w %d0 | 2
+	and.w #15,%d0 | 4
+	addq.w #1,%d0 | 2
+
+	move.w %d4,-(%a7) | 2
+	move.l %d3,-(%a7) | 2
+| d4: drawing mode.
+	move.w 4+6(%a7),%d4 | 4
+	subq.w #1,%d4 | 2
+| d3: mask used by AND and RPLC.
+	moveq #-1,%d3 | 2
+	clr.w %d3 | 2
+	rol.l %d0,%d3 | 2
+| Jump to loop entry.
+	bra.s .L__s16_loopentry | 2
+
+| AND.
+.L__s16_Am:
+	or.l %d3,%d1 | 2
+	and.l %d1,(%a1) | 2
+
+| Next line.
+.L__s16_loop:
+	lea 30(%a1),%a1 | 4
+
+.L__s16_loopentry:
+| Have we finished ?
+	subq.w #1,%d2 | 2
+	blt.s .L__s16_rts | 2
+
+	moveq #0,%d1 | 2
+	move.w (%a0)+,%d1 | 2
+	lsl.l %d0,%d1 | 2
+	cmp.w #1,%d4 | 4
+	beq.s .L__s16_Am | 2
+	tst.w %d4 | 2
+	blt.s .L__s16_Xm | 2
+	beq.s .L__s16_Om | 2
+| RPLC.
+	and.l %d3,(%a1) | 2
+
+| OR.
+.L__s16_Om:
+	or.l %d1,(%a1) | 2
+	bra.s .L__s16_loop | 2
+
+| XOR
+.L__s16_Xm:
+	eor.l %d1,(%a1) | 2
+	bra.s .L__s16_loop | 2
+
+| Return
+.L__s16_rts:
+	move.l (%a7)+,%d3 | 2
+	move.w (%a7)+,%d4 | 2
+	rts | 2

+ 0 - 23
tigcc/archive/sprite32.c

@@ -1,23 +0,0 @@
-#include <sprites.h>
-
-__ATTR_LIB_C__ void Sprite32(short x, short y, short h, const unsigned long *sprite, void *buff, short mode)
-{
-  long addr=(long)buff+30*y+((x>>3)&0xfffe);
-  unsigned long data,d1,d2;
-  short cnt=x&15,ccnt=32-cnt;
-  for(;h--;addr+=30)
-    {
-      data=*sprite++;
-      if(mode==SPRT_AND)
-        {
-          data=~data;
-          *(long*)addr&=~(data>>cnt),*(long*)(addr+4)&=~(data<<ccnt);
-        }
-      else
-        {
-          d1=data>>cnt; d2=data<<ccnt;
-          if(mode==SPRT_XOR) *(long*)addr^=d1,*(long*)(addr+4)^=d2;
-          else *(long*)addr|=d1,*(long*)(addr+4)|=d2;
-        }
-    }
-}

+ 74 - 0
tigcc/archive/sprite32.s

@@ -0,0 +1,74 @@
+
+.globl Sprite32
+.text
+.even
+Sprite32:
+	movem.l %d3-%d7,-(%a7) | 4
+| Compute offset from beginning of plane.
+	mulu.w #30,%d1 | 4
+	adda.l %d1,%a1 | 2
+	move.w %d0,%d1 | 2
+	lsr.w #4,%d1 | 2
+	add.w %d1,%d1 | 2
+	adda.w %d1,%a1 | 2
+| d0, d5: shift counts.
+	and.w #15,%d0 | 4
+	moveq #16,%d5 | 2
+	sub.w %d0,%d5 | 2
+
+| d4: drawing mode.
+	move.w 4+5*4(%a7),%d4 | 4
+	subq.w #1,%d4 | 2
+| d3, d6: masks used by AND and RPLC.
+	moveq #-1,%d3 | 2
+	lsr.w %d0,%d3 | 2
+        move.w %d3,%d6 | 2
+        not.l %d3 | 2
+        swap %d3 | 2
+| Jump to loop entry.
+	bra.s .L__s32_loopentry | 2
+
+| AND.
+.L__s32_Am:
+	or.l %d3,%d1 | 2
+	or.w %d6,%d7 | 2
+	and.l %d1,(%a1)+ | 2
+	and.w %d7,(%a1) | 2
+
+| Next line.
+.L__s32_loop:
+	lea 26(%a1),%a1 | 4
+
+.L__s32_loopentry:
+| Have we finished ?
+	subq.w #1,%d2 | 2
+	blt.s .L__s32_rts | 2
+
+	move.l (%a0)+,%d1 | 2
+	move.w %d1,%d7 | 2
+        lsr.l %d0,%d1 | 2
+        lsl.w %d5,%d7 | 2
+	cmp.w #1,%d4 | 4
+	beq.s .L__s32_Am | 2
+	tst.w %d4 | 2
+	blt.s .L__s32_Xm | 2
+	beq.s .L__s32_Om | 2
+| RPLC.
+	and.l %d3,(%a1) | 2
+	and.w %d6,4(%a1) | 2
+| OR.
+.L__s32_Om:
+	or.l %d1,(%a1)+ | 2
+	or.w %d7,(%a1) | 2
+	bra.s .L__s32_loop | 2
+
+| XOR
+.L__s32_Xm:
+	eor.l %d1,(%a1)+ | 2
+	eor.w %d7,(%a1) | 2
+	bra.s .L__s32_loop | 2
+
+| Return
+.L__s32_rts:
+	movem.l (%a7)+,%d3-%d7 | 4
+	rts | 2

+ 0 - 18
tigcc/archive/sprite8.c

@@ -1,18 +0,0 @@
-#include <sprites.h>
-
-__ATTR_LIB_C__ void Sprite8(short x, short y, short h, const unsigned char *sprite, void *buff, short mode)
-{
-  long addr=(long)buff+30*y+((x>>3)&0xfffe),d1;
-  unsigned short cnt=24-(x&15),data;
-  for(;h--;addr+=30)
-    {
-      data=*sprite++;
-      if(mode==SPRT_AND) *(long*)addr&=~((long)(~data&0xff)<<cnt);
-      else
-        {
-          d1=(long)data<<cnt;
-          if(mode==SPRT_XOR) *(long*)addr^=d1;
-          else *(long*)addr|=d1;
-        }
-    }
-}

+ 69 - 0
tigcc/archive/sprite8.s

@@ -0,0 +1,69 @@
+
+.globl Sprite8
+.text
+.even
+Sprite8:
+| Compute offset from beginning of plane.
+	mulu.w #30,%d1 | 4
+	adda.l %d1,%a1 | 2
+	move.w %d0,%d1 | 2
+	lsr.w #4,%d1 | 2
+	add.w %d1,%d1 | 2
+	adda.w %d1,%a1 | 2
+| d0: shift count.
+	not.w %d0 | 2
+	and.w #15,%d0 | 4
+	add.w #9,%d0 | 4
+
+	move.w %d4,-(%a7) | 2
+	move.l %d3,-(%a7) | 2
+| d4: drawing mode.
+	move.w 4+6(%a7),%d4 | 4
+	subq.w #1,%d4 | 2
+| d3: mask used by AND and RPLC.
+	moveq #-1,%d3 | 2
+	clr.b %d3 | 2
+	rol.l %d0,%d3 | 2
+| Jump to loop entry.
+	bra.s .L__s8_loopentry | 2
+
+| AND.
+.L__s8_Am:
+	or.l %d3,%d1 | 2
+	and.l %d1,(%a1) | 2
+
+| Next line.
+.L__s8_loop:
+	lea 30(%a1),%a1 | 4
+
+.L__s8_loopentry:
+| Have we finished ?
+	subq.w #1,%d2 | 2
+	blt.s .L__s8_rts | 2
+
+	moveq #0,%d1 | 2
+	move.b (%a0)+,%d1 | 2
+	lsl.l %d0,%d1 | 2
+	cmp.w #1,%d4 | 4
+	beq.s .L__s8_Am | 2
+	tst.w %d4 | 2
+	blt.s .L__s8_Xm | 2
+	beq.s .L__s8_Om | 2
+| RPLC.
+	and.l %d3,(%a1) | 2
+
+| OR.
+.L__s8_Om:
+	or.l %d1,(%a1) | 2
+	bra.s .L__s8_loop | 2
+
+| XOR
+.L__s8_Xm:
+	eor.l %d1,(%a1) | 2
+	bra.s .L__s8_loop | 2
+
+| Return
+.L__s8_rts:
+	move.l (%a7)+,%d3 | 2
+	move.w (%a7)+,%d4 | 2
+	rts | 2

+ 8 - 8
tigcc/archive/tigcc.tpr

@@ -74,14 +74,11 @@ C File 16=rename.c
 C File 17=unlink.c
 C File 18=tmpnam.c
 C File 19=fsetbufsize.c
-C File 20=sprite8.c
-C File 21=sprite16.c
-C File 22=sprite32.c
-C File 23=pushfifonode.c
-C File 24=homestorepair.c
-C File 25=dll.c
-C File 26=grayversion.c
-C File 27=findprogramvar.c
+C File 20=pushfifonode.c
+C File 21=homestorepair.c
+C File 22=dll.c
+C File 23=grayversion.c
+C File 24=findprogramvar.c
 GNU Assembler File 1=bzero.s
 GNU Assembler File 2=bcopy.s
 GNU Assembler File 3=memcpy.s
@@ -435,6 +432,9 @@ GNU Assembler File 215=startup\_save_sp.s
 GNU Assembler File 215 Folder=startup
 GNU Assembler File 216=startup\_reference_symbols.s
 GNU Assembler File 216 Folder=startup
+GNU Assembler File 217=sprite8.s
+GNU Assembler File 218=sprite16.s
+GNU Assembler File 219=sprite32.s
 Text File 1=License.txt
 Text File 2=startup\Startup.txt
 Text File 2 Folder=startup

+ 9 - 3
tigcc/doc/System/Include/sprites.h/Sprite8.hsf

@@ -31,13 +31,19 @@ XOR mode switches every pixel with a corresponding '1' bit in the <I>sprite</I>
 <TD VALIGN="TOP">SPRT_OR</TD>
 <TD>OR the sprite into a background. This is mainly used for masked sprites together with SPRT_AND.
 OR means that every pixel with a corresponding '1' bit in the <I>sprite</I> array will be set to black, but all other pixels stay the same.
-If you want to turn all other pixels to white instead, one way to achieve this would be to AND
-the sprite as well.</TD>
+If you want to turn all other pixels to white instead, use SPRT_RPLC.</TD>
 </TR>
 <TR>
 <TD VALIGN="TOP">SPRT_AND</TD>
 <TD>AND the sprite into a background. This is used for masked sprites together with SPRT_OR.
-AND turns off every pixel with a corresponding '0' bit in the <I>sprite</I> array, but all other pixels remain untouched.</TD>
+AND turns off every pixel with a corresponding '0' bit in the <I>sprite</I> array, but all other pixels remain untouched.
+If you want to turn all other pixels to black instead, use SPRT_RPLC.</TD>
+</TR>
+<TR>
+<TD VALIGN="TOP">SPRT_RPLC</TD>
+<TD>RePLaCe the sprite into a background.
+RPLC sets every pixel with a corresponding '1' bit to black and every pixel with a corresponding '0' bit to white.
+This is equivalent to calling <CODE>Sprite8(x,y,h,sprite,plane,SPRT_AND); Sprite8(x,y,h,sprite,plane,SPRT_OR);</CODE>.</TD>
 </TR>
 </TABLE>
 <BR>

+ 1 - 1
tigcc/doc/System/Include/sprites.h/SprtModes.hsf

@@ -3,7 +3,7 @@ Name=SprtModes
 Type=Type
 Subtype=Enumeration
 Header Files=sprites.h
-Definition=enum SprtModes {SPRT_XOR, SPRT_OR, SPRT_AND};
+Definition=enum SprtModes {SPRT_XOR, SPRT_OR, SPRT_AND, SPRT_RPLC};
 
 [Description]
 An enumeration to describe possible modes of sprite drawing.

+ 1 - 1
tigcc/include/C/sprites.h

@@ -4,7 +4,7 @@
 #include <default.h>
 
 /* Begin Auto-Generated Part */
-enum SprtModes{SPRT_XOR,SPRT_OR,SPRT_AND};
+enum SprtModes{SPRT_XOR,SPRT_OR,SPRT_AND,SPRT_RPLC};
 extern void Sprite8(short,short,short,const unsigned char*,void*,short)__ATTR_LIB_C__;
 extern void Sprite16(short,short,short,__cpushort,void*,short)__ATTR_LIB_C__;
 extern void Sprite32(short,short,short,__cpulong,void*,short)__ATTR_LIB_C__;