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.16 by gbeauche, 2005-03-17T00:19:39Z

# Line 1 | Line 1
1   /*
2   *  video_sdl.cpp - Video/graphics emulation, SDL specific stuff
3   *
4 < *  Basilisk II (C) 1997-2004 Christian Bauer
4 > *  Basilisk II (C) 1997-2005 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
# 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 81 | Line 82 | static int display_type = DISPLAY_WINDOW
82   #endif
83  
84   // Constants
85 + #ifdef WIN32
86 + const char KEYCODE_FILE_NAME[] = "BasiliskII_keycodes";
87 + #else
88   const char KEYCODE_FILE_NAME[] = DATADIR "/keycodes";
89 + #endif
90  
91  
92   // Global variables
# Line 96 | Line 101 | static uint32 the_buffer_size;                                         // S
101   static bool redraw_thread_active = false;                       // Flag: Redraw thread installed
102   static volatile bool redraw_thread_cancel;                      // Flag: Cancel Redraw thread
103   static SDL_Thread *redraw_thread = NULL;                        // Redraw thread
104 + static volatile bool thread_stop_req = false;
105 + static volatile bool thread_stop_ack = false;           // Acknowledge for thread_stop_req
106  
107   #ifdef ENABLE_VOSF
108   static bool use_vosf = false;                                           // Flag: VOSF enabled
# Line 145 | Line 152 | extern void SysMountFirstFloppy(void);
152  
153  
154   /*
155 + *  Framebuffer allocation routines
156 + */
157 +
158 + static void *vm_acquire_framebuffer(uint32 size)
159 + {
160 + #ifdef SHEEPSHAVER
161 + #ifdef DIRECT_ADDRESSING_HACK
162 +        const uint32 FRAME_BUFFER_BASE = 0x61000000;
163 +        uint8 *fb = Mac2HostAddr(FRAME_BUFFER_BASE);
164 +        if (vm_acquire_fixed(fb, size) < 0)
165 +                fb = VM_MAP_FAILED;
166 +        return fb;
167 + #endif
168 + #endif
169 +        return vm_acquire(size);
170 + }
171 +
172 + static inline void vm_release_framebuffer(void *fb, uint32 size)
173 + {
174 +        vm_release(fb, size);
175 + }
176 +
177 +
178 + /*
179   *  SheepShaver glue
180   */
181  
# Line 324 | Line 355 | static inline int bytes_per_pixel(int de
355   }
356  
357   // Map video_mode depth ID to numerical depth value
358 < static int sdl_depth_of_video_depth(int video_depth)
358 > static int mac_depth_of_video_depth(int video_depth)
359   {
360          int depth = -1;
361          switch (video_depth) {
# Line 352 | Line 383 | static int sdl_depth_of_video_depth(int
383          return depth;
384   }
385  
386 + // Map video_mode depth ID to SDL screen depth
387 + static int sdl_depth_of_video_depth(int video_depth)
388 + {
389 +        return (video_depth <= VIDEO_DEPTH_8BIT) ? 8 : mac_depth_of_video_depth(video_depth);
390 + }
391 +
392   // Check wether specified mode is available
393   static bool has_mode(int type, int width, int height)
394   {
# Line 548 | Line 585 | driver_base::~driver_base()
585          if (s)
586                  SDL_FreeSurface(s);
587  
588 +        // the_buffer shall always be mapped through vm_acquire_framebuffer()
589 +        if (the_buffer != VM_MAP_FAILED) {
590 +                D(bug(" releasing the_buffer at %p (%d bytes)\n", the_buffer, the_buffer_size));
591 +                vm_release_framebuffer(the_buffer, the_buffer_size);
592 +                the_buffer = NULL;
593 +        }
594 +
595          // Free frame buffer(s)
596          if (!use_vosf) {
553                if (the_buffer) {
554                        free(the_buffer);
555                        the_buffer = NULL;
556                }
597                  if (the_buffer_copy) {
598                          free(the_buffer_copy);
599                          the_buffer_copy = NULL;
# Line 561 | Line 601 | driver_base::~driver_base()
601          }
602   #ifdef ENABLE_VOSF
603          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                }
604                  if (the_host_buffer) {
605                          D(bug(" freeing the_host_buffer at %p\n", the_host_buffer));
606                          free(the_host_buffer);
# Line 577 | Line 611 | driver_base::~driver_base()
611                          free(the_buffer_copy);
612                          the_buffer_copy = NULL;
613                  }
614 +
615 +                // Deinitialize VOSF
616 +                video_vosf_exit();
617          }
618   #endif
619   }
# Line 617 | Line 654 | driver_window::driver_window(SDL_monitor
654          ADBSetRelMouseMode(mouse_grabbed);
655  
656          // Create surface
657 <        int depth = ((int)VIDEO_MODE_DEPTH <= VIDEO_DEPTH_8BIT ? 8 : screen_depth);
657 >        int depth = sdl_depth_of_video_depth(VIDEO_MODE_DEPTH);
658          if ((s = SDL_SetVideoMode(width, height, depth, SDL_HWSURFACE)) == NULL)
659                  return;
660  
# Line 626 | Line 663 | driver_window::driver_window(SDL_monitor
663          // Allocate memory for frame buffer (SIZE is extended to page-boundary)
664          the_host_buffer = (uint8 *)s->pixels;
665          the_buffer_size = page_extend((aligned_height + 2) * s->pitch);
666 <        the_buffer = (uint8 *)vm_acquire(the_buffer_size);
666 >        the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
667          the_buffer_copy = (uint8 *)malloc(the_buffer_size);
668          D(bug("the_buffer = %p, the_buffer_copy = %p, the_host_buffer = %p\n", the_buffer, the_buffer_copy, the_host_buffer));
669  
# Line 650 | Line 687 | driver_window::driver_window(SDL_monitor
687                  // Allocate memory for frame buffer
688                  the_buffer_size = (aligned_height + 2) * s->pitch;
689                  the_buffer_copy = (uint8 *)calloc(1, the_buffer_size);
690 <                the_buffer = (uint8 *)calloc(1, the_buffer_size);
690 >                the_buffer = (uint8 *)vm_acquire_framebuffer(the_buffer_size);
691                  D(bug("the_buffer = %p, the_buffer_copy = %p\n", the_buffer, the_buffer_copy));
692          }
693          
# Line 675 | Line 712 | driver_window::driver_window(SDL_monitor
712          visualFormat.Rmask = f->Rmask;
713          visualFormat.Gmask = f->Gmask;
714          visualFormat.Bmask = f->Bmask;
715 <        Screen_blitter_init(visualFormat, true, sdl_depth_of_video_depth(VIDEO_MODE_DEPTH));
715 >        Screen_blitter_init(visualFormat, true, mac_depth_of_video_depth(VIDEO_MODE_DEPTH));
716  
717          // Load gray ramp to 8->16/32 expand map
718          if (!IsDirectMode(mode))
# Line 773 | Line 810 | static void keycode_init(void)
810                  SDL_VideoDriverName(video_driver, sizeof(video_driver));
811                  bool video_driver_found = false;
812                  char line[256];
813 +                int n_keys = 0;
814                  while (fgets(line, sizeof(line) - 1, f)) {
815                          // Read line
816                          int len = strlen(line);
# Line 785 | Line 823 | static void keycode_init(void)
823                                  continue;
824  
825                          if (video_driver_found) {
826 <                                // Skip aliases
826 >                                // Skip aliases as long as we have read keycodes yet
827 >                                // Otherwise, it's another mapping and we have to stop
828                                  static const char sdl_str[] = "sdl";
829 <                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0)
829 >                                if (strncmp(line, sdl_str, sizeof(sdl_str) - 1) == 0 && n_keys == 0)
830                                          continue;
831  
832                                  // Read keycode
833                                  int x_code, mac_code;
834                                  if (sscanf(line, "%d %d", &x_code, &mac_code) == 2)
835 <                                        keycode_table[x_code & 0xff] = mac_code;
835 >                                        keycode_table[x_code & 0xff] = mac_code, n_keys++;
836                                  else
837                                          break;
838                          } else {
# Line 818 | Line 857 | static void keycode_init(void)
857                          WarningAlert(str);
858                          return;
859                  }
860 +
861 +                D(bug("Using SDL/%s keycodes table, %d key mappings\n", video_driver, n_keys));
862          }
863   }
864  
# Line 954 | Line 995 | bool VideoInit(bool classic)
995                          add_mode(display_type, 512, 342, 0x80, 64, VIDEO_DEPTH_1BIT);
996                  else {
997                          for (int d = VIDEO_DEPTH_1BIT; d <= default_depth; d++) {
998 <                                int bpp = (d <= VIDEO_DEPTH_8BIT ? 8 : sdl_depth_of_video_depth(d));
998 >                                int bpp = sdl_depth_of_video_depth(d);
999                                  if (SDL_VideoModeOK(max_width, max_height, bpp, SDL_HWSURFACE))
1000                                          add_window_modes(video_depth(d));
1001                          }
# Line 1042 | Line 1083 | void SDL_monitor_desc::video_close(void)
1083          UNLOCK_FRAME_BUFFER;
1084          D(bug(" frame buffer unlocked\n"));
1085  
1045 #ifdef ENABLE_VOSF
1046        if (use_vosf) {
1047                // Deinitialize VOSF
1048                video_vosf_exit();
1049        }
1050 #endif
1051
1086          // Close display
1087          delete drv;
1088          drv = NULL;
# Line 1207 | Line 1241 | int16 video_mode_change(VidLocals *csSav
1241                          csSave->saveData = ReadMacInt32(ParamPtr + csData);
1242                          csSave->savePage = ReadMacInt16(ParamPtr + csPage);
1243  
1244 <                        // Disable interrupts
1244 >                        // Disable interrupts and pause redraw thread
1245                          DisableInterrupt();
1246 +                        thread_stop_ack = false;
1247 +                        thread_stop_req = true;
1248 +                        while (!thread_stop_ack) ;
1249  
1250                          cur_mode = i;
1251                          monitor_desc *monitor = VideoMonitors[0];
# Line 1219 | Line 1256 | int16 video_mode_change(VidLocals *csSav
1256                          csSave->saveData=VModes[cur_mode].viAppleID;/* First mode ... */
1257                          csSave->saveMode=VModes[cur_mode].viAppleMode;
1258  
1259 <                        // Enable interrupts
1259 >                        // Enable interrupts and resume redraw thread
1260 >                        thread_stop_req = false;
1261                          EnableInterrupt();
1262                          return noErr;
1263                  }
# Line 1860 | Line 1898 | static int redraw_func(void *arg)
1898                          next = GetTicks_usec();
1899                  ticks++;
1900  
1901 + #ifdef SHEEPSHAVER
1902 +                // Pause if requested (during video mode switches)
1903 +                if (thread_stop_req) {
1904 +                        thread_stop_ack = true;
1905 +                        continue;
1906 +                }
1907 + #endif
1908 +
1909                  // Handle SDL events
1910                  handle_events();
1911  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines