Jump to content



1

Questions about using the timer.


5 replies to this topic

#1 xucaen OFFLINE  

xucaen

    Star Raider

  • 94 posts
  • Looking for new owner for commodore 64
  • Location:Ma

Posted Sun Aug 7, 2005 10:44 PM

Hi, I'm seeing examples of code that use TIM64T and INTIM. I'm reading page 12 of the Stella's Programming Guide. I'm not sure I understand what it all means. It sounds like any number you move into one of the interval timers gets multiplied by that interval and starts counting down to zero. So, page 12 says if I load #100 to TIM64T, then the timer would start counting down from 6400 clocks to zero. I'm confused about what a "clock" is. Is a clock one cpu cycle? So loading #100 to TIM64T would be 6400 CPU cycles?

Another thing I am not clear on is, when the timer reaches zero, the Guide says "It holds that count for one interval". Is an interval one cpu cycle or is it 64 cpu cycles?

Jim

#2 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Mon Aug 8, 2005 2:09 AM

xucaen, on Mon Aug 8, 2005 6:44 AM, said:

So loading #100 to TIM64T would be 6400 CPU cycles?
Yup.

Quote

Is an interval one cpu cycle or is it 64 cpu cycles?
Yes, for TIM64T it is 64 cycles.

#3 xucaen OFFLINE  

xucaen

    Star Raider

  • 94 posts
  • Looking for new owner for commodore 64
  • Location:Ma

Posted Mon Aug 8, 2005 12:45 PM

Great! So I'm thinking that after the last WSYNC of Vblank, if I load the correct number into TIM64T, then that will count down through all the cpu cycles of the visible 192 scanlines.

192 * 76 cycles is 14592 / 64 = 228.
or because loading TIM64 will take (I think) 5 cycles, I should load in 213.

sample code might look like this?


sta WSYNC;last wsync of the vertical blank
   ;in this example I think lda takes 2 cycles and sta takes 3 cycles
   ;so I have to subtract 5 from 76 to get 71 cycles. 
   ;71 * 192 = 13632
   ;13632 / 64 = 213
    lda #213
    sta TIM64T

LOOP 

  ;do some stuff

    lda INTIM
    bne LOOP

   ;we should be at the last visible scanline

OverScan


Does this look right?

jim

#4 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Mon Aug 8, 2005 1:04 PM

xucaen, on Mon Aug 8, 2005 8:45 PM, said:

192 * 76 cycles is 14592 / 64 = 228.
or because loading TIM64 will take (I think) 5 cycles, I should load in 213.
No, you should still load 228, by using 213 you will loose about 4 scanlines (5*64 = ~4*76). And finally do one WSYNC do hit the exact end of the last scanline.

BTW: Since the timer will go from 218 to 217 immediately, you will actually only wait for 217 timer loops.

#5 xucaen OFFLINE  

xucaen

    Star Raider

  • 94 posts
  • Looking for new owner for commodore 64
  • Location:Ma

Posted Mon Aug 8, 2005 2:25 PM

Thomas Jentzsch, on Mon Aug 8, 2005 2:04 PM, said:

BTW: Since the timer will go from 218 to 217 immediately, you will actually only wait for 217 timer loops.

Where did you get 218 or did you mean 228?

#6 Thomas Jentzsch OFFLINE  

Thomas Jentzsch

    Thrust, Jammed, SWOOPS!

  • 16,745 posts
  • Always left from right here!
  • Location:Düsseldorf, Germany

Posted Mon Aug 8, 2005 2:35 PM

xucaen, on Mon Aug 8, 2005 10:25 PM, said:

Where did you get 218...?
Where you got the 213: By mistake! :)

228 is correct.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users