riamosfunclib
This library began as a set of commands that work like their AMOS counterparts and grew into a collection of small helpers: memory banks, file loading and saving, directory and volume functions, memory copies and fills, the processor caches and a few hardware registers.
A bank is a block of memory with a number, from 0 to 49 by default;
BankLimit changes the number of banks. Reserve allocates a bank,
Start and Length give its address and size, Erase frees it, and
all banks still in use are freed when the program ends. FillMem,
BLoad and BSave take a bank or an address: a number from 0 to one
below the bank limit is a bank, any other number an address. The other
bank commands treat a number outside as a bank not in use.
The file and directory commands (BLoad, BSave, FileSize,
MakeDir, Rename, ChangeDir, FindVolume, DeviceName$,
SaveExec) work in Amiga mode only.
Loading a file into a new bank and saving it again:
b=BLoad("s:startup-sequence")
If b>=0
NPrint "bank ",b,", ",Length(b)," bytes"
r=BSave("ram:copy",b)
Erase b
EndIfThe fixed bugs of the library are listed in Fixes in riamosfunclib.
Based on the RI AMOS Func Library guide by Red When Excited.
Library number 75.
Commands
BankLimit
Without an argument, the number of banks (50 at the start). BankLimit numbanks sets a new number of banks and frees every bank in use; used as a function, it returns the new number.
Statement or function, result .l. Help text: [numbanks]
2 forms:
.l- no arguments
BlitterDone
Returns -1 if the blitter is idle and 0 if it is still busy.
Function, result .l. No help text.
No arguments.
BLoad
Loads a file into memory. With the name alone, it reserves the next free bank of the file’s size and returns its number, or -1 on failure; with a bank or an address, it returns -1 if the file was read and 0 otherwise.
Statement or function, result .l. Help text: (filename$,[address,[,length,[offset,[memtype]]]])
5 forms:
$$, .l$, .l, .l$, .l, .l, .l$, .l, .l, .l, .l
Amiga mode only. A length of 0, or none, loads the whole file;
offset is the position in the file to start at. A bank given to
BLoad is erased and reserved anew with that length and with the
memory type memtype (the flags of Reserve; 0 or none for any
memory), once the file is open; a file that cannot be opened leaves
the bank as it is. An address must point to enough memory. A file
shorter than length is loaded as far as it goes, which counts as
success.
The form with the name alone returns -1 for an empty or missing file,
when no bank is free, when there is not enough memory (see Reserve)
and when reading the file fails; the bank it reserved is then freed
again.
BSave
Saves a bank, or length bytes from an address, as a file. Returns -1 if the file was written, else 0.
Statement or function, result .l. Help text: (filename$,address/bank[,length])
2 forms:
$, .l$, .l, .l
Amiga mode only. Without a length, or with 0, a bank is saved
whole, and a length larger than the bank saves the whole bank; an
address needs a length.
CachesOff
Switches off the processor caches whose bits are set in bitmask (the bits of exec’s CacheControl) and returns the previous cache bits.
Statement or function, result .l. Help text: bitmask
Arguments: .l
On Kickstart 1.x, which has no CacheControl, it switches nothing
and returns 0.
CachesOn
Switches on the processor caches whose bits are set in bitmask (the bits of exec’s CacheControl) and returns the previous cache bits.
Statement or function, result .l. Help text: bitmask
Arguments: .l
On Kickstart 1.x, which has no CacheControl, it switches nothing
and returns 0.
ChangeDir
Makes a directory the current one. Returns -1 on success and 0 if the directory cannot be found.
Statement or function, result .l. Help text: dir$
Arguments: $
Amiga mode only. When the program ends, the directory it was started
in is made current again, unless the program changed the current
directory itself since the last ChangeDir.
CopyByte
Copies bytes bytes from sourceaddr to destaddr, from the first byte upwards. A count of 0 or below copies nothing.
Statement. Help text: sourceaddr,destaddr,bytes
Arguments: .l, .l, .l
Because the copy runs upwards, overlapping areas copy correctly only
when destaddr is below sourceaddr.
CopyLong
Like CopyByte, copying longs longs (4 bytes each); both addresses must be even.
Statement. Help text: sourceaddr,destaddr,longs
Arguments: .l, .l, .l
CopyWord
Like CopyByte, copying words words (2 bytes each); both addresses must be even.
Statement. Help text: sourceaddr,destaddr,words
Arguments: .l, .l, .l
DeviceName$
The name of the device that holds a volume, with a colon, or "" if there is no such device or volume. The colon at the end of the argument is optional.
Function, result $. Help text: (volumename$)
Arguments: $
Amiga mode only. A device or volume without a running handler gives “”.
Erase
Frees a bank. A bank not in use is left alone.
Statement. Help text: bank
Arguments: .l
EraseAll
Frees every bank in use.
Statement. No help text.
No arguments.
FileSize
The size of a file in bytes, or 0 if it cannot be found.
Function, result .l. Help text: (filename$)
Arguments: $
Amiga mode only.
FillMem
Fills length bytes from an address, or from the start of a bank, with the byte value, or with 0 without it. A bank not in use is left alone, and a length of 0 or below fills nothing.
Statement. Help text: address,length[,value]
2 forms:
.l, .l.l, .l, .l
FindVolume
Looks for a device, volume or assign of that name, without the colon, and returns -1 if there is one, or 0 if there is none. No “Please insert volume” requester appears.
Function, result .l. Help text: (volumename)
Arguments: .l
Amiga mode only. The argument is a long, the address of a name that
ends in a zero byte, for example &v$.
GTTagValue
The base value of the GadTools tags, $80080000, plus tagvalue if given.
Function, result .l. Help text: ([tagvalue])
2 forms:
- no arguments
.l
KeyCode
The raw byte of the keyboard’s serial register, as the keyboard last sent it, not decoded into a key number.
Function, result .w. No help text.
No arguments.
Length
The length of a bank in bytes, or 0 if the bank is not in use or not below the bank limit.
Function, result .l. Help text: (bank)
Arguments: .l
Lisa
The contents of the chip ID register of Denise or Lisa.
Function, result .w. Help text: -- returns Lisa chip version
No arguments.
MakeDir
Creates a directory. Returns -1 if it was created, else 0.
Statement or function, result .l. Help text: (dirname$)
Arguments: $
Amiga mode only.
Max
The larger of two signed long values.
Function, result .l. Help text: (a,b)
Arguments: .l, .l
MemFree
The number of bytes of free public memory.
Function, result .l. No help text.
No arguments.
Min
The smaller of two signed long values.
Function, result .l. Help text: (a,b)
Arguments: .l, .l
NextBank
The number of the first free bank from startbank on, or from bank 0 without it; -1 if none is free or startbank is not a bank.
Function, result .l. Help text: [startbank]
2 forms:
- no arguments
.l
Reboot
Reboots the Amiga at once (a cold reboot); it does not return.
Statement. Help text: -- performs a cold reboot
No arguments.
On Kickstart 1.x it uses the reset routine that Commodore published for the Kickstarts before 2.0.
Rename
Renames a file or directory. Returns -1 on success, else 0.
Statement or function, result .l. Help text: (oldfilename$,newfilename$)
Arguments: $, $
Amiga mode only.
Reserve
Allocates a bank. Reserve(length) takes the next free bank and returns its number, or -1 if there is not enough memory; Reserve(bank,length[,requirements]) returns -1 on success and 0 otherwise.
Statement or function, result .l. Help text: (length)|(bank,length[,requirements])
3 forms:
.l.l, .l.l, .l, .l
requirements are exec’s memory flags, added together: 1 public, 2
chip, 4 fast, $10000 cleared; without them the memory is public.
Reserve(length) returns -1 also for a negative length and when
every bank is in use; Reserve(bank,length) returns 0 for a number
outside 0 to one below the bank limit.
A bank already in use is erased first, also when the new allocation fails: reserving first would need the memory of both blocks at once.
SaveExec
Writes an executable file built from a Blitz list of code hunks (a NEWTYPE .hunk with type, address, length, relocation table and its length, and memory flags). Returns -1 on success.
Statement or function, result .l. Help text: filename$,list()
Arguments: $, array()
Amiga mode only. Only code hunks are written; others are skipped. Returns 0 if the file cannot be created or the list holds no code hunk; then no file is written.
Start
The address of a bank, or 0 if the bank is not in use or not below the bank limit.
Function, result .l. Help text: (bank)
Arguments: .l
SwapBank
Exchanges two banks, so that each number refers to the other’s memory. Returns -1 if both banks are in use and were swapped, else 0.
Statement or function, result .l. Help text: (sourcebank,destbank)
Arguments: .l, .l
Timer
The count of the time-of-day counter of the CIA-A chip, which advances once per vertical blank, 50 or 60 times a second; as a word function, its low 16 bits.
Function, result .w. No help text.
No arguments.
WaitBlitter
Waits until the blitter is idle.
Statement. No help text.
No arguments.