--- BasiliskII/src/AmigaOS/video_amiga.cpp 1999/10/03 14:16:25 1.1.1.1 +++ BasiliskII/src/AmigaOS/video_amiga.cpp 2000/07/22 18:25:48 1.8 @@ -1,7 +1,7 @@ /* * video_amiga.cpp - Video/graphics emulation, AmigaOS specific stuff * - * Basilisk II (C) 1997-1999 Christian Bauer + * Basilisk II (C) 1997-2000 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 @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include #include +#include #include "sysdeps.h" #include "main.h" @@ -37,7 +39,7 @@ #include "user_strings.h" #include "video.h" -#define DEBUG 1 +#define DEBUG 0 #include "debug.h" @@ -45,7 +47,8 @@ enum { DISPLAY_WINDOW, DISPLAY_PIP, - DISPLAY_SCREEN + DISPLAY_SCREEN_P96, + DISPLAY_SCREEN_CGFX }; // Global variables @@ -54,6 +57,8 @@ static int display_type = DISPLAY_WINDOW 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 @@ -107,7 +112,7 @@ static bool init_window(int width, int h WA_DragBar, TRUE, WA_DepthGadget, TRUE, WA_SizeGadget, FALSE, - WA_Title, GetString(STR_WINDOW_TITLE), + WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), TAG_END ); if (the_win == NULL) { @@ -150,7 +155,7 @@ static bool init_pip(int width, int heig P96PIP_SourceFormat, RGBFB_R5G5B5, P96PIP_SourceWidth, width, P96PIP_SourceHeight, height, - P96PIP_ErrorCode, &error, + P96PIP_ErrorCode, (ULONG)&error, WA_Left, 0, WA_Top, 0, WA_InnerWidth, width, WA_InnerHeight, height, WA_SimpleRefresh, TRUE, @@ -161,8 +166,8 @@ static bool init_pip(int width, int heig WA_DragBar, TRUE, WA_DepthGadget, TRUE, WA_SizeGadget, FALSE, - WA_Title, GetString(STR_WINDOW_TITLE), - WA_PubScreenName, "Workbench", + WA_Title, (ULONG)GetString(STR_WINDOW_TITLE), + WA_PubScreenName, (ULONG)"Workbench", TAG_END ); if (the_win == NULL || error) { @@ -171,7 +176,7 @@ static bool init_pip(int width, int heig } // Find bitmap - p96PIP_GetTags(the_win, P96PIP_SourceBitMap, &the_bitmap, TAG_END); + p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); // Set VideoMonitor VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); @@ -182,21 +187,16 @@ static bool init_pip(int width, int heig return true; } -// Open screen (requires Picasso96 as we need chunky modes) -static bool init_screen(ULONG mode_id) +// Open Picasso96 screen +static bool init_screen_p96(ULONG mode_id) { // Set relative mouse mode ADBSetRelMouseMode(true); - // Check if the mode is a Picasso96 mode - if (!p96GetModeIDAttr(mode_id, P96IDA_ISP96)) { - ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); - return false; - } - // Check if the mode is one we can handle uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); + switch (depth) { case 8: VideoMonitor.mode = VMODE_8BIT; @@ -225,13 +225,14 @@ static bool init_screen(ULONG mode_id) // Yes, get width and height uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); + VideoMonitor.x = width; VideoMonitor.y = height; // Open screen the_screen = p96OpenScreenTags( P96SA_DisplayID, mode_id, - P96SA_Title, GetString(STR_WINDOW_TITLE), + P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), P96SA_Quiet, TRUE, P96SA_NoMemory, TRUE, P96SA_NoSprite, TRUE, @@ -252,7 +253,7 @@ static bool init_screen(ULONG mode_id) WA_Activate, TRUE, WA_RMBTrap, TRUE, WA_ReportMouse, TRUE, - WA_CustomScreen, the_screen, + WA_CustomScreen, (ULONG)the_screen, TAG_END ); if (the_win == NULL) { @@ -267,8 +268,99 @@ static bool init_screen(ULONG mode_id) return true; } +// Open CyberGraphX screen +static bool init_screen_cgfx(ULONG mode_id) +{ + // Set relative mouse mode + ADBSetRelMouseMode(true); + + // Check if the mode is one we can handle + uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); + uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); + + switch (depth) { + case 8: + VideoMonitor.mode = VMODE_8BIT; + break; + case 15: + case 16: + if (format != PIXFMT_RGB16) { + ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); + return false; + } + VideoMonitor.mode = VMODE_16BIT; + break; + case 24: + case 32: + if (format != PIXFMT_ARGB32) { + ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); + return false; + } + VideoMonitor.mode = VMODE_32BIT; + break; + default: + ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); + return false; + } + + // Yes, get width and height + uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); + uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); + + VideoMonitor.x = width; + VideoMonitor.y = height; + + // 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(GetString(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_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(GetString(STR_OPEN_WINDOW_ERR)); + return false; + } + + // Set VideoMonitor + ScreenToFront(the_screen); + static UWORD ptr[] = { 0, 0, 0, 0 }; + SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer + APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, + LBMI_BASEADDRESS, (ULONG)&VideoMonitor.mac_frame_base, + TAG_END); + UnLockBitMap(handle); + VideoMonitor.bytes_per_row = GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD); + return true; +} + bool VideoInit(bool classic) { + // Allocate blank mouse pointer data + null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR); + if (null_pointer == NULL) { + ErrorAlert(GetString(STR_NO_MEM_ERR)); + return false; + } + // Read frame skip prefs frame_skip = PrefsFindInt32("frameskip"); if (frame_skip == 0) @@ -290,8 +382,16 @@ bool VideoInit(bool classic) display_type = DISPLAY_WINDOW; else if (sscanf(mode_str, "pip/%d/%d", &width, &height) == 2 && P96Base) display_type = DISPLAY_PIP; - else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && P96Base) - display_type = DISPLAY_SCREEN; + else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && (CyberGfxBase || P96Base)) { + if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) + display_type = DISPLAY_SCREEN_P96; + else if (CyberGfxBase && IsCyberModeID(mode_id)) + display_type = DISPLAY_SCREEN_CGFX; + else { + ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); + return false; + } + } } // Open display @@ -306,16 +406,21 @@ bool VideoInit(bool classic) return false; break; - case DISPLAY_SCREEN: - if (!init_screen(mode_id)) + case DISPLAY_SCREEN_P96: + if (!init_screen_p96(mode_id)) + return false; + break; + + case DISPLAY_SCREEN_CGFX: + if (!init_screen_cgfx(mode_id)) return false; break; } // Start periodic process periodic_proc = CreateNewProcTags( - NP_Entry, periodic_func, - NP_Name, "Basilisk II IDCMP Handler", + NP_Entry, (ULONG)periodic_func, + NP_Name, (ULONG)"Basilisk II IDCMP Handler", NP_Priority, 0, TAG_END ); @@ -366,16 +471,37 @@ void VideoExit(void) p96PIP_Close(the_win); break; - case DISPLAY_SCREEN: + case DISPLAY_SCREEN_P96: // Close window if (the_win) CloseWindow(the_win); // Close screen - if (the_screen) + if (the_screen) { p96CloseScreen(the_screen); + the_screen = NULL; + } break; + + case DISPLAY_SCREEN_CGFX: + + // Close window + if (the_win) + CloseWindow(the_win); + + // Close screen + if (the_screen) { + CloseScreen(the_screen); + the_screen = NULL; + } + break; + } + + // Free mouse pointer + if (null_pointer) { + FreeMem(null_pointer, 12); + null_pointer = NULL; } } @@ -386,7 +512,7 @@ void VideoExit(void) void video_set_palette(uint8 *pal) { - if (display_type == DISPLAY_SCREEN) { + if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) { // Convert palette to 32 bits ULONG table[2 + 256 * 3]; @@ -429,7 +555,7 @@ static __saveds void periodic_func(void) 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 ? IDCMP_DELTAMOVE : 0)); + ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); } // Start 60Hz timer for window refresh @@ -487,10 +613,26 @@ static __saveds void periodic_func(void) // Handle message according to class switch (cl) { case IDCMP_MOUSEMOVE: - if (display_type == DISPLAY_SCREEN) + if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ADBMouseMoved(mx, my); - else + else { ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); + if (mx < the_win->BorderLeft + || my < the_win->BorderTop + || mx >= the_win->BorderLeft + VideoMonitor.x + || my >= the_win->BorderTop + VideoMonitor.y) { + if (current_pointer) { + ClearPointer(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); + current_pointer = null_pointer; + } + } + } break; case IDCMP_MOUSEBUTTONS: