Skip to Content
Amiga Assembly Library v41.21 — Motorola 68020 shared library for Commodore Amiga

AllocNode

Synopsis

node = AllocNode(list, string, type, pri) D0 A0 A1 D0 D1

C Prototype

struct Node *AllocNode(struct List *list, STRPTR string, ULONG type, LONG pri);

Description

Allocates and initializes a Node structure. If list is not NULL, the node is inserted into the list taking the pri (priority) parameter into account. The insertion is performed using the ENQUEUE macro defined in assembly/asmmacros.i, which performs the same function as exec/Enqueue().

If list is NULL, the node is only allocated and no insertion into a list is performed. In this case, the task is responsible for inserting the node into a list as it sees fit.

Inputs

  • list — Address of a List structure. If NULL, the node will only be allocated and NOT inserted into a list.
  • string — Address to place in LN_NAME. Can be NULL.
  • type — Value to place in LN_TYPE. Can be NULL.
  • pri — Priority to place in LN_PRI. Can be NULL. This parameter is only considered when list is not NULL, and allows priority-based insertion of nodes. See also exec/Enqueue().

Result

  • node — Address of the allocated Node structure. If NULL, an error occurred.

Example

/* Simple usage of AllocNewList() and AllocNode() */ /* to create a label list for a LISTVIEW, using and */ /* not using the priority (pri) parameter */ struct List *list; struct Node *node; list = AllocNewList(); /* Create the list */ node = AllocNode(list, "Last Element", NULL, -5); node = AllocNode(list, "I Element", NULL, 1); node = AllocNode(list, "II Element", NULL, 2); node = AllocNode(list, "IV Element", NULL, 4); /*** this one I manage myself ***/ node = AllocNode(NULL, "???? Element", NULL, 0); /** here you can call whichever function you prefer **/ /** the node has been allocated, but not inserted **/ /** into the list... for example you could use **/ /** AddTail() or AddHead(), etc... **/ node = AllocNode(list, "III Element", NULL, 3); /* etc... as you can see, the priority determines the */ /* position of the node in the list, as long as */ /* list != NULL */

See Also

AllocNewList, FreeNode, FreeList

exec/Enqueue()

Implementation

The original 68020 assembly implementation:

; (13-Jan-1995) --- AllocNode(List,name,type,pri) (a0/a1/d0/d1) _LVOAllocNode movem.l d2-d4/a2-a6,-(sp) move.l a0,a3 ; Save struct List * move.l a1,a2 ; Save STRPTR string move.b d0,d2 ; type move.b d1,d3 ; pri moveq #4+LN_SIZE,d0 ; D0 = SIZEOF move.l d0,d4 ; Save for PackAlloc() moveq #1,d1 swap d1 move.l ab_ExecBase(a6),a6 ; Exec... jsr _LVOAllocMem(a6) tst.l d0 beq.s ANFail ; Can't Alloc Memory... move.l d0,a5 ; A5 = (struct Node *) move.l d4,(a5)+ ; A5 = True address to return... move.b d2,LN_TYPE(a5) ; INITIALIZE THE NODE move.b d3,LN_PRI(a5) move.l a2,LN_NAME(a5) move.l a3,d0 ; Does a List exist?? beq.s ANExit ; No then exit move.l d0,a0 ; List ENQUEUE a5 ANExit move.l a5,d0 ; Result... ANFail movem.l (sp)+,d2-d4/a2-a6 rts
Last updated on