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

Comparing BasiliskII/src/AmigaOS/video_amiga.cpp (file contents):
Revision 1.7 by cebix, 2000-07-22T16:20:55Z vs.
Revision 1.19 by cebix, 2001-07-03T19:26:51Z

# Line 1 | Line 1
1   /*
2   *  video_amiga.cpp - Video/graphics emulation, AmigaOS specific stuff
3   *
4 < *  Basilisk II (C) 1997-2000 Christian Bauer
4 > *  Basilisk II (C) 1997-2001 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 33 | Line 33
33   #include <proto/cybergraphics.h>
34  
35   #include "sysdeps.h"
36 + #include "cpu_emulation.h"
37   #include "main.h"
38   #include "adb.h"
39   #include "prefs.h"
# Line 57 | Line 58 | static int display_type = DISPLAY_WINDOW
58   static struct Screen *the_screen = NULL;
59   static struct Window *the_win = NULL;
60   static struct BitMap *the_bitmap = NULL;
61 + static UWORD *null_pointer = NULL;                              // Blank mouse pointer data
62 + static UWORD *current_pointer = (UWORD *)-1;    // Currently visible mouse pointer data
63   static LONG black_pen = -1, white_pen = -1;
64   static struct Process *periodic_proc = NULL;    // Periodic process
65  
# Line 92 | Line 95 | static void periodic_func(void);
95   *  Initialization
96   */
97  
98 + // Add resolution to list of supported modes and set VideoMonitor
99 + static void set_video_monitor(uint32 width, uint32 height, uint32 bytes_per_row, int depth)
100 + {
101 +        video_mode mode;
102 +
103 +        mode.x = width;
104 +        mode.y = height;
105 +        mode.resolution_id = 0x80;
106 +        mode.bytes_per_row = bytes_per_row;
107 +
108 +        switch (depth) {
109 +                case 1:
110 +                        mode.depth = VDEPTH_1BIT;
111 +                        break;
112 +                case 2:
113 +                        mode.depth = VDEPTH_2BIT;
114 +                        break;
115 +                case 4:
116 +                        mode.depth = VDEPTH_4BIT;
117 +                        break;
118 +                case 8:
119 +                        mode.depth = VDEPTH_8BIT;
120 +                        break;
121 +                case 15:
122 +                case 16:
123 +                        mode.depth = VDEPTH_16BIT;
124 +                        break;
125 +                case 24:
126 +                case 32:
127 +                        mode.depth = VDEPTH_32BIT;
128 +                        break;
129 +        }
130 +
131 +        VideoModes.push_back(mode);
132 +        video_init_depth_list();
133 +        VideoMonitor.mode = mode;
134 + }
135 +
136   // Open window
137   static bool init_window(int width, int height)
138   {
# Line 114 | Line 155 | static bool init_window(int width, int h
155                  TAG_END
156          );
157          if (the_win == NULL) {
158 <                ErrorAlert(GetString(STR_OPEN_WINDOW_ERR));
158 >                ErrorAlert(STR_OPEN_WINDOW_ERR);
159                  return false;
160          }
161  
162          // Create bitmap ("height + 2" for safety)
163          the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL);
164          if (the_bitmap == NULL) {
165 <                ErrorAlert(GetString(STR_NO_MEM_ERR));
165 >                ErrorAlert(STR_NO_MEM_ERR);
166                  return false;
167          }
168  
169 <        // Set VideoMonitor
169 >        // Add resolution and set VideoMonitor
170 >        set_video_monitor(width, height, the_bitmap->BytesPerRow, 1);
171          VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0];
130        VideoMonitor.bytes_per_row = the_bitmap->BytesPerRow;
131        VideoMonitor.x = width;
132        VideoMonitor.y = height;
133        VideoMonitor.mode = VMODE_1BIT;
172  
173          // Set FgPen and BgPen
174          black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL);
# Line 169 | Line 207 | static bool init_pip(int width, int heig
207                  TAG_END
208          );
209          if (the_win == NULL || error) {
210 <                ErrorAlert(GetString(STR_OPEN_WINDOW_ERR));
210 >                ErrorAlert(STR_OPEN_WINDOW_ERR);
211                  return false;
212          }
213  
214          // Find bitmap
215          p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END);
216  
217 <        // Set VideoMonitor
217 >        // Add resolution and set VideoMonitor
218          VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY);
219 <        VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW);
182 <        VideoMonitor.x = width;
183 <        VideoMonitor.y = height;
184 <        VideoMonitor.mode = VMODE_16BIT;
219 >        set_video_monitor(width, height, p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW), 16);
220          return true;
221   }
222  
# Line 197 | Line 232 | static bool init_screen_p96(ULONG mode_i
232  
233          switch (depth) {
234                  case 8:
200                        VideoMonitor.mode = VMODE_8BIT;
235                          break;
236                  case 15:
237                  case 16:
238                          if (format != RGBFB_R5G5B5) {
239 <                                ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR));
239 >                                ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR);
240                                  return false;
241                          }
208                        VideoMonitor.mode = VMODE_16BIT;
242                          break;
243                  case 24:
244                  case 32:
245                          if (format != RGBFB_A8R8G8B8) {
246 <                                ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR));
246 >                                ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR);
247                                  return false;
248                          }
216                        VideoMonitor.mode = VMODE_32BIT;
249                          break;
250                  default:
251 <                        ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR));
251 >                        ErrorAlert(STR_WRONG_SCREEN_DEPTH_ERR);
252                          return false;
253          }
254  
# Line 224 | Line 256 | static bool init_screen_p96(ULONG mode_i
256          uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH);
257          uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT);
258  
227        VideoMonitor.x = width;
228        VideoMonitor.y = height;
229
259          // Open screen
260          the_screen = p96OpenScreenTags(
261                  P96SA_DisplayID, mode_id,
# Line 238 | Line 267 | static bool init_screen_p96(ULONG mode_i
267                  TAG_END
268          );
269          if (the_screen == NULL) {
270 <                ErrorAlert(GetString(STR_OPEN_SCREEN_ERR));
270 >                ErrorAlert(STR_OPEN_SCREEN_ERR);
271                  return false;
272          }
273  
# Line 255 | Line 284 | static bool init_screen_p96(ULONG mode_i
284                  TAG_END
285          );
286          if (the_win == NULL) {
287 <                ErrorAlert(GetString(STR_OPEN_WINDOW_ERR));
287 >                ErrorAlert(STR_OPEN_WINDOW_ERR);
288                  return false;
289          }
290  
262        // Set VideoMonitor
291          ScreenToFront(the_screen);
292 +
293 +        // Add resolution and set VideoMonitor
294 +        set_video_monitor(width, height, p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW), depth);
295          VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY);
265        VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW);
296          return true;
297   }
298  
# Line 278 | Line 308 | static bool init_screen_cgfx(ULONG mode_
308  
309          switch (depth) {
310                  case 8:
281                        VideoMonitor.mode = VMODE_8BIT;
311                          break;
312                  case 15:
313                  case 16:
314 <                        if (format != PIXFMT_RGB16) {
315 <                                ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR));
314 >                        // !!! PIXFMT_RGB15 is correct !!!
315 >                        if (format != PIXFMT_RGB15) {
316 >                                ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR);
317                                  return false;
318                          }
289                        VideoMonitor.mode = VMODE_16BIT;
319                          break;
320                  case 24:
321                  case 32:
322                          if (format != PIXFMT_ARGB32) {
323 <                                ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR));
323 >                                ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR);
324                                  return false;
325                          }
297                        VideoMonitor.mode = VMODE_32BIT;
326                          break;
327                  default:
328 <                        ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR));
328 >                        ErrorAlert(STR_WRONG_SCREEN_DEPTH_ERR);
329                          return false;
330          }
331  
# Line 305 | Line 333 | static bool init_screen_cgfx(ULONG mode_
333          uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id);
334          uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id);
335  
308        VideoMonitor.x = width;
309        VideoMonitor.y = height;
310
336          // Open screen
337          the_screen = OpenScreenTags(NULL,
338                  SA_DisplayID, mode_id,
# Line 317 | Line 342 | static bool init_screen_cgfx(ULONG mode_
342                  TAG_END
343          );
344          if (the_screen == NULL) {
345 <                ErrorAlert(GetString(STR_OPEN_SCREEN_ERR));
345 >                ErrorAlert(STR_OPEN_SCREEN_ERR);
346                  return false;
347          }
348  
# Line 334 | Line 359 | static bool init_screen_cgfx(ULONG mode_
359                  TAG_END
360          );
361          if (the_win == NULL) {
362 <                ErrorAlert(GetString(STR_OPEN_WINDOW_ERR));
362 >                ErrorAlert(STR_OPEN_WINDOW_ERR);
363                  return false;
364          }
365  
341        // Set VideoMonitor
366          ScreenToFront(the_screen);
367          static UWORD ptr[] = { 0, 0, 0, 0 };
368          SetPointer(the_win, ptr, 0, 0, 0, 0);   // Hide mouse pointer
369 +
370 +        // Set VideoMonitor
371 +        ULONG frame_base;
372          APTR handle = LockBitMapTags(the_screen->RastPort.BitMap,
373 <                        LBMI_BASEADDRESS, (ULONG)&VideoMonitor.mac_frame_base,
374 <                        TAG_END);
373 >                LBMI_BASEADDRESS, (ULONG)&frame_base,
374 >                TAG_END
375 >        );
376          UnLockBitMap(handle);
377 <        VideoMonitor.bytes_per_row = GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD);
377 >        set_video_monitor(width, height, GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD), depth);
378 >        VideoMonitor.mac_frame_base = frame_base;
379          return true;
380   }
381  
382   bool VideoInit(bool classic)
383   {
384 +        // Allocate blank mouse pointer data
385 +        null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR);
386 +        if (null_pointer == NULL) {
387 +                ErrorAlert(STR_NO_MEM_ERR);
388 +                return false;
389 +        }
390 +
391          // Read frame skip prefs
392          frame_skip = PrefsFindInt32("frameskip");
393          if (frame_skip == 0)
# Line 379 | Line 415 | bool VideoInit(bool classic)
415                          else if (CyberGfxBase && IsCyberModeID(mode_id))
416                                  display_type = DISPLAY_SCREEN_CGFX;
417                          else {
418 <                                ErrorAlert(GetString(STR_NO_P96_MODE_ERR));
418 >                                ErrorAlert(STR_NO_P96_MODE_ERR);
419                                  return false;
420                          }
421                  }
# Line 416 | Line 452 | bool VideoInit(bool classic)
452                  TAG_END
453          );
454          if (periodic_proc == NULL) {
455 <                ErrorAlert(GetString(STR_NO_MEM_ERR));
455 >                ErrorAlert(STR_NO_MEM_ERR);
456                  return false;
457          }
458          return true;
# Line 488 | Line 524 | void VideoExit(void)
524                          }
525                          break;
526          }
527 +
528 +        // Free mouse pointer
529 +        if (null_pointer) {
530 +                FreeMem(null_pointer, 12);
531 +                null_pointer = NULL;
532 +        }
533   }
534  
535  
# Line 495 | Line 537 | void VideoExit(void)
537   *  Set palette
538   */
539  
540 < void video_set_palette(uint8 *pal)
540 > void video_set_palette(uint8 *pal, int num)
541   {
542 <        if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) {
542 >        if ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX)
543 >         && !IsDirectMode(VideoMonitor.mode)) {
544  
545                  // Convert palette to 32 bits
546                  ULONG table[2 + 256 * 3];
547 <                table[0] = 256 << 16;
548 <                table[256 * 3 + 1] = 0;
549 <                for (int i=0; i<256; i++) {
547 >                table[0] = num << 16;
548 >                table[num * 3 + 1] = 0;
549 >                for (int i=0; i<num; i++) {
550                          table[i*3+1] = pal[i*3] * 0x01010101;
551                          table[i*3+2] = pal[i*3+1] * 0x01010101;
552                          table[i*3+3] = pal[i*3+2] * 0x01010101;
# Line 516 | Line 559 | void video_set_palette(uint8 *pal)
559  
560  
561   /*
562 + *  Switch video mode
563 + */
564 +
565 + void video_switch_to_mode(const video_mode &mode)
566 + {
567 + }
568 +
569 +
570 + /*
571 + *  Close down full-screen mode (if bringing up error alerts is unsafe while in full-screen mode)
572 + */
573 +
574 + void VideoQuitFullScreen(void)
575 + {
576 + }
577 +
578 +
579 + /*
580   *  Video message handling (not neccessary under AmigaOS, handled by periodic_func())
581   */
582  
# Line 573 | Line 634 | static __saveds void periodic_func(void)
634  
635                          // Timer tick, update display
636                          BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort,
637 <                                the_win->BorderLeft, the_win->BorderTop, VideoMonitor.x, VideoMonitor.y);
637 >                                the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y);
638  
639                          // Restart timer
640                          timer_io->tr_node.io_Command = TR_ADDREQUEST;
# Line 600 | Line 661 | static __saveds void periodic_func(void)
661                                          case IDCMP_MOUSEMOVE:
662                                                  if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX)
663                                                          ADBMouseMoved(mx, my);
664 <                                                else
664 >                                                else {
665                                                          ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop);
666 +                                                        if (mx < the_win->BorderLeft
667 +                                                         || my < the_win->BorderTop
668 +                                                         || mx >= the_win->BorderLeft + VideoMonitor.mode.x
669 +                                                         || my >= the_win->BorderTop + VideoMonitor.mode.y) {
670 +                                                                if (current_pointer) {
671 +                                                                        ClearPointer(the_win);
672 +                                                                        current_pointer = NULL;
673 +                                                                }
674 +                                                        } else {
675 +                                                                if (current_pointer != null_pointer) {
676 +                                                                        // Hide mouse pointer inside window
677 +                                                                        SetPointer(the_win, null_pointer, 1, 16, 0, 0);
678 +                                                                        current_pointer = null_pointer;
679 +                                                                }
680 +                                                        }
681 +                                                }
682                                                  break;
683  
684                                          case IDCMP_MOUSEBUTTONS:
# Line 622 | Line 699 | static __saveds void periodic_func(void)
699                                          case IDCMP_RAWKEY:
700                                                  if (qualifier & IEQUALIFIER_REPEAT)     // Keyboard repeat is done by MacOS
701                                                          break;
702 +                                                if ((qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) ==
703 +                                                    (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL) && code == 0x5f) {
704 +                                                        SetInterruptFlag(INTFLAG_NMI);
705 +                                                        TriggerInterrupt();
706 +                                                        break;
707 +                                                }
708 +
709                                                  if (code & IECODE_UP_PREFIX)
710                                                          ADBKeyUp(keycode2mac[code & 0x7f]);
711                                                  else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines