float options_get_float_range(const char *name, float minval, float maxval) { options_data *data = find_entry_data(name, FALSE); float value = 0; if (data == NULL) mame_printf_error("Unexpected float option %s queried\n", name); else if (data->data == NULL || sscanf(data->data, "%f", &value) != 1) { if (data->defdata != NULL) { options_set_string(name, data->defdata); value = options_get_float(name); } if (!data->error_reported) { mame_printf_error("Illegal float value for %s; reverting to %f\n", data->names[0], (double)value); data->error_reported = TRUE; } } else if (value < minval || value > maxval) { options_set_string(name, data->defdata); value = options_get_float(name); if (!data->error_reported) { mame_printf_error("Invalid %s value (must be between %f and %f); reverting to %f\n", data->names[0], (double)minval, (double)maxval, (double)value); data->error_reported = TRUE; } } return value; }
static int ddraw_create_surfaces(win_window_info *window) { dd_info *dd = window->drawdata; HRESULT result; // make a description of the primary surface memset(&dd->primarydesc, 0, sizeof(dd->primarydesc)); dd->primarydesc.dwSize = sizeof(dd->primarydesc); dd->primarydesc.dwFlags = DDSD_CAPS; dd->primarydesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // for triple-buffered full screen mode, allocate flipping surfaces if (window->fullscreen && video_config.triplebuf) { dd->primarydesc.dwFlags |= DDSD_BACKBUFFERCOUNT; dd->primarydesc.ddsCaps.dwCaps |= DDSCAPS_FLIP | DDSCAPS_COMPLEX; dd->primarydesc.dwBackBufferCount = 2; } // create the primary surface and report errors result = create_surface(dd, &dd->primarydesc, &dd->primary, "primary"); if (result != DD_OK) goto error; // full screen mode: get the back surface dd->back = NULL; if (window->fullscreen && video_config.triplebuf) { DDSCAPS2 caps = { DDSCAPS_BACKBUFFER }; result = IDirectDrawSurface7_GetAttachedSurface(dd->primary, &caps, &dd->back); if (result != DD_OK) { mame_printf_verbose("DirectDraw: Error %08X getting attached back surface\n", (int)result); goto error; } } // now make a description of our blit surface, based on the primary surface if (dd->blitwidth == 0 || dd->blitheight == 0) compute_blit_surface_size(window); dd->blitdesc = dd->primarydesc; dd->blitdesc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CAPS; dd->blitdesc.dwWidth = dd->blitwidth; dd->blitdesc.dwHeight = dd->blitheight; dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY; // then create the blit surface, fall back to system memory if video mem doesn't work result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit"); if (result != DD_OK) { dd->blitdesc.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY; result = create_surface(dd, &dd->blitdesc, &dd->blit, "blit"); } if (result != DD_OK) goto error; // create a memory buffer for offscreen drawing if (dd->membuffersize < dd->blitwidth * dd->blitheight * 4) { dd->membuffersize = dd->blitwidth * dd->blitheight * 4; dd->membuffer = realloc(dd->membuffer, dd->membuffersize); } if (dd->membuffer == NULL) goto error; #ifdef MESS // create a clipper for all modes, since MESS has dialogs if (create_clipper(window)) goto error; #else // create a clipper for windowed mode if (!window->fullscreen && create_clipper(window)) goto error; #endif // full screen mode: set the gamma if (window->fullscreen) { // only set the gamma if it's not 1.0f float brightness = options_get_float(mame_options(), WINOPTION_FULLSCREENBRIGHTNESS); float contrast = options_get_float(mame_options(), WINOPTION_FULLLSCREENCONTRAST); float gamma = options_get_float(mame_options(), WINOPTION_FULLSCREENGAMMA); if (brightness != 1.0f || contrast != 1.0f || gamma != 1.0f) { // see if we can get a GammaControl object result = IDirectDrawSurface_QueryInterface(dd->primary, &IID_IDirectDrawGammaControl, (void **)&dd->gamma); if (result != DD_OK) { mame_printf_warning("DirectDraw: Warning - device does not support full screen gamma correction.\n"); dd->gamma = NULL; } // proceed if we can if (dd->gamma != NULL) { DDGAMMARAMP ramp; int i; // create a standard ramp and set it for (i = 0; i < 256; i++) ramp.red[i] = ramp.green[i] = ramp.blue[i] = apply_brightness_contrast_gamma(i, brightness, contrast, gamma) << 8; // attempt to set it result = IDirectDrawGammaControl_SetGammaRamp(dd->gamma, 0, &ramp); if (result != DD_OK) mame_printf_verbose("DirectDraw: Error %08X attempting to set gamma correction.\n", (int)result); } } } // force some updates update_outer_rects(dd); return 0; error: ddraw_delete_surfaces(window); return 1; }
static int drawgx_window_create(sdl_window_info *window, int width, int height) { sdl_info *sdl = window->dxdata; u32 xfbHeight; f32 yscale; Mtx44 perspective; Mtx GXmodelView2D; GXColor background = {0, 0, 0, 0xff}; currfb = 0; // allocate memory for our structures sdl = malloc(sizeof(*sdl)); memset(sdl, 0, sizeof(*sdl)); window->dxdata = sdl; sdl->scale_mode = &scale_modes[window->scale_mode]; sdl->extra_flags = (window->fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE); sdl->extra_flags |= sdl->scale_mode->extra_flags; /*sdl->sdlsurf = SDL_SetVideoMode(width, height, 0, SDL_SWSURFACE | SDL_ANYFORMAT | sdl->extra_flags);*/ //sdl->sdlsurf = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); //if (!sdl->sdlsurf) // return 1; window->width = gx_screenWidth();//sdl->sdlsurf->w; window->height = 480;//sdl->sdlsurf->h; sdl->safe_hofs = (window->width - window->width * options_get_float(mame_options(), SDLOPTVAL_SAFEAREA)) / 2; sdl->safe_vofs = (window->height - window->height * options_get_float(mame_options(), SDLOPTVAL_SAFEAREA)) / 2; /*if (sdl->scale_mode->is_yuv) yuv_overlay_init(window);*/ sdl->yuv_lookup = NULL; sdl->blittimer = 0; //if (is_inited) return 0; //is_inited = 1; //drawgx_yuv_init(sdl); //SDL_QuitSubSystem(SDL_INIT_VIDEO); if (is_inited) return 0; is_inited = 1; VIDEO_Init(); VIDEO_SetBlack(true); vmode = VIDEO_GetPreferredMode(NULL); switch (vmode->viTVMode >> 2) { case VI_PAL: vmode = &TVPal574IntDfScale; vmode->xfbHeight = 480; vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - 480)/2; vmode->viHeight = 480; break; case VI_NTSC: break; default: break; } VIDEO_Configure(vmode); xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(vmode)); VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer(xfb[currfb]); VIDEO_Flush(); VIDEO_WaitVSync(); if (vmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync(); else while (VIDEO_GetNextField()) VIDEO_WaitVSync(); gp_fifo = memalign(32, DEFAULT_FIFO_SIZE); memset(gp_fifo, 0, DEFAULT_FIFO_SIZE); GX_Init(gp_fifo, DEFAULT_FIFO_SIZE); atexit(drawgx_shutdown); GX_SetCopyClear(background, 0x00ffffff); // other gx setup GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); yscale = GX_GetYScaleFactor(vmode->efbHeight,vmode->xfbHeight); xfbHeight = GX_SetDispCopyYScale(yscale); GX_SetScissor(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopySrc(0,0,vmode->fbWidth,vmode->efbHeight); GX_SetDispCopyDst(vmode->fbWidth,xfbHeight); GX_SetCopyFilter(vmode->aa,vmode->sample_pattern,GX_TRUE,vmode->vfilter); GX_SetFieldMode(vmode->field_rendering,((vmode->viHeight==2*vmode->xfbHeight)?GX_ENABLE:GX_DISABLE)); if (vmode->aa) GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR); else GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR); GX_SetCullMode(GX_CULL_NONE); GX_CopyDisp(xfb[currfb],GX_TRUE); GX_SetDispCopyGamma(GX_GM_1_0); GX_SetNumChans(1); GX_SetNumTexGens(1); GX_SetTevOp(GX_TEVSTAGE0, GX_MODULATE); GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY); GX_SetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR); GX_SetAlphaUpdate(GX_TRUE); GX_SetColorUpdate(GX_TRUE); guOrtho(perspective,0,479,0,gx_screenWidth()-1,0,300); GX_LoadProjectionMtx(perspective, GX_ORTHOGRAPHIC); guMtxIdentity(GXmodelView2D); guMtxTransApply (GXmodelView2D, GXmodelView2D, 0.0F, 0.0F, -5.0F); GX_LoadPosMtxImm(GXmodelView2D,GX_PNMTX0); GX_SetViewport(0,0,vmode->fbWidth,vmode->efbHeight,0,1); GX_InvVtxCache(); GX_ClearVtxDesc(); GX_InvalidateTexAll(); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); GX_SetVtxDesc(GX_VA_POS, GX_DIRECT); GX_SetVtxDesc(GX_VA_CLR0, GX_DIRECT); GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT); GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); VIDEO_SetBlack(false); GX_InitTexObj(&blankTex, blanktex, 1, 1, GX_TF_RGB5A3, GX_CLAMP, GX_CLAMP, GX_FALSE); return 0; }
static void extract_video_config(running_machine *machine) { const char *stemp; // global options: extract the data video_config.windowed = options_get_bool(&machine->options(), WINOPTION_WINDOW); video_config.prescale = options_get_int(&machine->options(), WINOPTION_PRESCALE); video_config.keepaspect = options_get_bool(&machine->options(), WINOPTION_KEEPASPECT); video_config.numscreens = options_get_int(&machine->options(), WINOPTION_NUMSCREENS); // if we are in debug mode, never go full screen if (machine->debug_flags & DEBUG_FLAG_OSD_ENABLED) video_config.windowed = TRUE; // per-window options: extract the data get_resolution(machine->options(), WINOPTION_RESOLUTION0, &video_config.window[0], TRUE); get_resolution(machine->options(), WINOPTION_RESOLUTION1, &video_config.window[1], TRUE); get_resolution(machine->options(), WINOPTION_RESOLUTION2, &video_config.window[2], TRUE); get_resolution(machine->options(), WINOPTION_RESOLUTION3, &video_config.window[3], TRUE); // video options: extract the data stemp = options_get_string(&machine->options(), WINOPTION_VIDEO); if (strcmp(stemp, "d3d") == 0) video_config.mode = VIDEO_MODE_D3D; else if (strcmp(stemp, "ddraw") == 0) video_config.mode = VIDEO_MODE_DDRAW; else if (strcmp(stemp, "gdi") == 0) video_config.mode = VIDEO_MODE_GDI; else if (strcmp(stemp, "none") == 0) { video_config.mode = VIDEO_MODE_NONE; if (options_get_int(&machine->options(), OPTION_SECONDS_TO_RUN) == 0) mame_printf_warning("Warning: -video none doesn't make much sense without -seconds_to_run\n"); } else { mame_printf_warning("Invalid video value %s; reverting to gdi\n", stemp); video_config.mode = VIDEO_MODE_GDI; } video_config.waitvsync = options_get_bool(&machine->options(), WINOPTION_WAITVSYNC); video_config.syncrefresh = options_get_bool(&machine->options(), WINOPTION_SYNCREFRESH); video_config.triplebuf = options_get_bool(&machine->options(), WINOPTION_TRIPLEBUFFER); video_config.switchres = options_get_bool(&machine->options(), WINOPTION_SWITCHRES); // ddraw options: extract the data video_config.hwstretch = options_get_bool(&machine->options(), WINOPTION_HWSTRETCH); // d3d options: extract the data video_config.filter = options_get_bool(&machine->options(), WINOPTION_FILTER); if (video_config.prescale == 0) video_config.prescale = 1; // misc options: sanity check values // per-window options: sanity check values // d3d options: sanity check values options_get_int(&machine->options(), WINOPTION_D3DVERSION); options_get_float(&machine->options(), WINOPTION_FULLSCREENBRIGHTNESS); options_get_float(&machine->options(), WINOPTION_FULLLSCREENCONTRAST); options_get_float(&machine->options(), WINOPTION_FULLSCREENGAMMA); }