OSDN Git Service

[Qt][OSD][KEYBOARD] Apply upstream's update.
[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 "./osd.h"
13 //#include "emu_thread.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.isEmpty()) {
30                 console_cmd_str.append(s);
31                 console_cmd_str.append(QString::fromUtf8("\n"));
32         }
33 }
34
35 _TCHAR *OSD_BASE::console_input_string(void)
36 {
37         //DebugSemaphore->acquire(1);
38         if(console_cmd_str.isEmpty()) {
39                 //DebugSemaphore->release(1);
40                 return NULL;
41         }
42         _TCHAR *p = (_TCHAR *)console_cmd_str.toUtf8().constData();
43         //DebugSemaphore->release();
44         return p;
45 }
46
47 void OSD_BASE::clear_console_input_string(void)
48 {
49         //DebugSemaphore->acquire(1);
50         console_cmd_str.clear();
51         //DebugSemaphore->release();
52 }
53
54 void OSD_BASE::open_console(_TCHAR* title)
55 {
56         if(osd_console_opened) return;
57         //DebugSemaphore->acquire(1);
58         console_cmd_str.clear();
59         osd_console_opened = true;
60         //DebugSemaphore->release();
61
62 }
63
64 void OSD_BASE::close_console()
65 {
66         //DebugSemaphore->release(DebugSemaphore->available());
67         console_cmd_str.clear();
68         osd_console_opened = false;
69         emit sig_close_console();
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, int length)
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         if(count > length) count = length;
117         //DebugSemaphore->acquire(1);
118         int l = console_cmd_str.length();
119         
120         console_cmd_str = console_cmd_str.right(l - count);     
121         strncpy((char *)buffer, tmps.toLocal8Bit().constData(), count);
122         //DebugSemaphore->release(1);
123
124         return count;
125 }
126
127 // This is not recognise char code.
128 bool OSD_BASE::is_console_key_pressed(uint32_t ch)
129 {
130         _TCHAR buf[17];
131         if(read_console_input(buf, 16) > 0) return true;
132         return false;
133 }
134         
135 void OSD_BASE::close_debugger_console()
136 {
137         emit sig_debugger_finished(); // It's dirty...
138 }
139
140 void OSD_BASE::do_close_debugger_thread()
141 {
142         emit sig_debugger_finished();
143 }