OSDN Git Service

[UI][EMU][OSD][Qt][FLOPPY] Fix message routing.
[csp-qt/common_source_project-fm7.git] / source / src / qt / common / util_fd2.cpp
1 #include "emu_thread_tmpl.h"
2 #include "mainwidget_base.h"
3 #include "commonclasses.h"
4 #include "menu_disk.h"
5 #include "qt_dialogs.h"
6
7 #include "menu_flags.h"
8
9 #include "../../fileio.h"
10
11 //#if defined(USE_FLOPPY_DISK)
12
13 #ifndef UPDATE_D88_LIST
14 #define UPDATE_D88_LIST(__d, lst) { \
15         lst.clear(); \
16         QString __tmps; \
17         for(int iii = 0; iii < 64; iii++) { \
18                 __tmps = QString::fromUtf8(""); \
19                 if(iii < hRunEmu->get_d88_file_bank_num(__d)) {         \
20                         __tmps = hRunEmu->get_d88_file_disk_name(__d, iii); \
21                 } \
22         lst << __tmps; \
23         } \
24 }
25 #endif
26
27
28 //extern DLL_PREFIX_I EMU *emu;
29 int Ui_MainWindowBase::set_d88_slot(int drive, int num)
30 {
31         QString path;
32         if((num < 0) || (num >= 64)) return -1;
33         //path = QString::fromUtf8(emu->d88_file[drive].path);
34         path = hRunEmu->get_d88_file_path(drive);
35         menu_fds[drive]->do_select_inner_media(num);
36
37         if(hRunEmu->get_d88_file_cur_bank(drive) != num) {
38                 emit sig_close_disk(drive);
39                 emit sig_open_disk(drive, path, num);
40                 if(hRunEmu->is_floppy_disk_protected(drive)) {
41                         menu_fds[drive]->do_set_write_protect(true);
42                 } else {
43                         menu_fds[drive]->do_set_write_protect(false);
44                 }
45         }
46         return 0;
47 }
48
49 void Ui_MainWindowBase::do_update_recent_disk(int drv)
50 {
51         if(hRunEmu == NULL) return;
52         menu_fds[drv]->do_update_histories(listFDs[drv]);
53         menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
54         if(hRunEmu != NULL) {
55 //              if(hRunEmu->get_d88_file_cur_bank(drv) != num) {
56                         if(hRunEmu->is_floppy_disk_protected(drv)) {
57                                 menu_fds[drv]->do_set_write_protect(true);
58                         } else {
59                                 menu_fds[drv]->do_set_write_protect(false);
60                         }
61 //              }
62         }
63 }
64
65
66 extern const _TCHAR* DLL_PREFIX_I get_parent_dir(const _TCHAR* file);
67
68 int Ui_MainWindowBase::set_recent_disk(int drv, int num) 
69 {
70         QString s_path;
71
72         if(using_flags->get_max_drive() <= drv) return -1;
73         if((num < 0) || (num >= MAX_HISTORY)) return -1;
74         s_path = QString::fromLocal8Bit(p_config->recent_floppy_disk_path[drv][num]);
75         if(!(s_path.isEmpty())) {
76                 _open_disk(drv, s_path);
77                 return 0;
78         }
79         return -1;
80 }
81
82 void Ui_MainWindowBase::do_ui_floppy_insert_history(int drv, QString fname, quint64 bank)
83 {
84         if(fname.length() <= 0) return;
85         if(using_flags->get_max_drive() <= drv) return;
86         
87         _TCHAR path_shadow[_MAX_PATH] = {0};
88         strncpy(path_shadow, fname.toLocal8Bit().constData(), _MAX_PATH - 1);
89         if(!(FILEIO::IsFileExisting(path_shadow))) return;
90
91         if((bank & 0x80) == 0) {
92                 UPDATE_HISTORY(path_shadow, p_config->recent_floppy_disk_path[drv], listFDs[drv]);
93                 strcpy(p_config->initial_floppy_disk_dir,       get_parent_dir((const _TCHAR *)path_shadow));
94         // Update List
95                 strncpy(path_shadow, fname.toLocal8Bit().constData(), _MAX_PATH - 1);
96                 menu_fds[drv]->do_set_initialize_directory(p_config->initial_floppy_disk_dir);
97         }
98         do_update_floppy_history(drv, listFDs[drv]);
99         
100         if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
101                 UPDATE_D88_LIST(drv, listD88[drv]);
102                 menu_fds[drv]->do_update_inner_media(listD88[drv], bank & 0x7f);
103         } else {
104                 menu_fds[drv]->do_clear_inner_media();
105         }
106 }
107
108 void Ui_MainWindowBase::_open_disk(int drv, const QString fname)
109 {
110         char path_shadow[PATH_MAX];
111
112         if(fname.length() <= 0) return;
113         if(using_flags->get_max_drive() <= drv) return;
114         if(!(FILEIO::IsFileExisting(fname.toLocal8Bit().constData()))) return; // File not found.       
115 //      drv = drv & 7;
116         strncpy(path_shadow, fname.toLocal8Bit().constData(), PATH_MAX - 1);
117         emit sig_close_disk(drv);
118         emit sig_open_disk(drv, fname, 0);
119
120         if(using_flags->get_max_drive() > (drv + 1)) {
121                 if(check_file_extension(path_shadow, ".d88") || check_file_extension(path_shadow, ".d77")) {
122                         if(((drv & 1) == 0) && (drv + 1 < using_flags->get_max_drive()) && (1 < hRunEmu->get_d88_file_bank_num(drv))) {
123                                 int drv2 = drv + 1;
124                                 emit sig_close_disk(drv2);
125                                 emit sig_open_disk(drv2, fname, 1 + 128);
126                         }
127                 }
128         }
129 }
130
131
132 void Ui_MainWindowBase::do_update_d88_list(int drv, int bank)
133 {
134         UPDATE_D88_LIST(drv, listD88[drv]);
135         menu_fds[drv]->do_update_inner_media(listD88[drv], bank);
136 }
137 //#endif