52 |
|
# include <sys/mman.h> |
53 |
|
#endif |
54 |
|
|
55 |
+ |
#ifdef ENABLE_VOSF |
56 |
+ |
# include <unistd.h> |
57 |
+ |
# include <signal.h> |
58 |
+ |
# include <fcntl.h> |
59 |
+ |
# include <sys/mman.h> |
60 |
+ |
#endif |
61 |
+ |
|
62 |
|
#include "cpu_emulation.h" |
63 |
|
#include "main.h" |
64 |
|
#include "adb.h" |
161 |
|
static int num_x_video_modes; |
162 |
|
#endif |
163 |
|
|
164 |
+ |
#ifdef ENABLE_VOSF |
165 |
+ |
static bool use_vosf = true; // Flag: VOSF enabled |
166 |
+ |
#else |
167 |
+ |
static const bool use_vosf = false; // Flag: VOSF enabled |
168 |
+ |
#endif |
169 |
+ |
|
170 |
+ |
#ifdef ENABLE_VOSF |
171 |
+ |
static uint8 * the_host_buffer; // Host frame buffer in VOSF mode |
172 |
+ |
static uint32 the_buffer_size; // Size of allocated the_buffer |
173 |
+ |
#endif |
174 |
+ |
|
175 |
+ |
#ifdef ENABLE_VOSF |
176 |
+ |
// Variables for Video on SEGV support (taken from the Win32 port) |
177 |
+ |
struct ScreenPageInfo { |
178 |
+ |
int top, bottom; // Mapping between this virtual page and Mac scanlines |
179 |
+ |
}; |
180 |
+ |
|
181 |
+ |
struct ScreenInfo { |
182 |
+ |
uint32 memBase; // Real start address |
183 |
+ |
uint32 memStart; // Start address aligned to page boundary |
184 |
+ |
uint32 memEnd; // Address of one-past-the-end of the screen |
185 |
+ |
uint32 memLength; // Length of the memory addressed by the screen pages |
186 |
+ |
|
187 |
+ |
uint32 pageSize; // Size of a page |
188 |
+ |
int pageBits; // Shift count to get the page number |
189 |
+ |
uint32 pageCount; // Number of pages allocated to the screen |
190 |
+ |
|
191 |
+ |
uint8 * dirtyPages; // Table of flags set if page was altered |
192 |
+ |
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
193 |
+ |
}; |
194 |
+ |
|
195 |
+ |
static ScreenInfo mainBuffer; |
196 |
+ |
|
197 |
+ |
#define PFLAG_SET(page) mainBuffer.dirtyPages[page] = 1 |
198 |
+ |
#define PFLAG_CLEAR(page) mainBuffer.dirtyPages[page] = 0 |
199 |
+ |
#define PFLAG_ISSET(page) mainBuffer.dirtyPages[page] |
200 |
+ |
#define PFLAG_ISCLEAR(page) (mainBuffer.dirtyPages[page] == 0) |
201 |
+ |
#ifdef UNALIGNED_PROFITABLE |
202 |
+ |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + page)) == 0) |
203 |
+ |
#else |
204 |
+ |
# define PFLAG_ISCLEAR_4(page) \ |
205 |
+ |
(mainBuffer.dirtyPages[page ] == 0) \ |
206 |
+ |
&& (mainBuffer.dirtyPages[page+1] == 0) \ |
207 |
+ |
&& (mainBuffer.dirtyPages[page+2] == 0) \ |
208 |
+ |
&& (mainBuffer.dirtyPages[page+3] == 0) |
209 |
+ |
#endif |
210 |
+ |
#define PFLAG_CLEAR_ALL memset(mainBuffer.dirtyPages, 0, mainBuffer.pageCount) |
211 |
+ |
#define PFLAG_SET_ALL memset(mainBuffer.dirtyPages, 1, mainBuffer.pageCount) |
212 |
+ |
|
213 |
+ |
static int zero_fd = -1; |
214 |
+ |
static bool Screen_fault_handler_init(); |
215 |
+ |
static struct sigaction vosf_sa; |
216 |
+ |
|
217 |
+ |
#ifdef HAVE_PTHREADS |
218 |
+ |
static pthread_mutex_t Screen_draw_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
219 |
+ |
#endif |
220 |
+ |
|
221 |
+ |
static int log_base_2(uint32 x) |
222 |
+ |
{ |
223 |
+ |
uint32 mask = 0x80000000; |
224 |
+ |
int l = 31; |
225 |
+ |
while (l >= 0 && (x & mask) == 0) { |
226 |
+ |
mask >>= 1; |
227 |
+ |
l--; |
228 |
+ |
} |
229 |
+ |
return l; |
230 |
+ |
} |
231 |
+ |
|
232 |
+ |
#endif |
233 |
+ |
|
234 |
+ |
// VideoRefresh function |
235 |
+ |
void VideoRefreshInit(void); |
236 |
+ |
static void (*video_refresh)(void); |
237 |
|
|
238 |
|
// Prototypes |
239 |
|
static void *redraw_func(void *arg); |
247 |
|
// From sys_unix.cpp |
248 |
|
extern void SysMountFirstFloppy(void); |
249 |
|
|
250 |
+ |
#ifdef ENABLE_VOSF |
251 |
+ |
# include "video_vosf.h" |
252 |
+ |
#endif |
253 |
+ |
|
254 |
|
|
255 |
|
/* |
256 |
|
* Initialization |
259 |
|
// Set VideoMonitor according to video mode |
260 |
|
void set_video_monitor(int width, int height, int bytes_per_row, bool native_byte_order) |
261 |
|
{ |
262 |
< |
#if !REAL_ADDRESSING |
262 |
> |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
263 |
|
int layout = FLAYOUT_DIRECT; |
264 |
|
switch (depth) { |
265 |
|
case 1: |
421 |
|
img->bitmap_bit_order = MSBFirst; |
422 |
|
} |
423 |
|
|
424 |
+ |
#ifdef ENABLE_VOSF |
425 |
+ |
// Allocate a page-aligned chunk of memory for frame buffer |
426 |
+ |
the_buffer_size = align_on_page_boundary((aligned_height + 2) * img->bytes_per_line); |
427 |
+ |
the_host_buffer = the_buffer_copy; |
428 |
+ |
|
429 |
+ |
the_buffer_copy = (uint8 *)allocate_framebuffer(the_buffer_size); |
430 |
+ |
memset(the_buffer_copy, 0, the_buffer_size); |
431 |
+ |
|
432 |
+ |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
433 |
+ |
memset(the_buffer, 0, the_buffer_size); |
434 |
+ |
#else |
435 |
|
// Allocate memory for frame buffer |
436 |
|
the_buffer = (uint8 *)malloc((aligned_height + 2) * img->bytes_per_line); |
437 |
+ |
#endif |
438 |
|
|
439 |
|
// Create GC |
440 |
|
the_gc = XCreateGC(x_display, the_win, 0, 0); |
448 |
|
XDefineCursor(x_display, the_win, mac_cursor); |
449 |
|
|
450 |
|
// Set VideoMonitor |
451 |
+ |
bool native_byte_order; |
452 |
|
#ifdef WORDS_BIGENDIAN |
453 |
< |
set_video_monitor(width, height, img->bytes_per_line, img->bitmap_bit_order == MSBFirst); |
453 |
> |
native_byte_order = (img->bitmap_bit_order == MSBFirst); |
454 |
|
#else |
455 |
< |
set_video_monitor(width, height, img->bytes_per_line, img->bitmap_bit_order == LSBFirst); |
455 |
> |
native_byte_order = (img->bitmap_bit_order == LSBFirst); |
456 |
|
#endif |
457 |
+ |
#ifdef ENABLE_VOSF |
458 |
+ |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, native_byte_order, DISPLAY_WINDOW); |
459 |
+ |
#endif |
460 |
+ |
set_video_monitor(width, height, img->bytes_per_line, native_byte_order); |
461 |
|
|
462 |
< |
#if REAL_ADDRESSING |
463 |
< |
VideoMonitor.mac_frame_base = (uint32)the_buffer; |
462 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
463 |
> |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
464 |
|
#else |
465 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
466 |
|
#endif |
593 |
|
} |
594 |
|
} |
595 |
|
|
596 |
+ |
#if ENABLE_VOSF |
597 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
598 |
+ |
// If the blit function is null, i.e. just a copy of the buffer, |
599 |
+ |
// we first try to avoid the allocation of a temporary frame buffer |
600 |
+ |
use_vosf = true; |
601 |
+ |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA); |
602 |
+ |
if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw)) |
603 |
+ |
use_vosf = false; |
604 |
+ |
|
605 |
+ |
if (use_vosf) { |
606 |
+ |
the_host_buffer = the_buffer; |
607 |
+ |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
608 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
609 |
+ |
memset(the_buffer_copy, 0, the_buffer_size); |
610 |
+ |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
611 |
+ |
memset(the_buffer, 0, the_buffer_size); |
612 |
+ |
} |
613 |
+ |
#else |
614 |
+ |
use_vosf = false; |
615 |
+ |
#endif |
616 |
+ |
#endif |
617 |
+ |
|
618 |
|
set_video_monitor(width, height, bytes_per_row, true); |
619 |
< |
#if REAL_ADDRESSING |
620 |
< |
VideoMonitor.mac_frame_base = (uint32)the_buffer; |
619 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
620 |
> |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
621 |
|
#else |
622 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
623 |
|
#endif |
698 |
|
bytes_per_row *= 4; |
699 |
|
break; |
700 |
|
} |
701 |
+ |
|
702 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
703 |
+ |
// If the blit function is null, i.e. just a copy of the buffer, |
704 |
+ |
// we first try to avoid the allocation of a temporary frame buffer |
705 |
+ |
use_vosf = true; |
706 |
+ |
do_update_framebuffer = GET_FBCOPY_FUNC(depth, true, DISPLAY_DGA); |
707 |
+ |
if (do_update_framebuffer == FBCOPY_FUNC(fbcopy_raw)) |
708 |
+ |
use_vosf = false; |
709 |
+ |
|
710 |
+ |
if (use_vosf) { |
711 |
+ |
the_host_buffer = the_buffer; |
712 |
+ |
the_buffer_size = align_on_page_boundary((height + 2) * bytes_per_row); |
713 |
+ |
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
714 |
+ |
memset(the_buffer_copy, 0, the_buffer_size); |
715 |
+ |
the_buffer = (uint8 *)allocate_framebuffer(the_buffer_size); |
716 |
+ |
memset(the_buffer, 0, the_buffer_size); |
717 |
+ |
} |
718 |
+ |
#elif defined(ENABLE_VOSF) |
719 |
+ |
// The UAE memory handlers will already handle color conversion, if needed. |
720 |
+ |
use_vosf = false; |
721 |
+ |
#endif |
722 |
+ |
|
723 |
|
set_video_monitor(width, height, bytes_per_row, true); |
724 |
< |
#if REAL_ADDRESSING |
725 |
< |
VideoMonitor.mac_frame_base = (uint32)the_buffer; |
726 |
< |
MacFrameLayout = FLAYOUT_DIRECT; |
724 |
> |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
725 |
> |
VideoMonitor.mac_frame_base = Host2MacAddr(the_buffer); |
726 |
> |
// MacFrameLayout = FLAYOUT_DIRECT; |
727 |
|
#else |
728 |
|
VideoMonitor.mac_frame_base = MacFrameBaseMac; |
729 |
|
#endif |
799 |
|
} |
800 |
|
} |
801 |
|
|
802 |
+ |
bool VideoInitBuffer() |
803 |
+ |
{ |
804 |
+ |
#ifdef ENABLE_VOSF |
805 |
+ |
if (use_vosf) { |
806 |
+ |
const uint32 page_size = getpagesize(); |
807 |
+ |
const uint32 page_mask = page_size - 1; |
808 |
+ |
|
809 |
+ |
mainBuffer.memBase = (uint32) the_buffer; |
810 |
+ |
// Align the frame buffer on page boundary |
811 |
+ |
mainBuffer.memStart = (uint32)((((unsigned long) the_buffer) + page_mask) & ~page_mask); |
812 |
+ |
mainBuffer.memLength = the_buffer_size; |
813 |
+ |
mainBuffer.memEnd = mainBuffer.memStart + mainBuffer.memLength; |
814 |
+ |
|
815 |
+ |
mainBuffer.pageSize = page_size; |
816 |
+ |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
817 |
+ |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
818 |
+ |
|
819 |
+ |
if (mainBuffer.dirtyPages != 0) |
820 |
+ |
free(mainBuffer.dirtyPages); |
821 |
+ |
|
822 |
+ |
mainBuffer.dirtyPages = (uint8 *) malloc(mainBuffer.pageCount); |
823 |
+ |
|
824 |
+ |
if (mainBuffer.pageInfo != 0) |
825 |
+ |
free(mainBuffer.pageInfo); |
826 |
+ |
|
827 |
+ |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
828 |
+ |
|
829 |
+ |
if ((mainBuffer.dirtyPages == 0) || (mainBuffer.pageInfo == 0)) |
830 |
+ |
return false; |
831 |
+ |
|
832 |
+ |
PFLAG_CLEAR_ALL; |
833 |
+ |
|
834 |
+ |
uint32 a = 0; |
835 |
+ |
for (int i = 0; i < mainBuffer.pageCount; i++) { |
836 |
+ |
int y1 = a / VideoMonitor.bytes_per_row; |
837 |
+ |
if (y1 >= VideoMonitor.y) |
838 |
+ |
y1 = VideoMonitor.y - 1; |
839 |
+ |
|
840 |
+ |
int y2 = (a + mainBuffer.pageSize) / VideoMonitor.bytes_per_row; |
841 |
+ |
if (y2 >= VideoMonitor.y) |
842 |
+ |
y2 = VideoMonitor.y - 1; |
843 |
+ |
|
844 |
+ |
mainBuffer.pageInfo[i].top = y1; |
845 |
+ |
mainBuffer.pageInfo[i].bottom = y2; |
846 |
+ |
|
847 |
+ |
a += mainBuffer.pageSize; |
848 |
+ |
if (a > mainBuffer.memLength) |
849 |
+ |
a = mainBuffer.memLength; |
850 |
+ |
} |
851 |
+ |
|
852 |
+ |
// We can now write-protect the frame buffer |
853 |
+ |
if (mprotect((caddr_t)mainBuffer.memStart, mainBuffer.memLength, PROT_READ) != 0) |
854 |
+ |
return false; |
855 |
+ |
} |
856 |
+ |
#endif |
857 |
+ |
return true; |
858 |
+ |
} |
859 |
+ |
|
860 |
|
bool VideoInit(bool classic) |
861 |
|
{ |
862 |
+ |
#ifdef ENABLE_VOSF |
863 |
+ |
// Open /dev/zero |
864 |
+ |
zero_fd = open("/dev/zero", O_RDWR); |
865 |
+ |
if (zero_fd < 0) { |
866 |
+ |
char str[256]; |
867 |
+ |
sprintf(str, GetString(STR_NO_DEV_ZERO_ERR), strerror(errno)); |
868 |
+ |
ErrorAlert(str); |
869 |
+ |
return false; |
870 |
+ |
} |
871 |
+ |
|
872 |
+ |
// Zero the mainBuffer structure |
873 |
+ |
mainBuffer.dirtyPages = 0; |
874 |
+ |
mainBuffer.pageInfo = 0; |
875 |
+ |
#endif |
876 |
+ |
|
877 |
|
// Check if X server runs on local machine |
878 |
|
local_X11 = (strncmp(XDisplayName(x_display_name), ":", 1) == 0) |
879 |
|
|| (strncmp(XDisplayName(x_display_name), "unix:", 5) == 0); |
1025 |
|
pthread_mutex_lock(&frame_buffer_lock); |
1026 |
|
#endif |
1027 |
|
|
1028 |
< |
#if !REAL_ADDRESSING |
1028 |
> |
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
1029 |
|
// Set variables for UAE memory mapping |
1030 |
|
MacFrameBaseHost = the_buffer; |
1031 |
|
MacFrameSize = VideoMonitor.bytes_per_row * VideoMonitor.y; |
1035 |
|
MacFrameLayout = FLAYOUT_NONE; |
1036 |
|
#endif |
1037 |
|
|
1038 |
+ |
#ifdef ENABLE_VOSF |
1039 |
+ |
if (use_vosf) { |
1040 |
+ |
// Initialize the mainBuffer structure |
1041 |
+ |
if (!VideoInitBuffer()) { |
1042 |
+ |
// TODO: STR_VOSF_INIT_ERR ? |
1043 |
+ |
ErrorAlert("Could not initialize Video on SEGV signals"); |
1044 |
+ |
return false; |
1045 |
+ |
} |
1046 |
+ |
|
1047 |
+ |
// Initialize the handler for SIGSEGV |
1048 |
+ |
if (!Screen_fault_handler_init()) { |
1049 |
+ |
// TODO: STR_VOSF_INIT_ERR ? |
1050 |
+ |
ErrorAlert("Could not initialize Video on SEGV signals"); |
1051 |
+ |
return false; |
1052 |
+ |
} |
1053 |
+ |
} |
1054 |
+ |
#endif |
1055 |
+ |
|
1056 |
+ |
// Initialize VideoRefresh function |
1057 |
+ |
VideoRefreshInit(); |
1058 |
+ |
|
1059 |
|
XSync(x_display, false); |
1060 |
|
|
1061 |
|
#ifdef HAVE_PTHREADS |
1124 |
|
XFreeColormap(x_display, cmap[0]); |
1125 |
|
XFreeColormap(x_display, cmap[1]); |
1126 |
|
} |
1127 |
+ |
|
1128 |
+ |
if (!use_vosf) { |
1129 |
+ |
if (the_buffer) { |
1130 |
+ |
free(the_buffer); |
1131 |
+ |
the_buffer = NULL; |
1132 |
+ |
} |
1133 |
|
|
1134 |
< |
if (the_buffer) { |
1135 |
< |
free(the_buffer); |
1136 |
< |
the_buffer = NULL; |
1134 |
> |
if (!have_shm && the_buffer_copy) { |
1135 |
> |
free(the_buffer_copy); |
1136 |
> |
the_buffer_copy = NULL; |
1137 |
> |
} |
1138 |
> |
} |
1139 |
> |
#ifdef ENABLE_VOSF |
1140 |
> |
else { |
1141 |
> |
if (the_buffer != (uint8 *)MAP_FAILED) { |
1142 |
> |
munmap((caddr_t)the_buffer, the_buffer_size); |
1143 |
> |
the_buffer = 0; |
1144 |
> |
} |
1145 |
> |
|
1146 |
> |
if (the_buffer_copy != (uint8 *)MAP_FAILED) { |
1147 |
> |
munmap((caddr_t)the_buffer_copy, the_buffer_size); |
1148 |
> |
the_buffer_copy = 0; |
1149 |
> |
} |
1150 |
> |
} |
1151 |
> |
#endif |
1152 |
> |
} |
1153 |
> |
|
1154 |
> |
#ifdef ENABLE_VOSF |
1155 |
> |
if (use_vosf) { |
1156 |
> |
// Clear mainBuffer data |
1157 |
> |
if (mainBuffer.pageInfo) { |
1158 |
> |
free(mainBuffer.pageInfo); |
1159 |
> |
mainBuffer.pageInfo = 0; |
1160 |
|
} |
1161 |
|
|
1162 |
< |
if (!have_shm && the_buffer_copy) { |
1163 |
< |
free(the_buffer_copy); |
1164 |
< |
the_buffer_copy = NULL; |
1162 |
> |
if (mainBuffer.dirtyPages) { |
1163 |
> |
free(mainBuffer.dirtyPages); |
1164 |
> |
mainBuffer.dirtyPages = 0; |
1165 |
|
} |
1166 |
|
} |
1167 |
+ |
|
1168 |
+ |
// Close /dev/zero |
1169 |
+ |
if (zero_fd > 0) |
1170 |
+ |
close(zero_fd); |
1171 |
+ |
#endif |
1172 |
|
} |
1173 |
|
|
1174 |
|
|
1300 |
|
XF86DGASetViewPort(x_display, screen, 0, 0); |
1301 |
|
#endif |
1302 |
|
XSync(x_display, false); |
1303 |
< |
|
1303 |
> |
|
1304 |
> |
// the_buffer already contains the data to restore. i.e. since a temporary |
1305 |
> |
// frame buffer is used when VOSF is actually used, fb_save is therefore |
1306 |
> |
// not necessary. |
1307 |
> |
#ifdef ENABLE_VOSF |
1308 |
> |
if (use_vosf) { |
1309 |
> |
#ifdef HAVE_PTHREADS |
1310 |
> |
pthread_mutex_lock(&Screen_draw_lock); |
1311 |
> |
#endif |
1312 |
> |
PFLAG_SET_ALL; |
1313 |
> |
#ifdef HAVE_PTHREADS |
1314 |
> |
pthread_mutex_unlock(&Screen_draw_lock); |
1315 |
> |
#endif |
1316 |
> |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1317 |
> |
} |
1318 |
> |
#endif |
1319 |
> |
|
1320 |
|
// Restore frame buffer |
1321 |
|
if (fb_save) { |
1322 |
+ |
#ifdef ENABLE_VOSF |
1323 |
+ |
// Don't copy fb_save to the temporary frame buffer in VOSF mode |
1324 |
+ |
if (!use_vosf) |
1325 |
+ |
#endif |
1326 |
|
memcpy(the_buffer, fb_save, VideoMonitor.y * VideoMonitor.bytes_per_row); |
1327 |
|
free(fb_save); |
1328 |
|
fb_save = NULL; |
1604 |
|
// Hidden parts exposed, force complete refresh of window |
1605 |
|
case Expose: |
1606 |
|
if (display_type == DISPLAY_WINDOW) { |
1607 |
+ |
#ifdef ENABLE_VOSF |
1608 |
+ |
if (use_vosf) { // VOSF refresh |
1609 |
+ |
#ifdef HAVE_PTHREADS |
1610 |
+ |
pthread_mutex_lock(&Screen_draw_lock); |
1611 |
+ |
#endif |
1612 |
+ |
PFLAG_SET_ALL; |
1613 |
+ |
#ifdef HAVE_PTHREADS |
1614 |
+ |
pthread_mutex_unlock(&Screen_draw_lock); |
1615 |
+ |
#endif |
1616 |
+ |
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1617 |
+ |
} |
1618 |
+ |
else |
1619 |
+ |
#endif |
1620 |
|
if (frame_skip == 0) { // Dynamic refresh |
1621 |
|
int x1, y1; |
1622 |
|
for (y1=0; y1<16; y1++) |
1623 |
|
for (x1=0; x1<16; x1++) |
1624 |
|
updt_box[x1][y1] = true; |
1625 |
|
nr_boxes = 16 * 16; |
1626 |
< |
} else |
1626 |
> |
} else // Static refresh |
1627 |
|
memset(the_buffer_copy, 0, VideoMonitor.bytes_per_row * VideoMonitor.y); |
1628 |
|
} |
1629 |
|
break; |
1755 |
|
// Check for first column from left and first column from right that have changed |
1756 |
|
if (high) { |
1757 |
|
if (depth == 1) { |
1758 |
< |
x1 = VideoMonitor.x; |
1758 |
> |
x1 = VideoMonitor.x - 1; |
1759 |
|
for (j=y1; j<=y2; j++) { |
1760 |
|
p = &the_buffer[j * bytes_per_row]; |
1761 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1776 |
|
for (i=(VideoMonitor.x>>3); i>(x2>>3); i--) { |
1777 |
|
p--; p2--; |
1778 |
|
if (*p != *p2) { |
1779 |
< |
x2 = i << 3; |
1779 |
> |
x2 = (i << 3) + 7; |
1780 |
|
break; |
1781 |
|
} |
1782 |
|
} |
1783 |
|
} |
1784 |
< |
wide = x2 - x1; |
1784 |
> |
wide = x2 - x1 + 1; |
1785 |
|
|
1786 |
|
// Update copy of the_buffer |
1787 |
|
if (high && wide) { |
1842 |
|
|
1843 |
|
|
1844 |
|
/* |
1845 |
+ |
* Screen refresh functions |
1846 |
+ |
*/ |
1847 |
+ |
|
1848 |
+ |
// The specialisations hereunder are meant to enable VOSF with DGA in direct |
1849 |
+ |
// addressing mode in case the address spaces (RAM, ROM, FrameBuffer) could |
1850 |
+ |
// not get mapped correctly with respect to the predetermined host frame |
1851 |
+ |
// buffer base address. |
1852 |
+ |
// |
1853 |
+ |
// Hmm, in other words, when in direct addressing mode and DGA is requested, |
1854 |
+ |
// we first try to "triple allocate" the address spaces according to the real |
1855 |
+ |
// host frame buffer address. Then, if it fails, we will use a temporary |
1856 |
+ |
// frame buffer thus making the real host frame buffer updated when pages |
1857 |
+ |
// of the temp frame buffer are altered. |
1858 |
+ |
// |
1859 |
+ |
// As a side effect, a little speed gain in screen updates could be noticed |
1860 |
+ |
// for other modes than DGA. |
1861 |
+ |
// |
1862 |
+ |
// The following two functions below are inline so that a clever compiler |
1863 |
+ |
// could specialise the code according to the current screen depth and |
1864 |
+ |
// display type. A more clever compiler would the job by itself though... |
1865 |
+ |
// (update_display_vosf is inlined as well) |
1866 |
+ |
|
1867 |
+ |
static inline void possibly_quit_dga_mode() |
1868 |
+ |
{ |
1869 |
+ |
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
1870 |
+ |
// Quit DGA mode if requested |
1871 |
+ |
if (quit_full_screen) { |
1872 |
+ |
quit_full_screen = false; |
1873 |
+ |
#ifdef ENABLE_XF86_DGA |
1874 |
+ |
XF86DGADirectVideo(x_display, screen, 0); |
1875 |
+ |
#endif |
1876 |
+ |
XUngrabPointer(x_display, CurrentTime); |
1877 |
+ |
XUngrabKeyboard(x_display, CurrentTime); |
1878 |
+ |
XUnmapWindow(x_display, the_win); |
1879 |
+ |
XSync(x_display, false); |
1880 |
+ |
} |
1881 |
+ |
#endif |
1882 |
+ |
} |
1883 |
+ |
|
1884 |
+ |
static inline void handle_palette_changes(int depth, int display_type) |
1885 |
+ |
{ |
1886 |
+ |
#ifdef HAVE_PTHREADS |
1887 |
+ |
pthread_mutex_lock(&palette_lock); |
1888 |
+ |
#endif |
1889 |
+ |
if (palette_changed) { |
1890 |
+ |
palette_changed = false; |
1891 |
+ |
if (depth == 8) { |
1892 |
+ |
XStoreColors(x_display, cmap[0], palette, 256); |
1893 |
+ |
XStoreColors(x_display, cmap[1], palette, 256); |
1894 |
+ |
|
1895 |
+ |
#ifdef ENABLE_XF86_DGA |
1896 |
+ |
if (display_type == DISPLAY_DGA) { |
1897 |
+ |
current_dga_cmap ^= 1; |
1898 |
+ |
XF86DGAInstallColormap(x_display, screen, cmap[current_dga_cmap]); |
1899 |
+ |
} |
1900 |
+ |
#endif |
1901 |
+ |
} |
1902 |
+ |
} |
1903 |
+ |
#ifdef HAVE_PTHREADS |
1904 |
+ |
pthread_mutex_unlock(&palette_lock); |
1905 |
+ |
#endif |
1906 |
+ |
} |
1907 |
+ |
|
1908 |
+ |
static void video_refresh_dga(void) |
1909 |
+ |
{ |
1910 |
+ |
// Quit DGA mode if requested |
1911 |
+ |
possibly_quit_dga_mode(); |
1912 |
+ |
|
1913 |
+ |
// Handle X events |
1914 |
+ |
handle_events(); |
1915 |
+ |
|
1916 |
+ |
// Handle palette changes |
1917 |
+ |
handle_palette_changes(depth, DISPLAY_DGA); |
1918 |
+ |
} |
1919 |
+ |
|
1920 |
+ |
#ifdef ENABLE_VOSF |
1921 |
+ |
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
1922 |
+ |
static void video_refresh_dga_vosf(void) |
1923 |
+ |
{ |
1924 |
+ |
// Quit DGA mode if requested |
1925 |
+ |
possibly_quit_dga_mode(); |
1926 |
+ |
|
1927 |
+ |
// Handle X events |
1928 |
+ |
handle_events(); |
1929 |
+ |
|
1930 |
+ |
// Handle palette changes |
1931 |
+ |
handle_palette_changes(depth, DISPLAY_DGA); |
1932 |
+ |
|
1933 |
+ |
// Update display (VOSF variant) |
1934 |
+ |
static int tick_counter = 0; |
1935 |
+ |
if (++tick_counter >= frame_skip) { |
1936 |
+ |
tick_counter = 0; |
1937 |
+ |
#ifdef HAVE_PTHREADS |
1938 |
+ |
pthread_mutex_lock(&Screen_draw_lock); |
1939 |
+ |
#endif |
1940 |
+ |
update_display_dga_vosf(); |
1941 |
+ |
#ifdef HAVE_PTHREADS |
1942 |
+ |
pthread_mutex_unlock(&Screen_draw_lock); |
1943 |
+ |
#endif |
1944 |
+ |
} |
1945 |
+ |
} |
1946 |
+ |
#endif |
1947 |
+ |
|
1948 |
+ |
static void video_refresh_window_vosf(void) |
1949 |
+ |
{ |
1950 |
+ |
// Quit DGA mode if requested |
1951 |
+ |
possibly_quit_dga_mode(); |
1952 |
+ |
|
1953 |
+ |
// Handle X events |
1954 |
+ |
handle_events(); |
1955 |
+ |
|
1956 |
+ |
// Handle palette changes |
1957 |
+ |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1958 |
+ |
|
1959 |
+ |
// Update display (VOSF variant) |
1960 |
+ |
static int tick_counter = 0; |
1961 |
+ |
if (++tick_counter >= frame_skip) { |
1962 |
+ |
tick_counter = 0; |
1963 |
+ |
#ifdef HAVE_PTHREADS |
1964 |
+ |
pthread_mutex_lock(&Screen_draw_lock); |
1965 |
+ |
#endif |
1966 |
+ |
update_display_window_vosf(); |
1967 |
+ |
#ifdef HAVE_PTHREADS |
1968 |
+ |
pthread_mutex_unlock(&Screen_draw_lock); |
1969 |
+ |
#endif |
1970 |
+ |
} |
1971 |
+ |
} |
1972 |
+ |
#endif // def ENABLE_VOSF |
1973 |
+ |
|
1974 |
+ |
static void video_refresh_window_static(void) |
1975 |
+ |
{ |
1976 |
+ |
// Handle X events |
1977 |
+ |
handle_events(); |
1978 |
+ |
|
1979 |
+ |
// Handle_palette changes |
1980 |
+ |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1981 |
+ |
|
1982 |
+ |
// Update display (static variant) |
1983 |
+ |
static int tick_counter = 0; |
1984 |
+ |
if (++tick_counter >= frame_skip) { |
1985 |
+ |
tick_counter = 0; |
1986 |
+ |
update_display_static(); |
1987 |
+ |
} |
1988 |
+ |
} |
1989 |
+ |
|
1990 |
+ |
static void video_refresh_window_dynamic(void) |
1991 |
+ |
{ |
1992 |
+ |
// Handle X events |
1993 |
+ |
handle_events(); |
1994 |
+ |
|
1995 |
+ |
// Handle_palette changes |
1996 |
+ |
handle_palette_changes(depth, DISPLAY_WINDOW); |
1997 |
+ |
|
1998 |
+ |
// Update display (dynamic variant) |
1999 |
+ |
static int tick_counter = 0; |
2000 |
+ |
tick_counter++; |
2001 |
+ |
update_display_dynamic(tick_counter); |
2002 |
+ |
} |
2003 |
+ |
|
2004 |
+ |
|
2005 |
+ |
/* |
2006 |
|
* Thread for screen refresh, input handling etc. |
2007 |
|
*/ |
2008 |
|
|
2009 |
+ |
void VideoRefreshInit(void) |
2010 |
+ |
{ |
2011 |
+ |
// TODO: set up specialised 8bpp VideoRefresh handlers ? |
2012 |
+ |
if (display_type == DISPLAY_DGA) { |
2013 |
+ |
#if ENABLE_VOSF && (REAL_ADDRESSING || DIRECT_ADDRESSING) |
2014 |
+ |
if (use_vosf) |
2015 |
+ |
video_refresh = video_refresh_dga_vosf; |
2016 |
+ |
else |
2017 |
+ |
#endif |
2018 |
+ |
video_refresh = video_refresh_dga; |
2019 |
+ |
} |
2020 |
+ |
else { |
2021 |
+ |
#ifdef ENABLE_VOSF |
2022 |
+ |
if (use_vosf) |
2023 |
+ |
video_refresh = video_refresh_window_vosf; |
2024 |
+ |
else |
2025 |
+ |
#endif |
2026 |
+ |
if (frame_skip == 0) |
2027 |
+ |
video_refresh = video_refresh_window_dynamic; |
2028 |
+ |
else |
2029 |
+ |
video_refresh = video_refresh_window_static; |
2030 |
+ |
} |
2031 |
+ |
} |
2032 |
+ |
|
2033 |
+ |
void VideoRefresh(void) |
2034 |
+ |
{ |
2035 |
+ |
// TODO: make main_unix/VideoRefresh call directly video_refresh() ? |
2036 |
+ |
video_refresh(); |
2037 |
+ |
} |
2038 |
+ |
|
2039 |
+ |
#if 0 |
2040 |
|
void VideoRefresh(void) |
2041 |
|
{ |
2042 |
|
#if defined(ENABLE_XF86_DGA) || defined(ENABLE_FBDEV_DGA) |
2092 |
|
} |
2093 |
|
} |
2094 |
|
} |
2095 |
+ |
#endif |
2096 |
|
|
2097 |
|
#ifdef HAVE_PTHREADS |
2098 |
|
static void *redraw_func(void *arg) |
2099 |
|
{ |
2100 |
< |
uint64 start = GetTicks_usec(); |
2101 |
< |
int64 ticks = 0; |
2100 |
> |
uint64 start = GetTicks_usec(); |
2101 |
> |
int64 ticks = 0; |
2102 |
|
uint64 next = GetTicks_usec(); |
2103 |
|
while (!redraw_thread_cancel) { |
2104 |
< |
VideoRefresh(); |
2104 |
> |
// VideoRefresh(); |
2105 |
> |
video_refresh(); |
2106 |
|
next += 16667; |
2107 |
|
int64 delay = next - GetTicks_usec(); |
2108 |
|
if (delay > 0) |
2109 |
|
Delay_usec(delay); |
2110 |
|
else if (delay < -16667) |
2111 |
|
next = GetTicks_usec(); |
2112 |
< |
ticks++; |
2112 |
> |
ticks++; |
2113 |
|
} |
2114 |
< |
uint64 end = GetTicks_usec(); |
2115 |
< |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks); |
2114 |
> |
uint64 end = GetTicks_usec(); |
2115 |
> |
printf("%Ld ticks in %Ld usec = %Ld ticks/sec\n", ticks, end - start, (end - start) / ticks); |
2116 |
|
return NULL; |
2117 |
|
} |
2118 |
|
#endif |