mirror of
https://github.com/kanjitalk755/macemu.git
synced 2024-12-22 13:30:07 +00:00
BeOS: WIP update to video mode switching support code.
This commit is contained in:
parent
2adcbc2694
commit
66f68a995a
@ -38,6 +38,7 @@ user_string_def platform_strings[] = {
|
||||
{STR_NET_CONFIG_MODIFY_WARN, "To enable Ethernet networking for Basilisk II, your network configuration has to be modified and the network restarted. Do you want this to be done now (selecting \"Cancel\" will disable Ethernet under Basilisk II)?."},
|
||||
{STR_NET_ADDON_INIT_FAILED, "SheepShaver net server add-on found\nbut there seems to be no network hardware.\nPlease check your network preferences."},
|
||||
{STR_NET_ADDON_CLONE_FAILED, "Cloning of the network transfer area failed."},
|
||||
{STR_VIDEO_FAILED, "Failed to set video mode."},
|
||||
|
||||
{-1, NULL} // End marker
|
||||
};
|
||||
|
@ -28,7 +28,8 @@ enum {
|
||||
STR_NO_NET_ADDON_WARN,
|
||||
STR_NET_CONFIG_MODIFY_WARN,
|
||||
STR_NET_ADDON_INIT_FAILED,
|
||||
STR_NET_ADDON_CLONE_FAILED
|
||||
STR_NET_ADDON_CLONE_FAILED,
|
||||
STR_VIDEO_FAILED
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -70,6 +70,27 @@ enum {
|
||||
extern void SysCreateVolumeMenu(BMenu *menu, uint32 msg);
|
||||
extern void SysMountVolume(const char *name);
|
||||
|
||||
// Global variables
|
||||
static bool classic_mode = false; // Flag: Classic Mac video mode
|
||||
static int scr_mode_bit = 0;
|
||||
static vector<video_mode> VideoModes; // Supported video modes
|
||||
|
||||
/*
|
||||
* monitor_desc subclass for BeOS display
|
||||
*/
|
||||
|
||||
class BeOS_monitor_desc : public monitor_desc {
|
||||
public:
|
||||
BeOS_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {}
|
||||
~BeOS_monitor_desc() {}
|
||||
|
||||
virtual void switch_to_current_mode(void);
|
||||
virtual void set_palette(uint8 *pal, int num);
|
||||
|
||||
bool video_open(void);
|
||||
void video_close(void);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* A simple view class for blitting a bitmap on the screen
|
||||
@ -98,7 +119,7 @@ private:
|
||||
|
||||
class MacWindow : public BDirectWindow {
|
||||
public:
|
||||
MacWindow(BRect frame);
|
||||
MacWindow(BRect frame, const BeOS_monitor_desc& monitor);
|
||||
virtual ~MacWindow();
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
virtual void DirectConnected(direct_buffer_info *info);
|
||||
@ -127,6 +148,8 @@ private:
|
||||
int32 bytes_per_row;
|
||||
color_space pixel_format;
|
||||
bool unclipped;
|
||||
|
||||
BeOS_monitor_desc monitor;
|
||||
};
|
||||
|
||||
|
||||
@ -136,7 +159,7 @@ private:
|
||||
|
||||
class MacScreen : public BWindowScreen {
|
||||
public:
|
||||
MacScreen(const char *name, int mode_bit, status_t *error);
|
||||
MacScreen(const BeOS_monitor_desc& monitor, const char *name, int mode_bit, status_t *error);
|
||||
virtual ~MacScreen();
|
||||
virtual void Quit(void);
|
||||
virtual void ScreenConnected(bool active);
|
||||
@ -155,6 +178,8 @@ private:
|
||||
bool quitting; // Flag for ScreenConnected: We are quitting, don't pause emulator thread
|
||||
bool screen_active;
|
||||
bool first_time;
|
||||
|
||||
BeOS_monitor_desc monitor;
|
||||
};
|
||||
|
||||
|
||||
@ -170,74 +195,144 @@ static uint8 MacCursor[68] = {16, 1}; // Mac cursor image
|
||||
* Initialization
|
||||
*/
|
||||
|
||||
// Add resolution to list of supported modes and set VideoMonitor
|
||||
static void set_video_monitor(uint32 width, uint32 height, uint32 bytes_per_row, int depth)
|
||||
// Add mode to list of supported modes
|
||||
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth)
|
||||
{
|
||||
video_mode mode;
|
||||
|
||||
mode.x = width;
|
||||
mode.y = height;
|
||||
mode.resolution_id = 0x80;
|
||||
mode.resolution_id = resolution_id;
|
||||
mode.bytes_per_row = bytes_per_row;
|
||||
|
||||
switch (depth) {
|
||||
case 1:
|
||||
mode.depth = VDEPTH_1BIT;
|
||||
break;
|
||||
case 2:
|
||||
mode.depth = VDEPTH_2BIT;
|
||||
break;
|
||||
case 4:
|
||||
mode.depth = VDEPTH_4BIT;
|
||||
break;
|
||||
case 8:
|
||||
mode.depth = VDEPTH_8BIT;
|
||||
break;
|
||||
case 15:
|
||||
mode.depth = VDEPTH_16BIT;
|
||||
break;
|
||||
case 16:
|
||||
mode.depth = VDEPTH_16BIT;
|
||||
break;
|
||||
case 24:
|
||||
case 32:
|
||||
mode.depth = VDEPTH_32BIT;
|
||||
break;
|
||||
}
|
||||
|
||||
mode.depth = depth;
|
||||
VideoModes.push_back(mode);
|
||||
video_init_depth_list();
|
||||
VideoMonitor.mode = mode;
|
||||
}
|
||||
|
||||
// Add standard list of windowed modes for given color depth
|
||||
static void add_window_modes(video_depth depth)
|
||||
{
|
||||
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth);
|
||||
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth);
|
||||
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth);
|
||||
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth);
|
||||
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth);
|
||||
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth);
|
||||
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth);
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool VideoInit(bool classic)
|
||||
{
|
||||
// Create semaphore
|
||||
mac_os_lock = create_sem(0, "MacOS Frame Buffer Lock");
|
||||
classic_mode = classic;
|
||||
|
||||
// Get screen mode from preferences
|
||||
const char *mode_str = PrefsFindString("screen");
|
||||
const char *mode_str;
|
||||
if (classic_mode)
|
||||
mode_str = "win/512/342";
|
||||
else
|
||||
mode_str = PrefsFindString("screen");
|
||||
|
||||
// Determine type and mode
|
||||
int default_width = 512, default_height = 384;
|
||||
display_type = DISPLAY_WINDOW;
|
||||
int width = 512, height = 384;
|
||||
int scr_mode_bit = 0;
|
||||
if (mode_str) {
|
||||
if (sscanf(mode_str, "win/%d/%d", &width, &height) == 2)
|
||||
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2)
|
||||
display_type = DISPLAY_WINDOW;
|
||||
else if (sscanf(mode_str, "scr/%d", &scr_mode_bit) == 1)
|
||||
display_type = DISPLAY_SCREEN;
|
||||
}
|
||||
#if 0
|
||||
if (default_width <= 0)
|
||||
default_width = DisplayWidth(x_display, screen);
|
||||
else if (default_width > DisplayWidth(x_display, screen))
|
||||
default_width = DisplayWidth(x_display, screen);
|
||||
if (default_height <= 0)
|
||||
default_height = DisplayHeight(x_display, screen);
|
||||
else if (default_height > DisplayHeight(x_display, screen))
|
||||
default_height = DisplayHeight(x_display, screen);
|
||||
#endif
|
||||
|
||||
// Mac screen depth follows X depth
|
||||
video_depth default_depth = VDEPTH_1BIT;
|
||||
#if 0
|
||||
switch (DefaultDepth(x_display, screen)) {
|
||||
case 8:
|
||||
default_depth = VDEPTH_8BIT;
|
||||
break;
|
||||
case 15: case 16:
|
||||
default_depth = VDEPTH_16BIT;
|
||||
break;
|
||||
case 24: case 32:
|
||||
default_depth = VDEPTH_32BIT;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Construct list of supported modes
|
||||
if (display_type == DISPLAY_WINDOW) {
|
||||
if (classic)
|
||||
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT);
|
||||
else {
|
||||
for (unsigned d=VDEPTH_1BIT; d<=VDEPTH_32BIT; d++) {
|
||||
//if (find_visual_for_depth(video_depth(d)))
|
||||
add_window_modes(video_depth(d));
|
||||
}
|
||||
}
|
||||
} else
|
||||
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth);
|
||||
if (VideoModes.empty()) {
|
||||
ErrorAlert(STR_VIDEO_FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find requested default mode with specified dimensions
|
||||
uint32 default_id;
|
||||
std::vector<video_mode>::const_iterator i, end = VideoModes.end();
|
||||
for (i = VideoModes.begin(); i != end; ++i) {
|
||||
if (i->x == default_width && i->y == default_height && i->depth == default_depth) {
|
||||
default_id = i->resolution_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == end) { // not found, use first available mode
|
||||
default_depth = VideoModes[0].depth;
|
||||
default_id = VideoModes[0].resolution_id;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
D(bug("Available video modes:\n"));
|
||||
for (i = VideoModes.begin(); i != end; ++i) {
|
||||
int bits = 1 << i->depth;
|
||||
if (bits == 16)
|
||||
bits = 15;
|
||||
else if (bits == 32)
|
||||
bits = 24;
|
||||
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create X11_monitor_desc for this (the only) display
|
||||
BeOS_monitor_desc *monitor = new BeOS_monitor_desc(VideoModes, default_depth, default_id);
|
||||
VideoMonitors.push_back(monitor);
|
||||
|
||||
// Open display
|
||||
return monitor->video_open();
|
||||
}
|
||||
|
||||
bool BeOS_monitor_desc::video_open() {
|
||||
// Create semaphore
|
||||
mac_os_lock = create_sem(0, "MacOS Frame Buffer Lock");
|
||||
|
||||
const video_mode &mode = get_current_mode();
|
||||
|
||||
// Open display
|
||||
switch (display_type) {
|
||||
case DISPLAY_WINDOW:
|
||||
the_window = new MacWindow(BRect(0, 0, width-1, height-1));
|
||||
the_window = new MacWindow(BRect(0, 0, mode.x-1, mode.y-1), *this);
|
||||
break;
|
||||
case DISPLAY_SCREEN: {
|
||||
status_t screen_error;
|
||||
the_screen = new MacScreen(GetString(STR_WINDOW_TITLE), scr_mode_bit & 0x1f, &screen_error);
|
||||
the_screen = new MacScreen(*this, GetString(STR_WINDOW_TITLE), scr_mode_bit & 0x1f, &screen_error);
|
||||
if (screen_error != B_NO_ERROR) {
|
||||
the_screen->PostMessage(B_QUIT_REQUESTED);
|
||||
while (the_screen)
|
||||
@ -288,7 +383,7 @@ void VideoExit(void)
|
||||
* Set palette
|
||||
*/
|
||||
|
||||
void video_set_palette(uint8 *pal, int num)
|
||||
void BeOS_monitor_desc::set_palette(uint8 *pal, int num)
|
||||
{
|
||||
switch (display_type) {
|
||||
case DISPLAY_WINDOW: {
|
||||
@ -313,7 +408,7 @@ void video_set_palette(uint8 *pal, int num)
|
||||
* Switch video mode
|
||||
*/
|
||||
|
||||
void video_switch_to_mode(const video_mode &mode)
|
||||
void BeOS_monitor_desc::switch_to_current_mode()
|
||||
{
|
||||
}
|
||||
|
||||
@ -461,7 +556,9 @@ static filter_result filter_func(BMessage *msg, BHandler **target, BMessageFilte
|
||||
* Window constructor
|
||||
*/
|
||||
|
||||
MacWindow::MacWindow(BRect frame) : BDirectWindow(frame, GetString(STR_WINDOW_TITLE), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE)
|
||||
MacWindow::MacWindow(BRect frame, const BeOS_monitor_desc& monitor)
|
||||
: BDirectWindow(frame, GetString(STR_WINDOW_TITLE), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE)
|
||||
, monitor(monitor)
|
||||
{
|
||||
supports_direct_mode = SupportsWindowMode();
|
||||
|
||||
@ -472,15 +569,24 @@ MacWindow::MacWindow(BRect frame) : BDirectWindow(frame, GetString(STR_WINDOW_TI
|
||||
// Allocate bitmap and Mac frame buffer
|
||||
uint32 x = frame.IntegerWidth() + 1;
|
||||
uint32 y = frame.IntegerHeight() + 1;
|
||||
the_bitmap = new BBitmap(frame, B_COLOR_8_BIT);
|
||||
the_buffer = new uint8[x * (y + 2)]; // "y + 2" for safety
|
||||
const video_mode &mode = monitor.get_current_mode();
|
||||
switch (mode.depth) {
|
||||
case VDEPTH_1BIT:
|
||||
the_bitmap = new BBitmap(frame, B_RGB16);
|
||||
break;
|
||||
case VDEPTH_8BIT:
|
||||
the_bitmap = new BBitmap(frame, B_CMAP8);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "width: %d", 1 << mode.depth);
|
||||
debugger("OOPS");
|
||||
}
|
||||
the_buffer = new uint8[x * (y + 2) * 2]; // "y + 2" for safety
|
||||
|
||||
// Add resolution and set VideoMonitor
|
||||
set_video_monitor(x, y, x, 8);
|
||||
#if REAL_ADDRESSING
|
||||
VideoMonitor.mac_frame_base = (uint32)the_buffer;
|
||||
monitor.set_mac_frame_base((uint32)the_buffer);
|
||||
#else
|
||||
VideoMonitor.mac_frame_base = MacFrameBaseMac;
|
||||
monitor.set_mac_frame_base(MacFrameBaseMac);
|
||||
#endif
|
||||
|
||||
#if !REAL_ADDRESSING
|
||||
@ -656,12 +762,13 @@ void MacWindow::MessageReceived(BMessage *msg)
|
||||
MessageQueue()->Unlock();
|
||||
|
||||
// Convert Mac screen buffer to BeOS palette and blit
|
||||
const video_mode &mode = monitor.get_current_mode();
|
||||
uint8 *source = the_buffer - 1;
|
||||
uint8 *dest = (uint8 *)the_bitmap->Bits() - 1;
|
||||
uint32 length = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y;
|
||||
uint32 length = mode.bytes_per_row * mode.y;
|
||||
for (int i=0; i<length; i++)
|
||||
*++dest = remap_mac_be[*++source];
|
||||
BRect update_rect = BRect(0, 0, VideoMonitor.mode.x-1, VideoMonitor.mode.y-1);
|
||||
BRect update_rect = BRect(0, 0, mode.x-1, mode.y-1);
|
||||
main_view->DrawBitmapAsync(the_bitmap, update_rect, update_rect);
|
||||
break;
|
||||
}
|
||||
@ -781,8 +888,9 @@ status_t MacWindow::tick_func(void *arg)
|
||||
uint8 *source = obj->the_buffer - 1;
|
||||
uint8 *dest = (uint8 *)obj->bits;
|
||||
uint32 bytes_per_row = obj->bytes_per_row;
|
||||
int xsize = VideoMonitor.mode.x;
|
||||
int ysize = VideoMonitor.mode.y;
|
||||
const video_mode &mode = obj->monitor.get_current_mode();
|
||||
int xsize = mode.x;
|
||||
int ysize = mode.y;
|
||||
for (int y=0; y<ysize; y++) {
|
||||
uint32 *p = (uint32 *)dest - 1;
|
||||
for (int x=0; x<xsize/4; x++) {
|
||||
@ -837,7 +945,9 @@ void BitmapView::MouseMoved(BPoint point, uint32 transit, const BMessage *messag
|
||||
* Screen constructor
|
||||
*/
|
||||
|
||||
MacScreen::MacScreen(const char *name, int mode_bit, status_t *error) : BWindowScreen(name, 1 << mode_bit, error), tick_thread(-1)
|
||||
MacScreen::MacScreen(const BeOS_monitor_desc& monitor, const char *name, int mode_bit, status_t *error)
|
||||
: BWindowScreen(name, 1 << mode_bit, error), tick_thread(-1)
|
||||
, monitor(monitor)
|
||||
{
|
||||
// Set all variables
|
||||
frame_backup = NULL;
|
||||
@ -902,26 +1012,21 @@ void MacScreen::ScreenConnected(bool active)
|
||||
{
|
||||
graphics_card_info *info = CardInfo();
|
||||
screen_active = active;
|
||||
const video_mode &mode = monitor.get_current_mode();
|
||||
|
||||
if (active == true) {
|
||||
|
||||
// Add resolution and set VideoMonitor
|
||||
if (first_time) {
|
||||
set_video_monitor(info->width, info->height, info->bytes_per_row, info->bits_per_pixel);
|
||||
first_time = false;
|
||||
}
|
||||
|
||||
// Set VideoMonitor
|
||||
#if REAL_ADDRESSING
|
||||
VideoMonitor.mac_frame_base = (uint32)info->frame_buffer;
|
||||
monitor.set_mac_frame_base((uint32)info->frame_buffer);
|
||||
#else
|
||||
VideoMonitor.mac_frame_base = MacFrameBaseMac;
|
||||
monitor.set_mac_frame_base(MacFrameBaseMac);
|
||||
#endif
|
||||
|
||||
#if !REAL_ADDRESSING
|
||||
// Set variables for UAE memory mapping
|
||||
MacFrameBaseHost = (uint8 *)info->frame_buffer;
|
||||
MacFrameSize = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y;
|
||||
MacFrameSize = mode.bytes_per_row * mode.y;
|
||||
switch (info->bits_per_pixel) {
|
||||
case 15:
|
||||
MacFrameLayout = FLAYOUT_HOST_555;
|
||||
@ -940,13 +1045,13 @@ void MacScreen::ScreenConnected(bool active)
|
||||
|
||||
// Copy from backup store to frame buffer
|
||||
if (frame_backup != NULL) {
|
||||
memcpy(info->frame_buffer, frame_backup, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
|
||||
memcpy(info->frame_buffer, frame_backup, mode.bytes_per_row * mode.y);
|
||||
delete[] frame_backup;
|
||||
frame_backup = NULL;
|
||||
}
|
||||
|
||||
// Restore palette
|
||||
if (VideoMonitor.mode.depth == VDEPTH_8BIT)
|
||||
if (mode.depth == VDEPTH_8BIT)
|
||||
SetColorList(palette);
|
||||
|
||||
// Restart/signal emulator thread
|
||||
@ -960,8 +1065,8 @@ void MacScreen::ScreenConnected(bool active)
|
||||
acquire_sem(mac_os_lock);
|
||||
|
||||
// Create backup store and save frame buffer
|
||||
frame_backup = new uint8[VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y];
|
||||
memcpy(frame_backup, info->frame_buffer, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y);
|
||||
frame_backup = new uint8[mode.bytes_per_row * mode.y];
|
||||
memcpy(frame_backup, info->frame_buffer, mode.bytes_per_row * mode.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user