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

Comparing BasiliskII/src/video.cpp (file contents):
Revision 1.15 by cebix, 2001-06-30T22:23:43Z vs.
Revision 1.19 by cebix, 2001-07-01T21:09:26Z

# Line 40 | Line 40
40  
41  
42   // List of supported video modes
43 < std::vector<video_mode> VideoModes;
43 > vector<video_mode> VideoModes;
44  
45   // Description of the main monitor
46   monitor_desc VideoMonitor;
# Line 57 | Line 57 | struct {
57          uint32 current_id;
58          uint16 preferred_mode;          // Preferred depth/resolution
59          uint32 preferred_id;
60 <        uint32 sp;                                      // Mac address of Slot Manager parameter block
60 >        uint32 slot_param;                      // Mac address of Slot Manager parameter block
61   } VidLocal;
62  
63  
# Line 67 | Line 67 | struct {
67  
68   static bool has_resolution(uint32 id)
69   {
70 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
71 <        while (i != end) {
70 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
71 >        for (i = VideoModes.begin(); i != end; ++i) {
72                  if (i->resolution_id == id)
73                          return true;
74                ++i;
74          }
75          return false;
76   }
# Line 81 | Line 80 | static bool has_resolution(uint32 id)
80   *  Find specified mode (depth/resolution) (or VideoModes.end() if not found)
81   */
82  
83 < static std::vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
83 > static vector<video_mode>::const_iterator find_mode(uint16 mode, uint32 id)
84   {
85 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
86 <        while (i != end) {
85 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
86 >        for (i = VideoModes.begin(); i != end; ++i) {
87                  if (i->resolution_id == id && DepthToAppleMode(i->depth) == mode)
88                          return i;
90                ++i;
89          }
90          return i;
91   }
# Line 100 | Line 98 | static std::vector<video_mode>::const_it
98   static video_depth max_depth_of_resolution(uint32 id)
99   {
100          video_depth m = VDEPTH_1BIT;
101 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
102 <        while (i != end) {
101 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
102 >        for (i = VideoModes.begin(); i != end; ++i) {
103                  if (i->depth > m)
104                          m = i->depth;
107                ++i;
105          }
106          return m;
107   }
# Line 116 | Line 113 | static video_depth max_depth_of_resoluti
113  
114   static void get_size_of_resolution(uint32 id, uint32 &x, uint32 &y)
115   {
116 <        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
117 <        while (i != end) {
116 >        vector<video_mode>::const_iterator i, end = VideoModes.end();
117 >        for (i = VideoModes.begin(); i != end; ++i) {
118                  if (i->resolution_id == id) {
119                          x = i->x;
120                          y = i->y;
121                          return;
122                  }
123 <                ++i;
123 >        }
124 > }
125 >
126 >
127 > /*
128 > *  Find palette size for given color depth
129 > */
130 >
131 > static int palette_size(video_depth depth)
132 > {
133 >        switch (depth) {
134 >                case VDEPTH_1BIT: return 2;
135 >                case VDEPTH_2BIT: return 4;
136 >                case VDEPTH_4BIT: return 16;
137 >                case VDEPTH_8BIT: return 256;
138 >                case VDEPTH_16BIT: return 32;
139 >                case VDEPTH_32BIT: return 256;
140 >                default: return 0;
141          }
142   }
143  
# Line 139 | Line 153 | static void set_gray_palette(void)
153                  VidLocal.palette[i * 3 + 1] = 127;
154                  VidLocal.palette[i * 3 + 2] = 127;
155          }
156 <        video_set_palette(VidLocal.palette);
156 >        video_set_palette(VidLocal.palette, 256);
157   }
158  
159  
# Line 182 | Line 196 | static void load_ramp_palette(void)
196                  *p++ = blue;
197          }
198  
199 <        video_set_palette(VidLocal.palette);
199 >        video_set_palette(VidLocal.palette, num);
200   }
201  
202  
# Line 273 | Line 287 | static bool set_gamma_table(uint32 user_
287  
288  
289   /*
290 + *  Switch video mode
291 + */
292 +
293 + static void switch_mode(const video_mode &mode, uint32 param, uint32 dce)
294 + {
295 +        // Switch mode
296 +        set_gray_palette();
297 +        video_switch_to_mode(mode);
298 +
299 +        // Update VidLocal
300 +        VidLocal.current_mode = DepthToAppleMode(mode.depth);
301 +        VidLocal.current_id = mode.resolution_id;
302 +
303 +        uint32 frame_base = VidLocal.desc->mac_frame_base;
304 +
305 +        M68kRegisters r;
306 +        uint32 sp = VidLocal.slot_param;
307 +        r.a[0] = sp;
308 +
309 +        // Find functional sResource for this display
310 +        WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
311 +        WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
312 +        WriteMacInt8(sp + spExtDev, 0);
313 +        r.d[0] = 0x0016;
314 +        Execute68kTrap(0xa06e, &r);     // SRsrcInfo()
315 +        uint32 rsrc = ReadMacInt32(sp + spPointer);
316 +
317 +        // Patch minorBase (otherwise rebooting won't work)
318 +        WriteMacInt8(sp + spID, 0x0a); // minorBase
319 +        r.d[0] = 0x0006;
320 +        Execute68kTrap(0xa06e, &r); // SFindStruct()
321 +        uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
322 +        ROMBaseHost[minor_base + 0] = frame_base >> 24;
323 +        ROMBaseHost[minor_base + 1] = frame_base >> 16;
324 +        ROMBaseHost[minor_base + 2] = frame_base >> 8;
325 +        ROMBaseHost[minor_base + 3] = frame_base;
326 +
327 +        // Patch video mode parameter table
328 +        WriteMacInt32(sp + spPointer, rsrc);
329 +        WriteMacInt8(sp + spID, DepthToAppleMode(mode.depth));
330 +        r.d[0] = 0x0006;
331 +        Execute68kTrap(0xa06e, &r); // SFindStruct()
332 +        WriteMacInt8(sp + spID, 0x01);
333 +        r.d[0] = 0x0006;
334 +        Execute68kTrap(0xa06e, &r); // SFindStruct()
335 +        uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
336 +        ROMBaseHost[p +  8] = mode.bytes_per_row >> 8;
337 +        ROMBaseHost[p +  9] = mode.bytes_per_row;
338 +        ROMBaseHost[p + 14] = mode.y >> 8;
339 +        ROMBaseHost[p + 15] = mode.y;
340 +        ROMBaseHost[p + 16] = mode.x >> 8;
341 +        ROMBaseHost[p + 17] = mode.x;
342 +
343 +        // Recalculate slot ROM checksum
344 +        ChecksumSlotROM();
345 +
346 +        // Update sResource
347 +        WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
348 +        r.d[0] = 0x002b;
349 +        Execute68kTrap(0xa06e, &r); // SUpdateSRT()
350 +
351 +        // Update frame buffer base in DCE and param block
352 +        WriteMacInt32(dce + dCtlDevBase, frame_base);
353 +        WriteMacInt32(param + csBaseAddr, frame_base);
354 + }
355 +
356 +
357 + /*
358   *  Driver Open() routine
359   */
360  
# Line 299 | Line 381 | int16 VideoDriverOpen(uint32 pb, uint32
381          Execute68kTrap(0xa71e, &r);     // NewPtrSysClear()
382          if (r.a[0] == 0)
383                  return memFullErr;
384 <        VidLocal.sp = r.a[0];
385 <        D(bug("SPBlock at %08x\n", VidLocal.sp));
384 >        VidLocal.slot_param = r.a[0];
385 >        D(bug("SPBlock at %08x\n", VidLocal.slot_param));
386  
387          // Find and set default gamma table
388          VidLocal.gamma_table = 0;
# Line 335 | Line 417 | int16 VideoDriverControl(uint32 pb, uint
417                                  return paramErr;
418  
419                          if (mode != VidLocal.current_mode) {
420 <                                std::vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
420 >                                vector<video_mode>::const_iterator i = find_mode(mode, VidLocal.current_id);
421                                  if (i == VideoModes.end())
422                                          return paramErr;
423 <                                set_gray_palette();
342 <                                video_switch_to_mode(*i);
343 <                                VidLocal.current_mode = mode;
344 <                                WriteMacInt32(param + csBaseAddr, VidLocal.desc->mac_frame_base);
345 <                                WriteMacInt32(dce + dCtlDevBase, VidLocal.desc->mac_frame_base);
423 >                                switch_mode(*i, param, dce);
424                          }
425                          D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
426                          return noErr;
# Line 423 | Line 501 | int16 VideoDriverControl(uint32 pb, uint
501                                          s_pal += 8;
502                                  }
503                          }
504 <                        video_set_palette(VidLocal.palette);
504 >                        video_set_palette(VidLocal.palette, palette_size(VidLocal.desc->mode.depth));
505                          return noErr;
506                  }
507  
# Line 494 | Line 572 | int16 VideoDriverControl(uint32 pb, uint
572                                  return paramErr;
573  
574                          if (mode != VidLocal.current_mode || id != VidLocal.current_id) {
575 <                                std::vector<video_mode>::const_iterator i = find_mode(mode, id);
575 >                                vector<video_mode>::const_iterator i = find_mode(mode, id);
576                                  if (i == VideoModes.end())
577                                          return paramErr;
578 <                                set_gray_palette();
501 <                                video_switch_to_mode(*i);
502 <                                VidLocal.current_mode = mode;
503 <                                VidLocal.current_id = id;
504 <                                uint32 frame_base = VidLocal.desc->mac_frame_base;
505 <                                WriteMacInt32(param + csBaseAddr, frame_base);
506 <
507 <                                M68kRegisters r;
508 <                                uint32 sp = VidLocal.sp;
509 <                                r.a[0] = sp;
510 <
511 <                                // Find functional sResource for this display
512 <                                WriteMacInt8(sp + spSlot, ReadMacInt8(dce + dCtlSlot));
513 <                                WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
514 <                                WriteMacInt8(sp + spExtDev, 0);
515 <                                r.d[0] = 0x0016;
516 <                                Execute68kTrap(0xa06e, &r);     // SRsrcInfo()
517 <                                uint32 rsrc = ReadMacInt32(sp + spPointer);
518 <
519 <                                // Patch minorBase (otherwise rebooting won't work)
520 <                                WriteMacInt8(sp + spID, 0x0a); // minorBase
521 <                                r.d[0] = 0x0006;
522 <                                Execute68kTrap(0xa06e, &r); // SFindStruct()
523 <                                uint32 minor_base = ReadMacInt32(sp + spPointer) - ROMBaseMac;
524 <                                ROMBaseHost[minor_base + 0] = frame_base >> 24;
525 <                                ROMBaseHost[minor_base + 1] = frame_base >> 16;
526 <                                ROMBaseHost[minor_base + 2] = frame_base >> 8;
527 <                                ROMBaseHost[minor_base + 3] = frame_base;
528 <
529 <                                // Patch video mode parameter table
530 <                                WriteMacInt32(sp + spPointer, rsrc);
531 <                                WriteMacInt8(sp + spID, mode);
532 <                                r.d[0] = 0x0006;
533 <                                Execute68kTrap(0xa06e, &r); // SFindStruct()
534 <                                WriteMacInt8(sp + spID, 0x01);
535 <                                r.d[0] = 0x0006;
536 <                                Execute68kTrap(0xa06e, &r); // SFindStruct()
537 <                                uint32 p = ReadMacInt32(sp + spPointer) - ROMBaseMac;
538 <                                ROMBaseHost[p +  8] = i->bytes_per_row >> 8;
539 <                                ROMBaseHost[p +  9] = i->bytes_per_row;
540 <                                ROMBaseHost[p + 14] = i->y >> 8;
541 <                                ROMBaseHost[p + 15] = i->y;
542 <                                ROMBaseHost[p + 16] = i->x >> 8;
543 <                                ROMBaseHost[p + 17] = i->x;
544 <
545 <                                // Recalculate slot ROM checksum
546 <                                ChecksumSlotROM();
547 <
548 <                                // Update sResource
549 <                                WriteMacInt8(sp + spID, ReadMacInt8(dce + dCtlSlotId));
550 <                                r.d[0] = 0x002b;
551 <                                Execute68kTrap(0xa06e, &r); // SUpdateSRT()
552 <
553 <                                // Update frame buffer base in DCE
554 <                                WriteMacInt32(dce + dCtlDevBase, frame_base);
578 >                                switch_mode(*i, param, dce);
579                          }
580                          D(bug("  base %08x\n", VidLocal.desc->mac_frame_base));
581                          return noErr;
# Line 751 | Line 775 | int16 VideoDriverStatus(uint32 pb, uint3
775                          uint16 mode = ReadMacInt16(param + csDepthMode);
776                          D(bug(" GetVideoParameters %04x/%08x\n", mode, id));
777  
778 <                        std::vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end();
779 <                        while (i != end) {
778 >                        vector<video_mode>::const_iterator i, end = VideoModes.end();
779 >                        for (i = VideoModes.begin(); i != end; ++i) {
780                                  if (DepthToAppleMode(i->depth) == mode && i->resolution_id == id) {
781                                          uint32 vp = ReadMacInt32(param + csVPBlockPtr);
782                                          WriteMacInt32(vp + vpBaseOffset, 0);
# Line 807 | Line 831 | int16 VideoDriverStatus(uint32 pb, uint3
831                                          WriteMacInt32(param + csDeviceType, dev_type);
832                                          return noErr;
833                                  }
810                                ++i;
834                          }
835                          return paramErr; // specified resolution/depth not supported
836                  }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines