DetectTVType: ; Returns a=0 for NTSC, a=1 for PAL ; uses a, hl, de di ; disable interrupts ld a,%01100000 ; set VDP such that the screen is on out ($bf),a ; with VBlank interrupts enabled ld a,$81 out ($bf),a ld hl,$0000 ; init counter -: in a,($bf) ; get VDP status or a ; inspect jp p,- ; loop until frame interrupt flag is set -: in a,($bf) ; do the same again, in case we were unlucky and came in just or a ; before the start of the VBlank with the flag already set jp p,- ; the VDP must now be at the start of the VBlank -: inc hl ; (6 cycles) increment counter until interrupt flag comes on again in a,($bf) ; (11 cycles) or a ; (4 cycles) jp p,- ; (10 cycles) xor a ; reset carry flag, also set a=0 ld de,2048 ; see if hl is more or less than 2048 sbc hl,de ret c ; if less, return a=0 ld a,1 ret ; if more or equal, return a=1