diff --git a/rootfs.manifest b/rootfs.manifest index f3881fd..bd034fc 100644 --- a/rootfs.manifest +++ b/rootfs.manifest @@ -1024,9 +1024,25 @@ file /share/examples/c/tetris.c # Files: /share/examples/gpanel # dir /share/examples/gpanel +dir /share/examples/gpanel/fonts file /share/examples/gpanel/Makefile +file /share/examples/gpanel/circle.c +file /share/examples/gpanel/fill.c +file /share/examples/gpanel/font.c +file /share/examples/gpanel/line.c +file /share/examples/gpanel/pixel.c +file /share/examples/gpanel/rect.c file /share/examples/gpanel/tft.c file /share/examples/gpanel/tftetris.c +file /share/examples/gpanel/fonts/5x7.c +file /share/examples/gpanel/fonts/6x9.c +file /share/examples/gpanel/fonts/digits20.c +file /share/examples/gpanel/fonts/digits32.c +file /share/examples/gpanel/fonts/lucidasans11.c +file /share/examples/gpanel/fonts/lucidasans15.c +file /share/examples/gpanel/fonts/lucidasans7.c +file /share/examples/gpanel/fonts/lucidasans9.c +file /share/examples/gpanel/fonts/verdana7.c # # Files: /share/examples/smallc diff --git a/share/examples/gpanel/Makefile b/share/examples/gpanel/Makefile index 6e44238..38876c0 100644 --- a/share/examples/gpanel/Makefile +++ b/share/examples/gpanel/Makefile @@ -1,5 +1,9 @@ CC = cc -PROG = tft tftetris +LIBS = -lgpanel +PROG = tft tftetris pixel line rect fill circle font + +FONTS = 5x7.o 6x9.o digits20.o digits32.o lucidasans11.o lucidasans15.o \ + lucidasans7.o lucidasans9.o verdana7.o all: $(PROG) @@ -11,3 +15,48 @@ tft: tft.c tftetris: tftetris.c $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? + +pixel: pixel.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) + +line: line.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) + +rect: rect.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) + +fill: fill.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) + +circle: circle.c + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) $? $(LIBS) + +font: font.c $(FONTS) + $(CC) $(CFLAGS) -o $@ $(LDFLAGS) font.c $(FONTS) $(LIBS) + +5x7.o: fonts/5x7.c + $(CC) $(CFLAGS) -o $@ -c $? + +6x9.o: fonts/6x9.c + $(CC) $(CFLAGS) -o $@ -c $? + +digits20.o: fonts/digits20.c + $(CC) $(CFLAGS) -o $@ -c $? + +digits32.o: fonts/digits32.c + $(CC) $(CFLAGS) -o $@ -c $? + +lucidasans11.o: fonts/lucidasans11.c + $(CC) $(CFLAGS) -o $@ -c $? + +lucidasans15.o: fonts/lucidasans15.c + $(CC) $(CFLAGS) -o $@ -c $? + +lucidasans7.o: fonts/lucidasans7.c + $(CC) $(CFLAGS) -o $@ -c $? + +lucidasans9.o: fonts/lucidasans9.c + $(CC) $(CFLAGS) -o $@ -c $? + +verdana7.o: fonts/verdana7.c + $(CC) $(CFLAGS) -o $@ -c $? diff --git a/share/examples/gpanel/circle.c b/share/examples/gpanel/circle.c new file mode 100644 index 0000000..997e9d2 --- /dev/null +++ b/share/examples/gpanel/circle.c @@ -0,0 +1,33 @@ +/* + * Draw random circles. + */ +#include +#include + +int xsize, ysize; + +int main() +{ + char *devname = "/dev/tft0"; + int x, y, r, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + srandom(time(0)); + printf("Draw random circles.\n"); + printf("Press ^C to stop.\n"); + + for (;;) { + x = random() % xsize; + y = random() % ysize; + r = random() % ysize; + color = random(); + gpanel_circle(color, x, y, r); + } + return 0; +} diff --git a/share/examples/gpanel/fill.c b/share/examples/gpanel/fill.c new file mode 100644 index 0000000..678f0df --- /dev/null +++ b/share/examples/gpanel/fill.c @@ -0,0 +1,34 @@ +/* + * Draw random filled rectangles. + */ +#include +#include + +int xsize, ysize; + +int main() +{ + char *devname = "/dev/tft0"; + int x0, y0, x1, y1, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + srandom(time(0)); + printf("Draw random filled rectangles.\n"); + printf("Press ^C to stop.\n"); + + for (;;) { + x0 = random() % xsize; + y0 = random() % ysize; + x1 = random() % xsize; + y1 = random() % ysize; + color = random(); + gpanel_fill(color, x0, y0, x1, y1); + } + return 0; +} diff --git a/share/examples/gpanel/font.c b/share/examples/gpanel/font.c new file mode 100644 index 0000000..b868eab --- /dev/null +++ b/share/examples/gpanel/font.c @@ -0,0 +1,90 @@ +/* + * Draw samples of various fonts. + */ +#include +#include + +/* + * Data from external font files. + */ +extern const struct gpanel_font_t font_lucidasans15; +extern const struct gpanel_font_t font_lucidasans11; +extern const struct gpanel_font_t font_lucidasans9; +extern const struct gpanel_font_t font_lucidasans7; +extern const struct gpanel_font_t font_verdana7; +extern const struct gpanel_font_t font_6x9; +extern const struct gpanel_font_t font_5x7; +extern const struct gpanel_font_t font_digits32; +extern const struct gpanel_font_t font_digits20; + +/* + * Color constants. + */ +#define COLOR_RGB(r,g,b) ((r)<<11 | (g)<<5 | (b)) +#define COLOR_BLACK 0 +#define COLOR_WHITE COLOR_RGB(31, 63, 31) +#define COLOR_YELLOW COLOR_RGB(31, 63, 0) +#define COLOR_MAGENTA COLOR_RGB(31, 0, 31) +#define COLOR_CYAN COLOR_RGB(0, 63, 31) + +/* + * Screen size. + */ +int xsize, ysize; + +void show(const struct gpanel_font_t *font, const char *title, int digits_only) +{ + char line[100]; + int x = 10; + int y = 10; + + gpanel_clear(COLOR_BLACK, 0, 0); + gpanel_text(&font_lucidasans15, COLOR_WHITE, COLOR_BLACK, x, y, title); + y += font_lucidasans15.height; + + gpanel_text(font, COLOR_YELLOW, COLOR_BLACK, x, y, + digits_only ? "0123456789" + : "The quick brown fox"); + y += font->height; + + gpanel_text(font, COLOR_CYAN, COLOR_BLACK, x, y, + digits_only ? "3456789012" + : "jumps over"); + y += font->height; + + gpanel_text(font, COLOR_MAGENTA, COLOR_BLACK, x, y, + digits_only ? "6789012345" + : "the lazy dog."); + + printf("Font %s: press Enter...", title); + fflush(stdout); + fgets(line, sizeof(line), stdin); +} + +int main() +{ + char *devname = "/dev/tft0"; + int x, y, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + printf("Draw fonts.\n"); + printf("Press ^C to stop.\n"); + + for (;;) { + show(&font_lucidasans15, "Lucida Sans 15", 0); + show(&font_lucidasans11, "Lucida Sans 11", 0); + show(&font_lucidasans9, "Lucida Sans 9", 0); + show(&font_lucidasans7, "Lucida Sans 7", 0); + show(&font_verdana7, "Verdana 7", 0); + show(&font_6x9, "Fixed 6x9", 0); + show(&font_5x7, "Fixed 5x7", 0); + show(&font_digits32, "Digits 32", 1); + show(&font_digits20, "Digits 20", 1); + } + return 0; +} diff --git a/share/examples/gpanel/fonts/5x7.c b/share/examples/gpanel/fonts/5x7.c index 9720d9f..0a72bd9 100644 --- a/share/examples/gpanel/fonts/5x7.c +++ b/share/examples/gpanel/fonts/5x7.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */ +#include /* Font information: name: 5x7 @@ -4168,7 +4168,7 @@ static const unsigned short _5x7_offset[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_5x7 = { +const struct gpanel_font_t font_5x7 = { "5x7", 5, 7, diff --git a/share/examples/gpanel/fonts/6x9.c b/share/examples/gpanel/fonts/6x9.c index 0e5e6a9..135b37e 100644 --- a/share/examples/gpanel/fonts/6x9.c +++ b/share/examples/gpanel/fonts/6x9.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */ +#include /* Font information: name: 6x9 @@ -4808,7 +4808,7 @@ static const unsigned short _6x9_offset[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_6x9 = { +const struct gpanel_font_t font_6x9 = { "6x9", 6, 9, diff --git a/share/examples/gpanel/fonts/convbdf.c b/share/examples/gpanel/fonts/convbdf.c index c14fefc..f622593 100644 --- a/share/examples/gpanel/fonts/convbdf.c +++ b/share/examples/gpanel/fonts/convbdf.c @@ -733,7 +733,7 @@ gen_c_source(font_t *pf, char *path) char obuf[256]; char hdr1[] = { "/* Generated by convbdf on %s. */\n" - "#include \"gpanel.h\"\n" + "#include \n" "\n" "/* Font information:\n" " name: %s\n" @@ -894,7 +894,7 @@ gen_c_source(font_t *pf, char *path) sprintf(buf, "_%s_width,", pf->name); else sprintf(buf, "0, /* fixed width*/"); fprintf(ofp, "/* Exported structure definition. */\n" - "const gpanel_font_t font_%s = {\n" + "const struct gpanel_font_t font_%s = {\n" " \"%s\",\n" " %d,\n" " %d,\n" diff --git a/share/examples/gpanel/fonts/digits20.c b/share/examples/gpanel/fonts/digits20.c index 457662e..92ddf07 100644 --- a/share/examples/gpanel/fonts/digits20.c +++ b/share/examples/gpanel/fonts/digits20.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:54 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */ +#include /* Font information: name: digits20 @@ -670,7 +670,7 @@ static const unsigned char _digits20_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_digits20 = { +const struct gpanel_font_t font_digits20 = { "digits20", 18, 22, diff --git a/share/examples/gpanel/fonts/digits32.c b/share/examples/gpanel/fonts/digits32.c index 93422f8..95edf3e 100644 --- a/share/examples/gpanel/fonts/digits32.c +++ b/share/examples/gpanel/fonts/digits32.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:54 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */ +#include /* Font information: name: digits32 @@ -1102,7 +1102,7 @@ static const unsigned char _digits32_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_digits32 = { +const struct gpanel_font_t font_digits32 = { "digits32", 28, 40, diff --git a/share/examples/gpanel/fonts/lucidasans11.c b/share/examples/gpanel/fonts/lucidasans11.c index 6fb8ae0..4cb5c62 100644 --- a/share/examples/gpanel/fonts/lucidasans11.c +++ b/share/examples/gpanel/fonts/lucidasans11.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */ +#include /* Font information: name: lucidasans11 @@ -4038,7 +4038,7 @@ static const unsigned char _lucidasans11_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_lucidasans11 = { +const struct gpanel_font_t font_lucidasans11 = { "lucidasans11", 14, 17, diff --git a/share/examples/gpanel/fonts/lucidasans15.c b/share/examples/gpanel/fonts/lucidasans15.c index 012b5ea..b669203 100644 --- a/share/examples/gpanel/fonts/lucidasans15.c +++ b/share/examples/gpanel/fonts/lucidasans15.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:34 2015. */ +#include /* Font information: name: lucidasans15 @@ -4998,7 +4998,7 @@ static const unsigned char _lucidasans15_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_lucidasans15 = { +const struct gpanel_font_t font_lucidasans15 = { "lucidasans15", 20, 22, diff --git a/share/examples/gpanel/fonts/lucidasans7.c b/share/examples/gpanel/fonts/lucidasans7.c index 3ff6494..2bd27b3 100644 --- a/share/examples/gpanel/fonts/lucidasans7.c +++ b/share/examples/gpanel/fonts/lucidasans7.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */ +#include /* Font information: name: lucidasans7 @@ -2502,7 +2502,7 @@ static const unsigned char _lucidasans7_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_lucidasans7 = { +const struct gpanel_font_t font_lucidasans7 = { "lucidasans7", 9, 9, diff --git a/share/examples/gpanel/fonts/lucidasans9.c b/share/examples/gpanel/fonts/lucidasans9.c index 40b223f..6ea1c2f 100644 --- a/share/examples/gpanel/fonts/lucidasans9.c +++ b/share/examples/gpanel/fonts/lucidasans9.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */ +#include /* Font information: name: lucidasans9 @@ -3462,7 +3462,7 @@ static const unsigned char _lucidasans9_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_lucidasans9 = { +const struct gpanel_font_t font_lucidasans9 = { "lucidasans9", 12, 14, diff --git a/share/examples/gpanel/fonts/verdana7.c b/share/examples/gpanel/fonts/verdana7.c index b37e3b0..2a3b7f5 100644 --- a/share/examples/gpanel/fonts/verdana7.c +++ b/share/examples/gpanel/fonts/verdana7.c @@ -1,5 +1,5 @@ -/* Generated by convbdf on Mon Oct 5 14:07:55 2015. */ -#include "gpanel.h" +/* Generated by convbdf on Thu Oct 8 21:26:35 2015. */ +#include /* Font information: name: verdana7 @@ -2694,7 +2694,7 @@ static const unsigned char _verdana7_width[] = { }; /* Exported structure definition. */ -const gpanel_font_t font_verdana7 = { +const struct gpanel_font_t font_verdana7 = { "verdana7", 11, 10, diff --git a/share/examples/gpanel/line.c b/share/examples/gpanel/line.c new file mode 100644 index 0000000..1a87a51 --- /dev/null +++ b/share/examples/gpanel/line.c @@ -0,0 +1,34 @@ +/* + * Draw random lines. + */ +#include +#include + +int xsize, ysize; + +int main() +{ + char *devname = "/dev/tft0"; + int x0, y0, x1, y1, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + srandom(time(0)); + printf("Draw random lines.\n"); + printf("Press ^C to stop.\n"); + + for (;;) { + x0 = random() % xsize; + y0 = random() % ysize; + x1 = random() % xsize; + y1 = random() % ysize; + color = random(); + gpanel_line(color, x0, y0, x1, y1); + } + return 0; +} diff --git a/share/examples/gpanel/pixel.c b/share/examples/gpanel/pixel.c new file mode 100644 index 0000000..33c5e0f --- /dev/null +++ b/share/examples/gpanel/pixel.c @@ -0,0 +1,32 @@ +/* + * Draw random pixels. + */ +#include +#include + +int xsize, ysize; + +int main() +{ + char *devname = "/dev/tft0"; + int x, y, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + srandom(time(0)); + printf("Draw random pixels.\n"); + printf("Press ^C to stop.\n"); + + for (;;) { + x = random() % xsize; + y = random() % ysize; + color = random(); + gpanel_pixel(color, x, y); + } + return 0; +} diff --git a/share/examples/gpanel/rect.c b/share/examples/gpanel/rect.c new file mode 100644 index 0000000..433e54d --- /dev/null +++ b/share/examples/gpanel/rect.c @@ -0,0 +1,34 @@ +/* + * Draw random rectangles. + */ +#include +#include + +int xsize, ysize; + +int main() +{ + char *devname = "/dev/tft0"; + int x0, y0, x1, y1, color; + + if (gpanel_open(devname) < 0) { + printf("Cannot open %s\n", devname); + exit(-1); + } + gpanel_clear(0, &xsize, &ysize); + printf("Screen size %u x %u.\n", xsize, ysize); + + srandom(time(0)); + printf("Draw random rectangles.\n"); + printf("Press ^C to stop.\n"); + + for (;;) { + x0 = random() % xsize; + y0 = random() % ysize; + x1 = random() % xsize; + y1 = random() % ysize; + color = random(); + gpanel_rect(color, x0, y0, x1, y1); + } + return 0; +} diff --git a/src/libc/compat/rand.c b/src/libc/compat/rand.c index 383fce3..5b51eac 100644 --- a/src/libc/compat/rand.c +++ b/src/libc/compat/rand.c @@ -15,9 +15,6 @@ srand(x) int rand() { -#ifdef pdp11 - return(((randx = randx * 1103515245 + 12345)>>16) & 0x7fff); -#else - return((randx = randx * 1103515245 + 12345) & 0x7fffffff); -#endif + randx = randx * 1103515245 + 12345; + return (randx >> 16) & 0x7fff; } diff --git a/sys/pic32/hx8357.c b/sys/pic32/hx8357.c index fcf7ed6..2bf6f3e 100644 --- a/sys/pic32/hx8357.c +++ b/sys/pic32/hx8357.c @@ -254,6 +254,15 @@ static void fillRectangle(int x0, int y0, int x1, int y1, int color) { int x, y; + if (x0 < 0) x0 = 0; + if (y0 < 0) x0 = 0; + if (x1 < 0) x1 = 0; + if (y1 < 0) x1 = 0; + if (x0 >= _width) x0 = _width-1; + if (x1 >= _width) x1 = _width-1; + if (y0 >= _height) y0 = _height-1; + if (y1 >= _height) y1 = _height-1; + if (x1 < x0) { int t = x0; x0 = x1; @@ -264,12 +273,12 @@ static void fillRectangle(int x0, int y0, int x1, int y1, int color) y0 = y1; y1 = t; } - setAddrWindow(x0, y0, x1-1, y1-1); + setAddrWindow(x0, y0, x1, y1); while (PMMODE & PIC32_PMMODE_BUSY); PMADDR = 0x0001; - for (y=y0; y