|
BB2 C port
API reference: Blitz libraries in C and the shared code
|
#include "blitzlib.h"Functions | |
| void | dopeek (void) |
| Peek [.Type](Address) - read a byte, word, long, quick, float or string from memory. | |
| void | dopoke (void) |
| Poke [.Type] Address,Data - write a byte, word, long, quick, float or string to memory. | |
| void | memacclib_docall (void) |
| Call Address - jump to machine code. | |
| void | dopeeks (void) |
| void | peekschk (void) |
| static ULONG | dopeeks_c (ULONG loc, ULONG n) |
| Peeks$(Address,Length) - a string of Length characters from memory. | |
| BLITZ_ALIAS (dopeeks, dopeeks_c) | |
| static void | peekschk_c (ULONG n) |
| void dopeek | ( | void | ) |
Peek [.Type](Address) - read a byte, word, long, quick, float or string from memory.
The original's code (MOVE.l d1,a0:CMP #2,d0:BHI 'long:BEQ 'word ...): the type compare is a word compare (type 0 reads a byte too); byte/word results replace only the low byte/word of d0 (MOVE.b (a0),d0 / MOVE (a0),d0), the rest of d0 is the type's upper bits (0 for the compiler's types). A string is copied to a3 up to and including its 0; a3 then points to the 0. Changes only d0, a0 (and a3 for strings). Assembler as in the original: Peek runs in the loops of programs that walk memory, and the C function's compares and merges cost up to 30 cycles more.
In: d0 the type the compiler chose (1 byte, 2 word, 3 long, 4 quick, 5 float, 7 string), d1 the address. Out: d0 the value; for a string its length.
| void dopeeks | ( | void | ) |
|
static |
Peeks$(Address,Length) - a string of Length characters from memory.
The characters are copied to a3 without a terminating 0 (as in the original, not a bug, #213: the compiler uses d0 = length, and where it passes a string on as an address it appends clr.b (a3)+ itself, blitz2.s:8767 sbtolong); a length of 0 copies nothing.
Fixed (#214): a negative length gives the empty string, as 0 does (the original counted it unsigned, SUBQ.l #1,d1:BNE, and copied ~4 GB). Errors (debugger, peekschk): "Can't Peeks$ a negative number of Characters!" (#214: the original had no check).
The original changes only d0, d1, a0 (and a3).
| loc | d0: the address. |
| n | d1: the number of characters. |
| void dopoke | ( | void | ) |
Poke [.Type] Address,Data - write a byte, word, long, quick, float or string to memory.
The original's code (MOVE.l d1,a0:CMP #2,d0:BHI 'long:BEQ 'word ...), with the type compares as SUBQ on d0.w (the same unsigned word compares; 6 to 8 cycles fewer than CMP, d0 is no result of a statement). Poke.s copies the length's bytes and writes a 0 behind them. Changes d0 and a0 (strings: also a1). The original takes the length with MOVE.l -(a2),d0 and leaves a2 decremented; here MOVE.l -4(a2),d0 keeps a2 (the compiler does not use it after the call). Assembler as in the original (see Peek).
In: d0 the type the compiler chose (1 byte, 2 word, 3 long, 4 quick, 5 float, 7 string), d1 the address, d2 the value (for a string the characters), a2 the stack pointer before the arguments (a string's length is the long at -4(a2)).
| void memacclib_docall | ( | void | ) |
Call Address - jump to machine code.
MOVE.l d0,a0:JMP (a0). Assembler by nature: the called code gets every register unchanged (a0 = d0 = address) and returns directly to the Blitz program; a C call would have to assume that it keeps d2-d7/a2-a6, which user code need not do.
| void peekschk | ( | void | ) |
|
static |