OSDN Git Service

[General][Qt] Fix FTBFSs.
[csp-qt/common_source_project-fm7.git] / source / src / qt / osd_console.cpp
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2015.11.20-
6
7         [ win32 console ]
8 */
9
10 #include "emu.h"
11 #include "fifo.h"
12 //#include "emu_thread.h"
13 #include "emu.h"
14 #include <QString>
15
16 extern EMU *emu;
17 //BOOL WINAPI ctrl_c_handler(DWORD type)
18 //{
19 //      return TRUE;
20 //}
21
22 void OSD_BASE::do_write_inputdata(QString s)
23 {
24         //emit sig_console_input_string(s);
25 }
26
27 void OSD_BASE::do_set_input_string(QString s)
28 {
29         //if(s.empty()
30         //DebugSemaphore->acquire(1);
31         console_cmd_str.append(s);
32         console_cmd_str.append(QString::fromUtf8("\n"));
33         //DebugSemaphore->release();
34 }
35
36 _TCHAR *OSD_BASE::console_input_string(void)
37 {
38         //DebugSemaphore->acquire(1);
39         if(console_cmd_str.isEmpty()) {
40                 //DebugSemaphore->release(1);
41                 return NULL;
42         }
43         _TCHAR *p = (_TCHAR *)console_cmd_str.toUtf8().constData();
44         //DebugSemaphore->release();
45         return p;
46 }
47
48 void OSD_BASE::clear_console_input_string(void)
49 {
50         //DebugSemaphore->acquire(1);
51         console_cmd_str.clear();
52         //DebugSemaphore->release();
53 }
54
55 void OSD_BASE::open_console(_TCHAR* title)
56 {
57         if(osd_console_opened) return;
58         //DebugSemaphore->acquire(1);
59         console_cmd_str.clear();
60         osd_console_opened = true;
61         //DebugSemaphore->release();
62
63 }
64
65 void OSD_BASE::close_console()
66 {
67         //DebugSemaphore->release(DebugSemaphore->available());
68         console_cmd_str.clear();
69         osd_console_opened = false;
70 }
71
72 unsigned int OSD_BASE::get_console_code_page()
73 {
74         //return GetConsoleCP();
75         return 0;
76 }
77
78 bool OSD_BASE::is_console_active()
79 {
80         return  osd_console_opened;
81 }
82
83 void OSD_BASE::set_console_text_attribute(unsigned short attr)
84 {
85         //SetConsoleTextAttribute(hStdOut, attr);
86 }
87
88 void OSD_BASE::write_console(_TCHAR* buffer, unsigned int length)
89 {
90         QString s = QString::fromLocal8Bit((const char *)buffer, length);
91         emit sig_put_string_debugger(s);
92 }
93
94 int OSD_BASE::read_console_input(_TCHAR* buffer)
95 {
96         int count = 0;
97         QString tmps;
98         //DebugSemaphore->acquire(1);
99         tmps = console_cmd_str.left(16);
100         //DebugSemaphore->release(1);
101         if(buffer == NULL) return 0;
102         memset(buffer, 0x00, 16);
103         if(tmps.isEmpty()) {
104                 return 0;
105         }
106         int locallen = tmps.indexOf(QString::fromUtf8("\n"));
107         if(locallen >= 16) locallen = 15;
108         if(locallen >= 0) {
109                 tmps = tmps.left(locallen + 1);
110                 locallen = locallen + 1;
111         }
112
113         count = tmps.length();
114         if(tmps.isEmpty() || (count <= 0)) return 0; 
115         if(count > 16) count = 16;
116         //DebugSemaphore->acquire(1);
117         int l = console_cmd_str.length();
118         
119         console_cmd_str = console_cmd_str.right(l - count);     
120         strncpy((char *)buffer, tmps.toLocal8Bit().constData(), count);
121         //DebugSemaphore->release(1);
122
123         return count;
124 }
125
126 // This is not recognise char code.
127 bool OSD_BASE::is_console_key_pressed(uint32_t ch)
128 {
129         _TCHAR buf[17];
130         if(read_console_input(buf) > 0) return true;
131         return false;
132 }
133         
134 void OSD_BASE::close_debugger_console()
135 {
136         emit sig_debugger_finished(); // It's dirty...
137 }
138
139 void OSD_BASE::do_close_debugger_thread()
140 {
141         emit sig_debugger_finished();
142 }