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

Macros

#define AT(base, off)
#define ARR_TOOBIG   0x7fffffffUL

Functions

void newarr (void)
void newlocarr (void)
void arrmult (void)
void arrmultchk (void)
void newlist (WORD ptr, WORD size, WORD itemsize)
 newlist ($C403, newarr+3): (re)allocate a global list (Dim List).
void newloclist (WORD ptr, WORD size, WORD itemsize)
 newloclist ($C404, newlocarr+3): newlist for a local list (Dim List in a procedure): the offsets are from a4.
static ULONG new_array (UBYTE *base, WORD ptr, WORD size)
static ULONG newarr_c (WORD ptr, WORD size)
 newarr ($C400): (re)allocate the memory of a global array (Dim).
 BLITZ_ALIAS (newarr, newarr_c)
static ULONG newlocarr_c (WORD ptr, WORD size)
 newlocarr ($C401): newarr for a local array (Dim in a procedure): the offsets are from a4.
 BLITZ_ALIAS (newlocarr, newlocarr_c)
static ULONG arrmult_c (ULONG size, ULONG dim)
 arrmult ($C402): multiply the array size by one dimension (Dim, once per dimension).
 BLITZ_ALIAS (arrmult, arrmult_c)
static void new_list (UBYTE *base, WORD ptr, WORD size, WORD itemsize)
static void arrmultchk_c (ULONG size, ULONG dim)

Macro Definition Documentation

◆ ARR_TOOBIG

#define ARR_TOOBIG   0x7fffffffUL

◆ AT

#define AT ( base,
off )
Value:
(*(ULONG *)((base) + (WORD)(off))) /* 0(a5,dN.w) */

Function Documentation

◆ arrmult()

void arrmult ( void )

◆ arrmult_c()

ULONG arrmult_c ( ULONG size,
ULONG dim )
static

arrmult ($C402): multiply the array size by one dimension (Dim, once per dimension).

d0 = d0 * (d1.w + 1), with two 16 bit MULUs: ADDQ #1,d1:MOVE.l d0,d2:MULU d1,d0 SWAP d2:MULU d1,d2:SWAP d2:ADD.l d2,d0 Fixed (#58): the second product is shifted (the original SWAPped it, so its high word was added to the low word of the result), and a size that does not fit in 32 bits becomes ARR_TOOBIG: the allocation of the array fails with memlib's runtime error "Out of Memory!" (the original went on with the size modulo 2^32, plus the SWAPped word: Dim a.l(32767,32767) got 1 byte and succeeded). Errors (debugger, arrmultchk): "Array Size out of Range" for a size that does not fit in 32 bits (#58: the original had no check). The count is a word: a dimension has at most 65535 elements, the highest index 65535 gives 0 (an invalid argument; with runtime error checking runerrlib's aarraychk refuses it, fixed #1037). DIFF: the original returns d1.w+1 and changes d2; the compiler does not use them (the next dimension is evaluated again), the C build keeps d2 and leaves d1 undefined. Keeps d2-d7/a2-a6 (only d0 is used after it); a0 and a1 are free.

Parameters
sized0: the size so far (element size times the dimensions)
dimd1.w: the dimension (its highest index)
Returns
d0: the new size, ARR_TOOBIG if it does not fit in 32 bits

◆ arrmultchk()

void arrmultchk ( void )

◆ arrmultchk_c()

void arrmultchk_c ( ULONG size,
ULONG dim )
static

◆ BLITZ_ALIAS() [1/3]

BLITZ_ALIAS ( arrmult ,
arrmult_c  )

◆ BLITZ_ALIAS() [2/3]

BLITZ_ALIAS ( newarr ,
newarr_c  )

◆ BLITZ_ALIAS() [3/3]

BLITZ_ALIAS ( newlocarr ,
newlocarr_c  )

◆ new_array()

ULONG new_array ( UBYTE * base,
WORD ptr,
WORD size )
static

◆ new_list()

void new_list ( UBYTE * base,
WORD ptr,
WORD size,
WORD itemsize )
static

◆ newarr()

void newarr ( void )

◆ newarr_c()

ULONG newarr_c ( WORD ptr,
WORD size )
static

newarr ($C400): (re)allocate the memory of a global array (Dim).

Frees the old array (memlib locfree) if the pointer at 0(a5,d2) is set, allocates 0(a5,d3) bytes (memlib localloc, MEMF_PUBLIC|MEMF_CLEAR) and stores the address at 0(a5,d2). Keeps d2-d7/a2-a6: the compiler calls it at the end of Dim and uses only d0 after it (perf-analysis thunks.md 1.4), and no third-party library calls it; a0 and a1 (kept by the original, as memlib keeps them) are free.

Parameters
ptrd2.w: offset of the array pointer from a5
sized3.w: offset of the long with the size in bytes from a5
Returns
d0: the array memory

◆ newlist()

void newlist ( WORD ptr,
WORD size,
WORD itemsize )

newlist ($C403, newarr+3): (re)allocate a global list (Dim List).

Frees the old list (memlib locfree, from 32 bytes before 0(a5,d2)), allocates the 32 byte header and 0(a5,d3) bytes (memlib localloc, MEMF_PUBLIC|MEMF_CLEAR), sets up the header (empty list of items in use, "lIsT") and links all items of d4.w bytes into the free list; 0(a5,d2) = the first item (header+32). Fixed (#59): only items whose node (8 bytes) fits are linked; the original still linked one item for a size of 0, its 8 bytes behind the block. The original changes d0/d1/a0-a3 (a3 too); the C build keeps a2/a3.

Parameters
ptrd2.w: offset of the list pointer from a5
sized3.w: offset of the long with the size of the items in bytes from a5
itemsized4.w: the size of one item (element size + 8)

◆ newlocarr()

void newlocarr ( void )

◆ newlocarr_c()

ULONG newlocarr_c ( WORD ptr,
WORD size )
static

newlocarr ($C401): newarr for a local array (Dim in a procedure): the offsets are from a4.

DIFF: the original swaps a4/a5 around the call of newarr; here the base (a4) is passed to the common code (memlib does not use a5). Registers as newarr.

Parameters
ptrd2.w: offset of the array pointer from a4
sized3.w: offset of the long with the size in bytes from a4
Returns
d0: the array memory

◆ newloclist()

void newloclist ( WORD ptr,
WORD size,
WORD itemsize )

newloclist ($C404, newlocarr+3): newlist for a local list (Dim List in a procedure): the offsets are from a4.

DIFF: no a4/a5 swap, the base (a4) is passed to the common code.

Parameters
ptrd2.w: offset of the list pointer from a4
sized3.w: offset of the long with the size of the items in bytes from a4
itemsized4.w: the size of one item (element size + 8)