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 18:44] – silverdr | base:efficient_tod_initialisation [2020-01-31 17:49] – [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 36: | Line 36: | ||
</ | </ | ||
- | That's it. At this point we already know what the actual frequency is. If you don't know how this is done then a few explanations follow. We use timer 2 of second CIA to count the number of CPU cycles between two consecutive changes of TO2TEN register (CIA #2 - TOD, tenths of seconds) and – after accounting for the overhead cycles – expect the result to be approximately one of the four values: | + | And that's it. Really :-) At this point we already know what the actual frequency is. If you don't know how this is done then a few explanations follow. We use timer 2 of second CIA to count the number of CPU cycles between two consecutive changes of TO2TEN register (CIA #2 - TOD, tenths of seconds) and – after accounting for the overhead cycles |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
- | which correspond to the four possible hardware setup combinations | + | which correspond to the four possible |
- | 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' | + | 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 it timers are by default not used by the system. Moreover KERNAL initialises those timers according to its needs, whenever it wants to use them. This saves us a few bytes, which would otherwise be needed to preserve original settings. Last and least we do not disable NMIs as it is assumed that checking/ | ||
+ | ===== Dual purpose ===== | ||
+ | I mentioned before that this routine can serve also another purpose and give us potentially even more savings. Yes, with addition of only a few bytes: | ||
+ | <code 6502acme> | ||
+ | cmp #$29 ; about the middle between $20(c0) and $32(51) | ||
+ | bcs pal50 | ||
+ | ; we run on NTSC machine with 50Hz TOD clock | ||
+ | pal50: | ||
+ | ; we run on PAL machine with 50Hz TOD clock | ||
+ | ticks_60hz: | ||
+ | cmp #$78 ; about the middle between $70(a6) and $7f(4a) | ||
+ | bcs pal60 | ||
+ | ; we run on NTSC machine with 60Hz TOD clock | ||
+ | pal60: | ||
+ | ; we run on PAL machine with 60Hz TOD clock | ||
+ | </ | ||
+ | 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