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" |
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 |
61 |
– |
static bool is_cgfx = false; // Flag: screen mode is a CyberGfx mode |
62 |
– |
static bool is_p96 = false; // Flag: screen mode is a Picasso96 mode |
65 |
|
|
66 |
|
extern struct Task *MainTask; // Pointer to main task (from main_amiga.cpp) |
67 |
|
|
188 |
|
return true; |
189 |
|
} |
190 |
|
|
191 |
< |
// Open screen (requires Picasso96/CyberGfx as we need chunky modes) |
192 |
< |
static bool init_screen(ULONG mode_id) |
191 |
> |
// Open Picasso96 screen |
192 |
> |
static bool init_screen_p96(ULONG mode_id) |
193 |
|
{ |
194 |
|
// Set relative mouse mode |
195 |
|
ADBSetRelMouseMode(true); |
196 |
|
|
197 |
< |
// Check whether the mode is a Picasso96 mode or a CyberGfx mode |
198 |
< |
if (CyberGfxBase && IsCyberModeID(mode_id)) |
199 |
< |
is_cgfx = true; |
200 |
< |
else if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) |
201 |
< |
is_p96 = true; |
202 |
< |
else { |
203 |
< |
ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); |
197 |
> |
// Check if the mode is one we can handle |
198 |
> |
uint32 depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
199 |
> |
uint32 format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
200 |
> |
|
201 |
> |
switch (depth) { |
202 |
> |
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 |
> |
} |
225 |
> |
|
226 |
> |
// Yes, get width and height |
227 |
> |
uint32 width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
228 |
> |
uint32 height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
229 |
> |
|
230 |
> |
VideoMonitor.x = width; |
231 |
> |
VideoMonitor.y = height; |
232 |
> |
|
233 |
> |
// Open screen |
234 |
> |
the_screen = p96OpenScreenTags( |
235 |
> |
P96SA_DisplayID, mode_id, |
236 |
> |
P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
237 |
> |
P96SA_Quiet, TRUE, |
238 |
> |
P96SA_NoMemory, TRUE, |
239 |
> |
P96SA_NoSprite, TRUE, |
240 |
> |
P96SA_Exclusive, TRUE, |
241 |
> |
TAG_END |
242 |
> |
); |
243 |
> |
if (the_screen == NULL) { |
244 |
> |
ErrorAlert(GetString(STR_OPEN_SCREEN_ERR)); |
245 |
> |
return false; |
246 |
> |
} |
247 |
> |
|
248 |
> |
// Open window |
249 |
> |
the_win = OpenWindowTags(NULL, |
250 |
> |
WA_Left, 0, WA_Top, 0, |
251 |
> |
WA_Width, width, WA_Height, height, |
252 |
> |
WA_NoCareRefresh, TRUE, |
253 |
> |
WA_Borderless, TRUE, |
254 |
> |
WA_Activate, TRUE, |
255 |
> |
WA_RMBTrap, TRUE, |
256 |
> |
WA_ReportMouse, TRUE, |
257 |
> |
WA_CustomScreen, (ULONG)the_screen, |
258 |
> |
TAG_END |
259 |
> |
); |
260 |
> |
if (the_win == NULL) { |
261 |
> |
ErrorAlert(GetString(STR_OPEN_WINDOW_ERR)); |
262 |
|
return false; |
263 |
|
} |
264 |
|
|
265 |
< |
uint32 depth; |
266 |
< |
uint32 format; |
265 |
> |
// Set VideoMonitor |
266 |
> |
ScreenToFront(the_screen); |
267 |
> |
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
268 |
> |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); |
269 |
> |
return true; |
270 |
> |
} |
271 |
> |
|
272 |
> |
// Open CyberGraphX screen |
273 |
> |
static bool init_screen_cgfx(ULONG mode_id) |
274 |
> |
{ |
275 |
> |
// Set relative mouse mode |
276 |
> |
ADBSetRelMouseMode(true); |
277 |
|
|
278 |
|
// Check if the mode is one we can handle |
279 |
< |
if (is_p96) { |
280 |
< |
depth = p96GetModeIDAttr(mode_id, P96IDA_DEPTH); |
211 |
< |
format = p96GetModeIDAttr(mode_id, P96IDA_RGBFORMAT); |
212 |
< |
} else { |
213 |
< |
depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
214 |
< |
format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
215 |
< |
} |
279 |
> |
uint32 depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, mode_id); |
280 |
> |
uint32 format = GetCyberIDAttr(CYBRIDATTR_PIXFMT, mode_id); |
281 |
|
|
282 |
|
switch (depth) { |
283 |
|
case 8: |
285 |
|
break; |
286 |
|
case 15: |
287 |
|
case 16: |
288 |
< |
if (format != RGBFB_R5G5B5 && format != PIXFMT_RGB16) { |
288 |
> |
// !!! PIXFMT_RGB15 is correct !!! |
289 |
> |
if (format != PIXFMT_RGB15) { |
290 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
291 |
|
return false; |
292 |
|
} |
294 |
|
break; |
295 |
|
case 24: |
296 |
|
case 32: |
297 |
< |
if (format != RGBFB_A8R8G8B8 && format != PIXFMT_ARGB32) { |
297 |
> |
if (format != PIXFMT_ARGB32) { |
298 |
|
ErrorAlert(GetString(STR_WRONG_SCREEN_FORMAT_ERR)); |
299 |
|
return false; |
300 |
|
} |
306 |
|
} |
307 |
|
|
308 |
|
// Yes, get width and height |
309 |
< |
uint32 width; |
310 |
< |
uint32 height; |
309 |
> |
uint32 width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
310 |
> |
uint32 height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
311 |
|
|
246 |
– |
if (is_p96) { |
247 |
– |
width = p96GetModeIDAttr(mode_id, P96IDA_WIDTH); |
248 |
– |
height = p96GetModeIDAttr(mode_id, P96IDA_HEIGHT); |
249 |
– |
} else { |
250 |
– |
width = GetCyberIDAttr(CYBRIDATTR_WIDTH, mode_id); |
251 |
– |
height = GetCyberIDAttr(CYBRIDATTR_HEIGHT, mode_id); |
252 |
– |
} |
312 |
|
VideoMonitor.x = width; |
313 |
|
VideoMonitor.y = height; |
314 |
|
|
315 |
|
// Open screen |
316 |
< |
if (is_p96) { |
317 |
< |
the_screen = p96OpenScreenTags( |
318 |
< |
P96SA_DisplayID, mode_id, |
319 |
< |
P96SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
320 |
< |
P96SA_Quiet, TRUE, |
321 |
< |
P96SA_NoMemory, TRUE, |
322 |
< |
P96SA_NoSprite, TRUE, |
264 |
< |
P96SA_Exclusive, TRUE, |
265 |
< |
TAG_END |
266 |
< |
); |
267 |
< |
} else { |
268 |
< |
the_screen = OpenScreenTags(NULL, |
269 |
< |
SA_DisplayID, mode_id, |
270 |
< |
SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
271 |
< |
SA_Quiet, TRUE, |
272 |
< |
SA_Exclusive, TRUE, |
273 |
< |
TAG_END |
274 |
< |
); |
275 |
< |
} |
276 |
< |
|
316 |
> |
the_screen = OpenScreenTags(NULL, |
317 |
> |
SA_DisplayID, mode_id, |
318 |
> |
SA_Title, (ULONG)GetString(STR_WINDOW_TITLE), |
319 |
> |
SA_Quiet, TRUE, |
320 |
> |
SA_Exclusive, TRUE, |
321 |
> |
TAG_END |
322 |
> |
); |
323 |
|
if (the_screen == NULL) { |
324 |
|
ErrorAlert(GetString(STR_OPEN_SCREEN_ERR)); |
325 |
|
return false; |
344 |
|
|
345 |
|
// Set VideoMonitor |
346 |
|
ScreenToFront(the_screen); |
347 |
< |
if (is_p96) { |
348 |
< |
VideoMonitor.mac_frame_base = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_MEMORY); |
349 |
< |
VideoMonitor.bytes_per_row = p96GetBitMapAttr(the_screen->RastPort.BitMap, P96BMA_BYTESPERROW); |
350 |
< |
} else { |
351 |
< |
static UWORD ptr[] = { 0, 0, 0, 0 }; |
352 |
< |
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide Pointer |
353 |
< |
|
308 |
< |
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
309 |
< |
LBMI_BASEADDRESS, (ULONG)&VideoMonitor.mac_frame_base, |
310 |
< |
TAG_END); |
311 |
< |
UnLockBitMap(handle); |
312 |
< |
VideoMonitor.bytes_per_row = GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD); |
313 |
< |
} |
347 |
> |
static UWORD ptr[] = { 0, 0, 0, 0 }; |
348 |
> |
SetPointer(the_win, ptr, 0, 0, 0, 0); // Hide mouse pointer |
349 |
> |
APTR handle = LockBitMapTags(the_screen->RastPort.BitMap, |
350 |
> |
LBMI_BASEADDRESS, (ULONG)&VideoMonitor.mac_frame_base, |
351 |
> |
TAG_END); |
352 |
> |
UnLockBitMap(handle); |
353 |
> |
VideoMonitor.bytes_per_row = GetCyberMapAttr(the_screen->RastPort.BitMap, CYBRMATTR_XMOD); |
354 |
|
return true; |
355 |
|
} |
356 |
|
|
357 |
|
bool VideoInit(bool classic) |
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(GetString(STR_NO_MEM_ERR)); |
363 |
+ |
return false; |
364 |
+ |
} |
365 |
+ |
|
366 |
|
// Read frame skip prefs |
367 |
|
frame_skip = PrefsFindInt32("frameskip"); |
368 |
|
if (frame_skip == 0) |
384 |
|
display_type = DISPLAY_WINDOW; |
385 |
|
else if (sscanf(mode_str, "pip/%d/%d", &width, &height) == 2 && P96Base) |
386 |
|
display_type = DISPLAY_PIP; |
387 |
< |
else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && (CyberGfxBase || P96Base)) |
388 |
< |
display_type = DISPLAY_SCREEN; |
387 |
> |
else if (sscanf(mode_str, "scr/%08lx", &mode_id) == 1 && (CyberGfxBase || P96Base)) { |
388 |
> |
if (P96Base && p96GetModeIDAttr(mode_id, P96IDA_ISP96)) |
389 |
> |
display_type = DISPLAY_SCREEN_P96; |
390 |
> |
else if (CyberGfxBase && IsCyberModeID(mode_id)) |
391 |
> |
display_type = DISPLAY_SCREEN_CGFX; |
392 |
> |
else { |
393 |
> |
ErrorAlert(GetString(STR_NO_P96_MODE_ERR)); |
394 |
> |
return false; |
395 |
> |
} |
396 |
> |
} |
397 |
|
} |
398 |
|
|
399 |
|
// Open display |
408 |
|
return false; |
409 |
|
break; |
410 |
|
|
411 |
< |
case DISPLAY_SCREEN: |
412 |
< |
if (!init_screen(mode_id)) |
411 |
> |
case DISPLAY_SCREEN_P96: |
412 |
> |
if (!init_screen_p96(mode_id)) |
413 |
> |
return false; |
414 |
> |
break; |
415 |
> |
|
416 |
> |
case DISPLAY_SCREEN_CGFX: |
417 |
> |
if (!init_screen_cgfx(mode_id)) |
418 |
|
return false; |
419 |
|
break; |
420 |
|
} |
473 |
|
p96PIP_Close(the_win); |
474 |
|
break; |
475 |
|
|
476 |
< |
case DISPLAY_SCREEN: |
476 |
> |
case DISPLAY_SCREEN_P96: |
477 |
|
|
478 |
|
// Close window |
479 |
|
if (the_win) |
481 |
|
|
482 |
|
// Close screen |
483 |
|
if (the_screen) { |
484 |
< |
if (is_p96) |
485 |
< |
p96CloseScreen(the_screen); |
486 |
< |
else |
487 |
< |
CloseScreen(the_screen); |
484 |
> |
p96CloseScreen(the_screen); |
485 |
> |
the_screen = NULL; |
486 |
> |
} |
487 |
> |
break; |
488 |
> |
|
489 |
> |
case DISPLAY_SCREEN_CGFX: |
490 |
|
|
491 |
+ |
// Close window |
492 |
+ |
if (the_win) |
493 |
+ |
CloseWindow(the_win); |
494 |
+ |
|
495 |
+ |
// Close screen |
496 |
+ |
if (the_screen) { |
497 |
+ |
CloseScreen(the_screen); |
498 |
|
the_screen = NULL; |
499 |
|
} |
500 |
|
break; |
501 |
|
} |
502 |
+ |
|
503 |
+ |
// Free mouse pointer |
504 |
+ |
if (null_pointer) { |
505 |
+ |
FreeMem(null_pointer, 12); |
506 |
+ |
null_pointer = NULL; |
507 |
+ |
} |
508 |
|
} |
509 |
|
|
510 |
|
|
514 |
|
|
515 |
|
void video_set_palette(uint8 *pal) |
516 |
|
{ |
517 |
< |
if (display_type == DISPLAY_SCREEN) { |
517 |
> |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) { |
518 |
|
|
519 |
|
// Convert palette to 32 bits |
520 |
|
ULONG table[2 + 256 * 3]; |
557 |
|
if (win_port) { |
558 |
|
win_mask = 1 << win_port->mp_SigBit; |
559 |
|
the_win->UserPort = win_port; |
560 |
< |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | (display_type == DISPLAY_SCREEN ? IDCMP_DELTAMOVE : 0)); |
560 |
> |
ModifyIDCMP(the_win, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY | ((display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) ? IDCMP_DELTAMOVE : 0)); |
561 |
|
} |
562 |
|
|
563 |
|
// Start 60Hz timer for window refresh |
615 |
|
// Handle message according to class |
616 |
|
switch (cl) { |
617 |
|
case IDCMP_MOUSEMOVE: |
618 |
< |
if (display_type == DISPLAY_SCREEN) |
618 |
> |
if (display_type == DISPLAY_SCREEN_P96 || display_type == DISPLAY_SCREEN_CGFX) |
619 |
|
ADBMouseMoved(mx, my); |
620 |
< |
else |
620 |
> |
else { |
621 |
|
ADBMouseMoved(mx - the_win->BorderLeft, my - the_win->BorderTop); |
622 |
+ |
if (mx < the_win->BorderLeft |
623 |
+ |
|| my < the_win->BorderTop |
624 |
+ |
|| mx >= the_win->BorderLeft + VideoMonitor.x |
625 |
+ |
|| my >= the_win->BorderTop + VideoMonitor.y) { |
626 |
+ |
if (current_pointer) { |
627 |
+ |
ClearPointer(the_win); |
628 |
+ |
current_pointer = NULL; |
629 |
+ |
} |
630 |
+ |
} else { |
631 |
+ |
if (current_pointer != null_pointer) { |
632 |
+ |
// Hide mouse pointer inside window |
633 |
+ |
SetPointer(the_win, null_pointer, 1, 16, 0, 0); |
634 |
+ |
current_pointer = null_pointer; |
635 |
+ |
} |
636 |
+ |
} |
637 |
+ |
} |
638 |
|
break; |
639 |
|
|
640 |
|
case IDCMP_MOUSEBUTTONS: |
655 |
|
case IDCMP_RAWKEY: |
656 |
|
if (qualifier & IEQUALIFIER_REPEAT) // Keyboard repeat is done by MacOS |
657 |
|
break; |
658 |
+ |
if ((qualifier & (IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) == |
659 |
+ |
(IEQUALIFIER_LALT | IEQUALIFIER_LSHIFT | IEQUALIFIER_CONTROL)) |
660 |
+ |
&& code == 0x5f) { |
661 |
+ |
SetInterruptFlag(INTFLAG_NMI); |
662 |
+ |
TriggerInterrupt(); |
663 |
+ |
break; |
664 |
+ |
} |
665 |
+ |
|
666 |
|
if (code & IECODE_UP_PREFIX) |
667 |
|
ADBKeyUp(keycode2mac[code & 0x7f]); |
668 |
|
else |