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 |
22 |
|
#include <intuition/intuition.h> |
23 |
|
#include <graphics/rastport.h> |
24 |
|
#include <graphics/gfx.h> |
25 |
< |
#include <cybergraphx/cybergraphics.h> |
25 |
> |
#include <cybergraphics/cybergraphics.h> |
26 |
|
#include <dos/dostags.h> |
27 |
|
#include <devices/timer.h> |
28 |
|
#include <proto/exec.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" |
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]; |
130 |
– |
VideoMonitor.bytes_per_row = the_bitmap->BytesPerRow; |
131 |
– |
VideoMonitor.x = width; |
132 |
– |
VideoMonitor.y = height; |
133 |
– |
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); |
181 |
– |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW); |
182 |
– |
VideoMonitor.x = width; |
183 |
– |
VideoMonitor.y = height; |
184 |
– |
VideoMonitor.mode = VMODE_16BIT; |
221 |
|
return true; |
222 |
|
} |
223 |
|
|
233 |
|
|
234 |
|
switch (depth) { |
235 |
|
case 8: |
200 |
– |
VideoMonitor.mode = VMODE_8BIT; |
236 |
|
break; |
237 |
|
case 15: |
238 |
|
case 16: |
240 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
241 |
|
return false; |
242 |
|
} |
208 |
– |
VideoMonitor.mode = VMODE_16BIT; |
243 |
|
break; |
244 |
|
case 24: |
245 |
|
case 32: |
247 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
248 |
|
return false; |
249 |
|
} |
216 |
– |
VideoMonitor.mode = VMODE_32BIT; |
250 |
|
break; |
251 |
|
default: |
252 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
257 |
|
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
258 |
|
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
259 |
|
|
227 |
– |
VideoMonitor.x = width; |
228 |
– |
VideoMonitor.y = height; |
229 |
– |
|
260 |
|
// Open screen |
261 |
|
the_screen = p96OpenScreenTags( |
262 |
|
P96SA_DisplayID, mode_id, |
289 |
|
return false; |
290 |
|
} |
291 |
|
|
262 |
– |
// 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); |
265 |
– |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); |
297 |
|
return true; |
298 |
|
} |
299 |
|
|
309 |
|
|
310 |
|
switch (depth) { |
311 |
|
case 8: |
281 |
– |
VideoMonitor.mode = VMODE_8BIT; |
312 |
|
break; |
313 |
|
case 15: |
314 |
|
case 16: |
315 |
< |
if (format != PIXFMT_RGB16) { |
315 |
> |
// !!! PIXFMT_RGB15 is correct !!! |
316 |
> |
if (format != PIXFMT_RGB15) { |
317 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
318 |
|
return false; |
319 |
|
} |
289 |
– |
VideoMonitor.mode = VMODE_16BIT; |
320 |
|
break; |
321 |
|
case 24: |
322 |
|
case 32: |
324 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
325 |
|
return false; |
326 |
|
} |
297 |
– |
VideoMonitor.mode = VMODE_32BIT; |
327 |
|
break; |
328 |
|
default: |
329 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
334 |
|
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
335 |
|
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
336 |
|
|
308 |
– |
VideoMonitor.x = width; |
309 |
– |
VideoMonitor.y = height; |
310 |
– |
|
337 |
|
// Open screen |
338 |
|
the_screen = OpenScreenTags(NULL, |
339 |
|
SA_DisplayID, mode_id, |
364 |
|
return false; |
365 |
|
} |
366 |
|
|
341 |
– |
// Set VideoMonitor |
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)&VideoMonitor.mac_frame_base, |
375 |
< |
TAG_END); |
374 |
> |
LBMI_BASEADDRESS, (ULONG)&frame_base, |
375 |
> |
TAG_END |
376 |
> |
); |
377 |
|
UnLockBitMap(handle); |
378 |
< |
VideoMonitor.bytes_per_row = GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD); |
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) |
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 |
|
|
616 |
|
|
617 |
|
// Timer tick, update display |
618 |
|
BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, |
619 |
< |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.x, VideoMonitor.y); |
619 |
> |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); |
620 |
|
|
621 |
|
// Restart timer |
622 |
|
timer_io->tr_node.io_Command = TR_ADDREQUEST; |
641 |
|
// Handle message according to class |
642 |
|
switch (cl) { |
643 |
|
case IDCMP_MOUSEMOVE: |
644 |
< |
if (display_type == DISPLAY_SCREEN || display_type == DISPLAY_SCREEN_CGFX) |
644 |
> |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
645 |
|
ADBMouseMoved(mx, my); |
646 |
< |
else |
646 |
> |
else { |
647 |
|
ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); |
648 |
+ |
if (mx < the_win->BorderLeft |
649 |
+ |
|| my < the_win->BorderTop |
650 |
+ |
|| mx >= the_win->BorderLeft + VideoMonitor.mode.x |
651 |
+ |
|| my >= the_win->BorderTop + VideoMonitor.mode.y) { |
652 |
+ |
if (current_pointer) { |
653 |
+ |
ClearPointer(the_win); |
654 |
+ |
current_pointer = NULL; |
655 |
+ |
} |
656 |
+ |
} else { |
657 |
+ |
if (current_pointer != null_pointer) { |
658 |
+ |
// Hide mouse pointer inside window |
659 |
+ |
SetPointer(the_win, null_pointer, 1, 16, 0, 0); |
660 |
+ |
current_pointer = null_pointer; |
661 |
+ |
} |
662 |
+ |
} |
663 |
+ |
} |
664 |
|
break; |
665 |
|
|
666 |
|
case IDCMP_MOUSEBUTTONS: |
681 |
|
case IDCMP_RAWKEY: |
682 |
|
if (qualifier & IEQUALIFIER_REPEAT) // Keyboard repeat is done by MacOS |
683 |
|
break; |
684 |
+ |
if ((qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) == |
685 |
+ |
(IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL) && code == 0x5f) { |
686 |
+ |
SetInterruptFlag(INTFLAG_NMI); |
687 |
+ |
TriggerInterrupt(); |
688 |
+ |
break; |
689 |
+ |
} |
690 |
+ |
|
691 |
|
if (code & IECODE_UP_PREFIX) |
692 |
|
ADBKeyUp(keycode2mac[code & 0x7f]); |
693 |
|
else |