Jump to content
IGNORED

VBI help with timer


gozar

Recommended Posts

I've set up the following as a VBI, and it works for the most part:

; Constants
VVBLKI      = $0222; VBI vector
SYSVBV      = $e45f; jump to OS VBI
RTCLOK      = $14
counth      = $604
countl      = $605
ts0         = $600
ts1         = $601
ts2         = $602
ts3         = $603

    *= $610

SETUP
    lda #0
    sta countl   ; Reset counter to 0
    sta counth

    lda #<VBI; register new VBI subroutine
    sta VVBLKI
    lda #>VBI
    sta VVBLKI+1

    lda #$c0; enable VBI's/DLI's
    sta NMIEN
    rts

VBI
    lda #60
    cmp RTCLOK
    bcs done
    lda #0
    sta RTCLOK  ; Reset Clock
    inc ts0
    bne done
    inc ts1
    bne done
    inc ts2
    bne done
    inc ts3

done
    inc countl
    bne check1k
    inc counth

check1k
    ldy countl
    lda counth
    cpy #$e8
    bne exit
    cmp #$03
    bne exit
    inc RTCLOK
    lda #0
    sta countl
    sta counth

exit
    jmp SYSVBV

The VBI increments a 32 bit number every second located at $600. It all works except the code increments the number slightly slower than a second.

 

Joe_z did the math for me, and every 1000 jiffies I need to add 1 jiffy since the clock isn't precisely 60 times a second. That's what the check1k procedure does, but it doesn't seem to help, the clock still runs slow.

 

What did I miss?

 

(p.s. This is a procedure in a larger MAD Pascal program.)

Link to comment
Share on other sites

May as well cater for PAL too... looks like an extra tick every 357 makes it more accurate.

 

In both cases you'll still get drift. I don't know if an extra couple of layers of corrections will bring it true or if it's just a repeating series of errors.

You'd probably be able to get more accurate timing using Pokey Timers but even then you're still relying on the system clock speed which in itself has some inaccuracy.

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...