Jump to content
IGNORED

Timer anomaly


TGB1718

Recommended Posts

I've been trying to use timers 3 , 4 & 5 and noticed something I wasn't expecting.

 

Unlike timers 1 and 2, there is no vector to a routine, instead you set the counter value using SETVBV i.e.

LDA #5 ; timer 5

ldy #0 ; timer countdown value hi

ldx #50 ; timer countdown value lo

jsr setvbv

 

when the counter reaches zero, the timer 5 flag (normally 0) is set ($FF) and that works fine.

But unlike timers 1 and 2 which stop counting down when they reach zero, timers 3, 4 and 5 

keep counting. I would have expected them to stop at zero.

 

The only way I have found to stop them is when the flag gets set is have a routine set x and y to zero

and call SETVBV

 

LDA #5 ; timer 5

ldy #0 ; timer countdown value hi

ldx #0 ; timer countdown value lo

jsr setvbv

 

Not tried on real hardware yet, this was using Altirra emulating a 130XE

 

EDIT: Just noticed timers 1 and 2 keep counting too, but they do set an interrupt and it gets actioned once until reset

Edited by TGB1718
Link to comment
Share on other sites

They should stop counting once they hit 0000.

 

The behaviour should be:   When timer hasn't been used it's flag will be 00 and it's value will be 0000.

When a timer is set, it's value becomes non-zero.

The OS VBlank checks timer values and doesn't touch any timer with value of 0000.

If the value is nonzero, the timer is decremented.  The flag will then be set to FF if the timer is nonzero, flag will be set to 00 if the timer value hits 0000.

 

So, the situation is the same for a never used timer and one that has reached 0000.  So programatically you should just keep track of whether you're using a particular timer.

And of course note that Timers 3-5 are maintained in deferred VBlank so not guaranteed to always be working.

Timers 1-2 aren't interrupts, just indirect JSR.

 

Link to comment
Share on other sites

What specific behavior are you seeing, are the CDTMV3-5 values actually underflowing below $0000 to $FFFF and counting down from there? In Altirra's debugger, you can watch these on screen (ww cdtmv3 / wb cdtmf3, and wc * to clear all).

 

There is an apparent error that I know of in the Atari OS Manual's description of these timers. Appendix L, P8 says that the CDTMF3-5 flags are only modified by the OS during initialization or upon timeout, but every version of the Atari OS that I know of unconditionally sets these flags on every VBLANK that the associated counters are decremented.

 

Link to comment
Share on other sites

Thanks for the info, I'll do some more checking with Altirra debug on (have to figure out how to use it again :) )

I was looking at the timer values and from what I could see is they continued counting after reaching zero, also

once triggered, I could not get the flag to reset, I think because the timer was cycling through zero.

 

I managed to achieve what I wanted, but feel it's a bit "cludgy" as I think the timer should stop once

it reaches zero.

Link to comment
Share on other sites

The OS code should be consistent among versions here and it's very clear - the counters do nothing if the value is 0000.

Note of course each timer is a 2 byte value.  Also note the flags are only maintained as part of the process of decrementing the timers.

You shouldn't need to call SetVBV to set the timers to 0.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...