Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Opcode Execution time != cpu cycles?
2012-02-05 14:37
Flavioweb

Registered: Nov 2011
Posts: 463
Opcode Execution time != cpu cycles?

As writed at: http://www.atarimax.com/jindroush.atari.org/aopc.html#TIMES

"
Execution Times

Op code execution times are measured in machine cycles, one of which equals two clock cycles. Many instructions require one extra cycle for execution if a page boundary is crossed; ...
"

This mean that using a Cia timer setup to count system cycles and supposing to starting it just after an LDA #$00 instruction and reading it again (the timer value) after instruction execution, since LDA time is 2 machine cycles the timer value can be 4 (or better... to have a timer value of "0" we need to setup it for starting at 4)?
2012-02-05 16:44
Cruzer

Registered: Dec 2001
Posts: 1048
lda #$00 is always two cycles, but other vary, e.g. bne - if the branch is not taken it's 2 cycles, if it's taken it's normally 3, but if the address it's jumping to is on another page, an additional cycles is used, resulting in 4 cycles.

See an overview here:
http://www.oxyron.de/html/opcodes02.html
2012-02-05 17:35
Flavioweb

Registered: Nov 2011
Posts: 463
Quote: lda #$00 is always two cycles, but other vary, e.g. bne - if the branch is not taken it's 2 cycles, if it's taken it's normally 3, but if the address it's jumping to is on another page, an additional cycles is used, resulting in 4 cycles.

See an overview here:
http://www.oxyron.de/html/opcodes02.html


Ok...
But CIA timer goes from 4 to 0 (3 to 0?) or from 2 to 0 (1 to 0?) during execution of LDA #$00 ?
2012-02-05 19:11
JackAsser

Registered: Jun 2002
Posts: 2014
The CIA timer will make two steps. It's clocked at the same speed as the CPU (using the same clock signal). The memory bus is clocked at 2mhz though allowing CPU to access memory while the VIC is reading from memory. Sometimes though the VIC needs to slurp data really fast and steals the whole bus, this is called a bad line, where the CPU won't get any time at all for a moment.
2012-02-05 20:40
WVL

Registered: Mar 2002
Posts: 902
slurp. I like that.

sluuurrrppP!!

Can we put that in the VIC article? :)

slurp!
2012-02-05 21:47
Graham
Account closed

Registered: Dec 2002
Posts: 990
Quoting Flavioweb

This mean that using a Cia timer setup to count system cycles and supposing to starting it just after an LDA #$00 instruction and reading it again (the timer value) after instruction execution, since LDA time is 2 machine cycles the timer value can be 4 (or better... to have a timer value of "0" we need to setup it for starting at 4)?

No, on LDA #$00 you always have 2 clock cycles and also the CIA will always count 2. Both, CPU and CIA use the same 1 MHz clock.

It should be noted that the CPU uses both edges (up and down) of the clock to do something, I think that's what they are trying to say.
2012-02-06 04:46
Flavioweb

Registered: Nov 2011
Posts: 463
Quote: Quoting Flavioweb

This mean that using a Cia timer setup to count system cycles and supposing to starting it just after an LDA #$00 instruction and reading it again (the timer value) after instruction execution, since LDA time is 2 machine cycles the timer value can be 4 (or better... to have a timer value of "0" we need to setup it for starting at 4)?

No, on LDA #$00 you always have 2 clock cycles and also the CIA will always count 2. Both, CPU and CIA use the same 1 MHz clock.

It should be noted that the CPU uses both edges (up and down) of the clock to do something, I think that's what they are trying to say.


Maybe that 1 "system cycle" are 2 edges, but 1 "clock cycle" is only 1 edge ?
So, if in a pal system with clock at 0,9875MHZ there are 987.500 "edges" per second, the cia can count "only" 493.750 "cycles" per second.
And the cpu to -execute- the LDA #$00 uses 2 -system- cycles that match at 4 "edges" or clock cycles...
correct?
2012-02-06 10:27
chatGPZ

Registered: Dec 2001
Posts: 11386
Quote:
Can we put that in the VIC article? :)

this stuff is explained right at the beginning of said article, *afaik* =)

other than that i recommend - especially for a beginner - to completely ignore the "machine cycle" vs "cpu cycle" thing. its the same in all practical situations anyway :)
2012-02-06 13:12
Graham
Account closed

Registered: Dec 2002
Posts: 990
Quoting Flavioweb
Maybe that 1 "system cycle" are 2 edges, but 1 "clock cycle" is only 1 edge ?

http://en.wikipedia.org/wiki/File:SquareWave.gif

Take a look at that graph: 0.0 to 1.0 is one cycle.

Quote:
So, if in a pal system with clock at 0,9875MHZ there are 987.500 "edges" per second, the cia can count "only" 493.750 "cycles" per second.

No, there are 1 million "high" states per second, each of them followed by a "low" state. That's the definition of a "cycle": It repeats on and on.

Quote:
And the cpu to -execute- the LDA #$00 uses 2 -system- cycles that match at 4 "edges" or clock cycles...
correct?

It's 2 clock cycles. The rest is pretty much irrelevant on the software side. What groepaz said: On 6502 machine cycles do not matter at all. You can completely ignore that something like that exists.
2012-02-06 21:15
Copyfault

Registered: Dec 2001
Posts: 478
Quote: Ok...
But CIA timer goes from 4 to 0 (3 to 0?) or from 2 to 0 (1 to 0?) during execution of LDA #$00 ?


Be careful with value '0' in timer regs. In theory, once a CIA timer is started it counts down from its inital value to zero. In reality the timer takes the init value again when reaching the 'zero state'. So it rather looks like this:

initial value e.g. = 4
at next clock cycle = 3
at next clock cycle =2
at next clock cycle = 1
at next clock cycle = 4
(in one shot mode, it stops here; otherwise it continues like this:)
at next clock cycle = 4
at next clock cycle =3
etc.

Confused me a lot when I had my first try with the CIA timers.
2012-02-06 21:22
chatGPZ

Registered: Dec 2001
Posts: 11386
also that is completely irrelevant unless you are trying to use the timer value right before it wraps. i cant tell any practical situation where this is true right now to be honest :o)
2012-02-06 21:50
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: also that is completely irrelevant unless you are trying to use the timer value right before it wraps. i cant tell any practical situation where this is true right now to be honest :o)

When using a timer to stabilize a raster it can be confusing if you assume the value 0 exists... :) But yeah... not really relevant in most cases indeed.
2012-02-06 21:55
Copyfault

Registered: Dec 2001
Posts: 478
Mainly I wanted to point this out because I think it helps a lot - at least it would've helped me back then ;)

In practice it could help to do a smart dejitter routine. This "zero state = init value"-thingie forced me to use the illegal asr-opcode ;)
2012-02-06 22:06
chatGPZ

Registered: Dec 2001
Posts: 11386
or just start the timer one cycle later perhaps? =P
2012-02-07 07:16
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: or just start the timer one cycle later perhaps? =P

Totally off-topic of course, but since I formulated a problem and you posted a solution (the one we all use), it's not completely irrelevant knowing that the timer actually doesn't reach 0. :)
2012-02-07 08:56
chatGPZ

Registered: Dec 2001
Posts: 11386
i have used timers for stable raster long before i knew about the wraparound bug though :)
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
ΛΛdZ
Chesser/Blazon
Scrap/Genesis Project
Acidchild/Padua
AMB/Level 64
The Syndrom/TIA/Pret..
Wayne Kerr/Flashtro
Guests online: 102
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Triad  (9.3)
5 Censor Design  (9.3)
Top Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.059 sec.