ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/SDL/video_sdl.cpp
(Generate patch)

Comparing BasiliskII/src/SDL/video_sdl.cpp (file contents):
Revision 1.11 by gbeauche, 2004-07-02T06:08:01Z vs.
Revision 1.14 by gbeauche, 2005-01-22T17:41:33Z

# Line 56 | Line 56
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"
# Line 96 | Line 97 | static uint32 the_buffer_size;                                         // S
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
# Line 145 | Line 148 | extern void SysMountFirstFloppy(void);
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  
# Line 324 | Line 351 | static inline int bytes_per_pixel(int de
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) {
# Line 352 | Line 379 | static int sdl_depth_of_video_depth(int
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   {
# Line 548 | Line 581 | driver_base::~driver_base()
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;
# Line 561 | Line 597 | driver_base::~driver_base()
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);
# Line 577 | Line 607 | driver_base::~driver_base()
607                          free(the_buffer_copy);
608                          the_buffer_copy = NULL;
609                  }
610 +
611 +                // Deinitialize VOSF
612 +                video_vosf_exit();
613          }
614   #endif
615   }
# Line 617 | Line 650 | driver_window::driver_window(SDL_monitor
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  
# Line 626 | Line 659 | driver_window::driver_window(SDL_monitor
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  
# Line 650 | Line 683 | driver_window::driver_window(SDL_monitor
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          
# Line 675 | Line 708 | driver_window::driver_window(SDL_monitor
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))
# Line 773 | Line 806 | static void keycode_init(void)
806                  SDL_VideoDriverName(video_driver, sizeof(video_driver));
807                  bool video_driver_found = false;
808                  char line[256];
809 +                int n_keys = 0;
810                  while (fgets(line, sizeof(line) - 1, f)) {
811                          // Read line
812                          int len = strlen(line);
# Line 785 | Line 819 | static void keycode_init(void)
819                                  continue;
820  
821                          if (video_driver_found) {
822 <                                // Skip aliases
822 >                                // Skip aliases as long as we have read keycodes yet
823 >                                // Otherwise, it's another mapping and we have to stop
824                                  static const char sdl_str[] = "sdl";
825 <                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0)
825 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0 && n_keys == 0)
826                                          continue;
827  
828                                  // Read keycode
829                                  int x_code, mac_code;
830                                  if (sscanf(line, "%d %d", &x_code, &mac_code) == 2)
831 <                                        keycode_table[x_code & 0xff] = mac_code;
831 >                                        keycode_table[x_code & 0xff] = mac_code, n_keys++;
832                                  else
833                                          break;
834                          } else {
# Line 818 | Line 853 | static void keycode_init(void)
853                          WarningAlert(str);
854                          return;
855                  }
856 +
857 +                D(bug("Using SDL/%s keycodes table, %d key mappings\n", video_driver, n_keys));
858          }
859   }
860  
# Line 954 | Line 991 | bool VideoInit(bool classic)
991                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
992                  else {
993                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
994 <                                int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d));
994 >                                int bpp = sdl_depth_of_video_depth(d);
995                                  if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
996                                          add_window_modes(video_depth(d));
997                          }
# Line 1042 | Line 1079 | void SDL_monitor_desc::video_close(void)
1079          UNLOCK_FRAME_BUFFER;
1080          D(bug(" frame buffer unlocked\n"));
1081  
1045 #ifdef ENABLE_VOSF
1046        if (use_vosf) {
1047                // Deinitialize VOSF
1048                video_vosf_exit();
1049        }
1050 #endif
1051
1082          // Close display
1083          delete drv;
1084          drv = NULL;
# Line 1207 | Line 1237 | int16 video_mode_change(VidLocals *csSav
1237                          csSave->saveData = ReadMacInt32(ParamPtr + csData);
1238                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
1239  
1240 <                        // Disable interrupts
1240 >                        // Disable interrupts and pause redraw thread
1241                          DisableInterrupt();
1242 +                        thread_stop_ack = false;
1243 +                        thread_stop_req = true;
1244 +                        while (!thread_stop_ack) ;
1245  
1246                          cur_mode = i;
1247                          monitor_desc *monitor = VideoMonitors[0];
# Line 1219 | Line 1252 | int16 video_mode_change(VidLocals *csSav
1252                          csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */
1253                          csSave->saveMode=VModes[cur_mode].viAppleMode;
1254  
1255 <                        // Enable interrupts
1255 >                        // Enable interrupts and resume redraw thread
1256 >                        thread_stop_req = false;
1257                          EnableInterrupt();
1258                          return noErr;
1259                  }
# Line 1860 | Line 1894 | static int redraw_func(void *arg)
1894                          next = GetTicks_usec();
1895                  ticks++;
1896  
1897 + #ifdef SHEEPSHAVER
1898 +                // Pause if requested (during video mode switches)
1899 +                if (thread_stop_req) {
1900 +                        thread_stop_ack = true;
1901 +                        continue;
1902 +                }
1903 + #endif
1904 +
1905                  // Handle SDL events
1906                  handle_events();
1907  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines