summary refs log tree commit diff
path: root/src/drive.h
blob: aa72f605d789415a820ef9f6a2dca89b8a34128d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef DRIVE_H
#define DRIVE_H

#include <stdbool.h>
#include <stdint.h>

#define DRIVE_LOOKAHEAD 8

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 {
	volatile bool spinning;
	uint8_t timer;
	uint8_t *image;

	volatile uint8_t track;
	volatile uint8_t halftrack;
	volatile uint32_t image_ptr;
	volatile 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;
	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);
void drive_step_up(drive_t *drive);
void drive_step_down(drive_t *drive);
bool drive_advance(drive_t *drive, uint8_t cycles);
void drive_cycle(drive_t *drive);

#endif