static void mark_sprite_colors(int controller) {
        int offs, attrib, sprite, color, i, pal_base;
        int sprite_sizex, sprite_sizey, temp_x, temp_y;
        int[] colmask = new int[64];

        UShortPtr source = new UShortPtr(spriteram_now[controller]);

        pal_base = Machine.drv.gfxdecodeinfo[((controller * 2) + 1)].color_codes_start;

        for (i = 0; i < 64; i++) {
            colmask[i] = 0;
        }

        for (offs = 0; offs < (TOAPLAN2_SPRITERAM_SIZE / 2); offs += 4) {
            attrib = source.read(offs);
            sprite = source.read(offs + 1) | ((attrib & 3) << 16);
            sprite %= Machine.gfx[((controller * 2) + 1)].total_elements;
            if ((attrib & 0x8000) != 0) {
                /* While we're here, mark all priorities used */
                sprite_priority[controller][((attrib & 0x0f00) >> 8)] = display_sp[controller];

                color = (attrib >> 2) & 0x3f;
                sprite_sizex = (source.read(offs + 2) & 0x0f) + 1;
                sprite_sizey = (source.read(offs + 3) & 0x0f) + 1;

                for (temp_y = 0; temp_y < sprite_sizey; temp_y++) {
                    for (temp_x = 0; temp_x < sprite_sizex; temp_x++) {
                        colmask[color] |= Machine.gfx[((controller * 2) + 1)].pen_usage[sprite];
                        sprite++;
                    }
                }
            }
        }

        for (color = 0; color < 64; color++) {
            if ((color == 0) && (colmask[0] & 1) != 0) {
                palette_used_colors.write(pal_base + 16 * color, PALETTE_COLOR_TRANSPARENT);
            }
            for (i = 1; i < 16; i++) {
                if ((colmask[color] & (1 << i)) != 0) {
                    palette_used_colors.write(pal_base + 16 * color + i, PALETTE_COLOR_USED);
                }
            }
        }
    }