Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > detecting pal, drean, ntsc or old ntsc
2012-11-26 14:21
Peiselulli

Registered: Oct 2006
Posts: 81
detecting pal, drean, ntsc or old ntsc

Hello,
I want to know if a test like this is reliable for the four different machine types PAL, NTSC, NTSC(old) and DREAN (ACME source code):

OLD_NTSC = 1
NTSC = 0
PAL = 2
DREAN = 3

        !to "detect.prg",cbm
	!cpu 6510

	* = $0801
	!by $0b,$08,$00,$00,$9e,$32,$30,$36,$31,$00,$00,$00
		
detect:	sei
w0:  	lda $d012
w1:  	cmp $d012
	beq w1
	bmi w0
	and #$03
	cmp #$01
	bne w2
	lda #OLD_NTSC
	bne detected ; unconditional
w2:	cmp #$03
	lda #$00
	rol
	beq detected	;ntsc

	;check for drean or pal
	ldx #$00
	lda #$10
l	inx
	cmp $d012
	bne l
	lda #PAL
	cpx #$70
	bcc detected
	;is a drean
	lda #DREAN
detected:
	tay
	lax offset,y
l2:	lda base_text,x
	beq end
	jsr $ffd2
	inx
	bne l2
end:	lda #$0d
	jmp $ffd2

base_text:
old_ntsc_text:	!text "OLD "
ntsc_text:	!text "NTSC",0
pal_text:	!text "PAL",0
drean_text:	!text "DREAN",0

offset:		
	!byte ntsc_text-base_text
	!byte old_ntsc_text-base_text
	!byte pal_text-base_text
	!byte drean_text-base_text


 
... 63 posts hidden. Click here to view all posts....
 
2014-01-21 21:47
MagerValp

Registered: Dec 2001
Posts: 1056
TWW's cycle counter is impressive, but seems like overkill for most things :) I prefer a straightforward approach:

init:
	lda #$7f	; Disable kernal IRQ.
	sta $dc0d
	
	lda #$ff	; Start on line 255.
:	cmp $d012
	bne :-
	
@nextline:
	lda $d012	; Wait until the next line.
:	cmp $d012
	beq :-		; A contains the previous line number.
	
	bit $d011	; Are we back on line 0?
	bmi @nextline
	
	ora #$30	; A contains the LSB of the last line number:
	sta $0400	;   $05 = 262 x 64 cycle NTSC
	lda #1		;   $06 = 263 x 65 cycle NTSC
	sta $d800	;   $37 = 312 x 63 cycle PAL or 312 x 65 cycle DREAN
2014-01-22 04:42
Peiselulli

Registered: Oct 2006
Posts: 81
@MagerValp : But the main reason for starting this thread is missing : detection between "drean" an "pal".
2014-01-22 04:48
TWW

Registered: Jul 2009
Posts: 541
Slightly improved version:

    // Use CIA #1 Timer B to count cycled in a frame
    lda #$ff
    sta $dc06
    sta $dc07  // Latch #$ffff to Timer B

    bit $d011
    bpl *-3    // Wait untill Raster > 256
    bit $d011
    bmi *-3    // Wait untill Raster = 0

    ldx #%00011001
    stx $dc0f  // Start Timer B (One shot mode (Timer stops automatically when underflow))

    bit $d011
    bpl *-3    // Wait untill Raster > 256
    bit $d011
    bmi *-3    // Wait untill Raster = 0

    sec
    sbc $dc07  // Hibyte number of total cycles
    and #%00000011
2014-01-22 05:21
Flavioweb

Registered: Nov 2011
Posts: 447
Here it is the stabilized TWW version:
INIT
    SEI
    CLD
    LDX #$FF
    TXS
    LDA #$2F
    STA $00
    LDA #$35
    STA $01
;-------------------
    LDX #<NO_NMI
    LDY #>NO_NMI
    STX $0318
    STY $0319
    STX $FFFA
    STY $FFFB
    LDY #$00
    STY $DC03                           ; Port $DC01 = Input
    DEY
    STY $DC02                           ; Port $DC00 = Output
;-------------------
    LDA #$7F
    STA $DC0D
    STA $DD0D
    LDA $DC0D
    LDA $DD0D
;-------------------
    LDA #$00
    STA $DD0E                           ; Stop CIA #2 Timer A
    STA $DD04
    STA $DD05                           ; Set Timer A = 0 (NMI will trigger immediately when Timer A is restarted)
    LDA #$81
    STA $DD0D                           ; Set Timer A as NMI source
    LDA #$01
    STA $DD0E                           ; Start Timer A (triggers NMI and unless the NMI get's acked, any new NMI's will be ignored).
    LDA #$00                            ; From this point on we will not be disturbed and can commence testing.
    STA $D015                           ; No Sprites
;------------------------------------------------------------------------------
; Detect the model
;---------------------------------------
; 312 rasterlines -> 63 cycles per line PAL        => 312 * 63 = 19656 Cycles / VSYNC
; 262 rasterlines -> 64 cycles per line NTSC V1    => 262 * 64 = 16768 Cycles / VSYNC
; 263 rasterlines -> 65 cycles per line NTSC V2    => 263 * 65 = 17095 Cycles / VSYNC
; 312 rasterlines -> 65 cycles per line PAL DREAN  => 312 * 65 = 20280 Cycles / VSYNC
;------------------------------------------------------------------------------
    LDA #$FF                            ; Use CIA #1 Timer A to count cycled in a frame
    STA $DC06
    STA $DC07                           ; Latch #$ffff to Timer B
    LDY #%00011001
    LDA #$7F
WAIT_BEAM_01
    CMP $D012
    BNE WAIT_BEAM_01
    BIT $DEAD
    BIT $BEEF
    STA $D011
    STY $DC0F                           ; Start Timer B (One shot mode (Timer stops automatically when underflow)
    LDY #$00
    LDA #$1B
    STA $D011
    LDA #$7F
WAIT_BEAM_02
    CMP $D012
    BNE WAIT_BEAM_02
    BIT $DEAD
    BIT $BEEF
    STA $D011
;-------------------
    STY $DC0F
    LDX $DC06
    LDY $DC07
    STY $0400
    STX $0401
    LDA #$1B                            ; TURN BACK ON SCREEN TO SEE RESULT
    STA $D011
;-------------------
WAIT_SOME_SPACE
    LDA $DC01
    AND $DC00
    AND #$10
    BNE WAIT_SOME_SPACE
    JMP INIT
;-------------------
NO_NMI
    RTI

In $0400/$0401 there are values to subtract from $FFFF to obtain cycles/VSYNC (-1).
PAL: $B338 ($FFFF-$B338 = $4CC7)
NTSC: $BD39 ($FFFF-$BD39 = $42C6)
DREAN: $B0C8 ($FFFF-$B0C8 = $4F37)

Tested on "x64 2.4.5 r27742M".
Someone can test it on real hardware?
2014-01-22 09:12
Fungus

Registered: Sep 2002
Posts: 621
Mine counted cycles also and used vsync to check. Although I made a small math error about old ntsc. sprites and DMA don't matter with a timer, since the clock runs independant of such stuff, and the up to 1 line delay doesn't matter really.

Nice different ways of checking, cool to see. Not that anyone cares about NTSC ;)
2014-01-22 11:45
MagerValp

Registered: Dec 2001
Posts: 1056
Quoting Peiselulli
@MagerValp : But the main reason for starting this thread is missing : detection between "drean" an "pal".

Yes, but that was in 2012, H Macaroni's thread necrophilia was regarding PAL vs NTSC. For Drean vs PAL it's of course a little more work.

I'd love to see some Drean releases though, two extra cycles per line should allow for some neat tricks not possible on PAL.
2014-01-22 20:56
Peiselulli

Registered: Oct 2006
Posts: 81
But unfortunately I'm waiting for a test result on a drean machine since then ;-(
2014-01-22 21:47
chatGPZ

Registered: Dec 2001
Posts: 11127
Quote:
I'd love to see some Drean releases though, two extra cycles per line should allow for some neat tricks not possible on PAL.

i'd love to see one or two people who own such machines and are willing to run a bunch of testprogs - because everything in VICE regarding drean is pure guesswork :)
2014-01-23 00:28
Durandal

Registered: May 2006
Posts: 30
Quote: Quote:
I'd love to see some Drean releases though, two extra cycles per line should allow for some neat tricks not possible on PAL.

i'd love to see one or two people who own such machines and are willing to run a bunch of testprogs - because everything in VICE regarding drean is pure guesswork :)


Me, hedning and Thierry already did 3 years ago ;)

http://csdb.dk/forums/?roomid=7&topicid=73859#81066

(unless there's some new tests that need to be done on the Drean)
2014-01-23 00:49
chatGPZ

Registered: Dec 2001
Posts: 11127
there are a couple new ones... not exactly sure which though, tlr is the VIC guy =)
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
Alakran_64
Unlock/Padua/Albion
Francesco Sblendorio
zzarko
t0m3000/ibex-crew
Kakka/Extend, Damone..
Krill/Plush
Guests online: 135
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Memento Mori  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 It's More Fun to Com..  (9.7)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 TRSAC, Gabber & Pebe..  (9.5)
6 Rainbow Connection  (9.5)
7 Wafer Demo  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Nostalgia  (9.3)
2 Oxyron  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Coders
1 Axis  (9.8)
2 Graham  (9.8)
3 Lft  (9.8)
4 Crossbow  (9.8)
5 HCL  (9.8)

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