Re: Update on emulating a paddle on the C64.

From: Jim Brain (brain_at_jbrain.com)
Date: 2004-12-09 21:19:02

>> ...  Then, the counter value is subtracted from the last
>> captured counter value.  The result is made positive, and it is checked
>> for sanity.  Assuming the number is < 7000, it is checked for equality
>> with 4096.  ...
>
> Is that sign-inversion necessary?  If the code to subtract the old counter
> value from the new one is less efficient, then can't you use the negative
> difference directly?  (If it's greater than -7000, then, compare it
> to -4096.)

Dunno, let me see

void calc (unsigned int old, unsigned int new) {
  unsigned int tmp;
  if(new < old) {
    tmp=old-new;
  } else {
    tmp=new-old;
  }
  if(tmp < 7000) {
...
  }
}

Is the old code...

void calc (unsigned int old, unsigned int new) {
  int tmp;
  tmp=new-old;
  if(tmp > -7000 && tmp < 7000) {
...
  }
}

The corner case is when the counter is at 65535 (for example), and it
wraps, to 4095.

4095-65535 = -61440 -> (signed int) -4095 (I think...)

It would seem to work, and it'd be a bit faster, but someone needs to
check my math.  I think the intermediate result would be stuffed into 16
bits, and that would normalize to -4095, but someone needs to verify.

Jim


-- 
Jim Brain
brain@jbrain.com

       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail pre-2.1.8.