diff --git a/src/lib/formats/ap2_dsk.cpp b/src/lib/formats/ap2_dsk.cpp index e07ae76a08503..8077a2ef70e70 100644 --- a/src/lib/formats/ap2_dsk.cpp +++ b/src/lib/formats/ap2_dsk.cpp @@ -35,7 +35,7 @@ int a2_13sect_format::identify(util::random_read &io, uint32_t form_factor, cons if (io.length(size)) return 0; - if (size != APPLE2_STD_TRACK_COUNT * 13 * 256) + if (size != APPLE2_STD_TRACK_COUNT * 13 * APPLE2_SECTOR_SIZE) return 0; return FIFID_SIZE; @@ -49,11 +49,11 @@ bool a2_13sect_format::load(util::random_read &io, uint32_t form_factor, const s image.set_form_variant(floppy_image::FF_525, floppy_image::SSSD); - int tracks = size / 13 / 256; + int tracks = size / 13 / APPLE2_SECTOR_SIZE; for(int track = 0; track < tracks; track++) { std::vector track_data; - uint8_t sector_data[256 * 13]; + uint8_t sector_data[APPLE2_SECTOR_SIZE * 13]; auto const [err, actual] = read_at( io, track * sizeof sector_data, sector_data, sizeof sector_data); @@ -89,7 +89,7 @@ bool a2_13sect_format::load(util::random_read &io, uint32_t form_factor, const s pval = nval; }; - const uint8_t *sdata = sector_data + 256 * sector; + const uint8_t *sdata = sector_data + APPLE2_SECTOR_SIZE * sector; // write 154 bytes encoding bits 2-0 write_data_byte(sdata[255] & 7); @@ -218,16 +218,17 @@ int a2_16sect_format::identify(util::random_read &io, uint32_t form_factor, cons if (io.length(size)) return 0; - //uint32_t expected_size = 35 * 16 * 256; - uint32_t expected_size = APPLE2_TRACK_COUNT * 16 * 256; - // check standard size plus some oddball sizes in our softlist - if ((size != expected_size) && (size != 35 * 16 * 256) && (size != 143403) && (size != 143363) && (size != 143358)) + if ( + size != APPLE2_TRACK_COUNT * 16 * APPLE2_SECTOR_SIZE + && size != APPLE2_STD_TRACK_COUNT * 16 * APPLE2_SECTOR_SIZE + && size != 143403 && size != 143363 && size != 143358 + ) { return 0; } - uint8_t sector_data[256*2]; + uint8_t sector_data[APPLE2_SECTOR_SIZE*2]; static const unsigned char pascal_block1[4] = { 0x08, 0xa5, 0x0f, 0x29 }; static const unsigned char pascal2_block1[4] = { 0xff, 0xa2, 0x00, 0x8e }; static const unsigned char dos33_block1[4] = { 0xa2, 0x02, 0x8e, 0x52 }; @@ -304,18 +305,18 @@ bool a2_16sect_format::load(util::random_read &io, uint32_t form_factor, const s image.set_form_variant(floppy_image::FF_525, floppy_image::SSSD); - int tracks = (size == (40 * 16 * 256)) ? 40 : 35; + int tracks = (size == (APPLE2_TRACK_COUNT * 16 * APPLE2_SECTOR_SIZE)) ? APPLE2_TRACK_COUNT : APPLE2_STD_TRACK_COUNT; int fpos = 0; for(int track=0; track < tracks; track++) { std::vector track_data; - uint8_t sector_data[256*16]; + uint8_t sector_data[APPLE2_SECTOR_SIZE*16]; auto const [err, actual] = read_at(io, fpos, sector_data, sizeof sector_data); if (err || actual != sizeof sector_data) return false; - fpos += 256*16; + fpos += APPLE2_SECTOR_SIZE*16; for(int i=0; i<49; i++) raw_w(track_data, 10, 0x3fc); for(int i=0; i<16; i++) { @@ -330,7 +331,7 @@ bool a2_16sect_format::load(util::random_read &io, uint32_t form_factor, const s sector = dos_skewing[i]; } - const uint8_t *sdata = sector_data + 256 * sector; + const uint8_t *sdata = sector_data + APPLE2_SECTOR_SIZE * sector; for(int j=0; j<20; j++) raw_w(track_data, 10, 0x3fc); raw_w(track_data, 8, 0xff); @@ -393,34 +394,37 @@ uint8_t a2_16sect_format::gb(const std::vector &buf, int &pos, int &wrap) return v; } -//#define VERBOSE_SAVE - bool a2_16sect_format::save(util::random_read_write &io, const std::vector &variants, const floppy_image &image) const { int g_tracks, g_heads; int visualgrid[16][APPLE2_TRACK_COUNT]; // visualizer grid, cleared/initialized below -// lenient addr check: if unset, only accept an addr mark if the checksum was good -// if set, accept an addr mark if the track and sector values are both sane -#undef LENIENT_ADDR_CHECK -// if set, use the old, not as robust logic for choosing which copy of a decoded sector to write -// to the resulting image if the sector has a bad checksum and/or postamble -#undef USE_OLD_BEST_SECTOR_PRIORITY -// nothing found -#define NOTFOUND 0 -// address mark was found -#define ADDRFOUND 1 -// address checksum is good -#define ADDRGOOD 2 -// data mark was found (requires addrfound and sane values) -#define DATAFOUND 4 -// data checksum is good -#define DATAGOOD 8 -// data postamble is good -#define DATAPOST 16 + constexpr bool VERBOSE_SAVE = false; + + // if false, only accept an addr mark if the checksum was good + // if true, accept an addr mark if the track and sector values are both sane + constexpr bool LENIENT_ADDR_CHECK = false; + + // if true, use the old, not as robust logic for choosing which copy of a decoded sector to write + // to the resulting image if the sector has a bad checksum and/or postamble + constexpr bool USE_OLD_BEST_SECTOR_PRIORITY = false; + + // nothing found + constexpr int NOTFOUND = 0; + // address mark was found + constexpr int ADDRFOUND = 1; + // address checksum is good + constexpr int ADDRGOOD = 2; + // data mark was found (requires addrfound and sane values) + constexpr int DATAFOUND = 4; + // data checksum is good + constexpr int DATAGOOD = 8; + // data postamble is good + constexpr int DATAPOST = 16; + for (auto & elem : visualgrid) { for (int j = 0; j < APPLE2_TRACK_COUNT; j++) { - elem[j] = 0; + elem[j] = NOTFOUND; } } image.get_actual_geometry(g_tracks, g_heads); @@ -430,16 +434,16 @@ bool a2_16sect_format::save(util::random_read_write &io, const std::vector0) printf("t%d,", track); - uint8_t const *const data = sectdata + (256)*i; - auto const [err, actual] = write_at(io, pos_data, data, 256); - if (err || actual != 256) + uint8_t const *const data = sectdata + APPLE2_SECTOR_SIZE*i; + auto const [err, actual] = write_at(io, pos_data, data, APPLE2_SECTOR_SIZE); + if (err || actual != APPLE2_SECTOR_SIZE) return false; - pos_data += 256; + pos_data += APPLE2_SECTOR_SIZE; } //printf("\n"); } // display a little table of which sectors decoded ok - #ifdef VERBOSE_SAVE - int total_good = 0; - for (int j = 0; j < APPLE2_TRACK_COUNT; j++) { - printf("T%2d: ",j); - for (int i = 0; i < 16; i++) { - if (visualgrid[i][j] == NOTFOUND) printf("-NF- "); - else { - if (visualgrid[i][j] & ADDRFOUND) printf("a"); else printf(" "); - if (visualgrid[i][j] & ADDRGOOD) printf("A"); else printf(" "); - if (visualgrid[i][j] & DATAFOUND) printf("d"); else printf(" "); - if (visualgrid[i][j] & DATAGOOD) { printf("D"); total_good++; } else printf(" "); - if (visualgrid[i][j] & DATAPOST) printf("."); else printf(" "); + if(VERBOSE_SAVE) { + int total_good = 0; + for (int j = 0; j < APPLE2_TRACK_COUNT; j++) { + printf("T%2d: ",j); + for (int i = 0; i < 16; i++) { + if (visualgrid[i][j] == NOTFOUND) printf("-NF- "); + else { + if (visualgrid[i][j] & ADDRFOUND) printf("a"); else printf(" "); + if (visualgrid[i][j] & ADDRGOOD) printf("A"); else printf(" "); + if (visualgrid[i][j] & DATAFOUND) printf("d"); else printf(" "); + if (visualgrid[i][j] & DATAGOOD) { printf("D"); total_good++; } else printf(" "); + if (visualgrid[i][j] & DATAPOST) printf("."); else printf(" "); + } } + printf("\n"); } - printf("\n"); + printf("Total Good Sectors: %d\n", total_good); } - printf("Total Good Sectors: %d\n", total_good); - #endif return true; } @@ -1407,7 +1410,7 @@ bool a2_nib_format::load(util::random_read &io, uint32_t form_factor, const std: if (size != expected_size_35t && size != expected_size_40t) return false; - const auto nr_tracks = size == expected_size_35t? 35 : 40; + const auto nr_tracks = size / nibbles_per_track; std::vector nibbles(nibbles_per_track); for (unsigned track = 0; track < nr_tracks; ++track) { diff --git a/src/lib/formats/ap2_dsk.h b/src/lib/formats/ap2_dsk.h index c89aa3d953359..33117ecbd844c 100644 --- a/src/lib/formats/ap2_dsk.h +++ b/src/lib/formats/ap2_dsk.h @@ -21,12 +21,9 @@ ***************************************************************************/ -#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 +constexpr int APPLE2_STD_TRACK_COUNT = 35; +constexpr int APPLE2_TRACK_COUNT = 40; +constexpr int APPLE2_SECTOR_SIZE = 256; /**************************************************************************/ class a2_13sect_format : public floppy_image_format_t @@ -145,8 +142,8 @@ class a2_nib_format : public floppy_image_format_t private: static constexpr size_t nibbles_per_track = 0x1a00; static constexpr size_t min_sync_bytes = 4; - static constexpr auto expected_size_35t = 35 * nibbles_per_track; - static constexpr auto expected_size_40t = 40 * nibbles_per_track; + static constexpr auto expected_size_35t = APPLE2_STD_TRACK_COUNT * nibbles_per_track; + static constexpr auto expected_size_40t = APPLE2_TRACK_COUNT * nibbles_per_track; static std::vector generate_levels_from_nibbles(const std::vector& nibbles); };