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 |
+ |
static int window_width, window_height; // width and height for window display |
66 |
+ |
static ULONG screen_mode_id; // mode ID for screen display |
67 |
|
|
68 |
|
extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) |
69 |
|
|
90 |
|
|
91 |
|
|
92 |
|
// Prototypes |
93 |
+ |
static bool video_open(const video_mode &mode); |
94 |
+ |
static void video_close(); |
95 |
|
static void periodic_func(void); |
96 |
+ |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth); |
97 |
+ |
static void add_modes(uint32 width, uint32 height, video_depth depth); |
98 |
+ |
static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth); |
99 |
+ |
static ULONG bits_from_depth(video_depth depth); |
100 |
|
|
101 |
|
|
102 |
|
/* |
103 |
|
* Initialization |
104 |
|
*/ |
105 |
|
|
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 |
– |
} |
106 |
|
|
107 |
|
// Open window |
108 |
|
static bool init_window(int width, int height) |
138 |
|
} |
139 |
|
|
140 |
|
// Add resolution and set VideoMonitor |
170 |
– |
set_video_monitor(width, height, the_bitmap->BytesPerRow, 1); |
141 |
|
VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0]; |
142 |
|
|
143 |
|
// Set FgPen and BgPen |
186 |
|
|
187 |
|
// Add resolution and set VideoMonitor |
188 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); |
189 |
< |
set_video_monitor(width, height, p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW), 16); |
189 |
> |
|
190 |
|
return true; |
191 |
|
} |
192 |
|
|
245 |
|
the_win = OpenWindowTags(NULL, |
246 |
|
WA_Left, 0, WA_Top, 0, |
247 |
|
WA_Width, width, WA_Height, height, |
248 |
+ |
WA_SimpleRefresh, TRUE, |
249 |
|
WA_NoCareRefresh, TRUE, |
250 |
|
WA_Borderless, TRUE, |
251 |
|
WA_Activate, TRUE, |
262 |
|
ScreenToFront(the_screen); |
263 |
|
|
264 |
|
// Add resolution and set VideoMonitor |
294 |
– |
set_video_monitor(width, height, p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW), depth); |
265 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
266 |
+ |
|
267 |
|
return true; |
268 |
|
} |
269 |
|
|
321 |
|
the_win = OpenWindowTags(NULL, |
322 |
|
WA_Left, 0, WA_Top, 0, |
323 |
|
WA_Width, width, WA_Height, height, |
324 |
+ |
WA_SimpleRefresh, TRUE, |
325 |
|
WA_NoCareRefresh, TRUE, |
326 |
|
WA_Borderless, TRUE, |
327 |
|
WA_Activate, TRUE, |
346 |
|
TAG_END |
347 |
|
); |
348 |
|
UnLockBitMap(handle); |
349 |
< |
set_video_monitor(width, height, GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD), depth); |
349 |
> |
|
350 |
|
VideoMonitor.mac_frame_base = frame_base; |
351 |
+ |
|
352 |
|
return true; |
353 |
|
} |
354 |
|
|
355 |
|
bool VideoInit(bool classic) |
356 |
|
{ |
357 |
+ |
int default_width, default_height, default_depth; |
358 |
+ |
|
359 |
|
// Allocate blank mouse pointer data |
360 |
|
null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR); |
361 |
|
if (null_pointer == NULL) { |
377 |
|
|
378 |
|
// Determine type and mode |
379 |
|
display_type = DISPLAY_WINDOW; |
380 |
< |
int width = 512, height = 384; |
381 |
< |
ULONG mode_id = 0; |
380 |
> |
|
381 |
> |
default_width = window_width = 512; |
382 |
> |
default_height = window_height = 384; |
383 |
> |
|
384 |
|
if (mode_str) { |
385 |
< |
if (sscanf(mode_str, "win/%d/%d", &width, &height) == 2) |
385 |
> |
if (sscanf(mode_str, "win/%d/%d", &window_width, &window_height) == 2) |
386 |
|
display_type = DISPLAY_WINDOW; |
387 |
< |
else if (sscanf(mode_str, "pip/%d/%d", &width, &height) == 2 && P96Base) |
387 |
> |
else if (sscanf(mode_str, "pip/%d/%d", &window_width, &window_height) == 2 && P96Base) |
388 |
|
display_type = DISPLAY_PIP; |
389 |
< |
else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && (CyberGfxBase || P96Base)) { |
390 |
< |
if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) |
389 |
> |
else if (sscanf(mode_str, "scr/%08lx", &screen_mode_id) == 1 && (CyberGfxBase || P96Base)) { |
390 |
> |
if (P96Base && p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) |
391 |
|
display_type = DISPLAY_SCREEN_P96; |
392 |
< |
else if (CyberGfxBase && IsCyberModeID(mode_id)) |
392 |
> |
else if (CyberGfxBase && IsCyberModeID(screen_mode_id)) |
393 |
|
display_type = DISPLAY_SCREEN_CGFX; |
394 |
|
else { |
395 |
|
ErrorAlert(STR_NO_P96_MODE_ERR); |
398 |
|
} |
399 |
|
} |
400 |
|
|
401 |
+ |
// Construct list of supported modes |
402 |
+ |
switch (display_type) { |
403 |
+ |
case DISPLAY_WINDOW: |
404 |
+ |
default_width = window_width; |
405 |
+ |
default_height = window_height; |
406 |
+ |
default_depth = 1; |
407 |
+ |
add_modes(window_width, window_height, VDEPTH_1BIT); |
408 |
+ |
break; |
409 |
+ |
|
410 |
+ |
case DISPLAY_PIP: |
411 |
+ |
default_depth = 16; |
412 |
+ |
default_width = window_width; |
413 |
+ |
default_height = window_height; |
414 |
+ |
add_modes(window_width, window_height, VDEPTH_16BIT); |
415 |
+ |
break; |
416 |
+ |
|
417 |
+ |
case DISPLAY_SCREEN_P96: |
418 |
+ |
case DISPLAY_SCREEN_CGFX: |
419 |
+ |
struct DimensionInfo dimInfo; |
420 |
+ |
DisplayInfoHandle handle = FindDisplayInfo(screen_mode_id); |
421 |
+ |
|
422 |
+ |
if (NULL == handle) |
423 |
+ |
return false; |
424 |
+ |
|
425 |
+ |
if (GetDisplayInfoData(handle, (UBYTE *) &dimInfo, sizeof(dimInfo), DTAG_DIMS, 0) <= 0) |
426 |
+ |
return false; |
427 |
+ |
|
428 |
+ |
default_width = 1 + dimInfo.Nominal.MaxX - dimInfo.Nominal.MinX; |
429 |
+ |
default_height = 1 + dimInfo.Nominal.MaxY - dimInfo.Nominal.MinY; |
430 |
+ |
default_depth = dimInfo.MaxDepth; |
431 |
+ |
|
432 |
+ |
for (unsigned d=VDEPTH_1BIT; d<=VDEPTH_32BIT; d++) |
433 |
+ |
{ |
434 |
+ |
if (INVALID_ID != find_mode_for_depth(default_width, default_height, bits_from_depth(video_depth(d)))) |
435 |
+ |
{ |
436 |
+ |
add_modes(default_width, default_height, video_depth(d)); |
437 |
+ |
} |
438 |
+ |
} |
439 |
+ |
break; |
440 |
+ |
} |
441 |
+ |
|
442 |
+ |
video_init_depth_list(); |
443 |
+ |
|
444 |
+ |
#if DEBUG |
445 |
+ |
bug("Available video modes:\n"); |
446 |
+ |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
447 |
+ |
while (i != end) { |
448 |
+ |
bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits_from_depth(i->depth)); |
449 |
+ |
++i; |
450 |
+ |
} |
451 |
+ |
#endif |
452 |
+ |
|
453 |
+ |
D(bug("VideoInit: def_width=%ld def_height=%ld def_depth=%ld\n", default_width, default_height, default_depth)); |
454 |
+ |
|
455 |
+ |
// Find requested default mode and open display |
456 |
+ |
if (VideoModes.size() == 1) |
457 |
+ |
return video_open(VideoModes[0]); |
458 |
+ |
else { |
459 |
+ |
// Find mode with specified dimensions |
460 |
+ |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
461 |
+ |
for (i = VideoModes.begin(); i != end; ++i) |
462 |
+ |
{ |
463 |
+ |
D(bug("VideoInit: w=%ld h=%ld d=%ld\n", i->x, i->y, bits_from_depth(i->depth))); |
464 |
+ |
if (i->x == default_width && i->y == default_height && bits_from_depth(i->depth) == default_depth) |
465 |
+ |
return video_open(*i); |
466 |
+ |
} |
467 |
+ |
return video_open(VideoModes[0]); |
468 |
+ |
} |
469 |
+ |
|
470 |
+ |
return true; |
471 |
+ |
} |
472 |
+ |
|
473 |
+ |
|
474 |
+ |
static bool video_open(const video_mode &mode) |
475 |
+ |
{ |
476 |
+ |
ULONG depth_bits = bits_from_depth(mode.depth); |
477 |
+ |
ULONG ID = find_mode_for_depth(mode.x, mode.y, depth_bits); |
478 |
+ |
|
479 |
+ |
D(bug("video_open: width=%ld height=%ld depth=%ld ID=%08lx\n", mode.x, mode.y, depth_bits, ID)); |
480 |
+ |
|
481 |
+ |
if (INVALID_ID == ID) |
482 |
+ |
{ |
483 |
+ |
ErrorAlert(STR_NO_VIDEO_MODE_ERR); |
484 |
+ |
return false; |
485 |
+ |
} |
486 |
+ |
|
487 |
+ |
VideoMonitor.mode = mode; |
488 |
+ |
|
489 |
|
// Open display |
490 |
|
switch (display_type) { |
491 |
|
case DISPLAY_WINDOW: |
492 |
< |
if (!init_window(width, height)) |
492 |
> |
if (!init_window(mode.x, mode.y)) |
493 |
|
return false; |
494 |
|
break; |
495 |
|
|
496 |
|
case DISPLAY_PIP: |
497 |
< |
if (!init_pip(width, height)) |
497 |
> |
if (!init_pip(mode.x, mode.y)) |
498 |
|
return false; |
499 |
|
break; |
500 |
|
|
501 |
|
case DISPLAY_SCREEN_P96: |
502 |
< |
if (!init_screen_p96(mode_id)) |
502 |
> |
if (!init_screen_p96(ID)) |
503 |
|
return false; |
504 |
|
break; |
505 |
|
|
506 |
|
case DISPLAY_SCREEN_CGFX: |
507 |
< |
if (!init_screen_cgfx(mode_id)) |
507 |
> |
if (!init_screen_cgfx(ID)) |
508 |
|
return false; |
509 |
|
break; |
510 |
|
} |
520 |
|
ErrorAlert(STR_NO_MEM_ERR); |
521 |
|
return false; |
522 |
|
} |
523 |
+ |
|
524 |
|
return true; |
525 |
|
} |
526 |
|
|
527 |
|
|
528 |
< |
/* |
463 |
< |
* Deinitialization |
464 |
< |
*/ |
465 |
< |
|
466 |
< |
void VideoExit(void) |
528 |
> |
static void video_close() |
529 |
|
{ |
530 |
|
// Stop periodic process |
531 |
|
if (periodic_proc) { |
550 |
|
ReleasePen(the_win->WScreen->ViewPort.ColorMap, white_pen); |
551 |
|
|
552 |
|
CloseWindow(the_win); |
553 |
+ |
the_win = NULL; |
554 |
|
} |
555 |
|
break; |
556 |
|
|
565 |
|
|
566 |
|
// Close window |
567 |
|
if (the_win) |
568 |
+ |
{ |
569 |
|
CloseWindow(the_win); |
570 |
+ |
the_win = NULL; |
571 |
+ |
} |
572 |
|
|
573 |
|
// Close screen |
574 |
|
if (the_screen) { |
581 |
|
|
582 |
|
// Close window |
583 |
|
if (the_win) |
584 |
+ |
{ |
585 |
|
CloseWindow(the_win); |
586 |
+ |
the_win = NULL; |
587 |
+ |
} |
588 |
|
|
589 |
|
// Close screen |
590 |
|
if (the_screen) { |
603 |
|
|
604 |
|
|
605 |
|
/* |
606 |
+ |
* Deinitialization |
607 |
+ |
*/ |
608 |
+ |
|
609 |
+ |
void VideoExit(void) |
610 |
+ |
{ |
611 |
+ |
video_close(); |
612 |
+ |
} |
613 |
+ |
|
614 |
+ |
|
615 |
+ |
/* |
616 |
|
* Set palette |
617 |
|
*/ |
618 |
|
|
619 |
< |
void video_set_palette(uint8 *pal, in num) |
619 |
> |
void video_set_palette(uint8 *pal, int num) |
620 |
|
{ |
621 |
|
if ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
622 |
|
&& !IsDirectMode(VideoMonitor.mode)) { |
643 |
|
|
644 |
|
void video_switch_to_mode(const video_mode &mode) |
645 |
|
{ |
646 |
+ |
// Close and reopen display |
647 |
+ |
video_close(); |
648 |
+ |
if (!video_open(mode)) |
649 |
+ |
{ |
650 |
+ |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
651 |
+ |
QuitEmulator(); |
652 |
+ |
} |
653 |
+ |
} |
654 |
+ |
|
655 |
+ |
|
656 |
+ |
/* |
657 |
+ |
* Close down full-screen mode (if bringing up error alerts is unsafe while in full-screen mode) |
658 |
+ |
*/ |
659 |
+ |
|
660 |
+ |
void VideoQuitFullScreen(void) |
661 |
+ |
{ |
662 |
|
} |
663 |
|
|
664 |
|
|
833 |
|
Forbid(); |
834 |
|
Signal(MainTask, SIGF_SINGLE); |
835 |
|
} |
836 |
+ |
|
837 |
+ |
|
838 |
+ |
// Add mode to list of supported modes |
839 |
+ |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
840 |
+ |
{ |
841 |
+ |
video_mode mode; |
842 |
+ |
mode.x = width; |
843 |
+ |
mode.y = height; |
844 |
+ |
mode.resolution_id = resolution_id; |
845 |
+ |
mode.bytes_per_row = bytes_per_row; |
846 |
+ |
mode.depth = depth; |
847 |
+ |
|
848 |
+ |
D(bug("Added video mode: w=%ld h=%ld d=%ld\n", width, height, depth)); |
849 |
+ |
|
850 |
+ |
VideoModes.push_back(mode); |
851 |
+ |
} |
852 |
+ |
|
853 |
+ |
// Add standard list of windowed modes for given color depth |
854 |
+ |
static void add_modes(uint32 width, uint32 height, video_depth depth) |
855 |
+ |
{ |
856 |
+ |
D(bug("add_modes: w=%ld h=%ld d=%ld\n", width, height, depth)); |
857 |
+ |
|
858 |
+ |
if (width >= 512 && height >= 384) |
859 |
+ |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
860 |
+ |
if (width >= 640 && height >= 480) |
861 |
+ |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
862 |
+ |
if (width >= 800 && height >= 600) |
863 |
+ |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
864 |
+ |
if (width >= 1024 && height >= 768) |
865 |
+ |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
866 |
+ |
if (width >= 1152 && height >= 870) |
867 |
+ |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
868 |
+ |
if (width >= 1280 && height >= 1024) |
869 |
+ |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
870 |
+ |
if (width >= 1600 && height >= 1200) |
871 |
+ |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
872 |
+ |
} |
873 |
+ |
|
874 |
+ |
|
875 |
+ |
static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth) |
876 |
+ |
{ |
877 |
+ |
ULONG ID = BestModeID(BIDTAG_NominalWidth, width, |
878 |
+ |
BIDTAG_NominalHeight, height, |
879 |
+ |
BIDTAG_Depth, depth, |
880 |
+ |
TAG_END); |
881 |
+ |
|
882 |
+ |
return ID; |
883 |
+ |
} |
884 |
+ |
|
885 |
+ |
|
886 |
+ |
static ULONG bits_from_depth(video_depth depth) |
887 |
+ |
{ |
888 |
+ |
int bits = 1 << depth; |
889 |
+ |
if (bits == 16) |
890 |
+ |
bits = 15; |
891 |
+ |
else if (bits == 32) |
892 |
+ |
bits = 24; |
893 |
+ |
|
894 |
+ |
return bits; |
895 |
+ |
} |
896 |
+ |
|