OSDN Git Service

[General] Merge from upstream version, 2015-01-28.
[csp-qt/common_source_project-fm7.git] / source / src / vm / disk.cpp
index 57c72ac..98e7640 100644 (file)
@@ -76,30 +76,12 @@ static const int secsize[8] = {
 
 static uint8 tmp_buffer[DISK_BUFFER_SIZE];
 
-DISK::DISK()
-{
-       inserted = ejected = write_protected = changed = false;
-       file_size = 0;
-       sector_size = sector_num = 0;
-       sector = NULL;
-       drive_type = DRIVE_TYPE_UNK;
-       drive_rpm = 0;
-       drive_mfm = true;
-}
-
-DISK::~DISK()
-{
-       if(inserted) {
-               close();
-       }
-}
-
-typedef struct fd_format {
+typedef struct {
        int type;
        int ncyl, nside, nsec, size;
-} fd_format;
+} fd_format_t;
 
-static const fd_format fd_formats[] = {
+static const fd_format_t fd_formats[] = {
        { MEDIA_TYPE_2D,  40, 1, 16,  256 },    // 1D   160KB
        { MEDIA_TYPE_2D , 40, 2, 16,  256 },    // 2D   320KB
 #if defined(_MZ80B) || defined(_MZ2000) || defined(_MZ2200) || defined(_MZ2500)
@@ -179,7 +161,7 @@ void DISK::open(_TCHAR path[], int offset)
                
                // check image file format
                for(int i = 0;; i++) {
-                       const fd_format *p = &fd_formats[i];
+                       const fd_format_t *p = &fd_formats[i];
                        if(p->type == -1) {
                                break;
                        }
@@ -277,13 +259,15 @@ file_loaded:
                                }
                        }
                }
-               // FIXME: ugly patch for X1turbo ALPHA and ARCUS
-               is_alpha = false;
-#if defined(_X1TURBO) || defined(_X1TURBOZ)
+               // FIXME: ugly patch for X1turbo ALPHA and Batten Tanuki
+               is_alpha = is_batten = false;
+#if defined(_X1) || defined(_X1TWIN) || defined(_X1TURBO) || defined(_X1TURBOZ)
                if(media_type == MEDIA_TYPE_2D) {
+                       static const uint8 batten[] = {0xca, 0xde, 0xaf, 0xc3, 0xdd, 0x20, 0xc0, 0xc7, 0xb7};
                        uint32 offset = buffer[0x20] | (buffer[0x21] << 8) | (buffer[0x22] << 16) | (buffer[0x23] << 24);
                        uint8 *t = buffer + offset;
                        is_alpha = (strncmp((char *)(t + 0x11), "turbo ALPHA", 11) == 0);
+                       is_batten = (memcmp((void *)(t + 0x11), batten, sizeof(batten)) == 0);
                }
 #endif
        }
@@ -300,7 +284,9 @@ void DISK::close()
                        if(fio->Fopen(dest_path, FILEIO_READ_WRITE_BINARY)) {
                                fio->Fseek(file_offset, FILEIO_SEEK_SET);
                        } else {
-                               fio->Fopen(dest_path, FILEIO_WRITE_BINARY);
+                               _TCHAR tmp_path[_MAX_PATH];
+                               _stprintf_s(tmp_path, _MAX_PATH, _T("temporary_saved_floppy_disk_#%d.d88"), drive_num);
+                               fio->Fopen(emu->bios_path(tmp_path), FILEIO_WRITE_BINARY);
                        }
                        if(fio->IsOpened()) {
                                if(is_standard_image) {
@@ -340,6 +326,20 @@ void DISK::close()
        sector = NULL;
 }
 
+bool DISK::insert_sector(uint32 trk, uint32 side, int secnum, uint8 *chrn, uint8 *buf)
+{
+       uint8 *from;
+       uint8 *to;
+       int n_size;
+       int s_size;
+       int right;
+       
+       if(secnum < 0) return false;
+       
+       // This function is not implemented yet.
+       return true;
+}
+    
 bool DISK::get_track(int trk, int side)
 {
        sector_size = sector_num = 0;
@@ -636,12 +636,12 @@ bool DISK::check_media_type()
 
 bool DISK::teledisk_to_d88()
 {
-       struct td_hdr_t hdr;
-       struct td_cmt_t cmt;
-       struct td_trk_t trk;
-       struct td_sct_t sct;
-       struct d88_hdr_t d88_hdr;
-       struct d88_sct_t d88_sct;
+       td_hdr_t hdr;
+       td_cmt_t cmt;
+       td_trk_t trk;
+       td_sct_t sct;
+       d88_hdr_t d88_hdr;
+       d88_sct_t d88_sct;
        uint8 obuf[512];
        
        // check teledisk header
@@ -999,9 +999,9 @@ int DISK::decode(uint8 *buf, int len)
 
 bool DISK::imagedisk_to_d88()
 {
-       struct imd_trk_t trk;
-       struct d88_hdr_t d88_hdr;
-       struct d88_sct_t d88_sct;
+       imd_trk_t trk;
+       d88_hdr_t d88_hdr;
+       d88_sct_t d88_sct;
        
        // skip comment
        fi->Fseek(0, FILEIO_SEEK_SET);
@@ -1104,8 +1104,8 @@ bool DISK::imagedisk_to_d88()
 
 bool DISK::cpdread_to_d88(int extended)
 {
-       struct d88_hdr_t d88_hdr;
-       struct d88_sct_t d88_sct;
+       d88_hdr_t d88_hdr;
+       d88_sct_t d88_sct;
        int total = 0;
        
        // get cylinder number and side number
@@ -1186,8 +1186,8 @@ bool DISK::cpdread_to_d88(int extended)
 
 bool DISK::standard_to_d88(int type, int ncyl, int nside, int nsec, int size)
 {
-       struct d88_hdr_t d88_hdr;
-       struct d88_sct_t d88_sct;
+       d88_hdr_t d88_hdr;
+       d88_sct_t d88_sct;
        int n = 0, t = 0;
        
        file_size = 0;
@@ -1249,7 +1249,7 @@ bool DISK::standard_to_d88(int type, int ncyl, int nside, int nsec, int size)
        return true;
 }
 
-#define STATE_VERSION  1
+#define STATE_VERSION  2
 
 void DISK::save_state(FILEIO* state_fio)
 {
@@ -1270,6 +1270,7 @@ void DISK::save_state(FILEIO* state_fio)
        state_fio->FputBool(is_standard_image);
        state_fio->FputBool(is_fdi_image);
        state_fio->FputBool(is_alpha);
+       state_fio->FputBool(is_batten);
        state_fio->Fwrite(track, sizeof(track), 1);
        state_fio->FputInt32(sector_num);
        state_fio->FputInt32(data_size_shift);
@@ -1309,6 +1310,7 @@ bool DISK::load_state(FILEIO* state_fio)
        is_standard_image = state_fio->FgetBool();
        is_fdi_image = state_fio->FgetBool();
        is_alpha = state_fio->FgetBool();
+       is_batten = state_fio->FgetBool();
        state_fio->Fread(track, sizeof(track), 1);
        sector_num = state_fio->FgetInt32();
        data_size_shift = state_fio->FgetInt32();