Subversion Repositories Kolibri OS

Rev

Rev 2854 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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