From 22d4b0d497e72779bcc328987fc69bca4a402178 Mon Sep 17 00:00:00 2001 From: Marco van den Heuvel Date: Thu, 8 Mar 2018 16:06:33 -0800 Subject: [PATCH] Improved tv timing detection for the c64. --- asminc/get_tv.inc | 2 ++ include/cbm.h | 4 +++- libsrc/c64/get_tv.s | 43 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/asminc/get_tv.inc b/asminc/get_tv.inc index 47e0d9c2a..2d4b5b253 100644 --- a/asminc/get_tv.inc +++ b/asminc/get_tv.inc @@ -11,6 +11,8 @@ .enum TV NTSC PAL + NTSC_OLD + PAL_N OTHER .endenum diff --git a/include/cbm.h b/include/cbm.h index 1395f700f..b121050af 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -150,7 +150,9 @@ struct cbm_dirent { #define TV_NTSC 0 #define TV_PAL 1 -#define TV_OTHER 2 +#define TV_NTSC_OLD 2 +#define TV_PAL_N 3 +#define TV_OTHER 4 unsigned char get_tv (void); /* Return the video mode the machine is using. */ diff --git a/libsrc/c64/get_tv.s b/libsrc/c64/get_tv.s index 4f46b8d64..8c73f6fa4 100644 --- a/libsrc/c64/get_tv.s +++ b/libsrc/c64/get_tv.s @@ -3,6 +3,11 @@ ; ; unsigned char get_tv (void); ; /* Return the video mode the machine is using */ +; +; Changed to actually detect the mode instead of using a flag +; Marco van den Heuvel, 2018-03-08 +; +; The detection goes wrong on accelerated machines for now. ; .include "c64.inc" @@ -13,8 +18,42 @@ .proc _get_tv - lda PALFLAG - ldx #0 + php + sei +timing_loop_0: + lda VIC_HLINE +timing_loop_1: + cmp VIC_HLINE + beq timing_loop_1 + bmi timing_loop_0 + and #$03 + cmp #$01 + bne check_ntsc + lda #TV::NTSC_OLD ; NTSC OLD constant + bne detected +check_ntsc: + cmp #$03 + bcc ntsc + +; check for PAL and PAL-N + + ldx #$00 + lda #$10 +timing_loop_2: + inx + cmp VIC_HLINE + bne timing_loop_2 + lda #TV::PAL ; PAL constant + cpx #$70 + bcc detected + lda #TV::PAL_N ; PAL-N constant +detected: + ldx #$00 + plp rts +ntsc: + lda #TV::NTSC ; NTSC constant + beq detected + .endproc -- 2.39.5