56 |
|
# include <fcntl.h> |
57 |
|
# include <sys/mman.h> |
58 |
|
# include "sigsegv.h" |
59 |
+ |
# include "vm_alloc.h" |
60 |
|
#endif |
61 |
|
|
62 |
|
#include "cpu_emulation.h" |
188 |
|
}; |
189 |
|
|
190 |
|
struct ScreenInfo { |
191 |
< |
uint32 memBase; // Real start address |
192 |
< |
uint32 memStart; // Start address aligned to page boundary |
193 |
< |
uint32 memEnd; // Address of one-past-the-end of the screen |
191 |
> |
uintptr memBase; // Real start address |
192 |
> |
uintptr memStart; // Start address aligned to page boundary |
193 |
> |
uintptr memEnd; // Address of one-past-the-end of the screen |
194 |
|
uint32 memLength; // Length of the memory addressed by the screen pages |
195 |
|
|
196 |
|
uint32 pageSize; // Size of a page |
325 |
|
* Initialization |
326 |
|
*/ |
327 |
|
|
328 |
< |
// Set VideoMonitor according to video mode |
329 |
< |
void set_video_monitor(int width, int height, int bytes_per_row, bool native_byte_order) |
328 |
> |
// Add resolution to list of supported modes and set VideoMonitor |
329 |
> |
static void set_video_monitor(uint32 width, uint32 height, uint32 bytes_per_row, bool native_byte_order) |
330 |
|
{ |
331 |
+ |
video_mode mode; |
332 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
333 |
|
int layout = FLAYOUT_DIRECT; |
334 |
|
switch (depth) { |
354 |
|
else |
355 |
|
MacFrameLayout = FLAYOUT_DIRECT; |
356 |
|
#endif |
357 |
+ |
|
358 |
+ |
mode.x = width; |
359 |
+ |
mode.y = height; |
360 |
+ |
mode.resolution_id = 0x80; |
361 |
+ |
mode.bytes_per_row = bytes_per_row; |
362 |
+ |
|
363 |
|
switch (depth) { |
364 |
|
case 1: |
365 |
< |
VideoMonitor.mode = VMODE_1BIT; |
365 |
> |
mode.depth = VDEPTH_1BIT; |
366 |
> |
break; |
367 |
> |
case 2: |
368 |
> |
mode.depth = VDEPTH_2BIT; |
369 |
> |
break; |
370 |
> |
case 4: |
371 |
> |
mode.depth = VDEPTH_4BIT; |
372 |
|
break; |
373 |
|
case 8: |
374 |
< |
VideoMonitor.mode = VMODE_8BIT; |
374 |
> |
mode.depth = VDEPTH_8BIT; |
375 |
|
break; |
376 |
|
case 15: |
377 |
< |
VideoMonitor.mode = VMODE_16BIT; |
377 |
> |
mode.depth = VDEPTH_16BIT; |
378 |
|
break; |
379 |
|
case 16: |
380 |
< |
VideoMonitor.mode = VMODE_16BIT; |
380 |
> |
mode.depth = VDEPTH_16BIT; |
381 |
|
break; |
382 |
|
case 24: |
383 |
|
case 32: |
384 |
< |
VideoMonitor.mode = VMODE_32BIT; |
384 |
> |
mode.depth = VDEPTH_32BIT; |
385 |
|
break; |
386 |
|
} |
387 |
< |
VideoMonitor.x = width; |
388 |
< |
VideoMonitor.y = height; |
389 |
< |
VideoMonitor.bytes_per_row = bytes_per_row; |
387 |
> |
|
388 |
> |
VideoModes.push_back(mode); |
389 |
> |
VideoMonitor.mode = mode; |
390 |
|
} |
391 |
|
|
392 |
|
// Set window name and class |
558 |
|
} |
559 |
|
|
560 |
|
#ifdef ENABLE_VOSF |
561 |
< |
// Allocate a page-aligned chunk of memory for frame buffer |
548 |
< |
the_buffer_size = align_on_page_boundary((aligned_height + 2) * img->bytes_per_line); |
561 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
562 |
|
the_host_buffer = the_buffer_copy; |
563 |
< |
|
564 |
< |
the_buffer_copy = (uint8 *)allocate_framebuffer(the_buffer_size); |
565 |
< |
memset(the_buffer_copy, 0, the_buffer_size); |
553 |
< |
|
554 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
555 |
< |
memset(the_buffer, 0, the_buffer_size); |
563 |
> |
the_buffer_size = page_extend((aligned_height + 2) * img->bytes_per_line); |
564 |
> |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
565 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
566 |
|
#else |
567 |
|
// Allocate memory for frame buffer |
568 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
579 |
|
&black, &white, 0, 0); |
580 |
|
XDefineCursor(x_display, the_win, mac_cursor); |
581 |
|
|
582 |
< |
// Set VideoMonitor |
582 |
> |
// Add resolution and set VideoMonitor |
583 |
|
bool native_byte_order; |
584 |
|
#ifdef WORDS_BIGENDIAN |
585 |
|
native_byte_order = (XImageByteOrder(x_display) == MSBFirst); |
731 |
|
use_vosf = Screen_blitter_init(&visualInfo, true); |
732 |
|
|
733 |
|
if (use_vosf) { |
734 |
< |
the_host_buffer = the_buffer; |
735 |
< |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
736 |
< |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
737 |
< |
memset(the_buffer_copy, 0, the_buffer_size); |
738 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
729 |
< |
memset(the_buffer, 0, the_buffer_size); |
734 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
735 |
> |
the_host_buffer = the_buffer; |
736 |
> |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
737 |
> |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
738 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
739 |
|
} |
740 |
|
#else |
741 |
|
use_vosf = false; |
830 |
|
bytes_per_row *= 4; |
831 |
|
break; |
832 |
|
} |
833 |
< |
|
833 |
> |
|
834 |
> |
#ifdef VIDEO_VOSF |
835 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
836 |
|
// Screen_blitter_init() returns TRUE if VOSF is mandatory |
837 |
|
// i.e. the framebuffer update function is not Blit_Copy_Raw |
838 |
|
use_vosf = Screen_blitter_init(&visualInfo, true); |
839 |
|
|
840 |
|
if (use_vosf) { |
841 |
< |
the_host_buffer = the_buffer; |
842 |
< |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
843 |
< |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
844 |
< |
memset(the_buffer_copy, 0, the_buffer_size); |
845 |
< |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
836 |
< |
memset(the_buffer, 0, the_buffer_size); |
841 |
> |
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
842 |
> |
the_host_buffer = the_buffer; |
843 |
> |
the_buffer_size = page_extend((height + 2) * bytes_per_row); |
844 |
> |
the_buffer_copy = (uint8 *)vm_acquire(the_buffer_size); |
845 |
> |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
846 |
|
} |
847 |
< |
#elif defined(ENABLE_VOSF) |
839 |
< |
// The UAE memory handlers will already handle color conversion, if needed. |
847 |
> |
#else |
848 |
|
use_vosf = false; |
849 |
|
#endif |
850 |
+ |
#endif |
851 |
|
|
852 |
|
set_video_monitor(width, height, bytes_per_row, true); |
853 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
935 |
|
const uint32 page_size = getpagesize(); |
936 |
|
const uint32 page_mask = page_size - 1; |
937 |
|
|
938 |
< |
mainBuffer.memBase = (uint32) the_buffer; |
938 |
> |
mainBuffer.memBase = (uintptr) the_buffer; |
939 |
|
// Align the frame buffer on page boundary |
940 |
< |
mainBuffer.memStart = (uint32)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
940 |
> |
mainBuffer.memStart = (uintptr)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
941 |
|
mainBuffer.memLength = the_buffer_size; |
942 |
|
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
943 |
|
|
968 |
|
|
969 |
|
uint32 a = 0; |
970 |
|
for (int i = 0; i < mainBuffer.pageCount; i++) { |
971 |
< |
int y1 = a / VideoMonitor.bytes_per_row; |
972 |
< |
if (y1 >= VideoMonitor.y) |
973 |
< |
y1 = VideoMonitor.y - 1; |
974 |
< |
|
975 |
< |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row; |
976 |
< |
if (y2 >= VideoMonitor.y) |
977 |
< |
y2 = VideoMonitor.y - 1; |
971 |
> |
int y1 = a / VideoMonitor.mode.bytes_per_row; |
972 |
> |
if (y1 >= VideoMonitor.mode.y) |
973 |
> |
y1 = VideoMonitor.mode.y - 1; |
974 |
> |
|
975 |
> |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.mode.bytes_per_row; |
976 |
> |
if (y2 >= VideoMonitor.mode.y) |
977 |
> |
y2 = VideoMonitor.mode.y - 1; |
978 |
|
|
979 |
|
mainBuffer.pageInfo[i].top = y1; |
980 |
|
mainBuffer.pageInfo[i].bottom = y2; |
985 |
|
} |
986 |
|
|
987 |
|
// We can now write-protect the frame buffer |
988 |
< |
if (mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ) != 0) |
988 |
> |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
989 |
|
return false; |
990 |
|
} |
991 |
|
#endif |
1161 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
1162 |
|
// Set variables for UAE memory mapping |
1163 |
|
MacFrameBaseHost = the_buffer; |
1164 |
< |
MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y; |
1164 |
> |
MacFrameSize = VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y; |
1165 |
|
|
1166 |
|
// No special frame buffer in Classic mode (frame buffer is in Mac RAM) |
1167 |
|
if (classic) |
1269 |
|
} |
1270 |
|
#ifdef ENABLE_VOSF |
1271 |
|
else { |
1272 |
< |
if (the_buffer != (uint8 *)MAP_FAILED) { |
1273 |
< |
munmap((caddr_t)the_buffer, the_buffer_size); |
1272 |
> |
if (the_buffer != (uint8 *)VM_MAP_FAILED) { |
1273 |
> |
vm_release(the_buffer, the_buffer_size); |
1274 |
|
the_buffer = 0; |
1275 |
|
} |
1276 |
|
|
1277 |
< |
if (the_buffer_copy != (uint8 *)MAP_FAILED) { |
1278 |
< |
munmap((caddr_t)the_buffer_copy, the_buffer_size); |
1277 |
> |
if (the_buffer_copy != (uint8 *)VM_MAP_FAILED) { |
1278 |
> |
vm_release(the_buffer_copy, the_buffer_size); |
1279 |
|
the_buffer_copy = 0; |
1280 |
|
} |
1281 |
|
} |
1357 |
|
|
1358 |
|
|
1359 |
|
/* |
1360 |
+ |
* Switch video mode |
1361 |
+ |
*/ |
1362 |
+ |
|
1363 |
+ |
void video_switch_to_mode(const video_mode &mode) |
1364 |
+ |
{ |
1365 |
+ |
} |
1366 |
+ |
|
1367 |
+ |
|
1368 |
+ |
/* |
1369 |
|
* Suspend/resume emulator |
1370 |
|
*/ |
1371 |
|
|
1381 |
|
LOCK_FRAME_BUFFER; |
1382 |
|
|
1383 |
|
// Save frame buffer |
1384 |
< |
fb_save = malloc(VideoMonitor.y * VideoMonitor.bytes_per_row); |
1384 |
> |
fb_save = malloc(VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1385 |
|
if (fb_save) |
1386 |
< |
memcpy(fb_save, the_buffer, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1386 |
> |
memcpy(fb_save, the_buffer, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1387 |
|
|
1388 |
|
// Close full screen display |
1389 |
|
#ifdef ENABLE_XF86_DGA |
1434 |
|
LOCK_VOSF; |
1435 |
|
PFLAG_SET_ALL; |
1436 |
|
UNLOCK_VOSF; |
1437 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1437 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1438 |
|
} |
1439 |
|
#endif |
1440 |
|
|
1444 |
|
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1445 |
|
if (!use_vosf) |
1446 |
|
#endif |
1447 |
< |
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1447 |
> |
memcpy(the_buffer, fb_save, VideoMonitor.mode.y * VideoMonitor.mode.bytes_per_row); |
1448 |
|
free(fb_save); |
1449 |
|
fb_save = NULL; |
1450 |
|
} |
1725 |
|
LOCK_VOSF; |
1726 |
|
PFLAG_SET_ALL; |
1727 |
|
UNLOCK_VOSF; |
1728 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1728 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1729 |
|
} |
1730 |
|
else |
1731 |
|
#endif |
1736 |
|
updt_box[x1][y1] = true; |
1737 |
|
nr_boxes = 16 * 16; |
1738 |
|
} else // Static refresh |
1739 |
< |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1739 |
> |
memset(the_buffer_copy, 0, VideoMonitor.mode.bytes_per_row * VideoMonitor.mode.y); |
1740 |
|
} |
1741 |
|
break; |
1742 |
|
|
1762 |
|
int y1, y2, y2s, y2a, i, x1, xm, xmo, ymo, yo, yi, yil, xi; |
1763 |
|
int xil = 0; |
1764 |
|
int rxm = 0, rxmo = 0; |
1765 |
< |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1766 |
< |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1767 |
< |
int rx = VideoMonitor.bytes_per_row / 16; |
1768 |
< |
int ry = VideoMonitor.y / 16; |
1765 |
> |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
1766 |
> |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
1767 |
> |
int rx = VideoMonitor.mode.bytes_per_row / 16; |
1768 |
> |
int ry = VideoMonitor.mode.y / 16; |
1769 |
|
int max_box; |
1770 |
|
|
1771 |
|
y2s = sm_uptd[ticker % 8]; |
1851 |
|
{ |
1852 |
|
// Incremental update code |
1853 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1854 |
< |
int bytes_per_row = VideoMonitor.bytes_per_row; |
1855 |
< |
int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
1854 |
> |
int bytes_per_row = VideoMonitor.mode.bytes_per_row; |
1855 |
> |
int bytes_per_pixel = VideoMonitor.mode.bytes_per_row / VideoMonitor.mode.x; |
1856 |
|
uint8 *p, *p2; |
1857 |
|
|
1858 |
|
// Check for first line from top and first line from bottom that have changed |
1859 |
|
y1 = 0; |
1860 |
< |
for (j=0; j<VideoMonitor.y; j++) { |
1860 |
> |
for (j=0; j<VideoMonitor.mode.y; j++) { |
1861 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1862 |
|
y1 = j; |
1863 |
|
break; |
1864 |
|
} |
1865 |
|
} |
1866 |
|
y2 = y1 - 1; |
1867 |
< |
for (j=VideoMonitor.y-1; j>=y1; j--) { |
1867 |
> |
for (j=VideoMonitor.mode.y-1; j>=y1; j--) { |
1868 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1869 |
|
y2 = j; |
1870 |
|
break; |
1875 |
|
// Check for first column from left and first column from right that have changed |
1876 |
|
if (high) { |
1877 |
|
if (depth == 1) { |
1878 |
< |
x1 = VideoMonitor.x - 1; |
1878 |
> |
x1 = VideoMonitor.mode.x - 1; |
1879 |
|
for (j=y1; j<=y2; j++) { |
1880 |
|
p = &the_buffer[j * bytes_per_row]; |
1881 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1893 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1894 |
|
p += bytes_per_row; |
1895 |
|
p2 += bytes_per_row; |
1896 |
< |
for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { |
1896 |
> |
for (i=(VideoMonitor.mode.x>>3); i>(x2>>3); i--) { |
1897 |
|
p--; p2--; |
1898 |
|
if (*p != *p2) { |
1899 |
|
x2 = (i << 3) + 7; |
1912 |
|
} |
1913 |
|
|
1914 |
|
} else { |
1915 |
< |
x1 = VideoMonitor.x; |
1915 |
> |
x1 = VideoMonitor.mode.x; |
1916 |
|
for (j=y1; j<=y2; j++) { |
1917 |
|
p = &the_buffer[j * bytes_per_row]; |
1918 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1930 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1931 |
|
p += bytes_per_row; |
1932 |
|
p2 += bytes_per_row; |
1933 |
< |
for (i=VideoMonitor.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1933 |
> |
for (i=VideoMonitor.mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1934 |
|
p--; |
1935 |
|
p2--; |
1936 |
|
if (*p != *p2) { |