/[rdesktop]/sourceforge.net/trunk/rdesktop/uiports/svgawin.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/uiports/svgawin.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 735 - (show annotations)
Fri Jul 9 17:27:56 2004 UTC (19 years, 11 months ago) by jsorg71
File MIME type: text/plain
File size: 45423 byte(s)
added svgawin.c

1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 User interface services - SVGA lib
4 Copyright (C) Jay Sorg 2004
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "../rdesktop.h"
22
23 #include <vga.h>
24 #include <vgakeyboard.h>
25 #include <vgamouse.h>
26 #include <vgagl.h>
27
28 #include <unistd.h> // gethostname
29 #include <pwd.h> // getpwuid
30 #include <stdarg.h> // va_list va_start va_end
31
32
33 extern int g_tcp_port_rdp;
34 int g_use_rdp5 = 0;
35 char g_hostname[16] = "";
36 char g_username[64] = "";
37 int g_height = 600;
38 int g_width = 800;
39 int g_server_bpp = 8;
40 int g_encryption = 1;
41 int g_desktop_save =1;
42 int g_bitmap_cache = 1;
43 int g_bitmap_cache_persist_enable = False;
44 int g_bitmap_cache_precache = True;
45 int g_bitmap_compression = 1;
46 int g_rdp5_performanceflags = 0;
47 int g_console_session = 0;
48 int g_keylayout = 0x409; /* Defaults to US keyboard layout */
49
50 /* hack globals */
51 int g_argc = 0;
52 char** g_argv = 0;
53 int UpAndRunning = 0;
54 int g_sock = 0;
55 int deactivated = 0;
56 uint32 ext_disc_reason = 0;
57 char g_servername[128] = "";
58 static uint32* colmap = 0;
59 static uint8* desk_save = 0;
60 static int g_server_Bpp = 1;
61
62 // this is non null if vgalib has non accel functions available
63 // reading from video memory is sooo slow
64 static uint8* sdata = 0;
65 static int g_save_mem = 0; // for video memory use eg sdata == 0
66
67 // video acceleration
68 static int use_accel = 1;
69 static int has_fill_box = 0;
70 static int has_screen_copy = 0;
71 static int has_put_image = 0;
72
73 // clip
74 int clip_startx;
75 int clip_starty;
76 int clip_endx;
77 int clip_endy;
78
79 // mouse
80 uint8 mouse_under[32 * 32 * 4]; // save area under mouse
81 int mousex = 0;
82 int mousey = 0;
83 int mouseb = 0;
84
85 // mouse info
86 typedef struct
87 {
88 uint8 andmask[32 * 32];
89 uint8 xormask[32 * 32];
90 int x;
91 int y;
92 int w;
93 int h;
94 } tcursor;
95
96 // mouse global
97 static tcursor mcursor;
98
99 static int g_draw_mouse = 1;
100
101 // bitmap
102 typedef struct
103 {
104 int width;
105 int height;
106 uint8* data;
107 uint8 Bpp;
108 } bitmap;
109
110 typedef struct
111 {
112 int x;
113 int y;
114 int cx;
115 int cy;
116 void* prev;
117 void* next;
118 } myrect;
119
120 myrect* head_rect = 0;
121
122 //*****************************************************************************
123 // do a raster op
124 int rop(int rop, int src, int dst)
125 {
126 switch (rop)
127 {
128 case 0x0: return 0;
129 case 0x1: return ~(src | dst);
130 case 0x2: return (~src) & dst;
131 case 0x3: return ~src;
132 case 0x4: return src & (~dst);
133 case 0x5: return ~(dst);
134 case 0x6: return src ^ dst;
135 case 0x7: return ~(src & dst);
136 case 0x8: return src & dst;
137 case 0x9: return ~(src) ^ dst;
138 case 0xa: return dst;
139 case 0xb: return (~src) | dst;
140 case 0xc: return src;
141 case 0xd: return src | (~dst);
142 case 0xe: return src | dst;
143 case 0xf: return ~0;
144 }
145 return dst;
146 }
147
148 //*****************************************************************************
149 // get a screen pixel
150 int get_pixel(int x, int y)
151 {
152 if (x >= 0 && x < g_width && y >= 0 && y < g_height)
153 {
154 if (sdata != 0)
155 {
156 if (g_server_Bpp == 1)
157 return sdata[y * g_width + x];
158 else if (g_server_Bpp == 2)
159 return ((uint16*)sdata)[y * g_width + x];
160 else
161 return 0;
162 }
163 else
164 return vga_getpixel(x, y);
165 }
166 else
167 return 0;
168 }
169
170 //*****************************************************************************
171 // set a screen pixel
172 void set_pixel(int x, int y, int pixel, int op)
173 {
174 if (x >= clip_startx && x < clip_endx && y >= clip_starty && y < clip_endy)
175 {
176 if (x >= 0 && x < g_width && y >= 0 && y < g_height)
177 {
178 if (op == 0x0)
179 pixel = 0;
180 else if (op == 0xf)
181 pixel = -1;
182 else if (op != 0xc)
183 pixel = rop(op, pixel, get_pixel(x, y));
184 if (sdata != 0)
185 {
186 if (g_server_Bpp == 1)
187 sdata[y * g_width + x] = pixel;
188 else if (g_server_Bpp == 2)
189 ((uint16*)sdata)[y * g_width + x] = pixel;
190 }
191 else
192 {
193 vga_setcolor(pixel);
194 vga_drawpixel(x, y);
195 }
196 }
197 }
198 }
199
200 //*****************************************************************************
201 // get a pixel from a bitmap
202 int get_pixel2(int x, int y, uint8* data, int width, int bpp)
203 {
204 if (bpp == 8)
205 return data[y * width + x];
206 else if (bpp == 16)
207 return ((uint16*)data)[y * width + x];
208 else
209 return 0;
210 }
211
212 //*****************************************************************************
213 // set a pixel in a bitmap
214 void set_pixel2(int x, int y, int pixel, uint8* data, int width, int bpp)
215 {
216 if (bpp == 8)
217 data[y * width + x] = pixel;
218 else if (bpp == 16)
219 ((uint16*)data)[y * width + x] = pixel;
220 }
221
222 //*****************************************************************************
223 // get a pointer into a bitmap
224 uint8* get_ptr(int x, int y, uint8* data, int width, int bpp)
225 {
226 if (bpp == 8)
227 return data + (y * width + x);
228 else if (bpp == 16)
229 return data + (y * width + x) * 2;
230 else
231 return 0;
232 }
233
234 //*****************************************************************************
235 // check if a certain pixel is set in a bitmap
236 BOOL is_pixel_on(uint8* data, int x, int y, int width, int bpp)
237 {
238 int start;
239 int shift;
240
241 if (bpp == 1)
242 {
243 width = (width + 7) / 8;
244 start = (y * width) + x / 8;
245 shift = x % 8;
246 return (data[start] & (0x80 >> shift)) != 0;
247 }
248 else if (bpp == 8)
249 {
250 return data[y * width + x] != 0;
251 }
252 else if (bpp == 24)
253 {
254 return data[(y * 3) * width + (x * 3)] != 0 &&
255 data[(y * 3) * width + (x * 3) + 1] != 0 &&
256 data[(y * 3) * width + (x * 3) + 2] != 0;
257 }
258 else
259 return False;
260 }
261
262 //*****************************************************************************
263 void set_pixel_on(uint8* data, int x, int y, int width, int bpp, int pixel)
264 {
265 if (bpp == 8)
266 {
267 data[y * width + x] = pixel;
268 }
269 }
270
271 /*****************************************************************************/
272 int warp_coords(int* x, int* y, int* cx, int* cy, int* srcx, int* srcy)
273 {
274 int dx;
275 int dy;
276 // int lx = *x, ly = *y, lcx = *cx, lcy = *cy;
277
278 if (clip_startx > *x)
279 dx = clip_startx - *x;
280 else
281 dx = 0;
282 if (clip_starty > *y)
283 dy = clip_starty - *y;
284 else
285 dy = 0;
286 if (*x + *cx > clip_endx)
287 *cx = (*cx - ((*x + *cx) - clip_endx)) /*+ 1*/;
288 if (*y + *cy > clip_endy)
289 *cy = (*cy - ((*y + *cy) - clip_endy)) /*+ 1*/;
290 *cx = *cx - dx;
291 *cy = *cy - dy;
292 if (*cx <= 0)
293 return False;
294 if (*cy <= 0)
295 return False;
296 *x = *x + dx;
297 *y = *y + dy;
298 if (srcx != NULL)
299 *srcx = *srcx + dx;
300 if (srcy != NULL)
301 *srcy = *srcy + dy;
302
303 // if (*x != lx || *y != ly || *cx != lcx || *cy != lcy)
304 // printf("%d %d %d %d to %d %d %d %d\n", lx, ly, lcx, lcy, *x, *y, *cx, *cy);
305
306 return True;
307 }
308
309 //*****************************************************************************
310 void copy_mem(uint8* d, uint8* s, int n)
311 {
312 while (n & (~7))
313 {
314 *(d++) = *(s++);
315 *(d++) = *(s++);
316 *(d++) = *(s++);
317 *(d++) = *(s++);
318 *(d++) = *(s++);
319 *(d++) = *(s++);
320 *(d++) = *(s++);
321 *(d++) = *(s++);
322 n = n - 8;
323 }
324 while (n > 0)
325 {
326 *(d++) = *(s++);
327 n--;
328 }
329 }
330
331 //*****************************************************************************
332 void copy_memb(uint8* d, uint8* s, int n)
333 {
334 d = (d + n) - 1;
335 s = (s + n) - 1;
336 while (n & (~7))
337 {
338 *(d--) = *(s--);
339 *(d--) = *(s--);
340 *(d--) = *(s--);
341 *(d--) = *(s--);
342 *(d--) = *(s--);
343 *(d--) = *(s--);
344 *(d--) = *(s--);
345 *(d--) = *(s--);
346 n = n - 8;
347 }
348 while (n > 0)
349 {
350 *(d--) = *(s--);
351 n--;
352 }
353 }
354
355 //*****************************************************************************
356 // all in pixel except line_size is in bytes
357 void accel_draw_box(int x, int y, int cx, int cy, uint8* data, int line_size)
358 {
359 int i;
360 uint8* s;
361 uint8* d;
362
363 if (sdata != 0)
364 {
365 s = data;
366 d = get_ptr(x, y, sdata, g_width, g_server_bpp);
367 for (i = 0; i < cy; i++)
368 {
369 copy_mem(d, s, cx * g_server_Bpp);
370 s = s + line_size;
371 d = d + g_width * g_server_Bpp;
372 }
373 }
374 else if (has_put_image && line_size == cx * g_server_Bpp)
375 {
376 vga_accel(ACCEL_PUTIMAGE, x, y, cx, cy, data);
377 }
378 else
379 {
380 s = data;
381 for (i = 0; i < cy; i++)
382 {
383 vga_drawscansegment(s, x, y + i, cx * g_server_Bpp);
384 s = s + line_size;
385 }
386 }
387 }
388
389 //*****************************************************************************
390 void accel_fill_rect(int x, int y, int cx, int cy, int color)
391 {
392 int i;
393 uint8* temp;
394 uint8* d;
395
396 if (sdata != 0)
397 {
398 temp = xmalloc(cx * g_server_Bpp);
399 if (g_server_Bpp == 1)
400 for (i = 0; i < cx; i++)
401 temp[i] = color;
402 else if (g_server_Bpp == 2)
403 for (i = 0; i < cx; i++)
404 ((uint16*)temp)[i] = color;
405 d = get_ptr(x, y, sdata, g_width, g_server_bpp);
406 for (i = 0; i < cy; i++)
407 {
408 copy_mem(d, temp, cx * g_server_Bpp);
409 d = d + g_width * g_server_Bpp;
410 }
411 xfree(temp);
412 }
413 else if (has_fill_box)
414 {
415 vga_accel(ACCEL_SETFGCOLOR, color);
416 vga_accel(ACCEL_FILLBOX, x, y, cx, cy);
417 }
418 else
419 {
420 temp = xmalloc(cx * g_server_Bpp);
421 if (g_server_Bpp == 1)
422 for (i = 0; i < cx; i++)
423 temp[i] = color;
424 else if (g_server_Bpp == 2)
425 for (i = 0; i < cx; i++)
426 ((uint16*)temp)[i] = color;
427 for (i = 0; i < cy; i++)
428 vga_drawscansegment(temp, x, y + i, cx * g_server_Bpp);
429 xfree(temp);
430 }
431 }
432
433 //*****************************************************************************
434 void accel_screen_copy(int x, int y, int cx, int cy, int srcx, int srcy)
435 {
436 uint8* temp;
437 uint8* s;
438 uint8* d;
439 int i;
440
441 if (sdata != 0)
442 {
443 if (srcy < y)
444 { // bottom to top
445 s = get_ptr(srcx, (srcy + cy) - 1, sdata, g_width, g_server_bpp);
446 d = get_ptr(x, (y + cy) - 1, sdata, g_width, g_server_bpp);
447 for (i = 0; i < cy; i++) // copy down
448 {
449 copy_mem(d, s, cx * g_server_Bpp);
450 s = s - g_width * g_server_Bpp;
451 d = d - g_width * g_server_Bpp;
452 }
453 }
454 else if (srcy > y || srcx > x) // copy up or left
455 { // top to bottom
456 s = get_ptr(srcx, srcy, sdata, g_width, g_server_bpp);
457 d = get_ptr(x, y, sdata, g_width, g_server_bpp);
458 for (i = 0; i < cy; i++)
459 {
460 copy_mem(d, s, cx * g_server_Bpp);
461 s = s + g_width * g_server_Bpp;
462 d = d + g_width * g_server_Bpp;
463 }
464 }
465 else // copy straight right
466 {
467 s = get_ptr(srcx, srcy, sdata, g_width, g_server_bpp);
468 d = get_ptr(x, y, sdata, g_width, g_server_bpp);
469 for (i = 0; i < cy; i++)
470 {
471 copy_memb(d, s, cx * g_server_Bpp);
472 s = s + g_width * g_server_Bpp;
473 d = d + g_width * g_server_Bpp;
474 }
475 }
476 }
477 else if (has_screen_copy)
478 {
479 vga_accel(ACCEL_SCREENCOPY, srcx, srcy, x, y, cx, cy);
480 }
481 else
482 {
483 // slow
484 temp = (uint8*)xmalloc(cx * cy * g_server_Bpp);
485 for (i = 0; i < cy; i++)
486 vga_getscansegment(get_ptr(0, i, temp, cx, g_server_bpp), srcx, srcy + i, cx * g_server_Bpp);
487 for (i = 0; i < cy; i++)
488 vga_drawscansegment(get_ptr(0, i, temp, cx, g_server_bpp), x, y + i, cx * g_server_Bpp);
489 xfree(temp);
490 }
491 }
492
493 //*****************************************************************************
494 // return bool
495 int contains_mouse(int x, int y, int cx, int cy)
496 {
497 if (mousex + 32 >= x &&
498 mousey + 32 >= y &&
499 mousex <= x + cx &&
500 mousey <= y + cy)
501 return 1;
502 else
503 return 0;
504 }
505
506 //*****************************************************************************
507 void fill_rect(int x, int y, int cx, int cy, int colour, int opcode)
508 {
509 int i;
510 int j;
511
512 if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
513 {
514 if (opcode == 0xc)
515 accel_fill_rect(x, y, cx, cy, colour);
516 else if (opcode == 0xf)
517 accel_fill_rect(x, y, cx, cy, -1);
518 else if (opcode == 0x0)
519 accel_fill_rect(x, y, cx, cy, 0);
520 else
521 {
522 for (i = 0; i < cy; i++)
523 for (j = 0; j < cx; j++)
524 set_pixel(x + j, y + i, colour, opcode);
525 }
526 }
527 }
528
529 //*****************************************************************************
530 void get_rect(int x, int y, int cx, int cy, uint8* p)
531 {
532 int i;
533
534 if (x < 0)
535 {
536 cx = cx + x;
537 x = 0;
538 }
539 if (y < 0)
540 {
541 cy = cy + y;
542 y = 0;
543 }
544 if (sdata != 0)
545 {
546 for (i = 0; i < cy; i++)
547 {
548 copy_mem(p, get_ptr(x, y + i, sdata, g_width, g_server_bpp), cx * g_server_Bpp);
549 p = p + cx * g_server_Bpp;
550 }
551 }
552 else
553 {
554 for (i = 0; i < cy; i++)
555 {
556 vga_getscansegment(p, x, y + i, cx * g_server_Bpp);
557 p = p + cx * g_server_Bpp;
558 }
559 }
560 }
561
562 /*****************************************************************************/
563 // return true if r1 is contained by r2
564 int is_contained_by(myrect* r1, myrect* r2)
565 {
566 if (r1->x >= r2->x &&
567 r1->y >= r2->y &&
568 r1->x + r1->cx <= r2->x + r2->cx &&
569 r1->y + r1->cy <= r2->y + r2->cy)
570 return 1;
571 else
572 return 0;
573 }
574
575 /*****************************************************************************/
576 void draw_cursor_under(int ox, int oy)
577 {
578 int i;
579 int j;
580 int k;
581 uint8* ptr;
582 int len;
583
584 if (ox < 0)
585 k = -ox;
586 else
587 k = 0;
588 j = g_width - ox;
589 if (j > 32)
590 j = 32;
591 if (j > 0)
592 {
593 for (i = 0; i < 32; i++)
594 {
595 ptr = get_ptr(k, i, mouse_under, 32, g_server_bpp);
596 len = (j - k) * g_server_Bpp;
597 if (ox + k >= 0 && oy + i >= 0 && ox + k < g_width && oy + i < g_height)
598 vga_drawscansegment(ptr, ox + k, oy + i, len);
599 }
600 }
601 g_draw_mouse = 1;
602 }
603
604 /*****************************************************************************/
605 void draw_cursor(void)
606 {
607 int i;
608 int j;
609 int k;
610 int pixel;
611 uint8 mouse_a[32 * 32 * 4];
612 uint8* ptr;
613 int len;
614
615 if (!g_draw_mouse)
616 return;
617 memset(mouse_under, 0, sizeof(mouse_under));
618 for (i = 0; i < 32; i++)
619 {
620 for (j = 0; j < 32; j++)
621 {
622 pixel = get_pixel(mousex + j, mousey + i);
623 set_pixel2(j, i, pixel, mouse_under, 32, g_server_bpp);
624 if (mcursor.andmask[i * 32 + j] == 0)
625 k = 0;
626 else
627 k = ~0;
628 pixel = rop(0x8, k, pixel);
629 if (mcursor.xormask[i * 32 + j] == 0)
630 k = 0;
631 else
632 k = ~0;
633 pixel = rop(0x6, k, pixel);
634 set_pixel2(j, i, pixel, mouse_a, 32, g_server_bpp);
635 }
636 }
637 if (mousex < 0)
638 k = -mousex;
639 else
640 k = 0;
641 j = g_width - mousex;
642 if (j > 32)
643 j = 32;
644 if (j > 0)
645 {
646 for (i = mousey; i < mousey + 32; i++)
647 if (i < g_height && i >= 0)
648 {
649 ptr = get_ptr(k, i - mousey, mouse_a, 32, g_server_bpp);
650 len = (j - k) * g_server_Bpp;
651 vga_drawscansegment(ptr, mousex + k, i, len);
652 }
653 }
654 g_draw_mouse = 0;
655 }
656
657 /*****************************************************************************/
658 // add a rect to cache
659 void cache_rect(int x, int y, int cx, int cy, int do_warp)
660 {
661 myrect* rect;
662 myrect* walk_rect;
663
664 if (sdata == 0)
665 {
666 draw_cursor();
667 return;
668 }
669 if (do_warp)
670 if (!warp_coords(&x, &y, &cx, &cy, NULL, NULL))
671 return;
672 rect = (myrect*)xmalloc(sizeof(myrect));
673 rect->x = x;
674 rect->y = y;
675 rect->cx = cx;
676 rect->cy = cy;
677 rect->next = 0;
678 rect->prev = 0;
679 if (head_rect == 0)
680 head_rect = rect;
681 else
682 {
683 walk_rect = 0;
684 do
685 {
686 if (walk_rect == 0)
687 walk_rect = head_rect;
688 else
689 walk_rect = walk_rect->next;
690 if (is_contained_by(rect, walk_rect))
691 {
692 xfree(rect);
693 return;
694 }
695 }
696 while (walk_rect->next != 0);
697 walk_rect->next = rect;
698 rect->prev = walk_rect;
699 }
700 }
701
702 //*****************************************************************************
703 void draw_cache_rects(void)
704 {
705 int i;
706 myrect* rect;
707 myrect* rect1;
708 uint8* p;
709
710 // draw all the rects
711 rect = head_rect;
712 while (rect != 0)
713 {
714 p = get_ptr(rect->x, rect->y, sdata, g_width, g_server_bpp);
715 for (i = 0; i < rect->cy; i++)
716 {
717 vga_drawscansegment(p, rect->x, rect->y + i, rect->cx * g_server_Bpp);
718 p = p + g_width * g_server_Bpp;
719 }
720 rect1 = rect;
721 rect = rect->next;
722 xfree(rect1);
723 }
724 head_rect = 0;
725 }
726
727 /*****************************************************************************/
728 void key_event(int scancode, int pressed)
729 {
730 int rdpkey;
731 int ext;
732
733 if (!UpAndRunning)
734 return;
735 rdpkey = scancode;
736 ext = 0;
737 switch (scancode)
738 {
739 case SCANCODE_CURSORBLOCKUP: rdpkey = 0xc8; ext = KBD_FLAG_EXT; break; // up arrow
740 case SCANCODE_CURSORBLOCKDOWN: rdpkey = 0xd0; ext = KBD_FLAG_EXT; break; // down arrow
741 case SCANCODE_CURSORBLOCKRIGHT: rdpkey = 0xcd; ext = KBD_FLAG_EXT; break; // right arrow
742 case SCANCODE_CURSORBLOCKLEFT: rdpkey = 0xcb; ext = KBD_FLAG_EXT; break; // left arrow
743 case SCANCODE_PAGEDOWN: rdpkey = 0xd1; ext = KBD_FLAG_EXT; break; // page down
744 case SCANCODE_PAGEUP: rdpkey = 0xc9; ext = KBD_FLAG_EXT; break; // page up
745 case SCANCODE_HOME: rdpkey = 0xc7; ext = KBD_FLAG_EXT; break; // home
746 case SCANCODE_END: rdpkey = 0xcf; ext = KBD_FLAG_EXT; break; // end
747 case SCANCODE_INSERT: rdpkey = 0xd2; ext = KBD_FLAG_EXT; break; // insert
748 case SCANCODE_REMOVE: rdpkey = 0xd3; ext = KBD_FLAG_EXT; break; // delete
749 case SCANCODE_KEYPADDIVIDE: rdpkey = 0x35; break; // /
750 case SCANCODE_KEYPADENTER: rdpkey = 0x1c; break; // enter
751 case SCANCODE_RIGHTCONTROL: rdpkey = 0x1d; break; // right ctrl
752 case SCANCODE_RIGHTALT: rdpkey = 0x38; break; // right alt
753 case SCANCODE_LEFTWIN: rdpkey = 0; break; // left win
754 case SCANCODE_RIGHTWIN: rdpkey = 0; break; // right win
755 case 127: rdpkey = 0; break; // menu key
756 case SCANCODE_PRINTSCREEN: rdpkey = 0; break; // print screen
757 case SCANCODE_BREAK: rdpkey = 0; break; // break
758 case SCANCODE_SCROLLLOCK: rdpkey = 0; break; // scroll lock
759 case 112: // mouse down
760 {
761 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON4,
762 mouse_getx(), mouse_gety());
763 return;
764 }
765 case 113: // mouse up
766 {
767 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON5,
768 mouse_getx(), mouse_gety());
769 return;
770 }
771 }
772 // printf("%d %d\n", scancode, pressed);
773 if (pressed)
774 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS | ext, rdpkey, 0);
775 else
776 rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE | ext, rdpkey, 0);
777
778 }
779
780 /*****************************************************************************/
781 int ui_init(void)
782 {
783 vga_init();
784 memset(&mcursor, 0, sizeof(tcursor));
785 desk_save = (uint8*)xmalloc(0x38400 * g_server_Bpp);
786 return 1;
787 }
788
789 /*****************************************************************************/
790 void ui_deinit(void)
791 {
792 xfree(desk_save);
793 }
794
795 /*****************************************************************************/
796 int ui_create_window(void)
797 {
798 int vgamode;
799 int i;
800
801 vgamode = G800x600x256;
802 if (g_width == 640 && g_height == 480)
803 {
804 if (g_server_Bpp == 1)
805 vgamode = G640x480x256;
806 else if (g_server_Bpp == 2)
807 vgamode = G640x480x64K;
808 }
809 else if (g_width == 800 && g_height == 600)
810 {
811 if (g_server_Bpp == 1)
812 vgamode = G800x600x256;
813 else if (g_server_Bpp == 2)
814 vgamode = G800x600x64K;
815 }
816 else if (g_width == 1024 && g_height == 768)
817 {
818 if (g_server_Bpp == 1)
819 vgamode = G1024x768x256;
820 else if (g_server_Bpp == 2)
821 vgamode = G1024x768x64K;
822 }
823 else
824 {
825 error("Invalid width / height");
826 return 0;
827 }
828 ui_reset_clip();
829 if (!vga_hasmode(vgamode))
830 {
831 error("Graphics unavailable");
832 return 0;
833 }
834 vga_setmousesupport(1);
835 mouse_setposition(g_width / 2, g_height / 2);
836 vga_setmode(vgamode);
837 if (keyboard_init())
838 {
839 error("Keyboard unavailable");
840 return 0;
841 }
842 keyboard_seteventhandler(key_event);
843 if (use_accel)
844 {
845 i = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_ACCEL);
846 if (i & ACCELFLAG_PUTIMAGE)
847 has_put_image = 1;
848 if (i & ACCELFLAG_SCREENCOPY)
849 has_screen_copy = 1;
850 if (i & ACCELFLAG_FILLBOX)
851 has_fill_box = 1;
852 printf("accel %d\n", i);
853 }
854 if (!has_screen_copy && !g_save_mem)
855 sdata = xmalloc(g_width * g_height * g_server_Bpp);
856 return 1;
857 }
858
859 /*****************************************************************************/
860 void ui_destroy_window(void)
861 {
862 keyboard_close(); /* Don't forget this! */
863 vga_setmode(TEXT);
864 if (sdata != 0)
865 xfree(sdata);
866 }
867
868 /*****************************************************************************/
869 void process_mouse(void)
870 {
871 int ox = mousex;
872 int oy = mousey;
873 int ob = mouseb;
874
875 if (!UpAndRunning)
876 return;
877 mousex = mouse_getx() - mcursor.x;
878 mousey = mouse_gety() - mcursor.y;
879 mouseb = mouse_getbutton();
880
881 if (mouseb != ob) // button
882 {
883 // right button
884 if (mouseb & 1)
885 if (!(ob & 1))
886 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
887 mousex + mcursor.x, mousey + mcursor.y);
888 if (ob & 1)
889 if (!(mouseb & 1))
890 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2,
891 mousex + mcursor.x, mousey + mcursor.y);
892 // middle button
893 if (mouseb & 2)
894 if (!(ob & 2))
895 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3,
896 mousex + mcursor.x, mousey + mcursor.y);
897 if (ob & 2)
898 if (!(mouseb & 2))
899 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3,
900 mousex + mcursor.x, mousey + mcursor.y);
901 // left button
902 if (mouseb & 4)
903 if (!(ob & 4))
904 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
905 mousex + mcursor.x, mousey + mcursor.y);
906 if (ob & 4)
907 if (!(mouseb & 4))
908 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
909 mousex + mcursor.x, mousey + mcursor.y);
910 }
911 if (mousex != ox || mousey != oy) // movement
912 {
913 rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE,
914 mousex + mcursor.x, mousey + mcursor.y);
915 draw_cursor_under(ox, oy);
916 draw_cursor();
917 }
918 }
919
920 /*****************************************************************************/
921 void process_keyboard(void)
922 {
923 if (!UpAndRunning)
924 return;
925 }
926
927 /*****************************************************************************/
928 BOOL ui_main_loop(void)
929 {
930 int sel;
931 fd_set rfds;
932
933 if (!rdp_connect(g_servername, RDP_LOGON_NORMAL, "", "", "", ""))
934 return False;
935 UpAndRunning = 1;
936 FD_ZERO(&rfds);
937 FD_SET(g_sock, &rfds);
938 sel = vga_waitevent(3, &rfds, NULL, NULL, NULL);
939 while (sel >= 0)
940 {
941 if (sel & 1) /* mouse */
942 {
943 process_mouse();
944 }
945 else if (sel & 2) /* keyboard */
946 {
947 process_keyboard();
948 }
949 else
950 {
951 if (!rdp_loop(&deactivated, &ext_disc_reason))
952 return True; /* ok */
953 }
954 FD_ZERO(&rfds);
955 FD_SET(g_sock, &rfds);
956 sel = vga_waitevent(3, &rfds, NULL, NULL, NULL);
957 }
958 return True;
959 }
960
961 /*****************************************************************************/
962 void ui_bell(void)
963 {
964 }
965
966 /*****************************************************************************/
967 int ui_select(int in)
968 {
969 g_sock = in;
970 return 1;
971 }
972
973 /*****************************************************************************/
974 void* ui_create_glyph(int width, int height, uint8* data)
975 {
976 int i, j;
977 uint8* glyph_data;
978 bitmap* the_glyph;
979
980 glyph_data = (uint8*)xmalloc(width * height);
981 the_glyph = (bitmap*)xmalloc(sizeof(bitmap));
982 the_glyph->width = width;
983 the_glyph->height = height;
984 the_glyph->data = glyph_data;
985 memset(glyph_data, 0, width * height);
986 for (i = 0; i < height; i++)
987 for (j = 0; j < width; j++)
988 if (is_pixel_on(data, j, i, width, 1))
989 set_pixel_on(glyph_data, j, i, width, 8, 255);
990 return the_glyph;
991 }
992
993 /*****************************************************************************/
994 void ui_destroy_glyph(void* glyph)
995 {
996 bitmap* the_glyph;
997
998 the_glyph = (bitmap*)glyph;
999 if (the_glyph != NULL)
1000 {
1001 if (the_glyph->data != NULL)
1002 xfree(the_glyph->data);
1003 xfree(the_glyph);
1004 }
1005 }
1006
1007 /*****************************************************************************/
1008 void ui_destroy_bitmap(void* bmp)
1009 {
1010 bitmap* b;
1011
1012 b = (bitmap*)bmp;
1013 xfree(b->data);
1014 xfree(b);
1015 }
1016
1017 /*****************************************************************************/
1018 void ui_reset_clip(void)
1019 {
1020 clip_startx = 0;
1021 clip_starty = 0;
1022 clip_endx = g_width;
1023 clip_endy = g_height;
1024 }
1025
1026 /*****************************************************************************/
1027 void ui_set_clip(int x, int y, int cx, int cy)
1028 {
1029 clip_startx = x;
1030 clip_starty = y;
1031 clip_endx = x + cx;
1032 clip_endy = y + cy;
1033 }
1034
1035 /*****************************************************************************/
1036 void* ui_create_colourmap(COLOURMAP * colours)
1037 {
1038 int i = 0;
1039 int n = colours->ncolours;
1040 COLOURENTRY* c = colours->colours;
1041 int* cmap = (int*)xmalloc(3 * 256 * sizeof (int));
1042 if (n > 256)
1043 n = 256;
1044 bzero(cmap, 256 * 3 * sizeof (int));
1045 for (i = 0; i < (3 * n); c++)
1046 {
1047 cmap[i++] = (c->red) >> 2;
1048 cmap[i++] = (c->green) >> 2;
1049 cmap[i++] = (c->blue) >> 2;
1050 }
1051 return cmap;
1052 }
1053
1054 /*****************************************************************************/
1055 void ui_destroy_colourmap(HCOLOURMAP map)
1056 {
1057 if (colmap == map)
1058 colmap = 0;
1059 xfree(map);
1060 }
1061
1062 /*****************************************************************************/
1063 void ui_set_colourmap(void* map)
1064 {
1065 if (colmap != 0)
1066 xfree(colmap);
1067 vga_setpalvec(0, 256, (int*)map);
1068 colmap = map;
1069 }
1070
1071 /*****************************************************************************/
1072 HBITMAP ui_create_bitmap(int width, int height, uint8* data)
1073 {
1074 bitmap* b;
1075
1076 b = (bitmap*)xmalloc(sizeof(bitmap));
1077 b->data = (uint8*)xmalloc(width * height * g_server_Bpp);
1078 b->width = width;
1079 b->height = height;
1080 b->Bpp = g_server_Bpp;
1081 copy_mem(b->data, data, width * height * g_server_Bpp);
1082 return (void*)b;
1083 }
1084
1085 //*****************************************************************************
1086 void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)
1087 {
1088 bitmap* the_glyph;
1089 int i, j;
1090
1091 the_glyph = (bitmap*)glyph;
1092 if (the_glyph == NULL)
1093 return;
1094 for (i = 0; i < the_glyph->height; i++)
1095 for (j = 0; j < the_glyph->width; j++)
1096 if (is_pixel_on(the_glyph->data, j, i, the_glyph->width, 8))
1097 set_pixel(x + j, y + i, fgcolour, 0xc);
1098 }
1099
1100 #define DO_GLYPH(ttext,idx) \
1101 {\
1102 glyph = cache_get_font (font, ttext[idx]);\
1103 if (!(flags & TEXT2_IMPLICIT_X))\
1104 {\
1105 xyoffset = ttext[++idx];\
1106 if ((xyoffset & 0x80))\
1107 {\
1108 if (flags & TEXT2_VERTICAL) \
1109 y += ttext[idx+1] | (ttext[idx+2] << 8);\
1110 else\
1111 x += ttext[idx+1] | (ttext[idx+2] << 8);\
1112 idx += 2;\
1113 }\
1114 else\
1115 {\
1116 if (flags & TEXT2_VERTICAL) \
1117 y += xyoffset;\
1118 else\
1119 x += xyoffset;\
1120 }\
1121 }\
1122 if (glyph != NULL)\
1123 {\
1124 draw_glyph (x + glyph->offset, y + glyph->baseline, glyph->pixmap, fgcolour);\
1125 if (flags & TEXT2_IMPLICIT_X)\
1126 x += glyph->width;\
1127 }\
1128 }
1129
1130 /*****************************************************************************/
1131 void ui_draw_text(uint8 font, uint8 flags, int mixmode,
1132 int x, int y,
1133 int clipx, int clipy, int clipcx, int clipcy,
1134 int boxx, int boxy, int boxcx, int boxcy,
1135 int bgcolour, int fgcolour, uint8* text, uint8 length)
1136 {
1137 int i;
1138 int j;
1139 int xyoffset;
1140 DATABLOB* entry;
1141 FONTGLYPH* glyph;
1142
1143 if (boxcx > 1)
1144 {
1145 if (contains_mouse(boxx, boxy, boxcx, boxcy))
1146 draw_cursor_under(mousex, mousey);
1147 fill_rect(boxx, boxy, boxcx, boxcy, bgcolour, 0xc);
1148 }
1149 else
1150 {
1151 if (contains_mouse(clipx, clipy, clipcx, clipcy))
1152 draw_cursor_under(mousex, mousey);
1153 if (mixmode == MIX_OPAQUE)
1154 fill_rect(clipx, clipy, clipcx, clipcy, bgcolour, 0xc);
1155 }
1156
1157 /* Paint text, character by character */
1158 for (i = 0; i < length;)
1159 {
1160 switch (text[i])
1161 {
1162 case 0xff:
1163 if (i + 2 < length)
1164 cache_put_text(text[i + 1], text, text[i + 2]);
1165 else
1166 {
1167 error("this shouldn't be happening\n");
1168 exit(1);
1169 }
1170 /* this will move pointer from start to first character after FF command */
1171 length -= i + 3;
1172 text = &(text[i + 3]);
1173 i = 0;
1174 break;
1175
1176 case 0xfe:
1177 entry = cache_get_text(text[i + 1]);
1178 if (entry != NULL)
1179 {
1180 if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X)))
1181 {
1182 if (flags & TEXT2_VERTICAL)
1183 y += text[i + 2];
1184 else
1185 x += text[i + 2];
1186 }
1187 for (j = 0; j < entry->size; j++)
1188 DO_GLYPH(((uint8 *) (entry->data)), j);
1189 }
1190 if (i + 2 < length)
1191 i += 3;
1192 else
1193 i += 2;
1194 length -= i;
1195 /* this will move pointer from start to first character after FE command */
1196 text = &(text[i]);
1197 i = 0;
1198 break;
1199
1200 default:
1201 DO_GLYPH(text, i);
1202 i++;
1203 break;
1204 }
1205 }
1206 if (boxcx > 1)
1207 cache_rect(boxx, boxy, boxcx, boxcy, True);
1208 else
1209 cache_rect(clipx, clipy, clipcx, clipcy, True);
1210 }
1211
1212 //*****************************************************************************
1213 // Bresenham's line drawing algorithm
1214 void ui_line(uint8 opcode, int startx, int starty, int endx,
1215 int endy, PEN* pen)
1216 {
1217 int dx;
1218 int dy;
1219 int incx;
1220 int incy;
1221 int dpr;
1222 int dpru;
1223 int p;
1224 int left;
1225 int top;
1226 int right;
1227 int bottom;
1228
1229 if (startx > endx)
1230 {
1231 dx = startx - endx;
1232 incx = -1;
1233 left = endx;
1234 right = startx;
1235 }
1236 else
1237 {
1238 dx = endx - startx;
1239 incx = 1;
1240 left = startx;
1241 right = endx;
1242 }
1243 if (starty > endy)
1244 {
1245 dy = starty - endy;
1246 incy = -1;
1247 top = endy;
1248 bottom = starty;
1249 }
1250 else
1251 {
1252 dy = endy - starty;
1253 incy = 1;
1254 top = starty;
1255 bottom = endy;
1256 }
1257 if (contains_mouse(left, top, (right - left) + 1, (bottom - top) + 1))
1258 draw_cursor_under(mousex, mousey);
1259 if (dx >= dy)
1260 {
1261 dpr = dy << 1;
1262 dpru = dpr - (dx << 1);
1263 p = dpr - dx;
1264 for (; dx >= 0; dx--)
1265 {
1266 set_pixel(startx, starty, pen->colour, opcode);
1267 if (p > 0)
1268 {
1269 startx += incx;
1270 starty += incy;
1271 p += dpru;
1272 }
1273 else
1274 {
1275 startx += incx;
1276 p += dpr;
1277 }
1278 }
1279 }
1280 else
1281 {
1282 dpr = dx << 1;
1283 dpru = dpr - (dy << 1);
1284 p = dpr - dy;
1285 for (; dy >= 0; dy--)
1286 {
1287 set_pixel(startx, starty, pen->colour, opcode);
1288 if (p > 0)
1289 {
1290 startx += incx;
1291 starty += incy;
1292 p += dpru;
1293 }
1294 else
1295 {
1296 starty += incy;
1297 p += dpr;
1298 }
1299 }
1300 }
1301 cache_rect(left, top, (right - left) + 1, (bottom - top) + 1, True);
1302 }
1303
1304 /*****************************************************************************/
1305 void ui_triblt(uint8 opcode, int x, int y, int cx, int cy,
1306 HBITMAP src, int srcx, int srcy,
1307 BRUSH* brush, int bgcolour, int fgcolour)
1308 {
1309 // non used
1310 }
1311
1312 /*****************************************************************************/
1313 void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,
1314 HBITMAP src, int srcx, int srcy)
1315 {
1316 bitmap* b;
1317 int i;
1318 int j;
1319 int pixel;
1320
1321 if (warp_coords(&x, &y, &cx, &cy, &srcx, &srcy))
1322 {
1323 if (contains_mouse(x, y, cx, cy))
1324 draw_cursor_under(mousex, mousey);
1325 b = (bitmap*)src;
1326 if (opcode == 0xc)
1327 accel_draw_box(x, y, cx, cy, get_ptr(srcx, srcy, b->data, b->width, g_server_bpp),
1328 b->width * g_server_Bpp);
1329 else
1330 {
1331 for (i = 0; i < cy; i++)
1332 {
1333 for (j = 0; j < cx; j++)
1334 {
1335 pixel = get_pixel2(srcx + j, srcy + i, b->data, b->width, g_server_bpp);
1336 set_pixel(x + j, y + i, pixel, opcode);
1337 }
1338 }
1339 }
1340 cache_rect(x, y, cx, cy, False);
1341 }
1342 }
1343
1344 /*****************************************************************************/
1345 void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
1346 {
1347 uint8* p;
1348
1349 if (offset > 0x38400)
1350 offset = 0;
1351 if (offset + cx * cy > 0x38400)
1352 return;
1353 p = desk_save + offset * g_server_Bpp;
1354 ui_paint_bitmap(x, y, cx, cy, cx, cy, p);
1355 }
1356
1357 /*****************************************************************************/
1358 void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
1359 {
1360 uint8* p;
1361
1362 if (offset > 0x38400)
1363 offset = 0;
1364 if (offset + cx * cy > 0x38400)
1365 return;
1366 if (contains_mouse(x, y, cx, cy))
1367 draw_cursor_under(mousex, mousey);
1368 p = desk_save + offset * g_server_Bpp;
1369 get_rect(x, y, cx, cy, p);
1370 }
1371
1372 /*****************************************************************************/
1373 void ui_rect(int x, int y, int cx, int cy, int colour)
1374 {
1375 if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
1376 {
1377 if (contains_mouse(x, y, cx, cy))
1378 draw_cursor_under(mousex, mousey);
1379 accel_fill_rect(x, y, cx, cy, colour);
1380 cache_rect(x, y, cx, cy, False);
1381 }
1382 }
1383
1384 /*****************************************************************************/
1385 void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,
1386 int srcx, int srcy)
1387 {
1388 int i;
1389 int j;
1390 uint8* temp;
1391
1392 if (x == srcx && y == srcy)
1393 return;
1394 if (warp_coords(&x, &y, &cx, &cy, &srcx, &srcy))
1395 {
1396 if (contains_mouse(x, y, cx, cy) || contains_mouse(srcx, srcy, cx, cy))
1397 draw_cursor_under(mousex, mousey);
1398 if (opcode == 0xc) /* copy */
1399 accel_screen_copy(x, y, cx, cy, srcx, srcy);
1400 else
1401 {
1402 temp = (uint8*)xmalloc(cx * cy * g_server_Bpp);
1403 for (i = 0; i < cy; i++)
1404 for (j = 0; j < cx; j++)
1405 set_pixel2(j, i, get_pixel(srcx + j, srcy + i), temp, cx, g_server_bpp);
1406 for (i = 0; i < cy; i++)
1407 for (j = 0; j < cx; j++)
1408 set_pixel(x + j, y + i, get_pixel2(j, i, temp, cx, g_server_bpp), opcode);
1409 xfree(temp);
1410 }
1411 cache_rect(x, y, cx, cy, False);
1412 draw_cache_rects(); // draw them all so screen is not jumpy
1413 }
1414 }
1415
1416 /*****************************************************************************/
1417 void ui_patblt(uint8 opcode, int x, int y, int cx, int cy,
1418 BRUSH * brush, int bgcolour, int fgcolour)
1419 {
1420 int i;
1421 int j;
1422 uint8 ipattern[8];
1423
1424 if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
1425 {
1426 if (contains_mouse(x, y, cx, cy))
1427 draw_cursor_under(mousex, mousey);
1428 switch (brush->style)
1429 {
1430 case 0:
1431 fill_rect(x, y, cx, cy, fgcolour, opcode);
1432 break;
1433 case 3:
1434 for (i = 0; i < 8; i++)
1435 ipattern[i] = ~brush->pattern[7 - i];
1436 for (i = 0; i < cy; i++)
1437 for (j = 0; j < cx; j++)
1438 if (is_pixel_on(ipattern, (x + j + brush->xorigin) % 8,
1439 (y + i + brush->yorigin) % 8, 8, 1))
1440 set_pixel(x + j, y + i, fgcolour, opcode);
1441 else
1442 set_pixel(x + j, y + i, bgcolour, opcode);
1443 break;
1444 }
1445 cache_rect(x, y, cx, cy, False);
1446 }
1447 }
1448
1449 /*****************************************************************************/
1450 void ui_destblt(uint8 opcode, int x, int y, int cx, int cy)
1451 {
1452 if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
1453 {
1454 if (contains_mouse(x, y, cx, cy))
1455 draw_cursor_under(mousex, mousey);
1456 fill_rect(x, y, cx, cy, -1, opcode);
1457 cache_rect(x, y, cx, cy, False);
1458 }
1459 }
1460
1461 /*****************************************************************************/
1462 void ui_move_pointer(int x, int y)
1463 {
1464 }
1465
1466 /*****************************************************************************/
1467 void ui_set_null_cursor(void)
1468 {
1469 draw_cursor_under(mousex, mousey);
1470 mousex = mousex - mcursor.x;
1471 mousey = mousey - mcursor.y;
1472 memset(&mcursor, 0, sizeof(mcursor));
1473 memset(mcursor.andmask, 255, sizeof(mcursor.andmask));
1474 memset(mcursor.xormask, 0, sizeof(mcursor.xormask));
1475 draw_cursor();
1476 }
1477
1478 /*****************************************************************************/
1479 void ui_paint_bitmap(int x, int y, int cx, int cy,
1480 int width, int height, uint8* data)
1481 {
1482 if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
1483 {
1484 if (contains_mouse(x, y, cx, cy))
1485 draw_cursor_under(mousex, mousey);
1486 accel_draw_box(x, y, cx, cy, data, width * g_server_Bpp);
1487 cache_rect(x, y, cx, cy, False);
1488 }
1489 }
1490
1491 /*****************************************************************************/
1492 void* ui_create_cursor(unsigned int x, unsigned int y,
1493 int width, int height,
1494 uint8* andmask, uint8* xormask)
1495 {
1496 tcursor* c;
1497 int i;
1498 int j;
1499
1500 c = (tcursor*)xmalloc(sizeof(tcursor));
1501 memset(c, 0, sizeof(tcursor));
1502 c->w = width;
1503 c->h = height;
1504 c->x = x;
1505 c->y = y;
1506 for (i = 0; i < 32; i++)
1507 {
1508 for (j = 0; j < 32; j++)
1509 {
1510 if (is_pixel_on(andmask, j, i, 32, 1))
1511 set_pixel_on(c->andmask, j, 31 - i, 32, 8, 255);
1512 if (is_pixel_on(xormask, j, i, 32, 24))
1513 set_pixel_on(c->xormask, j, 31 - i, 32, 8, 255);
1514 }
1515 }
1516 return (void*)c;
1517 }
1518
1519 /*****************************************************************************/
1520 void ui_destroy_cursor(void* cursor)
1521 {
1522 if (cursor != NULL)
1523 xfree(cursor);
1524 }
1525
1526 /*****************************************************************************/
1527 void ui_set_cursor(void* cursor)
1528 {
1529 int x;
1530 int y;
1531 int ox;
1532 int oy;
1533
1534 ox = mousex;
1535 oy = mousey;
1536 x = mousex + mcursor.x;
1537 y = mousey + mcursor.y;
1538 memcpy(&mcursor, cursor, sizeof(tcursor));
1539 mousex = x - mcursor.x;
1540 mousey = y - mcursor.y;
1541 draw_cursor_under(ox, oy);
1542 draw_cursor();
1543 }
1544
1545 /*****************************************************************************/
1546 uint16 ui_get_numlock_state(unsigned int state)
1547 {
1548 return 0;
1549 }
1550
1551 /*****************************************************************************/
1552 unsigned int read_keyboard_state(void)
1553 {
1554 return 0;
1555 }
1556
1557 /*****************************************************************************/
1558 void ui_resize_window(void)
1559 {
1560 }
1561
1562 /*****************************************************************************/
1563 void ui_begin_update(void)
1564 {
1565 }
1566
1567 /*****************************************************************************/
1568 void ui_end_update(void)
1569 {
1570 draw_cache_rects();
1571 draw_cursor();
1572 }
1573
1574 /*****************************************************************************/
1575 void generate_random(uint8* random)
1576 {
1577 memcpy(random, "12345678901234567890123456789012", 32);
1578 }
1579
1580 /*****************************************************************************/
1581 void save_licence(uint8* data, int length)
1582 {
1583 }
1584
1585 /*****************************************************************************/
1586 int load_licence(uint8** data)
1587 {
1588 return 0;
1589 }
1590
1591 /*****************************************************************************/
1592 void* xrealloc(void* in_val, int size)
1593 {
1594 return realloc(in_val, size);
1595 }
1596
1597 /*****************************************************************************/
1598 void* xmalloc(int size)
1599 {
1600 return malloc(size);
1601 }
1602
1603 /*****************************************************************************/
1604 void xfree(void* in_val)
1605 {
1606 free(in_val);
1607 }
1608
1609 /*****************************************************************************/
1610 void warning(char* format, ...)
1611 {
1612 va_list ap;
1613
1614 fprintf(stderr, "WARNING: ");
1615 va_start(ap, format);
1616 vfprintf(stderr, format, ap);
1617 va_end(ap);
1618 }
1619
1620 /*****************************************************************************/
1621 void unimpl(char* format, ...)
1622 {
1623 va_list ap;
1624
1625 fprintf(stderr, "NOT IMPLEMENTED: ");
1626 va_start(ap, format);
1627 vfprintf(stderr, format, ap);
1628 va_end(ap);
1629 }
1630
1631 /*****************************************************************************/
1632 void error(char* format, ...)
1633 {
1634 va_list ap;
1635
1636 fprintf(stderr, "ERROR: ");
1637 va_start(ap, format);
1638 vfprintf(stderr, format, ap);
1639 va_end(ap);
1640 }
1641
1642 BOOL rd_pstcache_mkdir(void)
1643 {
1644 return 0;
1645 }
1646
1647 /*****************************************************************************/
1648 int rd_open_file(char *filename)
1649 {
1650 return 0;
1651 }
1652
1653 /*****************************************************************************/
1654 void rd_close_file(int fd)
1655 {
1656 return;
1657 }
1658
1659 /*****************************************************************************/
1660 int rd_read_file(int fd, void *ptr, int len)
1661 {
1662 return 0;
1663 }
1664
1665 /*****************************************************************************/
1666 int rd_write_file(int fd, void* ptr, int len)
1667 {
1668 return 0;
1669 }
1670
1671 /*****************************************************************************/
1672 int rd_lseek_file(int fd, int offset)
1673 {
1674 return 0;
1675 }
1676
1677 /*****************************************************************************/
1678 BOOL rd_lock_file(int fd, int start, int len)
1679 {
1680 return False;
1681 }
1682
1683 /*****************************************************************************/
1684 void get_username_and_hostname(void)
1685 {
1686 char fullhostname[64];
1687 char* p;
1688 struct passwd* pw;
1689
1690 STRNCPY(g_username, "unknown", sizeof(g_username));
1691 STRNCPY(g_hostname, "unknown", sizeof(g_hostname));
1692 pw = getpwuid(getuid());
1693 if (pw != NULL && pw->pw_name != NULL)
1694 {
1695 STRNCPY(g_username, pw->pw_name, sizeof(g_username));
1696 }
1697 if (gethostname(fullhostname, sizeof(fullhostname)) != -1)
1698 {
1699 p = strchr(fullhostname, '.');
1700 if (p != NULL)
1701 *p = 0;
1702 STRNCPY(g_hostname, fullhostname, sizeof(g_hostname));
1703 }
1704 }
1705
1706 /*****************************************************************************/
1707 void out_params(void)
1708 {
1709 fprintf(stderr, "rdesktop: A Remote Desktop Protocol client.\n");
1710 fprintf(stderr, "Version " VERSION ". Copyright (C) 1999-2003 Matt Chapman.\n");
1711 fprintf(stderr, "See http://www.rdesktop.org/ for more information.\n\n");
1712 fprintf(stderr, "Usage: svgardesktop [options] server\n");
1713 fprintf(stderr, " -g: desktop geometry (WxH)\n");
1714 fprintf(stderr, " -4: use RDP version 4\n");
1715 fprintf(stderr, " -5: use RDP version 5 (default)\n");
1716 fprintf(stderr, " -t: tcp port\n");
1717 fprintf(stderr, " -u: user name\n");
1718 fprintf(stderr, " -n: client hostname\n");
1719 fprintf(stderr, " -d: disable accel funcs\n");
1720 fprintf(stderr, " -a: connection colour depth\n");
1721 fprintf(stderr, " -l: low memory\n");
1722 fprintf(stderr, "\n");
1723 }
1724
1725 /* produce a hex dump */
1726 void hexdump(uint8* p, uint32 len)
1727 {
1728 uint8* line;
1729 int i;
1730 int thisline;
1731 int offset;
1732
1733 line = p;
1734 offset = 0;
1735 while (offset < len)
1736 {
1737 printf("%04x ", offset);
1738 thisline = len - offset;
1739 if (thisline > 16)
1740 thisline = 16;
1741
1742 for (i = 0; i < thisline; i++)
1743 printf("%02x ", line[i]);
1744
1745 for (; i < 16; i++)
1746 printf(" ");
1747
1748 for (i = 0; i < thisline; i++)
1749 printf("%c", (line[i] >= 0x20 && line[i] < 0x7f) ? line[i] : '.');
1750
1751 printf("\n");
1752 offset += thisline;
1753 line += thisline;
1754 }
1755 }
1756
1757 /*****************************************************************************/
1758 int parse_parameters(int in_argc, char** in_argv)
1759 {
1760 int i;
1761 char* p;
1762
1763 if (in_argc <= 1)
1764 {
1765 out_params();
1766 return 0;
1767 }
1768 g_argc = in_argc;
1769 g_argv = in_argv;
1770 for (i = 1; i < in_argc; i++)
1771 {
1772 strcpy(g_servername, in_argv[i]);
1773 if (strcmp(in_argv[i], "-g") == 0)
1774 {
1775 g_width = strtol(in_argv[i + 1], &p, 10);
1776 if (g_width <= 0)
1777 {
1778 error("invalid geometry\n");
1779 return 0;
1780 }
1781 if (*p == 'x')
1782 g_height = strtol(p + 1, NULL, 10);
1783 if (g_height <= 0)
1784 {
1785 error("invalid geometry\n");
1786 return 0;
1787 }
1788 g_width = (g_width + 3) & ~3;
1789 }
1790 else if (strcmp(in_argv[i], "-4") == 0)
1791 g_use_rdp5 = 0;
1792 else if (strcmp(in_argv[i], "-5") == 0)
1793 g_use_rdp5 = 1;
1794 else if (strcmp(in_argv[i], "-t") == 0)
1795 g_tcp_port_rdp = strtol(in_argv[i + 1], &p, 10);
1796 else if (strcmp(in_argv[i], "-h") == 0)
1797 {
1798 out_params();
1799 return 0;
1800 }
1801 else if (strcmp(in_argv[i], "-n") == 0)
1802 {
1803 STRNCPY(g_hostname, in_argv[i + 1], sizeof(g_hostname));
1804 }
1805 else if (strcmp(in_argv[i], "-u") == 0)
1806 {
1807 STRNCPY(g_username, in_argv[i + 1], sizeof(g_username));
1808 }
1809 else if (strcmp(in_argv[i], "-d") == 0)
1810 {
1811 use_accel = 0;
1812 }
1813 else if (strcmp(in_argv[i], "-a") == 0)
1814 {
1815 g_server_bpp = strtol(in_argv[i + 1], NULL, 10);
1816 if (g_server_bpp != 8 && g_server_bpp != 16)
1817 {
1818 error("invalid server bpp\n");
1819 return 0;
1820 }
1821 g_server_Bpp = (g_server_bpp + 7) / 8;
1822 }
1823 else if (strcmp(in_argv[i], "-l") == 0)
1824 g_save_mem = 1;
1825 }
1826 return 1;
1827 }
1828
1829 /*****************************************************************************/
1830 int main(int in_argc, char** in_argv)
1831 {
1832 get_username_and_hostname();
1833 if (!parse_parameters(in_argc, in_argv))
1834 return 0;
1835 if (!ui_init())
1836 return 1;
1837 if (!ui_create_window())
1838 return 1;
1839 ui_main_loop();
1840 ui_destroy_window();
1841 ui_deinit();
1842 return 0;
1843 }

  ViewVC Help
Powered by ViewVC 1.1.26