Files
open-roms/c64/kernal/tape/tape_common_autodetect.s
T
FeralChild64 d489e7bf41 tape routines can now be placed in Mega65 extra ROM space
commit 2f27e29758da1f1ec965588c0712125051a6f71a
Merge: ba722b1 796b62f
Author: FeralChild64 <you@example.com>
Date:   Tue Jan 28 17:34:53 2020 +0100

    Merge branch 'master' into tape_redirect

commit ba722b17e627af7dd067932688de0a3d86423e37
Author: FeralChild64 <you@example.com>
Date:   Tue Jan 28 17:28:19 2020 +0100

    finished Mega65 variant of tape routines

commit 47de685f2e08576504c5e00a5b7cb78498d22e72
Author: FeralChild64 <you@example.com>
Date:   Mon Jan 27 23:06:45 2020 +0100

    compilation fix

commit c3641acec049a7a6b53c35795b1f9e2df212cec2
Author: FeralChild64 <you@example.com>
Date:   Mon Jan 27 22:53:30 2020 +0100

    dependencies fix

commit dfad7a30bde043fa077005624dde1de4b72573b6
Merge: e4b0ec9 e410bc0
Author: FeralChild64 <you@example.com>
Date:   Mon Jan 27 21:25:49 2020 +0100

    Merge branch 'master' into tape_redirect

commit e4b0ec9c85861bde2ce52e0828d3bf895a681e17
Author: FeralChild64 <you@example.com>
Date:   Sat Jan 25 22:25:20 2020 +0100

    initial attempt to move tape code to Mega65 extra ROM
2020-01-28 17:35:42 +01:00

98 lines
2.1 KiB
ArmAsm

// #LAYOUT# STD * #TAKE
// #LAYOUT# M65 KERNAL_1 #TAKE
// #LAYOUT# * * #IGNORE
//
// Tries to detect
//
// Carry clear - normal, Carry set - turbo
//
#if CONFIG_TAPE_AUTODETECT
tape_common_autodetect:
// Set screen color to something neutral, silence the audio
lda #$0B
sta VIC_EXTCOL
lda #$00
sta SID_SIGVOL
// FALLTROUGH
tape_common_autodetect_retry:
// It is not trivial to distinguish between normal and turbo,
// as short pulses of normal (and sync uses only shorts)
// have similar lengths as long pulses of turbo
// Thus, the routine here reads certain amount of pulses
// looking for evidence for either normal or turbo system;
// in case of no evidence found, assume normal
lda #$00 // plus = probably normal, minus = turbo
sta XSAV
ldy #$60 // $60 pulses cover 12 bytes of turbo recording
jsr tape_common_get_pulse // first pulse might be a garbage, ignore it
// FALLTROUGH
tape_common_autodetect_loop:
jsr tape_common_get_pulse // read pulse for detection attempt
// If garbage found, retry detection
cmp #$28
bcc tape_common_autodetect_retry // this is a VERY long pulse
cmp #$E8
bcs tape_common_autodetect_retry // this is a VERY short pulse
// First try to distinguish turbo short signal (reference: $CD)
// from normal signals (reference: $A5 or lower), these values
// give us threshold of ($CD + $A5) / 2 = $B9
cmp #$B9
bcc !+
dec XSAV // above $B9 (so signal is shorter), looks like turbo
!:
// Now try to distinguish turbo signals (reference: $B1 or higher)
// from normal medium/long signals (reference: $7D or below), these values
// give us threshold of ($B1 + $7D) / 2 = $97
cmp #$97
bcs !+
inc XSAV
!:
// The sync for turbo is not too long - if we have enough evidence,
// assume turbo recording already
lda XSAV
cmp #$FD
beq tape_common_autodetect_turbo
// Next iteration
dey
bpl tape_common_autodetect_loop
// Last chance for turbo
lda XSAV
bmi tape_common_autodetect_turbo
// FALLTROUGH
tape_common_autodetect_normal:
clc
rts
tape_common_autodetect_turbo:
sec
rts
#endif