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-2002 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 |
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 |
+ |
static bool is_valid_modeid(int display_type, ULONG mode_id); |
101 |
+ |
static bool check_modeid_p96(ULONG mode_id); |
102 |
+ |
static bool check_modeid_cgfx(ULONG mode_id); |
103 |
|
|
104 |
|
|
105 |
|
/* |
106 |
|
* Initialization |
107 |
|
*/ |
108 |
|
|
109 |
+ |
|
110 |
|
// Open window |
111 |
|
static bool init_window(int width, int height) |
112 |
|
{ |
129 |
|
TAG_END |
130 |
|
); |
131 |
|
if (the_win == NULL) { |
132 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
132 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
133 |
|
return false; |
134 |
|
} |
135 |
|
|
136 |
|
// Create bitmap ("height + 2" for safety) |
137 |
|
the_bitmap = AllocBitMap(width, height + 2, 1, BMF_CLEAR, NULL); |
138 |
|
if (the_bitmap == NULL) { |
139 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
139 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
140 |
|
return false; |
141 |
|
} |
142 |
|
|
143 |
< |
// Set VideoMonitor |
143 |
> |
// Add resolution and set VideoMonitor |
144 |
|
VideoMonitor.mac_frame_base = (uint32)the_bitmap->Planes[0]; |
133 |
– |
VideoMonitor.bytes_per_row = the_bitmap->BytesPerRow; |
134 |
– |
VideoMonitor.x = width; |
135 |
– |
VideoMonitor.y = height; |
136 |
– |
VideoMonitor.mode = VMODE_1BIT; |
145 |
|
|
146 |
|
// Set FgPen and BgPen |
147 |
|
black_pen = ObtainBestPenA(the_win->WScreen->ViewPort.ColorMap, 0, 0, 0, NULL); |
180 |
|
TAG_END |
181 |
|
); |
182 |
|
if (the_win == NULL || error) { |
183 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
183 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
184 |
|
return false; |
185 |
|
} |
186 |
|
|
187 |
|
// Find bitmap |
188 |
|
p96PIP_GetTags(the_win, P96PIP_SourceBitMap, (ULONG)&the_bitmap, TAG_END); |
189 |
|
|
190 |
< |
// Set VideoMonitor |
190 |
> |
// Add resolution and set VideoMonitor |
191 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_bitmap, P96BMA_MEMORY); |
192 |
< |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_bitmap, P96BMA_BYTESPERROW); |
185 |
< |
VideoMonitor.x = width; |
186 |
< |
VideoMonitor.y = height; |
187 |
< |
VideoMonitor.mode = VMODE_16BIT; |
192 |
> |
|
193 |
|
return true; |
194 |
|
} |
195 |
|
|
200 |
|
ADBSetRelMouseMode(true); |
201 |
|
|
202 |
|
// Check if the mode is one we can handle |
203 |
< |
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
204 |
< |
uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
205 |
< |
|
206 |
< |
switch (depth) { |
207 |
< |
case 8: |
203 |
< |
VideoMonitor.mode = VMODE_8BIT; |
204 |
< |
break; |
205 |
< |
case 15: |
206 |
< |
case 16: |
207 |
< |
if (format != RGBFB_R5G5B5) { |
208 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
209 |
< |
return false; |
210 |
< |
} |
211 |
< |
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)); |
217 |
< |
return false; |
218 |
< |
} |
219 |
< |
VideoMonitor.mode = VMODE_32BIT; |
220 |
< |
break; |
221 |
< |
default: |
222 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
223 |
< |
return false; |
224 |
< |
} |
203 |
> |
if (!check_modeid_p96(mode_id)) |
204 |
> |
{ |
205 |
> |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
206 |
> |
return false; |
207 |
> |
} |
208 |
|
|
209 |
|
// Yes, get width and height |
210 |
+ |
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
211 |
|
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
212 |
|
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
213 |
|
|
230 |
– |
VideoMonitor.x = width; |
231 |
– |
VideoMonitor.y = height; |
232 |
– |
|
214 |
|
// Open screen |
215 |
|
the_screen = p96OpenScreenTags( |
216 |
|
P96SA_DisplayID, mode_id, |
222 |
|
TAG_END |
223 |
|
); |
224 |
|
if (the_screen == NULL) { |
225 |
< |
ErrorAlert(GetString(STR_OPEN_SCREEN_ERR)); |
225 |
> |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
226 |
|
return false; |
227 |
|
} |
228 |
|
|
230 |
|
the_win = OpenWindowTags(NULL, |
231 |
|
WA_Left, 0, WA_Top, 0, |
232 |
|
WA_Width, width, WA_Height, height, |
233 |
+ |
WA_SimpleRefresh, TRUE, |
234 |
|
WA_NoCareRefresh, TRUE, |
235 |
|
WA_Borderless, TRUE, |
236 |
|
WA_Activate, TRUE, |
240 |
|
TAG_END |
241 |
|
); |
242 |
|
if (the_win == NULL) { |
243 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
243 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
244 |
|
return false; |
245 |
|
} |
246 |
|
|
265 |
– |
// Set VideoMonitor |
247 |
|
ScreenToFront(the_screen); |
248 |
+ |
|
249 |
+ |
// Add resolution and set VideoMonitor |
250 |
|
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
251 |
< |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); |
251 |
> |
|
252 |
|
return true; |
253 |
|
} |
254 |
|
|
259 |
|
ADBSetRelMouseMode(true); |
260 |
|
|
261 |
|
// Check if the mode is one we can handle |
262 |
< |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
263 |
< |
uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
264 |
< |
|
265 |
< |
switch (depth) { |
266 |
< |
case 8: |
284 |
< |
VideoMonitor.mode = VMODE_8BIT; |
285 |
< |
break; |
286 |
< |
case 15: |
287 |
< |
case 16: |
288 |
< |
// !!! PIXFMT_RGB15 is correct !!! |
289 |
< |
if (format != PIXFMT_RGB15) { |
290 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
291 |
< |
return false; |
292 |
< |
} |
293 |
< |
VideoMonitor.mode = VMODE_16BIT; |
294 |
< |
break; |
295 |
< |
case 24: |
296 |
< |
case 32: |
297 |
< |
if (format != PIXFMT_ARGB32) { |
298 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
299 |
< |
return false; |
300 |
< |
} |
301 |
< |
VideoMonitor.mode = VMODE_32BIT; |
302 |
< |
break; |
303 |
< |
default: |
304 |
< |
ErrorAlert(GetString(STR_WRONG_SCREEN_DEPTH_ERR)); |
305 |
< |
return false; |
306 |
< |
} |
262 |
> |
if (!check_modeid_cgfx(mode_id)) |
263 |
> |
{ |
264 |
> |
ErrorAlert(STR_WRONG_SCREEN_FORMAT_ERR); |
265 |
> |
return false; |
266 |
> |
} |
267 |
|
|
268 |
|
// Yes, get width and height |
269 |
+ |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
270 |
|
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
271 |
|
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
272 |
|
|
312 |
– |
VideoMonitor.x = width; |
313 |
– |
VideoMonitor.y = height; |
314 |
– |
|
273 |
|
// Open screen |
274 |
|
the_screen = OpenScreenTags(NULL, |
275 |
|
SA_DisplayID, mode_id, |
279 |
|
TAG_END |
280 |
|
); |
281 |
|
if (the_screen == NULL) { |
282 |
< |
ErrorAlert(GetString(STR_OPEN_SCREEN_ERR)); |
282 |
> |
ErrorAlert(STR_OPEN_SCREEN_ERR); |
283 |
|
return false; |
284 |
|
} |
285 |
|
|
287 |
|
the_win = OpenWindowTags(NULL, |
288 |
|
WA_Left, 0, WA_Top, 0, |
289 |
|
WA_Width, width, WA_Height, height, |
290 |
+ |
WA_SimpleRefresh, TRUE, |
291 |
|
WA_NoCareRefresh, TRUE, |
292 |
|
WA_Borderless, TRUE, |
293 |
|
WA_Activate, TRUE, |
297 |
|
TAG_END |
298 |
|
); |
299 |
|
if (the_win == NULL) { |
300 |
< |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
300 |
> |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
301 |
|
return false; |
302 |
|
} |
303 |
|
|
345 |
– |
// Set VideoMonitor |
304 |
|
ScreenToFront(the_screen); |
305 |
|
static UWORD ptr[] = { 0, 0, 0, 0 }; |
306 |
|
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer |
307 |
+ |
|
308 |
+ |
// Set VideoMonitor |
309 |
+ |
ULONG frame_base; |
310 |
|
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
311 |
< |
LBMI_BASEADDRESS, (ULONG)&VideoMonitor.mac_frame_base, |
312 |
< |
TAG_END); |
311 |
> |
LBMI_BASEADDRESS, (ULONG)&frame_base, |
312 |
> |
TAG_END |
313 |
> |
); |
314 |
|
UnLockBitMap(handle); |
315 |
< |
VideoMonitor.bytes_per_row = GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD); |
315 |
> |
|
316 |
> |
VideoMonitor.mac_frame_base = frame_base; |
317 |
> |
|
318 |
|
return true; |
319 |
|
} |
320 |
|
|
321 |
|
bool VideoInit(bool classic) |
322 |
|
{ |
323 |
+ |
int default_width, default_height, default_depth; |
324 |
+ |
|
325 |
|
// Allocate blank mouse pointer data |
326 |
|
null_pointer = (UWORD *)AllocMem(12, MEMF_PUBLIC | MEMF_CHIP | MEMF_CLEAR); |
327 |
|
if (null_pointer == NULL) { |
328 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
328 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
329 |
|
return false; |
330 |
|
} |
331 |
|
|
343 |
|
|
344 |
|
// Determine type and mode |
345 |
|
display_type = DISPLAY_WINDOW; |
346 |
< |
int width = 512, height = 384; |
347 |
< |
ULONG mode_id = 0; |
346 |
> |
|
347 |
> |
default_width = window_width = 512; |
348 |
> |
default_height = window_height = 384; |
349 |
> |
|
350 |
|
if (mode_str) { |
351 |
< |
if (sscanf(mode_str, "win/%d/%d", &width, &height) == 2) |
351 |
> |
if (sscanf(mode_str, "win/%d/%d", &window_width, &window_height) == 2) |
352 |
|
display_type = DISPLAY_WINDOW; |
353 |
< |
else if (sscanf(mode_str, "pip/%d/%d", &width, &height) == 2 && P96Base) |
353 |
> |
else if (sscanf(mode_str, "pip/%d/%d", &window_width, &window_height) == 2 && P96Base) |
354 |
|
display_type = DISPLAY_PIP; |
355 |
< |
else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && (CyberGfxBase || P96Base)) { |
356 |
< |
if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) |
355 |
> |
else if (sscanf(mode_str, "scr/%08lx", &screen_mode_id) == 1 && (CyberGfxBase || P96Base)) { |
356 |
> |
if (P96Base && p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) |
357 |
|
display_type = DISPLAY_SCREEN_P96; |
358 |
< |
else if (CyberGfxBase && IsCyberModeID(mode_id)) |
358 |
> |
else if (CyberGfxBase && IsCyberModeID(screen_mode_id)) |
359 |
|
display_type = DISPLAY_SCREEN_CGFX; |
360 |
|
else { |
361 |
< |
ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); |
361 |
> |
ErrorAlert(STR_NO_P96_MODE_ERR); |
362 |
|
return false; |
363 |
|
} |
364 |
|
} |
365 |
|
} |
366 |
|
|
367 |
+ |
// Construct list of supported modes |
368 |
+ |
switch (display_type) { |
369 |
+ |
case DISPLAY_WINDOW: |
370 |
+ |
default_width = window_width; |
371 |
+ |
default_height = window_height; |
372 |
+ |
default_depth = 1; |
373 |
+ |
add_modes(window_width, window_height, VDEPTH_1BIT); |
374 |
+ |
break; |
375 |
+ |
|
376 |
+ |
case DISPLAY_PIP: |
377 |
+ |
default_depth = 16; |
378 |
+ |
default_width = window_width; |
379 |
+ |
default_height = window_height; |
380 |
+ |
add_modes(window_width, window_height, VDEPTH_16BIT); |
381 |
+ |
break; |
382 |
+ |
|
383 |
+ |
case DISPLAY_SCREEN_P96: |
384 |
+ |
case DISPLAY_SCREEN_CGFX: |
385 |
+ |
struct DimensionInfo dimInfo; |
386 |
+ |
DisplayInfoHandle handle = FindDisplayInfo(screen_mode_id); |
387 |
+ |
|
388 |
+ |
if (NULL == handle) |
389 |
+ |
return false; |
390 |
+ |
|
391 |
+ |
if (GetDisplayInfoData(handle, (UBYTE *) &dimInfo, sizeof(dimInfo), DTAG_DIMS, 0) <= 0) |
392 |
+ |
return false; |
393 |
+ |
|
394 |
+ |
default_width = 1 + dimInfo.Nominal.MaxX - dimInfo.Nominal.MinX; |
395 |
+ |
default_height = 1 + dimInfo.Nominal.MaxY - dimInfo.Nominal.MinY; |
396 |
+ |
default_depth = dimInfo.MaxDepth; |
397 |
+ |
|
398 |
+ |
for (unsigned d=VDEPTH_8BIT; d<=VDEPTH_32BIT; d++) |
399 |
+ |
{ |
400 |
+ |
ULONG mode_id = find_mode_for_depth(default_width, default_height, bits_from_depth(video_depth(d))); |
401 |
+ |
|
402 |
+ |
if (is_valid_modeid(display_type, mode_id)) |
403 |
+ |
{ |
404 |
+ |
add_modes(default_width, default_height, video_depth(d)); |
405 |
+ |
} |
406 |
+ |
} |
407 |
+ |
break; |
408 |
+ |
} |
409 |
+ |
|
410 |
+ |
video_init_depth_list(); |
411 |
+ |
|
412 |
+ |
#if DEBUG |
413 |
+ |
bug("Available video modes:\n"); |
414 |
+ |
vector<video_mode>::const_iterator i = VideoModes.begin(), end = VideoModes.end(); |
415 |
+ |
while (i != end) { |
416 |
+ |
bug(" %dx%d (ID %02x), %d colors\n", i->x, i->y, i->resolution_id, 1 << bits_from_depth(i->depth)); |
417 |
+ |
++i; |
418 |
+ |
} |
419 |
+ |
#endif |
420 |
+ |
|
421 |
+ |
D(bug("VideoInit: def_width=%ld def_height=%ld def_depth=%ld\n", default_width, default_height, default_depth)); |
422 |
+ |
|
423 |
+ |
// Find requested default mode and open display |
424 |
+ |
if (VideoModes.size() == 1) |
425 |
+ |
return video_open(VideoModes[0]); |
426 |
+ |
else { |
427 |
+ |
// Find mode with specified dimensions |
428 |
+ |
std::vector<video_mode>::const_iterator i, end = VideoModes.end(); |
429 |
+ |
for (i = VideoModes.begin(); i != end; ++i) |
430 |
+ |
{ |
431 |
+ |
D(bug("VideoInit: w=%ld h=%ld d=%ld\n", i->x, i->y, bits_from_depth(i->depth))); |
432 |
+ |
if (i->x == default_width && i->y == default_height && bits_from_depth(i->depth) == default_depth) |
433 |
+ |
return video_open(*i); |
434 |
+ |
} |
435 |
+ |
return video_open(VideoModes[0]); |
436 |
+ |
} |
437 |
+ |
|
438 |
+ |
return true; |
439 |
+ |
} |
440 |
+ |
|
441 |
+ |
|
442 |
+ |
static bool video_open(const video_mode &mode) |
443 |
+ |
{ |
444 |
+ |
ULONG depth_bits = bits_from_depth(mode.depth); |
445 |
+ |
ULONG ID = find_mode_for_depth(mode.x, mode.y, depth_bits); |
446 |
+ |
|
447 |
+ |
D(bug("video_open: width=%ld height=%ld depth=%ld ID=%08lx\n", mode.x, mode.y, depth_bits, ID)); |
448 |
+ |
|
449 |
+ |
if (INVALID_ID == ID) |
450 |
+ |
{ |
451 |
+ |
ErrorAlert(STR_NO_VIDEO_MODE_ERR); |
452 |
+ |
return false; |
453 |
+ |
} |
454 |
+ |
|
455 |
+ |
VideoMonitor.mode = mode; |
456 |
+ |
|
457 |
|
// Open display |
458 |
|
switch (display_type) { |
459 |
|
case DISPLAY_WINDOW: |
460 |
< |
if (!init_window(width, height)) |
460 |
> |
if (!init_window(mode.x, mode.y)) |
461 |
|
return false; |
462 |
|
break; |
463 |
|
|
464 |
|
case DISPLAY_PIP: |
465 |
< |
if (!init_pip(width, height)) |
465 |
> |
if (!init_pip(mode.x, mode.y)) |
466 |
|
return false; |
467 |
|
break; |
468 |
|
|
469 |
|
case DISPLAY_SCREEN_P96: |
470 |
< |
if (!init_screen_p96(mode_id)) |
470 |
> |
if (!init_screen_p96(ID)) |
471 |
|
return false; |
472 |
|
break; |
473 |
|
|
474 |
|
case DISPLAY_SCREEN_CGFX: |
475 |
< |
if (!init_screen_cgfx(mode_id)) |
475 |
> |
if (!init_screen_cgfx(ID)) |
476 |
|
return false; |
477 |
|
break; |
478 |
|
} |
485 |
|
TAG_END |
486 |
|
); |
487 |
|
if (periodic_proc == NULL) { |
488 |
< |
ErrorAlert(GetString(STR_NO_MEM_ERR)); |
488 |
> |
ErrorAlert(STR_NO_MEM_ERR); |
489 |
|
return false; |
490 |
|
} |
491 |
+ |
|
492 |
|
return true; |
493 |
|
} |
494 |
|
|
495 |
|
|
496 |
< |
/* |
438 |
< |
* Deinitialization |
439 |
< |
*/ |
440 |
< |
|
441 |
< |
void VideoExit(void) |
496 |
> |
static void video_close() |
497 |
|
{ |
498 |
|
// Stop periodic process |
499 |
|
if (periodic_proc) { |
518 |
|
ReleasePen(the_win->WScreen->ViewPort.ColorMap, white_pen); |
519 |
|
|
520 |
|
CloseWindow(the_win); |
521 |
+ |
the_win = NULL; |
522 |
|
} |
523 |
|
break; |
524 |
|
|
533 |
|
|
534 |
|
// Close window |
535 |
|
if (the_win) |
536 |
+ |
{ |
537 |
|
CloseWindow(the_win); |
538 |
+ |
the_win = NULL; |
539 |
+ |
} |
540 |
|
|
541 |
|
// Close screen |
542 |
|
if (the_screen) { |
549 |
|
|
550 |
|
// Close window |
551 |
|
if (the_win) |
552 |
+ |
{ |
553 |
|
CloseWindow(the_win); |
554 |
+ |
the_win = NULL; |
555 |
+ |
} |
556 |
|
|
557 |
|
// Close screen |
558 |
|
if (the_screen) { |
571 |
|
|
572 |
|
|
573 |
|
/* |
574 |
+ |
* Deinitialization |
575 |
+ |
*/ |
576 |
+ |
|
577 |
+ |
void VideoExit(void) |
578 |
+ |
{ |
579 |
+ |
video_close(); |
580 |
+ |
} |
581 |
+ |
|
582 |
+ |
|
583 |
+ |
/* |
584 |
|
* Set palette |
585 |
|
*/ |
586 |
|
|
587 |
< |
void video_set_palette(uint8 *pal) |
587 |
> |
void video_set_palette(uint8 *pal, int num) |
588 |
|
{ |
589 |
< |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) { |
589 |
> |
if ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
590 |
> |
&& !IsDirectMode(VideoMonitor.mode)) { |
591 |
|
|
592 |
|
// Convert palette to 32 bits |
593 |
|
ULONG table[2 + 256 * 3]; |
594 |
< |
table[0] = 256 << 16; |
595 |
< |
table[256 * 3 + 1] = 0; |
596 |
< |
for (int i=0; i<256; i++) { |
594 |
> |
table[0] = num << 16; |
595 |
> |
table[num * 3 + 1] = 0; |
596 |
> |
for (int i=0; i<num; i++) { |
597 |
|
table[i*3+1] = pal[i*3] * 0x01010101; |
598 |
|
table[i*3+2] = pal[i*3+1] * 0x01010101; |
599 |
|
table[i*3+3] = pal[i*3+2] * 0x01010101; |
606 |
|
|
607 |
|
|
608 |
|
/* |
609 |
+ |
* Switch video mode |
610 |
+ |
*/ |
611 |
+ |
|
612 |
+ |
void video_switch_to_mode(const video_mode &mode) |
613 |
+ |
{ |
614 |
+ |
// Close and reopen display |
615 |
+ |
video_close(); |
616 |
+ |
if (!video_open(mode)) |
617 |
+ |
{ |
618 |
+ |
ErrorAlert(STR_OPEN_WINDOW_ERR); |
619 |
+ |
QuitEmulator(); |
620 |
+ |
} |
621 |
+ |
} |
622 |
+ |
|
623 |
+ |
|
624 |
+ |
/* |
625 |
+ |
* Close down full-screen mode (if bringing up error alerts is unsafe while in full-screen mode) |
626 |
+ |
*/ |
627 |
+ |
|
628 |
+ |
void VideoQuitFullScreen(void) |
629 |
+ |
{ |
630 |
+ |
} |
631 |
+ |
|
632 |
+ |
|
633 |
+ |
/* |
634 |
|
* Video message handling (not neccessary under AmigaOS, handled by periodic_func()) |
635 |
|
*/ |
636 |
|
|
688 |
|
|
689 |
|
// Timer tick, update display |
690 |
|
BltTemplate(the_bitmap->Planes[0], 0, the_bitmap->BytesPerRow, the_win->RPort, |
691 |
< |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.x, VideoMonitor.y); |
691 |
> |
the_win->BorderLeft, the_win->BorderTop, VideoMonitor.mode.x, VideoMonitor.mode.y); |
692 |
|
|
693 |
|
// Restart timer |
694 |
|
timer_io->tr_node.io_Command = TR_ADDREQUEST; |
719 |
|
ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); |
720 |
|
if (mx < the_win->BorderLeft |
721 |
|
|| my < the_win->BorderTop |
722 |
< |
|| mx >= the_win->BorderLeft + VideoMonitor.x |
723 |
< |
|| my >= the_win->BorderTop + VideoMonitor.y) { |
722 |
> |
|| mx >= the_win->BorderLeft + VideoMonitor.mode.x |
723 |
> |
|| my >= the_win->BorderTop + VideoMonitor.mode.y) { |
724 |
|
if (current_pointer) { |
725 |
|
ClearPointer(the_win); |
726 |
|
current_pointer = NULL; |
801 |
|
Forbid(); |
802 |
|
Signal(MainTask, SIGF_SINGLE); |
803 |
|
} |
804 |
+ |
|
805 |
+ |
|
806 |
+ |
// Add mode to list of supported modes |
807 |
+ |
static void add_mode(uint32 width, uint32 height, uint32 resolution_id, uint32 bytes_per_row, video_depth depth) |
808 |
+ |
{ |
809 |
+ |
video_mode mode; |
810 |
+ |
mode.x = width; |
811 |
+ |
mode.y = height; |
812 |
+ |
mode.resolution_id = resolution_id; |
813 |
+ |
mode.bytes_per_row = bytes_per_row; |
814 |
+ |
mode.depth = depth; |
815 |
+ |
|
816 |
+ |
D(bug("Added video mode: w=%ld h=%ld d=%ld\n", width, height, depth)); |
817 |
+ |
|
818 |
+ |
VideoModes.push_back(mode); |
819 |
+ |
} |
820 |
+ |
|
821 |
+ |
// Add standard list of windowed modes for given color depth |
822 |
+ |
static void add_modes(uint32 width, uint32 height, video_depth depth) |
823 |
+ |
{ |
824 |
+ |
D(bug("add_modes: w=%ld h=%ld d=%ld\n", width, height, depth)); |
825 |
+ |
|
826 |
+ |
if (width >= 512 && height >= 384) |
827 |
+ |
add_mode(512, 384, 0x80, TrivialBytesPerRow(512, depth), depth); |
828 |
+ |
if (width >= 640 && height >= 480) |
829 |
+ |
add_mode(640, 480, 0x81, TrivialBytesPerRow(640, depth), depth); |
830 |
+ |
if (width >= 800 && height >= 600) |
831 |
+ |
add_mode(800, 600, 0x82, TrivialBytesPerRow(800, depth), depth); |
832 |
+ |
if (width >= 1024 && height >= 768) |
833 |
+ |
add_mode(1024, 768, 0x83, TrivialBytesPerRow(1024, depth), depth); |
834 |
+ |
if (width >= 1152 && height >= 870) |
835 |
+ |
add_mode(1152, 870, 0x84, TrivialBytesPerRow(1152, depth), depth); |
836 |
+ |
if (width >= 1280 && height >= 1024) |
837 |
+ |
add_mode(1280, 1024, 0x85, TrivialBytesPerRow(1280, depth), depth); |
838 |
+ |
if (width >= 1600 && height >= 1200) |
839 |
+ |
add_mode(1600, 1200, 0x86, TrivialBytesPerRow(1600, depth), depth); |
840 |
+ |
} |
841 |
+ |
|
842 |
+ |
|
843 |
+ |
static ULONG find_mode_for_depth(uint32 width, uint32 height, uint32 depth) |
844 |
+ |
{ |
845 |
+ |
ULONG ID = BestModeID(BIDTAG_NominalWidth, width, |
846 |
+ |
BIDTAG_NominalHeight, height, |
847 |
+ |
BIDTAG_Depth, depth, |
848 |
+ |
BIDTAG_DIPFMustNotHave, DIPF_IS_ECS | DIPF_IS_HAM | DIPF_IS_AA, |
849 |
+ |
TAG_END); |
850 |
+ |
|
851 |
+ |
return ID; |
852 |
+ |
} |
853 |
+ |
|
854 |
+ |
|
855 |
+ |
static ULONG bits_from_depth(video_depth depth) |
856 |
+ |
{ |
857 |
+ |
int bits = 1 << depth; |
858 |
+ |
if (bits == 16) |
859 |
+ |
bits = 15; |
860 |
+ |
else if (bits == 32) |
861 |
+ |
bits = 24; |
862 |
+ |
|
863 |
+ |
return bits; |
864 |
+ |
} |
865 |
+ |
|
866 |
+ |
|
867 |
+ |
static bool is_valid_modeid(int display_type, ULONG mode_id) |
868 |
+ |
{ |
869 |
+ |
if (INVALID_ID == mode_id) |
870 |
+ |
return false; |
871 |
+ |
|
872 |
+ |
switch (display_type) |
873 |
+ |
{ |
874 |
+ |
case DISPLAY_SCREEN_P96: |
875 |
+ |
return check_modeid_p96(mode_id); |
876 |
+ |
break; |
877 |
+ |
case DISPLAY_SCREEN_CGFX: |
878 |
+ |
return check_modeid_cgfx(mode_id); |
879 |
+ |
break; |
880 |
+ |
default: |
881 |
+ |
return false; |
882 |
+ |
break; |
883 |
+ |
} |
884 |
+ |
} |
885 |
+ |
|
886 |
+ |
|
887 |
+ |
static bool check_modeid_p96(ULONG mode_id) |
888 |
+ |
{ |
889 |
+ |
// Check if the mode is one we can handle |
890 |
+ |
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
891 |
+ |
uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
892 |
+ |
|
893 |
+ |
if (!p96GetModeIDAttr(screen_mode_id, P96IDA_ISP96)) |
894 |
+ |
return false; |
895 |
+ |
|
896 |
+ |
switch (depth) { |
897 |
+ |
case 8: |
898 |
+ |
break; |
899 |
+ |
case 15: |
900 |
+ |
case 16: |
901 |
+ |
if (format != RGBFB_R5G5B5) |
902 |
+ |
return false; |
903 |
+ |
break; |
904 |
+ |
case 24: |
905 |
+ |
case 32: |
906 |
+ |
if (format != RGBFB_A8R8G8B8) |
907 |
+ |
return false; |
908 |
+ |
break; |
909 |
+ |
default: |
910 |
+ |
return false; |
911 |
+ |
} |
912 |
+ |
|
913 |
+ |
return true; |
914 |
+ |
} |
915 |
+ |
|
916 |
+ |
|
917 |
+ |
static bool check_modeid_cgfx(ULONG mode_id) |
918 |
+ |
{ |
919 |
+ |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
920 |
+ |
uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
921 |
+ |
|
922 |
+ |
D(bug("init_screen_cgfx: mode_id=%08lx depth=%ld format=%ld\n", mode_id, depth, format)); |
923 |
+ |
|
924 |
+ |
if (!IsCyberModeID(mode_id)) |
925 |
+ |
return false; |
926 |
+ |
|
927 |
+ |
switch (depth) { |
928 |
+ |
case 8: |
929 |
+ |
break; |
930 |
+ |
case 15: |
931 |
+ |
case 16: |
932 |
+ |
// !!! PIXFMT_RGB15 is correct !!! |
933 |
+ |
if (format != PIXFMT_RGB15) |
934 |
+ |
return false; |
935 |
+ |
break; |
936 |
+ |
case 24: |
937 |
+ |
case 32: |
938 |
+ |
if (format != PIXFMT_ARGB32) |
939 |
+ |
return false; |
940 |
+ |
break; |
941 |
+ |
default: |
942 |
+ |
return false; |
943 |
+ |
} |
944 |
+ |
|
945 |
+ |
return true; |
946 |
+ |
} |
947 |
+ |
|