decompiled_code:
void *__fastcall mikie_palettebank_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 7;
if ( v2 != palettebank )
{
palettebank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

v2 = a2 & 7;
if ( v2 != palettebank )
{
palettebank = v2;
result = memset(dirtybuffer, 1, videoram_size);
}
return result;
}

original_code:
void mikie_palettebank_w(offs_t offset,data_t data)
{
 if (palettebank != (data & 7))
 {
  palettebank = data & 7;
  memset(dirtybuffer,1,videoram_size);
 }
}

canonical_original_code:
void mikie_palettebank_w(unsigned int offset, unsigned int data)
{
 if (palettebank != (data & 7))
 {
  palettebank = data & 7;
  memset(dirtybuffer,1,videoram_size);
 }
}


decompiled_code:
void *__fastcall mikie_flipscreen_w(__int64 a1, char a2)
{
int v2; // esi
void *result; // rax

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

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

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

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

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

variable_types:
offset
unsigned int

variable_types:
data
unsigned int

return_type: void


decompiled_code:
__int64 mikie_sh_timer_r()
{
return (unsigned int)((int)cpu_gettotalcycles() / 512);
}

canonical_decompiled_code:
__int64 func4()
{
return (unsigned int)((int)cpu_gettotalcycles() / 512);
}

original_code:
data_t mikie_sh_timer_r(offs_t offset)
{
 int clock;
 clock = cpu_gettotalcycles() / 512;
 return clock;
}

canonical_original_code:
unsigned int mikie_sh_timer_r(unsigned int offset)
{
 int clock;
 clock = cpu_gettotalcycles() / 512;
 return clock;
}

variable_types: clock int

return_type: unsigned int


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

result = (unsigned int)last_0;
if ( !last_0 && a2 == 1 )
{
result = cpu_cause_interrupt(1LL, 255LL);
last_0 = 1;
}
else
{
last_0 = a2;
}
return result;
}

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

result = (unsigned int)last_0;
if ( !last_0 && a2 == 1 )
{
result = cpu_cause_interrupt(1LL, 255LL);
last_0 = 1;
}
else
{
last_0 = a2;
}
return result;
}

original_code:
void mikie_sh_irqtrigger_w(offs_t offset,data_t data)
{
 static int last;
 if (last == 0 && data == 1)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

canonical_original_code:
void mikie_sh_irqtrigger_w(unsigned int offset, unsigned int data)
{
 static int last;
 if (last == 0 && data == 1)
 {
  cpu_cause_interrupt(1,0xff);
 }
 last = data;
}

variable_types: last int


decompiled_code:
__int64 __fastcall bionicc_bgvideoram_r(unsigned int a1)
{
return *(unsigned __int16 *)(bionicc_bgvideoram + a1);
}

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

original_code:
data_t bionicc_bgvideoram_r(offs_t offset)
{
 return (*(UINT16 *)(&bionicc_bgvideoram[offset]));
}

canonical_original_code:
unsigned int bionicc_bgvideoram_r(unsigned int offset)
{
 return (*(unsigned short *)(&bionicc_bgvideoram[offset]));
}


decompiled_code:
__int64 __fastcall bionicc_fgvideoram_r(unsigned int a1)
{
return *(unsigned __int16 *)(bionicc_fgvideoram + a1);
}

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

original_code:
data_t bionicc_fgvideoram_r(offs_t offset)
{
 return (*(UINT16 *)(&bionicc_fgvideoram[offset]));
}

canonical_original_code:
unsigned int bionicc_fgvideoram_r(unsigned int offset)
{
 return (*(unsigned short *)(&bionicc_fgvideoram[offset]));
}


decompiled_code:
__int64 __fastcall bionicc_txvideoram_r(unsigned int a1)
{
return *(unsigned __int16 *)(bionicc_txvideoram + a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
return *(unsigned __int16 *)(bionicc_txvideoram + a1);
}

original_code:
data_t bionicc_txvideoram_r(offs_t offset)
{
 return (*(UINT16 *)(&bionicc_txvideoram[offset]));
}

canonical_original_code:
unsigned int bionicc_txvideoram_r(unsigned int offset)
{
 return (*(unsigned short *)(&bionicc_txvideoram[offset]));
}


decompiled_code:
__int64 __fastcall hacked_controls_r(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&bionicc_inp + a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&bionicc_inp + a1);
}

original_code:
static data_t hacked_controls_r(offs_t offset)
{
 return (*(UINT16 *)(&bionicc_inp[offset]));
}

canonical_original_code:
static unsigned int hacked_controls_r(unsigned int offset)
{
 return (*(unsigned short *)(&bionicc_inp[offset]));
}


decompiled_code:
__int64 __fastcall hacked_soundcommand_r(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&soundcommand + a1);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
return *(unsigned __int16 *)((char *)&soundcommand + a1);
}

original_code:
static data_t hacked_soundcommand_r(offs_t offset)
{
 return (*(UINT16 *)(&soundcommand[offset]));
}

canonical_original_code:
static unsigned int hacked_soundcommand_r(unsigned int offset)
{
 return (*(unsigned short *)(&soundcommand[offset]));
}


decompiled_code:
__int64 bionicc_vh_start()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rdx
__int64 v5; // [rsp+0h] [rbp-18h]
__int64 v6; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v5) = 64;
tx_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 64LL, v5);
LODWORD(v6) = 64;
fg_tilemap = v1;
v2 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v6);
v3 = fg_tilemap;
bg_tilemap = v2;
if ( !fg_tilemap || !v2 || !tx_tilemap )
return 1LL;
*(_DWORD *)(tx_tilemap + 132) = 3;
*(_DWORD *)(v3 + 132) = 15;
*(_DWORD *)(v2 + 132) = 15;
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 v0; // rax
__int64 v1; // rax
__int64 v2; // rax
__int64 v3; // rdx
__int64 v5; // [rsp+0h] [rbp-18h]
__int64 v6; // [rsp+0h] [rbp-18h]

v0 = tilemap_create(get_tx_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 32LL, 32LL);
LODWORD(v5) = 64;
tx_tilemap = v0;
v1 = tilemap_create(get_fg_tile_info, &tilemap_scan_rows, 1LL, 16LL, 16LL, 64LL, v5);
LODWORD(v6) = 64;
fg_tilemap = v1;
v2 = tilemap_create(get_bg_tile_info, &tilemap_scan_rows, 1LL, 8LL, 8LL, 64LL, v6);
v3 = fg_tilemap;
bg_tilemap = v2;
if ( !fg_tilemap || !v2 || !tx_tilemap )
return 1LL;
*(_DWORD *)(tx_tilemap + 132) = 3;
*(_DWORD *)(v3 + 132) = 15;
*(_DWORD *)(v2 + 132) = 15;
return 0LL;
}

original_code:
int bionicc_vh_start(void)
{
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,64,64);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x01, 8,8,64,64);
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 tx_tilemap->transparent_pen = 3;
 fg_tilemap->transparent_pen = 15;
 bg_tilemap->transparent_pen = 15;
 return 0;
}

canonical_original_code:
int bionicc_vh_start()
{
 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,0x01, 8,8,32,32);
 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,0x01,16,16,64,64);
 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,0x01, 8,8,64,64);
 if (!fg_tilemap || !bg_tilemap || !tx_tilemap)
  return 1;
 tx_tilemap->transparent_pen = 3;
 fg_tilemap->transparent_pen = 15;
 bg_tilemap->transparent_pen = 15;
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall bionicc_bgvideoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(bionicc_bgvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(bionicc_bgvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(bg_tilemap, a1 >> 2);
}
return result;
}

original_code:
void bionicc_bgvideoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&bionicc_bgvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  int tile_index = offset/4;
  (*(UINT16 *)(&bionicc_bgvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,tile_index);
 }
}

canonical_original_code:
void bionicc_bgvideoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&bionicc_bgvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  int tile_index = offset/4;
  (*(unsigned short *)(&bionicc_bgvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(bg_tilemap,tile_index);
 }
}

variable_types: oldword int

variable_types: newword int


decompiled_code:
__int64 __fastcall bionicc_fgvideoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(bionicc_fgvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(fg_tilemap, a1 >> 2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(bionicc_fgvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(fg_tilemap, a1 >> 2);
}
return result;
}

original_code:
void bionicc_fgvideoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&bionicc_fgvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  int tile_index = offset/4;
  (*(UINT16 *)(&bionicc_fgvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(fg_tilemap,tile_index);
 }
}

canonical_original_code:
void bionicc_fgvideoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&bionicc_fgvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  int tile_index = offset/4;
  (*(unsigned short *)(&bionicc_fgvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(fg_tilemap,tile_index);
 }
}


decompiled_code:
__int64 __fastcall bionicc_txvideoram_w(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(bionicc_txvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(tx_tilemap, (a1 >> 1) & 0x3FF);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int a1, unsigned int a2)
{
_WORD *v2; // rdx
int v3; // ecx
__int64 result; // rax
int v5; // esi

v2 = (_WORD *)(bionicc_txvideoram + a1);
v3 = (unsigned __int16)*v2;
result = v3 & HIWORD(a2);
v5 = result | (unsigned __int16)a2;
if ( v3 != v5 )
{
*v2 = v5;
result = tilemap_mark_tile_dirty(tx_tilemap, (a1 >> 1) & 0x3FF);
}
return result;
}

original_code:
void bionicc_txvideoram_w(offs_t offset,data_t data)
{
 int oldword = (*(UINT16 *)(&bionicc_txvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  int tile_index = (offset&0x7ff)/2;
  (*(UINT16 *)(&bionicc_txvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(tx_tilemap,tile_index);
 }
}

canonical_original_code:
void bionicc_txvideoram_w(unsigned int offset, unsigned int data)
{
 int oldword = (*(UINT16 *)(&bionicc_txvideoram[offset]));
 int newword = (((oldword) & ((data) >> 16)) | ((data) & 0xffff));
 if (oldword != newword)
 {
  int tile_index = (offset&0x7ff)/2;
  (*(unsigned short *)(&bionicc_txvideoram[offset]) = (newword));
  tilemap_mark_tile_dirty(tx_tilemap,tile_index);
 }
}


decompiled_code:
__int64 __fastcall bionicc_paletteram_w(__int64 a1, __int16 a2)
{
return paletteram_RRRRGGGGBBBBIIII_word_w(a1, (2 * (_BYTE)a2) & 0xE | a2 & 0xFFF1u);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int16 a2)
{
return paletteram_RRRRGGGGBBBBIIII_word_w(a1, (2 * (_BYTE)a2) & 0xE | a2 & 0xFFF1u);
}

original_code:
void bionicc_paletteram_w(offs_t offset,data_t data)
{
 paletteram_RRRRGGGGBBBBIIII_word_w(offset,(data & 0xfff1) | ((data & 0x0007) << 1));
}

canonical_original_code:
void bionicc_paletteram_w(unsigned int offset, unsigned int data)
{
 paletteram_RRRRGGGGBBBBIIII_word_w(offset,(data & 0xfff1) | ((data & 0x0007) << 1));
}


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

if ( a1 == 4 )
return tilemap_set_scrollx(bg_tilemap, 0LL, a2);
if ( a1 > 4 )
{
if ( a1 == 6 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, a2);
}
else if ( a1 )
{
if ( a1 == 2 )
result = tilemap_set_scrolly(fg_tilemap, 0LL, a2);
}
else
{
result = tilemap_set_scrollx(fg_tilemap, 0LL, a2);
}
return result;
}

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

if ( a1 == 4 )
return tilemap_set_scrollx(bg_tilemap, 0LL, a2);
if ( a1 > 4 )
{
if ( a1 == 6 )
result = tilemap_set_scrolly(bg_tilemap, 0LL, a2);
}
else if ( a1 )
{
if ( a1 == 2 )
result = tilemap_set_scrolly(fg_tilemap, 0LL, a2);
}
else
{
result = tilemap_set_scrollx(fg_tilemap, 0LL, a2);
}
return result;
}

original_code:
void bionicc_scroll_w(offs_t offset,data_t data)
{
 switch( offset )
 {
  case 0:
   tilemap_set_scrollx(fg_tilemap,0,data);
   break;
  case 2:
   tilemap_set_scrolly(fg_tilemap,0,data);
   break;
  case 4:
   tilemap_set_scrollx(bg_tilemap,0,data);
   break;
  case 6:
   tilemap_set_scrolly(bg_tilemap,0,data);
   break;
 }
}

canonical_original_code:
void bionicc_scroll_w(unsigned int offset, unsigned int data)
{
 switch( offset )
 {
  case 0:
   tilemap_set_scrollx(fg_tilemap,0,data);
   break;
  case 2:
   tilemap_set_scrolly(fg_tilemap,0,data);
   break;
  case 4:
   tilemap_set_scrollx(bg_tilemap,0,data);
   break;
  case 6:
   tilemap_set_scrolly(bg_tilemap,0,data);
   break;
 }
}


decompiled_code:
__int64 __fastcall bionicc_gfxctrl_w(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx
__int64 v3; // rsi

v2 = a2 >> 8;
v3 = BYTE1(a2) & 1;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
tilemap_set_enable(bg_tilemap, v2 & 0x20);
tilemap_set_enable(fg_tilemap, v2 & 0x10);
coin_counter_w(0LL, v2 & 0x80);
return coin_counter_w(1LL, v2 & 0x40);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx
__int64 v3; // rsi

v2 = a2 >> 8;
v3 = BYTE1(a2) & 1;
flipscreen = v3;
if ( (_DWORD)v3 )
v3 = 3LL;
tilemap_set_flip(0LL, v3);
tilemap_set_enable(bg_tilemap, v2 & 0x20);
tilemap_set_enable(fg_tilemap, v2 & 0x10);
coin_counter_w(0LL, v2 & 0x80);
return coin_counter_w(1LL, v2 & 0x40);
}

original_code:
void bionicc_gfxctrl_w(offs_t offset,data_t data)
{
 data >>= 8;
 flipscreen = data & 1;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 tilemap_set_enable(bg_tilemap,data & 0x20);
 tilemap_set_enable(fg_tilemap,data & 0x10);
 coin_counter_w(0,data & 0x80);
 coin_counter_w(1,data & 0x40);
}

canonical_original_code:
void bionicc_gfxctrl_w(unsigned int offset, unsigned int data)
{
 data >>= 8;
 flipscreen = data & 1;
 tilemap_set_flip(0,flipscreen ? (0x2 | 0x1) : 0);
 tilemap_set_enable(bg_tilemap,data & 0x20);
 tilemap_set_enable(fg_tilemap,data & 0x10);
 coin_counter_w(0,data & 0x80);
 coin_counter_w(1,data & 0x40);
}


decompiled_code:
__int64 __fastcall bionicc_draw_sprites(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r13
__int64 v3; // rbx
int v4; // er14
__int64 v5; // r15
unsigned __int16 v6; // dx
__int64 v7; // rsi
__int64 v8; // rcx
__int64 v9; // r9
unsigned int v10; // er10
__int64 v11; // r8
unsigned int v12; // er10

result = spriteram_size;
v2 = *(_QWORD *)(Machine + 536LL);
v3 = Machine + 776LL;
v4 = spriteram_size - 8;
if ( (int)spriteram_size - 8 >= 0 )
{
v5 = v4;
do
{
v6 = *(_WORD *)(buffered_spriteram + v5) & 0x7FF;
if ( v6 != 2047 )
{
v7 = (unsigned int)*(__int16 *)(buffered_spriteram + v5 + 6);
v8 = (unsigned int)*(__int16 *)(buffered_spriteram + v5 + 4);
v9 = (unsigned int)flipscreen;
v10 = *(unsigned __int16 *)(buffered_spriteram + v5 + 2);
v11 = v10 & 2;
v12 = (v10 >> 2) & 0xF;
if ( (int)v8 > 496 )
v8 = (unsigned int)(v8 - 512);
if ( flipscreen )
{
v9 = 1LL;
v7 = (unsigned int)(240 - v7);
v8 = (unsigned int)(240 - v8);
v11 = (_DWORD)v11 == 0;
}
result = drawgfx(a1, v2, v6, v12, v11, v9, v7, v8, v3, 2LL, 15LL);
}
v5 -= 8LL;
v4 -= 8;
}
while ( v4 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r13
__int64 v3; // rbx
int v4; // er14
__int64 v5; // r15
unsigned __int16 v6; // dx
__int64 v7; // rsi
__int64 v8; // rcx
__int64 v9; // r9
unsigned int v10; // er10
__int64 v11; // r8
unsigned int v12; // er10

result = spriteram_size;
v2 = *(_QWORD *)(Machine + 536LL);
v3 = Machine + 776LL;
v4 = spriteram_size - 8;
if ( (int)spriteram_size - 8 >= 0 )
{
v5 = v4;
do
{
v6 = *(_WORD *)(buffered_spriteram + v5) & 0x7FF;
if ( v6 != 2047 )
{
v7 = (unsigned int)*(__int16 *)(buffered_spriteram + v5 + 6);
v8 = (unsigned int)*(__int16 *)(buffered_spriteram + v5 + 4);
v9 = (unsigned int)flipscreen;
v10 = *(unsigned __int16 *)(buffered_spriteram + v5 + 2);
v11 = v10 & 2;
v12 = (v10 >> 2) & 0xF;
if ( (int)v8 > 496 )
v8 = (unsigned int)(v8 - 512);
if ( flipscreen )
{
v9 = 1LL;
v7 = (unsigned int)(240 - v7);
v8 = (unsigned int)(240 - v8);
v11 = (_DWORD)v11 == 0;
}
result = drawgfx(a1, v2, v6, v12, v11, v9, v7, v8, v3, 2LL, 15LL);
}
v5 -= 8LL;
v4 -= 8;
}
while ( v4 >= 0 );
}
return result;
}

original_code:
static void bionicc_draw_sprites( struct osd_bitmap *bitmap )
{
 int offs;
 const struct GfxElement *gfx = Machine->gfx[3];
 const struct rectangle *clip = &Machine->visible_area;
 for (offs = spriteram_size-8;offs >= 0;offs -= 8)
 {
  int tile_number = (*(UINT16 *)(&buffered_spriteram[offs]))&0x7ff;
  if( tile_number!=0x7FF ){
   int attr = (*(UINT16 *)(&buffered_spriteram[offs+2]));
   int color = (attr&0x3C)>>2;
   int flipx = attr&0x02;
   int flipy = 0;
   int sx= (signed short)(*(UINT16 *)(&buffered_spriteram[offs+6]));
   int sy= (signed short)(*(UINT16 *)(&buffered_spriteram[offs+4]));
   if(sy>512-16) sy-=512;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx( bitmap, gfx,
    tile_number,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,15);
  }
 }
}

canonical_original_code:
static void bionicc_draw_sprites(struct osd_bitmap *bitmap)
{
 int offs;
 struct GfxElement *gfx = Machine->gfx[3];
 struct rectangle *clip = &Machine->visible_area;
 for (offs = spriteram_size-8;offs >= 0;offs -= 8)
 {
  int tile_number = (*(UINT16 *)(&buffered_spriteram[offs]))&0x7ff;
  if( tile_number!=0x7FF ){
   int attr = (*(UINT16 *)(&buffered_spriteram[offs+2]));
   int color = (attr&0x3C)>>2;
   int flipx = attr&0x02;
   int flipy = 0;
   int sx = (signed short)(*(UINT16 *)(&buffered_spriteram[offs+6]));
   int sy = (signed short)(*(UINT16 *)(&buffered_spriteram[offs+4]));
   if(sy>512-16) sy-=512;
   if (flipscreen)
   {
    sx = 240 - sx;
    sy = 240 - sy;
    flipx = !flipx;
    flipy = !flipy;
   }
   drawgfx( bitmap, gfx,
    tile_number,
    color,
    flipx,flipy,
    sx,sy,
    clip,TRANSPARENCY_PEN,15);
  }
 }
}

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

variable_types: offs 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: attr int

variable_types: color int

variable_types: flipx int

variable_types: flipy int

variable_types: sx int

variable_types: sy int


decompiled_code:
__int64 bionicc_eof_callback()
{
return buffer_spriteram_w(0LL, 0LL);
}

canonical_decompiled_code:
__int64 func17()
{
return buffer_spriteram_w(0LL, 0LL);
}

original_code:
void bionicc_eof_callback(void)
{
 buffer_spriteram_w(0,0);
}

canonical_original_code:
void bionicc_eof_callback()
{
 buffer_spriteram_w(0,0);
}


decompiled_code:
__int64 __fastcall bionicc_inputs_r(int a1)
{
int v1; // ebx

v1 = ((__int64 (*)(void))readinputport)();
return (v1 << 8) + (unsigned int)readinputport((unsigned int)(a1 + 1));
}

canonical_decompiled_code:
__int64 __fastcall func18(int a1)
{
int v1; // ebx

v1 = ((__int64 (*)(void))readinputport)();
return (v1 << 8) + (unsigned int)readinputport((unsigned int)(a1 + 1));
}

original_code:
data_t bionicc_inputs_r(offs_t offset)
{
 return (readinputport(offset)<<8) + readinputport(offset+1);
}

canonical_original_code:
unsigned int bionicc_inputs_r(unsigned int offset)
{
 return (readinputport(offset)<<8) + readinputport(offset+1);
}


decompiled_code:
char bionicc_mpu_trigger_w()
{
__int16 v0; // ax
__int16 v1; // ax

bionicc_inp = ((int)readinputport(0LL) >> 4) ^ 0xF;
v0 = readinputport(5LL);
LOBYTE(v0) = ~(_BYTE)v0;
word_122C = v0;
v1 = readinputport(4LL);
LOBYTE(v1) = ~(_BYTE)v1;
word_122E = v1;
return v1;
}

canonical_decompiled_code:
char func19()
{
__int16 v0; // ax
__int16 v1; // ax

bionicc_inp = ((int)readinputport(0LL) >> 4) ^ 0xF;
v0 = readinputport(5LL);
LOBYTE(v0) = ~(_BYTE)v0;
word_122C = v0;
v1 = readinputport(4LL);
LOBYTE(v1) = ~(_BYTE)v1;
word_122E = v1;
return v1;
}

original_code:
static void bionicc_mpu_trigger_w(offs_t offset,data_t data)
{
 data = readinputport(0) >> 4;
 (*(UINT16 *)(&bionicc_inp[0x00]) = (data ^ 0x0f));
 data = readinputport(5);
 (*(UINT16 *)(&bionicc_inp[0x02]) = (data ^ 0xff));
 data = readinputport(4);
 (*(UINT16 *)(&bionicc_inp[0x04]) = (data ^ 0xff));
}

canonical_original_code:
static void bionicc_mpu_trigger_w(unsigned int offset, unsigned int data)
{
 data = readinputport(0) >> 4;
 (*(unsigned short *)(&bionicc_inp[0x00]) = (data ^ 0x0f));
 data = readinputport(5);
 (*(unsigned short *)(&bionicc_inp[0x02]) = (data ^ 0xff));
 data = readinputport(4);
 (*(unsigned short *)(&bionicc_inp[0x04]) = (data ^ 0xff));
}


decompiled_code:
__int64 __fastcall hacked_soundcommand_w(unsigned int a1, int a2)
{
*(_WORD *)((char *)&soundcommand + a1) = a2 | *(_WORD *)((_BYTE *)&soundcommand + a1) & HIWORD(a2);
return soundlatch_w(0LL, (unsigned __int8)a2);
}

canonical_decompiled_code:
__int64 __fastcall func20(unsigned int a1, int a2)
{
*(_WORD *)((char *)&soundcommand + a1) = a2 | *(_WORD *)((_BYTE *)&soundcommand + a1) & HIWORD(a2);
return soundlatch_w(0LL, (unsigned __int8)a2);
}

original_code:
void hacked_soundcommand_w(offs_t offset,data_t data)
{
 ((*(UINT16 *)((&soundcommand[offset])) = (((*(UINT16 *)(&soundcommand[offset])) & ((data) >> 16)) | (data))));
 soundlatch_w(0,data & 0xff);
}

canonical_original_code:
void hacked_soundcommand_w(unsigned int offset, unsigned int data)
{
 ((*(unsigned short *)((&soundcommand[offset])) = (((*(unsigned short *)(&soundcommand[offset])) & ((data) >> 16)) | (data))));
 soundlatch_w(0,data & 0xff);
}


decompiled_code:
__int64 bionicc_interrupt()
{
return (unsigned int)cpu_getiloops() == 0 ? 2 : 4;
}

canonical_decompiled_code:
__int64 func21()
{
return (unsigned int)cpu_getiloops() == 0 ? 2 : 4;
}

original_code:
int bionicc_interrupt(void)
{
 if (cpu_getiloops() == 0) return 2;
 else return 4;
}

canonical_original_code:
int bionicc_interrupt()
{
 if (cpu_getiloops() == 0) return 2;
 else return 4;
}


decompiled_code:
__int64 __fastcall bionicc_vh_screenrefresh(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
mark_sprite_colors();
*palette_used_colors |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
tilemap_draw(a1, fg_tilemap, 2LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
bionicc_draw_sprites(a1);
tilemap_draw(a1, fg_tilemap, 1LL);
return tilemap_draw(a1, tx_tilemap, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1)
{
tilemap_update(0LL);
palette_init_used_colors();
func22();
*palette_used_colors |= 1u;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
tilemap_draw(a1, fg_tilemap, 2LL);
tilemap_draw(a1, bg_tilemap, 0LL);
tilemap_draw(a1, fg_tilemap, 0LL);
func16(a1);
tilemap_draw(a1, fg_tilemap, 1LL);
return tilemap_draw(a1, tx_tilemap, 0LL);
}

original_code:
void bionicc_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colors();
 palette_used_colors[0] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 tilemap_draw(bitmap,fg_tilemap,2);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 bionicc_draw_sprites(bitmap);
 tilemap_draw(bitmap,fg_tilemap,1);
 tilemap_draw(bitmap,tx_tilemap,0);
}

canonical_original_code:
void bionicc_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 tilemap_update(0);
 palette_init_used_colors();
 mark_sprite_colors();
 palette_used_colors[0] |= 1;
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 tilemap_draw(bitmap,fg_tilemap,2);
 tilemap_draw(bitmap,bg_tilemap,0);
 tilemap_draw(bitmap,fg_tilemap,0);
 bionicc_draw_sprites(bitmap);
 tilemap_draw(bitmap,fg_tilemap,1);
 tilemap_draw(bitmap,tx_tilemap,0);
}

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


decompiled_code:
__int64 __fastcall get_bg_tile_info(int a1)
{
__int64 v1; // rdi
int v2; // ecx
__int64 v3; // rsi
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rsi
int v8; // eax
__int64 result; // rax

v1 = 2 * a1;
v2 = *(unsigned __int16 *)(bionicc_bgvideoram + 2 * v1 + 2);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(bionicc_bgvideoram + 2 * v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 3) & 3);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
v8 = 0;
if ( v7 )
v8 = *(_DWORD *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v8;
result = ((unsigned int)v2 >> 5) & 2;
*((_DWORD *)&tile_info + 5) = result | (v2 >> 7) & 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rdi
int v2; // ecx
__int64 v3; // rsi
__int64 v4; // r8
unsigned int v5; // edx
int v6; // eax
__int64 v7; // rsi
int v8; // eax
__int64 result; // rax

v1 = 2 * a1;
v2 = *(unsigned __int16 *)(bionicc_bgvideoram + 2 * v1 + 2);
v3 = *(_QWORD *)(Machine + 520LL);
v4 = *(_QWORD *)(v3 + 16);
v5 = (((_WORD)v2 << 8) & 0x700 | (unsigned __int64)*(unsigned __int8 *)(bionicc_bgvideoram + 2 * v1))
% *(unsigned int *)(v3 + 8);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v5 * *(_DWORD *)(v3 + 52));
v6 = *(_DWORD *)(v3 + 12) * ((v2 >> 3) & 3);
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v4 + 2LL * v6;
v8 = 0;
if ( v7 )
v8 = *(_DWORD *)(v7 + 4LL * v5);
*((_DWORD *)&tile_info + 4) = v8;
result = ((unsigned int)v2 >> 5) & 2;
*((_DWORD *)&tile_info + 5) = result | (v2 >> 7) & 1;
return result;
}

original_code:
static void get_bg_tile_info(int tile_index)
{
 UINT16 *videoram1 = (UINT16 *)bionicc_bgvideoram;
 int attr = videoram1[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
}

canonical_original_code:
static void get_bg_tile_info(int tile_index)
{
 unsigned short *videoram1 = (UINT16 *)bionicc_bgvideoram;
 int attr = videoram1[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(1)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
}

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; }


original_code:
static void get_fg_tile_info(int tile_index)
{
 UINT16 *videoram1 = (UINT16 *)bionicc_fgvideoram;
 int attr = videoram1[2*tile_index+1];
 { const struct GfxElement *gfx = Machine->gfx[(2)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 if ((attr & 0xc0) == 0xc0)
 {
  tile_info.priority = 2;
  tile_info.flags = 0;
 }
 else
 {
  tile_info.priority = (attr & 0x20) >> 5;
  tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
 }
}

canonical_original_code:
static void get_fg_tile_info(int tile_index)
{
 unsigned short *videoram1 = (UINT16 *)bionicc_fgvideoram;
 int attr = videoram1[2*tile_index+1];
 { struct GfxElement *gfx = Machine->gfx[(2)]; int _code = ((videoram1[2*tile_index] & 0xff) + ((attr & 0x07) << 8)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * ((attr & 0x18) >> 3)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
 if ((attr & 0xc0) == 0xc0)
 {
  tile_info.priority = 2;
  tile_info.flags = 0;
 }
 else
 {
  tile_info.priority = (attr & 0x20) >> 5;
  tile_info.flags = (((((attr & 0xc0) >> 6)>>1)|(((attr & 0xc0) >> 6)<<1))&3);
 }
}


decompiled_code:
__int64 __fastcall get_tx_tile_info(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1 + 1024LL;
v2 = *(_WORD *)(bionicc_txvideoram + 2 * v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = ((4 * v2) & 0x300 | (unsigned int)*(unsigned __int8 *)(bionicc_txvideoram + 2 * v1 - 2048)) % *(_DWORD *)(v3 + 8);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 0x3F);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
__int64 v1; // rdi
__int16 v2; // cx
__int64 v3; // rsi
unsigned int v4; // edx
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 result; // rax

v1 = a1 + 1024LL;
v2 = *(_WORD *)(bionicc_txvideoram + 2 * v1);
v3 = *(_QWORD *)(Machine + 512LL);
v4 = ((4 * v2) & 0x300 | (unsigned int)*(unsigned __int8 *)(bionicc_txvideoram + 2 * v1 - 2048)) % *(_DWORD *)(v3 + 8);
v5 = *(_DWORD *)(v3 + 12) * (v2 & 0x3F);
tile_info = *(_QWORD *)(v3 + 40) + (int)(v4 * *(_DWORD *)(v3 + 52));
v6 = *(_QWORD *)(v3 + 16) + 2 * v5;
v7 = *(_QWORD *)(v3 + 32);
*((_QWORD *)&tile_info + 1) = v6;
result = 0LL;
if ( v7 )
result = *(unsigned int *)(v7 + 4LL * v4);
*((_DWORD *)&tile_info + 4) = result;
return result;
}

original_code:
static void get_tx_tile_info(int tile_index)
{
 UINT16 *videoram1 = (UINT16 *)bionicc_txvideoram;
 int attr = videoram1[tile_index + 0x400];
 { const struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((videoram1[tile_index] & 0xff) + ((attr & 0x00c0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}

canonical_original_code:
static void get_tx_tile_info(int tile_index)
{
 unsigned short *videoram1 = (UINT16 *)bionicc_txvideoram;
 int attr = videoram1[tile_index + 0x400];
 { struct GfxElement *gfx = Machine->gfx[(0)]; int _code = ((videoram1[tile_index] & 0xff) + ((attr & 0x00c0) << 2)) % gfx->total_elements; tile_info.pen_data = gfx->gfxdata + _code*gfx->char_modulo; tile_info.pal_data = &gfx->colortable[gfx->color_granularity * (attr & 0x3f)]; tile_info.pen_usage = gfx->pen_usage?gfx->pen_usage[_code]:0; };
}


decompiled_code:
__int64 mark_sprite_colors()
{
__int64 v0; // r9
__int64 v1; // rax
int v2; // edi
_WORD *v3; // rdx
__int64 v4; // r8
unsigned __int16 v5; // ax
__int64 v6; // rcx
char *v7; // r8
int v8; // ecx
__int64 result; // rax
__int128 v10[4]; // [rsp+0h] [rbp-48h] BYREF
char v11; // [rsp+40h] [rbp-8h] BYREF

v10[0] = 0LL;
v0 = Machine;
v10[1] = 0LL;
v10[2] = 0LL;
v1 = *(_QWORD *)(Machine + 824LL);
v10[3] = 0LL;
v2 = *(_DWORD *)(*(_QWORD *)(v1 + 688) + 88LL);
v3 = (_WORD *)buffered_spriteram;
v4 = buffered_spriteram + 1280LL;
do
{
v5 = *v3 & 0x7FF;
if ( v5 != 2047 )
{
v6 = ((int)(unsigned __int16)v3[1] >> 2) & 0xF;
*((_DWORD *)v10 + v6) |= *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v0 + 536) + 32LL) + 4LL * v5);
}
v3 += 4;
}
while ( (_WORD *)v4 != v3 );
v7 = (char *)v10;
do
{
v8 = *(_DWORD *)v7;
LODWORD(result) = 0;
do
{
if ( _bittest(&v8, result) )
*(_BYTE *)(palette_used_colors + (int)result + v2) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v7 += 4;
v2 += 16;
}
while ( v7 != &v11 );
return result;
}

canonical_decompiled_code:
__int64 func22()
{
__int64 v0; // r9
__int64 v1; // rax
int v2; // edi
_WORD *v3; // rdx
__int64 v4; // r8
unsigned __int16 v5; // ax
__int64 v6; // rcx
char *v7; // r8
int v8; // ecx
__int64 result; // rax
__int128 v10[4]; // [rsp+0h] [rbp-48h] BYREF
char v11; // [rsp+40h] [rbp-8h] BYREF

v10[0] = 0LL;
v0 = Machine;
v10[1] = 0LL;
v10[2] = 0LL;
v1 = *(_QWORD *)(Machine + 824LL);
v10[3] = 0LL;
v2 = *(_DWORD *)(*(_QWORD *)(v1 + 688) + 88LL);
v3 = (_WORD *)buffered_spriteram;
v4 = buffered_spriteram + 1280LL;
do
{
v5 = *v3 & 0x7FF;
if ( v5 != 2047 )
{
v6 = ((int)(unsigned __int16)v3[1] >> 2) & 0xF;
*((_DWORD *)v10 + v6) |= *(_DWORD *)(*(_QWORD *)(*(_QWORD *)(v0 + 536) + 32LL) + 4LL * v5);
}
v3 += 4;
}
while ( (_WORD *)v4 != v3 );
v7 = (char *)v10;
do
{
v8 = *(_DWORD *)v7;
LODWORD(result) = 0;
do
{
if ( _bittest(&v8, result) )
*(_BYTE *)(palette_used_colors + (int)result + v2) = 3;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != 15 );
v7 += 4;
v2 += 16;
}
while ( v7 != &v11 );
return result;
}

original_code:
void mark_sprite_colors( void )
{
 int offs, code, color, i, pal_base;
 int colmask[16];
 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
 for(i=0;i<16;i++) colmask[i] = 0;
 for (offs = 0; offs < 0x500;offs += 8)
 {
  code = (*(UINT16 *)(&buffered_spriteram[offs])) & 0x7ff;
  if( code != 0x7FF ) {
   color = ((*(UINT16 *)(&buffered_spriteram[offs+2])) & 0x3c) >> 2;
   colmask[color] |= Machine->gfx[3]->pen_usage[code];
  }
 }
 for (color = 0;color < 16;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

canonical_original_code:
void mark_sprite_colors()
{
 int offs; int code; int color; int i; int pal_base;
 int colmask[16];
 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
 for(i=0;i<16;i++) colmask[i] = 0;
 for (offs = 0; offs < 0x500;offs += 8)
 {
  code = (*(unsigned short *)(&buffered_spriteram[offs])) & 0x7ff;
  if( code != 0x7FF ) {
   color = ((*(unsigned short *)(&buffered_spriteram[offs+2])) & 0x3c) >> 2;
   colmask[color] |= Machine->gfx[3]->pen_usage[code];
  }
 }
 for (color = 0;color < 16;color++)
 {
  for (i = 0;i < 15;i++)
  {
   if (colmask[color] & (1 << i))
    palette_used_colors[pal_base + 16 * color + i] = (1|2);
  }
 }
}

variable_types: code int

variable_types: i int

variable_types:
colmask
int [16]


decompiled_code:
void __fastcall milliped_input_select_w(__int64 a1, int a2)
{
dsw_select = a2 == 0;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
dsw_select = a2 == 0;
}

original_code:
static void milliped_input_select_w(offs_t offset,data_t data)
{
 dsw_select = (data == 0);
}

canonical_original_code:
static void milliped_input_select_w(unsigned int offset, unsigned int data)
{
 dsw_select = (data == 0);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int


original_code:
void milliped_paletteram_w(offs_t offset,data_t data)
{
 int bit0,bit1,bit2;
 int r,g,b;
 paletteram[offset] = data;
 bit0 = (~data >> 5) & 0x01;
 bit1 = (~data >> 6) & 0x01;
 bit2 = (~data >> 7) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (~data >> 3) & 0x01;
 bit2 = (~data >> 4) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (~data >> 0) & 0x01;
 bit1 = (~data >> 1) & 0x01;
 bit2 = (~data >> 2) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset,r,g,b);
}

canonical_original_code:
void milliped_paletteram_w(unsigned int offset, unsigned int data)
{
 int bit0; int bit1; int bit2;
 int r; int g; int b;
 paletteram[offset] = data;
 bit0 = (~data >> 5) & 0x01;
 bit1 = (~data >> 6) & 0x01;
 bit2 = (~data >> 7) & 0x01;
 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = 0;
 bit1 = (~data >> 3) & 0x01;
 bit2 = (~data >> 4) & 0x01;
 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 bit0 = (~data >> 0) & 0x01;
 bit1 = (~data >> 1) & 0x01;
 bit2 = (~data >> 2) & 0x01;
 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
 palette_change_color(offset,r,g,b);
}

variable_types: r int

variable_types: g int

variable_types: b int


decompiled_code:
__int64 __fastcall milliped_vh_screenrefresh(__int64 a1, int a2)
{
int v3; // ebx
__int64 v4; // rbp
char v5; // al
int v6; // ecx
unsigned int v7; // er10
__int64 i; // rbp
_BYTE *v9; // r10
__int64 v10; // r15
int v11; // eax
__int64 v12; // rbx
char v13; // r14
char v14; // di
__int64 v15; // rdx
int v16; // ecx
__int64 v17; // r9
__int64 v18; // rsi
_WORD *v19; // r8
int v20; // er15
__int64 result; // rax
unsigned int v22; // er8
int v23; // er11
int v24; // ecx
__int64 v25; // [rsp-30h] [rbp-68h]

if ( palette_recalc() || a2 )
{
memset(dirtybuffer, 1, videoram_size);
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_10;
}
else
{
v3 = videoram_size - 1;
if ( (int)videoram_size - 1 < 0 )
goto LABEL_10;
}
v4 = v3;
do
{
if ( *((_BYTE *)dirtybuffer + v4) )
{
*((_BYTE *)dirtybuffer + v4) = 0;
v5 = *(_BYTE *)(videoram + v4);
v6 = (v5 & 0x40) != 0;
v7 = v6 + 2;
if ( v5 >= 0 )
v7 = (*(_BYTE *)(videoram + v4) & 0x40) != 0;
drawgfx(
a1,
*(_QWORD *)(Machine + 512LL),
(v6 << 7) + (unsigned int)(unsigned __int8)((v5 & 0x3F) + 64),
v7,
0LL,
0LL,
8 * (v3 & 0x1Fu),
(unsigned int)(8 * (v3 >> 5)),
Machine + 776LL,
0LL,
0LL);
}
--v3;
--v4;
}
while ( v3 != -1 );
LABEL_10:
for ( i = 0LL; i != 16; ++i )
{
v9 = (_BYTE *)(spriteram + i);
v10 = *(unsigned __int8 *)(spriteram + i + 32);
v11 = *(unsigned __int8 *)(spriteram + i + 48);
v12 = 240 - (unsigned int)*(unsigned __int8 *)(spriteram + i + 16);
v13 = *(_BYTE *)(spriteram + i + 32);
v14 = *(_BYTE *)(spriteram + i + 48);
v15 = (*(_BYTE *)(spriteram + i) & 0x3F) >> 1;
if ( (*(_BYTE *)(spriteram + i) & 1) != 0 )
v15 = (unsigned int)(v15 + 64);
v16 = 4 * ((int)*(unsigned __int8 *)(spriteram + i + 48) >> 6);
v17 = *(_QWORD *)(Machine + 792LL);
v18 = *(_QWORD *)(Machine + 520LL);
v19 = *(_WORD **)(v18 + 16);
v19[3] = *(_WORD *)(v17 + 2LL * (v16 + (((int)*(unsigned __int8 *)(spriteram + i + 48) >> 4) & 3) + 16));
v19[2] = *(_WORD *)(v17 + 2LL * (v16 + ((v11 >> 2) & 3) + 16));
v19[1] = *(_WORD *)(v17 + 2LL * (v16 + (v14 & 3) + 16));
v25 = v10;
v20 = (int)v10 >> 3;
result = drawgfx(a1, v18, v15, 0LL, 0LL, *v9 & 0x80, v25, v12, &spritevisiblearea, 2LL, 0LL);
v22 = (int)v12 >> 3;
v23 = ((int)v12 >> 3) - (((v12 & 0xF) == 0) - 3);
if ( (int)v12 >> 3 < v23 )
{
v24 = v20 + ((v13 & 7) != 0) + 1;
do
{
if ( v20 < v24 )
{
LODWORD(result) = v20;
do
{
if ( (int)result <= 31 && v22 <= 0x1F )
*((_BYTE *)dirtybuffer + (int)(result + 32 * v22)) = 1;
result = (unsigned int)(result + 1);
}
while ( (_DWORD)result != v24 );
}
++v22;
}
while ( v22 != v23 );
}
}
return result;
}

original_code:
void milliped_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx,sy;
   int bank;
   int color;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (videoram[offs] & 0x40)
    bank = 1;
   else bank = 0;
   if (videoram[offs] & 0x80)
    color = 2;
   else color = 0;
   drawgfx(bitmap,Machine->gfx[0],
     0x40 + (videoram[offs] & 0x3f) + 0x80 * bank,
     bank + color,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum,color;
  int x, y;
  int sx, sy;
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  spritenum = spriteram[offs] & 0x3f;
  if (spritenum & 1) spritenum = spritenum / 2 + 64;
  else spritenum = spritenum / 2;
  color = spriteram[offs + 0x30];
  Machine->gfx[1]->colortable[3] =
    Machine->pens[16+((color >> 4) & 3)+4*((color >> 6) & 3)];
  Machine->gfx[1]->colortable[2] =
    Machine->pens[16+((color >> 2) & 3)+4*((color >> 6) & 3)];
  Machine->gfx[1]->colortable[1] =
    Machine->pens[16+((color >> 0) & 3)+4*((color >> 6) & 3)];
  drawgfx(bitmap,Machine->gfx[1],
    spritenum,
    0,
    0,spriteram[offs] & 0x80,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2, y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

canonical_original_code:
void milliped_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
 int offs;
 if (palette_recalc() || full_refresh)
  memset (dirtybuffer, 1, videoram_size);
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
  if (dirtybuffer[offs])
  {
   int sx; int sy;
   int bank;
   int color;
   dirtybuffer[offs] = 0;
   sx = offs % 32;
   sy = offs / 32;
   if (videoram[offs] & 0x40)
    bank = 1;
   else bank = 0;
   if (videoram[offs] & 0x80)
    color = 2;
   else color = 0;
   drawgfx(bitmap,Machine->gfx[0],
     0x40 + (videoram[offs] & 0x3f) + 0x80 * bank,
     bank + color,
     0,0,
     8*sx,8*sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
  }
 }
 for (offs = 0;offs < 0x10;offs++)
 {
  int spritenum; int color;
  int x; int y;
  int sx; int sy;
  x = spriteram[offs + 0x20];
  y = 240 - spriteram[offs + 0x10];
  spritenum = spriteram[offs] & 0x3f;
  if (spritenum & 1) spritenum = spritenum / 2 + 64;
  else spritenum = spritenum / 2;
  color = spriteram[offs + 0x30];
  Machine->gfx[1]->colortable[3] =
    Machine->pens[16+((color >> 4) & 3)+4*((color >> 6) & 3)];
  Machine->gfx[1]->colortable[2] =
    Machine->pens[16+((color >> 2) & 3)+4*((color >> 6) & 3)];
  Machine->gfx[1]->colortable[1] =
    Machine->pens[16+((color >> 0) & 3)+4*((color >> 6) & 3)];
  drawgfx(bitmap,Machine->gfx[1],
    spritenum,
    0,
    0,spriteram[offs] & 0x80,
    x,y,
    &spritevisiblearea,TRANSPARENCY_PEN,0);
  sx = x >> 3;
  sy = y >> 3;
  {
   int max_x = 1;
   int max_y = 2;
   int x2; int y2;
   if (x & 0x07) max_x ++;
   if (y & 0x0f) max_y ++;
   for (y2 = sy; y2 < sy + max_y; y2 ++)
   {
    for (x2 = sx; x2 < sx + max_x; x2 ++)
    {
     if ((x2 < 32) && (y2 < 32) && (x2 >= 0) && (y2 >= 0))
      dirtybuffer[x2 + 32*y2] = 1;
    }
   }
  }
 }
}

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

variable_types: offs int

variable_types: bank int

variable_types: spritenum int

variable_types: x int

variable_types: y int


decompiled_code:
__int64 __fastcall milliped_led_w(__int64 a1, unsigned int a2)
{
return osd_led_w(a1, ~(a2 >> 7));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2)
{
return osd_led_w(a1, ~(a2 >> 7));
}

original_code:
static void milliped_led_w(offs_t offset,data_t data)
{
 osd_led_w (offset, ~(data >> 7));
}

canonical_original_code:
static void milliped_led_w(unsigned int offset, unsigned int data)
{
 osd_led_w (offset, ~(data >> 7));
}


decompiled_code:
__int64 milliped_IN1_r()
{
int v0; // eax
char v1; // dl

if ( dsw_select )
return sign_3 | (unsigned int)readinputport(1LL);
v0 = readinputport(7LL);
v1 = oldpos_2;
if ( oldpos_2 != v0 )
{
oldpos_2 = v0;
sign_3 = ((_BYTE)v0 - v1) & 0x80;
}
return readinputport(1LL) & 0x70 | sign_3 | oldpos_2 & 0xFu;
}

canonical_decompiled_code:
__int64 func4()
{
int v0; // eax
char v1; // dl

if ( dsw_select )
return sign_3 | (unsigned int)readinputport(1LL);
v0 = readinputport(7LL);
v1 = oldpos_2;
if ( oldpos_2 != v0 )
{
oldpos_2 = v0;
sign_3 = ((_BYTE)v0 - v1) & 0x80;
}
return readinputport(1LL) & 0x70 | sign_3 | oldpos_2 & 0xFu;
}

original_code:
static data_t milliped_IN1_r(offs_t offset)
{
 static int oldpos,sign;
 int newpos;
 if (dsw_select)
  return (readinputport(1) | sign);
 newpos = readinputport(7);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((readinputport(1) & 0x70) | (oldpos & 0x0f) | sign );
}

canonical_original_code:
static unsigned int milliped_IN1_r(unsigned int offset)
{
 static int oldpos; static int sign;
 int newpos;
 if (dsw_select)
  return (readinputport(1) | sign);
 newpos = readinputport(7);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((readinputport(1) & 0x70) | (oldpos & 0x0f) | sign );
}

variable_types: oldpos int

variable_types: sign int

variable_types: newpos int


decompiled_code:
__int64 milliped_IN0_r()
{
int v0; // eax
char v1; // dl

if ( dsw_select )
return sign_1 | (unsigned int)readinputport(0LL);
v0 = readinputport(6LL);
v1 = oldpos_0;
if ( oldpos_0 != v0 )
{
oldpos_0 = v0;
sign_1 = ((_BYTE)v0 - v1) & 0x80;
}
return readinputport(0LL) & 0x70 | sign_1 | oldpos_0 & 0xFu;
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // eax
char v1; // dl

if ( dsw_select )
return sign_1 | (unsigned int)readinputport(0LL);
v0 = readinputport(6LL);
v1 = oldpos_0;
if ( oldpos_0 != v0 )
{
oldpos_0 = v0;
sign_1 = ((_BYTE)v0 - v1) & 0x80;
}
return readinputport(0LL) & 0x70 | sign_1 | oldpos_0 & 0xFu;
}

original_code:
static data_t milliped_IN0_r(offs_t offset)
{
 static int oldpos,sign;
 int newpos;
 if (dsw_select)
  return (readinputport(0) | sign);
 newpos = readinputport(6);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((readinputport(0) & 0x70) | (oldpos & 0x0f) | sign );
}

canonical_original_code:
static unsigned int milliped_IN0_r(unsigned int offset)
{
 static int oldpos; static int sign;
 int newpos;
 if (dsw_select)
  return (readinputport(0) | sign);
 newpos = readinputport(6);
 if (newpos != oldpos)
 {
  sign = (newpos - oldpos) & 0x80;
  oldpos = newpos;
 }
 return ((readinputport(0) & 0x70) | (oldpos & 0x0f) | sign );
}


decompiled_code:
void __fastcall bsktball_nmion_w(char a1)
{
NMION = a1 & 1;
}

canonical_decompiled_code:
void __fastcall func0(char a1)
{
NMION = a1 & 1;
}

original_code:
void bsktball_nmion_w(offs_t offset,data_t data)
{
 NMION = offset & 0x01;
}

canonical_original_code:
void bsktball_nmion_w(unsigned int offset, unsigned int data)
{
 NMION = offset & 0x01;
}


decompiled_code:
void __fastcall bsktball_ld1_w(char a1)
{
LD1 = a1 & 1;
}

canonical_decompiled_code:
void __fastcall func1(char a1)
{
LD1 = a1 & 1;
}

original_code:
void bsktball_ld1_w(offs_t offset,data_t data)
{
 LD1 = (offset & 0x01);
}

canonical_original_code:
void bsktball_ld1_w(unsigned int offset, unsigned int data)
{
 LD1 = (offset & 0x01);
}


decompiled_code:
void __fastcall bsktball_ld2_w(char a1)
{
LD2 = a1 & 1;
}

canonical_decompiled_code:
void __fastcall func2(char a1)
{
LD2 = a1 & 1;
}

original_code:
void bsktball_ld2_w(offs_t offset,data_t data)
{
 LD2 = (offset & 0x01);
}

canonical_original_code:
void bsktball_ld2_w(unsigned int offset, unsigned int data)
{
 LD2 = (offset & 0x01);
}


decompiled_code:
__int64 __fastcall bsktball_vh_screenrefresh(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
int v3; // er8
char v4; // al
__int64 v5; // rbx
__int64 v6; // r8
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rdx
__int64 result; // rax
__int64 v11; // [rsp-28h] [rbp-60h]
__int64 v12; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(videoram + v2--);
v11 = (unsigned int)(8 * (v1 >> 5));
v4 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(4 * (_BYTE)v3) & 0x3C | (v3 >> 4) & 3u,
(v3 >> 6) & 1,
(unsigned int)v3 >> 7,
0LL,
8 * (v4 & 0x1Fu),
v11,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v5 = 0LL;
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v6 = *(unsigned __int8 *)(bsktball_motion + v5) >> 7;
v7 = *(_BYTE *)(bsktball_motion + v5 + 3) & 0x3F;
v12 = 224 - (unsigned int)*(unsigned __int8 *)(bsktball_motion + v5 + 1);
v8 = *(unsigned __int8 *)(bsktball_motion + v5 + 2);
v9 = *(_BYTE *)(bsktball_motion + v5) & 0x3F;
v5 += 4LL;
result = drawgfx(a1, *(_QWORD *)(Machine + 520LL), v9, v7, v6, 0LL, v8, v12, Machine + 776LL, 2LL, 0LL);
}
while ( v5 != 64 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebx
__int64 v2; // r13
int v3; // er8
char v4; // al
__int64 v5; // rbx
__int64 v6; // r8
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rdx
__int64 result; // rax
__int64 v11; // [rsp-28h] [rbp-60h]
__int64 v12; // [rsp-28h] [rbp-60h]

v1 = videoram_size - 1;
if ( videoram_size - 1 >= 0 )
{
v2 = v1;
do
{
while ( !*(_BYTE *)(v2 + dirtybuffer) )
{
--v1;
--v2;
if ( v1 == -1 )
goto LABEL_6;
}
*(_BYTE *)(v2 + dirtybuffer) = 0;
v3 = *(unsigned __int8 *)(videoram + v2--);
v11 = (unsigned int)(8 * (v1 >> 5));
v4 = v1--;
drawgfx(
tmpbitmap,
*(_QWORD *)(Machine + 512LL),
(4 * (_BYTE)v3) & 0x3C | (v3 >> 4) & 3u,
(v3 >> 6) & 1,
(unsigned int)v3 >> 7,
0LL,
8 * (v4 & 0x1Fu),
v11,
Machine + 776LL,
0LL,
0LL);
}
while ( v1 != -1 );
}
LABEL_6:
v5 = 0LL;
copybitmap(a1, tmpbitmap, 0LL, 0LL, 0LL, 0LL, Machine + 776LL, 0LL, 0LL);
do
{
v6 = *(unsigned __int8 *)(bsktball_motion + v5) >> 7;
v7 = *(_BYTE *)(bsktball_motion + v5 + 3) & 0x3F;
v12 = 224 - (unsigned int)*(unsigned __int8 *)(bsktball_motion + v5 + 1);
v8 = *(unsigned __int8 *)(bsktball_motion + v5 + 2);
v9 = *(_BYTE *)(bsktball_motion + v5) & 0x3F;
v5 += 4LL;
result = drawgfx(a1, *(_QWORD *)(Machine + 520LL), v9, v7, v6, 0LL, v8, v12, Machine + 776LL, 2LL, 0LL);
}
while ( v5 != 64 );
return result;
}

original_code:
void bsktball_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
{
    int offs,motion;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
                if (dirtybuffer[offs])
                {
                        int charcode;
                        int sx,sy;
      int flipx;
                        int color;
                        dirtybuffer[offs]=0;
                        charcode = videoram[offs];
                        color = (charcode & 0x40) >> 6;
      flipx = (charcode & 0x80) >> 7;
                        charcode = ((charcode & 0x0F) << 2) | ((charcode & 0x30) >> 4);
                        sx = 8 * (offs % 32);
                        sy = 8 * (offs / 32);
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                charcode, color,
        flipx,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
                }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (motion=0;motion<16;motion++)
 {
  int pic,sx,sy,color,flipx;
  pic = bsktball_motion[motion*4];
  sy = 28*8 - bsktball_motion[motion*4 + 1];
  sx = bsktball_motion[motion*4 + 2];
  color = bsktball_motion[motion*4 + 3];
  flipx = (pic & 0x80) >> 7;
  pic = (pic & 0x3F);
        color = (color & 0x3F);
        drawgfx(bitmap,Machine->gfx[1],
                pic, color,
    flipx,0,sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

canonical_original_code:
void bsktball_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh)
{
    int offs; int motion;
 for (offs = videoram_size - 1;offs >= 0;offs--)
 {
                if (dirtybuffer[offs])
                {
                        int charcode;
                        int sx; int sy;
      int flipx;
                        int color;
                        dirtybuffer[offs]=0;
                        charcode = videoram[offs];
                        color = (charcode & 0x40) >> 6;
      flipx = (charcode & 0x80) >> 7;
                        charcode = ((charcode & 0x0F) << 2) | ((charcode & 0x30) >> 4);
                        sx = 8 * (offs % 32);
                        sy = 8 * (offs / 32);
                        drawgfx(tmpbitmap,Machine->gfx[0],
                                charcode, color,
        flipx,0,sx,sy,
     &Machine->visible_area,TRANSPARENCY_NONE,0);
                }
 }
 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
 for (motion=0;motion<16;motion++)
 {
  int pic; int sx; int sy; int color; int flipx;
  pic = bsktball_motion[motion*4];
  sy = 28*8 - bsktball_motion[motion*4 + 1];
  sx = bsktball_motion[motion*4 + 2];
  color = bsktball_motion[motion*4 + 3];
  flipx = (pic & 0x80) >> 7;
  pic = (pic & 0x3F);
        color = (color & 0x3F);
        drawgfx(bitmap,Machine->gfx[1],
                pic, color,
    flipx,0,sx,sy,
    &Machine->visible_area,TRANSPARENCY_PEN,0);
 }
}

variable_types: motion int

variable_types: charcode int

variable_types: sx int

variable_types: sy int

variable_types: flipx int

variable_types: color int

variable_types: pic int


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

v0 = i256V_8 + 1;
i256V_8 = (i256V_8 + 1) % 8;
if ( (v0 & 7) == 0 )
return interrupt();
if ( NMION )
return nmi_interrupt();
return 0LL;
}

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

v0 = i256V_8 + 1;
i256V_8 = (i256V_8 + 1) % 8;
if ( (v0 & 7) == 0 )
return interrupt();
if ( NMION )
return nmi_interrupt();
return 0LL;
}

original_code:
int bsktball_interrupt(void)
{
 static int i256V=0;
 i256V=(i256V+1) % 8;
 if (i256V==0)
  return interrupt();
 else if (NMION)
  return nmi_interrupt();
 else
  return 0;
}

canonical_original_code:
int bsktball_interrupt()
{
 static int i256V = 0;
 i256V=(i256V+1) % 8;
 if (i256V==0)
  return interrupt();
 else if (NMION)
  return nmi_interrupt();
 else
  return 0;
}


decompiled_code:
__int64 __fastcall bsktball_in0_r(unsigned int a1, __int64 a2)
{
int v2; // er13
int v3; // er12
int v4; // ebx
int v5; // eax
int v6; // edx
bool v7; // cc
int v8; // edx
bool v9; // cc
int v10; // edx
bool v11; // cc
char v13; // al

v2 = input_port_0_r();
v3 = input_port_1_r(a1);
v4 = input_port_2_r(a1);
v5 = input_port_3_r(a1);
if ( last_p1_horiz_7 >= v2 )
{
if ( last_p1_horiz_7 <= v2 )
{
LABEL_4:
v6 = last_p1_vert_5;
v7 = last_p1_vert_5 <= v3;
if ( last_p1_vert_5 < v3 )
goto LABEL_5;
goto LABEL_19;
}
if ( last_p1_horiz_7 - v2 > 128 )
{
LABEL_3:
DR2_6 = 0;
goto LABEL_4;
}
}
else if ( v2 - last_p1_horiz_7 <= 128 )
{
goto LABEL_3;
}
DR2_6 = 64;
v6 = last_p1_vert_5;
v7 = last_p1_vert_5 <= v3;
if ( last_p1_vert_5 < v3 )
{
LABEL_5:
if ( v3 - v6 > 128 )
goto LABEL_6;
goto LABEL_21;
}
LABEL_19:
if ( v7 )
{
LABEL_7:
v8 = last_p2_horiz_3;
v9 = last_p2_horiz_3 <= v4;
if ( last_p2_horiz_3 < v4 )
goto LABEL_8;
goto LABEL_22;
}
if ( v6 - v3 <= 128 )
{
LABEL_6:
DR3_4 = 0;
goto LABEL_7;
}
LABEL_21:
DR3_4 = 128;
v8 = last_p2_horiz_3;
v9 = last_p2_horiz_3 <= v4;
if ( last_p2_horiz_3 < v4 )
{
LABEL_8:
if ( v4 - v8 > 128 )
goto LABEL_9;
goto LABEL_24;
}
LABEL_22:
if ( v9 )
{
LABEL_10:
v10 = last_p2_vert_1;
v11 = last_p2_vert_1 <= v5;
if ( last_p2_vert_1 < v5 )
goto LABEL_11;
goto LABEL_25;
}
if ( v8 - v4 <= 128 )
{
LABEL_9:
DR0_2 = 16;
goto LABEL_10;
}
LABEL_24:
DR0_2 = 0;
v10 = last_p2_vert_1;
v11 = last_p2_vert_1 <= v5;
if ( last_p2_vert_1 < v5 )
{
LABEL_11:
if ( v5 - v10 > 128 )
{
LABEL_12:
DR1_0 = 0;
goto LABEL_13;
}
goto LABEL_27;
}
LABEL_25:
if ( v11 )
goto LABEL_13;
if ( v10 - v5 <= 128 )
goto LABEL_12;
LABEL_27:
DR1_0 = 32;
LABEL_13:
last_p1_horiz_7 = v2;
last_p1_vert_5 = v3;
last_p2_horiz_3 = v4;
last_p2_vert_1 = v5;
if ( (LD1 & LD2) != 0 )
return v2 & 0xF | (unsigned int)(unsigned __int8)(16 * v3);
if ( LD2 )
return v4 & 0xF | (unsigned int)(unsigned __int8)(16 * v5);
v13 = input_port_4_r(a1, a2, (unsigned int)LD2, LD1 & (unsigned int)LD2);
return ((v13 & 0xF) >> 2) & v13 & 0xF | DR3_4 | DR2_6 | DR1_0 | (unsigned int)DR0_2;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, __int64 a2)
{
int v2; // er13
int v3; // er12
int v4; // ebx
int v5; // eax
int v6; // edx
bool v7; // cc
int v8; // edx
bool v9; // cc
int v10; // edx
bool v11; // cc
char v13; // al

v2 = input_port_0_r();
v3 = input_port_1_r(a1);
v4 = input_port_2_r(a1);
v5 = input_port_3_r(a1);
if ( last_p1_horiz_7 >= v2 )
{
if ( last_p1_horiz_7 <= v2 )
{
LABEL_4:
v6 = last_p1_vert_5;
v7 = last_p1_vert_5 <= v3;
if ( last_p1_vert_5 < v3 )
goto LABEL_5;
goto LABEL_19;
}
if ( last_p1_horiz_7 - v2 > 128 )
{
LABEL_3:
DR2_6 = 0;
goto LABEL_4;
}
}
else if ( v2 - last_p1_horiz_7 <= 128 )
{
goto LABEL_3;
}
DR2_6 = 64;
v6 = last_p1_vert_5;
v7 = last_p1_vert_5 <= v3;
if ( last_p1_vert_5 < v3 )
{
LABEL_5:
if ( v3 - v6 > 128 )
goto LABEL_6;
goto LABEL_21;
}
LABEL_19:
if ( v7 )
{
LABEL_7:
v8 = last_p2_horiz_3;
v9 = last_p2_horiz_3 <= v4;
if ( last_p2_horiz_3 < v4 )
goto LABEL_8;
goto LABEL_22;
}
if ( v6 - v3 <= 128 )
{
LABEL_6:
DR3_4 = 0;
goto LABEL_7;
}
LABEL_21:
DR3_4 = 128;
v8 = last_p2_horiz_3;
v9 = last_p2_horiz_3 <= v4;
if ( last_p2_horiz_3 < v4 )
{
LABEL_8:
if ( v4 - v8 > 128 )
goto LABEL_9;
goto LABEL_24;
}
LABEL_22:
if ( v9 )
{
LABEL_10:
v10 = last_p2_vert_1;
v11 = last_p2_vert_1 <= v5;
if ( last_p2_vert_1 < v5 )
goto LABEL_11;
goto LABEL_25;
}
if ( v8 - v4 <= 128 )
{
LABEL_9:
DR0_2 = 16;
goto LABEL_10;
}
LABEL_24:
DR0_2 = 0;
v10 = last_p2_vert_1;
v11 = last_p2_vert_1 <= v5;
if ( last_p2_vert_1 < v5 )
{
LABEL_11:
if ( v5 - v10 > 128 )
{
LABEL_12:
DR1_0 = 0;
goto LABEL_13;
}
goto LABEL_27;
}
LABEL_25:
if ( v11 )
goto LABEL_13;
if ( v10 - v5 <= 128 )
goto LABEL_12;
LABEL_27:
DR1_0 = 32;
LABEL_13:
last_p1_horiz_7 = v2;
last_p1_vert_5 = v3;
last_p2_horiz_3 = v4;
last_p2_vert_1 = v5;
if ( (LD1 & LD2) != 0 )
return v2 & 0xF | (unsigned int)(unsigned __int8)(16 * v3);
if ( LD2 )
return v4 & 0xF | (unsigned int)(unsigned __int8)(16 * v5);
v13 = input_port_4_r(a1, a2, (unsigned int)LD2, LD1 & (unsigned int)LD2);
return ((v13 & 0xF) >> 2) & v13 & 0xF | DR3_4 | DR2_6 | DR1_0 | (unsigned int)DR0_2;
}

original_code:
data_t bsktball_in0_r(offs_t offset)
{
 static int DR0=0;
 static int DR1=0;
 static int DR2=0;
 static int DR3=0;
 static int last_p1_horiz=0;
 static int last_p1_vert=0;
 static int last_p2_horiz=0;
 static int last_p2_vert=0;
 int p1_horiz;
 int p1_vert;
 int p2_horiz;
 int p2_vert;
 int temp;
 p1_horiz = input_port_0_r(offset);
 p1_vert = input_port_1_r(offset);
 p2_horiz = input_port_2_r(offset);
 p2_vert = input_port_3_r(offset);
 if (p1_horiz > last_p1_horiz)
 {
  if ((p1_horiz-last_p1_horiz) > 128) DR2=0x40;
  else DR2=0;
 }
 else if (p1_horiz < last_p1_horiz)
 {
  if ((last_p1_horiz-p1_horiz) > 128) DR2=0;
  else DR2=0x40;
 }
 if (p1_vert > last_p1_vert)
 {
  if ((p1_vert-last_p1_vert) > 128) DR3=0;
  else DR3=0x80;
 }
 else if (p1_vert < last_p1_vert)
 {
  if ((last_p1_vert-p1_vert) > 128) DR3=0x80;
  else DR3=0;
 }
 if (p2_horiz > last_p2_horiz)
 {
  if ((p2_horiz-last_p2_horiz) > 128) DR0=0x10;
  else DR0=0;
 }
 else if (p2_horiz < last_p2_horiz)
 {
  if ((last_p2_horiz-p2_horiz) > 128) DR0=0;
  else DR0=0x10;
 }
 if (p2_vert > last_p2_vert)
 {
  if ((p2_vert-last_p2_vert) > 128) DR1=0;
  else DR1=0x20;
 }
 else if (p2_vert < last_p2_vert)
 {
  if ((last_p2_vert-p2_vert) > 128) DR1=0x20;
  else DR1=0;
 }
 last_p1_horiz = p1_horiz;
 last_p1_vert = p1_vert;
 last_p2_horiz = p2_horiz;
 last_p2_vert = p2_vert;
 if ((LD1) & (LD2))
 {
  return ((p1_horiz & 0x0F) | ((p1_vert << 4) & 0xF0));
 }
 else if (LD2)
 {
  return ((p2_horiz & 0x0F) | ((p2_vert << 4) & 0xF0));
 }
 else
 {
  temp = input_port_4_r(offset) & 0x0F;
  temp = (temp) & (temp>>2);
  return (temp | DR0 | DR1 | DR2 | DR3);
 }
}

canonical_original_code:
unsigned int bsktball_in0_r(unsigned int offset)
{
 static int DR0 = 0;
 static int DR1 = 0;
 static int DR2 = 0;
 static int DR3 = 0;
 static int last_p1_horiz = 0;
 static int last_p1_vert = 0;
 static int last_p2_horiz = 0;
 static int last_p2_vert = 0;
 int p1_horiz;
 int p1_vert;
 int p2_horiz;
 int p2_vert;
 int temp;
 p1_horiz = input_port_0_r(offset);
 p1_vert = input_port_1_r(offset);
 p2_horiz = input_port_2_r(offset);
 p2_vert = input_port_3_r(offset);
 if (p1_horiz > last_p1_horiz)
 {
  if ((p1_horiz-last_p1_horiz) > 128) DR2=0x40;
  else DR2=0;
 }
 else if (p1_horiz < last_p1_horiz)
 {
  if ((last_p1_horiz-p1_horiz) > 128) DR2=0;
  else DR2=0x40;
 }
 if (p1_vert > last_p1_vert)
 {
  if ((p1_vert-last_p1_vert) > 128) DR3=0;
  else DR3=0x80;
 }
 else if (p1_vert < last_p1_vert)
 {
  if ((last_p1_vert-p1_vert) > 128) DR3=0x80;
  else DR3=0;
 }
 if (p2_horiz > last_p2_horiz)
 {
  if ((p2_horiz-last_p2_horiz) > 128) DR0=0x10;
  else DR0=0;
 }
 else if (p2_horiz < last_p2_horiz)
 {
  if ((last_p2_horiz-p2_horiz) > 128) DR0=0;
  else DR0=0x10;
 }
 if (p2_vert > last_p2_vert)
 {
  if ((p2_vert-last_p2_vert) > 128) DR1=0;
  else DR1=0x20;
 }
 else if (p2_vert < last_p2_vert)
 {
  if ((last_p2_vert-p2_vert) > 128) DR1=0x20;
  else DR1=0;
 }
 last_p1_horiz = p1_horiz;
 last_p1_vert = p1_vert;
 last_p2_horiz = p2_horiz;
 last_p2_vert = p2_vert;
 if ((LD1) & (LD2))
 {
  return ((p1_horiz & 0x0F) | ((p1_vert << 4) & 0xF0));
 }
 else if (LD2)
 {
  return ((p2_horiz & 0x0F) | ((p2_vert << 4) & 0xF0));
 }
 else
 {
  temp = input_port_4_r(offset) & 0x0F;
  temp = (temp) & (temp>>2);
  return (temp | DR0 | DR1 | DR2 | DR3);
 }
}

variable_types:
offset
unsigned int

variable_types: temp int


decompiled_code:
__int64 __fastcall bsktball_led1_w(char a1)
{
return osd_led_w(0LL, a1 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func6(char a1)
{
return osd_led_w(0LL, a1 & 1);
}

original_code:
void bsktball_led1_w(offs_t offset,data_t data)
{
        osd_led_w(0,(offset & 0x01));
}

canonical_original_code:
void bsktball_led1_w(unsigned int offset, unsigned int data)
{
        osd_led_w(0,(offset & 0x01));
}

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall bsktball_led2_w(char a1)
{
return osd_led_w(1LL, a1 & 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return osd_led_w(1LL, a1 & 1);
}

original_code:
void bsktball_led2_w(offs_t offset,data_t data)
{
        osd_led_w(1,(offset & 0x01));
}

canonical_original_code:
void bsktball_led2_w(unsigned int offset, unsigned int data)
{
        osd_led_w(1,(offset & 0x01));
}


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

result = (unsigned int)init_timer;
note_timer = a2;
note_count = 256;
if ( init_timer )
{
if ( a2 != 255 )
{
result = timer_set(22724LL, 0LL, bsktball_note_32H);
init_timer = 0;
}
}
return result;
}

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

result = (unsigned int)init_timer;
note_timer = a2;
note_count = 256;
if ( init_timer )
{
if ( a2 != 255 )
{
result = timer_set(22724LL, 0LL, bsktball_note_32H);
init_timer = 0;
}
}
return result;
}

original_code:
static void bsktball_note_w(offs_t offset,data_t data)
{
 note_timer=data;
 note_count=256;
 if ((init_timer) && (note_timer!=255))
 {
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_note_32H);
  init_timer=0;
 }
}

canonical_original_code:
static void bsktball_note_w(unsigned int offset, unsigned int data)
{
 note_timer=data;
 note_count=256;
 if ((init_timer) && (note_timer!=255))
 {
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_note_32H);
  init_timer=0;
 }
}


decompiled_code:
__int64 bsktball_note_32H()
{
int v0; // edx
__int64 result; // rax

v0 = note_count - 1;
note_count = v0;
if ( v0 == note_timer )
{
note_count = 256;
v0 = 256;
}
if ( note_timer + ((256 - note_timer) >> 1) >= v0 )
{
result = DAC_data_w(0LL, 0LL);
if ( note_timer == 255 )
goto LABEL_5;
}
else
{
result = DAC_data_w(0LL, 255LL);
if ( note_timer == 255 )
{
LABEL_5:
init_timer = 1;
return result;
}
}
return timer_set(22724LL, 0LL, bsktball_note_32H);
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // edx
__int64 result; // rax

v0 = note_count - 1;
note_count = v0;
if ( v0 == note_timer )
{
note_count = 256;
v0 = 256;
}
if ( note_timer + ((256 - note_timer) >> 1) >= v0 )
{
result = DAC_data_w(0LL, 0LL);
if ( note_timer == 255 )
goto LABEL_5;
}
else
{
result = DAC_data_w(0LL, 255LL);
if ( note_timer == 255 )
{
LABEL_5:
init_timer = 1;
return result;
}
}
return timer_set(22724LL, 0LL, bsktball_note_32H);
}

original_code:
static void bsktball_note_32H(int foo)
{
 note_count--;
 if (note_count==note_timer)
  note_count=256;
 if (note_count > ((256-note_timer)>>1)+note_timer)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if (note_timer!=255)
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_note_32H);
 else
  init_timer=1;
}

canonical_original_code:
static void bsktball_note_32H(int foo)
{
 note_count--;
 if (note_count==note_timer)
  note_count=256;
 if (note_count > ((256-note_timer)>>1)+note_timer)
  DAC_data_w(0,255);
 else
  DAC_data_w(0,0);
 if (note_timer!=255)
  timer_set ((((INT64)(10582*2)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_note_32H);
 else
  init_timer=1;
}

variable_types: foo int


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

noise_a10 = 0;
noise_b10 = 0;
DAC_data_w(2LL, 0LL);
result = (unsigned int)noise_timer_set;
if ( !noise_timer_set )
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

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

noise_a10 = 0;
noise_b10 = 0;
DAC_data_w(2LL, 0LL);
result = (unsigned int)noise_timer_set;
if ( !noise_timer_set )
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

original_code:
static void bsktball_noise_reset_w(offs_t offset,data_t data)
{
 noise_a10=0;
 noise_b10=0;
 DAC_data_w(2,0);
 if (!noise_timer_set)
  timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}

canonical_original_code:
static void bsktball_noise_reset_w(unsigned int offset, unsigned int data)
{
 noise_a10=0;
 noise_b10=0;
 DAC_data_w(2,0);
 if (!noise_timer_set)
  timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}


decompiled_code:
__int64 bsktball_noise_256H()
{
int v0; // edx
__int64 result; // rax

v0 = (unsigned __int8)((2 * noise_b10) | (noise_b10 ^ (~noise_a10 >> 6)) & 1);
noise_a10 = (unsigned __int8)((2 * noise_a10) | (noise_b10 >> 7) & 1);
noise_b10 = v0;
noise = noise_a10 >> 7;
if ( noise_a10 >> 7 )
DAC_data_w(2LL, (unsigned int)crowd_mask);
else
DAC_data_w(2LL, 0LL);
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

canonical_decompiled_code:
__int64 func12()
{
int v0; // edx
__int64 result; // rax

v0 = (unsigned __int8)((2 * noise_b10) | (noise_b10 ^ (~noise_a10 >> 6)) & 1);
noise_a10 = (unsigned __int8)((2 * noise_a10) | (noise_b10 >> 7) & 1);
noise_b10 = v0;
noise = noise_a10 >> 7;
if ( noise_a10 >> 7 )
DAC_data_w(2LL, (unsigned int)crowd_mask);
else
DAC_data_w(2LL, 0LL);
result = timer_set(90898LL, 0LL, bsktball_noise_256H);
noise_timer_set = 1;
return result;
}

original_code:
static void bsktball_noise_256H(int foo)
{
 int b10_input;
 int a10_input;
 b10_input = (noise_b10 & 0x01) ^ (((~noise_a10) & 0x40) >> 6);
 a10_input = (noise_b10 & 0x80) >> 7;
 noise_b10 = ((noise_b10 << 1) | b10_input) & 0xFF;
 noise_a10 = ((noise_a10 << 1) | a10_input) & 0xFF;
 noise = (noise_a10 & 0x80) >> 7;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(INT64)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}

canonical_original_code:
static void bsktball_noise_256H(int foo)
{
 int b10_input;
 int a10_input;
 b10_input = (noise_b10 & 0x01) ^ (((~noise_a10) & 0x40) >> 6);
 a10_input = (noise_b10 & 0x80) >> 7;
 noise_b10 = ((noise_b10 << 1) | b10_input) & 0xFF;
 noise_a10 = ((noise_a10 << 1) | a10_input) & 0xFF;
 noise = (noise_a10 & 0x80) >> 7;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 timer_set ((((INT64)(10582*2*4)*(INT64)((1<<30)))/(long long)1000000000), 0, bsktball_noise_256H);
 noise_timer_set=1;
}


decompiled_code:
__int64 __fastcall bsktball_bounce_w(__int64 a1, char a2)
{
__int64 v3; // rsi
__int64 result; // rax

v3 = (unsigned __int8)(16 * a2);
crowd_mask = v3;
if ( !noise )
v3 = 0LL;
DAC_data_w(2LL, v3);
if ( (a2 & 0x10) != 0 )
result = DAC_data_w(1LL, 255LL);
else
result = DAC_data_w(1LL, 0LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, char a2)
{
__int64 v3; // rsi
__int64 result; // rax

v3 = (unsigned __int8)(16 * a2);
crowd_mask = v3;
if ( !noise )
v3 = 0LL;
DAC_data_w(2LL, v3);
if ( (a2 & 0x10) != 0 )
result = DAC_data_w(1LL, 255LL);
else
result = DAC_data_w(1LL, 0LL);
return result;
}

original_code:
static void bsktball_bounce_w(offs_t offset,data_t data)
{
 crowd_mask = (data & 0x0F) << 4;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 if (data & 0x10)
  DAC_data_w(1,255);
 else
  DAC_data_w(1,0);
}

canonical_original_code:
static void bsktball_bounce_w(unsigned int offset, unsigned int data)
{
 crowd_mask = (data & 0x0F) << 4;
 if (noise)
  DAC_data_w(2,crowd_mask);
 else
  DAC_data_w(2,0);
 if (data & 0x10)
  DAC_data_w(1,255);
 else
  DAC_data_w(1,0);
}


decompiled_code:
__int64 __fastcall init_palette(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

*(_DWORD *)(a1 + 8) = -176;
*(_QWORD *)a1 = 0x5050808080000000LL;
*a2 = colortable;
result = qword_948;
a2[65] = qword_948;
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&colortable - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 528) >> 3));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

*(_DWORD *)(a1 + 8) = -176;
*(_QWORD *)a1 = 0x5050808080000000LL;
*a2 = colortable;
result = qword_948;
a2[65] = qword_948;
qmemcpy(
(void *)((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL),
(const void *)((char *)&colortable - ((char *)a2 - ((unsigned __int64)(a2 + 1) & 0xFFFFFFFFFFFFFFF8LL))),
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 528) >> 3));
return result;
}

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));
}


casencmp

decompiled_code:
__int64 __fastcall casencmp(__int64 a1, __int64 a2, __int64 a3)
{
const __int32_t *v5; // rcx
__int64 v6; // rax
__int32_t v7; // edx
__int32_t v8; // esi

if ( !a3 )
return 0LL;
v5 = *_ctype_tolower_loc();
v6 = 0LL;
do
{
v7 = v5[*(char *)(a1 + v6)];
v8 = v5[*(char *)(a2 + v6)];
if ( v8 != v7 )
return (unsigned int)(v7 - v8);
++v6;
}
while ( v6 != a3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
const __int32_t *v5; // rcx
__int64 v6; // rax
__int32_t v7; // edx
__int32_t v8; // esi

if ( !a3 )
return 0LL;
v5 = *_ctype_tolower_loc();
v6 = 0LL;
do
{
v7 = v5[*(char *)(a1 + v6)];
v8 = v5[*(char *)(a2 + v6)];
if ( v8 != v7 )
return (unsigned int)(v7 - v8);
++v6;
}
while ( v6 != a3 );
return 0LL;
}

original_code:
static int casencmp(const char *a, const char *b, size_t n)
{
   size_t i;
   for (i = 0; i < n; i++)
   {
      int a_lower = tolower(a[i]);
      int b_lower = tolower(b[i]);
      if (a_lower != b_lower)
         return a_lower - b_lower;
   }
   return 0;
}

canonical_original_code:
static int casencmp(char *a, char *b, unsigned long n)
{
   unsigned long i;
   for (i = 0; i < n; i++)
   {
      int a_lower = tolower(a[i]);
      int b_lower = tolower(b[i]);
      if (a_lower != b_lower)
         return a_lower - b_lower;
   }
   return 0;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
n
unsigned long

variable_types:
i
unsigned long


decompiled_code:
const char *__fastcall strcasestr_retro__(const char *a1, const char *a2)
{
size_t v2; // rbp
size_t v3; // rax
__int64 v4; // r15
size_t v5; // rbp
__int64 v6; // rbx
const char *v7; // r12

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 < v3 )
return 0LL;
v4 = v3;
v5 = v2 - v3;
v6 = 0LL;
while ( 1 )
{
v7 = &a1[v6];
if ( !(unsigned int)casencmp((__int64)&a1[v6], (__int64)a2, v4) )
break;
if ( v5 < ++v6 )
return 0LL;
}
return v7;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1, const char *a2)
{
size_t v2; // rbp
size_t v3; // rax
__int64 v4; // r15
size_t v5; // rbp
__int64 v6; // rbx
const char *v7; // r12

v2 = strlen(a1);
v3 = strlen(a2);
if ( v2 < v3 )
return 0LL;
v4 = v3;
v5 = v2 - v3;
v6 = 0LL;
while ( 1 )
{
v7 = &a1[v6];
if ( !(unsigned int)func0((__int64)&a1[v6], (__int64)a2, v4) )
break;
if ( v5 < ++v6 )
return 0LL;
}
return v7;
}

original_code:
char *strcasestr_retro__(const char *haystack, const char *needle)
{
   size_t i, search_off;
   size_t hay_len = strlen(haystack);
   size_t needle_len = strlen(needle);
   if (needle_len > hay_len)
      return ((void *)0);
   search_off = hay_len - needle_len;
   for (i = 0; i <= search_off; i++)
      if (!casencmp(haystack + i, needle, needle_len))
         return (char*)haystack + i;
   return ((void *)0);
}

canonical_original_code:
char *strcasestr_retro__(char *haystack, char *needle)
{
   unsigned long i; unsigned long search_off;
   unsigned long hay_len = strlen(haystack);
   unsigned long needle_len = strlen(needle);
   if (needle_len > hay_len)
      return ((void *)0);
   search_off = hay_len - needle_len;
   for (i = 0; i <= search_off; i++)
      if (!casencmp(haystack + i, needle, needle_len))
         return (char *)haystack + i;
   return ((void *)0);
}

variable_types:
haystack
char *

variable_types:
needle
char *

return_type: char *


decompiled_code:
__int64 __fastcall carnival_sh_port1_w(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
char v4; // bl
char v5; // bp

v2 = port1State_1;
port1State_1 = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( (v4 & 1) != 0 )
{
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v5 & 2) == 0 )
goto LABEL_4;
goto LABEL_16;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(3LL, 3LL, 0LL);
if ( (v5 & 2) == 0 )
{
LABEL_4:
if ( (v4 & 4) == 0 )
goto LABEL_5;
goto LABEL_17;
}
LABEL_16:
result = sample_stop(3LL);
if ( (v4 & 4) == 0 )
{
LABEL_5:
if ( (v5 & 4) == 0 )
goto LABEL_6;
goto LABEL_18;
}
LABEL_17:
result = sample_start(4LL, 4LL, 1LL);
if ( (v5 & 4) == 0 )
{
LABEL_6:
if ( (v4 & 8) == 0 )
goto LABEL_7;
goto LABEL_19;
}
LABEL_18:
result = sample_stop(4LL);
if ( (v4 & 8) == 0 )
{
LABEL_7:
if ( (v5 & 8) == 0 )
goto LABEL_8;
goto LABEL_20;
}
LABEL_19:
result = sample_start(5LL, 5LL, 1LL);
if ( (v5 & 8) == 0 )
{
LABEL_8:
if ( (v4 & 0x10) == 0 )
goto LABEL_9;
goto LABEL_21;
}
LABEL_20:
result = sample_stop(5LL);
if ( (v4 & 0x10) == 0 )
{
LABEL_9:
if ( (v5 & 0x10) == 0 )
goto LABEL_10;
goto LABEL_22;
}
LABEL_21:
result = sample_start(6LL, 6LL, 1LL);
if ( (v5 & 0x10) == 0 )
{
LABEL_10:
if ( (v4 & 0x20) == 0 )
goto LABEL_11;
goto LABEL_23;
}
LABEL_22:
result = sample_stop(6LL);
if ( (v4 & 0x20) == 0 )
{
LABEL_11:
if ( (v4 & 0x40) == 0 )
goto LABEL_12;
goto LABEL_24;
}
LABEL_23:
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 0x40) == 0 )
{
LABEL_12:
if ( (v4 & 0x80) == 0 )
return result;
return sample_start(2LL, 2LL, 0LL);
}
LABEL_24:
result = sample_start(1LL, 1LL, 0LL);
if ( (v4 & 0x80) != 0 )
return sample_start(2LL, 2LL, 0LL);
return result;
}

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

v2 = port1State_1;
port1State_1 = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( (v4 & 1) != 0 )
{
result = sample_start(9LL, 9LL, 0LL);
if ( (v4 & 2) == 0 )
{
LABEL_3:
if ( (v5 & 2) == 0 )
goto LABEL_4;
goto LABEL_16;
}
}
else if ( (v4 & 2) == 0 )
{
goto LABEL_3;
}
result = sample_start(3LL, 3LL, 0LL);
if ( (v5 & 2) == 0 )
{
LABEL_4:
if ( (v4 & 4) == 0 )
goto LABEL_5;
goto LABEL_17;
}
LABEL_16:
result = sample_stop(3LL);
if ( (v4 & 4) == 0 )
{
LABEL_5:
if ( (v5 & 4) == 0 )
goto LABEL_6;
goto LABEL_18;
}
LABEL_17:
result = sample_start(4LL, 4LL, 1LL);
if ( (v5 & 4) == 0 )
{
LABEL_6:
if ( (v4 & 8) == 0 )
goto LABEL_7;
goto LABEL_19;
}
LABEL_18:
result = sample_stop(4LL);
if ( (v4 & 8) == 0 )
{
LABEL_7:
if ( (v5 & 8) == 0 )
goto LABEL_8;
goto LABEL_20;
}
LABEL_19:
result = sample_start(5LL, 5LL, 1LL);
if ( (v5 & 8) == 0 )
{
LABEL_8:
if ( (v4 & 0x10) == 0 )
goto LABEL_9;
goto LABEL_21;
}
LABEL_20:
result = sample_stop(5LL);
if ( (v4 & 0x10) == 0 )
{
LABEL_9:
if ( (v5 & 0x10) == 0 )
goto LABEL_10;
goto LABEL_22;
}
LABEL_21:
result = sample_start(6LL, 6LL, 1LL);
if ( (v5 & 0x10) == 0 )
{
LABEL_10:
if ( (v4 & 0x20) == 0 )
goto LABEL_11;
goto LABEL_23;
}
LABEL_22:
result = sample_stop(6LL);
if ( (v4 & 0x20) == 0 )
{
LABEL_11:
if ( (v4 & 0x40) == 0 )
goto LABEL_12;
goto LABEL_24;
}
LABEL_23:
result = sample_start(7LL, 7LL, 0LL);
if ( (v4 & 0x40) == 0 )
{
LABEL_12:
if ( (v4 & 0x80) == 0 )
return result;
return sample_start(2LL, 2LL, 0LL);
}
LABEL_24:
result = sample_start(1LL, 1LL, 0LL);
if ( (v4 & 0x80) != 0 )
return sample_start(2LL, 2LL, 0LL);
return result;
}

original_code:
void carnival_sh_port1_w(offs_t offset,data_t data)
{
 static int port1State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_RIFLE_SHOT, SND_RIFLE_SHOT, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_DUCK_1, SND_DUCK_1, 1 );
 }
 if ( bitsGoneHigh & 0x04 )
 {
  sample_stop( SND_DUCK_1 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_DUCK_2, SND_DUCK_2, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_DUCK_2 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_DUCK_3, SND_DUCK_3, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_DUCK_3 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PIPE_HIT, SND_PIPE_HIT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS_1, SND_BONUS_1, 0 );
 }
 if ( bitsGoneLow & 0x80 )
 {
  sample_start( SND_BONUS_2, SND_BONUS_2, 0 );
 }
}

canonical_original_code:
void carnival_sh_port1_w(unsigned int offset, unsigned int data)
{
 static int port1State = 0;
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port1State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port1State = data;
 if ( bitsGoneLow & 0x01 )
 {
  sample_start( SND_RIFLE_SHOT, SND_RIFLE_SHOT, 0 );
 }
 if ( bitsGoneLow & 0x02 )
 {
  sample_start( SND_CLANG, SND_CLANG, 0 );
 }
 if ( bitsGoneHigh & 0x02 )
 {
  sample_stop( SND_CLANG );
 }
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_DUCK_1, SND_DUCK_1, 1 );
 }
 if ( bitsGoneHigh & 0x04 )
 {
  sample_stop( SND_DUCK_1 );
 }
 if ( bitsGoneLow & 0x08 )
 {
  sample_start( SND_DUCK_2, SND_DUCK_2, 1 );
 }
 if ( bitsGoneHigh & 0x08 )
 {
  sample_stop( SND_DUCK_2 );
 }
 if ( bitsGoneLow & 0x10 )
 {
  sample_start( SND_DUCK_3, SND_DUCK_3, 1 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  sample_stop( SND_DUCK_3 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_PIPE_HIT, SND_PIPE_HIT, 0 );
 }
 if ( bitsGoneLow & 0x40 )
 {
  sample_start( SND_BONUS_1, SND_BONUS_1, 0 );
 }
 if ( bitsGoneLow & 0x80 )
 {
  sample_start( SND_BONUS_2, SND_BONUS_2, 0 );
 }
}

variable_types: bitsChanged int

variable_types: bitsGoneHigh int

variable_types: bitsGoneLow int


decompiled_code:
__int64 __fastcall carnival_sh_port2_w(__int64 a1, int a2)
{
int v2; // eax
__int64 result; // rax
char v4; // bl
char v5; // bp

v2 = port2State;
port2State = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( (v4 & 4) != 0 )
{
result = sample_start(0LL, 0LL, 0LL);
if ( (v4 & 0x20) == 0 )
{
LABEL_3:
if ( (v5 & 0x10) == 0 )
return result;
return cpu_set_reset_line(1LL, 3LL);
}
}
else if ( ((unsigned __int8)result & (unsigned __int8)~(_BYTE)a2 & 0x20) == 0 )
{
goto LABEL_3;
}
result = sample_start(8LL, 8LL, 0LL);
if ( (v5 & 0x10) != 0 )
return cpu_set_reset_line(1LL, 3LL);
return result;
}

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

v2 = port2State;
port2State = a2;
result = a2 ^ (unsigned int)v2;
v4 = result & ~(_BYTE)a2;
v5 = a2 & result;
if ( (v4 & 4) != 0 )
{
result = sample_start(0LL, 0LL, 0LL);
if ( (v4 & 0x20) == 0 )
{
LABEL_3:
if ( (v5 & 0x10) == 0 )
return result;
return cpu_set_reset_line(1LL, 3LL);
}
}
else if ( ((unsigned __int8)result & (unsigned __int8)~(_BYTE)a2 & 0x20) == 0 )
{
goto LABEL_3;
}
result = sample_start(8LL, 8LL, 0LL);
if ( (v5 & 0x10) != 0 )
return cpu_set_reset_line(1LL, 3LL);
return result;
}

original_code:
void carnival_sh_port2_w(offs_t offset,data_t data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BEAR, SND_BEAR, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_RANKING, SND_RANKING, 0 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  cpu_set_reset_line( 1, 3 );
 }
}

canonical_original_code:
void carnival_sh_port2_w(unsigned int offset, unsigned int data)
{
 int bitsChanged;
 int bitsGoneHigh;
 int bitsGoneLow;
 bitsChanged = port2State ^ data;
 bitsGoneHigh = bitsChanged & data;
 bitsGoneLow = bitsChanged & ~data;
 port2State = data;
 if ( bitsGoneLow & 0x04 )
 {
  sample_start( SND_BEAR, SND_BEAR, 0 );
 }
 if ( bitsGoneLow & 0x20 )
 {
  sample_start( SND_RANKING, SND_RANKING, 0 );
 }
 if ( bitsGoneHigh & 0x10 )
 {
  cpu_set_reset_line( 1, 3 );
 }
}


decompiled_code:
_BOOL8 carnival_music_port_t1_r()
{
return (port2State & 8) == 0;
}

canonical_decompiled_code:
_BOOL8 func2()
{
return (port2State & 8) == 0;
}

original_code:
data_t carnival_music_port_t1_r(offs_t offset)
{
 return ( port2State & 0x08 ) ? 0 : 1;
}

canonical_original_code:
unsigned int carnival_music_port_t1_r(unsigned int offset)
{
 return ( port2State & 0x08 ) ? 0 : 1;
}


decompiled_code:
void __fastcall carnival_music_port_1_w(__int64 a1, int a2)
{
psgData = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
psgData = a2;
}

original_code:
void carnival_music_port_1_w(offs_t offset,data_t data)
{
 psgData = data;
}

canonical_original_code:
void carnival_music_port_1_w(unsigned int offset, unsigned int data)
{
 psgData = data;
}


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

v2 = a2 & 0xC0;
if ( psgSelect_0 != v2 )
{
psgSelect_0 = v2;
if ( v2 == 64 )
{
result = AY8910_write_port_0_w(0LL, (unsigned int)psgData);
}
else if ( v2 == 192 )
{
result = AY8910_control_port_0_w(0LL, (unsigned int)psgData);
}
}
return result;
}

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

v2 = a2 & 0xC0;
if ( psgSelect_0 != v2 )
{
psgSelect_0 = v2;
if ( v2 == 64 )
{
result = AY8910_write_port_0_w(0LL, (unsigned int)psgData);
}
else if ( v2 == 192 )
{
result = AY8910_control_port_0_w(0LL, (unsigned int)psgData);
}
}
return result;
}

original_code:
void carnival_music_port_2_w(offs_t offset,data_t data)
{
 static int psgSelect = 0;
 int newSelect;
 newSelect = data & ( 0x40 | 0x80 );
 if ( psgSelect != newSelect )
 {
  psgSelect = newSelect;
  switch ( psgSelect )
  {
  case 0:
   break;
  case 0x80:
   break;
  case 0x40:
   AY8910_write_port_0_w( 0, psgData );
   break;
  case ( 0x40 | 0x80 ):
   AY8910_control_port_0_w( 0, psgData );
   break;
  }
 }
}

canonical_original_code:
void carnival_music_port_2_w(unsigned int offset, unsigned int data)
{
 static int psgSelect = 0;
 int newSelect;
 newSelect = data & ( 0x40 | 0x80 );
 if ( psgSelect != newSelect )
 {
  psgSelect = newSelect;
  switch ( psgSelect )
  {
  case 0:
   break;
  case 0x80:
   break;
  case 0x40:
   AY8910_write_port_0_w( 0, psgData );
   break;
  case ( 0x40 | 0x80 ):
   AY8910_control_port_0_w( 0, psgData );
   break;
  }
 }
}

variable_types: psgSelect int

variable_types: newSelect int


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

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

original_code:
data_t ajax_sharedram_r(offs_t offset)
{
 return ajax_sharedram[offset];
}

canonical_original_code:
unsigned int ajax_sharedram_r(unsigned int offset)
{
 return ajax_sharedram[offset];
}


decompiled_code:
void ajax_init_machine()
{
firq_enable = 1;
}

canonical_decompiled_code:
void func2()
{
firq_enable = 1;
}

original_code:
void ajax_init_machine( void )
{
 firq_enable = 1;
}


decompiled_code:
int __fastcall ajax_ls138_f10_r(unsigned int a1)
{
int v1; // eax
int result; // eax

v1 = (a1 >> 6) & 7;
if ( v1 == 6 )
{
if ( (a1 & 2) != 0 )
result = readinputport(a1 & 1);
else
result = readinputport((a1 & 1) + 3);
}
else if ( v1 == 7 )
{
result = readinputport(2LL);
}
else if ( v1 )
{
if ( v1 == 4 )
result = readinputport(5LL);
else
result = 0;
}
else
{
result = rand();
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(unsigned int a1)
{
int v1; // eax
int result; // eax

v1 = (a1 >> 6) & 7;
if ( v1 == 6 )
{
if ( (a1 & 2) != 0 )
result = readinputport(a1 & 1);
else
result = readinputport((a1 & 1) + 3);
}
else if ( v1 == 7 )
{
result = readinputport(2LL);
}
else if ( v1 )
{
if ( v1 == 4 )
result = readinputport(5LL);
else
result = 0;
}
else
{
result = rand();
}
return result;
}

original_code:
data_t ajax_ls138_f10_r(offs_t offset)
{
 int data = 0;
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   data = rand();
   break;
  case 0x04:
   data = readinputport(5);
   break;
  case 0x06:
   if (offset & 0x02)
    data = readinputport(offset & 0x01);
   else
    data = readinputport(3 + (offset & 0x01));
   break;
  case 0x07:
   data = readinputport(2);
   break;
  default:
   break;
 }
 return data;
}

canonical_original_code:
unsigned int ajax_ls138_f10_r(unsigned int offset)
{
 int data = 0;
 switch ((offset & 0x01c0) >> 6){
  case 0x00:
   data = rand();
   break;
  case 0x04:
   data = readinputport(5);
   break;
  case 0x06:
   if (offset & 0x02)
    data = readinputport(offset & 0x01);
   else
    data = readinputport(3 + (offset & 0x01));
   break;
  case 0x07:
   data = readinputport(2);
   break;
  default:
   break;
 }
 return data;
}

variable_types: data int


decompiled_code:
void *__fastcall ajax_bankswitch_2_w(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(130LL);
K052109_set_RMRD_line((a2 >> 6) & 1);
K051316_wraparound_enable(0LL, a2 & 0x20);
firq_enable = a2 & 0x10;
cpu_bankbase[1] = v2 + (((a2 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(__int64 a1, unsigned int a2)
{
__int64 v2; // rbp
void *result; // rax
unsigned int v4; // eax

v2 = memory_region(130LL);
K052109_set_RMRD_line((a2 >> 6) & 1);
K051316_wraparound_enable(0LL, a2 & 0x20);
firq_enable = a2 & 0x10;
cpu_bankbase[1] = v2 + (((a2 & 0xF) + 8) << 13);
result = &ophw;
if ( ophw == 1 )
{
ophw = -1;
v4 = cpu_get_pc();
result = (void *)cpu_setOPbase16(v4);
}
return result;
}

original_code:
void ajax_bankswitch_2_w(offs_t offset,data_t data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int bankaddress;
 K052109_set_RMRD_line((data & 0x40) ? 1 : 0);
 K051316_wraparound_enable(0, data & 0x20);
 firq_enable = data & 0x10;
 bankaddress = 0x10000 + (data & 0x0f)*0x2000;
 { 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 ajax_bankswitch_2_w(unsigned int offset, unsigned int data)
{
 unsigned char *RAM = memory_region(REGION_CPU2);
 int bankaddress;
 K052109_set_RMRD_line((data & 0x40) ? 1 : 0);
 K051316_wraparound_enable(0, data & 0x20);
 firq_enable = data & 0x10;
 bankaddress = 0x10000 + (data & 0x0f)*0x2000;
 { if (1 >= 1 && 1 <= 16) { cpu_bankbase[1] = (unsigned char *)(&RAM[bankaddress]); if (ophw == 1) { ophw = 0xff; cpu_setOPbase16(cpu_get_pc()); } } };
}

variable_types:
RAM
unsigned char *

variable_types: bankaddress int


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

if ( (unsigned int)K051960_is_IRQ_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

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

if ( (unsigned int)K051960_is_IRQ_enabled() )
result = 1LL;
else
result = ignore_interrupt();
return result;
}

original_code:
int ajax_interrupt( void )
{
 if (K051960_is_IRQ_enabled())
  return 1;
 else
  return ignore_interrupt();
}

canonical_original_code:
int ajax_interrupt()
{
 if (K051960_is_IRQ_enabled())
  return 1;
 else
  return ignore_interrupt();
}


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

layer_colorbase = 64LL;
dword_748 = 32;
v0 = 1;
sprite_colorbase = 16;
zoom_colorbase = 6;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
return v0;
if ( !(unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(139LL, 7LL, zoom_callback);
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
K051960_vh_stop();
}
return v0;
}
K052109_vh_stop();
return 1LL;
}

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

layer_colorbase = 64LL;
dword_748 = 32;
v0 = 1;
sprite_colorbase = 16;
zoom_colorbase = 6;
if ( (unsigned int)K052109_vh_start(137LL, 0LL, 1LL, 2LL, 3LL, tile_callback) )
return v0;
if ( !(unsigned int)K051960_vh_start(138LL, 0LL, 1LL, 2LL, 3LL, sprite_callback) )
{
v0 = K051316_vh_start_0(139LL, 7LL, zoom_callback);
if ( v0 )
{
K052109_vh_stop();
v0 = 1;
K051960_vh_stop();
}
return v0;
}
K052109_vh_stop();
return 1LL;
}

original_code:
int ajax_vh_start( void )
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 32;
 sprite_colorbase = 16;
 zoom_colorbase = 6;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,7,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}

canonical_original_code:
int ajax_vh_start()
{
 layer_colorbase[0] = 64;
 layer_colorbase[1] = 0;
 layer_colorbase[2] = 32;
 sprite_colorbase = 16;
 zoom_colorbase = 6;
 if (K052109_vh_start(REGION_GFX1,0,1,2,3,tile_callback))
  return 1;
 if (K051960_vh_start(REGION_GFX2,0,1,2,3,sprite_callback))
 {
  K052109_vh_stop();
  return 1;
 }
 if (K051316_vh_start_0(REGION_GFX3,7,zoom_callback))
 {
  K052109_vh_stop();
  K051960_vh_stop();
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall ajax_vh_screenrefresh(__int64 a1)
{
int v1; // eax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = (zoom_colorbase << 7) + 128;
*(_BYTE *)(palette_used_colors + (zoom_colorbase << 7)) = 7;
*(_BYTE *)(palette_used_colors + v1) = 7;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K052109_tilemap_draw(a1, 2LL, 0x10000LL);
if ( ajax_priority )
{
K051316_zoom_draw_0(a1, 4LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K051316_zoom_draw_0(a1, 4LL);
}
K052109_tilemap_draw(a1, 0LL, 0x80000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // eax

K052109_tilemap_update();
K051316_tilemap_update_0();
palette_init_used_colors();
K051960_mark_sprites_colors();
v1 = (zoom_colorbase << 7) + 128;
*(_BYTE *)(palette_used_colors + (zoom_colorbase << 7)) = 7;
*(_BYTE *)(palette_used_colors + v1) = 7;
if ( palette_recalc() )
tilemap_mark_all_pixels_dirty(0LL);
tilemap_render(0LL);
fillbitmap(priority_bitmap, 0LL, 0LL);
fillbitmap(a1, **(unsigned __int16 **)(Machine + 792LL), Machine + 776LL);
K052109_tilemap_draw(a1, 2LL, 0x10000LL);
if ( ajax_priority )
{
K051316_zoom_draw_0(a1, 4LL);
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
}
else
{
K052109_tilemap_draw(a1, 1LL, 0x20000LL);
K051316_zoom_draw_0(a1, 4LL);
}
K052109_tilemap_draw(a1, 0LL, 0x80000LL);
return K051960_sprites_draw(a1, 0xFFFFFFFFLL, 0xFFFFFFFFLL);
}

original_code:
void ajax_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
{
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[(zoom_colorbase + 0) * 128] = (4|(1|2));
 palette_used_colors[(zoom_colorbase + 1) * 128] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,2,1<<16);
 if (ajax_priority)
 {
  K051316_zoom_draw_0(bitmap,4);
  K052109_tilemap_draw(bitmap,1,2<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,1,2<<16);
  K051316_zoom_draw_0(bitmap,4);
 }
 K052109_tilemap_draw(bitmap,0,8<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

canonical_original_code:
void ajax_vh_screenrefresh(struct osd_bitmap *bitmap, int fullrefresh)
{
 K052109_tilemap_update();
 K051316_tilemap_update_0();
 palette_init_used_colors();
 K051960_mark_sprites_colors();
 palette_used_colors[(zoom_colorbase + 0) * 128] = (4|(1|2));
 palette_used_colors[(zoom_colorbase + 1) * 128] = (4|(1|2));
 if (palette_recalc())
  tilemap_mark_all_pixels_dirty(0);
 tilemap_render(0);
 fillbitmap(priority_bitmap,0,((void *)0));
 fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
 K052109_tilemap_draw(bitmap,2,1<<16);
 if (ajax_priority)
 {
  K051316_zoom_draw_0(bitmap,4);
  K052109_tilemap_draw(bitmap,1,2<<16);
 }
 else
 {
  K052109_tilemap_draw(bitmap,1,2<<16);
  K051316_zoom_draw_0(bitmap,4);
 }
 K052109_tilemap_draw(bitmap,0,8<<16);
 K051960_sprites_draw(bitmap,-1,-1);
}

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

variable_types: fullrefresh int


decompiled_code:
__int64 init_ajax()
{
konami_rom_deinterleave_2(137LL);
return konami_rom_deinterleave_2(138LL);
}

canonical_decompiled_code:
__int64 func12()
{
konami_rom_deinterleave_2(137LL);
return konami_rom_deinterleave_2(138LL);
}

original_code:
static void init_ajax(void)
{
 konami_rom_deinterleave_2(REGION_GFX1);
 konami_rom_deinterleave_2(REGION_GFX2);
}

canonical_original_code:
static void init_ajax()
{
 konami_rom_deinterleave_2(REGION_GFX1);
 konami_rom_deinterleave_2(REGION_GFX2);
}


original_code:
static void k007232_extvol_w(offs_t offset,data_t data)
{
 K007232_set_volume(1,0,(data & 0x0f) * 0x11/2,(data & 0x0f) * 0x11/2);
}

canonical_original_code:
static void k007232_extvol_w(unsigned int offset, unsigned int data)
{
 K007232_set_volume(1,0,(data & 0x0f) * 0x11/2,(data & 0x0f) * 0x11/2);
}

variable_types:
offset
unsigned int

variable_types:
data
unsigned int