decompiled_code:
__int64 __fastcall TMS34061_register_r(unsigned int a1)
{
int v1; // ecx
__int64 result; // rax
unsigned int v3; // ecx

v1 = *((_DWORD *)&regs + (a1 >> 2));
result = (unsigned __int8)v1;
v3 = v1 >> 8;
if ( (a1 & 2) != 0 )
result = v3;
if ( a1 >> 2 == 13 )
dword_D74 = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
int v1; // ecx
__int64 result; // rax
unsigned int v3; // ecx

v1 = *((_DWORD *)&regs + (a1 >> 2));
result = (unsigned __int8)v1;
v3 = v1 >> 8;
if ( (a1 & 2) != 0 )
result = v3;
if ( a1 >> 2 == 13 )
dword_D74 = 0;
return result;
}

original_code:
static inline data_t TMS34061_register_r(offs_t offset)
{
 int ret;
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  ret = (regs[reg] >> 8);
 }
 else
 {
  ret = (regs[reg] & 0xff);
 }
 switch (reg)
 {
 case 13:
  regs[reg] = 0;
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
 return ret;
}

canonical_original_code:
static inline unsigned int TMS34061_register_r(unsigned int offset)
{
 int ret;
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  ret = (regs[reg] >> 8);
 }
 else
 {
  ret = (regs[reg] & 0xff);
 }
 switch (reg)
 {
 case 13:
  regs[reg] = 0;
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
 return ret;
}

variable_types: ret int

variable_types: status int

variable_types: reg int


decompiled_code:
void __fastcall adjust_xyaddress(char a1, int a2, __int16 a3)
{
int v3; // ecx
int v4; // edi

v3 = a1 & 6;
if ( v3 == 4 )
{
a2 = (unsigned __int8)(a2 - 1);
goto LABEL_5;
}
if ( v3 != 6 )
{
if ( v3 == 2 )
a2 = (unsigned __int8)(a2 + 1);
LABEL_5:
v4 = a1 & 0x18;
if ( v4 != 16 )
goto LABEL_6;
LABEL_11:
--a3;
goto LABEL_8;
}
v4 = a1 & 0x18;
a2 = 0;
if ( v4 == 16 )
goto LABEL_11;
LABEL_6:
if ( v4 == 24 )
{
LABEL_9:
dword_D7C = a2;
return;
}
if ( v4 != 8 )
{
LABEL_8:
a2 |= (unsigned __int16)(a3 << 8);
goto LABEL_9;
}
dword_D7C = (unsigned __int16)((a3 + 1) << 8) | a2;
}

canonical_decompiled_code:
void __fastcall func7(char a1, int a2, __int16 a3)
{
int v3; // ecx
int v4; // edi

v3 = a1 & 6;
if ( v3 == 4 )
{
a2 = (unsigned __int8)(a2 - 1);
goto LABEL_5;
}
if ( v3 != 6 )
{
if ( v3 == 2 )
a2 = (unsigned __int8)(a2 + 1);
LABEL_5:
v4 = a1 & 0x18;
if ( v4 != 16 )
goto LABEL_6;
LABEL_11:
--a3;
goto LABEL_8;
}
v4 = a1 & 0x18;
a2 = 0;
if ( v4 == 16 )
goto LABEL_11;
LABEL_6:
if ( v4 == 24 )
{
LABEL_9:
dword_D7C = a2;
return;
}
if ( v4 != 8 )
{
LABEL_8:
a2 |= (unsigned __int16)(a3 << 8);
goto LABEL_9;
}
dword_D7C = (unsigned __int16)((a3 + 1) << 8) | a2;
}

original_code:
static inline void adjust_xyaddress(int offset, int x, int y)
{
 switch (offset & 0x06)
 {
 case 0x00: break;
 case 0x02: x++; break;
 case 0x04: x--; break;
 case 0x06: x=0; break;
 }
 switch (offset & 0x18)
 {
 case 0x00: break;
 case 0x08: y++; break;
 case 0x10: y--; break;
 case 0x18: y=0; break;
 }
 regs[15] = ((y & 0xff) << 8) | (x & 0xff);
}

variable_types: offset int

variable_types: x int

variable_types: y int

return_type: void


decompiled_code:
void __fastcall TMS34061_xypixel_w(int a1, unsigned int a2)
{
int v2; // er13
int v3; // er12

v2 = (unsigned __int8)dword_D7C;
v3 = dword_D7C >> 8;
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(
(unsigned __int8)dword_D7C,
(unsigned int)(dword_D7C >> 8),
a2);
if ( a1 )
adjust_xyaddress(a1, v2, v3);
}

canonical_decompiled_code:
void __fastcall func8(int a1, unsigned int a2)
{
int v2; // er13
int v3; // er12

v2 = (unsigned __int8)dword_D7C;
v3 = dword_D7C >> 8;
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(
(unsigned __int8)dword_D7C,
(unsigned int)(dword_D7C >> 8),
a2);
if ( a1 )
func7(a1, v2, v3);
}

original_code:
static inline void TMS34061_xypixel_w(offs_t offset,data_t data)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    intf->setpixel(x, y, data);
 if (offset) adjust_xyaddress(offset, x, y);
}

canonical_original_code:
static inline void TMS34061_xypixel_w(unsigned int offset, unsigned int data)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    intf->setpixel(x, y, data);
 if (offset) adjust_xyaddress(offset, x, y);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall TMS34061_xypixel_r(int a1)
{
int v1; // er13
int v2; // er12
__int64 result; // rax
unsigned int v4; // [rsp+Ch] [rbp-1Ch]

v1 = (unsigned __int8)dword_D7C;
v2 = dword_D7C >> 8;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(
(unsigned __int8)dword_D7C,
(unsigned int)(dword_D7C >> 8));
if ( a1 )
{
v4 = result;
adjust_xyaddress(a1, v1, v2);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1)
{
int v1; // er13
int v2; // er12
__int64 result; // rax
unsigned int v4; // [rsp+Ch] [rbp-1Ch]

v1 = (unsigned __int8)dword_D7C;
v2 = dword_D7C >> 8;
result = (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(
(unsigned __int8)dword_D7C,
(unsigned int)(dword_D7C >> 8));
if ( a1 )
{
v4 = result;
func7(a1, v1, v2);
result = v4;
}
return result;
}

original_code:
static inline data_t TMS34061_xypixel_r(offs_t offset)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    int ret = intf->getpixel(x, y);
 if (offset) adjust_xyaddress(offset, x, y);
 return ret;
}

canonical_original_code:
static inline unsigned int TMS34061_xypixel_r(unsigned int offset)
{
 int x = regs[15] & 0xff;
 int y = regs[15] >> 8;
    int ret = intf->getpixel(x, y);
 if (offset) adjust_xyaddress(offset, x, y);
 return ret;
}

return_type: unsigned int


decompiled_code:
__int64 __fastcall TMS34061_r(unsigned int a1)
{
unsigned int v1; // er12
unsigned int v2; // er13
int v3; // eax

v1 = (*(__int64 (**)(void))(intf + 16))();
v2 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
v3 = (*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( v3 == 2 )
return TMS34061_register_r(v1);
if ( v3 > 2 )
{
if ( v3 == 3 )
return (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(v1, v2);
return 0LL;
}
if ( !v3 )
return TMS34061_register_r(v1);
if ( v3 == 1 )
return TMS34061_xypixel_r(v1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1)
{
unsigned int v1; // er12
unsigned int v2; // er13
int v3; // eax

v1 = (*(__int64 (**)(void))(intf + 16))();
v2 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
v3 = (*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( v3 == 2 )
return func6(v1);
if ( v3 > 2 )
{
if ( v3 == 3 )
return (*(__int64 (__fastcall **)(_QWORD, _QWORD))(intf + 24))(v1, v2);
return 0LL;
}
if ( !v3 )
return func6(v1);
if ( v3 == 1 )
return func9(v1);
return 0LL;
}

original_code:
data_t TMS34061_r(offs_t offset)
{
 int ret = 0;
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  ret = TMS34061_register_r(col);
  break;
 case 1:
  ret = TMS34061_xypixel_r(col);
  break;
 case 3:
  ret = intf->getpixel(col, row);
  break;
 default:
  break;
 }
 return ret;
}

canonical_original_code:
unsigned int TMS34061_r(unsigned int offset)
{
 int ret = 0;
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  ret = TMS34061_register_r(col);
  break;
 case 1:
  ret = TMS34061_xypixel_r(col);
  break;
 case 3:
  ret = intf->getpixel(col, row);
  break;
 default:
  break;
 }
 return ret;
}

variable_types: col int

variable_types: row int

variable_types: func int


decompiled_code:
__int64 capbowl_init_machine()
{
return ticket_dispenser_init(100LL, 1LL, 0LL);
}

canonical_decompiled_code:
__int64 func11()
{
return ticket_dispenser_init(100LL, 1LL, 0LL);
}

original_code:
void capbowl_init_machine(void)
{
 ticket_dispenser_init(100, 1, 0);
}

canonical_original_code:
void capbowl_init_machine()
{
 ticket_dispenser_init(100, 1, 0);
}


decompiled_code:
__int64 __fastcall bowlrama_turbo_r(int a1)
{
__int64 v1; // rax
__int16 v2; // dx
__int64 result; // rax
unsigned int v4; // ecx
bool v5; // zf

v1 = memory_region(137LL);
v2 = currentaddress;
result = *(unsigned __int8 *)(v1 + currentaddress);
if ( a1 )
{
if ( a1 == 4 )
{
GRLowByte = (unsigned __int8)(currentaddress + 1);
currentaddress = (currentaddress + 1) & 0x3FFFF;
GRMidByte = (unsigned __int8)((unsigned __int16)(v2 + 1) >> 8);
GRHighByte = currentaddress >> 16;
}
else
{
result = 0LL;
}
}
else
{
v4 = ((result & 0xF0) == 0 ? 0xF0 : 0) | 0xF;
v5 = (result & 0xF) == 0;
result = (result & 0xF0) == 0 ? 0xF0 : 0;
if ( v5 )
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1)
{
__int64 v1; // rax
__int16 v2; // dx
__int64 result; // rax
unsigned int v4; // ecx
bool v5; // zf

v1 = memory_region(137LL);
v2 = currentaddress;
result = *(unsigned __int8 *)(v1 + currentaddress);
if ( a1 )
{
if ( a1 == 4 )
{
GRLowByte = (unsigned __int8)(currentaddress + 1);
currentaddress = (currentaddress + 1) & 0x3FFFF;
GRMidByte = (unsigned __int8)((unsigned __int16)(v2 + 1) >> 8);
GRHighByte = currentaddress >> 16;
}
else
{
result = 0LL;
}
}
else
{
v4 = ((result & 0xF0) == 0 ? 0xF0 : 0) | 0xF;
v5 = (result & 0xF) == 0;
result = (result & 0xF0) == 0 ? 0xF0 : 0;
if ( v5 )
result = v4;
}
return result;
}

original_code:
data_t bowlrama_turbo_r(offs_t offset)
{
 int ret = 0;
 int data = memory_region(REGION_GFX1)[currentaddress];
 switch (offset)
 {
 case 0:
  if(!(data & 0xf0))
  {
   ret = 0xf0;
  }
  if(!(data & 0x0f))
  {
   ret |= 0x0f;
  }
  break;
 case 4:
  ret = data;
  currentaddress = (currentaddress + 1) & 0x3ffff;
  GRHighByte = (currentaddress >> 16);
  GRMidByte = (currentaddress >> 8) & 0xff;
  GRLowByte = (currentaddress & 0xff);
  break;
 default:
  break;
 }
 return ret;
}

canonical_original_code:
unsigned int bowlrama_turbo_r(unsigned int offset)
{
 int ret = 0;
 int data = memory_region(REGION_GFX1)[currentaddress];
 switch (offset)
 {
 case 0:
  if(!(data & 0xf0))
  {
   ret = 0xf0;
  }
  if(!(data & 0x0f))
  {
   ret |= 0x0f;
  }
  break;
 case 4:
  ret = data;
  currentaddress = (currentaddress + 1) & 0x3ffff;
  GRHighByte = (currentaddress >> 16);
  GRMidByte = (currentaddress >> 8) & 0xff;
  GRLowByte = (currentaddress & 0xff);
  break;
 default:
  break;
 }
 return ret;
}

variable_types: data int


decompiled_code:
void *__fastcall capbowl_rom_select_w(__int64 a1, int a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + (((_WORD)a2 << 14) & 0x4000 | (a2 << 13) & 0x18000u) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func13(__int64 a1, int a2)
{
void *result; // rax
unsigned int v3; // eax

cpu_bankbase[1] = memory_region(129LL) + (((_WORD)a2 << 14) & 0x4000 | (a2 << 13) & 0x18000u) + 0x10000;
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v3 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v3);
}
return result;
}

original_code:
void capbowl_rom_select_w(offs_t offset,data_t data)
{
 int bankaddress = 0x10000 + ((data & 0x0c) << 13) + ((data & 0x01) << 14);
 unsigned char *RAM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (UINT8 *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

canonical_original_code:
void capbowl_rom_select_w(unsigned int offset, unsigned int data)
{
 int bankaddress = 0x10000 + ((data & 0x0c) << 13) + ((data & 0x01) << 14);
 unsigned char *RAM = memory_region(REGION_CPU1);
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types: bankaddress int

variable_types:
RAM
unsigned char *


decompiled_code:
__int64 __fastcall capbowl_tms34061_setpixel(int a1, int a2, int a3)
{
_BYTE *v3; // r8
int v4; // ecx
__int64 result; // rax
bool v6; // cc
unsigned __int8 v7; // r9
int v8; // er10
int v9; // eax
int v11; // er9
int v12; // edx
int v13; // ecx
bool v14; // zf

v3 = raw_video_ram;
v4 = a1 | (a2 << 8);
result = (__int64)raw_video_ram + v4;
v6 = max_row < a2;
v7 = *(_BYTE *)result;
*(_BYTE *)result = a3;
if ( !v6 && max_col_offset > a1 )
{
v8 = 16 * a2;
if ( a1 <= 31 )
{
result = palette_change_color(
v8 | (unsigned int)(a1 >> 1),
17 * (v3[v4 & 0xFFFFFFFE] & 0xFu),
17 * (unsigned int)(v3[v4 | 1] >> 4),
17 * (v3[v4 | 1] & 0xFu));
}
else
{
v9 = v7;
v11 = v8 | v7 & 0xF;
v12 = v8 | a3 & 0xF;
result = v8 | (unsigned int)(v9 >> 4);
v13 = v8 | (a3 >> 4);
if ( (_DWORD)result != v13 )
{
*((_BYTE *)&dirty_row + a2) = 1;
v14 = color_count[(int)result]-- == 1;
if ( v14 )
*(_BYTE *)(palette_used_colors + (int)result) = 0;
result = palette_used_colors;
++color_count[v13];
*(_BYTE *)(result + v13) = 3;
}
if ( v11 != v12 )
{
v14 = color_count[v11]-- == 1;
*((_BYTE *)&dirty_row + a2) = 1;
if ( v14 )
*(_BYTE *)(palette_used_colors + v11) = 0;
result = palette_used_colors;
++color_count[v12];
*(_BYTE *)(result + v12) = 3;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, int a2, int a3)
{
_BYTE *v3; // r8
int v4; // ecx
__int64 result; // rax
bool v6; // cc
unsigned __int8 v7; // r9
int v8; // er10
int v9; // eax
int v11; // er9
int v12; // edx
int v13; // ecx
bool v14; // zf

v3 = raw_video_ram;
v4 = a1 | (a2 << 8);
result = (__int64)raw_video_ram + v4;
v6 = max_row < a2;
v7 = *(_BYTE *)result;
*(_BYTE *)result = a3;
if ( !v6 && max_col_offset > a1 )
{
v8 = 16 * a2;
if ( a1 <= 31 )
{
result = palette_change_color(
v8 | (unsigned int)(a1 >> 1),
17 * (v3[v4 & 0xFFFFFFFE] & 0xFu),
17 * (unsigned int)(v3[v4 | 1] >> 4),
17 * (v3[v4 | 1] & 0xFu));
}
else
{
v9 = v7;
v11 = v8 | v7 & 0xF;
v12 = v8 | a3 & 0xF;
result = v8 | (unsigned int)(v9 >> 4);
v13 = v8 | (a3 >> 4);
if ( (_DWORD)result != v13 )
{
*((_BYTE *)&dirty_row + a2) = 1;
v14 = color_count[(int)result]-- == 1;
if ( v14 )
*(_BYTE *)(palette_used_colors + (int)result) = 0;
result = palette_used_colors;
++color_count[v13];
*(_BYTE *)(result + v13) = 3;
}
if ( v11 != v12 )
{
v14 = color_count[v11]-- == 1;
*((_BYTE *)&dirty_row + a2) = 1;
if ( v14 )
*(_BYTE *)(palette_used_colors + v11) = 0;
result = palette_used_colors;
++color_count[v12];
*(_BYTE *)(result + v12) = 3;
}
}
}
return result;
}

original_code:
static void capbowl_tms34061_setpixel(int col, int row, int pixel)
{
 int off = ((row << 8) | col);
 int penstart = row << 4;
 int oldpixel = raw_video_ram[off];
 raw_video_ram[off] = pixel;
 if (row > max_row || col >= max_col_offset) return;
 if (col >= 0x20)
 {
  int oldpen1 = penstart | (oldpixel >> 4);
  int oldpen2 = penstart | (oldpixel & 0x0f);
  int newpen1 = penstart | (pixel >> 4);
  int newpen2 = penstart | (pixel & 0x0f);
  if (oldpen1 != newpen1)
  {
   dirty_row[row] = 1;
   color_count[oldpen1]--;
   if (!color_count[oldpen1]) palette_used_colors[oldpen1] = 0;
   color_count[newpen1]++;
   palette_used_colors[newpen1] = (1|2);
  }
  if (oldpen2 != newpen2)
  {
   dirty_row[row] = 1;
   color_count[oldpen2]--;
   if (!color_count[oldpen2]) palette_used_colors[oldpen2] = 0;
   color_count[newpen2]++;
   palette_used_colors[newpen2] = (1|2);
  }
 }
 else
 {
  int r = (raw_video_ram[off & ~1] & 0x0f);
  int g = (raw_video_ram[off | 1] >> 4);
  int b = (raw_video_ram[off | 1] & 0x0f);
  r = (r << 4) + r;
  g = (g << 4) + g;
  b = (b << 4) + b;
  palette_change_color(penstart | (col >> 1),r,g,b);
 }
}

variable_types: pixel int

variable_types: off int

variable_types: penstart int

variable_types: oldpixel int

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
void __fastcall TMS34061_intcallback(unsigned int a1)
{
unsigned int v1; // eax

if ( (qword_D68 & 0x40000000000LL) != 0 )
{
dword_D74 |= 1u;
v1 = (*(__int64 (**)(void))(intf + 48))();
cpu_cause_interrupt(a1, v1);
}
}

canonical_decompiled_code:
void __fastcall func15(unsigned int a1)
{
unsigned int v1; // eax

if ( (qword_D68 & 0x40000000000LL) != 0 )
{
dword_D74 |= 1u;
v1 = (*(__int64 (**)(void))(intf + 48))();
cpu_cause_interrupt(a1, v1);
}
}

original_code:
static void TMS34061_intcallback(int param)
{
    if (!(regs[11] & 0x400)) return;
 regs[13] |= 0x0001;
 cpu_cause_interrupt (param, intf->vertical_interrupt());
}

variable_types: param int


decompiled_code:
__int64 __fastcall TMS34061_register_w(unsigned int a1, int a2)
{
unsigned int v2; // edx
__int64 result; // rax
unsigned int v4; // eax

v2 = a1 >> 2;
LODWORD(result) = *((_DWORD *)&regs + (a1 >> 2));
if ( (a1 & 2) != 0 )
{
result = (unsigned __int8)result;
*((_DWORD *)&regs + (int)v2) = (unsigned __int8)result | (a2 << 8);
if ( v2 != 10 )
return result;
LABEL_5:
v4 = cpu_getscanlinetime((unsigned int)qword_D68);
return timer_reset(timer, v4);
}
result = (unsigned __int16)result & 0xFF00;
*((_DWORD *)&regs + (int)v2) = result | a2;
if ( v2 == 10 )
goto LABEL_5;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(unsigned int a1, int a2)
{
unsigned int v2; // edx
__int64 result; // rax
unsigned int v4; // eax

v2 = a1 >> 2;
LODWORD(result) = *((_DWORD *)&regs + (a1 >> 2));
if ( (a1 & 2) != 0 )
{
result = (unsigned __int8)result;
*((_DWORD *)&regs + (int)v2) = (unsigned __int8)result | (a2 << 8);
if ( v2 != 10 )
return result;
LABEL_5:
v4 = cpu_getscanlinetime((unsigned int)qword_D68);
return timer_reset(timer, v4);
}
result = (unsigned __int16)result & 0xFF00;
*((_DWORD *)&regs + (int)v2) = result | a2;
if ( v2 == 10 )
goto LABEL_5;
return result;
}

original_code:
static inline void TMS34061_register_w(offs_t offset,data_t data)
{
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  regs[reg] = ((regs[reg] & 0xff) | (data << 8));
 }
 else
 {
  regs[reg] = ((regs[reg] & 0xff00) | data);
 }
 switch (reg)
 {
 case 10:
  timer_reset(timer, cpu_getscanlinetime(regs[reg]));
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
}

canonical_original_code:
static inline void TMS34061_register_w(unsigned int offset, unsigned int data)
{
 int status = 0;
 int reg = offset >> 2;
 if (offset & 0x02)
 {
  regs[reg] = ((regs[reg] & 0xff) | (data << 8));
 }
 else
 {
  regs[reg] = ((regs[reg] & 0xff00) | data);
 }
 switch (reg)
 {
 case 10:
  timer_reset(timer, cpu_getscanlinetime(regs[reg]));
 case 11:
 case 12:
 case 15:
  status = 1;
  break;
 }
}

variable_types: status int

variable_types: reg int


decompiled_code:
void __fastcall TMS34061_w(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned int v3; // er14
int v4; // eax

v2 = (*(__int64 (**)(void))(intf + 16))();
v3 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
v4 = (*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( v4 == 2 )
goto LABEL_8;
if ( v4 <= 2 )
{
if ( v4 )
{
if ( v4 == 1 )
TMS34061_xypixel_w(v2, a2);
return;
}
LABEL_8:
TMS34061_register_w(v2, a2);
return;
}
if ( v4 == 3 )
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(v2, v3, a2);
}

canonical_decompiled_code:
void __fastcall func17(unsigned int a1, unsigned int a2)
{
unsigned int v2; // er12
unsigned int v3; // er14
int v4; // eax

v2 = (*(__int64 (**)(void))(intf + 16))();
v3 = (*(__int64 (__fastcall **)(_QWORD))(intf + 8))(a1);
v4 = (*(__int64 (__fastcall **)(_QWORD))intf)(a1);
if ( v4 == 2 )
goto LABEL_8;
if ( v4 <= 2 )
{
if ( v4 )
{
if ( v4 == 1 )
func8(v2, a2);
return;
}
LABEL_8:
func16(v2, a2);
return;
}
if ( v4 == 3 )
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(intf + 32))(v2, v3, a2);
}

original_code:
void TMS34061_w(offs_t offset,data_t data)
{
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  TMS34061_register_w(col, data);
  break;
 case 1:
  TMS34061_xypixel_w(col, data);
  break;
 case 3:
  intf->setpixel(col, row, data);
  break;
 default:
     break;
 }
}

canonical_original_code:
void TMS34061_w(unsigned int offset, unsigned int data)
{
 int col = intf->getcoladdress(offset);
 int row = intf->getrowaddress(offset);
 int func = intf->getfunction(offset);
 switch (func)
 {
 case 0:
 case 2:
  TMS34061_register_w(col, data);
  break;
 case 1:
  TMS34061_xypixel_w(col, data);
  break;
 case 3:
  intf->setpixel(col, row, data);
  break;
 default:
     break;
 }
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


firqhandler

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

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

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

variable_types: irq int


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

if ( (readinputport(4LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

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

if ( (readinputport(4LL) & 1) != 0 )
result = nmi_interrupt();
else
result = ignore_interrupt();
return result;
}

original_code:
static int capbowl_interrupt(void)
{
 if (readinputport(4) & 1)
  return nmi_interrupt();
 return ignore_interrupt();
}

canonical_original_code:
static int capbowl_interrupt()
{
 if (readinputport(4) & 1)
  return nmi_interrupt();
 return ignore_interrupt();
}

return_type: int


decompiled_code:
__int64 __fastcall track_reset_w(unsigned int a1, unsigned int a2)
{
track = input_port_2_r();
dword_D0C = input_port_3_r(a1);
return watchdog_reset_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func21(unsigned int a1, unsigned int a2)
{
track = input_port_2_r();
dword_D0C = input_port_3_r(a1);
return watchdog_reset_w(a1, a2);
}

original_code:
static void track_reset_w(offs_t offset,data_t data)
{
 track[0] = input_port_2_r(offset);
 track[1] = input_port_3_r(offset);
 watchdog_reset_w(offset,data);
}

canonical_original_code:
static void track_reset_w(unsigned int offset, unsigned int data)
{
 track[0] = input_port_2_r(offset);
 track[1] = input_port_3_r(offset);
 watchdog_reset_w(offset,data);
}


decompiled_code:
__int64 __fastcall capbowl_sndcmd_w(unsigned int a1, unsigned int a2)
{
cpu_cause_interrupt(1LL, 1LL);
return soundlatch_w(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func22(unsigned int a1, unsigned int a2)
{
cpu_cause_interrupt(1LL, 1LL);
return soundlatch_w(a1, a2);
}

original_code:
static void capbowl_sndcmd_w(offs_t offset,data_t data)
{
 cpu_cause_interrupt(1, 1);
 soundlatch_w(offset, data);
}

canonical_original_code:
static void capbowl_sndcmd_w(unsigned int offset, unsigned int data)
{
 cpu_cause_interrupt(1, 1);
 soundlatch_w(offset, data);
}


decompiled_code:
__int64 __fastcall track_1_r(unsigned int a1)
{
char v1; // bl

v1 = input_port_1_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_3_r(a1) - (_BYTE)dword_D0C) & 0xFu;
}

canonical_decompiled_code:
__int64 __fastcall func23(unsigned int a1)
{
char v1; // bl

v1 = input_port_1_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_3_r(a1) - (_BYTE)dword_D0C) & 0xFu;
}

original_code:
static data_t track_1_r(offs_t offset)
{
 return (input_port_1_r(offset) & 0xf0) | ((input_port_3_r(offset) - track[1]) & 0x0f);
}

canonical_original_code:
static unsigned int track_1_r(unsigned int offset)
{
 return (input_port_1_r(offset) & 0xf0) | ((input_port_3_r(offset) - track[1]) & 0x0f);
}


decompiled_code:
__int64 __fastcall track_0_r(unsigned int a1)
{
char v1; // bl

v1 = input_port_0_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_2_r(a1) - (_BYTE)track) & 0xFu;
}

canonical_decompiled_code:
__int64 __fastcall func24(unsigned int a1)
{
char v1; // bl

v1 = input_port_0_r();
return v1 & 0xF0 | ((unsigned __int8)input_port_2_r(a1) - (_BYTE)track) & 0xFu;
}

original_code:
static data_t track_0_r(offs_t offset)
{
 return (input_port_0_r(offset) & 0xf0) | ((input_port_2_r(offset) - track[0]) & 0x0f);
}

canonical_original_code:
static unsigned int track_0_r(unsigned int offset)
{
 return (input_port_0_r(offset) & 0xf0) | ((input_port_2_r(offset) - track[0]) & 0x0f);
}


original_code:
int TMS34061_start(struct TMS34061interface *interface)
{
 intf = interface;
 regs[0] = 0x10;
 regs[1] = 0x20;
 regs[2] = 0x1f0;
 regs[3] = 0x200;
 regs[4] = 0x04;
 regs[5] = 0x10;
 regs[6] = 0xf0;
 regs[7] = 0x100;
 regs[8] = 0x00;
 regs[9] = 0x00;
 regs[10] = 0x00;
 regs[11] = 0x7000;
 regs[12] = 0x600;
 regs[13] = 0x00;
 regs[14] = 0x10;
 regs[15] = 0x00;
 regs[16] = 0x00;
 regs[17] = 0x00;
 timer = timer_pulse(((1<<30) / ((timer_tm)(Machine->drv->frames_per_second))),
                     intf->cpu, TMS34061_intcallback);
 return !timer;
}

variable_types: struct TMS34061interface { int (*getfunction)(int offset); int (*getrowaddress)(int offset); int (*getcoladdress)(int offset); int (*getpixel)(int col, int row); void (*setpixel)(int col, int row, int pixel); int cpu; int (*vertical_interrupt)(); } *


decompiled_code:
__int64 capbowl_vh_start()
{
_BOOL4 v0; // er12
int v1; // eax
int v2; // ecx
int v3; // esi
__int64 v4; // rax

raw_video_ram = malloc(0x10000uLL);
if ( !raw_video_ram )
return 1;
v0 = TMS34061_start((__int64)&tms34061_interface);
if ( !v0 )
{
v1 = *(_DWORD *)(Machine + 780LL);
max_row = *(_DWORD *)(Machine + 788LL);
max_col = v1;
max_col_offset = (v1 + 1) / 2 + 32;
memset(raw_video_ram, 0, 0x10000uLL);
palette_init_used_colors();
memset(color_count, 0, sizeof(color_count));
v2 = 16 * max_row;
dirty_row = (__int128)_mm_load_si128((const __m128i *)&LC0);
xmmword_DB0 = dirty_row;
xmmword_DC0 = dirty_row;
xmmword_DD0 = dirty_row;
xmmword_DE0 = dirty_row;
xmmword_DF0 = dirty_row;
xmmword_E00 = dirty_row;
xmmword_E10 = dirty_row;
xmmword_E20 = dirty_row;
xmmword_E30 = dirty_row;
xmmword_E40 = dirty_row;
xmmword_E50 = dirty_row;
xmmword_E60 = dirty_row;
xmmword_E70 = dirty_row;
xmmword_E80 = dirty_row;
xmmword_E90 = dirty_row;
if ( 16 * max_row > 0 )
{
v3 = max_col + 1;
v4 = 0LL;
do
{
*(_BYTE *)(palette_used_colors + v4) = 3;
color_count[v4] = v3;
v4 += 16LL;
}
while ( v2 > (int)v4 );
}
return v0;
}
free(raw_video_ram);
return 1LL;
}

canonical_decompiled_code:
__int64 func26()
{
_BOOL4 v0; // er12
int v1; // eax
int v2; // ecx
int v3; // esi
__int64 v4; // rax

raw_video_ram = malloc(0x10000uLL);
if ( !raw_video_ram )
return 1;
v0 = func25((__int64)&tms34061_interface);
if ( !v0 )
{
v1 = *(_DWORD *)(Machine + 780LL);
max_row = *(_DWORD *)(Machine + 788LL);
max_col = v1;
max_col_offset = (v1 + 1) / 2 + 32;
memset(raw_video_ram, 0, 0x10000uLL);
palette_init_used_colors();
memset(color_count, 0, sizeof(color_count));
v2 = 16 * max_row;
dirty_row = (__int128)_mm_load_si128((const __m128i *)&LC0);
xmmword_DB0 = dirty_row;
xmmword_DC0 = dirty_row;
xmmword_DD0 = dirty_row;
xmmword_DE0 = dirty_row;
xmmword_DF0 = dirty_row;
xmmword_E00 = dirty_row;
xmmword_E10 = dirty_row;
xmmword_E20 = dirty_row;
xmmword_E30 = dirty_row;
xmmword_E40 = dirty_row;
xmmword_E50 = dirty_row;
xmmword_E60 = dirty_row;
xmmword_E70 = dirty_row;
xmmword_E80 = dirty_row;
xmmword_E90 = dirty_row;
if ( 16 * max_row > 0 )
{
v3 = max_col + 1;
v4 = 0LL;
do
{
*(_BYTE *)(palette_used_colors + v4) = 3;
color_count[v4] = v3;
v4 += 16LL;
}
while ( v2 > (int)v4 );
}
return v0;
}
free(raw_video_ram);
return 1LL;
}

original_code:
int capbowl_vh_start(void)
{
 int i;
 if ((raw_video_ram = (unsigned char*)malloc(256 * 256)) == 0)
 {
  return 1;
 }
    if (TMS34061_start(&tms34061_interface))
 {
  free(raw_video_ram);
  return 1;
 }
 max_row = Machine->visible_area.max_y;
 max_col = Machine->visible_area.max_x;
 max_col_offset = (max_col + 1) / 2 + 0x20;
 memset(raw_video_ram, 0, 256*256);
 palette_init_used_colors();
 memset(color_count, 0, sizeof(color_count));
 memset(dirty_row, 1, sizeof(dirty_row));
 for (i = 0; i < max_row * 16; i+=16)
 {
  palette_used_colors[i] = (1|2);
  color_count[i] = max_col + 1;
 }
 return 0;
}

canonical_original_code:
int capbowl_vh_start()
{
 int i;
 if ((raw_video_ram = (unsigned char *)malloc(256 * 256)) == 0)
 {
  return 1;
 }
    if (TMS34061_start(&tms34061_interface))
 {
  free(raw_video_ram);
  return 1;
 }
 max_row = Machine->visible_area.max_y;
 max_col = Machine->visible_area.max_x;
 max_col_offset = (max_col + 1) / 2 + 0x20;
 memset(raw_video_ram, 0, 256*256);
 palette_init_used_colors();
 memset(color_count, 0, sizeof(color_count));
 memset(dirty_row, 1, sizeof(dirty_row));
 for (i = 0; i < max_row * 16; i+=16)
 {
  palette_used_colors[i] = (1|2);
  color_count[i] = max_col + 1;
 }
 return 0;
}

variable_types: i int


decompiled_code:
__int64 TMS34061_stop()
{
return timer_remove(timer);
}

canonical_decompiled_code:
__int64 func27()
{
return timer_remove(timer);
}

original_code:
void TMS34061_stop(void)
{
 timer_remove(timer);
}

canonical_original_code:
void TMS34061_stop()
{
 timer_remove(timer);
}


decompiled_code:
__int64 capbowl_vh_stop()
{
free(raw_video_ram);
return TMS34061_stop();
}

canonical_decompiled_code:
__int64 func28()
{
free(raw_video_ram);
return func27();
}

original_code:
void capbowl_vh_stop(void)
{
 free(raw_video_ram);
 TMS34061_stop();
}

canonical_original_code:
void capbowl_vh_stop()
{
 free(raw_video_ram);
 TMS34061_stop();
}


decompiled_code:
_BOOL8 TMS34061_display_blanked()
{
return (byte_D71 & 0x20) == 0;
}

original_code:
int TMS34061_display_blanked(void)
{
 return (!(regs[12] & 0x2000));
}

canonical_original_code:
int TMS34061_display_blanked()
{
 return (!(regs[12] & 0x2000));
}


decompiled_code:
__int64 __fastcall capbowl_vh_screenrefresh(__int64 a1, int a2)
{
__int64 result; // rax
_BYTE *v4; // rdx
int v5; // esi
__int128 *v6; // rcx
int v7; // edi
_BYTE *v8; // rax
__int64 v9; // r15
unsigned int v10; // ebx
int v11; // er12
bool v12; // cc
unsigned int v13; // er15
__int64 v14; // r13
__int64 v15; // rsi
unsigned int v16; // er10
int v17; // edx
char v18; // [rsp+7h] [rbp-51h]
unsigned int v19; // [rsp+8h] [rbp-50h]
int v20; // [rsp+Ch] [rbp-4Ch]
__int64 v21; // [rsp+18h] [rbp-40h]

if ( a2 && max_row >= 0 )
memset(&dirty_row, 1, max_row + 1LL);
if ( TMS34061_display_blanked() )
return fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
result = palette_recalc();
if ( result )
{
if ( max_row < 0 )
return result;
v4 = (_BYTE *)(result + 16);
v5 = 0;
v6 = &dirty_row;
v7 = 16 * (max_row + 1);
do
{
while ( *(_BYTE *)v6 )
{
LABEL_8:
v5 += 16;
v6 = (__int128 *)((char *)v6 + 1);
v4 += 16;
if ( v5 == v7 )
goto LABEL_14;
}
v8 = v4 - 16;
while ( !*v8 )
{
if ( v4 == ++v8 )
goto LABEL_8;
}
v5 += 16;
*(_BYTE *)v6 = 1;
v4 += 16;
v6 = (__int128 *)((char *)v6 + 1);
}
while ( v5 != v7 );
}
else
{
result = (unsigned int)max_row;
if ( max_row < 0 )
return result;
}
LABEL_14:
v9 = 0LL;
do
{
while ( 1 )
{
result = (__int64)&dirty_row;
v10 = v9;
if ( *((_BYTE *)&dirty_row + v9) )
{
v11 = 16 * v9;
result = ((_DWORD)v9 << 8) | 0x20u;
v12 = max_col_offset <= 32;
*((_BYTE *)&dirty_row + v9) = 0;
if ( !v12 )
break;
}
if ( max_row < (int)++v9 )
return result;
}
v21 = v9;
v13 = 0;
v14 = (int)result;
v20 = 32 - result;
do
{
v15 = v13;
v16 = v13 + 1;
v13 += 2;
v17 = *((unsigned __int8 *)raw_video_ram + v14);
v19 = v16;
++v14;
v18 = v17;
plot_pixel(a1, v15, v10, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v11 | (v17 >> 4))));
plot_pixel(a1, v19, v10, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v11 | v18 & 0xF)));
result = (unsigned int)(v14 + v20);
}
while ( max_col_offset > (int)result );
v9 = v21 + 1;
}
while ( max_row >= (int)v21 + 1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1, int a2)
{
__int64 result; // rax
_BYTE *v4; // rdx
int v5; // esi
__int128 *v6; // rcx
int v7; // edi
_BYTE *v8; // rax
__int64 v9; // r15
unsigned int v10; // ebx
int v11; // er12
bool v12; // cc
unsigned int v13; // er15
__int64 v14; // r13
__int64 v15; // rsi
unsigned int v16; // er10
int v17; // edx
char v18; // [rsp+7h] [rbp-51h]
unsigned int v19; // [rsp+8h] [rbp-50h]
int v20; // [rsp+Ch] [rbp-4Ch]
__int64 v21; // [rsp+18h] [rbp-40h]

if ( a2 && max_row >= 0 )
memset(&dirty_row, 1, max_row + 1LL);
if ( func29() )
return fillbitmap(a1, palette_transparent_pen, Machine + 776LL);
result = palette_recalc();
if ( result )
{
if ( max_row < 0 )
return result;
v4 = (_BYTE *)(result + 16);
v5 = 0;
v6 = &dirty_row;
v7 = 16 * (max_row + 1);
do
{
while ( *(_BYTE *)v6 )
{
LABEL_8:
v5 += 16;
v6 = (__int128 *)((char *)v6 + 1);
v4 += 16;
if ( v5 == v7 )
goto LABEL_14;
}
v8 = v4 - 16;
while ( !*v8 )
{
if ( v4 == ++v8 )
goto LABEL_8;
}
v5 += 16;
*(_BYTE *)v6 = 1;
v4 += 16;
v6 = (__int128 *)((char *)v6 + 1);
}
while ( v5 != v7 );
}
else
{
result = (unsigned int)max_row;
if ( max_row < 0 )
return result;
}
LABEL_14:
v9 = 0LL;
do
{
while ( 1 )
{
result = (__int64)&dirty_row;
v10 = v9;
if ( *((_BYTE *)&dirty_row + v9) )
{
v11 = 16 * v9;
result = ((_DWORD)v9 << 8) | 0x20u;
v12 = max_col_offset <= 32;
*((_BYTE *)&dirty_row + v9) = 0;
if ( !v12 )
break;
}
if ( max_row < (int)++v9 )
return result;
}
v21 = v9;
v13 = 0;
v14 = (int)result;
v20 = 32 - result;
do
{
v15 = v13;
v16 = v13 + 1;
v13 += 2;
v17 = *((unsigned __int8 *)raw_video_ram + v14);
v19 = v16;
++v14;
v18 = v17;
plot_pixel(a1, v15, v10, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v11 | (v17 >> 4))));
plot_pixel(a1, v19, v10, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL * (v11 | v18 & 0xF)));
result = (unsigned int)(v14 + v20);
}
while ( max_col_offset > (int)result );
v9 = v21 + 1;
}
while ( max_row >= (int)v21 + 1 );
return result;
}

original_code:
void capbowl_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int col, row;
 const unsigned char *remapped;
 if (full_refresh)
 {
  for (row = 0; row <= max_row; row++) dirty_row[row] = 1;
 }
 if (TMS34061_display_blanked())
 {
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
  return;
 }
 if ((remapped = palette_recalc()) != 0)
 {
  for (row = 0; row <= max_row; row++)
  {
   if (dirty_row[row] == 0)
   {
    int i;
    for (i = 0;i < 16;i++)
    {
     if (remapped[16 * row + i] != 0)
     {
      dirty_row[row] = 1;
      break;
     }
    }
   }
  }
 }
 for (row = 0; row <= max_row; row++)
 {
  if (dirty_row[row])
  {
   int col1 = 0;
   int row1 = (row << 8 | 0x20);
   int row2 = row << 4;
   dirty_row[row] = 0;
   for (col = 0x20; col < max_col_offset; col++)
   {
    int pixel = raw_video_ram[row1++];
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel >> 4) ]);
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel & 0x0f)]);
   }
  }
 }
}

canonical_original_code:
void capbowl_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int col; int row;
 unsigned char *remapped;
 if (full_refresh)
 {
  for (row = 0; row <= max_row; row++) dirty_row[row] = 1;
 }
 if (TMS34061_display_blanked())
 {
  fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
  return;
 }
 if ((remapped = palette_recalc()) != 0)
 {
  for (row = 0; row <= max_row; row++)
  {
   if (dirty_row[row] == 0)
   {
    int i;
    for (i = 0;i < 16;i++)
    {
     if (remapped[16 * row + i] != 0)
     {
      dirty_row[row] = 1;
      break;
     }
    }
   }
  }
 }
 for (row = 0; row <= max_row; row++)
 {
  if (dirty_row[row])
  {
   int col1 = 0;
   int row1 = (row << 8 | 0x20);
   int row2 = row << 4;
   dirty_row[row] = 0;
   for (col = 0x20; col < max_col_offset; col++)
   {
    int pixel = raw_video_ram[row1++];
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel >> 4) ]);
    plot_pixel(bitmap, col1++,row,Machine->pens[row2 | (pixel & 0x0f)]);
   }
  }
 }
}

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

variable_types: col int

variable_types: row int

variable_types:
remapped
unsigned char *


decompiled_code:
void *__fastcall nvram_handler(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, nvram_size);
return memset(nvram, 1, nvram_size);
}

canonical_decompiled_code:
void *__fastcall func18(__int64 a1, int a2)
{
if ( a2 )
return (void *)osd_fwrite(a1, nvram, nvram_size);
if ( a1 )
return (void *)osd_fread(a1, nvram, nvram_size);
return memset(nvram, 1, nvram_size);
}

original_code:
static void nvram_handler(void *file,int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
  {
   memset(nvram,0x01,nvram_size);
  }
 }
}

canonical_original_code:
static void nvram_handler(void *file, int read_or_write)
{
 if (read_or_write)
  osd_fwrite(file,nvram,nvram_size);
 else
 {
  if (file)
   osd_fread(file,nvram,nvram_size);
  else
  {
   memset(nvram,0x01,nvram_size);
  }
 }
}

variable_types:
file
void *


decompiled_code:
__int64 __fastcall vert_scale(int a1)
{
return ((2 * (_BYTE)a1) & 0xE) + 10 * ((a1 >> 3) & 0x1Fu);
}

original_code:
static int vert_scale(int data)
{
 return ((data & 0x07)<<1) + ((data & 0xf8)>>3) * 10;
}

variable_types: data int


decompiled_code:
void lazercmd_ctrl_port_w()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

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

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


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

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

original_code:
static data_t lazercmd_ctrl_port_r(offs_t offset)
{
 int data = 0;
 return data;
}

canonical_original_code:
static unsigned int lazercmd_ctrl_port_r(unsigned int offset)
{
 int data = 0;
 return data;
}


decompiled_code:
void lazercmd_data_port_w()
{
;
}

canonical_decompiled_code:
void func3()
{
;
}

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

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


decompiled_code:
__int64 __fastcall plot_pattern(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // ebp
unsigned int v4; // er15
__int64 result; // rax
int v6; // er14
unsigned int v7; // ebx

v3 = a3;
v4 = a3 + 2;
result = (input_port_2_r(0LL) & 0x40) == 0 ? 0xFFFFFFFE : 0;
v6 = result + a2 + 4;
do
{
if ( v3 > 0xEF )
break;
v7 = a2;
do
{
if ( v7 <= 0xFF )
result = plot_pixel(a1, v7, v3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 4LL));
++v7;
}
while ( v7 != v6 );
++v3;
}
while ( v3 != v4 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v3; // ebp
unsigned int v4; // er15
__int64 result; // rax
int v6; // er14
unsigned int v7; // ebx

v3 = a3;
v4 = a3 + 2;
result = (input_port_2_r(0LL) & 0x40) == 0 ? 0xFFFFFFFE : 0;
v6 = result + a2 + 4;
do
{
if ( v3 > 0xEF )
break;
v7 = a2;
do
{
if ( v7 <= 0xFF )
result = plot_pixel(a1, v7, v3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 4LL));
++v7;
}
while ( v7 != v6 );
++v3;
}
while ( v3 != v4 );
return result;
}

original_code:
static void plot_pattern(struct osd_bitmap *bitmap, int x, int y)
{
 int xbit, ybit, size;
    size = 2;
 if (input_port_2_r(0) & 0x40)
    {
  size = 4;
    }
 for (ybit = 0; ybit < 2; ybit++)
 {
     if (y+ybit < 0 || y+ybit >= 24 * 10)
      return;
     for (xbit = 0; xbit < size; xbit++)
  {
   if (x+xbit < 0 || x+xbit >= 32 * 8)
    continue;
   plot_pixel(bitmap, x+xbit, y+ybit, Machine->pens[2]);
  }
 }
}

canonical_original_code:
static void plot_pattern(struct osd_bitmap *bitmap, int x, int y)
{
 int xbit; int ybit; int size;
    size = 2;
 if (input_port_2_r(0) & 0x40)
    {
  size = 4;
    }
 for (ybit = 0; ybit < 2; ybit++)
 {
     if (y+ybit < 0 || y+ybit >= 24 * 10)
      return;
     for (xbit = 0; xbit < size; xbit++)
  {
   if (x+xbit < 0 || x+xbit >= 32 * 8)
    continue;
   plot_pixel(bitmap, x+xbit, y+ybit, Machine->pens[2]);
  }
 }
}

variable_types: x int

variable_types: y int

variable_types: xbit int

variable_types: ybit int

variable_types: size int

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


decompiled_code:
__int64 lazercmd_data_port_r()
{
return input_port_2_r(0LL) & 0xF;
}

canonical_decompiled_code:
__int64 func6()
{
return input_port_2_r(0LL) & 0xF;
}

original_code:
static data_t lazercmd_data_port_r(offs_t offset)
{
 int data;
 data = input_port_2_r(0) & 0x0f;
 return data;
}

canonical_original_code:
static unsigned int lazercmd_data_port_r(unsigned int offset)
{
 int data;
 data = input_port_2_r(0) & 0x0f;
 return data;
}


decompiled_code:
__int64 lazercmd_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( (unsigned int)generic_vh_start() )
return v0;
v0 = 0;
if ( (input_port_2_r(0LL) & 0x80u) == 0LL )
return v0;
overlay_create(&overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
unsigned int v0; // er12

v0 = 1;
if ( (unsigned int)generic_vh_start() )
return v0;
v0 = 0;
if ( (input_port_2_r(0LL) & 0x80u) == 0LL )
return v0;
overlay_create(&overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
return 0LL;
}

original_code:
int lazercmd_vh_start(void)
{
 if( generic_vh_start() )
  return 1;
 if (input_port_2_r(0) & 0x80)
 {
  overlay_create(overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}

canonical_original_code:
int lazercmd_vh_start()
{
 if( generic_vh_start() )
  return 1;
 if (input_port_2_r(0) & 0x80)
 {
  overlay_create(overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}


decompiled_code:
__int64 __fastcall lazercmd_vh_screenrefresh(__int64 a1, int a2)
{
__int64 i; // rbx
int v3; // esi
int v4; // edx
int v5; // ecx
unsigned int v6; // er10
int v7; // eax

if ( (input_port_2_r(0LL) & 0x20) != video_inverted )
{
LOBYTE(video_inverted) = input_port_2_r(0LL) & 0x20;
video_inverted = (unsigned __int8)video_inverted;
memset(dirtybuffer, 1, videoram_size);
}
if ( palette_recalc() || a2 )
memset(dirtybuffer, 1, videoram_size);
for ( i = 0LL; i != 736; ++i )
{
while ( !*((_BYTE *)dirtybuffer + i) )
{
if ( ++i == 736 )
goto LABEL_10;
}
v3 = video_inverted;
*((_BYTE *)dirtybuffer + i) = 0;
v4 = i & 0x1F;
v5 = (int)i >> 5;
v6 = *(unsigned __int8 *)(videoram + i);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v6,
v3 != 0,
0LL,
0LL,
(unsigned int)(8 * v4),
(unsigned int)(10 * v5),
Machine + 776LL,
0LL,
0LL);
}
LABEL_10:
v7 = vert_scale(marker_y);
return plot_pattern(a1, marker_x - 1, v7 - 10);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 i; // rbx
int v3; // esi
int v4; // edx
int v5; // ecx
unsigned int v6; // er10
int v7; // eax

if ( (input_port_2_r(0LL) & 0x20) != video_inverted )
{
LOBYTE(video_inverted) = input_port_2_r(0LL) & 0x20;
video_inverted = (unsigned __int8)video_inverted;
memset(dirtybuffer, 1, videoram_size);
}
if ( palette_recalc() || a2 )
memset(dirtybuffer, 1, videoram_size);
for ( i = 0LL; i != 736; ++i )
{
while ( !*((_BYTE *)dirtybuffer + i) )
{
if ( ++i == 736 )
goto LABEL_10;
}
v3 = video_inverted;
*((_BYTE *)dirtybuffer + i) = 0;
v4 = i & 0x1F;
v5 = (int)i >> 5;
v6 = *(unsigned __int8 *)(videoram + i);
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
v6,
v3 != 0,
0LL,
0LL,
(unsigned int)(8 * v4),
(unsigned int)(10 * v5),
Machine + 776LL,
0LL,
0LL);
}
LABEL_10:
v7 = func0(marker_y);
return func5(a1, marker_x - 1, v7 - 10);
}

original_code:
void lazercmd_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int i,x,y;
 if (video_inverted != (input_port_2_r(0) & 0x20))
 {
  video_inverted = input_port_2_r(0) & 0x20;
  memset(dirtybuffer, 1, videoram_size);
 }
 if (palette_recalc() || full_refresh)
        memset(dirtybuffer, 1, videoram_size);
 for (i = 0; i < (24 - 1) * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int sx,sy;
   dirtybuffer[i] = 0;
   sx = i % 32;
   sy = i / 32;
   sx *= 8;
   sy *= 10;
   drawgfx(bitmap, Machine->gfx[0],
     videoram[i], video_inverted ? 1 : 0,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 x = marker_x - 1;
 y = vert_scale(marker_y) - 10;
 plot_pattern(bitmap,x,y);
}

canonical_original_code:
void lazercmd_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int i; int x; int y;
 if (video_inverted != (input_port_2_r(0) & 0x20))
 {
  video_inverted = input_port_2_r(0) & 0x20;
  memset(dirtybuffer, 1, videoram_size);
 }
 if (palette_recalc() || full_refresh)
        memset(dirtybuffer, 1, videoram_size);
 for (i = 0; i < (24 - 1) * 32; i++)
 {
  if (dirtybuffer[i])
  {
   int sx; int sy;
   dirtybuffer[i] = 0;
   sx = i % 32;
   sy = i / 32;
   sx *= 8;
   sy *= 10;
   drawgfx(bitmap, Machine->gfx[0],
     videoram[i], video_inverted ? 1 : 0,
     0,0,
     sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 x = marker_x - 1;
 y = vert_scale(marker_y) - 10;
 plot_pattern(bitmap,x,y);
}

variable_types: sx int

variable_types: sy int


variable_types:
d
unsigned char *

variable_types:
s
unsigned char *


decompiled_code:
__int64 lazercmd_timer()
{
bool v1; // zf

if ( timer_count + 1 > 0x1FFF )
{
v1 = sense_state_2 == 1;
sense_state_2 ^= 1u;
timer_count = 0;
cpu_set_irq_line(0LL, 1LL, !v1);
}
else
{
++timer_count;
}
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func11()
{
bool v1; // zf

if ( timer_count + 1 > 0x1FFF )
{
v1 = sense_state_2 == 1;
sense_state_2 ^= 1u;
timer_count = 0;
cpu_set_irq_line(0LL, 1LL, !v1);
}
else
{
++timer_count;
}
return ignore_interrupt();
}

original_code:
static int lazercmd_timer(void)
{
 static int sense_state = 0;
 if( ++timer_count >= 64*128 ) {
  timer_count = 0;
  sense_state ^= 1;
  cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0 );
 }
    return ignore_interrupt();
}

canonical_original_code:
static int lazercmd_timer()
{
 static int sense_state = 0;
 if( ++timer_count >= 64*128 ) {
  timer_count = 0;
  sense_state ^= 1;
  cpu_set_irq_line( 0, 1, (sense_state) ? 1 : 0 );
 }
    return ignore_interrupt();
}


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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
result = input_port_1_r(0LL);
break;
case 2:
result = input_port_4_r(0LL);
break;
case 3:
result = input_port_3_r(0LL);
break;
case 4:
result = (timer_count >> 7) & 1 | (timer_count >> 5) & 2 | (timer_count >> 3) & 4 | (timer_count >> 1) & 8u;
break;
case 5:
result = timer_count & 0xF;
break;
case 6:
result = marker_x;
break;
case 7:
result = marker_y;
break;
default:
JUMPOUT(0xA24LL);
}
return result;
}

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

switch ( a1 )
{
case 0:
result = input_port_0_r(0LL);
break;
case 1:
result = input_port_1_r(0LL);
break;
case 2:
result = input_port_4_r(0LL);
break;
case 3:
result = input_port_3_r(0LL);
break;
case 4:
result = (timer_count >> 7) & 1 | (timer_count >> 5) & 2 | (timer_count >> 3) & 4 | (timer_count >> 1) & 8u;
break;
case 5:
result = timer_count & 0xF;
break;
case 6:
result = marker_x;
break;
case 7:
result = marker_y;
break;
default:
JUMPOUT(0xA24LL);
}
return result;
}

original_code:
static data_t lazercmd_hardware_r(offs_t offset)
{
 int data = 0;
 switch (offset)
 {
  case 0:
   data = input_port_0_r(0);
   break;
  case 1:
   data = input_port_1_r(0);
   break;
  case 2:
   data = input_port_4_r(0);
   break;
  case 3:
   data = input_port_3_r(0);
   break;
  case 4:
   data = ((timer_count&0x10)>>1)|((timer_count&0x20)>>3)|((timer_count&0x40)>>5)|((timer_count&0x80)>>7);
   break;
  case 5:
   data = timer_count & 0x0f;
   break;
  case 6:
   data = marker_x;
   break;
  case 7:
   data = marker_y;
   break;
 }
    return data;
}

canonical_original_code:
static unsigned int lazercmd_hardware_r(unsigned int offset)
{
 int data = 0;
 switch (offset)
 {
  case 0:
   data = input_port_0_r(0);
   break;
  case 1:
   data = input_port_1_r(0);
   break;
  case 2:
   data = input_port_4_r(0);
   break;
  case 3:
   data = input_port_3_r(0);
   break;
  case 4:
   data = ((timer_count&0x10)>>1)|((timer_count&0x20)>>3)|((timer_count&0x40)>>5)|((timer_count&0x80)>>7);
   break;
  case 5:
   data = timer_count & 0x0f;
   break;
  case 6:
   data = marker_x;
   break;
  case 7:
   data = marker_y;
   break;
 }
    return data;
}

variable_types:
offset
unsigned int


decompiled_code:
__int64 lazercmd_marker_dirty()
{
__int64 result; // rax
int v1; // esi
int v2; // ecx
int v3; // ecx
int v4; // edx
int v5; // eax
int v6; // ecx
int v7; // esi
int v8; // esi

result = (__int64)&marker_x;
v1 = marker_x;
if ( (unsigned int)(marker_x - 1) <= 0xFF )
{
result = vert_scale(marker_y);
if ( (unsigned int)(result - 10) <= 0xE5 )
{
v3 = v2 >> 3;
v4 = 32 * (((int)result - 10) / 10);
*((_BYTE *)dirtybuffer + v4 + v3) = 1;
v5 = 32 * (((int)result - 7) / 10);
*((_BYTE *)dirtybuffer + v5 + v3) = 1;
v6 = v1 + 9;
v7 = v1 + 2;
if ( v7 < 0 )
v7 = v6;
v8 = v7 >> 3;
result = v8 + v5;
*((_BYTE *)dirtybuffer + v8 + v4) = 1;
*((_BYTE *)dirtybuffer + result) = 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax
int v1; // esi
int v2; // ecx
int v3; // ecx
int v4; // edx
int v5; // eax
int v6; // ecx
int v7; // esi
int v8; // esi

result = (__int64)&marker_x;
v1 = marker_x;
if ( (unsigned int)(marker_x - 1) <= 0xFF )
{
result = func0(marker_y);
if ( (unsigned int)(result - 10) <= 0xE5 )
{
v3 = v2 >> 3;
v4 = 32 * (((int)result - 10) / 10);
*((_BYTE *)dirtybuffer + v4 + v3) = 1;
v5 = 32 * (((int)result - 7) / 10);
*((_BYTE *)dirtybuffer + v5 + v3) = 1;
v6 = v1 + 9;
v7 = v1 + 2;
if ( v7 < 0 )
v7 = v6;
v8 = v7 >> 3;
result = v8 + v5;
*((_BYTE *)dirtybuffer + v8 + v4) = 1;
*((_BYTE *)dirtybuffer + result) = 1;
}
}
return result;
}

variable_types: marker int


decompiled_code:
__int64 sbrkout_select1_r()
{
return (unsigned __int8)(sbrkout_game_switch == 2) << 7;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned __int8)(sbrkout_game_switch == 2) << 7;
}

original_code:
data_t sbrkout_select1_r(offs_t offset)
{
    if (sbrkout_game_switch==0x02)
        return 0x80;
    else return 0x00;
}

canonical_original_code:
unsigned int sbrkout_select1_r(unsigned int offset)
{
    if (sbrkout_game_switch==0x02)
        return 0x80;
    else return 0x00;
}


decompiled_code:
__int64 sbrkout_select2_r()
{
return (unsigned __int8)(sbrkout_game_switch == 1) << 7;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int8)(sbrkout_game_switch == 1) << 7;
}

original_code:
data_t sbrkout_select2_r(offs_t offset)
{
    if (sbrkout_game_switch==0x01)
        return 0x80;
    else return 0x00;
}

canonical_original_code:
unsigned int sbrkout_select2_r(unsigned int offset)
{
    if (sbrkout_game_switch==0x01)
        return 0x80;
    else return 0x00;
}


decompiled_code:
__int64 sbrkout_interrupt()
{
char v0; // al

v0 = input_port_7_r(0LL);
if ( (v0 & 1) != 0 )
{
sbrkout_game_switch = 0;
}
else if ( (v0 & 2) != 0 )
{
sbrkout_game_switch = 1;
}
else if ( (v0 & 4) != 0 )
{
sbrkout_game_switch = 2;
}
return interrupt();
}

canonical_decompiled_code:
__int64 func2()
{
char v0; // al

v0 = input_port_7_r(0LL);
if ( (v0 & 1) != 0 )
{
sbrkout_game_switch = 0;
}
else if ( (v0 & 2) != 0 )
{
sbrkout_game_switch = 1;
}
else if ( (v0 & 4) != 0 )
{
sbrkout_game_switch = 2;
}
return interrupt();
}

original_code:
int sbrkout_interrupt(void)
{
    int game_switch;
    game_switch=input_port_7_r(0);
    if (game_switch & 0x01)
        sbrkout_game_switch=0x00;
    else if (game_switch & 0x02)
        sbrkout_game_switch=0x01;
    else if (game_switch & 0x04)
        sbrkout_game_switch=0x02;
    return interrupt();
}

canonical_original_code:
int sbrkout_interrupt()
{
    int game_switch;
    game_switch=input_port_7_r(0);
    if (game_switch & 0x01)
        sbrkout_game_switch=0x00;
    else if (game_switch & 0x02)
        sbrkout_game_switch=0x01;
    else if (game_switch & 0x04)
        sbrkout_game_switch=0x02;
    return interrupt();
}


decompiled_code:
__int64 __fastcall sbrkout_read_DIPs_r(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 2 )
return input_port_0_r(0LL) & 0xC0;
if ( a1 > 2 )
{
result = 255LL;
if ( a1 == 3 )
result = (unsigned __int8)(4 * input_port_0_r(0LL)) & 0xC0;
}
else if ( a1 )
{
result = (unsigned __int8)(16 * input_port_0_r(0LL)) & 0xC0;
}
else
{
result = (unsigned __int8)((unsigned __int8)input_port_0_r(0LL) << 6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
__int64 result; // rax

if ( a1 == 2 )
return input_port_0_r(0LL) & 0xC0;
if ( a1 > 2 )
{
result = 255LL;
if ( a1 == 3 )
result = (unsigned __int8)(4 * input_port_0_r(0LL)) & 0xC0;
}
else if ( a1 )
{
result = (unsigned __int8)(16 * input_port_0_r(0LL)) & 0xC0;
}
else
{
result = (unsigned __int8)((unsigned __int8)input_port_0_r(0LL) << 6);
}
return result;
}

original_code:
data_t sbrkout_read_DIPs_r(offs_t offset)
{
        switch (offset)
        {
                case 0x00: return ((input_port_0_r(0) & 0x03) << 6);
                case 0x01: return ((input_port_0_r(0) & 0x0C) << 4);
                case 0x02: return ((input_port_0_r(0) & 0xC0) << 0);
                case 0x03: return ((input_port_0_r(0) & 0x30) << 2);
                default: return 0xFF;
        }
}

canonical_original_code:
unsigned int sbrkout_read_DIPs_r(unsigned int offset)
{
        switch (offset)
        {
                case 0x00: return ((input_port_0_r(0) & 0x03) << 6);
                case 0x01: return ((input_port_0_r(0) & 0x0C) << 4);
                case 0x02: return ((input_port_0_r(0) & 0xC0) << 0);
                case 0x03: return ((input_port_0_r(0) & 0x30) << 2);
                default: return 0xFF;
        }
}


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

if ( (_DWORD)a1 )
result = osd_led_w(0LL, 1LL);
else
result = osd_led_w(a1, 0LL);
return result;
}

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

if ( (_DWORD)a1 )
result = osd_led_w(0LL, 1LL);
else
result = osd_led_w(a1, 0LL);
return result;
}

original_code:
void sbrkout_start_1_led_w(offs_t offset,data_t data)
{
    if (offset==0)
        osd_led_w(0,0);
    else
        osd_led_w(0,1);
}

canonical_original_code:
void sbrkout_start_1_led_w(unsigned int offset, unsigned int data)
{
    if (offset==0)
        osd_led_w(0,0);
    else
        osd_led_w(0,1);
}

variable_types:
data
unsigned int


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

if ( a1 )
result = osd_led_w(1LL, 1LL);
else
result = osd_led_w(1LL, 0LL);
return result;
}

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

if ( a1 )
result = osd_led_w(1LL, 1LL);
else
result = osd_led_w(1LL, 0LL);
return result;
}

original_code:
void sbrkout_start_2_led_w(offs_t offset,data_t data)
{
    if (offset==0)
        osd_led_w(1,0);
    else
        osd_led_w(1,1);
}

canonical_original_code:
void sbrkout_start_2_led_w(unsigned int offset, unsigned int data)
{
    if (offset==0)
        osd_led_w(1,0);
    else
        osd_led_w(1,1);
}


decompiled_code:
__int64 sbrkout_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&sbrkout_ol, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

canonical_decompiled_code:
__int64 func6()
{
unsigned int v0; // er12

v0 = 1;
if ( !(unsigned int)generic_vh_start() )
{
v0 = 0;
overlay_create(&sbrkout_ol, 2LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 2));
}
return v0;
}

original_code:
int sbrkout_vh_start(void)
{
 int start_pen = 2;
 if (generic_vh_start()!=0)
  return 1;
 overlay_create(sbrkout_ol, start_pen, Machine->drv->total_colors-start_pen);
 return 0;
}

canonical_original_code:
int sbrkout_vh_start()
{
 int start_pen = 2;
 if (generic_vh_start()!=0)
  return 1;
 overlay_create(sbrkout_ol, start_pen, Machine->drv->total_colors-start_pen);
 return 0;
}


decompiled_code:
__int64 __fastcall sbrkout_vh_screenrefresh(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
unsigned __int8 v4; // dl
char v5; // al
__int64 v6; // rbx
__int64 v7; // rdx
int v8; // ecx
__int64 result; // rax
__int64 v10; // [rsp-28h] [rbp-60h]
__int64 v11; // [rsp-28h] [rbp-60h]

if ( palette_recalc() || a2 )
{
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
else
{
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
v3 = v2;
do
{
while ( !*((_BYTE *)dirtybuffer + v3) )
{
--v2;
--v3;
if ( v2 == -1 )
goto LABEL_8;
}
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(_BYTE *)(videoram + v3--);
v10 = (unsigned int)(8 * (v2 >> 5));
v5 = v2--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
v4 & 0x3F,
v4 >> 7,
0LL,
0LL,
8 * (v5 & 0x1Fu),
v10,
Machine + 776LL,
0LL,
0LL);
}
while ( v2 != -1 );
LABEL_8:
v6 = 4LL;
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v7 = *(_BYTE *)(sbrkout_vert_ram + v6 + 1) >> 7;
v11 = 240 - (unsigned int)*(unsigned __int8 *)(sbrkout_vert_ram + v6);
v8 = *(unsigned __int8 *)(sbrkout_horiz_ram + v6);
v6 -= 2LL;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v7,
1LL,
0LL,
0LL,
(unsigned int)(248 - v8),
v11,
Machine + 776LL,
2LL,
0LL);
}
while ( v6 != -2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
int v2; // ebx
__int64 v3; // rbp
unsigned __int8 v4; // dl
char v5; // al
__int64 v6; // rbx
__int64 v7; // rdx
int v8; // ecx
__int64 result; // rax
__int64 v10; // [rsp-28h] [rbp-60h]
__int64 v11; // [rsp-28h] [rbp-60h]

if ( palette_recalc() || a2 )
{
memset(dirtybuffer, 1, videoram_size);
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
else
{
v2 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_8;
}
v3 = v2;
do
{
while ( !*((_BYTE *)dirtybuffer + v3) )
{
--v2;
--v3;
if ( v2 == -1 )
goto LABEL_8;
}
*((_BYTE *)dirtybuffer + v3) = 0;
v4 = *(_BYTE *)(videoram + v3--);
v10 = (unsigned int)(8 * (v2 >> 5));
v5 = v2--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
v4 & 0x3F,
v4 >> 7,
0LL,
0LL,
8 * (v5 & 0x1Fu),
v10,
Machine + 776LL,
0LL,
0LL);
}
while ( v2 != -1 );
LABEL_8:
v6 = 4LL;
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v7 = *(_BYTE *)(sbrkout_vert_ram + v6 + 1) >> 7;
v11 = 240 - (unsigned int)*(unsigned __int8 *)(sbrkout_vert_ram + v6);
v8 = *(unsigned __int8 *)(sbrkout_horiz_ram + v6);
v6 -= 2LL;
result = drawgfx(
a1,
*(_QWORD *)(Machine + 520LL),
v7,
1LL,
0LL,
0LL,
(unsigned int)(248 - v8),
v11,
Machine + 776LL,
2LL,
0LL);
}
while ( v6 != -2 );
return result;
}

original_code:
void sbrkout_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 int ball;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int code,sx,sy,color;
   dirtybuffer[offs]=0;
   code = videoram[offs] & 0x3f;
   sx = 8*(offs % 32);
   sy = 8*(offs / 32);
   color = ((videoram[offs] & 0x80)>>7);
   drawgfx(tmpbitmap,Machine->gfx[0],
     code, color,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (ball=2;ball>=0;ball--)
 {
  int sx,sy,code;
  sx = 31*8-sbrkout_horiz_ram[ball*2];
  sy = 30*8-sbrkout_vert_ram[ball*2];
  code = ((sbrkout_vert_ram[ball*2+1] & 0x80) >> 7);
  drawgfx(bitmap,Machine->gfx[1],
    code,1,
    0,0,sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void sbrkout_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 int ball;
 if (palette_recalc() || full_refresh)
 {
  memset(dirtybuffer,1,videoram_size);
 }
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int code; int sx; int sy; int color;
   dirtybuffer[offs]=0;
   code = videoram[offs] & 0x3f;
   sx = 8*(offs % 32);
   sy = 8*(offs / 32);
   color = ((videoram[offs] & 0x80)>>7);
   drawgfx(tmpbitmap,Machine->gfx[0],
     code, color,
     0,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (ball=2;ball>=0;ball--)
 {
  int sx; int sy; int code;
  sx = 31*8-sbrkout_horiz_ram[ball*2];
  sy = 30*8-sbrkout_vert_ram[ball*2];
  code = ((sbrkout_vert_ram[ball*2+1] & 0x80) >> 7);
  drawgfx(bitmap,Machine->gfx[1],
    code,1,
    0,0,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: ball int

variable_types: code int

variable_types: color int


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

*(_BYTE *)(sbrkout_sound + a1) = a2;
result = (unsigned int)init_timer;
if ( init_timer )
{
result = timer_set(1093874LL, 0LL, sbrkout_tones_4V);
init_timer = 0;
}
return result;
}

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

*(_BYTE *)(sbrkout_sound + a1) = a2;
result = (unsigned int)init_timer;
if ( init_timer )
{
result = timer_set(1093874LL, 0LL, sbrkout_tones_4V);
init_timer = 0;
}
return result;
}

original_code:
static void sbrkout_dac_w(offs_t offset,data_t data)
{
 sbrkout_sound[offset]=data;
 if (init_timer)
 {
  timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
  init_timer=0;
 }
}

canonical_original_code:
static void sbrkout_dac_w(unsigned int offset, unsigned int data)
{
 sbrkout_sound[offset]=data;
 if (init_timer)
 {
  timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
  init_timer=0;
 }
}


decompiled_code:
__int64 sbrkout_tones_4V()
{
if ( ((unsigned __int8)vlines_0 & *sbrkout_sound) != 0 )
DAC_data_w(0LL, 255LL);
else
DAC_data_w(0LL, 0LL);
vlines_0 = (vlines_0 + 1) % 16;
return timer_set(1093874LL, 0LL, sbrkout_tones_4V);
}

canonical_decompiled_code:
__int64 func10()
{
if ( ((unsigned __int8)vlines_0 & *sbrkout_sound) != 0 )
DAC_data_w(0LL, 255LL);
else
DAC_data_w(0LL, 0LL);
vlines_0 = (vlines_0 + 1) % 16;
return timer_set(1093874LL, 0LL, sbrkout_tones_4V);
}

original_code:
static void sbrkout_tones_4V(int foo)
{
 static int vlines=0;
 if ((*sbrkout_sound) & vlines)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 vlines = (vlines+1) % 16;
 timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
}

canonical_original_code:
static void sbrkout_tones_4V(int foo)
{
 static int vlines = 0;
 if ((*sbrkout_sound) & vlines)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 vlines = (vlines+1) % 16;
 timer_set (((timer_tm)(((float)(4.075/4)*(float)((1<<30)))/(float)1000)), 0, sbrkout_tones_4V);
}

variable_types: foo int

variable_types: vlines int


decompiled_code:
__int64 sbrkout_irq_w()
{
return cpu_cause_interrupt(0LL, 1LL);
}

canonical_decompiled_code:
__int64 func11()
{
return cpu_cause_interrupt(0LL, 1LL);
}

original_code:
void sbrkout_irq_w(offs_t offset,data_t data)
{
        cpu_cause_interrupt(0,1);
}

canonical_original_code:
void sbrkout_irq_w(unsigned int offset, unsigned int data)
{
        cpu_cause_interrupt(0,1);
}


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

if ( a1 )
result = osd_led_w(2LL, 0LL);
else
result = osd_led_w(2LL, 1LL);
return result;
}

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

if ( a1 )
result = osd_led_w(2LL, 0LL);
else
result = osd_led_w(2LL, 1LL);
return result;
}

original_code:
void sbrkout_serve_led_w(offs_t offset,data_t data)
{
    if (offset==0)
        osd_led_w(2,1);
    else
        osd_led_w(2,0);
}

canonical_original_code:
void sbrkout_serve_led_w(unsigned int offset, unsigned int data)
{
    if (offset==0)
        osd_led_w(2,1);
    else
        osd_led_w(2,0);
}


decompiled_code:
void *__fastcall init_palette(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, void *a2)
{
*(_DWORD *)a1 = -16777216;
*(_WORD *)(a1 + 4) = -1;
return memcpy(a2, &colortable, (size_t)&unk_10004);
}

original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable,const unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}

canonical_original_code:
static void init_palette(unsigned char *game_palette, unsigned short *game_colortable, unsigned char *color_prom)
{
 memcpy(game_palette,palette,sizeof(palette));
 memcpy(game_colortable,colortable,sizeof(colortable));
}


decompiled_code:
__int64 __fastcall geebee_init_palette(__int64 a1, __m128i *a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&LC0);
*(_BYTE *)(a1 + 8) = 127;
result = 0x7F7FFFFFFF000000LL;
*(_QWORD *)a1 = 0x7F7FFFFFFF000000LL;
*a2 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __m128i *a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&LC0);
*(_BYTE *)(a1 + 8) = 127;
result = 0x7F7FFFFFFF000000LL;
*(_QWORD *)a1 = 0x7F7FFFFFFF000000LL;
*a2 = v2;
return result;
}

original_code:
void geebee_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, const unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, geebee_colortable, sizeof (geebee_colortable));
}

canonical_original_code:
void geebee_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, geebee_colortable, sizeof (geebee_colortable));
}


decompiled_code:
__int64 __fastcall navalone_init_palette(__int64 a1, __m128i *a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&LC1);
*(_BYTE *)(a1 + 8) = 127;
result = 0x7F7FFFFFFF000000LL;
*(_QWORD *)a1 = 0x7F7FFFFFFF000000LL;
*a2 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __m128i *a2)
{
__m128i v2; // xmm0
__int64 result; // rax

v2 = _mm_load_si128((const __m128i *)&LC1);
*(_BYTE *)(a1 + 8) = 127;
result = 0x7F7FFFFFFF000000LL;
*(_QWORD *)a1 = 0x7F7FFFFFFF000000LL;
*a2 = v2;
return result;
}

original_code:
void navalone_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, const unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, navalone_colortable, sizeof (navalone_colortable));
}

canonical_original_code:
void navalone_init_palette(unsigned char *sys_palette, unsigned short *sys_colortable, unsigned char *color_prom)
{
 memcpy(sys_palette, palette, sizeof (palette));
 memcpy(sys_colortable, navalone_colortable, sizeof (navalone_colortable));
}


decompiled_code:
__int64 __fastcall geebee_plot(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

result = Machine;
if ( (int)a2 <= *(_DWORD *)(Machine + 780LL)
&& (int)a3 <= *(_DWORD *)(Machine + 788LL)
&& (int)a3 >= *(_DWORD *)(Machine + 784LL)
&& *(_DWORD *)(Machine + 776LL) <= (int)a2 )
{
result = plot_pixel(a1, a2, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL));
}
return result;
}

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

result = Machine;
if ( (int)a2 <= *(_DWORD *)(Machine + 780LL)
&& (int)a3 <= *(_DWORD *)(Machine + 788LL)
&& (int)a3 >= *(_DWORD *)(Machine + 784LL)
&& *(_DWORD *)(Machine + 776LL) <= (int)a2 )
{
result = plot_pixel(a1, a2, a3, *(unsigned __int16 *)(*(_QWORD *)(Machine + 792LL) + 2LL));
}
return result;
}

original_code:
static inline void geebee_plot(struct osd_bitmap *bitmap, int x, int y)
{
 struct rectangle r = Machine->visible_area;
 if (x >= r.min_x && x <= r.max_x && y >= r.min_y && y <= r.max_y)
  plot_pixel(bitmap,x,y,Machine->pens[1]);
}

variable_types: x int

variable_types: y int

variable_types: struct rectangle { int min_x; int min_y; }


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

result = (unsigned int)(volume - 1);
if ( volume - 1 < 0 )
result = 0LL;
volume = result;
return result;
}

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

result = (unsigned int)(volume - 1);
if ( volume - 1 < 0 )
result = 0LL;
volume = result;
return result;
}

original_code:
static void volume_decay(int param)
{
 if( --volume < 0 )
  volume = 0;
}

variable_types: param int


decompiled_code:
__int64 __fastcall geebee_sound_update(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax
int v4; // ecx
int v5; // er8
char v6; // r12
int v7; // er10
__int64 v8; // r14
int v10; // esi
__int64 v11; // r13
unsigned __int16 *v12; // rbp
int v13; // edx
int v14; // eax
int v15; // edx

result = a3;
if ( a3 )
{
v4 = vcarry_1;
v5 = vcount_0;
v6 = 0;
v7 = sound_latch & 7;
v8 = Machine;
v10 = noise;
v11 = a2 + 2LL * a3;
result = 0LL;
v12 = (unsigned __int16 *)((char *)decay + 2 * volume);
v13 = sound_signal;
do
{
a2 += 2LL;
*(_WORD *)(a2 - 2) = v13;
v4 -= 8000;
if ( v4 < 0 )
{
v14 = v5 + 1;
do
{
v4 += *(_DWORD *)(v8 + 836);
v5 = v14;
if ( (v14 & 3) == 2 )
{
v6 = 1;
v15 = ((unsigned __int8)v10 ^ (unsigned __int8)(v10 >> 10)) & 1;
v10 = (unsigned __int16)(2 * v10);
if ( !v15 )
v10 |= 1u;
}
switch ( v7 )
{
case 0:
v13 = v14 & 4;
if ( (v14 & 4) != 0 )
goto LABEL_8;
break;
case 1:
v13 = v14 & 8;
if ( (v14 & 8) != 0 )
goto LABEL_8;
break;
case 2:
v13 = v14 & 0x10;
if ( (v14 & 0x10) != 0 )
goto LABEL_8;
break;
case 3:
v13 = v14 & 0x20;
if ( (v14 & 0x20) != 0 )
goto LABEL_8;
break;
case 4:
v13 = 0;
if ( (v14 & 0x11) == 0 )
goto LABEL_8;
break;
case 5:
v13 = 0;
if ( (v14 & 0x22) == 0 )
goto LABEL_8;
break;
case 6:
v13 = 0;
if ( (v14 & 0x44) == 0 )
goto LABEL_8;
break;
default:
v13 = v10 & 0x8000;
if ( (v10 & 0x8000) != 0 )
LABEL_8:
v13 = *v12;
break;
}
++v14;
}
while ( v4 < 0 );
result = 1LL;
}
}
while ( v11 != a2 );
vcarry_1 = v4;
if ( (_BYTE)result )
{
vcount_0 = v5;
if ( v6 )
noise = v10;
sound_signal = v13;
}
else if ( v6 )
{
noise = v10;
}
}
return result;
}

original_code:
static void geebee_sound_update(int param, INT16 *buffer, int length)
{
    static int vcarry = 0;
    static int vcount = 0;
    while (length--)
    {
  *buffer++ = sound_signal;
  vcarry -= 18432000 / 3 / 2 / 384;
        while (vcarry < 0)
        {
            vcarry += Machine->sample_rate;
            vcount++;
   if ((vcount & 3) == 2)
   {
    if ((noise & 1) == ((noise >> 10) & 1))
     noise = ((noise << 1) & 0xfffe) | 1;
    else
     noise = (noise << 1) & 0xfffe;
   }
            switch (sound_latch & 7)
            {
            case 0:
    sound_signal = (vcount & 0x04) ? decay[volume] : 0;
                break;
            case 1:
    sound_signal = (vcount & 0x08) ? decay[volume] : 0;
                break;
            case 2:
    sound_signal = (vcount & 0x10) ? decay[volume] : 0;
                break;
            case 3:
    sound_signal = (vcount & 0x20) ? decay[volume] : 0;
                break;
            case 4:
    sound_signal = !(vcount & 0x01) && !(vcount & 0x10) ? decay[volume] : 0;
                break;
            case 5:
    sound_signal = !(vcount & 0x02) && !(vcount & 0x20) ? decay[volume] : 0;
                break;
            case 6:
    sound_signal = !(vcount & 0x04) && !(vcount & 0x40) ? decay[volume] : 0;
                break;
   default:
                sound_signal = (noise & 0x8000) ? decay[volume] : 0;
            }
        }
    }
}

canonical_original_code:
static void geebee_sound_update(int param, short *buffer, int length)
{
    static int vcarry = 0;
    static int vcount = 0;
    while (length--)
    {
  *buffer++ = sound_signal;
  vcarry -= 18432000 / 3 / 2 / 384;
        while (vcarry < 0)
        {
            vcarry += Machine->sample_rate;
            vcount++;
   if ((vcount & 3) == 2)
   {
    if ((noise & 1) == ((noise >> 10) & 1))
     noise = ((noise << 1) & 0xfffe) | 1;
    else
     noise = (noise << 1) & 0xfffe;
   }
            switch (sound_latch & 7)
            {
            case 0:
    sound_signal = (vcount & 0x04) ? decay[volume] : 0;
                break;
            case 1:
    sound_signal = (vcount & 0x08) ? decay[volume] : 0;
                break;
            case 2:
    sound_signal = (vcount & 0x10) ? decay[volume] : 0;
                break;
            case 3:
    sound_signal = (vcount & 0x20) ? decay[volume] : 0;
                break;
            case 4:
    sound_signal = !(vcount & 0x01) && !(vcount & 0x10) ? decay[volume] : 0;
                break;
            case 5:
    sound_signal = !(vcount & 0x02) && !(vcount & 0x20) ? decay[volume] : 0;
                break;
            case 6:
    sound_signal = !(vcount & 0x04) && !(vcount & 0x40) ? decay[volume] : 0;
                break;
   default:
                sound_signal = (noise & 0x8000) ? decay[volume] : 0;
            }
        }
    }
}

variable_types:
buffer
short *

variable_types: length int

variable_types: vcarry int

variable_types: vcount int


decompiled_code:
__int64 geebee_interrupt()
{
cpu_set_irq_line(0LL, 0LL, 3LL);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func6()
{
cpu_set_irq_line(0LL, 0LL, 3LL);
return ignore_interrupt();
}

original_code:
int geebee_interrupt(void)
{
 cpu_set_irq_line(0, 0, 3);
    return ignore_interrupt();
}

canonical_original_code:
int geebee_interrupt()
{
 cpu_set_irq_line(0, 0, 3);
    return ignore_interrupt();
}


decompiled_code:
__int64 kaitei_interrupt()
{
cpu_set_irq_line(0LL, 0LL, 2LL);
return ignore_interrupt();
}

canonical_decompiled_code:
__int64 func7()
{
cpu_set_irq_line(0LL, 0LL, 2LL);
return ignore_interrupt();
}

original_code:
int kaitei_interrupt(void)
{
 cpu_set_irq_line(0, 0, 2);
    return ignore_interrupt();
}

canonical_original_code:
int kaitei_interrupt()
{
 cpu_set_irq_line(0, 0, 2);
    return ignore_interrupt();
}


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

LODWORD(result) = readinputport(a1 & 3);
if ( (a1 & 3) != 2 )
return (unsigned int)result;
if ( (result & 2) != 0 )
return (unsigned int)readinputport(5LL) | (unsigned int)result;
return (unsigned int)readinputport(4LL) | (unsigned int)result;
}

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

LODWORD(result) = readinputport(a1 & 3);
if ( (a1 & 3) != 2 )
return (unsigned int)result;
if ( (result & 2) != 0 )
return (unsigned int)readinputport(5LL) | (unsigned int)result;
return (unsigned int)readinputport(4LL) | (unsigned int)result;
}

original_code:
data_t geebee_in_r(offs_t offset)
{
 int data = readinputport(offset & 3);
 if ((offset & 3) == 2)
 {
  if (data & 0x02)
   data |= readinputport(5);
  else
   data |= readinputport(4);
 }
 return data;
}

canonical_original_code:
unsigned int geebee_in_r(unsigned int offset)
{
 int data = readinputport(offset & 3);
 if ((offset & 3) == 2)
 {
  if (data & 0x02)
   data |= readinputport(5);
  else
   data |= readinputport(4);
 }
 return data;
}

variable_types:
offset
unsigned int

variable_types: data int


decompiled_code:
__int64 __fastcall navalone_in_r(char a1)
{
__int64 v1; // rdi
__int64 result; // rax
unsigned int v3; // ebx
char v4; // al
bool v5; // zf

v1 = a1 & 3;
result = readinputport(v1);
v3 = result;
if ( (_DWORD)v1 == 3 )
{
v4 = readinputport(4LL);
if ( (v4 & 1) != 0 )
v3 = 160;
v5 = (v4 & 2) == 0;
result = 16LL;
if ( v5 )
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(char a1)
{
__int64 v1; // rdi
__int64 result; // rax
unsigned int v3; // ebx
char v4; // al
bool v5; // zf

v1 = a1 & 3;
result = readinputport(v1);
v3 = result;
if ( (_DWORD)v1 == 3 )
{
v4 = readinputport(4LL);
if ( (v4 & 1) != 0 )
v3 = 160;
v5 = (v4 & 2) == 0;
result = 16LL;
if ( v5 )
result = v3;
}
return result;
}

original_code:
data_t navalone_in_r(offs_t offset)
{
    int data = readinputport(offset & 3);
 if ((offset & 3) == 3)
 {
  int joy = readinputport(4);
  if( joy & 1 ) data = 0xa0;
  if( joy & 2 ) data = 0x10;
 }
    return data;
}

canonical_original_code:
unsigned int navalone_in_r(unsigned int offset)
{
    int data = readinputport(offset & 3);
 if ((offset & 3) == 3)
 {
  int joy = readinputport(4);
  if( joy & 1 ) data = 0xa0;
  if( joy & 2 ) data = 0x10;
 }
    return data;
}

variable_types: joy int


decompiled_code:
__int64 geebee_vh_start()
{
unsigned int v0; // er12

v0 = 1;
if ( (unsigned int)generic_vh_start() )
return v0;
v0 = 0;
if ( (readinputport(2LL) & 1) != 0 )
return v0;
overlay_create(&geebee_overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
return 0LL;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v0; // er12

v0 = 1;
if ( (unsigned int)generic_vh_start() )
return v0;
v0 = 0;
if ( (readinputport(2LL) & 1) != 0 )
return v0;
overlay_create(&geebee_overlay, 3LL, (unsigned int)(*(_DWORD *)(*(_QWORD *)(Machine + 824LL) + 696LL) - 3));
return 0LL;
}

original_code:
int geebee_vh_start(void)
{
 if( generic_vh_start() )
  return 1;
 if( (readinputport(2) & 0x01) == 0 )
 {
  overlay_create(geebee_overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}

canonical_original_code:
int geebee_vh_start()
{
 if( generic_vh_start() )
  return 1;
 if( (readinputport(2) & 0x01) == 0 )
 {
  overlay_create(geebee_overlay, 3, Machine->drv->total_colors-3);
 }
 return 0;
}


decompiled_code:
__int64 geebee_sh_update()
{
return stream_update((unsigned int)channel, 0LL);
}

canonical_decompiled_code:
__int64 func13()
{
return stream_update((unsigned int)channel, 0LL);
}

original_code:
void geebee_sh_update(void)
{
 stream_update(channel,0);
}

canonical_original_code:
void geebee_sh_update()
{
 stream_update(channel,0);
}


decompiled_code:
__int64 geebee_sh_start()
{
char *v0; // rax
char *v1; // rbp
int i; // ebx
double v3; // xmm0_8

v0 = (char *)malloc(0x10000uLL);
decay = v0;
if ( !v0 )
return 1LL;
v1 = v0 + 65534;
for ( i = 0; i != 0x8000; ++i )
{
v1 -= 2;
v3 = (double)i * 0.000244140625;
*((_WORD *)v1 + 1) = (int)(32767.0 / exp(v3));
}
channel = stream_init("GeeBee", 100LL, *(unsigned int *)(Machine + 836LL), 0LL, geebee_sound_update);
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
char *v0; // rax
char *v1; // rbp
int i; // ebx
double v3; // xmm0_8

v0 = (char *)malloc(0x10000uLL);
decay = v0;
if ( !v0 )
return 1LL;
v1 = v0 + 65534;
for ( i = 0; i != 0x8000; ++i )
{
v1 -= 2;
v3 = (double)i * 0.000244140625;
*((_WORD *)v1 + 1) = (int)(32767.0 / exp(v3));
}
channel = stream_init("GeeBee", 100LL, *(unsigned int *)(Machine + 836LL), 0LL, geebee_sound_update);
return 0LL;
}

original_code:
int geebee_sh_start(const struct MachineSound *msound)
{
 int i;
 decay = (UINT16 *)malloc(32768 * sizeof(INT16));
 if( !decay )
  return 1;
    for( i = 0; i < 0x8000; i++ )
  decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096));
 channel = stream_init("GeeBee", 100, Machine->sample_rate, 0, geebee_sound_update);
    return 0;
}

canonical_original_code:
int geebee_sh_start(struct MachineSound *msound)
{
 int i;
 decay = (unsigned short *)malloc(32768 * sizeof(INT16));
 if( !decay )
  return 1;
    for( i = 0; i < 0x8000; i++ )
  decay[0x7fff-i] = (INT16) (0x7fff/exp(1.0*i/4096));
 channel = stream_init("GeeBee", 100, Machine->sample_rate, 0, geebee_sound_update);
    return 0;
}

variable_types: struct MachineSound { int sound_type; void *sound_interface; } *

variable_types: i int


decompiled_code:
void geebee_sh_stop()
{
if ( volume_timer )
timer_remove();
volume_timer = 0LL;
if ( decay )
free(decay);
decay = 0LL;
}

canonical_decompiled_code:
void func15()
{
if ( volume_timer )
timer_remove();
volume_timer = 0LL;
if ( decay )
free(decay);
decay = 0LL;
}

original_code:
void geebee_sh_stop(void)
{
 if( volume_timer )
  timer_remove(volume_timer);
 volume_timer = ((void *)0);
    if( decay )
  free(decay);
 decay = ((void *)0);
}

canonical_original_code:
void geebee_sh_stop()
{
 if( volume_timer )
  timer_remove(volume_timer);
 volume_timer = ((void *)0);
    if( decay )
  free(decay);
 decay = ((void *)0);
}


decompiled_code:
// attributes: thunk
_BOOL8 sos_vh_start()
{
return navalone_vh_start_localalias();
}

canonical_decompiled_code:
_BOOL8 func16()
{
return func10();
}

original_code:
int sos_vh_start(void)
{
 if( generic_vh_start() )
  return 1;
 return 0;
}

canonical_original_code:
int sos_vh_start()
{
 if( generic_vh_start() )
  return 1;
 return 0;
}


decompiled_code:
// attributes: thunk
_BOOL8 kaitei_vh_start()
{
return navalone_vh_start_localalias();
}

canonical_decompiled_code:
_BOOL8 func17()
{
return func10();
}

original_code:
int kaitei_vh_start(void)
{
 if( generic_vh_start() )
 return 1;
 return 0;
}

canonical_original_code:
int kaitei_vh_start()
{
 if( generic_vh_start() )
 return 1;
 return 0;
}


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

stream_update((unsigned int)channel, 0LL);
sound_latch = a2;
volume = 0x7FFF;
noise = 0;
if ( (a2 & 8) != 0 )
{
if ( volume_timer )
timer_remove(volume_timer);
result = timer_pulse(4606LL, 0LL, volume_decay);
volume_timer = result;
}
else
{
if ( volume_timer )
timer_remove(volume_timer);
result = timer_pulse(9522LL, 0LL, volume_decay);
volume_timer = result;
}
return result;
}

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

stream_update((unsigned int)channel, 0LL);
sound_latch = a2;
volume = 0x7FFF;
noise = 0;
if ( (a2 & 8) != 0 )
{
if ( volume_timer )
timer_remove(volume_timer);
result = timer_pulse(4606LL, 0LL, volume_decay);
volume_timer = result;
}
else
{
if ( volume_timer )
timer_remove(volume_timer);
result = timer_pulse(9522LL, 0LL, volume_decay);
volume_timer = result;
}
return result;
}

original_code:
void geebee_sound_w(offs_t offset,data_t data)
{
 stream_update(channel,0);
 sound_latch = data;
 volume = 0x7fff;
 noise = 0x0000;
 if( sound_latch & 8 )
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.14058))), 0, volume_decay);
 }
 else
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.2906))), 0, volume_decay);
    }
}

canonical_original_code:
void geebee_sound_w(unsigned int offset, unsigned int data)
{
 stream_update(channel,0);
 sound_latch = data;
 volume = 0x7fff;
 noise = 0x0000;
 if( sound_latch & 8 )
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.14058))), 0, volume_decay);
 }
 else
 {
  if( volume_timer )
   timer_remove(volume_timer);
  volume_timer = timer_pulse(((1<<30) / ((timer_tm)(32768/0.2906))), 0, volume_decay);
    }
}

variable_types:
data
unsigned int


original_code:
void aso_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom){
 int i;
 int num_colors = 1024;
 for( i=0; i<num_colors; i++ ){
  int bit0=0,bit1,bit2,bit3;
  colortable[i] = i;
  bit0 = (color_prom[2*num_colors] >> 2) & 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[2*num_colors] >> 1) & 0x01;
  bit1 = (color_prom[num_colors] >> 2) & 0x01;
  bit2 = (color_prom[num_colors] >> 3) & 0x01;
  bit3 = (color_prom[0] >> 0) & 0x01;
  *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*num_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*num_colors] >> 3) & 0x01;
  bit2 = (color_prom[num_colors] >> 0) & 0x01;
  bit3 = (color_prom[num_colors] >> 1) & 0x01;
  *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

canonical_original_code:
void aso_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable, unsigned char *color_prom){
 int i;
 int num_colors = 1024;
 for( i=0; i<num_colors; i++ ){
  int bit0 = 0; int bit1; int bit2; int bit3;
  colortable[i] = i;
  bit0 = (color_prom[2*num_colors] >> 2) & 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[2*num_colors] >> 1) & 0x01;
  bit1 = (color_prom[num_colors] >> 2) & 0x01;
  bit2 = (color_prom[num_colors] >> 3) & 0x01;
  bit3 = (color_prom[0] >> 0) & 0x01;
  *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  bit0 = (color_prom[2*num_colors] >> 0) & 0x01;
  bit1 = (color_prom[2*num_colors] >> 3) & 0x01;
  bit2 = (color_prom[num_colors] >> 0) & 0x01;
  bit3 = (color_prom[num_colors] >> 1) & 0x01;
  *palette++ = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
  color_prom++;
 }
}

variable_types:
palette
unsigned char *

variable_types:
colortable
unsigned short *


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

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

original_code: static data_t shared_auxram_r(offs_t offset){ return shared_auxram[offset]; }

canonical_original_code: static unsigned int shared_auxram_r(unsigned int offset){ return shared_auxram[offset]; }


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

result = (unsigned int)snk_soundcommand;
snk_soundcommand = 0;
return result;
}

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

result = (unsigned int)snk_soundcommand;
snk_soundcommand = 0;
return result;
}

original_code:
static data_t snk_soundcommand_r(offs_t offset)
{
 int val = snk_soundcommand;
 snk_soundcommand = 0;
 return val;
}

canonical_original_code:
static unsigned int snk_soundcommand_r(unsigned int offset)
{
 int val = snk_soundcommand;
 snk_soundcommand = 0;
 return val;
}

variable_types: val int


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

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

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

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


decompiled_code:
__int64 aso_vh_start()
{
scrollx_base = -16;
return common_vh_start();
}

canonical_decompiled_code:
__int64 func9()
{
scrollx_base = -16;
return func8();
}

original_code:
int aso_vh_start( void ){
 scrollx_base = -16;
 return common_vh_start();
}

canonical_original_code:
int aso_vh_start(){
 scrollx_base = -16;
 return common_vh_start();
}


decompiled_code:
__int64 hal21_vh_start()
{
scrollx_base = 240;
return common_vh_start();
}

canonical_decompiled_code:
__int64 func10()
{
scrollx_base = 240;
return func8();
}

original_code:
int hal21_vh_start( void ){
 scrollx_base = 240;
 return common_vh_start();
}

canonical_original_code:
int hal21_vh_start(){
 scrollx_base = 240;
 return common_vh_start();
}


decompiled_code:
void aso_vh_stop()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

canonical_decompiled_code:
void func11()
{
bitmap_free(tmpbitmap);
free(dirtybuffer);
}

original_code:
void aso_vh_stop( void ){
 bitmap_free( tmpbitmap );
 free( dirtybuffer );
}

canonical_original_code:
void aso_vh_stop(){
 bitmap_free( tmpbitmap );
 free( dirtybuffer );
}


decompiled_code:
__int64 __fastcall aso_draw_background(__int64 a1, int a2, int a3, int a4, unsigned int a5, __int64 a6)
{
_QWORD *v8; // rdx
unsigned __int64 v9; // rdi
int v10; // ebx
__int64 i; // r15
__int64 v13; // [rsp+8h] [rbp-50h]
int v15; // [rsp+18h] [rbp-40h] BYREF
int v16[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v16[0] = a2;
v15 = a3;
v13 = Machine + 776LL;
if ( old_color_1 != a5 || old_bank_0 != a4 )
{
v8 = dirtybuffer;
v9 = (unsigned __int64)dirtybuffer + 8;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v8[511] = 0x101010101010101LL;
memset((void *)(v9 & 0xFFFFFFFFFFFFFFF8LL), 1u, 8 * (((unsigned int)v8 - (v9 & 0xFFFFFFF8) + 4096) >> 3));
old_bank_0 = a4;
old_color_1 = a5;
}
v10 = a4 << 8;
for ( i = 0LL; i != 4096; ++i )
{
while ( !*((_BYTE *)dirtybuffer + i) )
{
if ( ++i == 4096 )
return copyscrollbitmap(a1, tmpbitmap, 1LL, v16, 1LL, &v15, v13, 0LL, 0LL);
}
drawgfx(
tmpbitmap,
a6,
v10 + (unsigned int)*(unsigned __int8 *)(videoram + i),
a5,
0LL,
0LL,
(unsigned int)(8 * ((int)i >> 6)),
8 * (unsigned int)(i & 0x3F),
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + i) = 0;
}
return copyscrollbitmap(a1, tmpbitmap, 1LL, v16, 1LL, &v15, v13, 0LL, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3, int a4, unsigned int a5, __int64 a6)
{
_QWORD *v8; // rdx
unsigned __int64 v9; // rdi
int v10; // ebx
__int64 i; // r15
__int64 v13; // [rsp+8h] [rbp-50h]
int v15; // [rsp+18h] [rbp-40h] BYREF
int v16[15]; // [rsp+1Ch] [rbp-3Ch] BYREF

v16[0] = a2;
v15 = a3;
v13 = Machine + 776LL;
if ( old_color_1 != a5 || old_bank_0 != a4 )
{
v8 = dirtybuffer;
v9 = (unsigned __int64)dirtybuffer + 8;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v8[511] = 0x101010101010101LL;
memset((void *)(v9 & 0xFFFFFFFFFFFFFFF8LL), 1u, 8 * (((unsigned int)v8 - (v9 & 0xFFFFFFF8) + 4096) >> 3));
old_bank_0 = a4;
old_color_1 = a5;
}
v10 = a4 << 8;
for ( i = 0LL; i != 4096; ++i )
{
while ( !*((_BYTE *)dirtybuffer + i) )
{
if ( ++i == 4096 )
return copyscrollbitmap(a1, tmpbitmap, 1LL, v16, 1LL, &v15, v13, 0LL, 0LL);
}
drawgfx(
tmpbitmap,
a6,
v10 + (unsigned int)*(unsigned __int8 *)(videoram + i),
a5,
0LL,
0LL,
(unsigned int)(8 * ((int)i >> 6)),
8 * (unsigned int)(i & 0x3F),
0LL,
0LL,
0LL);
*((_BYTE *)dirtybuffer + i) = 0;
}
return copyscrollbitmap(a1, tmpbitmap, 1LL, v16, 1LL, &v15, v13, 0LL, 0LL);
}

original_code:
static void aso_draw_background(
  struct osd_bitmap *bitmap,
  int scrollx, int scrolly,
  int bank, int color,
  const struct GfxElement *gfx )
{
 const struct rectangle *clip = &Machine->visible_area;
 int offs;
 static int old_bank, old_color;
 if( color!=old_color || bank!=old_bank ){
  memset( dirtybuffer, 1, 64*64 );
  old_bank = bank;
  old_color = color;
 }
 for( offs=0; offs<64*64; offs++ ){
  if( dirtybuffer[offs] ){
   int tile_number = videoram[offs]+bank*256;
   int sy = (offs%64)*8;
   int sx = (offs/64)*8;
   drawgfx( tmpbitmap,gfx,
    tile_number,
    color,
    0,0,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,
  1,&scrollx,1,&scrolly,
  clip,
  TRANSPARENCY_NONE,0);
}

canonical_original_code:
static void aso_draw_background(struct osd_bitmap *bitmap, int scrollx, int scrolly, int bank, int color, struct GfxElement *gfx)
{
 struct rectangle *clip = &Machine->visible_area;
 int offs;
 static int old_bank; static int old_color;
 if( color!=old_color || bank!=old_bank ){
  memset( dirtybuffer, 1, 64*64 );
  old_bank = bank;
  old_color = color;
 }
 for( offs=0; offs<64*64; offs++ ){
  if( dirtybuffer[offs] ){
   int tile_number = videoram[offs]+bank*256;
   int sy = (offs%64)*8;
   int sx = (offs/64)*8;
   drawgfx( tmpbitmap,gfx,
    tile_number,
    color,
    0,0,
    sx,sy,
    0,TRANSPARENCY_NONE,0);
   dirtybuffer[offs] = 0;
  }
 }
 copyscrollbitmap(bitmap,tmpbitmap,
  1,&scrollx,1,&scrolly,
  clip,
  TRANSPARENCY_NONE,0);
}

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

variable_types: scrollx int

variable_types: scrolly int

variable_types: bank int

variable_types: color int

variable_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; } *

variable_types: struct rectangle { int min_x; int min_y; } *

variable_types: offs int

variable_types: sy int

variable_types: sx int


decompiled_code:
__int64 __fastcall snk_soundcommand_w(__int64 a1, int a2)
{
snk_soundcommand = a2;
return cpu_cause_interrupt(2LL, 4294966296LL);
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int a2)
{
snk_soundcommand = a2;
return cpu_cause_interrupt(2LL, 4294966296LL);
}

original_code:
static void snk_soundcommand_w(offs_t offset,data_t data){
 snk_soundcommand = data;
 cpu_cause_interrupt( 2, -1000 );
}

canonical_original_code:
static void snk_soundcommand_w(unsigned int offset, unsigned int data){
 snk_soundcommand = data;
 cpu_cause_interrupt( 2, -1000 );
}

variable_types:
offset
unsigned int


original_code:
void aso_draw_sprites(
  struct osd_bitmap *bitmap,
  int xscroll, int yscroll,
  const struct GfxElement *gfx
){
 const unsigned char *source = spriteram;
 const unsigned char *finish = source+60*4;
 struct rectangle clip = Machine->visible_area;
 while( source<finish ){
  int attributes = source[3];
  int tile_number = source[1];
  int sy = source[0] + ((attributes&0x10)?256:0) - yscroll;
  int sx = source[2] + ((attributes&0x80)?256:0) - xscroll;
  int color = attributes&0xf;
  if( !(attributes&0x20) ) tile_number += 512;
  if( attributes&0x40 ) tile_number += 256;
  drawgfx(bitmap,gfx,
   tile_number,
   color,
   0,0,
   (256-sx)&0x1ff,sy&0x1ff,
   &clip,TRANSPARENCY_PEN,7);
  source+=4;
 }
}

canonical_original_code:
void aso_draw_sprites(struct osd_bitmap *bitmap, int xscroll, int yscroll, struct GfxElement *gfx){
 unsigned char *source = spriteram;
 unsigned char *finish = source+60*4;
 struct rectangle clip = Machine->visible_area;
 while( source<finish ){
  int attributes = source[3];
  int tile_number = source[1];
  int sy = source[0] + ((attributes&0x10)?256:0) - yscroll;
  int sx = source[2] + ((attributes&0x80)?256:0) - xscroll;
  int color = attributes&0xf;
  if( !(attributes&0x20) ) tile_number += 512;
  if( attributes&0x40 ) tile_number += 256;
  drawgfx(bitmap,gfx,
   tile_number,
   color,
   0,0,
   (256-sx)&0x1ff,sy&0x1ff,
   &clip,TRANSPARENCY_PEN,7);
  source+=4;
 }
}

variable_types: xscroll int

variable_types: yscroll int

variable_types:
source
unsigned char *

variable_types:
finish
unsigned char *

variable_types: struct rectangle { int min_x; int min_y; }

variable_types: attributes int

user_defined_types: struct GfxElement { int width; unsigned int total_elements; int color_granularity; unsigned short *colortable; int total_colors; unsigned int *pen_usage; unsigned char *gfxdata; int line_modulo; int char_modulo; }


decompiled_code:
__int64 __fastcall aso_vh_screenrefresh(__int64 a1)
{
__int64 v1; // r13
int v2; // ebx
int v3; // esi
int v4; // edx
__int16 v5; // ax
unsigned int v6; // ebx

v1 = memory_region(129LL);
v2 = hal21_vreg[1];
v3 = hal21_vreg[5] + scrollx_base;
if ( (v2 & 2) == 0 )
v3 += 256;
aso_draw_background(
a1,
-v3,
8 - (hal21_vreg[4] + ((16 * (unsigned __int16)hal21_vreg[1]) & 0x100)),
LOBYTE(hal21_vreg[0]) >> 4,
hal21_vreg[0] & 0xF,
*(_QWORD *)(Machine + 520LL));
v4 = hal21_vreg[2] + ((32 * (_WORD)v2) & 0x100) + 9;
v5 = v2;
v6 = (v2 >> 6) & 1;
aso_draw_sprites(a1, LOWORD(hal21_vreg[3]) + ((v5 << 8) & 0x100) + 30, v4, *(_QWORD *)(Machine + 528LL));
tnk3_draw_text(a1, v6, v1 + 63488);
return tnk3_draw_status(a1, v6, v1 + 64512);
}

original_code:
void aso_vh_screenrefresh( struct osd_bitmap *bitmap, int full_refresh ){
 unsigned char *ram = memory_region(REGION_CPU1);
 int attributes = hal21_vreg[1];
 {
  unsigned char bg_attrs = hal21_vreg[0];
  int scrolly = -8+hal21_vreg[4]+((attributes&0x10)?256:0);
  int scrollx = scrollx_base + hal21_vreg[5]+((attributes&0x02)?0:256);
  aso_draw_background( bitmap, -scrollx, -scrolly,
   bg_attrs>>4,
   bg_attrs&0xf,
   Machine->gfx[1]
  );
 }
 {
  int scrollx = 0x1e + hal21_vreg[3] + ((attributes&0x01)?256:0);
  int scrolly = -8+0x11+hal21_vreg[2] + ((attributes&0x08)?256:0);
  aso_draw_sprites( bitmap, scrollx, scrolly, Machine->gfx[2] );
 }
 {
  int bank = (attributes&0x40)?1:0;
  tnk3_draw_text( bitmap, bank, &ram[0xf800] );
  tnk3_draw_status( bitmap, bank, &ram[0xfc00] );
 }
}

canonical_original_code:
void aso_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh){
 unsigned char *ram = memory_region(REGION_CPU1);
 int attributes = hal21_vreg[1];
 {
  unsigned char bg_attrs = hal21_vreg[0];
  int scrolly = -8+hal21_vreg[4]+((attributes&0x10)?256:0);
  int scrollx = scrollx_base + hal21_vreg[5]+((attributes&0x02)?0:256);
  aso_draw_background( bitmap, -scrollx, -scrolly,
   bg_attrs>>4,
   bg_attrs&0xf,
   Machine->gfx[1]
  );
 }
 {
  int scrollx = 0x1e + hal21_vreg[3] + ((attributes&0x01)?256:0);
  int scrolly = -8+0x11+hal21_vreg[2] + ((attributes&0x08)?256:0);
  aso_draw_sprites( bitmap, scrollx, scrolly, Machine->gfx[2] );
 }
 {
  int bank = (attributes&0x40)?1:0;
  tnk3_draw_text( bitmap, bank, &ram[0xf800] );
  tnk3_draw_status( bitmap, bank, &ram[0xfc00] );
 }
}

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

variable_types:
ram
unsigned char *


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

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

original_code: static data_t shared_ram_r(offs_t offset){ return shared_ram[offset]; }

canonical_original_code: static unsigned int shared_ram_r(unsigned int offset){ return shared_ram[offset]; }


decompiled_code:
__int64 common_vh_start()
{
_QWORD *v0; // rcx
__int64 v1; // rdi
__int64 result; // rax

dirtybuffer = malloc(0x1000uLL);
if ( !dirtybuffer )
return 1LL;
tmpbitmap = bitmap_alloc(512LL, 512LL);
if ( tmpbitmap )
{
v0 = dirtybuffer;
v1 = (__int64)dirtybuffer + 8;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v0[511] = 0x101010101010101LL;
memset(
(void *)(v1 & 0xFFFFFFFFFFFFFFF8LL),
1u,
8 * ((unsigned __int64)((unsigned int)v0 - (v1 & 0xFFFFFFF8) + 4096) >> 3));
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func8()
{
_QWORD *v0; // rcx
__int64 v1; // rdi
__int64 result; // rax

dirtybuffer = malloc(0x1000uLL);
if ( !dirtybuffer )
return 1LL;
tmpbitmap = bitmap_alloc(512LL, 512LL);
if ( tmpbitmap )
{
v0 = dirtybuffer;
v1 = (__int64)dirtybuffer + 8;
*(_QWORD *)dirtybuffer = 0x101010101010101LL;
v0[511] = 0x101010101010101LL;
memset(
(void *)(v1 & 0xFFFFFFFFFFFFFFF8LL),
1u,
8 * ((unsigned __int64)((unsigned int)v0 - (v1 & 0xFFFFFFF8) + 4096) >> 3));
result = 0LL;
}
else
{
free(dirtybuffer);
result = 1LL;
}
return result;
}

original_code:
static int common_vh_start( void ){
 dirtybuffer = (unsigned char*)malloc( 64*64 );
 if( dirtybuffer ){
  tmpbitmap = bitmap_alloc( 512, 512 );
  if( tmpbitmap ){
   memset( dirtybuffer, 1, 64*64 );
   return 0;
  }
  free( dirtybuffer );
 }
 return 1;
}

canonical_original_code:
static int common_vh_start(){
 dirtybuffer = (unsigned char *)malloc( 64*64 );
 if( dirtybuffer ){
  tmpbitmap = bitmap_alloc( 512, 512 );
  if( tmpbitmap ){
   memset( dirtybuffer, 1, 64*64 );
   return 0;
  }
  free( dirtybuffer );
 }
 return 1;
}