From 0205c39f21db7e1411e0e59136f4f2d49c1fcbac Mon Sep 17 00:00:00 2001 From: lephe Date: Sun, 14 Aug 2016 19:57:58 +0200 Subject: [PATCH] Fixed area functions (rectangles completely outside the screen). --- Makefile | 2 +- TODO | 4 +++- include/internals/display.h | 3 ++- include/keyboard.h | 2 +- include/stdlib.h | 10 +++++++++- src/bopti/dimage.c | 2 +- src/bopti/dimage_part.c | 2 +- src/bopti/gimage.c | 2 +- src/bopti/gimage_part.c | 2 +- src/display/adjustRectangle.c | 7 ++++++- src/display/dclear_area.c | 2 +- src/display/dline.c | 2 +- src/display/dreverse_area.c | 2 +- src/tales/tales_internals.c | 1 + 14 files changed, 30 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 6081443..0789106 100644 --- a/Makefile +++ b/Makefile @@ -173,7 +173,7 @@ mrproper: clean distclean: mrproper install: - usb-connector SEND $(target-g1a) $(target-g1a) fls0 + CasioUsbUploader -f $(target-g1a) -w -l 1 .PHONY: all clean mrproper distclean diff --git a/TODO b/TODO index 9abcd57..cbef227 100644 --- a/TODO +++ b/TODO @@ -9,10 +9,12 @@ ~ needs investigation -@ possibility of vram overflow with text +@ possibility of vram left-overflow with text @ garbage displayed as year in the clock, possibly during edition (could not reproduce) +@ a few key hits ignored after leaving the application ++ rect functions + bitmap blending modes + minimize use of 7705.h and 7305.h; use local structures instead + partial transparency diff --git a/include/internals/display.h b/include/internals/display.h index ac8d4bd..d862f58 100644 --- a/include/internals/display.h +++ b/include/internals/display.h @@ -41,8 +41,9 @@ extern int *vram; - x1 < x2 - y1 < y2 which is needed when working with screen rectangles. + Returns non-zero if the rectangle is outside the screen. */ -void adjustRectangle(int *x1, int *y1, int *x2, int *y2); +int adjustRectangle(int *x1, int *y1, int *x2, int *y2); /* getMasks() diff --git a/include/keyboard.h b/include/keyboard.h index 7b57390..a3cf2c8 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -192,7 +192,7 @@ int getkey_opt(enum GetkeyOpt options, int max_cycles); Listens the keyboard for simultaneous key hits. This functions fills array `keys` with `count` keycodes, adding KEY_NONE at the end if - more than `count` keys are pressed. + less than `count` keys are pressed. If `max_cycles` is non-zero and nothing happens after `max_cycles` cycles, this function returns an array of KEY_NONE. diff --git a/include/stdlib.h b/include/stdlib.h index a8a2aac..1c2c520 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -101,8 +101,16 @@ void free(void *ptr); //--- /* - int rand(void) + rand() + Returns a pseudo-random number. */ +int rand(void); + +/* + srand() + Changes the seed used by rand(). +*/ +void srand(unsigned int seed); //--- // Integer arithmetic. diff --git a/src/bopti/dimage.c b/src/bopti/dimage.c index 9f28532..6b09ae5 100644 --- a/src/bopti/dimage.c +++ b/src/bopti/dimage.c @@ -7,7 +7,7 @@ */ void dimage(int x, int y, struct Image *img) { - if(img->magic != 0xb7) return; + if(!img || img->magic != 0xb7) return; struct Structure s; struct Command command; diff --git a/src/bopti/dimage_part.c b/src/bopti/dimage_part.c index 00d1977..06ef43b 100644 --- a/src/bopti/dimage_part.c +++ b/src/bopti/dimage_part.c @@ -10,7 +10,7 @@ void dimage_part(int x, int y, struct Image *img, int left, int top, int width, int height) { - if(img->magic != 0xb7) return; + if(!img || img->magic != 0xb7) return; struct Structure s; struct Command command; diff --git a/src/bopti/gimage.c b/src/bopti/gimage.c index e7499f4..4f8371e 100644 --- a/src/bopti/gimage.c +++ b/src/bopti/gimage.c @@ -8,7 +8,7 @@ */ void gimage(int x, int y, struct Image *img) { - if(img->magic != 0xb7) return; + if(!img || img->magic != 0xb7) return; struct Structure s; struct Command command; diff --git a/src/bopti/gimage_part.c b/src/bopti/gimage_part.c index abeb1b5..744a7c2 100644 --- a/src/bopti/gimage_part.c +++ b/src/bopti/gimage_part.c @@ -30,7 +30,7 @@ struct Rect intersect(struct Rect r1, struct Rect r2) void gimage_part(int x, int y, struct Image *img, int left, int top, int width, int height) { - if(img->magic != 0xb7) return; + if(!img || img->magic != 0xb7) return; struct Structure s; struct Command command; diff --git a/src/display/adjustRectangle.c b/src/display/adjustRectangle.c index a865e4f..f46f9b2 100644 --- a/src/display/adjustRectangle.c +++ b/src/display/adjustRectangle.c @@ -7,8 +7,9 @@ - x1 < x2 - y1 < y2 which is needed when working with screen rectangles. + Returns non-zero if the rectangle is outside the screen. */ -void adjustRectangle(int *x1, int *y1, int *x2, int *y2) +int adjustRectangle(int *x1, int *y1, int *x2, int *y2) { #define swap(a, b) tmp = a, a = b, b = tmp int tmp; @@ -16,9 +17,13 @@ void adjustRectangle(int *x1, int *y1, int *x2, int *y2) if(*x2 < *x1) swap(*x1, *x2); if(*y2 < *y1) swap(*y1, *y2); + if(*x1 > 127 || *y1 > 63 || *x2 < 0 || *y2 < 0) return 1; + if(*x1 < 0) *x1 = 0; if(*y1 < 0) *y1 = 0; if(*x2 > 127) *x2 = 127; if(*y2 > 63) *y2 = 63; + + return 0; #undef swap } diff --git a/src/display/dclear_area.c b/src/display/dclear_area.c index a8755c5..4cb4a70 100644 --- a/src/display/dclear_area.c +++ b/src/display/dclear_area.c @@ -9,7 +9,7 @@ void dclear_area(int x1, int y1, int x2, int y2) { uint32_t masks[4]; - adjustRectangle(&x1, &y1, &x2, &y2); + if(adjustRectangle(&x1, &y1, &x2, &y2)) return; getMasks(x1, x2, masks); int begin = y1 << 2; diff --git a/src/display/dline.c b/src/display/dline.c index 7a76173..e6e1422 100644 --- a/src/display/dline.c +++ b/src/display/dline.c @@ -67,7 +67,7 @@ static void dvline(int y1, int y2, int x, enum Color color) void dline(int x1, int y1, int x2, int y2, enum Color color) { - adjustRectangle(&x1, &y1, &x2, &y2); + if(adjustRectangle(&x1, &y1, &x2, &y2)) return; // Possible optimizations. if(y1 == y2) diff --git a/src/display/dreverse_area.c b/src/display/dreverse_area.c index 286f221..0288cbe 100644 --- a/src/display/dreverse_area.c +++ b/src/display/dreverse_area.c @@ -10,7 +10,7 @@ void dreverse_area(int x1, int y1, int x2, int y2) { uint32_t masks[4]; - adjustRectangle(&x1, &y1, &x2, &y2); + if(adjustRectangle(&x1, &y1, &x2, &y2)) return; getMasks(x1, x2, masks); int begin = y1 << 2; diff --git a/src/tales/tales_internals.c b/src/tales/tales_internals.c index a92ccac..4cb412a 100644 --- a/src/tales/tales_internals.c +++ b/src/tales/tales_internals.c @@ -262,6 +262,7 @@ void render(int x, int y, const char *str, void (*op)(OPERATE_ARGS)) // Allocating data. There will be one operator for each line. height = font->data_height; if(x > 127 || y > 63 || y <= -height) return; + if(y + height > 64) height = 64 - y; operators = alloca(height * sizeof(uint32_t)); for(i = 0; i < height; i++) operators[i] = 0;