Files
open-roms/c64/kernal/tape/load_tape_turbo.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

163 lines
3.3 KiB
ArmAsm

// #LAYOUT# STD * #TAKE
// #LAYOUT# M65 KERNAL_1 #TAKE
// #LAYOUT# * * #IGNORE
//
// Tape (turbo) part of the LOAD routine
//
// Initially based on routine by enthusi/Onslaught, found here:
// - https://codebase64.pokefinder.org/doku.php?id=base:turbotape_loader_source
// but heavily reworked since then. Still, original authors deserve credits!
#if CONFIG_TAPE_TURBO
#if !CONFIG_TAPE_AUTODETECT
load_tape_turbo:
#else
load_tape_auto:
#endif
jsr tape_ditch_verify // only LOAD is supported, no VERIFY
// Prepare for sound effects
jsr tape_clean_sid
// Start playing
jsr tape_common_prepare_cia
jsr tape_ask_play
// FALLTROUGH
#if CONFIG_TAPE_AUTODETECT
load_tape_turbo_takeover: // entry point for normal->turbo takeover
jsr tape_common_autodetect
bcc_16 load_tape_normal_takeover
#endif
// FALLTROUGH
load_tape_turbo_header:
// Read file header; structure described here:
// - https://www.luigidifraia.com/c64/docs/tapeloaders.html#turbotape64
//
// 1 byte - file type (0 = data, odd value = relocatable, even value = non-relocatable)
// 2 bytes - start address
// 2 bytes - end address + 1
// 1 byte - if $B0 (tape timing) contained at the time of saving
// (we skip this one to match normal system header)
// 16 bytes - filename, padded with 0x20
jsr tape_turbo_sync_header
#if CONFIG_TAPE_AUTODETECT
bcs_16 load_tape_normal_takeover // failure, probably not a turbo tape file
#endif
ldy #$00
sta (TAPE1), y // store header type
iny
// FALLTROUGH
load_tape_turbo_header_loop:
jsr tape_turbo_get_byte
sta (TAPE1), y
iny
cpy #$05
bne !+
jsr tape_turbo_get_byte // tape timing - skip this one
!:
cpy #$C0 // header is 192 bytes long in total
bne load_tape_turbo_header_loop
// For non-relocatable files, override secondary address
ldy #$00 // XXX optimize out for 65C02
lda (TAPE1), y
beq !+
and #$01
bne !+
lda #$01 // XXX for 65C02 just set the bit with one instruction
sta SA
!:
// Handle the header
jsr tape_clean_sid
jsr tape_handle_header
bcs load_tape_turbo_header // if name does not match, look for other header
// FALLTROUGH
load_tape_turbo_payload:
// Copy helper byte store routine to RAM, provide default memory mapping
ldx #(__tape_turbo_bytestore_size - 1)
!:
lda tape_turbo_bytestore_source, x
sta __tape_turbo_bytestore, x
dex
bpl !-
lda CPU_R6510
sta __tape_turbo_bytestore_defmap
// Initial checksum value
lda #$00
sta PRTY
// Read file payload
!:
jsr tape_turbo_sync_payload
#if CONFIG_TAPE_AUTODETECT
bcs !-
#endif
// FALLTROUGH
load_tape_turbo_loop:
jsr tape_turbo_get_byte
#if ROM_LAYOUT_M65
jsr tape_turbo_byte_store
#else
jsr __tape_turbo_bytestore // like 'sta (MEMUSS),y' - but under I/O
#endif
eor PRTY // handle checksum
sta PRTY
// Advance MEMUSS (see Mapping the C64, page 36)
#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
jsr tape_turbo_get_byte
tax
// Silence audio
jsr tape_clean_sid
// Verify the checksum
cpx PRTY
beq_16 tape_load_success
jmp tape_load_error
#endif // CONFIG_TAPE_TURBO