public static int K051316_vh_start(int chip, int gfx_memory_region, int bpp, K051316_callbackProcPtr callback) {
        int gfx_index;


        /* find first empty slot to decode gfx */
        for (gfx_index = 0; gfx_index < MAX_GFX_ELEMENTS; gfx_index++) {
            if (Machine.gfx[gfx_index] == null) {
                break;
            }
        }
        if (gfx_index == MAX_GFX_ELEMENTS) {
            return 1;
        }

        if (bpp == 4) {
            GfxLayout charlayout = new GfxLayout(
                    16, 16,
                    0, /* filled in later */
                    4,
                    new int[]{0, 1, 2, 3},
                    new int[]{0 * 4, 1 * 4, 2 * 4, 3 * 4, 4 * 4, 5 * 4, 6 * 4, 7 * 4,
                        8 * 4, 9 * 4, 10 * 4, 11 * 4, 12 * 4, 13 * 4, 14 * 4, 15 * 4},
                    new int[]{0 * 64, 1 * 64, 2 * 64, 3 * 64, 4 * 64, 5 * 64, 6 * 64, 7 * 64,
                        8 * 64, 9 * 64, 10 * 64, 11 * 64, 12 * 64, 13 * 64, 14 * 64, 15 * 64},
                    128 * 8
            );


            /* tweak the structure for the number of tiles we have */
            charlayout.total = memory_region_length(gfx_memory_region) / 128;

            /* decode the graphics */
            Machine.gfx[gfx_index] = decodegfx(memory_region(gfx_memory_region), charlayout);
        } else if (bpp == 7) {
            GfxLayout charlayout = new GfxLayout(
                    16, 16,
                    0, /* filled in later */
                    7,
                    new int[]{1, 2, 3, 4, 5, 6, 7},
                    new int[]{0 * 8, 1 * 8, 2 * 8, 3 * 8, 4 * 8, 5 * 8, 6 * 8, 7 * 8,
                        8 * 8, 9 * 8, 10 * 8, 11 * 8, 12 * 8, 13 * 8, 14 * 8, 15 * 8},
                    new int[]{0 * 128, 1 * 128, 2 * 128, 3 * 128, 4 * 128, 5 * 128, 6 * 128, 7 * 128,
                        8 * 128, 9 * 128, 10 * 128, 11 * 128, 12 * 128, 13 * 128, 14 * 128, 15 * 128},
                    256 * 8
            );


            /* tweak the structure for the number of tiles we have */
            charlayout.total = memory_region_length(gfx_memory_region) / 256;

            /* decode the graphics */
            Machine.gfx[gfx_index] = decodegfx(memory_region(gfx_memory_region), charlayout);
        } else {
            if (errorlog != null) {
                fprintf(errorlog, "K051316_vh_start supports only 4 or 7 bpp\n");
            }
            return 1;
        }

        if (Machine.gfx[gfx_index] == null) {
            return 1;
        }

        /* set the color information */
        Machine.gfx[gfx_index].colortable = new CharPtr(Machine.remapped_colortable);
        Machine.gfx[gfx_index].total_colors = Machine.drv.color_table_len / (1 << bpp);

        K051316_memory_region[chip] = gfx_memory_region;
        K051316_gfxnum[chip] = gfx_index;
        K051316_bpp[chip] = bpp;
        K051316_callback[chip] = callback;

        K051316_tilemap[chip] = tilemap_create(K051316_get_tile_info, TILEMAP_OPAQUE, 16, 16, 32, 32);

        K051316_ram[chip] = new UBytePtr(0x800);

        if (K051316_ram[chip] == null || K051316_tilemap[chip] == null) {
            K051316_vh_stop(chip);
            return 1;
        }

        tilemap_set_clip(K051316_tilemap[chip], null);

        K051316_wraparound[chip] = 0;	/* default = no wraparound */

        K051316_offset[chip][0] = K051316_offset[chip][1] = 0;

        return 0;
    }