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

Data Structures

struct  cfx
struct  colsplit
struct  grad

Macros

#define DMACON   0x096
#define BPLCON3   0x106
#define COLOR00   0x180
#define BPLSPR_DMAOFF   (((ULONG)DMACON << 16) + 0x120)
#define AGAHIGHNIBBLE   (((ULONG)BPLCON3 << 16) + 0xc00)
#define AGALOWNIBBLE   (((ULONG)BPLCON3 << 16) + 0xe00)
#define ROLFACTOR   14
#define CALCFACTOR   (1 << ROLFACTOR)

Functions

void ricopperfxlib_libinit (void)
void ricopperfxlib_libfinit (void)
void ricopperfxlib_docolsplit (void)
void redocolsplit (void)
void splitreset2 (void)
void splitreset (void)
void EndSplit (void)
void InfoBlock (void)
void CustomCommand (void)
void CustomMove (void)
void CustomWait (void)
void CustomSkip (void)
void getccoffset (void)
void CustomAGACol (void)
void splitresethard (void)
void splitbplcon3 (void)
void colsplitchk (void)
static UWORD * getcustom (void)
static UWORD bank (UBYTE reg)
static UWORD colourreg (UBYTE reg)
static UWORD highnibbles (UWORD r, UWORD g, UWORD b)
static UWORD lownibbles (UWORD r, UWORD g, UWORD b)
static void gradient (struct grad *g, const struct colsplit *cols, UWORD numlines)
ULONG c_docolsplit (const struct colsplit *cols, UWORD numlines, UBYTE reg)
 DoColSplit cols_adr,numlines,colour_register: a 24 bit colour gradient over numlines lines.
void c_redocolsplit (const struct colsplit *cols, UWORD numlines, ULONG ccoffset)
 RedoColSplit cols_adr,numlines,ccoffset: new colours for a split made by DoColSplit.
void c_splitreset (UWORD startline, UWORD ccoffset, struct bb_coplist *coplist)
 CopperReset coplist#,startline,ccoffset: use the custom copper space of a coplist.
void c_splitreset2 (UWORD startline, struct bb_coplist *coplist)
 CopperReset coplist#,startline: c_splitreset() with ccoffset 0.
void c_splitresethard (UBYTE *custom, UWORD startline)
 CopperResetAdr address,startline: use a custom copper space at an address.
ULONG c_getccoffset (void)
 GetCCOffset: the current offset in the custom space, in instructions.
void c_splitbplcon3 (UBYTE lo)
 ColSplitBplcon3 bplcon3: the low byte of BPLCON3 for the next DoColSplit.
void c_CustomCommand (UWORD ins1, UWORD ins2)
 CopperCommand copins1,copins2: write one copper instruction (two words).
void c_CustomMove (UWORD reg, UWORD value)
 CopperMove register,value: a MOVE instruction (bit 0 of the register cleared).
void c_CustomWait (UWORD x, UWORD y)
 CopperWait x,y: a WAIT instruction for the position x,y.
void c_CustomSkip (UWORD x, UWORD y)
 CopperSkip x,y: a SKIP instruction for the position x,y.
void c_EndSplit (void)
 CopperEnd: end the custom part: WAIT line $2c, DMA off, BPLCON3 bank 0, COLOR00 = 0.
ULONG c_CustomAGACol (ULONG col, UWORD r, UWORD g, UWORD b)
 CopperAGACol col#,r,g,b: set one 24 bit colour (4 instructions).
ULONG c_InfoBlock (void)
 CopperInfoBlock: the address of the state block (struct cfx, the original's layout).
static void c_libinit (void)
 init: no custom space, the state block cleared.
static void c_libfinit (void)
 finit: nothing (_libfinit is an RTS).
static void colsplitchk_c (ULONG numlines)
 The error check of DoColSplit and RedoColSplit (debugger only).

Variables

static struct cfx cfx

Macro Definition Documentation

◆ AGAHIGHNIBBLE

#define AGAHIGHNIBBLE   (((ULONG)BPLCON3 << 16) + 0xc00)

◆ AGALOWNIBBLE

#define AGALOWNIBBLE   (((ULONG)BPLCON3 << 16) + 0xe00)

◆ BPLCON3

#define BPLCON3   0x106

◆ BPLSPR_DMAOFF

#define BPLSPR_DMAOFF   (((ULONG)DMACON << 16) + 0x120)

◆ CALCFACTOR

#define CALCFACTOR   (1 << ROLFACTOR)

◆ COLOR00

#define COLOR00   0x180

◆ DMACON

#define DMACON   0x096

◆ ROLFACTOR

#define ROLFACTOR   14

Function Documentation

◆ bank()

UWORD bank ( UBYTE reg)
static

◆ c_CustomAGACol()

ULONG c_CustomAGACol ( ULONG col,
UWORD r,
UWORD g,
UWORD b )

CopperAGACol col#,r,g,b: set one 24 bit colour (4 instructions).

BPLCON3 with the high nibbles of the colour's bank, the register, BPLCON3 with the low nibbles, the register.

Parameters
cold0: the colour register (0-255)
rd1: red (8 bit)
gd2: green
bd3: blue
Returns
d0: -1 when the colour was written, 0 without a custom space (fixed #590: the original returned the col# argument, 1234 without a custom space)

◆ c_CustomCommand()

void c_CustomCommand ( UWORD ins1,
UWORD ins2 )

CopperCommand copins1,copins2: write one copper instruction (two words).

Also the end of CopperMove/Wait/Skip. Nothing without a custom space.

Parameters
ins1d0: the first word
ins2d1: the second word

◆ c_CustomMove()

void c_CustomMove ( UWORD reg,
UWORD value )

CopperMove register,value: a MOVE instruction (bit 0 of the register cleared).

Parameters
regd0: the custom chip register offset
valued1: the value

◆ c_CustomSkip()

void c_CustomSkip ( UWORD x,
UWORD y )

CopperSkip x,y: a SKIP instruction for the position x,y.

Parameters
xd0: the x position (bit 0 cleared)
yd1: the line

◆ c_CustomWait()

void c_CustomWait ( UWORD x,
UWORD y )

CopperWait x,y: a WAIT instruction for the position x,y.

The x position is ((x >> 1) & $FE) + 6, masked with $FE again: fixed (#591), the original adds the 6 as a word after the mask, so for x >= 500 it carried into the line bits (line y | 1, x 0-4); now the horizontal position wraps within its byte and the line stays y.

Parameters
xd0: the x position
yd1: the line

◆ c_docolsplit()

ULONG c_docolsplit ( const struct colsplit * cols,
UWORD numlines,
UBYTE reg )

DoColSplit cols_adr,numlines,colour_register: a 24 bit colour gradient over numlines lines.

Writes into the custom space from ccoffset on, per line: a WAIT for the line (startline, counted up), BPLCON3 (high nibbles), the colour register, BPLCON3 (low nibbles), the colour register; the bank of the register selects bits 13-15 of BPLCON3 (| ColSplitBplcon3's low byte). The colours run linearly from the start to the end r, g, b. Without a custom space only bplcon3LO/HI and colreg are set. numlines below 1 is the programmer's: with runtime error checking colsplitchk refuses it (fixed #589); without it 0 divides by zero (the exception as in the original) and a negative value runs up to 65536 lines (the DBRA counter as a word). The step (1 << 14) / numlines is a word quotient. The $FFE1FFFE wait (line 256) comes before a line whose low byte is 0 but not before line 0: fixed (#588), the original tested the low byte alone, so a split from line 0 waited for line 256 first.

Parameters
colsd0: the colours (cols_adr)
numlinesd1: the number of lines
regd2: the colour register (0-255)
Returns
d0: -1 when the split was written, 0 without a custom space (fixed #592: the original left the red step value, or cols_adr without a custom space)

◆ c_EndSplit()

void c_EndSplit ( void )

CopperEnd: end the custom part: WAIT line $2c, DMA off, BPLCON3 bank 0, COLOR00 = 0.

Four instructions; nothing without a custom space.

◆ c_getccoffset()

ULONG c_getccoffset ( void )

GetCCOffset: the current offset in the custom space, in instructions.

ASR.w on a d0 cleared by MOVEQ: the upper word is 0. Fixed (#593): tests customaddr as every other command; the original tests coplistaddr, so after CopperResetAdr it returned -1 although the commands worked.

Returns
d0: ccoffset / 4, -1 without a custom space

◆ c_InfoBlock()

ULONG c_InfoBlock ( void )

CopperInfoBlock: the address of the state block (struct cfx, the original's layout).

Returns
d0: &cfx

◆ c_libfinit()

void c_libfinit ( void )
static

finit: nothing (_libfinit is an RTS).

◆ c_libinit()

void c_libinit ( void )
static

init: no custom space, the state block cleared.

Fixed (#1126): the original's init is an RTS, so a second run of a program with the library still loaded (from the editor) started with the state of the run before: a command before CopperReset wrote into the custom space of the run before (perhaps a freed coplist), and its ColSplitBplcon3 byte stayed in effect. The whole block is cleared, as at the first load (Dc.l 0/Dc.w 0); stores to absolute addresses, no register changes.

◆ c_redocolsplit()

void c_redocolsplit ( const struct colsplit * cols,
UWORD numlines,
ULONG ccoffset )

RedoColSplit cols_adr,numlines,ccoffset: new colours for a split made by DoColSplit.

Starts at instruction ccoffset of the custom space, skips a line 256 WAIT, writes only the two colour values per line. Nothing without a custom space. The byte offset is ccoffset * 4 as a long: fixed (#594), the original's ASL.w #2 shifted only the low word and added the upper word unchanged. numlines as in DoColSplit (colsplitchk, fixed #589).

Parameters
colsd0: the colours (cols_adr)
numlinesd1: the number of lines
ccoffsetd2: the split's offset in instructions (4 bytes)

◆ c_splitbplcon3()

void c_splitbplcon3 ( UBYTE lo)

ColSplitBplcon3 bplcon3: the low byte of BPLCON3 for the next DoColSplit.

Parameters
lod0: the low byte

◆ c_splitreset()

void c_splitreset ( UWORD startline,
UWORD ccoffset,
struct bb_coplist * coplist )

CopperReset coplist#,startline,ccoffset: use the custom copper space of a coplist.

customaddr = the coplist's custom space (+28), 0 = none: then every command does nothing.

Parameters
startlined1: the line of the next colour split
ccoffsetd2: the offset of the next instruction, in instructions
coplista0: the coplist object (!libs displaylib,ia0|pd0)

◆ c_splitreset2()

void c_splitreset2 ( UWORD startline,
struct bb_coplist * coplist )

CopperReset coplist#,startline: c_splitreset() with ccoffset 0.

Parameters
startlined1: the line of the next colour split
coplista0: the coplist object

◆ c_splitresethard()

void c_splitresethard ( UBYTE * custom,
UWORD startline )

CopperResetAdr address,startline: use a custom copper space at an address.

coplistaddr becomes 0, ccoffset 0.

Parameters
customd0: the address of the custom space
startlined1: the line of the next colour split

◆ colourreg()

UWORD colourreg ( UBYTE reg)
static

◆ colsplitchk()

void colsplitchk ( void )

◆ colsplitchk_c()

void colsplitchk_c ( ULONG numlines)
static

The error check of DoColSplit and RedoColSplit (debugger only).

Fixed (#589), not in the original (ricopperfxlib had no error check area): both compute the colour step with DIVS by numlines and loop with DBRA on numlines - 1 as a word, without a look at numlines: 0 raised the divide-by-zero exception, a negative value wrote (DoColSplit) or rewrote (RedoColSplit) up to 65536 lines of 20 bytes behind the custom space. The release code is unchanged (an invalid argument, D-005).

Errors: "Colour split needs at least one line" (numlines, a word, below 1).

Parameters
numlinesd1: the number of lines (a word; the upper word is the caller's)

◆ CustomAGACol()

void CustomAGACol ( void )

◆ CustomCommand()

void CustomCommand ( void )

◆ CustomMove()

void CustomMove ( void )

◆ CustomSkip()

void CustomSkip ( void )

◆ CustomWait()

void CustomWait ( void )

◆ EndSplit()

void EndSplit ( void )

◆ getccoffset()

void getccoffset ( void )

◆ getcustom()

UWORD * getcustom ( void )
static

◆ gradient()

void gradient ( struct grad * g,
const struct colsplit * cols,
UWORD numlines )
static

◆ highnibbles()

UWORD highnibbles ( UWORD r,
UWORD g,
UWORD b )
static

◆ InfoBlock()

void InfoBlock ( void )

◆ lownibbles()

UWORD lownibbles ( UWORD r,
UWORD g,
UWORD b )
static

◆ redocolsplit()

void redocolsplit ( void )

◆ ricopperfxlib_docolsplit()

void ricopperfxlib_docolsplit ( void )

◆ ricopperfxlib_libfinit()

void ricopperfxlib_libfinit ( void )

◆ ricopperfxlib_libinit()

void ricopperfxlib_libinit ( void )

◆ splitbplcon3()

void splitbplcon3 ( void )

◆ splitreset()

void splitreset ( void )

◆ splitreset2()

void splitreset2 ( void )

◆ splitresethard()

void splitresethard ( void )

Variable Documentation

◆ cfx

struct cfx cfx
static