From 58d5ba54c216b8319856e4bb6ffc7298aa60d510 Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 19 Dec 2019 17:12:44 +0100 Subject: [PATCH] updated documentation, added synchronization and pilot support to tape load --- CONTRIBUTORS.md | 3 ++- Makefile | 2 +- c64/aliases/,aliases_ram_lowmem.s | 2 +- c64/kernal/tape/load_tape_normal.s | 15 +++++++++-- c64/kernal/tape/tape_normal_get_bit.s | 19 +++++++------- c64/kernal/tape/tape_normal_get_byte.s | 19 ++++++-------- c64/kernal/tape/tape_normal_pilot.s | 29 +++++++++++++++++++++ c64/kernal/tape/tape_normal_sync.s | 36 ++++++++++++++++++++++++++ c64/kernal/tape/tape_turbo_get_byte.s | 6 ++--- c64/kernal/tape/tape_turbo_sync.s | 10 +++---- 10 files changed, 108 insertions(+), 33 deletions(-) create mode 100644 c64/kernal/tape/tape_normal_pilot.s create mode 100644 c64/kernal/tape/tape_normal_sync.s diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 2bb826fe..c2bcde66 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,2 +1,3 @@ -Although the project itself is LGPL3, I (FeralChild64) allow to redistribute my contributions to this project under any OSI (Open Source Initiative) approved open source license. +Although the project itself is LGPL3, I (FeralChild64 - Roman St********ski) allow to redistribute +my contributions to this project under any OSI (Open Source Initiative) approved open source license. diff --git a/Makefile b/Makefile index 17a662f8..a1563c96 100644 --- a/Makefile +++ b/Makefile @@ -117,7 +117,7 @@ build/target_generic/OUTB.BIN build/target_generic/BASIC_combined.vs: \ $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC) \ c64/,,config_generic.s build/target_generic/KERNAL_combined.sym \ $(foreach dir,$(SRCDIR_BASIC),$(wildcard $(dir)/*.s)) -build/target_testing/OUTB.BIN build/target_generic/BASIC_combined.vs: \ +build/target_testing/OUTB.BIN build/target_testing/BASIC_combined.vs: \ $(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC) \ c64/,,config_testing.s build/target_testing/KERNAL_combined.sym \ $(foreach dir,$(SRCDIR_BASIC),$(wildcard $(dir)/*.s)) diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s index 814aff63..babb1690 100644 --- a/c64/aliases/,aliases_ram_lowmem.s +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -111,7 +111,7 @@ .label TBTCNT = $A4 // temporary variable for tape and IEC, [!] our usage probably differs in details .label CNTDN = $A5 // -- NOT IMPLEMENTED -- .label BUFPNT = $A6 // -- NOT IMPLEMENTED -- - .label INBIT = $A7 // -- NOT IMPLEMENTED -- + .label INBIT = $A7 // temporary storage for tape / RS-232 received bits #if !CONFIG_LEGACY_SCNKEY .label BITCI = $A8 // -- NOT IMPLEMENTED -- .label RINONE = $A9 // -- WIP -- (UP9600 only) RS-232 check for start bit flag diff --git a/c64/kernal/tape/load_tape_normal.s b/c64/kernal/tape/load_tape_normal.s index 9cec4f7d..3a3719b1 100644 --- a/c64/kernal/tape/load_tape_normal.s +++ b/c64/kernal/tape/load_tape_normal.s @@ -28,6 +28,9 @@ // (L,S) = end-of-data marker +// XXX use pilot to calibrate reading speed + + #if CONFIG_TAPE_NORMAL @@ -58,10 +61,18 @@ load_tape_normal: load_tape_normal_header: - // XXX replace this placeholder by a real routine + lda #$00 + sta ROPRTY // initialize EOR checksum +!: + jsr tape_normal_pilot + ldy #$89 + jsr tape_normal_sync + bcs !- + // XXX replace this placeholder with a real routine +!: jsr tape_normal_get_byte - jmp load_tape_normal_header + jmp !- #endif diff --git a/c64/kernal/tape/tape_normal_get_bit.s b/c64/kernal/tape/tape_normal_get_bit.s index 93602e3d..b619f29e 100644 --- a/c64/kernal/tape/tape_normal_get_bit.s +++ b/c64/kernal/tape/tape_normal_get_bit.s @@ -14,17 +14,17 @@ tape_normal_get_bit: // Fetch the first pulse jsr tape_normal_get_pulse - bcc tape_normal_get_bit_0 + bcc tape_normal_get_bit_1 - // First impulse was short, second should be long + // First impulse was short, second should be medium jsr tape_normal_get_pulse bcs tape_normal_get_bit_error - // We have a bit '1' + // We have a bit '0' // Carry flag already clear - lda #$06 + lda #$00 // FALLTROUGH @@ -34,21 +34,22 @@ tape_normal_get_bit_done: rts -tape_normal_get_bit_0: +tape_normal_get_bit_1: - // First impulse was long, second should be short + // First impulse was medium, second should be short jsr tape_normal_get_pulse bcc tape_normal_get_bit_error - // We have a bit '0' + // We have a bit '1' clc - lda #$00 - beq tape_normal_get_bit_done // branch always + lda #$06 + bne tape_normal_get_bit_done // branch always tape_normal_get_bit_error: + sec rts diff --git a/c64/kernal/tape/tape_normal_get_byte.s b/c64/kernal/tape/tape_normal_get_byte.s index 2188c4a3..5bb70c6a 100644 --- a/c64/kernal/tape/tape_normal_get_byte.s +++ b/c64/kernal/tape/tape_normal_get_byte.s @@ -13,9 +13,9 @@ tape_normal_get_byte: // Init byte checksum and canary bit lda #$01 - sta ROPRTY + sta PRTY lda #%01111111 // canary bit is 0 - pha + sta INBIT // First we need a byte marker - (L,M) !: @@ -35,16 +35,13 @@ tape_normal_get_byte_loop: // Handle parity bit lda #$01 - eor ROPRTY - sta ROPRTY + eor PRTY + sta PRTY sec !: // moved bit state from Zero to Carry flag - pla - ror // put the bit in - pha - + ror INBIT // put the bit in bcs tape_normal_get_byte_loop // loop if no canary bit reached // Byte retrieved (on stack), now we need to validate the checksum @@ -54,8 +51,8 @@ tape_normal_get_byte_loop: beq !+ lda #$01 !: - eor ROPRTY - beq tape_normal_get_byte_error + eor PRTY + bne tape_normal_get_byte_error // Checksum validated succesfully @@ -66,8 +63,8 @@ tape_normal_get_byte_loop: tape_normal_get_byte_done: - pla stx VIC_EXTCOL + lda INBIT rts diff --git a/c64/kernal/tape/tape_normal_pilot.s b/c64/kernal/tape/tape_normal_pilot.s new file mode 100644 index 00000000..b2ee829f --- /dev/null +++ b/c64/kernal/tape/tape_normal_pilot.s @@ -0,0 +1,29 @@ + +// +// Tape (turbo) helper routine - handling the pilot +// + + +#if CONFIG_TAPE_NORMAL + + +tape_normal_pilot: + + // Injest the pilot - series of short pulses. According to http://sidpreservation.6581.org/tape-format/ + // it consist of the foollowing number of pulses: + // - $6A00 for header + // - $1A00 for data and seq block header + // - $4F for repeated header/data + + ldy #$05 // this should be enough +!: + jsr tape_normal_get_pulse + bcc tape_normal_pilot // not a pilot - try again + + dey + bne !- + + rts + + +#endif diff --git a/c64/kernal/tape/tape_normal_sync.s b/c64/kernal/tape/tape_normal_sync.s new file mode 100644 index 00000000..0e1716ed --- /dev/null +++ b/c64/kernal/tape/tape_normal_sync.s @@ -0,0 +1,36 @@ + +// +// Tape (turbo) helper routine - synchronization handling +// +// .Y should contain start value (either $89 or $09) +// Carry set = failed + + +#if CONFIG_TAPE_NORMAL + + +tape_normal_sync: + + // Injest bytes of decreasing values + + jsr tape_normal_get_byte + bcs tape_normal_sync_fail + + cpy INBIT // INBIT contains same value as .A + bne tape_normal_sync_fail + + dey + and #%01111110 + bne tape_normal_sync // branch if not $80 and not $00 + + clc + rts + + +tape_normal_sync_fail: + + sec + rts + + +#endif diff --git a/c64/kernal/tape/tape_turbo_get_byte.s b/c64/kernal/tape/tape_turbo_get_byte.s index 68c0192a..d1ee0ded 100644 --- a/c64/kernal/tape/tape_turbo_get_byte.s +++ b/c64/kernal/tape/tape_turbo_get_byte.s @@ -15,12 +15,12 @@ tape_turbo_get_byte: lda #$01 - sta ROPRTY // init the to-be-read byte with 1 (canary bit to mark loop end) + sta INBIT // init the to-be-read byte with 1 (canary bit to mark loop end) !: jsr tape_turbo_get_bit - rol ROPRTY + rol INBIT bcc !- // is the initial 1 shifted into carry already? - lda ROPRTY // much nicer than ldx #8: dex: loop + lda INBIT // much nicer than ldx #8: dex: loop rts diff --git a/c64/kernal/tape/tape_turbo_sync.s b/c64/kernal/tape/tape_turbo_sync.s index a7dde565..1c1aedc6 100644 --- a/c64/kernal/tape/tape_turbo_sync.s +++ b/c64/kernal/tape/tape_turbo_sync.s @@ -13,8 +13,8 @@ tape_turbo_sync_common: jsr tape_turbo_get_bit - rol ROPRTY - lda ROPRTY + rol INBIT + lda INBIT cmp #$02 bne tape_turbo_sync_common rts @@ -37,14 +37,14 @@ tape_turbo_sync_payload: jsr tape_turbo_sync_common !: - ldx #$09 // 9,8,... is real turboTape -!: // I sometimes used 8,7,6... to avoid it being listed in vice :) + ldx #$09 // 9, 8, ... +!: jsr tape_turbo_get_byte cmp #$02 beq !- ldy #$00 !: - cpx ROPRTY + cpx INBIT bne tape_turbo_sync_payload jsr tape_turbo_get_byte dex