From: Maxwell Beck Date: Mon, 30 Dec 2024 23:44:29 +0000 (-0600) Subject: Fix byte ready to CPU overflow flag sync X-Git-Url: https://rastertail.net/scm/?a=commitdiff_plain;p=pico1541.git Fix byte ready to CPU overflow flag sync --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f4a923..fdff714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ include(pico_sdk_import.cmake) project(pico1541 VERSION 0.1.0) pico_sdk_init() -add_executable(pico1541 src/pico1541.c src/6502.c src/6522.c src/drive.c testbin/1541.o testbin/bsk1.o) +add_executable(pico1541 src/pico1541.c src/6502.c src/6522.c src/drive.c testbin/1541.o testbin/memento_mori.o) pico_set_binary_type(pico1541 copy_to_ram) target_link_libraries(pico1541 pico_runtime pico_multicore hardware_timer) pico_add_extra_outputs(pico1541) \ No newline at end of file diff --git a/src/drive.c b/src/drive.c index 64b765a..5bc2e3b 100644 --- a/src/drive.c +++ b/src/drive.c @@ -47,7 +47,7 @@ void drive_init(drive_t *drive) { drive->current_idx = 0; drive->lookahead_idx = 0; - drive_cycle(drive, 0, false); + drive_cycle(drive); } void drive_step_up(drive_t *drive) { @@ -68,16 +68,19 @@ void drive_step_down(drive_t *drive) { } } -bool drive_cycle(drive_t *drive, uint8_t cycles, bool advance) { +bool drive_advance(drive_t *drive, uint8_t cycles) { bool byte_ready = false; - if (advance) { - for (uint8_t i = 0; i < cycles; i++) { - uint8_t j = (i + drive->current_idx) & (DRIVE_LOOKAHEAD - 1); - byte_ready |= drive->byte_ready[j]; - } - drive->current_idx = (drive->current_idx + cycles) & (DRIVE_LOOKAHEAD - 1); + + for (uint8_t i = 0; i < cycles; i++) { + uint8_t j = (i + drive->current_idx) & (DRIVE_LOOKAHEAD - 1); + byte_ready |= drive->byte_ready[j]; } + drive->current_idx = (drive->current_idx + cycles) & (DRIVE_LOOKAHEAD - 1); + return byte_ready; +} + +void drive_cycle(drive_t *drive) { while (drive->lookahead_idx != ((drive->current_idx - 1) & (DRIVE_LOOKAHEAD - 1))) { uint8_t j = (drive->lookahead_idx + 1) & (DRIVE_LOOKAHEAD - 1); uint8_t timer_next = drive->timer + BITRATE_PER_TRACK[drive->track]; @@ -194,6 +197,4 @@ bool drive_cycle(drive_t *drive, uint8_t cycles, bool advance) { drive->lookahead_idx = j; drive->timer = timer_next; } - - return byte_ready; } diff --git a/src/drive.h b/src/drive.h index e131c5c..aa72f60 100644 --- a/src/drive.h +++ b/src/drive.h @@ -42,6 +42,7 @@ typedef struct drive_s { void drive_init(drive_t *drive); void drive_step_up(drive_t *drive); void drive_step_down(drive_t *drive); -bool drive_cycle(drive_t *drive, uint8_t cycles, bool advance); +bool drive_advance(drive_t *drive, uint8_t cycles); +void drive_cycle(drive_t *drive); #endif \ No newline at end of file diff --git a/src/pico1541.c b/src/pico1541.c index 3489fee..fec76a3 100644 --- a/src/pico1541.c +++ b/src/pico1541.c @@ -18,7 +18,7 @@ const uint8_t DEVICE = 8; static uint8_t ram[2048]; extern uint8_t _binary__Users_max_Documents_c64_roms_dos1541_start[16384]; // extern uint8_t _binary__Users_max_Downloads_blackbird_1_2_Blackbird_1_2_d64_start[174848]; -extern uint8_t _binary__Users_max_Downloads_Bloodsuckers_StillRising_BSK_StillRising_disk1_d64_start[174848]; +extern uint8_t _binary__Users_max_Downloads_MementoMori_GP_MementoMori_GP_Disk1_d64_start[174848]; uint32_t ts; cpu_t cpu; @@ -138,14 +138,11 @@ void atn_irq_callback(uint pin, uint32_t flags) { void drive_thread() { drive_init(&drive); - drive.image = _binary__Users_max_Downloads_Bloodsuckers_StillRising_BSK_StillRising_disk1_d64_start; + drive.image = _binary__Users_max_Downloads_MementoMori_GP_MementoMori_GP_Disk1_d64_start; multicore_fifo_push_blocking(1); - while (true) { - uint32_t cycles = multicore_fifo_pop_blocking_inline(); - if (drive_cycle(&drive, cycles, true) && (via2.pcr & 0b1110) == 0b1110) { - cpu.flags |= 1 << FLAG_V_BIT; - } + while (multicore_fifo_pop_blocking_inline()) { + drive_cycle(&drive); } } @@ -192,7 +189,10 @@ int main() { } uint8_t cycles = cpu_step(&cpu); - multicore_fifo_push_blocking_inline((uint32_t)cycles); + if (drive_advance(&drive, cycles) && (via2.pcr & 0b1110) == 0b1110) { + cpu.flags |= 1 << FLAG_V_BIT; + } + multicore_fifo_push_blocking_inline(1); via_cycle(&via1, cycles); via_cycle(&via2, cycles);