public void handler() {
            UBytePtr gfxdata;
            int len;
            int i, j, k, A, B;
            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, MIA 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);
            if (temp == null) {
                return;	/* bad thing! */

            }
            memcpy(temp, gfxdata, len);
            for (A = 0; A < len / 4; A++) {
                /* the bits to scramble are the low 8 ones */
                for (i = 0; i < 8; i++) {
                    bits[i] = (A >> i) & 0x01;
                }

                B = A & 0x3ff00;

                if ((A & 0x3c000) == 0x3c000) {
                    B |= bits[3] << 0;
                    B |= bits[5] << 1;
                    B |= bits[0] << 2;
                    B |= bits[1] << 3;
                    B |= bits[2] << 4;
                    B |= bits[4] << 5;
                    B |= bits[6] << 6;
                    B |= bits[7] << 7;
                } else {
                    B |= bits[3] << 0;
                    B |= bits[5] << 1;
                    B |= bits[7] << 2;
                    B |= bits[0] << 3;
                    B |= bits[1] << 4;
                    B |= bits[2] << 5;
                    B |= bits[4] << 6;
                    B |= bits[6] << 7;
                }

                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;
        }