| |
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.... |
| |
tlr
Registered: Sep 2003 Posts: 1787 |
A quick way to determine the number of cycles per line is to start a timer at raster line 0 then wait until raster line 256 and check the MSB of the timer.
Correctly done (just some inversion) you'll now have the number of cycles directly.
I do this here: http://vice-emu.svn.sourceforge.net/viewvc/vice-emu/testprogs/V..
modesplit.asm, line 194, function check_time. |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
The easiest way to determine cycles/rasterline is to count the rasterlines:
312 rasterlines -> 63 cycles per line
263 rasterlines -> 65 cycles per line
262 rasterlines -> 64 cycles per line
Counting the lines:
w0 LDA $D012
w1 CMP $D012
BEQ w1
BCC w0
Result in Akku (low byte of rasterlinecount-1):
#$37 -> 312 rasterlines
#$06 -> 263 rasterlines
#$05 -> 262 rasterlines
|
| |
tlr
Registered: Sep 2003 Posts: 1787 |
It should be pointed out that my routine is designed for the purpose of hardware analysis and emulator evaluation.
I therefor require the number of cycles per line to be measured directly, not relying on the number of raster lines.
That routine should work with any timing encountered as long as there are more than 256 raster lines on the system.
There are no known hardware with timings different from those listed by Graham so normally you can use his method.
It will for almost all intents and purposes be equally accurate and shorter.
EDIT: nojoopa points out that the Drean PAL-N machine has 65 cycles per line and 312 raster lines so my statement about the known machines was wrong. |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
BCC should have been BMI
|
| |
Frantic
Registered: Mar 2003 Posts: 1647 |
I added TLR's and Graham's routines to codebase (the PAL/NTSC detect page) (and changed bcc to bmi).
//FTC |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
Slight improvement would be:
w0 LDA $D012
w1 CMP $D012
BEQ w1
BMI w0
AND #$03
#$03 -> 312 rasterlines
#$02 -> 263 rasterlines
#$01 -> 262 rasterlines
|
| |
Moloch
Registered: Jan 2002 Posts: 2925 |
Ancient thread brought back to life, but certainly some excellent examples recently posted. Will work nicely for my NTSC/PAL detection needs, thanks!
|
| |
Sokrates
Registered: Jun 2014 Posts: 7 |
Enhanced version to differ between PAL and PAL-N. First count rasterlines, then count cycles.
LDX #$00
w0 LDA $D012
w1 CMP $D012
BEQ w1
BMI w0
AND #$03
CMP #$03
BNE detectionDone ; done for NTSC
TAY
countCycles
INX
LDA $D012
BPL countCycles
CPX #$5E ; VICE values: PAL-N=$6C PAL=$50
; so choose middle value $5E for check
BCC isPAL
INY ; is PAL-N
isPAL
TYA
detectionDone
...
Results in the accumulator:
#$01: 262 rasterlines and 64 cycles per line [NTSC: 6567R56A VIC] (OLD NTSC)
#$02: 263 rasterlines and 65 cycles per line [NTSC: 6567R8 VIC]
#$03: 312 rasterlines and 63 cycles per line [PAL: 6569 VIC]
#$04: 312 rasterlines and 65 cycles per line [Drean PAL-N: 6572 VIC] |
| |
Count Zero
Registered: Jan 2003 Posts: 1927 |
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? |
| |
TWW
Registered: Jul 2009 Posts: 545 |
Another version:
.pseudocommand VSync {
bit $d011
bpl *-3
bit $d011
bmi *-3
}
lda #$ff
sta $dc04
sta $dc05 // Latch #$ffff to Timer A
:VSync
ldx #%00011001
stx $dc0e // Start Timer A (One shot mode (Timer stops automatically when underflow))
:VSync
sec
sbc $dc05 // Hibyte number of counter
and #%00000011
A now contains the video system as follows:
#0 - NTSC1
#1 - DREAN
#2 - PAL
#3 - NTSC2
Edit: Rectified bug. |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 - Next |