public static int osd_set_display(int width, int height, int attributes) {
        /*TODO*///	struct mode_adjust *adjust_array;
        /*TODO*///
        int i;
        /* moved 'found' to here (req. for 15.75KHz Arcade Monitor Modes) */
        int found;

        if (gfx_height == 0 || gfx_width == 0) {
            printf("Please specify height AND width (e.g. -640x480)\n");
            return 0;
        }

        if ((Machine.orientation & ORIENTATION_SWAP_XY) != 0) {
            int temp;

            temp = width;
            width = height;
            height = temp;
        }
        /* Mark the dirty buffers as dirty */

 /*TODO*///	if (use_dirty)
        /*TODO*///	{
        /*TODO*///		if (vector_game)
        /*TODO*///			/* vector games only use one dirty buffer */
        /*TODO*///			init_dirty (0);
        /*TODO*///		else
        /*TODO*///			init_dirty(1);
        /*TODO*///		swap_dirty();
        /*TODO*///		init_dirty(1);
        /*TODO*///	}
        /*TODO*///	if (dirtycolor)
        /*TODO*///	{
        /*TODO*///		for (i = 0;i < screen_colors;i++)
        /*TODO*///			dirtycolor[i] = 1;
        /*TODO*///		dirtypalette = 1;
        /*TODO*///	}
        /*TODO*///	/* handle special 15.75KHz modes, these now include SVGA modes */
        /*TODO*///	found = 0;
        /*TODO*///	/*move video freq set to here, as we need to set it explicitly for the 15.75KHz modes */
        /*TODO*///	videofreq = vgafreq;
        /*TODO*///
        /*TODO*///	if (use_vesa != 0)
        /*TODO*///	{
        /*TODO*///		/*removed local 'found' */
        /*TODO*///		int mode, bits, err;
        /*TODO*///
        /*TODO*///		mode = gfx_mode;
        /*TODO*///		found = 0;
        /*TODO*///		bits = scrbitmap->depth;
        /*TODO*///
        /*TODO*///		/* Try the specified vesamode, 565 and 555 for 16 bit color modes, */
        /*TODO*///		/* doubled resolution in case of noscanlines and if not succesful  */
        /*TODO*///		/* repeat for all "lower" VESA modes. NS/BW 19980102 */
        /*TODO*///
        /*TODO*///		while (!found)
        /*TODO*///		{
        /*TODO*///			set_color_depth(bits);
        /*TODO*///
        /*TODO*///			/* allocate a wide enough virtual screen if possible */
        /*TODO*///			/* we round the width (in dwords) to be an even multiple 256 - that */
        /*TODO*///			/* way, during page flipping only one byte of the video RAM */
        /*TODO*///			/* address changes, therefore preventing flickering. */
        /*TODO*///			if (bits == 8)
        /*TODO*///				triplebuf_page_width = (gfx_width + 0x3ff) & ~0x3ff;
        /*TODO*///			else
        /*TODO*///				triplebuf_page_width = (gfx_width + 0x1ff) & ~0x1ff;
        /*TODO*///
        /*TODO*///			/* don't ask for a larger screen if triplebuffer not requested - could */
        /*TODO*///			/* cause problems in some cases. */
        /*TODO*///			err = 1;
        /*TODO*///			if (use_triplebuf)
        /*TODO*///				err = set_gfx_mode(mode,gfx_width,gfx_height,3*triplebuf_page_width,0);
        /*TODO*///			if (err)
        /*TODO*///			{
        /*TODO*///				/* if we're using a SVGA 15KHz driver - tell Allegro the virtual screen width */
        /*TODO*///				if(SVGA15KHzdriver)
        /*TODO*///					err = set_gfx_mode(mode,gfx_width,gfx_height,SVGA15KHzdriver->getlogicalwidth(gfx_width),0);
        /*TODO*///				else
        /*TODO*///					err = set_gfx_mode(mode,gfx_width,gfx_height,0,0);
        /*TODO*///			}
        /*TODO*///
        /*TODO*///			if (errorlog)
        /*TODO*///			{
        /*TODO*///				fprintf (errorlog,"Trying ");
        /*TODO*///				if      (mode == GFX_VESA1)
        /*TODO*///					fprintf (errorlog, "VESA1");
        /*TODO*///				else if (mode == GFX_VESA2B)
        /*TODO*///					fprintf (errorlog, "VESA2B");
        /*TODO*///				else if (mode == GFX_VESA2L)
        /*TODO*///				    fprintf (errorlog, "VESA2L");
        /*TODO*///				else if (mode == GFX_VESA3)
        /*TODO*///					fprintf (errorlog, "VESA3");
        /*TODO*///			    fprintf (errorlog, "  %dx%d, %d bit\n",
        /*TODO*///						gfx_width, gfx_height, bits);
        /*TODO*///			}
        /*TODO*///
        /*TODO*///			if (err == 0)
        /*TODO*///			{
        /*TODO*///				found = 1;
        /*TODO*///				/* replace gfx_mode with found mode */
        /*TODO*///				gfx_mode = mode;
        /*TODO*///				continue;
        /*TODO*///			}
        /*TODO*///			else if (errorlog)
        /*TODO*///				fprintf (errorlog,"%s\n",allegro_error);
        /*TODO*///
        /*TODO*///			/* Now adjust parameters for the next loop */
        /*TODO*///
        /*TODO*///			/* try 5-5-5 in case there is no 5-6-5 16 bit color mode */
        /*TODO*///			if (scrbitmap->depth == 16)
        /*TODO*///			{
        /*TODO*///				if (bits == 16)
        /*TODO*///				{
        /*TODO*///					bits = 15;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///				else
        /*TODO*///					bits = 16; /* reset to 5-6-5 */
        /*TODO*///			}
        /*TODO*///
        /*TODO*///			/* try VESA modes in VESA3-VESA2L-VESA2B-VESA1 order */
        /*TODO*///
        /*TODO*///			if (mode == GFX_VESA3)
        /*TODO*///			{
        /*TODO*///				mode = GFX_VESA2L;
        /*TODO*///				continue;
        /*TODO*///			}
        /*TODO*///			else if (mode == GFX_VESA2L)
        /*TODO*///			{
        /*TODO*///				mode = GFX_VESA2B;
        /*TODO*///				continue;
        /*TODO*///			}
        /*TODO*///			else if (mode == GFX_VESA2B)
        /*TODO*///			{
        /*TODO*///				mode = GFX_VESA1;
        /*TODO*///				continue;
        /*TODO*///			}
        /*TODO*///			else if (mode == GFX_VESA1)
        /*TODO*///				mode = gfx_mode; /* restart with the mode given in mame.cfg */
        /*TODO*///
        /*TODO*///			/* try higher resolutions */
        /*TODO*///			if (auto_resolution)
        /*TODO*///			{
        /*TODO*///				if (stretch && gfx_width <= 512)
        /*TODO*///				{
        /*TODO*///					/* low res VESA mode not available, try an high res one */
        /*TODO*///					gfx_width *= 2;
        /*TODO*///					gfx_height *= 2;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///
        /*TODO*///				/* try next higher resolution */
        /*TODO*///				if (gfx_height < 300 && gfx_width < 400)
        /*TODO*///				{
        /*TODO*///					gfx_width = 400;
        /*TODO*///					gfx_height = 300;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///				else if (gfx_height < 384 && gfx_width < 512)
        /*TODO*///				{
        /*TODO*///					gfx_width = 512;
        /*TODO*///					gfx_height = 384;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///				else if (gfx_height < 480 && gfx_width < 640)
        /*TODO*///				{
        /*TODO*///					gfx_width = 640;
        /*TODO*///					gfx_height = 480;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///				else if (gfx_height < 600 && gfx_width < 800)
        /*TODO*///				{
        /*TODO*///					gfx_width = 800;
        /*TODO*///					gfx_height = 600;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///				else if (gfx_height < 768 && gfx_width < 1024)
        /*TODO*///				{
        /*TODO*///					gfx_width = 1024;
        /*TODO*///					gfx_height = 768;
        /*TODO*///					continue;
        /*TODO*///				}
        /*TODO*///			}
        /*TODO*///
        /*TODO*///			/* If there was no continue up to this point, we give up */
        /*TODO*///			break;
        /*TODO*///		}
        /*TODO*///
        /*TODO*///		if (found == 0)
        /*TODO*///		{
        /*TODO*///			printf ("\nNo %d-bit %dx%d VESA mode available.\n",
        /*TODO*///					scrbitmap->depth,gfx_width,gfx_height);
        /*TODO*///			printf ("\nPossible causes:\n"
        /*TODO*///"1) Your video card does not support VESA modes at all. Almost all\n"
        /*TODO*///"   video cards support VESA modes natively these days, so you probably\n"
        /*TODO*///"   have an older card which needs some driver loaded first.\n"
        /*TODO*///"   In case you can't find such a driver in the software that came with\n"
        /*TODO*///"   your video card, Scitech Display Doctor or (for S3 cards) S3VBE\n"
        /*TODO*///"   are good alternatives.\n"
        /*TODO*///"2) Your VESA implementation does not support this resolution. For example,\n"
        /*TODO*///"   '-320x240', '-400x300' and '-512x384' are only supported by a few\n"
        /*TODO*///"   implementations.\n"
        /*TODO*///"3) Your video card doesn't support this resolution at this color depth.\n"
        /*TODO*///"   For example, 1024x768 in 16 bit colors requires 2MB video memory.\n"
        /*TODO*///"   You can either force an 8 bit video mode ('-depth 8') or use a lower\n"
        /*TODO*///"   resolution ('-640x480', '-800x600').\n");
        /*TODO*///			return 0;
        /*TODO*///		}
        /*TODO*///		else
        /*TODO*///		{
        /*TODO*///			if (errorlog)
        /*TODO*///				fprintf (errorlog, "Found matching %s mode\n", gfx_driver->desc);
        /*TODO*///			gfx_mode = mode;
        /*TODO*///			/* disable triple buffering if the screen is not large enough */
        /*TODO*///			if (errorlog)
        /*TODO*///				fprintf (errorlog, "Virtual screen size %dx%d\n",VIRTUAL_W,VIRTUAL_H);
        /*TODO*///			if (VIRTUAL_W < 3*triplebuf_page_width)
        /*TODO*///			{
        /*TODO*///				use_triplebuf = 0;
        /*TODO*///				if (errorlog)
        /*TODO*///					fprintf (errorlog, "Triple buffer disabled\n");
        /*TODO*///			}
        /*TODO*///
        /*TODO*///			/* if triple buffering is enabled, turn off vsync */
        /*TODO*///			if (use_triplebuf)
        /*TODO*///			{
        /*TODO*///				wait_vsync = 0;
        /*TODO*///				video_sync = 0;
        /*TODO*///			}
        /*TODO*///		}
        /*TODO*///	}
        /*TODO*///	else
        /*TODO*///	{
        /*TODO*///
        /*TODO*///
        /*TODO*///		/* set the VGA clock */
        /*TODO*///		if (video_sync || always_synced || wait_vsync)
        /*TODO*///			reg[0].value = (reg[0].value & 0xf3) | (videofreq << 2);
        /*TODO*///
        /*TODO*///		/* VGA triple buffering */
        /*TODO*///		if(use_triplebuf)
        /*TODO*///		{
        /*TODO*///
        /*TODO*///			int vga_page_size = (gfx_width * gfx_height);
        /*TODO*///			/* see if it'll fit */
        /*TODO*///			if ((vga_page_size * 3) > 0x40000)
        /*TODO*///			{
        /*TODO*///				/* too big */
        /*TODO*///				if (errorlog)
        /*TODO*///					fprintf(errorlog,"tweaked mode %dx%d is too large to triple buffer\ntriple buffering disabled\n",gfx_width,gfx_height);
        /*TODO*///				use_triplebuf = 0;
        /*TODO*///			}
        /*TODO*///			else
        /*TODO*///			{
        /*TODO*///				/* it fits, so set up the 3 pages */
        /*TODO*///				no_xpages = 3;
        /*TODO*///				xpage_size = vga_page_size / 4;
        /*TODO*///				if (errorlog)
        /*TODO*///					fprintf(errorlog,"unchained VGA triple buffering page size :%d\n",xpage_size);
        /*TODO*///				/* and make sure the mode's unchained */
        /*TODO*///				unchain_vga (reg);
        /*TODO*///				/* triple buffering is enabled, turn off vsync */
        /*TODO*///				wait_vsync = 0;
        /*TODO*///				video_sync = 0;
        /*TODO*///			}
        /*TODO*///		}
        /*TODO*///		/* center the mode */
        /*TODO*///		center_mode (reg);
        /*TODO*///
        /*TODO*///		/* set the horizontal and vertical total */
        /*TODO*///		if (scanrate15KHz)
        /*TODO*///			/* 15.75KHz modes */
        /*TODO*///			adjust_array = arcade_adjust;
        /*TODO*///		else
        /*TODO*///			/* PC monitor modes */
        /*TODO*///			adjust_array = pc_adjust;
        /*TODO*///
        /*TODO*///		for (i=0; adjust_array[i].x != 0; i++)
        /*TODO*///		{
        /*TODO*///			if ((gfx_width == adjust_array[i].x) && (gfx_height == adjust_array[i].y))
        /*TODO*///			{
        /*TODO*///				/* check for 'special vertical' modes */
        /*TODO*///				if((!adjust_array[i].vertical_mode && !(Machine->orientation & ORIENTATION_SWAP_XY)) ||
        /*TODO*///					(adjust_array[i].vertical_mode && (Machine->orientation & ORIENTATION_SWAP_XY)))
        /*TODO*///				{
        /*TODO*///					reg[H_TOTAL_INDEX].value = *adjust_array[i].hadjust;
        /*TODO*///					reg[V_TOTAL_INDEX].value = *adjust_array[i].vadjust;
        /*TODO*///					break;
        /*TODO*///				}
        /*TODO*///			}
        /*TODO*///		}
        /*TODO*///
        /*TODO*///		/*if scanlines were requested - change the array values to get a scanline mode */
        /*TODO*///		if (scanlines && !scanrate15KHz)
        /*TODO*///			reg = make_scanline_mode(reg,reglen);
        /*TODO*///
        /*TODO*///		/* big hack: open a mode 13h screen using Allegro, then load the custom screen */
        /*TODO*///		/* definition over it. */
        /*TODO*///		if (set_gfx_mode(GFX_VGA,320,200,0,0) != 0)
        /*TODO*///			return 0;
        /*TODO*///
        /*TODO*///		if (errorlog)
        /*TODO*///		{
        /*TODO*///			fprintf(errorlog,"Generated Tweak Values :-\n");
        /*TODO*///			for (i=0; i<reglen; i++)
        /*TODO*///			{
        /*TODO*///				fprintf(errorlog,"{ 0x%02x, 0x%02x, 0x%02x},",reg[i].port,reg[i].index,reg[i].value);
        /*TODO*///				if (!((i+1)%3))
        /*TODO*///					fprintf(errorlog,"\n");
        /*TODO*///			}
        /*TODO*///		}
        /*TODO*///
        /*TODO*///		/* tweak the mode */
        /*TODO*///		outRegArray(reg,reglen);
        /*TODO*///
        /*TODO*///		/* check for unchained mode,  if unchained clear all pages */
        /*TODO*///		if (unchained)
        /*TODO*///		{
        /*TODO*///			unsigned long address;
        /*TODO*///			/* clear all 4 bit planes */
        /*TODO*///			outportw (0x3c4, (0x02 | (0x0f << 0x08)));
        /*TODO*///			for (address = 0xa0000; address < 0xb0000; address += 4)
        /*TODO*///				_farpokel(screen->seg, address, 0);
        /*TODO*///		}
        /*TODO*///	}
        /*TODO*///
        /*TODO*///
        /*TODO*///	gone_to_gfx_mode = 1;
        /*TODO*///
        /*TODO*///
        vsync_frame_rate = Machine.drv.frames_per_second;
        /*TODO*///
        /*TODO*///	if (video_sync)
        /*TODO*///	{
        /*TODO*///		TICKER a,b;
        /*TODO*///		float rate;
        /*TODO*///
        /*TODO*///
        /*TODO*///		/* wait some time to let everything stabilize */
        /*TODO*///		for (i = 0;i < 60;i++)
        /*TODO*///		{
        /*TODO*///			vsync();
        /*TODO*///			a = ticker();
        /*TODO*///		}
        /*TODO*///
        /*TODO*///		/* small delay for really really fast machines */
        /*TODO*///		for (i = 0;i < 100000;i++) ;
        /*TODO*///
        /*TODO*///		vsync();
        /*TODO*///		b = ticker();
        /*TODO*///
        /*TODO*///		rate = ((float)TICKS_PER_SEC)/(b-a);
        /*TODO*///
        /*TODO*///		if (errorlog)
        /*TODO*///			fprintf(errorlog,"target frame rate = %ffps, video frame rate = %3.2fHz\n",Machine->drv->frames_per_second,rate);
        /*TODO*///
        /*TODO*///		/* don't allow more than 8% difference between target and actual frame rate */
        /*TODO*///		while (rate > Machine->drv->frames_per_second * 108 / 100)
        /*TODO*///			rate /= 2;
        /*TODO*///
        /*TODO*///		if (rate < Machine->drv->frames_per_second * 92 / 100)
        /*TODO*///		{
        /*TODO*///			osd_close_display();
        /*TODO*///			if (errorlog) fprintf(errorlog,"-vsync option cannot be used with this display mode:\n"
        /*TODO*///						"video refresh frequency = %dHz, target frame rate = %ffps\n",
        /*TODO*///						(int)(TICKS_PER_SEC/(b-a)),Machine->drv->frames_per_second);
        /*TODO*///			return 0;
        /*TODO*///		}
        /*TODO*///
        /*TODO*///		if (errorlog) fprintf(errorlog,"adjusted video frame rate = %3.2fHz\n",rate);
        /*TODO*///			vsync_frame_rate = rate;
        /*TODO*///
        /*TODO*///		if (Machine->sample_rate)
        /*TODO*///		{
        /*TODO*///			Machine->sample_rate = Machine->sample_rate * Machine->drv->frames_per_second / rate;
        /*TODO*///			if (errorlog)
        /*TODO*///				fprintf(errorlog,"sample rate adjusted to match video freq: %d\n",Machine->sample_rate);
        /*TODO*///		}
        /*TODO*///	}
        /*TODO*///
        warming_up = 1;

        //kill loading window
        if (MainApplet.inst != null) {
            //kill loading window
            osdepend.dlprogress.setVisible(false);

            MainApplet.inst.addKeyListener(MainApplet.inst);
            MainApplet.inst.setSize((scanlines == 0), width, height);
            MainApplet.inst.setBackground(Color.black);
            MainApplet.inst.start();
            MainApplet.inst.run();
            MainApplet.inst.getFocus();

        } else if (MainStream.inst != null) {
            //main.MainStream.inst.addKeyListener(main.MainStream.inst);
            MainStream.inst.setSize((scanlines == 0), width, height);
            //main.MainStream.inst.setBackground(Color.black);
            //MainStream.inst.start();
            //MainStream.inst.run();
            //main.MainStream.inst.getFocus();
            if (MainStream.debug) {
                screen = new software_gfx(settings.version + " (based on mame v" + build_version + ")");
                screen.pack();
                //screen.setSize((scanlines==1),gfx_width,gfx_height);//this???
                //screen.setSize((scanlines==1),width,height);//this???
                screen.setSize((scanlines == 0), width, height);
                screen.setBackground(Color.black);
                /*part of the old arcadeflex emulator probably need refactoring */
                Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
                screen.setLocation((int) ((localDimension.getWidth() - screen.getWidth()) / 2.0D), (int) ((localDimension.getHeight() - screen.getHeight()) / 2.0D));
                screen.setVisible(true);

                screen.addWindowListener(new WindowAdapter() {

                    public void windowClosing(WindowEvent evt) {
                        screen.readkey = KeyEvent.VK_ESCAPE;
                        screen.key[KeyEvent.VK_ESCAPE] = true;
                        osd_refresh();
                        if (screen != null) {
                            screen.key[KeyEvent.VK_ESCAPE] = false;
                        }
                    }
                });

                screen.addKeyListener(screen);
                screen.setFocusTraversalKeysEnabled(false);
            }
        } else {
            /*part of the old arcadeflex emulator probably need refactoring */
            Dimension localDimension = Toolkit.getDefaultToolkit().getScreenSize();
            //kill loading window
            osdepend.dlprogress.setVisible(false);

            screen = new software_gfx(settings.version + " (based on mame v" + build_version + ")");
            screen.pack();
            //screen.setSize((scanlines==1),gfx_width,gfx_height);//this???
            //screen.setSize((scanlines==1),width,height);//this???
            screen.setSize((scanlines == 0), width, height);
            screen.setBackground(Color.black);
            screen.start();
            screen.run();
            screen.setLocation((int) ((localDimension.getWidth() - screen.getWidth()) / 2.0D), (int) ((localDimension.getHeight() - screen.getHeight()) / 2.0D));
            screen.setVisible(true);
            screen.setResizable((scanlines == 1));

            screen.addWindowListener(new WindowAdapter() {

                public void windowClosing(WindowEvent evt) {
                    screen.readkey = KeyEvent.VK_ESCAPE;
                    screen.key[KeyEvent.VK_ESCAPE] = true;
                    osd_refresh();
                    if (screen != null) {
                        screen.key[KeyEvent.VK_ESCAPE] = false;
                    }
                }
            });

            screen.addComponentListener(new ComponentAdapter() {

                public void componentResized(ComponentEvent evt) {
                    screen.resizeVideo();
                }
            });

            screen.addKeyListener(screen);
            screen.setFocusTraversalKeysEnabled(false);
            screen.requestFocus();

        }
        return 1;
    }