BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
banklib.c File Reference
#include "blitzlib.h"
#include <dos/dos.h>
#include <proto/dos.h>

Data Structures

struct  bank

Macros

#define __NOLIBBASE__
#define DOS_BASE_NAME   dosbase
#define BANK   ((struct bank *)blitz_string)

Functions

void _bankloc (void)
void _banksize (void)
void _initbank (void)
void _freebank (void)
void banklib_allocmem (void)
void _freemem (void)
void _bankload (const UBYTE *name, struct Library *dosbase)
 LoadBank bank#,filename$: LoadBank with the bank's memtype if it is in use, else 0.
void _bankloadb (const UBYTE *name, ULONG memtype, struct Library *dosbase)
 LoadBank bank#,filename$,memtype: load a file into the bank.
void _banksave (const UBYTE *name, struct Library *dosbase)
 SaveBank bank#,filename$: write the bank to a new file.
static void freebank (struct bank *b)
static void freebank_c (void)
 FreeBank bank#: free the bank's memory.
 BLITZ_ALIAS (_freebank, freebank_c)
static void initbank (struct bank *b, ULONG size, ULONG memtype)
static void initbank_c (ULONG size, ULONG memtype)
 InitBank bank#,size,memtype: (re)allocate the bank.
 BLITZ_ALIAS (_initbank, initbank_c)
static ULONG bankloc_c (const struct bank *b)
 Bank(bank#), BankLoc(bank#): the address of the bank's memory.
 BLITZ_ALIAS (_bankloc, bankloc_c)
static ULONG banksize_c (const struct bank *b)
 BankSize(bank#): the size of the bank.
 BLITZ_ALIAS (_banksize, banksize_c)
static ULONG allocmem_c (ULONG size, ULONG memtype)
 AllocMem(size,memtype): memory from memlib globalloc (freed at the end of the program).
static void freemem_c (ULONG mem, ULONG size)
 FreeMem address,size: memlib globfree (a1 = address, d0 = size).
 BLITZ_ALIAS (_freemem, freemem_c)

Variables

static BPTR hand
static const UBYTE * fname

Macro Definition Documentation

◆ __NOLIBBASE__

#define __NOLIBBASE__

◆ BANK

#define BANK   ((struct bank *)blitz_string)

◆ DOS_BASE_NAME

#define DOS_BASE_NAME   dosbase

Function Documentation

◆ _bankload()

void _bankload ( const UBYTE * name,
struct Library * dosbase )

LoadBank bank#,filename$: LoadBank with the bank's memtype if it is in use, else 0.

The bank comes in a3 (!libs {banklib,$1380}, from bank# in d0).

Parameters
named1: the file name
dosbasea6: dos.library

◆ _bankloadb()

void _bankloadb ( const UBYTE * name,
ULONG memtype,
struct Library * dosbase )

LoadBank bank#,filename$,memtype: load a file into the bank.

Asks fileiolib's Exists (ALibJsr $3E15) for the file size: 0 (no file, an empty file) = nothing happens. The bank is (re)allocated with the file size if the memtype differs or if the file is not smaller than the bank (CMP.l/BMI: the same size is reallocated too); a larger bank is kept, its old contents behind the file's data stay. Then Read(file, pos, BANK size). Errors of Open/Read are ignored. Fixed (#72): a drawer (Exists = -1) leaves the bank as it is; the original reallocated it with $FFFFFFFF bytes for a different memtype (memlib's header made it AllocMem(7), pos behind that block, size -1).

The bank comes in a3 (!libs {banklib,$1380}, from bank# in d0).

Parameters
named1: the file name
memtyped2: the memory type (0 = fast, 2 = chip, 65536 = clear)
dosbasea6: dos.library

◆ _bankloc()

void _bankloc ( void )

◆ _banksave()

void _banksave ( const UBYTE * name,
struct Library * dosbase )

SaveBank bank#,filename$: write the bank to a new file.

Write(pos, size); nothing for an unused bank. Not a bug (no error reporting anywhere in the library): errors of Open/Write are ignored.

The bank comes in a3 (!libs {banklib,$1380}, from bank# in d0).

Parameters
named1: the file name
dosbasea6: dos.library

◆ _banksize()

void _banksize ( void )

◆ _freebank()

void _freebank ( void )

◆ _freemem()

void _freemem ( void )

◆ _initbank()

void _initbank ( void )

◆ allocmem_c()

ULONG allocmem_c ( ULONG size,
ULONG memtype )
static

AllocMem(size,memtype): memory from memlib globalloc (freed at the end of the program).

Keeps a0/a1 like globalloc.

Parameters
sized0: the size in bytes
memtyped1: the memory type (0 = fast, 2 = chip, 65536 = clear)
Returns
d0: the address (no memory: memlib's "Out of Memory!"); the flags of globalloc's tst.l d0 (Z clear after success), which callers test with beq (MikesMapLib, MikesSpaceFXLib, #1059): allocmem_c ends with movem/rts after the call, which keep them (pinned by libs/tests/systest.c, "banklib AllocMem").

◆ banklib_allocmem()

void banklib_allocmem ( void )

◆ bankloc_c()

ULONG bankloc_c ( const struct bank * b)
static

Bank(bank#), BankLoc(bank#): the address of the bank's memory.

Parameters
ba0: the bank (!libs {banklib,$1080}, from bank# in d0)
Returns
d0: the address, 0 if the bank is not in use

◆ banksize_c()

ULONG banksize_c ( const struct bank * b)
static

BankSize(bank#): the size of the bank.

Parameters
ba0: the bank (!libs {banklib,$1080}, from bank# in d0)
Returns
d0: the size in bytes (0 if never set)

◆ BLITZ_ALIAS() [1/5]

BLITZ_ALIAS ( _bankloc ,
bankloc_c  )

◆ BLITZ_ALIAS() [2/5]

BLITZ_ALIAS ( _banksize ,
banksize_c  )

◆ BLITZ_ALIAS() [3/5]

BLITZ_ALIAS ( _freebank ,
freebank_c  )

◆ BLITZ_ALIAS() [4/5]

BLITZ_ALIAS ( _freemem ,
freemem_c  )

◆ BLITZ_ALIAS() [5/5]

BLITZ_ALIAS ( _initbank ,
initbank_c  )

◆ freebank()

void freebank ( struct bank * b)
static

◆ freebank_c()

void freebank_c ( void )
static

FreeBank bank#: free the bank's memory.

memlib globfree of pos/size if both are set, then both cleared; memtype stays (not a bug: no visible effect).

The bank comes in a3 (!libs {banklib,$1380}, from bank# in d0).

◆ freemem_c()

void freemem_c ( ULONG mem,
ULONG size )
static

FreeMem address,size: memlib globfree (a1 = address, d0 = size).

Keeps d1/a0.

Parameters
memd0: the address
sized1: the size in bytes

◆ initbank()

void initbank ( struct bank * b,
ULONG size,
ULONG memtype )
static

◆ initbank_c()

void initbank_c ( ULONG size,
ULONG memtype )
static

InitBank bank#,size,memtype: (re)allocate the bank.

Frees the bank, then (size not 0) stores size and memtype and allocates size bytes (memlib globalloc). Not a bug (intended): size 0 only frees the bank. Not a bug (no visible effect, #71): size and memtype are stored before the allocation; the original memlib never returns from a failed one ("Out of Memory!"), only the C memlib does (K).

The bank comes in a3 (!libs {banklib,$1380}, from bank# in d0).

Parameters
sized1: the size in bytes
memtyped2: the memory type (0 = fast, 2 = chip, 65536 = clear)

Variable Documentation

◆ fname

const UBYTE* fname
static

◆ hand

BPTR hand
static