gint/src/gray/gpixel.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

58 lines
986 B
C

#include <gint/gray.h>
#include <gint/defs/types.h>
/* gpixel(): Change a pixel's color */
void gpixel(int x, int y, color_t color)
{
uint32_t *light, *dark;
dgray_getvram(&light, &dark);
int offset = (y << 2) + (x >> 5);
uint32_t mask = 1 << (~x & 31), tmp;
switch(color)
{
case C_WHITE:
light[offset] &= ~mask;
dark [offset] &= ~mask;
break;
case C_LIGHT:
light[offset] |= mask;
dark [offset] &= ~mask;
break;
case C_DARK:
light[offset] &= ~mask;
dark [offset] |= mask;
break;
case C_BLACK:
light[offset] |= mask;
dark [offset] |= mask;
break;
case C_NONE:
break;
case C_INVERT:
light[offset] ^= mask;
dark [offset] ^= mask;
break;
case C_LIGHTEN:
tmp = dark[offset];
dark[offset] &= light[offset] | ~mask;
light[offset] = (light[offset] ^ mask) & (tmp | ~mask);
break;
case C_DARKEN:
tmp = dark[offset];
dark[offset] |= light[offset] & mask;
light[offset] = (light[offset] ^ mask) | (tmp & mask);
break;
}
}