--- BasiliskII/src/AmigaOS/video_amiga.cpp 2000/07/13 17:45:33 1.5 +++ BasiliskII/src/AmigaOS/video_amiga.cpp 2001/07/03 19:20:45 1.18 @@ -1,7 +1,7 @@ /* * video_amiga.cpp - Video/graphics emulation, AmigaOS specific stuff * - * Basilisk II (C) 1997-2000 Christian Bauer + * Basilisk II (C) 1997-2001 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,7 +22,7 @@ #include #include #include -#include +#include #include #include #include @@ -33,6 +33,7 @@ #include #include "sysdeps.h" +#include "cpu_emulation.h" #include "main.h" #include "adb.h" #include "prefs.h" @@ -47,7 +48,8 @@ enum { DISPLAY_WINDOW, DISPLAY_PIP, - DISPLAY_SCREEN + DISPLAY_SCREEN_P96, + DISPLAY_SCREEN_CGFX }; // Global variables @@ -56,10 +58,10 @@ 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 -static bool is_cgfx = false; // Flag: screen mode is a CyberGfx mode -static bool is_p96 = false; // Flag: screen mode is a Picasso96 mode extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) @@ -93,6 +95,44 @@ static void periodic_func(void); * 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) +{ + video_mode mode; + + mode.x = width; + mode.y = height; + mode.resolution_id = 0x80; + 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: + case 16: + mode.depth = VDEPTH_16BIT; + break; + case 24: + case 32: + mode.depth = VDEPTH_32BIT; + break; + } + + VideoModes.push_back(mode); + video_init_depth_list(); + VideoMonitor.mode = mode; +} + // Open window static bool init_window(int width, int height) { @@ -115,23 +155,20 @@ static bool init_window(int width, int h TAG_END ); if (the_win == NULL) { - ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); + 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(GetString(STR_NO_MEM_ERR)); + ErrorAlert(STR_NO_MEM_ERR); return false; } - // Set VideoMonitor + // Add resolution and set VideoMonitor + set_video_monitor(width, height, the_bitmap->BytesPerRow, 1); VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0]; - VideoMonitor.bytes_per_row = the_bitmap->BytesPerRow; - VideoMonitor.x = width; - VideoMonitor.y = height; - VideoMonitor.mode = VMODE_1BIT; // Set FgPen and BgPen black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); @@ -170,112 +207,142 @@ static bool init_pip(int width, int heig TAG_END ); if (the_win == NULL || error) { - ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); + ErrorAlert(STR_OPEN_WINDOW_ERR); return false; } // Find bitmap p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); - // Set VideoMonitor + // Add resolution and set VideoMonitor VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); - VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW); - VideoMonitor.x = width; - VideoMonitor.y = height; - VideoMonitor.mode = VMODE_16BIT; + set_video_monitor(width, height, p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW), 16); return true; } -// Open screen (requires Picasso96/CyberGfx 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 whether the mode is a Picasso96 mode or a CyberGfx mode - if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) - is_p96 = true; - else if (CyberGfxBase && IsCyberModeID(mode_id)) - is_cgfx = true; - else { - ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); + // 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: + break; + case 15: + case 16: + if (format != RGBFB_R5G5B5) { + ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); + return false; + } + break; + case 24: + case 32: + if (format != RGBFB_A8R8G8B8) { + ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); + return false; + } + break; + default: + ErrorAlert(STR_WRONG_SCREEN_DEPTH_ERR); + return false; + } + + // Yes, get width and height + 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); + 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(STR_OPEN_WINDOW_ERR); return false; } - uint32 depth; - uint32 format; + ScreenToFront(the_screen); + + // Add resolution and set VideoMonitor + set_video_monitor(width, height, p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW), depth); + VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); + 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 - if (is_p96) { - depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); - format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); - } else { - depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); - format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); - } + 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 != RGBFB_R5G5B5 && format != PIXFMT_RGB16) { - ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); + // !!! PIXFMT_RGB15 is correct !!! + if (format != PIXFMT_RGB15) { + ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); return false; } - VideoMonitor.mode = VMODE_16BIT; break; case 24: case 32: - if (format != RGBFB_A8R8G8B8 && format != PIXFMT_ARGB32) { - ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); + if (format != PIXFMT_ARGB32) { + ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); return false; } - VideoMonitor.mode = VMODE_32BIT; break; default: - ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); + ErrorAlert(STR_WRONG_SCREEN_DEPTH_ERR); return false; } // Yes, get width and height - uint32 width; - uint32 height; - - if (is_p96) { - width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); - height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); - } else { - width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); - height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); - } - VideoMonitor.x = width; - VideoMonitor.y = height; + uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); + uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); // Open screen - if (is_p96) { - 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 - ); - } else { - the_screen = OpenScreenTags(NULL, - SA_DisplayID, mode_id, - SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), - SA_Quiet, TRUE, - SA_Exclusive, TRUE, - TAG_END - ); - } - + 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)); + ErrorAlert(STR_OPEN_SCREEN_ERR); return false; } @@ -292,30 +359,35 @@ static bool init_screen(ULONG mode_id) TAG_END ); if (the_win == NULL) { - ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); + ErrorAlert(STR_OPEN_WINDOW_ERR); return false; } - // Set VideoMonitor ScreenToFront(the_screen); - if (is_p96) { - VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); - VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); - } else { - static UWORD ptr[] = { 0, 0, 0, 0 }; - SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide 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); - } + 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); + set_video_monitor(width, height, GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD), depth); + VideoMonitor.mac_frame_base = frame_base; 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(STR_NO_MEM_ERR); + return false; + } + // Read frame skip prefs frame_skip = PrefsFindInt32("frameskip"); if (frame_skip == 0) @@ -337,8 +409,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 && (CyberGfxBase || 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(STR_NO_P96_MODE_ERR); + return false; + } + } } // Open display @@ -353,8 +433,13 @@ 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; } @@ -367,7 +452,7 @@ bool VideoInit(bool classic) TAG_END ); if (periodic_proc == NULL) { - ErrorAlert(GetString(STR_NO_MEM_ERR)); + ErrorAlert(STR_NO_MEM_ERR); return false; } return true; @@ -413,7 +498,7 @@ void VideoExit(void) p96PIP_Close(the_win); break; - case DISPLAY_SCREEN: + case DISPLAY_SCREEN_P96: // Close window if (the_win) @@ -421,15 +506,30 @@ void VideoExit(void) // Close screen if (the_screen) { - if (is_p96) - p96CloseScreen(the_screen); - else - CloseScreen(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; + } } @@ -437,15 +537,16 @@ void VideoExit(void) * Set palette */ -void video_set_palette(uint8 *pal) +void video_set_palette(uint8 *pal, in num) { - if (display_type == DISPLAY_SCREEN) { + 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] = 256 << 16; - table[256 * 3 + 1] = 0; - for (int i=0; i<256; i++) { + table[0] = num << 16; + table[num * 3 + 1] = 0; + for (int i=0; imp_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 @@ -515,7 +625,7 @@ static __saveds void periodic_func(void) // Timer tick, update display BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, - the_win->BorderLeft, the_win->BorderTop, VideoMonitor.x, VideoMonitor.y); + the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); // Restart timer timer_io->tr_node.io_Command = TR_ADDREQUEST; @@ -540,10 +650,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.mode.x + || my >= the_win->BorderTop + VideoMonitor.mode.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: @@ -564,6 +690,13 @@ static __saveds void periodic_func(void) case IDCMP_RAWKEY: if (qualifier & IEQUALIFIER_REPEAT) // Keyboard repeat is done by MacOS break; + if ((qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) == + (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL) && code == 0x5f) { + SetInterruptFlag(INTFLAG_NMI); + TriggerInterrupt(); + break; + } + if (code & IECODE_UP_PREFIX) ADBKeyUp(keycode2mac[code & 0x7f]); else