BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
collslib.c File Reference
#include "blitzlib.h"
#include "blitzobj.h"

Macros

#define BLITZONLY(chk)
#define CLXDAT   (*(volatile UWORD *)0xdff00e)
#define CLXCON   (*(volatile UWORD *)0xdff098)

Functions

void dosetcolodd (void)
void dosetcol (void)
void dosetcol2 (void)
void dosetcolhi (void)
void doshapeshit (void)
void doshsphit (void)
void dosphit (void)
void dorectshit (void)
void doscoll (void)
 SColl(Sprite Channel,Sprite Channel): whether two sprites collided.
void dopcoll (void)
 PColl(Sprite Channel): whether a sprite collided with the playfield.
void dodocoll (void)
 DoColl: latch the hardware collision bits (Blitz mode only).
void setcolchk (void)
void setcolchk2 (void)
void colbpchk (void)
void shitchk (void)
void shspchk (void)
void spspchk (void)
void scollchk (void)
void pcollchk (void)
static ULONG setclx (ULONG result, UWORD v)
BL_ALWAYS_INLINE BB_BOOL chkifhit (WORD x1, WORD y1, WORD w1, WORD h1, WORD x2, WORD y2, WORD w2, WORD h2)
static BLITZ_ENTRYPOINT BB_BOOL doshapeshit_c (ULONG x1, ULONG y1, ULONG x2, ULONG y2, const struct bb_shape *a, const struct bb_shape *b)
 ShapesHit(Shape#,X,Y,Shape#,X,Y): whether two shapes overlap.
 BLITZ_ALIAS_EP (doshapeshit, doshapeshit_c)
static BLITZ_ENTRYPOINT BB_BOOL doshsphit_c (ULONG x1, ULONG y1, ULONG x2, ULONG y2, const struct bb_shape *a, const struct bb_sprite *b)
 ShapeSpriteHit(Shape#,X,Y,Sprite#,X,Y): whether a shape and a sprite overlap.
 BLITZ_ALIAS_EP (doshsphit, doshsphit_c)
static BLITZ_ENTRYPOINT BB_BOOL dosphit_c (ULONG x1, ULONG y1, ULONG x2, ULONG y2, const struct bb_sprite *a, const struct bb_sprite *b)
 SpritesHit(Sprite#,X,Y,Sprite#,X,Y): whether two sprites overlap.
 BLITZ_ALIAS_EP (dosphit, dosphit_c)
static BLITZ_ENTRYPOINT BB_BOOL dorectshit_c (ULONG x1, ULONG y1, ULONG w1, ULONG h1, ULONG x2, ULONG y2, const UWORD *args)
 RectsHit(X1,Y1,Width1,Height1,X2,Y2,Width2,Height2): whether two rectangles overlap.
 BLITZ_ALIAS_EP (dorectshit, dorectshit_c)
static ULONG dosetcolodd_c (ULONG result)
 SetCollOdd: collisions with the odd bitplanes (CLXCON = $F041).
 BLITZ_ALIAS (dosetcolodd, dosetcolodd_c)
static ULONG setcol (ULONG colour, UWORD planes)
static ULONG dosetcol_c (ULONG col, ULONG planes)
 SetColl Colour,Bitplanes: collisions with a colour.
 BLITZ_ALIAS (dosetcol, dosetcol_c)
static UWORD spreadit (UWORD bits)
static ULONG dosetcol2_c (ULONG col, ULONG planes, ULONG pf)
 SetColl Colour,Bitplanes,Playfield: collisions with a colour of one playfield.
 BLITZ_ALIAS (dosetcol2, dosetcol2_c)
static ULONG dosetcolhi_c (ULONG planes)
 SetCollHi Bitplanes: collisions with the highest bitplane only.
 BLITZ_ALIAS (dosetcolhi, dosetcolhi_c)
static void setcolchk_c (ULONG col, ULONG planes)
static void setcolchk2_c (ULONG col, ULONG planes, ULONG pf)
static void colbpchk_c (ULONG planes)
static void shitchk_c (const struct bb_shape *a, const struct bb_shape *b)
static void shspchk_c (const struct bb_shape *a, const struct bb_sprite *b)
static void spspchk_c (const struct bb_sprite *a, const struct bb_sprite *b)
static void scollchk_c (ULONG c0, ULONG c1)
static void pcollchk_c (ULONG c)

Variables

static UWORD colval

Macro Definition Documentation

◆ BLITZONLY

#define BLITZONLY ( chk)
Value:
((char *)(chk) + 1)

◆ CLXCON

#define CLXCON   (*(volatile UWORD *)0xdff098)

◆ CLXDAT

#define CLXDAT   (*(volatile UWORD *)0xdff00e)

Function Documentation

◆ BLITZ_ALIAS() [1/4]

BLITZ_ALIAS ( dosetcol ,
dosetcol_c  )

◆ BLITZ_ALIAS() [2/4]

BLITZ_ALIAS ( dosetcol2 ,
dosetcol2_c  )

◆ BLITZ_ALIAS() [3/4]

BLITZ_ALIAS ( dosetcolhi ,
dosetcolhi_c  )

◆ BLITZ_ALIAS() [4/4]

BLITZ_ALIAS ( dosetcolodd ,
dosetcolodd_c  )

◆ BLITZ_ALIAS_EP() [1/4]

BLITZ_ALIAS_EP ( dorectshit ,
dorectshit_c  )

◆ BLITZ_ALIAS_EP() [2/4]

BLITZ_ALIAS_EP ( doshapeshit ,
doshapeshit_c  )

◆ BLITZ_ALIAS_EP() [3/4]

BLITZ_ALIAS_EP ( doshsphit ,
doshsphit_c  )

◆ BLITZ_ALIAS_EP() [4/4]

BLITZ_ALIAS_EP ( dosphit ,
dosphit_c  )

◆ chkifhit()

BL_ALWAYS_INLINE BB_BOOL chkifhit ( WORD x1,
WORD y1,
WORD w1,
WORD h1,
WORD x2,
WORD y2,
WORD w2,
WORD h2 )

◆ colbpchk()

void colbpchk ( void )

◆ colbpchk_c()

void colbpchk_c ( ULONG planes)
static

◆ dodocoll()

void dodocoll ( void )

DoColl: latch the hardware collision bits (Blitz mode only).

MOVE $DFF00E,colval: reads CLXDAT (which clears it) into colval, which SColl and PColl test. The original's code (GCC made the same of the C function), an assembler entry like SColl and PColl; it changes no register. Errors: Blitz mode only (err1 = 1).

◆ dopcoll()

void dopcoll ( void )

PColl(Sprite Channel): whether a sprite collided with the playfield.

Tests two bits of the CLXDAT value latched by DoColl, pair + 1 and pair + 5 (mod 32, BTST on a register). Blitz mode only. A word function: the upper word of d0 is the caller's. Errors (debugger only): "Illegal Sprite channel" (>= 8). The original tests both bits into d0 and d1 (SNE d0, SNE d1, AND d1,d0, EXT d0) with colval in d2; here the second test is made only when the first bit is set, with colval in d1: the same d0 (EXT uses only the low byte of the AND, so the high bytes of the bit numbers do not matter), and only d0 and d1 change. Assembler: as a C function PColl cost 120 cycles more.

In: d0.w the sprite channel (0..7) Out: d0.w -1 = both bits set, 0 otherwise

◆ dorectshit()

void dorectshit ( void )

◆ dorectshit_c()

BLITZ_ENTRYPOINT BB_BOOL dorectshit_c ( ULONG x1,
ULONG y1,
ULONG w1,
ULONG h1,
ULONG x2,
ULONG y2,
const UWORD * args )
static

RectsHit(X1,Y1,Width1,Height1,X2,Y2,Width2,Height2): whether two rectangles overlap.

Hit when the rectangles overlap (chkifhit, signed word compares).

Parameters
x1d0.w: x of the first rectangle
y1d1.w: y of the first rectangle
w1d2.w: its width
h1d3.w: its height
x2d4.w: x of the second rectangle
y2d5.w: y of the second rectangle
argsa2: the argument stack with Width2 and Height2 (words)
Returns
d0: BB_TRUE if the rectangles overlap, else BB_FALSE

◆ doscoll()

void doscoll ( void )

SColl(Sprite Channel,Sprite Channel): whether two sprites collided.

Tests the bit of the pair in the CLXDAT value latched by DoColl (bits 9-14 = sprite pairs) - with BTST Dn,<memory>: a bit of the HIGH byte of the latched word, bit number mod 8. Blitz mode only. A word function: the upper word of d0 is the caller's. Changes d0.w and d1, as the original. Errors (debugger only): "Illegal Sprite channel" (>= 8), "Sprite channels must be different", "Sprite channels must be of different pairs" (the last fixed #110, the original has no such check). Fixed (#110): the original's bit number was right only with the lower channel first (SColl(2,0): bit 10 instead of 9, SColl(4,0): 11 instead of 10, SColl(6,0): 12 instead of 11). With the pairs p0 = d0/2 and p1 = d1/2 the original tests bit p1 of the high byte (CLXDAT bit 8 + p1) for p0 = 0 and p0 + 1 + p1 otherwise; the bit of two different pairs is p0 + p1 + 1 when neither is pair 0, else p0 + p1, so the original is wrong only for p0 != 0 and p1 = 0. The routine is the original's code with ADDQ #1,d0 : ADD d0,d1 replaced by NEG d1 : NEG d1 : ADDX d0,d1, which adds p0 and the X flag of the second NEG (set for p1 != 0) to p1: the same cycles (12 against 8, but BEQ.s instead of the original's BEQ.w saves 4 when it falls through), and BTST reads colval PC-relative instead of absolute (4 cycles less on both paths). Every other input, also the invalid ones (same pair, channel >= 8, the upper word of d1), tests the original's bit. Assembler in the argument registers: as a C function SColl cost a thunk, a register save and copies (about 250 cycles more per call). Cycles (68000, without the call): p0 = 0 62/64 (the original 66/68), p0 != 0 72/74 (76/78), no collision/collision.

In: d0.w the first sprite channel (0..7), d1.w the second Out: d0.w -1 = collision, 0 = none

◆ dosetcol()

void dosetcol ( void )

◆ dosetcol2()

void dosetcol2 ( void )

◆ dosetcol2_c()

ULONG dosetcol2_c ( ULONG col,
ULONG planes,
ULONG pf )
static

SetColl Colour,Bitplanes,Playfield: collisions with a colour of one playfield.

The colour bits are spread to the odd planes (spreadit), playfield 2 (anything but 1) one bit up; then as SetColl Colour,Bitplanes. Errors (debugger only): "PlayField must be 1 or 2", then those of SetColl. By design (#111): 0 planes loop 65536 times (DBF); setcolchk refuses them.

Parameters
cold0.w: the colour
planesd1.w: the number of bitplanes
pfd2.w: the playfield, 1 = front, 2 = back
Returns
d0.w: CLXDAT (a statement: the value is not used)

◆ dosetcol_c()

ULONG dosetcol_c ( ULONG col,
ULONG planes )
static

SetColl Colour,Bitplanes: collisions with a colour.

CLXCON = $F000 | enable bits for the planes | colour. Errors (debugger only): "Illegal number of BitPlanes" (not 1..6), "Illegal Colour for Collision" (>= 2^planes). By design (#111): 0 planes loop 65536 times (DBF); setcolchk refuses them.

Parameters
cold0.w: the colour
planesd1.w: the number of bitplanes
Returns
d0.w: CLXDAT (a statement: the value is not used); the upper word is the colour's

◆ dosetcolhi()

void dosetcolhi ( void )

◆ dosetcolhi_c()

ULONG dosetcolhi_c ( ULONG planes)
static

SetCollHi Bitplanes: collisions with the highest bitplane only.

CLXCON = $F000 | the enable and match bit of plane planes. Errors (debugger only): "Illegal number of BitPlanes" (not 1..6).

Parameters
planesd0.w: the number of bitplanes
Returns
d0.w: CLXDAT (a statement: the value is not used)

◆ dosetcolodd()

void dosetcolodd ( void )

◆ dosetcolodd_c()

ULONG dosetcolodd_c ( ULONG result)
static

SetCollOdd: collisions with the odd bitplanes (CLXCON = $F041).

Parameters
resultd0: the caller's register (its upper word stays)
Returns
d0.w: CLXDAT (a statement: the value is not used)

◆ doshapeshit()

void doshapeshit ( void )

◆ doshapeshit_c()

BLITZ_ENTRYPOINT BB_BOOL doshapeshit_c ( ULONG x1,
ULONG y1,
ULONG x2,
ULONG y2,
const struct bb_shape * a,
const struct bb_shape * b )
static

ShapesHit(Shape#,X,Y,Shape#,X,Y): whether two shapes overlap.

Rectangle test (chkifhit): the position minus the shape's handle (+10/+12), the size width/height (+0/+2); signed word compares. Errors (debugger only): "Uninitialized Shape".

Parameters
x1d1.w: x of the first shape
y1d2.w: y of the first shape
x2d4.w: x of the second shape
y2d5.w: y of the second shape
aa0: the first shape object (from Shape# in d0)
ba1: the second shape object (from Shape# in d3)
Returns
d0: BB_TRUE if the rectangles overlap, else BB_FALSE

◆ doshsphit()

void doshsphit ( void )

◆ doshsphit_c()

BLITZ_ENTRYPOINT BB_BOOL doshsphit_c ( ULONG x1,
ULONG y1,
ULONG x2,
ULONG y2,
const struct bb_shape * a,
const struct bb_sprite * b )
static

ShapeSpriteHit(Shape#,X,Y,Sprite#,X,Y): whether a shape and a sprite overlap.

Rectangle test (chkifhit) as ShapesHit; the sprite: position minus its handle (+12/+14), width the low byte of +8, height +4 - 1. Errors (debugger only): "Uninitialized Shape", "Uninitialized Sprite".

Parameters
x1d1.w: x of the shape
y1d2.w: y of the shape
x2d4.w: x of the sprite
y2d5.w: y of the sprite
aa0: the shape object (from Shape# in d0)
ba1: the sprite object (from Sprite# in d3)
Returns
d0: BB_TRUE if the rectangles overlap, else BB_FALSE

◆ dosphit()

void dosphit ( void )

◆ dosphit_c()

BLITZ_ENTRYPOINT BB_BOOL dosphit_c ( ULONG x1,
ULONG y1,
ULONG x2,
ULONG y2,
const struct bb_sprite * a,
const struct bb_sprite * b )
static

SpritesHit(Sprite#,X,Y,Sprite#,X,Y): whether two sprites overlap.

Rectangle test (chkifhit) with the sprites' handles and pixel sizes (see ShapeSpriteHit). Errors (debugger only): "Uninitialized Sprite".

Parameters
x1d1.w: x of the first sprite
y1d2.w: y of the first sprite
x2d4.w: x of the second sprite
y2d5.w: y of the second sprite
aa0: the first sprite object (from Sprite# in d0)
ba1: the second sprite object (from Sprite# in d3)
Returns
d0: BB_TRUE if the rectangles overlap, else BB_FALSE

◆ pcollchk()

void pcollchk ( void )

◆ pcollchk_c()

void pcollchk_c ( ULONG c)
static

◆ scollchk()

void scollchk ( void )

◆ scollchk_c()

void scollchk_c ( ULONG c0,
ULONG c1 )
static

◆ setclx()

ULONG setclx ( ULONG result,
UWORD v )
static

◆ setcol()

ULONG setcol ( ULONG colour,
UWORD planes )
static

◆ setcolchk()

void setcolchk ( void )

◆ setcolchk2()

void setcolchk2 ( void )

◆ setcolchk2_c()

void setcolchk2_c ( ULONG col,
ULONG planes,
ULONG pf )
static

◆ setcolchk_c()

void setcolchk_c ( ULONG col,
ULONG planes )
static

◆ shitchk()

void shitchk ( void )

◆ shitchk_c()

void shitchk_c ( const struct bb_shape * a,
const struct bb_shape * b )
static

◆ shspchk()

void shspchk ( void )

◆ shspchk_c()

void shspchk_c ( const struct bb_shape * a,
const struct bb_sprite * b )
static

◆ spreadit()

UWORD spreadit ( UWORD bits)
static

◆ spspchk()

void spspchk ( void )

◆ spspchk_c()

void spspchk_c ( const struct bb_sprite * a,
const struct bb_sprite * b )
static

Variable Documentation

◆ colval

UWORD colval
static