public void handler() {
            UBytePtr gfxdata;
            int len;
            int i, j, k, A, B, entry;
            int[] bits = new int[32];
            UBytePtr temp;

            init_gfx.handler();

            /*
             along with the normal byte reordering, TMNT also needs the bits to
             be shuffled around because the ROMs are connected differently to the
             051962 custom IC.
             */
            gfxdata = memory_region(REGION_GFX1);
            len = memory_region_length(REGION_GFX1);
            for (i = 0; i < len; i += 4) {
                for (j = 0; j < 4; j++) {
                    for (k = 0; k < 8; k++) {
                        bits[8 * j + k] = (gfxdata.read(i + j) >> k) & 1;
                    }
                }

                for (j = 0; j < 4; j++) {
                    gfxdata.write(i + j, 0);
                    for (k = 0; k < 8; k++) {
                        gfxdata.write(i + j, gfxdata.read(i + j) | bits[j + 4 * k] << k);
                    }
                }
            }

            /*
             along with the normal byte reordering, TMNT also needs the bits to
             be shuffled around because the ROMs are connected differently to the
             051937 custom IC.
             */
            gfxdata = memory_region(REGION_GFX2);
            len = memory_region_length(REGION_GFX2);
            for (i = 0; i < len; i += 4) {
                for (j = 0; j < 4; j++) {
                    for (k = 0; k < 8; k++) {
                        bits[8 * j + k] = (gfxdata.read(i + j) >> k) & 1;
                    }
                }

                for (j = 0; j < 4; j++) {
                    gfxdata.write(i + j, 0);
                    for (k = 0; k < 8; k++) {
                        gfxdata.write(i + j, gfxdata.read(i + j) | bits[j + 4 * k] << k);
                    }
                }
            }

            temp = new UBytePtr(len);
            memcpy(temp, gfxdata, len);
            for (A = 0; A < len / 4; A++) {
                UBytePtr code_conv_table = new UBytePtr(memory_region(REGION_PROMS), 0x0000);
                int CA0 = 0;
                int CA1 = 1;
                int CA2 = 2;
                int CA3 = 3;
                int CA4 = 4;
                int CA5 = 5;
                int CA6 = 6;
                int CA7 = 7;
                int CA8 = 8;
                int CA9 = 9;

                /* following table derived from the schematics. It indicates, for each of the */
                /* 9 low bits of the sprite line address, which bit to pick it from. */
                /* For example, when the PROM contains 4, which applies to 4x2 sprites, */
                /* bit OA1 comes from CA5, OA2 from CA0, and so on. */
                int bit_pick_table[][]
                        = {
                            /*0(1x1) 1(2x1) 2(1x2) 3(2x2) 4(4x2) 5(2x4) 6(4x4) 7(8x8) */
                            {CA3, CA3, CA3, CA3, CA3, CA3, CA3, CA3}, /* CA3 */
                            {CA0, CA0, CA5, CA5, CA5, CA5, CA5, CA5}, /* OA1 */
                            {CA1, CA1, CA0, CA0, CA0, CA7, CA7, CA7}, /* OA2 */
                            {CA2, CA2, CA1, CA1, CA1, CA0, CA0, CA9}, /* OA3 */
                            {CA4, CA4, CA2, CA2, CA2, CA1, CA1, CA0}, /* OA4 */
                            {CA5, CA6, CA4, CA4, CA4, CA2, CA2, CA1}, /* OA5 */
                            {CA6, CA5, CA6, CA6, CA6, CA4, CA4, CA2}, /* OA6 */
                            {CA7, CA7, CA7, CA7, CA8, CA6, CA6, CA4}, /* OA7 */
                            {CA8, CA8, CA8, CA8, CA7, CA8, CA8, CA6}, /* OA8 */
                            {CA9, CA9, CA9, CA9, CA9, CA9, CA9, CA8} /* OA9 */};

                /* pick the correct entry in the PROM (top 8 bits of the address) */
                entry = code_conv_table.read((A & 0x7f800) >> 11) & 7;

                /* the bits to scramble are the low 10 ones */
                for (i = 0; i < 10; i++) {
                    bits[i] = (A >> i) & 0x01;
                }

                B = A & 0x7fc00;

                for (i = 0; i < 10; i++) {
                    B |= bits[bit_pick_table[i][entry]] << i;
                }

                gfxdata.write(4 * A + 0, temp.read(4 * B + 0));
                gfxdata.write(4 * A + 1, temp.read(4 * B + 1));
                gfxdata.write(4 * A + 2, temp.read(4 * B + 2));
                gfxdata.write(4 * A + 3, temp.read(4 * B + 3));
            }
            temp = null;
        }