blob: 4ee96db65a1b7f7eff54d2954972d11450d14197 [file] [log] [blame]
adamdunkels4fa940f2003-04-11 20:30:14 +00001/*
2 * Copyright (c) 2003, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * 3. All advertising materials mentioning features or use of this
15 * software must display the following acknowledgement:
16 * This product includes software developed by Adam Dunkels.
17 * 4. The name of the author may not be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * This file is part of the Contiki VNC client
34 *
oliverschmidta5b57db2004-07-18 13:23:28 +000035 * $Id: vnc-draw.c,v 1.2 2004/07/18 13:23:28 oliverschmidt Exp $
adamdunkels4fa940f2003-04-11 20:30:14 +000036 *
37 */
38
39
40
41#include "vnc-draw.h"
42#include "vnc-draw-asm.h"
43
44#include "vnc-conf.h"
45
46
47static unsigned char conv[256];
48
49static unsigned char oratab[8] =
50 { 0x80, 0x40, 0x20, 0x10,
51 0x08, 0x04, 0x02, 0x01 };
52static unsigned char andtab[8] =
53 { 0x7f, 0xbf, 0xdf, 0xef,
54 0xf7, 0xfb, 0xfd, 0xfe };
55
56static u8_t *bitmapptrtab[VNC_CONF_VIEWPORT_HEIGHT];
57
58static unsigned short viewport_x,
59 viewport_y, viewport_w, viewport_h;
60
61u8_t vnc_draw_bitmap[(VNC_CONF_VIEWPORT_WIDTH / 8) *
62 VNC_CONF_VIEWPORT_HEIGHT];
63
64
65
66u16_t vnc_draw_x;
67u16_t vnc_draw_y;
68u8_t *vnc_draw_dataptr;
69u8_t *vnc_draw_bitmapptr;
70u16_t vnc_draw_datalen;
71
72/*-----------------------------------------------------------------------------------*/
73void
74vnc_draw_pixel(u16_t x, u8_t y, u8_t c)
75{
76 u8_t o, a;
77
78 vnc_draw_bitmapptr = bitmapptrtab[y] + (x & 0x1f8);
79
80 if(c) {
81 o = oratab[x & 7];
82 *vnc_draw_bitmapptr = *vnc_draw_bitmapptr | o;
83 } else {
84 a = andtab[x & 7];
85 *vnc_draw_bitmapptr = *vnc_draw_bitmapptr & a;
86 }
87}
88/*-----------------------------------------------------------------------------------*/
89void
90vnc_draw_pixelline(u16_t x, u16_t y, u8_t *data, u16_t datalen)
91{
92 u8_t o, a;
93 register u8_t *bitmapptr;
94
95 vnc_draw_x = x - viewport_x;
96 vnc_draw_y = y - viewport_y;
97
98 /* if(vnc_draw_y & 1) {
99 return;
100 } else {
101 vnc_draw_y /= 2;
102 }*/
103
104
105
106 if(vnc_draw_y >= VNC_CONF_VIEWPORT_HEIGHT ||
107 vnc_draw_x >= VNC_CONF_VIEWPORT_WIDTH) {
108 return;
109 }
110
111 vnc_draw_datalen = datalen;
112
113 if(vnc_draw_datalen + vnc_draw_x >= VNC_CONF_VIEWPORT_WIDTH) {
114 vnc_draw_datalen = VNC_CONF_VIEWPORT_WIDTH - vnc_draw_x;
115 if(vnc_draw_datalen == 0) {
116 return;
117 }
118 }
119
120 vnc_draw_dataptr = data;
121
122 /* vnc_draw_bitmapptr = bitmaptab[vnc_draw_y] +
123 (vnc_draw_x & 0x1f8);*/
124
125 for(; vnc_draw_datalen > 0; --vnc_draw_datalen) {
126 /* vnc_draw_pixel(vnc_draw_x, vnc_draw_y,
127 conv[*vnc_draw_dataptr]);*/
128
129 bitmapptr = bitmapptrtab[vnc_draw_y] + (vnc_draw_x & 0x1f8);
130
131 if(conv[*vnc_draw_dataptr]) {
132 o = oratab[vnc_draw_x & 7];
133 *bitmapptr = *bitmapptr | o;
134 } else {
135 a = andtab[vnc_draw_x & 7];
136 *bitmapptr = *bitmapptr & a;
137 }
138 ++vnc_draw_dataptr;
139 ++vnc_draw_x;
140 }
141}
142/*-----------------------------------------------------------------------------------*/
143void
144vnc_draw_init(void)
145{
146 unsigned int tmp;
147 unsigned int i;
148 unsigned short ptr;
149
150
151 /* Create color conversion table. */
152 for(i = 0; i < 256; ++i) {
153 if(((i & 0xc0) > 0xc0) ||
154 ((i & 0x38) > 0x18) ||
155 ((i & 0x07) > 0x03)) {
156 conv[i] = 0;
157 } else {
158 conv[i] = 1;
159 }
160 }
161
162 memset(vnc_draw_bitmap, 0, sizeof(vnc_draw_bitmap));
163
164 for(i = 0; i < VNC_CONF_VIEWPORT_HEIGHT; ++i) {
165 bitmapptrtab[i] = (u8_t *)((u16_t)vnc_draw_bitmap +
166 ((i & 0xfff8)/8) * VNC_CONF_VIEWPORT_WIDTH +
167 (i & 7));
168 }
169
170 viewport_x = 0;
171 viewport_y = 0;
172
173 viewport_w = VNC_CONF_VIEWPORT_WIDTH;
174 viewport_h = VNC_CONF_VIEWPORT_HEIGHT;
175
176 return;
177}
178/*-----------------------------------------------------------------------------------*/
179u16_t
180vnc_draw_viewport_x(void)
181{
182 return viewport_x;
183}
184/*-----------------------------------------------------------------------------------*/
185u16_t
186vnc_draw_viewport_y(void)
187{
188 return viewport_y;
189}
190/*-----------------------------------------------------------------------------------*/
191u16_t
192vnc_draw_viewport_w(void)
193{
194 return viewport_w;
195}
196/*-----------------------------------------------------------------------------------*/
197u16_t
198vnc_draw_viewport_h(void)
199{
200 return viewport_h;
201}
202/*-----------------------------------------------------------------------------------*/
203#if 0
204signed short
205c64_mouse_x(void)
206{
207 return 0;
208}
209/*-----------------------------------------------------------------------------------*/
210signed short
211c64_mouse_y(void)
212{
213 return 0;
214}
215/*-----------------------------------------------------------------------------------*/
216u8_t
217c64_mouse_buttons(void)
218{
219 return firebutton;
220}
221/*-----------------------------------------------------------------------------------*/
222void
223c64_set_mouse_x(unsigned short x)
224{
225 joyx = x;
226}
227/*-----------------------------------------------------------------------------------*/
228void
229c64_set_mouse_y(unsigned short y)
230{
231 joyy = y;
232}
233/*-----------------------------------------------------------------------------------*/
234void
235c64_set_viewport_x(unsigned short x)
236{
237 viewport_x = x;
238}
239/*-----------------------------------------------------------------------------------*/
240void
241c64_set_viewport_y(unsigned short y)
242{
243 viewport_y = y;
244}
245/*-----------------------------------------------------------------------------------*/
246
247#endif /* 0 */
248#if 0
oliverschmidta5b57db2004-07-18 13:23:28 +0000249#pragma optimize(push, off)
adamdunkels4fa940f2003-04-11 20:30:14 +0000250void
251c64_scroll_up(unsigned char c)
252{
253 asm("lda $f7");
254 asm("pha");
255 asm("lda $f8");
256 asm("pha");
257 asm("lda $f9");
258 asm("pha");
259 asm("lda $fa");
260 asm("pha");
261 asm("lda $fb");
262 asm("pha");
263 asm("lda $fc");
264 asm("pha");
265 asm("lda $fd");
266 asm("pha");
267 asm("lda $fe");
268 asm("pha");
269
270 asm("lda $01");
271 asm("pha");
272 asm("lda #$35");
273 asm("sta $01");
274
275 asm("lda #$80");
276 asm("sta $f7");
277 asm("lda #$a2");
278 asm("sta $f8");
279 asm("lda #$00");
280 asm("sta $f9");
281 asm("lda #$a0");
282 asm("sta $fa");
283
284 asm("lda #$80");
285 asm("sta $fb");
286 asm("lda #$e2");
287 asm("sta $fc");
288 asm("lda #$00");
289 asm("sta $fd");
290 asm("lda #$e0");
291 asm("sta $fe");
292
293 asm("ldy #0");
294 asm("loop:");
295 asm("lda ($f7),y");
296 asm("sta ($f9),y");
297 asm("lda ($fb),y");
298 asm("sta ($fd),y");
299 asm("iny");
300 asm("bne loop");
301
302 asm("inc $f8");
303 asm("inc $fa");
304 asm("inc $fc");
305 asm("inc $fe");
306
307 asm("lda $fc");
308 asm("cmp #$00");
309 asm("bne loop");
310
311 asm("ldy #0");
312 asm("lda #0");
313 asm("sta $fe00,y");
314 asm("sta $be00,y");
315 asm("sta $fcc0,y");
316 asm("sta $bcc0,y");
317 asm("iny");
318 asm("bne *-13");
319 asm("sta $ff00,y");
320 asm("sta $bf00,y");
321 asm("sta $fdc0,y");
322 asm("sta $bdc0,y");
323 asm("iny");
324 asm("cpy #$40");
325 asm("bne *-15");
326
327
328 asm("pla");
329 asm("sta $01");
330 asm("pla");
331 asm("sta $fe");
332 asm("pla");
333 asm("sta $fd");
334 asm("pla");
335 asm("sta $fc");
336 asm("pla");
337 asm("sta $fb");
338 asm("pla");
339 asm("sta $fa");
340 asm("pla");
341 asm("sta $f9");
342 asm("pla");
343 asm("sta $f8");
344 asm("pla");
345 asm("sta $f7");
346}
oliverschmidta5b57db2004-07-18 13:23:28 +0000347#pragma optimize(pop)
adamdunkels4fa940f2003-04-11 20:30:14 +0000348/*-----------------------------------------------------------------------------------*/
oliverschmidta5b57db2004-07-18 13:23:28 +0000349#pragma optimize(push, off)
adamdunkels4fa940f2003-04-11 20:30:14 +0000350void
351c64_scroll_down(unsigned char c)
352{
353 asm("lda $f7");
354 asm("pha");
355 asm("lda $f8");
356 asm("pha");
357 asm("lda $f9");
358 asm("pha");
359 asm("lda $fa");
360 asm("pha");
361 asm("lda $fb");
362 asm("pha");
363 asm("lda $fc");
364 asm("pha");
365 asm("lda $fd");
366 asm("pha");
367 asm("lda $fe");
368 asm("pha");
369
370
371 asm("lda $01");
372 asm("pha");
373 asm("lda #$35");
374 asm("sta $01");
375
376 asm("lda #$c0");
377 asm("sta $fb");
378 asm("lda #$fb");
379 asm("sta $fc");
380 asm("lda #$40");
381 asm("sta $fd");
382 asm("lda #$fe");
383 asm("sta $fe");
384
385 asm("lda #$c0");
386 asm("sta $f7");
387 asm("lda #$bb");
388 asm("sta $f8");
389 asm("lda #$40");
390 asm("sta $f9");
391 asm("lda #$be");
392 asm("sta $fa");
393
394
395 asm("ldy #0");
396 asm("loop:");
397 asm("lda ($fb),y");
398 asm("sta ($fd),y");
399 asm("lda ($f7),y");
400 asm("sta ($f9),y");
401 asm("iny");
402 asm("bne loop");
403
404 asm("dec $f8");
405 asm("dec $fa");
406 asm("dec $fc");
407 asm("dec $fe");
408
409
410 asm("lda $fe");
411 asm("cmp #$df");
412 asm("bne loop");
413
414 asm("ldy #0");
415 asm("lda #0");
416 asm("sta $e000,y");
417 asm("sta $a000,y");
418 asm("sta $e140,y");
419 asm("sta $a140,y");
420 asm("iny");
421 asm("bne *-13");
422 asm("sta $e100,y");
423 asm("sta $a100,y");
424 asm("sta $e240,y");
425 asm("sta $a240,y");
426 asm("iny");
427 asm("cpy #$40");
428 asm("bne *-15");
429
430 asm("pla");
431 asm("sta $01");
432 asm("pla");
433 asm("sta $fe");
434 asm("pla");
435 asm("sta $fd");
436 asm("pla");
437 asm("sta $fc");
438 asm("pla");
439 asm("sta $fb");
440 asm("pla");
441 asm("sta $fa");
442 asm("pla");
443 asm("sta $f9");
444 asm("pla");
445 asm("sta $f8");
446 asm("pla");
447 asm("sta $f7");
448}
oliverschmidta5b57db2004-07-18 13:23:28 +0000449#pragma optimize(pop)
adamdunkels4fa940f2003-04-11 20:30:14 +0000450/*-----------------------------------------------------------------------------------*/
oliverschmidta5b57db2004-07-18 13:23:28 +0000451#pragma optimize(push, off)
adamdunkels4fa940f2003-04-11 20:30:14 +0000452void
453c64_scroll_right(unsigned char c)
454{
455 asm("lda $f7");
456 asm("pha");
457 asm("lda $f8");
458 asm("pha");
459 asm("lda $f9");
460 asm("pha");
461 asm("lda $fa");
462 asm("pha");
463 asm("lda $fb");
464 asm("pha");
465 asm("lda $fc");
466 asm("pha");
467 asm("lda $fd");
468 asm("pha");
469 asm("lda $fe");
470 asm("pha");
471
472
473 asm("lda $01");
474 asm("pha");
475 asm("lda #$35");
476 asm("sta $01");
477
478 asm("lda #$00");
479 asm("sta $f7");
480 asm("lda #$a0");
481 asm("sta $f8");
482 asm("lda #$10");
483 asm("sta $f9");
484 asm("lda #$a0");
485 asm("sta $fa");
486
487 asm("lda #$00");
488 asm("sta $fb");
489 asm("lda #$e0");
490 asm("sta $fc");
491 asm("lda #$10");
492 asm("sta $fd");
493 asm("lda #$e0");
494 asm("sta $fe");
495
496 asm("ldx #0");
497
498 asm("loop3:");
499
500 asm("ldy #$ff");
501 asm("loop:");
502 asm("lda ($f7),y");
503 asm("sta ($f9),y");
504 asm("lda ($fb),y");
505 asm("sta ($fd),y");
506 asm("dey");
507 asm("cpy #$ff");
508 asm("bne loop");
509
510 asm("inc $f8");
511 asm("inc $fa");
512 asm("inc $fc");
513 asm("inc $fe");
514
515 asm("ldy #$30");
516 asm("loop2:");
517 asm("lda ($f7),y");
518 asm("sta ($f9),y");
519 asm("lda ($fb),y");
520 asm("sta ($fd),y");
521 asm("dey");
522 asm("cpy #$ff");
523 asm("bne loop2");
524
525 asm("lda $f7");
526 asm("clc");
527 asm("adc #$40");
528 asm("sta $f7");
529 asm("sta $fb");
530 asm("bcc :+");
531 asm("inc $f8");
532 asm("inc $fc");
533 asm(":");
534
535 asm("lda $f9");
536 asm("clc");
537 asm("adc #$40");
538 asm("sta $f9");
539 asm("sta $fd");
540 asm("bcc :+");
541 asm("inc $fa");
542 asm("inc $fe");
543 asm(":");
544
545
546
547 asm("inx");
548 asm("cpx #24");
549 asm("bne loop3");
550
551 asm("pla");
552 asm("sta $01");
553 asm("pla");
554 asm("sta $fe");
555 asm("pla");
556 asm("sta $fd");
557 asm("pla");
558 asm("sta $fc");
559 asm("pla");
560 asm("sta $fb");
561 asm("pla");
562 asm("sta $fa");
563 asm("pla");
564 asm("sta $f9");
565 asm("pla");
566 asm("sta $f8");
567 asm("pla");
568 asm("sta $f7");
569}
oliverschmidta5b57db2004-07-18 13:23:28 +0000570#pragma optimize(pop)
adamdunkels4fa940f2003-04-11 20:30:14 +0000571/*-----------------------------------------------------------------------------------*/
oliverschmidta5b57db2004-07-18 13:23:28 +0000572#pragma optimize(push, off)
adamdunkels4fa940f2003-04-11 20:30:14 +0000573void
574c64_scroll_left(unsigned char c)
575{
576 asm("lda $f7");
577 asm("pha");
578 asm("lda $f8");
579 asm("pha");
580 asm("lda $f9");
581 asm("pha");
582 asm("lda $fa");
583 asm("pha");
584 asm("lda $fb");
585 asm("pha");
586 asm("lda $fc");
587 asm("pha");
588 asm("lda $fd");
589 asm("pha");
590 asm("lda $fe");
591 asm("pha");
592
593
594 asm("lda $01");
595 asm("pha");
596 asm("lda #$35");
597 asm("sta $01");
598
599 asm("lda #$10");
600 asm("sta $f7");
601 asm("lda #$a0");
602 asm("sta $f8");
603 asm("lda #$00");
604 asm("sta $f9");
605 asm("lda #$a0");
606 asm("sta $fa");
607
608 asm("lda #$10");
609 asm("sta $fb");
610 asm("lda #$e0");
611 asm("sta $fc");
612 asm("lda #$00");
613 asm("sta $fd");
614 asm("lda #$e0");
615 asm("sta $fe");
616
617 asm("ldx #0");
618 asm("loop3:");
619 asm("ldy #0");
620 asm("loop:");
621 asm("lda ($f7),y");
622 asm("sta ($f9),y");
623 asm("lda ($fb),y");
624 asm("sta ($fd),y");
625 asm("iny");
626 asm("bne loop");
627
628 asm("inc $f8");
629 asm("inc $fa");
630 asm("inc $fc");
631 asm("inc $fe");
632
633 asm("ldy #0");
634 asm("loop2:");
635 asm("lda ($f7),y");
636 asm("sta ($f9),y");
637 asm("lda ($fb),y");
638 asm("sta ($fd),y");
639 asm("iny");
640 asm("cpy #$30");
641 asm("bne loop2");
642
643 asm("lda $f7");
644 asm("clc");
645 asm("adc #$40");
646 asm("sta $f7");
647 asm("sta $fb");
648 asm("bcc :+");
649 asm("inc $f8");
650 asm("inc $fc");
651 asm(":");
652
653 asm("lda $f9");
654 asm("clc");
655 asm("adc #$40");
656 asm("sta $f9");
657 asm("sta $fd");
658 asm("bcc :+");
659 asm("inc $fa");
660 asm("inc $fe");
661 asm(":");
662
663
664 asm("inx");
665 asm("cpx #24");
666 asm("bne loop3");
667
668 asm("pla");
669 asm("sta $01");
670 asm("pla");
671 asm("sta $fe");
672 asm("pla");
673 asm("sta $fd");
674 asm("pla");
675 asm("sta $fc");
676 asm("pla");
677 asm("sta $fb");
678 asm("pla");
679 asm("sta $fa");
680 asm("pla");
681 asm("sta $f9");
682 asm("pla");
683 asm("sta $f8");
684 asm("pla");
685 asm("sta $f7");
686}
oliverschmidta5b57db2004-07-18 13:23:28 +0000687#pragma optimize(pop)
adamdunkels4fa940f2003-04-11 20:30:14 +0000688/*-----------------------------------------------------------------------------------*/
689
690
691
692#endif /* 0 */