*** /dev/null
--- /dev/null
***************
*** 61,66 ****
                                  (COLOR_ADDb((l >> 8) & 0xFF, g) << 16) | \
                                  (COLOR_ADDb((l >> 16) & 0xFF, b) << 8) | \
                                  ((l >> 24) & 0xFF)
  #else
  #define COLOR_ADD(l,r,g,b)	COLOR_ADDb((l & 0xFF), r) | \
                                  (COLOR_ADDb((l >> 8) & 0xFF, g) << 8) | \
--- 65,80 ----
                                  (COLOR_ADDb((l >> 8) & 0xFF, g) << 16) | \
                                  (COLOR_ADDb((l >> 16) & 0xFF, b) << 8) | \
                                  ((l >> 24) & 0xFF)
+ #ifdef GEKKO
+ #define COLOR_ADDBIG(l,r,g,b)   (COLOR_ADDb((l >> 24), r) << 24) | \
+                                 (COLOR_ADDb((l >> 16) & 0xFF, g) << 16) | \
+                                 (COLOR_ADDb((l >> 8) & 0xFF, b) << 8) |   \
+                                 (l & 0xFF)
+ #define COLOR_ADD16LIT(l,r,g,b) (COLOR_ADDb((l << 3) & 0xF8, r)) |       \
+                                 (COLOR_ADDb((l >> 2) & 0xF8, g) << 8) |  \
+                                 (COLOR_ADDb((l >> 7) & 0xF8, b) << 16) | \
+                                 (l & 0x8000)
+ #endif
  #else
  #define COLOR_ADD(l,r,g,b)	COLOR_ADDb((l & 0xFF), r) | \
                                  (COLOR_ADDb((l >> 8) & 0xFF, g) << 8) | \
***************
*** 148,153 ****
  
  static int vdp1width;
  static int vdp1height;
  static int vdp1clipxstart;
  static int vdp1clipxend;
  static int vdp1clipystart;
--- 162,172 ----
  
  static int vdp1width;
  static int vdp1height;
+ #ifdef GEKKO
+ int vdp1w;
+ int vdp1h;
+ extern int specialcoloron;
+ #endif
  static int vdp1clipxstart;
  static int vdp1clipxend;
  static int vdp1clipystart;
***************
*** 197,204 ****
  static INLINE u8 Vdp2GetPixelPriority(u32 pixel)
  {
  #if defined WORDS_BIGENDIAN
     return pixel;
  #else
     return pixel >> 24;
  #endif
  }
--- 216,227 ----
  static INLINE u8 Vdp2GetPixelPriority(u32 pixel)
  {
  #if defined WORDS_BIGENDIAN
+ #ifndef GEKKO
     return pixel;
  #else
+    return (pixel & 0xFF);
+ #endif
+ #else
     return pixel >> 24;
  #endif
  }
***************
*** 333,339 ****
  
  static INLINE u32 FASTCALL DoColorOffset(void *info, u32 pixel)
  {
      return COLOR_ADD(pixel, ((vdp2draw_struct *)info)->cor,
                       ((vdp2draw_struct *)info)->cog,
                       ((vdp2draw_struct *)info)->cob);
  }
--- 356,366 ----
  
  static INLINE u32 FASTCALL DoColorOffset(void *info, u32 pixel)
  {
+ #ifndef GEKKO
      return COLOR_ADD(pixel, ((vdp2draw_struct *)info)->cor,
+ #else
+     return COLOR_ADDBIG(pixel, ((vdp2draw_struct *)info)->cor,
+ #endif
                       ((vdp2draw_struct *)info)->cog,
                       ((vdp2draw_struct *)info)->cob);
  }
***************
*** 342,379 ****
  
  static INLINE u32 FASTCALL DoColorCalc(void *info, u32 pixel)
  {
! #if 0
     u8 oldr, oldg, oldb;
     u8 r, g, b;
!    u32 oldpixel = 0x00FFFFFF; // fix me
  
!    static int topratio[32] = {
        31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
        15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
     };
!    static int bottomratio[32] = {
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
     };
  
     // separate color components for top and second pixel
!    r = (pixel & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
!    g = ((pixel >> 8) & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
!    b = ((pixel >> 16) & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
  
  #ifdef WORDS_BIGENDIAN
!    oldr = ((oldpixel >> 24) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldg = ((oldpixel >> 16) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldb = ((oldpixel >> 8) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
  #else
     oldr = (oldpixel & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldg = ((oldpixel >> 8) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldb = ((oldpixel >> 16) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
  #endif
  
     // add color components and reform the pixel
     pixel = ((b + oldb) << 16) | ((g + oldg) << 8) | (r + oldr);
  #endif
     return pixel;
  }
  
--- 369,446 ----
  
  static INLINE u32 FASTCALL DoColorCalc(void *info, u32 pixel)
  {
! #ifdef GEKKO
     u8 oldr, oldg, oldb;
     u8 r, g, b;
!    //u32 oldpixel = 0x00FFFFFF; // fix me
!    u32 oldpixel = ((vdp2draw_struct *)info)->oldpixel;
  
!    static const int topratio[32] = {
        31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16,
        15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
     };
!    static const int bottomratio[32] = {
        1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
        17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32
     };
  
+    if(((vdp2draw_struct *)info)->colorcalcmode)
+    {
+ #ifdef WORDS_BIGENDIAN
     // separate color components for top and second pixel
!    r = (pixel >> 24);
!    g = ((pixel >> 16) & 0xFF);
!    b = ((pixel >> 8) & 0xFF);
!    oldr = (oldpixel >> 24);
!    oldg = ((oldpixel >> 16) & 0xFF);
!    oldb = ((oldpixel >> 8) & 0xFF);
! #else
!    // separate color components for top and second pixel
!    r = (pixel & 0xFF);
!    g = ((pixel >> 8) & 0xFF);
!    b = ((pixel >> 16) & 0xFF);
!    oldr = (oldpixel & 0xFF);
!    oldg = ((oldpixel >> 8) & 0xFF);
!    oldb = ((oldpixel >> 16) & 0xFF);
! #endif
! 
!    // add color components and reform the pixel
! #ifdef WORDS_BIGENDIAN
!    pixel = (COLOR_ADDb(b, oldb) << 8) | (COLOR_ADDb(g, oldg) << 16) | (COLOR_ADDb(r, oldr) << 24) | (pixel & 0xFF);
! #else
!    pixel = (COLOR_ADDb(b, oldb) << 16) | (COLOR_ADDb(g, oldg) << 8) | COLOR_ADDb(r, oldr);
! #endif
! 
!    }
!    else
!    {
  
  #ifdef WORDS_BIGENDIAN
!    // separate color components for top and second pixel
!    r = (pixel >> 24) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
!    g = ((pixel >> 16) & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
!    b = ((pixel >> 8) & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
!    oldr = (oldpixel >> 24) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldg = ((oldpixel >> 16) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldb = ((oldpixel >> 8) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
  #else
+    // separate color components for top and second pixel
+    r = (pixel & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
+    g = ((pixel >> 8) & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
+    b = ((pixel >> 16) & 0xFF) * topratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldr = (oldpixel & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldg = ((oldpixel >> 8) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
     oldb = ((oldpixel >> 16) & 0xFF) * bottomratio[((vdp2draw_struct *)info)->alpha] >> 5;
  #endif
  
     // add color components and reform the pixel
+ #ifdef WORDS_BIGENDIAN
+    pixel = ((b + oldb) << 8) | ((g + oldg) << 16) | ((r + oldr) << 24) | (pixel & 0xFF);
+ #else
     pixel = ((b + oldb) << 16) | ((g + oldg) << 8) | (r + oldr);
  #endif
+    }
+ #endif
     return pixel;
  }
  
***************
*** 383,389 ****
  {
     pixel = DoColorCalc(info, pixel);
  
     return COLOR_ADD(pixel, ((vdp2draw_struct *)info)->cor,
                      ((vdp2draw_struct *)info)->cog,
                      ((vdp2draw_struct *)info)->cob);
  }
--- 450,460 ----
  {
     pixel = DoColorCalc(info, pixel);
  
+ #ifndef GEKKO
     return COLOR_ADD(pixel, ((vdp2draw_struct *)info)->cor,
+ #else
+    return COLOR_ADDBIG(pixel, ((vdp2draw_struct *)info)->cor,
+ #endif
                      ((vdp2draw_struct *)info)->cog,
                      ((vdp2draw_struct *)info)->cob);
  }
***************
*** 392,397 ****
  
  static INLINE void ReadVdp2ColorOffset(vdp2draw_struct *info, int clofmask, int ccmask)
  {
     if (Vdp2Regs->CLOFEN & clofmask)
     {
        // color offset enable
--- 463,471 ----
  
  static INLINE void ReadVdp2ColorOffset(vdp2draw_struct *info, int clofmask, int ccmask)
  {
+ #ifdef GEKKO
+    info->cor = info->cog = info->cob = 0;
+ #endif
     if (Vdp2Regs->CLOFEN & clofmask)
     {
        // color offset enable
***************
*** 428,441 ****
  
        if (info->cor == 0 && info->cog == 0 && info->cob == 0)
        {
           if (Vdp2Regs->CCCTL & ccmask)
              info->PostPixelFetchCalc = &DoColorCalc;
           else
              info->PostPixelFetchCalc = &DoNothing;
        }
        else
        {
           if (Vdp2Regs->CCCTL & ccmask)
              info->PostPixelFetchCalc = &DoColorCalcWithColorOffset;
           else
              info->PostPixelFetchCalc = &DoColorOffset;
--- 502,523 ----
  
        if (info->cor == 0 && info->cog == 0 && info->cob == 0)
        {
+ #ifndef GEKKO
           if (Vdp2Regs->CCCTL & ccmask)
+ #else
+          if ((Vdp2Regs->CCCTL & ccmask) && specialcoloron)
+ #endif
              info->PostPixelFetchCalc = &DoColorCalc;
           else
              info->PostPixelFetchCalc = &DoNothing;
        }
        else
        {
+ #ifndef GEKKO
           if (Vdp2Regs->CCCTL & ccmask)
+ #else
+          if ((Vdp2Regs->CCCTL & ccmask) && specialcoloron)
+ #endif
              info->PostPixelFetchCalc = &DoColorCalcWithColorOffset;
           else
              info->PostPixelFetchCalc = &DoColorOffset;
***************
*** 443,453 ****
     }
     else // color offset disable
     {
        if (Vdp2Regs->CCCTL & ccmask)
           info->PostPixelFetchCalc = &DoColorCalc;
        else
           info->PostPixelFetchCalc = &DoNothing;
     }
  
  }
  
--- 525,545 ----
     }
     else // color offset disable
     {
+ #ifndef GEKKO
        if (Vdp2Regs->CCCTL & ccmask)
+ #else
+       if ((Vdp2Regs->CCCTL & ccmask) && specialcoloron)
+ #endif
           info->PostPixelFetchCalc = &DoColorCalc;
        else
           info->PostPixelFetchCalc = &DoNothing;
     }
+ #ifdef GEKKO
+    if ((Vdp2Regs->CCCTL & ccmask) && specialcoloron)
+       info->docolorcalcenable = 1;
+    else
+       info->docolorcalcenable = 0;
+ #endif
  
  }
  
***************
*** 489,495 ****
           if (!(dot & 0x8000) && info->transparencyenable) return 0;
           else
           {
              *color = COLSAT2YAB16(0, dot);
              return 1;
           }
        case 4: // 32 BPP
--- 581,591 ----
           if (!(dot & 0x8000) && info->transparencyenable) return 0;
           else
           {
+ #ifndef GEKKO
              *color = COLSAT2YAB16(0, dot);
+ #else
+             *color = COLSAT2YAB16LIT(0, dot);
+ #endif
              return 1;
           }
        case 4: // 32 BPP
***************
*** 497,503 ****
           if (!(dot & 0x80000000) && info->transparencyenable) return 0;
           else
           {
              *color = COLSAT2YAB32(0, dot);
              return 1;
           }
        default:
--- 593,603 ----
           if (!(dot & 0x80000000) && info->transparencyenable) return 0;
           else
           {
+ #ifndef GEKKO
              *color = COLSAT2YAB32(0, dot);
+ #else
+             *color = COLSAT2YAB32LIT(0, dot);
+ #endif
              return 1;
           }
        default:
***************
*** 524,533 ****
           if (x >= clip->xstart && x <= clip->xend &&
               y >= clip->ystart && y <= clip->yend)
              return 0;
! 
  		 //it seems to overflow vertically on hardware
  		 if(clip->yend > vdp2height && (x >= clip->xstart && x <= clip->xend ))
  			 return 0;
        }
     }
     return 1;
--- 624,634 ----
           if (x >= clip->xstart && x <= clip->xend &&
               y >= clip->ystart && y <= clip->yend)
              return 0;
! #ifndef GEKKO
  		 //it seems to overflow vertically on hardware
  		 if(clip->yend > vdp2height && (x >= clip->xstart && x <= clip->xend ))
  			 return 0;
+ #endif
        }
     }
     return 1;
***************
*** 539,545 ****
  {
     int i;
  
     for (i = 0; i < (info->mapwh*info->mapwh); i++)
     {
        info->PlaneAddr(info, i);
        planetbl[i] = info->addr;
--- 640,650 ----
  {
     int i;
  
+ #ifndef GEKKO
     for (i = 0; i < (info->mapwh*info->mapwh); i++)
+ #else
+    for (i = info->mapwh*info->mapwh -1; i >= 0; i--)
+ #endif
     {
        info->PlaneAddr(info, i);
        planetbl[i] = info->addr;
***************
*** 705,712 ****
     int scrollx, scrolly;
     int *mosaic_y, *mosaic_x;
  
     info->coordincx *= (float)resxratio;
     info->coordincy *= (float)resyratio;
  
     SetupScreenVars(info, &sinfo);
  
--- 810,822 ----
     int scrollx, scrolly;
     int *mosaic_y, *mosaic_x;
  
+ #ifndef GEKKO
     info->coordincx *= (float)resxratio;
     info->coordincy *= (float)resyratio;
+ #else
+    info->coordincx *= (float)(resxratio+1);
+    info->coordincy *= (float)(resyratio+1);
+ #endif
  
     SetupScreenVars(info, &sinfo);
  
***************
*** 794,800 ****
  
           // See if screen position is clipped, if it isn't, continue
  		 // AND window logic
  		 if(!TestWindow(info->wctl, 0x2, 0x1, &clip[0], i, j) && !TestWindow(info->wctl, 0x8, 0x4, &clip[1], i, j) && (info->wctl & 0x80) == 0x80)
  		 {
  			 textdata++;
  			 continue;
--- 908,918 ----
  
           // See if screen position is clipped, if it isn't, continue
  		 // AND window logic
+ #ifndef GEKKO
  		 if(!TestWindow(info->wctl, 0x2, 0x1, &clip[0], i, j) && !TestWindow(info->wctl, 0x8, 0x4, &clip[1], i, j) && (info->wctl & 0x80) == 0x80)
+ #else
+ 		 if(!TestWindow(info->wctl, 0x2, 0x1, &clip[0], i << resxratio, j << resyratio) && !TestWindow(info->wctl, 0x8, 0x4, &clip[1], i << resxratio, j << resyratio) && (info->wctl & 0x80) == 0x80)
+ #endif
  		 {
  			 textdata++;
  			 continue;
***************
*** 802,815 ****
  		 //OR window logic
  		 else if ((info->wctl & 0x80) == 0)
  		 {
  			 if (!TestWindow(info->wctl, 0x2, 0x1, &clip[0], i, j))
  			 {
  				 textdata++;
  				 continue;
  			 }
  
  			 // Window 1
  			 if (!TestWindow(info->wctl, 0x8, 0x4, &clip[1], i,j))
  			 {
  				 textdata++;
  				 continue;
--- 920,941 ----
  		 //OR window logic
  		 else if ((info->wctl & 0x80) == 0)
  		 {
+ #ifndef GEKKO
  			 if (!TestWindow(info->wctl, 0x2, 0x1, &clip[0], i, j))
+ #else
+ 			 if (!TestWindow(info->wctl, 0x2, 0x1, &clip[0], i << resxratio, j << resyratio))
+ #endif
  			 {
  				 textdata++;
  				 continue;
  			 }
  
  			 // Window 1
+ #ifndef GEKKO
  			 if (!TestWindow(info->wctl, 0x8, 0x4, &clip[1], i,j))
+ #else
+ 			 if (!TestWindow(info->wctl, 0x8, 0x4, &clip[1], i << resxratio,j << resyratio))
+ #endif
  			 {
  				 textdata++;
  				 continue;
***************
*** 835,841 ****
  
           // If priority of screen is less than current top pixel and per
           // pixel priority isn't used, skip it
           if (Vdp2GetPixelPriority(textdata[0]) > info->priority)
           {
              textdata++;
              continue;
--- 961,972 ----
  
           // If priority of screen is less than current top pixel and per
           // pixel priority isn't used, skip it
+ #ifndef GEKKO
           if (Vdp2GetPixelPriority(textdata[0]) > info->priority)
+ #else
+          if ((Vdp2GetPixelPriority(*textdata) > info->priority) &&
+                   !info->docolorcalcenable)
+ #endif
           {
              textdata++;
              continue;
***************
*** 853,860 ****
           // and then continue.
           // We almost need to know well ahead of time what the top
           // and second pixel is in order to work this.
! 
           textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
           textdata++;
        }
     }    
--- 984,997 ----
           // and then continue.
           // We almost need to know well ahead of time what the top
           // and second pixel is in order to work this.
! #ifdef GEKKO
!          info->oldpixel = *textdata;
! #endif
! #ifndef GEKKO
           textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
+ #else
+          *textdata = info->PostPixelFetchCalc(info, COLSAT2YAB32(info->priority, color));
+ #endif
           textdata++;
        }
     }    
***************
*** 930,936 ****
   
                 // If priority of screen is less than current top pixel and per
                 // pixel priority isn't used, skip it
                 if (Vdp2GetPixelPriority(textdata[0]) > info->priority)
                 {
                    textdata++;
                    continue;
--- 1067,1078 ----
   
                 // If priority of screen is less than current top pixel and per
                 // pixel priority isn't used, skip it
+ #ifndef GEKKO
                 if (Vdp2GetPixelPriority(textdata[0]) > info->priority)
+ #else
+                if ((Vdp2GetPixelPriority(*textdata) > info->priority) &&
+                   !info->docolorcalcenable)
+ #endif
                 {
                    textdata++;
                    continue;
***************
*** 943,949 ****
                    continue;
                 }
  
                 textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
                 textdata++;
              }
              ymul += p->deltaYst;
--- 1085,1099 ----
                    continue;
                 }
  
+ #ifdef GEKKO
+                info->oldpixel = *textdata;
+                info->colorcalcmode = (Vdp2Regs->CCCTL & 0x100);
+ #endif
+ #ifndef GEKKO
                 textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
+ #else
+                *textdata = info->PostPixelFetchCalc(info, COLSAT2YAB32(info->priority, color));
+ #endif
                 textdata++;
              }
              ymul += p->deltaYst;
***************
*** 1009,1015 ****
  
              // If priority of screen is less than current top pixel and per
              // pixel priority isn't used, skip it
              if (Vdp2GetPixelPriority(textdata[0]) > info->priority)
              {
                 textdata++;
                 continue;
--- 1159,1170 ----
  
              // If priority of screen is less than current top pixel and per
              // pixel priority isn't used, skip it
+ #ifndef GEKKO
              if (Vdp2GetPixelPriority(textdata[0]) > info->priority)
+ #else
+             if ((Vdp2GetPixelPriority(*textdata) > info->priority) &&
+                !info->docolorcalcenable)
+ #endif
              {
                 textdata++;
                 continue;
***************
*** 1022,1028 ****
                 continue;
              }
  
              textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
              textdata++;
           }
           ymul += p->deltaYst;
--- 1177,1191 ----
                 continue;
              }
  
+ #ifdef GEKKO
+             info->oldpixel = *textdata;
+             info->colorcalcmode = (Vdp2Regs->CCCTL & 0x100);
+ #endif
+ #ifndef GEKKO
              textdata[0] = COLSAT2YAB32(info->priority, info->PostPixelFetchCalc(info, color));
+ #else
+             *textdata = info->PostPixelFetchCalc(info, COLSAT2YAB32(info->priority, color));
+ #endif
              textdata++;
           }
           ymul += p->deltaYst;
***************
*** 1040,1052 ****
  static void Vdp2DrawBackScreen(void)
  {
     int i;
  
     // Only draw black if TVMD's DISP and BDCLMD bits are cleared
     if ((Vdp2Regs->TVMD & 0x8000) == 0 && (Vdp2Regs->TVMD & 0x100) == 0)
     {
        // Draw Black
        for (i = 0; i < (vdp2width * vdp2height); i++)
           vdp2framebuffer[i] = 0;
     }
     else
     {
--- 1203,1224 ----
  static void Vdp2DrawBackScreen(void)
  {
     int i;
+ #ifdef GEKKO
+    vdp2draw_struct info;
+    info.cor = info.cog = info.cob = 0;
+ #endif
  
     // Only draw black if TVMD's DISP and BDCLMD bits are cleared
     if ((Vdp2Regs->TVMD & 0x8000) == 0 && (Vdp2Regs->TVMD & 0x100) == 0)
     {
        // Draw Black
+ #ifndef GEKKO
        for (i = 0; i < (vdp2width * vdp2height); i++)
           vdp2framebuffer[i] = 0;
+ #else
+       for (i = vdp2width * vdp2height - 1; i >= 0; i--)
+          *(vdp2framebuffer + i) = 0;
+ #endif
     }
     else
     {
***************
*** 1054,1059 ****
        u32 scrAddr;
        u16 dot;
  
        if (Vdp2Regs->VRSIZE & 0x8000)
           scrAddr = (((Vdp2Regs->BKTAU & 0x7) << 16) | Vdp2Regs->BKTAL) * 2;
        else
--- 1226,1234 ----
        u32 scrAddr;
        u16 dot;
  
+ #ifdef GEKKO
+       ReadVdp2ColorOffset(&info, 0x20, 0x20);
+ #endif
        if (Vdp2Regs->VRSIZE & 0x8000)
           scrAddr = (((Vdp2Regs->BKTAU & 0x7) << 16) | Vdp2Regs->BKTAL) * 2;
        else
***************
*** 1062,1070 ****
        if (Vdp2Regs->BKTAU & 0x8000)
        {
           // Per Line
           for (i = 0; i < vdp2height; i++)
           {
              dot = T1ReadWord(Vdp2Ram, scrAddr);
              scrAddr += 2;
  
              puthline16(0, i, vdp2width, dot, 0);
--- 1237,1256 ----
        if (Vdp2Regs->BKTAU & 0x8000)
        {
           // Per Line
+ #ifndef GEKKO
           for (i = 0; i < vdp2height; i++)
+ #else
+          for (i = vdp2height - 1; i >= 0; i--)
+ #endif
           {
+ #ifndef GEKKO
              dot = T1ReadWord(Vdp2Ram, scrAddr);
+ #else
+             if (Vdp2Regs->CLOFEN & 0x20 && (info.cor || info.cog || info.cob))
+               dot = COLOR_ADD16LIT(T1ReadWord(Vdp2Ram, scrAddr), info.cor, info.cog, info.cob);
+             else
+               dot = T1ReadWord(Vdp2Ram, scrAddr);
+ #endif
              scrAddr += 2;
  
              puthline16(0, i, vdp2width, dot, 0);
***************
*** 1073,1082 ****
        else
        {
           // Single Color
           dot = T1ReadWord(Vdp2Ram, scrAddr);
  
           for (i = 0; i < (vdp2width * vdp2height); i++)
              vdp2framebuffer[i] = COLSAT2YAB16(0, dot);
        }
     }
  }
--- 1259,1280 ----
        else
        {
           // Single Color
+ #ifndef GEKKO
           dot = T1ReadWord(Vdp2Ram, scrAddr);
+ #else
+          if (Vdp2Regs->CLOFEN & 0x20 && (info.cor || info.cog || info.cob))
+             dot = COLOR_ADD16LIT(T1ReadWord(Vdp2Ram, scrAddr), info.cor, info.cog, info.cob);
+           else
+             dot = T1ReadWord(Vdp2Ram, scrAddr);
+ #endif
  
+ #ifndef GEKKO
           for (i = 0; i < (vdp2width * vdp2height); i++)
              vdp2framebuffer[i] = COLSAT2YAB16(0, dot);
+ #else
+          for (i = vdp2width * vdp2height - 1; i >= 0; i--)
+             *(vdp2framebuffer + i) = COLSAT2YAB16(0, dot);
+ #endif
        }
     }
  }
***************
*** 1452,1462 ****
        return -1;
  
     // Initialize VDP1 framebuffer 1
     if ((vdp1framebuffer[0] = (u8 *)calloc(sizeof(u8), 0x40000)) == NULL)
        return -1;
  
     // Initialize VDP1 framebuffer 2
     if ((vdp1framebuffer[1] = (u8 *)calloc(sizeof(u8), 0x40000)) == NULL)
        return -1;
  
     // Initialize VDP2 framebuffer
--- 1650,1668 ----
        return -1;
  
     // Initialize VDP1 framebuffer 1
+ #ifndef GEKKO
     if ((vdp1framebuffer[0] = (u8 *)calloc(sizeof(u8), 0x40000)) == NULL)
+ #else
+    if ((vdp1framebuffer[0] = (u8 *)calloc(sizeof(u8), 0x80000)) == NULL)
+ #endif
        return -1;
  
     // Initialize VDP1 framebuffer 2
+ #ifndef GEKKO
     if ((vdp1framebuffer[1] = (u8 *)calloc(sizeof(u8), 0x40000)) == NULL)
+ #else
+    if ((vdp1framebuffer[1] = (u8 *)calloc(sizeof(u8), 0x80000)) == NULL)
+ #endif
        return -1;
  
     // Initialize VDP2 framebuffer
***************
*** 1573,1578 ****
  
  void VIDSoftVdp1DrawStart(void)
  {
     if (Vdp1Regs->TVMR & 0x1)
     {
        if (Vdp1Regs->TVMR & 0x2)
--- 1779,1785 ----
  
  void VIDSoftVdp1DrawStart(void)
  {
+ #ifndef GEKKO
     if (Vdp1Regs->TVMR & 0x1)
     {
        if (Vdp1Regs->TVMR & 0x2)
***************
*** 1683,1689 ****
  
  static INLINE u16  Vdp1ReadPattern256( u32 base, u32 offset ) {
  
    return T1ReadByte(Vdp1Ram, ( base + offset ) & 0x7FFFF) & 0xFF;
  }
  
  static INLINE u16  Vdp1ReadPattern64k( u32 base, u32 offset ) {
--- 1944,1954 ----
  
  static INLINE u16  Vdp1ReadPattern256( u32 base, u32 offset ) {
  
+ #ifndef GEKKO
    return T1ReadByte(Vdp1Ram, ( base + offset ) & 0x7FFFF) & 0xFF;
+ #else
+   return T1ReadByte(Vdp1Ram, ( base + offset ) & 0x7FFFF);
+ #endif
  }
  
  static INLINE u16  Vdp1ReadPattern64k( u32 base, u32 offset ) {
***************
*** 1796,1803 ****
  			endcode = 63;
  			currentPixel = Vdp1ReadPattern64( characterAddress + (linenumber*(characterWidth)), currentlineindex );
  			if(isTextured && endcodesEnabled && currentPixel == endcode)
  				currentPixel = 0;
! 		//		return 1;
  			if (!((currentPixel == 0) && !SPD)) 
  				currentPixel = colorbank | currentPixel;
  			currentPixelIsVisible = 0x3f;
--- 2061,2071 ----
  			endcode = 63;
  			currentPixel = Vdp1ReadPattern64( characterAddress + (linenumber*(characterWidth)), currentlineindex );
  			if(isTextured && endcodesEnabled && currentPixel == endcode)
+ #ifndef GEKKO
  				currentPixel = 0;
! #else
! 				return 1;
! #endif
  			if (!((currentPixel == 0) && !SPD)) 
  				currentPixel = colorbank | currentPixel;
  			currentPixelIsVisible = 0x3f;
***************
*** 1850,1856 ****
  
  static void putpixel(int x, int y) {
  
  	u16* iPix = &((u16 *)vdp1backframebuffer)[(y * vdp1width) + x];
  	int mesh = cmd.CMDPMOD & 0x0100;
  	int SPD = ((cmd.CMDPMOD & 0x40) != 0);//show the actual color of transparent pixels if 1 (they won't be drawn transparent)
  	int currentShape = cmd.CMDCTRL & 0x7;
--- 2118,2129 ----
  
  static void putpixel(int x, int y) {
  
+ #ifdef GEKKO
+ 	u16* iPix;
+ #endif
+ #ifndef GEKKO
  	u16* iPix = &((u16 *)vdp1backframebuffer)[(y * vdp1width) + x];
+ #endif
  	int mesh = cmd.CMDPMOD & 0x0100;
  	int SPD = ((cmd.CMDPMOD & 0x40) != 0);//show the actual color of transparent pixels if 1 (they won't be drawn transparent)
  	int currentShape = cmd.CMDCTRL & 0x7;
***************
*** 1868,1879 ****
  		x < vdp1clipxend &&
  		y >= vdp1clipystart &&
  		y < vdp1clipyend)
! 	{}
  	else
  		return;
  
  	if (cmd.CMDPMOD & 0x0400) PopUserClipping();
  
  
  	if ( SPD || (currentPixel & currentPixelIsVisible))
  	{
--- 2141,2168 ----
  		x < vdp1clipxend &&
  		y >= vdp1clipystart &&
  		y < vdp1clipyend)
! 	{
! #ifdef GEKKO
! 	   if (cmd.CMDPMOD & 0x0400) PopUserClipping();
! #endif
!         }
  	else
+ #ifdef GEKKO
+         {
+ 	   if (cmd.CMDPMOD & 0x0400) PopUserClipping();
+ 	   return;
+         } 
+ #else
  		return;
+ #endif
  
+ #ifndef GEKKO
  	if (cmd.CMDPMOD & 0x0400) PopUserClipping();
+ #endif
  
+ #ifdef GEKKO
+         iPix = &((u16 *)vdp1backframebuffer)[((y >> vdp1h) * vdp1width) + (x >> vdp1w)];
+ #endif
  
  	if ( SPD || (currentPixel & currentPixelIsVisible))
  	{
***************
*** 1884,1890 ****
  				*(iPix) = currentPixel;
  			break;
  		case 1: // shadow, TODO
  			*(iPix) = currentPixel;
  			break;
  		case 2: // half luminance
  			*(iPix) = ((currentPixel & ~0x8421) >> 1) | (1 << 15);
--- 2173,2184 ----
  				*(iPix) = currentPixel;
  			break;
  		case 1: // shadow, TODO
+ #ifndef GEKKO
  			*(iPix) = currentPixel;
+ #else
+                         if ( *(iPix) & (1 << 15) )//only if MSB of framebuffer data is set
+                                 *(iPix) = ((*(iPix) & ~0x8421) >> 1) | (1 << 15);
+ #endif
  			break;
  		case 2: // half luminance
  			*(iPix) = ((currentPixel & ~0x8421) >> 1) | (1 << 15);
***************
*** 2239,2245 ****
  	COLOR colors[4];
  
  	Vdp1ReadCommand(&cmd, Vdp1Regs->addr);
  	characterWidth = ((cmd.CMDSIZE >> 8) & 0x3F) * 8;
  	characterHeight = cmd.CMDSIZE & 0xFF;
  
  	totalleft  = bresenham(tl_x,tl_y,bl_x,bl_y,xleft,yleft);
--- 2533,2543 ----
  	COLOR colors[4];
  
  	Vdp1ReadCommand(&cmd, Vdp1Regs->addr);
+ #ifndef GEKKO
  	characterWidth = ((cmd.CMDSIZE >> 8) & 0x3F) * 8;
+ #else
+ 	characterWidth = ((cmd.CMDSIZE & 0x3F00) >> 5);
+ #endif
  	characterHeight = cmd.CMDSIZE & 0xFF;
  
  	totalleft  = bresenham(tl_x,tl_y,bl_x,bl_y,xleft,yleft);
***************
*** 2280,2286 ****
  		leftLineStep = (double)totalleft / totalright;
  	}
  
  	for(i = 0; i < total; i++) {
  
  		int xlinelength;
  
--- 2578,2588 ----
  		leftLineStep = (double)totalleft / totalright;
  	}
  
+ #ifndef GEKKO
  	for(i = 0; i < total; i++) {
+ #else
+ 	for(i = total - 1; i >= 0; i--) {
+ #endif
  
  		int xlinelength;
  
***************
*** 2292,2302 ****
  		COLOR_PARAMS leftToRightStep = {0,0,0};
  
  		//get the length of the line we are about to draw
  		xlinelength = getlinelength(
  			xleft[(int)(i*leftLineStep)],
  			yleft[(int)(i*leftLineStep)],
  			xright[(int)(i*rightLineStep)],
  			yright[(int)(i*rightLineStep)]);
  
  		//so from 0 to the width of the texture / the length of the line is how far we need to step
  		xtexturestep=interpolate(0,characterWidth,xlinelength);
--- 2594,2612 ----
  		COLOR_PARAMS leftToRightStep = {0,0,0};
  
  		//get the length of the line we are about to draw
+ #ifndef GEKKO
  		xlinelength = getlinelength(
  			xleft[(int)(i*leftLineStep)],
  			yleft[(int)(i*leftLineStep)],
  			xright[(int)(i*rightLineStep)],
  			yright[(int)(i*rightLineStep)]);
+ #else
+                 xlinelength = getlinelength(
+                         *(xleft + (int)(i*leftLineStep)),
+                         *(yleft + (int)(i*leftLineStep)),
+                         *(xright + (int)(i*rightLineStep)),
+                         *(yright + (int)(i*rightLineStep)));
+ #endif
  
  		//so from 0 to the width of the texture / the length of the line is how far we need to step
  		xtexturestep=interpolate(0,characterWidth,xlinelength);
***************
*** 2326,2335 ****
  		}
  
  		DrawLine(
  			xleft[(int)(i*leftLineStep)],
  			yleft[(int)(i*leftLineStep)],
  			xright[(int)(i*rightLineStep)],
  			yright[(int)(i*rightLineStep)],
  			ytexturestep*i, 
  			xtexturestep,
  			leftToRightStep.r,
--- 2636,2652 ----
  		}
  
  		DrawLine(
+ #ifndef GEKKO
  			xleft[(int)(i*leftLineStep)],
  			yleft[(int)(i*leftLineStep)],
  			xright[(int)(i*rightLineStep)],
  			yright[(int)(i*rightLineStep)],
+ #else
+                         *(xleft + (int)(i*leftLineStep)),
+                         *(yleft + (int)(i*leftLineStep)),
+                         *(xright + (int)(i*rightLineStep)),
+                         *(yright + (int)(i*rightLineStep)),
+ #endif
  			ytexturestep*i, 
  			xtexturestep,
  			leftToRightStep.r,
***************
*** 2348,2354 ****
  
  	topLeftx = cmd.CMDXA + Vdp1Regs->localX;
  	topLefty = cmd.CMDYA + Vdp1Regs->localY;
  	spriteWidth = ((cmd.CMDSIZE >> 8) & 0x3F) * 8;
  	spriteHeight = cmd.CMDSIZE & 0xFF;
  
  	topRightx = topLeftx+spriteWidth;
--- 2665,2675 ----
  
  	topLeftx = cmd.CMDXA + Vdp1Regs->localX;
  	topLefty = cmd.CMDYA + Vdp1Regs->localY;
+ #ifndef GEKKO
  	spriteWidth = ((cmd.CMDSIZE >> 8) & 0x3F) * 8;
+ #else
+ 	spriteWidth = ((cmd.CMDSIZE & 0x3F00) >> 5);
+ #endif
  	spriteHeight = cmd.CMDSIZE & 0xFF;
  
  	topRightx = topLeftx+spriteWidth;
***************
*** 2445,2451 ****
  		break;
  	}
  
  	spriteWidth = ((cmd.CMDSIZE >> 8) & 0x3F) * 8;
  	spriteHeight = cmd.CMDSIZE & 0xFF;
  
  	topLeftx = x0;
--- 2766,2776 ----
  		break;
  	}
  
+ #ifndef GEKKO
  	spriteWidth = ((cmd.CMDSIZE >> 8) & 0x3F) * 8;
+ #else
+ 	spriteWidth = ((cmd.CMDSIZE & 0x3F00) >> 5);
+ #endif
  	spriteHeight = cmd.CMDSIZE & 0xFF;
  
  	topLeftx = x0;
***************
*** 2592,2602 ****
  
  static void PushUserClipping(int mode)
  {
     if (mode == 1)
     {
        VDP1LOG("User clipping mode 1 not implemented\n");
        return;
     }
  
     vdp1clipxstart = Vdp1Regs->userclipX1;
     vdp1clipxend = Vdp1Regs->userclipX2;
--- 2917,2929 ----
  
  static void PushUserClipping(int mode)
  {
+ #ifndef GEKKO
     if (mode == 1)
     {
        VDP1LOG("User clipping mode 1 not implemented\n");
        return;
     }
+ #endif
  
     vdp1clipxstart = Vdp1Regs->userclipX1;
     vdp1clipxend = Vdp1Regs->userclipX2;
***************
*** 2682,2689 ****
     u32 vdp1coloroffset;
     int colormode = Vdp2Regs->SPCTL & 0x20;
     vdp2draw_struct info;
     u32 *dst=dispbuffer;
     u32 *vdp2src=vdp2framebuffer;
     int islinewindow;
     clipping_struct clip[2];
     u32 linewnd0addr, linewnd1addr;
--- 3009,3021 ----
     u32 vdp1coloroffset;
     int colormode = Vdp2Regs->SPCTL & 0x20;
     vdp2draw_struct info;
+ #ifndef GEKKO
     u32 *dst=dispbuffer;
     u32 *vdp2src=vdp2framebuffer;
+ #else
+    u32 *dst=dispbuffer + vdp2height * vdp2width - 1;
+    u32 *vdp2src=vdp2framebuffer + vdp2height * vdp2width - 1;
+ #endif
     int islinewindow;
     clipping_struct clip[2];
     u32 linewnd0addr, linewnd1addr;
***************
*** 2741,2754 ****
  
           if (info.cor == 0 && info.cog == 0 && info.cob == 0)
           {
              if (Vdp2Regs->CCCTL & 0x40)
                 info.PostPixelFetchCalc = &DoColorCalc;
              else
                 info.PostPixelFetchCalc = &DoNothing;
           }
           else
           {
              if (Vdp2Regs->CCCTL & 0x40)
                 info.PostPixelFetchCalc = &DoColorCalcWithColorOffset;
              else
                 info.PostPixelFetchCalc = &DoColorOffset;
--- 3073,3094 ----
  
           if (info.cor == 0 && info.cog == 0 && info.cob == 0)
           {
+ #ifndef GEKKO
              if (Vdp2Regs->CCCTL & 0x40)
+ #else
+             if ((Vdp2Regs->CCCTL & 0x40) && specialcoloron)
+ #endif
                 info.PostPixelFetchCalc = &DoColorCalc;
              else
                 info.PostPixelFetchCalc = &DoNothing;
           }
           else
           {
+ #ifndef GEKKO
              if (Vdp2Regs->CCCTL & 0x40)
+ #else
+             if ((Vdp2Regs->CCCTL & 0x40) && specialcoloron)
+ #endif
                 info.PostPixelFetchCalc = &DoColorCalcWithColorOffset;
              else
                 info.PostPixelFetchCalc = &DoColorOffset;
***************
*** 2756,2766 ****
        }
        else // color offset disable
        {
           if (Vdp2Regs->CCCTL & 0x40)
              info.PostPixelFetchCalc = &DoColorCalc;
           else
              info.PostPixelFetchCalc = &DoNothing;
        }
  
        wctl = Vdp2Regs->WCTLC >> 8;
        clip[0].xstart = clip[0].ystart = clip[0].xend = clip[0].yend = 0;
--- 3096,3116 ----
        }
        else // color offset disable
        {
+ #ifndef GEKKO
           if (Vdp2Regs->CCCTL & 0x40)
+ #else
+          if ((Vdp2Regs->CCCTL & 0x40) && specialcoloron)
+ #endif
              info.PostPixelFetchCalc = &DoColorCalc;
           else
              info.PostPixelFetchCalc = &DoNothing;
        }
+ #ifdef GEKKO
+       if ((Vdp2Regs->CCCTL & 0x40) && specialcoloron)
+          info.docolorcalcenable = 1;
+       else
+          info.docolorcalcenable = 0;
+ #endif
  
        wctl = Vdp2Regs->WCTLC >> 8;
        clip[0].xstart = clip[0].ystart = clip[0].xend = clip[0].yend = 0;
***************
*** 2769,2822 ****
        linewnd0addr = linewnd1addr = 0;
        ReadLineWindowData(&islinewindow, wctl, &linewnd0addr, &linewnd1addr);
  
        for (i2 = 0; i2 < vdp2height; i2++)
        {
           ReadLineWindowClip(islinewindow, clip, &linewnd0addr, &linewnd1addr);
  
           for (i = 0; i < vdp2width; i++)
           {
              // See if screen position is clipped, if it isn't, continue
              // Window 0
              if (!TestWindow(wctl, 0x2, 0x1, &clip[0], i, i2))
              {
                 dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                 vdp2src++;
                 dst++;
                 continue;
              }
  
              // Window 1
              if (!TestWindow(wctl, 0x8, 0x4, &clip[1], i, i2))
              {
!                vdp2src++;
                 dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                 dst++;
                 continue;
              }
  
              if (vdp1pixelsize == 2)
              {
                 // 16-bit pixel size
                 pixel = ((u16 *)vdp1frontframebuffer)[(i2 * vdp1width) + i];
  
                 if (pixel == 0)
                    dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                 else if (pixel & 0x8000 && colormode)
                 {
                    // 16 BPP               
                    if (prioritytable[0] >= Vdp2GetPixelPriority(vdp2src[0]))
                    {
                       // if pixel is 0x8000, only draw pixel if sprite window
                       // is disabled/sprite type 2-7. sprite types 0 and 1 are
                       // -always- drawn and sprite types 8-F are always
                       // transparent.
                       if (pixel != 0x8000 || vdp1spritetype < 2 || (vdp1spritetype < 8 && !(Vdp2Regs->SPCTL & 0x10)))
                          dst[0] = info.PostPixelFetchCalc(&info, COLSAT2YAB16(0xFF, pixel));
                       else
                          dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                    }
                    else               
                       dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                 }
                 else
                 {
--- 3119,3227 ----
        linewnd0addr = linewnd1addr = 0;
        ReadLineWindowData(&islinewindow, wctl, &linewnd0addr, &linewnd1addr);
  
+ #ifdef GEKKO
+             info.colorcalcmode = (Vdp2Regs->CCCTL & 0x100);
+             //info.alpha = ((u8 *)&Vdp2Regs->CCRSA)[0] & 0x1F;
+ #endif
+ 
+ #ifndef GEKKO
        for (i2 = 0; i2 < vdp2height; i2++)
+ #else
+       for (i2 = vdp2height - 1; i2 >= 0; i2--)
+ #endif
        {
           ReadLineWindowClip(islinewindow, clip, &linewnd0addr, &linewnd1addr);
  
+ #ifndef GEKKO
           for (i = 0; i < vdp2width; i++)
+ #else
+          for (i = vdp2width - 1; i >= 0; i--)
+ #endif
           {
              // See if screen position is clipped, if it isn't, continue
              // Window 0
              if (!TestWindow(wctl, 0x2, 0x1, &clip[0], i, i2))
              {
                 dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #ifndef GEKKO
                 vdp2src++;
                 dst++;
+ #else
+                vdp2src--;
+                dst--;
+ #endif
                 continue;
              }
  
              // Window 1
              if (!TestWindow(wctl, 0x8, 0x4, &clip[1], i, i2))
              {
! #ifndef GEKKO
!                vdp2src++; 
! #endif
                 dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #ifdef GEKKO
+                vdp2src--;
+                dst--;
+ #endif
+ #ifndef GEKKO
                 dst++;
+ #endif
                 continue;
              }
+ #ifdef GEKKO
+             info.oldpixel = *vdp2src;
+ #endif
  
+ #ifndef GEKKO
              if (vdp1pixelsize == 2)
              {
+ #endif
                 // 16-bit pixel size
+ #ifndef GEKKO
                 pixel = ((u16 *)vdp1frontframebuffer)[(i2 * vdp1width) + i];
+ #else
+                pixel = *(((u16 *)vdp1frontframebuffer) + (i2 * vdp1width) + i);
+ #endif
  
                 if (pixel == 0)
+ #ifndef GEKKO
                    dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #else
+                   *dst = COLSATSTRIPPRIORITY(*vdp2src);
+ #endif
                 else if (pixel & 0x8000 && colormode)
                 {
                    // 16 BPP               
+ #ifndef GEKKO
                    if (prioritytable[0] >= Vdp2GetPixelPriority(vdp2src[0]))
+ #else
+                   if (*prioritytable >= Vdp2GetPixelPriority(*vdp2src))
+ #endif
                    {
                       // if pixel is 0x8000, only draw pixel if sprite window
                       // is disabled/sprite type 2-7. sprite types 0 and 1 are
                       // -always- drawn and sprite types 8-F are always
                       // transparent.
                       if (pixel != 0x8000 || vdp1spritetype < 2 || (vdp1spritetype < 8 && !(Vdp2Regs->SPCTL & 0x10)))
+ #ifndef GEKKO
                          dst[0] = info.PostPixelFetchCalc(&info, COLSAT2YAB16(0xFF, pixel));
+ #else
+                         *dst = DoNothing(&info, COLSAT2YAB16(0xFF, pixel));
+ #endif
                       else
+ #ifndef GEKKO
                          dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #else
+                         *dst = COLSATSTRIPPRIORITY(*vdp2src);
+ #endif
                    }
                    else               
+ #ifndef GEKKO
                       dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #else
+                      *dst = COLSATSTRIPPRIORITY(*vdp2src);
+ #endif
                 }
                 else
                 {
***************
*** 2825,2836 ****
  		  int shadow;
  		  int colorcalc;
  		  priority = 0;  // Avoid compiler warning
                    Vdp1ProcessSpritePixel(vdp1spritetype, &pixel, &shadow, &priority, &colorcalc);
                    if (prioritytable[priority] >= Vdp2GetPixelPriority(vdp2src[0]))
                       dst[0] = info.PostPixelFetchCalc(&info, COLSAT2YAB32(0xFF, Vdp2ColorRamGetColor(vdp1coloroffset + pixel)));
                    else               
                       dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                 }
              }
              else
              {
--- 3230,3273 ----
  		  int shadow;
  		  int colorcalc;
  		  priority = 0;  // Avoid compiler warning
+ #ifdef GEKKO
+ 		  shadow = 0;  // Avoid compiler warning
+ 		  colorcalc = 0;  // Avoid compiler warning
+ #endif
                    Vdp1ProcessSpritePixel(vdp1spritetype, &pixel, &shadow, &priority, &colorcalc);
+ #ifdef GEKKO
+                   info.alpha = ((u8 *)&Vdp2Regs->CCRSA)[colorcalc] & 0x1F;
+                   if (pixel != 0x8000 || vdp1spritetype < 2 || (vdp1spritetype < 8 && !(Vdp2Regs->SPCTL & 0x10)))
+                   {
+                      if(info.PostPixelFetchCalc == &DoColorCalc)
+                         info.PostPixelFetchCalc = &DoNothing;
+                      if(info.PostPixelFetchCalc == &DoColorCalcWithColorOffset)
+                         info.PostPixelFetchCalc = &DoColorOffset;
+ 
+                      info.docolorcalcenable=0;
+                   }
+ #endif
+ #ifndef GEKKO
                    if (prioritytable[priority] >= Vdp2GetPixelPriority(vdp2src[0]))
+ #else
+                   if ((*(prioritytable + priority) >= Vdp2GetPixelPriority(*vdp2src)) || info.docolorcalcenable)
+ #endif
+ #ifndef GEKKO
                       dst[0] = info.PostPixelFetchCalc(&info, COLSAT2YAB32(0xFF, Vdp2ColorRamGetColor(vdp1coloroffset + pixel)));
+ #else
+                      if (pixel & 0x8000 && !colormode)
+                         *dst = DoColorOffset(&info, COLSAT2YAB16(0xFF, pixel));
+                      else               
+                         *dst = info.PostPixelFetchCalc(&info, COLSAT2YAB32(0xFF, Vdp2ColorRamGetColor(vdp1coloroffset + pixel)));
+ #endif
                    else               
+ #ifndef GEKKO
                       dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #else
+                      *dst = COLSATSTRIPPRIORITY(*vdp2src);
+ #endif
                 }
+ #ifndef GEKKO
              }
              else
              {
***************
*** 2838,2861 ****
                 pixel = vdp1frontframebuffer[(i2 * vdp1width) + i];
  
                 if (pixel == 0)
                    dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
!                else
                 {
                    // Color bank(fix me)
!                   LOG("8-bit Color Bank draw - %02X\n", pixel);
                    dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
                 }
              }
              vdp2src++;
              dst++;
           }
        }
     }
     else
     {
        // Render VDP2 only
        for (i = 0; i < (vdp2width*vdp2height); i++)
           dispbuffer[i] = COLSATSTRIPPRIORITY(vdp2framebuffer[i]);
     }
  
     VIDSoftVdp1SwapFrameBuffer();
--- 3275,3322 ----
                 pixel = vdp1frontframebuffer[(i2 * vdp1width) + i];
  
                 if (pixel == 0)
+ #ifndef GEKKO
                    dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
!                else if (prioritytable[0] >= Vdp2GetPixelPriority(vdp2src[0]))
!                   dst[0] = COLSAT2YAB32(0xFF, Vdp2ColorRamGetColor(vdp1coloroffset + pixel)); 
! #else
!                   *dst = COLSATSTRIPPRIORITY(*vdp2src);
!                else if ((*prioritytable >= Vdp2GetPixelPriority(*vdp2src))
!                   || info.docolorcalcenable)
!                   *dst = info.PostPixelFetchCalc(&info, COLSAT2YAB32(0xFF, Vdp2ColorRamGetColor(vdp1coloroffset + pixel)));
! #endif
                 {
                    // Color bank(fix me)
!                   //LOG("8-bit Color Bank draw - %02X\n", pixel);
! #ifndef GEKKO
                    dst[0] = COLSATSTRIPPRIORITY(vdp2src[0]);
+ #else
+                   *dst = COLSATSTRIPPRIORITY(*vdp2src);
+ #endif
+ 
                 }
              }
+ #endif // 8-bit
+ #ifndef GEKKO
              vdp2src++;
              dst++;
+ #else
+             vdp2src--;
+             dst--;
+ #endif
           }
        }
     }
     else
     {
        // Render VDP2 only
+ #ifndef GEKKO
        for (i = 0; i < (vdp2width*vdp2height); i++)
           dispbuffer[i] = COLSATSTRIPPRIORITY(vdp2framebuffer[i]);
+ #else
+       for (i = vdp2width*vdp2height - 1; i >=0; i--)
+          *(dispbuffer + i) = COLSATSTRIPPRIORITY(*(vdp2framebuffer + i));
+ #endif
     }
  
     VIDSoftVdp1SwapFrameBuffer();
***************
*** 2900,2905 ****
  {
     int i;
  
     for (i = 7; i > 0; i--)
     {   
        if (nbg3priority == i)
--- 3361,3367 ----
  {
     int i;
  
+ #ifndef GEKKO
     for (i = 7; i > 0; i--)
     {   
        if (nbg3priority == i)
***************
*** 2941,2975 ****
     {
        case 0:
           vdp2width = 320;
           resxratio=1;
           break;
        case 1:
           vdp2width = 352;
           resxratio=1;
           break;
        case 2: // 640
           vdp2width = 320;
           resxratio=2;
           break;
        case 3: // 704
           vdp2width = 352;
           resxratio=2;
           break;
        case 4:
           vdp2width = 320;
           resxratio=1;
           break;
        case 5:
           vdp2width = 352;
           resxratio=1;
           break;
        case 6: // 640
           vdp2width = 320;
           resxratio=2;
           break;
        case 7: // 704
           vdp2width = 352;
           resxratio=2;
           break;
     }
  
--- 3418,3484 ----
     {
        case 0:
           vdp2width = 320;
+ #ifndef GEKKO
           resxratio=1;
+ #else
+          resxratio=0;
+ #endif
           break;
        case 1:
           vdp2width = 352;
+ #ifndef GEKKO
           resxratio=1;
+ #else
+          resxratio=0;
+ #endif
           break;
        case 2: // 640
           vdp2width = 320;
+ #ifndef GEKKO
           resxratio=2;
+ #else
+          resxratio=1;
+ #endif
           break;
        case 3: // 704
           vdp2width = 352;
+ #ifndef GEKKO
           resxratio=2;
+ #else
+          resxratio=1;
+ #endif
           break;
        case 4:
           vdp2width = 320;
+ #ifndef GEKKO
           resxratio=1;
+ #else
+          resxratio=0;
+ #endif
           break;
        case 5:
           vdp2width = 352;
+ #ifndef GEKKO
           resxratio=1;
+ #else
+          resxratio=0;
+ #endif
           break;
        case 6: // 640
           vdp2width = 320;
+ #ifndef GEKKO
           resxratio=2;
+ #else
+          resxratio=1;
+ #endif
           break;
        case 7: // 704
           vdp2width = 352;
+ #ifndef GEKKO
           resxratio=2;
+ #else
+          resxratio=1;
+ #endif
           break;
     }
  
***************
*** 2987,3000 ****
           break;
        default: break;
     }
     resyratio=1;
  
     // Check for interlace
     switch ((TVMD >> 6) & 0x3)
     {
        case 3: // Double-density Interlace
  //         vdp2height *= 2;
           resyratio=2;
           break;
        case 2: // Single-density Interlace
        case 0: // Non-interlace
--- 3496,3517 ----
           break;
        default: break;
     }
+ #ifndef GEKKO
     resyratio=1;
+ #else
+    resyratio=0;
+ #endif
  
     // Check for interlace
     switch ((TVMD >> 6) & 0x3)
     {
        case 3: // Double-density Interlace
  //         vdp2height *= 2;
+ #ifndef GEKKO
           resyratio=2;
+ #else
+          resyratio=1;
+ #endif
           break;
        case 2: // Single-density Interlace
        case 0: // Non-interlace
***************
*** 3081,3087 ****
     for (i2 = (Vdp1Regs->EWLR & 0x1FF); i2 < h; i2++)
     {
        for (i = ((Vdp1Regs->EWLR >> 6) & 0x1F8); i < w; i++)
           ((u16 *)vdp1backframebuffer)[(i2 * vdp1width) + i] = Vdp1Regs->EWDR;
     }
  }
  
--- 3598,3608 ----
     for (i2 = (Vdp1Regs->EWLR & 0x1FF); i2 < h; i2++)
     {
        for (i = ((Vdp1Regs->EWLR >> 6) & 0x1F8); i < w; i++)
+ #ifndef GEKKO
           ((u16 *)vdp1backframebuffer)[(i2 * vdp1width) + i] = Vdp1Regs->EWDR;
+ #else
+          *(((u16 *)vdp1backframebuffer) + (i2 * vdp1width) + i) = Vdp1Regs->EWDR;
+ #endif
     }
  }
  
