public static int init_machine() {
        int i;

           if (code_init() != 0)
                   return out();

        for (i = 0; i < MAX_MEMORY_REGIONS; i++) {
            Machine.memory_region[i] = null;
            Machine.memory_region_length[i] = 0;
            Machine.memory_region_type[i] = 0;
        }

        if (gamedrv.input_ports!=null)
        {
                 Machine.input_ports = input_port_allocate(gamedrv.input_ports);
                    if (Machine.input_ports==null)
                            return out_code();
                    Machine.input_ports_default = input_port_allocate(gamedrv.input_ports);
                    if (Machine.input_ports_default==null)
                    {
                            input_port_free(Machine.input_ports);
                            Machine.input_ports = null;
                            return out_code();
                    }
         }

        if (readroms() != 0) {
            return out_free();
        }


        /* Mish:  Multi-session safety - set spriteram size to zero before memory map is set up */
        spriteram_size[0]=0;
        spriteram_2_size[0]=0;

        /* first of all initialize the memory handlers, which could be used by the */
        /* other initialization routines */
        cpu_init();

        /* load input ports settings (keys, dip switches, and so on) */
        settingsloaded = load_input_port_settings();

        if (memory_init() == 0) {
            return out_free();
        }

        if (gamedrv.driver_init != null) {
            gamedrv.driver_init.handler();
        }

        return 0;
    }