Re: [stella] reading the driving controllers, generic thoughts

Subject: Re: [stella] reading the driving controllers, generic thoughts
From: "Thomas Jentzsch" <tjentzsch@xxxxxx>
Date: Tue, 30 Oct 2001 11:45:29 +0100
Glenn Saunders wrote:
> This would probably be faster.  Don't know how the
> ROM usage would
> compare. What do you guys think?

After some playing with the code, here are my

(We should ignore the bits 2+3, because they are
always set.)

The first idea I had, is not to scan the tables, but
to let the tables contain the next *expected* value.
This is an assembler conversion of your switch/case
suggestion. The resulting code looks already quite
nice and compact:

	lda SWCHA
  	and #%11
  	ldy last
  	sta last
  	cmp NextLeftTab,y
  	beq .left
  	cmp NextRightTab,y
  	beq .right

	.byte	%01
	.byte %11
	.byte	%00
	.byte	%10

	.byte	%10
	.byte	%00
	.byte	%11
	.byte	%01

Then I noticed, that the the right table values are
the left values EOR %11. So I can even save some
more bytes and cycles:

	ldy last
	lda SWCHA
  	and #%11
  	sta last
  	eor NextLeftTab,y	; works like cmp for beq
  	beq .left
  	eor	#%11
  	beq .right

Finally, I started search for a solution without
tables at all. And I found this (very hard to
explain:) routine:

  	lda SWCHA
  	eor last	; 01 or 10 (else: abrupt twist)
  	sty last
  	dey		; -> y = -1..2
  	cpy  #2	
  	sbc  #1	; -> a = -1, 0, 1
  	beq .right

I think that solution comes very close to the
optimum. (You need some additional code here to
recognize abrupt twists of the wheel.)

I haven't tested the code, so maybe it's buggy, but
from theory it should work.

Have fun!
Thomas Jentzsch         | *** Every bit is sacred ! ***
tjentzsch at web dot de |

Lotto online tippen! Egal zu welcher Zeit, egal von welchem Ort.
Mit dem WEB.DE Lottoservice.

Archives (includes files) at
Unsub & more at

Current Thread