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 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....
 
2020-11-07 18:34
Silver Dream !

Registered: Nov 2005
Posts: 108
Quoting Copyfault
I'll maybe try this later, should become even shorter than the above.


<shameless_promo>
I guess getting shorter than
	LDA $D03E
	AND #$07

with BeamRacer would be more than difficult ;-)

000 - NTSC (6567R8 or 8562)
110 - PAL (6569 or 8565)
100 - PAL-N (6572)
011 - NTSC (6567R56A)
</shameless_promo>

But I still find this novelty method really cool.
2020-11-08 01:31
Copyfault

Registered: Dec 2001
Posts: 467
Quoting Frantic
As usual: Please feel free to add stuff like this to Codebase. Generations of C64 coders will thank you for all eternity. :)
I will, but I have to dig out my password from the depth of disorder hell /o\

Meanwhile, I tried the wait-only-approach. This is how it looks like currently:
             sei
wait_lower:  
             bit $d011
             bpl wait_lower
             ldx #$fc
waitline:    cpx $d012
             bne waitline
             nop
             nop
wait40lines: lda $d012
             //pagebreak
             dex
             bne wait40lines
             and #$03
             rts
The two NOPs are disturbing, but without them the LDA $D012 inside of the waitloop can fetch the rasterline value too early in some cases (for EU-PAL). This way it delivers (values after AND listed):
$00: EU-PAL
$01: NTSC old
$02: PAL-N
$03: NTSC-new

I'm sure there are other possibilities for the loop length. But it's already quite short I think (@Silver Dream: and BeamRacer *is* cheating!!!;)).
2020-11-08 10:27
Peiselulli

Registered: Oct 2006
Posts: 81
maybe replace one nop with "ldy #$ff" and use "lda $d012-$ff,y" to get rid of the pagebreak ?
2020-11-08 13:18
Copyfault

Registered: Dec 2001
Posts: 467
Quoting Peiselulli
maybe replace one nop with "ldy #$ff" and use "lda $d012-$ff,y" to get rid of the pagebreak ?
Wanted to let it be, but... maybe like this:
             sei
             ldy #$01
             ldx #$fc
waitline:    cpx $d012
             bne waitline
             dey
             bpl waitline
wait40lines: lda $d012-$ff,y
             dex
             bne wait40lines
             and #$03
             rts
The double-check of line $fc should ensure that we do not leave it "inbetween". Downside: we also need y-reg, but the pagebreak is gone \o/
2020-11-08 13:58
Frantic

Registered: Mar 2003
Posts: 1633
Quoting copyfault
Downside: we also need y-reg


I'd say this type of code is typically executed in a context where it is not a problem if many sid registers are (ab)used, like.. some init code somewhere or so. So the use of the y-register isn't much of a drawback here, I guess?
2020-11-08 14:06
chatGPZ

Registered: Dec 2001
Posts: 11154
many sid registers
coffee!
2020-11-08 14:10
Frantic

Registered: Mar 2003
Posts: 1633
Ah.. Haha.. yes, maybe I should have a cup of coffee to wake up properly. I obviously meant cpu registers.
2020-11-08 14:23
Copyfault

Registered: Dec 2001
Posts: 467
Quoting Frantic
Ah.. Haha.. yes, maybe I should have a cup of coffee to wake up properly. I obviously meant cpu registers.
You were hearing the melody of that code, weren't you *rotfl*

By the way, I think y must be init'ed with a higher value since it might not be enough to double-check line $fc.

Before porting it to codebase I'll check it at least on vice with the different VIC-type settings.


Aaaand: coffee ftw!!!
2020-11-08 20:55
Copyfault

Registered: Dec 2001
Posts: 467
The idea with checking the same line multiple times was crap! We need to ensure (somehow) that we start at a line that exists on all systems and is unique AND that the edge case of starting the routine while IN this specific line is avoided/handled. No matter what value we choose for y, there will still be cases that lead to a wrong starting situation.

So here comes my final (and hopefully robust-as-f*ck) version:
chk_victype: sei
             ldy #$04
ld_DEY:      ldx #DEY     //DEY = $88
waitline:    cpy $d012
             bne waitline
             dex
             bmi ld_DEY + 1
wait40lines: lda $d012 - $7f,x
             dey
             bne wait40lines
             and #$03
             rts
If someone with real machines wants to volunteer to test it, send me a pm. Ah, and I'll feed codebase within the next days, promised!
2020-11-09 07:36
Knight Rider

Registered: Mar 2005
Posts: 116
I have all 4 machines.
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
t0m3000/HF^BOOM!^IBX
Heavy Head/NetPhreak..
goto80/HT
pcollins/Quantum
Mihai
Majikeyric
Guests online: 117
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 Diskmag Editors
1 Magic  (9.4)
2 Jazzcat  (9.4)
3 hedning  (9.2)
4 Elwix  (9.1)
5 Remix  (9.1)

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