]> Untitled Git - pico1541.git/commitdiff
Use multicore to meet timing
authorMaxwell Beck <max@rastertail.net>
Sun, 29 Dec 2024 01:09:06 +0000 (19:09 -0600)
committerMaxwell Beck <max@rastertail.net>
Sun, 29 Dec 2024 01:09:06 +0000 (19:09 -0600)
CMakeLists.txt
src/6502.h
src/drive.h
src/pico1541.c

index 59c6d704656c4cf4febbbaa21f7205a4e0120654..0f4a923d8b961d4f189e3ab9f64dd94a331d1d77 100644 (file)
@@ -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/testimage.o)
+add_executable(pico1541 src/pico1541.c src/6502.c src/6522.c src/drive.c testbin/1541.o testbin/bsk1.o)
 pico_set_binary_type(pico1541 copy_to_ram)
-target_link_libraries(pico1541 pico_runtime hardware_timer)
+target_link_libraries(pico1541 pico_runtime pico_multicore hardware_timer)
 pico_add_extra_outputs(pico1541)
\ No newline at end of file
index 133362373df0d58c3895b71bd0645dfcca2ca903..78f03e8d3763804a07d23f3410863445992999bf 100644 (file)
@@ -25,7 +25,7 @@ typedef struct cpu_s {
        uint8_t x;
        uint8_t y;
        uint8_t sp;
-       uint8_t flags;
+       volatile uint8_t flags;
 
        bool irq;
        bool nmi;
index b9fb1f2a4caafa4580e238ecf93926e216500384..c41712ae00999d685c7ee6fffd38fc46c577404a 100644 (file)
@@ -11,14 +11,14 @@ extern const uint8_t BITRATE_PER_TRACK[40];
 extern const uint8_t GCR_CONV[16];
 
 typedef struct drive_s {
-       bool spinning;
+       volatile bool spinning;
        uint8_t timer;
        uint8_t *image;
 
-       uint8_t track;
-       uint8_t halftrack;
-       uint32_t image_ptr;
-       uint8_t sector;
+       volatile uint8_t track;
+       volatile uint8_t halftrack;
+       volatile uint32_t image_ptr;
+       volatile uint8_t sector;
        uint8_t byte;
 
        uint16_t gcr_word;
@@ -33,10 +33,10 @@ typedef struct drive_s {
 
        uint8_t current_idx;
        uint8_t lookahead_idx;
-       uint16_t unlatched[DRIVE_LOOKAHEAD];
-       uint16_t latched[DRIVE_LOOKAHEAD];
-       bool sync[DRIVE_LOOKAHEAD];
-       bool byte_ready[DRIVE_LOOKAHEAD];
+       volatile uint16_t unlatched[DRIVE_LOOKAHEAD];
+       volatile uint16_t latched[DRIVE_LOOKAHEAD];
+       volatile bool sync[DRIVE_LOOKAHEAD];
+       volatile bool byte_ready[DRIVE_LOOKAHEAD];
 } drive_t;
 
 void drive_init(drive_t *drive);
index f76d8c3ce9a57ab2b066e6a7671422cf096b28da..266bfd781ca0380dd99ab24dd3cc625c1d9a43d9 100644 (file)
@@ -1,6 +1,7 @@
 #include <hardware/clocks.h>
 #include <hardware/gpio.h>
 #include <hardware/timer.h>
+#include <pico/multicore.h>
 
 #include "6502.h"
 #include "6522.h"
@@ -16,14 +17,14 @@ 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_3sira_still_human_by_arise_3sira_by_arise_A_d64_start[174848];
+// 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];
 
-static uint32_t ts;
-static cpu_t cpu;
+uint32_t ts;
+cpu_t cpu;
 static via_t via1;
 static via_t via2;
-static drive_t drive;
+drive_t drive;
 
 int8_t track_step;
 
@@ -135,8 +136,22 @@ 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;
+       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;
+               }
+       }
+}
+
 int main() {
        set_sys_clock_khz(250000, true);
+       multicore_launch_core1(drive_thread);
 
        gpio_init(GPIO_CLK);
        gpio_init(GPIO_DATA);
@@ -163,8 +178,7 @@ int main() {
        gpio_set_irq_enabled_with_callback(GPIO_ATN, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, &atn_irq_callback);
 
        track_step = 0;
-       drive_init(&drive);
-       drive.image = _binary__Users_max_Downloads_blackbird_1_2_Blackbird_1_2_d64_start;
+       multicore_fifo_pop_blocking();
 
        cpu_reset(&cpu);
        via_init(&via1);
@@ -173,25 +187,20 @@ int main() {
        ts = time_us_32();
        uint16_t osc2 = 0xffff;
        while (!cpu.jammed) {
-               if (ts + 100 < time_us_32()) {
+               if (ts < time_us_32()) {
                        break;
                }
 
                uint8_t cycles = cpu_step(&cpu);
+               multicore_fifo_push_blocking_inline((uint32_t)cycles);
 
                via_cycle(&via1, cycles);
                via_cycle(&via2, cycles);
                cpu.irq = via_irq(&via1) | via_irq(&via2);
 
-               if (drive_cycle(&drive, cycles, true) && (via2.pcr & 0b1110) == 0b1110) {
-                       cpu.flags |= 1 << FLAG_V_BIT;
-               }
-
                ts += cycles;
                while (ts > time_us_32()) {}
        }
 
-       gpio_put(GPIO_LED, 1);
-
        return 0;
 }