| |
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.... |
| |
Copyfault
Registered: Dec 2001 Posts: 474 |
Quoting KrillQuoting CopyfaultUnfortunately, it's not possible to distinguish between EU-PAL and PAL-N Aw. Nice routine, but i need PAL-N detection. =) That can be helped ;)chk_ntsc: ldx #TAX
lda $d012
bne chk_ntsc+1
txa
bmi chk_ntsc
wait10lines: cmp #$37
bne end_chk
dex
cpx $0a
cpx #$0a
bne wait10lines
cpx $d012
bne end_chk
lda #00
end_chk: and #$03
rts
Ends with A (now != X)
$00: EU-PAL (63 cycles per line)
$01: old NTSC (64 cycles per line)
$02: standard NTSC (65 cycles per line)
$03: PAL-N (Dreany 65-cycles per one of the 312 lines)
Did not test thoroughly, but the waitloop should suffice to shift the cycle-pos to line $09 in case of a 65-cycles-per-line-system, for any cycle position the wait10lines-loop can start with. Bet it can be shortened even more, but... not this session, at least for me;)
Another minus: ends on different rasterlines ($00 on ntsc, $0a on PAL). Maybe a plus, depends on how you look at it... |
| |
Copyfault
Registered: Dec 2001 Posts: 474 |
chk_ntsc:
ldx #TAX
lda $d012
bne chk_ntsc+1
txa
wait10lines:
bmi chk_ntsc
cmp #$37
//pagebreak
bne end_chk
dex
cpx #$0a
bne wait10lines
cpx $d012
bne end_chk
lda #00
end_chk:
and #$03
rts
The bmi can be "embraced" for the waitloop - 2 bytes saved;) - but a pagebreak is needed in this case.
Another approach could be to wait for a rasterline that exists on all systems (i.e.$fc), then wait for 63*63 cycles. The rasterline which we're in after such a waitloop should uniquely determine the system. I'll maybe try this later, should become even shorter than the above. |
| |
Frantic
Registered: Mar 2003 Posts: 1646 |
As usual: Please feel free to add stuff like this to Codebase. Generations of C64 coders will thank you for all eternity. :) |
| |
Silver Dream !
Registered: Nov 2005 Posts: 108 |
Quoting CopyfaultI'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. |
| |
Copyfault
Registered: Dec 2001 Posts: 474 |
Quoting FranticAs 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!!!;)). |
| |
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 ? |
| |
Copyfault
Registered: Dec 2001 Posts: 474 |
Quoting Peiselullimaybe 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/ |
| |
Frantic
Registered: Mar 2003 Posts: 1646 |
Quoting copyfaultDownside: 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? |
| |
chatGPZ
Registered: Dec 2001 Posts: 11350 |
many sid registers
coffee! |
| |
Frantic
Registered: Mar 2003 Posts: 1646 |
Ah.. Haha.. yes, maybe I should have a cup of coffee to wake up properly. I obviously meant cpu registers. |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 - Next |