From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2000-03-31 21:24:28
On Fri, Mar 31, 2000 at 08:31:25PM +0200, Martin Ancher Holm wrote: > Over the last days, i've tried to make a macro to access kernel-calls. > I've tried to use the #define statement. > > Can't I make a simple macro like #define kernel(function, a, x, y), > instead of this for every function? What you can do is: -------------------------------------------------------------------------- unsigned char Y; /* We need a temporary storage */ #define kcall(name, a, x, y) \ Y = y; \ __AX__ = ((unsigned)(x) << 8) + (a); \ asm("\tldy\t_Y"); \ asm("\tjsr\t" #name); -------------------------------------------------------------------------- One problem here is, that the names of the kernal functions are unknown. You have to define them using asm() instructions, or use the address in hex. As an example, to output a character, use #define BSOUT(c) kcall($FFD2,c,0,0) Calling BSOUT('a'); Will then translate into the (inlined) code lda #$00 sta _Y+0 ldx #$00 lda #$41 ldy _Y jsr $FFD2 The loads and stores of y are useless in this case and can be avoided by using a more specialized macro. The load of x cannot be avoided, because the compiler is not smart enough. There is also a C function called _sys (defined in 6502.h). The function is able to call an arbitrary machine language subroutine, pass all registers and the flags as parameters and return the register and flags after the call. Because of the magic involved, the function is slower than using a specialized macro to insert some lines of inline code. Regards Uz -- Ullrich von Bassewitz uz_at_musoftware.de ---------------------------------------------------------------------- To unsubscribe from the list send mail to majordomo_at_musoftware.de with the string "unsubscribe cc65" in the body(!) of the mail.
This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:36 CET