initial work towards burst IEC protocol support

This commit is contained in:
FeralChild64 committed 2019-12-30 20:28:52 +01:00
1 parent 99afae45c6
commit f05ddef5fd
20 files changed
+280 -68

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
//
// Values for IRQ generation timer - original idea was:
//
// (This value was calculated by running a custom IRQ handler on a C64
// with original KERNAL, and writing the values of $DC04/5 to the screen
// in the IRQ handler to see roughly what value the timers must be set to)
// ldy #<16380
// ldx #>16380
// Current values selected on the following assumptions:
//
// PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
// is clocked at 0.985248 MHz, so that 1/60s is 16421 ($4025) CPU cycles
//
// NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
// is clocked at 1.022727 MHz, so that 1/60s is 17045 ($4295) CPU cycles
irq_timing_hi: // high bytes
.byte >17045 // NTSC
.byte >16421 // PAL
+23
View File
@@ -0,0 +1,23 @@
//
// Values for IRQ generation timer - original idea was:
//
// (This value was calculated by running a custom IRQ handler on a C64
// with original KERNAL, and writing the values of $DC04/5 to the screen
// in the IRQ handler to see roughly what value the timers must be set to)
// ldy #<16380
// ldx #>16380
// Current values selected on the following assumptions:
//
// PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
// is clocked at 0.985248 MHz, so that 1/60s is 16421 ($4025) CPU cycles
//
// NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
// is clocked at 1.022727 MHz, so that 1/60s is 17045 ($4295) CPU cycles
irq_timing_lo: // low bytes
.byte <17045 // NTSC
.byte <16421 // PAL
+7 -1
View File
@@ -17,13 +17,19 @@ iec_cmd_open: // similar to TKSA, but without turnaround
!:
ora #$F0
#if CONFIG_IEC_DOLPHINDOS
#if CONFIG_IEC_DOLPHINDOS || CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT
sta TBTCNT
jsr iec_tx_command
bcs !+ // branch if error
#if CONFIG_IEC_DOLPHINDOS
jsr dolphindos_detect
#endif
#if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT
jsr burst_detect
#endif
jmp iec_tx_command_finalize
#else
@@ -1,6 +1,6 @@
//
// Common routines for multiple IEC fact protocols
// Common EAL update routine
//
+3 -2
View File
@@ -63,9 +63,10 @@ load_iec:
bcs load_iec_error
#if CONFIG_IEC_DOLPHINDOS
jsr dolphindos_detect
#endif
#if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT
jsr burst_detect
#endif
// We are currently talker, so do the IEC turn around so that we
+3 -2
View File
@@ -45,9 +45,10 @@ save_iec:
bcs save_iec_dev_not_found
#if CONFIG_IEC_DOLPHINDOS
jsr dolphindos_detect
#endif
#if CONFIG_IEC_BURST_CIA1 || CONFIG_IEC_BURST_CIA2 || CONFIG_IEC_BURST_SOFT
jsr burst_detect
#endif
// Save start address
+31
View File
@@ -0,0 +1,31 @@
//
// Helper routine for burst IEC protocol support
//
//
// Based on idea by Pasi 'Albert' Ojala
//
#if CONFIG_IEC_BURST_CIA1
burst_detect:
#if CONFIG_IEC_JIFFYDOS || CONFIG_IEC_DOLPHINDOS
lda IECPROTO
bmi !+
bne burst_detect_fail // skip if other protocol already detected
!:
#endif
panic #$FF // XXX implement this
burst_detect_fail:
rts
#endif
+66
View File
@@ -0,0 +1,66 @@
//
// Helper routine for burst IEC protocol support
//
//
// Based on idea by Pasi 'Albert' Ojala
//
#if CONFIG_IEC_BURST_CIA2
burst_detect:
#if CONFIG_IEC_JIFFYDOS || CONFIG_IEC_DOLPHINDOS
lda IECPROTO
bmi !+
bne burst_detect_fail // skip if other protocol already detected
!:
#endif
// For extra safety, do it on disabled interupts
php
sei
// 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 !-
// Now see if we get any byte back
lda CIA2_SDR // XXX we do not need a value, we need to know if it was received
panic #$00 // XXX finish this routine
plp
// FALLTROUGH
burst_detect_fail:
rts
#endif
+27
View File
@@ -0,0 +1,27 @@
//
// Helper routine for burst IEC protocol support
//
#if CONFIG_IEC_BURST_SOFT
burst_detect:
#if CONFIG_IEC_JIFFYDOS || CONFIG_IEC_DOLPHINDOS
lda IECPROTO
bmi !+
bne burst_detect_fail // skip if other protocol already detected
!:
#endif
panic #$FF // XXX implement this
burst_detect_fail:
rts
#endif
+3 -3
View File
@@ -20,7 +20,7 @@ jiffydos_load:
// Timing is critical, do not allow interrupts
sei
#if CONFIG_IEC_BLANK_SCREEN
#if CONFIG_IEC_JIFFYDOS_BLANK
// Preserve register with screen status (blank/visibe)
lda VIC_SCROLY
@@ -57,7 +57,7 @@ jiffydos_load_loop:
lda CIA2_PRA
and #$FF - BIT_CIA2_PRA_DAT_OUT // release
#if CONFIG_IEC_BLANK_SCREEN
#if CONFIG_IEC_JIFFYDOS_BLANK
// It seems JiffyDOS needs some time here; waste few cycles
nop
@@ -143,7 +143,7 @@ jiffydos_load_end:
lda #$01
sta IECPROTO
#if CONFIG_IEC_BLANK_SCREEN
#if CONFIG_IEC_JIFFYDOS_BLANK
// Restore screen state
lda TBTCNT
+2 -9
View File
@@ -110,8 +110,6 @@ IOINIT:
lda #$3F
sta CIA2_DDRA // $DD02
// XXX detect TOD clock, see https://codebase64.org/doku.php?id=base:efficient_tod_initialisation
// XXX how to initialize these timers???
// stx CIA1_CRB // $DC0F
// stx CIA2_CRA // $DD0E
@@ -123,13 +121,8 @@ IOINIT:
ldx #%00000111 // XXX adapt this to IEC idle state, JMP at the end won't be needed
stx CIA2_PRA // $DD00
//
ldy #<16421
ldx #>16421
sty CIA1_TIMALO // $DC04
stx CIA1_TIMAHI // $DC05
// Put something sane in the IRQ timer
jsr setup_irq_timer
// Enable timer A to run continuously (http://codebase64.org/doku.php?id=base:timerinterrupts)
ldx #$11
+27 -31
View File
@@ -23,43 +23,39 @@ setup_pal_ntsc:
setup_pal:
// Set timer interval to ~1/60th of a second
// (This value was calculated by running a custom IRQ handler on a C64
// with original KERNAL, and writing the values of $DC04/5 to the screen
// in the IRQ handler to see roughly what value the timers must be set to)
// ldy #<16380
// ldx #>16380
// PAL C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
// is clocked at 0.985248 MHz, so that 1/60s is 16421 ($4025) CPU cycles
ldy #<16421
ldx #>16421
lda #$01
skip_2_bytes_trash_nvz
// FALLTROUGH
setup_ntsc:
lda #$00
// FALLTROUGH
setup_pal_ntsc_end:
sty CIA1_TIMALO // $DC04
stx CIA1_TIMAHI // $DC05
sta TVSFLG
// FALLTROUGH
setup_irq_timer: // entry point needed by UP9600 and CIA1 burst mod support
// Sets up IRQ timer in CIA1 to ~1/60th of a second,
// depending on the detected video system
// Retrieve video system (0 - NTSC, 1 - PAL), assume PAL for unknown values
ldx TVSFLG
beq !+
ldx #$01
!:
// Setup interval for timer A in CIA1
lda irq_timing_lo, x
sta CIA1_TIMALO // $DC04
lda irq_timing_hi, x
sta CIA1_TIMAHI // $DC05
rts
setup_ntsc:
// Set timer interval to ~1/60th of a second
// NTSC C64 (https://codebase64.org/doku.php?id=base:cpu_clocking),
// is clocked at 1.022727 MHz, so that 1/60s is 17045 ($4295) CPU cycles
ldy #<17045
ldx #>17045
lda #$00
beq setup_pal_ntsc_end // branch always