more sane directory name, updated binaries

This commit is contained in:
FeralChild64 committed 2020-06-26 19:44:01 +02:00
1 parent d4d32095d1
commit 76aaf298b8
697 files changed
+56 -56

No files matched your search

@@ -0,0 +1,36 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Advertise burst IEC protocol support to the receiver
//
//
// Based on idea by Pasi 'Albert' Ojala and description from
// https://sites.google.com/site/h2obsession/CBM/C128/fast-serial-for-uiec
//
#if CONFIG_IEC_BURST_CIA1
burst_advertise:
#if CONFIG_IEC_JIFFYDOS
// Skip if other protocol (only JiffyDOS is possible at this moment) already detected
lda IECPROTO
bmi !+
bne burst_advertise_done
!:
#endif
panic #$FF // XXX implement this
burst_advertise_done:
rts
#endif
@@ -0,0 +1,60 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Advertise burst IEC protocol support to the receiver
//
//
// Based on idea by Pasi 'Albert' Ojala and description from
// https://sites.google.com/site/h2obsession/CBM/C128/fast-serial-for-uiec
//
#if CONFIG_IEC_BURST_CIA2
burst_advertise:
#if CONFIG_IEC_JIFFYDOS
// Skip if other protocol (only JiffyDOS is possible at this moment) already detected
lda IECPROTO
bmi !+
bne burst_advertise_done
!:
#endif
// Make sure this is not done under ATN
jst iec_release_atn
// Set the clock rate to the fastest possible
ldy #$01
sty CIA2_TIMALO
dey
sty CIA2_TIMAHI
// Prepare registers for transfer
lda #$C1
sta CIA2_CRA // start timer A, serial out, TOD 50Hz
bit CIA2_ICR // clear interrupt register
// Send test byte
lda #$FF // $FF keeps DATA released, see https://www.c64-wiki.com/wiki/Fast_serial_bus_protocol
sta CIA2_SDR
// Wait until byte sent
lda #$08 // interrupt mask
!:
bit CIA2_ICR
beq !-
// FALLTROUGH
burst_advertise_done:
rts
#endif
+31
View File
@@ -0,0 +1,31 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Advertise burst IEC protocol support to the receiver
//
#if CONFIG_IEC_BURST_MEGA_65
burst_advertise:
#if CONFIG_IEC_JIFFYDOS
// Skip if other protocol (only JiffyDOS is possible at this moment) already detected
lda IECPROTO
bmi !+
bne burst_advertise_done:
!:
#endif
panic #$FF // XXX implement this
burst_advertise_done:
rts
#endif
+65
View File
@@ -0,0 +1,65 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine for JiffyDOS detection
//
// The standard parallel cable (used by SpeedDOS, DolphinDOS 2, etc.) connects the following UserPort lines:
// - PB0-PB7 - CIA2_PRB ($DD01), CIA #2 port B
// - PC2, FLAG2 - CIA2_ICR ($DD0D), CIA #2 handshaking line
//
// See:
// - http://sta.c64.org/cbmpar41c.html
// - http://sta.c64.org/cbmpar71c.html
// - Commodore 64 Programers Referencee Guide, pages 360-361, 429
// - Computes Mapping the C64, page 183
#if CONFIG_IEC_DOLPHINDOS
dolphindos_detect:
// Make sure the port settings are correct
lda #$7F
sta CIA2_ICR // disable interrupt generation
lda #$00
sta CIA2_DDRB // set all port B lines as input
// According to logs collected from modified VICE emulator, original DolphinDOS ROM
// constantly reads $DD0D and $DD01 until handshake bit of $DD0D is set, or some kind
// of timeout occurs
ldx #$20
dolphindos_detect_loop:
lda CIA2_ICR
cmp #$10
beq dolphindos_detect_success
lda CIA2_PRB // XXX do we need this read?
dex
bne dolphindos_detect_loop
// FALLTROUGH - protocol not detected
dolphindos_detect_fail:
rts
dolphindos_detect_success:
// Protocol detected
lda #$02
sta IECPROTO
rts
#endif // CONFIG_IEC_DOLPHINDOS
+122
View File
@@ -0,0 +1,122 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// DolphinDOS protocol support for IEC - optimized load loop
//
#if CONFIG_IEC_DOLPHINDOS && !CONFIG_MEMORY_MODEL_60K
dolphindos_load:
// Timing is critical for some parts, do not allow interrupts
sei
// A trick to shorten EAL update time
ldy #$00
#if CONFIG_IEC_DOLPHINDOS_FAST
// Another trick: prepare values for quickly setting/releasing DATA
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT - BIT_CIA2_PRA_CLK_OUT - BIT_CIA2_PRA_ATN_OUT
sta IECPROTO // release DATA
ora #BIT_CIA2_PRA_DAT_OUT
sta TBTCNT // pull DATA
#endif
// FALLTROUGH
dolphindos_load_loop:
#if !CONFIG_IEC_DOLPHINDOS_FAST
// Check if this was EOI
bit IOSTATUS
bvs dolphindos_load_end
#endif
// Wait for the talker to release the CLK line
!:
bit CIA2_PRA
bvc !-
// Release the DATA to signal we are ready
#if !CONFIG_IEC_DOLPHINDOS_FAST
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
#else
lda IECPROTO
#endif
sta CIA2_PRA
#if !CONFIG_IEC_DOLPHINDOS_FAST
// Check if EOI
jsr iec_rx_check_eoi // can damage .X, but this is safe
#else
// Check if EOI - inlined code to avoid wasting cycles on RTS
ldx #$13
!:
bit CIA2_PRA
bvc dolphindos_load_no_eoi
dex
bne !-
// EOI - mark it and retrieve the last byte
jsr iec_rx_check_eoi_confirm
lda CIA2_PRB
sta (EAL),y
// Update EAL for the last time
sec
jsr iec_update_EAL_by_Y
// Restore proper IECPROTO value
lda #$02
sta IECPROTO
// End of load loop
jmp load_iec_loop_end
dolphindos_load_no_eoi:
#endif
// Retrieve and store byte
lda CIA2_PRB
sta (EAL),y
// Pull DATA to acknowledge
#if !CONFIG_IEC_DOLPHINDOS_FAST
lda CIA2_PRA
ora #BIT_CIA2_PRA_DAT_OUT
#else
lda TBTCNT
#endif
sta CIA2_PRA
// Handle EAL
iny
bne dolphindos_load_loop
inc EAL+1
jmp dolphindos_load_loop
#if !CONFIG_IEC_DOLPHINDOS_FAST
dolphindos_load_end:
// Update EAL
clc
jsr iec_update_EAL_by_Y
// End of load loop
jmp load_iec_loop_end
#endif
#endif // CONFIG_IEC_DOLPHINDOS and not CONFIG_MEMORY_MODEL_60K
+42
View File
@@ -0,0 +1,42 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper table for encoding lower nibble for JiffyDOS,
// values found by observing the actual transfer using
// original ROMs
//
// Similar tables are probably used by nearly all the disk turbo loaders,
// either on the C64 or drive side, soometimes generated in RAM on the fly;
// example disk turbo presented below has a very similar table - but the
// values are in reversed order:
// - https://www.pagetable.com/?p=568
#if CONFIG_IEC_JIFFYDOS
jiffydos_bittable:
.byte $00
.byte $80 // $10 + $70
.byte $20
.byte $A0 // $30 + $70
.byte $40
.byte $C0 // $50 + $70
.byte $60
.byte $E0 // $70 + $70
.byte $10 // $80 - $70
.byte $90
.byte $30 // $A0 - $70
.byte $B0
.byte $50 // $C0 - $70
.byte $D0
.byte $70 // $E0 - $70
.byte $F0
#endif // CONFIG_IEC_JIFFYDOS
+54
View File
@@ -0,0 +1,54 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// Helper routine for JiffyDOS detection
//
// Detection is done by inserting a long delay (above 400us?) during sending command last bit, see:
// - https://sites.google.com/site/h2obsession/CBM/C128/JiffySoft128
// - https://github.com/rkrajnc/sd2iec/blob/master/src/iec.c
// The 'iec.s' suggests, that the drive should respond by pulling data
// The original JiffyDOS ROM seems to perform detection with every command
// (even though for many of them it always fails) and we have to replicate
// this behaviour for compatibility with at least 1541 JiffyDOS ROM
#if CONFIG_IEC_JIFFYDOS
jiffydos_detect:
ldy #$25 // 400us is nearly 410 cycles on NTSC
// loop iteration below is 11 cycles,
// and several cycles were already used
jiffydos_detect_loop:
lda CIA2_PRA // 4 cycles
bpl jiffydos_detected // 2 cycles
dey // 2 cycles
bne jiffydos_detect_loop // 3 cycles if branch
lda IECPROTO
bpl jiffydos_detect_end // no detection requested, preserve existing protocol
lda #$00 // normal protocol
beq jiffydos_store_proto // branch always
jiffydos_detected:
jsr iec_wait_for_data_release // guessed from VICE logs
lda #$01 // JiffyDOS protocol
// FALLTROUGH
jiffydos_store_proto:
sta IECPROTO
// FALLTROUGH
jiffydos_detect_end:
rts
#endif // CONFIG_IEC_JIFFYDOS
+175
View File
@@ -0,0 +1,175 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// JiffyDOS protocol support for IEC - optimized load loop
//
#if CONFIG_IEC_JIFFYDOS && !CONFIG_MEMORY_MODEL_60K
// Note: original JiffyDOS LOAD loop checks for RUN/STOP key every time a sector is read,
// see description at https://sites.google.com/site/h2obsession/CBM/C128/JiffySoft128
//
// For simplicity and some space savings, our routine does not check the RUN/STOP key at all;
// the protocol is fast enough (especially with modern flash mediums) that probably nobody
// will want to terminate the loading.
jiffydos_load:
// XXX implement JiffyDOS optimized LOAD protocol, this one is ineffective
// Timing is critical, do not allow interrupts
sei
#if CONFIG_IEC_JIFFYDOS_BLANK
// Preserve register with screen status (blank/visible)
lda VIC_SCROLY
sta TBTCNT
// Blank screen to make sure no sprite/badline will interrupt
jsr screen_off
// Preserve 3 lowest bits of CIA2_PRA XXX deduplicate this
lda CIA2_PRA
and #%00000111
sta C3PO
#else
// Store previous sprite status in temporary variable
jsr jiffydos_prepare
sta TBTCNT
#endif
// A trick to shorten EAL update time
ldy #$FF
// FALLTROUGH
jiffydos_load_loop:
// Wait until device is ready to send (releases CLK)
jsr iec_wait_for_clk_release
// Prepare 'start sending' message
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
#if CONFIG_IEC_JIFFYDOS_BLANK
// It seems JiffyDOS needs some time here; waste few cycles
nop
jsr iec_wait_rts
// Ask device to start sending bits
sta CIA2_PRA
#else
// Wait for appropriate moment, ask device to start sending bits
tax
jsr jiffydos_wait_line
stx CIA2_PRA // cycles: 4
#endif
// Prepare 'data pull' byte, cycles: 3 + 2 + 2 = 7
lda C3PO
ora #BIT_CIA2_PRA_DAT_OUT // pull
tax
// Delay, JiffyDOS needs some time, 4 cycles
nop
nop
// Get bits, cycles: 4 + 2 + 2 = 8
lda CIA2_PRA // bits 0 and 1 on CLK/DATA
lsr
lsr
// Delay, JiffyDOS needs some time, 2 cycles
nop
// Get bits, cycles: 4 + 2 + 2 = 8
ora CIA2_PRA // bits 2 and 3 on CLK/DATA
lsr
lsr
// Get bits, cycles: 3 + 4 + 2 + 2 = 11
eor C3PO
eor CIA2_PRA // bits 4 and 5 on CLK/DATA
lsr
lsr
// Get bits, cycles: 3 + 4 = 7
eor C3PO
eor CIA2_PRA // bits 6 and 7 on CLK/DATA
// Store retrieved byte, cycles: 2 + 6 = 8
iny // NTSC needs this delay
sta (EAL),y // not compatible with CONFIG_MEMORY_MODEL_60K
// Retrieve status bits, cycles: 4
bit CIA2_PRA
// Pull DATA at the end, cycles: 4
stx CIA2_PRA
// If CLK line not active - this was the last byte
bvs jiffydos_load_end
// Handle EAL
cpy #$FF
bne jiffydos_load_loop
inc EAL+1
jmp jiffydos_load_loop
jiffydos_load_end:
// Save last byte
tax
// Update EAL
sec
jsr iec_update_EAL_by_Y
// Indicate that no byte waits in output buffer
lda #$00
sta C3PO
// Restore proper IECPROTO value
lda #$01
sta IECPROTO
#if CONFIG_IEC_JIFFYDOS_BLANK
// Restore screen state
lda TBTCNT
sta VIC_SCROLY
#else
// Re-enable sprites
lda TBTCNT
sta VIC_SPENA
#endif
// Store last byte as unoptimized LOAD routine would
stx TBTCNT
// No need to re-enable interrupts; other IEC routines
// called by LOAD will do this nevertheless
// End of load loop
jmp load_iec_loop_end
#endif // CONFIG_IEC_JIFFYDOS and not CONFIG_MEMORY_MODEL_60K
+32
View File
@@ -0,0 +1,32 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// JiffyDOS transfer preparation routine
//
#if CONFIG_IEC_JIFFYDOS
jiffydos_prepare:
// We need to preserve 3 lowest bits of CIA2_PRA, they contain important
// data - fortunately, the bits are never changed by external devices
// Use C3PO for this, as afterwards we have to set there 0 nevertheless
lda CIA2_PRA
and #%00000111
sta C3PO
// Hide sprites; JiffyDOS timing regime is very strict, before transmitting
// anything we need to make sure nothing will steal the cycles
lda VIC_SPENA
ldx #$00
stx VIC_SPENA
rts
#endif // CONFIG_IEC_JIFFYDOS
+121
View File
@@ -0,0 +1,121 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// JiffyDOS protocol support for IEC - byte reception
//
#if CONFIG_IEC_JIFFYDOS
jiffydos_rx_byte:
// Timing is critical, do not allow interrupts
sei
// Store .X and .Y on the stack - preserve them
phx_trash_a
phy_trash_a
// Store previous sprite status on stack
jsr jiffydos_prepare
pha
// Wait until device is ready to send (releases CLK)
jsr iec_wait_for_clk_release
// Prepare 'start sending' message
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
tax
// Wait for appropriate moment
jsr jiffydos_wait_line
// Ask device to start sending bits
stx CIA2_PRA // cycles: 4
// Prepare 'data pull' byte, cycles: 3 + 2 + 2 = 7
lda C3PO
ora #BIT_CIA2_PRA_DAT_OUT // pull
tax
// Delay, JiffyDOS needs some time, 4 cycles
nop
nop
// Get bits, cycles: 4 + 2 + 2 = 8
lda CIA2_PRA // bits 0 and 1 on CLK/DATA
lsr
lsr
// Wait for the drive, cycles: 2
nop
// Get bits, cycles: 4 + 2 + 2 = 8
ora CIA2_PRA // bits 2 and 3 on CLK/DATA
lsr
lsr
// Get bits, cycles: 3 + 4 + 2 + 2 = 11
eor C3PO
eor CIA2_PRA // bits 4 and 5 on CLK/DATA
lsr
lsr
// Get bits, cycles: 3 + 4 = 7
eor C3PO
eor CIA2_PRA // bits 6 and 7 on CLK/DATA
// Preserve read byte, cycles: 3
sta TBTCNT // $A4 is a byte buffer according to http://sta.c64.org/cbm64mem.html
// Delay, JiffyDOS needs some time; for PAL one NOP would be enough,
// but NTSC machines are clocked slightly faster; cycles: 4
nop
nop
// Retrieve status bits, cycles: 4
bit CIA2_PRA
// Pull DATA at the end, cycles: 4
stx CIA2_PRA
// If CLK line active - success
bvc jiffydos_rx_byte_end
// EOI or error, released DATA (highest byte set to 1) means error - see protocol analysis by Michael Steil, step R7a
lda CIA2_PRA
bmi jiffydos_rx_byte_error
// EOI - no error
jsr kernalstatus_EOI
// FALLTROUGH
jiffydos_rx_byte_end:
// Indicate that no byte waits in output buffer
lda #$00
sta C3PO
// Restore proper IECPROTO value
lda #$01
sta IECPROTO
// Re-enable sprites
pla
sta VIC_SPENA
// End byte reception
jmp iec_rx_end
jiffydos_rx_byte_error:
jsr kernalerror_IEC_TIMEOUT_READ
bcs jiffydos_rx_byte_end // branch always
#endif // CONFIG_IEC_JIFFYDOS
+111
View File
@@ -0,0 +1,111 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// JiffyDOS protocol support for IEC - byte transfer
//
#if CONFIG_IEC_JIFFYDOS
jiffydos_tx_byte:
// Timing is critical, do not allow interrupts
sei
// If EOI requested (carry flag set), mark this in IECPROTO as 0
bcc !+
dec IECPROTO // turns 1 into 0
!:
// Store .X and .Y on the stack - preserve them
phx_trash_a
phy_trash_a
// Make sure we are not sending data on ATN
jsr iec_release_atn
// Store previous sprite status on stack
jsr jiffydos_prepare
pha
// Prepare nibbles to send
lda TBTCNT
and #$0F
tax
lda jiffydos_bittable, X // low nibble has to be encoded
pha
lda TBTCNT
and #$F0
pha
// Prepare value for device notification
ldx C3PO
// Wait till receiver is ready
jsr iec_wait_for_data_release
// Wait till it is safe to send data
jsr jiffydos_wait_line
// Notify device that we are going to send byte by releasing everything
stx CIA2_PRA // cycles: 4
// Send high nibble; cycles: 4 + 3 + 4 + 2 + 2 + 2 + 3 + 4 = 24
pla // retrieve high nibble from stack
ora C3PO // restore VIC-II and RS-232 bits
sta CIA2_PRA // bits 4 and 5 on CLK/DATA
lsr // move bits 6 and 7 to positions 4 and 5
lsr
and #%00110000 // clear everything but CLK/DATA
ora C3PO
sta CIA2_PRA // bits 6 and 7 on CLK/DATA
// Send low nibble; cycles: 4 + 3 + 4 + 2 + 2 + 2 + 4 = 21
pla // retrieve low nibble from stack
ora C3PO // restore VIC-II and RS-232 bits
sta CIA2_PRA
lsr
lsr
and #%00110000 // clear everything but CLK/DATA
sta CIA2_PRA
// Signal EOI if needed; cycles till no EOI: 3 + 3 + 2 + 2 + 4 = 14
lda C3PO
ldx IECPROTO
beq jiffydos_tx_byte_wait_eoi
// FALLTROUGH
jiffydos_tx_byte_finalize:
ora #BIT_CIA2_PRA_CLK_OUT // pull CLK
sta CIA2_PRA
// Restore proper IECPROTO value
lda #$01
sta IECPROTO
// Re-enable sprites and interrupts
pla
sta VIC_SPENA
cli
// Return success
jmp iec_return_success
jiffydos_tx_byte_wait_eoi:
sta CIA2_PRA
jsr iec_wait20us
lda C3PO
// According to protocol analysis by Michael Steil (step S8) we should pull the DATA here
// to signal there was no error; but DATA pulled by the controller is a normal state
// (which should be stored in C3PO), so there is nothing to do here.
jmp jiffydos_tx_byte_finalize
#endif // CONFIG_IEC_JIFFYDOS
+37
View File
@@ -0,0 +1,37 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * KERNAL_0 #TAKE
// #LAYOUT# * * #IGNORE
//
// JiffyDOS helper routine to wait for appropriate moment,
// where no badline will interrupt the transmission
//
#if CONFIG_IEC_JIFFYDOS
jiffydos_wait_line:
// One might try to optimize the code by checking for disabled screen
// (bit 4 of VIC_SCROLY); problem: VIC checks this bit only once per frame:
// - https://www.lemon64.com/forum/viewtopic.php?t=56582
// so it would complicated the code
// Avoid 2 lines before the badline, otherwise VIC will ruin the synchronization
lda VIC_RASTER
cmp #$2E
bcc jiffydos_wait_line_done // we are safe, border - lot of time till badline
!:
lda VIC_RASTER // carry+ is definitely set here!
sbc VIC_SCROLY
and #$07 // we want 8 lowest bits
cmp #$06
bcs !-
jiffydos_wait_line_done:
rts
#endif // CONFIG_IEC_JIFFYDOS