Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. thread_start:
  3.  
  4.         DEBUGF  1, 'I am the thread!\n'
  5.  
  6.         mcall   40, 1 shl 7
  7.  
  8. ; resolve name
  9.         push    esp     ; reserve stack place
  10.         invoke  getaddrinfo, first, 0, 0, esp
  11.         pop     esi
  12. ; test for error
  13.         test    eax, eax
  14.         jnz     exit
  15.  
  16.         mov     eax, [esi+addrinfo.ai_addr]
  17.         mov     eax, [eax+sockaddr_in.sin_addr]
  18.         mov     [sockaddr1.ip], eax
  19.  
  20. ;        DEBUGF  1, 'Connecting to %u.%u.%u.%u:%u\n', \
  21. ;                [server_ip]:1, [server_ip+1]:1, \
  22. ;                [server_ip+2]:1, [server_ip+3]:1, \
  23. ;                [server_port]:2
  24.  
  25.         mcall   socket, AF_INET4, SOCK_STREAM, 0
  26.         mov     [socketnum], eax
  27.         mcall   connect, [socketnum], sockaddr1, 18
  28.  
  29.         call    wait_for_data
  30.  
  31.         cmp     dword [receive_buffer], 'RFB '
  32.         jne     no_rfb
  33.         DEBUGF  1, 'received: %s\n', receive_buffer
  34.         mcall   send, [socketnum], handshake, 12, 0
  35.         DEBUGF  1, 'Sending handshake: protocol version\n'
  36.  
  37.         call    wait_for_data
  38.  
  39.         cmp     dword [receive_buffer], 0x00000000
  40.         je      invalid_security
  41.  
  42.         cmp     dword [receive_buffer], 0x01000000
  43.         je      no_security
  44.  
  45.         cmp     dword [receive_buffer], 0x02000000
  46.         je      vnc_security
  47.  
  48.         jmp     exit
  49.  
  50. vnc_security:
  51.         mov     byte[mode], 1
  52.         call    red_logon
  53.  
  54. no_security:
  55.         mcall   send, [socketnum], shared, 1, 0
  56.         DEBUGF  1, 'Sending handshake: shared session?\n'
  57.  
  58.         mcall   23, 100*TIMEOUT
  59.  
  60.         call    wait_for_data       ; now the server should send init message
  61.  
  62.         DEBUGF  1, 'Serverinit: bpp: %u depth: %u bigendian: %u truecolor: %u\n', \
  63.                 [receive_buffer+framebuffer.pixelformat.bpp]:1, \
  64.                 [receive_buffer+framebuffer.pixelformat.depth]:1, \
  65.                 [receive_buffer+framebuffer.pixelformat.big_endian]:1, \
  66.                 [receive_buffer+framebuffer.pixelformat.true_color]:1
  67.  
  68.         mov     eax, dword [receive_buffer]
  69.         mov     dword [fbur.width], eax
  70.         bswap   eax
  71.         mov     dword [screen], eax
  72.  
  73.         mcall   send, [socketnum], pixel_format8, 20, 0
  74.         DEBUGF  1, 'Sending pixel format\n'
  75.         call    read_data
  76.  
  77. ;    eth.write_tcp [socket],8,encodings
  78. ;    DEBUGF 1,'Sending encoding info\n'
  79. ;    call    read_data
  80.  
  81.         mov     byte [thread_ready], 1
  82.  
  83. request_rfb:
  84.         mov     [fbur.inc], 2
  85.         mcall   send, [socketnum], fbur, 10, 0
  86.  
  87. thread_loop:
  88.         mcall   23, 100
  89.  
  90.         call    read_data              ; Read the data into the buffer
  91.  
  92. ;        cmp     eax, 2
  93. ;        jb      mainloop
  94.  
  95.         DEBUGF 1,'Data received, %u bytes\n', eax
  96.  
  97.         cmp     byte [receive_buffer],0
  98.         je      framebufferupdate
  99.  
  100.         cmp     byte [receive_buffer],1
  101.         je      setcolourmapentries
  102.  
  103.         cmp     byte [receive_buffer],2
  104.         je      bell
  105.  
  106.         cmp     byte [receive_buffer],3
  107.         je      servercuttext
  108.  
  109.         jmp     thread_loop
  110.  
  111. align 4
  112. framebufferupdate:
  113.  
  114.         mov     ax, word [receive_buffer+2]
  115.         xchg    al, ah
  116.         mov     di, ax
  117.         DEBUGF  1, 'Framebufferupdate: %u frames\n', di
  118.         mov     esi, receive_buffer+4
  119.         jmp     rectangle_loop
  120.  
  121.  
  122. next_rectangle:
  123.         call    drawbuffer
  124.  
  125.         dec     di
  126.         test    di, di
  127.         jz      request_rfb
  128.  
  129. rectangle_loop:
  130.  
  131.         mov     edx, [esi]
  132.         bswap   edx
  133.         mov     ebx, edx
  134.         shr     edx, 16
  135.         mov     [frame.x], dx
  136.         mov     [frame.y], bx
  137.         add     esi, 4
  138.         mov     ecx, [esi]
  139.         bswap   ecx
  140.         mov     eax, ecx
  141.         shr     ecx, 16
  142.         mov     [frame.width], cx
  143.         mov     [frame.height], ax
  144.         add     esi, 4
  145.         mov     eax, [esi]
  146.         add     esi, 4
  147.  
  148.         mov     ebx, esi
  149.         sub     ebx, receive_buffer+12
  150.         DEBUGF  1, 'frame: width=%u height=%u x=%u y=%u offset:%u encoding:',\
  151.                 [frame.width]:2, [frame.height]:2, [frame.x]:2, [frame.y]:2, ebx
  152.  
  153.         cmp     eax, 0
  154.         je      encoding_raw
  155. ;        cmp     eax, 1
  156. ;        je      encoding_copyrect
  157.         cmp     eax, 2
  158.         je      encoding_RRE
  159.         cmp     eax, 5
  160.         je      encoding_hextile
  161.         cmp     eax, 16
  162.         je      encoding_ZRLE
  163.  
  164.         mov     ebx, esi
  165.         sub     ebx, receive_buffer+8
  166.         DEBUGF  1, '\nunknown encoding: %u (offset %u)\n', eax, ebx
  167.         jmp     bell
  168.         jmp     thread_loop
  169.  
  170. encoding_RRE:
  171.  
  172.         DEBUGF  1, 'RRE\n'
  173.  
  174.         jmp     next_rectangle
  175.  
  176. encoding_hextile:
  177.  
  178.         DEBUGF  1, 'hextile\n'
  179.  
  180.         jmp     next_rectangle
  181.  
  182. encoding_ZRLE:
  183.  
  184.         DEBUGF  1, 'ZRLE\n'
  185.  
  186.         jmp     next_rectangle
  187.  
  188. setcolourmapentries:
  189.  
  190.         DEBUGF  1, 'Server sent SetColourMapEntries message\n'
  191.  
  192.         jmp     thread_loop
  193.  
  194.  
  195. bell:
  196.         mcall   55, 55, , , beep
  197.  
  198.         jmp     thread_loop
  199.  
  200.  
  201. servercuttext:
  202.  
  203.         DEBUGF  1, 'Server cut text\n'
  204.  
  205.         jmp     thread_loop
  206.  
  207.  
  208. read_data:
  209.  
  210.         mov     [datapointer], receive_buffer
  211.   .loop:
  212.         mcall   23, 100*TIMEOUT
  213.         mcall   recv, [socketnum], [datapointer], 4096, 0
  214.         cmp     eax, -1
  215.         je      .done
  216.  
  217.         add     [datapointer], eax
  218.  
  219.         cmp     eax, 4096
  220.         je      .loop
  221.  
  222.   .done:
  223.         mov     eax, [datapointer]
  224.         sub     eax, receive_buffer
  225.         ret
  226.  
  227.  
  228.  
  229. wait_for_data:
  230.  
  231.         mcall   23, 500
  232.         mcall   recv, [socketnum], receive_buffer, 4096, 0
  233.         cmp     eax, -1
  234.         je      wait_for_data
  235.         test    eax, eax
  236.         jz      wait_for_data
  237.  
  238.         ret
  239.  
  240.