// license:BSD-3-Clause // copyright-holders:Olivier Galibert #include #include "mfi_dsk.h" #include /* Mess floppy image structure: - header with signature, number of cylinders, number of heads. Min track and min head are considered to always be 0. The two top bits of the cylinder count is the resolution: 0=tracks, 1=half tracks, 2=quarter tracks. - vector of track descriptions, looping on cylinders with the given resolution and sub-lopping on heads, each description composed of: - offset of the track data in bytes from the start of the file - size of the compressed track data in bytes (0 for unformatted) - size of the uncompressed track data in bytes (0 for unformatted) - track data All values are 32-bits lsb first. Track data is zlib-compressed independently for each track using the simple "compress" function. Track data consists of a series of 32-bits lsb-first values representing magnetic cells. Bits 0-27 indicate the sizes, and bits 28-31 the types. Type can be: - 0, MG_A -> Magnetic orientation A - 1, MG_B -> Magnetic orientation B - 2, MG_N -> Non-magnetized zone (neutral) - 3, MG_D -> Damaged zone, reads as neutral but cannot be changed by writing Remember that the fdcs detect transitions, not absolute levels, so the actual physical significance of the orientation A and B is arbitrary. Tracks data is aligned so that the index pulse is at the start, whether the disk is hard-sectored or not. The size is the angular size in units of 1/200,000,000th of a turn. Such a size, not coincidentally at all, is also the flyover time in nanoseconds for a perfectly stable 300rpm drive. That makes the standard cell size of a MFM 3.5" DD floppy at 2000 exactly for instance (2us). Smallest expected cell size is 500 (ED density drives). The sum of all sizes must of course be 200,000,000. An unformatted track is equivalent to one big MG_N cell covering a whole turn, but is encoded as zero-size. The "track splice" information indicates where to start writing if you try to rewrite a physical disk with the data. Some preservation formats encode that information, it is guessed for others. The write track function of fdcs should set it. The representation is the angular position relative to the index. The media type is divided in two parts. The first half indicate the physical form factor, i.e. all medias with that form factor can be physically inserted in a reader that handles it. The second half indicates the variants which are usually detectable by the reader, such as density and number of sides. TODO: big-endian support */ const char mfi_format::sign[16] = "MESSFLOPPYIMAGE"; // Includes the final \0 mfi_format::mfi_format() : floppy_image_format_t() { } const char *mfi_format::name() const { return "mfi"; } const char *mfi_format::description() const { return "MESS floppy image"; } const char *mfi_format::extensions() const { return "mfi"; } bool mfi_format::supports_save() const { return true; } int mfi_format::identify(io_generic *io, uint32_t form_factor) { header h; io_generic_read(io, &h, 0, sizeof(header)); if(memcmp( h.sign, sign, 16 ) == 0 && (h.cyl_count & CYLINDER_MASK) <= 84 && (h.cyl_count >> RESOLUTION_SHIFT) < 3 && h.head_count <= 2 && (!form_factor || !h.form_factor || h.form_factor == form_factor)) return 100; return 0; } bool mfi_format::load(io_generic *io, uint32_t form_factor, floppy_image *image) { header h; entry entries[84*2*4]; io_generic_read(io, &h, 0, sizeof(header)); int resolution = h.cyl_count >> RESOLUTION_SHIFT; h.cyl_count &= CYLINDER_MASK; io_generic_read(io, &entries, sizeof(header), (h.cyl_count << resolution)*h.head_count*sizeof(entry)); image->set_variant(h.variant); std::vector compressed; entry *ent = entries; for(unsigned int cyl=0; cyl <= (h.cyl_count - 1) << 2; cyl += 4 >> resolution) for(unsigned int head=0; head != h.head_count; head++) { image->set_write_splice_position(cyl >> 2, head, ent->write_splice, cyl & 3); if(ent->uncompressed_size == 0) { // Unformatted track image->get_buffer(cyl >> 2, head, cyl & 3).clear(); ent++; continue; } compressed.resize(ent->compressed_size); io_generic_read(io, &compressed[0], ent->offset, ent->compressed_size); unsigned int cell_count = ent->uncompressed_size/4; std::vector &trackbuf = image->get_buffer(cyl >> 2, head, cyl & 3);; trackbuf.resize(cell_count); uLongf size = ent->uncompressed_size; if(uncompress((Bytef *)&trackbuf[0], &size, &compressed[0], ent->compressed_size) != Z_OK) return false; uint32_t cur_time = 0; for(unsigned int i=0; i != cell_count; i++) { uint32_t next_cur_time = cur_time + (trackbuf[i] & TIME_MASK); trackbuf[i] = (trackbuf[i] & MG_MASK) | cur_time; cur_time = next_cur_time; } if(cur_time != 200000000) return false; ent++; } return true; } bool mfi_format::save(io_generic *io, floppy_image *image) { int tracks, heads; image->get_actual_geometry(tracks, heads); int resolution = image->get_resolution(); int max_track_size = 0; for(int track=0; track <= (tracks-1) << 2; track += 4 >> resolution) for(int head=0; headget_buffer(track >> 2, head, track & 3).size(); if(tsize > max_track_size) max_track_size = tsize; } header h; entry entries[84*2*4]; memcpy(h.sign, sign, 16); h.cyl_count = tracks | (resolution << RESOLUTION_SHIFT); h.head_count = heads; h.form_factor = image->get_form_factor(); h.variant = image->get_variant(); io_generic_write(io, &h, 0, sizeof(header)); memset(entries, 0, sizeof(entries)); int pos = sizeof(header) + (tracks << resolution)*heads*sizeof(entry); int epos = 0; auto precomp = global_alloc_array(uint32_t, max_track_size); auto postcomp = global_alloc_array(uint8_t, max_track_size*4 + 1000); for(int track=0; track <= (tracks-1) << 2; track += 4 >> resolution) for(int head=0; head &buffer = image->get_buffer(track >> 2, head, track & 3); int tsize = buffer.size(); if(!tsize) { epos++; continue; } memcpy(precomp, &buffer[0], tsize*4); for(int j=0; jget_write_splice_position(track >> 2, head, track & 3); epos++; io_generic_write(io, postcomp, pos, csize); pos += csize; } io_generic_write(io, entries, sizeof(header), (tracks << resolution)*heads*sizeof(entry)); global_free_array(precomp); global_free_array(postcomp); return true; } const floppy_format_type FLOPPY_MFI_FORMAT = &floppy_image_format_creator; ='insertions'>+149 2024-03-22-mr/nl_dribling.cpp: Added note about error in schematic. Vas Crabb2-1/+2 2024-03-21freedom200: Support reverse video Dirk Best4-113/+120 2024-03-21mr/dribling.cpp: Added netlist sound simulation for Model Racing Dribbling. (... Paperinik5-1302/+3519 2024-03-20machine/mediagx_host: prepare for MediaGX virtual VGA hookup angelosa7-29/+147 2024-03-20New systems marked not working Ivan Vangelista2-2/+213 2024-03-21emu/debug/debugcmd.cpp: Add NUL-terminated string argument support to printf/... Patrick Mackinlay3-43/+98 2024-03-20New working clones hap2-3/+13 2024-03-20source org: move yeno drivers to yeno folder hap3-6/+6 2024-03-20misc chess: small tweak to leds hap37-57/+839 2024-03-20drawogl: increase texture hashtable size (emirage/robotadv were crashing with... hap1-2/+2 2024-03-20igs/pgm2.cpp: Add the program ROM of "Bu Bu Car" (#12132) ClawGrip2-6/+38 2024-03-20process all new ROM dumps sent by Team Europe and Sean Riddle [David Haywood]... mamehaze7-20/+179 2024-03-20Added e-kara, Hi-kara and Karaoke Ranking Party cartridges. Vas Crabb6-25/+203 2024-03-20Updated some comments. Vas Crabb5-22/+26 2024-03-20heathkit/h89.cpp: Added missing conditions to some Ultimeth MTRHEX-2k DIP swi... Mark Garlanger1-43/+43 2024-03-19misc swx00 fixes Olivier Galibert5-5/+17 2024-03-20cirsa/neptunp2.cpp: Added Charleston electromechanical slot machine from Euro... ClawGrip2-13/+36 2024-03-19mks3: Fix copy/paste error that prevented saving mappings Olivier Galibert1-61/+61 2024-03-19mks3: Fix keyoff Olivier Galibert2-134/+78 2024-03-19fidel_phantom: update internal artwork color theme hap5-336/+341 2024-03-19visual50: Main screen turn on Dirk Best3-21/+447 2024-03-19New systems marked not working Ivan Vangelista7-22/+133 2024-03-19Add a skeleton for a new PC-based game named 'Pull The Trigger' (#12153) ClawGrip2-0/+97 2024-03-19emu/debug/debugcmd.cpp: Added support for lowercase hex to printf/logerror. [... Vas Crabb5-73/+54 2024-03-19h8_timer: compare match event was off by 1 hap4-61/+64 2024-03-18mks3: first hle Olivier Galibert5-4/+327 2024-03-18dirom fix Olivier Galibert1-3/+0 2024-03-18sh7042: Start introducing the interrupts Olivier Galibert4-4/+52 2024-03-18swx00: Advance Olivier Galibert11-183/+708 2024-03-18Start adding the m37640 Olivier Galibert3-0/+72 2024-03-19cpu/hcd62121, casio/cfx9850.cpp: Various fixes: (#12137) qufb5-108/+445 2024-03-18h8: don't save the mode settings, move mac_saturating var to h8s2600 and hook... hap7-9/+31 2024-03-18New systems marked not working Ivan Vangelista3-45/+554 2024-03-19nmk/nmk16.cpp: Use emulated NMK214/NMK215 protection for more games. (#12152) Sergio G2-73/+131 2024-03-19sony/psx.cpp: Added compatibility filters for CD software list. Vas Crabb1-2/+11 2024-03-19Use literal romaji for Jikkyou Powerful Pro Yakyuu game titles. (#12074) Vas Crabb6-591/+617 2024-03-19sms.xml: Added 19 working items (#12121) ArcadeShadow1-10/+266 2024-03-19igs/goldstar.cpp: Added a fourth version of Animal House set, and PLDs dumps ... ClawGrip2-11/+42