BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
memacclib.c File Reference
#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)

Function Documentation

◆ BLITZ_ALIAS()

BLITZ_ALIAS ( dopeeks ,
dopeeks_c  )

◆ dopeek()

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.

◆ dopeeks()

void dopeeks ( void )

◆ dopeeks_c()

ULONG dopeeks_c ( ULONG loc,
ULONG n )
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).

Parameters
locd0: the address.
nd1: the number of characters.
Returns
d0: the length (= d1, 0 for a negative d1).

◆ dopoke()

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)).

◆ memacclib_docall()

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.

  • d0 the address of the code.

◆ peekschk()

void peekschk ( void )

◆ peekschk_c()

void peekschk_c ( ULONG n)
static