BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
rianimlib.c File Reference
#include "blitzlib.h"
#include <graphics/gfx.h>
#include <datatypes/pictureclass.h>
#include <stddef.h>

Data Structures

struct  anhd

Macros

#define TOK_unpackiff   ((LIB_ripacklib << 7) + 3) /* form 1 */
#define TOK_ilbmpalette   ((LIB_ripacklib << 7) + 4)
#define LG(p)
#define WD(p)
#define ID_ANIM   0x414e494dUL
#define ID_ANHD   0x414e4844UL
#define ID_DLTA   0x444c5441UL
#define SIZEOF_BITMAP   64
#define NOCOLUMNS   ((UWORD)0xFFFF)
#define COUNT(c)
#define ANIM7_PLANE(SZ, STEP)

Enumerations

enum  { DELTA5 , DELTA7 , DELTA7SHORT }

Functions

void _InitAnim2 (void)
void _InitAnim (void)
void _InitAnim3 (void)
void _NextAnimFrame (void)
void _AnimLoop (void)
void _CountFrames (void)
void _AnimDepth (void)
void _AnimWidth (void)
void _AnimHeight (void)
void xychk (void)
void nextchk (void)
static void codeinit (void)
 init: no animation, AnimLoop on.
static LONG initfindchunk (UBYTE *chunk, ULONG id)
static ULONG padded (const UBYTE *data, ULONG len)
static UBYTE * nextchunk (UBYTE *p, UBYTE *end)
static LONG fcloop (UBYTE *p, ULONG id, UBYTE **data)
static LONG findchunk (ULONG id, UBYTE **data)
static LONG findnextchunk (ULONG id, UBYTE **data)
static int oddchunk (UBYTE *form)
static LONG findbmhd (ULONG address, struct BitMapHeader **data)
ULONG c_AnimDepth (ULONG address)
 RIAnimDepth address: the depth (bmh_Depth) of the ANIM's first frame.
ULONG c_AnimWidth (ULONG address)
 RIAnimWidth address: the width (bmh_Width) of the ANIM's first frame.
ULONG c_AnimHeight (ULONG address)
 RIAnimHeight address: the height (bmh_Height) of the ANIM's first frame.
void c_AnimLoop (UBYTE on)
 AnimLoop On|Off: go on with the third frame at the end of the ANIM (default On).
BB_BOOL c_InitAnim (ULONG address, ULONG bm, ULONG pal, ULONG offset)
 RIAnimInit address,bitmap#,palette#,xy_offset: show the first frame of an ANIM.
BB_BOOL c_InitAnim2 (ULONG address, ULONG bm, ULONG pal)
 RIAnimInit address,bitmap#,palette#: c_InitAnim() with offset 0.
BB_BOOL c_InitAnim3 (ULONG address, ULONG bm, ULONG pal, ULONG x, ULONG y, const struct BitMap *bitmap)
 RIAnimInit address,bitmap#,palette#,x,y: c_InitAnim() at the pixel position x,y.
ULONG c_CountFrames (void)
 RIAnimFrameCount: the number of frames of the ANIM of the last RIAnimInit.
static void plane5 (const UBYTE *ops, UBYTE *column, ULONG mod)
static void plane7 (const UBYTE *ops, UBYTE *column, const ULONG *data, ULONG mod)
static void plane7short (const UBYTE *ops, UBYTE *column, const UWORD *data, ULONG mod)
static void planes7 (UBYTE *body, int kind, ULONG mod)
static int unpackanim (UBYTE *dlta, int kind)
static UBYTE * otherchunks (UBYTE *chunk)
static UBYTE * framestep (UBYTE *p)
static UBYTE * nextform (UBYTE *chunk)
ULONG c_NextAnimFrame (struct BitMap *bitmap)
 RINextAnimFrame bitmap#: apply the DLTA of the next frame to the bitmap.
static void xychk_c (ULONG x, ULONG y, const struct BitMap *bitmap)
 The error check of RIAnimInit's x,y form (debugger only).
static void nextchk_c (const struct BitMap *bitmap)
 The error check of RINextAnimFrame (debugger only).

Variables

static UBYTE * firstchunk
static UBYTE * lastfoundchunk
static UBYTE * endoffile
static UBYTE * firstframe
static UBYTE * animaddress
static UBYTE * animend
static UBYTE * nextanimframe
static UWORD animheight
static UWORD animwidth
static UWORD deltacolumns
static UWORD columns [3]
static UBYTE animdepth
static PLANEPTR * bitmapaddress
static ULONG animtype7
static ULONG bitplaneoffset
static UBYTE * thirdframe
static UBYTE * cmapchunk
static UBYTE doanimloop = 0xff
static UBYTE bitmapnumber
static UBYTE palettenumber
static UBYTE animtype

Macro Definition Documentation

◆ ANIM7_PLANE

#define ANIM7_PLANE ( SZ,
STEP )

◆ COUNT

#define COUNT ( c)
Value:
((UWORD)(UBYTE)((c) - 1))
ULONG WORD UWORD c
Definition 2dlib.c:2491

◆ ID_ANHD

#define ID_ANHD   0x414e4844UL

◆ ID_ANIM

#define ID_ANIM   0x414e494dUL

◆ ID_DLTA

#define ID_DLTA   0x444c5441UL

◆ LG

#define LG ( p)
Value:
(*(ULONG *)(p))

◆ NOCOLUMNS

#define NOCOLUMNS   ((UWORD)0xFFFF)

◆ SIZEOF_BITMAP

#define SIZEOF_BITMAP   64

◆ TOK_ilbmpalette

#define TOK_ilbmpalette   ((LIB_ripacklib << 7) + 4)

◆ TOK_unpackiff

#define TOK_unpackiff   ((LIB_ripacklib << 7) + 3) /* form 1 */

◆ WD

#define WD ( p)
Value:
(*(UWORD *)(p))

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
DELTA5 
DELTA7 
DELTA7SHORT 

Function Documentation

◆ _AnimDepth()

void _AnimDepth ( void )

◆ _AnimHeight()

void _AnimHeight ( void )

◆ _AnimLoop()

void _AnimLoop ( void )

◆ _AnimWidth()

void _AnimWidth ( void )

◆ _CountFrames()

void _CountFrames ( void )

◆ _InitAnim()

void _InitAnim ( void )

◆ _InitAnim2()

void _InitAnim2 ( void )

◆ _InitAnim3()

void _InitAnim3 ( void )

◆ _NextAnimFrame()

void _NextAnimFrame ( void )

◆ c_AnimDepth()

ULONG c_AnimDepth ( ULONG address)

RIAnimDepth address: the depth (bmh_Depth) of the ANIM's first frame.

The BMHD is searched in the first frame (InitFindChunk of the ANIM and of its first ILBM, then FindChunk); the chunk walk adds the pad byte of an odd length when it is 0 (fixed #505) and stops at a chunk at an odd address (fixed #1119). It changes the chunk search state.

Parameters
addressd0: the ANIM file in memory
Returns
d0: the depth (a byte), 0 without ANIM, ILBM or BMHD

◆ c_AnimHeight()

ULONG c_AnimHeight ( ULONG address)

RIAnimHeight address: the height (bmh_Height) of the ANIM's first frame.

As RIAnimWidth.

Parameters
addressd0: the ANIM file in memory
Returns
d0: $FFFF0000 | the height, 0 without ANIM, ILBM or BMHD

◆ c_AnimLoop()

void c_AnimLoop ( UBYTE on)

AnimLoop On|Off: go on with the third frame at the end of the ANIM (default On).

Parameters
ond0: the byte of On (-1) or Off (0)

◆ c_AnimWidth()

ULONG c_AnimWidth ( ULONG address)

RIAnimWidth address: the width (bmh_Width) of the ANIM's first frame.

As RIAnimDepth; MOVE.w into a d0 that is -1: the upper word is $FFFF.

Parameters
addressd0: the ANIM file in memory
Returns
d0: $FFFF0000 | the width, 0 without ANIM, ILBM or BMHD

◆ c_CountFrames()

ULONG c_CountFrames ( void )

RIAnimFrameCount: the number of frames of the ANIM of the last RIAnimInit.

Counts the FORM ILBM chunks of the ANIM (fixed #510: the original counted every chunk). The walk is unsigned and stays inside the ANIM (fixed #506), with the pad bytes (fixed #505).

Returns
d0: the number of frames, 0 before an RIAnimInit

◆ c_InitAnim()

BB_BOOL c_InitAnim ( ULONG address,
ULONG bm,
ULONG pal,
ULONG offset )

RIAnimInit address,bitmap#,palette#,xy_offset: show the first frame of an ANIM.

Finds the first frame (FORM ILBM in the FORM ANIM) and its BMHD (in that frame; fixed #511: the original searched up to the end of the ANIM), unpacks it into the bitmap with RIPackLib's UnpackIFF (form 1: d0 source, d1 bitmap#, d2 -1 lines, d3 offset) and sets the palette with ILBMPalette (d0 source, d1 palette#), both through ALibJsr; then remembers the second and third frame (the first if there are none). RIAnimInit fails when UnpackIFF refuses the bitmap (fixed #1106: the original dropped its result): too narrow (fewer bytes per row than the frame's word-aligned row), too shallow or without plane 0; the height is not checked (UnpackIFF unpacks as many rows as the bitmap has). ILBMPalette's result is not looked at, as in the original. A failed RIAnimInit leaves no animation: RIAnimFrameCount and RINextAnimFrame return 0 (fixed #512: the original kept the ANIM's address and end, and the frame pointers of the animation before). The original returns to the caller's a1 for a chunk "pointed at directly" (#513, DIFF: -1 here).

Parameters
addressd0: the ANIM file in memory
bmd1: bitmap# (its low byte is kept)
pald2: palette# (its low byte is kept)
offsetd3: the byte offset into each plane
Returns
d0: BB_TRUE, BB_FALSE if there is no ANIM with an ILBM and BMHD, the BMHD depth is 0 or above 8 (fixed #509) or its width 0 (fixed #507), UnpackIFF refuses the bitmap (fixed #1106), or a chunk of the ANIM or of a frame starts at an odd address (fixed #1119)

◆ c_InitAnim2()

BB_BOOL c_InitAnim2 ( ULONG address,
ULONG bm,
ULONG pal )

RIAnimInit address,bitmap#,palette#: c_InitAnim() with offset 0.

Parameters
addressd0: the ANIM file in memory
bmd1: bitmap#
pald2: palette#
Returns
d0: as c_InitAnim()

◆ c_InitAnim3()

BB_BOOL c_InitAnim3 ( ULONG address,
ULONG bm,
ULONG pal,
ULONG x,
ULONG y,
const struct BitMap * bitmap )

RIAnimInit address,bitmap#,palette#,x,y: c_InitAnim() at the pixel position x,y.

The offset is BytesPerRow * y (MULU.w: the low words) + x >> 3 (ASR.l); the bitmap# is d1 / 64 with DIVU.w, which overflows (no change) for numbers of 64 * 65536 and above. A position outside the bitmap is the programmer's: with runtime error checking xychk refuses it (fixed #514); an odd byte offset for an ANIM7 frame is refused by RINextAnimFrame's check, nextchk (fixed #1122).

Parameters
addressd0: the ANIM file in memory
bmd1: bitmap# * 64 (pd1)
pald2: palette#
xd3: the x position in pixels
yd4: the y position in lines
bitmapa0: the bitmap object (!bmap {0,1})
Returns
d0: as c_InitAnim()

◆ c_NextAnimFrame()

ULONG c_NextAnimFrame ( struct BitMap * bitmap)

RINextAnimFrame bitmap#: apply the DLTA of the next frame to the bitmap.

ANHD operation 5 or 65 (byte vertical delta) or 7 (short or long vertical delta by bit 0 of the ANHD bits; fixed #504: the original always took the long form) on the planes (+ the offset of RIAnimInit); a CMAP of the frame goes through ILBMPalette. Chunks of the ANIM that are no FORM are skipped (fixed #1116: the original took one between two frames as the end). At the end of the ANIM it goes on with the third frame if AnimLoop is on, else returns 0. ANIM5 has the byte columns of the word-aligned row (fixed #507), ANIM7's short form the words of the row (fixed #504), its long form the long columns of that row, none up to 16 pixels (fixed #1115: the original took width >> 5 with ASR.w, dropping the rest of the row and giving 65536 columns below 32 pixels; the last word of a row with an odd number of words is not updated). BUG(orig): a run or copy count of 0 is 256 (#508). The depth is 1 to 8 (fixed #509: RIAnimInit refuses 0 and above 8). Other chunks between ANHD (and CMAP) and the DLTA are skipped inside the frame, a CMAP among them goes through ILBMPalette; a frame without DLTA returns 0 (fixed #515: the original returned without restoring its 14 saved registers, through the saved d1). The steps over ANHD and CMAP stay inside the frame: a frame too short for its ILBM and ANHD fields, or an ANHD or CMAP whose length leaves no chunk header in the frame, returns 0 (fixed #1117: the original stepped by the length and read the next chunk anywhere). A DLTA whose plane offsets leave it returns 0 (fixed #1120; the ops inside the columns stay unchecked, BUG(orig) (#1120)), so does an ANIM7 DLTA with an odd data list offset (fixed #1121). With runtime error checking nextchk refuses an ANIM7 frame at an odd plane address (fixed #1122).

Parameters
bitmapa0: the bitmap object (!bmap {0,0})
Returns
d0: -1 if a delta was applied, else 0

◆ codeinit()

void codeinit ( void )
static

init: no animation, AnimLoop on.

Fixed (#1107): the original has no init, so a second run of a program with the library still loaded (from the editor) started with the animation of the run before: RIAnimFrameCount and RINextAnimFrame before an RIAnimInit walked it (perhaps freed memory), and an AnimLoop Off of the run before stayed off (the manual's default is on). Clears with CLR.l/ST on absolute addresses: no register changes.

◆ fcloop()

LONG fcloop ( UBYTE * p,
ULONG id,
UBYTE ** data )
static

◆ findbmhd()

LONG findbmhd ( ULONG address,
struct BitMapHeader ** data )
static

◆ findchunk()

LONG findchunk ( ULONG id,
UBYTE ** data )
static

◆ findnextchunk()

LONG findnextchunk ( ULONG id,
UBYTE ** data )
static

◆ framestep()

UBYTE * framestep ( UBYTE * p)
inlinestatic

◆ initfindchunk()

LONG initfindchunk ( UBYTE * chunk,
ULONG id )
static

◆ nextchk()

void nextchk ( void )

◆ nextchk_c()

void nextchk_c ( const struct BitMap * bitmap)
static

The error check of RINextAnimFrame (debugger only).

Fixed (#1122), not in the original: RIAnimInit adds its offset (the x,y form: BytesPerRow * y + x >> 3; the xy_offset form: the offset as given) to the plane pointers, and the ANIM7 decoders write words and longs through them: an odd address was an address error on a 68000. ANIM5 writes bytes and plays at any offset. The check finds the coming frame as RINextAnimFrame does (nextanimframe, a chunk that is no FORM skipped, at the end the third frame with AnimLoop on) and looks at the operation of its ANHD; a frame RINextAnimFrame refuses before its DLTA (no frame, too short, no ANHD) passes. The release code is unchanged (an invalid argument, D-005).

Errors: "Animation position on an odd byte for ANIM7" (the coming frame is ANIM7 and a plane pointer of the bitmap plus the offset is odd, for a plane of the animation's depth).

Parameters
bitmapa0: the bitmap object (!bmap {0,0})

◆ nextchunk()

UBYTE * nextchunk ( UBYTE * p,
UBYTE * end )
static

◆ nextform()

UBYTE * nextform ( UBYTE * chunk)
static

◆ oddchunk()

int oddchunk ( UBYTE * form)
static

◆ otherchunks()

UBYTE * otherchunks ( UBYTE * chunk)
static

◆ padded()

ULONG padded ( const UBYTE * data,
ULONG len )
inlinestatic

◆ plane5()

void plane5 ( const UBYTE * ops,
UBYTE * column,
ULONG mod )
static

◆ plane7()

void plane7 ( const UBYTE * ops,
UBYTE * column,
const ULONG * data,
ULONG mod )
inlinestatic

◆ plane7short()

void plane7short ( const UBYTE * ops,
UBYTE * column,
const UWORD * data,
ULONG mod )
inlinestatic

◆ planes7()

void planes7 ( UBYTE * body,
int kind,
ULONG mod )
static

◆ unpackanim()

int unpackanim ( UBYTE * dlta,
int kind )
static

◆ xychk()

void xychk ( void )

◆ xychk_c()

void xychk_c ( ULONG x,
ULONG y,
const struct BitMap * bitmap )
static

The error check of RIAnimInit's x,y form (debugger only).

Fixed (#514), not in the original (rianimlib had no error check area): the position becomes the byte offset BytesPerRow * y (MULU.w of the low words) + x >> 3 into every plane, without a look at the bitmap; a negative y or one of 65536 and above gave an offset of up to 65535 rows, and UnpackIFF and every RINextAnimFrame wrote there. The release code is unchanged (an invalid argument, D-005).

Errors: "Animation position outside the bitmap" (x not in 0 to the bitmap's width in pixels - 1, or y not in 0 to its rows - 1).

Parameters
xd3: the x position in pixels
yd4: the y position in lines
bitmapa0: the bitmap object (!bmap {0,1})

Variable Documentation

◆ animaddress

UBYTE * animaddress
static

◆ animdepth

UBYTE animdepth
static

◆ animend

UBYTE * animend
static

◆ animheight

UWORD animheight
static

◆ animtype

UBYTE animtype
static

◆ animtype7

ULONG animtype7
static

◆ animwidth

UWORD animwidth
static

◆ bitmapaddress

PLANEPTR* bitmapaddress
static

◆ bitmapnumber

UBYTE bitmapnumber
static

◆ bitplaneoffset

ULONG bitplaneoffset
static

◆ cmapchunk

UBYTE* cmapchunk
static

◆ columns

UWORD columns[3]
static

◆ deltacolumns

UWORD deltacolumns
static

◆ doanimloop

UBYTE doanimloop = 0xff
static

◆ endoffile

UBYTE * endoffile
static

◆ firstchunk

UBYTE* firstchunk
static

◆ firstframe

UBYTE* firstframe
static

◆ lastfoundchunk

UBYTE * lastfoundchunk
static

◆ nextanimframe

UBYTE * nextanimframe
static

◆ palettenumber

UBYTE palettenumber
static

◆ thirdframe

UBYTE* thirdframe
static