diff --git a/c64/aliases/,aliases_config.s b/c64/aliases/,aliases_config.s index 7ed7990a..b3ff8bfe 100644 --- a/c64/aliases/,aliases_config.s +++ b/c64/aliases/,aliases_config.s @@ -169,6 +169,9 @@ #if CONFIG_LEGACY_SCNKEY && CONFIG_RS232_UP9600 .error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_RS232_UP9600" #endif +#if CONFIG_LEGACY_SCNKEY && CONFIG_TAPE_NORMAL + .error "CONFIG_LEGACY_SCNKEY is not compatible with CONFIG_TAPE_NORMAL" +#endif #if CONFIG_LEGACY_SCNKEY && (CONFIG_KEYBOARD_C128 || CONFIG_KEYBOARD_C128_CAPS_LOCK || CONFIG_KEYBOARD_C65 || CONFIG_KEYBOARD_C65_CAPS_LOCK) .error "CONFIG_LEGACY_SCNKEY and CONFIG_KEYBOARD_C128* / CONFIG_KEYBOARD_C65* are mutually exclusive" #endif diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s index 8ccfc953..37e3ae08 100644 --- a/c64/aliases/,aliases_ram_lowmem.s +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -116,7 +116,7 @@ .label BITCI = $A8 // -- NOT IMPLEMENTED -- .label RINONE = $A9 // -- WIP -- (UP9600 only) RS-232 check for start bit flag .label RIDDATA = $AA // -- NOT IMPLEMENTED -- - .label RIPRTY = $AB // -- NOT IMPLEMENTED -- + .label RIPRTY = $AB // -- WIP -- checksum while reading tape #endif .label SAL = $AC // $AC-$AD -- NOT IMPLEMENTED -- (implemented screen part) .label EAL = $AE // $AE-$AF -- NOT IMPLEMENTED -- [!] used also by screen editor, for temporary color storage when scrolling diff --git a/c64/kernal/iostack/load_save_common.s b/c64/kernal/iostack/load_save_common.s index 9aa7ed97..10c975b3 100644 --- a/c64/kernal/iostack/load_save_common.s +++ b/c64/kernal/iostack/load_save_common.s @@ -85,6 +85,10 @@ lvs_setup_MEMUSS: sta MEMUSS+1 rts +#endif + +#if CONFIG_TAPE_TURBO || CONFIG_IEC + lvs_advance_MEMUSS_check_EAL: // Advance pointer @@ -95,7 +99,15 @@ lvs_advance_MEMUSS_check_EAL: !: #else inw MEMUSS+0 + #endif + + // FALLTROUGH + +#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO || CONFIG_IEC + +lvs_check_EAL: + lda MEMUSS+1 cmp EAL+1 bne !+ diff --git a/c64/kernal/tape/load_tape_normal.s b/c64/kernal/tape/load_tape_normal.s index b3a51172..a28bea37 100644 --- a/c64/kernal/tape/load_tape_normal.s +++ b/c64/kernal/tape/load_tape_normal.s @@ -117,18 +117,24 @@ load_tape_normal_header_loop: load_tape_normal_payload: - jsr tape_normal_pilot - ldy #$09 - jsr tape_normal_sync + // Retrieve block + jsr tape_normal_get_block // XXX handle errors + // Advance MEMUSS (see Mapping the C64, page 36), check if end - - // XXX replace this placeholder with a real routine + tya + clc + adc MEMUSS+0 + sta MEMUSS+0 + bcc !+ + inc MEMUSS+1 !: - jsr tape_normal_get_marker - jsr tape_normal_get_byte - jmp !- + + jsr lvs_check_EAL + bne load_tape_normal_payload + + jmp tape_load_success #endif diff --git a/c64/kernal/tape/tape_normal_get_bit.s b/c64/kernal/tape/tape_normal_get_bit.s index b619f29e..54f9b969 100644 --- a/c64/kernal/tape/tape_normal_get_bit.s +++ b/c64/kernal/tape/tape_normal_get_bit.s @@ -1,6 +1,6 @@ // -// Tape (turbo) helper routine - bit reading +// Tape (normal) helper routine - bit reading // // Returns bit in Zero flag, Carry set means error, on 0 bit .A is 0 too // diff --git a/c64/kernal/tape/tape_normal_get_block.s b/c64/kernal/tape/tape_normal_get_block.s new file mode 100644 index 00000000..f4e3798d --- /dev/null +++ b/c64/kernal/tape/tape_normal_get_block.s @@ -0,0 +1,74 @@ + +// +// Tape (normal) helper routine - block reading +// +// Stores data starting from MEMUSS, Carry set means error, on 0 bit .A is 0 too +// + + +// XXX does not detect block end - find out why +// XXX improve error handling - do not ignore second copy, handle damaged checksum byte, handle damaged sync part + + +tape_normal_get_block: + + // Read the pilot and sync of the block + + jsr tape_normal_pilot + ldy #$89 + jsr tape_normal_sync // XXX handle result + + // Initialize byte counter and block checksum (RIPRTY, see http://sta.c64.org/cbm64mem.html) + ldy #$00 + sty RIPRTY + +tape_normal_get_block_loop: + + jsr tape_normal_get_marker + bcs tape_normal_get_block_checksum // end of data for the block + jsr tape_normal_get_byte + + bcs tape_normal_get_block_done // error reading byte - fatal for now + + // Store byte, calculate checksum + sta (MEMUSS), y + eor RIPRTY + sta RIPRTY + + iny + bne tape_normal_get_block_loop + + // FALLTROUGH - if we are here, it means the block is too long + +tape_normal_get_block_done_fail: + + sec + rts + +tape_normal_get_block_checksum: +.break + jsr tape_normal_get_byte + bcs tape_normal_get_block_done // cannot get block checksum - fatal for now + + eor RIPRTY + cmp #$01 + bcs tape_normal_get_block_done // checksum error - fatal for now + + // Read trailing pulses + + jsr tape_normal_sync // XXX handle result + + // Read the pilot and sync of the backup block + + jsr tape_normal_pilot + ldy #$09 + jsr tape_normal_sync // XXX handle result + + // For now we ignore the backup block + clc + + // FALLTROUGH + +tape_normal_get_block_done: + + rts