Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
264 hidnplayr 1
;
2
;
3
; VNC Client for kolibrios by hidnplayr
4
;
5
;
6
; WORK IN PROGRESS...
7
;
8
; FEEL FREE TO CONTRIBUTE !
9
;
10
; hidnplayr@gmail.com
11
;
12
 
13
use32
14
 
15
    org     0x0
16
 
17
    db	   'MENUET01'	     ; 8 byte id
18
    dd	   0x01 	     ; header version
19
    dd	   START	     ; start of code
20
    dd	   I_END	     ; size of image
21
    dd	   IM_END	     ; memory for app
22
    dd	   IM_END	     ; esp
23
    dd	   0x0 , 0x0	     ; I_Param , I_Icon
24
 
25
__DEBUG__ equ 1
26
__DEBUG_LEVEL__ equ 1
27
 
28
STRLEN = 64	 ; password and server max length
29
xpos = 4	 ; coordinates of image
30
ypos = 22	 ;
31
 
32
TIMEOUT = 60	 ; timeout in seconds
33
BUFFER	= 1500	 ; Buffer size for DNS
34
 
485 heavyiron 35
include '..\..\macros.inc'
264 hidnplayr 36
include 'fdo.inc'
37
include 'ETH.INC'
38
include 'logon.inc'
39
include 'raw.inc'
40
include 'copyrect.inc'
41
include 'thread.inc'
42
 
43
START:				       ; start of execution
44
 
45
    call    red_logon
46
 
47
    mov     eax,40		       ; Report events
48
    mov     ebx,00000000b	       ; Only Stack
485 heavyiron 49
    mcall
264 hidnplayr 50
 
51
    mov     eax,67		       ; resize the window (hide it)
52
    xor     ebx,ebx
53
    mov     ecx,ebx
54
    mov     edx,ebx
55
    mov     esi,ebx
485 heavyiron 56
    mcall
264 hidnplayr 57
 
58
    mov     eax,51
59
    mov     ebx,1
60
    mov     ecx,thread_start
61
    mov     edx,thread_stack
485 heavyiron 62
    mcall
264 hidnplayr 63
 
64
    DEBUGF 1,'Thread created: %u\n',eax
65
 
66
   @@:
67
    mov     eax,5
68
    mov     ebx,10
485 heavyiron 69
    mcall
264 hidnplayr 70
 
71
    cmp     byte[thread_ready],0
72
    je	    @r
73
 
74
    mov     eax,40		   ; report events
75
    mov     ebx,100111b 	   ; mouse, button, key, redraw
485 heavyiron 76
    mcall
264 hidnplayr 77
 
78
    mov     eax,67		   ; resize the window
79
    mov     ebx,10
80
    mov     ecx,10
81
    mov     edx,dword[framebuffer]
82
    bswap   edx
83
    movzx   esi,dx
84
    shr     edx,16
85
    add     edx,2*xpos
86
    add     esi,ypos+xpos
485 heavyiron 87
    mcall
264 hidnplayr 88
 
89
  mainloop:
90
    eth.socket_status [socket],eax
91
    cmp     al,TCB_CLOSE_WAIT
92
    je	    close
93
 
94
    mov     eax,23		   ; wait for event with timeout
95
    mov     ebx,50		   ; 0,5 s
485 heavyiron 96
    mcall
264 hidnplayr 97
 
98
    cmp     eax,1
99
    je	    redraw
100
    cmp     eax,2		   ; key
101
    je	    key
102
    cmp     eax,3		   ; button
103
    je	    button
104
    cmp     eax,6		   ; mouse
105
    je	    mouse
106
 
107
    call    drawbuffer
108
 
109
    jmp     mainloop
110
 
111
  key:
112
    DEBUGF 1,'Sending key event\n'
113
 
114
    mov     eax,2
485 heavyiron 115
    mcall
264 hidnplayr 116
    mov     byte[keyevent.key+3],ah
117
 
118
    eth.write_tcp [socket],8,keyevent
119
 
120
    jmp     mainloop
121
 
122
  mouse:
123
    DEBUGF 1,'Sending mouse event\n'
124
 
125
    mov     eax,37
126
    mov     ebx,1
485 heavyiron 127
    mcall
264 hidnplayr 128
 
129
    sub     eax,xpos*65536+ypos
130
    bswap   eax
131
    mov     word[pointerevent.x],ax
132
    shr     eax,16
133
    mov     word[pointerevent.y],ax
134
 
135
    mov     eax,37
136
    mov     ebx,2
485 heavyiron 137
    mcall
264 hidnplayr 138
 
139
    test    al,00000010b	    ; test if right button was pressed  (bit 1 in kolibri)
140
    jz	    @f
141
    add     al,00000010b	    ; in RFB protocol it is bit 2, so if we add bit 2 again, we'll get bit 3 and bit 1 will remain the same
142
   @@:
143
 
144
    mov     byte[pointerevent.mask],al
145
 
146
    eth.write_tcp [socket],6,pointerevent
147
 
148
    jmp     mainloop
149
 
150
  redraw:
151
 
152
    DEBUGF 1,'Drawing window\n'
153
 
154
    mov     eax,12
155
    mov     ebx,1
485 heavyiron 156
    mcall
264 hidnplayr 157
 
158
    mov     eax,0		      ; draw window
159
    mov     ebx,dword[framebuffer]
160
    bswap   ebx
161
    movzx   ecx,bx
162
    shr     ebx,16
163
    add     ebx,2*xpos
164
    add     ecx,ypos+xpos
165
    mov     edx,0x03ffffff
485 heavyiron 166
    mcall
264 hidnplayr 167
 
168
    mov     eax,4		      ; label
169
    mov     ebx,9*65536+8
170
    mov     ecx,0x10ffffff
171
    mov     edx,name
172
    mov     esi,[name_length]
173
    bswap   esi
485 heavyiron 174
    mcall
264 hidnplayr 175
 
176
    call    drawbuffer
177
 
178
    mov     eax,12
179
    mov     ebx,2
485 heavyiron 180
    mcall
264 hidnplayr 181
 
182
    jmp     mainloop
183
 
184
  drawbuffer:
185
 
186
    mov     eax,7
187
    mov     ebx,framebuffer_data
188
    mov     ecx,dword[screen]
189
    mov     edx,xpos*65536+ypos
485 heavyiron 190
    mcall
264 hidnplayr 191
 
192
    ret
193
 
194
 
195
  button:			  ; button
196
    mov     eax,17		  ; get id
485 heavyiron 197
    mcall
264 hidnplayr 198
 
199
  close:
200
    call    read_data
201
;    eth.close_tcp [socket]             ; We're done, close the socket ;;; BUG WHEN CLOSING SOCKET !!
202
    DEBUGF 1,'Socket closed\n'
203
 
204
    mov     eax,-1
485 heavyiron 205
    mcall
264 hidnplayr 206
 
207
    no_rfb:
208
    DEBUGF 1,'This is no vnc server!\n'
209
    jmp     close
210
 
211
    invalid_security:
212
    DEBUGF 1,'Security error: %s\n',receive_buffer+5
213
    jmp     close
214
 
215
 
216
; DATA AREA
217
 
218
include_debug_strings	 ; ALWAYS present in data section
219
 
220
handshake	   db 'RFB 003.003',0x0a
221
shared		   db 0
222
beep		   db 0x85,0x25,0x85,0x40,0
223
 
224
pixel_format32	   db 0       ; setPixelformat
225
		   rb 3       ; padding
226
.bpp		   db 32      ; bits per pixel
227
.depth		   db 32      ; depth
228
.big_endian	   db 0       ; big-endian flag
229
.true_color	   db 1       ; true-colour flag
230
.red_max	   db 0,255   ; red-max
231
.green_max	   db 0,255   ; green-max
232
.blue_max	   db 0,255   ; blue-max
233
.red_shif	   db 0       ; red-shift
234
.green_shift	   db 8       ; green-shift
235
.blue_shift	   db 16      ; blue-shift
236
		   rb 3       ; padding
237
 
238
pixel_format16	   db 0       ; setPixelformat
239
		   rb 3       ; padding
240
.bpp		   db 16      ; bits per pixel
241
.depth		   db 15      ; depth
242
.big_endian	   db 0       ; big-endian flag
243
.true_color	   db 1       ; true-colour flag
244
.red_max	   db 0,31    ; red-max
245
.green_max	   db 0,31    ; green-max
246
.blue_max	   db 0,31    ; blue-max
247
.red_shif	   db 0       ; red-shift
248
.green_shift	   db 5       ; green-shift
249
.blue_shift	   db 10      ; blue-shift
250
		   rb 3       ; padding
251
 
252
pixel_format8	   db 0       ; setPixelformat
253
		   rb 3       ; padding
254
.bpp		   db 8       ; bits per pixel
255
.depth		   db 6       ; depth
256
.big_endian	   db 0       ; big-endian flag
257
.true_color	   db 1       ; true-colour flag
258
.red_max	   db 0,3     ; red-max
259
.green_max	   db 0,3     ; green-max
260
.blue_max	   db 0,3     ; blue-max
261
.red_shif	   db 0       ; red-shift
262
.green_shift	   db 2       ; green-shift
263
.blue_shift	   db 4       ; blue-shift
264
		   rb 3       ; padding
265
 
266
encodings	   db 2       ; setEncodings
267
		   rb 1       ; padding
268
		   db 1,0     ; number of encodings
269
		   db 0,0,0,0 ; raw encoding        (DWORD, Big endian order)
270
		   db 1,0,0,0 ; Copyrect encoding
271
 
272
fbur		   db 3       ; frame buffer update request
273
.inc		   db 0       ; incremental
274
.x		   dw 0
275
.y		   dw 0
276
.width		   dw 0
277
.height 	   dw 0
278
 
279
keyevent	   db 4       ; keyevent
280
.down		   db 0       ; down-flag
281
		   dw 0       ; padding
282
.key		   dd 0       ; key
283
 
284
pointerevent	   db 5       ; pointerevent
285
.mask		   db 0       ; button-mask
286
.x		   dw 0       ; x-position
287
.y		   dw 0       ; y-position
288
 
289
I_END:
290
 
291
framebuffer:
292
.width		   dw ?
293
.height 	   dw ?
294
pixelformat:
295
.bpp		   db ?
296
.depth		   db ?
297
.big_endian	   db ?
298
.true_color	   db ?
299
.red_max	   dw ?
300
.green_max	   dw ?
301
.blue_max	   dw ?
302
.red_shift	   db ?
303
.green_shift	   db ?
304
.blue_shift	   db ?
305
.padding	   rb 3
306
name_length	   dd ?
307
name		   rb 256
308
 
309
server_ip	   dd 0
310
server_port	   dd 0
311
socket		   dd 0
312
datapointer	   dd 0
313
 
314
frame:
315
.width		   dw 0
316
.height 	   dw 0
317
.x		   dw 0
318
.y		   dw 0
319
 
320
screen:
321
.height 	   dw 0
322
.width		   dw 0
323
 
324
thread_ready	   db 0
325
 
326
dnsMsg:
327
receive_buffer	   rb 5*1024*1024 ; 5 mb buffer for received data (incoming frbupdate etc)
328
framebuffer_data   rb 1024*768*3  ; framebuffer
329
 
330
thread_stack	   rb 0x1000
331
 
332
IM_END:
333