OSDN Git Service

e14ecb0505d8b92c3c8c8897fc4dd451e25574e5
[csp-qt/common_source_project-fm7.git] / source / src / qt / gui / util_fd.cpp
1 /*
2  * UI->Qt->MainWindow : FDD Utils.
3  * (C) 2015 K.Ohta <whatisthis.sowhat _at_ gmail.com>
4  * License: GPLv2
5  *
6  * History:
7  * Jan 24, 2014 : Moved from some files.
8  */
9
10
11 #include "mainwidget.h"
12 #include "commonclasses.h"
13 #include "menu_disk.h"
14
15 #include "qt_dialogs.h"
16 #include "emu.h"
17 #include "agar_logger.h"
18
19 extern class EMU *emu;
20
21 void Object_Menu_Control::insert_fd(void) {
22         emit sig_insert_fd(getDrive());
23 }
24 void Object_Menu_Control::eject_fd(void) {
25         write_protect = false;
26         emit sig_eject_fd(getDrive());
27 }
28 void Object_Menu_Control::on_d88_slot(void) {
29         emit set_d88_slot(drive, s_num);
30 }
31 void Object_Menu_Control::on_recent_disk(void){
32   //   write_protect = false; // Right? On D88, May be writing entry  exists. 
33         emit set_recent_disk(drive, s_num);
34 }
35 void Object_Menu_Control::write_protect_fd(void) {
36         write_protect = true;
37         emit sig_write_protect_fd(drive, write_protect);
38 }
39 void Object_Menu_Control::no_write_protect_fd(void) {
40         write_protect = false;
41         emit sig_write_protect_fd(drive, write_protect);
42 }
43
44 void Object_Menu_Control::do_set_ignore_crc_error(bool flag)
45 {
46 #ifdef USE_FD1
47         config.ignore_disk_crc[drive] = flag;
48         emit sig_emu_update_config();
49 #endif   
50 }
51
52 #ifndef UPDATE_D88_LIST
53 #define UPDATE_D88_LIST(__d, lst) { \
54         lst.clear(); \
55         QString __tmps; \
56         for(int iii = 0; iii < MAX_D88_BANKS; iii++) { \
57                 __tmps = QString::fromUtf8(""); \
58                 if(iii < emu->d88_file[__d].bank_num) { \
59                         __tmps = QString::fromUtf8(emu->d88_file[__d].disk_name[iii]); \
60                 } \
61         lst << __tmps; \
62         } \
63 }
64 #endif
65
66 void Object_Menu_Control::do_set_correct_disk_timing(bool flag)
67 {
68 #ifdef USE_FD1
69         config.correct_disk_timing[drive] = flag;
70         emit sig_emu_update_config();
71 #endif   
72 }
73
74
75
76 int Ui_MainWindow::write_protect_fd(int drv, bool flag)
77 {
78 #ifdef USE_FD1
79         if((drv < 0) || (drv >= MAX_FD)) return -1;
80         emit sig_write_protect_disk(drv, flag);
81 #endif
82         return 0;
83 }
84   
85 #ifdef USE_FD1
86 int Ui_MainWindow::set_d88_slot(int drive, int num)
87 {
88         QString path;
89         
90         if((num < 0) || (num >= MAX_D88_BANKS)) return -1;
91         path = QString::fromUtf8(emu->d88_file[drive].path);
92         menu_fds[drive]->do_select_inner_media(num);
93
94         if(emu && emu->d88_file[drive].cur_bank != num) {
95                 emit sig_open_disk(drive, path, num);
96                 if(emu->is_floppy_disk_protected(drive)) {
97                         menu_fds[drive]->do_set_write_protect(true);
98                 } else {
99                         menu_fds[drive]->do_set_write_protect(false);
100                 }
101         }
102         return 0;
103 }
104
105 void Ui_MainWindow::do_update_recent_disk(int drv)
106 {
107         int i;
108         if(emu == NULL) return;
109         menu_fds[drv]->do_update_histories(listFDs[drv]);
110         menu_fds[drv]->do_set_initialize_directory(config.initial_floppy_disk_dir);
111         if(emu->is_floppy_disk_protected(drv)) {
112                 menu_fds[drv]->do_write_protect_media();
113         } else {
114                 menu_fds[drv]->do_write_unprotect_media();
115         }               
116 }
117
118
119 int Ui_MainWindow::set_recent_disk(int drv, int num) 
120 {
121         QString s_path;
122         char path_shadow[PATH_MAX];
123         int i;
124         if((num < 0) || (num >= MAX_HISTORY)) return -1;
125         s_path = QString::fromUtf8(config.recent_floppy_disk_path[drv][num]);
126         strncpy(path_shadow, s_path.toUtf8().constData(), PATH_MAX);
127         UPDATE_HISTORY(path_shadow, config.recent_floppy_disk_path[drv], listFDs[drv]);
128         strncpy(path_shadow, s_path.toUtf8().constData(), PATH_MAX);
129    
130         get_parent_dir(path_shadow);
131         strcpy(config.initial_floppy_disk_dir, path_shadow);
132         strncpy(path_shadow, s_path.toUtf8().constData(), PATH_MAX);
133
134         if(emu) {
135                 emit sig_close_disk(drv);
136                 emit sig_open_disk(drv, s_path, 0);
137                 menu_fds[drv]->do_update_histories(listFDs[drv]);
138                 menu_fds[drv]->do_set_initialize_directory(config.initial_floppy_disk_dir);
139                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
140                         UPDATE_D88_LIST(drv, listD88[drv]);
141                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
142                 } else {
143                         menu_fds[drv]->do_clear_inner_media();
144                 }
145 # ifdef USE_FD2
146                 strncpy(path_shadow, s_path.toUtf8().constData(), PATH_MAX);
147                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
148                         if(((drv & 1) == 0) && (drv + 1 < MAX_FD) && (1 < emu->d88_file[drv].bank_num)) {
149                                 int drv2 = drv + 1;
150                                 emit sig_close_disk(drv2);
151                                 emit sig_open_disk(drv2, s_path, 1);
152                                 menu_fds[drv2]->do_update_histories(listFDs[drv2]);
153                                 menu_fds[drv2]->do_set_initialize_directory(config.initial_floppy_disk_dir);
154                                 UPDATE_D88_LIST(drv2, listD88[drv2]);
155                                 menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
156                         }
157                 }
158 # endif
159         }
160         return 0;
161 }
162
163 #endif
164
165 void Ui_MainWindow::_open_disk(int drv, const QString fname)
166 {
167         char path_shadow[PATH_MAX];
168         int i;
169 #ifdef USE_FD1
170         if(fname.length() <= 0) return;
171         drv = drv & 7;
172         strncpy(path_shadow, fname.toUtf8().constData(), PATH_MAX);
173         UPDATE_HISTORY(path_shadow, config.recent_floppy_disk_path[drv], listFDs[drv]);
174         get_parent_dir(path_shadow);
175         strcpy(config.initial_floppy_disk_dir, path_shadow);
176         // Update List
177         strncpy(path_shadow, fname.toUtf8().constData(), PATH_MAX);
178         if(emu) {
179                 emit sig_close_disk(drv);
180                 //emu->LockVM();
181                 emit sig_open_disk(drv, fname, 0);
182                 menu_fds[drv]->do_update_histories(listFDs[drv]);
183                 menu_fds[drv]->do_set_initialize_directory(config.initial_floppy_disk_dir);
184                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
185                         UPDATE_D88_LIST(drv, listD88[drv]);
186                         menu_fds[drv]->do_update_inner_media(listD88[drv], 0);
187                 } else {
188                         menu_fds[drv]->do_clear_inner_media();
189                 }
190         }
191 # ifdef USE_FD2
192         if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
193                 if(((drv & 1) == 0) && (drv + 1 < MAX_FD) && (1 < emu->d88_file[drv].bank_num)) {
194                         int drv2 = drv + 1;
195                         emit sig_close_disk(drv2);
196                         //emu->LockVM();
197                         strncpy(path_shadow, fname.toUtf8().constData(), PATH_MAX);
198                         emit sig_open_disk(drv2, fname, 1);
199                         menu_fds[drv2]->do_update_histories(listFDs[drv2]);
200                         menu_fds[drv2]->do_set_initialize_directory(config.initial_floppy_disk_dir);
201                         UPDATE_D88_LIST(drv2, listD88[drv2]);
202                         menu_fds[drv2]->do_update_inner_media(listD88[drv2], 1);
203         }
204         }
205 # endif
206 #endif
207 }
208
209 void Ui_MainWindow::eject_fd(int drv) 
210 {
211         int i;
212 #ifdef USE_FD1
213         if(emu) {
214                 emit sig_close_disk(drv);
215                 menu_fds[drv]->do_clear_inner_media();
216         }
217 #endif
218 }
219
220 // Common Routine
221
222 void Ui_MainWindow::CreateFloppyMenu(int drv, int drv_base)
223 {
224 #if defined(USE_FD1)
225         {
226                 QString ext = "*.d88 *.d77 *.1dd *.td0 *.imd *.dsk *.fdi *.hdm *.tfd *.xdf *.2d *.sf7 *.img *.ima *.vfd";
227                 QString desc1 = "Floppy Disk";
228                 menu_fds[drv] = new Menu_FDClass(emu, menubar, QString::fromUtf8("Obj_Floppy"), this, drv);
229                 menu_fds[drv]->create_pulldown_menu();
230                 
231                 menu_fds[drv]->do_clear_inner_media();
232                 menu_fds[drv]->do_add_media_extension(ext, desc1);
233                 SETUP_HISTORY(config.recent_floppy_disk_path[drv], listFDs[drv]);
234                 menu_fds[drv]->do_update_histories(listFDs[drv]);
235                 menu_fds[drv]->do_set_initialize_directory(config.initial_floppy_disk_dir);
236                 listD88[drv].clear();
237
238                 QString name = QString::fromUtf8("FD");
239                 QString tmpv;
240                 tmpv.setNum(drv_base);
241                 name.append(tmpv);
242                 menu_fds[drv]->setTitle(name);
243         }
244 #endif  
245 }
246
247 void Ui_MainWindow::CreateFloppyPulldownMenu(int drv)
248 {
249 }
250
251 void Ui_MainWindow::ConfigFloppyMenuSub(int drv)
252 {
253 }
254
255 void Ui_MainWindow::retranslateFloppyMenu(int drv, int basedrv)
256 {
257 # ifdef USE_FD1
258         QString drive_name = (QApplication::translate("MainWindow", "Floppy ", 0));
259         drive_name += QString::number(basedrv);
260   
261         if((drv < 0) || (drv >= 8)) return;
262         menu_fds[drv]->setTitle(QApplication::translate("MainWindow", drive_name.toUtf8().constData() , 0));
263         menu_fds[drv]->retranslateUi();
264 # endif
265 }
266
267 void Ui_MainWindow::ConfigFloppyMenu(void)
268 {
269 #if defined(USE_FD1)
270         ConfigFloppyMenuSub(0); 
271 #endif
272 #if defined(USE_FD2)
273         ConfigFloppyMenuSub(1);
274 #endif
275 #if defined(USE_FD3)
276         ConfigFloppyMenuSub(2);
277 #endif
278 #if defined(USE_FD4)
279         ConfigFloppyMenuSub(3);
280 #endif
281 #if defined(USE_FD5)
282         ConfigFloppyMenuSub(4);
283 #endif
284 #if defined(USE_FD6)
285         ConfigFloppyMenuSub(5);
286 #endif
287 #if defined(USE_FD7)
288         ConfigFloppyMenuSub(6);
289 #endif
290 #if defined(USE_FD8)
291         ConfigFloppyMenuSub(7);
292 #endif
293 }