From 2afe11c3b313999f86ba7f26bd3e6e2e5270256d Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Sun, 20 Oct 2019 16:14:54 +0200 Subject: [PATCH] moved PAL/NTSC support to a separate routine --- c64/kernal/init/fda3.ioinit.s | 18 +-------- c64/kernal/init/ff5b.cint.s | 44 +-------------------- c64/kernal/init/setup_pal_ntsc.s | 65 ++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 60 deletions(-) create mode 100644 c64/kernal/init/setup_pal_ntsc.s diff --git a/c64/kernal/init/fda3.ioinit.s b/c64/kernal/init/fda3.ioinit.s index 21db2594..0337ec11 100644 --- a/c64/kernal/init/fda3.ioinit.s +++ b/c64/kernal/init/fda3.ioinit.s @@ -8,6 +8,7 @@ // CPU registers that has to be preserved (see [RG64]): none // + IOINIT: // Set $00/$01 port mode and value @@ -75,22 +76,6 @@ IOINIT: sta CIA2_ICR sta CIA1_ICR - // Set timer interval to ~1/60th of a second - - // Probably NTSC is the default one, as PAL support was introduced later, - // in a patch - see [CM64] page 242 and page: - // - http://commodore64.se/wiki/index.php/Commodore_64_KERNAL_ROM_versions - // "The KERNAL ROM R1 was obviously used only in early NTSC systems. It lacks the PAL/NTSC detection" - - // NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), - // is clocked at 1.022727 MHz, so that 1/60s is 17045 CPU cycles - - ldy #<17045 - ldx #>17045 - - sty CIA1_TIMALO - stx CIA1_TIMAHI - // Enable timer interrupt lda #$81 sta CIA1_ICR @@ -117,4 +102,3 @@ IOINIT: // Set IEC bus to its initial idle state jmp iec_set_idle - diff --git a/c64/kernal/init/ff5b.cint.s b/c64/kernal/init/ff5b.cint.s index 3be82f54..6f8fe591 100644 --- a/c64/kernal/init/ff5b.cint.s +++ b/c64/kernal/init/ff5b.cint.s @@ -11,46 +11,4 @@ CINT: jsr cint_legacy - -cint_check_pal_ntsc: - - // Detect video system (PAL/NTSC), use Graham's method, as it's short and reliable - // see here: https://codebase64.org/doku.php?id=base:detect_pal_ntsc - - lda VIC_RASTER -!: - cmp VIC_RASTER - beq !- - bmi cint_check_pal_ntsc - - // Result in A, if no interrupt happened during the test: - // #$37 -> 312 rasterlines, PAL, VIC 6569 - // #$06 -> 263 rasterlines, NTSC, VIC 6567R8 - // #$05 -> 262 rasterlines, NTSC, VIC 6567R56A - - cmp #$07 - bcc cont_done - -cint_pal: - - // (This value was calculated by running a custom IRQ handler on a C64 - // with original KERNAL, and writing the values of $DC04/5 to the screen - // in the IRQ handler to see roughly what value the timers must be set to) - // ldy #<16380 - // ldx #>16380 - - // PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), - // is clocked at 0.985248 MHz, so that 1/60s is 16421 CPU cycles - - ldy #<16421 - ldx #>16421 - - sty CIA1_TIMALO - stx CIA1_TIMAHI - - lda #$01 -!: - sta TVSFLG - -cont_done: - rts + jmp setup_pal_ntsc diff --git a/c64/kernal/init/setup_pal_ntsc.s b/c64/kernal/init/setup_pal_ntsc.s new file mode 100644 index 00000000..0b5ae619 --- /dev/null +++ b/c64/kernal/init/setup_pal_ntsc.s @@ -0,0 +1,65 @@ + +// Detect video system (PAL/NTSC), use Graham's method, as it's short and reliable +// see here: https://codebase64.org/doku.php?id=base:detect_pal_ntsc + + +setup_pal_ntsc: + + lda VIC_RASTER +!: + cmp VIC_RASTER + beq !- + bmi setup_pal_ntsc + + // Result in A, if no interrupt happened during the test: + // #$37 -> 312 rasterlines, PAL, VIC 6569 + // #$06 -> 263 rasterlines, NTSC, VIC 6567R8 + // #$05 -> 262 rasterlines, NTSC, VIC 6567R56A + + cmp #$07 + bcc setup_ntsc + + // FALLTROUGH + +setup_pal: + + // Set timer interval to ~1/60th of a second + + // (This value was calculated by running a custom IRQ handler on a C64 + // with original KERNAL, and writing the values of $DC04/5 to the screen + // in the IRQ handler to see roughly what value the timers must be set to) + // ldy #<16380 + // ldx #>16380 + + // PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), + // is clocked at 0.985248 MHz, so that 1/60s is 16421 CPU cycles + + ldy #<16421 + ldx #>16421 + + lda #$01 + + // FALLTROUGH + +setup_pal_ntsc_end: + + sty CIA1_TIMALO + stx CIA1_TIMAHI + + sta TVSFLG + + rts + +setup_ntsc: + + // Set timer interval to ~1/60th of a second + + // NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking), + // is clocked at 1.022727 MHz, so that 1/60s is 17045 CPU cycles + + ldy #<17045 + ldx #>17045 + + lda #$00 + + beq setup_pal_ntsc_end // branch always