summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats
diff options
context:
space:
mode:
author arbee <rb6502@users.noreply.github.com>2022-09-24 20:48:35 -0400
committer arbee <rb6502@users.noreply.github.com>2022-09-24 20:48:35 -0400
commitdc57db5cebf8418f5932112dcd254b3d565b3023 (patch)
treeb41645c053f2be7a7593d7c29919bead2879a2e4 /src/lib/formats
parenta9cdc7d7c213512d434c4afb4a46417da6437063 (diff)
apple: remove legacy floppy format handlers. [R. Belmont]
Diffstat (limited to 'src/lib/formats')
-rw-r--r--src/lib/formats/ap2_dsk.cpp497
-rw-r--r--src/lib/formats/ap2_dsk.h20
-rw-r--r--src/lib/formats/ap_dsk35.cpp1108
-rw-r--r--src/lib/formats/ap_dsk35.h11
4 files changed, 8 insertions, 1628 deletions
diff --git a/src/lib/formats/ap2_dsk.cpp b/src/lib/formats/ap2_dsk.cpp
index bb29cd1702b..6cb22219b93 100644
--- a/src/lib/formats/ap2_dsk.cpp
+++ b/src/lib/formats/ap2_dsk.cpp
@@ -2,7 +2,7 @@
// copyright-holders:Olivier Galibert, R. Belmont
/*********************************************************************
- ap2_dsk.c
+ ap2_dsk.cpp
Apple II disk images
@@ -17,31 +17,6 @@
#include <cstdlib>
#include <cstring>
-
-#define APPLE2_IMAGE_DO 0
-#define APPLE2_IMAGE_PO 1
-#define APPLE2_IMAGE_NIB 2
-
-
-/* used in for all Apple II images */
-static uint32_t apple2_get_track_size(floppy_image_legacy *floppy, int head, int track);
-static int disk_decode_nib(uint8_t *data, const uint8_t *nibble, int *volume, int *track, int *sector);
-static void disk_encode_nib(uint8_t *nibble, const uint8_t *data, int volume, int track, int sector);
-
-/* used in DOS/ProDOS order images */
-static int apple2_do_translate_sector(floppy_image_legacy *floppy, int sector);
-static int apple2_po_translate_sector(floppy_image_legacy *floppy, int sector);
-static floperr_t apple2_dsk_read_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen);
-static floperr_t apple2_dsk_write_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen);
-
-/* used in nibble order images */
-static floperr_t apple2_nib_read_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen);
-static floperr_t apple2_nib_write_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen);
-static floperr_t apple2_nib_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen);
-static floperr_t apple2_nib_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam);
-static floperr_t apple2_nib_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length);
-
-
static const uint8_t translate6[0x40] =
{
0x96, 0x97, 0x9a, 0x9b, 0x9d, 0x9e, 0x9f, 0xa6,
@@ -54,476 +29,6 @@ static const uint8_t translate6[0x40] =
0xf7, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
};
-
-
-/* -----------------------------------------------------------------------
- * Utility code
- * ----------------------------------------------------------------------- */
-
-static const uint8_t *get_untranslate6_map(void)
-{
- static uint8_t map[256];
- static int map_inited = 0;
- uint8_t i;
-
- if (!map_inited)
- {
- memset(map, 0xff, sizeof(map));
- for (i = 0; i < std::size(translate6); i++)
- map[translate6[i]] = i;
- map_inited = 1;
- }
- return map;
-}
-
-
-
-/* -----------------------------------------------------------------------
- * Core constructor
- * ----------------------------------------------------------------------- */
-
-
-static floperr_t apple2_general_construct(floppy_image_legacy *floppy, int floppy_type)
-{
- floperr_t err;
- struct basicdsk_geometry geometry;
- struct FloppyCallbacks *format;
-
- format = floppy_callbacks(floppy);
-
- switch(floppy_type) {
- case APPLE2_IMAGE_DO:
- case APPLE2_IMAGE_PO:
- memset(&geometry, 0, sizeof(geometry));
- geometry.heads = 1;
- geometry.tracks = APPLE2_TRACK_COUNT;
- geometry.sectors = APPLE2_SECTOR_COUNT;
- geometry.sector_length = APPLE2_SECTOR_SIZE;
- geometry.translate_sector = (floppy_type == APPLE2_IMAGE_DO) ? apple2_do_translate_sector : apple2_po_translate_sector;
-
- err = basicdsk_construct(floppy, &geometry);
- if (err)
- return err;
-
- format->read_track = apple2_dsk_read_track;
- format->write_track = apple2_dsk_write_track;
- break;
-
- case APPLE2_IMAGE_NIB:
- format->read_track = apple2_nib_read_track;
- format->write_track = apple2_nib_write_track;
- format->read_sector = apple2_nib_read_sector;
- format->write_sector = apple2_nib_write_sector;
- format->get_sector_length = apple2_nib_get_sector_length;
- break;
-
- default:
- assert(0);
- return FLOPPY_ERROR_INTERNAL;
- }
-
- format->get_track_size = apple2_get_track_size;
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-/* -----------------------------------------------------------------------
- * DOS order and ProDOS order code
- * ----------------------------------------------------------------------- */
-
-static FLOPPY_IDENTIFY(apple2_dsk_identify)
-{
- uint64_t size;
- uint64_t expected_size;
-
- size = floppy_image_size(floppy);
- expected_size = APPLE2_TRACK_COUNT * APPLE2_SECTOR_COUNT * APPLE2_SECTOR_SIZE;
-
- if ((size == expected_size) || (size == APPLE2_STD_TRACK_COUNT * APPLE2_SECTOR_COUNT * APPLE2_SECTOR_SIZE))
- *vote = 100;
- else if ((size > expected_size) && ((size - expected_size) < 8))
- *vote = 90; /* tolerate images with up to eight fewer/extra bytes (bug #638) */
- else if ((size < expected_size) && ((expected_size - size) < 8))
- *vote = 90; /* tolerate images with up to eight fewer/extra bytes (bug #638) */
- else
- *vote = 0;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static int apple2_do_translate_sector(floppy_image_legacy *floppy, int sector)
-{
- static const uint8_t skewing[] =
- {
- /* DOS order (*.do) */
- 0x00, 0x07, 0x0E, 0x06, 0x0D, 0x05, 0x0C, 0x04,
- 0x0B, 0x03, 0x0A, 0x02, 0x09, 0x01, 0x08, 0x0F
- };
- return skewing[sector];
-}
-
-
-
-static int apple2_po_translate_sector(floppy_image_legacy *floppy, int sector)
-{
- static const uint8_t skewing[] =
- {
- /* ProDOS order (*.po) */
- 0x00, 0x08, 0x01, 0x09, 0x02, 0x0A, 0x03, 0x0B,
- 0x04, 0x0C, 0x05, 0x0D, 0x06, 0x0E, 0x07, 0x0F
- };
- return skewing[sector];
-}
-
-
-
-static FLOPPY_CONSTRUCT(apple2_do_construct)
-{
- return apple2_general_construct(floppy, APPLE2_IMAGE_DO);
-}
-
-
-
-static FLOPPY_CONSTRUCT(apple2_po_construct)
-{
- return apple2_general_construct(floppy, APPLE2_IMAGE_PO);
-}
-
-
-
-static floperr_t apple2_dsk_read_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen)
-{
- uint8_t sector_buffer[APPLE2_SECTOR_SIZE];
- int sector;
- uint8_t *nibble;
-
- if (buflen < APPLE2_NIBBLE_SIZE*APPLE2_SECTOR_COUNT)
- return FLOPPY_ERROR_INTERNAL;
- if (offset != 0)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- memset(buffer, 0, buflen);
-
- for (sector = 0; sector < APPLE2_SECTOR_COUNT; sector++)
- {
- nibble = (uint8_t *)buffer;
- nibble += sector * APPLE2_SMALL_NIBBLE_SIZE;
-
- floppy_read_sector(floppy, head, track, sector, 0, sector_buffer, sizeof(sector_buffer));
- disk_encode_nib(nibble, sector_buffer, 254, track, sector);
- }
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple2_dsk_write_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen)
-{
- int sector;
- uint8_t sector_buffer[APPLE2_SECTOR_SIZE];
- const uint8_t *nibble;
-
- if (offset != 0)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- for (sector = 0; sector < APPLE2_SECTOR_COUNT; sector++)
- {
- nibble = (uint8_t *)buffer;
- nibble += sector * APPLE2_SMALL_NIBBLE_SIZE;
-
- disk_decode_nib(sector_buffer, nibble, nullptr, nullptr, nullptr);
- floppy_write_sector(floppy, head, track, sector, 0, sector_buffer, sizeof(sector_buffer), 0);
- }
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-/* -----------------------------------------------------------------------
- * Nibble order code
- * ----------------------------------------------------------------------- */
-
-static FLOPPY_IDENTIFY(apple2_nib_identify)
-{
- uint64_t size;
- size = floppy_image_size(floppy);
- *vote = ((size == APPLE2_STD_TRACK_COUNT * APPLE2_SECTOR_COUNT * APPLE2_NIBBLE_SIZE) || (size == (APPLE2_STD_TRACK_COUNT + 1) * APPLE2_SECTOR_COUNT * APPLE2_NIBBLE_SIZE)) ? 100 : 0;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static FLOPPY_CONSTRUCT(apple2_nib_construct)
-{
- return apple2_general_construct(floppy, APPLE2_IMAGE_NIB);
-}
-
-
-
-static floperr_t apple2_nib_read_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen)
-{
- if ((head != 0) || (track < 0) || (track > APPLE2_TRACK_COUNT))
- return FLOPPY_ERROR_SEEKERROR;
- if (offset != 0)
- return FLOPPY_ERROR_UNSUPPORTED;
- floppy_image_read(floppy, buffer, track * APPLE2_NIBBLE_SIZE * APPLE2_SECTOR_COUNT, buflen);
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple2_nib_write_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen)
-{
- if ((head != 0) || (track < 0) || (track > APPLE2_TRACK_COUNT))
- return FLOPPY_ERROR_SEEKERROR;
- if (offset != 0)
- return FLOPPY_ERROR_UNSUPPORTED;
- floppy_image_write(floppy, buffer, track * APPLE2_NIBBLE_SIZE * APPLE2_SECTOR_COUNT, buflen);
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-/* -----------------------------------------------------------------------
- * Track conversion
- * ----------------------------------------------------------------------- */
-
-static int decode_nibbyte(uint8_t *nibint, const uint8_t *nibdata)
-{
- if ((nibdata[0] & 0xAA) != 0xAA)
- return 1;
- if ((nibdata[1] & 0xAA) != 0xAA)
- return 1;
-
- *nibint = (nibdata[0] & ~0xAA) << 1;
- *nibint |= (nibdata[1] & ~0xAA) << 0;
- return 0;
-}
-
-
-
-static int disk_decode_nib(uint8_t *data, const uint8_t *nibble, int *volume, int *track, int *sector)
-{
- uint8_t read_volume;
- uint8_t read_track;
- uint8_t read_sector;
- uint8_t read_checksum;
- int i;
- uint8_t b, xorvalue, newvalue;
-
- const uint8_t *untranslate6 = get_untranslate6_map();
-
- /* pick apart the volume/track/sector info and checksum */
- if (decode_nibbyte(&read_volume, &nibble[10]))
- return 1;
- if (decode_nibbyte(&read_track, &nibble[12]))
- return 1;
- if (decode_nibbyte(&read_sector, &nibble[14]))
- return 1;
- if (decode_nibbyte(&read_checksum, &nibble[16]))
- return 1;
- if (read_checksum != (read_volume ^ read_track ^ read_sector))
- return 1;
-
- /* decode the nibble core */
- xorvalue = 0;
- for (i = 0; i < 342; i++)
- {
- b = untranslate6[nibble[i+28]];
- if (b == 0xff)
- return 1;
- newvalue = b ^ xorvalue;
-
- if (i >= 0x56)
- {
- /* 6 bit */
- data[i - 0x56] |= (newvalue << 2);
- }
- else
- {
- /* 3 * 2 bit */
- data[i + 0x00] = ((newvalue >> 1) & 0x01) | ((newvalue << 1) & 0x02);
- data[i + 0x56] = ((newvalue >> 3) & 0x01) | ((newvalue >> 1) & 0x02);
- if (i + 0xAC < APPLE2_SECTOR_SIZE)
- data[i + 0xAC] = ((newvalue >> 5) & 0x01) | ((newvalue >> 3) & 0x02);
- }
- xorvalue = newvalue;
- }
-
- /* success; write out values if pointers not null */
- if (volume)
- *volume = read_volume;
- if (track)
- *track = read_track;
- if (sector)
- *sector = read_sector;
- return 0;
-}
-
-
-
-static floperr_t apple2_nib_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen)
-{
- floperr_t err;
- const uint8_t *nibble;
- uint8_t *track_data;
- void *track_data_v;
-
- if ((sector < 0) || (sector >= APPLE2_SECTOR_COUNT))
- return FLOPPY_ERROR_SEEKERROR;
- if (buflen != APPLE2_SECTOR_SIZE)
- return FLOPPY_ERROR_INTERNAL;
-
- err = floppy_load_track(floppy, head, track, false, &track_data_v, nullptr);
- if (err)
- return err;
- track_data = (uint8_t *) track_data_v;
-
- nibble = track_data + (sector * APPLE2_NIBBLE_SIZE);
-
- if (disk_decode_nib((uint8_t *)buffer, nibble, nullptr, nullptr, nullptr))
- return FLOPPY_ERROR_INVALIDIMAGE;
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static void disk_encode_nib(uint8_t *nibble, const uint8_t *data, int volume, int track, int sector)
-{
- int checksum, oldvalue, xorvalue, i;
-
- /* setup header values */
- checksum = volume ^ track ^ sector;
-
- memset(nibble, 0xFF, APPLE2_NIBBLE_SIZE);
- nibble[ 7] = 0xD5;
- nibble[ 8] = 0xAA;
- nibble[ 9] = 0x96;
- nibble[10] = (volume >> 1) | 0xAA;
- nibble[11] = volume | 0xAA;
- nibble[12] = (track >> 1) | 0xAA;
- nibble[13] = track | 0xAA;
- nibble[14] = (sector >> 1) | 0xAA;
- nibble[15] = sector | 0xAA;
- nibble[16] = (checksum >> 1) | 0xAA;
- nibble[17] = (checksum) | 0xAA;
- nibble[18] = 0xDE;
- nibble[19] = 0xAA;
- nibble[20] = 0xEB;
- nibble[25] = 0xD5;
- nibble[26] = 0xAA;
- nibble[27] = 0xAD;
- nibble[27+344] = 0xDE;
- nibble[27+345] = 0xAA;
- nibble[27+346] = 0xEB;
- xorvalue = 0;
-
- for (i = 0; i < 342; i++)
- {
- if (i >= 0x56)
- {
- /* 6 bit */
- oldvalue = data[i - 0x56];
- oldvalue = oldvalue >> 2;
- }
- else
- {
- /* 3 * 2 bit */
- oldvalue = 0;
- oldvalue |= (data[i + 0x00] & 0x01) << 1;
- oldvalue |= (data[i + 0x00] & 0x02) >> 1;
- oldvalue |= (data[i + 0x56] & 0x01) << 3;
- oldvalue |= (data[i + 0x56] & 0x02) << 1;
- if (i + 0xAC < APPLE2_SECTOR_SIZE)
- {
- oldvalue |= (data[i + 0xAC] & 0x01) << 5;
- oldvalue |= (data[i + 0xAC] & 0x02) << 3;
- }
-
- }
- xorvalue ^= oldvalue;
- nibble[28+i] = translate6[xorvalue & 0x3F];
- xorvalue = oldvalue;
- }
-
- nibble[27+343] = translate6[xorvalue & 0x3F];
-}
-
-
-
-static floperr_t apple2_nib_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
-{
- floperr_t err;
- uint8_t *track_data;
- void *track_data_v;
-
- if ((sector < 0) || (sector >= APPLE2_SECTOR_COUNT))
- return FLOPPY_ERROR_SEEKERROR;
- if (buflen != APPLE2_SECTOR_SIZE)
- return FLOPPY_ERROR_INTERNAL;
-
- err = floppy_load_track(floppy, head, track, true, &track_data_v, nullptr);
- if (err)
- return err;
- track_data = (uint8_t *) track_data_v;
-
- disk_encode_nib(track_data + sector * APPLE2_NIBBLE_SIZE, (const uint8_t *)buffer, 254, track, sector);
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple2_nib_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length)
-{
- *sector_length = APPLE2_SECTOR_SIZE;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static uint32_t apple2_get_track_size(floppy_image_legacy *floppy, int head, int track)
-{
- return APPLE2_NIBBLE_SIZE * APPLE2_SECTOR_COUNT;
-}
-
-
-
-/* ----------------------------------------------------------------------- */
-
-LEGACY_FLOPPY_OPTIONS_START( apple2 )
- LEGACY_FLOPPY_OPTION( apple2_do, "do,dsk,bin", "Apple ][ DOS order disk image", apple2_dsk_identify, apple2_do_construct, nullptr,
- HEADS([1])
- TRACKS([40]) // APPLE2_TRACK_COUNT
- SECTORS([16])
- SECTOR_LENGTH([256])
- FIRST_SECTOR_ID([0]))
- LEGACY_FLOPPY_OPTION( apple2_po, "po,dsk,bin", "Apple ][ ProDOS order disk image", apple2_dsk_identify, apple2_po_construct, nullptr,
- HEADS([1])
- TRACKS([40]) // APPLE2_TRACK_COUNT
- SECTORS([16])
- SECTOR_LENGTH([256])
- FIRST_SECTOR_ID([0]))
- LEGACY_FLOPPY_OPTION( apple2_nib, "dsk,nib", "Apple ][ Nibble order disk image", apple2_nib_identify, apple2_nib_construct, nullptr,
- HEADS([1])
- TRACKS([40]) // APPLE2_TRACK_COUNT
- SECTORS([16])
- SECTOR_LENGTH([256])
- FIRST_SECTOR_ID([0]))
-LEGACY_FLOPPY_OPTIONS_END
-
-// license:BSD-3-Clause
-// copyright-holders:Olivier Galibert
-/***************************************************************************
-
- New implementation
-
-****************************************************************************/
-
static const uint8_t dos_skewing[] =
{
0x00, 0x07, 0x0E, 0x06, 0x0D, 0x05, 0x0C, 0x04,
diff --git a/src/lib/formats/ap2_dsk.h b/src/lib/formats/ap2_dsk.h
index 4d8d5519952..c5503133295 100644
--- a/src/lib/formats/ap2_dsk.h
+++ b/src/lib/formats/ap2_dsk.h
@@ -13,7 +13,6 @@
#pragma once
#include "flopimg.h"
-#include "flopimg_legacy.h"
/***************************************************************************
@@ -22,21 +21,14 @@
***************************************************************************/
-#define APPLE2_NIBBLE_SIZE 416
-#define APPLE2_SMALL_NIBBLE_SIZE 374
-#define APPLE2_STD_TRACK_COUNT 35
-#define APPLE2_TRACK_COUNT 40
-#define APPLE2_SECTOR_COUNT 16
-#define APPLE2_SECTOR_SIZE 256
-
-
+#define APPLE2_NIBBLE_SIZE 416
+#define APPLE2_SMALL_NIBBLE_SIZE 374
+#define APPLE2_STD_TRACK_COUNT 35
+#define APPLE2_TRACK_COUNT 40
+#define APPLE2_SECTOR_COUNT 16
+#define APPLE2_SECTOR_SIZE 256
/**************************************************************************/
-
-LEGACY_FLOPPY_OPTIONS_EXTERN(apple2);
-
-// new style code
-
class a2_16sect_format : public floppy_image_format_t
{
public:
diff --git a/src/lib/formats/ap_dsk35.cpp b/src/lib/formats/ap_dsk35.cpp
index 984ba6ce046..d481fdbb61a 100644
--- a/src/lib/formats/ap_dsk35.cpp
+++ b/src/lib/formats/ap_dsk35.cpp
@@ -1,5 +1,5 @@
// license:BSD-3-Clause
-// copyright-holders:Nathan Woods, R. Belmont
+// copyright-holders:O. Galibert, R. Belmont
/*********************************************************************
ap_dsk35.c
@@ -108,1112 +108,6 @@
#include <cstdio>
#include <cstring>
-
-struct apple35_tag
-{
- uint32_t data_offset;
- uint32_t data_size;
- uint8_t format_byte;
- uint8_t sides;
- unsigned int is_1440k : 1;
-
- /* stuff used in DiskCopy images */
- uint32_t tag_offset;
- uint32_t tag_size;
-};
-
-
-
-/* normal number of sector for each track */
-static const uint8_t apple35_tracklen_800kb[80] =
-{
- 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
- 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8
-};
-
-/* blocks of data used to nibblize tracks */
-static const uint8_t diskbytes[] =
-{
- 0x96, 0x97, 0x9A, 0x9B, 0x9D, 0x9E, 0x9F, 0xA6, /* 0x00 */
- 0xA7, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB2, 0xB3,
- 0xB4, 0xB5, 0xB6, 0xB7, 0xB9, 0xBA, 0xBB, 0xBC, /* 0x10 */
- 0xBD, 0xBE, 0xBF, 0xCB, 0xCD, 0xCE, 0xCF, 0xD3,
- 0xD6, 0xD7, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, /* 0x20 */
- 0xDF, 0xE5, 0xE6, 0xE7, 0xE9, 0xEA, 0xEB, 0xEC,
- 0xED, 0xEE, 0xEF, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, /* 0x30 */
- 0xF7, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
-};
-
-/* reverse lookup of diskbytes */
-static const int16_t rev_diskbytes[] =
-{
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x00 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x10 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x20 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x30 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x40 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x50 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x60 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x70 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0x80 */
- -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, 0x00, 0x01, /* 0x90 */
- -1, -1, 0x02, 0x03, -1, 0x04, 0x05, 0x06,
- -1, -1, -1, -1, -1, -1, 0x07, 0x08, /* 0xA0 */
- -1, -1, -1, 0x09, 0x0A, 0x0B, 0x0C, 0x0D,
- -1, -1, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, /* 0xB0 */
- -1, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A,
- -1, -1, -1, -1, -1, -1, -1, -1, /* 0xC0 */
- -1, -1, -1, 0x1B, -1, 0x1C, 0x1D, 0x1E,
- -1, -1, -1, 0x1F, -1, -1, 0x20, 0x21, /* 0xD0 */
- -1, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
- -1, -1, -1, -1, -1, 0x29, 0x2A, 0x2B, /* 0xE0 */
- -1, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32,
- -1, -1, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, /* 0xF0 */
- -1, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
-};
-
-static const uint8_t blk1[] =
-{
- /*0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
- 0xFF, 0xFF, 0xD5, 0xAA, 0x96*/
- 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF,
- 0xD5, 0xAA, 0x96
-};
-static const uint8_t blk2[] =
-{
- 0xDE, 0xAA, 0xFF, 0xFF, 0x3F, 0xCF, 0xF3, 0xFC, 0xFF, 0xD5, 0xAA, 0xAD
-};
-static const uint8_t blk3[] =
-{
- 0xDE, 0xAA, 0xFF
-};
-
-
-
-static struct apple35_tag *get_apple35_tag(floppy_image_legacy *floppy)
-{
- struct apple35_tag *tag;
- tag = (struct apple35_tag *) floppy_tag(floppy);
- return tag;
-}
-
-
-
-int apple35_sectors_per_track(floppy_image_legacy *image, int track)
-{
- int sectors;
-
- assert(track >= 0);
- assert(track < std::size(apple35_tracklen_800kb));
-
- if (get_apple35_tag(image)->is_1440k)
- sectors = 18;
- else
- sectors = apple35_tracklen_800kb[track];
- return sectors;
-}
-
-
-
-/*
- converts data to its nibblized representation, and generate checksum
-
- now handles 524-byte-long sectors
-
- tag data IS important, since it allows data recovery when the catalog is trashed
-*/
-static void sony_nibblize35(const uint8_t *in, uint8_t *nib_ptr, uint8_t *csum)
-{
- int i, j;
- uint32_t c1, c2, c3, c4;
- uint8_t val;
- uint8_t w1, w2, w3, w4;
- uint8_t b1[175], b2[175], b3[175];
-
- /* Copy from the user's buffer to our buffer, while computing
- * the three-byte data checksum
- */
-
- i = 0;
- j = 0;
- c1 = 0;
- c2 = 0;
- c3 = 0;
- while (1)
- {
- c1 = (c1 & 0xFF) << 1;
- if (c1 & 0x0100)
- c1++;
-
- val = in[i++];
- c3 += val;
- if (c1 & 0x0100)
- {
- c3++;
- c1 &= 0xFF;
- }
- b1[j] = (val ^ c1) & 0xFF;
-
- val = in[i++];
- c2 += val;
- if (c3 > 0xFF)
- {
- c2++;
- c3 &= 0xFF;
- }
- b2[j] = (val ^ c3) & 0xFF;
-
- if (i == 524) break;
-
- val = in[i++];
- c1 += val;
- if (c2 > 0xFF)
- {
- c1++;
- c2 &= 0xFF;
- }
- b3[j] = (val ^ c2) & 0xFF;
- j++;
- }
- c4 = ((c1 & 0xC0) >> 6) | ((c2 & 0xC0) >> 4) | ((c3 & 0xC0) >> 2);
- b3[174] = 0;
-
- j = 0;
- for (i = 0; i <= 174; i++)
- {
- w1 = b1[i] & 0x3F;
- w2 = b2[i] & 0x3F;
- w3 = b3[i] & 0x3F;
- w4 = ((b1[i] & 0xC0) >> 2);
- w4 |= ((b2[i] & 0xC0) >> 4);
- w4 |= ((b3[i] & 0xC0) >> 6);
-
- nib_ptr[j++] = w4;
- nib_ptr[j++] = w1;
- nib_ptr[j++] = w2;
-
- if (i != 174) nib_ptr[j++] = w3;
- }
-
- csum[0] = c1 & 0x3F;
- csum[1] = c2 & 0x3F;
- csum[2] = c3 & 0x3F;
- csum[3] = c4 & 0x3F;
-}
-
-
-
-/*
- does the reverse process of sony_nibblize35
-*/
-static void sony_denibblize35(uint8_t *out, const uint8_t *nib_ptr, uint8_t *checksum)
-{
- int i, j;
- uint32_t c1,c2,c3,c4;
- uint8_t val;
- uint8_t w1,w2,w3=0,w4;
- uint8_t b1[175],b2[175],b3[175];
-
- j = 0;
- for (i=0; i<=174; i++)
- {
- w4 = nib_ptr[j++];
- w1 = nib_ptr[j++];
- w2 = nib_ptr[j++];
-
- if (i != 174) w3 = nib_ptr[j++];
-
- b1[i] = (w1 & 0x3F) | ((w4 << 2) & 0xC0);
- b2[i] = (w2 & 0x3F) | ((w4 << 4) & 0xC0);
- b3[i] = (w3 & 0x3F) | ((w4 << 6) & 0xC0);
- }
-
- /* Copy from the user's buffer to our buffer, while computing
- * the three-byte data checksum
- */
-
- i = 0;
- j = 0;
- c1 = 0;
- c2 = 0;
- c3 = 0;
- while (1)
- {
- c1 = (c1 & 0xFF) << 1;
- if (c1 & 0x0100)
- c1++;
-
- val = (b1[j] ^ c1) & 0xFF;
- c3 += val;
- if (c1 & 0x0100)
- {
- c3++;
- c1 &= 0xFF;
- }
- out[i++] = val;
-
- val = (b2[j] ^ c3) & 0xFF;
- c2 += val;
- if (c3 > 0xFF)
- {
- c2++;
- c3 &= 0xFF;
- }
- out[i++] = val;
-
- if (i == 524) break;
-
- val = (b3[j] ^ c2) & 0xFF;
- c1 += val;
- if (c2 > 0xFF)
- {
- c1++;
- c2 &= 0xFF;
- }
- out[i++] = val;
- j++;
- }
- c4 = ((c1 & 0xC0) >> 6) | ((c2 & 0xC0) >> 4) | ((c3 & 0xC0) >> 2);
- b3[174] = 0;
-
- checksum[0] = c1 & 0x3F;
- checksum[1] = c2 & 0x3F;
- checksum[2] = c3 & 0x3F;
- checksum[3] = c4 & 0x3F;
-}
-
-
-
-void sony_filltrack(uint8_t *buffer, size_t buffer_len, size_t *pos, uint8_t data)
-{
- buffer[*pos / 8] &= 0xFF << (8 - (*pos % 8));
- buffer[*pos / 8] |= data >> (*pos % 8);
-
- *pos += 8;
- *pos %= buffer_len * 8;
-
- buffer[*pos / 8] &= 0xFF >> (*pos % 8);
- buffer[*pos / 8] |= data << (8 - (*pos % 8));
-}
-
-
-
-uint8_t sony_fetchtrack(const uint8_t *buffer, size_t buffer_len, size_t *pos)
-{
- uint8_t data;
-
- data = buffer[*pos / 8] << (*pos % 8);
- *pos += 8;
- *pos %= (buffer_len * 8);
- data |= buffer[*pos / 8] >> (8 - (*pos % 8));
-
- while ((data & 0x80) == 0)
- {
- /* this code looks weird because it isn't simply rotating the new bit
- * in, but for some reason it won't work if I rotate the bit in; I
- * have to match the algorithm used by the old code */
- data <<= 1;
- data |= (buffer[*pos / 8] >> (8 - ((*pos % 8) + 1)));
- (*pos)++;
- *pos %= (buffer_len * 8);
- }
-
-// printf("sony_fetchtrack: pos %ld = %02x\n", *pos/8, data);
-
- return data;
-}
-
-
-
-static uint32_t apple35_get_offset(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *tag_offset)
-{
- int i;
- uint32_t sector_index = 0;
- struct apple35_tag *tag;
-
- tag = get_apple35_tag(floppy);
-
- if (track >= std::size(apple35_tracklen_800kb))
- return ~0;
- if (head >= tag->sides)
- return ~0;
- if (sector >= apple35_sectors_per_track(floppy, track))
- return ~0;
-
- for (i = 0; i < track; i++)
- sector_index += apple35_sectors_per_track(floppy, i);
- sector_index *= tag->sides;
- if (head)
- sector_index += apple35_sectors_per_track(floppy, i);
- sector_index += sector;
-
- if (tag_offset)
- {
- *tag_offset = sector_index * 12;
- if (*tag_offset >= tag->tag_size)
- {
- *tag_offset = ~0;
- }
- else
- {
- *tag_offset += tag->tag_offset;
- }
- }
- return sector_index * 0x200 + tag->data_offset;
-}
-
-
-
-static floperr_t apple35_read_sector(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen)
-{
- uint32_t data_offset;
- data_offset = apple35_get_offset(floppy, head, track, sector, nullptr);
- if (data_offset == ~0)
- {
- return FLOPPY_ERROR_SEEKERROR;
- }
- floppy_image_read(floppy, buffer, data_offset, buflen);
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple35_write_sector(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
-{
- uint32_t data_offset;
-
- data_offset = apple35_get_offset(floppy, head, track, sector, nullptr);
- if (data_offset == ~0)
- return FLOPPY_ERROR_SEEKERROR;
- floppy_image_write(floppy, buffer, data_offset, buflen);
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple35_read_sector_td(floppy_image_legacy *floppy, int head, int track, int sector, void *buffer, size_t buflen)
-{
- floperr_t err;
- uint32_t tag_offset = 0;
-
- assert(buflen == 524);
-
- /* first read the sector */
- err = apple35_read_sector(floppy, head, track, sector, ((uint8_t *) buffer) + 12, 512);
- if (err)
- {
- return err;
- }
-
- /* read the tag data, if possible */
- memset(buffer, '\0', 12);
- apple35_get_offset(floppy, head, track, sector, &tag_offset);
- if (tag_offset != ~0)
- {
- floppy_image_read(floppy, buffer, tag_offset, 12);
- }
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple35_write_sector_td(floppy_image_legacy *floppy, int head, int track, int sector, const void *buffer, size_t buflen, int ddam)
-{
- floperr_t err;
- uint32_t tag_offset = 0;
-
- assert(buflen == 524);
-
- /* first write the sector */
- err = apple35_write_sector(floppy, head, track, sector, ((const uint8_t *) buffer) + 12, 512, 0);
- if (err)
- return err;
-
- /* write the tag data, if possible */
- apple35_get_offset(floppy, head, track, sector, &tag_offset);
- if (tag_offset != ~0)
- floppy_image_write(floppy, buffer, tag_offset, 12);
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple35_get_sector_length(floppy_image_legacy *floppy, int head, int track, int sector, uint32_t *sector_length)
-{
- *sector_length = 512;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static int apple35_get_heads_per_disk(floppy_image_legacy *floppy)
-{
- return get_apple35_tag(floppy)->sides;
-}
-
-
-
-static int apple35_get_tracks_per_disk(floppy_image_legacy *floppy)
-{
- return 80;
-}
-
-
-
-static uint32_t apple35_get_track_size(floppy_image_legacy *floppy, int head, int track)
-{
- if ((track < 0) || (track >= 80))
- return 0;
- return apple35_sectors_per_track(floppy, track) * 800;
-}
-
-
-
-static uint8_t calculate_side(int head, int track)
-{
- uint8_t side;
- side = head ? 0x20 : 0x00;
- if (track & 0x40)
- side |= 0x01;
- return side;
-}
-
-
-
-static floperr_t apple35_read_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, void *buffer, size_t buflen)
-{
- floperr_t err;
- size_t pos = 0;
- int sector_count, sector, i;
- uint8_t sum, side;
- struct apple35_tag *tag;
- uint8_t sector_data[524];
- uint8_t nibble_data[699];
- uint8_t checksum[4];
-
- tag = get_apple35_tag(floppy);
-
- if (track >= std::size(apple35_tracklen_800kb))
- return FLOPPY_ERROR_SEEKERROR;
- if (offset != 0)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- memset(buffer, 0xFF, buflen);
- sector_count = apple35_sectors_per_track(floppy, track);
- side = calculate_side(head, track);
-
- for (sector = 0; sector < sector_count; sector++)
- {
- /* read the sector */
- err = apple35_read_sector_td(floppy, head, track, sector, sector_data, std::size(sector_data));
- if (err)
- {
- return err;
- }
-
- sony_nibblize35(sector_data, nibble_data, checksum);
-
- for (i = 0; i < std::size(blk1); i++)
- sony_filltrack((uint8_t*)buffer, buflen, &pos, blk1[i]);
-
- sum = (track ^ sector ^ side ^ tag->format_byte) & 0x3F;
-
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[track & 0x3f]);
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[sector]);
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[side]);
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[tag->format_byte]);
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[sum]);
-
- for (i = 0; i < std::size(blk2); i++)
- sony_filltrack((uint8_t*)buffer, buflen, &pos, blk2[i]);
-
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[sector]);
-
- for (i = 0; i < std::size(nibble_data); i++)
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[nibble_data[i]]);
-
- for (i = 3; i >= 0; i--)
- sony_filltrack((uint8_t*)buffer, buflen, &pos, diskbytes[checksum[i]]);
-
- for (i = 0; i < std::size(blk3); i++)
- sony_filltrack((uint8_t*)buffer, buflen, &pos, blk3[i]);
- }
-
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple35_write_track(floppy_image_legacy *floppy, int head, int track, uint64_t offset, const void *buffer, size_t buflen)
-{
- floperr_t err;
- size_t pos = 0;
- int sector_count, sector, i, j;
- struct apple35_tag *tag;
- uint8_t sum, format_byte, val, side;
- uint32_t found_sectors = 0;
- uint8_t sector_data[524];
- uint8_t nibble_data[699];
- uint8_t checksum[4];
-
- tag = get_apple35_tag(floppy);
-
- if (track >= std::size(apple35_tracklen_800kb))
- return FLOPPY_ERROR_SEEKERROR;
- if (offset != 0)
- return FLOPPY_ERROR_UNSUPPORTED;
-
- sector_count = apple35_sectors_per_track(floppy, track);
- side = calculate_side(head, track);
-
- /* do 2 rotations, in case the bit slip stuff prevent us to read the first sector */
- for (j = 0; j < (buflen * 2); j++)
- {
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0xD5)
- continue;
- j++;
-
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0xAA)
- continue;
- j++;
-
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0x96)
- continue;
- j++;
-
- if (rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)] != (track & 0x3F))
- continue;
- j++;
-
- sector = rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)];
- if ((sector < 0) || (sector >= sector_count))
- continue;
- j++;
-
- if (rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)] != side)
- continue;
- j++;
-
- format_byte = rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)];
- if (format_byte != tag->format_byte)
- {
- /* this is an error, but not THAT critical, I guess */
- }
- j++;
-
- sum = track ^ sector ^ side ^ format_byte;
- if (rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)] != sum)
- continue;
- j++;
-
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0xDE)
- continue;
- j++;
-
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0xAA)
- continue;
- j++;
-
- while((val = sony_fetchtrack((uint8_t*)buffer, buflen, &pos)) == 0xFF)
- j++;
- if (val != 0xD5)
- continue; /* lost bit slip mark! */
- j++;
-
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0xAA)
- continue;
- j++;
-
- if (sony_fetchtrack((uint8_t*)buffer, buflen, &pos) != 0xAD)
- continue;
- j++;
-
- /* should this be regarded as a critical error ??? */
- if (rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)] != sector)
- continue;
- j++;
-
- for (i = 0; i < std::size(nibble_data); i++)
- {
- nibble_data[i] = rev_diskbytes[sony_fetchtrack((uint8_t*)buffer, buflen, &pos)];
- j++;
- }
-
- for (i = 3; i >= 0; i--)
- {
- /* should be checking checksum */
- sony_fetchtrack((uint8_t*)buffer, buflen, &pos);
- }
-
- sony_fetchtrack((uint8_t*)buffer, buflen, &pos); /* should get 0xDE */
- sony_fetchtrack((uint8_t*)buffer, buflen, &pos); /* should get 0xAA */
- sony_fetchtrack((uint8_t*)buffer, buflen, &pos); /* should get 0xFF */
-
- /* did we already write this sector? */
- if ((found_sectors & (1 << sector)) == 0)
- {
- sony_denibblize35(sector_data, nibble_data, checksum);
-
- /* write the sector */
- err = apple35_write_sector_td(floppy, head, track, sector, sector_data, std::size(sector_data), 0);
- if (err)
- return err;
-
- found_sectors |= 1 << sector;
- }
- }
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static floperr_t apple35_construct(floppy_image_legacy *floppy, uint32_t data_offset, uint32_t data_size,
- uint32_t tag_offset, uint32_t tag_size, int16_t format_byte, uint8_t sides, bool is_1440k)
-{
- struct apple35_tag *tag;
- struct FloppyCallbacks *format;
-
- /* figure out format byte if not specified */
- if (format_byte < 0)
- {
- switch(sides)
- {
- case 1:
- format_byte = 0x02;
- break;
- case 2:
- format_byte = 0x22;
- break;
- default:
- return FLOPPY_ERROR_INVALIDIMAGE;
- }
- }
-
- /* create tag */
- tag = (struct apple35_tag *) floppy_create_tag(floppy, sizeof(struct apple35_tag));
- if (!tag)
- return FLOPPY_ERROR_OUTOFMEMORY;
- tag->data_offset = data_offset;
- tag->data_size = data_size;
- tag->tag_offset = tag_offset;
- tag->tag_size = tag_size;
- tag->format_byte = (uint8_t) format_byte;
- tag->sides = sides;
- tag->is_1440k = is_1440k ? 1 : 0;
-
- /* set up format callbacks */
- format = floppy_callbacks(floppy);
- format->read_sector = apple35_read_sector;
- format->write_sector = apple35_write_sector;
- format->read_track = apple35_read_track;
- format->write_track = apple35_write_track;
- format->get_sector_length = apple35_get_sector_length;
- format->get_heads_per_disk = apple35_get_heads_per_disk;
- format->get_tracks_per_disk = apple35_get_tracks_per_disk;
- format->get_track_size = apple35_get_track_size;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-/* ----------------------------------------------------------------------- */
-
-static FLOPPY_IDENTIFY(apple35_raw_identify)
-{
- uint64_t size;
- size = floppy_image_size(floppy);
- *vote = ((size == 80*1*10*512) || (size == 80*2*10*512) || (size == (80*2*18*512)+84)
- || (size == 80*2*18*512)) ? 100 : 0;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-
-static FLOPPY_CONSTRUCT(apple35_raw_construct)
-{
- uint64_t size;
- uint8_t sides;
- bool is_1440k;
-
- if (params)
- {
- /* create */
- sides = params->lookup_int(PARAM_HEADS);
- size = 80*sides*10*512;
- is_1440k = false;
- }
- else
- {
- /* load */
- size = floppy_image_size(floppy);
- if (size == 80*1*10*512)
- {
- sides = 1;
- is_1440k = false;
- }
- else if ((size == 80*2*10*512) || (size == 80*2*18*512) || (size == (80*2*18*512)+84))
- {
- sides = 2;
- is_1440k = (size == 80*2*18*512) || (size == (80*2*18*512)+84);
- }
- else
- return FLOPPY_ERROR_INVALIDIMAGE;
- }
-
- return apple35_construct(floppy, 0, (uint32_t) size, 0, 0, -1, sides, is_1440k);
-}
-
-
-
-/* ----------------------------------------------------------------------- */
-
-struct header_diskcopy
-{
- uint8_t disk_name[64]; /* name of the disk */
- uint32_t data_size; /* total size of data for all sectors (512*number_of_sectors) */
- uint32_t tag_size; /* total size of tag data for all sectors (12*number_of_sectors for GCR 3.5" floppies, 20*number_of_sectors for HD20, 0 otherwise) */
- uint32_t data_checksum; /* CRC32 checksum of all sector data */
- uint32_t tag_checksum; /* CRC32 checksum of all tag data */
- uint8_t disk_format; /* 0 = 400K, 1 = 800K, 2 = 720K, 3 = 1440K (other values reserved) */
- uint8_t format_byte; /* should be $00 Apple II, $01 Lisa, $02 Mac MFS ??? */
- /* $12 = 400K, $22 = >400K Macintosh (DiskCopy uses this value for
- all Apple II disks not 800K in size, and even for some of those),
- $24 = 800K Apple II disk */
- uint16_t magic; /* always $0100 (otherwise, the file may be in a different format. */
-};
-
-
-
-static floperr_t apple35_diskcopy_headerdecode(floppy_image_legacy *floppy, uint32_t *data_offset,
- uint32_t *data_size, uint32_t *tag_offset, uint32_t *tag_size, uint8_t *format_byte, uint8_t *sides)
-{
- uint64_t size;
- struct header_diskcopy header;
-
- if (data_offset)
- *data_offset = 0;
- if (data_size)
- *data_size = 0;
- if (tag_offset)
- *tag_offset = 0;
- if (tag_size)
- *tag_size = 0;
- if (format_byte)
- *format_byte = 0;
- if (sides)
- *sides = 0;
-
- size = floppy_image_size(floppy);
- if (size < sizeof(struct header_diskcopy))
- return FLOPPY_ERROR_INVALIDIMAGE;
-
- floppy_image_read(floppy, &header, 0, sizeof(header));
-
- header.data_size = big_endianize_int32(header.data_size);
- header.tag_size = big_endianize_int32(header.tag_size);
- header.data_checksum = big_endianize_int32(header.data_checksum);
- header.tag_checksum = big_endianize_int32(header.tag_checksum);
- header.magic = big_endianize_int16(header.magic);
-
- if (header.disk_name[0] >= sizeof(header.disk_name))
- return FLOPPY_ERROR_INVALIDIMAGE;
- if (header.magic != 0x0100)
- return FLOPPY_ERROR_INVALIDIMAGE;
- if (size != (header.data_size + header.tag_size + sizeof(header)))
- return FLOPPY_ERROR_INVALIDIMAGE;
-
- if (header.data_size == 80*1*10*512)
- {
- if (sides)
- *sides = 1;
- }
- else if (header.data_size == 80*2*10*512)
- {
- if (sides)
- *sides = 2;
- }
- else
- return FLOPPY_ERROR_INVALIDIMAGE;
-
- if (data_offset)
- *data_offset = sizeof(header);
- if (data_size)
- *data_size = header.data_size;
- if (tag_offset)
- *tag_offset = sizeof(header) + header.data_size;
- if (tag_size)
- *tag_size = header.tag_size;
- if (format_byte)
- *format_byte = header.format_byte;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static FLOPPY_IDENTIFY(apple35_diskcopy_identify)
-{
- *vote = apple35_diskcopy_headerdecode(floppy, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr) ? 0 : 100;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-
-static FLOPPY_CONSTRUCT(apple35_diskcopy_construct)
-{
- floperr_t err;
- uint8_t format_byte, sides;
- uint32_t data_offset, data_size;
- uint32_t tag_offset, tag_size;
- int16_t format_byte_param = -1;
- struct header_diskcopy header;
-
- if (params)
- {
- /* create */
- sides = params->lookup_int(PARAM_HEADS);
-
- data_size = 80*sides*10*512;
- tag_size = 80*sides*10*12;
-
- memset(&header, 0, sizeof(header));
- header.data_size = big_endianize_int32(data_size);
- header.tag_size = big_endianize_int32(tag_size);
- header.disk_format = (sides > 1) ? 1 : 0;
- header.magic = big_endianize_int16(0x100);
-
- floppy_image_write(floppy, &header, 0, sizeof(header));
- floppy_image_write_filler(floppy, 0, sizeof(header), data_size + tag_size);
- }
-
- /* load */
- err = apple35_diskcopy_headerdecode(floppy, &data_offset, &data_size,
- &tag_offset, &tag_size, &format_byte, &sides);
- if (err)
- return err;
-
- format_byte_param = format_byte;
-
- return apple35_construct(floppy, data_offset, data_size,
- tag_offset, tag_size, format_byte_param, sides, false);
-}
-
-
-
-/* ----------------------------------------------------------------------- */
-
-struct header_2img
-{
- char magic[4]; /* '2IMG' */
- char creator[4]; /* signature; 'MESS' for MESS */
- uint16_t header_length;
- uint16_t version;
- uint32_t image_format;
- uint32_t flags;
- uint32_t block_count;
- uint32_t data_offset;
- uint32_t data_length;
- uint32_t comment_offset;
- uint32_t comment_length;
- uint32_t creator_offset;
- uint32_t creator_length;
- uint32_t padding[4];
-};
-
-#define IMAGE_FORMAT_DO 0
-#define IMAGE_FORMAT_PO 1
-#define IMAGE_FORMAT_NIB 2
-#define IMAGE_FLAGS_LOCKED 0x80000000
-
-
-
-static floperr_t apple35_2img_decode(floppy_image_legacy *floppy, uint32_t *image_format,
- uint32_t *data_offset, uint32_t *data_length)
-{
- struct header_2img header;
- uint64_t size;
-
- if (image_format)
- *image_format = 0;
- if (data_offset)
- *data_offset = 0;
- if (data_length)
- *data_length = 0;
-
- size = floppy_image_size(floppy);
- if (size < sizeof(header))
- {
- return FLOPPY_ERROR_INVALIDIMAGE;
- }
-
- floppy_image_read(floppy, &header, 0, sizeof(header));
-
- if (memcmp(header.magic, "2IMG", 4))
- {
- return FLOPPY_ERROR_INVALIDIMAGE;
- }
-
- header.header_length = little_endianize_int16(header.header_length);
- header.version = little_endianize_int16(header.version);
- header.image_format = little_endianize_int32(header.image_format);
- header.flags = little_endianize_int32(header.flags);
- header.block_count = little_endianize_int32(header.block_count);
- header.data_offset = little_endianize_int32(header.data_offset);
- header.data_length = little_endianize_int32(header.data_length);
- header.comment_offset = little_endianize_int32(header.comment_offset);
- header.comment_length = little_endianize_int32(header.comment_length);
- header.creator_offset = little_endianize_int32(header.creator_offset);
- header.creator_length = little_endianize_int32(header.creator_length);
-
- // at least some images "in the wild" (e.g. TOSEC Minor Set 1) have big-endian data sizes
- // even though that's against the .2mg spec
- if (header.data_length == 0x800c00)
- {
- LOG_FORMATS("ap_dsk35: corrected bad-endian data length\n");
- header.data_length = 0x0c8000;
- }
-
- if ((((uint64_t) header.data_offset) + header.data_length) > size)
- return FLOPPY_ERROR_INVALIDIMAGE;
- if ((((uint64_t) header.comment_offset) + header.comment_length) > size)
- return FLOPPY_ERROR_INVALIDIMAGE;
- if ((((uint64_t) header.creator_offset) + header.creator_length) > size)
- return FLOPPY_ERROR_INVALIDIMAGE;
- if ((header.image_format != IMAGE_FORMAT_DO) &&
- (header.image_format != IMAGE_FORMAT_PO) &&
- (header.image_format != IMAGE_FORMAT_NIB))
- return FLOPPY_ERROR_INVALIDIMAGE;
-
- if (image_format)
- *image_format = header.image_format;
- if (data_offset)
- *data_offset = header.data_offset;
- if (data_length)
- *data_length = header.data_length;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static FLOPPY_IDENTIFY(apple35_2img_identify)
-{
- *vote = apple35_2img_decode(floppy, nullptr, nullptr, nullptr) ? 0 : 100;
- return FLOPPY_ERROR_SUCCESS;
-}
-
-
-
-static FLOPPY_CONSTRUCT(apple35_2img_construct)
-{
- floperr_t err;
- uint32_t image_format;
- uint32_t data_offset;
- uint32_t data_size;
- uint8_t sides = 2;
- struct header_2img header;
-
- if (params)
- {
- /* create */
- sides = params->lookup_int(PARAM_HEADS);
-
- data_offset = sizeof(header);
- data_size = 80*sides*10*512;
-
- memset(&header, 0, sizeof(header));
- header.header_length = little_endianize_int16(sizeof(header));
- header.block_count = little_endianize_int32(80*sides*10);
- header.data_offset = little_endianize_int32(data_offset);
- header.data_length = little_endianize_int32(data_size);
-
- floppy_image_write(floppy, &header, 0, sizeof(header));
- floppy_image_write_filler(floppy, 0, sizeof(header), data_size);
- }
- else
- {
- /* load */
- err = apple35_2img_decode(floppy, &image_format, &data_offset, &data_size);
- if (err)
- return err;
-
- if (data_size == 80*1*10*512)
- sides = 1; /* single sided */
- else if (data_size == 80*2*10*512)
- sides = 2; /* double sided */
- else
- sides = 2; /* unknown... what to do... */
- }
-
- return apple35_construct(floppy, data_offset, data_size,
- 0, 0, -1, sides, false);
-}
-
-
-
-LEGACY_FLOPPY_OPTIONS_START( apple35_mac )
- LEGACY_FLOPPY_OPTION( apple35_raw, "dsk,img,image", "Apple raw 3.5\" disk image", apple35_raw_identify, apple35_raw_construct, nullptr,
- HEADS([1]-2)
- TRACKS([80])
- SECTOR_LENGTH([512])
- FIRST_SECTOR_ID([0]))
- LEGACY_FLOPPY_OPTION( apple35_dc, "dc,dc42,dsk,img,image", "Apple DiskCopy disk image", apple35_diskcopy_identify, apple35_diskcopy_construct, nullptr,
- HEADS([1]-2)
- TRACKS([80])
- SECTOR_LENGTH([512])
- FIRST_SECTOR_ID([0]))
-LEGACY_FLOPPY_OPTIONS_END
-
-LEGACY_FLOPPY_OPTIONS_START( apple35_iigs )
- LEGACY_FLOPPY_OPTION( apple35_raw, "dsk,img,image,po", "Apple raw 3.5\" disk image", apple35_raw_identify, apple35_raw_construct, nullptr,
- HEADS([1]-2)
- TRACKS([80])
- SECTOR_LENGTH([512])
- FIRST_SECTOR_ID([0]))
- LEGACY_FLOPPY_OPTION( apple35_dc, "dc,dsk,img,image", "Apple DiskCopy disk image", apple35_diskcopy_identify, apple35_diskcopy_construct, nullptr,
- HEADS([1]-2)
- TRACKS([80])
- SECTOR_LENGTH([512])
- FIRST_SECTOR_ID([0]))
- LEGACY_FLOPPY_OPTION( apple35_2img, "2img,2mg", "Apple ][gs 2IMG disk image", apple35_2img_identify, apple35_2img_construct, nullptr,
- HEADS([1]-2)
- TRACKS([80])
- SECTOR_LENGTH([512])
- FIRST_SECTOR_ID([0]))
-LEGACY_FLOPPY_OPTIONS_END
-
-
-// license:BSD-3-Clause
-// copyright-holders:Olivier Galibert
-
dc42_format::dc42_format() : floppy_image_format_t()
{
}
diff --git a/src/lib/formats/ap_dsk35.h b/src/lib/formats/ap_dsk35.h
index f9df62a326d..0b4490348e4 100644
--- a/src/lib/formats/ap_dsk35.h
+++ b/src/lib/formats/ap_dsk35.h
@@ -13,17 +13,6 @@
#pragma once
#include "flopimg.h"
-#include "flopimg_legacy.h"
-
-void sony_filltrack(uint8_t *buffer, size_t buffer_len, size_t *pos, uint8_t data);
-uint8_t sony_fetchtrack(const uint8_t *buffer, size_t buffer_len, size_t *pos);
-
-int apple35_sectors_per_track(floppy_image_legacy *image, int track);
-
-/**************************************************************************/
-
-LEGACY_FLOPPY_OPTIONS_EXTERN(apple35_mac);
-LEGACY_FLOPPY_OPTIONS_EXTERN(apple35_iigs);
class dc42_format : public floppy_image_format_t
{