| |
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.... |
| |
Sokrates
Registered: Jun 2014 Posts: 7 |
Quote: The module version of Spike+Minestorm have a drean detection and support it, also Jars Revenge ...
Could you elaborate on that please? Maybe in a new thread "extra features in games/demos for drean" or so? |
| |
Peiselulli
Registered: Oct 2006 Posts: 81 |
"support" only means that my (typical) CIA timers are adjusted if the different machines are detected, so the games will work. No more, no less. |
| |
Silver Dream !
Registered: Nov 2005 Posts: 108 |
FYI - added a different approach to codebase64 a few days ago. Can save some bytes in specific situations.
http://codebase64.org/doku.php?id=base:efficient_tod_initialisa.. |
| |
TWW
Registered: Jul 2009 Posts: 545 |
Interesting.
This is the way I detect the frequency (after determining the model):
// Detect AC Frequency
// ===================
// PAL TEST 50Hz: #$7f
// PAL TEST 60Hz: #$32
// NTSC TEST 50Hz: #$b3
// NTSC TEST 60Hz: #$70
// NTSC2 TEST 50Hz: #$b3
// NTSC2 TEST 60Hz: #$70
// DREAN TEST 50Hz: #$70
// DREAN TEST 60Hz: #$20
DetectACFrequency:
lda #$ff
sta $dc04
sta $dc05 // CIA #1 Timer A = #$ffff
sta $dc06
sta $dc07 // CIA #1 Timer B = #$ffff
lda #$00
sta $dc0b
sta $dc0a
sta $dc09
sta $dc08 // CIA #1 TOD set to 00:00:00:00
ldx #%10000001 // CIA #1 Timer A Start + TOD = 50 Hz
lda VideoSystem
beq !+ // Branch if PAL (use 50Hz)
cmp #$03
beq !+ // Branch if DREAN (use 50Hz)
ldx #%00000001 // CIA #1 Timer A Start + TOD = 60 Hz (NTSC/NTSC2)
!: ldy #%01000001 // CIA #1 Timer B Start + Sync with Timer A
lda $dc08
!: cmp $dc08
beq !- // Wait untill TOD changes with 1/10 second
stx $dc0e // CIA #1 Timer A Start
sty $dc0f // CIA #1 Timer B Start
lda $dc08
!: cmp $dc08
beq !- // Wait untill TOD changes with 1/10 second
lda $dc05
ldx VideoSystem
beq PALorDREAN
cpx #$03
beq PALorDREAN
NTSCorNTSC2:
cmp Table50Hz,x
bne TOD50Hz
jmp TOD60Hz
PALorDREAN:
cmp Table50Hz,x
bne TOD60Hz
TOD50Hz:
lda #$81
ldx #$80
ldy #50
jmp !+
TOD60Hz:
lda #$01
ldx #$00
ldy #60
!: sta $dc0e
stx $dd0e // Set correct frequency on TOD Clocks and initialize CIA #1 & #2 Control Register A
sty ACMains
rts
//---------------------------------------------------------------------
// DATA: 50/60 Hz Detection Table
//
// PAL/50 - #$fffe 7f 28 - 98.519 cycles => MPU Clock = 0,985 MHz
// PAL/60 - #$fffe 32 24 - 118.235 cycles
//
// NTSC/50 - #$fffe b3 0f - 85.232 cycles
// NTSC/60 - #$fffe 70 7d - 102.274 cycles => MPU Clock = 1,023 MHz
//
// NTSC2/50 - #$fffe b3 12 - 85.229 cycles
// NTSC2/60 - #$fffe 70 6b - 102.292 cycles => MPU Clock = 1,023 MHz
//
// DREAN/50 - #$fffe 70 23 - 102.326 cycles => MPU Clock = 1,023 MHz
// DREAN/60 - #$fffe 20 32 - 122.829 cycles
Table50Hz: // Values to detect that
.byte $7f // PAL
.byte $70 // NTSC_OLD
.byte $70 // NTSC
.byte $70 // DREAN
Works in all configs of vice using a regular C64 but that 'could' be missguiding ,-) |
| |
Silver Dream !
Registered: Nov 2005 Posts: 108 |
I basically needed simple way to properly initialise TOD. Being lazy I had a look at what was available on codebase but found only something I wouldn't want to use for a few reasons. Therefore I fired up a spreadsheet, calculated what was needed and wrote my own. Once done, adding only two CMPs looked like a no-brainer. |
| |
TWW
Registered: Jul 2009 Posts: 545 |
Do please share 8-) |
| |
Krill
Registered: Apr 2002 Posts: 2969 |
I'm not sure i understand. The aim is to detect the mains frequency regardless of the computer's native video mode? E.g.., be able to detect a PAL C-64 running in NTSC land and vice versa, for some reason? Why? :) |
| |
soci
Registered: Sep 2003 Posts: 479 |
Put there a large tolerance (like 4Hz) if it's used for anything important.
It's not like the mains frequency is always the same. The machine could run off generator/ups or some refurbished AT/ATX supply with a 12V inverter. Or someone just stuck in a 555 internally instead of bothering to build that inverter and set the trimmer so that the TOD speed "feels about right". |
| |
Silver Dream !
Registered: Nov 2005 Posts: 108 |
Quoting KrillI'm not sure i understand. The aim is to detect the mains frequency regardless of the computer's native video mode? E.g.., be able to detect a PAL C-64 running in NTSC land and vice versa, for some reason? Why? :)
The aim was neither to detect mains frequency (mains frequency is not necessarily the same as TOD ticks) nor the video norm. It was to detect TOD ticks frequency so that TOD can be set correctly up before being used. An old problem, to which I felt like better approach was needed. Only as a side-effect it can also detect the video norm. Therefore – if your PRG needs both TOD and PAL/NTSC – it's probably the most time/byte efficient approach. |
| |
Silver Dream !
Registered: Nov 2005 Posts: 108 |
Quoting sociPut there a large tolerance (like 4Hz) if it's used for anything important.
It's not like the mains frequency is always the same. The machine could run off generator/ups or some refurbished AT/ATX supply with a 12V inverter. Or someone just stuck in a 555 internally instead of bothering to build that inverter and set the trimmer so that the TOD speed "feels about right".
Mains frequency is expected to be long-term stable. So yes, you are generally right. For something short-term important TOD's neither really accurate nor granular enough. As for what it runs off is a different thing. Surely you can't account for all possible modifications/deviations when you have only binary choice between expected 50 and 60Hz in the chip. |
Previous - 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 - Next |