risnowlib
This library lets snow fall through a bitmap. The flakes are pixels in
the first bitplane of the bitmap; the second bitplane holds the snow
that has come to rest, and the third holds “blue” pixels, which the
program can remove with KillPoint so that the snow resting on them
falls on. The bitmap therefore needs at least 3 bitplanes, and the
library takes every row as 40 bytes long: it works on bitmaps 320
pixels wide only.
A snow field is set up with InitSnowDrop, which allocates its lists.
There are 4 snow fields, numbered 0 to 3; with runtime error checking,
another number is a runtime error. Each
LDoSnow moves every flake of a field one step: one row down if the
pixel there is free, else to a free side, and if it cannot move and
rests on settled snow, it settles too. Each step also adds one new
flake, from a table of random positions that the program provides.
The random table is memory the program fills:
| Offset | Size | Contents |
|---|---|---|
| 0 | word | the index of the next position, which the library steps on by 2 (after 1022 it wraps to 0) |
| 2 | 512 pairs of bytes | the positions |
The first byte of a pair is the byte offset in the bitplane, so new flakes start in the first rows of the bitmap; the second is the bit in that byte, 0 to 7, 7 being the leftmost pixel.
A field has room for numpoints times 4 flakes, less one; when its lists are
full, no more flakes are added. Kept from the original: LDoSnow
flashes the background colour (colour 0 of the hardware) red while it
runs and leaves it black. LDoSnow is as fast as the original’s.
Library number 195.
Commands
InitSnowDrop
Sets up snow field listnum, 0 to 3, on a bitmap, with lists for numpoints times 4 flakes, all empty. bp_size is the size of a bitplane in bytes; flakes are removed at its end. Returns the address of the library’s table of lists.
Statement or function, result .l. Help text: listnum,numpoints,bitmap,bp_size
Arguments: .l, .l, .w, .l
Setting up a field again frees its old lists. With runtime error
checking, a listnum outside 0 to 3 is a runtime error; without it,
the number is not checked.
KillPoint
Removes a blue pixel, set in the third bitplane, at x,y, clearing it in the first three bitplanes, so that LDoSnowActivate lets the snow above it fall. Returns -1, or 0 if there is no blue pixel at x,y or the field’s list of removed pixels is full.
Statement or function, result .l. Help text: listnum,x,y
Arguments: .l, .w, .w
With runtime error checking, a pixel outside the 320 pixels of a row or the rows of the bitmap is a runtime error.
LDoSnow
Moves every flake of snow field listnum one step and adds one new flake from the random table at randomtable.
Statement. Help text: listnum,randomtable
Arguments: .l, .l
A flake falls one row if the pixel below is clear; otherwise it moves
to the side, left or right first in turns, where that pixel and the
one below it are clear. A flake that cannot move and has settled snow
below it settles: it is set in the second bitplane and leaves the
list. A flake that reaches bp_size is removed.
A full list takes no new flake. The bit of a new flake is taken from the random table modulo 8.
Kept from the original: the command sets the hardware background colour to red while it runs and to black at its end.
LDoSnowActivate
Lets settled snow next to the removed pixels of snow field listnum fall again, and moves each removed pixel where snow fell one row up for the next call. Returns the number of removed pixels looked at plus 1.
Statement or function, result .l. Help text: listnum
Arguments: .l
When the field’s list of falling snow is full, settled snow stays where it is.