Re: Update on emulating a paddle on the C64.

From: Jim Brain (
Date: 2004-12-14 07:25:20

In an Atmel, an int is 16bits.

I changed the code to:

unsigned int len=(JOY_icr_cnt-JOY_icr_cnt_last);  // removed & 0x7ffff;
  if(len < 7000 && len!=0) {  // added the len!=0
    if(len > (JOY_POT_CYCLE + JOY_SPEED_WIN)) {
    } else if(len < (JOY_POT_CYCLE - JOY_SPEED_WIN)) {

JOY_POT_CYCLE = 4096 (512*8) and JOY_SPEED_WIN is a fudge factor, to 
keep the code from constantly bouncing around the target.  It's 
currently 8 (1uS)

Seems to work fine, but I didn't check the code to see how much time I 
save.  This portion of the code is not terribly critical, as I'm waiting 
256 cycles for the POT lines to quit being discharged.

Your explanation maks perfect sense (two's complement was not my strong 
suit in college), but I wonder what my original & 0x7fff actually did.  
Looks like if last = 0 and cnt > 32767, it pushed the name back down, 
which is actually wrong.


Jim Brain, Brain Innovations                      
Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times!

       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.