gint/src/render-fx/drect.c
Lephe 94fb300e72
gray: finalize the gray engine API
* Define dgray() to replace gray_start() and gray_stop()
* Introduce a mechanism to override the d*() functions rather than using
  another set of functions, namely g*(). Gray rendering should now be
  done with d*() (a compatibility macro for g*() is available until v2.1).
* Gray engine now reserves TMU0 at the start of the add-in to prevent
  surprises if timers are exhausted, so it nevers fails to start
* Replace other gray engine functions with dgray_*()
* More general rendering functions (in render/) to lessen the burden of
  porting them to the gray engine. As a consequence, dtext_opt(),
  dprint_opt() and drect_border() are now available in the gray engine,
  which was an omission from 230b796.
* Allow C_NONE in more functions, mainly on fx-CG 50
* Remove the now-unused dupdate_noint()
2020-07-13 13:49:07 +02:00

49 lines
1,023 B
C

#include <gint/defs/util.h>
#include <gint/display.h>
#include <display/fx.h>
/* drect() - fill a rectangle of the screen */
void drect(int x1, int y1, int x2, int y2, int color)
{
if(x1 > x2) swap(x1, x2);
if(y1 > y2) swap(y1, y2);
/* Argument checking */
if(x1 >= 128 || x2 < 0 || y1 >= 64 || y2 < 0) return;
if(x1 < 0) x1 = 0;
if(x2 >= 128) x2 = 127;
if(y1 < 0) y1 = 0;
if(y2 >= 64) y2 = 63;
DMODE_OVERRIDE(drect, x1, y1, x2, y2, color);
/* Use masks to get the work done fast! */
uint32_t m[4];
masks(x1, x2, m);
uint32_t *base = gint_vram + (y1 << 2);
uint32_t *lword = gint_vram + (y2 << 2) + 4;
if(color == C_WHITE) while(lword > base)
{
*--lword &= ~m[3];
*--lword &= ~m[2];
*--lword &= ~m[1];
*--lword &= ~m[0];
}
else if(color == C_BLACK) while(lword > base)
{
*--lword |= m[3];
*--lword |= m[2];
*--lword |= m[1];
*--lword |= m[0];
}
else if(color == C_INVERT) while(lword > base)
{
*--lword ^= m[3];
*--lword ^= m[2];
*--lword ^= m[1];
*--lword ^= m[0];
}
}