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

Data Structures

struct  stackentry

Macros

#define HEAD(b)
#define CURRENT(b)
#define USED(b)
#define USEDTAIL(b)
#define TAILPRED(b)
#define FREE(b)
#define LISTID(b)
#define KEY(i)

Functions

BB_BOOL dofirstitem (UBYTE *base)
 FirstItem(Arrayname()): make the first item the current one.
void doadditem (void)
void donextitem (void)
void doreslist (UBYTE *base)
 ResetList Arrayname(): no current item (the next NextItem gives the first). Errors (debugger only): "Array is not a List" (lchk).
void dokillitem (void)
void doaddfirst (void)
void doclearlist (void)
void doaddlast (void)
void dopushcurrent (UBYTE *base)
 PushItem Arrayname(): push the list and its current item on the item stack.
void dopopcurrent (UBYTE *base)
 PopItem Arrayname(): pop the current item from the item stack into the given list.
void doprevitem (void)
BB_BOOL dolastitem (UBYTE *base)
 LastItem(Arrayname()): make the last item the current one, as FirstItem.
void setstack (ULONG n)
 ItemStackSize Max Items: a new item stack.
void dosortlist (UBYTE *base, WORD offset)
 SortList Arrayname(),sizeof .type\offset: sort a list by a long of its elements.
static void doinit (void)
 The library's init: an empty item stack of 8 entries.
void lchk (void)
void lchk2 (void)
void pushchk (void)
void popchk (void)
BL_ALWAYS_INLINE void unlinkitem (struct bb_listitem *item)
BL_ALWAYS_INLINE void linkitem (struct bb_listitem *item, struct bb_listitem *after)
static BLITZ_ENTRYPOINT void doclearlist_c (UBYTE *base)
 ClearList Arrayname(): empty a list.
 BLITZ_ALIAS_EP (doclearlist, doclearlist_c)
BL_ALWAYS_INLINE BB_BOOL firstitem2 (UBYTE *base)
BL_ALWAYS_INLINE BB_BOOL lastitem2 (UBYTE *base)
static BLITZ_ENTRYPOINT void dokillitem_c (UBYTE *base)
 KillItem Arrayname(): remove the current item.
 BLITZ_ALIAS_EP (dokillitem, dokillitem_c)
static BLITZ_ENTRYPOINT BB_BOOL doadditem_c (UBYTE *base)
 AddItem(Arrayname()): insert an item after the current one.
 BLITZ_ALIAS_EP (doadditem, doadditem_c)
static BLITZ_ENTRYPOINT BB_BOOL doaddfirst_c (UBYTE *base)
 AddFirst(Arrayname()): add an item at the beginning of the list, as AddItem; it becomes current.
 BLITZ_ALIAS_EP (doaddfirst, doaddfirst_c)
static BLITZ_ENTRYPOINT BB_BOOL doaddlast_c (UBYTE *base)
 AddLast(Arrayname()): add an item at the end of the list, as AddItem; it becomes current.
 BLITZ_ALIAS_EP (doaddlast, doaddlast_c)
static BB_BOOL donextitem_c (UBYTE *base)
 NextItem(Arrayname()): make the next item the current one.
 BLITZ_ALIAS (donextitem, donextitem_c)
static BB_BOOL doprevitem_c (UBYTE *base)
 PrevItem Arrayname(): make the previous item the current one, as NextItem backwards (without a current item it does LastItem).
 BLITZ_ALIAS (doprevitem, doprevitem_c)
static void lchk_c (UBYTE *base)
static void lchk2_c (UBYTE *base)
static void pushchk_c (UBYTE *base)
static void popchk_c (UBYTE *base)

Variables

static ULONG maxstack
static struct stackentry * currstack
static struct stackentry * currsp

Macro Definition Documentation

◆ CURRENT

#define CURRENT ( b)
Value:
(HEAD(b)->current)
#define HEAD(b)
Definition linklistlib.c:166

◆ FREE

#define FREE ( b)
Value:
((struct bb_listitem *)&HEAD(b)->free.mlh_Head) /* &lh_Head of free */
The node at the start of every item of a Blitz list.
Definition blitzobj.h:340

◆ HEAD

#define HEAD ( b)
Value:
((struct bb_listhead *)((b) - sizeof(struct bb_listhead)))
The 32 bytes in front of a Blitz list array (Dim List): the array points behind it,...
Definition blitzobj.h:354

◆ KEY

#define KEY ( i)
Value:
(*(ULONG *)((UBYTE *)((i) + 1) + offset)) /* the element: behind the node */
static UWORD offset
Definition scrolllib.c:107

◆ LISTID

#define LISTID ( b)
Value:
(HEAD(b)->id)

◆ TAILPRED

#define TAILPRED ( b)
Value:
(*(struct bb_listitem **)&HEAD(b)->used.mlh_TailPred)

◆ USED

#define USED ( b)
Value:
((struct bb_listitem *)&HEAD(b)->used.mlh_Head) /* &lh_Head as node */

◆ USEDTAIL

#define USEDTAIL ( b)
Value:
((struct bb_listitem *)&HEAD(b)->used.mlh_Tail) /* &lh_Tail as node */

Function Documentation

◆ BLITZ_ALIAS() [1/2]

BLITZ_ALIAS ( donextitem ,
donextitem_c  )

◆ BLITZ_ALIAS() [2/2]

BLITZ_ALIAS ( doprevitem ,
doprevitem_c  )

◆ BLITZ_ALIAS_EP() [1/5]

BLITZ_ALIAS_EP ( doaddfirst ,
doaddfirst_c  )

◆ BLITZ_ALIAS_EP() [2/5]

BLITZ_ALIAS_EP ( doadditem ,
doadditem_c  )

◆ BLITZ_ALIAS_EP() [3/5]

BLITZ_ALIAS_EP ( doaddlast ,
doaddlast_c  )

◆ BLITZ_ALIAS_EP() [4/5]

BLITZ_ALIAS_EP ( doclearlist ,
doclearlist_c  )

◆ BLITZ_ALIAS_EP() [5/5]

BLITZ_ALIAS_EP ( dokillitem ,
dokillitem_c  )

◆ doaddfirst()

void doaddfirst ( void )

◆ doaddfirst_c()

BLITZ_ENTRYPOINT BB_BOOL doaddfirst_c ( UBYTE * base)
static

AddFirst(Arrayname()): add an item at the beginning of the list, as AddItem; it becomes current.

Parameters
based0: the list array
Returns
d0: BB_TRUE if an item was added, BB_FALSE if none is free

◆ doadditem()

void doadditem ( void )

◆ doadditem_c()

BLITZ_ENTRYPOINT BB_BOOL doadditem_c ( UBYTE * base)
static

AddItem(Arrayname()): insert an item after the current one.

Takes the first free item and inserts it after the current one (no current: at the beginning); it becomes current. Errors (debugger only): "Array is not a List" (lchk).

Parameters
based0: the list array
Returns
d0: BB_TRUE if an item was added, BB_FALSE if there is no free item

◆ doaddlast()

void doaddlast ( void )

◆ doaddlast_c()

BLITZ_ENTRYPOINT BB_BOOL doaddlast_c ( UBYTE * base)
static

AddLast(Arrayname()): add an item at the end of the list, as AddItem; it becomes current.

Parameters
based0: the list array
Returns
d0: BB_TRUE if an item was added, BB_FALSE if none is free

◆ doclearlist()

void doclearlist ( void )

◆ doclearlist_c()

BLITZ_ENTRYPOINT void doclearlist_c ( UBYTE * base)
static

ClearList Arrayname(): empty a list.

Moves all used items to the front of the free list (one by one, so their order is reversed); no current item. Interrupts disabled meanwhile. Errors (debugger only): "Array is not a List" (lchk).

Parameters
based0: the list array

◆ dofirstitem()

BB_BOOL dofirstitem ( UBYTE * base)

FirstItem(Arrayname()): make the first item the current one.

No current item if the list is empty. Errors (debugger only): "Array is not a List" (lchk).

Parameters
based0: the list array
Returns
d0: BB_TRUE if there is an item, BB_FALSE if the list is empty

◆ doinit()

void doinit ( void )
static

The library's init: an empty item stack of 8 entries.

◆ dokillitem()

void dokillitem ( void )

◆ dokillitem_c()

BLITZ_ENTRYPOINT void dokillitem_c ( UBYTE * base)
static

KillItem Arrayname(): remove the current item.

There must be a current item to kill (checked only with the debugger: "No Current Item", lchk2). It moves to the front of the free list; the new current item is its previous one (none if it was the first).

Parameters
based0: the list array

◆ dolastitem()

BB_BOOL dolastitem ( UBYTE * base)

LastItem(Arrayname()): make the last item the current one, as FirstItem.

Parameters
based0: the list array
Returns
d0: BB_TRUE if there is an item, BB_FALSE if the list is empty

◆ donextitem()

void donextitem ( void )

◆ donextitem_c()

BB_BOOL donextitem_c ( UBYTE * base)
static

NextItem(Arrayname()): make the next item the current one.

Without a current item it does FirstItem. At the end the current item stays. Errors (debugger only): "Array is not a List" (lchk).

The current item is read into a data register (the empty asm with a "+d" operand): MOVE sets the flags there, where GCC tested an address register with CMPA.w #0 (10 cycles); the middle item, the common case, goes straight through to its own RTS. The entry is an alias of the static C function: with the function itself in the !subs table above (its address taken before its body) GCC put the RTS behind the rare exits and branched to it (BRA.s, 10 cycles).

Parameters
based0: the list array
Returns
d0: BB_TRUE if there is a next item, BB_FALSE at the end

◆ dopopcurrent()

void dopopcurrent ( UBYTE * base)

PopItem Arrayname(): pop the current item from the item stack into the given list.

Errors (debugger only): "Current Stack Empty", "Wrong Array on Stack" (the array on the stack is only checked then), "Array is not a List" (popchk).

Parameters
based0: the list array

◆ doprevitem()

void doprevitem ( void )

◆ doprevitem_c()

BB_BOOL doprevitem_c ( UBYTE * base)
static

PrevItem Arrayname(): make the previous item the current one, as NextItem backwards (without a current item it does LastItem).

Parameters
based0: the list array
Returns
d0: BB_TRUE if there is a previous item, BB_FALSE at the beginning

◆ dopushcurrent()

void dopushcurrent ( UBYTE * base)

PushItem Arrayname(): push the list and its current item on the item stack.

Errors (debugger only): "Current Stack overflow", "Array is not a List" (pushchk). Without the debugger there is no check.

Parameters
based0: the list array

◆ doreslist()

void doreslist ( UBYTE * base)

ResetList Arrayname(): no current item (the next NextItem gives the first). Errors (debugger only): "Array is not a List" (lchk).

Parameters
based0: the list array

◆ dosortlist()

void dosortlist ( UBYTE * base,
WORD offset )

SortList Arrayname(),sizeof .type\offset: sort a list by a long of its elements.

Sorts the used items ascending by the long at offset in the element (bubble sort; every pass ends one item earlier). The current item stays the same item. Interrupts disabled meanwhile. Errors (debugger only): "Array is not a List" (lchk). DIFF: a3 is not changed (the original destroys a3 and d6). Fixed (#201): the keys are compared signed (the original took the sign of the difference, CMP.l:BMI, which wraps for keys more than 2^31 apart); items with equal keys are not swapped.

Parameters
based0: the list array
offsetd1: the offset of the key in the element

◆ firstitem2()

BL_ALWAYS_INLINE BB_BOOL firstitem2 ( UBYTE * base)

◆ lastitem2()

BL_ALWAYS_INLINE BB_BOOL lastitem2 ( UBYTE * base)

◆ lchk()

void lchk ( void )

◆ lchk2()

void lchk2 ( void )

◆ lchk2_c()

void lchk2_c ( UBYTE * base)
static

◆ lchk_c()

void lchk_c ( UBYTE * base)
static

◆ linkitem()

BL_ALWAYS_INLINE void linkitem ( struct bb_listitem * item,
struct bb_listitem * after )

◆ popchk()

void popchk ( void )

◆ popchk_c()

void popchk_c ( UBYTE * base)
static

◆ pushchk()

void pushchk ( void )

◆ pushchk_c()

void pushchk_c ( UBYTE * base)
static

◆ setstack()

void setstack ( ULONG n)

ItemStackSize Max Items: a new item stack.

Frees the old stack (memlib globfree), allocates n*8 bytes (globalloc, MEMF_PUBLIC); the stack is empty afterwards.

Parameters
nd0: the number of entries

◆ unlinkitem()

BL_ALWAYS_INLINE void unlinkitem ( struct bb_listitem * item)

Variable Documentation

◆ currsp

struct stackentry* currsp
static

◆ currstack

struct stackentry* currstack
static

◆ maxstack

ULONG maxstack
static