Re: [cc65] Interrupt <-> C runtime environment

From: marcas <marcas1chello.at>
Date: 2011-07-11 07:03:02
Hi,


On 2011-07-10 04:51, Greg King wrote:
> From: "marcas"; on Friday, July 08, 2011; at 05:19 PM -0400
>> I tried to invoke a C function within an interrupt.
>> As the cc65 run-time environment does not allow that, my question is:
>>
>> Which memory addresses must I save, in order to restore the state
>> from before the interrupt?
> 1. You must save the contents of the ZEROPAGE segment (currently, 26
> bytes).
Thank you for the information, I also got an answer from Uz that pointed 
me to "the secret FAQ stuff":-). I think my question is covered with the 
information there.

> 2. Interrupts can happen in-between changes to the two bytes of the
> Stack-Pointer -- the SP will be "indeterminate".  Therefore, your
> interrupt functions must create their own stack.
>

Why do I need an own stack? The only problem is, that the stack is very 
small and overflows after 256 bytes. Maybe then I will have to copy it 
to have 256 bytes for every task.

My current ISR is able to handle small C code. (e.g. uint8_t++ works, 
uint16_t++ works, uint32_t++ does not work and results in weird behaviour)



static uint8_t TimeStampCounter;

void ISR (void)
{
     // regs pushed on stack yet, see c64 - kernels/kernals interrupt 
entry code at $FF48

     // save C RT context here?

     // INTERRUPT SUBROUTINE PRODUCTIVE C CODE HERE
     TimeStampCounter++;

     // restore C RT context here?

     mBits(CIA1.icr,BIT7); //ACK CIA 1 interrupts or any other sources ( 
   #define mBits(x,m) ((x)&(m)) )

     //  __asm__("JMP $EA31"); // not used, I will cleanup manually, see 
below

     __asm__("PLA");
     __asm__("TAY");
     __asm__("PLA");
     __asm__("TAX");
     __asm__("PLA");
     __asm__("RTI");
}

Kind regards
marcas
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Mon Jul 11 07:03:16 2011

This archive was generated by hypermail 2.1.8 : 2011-07-11 07:03:20 CEST