<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 05 Feb 2013 00:02:41 +0000
From   : jgh@... (J.G.Harston)
Subject: 6502 coding request

J. E. Klasek wrote:
> See http://unusedino.de/ec64/technical/aay/c64/romfddd.htm
> BTW: I used a PAL version all the time and there was always a 1/60 
> time base.

All the documentation said 1/60s and I did a test with a continuous 
display with a stopwatch next to it and it matched.

Anyway, I was staring into space while eating my lunch and it occurred 
to me that converting 60 to 100 is multiplying by 1.6666etc. and 
wondered if I could make a fast multiply-by-1.6666 routine with shifts 
and adds. A bit of scribbling showed that 1.6666 in binary is 
1.101010101010etc. Wonderful, a loop with a shift and an add on every 
second shift:

JSR &FFDE                    :\ Read Jiffy clock to &YYXXAA
STA wksp+0:STA wksp+3        :\ Prepare to multiple by 1+2/3
STX wksp+1:STX wksp+4        :\  to convert 1/60ths to 1/100ths
STY wksp+2:STY wksp+5
.c64Word01lp1                     :\ Can probably optimise this
LSR wksp+5:ROR wksp+4:ROR wksp+3  :\ add=add/2
LDA wksp+0:ADC wksp+3:STA wksp+0  :\ num=num+add
LDA wksp+1:ADC wksp+4:STA wksp+1
LDA wksp+2:ADC wksp+5:STA wksp+2
LSR wksp+5:ROR wksp+4:ROR wksp+3  :\ add=add/2
LDA wksp+5:ORA wksp+4:ORA wksp+3
BNE c64Word01lp1                  :\ Loop until nothing left to add

Multiply by 1+2/3 is 1 + 1/2 + 1/8 + 1/32 + 1/128 etc. Significantly 
faster than looping subtracting 3s and counting. See, learning infinite 
series in 'A' level maths does have real-world applications :)

ClockSpeed now works correctly and confirms the C64 runs at 1MHz.

-- 
J.G.Harston - jgh@...      - mdfs.net
BBC BASIC for the Commodore 64 - mdfs.net/bbcbasic/C64
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>