summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/concept_dsk.cpp
blob: 7f5edce3363c3aa7c949c2a0c3d8bde08393da1e (plain) (blame)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert, R. Belmont
/*********************************************************************

    formats/concept_dsk.c

    Formats for Corvus Concept

    5.25" DSDD is PC MFM, 77 tracks, double-sided, with 9 sectors per track

*********************************************************************/

#include "formats/concept_dsk.h"

#include "ioprocs.h"


/* 9 sectors / track, 512 bytes per sector */
const floppy_image_format_t::desc_e cc525dsdd_format::cc_9_desc[] = {
	{ MFM, 0x4e, 80 },
	{ MFM, 0x00, 12 },
	{ RAW, 0x5224, 3 },
	{ MFM, 0xfc, 1 },
	{ MFM, 0x4e, 50 },
	{ MFM, 0x00, 12 },
	{ SECTOR_LOOP_START, 1, 9 },
	{   CRC_CCITT_START, 1 },
	{     RAW, 0x4489, 3 },
	{     MFM, 0xfe, 1 },
	{     TRACK_ID },
	{     HEAD_ID },
	{     SECTOR_ID },
	{     SIZE_ID },
	{   CRC_END, 1 },
	{   CRC, 1 },
	{   MFM, 0x4e, 22 },
	{   MFM, 0x00, 12 },
	{   CRC_CCITT_START, 2 },
	{     RAW, 0x4489, 3 },
	{     MFM, 0xfb, 1 },
	{     SECTOR_DATA, -1 },
	{   CRC_END, 2 },
	{   CRC, 2 },
	{   MFM, 0x4e, 84 },
	{   MFM, 0x00, 12 },
	{ SECTOR_LOOP_END },
	{ MFM, 0x4e, 170 },
	{ END }
};

cc525dsdd_format::cc525dsdd_format()
{
}

const char *cc525dsdd_format::name() const
{
	return "concept";
}

const char *cc525dsdd_format::description() const
{
	return "Corvus Concept 5.25\" DSDD floppy disk image";
}

const char *cc525dsdd_format::extensions() const
{
	return "img";
}

bool cc525dsdd_format::supports_save() const
{
	return true;
}

void cc525dsdd_format::find_size(util::random_read &io, uint8_t &track_count, uint8_t &head_count, uint8_t &sector_count)
{
	track_count = 77;
	head_count = 2;
	sector_count = 9;

	uint32_t const expected_size = 512 * track_count*head_count*sector_count;

	uint64_t size;
	if (!io.length(size) && (size == expected_size))
		return;

	track_count = head_count = sector_count = 0;
}

int cc525dsdd_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants)
{
	uint8_t track_count, head_count, sector_count;
	find_size(io, track_count, head_count, sector_count);

	if (track_count)
		return 50;

	return 0;
}

bool cc525dsdd_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image)
{
	uint8_t track_count, head_count, sector_count;
	find_size(io, track_count, head_count, sector_count);

	uint8_t sectdata[10*512];
	desc_s sectors[10];
	for (int i=0; i<sector_count; i++) {
		sectors[i+1].data = sectdata + 512*i;
		sectors[i+1].size = 512;
		sectors[i+1].sector_id = i+1;
	}

	int track_size = sector_count*512;
	for (int track=0; track < track_count; track++) {
		for (int head=0; head < head_count; head++) {
			size_t actual;
			io.read_at((track*head_count + head) * track_size, sectdata, track_size, actual);
			generate_track(cc_9_desc, track, head, sectors, sector_count, 100000, image);
		}
	}

	image->set_variant(floppy_image::DSDD);

	return true;
}

bool cc525dsdd_format::save(util::random_read_write &io, const std::vector<uint32_t> &variants, floppy_image *image)
{
	int track_count, head_count, sector_count;
	get_geometry_mfm_pc(image, 2000, track_count, head_count, sector_count);

	if (track_count != 77)
		track_count = 77;

	// Happens for a fully unformatted floppy
	if (!head_count)
		head_count = 2;

	if (sector_count != 9)
		sector_count = 9;

	uint8_t sectdata[9*512];
	int track_size = sector_count*512;

	for (int track=0; track < track_count; track++) {
		for (int head=0; head < head_count; head++) {
			get_track_data_mfm_pc(track, head, image, 2000, 512, sector_count, sectdata);
			size_t actual;
			io.write_at((track*head_count + head)*track_size, sectdata, track_size, actual);
		}
	}

	return true;
}

const floppy_format_type FLOPPY_CONCEPT_525DSDD_FORMAT = &floppy_image_format_creator<cc525dsdd_format>;