|
|
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:
1.1.1.2 ! root 529: gfxvidinfo.emergmem = 0;
! 530: gfxvidinfo.linemem = 0;
1.1 root 531: gfxvidinfo.rowbytes = gfxvidinfo.pixbytes * currprefs.gfx_width;
532: gfxvidinfo.bufmem = (char *)calloc(gfxvidinfo.rowbytes,
533: currprefs.gfx_height);
534: if(!gfxvidinfo.bufmem) {
535: fprintf(stderr,"Not enough memory for video bufmem.\n");
536: return 0;
537: }
538: gfxvidinfo.maxblocklines = 0;
539:
540: if (currprefs.use_low_bandwidth) {
541: oldpixbuf = (char *)calloc(gfxvidinfo.rowbytes,
542: currprefs.gfx_height);
543: if(!gfxvidinfo.bufmem) {
544: write_log("Not enough mem for low-bandwidth!\n");
545: currprefs.use_low_bandwidth = 0;
546: } else gfxvidinfo.maxblocklines = currprefs.gfx_height-1;
547: }
548:
549: set_title();
550:
551: if (!init_colors()) {
552: write_log("Failed to init colors.\n");
553: return 0;
554: }
555:
556: buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
557: for(i=0; i<256; i++)
558: keystate[i] = 0;
559:
560: lastmx = lastmy = 0;
561: newmousecounters = 0;
562: inwindow = 0;
563:
564: rexx_init();
565:
566: pOS_ActivateWindow(W);
567:
568: return 1;
569: }
570:
571: /****************************************************************************/
572:
573: void graphics_leave(void)
574: {
575: rexx_exit();
576: closepseudodevices();
577: if(GM8) {
578: pOS_FreeGfxMap(&GM8->ckgm_Gfx);
579: GM8 = NULL;
580: }
581: if(GM24) {
582: pOS_FreeGfxMap(&GM24->rgbgm_Gfx);
583: GM24 = NULL;
584: }
585: if(CM) {
586: pOS_FreeColorMap(&CM->rlcm_CM);
587: CM = NULL;
588: }
589: if(W) {
590: pOS_CloseWindow(W);
591: W = NULL;
592: }
593: if(DDGad) {
594: pOS_DisposeIObject(DDGad);
595: DDGad = NULL;
596: }
597: if(gb_DtTypeBase) {
598: pOS_CloseLibrary((void*)gb_DtTypeBase);
599: gb_DtTypeBase = NULL;
600: }
601: if(gb_PSLBase) {
602: pOS_CloseLibrary((void*)gb_PSLBase);
603: gb_PSLBase = NULL;
604: }
605: if(gb_IntuiBase) {
606: pOS_CloseLibrary((void*)gb_IntuiBase);
607: gb_IntuiBase = NULL;
608: }
609: if(gb_GfxBase) {
610: pOS_CloseLibrary((void*)gb_GfxBase);
611: gb_GfxBase = NULL;
612: }
613: }
614:
615:
616: /***************************************************************************/
617:
618: void handle_events(void)
619: {
620: struct pOS_IntuiMessage *msg;
621: int mx,my,class,code;
622:
623: newmousecounters = 0;
624:
625: if(pOS_SetSignal(0L, DOSSIGF_CTRL_C|DOSSIGF_CTRL_D) &
626: (DOSSIGF_CTRL_C|DOSSIGF_CTRL_D)) {
627: activate_debugger();
628: }
629:
630: while((msg=(void*)pOS_GetMsg(W->win_UserPort))) {
631: class = msg->im_Class;
632: code = msg->im_Code;
633: mx = msg->im_MouseX;
634: my = msg->im_MouseY;
635:
636: mx -= XOffset;
637: my -= YOffset;
638:
639: switch(class) {
640: case IDCMP_DragDrop:
641: if(code == IECODE_DROP_WORK) { /* object is dropped */
642: struct pOS_IEDragDrop *DD;
643:
644: DD = &((struct pOS_ISMDrop*)msg->im_Data)->ismd_IEDD;
645: HandleDrop(DD);
646: pOS_ActivateWindow(W);
647: }
648: break;
649:
650: case IDCMP_NewSize:
651: /* where is WFLG_ZOOMED for pOS ? */
652: inhibit_frame = W->win_Height<50?1:0;
653: set_title();
654: break;
655:
656: case IDCMP_RefreshWindow:
657: if(currprefs.use_low_bandwidth) {
658: /* hack: this forces refresh */
659: char *ptr = oldpixbuf;
660: int i, len = gfxvidinfo.rowbytes;
661: for(i=0;i<gfxvidinfo.height;++i) {
662: ptr[00000] ^= 255;
663: ptr[len-1] ^= 255;
664: ptr += len;
665: }
666: }
667: pOS_BeginRefresh(W, NULL);
668: flush_block(0,gfxvidinfo.height-1);
669: pOS_EndRefresh(W, TRUE);
670: set_title();
671: break;
672:
673: case IDCMP_CloseWindow:
674: activate_debugger();
675: break;
676:
677: case IDCMP_RawKey: {
678: int kc = code&127;
679: int released = code&128?1:0;
680:
681: if(released) {
682: keystate[kc] = 0;
683: record_key ((kc << 1) | 1);
684: } else if (!keystate[kc]) {
685: keystate[kc] = 1;
686: record_key (kc << 1);
687: }
688: } break;
689:
690: case IDCMP_MouseMove:
691: if(inwindow) {
692: lastmx = mx;
693: lastmy = my;
694: } break;
695:
696: case IDCMP_MouseButtons:
697: if(code==IECODE_LBUTTON) buttonstate[0]=1;
698: if(code==IECODE_LBUTTON+IECODE_UP_PREFIX) buttonstate[0]=0;
699: if(code==IECODE_MBUTTON) buttonstate[1]=1;
700: if(code==IECODE_MBUTTON+IECODE_UP_PREFIX) buttonstate[1]=0;
701: if(code==IECODE_RBUTTON) buttonstate[2]=1;
702: if(code==IECODE_RBUTTON+IECODE_UP_PREFIX) buttonstate[2]=0;
703: break;
704:
705: case IDCMP_ActiveWindow:
706: inwindow = 1;
707: newmousecounters = 1;
708: set_title();
709: break;
710:
711: case IDCMP_InactiveWindow:
712: inwindow = 0;
713: set_title();
714: break;
715:
716: case IDCMP_ChangeWindow:
717: set_title();
718: break;
719:
720: default:
721: fprintf(stderr, "Unknown class: 0x%x\n",class);
722: break;
723: }
724: if(msg && !pOS_SysIMessage(msg)) pOS_ReplyMsg(&msg->im_Message);
725: }
726: /* "Affengriff" */
727: if(keystate[AK_CTRL] && keystate[AK_LAMI] && keystate[AK_RAMI])
728: m68k_reset();
729:
730: /* PC-like :-) CTRL-ALT-DEL => reboot */
731: if(keystate[AK_CTRL] && (keystate[AK_LALT] || keystate[AK_RALT]) &&
732: keystate[AK_DEL])
733: m68k_reset();
734:
735: /* CTRL+LSHIFT+LALT+F10 on amiga => F12 on X11 */
736: /* F9 => ScrollLock on X11 (inhibit_frame) */
737: if(keystate[AK_CTRL] && keystate[AK_LSH] && keystate[AK_LALT]) {
738: if(keystate[AK_F10]) togglemouse();
739: if(keystate[AK_F9]) {
740: inhibit_frame ^= 1;
741: set_title();
742: if(inhibit_frame) printf("display disabled\n");
743: else printf("display enabled\n");
744: }
745: }
746: disk_hotkeys();
747: gui_handle_events();
748: }
749:
750: /***************************************************************************/
751:
752: int debuggable(void)
753: {
754: return 1;
755: }
756:
757: /***************************************************************************/
758:
759: int needmousehack(void)
760: {
761: return 1;
762: }
763:
764: /***************************************************************************/
765:
766: void LED(int on)
767: {
768: }
769:
770: /***************************************************************************/
771:
772: static int led_state[5];
773:
774: /* prints some text */
775: static void t_print(char *t, const struct pOS_DrawInfo *di)
776: {
777: pOS_SetABPenDrMd(RP, di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
778: SCRPEN_ActiveWinTitle:
779: SCRPEN_InactiveWinTitle],
780: di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
781: SCRPEN_ActiveWindow:
782: SCRPEN_InactiveWindow],
783: DRMD_Jam2);
784: pOS_DrawText(RP, t, strlen(t));
785: /*
786: RP->rp_CP.X += pOS_TextLength(RP, t, strlen(t));
787: */
788: }
789:
790: /* display one led */
791: static void t_led(ULONG BGR, const struct pOS_DrawInfo *di)
792: {
793: struct pOS_Rectangle rect;
794: int x,y,oy;
795:
796: oy = RP->rp_CP.Y;
797: x = RP->rp_CP.X;
798: y = (W->win_BorTop - 6)/2;
799:
800: rect.MinX = x;
801: rect.MaxX = x+pOS_TextLength(RP,IND,strlen(IND))-1;
802: rect.MinY = y;
803: rect.MaxY = y+5;
804:
805: if(BGR<=0x100000)
806: pOS_SetAPenR(RP, (struct pOS_RColor*)&BGR);
807: else
808: pOS_SetAPen(RP, di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
809: SCRPEN_ActiveWindow:SCRPEN_InactiveWindow]);
810:
811: pOS_DrawRectFill(RP, rect.MinX+1,rect.MinY+1, rect.MaxX-1,rect.MaxY-1);
812: pOS_DrawBorderBox(RP, di, (W->win_Flags&WINFLGF_Activate)?
813: GADBORTYP_BevelDownBox:GADBORTYP_HfBevelDownBox,
814: &rect);
815: RP->rp_CP.X = rect.MaxX+1;
816: RP->rp_CP.Y = oy;
817: }
818:
819: static void set_title(void)
820: {
821: int drk, red, grn;
822: const struct pOS_DrawInfo *di = W->win_ICI->ici_DrawInfo;
823:
824: if(W->win_Width<=128) return; /* iconified: no txt */
825:
826: pOS_SetPosition(RP, 25, (W->win_BorTop - RP->rp_TxHeight)/2
827: + RP->rp_TxBaseline);
828:
829:
830: red = (W->win_Flags&WINFLGF_Activate)?255:190;
831: grn = ((W->win_Flags&WINFLGF_Activate)?255:190)<<8;
832: drk = 0x1000000/*0xAAAAAA*/;
833:
834: t_print("UAE - Power: ", di);
835: t_led(led_state[0]?red:drk, di);
836: t_print(" Disks: ", di);
837: t_led(led_state[1]?grn:drk, di);
838: t_print(" ", di);
839: t_led(led_state[2]?grn:drk, di);
840: t_print(" ", di);
841: t_led(led_state[3]?grn:drk, di);
842: t_print(" ", di);
843: t_led(led_state[4]?grn:drk, di);
844: }
845:
846: /****************************************************************************/
847:
848: void main_window_led(int led, int on) /* is used in amigui.c */
849: {
850: if(led>=0 && led<=4) led_state[led] = on;
851: set_title();
852: }
853:
854: /****************************************************************************/
855:
856: static void unrecord(int kc)
857: {
858: keystate[kc] = 0;
859: record_key ((kc << 1) | 1);
860: }
861:
862: /****************************************************************************/
863:
864: static void disk_hotkeys(void)
865: {
866: struct pOS_PslFileRequester *FileRequest;
867: char buff[80];
868: int drive;
869: char *last_file,*last_dir,*s;
870:
871: if(!(keystate[AK_CTRL] && keystate[AK_LALT])) return;
872:
873: /* CTRL-LSHIFT-LALT F1-F4 => eject_disk */
874: if(keystate[AK_LSH]) {
875: int ok = 0;
876:
877: if(keystate[AK_F1]) {ok=1;disk_eject(0);
878: printf("drive DF0: ejected\n");}
879: if(keystate[AK_F2]) {ok=1;disk_eject(1);
880: printf("drive DF1: ejected\n");}
881: if(keystate[AK_F3]) {ok=1;disk_eject(2);
882: printf("drive DF2: ejected\n");}
883: if(keystate[AK_F4]) {ok=1;disk_eject(3);
884: printf("drive DF3: ejected\n");}
885:
886: if(ok) {
887: unrecord(AK_CTRL);unrecord(AK_LALT);unrecord(AK_LSH);
888: unrecord(AK_F1);unrecord(AK_F2);
889: unrecord(AK_F3);unrecord(AK_F4);
890: }
891: return;
892: }
893:
894: /* CTRL-LALT F1-F4 => insert_disk */
895: if(keystate[AK_F1]) {drive = 0;unrecord(AK_F1);}
896: else if(keystate[AK_F2]) {drive = 1;unrecord(AK_F2);}
897: else if(keystate[AK_F3]) {drive = 2;unrecord(AK_F3);}
898: else if(keystate[AK_F4]) {drive = 3;unrecord(AK_F4);}
899: else return;
900: unrecord(AK_CTRL);unrecord(AK_LALT);
901:
902: switch(drive) {
903: case 0: case 1: case 2: case 3: last_file = currprefs.df[drive]; break;
904: default: return;
905: }
906:
907: split_dir_file(from_unix_path(last_file), &last_dir, &last_file);
908: if(!last_file) return;
909: if(!last_dir) return;
910:
911: if(!gb_PSLBase) gb_PSLBase=(void*)pOS_OpenLibrary("psl.library",0);
912: if(!gb_PSLBase) {
913: write_log("Can't open psl.library!\n");
914: return;
915: }
916:
917: FileRequest = pOS_AllocFileRequest(TAG_DONE);
918: if(!FileRequest) {
919: write_log("Unable to allocate file requester.\n");
920: return;
921: }
922:
923: sprintf(buff,"Select file to use for drive DF%d:",drive);
924: if(pOS_PslFileRequest(FileRequest,
925: PSLFRTAG_Title, (ULONG)buff,
926: PSLFRTAG_PathPart, (ULONG)last_dir,
927: PSLFRTAG_FilePart, (ULONG)last_file,
928: PSLFRTAG_Pattern, (ULONG)"(#?.ad(f|z)#?|df?|?)",
929: PSLFRTAG_PatternGad, TRUE,
930: TAG_DONE)) {
931: free(last_file);
932: last_file = malloc(3 + strlen(FileRequest->pfr_Path) +
933: strlen(FileRequest->pfr_File));
934: if(last_file) {
935: s = last_file;
936: strcpy(s,FileRequest->pfr_Path);
937: if(*s && !(s[strlen(s)-1]==':' || s[strlen(s)-1]=='/'))
938: strcat(s,"/");
939: strcat(s,FileRequest->pfr_File);
940: last_file = to_unix_path(s);free(s);
941: }
942: } else {
943: free(last_file);
944: last_file = NULL;
945: }
946: pOS_FreePslRequest(FileRequest);
947: free(last_dir);
948:
949: if(last_file) {
950: disk_insert(drive,last_file);
951: free(last_file);
952: }
953: }
954:
955: /****************************************************************************/
956:
957: ULONG pOS_GetObjectData(APTR obj,ULONG tag)
958: {
959: struct pOS_IntuiMethod Mth;
960: ULONG Dt;
961:
962: Mth.imth_Method=ICLMTH_Get;
963: Mth.imth_U.imth_Get.imgt_ID=tag;
964: Mth.imth_U.imth_Get.imgt_Variable=&Dt;
965: pOS_DoIMethodA(obj,(struct pOS_Method*)&Mth);
966: return(Dt);
967: }
968:
969: /****************************************************************************/
970:
971: #define SIZE 1024
972:
973: static void HandleDrop(struct pOS_IEDragDrop *dd)
974: {
975: char *Type = (char*)pOS_GetObjectData(dd->iedd_Object, DCLTAG_Type);
976: if(!stricmp(Type, pOS_DTFORM_DOSOBJ)) {
977: char *Buffer = (CHAR*)pOS_AllocMem(2*SIZE, MEMF_ANY);
978: if( Buffer ) {
979: struct pOS_DtTypeDosObj DosObj = {NULL, 0, NULL};
980: struct pOS_DClassInfo DCI = {
981: pOS_DTFORM_DOSOBJ, NULL, DCLINFOF_None, NULL
982: };
983:
984: pOS_DCLASSINFO(&DCI);
985: DCI.dci_Data = &DosObj;
986:
987: DosObj.dtdos_Buffer = Buffer+SIZE;
988: DosObj.dtdos_BufSize = SIZE;
989: strcpy(DosObj.dtdos_Buffer, "run ");
990: DosObj.dtdos_Buffer += strlen(DosObj.dtdos_Buffer);
991: DosObj.dtdos_BufSize -= strlen(DosObj.dtdos_Buffer);
992:
993: if(pOS_LoadDTObjectA(dd->iedd_Object, &DCI, NULL)) {
994: if(DCI.dci_Result > 0) {
995: if(DosObj.dtdos_Lock) {
996: strcpy(Buffer, "cd ");
997:
998: pOS_NameFromObjectLock(DosObj.dtdos_Lock,
999: Buffer+3, SIZE-3-1);
1000: uaeexe(Buffer);
1001: uaeexe(DosObj.dtdos_Buffer);
1002: } else {
1003: uaeexe(DosObj.dtdos_Buffer);
1004: }
1005: }
1006: }
1007: }
1008: pOS_FreeMem(Buffer, 2*SIZE);
1009: }
1010: }
1011:
1012: /***************************************************************************/
1013:
1014: /* sam: need to put all this in a separate module */
1015:
1016: #ifdef PICASSO96
1017:
1018: void DX_Invalidate (int first, int last)
1019: {
1020: }
1021:
1022: int DX_BitsPerCannon (void)
1023: {
1024: return 8;
1025: }
1026:
1027: void DX_SetPalette(int start, int count)
1028: {
1029: }
1030:
1031: int DX_FillResolutions (uae_u16 *ppixel_format)
1032: {
1033: return 0;
1034: }
1035:
1036: void gfx_set_picasso_modeinfo (int w, int h, int depth)
1037: {
1038: }
1039:
1040: void gfx_set_picasso_baseaddr (uaecptr a)
1041: {
1042: }
1043:
1044: void gfx_set_picasso_state (int on)
1045: {
1046: }
1047:
1048: void begindrawing (void)
1049: {
1050: }
1051:
1052: void enddrawing (void)
1053: {
1054: }
1055:
1056: uae_u8 *lockscr (void)
1057: {
1058: return NULL;
1059: }
1060:
1061: void unlockscr (void)
1062: {
1063: }
1064: #endif
1065:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.