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 <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 |
+ |
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 |
|
|
106 |
+ |
|
107 |
|
// Open window |
108 |
|
static bool init_window(int width, int height) |
109 |
|
{ |
126 |
|
TAG_END |
127 |
|
); |
128 |
|
if (the_win == NULL) { |
129 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
129 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
130 |
|
return false; |
131 |
|
} |
132 |
|
|
133 |
|
// Create bitmap ("height + 2" for safety) |
134 |
|
the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL); |
135 |
|
if (the_bitmap == NULL) { |
136 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
136 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
137 |
|
return false; |
138 |
|
} |
139 |
|
|
140 |
< |
// Set VideoMonitor |
140 |
> |
// Add resolution and set VideoMonitor |
141 |
|
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; |
142 |
|
|
143 |
|
// Set FgPen and BgPen |
144 |
|
black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); |
177 |
|
TAG_END |
178 |
|
); |
179 |
|
if (the_win == NULL || error) { |
180 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
180 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
181 |
|
return false; |
182 |
|
} |
183 |
|
|
184 |
|
// Find bitmap |
185 |
|
p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); |
186 |
|
|
187 |
< |
// Set VideoMonitor |
187 |
> |
// Add resolution and set VideoMonitor |
188 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); |
189 |
< |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW); |
179 |
< |
VideoMonitor.x = width; |
180 |
< |
VideoMonitor.y = height; |
181 |
< |
VideoMonitor.mode = VMODE_16BIT; |
189 |
> |
|
190 |
|
return true; |
191 |
|
} |
192 |
|
|
193 |
< |
// Open screen (requires Picasso96 as we need chunky modes) |
194 |
< |
static bool init_screen(ULONG mode_id) |
193 |
> |
// Open Picasso96 screen |
194 |
> |
static bool init_screen_p96(ULONG mode_id) |
195 |
|
{ |
196 |
|
// Set relative mouse mode |
197 |
|
ADBSetRelMouseMode(true); |
198 |
|
|
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 |
– |
|
199 |
|
// Check if the mode is one we can handle |
200 |
|
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
201 |
|
uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
202 |
+ |
|
203 |
|
switch (depth) { |
204 |
|
case 8: |
202 |
– |
VideoMonitor.mode = VMODE_8BIT; |
205 |
|
break; |
206 |
|
case 15: |
207 |
|
case 16: |
208 |
|
if (format != RGBFB_R5G5B5) { |
209 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
209 |
> |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
210 |
|
return false; |
211 |
|
} |
210 |
– |
VideoMonitor.mode = VMODE_16BIT; |
212 |
|
break; |
213 |
|
case 24: |
214 |
|
case 32: |
215 |
|
if (format != RGBFB_A8R8G8B8) { |
216 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
216 |
> |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
217 |
|
return false; |
218 |
|
} |
218 |
– |
VideoMonitor.mode = VMODE_32BIT; |
219 |
|
break; |
220 |
|
default: |
221 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
221 |
> |
ErrorAlert(STR_WRONG_SCREEN_DEPTH_ERR); |
222 |
|
return false; |
223 |
|
} |
224 |
|
|
225 |
|
// Yes, get width and height |
226 |
|
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
227 |
|
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
228 |
– |
VideoMonitor.x = width; |
229 |
– |
VideoMonitor.y = height; |
228 |
|
|
229 |
|
// Open screen |
230 |
|
the_screen = p96OpenScreenTags( |
237 |
|
TAG_END |
238 |
|
); |
239 |
|
if (the_screen == NULL) { |
240 |
< |
ErrorAlert(GetString(STR_OPEN_SCREEN_ERR)); |
240 |
> |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
241 |
|
return false; |
242 |
|
} |
243 |
|
|
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, |
255 |
|
TAG_END |
256 |
|
); |
257 |
|
if (the_win == NULL) { |
258 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
258 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
259 |
|
return false; |
260 |
|
} |
261 |
|
|
263 |
– |
// Set VideoMonitor |
262 |
|
ScreenToFront(the_screen); |
263 |
+ |
|
264 |
+ |
// Add resolution and set VideoMonitor |
265 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
266 |
< |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); |
266 |
> |
|
267 |
> |
return true; |
268 |
> |
} |
269 |
> |
|
270 |
> |
// Open CyberGraphX screen |
271 |
> |
static bool init_screen_cgfx(ULONG mode_id) |
272 |
> |
{ |
273 |
> |
// Set relative mouse mode |
274 |
> |
ADBSetRelMouseMode(true); |
275 |
> |
|
276 |
> |
// Check if the mode is one we can handle |
277 |
> |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
278 |
> |
uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
279 |
> |
|
280 |
> |
switch (depth) { |
281 |
> |
case 8: |
282 |
> |
break; |
283 |
> |
case 15: |
284 |
> |
case 16: |
285 |
> |
// !!! PIXFMT_RGB15 is correct !!! |
286 |
> |
if (format != PIXFMT_RGB15) { |
287 |
> |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
288 |
> |
return false; |
289 |
> |
} |
290 |
> |
break; |
291 |
> |
case 24: |
292 |
> |
case 32: |
293 |
> |
if (format != PIXFMT_ARGB32) { |
294 |
> |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
295 |
> |
return false; |
296 |
> |
} |
297 |
> |
break; |
298 |
> |
default: |
299 |
> |
ErrorAlert(STR_WRONG_SCREEN_DEPTH_ERR); |
300 |
> |
return false; |
301 |
> |
} |
302 |
> |
|
303 |
> |
// Yes, get width and height |
304 |
> |
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
305 |
> |
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
306 |
> |
|
307 |
> |
// Open screen |
308 |
> |
the_screen = OpenScreenTags(NULL, |
309 |
> |
SA_DisplayID, mode_id, |
310 |
> |
SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
311 |
> |
SA_Quiet, TRUE, |
312 |
> |
SA_Exclusive, TRUE, |
313 |
> |
TAG_END |
314 |
> |
); |
315 |
> |
if (the_screen == NULL) { |
316 |
> |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
317 |
> |
return false; |
318 |
> |
} |
319 |
> |
|
320 |
> |
// Open window |
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, |
328 |
> |
WA_RMBTrap, TRUE, |
329 |
> |
WA_ReportMouse, TRUE, |
330 |
> |
WA_CustomScreen, (ULONG)the_screen, |
331 |
> |
TAG_END |
332 |
> |
); |
333 |
> |
if (the_win == NULL) { |
334 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
335 |
> |
return false; |
336 |
> |
} |
337 |
> |
|
338 |
> |
ScreenToFront(the_screen); |
339 |
> |
static UWORD ptr[] = { 0, 0, 0, 0 }; |
340 |
> |
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer |
341 |
> |
|
342 |
> |
// Set VideoMonitor |
343 |
> |
ULONG frame_base; |
344 |
> |
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
345 |
> |
LBMI_BASEADDRESS, (ULONG)&frame_base, |
346 |
> |
TAG_END |
347 |
> |
); |
348 |
> |
UnLockBitMap(handle); |
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) { |
362 |
+ |
ErrorAlert(STR_NO_MEM_ERR); |
363 |
+ |
return false; |
364 |
+ |
} |
365 |
+ |
|
366 |
|
// Read frame skip prefs |
367 |
|
frame_skip = PrefsFindInt32("frameskip"); |
368 |
|
if (frame_skip == 0) |
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 && P96Base) |
390 |
< |
display_type = DISPLAY_SCREEN; |
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(screen_mode_id)) |
393 |
> |
display_type = DISPLAY_SCREEN_CGFX; |
394 |
> |
else { |
395 |
> |
ErrorAlert(STR_NO_P96_MODE_ERR); |
396 |
> |
return false; |
397 |
> |
} |
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(ID)) |
503 |
|
return false; |
504 |
|
break; |
505 |
|
|
506 |
< |
case DISPLAY_SCREEN: |
507 |
< |
if (!init_screen(mode_id)) |
506 |
> |
case DISPLAY_SCREEN_CGFX: |
507 |
> |
if (!init_screen_cgfx(ID)) |
508 |
|
return false; |
509 |
|
break; |
510 |
|
} |
517 |
|
TAG_END |
518 |
|
); |
519 |
|
if (periodic_proc == NULL) { |
520 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
520 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
521 |
|
return false; |
522 |
|
} |
523 |
+ |
|
524 |
|
return true; |
525 |
|
} |
526 |
|
|
527 |
|
|
528 |
< |
/* |
331 |
< |
* Deinitialization |
332 |
< |
*/ |
333 |
< |
|
334 |
< |
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 |
|
|
561 |
|
p96PIP_Close(the_win); |
562 |
|
break; |
563 |
|
|
564 |
< |
case DISPLAY_SCREEN: |
564 |
> |
case DISPLAY_SCREEN_P96: |
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) |
574 |
> |
if (the_screen) { |
575 |
|
p96CloseScreen(the_screen); |
576 |
+ |
the_screen = NULL; |
577 |
+ |
} |
578 |
+ |
break; |
579 |
+ |
|
580 |
+ |
case DISPLAY_SCREEN_CGFX: |
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) { |
591 |
+ |
CloseScreen(the_screen); |
592 |
+ |
the_screen = NULL; |
593 |
+ |
} |
594 |
|
break; |
595 |
|
} |
596 |
+ |
|
597 |
+ |
// Free mouse pointer |
598 |
+ |
if (null_pointer) { |
599 |
+ |
FreeMem(null_pointer, 12); |
600 |
+ |
null_pointer = NULL; |
601 |
+ |
} |
602 |
+ |
} |
603 |
+ |
|
604 |
+ |
|
605 |
+ |
/* |
606 |
+ |
* Deinitialization |
607 |
+ |
*/ |
608 |
+ |
|
609 |
+ |
void VideoExit(void) |
610 |
+ |
{ |
611 |
+ |
video_close(); |
612 |
|
} |
613 |
|
|
614 |
|
|
616 |
|
* Set palette |
617 |
|
*/ |
618 |
|
|
619 |
< |
void video_set_palette(uint8 *pal) |
619 |
> |
void video_set_palette(uint8 *pal, int num) |
620 |
|
{ |
621 |
< |
if (display_type == DISPLAY_SCREEN) { |
621 |
> |
if ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
622 |
> |
&& !IsDirectMode(VideoMonitor.mode)) { |
623 |
|
|
624 |
|
// Convert palette to 32 bits |
625 |
|
ULONG table[2 + 256 * 3]; |
626 |
< |
table[0] = 256 << 16; |
627 |
< |
table[256 * 3 + 1] = 0; |
628 |
< |
for (int i=0; i<256; i++) { |
626 |
> |
table[0] = num << 16; |
627 |
> |
table[num * 3 + 1] = 0; |
628 |
> |
for (int i=0; i<num; i++) { |
629 |
|
table[i*3+1] = pal[i*3] * 0x01010101; |
630 |
|
table[i*3+2] = pal[i*3+1] * 0x01010101; |
631 |
|
table[i*3+3] = pal[i*3+2] * 0x01010101; |
638 |
|
|
639 |
|
|
640 |
|
/* |
641 |
+ |
* Switch video mode |
642 |
+ |
*/ |
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 |
+ |
|
665 |
+ |
/* |
666 |
|
* Video message handling (not neccessary under AmigaOS, handled by periodic_func()) |
667 |
|
*/ |
668 |
|
|
687 |
|
if (win_port) { |
688 |
|
win_mask = 1 << win_port->mp_SigBit; |
689 |
|
the_win->UserPort = win_port; |
690 |
< |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | (display_type == DISPLAY_SCREEN ? IDCMP_DELTAMOVE : 0)); |
690 |
> |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); |
691 |
|
} |
692 |
|
|
693 |
|
// Start 60Hz timer for window refresh |
720 |
|
|
721 |
|
// Timer tick, update display |
722 |
|
BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, |
723 |
< |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.x, VideoMonitor.y); |
723 |
> |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); |
724 |
|
|
725 |
|
// Restart timer |
726 |
|
timer_io->tr_node.io_Command = TR_ADDREQUEST; |
745 |
|
// Handle message according to class |
746 |
|
switch (cl) { |
747 |
|
case IDCMP_MOUSEMOVE: |
748 |
< |
if (display_type == DISPLAY_SCREEN) |
748 |
> |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
749 |
|
ADBMouseMoved(mx, my); |
750 |
< |
else |
750 |
> |
else { |
751 |
|
ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); |
752 |
+ |
if (mx < the_win->BorderLeft |
753 |
+ |
|| my < the_win->BorderTop |
754 |
+ |
|| mx >= the_win->BorderLeft + VideoMonitor.mode.x |
755 |
+ |
|| my >= the_win->BorderTop + VideoMonitor.mode.y) { |
756 |
+ |
if (current_pointer) { |
757 |
+ |
ClearPointer(the_win); |
758 |
+ |
current_pointer = NULL; |
759 |
+ |
} |
760 |
+ |
} else { |
761 |
+ |
if (current_pointer != null_pointer) { |
762 |
+ |
// Hide mouse pointer inside window |
763 |
+ |
SetPointer(the_win, null_pointer, 1, 16, 0, 0); |
764 |
+ |
current_pointer = null_pointer; |
765 |
+ |
} |
766 |
+ |
} |
767 |
+ |
} |
768 |
|
break; |
769 |
|
|
770 |
|
case IDCMP_MOUSEBUTTONS: |
785 |
|
case IDCMP_RAWKEY: |
786 |
|
if (qualifier & IEQUALIFIER_REPEAT) // Keyboard repeat is done by MacOS |
787 |
|
break; |
788 |
+ |
if ((qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) == |
789 |
+ |
(IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL) && code == 0x5f) { |
790 |
+ |
SetInterruptFlag(INTFLAG_NMI); |
791 |
+ |
TriggerInterrupt(); |
792 |
+ |
break; |
793 |
+ |
} |
794 |
+ |
|
795 |
|
if (code & IECODE_UP_PREFIX) |
796 |
|
ADBKeyUp(keycode2mac[code & 0x7f]); |
797 |
|
else |
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 |
+ |
|