1 // license:BSD-3-Clause
2 // copyright-holders:Olivier Galibert
3 /*********************************************************************
4
5 formats/oric_dsk.c
6
7 Oric disk images
8
9 *********************************************************************/
10
11 #include "formats/oric_dsk.h"
12
13
oric_dsk_format()14 oric_dsk_format::oric_dsk_format()
15 {
16 }
17
name() const18 const char *oric_dsk_format::name() const
19 {
20 return "oric_dsk";
21 }
22
description() const23 const char *oric_dsk_format::description() const
24 {
25 return "Oric disk image";
26 }
27
extensions() const28 const char *oric_dsk_format::extensions() const
29 {
30 return "dsk";
31 }
32
supports_save() const33 bool oric_dsk_format::supports_save() const
34 {
35 return true;
36 }
37
identify(io_generic * io,uint32_t form_factor)38 int oric_dsk_format::identify(io_generic *io, uint32_t form_factor)
39 {
40 uint8_t h[256];
41 io_generic_read(io, h, 0, 256);
42
43 if(memcmp(h, "MFM_DISK", 8))
44 return 0;
45
46 int sides = (h[11] << 24) | (h[10] << 16) | (h[ 9] << 8) | h[ 8];
47 int tracks = (h[15] << 24) | (h[14] << 16) | (h[13] << 8) | h[12];
48 int geom = (h[19] << 24) | (h[18] << 16) | (h[17] << 8) | h[16];
49
50 int size = io_generic_size(io);
51 if(sides < 0 || sides > 2 || geom != 1 || size != 256+6400*sides*tracks)
52 return 0;
53
54 return 100;
55 }
56
load(io_generic * io,uint32_t form_factor,floppy_image * image)57 bool oric_dsk_format::load(io_generic *io, uint32_t form_factor, floppy_image *image)
58 {
59 uint8_t h[256];
60 uint8_t t[6250+3];
61
62 t[6250] = t[6251] = t[6252] = 0;
63 io_generic_read(io, h, 0, 256);
64
65 int sides = (h[11] << 24) | (h[10] << 16) | (h[ 9] << 8) | h[ 8];
66 int tracks = (h[15] << 24) | (h[14] << 16) | (h[13] << 8) | h[12];
67
68 for(int side=0; side<sides; side++)
69 for(int track=0; track<tracks; track++) {
70 io_generic_read(io, t, 256+6400*(tracks*side + track), 6250);
71 std::vector<uint32_t> stream;
72 int sector_size = 128;
73 for(int i=0; i<6250; i++) {
74 if(t[i] == 0xc2 && t[i+1] == 0xc2 && t[i+2] == 0xc2) {
75 raw_w(stream, 16, 0x5224);
76 raw_w(stream, 16, 0x5224);
77 raw_w(stream, 16, 0x5224);
78 i += 2;
79 continue;
80 }
81 if(t[i] == 0xa1 && t[i+1] == 0xa1 && t[i+2] == 0xa1) {
82 raw_w(stream, 16, 0x4489);
83 raw_w(stream, 16, 0x4489);
84 raw_w(stream, 16, 0x4489);
85 int copy;
86 if(t[i+3] == 0xfe) {
87 copy = 7;
88 sector_size = 128 << (t[i+7] & 3);
89 } else if(t[i+3] == 0xfb)
90 copy = sector_size+3;
91 else
92 copy = 0;
93 for(int j=0; j<copy; j++)
94 mfm_w(stream, 8, t[i+3+j]);
95 i += 2+copy;
96 continue;
97 }
98 mfm_w(stream, 8, t[i]);
99 }
100 generate_track_from_levels(track, side, stream, 0, image);
101 }
102
103 return true;
104 }
105
save(io_generic * io,floppy_image * image)106 bool oric_dsk_format::save(io_generic *io, floppy_image *image)
107 {
108 return true;
109 }
110
111 const floppy_format_type FLOPPY_ORIC_DSK_FORMAT = &floppy_image_format_creator<oric_dsk_format>;
112