|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "blitzlib.h"#include "blitzexec.h"#include <exec/execbase.h>#include <dos/dos.h>#include <dos/dosextens.h>#include <intuition/intuition.h>#include <prefs/font.h>#include <proto/dos.h>#include <proto/intuition.h>Macros | |
| #define | __NOLIBBASE__ |
| #define | DOS_BASE_NAME dosbase_ |
| #define | INTUITION_BASE_NAME intuibase |
| #define | BL_ID4(a, b, c, d) |
| #define | FONTBUF 16384 |
| #define | FONTCHUNK 164 /* "FONT", size, struct FontPrefs */ |
| #define | CIAA_PRA (*(volatile UBYTE *)0xbfe001) |
| #define | CIAA_TODLOW (*(volatile UBYTE *)0xbfe801) |
| #define | CIAA_TODMID (*(volatile UBYTE *)0xbfe901) |
| #define | CIAA_TODHI (*(volatile UBYTE *)0xbfea01) |
Functions | |
| void | _resettimer (void) |
| void | _getsigbit (void) |
| void | _iswbhere (void) |
| void | _doeasy (void) |
| void | _doeasy2 (void) |
| void | _doeasy3 (void) |
| void | _doeasy4 (void) |
| void | _doflip (void) |
| void | _parseinit (void) |
| void | rimisclib_nextparsearg (void) |
| void | _ezoutput (void) |
| void | _ezoutput2 (void) |
| void | _doeasy6 (void) |
| void | _doeasysep (void) |
| void | _doclickwait (void) |
| void | _doprogpath (void) |
| void | _doprogdir (void) |
| void | _doprogname (void) |
| void | _fromblitz (void) |
| void | _ltos (void) |
| void | _ascraw (void) |
| void | _rawasc (void) |
| void | _openfontprefs (void) |
| void | _closefontprefs (void) |
| void | _defaultfontheight (void) |
| void | _defaultfontname (void) |
| void | _nextparseuntilchar (void) |
| void | _binstr (void) |
| void | rimisclib_libinit (void) |
| void | rimisclib_libfinit (void) |
| void | ezargschk (void) |
| void | ezreqargschk (void) |
| void | ezgad3chk (void) |
| void | ezgad2chk (void) |
| static ULONG | copyout (const UBYTE *s) |
| static ULONG | libinit_c (void) |
| init: open dos.library and intuition.library (any version). | |
| static ULONG | closefontprefs_c (void) |
| CloseFontPrefs: free the font prefs buffer of OpenFontPrefs. | |
| static void | libfinit_c (void) |
| finit: close intuition.library (if open) and dos.library, free the font prefs buffer. | |
| static void | resettimer_c (void) |
| TimerReset: set the CIA-A TOD counter to 0. | |
| static void | doclickwait_c (void) |
| ClickWait: wait for a click of the left mouse button. | |
| static ULONG | getsigbit_c (const struct MsgPort *port) |
| PortSigBit(msgport): the signal bit of a message port. | |
| static BB_BOOL | iswbhere_c (void) |
| WorkbenchHere: whether a screen's title contains "Workbench". | |
| static BB_BOOL | fromblitz_c (void) |
| FromBlitz: whether the program runs from Blitz (the task name starts with "Blitz ][ Program Proc"). | |
| static ULONG | ltos_c (ULONG v) |
| LtoS(longword): a long as a string of its 4 bytes. | |
| static ULONG | ascraw_c (UWORD key) |
| ASCRaw(rawkey): the character of a raw key code. | |
| static ULONG | rawasc_c (const UBYTE *s) |
| RawASC(char): the raw key code of a character. | |
| static ULONG | doflip_c (const ULONG *lens) |
| Flip$(String$): the string reversed. | |
| static ULONG | binstr_c (const UBYTE *src, const UBYTE *find, const ULONG *lens) |
| BInstr(String$,Findstring$): the position of the last Findstring$ in String$. | |
| static void | parseinit_c (const UBYTE *s) |
| InitArgParse parameter$: start parsing a string with NextArg$ / NextArgChar$. | |
| static ULONG | nextparsearg_c (void) |
| NextArg$: the next word of the InitArgParse string. | |
| static ULONG | nextparseuntilchar_c (UBYTE ch) |
| NextArgChar$ char: the InitArgParse string up to a character. | |
| static ULONG | fmtbytes (const UBYTE *f) |
| static UBYTE * | ezformat (const UBYTE *f, APTR args, ULONG *size) |
| static UWORD | ezitext (struct IntuiText *it, UBYTE *s, WORD top, struct IntuiText *next) |
| static ULONG | doeasy13 (void) |
| static ULONG | doeasybegin (void) |
| static LONG | quicktrunc (ULONG q) |
| static LONG | ffptrunc (ULONG f) |
| static void | doargs (const UBYTE *sp, UWORD cnt, UBYTE *fmt) |
| static ULONG | doeasy_c (STRPTR title, STRPTR body, STRPTR gadget) |
| EZRequest title$,body$,gadget$: an EasyRequest on the EZOutput window ('|' in the body: a line feed). | |
| static ULONG | doeasy2_c (STRPTR body, STRPTR gadget) |
| EZRequest body$,gadget$: an EasyRequest without a title. | |
| static ULONG | doeasy3_c (STRPTR body) |
| EZRequest body$: an EasyRequest without a title, gadget "Ok". | |
| static ULONG | doeasy4_c (STRPTR title, STRPTR body, STRPTR gadget, UBYTE *args, UWORD reps) |
| EZRequest title$,body$,gadget$,var..: an EasyRequest with the arguments as the format arguments. | |
| static ULONG | doeasy6_c (UBYTE *args, ULONG reps) |
| EZRequestArgs args..: an EasyRequest whose body is built from the arguments. | |
| static void | ezoutput_c (struct Window **w) |
| EZOutput win#: the window of the EZRequests. | |
| static void | ezoutput2_c (void) |
| EZOutput: the EZRequests on the default screen again (no window). | |
| static void | doeasysep_c (const UBYTE *s) |
| EZSeparator char: the separator EZRequestArgs puts between the arguments (default '|', a line feed). | |
| static void | dirpath13 (UBYTE *buf) |
| static void | progname13 (UBYTE *buf) |
| static ULONG | doprogpath_c (void) |
| ProgPath$: the program's directory and name. | |
| static ULONG | doprogdir_c (void) |
| ProgDir$: the program's directory. | |
| static ULONG | doprogname_c (void) |
| ProgName$: the program's name. | |
| static BB_BOOL | openfontprefs_c (void) |
| OpenFontPrefs: read ENV:SYS/Font.Prefs into a 16K buffer. | |
| static const struct FontPrefs * | findfont (UWORD type) |
| static ULONG | defaultfontheight_c (ULONG type) |
| DefaultFontHeight(fonttype): the height of a font of the font prefs (OpenFontPrefs). | |
| static ULONG | defaultfontname_c (UWORD type) |
| DefaultFontName(fonttype): the name of a font of the font prefs. | |
| static void | gadchk (const UBYTE *g) |
| static ULONG | argbytes (const UBYTE *sp, UWORD cnt) |
| static void | ezargschk_c (const UBYTE *args, UWORD reps, const UBYTE *gadget) |
| The error check of EZRequest title$,body$,gadget$,var.. (debugger only). | |
| static void | ezgad3chk_c (const UBYTE *gadget) |
| The error check of EZRequest title$,body$,gadget$ (debugger only). | |
| static void | ezgad2chk_c (const UBYTE *gadget) |
| The error check of EZRequest body$,gadget$ (debugger only). | |
| static void | ezreqargschk_c (const UBYTE *args, UWORD reps) |
| The error check of EZRequestArgs args.. (debugger only). | |
Variables | |
| static struct DosLibrary * | dosbase_ |
| static struct IntuitionBase * | intuibase |
| static const char | dosname [] = "dos.library" |
| static const char | intuiname [] = "intuition.library" |
| static UBYTE * | fontpos |
| static UBYTE * | fontloc |
| static ULONG | fontlen |
| static BPTR | fontfh |
| static const char | fontname [] = "ENV:SYS/Font.Prefs" |
| struct { | |
| UBYTE guard0 [2] | |
| UBYTE rawprogname [256] | |
| UBYTE guard1 [2] | |
| UBYTE progname [256] | |
| UBYTE guard2 [2] | |
| UBYTE progdir [256] | |
| } | pd |
| static UBYTE * | parseadr |
| static UBYTE * | curadr |
| static UBYTE | argbuffer [256] |
| struct { | |
| struct EasyStruct es | |
| APTR args | |
| ULONG args2 [16] | |
| } | ez = { { 20, 0, NULL, NULL, NULL }, NULL, { 0 } } |
| static UBYTE | ezargsbuf [160] |
| static ULONG | numargs |
| static UBYTE | flag |
| static UBYTE | sep = '|' |
| static UBYTE * | ezfirst |
| static struct Window * | win |
| static const char | okgad [] = "Ok" |
| static const UBYTE * | thisscreen |
| static const char | titlestring [] = "Workbench" |
| static const char | procname [] = "Blitz ][ Program Proc" |
| static const UBYTE | rawtable [114] |
| static const UWORD | ez_putch [] = { 0x16c0, 0x4e75 } |
| static const UWORD | ez_countch [] = { 0x5293, 0x4e75 } |
| static struct TextAttr | topaz8 = { (STRPTR)"topaz.font", 8, FS_NORMAL, FPF_ROMFONT } |
| #define __NOLIBBASE__ |
| #define CIAA_PRA (*(volatile UBYTE *)0xbfe001) |
| #define CIAA_TODHI (*(volatile UBYTE *)0xbfea01) |
| #define CIAA_TODLOW (*(volatile UBYTE *)0xbfe801) |
| #define CIAA_TODMID (*(volatile UBYTE *)0xbfe901) |
| #define DOS_BASE_NAME dosbase_ |
| #define FONTBUF 16384 |
| #define FONTCHUNK 164 /* "FONT", size, struct FontPrefs */ |
| #define INTUITION_BASE_NAME intuibase |
| void _ascraw | ( | void | ) |
| void _binstr | ( | void | ) |
| void _closefontprefs | ( | void | ) |
| void _defaultfontheight | ( | void | ) |
| void _defaultfontname | ( | void | ) |
| void _doclickwait | ( | void | ) |
| void _doeasy | ( | void | ) |
| void _doeasy2 | ( | void | ) |
| void _doeasy3 | ( | void | ) |
| void _doeasy4 | ( | void | ) |
| void _doeasy6 | ( | void | ) |
| void _doeasysep | ( | void | ) |
| void _doflip | ( | void | ) |
| void _doprogdir | ( | void | ) |
| void _doprogname | ( | void | ) |
| void _doprogpath | ( | void | ) |
| void _ezoutput | ( | void | ) |
| void _ezoutput2 | ( | void | ) |
| void _fromblitz | ( | void | ) |
| void _getsigbit | ( | void | ) |
| void _iswbhere | ( | void | ) |
| void _ltos | ( | void | ) |
| void _nextparseuntilchar | ( | void | ) |
| void _openfontprefs | ( | void | ) |
| void _parseinit | ( | void | ) |
| void _rawasc | ( | void | ) |
| void _resettimer | ( | void | ) |
|
static |
|
static |
ASCRaw(rawkey): the character of a raw key code.
From the original's table of 114 entries; a key outside 0..113 (a key up code, a negative value) gives the character 0, as the table's keys without a character do. Fixed (#744): the original did not check the code and read behind (or before) the table.
| key | d0.w: the raw key code |
|
static |
BInstr(String$,Findstring$): the position of the last Findstring$ in String$.
Searches backwards. DIFF: a2 and a3 stay unchanged (the original leaves them on the strings).
| src | d0: String$ |
| find | d1: Findstring$ |
| lens | a2: the argument stack, -4(a2) the length of String$ |
|
static |
CloseFontPrefs: free the font prefs buffer of OpenFontPrefs.
|
static |
|
static |
DefaultFontHeight(fonttype): the height of a font of the font prefs (OpenFontPrefs).
| type | d0.w: fp_Type (0 icon, 1 system, 2 screen) |
|
static |
DefaultFontName(fonttype): the name of a font of the font prefs.
| type | d0.w: fp_Type (0 icon, 1 system, 2 screen) |
|
static |
|
static |
|
static |
ClickWait: wait for a click of the left mouse button.
Busy waits on CIA-A until the button is pressed, a short delay (DBRA of 12767), until it is released.
|
static |
|
static |
EZRequest body$,gadget$: an EasyRequest without a title.
Fixed (#1027): a3 = body$ afterwards (the original: 0).
| body | d0: the body text |
| gadget | d1: the gadgets |
|
static |
EZRequest body$: an EasyRequest without a title, gadget "Ok".
| body | d0: the body text |
|
static |
EZRequest title$,body$,gadget$,var..: an EasyRequest with the arguments as the format arguments.
See doargs; no limit of the 16 argument longs (an invalid argument: ezargschk, fixed #748). Quick and Float arguments: their integer part (fixed #750, #749). Fixed (#1027): a3 = title$ afterwards (the original: the argument array).
| title | d0: the title |
| body | d1: the body (format) text |
| gadget | d2: the gadgets |
| args | a2: the argument stack: the three lengths, below them the repeated arguments |
| reps | d7.w: the number of arguments |
|
static |
EZRequestArgs args..: an EasyRequest whose body is built from the arguments.
s / ld / d per type, separated by the EZSeparator character ('|': a line feed), gadget "Ok", no title. Fixed (#747): the format text ends with a 0 (the original wrote none, a shorter text kept the end of the one before). No limit of the arguments (an invalid argument: ezreqargschk, fixed #748); BUG(orig): without arguments a type word is read from a2 and the count 0 runs the loop 65536 times (#746). Quick/Float: their integer part (fixed #750, #749). Fixed (#1027): a3 = the first string argument afterwards, unchanged without one (the original: the argument array).
| args | a2: the argument stack, the repeated arguments |
| reps | d7.w: the number of arguments |
|
static |
EZRequest title$,body$,gadget$: an EasyRequest on the EZOutput window ('|' in the body: a line feed).
DIFF: a2 stays (the original: 0). Fixed (#1027): a3 = title$ afterwards (the original: 0).
| title | d0: the title |
| body | d1: the body text |
| gadget | d2: the gadgets ('|' separated) |
|
static |
|
static |
EZSeparator char: the separator EZRequestArgs puts between the arguments (default '|', a line feed).
| s | d0: the string, its first character |
|
static |
Flip$(String$): the string reversed.
Reversed in place: the argument is the string below a3, a3 stays. A string of 0 or 1 characters stays as it is. Fixed (#751): the original swapped 65536 byte pairs around it (DBRA with -1).
| lens | a2: the argument stack, -4(a2) the length of the string |
|
static |
ProgDir$: the program's directory.
Calls ProgPath$ only while its buffer is empty (the directory does not change). a3 ends on the 0 (fixed, #743).
|
static |
ProgName$: the program's name.
Calls ProgPath$ only while its buffer is empty. a3 ends on the 0 (fixed, #743).
|
static |
ProgPath$: the program's directory and name.
GetProgramDir (without one: the current directory) and GetProgramName (empty: the task name); fills the buffers of ProgDir$ and ProgName$. a3 ends on the 0 of the result (fixed, #743: the original left it behind the 0). Without a directory name the result is the name alone; fixed (#758): the original decided on the "/" by the byte before the result. "/" is added unless the directory ends in ":". Below dos V36 (Kickstart 1.x has none of the four functions; fixed #1150, the original called them there, behind dos's jump table): the current directory, its path built by the library (dirpath13), and the shell's command name (cli_CommandName; without a shell the task name). A program started with a path from another directory gets the current directory there, not its own.
| void ezargschk | ( | void | ) |
|
static |
The error check of EZRequest title$,body$,gadget$,var.. (debugger only).
Fixed (#748), not in the original (neither form limits its arguments; the library had no error check area): arguments that take more than the 64 bytes of the argument array (16 longs), which doargs would write behind it. The release code is unchanged (the number of arguments is in the program's source).
Fixed (#1150): below intuition V36 also more than two gadgets, as ezgad3chk.
Errors: "Too Many EZRequest Arguments"; "More than two EZRequest gadgets need Kickstart 2.0".
| args | a2: the argument stack: the three lengths, below them the repeated arguments |
| reps | d7.w: the number of arguments |
| gadget | d2: the gadgets |
|
static |
| void ezgad2chk | ( | void | ) |
|
static |
The error check of EZRequest body$,gadget$ (debugger only).
As ezgad3chk (fixed #1150).
Errors: "More than two EZRequest gadgets need Kickstart 2.0".
| gadget | d1: the gadgets |
| void ezgad3chk | ( | void | ) |
|
static |
The error check of EZRequest title$,body$,gadget$ (debugger only).
Fixed (#1150), not in the original (it called EasyRequestArgs also on Kickstart 1.x, a crash): below intuition V36 more than two gadgets, which the library's AutoRequest cannot show (the release code shows no requester and returns 0).
Errors: "More than two EZRequest gadgets need Kickstart 2.0".
| gadget | d2: the gadgets |
|
static |
|
static |
EZOutput: the EZRequests on the default screen again (no window).
|
static |
EZOutput win#: the window of the EZRequests.
| w | a0: the window object (windowslib, ia0|pd0), its first long the Window |
| void ezreqargschk | ( | void | ) |
|
static |
The error check of EZRequestArgs args.. (debugger only).
As ezargschk (fixed #748): more than 64 bytes of arguments. Within 64 bytes the format text cannot overflow its 160 bytes (at most 32 words, 3 bytes each with the separator: 96).
Errors: "Too Many EZRequest Arguments".
| args | a2: the argument stack, the repeated arguments |
| reps | d7.w: the number of arguments |
|
static |
|
static |
|
static |
|
static |
FromBlitz: whether the program runs from Blitz (the task name starts with "Blitz ][ Program Proc").
Compares bytes (DIFF: the original's CMPM.l is an address error at an odd task name on a 68000).
|
static |
|
static |
PortSigBit(msgport): the signal bit of a message port.
| port | d0: the MsgPort |
|
static |
WorkbenchHere: whether a screen's title contains "Workbench".
Searches the screen titles from the library's IntuitionBase (FirstScreen) up to the end of the list, each title from every character on; a screen without a title is skipped. Fixed (#759): the original took IntuitionBase from d0, which is no argument (MOVE.l intuibase,a0 overwritten by MOVE.l d0,a0). Fixed (#761): the original never ends the screen list (no 0 check: it reads the "screen" at address 0 and goes on), so it returned BB_TRUE or hung, never BB_FALSE. Fixed (#762): the original restarted the same title when it ended during a partial match, for ever for a title that ends with the start of "Workbench". Fixed (#760): the original went on with the next screen at the first mismatch after a "W" ("A Window on Workbench" was not found).
|
static |
finit: close intuition.library (if open) and dos.library, free the font prefs buffer.
The bases are not cleared (no defect: nothing uses them after finit).
|
static |
init: open dos.library and intuition.library (any version).
No font prefs buffer yet.
|
static |
LtoS(longword): a long as a string of its 4 bytes.
Highest byte first, written to a3 without a 0. The bytes 0-31 and 128-255 become 128 (a signed CMPI.b #32), the documented "non-ASCII characters are replaced with character 128" (no defect, #753).
| v | d0: the long |
|
static |
NextArg$: the next word of the InitArgParse string.
Leading spaces are skipped; quotes group (a quoted word ends at the closing quote even if no space follows, as ReadItem does), "" inside quotes is a quote. The word goes to a3 without a 0 (none needed, #257). The parse position stays on the 0 at the end of the string. Fixed (#755): the original counts the quotes (d7) and ends the word at an even count unless a quote follows; "" moved the count on by one only, so the quote behind it copied the next character (possibly the 0, stepping behind it). A quote now ends the word unless a quote follows, which is copied once.
|
static |
NextArgChar$ char: the InitArgParse string up to a character.
Everything up to char (or the end) to a3, without a 0; the parse position goes behind char. Before InitArgParse and after NextArg$ came to the end the result is "", as NextArg$'s. Fixed (#754): the original did not check the parse pointer and read from address 0.
| ch | d0.b: the character |
|
static |
OpenFontPrefs: read ENV:SYS/Font.Prefs into a 16K buffer.
Without memory for the buffer it returns BB_FALSE; fixed (#756): the original did not check AllocMem and read the file to address 0. The buffer of an OpenFontPrefs before is freed first; fixed (#757): the original lost it. Fixed (#745): the chunks are read within the bytes read (the original ignored Read's result and took the PRHD size unchecked; a read error is a failed open now).
|
static |
InitArgParse parameter$: start parsing a string with NextArg$ / NextArgChar$.
Copies at most 255 characters of it and a 0 into the 256 byte buffer; the rest of a longer string is cut off. Fixed (#752): the original copies without a limit and clears four more bytes behind the copy, an end guard for NextArg$, which stepped behind the 0 (it stays on it since #755).
| s | d0: the string |
|
static |
|
static |
|
static |
RawASC(char): the raw key code of a character.
The first index of the string's first character in the table; -1 for a character not in the table and for "" (as Asc gives -1 for ""). Fixed (#744): the original searched on behind the table until it found the byte somewhere (or for ever), and found "" (its 0) at 14.
| s | d0: the string |
|
static |
TimerReset: set the CIA-A TOD counter to 0.
Writing the high byte stops it, the low byte starts it again.
| void rimisclib_libfinit | ( | void | ) |
| void rimisclib_libinit | ( | void | ) |
| void rimisclib_nextparsearg | ( | void | ) |
|
static |
| APTR args |
| ULONG args2[16] |
|
static |
|
static |
|
static |
| struct EasyStruct es |
| struct { ... } ez |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
| UBYTE guard0[2] |
| UBYTE guard1[2] |
| UBYTE guard2[2] |
|
static |
|
static |
|
static |
|
static |
|
static |
| struct { ... } pd |
|
static |
| UBYTE progdir[256] |
| UBYTE progname[256] |
| UBYTE rawprogname[256] |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |