Buggy code:
; public static WriteHandlerPtr mwh_error = new WriteHandlerPtr ( ) { public void handler ( int offset , int data ) { } } ; public static WriteHandlerPtr mwh_error_sparse = new WriteHandlerPtr ( ) { public void handler ( int offset , int data ) { } } ; public static WriteHandlerPtr mwh_error_sparse_bit = new WriteHandlerPtr ( ) { public void handler ( int offset , int data ) { } } ; public static WriteHandlerPtr mwh_rom = new WriteHandlerPtr ( ) { public void handler ( int offset , int data ) { } } ; public static WriteHandlerPtr mwh_ramrom = new WriteHandlerPtr ( ) { public void handler ( int offset , int data ) { } } ; public static WriteHandlerPtr mwh_nop = new WriteHandlerPtr ( ) { public void handler ( int offset , int data ) { } } ; static UBytePtr get_element ( UBytePtr element , int ad , int elemask , UBytePtr subelement , int [ ] ele_max ) { } static void set_element ( int cpu , UBytePtr celement , int sp , int ep , UByte type , UBytePtr subelement , int [ ] ele_max ) { } public static int memory_allocate_ext ( ) { } public static UBytePtr memory_find_base ( int cpu , int offset ) { } static int rdelement_max = 0 ; static int wrelement_max = 0 ; static int rdhard_max = memory . HT_USER ; static int wrhard_max = memory . HT_USER ; public static int memory_init ( ) { } public static void memory_set_opcode_base ( int cpu , UBytePtr base ) { } public static void memorycontextswap ( int activecpu ) { } public static void memory_shutdown ( ) { } public static int cpu_readmem16 ( int address ) { } public static int cpu_readmem20 ( int address ) { } public static int cpu_readmem24 ( int address ) { } public static int cpu_readmem24_word ( int address ) { } public static int cpu_readmem24_dword ( int address ) { } public static void cpu_writemem16 ( int address , int data ) { } public static void cpu_writemem20 ( int address , int data ) { } public static void cpu_writemem24 ( int address , int data ) { UByte hw = new UByte ( ) ; hw . set ( memory . cur_mwhard [ ( address > > > ( ( ABITS2_24 ) + ( ABITS_MIN_24 ) ) ) ] ) ; if ( ( hw . read ( ) ) <= ( memory . HT_BANKMAX ) ) { memory . cpu_bankbase [ hw . read ( ) ] . memory [ ( ( memory . BYTE_XOR_BE ( address ) ) - ( memory . memorywriteoffset [ hw . read ( ) ] ) ) ] = ( ( char ) ( data ) ) ; return ; } if ( ( hw . read ( ) ) >= ( MH_HARDMAX ) ) { hw . set ( ( ( char ) ( ( hw . read ( ) ) - ( MH_HARDMAX ) ) ) ) ; hw . set ( memory . writehardware . read ( ( ( ( hw . read ( ) ) << ( MH_SBITS ) ) + ( ( address > > > ( ABITS_MIN_24 ) ) & ( MHMASK ( ABITS2_24 ) ) ) ) ) ) ; if ( ( hw . read ( ) ) <= ( memory . HT_BANKMAX ) ) { memory . cpu_bankbase [ hw . read ( ) ] . memory [ ( ( memory . BYTE_XOR_BE ( address ) ) - ( memory . memorywriteoffset [ hw . read ( ) ] ) ) ] = ( ( char ) ( data ) ) ; return ; } } int shift = ( address & 1 ) << 3 ; shift ^= 8 ; <START_BUG> data = ( - 16777216 > > shift ) | ( ( data & 255 ) << shift ) ; <END_BUG> address &= ~ 1 ; memory . memorywritehandler [ hw . read ( ) ] . handler ( ( address - ( memory . memorywriteoffset [ hw . read ( ) ] ) ) , data ) ; } public static void cpu_writemem24_word ( int address , int data ) { } public static void cpu_writemem24_dword ( int address , int data ) { } public static setopbase cpu_setOPbase16 = new setopbase ( ) { public void handler ( int pc , int shift ) { } } ; public static setopbase cpu_setOPbase20 = new setopbase ( ) { public void handler ( int pc , int shift ) { } } ; public static setopbase cpu_setOPbase24 = new setopbase ( ) { public void handler ( int pc , int shift ) { } } ; public static int cpu_readport ( int port ) { } public static void cpu_writeport ( int port , int value ) { } public static void cpu_setbankhandler_r ( int bank , ReadHandlerPtr _handler ) { } public static void cpu_setbankhandler_w ( int bank , WriteHandlerPtr _handler ) { } public static UBytePtr install_mem_read_handler ( int cpu , int start , int end , ReadHandlerPtr _handler ) { } public static UBytePtr install_mem_write_handler ( int cpu , int start , int end , WriteHandlerPtr _handler ) { } public static IOWritePort [ ] install_port_write_handler ( int cpu , int start , int end , WriteHandlerPtr _handler ) { } public static IOReadPort [ ] install_port_read_handler_common ( int cpu , int start , int end , int handler , ReadHandlerPtr _handler , int install_at_beginning ) { } public static IOWritePort [ ] install_port_write_handler_common ( int cpu , int start , int end , int handler , WriteHandlerPtr _handler , int install_at_beginning ) { } public static void mem_dump ( ) { } }

Fix:
data = ( - 16777216 > > > shift ) | ( ( data & 255 ) << shift ) ;