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 | mov edi, path ; Calculate the length of zero-terminated string |
||
42 | xor al, al |
||
43 | mov ecx, 1024 |
||
44 | repne scasb |
||
45 | dec edi |
||
46 | mov esi, filename ; append the path with '.ini' |
||
47 | movsd |
||
48 | movsb |
||
49 | |||
50 | mcall 68, 11 |
||
4376 | hidnplayr | 51 | mcall 66, 1, 1 |
3545 | hidnplayr | 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 |
4376 | hidnplayr | 114 | mcall 10 |
3545 | hidnplayr | 115 | |
116 | login: |
||
117 | call wait_for_data |
||
118 | |||
119 | push buffer_ptr + 4 |
||
120 | call [con_write_asciiz] |
||
121 | |||
4376 | hidnplayr | 122 | cmp dword [buffer_ptr], 11 shl 24 ; length of string |
123 | jne error |
||
3545 | hidnplayr | 124 | cmp dword [buffer_ptr + 4], 'Syne' |
4376 | hidnplayr | 125 | jne error |
3545 | hidnplayr | 126 | cmp word [buffer_ptr + 8], 'rg' |
4376 | hidnplayr | 127 | jne error |
3545 | hidnplayr | 128 | cmp byte [buffer_ptr + 10], 'y' |
4376 | hidnplayr | 129 | jne error |
3545 | hidnplayr | 130 | |
131 | push str2 |
||
132 | call [con_write_asciiz] |
||
133 | |||
134 | lea edi, [buffer_ptr + 11 + 4 + 4] |
||
135 | invoke ini.get_str, path, str_local, str_name, edi, 255, 0 |
||
136 | xor al , al |
||
137 | mov ecx, 256 |
||
138 | repne scasb |
||
139 | sub edi, buffer_ptr + 1 + 4 |
||
140 | mov esi, edi |
||
141 | bswap edi |
||
142 | mov dword [buffer_ptr], edi |
||
143 | mov edi, esi |
||
144 | sub edi, 11 + 4 |
||
145 | bswap edi |
||
146 | mov dword [buffer_ptr + 11 + 4], edi |
||
147 | add esi, 4 |
||
148 | |||
149 | mcall send, [socketnum], buffer_ptr, , 0 |
||
150 | |||
151 | mainloop: |
||
152 | call wait_for_data |
||
153 | mov edi, buffer_ptr |
||
154 | |||
155 | .command: |
||
156 | push eax edi |
||
157 | |||
158 | cmp dword [edi + 4], 'QINF' ; query screen info |
||
159 | je .qinf |
||
160 | |||
161 | cmp dword [edi + 4], 'CALV' ; alive ? |
||
162 | je .calv |
||
163 | |||
164 | cmp dword [edi + 4], 'CINN' ; mouse moved into screen |
||
165 | je .cinn |
||
166 | |||
167 | cmp dword [edi + 4], 'DCLP' ; Clipboard event |
||
168 | je .dclp |
||
169 | |||
170 | cmp dword [edi + 4], 'DMMV' ; Mouse moved |
||
171 | je .dmmv |
||
172 | |||
173 | cmp dword [edi + 4], 'COUT' ; leave screen |
||
174 | je .cout |
||
175 | |||
176 | cmp dword [edi + 4], 'DMDN' ; mouse button down |
||
177 | je .dmdn |
||
178 | |||
179 | cmp dword [edi + 4], 'DMUP' ; mouse button released |
||
180 | je .dmup |
||
181 | |||
182 | cmp dword [edi + 4], 'CNOP' ; no operation |
||
183 | je .next |
||
184 | |||
185 | cmp dword [edi + 4], 'CIAK' ; resolution changed? |
||
186 | je .ciak |
||
187 | |||
4376 | hidnplayr | 188 | ; cmp dword [edi + 4], 'DMWM' ; mouse wheel moved |
189 | ; je .dmwm |
||
190 | |||
191 | cmp dword [edi + 4], 'DKDN' ; Key pressed |
||
192 | je .dkdn |
||
193 | |||
194 | cmp dword [edi + 4], 'DKUP' ; key up |
||
195 | je .dkup |
||
196 | |||
197 | cmp dword [edi + 4], 'DKRP' ; key auto repeat |
||
198 | je .dkrp |
||
199 | |||
3545 | hidnplayr | 200 | push str3 |
201 | call [con_write_asciiz] |
||
202 | |||
203 | mov byte[edi+8],0 |
||
204 | add edi, 4 |
||
205 | push edi |
||
206 | call [con_write_asciiz] |
||
207 | |||
208 | push newline |
||
209 | call [con_write_asciiz] |
||
210 | |||
211 | .next: |
||
212 | pop edi eax |
||
213 | |||
214 | mov ecx, dword [edi] |
||
215 | bswap ecx |
||
216 | add ecx, 4 |
||
217 | sub eax, ecx |
||
218 | jle mainloop |
||
219 | add edi, ecx |
||
220 | jmp .command |
||
221 | |||
222 | |||
223 | .qinf: |
||
224 | mcall 14 ; get screen info |
||
225 | add eax, 0x00010001 |
||
226 | bswap eax |
||
227 | mov dword [screeninfo.size], eax |
||
228 | mcall send, [socketnum], screeninfo, screeninfo.length, 0 ; send client name |
||
229 | jmp .next |
||
230 | |||
231 | |||
232 | .calv: |
||
4376 | hidnplayr | 233 | mcall send, [socketnum], calv, calv.length, 0 ; keepalive |
234 | |||
3545 | hidnplayr | 235 | jmp .next |
236 | |||
237 | |||
238 | .cinn: |
||
239 | mov edx, [edi + 8] |
||
240 | bswap edx |
||
241 | mcall 18, 19, 4 |
||
242 | ; ignore sequence number and modify key mask for now |
||
243 | push str6 |
||
244 | call [con_write_asciiz] |
||
245 | jmp .next |
||
246 | |||
247 | .dclp: |
||
248 | |||
249 | jmp .next |
||
250 | |||
251 | .dmmv: |
||
252 | mov edx, [edi + 8] |
||
253 | bswap edx |
||
254 | mcall 18, 19, 4 |
||
255 | mcall send, [socketnum], cnop, cnop.length, 0 ; reply with NOP |
||
256 | jmp .next |
||
257 | |||
258 | .cout: |
||
4376 | hidnplayr | 259 | ; TODO: hide cursor |
260 | push str8 |
||
261 | call [con_write_asciiz] |
||
3545 | hidnplayr | 262 | jmp .next |
263 | |||
264 | .dmdn: |
||
265 | movzx eax, byte [edi + 8] |
||
266 | or [mousestate], eax |
||
267 | mcall 18, 19, 5, [mousestate] |
||
268 | mcall send, [socketnum], cnop, cnop.length, 0 ; reply with NOP |
||
269 | jmp .next |
||
270 | |||
271 | .dmup: |
||
272 | movzx eax, byte [edi + 8] |
||
273 | not eax |
||
274 | and [mousestate], eax |
||
275 | mcall 18, 19, 5, [mousestate] |
||
276 | mcall send, [socketnum], cnop, cnop.length, 0 ; reply with NOP |
||
277 | jmp .next |
||
278 | |||
279 | .ciak: |
||
280 | jmp .next |
||
281 | |||
4376 | hidnplayr | 282 | ; .dmwm: |
283 | ; jmp .next |
||
284 | |||
285 | .dkdn: |
||
286 | movzx edx, word[edi + 8 + 4] ; key button |
||
287 | rol dx, 8 |
||
288 | mcall 72, 1, 2 ; send key |
||
289 | jmp .next |
||
290 | |||
291 | .dkrp: |
||
292 | movzx edx, word[edi + 8 + 6] |
||
293 | rol dx, 8 |
||
294 | mcall 72, 1, 2 ; send key |
||
295 | jmp .next |
||
296 | |||
297 | .dkup: |
||
298 | movzx edx, word[edi + 8 + 4] |
||
299 | rol dx, 8 |
||
300 | add edx, 128 |
||
301 | mcall 72, 1, 2 ; send key |
||
302 | |||
303 | jmp .next |
||
304 | |||
3545 | hidnplayr | 305 | error: |
306 | push str_err |
||
307 | call [con_write_asciiz] |
||
308 | |||
4376 | hidnplayr | 309 | wait_for_key: |
3618 | hidnplayr | 310 | call [con_getch2] |
311 | |||
312 | mcall close, [socketnum] |
||
313 | |||
3545 | hidnplayr | 314 | push 1 |
315 | call [con_exit] |
||
316 | exit: |
||
317 | |||
318 | mcall -1 |
||
319 | |||
320 | |||
321 | wait_for_data: |
||
322 | mcall recv, [socketnum], buffer_ptr, BUFFERSIZE, 0 |
||
4376 | hidnplayr | 323 | inc eax |
324 | jz error |
||
325 | dec eax |
||
326 | jz closed |
||
3545 | hidnplayr | 327 | |
328 | cmp eax, 8 |
||
3618 | hidnplayr | 329 | jb wait_for_data ; FIXME |
3545 | hidnplayr | 330 | |
331 | ret |
||
332 | |||
4376 | hidnplayr | 333 | closed: |
3545 | hidnplayr | 334 | |
4376 | hidnplayr | 335 | push str_cls |
336 | call [con_write_asciiz] |
||
3545 | hidnplayr | 337 | |
4376 | hidnplayr | 338 | jmp wait_for_key |
339 | |||
340 | |||
341 | |||
3545 | hidnplayr | 342 | ; data |
343 | title db 'Synergy client',0 |
||
3618 | hidnplayr | 344 | str0 db 'Welcome to the software KM switch for KolibriOS.',10,10,0 |
3545 | hidnplayr | 345 | str1 db 'Connecting to: ',0 |
3618 | hidnplayr | 346 | str7 db 'Connected!',10,0 |
347 | str2 db 10,'Handshake received',10,0 |
||
3545 | hidnplayr | 348 | str3 db 'Unsupported command: ',0 |
3618 | hidnplayr | 349 | newline db 10,0 |
4376 | hidnplayr | 350 | str6 db 'Entering screen',10,0 |
351 | str8 db 'Leaving screen',10,0 |
||
3618 | hidnplayr | 352 | str_err db 'Uh-Oh.. some error occured !',10,'Press any key to quit.',0 |
4376 | hidnplayr | 353 | str_cls db 'Server disconnected',10,0 |
3545 | hidnplayr | 354 | |
355 | screeninfo: |
||
356 | dd (screeninfo.length - 4) shl 24 |
||
357 | db 'DINF' |
||
358 | dw 0 ; coordinate of leftmost pixel |
||
359 | dw 0 ; coordiante of topmost pixel |
||
360 | .size: |
||
361 | dw 0 ; width |
||
362 | dw 0 ; height |
||
363 | |||
364 | dw 0 ; size of warp zone |
||
365 | |||
366 | dw 0xb88b ; x position of the mouse on the secondary screen (no idea what it means) |
||
367 | dw 0xbcfb ; y position of the mouse on the secondary screen |
||
368 | .length = $ - screeninfo |
||
369 | |||
370 | calv: |
||
371 | dd (4) shl 24 |
||
372 | db 'CALV' |
||
373 | .length = $ - calv + 8 ; also send cnop |
||
374 | |||
375 | cnop: |
||
376 | dd (4) shl 24 |
||
377 | db 'CNOP' |
||
378 | .length = $ - cnop |
||
379 | |||
380 | mousestate dd 0 |
||
381 | |||
382 | |||
383 | sockaddr1: |
||
384 | dw AF_INET4 |
||
385 | .port dw 0 |
||
4376 | hidnplayr | 386 | .ip dd 0 |
3545 | hidnplayr | 387 | rb 10 |
388 | |||
389 | filename db '.ini', 0 |
||
390 | str_local db 'local', 0 |
||
391 | str_name db 'name', 0 |
||
392 | str_remote db 'remote', 0 |
||
393 | str_port db 'port', 0 |
||
394 | str_ip db 'ip', 0 |
||
395 | |||
396 | ; import |
||
397 | align 16 |
||
398 | @IMPORT: |
||
399 | |||
400 | library console, 'console.obj',\ |
||
401 | network, 'network.obj',\ |
||
402 | libini, 'libini.obj' |
||
403 | |||
404 | import network,\ |
||
3618 | hidnplayr | 405 | getaddrinfo, 'getaddrinfo' |
3545 | hidnplayr | 406 | |
407 | import console, \ |
||
408 | con_start, 'START',\ |
||
409 | con_init, 'con_init',\ |
||
410 | con_write_asciiz, 'con_write_asciiz',\ |
||
411 | con_exit, 'con_exit',\ |
||
412 | con_gets, 'con_gets',\ |
||
413 | con_cls, 'con_cls',\ |
||
414 | con_getch2, 'con_getch2',\ |
||
415 | con_set_cursor_pos, 'con_set_cursor_pos' |
||
416 | |||
417 | import libini,\ |
||
418 | ini.get_str, 'ini_get_str',\ |
||
419 | ini.get_int, 'ini_get_int' |
||
420 | |||
421 | align 4 |
||
422 | i_end: |
||
423 | socketnum dd ? |
||
424 | buffer_ptr rb BUFFERSIZE |
||
425 | path rb 4096 ; stack |
||
426 | mem: |