public static WriteHandlerPtr sys16_tileram_w = new WriteHandlerPtr() { public void handler(int offset, int data){
		int oldword = sys16_tileram.READ_WORD(offset);
		int newword = COMBINE_WORD(oldword,data);
		if( oldword != newword ){
			int row,col,page;
			sys16_tileram.WRITE_WORD(offset,newword);
			offset = offset/2;
			col = offset%64;
			row = (offset/64)%32;
			page = offset/(64*32);
	
			if( sys16_bg_page[0]==page ) tilemap_mark_tile_dirty( background, col, row );
			if( sys16_bg_page[1]==page ) tilemap_mark_tile_dirty( background, col+64, row );
			if( sys16_bg_page[2]==page ) tilemap_mark_tile_dirty( background, col, row+32 );
			if( sys16_bg_page[3]==page ) tilemap_mark_tile_dirty( background, col+64, row+32 );
	
			if( sys16_fg_page[0]==page ) tilemap_mark_tile_dirty( foreground, col, row );
			if( sys16_fg_page[1]==page ) tilemap_mark_tile_dirty( foreground, col+64, row );
			if( sys16_fg_page[2]==page ) tilemap_mark_tile_dirty( foreground, col, row+32 );
			if( sys16_fg_page[3]==page ) tilemap_mark_tile_dirty( foreground, col+64, row+32 );
	
			if (sys16_18_mode != 0)
			{
				if( sys16_bg2_page[0]==page ) tilemap_mark_tile_dirty( background2, col, row );
				if( sys16_bg2_page[1]==page ) tilemap_mark_tile_dirty( background2, col+64, row );
				if( sys16_bg2_page[2]==page ) tilemap_mark_tile_dirty( background2, col, row+32 );
				if( sys16_bg2_page[3]==page ) tilemap_mark_tile_dirty( background2, col+64, row+32 );
	
				if( sys16_fg2_page[0]==page ) tilemap_mark_tile_dirty( foreground2, col, row );
				if( sys16_fg2_page[1]==page ) tilemap_mark_tile_dirty( foreground2, col+64, row );
				if( sys16_fg2_page[2]==page ) tilemap_mark_tile_dirty( foreground2, col, row+32 );
				if( sys16_fg2_page[3]==page ) tilemap_mark_tile_dirty( foreground2, col+64, row+32 );
			}
		}
	} }