draw.c File Reference
Buffered graphics routines.
More...
Defines |
#define | FONT_FIRST_CHAR 32 |
#define | FONT_HEIGHT 7 |
#define | FONT_LAST_CHAR 127 |
Functions |
void | draw_bitmap (uns8 x, uns8 y, uns8 colour, char *bitmap) |
void | draw_circle (int x_centre, int y_centre, int r, uns8 colour) |
void | draw_circle2 (int x_centre, int y_centre, int r, uns8 colour) |
void | draw_circle_lines (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour) |
void | draw_circle_points (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour) |
void | draw_circle_points2 (int ctr_x, int ctr_y, int pt_x, int pt_y, uns8 colour) |
void | draw_clear_screen () |
void | draw_filled_circle (int x_centre, int y_centre, int r, uns8 colour) |
uns8 | draw_get_pixel (uns8 x, uns8 y) |
void | draw_init () |
uns16 | draw_length_str (char *str) |
void | draw_line (uns8 x0, uns8 y0, uns8 x1, uns8 y1, uns8 colour) |
void | draw_print_buffer () |
void | draw_print_str (uns8 x, uns8 y, uns8 width, uns8 start_pixel, uns8 colour, char *str) |
void | draw_rect (uns8 x, uns8 y, uns16 width, uns8 height, uns8 colour) |
void | draw_set_pixel (uns8 x, uns8 y, uns8 colour) |
void | draw_setup_io () |
Variables |
rom char | PicPack5x7_bitmap_0 [1] |
rom char | PicPack5x7_bitmap_1 [1] |
uns16 | PicPack5x7_index [1] |
Detailed Description
Define Documentation
#define FONT_FIRST_CHAR 32 |
#define FONT_LAST_CHAR 127 |
Function Documentation
void draw_bitmap |
( |
uns8 |
x, |
|
|
uns8 |
y, |
|
|
uns8 |
colour, |
|
|
char * |
bitmap | |
|
) |
| | |
00593 {
00594
00595
00596 uns8 bitpos = 0;
00597 uns8 bytepos = 0;
00598 uns8 value;
00599 uns8 bitmap_width = bitmap[0];
00600 uns8 bitmap_height = bitmap[1];
00601 uns8 bitmap_bpp = bitmap[2];
00602 uns8 xbitmap, ybitmap;
00603
00604
00605 bytepos = 3;
00606 bitpos = 0b10000000;
00607
00608 for (xbitmap = 0; xbitmap < bitmap_width; xbitmap++) {
00609 for (ybitmap = 0; ybitmap < bitmap_height; ybitmap++) {
00610 if (bitpos == 0b10000000) {
00611 bitpos = 0b00000001;
00612 bytepos++;
00613 value = bitmap[bytepos];
00614 } else {
00615 bitpos = bitpos << 1;
00616 }
00617 if (value & bitpos) {
00618 #if DRAW_HW_Y_ORIGIN == TOP_LEFT
00619 draw_set_pixel(x + xbitmap, y + ybitmap, colour);
00620 #else
00621 draw_set_pixel(x + xbitmap, y - ybitmap, colour);
00622 #endif
00623 }
00624 }
00625 }
00626 }
void draw_circle |
( |
int |
x_centre, |
|
|
int |
y_centre, |
|
|
int |
r, |
|
|
uns8 |
colour | |
|
) |
| | |
00392 {
00393 int x,y;
00394 int p = 1 - r;
00395
00396 x = 0;
00397 y = r;
00398
00399 draw_circle_points(x_centre, y_centre, x, y, 2);
00400
00401 while (x < y) {
00402 x++;
00403 if (p < 0)
00404 p += 2 * x + 1;
00405 else {
00406 y--;
00407 p += 2 * (x - y + 1);
00408 }
00409 draw_circle_points (x_centre, y_centre, x, y, colour);
00410 }
00411
00412 }
void draw_circle2 |
( |
int |
x_centre, |
|
|
int |
y_centre, |
|
|
int |
r, |
|
|
uns8 |
colour | |
|
) |
| | |
00428 {
00429 int x, y;
00430
00431
00432
00433 int p = 1 -r;
00434 x = 0;
00435 y = r;
00436
00437 draw_circle_points2(x_centre, y_centre, x, y, colour);
00438
00439 while (x < y) {
00440 x++;
00441 if (p < 0)
00442
00443
00444
00445 p = p + 2* x + 1;
00446 else {
00447 y--;
00448
00449
00450
00451 p = p + 2*(x-y) + 1;
00452 }
00453 draw_circle_points2 (x_centre, y_centre, x, y, colour);
00454 }
00455
00456 }
void draw_circle_lines |
( |
int |
ctr_x, |
|
|
int |
ctr_y, |
|
|
int |
pt_x, |
|
|
int |
pt_y, |
|
|
uns8 |
colour | |
|
) |
| | |
00347 {
00348 draw_line(ctr_x - pt_x, ctr_y + pt_y, ctr_x + pt_x, ctr_y + pt_y, colour);
00349 draw_line(ctr_x - pt_x, ctr_y - pt_y, ctr_x + pt_x, ctr_y - pt_y, colour);
00350 draw_line(ctr_x + pt_y, ctr_y + pt_x, ctr_x - pt_y, ctr_y + pt_x, colour);
00351 draw_line(ctr_x + pt_y, ctr_y - pt_x, ctr_x - pt_y, ctr_y - pt_x, colour);
00352 }
void draw_circle_points |
( |
int |
ctr_x, |
|
|
int |
ctr_y, |
|
|
int |
pt_x, |
|
|
int |
pt_y, |
|
|
uns8 |
colour | |
|
) |
| | |
00377 {
00378
00379 draw_set_pixel (ctr_x + pt_x, ctr_y + pt_y, colour);
00380 draw_set_pixel (ctr_x - pt_x, ctr_y + pt_y, colour);
00381
00382 draw_set_pixel (ctr_x + pt_x, ctr_y - pt_y, colour);
00383 draw_set_pixel (ctr_x - pt_x, ctr_y - pt_y, colour);
00384
00385 draw_set_pixel (ctr_x + pt_y, ctr_y + pt_x, colour);
00386 draw_set_pixel (ctr_x - pt_y, ctr_y + pt_x, colour);
00387
00388 draw_set_pixel (ctr_x + pt_y, ctr_y - pt_x, colour);
00389 draw_set_pixel (ctr_x - pt_y, ctr_y - pt_x, colour);
00390 }
void draw_circle_points2 |
( |
int |
ctr_x, |
|
|
int |
ctr_y, |
|
|
int |
pt_x, |
|
|
int |
pt_y, |
|
|
uns8 |
colour | |
|
) |
| | |
00413 {
00414
00415 draw_set_pixel (ctr_x + pt_x + 1, ctr_y + pt_y +1, colour);
00416 draw_set_pixel (ctr_x + pt_y + 1, ctr_y + pt_x +1, colour);
00417
00418 draw_set_pixel (ctr_x + pt_x + 1, ctr_y - pt_y, colour);
00419 draw_set_pixel (ctr_x + pt_y + 1, ctr_y - pt_x, colour);
00420
00421 draw_set_pixel (ctr_x - pt_x, ctr_y - pt_y, colour);
00422 draw_set_pixel (ctr_x - pt_y, ctr_y - pt_x, colour);
00423
00424 draw_set_pixel (ctr_x - pt_x, ctr_y + pt_y +1, colour);
00425 draw_set_pixel (ctr_x - pt_y, ctr_y + pt_x +1, colour);
00426
00427 }
void draw_clear_screen |
( |
|
) |
|
00049 {
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 }
void draw_filled_circle |
( |
int |
x_centre, |
|
|
int |
y_centre, |
|
|
int |
r, |
|
|
uns8 |
colour | |
|
) |
| | |
00354 {
00355 int x,y;
00356 int p = 1 - r;
00357
00358 x = 0;
00359 y = r;
00360
00361 draw_circle_lines(x_centre, y_centre, x, y, colour);
00362
00363 while (x < y) {
00364 x++;
00365 if (p < 0)
00366 p += 2 * x + 1;
00367 else {
00368 y--;
00369 p += 2 * (x - y) + 1;
00370 }
00371 draw_circle_lines (x_centre, y_centre, x, y, colour);
00372 }
00373
00374 }
uns8 draw_get_pixel |
( |
uns8 |
x, |
|
|
uns8 |
y | |
|
) |
| | |
00248 {
00249 return 0;
00250 }
uns16 draw_length_str |
( |
char * |
str |
) |
|
00516 {
00517 uns8 my_char;
00518 uns16 length;
00519
00520 length = 0;
00521 while (*str != 0) {
00522 my_char = *str;
00523 my_char = my_char - 32;
00524 length = length + (PicPack5x7_index[my_char + 1] - PicPack5x7_index[my_char]) + 1;
00525 str++;
00526 }
00527 length = length - 1;
00528 return length;
00529 }
void draw_line |
( |
uns8 |
x0, |
|
|
uns8 |
y0, |
|
|
uns8 |
x1, |
|
|
uns8 |
y1, |
|
|
uns8 |
colour | |
|
) |
| | |
00309 {
00310
00311 int dy = y1 - y0;
00312 int dx = x1 - x0;
00313 int stepx, stepy;
00314
00315 if (dy < 0) { dy = -dy; stepy = -1; } else { stepy = 1; }
00316 if (dx < 0) { dx = -dx; stepx = -1; } else { stepx = 1; }
00317 dy <<= 1;
00318 dx <<= 1;
00319
00320 draw_set_pixel(x0, y0, colour);
00321 if (dx > dy) {
00322 int fraction = dy - (dx >> 1);
00323 while (x0 != x1) {
00324 if (fraction >= 0) {
00325 y0 += stepy;
00326 fraction -= dx;
00327 }
00328 x0 += stepx;
00329 fraction += dy;
00330 draw_set_pixel(x0, y0, colour);
00331 }
00332 } else {
00333 int fraction = dx - (dy >> 1);
00334 while (y0 != y1) {
00335 if (fraction >= 0) {
00336 x0 += stepx;
00337 fraction -= dy;
00338 }
00339 y0 += stepy;
00340 fraction += dx;
00341 draw_set_pixel(x0, y0, colour);
00342 }
00343 }
00344 }
void draw_print_buffer |
( |
|
) |
|
void draw_print_str |
( |
uns8 |
x, |
|
|
uns8 |
y, |
|
|
uns8 |
width, |
|
|
uns8 |
start_pixel, |
|
|
uns8 |
colour, |
|
|
char * |
str | |
|
) |
| | |
00531 {
00532
00533 uns8 my_char;
00534 uns16 index_pos;
00535 uns16 index_pos_next;
00536 uns16 count, s_count;
00537 uns8 sliver, x_origin, y_origin, pixel;
00538 y_origin = y;
00539 x_origin = x;
00540 pixel = 0;
00541 while (*str != 0) {
00542
00543 my_char = *str;
00544 my_char = my_char - 32;
00545
00546
00547 index_pos = PicPack5x7_index[my_char];
00548 index_pos_next = PicPack5x7_index[my_char + 1];
00549 for(count = index_pos ; count < index_pos_next ; count++) {
00550 if (count < 256) {
00551 sliver = PicPack5x7_bitmap_0[count];
00552 } else {
00553 sliver = PicPack5x7_bitmap_1[count-256];
00554 }
00555
00556 if (pixel >= start_pixel) {
00557 s_count = 0;
00558 while (s_count < 7) {
00559 if (test_bit(sliver, 6)) {
00560 #if DRAW_HW_Y_ORIGIN == BOTTOM_LEFT
00561 draw_set_pixel(x, y + s_count, colour);
00562 #else
00563
00564 draw_set_pixel(x, y - s_count, colour);
00565 #endif
00566 }
00567 sliver <<= 1;
00568 s_count++;
00569 }
00570 x++;
00571 }
00572 if (x - x_origin == width) {
00573 return;
00574 }
00575 pixel++;
00576
00577
00578
00579 }
00580 str++;
00581 if (pixel >= start_pixel) {
00582 x++;
00583 }
00584 pixel++;
00585
00586 if (x - x_origin == width) {
00587 return;
00588 }
00589 }
00590 }
void draw_rect |
( |
uns8 |
x, |
|
|
uns8 |
y, |
|
|
uns16 |
width, |
|
|
uns8 |
height, |
|
|
uns8 |
colour | |
|
) |
| | |
00253 {
00254 uns16 dx, dy;
00255
00256 for(dy = y ; dy < y + height ; dy++) {
00257 for(dx = x ; dx < x + width ; dx++) {
00258 draw_set_pixel(dx, dy, colour);
00259
00260
00261
00262
00263
00264 }
00265 }
00266 }
void draw_set_pixel |
( |
uns8 |
x, |
|
|
uns8 |
y, |
|
|
uns8 |
colour | |
|
) |
| | |
00135 {
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
00168
00169 buffer_loc = buffer_loc * DRAW_BITS_PER_PIXEL;
00170
00171 loc_byte = buffer_loc / 8;
00172 loc_bit = (buffer_loc & (0x07));
00173
00174
00175
00176
00177
00178
00179 loc_in_buffer = loc_byte & 0xff;
00180 buffer_num = loc_byte >> 8;
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 if (buffer_num == 0) {
00202 buffer = &draw_buffer0;
00203 }
00204 #if DRAW_TOTAL_BUFFER_SIZE > 256
00205
00206 else if (buffer_num == 1) {
00207 buffer = &draw_buffer1;
00208
00209 }
00210 #if DRAW_TOTAL_BUFFER_SIZE > 512
00211 else if (buffer_num == 2) {
00212 buffer = &draw_buffer2;
00213
00214 }
00215 #if DRAW_TOTAL_BUFFER_SIZE > 768
00216 else if (buffer_num == 3) {
00217 buffer = &draw_buffer3;
00218
00219 }
00220 #endif
00221 #endif
00222 #endif
00223 #if DRAW_BITS_PER_PIXEL > 1
00224
00225 bit_count = 0;
00226
00227 while (bit_count < DRAW_BITS_PER_PIXEL) {
00228 if (test_bit(colour, bit_count)) {
00229 set_bit(buffer[loc_in_buffer], loc_bit);
00230 } else {
00231 clear_bit(buffer[loc_in_buffer], loc_bit);
00232 }
00233 bit_count++;
00234 loc_bit++;
00235 }
00236 #else
00237
00238 if (colour) {
00239 set_bit(buffer[loc_in_buffer], loc_bit);
00240 } else {
00241 clear_bit(buffer[loc_in_buffer], loc_bit);
00242 }
00243 #endif
00244
00245 }
Variable Documentation