From 19a2c632ae288b1763b56c6d6e1772f11f21d1cb Mon Sep 17 00:00:00 2001 From: Michael Zapf Date: Wed, 24 Aug 2016 14:22:21 +0200 Subject: [PATCH] ti99: Fix a problem with formatted disk images that do not match the expected file size --- src/lib/formats/ti99_dsk.cpp | 15 +++++++++------ src/lib/formats/ti99_dsk.h | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib/formats/ti99_dsk.cpp b/src/lib/formats/ti99_dsk.cpp index 9e9288cbc5f..943bb82ab5a 100644 --- a/src/lib/formats/ti99_dsk.cpp +++ b/src/lib/formats/ti99_dsk.cpp @@ -47,7 +47,7 @@ #define SECTOR_SIZE 256 // Debugging -#define TRACE 0 +#define TRACE 1 // ==================================================== // Common methods for both formats. @@ -99,7 +99,8 @@ bool ti99_floppy_format::load(io_generic *io, UINT32 form_factor, floppy_image * int cell_size = 0; int sector_count = 0; int heads = 0; - determine_sizes(io, cell_size, sector_count, heads); + int tracks = 0; + determine_sizes(io, cell_size, sector_count, heads, tracks); if (cell_size == 0) return false; @@ -111,7 +112,8 @@ bool ti99_floppy_format::load(io_generic *io, UINT32 form_factor, floppy_image * int file_size = io_generic_size(io); int track_size = get_track_size(cell_size, sector_count); - int track_count = file_size / (track_size*heads); + int track_count = tracks; + if (tracks==0) track_count = file_size / (track_size*heads); if (TRACE) osd_printf_info("ti99_dsk: track count = %d\n", track_count); @@ -785,7 +787,7 @@ int ti99_sdf_format::identify(io_generic *io, UINT32 form_factor) return vote; } -void ti99_sdf_format::determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads) +void ti99_sdf_format::determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads, int& tracks) { UINT64 file_size = io_generic_size(io); ti99vib vib; @@ -819,10 +821,11 @@ void ti99_sdf_format::determine_sizes(io_generic *io, int& cell_size, int& secto } if (TRACE) osd_printf_info("ti99_dsk: VIB says that this disk is %s density with %d sectors per track, %d tracks, and %d heads\n", (cell_size==4000)? "single": ((cell_size==2000)? "double" : "high"), sector_count, vib.tracksperside, heads); have_vib = true; + tracks = vib.tracksperside; } // Do we have a broken VIB? The Pascal disks are known to have such incomplete VIBs - if (heads == 0 || sector_count == 0) have_vib = false; + if (tracks == 0 || heads == 0 || sector_count == 0) have_vib = false; // We're also checking the size of the image int cell_size1 = 0; @@ -1095,7 +1098,7 @@ int ti99_tdf_format::identify(io_generic *io, UINT32 form_factor) Find the proper format for a given image file. We determine the cell size, but we do not care about the sector size (only needed by the SDF converter). */ -void ti99_tdf_format::determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads) +void ti99_tdf_format::determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads, int& tracks) { UINT64 file_size = io_generic_size(io); heads = 2; // TDF only supports two-sided recordings diff --git a/src/lib/formats/ti99_dsk.h b/src/lib/formats/ti99_dsk.h index 64285c1dcce..a29f3698808 100644 --- a/src/lib/formats/ti99_dsk.h +++ b/src/lib/formats/ti99_dsk.h @@ -29,7 +29,7 @@ protected: virtual int min_heads() =0; - virtual void determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads) =0; + virtual void determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads, int& tracks) =0; virtual int get_track_size(int cell_size, int sector_count) =0; virtual void load_track(io_generic *io, UINT8 *trackdata, int head, int track, int sectorcount, int trackcount, int cellsize) =0; virtual void write_track(io_generic *io, UINT8 *trackdata, int *sector, int track, int head, int maxsect, int maxtrack, int numbytes) =0; @@ -57,7 +57,7 @@ public: const char *extensions() const override; private: - void determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads) override; + void determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads, int& tracks) override; int get_track_size(int cell_size, int sector_count) override; void write_track(io_generic *io, UINT8 *trackdata, int *sector, int track, int head, int maxsect, int maxtrack, int numbytes) override; void load_track(io_generic *io, UINT8 *trackdata, int head, int track, int sectorcount, int trackcount, int cellsize) override; @@ -96,7 +96,7 @@ public: const char *extensions() const override; private: - void determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads) override; + void determine_sizes(io_generic *io, int& cell_size, int& sector_count, int& heads, int& tracks) override; void load_track(io_generic *io, UINT8 *trackdata, int head, int track, int sectorcount, int trackcount, int cellsize) override; void write_track(io_generic *io, UINT8 *trackdata, int *sector, int track, int head, int maxsect, int maxtrack, int numbytes) override; int get_track_size(int cell_size, int sector_count) override;