Re: [cc65] interruptor from C?

From: Ullrich von Bassewitz <uz1musoftware.de>
Date: 2004-10-13 14:47:19
Sorry for the late answer ...

On Tue, Oct 12, 2004 at 12:22:33PM +0300, Karri Kaksonen wrote:
> I also read the FAQ and found out why the interrupt should be in asm.
>
> But my C-code produces exactly the same thing I would write by hand
> so I would prefer to have a way to write the routine in C for readability
> reasons.

It is sometimes not obvious, if a function uses the stack and/or temporary
storage in the zero page, in which case it is not interrupt safe. It would be
trivial to allow declaring C code as an interruptor (for example by adding a
"#pragma interruptor"), but since a lot of code will not work, it is almost
sure that people will complain. Having to check the asm code is not really an
option, since a small change in the C source may cause the function to be no
longer interrupt safe.

It would be possible to use the macros defined in lynx.h to save the zeropage
contents, but this has two drawbacks:

  1. It has a high overhead. 26 bytes must be saved onto the stack (10 cycles
     per byte) and restored on exit. Together with the registers, more than
     30 bytes are pushed and restored in case of an interrupt.
     (The register bank does not need to be saved, but there are currently
     no provisions for user code to distinguish it from the remainder of the
     zero page space).

  2. Since such a macro is a statement, the compiler will use the parameter
     stack before the statement is executed, if register variables are used.
     So an interrupt routine may not use register variables.

I see still no real solution for writing interrupt handlers in C. The overhead
for saving and restoring the zero page locations used by the compiler and
runtime is so high that I would still advise people to write interrupt
handlers in assembler.

If you really, really want to trick the compiler into adding your C code as an
interruptor, you may use an assembler module like

        .import         _vbl
        .interruptor    _vbl, 2

and link this module as an object file to your code.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Oct 13 14:47:23 2004

This archive was generated by hypermail 2.1.8 : 2004-10-13 14:47:32 CEST