--- BasiliskII/src/video.cpp 2001/07/01 21:09:26 1.19 +++ BasiliskII/src/video.cpp 2002/01/15 14:58:32 1.24 @@ -1,8 +1,8 @@ /* * video.cpp - Video/graphics emulation * - * Basilisk II (C) 1997-2001 Christian Bauer - * Portions (C) 1997-1999 Marc Hellwig + * Basilisk II (C) 1997-2002 Christian Bauer + * Portions written by Marc Hellwig * * 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 @@ -23,6 +23,8 @@ * SEE ALSO * Inside Macintosh: Devices, chapter 1 "Device Manager" * Designing Cards and Drivers for the Macintosh Family, Second Edition + * Designing PCI Cards and Drivers for Power Macintosh Computers + * Display Device Driver Guide */ #include @@ -45,12 +47,16 @@ vector VideoModes; // Description of the main monitor monitor_desc VideoMonitor; +// Depth code -> Apple mode mapping +uint16 apple_mode_for_depth[6]; + // Local variables (per monitor) struct { monitor_desc *desc; // Pointer to description of monitor handled by this instance of the driver uint8 palette[256 * 3]; // Color palette, 256 entries, RGB bool luminance_mapping; // Luminance mapping on/off bool interrupts_enabled; // VBL interrupts on/off + bool dm_present; // We received a GetVideoParameters call, so the Display Manager seems to be present uint32 gamma_table; // Mac address of gamma table int alloc_gamma_table_size; // Allocated size of gamma table uint16 current_mode; // Currently selected depth/resolution @@ -62,6 +68,38 @@ struct { /* + * Initialize apple_mode_for_depth[] array from VideoModes list + */ + +void video_init_depth_list(void) +{ + uint16 mode = 0x80; + for (int depth = VDEPTH_1BIT; depth <= VDEPTH_32BIT; depth++) { + if (video_has_depth(video_depth(depth))) + apple_mode_for_depth[depth] = mode++; + else + apple_mode_for_depth[depth] = 0; + } +} + + +/* + * Check whether a mode with the specified depth exists + */ + +bool video_has_depth(video_depth depth) +{ + vector::const_iterator i = VideoModes.begin(), end = VideoModes.end(); + while (i != end) { + if (i->depth == depth) + return true; + ++i; + } + return false; +} + + +/* * Check whether specified resolution ID is one of the supported resolutions */ @@ -121,6 +159,24 @@ static void get_size_of_resolution(uint3 return; } } + x = y = 0; +} + + +/* + * Get bytes-per-row value for specified resolution/depth + */ + +uint32 video_bytes_per_row(video_depth depth, uint32 id) +{ + vector::const_iterator i, end = VideoModes.end(); + for (i = VideoModes.begin(); i != end; ++i) { + if (i->depth == depth && i->resolution_id == id) + return i->bytes_per_row; + } + uint32 x, y; + get_size_of_resolution(id, x, y); + return TrivialBytesPerRow(x, depth); } @@ -164,7 +220,7 @@ static void set_gray_palette(void) static void load_ramp_palette(void) { // Find tables for gamma correction - uint8 *red_gamma, *green_gamma, *blue_gamma; + uint8 *red_gamma = NULL, *green_gamma = NULL, *blue_gamma = NULL; bool have_gamma = false; int data_width = 0; if (VidLocal.gamma_table) { @@ -279,7 +335,7 @@ static bool set_gamma_table(uint32 user_ Mac2Mac_memcpy(table, user_table, size); } - if (IsDirectMode(VidLocal.current_mode)) + if (IsDirectMode(VidLocal.desc->mode)) load_ramp_palette(); return true; @@ -351,6 +407,17 @@ static void switch_mode(const video_mode // Update frame buffer base in DCE and param block WriteMacInt32(dce + dCtlDevBase, frame_base); WriteMacInt32(param + csBaseAddr, frame_base); + + // Patch frame buffer base address for MacOS versions <7.6 + if (!VidLocal.dm_present) { // Only do this when no Display Manager seems to be present; otherwise, the screen will not get redrawn + WriteMacInt32(0x824, frame_base); // ScrnBase + WriteMacInt32(0x898, frame_base); // CrsrBase + uint32 gdev = ReadMacInt32(0x8a4); // MainDevice + gdev = ReadMacInt32(gdev); + uint32 pmap = ReadMacInt32(gdev + 0x16); // gdPMap + pmap = ReadMacInt32(pmap); + WriteMacInt32(pmap, frame_base); // baseAddr + } } @@ -374,6 +441,7 @@ int16 VideoDriverOpen(uint32 pb, uint32 VidLocal.current_id = VidLocal.desc->mode.resolution_id; VidLocal.preferred_mode = VidLocal.current_mode; VidLocal.preferred_id = VidLocal.current_id; + VidLocal.dm_present = false; // Allocate Slot Manager parameter block in Mac RAM M68kRegisters r; @@ -429,7 +497,7 @@ int16 VideoDriverControl(uint32 pb, uint case cscSetEntries: // Set palette case cscDirectSetEntries: { D(bug(" (Direct)SetEntries table %08x, count %d, start %d\n", ReadMacInt32(param + csTable), ReadMacInt16(param + csCount), ReadMacInt16(param + csStart))); - bool is_direct = IsDirectMode(VidLocal.current_mode); + bool is_direct = IsDirectMode(VidLocal.desc->mode); if (code == cscSetEntries && is_direct) return controlErr; if (code == cscDirectSetEntries && !is_direct) @@ -443,7 +511,7 @@ int16 VideoDriverControl(uint32 pb, uint return paramErr; // Find tables for gamma correction - uint8 *red_gamma, *green_gamma, *blue_gamma; + uint8 *red_gamma = NULL, *green_gamma = NULL, *blue_gamma = NULL; bool have_gamma = false; int data_width = 0; if (VidLocal.gamma_table) { @@ -524,20 +592,20 @@ int16 VideoDriverControl(uint32 pb, uint 0xffff0000, // 16 bpp 0xffffffff // 32 bpp }; - uint32 p = VidLocal.desc->mac_frame_base; + uint32 frame_base = VidLocal.desc->mac_frame_base; uint32 pat = pattern[VidLocal.desc->mode.depth]; bool invert = (VidLocal.desc->mode.depth == VDEPTH_32BIT); for (uint32 y=0; ymode.y; y++) { for (uint32 x=0; xmode.bytes_per_row; x+=4) { - WriteMacInt32(p + x, pat); + WriteMacInt32(frame_base + x, pat); if (invert) pat = ~pat; } - p += VidLocal.desc->mode.bytes_per_row; + frame_base += VidLocal.desc->mode.bytes_per_row; pat = ~pat; } - if (IsDirectMode(VidLocal.current_mode)) + if (IsDirectMode(VidLocal.desc->mode)) load_ramp_palette(); return noErr; @@ -554,8 +622,8 @@ int16 VideoDriverControl(uint32 pb, uint return noErr; case cscSetDefaultMode: { // Set default color depth - uint16 mode = ReadMacInt16(param + csMode); - D(bug(" SetDefaultMode %04x\n", mode)); + uint16 mode = ReadMacInt8(param + csMode); + D(bug(" SetDefaultMode %02x\n", mode)); VidLocal.preferred_mode = mode; return noErr; } @@ -668,12 +736,12 @@ int16 VideoDriverStatus(uint32 pb, uint3 case cscGetGray: // Get luminance mapping flag D(bug(" GetGray -> %d\n", VidLocal.luminance_mapping)); - WriteMacInt16(param, VidLocal.luminance_mapping ? 0x0100 : 0); + WriteMacInt8(param, VidLocal.luminance_mapping ? 1 : 0); return noErr; case cscGetInterrupt: // Get interrupt disable flag D(bug(" GetInterrupt -> %d\n", VidLocal.interrupts_enabled)); - WriteMacInt16(param, VidLocal.interrupts_enabled ? 0 : 0x0100); + WriteMacInt8(param, VidLocal.interrupts_enabled ? 0 : 1); return noErr; case cscGetGamma: @@ -682,8 +750,8 @@ int16 VideoDriverStatus(uint32 pb, uint3 return noErr; case cscGetDefaultMode: // Get default color depth - D(bug(" GetDefaultMode -> %04x\n", VidLocal.preferred_mode)); - WriteMacInt16(param + csMode, VidLocal.preferred_mode); + D(bug(" GetDefaultMode -> %02x\n", VidLocal.preferred_mode)); + WriteMacInt8(param + csMode, VidLocal.preferred_mode); return noErr; case cscGetCurrentMode: // Get current video mode (depth and resolution) @@ -767,6 +835,7 @@ int16 VideoDriverStatus(uint32 pb, uint3 WriteMacInt32(param + csVerticalLines, y); WriteMacInt32(param + csRefreshRate, 75 << 16); WriteMacInt16(param + csMaxDepthMode, DepthToAppleMode(max_depth_of_resolution(id))); + WriteMacInt32(param + csResolutionFlags, 0); return noErr; } @@ -774,6 +843,7 @@ int16 VideoDriverStatus(uint32 pb, uint3 uint32 id = ReadMacInt32(param + csDisplayModeID); uint16 mode = ReadMacInt16(param + csDepthMode); D(bug(" GetVideoParameters %04x/%08x\n", mode, id)); + VidLocal.dm_present = true; // Display Manager seems to be present vector::const_iterator i, end = VideoModes.end(); for (i = VideoModes.begin(); i != end; ++i) { @@ -792,26 +862,6 @@ int16 VideoDriverStatus(uint32 pb, uint3 WriteMacInt32(vp + vpVRes, 0x00480000); uint32 pix_type, pix_size, cmp_count, cmp_size, dev_type; switch (i->depth) { - case VDEPTH_1BIT: - pix_type = 0; pix_size = 1; - cmp_count = 1; cmp_size = 1; - dev_type = 0; // CLUT - break; - case VDEPTH_2BIT: - pix_type = 0; pix_size = 2; - cmp_count = 1; cmp_size = 2; - dev_type = 0; // CLUT - break; - case VDEPTH_4BIT: - pix_type = 0; pix_size = 4; - cmp_count = 1; cmp_size = 4; - dev_type = 0; // CLUT - break; - case VDEPTH_8BIT: - pix_type = 0; pix_size = 8; - cmp_count = 1; cmp_size = 8; - dev_type = 0; // CLUT - break; case VDEPTH_16BIT: pix_type = 0x10; pix_size = 16; cmp_count = 3; cmp_size = 5; @@ -822,6 +872,11 @@ int16 VideoDriverStatus(uint32 pb, uint3 cmp_count = 3; cmp_size = 8; dev_type = 2; // direct break; + default: + pix_type = 0; pix_size = 1 << i->depth; + cmp_count = 1; cmp_size = 1 << i->depth; + dev_type = 0; // CLUT + break; } WriteMacInt16(vp + vpPixelType, pix_type); WriteMacInt16(vp + vpPixelSize, pix_size); @@ -835,6 +890,23 @@ int16 VideoDriverStatus(uint32 pb, uint3 return paramErr; // specified resolution/depth not supported } + case cscGetMultiConnect: { + uint32 conn = ReadMacInt32(param + csDisplayCountOrNumber); + D(bug(" GetMultiConnect %08x\n", conn)); + if (conn == 0xffffffff) { // Get number of connections + WriteMacInt32(param + csDisplayCountOrNumber, 1); // Single-headed + return noErr; + } else if (conn == 1) { // Get information about first connection + WriteMacInt16(param + csConnectInfo + csDisplayType, 8); // Modeless connection + WriteMacInt8(param + csConnectInfo + csConnectTaggedType, 0); + WriteMacInt8(param + csConnectInfo + csConnectTaggedData, 0); + WriteMacInt32(param + csConnectInfo + csConnectFlags, 0x43); // All modes valid and safe, non-standard tagging + WriteMacInt32(param + csConnectInfo + csDisplayComponent, 0); + return noErr; + } else + return paramErr; + } + default: printf("WARNING: Unknown VideoDriverStatus(%d)\n", code); return statusErr;