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

Data Structures

struct  droplist
struct  killlist
struct  snowfield
struct  randomtable
struct  side

Macros

#define END   0xabcd /* the end of a list */
#define ASLW(d, n)
#define FULL(entries, size)
#define DROP(a)
#define KILL(a)
#define PLANE(bm, n)

Functions

void _AsmDoSnow (void)
 LDoSnow listnum,randomtable: one step of the snow.
void _InitSnowDrop (void)
void _KillPoint (void)
void _DoKillList (void)
void risnowlib_libinit (void)
void risnowlib_libfinit (void)
void initchk (void)
void fieldchk (void)
void killchk (void)
static struct snowfield * entry (ULONG n)
static int btst (const UBYTE *p, UWORD idx, UWORD bit)
static void bclr (UBYTE *p, UWORD idx, UWORD bit)
static void bset (UBYTE *p, UWORD idx, UWORD bit)
static void libinit_c (void)
 init: clears the list table, as at the first load.
static void nothing_c (void)
 finit: RTS (nothing to do).
static UBYTE * drophead (UBYTE *p, ULONG size, ULONG bm, ULONG bpsize)
static UBYTE * killhead (UBYTE *p, ULONG size)
static ULONG initsnowdrop_c (ULONG n, ULONG num, ULONG bpsize, ULONG bm)
 InitSnowDrop(listnum,numpoints,bitmap,bp_size): the four lists of a snow field.
static int unpause (UBYTE *plane1, const UBYTE *plane2, UWORD at, UWORD bit, UWORD **drop, const UWORD *full)
static ULONG dokilllist_c (ULONG n)
 LDoSnowActivate(listnum): stopped snow next to removed pixels falls again.
static BB_BOOL killpoint_c (ULONG n, ULONG x, ULONG y)
 KillPoint(listnum,x,y): removes a "blue" pixel (plane 2).
static void listchk (ULONG n)
static void initdonechk (ULONG n)
static void initchk_c (ULONG n)
 The error check of InitSnowDrop (debugger only).
static void fieldchk_c (ULONG n)
 The error check of LDoSnow and LDoSnowActivate (debugger only).
static void killchk_c (ULONG n, ULONG x, ULONG y)
 The error check of KillPoint (debugger only).

Variables

static struct snowfield lp [4]
static const struct side lookup [2][8][2]

Macro Definition Documentation

◆ ASLW

#define ASLW ( d,
n )
Value:
(((ULONG)(d) & 0xffff0000UL) | (UWORD)((ULONG)(d) << (n)))
ULONG WORD UWORD UWORD border ULONG ULONG struct bb_bitmap *dst void UWORD n
Definition 2dlib.c:2498
static struct @065163037313156332013005143365272036211065172003 d

◆ DROP

#define DROP ( a)
Value:
((struct droplist *)(a))
Definition risnowlib.c:147

◆ END

#define END   0xabcd /* the end of a list */

◆ FULL

#define FULL ( entries,
size )
Value:
((UWORD *)((UBYTE *)(entries) + (size) - 6))
UWORD size
Definition 2dlib.c:1170

◆ KILL

#define KILL ( a)
Value:
((struct killlist *)(a))
Definition risnowlib.c:157

◆ PLANE

#define PLANE ( bm,
n )
Value:
((UBYTE *)*(ULONG *)&((const struct BitMap *)(bm))->Planes[n])
struct BitMap bm
Definition iffmakelib.c:162

Function Documentation

◆ _AsmDoSnow()

void _AsmDoSnow ( void )

LDoSnow listnum,randomtable: one step of the snow.

Reads the newer drop list and writes the other (they swap): a flake moves one row down if the pixel there is clear, else to the side (left or right first, alternating) where the pixel and the one below are clear, else it stays; one that cannot move with plane 1 set below it stops (set in plane 1, dropped). A flake below bp_size (compared as a signed word) is removed. Then a new flake from the random table (the index steps by 2 modulo 1024). COLOR00 is red while it runs ($F00, then 0: a debug flash).

An assembler entry, the original's loop (registers as there: a1 plane 0, a4 plane 1, a0 the list read, a2 the list written, a5 the random table, d7 bp_size, d6 left or right first, a3 the side table): as C (even with the bit operations as inline assembler) it took 4.2 and 1.7 times the original's cycles per call (perf bsnow). Keeps d1/a0/a1 and a4-a6 (the original a4-a6, the C thunk d1/a0/a1); changes d0, d2-d7, a2, a3.

The list number: fieldchk (fixed #913). Fixed (#914): no new flake when the list written is full (a6: its FULL place; the original had no bound). Fixed (#910): the bit of a new flake is taken modulo 8 (a bit above 7 read behind the side tables).

  • d0 the list number
  • d1 the random table (index.w, then pairs offset.b, bit.b)

◆ _DoKillList()

void _DoKillList ( void )

◆ _InitSnowDrop()

void _InitSnowDrop ( void )

◆ _KillPoint()

void _KillPoint ( void )

◆ bclr()

void bclr ( UBYTE * p,
UWORD idx,
UWORD bit )
inlinestatic

◆ bset()

void bset ( UBYTE * p,
UWORD idx,
UWORD bit )
inlinestatic

◆ btst()

int btst ( const UBYTE * p,
UWORD idx,
UWORD bit )
inlinestatic

◆ dokilllist_c()

ULONG dokilllist_c ( ULONG n)
static

LDoSnowActivate(listnum): stopped snow next to removed pixels falls again.

For each pixel of the kill list (the two kill lists swap): stopped snow (plane 1 set, plane 2 clear) at the two sides below and at the pixel is cleared in plane 1 and added to the newer drop list; the pixel above goes into the other kill list. Checking plane 2 at the killed pixel again is redundant (no defect). The bits of the entries are 0-7 (fixed #910: LDoSnow masks the random table's). The list number: fieldchk (fixed #913). Fixed (#909): the drop list's last is updated (the original's stayed, so the next call overwrote the entries). Fixed (#914): stopped snow stays when the drop list is full (the original had no bound). Fixed (#908): before the first LDoSnow the drop list's last is its first entry (InitSnowDrop sets it; the original's 0 wrote at address 0).

Parameters
nd0: the list number
Returns
d0: the number of kill list entries + 1

◆ drophead()

UBYTE * drophead ( UBYTE * p,
ULONG size,
ULONG bm,
ULONG bpsize )
static

◆ entry()

struct snowfield * entry ( ULONG n)
static

◆ fieldchk()

void fieldchk ( void )

◆ fieldchk_c()

void fieldchk_c ( ULONG n)
static

The error check of LDoSnow and LDoSnowActivate (debugger only).

Fixed (#913), not in the original: the list number was not checked (lists and bitmap read behind the table); with it a list number without InitSnowDrop, whose entry is 0 (the lists and the bitmap read at address 0). The release code is unchanged (D-005).

Errors: "Snow list number must be 0 to 3", "Snow list needs InitSnowDrop".

Parameters
nd0: the list number

◆ initchk()

void initchk ( void )

◆ initchk_c()

void initchk_c ( ULONG n)
static

The error check of InitSnowDrop (debugger only).

Fixed (#913), not in the original (risnowlib had no error check area): the list number indexes the table of 4 numbers with ASL.w #4 without a check, so 4 and up (and negative numbers, a non-zero upper word) wrote the four list pointers behind or before the table. The release code is unchanged (an invalid argument, D-005).

Errors: "Snow list number must be 0 to 3".

Parameters
nd0: the list number

◆ initdonechk()

void initdonechk ( ULONG n)
static

◆ initsnowdrop_c()

ULONG initsnowdrop_c ( ULONG n,
ULONG num,
ULONG bpsize,
ULONG bm )
static

InitSnowDrop(listnum,numpoints,bitmap,bp_size): the four lists of a snow field.

One block (memlib globalloc, MEMF_CLEAR; not checked: memlib raises Out of Memory) for drop lists A and B and kill lists 1 and 2, each numpoints*16 bytes, all empty. Fixed (#911): the block the number had is freed first (memlib globfree; the original lost it). Fixed (#912): the size is a long (the original's ASL.w #2 made the block too small from numpoints 1024 on). Fixed (#908): the drop lists' last is set (the original left it 0).

Parameters
nd0: the list number (0-3)
numd1: the number of points
bpsized3: the end offset in the plane (bp_size)
bma3: the bitmap object (!libs bitmaplib,ia3|pd2)
Returns
d0: the address of the list table (listpointers)

◆ killchk()

void killchk ( void )

◆ killchk_c()

void killchk_c ( ULONG n,
ULONG x,
ULONG y )
static

The error check of KillPoint (debugger only).

Fixed (#913), not in the original: as fieldchk_c, and the pixel: x outside the 320 pixels of a row (the library assumes 40 bytes per row) or y outside the rows of the field's bitmap cleared bits and appended kill entries outside the planes. The release code is unchanged (D-005).

Errors: "Snow list number must be 0 to 3", "Snow list needs InitSnowDrop", "KillPoint outside the bitmap".

Parameters
nd0: the list number
xd1: x (a word)
yd2: y (a word)

◆ killhead()

UBYTE * killhead ( UBYTE * p,
ULONG size )
static

◆ killpoint_c()

BB_BOOL killpoint_c ( ULONG n,
ULONG x,
ULONG y )
static

KillPoint(listnum,x,y): removes a "blue" pixel (plane 2).

The pixel is cleared in all three planes and the pixel above it added to the kill list. The list number and the pixel: killchk (fixed #913).

Parameters
nd0: the list number
xd1: x (a word)
yd2: y (a word; 40 bytes per row)
Returns
d0: BB_TRUE, BB_FALSE if the pixel was clear in plane 2 or the kill list is full (then nothing is done: fixed #914)

◆ libinit_c()

void libinit_c ( void )
static

init: clears the list table, as at the first load.

Fixed (#1135): the original's init was an RTS; in a second run of a program from the editor (the library stays loaded, memlib has freed the blocks) the table still pointed to the first run's lists.

◆ listchk()

void listchk ( ULONG n)
static

◆ nothing_c()

void nothing_c ( void )
static

finit: RTS (nothing to do).

◆ risnowlib_libfinit()

void risnowlib_libfinit ( void )

◆ risnowlib_libinit()

void risnowlib_libinit ( void )

◆ unpause()

int unpause ( UBYTE * plane1,
const UBYTE * plane2,
UWORD at,
UWORD bit,
UWORD ** drop,
const UWORD * full )
static

Variable Documentation

◆ lookup

const struct side lookup[2][8][2]
static
Initial value:
= {
{ { { 0, 1 }, { 1, 7 } }, { { 0, 2 }, { 0, 0 } }, { { 0, 3 }, { 0, 1 } },
{ { 0, 4 }, { 0, 2 } }, { { 0, 5 }, { 0, 3 } }, { { 0, 6 }, { 0, 4 } },
{ { 0, 7 }, { 0, 5 } }, { { -1, 0 }, { 0, 6 } } },
{ { { 1, 7 }, { 0, 1 } }, { { 0, 0 }, { 0, 2 } }, { { 0, 1 }, { 0, 3 } },
{ { 0, 2 }, { 0, 4 } }, { { 0, 3 }, { 0, 5 } }, { { 0, 4 }, { 0, 6 } },
{ { 0, 5 }, { 0, 7 } }, { { 0, 6 }, { -1, 0 } } },
}

◆ lp

struct snowfield lp[4]
static