Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user nurd ! (Registered 2024-06-16) You are not logged in - nap
CSDb User Forums


Forums > C64 Productions > PAL/NTSC detect
2003-01-29 18:35
Dr. Jay
Account closed

Registered: Jan 2003
Posts: 32
PAL/NTSC detect

Just wanted to share a quick routine that detects PAL/NTSC WITHOUT using interrupts or latches.

;pal/NTSC detect - 0 = PAL, non-zero = NTSC

palntsc
sei ; disable interrupts
wait
lda $d012
bne wait ; wait for rasterline 0 or 256
wait1
lda $d011 ; Is rasterbeam in the area
bpl wait1 ; 0-255? if yes, wait
wait2
ldy #$00
synch1 lda $d012
cmp #$37 ; top PAL rasterline
bne synch1
lda $d012 ; if next is 0, then PAL
synch2 cmp $d012
beq synch2
lda $d012
cli ; enable interrupts
rts ; return
 
... 67 posts hidden. Click here to view all posts....
 
2016-10-01 21:22
Sokrates

Registered: Jun 2014
Posts: 7
Quote: The module version of Spike+Minestorm have a drean detection and support it, also Jars Revenge ...

Could you elaborate on that please? Maybe in a new thread "extra features in games/demos for drean" or so?
2016-10-04 10:14
Peiselulli

Registered: Oct 2006
Posts: 81
"support" only means that my (typical) CIA timers are adjusted if the different machines are detected, so the games will work. No more, no less.
2019-05-15 20:13
Silver Dream !

Registered: Nov 2005
Posts: 108
FYI - added a different approach to codebase64 a few days ago. Can save some bytes in specific situations.

http://codebase64.org/doku.php?id=base:efficient_tod_initialisa..
2019-05-15 21:42
TWW

Registered: Jul 2009
Posts: 541
Interesting.

This is the way I detect the frequency (after determining the model):

    // Detect AC Frequency
    // ===================
    // PAL TEST 50Hz:   #$7f
    // PAL TEST 60Hz:   #$32
    // NTSC TEST 50Hz:  #$b3
    // NTSC TEST 60Hz:  #$70
    // NTSC2 TEST 50Hz: #$b3
    // NTSC2 TEST 60Hz: #$70
    // DREAN TEST 50Hz: #$70
    // DREAN TEST 60Hz: #$20

DetectACFrequency:
    lda #$ff
    sta $dc04
    sta $dc05              // CIA #1 Timer A = #$ffff
    sta $dc06
    sta $dc07              // CIA #1 Timer B = #$ffff
    lda #$00
    sta $dc0b
    sta $dc0a
    sta $dc09
    sta $dc08              // CIA #1 TOD set to 00:00:00:00
    ldx #%10000001         // CIA #1 Timer A Start + TOD = 50 Hz
    lda VideoSystem
    beq !+                 // Branch if PAL (use 50Hz)
    cmp #$03
    beq !+                 // Branch if DREAN (use 50Hz)
    ldx #%00000001         // CIA #1 Timer A Start + TOD = 60 Hz (NTSC/NTSC2)
!:  ldy #%01000001         // CIA #1 Timer B Start + Sync with Timer A
    lda $dc08
!:  cmp $dc08
    beq !-                 // Wait untill TOD changes with 1/10 second
    stx $dc0e              // CIA #1 Timer A Start
    sty $dc0f              // CIA #1 Timer B Start
    lda $dc08
!:  cmp $dc08
    beq !-                 // Wait untill TOD changes with 1/10 second
    lda $dc05


    ldx VideoSystem
    beq PALorDREAN
    cpx #$03
    beq PALorDREAN
NTSCorNTSC2:
    cmp Table50Hz,x
    bne TOD50Hz
    jmp TOD60Hz

PALorDREAN:
    cmp Table50Hz,x
    bne TOD60Hz
TOD50Hz:
    lda #$81
    ldx #$80
    ldy #50
    jmp !+
TOD60Hz:
    lda #$01
    ldx #$00
    ldy #60
!:  sta $dc0e
    stx $dd0e  // Set correct frequency on TOD Clocks and initialize CIA #1 & #2 Control Register A
    sty ACMains
    rts

    //---------------------------------------------------------------------
    // DATA: 50/60 Hz Detection Table
    //
    // PAL/50   - #$fffe 7f 28 -  98.519 cycles => MPU Clock = 0,985 MHz
    // PAL/60   - #$fffe 32 24 - 118.235 cycles
    //
    // NTSC/50  - #$fffe b3 0f -  85.232 cycles
    // NTSC/60  - #$fffe 70 7d - 102.274 cycles => MPU Clock = 1,023 MHz
    //
    // NTSC2/50 - #$fffe b3 12 -  85.229 cycles
    // NTSC2/60 - #$fffe 70 6b - 102.292 cycles => MPU Clock = 1,023 MHz
    //
    // DREAN/50 - #$fffe 70 23 - 102.326 cycles => MPU Clock = 1,023 MHz
    // DREAN/60 - #$fffe 20 32 - 122.829 cycles

Table50Hz:  // Values to detect that 
    .byte $7f  // PAL
    .byte $70  // NTSC_OLD
    .byte $70  // NTSC
    .byte $70  // DREAN


Works in all configs of vice using a regular C64 but that 'could' be missguiding ,-)
2019-05-16 16:00
Silver Dream !

Registered: Nov 2005
Posts: 108
I basically needed simple way to properly initialise TOD. Being lazy I had a look at what was available on codebase but found only something I wouldn't want to use for a few reasons. Therefore I fired up a spreadsheet, calculated what was needed and wrote my own. Once done, adding only two CMPs looked like a no-brainer.
2019-05-17 00:12
TWW

Registered: Jul 2009
Posts: 541
Do please share 8-)
2019-05-17 00:26
Krill

Registered: Apr 2002
Posts: 2856
I'm not sure i understand. The aim is to detect the mains frequency regardless of the computer's native video mode? E.g.., be able to detect a PAL C-64 running in NTSC land and vice versa, for some reason? Why? :)
2019-05-17 07:40
soci

Registered: Sep 2003
Posts: 474
Put there a large tolerance (like 4Hz) if it's used for anything important.

It's not like the mains frequency is always the same. The machine could run off generator/ups or some refurbished AT/ATX supply with a 12V inverter. Or someone just stuck in a 555 internally instead of bothering to build that inverter and set the trimmer so that the TOD speed "feels about right".
2019-05-17 11:39
Silver Dream !

Registered: Nov 2005
Posts: 108
Quoting Krill
I'm not sure i understand. The aim is to detect the mains frequency regardless of the computer's native video mode? E.g.., be able to detect a PAL C-64 running in NTSC land and vice versa, for some reason? Why? :)

The aim was neither to detect mains frequency (mains frequency is not necessarily the same as TOD ticks) nor the video norm. It was to detect TOD ticks frequency so that TOD can be set correctly up before being used. An old problem, to which I felt like better approach was needed. Only as a side-effect it can also detect the video norm. Therefore – if your PRG needs both TOD and PAL/NTSC – it's probably the most time/byte efficient approach.
2019-05-17 11:48
Silver Dream !

Registered: Nov 2005
Posts: 108
Quoting soci
Put there a large tolerance (like 4Hz) if it's used for anything important.

It's not like the mains frequency is always the same. The machine could run off generator/ups or some refurbished AT/ATX supply with a 12V inverter. Or someone just stuck in a 555 internally instead of bothering to build that inverter and set the trimmer so that the TOD speed "feels about right".

Mains frequency is expected to be long-term stable. So yes, you are generally right. For something short-term important TOD's neither really accurate nor granular enough. As for what it runs off is a different thing. Surely you can't account for all possible modifications/deviations when you have only binary choice between expected 50 and 60Hz in the chip.
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
zzarko
Didi/Laxity
JCH/Vibrants
rexbeng
Endurion
Apollyon/ALD
Guests online: 78
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.7)
6 Aliens in Wonderland  (9.6)
7 Comaland 100%  (9.6)
8 No Bounds  (9.6)
9 Uncensored  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Cubic Dream  (9.6)
3 Party Elk 2  (9.6)
4 Copper Booze  (9.6)
5 Rainbow Connection  (9.5)
6 It's More Fun to Com..  (9.5)
7 Dawnfall V1.1  (9.5)
8 Daah, Those Acid Pil..  (9.5)
9 Birth of a Flower  (9.5)
10 Quadrants  (9.5)
Top Groups
1 Nostalgia  (9.4)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 SHAPE  (9.3)
Top Logo Graphicians
1 Sander  (9.9)
2 Facet  (9.5)
3 Mermaid  (9.4)
4 Pal  (9.4)
5 Shine  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.038 sec.