Rev 3545 | Rev 3704 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3545 | hidnplayr | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
3618 | hidnplayr | 3 | ;; Copyright (C) KolibriOS team 2010-2013. All rights reserved. ;; |
3545 | hidnplayr | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; Synergyc.asm - Synergy client for KolibriOS ;; |
||
7 | ;; ;; |
||
8 | ;; Written by hidnplayr@kolibrios.org ;; |
||
9 | ;; ;; |
||
10 | ;; GNU GENERAL PUBLIC LICENSE ;; |
||
11 | ;; Version 2, June 1991 ;; |
||
12 | ;; ;; |
||
13 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
14 | |||
15 | format binary as "" |
||
16 | |||
3618 | hidnplayr | 17 | BUFFERSIZE = 1024 |
18 | DEFAULTPORT = 24800 |
||
19 | |||
3545 | hidnplayr | 20 | use32 |
21 | org 0x0 |
||
22 | |||
23 | db 'MENUET01' ; signature |
||
24 | dd 1 ; header version |
||
25 | dd start ; entry point |
||
26 | dd i_end ; initialized size |
||
27 | dd mem+0x1000 ; required memory |
||
28 | dd mem+0x1000 ; stack pointer |
||
29 | dd 0 ; parameters |
||
30 | dd path ; path |
||
31 | |||
3618 | hidnplayr | 32 | include '../../macros.inc' |
3545 | hidnplayr | 33 | purge mov,add,sub |
3618 | hidnplayr | 34 | include '../../proc32.inc' |
35 | include '../../dll.inc' |
||
3545 | hidnplayr | 36 | |
3618 | hidnplayr | 37 | include '../../network.inc' |
3545 | hidnplayr | 38 | |
39 | start: |
||
40 | |||
41 | cld |
||
42 | mov edi, path ; Calculate the length of zero-terminated string |
||
43 | xor al, al |
||
44 | mov ecx, 1024 |
||
45 | repne scasb |
||
46 | dec edi |
||
47 | mov esi, filename ; append the path with '.ini' |
||
48 | movsd |
||
49 | movsb |
||
50 | |||
51 | mcall 68, 11 |
||
52 | |||
53 | stdcall dll.Load, @IMPORT |
||
54 | test eax, eax |
||
55 | jnz exit |
||
56 | |||
57 | push 1 |
||
58 | call [con_start] |
||
59 | |||
60 | push title |
||
61 | push 25 |
||
62 | push 80 |
||
63 | push 25 |
||
64 | push 80 |
||
65 | call [con_init] |
||
66 | |||
3618 | hidnplayr | 67 | push str0 |
3545 | hidnplayr | 68 | call [con_write_asciiz] |
69 | |||
70 | invoke ini.get_str, path, str_remote, str_ip, buffer_ptr, 16, 0 |
||
71 | test eax, eax |
||
72 | jnz error |
||
73 | |||
74 | invoke ini.get_int, path, str_remote, str_port, DEFAULTPORT |
||
75 | xchg al, ah |
||
76 | mov [sockaddr1.port], ax |
||
77 | |||
78 | push str1 |
||
79 | call [con_write_asciiz] |
||
80 | |||
81 | push buffer_ptr |
||
82 | call [con_write_asciiz] |
||
83 | |||
84 | push newline |
||
85 | call [con_write_asciiz] |
||
86 | |||
87 | mcall socket, AF_INET4, SOCK_STREAM, 0 |
||
88 | cmp eax, -1 |
||
89 | je error |
||
90 | mov [socketnum], eax |
||
91 | |||
3618 | hidnplayr | 92 | ; resolve name |
93 | push esp ; reserve stack place |
||
94 | push esp ; ptr to result |
||
95 | push 0 ; addrinfo hints |
||
96 | push 0 ; servname |
||
3545 | hidnplayr | 97 | push buffer_ptr ; hostname |
3618 | hidnplayr | 98 | call [getaddrinfo] |
99 | pop esi |
||
100 | ; test for error |
||
101 | test eax, eax |
||
102 | jnz error |
||
103 | |||
104 | mov eax, [esi+addrinfo.ai_addr] |
||
105 | mov eax, [eax+sockaddr_in.sin_addr] |
||
3545 | hidnplayr | 106 | mov [sockaddr1.ip], eax |
107 | |||
108 | mcall connect, [socketnum], sockaddr1, 18 |
||
109 | |||
110 | push str7 |
||
111 | call [con_write_asciiz] |
||
112 | |||
3618 | hidnplayr | 113 | mcall 40, EVM_STACK |
3545 | hidnplayr | 114 | |
115 | login: |
||
116 | call wait_for_data |
||
117 | |||
118 | push buffer_ptr + 4 |
||
119 | call [con_write_asciiz] |
||
120 | |||
121 | cmp dword [buffer_ptr], 11 shl 24 |
||
122 | jne login |
||
123 | cmp dword [buffer_ptr + 4], 'Syne' |
||
124 | jne login |
||
125 | cmp word [buffer_ptr + 8], 'rg' |
||
126 | jne login |
||
127 | cmp byte [buffer_ptr + 10], 'y' |
||
128 | jne login |
||
129 | |||
130 | push str2 |
||
131 | call [con_write_asciiz] |
||
132 | |||
133 | lea edi, [buffer_ptr + 11 + 4 + 4] |
||
134 | invoke ini.get_str, path, str_local, str_name, edi, 255, 0 |
||
135 | xor al , al |
||
136 | mov ecx, 256 |
||
137 | repne scasb |
||
138 | sub edi, buffer_ptr + 1 + 4 |
||
139 | mov esi, edi |
||
140 | bswap edi |
||
141 | mov dword [buffer_ptr], edi |
||
142 | mov edi, esi |
||
143 | sub edi, 11 + 4 |
||
144 | bswap edi |
||
145 | mov dword [buffer_ptr + 11 + 4], edi |
||
146 | add esi, 4 |
||
147 | |||
148 | mcall send, [socketnum], buffer_ptr, , 0 |
||
149 | |||
150 | mainloop: |
||
151 | call wait_for_data |
||
152 | mov edi, buffer_ptr |
||
153 | |||
154 | .command: |
||
155 | push eax edi |
||
156 | |||
157 | cmp dword [edi + 4], 'QINF' ; query screen info |
||
158 | je .qinf |
||
159 | |||
160 | cmp dword [edi + 4], 'CALV' ; alive ? |
||
161 | je .calv |
||
162 | |||
163 | cmp dword [edi + 4], 'CINN' ; mouse moved into screen |
||
164 | je .cinn |
||
165 | |||
166 | cmp dword [edi + 4], 'DCLP' ; Clipboard event |
||
167 | je .dclp |
||
168 | |||
169 | cmp dword [edi + 4], 'DMMV' ; Mouse moved |
||
170 | je .dmmv |
||
171 | |||
172 | cmp dword [edi + 4], 'COUT' ; leave screen |
||
173 | je .cout |
||
174 | |||
175 | cmp dword [edi + 4], 'DMDN' ; mouse button down |
||
176 | je .dmdn |
||
177 | |||
178 | cmp dword [edi + 4], 'DMUP' ; mouse button released |
||
179 | je .dmup |
||
180 | |||
181 | cmp dword [edi + 4], 'CNOP' ; no operation |
||
182 | je .next |
||
183 | |||
184 | cmp dword [edi + 4], 'CIAK' ; resolution changed? |
||
185 | je .ciak |
||
186 | |||
187 | push str3 |
||
188 | call [con_write_asciiz] |
||
189 | |||
190 | mov byte[edi+8],0 |
||
191 | add edi, 4 |
||
192 | push edi |
||
193 | call [con_write_asciiz] |
||
194 | |||
195 | push newline |
||
196 | call [con_write_asciiz] |
||
197 | |||
198 | .next: |
||
199 | pop edi eax |
||
200 | |||
201 | mov ecx, dword [edi] |
||
202 | bswap ecx |
||
203 | add ecx, 4 |
||
204 | sub eax, ecx |
||
205 | jle mainloop |
||
206 | add edi, ecx |
||
207 | jmp .command |
||
208 | |||
209 | |||
210 | .qinf: |
||
211 | mcall 14 ; get screen info |
||
212 | add eax, 0x00010001 |
||
213 | bswap eax |
||
214 | mov dword [screeninfo.size], eax |
||
215 | mcall send, [socketnum], screeninfo, screeninfo.length, 0 ; send client name |
||
216 | jmp .next |
||
217 | |||
218 | |||
219 | .calv: |
||
220 | mcall send, [socketnum], calv, calv.length, 0 ; looks like ping-pong event |
||
221 | jmp .next |
||
222 | |||
223 | |||
224 | .cinn: |
||
225 | mov edx, [edi + 8] |
||
226 | bswap edx |
||
227 | mcall 18, 19, 4 |
||
228 | ; ignore sequence number and modify key mask for now |
||
229 | push str6 |
||
230 | call [con_write_asciiz] |
||
231 | jmp .next |
||
232 | |||
233 | .dclp: |
||
234 | |||
235 | jmp .next |
||
236 | |||
237 | .dmmv: |
||
238 | mov edx, [edi + 8] |
||
239 | bswap edx |
||
240 | mcall 18, 19, 4 |
||
241 | mcall send, [socketnum], cnop, cnop.length, 0 ; reply with NOP |
||
242 | push str4 |
||
243 | call [con_write_asciiz] |
||
244 | jmp .next |
||
245 | |||
246 | .cout: |
||
247 | jmp .next |
||
248 | |||
249 | .dmdn: |
||
250 | movzx eax, byte [edi + 8] |
||
251 | or [mousestate], eax |
||
252 | mcall 18, 19, 5, [mousestate] |
||
253 | mcall send, [socketnum], cnop, cnop.length, 0 ; reply with NOP |
||
254 | push str5 |
||
255 | call [con_write_asciiz] |
||
256 | jmp .next |
||
257 | |||
258 | .dmup: |
||
259 | movzx eax, byte [edi + 8] |
||
260 | not eax |
||
261 | and [mousestate], eax |
||
262 | mcall 18, 19, 5, [mousestate] |
||
263 | mcall send, [socketnum], cnop, cnop.length, 0 ; reply with NOP |
||
264 | push str5 |
||
265 | call [con_write_asciiz] |
||
266 | jmp .next |
||
267 | |||
268 | .ciak: |
||
269 | jmp .next |
||
270 | |||
271 | error: |
||
272 | push str_err |
||
273 | call [con_write_asciiz] |
||
274 | |||
3618 | hidnplayr | 275 | ; call [con_gets] |
3545 | hidnplayr | 276 | |
3618 | hidnplayr | 277 | call [con_getch2] |
278 | |||
279 | mcall close, [socketnum] |
||
280 | |||
3545 | hidnplayr | 281 | push 1 |
282 | call [con_exit] |
||
283 | exit: |
||
284 | |||
285 | mcall -1 |
||
286 | |||
287 | |||
288 | wait_for_data: |
||
289 | mcall 10 ; wait for data |
||
290 | |||
291 | mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0 |
||
292 | cmp eax, -1 |
||
293 | je wait_for_data |
||
294 | |||
295 | cmp eax, 8 |
||
3618 | hidnplayr | 296 | jb wait_for_data ; FIXME |
3545 | hidnplayr | 297 | |
298 | ret |
||
299 | |||
300 | |||
301 | |||
302 | ; data |
||
303 | title db 'Synergy client',0 |
||
3618 | hidnplayr | 304 | str0 db 'Welcome to the software KM switch for KolibriOS.',10,10,0 |
3545 | hidnplayr | 305 | str1 db 'Connecting to: ',0 |
3618 | hidnplayr | 306 | str7 db 'Connected!',10,0 |
307 | str2 db 10,'Handshake received',10,0 |
||
3545 | hidnplayr | 308 | str3 db 'Unsupported command: ',0 |
3618 | hidnplayr | 309 | newline db 10,0 |
310 | str4 db 'mouse moved',10,0 |
||
311 | str5 db 'mouse buttons changed',10,0 |
||
312 | str6 db 'Enter screen',10,0 |
||
313 | str_err db 'Uh-Oh.. some error occured !',10,'Press any key to quit.',0 |
||
3545 | hidnplayr | 314 | |
315 | screeninfo: |
||
316 | dd (screeninfo.length - 4) shl 24 |
||
317 | db 'DINF' |
||
318 | dw 0 ; coordinate of leftmost pixel |
||
319 | dw 0 ; coordiante of topmost pixel |
||
320 | .size: |
||
321 | dw 0 ; width |
||
322 | dw 0 ; height |
||
323 | |||
324 | dw 0 ; size of warp zone |
||
325 | |||
326 | dw 0xb88b ; x position of the mouse on the secondary screen (no idea what it means) |
||
327 | dw 0xbcfb ; y position of the mouse on the secondary screen |
||
328 | .length = $ - screeninfo |
||
329 | |||
330 | calv: |
||
331 | dd (4) shl 24 |
||
332 | db 'CALV' |
||
333 | .length = $ - calv + 8 ; also send cnop |
||
334 | |||
335 | cnop: |
||
336 | dd (4) shl 24 |
||
337 | db 'CNOP' |
||
338 | .length = $ - cnop |
||
339 | |||
340 | mousestate dd 0 |
||
341 | |||
342 | |||
343 | sockaddr1: |
||
344 | dw AF_INET4 |
||
345 | .port dw 0 |
||
346 | .ip dd 192 + 168 shl 8 + 1 shl 16 + 115 shl 24 |
||
347 | rb 10 |
||
348 | |||
349 | filename db '.ini', 0 |
||
350 | str_local db 'local', 0 |
||
351 | str_name db 'name', 0 |
||
352 | str_remote db 'remote', 0 |
||
353 | str_port db 'port', 0 |
||
354 | str_ip db 'ip', 0 |
||
355 | |||
356 | ; import |
||
357 | align 16 |
||
358 | @IMPORT: |
||
359 | |||
360 | library console, 'console.obj',\ |
||
361 | network, 'network.obj',\ |
||
362 | libini, 'libini.obj' |
||
363 | |||
364 | import network,\ |
||
3618 | hidnplayr | 365 | getaddrinfo, 'getaddrinfo' |
3545 | hidnplayr | 366 | |
367 | import console, \ |
||
368 | con_start, 'START',\ |
||
369 | con_init, 'con_init',\ |
||
370 | con_write_asciiz, 'con_write_asciiz',\ |
||
371 | con_exit, 'con_exit',\ |
||
372 | con_gets, 'con_gets',\ |
||
373 | con_cls, 'con_cls',\ |
||
374 | con_getch2, 'con_getch2',\ |
||
375 | con_set_cursor_pos, 'con_set_cursor_pos' |
||
376 | |||
377 | import libini,\ |
||
378 | ini.get_str, 'ini_get_str',\ |
||
379 | ini.get_int, 'ini_get_int' |
||
380 | |||
381 | align 4 |
||
382 | i_end: |
||
383 | socketnum dd ? |
||
384 | buffer_ptr rb BUFFERSIZE |
||
385 | path rb 4096 ; stack |
||
386 | mem: |