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....
 
2020-11-11 14:39
Copyfault

Registered: Dec 2001
Posts: 474
Quoting Knight Rider
I am sure the purists will argue that the SEI in the routine could lead to false results in some circumstances
Well, the SEI was the smallest solution to switch off IRQs (besides NMI ofcourse). As mentioned in the introductory text for the full VIC-detection routine, the routine requires to be run in a badline- and IRQ-free environment. Since such a VIC-detect-routine is usually called when initialising also other things, I don't think the SEI is a real problem here - depending on how you arrange your overall init code, it could even be ommitted.


Quoting JackAsser
Really elegant! I might switch to that.
...
Thanks! Feel free to use it if it improves things on the project. Ah, and thanks for sharing your code;)
2020-11-11 14:40
Krill

Registered: Apr 2002
Posts: 2968
Quoting JackAsser
then check what raster line I'm on:
		[...]
		bne :+
		[...]
		bne :+
		[...]
Is there a specific reason to check for equality rather than ranges? =)
2020-11-11 14:53
Krill

Registered: Apr 2002
Posts: 2968
Quoting Copyfault
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
Does this boil down to the same basic approach i suggested in https://csdb.dk/forums/?roomid=11&topicid=94459#146098 - but squeezed for size? =)
2020-11-11 15:32
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Quoting JackAsser
then check what raster line I'm on:
		[...]
		bne :+
		[...]
		bne :+
		[...]
Is there a specific reason to check for equality rather than ranges? =)


Not really no, but bcc and bcs are so complicated. :D
2020-11-11 15:39
Copyfault

Registered: Dec 2001
Posts: 474
Quoting Krill
[...]Does this boil down to the same basic approach i suggested in https://csdb.dk/forums/?roomid=11&topicid=94459#146098 - but squeezed for size? =)
Correct! I pointed this out in the text I wrote on codebase, i.e. that the idea was brought up by a certain Krill;)

Have to admit that I had this idea on my own but it took me some days until I fully realised that this idea was not new at all, but rather the reason for your post here in the thread (see link above). Well, that tunnel thing /o\
2020-11-11 21:22
Krill

Registered: Apr 2002
Posts: 2968
Quoting JackAsser
Not really no, but bcc and bcs are so complicated. :D
Though you were obviously joking... i use to picture CMP as just an SBC that doesn't store the result and has a built-in SEC. Then it becomes quite easy to decide between BCS (A/X/Y >= value) and BCC (A/X/Y < value). :)
2020-11-11 21:38
Frantic

Registered: Mar 2003
Posts: 1646
Quote: Quoting JackAsser
Not really no, but bcc and bcs are so complicated. :D
Though you were obviously joking... i use to picture CMP as just an SBC that doesn't store the result and has a built-in SEC. Then it becomes quite easy to decide between BCS (A/X/Y >= value) and BCC (A/X/Y < value). :)


Hehe.. Yeah, that's exactly how I think about it as well. So far so good, but if we talk about the v-flag instead (as associated with bvc/bvs), I have to confess that it is much less clear to me how to conceptualize it. Sometimes I use it with the BIT instruction, but then I just treat it as... a bit, e.g. a way to check the status of bit6. Using it with ADC/SBC is another issue. Anyway, back to topic. :)
2020-11-11 21:44
TWW

Registered: Jul 2009
Posts: 545
Should also work:


// NTSC Old:		00
// PAL:			01
// Drean:		10
// NTSC:		11

    ldx #%10011001
    stx $dc04
    stx $dc05
    cpx $d012
    bne *-3
    stx $dc0e
    dex
    cpx $d012
    bne *-3
    lda $dc05
    and #%00000011



There is probably a 'magic' value one can use to omit setting dc04 and bring this down to 10 lines of code but it's still more bytes so I can't be bothered :). It get's the job done in less than a frame though^^

If you have VSYNC somewhere else in your code, you could substitute the cpx/bne and dex/cpx/bne for two jsr'r but I guess that is cheating in this context.
2020-11-11 21:48
Krill

Registered: Apr 2002
Posts: 2968
Quoting Frantic
Hehe.. Yeah, that's exactly how I think about it as well. So far so good, but if we talk about the v-flag instead (as associated with bvc/bvs), I have to confess that it is much less clear to me how to conceptualize it. Sometimes I use it with the BIT instruction, but then I just treat it as... a bit, e.g. a way to check the status of bit6. Using it with ADC/SBC is another issue. Anyway, back to topic. :)
Sorry for staying off-topic for another post. :)

The V-flag can only be set if the signs of both operands match. And then it gets set if the result's sign is the opposite of both operands' sign.

I.e., adding two positive numbers and getting a negative result would be... unexpected in certain scenarios, thus overflow. :D

(Analogous with subtraction.)

HTH! :D (And also hope i got it right.)
2020-11-12 08:24
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: Should also work:


// NTSC Old:		00
// PAL:			01
// Drean:		10
// NTSC:		11

    ldx #%10011001
    stx $dc04
    stx $dc05
    cpx $d012
    bne *-3
    stx $dc0e
    dex
    cpx $d012
    bne *-3
    lda $dc05
    and #%00000011



There is probably a 'magic' value one can use to omit setting dc04 and bring this down to 10 lines of code but it's still more bytes so I can't be bothered :). It get's the job done in less than a frame though^^

If you have VSYNC somewhere else in your code, you could substitute the cpx/bne and dex/cpx/bne for two jsr'r but I guess that is cheating in this context.


Really neat!
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
Walt/Bonzai
t0m3000/hf^boom!^ibx
Holy Moses/Role
Mr. Spock/T'Pau
subjik/F4CG
sLASH
Conjuror
REBEL 1/HF
Kakka/Extend, Damone..
CopAss/Leader
Glenn/Shape
Electric/Extend
Epyx/TSA
Copyfault/TOM/tsn
sebalozlepsi
Barfly/Extend
QuasaR/CENTRiC
Peiselulli/tRSi
El Jefe/Slackers^sidD
Xiny6581/Dees Produc..
Exile/Anubis
Airwolf/F4CG
Alias Medron/Padua
Mojzesh/TGR🇬🇧
cobbpg
Vent
WVL/Xenon
MAT64
psych
Flex/Artline Designs
Gregfeel/Lepsi De, S..
TMA/Abyss-Connection
Twilight/Excess/Arcade
commodore_freak
Guests online: 171
Top Demos
1 Fishbomb  (9.9)
2 Next Level  (9.7)
3 13:37  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Mojo  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 Comaland 100%  (9.6)
10 No Bounds  (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 Censor Design  (9.3)
Top Diskmag Editors
1 Magic  (9.8)
2 hedning  (9.6)
3 Jazzcat  (9.5)
4 Elwix  (9.1)
5 Remix  (9.1)

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