Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Harvey ! (Registered 2024-11-25) 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-09-29 19:58
Sokrates

Registered: Jun 2014
Posts: 7
Quote: Saw your edit on codebase - thanks for that!

Wonder whenever some special fix becomes drean-only or such. Those few more cycles likely only add advantage on calculations for some games, hm?


Does anyone know about games/demos using the extra cycles of the drean?

My interest was only to have stable rasterlines for all VIC types. Just to be complete.

@TWW: I found your webpage about this topic after you post :-)
2016-09-30 23:13
Peiselulli

Registered: Oct 2006
Posts: 81
The module version of Spike+Minestorm have a drean detection and support it, also Jars Revenge ...
2016-10-01 01:02
Fungus

Registered: Sep 2002
Posts: 680
already discussed here a couple years ago detecting pal, drean, ntsc or old ntsc
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: 545
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: 545
Do please share 8-)
2019-05-17 00:26
Krill

Registered: Apr 2002
Posts: 2969
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? :)
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
Shake/Role
Alakran_64
fegolhuzz
Mythus/Delysid
kbs/Pht/Lxt
Bob/Censor Design
jmagic
celticdesign/G★P/M..
rexbeng
Holy Moses/Role
Higgie/Kraze/Slackers
Scooby/G★P/Light
Guests online: 129
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Mojo  (9.6)
6 The Demo Coder  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Wonderland XIV  (9.6)
10 Comaland 100%  (9.6)
Top onefile Demos
1 Layers  (9.6)
2 Party Elk 2  (9.6)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.6)
5 Libertongo  (9.5)
6 Rainbow Connection  (9.5)
7 Onscreen 5k  (9.5)
8 Morph  (9.5)
9 Dawnfall V1.1  (9.5)
10 It's More Fun to Com..  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Nostalgia  (9.3)
5 Triad  (9.2)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Crossbow  (9.8)
4 Lft  (9.8)
5 HCL  (9.8)

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