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:
[snip]
> 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
results:

(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
	...

NextLeftTab:
	.byte	%01
	.byte %11
	.byte	%00
	.byte	%10

NextRightTab:
	.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
  	tay
  	eor last	; 01 or 10 (else: abrupt twist)
  	sty last
  	dey		; -> y = -1..2
  	cpy  #2	
  	sbc  #1	; -> a = -1, 0, 1
  	beq .right
.left:

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
_______________________________________________________
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. http://tippen2.web.de/?x=13



-
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/

Current Thread