Skip to content

banklib

A bank is a Blitz object, numbered from 0, that holds a block of memory: for data such as a level map, a sample or a file to be read with Peek. InitBank gives a bank memory of a size and type, LoadBank fills it from a file and makes it as large as the file if needed, and SaveBank writes it to a file. Bank and BankSize give its address and size.

LoadBank 0,"level1.dat"
For i=0 To BankSize(0)-1
  v=Peek.b(Bank(0)+i)
Next

The memory type is the sum of the system’s memory flags: 0 any memory, 1 public, 2 chip memory (for graphics and sound), and 65536 to clear it. AllocMem and FreeMem give plain memory blocks of a type without a bank. The memory of banks and of AllocMem that the program does not free is freed when it ends.

File errors are not reported: a file that cannot be loaded or saved is skipped without a message.

Based on the banklib guide by Acid Software.

Library number 76. It manages Bank objects, by default at most 5 (the compiler options set the maximum).

Commands

AllocMem

A block of size bytes of memory of the type memtype, as its address. It is freed when the program ends, or before with FreeMem.

Function, result .l. Help text: (size,memtype) memtype: 0=fast 2=chip 65536=clrmem
Arguments: .l, .l

Bank

The address of the memory of the bank, or 0 if the bank is not in use.

Function, result .l. Help text: (bank#) ;returns location of bank, 0 if not in use
Arguments: .w

BankLoc

The address of the memory of the bank, as Bank.

Function, result .l. Help text: (bank#)
Arguments: .w

BankSize

The size of the bank in bytes.

Function, result .l. Help text: (bank#)
Arguments: .w

FreeBank

Frees the memory of the bank.

Statement. Help text: bank#
Arguments: .w

FreeMem

Frees a block of memory from AllocMem; give the same size.

Statement. Help text: address,size
Arguments: .l, .l

InitBank

Gives the bank size bytes of memory of the type memtype; the old memory of the bank is freed first. A size of 0 only frees the bank.

Statement. Help text: bank#,size,memtype ;0=fast 2=chip 65536=clrmem
Arguments: .w, .l, .l

LoadBank

Loads a file into the bank. The bank gets new memory of the file’s size if it is smaller than the file, not in use, or of another memory type than memtype; without memtype, the type of a bank in use is kept, and a bank not in use gets type 0. Nothing happens for a file that does not exist or is empty, or for a drawer.

Statement. Help text: bank#,filename$[,memtype]
2 forms:

  • .w, $
  • .w, $, .l

A bank larger than the file keeps its size, and its bytes after the file’s data stay as they were.

SaveBank

Writes the memory of the bank into a new file; nothing for a bank not in use.

Statement. Help text: bank#,filename$
Arguments: .w, $