No renderer 'pdf' found for mode 'pdf'
base:tod_calibration
This is an old revision of the document!
The code below sets the TOD 50/60 Hz pre-scaler of CIA. It needs to correspond to the power line frequency which might or might not relate to the video standard.
The idea is to use the horizontal retrace frequency (15.6-16 KHz) as base to measure the TOD tick interval. If it takes longer then a threshold the 50 Hz pre-scaler is used otherwise the 60 Hz one.
Advantages:
- Independent of CPU clock so it works on SuperCPU
- Does not hang on DC only powered machines
- No need to switch off screen or sprites
- Does not mess with timers or anything else
Of course timer NMIs should be avoided during the measurement. If interrupts are already disabled it can be shortened by 3 bytes.
tod_cia = $dc08 ; or $dd08 tod_calibrate ldy #255 jsr tod_prescale ; use 50 Hz php ; no interrupts sei ; while measuring jsr tod_measure jsr tod_measure plp tod_prescale lda tod_cia+6 asl a cpy #204 ; threshold ror a sta tod_cia+6 ; set pre-scaler rts tod_measure ldy #0 sty tod_cia tod_lp2 lda #64 tod_lp cpx $d012 beq tod_lp ldx $d012 lsr a bne tod_lp lda tod_cia bne tod_done iny bne tod_lp2 tod_done rts
base/tod_calibration.1558244949.txt.gz · Last modified: 2019-05-19 07:49 by soci