--- BasiliskII/src/AmigaOS/video_amiga.cpp 2001/10/16 17:27:52 1.21 +++ BasiliskII/src/AmigaOS/video_amiga.cpp 2002/06/23 08:27:05 1.24 @@ -1,7 +1,7 @@ /* * video_amiga.cpp - Video/graphics emulation, AmigaOS specific stuff * - * Basilisk II (C) 1997-2001 Christian Bauer + * Basilisk II (C) 1997-2002 Christian Bauer * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,12 +25,18 @@ #include #include #include +#define __USE_SYSBASE #include #include #include #include #include #include +#include +#include +#include +#include +#include #include "sysdeps.h" #include "cpu_emulation.h" @@ -44,6 +50,9 @@ #include "debug.h" +// Supported video modes +static vector VideoModes; + // Display types enum { DISPLAY_WINDOW, @@ -54,18 +63,11 @@ enum { // Global variables static int32 frame_skip; -static int display_type = DISPLAY_WINDOW; // See enum above -static struct Screen *the_screen = NULL; -static struct Window *the_win = NULL; -static struct BitMap *the_bitmap = NULL; -static UWORD *null_pointer = NULL; // Blank mouse pointer data -static UWORD *current_pointer = (UWORD *)-1; // Currently visible mouse pointer data -static LONG black_pen = -1, white_pen = -1; -static struct Process *periodic_proc = NULL; // Periodic process -static int window_width, window_height; // width and height for window display -static ULONG screen_mode_id; // mode ID for screen display +static UWORD *null_pointer = NULL; // Blank mouse pointer data +static UWORD *current_pointer = (UWORD *)-1; // Currently visible mouse pointer data +static struct Process *periodic_proc = NULL; // Periodic process -extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) +extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) // Amiga -> Mac raw keycode translation table @@ -89,238 +91,114 @@ static const uint8 keycode2mac[0x80] = { }; -// Prototypes -static bool video_open(const video_mode &mode); -static void video_close(); -static void periodic_func(void); -static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth); -static void add_modes(uint32 width, uint32 height, video_depth depth); -static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth); -static ULONG bits_from_depth(video_depth depth); -static bool is_valid_modeid(int display_type, ULONG mode_id); -static bool check_modeid_p96(ULONG mode_id); -static bool check_modeid_cgfx(ULONG mode_id); +class Amiga_monitor_desc : public monitor_desc { +public: + Amiga_monitor_desc(const vector &available_modes, video_depth default_depth, uint32 default_id, int default_display_type) + : monitor_desc(available_modes, default_depth, default_id), display_type(default_display_type) {}; + ~Amiga_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); +public: + int display_type; // See enum above +}; /* - * Initialization + * Display "driver" classes */ +class driver_base { +public: + driver_base(Amiga_monitor_desc &m); + virtual ~driver_base(); + + virtual void set_palette(uint8 *pal, int num) {}; + virtual struct BitMap *get_bitmap() { return NULL; }; +public: + Amiga_monitor_desc &monitor; // Associated video monitor + const video_mode &mode; // Video mode handled by the driver + BOOL init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) + struct Window *the_win; +}; -// Open window -static bool init_window(int width, int height) -{ - // Set absolute mouse mode - ADBSetRelMouseMode(false); - - // Open window - the_win = OpenWindowTags(NULL, - WA_Left, 0, WA_Top, 0, - WA_InnerWidth, width, WA_InnerHeight, height, - WA_SimpleRefresh, TRUE, - WA_NoCareRefresh, TRUE, - WA_Activate, TRUE, - WA_RMBTrap, TRUE, - WA_ReportMouse, TRUE, - WA_DragBar, TRUE, - WA_DepthGadget, TRUE, - WA_SizeGadget, FALSE, - WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), - TAG_END - ); - if (the_win == NULL) { - ErrorAlert(STR_OPEN_WINDOW_ERR); - return false; - } - - // Create bitmap ("height + 2" for safety) - the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL); - if (the_bitmap == NULL) { - ErrorAlert(STR_NO_MEM_ERR); - return false; - } - - // Add resolution and set VideoMonitor - VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0]; - - // Set FgPen and BgPen - black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); - white_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0xffffffff, 0xffffffff, 0xffffffff, NULL); - SetAPen(the_win->RPort, black_pen); - SetBPen(the_win->RPort, white_pen); - SetDrMd(the_win->RPort, JAM2); - return true; -} - -// Open PIP (requires Picasso96) -static bool init_pip(int width, int height) -{ - // Set absolute mouse mode - ADBSetRelMouseMode(false); - - // Open window - ULONG error = 0; - the_win = p96PIP_OpenTags( - P96PIP_SourceFormat, RGBFB_R5G5B5, - P96PIP_SourceWidth, width, - P96PIP_SourceHeight, height, - P96PIP_ErrorCode, (ULONG)&error, - WA_Left, 0, WA_Top, 0, - WA_InnerWidth, width, WA_InnerHeight, height, - WA_SimpleRefresh, TRUE, - WA_NoCareRefresh, TRUE, - WA_Activate, TRUE, - WA_RMBTrap, TRUE, - WA_ReportMouse, TRUE, - WA_DragBar, TRUE, - WA_DepthGadget, TRUE, - WA_SizeGadget, FALSE, - WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), - WA_PubScreenName, (ULONG)"Workbench", - TAG_END - ); - if (the_win == NULL || error) { - ErrorAlert(STR_OPEN_WINDOW_ERR); - return false; - } - - // Find bitmap - p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); - - // Add resolution and set VideoMonitor - VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); - return true; -} +class driver_window : public driver_base { +public: + driver_window(Amiga_monitor_desc &m, int width, int height); + ~driver_window(); + + struct BitMap *get_bitmap() { return the_bitmap; }; + +private: + LONG black_pen, white_pen; + struct BitMap *the_bitmap; +}; -// Open Picasso96 screen -static bool init_screen_p96(ULONG mode_id) -{ - // Set relative mouse mode - ADBSetRelMouseMode(true); +class driver_pip : public driver_base { +public: + driver_pip(Amiga_monitor_desc &m, int width, int height); + ~driver_pip(); - // Check if the mode is one we can handle - if (!check_modeid_p96(mode_id)) - { - ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); - return false; - } + struct BitMap *get_bitmap() { return the_bitmap; }; - // Yes, get width and height - uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); - uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); - uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); +private: + struct BitMap *the_bitmap; +}; - // Open screen - the_screen = p96OpenScreenTags( - P96SA_DisplayID, mode_id, - P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), - P96SA_Quiet, TRUE, - P96SA_NoMemory, TRUE, - P96SA_NoSprite, TRUE, - P96SA_Exclusive, TRUE, - TAG_END - ); - if (the_screen == NULL) { - ErrorAlert(STR_OPEN_SCREEN_ERR); - return false; - } +class driver_screen_p96 : public driver_base { +public: + driver_screen_p96(Amiga_monitor_desc &m, ULONG mode_id); + ~driver_screen_p96(); - // Open window - the_win = OpenWindowTags(NULL, - WA_Left, 0, WA_Top, 0, - WA_Width, width, WA_Height, height, - WA_SimpleRefresh, TRUE, - WA_NoCareRefresh, TRUE, - WA_Borderless, TRUE, - WA_Activate, TRUE, - WA_RMBTrap, TRUE, - WA_ReportMouse, TRUE, - WA_CustomScreen, (ULONG)the_screen, - TAG_END - ); - if (the_win == NULL) { - ErrorAlert(STR_OPEN_WINDOW_ERR); - return false; - } + void set_palette(uint8 *pal, int num); - ScreenToFront(the_screen); +private: + struct Screen *the_screen; +}; - // Add resolution and set VideoMonitor - VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); +class driver_screen_cgfx : public driver_base { +public: + driver_screen_cgfx(Amiga_monitor_desc &m, ULONG mode_id); + ~driver_screen_cgfx(); - return true; -} + void set_palette(uint8 *pal, int num); -// Open CyberGraphX screen -static bool init_screen_cgfx(ULONG mode_id) -{ - // Set relative mouse mode - ADBSetRelMouseMode(true); +private: + struct Screen *the_screen; +}; - // Check if the mode is one we can handle - if (!check_modeid_cgfx(mode_id)) - { - ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); - return false; - } - // Yes, get width and height - uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); - uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); - uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); +static driver_base *drv = NULL; // Pointer to currently used driver object - // Open screen - the_screen = OpenScreenTags(NULL, - SA_DisplayID, mode_id, - SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), - SA_Quiet, TRUE, - SA_Exclusive, TRUE, - TAG_END - ); - if (the_screen == NULL) { - ErrorAlert(STR_OPEN_SCREEN_ERR); - return false; - } - // Open window - the_win = OpenWindowTags(NULL, - WA_Left, 0, WA_Top, 0, - WA_Width, width, WA_Height, height, - WA_SimpleRefresh, TRUE, - WA_NoCareRefresh, TRUE, - WA_Borderless, TRUE, - WA_Activate, TRUE, - WA_RMBTrap, TRUE, - WA_ReportMouse, TRUE, - WA_CustomScreen, (ULONG)the_screen, - TAG_END - ); - if (the_win == NULL) { - ErrorAlert(STR_OPEN_WINDOW_ERR); - return false; - } - ScreenToFront(the_screen); - static UWORD ptr[] = { 0, 0, 0, 0 }; - SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer +// Prototypes +static void periodic_func(void); +static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth); +static void add_modes(uint32 width, uint32 height, video_depth depth); +static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth); +static ULONG bits_from_depth(video_depth depth); +static bool is_valid_modeid(int display_type, ULONG mode_id); +static bool check_modeid_p96(ULONG mode_id); +static bool check_modeid_cgfx(ULONG mode_id); - // Set VideoMonitor - ULONG frame_base; - APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, - LBMI_BASEADDRESS, (ULONG)&frame_base, - TAG_END - ); - UnLockBitMap(handle); - VideoMonitor.mac_frame_base = frame_base; +/* + * Initialization + */ - return true; -} bool VideoInit(bool classic) { - int default_width, default_height, default_depth; + video_depth default_depth = VDEPTH_1BIT; + int default_width, default_height; + int default_display_type = DISPLAY_WINDOW; + int window_width, window_height; // width and height for window display + ULONG screen_mode_id; // mode ID for screen display // Allocate blank mouse pointer data null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR); @@ -341,22 +219,19 @@ bool VideoInit(bool classic) else mode_str = PrefsFindString("screen"); - // Determine type and mode - display_type = DISPLAY_WINDOW; - default_width = window_width = 512; default_height = window_height = 384; if (mode_str) { if (sscanf(mode_str, "win/%d/%d", &window_width, &window_height) == 2) - display_type = DISPLAY_WINDOW; + default_display_type = DISPLAY_WINDOW; else if (sscanf(mode_str, "pip/%d/%d", &window_width, &window_height) == 2 && P96Base) - display_type = DISPLAY_PIP; + default_display_type = DISPLAY_PIP; else if (sscanf(mode_str, "scr/%08lx", &screen_mode_id) == 1 && (CyberGfxBase || P96Base)) { if (P96Base && p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) - display_type = DISPLAY_SCREEN_P96; + default_display_type = DISPLAY_SCREEN_P96; else if (CyberGfxBase && IsCyberModeID(screen_mode_id)) - display_type = DISPLAY_SCREEN_CGFX; + default_display_type = DISPLAY_SCREEN_CGFX; else { ErrorAlert(STR_NO_P96_MODE_ERR); return false; @@ -364,17 +239,19 @@ bool VideoInit(bool classic) } } + D(bug("default_display_type %d, window_width %d, window_height %d\n", default_display_type, window_width, window_height)); + // Construct list of supported modes - switch (display_type) { + switch (default_display_type) { case DISPLAY_WINDOW: default_width = window_width; default_height = window_height; - default_depth = 1; + default_depth = VDEPTH_1BIT; add_modes(window_width, window_height, VDEPTH_1BIT); break; case DISPLAY_PIP: - default_depth = 16; + default_depth = VDEPTH_16BIT; default_width = window_width; default_height = window_height; add_modes(window_width, window_height, VDEPTH_16BIT); @@ -385,7 +262,7 @@ bool VideoInit(bool classic) struct DimensionInfo dimInfo; DisplayInfoHandle handle = FindDisplayInfo(screen_mode_id); - if (NULL == handle) + if (handle == NULL) return false; if (GetDisplayInfoData(handle, (UBYTE *) &dimInfo, sizeof(dimInfo), DTAG_DIMS, 0) <= 0) @@ -393,90 +270,142 @@ bool VideoInit(bool classic) default_width = 1 + dimInfo.Nominal.MaxX - dimInfo.Nominal.MinX; default_height = 1 + dimInfo.Nominal.MaxY - dimInfo.Nominal.MinY; - default_depth = dimInfo.MaxDepth; - for (unsigned d=VDEPTH_8BIT; d<=VDEPTH_32BIT; d++) + switch (dimInfo.MaxDepth) { + case 1: + default_depth = VDEPTH_1BIT; + break; + 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; + } + + for (unsigned d=VDEPTH_8BIT; d<=VDEPTH_32BIT; d++) { ULONG mode_id = find_mode_for_depth(default_width, default_height, bits_from_depth(video_depth(d))); - if (is_valid_modeid(display_type, mode_id)) - { + if (is_valid_modeid(default_display_type, mode_id)) add_modes(default_width, default_height, video_depth(d)); - } - } + } break; } - video_init_depth_list(); +// video_init_depth_list(); #if DEBUG bug("Available video modes:\n"); vector::const_iterator i = VideoModes.begin(), end = VideoModes.end(); while (i != end) { - bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits_from_depth(i->depth)); + bug(" %ld x %ld (ID %02lx), %ld colors\n", i->x, i->y, i->resolution_id, 1 << bits_from_depth(i->depth)); ++i; } #endif - D(bug("VideoInit: def_width=%ld def_height=%ld def_depth=%ld\n", default_width, default_height, default_depth)); + D(bug("VideoInit/%ld: def_width=%ld def_height=%ld def_depth=%ld\n", \ + __LINE__, default_width, default_height, default_depth)); // Find requested default mode and open display if (VideoModes.size() == 1) - return video_open(VideoModes[0]); + { + uint32 default_id ; + + // Create Amiga_monitor_desc for this (the only) display + default_id = VideoModes[0].resolution_id; + D(bug("VideoInit/%ld: default_id=%ld\n", __LINE__, default_id)); + Amiga_monitor_desc *monitor = new Amiga_monitor_desc(VideoModes, default_depth, default_id, default_display_type); + VideoMonitors.push_back(monitor); + + // Open display + return monitor->video_open(); + } else { // Find mode with specified dimensions std::vector::const_iterator i, end = VideoModes.end(); - for (i = VideoModes.begin(); i != end; ++i) - { - D(bug("VideoInit: w=%ld h=%ld d=%ld\n", i->x, i->y, bits_from_depth(i->depth))); - if (i->x == default_width && i->y == default_height && bits_from_depth(i->depth) == default_depth) - return video_open(*i); - } - return video_open(VideoModes[0]); + for (i = VideoModes.begin(); i != end; ++i) { + D(bug("VideoInit/%ld: w=%ld h=%ld d=%ld\n", __LINE__, i->x, i->y, bits_from_depth(i->depth))); + if (i->x == default_width && i->y == default_height && i->depth == default_depth) + { + // Create Amiga_monitor_desc for this (the only) display + uint32 default_id = i->resolution_id; + D(bug("VideoInit/%ld: default_id=%ld\n", __LINE__, default_id)); + Amiga_monitor_desc *monitor = new Amiga_monitor_desc(VideoModes, default_depth, default_id, default_display_type); + VideoMonitors.push_back(monitor); + + // Open display + return monitor->video_open(); + } + } + + // Create Amiga_monitor_desc for this (the only) display + uint32 default_id = VideoModes[0].resolution_id; + D(bug("VideoInit/%ld: default_id=%ld\n", __LINE__, default_id)); + Amiga_monitor_desc *monitor = new Amiga_monitor_desc(VideoModes, default_depth, default_id, default_display_type); + VideoMonitors.push_back(monitor); + + // Open display + return monitor->video_open(); } return true; } -static bool video_open(const video_mode &mode) +bool Amiga_monitor_desc::video_open() { + const video_mode &mode = get_current_mode(); ULONG depth_bits = bits_from_depth(mode.depth); ULONG ID = find_mode_for_depth(mode.x, mode.y, depth_bits); - D(bug("video_open: width=%ld height=%ld depth=%ld ID=%08lx\n", mode.x, mode.y, depth_bits, ID)); + D(bug("video_open/%ld: width=%ld height=%ld depth=%ld ID=%08lx\n", __LINE__, mode.x, mode.y, depth_bits, ID)); - if (INVALID_ID == ID) - { + if (ID == INVALID_ID) { ErrorAlert(STR_NO_VIDEO_MODE_ERR); return false; - } + } - VideoMonitor.mode = mode; +// VideoMonitor.mode = mode; + + D(bug("video_open/%ld: display_type=%ld\n", __LINE__, display_type)); // Open display switch (display_type) { case DISPLAY_WINDOW: - if (!init_window(mode.x, mode.y)) - return false; + drv = new driver_window(*this, mode.x, mode.y); break; case DISPLAY_PIP: - if (!init_pip(mode.x, mode.y)) - return false; + drv = new driver_pip(*this, mode.x, mode.y); break; case DISPLAY_SCREEN_P96: - if (!init_screen_p96(ID)) - return false; + drv = new driver_screen_p96(*this, ID); break; case DISPLAY_SCREEN_CGFX: - if (!init_screen_cgfx(ID)) - return false; + drv = new driver_screen_cgfx(*this, ID); break; } + D(bug("video_open/%ld: drv=%08lx\n", __LINE__, drv)); + + if (drv == NULL) + return false; + + D(bug("video_open/%ld: init_ok=%ld\n", __LINE__, drv->init_ok)); + if (!drv->init_ok) { + delete drv; + drv = NULL; + return false; + } + // Start periodic process periodic_proc = CreateNewProcTags( NP_Entry, (ULONG)periodic_func, @@ -484,6 +413,9 @@ static bool video_open(const video_mode NP_Priority, 0, TAG_END ); + + D(bug("video_open/%ld: periodic_proc=%08lx\n", __LINE__, periodic_proc)); + if (periodic_proc == NULL) { ErrorAlert(STR_NO_MEM_ERR); return false; @@ -493,7 +425,7 @@ static bool video_open(const video_mode } -static void video_close() +void Amiga_monitor_desc::video_close() { // Stop periodic process if (periodic_proc) { @@ -502,65 +434,7 @@ static void video_close() Wait(SIGF_SINGLE); } - switch (display_type) { - - case DISPLAY_WINDOW: - - // Window mode, free bitmap - if (the_bitmap) { - WaitBlit(); - FreeBitMap(the_bitmap); - } - - // Free pens and close window - if (the_win) { - ReleasePen(the_win->WScreen->ViewPort.ColorMap, black_pen); - ReleasePen(the_win->WScreen->ViewPort.ColorMap, white_pen); - - CloseWindow(the_win); - the_win = NULL; - } - break; - - case DISPLAY_PIP: - - // Close PIP - if (the_win) - p96PIP_Close(the_win); - break; - - case DISPLAY_SCREEN_P96: - - // Close window - if (the_win) - { - CloseWindow(the_win); - the_win = NULL; - } - - // Close screen - if (the_screen) { - p96CloseScreen(the_screen); - the_screen = NULL; - } - break; - - case DISPLAY_SCREEN_CGFX: - - // Close window - if (the_win) - { - CloseWindow(the_win); - the_win = NULL; - } - - // Close screen - if (the_screen) { - CloseScreen(the_screen); - the_screen = NULL; - } - break; - } + delete drv; // Free mouse pointer if (null_pointer) { @@ -576,7 +450,10 @@ static void video_close() void VideoExit(void) { - video_close(); + // Close displays + vector::iterator i, end = VideoMonitors.end(); + for (i = VideoMonitors.begin(); i != end; ++i) + dynamic_cast(*i)->video_close(); } @@ -584,24 +461,9 @@ void VideoExit(void) * Set palette */ -void video_set_palette(uint8 *pal, int num) +void Amiga_monitor_desc::set_palette(uint8 *pal, int num) { - if ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) - && !IsDirectMode(VideoMonitor.mode)) { - - // Convert palette to 32 bits - ULONG table[2 + 256 * 3]; - table[0] = num << 16; - table[num * 3 + 1] = 0; - for (int i=0; iViewPort, table); - } + drv->set_palette(pal, num); } @@ -609,15 +471,14 @@ void video_set_palette(uint8 *pal, int n * Switch video mode */ -void video_switch_to_mode(const video_mode &mode) +void Amiga_monitor_desc::switch_to_current_mode() { // Close and reopen display video_close(); - if (!video_open(mode)) - { + if (!video_open()) { ErrorAlert(STR_OPEN_WINDOW_ERR); QuitEmulator(); - } + } } @@ -650,21 +511,26 @@ static __saveds void periodic_func(void) struct IntuiMessage *msg; ULONG win_mask = 0, timer_mask = 0; + D(bug("periodic_func/%ld: \n", __LINE__)); + // Create message port for window and attach it struct MsgPort *win_port = CreateMsgPort(); if (win_port) { win_mask = 1 << win_port->mp_SigBit; - the_win->UserPort = win_port; - ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); + drv->the_win->UserPort = win_port; + ModifyIDCMP(drv->the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | + ((drv->monitor.display_type == DISPLAY_SCREEN_P96 || drv->monitor.display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); } + D(bug("periodic_func/%ld: \n", __LINE__)); + // Start 60Hz timer for window refresh - if (display_type == DISPLAY_WINDOW) { + if (drv->monitor.display_type == DISPLAY_WINDOW) { timer_port = CreateMsgPort(); if (timer_port) { timer_io = (struct timerequest *)CreateIORequest(timer_port, sizeof(struct timerequest)); if (timer_io) { - if (!OpenDevice((UBYTE *)TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timer_io, 0)) { + if (!OpenDevice((UBYTE *) TIMERNAME, UNIT_MICROHZ, (struct IORequest *)timer_io, 0)) { timer_mask = 1 << timer_port->mp_SigBit; timer_io->tr_node.io_Command = TR_ADDREQUEST; timer_io->tr_time.tv_secs = 0; @@ -675,8 +541,11 @@ static __saveds void periodic_func(void) } } + D(bug("periodic_func/%ld: \n", __LINE__)); + // Main loop for (;;) { + const video_mode &mode = drv->monitor.get_current_mode(); // Wait for timer and/or window (CTRL_C is used for quitting the task) ULONG sig = Wait(win_mask | timer_mask | SIGBREAKF_CTRL_C); @@ -684,11 +553,17 @@ static __saveds void periodic_func(void) if (sig & SIGBREAKF_CTRL_C) break; - if (sig & timer_mask) { +// D(bug("periodic_func/%ld: display_type=%ld the_win=%08lx\n", __LINE__, drv->monitor.display_type, drv->the_win)); - // Timer tick, update display - BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, - the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); + if (sig & timer_mask) { + if (drv->get_bitmap()) + { + // Timer tick, update display + BltTemplate(drv->get_bitmap()->Planes[0], 0, + drv->get_bitmap()->BytesPerRow, drv->the_win->RPort, + drv->the_win->BorderLeft, drv->the_win->BorderTop, + mode.x, mode.y); + } // Restart timer timer_io->tr_node.io_Command = TR_ADDREQUEST; @@ -713,26 +588,33 @@ static __saveds void periodic_func(void) // Handle message according to class switch (cl) { case IDCMP_MOUSEMOVE: - if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) + switch (drv->monitor.display_type) + { + case DISPLAY_SCREEN_P96: + case DISPLAY_SCREEN_CGFX: +// D(bug("periodic_func/%ld: IDCMP_MOUSEMOVE mx=%ld my=%ld\n", __LINE__, mx, my)); ADBMouseMoved(mx, my); - else { - ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); - if (mx < the_win->BorderLeft - || my < the_win->BorderTop - || mx >= the_win->BorderLeft + VideoMonitor.mode.x - || my >= the_win->BorderTop + VideoMonitor.mode.y) { + break; + default: +// D(bug("periodic_func/%ld: IDCMP_MOUSEMOVE mx=%ld my=%ld\n", __LINE__, mx - drv->the_win->BorderLeft, my - drv->the_win->BorderTop)); + ADBMouseMoved(mx - drv->the_win->BorderLeft, my - drv->the_win->BorderTop); + if (mx < drv->the_win->BorderLeft + || my < drv->the_win->BorderTop + || mx >= drv->the_win->BorderLeft + mode.x + || my >= drv->the_win->BorderTop + mode.y) { if (current_pointer) { - ClearPointer(the_win); + ClearPointer(drv->the_win); current_pointer = NULL; } } else { if (current_pointer != null_pointer) { // Hide mouse pointer inside window - SetPointer(the_win, null_pointer, 1, 16, 0, 0); + SetPointer(drv->the_win, null_pointer, 1, 16, 0, 0); current_pointer = null_pointer; } } - } + break; + } break; case IDCMP_MOUSEBUTTONS: @@ -770,6 +652,8 @@ static __saveds void periodic_func(void) } } + D(bug("periodic_func/%ld: \n", __LINE__)); + // Stop timer if (timer_io) { if (!CheckIO((struct IORequest *)timer_io)) @@ -786,14 +670,14 @@ static __saveds void periodic_func(void) msg = (struct IntuiMessage *)win_port->mp_MsgList.lh_Head; struct Node *succ; while (succ = msg->ExecMessage.mn_Node.ln_Succ) { - if (msg->IDCMPWindow == the_win) { + if (msg->IDCMPWindow == drv->the_win) { Remove((struct Node *)msg); ReplyMsg((struct Message *)msg); } msg = (struct IntuiMessage *)succ; } - the_win->UserPort = NULL; - ModifyIDCMP(the_win, 0); + drv->the_win->UserPort = NULL; + ModifyIDCMP(drv->the_win, 0); Permit(); DeleteMsgPort(win_port); @@ -818,7 +702,7 @@ static void add_mode(uint32 width, uint3 VideoModes.push_back(mode); } -// Add standard list of windowed modes for given color depth +// Add standard list of modes for given color depth static void add_modes(uint32 width, uint32 height, video_depth depth) { D(bug("add_modes: w=%ld h=%ld d=%ld\n", width, height, depth)); @@ -869,18 +753,17 @@ static bool is_valid_modeid(int display_ if (INVALID_ID == mode_id) return false; - switch (display_type) - { - case DISPLAY_SCREEN_P96: - return check_modeid_p96(mode_id); - break; - case DISPLAY_SCREEN_CGFX: - return check_modeid_cgfx(mode_id); - break; - default: - return false; - break; - } + switch (display_type) { + case DISPLAY_SCREEN_P96: + return check_modeid_p96(mode_id); + break; + case DISPLAY_SCREEN_CGFX: + return check_modeid_cgfx(mode_id); + break; + default: + return false; + break; + } } @@ -890,7 +773,9 @@ static bool check_modeid_p96(ULONG mode_ uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); - if (!p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) + D(bug("check_modeid_p96: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); + + if (!p96GetModeIDAttr(mode_id, P96IDA_ISP96)) return false; switch (depth) { @@ -919,7 +804,7 @@ static bool check_modeid_cgfx(ULONG mode uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); - D(bug("init_screen_cgfx: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); + D(bug("check_modeid_cgfx: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); if (!IsCyberModeID(mode_id)) return false; @@ -929,7 +814,6 @@ static bool check_modeid_cgfx(ULONG mode break; case 15: case 16: - // !!! PIXFMT_RGB15 is correct !!! if (format != PIXFMT_RGB15) return false; break; @@ -945,3 +829,342 @@ static bool check_modeid_cgfx(ULONG mode return true; } + +driver_base::driver_base(Amiga_monitor_desc &m) + : monitor(m), mode(m.get_current_mode()), init_ok(false) +{ +} + +driver_base::~driver_base() +{ +} + + +// Open window +driver_window::driver_window(Amiga_monitor_desc &m, int width, int height) + : black_pen(-1), white_pen(-1), driver_base(m) +{ + // Set relative mouse mode + ADBSetRelMouseMode(false); + + // Open window + the_win = OpenWindowTags(NULL, + WA_Left, 0, WA_Top, 0, + WA_InnerWidth, width, WA_InnerHeight, height, + WA_SimpleRefresh, true, + WA_NoCareRefresh, true, + WA_Activate, true, + WA_RMBTrap, true, + WA_ReportMouse, true, + WA_DragBar, true, + WA_DepthGadget, true, + WA_SizeGadget, false, + WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), + TAG_END + ); + if (the_win == NULL) { + init_ok = false; + ErrorAlert(STR_OPEN_WINDOW_ERR); + return; + } + + // Create bitmap ("height + 2" for safety) + the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL); + if (the_bitmap == NULL) { + init_ok = false; + ErrorAlert(STR_NO_MEM_ERR); + return; + } + + // Add resolution and set VideoMonitor + monitor.set_mac_frame_base((uint32)the_bitmap->Planes[0]); + + // Set FgPen and BgPen + black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); + white_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0xffffffff, 0xffffffff, 0xffffffff, NULL); + SetAPen(the_win->RPort, black_pen); + SetBPen(the_win->RPort, white_pen); + SetDrMd(the_win->RPort, JAM2); + + init_ok = true; +} + + +driver_window::~driver_window() +{ + // Window mode, free bitmap + if (the_bitmap) { + WaitBlit(); + FreeBitMap(the_bitmap); + } + + // Free pens and close window + if (the_win) { + ReleasePen(the_win->WScreen->ViewPort.ColorMap, black_pen); + ReleasePen(the_win->WScreen->ViewPort.ColorMap, white_pen); + + CloseWindow(the_win); + the_win = NULL; + } +} + + +// Open PIP (requires Picasso96) +driver_pip::driver_pip(Amiga_monitor_desc &m, int width, int height) + : driver_base(m) +{ + // Set relative mouse mode + ADBSetRelMouseMode(false); + + // Open window + ULONG error = 0; + the_win = p96PIP_OpenTags( + P96PIP_SourceFormat, RGBFB_R5G5B5, + P96PIP_SourceWidth, width, + P96PIP_SourceHeight, height, + P96PIP_ErrorCode, (ULONG)&error, + WA_Left, 0, WA_Top, 0, + WA_InnerWidth, width, WA_InnerHeight, height, + WA_SimpleRefresh, true, + WA_NoCareRefresh, true, + WA_Activate, true, + WA_RMBTrap, true, + WA_ReportMouse, true, + WA_DragBar, true, + WA_DepthGadget, true, + WA_SizeGadget, false, + WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), + WA_PubScreenName, (ULONG)"Workbench", + TAG_END + ); + if (the_win == NULL || error) { + init_ok = false; + ErrorAlert(STR_OPEN_WINDOW_ERR); + return; + } + + // Find bitmap + p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); + + // Add resolution and set VideoMonitor + monitor.set_mac_frame_base(p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY)); + + init_ok = true; +} + +driver_pip::~driver_pip() +{ + // Close PIP + if (the_win) + p96PIP_Close(the_win); +} + + +// Open Picasso96 screen +driver_screen_p96::driver_screen_p96(Amiga_monitor_desc &m, ULONG mode_id) + : driver_base(m) +{ + // Set absolute mouse mode + ADBSetRelMouseMode(true); + + // Check if the mode is one we can handle + if (!check_modeid_p96(mode_id)) + { + init_ok = false; + ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); + return; + } + + // Yes, get width and height + uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); + uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); + uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); + + // Open screen + the_screen = p96OpenScreenTags( + P96SA_DisplayID, mode_id, + P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), + P96SA_Quiet, true, + P96SA_NoMemory, true, + P96SA_NoSprite, true, + P96SA_Exclusive, true, + TAG_END + ); + if (the_screen == NULL) { + ErrorAlert(STR_OPEN_SCREEN_ERR); + init_ok = false; + return; + } + + // Open window + the_win = OpenWindowTags(NULL, + WA_Left, 0, WA_Top, 0, + WA_Width, width, WA_Height, height, + WA_SimpleRefresh, true, + WA_NoCareRefresh, true, + WA_Borderless, true, + WA_Activate, true, + WA_RMBTrap, true, + WA_ReportMouse, true, + WA_CustomScreen, (ULONG)the_screen, + TAG_END + ); + if (the_win == NULL) { + ErrorAlert(STR_OPEN_WINDOW_ERR); + init_ok = false; + return; + } + + ScreenToFront(the_screen); + + // Add resolution and set VideoMonitor + monitor.set_mac_frame_base(p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY)); + + init_ok = true; +} + + +driver_screen_p96::~driver_screen_p96() +{ + // Close window + if (the_win) + { + CloseWindow(the_win); + the_win = NULL; + } + + // Close screen + if (the_screen) { + p96CloseScreen(the_screen); + the_screen = NULL; + } +} + + +void driver_screen_p96::set_palette(uint8 *pal, int num) +{ + // Convert palette to 32 bits + ULONG table[2 + 256 * 3]; + table[0] = num << 16; + table[num * 3 + 1] = 0; + for (int i=0; iViewPort, table); +} + + +// Open CyberGraphX screen +driver_screen_cgfx::driver_screen_cgfx(Amiga_monitor_desc &m, ULONG mode_id) + : driver_base(m) +{ + D(bug("driver_screen_cgfx/%ld: mode_id=%08lx\n", __LINE__, mode_id)); + + // Set absolute mouse mode + ADBSetRelMouseMode(true); + + // Check if the mode is one we can handle + if (!check_modeid_cgfx(mode_id)) + { + ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); + init_ok = false; + return; + } + + // Yes, get width and height + uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); + uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); + uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); + + // Open screen + the_screen = OpenScreenTags(NULL, + SA_DisplayID, mode_id, + SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), + SA_Quiet, true, + SA_Exclusive, true, + TAG_END + ); + if (the_screen == NULL) { + ErrorAlert(STR_OPEN_SCREEN_ERR); + init_ok = false; + return; + } + + // Open window + the_win = OpenWindowTags(NULL, + WA_Left, 0, WA_Top, 0, + WA_Width, width, WA_Height, height, + WA_SimpleRefresh, true, + WA_NoCareRefresh, true, + WA_Borderless, true, + WA_Activate, true, + WA_RMBTrap, true, + WA_ReportMouse, true, + WA_CustomScreen, (ULONG)the_screen, + TAG_END + ); + if (the_win == NULL) { + ErrorAlert(STR_OPEN_WINDOW_ERR); + init_ok = false; + return; + } + + ScreenToFront(the_screen); + static UWORD ptr[] = { 0, 0, 0, 0 }; + SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer + + // Set VideoMonitor + ULONG frame_base; + APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, + LBMI_BASEADDRESS, (ULONG)&frame_base, + TAG_END + ); + UnLockBitMap(handle); + + D(bug("driver_screen_cgfx/%ld: frame_base=%08lx\n", __LINE__, frame_base)); + + monitor.set_mac_frame_base(frame_base); + + init_ok = true; +} + + +driver_screen_cgfx::~driver_screen_cgfx() +{ + D(bug("~driver_screen_cgfx/%ld: \n", __LINE__)); + + // Close window + if (the_win) + { + CloseWindow(the_win); + the_win = NULL; + } + + // Close screen + if (the_screen) { + CloseScreen(the_screen); + the_screen = NULL; + } +} + + +void driver_screen_cgfx::set_palette(uint8 *pal, int num) +{ + // Convert palette to 32 bits + ULONG table[2 + 256 * 3]; + table[0] = num << 16; + table[num * 3 + 1] = 0; + for (int i=0; iViewPort, table); +} +