Skip to content

Commit

Permalink
fix for SDL_DC_TEXTURED_VIDEO, default video init to 320x240, for sup…
Browse files Browse the repository at this point in the history
…port of 512X256 texure scaling.
  • Loading branch information
GPF committed Jan 4, 2025
1 parent c7e1dea commit 569f473
Showing 1 changed file with 61 additions and 141 deletions.
202 changes: 61 additions & 141 deletions src/video/dreamcast/SDL_dreamcastvideo.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,200 +191,120 @@ static void DREAMCAST_EVDEV_Poll(_THIS)
SDL_EVDEV_Poll();
}
#endif
int __sdl_dc_is_60hz=0;

int __sdl_dc_is_60hz = 0;

int DREAMCAST_VideoInit(_THIS) {
SDL_VideoDisplay display;
SDL_DisplayMode current_mode;
int disp_mode;
int pixel_mode;
int width = 640, height = 480; // Default to 640x480, modify based on requirements
int bpp = 32; // Bits per pixel
Uint32 Rmask, Gmask, Bmask;

SDL_zero(current_mode);

// Determine if we are in 60Hz or 50Hz mode based on cable type and region
if (!vid_check_cable()) {
__sdl_dc_is_60hz = 1; // 60Hz for VGA
if (width == 320 && height == 240) disp_mode = DM_320x240_VGA;
else if (width == 640 && height == 480) disp_mode = DM_640x480_VGA;
else if (width == 768 && height == 480) disp_mode = DM_768x480_PAL_IL;
else {
SDL_SetError("Couldn't find requested mode in list");
return -1;
}
} else if (flashrom_get_region() != FLASHROM_REGION_US && !sdl_dc_ask_60hz()) {
__sdl_dc_is_60hz = 0;
if (width == 320 && height == 240) disp_mode = DM_320x240_PAL;
else if (width == 640 && height == 480) disp_mode = DM_640x480_PAL_IL;
else {
SDL_SetError("Couldn't find requested mode in list");
return -1;
}
} else {
__sdl_dc_is_60hz = 1; // Default to 60Hz
if (width == 320 && height == 240) disp_mode = DM_320x240;
else if (width == 640 && height == 480) disp_mode = DM_640x480;
else if (width == 768 && height == 480) disp_mode = DM_768x480;
else {
SDL_SetError("Couldn't find requested mode in list");
return -1;
}
}
SDL_VideoDisplay display;

// Set pixel mode based on bpp
switch (bpp) {
case 15: // ARGB1555
pixel_mode = PM_RGB555;
Rmask = 0x00007C00; // 5 bits for Red
Gmask = 0x000003E0; // 5 bits for Green
Bmask = 0x0000001F; // 5 bits for Blue
current_mode.format = SDL_PIXELFORMAT_ARGB1555; // Set the correct format
break;
case 16: // RGB565
pixel_mode = PM_RGB565;
Rmask = 0x0000F800;
Gmask = 0x000007E0;
Bmask = 0x0000001F;
current_mode.format = SDL_PIXELFORMAT_RGB565; // Set the correct format
break;
case 24: // RGB888
case 32: // ARGB8888
pixel_mode = PM_RGB888;
Rmask = 0x00FF0000;
Gmask = 0x0000FF00;
Bmask = 0x000000FF;
current_mode.format = SDL_PIXELFORMAT_RGB888; // Set the correct format
break;
default:
SDL_SetError("Unsupported pixel format");
return -1;
// Set default pixel format to 16-bit RGB565
Uint32 Rmask = 0x0000f800;
Uint32 Gmask = 0x000007e0;
Uint32 Bmask = 0x0000001f;
Uint32 Amask = 0; // No alpha channel
int width = 640;
int height = 480;
const char *video_mode_hint = SDL_GetHint(SDL_HINT_DC_VIDEO_MODE);
if (video_mode_hint != NULL && strcmp(video_mode_hint, "SDL_DC_TEXTURED_VIDEO") == 0) {
width = 320;
height = 240;
}
SDL_zero(current_mode);

// Initialize other properties of current_mode as needed
// Initialize the default display mode
current_mode.format = SDL_PIXELFORMAT_RGB565;
current_mode.w = width;
current_mode.h = height;
current_mode.refresh_rate = (__sdl_dc_is_60hz) ? 60 : 50; // Set refresh rate based on __sdl_dc_is_60hz
current_mode.refresh_rate = 60; // Assume 60Hz for simplicity
current_mode.driverdata = NULL;

// Set up the display
SDL_zero(display);
display.desktop_mode = current_mode;
display.current_mode = current_mode;
display.driverdata = NULL;

SDL_AddDisplayMode(&display, &current_mode);
SDL_AddVideoDisplay(&display, SDL_TRUE);

SDL_SetHint(SDL_HINT_DC_VIDEO_MODE, "SDL_DC_DIRECT_VIDEO"); // Default video mode
SDL_SetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER, "1"); // Default double buffering

disp_mode |= DM_MULTIBUFFER; // Enable double buffering
SDL_Log("SDL2 Double Buffer enabled");

// Set the mode using KOS
vid_set_mode(disp_mode, pixel_mode);
// Add the display to SDL's list of displays
if (SDL_AddVideoDisplay(&display, SDL_FALSE) < 0) {
SDL_SetError("Failed to add video display");
return -1;
}

SDL_Log("SDL2 Dreamcast video initialized.");
return 1; // Success
SDL_Log("SDL2 Dreamcast video initialized: %dx%d, RGB565", width, height);
return 0;
}


void DREAMCAST_GetDisplayModes(_THIS, SDL_VideoDisplay *display) {
SDL_DisplayMode mode;
int refresh_rate = __sdl_dc_is_60hz ? 60 : 50; // Determine refresh rate based on flag

// Adding a 320x240 mode in ARGB1555 format
SDL_zero(mode);
mode.w = 320;
mode.h = 240;
mode.format = SDL_PIXELFORMAT_ARGB1555; // Change as necessary
mode.refresh_rate = refresh_rate; // Use the determined refresh rate
SDL_AddDisplayMode(display, &mode);

// Adding a 640x480 mode in RGB565 format
SDL_zero(mode);
mode.w = 640;
mode.h = 480;
mode.format = SDL_PIXELFORMAT_RGB565; // Change as necessary
mode.refresh_rate = refresh_rate; // Use the determined refresh rate
SDL_AddDisplayMode(display, &mode);

// Adding a 768x480 mode in RGB565 format
SDL_zero(mode);
mode.w = 768;
mode.h = 480;
mode.format = SDL_PIXELFORMAT_RGB565; // Change as necessary
mode.refresh_rate = refresh_rate; // Use the determined refresh rate
SDL_AddDisplayMode(display, &mode);

// Adding a 640x480 mode in RGB888 format
SDL_zero(mode);
mode.w = 640;
mode.h = 480;
mode.format = SDL_PIXELFORMAT_RGB888; // Change as necessary
mode.refresh_rate = refresh_rate; // Use the determined refresh rate
SDL_AddDisplayMode(display, &mode);

// Optionally, you can add more modes depending on your requirements
// e.g., 800x600, 1024x768, etc.
int refresh_rate = __sdl_dc_is_60hz ? 60 : 50;

// Adding supported modes
const int supported_modes[][2] = {
{320, 240},
{640, 480},
{768, 480}
};

for (int i = 0; i < sizeof(supported_modes) / sizeof(supported_modes[0]); i++) {
SDL_zero(mode);
mode.w = supported_modes[i][0];
mode.h = supported_modes[i][1];
mode.format = SDL_PIXELFORMAT_RGB565; // Change as necessary
mode.refresh_rate = refresh_rate;
SDL_AddDisplayMode(display, &mode);
}

SDL_Log("Display modes for Dreamcast retrieved successfully.");
}

int DREAMCAST_SetDisplayMode(_THIS, SDL_VideoDisplay *display, SDL_DisplayMode *mode) {
int pixel_mode;
int disp_mode = -1; // Initialize to an invalid value
int disp_mode = -1;

// Determine the appropriate display mode based on width and height
// Determine the appropriate display mode
if (__sdl_dc_is_60hz) {
if (mode->w == 320 && mode->h == 240) {
disp_mode = DM_320x240; // 60Hz mode
disp_mode = DM_320x240;
} else if (mode->w == 640 && mode->h == 480) {
disp_mode = DM_640x480; // 60Hz mode
disp_mode = DM_640x480;
} else if (mode->w == 768 && mode->h == 480) {
disp_mode = DM_768x480; // 60Hz mode
disp_mode = DM_768x480;
}
} else { // 50Hz
} else {
if (mode->w == 320 && mode->h == 240) {
disp_mode = DM_320x240_PAL; // 50Hz mode
disp_mode = DM_320x240_PAL;
} else if (mode->w == 640 && mode->h == 480) {
disp_mode = DM_640x480_PAL_IL; // 50Hz mode
disp_mode = DM_640x480_PAL_IL;
}
}

// Check if the determined display mode is valid
if (disp_mode < 0) {
SDL_SetError("Unsupported display mode");
return -1;
}

// Determine pixel mode based on the format in the mode
// Determine pixel mode
switch (mode->format) {
case SDL_PIXELFORMAT_ARGB1555:
pixel_mode = PM_RGB555; // Use the correct constant
pixel_mode = PM_RGB555;
break;
case SDL_PIXELFORMAT_RGB565:
pixel_mode = PM_RGB565; // Keep as is
pixel_mode = PM_RGB565;
break;
case SDL_PIXELFORMAT_RGB888:
pixel_mode = PM_RGB888; // Keep as is
pixel_mode = PM_RGB888;
break;
case SDL_PIXELFORMAT_UNKNOWN:
default:
SDL_SetError("Unsupported pixel format");
return -1;
}

// Check for double buffering hint
const char *double_buffer_hint = SDL_GetHint(SDL_HINT_VIDEO_DOUBLE_BUFFER);
if (double_buffer_hint && SDL_GetHintBoolean(SDL_HINT_VIDEO_DOUBLE_BUFFER, SDL_TRUE)) {
disp_mode |= DM_MULTIBUFFER; // Enable double buffering
SDL_Log("SDL2 Double Buffer enabled");
}
// Set the video mode using KOS (no return value handling)
vid_set_mode(disp_mode, pixel_mode); // Assuming this function works fine without return checks

SDL_Log("Display mode set to: %dx%d @ %dHz", mode->w, mode->h, mode->refresh_rate);
return 0; // Return success
// Set the video mode
vid_set_mode(disp_mode, pixel_mode);
SDL_Log("Display mode set to %dx%d @ %dHz", mode->w, mode->h, mode->refresh_rate);
return 0;
}

void DREAMCAST_VideoQuit(_THIS)
Expand Down

0 comments on commit 569f473

Please sign in to comment.