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

Data Structures

struct  printvars
struct  ffpvars
struct  ez

Macros

#define PL_BASE   ((UBYTE *)&pl)
#define PL_FORM   (PL_BASE + offsetof(struct printvars, form))
#define PL_CHARS   (PL_BASE + offsetof(struct printvars, chars))
#define PL_NUMBUFF   (PL_BASE + offsetof(struct printvars, numbuff))
#define PL_NUMBUFFF   (PL_BASE + offsetof(struct printvars, numbufff))
#define T(e, m)
#define FA_BASE   ((UBYTE *)&fa)
#define FA_BUF1   (FA_BASE + offsetof(struct ffpvars, buf1))
#define FA_BUF2   (FA_BASE + offsetof(struct ffpvars, buf2))
#define FA_ONE   (FA_BASE + offsetof(struct ffpvars, tab[19])) /* table entry 1E0 */
#define RDW(p)
#define RDL(p)

Functions

void doformat (void)
void dofloatmode (void)
void printlib_codeinit (void)
void formatchk (void)
void printctrlc (void)
void doprint (UWORD n, const UBYTE *args)
 Print Expression[,Expression...] - output the values to the current output (inputoutputlib, dooutstring1 $5208).
void donprint (UWORD n, const UBYTE *args)
 NPrint Expression[,Expression...] - Print, then a newline (dooutsingle $5207 with 10).
ULONG dostrstr (ULONG v, const UBYTE *args)
 Str$(Expression) - the value as Print would output it, as a string.
ULONG doustrstr (ULONG v, const UBYTE *args)
 UStr$(Expression) - Str$ without Format (the Format string is switched off meanwhile).
BL_ALWAYS_INLINE ULONG output (const UBYTE *s, ULONG len)
static int ezchar (struct ez *z)
static const UBYTE * fmtround (UBYTE *buf, UWORD size, const UBYTE *num, UWORD *len, UWORD places)
static ULONG prtype1 (const UBYTE *numtext, ULONG len)
BL_ALWAYS_INLINE ULONG prtype2 (const UBYTE *buf)
static void doformat_c (const UBYTE *s, const UBYTE *args)
 Format FormatString - the format of numbers for Print, NPrint and Str$ ("" = none).
 BLITZ_ALIAS (doformat, doformat_c)
static void dofloatmode_c (UWORD m)
 FloatMode Mode - how floats are printed: -1 = always fixed point ("standard"), 0 = guess (fixed point for 1E-9 <= |x| < 1E+7, else exponent form), 1 = always exponent form.
 BLITZ_ALIAS (dofloatmode, dofloatmode_c)
static void codeinit_c (void)
 Library init - no Format, FloatMode 0. Keeps all registers.
static UBYTE * makeval3 (UBYTE *dst, ULONG *value, UWORD n)
static UBYTE * makeval2 (UBYTE *dst, ULONG value, UWORD n)
static UBYTE * makeval (ULONG value, UWORD n)
static void makelong (ULONG value)
static UBYTE * plong2 (ULONG value)
static UBYTE * pbyte2 (ULONG value)
static UBYTE * pword2 (ULONG value)
static UBYTE * quick3 (ULONG value)
static UBYTE * pquick2 (ULONG value)
static UBYTE * ffptoascii (ULONG value, UWORD mode)
static UBYTE * pfloat2 (ULONG value)
BL_ALWAYS_INLINE UBYTE * numtext (UWORD type, ULONG value)
BL_ALWAYS_INLINE ULONG ptype (UWORD type, const UBYTE **sp)
void strprint (void)
BL_ALWAYS_INLINE ULONG wstr (ULONG value, const UBYTE *args)
static void formatchk_c (const ULONG *lens)
 BLITZ_ERRCHK_ASM (printctrlc, " .globl _printctrlc\n" "_printctrlc:\n" " jmp _blitz_tok+" BL_ASMTOK(LIB_inputoutputlib, 12))

Variables

static struct printvars pl = { .space2 = 0x2020 }
static struct ffpvars fa
static const ULONG divisors [10]

Macro Definition Documentation

◆ FA_BASE

#define FA_BASE   ((UBYTE *)&fa)

◆ FA_BUF1

#define FA_BUF1   (FA_BASE + offsetof(struct ffpvars, buf1))

◆ FA_BUF2

#define FA_BUF2   (FA_BASE + offsetof(struct ffpvars, buf2))

◆ FA_ONE

#define FA_ONE   (FA_BASE + offsetof(struct ffpvars, tab[19])) /* table entry 1E0 */

◆ PL_BASE

#define PL_BASE   ((UBYTE *)&pl)

◆ PL_CHARS

#define PL_CHARS   (PL_BASE + offsetof(struct printvars, chars))

◆ PL_FORM

#define PL_FORM   (PL_BASE + offsetof(struct printvars, form))

◆ PL_NUMBUFF

#define PL_NUMBUFF   (PL_BASE + offsetof(struct printvars, numbuff))

◆ PL_NUMBUFFF

#define PL_NUMBUFFF   (PL_BASE + offsetof(struct printvars, numbufff))

◆ RDL

#define RDL ( p)
Value:
(*(const ULONG *)(p))

◆ RDW

#define RDW ( p)
Value:
(*(const UWORD *)(p))

◆ T

#define T ( e,
m )
Value:
{ (e), (UWORD)((m) >> 16), (UWORD)(m) }

Function Documentation

◆ BLITZ_ALIAS() [1/2]

BLITZ_ALIAS ( dofloatmode ,
dofloatmode_c  )

◆ BLITZ_ALIAS() [2/2]

BLITZ_ALIAS ( doformat ,
doformat_c  )

◆ BLITZ_ERRCHK_ASM()

BLITZ_ERRCHK_ASM ( printctrlc ,
" .globl _printctrlc\n" "_printctrlc:\n" " jmp _blitz_tok+" BL_ASMTOKLIB_inputoutputlib, 12 )

◆ codeinit_c()

void codeinit_c ( void )
static

Library init - no Format, FloatMode 0. Keeps all registers.

◆ dofloatmode()

void dofloatmode ( void )

◆ dofloatmode_c()

void dofloatmode_c ( UWORD m)
static

FloatMode Mode - how floats are printed: -1 = always fixed point ("standard"), 0 = guess (fixed point for 1E-9 <= |x| < 1E+7, else exponent form), 1 = always exponent form.

Keeps all registers like the original.

Fixed (#241): fixed point with FloatMode -1 (or a Format string) and |x| < 1E-17 wrote past the 50 byte buffer into the table of powers of ten; the buffer has 52 bytes.

Parameters
md0: the mode.

◆ doformat()

void doformat ( void )

◆ doformat_c()

void doformat_c ( const UBYTE * s,
const UBYTE * args )
static

Format FormatString - the format of numbers for Print, NPrint and Str$ ("" = none).

doformat - copy the string to form, count the digit places before and after the point. "#" = digit or space, "0" = digit or zero, "." decimal point, "-" = "-" if negative else space, "+" = "+"/"-", "," = "," (space in the leading pad), other characters literally. With a Format string floats are always fixed point. The original keeps d0 (MOVE.l d0,a0).

By design (#240): a Format string longer than 32 characters (no check without the debugger) runs over formlen/formlead/formtrail/decpos and further into the conversion buffers. (The bugs of the formatting itself, #235-#238, are fixed.)

Errors (debugger only, formatchk): "Format String too long" (> 32).

Parameters
sd0: the characters.
argsa2: the argument stack: the length is popped with MOVE.l -(a2),d1, only its low word is used.

◆ donprint()

void donprint ( UWORD n,
const UBYTE * args )

NPrint Expression[,Expression...] - Print, then a newline (dooutsingle $5207 with 10).

Parameters
nd7: the number of arguments.
argsa2: the argument stack.

◆ doprint()

void doprint ( UWORD n,
const UBYTE * args )

Print Expression[,Expression...] - output the values to the current output (inputoutputlib, dooutstring1 $5208).

The arguments are of unknown type: for each the type word and then the value are popped from the a2 stack (MOVE.l for long/quick/float, MOVE for byte/word, length then address for a string). Number formats (see the top): byte/word/long decimal, quick with up to 4 decimals, float as FloatMode says; with a Format string all numbers formatted. DIFF: a2 is left unchanged (the original returns it decremented by everything it popped).

Parameters
nd7: the number of arguments (move.w numreps,d7).
argsa2: the argument stack.

◆ dostrstr()

ULONG dostrstr ( ULONG v,
const UBYTE * args )

Str$(Expression) - the value as Print would output it, as a string.

Redirects the output to strprint (inputoutputlib dosetout), prints, restores: with Format active, Str$ formats like Print. The characters go to a3. Not a bug (no effect): dosetout is called twice, so every Str$ pushes two entries on inputoutputlib's output stack (a ring of 16).

Fixed (#242): Str$ of a string is the string itself (the original printed it as a byte, the low byte of the address).

Parameters
vd0: the value (for a string: its address).
argsa2: the argument stack: the type word is popped (for a string then its length).
Returns
d0: the length of the string.

◆ doustrstr()

ULONG doustrstr ( ULONG v,
const UBYTE * args )

UStr$(Expression) - Str$ without Format (the Format string is switched off meanwhile).

Fixed (#242) as Str$: a string is the result itself.

Parameters
vd0: the value (for a string: its address).
argsa2: the argument stack: the type word is popped (for a string then its length).
Returns
d0: the length of the string.

◆ ezchar()

int ezchar ( struct ez * z)
static

◆ ffptoascii()

UBYTE * ffptoascii ( ULONG value,
UWORD mode )
static

◆ fmtround()

const UBYTE * fmtround ( UBYTE * buf,
UWORD size,
const UBYTE * num,
UWORD * len,
UWORD places )
static

◆ formatchk()

void formatchk ( void )

◆ formatchk_c()

void formatchk_c ( const ULONG * lens)
static

◆ makelong()

void makelong ( ULONG value)
static

◆ makeval()

UBYTE * makeval ( ULONG value,
UWORD n )
static

◆ makeval2()

UBYTE * makeval2 ( UBYTE * dst,
ULONG value,
UWORD n )
static

◆ makeval3()

UBYTE * makeval3 ( UBYTE * dst,
ULONG * value,
UWORD n )
static

◆ numtext()

BL_ALWAYS_INLINE UBYTE * numtext ( UWORD type,
ULONG value )

◆ output()

BL_ALWAYS_INLINE ULONG output ( const UBYTE * s,
ULONG len )

◆ pbyte2()

UBYTE * pbyte2 ( ULONG value)
static

◆ pfloat2()

UBYTE * pfloat2 ( ULONG value)
static

◆ plong2()

UBYTE * plong2 ( ULONG value)
static

◆ pquick2()

UBYTE * pquick2 ( ULONG value)
static

◆ printctrlc()

void printctrlc ( void )

◆ printlib_codeinit()

void printlib_codeinit ( void )

◆ prtype1()

ULONG prtype1 ( const UBYTE * numtext,
ULONG len )
static

◆ prtype2()

BL_ALWAYS_INLINE ULONG prtype2 ( const UBYTE * buf)

◆ ptype()

BL_ALWAYS_INLINE ULONG ptype ( UWORD type,
const UBYTE ** sp )

◆ pword2()

UBYTE * pword2 ( ULONG value)
static

◆ quick3()

UBYTE * quick3 ( ULONG value)
static

◆ strprint()

void strprint ( void )

◆ wstr()

BL_ALWAYS_INLINE ULONG wstr ( ULONG value,
const UBYTE * args )

Variable Documentation

◆ divisors

const ULONG divisors[10]
static
Initial value:
= {
1, 10, 100, 1000, 10000, 100000,
1000000, 10000000, 100000000, 1000000000,
}

◆ fa

struct ffpvars fa
static
Initial value:
= {
.tab = {
#define T(e, m)
T(0x0040, 0x8ac72305), T(0x003c, 0xde0b6b3a), T(0x0039, 0xb1a2bc2f),
T(0x0036, 0x8e1bc9bf), T(0x0032, 0xe35fa932), T(0x002f, 0xb5e620f5),
T(0x002c, 0x9184e72a), T(0x0028, 0xe8d4a510), T(0x0025, 0xba43b740),
T(0x0022, 0x9502f900), T(0x001e, 0xee6b2800), T(0x001b, 0xbebc2000),
T(0x0018, 0x98968000), T(0x0014, 0xf4240000), T(0x0011, 0xc3500000),
T(0x000e, 0x9c400000), T(0x000a, 0xfa000000), T(0x0007, 0xc8000000),
T(0x0004, 0xa0000000), T(0x0001, 0x80000000), T(0xfffd, 0xcccccccd),
T(0xfffa, 0xa3d70a3d), T(0xfff7, 0x83126e98), T(0xfff3, 0xd1b71759),
T(0xfff0, 0xa7c5ac47), T(0xffed, 0x8637bd06), T(0xffe9, 0xd6bf94d6),
T(0xffe6, 0xabcc7712), T(0xffe3, 0x89705f41), T(0xffdf, 0xdbe6fecf),
T(0xffdc, 0xafebff0c), T(0xffd9, 0x8cbccc09), T(0xffd5, 0xe12e1342),
T(0xffd2, 0xb424dc35), T(0xffcf, 0x901d7cf7), T(0xffcb, 0xe69594bf),
T(0xffc8, 0xb877aa32), T(0xffc5, 0x9392ee8f), T(0xffc1, 0xec1e4a7e),
T(0xffbe, 0xbce50865), T(0xffbb, 0x971da050), T(0xffb7, 0xf1c90081),
T(0xffb4, 0xc16d9a01), T(0xffb1, 0x9abe14cd), T(0xffad, 0xf79687ae),
T(0xffaa, 0xc6120625), T(0xffa7, 0x9e74d1b8), T(0xffa3, 0xfd87b5f3),
},
}
#define T(maxbp, fetchwid, xmask, xrshift, adjwid, adjstop, fmode, diwstrt, diwstop, ddfstrt, ddfstop, bplcon0)
Definition displaylib.c:377

◆ pl

struct printvars pl = { .space2 = 0x2020 }
static