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

Data Structures

struct  portnode

Macros

#define PORTBLOCK   0x2a

Functions

void _CreateMsgPort (void)
void _DeleteMsgPort (void)
ULONG _dowait (void)
 Wait - wait for any allocated signal of the task.
void _taskname (void)
void _startup (void)
void utillib_CloseRoutine (void)
void delportchk (void)
static ULONG taskname_c (struct Task *task)
 TaskName$(task) - the name of a task.
 BLITZ_ALIAS (_taskname, taskname_c)
static ULONG startup_c (void)
 init - CLR.l signals:MOVE.l signals,d0.
static struct portnode * findlistend (void)
static ULONG createmsgport_c (const UBYTE *name, const ULONG *lens)
 CreateMsgPort(PortName$) - create a message port.
 BLITZ_ALIAS (_CreateMsgPort, createmsgport_c)
static void deletemsgport_c (struct MsgPort *port)
 DeleteMsgPort *UserPort - delete a port made by CreateMsgPort.
 BLITZ_ALIAS (_DeleteMsgPort, deletemsgport_c)
static void closeroutine_c (void)
static void delportchk_c (const struct MsgPort *port)
 The error check of DeleteMsgPort (debugger only).

Variables

static ULONG signals
struct { 
   struct portnode *   next 
   struct portnode *   prev 
} PortListStart
static const char NoMem [] = "Failed to allocate memory for Port"
static const char NoSig [] = "Failed to allocate signal for Port"

Macro Definition Documentation

◆ PORTBLOCK

#define PORTBLOCK   0x2a

Function Documentation

◆ _CreateMsgPort()

void _CreateMsgPort ( void )

◆ _DeleteMsgPort()

void _DeleteMsgPort ( void )

◆ _dowait()

ULONG _dowait ( void )

Wait - wait for any allocated signal of the task.

Wait(FindTask(0)->tc_SigAlloc) - all allocated signals (not a bug: the intended semantics); the result also goes to signals.

Returns
d0: the signals received

◆ _startup()

void _startup ( void )

◆ _taskname()

void _taskname ( void )

◆ BLITZ_ALIAS() [1/3]

BLITZ_ALIAS ( _CreateMsgPort ,
createmsgport_c  )

◆ BLITZ_ALIAS() [2/3]

BLITZ_ALIAS ( _DeleteMsgPort ,
deletemsgport_c  )

◆ BLITZ_ALIAS() [3/3]

BLITZ_ALIAS ( _taskname ,
taskname_c  )

◆ closeroutine_c()

void closeroutine_c ( void )
static

◆ createmsgport_c()

ULONG createmsgport_c ( const UBYTE * name,
const ULONG * lens )
static

CreateMsgPort(PortName$) - create a message port.

Allocates the $2A byte block (memlib globalloc, MEMF_PUBLIC|MEMF_CLEAR), allocates a signal, initialises the port (PA_SIGNAL, this task) and links it into utillib's port list (freed by the finit). A non-empty name is copied into its own block {size.l, characters, 0} and the port made public (AddPort). Returns with a3 = the name argument ("Protect BB2 String area from corruption") and copies (UWORD)len+1 bytes of the name (DBRA on the length's low word; not a bug: a port name of 64 KB does not occur).

Errors: "Failed to allocate memory for Port" (runtime error; the port block stays allocated if the name allocation fails). DIFF (K, #300): after a returning TRAP #0 the original runs into its message text; the C version returns 0.

Fixed (#298): a failed AllocSignal (-1) frees the block ($2A bytes) and gives the runtime error "Failed to allocate signal for Port" (the original tested for signal 0 and made a port with mp_SigBit $FF; its error path would have freed the port address with $22 bytes).

Parameters
named0: the port name ("" = a private port)
lensa2: the compiler's argument pointer: -4(a2) = the name's length
Returns
d0: the MsgPort (block + 8), 0 after an error (DIFF)

◆ deletemsgport_c()

void deletemsgport_c ( struct MsgPort * port)
static

DeleteMsgPort *UserPort - delete a port made by CreateMsgPort.

RemPort and frees the name if there is one, replies the messages still queued, frees the signal, unlinks the port from utillib's list and frees its block. Keeps all registers.

Fixed (#299): the queued messages are replied (the original freed the port with them); replies that came back to the port (NT_REPLYMSG) are only removed. Errors (debugger only, delportchk): "Port Not Created By CreateMsgPort" (fixed, #1041: the original took any address; without the debugger a port that utillib did not create still corrupts memory, an invalid argument).

Parameters
portd0: the port

◆ delportchk()

void delportchk ( void )

◆ delportchk_c()

void delportchk_c ( const struct MsgPort * port)
static

The error check of DeleteMsgPort (debugger only).

Fixed (#1041), not in the original (DeleteMsgPort took any address): the port must be one of utillib's list, made by CreateMsgPort and not deleted yet.

Errors: "Port Not Created By CreateMsgPort".

Parameters
portd0: the port

◆ findlistend()

struct portnode * findlistend ( void )
static

◆ startup_c()

ULONG startup_c ( void )
static

init - CLR.l signals:MOVE.l signals,d0.

"other libs access using #utillib,#la0 then btst sigbit,(a0)".

Returns
d0: the address of signals, the library's init value

◆ taskname_c()

ULONG taskname_c ( struct Task * task)
static

TaskName$(task) - the name of a task.

Copies the name to a3 including the 0.

Not a bug: a3 is left BEHIND the terminating 0 (no SUBQ #1,a3; no visible effect). Fixed (#297): a task without a name has the empty name (the original copied from address 0).

Parameters
taskd0: the task, 0 = this task (FindTask(0))
Returns
d0: the length of the name; a3 behind its 0

◆ utillib_CloseRoutine()

void utillib_CloseRoutine ( void )

Variable Documentation

◆ next

struct portnode* next

◆ NoMem

const char NoMem[] = "Failed to allocate memory for Port"
static

◆ NoSig

const char NoSig[] = "Failed to allocate signal for Port"
static

◆ [struct]

struct { ... } PortListStart

◆ prev

struct portnode * prev

◆ signals

ULONG signals
static