[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Sudoku puzzle solver for Apple II
"Michael J. Mahon" <mjmahon@aol.com> wrote in message
GL2dnfZbpopeQyjZnZ2dnUVZ_rKdnZ2d@comcast.com">news:GL2dnfZbpopeQyjZnZ2dnUVZ_rKdnZ2d@comcast.com...
> Michael J. Mahon wrote:
> > Michael J. Mahon wrote:
> >
> >> Paul Schlyter wrote:
> >>
> >>> APproximately how much slower do you think a 6502 version would have
> >>> been? 10% slower? Twice as slow? 10 times as slow?
> >>
> >>
> >>
> >> Certainly less than twice as slow. I'll find out what the current
> >> speed impact would be...
> >
> >
> > Paul's message prompted me to re-look at where 65C02 ops are used, and
> > they are all quite easy to eliminate--most with no or negligible time
> > impact.
> >
> > The only one that has a measurable impact is the LDA (p) in setbox,
> > and that can be eliminated by just doing an LDA bit rather than a TXA,
> > which frees up the X register to hold 0, so that the LDA (p) can become
> > LDA (p,x). (I don't get to use that addressing mode much--even if it is
> > with a constant 0 index. ;-)
Speaking of 'setbox', I'm surprised that you used a lookup table to
determine screen addresses but did not use one for the 'other' array. If I
understand the code correctly, you could replace the
'best*24+other_base_address' calculation with a pre-computed value. Also you
could get rid of three '-1' values in 80 rows of 'other', for a net savings
of 80 bytes to boot.
Heck, you could get rid of that last -1 value in each row as well: add $80
to the last entry, so that the ASL instruction in the main loop of 'setbox'
sets the carry for that entry, clears it for all the others. Then after
you've set the bit of interest, break the loop if the carry flag is set.
That also saves one LDA instruction at the top of the loop (20 executions
instead of 21).
And then you might consider breaking the 'setbox' loop in two loops, one for
setting the low byte and one setting the 9th bit. That would eliminate the
redundant test executed inside the loop: just test it once to decide which
loop to execute. Of course all the loop control code would be duplicated and
the only differences would be the few instructions that actually set bits,
but you just saved a bunch of space by implementing that 'others' lookup
table.
And of course you don't need 65C02 instructions to do any of this :)
Something like this:
...
lda best
asl
tax
lda otherptr,x
sta p
lda otherptr+1,x
sta p+1
ldx #20-1
lda bit
beq high_bit_loop
:1 txa
tay
lda (p),y
asl
tay
lda (bits),y
ora bit
sta (bits),y
dex
bpl :1
rts
high_bit_loop:
txa
tay
lda (p),y
asl
tay
iny
lda (bits),y
ora #$01
sta (bits),y
dex
bpl high_bit_loop
rts
...to take advantage of the fact that there are two indirect pointers
already. Can use the X-register for counting directly,
and don't need to put any kind of special coded values in the 'other' table
at all.
And if that works, why not store the neighbor square# times two in the
'other' table and eliminate the ASL instruction in each loop?
Oh, I gotta stop now...
- Anton Treuenfels