|
|
1.1 root 1: /*
2: * UAE - The Un*x Amiga Emulator
3: *
4: * p.OS interface
5: *
6: * Copyright 1997 Samuel Devulder.
7: */
8:
9: /****************************************************************************/
10:
11: #include "sysconfig.h"
12: #include "sysdeps.h"
13:
14: #include <ctype.h>
15: #include <signal.h>
16: #include <ix.h>
17:
18: /****************************************************************************/
19:
20: #include "threaddep/penguin.h"
21: #include "uae.h"
22: #include "config.h"
23: #include "options.h"
24: #include "../include/memory.h"
25: #include "custom.h"
26: #include "readcpu.h"
27: #include "newcpu.h"
28: #include "xwin.h"
29: #include "keyboard.h"
30: #include "keybuf.h"
31: #include "disk.h"
32: #include "debug.h"
33: #include "gui.h"
34: #include "uaeexe.h"
35: #include "picasso96.h"
36:
37: /****************************************************************************/
38:
39: struct pOS_Locale;
40: struct pOS_Library;
41: struct pOS_ExecBase;
42: struct pOS_DosBase;
43: struct pOS_Method;
44: struct pOS_Resource;
45: struct pOS_RawDoFmtData;
46: struct pOS_AsciiDoFmtData;
47: struct pOS_AsciiFmtData;
48: struct pOS_ClassGrp;
49: struct pOS_DosDevPathInfo;
50: struct pOS_ShellScript;
51: struct pOS_SegmentInfo;
52: struct IClass;
53: struct Isrvstr;
54: struct TagItem;
55: struct MemHeader;
56: struct SemaphoreMessage;
57: struct StackSwapStruct;
58: struct Interrupt;
59: struct StandardPacket;
60: struct InfoData;
61: struct WBStartup;
62:
63: #define _SIZE_T /* to avoid interference with <syst/types.h> */
64: #include <pExec/Types.h>
65: #include <pDOS/Lock.h>
66: #include <pDOS/ArgTags.h>
67: #include <pDOS/DosSig.h>
68: #include <pDOS/DosErrors.h>
69: #include <psl/FileReq.h>
70: #include <psl/pSLTags.h>
71: #include <pGadget/Gadget.h>
72: #include <pGfx/StdGMap.h>
73: #include <pGfx/StdCMap.h>
74: #include <pGfx/GfxTags.h>
75: #include <pGfx/RastPort.h>
76: #include <pScreen/ScrTags.h>
77: #include <pScreen/Window.h>
78: #include <pScreen/Screen.h>
79: #include <pScreen/DrawInfo.h>
80: #include <pIntui/IntuMsg.h>
81: #include <pIntui/ICI.h>
82: #include <pIntui/Tags.h>
83: #include <pIntui/GClass.h>
84: #include <pIntui/DragTags.h>
85: #include <pDtType/DClass.h>
86: #include <pDtType/DtBase.h>
87: #include <pDtType/DtTags.h>
88: #include <pDtType/DosObj.h>
89:
90: /*#include <pInline/pLibExt.h> */
91: #include <pInline/pExec2.h>
92: #include <pInline/pDos2.h>
93: #include <pInline/pIntui2.h>
94: #include <pInline/pGfx2.h>
95: #include <pInline/pPSL2.h>
96: #include <pInline/pDtType2.h>
97:
98: /****************************************************************************/
99:
100: xcolnr xcolors[4096];
101:
102: /* Keyboard and mouse */
103:
104: static int keystate[256];
105:
106: int buttonstate[3];
107: int lastmx, lastmy;
108: int newmousecounters;
109:
110: static int inwindow;
111:
112: struct vidbuf_description gfxvidinfo;
113: static char *oldpixbuf;
114:
115: /****************************************************************************/
116: /*
117: * prototypes & global vars
118: */
119: extern int rexx_init(void);
120: extern void rexx_exit(void);
121: extern void initpseudodevices(void);
122: extern void closepseudodevices(void);
123: extern char *to_unix_path(char *s);
124: extern char *from_unix_path(char *s);
125: extern void split_dir_file(char *src, char **dir, char **file);
126:
127: void main_window_led(int led, int on);
128: ULONG pOS_GetObjectData(APTR obj,ULONG tag);
129:
130: extern struct pOS_ExecBase *gb_ExecBase;
131: extern struct pOS_ExecLibFunction *gb_ExecLib;
132: extern struct pOS_DosBase *gb_DosBase;
133: extern struct pOS_LocaleBase *gb_LocaleBase;
134:
135: struct pOS_IntuiDevice *gb_IntuiBase;
136: struct pOS_GfxBase *gb_GfxBase;
137: struct pOS_pSLBase *gb_PSLBase;
138: struct pOS_DataTypeBase *gb_DtTypeBase;
139:
140: /****************************************************************************/
141:
142: static void disk_hotkeys(void);
143: static void set_title(void);
144: static void HandleDrop(struct pOS_IEDragDrop *DD);
145:
146: static struct pOS_Window *W;
147: static struct pOS_RastPort *RP;
148: static struct pOS_StdRGB8GfxMap *GM24;
149: static struct pOS_StdChunky8GfxMap *GM8;
150: static struct pOS_StdRLColorMap *CM;
151: static struct pOS_Gadget *DDGad; /* Drag&Drop gadget */
152:
153: static int XOffset,YOffset;
154: static int use_gray;
155:
156: /****************************************************************************/
157:
158: static RETSIGTYPE sigbrkhandler(int foo)
159: {
160: activate_debugger();
161: }
162:
163: void setup_brkhandler(void)
164: {
165: signal(SIGINT,sigbrkhandler);
166: }
167:
168: /****************************************************************************/
169:
170: __inline__ void flush_line(int y)
171: {
172: int len, l;
173: unsigned char *buf, *dst, *src;
174: int xs;
175:
176: if(y<0 || y>=gfxvidinfo.height) return;
177: xs = 0;
178: len = gfxvidinfo.width;
179: buf = gfxvidinfo.linemem; if(!buf)
180: buf = gfxvidinfo.bufmem + y*gfxvidinfo.rowbytes;
181:
182: if(currprefs.use_low_bandwidth) {
183: switch(gfxvidinfo.pixbytes) {
184: case 2: {
185: short *newp = (short *)buf;
186: short *oldp = (short *)(oldpixbuf + y*gfxvidinfo.rowbytes);
187: while (*newp++ == *oldp++) if(!--len) return;
188: src = (char *)--newp;
189: dst = (char *)--oldp;
190: newp += len;
191: oldp += len;
192: while (*--newp == *--oldp);
193: len = 1 + (oldp - (short *)dst);
194: xs = (src - buf)/2;
195: pOS_CopyMem (src, dst, len * 2);
196: } break;
197: case 1: {
198: char *newp = (char *)buf;
199: char *oldp = (char *)(oldpixbuf + y*gfxvidinfo.rowbytes);
200: while (*newp++ == *oldp++) if(!--len) return;
201: src = (char *)--newp;
202: dst = (char *)--oldp;
203: newp += len;
204: oldp += len;
205: while (*--newp == *--oldp);
206: len = 1 + (oldp - (char *)dst);
207: xs = (src - buf);
208: pOS_CopyMem (src, dst, len);
209: } break;
210: default: abort();
211: }
212: }
213: switch(gfxvidinfo.pixbytes) {
214: case 1:
215: buf += xs;
216: l = len; src = buf; dst = GM8->ckgm_Chunky+xs;
217: while(l--) {*dst++ = *src++;}
218: pOS_WriteStdGfxMapRastPort(&GM8->ckgm_Gfx,xs,0,
219: RP,XOffset+xs,YOffset+y,len,1,0);
220: break;
221: case 2:
222: /* if only pOS could provide a ARGB8 struct that fits on a ULONG */
223: buf += 2*xs;
224: l = len; src = buf; dst = GM24->rgbgm_R+xs;
225: while(l--) {*dst++ = (ULONG)*src * 0x11 ; src+=2;}
226: l = len; src = buf+1; dst = GM24->rgbgm_G+xs;
227: while(l--) {*dst++ = (ULONG)(*src>>4) * 0x11; src+=2;}
228: l = len; src = buf+1; dst = GM24->rgbgm_B+xs;
229: while(l--) {*dst++ = (ULONG)(*src&15) * 0x11; src+=2;}
230: pOS_WriteStdGfxMapRastPort(&GM24->rgbgm_Gfx,xs,0,
231: RP,XOffset+xs,YOffset+y,len,1,0);
232: break;
233: }
234: }
235:
236: /****************************************************************************/
237:
238: void flush_block (int ystart, int ystop)
239: {
240: int y;
241: for(y=ystart; y<=ystop; ++y) flush_line(y);
242: }
243:
244: /****************************************************************************/
245:
246: void flush_screen (int ystart, int ystop)
247: {
248: }
249:
250: /****************************************************************************/
251:
252: static int get_color(int r, int g, int b, xcolnr *cnp)
253: {
254: static int col;
255:
256: r *= 0x11; g *= 0x11; b *= 0x11;
257: if(use_gray) r = g = b = (77*r + 151*g + 29*b) / 256;
258:
259: CM->rlcm_Colors[col].rc_U.rc_E.rcue_R = r;
260: CM->rlcm_Colors[col].rc_U.rc_E.rcue_G = g;
261: CM->rlcm_Colors[col].rc_U.rc_E.rcue_B = b;
262:
263: *cnp = col++;
264:
265: return 1;
266: }
267:
268: /****************************************************************************/
269:
270: static int init_colors(void)
271: {
272: int i;
273:
274: switch(currprefs.color_mode) {
275: case 0: case 2:
276: write_log("Using 256 gray scales.\n");
277: use_gray = 1;
278: /* fall through */
279: case 1:
280: if(!use_gray) write_log("Using 256 colors.\n");
281: alloc_colors256(get_color);
282: break;
283: case 3:
284: printf("Using truecolor.\n");
285: for(i=0;i<4096;++i) xcolors[i] = i;
286: break;
287: }
288: switch (gfxvidinfo.pixbytes) {
289: case 2:
290: for (i = 0; i < 4096; i++)
291: xcolors[i] = xcolors[i] * 0x00010001;
292: gfxvidinfo.can_double = 1;
293: break;
294: case 1:
295: for (i = 0; i < 4096; i++)
296: xcolors[i] = xcolors[i] * 0x01010101;
297: gfxvidinfo.can_double = 1;
298: break;
299: default:
300: gfxvidinfo.can_double = 0;
301: break;
302: }
303: return 1;
304: }
305:
306: /****************************************************************************/
307:
308: #define IND "==="
309:
310: static int setup_publicscreen(void)
311: {
312: static char ScreenTitle[100];
313: static struct pOS_IBox ZoomArray = {0,0,0,0};
314: struct pOS_Screen *S;
315:
316: sprintf(ScreenTitle,
317: "UAE-%d.%d.%d � by Bernd Schmidt & contributors, "
318: "p.OS Port by Samuel Devulder.",
319: (version / 100) % 10, (version / 10) % 10, version % 10);
320:
321: S = pOS_LockPubScreen(NULL);
322: if(!S) {
323: write_log("No public screen !\n");
324: return 0;
325: }
326:
327: if(currprefs.gfx_height + S->scr_BarHeight + 1 >= (int)S->scr_Height) {
328: currprefs.gfx_height >>= 1;
329: currprefs.gfx_correct_aspect = 1;
330: }
331:
332: DDGad = (void *)pOS_NewIObject(
333: NULL, S->scr_DrawInfo->dri_Names[SCRNAM_GClass], 0,
334: ICLTAG_GadBorderType, GADBORTYP_BlkBox,
335: ICLTAG_Left, 1,
336: ICLTAG_Top, 1,
337: ICLTAG_RelWidth, -1,
338: ICLTAG_RelHeight, -1,
339: ICLTAG_StandardDrop, TRUE,
340: ICLTAG_AddDropAttName, (ULONG)"#?dosobj/#?",
341: // ICLTAG_StandardDrag, TRUE,
342: ICLTAG_HighlightDropBox, TRUE,
343: ICLTAG_NoSelect, TRUE,
344: TAG_DONE);
345:
346: ZoomArray.Top = 0;
347: ZoomArray.Left = S->scr_Width - 128;
348: ZoomArray.Width = 128;
349: ZoomArray.Height = S->scr_BarHeight+1;
350:
351: W=pOS_OpenWindow(
352: SCRTAG_Title, (ULONG)"UAE - Power: "IND" Disks: "
353: IND" "IND" "IND" "IND,
354: SCRTAG_ScreenTitle, (ULONG)ScreenTitle,
355: SCRTAG_Screen, (ULONG)S,
356: SCRTAG_InnerWidth, currprefs.gfx_width,
357: SCRTAG_InnerHeight, currprefs.gfx_height,
358: SCRTAG_AutoAdjust, TRUE,
359: SCRTAG_UnderMouse, TRUE,
360: SCRTAG_ZipGadget, TRUE,
361: SCRTAG_ZipIBox, (ULONG)&ZoomArray,
362: SCRTAG_Flags, WINFLGF_DepthGadget|
363: WINFLGF_SimpleRefresh|
364: WINFLGF_CloseGadget|
365: WINFLGF_Dragbar|
366: WINFLGF_ReportMouse|
367: WINFLGF_RMBTrap|
368: // WINFLGF_Activate|
369: 0,
370: SCRTAG_IDCMP, IDCMP_MouseButtons|
371: IDCMP_MouseMove|
372: IDCMP_RawKey|
373: IDCMP_ActiveWindow|
374: IDCMP_InactiveWindow|
375: IDCMP_CloseWindow|
376: IDCMP_RefreshWindow|
377: IDCMP_NewSize|
378: IDCMP_DragDrop|
379: 0,
380: SCRTAG_Gadget, (ULONG)DDGad,
381: TAG_DONE);
382: pOS_UnlockPubScreen(S);
383: if(!W) {
384: fprintf(stderr,"Can't open window !\n");
385: return 0;
386: }
387:
388: /* now we know the window box and can setup the drag&drop gad. */
389: {
390: struct pOS_IBox Box;
391:
392: pOS_GetWindowIBox(W, &Box, NULL);
393: --Box.Left;
394: --Box.Top;
395:
396: DDGad->gad_LeftEdge = Box.Left;
397: DDGad->gad_TopEdge = Box.Top;
398: DDGad->gad_Width = -(W->win_BorRight + W->win_BorLeft) + 2;
399: DDGad->gad_Height = -(W->win_BorBottom + W->win_BorTop) + 2;
400: /*
401: pOS_DrawBorderBox(W->win_RastPort, S->scr_DrawInfo,
402: (W->win_Flags&WINFLGF_Activate)?
403: GADBORTYP_BevelDownBox:GADBORTYP_HfBevelDownBox,
404: &Box);
405: */
406: }
407:
408: /* Give priority 0 when active, -1 when inactive */
409: pOS_SetWindowTask(W, pOS_FindTask(NULL), 0, -1);
410:
411: gfxvidinfo.width = (W->win_Width - W->win_BorRight - W->win_BorLeft);
412: gfxvidinfo.height = (W->win_Height - W->win_BorTop - W->win_BorBottom);
413: XOffset = W->win_BorLeft;
414: YOffset = W->win_BorTop;
415:
416: RP = W->win_RastPort;
417:
418: return 1;
419: }
420:
421: /****************************************************************************/
422:
423: #ifndef HAVE_SIGACTION /* test for -nixpos */
424: double frexp(double value, int *exp)
425: {
426: *exp = 0;
427: if(value>1) while(value>1) {value /= 2;++*exp;}
428: else if(value>0) while(value<1) {value *= 2;--*exp;}
429: else if(value<-1) while(value<-1) {value /= 2;++*exp;}
430: else if(value<0) while(value>-1) {value *= 2;--*exp;}
431: return value;
432: }
433:
434: double ldexp(double value, int exp)
435: {
436: if(exp<0) while(exp++) value /= 2;
437: else while(exp--) value *= 2;
438: return value;
439: }
440: #endif
441:
442: /****************************************************************************/
443:
444: int graphics_setup(void)
445: {
446: #ifdef HAVE_SIGACTION /* test for -nixpos */
447: if(ix_os != OS_IS_POS) {
448: ix_req(NULL, "Abort", NULL, "That version of %s is only for p.OS!", __progname);
449: exit(20);
450: }
451: #endif
452: gb_IntuiBase = (void*)pOS_OpenLibrary("pintui.library",0);
453: if(!gb_IntuiBase) {
454: fprintf(stderr,"No pintui.library ?\n");
455: return 0;
456: }
457: gb_GfxBase = (void*)pOS_OpenLibrary("pgraphics.library",0);
458: if(!gb_GfxBase) {
459: fprintf(stderr,"No pgraphics.library ?\n");
460: return 0;
461: }
462: gb_DtTypeBase =(void*)pOS_OpenLibrary("pDtType.library",0);
463: if(!gb_DtTypeBase) {
464: fprintf(stderr,"No pDtType.library ?\n");
465: return 0;
466: }
467: initpseudodevices();
468: atexit(graphics_leave);
469: return 1;
470: }
471:
472: /****************************************************************************/
473:
474: int graphics_init(void)
475: {
476: int i;
477:
478: if (currprefs.color_mode > 3) {
479: fprintf(stderr, "Bad color mode selected. Using default.\n");
480: currprefs.color_mode = 3;
481: }
482: if (currprefs.gfx_width < 320)
483: currprefs.gfx_width = 320;
484: if (currprefs.gfx_height < 100)
485: currprefs.gfx_height = 100;
486: currprefs.gfx_width += 7;
487: currprefs.gfx_width &= ~7;
488:
489: gfxvidinfo.width = currprefs.gfx_width;
490: gfxvidinfo.height = currprefs.gfx_height;
491:
492: if(!setup_publicscreen()) return 0;
493:
494: switch(currprefs.color_mode) {
495: case 0: case 1: case 2:
496: gfxvidinfo.pixbytes = 1;
497: CM=(void*)pOS_AllocColorMap(NULL,
498: GFXTAG_ColorType, COLMAPTYP_StdRLut,
499: GFXTAG_Colors, 256,
500: currprefs.color_mode==2?TAG_IGNORE:
501: GFXTAG_ColorFlags, COLMAPF_Q1,
502: TAG_END);
503: if(CM)
504: GM8=(void*)pOS_AllocGfxMap(NULL,
505: GFXTAG_Width, currprefs.gfx_width,
506: GFXTAG_Height, 1,
507: GFXTAG_GfxType, GFXMAPTYP_StdChunky8,
508: GFXTAG_CrtGfxMapEx, TRUE,
509: GFXTAG_ColorMap, (ULONG)CM,
510: TAG_END);
511: if(GM8) break;
512: write_log("trying 24bit GfxMap...\n");
513: /* fall through */
514: case 3: /* 24 bits */
515: gfxvidinfo.pixbytes = 2;
516: GM24=(void*)pOS_AllocGfxMap(NULL,
517: GFXTAG_Width, currprefs.gfx_width,
518: GFXTAG_Height, 1,
519: GFXTAG_GfxType, GFXMAPTYP_StdRGB8,
520: TAG_END);
521: break;
522: }
523:
524: if(!GM8 && !GM24) {
525: fprintf(stderr,"Unable to get GfxMap.\n");
526: return 0;
527: }
528:
529: gfxvidinfo.linemem = NULL;
530: gfxvidinfo.rowbytes = gfxvidinfo.pixbytes * currprefs.gfx_width;
531: gfxvidinfo.bufmem = (char *)calloc(gfxvidinfo.rowbytes,
532: currprefs.gfx_height);
533: if(!gfxvidinfo.bufmem) {
534: fprintf(stderr,"Not enough memory for video bufmem.\n");
535: return 0;
536: }
537: gfxvidinfo.maxblocklines = 0;
538:
539: if (currprefs.use_low_bandwidth) {
540: oldpixbuf = (char *)calloc(gfxvidinfo.rowbytes,
541: currprefs.gfx_height);
542: if(!gfxvidinfo.bufmem) {
543: write_log("Not enough mem for low-bandwidth!\n");
544: currprefs.use_low_bandwidth = 0;
545: } else gfxvidinfo.maxblocklines = currprefs.gfx_height-1;
546: }
547:
548: set_title();
549:
550: if (!init_colors()) {
551: write_log("Failed to init colors.\n");
552: return 0;
553: }
554:
555: buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
556: for(i=0; i<256; i++)
557: keystate[i] = 0;
558:
559: lastmx = lastmy = 0;
560: newmousecounters = 0;
561: inwindow = 0;
562:
563: rexx_init();
564:
565: pOS_ActivateWindow(W);
566:
567: return 1;
568: }
569:
570: /****************************************************************************/
571:
572: void graphics_leave(void)
573: {
574: rexx_exit();
575: closepseudodevices();
576: if(GM8) {
577: pOS_FreeGfxMap(&GM8->ckgm_Gfx);
578: GM8 = NULL;
579: }
580: if(GM24) {
581: pOS_FreeGfxMap(&GM24->rgbgm_Gfx);
582: GM24 = NULL;
583: }
584: if(CM) {
585: pOS_FreeColorMap(&CM->rlcm_CM);
586: CM = NULL;
587: }
588: if(W) {
589: pOS_CloseWindow(W);
590: W = NULL;
591: }
592: if(DDGad) {
593: pOS_DisposeIObject(DDGad);
594: DDGad = NULL;
595: }
596: if(gb_DtTypeBase) {
597: pOS_CloseLibrary((void*)gb_DtTypeBase);
598: gb_DtTypeBase = NULL;
599: }
600: if(gb_PSLBase) {
601: pOS_CloseLibrary((void*)gb_PSLBase);
602: gb_PSLBase = NULL;
603: }
604: if(gb_IntuiBase) {
605: pOS_CloseLibrary((void*)gb_IntuiBase);
606: gb_IntuiBase = NULL;
607: }
608: if(gb_GfxBase) {
609: pOS_CloseLibrary((void*)gb_GfxBase);
610: gb_GfxBase = NULL;
611: }
612: }
613:
614:
615: /***************************************************************************/
616:
617: void handle_events(void)
618: {
619: struct pOS_IntuiMessage *msg;
620: int mx,my,class,code;
621:
622: newmousecounters = 0;
623:
624: if(pOS_SetSignal(0L, DOSSIGF_CTRL_C|DOSSIGF_CTRL_D) &
625: (DOSSIGF_CTRL_C|DOSSIGF_CTRL_D)) {
626: activate_debugger();
627: }
628:
629: while((msg=(void*)pOS_GetMsg(W->win_UserPort))) {
630: class = msg->im_Class;
631: code = msg->im_Code;
632: mx = msg->im_MouseX;
633: my = msg->im_MouseY;
634:
635: mx -= XOffset;
636: my -= YOffset;
637:
638: switch(class) {
639: case IDCMP_DragDrop:
640: if(code == IECODE_DROP_WORK) { /* object is dropped */
641: struct pOS_IEDragDrop *DD;
642:
643: DD = &((struct pOS_ISMDrop*)msg->im_Data)->ismd_IEDD;
644: HandleDrop(DD);
645: pOS_ActivateWindow(W);
646: }
647: break;
648:
649: case IDCMP_NewSize:
650: /* where is WFLG_ZOOMED for pOS ? */
651: inhibit_frame = W->win_Height<50?1:0;
652: set_title();
653: break;
654:
655: case IDCMP_RefreshWindow:
656: if(currprefs.use_low_bandwidth) {
657: /* hack: this forces refresh */
658: char *ptr = oldpixbuf;
659: int i, len = gfxvidinfo.rowbytes;
660: for(i=0;i<gfxvidinfo.height;++i) {
661: ptr[00000] ^= 255;
662: ptr[len-1] ^= 255;
663: ptr += len;
664: }
665: }
666: pOS_BeginRefresh(W, NULL);
667: flush_block(0,gfxvidinfo.height-1);
668: pOS_EndRefresh(W, TRUE);
669: set_title();
670: break;
671:
672: case IDCMP_CloseWindow:
673: activate_debugger();
674: break;
675:
676: case IDCMP_RawKey: {
677: int kc = code&127;
678: int released = code&128?1:0;
679:
680: if(released) {
681: keystate[kc] = 0;
682: record_key ((kc << 1) | 1);
683: } else if (!keystate[kc]) {
684: keystate[kc] = 1;
685: record_key (kc << 1);
686: }
687: } break;
688:
689: case IDCMP_MouseMove:
690: if(inwindow) {
691: lastmx = mx;
692: lastmy = my;
693: } break;
694:
695: case IDCMP_MouseButtons:
696: if(code==IECODE_LBUTTON) buttonstate[0]=1;
697: if(code==IECODE_LBUTTON+IECODE_UP_PREFIX) buttonstate[0]=0;
698: if(code==IECODE_MBUTTON) buttonstate[1]=1;
699: if(code==IECODE_MBUTTON+IECODE_UP_PREFIX) buttonstate[1]=0;
700: if(code==IECODE_RBUTTON) buttonstate[2]=1;
701: if(code==IECODE_RBUTTON+IECODE_UP_PREFIX) buttonstate[2]=0;
702: break;
703:
704: case IDCMP_ActiveWindow:
705: inwindow = 1;
706: newmousecounters = 1;
707: set_title();
708: break;
709:
710: case IDCMP_InactiveWindow:
711: inwindow = 0;
712: set_title();
713: break;
714:
715: case IDCMP_ChangeWindow:
716: set_title();
717: break;
718:
719: default:
720: fprintf(stderr, "Unknown class: 0x%x\n",class);
721: break;
722: }
723: if(msg && !pOS_SysIMessage(msg)) pOS_ReplyMsg(&msg->im_Message);
724: }
725: /* "Affengriff" */
726: if(keystate[AK_CTRL] && keystate[AK_LAMI] && keystate[AK_RAMI])
727: m68k_reset();
728:
729: /* PC-like :-) CTRL-ALT-DEL => reboot */
730: if(keystate[AK_CTRL] && (keystate[AK_LALT] || keystate[AK_RALT]) &&
731: keystate[AK_DEL])
732: m68k_reset();
733:
734: /* CTRL+LSHIFT+LALT+F10 on amiga => F12 on X11 */
735: /* F9 => ScrollLock on X11 (inhibit_frame) */
736: if(keystate[AK_CTRL] && keystate[AK_LSH] && keystate[AK_LALT]) {
737: if(keystate[AK_F10]) togglemouse();
738: if(keystate[AK_F9]) {
739: inhibit_frame ^= 1;
740: set_title();
741: if(inhibit_frame) printf("display disabled\n");
742: else printf("display enabled\n");
743: }
744: }
745: disk_hotkeys();
746: gui_handle_events();
747: }
748:
749: /***************************************************************************/
750:
751: int debuggable(void)
752: {
753: return 1;
754: }
755:
756: /***************************************************************************/
757:
758: int needmousehack(void)
759: {
760: return 1;
761: }
762:
763: /***************************************************************************/
764:
765: void LED(int on)
766: {
767: }
768:
769: /***************************************************************************/
770:
771: static int led_state[5];
772:
773: /* prints some text */
774: static void t_print(char *t, const struct pOS_DrawInfo *di)
775: {
776: pOS_SetABPenDrMd(RP, di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
777: SCRPEN_ActiveWinTitle:
778: SCRPEN_InactiveWinTitle],
779: di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
780: SCRPEN_ActiveWindow:
781: SCRPEN_InactiveWindow],
782: DRMD_Jam2);
783: pOS_DrawText(RP, t, strlen(t));
784: /*
785: RP->rp_CP.X += pOS_TextLength(RP, t, strlen(t));
786: */
787: }
788:
789: /* display one led */
790: static void t_led(ULONG BGR, const struct pOS_DrawInfo *di)
791: {
792: struct pOS_Rectangle rect;
793: int x,y,oy;
794:
795: oy = RP->rp_CP.Y;
796: x = RP->rp_CP.X;
797: y = (W->win_BorTop - 6)/2;
798:
799: rect.MinX = x;
800: rect.MaxX = x+pOS_TextLength(RP,IND,strlen(IND))-1;
801: rect.MinY = y;
802: rect.MaxY = y+5;
803:
804: if(BGR<=0x100000)
805: pOS_SetAPenR(RP, (struct pOS_RColor*)&BGR);
806: else
807: pOS_SetAPen(RP, di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
808: SCRPEN_ActiveWindow:SCRPEN_InactiveWindow]);
809:
810: pOS_DrawRectFill(RP, rect.MinX+1,rect.MinY+1, rect.MaxX-1,rect.MaxY-1);
811: pOS_DrawBorderBox(RP, di, (W->win_Flags&WINFLGF_Activate)?
812: GADBORTYP_BevelDownBox:GADBORTYP_HfBevelDownBox,
813: &rect);
814: RP->rp_CP.X = rect.MaxX+1;
815: RP->rp_CP.Y = oy;
816: }
817:
818: static void set_title(void)
819: {
820: int drk, red, grn;
821: const struct pOS_DrawInfo *di = W->win_ICI->ici_DrawInfo;
822:
823: if(W->win_Width<=128) return; /* iconified: no txt */
824:
825: pOS_SetPosition(RP, 25, (W->win_BorTop - RP->rp_TxHeight)/2
826: + RP->rp_TxBaseline);
827:
828:
829: red = (W->win_Flags&WINFLGF_Activate)?255:190;
830: grn = ((W->win_Flags&WINFLGF_Activate)?255:190)<<8;
831: drk = 0x1000000/*0xAAAAAA*/;
832:
833: t_print("UAE - Power: ", di);
834: t_led(led_state[0]?red:drk, di);
835: t_print(" Disks: ", di);
836: t_led(led_state[1]?grn:drk, di);
837: t_print(" ", di);
838: t_led(led_state[2]?grn:drk, di);
839: t_print(" ", di);
840: t_led(led_state[3]?grn:drk, di);
841: t_print(" ", di);
842: t_led(led_state[4]?grn:drk, di);
843: }
844:
845: /****************************************************************************/
846:
847: void main_window_led(int led, int on) /* is used in amigui.c */
848: {
849: if(led>=0 && led<=4) led_state[led] = on;
850: set_title();
851: }
852:
853: /****************************************************************************/
854:
855: static void unrecord(int kc)
856: {
857: keystate[kc] = 0;
858: record_key ((kc << 1) | 1);
859: }
860:
861: /****************************************************************************/
862:
863: static void disk_hotkeys(void)
864: {
865: struct pOS_PslFileRequester *FileRequest;
866: char buff[80];
867: int drive;
868: char *last_file,*last_dir,*s;
869:
870: if(!(keystate[AK_CTRL] && keystate[AK_LALT])) return;
871:
872: /* CTRL-LSHIFT-LALT F1-F4 => eject_disk */
873: if(keystate[AK_LSH]) {
874: int ok = 0;
875:
876: if(keystate[AK_F1]) {ok=1;disk_eject(0);
877: printf("drive DF0: ejected\n");}
878: if(keystate[AK_F2]) {ok=1;disk_eject(1);
879: printf("drive DF1: ejected\n");}
880: if(keystate[AK_F3]) {ok=1;disk_eject(2);
881: printf("drive DF2: ejected\n");}
882: if(keystate[AK_F4]) {ok=1;disk_eject(3);
883: printf("drive DF3: ejected\n");}
884:
885: if(ok) {
886: unrecord(AK_CTRL);unrecord(AK_LALT);unrecord(AK_LSH);
887: unrecord(AK_F1);unrecord(AK_F2);
888: unrecord(AK_F3);unrecord(AK_F4);
889: }
890: return;
891: }
892:
893: /* CTRL-LALT F1-F4 => insert_disk */
894: if(keystate[AK_F1]) {drive = 0;unrecord(AK_F1);}
895: else if(keystate[AK_F2]) {drive = 1;unrecord(AK_F2);}
896: else if(keystate[AK_F3]) {drive = 2;unrecord(AK_F3);}
897: else if(keystate[AK_F4]) {drive = 3;unrecord(AK_F4);}
898: else return;
899: unrecord(AK_CTRL);unrecord(AK_LALT);
900:
901: switch(drive) {
902: case 0: case 1: case 2: case 3: last_file = currprefs.df[drive]; break;
903: default: return;
904: }
905:
906: split_dir_file(from_unix_path(last_file), &last_dir, &last_file);
907: if(!last_file) return;
908: if(!last_dir) return;
909:
910: if(!gb_PSLBase) gb_PSLBase=(void*)pOS_OpenLibrary("psl.library",0);
911: if(!gb_PSLBase) {
912: write_log("Can't open psl.library!\n");
913: return;
914: }
915:
916: FileRequest = pOS_AllocFileRequest(TAG_DONE);
917: if(!FileRequest) {
918: write_log("Unable to allocate file requester.\n");
919: return;
920: }
921:
922: sprintf(buff,"Select file to use for drive DF%d:",drive);
923: if(pOS_PslFileRequest(FileRequest,
924: PSLFRTAG_Title, (ULONG)buff,
925: PSLFRTAG_PathPart, (ULONG)last_dir,
926: PSLFRTAG_FilePart, (ULONG)last_file,
927: PSLFRTAG_Pattern, (ULONG)"(#?.ad(f|z)#?|df?|?)",
928: PSLFRTAG_PatternGad, TRUE,
929: TAG_DONE)) {
930: free(last_file);
931: last_file = malloc(3 + strlen(FileRequest->pfr_Path) +
932: strlen(FileRequest->pfr_File));
933: if(last_file) {
934: s = last_file;
935: strcpy(s,FileRequest->pfr_Path);
936: if(*s && !(s[strlen(s)-1]==':' || s[strlen(s)-1]=='/'))
937: strcat(s,"/");
938: strcat(s,FileRequest->pfr_File);
939: last_file = to_unix_path(s);free(s);
940: }
941: } else {
942: free(last_file);
943: last_file = NULL;
944: }
945: pOS_FreePslRequest(FileRequest);
946: free(last_dir);
947:
948: if(last_file) {
949: disk_insert(drive,last_file);
950: free(last_file);
951: }
952: }
953:
954: void write_log (const char *buf)
955: {
956: fprintf (stderr, buf);
957: }
958:
959: /****************************************************************************/
960:
961: ULONG pOS_GetObjectData(APTR obj,ULONG tag)
962: {
963: struct pOS_IntuiMethod Mth;
964: ULONG Dt;
965:
966: Mth.imth_Method=ICLMTH_Get;
967: Mth.imth_U.imth_Get.imgt_ID=tag;
968: Mth.imth_U.imth_Get.imgt_Variable=&Dt;
969: pOS_DoIMethodA(obj,(struct pOS_Method*)&Mth);
970: return(Dt);
971: }
972:
973: /****************************************************************************/
974:
975: #define SIZE 1024
976:
977: static void HandleDrop(struct pOS_IEDragDrop *dd)
978: {
979: char *Type = (char*)pOS_GetObjectData(dd->iedd_Object, DCLTAG_Type);
980: if(!stricmp(Type, pOS_DTFORM_DOSOBJ)) {
981: char *Buffer = (CHAR*)pOS_AllocMem(2*SIZE, MEMF_ANY);
982: if( Buffer ) {
983: struct pOS_DtTypeDosObj DosObj = {NULL, 0, NULL};
984: struct pOS_DClassInfo DCI = {
985: pOS_DTFORM_DOSOBJ, NULL, DCLINFOF_None, NULL
986: };
987:
988: pOS_DCLASSINFO(&DCI);
989: DCI.dci_Data = &DosObj;
990:
991: DosObj.dtdos_Buffer = Buffer+SIZE;
992: DosObj.dtdos_BufSize = SIZE;
993: strcpy(DosObj.dtdos_Buffer, "run ");
994: DosObj.dtdos_Buffer += strlen(DosObj.dtdos_Buffer);
995: DosObj.dtdos_BufSize -= strlen(DosObj.dtdos_Buffer);
996:
997: if(pOS_LoadDTObjectA(dd->iedd_Object, &DCI, NULL)) {
998: if(DCI.dci_Result > 0) {
999: if(DosObj.dtdos_Lock) {
1000: strcpy(Buffer, "cd ");
1001:
1002: pOS_NameFromObjectLock(DosObj.dtdos_Lock,
1003: Buffer+3, SIZE-3-1);
1004: uaeexe(Buffer);
1005: uaeexe(DosObj.dtdos_Buffer);
1006: } else {
1007: uaeexe(DosObj.dtdos_Buffer);
1008: }
1009: }
1010: }
1011: }
1012: pOS_FreeMem(Buffer, 2*SIZE);
1013: }
1014: }
1015:
1016: /***************************************************************************/
1017:
1018: /* sam: need to put all this in a separate module */
1019:
1020: #ifdef PICASSO96
1021:
1022: void DX_Invalidate (int first, int last)
1023: {
1024: }
1025:
1026: int DX_BitsPerCannon (void)
1027: {
1028: return 8;
1029: }
1030:
1031: void DX_SetPalette(int start, int count)
1032: {
1033: }
1034:
1035: int DX_FillResolutions (uae_u16 *ppixel_format)
1036: {
1037: return 0;
1038: }
1039:
1040: void gfx_set_picasso_modeinfo (int w, int h, int depth)
1041: {
1042: }
1043:
1044: void gfx_set_picasso_baseaddr (uaecptr a)
1045: {
1046: }
1047:
1048: void gfx_set_picasso_state (int on)
1049: {
1050: }
1051:
1052: void begindrawing (void)
1053: {
1054: }
1055:
1056: void enddrawing (void)
1057: {
1058: }
1059:
1060: uae_u8 *lockscr (void)
1061: {
1062: return NULL;
1063: }
1064:
1065: void unlockscr (void)
1066: {
1067: }
1068: #endif
1069:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.