|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
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) |
| #define ARR_TOOBIG 0x7fffffffUL |
| #define AT | ( | base, | |
| off ) |
| void arrmult | ( | void | ) |
|
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.
| size | d0: the size so far (element size times the dimensions) |
| dim | d1.w: the dimension (its highest index) |
| void arrmultchk | ( | void | ) |
|
static |
| BLITZ_ALIAS | ( | newlocarr | , |
| newlocarr_c | ) |
|
static |
|
static |
| void newarr | ( | void | ) |
|
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.
| ptr | d2.w: offset of the array pointer from a5 |
| size | d3.w: offset of the long with the size in bytes from a5 |
| 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.
| ptr | d2.w: offset of the list pointer from a5 |
| size | d3.w: offset of the long with the size of the items in bytes from a5 |
| itemsize | d4.w: the size of one item (element size + 8) |
| void newlocarr | ( | void | ) |
|
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.
| ptr | d2.w: offset of the array pointer from a4 |
| size | d3.w: offset of the long with the size in bytes from a4 |
| 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.
| ptr | d2.w: offset of the list pointer from a4 |
| size | d3.w: offset of the long with the size of the items in bytes from a4 |
| itemsize | d4.w: the size of one item (element size + 8) |