User Tools

Site Tools


base:efficient_tod_initialisation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
base:efficient_tod_initialisation [2019-05-12 20:32] – [TOD initialisation - the problem] silverdrbase:efficient_tod_initialisation [2019-05-20 11:45] – [Proper solution] silverdr
Line 4: Line 4:
 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/colour encoding standards are NOT directly linked to mains power frequency. This means that checking which video standard the machine is of, should never be used to make assumptions about what the TOD frequency is. Not only PAL computers can be used in countries with 60Hz AC (and vice versa - NTSC computers can be run of 50Hz power) but in addition to that some computers do not derive their TOD clock frequency from the mains power source at all. For example both NTSC and PAL variants of Commodore SX-64 use 60 Hz TOD clock supplied by a dedicated crystal. 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/colour encoding standards are NOT directly linked to mains power frequency. This means that checking which video standard the machine is of, should never be used to make assumptions about what the TOD frequency is. Not only PAL computers can be used in countries with 60Hz AC (and vice versa - NTSC computers can be run of 50Hz power) but in addition to that some computers do not derive their TOD clock frequency from the mains power source at all. For example both NTSC and PAL variants of Commodore SX-64 use 60 Hz TOD clock supplied by a dedicated crystal.
 ===== Proper solution ===== ===== Proper solution =====
-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, increasing the byte-size savings even further.+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 (see below), increasing the byte-size savings even further.
 <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' original values. Last and least we do not disable NMIs as it is assumed that checking/setting the params will be done as part of application initialisation, before setting up IRQ/NMI handlers. 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' original values. Last and least we do not disable NMIs as it is assumed that checking/setting the params will be done as part of application initialisation, before setting up IRQ/NMI handlers.
Line 62: Line 67:
     ; we run on PAL machine with 60Hz TOD clock     ; we run on PAL machine with 60Hz TOD clock
 </code> </code>
-we can determine not only the TOD frequency but also the video standard. This is possible because – unlike the TOD frequency – the CPU clock frequency is directly related to the computer's video standard. PAL computers have their CPU (and CIAs) clocked at 985248.444Hz while NTSC ones run faster and have their CPU/CIAs clocked at 1022727.14Hz. This is a side-effect of deriving all (except TOD) required clock frequencies from a single crystal of either 14318180Hz (for NTSC machines) or 17734472Hz (for PAL ones).+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's video standard. PAL computers have their CPU (and CIAs) clocked at 985248.444Hz while NTSC ones run faster and have their CPU/CIAs clocked at 1022727.14Hz. This is a side-effect of deriving all (except TOD) required clock frequencies from a single crystal of either 14318180Hz (for NTSC machines) or 17734472Hz (for PAL ones).
base/efficient_tod_initialisation.txt · Last modified: 2020-10-27 02:31 by silverdr