Re: Commodore joystick ports

From: Marko Mäkelä (
Date: 2004-11-03 14:47:53

On Wed, Nov 03, 2004 at 02:23:28PM +0100, Hársfalvi Levente wrote:
> I could think of 2 or 3 possible solutions; first, similarly to the C64, 
> you could probably write a "cycle exact timing" routine (use an 
> otherwise unused timer in the AVR, and for each interrupt services, 
> first determine the 1,2 or 3 cycles extra delay of the executed IRQ 
> routine, then spend 3,2 or 1 plus cycles respectively). The second: 
> program the hw to do the task "itself"; IIRC the timer1 can be reset 
> upon an external event, and can activate outputs upon a compare match. 
> (Could possibly be tricky in overall, but...) 3.) Even if something is 
> missing for the full hw operation, the timer is read/writeable, so 
> previous values (ie. current time ;-) ) can be taken into account.

You didn't mention one trick that Andreas Boose once told me: the double
interrupt trick.  Set up two interrupts.  The first one would be served with
some jitter, and the second one would be triggered while the first one is
executing NOP instructions.  On the 6502, you'd have to get rid of the 0..1
cycle jitter in the second interrupt because the shortest instructions take
2 cycles, but on the AVR the first interrupt can be executing 1-cycle
instructions, and the second interrupt will be cycle-exact.

The double interrupt method can waste a lot of time (1 or 2 rasterlines if
you're using a raster interrupt on the Commodore 64).  I don't know about
the AVR.  It'll consume 2 more bytes of stack, which may be important.
(In my C2N232 firmware, the maximum stack space consumption is 4 bytes, and
the rest of the 128-byte RAM is reserved for the RS-232 input buffer.)


       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.