56 |
|
#include "video.h" |
57 |
|
#include "video_defs.h" |
58 |
|
#include "video_blit.h" |
59 |
+ |
#include "vm_alloc.h" |
60 |
|
|
61 |
|
#define DEBUG 0 |
62 |
|
#include "debug.h" |
97 |
|
static bool redraw_thread_active = false; // Flag: Redraw thread installed |
98 |
|
static volatile bool redraw_thread_cancel; // Flag: Cancel Redraw thread |
99 |
|
static SDL_Thread *redraw_thread = NULL; // Redraw thread |
100 |
+ |
static volatile bool thread_stop_req = false; |
101 |
+ |
static volatile bool thread_stop_ack = false; // Acknowledge for thread_stop_req |
102 |
|
|
103 |
|
#ifdef ENABLE_VOSF |
104 |
|
static bool use_vosf = false; // Flag: VOSF enabled |
148 |
|
|
149 |
|
|
150 |
|
/* |
151 |
+ |
* Framebuffer allocation routines |
152 |
+ |
*/ |
153 |
+ |
|
154 |
+ |
static void *vm_acquire_framebuffer(uint32 size) |
155 |
+ |
{ |
156 |
+ |
#ifdef SHEEPSHAVER |
157 |
+ |
#ifdef DIRECT_ADDRESSING_HACK |
158 |
+ |
const uint32 FRAME_BUFFER_BASE = 0x61000000; |
159 |
+ |
uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE); |
160 |
+ |
if (vm_acquire_fixed(fb, size) < 0) |
161 |
+ |
fb = VM_MAP_FAILED; |
162 |
+ |
return fb; |
163 |
+ |
#endif |
164 |
+ |
#endif |
165 |
+ |
return vm_acquire(size); |
166 |
+ |
} |
167 |
+ |
|
168 |
+ |
static inline void vm_release_framebuffer(void *fb, uint32 size) |
169 |
+ |
{ |
170 |
+ |
vm_release(fb, size); |
171 |
+ |
} |
172 |
+ |
|
173 |
+ |
|
174 |
+ |
/* |
175 |
|
* SheepShaver glue |
176 |
|
*/ |
177 |
|
|
351 |
|
} |
352 |
|
|
353 |
|
// Map video_mode depth ID to numerical depth value |
354 |
< |
static int sdl_depth_of_video_depth(int video_depth) |
354 |
> |
static int mac_depth_of_video_depth(int video_depth) |
355 |
|
{ |
356 |
|
int depth = -1; |
357 |
|
switch (video_depth) { |
379 |
|
return depth; |
380 |
|
} |
381 |
|
|
382 |
+ |
// Map video_mode depth ID to SDL screen depth |
383 |
+ |
static int sdl_depth_of_video_depth(int video_depth) |
384 |
+ |
{ |
385 |
+ |
return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth); |
386 |
+ |
} |
387 |
+ |
|
388 |
|
// Check wether specified mode is available |
389 |
|
static bool has_mode(int type, int width, int height) |
390 |
|
{ |
581 |
|
if (s) |
582 |
|
SDL_FreeSurface(s); |
583 |
|
|
584 |
+ |
// the_buffer shall always be mapped through vm_acquire_framebuffer() |
585 |
+ |
if (the_buffer != VM_MAP_FAILED) { |
586 |
+ |
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size)); |
587 |
+ |
vm_release_framebuffer(the_buffer, the_buffer_size); |
588 |
+ |
the_buffer = NULL; |
589 |
+ |
} |
590 |
+ |
|
591 |
|
// Free frame buffer(s) |
592 |
|
if (!use_vosf) { |
553 |
– |
if (the_buffer) { |
554 |
– |
free(the_buffer); |
555 |
– |
the_buffer = NULL; |
556 |
– |
} |
593 |
|
if (the_buffer_copy) { |
594 |
|
free(the_buffer_copy); |
595 |
|
the_buffer_copy = NULL; |
597 |
|
} |
598 |
|
#ifdef ENABLE_VOSF |
599 |
|
else { |
564 |
– |
// the_buffer shall always be mapped through vm_acquire() so that we can vm_protect() it at will |
565 |
– |
if (the_buffer != VM_MAP_FAILED) { |
566 |
– |
D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size)); |
567 |
– |
vm_release(the_buffer, the_buffer_size); |
568 |
– |
the_buffer = NULL; |
569 |
– |
} |
600 |
|
if (the_host_buffer) { |
601 |
|
D(bug(" freeing the_host_buffer at %p\n", the_host_buffer)); |
602 |
|
free(the_host_buffer); |
607 |
|
free(the_buffer_copy); |
608 |
|
the_buffer_copy = NULL; |
609 |
|
} |
610 |
+ |
|
611 |
+ |
// Deinitialize VOSF |
612 |
+ |
video_vosf_exit(); |
613 |
|
} |
614 |
|
#endif |
615 |
|
} |
650 |
|
ADBSetRelMouseMode(mouse_grabbed); |
651 |
|
|
652 |
|
// Create surface |
653 |
< |
int depth = ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth); |
653 |
> |
int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH); |
654 |
|
if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL) |
655 |
|
return; |
656 |
|
|
659 |
|
// Allocate memory for frame buffer (SIZE is extended to page-boundary) |
660 |
|
the_host_buffer = (uint8 *)s->pixels; |
661 |
|
the_buffer_size = page_extend((aligned_height + 2) * s->pitch); |
662 |
< |
the_buffer = (uint8 *)vm_acquire(the_buffer_size); |
662 |
> |
the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size); |
663 |
|
the_buffer_copy = (uint8 *)malloc(the_buffer_size); |
664 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer)); |
665 |
|
|
683 |
|
// Allocate memory for frame buffer |
684 |
|
the_buffer_size = (aligned_height + 2) * s->pitch; |
685 |
|
the_buffer_copy = (uint8 *)calloc(1, the_buffer_size); |
686 |
< |
the_buffer = (uint8 *)calloc(1, the_buffer_size); |
686 |
> |
the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size); |
687 |
|
D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy)); |
688 |
|
} |
689 |
|
|
708 |
|
visualFormat.Rmask = f->Rmask; |
709 |
|
visualFormat.Gmask = f->Gmask; |
710 |
|
visualFormat.Bmask = f->Bmask; |
711 |
< |
Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
711 |
> |
Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH)); |
712 |
|
|
713 |
|
// Load gray ramp to 8->16/32 expand map |
714 |
|
if (!IsDirectMode(mode)) |
987 |
|
add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT); |
988 |
|
else { |
989 |
|
for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) { |
990 |
< |
int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d)); |
990 |
> |
int bpp = sdl_depth_of_video_depth(d); |
991 |
|
if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE)) |
992 |
|
add_window_modes(video_depth(d)); |
993 |
|
} |
1075 |
|
UNLOCK_FRAME_BUFFER; |
1076 |
|
D(bug(" frame buffer unlocked\n")); |
1077 |
|
|
1045 |
– |
#ifdef ENABLE_VOSF |
1046 |
– |
if (use_vosf) { |
1047 |
– |
// Deinitialize VOSF |
1048 |
– |
video_vosf_exit(); |
1049 |
– |
} |
1050 |
– |
#endif |
1051 |
– |
|
1078 |
|
// Close display |
1079 |
|
delete drv; |
1080 |
|
drv = NULL; |
1233 |
|
csSave->saveData = ReadMacInt32(ParamPtr + csData); |
1234 |
|
csSave->savePage = ReadMacInt16(ParamPtr + csPage); |
1235 |
|
|
1236 |
< |
// Disable interrupts |
1236 |
> |
// Disable interrupts and pause redraw thread |
1237 |
|
DisableInterrupt(); |
1238 |
+ |
thread_stop_ack = false; |
1239 |
+ |
thread_stop_req = true; |
1240 |
+ |
while (!thread_stop_ack) ; |
1241 |
|
|
1242 |
|
cur_mode = i; |
1243 |
|
monitor_desc *monitor = VideoMonitors[0]; |
1248 |
|
csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */ |
1249 |
|
csSave->saveMode=VModes[cur_mode].viAppleMode; |
1250 |
|
|
1251 |
< |
// Enable interrupts |
1251 |
> |
// Enable interrupts and resume redraw thread |
1252 |
> |
thread_stop_req = false; |
1253 |
|
EnableInterrupt(); |
1254 |
|
return noErr; |
1255 |
|
} |
1890 |
|
next = GetTicks_usec(); |
1891 |
|
ticks++; |
1892 |
|
|
1893 |
+ |
#ifdef SHEEPSHAVER |
1894 |
+ |
// Pause if requested (during video mode switches) |
1895 |
+ |
if (thread_stop_req) { |
1896 |
+ |
thread_stop_ack = true; |
1897 |
+ |
continue; |
1898 |
+ |
} |
1899 |
+ |
#endif |
1900 |
+ |
|
1901 |
|
// Handle SDL events |
1902 |
|
handle_events(); |
1903 |
|
|