base:efficient_tod_initialisation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
base:efficient_tod_initialisation [2019-05-11 20:08] – [Dual purpose] silverdr | base:efficient_tod_initialisation [2019-05-20 11:45] – [Proper solution] silverdr | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== TOD initialisation - the problem ====== | ====== TOD initialisation - the problem ====== | ||
- | Each [[https:// | + | Each [[https:// |
===== Popular misconception ===== | ===== Popular misconception ===== | ||
First let's say how NOT to do it. It is important to note that contrary to a very popular and utterly wrong belief, NTSC or PAL video/ | First let's say how NOT to do it. It is important to note that contrary to a very popular and utterly wrong belief, NTSC or PAL video/ | ||
===== Proper solution ===== | ===== Proper solution ===== | ||
- | While there are various | + | While there are various approaches to this problem, we believe the one presented below is not only the most compact but can also serve dual purpose |
<code 6502acme> | <code 6502acme> | ||
; Detecting TOD frequency by Silver Dream ! / Thorgal / W.F.M.H. | ; Detecting TOD frequency by Silver Dream ! / Thorgal / W.F.M.H. | ||
Line 44: | Line 44: | ||
which correspond to the four possible C64 hardware setup combinations. Comparing to $51, which falls more or less in the middle, gives us the expected answer. If the HI byte of the timer has value higher than $51 we have 60Hz supplied to the TOD pin. If OTOH it has lower value, we have 50Hz supplied. | which correspond to the four possible C64 hardware setup combinations. Comparing to $51, which falls more or less in the middle, gives us the expected answer. If the HI byte of the timer has value higher than $51 we have 60Hz supplied to the TOD pin. If OTOH it has lower value, we have 50Hz supplied. | ||
+ | |||
+ | Advantages: | ||
+ | * Does not break on Super-CPU and similar | ||
+ | * No screen side-effects | ||
+ | * Short and fast | ||
Please also note that we use CIA #2 and not CIA #1. CIA #2 is chosen because changing the timer values there does not affect regular IRQ timings. Moreover, KERNAL re-initialises those timers whenever it wants to use them. This saves as a few bytes, which would otherwise be needed to save and restore timer registers' | Please also note that we use CIA #2 and not CIA #1. CIA #2 is chosen because changing the timer values there does not affect regular IRQ timings. Moreover, KERNAL re-initialises those timers whenever it wants to use them. This saves as a few bytes, which would otherwise be needed to save and restore timer registers' | ||
Line 51: | Line 56: | ||
cmp #$29 ; about the middle between $20(c0) and $32(51) | cmp #$29 ; about the middle between $20(c0) and $32(51) | ||
bcs pal50 | bcs pal50 | ||
- | ; we run NTSC machine with 50Hz TOD clock | + | ; we run on NTSC machine with 50Hz TOD clock |
pal50: | pal50: | ||
- | ; we run PAL machine with 50Hz TOD clock | + | ; we run on PAL machine with 50Hz TOD clock |
ticks_60hz: | ticks_60hz: | ||
cmp #$78 ; about the middle between $70(a6) and $7f(4a) | cmp #$78 ; about the middle between $70(a6) and $7f(4a) | ||
bcs pal60 | bcs pal60 | ||
- | ; we run NTSC machine with 60Hz TOD clock | + | ; we run on NTSC machine with 60Hz TOD clock |
pal60: | pal60: | ||
- | ; we run PAL machine with 60Hz TOD clock | + | ; we run on PAL machine with 60Hz TOD clock |
</ | </ | ||
- | we can determine not only the TOD frequency but also the video standard. This is possible because – unlike | + | we can determine not only the TOD frequency but also the video norm. This is possible because – unlike TOD frequency – the CPU clock frequency is directly related to the computer' |
base/efficient_tod_initialisation.txt · Last modified: 2020-10-27 02:31 by silverdr