Subversion Repositories Kolibri OS

Rev

Rev 3618 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                                 ;;
  3. ;; Copyright (C) KolibriOS team 2010-2013. All rights reserved.    ;;
  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.  
  17. BUFFERSIZE      = 1024
  18. DEFAULTPORT     = 24800
  19.  
  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.  
  32. include '../../macros.inc'
  33. purge mov,add,sub
  34. include '../../proc32.inc'
  35. include '../../dll.inc'
  36.  
  37. include '../../network.inc'
  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.  
  67.         push    str0
  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.  
  92. ; resolve name
  93.         push    esp             ; reserve stack place
  94.         push    esp             ; ptr to result
  95.         push    0               ; addrinfo hints
  96.         push    0               ; servname
  97.         push    buffer_ptr      ; hostname
  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]
  106.         mov     [sockaddr1.ip], eax
  107.  
  108.         mcall   connect, [socketnum], sockaddr1, 18
  109.  
  110.         push    str7
  111.         call    [con_write_asciiz]
  112.  
  113.         mcall   40, EVM_STACK
  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.  
  275. ;        call    [con_gets]
  276.  
  277.         call    [con_getch2]
  278.  
  279.         mcall   close, [socketnum]
  280.  
  281.         push    1
  282.         call    [con_exit]
  283. exit:
  284.  
  285.         mcall   -1
  286.  
  287.  
  288. wait_for_data:
  289.         mcall   recv, [socketnum], buffer_ptr, BUFFERSIZE, 0
  290.         cmp     eax, -1
  291.         je      wait_for_data
  292.  
  293.         cmp     eax, 8
  294.         jb      wait_for_data   ; FIXME
  295.  
  296.         ret
  297.  
  298.  
  299.  
  300. ; data
  301. title   db      'Synergy client',0
  302. str0    db      'Welcome to the software KM switch for KolibriOS.',10,10,0
  303. str1    db      'Connecting to: ',0
  304. str7    db      'Connected!',10,0
  305. str2    db      10,'Handshake received',10,0
  306. str3    db      'Unsupported command: ',0
  307. newline db      10,0
  308. str4    db      'mouse moved',10,0
  309. str5    db      'mouse buttons changed',10,0
  310. str6    db      'Enter screen',10,0
  311. str_err db      'Uh-Oh.. some error occured !',10,'Press any key to quit.',0
  312.  
  313. screeninfo:
  314.         dd (screeninfo.length - 4) shl 24
  315.         db 'DINF'
  316.         dw 0    ; coordinate of leftmost pixel
  317.         dw 0    ; coordiante of topmost pixel
  318.   .size:
  319.         dw 0    ; width
  320.         dw 0    ; height
  321.  
  322.         dw 0    ; size of warp zone
  323.  
  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
  326.   .length = $ - screeninfo
  327.  
  328. calv:
  329.         dd (4) shl 24
  330.         db 'CALV'
  331.   .length = $ - calv + 8 ; also send cnop
  332.  
  333. cnop:
  334.         dd (4) shl 24
  335.         db 'CNOP'
  336.   .length = $ - cnop
  337.  
  338. mousestate      dd 0
  339.  
  340.  
  341. sockaddr1:
  342.         dw AF_INET4
  343. .port   dw 0
  344. .ip     dd 192 + 168 shl 8 + 1 shl 16 + 115 shl 24
  345.         rb 10
  346.  
  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
  353.  
  354. ; import
  355. align 16
  356. @IMPORT:
  357.  
  358. library console,        'console.obj',\
  359.         network,        'network.obj',\
  360.         libini,         'libini.obj'
  361.  
  362. import  network,\
  363.         getaddrinfo,    'getaddrinfo'
  364.  
  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'
  374.  
  375. import  libini,\
  376.         ini.get_str,    'ini_get_str',\
  377.         ini.get_int,    'ini_get_int'
  378.  
  379. align   4
  380. i_end:
  381. socketnum       dd ?
  382. buffer_ptr      rb BUFFERSIZE
  383. path            rb 4096    ; stack
  384. mem: