|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "blitzlib.h"#include "blitzobj.h"#include "blitzexec.h"#include "blitzdos.h"#include <dos/dos.h>#include <dos/dosextens.h>#include <dos/doshunks.h>#include <proto/dos.h>Data Structures | |
| struct | hunkitem |
Macros | |
| #define | __NOLIBBASE__ |
| #define | DOS_BASE_NAME dos |
| #define | FIBSIZE |
| #define | ENTRY(tab, n) |
| #define | ISBANK(n) |
| #define | LDF_FINDVOLUME (LDF_READ | LDF_DEVICES | LDF_VOLUMES | LDF_ASSIGNS | LDF_ENTRY) |
Functions | |
| void | _cacheon (void) |
| void | _cacheoff (void) |
| void | _reboot (void) |
| void | _lisa (void) |
| void | _makedir (void) |
| void | _rename (void) |
| void | _memfree (void) |
| void | riamosfunclib_gttags (void) |
| GTTagValue([tagvalue]): GadTools' tag base TAG_USER|$80000 (+ tagvalue in d0) - inline code, copied by the compiler. | |
| void | _gttags2 (void) |
| void | _timer (void) |
| void | _min (void) |
| void | _max (void) |
| void | _copybyte (void) |
| void | _copyword (void) |
| void | _copylong (void) |
| void | _filesize (void) |
| void | _bload4 (void) |
| void | _bload1 (void) |
| void | _bload0 (void) |
| void | _bload (void) |
| void | _bload2 (void) |
| void | _bsave2 (void) |
| void | _bsave (void) |
| void | _start (void) |
| void | _length (void) |
| void | _erase (void) |
| void | _eraseall (void) |
| void | _allocmem2 (void) |
| void | _allocmem1 (void) |
| void | riamosfunclib_allocmem (void) |
| void | _findfreebank (void) |
| void | _nextbank0 (void) |
| void | _fillmemzeros (void) |
| void | _fillmem (void) |
| void | _keycode (void) |
| void | _blitdone (void) |
| void | _blitwait (void) |
| void | riamosfunclib_finddev (void) |
| void | _swapbank (void) |
| void | _getdevname (void) |
| void | _cd (void) |
| void | _banklimit (void) |
| void | _getbanklimit (void) |
| void | _saveexec (void) |
| void | riamosfunclib_libinit (void) |
| void | riamosfunclib_libfinit (void) |
| static void | bloadchk (void) |
| static ULONG | start_c (LONG bank) |
| Start(bank): the address of a bank. | |
| static ULONG | length_c (LONG bank) |
| Length(bank): the length of a bank. | |
| static void | eraseit (LONG bank) |
| static BB_BOOL | newbank (LONG bank, ULONG len, ULONG flags) |
| static void | erase_c (LONG bank) |
| Erase bank: frees a bank (FreeMem) if it is in use. | |
| static void | eraseall_c (void) |
| EraseAll: frees every bank in use, from maxbanks-1 down to 0. | |
| static BB_BOOL | allocmem_c (LONG bank, ULONG len, ULONG flags) |
| Reserve(bank,length,requirements): allocates a bank (exec AllocMem). | |
| static BB_BOOL | allocmem1_c (LONG bank, ULONG len) |
| Reserve(bank,length): as above with MEMF_PUBLIC. | |
| static ULONG | findfreebank_c (LONG bank) |
| NextBank [startbank]: the first free bank from startbank on. | |
| static ULONG | nextbank0_c (void) |
| NextBank: the first free bank (from bank 0). | |
| static ULONG | allocmem2_c (LONG len) |
| Reserve(length): allocates the next free bank (NextBank from 0, MEMF_PUBLIC). | |
| static BB_BOOL | swapbank_c (LONG a, LONG b) |
| SwapBank(sourcebank,destbank): exchanges two banks (address and length). | |
| static void | fillmem_c (ULONG adr, ULONG len, UBYTE v) |
| FillMem address,length,value: fills memory (or a bank) with a byte. | |
| static void | fillmemzeros_c (ULONG adr, ULONG len) |
| FillMem address,length: as above with 0. | |
| static ULONG | libinit_c (void) |
| init: opens dos.library and allocates the bank tables. | |
| static void | finitbanks (void) |
| static void | libfinit_c (void) |
| finit: makes the directory the first ChangeDir replaced current again, unlocks ChangeDir's lock, frees every bank and the tables, closes dos.library. | |
| static ULONG | banklimit_c (LONG n) |
| BankLimit numbanks: a new number of banks - finit (every bank freed), the new number, init. | |
| static ULONG | getbanklimit_c (void) |
| BankLimit: the number of banks (50 at the start). | |
| static ULONG | filesize_c (CONST_STRPTR name) |
| FileSize(filename$): the size of a file. | |
| static BB_BOOL | bload2_c (CONST_STRPTR name, ULONG adr, ULONG len, LONG offset, ULONG memtype) |
| BLoad(filename$,address,length,offset,memtype): loads a file (or a part of it) to an address or into a bank. | |
| static BB_BOOL | bload_c (CONST_STRPTR name, ULONG adr, ULONG len, LONG offset) |
| BLoad(filename$,address,length,offset): as above, memtype 0. | |
| static BB_BOOL | bload0_c (CONST_STRPTR name, ULONG adr, ULONG len) |
| BLoad(filename$,address,length): as above from the start of the file, memtype 0. | |
| static BB_BOOL | bload1_c (CONST_STRPTR name, ULONG adr) |
| BLoad(filename$,address): the whole file to an address or into a bank (memtype 0). | |
| static ULONG | bload4_c (CONST_STRPTR name) |
| BLoad(filename$): loads a file into a new bank (Reserve(length)). | |
| static BB_BOOL | bsave_c (CONST_STRPTR name, ULONG adr, ULONG len) |
| BSave(filename$,address/bank,length): writes memory (or a bank) to a file. | |
| static BB_BOOL | bsave2_c (CONST_STRPTR name, ULONG adr) |
| BSave(filename$,bank): writes a whole bank (an address: nothing). | |
| static BB_BOOL | makedir_c (CONST_STRPTR name) |
| MakeDir(dirname$): creates a directory (dos CreateDir) and gives its lock back. | |
| static ULONG | rename_c (CONST_STRPTR from, CONST_STRPTR to) |
| Rename(oldfilename$,newfilename$): renames a file (dos Rename). | |
| static BB_BOOL | cd_c (CONST_STRPTR name) |
| ChangeDir dir$: makes a directory the current one (CurrentDir(Lock(dir$))). | |
| static ULONG | finddev_c (CONST_STRPTR name) |
| FindVolume(volumename): whether a device, volume or assign of that name is present (FindDosEntry). | |
| static ULONG | devname (const struct DosList *dl) |
| static ULONG | getdevname_c (const ULONG *lens) |
| DeviceName$(volumename$): the name of the handler task of a device or volume, with ":" (AmiBlitz3's version). | |
| static ULONG | hunklongs (const struct hunkitem *h) |
| static ULONG | execinit (CONST_STRPTR name, const struct hunkitem *h, ULONG n) |
| static void | docode (const struct hunkitem *h, ULONG num) |
| static ULONG | saveexec_c (CONST_STRPTR name, const UBYTE *list) |
| SaveExec filename$,list(): writes an executable from a Blitz list of NEWTYPE .hunk (code hunks with RELOC32). | |
| static ULONG | cacheon_c (ULONG mask) |
| CachesOn bitmask: switches caches on (exec CacheControl(bitmask,bitmask)). | |
| static ULONG | cacheoff_c (ULONG mask) |
| CachesOff bitmask: switches caches off (exec CacheControl(0,bitmask)). | |
| void | riamosfunclib_oldreboot (void) |
| static void | reboot_c (void) |
| Reboot: a cold reboot (exec ColdReboot); does not return. | |
| static ULONG | memfree_c (void) |
| MemFree: the free public memory (AvailMem(MEMF_PUBLIC)). | |
| static ULONG | lisa_c (ULONG result) |
| Lisa: the Lisa (Denise) chip version, DENISEID ($DFF07C). | |
| static ULONG | timer_c (void) |
| Timer: the CIA-A TOD counter (vertical blanks). | |
| static ULONG | keycode_c (void) |
| KeyCode: the raw keyboard byte of CIA-A SDR ($BFEC01). | |
| static BB_BOOL | blitdone_c (void) |
| BlitterDone: whether the blitter is idle (one BTST of DMACONR's BBUSY, no Agnus wait). | |
| static void | blitwait_c (void) |
| WaitBlitter: waits until the blitter is idle (DMACONR's BBUSY). Returns nothing (all registers kept). | |
| static LONG | max_c (LONG a, LONG b) |
| Max(a,b): the larger of two signed longs. | |
| static LONG | min_c (LONG a, LONG b) |
| Min(a,b): the smaller of two signed longs. | |
| static ULONG | copybyte_c (const UBYTE *src, UBYTE *d, LONG n) |
| CopyByte sourceaddr,destaddr,bytes: copies bytes, ascending. | |
| static ULONG | copyword_c (const UWORD *src, UWORD *d, LONG n) |
| CopyWord sourceaddr,destaddr,words: copies words, ascending. | |
| static ULONG | copylong_c (const ULONG *src, ULONG *d, LONG n) |
| CopyLong sourceaddr,destaddr,longs: copies longs, ascending. | |
Variables | |
| static ULONG * | lenptr |
| static ULONG * | startptr |
| static LONG | maxbanks = 50 |
| static BPTR | oldlock |
| static BPTR | startdir |
| static BOOL | startkept |
| static struct DosLibrary * | dosbase_ |
| static const char | dosname [] = "dos.library" |
| static BPTR | fh |
| static ULONG | hunkbuff [8] |
| #define __NOLIBBASE__ |
| #define DOS_BASE_NAME dos |
| #define FIBSIZE |
| #define ISBANK | ( | n | ) |
| #define LDF_FINDVOLUME (LDF_READ | LDF_DEVICES | LDF_VOLUMES | LDF_ASSIGNS | LDF_ENTRY) |
| void _allocmem1 | ( | void | ) |
| void _allocmem2 | ( | void | ) |
| void _banklimit | ( | void | ) |
| void _blitdone | ( | void | ) |
| void _blitwait | ( | void | ) |
| void _bload | ( | void | ) |
| void _bload0 | ( | void | ) |
| void _bload1 | ( | void | ) |
| void _bload2 | ( | void | ) |
| void _bload4 | ( | void | ) |
| void _bsave | ( | void | ) |
| void _bsave2 | ( | void | ) |
| void _cacheoff | ( | void | ) |
| void _cacheon | ( | void | ) |
| void _cd | ( | void | ) |
| void _copybyte | ( | void | ) |
| void _copylong | ( | void | ) |
| void _copyword | ( | void | ) |
| void _erase | ( | void | ) |
| void _eraseall | ( | void | ) |
| void _filesize | ( | void | ) |
| void _fillmem | ( | void | ) |
| void _fillmemzeros | ( | void | ) |
| void _findfreebank | ( | void | ) |
| void _getbanklimit | ( | void | ) |
| void _getdevname | ( | void | ) |
| void _gttags2 | ( | void | ) |
| void _keycode | ( | void | ) |
| void _length | ( | void | ) |
| void _lisa | ( | void | ) |
| void _makedir | ( | void | ) |
| void _max | ( | void | ) |
| void _memfree | ( | void | ) |
| void _min | ( | void | ) |
| void _nextbank0 | ( | void | ) |
| void _reboot | ( | void | ) |
| void _rename | ( | void | ) |
| void _saveexec | ( | void | ) |
| void _start | ( | void | ) |
| void _swapbank | ( | void | ) |
| void _timer | ( | void | ) |
|
static |
|
static |
Reserve(length): allocates the next free bank (NextBank from 0, MEMF_PUBLIC).
Fixed (#498): -1 when every bank is in use; the original tested only the sign of the length and reserved "bank -1". Fixed (#500): -1 for a negative length; the original returned 0, a bank number.
| len | d0: the length |
|
static |
Reserve(bank,length,requirements): allocates a bank (exec AllocMem).
A bank in use is erased first, also when the new allocation fails (#499). Fixed (#484): 0 for a bank outside 0..maxbanks-1; the original did not check - bank >= maxbanks wrote behind the start table, a negative bank before the tables.
|
static |
BankLimit numbanks: a new number of banks - finit (every bank freed), the new number, init.
Fixed (#483): returns the new number of banks; the original returned the address of the new start table (init's d0). Fixed (#491): the current directory and ChangeDir's lock stay; the original unlocked the lock as finit does, while it was current.
| n | d0: numbanks |
|
static |
BlitterDone: whether the blitter is idle (one BTST of DMACONR's BBUSY, no Agnus wait).
|
static |
WaitBlitter: waits until the blitter is idle (DMACONR's BBUSY). Returns nothing (all registers kept).
|
static |
|
static |
BLoad(filename$,address): the whole file to an address or into a bank (memtype 0).
| name | d0: filename$ |
| adr | d1: the address or bank |
|
static |
BLoad(filename$,address,length,offset,memtype): loads a file (or a part of it) to an address or into a bank.
Length 0 = the file's size (0 for an empty or missing file). A number from 0 to maxbanks-1 is a bank: erased and reserved anew with that length and memtype (#499); anything else is an address (fixed, #484: the original compared signed). The file is opened first: one that cannot be opened leaves the bank as it was (fixed, #487: the original erased and reserved the bank first and left it so). A failed read (Read's -1) is 0 (fixed, #488: the original tested for 0 only; a short read stays success: a length beyond the file is a valid call). The error check is switched off (#485, not a defect: see bloadchk).
| name | d0: filename$ |
| adr | d1: the address or bank |
| len | d2: the number of bytes |
| offset | d3: the start in the file (0 = from the start) |
| memtype | d4: the memory type of a bank |
|
static |
BLoad(filename$): loads a file into a new bank (Reserve(length)).
Fixed (#486): -1 when Reserve fails, and when the load fails (the bank is erased); the original returned 0 for the first and the bank, still reserved, for the second.
| name | d0: filename$ |
|
static |
|
static |
|
static |
BSave(filename$,bank): writes a whole bank (an address: nothing).
| name | d0: filename$ |
| adr | d1: the bank |
|
static |
BSave(filename$,address/bank,length): writes memory (or a bank) to a file.
A number from 0 to maxbanks-1 is a bank, anything else an address (fixed, #484: the original compared signed). Length 0 = the bank's length (an address without a length: 0); a length beyond the bank's is the bank's (fixed, #489: the original wrote that many bytes from the bank's start, whatever the bank's size).
|
static |
CachesOff bitmask: switches caches off (exec CacheControl(0,bitmask)).
Fixed (#1145): below exec V36 (no CacheControl) 0, nothing switched; the original called CacheControl there, a crash on Kickstart 1.x.
| mask | d0: the CACRF_ bits |
|
static |
CachesOn bitmask: switches caches on (exec CacheControl(bitmask,bitmask)).
Fixed (#1145): below exec V36 (no CacheControl) 0, nothing switched; the original called CacheControl there, a crash on Kickstart 1.x.
| mask | d0: the CACRF_ bits |
|
static |
ChangeDir dir$: makes a directory the current one (CurrentDir(Lock(dir$))).
The previous ChangeDir lock is unlocked (AmiBlitz3: MOVE.L oldlock - func-library7 and BSS2 tested and unlocked the word MOVE oldlock,d1 left in d1). The directory the first call replaces (the program's own) is kept for finit (fixed, #491: the original dropped it). Fixed (#490): CurrentDir's result is not tested (0 is a valid current directory); the original returned 0 for it, with the new lock current but not remembered.
| name | d0: dir$ |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
Erase bank: frees a bank (FreeMem) if it is in use.
Nothing for a number that is no bank (Start gives 0; fixed, #484: the original freed an "entry" before the tables for a negative one).
| bank | d0: the bank Returns nothing (all registers kept). |
|
static |
EraseAll: frees every bank in use, from maxbanks-1 down to 0.
Fixed (#495): the count is the whole long; the original counted with DBRA on the low word - with more than 65536 banks only those down to the next multiple of 65536 were freed, BankLimit 0 ran through 65536 negative banks. Returns nothing (all registers kept).
|
static |
|
static |
|
static |
FileSize(filename$): the size of a file.
fib_Size of Examine (its result unchecked) into an AllocMem'd FileInfoBlock.
| name | d0: filename$ |
|
static |
FillMem address,length,value: fills memory (or a bank) with a byte.
A number from 0 to maxbanks-1 is a bank: nothing for a free bank; anything else is an address (fixed, #484: the original compared signed, a negative number was a bank before the tables). Fixed (#492): nothing for a length of 0 or below; the original filled 2^32 bytes for 0 (it tested the length only after the first byte).
|
static |
FillMem address,length: as above with 0.
| adr | d0: the address or bank |
| len | d1: the number of bytes Returns nothing (all registers kept). |
|
static |
FindVolume(volumename): whether a device, volume or assign of that name is present (FindDosEntry).
Fixed (#1082): -1 for a name that is present, as the manual documents; the original returned the entry's address, an entry of the list after UnLockDosList. Fixed (#1145): below dos.library V36 (no LockDosList) the device list of DosInfo is walked under Forbid; the original called the V36 functions there, a crash on Kickstart 1.x.
| name | d0: the name (without ":") |
|
static |
NextBank [startbank]: the first free bank from startbank on.
Fixed (#484): -1 for a start outside 0..maxbanks-1; the original compared signed and searched from a negative start before the tables.
| bank | d0: startbank |
|
static |
|
static |
BankLimit: the number of banks (50 at the start).
|
static |
DeviceName$(volumename$): the name of the handler task of a device or volume, with ":" (AmiBlitz3's version).
A ":" at the end of the argument is cut; the result is written over the argument (a3 = its start, the length below a2), with a terminating 0. The name is taken from the string space (a3), not from d0 (the same string in compiled code). Fixed (#493): the ":" test only for an argument that is not empty; the original tested -2(a3) also for an empty one, a byte of the expression in front. Fixed (#494): "" for an entry without a handler task (or name); the original read through dol_Task without a check. Fixed (#1145): below dos.library V36 (no LockDosList) the device list of DosInfo is walked and the name copied under Forbid; the original called the V36 functions there, a crash on Kickstart 1.x.
| lens | a2: the argument stack, the argument's length at -4(a2) |
|
static |
|
static |
KeyCode: the raw keyboard byte of CIA-A SDR ($BFEC01).
|
static |
Length(bank): the length of a bank.
Fixed (#484): 0 for a negative number too; the original read before the table.
| bank | d0: the bank |
|
static |
finit: makes the directory the first ChangeDir replaced current again, unlocks ChangeDir's lock, frees every bank and the tables, closes dos.library.
If the current directory is not ChangeDir's lock (the program changed it itself), it stays. Fixed (#491): the original unlocked the lock while it was still the current directory and did not clear oldlock.
|
static |
init: opens dos.library and allocates the bank tables.
One memlib globalloc block (MEMF_CLEAR) of 2 * maxbanks longs: the lengths, then the start addresses. The result is not checked (memlib raises "Out of Memory" itself).
|
static |
Lisa: the Lisa (Denise) chip version, DENISEID ($DFF07C).
| result | d0: the caller's d0 (its high word stays, MOVE.w) |
|
static |
MakeDir(dirname$): creates a directory (dos CreateDir) and gives its lock back.
Fixed (#496): the lock CreateDir returns is unlocked; the original unlocked whatever CreateDir left in d1 (JSR _CreateDir : TST.l d0 : BEQ oops : JSR _UnLock; OS 3.2 leaves the lock in d1 as well).
| name | d0: dirname$ |
|
static |
Max(a,b): the larger of two signed longs.
| a | d0: a |
| b | d1: b |
|
static |
MemFree: the free public memory (AvailMem(MEMF_PUBLIC)).
|
static |
Min(a,b): the smaller of two signed longs.
| a | d0: a |
| b | d1: b |
|
static |
|
static |
NextBank: the first free bank (from bank 0).
Fixed (#497): the original used findfreebank for this form too and started at whatever d0 held.
|
static |
Reboot: a cold reboot (exec ColdReboot); does not return.
Fixed (#1145): below exec V36 (no ColdReboot) Commodore's reset routine for older Kickstarts; the original called ColdReboot there, a crash on Kickstart 1.x.
|
static |
| void riamosfunclib_allocmem | ( | void | ) |
| void riamosfunclib_finddev | ( | void | ) |
| void riamosfunclib_gttags | ( | void | ) |
GTTagValue([tagvalue]): GadTools' tag base TAG_USER|$80000 (+ tagvalue in d0) - inline code, copied by the compiler.
_gttags: the form with an argument (ADDI.l to d0), _gttags2: without.
| void riamosfunclib_libfinit | ( | void | ) |
| void riamosfunclib_libinit | ( | void | ) |
| void riamosfunclib_oldreboot | ( | void | ) |
|
static |
SaveExec filename$,list(): writes an executable from a Blitz list of NEWTYPE .hunk (code hunks with RELOC32).
Fixed (#501): 0 for a file that cannot be made, and for an empty list (tested before the file is created); the original returned the name's address, wrote an empty list's tail node as a hunk and left the file open for a first pointer 0. Fixed (#502): only the code hunks written are counted (table size, RELOC32 hunk numbers); the original counted the skipped items too. Fixed (#503): the header has last = n-1 and one size per hunk, every hunk its HUNK_END; a list without code items writes no file. The original wrote one size slot (the sum, last 0) and one HUNK_END behind all hunks.
|
static |
Start(bank): the address of a bank.
Fixed (#484): 0 for a negative number too; the original read before the table.
| bank | d0: the bank |
|
static |
SwapBank(sourcebank,destbank): exchanges two banks (address and length).
Both must have a length (a number that is no bank has none; fixed, #484: the original indexed before the tables for a negative one).
| a | d0: sourcebank |
| b | d1: destbank |
|
static |
Timer: the CIA-A TOD counter (vertical blanks).
High, mid, low byte (the read of high latches it).
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |