summary refs log tree commit diff
path: root/src/drive.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/drive.h')
-rw-r--r--src/drive.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/drive.h b/src/drive.h
new file mode 100644
index 0000000..b9fb1f2
--- /dev/null
+++ b/src/drive.h
@@ -0,0 +1,47 @@
+#ifndef DRIVE_H
+#define DRIVE_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#define DRIVE_LOOKAHEAD 16
+
+extern const uint8_t SECTORS_PER_TRACK[40];
+extern const uint8_t BITRATE_PER_TRACK[40];
+extern const uint8_t GCR_CONV[16];
+
+typedef struct drive_s {
+	bool spinning;
+	uint8_t timer;
+	uint8_t *image;
+
+	uint8_t track;
+	uint8_t halftrack;
+	uint32_t image_ptr;
+	uint8_t sector;
+	uint8_t byte;
+
+	uint16_t gcr_word;
+	uint8_t gcr_bits;
+	uint8_t bit_counter;
+
+	uint8_t gap_remain;
+	uint8_t sync_remain;
+	uint8_t header_remain;
+	uint16_t data_remain;
+	uint8_t data_checksum;
+
+	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];
+} drive_t;
+
+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);
+
+#endif
\ No newline at end of file