public static UBytePtr palette_recalc_16_static() {
        int i, color;
        int did_remap = 0;
        int need_refresh = 0;

        //memset(just_remapped,0,Machine->drv->total_colors * sizeof(unsigned char));
        for (int mem = 0; mem < Machine.drv.total_colors; mem++) {
            just_remapped.write(mem, 0);
        }

        for (color = 0; color < Machine.drv.total_colors; color++) {
            /* the comparison between palette_used_colors and old_used_colors also includes */
            /* PALETTE_COLOR_NEEDS_REMAP which might have been set by palette_change_color() */
            if ((palette_used_colors.read(color) & PALETTE_COLOR_VISIBLE) != 0
                    && palette_used_colors.read(color) != old_used_colors.read(color)) {
                int r, g, b;

                did_remap = 1;
                if ((old_used_colors.read(color) & palette_used_colors.read(color) & PALETTE_COLOR_CACHED) != 0) {
                    /* the color was and still is cached, we'll have to redraw everything */
                    need_refresh = 1;
                    just_remapped.write(color, 1);
                }

                if ((palette_used_colors.read(color) & PALETTE_COLOR_TRANSPARENT_FLAG) != 0) {
                    Machine.pens[color] = palette_transparent_pen;
                } else {
                    r = game_palette[3 * color + 0].read();
                    g = game_palette[3 * color + 1].read();
                    b = game_palette[3 * color + 2].read();

                    Machine.pens[color] = shrinked_pens[rgbpenindex(r, g, b)];
                }
            }

            old_used_colors.write(color, palette_used_colors.read(color));
        }

        if (did_remap != 0) {
            /* rebuild the color lookup table */
            for (i = 0; i < Machine.drv.color_table_len; i++) {
                Machine.remapped_colortable[i] = Machine.pens[Machine.game_colortable[i]];
            }
        }

        if (need_refresh != 0) {
            return just_remapped;
        } else {
            return null;
        }
    }