bool DISK::get_track(int trk, int side)
{
if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
- if(trk >= 0) trk >>= 1;
+ if(trk >= 0) {
+ if(trk & 1) {
+ return false; // unformat
+ }
+ trk >>= 1;
+ }
} else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
if(trk >= 0) trk <<= 1;
}
bool DISK::make_track(int trk, int side)
{
if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
- if(trk >= 0) trk >>= 1;
+ if(trk >= 0) {
+ if(trk & 1) {
+ return false; // unformat
+ }
+ trk >>= 1;
+ }
} else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
if(trk >= 0) trk <<= 1;
}
bool DISK::get_sector(int trk, int side, int index)
{
if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
- if(trk >= 0) trk >>= 1;
+ if(trk >= 0) {
+ if(trk & 1) {
+ return false; // unformat
+ }
+ trk >>= 1;
+ }
} else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
if(trk >= 0) trk <<= 1;
}
bool DISK::format_track(int trk, int side)
{
if(media_type == MEDIA_TYPE_2D && drive_type == DRIVE_TYPE_2DD) {
- if(trk >= 0) trk >>= 1;
+ if(trk >= 0) {
+ if(trk & 1) {
+ return false; // unformat
+ }
+ trk >>= 1;
+ }
} else if(media_type == MEDIA_TYPE_2DD && drive_type == DRIVE_TYPE_2D) {
if(trk >= 0) trk <<= 1;
}
file_size.write_4bytes_le_to(tmp_buffer + 0x1c);
memset(buffer, 0, sizeof(buffer));
- memcpy(buffer, tmp_buffer, min(sizeof(buffer), file_size.d));
+ memcpy(buffer, tmp_buffer, min((unsigned int)sizeof(buffer), file_size.d));
}
int DISK::get_max_tracks()
return true;
}
-#define STATE_VERSION 13
+#define STATE_VERSION 14
+
+#include "../../statesub.h"
+#include "../../qt/gui/csp_logger.h"
+void DISK::decl_state(void *p)
+{
+ CSP_Logger *p_logger = (CSP_Logger *)p;
+ state_entry = new csp_state_utils(STATE_VERSION, drive_num, _T("FLOPPY_DISK"), p_logger);
+
+ DECL_STATE_ENTRY_1D_ARRAY(buffer, sizeof(buffer));
+ DECL_STATE_ENTRY_STRING(orig_path, sizeof(orig_path) / sizeof(_TCHAR));
+ DECL_STATE_ENTRY_STRING(dest_path, sizeof(dest_path) / sizeof(_TCHAR));
+
+ DECL_STATE_ENTRY_PAIR(file_size);
+ DECL_STATE_ENTRY_INT32(file_bank);
+ DECL_STATE_ENTRY_UINT32(orig_file_size);
+ DECL_STATE_ENTRY_UINT32(orig_crc32);
+ DECL_STATE_ENTRY_BOOL(trim_required);
+ DECL_STATE_ENTRY_BOOL(is_1dd_image);
+ DECL_STATE_ENTRY_BOOL(is_solid_image);
+ DECL_STATE_ENTRY_BOOL(is_fdi_image);
+
+ DECL_STATE_ENTRY_1D_ARRAY(fdi_header, sizeof(fdi_header));
+
+ DECL_STATE_ENTRY_INT32(solid_ncyl);
+ DECL_STATE_ENTRY_INT32(solid_nside);
+ DECL_STATE_ENTRY_INT32(solid_nsec);
+ DECL_STATE_ENTRY_INT32(solid_size);
+ DECL_STATE_ENTRY_BOOL(solid_mfm);
+ DECL_STATE_ENTRY_BOOL(inserted);
+ DECL_STATE_ENTRY_BOOL(ejected);
+ DECL_STATE_ENTRY_BOOL(write_protected);
+ DECL_STATE_ENTRY_BOOL(changed);
+ DECL_STATE_ENTRY_UINT8(media_type);
+ DECL_STATE_ENTRY_INT32(is_special_disk);
+
+ DECL_STATE_ENTRY_1D_ARRAY(track, sizeof(track));
+
+ DECL_STATE_ENTRY_PAIR(sector_num);
+ DECL_STATE_ENTRY_BOOL(track_mfm);
+ DECL_STATE_ENTRY_BOOL(invalid_format);
+// DECL_STATE_ENTRY_BOOL(no_skew);
+ DECL_STATE_ENTRY_1D_ARRAY(sync_position, sizeof(sync_position) / sizeof(int));
+ DECL_STATE_ENTRY_1D_ARRAY(am1_position, sizeof(am1_position) / sizeof(int));
+ DECL_STATE_ENTRY_1D_ARRAY(id_position, sizeof(id_position) / sizeof(int));
+ DECL_STATE_ENTRY_1D_ARRAY(data_position, sizeof(data_position) / sizeof(int));
+// DECL_STATE_ENTRY_INT32(gap3_size);
+ DECL_STATE_ENTRY_INT32(_tmp_sector_offset);
+ DECL_STATE_ENTRY_PAIR(sector_size);
+
+ DECL_STATE_ENTRY_1D_ARRAY(id, sizeof(id));
+ DECL_STATE_ENTRY_UINT8(density);
+ DECL_STATE_ENTRY_BOOL(deleted);
+ DECL_STATE_ENTRY_BOOL(addr_crc_error);
+ DECL_STATE_ENTRY_BOOL(data_crc_error);
+ DECL_STATE_ENTRY_UINT8(drive_type);
+ DECL_STATE_ENTRY_INT32(drive_rpm);
+ DECL_STATE_ENTRY_BOOL(drive_mfm);
+}
void DISK::save_state(FILEIO* state_fio)
{
- state_fio->FputUint32(STATE_VERSION);
-
- state_fio->Fwrite(buffer, sizeof(buffer), 1);
- state_fio->Fwrite(orig_path, sizeof(orig_path), 1);
- state_fio->Fwrite(dest_path, sizeof(dest_path), 1);
- state_fio->FputUint32(file_size.d);
- state_fio->FputInt32(file_bank);
- state_fio->FputUint32(orig_file_size);
- state_fio->FputUint32(orig_crc32);
- state_fio->FputBool(trim_required);
- state_fio->FputBool(is_1dd_image);
- state_fio->FputBool(is_solid_image);
- state_fio->FputBool(is_fdi_image);
- state_fio->Fwrite(fdi_header, sizeof(fdi_header), 1);
- state_fio->FputInt32(solid_ncyl);
- state_fio->FputInt32(solid_nside);
- state_fio->FputInt32(solid_nsec);
- state_fio->FputInt32(solid_size);
- state_fio->FputBool(solid_mfm);
- state_fio->FputBool(inserted);
- state_fio->FputBool(ejected);
- state_fio->FputBool(write_protected);
- state_fio->FputBool(changed);
- state_fio->FputUint8(media_type);
- state_fio->FputInt32(is_special_disk);
- state_fio->Fwrite(track, sizeof(track), 1);
- state_fio->FputInt32(sector_num.sd);
- state_fio->FputBool(track_mfm);
- state_fio->FputBool(invalid_format);
+ _tmp_sector_offset = (sector != NULL) ? (int)(sector - buffer) : -1;
+
+ if(state_entry != NULL) {
+ state_entry->save_state(state_fio);
+ }
+ //state_fio->FputUint32(STATE_VERSION);
+
+ //state_fio->Fwrite(buffer, sizeof(buffer), 1);
+ //state_fio->Fwrite(orig_path, sizeof(orig_path), 1);
+ //state_fio->Fwrite(dest_path, sizeof(dest_path), 1);
+ //state_fio->FputUint32(file_size.d);
+ //state_fio->FputInt32(file_bank);
+ //state_fio->FputUint32(orig_file_size);
+ //state_fio->FputUint32(orig_crc32);
+ //state_fio->FputBool(trim_required);
+ //state_fio->FputBool(is_1dd_image);
+ //state_fio->FputBool(is_solid_image);
+ //state_fio->FputBool(is_fdi_image);
+ //state_fio->Fwrite(fdi_header, sizeof(fdi_header), 1);
+ //state_fio->FputInt32(solid_ncyl);
+ //state_fio->FputInt32(solid_nside);
+ //state_fio->FputInt32(solid_nsec);
+ //state_fio->FputInt32(solid_size);
+ //state_fio->FputBool(solid_mfm);
+ //state_fio->FputBool(inserted);
+ //state_fio->FputBool(ejected);
+ //state_fio->FputBool(write_protected);
+ //state_fio->FputBool(changed);
+ //state_fio->FputUint8(media_type);
+ //state_fio->FputInt32(is_special_disk);
+ //state_fio->Fwrite(track, sizeof(track), 1);
+ //state_fio->FputInt32(sector_num.sd);
+ //state_fio->FputBool(track_mfm);
+ //state_fio->FputBool(invalid_format);
// state_fio->FputBool(no_skew);
- state_fio->Fwrite(sync_position, sizeof(sync_position), 1);
- state_fio->Fwrite(am1_position, sizeof(am1_position), 1);
- state_fio->Fwrite(id_position, sizeof(id_position), 1);
- state_fio->Fwrite(data_position, sizeof(data_position), 1);
+ //state_fio->Fwrite(sync_position, sizeof(sync_position), 1);
+ //state_fio->Fwrite(am1_position, sizeof(am1_position), 1);
+ //state_fio->Fwrite(id_position, sizeof(id_position), 1);
+ //state_fio->Fwrite(data_position, sizeof(data_position), 1);
// state_fio->FputInt32(gap3_size);
- state_fio->FputInt32(sector ? (int)(sector - buffer) : -1);
- state_fio->FputInt32(sector_size.sd);
- state_fio->Fwrite(id, sizeof(id), 1);
- state_fio->FputUint8(density);
- state_fio->FputBool(deleted);
- state_fio->FputBool(addr_crc_error);
- state_fio->FputBool(data_crc_error);
- state_fio->FputUint8(drive_type);
- state_fio->FputInt32(drive_rpm);
- state_fio->FputBool(drive_mfm);
+ //state_fio->FputInt32(sector ? (int)(sector - buffer) : -1);
+ //state_fio->FputInt32(sector_size.sd);
+ //state_fio->Fwrite(id, sizeof(id), 1);
+ //state_fio->FputUint8(density);
+ //state_fio->FputBool(deleted);
+ //state_fio->FputBool(addr_crc_error);
+ //state_fio->FputBool(data_crc_error);
+ //state_fio->FputUint8(drive_type);
+ //state_fio->FputInt32(drive_rpm);
+ //state_fio->FputBool(drive_mfm);
}
bool DISK::load_state(FILEIO* state_fio)
{
- if(state_fio->FgetUint32() != STATE_VERSION) {
- return false;
- }
- state_fio->Fread(buffer, sizeof(buffer), 1);
- state_fio->Fread(orig_path, sizeof(orig_path), 1);
- state_fio->Fread(dest_path, sizeof(dest_path), 1);
- file_size.d = state_fio->FgetUint32();
- file_bank = state_fio->FgetInt32();
- orig_file_size = state_fio->FgetUint32();
- orig_crc32 = state_fio->FgetUint32();
- trim_required = state_fio->FgetBool();
- is_1dd_image = state_fio->FgetBool();
- is_solid_image = state_fio->FgetBool();
- is_fdi_image = state_fio->FgetBool();
- state_fio->Fread(fdi_header, sizeof(fdi_header), 1);
- solid_ncyl = state_fio->FgetInt32();
- solid_nside = state_fio->FgetInt32();
- solid_nsec = state_fio->FgetInt32();
- solid_size = state_fio->FgetInt32();
- solid_mfm = state_fio->FgetBool();
- inserted = state_fio->FgetBool();
- ejected = state_fio->FgetBool();
- write_protected = state_fio->FgetBool();
- changed = state_fio->FgetBool();
- media_type = state_fio->FgetUint8();
- is_special_disk = state_fio->FgetInt32();
- state_fio->Fread(track, sizeof(track), 1);
- sector_num.sd = state_fio->FgetInt32();
- track_mfm = state_fio->FgetBool();
- invalid_format = state_fio->FgetBool();
+ bool mb = false;
+ if(state_entry != NULL) {
+ mb = state_entry->load_state(state_fio);
+ }
+ if(!mb) return false;
+ //if(state_fio->FgetUint32() != STATE_VERSION) {
+ // return false;
+ //}
+ //state_fio->Fread(buffer, sizeof(buffer), 1);
+ //state_fio->Fread(orig_path, sizeof(orig_path), 1);
+ //state_fio->Fread(dest_path, sizeof(dest_path), 1);
+ //file_size.d = state_fio->FgetUint32();
+ //file_bank = state_fio->FgetInt32();
+ //orig_file_size = state_fio->FgetUint32();
+ //orig_crc32 = state_fio->FgetUint32();
+ //trim_required = state_fio->FgetBool();
+ //is_1dd_image = state_fio->FgetBool();
+ //is_solid_image = state_fio->FgetBool();
+ //is_fdi_image = state_fio->FgetBool();
+ //state_fio->Fread(fdi_header, sizeof(fdi_header), 1);
+ //solid_ncyl = state_fio->FgetInt32();
+ //solid_nside = state_fio->FgetInt32();
+ //solid_nsec = state_fio->FgetInt32();
+ //solid_size = state_fio->FgetInt32();
+ //solid_mfm = state_fio->FgetBool();
+ //inserted = state_fio->FgetBool();
+ //ejected = state_fio->FgetBool();
+ //write_protected = state_fio->FgetBool();
+ //changed = state_fio->FgetBool();
+ //media_type = state_fio->FgetUint8();
+ //is_special_disk = state_fio->FgetInt32();
+ //state_fio->Fread(track, sizeof(track), 1);
+ //sector_num.sd = state_fio->FgetInt32();
+ //track_mfm = state_fio->FgetBool();
+ //invalid_format = state_fio->FgetBool();
// no_skew = state_fio->FgetBool();
- state_fio->Fread(sync_position, sizeof(sync_position), 1);
- state_fio->Fread(am1_position, sizeof(am1_position), 1);
- state_fio->Fread(id_position, sizeof(id_position), 1);
- state_fio->Fread(data_position, sizeof(data_position), 1);
+ //state_fio->Fread(sync_position, sizeof(sync_position), 1);
+ //state_fio->Fread(am1_position, sizeof(am1_position), 1);
+ //state_fio->Fread(id_position, sizeof(id_position), 1);
+ //state_fio->Fread(data_position, sizeof(data_position), 1);
// gap3_size = state_fio->FgetInt32();
- int offset = state_fio->FgetInt32();
- sector = (offset != -1) ? buffer + offset : NULL;
- sector_size.sd = state_fio->FgetInt32();
- state_fio->Fread(id, sizeof(id), 1);
- density = state_fio->FgetUint8();
- deleted = state_fio->FgetBool();
- addr_crc_error = state_fio->FgetBool();
- data_crc_error = state_fio->FgetBool();
- drive_type = state_fio->FgetUint8();
- drive_rpm = state_fio->FgetInt32();
- drive_mfm = state_fio->FgetBool();
+ //int offset = state_fio->FgetInt32();
+ //sector = (offset != -1) ? buffer + offset : NULL;
+ //sector_size.sd = state_fio->FgetInt32();
+ //state_fio->Fread(id, sizeof(id), 1);
+ //density = state_fio->FgetUint8();
+ //deleted = state_fio->FgetBool();
+ //addr_crc_error = state_fio->FgetBool();
+ //data_crc_error = state_fio->FgetBool();
+ //drive_type = state_fio->FgetUint8();
+ //drive_rpm = state_fio->FgetInt32();
+ //drive_mfm = state_fio->FgetBool();
+ sector = (_tmp_sector_offset != -1) ? (buffer + _tmp_sector_offset) : NULL;
return true;
}