Author Topic: Finish that grayscale engine  (Read 5972 times)

0 Members and 1 Guest are viewing this topic.

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Finish that grayscale engine
« on: May 09, 2012, 02:14:24 pm »
#include "draw.h"
#include "gray.h"

void draw_bmp(unsigned char* bmp, int x, int y, int width, int height, Buffer buffer, DrawMode drawmode)
{
   char* screen;
   if(buffer == LIGHT_BUFFER)
      screen = gray_getScreen()->VRAM1;
   else
      screen = gray_getScreen()->VRAM2;

   switch(drawmode) {
      case OR: draw_bmp_or_cl(bmp, x, y, width, height, screen); break;
      case AND: draw_bmp_and_cl(bmp, x, y, width, height, screen); break;
      case AND_NOT: draw_bmp_andnot_cl(bmp, x, y, width, height, screen); break;
   }
}

int draw_read_pix(int x, int y, char* light_buffer, char* dark_buffer)
{
   char color;
   if(x<0 || y<0 || x>127 || y>63) return 0;
   color = (light_buffer[(y<<4)+(x>>3)]&128>>(x&7) ? 1 : 0);
   color |= (dark_buffer[(y<<4)+(x>>3)]&128>>(x&7) ? 2 : 0);
   return color;
}

void draw_write_pix(int x, int y, int color, char* light_buffer, char* dark_buffer)
{
   if(x<0 || y<0 || x>127 || y>63) return;
   if(color < 0) color = 0;
   else if(color > 3) color = 3;

   if(color & 1) light_buffer[(y<<4)+(x>>3)] |= 128>>(x&7);
   else light_buffer[(y<<4)+(x>>3)] &= ~(unsigned char)(128>>(x&7));
   if(color & 2) dark_buffer[(y<<4)+(x>>3)] |= 128>>(x&7);
   else dark_buffer[(y<<4)+(x>>3)] &= ~(unsigned char)(128>>(x&7));
}


void draw_bmp_or_cl(unsigned char *bmp, int x, int y, int width, int height, char* buffer)
{
   unsigned short line;
   char shift, *screen, *p;
   int i, j, real_width, begin_x, end_x, begin_y, end_y;
   char bool1=1, bool2=1, bool3;
   if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return;
   p = (char*)&line;
   real_width = (width-1>>3<<3)+8;
   if(y < 0) begin_y = -y;
   else begin_y = 0;
   if(y+height > 64) end_y = 64-y;
   else end_y = height;
   shift = 8-(x&7);
   if(x<0)
   {
      begin_x = -x>>3;
      if(shift != 8) bool1 = 0;
   } else begin_x = 0;
   if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0;
   else end_x = real_width-1>>3;
   bool3 = (end_x == real_width-1>>3);
   screen = buffer+(y+begin_y<<4)+(x>>3);

   for(i=begin_y ; i<end_y ; i++)
   {
      if(begin_x < end_x)
      {
         line = bmp[i*(real_width>>3)+begin_x] << shift;
         if(bool1) screen[begin_x] |= *p;
         if(shift!=8) screen[begin_x+1] |= *(p+1);
         for(j=begin_x+1 ; j<end_x ; j++)
         {
            line = bmp[i*(real_width>>3)+j] << shift;
            screen[j] |= *p;
            if(shift!=8) screen[j+1] |= *(p+1);
         }
      }
      line = bmp[i*(real_width>>3)+end_x];
      if(bool3) line &= -1<<real_width-width;
      line <<= shift;
      if(begin_x < end_x || bool1) screen[end_x] |= *p;
      if(bool2) screen[end_x+1] |= *(p+1);
      screen += 16;
   }
}

void draw_bmp_and_cl(unsigned char *bmp, int x, int y, int width, int height, char* buffer)
{
   unsigned short line;
   char shift, *screen, *p;
   int i, j, real_width, begin_x, end_x, begin_y, end_y;
   char bool1=1, bool2=1, bool3;
   if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return;
   p = (char*)&line;
   real_width = (width-1>>3<<3)+8;
   if(y < 0) begin_y = -y;
   else begin_y = 0;
   if(y+height > 64) end_y = 64-y;
   else end_y = height;
   shift = 8-(x&7);
   if(x<0)
   {
      begin_x = -x>>3;
      if(shift != 8) bool1 = 0;
   } else begin_x = 0;
   if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0;
   else end_x = real_width-1>>3;
   bool3 = (end_x == real_width-1>>3);
   screen = buffer+(y+begin_y<<4)+(x>>3);

   for(i=begin_y ; i<end_y ; i++)
   {
      if(begin_x < end_x)

      {
         line = ~((unsigned char)~bmp[i*(real_width>>3)+begin_x]<<shift);
         if(bool1) screen[begin_x] &= *p;
         if(shift!=8) screen[begin_x+1] &= *(p+1);
         for(j=begin_x+1 ; j<end_x ; j++)
         {
            line = ~((unsigned char)~bmp[i*(real_width>>3)+j]<<shift);
            screen[j] &= *p;
            if(shift!=8) screen[j+1] &= *(p+1);
         }
      }
      line = (unsigned char)~bmp[i*(real_width>>3)+end_x];
      if(bool3) line &= -1<<real_width-width;
      line = ~(line << shift);
      if(begin_x < end_x || bool1) screen[end_x] &= *p;
      if(bool2) screen[end_x+1] &= *(p+1);
      screen += 16;
   }
}

void draw_bmp_andnot_cl(unsigned char *bmp, int x, int y, int width, int height, char* buffer)
{
   unsigned short line;
   char shift, *screen, *p;
   int i, j, real_width, begin_x, end_x, begin_y, end_y;
   char bool1=1, bool2=1, bool3;
   if(!bmp || x<1-width || x>127 || y<1-height || y>63 || height<1 || width<1) return;
   p = (char*)&line;
   real_width = (width-1>>3<<3)+8;
   if(y < 0) begin_y = -y;
   else begin_y = 0;
   if(y+height > 64) end_y = 64-y;
   else end_y = height;
   shift = 8-(x&7);
   if(x<0)
   {
      begin_x = -x>>3;
      if(shift != 8) bool1 = 0;
   } else begin_x = 0;
   if(x+real_width > 128) end_x = 15-(x>>3), bool2 = 0;
   else end_x = real_width-1>>3;
   bool3 = (end_x == real_width-1>>3);
   screen = buffer+(y+begin_y<<4)+(x>>3);

   for(i=begin_y ; i<end_y ; i++)
   {
      if(begin_x < end_x)

      {
         line = ~(bmp[i*(real_width>>3)+begin_x]<<shift);
         if(bool1) screen[begin_x] &= *p;
         if(shift!=8) screen[begin_x+1] &= *(p+1);
         for(j=begin_x+1 ; j<end_x ; j++)
         {
            line = ~(bmp[i*(real_width>>3)+j]<<shift);
            screen[j] &= *p;
            if(shift!=8) screen[j+1] &= *(p+1);
         }
      }
      line = bmp[i*(real_width>>3)+end_x];
      if(bool3) line &= -1<<real_width-width;
      line = ~(line << shift);
      if(begin_x < end_x || bool1) screen[end_x] &= *p;
      if(bool2) screen[end_x+1] &= *(p+1);
      screen += 16;
   }
}
« Last Edit: May 10, 2012, 01:33:49 pm by Eiyeron »

Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: Finish that grayscale engine
« Reply #1 on: May 10, 2012, 09:10:52 am »
Wow, that is awesome!

Is he using it in LuaFX? That way we could maybe exit to the LuaFX menu instead of rebooting....

This piece of code certainly has potential...



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Finish that grayscale engine
« Reply #2 on: May 10, 2012, 10:58:39 am »
Don't use it atm, I messed it quite bit fiddling to search the good sequence
EDIT: found something useful into debugging: INTC.INTEVT seems to be edited for some reasons... We must found why, and avoir this
« Last Edit: May 10, 2012, 01:01:43 pm by Eiyeron »

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Finish that grayscale engine
« Reply #3 on: May 10, 2012, 01:34:34 pm »
Spoiler For POST NOT FOUND:
Bump for announcement: The grayscale engine seems to be STABLE! No need to reboot anymore! I need more testing, but I think here we are

PS : 404th post :-°
« Last Edit: May 10, 2012, 01:35:21 pm by Eiyeron »

Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: Finish that grayscale engine
« Reply #4 on: May 10, 2012, 04:10:09 pm »
looks good... why don't you wrap the code in [code ][ /code] tags?
« Last Edit: May 10, 2012, 04:10:25 pm by flyingfisch »



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Finish that grayscale engine
« Reply #5 on: May 11, 2012, 08:50:00 am »
Whoops, I made a little mistake posting: frogotten to take the old post.
Anyway, I'll adapt MonochromeLib to grayscales, GrayscaleLib.
I have already finished the graphics routines, the sprites will come later.

How could I store 3 sprites easily and user-friendly? (dark, light and alpha)

Offline flyingfisch

  • I'm 1337 now!
  • Members
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1620
  • Rating: +94/-17
  • Testing, testing, 1...2...3...4...5...6...7...8..9
    • View Profile
    • Top Page Website Design
Re: Finish that grayscale engine
« Reply #6 on: May 11, 2012, 09:01:07 am »
in arrays?



Quote from: my dad
"welcome to the world of computers, where everything seems to be based on random number generators"



The Game V. 2.0

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Finish that grayscale engine
« Reply #7 on: May 11, 2012, 09:47:47 am »
For which project is this? ALso is it for the Algebra FX/Graph 100 series or for the FX-9860G/Graph 85?

Offline Eiyeron

  • Urist McEiyolobster
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1430
  • Rating: +130/-10
  • (-_(//));
    • View Profile
    • Rétro-Actif : Rétro/Prog/Blog
Re: Finish that grayscale engine
« Reply #8 on: May 11, 2012, 10:29:30 am »
Fx, we have already 5 gray mode in afx...
I don't know how? Tiple arrays, one combined array, or a struct