comparison cdd_mcu.h @ 2061:7c1760b5b3e5 segacd

Implemented basic TOC functionality of CDD MCU
author Michael Pavone <pavone@retrodev.com>
date Thu, 27 Jan 2022 00:33:41 -0800
parents
children 07ed42bd7b4c
comparison
equal deleted inserted replaced
2060:f1c2415f4d1d 2061:7c1760b5b3e5
1 #ifndef CDD_MCU_H_
2 #define CDD_MCU_H_
3 #include "system.h"
4
5
6 typedef enum {
7 SF_ABSOLUTE,
8 SF_RELATIVE,
9 SF_TRACK,
10 SF_TOCO,
11 SF_TOCT,
12 SF_TOCN,
13 SF_E,
14 SF_NOTREADY = 0xF
15 } status_format;
16
17 typedef enum {
18 CMD_NOP,
19 CMD_STOP,
20 CMD_REPORT_REQUEST,
21 CMD_READ,
22 CMD_SEEK,
23 CMD_INVALID,
24 CMD_PAUSE,
25 CMD_PLAY,
26 CMD_FFWD,
27 CMD_RWD,
28 CMD_TRACK_SKIP,
29 CMD_TRACK_CUE,
30 CMD_DOOR_CLOSE,
31 CMD_DOOR_OPEN
32 } host_cmd;
33
34 typedef enum {
35 DS_STOP,
36 DS_PLAY,
37 DS_SEEK,
38 DS_SCAN,
39 DS_PAUSE,
40 DS_DOOR_OPEN,
41 DS_SUM_ERROR,
42 DS_CMD_ERROR,
43 DS_FUNC_ERROR,
44 DS_TOC_READ,
45 DS_TRACKING,
46 DS_NO_DISC,
47 DS_DISC_LEADOUT,
48 DS_DISC_LEADIN,
49 DS_TRAY_MOVING,
50 } drive_status;
51
52
53 typedef struct {
54 uint8_t status;
55 uint8_t format;
56 union {
57 struct {
58 uint8_t min_high;
59 uint8_t min_low;
60 uint8_t sec_high;
61 uint8_t sec_low;
62 uint8_t frame_high;
63 uint8_t frame_low;
64 uint8_t flags;
65 } time;
66 struct {
67 uint8_t track_high;
68 uint8_t track_low;
69 uint8_t padding0;
70 uint8_t padding1;
71 uint8_t control;
72 uint8_t padding2;
73 uint8_t flags;
74 } track;
75 struct {
76 uint8_t first_track_high;
77 uint8_t first_track_low;
78 uint8_t last_track_high;
79 uint8_t last_track_low;
80 uint8_t version;
81 uint8_t padding;
82 uint8_t flags;
83 } toct;
84 struct {
85 uint8_t min_high;
86 uint8_t min_low;
87 uint8_t sec_high;
88 uint8_t sec_low;
89 uint8_t frame_high;
90 uint8_t frame_low;
91 uint8_t track_low;
92 } tocn;
93 struct {
94 } error;
95 } b;
96 uint8_t checksum;
97 } cdd_status;
98
99 typedef struct {
100 uint8_t cmd_type;
101 uint8_t must_be_zero;
102 union {
103 struct {
104 uint8_t min_high;
105 uint8_t min_low;
106 uint8_t sec_high;
107 uint8_t sec_low;
108 uint8_t frame_high;
109 uint8_t frame_low;
110 } time;
111 struct {
112 uint8_t padding;
113 uint8_t status_type;
114 uint8_t track_high;
115 uint8_t track_low;
116 } format;
117 struct {
118 uint8_t padding;
119 uint8_t direction;
120 uint8_t tracks_highest;
121 uint8_t tracks_midhigh;
122 uint8_t tracks_midlow;
123 uint8_t tracks_lowest;
124 } skip;
125 struct {
126 uint8_t track_high;
127 uint8_t track_low;
128 } track;
129 } b;
130 uint8_t padding;
131 uint8_t checksum;
132 } cdd_cmd;
133
134 typedef struct {
135 system_media *media;
136 uint32_t cycle; //this is in CD block CLKS
137 uint32_t next_int_cycle; //this is in SCD MCLKS
138 uint32_t last_subcode_cycle;
139 uint32_t last_nibble_cycle;
140 int current_status_nibble;
141 int current_cmd_nibble;
142 uint32_t head_pba;
143 uint32_t seek_pba;
144 cdd_status status_buffer;
145 cdd_cmd cmd_buffer;
146 status_format requested_format;
147 drive_status status;
148 drive_status error_status;
149 uint8_t requested_track;
150 uint8_t cmd_recv_wait;
151 uint8_t cmd_recv_pending;
152 uint8_t int_pending;
153 uint8_t toc_valid;
154 uint8_t seeking;
155 } cdd_mcu;
156
157 void cdd_mcu_init(cdd_mcu *context, system_media *media);
158 void cdd_mcu_run(cdd_mcu *context, uint32_t cycle, uint16_t *gate_array);
159 void cdd_hock_enabled(cdd_mcu *context);
160 void cdd_hock_disabled(cdd_mcu *context);
161 void cdd_mcu_start_cmd_recv(cdd_mcu *context, uint16_t *gate_array);
162 void cdd_mcu_adjust_cycle(cdd_mcu *context, uint32_t deduction);
163
164 #endif //CD_MCU_H_