1 |
|
/* |
2 |
|
* video_x.cpp - Video/graphics emulation, X11 specific stuff |
3 |
|
* |
4 |
< |
* SheepShaver (C) 1997-2004 Marc Hellwig and Christian Bauer |
4 |
> |
* SheepShaver (C) 1997-2005 Marc Hellwig and Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
503 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
504 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
505 |
|
#endif |
506 |
< |
screen_base = (uint32)the_buffer; |
506 |
> |
screen_base = Host2MacAddr(the_buffer); |
507 |
|
|
508 |
|
// Create GC |
509 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
633 |
|
|
634 |
|
// Set frame buffer base |
635 |
|
D(bug("the_buffer = %p, use_vosf = %d\n", the_buffer, use_vosf)); |
636 |
< |
screen_base = (uint32)the_buffer; |
636 |
> |
screen_base = Host2MacAddr(the_buffer); |
637 |
|
VModes[cur_mode].viRowBytes = bytes_per_row; |
638 |
|
return true; |
639 |
|
#else |
892 |
|
|
893 |
|
// Search for server vendor string, then read keycodes |
894 |
|
const char *vendor = ServerVendor(x_display); |
895 |
– |
#if (defined(__APPLE__) && defined(__MACH__)) |
895 |
|
// Force use of MacX mappings on MacOS X with Apple's X server |
896 |
|
int dummy; |
897 |
|
if (XQueryExtension(x_display, "Apple-DRI", &dummy, &dummy, &dummy)) |
898 |
|
vendor = "MacX"; |
900 |
– |
#endif |
899 |
|
bool vendor_found = false; |
900 |
|
char line[256]; |
901 |
|
while (fgets(line, 255, f)) { |
970 |
|
return -1; |
971 |
|
} |
972 |
|
|
973 |
+ |
// Add custom video mode |
974 |
+ |
static void add_custom_mode(VideoInfo *&p, int type, uint32 x, uint32 y, int apple_mode, int apple_id) |
975 |
+ |
{ |
976 |
+ |
p->viType = type; |
977 |
+ |
p->viXsize = x; |
978 |
+ |
p->viYsize = y; |
979 |
+ |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
980 |
+ |
p->viAppleMode = apple_mode; |
981 |
+ |
p->viAppleID = apple_id; |
982 |
+ |
p++; |
983 |
+ |
} |
984 |
+ |
|
985 |
|
// Add mode to list of supported modes |
986 |
|
static void add_mode(VideoInfo *&p, uint32 allow, uint32 test, int apple_mode, int apple_id, int type) |
987 |
|
{ |
988 |
|
if (allow & test) { |
989 |
< |
p->viType = type; |
989 |
> |
uint32 x = 0, y = 0; |
990 |
|
switch (apple_id) { |
991 |
|
case APPLE_W_640x480: |
992 |
|
case APPLE_640x480: |
993 |
< |
p->viXsize = 640; |
994 |
< |
p->viYsize = 480; |
993 |
> |
x = 640; |
994 |
> |
y = 480; |
995 |
|
break; |
996 |
|
case APPLE_W_800x600: |
997 |
|
case APPLE_800x600: |
998 |
< |
p->viXsize = 800; |
999 |
< |
p->viYsize = 600; |
998 |
> |
x = 800; |
999 |
> |
y = 600; |
1000 |
|
break; |
1001 |
|
case APPLE_1024x768: |
1002 |
< |
p->viXsize = 1024; |
1003 |
< |
p->viYsize = 768; |
1002 |
> |
x = 1024; |
1003 |
> |
y = 768; |
1004 |
|
break; |
1005 |
|
case APPLE_1152x768: |
1006 |
< |
p->viXsize = 1152; |
1007 |
< |
p->viYsize = 768; |
1006 |
> |
x = 1152; |
1007 |
> |
y = 768; |
1008 |
|
break; |
1009 |
|
case APPLE_1152x900: |
1010 |
< |
p->viXsize = 1152; |
1011 |
< |
p->viYsize = 900; |
1010 |
> |
x = 1152; |
1011 |
> |
y = 900; |
1012 |
|
break; |
1013 |
|
case APPLE_1280x1024: |
1014 |
< |
p->viXsize = 1280; |
1015 |
< |
p->viYsize = 1024; |
1014 |
> |
x = 1280; |
1015 |
> |
y = 1024; |
1016 |
|
break; |
1017 |
|
case APPLE_1600x1200: |
1018 |
< |
p->viXsize = 1600; |
1019 |
< |
p->viYsize = 1200; |
1018 |
> |
x = 1600; |
1019 |
> |
y = 1200; |
1020 |
|
break; |
1021 |
|
} |
1022 |
< |
p->viRowBytes = TrivialBytesPerRow(p->viXsize, apple_mode); |
1013 |
< |
p->viAppleMode = apple_mode; |
1014 |
< |
p->viAppleID = apple_id; |
1015 |
< |
p++; |
1022 |
> |
add_custom_mode(p, type, x, y, apple_mode, apple_id); |
1023 |
|
} |
1024 |
|
} |
1025 |
|
|
1129 |
|
break; |
1130 |
|
} |
1131 |
|
|
1132 |
+ |
// Get screen mode from preferences |
1133 |
+ |
const char *mode_str = PrefsFindString("screen"); |
1134 |
+ |
int default_width = 640, default_height = 480; |
1135 |
+ |
if (mode_str) { |
1136 |
+ |
display_type = DIS_INVALID; |
1137 |
+ |
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
1138 |
+ |
display_type = DIS_WINDOW; |
1139 |
+ |
#ifdef ENABLE_XF86_DGA |
1140 |
+ |
else if (has_dga && sscanf(mode_str, "dga/%d/%d", &default_width, &default_height) == 2) |
1141 |
+ |
display_type = DIS_SCREEN; |
1142 |
+ |
#endif |
1143 |
+ |
if (display_type == DIS_INVALID) { |
1144 |
+ |
D(bug("Invalid screen mode specified, defaulting to old modes selection\n")); |
1145 |
+ |
mode_str = NULL; |
1146 |
+ |
} |
1147 |
+ |
else { |
1148 |
+ |
if (default_width <= 0) |
1149 |
+ |
default_width = DisplayWidth(x_display, screen); |
1150 |
+ |
else if (default_width > DisplayWidth(x_display, screen)) |
1151 |
+ |
default_width = DisplayWidth(x_display, screen); |
1152 |
+ |
if (default_height <= 0) |
1153 |
+ |
default_height = DisplayHeight(x_display, screen); |
1154 |
+ |
else if (default_height > DisplayHeight(x_display, screen)) |
1155 |
+ |
default_height = DisplayHeight(x_display, screen); |
1156 |
+ |
} |
1157 |
+ |
} |
1158 |
+ |
|
1159 |
|
// Construct video mode table |
1160 |
|
uint32 window_modes = PrefsFindInt32("windowmodes"); |
1161 |
|
uint32 screen_modes = PrefsFindInt32("screenmodes"); |
1162 |
|
if (!has_dga) |
1163 |
|
screen_modes = 0; |
1164 |
< |
if (window_modes == 0 && screen_modes == 0) |
1164 |
> |
if (mode_str) |
1165 |
> |
window_modes = screen_modes = 0; |
1166 |
> |
else if (window_modes == 0 && screen_modes == 0) |
1167 |
|
window_modes |= 3; // Allow at least 640x480 and 800x600 window modes |
1168 |
|
|
1169 |
|
VideoInfo *p = VModes; |
1170 |
< |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1171 |
< |
if (find_visual_for_depth(d)) |
1172 |
< |
add_window_modes(p, window_modes, d); |
1173 |
< |
|
1174 |
< |
if (has_vidmode) { |
1170 |
> |
if (mode_str) { |
1171 |
> |
if (display_type == DIS_WINDOW) { |
1172 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) { |
1173 |
> |
if (find_visual_for_depth(d)) { |
1174 |
> |
if (default_width > 640 && default_height > 480) |
1175 |
> |
add_mode(p, 3, 1, d, APPLE_W_640x480, DIS_WINDOW); |
1176 |
> |
if (default_width > 800 && default_height > 600) |
1177 |
> |
add_mode(p, 3, 2, d, APPLE_W_800x600, DIS_WINDOW); |
1178 |
> |
add_custom_mode(p, display_type, default_width, default_height, d, APPLE_CUSTOM); |
1179 |
> |
} |
1180 |
> |
} |
1181 |
> |
} else |
1182 |
> |
add_custom_mode(p, display_type, default_width, default_height, default_mode, APPLE_CUSTOM); |
1183 |
> |
} else if (window_modes) { |
1184 |
> |
for (unsigned int d = APPLE_1_BIT; d <= APPLE_32_BIT; d++) |
1185 |
> |
if (find_visual_for_depth(d)) |
1186 |
> |
add_window_modes(p, window_modes, d); |
1187 |
> |
} else if (has_vidmode) { |
1188 |
|
if (has_mode(640, 480)) |
1189 |
|
add_mode(p, screen_modes, 1, default_mode, APPLE_640x480, DIS_SCREEN); |
1190 |
|
if (has_mode(800, 600)) |
1225 |
|
int apple_id = find_apple_resolution(screen_width, screen_height); |
1226 |
|
if (apple_id != -1) |
1227 |
|
cur_mode = find_mode(default_mode, apple_id, DIS_SCREEN); |
1228 |
< |
} |
1228 |
> |
} else if (has_dga && mode_str) |
1229 |
> |
cur_mode = find_mode(default_mode, APPLE_CUSTOM, DIS_SCREEN); |
1230 |
> |
|
1231 |
|
if (cur_mode == -1) { |
1232 |
|
// pick up first windowed mode available |
1233 |
|
for (VideoInfo *p = VModes; p->viType != DIS_INVALID; p++) { |
1318 |
|
// Save frame buffer |
1319 |
|
fb_save = malloc(VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1320 |
|
if (fb_save) |
1321 |
< |
memcpy(fb_save, (void *)screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1321 |
> |
Mac2Host_memcpy(fb_save, screen_base, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1322 |
|
|
1323 |
|
// Close full screen display |
1324 |
|
#ifdef ENABLE_XF86_DGA |
1380 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1381 |
|
if (!use_vosf) |
1382 |
|
#endif |
1383 |
< |
memcpy((void *)screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1383 |
> |
Host2Mac_memcpy(screen_base, fb_save, VModes[cur_mode].viYsize * VModes[cur_mode].viRowBytes); |
1384 |
|
free(fb_save); |
1385 |
|
fb_save = NULL; |
1386 |
|
} |
1711 |
|
} |
1712 |
|
|
1713 |
|
|
1663 |
– |
/* |
1664 |
– |
* Install graphics acceleration |
1665 |
– |
*/ |
1666 |
– |
|
1667 |
– |
// Rectangle inversion |
1668 |
– |
template< int bpp > |
1669 |
– |
static inline void do_invrect(uint8 *dest, uint32 length) |
1670 |
– |
{ |
1671 |
– |
#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] |
1672 |
– |
#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] |
1673 |
– |
#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] |
1674 |
– |
#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] |
1675 |
– |
|
1676 |
– |
#ifndef UNALIGNED_PROFITABLE |
1677 |
– |
// Align on 16-bit boundaries |
1678 |
– |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1679 |
– |
INVERT_1(dest, 0); |
1680 |
– |
dest += 1; length -= 1; |
1681 |
– |
} |
1682 |
– |
|
1683 |
– |
// Align on 32-bit boundaries |
1684 |
– |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1685 |
– |
INVERT_2(dest, 0); |
1686 |
– |
dest += 2; length -= 2; |
1687 |
– |
} |
1688 |
– |
#endif |
1689 |
– |
|
1690 |
– |
// Invert 8-byte words |
1691 |
– |
if (length >= 8) { |
1692 |
– |
const int r = (length / 8) % 8; |
1693 |
– |
dest += r * 8; |
1694 |
– |
|
1695 |
– |
int n = ((length / 8) + 7) / 8; |
1696 |
– |
switch (r) { |
1697 |
– |
case 0: do { |
1698 |
– |
dest += 64; |
1699 |
– |
INVERT_8(dest, -8); |
1700 |
– |
case 7: INVERT_8(dest, -7); |
1701 |
– |
case 6: INVERT_8(dest, -6); |
1702 |
– |
case 5: INVERT_8(dest, -5); |
1703 |
– |
case 4: INVERT_8(dest, -4); |
1704 |
– |
case 3: INVERT_8(dest, -3); |
1705 |
– |
case 2: INVERT_8(dest, -2); |
1706 |
– |
case 1: INVERT_8(dest, -1); |
1707 |
– |
} while (--n > 0); |
1708 |
– |
} |
1709 |
– |
} |
1710 |
– |
|
1711 |
– |
// 32-bit cell to invert? |
1712 |
– |
if (length & 4) { |
1713 |
– |
INVERT_4(dest, 0); |
1714 |
– |
if (bpp <= 16) |
1715 |
– |
dest += 4; |
1716 |
– |
} |
1717 |
– |
|
1718 |
– |
// 16-bit cell to invert? |
1719 |
– |
if (bpp <= 16 && (length & 2)) { |
1720 |
– |
INVERT_2(dest, 0); |
1721 |
– |
if (bpp <= 8) |
1722 |
– |
dest += 2; |
1723 |
– |
} |
1724 |
– |
|
1725 |
– |
// 8-bit cell to invert? |
1726 |
– |
if (bpp <= 8 && (length & 1)) |
1727 |
– |
INVERT_1(dest, 0); |
1728 |
– |
|
1729 |
– |
#undef INVERT_1 |
1730 |
– |
#undef INVERT_2 |
1731 |
– |
#undef INVERT_4 |
1732 |
– |
#undef INVERT_8 |
1733 |
– |
} |
1734 |
– |
|
1735 |
– |
void NQD_invrect(uint32 p) |
1736 |
– |
{ |
1737 |
– |
D(bug("accl_invrect %08x\n", p)); |
1738 |
– |
|
1739 |
– |
// Get inversion parameters |
1740 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1741 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1742 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1743 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1744 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1745 |
– |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); |
1746 |
– |
|
1747 |
– |
//!!?? pen_mode == 14 |
1748 |
– |
|
1749 |
– |
// And perform the inversion |
1750 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1751 |
– |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1752 |
– |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1753 |
– |
width *= bpp; |
1754 |
– |
switch (bpp) { |
1755 |
– |
case 1: |
1756 |
– |
for (int i = 0; i < height; i++) { |
1757 |
– |
do_invrect<8>(dest, width); |
1758 |
– |
dest += dest_row_bytes; |
1759 |
– |
} |
1760 |
– |
break; |
1761 |
– |
case 2: |
1762 |
– |
for (int i = 0; i < height; i++) { |
1763 |
– |
do_invrect<16>(dest, width); |
1764 |
– |
dest += dest_row_bytes; |
1765 |
– |
} |
1766 |
– |
break; |
1767 |
– |
case 4: |
1768 |
– |
for (int i = 0; i < height; i++) { |
1769 |
– |
do_invrect<32>(dest, width); |
1770 |
– |
dest += dest_row_bytes; |
1771 |
– |
} |
1772 |
– |
break; |
1773 |
– |
} |
1774 |
– |
} |
1775 |
– |
|
1776 |
– |
// Rectangle filling |
1777 |
– |
template< int bpp > |
1778 |
– |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1779 |
– |
{ |
1780 |
– |
#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) |
1781 |
– |
#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) |
1782 |
– |
#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) |
1783 |
– |
#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) |
1784 |
– |
|
1785 |
– |
#ifndef UNALIGNED_PROFITABLE |
1786 |
– |
// Align on 16-bit boundaries |
1787 |
– |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1788 |
– |
FILL_1(dest, 0, color); |
1789 |
– |
dest += 1; length -= 1; |
1790 |
– |
} |
1791 |
– |
|
1792 |
– |
// Align on 32-bit boundaries |
1793 |
– |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1794 |
– |
FILL_2(dest, 0, color); |
1795 |
– |
dest += 2; length -= 2; |
1796 |
– |
} |
1797 |
– |
#endif |
1798 |
– |
|
1799 |
– |
// Fill 8-byte words |
1800 |
– |
if (length >= 8) { |
1801 |
– |
const uint64 c = (((uint64)color) << 32) | color; |
1802 |
– |
const int r = (length / 8) % 8; |
1803 |
– |
dest += r * 8; |
1804 |
– |
|
1805 |
– |
int n = ((length / 8) + 7) / 8; |
1806 |
– |
switch (r) { |
1807 |
– |
case 0: do { |
1808 |
– |
dest += 64; |
1809 |
– |
FILL_8(dest, -8, c); |
1810 |
– |
case 7: FILL_8(dest, -7, c); |
1811 |
– |
case 6: FILL_8(dest, -6, c); |
1812 |
– |
case 5: FILL_8(dest, -5, c); |
1813 |
– |
case 4: FILL_8(dest, -4, c); |
1814 |
– |
case 3: FILL_8(dest, -3, c); |
1815 |
– |
case 2: FILL_8(dest, -2, c); |
1816 |
– |
case 1: FILL_8(dest, -1, c); |
1817 |
– |
} while (--n > 0); |
1818 |
– |
} |
1819 |
– |
} |
1820 |
– |
|
1821 |
– |
// 32-bit cell to fill? |
1822 |
– |
if (length & 4) { |
1823 |
– |
FILL_4(dest, 0, color); |
1824 |
– |
if (bpp <= 16) |
1825 |
– |
dest += 4; |
1826 |
– |
} |
1827 |
– |
|
1828 |
– |
// 16-bit cell to fill? |
1829 |
– |
if (bpp <= 16 && (length & 2)) { |
1830 |
– |
FILL_2(dest, 0, color); |
1831 |
– |
if (bpp <= 8) |
1832 |
– |
dest += 2; |
1833 |
– |
} |
1834 |
– |
|
1835 |
– |
// 8-bit cell to fill? |
1836 |
– |
if (bpp <= 8 && (length & 1)) |
1837 |
– |
FILL_1(dest, 0, color); |
1838 |
– |
|
1839 |
– |
#undef FILL_1 |
1840 |
– |
#undef FILL_2 |
1841 |
– |
#undef FILL_4 |
1842 |
– |
#undef FILL_8 |
1843 |
– |
} |
1844 |
– |
|
1845 |
– |
void NQD_fillrect(uint32 p) |
1846 |
– |
{ |
1847 |
– |
D(bug("accl_fillrect %08x\n", p)); |
1848 |
– |
|
1849 |
– |
// Get filling parameters |
1850 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1851 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1852 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1853 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1854 |
– |
uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen)); |
1855 |
– |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1856 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1857 |
– |
D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); |
1858 |
– |
|
1859 |
– |
// And perform the fill |
1860 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1861 |
– |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1862 |
– |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1863 |
– |
width *= bpp; |
1864 |
– |
switch (bpp) { |
1865 |
– |
case 1: |
1866 |
– |
for (int i = 0; i < height; i++) { |
1867 |
– |
memset(dest, color, width); |
1868 |
– |
dest += dest_row_bytes; |
1869 |
– |
} |
1870 |
– |
break; |
1871 |
– |
case 2: |
1872 |
– |
for (int i = 0; i < height; i++) { |
1873 |
– |
do_fillrect<16>(dest, color, width); |
1874 |
– |
dest += dest_row_bytes; |
1875 |
– |
} |
1876 |
– |
break; |
1877 |
– |
case 4: |
1878 |
– |
for (int i = 0; i < height; i++) { |
1879 |
– |
do_fillrect<32>(dest, color, width); |
1880 |
– |
dest += dest_row_bytes; |
1881 |
– |
} |
1882 |
– |
break; |
1883 |
– |
} |
1884 |
– |
} |
1885 |
– |
|
1886 |
– |
bool NQD_fillrect_hook(uint32 p) |
1887 |
– |
{ |
1888 |
– |
D(bug("accl_fillrect_hook %08x\n", p)); |
1889 |
– |
|
1890 |
– |
// Check if we can accelerate this fillrect |
1891 |
– |
if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { |
1892 |
– |
const int transfer_mode = ReadMacInt32(p + acclTransferMode); |
1893 |
– |
if (transfer_mode == 8) { |
1894 |
– |
// Fill |
1895 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); |
1896 |
– |
return true; |
1897 |
– |
} |
1898 |
– |
else if (transfer_mode == 10) { |
1899 |
– |
// Invert |
1900 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); |
1901 |
– |
return true; |
1902 |
– |
} |
1903 |
– |
} |
1904 |
– |
return false; |
1905 |
– |
} |
1906 |
– |
|
1907 |
– |
// Rectangle blitting |
1908 |
– |
// TODO: optimize for VOSF and target pixmap == screen |
1909 |
– |
void NQD_bitblt(uint32 p) |
1910 |
– |
{ |
1911 |
– |
D(bug("accl_bitblt %08x\n", p)); |
1912 |
– |
|
1913 |
– |
// Get blitting parameters |
1914 |
– |
int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); |
1915 |
– |
int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); |
1916 |
– |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1917 |
– |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1918 |
– |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1919 |
– |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1920 |
– |
D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); |
1921 |
– |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1922 |
– |
D(bug(" width %d, height %d\n", width, height)); |
1923 |
– |
|
1924 |
– |
// And perform the blit |
1925 |
– |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); |
1926 |
– |
width *= bpp; |
1927 |
– |
if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { |
1928 |
– |
const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); |
1929 |
– |
const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1930 |
– |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp)); |
1931 |
– |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp)); |
1932 |
– |
for (int i = 0; i < height; i++) { |
1933 |
– |
memmove(dst, src, width); |
1934 |
– |
src += src_row_bytes; |
1935 |
– |
dst += dst_row_bytes; |
1936 |
– |
} |
1937 |
– |
} |
1938 |
– |
else { |
1939 |
– |
const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); |
1940 |
– |
const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); |
1941 |
– |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp)); |
1942 |
– |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp)); |
1943 |
– |
for (int i = height - 1; i >= 0; i--) { |
1944 |
– |
memmove(dst, src, width); |
1945 |
– |
src -= src_row_bytes; |
1946 |
– |
dst -= dst_row_bytes; |
1947 |
– |
} |
1948 |
– |
} |
1949 |
– |
} |
1950 |
– |
|
1951 |
– |
/* |
1952 |
– |
BitBlt transfer modes: |
1953 |
– |
0 : srcCopy |
1954 |
– |
1 : srcOr |
1955 |
– |
2 : srcXor |
1956 |
– |
3 : srcBic |
1957 |
– |
4 : notSrcCopy |
1958 |
– |
5 : notSrcOr |
1959 |
– |
6 : notSrcXor |
1960 |
– |
7 : notSrcBic |
1961 |
– |
32 : blend |
1962 |
– |
33 : addPin |
1963 |
– |
34 : addOver |
1964 |
– |
35 : subPin |
1965 |
– |
36 : transparent |
1966 |
– |
37 : adMax |
1967 |
– |
38 : subOver |
1968 |
– |
39 : adMin |
1969 |
– |
50 : hilite |
1970 |
– |
*/ |
1971 |
– |
|
1972 |
– |
bool NQD_bitblt_hook(uint32 p) |
1973 |
– |
{ |
1974 |
– |
D(bug("accl_draw_hook %08x\n", p)); |
1975 |
– |
|
1976 |
– |
// Check if we can accelerate this bitblt |
1977 |
– |
if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && |
1978 |
– |
ReadMacInt32(p + 0x130) == 0 && |
1979 |
– |
ReadMacInt32(p + acclSrcPixelSize) >= 8 && |
1980 |
– |
ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && |
1981 |
– |
(ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? |
1982 |
– |
ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? |
1983 |
– |
ReadMacInt32(p + 0x15c) > 0) { |
1984 |
– |
|
1985 |
– |
// Yes, set function pointer |
1986 |
– |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); |
1987 |
– |
return true; |
1988 |
– |
} |
1989 |
– |
return false; |
1990 |
– |
} |
1991 |
– |
|
1992 |
– |
// Wait for graphics operation to finish |
1993 |
– |
bool NQD_sync_hook(uint32 arg) |
1994 |
– |
{ |
1995 |
– |
D(bug("accl_sync_hook %08x\n", arg)); |
1996 |
– |
return true; |
1997 |
– |
} |
1998 |
– |
|
1999 |
– |
void VideoInstallAccel(void) |
2000 |
– |
{ |
2001 |
– |
// Install acceleration hooks |
2002 |
– |
if (PrefsFindBool("gfxaccel")) { |
2003 |
– |
D(bug("Video: Installing acceleration hooks\n")); |
2004 |
– |
uint32 base; |
2005 |
– |
|
2006 |
– |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
2007 |
– |
base = bitblt_hook_info.addr(); |
2008 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
2009 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
2010 |
– |
WriteMacInt32(base + 8, ACCL_BITBLT); |
2011 |
– |
NQDMisc(6, bitblt_hook_info.ptr()); |
2012 |
– |
|
2013 |
– |
SheepVar fillrect_hook_info(sizeof(accl_hook_info)); |
2014 |
– |
base = fillrect_hook_info.addr(); |
2015 |
– |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); |
2016 |
– |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
2017 |
– |
WriteMacInt32(base + 8, ACCL_FILLRECT); |
2018 |
– |
NQDMisc(6, fillrect_hook_info.ptr()); |
2019 |
– |
} |
2020 |
– |
} |
2021 |
– |
|
2022 |
– |
|
1714 |
|
/* |
1715 |
|
* Change video mode |
1716 |
|
*/ |