Subversion Repositories Kolibri OS

Rev

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