1 |
|
/* |
2 |
|
* video_amiga.cpp - Video/graphics emulation, AmigaOS specific stuff |
3 |
|
* |
4 |
< |
* Basilisk II (C) 1997-1999 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 |
22 |
|
#include <intuition/intuition.h> |
23 |
|
#include <graphics/rastport.h> |
24 |
|
#include <graphics/gfx.h> |
25 |
+ |
#include <cybergraphics/cybergraphics.h> |
26 |
|
#include <dos/dostags.h> |
27 |
|
#include <devices/timer.h> |
28 |
|
#include <proto/exec.h> |
30 |
|
#include <proto/intuition.h> |
31 |
|
#include <proto/graphics.h> |
32 |
|
#include <proto/Picasso96.h> |
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" |
40 |
|
#include "user_strings.h" |
41 |
|
#include "video.h" |
42 |
|
|
43 |
< |
#define DEBUG 1 |
43 |
> |
#define DEBUG 0 |
44 |
|
#include "debug.h" |
45 |
|
|
46 |
|
|
48 |
|
enum { |
49 |
|
DISPLAY_WINDOW, |
50 |
|
DISPLAY_PIP, |
51 |
< |
DISPLAY_SCREEN |
51 |
> |
DISPLAY_SCREEN_P96, |
52 |
> |
DISPLAY_SCREEN_CGFX |
53 |
|
}; |
54 |
|
|
55 |
|
// Global variables |
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 |
|
|
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 |
+ |
mode.depth = VDEPTH_16BIT; |
123 |
+ |
break; |
124 |
+ |
case 16: |
125 |
+ |
mode.depth = VDEPTH_16BIT; |
126 |
+ |
break; |
127 |
+ |
case 24: |
128 |
+ |
case 32: |
129 |
+ |
mode.depth = VDEPTH_32BIT; |
130 |
+ |
break; |
131 |
+ |
} |
132 |
+ |
|
133 |
+ |
VideoModes.push_back(mode); |
134 |
+ |
VideoMonitor.mode = mode; |
135 |
+ |
} |
136 |
+ |
|
137 |
|
// Open window |
138 |
|
static bool init_window(int width, int height) |
139 |
|
{ |
167 |
|
return false; |
168 |
|
} |
169 |
|
|
170 |
< |
// Set VideoMonitor |
170 |
> |
// Add resolution and set VideoMonitor |
171 |
> |
set_video_monitor(width, height, the_bitmap->BytesPerRow, 1); |
172 |
|
VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0]; |
127 |
– |
VideoMonitor.bytes_per_row = the_bitmap->BytesPerRow; |
128 |
– |
VideoMonitor.x = width; |
129 |
– |
VideoMonitor.y = height; |
130 |
– |
VideoMonitor.mode = VMODE_1BIT; |
173 |
|
|
174 |
|
// Set FgPen and BgPen |
175 |
|
black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); |
215 |
|
// Find bitmap |
216 |
|
p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); |
217 |
|
|
218 |
< |
// Set VideoMonitor |
218 |
> |
// Add resolution and set VideoMonitor |
219 |
> |
set_video_monitor(width, height, p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW), 16); |
220 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); |
178 |
– |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW); |
179 |
– |
VideoMonitor.x = width; |
180 |
– |
VideoMonitor.y = height; |
181 |
– |
VideoMonitor.mode = VMODE_16BIT; |
221 |
|
return true; |
222 |
|
} |
223 |
|
|
224 |
< |
// Open screen (requires Picasso96 as we need chunky modes) |
225 |
< |
static bool init_screen(ULONG mode_id) |
224 |
> |
// Open Picasso96 screen |
225 |
> |
static bool init_screen_p96(ULONG mode_id) |
226 |
|
{ |
227 |
|
// Set relative mouse mode |
228 |
|
ADBSetRelMouseMode(true); |
229 |
|
|
191 |
– |
// Check if the mode is a Picasso96 mode |
192 |
– |
if (!p96GetModeIDAttr(mode_id, P96IDA_ISP96)) { |
193 |
– |
ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); |
194 |
– |
return false; |
195 |
– |
} |
196 |
– |
|
230 |
|
// Check if the mode is one we can handle |
231 |
|
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
232 |
|
uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
233 |
+ |
|
234 |
|
switch (depth) { |
235 |
|
case 8: |
202 |
– |
VideoMonitor.mode = VMODE_8BIT; |
236 |
|
break; |
237 |
|
case 15: |
238 |
|
case 16: |
240 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
241 |
|
return false; |
242 |
|
} |
210 |
– |
VideoMonitor.mode = VMODE_16BIT; |
243 |
|
break; |
244 |
|
case 24: |
245 |
|
case 32: |
247 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
248 |
|
return false; |
249 |
|
} |
218 |
– |
VideoMonitor.mode = VMODE_32BIT; |
250 |
|
break; |
251 |
|
default: |
252 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
256 |
|
// Yes, get width and height |
257 |
|
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
258 |
|
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
228 |
– |
VideoMonitor.x = width; |
229 |
– |
VideoMonitor.y = height; |
259 |
|
|
260 |
|
// Open screen |
261 |
|
the_screen = p96OpenScreenTags( |
289 |
|
return false; |
290 |
|
} |
291 |
|
|
263 |
– |
// Set VideoMonitor |
292 |
|
ScreenToFront(the_screen); |
293 |
+ |
|
294 |
+ |
// Add resolution and set VideoMonitor |
295 |
+ |
set_video_monitor(width, height, p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW), depth); |
296 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
297 |
< |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); |
297 |
> |
return true; |
298 |
> |
} |
299 |
> |
|
300 |
> |
// Open CyberGraphX screen |
301 |
> |
static bool init_screen_cgfx(ULONG mode_id) |
302 |
> |
{ |
303 |
> |
// Set relative mouse mode |
304 |
> |
ADBSetRelMouseMode(true); |
305 |
> |
|
306 |
> |
// Check if the mode is one we can handle |
307 |
> |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
308 |
> |
uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
309 |
> |
|
310 |
> |
switch (depth) { |
311 |
> |
case 8: |
312 |
> |
break; |
313 |
> |
case 15: |
314 |
> |
case 16: |
315 |
> |
// !!! PIXFMT_RGB15 is correct !!! |
316 |
> |
if (format != PIXFMT_RGB15) { |
317 |
> |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
318 |
> |
return false; |
319 |
> |
} |
320 |
> |
break; |
321 |
> |
case 24: |
322 |
> |
case 32: |
323 |
> |
if (format != PIXFMT_ARGB32) { |
324 |
> |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
325 |
> |
return false; |
326 |
> |
} |
327 |
> |
break; |
328 |
> |
default: |
329 |
> |
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
330 |
> |
return false; |
331 |
> |
} |
332 |
> |
|
333 |
> |
// Yes, get width and height |
334 |
> |
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
335 |
> |
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
336 |
> |
|
337 |
> |
// Open screen |
338 |
> |
the_screen = OpenScreenTags(NULL, |
339 |
> |
SA_DisplayID, mode_id, |
340 |
> |
SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
341 |
> |
SA_Quiet, TRUE, |
342 |
> |
SA_Exclusive, TRUE, |
343 |
> |
TAG_END |
344 |
> |
); |
345 |
> |
if (the_screen == NULL) { |
346 |
> |
ErrorAlert(GetString(STR_OPEN_SCREEN_ERR)); |
347 |
> |
return false; |
348 |
> |
} |
349 |
> |
|
350 |
> |
// Open window |
351 |
> |
the_win = OpenWindowTags(NULL, |
352 |
> |
WA_Left, 0, WA_Top, 0, |
353 |
> |
WA_Width, width, WA_Height, height, |
354 |
> |
WA_NoCareRefresh, TRUE, |
355 |
> |
WA_Borderless, TRUE, |
356 |
> |
WA_Activate, TRUE, |
357 |
> |
WA_RMBTrap, TRUE, |
358 |
> |
WA_ReportMouse, TRUE, |
359 |
> |
WA_CustomScreen, (ULONG)the_screen, |
360 |
> |
TAG_END |
361 |
> |
); |
362 |
> |
if (the_win == NULL) { |
363 |
> |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
364 |
> |
return false; |
365 |
> |
} |
366 |
> |
|
367 |
> |
ScreenToFront(the_screen); |
368 |
> |
static UWORD ptr[] = { 0, 0, 0, 0 }; |
369 |
> |
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer |
370 |
> |
|
371 |
> |
// Set VideoMonitor |
372 |
> |
ULONG frame_base; |
373 |
> |
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
374 |
> |
LBMI_BASEADDRESS, (ULONG)&frame_base, |
375 |
> |
TAG_END |
376 |
> |
); |
377 |
> |
UnLockBitMap(handle); |
378 |
> |
set_video_monitor(width, height, GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD), depth); |
379 |
> |
VideoMonitor.mac_frame_base = frame_base; |
380 |
|
return true; |
381 |
|
} |
382 |
|
|
383 |
|
bool VideoInit(bool classic) |
384 |
|
{ |
385 |
+ |
// Allocate blank mouse pointer data |
386 |
+ |
null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR); |
387 |
+ |
if (null_pointer == NULL) { |
388 |
+ |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
389 |
+ |
return false; |
390 |
+ |
} |
391 |
+ |
|
392 |
|
// Read frame skip prefs |
393 |
|
frame_skip = PrefsFindInt32("frameskip"); |
394 |
|
if (frame_skip == 0) |
410 |
|
display_type = DISPLAY_WINDOW; |
411 |
|
else if (sscanf(mode_str, "pip/%d/%d", &width, &height) == 2 && P96Base) |
412 |
|
display_type = DISPLAY_PIP; |
413 |
< |
else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && P96Base) |
414 |
< |
display_type = DISPLAY_SCREEN; |
413 |
> |
else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && (CyberGfxBase || P96Base)) { |
414 |
> |
if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) |
415 |
> |
display_type = DISPLAY_SCREEN_P96; |
416 |
> |
else if (CyberGfxBase && IsCyberModeID(mode_id)) |
417 |
> |
display_type = DISPLAY_SCREEN_CGFX; |
418 |
> |
else { |
419 |
> |
ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); |
420 |
> |
return false; |
421 |
> |
} |
422 |
> |
} |
423 |
|
} |
424 |
|
|
425 |
|
// Open display |
434 |
|
return false; |
435 |
|
break; |
436 |
|
|
437 |
< |
case DISPLAY_SCREEN: |
438 |
< |
if (!init_screen(mode_id)) |
437 |
> |
case DISPLAY_SCREEN_P96: |
438 |
> |
if (!init_screen_p96(mode_id)) |
439 |
> |
return false; |
440 |
> |
break; |
441 |
> |
|
442 |
> |
case DISPLAY_SCREEN_CGFX: |
443 |
> |
if (!init_screen_cgfx(mode_id)) |
444 |
|
return false; |
445 |
|
break; |
446 |
|
} |
499 |
|
p96PIP_Close(the_win); |
500 |
|
break; |
501 |
|
|
502 |
< |
case DISPLAY_SCREEN: |
502 |
> |
case DISPLAY_SCREEN_P96: |
503 |
|
|
504 |
|
// Close window |
505 |
|
if (the_win) |
506 |
|
CloseWindow(the_win); |
507 |
|
|
508 |
|
// Close screen |
509 |
< |
if (the_screen) |
509 |
> |
if (the_screen) { |
510 |
|
p96CloseScreen(the_screen); |
511 |
+ |
the_screen = NULL; |
512 |
+ |
} |
513 |
+ |
break; |
514 |
+ |
|
515 |
+ |
case DISPLAY_SCREEN_CGFX: |
516 |
+ |
|
517 |
+ |
// Close window |
518 |
+ |
if (the_win) |
519 |
+ |
CloseWindow(the_win); |
520 |
+ |
|
521 |
+ |
// Close screen |
522 |
+ |
if (the_screen) { |
523 |
+ |
CloseScreen(the_screen); |
524 |
+ |
the_screen = NULL; |
525 |
+ |
} |
526 |
|
break; |
527 |
|
} |
528 |
+ |
|
529 |
+ |
// Free mouse pointer |
530 |
+ |
if (null_pointer) { |
531 |
+ |
FreeMem(null_pointer, 12); |
532 |
+ |
null_pointer = NULL; |
533 |
+ |
} |
534 |
|
} |
535 |
|
|
536 |
|
|
540 |
|
|
541 |
|
void video_set_palette(uint8 *pal) |
542 |
|
{ |
543 |
< |
if (display_type == DISPLAY_SCREEN) { |
543 |
> |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) { |
544 |
|
|
545 |
|
// Convert palette to 32 bits |
546 |
|
ULONG table[2 + 256 * 3]; |
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 |
|
* Video message handling (not neccessary under AmigaOS, handled by periodic_func()) |
572 |
|
*/ |
573 |
|
|
592 |
|
if (win_port) { |
593 |
|
win_mask = 1 << win_port->mp_SigBit; |
594 |
|
the_win->UserPort = win_port; |
595 |
< |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | (display_type == DISPLAY_SCREEN ? IDCMP_DELTAMOVE : 0)); |
595 |
> |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); |
596 |
|
} |
597 |
|
|
598 |
|
// Start 60Hz timer for window refresh |
625 |
|
|
626 |
|
// Timer tick, update display |
627 |
|
BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, |
628 |
< |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.x, VideoMonitor.y); |
628 |
> |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); |
629 |
|
|
630 |
|
// Restart timer |
631 |
|
timer_io->tr_node.io_Command = TR_ADDREQUEST; |
650 |
|
// Handle message according to class |
651 |
|
switch (cl) { |
652 |
|
case IDCMP_MOUSEMOVE: |
653 |
< |
if (display_type == DISPLAY_SCREEN) |
653 |
> |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
654 |
|
ADBMouseMoved(mx, my); |
655 |
< |
else |
655 |
> |
else { |
656 |
|
ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); |
657 |
+ |
if (mx < the_win->BorderLeft |
658 |
+ |
|| my < the_win->BorderTop |
659 |
+ |
|| mx >= the_win->BorderLeft + VideoMonitor.mode.x |
660 |
+ |
|| my >= the_win->BorderTop + VideoMonitor.mode.y) { |
661 |
+ |
if (current_pointer) { |
662 |
+ |
ClearPointer(the_win); |
663 |
+ |
current_pointer = NULL; |
664 |
+ |
} |
665 |
+ |
} else { |
666 |
+ |
if (current_pointer != null_pointer) { |
667 |
+ |
// Hide mouse pointer inside window |
668 |
+ |
SetPointer(the_win, null_pointer, 1, 16, 0, 0); |
669 |
+ |
current_pointer = null_pointer; |
670 |
+ |
} |
671 |
+ |
} |
672 |
+ |
} |
673 |
|
break; |
674 |
|
|
675 |
|
case IDCMP_MOUSEBUTTONS: |
690 |
|
case IDCMP_RAWKEY: |
691 |
|
if (qualifier & IEQUALIFIER_REPEAT) // Keyboard repeat is done by MacOS |
692 |
|
break; |
693 |
+ |
if ((qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) == |
694 |
+ |
(IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL) && code == 0x5f) { |
695 |
+ |
SetInterruptFlag(INTFLAG_NMI); |
696 |
+ |
TriggerInterrupt(); |
697 |
+ |
break; |
698 |
+ |
} |
699 |
+ |
|
700 |
|
if (code & IECODE_UP_PREFIX) |
701 |
|
ADBKeyUp(keycode2mac[code & 0x7f]); |
702 |
|
else |