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

Macros

#define GENRND

Functions

void doval (void)
void doint (void)
 Int(Expression) - the integer part as a long.
void dosgn (void)
 Sgn(Expression) - the sign: -1, 0 or 1.
void doffrac (void)
 Frac(Expression) - the fractional part, as a float.
void doqfrac (void)
 QFrac(Quick) - the fraction of |q| (inline).
void doqwrap (void)
 QWrap(Quick,Low,High) - wrap q into low..high (inline).
void dornd1 (void)
 Rnd - a random fraction.
void dornd2 (void)
 Rnd(Range) - a random value 0..range.
void doqabs (void)
 QAbs(Quick) - the absolute value (inline).
void dofabs (void)
 Abs(Expression) - the absolute value, as a float.
void doqlimit (void)
 QLimit(Quick,Low,High) - limit q to low..high.
void dontsc (void)
void dodispheight (void)
void dobeamy (void)
 VPos - the vertical beam position (inline).
void dotrue (void)
 True - the constant -1 (inline: MOVEQ #-1,d0).
void dofalse (void)
 False - the constant 0 (inline: MOVEQ #0,d0).
void doqangle (void)
void intchk (void)
static ULONG divu (ULONG dividend, UWORD y)
static ULONG doqangle_c (UWORD sx, UWORD sy, UWORD dx, UWORD dy)
 QAngle(Src X,Src Y,Dest X,Dest Y) - the angle of the line dest -> src.
 BLITZ_ALIAS (doqangle, doqangle_c)
static ULONG dodispheight_c (ULONG hiword, const struct GfxBase *gfx)
 DispHeight - the display height: 200 for NTSC or 256 for PAL.
 BLITZ_ALIAS (dodispheight, dodispheight_c)
static ULONG dontsc_c (ULONG hiword, const struct GfxBase *gfx)
 NTSC - whether the display is NTSC.
 BLITZ_ALIAS (dontsc, dontsc_c)
static void intchk_c (const UBYTE *args)
 intchk - error check of Int, Sgn and Frac (debugger only).
BL_ALWAYS_INLINE UWORD getdec (const UBYTE **pp, LONG *np, ULONG *num, ULONG *scale, int frac)
BL_ALWAYS_INLINE ULONG notneg (const void *ffp, const UBYTE *p, LONG n)
BL_ALWAYS_INLINE ULONG gethex (const void *ffp, const UBYTE *p, LONG n)
BL_ALWAYS_INLINE ULONG getbin (const void *ffp, const UBYTE *p, LONG n)
static BLITZ_ENTRYPOINT ULONG doval_c (UBYTE *str, const void *ffp, const UBYTE *args)
 Val(String$) - the numeric value of a string, as a float.
 BLITZ_ALIAS_EP (doval, doval_c)

Variables

static UWORD last
static UWORD sweor
static const ULONG oct [8]
static const UWORD arc [512]

Macro Definition Documentation

◆ GENRND

#define GENRND
Value:
" move.w 0xdff006,d0\n" /* VHPOSR */ \
" move.w 0xdff00a,d1\n" /* JOY0DAT */ \
" ror.w #8,d1\n" \
" eor.w d1,d0\n" \
" move.b 0xbfe601,d1\n" /* CIA-A TALO */ \
" move.w _last(pc),d2\n" \
" rol.w d2,d1\n" \
" eor.w d1,d0\n" \
" eor.w d2,d0\n" \
" move.w _sweor(pc),d1\n" \
" eor.w #0xaaaa,d1\n" \
" ror.w #1,d1\n" \
" move.w d1,_sweor\n" \
" eor.w d1,d0\n" \
" move.w d0,_last\n"

Function Documentation

◆ BLITZ_ALIAS() [1/3]

BLITZ_ALIAS ( dodispheight ,
dodispheight_c  )

◆ BLITZ_ALIAS() [2/3]

BLITZ_ALIAS ( dontsc ,
dontsc_c  )

◆ BLITZ_ALIAS() [3/3]

BLITZ_ALIAS ( doqangle ,
doqangle_c  )

◆ BLITZ_ALIAS_EP()

BLITZ_ALIAS_EP ( doval ,
doval_c  )

◆ divu()

ULONG divu ( ULONG dividend,
UWORD y )
static

◆ dobeamy()

void dobeamy ( void )

VPos - the vertical beam position (inline).

MOVE.l $dff004,d0 (pick up whole long word...):LSR.l #8,d0:AND $1ff,d0 (the AND is word sized: the upper word keeps VPOSR>>8).

Result
d0: the beam line 0..511 in the low word

◆ dodispheight()

void dodispheight ( void )

◆ dodispheight_c()

ULONG dodispheight_c ( ULONG hiword,
const struct GfxBase * gfx )
static

DispHeight - the display height: 200 for NTSC or 256 for PAL.

Bit 0 of the low byte of GfxBase->DisplayFlags (207(a0)). MOVE.w: the upper word of d0 is kept.

Parameters
hiwordd0: the caller's d0 (its upper word is kept)
gfxa0: the graphics base
Returns
d0: 200 or 256 in the low word

◆ dofabs()

void dofabs ( void )

Abs(Expression) - the absolute value, as a float.

The value as Float with the sign bit (bit 7) cleared: float as is, quick via floatquicklib ($D300), byte/word sign extended, everything else (long, and types >= 6) with SPFlt. The original clears the bit with BCHG #7,d0:BNE 'skip:BCHG #7,d0; here BCLR #7,d0, the same bits.

In: d0 the value, a6 the mathffp base, a2 the argument stack (-2 = the type word: 1 byte, 2 word, 3 long, 4 quick, 5 float) Out: d0 |v| (FFP)

◆ dofalse()

void dofalse ( void )

False - the constant 0 (inline: MOVEQ #0,d0).

Result
d0: 0

◆ doffrac()

void doffrac ( void )

Frac(Expression) - the fractional part, as a float.

Any numeric type (!args{8}, unknown, as Int, Sgn and Abs; the type word at -2(a2)):

  • Float: f - Floor(f) for positive, f - Ceil(f) for negative f (FFP sign = bit 7): SPSub with d0 = f, d1 = Floor/Ceil, the original's code with the original's tail jump into SPSub.
  • Quick: the FFP built from the fraction word of |q| directly: shifted left until its top bit is set (the mantissa), exponent 64 minus the shifts, the sign of q; 0 for no fraction. No mathffp call. Fixed (#1064): the original takes a Float argument, so the compiler converted a Quick with qutofl first, whose 24-bit mantissa rounds away the low fraction bits of an integer part of 256 or more (Frac of the Quick 300.75 was right, of 30000 + 10/65536 it was 0); here the result is the exact fraction of the Quick (16 bits, which an FFP mantissa always holds).
  • Byte, Word, Long: 0 (the original's SPFlt gave an integral float, whose fraction is 0). The original's argument was float: a string was a compile error; now it is refused by intchk in the error check area (runtime error "Illegal Type", as for Int and Sgn).

Changes d0, d1 and what mathffp changes (a0, a1); keeps a2 and a6.

Errors (debugger only, intchk): a string -> "Illegal Type".

In: d0 the value, a6 the mathffp base, a2 the argument stack (-2 = the type word: 1 byte, 2 word, 3 long, 4 quick, 5 float) Out: d0 the fraction (FFP)

◆ doint()

void doint ( void )

Int(Expression) - the integer part as a long.

Float with SPFix (truncates, JMP -30(a6)), quick truncated towards 0 (negative: NEG.l, integer part, NEG), byte/word sign extended, long as is.

Errors (debugger only, intchk): a string -> "Illegal Type".

In: d0 the value, a6 the mathffp base, a2 the argument stack (-2 = the type word) Out: d0 the long

◆ dontsc()

void dontsc ( void )

◆ dontsc_c()

ULONG dontsc_c ( ULONG hiword,
const struct GfxBase * gfx )
static

NTSC - whether the display is NTSC.

BTST #0,207(a0):SNE d0:EXT d0 (upper word of d0 kept).

Parameters
hiwordd0: the caller's d0 (its upper word is kept)
gfxa0: the graphics base
Returns
d0: -1 ($FFFF in the low word) for NTSC, 0 for PAL

◆ doqabs()

void doqabs ( void )

QAbs(Quick) - the absolute value (inline).

NEG.l d0:BPL 'skip:NEG.l d0 ($80000000 stays).

  • q d0: the Quick value
    Result
    d0: |q|

◆ doqangle()

void doqangle ( void )

◆ doqangle_c()

ULONG doqangle_c ( UWORD sx,
UWORD sy,
UWORD dx,
UWORD dy )
static

QAngle(Src X,Src Y,Dest X,Dest Y) - the angle of the line dest -> src.

Octant from the signs and the steepness, arctan from the table arc (arc.bin of the original), mirrored and offset per octant (oct). Fixed (intended deviation, #1003): the differences are longs, their absolute values (0..65535) are compared unsigned. The original subtracted words: a difference of 32768 or more in magnitude wrapped (NEG of -32768 stays negative, CMP/BMI is the sign of the 16 bit difference) and gave the angle of another quadrant. The DIVU of the smaller value << 16 by the larger cannot overflow; for differences in -32767..32767 the result is the original's.

Parameters
sxd0: source x
syd1: source y
dxd2: destination x
dyd3: destination y
Returns
d0: Quick, the fraction of a full turn (0..$FFFF in the low word)

◆ doqfrac()

void doqfrac ( void )

QFrac(Quick) - the fraction of |q| (inline).

TST.l d0:BPL:NEG.l d0, SWAP:CLR:SWAP.

  • q d0: the Quick value
    Result
    d0: Quick, the fraction of |q| (the low word)

◆ doqlimit()

void doqlimit ( void )

QLimit(Quick,Low,High) - limit q to low..high.

Signed: below low -> low, at or above high -> high (CMP.l d2,d0:BLT - q = high also gives high, low wins if low > high only below low). The original's code, an assembler entry: it changes only d0, whatever GCC would make of a C function.

In: d0 the Quick value, d1 the lower limit, d2 the upper limit Out: d0 the limited value

◆ doqwrap()

void doqwrap ( void )

QWrap(Quick,Low,High) - wrap q into low..high (inline).

Below low: +high-low, at or above high: -high+low (once, signed long compares).

  • q d0: the Quick value
  • low d1: the lower limit
  • high d2: the upper limit (exclusive)
    Result
    d0: the wrapped value

◆ dornd1()

void dornd1 ( void )

Rnd - a random fraction.

MOVEQ #0,d0 + genrnd (hardware noise, see GENRND). Rnd and Rnd(Range) keep a0 and a1, which the CD programs SQUIRT2_TO and SQUIRT3_TO hold across them (inline assembler): the assembler changes only d0-d2 (KEEPS a0|a1 in libs/tests/systest_cmdlibs.c).

Out: d0 Quick 0..$FFFF/$10000 (16 random bits in the low word)

◆ dornd2()

void dornd2 ( void )

Rnd(Range) - a random value 0..range.

MULU range.w,genrnd (range as unsigned word: Rnd(-1) = Rnd(65535)). The original keeps the range in d7 (MOVE d0,d7); here it waits in the upper word of d1, which GENRND does not touch, so Rnd(Range) changes only d0-d2, as Rnd.

In: d0.w the range (unsigned word) Out: d0 Quick 0..range (exclusive)

◆ dosgn()

void dosgn ( void )

Sgn(Expression) - the sign: -1, 0 or 1.

Float through SPTst, long and quick tested as long, byte (type 1) and word (types 0, 2) sign extended.

Errors (debugger only, intchk): a string -> "Illegal Type".

Fixed (#301): mathffp SPTst tests D1, not D0; the original passes d1 as it has it, the type (MOVE -(a2),d1: 5 in the low word, the caller's upper word), so Sgn of a float was 1 whatever the value (Sgn(-1.0) = Sgn(0.0) = 1). Now SPTst gets the float in d1 (MOVE.l d0,d1).

In: d0 the value, a6 the mathffp base, a2 the argument stack (-2 = the type word) Out: d0 Quick -1, 0 or 1 ($FFFF0000, 0, $00010000)

◆ dotrue()

void dotrue ( void )

True - the constant -1 (inline: MOVEQ #-1,d0).

Result
d0: -1 (a word function: Blitz's true)

◆ doval()

void doval ( void )

◆ doval_c()

BLITZ_ENTRYPOINT ULONG doval_c ( UBYTE * str,
const void * ffp,
const UBYTE * args )
static

Val(String$) - the numeric value of a string, as a float.

doval2: leading spaces skipped, then "$" hex, "%" binary, "-" negative (SPNeg), else decimal with an optional fraction. MOVE.l d0,a3: a3 = the string afterwards (frees the work area).

Fixed (#302): after "$", "%" and "-" the count is decremented with the character skipped. The original did not, so hex, binary and negative numbers read one byte behind the string as a further digit (normally its terminating 0: Val(Left$("-12",2)) = -1; a digit there was taken too). Fixed (#303): the length is used as a long (the original counted its low word (SUBQ #1,d2:BMI): lengths 32769..65536 gave 0, longer ones counted mod 65536). Fixed (#304): only the first 9 fraction digits count (the original took them all modulo 2^32: wrong from 10 decimal places on, dropped from 32 on).

Parameters
strd0: the string
ffpa6: the mathffp base
argsa2: the argument stack, -4 = the string length (long)
Returns
d0: the value (FFP), 0 for an empty string

◆ getbin()

BL_ALWAYS_INLINE ULONG getbin ( const void * ffp,
const UBYTE * p,
LONG n )

◆ getdec()

BL_ALWAYS_INLINE UWORD getdec ( const UBYTE ** pp,
LONG * np,
ULONG * num,
ULONG * scale,
int frac )

◆ gethex()

BL_ALWAYS_INLINE ULONG gethex ( const void * ffp,
const UBYTE * p,
LONG n )

◆ intchk()

void intchk ( void )

◆ intchk_c()

void intchk_c ( const UBYTE * args)
static

intchk - error check of Int, Sgn and Frac (debugger only).

CMP #6,-2(a2):BCC err1:RTS - the type word on the a2 stack (not popped) must be numeric; keeps all registers.

Errors: type >= 6 (a string) -> runtime error "Illegal Type".

Parameters
argsa2: the argument stack, -2 = the type word

◆ notneg()

BL_ALWAYS_INLINE ULONG notneg ( const void * ffp,
const UBYTE * p,
LONG n )

Variable Documentation

◆ arc

const UWORD arc[512]
static

◆ last

UWORD last
static

◆ oct

const ULONG oct[8]
static
Initial value:
= {
0x00000000, 0x4000ffff, 0x0000ffff, 0xc0000000,
0x8000ffff, 0x40000000, 0x80000000, 0xc000ffff,
}

◆ sweor

UWORD sweor
static