00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00042 #include "pic_utils.h"
00043 #include "draw\draw.h"
00044 #include "config.h"
00045 #include "draw\draw_screen_buffer.h"
00046
00047
00048
00049 void draw_clear_screen() {
00050
00051 uns8 count;
00052 #if DRAW_TOTAL_BUFFER_SIZE == 1024 | DRAW_TOTAL_BUFFER_SIZE == 768 | DRAW_TOTAL_BUFFER_SIZE == 512 | DRAW_TOTAL_BUFFER_SIZE == 256
00053 count = 0;
00054 do {
00055 draw_buffer0[count] = 0;
00056 #if DRAW_TOTAL_BUFFER_SIZE > 256
00057 draw_buffer1[count] = 0;
00058 #if DRAW_TOTAL_BUFFER_SIZE > 512
00059 draw_buffer2[count] = 0;
00060 #if DRAW_TOTAL_BUFFER_SIZE > 768
00061 draw_buffer3[count] = 0;
00062 #endif
00063 #endif
00064 #endif
00065 count++;
00066 } while (count != 0);
00067 #else
00068 #if DRAW_TOTAL_BUFFER_SIZE < 256
00069 count = 0;
00070 do {
00071 draw_buffer0[count] = 0;
00072 count++;
00073 } while (count < DRAW_TOTAL_BUFFER_SIZE);
00074 #else
00075 count = 0;
00076 do {
00077 draw_buffer0[count] = 0;
00078 count++;
00079 } while (count != 0);
00080 #if DRAW_TOTAL_BUFFER_SIZE < 512
00081 do {
00082 draw_buffer1[count] = 0;
00083 count++;
00084 } while (count < DRAW_TOTAL_BUFFER_SIZE - 256);
00085 #else
00086 do {
00087 draw_buffer1[count] = 0;
00088 count++;
00089 } while (count != 0);
00090 #if DRAW_TOTAL_BUFFER_SIZE > 512
00091 #if DRAW_TOTAL_BUFFER_SIZE < 768
00092 do {
00093 draw_buffer2[count] = 0;
00094 count++;
00095 } while (count < DRAW_TOTAL_BUFFER_SIZE - 512);
00096 #else
00097
00098 do {
00099 draw_buffer2[count] = 0;
00100 count++;
00101 } while (count != 0);
00102
00103 #if DRAW_TOTAL_BUFFER_SIZE < 1024
00104 do {
00105 draw_buffer3[count] = 0;
00106 count++;
00107 } while (count < DRAW_TOTAL_BUFFER_SIZE - 768);
00108 #else
00109 do {
00110 draw_buffer3[count] = 0;
00111 count++;
00112 } while (count != 0);
00113 #endif
00114 #endif
00115 #endif
00116
00117 #endif
00118
00119 #endif
00120 #endif
00121
00122 }
00123
00124 void draw_setup_io() {
00125 drv_setup_io();
00126 }
00127
00128 void draw_init() {
00129 drv_init();
00130 draw_clear_screen();
00131 }
00132
00133
00134
00135 void draw_set_pixel(uns8 x, uns8 y, uns8 colour) {
00136
00137 uns8 *buffer;
00138 uns16 buffer_loc, loc_byte;
00139 uns8 loc_bit, loc_in_buffer, buffer_num;
00140 uns8 bit_count;
00141
00142
00143
00144 #if DRAW_HW_Y_ORIGIN == TOP_LEFT
00145 #if DRAW_HW_BUFFER_ORIENTATION == HORIZONTAL
00146 buffer_loc = y * DRAW_PIXELS_WIDE + x;
00147 #else
00148
00149 buffer_loc = x * DRAW_PIXELS_HIGH + y;
00150 #endif
00151 #else
00152
00153 #if DRAW_HW_BUFFER_ORIENTATION == HORIZONTAL
00154 buffer_loc = y * DRAW_PIXELS_WIDE + x;
00155 #else
00156
00157 buffer_loc = x * DRAW_PIXELS_HIGH + y;
00158 #endif
00159 #endif
00160
00161
00162
00163
00164
00165
00166
00167 buffer_loc = buffer_loc * DRAW_BITS_PER_PIXEL;
00168
00169 loc_byte = buffer_loc / 8;
00170 loc_bit = (buffer_loc & (0x07));
00171
00172
00173
00174
00175
00176
00177 loc_in_buffer = loc_byte & 0xff;
00178 buffer_num = loc_byte >> 8;
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 if (buffer_num == 0) {
00200 buffer = &draw_buffer0;
00201 }
00202 #if DRAW_TOTAL_BUFFER_SIZE > 256
00203
00204 else if (buffer_num == 1) {
00205 buffer = &draw_buffer1;
00206
00207 }
00208 #if DRAW_TOTAL_BUFFER_SIZE > 512
00209 else if (buffer_num == 2) {
00210 buffer = &draw_buffer2;
00211
00212 }
00213 #if DRAW_TOTAL_BUFFER_SIZE > 768
00214 else if (buffer_num == 3) {
00215 buffer = &draw_buffer3;
00216
00217 }
00218 #endif
00219 #endif
00220 #endif
00221 #if DRAW_BITS_PER_PIXEL > 1
00222
00223 bit_count = 0;
00224
00225 while (bit_count < DRAW_BITS_PER_PIXEL) {
00226 if (test_bit(colour, bit_count)) {
00227 set_bit(buffer[loc_in_buffer], loc_bit);
00228 } else {
00229 clear_bit(buffer[loc_in_buffer], loc_bit);
00230 }
00231 bit_count++;
00232 loc_bit++;
00233 }
00234 #else
00235
00236 if (colour) {
00237 set_bit(buffer[loc_in_buffer], loc_bit);
00238 } else {
00239 clear_bit(buffer[loc_in_buffer], loc_bit);
00240 }
00241 #endif
00242
00243 }
00244
00245
00246 uns8 draw_get_pixel(uns8 x, uns8 y) {
00247 return 0;
00248 }
00249
00250
00251 void draw_rect(uns8 x, uns8 y, uns16 width, uns8 height, uns8 colour) {
00252 uns16 dx, dy;
00253
00254 for(dy = y ; dy < y + height ; dy++) {
00255 for(dx = x ; dx < x + width ; dx++) {
00256 draw_set_pixel(dx, dy, colour);
00257
00258
00259
00260
00261
00262 }
00263 }
00264 }
00265
00266 void draw_print_buffer() {
00267 #ifdef DRAW_DEBUG
00268 uns8 inv_y, x , y,
00269 byte_loc, bit_loc;
00270 uns16 buffer_loc;
00271
00272 for(y = 0 ; y < DRAW_PIXELS_HIGH ; y++) {
00273 inv_y = DRAW_PIXELS_HIGH - 1 - y;
00274 if (inv_y < 10) {
00275 serial_putc('0');
00276 }
00277 serial_print_int(inv_y);
00278 serial_putc(' ');
00279 serial_print_int_hex(inv_y * DRAW_PIXELS_WIDE / DRAW_PIXELS_PER_BYTE);
00280 serial_putc('|');
00281 for(x = 0 ; x < DRAW_PIXELS_WIDE ; x++) {
00282 buffer_loc = inv_y * DRAW_PIXELS_WIDE + x;
00283 byte_loc = buffer_loc / DRAW_PIXELS_PER_BYTE;
00284 bit_loc = buffer_loc & (DRAW_PIXELS_PER_BYTE -1);
00285
00286
00287
00288
00289
00290
00291
00292 if (test_bit(draw_buffer0[byte_loc], bit_loc)) {
00293
00294 serial_putc('1');
00295
00296 } else {
00297 serial_putc('0');
00298 }
00299 }
00300
00301 serial_print_str("|\n");
00302
00303 }
00304 #endif
00305 }
00306
00307 void draw_line(uns8 x0, uns8 y0, uns8 x1, uns8 y1, uns8 colour) {
00308
00309 int dy = y1 - y0;
00310 int dx = x1 - x0;
00311 int stepx, stepy;
00312
00313 if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
00314 if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
00315 dy <<= 1;
00316 dx <<= 1;
00317
00318 draw_set_pixel(x0, y0, colour);
00319 if (dx > dy) {
00320 int fraction = dy - (dx >> 1);
00321 while (x0 != x1) {
00322 if (fraction >= 0) {
00323 y0 += stepy;
00324 fraction -= dx;
00325 }
00326 x0 += stepx;
00327 fraction += dy;
00328 draw_set_pixel(x0, y0, colour);
00329 }
00330 } else {
00331 int fraction = dx - (dy >> 1);
00332 while (y0 != y1) {
00333 if (fraction >= 0) {
00334 x0 += stepx;
00335 fraction -= dy;
00336 }
00337 y0 += stepy;
00338 fraction += dx;
00339 draw_set_pixel(x0, y0, colour);
00340 }
00341 }
00342 }
00343
00344
00345 void draw_circle_lines (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour) {
00346 draw_line(ctr_x - pt_x, ctr_y + pt_y, ctr_x + pt_x, ctr_y + pt_y, colour);
00347 draw_line(ctr_x - pt_x, ctr_y - pt_y, ctr_x + pt_x, ctr_y - pt_y, colour);
00348 draw_line(ctr_x + pt_y, ctr_y + pt_x, ctr_x - pt_y, ctr_y + pt_x, colour);
00349 draw_line(ctr_x + pt_y, ctr_y - pt_x, ctr_x - pt_y, ctr_y - pt_x, colour);
00350 }
00351
00352 void draw_filled_circle(int x_centre, int y_centre, int r, uns8 colour) {
00353 int x,y;
00354 int p = 1 - r;
00355
00356 x = 0;
00357 y = r;
00358
00359 draw_circle_lines(x_centre, y_centre, x, y, colour);
00360
00361 while (x < y) {
00362 x++;
00363 if (p < 0)
00364 p += 2 * x + 1;
00365 else {
00366 y--;
00367 p += 2 * (x - y) + 1;
00368 }
00369 draw_circle_lines (x_centre, y_centre, x, y, colour);
00370 }
00371
00372 }
00373
00374
00375 void draw_circle_points (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour) {
00376
00377 draw_set_pixel (ctr_x + pt_x, ctr_y + pt_y, colour);
00378 draw_set_pixel (ctr_x - pt_x, ctr_y + pt_y, colour);
00379
00380 draw_set_pixel (ctr_x + pt_x, ctr_y - pt_y, colour);
00381 draw_set_pixel (ctr_x - pt_x, ctr_y - pt_y, colour);
00382
00383 draw_set_pixel (ctr_x + pt_y, ctr_y + pt_x, colour);
00384 draw_set_pixel (ctr_x - pt_y, ctr_y + pt_x, colour);
00385
00386 draw_set_pixel (ctr_x + pt_y, ctr_y - pt_x, colour);
00387 draw_set_pixel (ctr_x - pt_y, ctr_y - pt_x, colour);
00388 }
00389
00390 void draw_circle(int x_centre, int y_centre, int r, uns8 colour) {
00391 int x,y;
00392 int p = 1 - r;
00393
00394 x = 0;
00395 y = r;
00396
00397 draw_circle_points(x_centre, y_centre, x, y, 2);
00398
00399 while (x < y) {
00400 x++;
00401 if (p < 0)
00402 p += 2 * x + 1;
00403 else {
00404 y--;
00405 p += 2 * (x - y + 1);
00406 }
00407 draw_circle_points (x_centre, y_centre, x, y, colour);
00408 }
00409
00410 }
00411 void draw_circle_points2 (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour) {
00412
00413 draw_set_pixel (ctr_x + pt_x + 1, ctr_y + pt_y +1, colour);
00414 draw_set_pixel (ctr_x + pt_y + 1, ctr_y + pt_x +1, colour);
00415
00416 draw_set_pixel (ctr_x + pt_x + 1, ctr_y - pt_y, colour);
00417 draw_set_pixel (ctr_x + pt_y + 1, ctr_y - pt_x, colour);
00418
00419 draw_set_pixel (ctr_x - pt_x, ctr_y - pt_y, colour);
00420 draw_set_pixel (ctr_x - pt_y, ctr_y - pt_x, colour);
00421
00422 draw_set_pixel (ctr_x - pt_x, ctr_y + pt_y +1, colour);
00423 draw_set_pixel (ctr_x - pt_y, ctr_y + pt_x +1, colour);
00424
00425 }
00426 void draw_circle2(int x_centre, int y_centre, int r, uns8 colour) {
00427 int x, y;
00428
00429
00430
00431 int p = 1 -r;
00432 x = 0;
00433 y = r;
00434
00435 draw_circle_points2(x_centre, y_centre, x, y, colour);
00436
00437 while (x < y) {
00438 x++;
00439 if (p < 0)
00440
00441
00442
00443 p = p + 2* x + 1;
00444 else {
00445 y--;
00446
00447
00448
00449 p = p + 2*(x-y) + 1;
00450 }
00451 draw_circle_points2 (x_centre, y_centre, x, y, colour);
00452 }
00453
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507 #define FONT_FIRST_CHAR 32
00508 #define FONT_LAST_CHAR 127
00509 #define FONT_HEIGHT 7
00510 extern rom char PicPack5x7_bitmap_0[1];
00511 extern rom char PicPack5x7_bitmap_1[1];
00512 extern uns16 PicPack5x7_index[1];
00513
00514 uns16 draw_length_str(char *str) {
00515 uns8 my_char;
00516 uns16 length;
00517
00518 length = 0;
00519 while (*str != 0) {
00520 my_char = *str;
00521 my_char = my_char - 32;
00522 length = length + (PicPack5x7_index[my_char + 1] - PicPack5x7_index[my_char]) + 1;
00523 str++;
00524 }
00525 length = length - 1;
00526 return length;
00527 }
00528
00529 void draw_print_str(uns8 x, uns8 y, uns8 width, uns8 start_pixel, uns8 colour, char *str) {
00530
00531 uns8 my_char;
00532 uns16 index_pos;
00533 uns16 index_pos_next;
00534 uns16 count, s_count;
00535 uns8 sliver, x_origin, y_origin, pixel;
00536 y_origin = y;
00537 x_origin = x;
00538 pixel = 0;
00539 while (*str != 0) {
00540
00541 my_char = *str;
00542 my_char = my_char - 32;
00543
00544
00545 index_pos = PicPack5x7_index[my_char];
00546 index_pos_next = PicPack5x7_index[my_char + 1];
00547 for(count = index_pos ; count < index_pos_next ; count++) {
00548 if (count < 256) {
00549 sliver = PicPack5x7_bitmap_0[count];
00550 } else {
00551 sliver = PicPack5x7_bitmap_1[count-256];
00552 }
00553
00554 if (pixel >= start_pixel) {
00555 s_count = 0;
00556 while (s_count < 7) {
00557 if (test_bit(sliver, 6)) {
00558 #if DRAW_HW_Y_ORIGIN == BOTTOM_LEFT
00559 draw_set_pixel(x, y + s_count, colour);
00560 #else
00561
00562 draw_set_pixel(x, y - s_count, colour);
00563 #endif
00564 }
00565 sliver <<= 1;
00566 s_count++;
00567 }
00568 x++;
00569 }
00570 if (x - x_origin == width) {
00571 return;
00572 }
00573 pixel++;
00574
00575
00576
00577 }
00578 str++;
00579 if (pixel >= start_pixel) {
00580 x++;
00581 }
00582 pixel++;
00583
00584 if (x - x_origin == width) {
00585 return;
00586 }
00587 }
00588 }
00589
00590
00591 void draw_bitmap(uns8 x, uns8 y, uns8 colour, char *bitmap) {
00592
00593
00594 uns8 bitpos = 0;
00595 uns8 bytepos = 0;
00596 uns8 value;
00597 uns8 bitmap_width = bitmap[0];
00598 uns8 bitmap_height = bitmap[1];
00599 uns8 bitmap_bpp = bitmap[2];
00600 uns8 xbitmap, ybitmap;
00601
00602
00603 bytepos = 3;
00604 bitpos = 0b10000000;
00605
00606 for (xbitmap = 0; xbitmap < bitmap_width; xbitmap++) {
00607 for (ybitmap = 0; ybitmap < bitmap_height; ybitmap++) {
00608 if (bitpos == 0b10000000) {
00609 bitpos = 0b00000001;
00610 bytepos++;
00611 value = bitmap[bytepos];
00612 } else {
00613 bitpos = bitpos << 1;
00614 }
00615 if (value & bitpos) {
00616 #if DRAW_HW_Y_ORIGIN == TOP_LEFT
00617 draw_set_pixel(x + xbitmap, y + ybitmap, colour);
00618 #else
00619 draw_set_pixel(x + xbitmap, y - ybitmap, colour);
00620 #endif
00621 }
00622 }
00623 }
00624 }
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695