Annotation of uae/src/od-pOS/pos-win.c, revision 1.1.1.5

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
1.1.1.4   root        3:   *
1.1       root        4:   * p.OS interface
1.1.1.4   root        5:   *
1.1       root        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: 
1.1.1.3   root       20: #include "threaddep/thread.h"
1.1       root       21: #include "uae.h"
                     22: #include "options.h"
                     23: #include "../include/memory.h"
1.1.1.4   root       24: #include "custom.h"
                     25: #include "readcpu.h"
                     26: #include "newcpu.h"
1.1       root       27: #include "xwin.h"
1.1.1.4   root       28: #include "keyboard.h"
                     29: #include "keybuf.h"
                     30: #include "disk.h"
1.1       root       31: #include "debug.h"
                     32: #include "gui.h"
                     33: #include "uaeexe.h"
                     34: #include "picasso96.h"
                     35: 
                     36: /****************************************************************************/
                     37: 
                     38: struct pOS_Locale;
                     39: struct pOS_Library;
                     40: struct pOS_ExecBase;
                     41: struct pOS_DosBase;
                     42: struct pOS_Method;
                     43: struct pOS_Resource;
                     44: struct pOS_RawDoFmtData;
                     45: struct pOS_AsciiDoFmtData;
                     46: struct pOS_AsciiFmtData;
                     47: struct pOS_ClassGrp;
                     48: struct pOS_DosDevPathInfo;
                     49: struct pOS_ShellScript;
                     50: struct pOS_SegmentInfo;
                     51: struct IClass;
                     52: struct Isrvstr;
                     53: struct TagItem;
                     54: struct MemHeader;
                     55: struct SemaphoreMessage;
                     56: struct StackSwapStruct;
                     57: struct Interrupt;
                     58: struct StandardPacket;
                     59: struct InfoData;
                     60: struct WBStartup;
                     61: 
                     62: #define _SIZE_T /* to avoid interference with <syst/types.h> */
                     63: #include <pExec/Types.h>
                     64: #include <pDOS/Lock.h>
                     65: #include <pDOS/ArgTags.h>
                     66: #include <pDOS/DosSig.h>
                     67: #include <pDOS/DosErrors.h>
                     68: #include <psl/FileReq.h>
                     69: #include <psl/pSLTags.h>
                     70: #include <pGadget/Gadget.h>
                     71: #include <pGfx/StdGMap.h>
                     72: #include <pGfx/StdCMap.h>
                     73: #include <pGfx/GfxTags.h>
                     74: #include <pGfx/RastPort.h>
                     75: #include <pScreen/ScrTags.h>
                     76: #include <pScreen/Window.h>
                     77: #include <pScreen/Screen.h>
                     78: #include <pScreen/DrawInfo.h>
                     79: #include <pIntui/IntuMsg.h>
                     80: #include <pIntui/ICI.h>
                     81: #include <pIntui/Tags.h>
                     82: #include <pIntui/GClass.h>
                     83: #include <pIntui/DragTags.h>
                     84: #include <pDtType/DClass.h>
                     85: #include <pDtType/DtBase.h>
                     86: #include <pDtType/DtTags.h>
                     87: #include <pDtType/DosObj.h>
                     88: 
                     89: /*#include <pInline/pLibExt.h> */
                     90: #include <pInline/pExec2.h>
                     91: #include <pInline/pDos2.h>
                     92: #include <pInline/pIntui2.h>
                     93: #include <pInline/pGfx2.h>
                     94: #include <pInline/pPSL2.h>
                     95: #include <pInline/pDtType2.h>
                     96: 
                     97: /****************************************************************************/
                     98: 
                     99: xcolnr xcolors[4096];
                    100: 
                    101:  /* Keyboard and mouse */
                    102: 
                    103: static int keystate[256];
                    104: 
                    105: int buttonstate[3];
                    106: int lastmx, lastmy;
                    107: int newmousecounters;
                    108: 
                    109: static int inwindow;
                    110: 
                    111: struct vidbuf_description gfxvidinfo;
                    112: static char *oldpixbuf;
                    113: 
1.1.1.4   root      114: /****************************************************************************/
1.1       root      115: /*
                    116:  * prototypes & global vars
                    117:  */
                    118: extern int  rexx_init(void);
                    119: extern void rexx_exit(void);
                    120: extern void initpseudodevices(void);
                    121: extern void closepseudodevices(void);
                    122: extern char *to_unix_path(char *s);
                    123: extern char *from_unix_path(char *s);
                    124: extern void split_dir_file(char *src, char **dir, char **file);
                    125: 
                    126: void main_window_led(int led, int on);
                    127: ULONG pOS_GetObjectData(APTR obj,ULONG tag);
                    128: 
                    129: extern struct pOS_ExecBase        *gb_ExecBase;
                    130: extern struct pOS_ExecLibFunction *gb_ExecLib;
                    131: extern struct pOS_DosBase         *gb_DosBase;
                    132: extern struct pOS_LocaleBase      *gb_LocaleBase;
                    133: 
                    134: struct pOS_IntuiDevice            *gb_IntuiBase;
                    135: struct pOS_GfxBase                *gb_GfxBase;
                    136: struct pOS_pSLBase                *gb_PSLBase;
                    137: struct pOS_DataTypeBase           *gb_DtTypeBase;
                    138: 
                    139: /****************************************************************************/
                    140: 
                    141: static void disk_hotkeys(void);
                    142: static void set_title(void);
                    143: static void HandleDrop(struct pOS_IEDragDrop *DD);
                    144: 
                    145: static struct pOS_Window           *W;
                    146: static struct pOS_RastPort         *RP;
                    147: static struct pOS_StdRGB8GfxMap    *GM24;
                    148: static struct pOS_StdChunky8GfxMap *GM8;
                    149: static struct pOS_StdRLColorMap    *CM;
                    150: static struct pOS_Gadget           *DDGad; /* Drag&Drop gadget */
                    151: 
                    152: static int                          XOffset,YOffset;
                    153: static int                          use_gray;
                    154: 
                    155: /****************************************************************************/
                    156: 
                    157: static RETSIGTYPE sigbrkhandler(int foo)
                    158: {
                    159:     activate_debugger();
                    160: }
                    161: 
                    162: void setup_brkhandler(void)
                    163: {
                    164:     signal(SIGINT,sigbrkhandler);
                    165: }
                    166: 
                    167: /****************************************************************************/
                    168: 
                    169: __inline__ void flush_line(int y)
                    170: {
                    171:     int len, l;
                    172:     unsigned char *buf, *dst, *src;
                    173:     int xs;
                    174: 
                    175:     if(y<0 || y>=gfxvidinfo.height) return;
                    176:     xs = 0;
                    177:     len = gfxvidinfo.width;
1.1.1.4   root      178:     buf = gfxvidinfo.linemem; if(!buf)
1.1       root      179:     buf = gfxvidinfo.bufmem + y*gfxvidinfo.rowbytes;
                    180: 
                    181:     if(currprefs.use_low_bandwidth) {
1.1.1.4   root      182:        switch(gfxvidinfo.pixbytes) {
                    183:        case 2: {
                    184:            short *newp = (short *)buf;
                    185:            short *oldp = (short *)(oldpixbuf + y*gfxvidinfo.rowbytes);
                    186:            while (*newp++ == *oldp++) if(!--len) return;
                    187:            src   = (char *)--newp;
                    188:            dst   = (char *)--oldp;
                    189:            newp += len;
                    190:            oldp += len;
                    191:            while (*--newp == *--oldp);
                    192:            len   = 1 + (oldp - (short *)dst);
                    193:            xs    = (src - buf)/2;
                    194:            pOS_CopyMem (src, dst, len * 2);
                    195:        } break;
                    196:        case 1: {
                    197:            char *newp = (char *)buf;
                    198:            char *oldp = (char *)(oldpixbuf + y*gfxvidinfo.rowbytes);
                    199:            while (*newp++ == *oldp++) if(!--len) return;
                    200:            src   = (char *)--newp;
                    201:            dst   = (char *)--oldp;
                    202:            newp += len;
                    203:            oldp += len;
                    204:            while (*--newp == *--oldp);
                    205:            len   = 1 + (oldp - (char *)dst);
                    206:            xs    = (src - buf);
                    207:            pOS_CopyMem (src, dst, len);
                    208:        } break;
                    209:        default: abort();
                    210:        }
1.1       root      211:     }
                    212:     switch(gfxvidinfo.pixbytes) {
                    213:       case 1:
1.1.1.4   root      214:        buf += xs;
                    215:        l = len; src = buf; dst = GM8->ckgm_Chunky+xs;
                    216:        while(l--) {*dst++ = *src++;}
                    217:        pOS_WriteStdGfxMapRastPort(&GM8->ckgm_Gfx,xs,0,
                    218:                                   RP,XOffset+xs,YOffset+y,len,1,0);
                    219:        break;
1.1       root      220:       case 2:
1.1.1.4   root      221:        /* if only pOS could provide a ARGB8 struct that fits on a ULONG */
                    222:        buf += 2*xs;
                    223:        l = len; src = buf;   dst = GM24->rgbgm_R+xs;
                    224:        while(l--) {*dst++ = (ULONG)*src * 0x11 ; src+=2;}
                    225:        l = len; src = buf+1; dst = GM24->rgbgm_G+xs;
                    226:        while(l--) {*dst++ = (ULONG)(*src>>4) * 0x11; src+=2;}
                    227:        l = len; src = buf+1; dst = GM24->rgbgm_B+xs;
                    228:        while(l--) {*dst++ = (ULONG)(*src&15) * 0x11; src+=2;}
                    229:        pOS_WriteStdGfxMapRastPort(&GM24->rgbgm_Gfx,xs,0,
                    230:                                   RP,XOffset+xs,YOffset+y,len,1,0);
                    231:        break;
1.1       root      232:     }
                    233: }
                    234: 
                    235: /****************************************************************************/
                    236: 
                    237: void flush_block (int ystart, int ystop)
                    238: {
                    239:     int y;
                    240:     for(y=ystart; y<=ystop; ++y) flush_line(y);
                    241: }
                    242: 
                    243: /****************************************************************************/
                    244: 
                    245: void flush_screen (int ystart, int ystop)
                    246: {
                    247: }
                    248: 
                    249: /****************************************************************************/
                    250: 
                    251: static int get_color(int r, int g, int b, xcolnr *cnp)
                    252: {
                    253:    static int col;
                    254: 
                    255:    r *= 0x11; g *= 0x11; b *= 0x11;
                    256:    if(use_gray) r = g = b = (77*r + 151*g + 29*b) / 256;
                    257: 
                    258:    CM->rlcm_Colors[col].rc_U.rc_E.rcue_R = r;
                    259:    CM->rlcm_Colors[col].rc_U.rc_E.rcue_G = g;
                    260:    CM->rlcm_Colors[col].rc_U.rc_E.rcue_B = b;
                    261: 
                    262:    *cnp = col++;
                    263: 
                    264:    return 1;
                    265: }
                    266: 
                    267: /****************************************************************************/
                    268: 
                    269: static int init_colors(void)
                    270: {
                    271:     int i;
                    272: 
                    273:     switch(currprefs.color_mode) {
                    274:       case 0: case 2:
1.1.1.4   root      275:        write_log("Using 256 gray scales.\n");
                    276:        use_gray = 1;
                    277:        /* fall through */
1.1       root      278:       case 1:
1.1.1.4   root      279:        if(!use_gray) write_log("Using 256 colors.\n");
                    280:        alloc_colors256(get_color);
                    281:        break;
1.1       root      282:       case 3:
1.1.1.4   root      283:        printf("Using truecolor.\n");
                    284:        for(i=0;i<4096;++i) xcolors[i] = i;
                    285:        break;
1.1       root      286:     }
                    287:     switch (gfxvidinfo.pixbytes) {
                    288:       case 2:
1.1.1.4   root      289:        for (i = 0; i < 4096; i++)
                    290:            xcolors[i] = xcolors[i] * 0x00010001;
                    291:        gfxvidinfo.can_double = 1;
                    292:        break;
1.1       root      293:       case 1:
1.1.1.4   root      294:        for (i = 0; i < 4096; i++)
                    295:            xcolors[i] = xcolors[i] * 0x01010101;
                    296:        gfxvidinfo.can_double = 1;
                    297:        break;
1.1       root      298:       default:
1.1.1.4   root      299:        gfxvidinfo.can_double = 0;
                    300:        break;
1.1       root      301:     }
                    302:     return 1;
                    303: }
                    304: 
                    305: /****************************************************************************/
                    306: 
                    307: #define IND "==="
                    308: 
                    309: static int setup_publicscreen(void)
                    310: {
                    311:     static char ScreenTitle[100];
                    312:     static struct pOS_IBox ZoomArray = {0,0,0,0};
                    313:     struct pOS_Screen *S;
                    314: 
                    315:     sprintf(ScreenTitle,
1.1.1.4   root      316:            "UAE-%d.%d.%d � by Bernd Schmidt & contributors, "
                    317:            "p.OS Port by Samuel Devulder.",
                    318:            (version / 100) % 10, (version / 10) % 10, version % 10);
1.1       root      319: 
                    320:     S = pOS_LockPubScreen(NULL);
                    321:     if(!S) {
1.1.1.4   root      322:        write_log("No public screen !\n");
                    323:        return 0;
1.1       root      324:     }
                    325: 
                    326:     if(currprefs.gfx_height + S->scr_BarHeight + 1 >= (int)S->scr_Height) {
1.1.1.4   root      327:        currprefs.gfx_height >>= 1;
                    328:        currprefs.gfx_correct_aspect = 1;
1.1       root      329:     }
1.1.1.4   root      330: 
                    331:     DDGad = (void *)pOS_NewIObject(
                    332:              NULL, S->scr_DrawInfo->dri_Names[SCRNAM_GClass], 0,
                    333:              ICLTAG_GadBorderType,         GADBORTYP_BlkBox,
                    334:              ICLTAG_Left,                  1,
                    335:              ICLTAG_Top,                   1,
                    336:              ICLTAG_RelWidth,             -1,
                    337:              ICLTAG_RelHeight,            -1,
                    338:              ICLTAG_StandardDrop,          TRUE,
                    339:              ICLTAG_AddDropAttName,        (ULONG)"#?dosobj/#?",
1.1       root      340: //            ICLTAG_StandardDrag,          TRUE,
1.1.1.4   root      341:              ICLTAG_HighlightDropBox,      TRUE,
                    342:              ICLTAG_NoSelect,              TRUE,
                    343:            TAG_DONE);
1.1       root      344: 
                    345:     ZoomArray.Top    = 0;
                    346:     ZoomArray.Left   = S->scr_Width - 128;
                    347:     ZoomArray.Width  = 128;
                    348:     ZoomArray.Height = S->scr_BarHeight+1;
                    349: 
                    350:     W=pOS_OpenWindow(
1.1.1.4   root      351:        SCRTAG_Title,          (ULONG)"UAE - Power: "IND" Disks: "
                    352:                                      IND" "IND" "IND" "IND,
                    353:        SCRTAG_ScreenTitle,    (ULONG)ScreenTitle,
                    354:        SCRTAG_Screen,         (ULONG)S,
                    355:        SCRTAG_InnerWidth,     currprefs.gfx_width,
                    356:        SCRTAG_InnerHeight,    currprefs.gfx_height,
                    357:        SCRTAG_AutoAdjust,     TRUE,
                    358:        SCRTAG_UnderMouse,     TRUE,
                    359:        SCRTAG_ZipGadget,      TRUE,
                    360:        SCRTAG_ZipIBox,        (ULONG)&ZoomArray,
                    361:        SCRTAG_Flags,          WINFLGF_DepthGadget|
                    362:                               WINFLGF_SimpleRefresh|
                    363:                               WINFLGF_CloseGadget|
                    364:                               WINFLGF_Dragbar|
                    365:                               WINFLGF_ReportMouse|
                    366:                               WINFLGF_RMBTrap|
1.1       root      367: //                             WINFLGF_Activate|
1.1.1.4   root      368:                               0,
                    369:        SCRTAG_IDCMP,          IDCMP_MouseButtons|
                    370:                               IDCMP_MouseMove|
                    371:                               IDCMP_RawKey|
                    372:                               IDCMP_ActiveWindow|
                    373:                               IDCMP_InactiveWindow|
                    374:                               IDCMP_CloseWindow|
                    375:                               IDCMP_RefreshWindow|
                    376:                               IDCMP_NewSize|
                    377:                               IDCMP_DragDrop|
                    378:                               0,
                    379:        SCRTAG_Gadget,         (ULONG)DDGad,
                    380:        TAG_DONE);
1.1       root      381:     pOS_UnlockPubScreen(S);
                    382:     if(!W) {
1.1.1.4   root      383:        fprintf(stderr,"Can't open window !\n");
                    384:        return 0;
1.1       root      385:     }
                    386: 
                    387:     /* now we know the window box and can setup the drag&drop gad. */
                    388:     {
1.1.1.4   root      389:        struct pOS_IBox Box;
1.1       root      390: 
1.1.1.4   root      391:        pOS_GetWindowIBox(W, &Box, NULL);
                    392:        --Box.Left;
                    393:        --Box.Top;
                    394: 
                    395:        DDGad->gad_LeftEdge = Box.Left;
                    396:        DDGad->gad_TopEdge  = Box.Top;
                    397:        DDGad->gad_Width    = -(W->win_BorRight + W->win_BorLeft) + 2;
                    398:        DDGad->gad_Height   = -(W->win_BorBottom + W->win_BorTop) + 2;
                    399:        /*
                    400:        pOS_DrawBorderBox(W->win_RastPort, S->scr_DrawInfo,
                    401:                          (W->win_Flags&WINFLGF_Activate)?
                    402:                          GADBORTYP_BevelDownBox:GADBORTYP_HfBevelDownBox,
                    403:                          &Box);
                    404:        */
1.1       root      405:     }
                    406: 
                    407:     /* Give priority 0 when active, -1 when inactive */
                    408:     pOS_SetWindowTask(W, pOS_FindTask(NULL), 0, -1);
                    409: 
                    410:     gfxvidinfo.width  = (W->win_Width  - W->win_BorRight - W->win_BorLeft);
                    411:     gfxvidinfo.height = (W->win_Height - W->win_BorTop - W->win_BorBottom);
                    412:     XOffset = W->win_BorLeft;
                    413:     YOffset = W->win_BorTop;
                    414: 
                    415:     RP = W->win_RastPort;
                    416: 
                    417:     return 1;
                    418: }
                    419: 
                    420: /****************************************************************************/
                    421: 
                    422: #ifndef HAVE_SIGACTION /* test for -nixpos */
                    423: double frexp(double value, int *exp)
                    424: {
                    425:     *exp = 0;
                    426:     if(value>1)       while(value>1)  {value /= 2;++*exp;}
                    427:     else if(value>0)  while(value<1)  {value *= 2;--*exp;}
                    428:     else if(value<-1) while(value<-1) {value /= 2;++*exp;}
                    429:     else if(value<0)  while(value>-1) {value *= 2;--*exp;}
                    430:     return value;
                    431: }
                    432: 
                    433: double ldexp(double value, int exp)
                    434: {
                    435:     if(exp<0) while(exp++) value /= 2;
                    436:     else      while(exp--) value *= 2;
                    437:     return value;
                    438: }
                    439: #endif
                    440: 
                    441: /****************************************************************************/
                    442: 
                    443: int graphics_setup(void)
                    444: {
                    445: #ifdef HAVE_SIGACTION /* test for -nixpos */
                    446:     if(ix_os != OS_IS_POS) {
1.1.1.4   root      447:        ix_req(NULL, "Abort", NULL, "That version of %s is only for p.OS!", __progname);
                    448:        exit(20);
                    449:     }
1.1       root      450: #endif
                    451:     gb_IntuiBase = (void*)pOS_OpenLibrary("pintui.library",0);
                    452:     if(!gb_IntuiBase) {
1.1.1.4   root      453:        fprintf(stderr,"No pintui.library ?\n");
                    454:        return 0;
1.1       root      455:     }
                    456:     gb_GfxBase   = (void*)pOS_OpenLibrary("pgraphics.library",0);
                    457:     if(!gb_GfxBase) {
1.1.1.4   root      458:        fprintf(stderr,"No pgraphics.library ?\n");
                    459:        return 0;
1.1       root      460:     }
                    461:     gb_DtTypeBase =(void*)pOS_OpenLibrary("pDtType.library",0);
                    462:     if(!gb_DtTypeBase) {
1.1.1.4   root      463:        fprintf(stderr,"No pDtType.library ?\n");
                    464:        return 0;
1.1       root      465:     }
1.1.1.4   root      466:     initpseudodevices();
1.1       root      467:     atexit(graphics_leave);
                    468:     return 1;
                    469: }
                    470: 
                    471: /****************************************************************************/
                    472: 
                    473: int graphics_init(void)
                    474: {
                    475:     int i;
                    476: 
                    477:     if (currprefs.color_mode > 3) {
1.1.1.4   root      478:        fprintf(stderr, "Bad color mode selected. Using default.\n");
                    479:        currprefs.color_mode = 3;
1.1       root      480:     }
                    481:     if (currprefs.gfx_width < 320)
1.1.1.4   root      482:        currprefs.gfx_width = 320;
1.1       root      483:     if (currprefs.gfx_height < 100)
1.1.1.4   root      484:        currprefs.gfx_height = 100;
1.1       root      485:     currprefs.gfx_width += 7;
                    486:     currprefs.gfx_width &= ~7;
1.1.1.4   root      487: 
1.1       root      488:     gfxvidinfo.width  = currprefs.gfx_width;
                    489:     gfxvidinfo.height = currprefs.gfx_height;
                    490: 
                    491:     if(!setup_publicscreen()) return 0;
1.1.1.4   root      492: 
1.1       root      493:     switch(currprefs.color_mode) {
                    494:     case 0: case 1: case 2:
1.1.1.4   root      495:        gfxvidinfo.pixbytes = 1;
                    496:        CM=(void*)pOS_AllocColorMap(NULL,
                    497:                                    GFXTAG_ColorType,   COLMAPTYP_StdRLut,
                    498:                                    GFXTAG_Colors,      256,
                    499:                                    currprefs.color_mode==2?TAG_IGNORE:
                    500:                                    GFXTAG_ColorFlags,  COLMAPF_Q1,
                    501:                                    TAG_END);
                    502:        if(CM)
                    503:        GM8=(void*)pOS_AllocGfxMap(NULL,
                    504:                                   GFXTAG_Width,       currprefs.gfx_width,
                    505:                                   GFXTAG_Height,      1,
                    506:                                   GFXTAG_GfxType,     GFXMAPTYP_StdChunky8,
                    507:                                   GFXTAG_CrtGfxMapEx, TRUE,
                    508:                                   GFXTAG_ColorMap,    (ULONG)CM,
                    509:                                   TAG_END);
                    510:        if(GM8) break;
                    511:        write_log("trying 24bit GfxMap...\n");
                    512:        /* fall through */
1.1       root      513:       case 3:  /* 24 bits */
1.1.1.4   root      514:        gfxvidinfo.pixbytes = 2;
                    515:        GM24=(void*)pOS_AllocGfxMap(NULL,
                    516:                                    GFXTAG_Width,    currprefs.gfx_width,
                    517:                                    GFXTAG_Height,   1,
                    518:                                    GFXTAG_GfxType,  GFXMAPTYP_StdRGB8,
                    519:                                    TAG_END);
                    520:        break;
1.1       root      521:     }
1.1.1.4   root      522: 
1.1       root      523:     if(!GM8 && !GM24) {
1.1.1.4   root      524:        fprintf(stderr,"Unable to get GfxMap.\n");
                    525:        return 0;
1.1       root      526:     }
                    527: 
1.1.1.2   root      528:     gfxvidinfo.emergmem = 0;
                    529:     gfxvidinfo.linemem = 0;
1.1       root      530:     gfxvidinfo.rowbytes = gfxvidinfo.pixbytes * currprefs.gfx_width;
1.1.1.4   root      531:     gfxvidinfo.bufmem = (char *)calloc(gfxvidinfo.rowbytes,
                    532:                                       currprefs.gfx_height);
1.1       root      533:     if(!gfxvidinfo.bufmem) {
1.1.1.4   root      534:        fprintf(stderr,"Not enough memory for video bufmem.\n");
                    535:        return 0;
                    536:     }
1.1       root      537:     gfxvidinfo.maxblocklines = 0;
                    538: 
                    539:     if (currprefs.use_low_bandwidth) {
1.1.1.4   root      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;
1.1       root      546:     }
                    547: 
                    548:     set_title();
                    549: 
                    550:     if (!init_colors()) {
1.1.1.4   root      551:        write_log("Failed to init colors.\n");
                    552:        return 0;
1.1       root      553:     }
                    554: 
                    555:     buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
                    556:     for(i=0; i<256; i++)
1.1.1.4   root      557:        keystate[i] = 0;
                    558: 
                    559:     lastmx = lastmy = 0;
1.1       root      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) {
1.1.1.4   root      577:        pOS_FreeGfxMap(&GM8->ckgm_Gfx);
                    578:        GM8 = NULL;
                    579:     }
1.1       root      580:     if(GM24) {
1.1.1.4   root      581:        pOS_FreeGfxMap(&GM24->rgbgm_Gfx);
                    582:        GM24 = NULL;
                    583:     }
1.1       root      584:     if(CM) {
1.1.1.4   root      585:        pOS_FreeColorMap(&CM->rlcm_CM);
                    586:        CM = NULL;
1.1       root      587:     }
                    588:     if(W) {
1.1.1.4   root      589:        pOS_CloseWindow(W);
                    590:        W = NULL;
1.1       root      591:     }
                    592:     if(DDGad) {
1.1.1.4   root      593:        pOS_DisposeIObject(DDGad);
                    594:        DDGad = NULL;
1.1       root      595:     }
                    596:     if(gb_DtTypeBase) {
1.1.1.4   root      597:        pOS_CloseLibrary((void*)gb_DtTypeBase);
                    598:        gb_DtTypeBase = NULL;
1.1       root      599:     }
                    600:     if(gb_PSLBase) {
1.1.1.4   root      601:        pOS_CloseLibrary((void*)gb_PSLBase);
                    602:        gb_PSLBase = NULL;
1.1       root      603:     }
                    604:     if(gb_IntuiBase) {
1.1.1.4   root      605:        pOS_CloseLibrary((void*)gb_IntuiBase);
                    606:        gb_IntuiBase = NULL;
1.1       root      607:     }
                    608:     if(gb_GfxBase) {
1.1.1.4   root      609:        pOS_CloseLibrary((void*)gb_GfxBase);
                    610:        gb_GfxBase = NULL;
1.1       root      611:     }
                    612: }
                    613: 
                    614: 
                    615: /***************************************************************************/
                    616: 
                    617: void handle_events(void)
                    618: {
                    619:     struct pOS_IntuiMessage *msg;
                    620:     int mx,my,class,code;
1.1.1.4   root      621: 
1.1       root      622:     newmousecounters = 0;
                    623: 
1.1.1.4   root      624:     if(pOS_SetSignal(0L, DOSSIGF_CTRL_C|DOSSIGF_CTRL_D) &
                    625:                        (DOSSIGF_CTRL_C|DOSSIGF_CTRL_D)) {
                    626:        activate_debugger();
1.1       root      627:     }
                    628: 
                    629:     while((msg=(void*)pOS_GetMsg(W->win_UserPort))) {
1.1.1.4   root      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);
1.1       root      724:     }
                    725:     /* "Affengriff" */
1.1.1.4   root      726:     if(keystate[AK_CTRL] && keystate[AK_LAMI] && keystate[AK_RAMI])
                    727:        m68k_reset();
1.1       root      728: 
                    729:     /* PC-like :-) CTRL-ALT-DEL => reboot */
1.1.1.4   root      730:     if(keystate[AK_CTRL] && (keystate[AK_LALT] || keystate[AK_RALT]) &&
                    731:        keystate[AK_DEL])
                    732:        m68k_reset();
1.1       root      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]) {
1.1.1.4   root      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:        }
1.1       root      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)?
1.1.1.4   root      777:                                      SCRPEN_ActiveWinTitle:
                    778:                                      SCRPEN_InactiveWinTitle],
                    779:                         di->dri_Pens[(W->win_Flags&WINFLGF_Activate)?
                    780:                                      SCRPEN_ActiveWindow:
                    781:                                      SCRPEN_InactiveWindow],
                    782:                         DRMD_Jam2);
1.1       root      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)?
1.1.1.4   root      808:                                 SCRPEN_ActiveWindow:SCRPEN_InactiveWindow]);
1.1       root      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)?
1.1.1.4   root      812:                              GADBORTYP_BevelDownBox:GADBORTYP_HfBevelDownBox,
                    813:                      &rect);
1.1       root      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
1.1.1.4   root      826:                            + RP->rp_TxBaseline);
1.1       root      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]) {
1.1.1.4   root      874:        int ok = 0;
1.1       root      875: 
1.1.1.4   root      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;
1.1       root      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;
1.1.1.4   root      899:     unrecord(AK_CTRL);unrecord(AK_LALT);
1.1       root      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) {
1.1.1.4   root      912:        write_log("Can't open psl.library!\n");
                    913:        return;
1.1       root      914:     }
                    915: 
                    916:     FileRequest = pOS_AllocFileRequest(TAG_DONE);
                    917:     if(!FileRequest) {
1.1.1.4   root      918:        write_log("Unable to allocate file requester.\n");
                    919:        return;
1.1       root      920:     }
                    921: 
                    922:     sprintf(buff,"Select file to use for drive DF%d:",drive);
                    923:     if(pOS_PslFileRequest(FileRequest,
1.1.1.4   root      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:        }
1.1       root      941:     } else {
1.1.1.4   root      942:        free(last_file);
                    943:        last_file = NULL;
1.1       root      944:     }
                    945:     pOS_FreePslRequest(FileRequest);
                    946:     free(last_dir);
                    947: 
                    948:     if(last_file) {
1.1.1.4   root      949:        disk_insert(drive,last_file);
                    950:        free(last_file);
1.1       root      951:     }
                    952: }
                    953: 
                    954: /****************************************************************************/
                    955: 
                    956: ULONG pOS_GetObjectData(APTR obj,ULONG tag)
                    957: {
                    958:   struct pOS_IntuiMethod Mth;
                    959:   ULONG Dt;
                    960: 
                    961:   Mth.imth_Method=ICLMTH_Get;
                    962:   Mth.imth_U.imth_Get.imgt_ID=tag;
                    963:   Mth.imth_U.imth_Get.imgt_Variable=&Dt;
                    964:   pOS_DoIMethodA(obj,(struct pOS_Method*)&Mth);
                    965:   return(Dt);
                    966: }
                    967: 
                    968: /****************************************************************************/
                    969: 
                    970: #define SIZE 1024
                    971: 
                    972: static void HandleDrop(struct pOS_IEDragDrop *dd)
                    973: {
                    974:     char *Type = (char*)pOS_GetObjectData(dd->iedd_Object, DCLTAG_Type);
                    975:     if(!stricmp(Type, pOS_DTFORM_DOSOBJ)) {
1.1.1.4   root      976:        char *Buffer = (CHAR*)pOS_AllocMem(2*SIZE, MEMF_ANY);
                    977:        if( Buffer ) {
                    978:            struct pOS_DtTypeDosObj DosObj = {NULL, 0, NULL};
                    979:            struct pOS_DClassInfo  DCI     = {
                    980:                pOS_DTFORM_DOSOBJ, NULL, DCLINFOF_None, NULL
                    981:            };
                    982: 
                    983:            pOS_DCLASSINFO(&DCI);
                    984:            DCI.dci_Data = &DosObj;
                    985: 
                    986:            DosObj.dtdos_Buffer   = Buffer+SIZE;
                    987:            DosObj.dtdos_BufSize  = SIZE;
                    988:            strcpy(DosObj.dtdos_Buffer, "run ");
                    989:            DosObj.dtdos_Buffer  += strlen(DosObj.dtdos_Buffer);
                    990:            DosObj.dtdos_BufSize -= strlen(DosObj.dtdos_Buffer);
                    991: 
                    992:            if(pOS_LoadDTObjectA(dd->iedd_Object, &DCI, NULL)) {
                    993:                if(DCI.dci_Result > 0) {
                    994:                    if(DosObj.dtdos_Lock) {
                    995:                        strcpy(Buffer, "cd ");
                    996: 
                    997:                        pOS_NameFromObjectLock(DosObj.dtdos_Lock,
                    998:                                               Buffer+3, SIZE-3-1);
                    999:                        uaeexe(Buffer);
                   1000:                        uaeexe(DosObj.dtdos_Buffer);
                   1001:                    } else {
                   1002:                        uaeexe(DosObj.dtdos_Buffer);
                   1003:                    }
                   1004:                }
                   1005:            }
                   1006:        }
                   1007:        pOS_FreeMem(Buffer, 2*SIZE);
1.1       root     1008:     }
                   1009: }
                   1010: 
                   1011: /***************************************************************************/
                   1012: 
                   1013: /* sam: need to put all this in a separate module */
                   1014: 
                   1015: #ifdef PICASSO96
                   1016: 
                   1017: void DX_Invalidate (int first, int last)
                   1018: {
                   1019: }
                   1020: 
                   1021: int DX_BitsPerCannon (void)
                   1022: {
                   1023:     return 8;
                   1024: }
                   1025: 
                   1026: void DX_SetPalette(int start, int count)
                   1027: {
                   1028: }
                   1029: 
                   1030: int DX_FillResolutions (uae_u16 *ppixel_format)
                   1031: {
                   1032:     return 0;
                   1033: }
                   1034: 
                   1035: void gfx_set_picasso_modeinfo (int w, int h, int depth)
                   1036: {
                   1037: }
                   1038: 
                   1039: void gfx_set_picasso_baseaddr (uaecptr a)
                   1040: {
                   1041: }
                   1042: 
                   1043: void gfx_set_picasso_state (int on)
                   1044: {
                   1045: }
                   1046: 
                   1047: void begindrawing (void)
                   1048: {
                   1049: }
                   1050: 
                   1051: void enddrawing (void)
                   1052: {
                   1053: }
                   1054: 
                   1055: uae_u8 *lockscr (void)
                   1056: {
                   1057: return NULL;
                   1058: }
                   1059: 
                   1060: void unlockscr (void)
                   1061: {
                   1062: }
                   1063: #endif
                   1064: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.