Skip to content
debrouxl edited this page Aug 24, 2012 · 4 revisions

Fixing the sprite routines in GCC4TI 0.96 Beta 10

In GCC4TI 0.96 Beta 10, the GCC4TI project provided to a wider community improved sprite routines: one more drawing mode, smaller and faster code. A mismatch between the implementation and the C prototypes of the sprite routines slipped through our testing, though: the project we used to test the sprite routines carried its own definitions (something we had forgotten about), and the compilation options were such that the problem didn't trigger in that project (this is common with those nasty calling convention mismatches).

The problem was found by Lionel Debroux through testing in other conditions, and fixed by SVN r1360, before being independently reported by Travis Evans. Here's how to fix it in the GCC4TI 0.96 Beta 10 release:

  • download a recompiled tigcc.a from http://www.mirari.fr/sncx (yAronet's upload area), to get fresh binaries of the Sprite8/16/32 routines and more (see below);
  • replace the prototypes of Sprite8/16/32, in $TIGCC/include/c/sprites.h, by:

extern void Sprite8(short asm("d0"),short asm("d1"),short asm("d2"),const unsigned char* asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;

extern void Sprite16(short asm("d0"),short asm("d1"),short asm("d2"),__cpushort asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;

extern void Sprite32(short asm("d0"),short asm("d1"),short asm("d2"),__cpulong asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;

  • add the prototypes of ClipSprite*, in $TIGCC/include/c/sprites.h:

extern void ClipSprite8(short asm("d0"),short asm("d1"),short asm("d2"),const unsigned char* asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;

extern void ClipSprite16(short asm("d0"),short asm("d1"),short asm("d2"),__cpushort asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;

extern void ClipSprite32(short asm("d0"),short asm("d1"),short asm("d2"),__cpulong asm("a0"),void* asm("a1"),short asm("d3"))__ATTR_LIB_ASM__;

  • replace the prototypes of bsearch and qsort, in $TIGCC/include/c/stdlib.h, by:

extern void *bsearch(const void* asm("a0"),const void* asm("a1"),short asm("d0"),short asm("d1"),compare_t asm("a2")) __ATTR_LIB_ASM__;

extern void qsort(void* asm("a0"),short asm("d0"),short asm("d1"),compare_t asm("a2"))__ATTR_LIB_ASM__;

This is because besides a slight change in the Sprite8/16/32 routines, the recompiled tigcc.a contains:

  1. a code correctness fix + size optimization for bsearch() (which has been broken since before the creation of the TIGCC CVS repository in 2004, probably since the routine was integrated in TIGCC);

  2. a significant size & speed optimization on qsort(), which was reported to be slow (it was, indeed, and it could be made faster by using a simple, well-known tweak for the algorithm);

  3. new ClipSprite8/16/32 routines (same prototype as Sprite8/16/32) that Joey Adams contributed to TIGCC in 2005;

  4. support for MIN_AMS 301 and 310.

In future GCC4TI releases, we plan to keep working on reviewing and integrating pieces of the community's work, which have been contributed to TIGCC years ago, but never acted upon by the maintainer. Among those ideas and contributions, the sprite routines were probably the most extreme example of delay: to date (20090923, still valid 20111014), TIGCC's sprite routines still are in their pristine form. That is, they don't even contain the well-tested optimizations that were performed in ExtGraph and simultaneously contributed to TIGCC in 2002 and 2003...

Clone this wiki locally