diff --git a/bin/basic_generic.rom b/bin/basic_generic.rom index b616aec8..67d6d761 100644 Binary files a/bin/basic_generic.rom and b/bin/basic_generic.rom differ diff --git a/bin/basic_testing.rom b/bin/basic_testing.rom index 1b0d3c9b..30d6963d 100644 Binary files a/bin/basic_testing.rom and b/bin/basic_testing.rom differ diff --git a/bin/basic_ultimate64.rom b/bin/basic_ultimate64.rom index d9a7f638..3e91cd62 100644 Binary files a/bin/basic_ultimate64.rom and b/bin/basic_ultimate64.rom differ diff --git a/bin/kernal_generic.rom b/bin/kernal_generic.rom index 3ce521dd..2a5d2dae 100644 Binary files a/bin/kernal_generic.rom and b/bin/kernal_generic.rom differ diff --git a/bin/kernal_testing.rom b/bin/kernal_testing.rom index 286dfc4b..4ee9d0c3 100644 Binary files a/bin/kernal_testing.rom and b/bin/kernal_testing.rom differ diff --git a/bin/kernal_ultimate64.rom b/bin/kernal_ultimate64.rom index 7d3f9735..0851f524 100644 Binary files a/bin/kernal_ultimate64.rom and b/bin/kernal_ultimate64.rom differ diff --git a/bin/mega65.rom b/bin/mega65.rom index 1db906dc..495d1f41 100644 Binary files a/bin/mega65.rom and b/bin/mega65.rom differ diff --git a/c64/aliases/,aliases_ram_lowmem.s b/c64/aliases/,aliases_ram_lowmem.s index 37e3ae08..6e377781 100644 --- a/c64/aliases/,aliases_ram_lowmem.s +++ b/c64/aliases/,aliases_ram_lowmem.s @@ -136,7 +136,7 @@ .label FA = $BA // current device number .label FNADDR = $BB // $BB-$BC current file name pointer .label ROPRTY = $BD // -- NOT IMPLEMENTED -- tape / RS-232 temporary storage - .label FSBLK = $BE // -- NOT IMPLEMENTED -- + .label FSBLK = $BE // -- NOT IMPLEMENTED -- tape / RS-232 temporary storage .label MYCH = $BF // -- NOT IMPLEMENTED -- .label CAS1 = $C0 // tape motor interlock .label STAL = $C1 // $C1-$C2 LOAD/SAVE start address diff --git a/c64/kernal/iec/save_iec.s b/c64/kernal/iec/save_iec.s index e06d4a9e..19413839 100644 --- a/c64/kernal/iec/save_iec.s +++ b/c64/kernal/iec/save_iec.s @@ -85,7 +85,12 @@ iec_save_loop: #endif // Next iteration - jsr lvs_advance_MEMUSS_check_EAL +#if !HAS_OPCODES_65CE02 + jsr lvs_advance_MEMUSS +#else + inw MEMUSS+0 +#endif + jsr lvs_check_EAL bne iec_save_loop iec_save_loop_end: diff --git a/c64/kernal/iostack/load_save_common.s b/c64/kernal/iostack/load_save_common.s index 10c975b3..a2d31714 100644 --- a/c64/kernal/iostack/load_save_common.s +++ b/c64/kernal/iostack/load_save_common.s @@ -87,25 +87,22 @@ lvs_setup_MEMUSS: #endif -#if CONFIG_TAPE_TURBO || CONFIG_IEC +#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO || CONFIG_IEC -lvs_advance_MEMUSS_check_EAL: +#if !HAS_OPCODES_65CE02 + +lvs_advance_MEMUSS: // Advance pointer -#if !HAS_OPCODES_65CE02 + inc MEMUSS+0 bne !+ inc MEMUSS+1 !: -#else - inw MEMUSS+0 + rts #endif - // FALLTROUGH - -#if CONFIG_TAPE_NORMAL || CONFIG_TAPE_TURBO || CONFIG_IEC - lvs_check_EAL: lda MEMUSS+1 @@ -116,7 +113,6 @@ lvs_check_EAL: !: rts -#endif lvs_display_searching_for: diff --git a/c64/kernal/tape/load_tape_normal.s b/c64/kernal/tape/load_tape_normal.s index cd2b0254..c5159b8b 100644 --- a/c64/kernal/tape/load_tape_normal.s +++ b/c64/kernal/tape/load_tape_normal.s @@ -56,15 +56,21 @@ load_tape_normal: ldx #%00010001 // start timer, force latch reload stx CIA2_CRA // $DD0E + // Temporarily store MEMUSS in EAL + + lda MEMUSS+1 + sta EAL+1 + lda MEMUSS+0 + sta EAL+0 + // Start playing + jsr tape_ask_play // FALLTROUGH load_tape_normal_header: -/* XXX try to reuse block retrieeval rooutine, like this: - // Try to load header into tape buffer lda TAPE1+1 @@ -72,66 +78,36 @@ load_tape_normal_header: lda TAPE1+0 sta MEMUSS+0 - // Initialize checksum (RIPRTY, see http://sta.c64.org/cbm64mem.html) - - lda #$00 - sta RIPRTY + // Retrieve the header - // Retrieve the header XXX limit it to 192 bytes - - jsr tape_normal_get_block + jsr tape_normal_pilot_header + jsr tape_normal_get_data // XXX limit it to 192 bytes bcs load_tape_normal_header // unable to read block, try again - // Handle the header + // Check header type - jsr tape_handle_header - bcs load_tape_normal_header // if name does not match, look for other header -*/ - - // Read pilot and sync of the first header - - jsr tape_normal_pilot - ldy #$89 - jsr tape_normal_sync - bcs load_tape_normal_header - - ldy #$00 - - // FALLTROUGH - -load_tape_normal_header_loop: - - // Read the header - - jsr tape_normal_get_marker // XXX handle result - jsr tape_normal_get_byte // XXX handle errors - sta (TAPE1), y - iny - cpy #$15 - bne load_tape_normal_header_loop - - // Read pilot and sync of the second header - - jsr tape_normal_pilot - ldy #$09 - jsr tape_normal_sync - bcs load_tape_normal_header - - // XXX do not skip second header, use it to correct data - ldy #$15 -!: - jsr tape_normal_get_marker - jsr tape_normal_get_byte - dey - bne !- - - // For now only one type of header is supported - - ldy #$00 + ldy #$00 // XXX probably can be optimized for 65C02 lda (TAPE1),y + cmp #$05 + beq_far tape_load_error // end of tape mark, nothing to load + cmp #$01 - bne load_tape_normal_header // XXX also handle other header types, see Mapping the C64 page 77 + beq !+ + cmp #$03 + bne load_tape_normal_header // header types 1 and 3 are loadable, see Mapping the C64, page 77 + + // XXX handle non-relocatable program, header type 3 + +!: + // Handle the header + + // Restore MEMUSS + + lda EAL+1 + sta MEMUSS+1 + lda EAL+0 + sta MEMUSS+0 // Handle the header @@ -142,28 +118,14 @@ load_tape_normal_header_loop: load_tape_normal_payload: - // Initialize checksum (RIPRTY, see http://sta.c64.org/cbm64mem.html) - - lda #$00 - sta RIPRTY - // Retrieve data + jsr tape_normal_pilot_data jsr tape_normal_get_data bcs_far tape_load_error - // Advance MEMUSS (see Mapping the C64, page 36), check if end - - tya - clc - adc MEMUSS+0 - sta MEMUSS+0 - bcc !+ - inc MEMUSS+1 -!: - // XXX check below does not work - why? - // jsr lvs_check_EAL - // bne_far tape_load_error // amount of data read does not match header info + jsr lvs_check_EAL + bne_far tape_load_error // amount of data read does not match header info jmp tape_load_success diff --git a/c64/kernal/tape/load_tape_turbo.s b/c64/kernal/tape/load_tape_turbo.s index eae97205..4825509b 100644 --- a/c64/kernal/tape/load_tape_turbo.s +++ b/c64/kernal/tape/load_tape_turbo.s @@ -64,7 +64,7 @@ load_tape_turbo_header_loop: // Handle the header jsr tape_clean_sid - jsr tape_handle_header + jsr tape_handle_header // XXX handle non-relocatable programs - any non-0 even header type bcs load_tape_turbo_header // if name does not match, look for other header // FALLTROUGH @@ -91,7 +91,12 @@ load_tape_turbo_loop: sta PRTY // Advance MEMUSS (see Mapping the C64, page 36) - jsr lvs_advance_MEMUSS_check_EAL +#if !HAS_OPCODES_65CE02 + jsr lvs_advance_MEMUSS +#else + inw MEMUSS+0 +#endif + jsr lvs_check_EAL bne load_tape_turbo_loop // Get the checksum diff --git a/c64/kernal/tape/tape_normal_get_byte.s b/c64/kernal/tape/tape_normal_get_byte.s index 1fbae18e..d63c1d0d 100644 --- a/c64/kernal/tape/tape_normal_get_byte.s +++ b/c64/kernal/tape/tape_normal_get_byte.s @@ -2,7 +2,7 @@ // // Tape (normal) helper routine - byte reading // -// Returns byte in .A, Carry flag set = error +// Returns byte in .A (also sotred in INBIT), Carry flag set = error // diff --git a/c64/kernal/tape/tape_normal_get_data.s b/c64/kernal/tape/tape_normal_get_data.s index 71efb6f7..7c7acb14 100644 --- a/c64/kernal/tape/tape_normal_get_data.s +++ b/c64/kernal/tape/tape_normal_get_data.s @@ -14,61 +14,46 @@ tape_normal_get_data: + // Initialize checksum (RIPRTY, see http://sta.c64.org/cbm64mem.html) + + lda #$00 + sta RIPRTY + // Read the pilot and sync of the block - jsr tape_normal_pilot ldy #$89 jsr tape_normal_sync bcs tape_normal_get_block_done // XXX make it more erroor resistant - - // Initialize byte counter - ldy #$00 + jsr tape_normal_get_marker tape_normal_get_data_loop: - jsr tape_normal_get_marker - bcs tape_normal_get_data_2nd_copy // end of data for the block jsr tape_normal_get_byte - bcs tape_normal_get_block_done // error reading byte - fatal for now + jsr tape_normal_get_marker + bcs tape_normal_get_checksum // end of data for the block // Store byte, calculate checksum + lda INBIT + ldy #$00 // XXX probably can be optimized for 65C02 sta (MEMUSS), y eor RIPRTY sta RIPRTY - iny - bne tape_normal_get_data_loop + // Advance pointer +#if !HAS_OPCODES_65CE02 + jsr lvs_advance_MEMUSS +#else + inw MEMUSS+0 +#endif - // 256 bytes read - - inc MEMUSS+1 jmp tape_normal_get_data_loop -tape_normal_get_data_2nd_copy: +tape_normal_get_checksum: // XXX handle second copy, with pilot starting from $09 - // Read the pilot and sync of the block - - jsr tape_normal_pilot - ldy #$09 - jsr tape_normal_sync - bcs tape_normal_get_block_done // XXX make it more error resistant - - // For now skip the error correction data -!: - jsr tape_normal_get_marker - bcs tape_normal_get_checksum - jsr tape_normal_get_byte - tay - jmp !- - -tape_normal_get_checksum: - - tya + lda INBIT eor RIPRTY - cmp #$01 // sets Carry if checksum verification failed - - clc // XXX checksum calculation fails - why? + cmp #$01 // sets Carry if checksum verification fails // FALLTROUGH diff --git a/c64/kernal/tape/tape_normal_pilot.s b/c64/kernal/tape/tape_normal_pilot.s index b2ee829f..e2fb5823 100644 --- a/c64/kernal/tape/tape_normal_pilot.s +++ b/c64/kernal/tape/tape_normal_pilot.s @@ -3,27 +3,70 @@ // Tape (turbo) helper routine - handling the pilot // +// Injest the pilot - series of short pulses. According to http://sidpreservation.6581.org/tape-format/ +// it consist of the following number of pulses: +// - $6A00 for header +// - $1A00 for data and seq block header +// - $4F for repeated header/data + #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 +tape_normal_pilot_short: // require 1x $40 pulses + + lda #$01 + + // FALLTROUGH + +tape_normal_pilot_common: + + sta FSBLK + + // FALLTROUGH + +tape_normal_pilot_common_restart: + + lda FSBLK + sta ROPRTY + + // FALLTROUGH + +tape_normal_pilot_common_loop_outer: + + ldy #$40 + + // FALLTROUGH + +tape_normal_pilot_common_loop_inner: - ldy #$05 // this should be enough -!: jsr tape_normal_get_pulse - bcc tape_normal_pilot // not a pilot - try again + bcc tape_normal_pilot_common_restart // not a pilot - try again dey - bne !- + bne tape_normal_pilot_common_loop_inner + + dec ROPRTY + bne tape_normal_pilot_common_loop_outer rts + +tape_normal_pilot_data: // require 4x $40 pulses + + lda #$04 + + skip_2_bytes_trash_nvz + + // FALLTROUGH + +tape_normal_pilot_header: // require 128x $40 pulses + + lda #$80 + + jmp tape_normal_pilot_common // XXX calibrate tape speeed afterwards + + #endif