BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
riapplib.c File Reference
#include "blitzlib.h"
#include "blitzexec.h"
#include <exec/ports.h>
#include <workbench/workbench.h>
#include <workbench/startup.h>
#include <proto/dos.h>
#include <proto/wb.h>
#include <proto/icon.h>

Data Structures

struct  appblock

Macros

#define __NOLIBBASE__
#define DOS_BASE_NAME   dosbase
#define WB_BASE_NAME   wbbase
#define ICON_BASE_NAME   iconbase
#define BLOCKSIZE   768 /* 192 + 512 + 64 */
#define NO_POS   0x80000000UL /* NO_ICON_POSITION */

Functions

void addwindow (void)
void delwindow (void)
void addmenu (void)
void delmenu (void)
void addicon (void)
void addicon3 (void)
void delicon (void)
void appevent (void)
void appeventcode (void)
void appeventid (void)
void appfile (void)
void appfilemine (void)
void appfiles (void)
void applock (void)
void appmessage (void)
void appmsgport (void)
void appeventidcmp (void)
 AppEventIDCMP: the value AppEvent returns for a message, $800000 (inline: MOVE.l $800000,d0; also in Blitz mode).
void riapplib_libinit (void)
void riapplib_libfinit (void)
void idchk (void)
void winchk (void)
void delwinchk (void)
static void closelibs (void)
static void libinit_c (void)
 init: workbench, dos and icon.library V37, then the message port and the block (768 bytes, MEMF_CLEAR).
static void delapp (ULONG *table, int kind)
static void libfinit_c (void)
 finit: replies the messages, removes every App object, deletes the port, frees the block and closes the libraries.
static ULONG appmsgport_c (void)
 AppMsgPort: the library's message port.
static ULONG appmessage_c (void)
 AppMessage: the current AppMessage (of the last AppEvent).
static ULONG applock_c (void)
 AppLock: the lock of the current AppFile, the argument NextAppFile or AppFile read last (the first argument before any read).
static ULONG appevent_c (void)
 AppEvent: replies to the current message and gets the next one.
static ULONG appfiles_c (void)
 AppNumFiles: the number of arguments (am_NumArgs) of the current message.
static ULONG appeventid_c (void)
 AppEventID: the id (am_ID) of the current message.
static ULONG appeventcode_c (void)
 AppEventType: the kind of the current message.
static ULONG appfile_c (void)
 NextAppFile: the full path of the current message's next argument, at a3.
static ULONG appfilemine_c (LONG num)
 AppFile(num): the full path of argument num (1 = the first), as NextAppFile; NextAppFile's position stays.
static BB_BOOL delmenu_c (LONG id)
 DelAppMenu(id): removes the App menu item with this id.
static BB_BOOL addmenu_c (LONG id, STRPTR text)
 AddAppMenu(id,text$): adds an item to Workbench's Tools menu.
static BB_BOOL addicon_c (LONG id, STRPTR text, STRPTR name)
 AddAppIcon (after the libflag test): the icon from GetDiskObject(filename$) at iconx/icony, added as an App icon.
static BB_BOOL addicon2_c (LONG id, STRPTR text, STRPTR name)
 AddAppIcon(id,text$,filename$): an App icon at a position of Workbench's choice (NO_ICON_POSITION).
static BB_BOOL addicon3_c (LONG id, STRPTR text, STRPTR name, ULONG x, ULONG y)
 AddAppIcon(id,text$,filename$,x,y): an App icon at x,y.
static BB_BOOL delicon_c (LONG id)
 DelAppIcon(id): removes the App icon and frees its DiskObject.
static BB_BOOL addwindow_c (struct Window **wobj, const ULONG *args)
 AddAppWindow(windownumber): makes a window an App window (id = the window number).
static BB_BOOL delwindow_c (LONG n)
 DelAppWindow(windownumber): removes the App window.
static void idchk_c (ULONG id)
 The error check of the commands with an id (debugger only): AddAppMenu, DelAppMenu, AddAppIcon (both forms) and DelAppIcon.
static void winchk_c (const ULONG *args)
 The error check of AddAppWindow (debugger only): its window number is on the argument stack (push), -4(a2).
static void delwinchk_c (ULONG n)
 The error check of DelAppWindow (debugger only).

Variables

static struct Library * wbbase
static struct Library * iconbase
static struct DosLibrary * dosbase
static ULONG * appmenus
static ULONG * appwindows
static ULONG * appicons
static struct DiskObject ** disklist
static UBYTE * arglist
static struct MsgPort * msgport
static UWORD msgtype
static ULONG msgid
static LONG numargs
static LONG libflag
static struct AppMessage * msg
static LONG argnum
static LONG lockarg
static ULONG iconx
static ULONG icony

Macro Definition Documentation

◆ __NOLIBBASE__

#define __NOLIBBASE__

◆ BLOCKSIZE

#define BLOCKSIZE   768 /* 192 + 512 + 64 */

◆ DOS_BASE_NAME

#define DOS_BASE_NAME   dosbase

◆ ICON_BASE_NAME

#define ICON_BASE_NAME   iconbase

◆ NO_POS

#define NO_POS   0x80000000UL /* NO_ICON_POSITION */

◆ WB_BASE_NAME

#define WB_BASE_NAME   wbbase

Function Documentation

◆ addicon()

void addicon ( void )

◆ addicon2_c()

BB_BOOL addicon2_c ( LONG id,
STRPTR text,
STRPTR name )
static

AddAppIcon(id,text$,filename$): an App icon at a position of Workbench's choice (NO_ICON_POSITION).

Fixed (#516): a3 = text$ afterwards on every path (the original: the DiskObject, or behind the arguments).

Parameters
idd0: the id
textd1: the icon's text
named2: the file name of the icon
Returns
d0: BB_TRUE, BB_FALSE on failure

◆ addicon3()

void addicon3 ( void )

◆ addicon3_c()

BB_BOOL addicon3_c ( LONG id,
STRPTR text,
STRPTR name,
ULONG x,
ULONG y )
static

AddAppIcon(id,text$,filename$,x,y): an App icon at x,y.

Fixed (#516): a3 = text$ afterwards, as above.

Parameters
idd0: the id
textd1: the icon's text
named2: the file name of the icon
xd3: x
yd4: y
Returns
d0: BB_TRUE, BB_FALSE on failure

◆ addicon_c()

BB_BOOL addicon_c ( LONG id,
STRPTR text,
STRPTR name )
static

AddAppIcon (after the libflag test): the icon from GetDiskObject(filename$) at iconx/icony, added as an App icon.

Fixed (#517): the slot of the old AppIcon is cleared once it is removed, and a new DiskObject that AddAppIconA did not take is freed (the original left both in their slots). Fixed (#516): a3 and a4 are kept around AddAppIconA.

Parameters
idd0: the id
textd1: the icon's text
named2: the file name of the icon (without .info)
Returns
d0: BB_TRUE, BB_FALSE on failure

◆ addmenu()

void addmenu ( void )

◆ addmenu_c()

BB_BOOL addmenu_c ( LONG id,
STRPTR text )
static

AddAppMenu(id,text$): adds an item to Workbench's Tools menu.

An item with the same id is removed first. The id indexes the table unchecked.

Parameters
idd0: the id
textd1: the item's text
Returns
d0: BB_TRUE, BB_FALSE on failure (fixed, #518: the original returned the AppMenuItem)

◆ addwindow()

void addwindow ( void )

◆ addwindow_c()

BB_BOOL addwindow_c ( struct Window ** wobj,
const ULONG * args )
static

AddAppWindow(windownumber): makes a window an App window (id = the window number).

An App window with the same number is removed first. DIFF: a2 stays unchanged.

Parameters
wobja0: the windowslib object (first long = the Intuition window)
argsa2: the argument stack, -4(a2) = the number (push)
Returns
d0: BB_TRUE, BB_FALSE on failure

◆ appevent()

void appevent ( void )

◆ appevent_c()

ULONG appevent_c ( void )
static

AppEvent: replies to the current message and gets the next one.

Its id, number of arguments and type are kept for AppEventID, AppNumFiles and AppEventType; NextAppFile starts again at the first argument, and AppLock returns the first argument's lock until a read.

Returns
d0: $800000 (AppEventIDCMP) if there is a message, else 0

◆ appeventcode()

void appeventcode ( void )

◆ appeventcode_c()

ULONG appeventcode_c ( void )
static

AppEventType: the kind of the current message.

Returns
d0: 1 AppWindow (am_Type 7), 2 AppIcon (8), 3 AppMenuItem (9), 0 otherwise or if there is no message

◆ appeventid()

void appeventid ( void )

◆ appeventid_c()

ULONG appeventid_c ( void )
static

AppEventID: the id (am_ID) of the current message.

Fixed (#1102): -1 without a current message, as RIAppLib.guide says (the original returned 0, also the id of an object).

Returns
d0: the id, -1 if there is no message (or init failed)

◆ appeventidcmp()

void appeventidcmp ( void )

AppEventIDCMP: the value AppEvent returns for a message, $800000 (inline: MOVE.l $800000,d0; also in Blitz mode).

◆ appfile()

void appfile ( void )

◆ appfile_c()

ULONG appfile_c ( void )
static

NextAppFile: the full path of the current message's next argument, at a3.

NameFromLock of the argument's lock, '/' unless the path ends with ':', then the name. Fixed (#521): the lock (Workbench's) stays in the message (the original unlocked and cleared it unless the path ended with ':'), and an empty path gets no '/' (the original's test read the byte before the string). a3 ends on the 0 (fixed, #519: the original left it behind the 0). The argument becomes AppLock's (fixed, #1103), also if NameFromLock fails.

Returns
d0: the length, 0 if there is no message, no argument left or NameFromLock fails

◆ appfilemine()

void appfilemine ( void )

◆ appfilemine_c()

ULONG appfilemine_c ( LONG num)
static

AppFile(num): the full path of argument num (1 = the first), as NextAppFile; NextAppFile's position stays.

Fixed (#520): num <= 0 is out of range, an empty string (the original read the WBArg before the list).

Parameters
numd0: the argument number
Returns
d0: the length, as NextAppFile

◆ appfiles()

void appfiles ( void )

◆ appfiles_c()

ULONG appfiles_c ( void )
static

AppNumFiles: the number of arguments (am_NumArgs) of the current message.

Returns
d0: the number, 0 if there is no message

◆ applock()

void applock ( void )

◆ applock_c()

ULONG applock_c ( void )
static

AppLock: the lock of the current AppFile, the argument NextAppFile or AppFile read last (the first argument before any read).

Fixed (#1103): the original returned the first argument's lock whatever NextAppFile or AppFile had read; RIAppLib.guide: "the lock associated with the current AppFile". A read that finds no argument (none left, a number out of range) leaves it. Fixed (#522): a message without arguments has no lock (the original read the first WBArg without looking at am_NumArgs).

Returns
d0: the lock, 0 if there is no message or it has no arguments

◆ appmessage()

void appmessage ( void )

◆ appmessage_c()

ULONG appmessage_c ( void )
static

AppMessage: the current AppMessage (of the last AppEvent).

Returns
d0: the message, 0 if none

◆ appmsgport()

void appmsgport ( void )

◆ appmsgport_c()

ULONG appmsgport_c ( void )
static

AppMsgPort: the library's message port.

Returns
d0: the MsgPort, 0 after a failed init (fixed, #526: the original returned the deleted port)

◆ closelibs()

void closelibs ( void )
static

◆ delapp()

void delapp ( ULONG * table,
int kind )
static

◆ delicon()

void delicon ( void )

◆ delicon_c()

BB_BOOL delicon_c ( LONG id)
static

DelAppIcon(id): removes the App icon and frees its DiskObject.

Fixed (#523): FreeDiskObject only for a DiskObject.

Parameters
idd0: the id
Returns
d0: BB_TRUE, BB_FALSE if there is none (or init failed)

◆ delmenu()

void delmenu ( void )

◆ delmenu_c()

BB_BOOL delmenu_c ( LONG id)
static

DelAppMenu(id): removes the App menu item with this id.

The id indexes the table unchecked.

Parameters
idd0: the id
Returns
d0: BB_TRUE, BB_FALSE if there is none (or init failed)

◆ delwinchk()

void delwinchk ( void )

◆ delwinchk_c()

void delwinchk_c ( ULONG n)
static

The error check of DelAppWindow (debugger only).

Fixed (#1097), not in the original: as winchk. The release code is unchanged.

Errors: "App window number must be 0 to 15".

Parameters
nd0: the window number

◆ delwindow()

void delwindow ( void )

◆ delwindow_c()

BB_BOOL delwindow_c ( LONG n)
static

DelAppWindow(windownumber): removes the App window.

Fixed (#523): an empty slot is BB_FALSE without a call (the original called RemoveAppWindow(NULL) and returned BB_TRUE).

Parameters
nd0: the window number
Returns
d0: BB_TRUE, BB_FALSE if there is none (or init failed)

◆ idchk()

void idchk ( void )

◆ idchk_c()

void idchk_c ( ULONG id)
static

The error check of the commands with an id (debugger only): AddAppMenu, DelAppMenu, AddAppIcon (both forms) and DelAppIcon.

Fixed (#1097), not in the original (riapplib had no error check area): the id indexes the tables of 16 entries without a check. The release code is unchanged (an invalid argument).

Errors: "App id must be 0 to 15".

Parameters
idd0: the id

◆ libfinit_c()

void libfinit_c ( void )
static

finit: replies the messages, removes every App object, deletes the port, frees the block and closes the libraries.

Fixed (#525): the current message and then the whole queue are replied (the original replied to the queue only if a message was current). Fixed (#524): the slot of each object is cleared (the original cleared the long at byte offset index*4/4).

◆ libinit_c()

void libinit_c ( void )
static

init: workbench, dos and icon.library V37, then the message port and the block (768 bytes, MEMF_CLEAR).

Sets libflag -1 when all is there, 0 otherwise (the commands then do nothing). Fixed (#1143): the port (CreateMsgPort, exec V36) is made only after the three V37 libraries opened, so on Kickstart 1.x init fails quietly (the original made the port first: behind exec's jump table, a crash at the program's start). Fixed (#526): on a failure the libraries opened before are closed and msgport is cleared (the original left them open and kept the deleted port for AppMsgPort). Fixed (#1099): no current message (the original kept the one of the run before, which its finit had replied to, for a second run from the editor).

◆ riapplib_libfinit()

void riapplib_libfinit ( void )

◆ riapplib_libinit()

void riapplib_libinit ( void )

◆ winchk()

void winchk ( void )

◆ winchk_c()

void winchk_c ( const ULONG * args)
static

The error check of AddAppWindow (debugger only): its window number is on the argument stack (push), -4(a2).

Fixed (#1097), not in the original: a window number of 16 or higher (a valid Blitz window with a larger Maximum) indexed past the AppWindow table into the AppIcon table. The release code is unchanged.

Errors: "App window number must be 0 to 15".

Parameters
argsa2: the argument stack, -4(a2) = the window number

Variable Documentation

◆ appicons

ULONG * appicons
static

◆ appmenus

ULONG* appmenus
static

◆ appwindows

ULONG * appwindows
static

◆ arglist

UBYTE* arglist
static

◆ argnum

LONG argnum
static

◆ disklist

struct DiskObject** disklist
static

◆ dosbase

struct DosLibrary* dosbase
static

◆ iconbase

struct Library * iconbase
static

◆ iconx

ULONG iconx
static

◆ icony

ULONG icony
static

◆ libflag

LONG libflag
static

◆ lockarg

LONG lockarg
static

◆ msg

struct AppMessage* msg
static

◆ msgid

ULONG msgid
static

◆ msgport

struct MsgPort* msgport
static

◆ msgtype

UWORD msgtype
static

◆ numargs

LONG numargs
static

◆ wbbase

struct Library* wbbase
static