From 3a33a00d9de8d90b5b9e2183ba74e29f6e867230 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 22 Oct 2020 16:32:45 +0200 Subject: [PATCH] tape autocalibration code is dangerous on 1MHz, disable it for slower machines --- STATUS.md | 2 +- src/aliases/,aliases_config.s | 8 ++++++++ src/aliases/,aliases_ram_lowmem.s | 3 +++ src/kernal/tape/tape_normal_calibrate.s | 4 ++-- src/kernal/tape/tape_normal_get_bit.s | 10 ++++++++-- src/kernal/tape/tape_normal_get_marker.s | 7 ++++--- src/kernal/tape/tape_normal_get_pilot.s | 3 ++- src/kernal/tape/tape_turbo_get_bit.s | 8 ++++++++ src/kernal/tape/tape_turbo_get_byte.s | 3 +++ 9 files changed, 39 insertions(+), 9 deletions(-) diff --git a/STATUS.md b/STATUS.md index 796b2b6c..ba005490 100644 --- a/STATUS.md +++ b/STATUS.md @@ -18,7 +18,7 @@ Here are the features of the Open ROMs not found in the original ROMs from the 8 * `LIST` command should never damage the screen if trying to list memory content which is not a BASIC program * high performance garbage collector -* turbo tape load support (as device 7, or using `←L` / `←M`, optionally with a file name), quite sophisticated: up to 250 blocks (can store bytes under I/O), automatically adjusts for tape speed differences +* turbo tape load support (as device 7, or using `←L` / `←M`, optionally with a file name), quite sophisticated: up to 250 blocks (can store bytes under I/O), on MEGA65 motherboard automatically adjusts itself for tape speed differences * normal tape load error log is limited by free stack space only (no artificial limitation like in original ROMs) * tape format autodetection; normal vs turbo is mostly transparent to user * improved support for tape adapters (for using regular casette players and other audio devices instead of Datasette) and emulators diff --git a/src/aliases/,aliases_config.s b/src/aliases/,aliases_config.s index d8610292..b8729fd4 100644 --- a/src/aliases/,aliases_config.s +++ b/src/aliases/,aliases_config.s @@ -451,6 +451,14 @@ +; Determine if it is OK to include tape autocalibration routines + +!ifndef CONFIG_MB_M65 { + !set HAS_TAPE_AUTOCALIBRATE = 1 +} + + + ; Defines for multi-segment ROMs !ifdef CONFIG_MB_M65 { diff --git a/src/aliases/,aliases_ram_lowmem.s b/src/aliases/,aliases_ram_lowmem.s index eafc56cb..f8e53af8 100644 --- a/src/aliases/,aliases_ram_lowmem.s +++ b/src/aliases/,aliases_ram_lowmem.s @@ -310,11 +310,14 @@ !ifdef HAS_TAPE { +!ifdef HAS_TAPE_AUTOCALIBRATE { + !addr __normal_time_S = IRQTMP+0 ; duration of the short pulse !addr __normal_time_M = IRQTMP+1 ; duration of the medium pulse !addr __turbo_half_S = IRQTMP+0 ; half-duration of the short pulse !addr __turbo_half_L = IRQTMP+1 ; half-duration of the long pulse +} !addr __pulse_threshold = SVXT ; pulse classification threshold !addr __pulse_threshold_ML = SYNO ; M/L pulse classification threshold, for normal only diff --git a/src/kernal/tape/tape_normal_calibrate.s b/src/kernal/tape/tape_normal_calibrate.s index 260fbc0c..9142fd77 100644 --- a/src/kernal/tape/tape_normal_calibrate.s +++ b/src/kernal/tape/tape_normal_calibrate.s @@ -10,7 +10,7 @@ ; -!ifdef CONFIG_TAPE_NORMAL { +!ifdef CONFIG_TAPE_NORMAL { !ifdef HAS_TAPE_AUTOCALIBRATE { tape_normal_calibrate_during_pilot: ; reecalibration during the pilot @@ -122,4 +122,4 @@ tape_normal_calibrate_threshold_inc: tape_normal_calibrate_done: rts -} +} } diff --git a/src/kernal/tape/tape_normal_get_bit.s b/src/kernal/tape/tape_normal_get_bit.s index f066f245..33a5d355 100644 --- a/src/kernal/tape/tape_normal_get_bit.s +++ b/src/kernal/tape/tape_normal_get_bit.s @@ -22,13 +22,16 @@ tape_normal_get_bit: ; First impulse was short, second should be medium +!ifdef HAS_TAPE_AUTOCALIBRATE { jsr tape_normal_calibrate_after_S +} jsr tape_common_get_pulse bcs tape_normal_get_bit_error +!ifdef HAS_TAPE_AUTOCALIBRATE { jsr tape_normal_calibrate_after_M - +} ; We have a bit '0' lda #$00 @@ -46,13 +49,16 @@ tape_normal_get_bit_1: ; First impulse was medium, second should be short +!ifdef HAS_TAPE_AUTOCALIBRATE { jsr tape_normal_calibrate_after_M +} jsr tape_common_get_pulse bcc tape_normal_get_bit_error +!ifdef HAS_TAPE_AUTOCALIBRATE { jsr tape_normal_calibrate_after_S - +} ; We have a bit '1' clc diff --git a/src/kernal/tape/tape_normal_get_marker.s b/src/kernal/tape/tape_normal_get_marker.s index 450b1e7a..afcdbcfe 100644 --- a/src/kernal/tape/tape_normal_get_marker.s +++ b/src/kernal/tape/tape_normal_get_marker.s @@ -32,16 +32,17 @@ tape_normal_get_marker_type: ; Not an entry point!!! -tape_normal_get_marker_while_sync_loop: +tape_normal_get_marker_while_sync__loop: +!ifdef HAS_TAPE_AUTOCALIBRATE { jsr tape_normal_calibrate_during_pilot ; while sync use short pulses for calibration - +} ; FALLTROUGH tape_normal_get_marker_while_sync: jsr tape_common_get_pulse - bcs tape_normal_get_marker_while_sync_loop ; branch if short pulse + bcs tape_normal_get_marker_while_sync__loop ; branch if short pulse cmp __pulse_threshold_ML bcs tape_normal_get_marker_while_sync ; too short for a long pulse diff --git a/src/kernal/tape/tape_normal_get_pilot.s b/src/kernal/tape/tape_normal_get_pilot.s index 5f96c2bd..433befc2 100644 --- a/src/kernal/tape/tape_normal_get_pilot.s +++ b/src/kernal/tape/tape_normal_get_pilot.s @@ -96,8 +96,9 @@ tape_normal_get_pilot_common_loop_inner: @1: } +!ifdef HAS_TAPE_AUTOCALIBRATE { jsr tape_normal_calibrate_during_pilot - +} dey bne tape_normal_get_pilot_common_loop_inner diff --git a/src/kernal/tape/tape_turbo_get_bit.s b/src/kernal/tape/tape_turbo_get_bit.s index 208f50b9..15789b7b 100644 --- a/src/kernal/tape/tape_turbo_get_bit.s +++ b/src/kernal/tape/tape_turbo_get_bit.s @@ -19,9 +19,12 @@ tape_turbo_get_bit: jsr tape_common_get_pulse bcs @1 +!ifdef HAS_TAPE_AUTOCALIBRATE { + clc ror sta __turbo_half_S ; store half of the last measurement result for short pulse +} lda #$01 !ifdef CONFIG_MB_M65 { @@ -34,10 +37,15 @@ tape_turbo_get_bit: sta VIC_EXTCOL sec rts + @1: + +!ifdef HAS_TAPE_AUTOCALIBRATE { + clc ror sta __turbo_half_L ; store half of the last measurement result for long pulse +} lda #$00 !ifdef CONFIG_MB_M65 { diff --git a/src/kernal/tape/tape_turbo_get_byte.s b/src/kernal/tape/tape_turbo_get_byte.s index e472371f..424df5b2 100644 --- a/src/kernal/tape/tape_turbo_get_byte.s +++ b/src/kernal/tape/tape_turbo_get_byte.s @@ -27,6 +27,8 @@ tape_turbo_get_byte: bcc @1 ; is the initial 1 shifted into carry already? +plx_trash_a +!ifdef HAS_TAPE_AUTOCALIBRATE { + ; Compensate for tape speed variations lda __turbo_half_S ; half of the last value for bit '0' @@ -51,6 +53,7 @@ tape_turbo_get_byte: beq tape_turbo_get_byte_done ; do not increase threshold too far no matter what inc __pulse_threshold +} tape_turbo_get_byte_done: