1 |
|
/* |
2 |
|
* video_vosf.h - Video/graphics emulation, video on SEGV signals support |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-2001 Christian Bauer |
4 |
> |
* Basilisk II (C) 1997-2002 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 |
21 |
|
#ifndef VIDEO_VOSF_H |
22 |
|
#define VIDEO_VOSF_H |
23 |
|
|
24 |
< |
// Note: this file is #include'd in video_x.cpp |
24 |
> |
// Note: this file must be #include'd only in video_x.cpp |
25 |
|
#ifdef ENABLE_VOSF |
26 |
|
|
27 |
< |
/* |
28 |
< |
* Page-aligned memory allocation |
29 |
< |
*/ |
27 |
> |
#include <fcntl.h> |
28 |
> |
#include <sys/mman.h> |
29 |
> |
#include "sigsegv.h" |
30 |
> |
#include "vm_alloc.h" |
31 |
> |
|
32 |
> |
// Glue for SheepShaver and BasiliskII |
33 |
> |
#if POWERPC_ROM |
34 |
> |
#define X11_MONITOR_INIT /* nothing */ |
35 |
> |
#define VIDEO_DRV_INIT /* nothing */ |
36 |
> |
#define VIDEO_DRV_WINDOW the_win |
37 |
> |
#define VIDEO_DRV_GC the_gc |
38 |
> |
#define VIDEO_DRV_IMAGE img |
39 |
> |
#define VIDEO_DRV_HAVE_SHM have_shm |
40 |
> |
#define VIDEO_MODE_INIT VideoInfo const & mode = VModes[cur_mode] |
41 |
> |
#define VIDEO_MODE_ROW_BYTES mode.viRowBytes |
42 |
> |
#define VIDEO_MODE_X mode.viXsize |
43 |
> |
#define VIDEO_MODE_Y mode.viYsize |
44 |
> |
#define VIDEO_MODE_DEPTH mode.viAppleMode |
45 |
> |
enum { |
46 |
> |
VIDEO_DEPTH_1BIT = APPLE_1_BIT, |
47 |
> |
VIDEO_DEPTH_2BIT = APPLE_2_BIT, |
48 |
> |
VIDEO_DEPTH_4BIT = APPLE_4_BIT, |
49 |
> |
VIDEO_DEPTH_8BIT = APPLE_8_BIT, |
50 |
> |
VIDEO_DEPTH_16BIT = APPLE_16_BIT, |
51 |
> |
VIDEO_DEPTH_32BIT = APPLE_32_BIT |
52 |
> |
}; |
53 |
> |
#else |
54 |
> |
#define X11_MONITOR_INIT X11_monitor_desc &monitor |
55 |
> |
#define VIDEO_DRV_INIT driver_window *drv |
56 |
> |
#define VIDEO_DRV_WINDOW drv->w |
57 |
> |
#define VIDEO_DRV_GC drv->gc |
58 |
> |
#define VIDEO_DRV_IMAGE drv->img |
59 |
> |
#define VIDEO_DRV_HAVE_SHM drv->have_shm |
60 |
> |
#define VIDEO_MODE_INIT video_mode const & mode = drv->monitor.get_current_mode(); |
61 |
> |
#define VIDEO_MODE_ROW_BYTES mode.bytes_per_row |
62 |
> |
#define VIDEO_MODE_X mode.x |
63 |
> |
#define VIDEO_MODE_Y mode.y |
64 |
> |
#define VIDEO_MODE_DEPTH (int)mode.depth |
65 |
> |
enum { |
66 |
> |
VIDEO_DEPTH_1BIT = VDEPTH_1BIT, |
67 |
> |
VIDEO_DEPTH_2BIT = VDEPTH_2BIT, |
68 |
> |
VIDEO_DEPTH_4BIT = VDEPTH_4BIT, |
69 |
> |
VIDEO_DEPTH_8BIT = VDEPTH_8BIT, |
70 |
> |
VIDEO_DEPTH_16BIT = VDEPTH_16BIT, |
71 |
> |
VIDEO_DEPTH_32BIT = VDEPTH_32BIT |
72 |
> |
}; |
73 |
> |
#endif |
74 |
|
|
75 |
< |
// Align on page boundaries |
76 |
< |
static uintptr align_on_page_boundary(uintptr size) |
77 |
< |
{ |
78 |
< |
const uint32 page_size = getpagesize(); |
79 |
< |
const uint32 page_mask = page_size - 1; |
80 |
< |
return (size + page_mask) & ~page_mask; |
75 |
> |
// Variables for Video on SEGV support |
76 |
> |
static uint8 *the_host_buffer; // Host frame buffer in VOSF mode |
77 |
> |
|
78 |
> |
struct ScreenPageInfo { |
79 |
> |
int top, bottom; // Mapping between this virtual page and Mac scanlines |
80 |
> |
}; |
81 |
> |
|
82 |
> |
struct ScreenInfo { |
83 |
> |
uintptr memStart; // Start address aligned to page boundary |
84 |
> |
uint32 memLength; // Length of the memory addressed by the screen pages |
85 |
> |
|
86 |
> |
uintptr pageSize; // Size of a page |
87 |
> |
int pageBits; // Shift count to get the page number |
88 |
> |
uint32 pageCount; // Number of pages allocated to the screen |
89 |
> |
|
90 |
> |
bool dirty; // Flag: set if the frame buffer was touched |
91 |
> |
char * dirtyPages; // Table of flags set if page was altered |
92 |
> |
ScreenPageInfo * pageInfo; // Table of mappings page -> Mac scanlines |
93 |
> |
}; |
94 |
> |
|
95 |
> |
static ScreenInfo mainBuffer; |
96 |
> |
|
97 |
> |
#define PFLAG_SET_VALUE 0x00 |
98 |
> |
#define PFLAG_CLEAR_VALUE 0x01 |
99 |
> |
#define PFLAG_SET_VALUE_4 0x00000000 |
100 |
> |
#define PFLAG_CLEAR_VALUE_4 0x01010101 |
101 |
> |
#define PFLAG_SET(page) mainBuffer.dirtyPages[page] = PFLAG_SET_VALUE |
102 |
> |
#define PFLAG_CLEAR(page) mainBuffer.dirtyPages[page] = PFLAG_CLEAR_VALUE |
103 |
> |
#define PFLAG_ISSET(page) (mainBuffer.dirtyPages[page] == PFLAG_SET_VALUE) |
104 |
> |
#define PFLAG_ISCLEAR(page) (mainBuffer.dirtyPages[page] != PFLAG_SET_VALUE) |
105 |
> |
|
106 |
> |
#ifdef UNALIGNED_PROFITABLE |
107 |
> |
# define PFLAG_ISSET_4(page) (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_SET_VALUE_4) |
108 |
> |
# define PFLAG_ISCLEAR_4(page) (*((uint32 *)(mainBuffer.dirtyPages + (page))) == PFLAG_CLEAR_VALUE_4) |
109 |
> |
#else |
110 |
> |
# define PFLAG_ISSET_4(page) \ |
111 |
> |
PFLAG_ISSET(page ) && PFLAG_ISSET(page+1) \ |
112 |
> |
&& PFLAG_ISSET(page+2) && PFLAG_ISSET(page+3) |
113 |
> |
# define PFLAG_ISCLEAR_4(page) \ |
114 |
> |
PFLAG_ISCLEAR(page ) && PFLAG_ISCLEAR(page+1) \ |
115 |
> |
&& PFLAG_ISCLEAR(page+2) && PFLAG_ISCLEAR(page+3) |
116 |
> |
#endif |
117 |
> |
|
118 |
> |
// Set the selected page range [ first_page, last_page [ into the SET state |
119 |
> |
#define PFLAG_SET_RANGE(first_page, last_page) \ |
120 |
> |
memset(mainBuffer.dirtyPages + (first_page), PFLAG_SET_VALUE, \ |
121 |
> |
(last_page) - (first_page)) |
122 |
> |
|
123 |
> |
// Set the selected page range [ first_page, last_page [ into the CLEAR state |
124 |
> |
#define PFLAG_CLEAR_RANGE(first_page, last_page) \ |
125 |
> |
memset(mainBuffer.dirtyPages + (first_page), PFLAG_CLEAR_VALUE, \ |
126 |
> |
(last_page) - (first_page)) |
127 |
> |
|
128 |
> |
#define PFLAG_SET_ALL do { \ |
129 |
> |
PFLAG_SET_RANGE(0, mainBuffer.pageCount); \ |
130 |
> |
mainBuffer.dirty = true; \ |
131 |
> |
} while (0) |
132 |
> |
|
133 |
> |
#define PFLAG_CLEAR_ALL do { \ |
134 |
> |
PFLAG_CLEAR_RANGE(0, mainBuffer.pageCount); \ |
135 |
> |
mainBuffer.dirty = false; \ |
136 |
> |
} while (0) |
137 |
> |
|
138 |
> |
// Set the following macro definition to 1 if your system |
139 |
> |
// provides a really fast strchr() implementation |
140 |
> |
//#define HAVE_FAST_STRCHR 0 |
141 |
> |
|
142 |
> |
static inline int find_next_page_set(int page) |
143 |
> |
{ |
144 |
> |
#if HAVE_FAST_STRCHR |
145 |
> |
char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_SET_VALUE); |
146 |
> |
return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount; |
147 |
> |
#else |
148 |
> |
while (PFLAG_ISCLEAR_4(page)) |
149 |
> |
page += 4; |
150 |
> |
while (PFLAG_ISCLEAR(page)) |
151 |
> |
page++; |
152 |
> |
return page; |
153 |
> |
#endif |
154 |
|
} |
155 |
|
|
156 |
< |
// Allocate memory on page boundary |
40 |
< |
static void * allocate_framebuffer(uint32 size, uint8 * hint = 0) |
156 |
> |
static inline int find_next_page_clear(int page) |
157 |
|
{ |
158 |
< |
// Remind that the system can allocate at 0x00000000... |
159 |
< |
return mmap((caddr_t)hint, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, zero_fd, 0); |
158 |
> |
#if HAVE_FAST_STRCHR |
159 |
> |
char *match = strchr(mainBuffer.dirtyPages + page, PFLAG_CLEAR_VALUE); |
160 |
> |
return match ? match - mainBuffer.dirtyPages : mainBuffer.pageCount; |
161 |
> |
#else |
162 |
> |
while (PFLAG_ISSET_4(page)) |
163 |
> |
page += 4; |
164 |
> |
while (PFLAG_ISSET(page)) |
165 |
> |
page++; |
166 |
> |
return page; |
167 |
> |
#endif |
168 |
|
} |
169 |
|
|
170 |
+ |
#ifdef HAVE_SPINLOCKS |
171 |
+ |
static spinlock_t vosf_lock = SPIN_LOCK_UNLOCKED; // Mutex to protect frame buffer (dirtyPages in fact) |
172 |
+ |
#define LOCK_VOSF spin_lock(&vosf_lock) |
173 |
+ |
#define UNLOCK_VOSF spin_unlock(&vosf_lock) |
174 |
+ |
#elif defined(HAVE_PTHREADS) |
175 |
+ |
static pthread_mutex_t vosf_lock = PTHREAD_MUTEX_INITIALIZER; // Mutex to protect frame buffer (dirtyPages in fact) |
176 |
+ |
#define LOCK_VOSF pthread_mutex_lock(&vosf_lock); |
177 |
+ |
#define UNLOCK_VOSF pthread_mutex_unlock(&vosf_lock); |
178 |
+ |
#else |
179 |
+ |
#define LOCK_VOSF |
180 |
+ |
#define UNLOCK_VOSF |
181 |
+ |
#endif |
182 |
|
|
183 |
< |
/* |
48 |
< |
* Screen fault handler |
49 |
< |
*/ |
50 |
< |
|
51 |
< |
const uintptr INVALID_PC = (uintptr)-1; |
52 |
< |
|
53 |
< |
static inline void do_handle_screen_fault(uintptr addr, uintptr pc = INVALID_PC) |
183 |
> |
static int log_base_2(uint32 x) |
184 |
|
{ |
185 |
< |
/* Someone attempted to write to the frame buffer. Make it writeable |
186 |
< |
* now so that the data could actually be written. It will be made |
187 |
< |
* read-only back in one of the screen update_*() functions. |
188 |
< |
*/ |
189 |
< |
if ((addr >= mainBuffer.memStart) && (addr < mainBuffer.memEnd)) { |
60 |
< |
const int page = (addr - mainBuffer.memStart) >> mainBuffer.pageBits; |
61 |
< |
caddr_t page_ad = (caddr_t)(addr & ~(mainBuffer.pageSize - 1)); |
62 |
< |
LOCK_VOSF; |
63 |
< |
PFLAG_SET(page); |
64 |
< |
mprotect(page_ad, mainBuffer.pageSize, PROT_READ | PROT_WRITE); |
65 |
< |
mainBuffer.dirty = true; |
66 |
< |
UNLOCK_VOSF; |
67 |
< |
return; |
185 |
> |
uint32 mask = 0x80000000; |
186 |
> |
int l = 31; |
187 |
> |
while (l >= 0 && (x & mask) == 0) { |
188 |
> |
mask >>= 1; |
189 |
> |
l--; |
190 |
|
} |
191 |
< |
|
70 |
< |
/* Otherwise, we don't know how to handle the fault, let it crash */ |
71 |
< |
fprintf(stderr, "do_handle_screen_fault: unhandled address 0x%08X", addr); |
72 |
< |
if (pc != INVALID_PC) |
73 |
< |
fprintf(stderr, " [IP=0x%08X]", pc); |
74 |
< |
fprintf(stderr, "\n"); |
75 |
< |
|
76 |
< |
signal(SIGSEGV, SIG_DFL); |
191 |
> |
return l; |
192 |
|
} |
193 |
|
|
194 |
< |
#if defined(HAVE_SIGINFO_T) |
195 |
< |
|
81 |
< |
static void Screen_fault_handler(int, siginfo_t * sip, void *) |
194 |
> |
// Extend size to page boundary |
195 |
> |
static uint32 page_extend(uint32 size) |
196 |
|
{ |
197 |
< |
D(bug("Screen_fault_handler: ADDR=0x%08X\n", sip->si_addr)); |
198 |
< |
do_handle_screen_fault((uintptr)sip->si_addr); |
197 |
> |
const uint32 page_size = getpagesize(); |
198 |
> |
const uint32 page_mask = page_size - 1; |
199 |
> |
return (size + page_mask) & ~page_mask; |
200 |
|
} |
201 |
|
|
87 |
– |
#elif defined(HAVE_SIGCONTEXT_SUBTERFUGE) |
202 |
|
|
203 |
< |
# if defined(__i386__) && defined(__linux__) |
204 |
< |
static void Screen_fault_handler(int, struct sigcontext scs) |
205 |
< |
{ |
92 |
< |
D(bug("Screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", scs.cr2, scs.eip)); |
93 |
< |
do_handle_screen_fault((uintptr)scs.cr2, (uintptr)scs.eip); |
94 |
< |
} |
95 |
< |
|
96 |
< |
# elif defined(__m68k__) && defined(__NetBSD__) |
203 |
> |
/* |
204 |
> |
* Initialize the VOSF system (mainBuffer structure, SIGSEGV handler) |
205 |
> |
*/ |
206 |
|
|
207 |
< |
# include <m68k/frame.h> |
99 |
< |
static void Screen_fault_handler(int, int code, struct sigcontext *scp) |
207 |
> |
static bool video_vosf_init(X11_MONITOR_INIT) |
208 |
|
{ |
209 |
< |
D(bug("Screen_fault_handler: ADDR=0x%08X\n", code)); |
210 |
< |
struct sigstate { |
211 |
< |
int ss_flags; |
212 |
< |
struct frame ss_frame; |
213 |
< |
}; |
214 |
< |
struct sigstate *state = (struct sigstate *)scp->sc_ap; |
215 |
< |
uintptr fault_addr; |
216 |
< |
switch (state->ss_frame.f_format) { |
217 |
< |
case 7: // 68040 access error |
218 |
< |
// "code" is sometimes unreliable (i.e. contains NULL or a bogus address), reason unknown |
219 |
< |
fault_addr = state->ss_frame.f_fmt7.f_fa; |
220 |
< |
break; |
221 |
< |
default: |
222 |
< |
fault_addr = (uintptr)code; |
223 |
< |
break; |
209 |
> |
VIDEO_MODE_INIT; |
210 |
> |
|
211 |
> |
const uintptr page_size = getpagesize(); |
212 |
> |
const uintptr page_mask = page_size - 1; |
213 |
> |
|
214 |
> |
// Round up frame buffer base to page boundary |
215 |
> |
mainBuffer.memStart = (((uintptr) the_buffer) + page_mask) & ~page_mask; |
216 |
> |
|
217 |
> |
// The frame buffer size shall already be aligned to page boundary (use page_extend) |
218 |
> |
mainBuffer.memLength = the_buffer_size; |
219 |
> |
|
220 |
> |
mainBuffer.pageSize = page_size; |
221 |
> |
mainBuffer.pageBits = log_base_2(mainBuffer.pageSize); |
222 |
> |
mainBuffer.pageCount = (mainBuffer.memLength + page_mask)/mainBuffer.pageSize; |
223 |
> |
|
224 |
> |
// The "2" more bytes requested are a safety net to insure the |
225 |
> |
// loops in the update routines will terminate. |
226 |
> |
// See "How can we deal with array overrun conditions ?" hereunder for further details. |
227 |
> |
mainBuffer.dirtyPages = (char *) malloc(mainBuffer.pageCount + 2); |
228 |
> |
if (mainBuffer.dirtyPages == NULL) |
229 |
> |
return false; |
230 |
> |
|
231 |
> |
PFLAG_CLEAR_ALL; |
232 |
> |
PFLAG_CLEAR(mainBuffer.pageCount); |
233 |
> |
PFLAG_SET(mainBuffer.pageCount+1); |
234 |
> |
|
235 |
> |
// Allocate and fill in pageInfo with start and end (inclusive) row in number of bytes |
236 |
> |
mainBuffer.pageInfo = (ScreenPageInfo *) malloc(mainBuffer.pageCount * sizeof(ScreenPageInfo)); |
237 |
> |
if (mainBuffer.pageInfo == NULL) |
238 |
> |
return false; |
239 |
> |
|
240 |
> |
uint32 a = 0; |
241 |
> |
for (unsigned i = 0; i < mainBuffer.pageCount; i++) { |
242 |
> |
unsigned y1 = a / VIDEO_MODE_ROW_BYTES; |
243 |
> |
if (y1 >= VIDEO_MODE_Y) |
244 |
> |
y1 = VIDEO_MODE_Y - 1; |
245 |
> |
|
246 |
> |
unsigned y2 = (a + mainBuffer.pageSize) / VIDEO_MODE_ROW_BYTES; |
247 |
> |
if (y2 >= VIDEO_MODE_Y) |
248 |
> |
y2 = VIDEO_MODE_Y - 1; |
249 |
> |
|
250 |
> |
mainBuffer.pageInfo[i].top = y1; |
251 |
> |
mainBuffer.pageInfo[i].bottom = y2; |
252 |
> |
|
253 |
> |
a += mainBuffer.pageSize; |
254 |
> |
if (a > mainBuffer.memLength) |
255 |
> |
a = mainBuffer.memLength; |
256 |
|
} |
257 |
< |
do_handle_screen_fault(fault_addr); |
257 |
> |
|
258 |
> |
// We can now write-protect the frame buffer |
259 |
> |
if (vm_protect((char *)mainBuffer.memStart, mainBuffer.memLength, VM_PAGE_READ) != 0) |
260 |
> |
return false; |
261 |
> |
|
262 |
> |
// The frame buffer is sane, i.e. there is no write to it yet |
263 |
> |
mainBuffer.dirty = false; |
264 |
> |
return true; |
265 |
|
} |
266 |
|
|
120 |
– |
# elif defined(__powerpc__) && defined(__linux__) |
267 |
|
|
268 |
< |
static void Screen_fault_handler(int, struct sigcontext_struct *scs) |
268 |
> |
/* |
269 |
> |
* Deinitialize VOSF system |
270 |
> |
*/ |
271 |
> |
|
272 |
> |
static void video_vosf_exit(void) |
273 |
|
{ |
274 |
< |
D(bug("Screen_fault_handler: ADDR=0x%08X from IP=0x%08X\n", scs->regs->dar, scs->regs->nip)); |
275 |
< |
do_handle_screen_fault((uintptr)scs->regs->dar, (uintptr)scs->regs->nip); |
274 |
> |
if (mainBuffer.pageInfo) { |
275 |
> |
free(mainBuffer.pageInfo); |
276 |
> |
mainBuffer.pageInfo = NULL; |
277 |
> |
} |
278 |
> |
if (mainBuffer.dirtyPages) { |
279 |
> |
free(mainBuffer.dirtyPages); |
280 |
> |
mainBuffer.dirtyPages = NULL; |
281 |
> |
} |
282 |
|
} |
283 |
|
|
128 |
– |
# else |
129 |
– |
# error "No suitable subterfuge for Video on SEGV signals" |
130 |
– |
# endif |
131 |
– |
#else |
132 |
– |
# error "Can't do Video on SEGV signals" |
133 |
– |
#endif |
134 |
– |
|
284 |
|
|
285 |
|
/* |
286 |
< |
* Screen fault handler initialization |
286 |
> |
* Screen fault handler |
287 |
|
*/ |
288 |
|
|
289 |
< |
#if defined(HAVE_SIGINFO_T) |
141 |
< |
static bool Screen_fault_handler_init() |
289 |
> |
bool Screen_fault_handler(sigsegv_address_t fault_address, sigsegv_address_t fault_instruction) |
290 |
|
{ |
291 |
< |
// Setup SIGSEGV handler to process writes to frame buffer |
292 |
< |
sigemptyset(&vosf_sa.sa_mask); |
293 |
< |
vosf_sa.sa_sigaction = Screen_fault_handler; |
294 |
< |
vosf_sa.sa_flags = SA_SIGINFO; |
295 |
< |
return (sigaction(SIGSEGV, &vosf_sa, NULL) == 0); |
296 |
< |
} |
297 |
< |
#elif defined(HAVE_SIGCONTEXT_SUBTERFUGE) |
298 |
< |
static bool Screen_fault_handler_init() |
299 |
< |
{ |
300 |
< |
// Setup SIGSEGV handler to process writes to frame buffer |
301 |
< |
sigemptyset(&vosf_sa.sa_mask); |
302 |
< |
vosf_sa.sa_handler = (void (*)(int)) Screen_fault_handler; |
303 |
< |
#if !EMULATED_68K && defined(__NetBSD__) |
304 |
< |
sigaddset(&vosf_sa.sa_mask, SIGALRM); |
305 |
< |
vosf_sa.sa_flags = SA_ONSTACK; |
306 |
< |
#else |
307 |
< |
vosf_sa.sa_flags = 0; |
308 |
< |
#endif |
161 |
< |
return (sigaction(SIGSEGV, &vosf_sa, NULL) == 0); |
291 |
> |
const uintptr addr = (uintptr)fault_address; |
292 |
> |
|
293 |
> |
/* Someone attempted to write to the frame buffer. Make it writeable |
294 |
> |
* now so that the data could actually be written to. It will be made |
295 |
> |
* read-only back in one of the screen update_*() functions. |
296 |
> |
*/ |
297 |
> |
if (((uintptr)addr - mainBuffer.memStart) < mainBuffer.memLength) { |
298 |
> |
const int page = ((uintptr)addr - mainBuffer.memStart) >> mainBuffer.pageBits; |
299 |
> |
LOCK_VOSF; |
300 |
> |
PFLAG_SET(page); |
301 |
> |
vm_protect((char *)(addr & -mainBuffer.pageSize), mainBuffer.pageSize, VM_PAGE_READ | VM_PAGE_WRITE); |
302 |
> |
mainBuffer.dirty = true; |
303 |
> |
UNLOCK_VOSF; |
304 |
> |
return true; |
305 |
> |
} |
306 |
> |
|
307 |
> |
/* Otherwise, we don't know how to handle the fault, let it crash */ |
308 |
> |
return false; |
309 |
|
} |
163 |
– |
#endif |
310 |
|
|
311 |
|
|
312 |
|
/* |
315 |
|
|
316 |
|
// From video_blit.cpp |
317 |
|
extern void (*Screen_blit)(uint8 * dest, const uint8 * source, uint32 length); |
318 |
< |
extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order); |
318 |
> |
extern bool Screen_blitter_init(XVisualInfo * visual_info, bool native_byte_order, int mac_depth); |
319 |
> |
extern uint32 ExpandMap[256]; |
320 |
|
|
321 |
|
/* How can we deal with array overrun conditions ? |
322 |
|
|
351 |
|
than pageCount. |
352 |
|
*/ |
353 |
|
|
354 |
< |
static inline void update_display_window_vosf(void) |
354 |
> |
static inline void update_display_window_vosf(VIDEO_DRV_INIT) |
355 |
|
{ |
356 |
+ |
VIDEO_MODE_INIT; |
357 |
+ |
|
358 |
|
int page = 0; |
359 |
|
for (;;) { |
360 |
< |
const int first_page = find_next_page_set(page); |
360 |
> |
const unsigned first_page = find_next_page_set(page); |
361 |
|
if (first_page >= mainBuffer.pageCount) |
362 |
|
break; |
363 |
|
|
367 |
|
// Make the dirty pages read-only again |
368 |
|
const int32 offset = first_page << mainBuffer.pageBits; |
369 |
|
const uint32 length = (page - first_page) << mainBuffer.pageBits; |
370 |
< |
mprotect((caddr_t)(mainBuffer.memStart + offset), length, PROT_READ); |
370 |
> |
vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); |
371 |
|
|
372 |
|
// There is at least one line to update |
373 |
|
const int y1 = mainBuffer.pageInfo[first_page].top; |
374 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
375 |
|
const int height = y2 - y1 + 1; |
376 |
|
|
377 |
< |
const int bytes_per_row = VideoMonitor.bytes_per_row; |
229 |
< |
const int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
230 |
< |
int i = y1 * bytes_per_row, j; |
231 |
< |
|
232 |
< |
if (depth == 1) { |
377 |
> |
if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
378 |
|
|
379 |
|
// Update the_host_buffer and copy of the_buffer |
380 |
+ |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
381 |
+ |
const int dst_bytes_per_row = VIDEO_DRV_IMAGE->bytes_per_line; |
382 |
+ |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
383 |
+ |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
384 |
|
for (j = y1; j <= y2; j++) { |
385 |
< |
Screen_blit(the_host_buffer + i, the_buffer + i, VideoMonitor.x >> 3); |
386 |
< |
i += bytes_per_row; |
385 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, VIDEO_MODE_X / pixels_per_byte); |
386 |
> |
i1 += src_bytes_per_row; |
387 |
> |
i2 += dst_bytes_per_row; |
388 |
|
} |
389 |
|
|
390 |
|
} else { |
391 |
|
|
392 |
|
// Update the_host_buffer and copy of the_buffer |
393 |
+ |
const int src_bytes_per_row = VIDEO_MODE_ROW_BYTES; |
394 |
+ |
const int dst_bytes_per_row = VIDEO_DRV_IMAGE->bytes_per_line; |
395 |
+ |
const int bytes_per_pixel = src_bytes_per_row / VIDEO_MODE_X; |
396 |
+ |
int i1 = y1 * src_bytes_per_row, i2 = y1 * dst_bytes_per_row, j; |
397 |
|
for (j = y1; j <= y2; j++) { |
398 |
< |
Screen_blit(the_host_buffer + i, the_buffer + i, bytes_per_pixel * VideoMonitor.x); |
399 |
< |
i += bytes_per_row; |
398 |
> |
Screen_blit(the_host_buffer + i2, the_buffer + i1, bytes_per_pixel * VIDEO_MODE_X); |
399 |
> |
i1 += src_bytes_per_row; |
400 |
> |
i2 += dst_bytes_per_row; |
401 |
|
} |
402 |
|
} |
403 |
|
|
404 |
< |
if (have_shm) |
405 |
< |
XShmPutImage(x_display, the_win, the_gc, img, 0, y1, 0, y1, VideoMonitor.x, height, 0); |
404 |
> |
if (VIDEO_DRV_HAVE_SHM) |
405 |
> |
XShmPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height, 0); |
406 |
|
else |
407 |
< |
XPutImage(x_display, the_win, the_gc, img, 0, y1, 0, y1, VideoMonitor.x, height); |
407 |
> |
XPutImage(x_display, VIDEO_DRV_WINDOW, VIDEO_DRV_GC, VIDEO_DRV_IMAGE, 0, y1, 0, y1, VIDEO_MODE_X, height); |
408 |
|
} |
254 |
– |
|
409 |
|
mainBuffer.dirty = false; |
410 |
|
} |
411 |
|
|
412 |
|
|
413 |
|
/* |
414 |
|
* Update display for DGA mode and VOSF |
415 |
< |
* (only in Direct Addressing mode) |
415 |
> |
* (only in Real or Direct Addressing mode) |
416 |
|
*/ |
417 |
|
|
418 |
|
#if REAL_ADDRESSING || DIRECT_ADDRESSING |
419 |
|
static inline void update_display_dga_vosf(void) |
420 |
|
{ |
421 |
+ |
VIDEO_MODE_INIT; |
422 |
+ |
|
423 |
|
int page = 0; |
424 |
|
for (;;) { |
425 |
< |
const int first_page = find_next_page_set(page); |
425 |
> |
const unsigned first_page = find_next_page_set(page); |
426 |
|
if (first_page >= mainBuffer.pageCount) |
427 |
|
break; |
428 |
|
|
432 |
|
// Make the dirty pages read-only again |
433 |
|
const int32 offset = first_page << mainBuffer.pageBits; |
434 |
|
const uint32 length = (page - first_page) << mainBuffer.pageBits; |
435 |
< |
mprotect((caddr_t)(mainBuffer.memStart + offset), length, PROT_READ); |
435 |
> |
vm_protect((char *)mainBuffer.memStart + offset, length, VM_PAGE_READ); |
436 |
|
|
437 |
|
// I am sure that y2 >= y1 and depth != 1 |
438 |
|
const int y1 = mainBuffer.pageInfo[first_page].top; |
439 |
|
const int y2 = mainBuffer.pageInfo[page - 1].bottom; |
440 |
|
|
441 |
< |
const int bytes_per_row = VideoMonitor.bytes_per_row; |
442 |
< |
const int bytes_per_pixel = VideoMonitor.bytes_per_row / VideoMonitor.x; |
441 |
> |
const int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
442 |
> |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
443 |
|
int i, j; |
444 |
|
|
445 |
|
// Check for first column from left and first column |
446 |
|
// from right that have changed |
447 |
< |
int x1 = VideoMonitor.x * bytes_per_pixel - 1; |
447 |
> |
int x1 = VIDEO_MODE_X * bytes_per_pixel - 1; |
448 |
|
for (j = y1; j <= y2; j++) { |
449 |
|
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
450 |
|
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
461 |
|
for (j = y2; j >= y1; j--) { |
462 |
|
uint8 * const p1 = &the_buffer[j * bytes_per_row]; |
463 |
|
uint8 * const p2 = &the_buffer_copy[j * bytes_per_row]; |
464 |
< |
for (i = VideoMonitor.x * bytes_per_pixel - 1; i > x2; i--) { |
464 |
> |
for (i = VIDEO_MODE_X * bytes_per_pixel - 1; i > x2; i--) { |
465 |
|
if (p1[i] != p2[i]) { |
466 |
|
x2 = i; |
467 |
|
break; |