barrym95838 wrote:
claw wrote:
It blinks as if the delay is around 250 to 500ms!
I took a quick stab at it and arrived at ~ 327 ms @ 1 MHz. Now, back to our regularly scheduled program ...
Well I'm intrigues now - obviously my back of an envelope calculations were an order of magnitude out, so let me see if I can get it right.. Just because:
This is the code:
Code:
delay_loop:
ldy #$ff
delloop1:
ldx #$ff
xloop1:
dex
bne xloop1
dey
bne delloop1
rts
So the inner loop is:
Code:
xloop1:
dex
bne xloop1
The dex is 2 cycles and the bne is 3 cycles, (but only 2 on the very last one which I never bothered counting before). X in initialised at 255, so the loop count in 255, so that's 254 loops of 5 cycles and one loop of 4 cycles = 1274 cycles.
The outer loop also runs 255 times, so the inner loop will run 255 times 1274 cycles = 324870 cycles.
The outer loop also has an overhead - same as the inner loop which is 254 * 5 + 4 = 1274 cycles.
And that needs to be added (not multiplied which I did before) to the grand total giving 324870 cycles or about 1/3 of a second at 1Mhz.
(plus a tiny overhead for jsr/rts)
Phew!
FWIW: I've used the WAIT routine out of the Apple II monitor in the past for a "calibrated" delay - not really needed here but maybe worthwhile knowing about.
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/