Fixed area functions (rectangles completely outside the screen).

This commit is contained in:
lephe 2016-08-14 19:57:58 +02:00
parent a39cc09001
commit 0205c39f21
14 changed files with 30 additions and 13 deletions

View file

@ -173,7 +173,7 @@ mrproper: clean
distclean: mrproper distclean: mrproper
install: install:
usb-connector SEND $(target-g1a) $(target-g1a) fls0 CasioUsbUploader -f $(target-g1a) -w -l 1
.PHONY: all clean mrproper distclean .PHONY: all clean mrproper distclean

4
TODO
View file

@ -9,10 +9,12 @@
~ needs investigation ~ 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 @ garbage displayed as year in the clock, possibly during edition (could not
reproduce) reproduce)
@ a few key hits ignored after leaving the application
+ rect functions
+ bitmap blending modes + bitmap blending modes
+ minimize use of 7705.h and 7305.h; use local structures instead + minimize use of 7705.h and 7305.h; use local structures instead
+ partial transparency + partial transparency

View file

@ -41,8 +41,9 @@ extern int *vram;
- x1 < x2 - x1 < x2
- y1 < y2 - y1 < y2
which is needed when working with screen rectangles. 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() getMasks()

View file

@ -192,7 +192,7 @@ int getkey_opt(enum GetkeyOpt options, int max_cycles);
Listens the keyboard for simultaneous key hits. This functions fills Listens the keyboard for simultaneous key hits. This functions fills
array `keys` with `count` keycodes, adding KEY_NONE at the end if 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` If `max_cycles` is non-zero and nothing happens after `max_cycles`
cycles, this function returns an array of KEY_NONE. cycles, this function returns an array of KEY_NONE.

View file

@ -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. // Integer arithmetic.

View file

@ -7,7 +7,7 @@
*/ */
void dimage(int x, int y, struct Image *img) void dimage(int x, int y, struct Image *img)
{ {
if(img->magic != 0xb7) return; if(!img || img->magic != 0xb7) return;
struct Structure s; struct Structure s;
struct Command command; struct Command command;

View file

@ -10,7 +10,7 @@
void dimage_part(int x, int y, struct Image *img, int left, int top, void dimage_part(int x, int y, struct Image *img, int left, int top,
int width, int height) int width, int height)
{ {
if(img->magic != 0xb7) return; if(!img || img->magic != 0xb7) return;
struct Structure s; struct Structure s;
struct Command command; struct Command command;

View file

@ -8,7 +8,7 @@
*/ */
void gimage(int x, int y, struct Image *img) void gimage(int x, int y, struct Image *img)
{ {
if(img->magic != 0xb7) return; if(!img || img->magic != 0xb7) return;
struct Structure s; struct Structure s;
struct Command command; struct Command command;

View file

@ -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, void gimage_part(int x, int y, struct Image *img, int left, int top,
int width, int height) int width, int height)
{ {
if(img->magic != 0xb7) return; if(!img || img->magic != 0xb7) return;
struct Structure s; struct Structure s;
struct Command command; struct Command command;

View file

@ -7,8 +7,9 @@
- x1 < x2 - x1 < x2
- y1 < y2 - y1 < y2
which is needed when working with screen rectangles. 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 #define swap(a, b) tmp = a, a = b, b = tmp
int tmp; int tmp;
@ -16,9 +17,13 @@ void adjustRectangle(int *x1, int *y1, int *x2, int *y2)
if(*x2 < *x1) swap(*x1, *x2); if(*x2 < *x1) swap(*x1, *x2);
if(*y2 < *y1) swap(*y1, *y2); if(*y2 < *y1) swap(*y1, *y2);
if(*x1 > 127 || *y1 > 63 || *x2 < 0 || *y2 < 0) return 1;
if(*x1 < 0) *x1 = 0; if(*x1 < 0) *x1 = 0;
if(*y1 < 0) *y1 = 0; if(*y1 < 0) *y1 = 0;
if(*x2 > 127) *x2 = 127; if(*x2 > 127) *x2 = 127;
if(*y2 > 63) *y2 = 63; if(*y2 > 63) *y2 = 63;
return 0;
#undef swap #undef swap
} }

View file

@ -9,7 +9,7 @@
void dclear_area(int x1, int y1, int x2, int y2) void dclear_area(int x1, int y1, int x2, int y2)
{ {
uint32_t masks[4]; uint32_t masks[4];
adjustRectangle(&x1, &y1, &x2, &y2); if(adjustRectangle(&x1, &y1, &x2, &y2)) return;
getMasks(x1, x2, masks); getMasks(x1, x2, masks);
int begin = y1 << 2; int begin = y1 << 2;

View file

@ -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) 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. // Possible optimizations.
if(y1 == y2) if(y1 == y2)

View file

@ -10,7 +10,7 @@
void dreverse_area(int x1, int y1, int x2, int y2) void dreverse_area(int x1, int y1, int x2, int y2)
{ {
uint32_t masks[4]; uint32_t masks[4];
adjustRectangle(&x1, &y1, &x2, &y2); if(adjustRectangle(&x1, &y1, &x2, &y2)) return;
getMasks(x1, x2, masks); getMasks(x1, x2, masks);
int begin = y1 << 2; int begin = y1 << 2;

View file

@ -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. // Allocating data. There will be one operator for each line.
height = font->data_height; height = font->data_height;
if(x > 127 || y > 63 || y <= -height) return; if(x > 127 || y > 63 || y <= -height) return;
if(y + height > 64) height = 64 - y;
operators = alloca(height * sizeof(uint32_t)); operators = alloca(height * sizeof(uint32_t));
for(i = 0; i < height; i++) operators[i] = 0; for(i = 0; i < height; i++) operators[i] = 0;