Subversion Repositories Kolibri OS

Rev

Rev 3618 | Rev 4376 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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