improved tape system autodetection
This commit is contained in:
1 parent
854f03ef84
commit
82347a8b17
11 files changed
+112
-30
No files matched your search
@@ -56,7 +56,7 @@
|
||||
|
||||
#define CONFIG_TAPE_NORMAL
|
||||
#define CONFIG_TAPE_TURBO
|
||||
#define CONFIG_TAPE_AUTODETECT // not fully done yet!
|
||||
#define CONFIG_TAPE_AUTODETECT // mostly works, but not fullyy done yet!
|
||||
// #define CONFIG_TAPE_NO_KEY_SENSE
|
||||
// #define CONFIG_TAPE_NO_MOTOR_CONTROL
|
||||
|
||||
|
||||
@@ -168,8 +168,8 @@
|
||||
|
||||
// Check that tape configuration is correct
|
||||
{
|
||||
#if !CONFIG_TAPE_TURBO && CONFIG_TAPE_TURBO_AUTOCALIBRATE
|
||||
.error "CONFIG_TAPE_TURBO_AUTOCALIBRATE requires CONFIG_TAPE_TURBO*"
|
||||
#if (!CONFIG_TAPE_NORMAL || !CONFIG_TAPE_TURBO) && CONFIG_TAPE_AUTODETECT
|
||||
.error "CONFIG_TAPE_AUTODETECT requires both CONFIG_TAPE_NORMAL and CONFIG_TAPE_TURBO"
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ load_tape_normal:
|
||||
|
||||
jsr tape_ditch_verify // only LOAD is supported, no VERIFY
|
||||
|
||||
#if CONFIG_TAPE_TURBO && CONFIG_TAPE_AUTODETECT
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
|
||||
// Prepare for sound effects in case of turbo takeover
|
||||
jsr tape_clean_sid
|
||||
@@ -55,7 +55,7 @@ load_tape_normal:
|
||||
jsr tape_common_prepare_cia
|
||||
jsr tape_ask_play
|
||||
|
||||
#if CONFIG_TAPE_TURBO && CONFIG_TAPE_AUTODETECT
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ load_tape_turbo:
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
#if CONFIG_TAPE_NORMAL && CONFIG_TAPE_AUTODETECT
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
|
||||
load_tape_turbo_takeover: // entry point for turbo->normal takeover
|
||||
|
||||
@@ -51,6 +51,9 @@ load_tape_turbo_header:
|
||||
// 16 bytes - filename, padded with 0x20
|
||||
|
||||
jsr tape_turbo_sync_header
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
bcs_16 load_tape_normal_takeover // failure, probably not a turbo tape file
|
||||
#endif
|
||||
ldy #$00
|
||||
sta (TAPE1), y // store header type
|
||||
iny
|
||||
@@ -106,8 +109,11 @@ load_tape_turbo_payload:
|
||||
sta PRTY
|
||||
|
||||
// Read file payload
|
||||
|
||||
!:
|
||||
jsr tape_turbo_sync_payload
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
bcs !-
|
||||
#endif
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
//
|
||||
// Tries to detect
|
||||
//
|
||||
// Carry clear - NORMAL, Carry set - TURBO
|
||||
// Carry clear - normal, Carry set - turbo
|
||||
//
|
||||
|
||||
// XXX implement fallback to autodetection, correct screen color for NORMAL
|
||||
// XXX implement fallback to autodetection in normal
|
||||
|
||||
|
||||
#if CONFIG_TAPE_NORMAL && CONFIG_TAPE_TURBO && CONFIG_TAPE_AUTODETECT
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
|
||||
|
||||
tape_common_autodetect:
|
||||
@@ -26,18 +26,18 @@ tape_common_autodetect:
|
||||
|
||||
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
|
||||
// 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
|
||||
// looking for evidence for either normal or turbo system;
|
||||
// in case of no evidence found, assume normal
|
||||
|
||||
lda #$00 // plus = probably NORMAL, minus = TURBO
|
||||
lda #$00 // plus = probably normal, minus = turbo
|
||||
sta XSAV
|
||||
|
||||
ldy #$60 // $60 pulses cover 12 bytes of TURBO recording
|
||||
ldy #$60 // $60 pulses cover 12 bytes of turbo recording
|
||||
jsr tape_normal_get_pulse // first pulse might be a garbage, ignore it
|
||||
|
||||
// FALLTROUGH
|
||||
@@ -52,24 +52,24 @@ tape_common_autodetect_loop:
|
||||
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
|
||||
// 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
|
||||
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
|
||||
// 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
|
||||
// The sync for turbo is not too long - if we have enough evidence,
|
||||
// assume turbo recording already
|
||||
|
||||
lda XSAV
|
||||
cmp #$FD
|
||||
@@ -79,7 +79,7 @@ tape_common_autodetect_loop:
|
||||
dey
|
||||
bpl tape_common_autodetect_loop
|
||||
|
||||
// Last chance for TURBO
|
||||
// Last chance for turbo
|
||||
|
||||
lda XSAV
|
||||
bmi tape_common_autodetect_turbo
|
||||
|
||||
@@ -24,10 +24,10 @@ tape_normal_get_data:
|
||||
lda #$00
|
||||
sta RIPRTY
|
||||
|
||||
// Read the pilot and sync of the block
|
||||
// Read sync of the block
|
||||
ldy #$89
|
||||
jsr tape_normal_sync
|
||||
bcs tape_normal_get_block_done // XXX make it more error resistant
|
||||
bcs tape_normal_get_block_done
|
||||
jsr tape_normal_get_marker
|
||||
|
||||
tape_normal_get_data_loop:
|
||||
@@ -39,7 +39,7 @@ tape_normal_get_data_loop:
|
||||
|
||||
// Store byte, calculate checksum
|
||||
lda INBIT
|
||||
ldy #$00 // XXX probably can be optimized out for 65C02
|
||||
ldy #$00
|
||||
sta (MEMUSS), y
|
||||
eor RIPRTY
|
||||
sta RIPRTY
|
||||
@@ -60,7 +60,7 @@ tape_normal_get_data_loop:
|
||||
sec
|
||||
rts
|
||||
|
||||
tape_normal_get_checksum: // XXX handle second copy, with pilot starting from $09
|
||||
tape_normal_get_checksum: // XXX handle second copy, with pilot starting from $09
|
||||
|
||||
lda INBIT
|
||||
eor RIPRTY
|
||||
|
||||
@@ -31,6 +31,9 @@ tape_normal_pilot_common:
|
||||
|
||||
tape_normal_pilot_common_restart:
|
||||
|
||||
lda #$0B
|
||||
sta VIC_EXTCOL
|
||||
|
||||
lda FSBLK
|
||||
sta ROPRTY
|
||||
|
||||
|
||||
@@ -14,9 +14,14 @@
|
||||
|
||||
tape_normal_sync:
|
||||
|
||||
lda #$06
|
||||
sta VIC_EXTCOL
|
||||
|
||||
// Injest bytes of decreasing values
|
||||
|
||||
jsr tape_normal_get_marker // XXX handle result
|
||||
jsr tape_normal_get_marker
|
||||
bcs tape_normal_sync_fail // branch if end of data marker
|
||||
|
||||
jsr tape_normal_get_byte
|
||||
bcs tape_normal_sync_fail
|
||||
|
||||
|
||||
@@ -31,5 +31,29 @@ tape_turbo_get_bit:
|
||||
|
||||
#endif
|
||||
|
||||
cmp SYNO // threshold
|
||||
bcs !+
|
||||
|
||||
clc
|
||||
ror
|
||||
sta IRQTMP+0 // store half of the last measurement result for short pulse
|
||||
|
||||
lda #$01
|
||||
sta SID_SIGVOL
|
||||
lda #$06
|
||||
sta VIC_EXTCOL
|
||||
sec
|
||||
rts
|
||||
!:
|
||||
clc
|
||||
ror
|
||||
sta IRQTMP+1 // store half of the last measurement result for long pulse
|
||||
|
||||
lda #$00
|
||||
sta SID_SIGVOL
|
||||
sta VIC_EXTCOL
|
||||
clc
|
||||
rts
|
||||
|
||||
|
||||
#endif // CONFIG_TAPE_TURBO
|
||||
@@ -21,6 +21,9 @@ tape_turbo_sync_header:
|
||||
|
||||
// Synchronize with start of sync sequence
|
||||
jsr tape_turbo_sync_first
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
bcs tape_turbo_sync_done
|
||||
#endif
|
||||
|
||||
// Perform synchronization, double loop, total $C0 * $04 iterations
|
||||
ldx #$C0
|
||||
@@ -43,6 +46,9 @@ tape_turbo_sync_header:
|
||||
tape_turbo_sync_payload:
|
||||
|
||||
jsr tape_turbo_sync_first
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
bcs tape_turbo_sync_done // this shopuld not happen
|
||||
#endif
|
||||
!:
|
||||
ldx #$09 // 9, 8, ...
|
||||
!:
|
||||
@@ -57,6 +63,14 @@ tape_turbo_sync_payload:
|
||||
dex
|
||||
bne !-
|
||||
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
clc
|
||||
#endif
|
||||
|
||||
// FALLTROUGH
|
||||
|
||||
tape_turbo_sync_done:
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
||||
@@ -11,13 +11,43 @@
|
||||
|
||||
tape_turbo_sync_first:
|
||||
|
||||
#if CONFIG_TAPE_AUTODETECT
|
||||
|
||||
ldy #$00
|
||||
!:
|
||||
jsr tape_turbo_get_bit
|
||||
rol INBIT
|
||||
lda INBIT
|
||||
|
||||
cmp #$FF
|
||||
bne !+
|
||||
iny
|
||||
bpl !-
|
||||
bmi tape_turbo_sync_first_fail // suspiciously many $FF bytes, probably not a turbo tape
|
||||
!:
|
||||
cmp #$02
|
||||
bne tape_turbo_sync_first
|
||||
|
||||
clc
|
||||
rts
|
||||
|
||||
tape_turbo_sync_first_fail:
|
||||
|
||||
sec
|
||||
rts
|
||||
|
||||
#else // no CONFIG_TAPE_AUTODETECT
|
||||
|
||||
jsr tape_turbo_get_bit
|
||||
rol INBIT
|
||||
lda INBIT
|
||||
|
||||
cmp #$02
|
||||
bne tape_turbo_sync_first
|
||||
|
||||
rts
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user