43 |
|
#include <SDL_mutex.h> |
44 |
|
#include <SDL_thread.h> |
45 |
|
#include <errno.h> |
46 |
+ |
#include <vector> |
47 |
|
|
48 |
|
#include "cpu_emulation.h" |
49 |
|
#include "main.h" |
52 |
|
#include "prefs.h" |
53 |
|
#include "user_strings.h" |
54 |
|
#include "video.h" |
55 |
+ |
#include "video_defs.h" |
56 |
|
#include "video_blit.h" |
57 |
|
|
58 |
|
#define DEBUG 0 |
60 |
|
|
61 |
|
|
62 |
|
// Supported video modes |
63 |
< |
static vector<video_mode> VideoModes; |
63 |
> |
using std::vector; |
64 |
> |
static vector<VIDEO_MODE> VideoModes; |
65 |
|
|
66 |
|
// Display types |
67 |
+ |
#ifdef SHEEPSHAVER |
68 |
|
enum { |
69 |
< |
DISPLAY_WINDOW, // windowed display |
70 |
< |
DISPLAY_SCREEN // fullscreen display |
69 |
> |
DISPLAY_WINDOW = DIS_WINDOW, // windowed display |
70 |
> |
DISPLAY_SCREEN = DIS_SCREEN // fullscreen display |
71 |
|
}; |
72 |
+ |
extern int display_type; // See enum above |
73 |
+ |
#else |
74 |
+ |
enum { |
75 |
+ |
DISPLAY_WINDOW, // windowed display |
76 |
+ |
DISPLAY_SCREEN // fullscreen display |
77 |
+ |
}; |
78 |
+ |
static int display_type = DISPLAY_WINDOW; // See enum above |
79 |
+ |
#endif |
80 |
|
|
81 |
|
// Constants |
82 |
|
const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes"; |
87 |
|
static int16 mouse_wheel_mode; |
88 |
|
static int16 mouse_wheel_lines; |
89 |
|
|
78 |
– |
static int display_type = DISPLAY_WINDOW; // See enum above |
90 |
|
static uint8 *the_buffer = NULL; // Mac frame buffer (where MacOS draws into) |
91 |
|
static uint8 *the_buffer_copy = NULL; // Copy of Mac frame buffer (for refreshed modes) |
92 |
|
static uint32 the_buffer_size; // Size of allocated the_buffer |
141 |
|
|
142 |
|
|
143 |
|
/* |
144 |
+ |
* SheepShaver glue |
145 |
+ |
*/ |
146 |
+ |
|
147 |
+ |
#ifdef SHEEPSHAVER |
148 |
+ |
// Color depth modes type |
149 |
+ |
typedef int video_depth; |
150 |
+ |
|
151 |
+ |
// 1, 2, 4 and 8 bit depths use a color palette |
152 |
+ |
static inline bool IsDirectMode(VIDEO_MODE const & mode) |
153 |
+ |
{ |
154 |
+ |
return IsDirectMode(mode.viAppleMode); |
155 |
+ |
} |
156 |
+ |
|
157 |
+ |
// Abstract base class representing one (possibly virtual) monitor |
158 |
+ |
// ("monitor" = rectangular display with a contiguous frame buffer) |
159 |
+ |
class monitor_desc { |
160 |
+ |
public: |
161 |
+ |
monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) {} |
162 |
+ |
virtual ~monitor_desc() {} |
163 |
+ |
|
164 |
+ |
// Get current Mac frame buffer base address |
165 |
+ |
uint32 get_mac_frame_base(void) const {return screen_base;} |
166 |
+ |
|
167 |
+ |
// Set Mac frame buffer base address (called from switch_to_mode()) |
168 |
+ |
void set_mac_frame_base(uint32 base) {screen_base = base;} |
169 |
+ |
|
170 |
+ |
// Get current video mode |
171 |
+ |
const VIDEO_MODE &get_current_mode(void) const {return VModes[cur_mode];} |
172 |
+ |
|
173 |
+ |
// Called by the video driver to switch the video mode on this display |
174 |
+ |
// (must call set_mac_frame_base()) |
175 |
+ |
virtual void switch_to_current_mode(void) = 0; |
176 |
+ |
|
177 |
+ |
// Called by the video driver to set the color palette (in indexed modes) |
178 |
+ |
// or the gamma table (in direct modes) |
179 |
+ |
virtual void set_palette(uint8 *pal, int num) = 0; |
180 |
+ |
}; |
181 |
+ |
|
182 |
+ |
// Vector of pointers to available monitor descriptions, filled by VideoInit() |
183 |
+ |
static vector<monitor_desc *> VideoMonitors; |
184 |
+ |
|
185 |
+ |
// Find Apple mode matching best specified dimensions |
186 |
+ |
static int find_apple_resolution(int xsize, int ysize) |
187 |
+ |
{ |
188 |
+ |
int apple_id; |
189 |
+ |
if (xsize < 800) |
190 |
+ |
apple_id = APPLE_640x480; |
191 |
+ |
else if (xsize < 1024) |
192 |
+ |
apple_id = APPLE_800x600; |
193 |
+ |
else if (xsize < 1152) |
194 |
+ |
apple_id = APPLE_1024x768; |
195 |
+ |
else if (xsize < 1280) { |
196 |
+ |
if (ysize < 900) |
197 |
+ |
apple_id = APPLE_1152x768; |
198 |
+ |
else |
199 |
+ |
apple_id = APPLE_1152x900; |
200 |
+ |
} |
201 |
+ |
else if (xsize < 1600) |
202 |
+ |
apple_id = APPLE_1280x1024; |
203 |
+ |
else |
204 |
+ |
apple_id = APPLE_1600x1200; |
205 |
+ |
return apple_id; |
206 |
+ |
} |
207 |
+ |
|
208 |
+ |
// Set parameters to specified Apple mode |
209 |
+ |
static void set_apple_resolution(int apple_id, int &xsize, int &ysize) |
210 |
+ |
{ |
211 |
+ |
switch (apple_id) { |
212 |
+ |
case APPLE_640x480: |
213 |
+ |
xsize = 640; |
214 |
+ |
ysize = 480; |
215 |
+ |
break; |
216 |
+ |
case APPLE_800x600: |
217 |
+ |
xsize = 800; |
218 |
+ |
ysize = 600; |
219 |
+ |
break; |
220 |
+ |
case APPLE_1024x768: |
221 |
+ |
xsize = 1024; |
222 |
+ |
ysize = 768; |
223 |
+ |
break; |
224 |
+ |
case APPLE_1152x768: |
225 |
+ |
xsize = 1152; |
226 |
+ |
ysize = 768; |
227 |
+ |
break; |
228 |
+ |
case APPLE_1152x900: |
229 |
+ |
xsize = 1152; |
230 |
+ |
ysize = 900; |
231 |
+ |
break; |
232 |
+ |
case APPLE_1280x1024: |
233 |
+ |
xsize = 1280; |
234 |
+ |
ysize = 1024; |
235 |
+ |
break; |
236 |
+ |
case APPLE_1600x1200: |
237 |
+ |
xsize = 1600; |
238 |
+ |
ysize = 1200; |
239 |
+ |
break; |
240 |
+ |
default: |
241 |
+ |
abort(); |
242 |
+ |
} |
243 |
+ |
} |
244 |
+ |
|
245 |
+ |
// Match Apple mode matching best specified dimensions |
246 |
+ |
static int match_apple_resolution(int &xsize, int &ysize) |
247 |
+ |
{ |
248 |
+ |
int apple_id = find_apple_resolution(xsize, ysize); |
249 |
+ |
set_apple_resolution(apple_id, xsize, ysize); |
250 |
+ |
return apple_id; |
251 |
+ |
} |
252 |
+ |
|
253 |
+ |
// Display error alert |
254 |
+ |
static void ErrorAlert(int error) |
255 |
+ |
{ |
256 |
+ |
ErrorAlert(GetString(error)); |
257 |
+ |
} |
258 |
+ |
#endif |
259 |
+ |
|
260 |
+ |
|
261 |
+ |
/* |
262 |
|
* monitor_desc subclass for SDL display |
263 |
|
*/ |
264 |
|
|
265 |
|
class SDL_monitor_desc : public monitor_desc { |
266 |
|
public: |
267 |
< |
SDL_monitor_desc(const vector<video_mode> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
267 |
> |
SDL_monitor_desc(const vector<VIDEO_MODE> &available_modes, video_depth default_depth, uint32 default_id) : monitor_desc(available_modes, default_depth, default_id) {} |
268 |
|
~SDL_monitor_desc() {} |
269 |
|
|
270 |
|
virtual void switch_to_current_mode(void); |
279 |
|
* Utility functions |
280 |
|
*/ |
281 |
|
|
282 |
+ |
// Find palette size for given color depth |
283 |
+ |
static int palette_size(int mode) |
284 |
+ |
{ |
285 |
+ |
switch (mode) { |
286 |
+ |
case VIDEO_DEPTH_1BIT: return 2; |
287 |
+ |
case VIDEO_DEPTH_2BIT: return 4; |
288 |
+ |
case VIDEO_DEPTH_4BIT: return 16; |
289 |
+ |
case VIDEO_DEPTH_8BIT: return 256; |
290 |
+ |
case VIDEO_DEPTH_16BIT: return 32; |
291 |
+ |
case VIDEO_DEPTH_32BIT: return 256; |
292 |
+ |
default: return 0; |
293 |
+ |
} |
294 |
+ |
} |
295 |
+ |
|
296 |
+ |
// Return bytes per pixel for requested depth |
297 |
+ |
static inline int bytes_per_pixel(int depth) |
298 |
+ |
{ |
299 |
+ |
int bpp; |
300 |
+ |
switch (depth) { |
301 |
+ |
case 8: |
302 |
+ |
bpp = 1; |
303 |
+ |
break; |
304 |
+ |
case 15: case 16: |
305 |
+ |
bpp = 2; |
306 |
+ |
break; |
307 |
+ |
case 24: case 32: |
308 |
+ |
bpp = 4; |
309 |
+ |
break; |
310 |
+ |
default: |
311 |
+ |
abort(); |
312 |
+ |
} |
313 |
+ |
return bpp; |
314 |
+ |
} |
315 |
+ |
|
316 |
|
// Map video_mode depth ID to numerical depth value |
317 |
|
static int sdl_depth_of_video_depth(int video_depth) |
318 |
|
{ |
319 |
|
int depth = -1; |
320 |
|
switch (video_depth) { |
321 |
< |
case VDEPTH_1BIT: |
321 |
> |
case VIDEO_DEPTH_1BIT: |
322 |
|
depth = 1; |
323 |
|
break; |
324 |
< |
case VDEPTH_2BIT: |
324 |
> |
case VIDEO_DEPTH_2BIT: |
325 |
|
depth = 2; |
326 |
|
break; |
327 |
< |
case VDEPTH_4BIT: |
327 |
> |
case VIDEO_DEPTH_4BIT: |
328 |
|
depth = 4; |
329 |
|
break; |
330 |
< |
case VDEPTH_8BIT: |
330 |
> |
case VIDEO_DEPTH_8BIT: |
331 |
|
depth = 8; |
332 |
|
break; |
333 |
< |
case VDEPTH_16BIT: |
333 |
> |
case VIDEO_DEPTH_16BIT: |
334 |
|
depth = 16; |
335 |
|
break; |
336 |
< |
case VDEPTH_32BIT: |
336 |
> |
case VIDEO_DEPTH_32BIT: |
337 |
|
depth = 32; |
338 |
|
break; |
339 |
|
default: |
343 |
|
} |
344 |
|
|
345 |
|
// Add mode to list of supported modes |
346 |
< |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
346 |
> |
static void add_mode(int type, int width, int height, int resolution_id, int bytes_per_row, int depth) |
347 |
|
{ |
348 |
< |
video_mode mode; |
349 |
< |
mode.x = width; |
350 |
< |
mode.y = height; |
351 |
< |
mode.resolution_id = resolution_id; |
352 |
< |
mode.bytes_per_row = bytes_per_row; |
353 |
< |
mode.depth = depth; |
348 |
> |
VIDEO_MODE mode; |
349 |
> |
#ifdef SHEEPSHAVER |
350 |
> |
// Don't add 512x384 modes |
351 |
> |
if (width == 512 && height == 384) |
352 |
> |
return; |
353 |
> |
|
354 |
> |
// Recalculate dimensions to fit Apple modes |
355 |
> |
resolution_id = match_apple_resolution(width, height); |
356 |
> |
mode.viType = type; |
357 |
> |
#endif |
358 |
> |
VIDEO_MODE_X = width; |
359 |
> |
VIDEO_MODE_Y = height; |
360 |
> |
VIDEO_MODE_RESOLUTION = resolution_id; |
361 |
> |
VIDEO_MODE_ROW_BYTES = bytes_per_row; |
362 |
> |
VIDEO_MODE_DEPTH = depth; |
363 |
|
VideoModes.push_back(mode); |
364 |
|
} |
365 |
|
|
366 |
|
// Add standard list of windowed modes for given color depth |
367 |
< |
static void add_window_modes(video_depth depth) |
367 |
> |
static void add_window_modes(int depth) |
368 |
|
{ |
369 |
< |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
370 |
< |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
371 |
< |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
372 |
< |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
373 |
< |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
374 |
< |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
375 |
< |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
369 |
> |
video_depth vdepth = (video_depth)depth; |
370 |
> |
add_mode(DISPLAY_WINDOW, 512, 384, 0x80, TrivialBytesPerRow(512, vdepth), depth); |
371 |
> |
add_mode(DISPLAY_WINDOW, 640, 480, 0x81, TrivialBytesPerRow(640, vdepth), depth); |
372 |
> |
add_mode(DISPLAY_WINDOW, 800, 600, 0x82, TrivialBytesPerRow(800, vdepth), depth); |
373 |
> |
add_mode(DISPLAY_WINDOW, 1024, 768, 0x83, TrivialBytesPerRow(1024, vdepth), depth); |
374 |
> |
add_mode(DISPLAY_WINDOW, 1152, 870, 0x84, TrivialBytesPerRow(1152, vdepth), depth); |
375 |
> |
add_mode(DISPLAY_WINDOW, 1280, 1024, 0x85, TrivialBytesPerRow(1280, vdepth), depth); |
376 |
> |
add_mode(DISPLAY_WINDOW, 1600, 1200, 0x86, TrivialBytesPerRow(1600, vdepth), depth); |
377 |
|
} |
378 |
|
|
379 |
|
// Set Mac frame layout and base address (uses the_buffer/MacFrameBaseMac) |
380 |
< |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, video_depth depth, bool native_byte_order) |
380 |
> |
static void set_mac_frame_buffer(SDL_monitor_desc &monitor, int depth, bool native_byte_order) |
381 |
|
{ |
382 |
|
#if !REAL_ADDRESSING && !DIRECT_ADDRESSING |
383 |
|
int layout = FLAYOUT_DIRECT; |
384 |
< |
if (depth == VDEPTH_16BIT) |
384 |
> |
if (depth == VIDEO_DEPTH_16BIT) |
385 |
|
layout = (screen_depth == 15) ? FLAYOUT_HOST_555 : FLAYOUT_HOST_565; |
386 |
< |
else if (depth == VDEPTH_32BIT) |
386 |
> |
else if (depth == VIDEO_DEPTH_32BIT) |
387 |
|
layout = (screen_depth == 24) ? FLAYOUT_HOST_888 : FLAYOUT_DIRECT; |
388 |
|
if (native_byte_order) |
389 |
|
MacFrameLayout = layout; |
392 |
|
monitor.set_mac_frame_base(MacFrameBaseMac); |
393 |
|
|
394 |
|
// Set variables used by UAE memory banking |
395 |
< |
const video_mode &mode = monitor.get_current_mode(); |
395 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
396 |
|
MacFrameBaseHost = the_buffer; |
397 |
< |
MacFrameSize = mode.bytes_per_row * mode.y; |
397 |
> |
MacFrameSize = VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y; |
398 |
|
InitFrameBufferMapping(); |
399 |
|
#else |
400 |
|
monitor.set_mac_frame_base(Host2MacAddr(the_buffer)); |
443 |
|
|
444 |
|
public: |
445 |
|
SDL_monitor_desc &monitor; // Associated video monitor |
446 |
< |
const video_mode &mode; // Video mode handled by the driver |
446 |
> |
const VIDEO_MODE &mode; // Video mode handled by the driver |
447 |
|
|
448 |
|
bool init_ok; // Initialization succeeded (we can't use exceptions because of -fomit-frame-pointer) |
449 |
|
SDL_Surface *s; // The surface we draw into |
531 |
|
// Palette has changed |
532 |
|
void driver_base::update_palette(void) |
533 |
|
{ |
534 |
< |
const video_mode &mode = monitor.get_current_mode(); |
534 |
> |
const VIDEO_MODE &mode = monitor.get_current_mode(); |
535 |
|
|
536 |
< |
if (mode.depth <= VDEPTH_8BIT) |
536 |
> |
if (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT) |
537 |
|
SDL_SetPalette(s, SDL_PHYSPAL, sdl_palette, 0, 256); |
538 |
|
} |
539 |
|
|
556 |
|
driver_window::driver_window(SDL_monitor_desc &m) |
557 |
|
: driver_base(m), mouse_grabbed(false) |
558 |
|
{ |
559 |
< |
int width = mode.x, height = mode.y; |
559 |
> |
int width = VIDEO_MODE_X, height = VIDEO_MODE_Y; |
560 |
|
int aligned_width = (width + 15) & ~15; |
561 |
|
int aligned_height = (height + 15) & ~15; |
562 |
|
|
564 |
|
ADBSetRelMouseMode(mouse_grabbed); |
565 |
|
|
566 |
|
// Create surface |
567 |
< |
int depth = (mode.depth <= VDEPTH_8BIT ? 8 : screen_depth); |
567 |
> |
int depth = (VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth); |
568 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
569 |
|
return; |
570 |
|
|
597 |
|
visualFormat.Rmask = f->Rmask; |
598 |
|
visualFormat.Gmask = f->Gmask; |
599 |
|
visualFormat.Bmask = f->Bmask; |
600 |
< |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(mode.depth)); |
600 |
> |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
601 |
|
|
602 |
|
// Load gray ramp to 8->16/32 expand map |
603 |
|
if (!IsDirectMode(mode)) |
605 |
|
ExpandMap[i] = SDL_MapRGB(f, i, i, i); |
606 |
|
|
607 |
|
// Set frame buffer base |
608 |
< |
set_mac_frame_buffer(monitor, mode.depth, true); |
608 |
> |
set_mac_frame_buffer(monitor, VIDEO_MODE_DEPTH, true); |
609 |
|
|
610 |
|
// Everything went well |
611 |
|
init_ok = true; |
747 |
|
bool SDL_monitor_desc::video_open(void) |
748 |
|
{ |
749 |
|
D(bug("video_open()\n")); |
750 |
< |
const video_mode &mode = get_current_mode(); |
750 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
751 |
|
|
752 |
|
// Create display driver object of requested type |
753 |
|
switch (display_type) { |
789 |
|
return true; |
790 |
|
} |
791 |
|
|
792 |
+ |
#ifdef SHEEPSHAVER |
793 |
+ |
bool VideoInit(void) |
794 |
+ |
{ |
795 |
+ |
const bool classic = false; |
796 |
+ |
#else |
797 |
|
bool VideoInit(bool classic) |
798 |
|
{ |
799 |
+ |
#endif |
800 |
|
classic_mode = classic; |
801 |
|
|
802 |
|
#ifdef ENABLE_VOSF |
827 |
|
mode_str = PrefsFindString("screen"); |
828 |
|
|
829 |
|
// Determine display type and default dimensions |
830 |
< |
int default_width = 512, default_height = 384; |
830 |
> |
int default_width, default_height; |
831 |
> |
if (classic) { |
832 |
> |
default_width = 512; |
833 |
> |
default_height = 384; |
834 |
> |
} |
835 |
> |
else { |
836 |
> |
default_width = 640; |
837 |
> |
default_height = 480; |
838 |
> |
} |
839 |
|
display_type = DISPLAY_WINDOW; |
840 |
|
if (mode_str) { |
841 |
|
if (sscanf(mode_str, "win/%d/%d", &default_width, &default_height) == 2) |
856 |
|
|
857 |
|
// Mac screen depth follows X depth |
858 |
|
screen_depth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; |
859 |
< |
video_depth default_depth; |
859 |
> |
int default_depth; |
860 |
|
switch (screen_depth) { |
861 |
|
case 8: |
862 |
< |
default_depth = VDEPTH_8BIT; |
862 |
> |
default_depth = VIDEO_DEPTH_8BIT; |
863 |
|
break; |
864 |
|
case 15: case 16: |
865 |
< |
default_depth = VDEPTH_16BIT; |
865 |
> |
default_depth = VIDEO_DEPTH_16BIT; |
866 |
|
break; |
867 |
|
case 24: case 32: |
868 |
< |
default_depth = VDEPTH_32BIT; |
868 |
> |
default_depth = VIDEO_DEPTH_32BIT; |
869 |
|
break; |
870 |
|
default: |
871 |
< |
default_depth = VDEPTH_1BIT; |
871 |
> |
default_depth = VIDEO_DEPTH_1BIT; |
872 |
|
break; |
873 |
|
} |
874 |
|
|
875 |
|
// Construct list of supported modes |
876 |
|
if (display_type == DISPLAY_WINDOW) { |
877 |
|
if (classic) |
878 |
< |
add_mode(512, 342, 0x80, 64, VDEPTH_1BIT); |
878 |
> |
add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT); |
879 |
|
else { |
880 |
< |
for (int d = VDEPTH_1BIT; d <= default_depth; d++) { |
881 |
< |
int bpp = (d <= VDEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
880 |
> |
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) { |
881 |
> |
int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
882 |
|
if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE)) |
883 |
|
add_window_modes(video_depth(d)); |
884 |
|
} |
885 |
|
} |
886 |
|
} else |
887 |
< |
add_mode(default_width, default_height, 0x80, TrivialBytesPerRow(default_width, default_depth), default_depth); |
887 |
> |
add_mode(display_type, default_width, default_height, 0x80, TrivialBytesPerRow(default_width, (video_depth)default_depth), default_depth); |
888 |
|
if (VideoModes.empty()) { |
889 |
|
ErrorAlert(STR_NO_XVISUAL_ERR); |
890 |
|
return false; |
892 |
|
|
893 |
|
// Find requested default mode with specified dimensions |
894 |
|
uint32 default_id; |
895 |
< |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
895 |
> |
std::vector<VIDEO_MODE>::const_iterator i, end = VideoModes.end(); |
896 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
897 |
< |
if (i->x == default_width && i->y == default_height && i->depth == default_depth) { |
898 |
< |
default_id = i->resolution_id; |
897 |
> |
const VIDEO_MODE & mode = (*i); |
898 |
> |
if (VIDEO_MODE_X == default_width && VIDEO_MODE_Y == default_height && VIDEO_MODE_DEPTH == default_depth) { |
899 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
900 |
> |
#ifdef SHEEPSHAVER |
901 |
> |
std::vector<VIDEO_MODE>::const_iterator begin = VideoModes.begin(); |
902 |
> |
cur_mode = distance(begin, i); |
903 |
> |
#endif |
904 |
|
break; |
905 |
|
} |
906 |
|
} |
907 |
|
if (i == end) { // not found, use first available mode |
908 |
< |
default_depth = VideoModes[0].depth; |
909 |
< |
default_id = VideoModes[0].resolution_id; |
908 |
> |
const VIDEO_MODE & mode = VideoModes[0]; |
909 |
> |
default_depth = VIDEO_MODE_DEPTH; |
910 |
> |
default_id = VIDEO_MODE_RESOLUTION; |
911 |
> |
#ifdef SHEEPSHAVER |
912 |
> |
cur_mode = 0; |
913 |
> |
#endif |
914 |
|
} |
915 |
|
|
916 |
+ |
#ifdef SHEEPSHAVER |
917 |
+ |
for (int i = 0; i < VideoModes.size(); ++i) |
918 |
+ |
VModes[i] = VideoModes[i]; |
919 |
+ |
|
920 |
+ |
const VIDEO_MODE & mode = VideoModes[cur_mode]; |
921 |
+ |
D(bug("Current video mode\n")); |
922 |
+ |
D(bug(" %dx%d (ID %02x), %d bpp\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << (VIDEO_MODE_DEPTH - 0x80))); |
923 |
+ |
#endif |
924 |
+ |
|
925 |
|
#if DEBUG |
926 |
|
D(bug("Available video modes:\n")); |
927 |
|
for (i = VideoModes.begin(); i != end; ++i) { |
928 |
< |
int bits = 1 << i->depth; |
928 |
> |
const VIDEO_MODE & mode = (*i); |
929 |
> |
int bits = 1 << VIDEO_MODE_DEPTH; |
930 |
|
if (bits == 16) |
931 |
|
bits = 15; |
932 |
|
else if (bits == 32) |
933 |
|
bits = 24; |
934 |
< |
D(bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits)); |
934 |
> |
D(bug(" %dx%d (ID %02x), %d colors\n", VIDEO_MODE_X, VIDEO_MODE_Y, VIDEO_MODE_RESOLUTION, 1 << bits)); |
935 |
|
} |
936 |
|
#endif |
937 |
|
|
938 |
|
// Create SDL_monitor_desc for this (the only) display |
939 |
< |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, default_depth, default_id); |
939 |
> |
SDL_monitor_desc *monitor = new SDL_monitor_desc(VideoModes, (video_depth)default_depth, default_id); |
940 |
|
VideoMonitors.push_back(monitor); |
941 |
|
|
942 |
|
// Open display |
1006 |
|
* Mac VBL interrupt |
1007 |
|
*/ |
1008 |
|
|
1009 |
+ |
/* |
1010 |
+ |
* Execute video VBL routine |
1011 |
+ |
*/ |
1012 |
+ |
|
1013 |
+ |
#ifdef SHEEPSHAVER |
1014 |
+ |
void VideoVBL(void) |
1015 |
+ |
{ |
1016 |
+ |
// Emergency quit requested? Then quit |
1017 |
+ |
if (emerg_quit) |
1018 |
+ |
QuitEmulator(); |
1019 |
+ |
|
1020 |
+ |
// Temporarily give up frame buffer lock (this is the point where |
1021 |
+ |
// we are suspended when the user presses Ctrl-Tab) |
1022 |
+ |
UNLOCK_FRAME_BUFFER; |
1023 |
+ |
LOCK_FRAME_BUFFER; |
1024 |
+ |
|
1025 |
+ |
// Execute video VBL |
1026 |
+ |
if (private_data != NULL && private_data->interruptsEnabled) |
1027 |
+ |
VSLDoInterruptService(private_data->vslServiceID); |
1028 |
+ |
} |
1029 |
+ |
#else |
1030 |
|
void VideoInterrupt(void) |
1031 |
|
{ |
1032 |
|
// We must fill in the events queue in the same thread that did call SDL_SetVideoMode() |
1041 |
|
UNLOCK_FRAME_BUFFER; |
1042 |
|
LOCK_FRAME_BUFFER; |
1043 |
|
} |
1044 |
+ |
#endif |
1045 |
|
|
1046 |
|
|
1047 |
|
/* |
1048 |
|
* Set palette |
1049 |
|
*/ |
1050 |
|
|
1051 |
+ |
#ifdef SHEEPSHAVER |
1052 |
+ |
void video_set_palette(void) |
1053 |
+ |
{ |
1054 |
+ |
monitor_desc * monitor = VideoMonitors[0]; |
1055 |
+ |
int n_colors = palette_size(monitor->get_current_mode().viAppleMode); |
1056 |
+ |
uint8 pal[256 * 3]; |
1057 |
+ |
for (int c = 0; c < n_colors; c++) { |
1058 |
+ |
pal[c*3 + 0] = mac_pal[c].red; |
1059 |
+ |
pal[c*3 + 1] = mac_pal[c].green; |
1060 |
+ |
pal[c*3 + 2] = mac_pal[c].blue; |
1061 |
+ |
} |
1062 |
+ |
monitor->set_palette(pal, n_colors); |
1063 |
+ |
} |
1064 |
+ |
#endif |
1065 |
+ |
|
1066 |
|
void SDL_monitor_desc::set_palette(uint8 *pal, int num_in) |
1067 |
|
{ |
1068 |
< |
const video_mode &mode = get_current_mode(); |
1068 |
> |
const VIDEO_MODE &mode = get_current_mode(); |
1069 |
|
|
1070 |
|
// FIXME: how can we handle the gamma ramp? |
1071 |
< |
if (mode.depth > VDEPTH_8BIT) |
1071 |
> |
if (VIDEO_MODE_DEPTH > VIDEO_DEPTH_8BIT) |
1072 |
|
return; |
1073 |
|
|
1074 |
|
LOCK_PALETTE; |
1097 |
|
LOCK_VOSF; |
1098 |
|
PFLAG_SET_ALL; |
1099 |
|
UNLOCK_VOSF; |
1100 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1100 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1101 |
|
#endif |
1102 |
|
} |
1103 |
|
|
1112 |
|
* Switch video mode |
1113 |
|
*/ |
1114 |
|
|
1115 |
+ |
#ifdef SHEEPSHAVER |
1116 |
+ |
int16 video_mode_change(VidLocals *csSave, uint32 ParamPtr) |
1117 |
+ |
{ |
1118 |
+ |
/* return if no mode change */ |
1119 |
+ |
if ((csSave->saveData == ReadMacInt32(ParamPtr + csData)) && |
1120 |
+ |
(csSave->saveMode == ReadMacInt16(ParamPtr + csMode))) return noErr; |
1121 |
+ |
|
1122 |
+ |
/* first find video mode in table */ |
1123 |
+ |
for (int i=0; VModes[i].viType != DIS_INVALID; i++) { |
1124 |
+ |
if ((ReadMacInt16(ParamPtr + csMode) == VModes[i].viAppleMode) && |
1125 |
+ |
(ReadMacInt32(ParamPtr + csData) == VModes[i].viAppleID)) { |
1126 |
+ |
csSave->saveMode = ReadMacInt16(ParamPtr + csMode); |
1127 |
+ |
csSave->saveData = ReadMacInt32(ParamPtr + csData); |
1128 |
+ |
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
1129 |
+ |
|
1130 |
+ |
// Disable interrupts |
1131 |
+ |
DisableInterrupt(); |
1132 |
+ |
|
1133 |
+ |
cur_mode = i; |
1134 |
+ |
monitor_desc *monitor = VideoMonitors[0]; |
1135 |
+ |
monitor->switch_to_current_mode(); |
1136 |
+ |
|
1137 |
+ |
WriteMacInt32(ParamPtr + csBaseAddr, screen_base); |
1138 |
+ |
csSave->saveBaseAddr=screen_base; |
1139 |
+ |
csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */ |
1140 |
+ |
csSave->saveMode=VModes[cur_mode].viAppleMode; |
1141 |
+ |
|
1142 |
+ |
// Enable interrupts |
1143 |
+ |
EnableInterrupt(); |
1144 |
+ |
return noErr; |
1145 |
+ |
} |
1146 |
+ |
} |
1147 |
+ |
return paramErr; |
1148 |
+ |
} |
1149 |
+ |
#endif |
1150 |
+ |
|
1151 |
|
void SDL_monitor_desc::switch_to_current_mode(void) |
1152 |
|
{ |
1153 |
|
// Close and reopen display |
1162 |
|
|
1163 |
|
|
1164 |
|
/* |
1165 |
+ |
* Can we set the MacOS cursor image into the window? |
1166 |
+ |
*/ |
1167 |
+ |
|
1168 |
+ |
#ifdef SHEEPSHAVER |
1169 |
+ |
bool video_can_change_cursor(void) |
1170 |
+ |
{ |
1171 |
+ |
// return hw_mac_cursor_accl && (display_type != DISPLAY_SCREEN); |
1172 |
+ |
return false; |
1173 |
+ |
} |
1174 |
+ |
#endif |
1175 |
+ |
|
1176 |
+ |
|
1177 |
+ |
/* |
1178 |
+ |
* Set cursor image for window |
1179 |
+ |
*/ |
1180 |
+ |
|
1181 |
+ |
#ifdef SHEEPSHAVER |
1182 |
+ |
void video_set_cursor(void) |
1183 |
+ |
{ |
1184 |
+ |
// cursor_changed = true; |
1185 |
+ |
} |
1186 |
+ |
#endif |
1187 |
+ |
|
1188 |
+ |
|
1189 |
+ |
/* |
1190 |
+ |
* Install graphics acceleration |
1191 |
+ |
*/ |
1192 |
+ |
|
1193 |
+ |
#ifdef SHEEPSHAVER |
1194 |
+ |
// Rectangle inversion |
1195 |
+ |
template< int bpp > |
1196 |
+ |
static inline void do_invrect(uint8 *dest, uint32 length) |
1197 |
+ |
{ |
1198 |
+ |
#define INVERT_1(PTR, OFS) ((uint8 *)(PTR))[OFS] = ~((uint8 *)(PTR))[OFS] |
1199 |
+ |
#define INVERT_2(PTR, OFS) ((uint16 *)(PTR))[OFS] = ~((uint16 *)(PTR))[OFS] |
1200 |
+ |
#define INVERT_4(PTR, OFS) ((uint32 *)(PTR))[OFS] = ~((uint32 *)(PTR))[OFS] |
1201 |
+ |
#define INVERT_8(PTR, OFS) ((uint64 *)(PTR))[OFS] = ~((uint64 *)(PTR))[OFS] |
1202 |
+ |
|
1203 |
+ |
#ifndef UNALIGNED_PROFITABLE |
1204 |
+ |
// Align on 16-bit boundaries |
1205 |
+ |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1206 |
+ |
INVERT_1(dest, 0); |
1207 |
+ |
dest += 1; length -= 1; |
1208 |
+ |
} |
1209 |
+ |
|
1210 |
+ |
// Align on 32-bit boundaries |
1211 |
+ |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1212 |
+ |
INVERT_2(dest, 0); |
1213 |
+ |
dest += 2; length -= 2; |
1214 |
+ |
} |
1215 |
+ |
#endif |
1216 |
+ |
|
1217 |
+ |
// Invert 8-byte words |
1218 |
+ |
if (length >= 8) { |
1219 |
+ |
const int r = (length / 8) % 8; |
1220 |
+ |
dest += r * 8; |
1221 |
+ |
|
1222 |
+ |
int n = ((length / 8) + 7) / 8; |
1223 |
+ |
switch (r) { |
1224 |
+ |
case 0: do { |
1225 |
+ |
dest += 64; |
1226 |
+ |
INVERT_8(dest, -8); |
1227 |
+ |
case 7: INVERT_8(dest, -7); |
1228 |
+ |
case 6: INVERT_8(dest, -6); |
1229 |
+ |
case 5: INVERT_8(dest, -5); |
1230 |
+ |
case 4: INVERT_8(dest, -4); |
1231 |
+ |
case 3: INVERT_8(dest, -3); |
1232 |
+ |
case 2: INVERT_8(dest, -2); |
1233 |
+ |
case 1: INVERT_8(dest, -1); |
1234 |
+ |
} while (--n > 0); |
1235 |
+ |
} |
1236 |
+ |
} |
1237 |
+ |
|
1238 |
+ |
// 32-bit cell to invert? |
1239 |
+ |
if (length & 4) { |
1240 |
+ |
INVERT_4(dest, 0); |
1241 |
+ |
if (bpp <= 16) |
1242 |
+ |
dest += 4; |
1243 |
+ |
} |
1244 |
+ |
|
1245 |
+ |
// 16-bit cell to invert? |
1246 |
+ |
if (bpp <= 16 && (length & 2)) { |
1247 |
+ |
INVERT_2(dest, 0); |
1248 |
+ |
if (bpp <= 8) |
1249 |
+ |
dest += 2; |
1250 |
+ |
} |
1251 |
+ |
|
1252 |
+ |
// 8-bit cell to invert? |
1253 |
+ |
if (bpp <= 8 && (length & 1)) |
1254 |
+ |
INVERT_1(dest, 0); |
1255 |
+ |
|
1256 |
+ |
#undef INVERT_1 |
1257 |
+ |
#undef INVERT_2 |
1258 |
+ |
#undef INVERT_4 |
1259 |
+ |
#undef INVERT_8 |
1260 |
+ |
} |
1261 |
+ |
|
1262 |
+ |
void NQD_invrect(uint32 p) |
1263 |
+ |
{ |
1264 |
+ |
D(bug("accl_invrect %08x\n", p)); |
1265 |
+ |
|
1266 |
+ |
// Get inversion parameters |
1267 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1268 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1269 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1270 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1271 |
+ |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1272 |
+ |
D(bug(" width %d, height %d, bytes_per_row %d\n", width, height, (int32)ReadMacInt32(p + acclDestRowBytes))); |
1273 |
+ |
|
1274 |
+ |
//!!?? pen_mode == 14 |
1275 |
+ |
|
1276 |
+ |
// And perform the inversion |
1277 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1278 |
+ |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1279 |
+ |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1280 |
+ |
width *= bpp; |
1281 |
+ |
switch (bpp) { |
1282 |
+ |
case 1: |
1283 |
+ |
for (int i = 0; i < height; i++) { |
1284 |
+ |
do_invrect<8>(dest, width); |
1285 |
+ |
dest += dest_row_bytes; |
1286 |
+ |
} |
1287 |
+ |
break; |
1288 |
+ |
case 2: |
1289 |
+ |
for (int i = 0; i < height; i++) { |
1290 |
+ |
do_invrect<16>(dest, width); |
1291 |
+ |
dest += dest_row_bytes; |
1292 |
+ |
} |
1293 |
+ |
break; |
1294 |
+ |
case 4: |
1295 |
+ |
for (int i = 0; i < height; i++) { |
1296 |
+ |
do_invrect<32>(dest, width); |
1297 |
+ |
dest += dest_row_bytes; |
1298 |
+ |
} |
1299 |
+ |
break; |
1300 |
+ |
} |
1301 |
+ |
} |
1302 |
+ |
|
1303 |
+ |
// Rectangle filling |
1304 |
+ |
template< int bpp > |
1305 |
+ |
static inline void do_fillrect(uint8 *dest, uint32 color, uint32 length) |
1306 |
+ |
{ |
1307 |
+ |
#define FILL_1(PTR, OFS, VAL) ((uint8 *)(PTR))[OFS] = (VAL) |
1308 |
+ |
#define FILL_2(PTR, OFS, VAL) ((uint16 *)(PTR))[OFS] = (VAL) |
1309 |
+ |
#define FILL_4(PTR, OFS, VAL) ((uint32 *)(PTR))[OFS] = (VAL) |
1310 |
+ |
#define FILL_8(PTR, OFS, VAL) ((uint64 *)(PTR))[OFS] = (VAL) |
1311 |
+ |
|
1312 |
+ |
#ifndef UNALIGNED_PROFITABLE |
1313 |
+ |
// Align on 16-bit boundaries |
1314 |
+ |
if (bpp < 16 && (((uintptr)dest) & 1)) { |
1315 |
+ |
FILL_1(dest, 0, color); |
1316 |
+ |
dest += 1; length -= 1; |
1317 |
+ |
} |
1318 |
+ |
|
1319 |
+ |
// Align on 32-bit boundaries |
1320 |
+ |
if (bpp < 32 && (((uintptr)dest) & 2)) { |
1321 |
+ |
FILL_2(dest, 0, color); |
1322 |
+ |
dest += 2; length -= 2; |
1323 |
+ |
} |
1324 |
+ |
#endif |
1325 |
+ |
|
1326 |
+ |
// Fill 8-byte words |
1327 |
+ |
if (length >= 8) { |
1328 |
+ |
const uint64 c = (((uint64)color) << 32) | color; |
1329 |
+ |
const int r = (length / 8) % 8; |
1330 |
+ |
dest += r * 8; |
1331 |
+ |
|
1332 |
+ |
int n = ((length / 8) + 7) / 8; |
1333 |
+ |
switch (r) { |
1334 |
+ |
case 0: do { |
1335 |
+ |
dest += 64; |
1336 |
+ |
FILL_8(dest, -8, c); |
1337 |
+ |
case 7: FILL_8(dest, -7, c); |
1338 |
+ |
case 6: FILL_8(dest, -6, c); |
1339 |
+ |
case 5: FILL_8(dest, -5, c); |
1340 |
+ |
case 4: FILL_8(dest, -4, c); |
1341 |
+ |
case 3: FILL_8(dest, -3, c); |
1342 |
+ |
case 2: FILL_8(dest, -2, c); |
1343 |
+ |
case 1: FILL_8(dest, -1, c); |
1344 |
+ |
} while (--n > 0); |
1345 |
+ |
} |
1346 |
+ |
} |
1347 |
+ |
|
1348 |
+ |
// 32-bit cell to fill? |
1349 |
+ |
if (length & 4) { |
1350 |
+ |
FILL_4(dest, 0, color); |
1351 |
+ |
if (bpp <= 16) |
1352 |
+ |
dest += 4; |
1353 |
+ |
} |
1354 |
+ |
|
1355 |
+ |
// 16-bit cell to fill? |
1356 |
+ |
if (bpp <= 16 && (length & 2)) { |
1357 |
+ |
FILL_2(dest, 0, color); |
1358 |
+ |
if (bpp <= 8) |
1359 |
+ |
dest += 2; |
1360 |
+ |
} |
1361 |
+ |
|
1362 |
+ |
// 8-bit cell to fill? |
1363 |
+ |
if (bpp <= 8 && (length & 1)) |
1364 |
+ |
FILL_1(dest, 0, color); |
1365 |
+ |
|
1366 |
+ |
#undef FILL_1 |
1367 |
+ |
#undef FILL_2 |
1368 |
+ |
#undef FILL_4 |
1369 |
+ |
#undef FILL_8 |
1370 |
+ |
} |
1371 |
+ |
|
1372 |
+ |
void NQD_fillrect(uint32 p) |
1373 |
+ |
{ |
1374 |
+ |
D(bug("accl_fillrect %08x\n", p)); |
1375 |
+ |
|
1376 |
+ |
// Get filling parameters |
1377 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1378 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1379 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1380 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1381 |
+ |
uint32 color = htonl(ReadMacInt32(p + acclPenMode) == 8 ? ReadMacInt32(p + acclForePen) : ReadMacInt32(p + acclBackPen)); |
1382 |
+ |
D(bug(" dest X %d, dest Y %d\n", dest_X, dest_Y)); |
1383 |
+ |
D(bug(" width %d, height %d\n", width, height)); |
1384 |
+ |
D(bug(" bytes_per_row %d color %08x\n", (int32)ReadMacInt32(p + acclDestRowBytes), color)); |
1385 |
+ |
|
1386 |
+ |
// And perform the fill |
1387 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclDestPixelSize)); |
1388 |
+ |
const int dest_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1389 |
+ |
uint8 *dest = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dest_row_bytes) + (dest_X * bpp)); |
1390 |
+ |
width *= bpp; |
1391 |
+ |
switch (bpp) { |
1392 |
+ |
case 1: |
1393 |
+ |
for (int i = 0; i < height; i++) { |
1394 |
+ |
memset(dest, color, width); |
1395 |
+ |
dest += dest_row_bytes; |
1396 |
+ |
} |
1397 |
+ |
break; |
1398 |
+ |
case 2: |
1399 |
+ |
for (int i = 0; i < height; i++) { |
1400 |
+ |
do_fillrect<16>(dest, color, width); |
1401 |
+ |
dest += dest_row_bytes; |
1402 |
+ |
} |
1403 |
+ |
break; |
1404 |
+ |
case 4: |
1405 |
+ |
for (int i = 0; i < height; i++) { |
1406 |
+ |
do_fillrect<32>(dest, color, width); |
1407 |
+ |
dest += dest_row_bytes; |
1408 |
+ |
} |
1409 |
+ |
break; |
1410 |
+ |
} |
1411 |
+ |
} |
1412 |
+ |
|
1413 |
+ |
bool NQD_fillrect_hook(uint32 p) |
1414 |
+ |
{ |
1415 |
+ |
D(bug("accl_fillrect_hook %08x\n", p)); |
1416 |
+ |
|
1417 |
+ |
// Check if we can accelerate this fillrect |
1418 |
+ |
if (ReadMacInt32(p + 0x284) != 0 && ReadMacInt32(p + acclDestPixelSize) >= 8) { |
1419 |
+ |
const int transfer_mode = ReadMacInt32(p + acclTransferMode); |
1420 |
+ |
if (transfer_mode == 8) { |
1421 |
+ |
// Fill |
1422 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_FILLRECT)); |
1423 |
+ |
return true; |
1424 |
+ |
} |
1425 |
+ |
else if (transfer_mode == 10) { |
1426 |
+ |
// Invert |
1427 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_INVRECT)); |
1428 |
+ |
return true; |
1429 |
+ |
} |
1430 |
+ |
} |
1431 |
+ |
return false; |
1432 |
+ |
} |
1433 |
+ |
|
1434 |
+ |
// Rectangle blitting |
1435 |
+ |
// TODO: optimize for VOSF and target pixmap == screen |
1436 |
+ |
void NQD_bitblt(uint32 p) |
1437 |
+ |
{ |
1438 |
+ |
D(bug("accl_bitblt %08x\n", p)); |
1439 |
+ |
|
1440 |
+ |
// Get blitting parameters |
1441 |
+ |
int16 src_X = (int16)ReadMacInt16(p + acclSrcRect + 2) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 2); |
1442 |
+ |
int16 src_Y = (int16)ReadMacInt16(p + acclSrcRect + 0) - (int16)ReadMacInt16(p + acclSrcBoundsRect + 0); |
1443 |
+ |
int16 dest_X = (int16)ReadMacInt16(p + acclDestRect + 2) - (int16)ReadMacInt16(p + acclDestBoundsRect + 2); |
1444 |
+ |
int16 dest_Y = (int16)ReadMacInt16(p + acclDestRect + 0) - (int16)ReadMacInt16(p + acclDestBoundsRect + 0); |
1445 |
+ |
int16 width = (int16)ReadMacInt16(p + acclDestRect + 6) - (int16)ReadMacInt16(p + acclDestRect + 2); |
1446 |
+ |
int16 height = (int16)ReadMacInt16(p + acclDestRect + 4) - (int16)ReadMacInt16(p + acclDestRect + 0); |
1447 |
+ |
D(bug(" src addr %08x, dest addr %08x\n", ReadMacInt32(p + acclSrcBaseAddr), ReadMacInt32(p + acclDestBaseAddr))); |
1448 |
+ |
D(bug(" src X %d, src Y %d, dest X %d, dest Y %d\n", src_X, src_Y, dest_X, dest_Y)); |
1449 |
+ |
D(bug(" width %d, height %d\n", width, height)); |
1450 |
+ |
|
1451 |
+ |
// And perform the blit |
1452 |
+ |
const int bpp = bytes_per_pixel(ReadMacInt32(p + acclSrcPixelSize)); |
1453 |
+ |
width *= bpp; |
1454 |
+ |
if ((int32)ReadMacInt32(p + acclSrcRowBytes) > 0) { |
1455 |
+ |
const int src_row_bytes = (int32)ReadMacInt32(p + acclSrcRowBytes); |
1456 |
+ |
const int dst_row_bytes = (int32)ReadMacInt32(p + acclDestRowBytes); |
1457 |
+ |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + (src_Y * src_row_bytes) + (src_X * bpp)); |
1458 |
+ |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + (dest_Y * dst_row_bytes) + (dest_X * bpp)); |
1459 |
+ |
for (int i = 0; i < height; i++) { |
1460 |
+ |
memmove(dst, src, width); |
1461 |
+ |
src += src_row_bytes; |
1462 |
+ |
dst += dst_row_bytes; |
1463 |
+ |
} |
1464 |
+ |
} |
1465 |
+ |
else { |
1466 |
+ |
const int src_row_bytes = -(int32)ReadMacInt32(p + acclSrcRowBytes); |
1467 |
+ |
const int dst_row_bytes = -(int32)ReadMacInt32(p + acclDestRowBytes); |
1468 |
+ |
uint8 *src = Mac2HostAddr(ReadMacInt32(p + acclSrcBaseAddr) + ((src_Y + height - 1) * src_row_bytes) + (src_X * bpp)); |
1469 |
+ |
uint8 *dst = Mac2HostAddr(ReadMacInt32(p + acclDestBaseAddr) + ((dest_Y + height - 1) * dst_row_bytes) + (dest_X * bpp)); |
1470 |
+ |
for (int i = height - 1; i >= 0; i--) { |
1471 |
+ |
memmove(dst, src, width); |
1472 |
+ |
src -= src_row_bytes; |
1473 |
+ |
dst -= dst_row_bytes; |
1474 |
+ |
} |
1475 |
+ |
} |
1476 |
+ |
} |
1477 |
+ |
|
1478 |
+ |
/* |
1479 |
+ |
BitBlt transfer modes: |
1480 |
+ |
0 : srcCopy |
1481 |
+ |
1 : srcOr |
1482 |
+ |
2 : srcXor |
1483 |
+ |
3 : srcBic |
1484 |
+ |
4 : notSrcCopy |
1485 |
+ |
5 : notSrcOr |
1486 |
+ |
6 : notSrcXor |
1487 |
+ |
7 : notSrcBic |
1488 |
+ |
32 : blend |
1489 |
+ |
33 : addPin |
1490 |
+ |
34 : addOver |
1491 |
+ |
35 : subPin |
1492 |
+ |
36 : transparent |
1493 |
+ |
37 : adMax |
1494 |
+ |
38 : subOver |
1495 |
+ |
39 : adMin |
1496 |
+ |
50 : hilite |
1497 |
+ |
*/ |
1498 |
+ |
|
1499 |
+ |
bool NQD_bitblt_hook(uint32 p) |
1500 |
+ |
{ |
1501 |
+ |
D(bug("accl_draw_hook %08x\n", p)); |
1502 |
+ |
|
1503 |
+ |
// Check if we can accelerate this bitblt |
1504 |
+ |
if (ReadMacInt32(p + 0x018) + ReadMacInt32(p + 0x128) == 0 && |
1505 |
+ |
ReadMacInt32(p + 0x130) == 0 && |
1506 |
+ |
ReadMacInt32(p + acclSrcPixelSize) >= 8 && |
1507 |
+ |
ReadMacInt32(p + acclSrcPixelSize) == ReadMacInt32(p + acclDestPixelSize) && |
1508 |
+ |
(ReadMacInt32(p + acclSrcRowBytes) ^ ReadMacInt32(p + acclDestRowBytes)) >= 0 && // same sign? |
1509 |
+ |
ReadMacInt32(p + acclTransferMode) == 0 && // srcCopy? |
1510 |
+ |
ReadMacInt32(p + 0x15c) > 0) { |
1511 |
+ |
|
1512 |
+ |
// Yes, set function pointer |
1513 |
+ |
WriteMacInt32(p + acclDrawProc, NativeTVECT(NATIVE_BITBLT)); |
1514 |
+ |
return true; |
1515 |
+ |
} |
1516 |
+ |
return false; |
1517 |
+ |
} |
1518 |
+ |
|
1519 |
+ |
// Wait for graphics operation to finish |
1520 |
+ |
bool NQD_sync_hook(uint32 arg) |
1521 |
+ |
{ |
1522 |
+ |
D(bug("accl_sync_hook %08x\n", arg)); |
1523 |
+ |
return true; |
1524 |
+ |
} |
1525 |
+ |
|
1526 |
+ |
void VideoInstallAccel(void) |
1527 |
+ |
{ |
1528 |
+ |
// Install acceleration hooks |
1529 |
+ |
if (PrefsFindBool("gfxaccel")) { |
1530 |
+ |
D(bug("Video: Installing acceleration hooks\n")); |
1531 |
+ |
uint32 base; |
1532 |
+ |
|
1533 |
+ |
SheepVar bitblt_hook_info(sizeof(accl_hook_info)); |
1534 |
+ |
base = bitblt_hook_info.addr(); |
1535 |
+ |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_BITBLT_HOOK)); |
1536 |
+ |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1537 |
+ |
WriteMacInt32(base + 8, ACCL_BITBLT); |
1538 |
+ |
NQDMisc(6, bitblt_hook_info.ptr()); |
1539 |
+ |
|
1540 |
+ |
SheepVar fillrect_hook_info(sizeof(accl_hook_info)); |
1541 |
+ |
base = fillrect_hook_info.addr(); |
1542 |
+ |
WriteMacInt32(base + 0, NativeTVECT(NATIVE_FILLRECT_HOOK)); |
1543 |
+ |
WriteMacInt32(base + 4, NativeTVECT(NATIVE_SYNC_HOOK)); |
1544 |
+ |
WriteMacInt32(base + 8, ACCL_FILLRECT); |
1545 |
+ |
NQDMisc(6, fillrect_hook_info.ptr()); |
1546 |
+ |
} |
1547 |
+ |
} |
1548 |
+ |
#endif |
1549 |
+ |
|
1550 |
+ |
|
1551 |
+ |
/* |
1552 |
|
* Translate key event to Mac keycode, returns -1 if no keycode was found |
1553 |
|
* and -2 if the key was recognized as a hotkey |
1554 |
|
*/ |
1781 |
|
// Hidden parts exposed, force complete refresh of window |
1782 |
|
case SDL_VIDEOEXPOSE: |
1783 |
|
if (display_type == DISPLAY_WINDOW) { |
1784 |
< |
const video_mode &mode = VideoMonitors[0]->get_current_mode(); |
1784 |
> |
const VIDEO_MODE &mode = VideoMonitors[0]->get_current_mode(); |
1785 |
|
#ifdef ENABLE_VOSF |
1786 |
|
if (use_vosf) { // VOSF refresh |
1787 |
|
LOCK_VOSF; |
1788 |
|
PFLAG_SET_ALL; |
1789 |
|
UNLOCK_VOSF; |
1790 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1790 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1791 |
|
} |
1792 |
|
else |
1793 |
|
#endif |
1794 |
< |
memset(the_buffer_copy, 0, mode.bytes_per_row * mode.y); |
1794 |
> |
memset(the_buffer_copy, 0, VIDEO_MODE_ROW_BYTES * VIDEO_MODE_Y); |
1795 |
|
} |
1796 |
|
break; |
1797 |
|
|
1815 |
|
{ |
1816 |
|
// Incremental update code |
1817 |
|
int wide = 0, high = 0, x1, x2, y1, y2, i, j; |
1818 |
< |
const video_mode &mode = drv->mode; |
1819 |
< |
int bytes_per_row = mode.bytes_per_row; |
1818 |
> |
const VIDEO_MODE &mode = drv->mode; |
1819 |
> |
int bytes_per_row = VIDEO_MODE_ROW_BYTES; |
1820 |
|
uint8 *p, *p2; |
1821 |
|
|
1822 |
|
// Check for first line from top and first line from bottom that have changed |
1823 |
|
y1 = 0; |
1824 |
< |
for (j=0; j<mode.y; j++) { |
1824 |
> |
for (j=0; j<VIDEO_MODE_Y; j++) { |
1825 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1826 |
|
y1 = j; |
1827 |
|
break; |
1828 |
|
} |
1829 |
|
} |
1830 |
|
y2 = y1 - 1; |
1831 |
< |
for (j=mode.y-1; j>=y1; j--) { |
1831 |
> |
for (j=VIDEO_MODE_Y-1; j>=y1; j--) { |
1832 |
|
if (memcmp(&the_buffer[j * bytes_per_row], &the_buffer_copy[j * bytes_per_row], bytes_per_row)) { |
1833 |
|
y2 = j; |
1834 |
|
break; |
1838 |
|
|
1839 |
|
// Check for first column from left and first column from right that have changed |
1840 |
|
if (high) { |
1841 |
< |
if (mode.depth < VDEPTH_8BIT) { |
1841 |
> |
if (VIDEO_MODE_DEPTH < VIDEO_DEPTH_8BIT) { |
1842 |
|
const int src_bytes_per_row = bytes_per_row; |
1843 |
|
const int dst_bytes_per_row = drv->s->pitch; |
1844 |
< |
const int pixels_per_byte = mode.x / src_bytes_per_row; |
1844 |
> |
const int pixels_per_byte = VIDEO_MODE_X / src_bytes_per_row; |
1845 |
|
|
1846 |
< |
x1 = mode.x / pixels_per_byte; |
1846 |
> |
x1 = VIDEO_MODE_X / pixels_per_byte; |
1847 |
|
for (j = y1; j <= y2; j++) { |
1848 |
|
p = &the_buffer[j * bytes_per_row]; |
1849 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1861 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1862 |
|
p += bytes_per_row; |
1863 |
|
p2 += bytes_per_row; |
1864 |
< |
for (i = (mode.x / pixels_per_byte); i > x2; i--) { |
1864 |
> |
for (i = (VIDEO_MODE_X / pixels_per_byte); i > x2; i--) { |
1865 |
|
p--; p2--; |
1866 |
|
if (*p != *p2) { |
1867 |
|
x2 = i; |
1899 |
|
} |
1900 |
|
|
1901 |
|
} else { |
1902 |
< |
const int bytes_per_pixel = mode.bytes_per_row / mode.x; |
1902 |
> |
const int bytes_per_pixel = VIDEO_MODE_ROW_BYTES / VIDEO_MODE_X; |
1903 |
|
|
1904 |
< |
x1 = mode.x; |
1904 |
> |
x1 = VIDEO_MODE_X; |
1905 |
|
for (j=y1; j<=y2; j++) { |
1906 |
|
p = &the_buffer[j * bytes_per_row]; |
1907 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1919 |
|
p2 = &the_buffer_copy[j * bytes_per_row]; |
1920 |
|
p += bytes_per_row; |
1921 |
|
p2 += bytes_per_row; |
1922 |
< |
for (i=mode.x*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1922 |
> |
for (i=VIDEO_MODE_X*bytes_per_pixel; i>x2*bytes_per_pixel; i--) { |
1923 |
|
p--; |
1924 |
|
p2--; |
1925 |
|
if (*p != *p2) { |
2079 |
|
} |
2080 |
|
} |
2081 |
|
|
2082 |
+ |
const int VIDEO_REFRESH_HZ = 60; |
2083 |
+ |
const int VIDEO_REFRESH_DELAY = 1000000 / VIDEO_REFRESH_HZ; |
2084 |
+ |
|
2085 |
|
static int redraw_func(void *arg) |
2086 |
|
{ |
2087 |
|
uint64 start = GetTicks_usec(); |
2088 |
|
int64 ticks = 0; |
2089 |
+ |
uint64 next = GetTicks_usec() + VIDEO_REFRESH_DELAY; |
2090 |
|
|
2091 |
|
while (!redraw_thread_cancel) { |
2092 |
|
|
2093 |
|
// Wait |
2094 |
< |
Delay_usec(16667); |
2094 |
> |
next += VIDEO_REFRESH_DELAY; |
2095 |
> |
int64 delay = next - GetTicks_usec(); |
2096 |
> |
if (delay > 0) |
2097 |
> |
Delay_usec(delay); |
2098 |
> |
else if (delay < -VIDEO_REFRESH_DELAY) |
2099 |
> |
next = GetTicks_usec(); |
2100 |
> |
ticks++; |
2101 |
|
|
2102 |
|
// Handle SDL events |
2103 |
|
handle_events(); |
2104 |
|
|
2105 |
|
// Refresh display |
2106 |
|
video_refresh(); |
1431 |
– |
ticks++; |
2107 |
|
|
2108 |
|
// Set new palette if it was changed |
2109 |
|
handle_palette_changes(); |