original_code:
void mb_go_w(offs_t offset,data_t data)
{
  s32 mb_temp;
  s16 mb_q;
  int msb;
  switch (offset)
    {
    case 0x00: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0xff00) | data; break;
    case 0x01: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0x00ff) | (data << 8); break;
    case 0x02: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0xff00) | data; break;
    case 0x03: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0x00ff) | (data << 8); break;
    case 0x04: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0xff00) | data; break;
    case 0x05: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0x00ff) | (data << 8); break;
    case 0x06: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0xff00) | data; break;
    case 0x07: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8); break;
    case 0x08: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0xff00) | data; break;
    case 0x09: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0x00ff) | (data << 8); break;
    case 0x0a: mb_result = mb_reg [0x05] = (mb_reg [0x05] & 0xff00) | data; break;
    case 0x0c: mb_result = mb_reg [0x06] = data; break;
    case 0x15: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0xff00) | data; break;
    case 0x16: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0x00ff) | (data << 8); break;
    case 0x1a: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0xff00) | data; break;
    case 0x1b: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0x00ff) | (data << 8); break;
    case 0x0d: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0xff00) | data; break;
    case 0x0e: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0x00ff) | (data << 8); break;
    case 0x0f: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0xff00) | data; break;
    case 0x10: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0x00ff) | (data << 8); break;
    case 0x17: mb_result = mb_reg [0x07]; break;
    case 0x19: mb_result = mb_reg [0x08]; break;
    case 0x18: mb_result = mb_reg [0x09]; break;
    case 0x0b:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = (s16)0xffff;
      mb_reg [0x04] -= mb_reg [0x02];
      mb_reg [0x05] -= mb_reg [0x03];
    step_048:
      mb_temp = ((s32) mb_reg [0x00]) * ((s32) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x0e] = mb_temp & 0xffff;
      mb_temp = ((s32) -mb_reg [0x01]) * ((s32) mb_reg [0x05]);
      mb_reg [0x07] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x07] += mb_reg [0x0c];
      mb_reg [0x0e] = (mb_reg [0x0e] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_q = mb_reg [0x0c] + mb_reg [0x0e];
      if (mb_q < 0)
 mb_reg [0x07]++;
      mb_result = mb_reg [0x07];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x07] += mb_reg [0x02];
    case 0x12:
      mb_temp = ((s32) mb_reg [0x01]) * ((s32) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x09] = mb_temp & 0xffff;
      mb_temp = ((s32) mb_reg [0x00]) * ((s32) mb_reg [0x05]);
      mb_reg [0x08] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x08] += mb_reg [0x0c];
      mb_reg [0x09] = (mb_reg [0x09] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_reg [0x09] += mb_reg [0x0c];
      if (mb_reg [0x09] < 0)
 mb_reg [0x08]++;
      mb_reg [0x09] <<= 1;
      mb_result = mb_reg [0x08];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x08] += mb_reg [0x03];
      mb_reg [0x09] &= 0xff00;
    case 0x13:
      mb_reg [0x0c] = mb_reg [0x09];
      mb_q = mb_reg [0x08];
      goto step_0bf;
    case 0x14:
      mb_reg [0x0c] = mb_reg [0x0a];
      mb_q = mb_reg [0x0b];
    step_0bf:
      mb_reg [0x0e] = mb_reg [0x07] ^ mb_q;
      mb_reg [0x0d] = mb_q;
      if (mb_q >= 0)
 mb_q = mb_reg [0x0c];
      else
 {
   mb_reg [0x0d] = - mb_q - 1;
   mb_q = - mb_reg [0x0c] - 1;
   if ((mb_q < 0) && ((mb_q + 1) < 0))
     mb_reg [0x0d]++;
   mb_q++;
 }
      if (mb_reg [0x07] >= 0)
 mb_reg [0x0c] = mb_reg [0x07];
      else
        mb_reg [0x0c] = -mb_reg [0x07];
      mb_reg [0x0f] = mb_reg [0x06];
      do
 {
   mb_reg [0x0d] -= mb_reg [0x0c];
   msb = ((mb_q & 0x8000) != 0);
   mb_q <<= 1;
   if (mb_reg [0x0d] >= 0)
     mb_q++;
   else
     mb_reg [0x0d] += mb_reg [0x0c];
   mb_reg [0x0d] <<= 1;
   mb_reg [0x0d] += msb;
 }
      while (--mb_reg [0x0f] >= 0);
      if (mb_reg [0x0e] >= 0)
 mb_result = mb_q;
      else
 mb_result = - mb_q;
      break;
    case 0x11:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = 0x0000;
      goto step_048;
      break;
    case 0x1c:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      do
 {
   mb_reg [0x0e] = (mb_reg [0x04] + mb_reg [0x07]) >> 1;
   mb_reg [0x0f] = (mb_reg [0x05] + mb_reg [0x08]) >> 1;
   if ((mb_reg [0x0b] < mb_reg [0x0e]) && (mb_reg [0x0f] < mb_reg [0x0e]) && ((mb_reg [0x0e] + mb_reg [0x0f]) >= 0))
     { mb_reg [0x07] = mb_reg [0x0e]; mb_reg [0x08] = mb_reg [0x0f]; }
   else
     { mb_reg [0x04] = mb_reg [0x0e]; mb_reg [0x05] = mb_reg [0x0f]; }
 }
      while (--mb_reg [0x06] >= 0);
      mb_result = mb_reg [0x08];
      break;
    case 0x1d:
      mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8);
      mb_reg [0x02] -= mb_reg [0x00];
      if (mb_reg [0x02] < 0)
 mb_reg [0x02] = -mb_reg [0x02];
      mb_reg [0x03] -= mb_reg [0x01];
      if (mb_reg [0x03] < 0)
 mb_reg [0x03] = -mb_reg [0x03];
    case 0x1e:
      if (mb_reg [0x03] >= mb_reg [0x02])
        { mb_reg [0x0c] = mb_reg [0x02]; mb_reg [0x0d] = mb_reg [0x03]; }
      else
 { mb_reg [0x0d] = mb_reg [0x02]; mb_reg [0x0c] = mb_reg [0x03]; }
      mb_reg [0x0c] >>= 2;
      mb_reg [0x0d] += mb_reg [0x0c];
      mb_reg [0x0c] >>= 1;
      mb_result = mb_reg [0x0d] = (mb_reg [0x0c] + mb_reg [0x0d]);
      break;
    case 0x1f:
      break;
    }
}

canonical_original_code:
void mb_go_w(unsigned int offset, unsigned int data)
{
  int mb_temp;
  short mb_q;
  int msb;
  switch (offset)
    {
    case 0x00: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0xff00) | data; break;
    case 0x01: mb_result = mb_reg [0x00] = (mb_reg [0x00] & 0x00ff) | (data << 8); break;
    case 0x02: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0xff00) | data; break;
    case 0x03: mb_result = mb_reg [0x01] = (mb_reg [0x01] & 0x00ff) | (data << 8); break;
    case 0x04: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0xff00) | data; break;
    case 0x05: mb_result = mb_reg [0x02] = (mb_reg [0x02] & 0x00ff) | (data << 8); break;
    case 0x06: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0xff00) | data; break;
    case 0x07: mb_result = mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8); break;
    case 0x08: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0xff00) | data; break;
    case 0x09: mb_result = mb_reg [0x04] = (mb_reg [0x04] & 0x00ff) | (data << 8); break;
    case 0x0a: mb_result = mb_reg [0x05] = (mb_reg [0x05] & 0xff00) | data; break;
    case 0x0c: mb_result = mb_reg [0x06] = data; break;
    case 0x15: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0xff00) | data; break;
    case 0x16: mb_result = mb_reg [0x07] = (mb_reg [0x07] & 0x00ff) | (data << 8); break;
    case 0x1a: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0xff00) | data; break;
    case 0x1b: mb_result = mb_reg [0x08] = (mb_reg [0x08] & 0x00ff) | (data << 8); break;
    case 0x0d: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0xff00) | data; break;
    case 0x0e: mb_result = mb_reg [0x0a] = (mb_reg [0x0a] & 0x00ff) | (data << 8); break;
    case 0x0f: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0xff00) | data; break;
    case 0x10: mb_result = mb_reg [0x0b] = (mb_reg [0x0b] & 0x00ff) | (data << 8); break;
    case 0x17: mb_result = mb_reg [0x07]; break;
    case 0x19: mb_result = mb_reg [0x08]; break;
    case 0x18: mb_result = mb_reg [0x09]; break;
    case 0x0b:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = (short)0xffff;
      mb_reg [0x04] -= mb_reg [0x02];
      mb_reg [0x05] -= mb_reg [0x03];
    step_048:
      mb_temp = ((int) mb_reg [0x00]) * ((int) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x0e] = mb_temp & 0xffff;
      mb_temp = ((s32) -mb_reg [0x01]) * ((int) mb_reg [0x05]);
      mb_reg [0x07] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x07] += mb_reg [0x0c];
      mb_reg [0x0e] = (mb_reg [0x0e] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_q = mb_reg [0x0c] + mb_reg [0x0e];
      if (mb_q < 0)
 mb_reg [0x07]++;
      mb_result = mb_reg [0x07];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x07] += mb_reg [0x02];
    case 0x12:
      mb_temp = ((int) mb_reg [0x01]) * ((int) mb_reg [0x04]);
      mb_reg [0x0c] = mb_temp >> 16;
      mb_reg [0x09] = mb_temp & 0xffff;
      mb_temp = ((int) mb_reg [0x00]) * ((int) mb_reg [0x05]);
      mb_reg [0x08] = mb_temp >> 16;
      mb_q = mb_temp & 0xffff;
      mb_reg [0x08] += mb_reg [0x0c];
      mb_reg [0x09] = (mb_reg [0x09] >> 1) & 0x7fff;
      mb_reg [0x0c] = (mb_q >> 1) & 0x7fff;
      mb_reg [0x09] += mb_reg [0x0c];
      if (mb_reg [0x09] < 0)
 mb_reg [0x08]++;
      mb_reg [0x09] <<= 1;
      mb_result = mb_reg [0x08];
      if (mb_reg [0x0f] < 0)
 break;
      mb_reg [0x08] += mb_reg [0x03];
      mb_reg [0x09] &= 0xff00;
    case 0x13:
      mb_reg [0x0c] = mb_reg [0x09];
      mb_q = mb_reg [0x08];
      goto step_0bf;
    case 0x14:
      mb_reg [0x0c] = mb_reg [0x0a];
      mb_q = mb_reg [0x0b];
    step_0bf:
      mb_reg [0x0e] = mb_reg [0x07] ^ mb_q;
      mb_reg [0x0d] = mb_q;
      if (mb_q >= 0)
 mb_q = mb_reg [0x0c];
      else
 {
   mb_reg [0x0d] = - mb_q - 1;
   mb_q = - mb_reg [0x0c] - 1;
   if ((mb_q < 0) && ((mb_q + 1) < 0))
     mb_reg [0x0d]++;
   mb_q++;
 }
      if (mb_reg [0x07] >= 0)
 mb_reg [0x0c] = mb_reg [0x07];
      else
        mb_reg [0x0c] = -mb_reg [0x07];
      mb_reg [0x0f] = mb_reg [0x06];
      do
 {
   mb_reg [0x0d] -= mb_reg [0x0c];
   msb = ((mb_q & 0x8000) != 0);
   mb_q <<= 1;
   if (mb_reg [0x0d] >= 0)
     mb_q++;
   else
     mb_reg [0x0d] += mb_reg [0x0c];
   mb_reg [0x0d] <<= 1;
   mb_reg [0x0d] += msb;
 }
      while (--mb_reg [0x0f] >= 0);
      if (mb_reg [0x0e] >= 0)
 mb_result = mb_q;
      else
 mb_result = - mb_q;
      break;
    case 0x11:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      mb_reg [0x0f] = 0x0000;
      goto step_048;
      break;
    case 0x1c:
      mb_reg [0x05] = (mb_reg [0x05] & 0x00ff) | (data << 8);
      do
 {
   mb_reg [0x0e] = (mb_reg [0x04] + mb_reg [0x07]) >> 1;
   mb_reg [0x0f] = (mb_reg [0x05] + mb_reg [0x08]) >> 1;
   if ((mb_reg [0x0b] < mb_reg [0x0e]) && (mb_reg [0x0f] < mb_reg [0x0e]) && ((mb_reg [0x0e] + mb_reg [0x0f]) >= 0))
     { mb_reg [0x07] = mb_reg [0x0e]; mb_reg [0x08] = mb_reg [0x0f]; }
   else
     { mb_reg [0x04] = mb_reg [0x0e]; mb_reg [0x05] = mb_reg [0x0f]; }
 }
      while (--mb_reg [0x06] >= 0);
      mb_result = mb_reg [0x08];
      break;
    case 0x1d:
      mb_reg [0x03] = (mb_reg [0x03] & 0x00ff) | (data << 8);
      mb_reg [0x02] -= mb_reg [0x00];
      if (mb_reg [0x02] < 0)
 mb_reg [0x02] = -mb_reg [0x02];
      mb_reg [0x03] -= mb_reg [0x01];
      if (mb_reg [0x03] < 0)
 mb_reg [0x03] = -mb_reg [0x03];
    case 0x1e:
      if (mb_reg [0x03] >= mb_reg [0x02])
        { mb_reg [0x0c] = mb_reg [0x02]; mb_reg [0x0d] = mb_reg [0x03]; }
      else
 { mb_reg [0x0d] = mb_reg [0x02]; mb_reg [0x0c] = mb_reg [0x03]; }
      mb_reg [0x0c] >>= 2;
      mb_reg [0x0d] += mb_reg [0x0c];
      mb_reg [0x0c] >>= 1;
      mb_result = mb_reg [0x0d] = (mb_reg [0x0c] + mb_reg [0x0d]);
      break;
    case 0x1f:
      break;
    }
}

variable_types: msb int


decompiled_code:
__int64 mb_status_r()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
data_t mb_status_r(offs_t offset)
{
 return 0x00;
}

canonical_original_code:
unsigned int mb_status_r(unsigned int offset)
{
 return 0x00;
}

variable_types:
offset
unsigned int

return_type: unsigned int


decompiled_code:
__int64 mb_lo_r()
{
return mb_result;
}

canonical_decompiled_code:
__int64 func2()
{
return mb_result;
}

original_code:
data_t mb_lo_r(offs_t offset)
{
 return mb_result & 0xff;
}

canonical_original_code:
unsigned int mb_lo_r(unsigned int offset)
{
 return mb_result & 0xff;
}


decompiled_code:
__int64 mb_hi_r()
{
return unk_6E1;
}

canonical_decompiled_code:
__int64 func3()
{
return unk_6E1;
}

original_code:
data_t mb_hi_r(offs_t offset)
{
 return (mb_result >> 8) & 0xff;
}

canonical_original_code:
unsigned int mb_hi_r(unsigned int offset)
{
 return (mb_result >> 8) & 0xff;
}


original_code:
void sauro_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2,bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void sauro_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2; int bit3;
  bit0 = (color_prom[0] >> 0) & 0x01;
  bit1 = (color_prom[0] >> 1) & 0x01;
  bit2 = (color_prom[0] >> 2) & 0x01;
  bit3 = (color_prom[0] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*Machine->drv->total_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*Machine->drv->total_colors] >> 1) & 0x01;
  bit2 = (color_prom[2*Machine->drv->total_colors] >> 2) & 0x01;
  bit3 = (color_prom[2*Machine->drv->total_colors] >> 3) & 0x01;
  *(palette++) = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: i int

return_type: void


decompiled_code:
void __fastcall sauro_scroll1_w(__int64 a1, int a2)
{
scroll1 = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
scroll1 = a2;
}

original_code:
void sauro_scroll1_w(offs_t offset,data_t data)
{
 scroll1 = data;
}

canonical_original_code:
void sauro_scroll1_w(unsigned int offset, unsigned int data)
{
 scroll1 = data;
}

variable_types:
data
unsigned int


decompiled_code:
void *__fastcall sauro_flipscreen_w(__int64 a1, int a2)
{
void *result; // rax

if ( flipscreen != a2 )
{
flipscreen = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(__int64 a1, int a2)
{
void *result; // rax

if ( flipscreen != a2 )
{
flipscreen = a2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void sauro_flipscreen_w(offs_t offset,data_t data)
{
 if (flipscreen != data)
 {
  flipscreen = data;
  memset(dirtybuffer, 1, videoram_size);
 }
}

canonical_original_code:
void sauro_flipscreen_w(unsigned int offset, unsigned int data)
{
 if (flipscreen != data)
 {
  flipscreen = data;
  memset(dirtybuffer, 1, videoram_size);
 }
}


decompiled_code:
__int64 __fastcall sauro_vh_screenrefresh(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 i; // rbx
unsigned int v3; // esi
__int64 result; // rax
unsigned __int64 v5; // rbx
unsigned __int8 v6; // r8
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( videoram_size )
{
v1 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v1) )
{
*(_BYTE *)(dirtybuffer + v1) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v1) + ((*(unsigned __int8 *)(colorram + v1) << 8) & 0x700u),
*(_BYTE *)(colorram + v1) >> 4);
}
++v1;
}
while ( videoram_size > v1 );
}
if ( flipscreen )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll1, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
else
{
v7[0] = -scroll1;
copyscrollbitmap(a1, tmpbitmap, 1LL, v7, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
for ( i = 0LL; videoram_size > i; ++i )
{
v3 = *(unsigned __int8 *)(sauro_videoram2 + i) + ((*(unsigned __int8 *)(sauro_colorram2 + i) << 8) & 0x700);
if ( v3 != 25 )
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v3, *(_BYTE *)(sauro_colorram2 + i) >> 4);
}
result = spriteram_size - 1LL;
if ( (unsigned __int64)(spriteram_size - 1LL) > 3 )
{
v5 = 3LL;
do
{
if ( *(unsigned __int8 *)(spriteram + v5) != 248 )
{
v6 = *(_BYTE *)(spriteram + v5 + 3);
if ( (v6 & 8) != 0 || *(unsigned __int8 *)(spriteram + v5 + 2) > 0x3Fu )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
((*(unsigned __int8 *)(spriteram + v5 + 3) << 8) & 0x300)
+ (unsigned int)*(unsigned __int8 *)(spriteram + v5 + 1),
v6 >> 4);
}
v5 += 4LL;
result = spriteram_size - 1LL;
}
while ( spriteram_size - 1LL > v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rbx
unsigned __int64 i; // rbx
unsigned int v3; // esi
__int64 result; // rax
unsigned __int64 v5; // rbx
unsigned __int8 v6; // r8
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

if ( videoram_size )
{
v1 = 0LL;
do
{
if ( *(_BYTE *)(dirtybuffer + v1) )
{
*(_BYTE *)(dirtybuffer + v1) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(videoram + v1) + ((*(unsigned __int8 *)(colorram + v1) << 8) & 0x700u),
*(_BYTE *)(colorram + v1) >> 4);
}
++v1;
}
while ( videoram_size > v1 );
}
if ( flipscreen )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, &scroll1, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
else
{
v7[0] = -scroll1;
copyscrollbitmap(a1, tmpbitmap, 1LL, v7, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
}
for ( i = 0LL; videoram_size > i; ++i )
{
v3 = *(unsigned __int8 *)(sauro_videoram2 + i) + ((*(unsigned __int8 *)(sauro_colorram2 + i) << 8) & 0x700);
if ( v3 != 25 )
drawgfx(a1, *(_QWORD *)(Machine + 512LL), v3, *(_BYTE *)(sauro_colorram2 + i) >> 4);
}
result = spriteram_size - 1LL;
if ( (unsigned __int64)(spriteram_size - 1LL) > 3 )
{
v5 = 3LL;
do
{
if ( *(unsigned __int8 *)(spriteram + v5) != 248 )
{
v6 = *(_BYTE *)(spriteram + v5 + 3);
if ( (v6 & 8) != 0 || *(unsigned __int8 *)(spriteram + v5 + 2) > 0x3Fu )
drawgfx(
a1,
*(_QWORD *)(Machine + 528LL),
((*(unsigned __int8 *)(spriteram + v5 + 3) << 8) & 0x300)
+ (unsigned int)*(unsigned __int8 *)(spriteram + v5 + 1),
v6 >> 4);
}
v5 += 4LL;
result = spriteram_size - 1LL;
}
while ( spriteram_size - 1LL > v5 );
}
return result;
}

original_code:
void sauro_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs,code,sx,sy,color,flipx;
 for (offs = 0; offs < videoram_size; offs ++)
 {
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  code = videoram[offs] + ((colorram[offs] & 0x07) << 8);
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (colorram[offs] >> 4) & 0x0f;
  flipx = colorram[offs] & 0x08;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(tmpbitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
 }
 if (!flipscreen)
 {
  int scroll = -scroll1;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll ,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 else
 {
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll1,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  code = sauro_videoram2[offs] + ((sauro_colorram2[offs] & 0x07) << 8);
  if (code == 0x19) continue;
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (sauro_colorram2[offs] >> 4) & 0x0f;
  flipx = sauro_colorram2[offs] & 0x08;
  sx = (sx - scroll2) & 0xff;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 };
 for (offs = 3;offs < spriteram_size - 1;offs += 4)
 {
  sy = spriteram[offs];
  if (sy == 0xf8) continue;
  code = spriteram[offs+1] + ((spriteram[offs+3] & 0x03) << 8);
  sx = spriteram[offs+2];
  sy = 236 - sy;
  color = (spriteram[offs+3] >> 4) & 0x0f;
  if (spriteram[offs+3] & 0x08)
  {
   if (sx > 0xc0)
   {
    sx = (signed int)(signed char)sx;
   }
  }
  else
  {
   if (sx < 0x40) continue;
  }
  flipx = spriteram[offs+3] & 0x04;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = (235 - sx) & 0xff;
   sy = 240 - sy;
  }
  drawgfx(bitmap, Machine->gfx[2],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void sauro_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs; int code; int sx; int sy; int color; int flipx;
 for (offs = 0; offs < videoram_size; offs ++)
 {
  if (!dirtybuffer[offs]) continue;
  dirtybuffer[offs] = 0;
  code = videoram[offs] + ((colorram[offs] & 0x07) << 8);
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (colorram[offs] >> 4) & 0x0f;
  flipx = colorram[offs] & 0x08;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(tmpbitmap,Machine->gfx[1],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
 }
 if (!flipscreen)
 {
  int scroll = -scroll1;
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll ,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 else
 {
  copyscrollbitmap(bitmap,tmpbitmap,1,&scroll1,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 }
 for (offs = 0; offs < videoram_size; offs++)
 {
  code = sauro_videoram2[offs] + ((sauro_colorram2[offs] & 0x07) << 8);
  if (code == 0x19) continue;
  sx = 8 * (offs / 32);
  sy = 8 * (offs % 32);
  color = (sauro_colorram2[offs] >> 4) & 0x0f;
  flipx = sauro_colorram2[offs] & 0x08;
  sx = (sx - scroll2) & 0xff;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = 248 - sx;
   sy = 248 - sy;
  }
  drawgfx(bitmap,Machine->gfx[0],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 };
 for (offs = 3;offs < spriteram_size - 1;offs += 4)
 {
  sy = spriteram[offs];
  if (sy == 0xf8) continue;
  code = spriteram[offs+1] + ((spriteram[offs+3] & 0x03) << 8);
  sx = spriteram[offs+2];
  sy = 236 - sy;
  color = (spriteram[offs+3] >> 4) & 0x0f;
  if (spriteram[offs+3] & 0x08)
  {
   if (sx > 0xc0)
   {
    sx = (int)(char)sx;
   }
  }
  else
  {
   if (sx < 0x40) continue;
  }
  flipx = spriteram[offs+3] & 0x04;
  if (flipscreen)
  {
   flipx = !flipx;
   sx = (235 - sx) & 0xff;
   sy = 240 - sy;
  }
  drawgfx(bitmap, Machine->gfx[2],
    code,
    color,
    flipx,flipscreen,
    sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: offs int

variable_types: code int

variable_types: sx int

variable_types: sy int

variable_types: color int

variable_types: flipx int

variable_types: scroll int


original_code:
static void init_sauro(void)
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memset(&RAM[0xe000], 0, 0x100);
 RAM[0xe000] = 1;
}

canonical_original_code:
static void init_sauro()
{
 unsigned char *RAM = memory_region(REGION_CPU1);
 memset(&RAM[0xe000], 0, 0x100);
 RAM[0xe000] = 1;
}

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 sauron_interrupt()
{
cpu_cause_interrupt(1LL, 4294967294LL);
return 4294966296LL;
}

original_code:
static int sauron_interrupt(void)
{
 cpu_cause_interrupt(1,-2);
 return -1000;
}

canonical_original_code:
static int sauron_interrupt()
{
 cpu_cause_interrupt(1,-2);
 return -1000;
}

return_type: int


decompiled_code:
__int64 __fastcall sauro_sound_command_r(unsigned int a1)
{
unsigned int v1; // ebp

v1 = soundlatch_r();
soundlatch_clear_w(a1, 0LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
unsigned int v1; // ebp

v1 = soundlatch_r();
soundlatch_clear_w(a1, 0LL);
return v1;
}

original_code:
static data_t sauro_sound_command_r(offs_t offset)
{
 int ret = soundlatch_r(offset);
 soundlatch_clear_w(offset,0);
 return ret;
}

canonical_original_code:
static unsigned int sauro_sound_command_r(unsigned int offset)
{
 int ret = soundlatch_r(offset);
 soundlatch_clear_w(offset,0);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall sauro_sound_command_w(__int64 a1, __int64 a2)
{
LOBYTE(a2) = a2 | 0x80;
return soundlatch_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
LOBYTE(a2) = a2 | 0x80;
return soundlatch_w(a1, a2);
}

original_code:
static void sauro_sound_command_w(offs_t offset,data_t data)
{
 data |= 0x80;
 soundlatch_w(offset,data);
}

canonical_original_code:
static void sauro_sound_command_w(unsigned int offset, unsigned int data)
{
 data |= 0x80;
 soundlatch_w(offset,data);
}


decompiled_code:
__int64 __fastcall dotron_change_palette(int a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rbx
int v3; // ebp
int v4; // er12

result = artwork_backdrop;
v2 = (unsigned __int8 *)&dotron_palettes + 768 * a1;
if ( *(int *)(artwork_backdrop + 48LL) > 0 )
{
v3 = 0;
v4 = *(_DWORD *)(artwork_backdrop + 68LL) + 95;
do
{
palette_change_color((unsigned int)(v4 + v3++), *v2, v2[1], v2[2]);
v2 += 3;
result = artwork_backdrop;
}
while ( *(_DWORD *)(artwork_backdrop + 48LL) > v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 result; // rax
unsigned __int8 *v2; // rbx
int v3; // ebp
int v4; // er12

result = artwork_backdrop;
v2 = (unsigned __int8 *)&dotron_palettes + 768 * a1;
if ( *(int *)(artwork_backdrop + 48LL) > 0 )
{
v3 = 0;
v4 = *(_DWORD *)(artwork_backdrop + 68LL) + 95;
do
{
palette_change_color((unsigned int)(v4 + v3++), *v2, v2[1], v2[2]);
v2 += 3;
result = artwork_backdrop;
}
while ( *(_DWORD *)(artwork_backdrop + 48LL) > v3 );
}
return result;
}

original_code:
static void dotron_change_palette(int which)
{
 UINT8 *new_palette;
 int i, offset;
 offset = artwork_backdrop->start_pen + 95;
 new_palette = dotron_palettes[which];
 for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  palette_change_color(i + offset, new_palette[i * 3], new_palette[i * 3 + 1], new_palette[i * 3 + 2]);
}

canonical_original_code:
static void dotron_change_palette(int which)
{
 unsigned char *new_palette;
 int i; int offset;
 offset = artwork_backdrop->start_pen + 95;
 new_palette = dotron_palettes[which];
 for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  palette_change_color(i + offset, new_palette[i * 3], new_palette[i * 3 + 1], new_palette[i * 3 + 2]);
}

variable_types: which int

variable_types: offset int


decompiled_code:
void *__fastcall mcr3_update_background(__int64 a1, unsigned __int8 a2)
{
void *result; // rax
int v3; // ebx
__int64 v6; // rbp
unsigned int v7; // edx
int v8; // esi
__int64 v9; // rcx
unsigned int v10; // edi

result = &videoram_size;
v3 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v6 = v3;
do
{
result = (void *)dirtybuffer;
if ( *(_BYTE *)(dirtybuffer + v6) )
{
v7 = ((((unsigned int)((int)(v3 + ((unsigned int)v3 >> 31)) >> 31) >> 27) + (unsigned __int8)(v3 / 2)) & 0x1F)
- ((unsigned int)((int)(v3 + ((unsigned int)v3 >> 31)) >> 31) >> 27);
v8 = v3 / 64;
v9 = a2 ^ (*(unsigned __int8 *)(videoram + v6 + 1) >> 4) & 3u;
v10 = ((*(_BYTE *)(videoram + v6 + 1) & 3) << 8) + *(unsigned __int8 *)(videoram + v6);
if ( mcr_cocktail_flip )
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v10,
v9,
((*(_BYTE *)(videoram + v6 + 1) >> 2) ^ 1) & 1,
((*(_BYTE *)(videoram + v6 + 1) >> 3) ^ 1) & 1,
16 * (31 - v7),
(unsigned int)(16 * (29 - v8)),
Machine + 776LL,
0LL,
0LL);
else
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v10,
v9,
*(_BYTE *)(videoram + v6 + 1) & 4,
*(_BYTE *)(videoram + v6 + 1) & 8,
16 * v7,
(unsigned int)(16 * v8),
Machine + 776LL,
0LL,
0LL);
result = (void *)dirtybuffer;
*(_BYTE *)(dirtybuffer + v6) = 0;
}
v6 -= 2LL;
v3 -= 2;
}
while ( v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, unsigned __int8 a2)
{
void *result; // rax
int v3; // ebx
__int64 v6; // rbp
unsigned int v7; // edx
int v8; // esi
__int64 v9; // rcx
unsigned int v10; // edi

result = &videoram_size;
v3 = videoram_size - 2;
if ( videoram_size - 2 >= 0 )
{
v6 = v3;
do
{
result = (void *)dirtybuffer;
if ( *(_BYTE *)(dirtybuffer + v6) )
{
v7 = ((((unsigned int)((int)(v3 + ((unsigned int)v3 >> 31)) >> 31) >> 27) + (unsigned __int8)(v3 / 2)) & 0x1F)
- ((unsigned int)((int)(v3 + ((unsigned int)v3 >> 31)) >> 31) >> 27);
v8 = v3 / 64;
v9 = a2 ^ (*(unsigned __int8 *)(videoram + v6 + 1) >> 4) & 3u;
v10 = ((*(_BYTE *)(videoram + v6 + 1) & 3) << 8) + *(unsigned __int8 *)(videoram + v6);
if ( mcr_cocktail_flip )
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v10,
v9,
((*(_BYTE *)(videoram + v6 + 1) >> 2) ^ 1) & 1,
((*(_BYTE *)(videoram + v6 + 1) >> 3) ^ 1) & 1,
16 * (31 - v7),
(unsigned int)(16 * (29 - v8)),
Machine + 776LL,
0LL,
0LL);
else
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v10,
v9,
*(_BYTE *)(videoram + v6 + 1) & 4,
*(_BYTE *)(videoram + v6 + 1) & 8,
16 * v7,
(unsigned int)(16 * v8),
Machine + 776LL,
0LL,
0LL);
result = (void *)dirtybuffer;
*(_BYTE *)(dirtybuffer + v6) = 0;
}
v6 -= 2LL;
v3 -= 2;
}
while ( v3 >= 0 );
}
return result;
}

original_code:
static void mcr3_update_background(struct osd_bitmap *bitmap, UINT8 color_xor)
{
 int offs;
 for (offs = videoram_size - 2; offs >= 0; offs -= 2)
 {
  if (dirtybuffer[offs])
  {
   int mx = (offs / 2) % 32;
   int my = (offs / 2) / 32;
   int attr = videoram[offs + 1];
   int color = ((attr & 0x30) >> 4) ^ color_xor;
   int code = videoram[offs] + 256 * (attr & 0x03);
   if (!mcr_cocktail_flip)
    drawgfx(bitmap, Machine->gfx[0], code, color, attr & 0x04, attr & 0x08,
      16 * mx, 16 * my, &Machine->visible_area, TRANSPARENCY_NONE, 0);
   else
    drawgfx(bitmap, Machine->gfx[0], code, color, !(attr & 0x04), !(attr & 0x08),
      16 * (31 - mx), 16 * (29 - my), &Machine->visible_area, TRANSPARENCY_NONE, 0);
   dirtybuffer[offs] = 0;
  }
 }
}

canonical_original_code:
static void mcr3_update_background(struct osd_bitmap *bitmap, unsigned char color_xor)
{
 int offs;
 for (offs = videoram_size - 2; offs >= 0; offs -= 2)
 {
  if (dirtybuffer[offs])
  {
   int mx = (offs / 2) % 32;
   int my = (offs / 2) / 32;
   int attr = videoram[offs + 1];
   int color = ((attr & 0x30) >> 4) ^ color_xor;
   int code = videoram[offs] + 256 * (attr & 0x03);
   if (!mcr_cocktail_flip)
    drawgfx(bitmap, Machine->gfx[0], code, color, attr & 0x04, attr & 0x08,
      16 * mx, 16 * my, &Machine->visible_area, TRANSPARENCY_NONE, 0);
   else
    drawgfx(bitmap, Machine->gfx[0], code, color, !(attr & 0x04), !(attr & 0x08),
      16 * (31 - mx), 16 * (29 - my), &Machine->visible_area, TRANSPARENCY_NONE, 0);
   dirtybuffer[offs] = 0;
  }
 }
}

variable_types: mx int

variable_types: my int

variable_types: attr int

user_defined_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; }


original_code:
void mcr3_paletteram_w(offs_t offset,data_t data)
{
 int r, g, b;
 paletteram[offset] = data;
 offset &= 0x7f;
 r = ((offset & 1) << 2) + (data >> 6);
 g = (data >> 0) & 7;
 b = (data >> 3) & 7;
 r = (r << 5) | (r << 2) | (r >> 1);
 g = (g << 5) | (g << 2) | (g >> 1);
 b = (b << 5) | (b << 2) | (b >> 1);
 palette_change_color(offset / 2, r, g, b);
}

canonical_original_code:
void mcr3_paletteram_w(unsigned int offset, unsigned int data)
{
 int r; int g; int b;
 paletteram[offset] = data;
 offset &= 0x7f;
 r = ((offset & 1) << 2) + (data >> 6);
 g = (data >> 0) & 7;
 b = (data >> 3) & 7;
 r = (r << 5) | (r << 2) | (r >> 1);
 g = (g << 5) | (g << 2) | (g >> 1);
 b = (b << 5) | (b << 2) | (b >> 1);
 palette_change_color(offset / 2, r, g, b);
}

variable_types:
offset
unsigned int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 spyhunt_vh_start()
{
size_t v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
spyhunt_backbitmap = bitmap_alloc(4096LL, 1024LL);
if ( spyhunt_backbitmap )
{
spyhunt_scrolly = 0;
spyhunt_scrollx = 0;
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func5()
{
size_t v0; // rbx
void *v1; // rdi
__int64 result; // rax

v0 = videoram_size;
v1 = malloc(videoram_size);
dirtybuffer = v1;
if ( !v1 )
return 1LL;
memset(v1, 1, v0);
spyhunt_backbitmap = bitmap_alloc(4096LL, 1024LL);
if ( spyhunt_backbitmap )
{
spyhunt_scrolly = 0;
spyhunt_scrollx = 0;
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
int spyhunt_vh_start(void)
{
 dirtybuffer = (unsigned char*)malloc(videoram_size);
 if (!dirtybuffer)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 spyhunt_backbitmap = bitmap_alloc(64*64, 32*32);
 if (!spyhunt_backbitmap)
 {
  free(dirtybuffer);
  return 1;
 }
 spyhunt_scrollx = spyhunt_scrolly = 0;
 return 0;
}

canonical_original_code:
int spyhunt_vh_start()
{
 dirtybuffer = (unsigned char *)malloc(videoram_size);
 if (!dirtybuffer)
  return 1;
 memset(dirtybuffer, 1, videoram_size);
 spyhunt_backbitmap = bitmap_alloc(64*64, 32*32);
 if (!spyhunt_backbitmap)
 {
  free(dirtybuffer);
  return 1;
 }
 spyhunt_scrollx = spyhunt_scrolly = 0;
 return 0;
}


decompiled_code:
void spyhunt_vh_stop()
{
bitmap_free(spyhunt_backbitmap);
free(dirtybuffer);
}

canonical_decompiled_code:
void func6()
{
bitmap_free(spyhunt_backbitmap);
free(dirtybuffer);
}

original_code:
void spyhunt_vh_stop(void)
{
 bitmap_free(spyhunt_backbitmap);
 free(dirtybuffer);
}


decompiled_code:
__int64 dotron_vh_start()
{
unsigned int v0; // er14
unsigned int v2; // er12
int v3; // eax
unsigned int i; // ebx
_QWORD *v5; // rax
_QWORD *v6; // rbx
_BYTE *v7; // rdx
int v8; // edi
__int64 v9; // rax
int v10; // ecx
int v11; // ecx
int v12; // ecx
int v13; // ecx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
backdrop_load("dotron.png", 64LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 64));
v2 = 0;
if ( artwork_backdrop )
{
do
{
v5 = artwork_backdrop;
for ( i = 0; *(_DWORD *)*artwork_backdrop > (signed int)i; v5 = artwork_backdrop )
{
v3 = read_pixel(v5[3], i, v2);
plot_pixel(artwork_backdrop[3], i++, v2, (unsigned int)(v3 + 95));
}
++v2;
}
while ( v2 != 138 );
backdrop_refresh(artwork_backdrop);
v6 = artwork_backdrop;
memcpy(&dotron_palettes, (const void *)artwork_backdrop[5], 3 * *((_DWORD *)artwork_backdrop + 12));
if ( *((int *)v6 + 12) > 0 )
{
v7 = &unk_1300;
v8 = 0;
v9 = 0LL;
do
{
v10 = 2 * *(unsigned __int8 *)(v6[5] + v9);
if ( v10 > 255 )
LOBYTE(v10) = -1;
*v7 = v10;
v7[1] = *(_BYTE *)(v6[5] + v9 + 1);
v11 = 2 * *(unsigned __int8 *)(v6[5] + v9 + 2);
if ( v11 > 255 )
LOBYTE(v11) = -1;
v7[2] = v11;
v12 = 3 * *(unsigned __int8 *)(v6[5] + v9);
if ( v12 > 255 )
LOBYTE(v12) = -1;
v7[768] = v12;
v7[769] = *(_BYTE *)(v6[5] + v9 + 1);
v13 = 3 * *(unsigned __int8 *)(v6[5] + v9 + 2);
if ( v13 > 255 )
LOBYTE(v13) = -1;
v7[770] = v13;
++v8;
v9 += 3LL;
v7 += 3;
}
while ( *((_DWORD *)v6 + 12) > v8 );
}
}
}
return v0;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er14
unsigned int v2; // er12
int v3; // eax
unsigned int i; // ebx
_QWORD *v5; // rax
_QWORD *v6; // rbx
_BYTE *v7; // rdx
int v8; // edi
__int64 v9; // rax
int v10; // ecx
int v11; // ecx
int v12; // ecx
int v13; // ecx

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
backdrop_load("dotron.png", 64LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 64));
v2 = 0;
if ( artwork_backdrop )
{
do
{
v5 = artwork_backdrop;
for ( i = 0; *(_DWORD *)*artwork_backdrop > (signed int)i; v5 = artwork_backdrop )
{
v3 = read_pixel(v5[3], i, v2);
plot_pixel(artwork_backdrop[3], i++, v2, (unsigned int)(v3 + 95));
}
++v2;
}
while ( v2 != 138 );
backdrop_refresh(artwork_backdrop);
v6 = artwork_backdrop;
memcpy(&dotron_palettes, (const void *)artwork_backdrop[5], 3 * *((_DWORD *)artwork_backdrop + 12));
if ( *((int *)v6 + 12) > 0 )
{
v7 = &unk_1300;
v8 = 0;
v9 = 0LL;
do
{
v10 = 2 * *(unsigned __int8 *)(v6[5] + v9);
if ( v10 > 255 )
LOBYTE(v10) = -1;
*v7 = v10;
v7[1] = *(_BYTE *)(v6[5] + v9 + 1);
v11 = 2 * *(unsigned __int8 *)(v6[5] + v9 + 2);
if ( v11 > 255 )
LOBYTE(v11) = -1;
v7[2] = v11;
v12 = 3 * *(unsigned __int8 *)(v6[5] + v9);
if ( v12 > 255 )
LOBYTE(v12) = -1;
v7[768] = v12;
v7[769] = *(_BYTE *)(v6[5] + v9 + 1);
v13 = 3 * *(unsigned __int8 *)(v6[5] + v9 + 2);
if ( v13 > 255 )
LOBYTE(v13) = -1;
v7[770] = v13;
++v8;
v9 += 3LL;
v7 += 3;
}
while ( *((_DWORD *)v6 + 12) > v8 );
}
}
}
return v0;
}

original_code:
int dotron_vh_start(void)
{
 int i, x, y;
 if (generic_vh_start())
  return 1;
 backdrop_load("dotron.png", 64, Machine->drv->total_colors-64);
 if (artwork_backdrop)
 {
  for (y = 0; y < 138; y++)
   for (x = 0; x < artwork_backdrop->artwork->width; x++)
   {
    int newpixel = read_pixel(artwork_backdrop->orig_artwork, x, y) + 95;
    plot_pixel(artwork_backdrop->orig_artwork, x, y, newpixel);
   }
  backdrop_refresh(artwork_backdrop);
  memcpy(dotron_palettes[0], artwork_backdrop->orig_palette, 3 * artwork_backdrop->num_pens_used);
  for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  {
   dotron_palettes[1][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3] * 2):(255));
   dotron_palettes[1][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[1][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 2):(255));
   dotron_palettes[2][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3] * 3):(255));
   dotron_palettes[2][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[2][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 3):(255));
  }
 }
 return 0;
}

canonical_original_code:
int dotron_vh_start()
{
 int i; int x; int y;
 if (generic_vh_start())
  return 1;
 backdrop_load("dotron.png", 64, Machine->drv->total_colors-64);
 if (artwork_backdrop)
 {
  for (y = 0; y < 138; y++)
   for (x = 0; x < artwork_backdrop->artwork->width; x++)
   {
    int newpixel = read_pixel(artwork_backdrop->orig_artwork, x, y) + 95;
    plot_pixel(artwork_backdrop->orig_artwork, x, y, newpixel);
   }
  backdrop_refresh(artwork_backdrop);
  memcpy(dotron_palettes[0], artwork_backdrop->orig_palette, 3 * artwork_backdrop->num_pens_used);
  for (i = 0; i < artwork_backdrop->num_pens_used; i++)
  {
   dotron_palettes[1][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3] * 2):(255));
   dotron_palettes[1][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[1][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 2)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 2):(255));
   dotron_palettes[2][i * 3 + 0] = ((artwork_backdrop->orig_palette[i * 3] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3] * 3):(255));
   dotron_palettes[2][i * 3 + 1] = artwork_backdrop->orig_palette[i * 3 + 1];
   dotron_palettes[2][i * 3 + 2] = ((artwork_backdrop->orig_palette[i * 3 + 2] * 3)<(255)?(artwork_backdrop->orig_palette[i * 3 + 2] * 3):(255));
  }
 }
 return 0;
}

variable_types: i int

variable_types: x int

variable_types: y int

variable_types: newpixel int


decompiled_code:
void __fastcall dotron_change_light(char a1)
{
light_status = a1;
}

canonical_decompiled_code:
void __fastcall func8(char a1)
{
light_status = a1;
}

original_code:
void dotron_change_light(int light)
{
 light_status = light;
}

variable_types: light int


decompiled_code:
__int64 __fastcall wardner_sprite_r(unsigned int a1)
{
return *(unsigned __int8 *)(spriteram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
return *(unsigned __int8 *)(spriteram + a1);
}

original_code:
static data_t wardner_sprite_r(offs_t offset)
{
 return spriteram[offset];
}

canonical_original_code:
static unsigned int wardner_sprite_r(unsigned int offset)
{
 return spriteram[offset];
}


decompiled_code:
__int64 __fastcall wardner_sharedram_r(unsigned int a1)
{
return *(unsigned __int8 *)(wardner_sharedram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
return *(unsigned __int8 *)(wardner_sharedram + a1);
}

original_code:
static data_t wardner_sharedram_r(offs_t offset)
{
 return wardner_sharedram[offset];
}

canonical_original_code:
static unsigned int wardner_sharedram_r(unsigned int offset)
{
 return wardner_sharedram[offset];
}


decompiled_code:
__int64 __fastcall wardner_spare_pal_ram_r(unsigned int a1)
{
return *(unsigned __int8 *)(wardner_spare_pal_ram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return *(unsigned __int8 *)(wardner_spare_pal_ram + a1);
}

original_code:
static data_t wardner_spare_pal_ram_r(offs_t offset)
{
 return wardner_spare_pal_ram[offset];
}

canonical_original_code:
static unsigned int wardner_spare_pal_ram_r(unsigned int offset)
{
 return wardner_spare_pal_ram[offset];
}


decompiled_code:
void __fastcall wardner_ramrom_banks_w(__int64 a1, int a2)
{
wardner_membank = a2;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
wardner_membank = a2;
}

original_code:
static void wardner_ramrom_banks_w(offs_t offset,data_t data)
{
 wardner_membank = data;
}

canonical_original_code:
static void wardner_ramrom_banks_w(unsigned int offset, unsigned int data)
{
 wardner_membank = data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 init_wardner()
{
__int64 v0; // rdx
__int64 result; // rax
char v2; // cl

v0 = memory_region(131LL);
for ( result = 0LL; result != 1536; ++result )
{
v2 = *(_BYTE *)(v0 + result + 6144);
*(_BYTE *)(v0 + 2 * result) = *(_BYTE *)(v0 + result + 4096);
*(_BYTE *)(v0 + 2 * result + 1) = v2;
*(_BYTE *)(v0 + result + 4096) = 0;
*(_BYTE *)(v0 + result + 6144) = 0;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rdx
__int64 result; // rax
char v2; // cl

v0 = memory_region(131LL);
for ( result = 0LL; result != 1536; ++result )
{
v2 = *(_BYTE *)(v0 + result + 6144);
*(_BYTE *)(v0 + 2 * result) = *(_BYTE *)(v0 + result + 4096);
*(_BYTE *)(v0 + 2 * result + 1) = v2;
*(_BYTE *)(v0 + result + 4096) = 0;
*(_BYTE *)(v0 + result + 6144) = 0;
}
return result;
}

original_code:
static void init_wardner(void)
{
 int A;
 unsigned char datamsb;
 unsigned char datalsb;
 unsigned char *DSP_ROMS = memory_region(REGION_CPU3);
 for (A = 0;A < 0x0600;A++)
 {
  datamsb = DSP_ROMS[0x1000 + A];
  datalsb = DSP_ROMS[0x1800 + A];
  DSP_ROMS[(A*2)] = datamsb;
  DSP_ROMS[(A*2)+1] = datalsb;
  DSP_ROMS[0x1000 + A] = 00;
  DSP_ROMS[0x1800 + A] = 00;
 }
}

canonical_original_code:
static void init_wardner()
{
 int A;
 unsigned char datamsb;
 unsigned char datalsb;
 unsigned char *DSP_ROMS = memory_region(REGION_CPU3);
 for (A = 0;A < 0x0600;A++)
 {
  datamsb = DSP_ROMS[0x1000 + A];
  datalsb = DSP_ROMS[0x1800 + A];
  DSP_ROMS[(A*2)] = datamsb;
  DSP_ROMS[(A*2)+1] = datalsb;
  DSP_ROMS[0x1000 + A] = 00;
  DSP_ROMS[0x1800 + A] = 00;
 }
}

variable_types: A int

variable_types:
datamsb
unsigned char

variable_types:
datalsb
unsigned char


decompiled_code:
__int64 wardner_interrupt()
{
if ( !twincobr_intenable )
return ignore_interrupt();
twincobr_intenable = 0;
return interrupt();
}

canonical_decompiled_code:
__int64 func9()
{
if ( !twincobr_intenable )
return ignore_interrupt();
twincobr_intenable = 0;
return interrupt();
}

original_code:
static int wardner_interrupt(void)
{
 if (twincobr_intenable) {
  twincobr_intenable = 0;
  return interrupt();
 }
 else return ignore_interrupt();
}

canonical_original_code:
static int wardner_interrupt()
{
 if (twincobr_intenable) {
  twincobr_intenable = 0;
  return interrupt();
 }
 else return ignore_interrupt();
}


decompiled_code:
__int64 __fastcall wardner_ram_rom_r(int a1)
{
__int16 v1; // bx
__int64 result; // rax
unsigned int v3; // edi
int v4; // edx

v1 = a1;
result = (unsigned int)wardner_membank;
if ( wardner_membank )
return *(unsigned __int8 *)(memory_region(129LL) + (unsigned int)(a1 + ((wardner_membank + 1) << 15)));
v3 = a1 & 0xFFF;
v4 = (v1 + 0x8000) & 0xE000;
switch ( v4 )
{
case 40960:
if ( v3 <= 0xDFF )
result = paletteram_r();
else
result = wardner_spare_pal_ram_r(v1 & 0x1FF);
break;
case 49152:
if ( (v1 & 0x800) == 0 )
result = wardner_sharedram_r(v1 & 0x7FF);
break;
case 32768:
result = wardner_sprite_r(v3);
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
__int16 v1; // bx
__int64 result; // rax
unsigned int v3; // edi
int v4; // edx

v1 = a1;
result = (unsigned int)wardner_membank;
if ( wardner_membank )
return *(unsigned __int8 *)(memory_region(129LL) + (unsigned int)(a1 + ((wardner_membank + 1) << 15)));
v3 = a1 & 0xFFF;
v4 = (v1 + 0x8000) & 0xE000;
switch ( v4 )
{
case 40960:
if ( v3 <= 0xDFF )
result = paletteram_r();
else
result = func4(v1 & 0x1FF);
break;
case 49152:
if ( (v1 & 0x800) == 0 )
result = func2(v1 & 0x7FF);
break;
case 32768:
result = func0(v3);
break;
}
return result;
}

original_code:
static data_t wardner_ram_rom_r(offs_t offset)
{
 int wardner_data = 0;
 if (wardner_membank == 0)
 {
  int wardner_bank = offset + 0x8000;
  offset &= 0xfff;
  switch (wardner_bank & 0xe000)
  {
   case 0x8000: wardner_data = wardner_sprite_r(offset); break;
   case 0xa000: if (offset < 0xe00) { wardner_data = paletteram_r(offset); }
       else { wardner_data = wardner_spare_pal_ram_r(offset & 0x1ff); } break;
   case 0xc000: if (offset < 0x800) wardner_data = wardner_sharedram_r(offset & 0x7ff); break;
   default: break;
  }
 }
 else
 {
  unsigned char *wardner_rom = memory_region(REGION_CPU1);
  int wardner_rombank = 0x8000 * (wardner_membank + 1);
  wardner_data = wardner_rom[wardner_rombank + offset];
 }
 return wardner_data;
}

canonical_original_code:
static unsigned int wardner_ram_rom_r(unsigned int offset)
{
 int wardner_data = 0;
 if (wardner_membank == 0)
 {
  int wardner_bank = offset + 0x8000;
  offset &= 0xfff;
  switch (wardner_bank & 0xe000)
  {
   case 0x8000: wardner_data = wardner_sprite_r(offset); break;
   case 0xa000: if (offset < 0xe00) { wardner_data = paletteram_r(offset); }
       else { wardner_data = wardner_spare_pal_ram_r(offset & 0x1ff); } break;
   case 0xc000: if (offset < 0x800) wardner_data = wardner_sharedram_r(offset & 0x7ff); break;
   default: break;
  }
 }
 else
 {
  unsigned char *wardner_rom = memory_region(REGION_CPU1);
  int wardner_rombank = 0x8000 * (wardner_membank + 1);
  wardner_data = wardner_rom[wardner_rombank + offset];
 }
 return wardner_data;
}


irqhandler

decompiled_code:
__int64 __fastcall irqhandler(unsigned int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1);
}

original_code:
static void irqhandler(int linestate)
{
 cpu_set_irq_line(1,0,linestate);
}

variable_types: linestate int


decompiled_code:
__int64 __fastcall pulsar_sh_port1_w(__int64 a1, int a2)
{
char v2; // bl
__int64 result; // rax

v2 = a2 ^ (port1State | a2);
port1State = a2;
if ( (v2 & 1) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v2 & 2) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v2 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v2 & 8) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v2 & 0x10) != 0 )
result = sample_start(4LL, 4LL, 0LL);
if ( (v2 & 0x20) != 0 )
result = sample_start(5LL, 5LL, 0LL);
if ( (v2 & 0x40) != 0 )
result = sample_start(6LL, 6LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
char v2; // bl
__int64 result; // rax

v2 = a2 ^ (port1State | a2);
port1State = a2;
if ( (v2 & 1) != 0 )
result = sample_start(0LL, 0LL, 0LL);
if ( (v2 & 2) != 0 )
result = sample_start(1LL, 1LL, 0LL);
if ( (v2 & 4) != 0 )
result = sample_start(2LL, 2LL, 0LL);
if ( (v2 & 8) != 0 )
result = sample_start(3LL, 3LL, 0LL);
if ( (v2 & 0x10) != 0 )
result = sample_start(4LL, 4LL, 0LL);
if ( (v2 & 0x20) != 0 )
result = sample_start(5LL, 5LL, 0LL);
if ( (v2 & 0x40) != 0 )
result = sample_start(6LL, 6LL, 0LL);
return result;
}

original_code:
void pulsar_sh_port1_w(offs_t offset,data_t data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_KEY, SND_KEY, 0 );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_ALIENHIT, SND_ALIENHIT, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_PHIT, SND_PHIT, 0 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_ASHOOT, SND_ASHOOT, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PSHOOT, SND_PSHOOT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS, SND_BONUS, 0 );
 }
}

canonical_original_code:
void pulsar_sh_port1_w(unsigned int offset, unsigned int data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_KEY, SND_KEY, 0 );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_ALIENHIT, SND_ALIENHIT, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_PHIT, SND_PHIT, 0 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_ASHOOT, SND_ASHOOT, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PSHOOT, SND_PSHOOT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS, SND_BONUS, 0 );
 }
}

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int


decompiled_code:
__int64 __fastcall pulsar_sh_port2_w(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port2State_0 ^ (unsigned int)a2;
v3 = a2 & (port2State_0 ^ a2);
v4 = (port2State_0 ^ a2) & ~(_BYTE)a2;
port2State_0 = a2;
if ( (v4 & 1) != 0 )
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 2) != 0 )
result = sample_start(0LL, 8LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_stop(0LL);
if ( (v4 & 4) != 0 )
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 8) != 0 )
result = sample_start(10LL, 10LL, 1LL);
if ( (v3 & 8) != 0 )
result = sample_stop(10LL);
if ( (v4 & 0x10) != 0 )
result = sample_start(11LL, 11LL, 1LL);
if ( (v3 & 0x10) != 0 )
result = sample_stop(11LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2)
{
__int64 result; // rax
char v3; // bp
char v4; // bl

result = port2State_0 ^ (unsigned int)a2;
v3 = a2 & (port2State_0 ^ a2);
v4 = (port2State_0 ^ a2) & ~(_BYTE)a2;
port2State_0 = a2;
if ( (v4 & 1) != 0 )
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 2) != 0 )
result = sample_start(0LL, 8LL, 0LL);
if ( (v3 & 2) != 0 )
result = sample_stop(0LL);
if ( (v4 & 4) != 0 )
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 8) != 0 )
result = sample_start(10LL, 10LL, 1LL);
if ( (v3 & 8) != 0 )
result = sample_stop(10LL);
if ( (v4 & 0x10) != 0 )
result = sample_start(11LL, 11LL, 1LL);
if ( (v3 & 0x10) != 0 )
result = sample_stop(11LL);
return result;
}

original_code:
void pulsar_sh_port2_w(offs_t offset,data_t data)
{
 static int port2State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_SIZZLE, SND_SIZZLE, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_GATE, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BIRTH, SND_BIRTH, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_HBEAT, SND_HBEAT, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_HBEAT );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_MOVMAZE, SND_MOVMAZE, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_MOVMAZE );
 }
}

canonical_original_code:
void pulsar_sh_port2_w(unsigned int offset, unsigned int data)
{
 static int port2State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_SIZZLE, SND_SIZZLE, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_GATE, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BIRTH, SND_BIRTH, 0 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_HBEAT, SND_HBEAT, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_HBEAT );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_MOVMAZE, SND_MOVMAZE, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_MOVMAZE );
 }
}

variable_types:
offset
unsigned int


original_code:
void pingpong_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
 {
  int code;
  int bit0,bit1,bit2,bit3;
  code = *(color_prom++) & 0x0f;
  bit0 = (code >> 0) & 1;
  bit1 = (code >> 1) & 1;
  bit2 = (code >> 2) & 1;
  bit3 = (code >> 3) & 1;
  code = (bit0 << 3) | (bit1 << 2) | (bit2 << 1) | (bit3 << 0);
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = code;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

canonical_original_code:
void pingpong_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
 {
  int code;
  int bit0; int bit1; int bit2; int bit3;
  code = *(color_prom++) & 0x0f;
  bit0 = (code >> 0) & 1;
  bit1 = (code >> 1) & 1;
  bit2 = (code >> 2) & 1;
  bit3 = (code >> 3) & 1;
  code = (bit0 << 3) | (bit1 << 2) | (bit2 << 1) | (bit3 << 0);
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = code;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = (*(color_prom++) & 0x0f) + 0x10;
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *

variable_types: code int


decompiled_code:
void *__fastcall pingpong_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ebp
__int64 v5; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((8 * *(unsigned __int8 *)(colorram + v2)) & 0x100u),
*(_BYTE *)(colorram + v2) & 0x1F,
*(_BYTE *)(colorram + v2) & 0x40,
*(_BYTE *)(colorram + v2) & 0x80,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v5 = v4 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + v5 - 1) & 0x7F,
*(_BYTE *)(spriteram + v5 - 3) & 0x1F,
*(_BYTE *)(spriteram + v5 - 3) & 0x40,
*(_BYTE *)(spriteram + v5 - 3) & 0x80,
*(unsigned __int8 *)(spriteram + v5),
241 - (unsigned int)*(unsigned __int8 *)(spriteram + v5 - 2),
&spritevisiblearea,
6LL,
0LL);
v5 -= 4LL;
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
void *result; // rax
int v4; // ebp
__int64 v5; // rbx

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((8 * *(unsigned __int8 *)(colorram + v2)) & 0x100u),
*(_BYTE *)(colorram + v2) & 0x1F,
*(_BYTE *)(colorram + v2) & 0x40,
*(_BYTE *)(colorram + v2) & 0x80,
(unsigned int)(8 * (v1 % 32)),
(unsigned int)(8 * (v1 / 32)),
Machine + 776LL,
0LL,
0LL);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = &spriteram_size;
v4 = spriteram_size - 4;
if ( spriteram_size - 4 >= 0 )
{
v5 = v4 + 3LL;
do
{
result = (void *)drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
*(_BYTE *)(spriteram + v5 - 1) & 0x7F,
*(_BYTE *)(spriteram + v5 - 3) & 0x1F,
*(_BYTE *)(spriteram + v5 - 3) & 0x40,
*(_BYTE *)(spriteram + v5 - 3) & 0x80,
*(unsigned __int8 *)(spriteram + v5),
241 - (unsigned int)*(unsigned __int8 *)(spriteram + v5 - 2),
&spritevisiblearea,
6LL,
0LL);
v5 -= 4LL;
v4 -= 4;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
void pingpong_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipx,flipy,tchar,color;
   sx = offs % 32;
   sy = offs / 32;
   dirtybuffer[offs] = 0;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x80;
   color = colorram[offs] & 0x1F;
   tchar = (videoram[offs] + ((colorram[offs] & 0x20)<<3));
   drawgfx(tmpbitmap,Machine->gfx[0],
     tchar,
     color,
     flipx,flipy,
     8 * sx,8 * sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx,sy,flipx,flipy,color,schar;
  sx = spriteram[offs + 3];
  sy = 241 - spriteram[offs + 1];
  flipx = spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  color = spriteram[offs] & 0x1F;
  schar = spriteram[offs + 2] & 0x7F;
  drawgfx(bitmap,Machine->gfx[1],
    schar,
    color,
    flipx,flipy,
    sx,sy,
    &spritevisiblearea,TRANSPARENCY_COLOR,0);
 }
}

canonical_original_code:
void pingpong_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipx; int flipy; int tchar; int color;
   sx = offs % 32;
   sy = offs / 32;
   dirtybuffer[offs] = 0;
   flipx = colorram[offs] & 0x40;
   flipy = colorram[offs] & 0x80;
   color = colorram[offs] & 0x1F;
   tchar = (videoram[offs] + ((colorram[offs] & 0x20)<<3));
   drawgfx(tmpbitmap,Machine->gfx[0],
     tchar,
     color,
     flipx,flipy,
     8 * sx,8 * sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
 {
  int sx; int sy; int flipx; int flipy; int color; int schar;
  sx = spriteram[offs + 3];
  sy = 241 - spriteram[offs + 1];
  flipx = spriteram[offs] & 0x40;
  flipy = spriteram[offs] & 0x80;
  color = spriteram[offs] & 0x1F;
  schar = spriteram[offs + 2] & 0x7F;
  drawgfx(bitmap,Machine->gfx[1],
    schar,
    color,
    flipx,flipy,
    sx,sy,
    &spritevisiblearea,TRANSPARENCY_COLOR,0);
 }
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: offs int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: flipy int

variable_types: tchar int

variable_types: color int

variable_types: schar int


decompiled_code:
__int64 pingpong_interrupt()
{
__int64 result; // rax

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (*(_BYTE *)intenable & 8) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (*(_BYTE *)intenable & 4) == 0 )
return ignore_interrupt();
result = interrupt();
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax

if ( (unsigned int)cpu_getiloops() )
{
if ( (cpu_getiloops() & 1) == 0 || (*(_BYTE *)intenable & 8) == 0 )
return ignore_interrupt();
result = nmi_interrupt();
}
else
{
if ( (*(_BYTE *)intenable & 4) == 0 )
return ignore_interrupt();
result = interrupt();
}
return result;
}

original_code:
static int pingpong_interrupt(void)
{
 if (cpu_getiloops() == 0)
 {
  if (*intenable & 0x04) return interrupt();
 }
 else if (cpu_getiloops() % 2)
 {
  if (*intenable & 0x08) return nmi_interrupt();
 }
 return ignore_interrupt();
}

canonical_original_code:
static int pingpong_interrupt()
{
 if (cpu_getiloops() == 0)
 {
  if (*intenable & 0x04) return interrupt();
 }
 else if (cpu_getiloops() % 2)
 {
  if (*intenable & 0x08) return nmi_interrupt();
 }
 return ignore_interrupt();
}


original_code:
void bankp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0,bit1,bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = *(color_prom++) & 0x0f;
 color_prom += 128;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
}

canonical_original_code:
void bankp_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom)
{
 int i;
 for (i = 0;i < Machine->drv->total_colors;i++)
 {
  int bit0; int bit1; int bit2;
  bit0 = (*color_prom >> 0) & 0x01;
  bit1 = (*color_prom >> 1) & 0x01;
  bit2 = (*color_prom >> 2) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = (*color_prom >> 3) & 0x01;
  bit1 = (*color_prom >> 4) & 0x01;
  bit2 = (*color_prom >> 5) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  bit0 = 0;
  bit1 = (*color_prom >> 6) & 0x01;
  bit2 = (*color_prom >> 7) & 0x01;
  *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  color_prom++;
 }
 for (i = 0;i < (Machine->gfx[0]->total_colors * Machine->gfx[0]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[0].color_codes_start + i]) = *(color_prom++) & 0x0f;
 color_prom += 128;
 for (i = 0;i < (Machine->gfx[1]->total_colors * Machine->gfx[1]->color_granularity);i++)
  (colortable[Machine->drv->gfxdecodeinfo[1].color_codes_start + i]) = *(color_prom++) & 0x0f;
}

variable_types: i int


decompiled_code:
void __fastcall bankp_scroll_w(__int64 a1, int a2)
{
scroll_x = a2;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, int a2)
{
scroll_x = a2;
}

original_code:
void bankp_scroll_w(offs_t offset,data_t data)
{
 scroll_x = data;
}

canonical_original_code:
void bankp_scroll_w(unsigned int offset, unsigned int data)
{
 scroll_x = data;
}

variable_types:
data
unsigned int


decompiled_code:
__int64 bankp_vh_start()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer2 = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap2 )
{
free(dirtybuffer2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
size_t v2; // rbp
void *v3; // rdi

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
v2 = videoram_size;
v3 = malloc(videoram_size);
dirtybuffer2 = v3;
if ( v3 )
{
memset(v3, 1, v2);
tmpbitmap2 = bitmap_alloc(
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 664LL),
*(unsigned int *)(*(_QWORD *)(Machine + 824LL) + 668LL));
if ( !tmpbitmap2 )
{
free(dirtybuffer2);
generic_vh_stop();
v0 = 1;
}
}
else
{
generic_vh_stop();
v0 = 1;
}
}
return v0;
}

original_code:
int bankp_vh_start(void)
{
 if (generic_vh_start() != 0)
  return 1;
 if ((dirtybuffer2 = (unsigned char*)malloc(videoram_size)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer2);
  generic_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int bankp_vh_start()
{
 if (generic_vh_start() != 0)
  return 1;
 if ((dirtybuffer2 = (unsigned char *)malloc(videoram_size)) == 0)
 {
  generic_vh_stop();
  return 1;
 }
 memset(dirtybuffer2,1,videoram_size);
 if ((tmpbitmap2 = bitmap_alloc(Machine->drv->screen_width,Machine->drv->screen_height)) == 0)
 {
  free(dirtybuffer2);
  generic_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 bankp_vh_stop()
{
free(dirtybuffer2);
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

canonical_decompiled_code:
__int64 func5()
{
free(dirtybuffer2);
bitmap_free(tmpbitmap2);
return generic_vh_stop();
}

original_code:
void bankp_vh_stop(void)
{
 free(dirtybuffer2);
 bitmap_free(tmpbitmap2);
 generic_vh_stop();
}

canonical_original_code:
void bankp_vh_stop()
{
 free(dirtybuffer2);
 bitmap_free(tmpbitmap2);
 generic_vh_stop();
}


decompiled_code:
void *__fastcall bankp_out_w(__int64 a1, char a2)
{
void *result; // rax

priority = a2 & 3;
if ( (a2 & 0x10) != 0 )
interrupt_enable_w(0LL, 1LL);
else
interrupt_enable_w(0LL, 0LL);
result = (void *)(a2 & 0x20);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 0x20;
memset(dirtybuffer, 1, videoram_size);
result = memset(dirtybuffer2, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1, char a2)
{
void *result; // rax

priority = a2 & 3;
if ( (a2 & 0x10) != 0 )
interrupt_enable_w(0LL, 1LL);
else
interrupt_enable_w(0LL, 0LL);
result = (void *)(a2 & 0x20);
if ( (_DWORD)result != flipscreen )
{
flipscreen = a2 & 0x20;
memset(dirtybuffer, 1, videoram_size);
result = memset(dirtybuffer2, 1, videoram_size);
}
return result;
}

original_code:
void bankp_out_w(offs_t offset,data_t data)
{
 priority = data & 0x03;
 if (data & 0x10) interrupt_enable_w(0,1);
 else interrupt_enable_w(0,0);
 if ((data & 0x20) != flipscreen)
 {
  flipscreen = data & 0x20;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
}

canonical_original_code:
void bankp_out_w(unsigned int offset, unsigned int data)
{
 priority = data & 0x03;
 if (data & 0x10) interrupt_enable_w(0,1);
 else interrupt_enable_w(0,0);
 if ((data & 0x20) != flipscreen)
 {
  flipscreen = data & 0x20;
  memset(dirtybuffer,1,videoram_size);
  memset(dirtybuffer2,1,videoram_size);
 }
}


decompiled_code:
__int64 __fastcall bankp_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r8
__int64 v4; // r8
__int64 result; // rax
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v3 = *(_BYTE *)(colorram + v2) & 4;
if ( flipscreen )
v3 = (_DWORD)v3 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
*(_BYTE *)(colorram + v2) >> 3,
v3);
}
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
*((_BYTE *)dirtybuffer2 + v2) = 0;
v4 = *(_BYTE *)(bankp_colorram2 + v2) & 8;
if ( flipscreen )
v4 = (_DWORD)v4 == 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(bankp_videoram2 + v2) + ((unsigned __int8)(*(_BYTE *)(bankp_colorram2 + v2) & 7) << 8),
*(_BYTE *)(bankp_colorram2 + v2) >> 4,
v4);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v6[0] = -scroll_x;
if ( priority == 2 )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
else
{
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
int v1; // ebx
__int64 v2; // rbp
__int64 v3; // r8
__int64 v4; // r8
__int64 result; // rax
int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v1 = videoram_size - 1;
if ( (int)videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
if ( *(_BYTE *)(dirtybuffer + v2) )
{
*(_BYTE *)(dirtybuffer + v2) = 0;
v3 = *(_BYTE *)(colorram + v2) & 4;
if ( flipscreen )
v3 = (_DWORD)v3 == 0;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
*(unsigned __int8 *)(videoram + v2) + ((unsigned __int8)(*(_BYTE *)(colorram + v2) & 3) << 8),
*(_BYTE *)(colorram + v2) >> 3,
v3);
}
if ( *((_BYTE *)dirtybuffer2 + v2) )
{
*((_BYTE *)dirtybuffer2 + v2) = 0;
v4 = *(_BYTE *)(bankp_colorram2 + v2) & 8;
if ( flipscreen )
v4 = (_DWORD)v4 == 0;
drawgfx(
tmpbitmap2,
*(_QWORD *)(Machine + 520LL),
*(unsigned __int8 *)(bankp_videoram2 + v2) + ((unsigned __int8)(*(_BYTE *)(bankp_colorram2 + v2) & 7) << 8),
*(_BYTE *)(bankp_colorram2 + v2) >> 4,
v4);
}
--v2;
--v1;
}
while ( v1 >= 0 );
}
v6[0] = -scroll_x;
if ( priority == 2 )
{
copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
else
{
copybitmap(a1, tmpbitmap2, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
result = copyscrollbitmap(a1, tmpbitmap, 1LL, v6, 0LL, 0LL, Machine + 776LL, 6LL, 0LL);
}
return result;
}

original_code:
void bankp_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy,flipx;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x04;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * ((colorram[offs] & 3) >> 0),
     colorram[offs] >> 3,
     flipx,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx,sy,flipx;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = bankp_colorram2[offs] & 0x08;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     bankp_videoram2[offs] + 256 * (bankp_colorram2[offs] & 0x07),
     bankp_colorram2[offs] >> 4,
     flipx,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll;
  scroll = -scroll_x;
  if (priority == 2)
  {
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
  else
  {
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
}

canonical_original_code:
void bankp_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy; int flipx;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = colorram[offs] & 0x04;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap,Machine->gfx[0],
     videoram[offs] + 256 * ((colorram[offs] & 3) >> 0),
     colorram[offs] >> 3,
     flipx,flipscreen,
     8*sx,8*sy,
     0,TRANSPARENCY_NONE,0);
  }
  if (dirtybuffer2[offs])
  {
   int sx; int sy; int flipx;
   dirtybuffer2[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   flipx = bankp_colorram2[offs] & 0x08;
   if (flipscreen)
   {
    sx = 31 - sx;
    sy = 31 - sy;
    flipx = !flipx;
   }
   drawgfx(tmpbitmap2,Machine->gfx[1],
     bankp_videoram2[offs] + 256 * (bankp_colorram2[offs] & 0x07),
     bankp_colorram2[offs] >> 4,
     flipx,flipscreen,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 {
  int scroll;
  scroll = -scroll_x;
  if (priority == 2)
  {
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
  else
  {
   copybitmap(bitmap,tmpbitmap2,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
   copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_COLOR,0);
  }
 }
}

variable_types: scroll int


decompiled_code:
__int64 tigeroad_interrupt()
{
return 2LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 2LL;
}

original_code:
int tigeroad_interrupt(void)
{
 return 2;
}

canonical_original_code:
int tigeroad_interrupt()
{
 return 2;
}


decompiled_code:
__int64 __fastcall tigeroad_videoctrl_w(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( (a2 & 0xFF000000) == 0 )
{
flipscreen = BYTE1(a2) & 2;
bgcharbank = (BYTE1(a2) >> 2) & 1;
coin_counter_w(0LL, BYTE1(a2) & 0x40);
result = coin_counter_w(1LL, (a2 >> 8) & 0x80);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( (a2 & 0xFF000000) == 0 )
{
flipscreen = BYTE1(a2) & 2;
bgcharbank = (BYTE1(a2) >> 2) & 1;
coin_counter_w(0LL, BYTE1(a2) & 0x40);
result = coin_counter_w(1LL, (a2 >> 8) & 0x80);
}
return result;
}

original_code:
void tigeroad_videoctrl_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
 {
  data = (data >> 8) & 0xff;
  flipscreen = data & 0x02;
  bgcharbank = (data & 0x04) >> 2;
  coin_counter_w(0,data & 0x40);
  coin_counter_w(1,data & 0x80);
 }
}

canonical_original_code:
void tigeroad_videoctrl_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
 {
  data = (data >> 8) & 0xff;
  flipscreen = data & 0x02;
  bgcharbank = (data & 0x04) >> 2;
  coin_counter_w(0,data & 0x40);
  coin_counter_w(1,data & 0x80);
 }
}


decompiled_code:
__int64 init_tigeroad()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, tigeroad_soundcmd_w);
}

canonical_decompiled_code:
__int64 func5()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, tigeroad_soundcmd_w);
}

original_code:
void init_tigeroad(void)
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, tigeroad_soundcmd_w);
}

canonical_original_code:
void init_tigeroad()
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, tigeroad_soundcmd_w);
}


decompiled_code:
__int64 init_f1dream()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, f1dream_control_w);
}

canonical_decompiled_code:
__int64 func6()
{
return install_mem_write_handler(0LL, 16662530LL, 16662531LL, f1dream_control_w);
}

original_code:
void init_f1dream(void)
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, f1dream_control_w);
}

canonical_original_code:
void init_f1dream()
{
 install_mem_write_handler(0, 0xfe4002, 0xfe4003, f1dream_control_w);
}


decompiled_code:
__int64 __fastcall tigeroad_soundcmd_w(__int64 a1, int a2)
{
__int64 result; // rax

if ( (a2 & 0xFF000000) == 0 )
result = soundlatch_w(a1, BYTE1(a2));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 result; // rax

if ( (a2 & 0xFF000000) == 0 )
result = soundlatch_w(a1, BYTE1(a2));
return result;
}

original_code:
static void tigeroad_soundcmd_w(offs_t offset,data_t data)
{
 if ((data & 0xff000000) == 0)
  soundlatch_w(offset,(data >> 8) & 0xff);
}

canonical_original_code:
static void tigeroad_soundcmd_w(unsigned int offset, unsigned int data)
{
 if ((data & 0xff000000) == 0)
  soundlatch_w(offset,(data >> 8) & 0xff);
}


decompiled_code:
__int64 f1dream_protection_w()
{
__int64 result; // rax
_WORD *v1; // rdx
int v2; // eax
int v3; // ecx
int v4; // esi
unsigned __int16 v5; // cx
int v6; // esi
int v7; // edx

result = cpu_get_reg(0xFFFFFFFFLL);
switch ( (_DWORD)result )
{
case 0x244C:
v1 = (_WORD *)ram;
v2 = *(unsigned __int16 *)(ram + 16368);
*(_WORD *)(ram + 16358) = f1dream_2450_lookup[*(unsigned __int16 *)(ram + 16368)];
v1[8180] = f1dream_2450_lookup[v2 + 1];
v1[8181] = f1dream_2450_lookup[v2 + 2];
result = f1dream_2450_lookup[v2 + 3];
v1[8182] = result;
break;
case 0x613A:
result = *(unsigned __int16 *)(ram + 16374);
LOWORD(v3) = 255;
if ( (unsigned __int16)result <= 0xEu )
{
v4 = f1dream_613ea_lookup[(unsigned __int16)result] - *(unsigned __int16 *)(ram + 16372);
LOWORD(v3) = 255;
if ( v4 > 255 )
{
result = 16 * v4 + (unsigned __int8)result;
v3 = f1dream_613eb_lookup[result];
}
}
*(_WORD *)(ram + 16370) = v3;
break;
case 0x17B70:
result = ram;
v5 = *(_WORD *)(ram + 16368);
if ( v5 > 3u )
goto LABEL_21;
v6 = 96;
if ( v5 != 3 )
{
v6 = 64;
if ( v5 != 2 )
v6 = 32 * (v5 == 1);
}
v7 = v6 + *(unsigned __int16 *)(ram + 16366);
if ( v7 > 127 )
{
LABEL_21:
*(_WORD *)(ram + 16358) = 255;
*(_WORD *)(result + 16360) = 255;
*(_WORD *)(result + 16362) = 255;
*(_WORD *)(result + 16364) = 255;
}
else
{
*(_WORD *)(ram + 16358) = f1dream_17b74_lookup[v7];
*(_WORD *)(result + 16360) = f1dream_17b74_lookup[v7 + 1];
*(_WORD *)(result + 16362) = f1dream_17b74_lookup[v7 + 2];
*(_WORD *)(result + 16364) = f1dream_17b74_lookup[v7 + 3];
}
break;
case 0x27F8:
case 0x511A:
case 0x5142:
case 0x516A:
result = soundlatch_w(2LL, *(unsigned __int16 *)(ram + 16380));
break;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax
_WORD *v1; // rdx
int v2; // eax
int v3; // ecx
int v4; // esi
unsigned __int16 v5; // cx
int v6; // esi
int v7; // edx

result = cpu_get_reg(0xFFFFFFFFLL);
switch ( (_DWORD)result )
{
case 0x244C:
v1 = (_WORD *)ram;
v2 = *(unsigned __int16 *)(ram + 16368);
*(_WORD *)(ram + 16358) = f1dream_2450_lookup[*(unsigned __int16 *)(ram + 16368)];
v1[8180] = f1dream_2450_lookup[v2 + 1];
v1[8181] = f1dream_2450_lookup[v2 + 2];
result = f1dream_2450_lookup[v2 + 3];
v1[8182] = result;
break;
case 0x613A:
result = *(unsigned __int16 *)(ram + 16374);
LOWORD(v3) = 255;
if ( (unsigned __int16)result <= 0xEu )
{
v4 = f1dream_613ea_lookup[(unsigned __int16)result] - *(unsigned __int16 *)(ram + 16372);
LOWORD(v3) = 255;
if ( v4 > 255 )
{
result = 16 * v4 + (unsigned __int8)result;
v3 = f1dream_613eb_lookup[result];
}
}
*(_WORD *)(ram + 16370) = v3;
break;
case 0x17B70:
result = ram;
v5 = *(_WORD *)(ram + 16368);
if ( v5 > 3u )
goto LABEL_21;
v6 = 96;
if ( v5 != 3 )
{
v6 = 64;
if ( v5 != 2 )
v6 = 32 * (v5 == 1);
}
v7 = v6 + *(unsigned __int16 *)(ram + 16366);
if ( v7 > 127 )
{
LABEL_21:
*(_WORD *)(ram + 16358) = 255;
*(_WORD *)(result + 16360) = 255;
*(_WORD *)(result + 16362) = 255;
*(_WORD *)(result + 16364) = 255;
}
else
{
*(_WORD *)(ram + 16358) = f1dream_17b74_lookup[v7];
*(_WORD *)(result + 16360) = f1dream_17b74_lookup[v7 + 1];
*(_WORD *)(result + 16362) = f1dream_17b74_lookup[v7 + 2];
*(_WORD *)(result + 16364) = f1dream_17b74_lookup[v7 + 3];
}
break;
case 0x27F8:
case 0x511A:
case 0x5142:
case 0x516A:
result = soundlatch_w(2LL, *(unsigned __int16 *)(ram + 16380));
break;
}
return result;
}

canonical_original_code:
static void f1dream_protection_w()
{
 int indx;
 int value = 255;
 int prevpc = cpu_get_reg(-1);
 if (prevpc == 0x244c)
 {
  indx = (*(unsigned short *)(&ram[0x3ff0]));
  (*(unsigned short *)(&ram[0x3fe6]) = (f1dream_2450_lookup[indx]));
  (*(unsigned short *)(&ram[0x3fe8]) = (f1dream_2450_lookup[++indx]));
  (*(unsigned short *)(&ram[0x3fea]) = (f1dream_2450_lookup[++indx]));
  (*(unsigned short *)(&ram[0x3fec]) = (f1dream_2450_lookup[++indx]));
 }
 else if (prevpc == 0x613a)
 {
  if (((*(unsigned short *)(&ram[0x3ff6]))) < 15)
  {
   indx = f1dream_613ea_lookup[(*(unsigned short *)(&ram[0x3ff6]))] - ((*(unsigned short *)(&ram[0x3ff4])));
   if (indx > 255)
   {
    indx <<= 4;
    indx += (*(unsigned short *)(&ram[0x3ff6])) & 0x00ff;
    value = f1dream_613eb_lookup[indx];
   }
  }
  (*(unsigned short *)(&ram[0x3ff2]) = (value));
 }
 else if (prevpc == 0x17b70)
 {
  if (((*(unsigned short *)(&ram[0x3ff0]))) >= 0x04) indx = 128;
  else if (((*(unsigned short *)(&ram[0x3ff0]))) > 0x02) indx = 96;
  else if (((*(unsigned short *)(&ram[0x3ff0]))) == 0x02) indx = 64;
  else if (((*(unsigned short *)(&ram[0x3ff0]))) == 0x01) indx = 32;
  else indx = 0;
  indx += (*(unsigned short *)(&ram[0x3fee]));
  if (indx < 128)
  {
   (*(unsigned short *)(&ram[0x3fe6]) = (f1dream_17b74_lookup[indx]));
   (*(unsigned short *)(&ram[0x3fe8]) = (f1dream_17b74_lookup[++indx]));
   (*(unsigned short *)(&ram[0x3fea]) = (f1dream_17b74_lookup[++indx]));
   (*(unsigned short *)(&ram[0x3fec]) = (f1dream_17b74_lookup[++indx]));
  }
  else
  {
   (*(unsigned short *)(&ram[0x3fe6]) = (0x00ff));
   (*(unsigned short *)(&ram[0x3fe8]) = (0x00ff));
   (*(unsigned short *)(&ram[0x3fea]) = (0x00ff));
   (*(unsigned short *)(&ram[0x3fec]) = (0x00ff));
  }
 }
 else if ((prevpc == 0x27f8) || (prevpc == 0x511a) || (prevpc == 0x5142) || (prevpc == 0x516a))
 {
  soundlatch_w(2,(*(unsigned short *)(&ram[0x3ffc])));
 }
}

variable_types: indx int

variable_types: value int

variable_types: prevpc int


decompiled_code:
__int64 f1dream_control_w()
{
return f1dream_protection_w();
}

canonical_decompiled_code:
__int64 func9()
{
return func8();
}

original_code:
static void f1dream_control_w(offs_t offset,data_t data)
{
 f1dream_protection_w();
}

canonical_original_code:
static void f1dream_control_w(unsigned int offset, unsigned int data)
{
 f1dream_protection_w();
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 __fastcall msm5205_w(__int64 a1, unsigned int a2)
{
MSM5205_reset_w(a1, (a2 >> 7) & 1);
MSM5205_data_w((unsigned int)a1, a2);
MSM5205_vclk_w((unsigned int)a1, 1LL);
return MSM5205_vclk_w((unsigned int)a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2)
{
MSM5205_reset_w(a1, (a2 >> 7) & 1);
MSM5205_data_w((unsigned int)a1, a2);
MSM5205_vclk_w((unsigned int)a1, 1LL);
return MSM5205_vclk_w((unsigned int)a1, 0LL);
}

original_code:
static void msm5205_w(offs_t offset,data_t data)
{
 MSM5205_reset_w(offset,(data>>7)&1);
 MSM5205_data_w(offset,data);
 MSM5205_vclk_w(offset,1);
 MSM5205_vclk_w(offset,0);
}

canonical_original_code:
static void msm5205_w(unsigned int offset, unsigned int data)
{
 MSM5205_reset_w(offset,(data>>7)&1);
 MSM5205_data_w(offset,data);
 MSM5205_vclk_w(offset,1);
 MSM5205_vclk_w(offset,0);
}


decompiled_code:
__int64 __fastcall render_sprites(__int64 a1)
{
unsigned __int64 v1; // r12
__int64 result; // rax
_WORD *v3; // rbx

v1 = spriteram;
result = spriteram_size;
v3 = (_WORD *)(spriteram + spriteram_size - 8LL);
if ( spriteram <= (unsigned __int64)v3 )
{
do
{
if ( *v3 != 4095 )
result = drawgfx(a1, *(_QWORD *)(Machine + 528LL), (unsigned __int16)*v3);
v3 -= 4;
}
while ( v1 <= (unsigned __int64)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // r12
__int64 result; // rax
_WORD *v3; // rbx

v1 = spriteram;
result = spriteram_size;
v3 = (_WORD *)(spriteram + spriteram_size - 8LL);
if ( spriteram <= (unsigned __int64)v3 )
{
do
{
if ( *v3 != 4095 )
result = drawgfx(a1, *(_QWORD *)(Machine + 528LL), (unsigned __int16)*v3);
v3 -= 4;
}
while ( v1 <= (unsigned __int64)v3 );
}
return result;
}

original_code:
static void render_sprites( struct osd_bitmap *bitmap )
{
 unsigned char *source = &spriteram[spriteram_size] - 8;
 unsigned char *finish = spriteram;
 while( source>=finish )
 {
  int tile_number = (*(UINT16 *)(source));
  if( tile_number!=0xFFF ){
   int attributes = (*(UINT16 *)(source+2));
   int sy = (*(UINT16 *)(source+4)) & 0x1ff;
   int sx = (*(UINT16 *)(source+6)) & 0x1ff;
   int flipx = attributes&2;
   int flipy = attributes&1;
   int color = (attributes>>2)&0xf;
   if( sx>0x100 ) sx -= 0x200;
   if( sy>0x100 ) sy -= 0x200;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
    tile_number,
    color,
    flipx,flipy,
    sx,240-sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,15);
  }
  source-=8;
 }
}

canonical_original_code:
static void render_sprites(struct osd_bitmap *bitmap)
{
 unsigned char *source = &spriteram[spriteram_size] - 8;
 unsigned char *finish = spriteram;
 while( source>=finish )
 {
  int tile_number = (*(UINT16 *)(source));
  if( tile_number!=0xFFF ){
   int attributes = (*(UINT16 *)(source+2));
   int sy = (*(UINT16 *)(source+4)) & 0x1ff;
   int sx = (*(UINT16 *)(source+6)) & 0x1ff;
   int flipx = attributes&2;
   int flipy = attributes&1;
   int color = (attributes>>2)&0xf;
   if( sx>0x100 ) sx -= 0x200;
   if( sy>0x100 ) sy -= 0x200;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx(bitmap,Machine->gfx[2],
    tile_number,
    color,
    flipx,flipy,
    sx,240-sy,
    &Machine->visible_area,
    TRANSPARENCY_PEN,15);
  }
  source-=8;
 }
}

variable_types:
source
unsigned char *

variable_types:
finish
unsigned char *

variable_types: attributes int


original_code:
static void render_background( struct osd_bitmap *bitmap, int priority )
{
 int scrollx = (*(UINT16 *)(&tigeroad_scrollram[0])) & 0xfff;
 int scrolly = (*(UINT16 *)(&tigeroad_scrollram[2])) & 0xfff;
 unsigned char *p = memory_region(REGION_GFX4);
 int alignx = scrollx%32;
 int aligny = scrolly%32;
 int row = scrolly/32;
 int sy = 224+aligny;
 int transp0,transp1;
 if( priority ){
  transp0 = 0xFFFF;
  transp1 = 0x01FF;
 }
 else {
  transp0 = 0;
  transp1 = 0xFE00;
 }
 while( sy>-32 ){
  int col = scrollx/32;
  int sx = -alignx;
  while( sx<256 ){
   int offset = 2*(col%8) + 16*(row%8) + 128*(col/8) + 2048*(row/8);
   int code = p[offset];
   int attr = p[offset+1];
   int flipx = attr & 0x20;
   int flipy = 0;
   int color = attr & 0x0f;
   if (flipscreen)
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      !flipx,!flipy,
      224-sx,224-sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   else
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      flipx,flipy,
      sx,sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   sx+=32;
   col++;
   if( col>=128 ) col-=128;
  }
  sy-=32;
  row++;
  if( row>=128 ) row-=128;
 }
}

canonical_original_code:
static void render_background(struct osd_bitmap *bitmap, int priority)
{
 int scrollx = (*(UINT16 *)(&tigeroad_scrollram[0])) & 0xfff;
 int scrolly = (*(UINT16 *)(&tigeroad_scrollram[2])) & 0xfff;
 unsigned char *p = memory_region(REGION_GFX4);
 int alignx = scrollx%32;
 int aligny = scrolly%32;
 int row = scrolly/32;
 int sy = 224+aligny;
 int transp0; int transp1;
 if( priority ){
  transp0 = 0xFFFF;
  transp1 = 0x01FF;
 }
 else {
  transp0 = 0;
  transp1 = 0xFE00;
 }
 while( sy>-32 ){
  int col = scrollx/32;
  int sx = -alignx;
  while( sx<256 ){
   int offset = 2*(col%8) + 16*(row%8) + 128*(col/8) + 2048*(row/8);
   int code = p[offset];
   int attr = p[offset+1];
   int flipx = attr & 0x20;
   int flipy = 0;
   int color = attr & 0x0f;
   if (flipscreen)
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      !flipx,!flipy,
      224-sx,224-sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   else
    drawgfx(bitmap,Machine->gfx[1],
      code + ((attr & 0xc0) << 2) + (bgcharbank << 10),
      color,
      flipx,flipy,
      sx,sy,
      &Machine->visible_area,
      TRANSPARENCY_PENS,(attr & 0x10) ? transp1 : transp0);
   sx+=32;
   col++;
   if( col>=128 ) col-=128;
  }
  sy-=32;
  row++;
  if( row>=128 ) row-=128;
 }
}

variable_types: struct osd_bitmap { int width; int depth; void *_private; unsigned char **line; } *

variable_types: priority int

variable_types: scrollx int

variable_types: scrolly int

variable_types:
p
unsigned char *

variable_types: alignx int

variable_types: aligny int

variable_types: row int

variable_types: col int

variable_types: sx int

variable_types: offset int

variable_types: code int

variable_types: attr int


decompiled_code:
__int64 __fastcall irqhandler(int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1 != 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return cpu_set_irq_line(1LL, 0LL, a1 != 0);
}

original_code:
static void irqhandler(int irq)
{
 cpu_set_irq_line(1,0,irq ? 1 : 0);
}

variable_types: irq int


decompiled_code:
void sharkatt_vtcsel_w()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void sharkatt_vtcsel_w(offs_t offset,data_t data)
{
}

canonical_original_code:
void sharkatt_vtcsel_w(unsigned int offset, unsigned int data)
{
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
void __fastcall sharkatt_color_plane_w(__int64 a1, char a2)
{
color_plane = a2 & 0x3F;
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, char a2)
{
color_plane = a2 & 0x3F;
}

original_code:
void sharkatt_color_plane_w(offs_t offset,data_t data)
{
 color_plane = (data & 0x3F);
}

canonical_original_code:
void sharkatt_color_plane_w(unsigned int offset, unsigned int data)
{
 color_plane = (data & 0x3F);
}


decompiled_code:
void __fastcall sharkatt_8255_w(char a1, int a2)
{
if ( (a1 & 3) == 0 )
PA_8255 = a2;
}

canonical_decompiled_code:
void __fastcall func2(char a1, int a2)
{
if ( (a1 & 3) == 0 )
PA_8255 = a2;
}

original_code:
static void sharkatt_8255_w(offs_t offset,data_t data)
{
 switch (offset & 0x03)
 {
  case 0: PA_8255 = data; break;
  case 1: PB_8255 = data; break;
  case 2: PC_8255 = data; break;
  case 3: break;
 }
}

canonical_original_code:
static void sharkatt_8255_w(unsigned int offset, unsigned int data)
{
 switch (offset & 0x03)
 {
  case 0: PA_8255 = data; break;
  case 1: PB_8255 = data; break;
  case 2: PC_8255 = data; break;
  case 3: break;
 }
}


decompiled_code:
void fake_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

original_code:
static void fake_w(offs_t offset,data_t data)
{
}

canonical_original_code:
static void fake_w(unsigned int offset, unsigned int data)
{
}


original_code:
void sharkatt_color_map_w(offs_t offset,data_t data)
{
    int vals[4] = {0x00,0x55,0xAA,0xFF};
    int r,g,b;
    r = vals[(data & 0x03) >> 0];
    g = vals[(data & 0x0C) >> 2];
    b = vals[(data & 0x30) >> 4];
 palette_change_color (offset,r,g,b);
}

canonical_original_code:
void sharkatt_color_map_w(unsigned int offset, unsigned int data)
{
    int vals[4] = {0x00,0x55,0xAA,0xFF};
    int r; int g; int b;
    r = vals[(data & 0x03) >> 0];
    g = vals[(data & 0x0C) >> 2];
    b = vals[(data & 0x30) >> 4];
 palette_change_color (offset,r,g,b);
}

variable_types:
vals
int [4]

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall sharkatt_videoram_w(unsigned int a1, char a2)
{
char v2; // bp
unsigned int v3; // er14
unsigned int v4; // ebx
unsigned int v5; // er12
__int64 result; // rax
unsigned __int16 *v7; // rdx

v2 = a2;
*(_BYTE *)(videoram + a1) = a2;
v3 = a1 >> 5;
v4 = 8 * (a1 & 0x1F);
v5 = v4 + 8;
do
{
v7 = *(unsigned __int16 **)(Machine + 792LL);
if ( v2 >= 0 )
result = plot_pixel2(tmpbitmap, *(_QWORD *)(Machine + 768LL), v3, v4, *v7);
else
result = plot_pixel2(tmpbitmap, *(_QWORD *)(Machine + 768LL), v3, v4, v7[color_plane & 0xF]);
++v4;
v2 *= 2;
}
while ( v5 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, char a2)
{
char v2; // bp
unsigned int v3; // er14
unsigned int v4; // ebx
unsigned int v5; // er12
__int64 result; // rax
unsigned __int16 *v7; // rdx

v2 = a2;
*(_BYTE *)(videoram + a1) = a2;
v3 = a1 >> 5;
v4 = 8 * (a1 & 0x1F);
v5 = v4 + 8;
do
{
v7 = *(unsigned __int16 **)(Machine + 792LL);
if ( v2 >= 0 )
result = plot_pixel2(tmpbitmap, *(_QWORD *)(Machine + 768LL), v3, v4, *v7);
else
result = plot_pixel2(tmpbitmap, *(_QWORD *)(Machine + 768LL), v3, v4, v7[color_plane & 0xF]);
++v4;
v2 *= 2;
}
while ( v5 != v4 );
return result;
}

original_code:
void sharkatt_videoram_w(offs_t offset,data_t data)
{
 int i,x,y;
 videoram[offset] = data;
 x = offset / 32;
 y = 8 * (offset % 32);
 for (i = 0;i < 8;i++)
 {
  int col;
  col = Machine->pens[color_plane & 0x0F];
  if (data & 0x80)
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, col);
  }
  else
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, Machine->pens[0]);
  }
  y++;
  data <<= 1;
 }
}

canonical_original_code:
void sharkatt_videoram_w(unsigned int offset, unsigned int data)
{
 int i; int x; int y;
 videoram[offset] = data;
 x = offset / 32;
 y = 8 * (offset % 32);
 for (i = 0;i < 8;i++)
 {
  int col;
  col = Machine->pens[color_plane & 0x0F];
  if (data & 0x80)
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, col);
  }
  else
  {
   plot_pixel2(tmpbitmap, Machine->scrbitmap, x, y, Machine->pens[0]);
  }
  y++;
  data <<= 1;
 }
}

variable_types: i int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 sharkatt_interrupt()
{
__int64 result; // rax

if ( (input_port_3_r(0LL) & 0x10) != 0 )
result = interrupt();
else
result = nmi_interrupt();
return result;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 result; // rax

if ( (input_port_3_r(0LL) & 0x10) != 0 )
result = interrupt();
else
result = nmi_interrupt();
return result;
}

original_code:
static int sharkatt_interrupt(void)
{
 if ((input_port_3_r(0) & 0x10) == 0)
  return nmi_interrupt();
 return interrupt();
}

canonical_original_code:
static int sharkatt_interrupt()
{
 if ((input_port_3_r(0) & 0x10) == 0)
  return nmi_interrupt();
 return interrupt();
}


decompiled_code:
__int64 __fastcall sharkatt_8255_r(__int64 a1)
{
__int64 result; // rax

result = 0LL;
if ( (a1 & 3) == 1 )
{
if ( (PA_8255 & 1) != 0 )
{
result = input_port_0_r();
}
else if ( (PA_8255 & 2) != 0 )
{
result = input_port_1_r();
}
else if ( (PA_8255 & 4) != 0 )
{
result = input_port_2_r();
}
else
{
result = 0LL;
if ( (PA_8255 & 8) != 0 )
result = input_port_3_r(a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax

result = 0LL;
if ( (a1 & 3) == 1 )
{
if ( (PA_8255 & 1) != 0 )
{
result = input_port_0_r();
}
else if ( (PA_8255 & 2) != 0 )
{
result = input_port_1_r();
}
else if ( (PA_8255 & 4) != 0 )
{
result = input_port_2_r();
}
else
{
result = 0LL;
if ( (PA_8255 & 8) != 0 )
result = input_port_3_r(a1);
}
}
return result;
}

original_code:
static data_t sharkatt_8255_r(offs_t offset)
{
 switch (offset & 0x03)
 {
  case 1:
   if (PA_8255 & 0x01)
    return input_port_0_r(offset);
   if (PA_8255 & 0x02)
    return input_port_1_r(offset);
   if (PA_8255 & 0x04)
    return input_port_2_r(offset);
   if (PA_8255 & 0x08)
    return input_port_3_r(offset);
   break;
  default:
   break;
 }
 return 0;
}

canonical_original_code:
static unsigned int sharkatt_8255_r(unsigned int offset)
{
 switch (offset & 0x03)
 {
  case 1:
   if (PA_8255 & 0x01)
    return input_port_0_r(offset);
   if (PA_8255 & 0x02)
    return input_port_1_r(offset);
   if (PA_8255 & 0x04)
    return input_port_2_r(offset);
   if (PA_8255 & 0x08)
    return input_port_3_r(offset);
   break;
  default:
   break;
 }
 return 0;
}