Files
open-roms/c64/kernal/tape/load_tape_normal.s
T
FeralChild64 d489e7bf41 tape routines can now be placed in Mega65 extra ROM space
commit 2f27e29758da1f1ec965588c0712125051a6f71a
Merge: ba722b1 796b62f
Author: FeralChild64 <you@example.com>
Date:   Tue Jan 28 17:34:53 2020 +0100

    Merge branch 'master' into tape_redirect

commit ba722b17e627af7dd067932688de0a3d86423e37
Author: FeralChild64 <you@example.com>
Date:   Tue Jan 28 17:28:19 2020 +0100

    finished Mega65 variant of tape routines

commit 47de685f2e08576504c5e00a5b7cb78498d22e72
Author: FeralChild64 <you@example.com>
Date:   Mon Jan 27 23:06:45 2020 +0100

    compilation fix

commit c3641acec049a7a6b53c35795b1f9e2df212cec2
Author: FeralChild64 <you@example.com>
Date:   Mon Jan 27 22:53:30 2020 +0100

    dependencies fix

commit dfad7a30bde043fa077005624dde1de4b72573b6
Merge: e4b0ec9 e410bc0
Author: FeralChild64 <you@example.com>
Date:   Mon Jan 27 21:25:49 2020 +0100

    Merge branch 'master' into tape_redirect

commit e4b0ec9c85861bde2ce52e0828d3bf895a681e17
Author: FeralChild64 <you@example.com>
Date:   Sat Jan 25 22:25:20 2020 +0100

    initial attempt to move tape code to Mega65 extra ROM
2020-01-28 17:35:42 +01:00

170 lines
3.9 KiB
ArmAsm
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// #LAYOUT# STD * #TAKE
// #LAYOUT# M65 KERNAL_1 #TAKE
// #LAYOUT# * * #IGNORE
//
// Tape (normal) part of the LOAD routine
//
// We have the following possible CPU frequencies:
// - C64    PAL:  CPU frequency 0.985248 MHz
// - C64    NTSC: CPU frequency 1.022727 MHz
// The clock difference is about 4% - it is unlikely to cause problems.
//
// We have to distinguish the following pulse lengths (http://sidpreservation.6581.org/tape-format/):
// - S (short)    tap value $30 (PAL: 352 us)
// - M (medium)   tap value $42 (PAL: 512 us)
// - L (long)     tap value $56 (PAL: 672 us)
//
// The TAP format (http://unusedino.de/ec64/technical/formats/tap.html) uses a resolution of 8 PAL ticks;
// this implementation sets the timer for twice the precision (timer B is triggered every 4 CPU cycles),
// probably an overkill, but in realityy it does not cost us anything.
//
// So - we have the following thresholds:
// - S vs M       $72 (in our units of 4 ticks)
// - M vs L       $98 (in our units of 4 ticks)
//
// We need to recognize the following pulse sequences:
//
// (S,M) = 0 bit
// (M,S) = 1 bit
// (L,M) = new-data marker
// (L,S) = end-of-data marker
#if CONFIG_TAPE_NORMAL
#if !CONFIG_TAPE_AUTODETECT
load_tape_normal:
jsr tape_ditch_verify // only LOAD is supported, no VERIFY
// Start playing
jsr tape_common_prepare_cia
jsr tape_ask_play
// FALLTROUGH
load_tape_normal_header:
#else
load_tape_normal_takeover: // entry point for turbo->normal takeover
#endif
jsr load_MEMUSS_to_STAL
// Try to load header into tape buffer (we will restore MEMUSS later)
jsr tape_normal_get_pilot_header
#if CONFIG_TAPE_AUTODETECT
bcs load_tape_normal_switch_turbo // failed, try turbo
#endif
jsr load_TAPE1_to_MEMUSS
jsr tape_normal_get_data_1
#if !CONFIG_TAPE_AUTODETECT
bcs load_tape_normal_header // unable to read block, try again
#else
bcc !+
load_tape_normal_switch_turbo:
jsr lvs_STAL_to_MEMUSS
jmp load_tape_turbo_takeover // unable to read block, try turbo instead
!:
#endif
#if CONFIG_TAPE_NO_ERROR_CORRECTION
lda RIPRTY
cmp #$01 // sets Carry if checksum verification fails
#else
jsr load_TAPE1_to_MEMUSS
jsr tape_normal_get_data_2
#endif
#if !CONFIG_TAPE_AUTODETECT
bcs load_tape_normal_header // block load error, try again
#else
bcs load_tape_normal_switch_turbo // block load error, try turbo instead
#endif
// Check header type
ldy #$00
lda (TAPE1),y
cmp #$05
beq_16 tape_load_error // end of tape mark, nothing to load
cmp #$01
beq !+
cmp #$03
#if !CONFIG_TAPE_AUTODETECT
bne load_tape_normal_header // header types 1 and 3 are loadable, see Mapping the C64, page 77
#else
bne load_tape_normal_takeover
#endif
lda #$01
sta SA // this file is non-relocatable; override secondary address with 1
!:
// Restore MEMUSS, handle header
jsr lvs_STAL_to_MEMUSS
jsr tape_handle_header
#if !CONFIG_TAPE_AUTODETECT
bcs load_tape_normal_header // if name does not match, look for other header
#else
bcs load_tape_normal_takeover
#endif
// FALLTROUGH
load_tape_normal_payload:
// Retrieve data
jsr tape_normal_get_pilot_data
ldy #$00 // no data size limit
jsr tape_normal_get_data_1
bcs_16 tape_load_error
jsr lvs_check_EAL
bne_16 tape_load_error // amount of data read does not match header info
#if CONFIG_TAPE_NO_ERROR_CORRECTION
lda RIPRTY
cmp #$01 // sets Carry if checksum verification fails
#else
jsr lvs_STAL_to_MEMUSS
jsr tape_normal_get_data_2
#endif
bcs_16 tape_load_error
jmp tape_load_success
load_TAPE1_to_MEMUSS: // set MEMUSS (start address) as tape buffer
lda TAPE1+1
sta MEMUSS+1
lda TAPE1+0
sta MEMUSS+0
rts
load_MEMUSS_to_STAL: // preserve MEMUSS
lda MEMUSS+1
sta STAL+1
lda MEMUSS+0
sta STAL+0
rts
#endif