Annotation of uae/src/od-macos/mac.c, revision 1.1.1.4

1.1.1.3   root        1:  /*
1.1       root        2:   * UAE - The Un*x Amiga Emulator
1.1.1.3   root        3:   *
1.1       root        4:   * Mac port specific stuff
1.1.1.3   root        5:   *
1.1       root        6:   * (c) 1996 Ernesto Corvi
                      7:   */
                      8: 
                      9: #include <stdio.h>
                     10: #include <stdlib.h>
                     11: #include <string.h>
                     12: #include <QDOffscreen.h>
                     13: #include <Palettes.h>
                     14: #include <Profiler.h>
                     15: #include <Sound.h>
                     16: #include <errno.h>
                     17: 
                     18: #include "mackbd.h"
1.1.1.2   root       19: #include "threaddep/thread.h"
1.1       root       20: #include "uae.h"
                     21: #include "amiga.h"
                     22: #include "options.h"
                     23: #include "memory.h"
                     24: #include "custom.h"
                     25: #include "newcpu.h"
                     26: #include "xwin.h"
                     27: #include "keyboard.h"
                     28: #include "keybuf.h"
                     29: 
                     30: #define kAppleMenuID   128
                     31: #define kFileMenuID            129
                     32: #define        kEditMenuID             130
                     33: #define        kDrivesMenuID   131
                     34: #define        kMemoryMenuID   132
                     35: #define        kResMenuID              135
                     36: #define        kRateMenuID             134
                     37: #define        kVideoMenuID    133
                     38: 
                     39: #define kAboutDialogID 128
                     40: #define kHardfileDialogID      129
                     41: #define kQuitError 130
                     42: 
                     43: #define mTopLeft(r)            (((Point *)&(r))[0])
                     44: #define mBotRight(r)   (((Point *)&(r))[1])
                     45: 
                     46: #define qd_CenterScreen 144
                     47: 
                     48: static GDHandle curDevice;
                     49: static int oldDepth=0;
                     50: static Boolean macCursorState=true;
                     51: int    use_quickdraw=true;
                     52: short  filesys_vRefNum=0;
                     53: static KeyMap keys;
                     54: static Boolean redraw=true,diskInit=true;
                     55: static int mBarState=1;
                     56: static int RM=0;
                     57: static int my_use_gfxlib=0;
                     58: static int my_automount_uaedev=1;
                     59: static int my_screen_res=3;
                     60: static int my_use_quickdraw=1;
                     61: static WindowPtr mywin;
                     62: static RgnHandle gOldVisRgn;
                     63: static short gOldMBarHeight;
                     64: static Boolean macDiskStatus[4];
                     65: static GWorldPtr gOffscreenBuffer;
                     66: static PixMapHandle gOffscreenPixels;
1.1.1.3   root       67: static Rect gOffscreenRect,gDrawRect;
1.1       root       68: static unsigned char *gOffscreenBaseAddr;
                     69: static unsigned long gOffscreenRowBytes;
                     70: static PaletteHandle mypal;
                     71: static int CenterScreen=0;
                     72: static CTabHandle      myCTAB;
                     73: static long screenH=0,screenV=0;
                     74: static GrafPtr dummyPort;
                     75: extern SndChannelPtr newChannel;
                     76: static unsigned long refresh;
                     77: extern char *xlinebuffer;
                     78: 
                     79:  /* Keyboard and mouse */
                     80: 
                     81: static int keystate[256];
                     82: 
                     83: static int colors_allocated;
                     84: 
                     85: // Prototypes
                     86: static void HandleMenu (long mSelect);
                     87: static void macHandleCursors(void);
                     88: static Boolean CheckForSetup (void);
                     89: static void ParamAString( ConstStr255Param theStr);
                     90: static void printStatusLine (void);
                     91: static void Share_main(void);
                     92: static void Share_ResolvePath (FSSpec *fSpec, char *path);
                     93: // end Prototypes
                     94: 
                     95: static void my_setpalette(int count, int r, int g, int b)
                     96: {      RGBColor mycolor;
1.1.1.3   root       97: 
1.1       root       98:        mycolor.red=r*1024;
                     99:        mycolor.green=g*1024;
                    100:        mycolor.blue=b*1024;
1.1.1.3   root      101: 
1.1       root      102:        if (count == 0 || count == 255) SetEntryColor(mypal, count, &mycolor);
                    103:        else SetEntryColor(mypal, (~count & 0x000000ff), &mycolor);
                    104: }
                    105: 
                    106: static int get_color(int r, int g, int b, xcolnr *cnp)
                    107: {
                    108:     if (colors_allocated == 256) return -1;
                    109:     *cnp = colors_allocated;
                    110:        my_setpalette(colors_allocated, doMask(r, 6, 0), doMask(g, 6, 0), doMask(b, 6, 0));
                    111:     colors_allocated++;
                    112:     return 1;
                    113: }
                    114: 
                    115: static void init_colors(void)
                    116: {
                    117:     int rw = 5, gw = 5, bw = 5;
                    118:     colors_allocated = 0;
1.1.1.3   root      119: 
1.1       root      120:     if (gfxvidinfo.pixbytes == 1)
                    121:        alloc_colors256(get_color);
                    122:        else
                    123:        {       if (gfxvidinfo.pixbytes == 4) rw=gw=bw=8;
                    124:                alloc_colors64k(rw, gw, bw, gw+bw, bw, 0);
                    125:        }
                    126: }
                    127: 
                    128: static void HideMenuBar(GrafPtr grafPort)
                    129: {      Rect    menuRect={0,0,20,640};
                    130:        RgnHandle newVisRgn;
                    131:        GrafPtr savePort;
1.1.1.3   root      132: 
1.1       root      133:        GetPort(&savePort);
                    134:        SetPort(grafPort);
                    135: 
                    136:                // save off vis region
                    137:        gOldVisRgn = NewRgn();
                    138:        CopyRgn(grafPort->visRgn, gOldVisRgn);
                    139: 
                    140:                // expand the vis region to the port rect
                    141:        newVisRgn = NewRgn();
                    142:        RectRgn(newVisRgn, &grafPort->portRect);
                    143:        CopyRgn(newVisRgn, grafPort->visRgn);
                    144:        DisposeRgn(newVisRgn);
                    145: 
                    146:        PaintRect(&menuRect);
                    147: 
                    148:        gOldMBarHeight = GetMBarHeight();
                    149:        LMSetMBarHeight(0);
1.1.1.3   root      150: 
1.1       root      151:        SetPort(savePort);
                    152: }
                    153: 
                    154: static void ShowMenuBar(GrafPtr grafPort)
                    155: {
                    156:        GrafPtr savePort;
                    157:        RgnHandle junkRgn;
                    158: 
                    159:        GetPort(&savePort);
                    160:        SetPort(grafPort);
                    161: 
                    162:                // fill the rounded corners of the screen with black again
                    163:        junkRgn = NewRgn();
                    164:        CopyRgn(gOldVisRgn, junkRgn);
                    165:        DiffRgn(grafPort->visRgn, junkRgn, junkRgn);
                    166: 
                    167:        #ifdef dangerousPattern
                    168:        FillRgn(junkRgn, qd.black);
                    169:        #else
                    170:        FillRgn(junkRgn, &qd.black);
                    171:        #endif
                    172: 
                    173:        DisposeRgn(junkRgn);
                    174: 
                    175:                // restore the old vis region
                    176:        CopyRgn(gOldVisRgn, grafPort->visRgn);
                    177:        DisposeRgn(gOldVisRgn);
                    178:        gOldVisRgn = NULL;
1.1.1.3   root      179: 
1.1       root      180:        LMSetMBarHeight(gOldMBarHeight);
1.1.1.3   root      181: 
1.1       root      182:        DrawMenuBar();
                    183: }
                    184: 
                    185: int graphics_init()
                    186: {
                    187:     int i;
                    188:     char p1;
                    189:     long tmp;
                    190:     long memtop=0;
                    191:        Rect    windowRectangle,osRect={0,0,600,800};
                    192:        char *dst;
                    193:        CGrafPtr oldPort;
                    194:     GDHandle oldDevice;
1.1.1.3   root      195: 
1.1       root      196:        my_use_gfxlib=use_gfxlib;
                    197:        my_automount_uaedev=automount_uaedev;
                    198:        my_screen_res=screen_res;
                    199:        my_use_quickdraw=use_quickdraw;
1.1.1.3   root      200: 
1.1       root      201:        if (CheckForSetup()) ExitToShell();
1.1.1.3   root      202: 
1.1       root      203:        gfxvidinfo.maxblocklines=600; // Whatever...
1.1.1.3   root      204: 
1.1       root      205:        if (gfxvidinfo.pixbytes == 1)
                    206:        {       myCTAB=GetCTable(128);
                    207:                mypal=NewPalette(256, myCTAB, pmTolerant + pmExplicit, 0x0000);
                    208:        }
1.1.1.3   root      209: 
1.1       root      210:        windowRectangle.left=0;
                    211:        if (screen_res > 4 || screen_res < 0) screen_res=3;
                    212:        if (screen_res == 4 || screen_res == 2) dont_want_aspect = 0;
                    213:        else dont_want_aspect = 1;
                    214:        switch (screen_res)
                    215:        {       case 0:
                    216:                case 1:
                    217:                case 2:
                    218:                        CenterScreen=(36*gfxvidinfo.pixbytes)/2;
                    219:                        windowRectangle.right=320;
                    220:                        use_lores = 1;
                    221:                        windowRectangle.top=40;
                    222:                        if (screen_res == 0) windowRectangle.bottom=200+windowRectangle.top+38;
                    223:                        else if (screen_res == 1) windowRectangle.bottom=256+windowRectangle.top+38;
                    224:                                 else windowRectangle.bottom=400+windowRectangle.top+38;
                    225:                break;
1.1.1.3   root      226: 
1.1       root      227:                case 3:
                    228:                case 4:
                    229:                        CenterScreen=36*gfxvidinfo.pixbytes;
                    230:                        use_lores = 0;
                    231:                        windowRectangle.right=640;
                    232:                        if (dont_want_aspect == 0)
                    233:                        {       windowRectangle.top=0;
                    234:                                windowRectangle.bottom=480;
                    235:                        }
                    236:                        else
                    237:                        {       windowRectangle.top=40;
                    238:                                windowRectangle.bottom=256+windowRectangle.top+38;
                    239:                        }
                    240:                break;
                    241:        }
1.1.1.3   root      242: 
1.1       root      243:        screenV=windowRectangle.bottom-windowRectangle.top;
                    244:        if (dont_want_aspect == 1 || screen_res == 2) screenV -= 12;
                    245:        screenH=windowRectangle.right-windowRectangle.left;
1.1.1.3   root      246: 
1.1       root      247:        mywin = NewCWindow(nil, &windowRectangle, "\pThe Un*x Amiga Emulator", 1, 4, (WindowPtr)-1L, 0, 0);
                    248:     SetPort(mywin);
1.1.1.3   root      249: 
1.1       root      250:     gui_prepare_leds(screenV);
1.1.1.3   root      251: 
1.1       root      252:     init_colors();
1.1.1.3   root      253: 
1.1       root      254:     if (use_quickdraw)
                    255:     {  GetGWorld(&oldPort, &oldDevice);
1.1.1.3   root      256:        NewGWorld( &gOffscreenBuffer, (gfxvidinfo.pixbytes*8), &osRect, 0L, oldDevice, 0);
1.1       root      257:                SetGWorld(oldPort, oldDevice);
                    258:                gOffscreenPixels = GetGWorldPixMap( gOffscreenBuffer );
                    259:                LockPixels(gOffscreenPixels);
                    260:                gDrawRect.top=(mywin->portRect).top;
                    261:                gDrawRect.left=(mywin->portRect).left;
                    262:                gDrawRect.right=(mywin->portRect).right;
                    263:                gDrawRect.bottom=(mywin->portRect).bottom;
                    264:                gDrawRect.bottom -= 12;
                    265:                gOffscreenRect.top=(mywin->portRect).top;
                    266:                gOffscreenRect.left=(mywin->portRect).left;
                    267:                gOffscreenRect.right=(mywin->portRect).right;
                    268:                gOffscreenRect.bottom=(mywin->portRect).bottom;
                    269:                gOffscreenRect.bottom -= 12;
                    270:                OffsetRect(&gOffscreenRect,(use_lores == 1) ? qd_CenterScreen/2 : qd_CenterScreen,0);
                    271:                gOffscreenBaseAddr = (unsigned char *)GetPixBaseAddr(gOffscreenPixels);
                    272:                gOffscreenRowBytes = (*gOffscreenPixels)->rowBytes & 0x3fff;
                    273:                gfxvidinfo.bufmem=(char *)gOffscreenBaseAddr;
                    274:                gfxvidinfo.rowbytes=gOffscreenRowBytes;
                    275:                SetGWorld(gOffscreenBuffer, NULL);
                    276:                PaintRect(&gOffscreenRect);
                    277:                SetGWorld(oldPort, oldDevice);
                    278:        }
                    279:        else
                    280:        {       gfxvidinfo.bufmem=NewPtrClear(600*(800*gfxvidinfo.pixbytes));
                    281:                if (gfxvidinfo.bufmem == 0) SysBeep(0);
                    282:            gfxvidinfo.rowbytes=800*gfxvidinfo.pixbytes;
                    283:        }
1.1.1.3   root      284: 
1.1       root      285:     if (dont_want_aspect || screen_res == 2) printStatusLine();
1.1.1.3   root      286: 
1.1       root      287:     if (gfxvidinfo.pixbytes == 1)
                    288:     {  SetPalette((WindowPtr) -1L, mypal, false);
                    289:     }
1.1.1.3   root      290: 
1.1       root      291:     buttonstate[0] = buttonstate[1] = buttonstate[2] = 0;
                    292:     for(i=0; i<256; i++) keystate[i] = 0;
1.1.1.3   root      293: 
1.1       root      294:     lastmx = lastmy = 0; newmousecounters=0;
1.1.1.3   root      295: 
1.1       root      296:     refresh=TickCount();
1.1.1.3   root      297: 
1.1       root      298: //    tmp=ProfilerInit(collectDetailed,bestTimeBase,200,10);
                    299:     return 1;
                    300: }
                    301: 
                    302: void graphics_leave()
                    303: {
                    304: //     ProfilerDump((unsigned char *)"\pmyProf");
                    305: //     ProfilerTerm();
1.1.1.3   root      306: 
1.1       root      307:     ShowCursor();
                    308:        if (dont_want_aspect == 0) if (!mBarState) ShowMenuBar(mywin);
                    309:     if (oldDepth != 0) SetDepth(curDevice,oldDepth,0,0);
                    310:     FlushEvents (everyEvent,0);
                    311:     SndDisposeChannel(newChannel,true);
                    312:     if (gfxvidinfo.pixbytes == 1)
                    313:     {  DisposePalette(mypal);
1.1.1.3   root      314:        DisposeCTable(myCTAB);
1.1       root      315:     }
                    316:     DisposeWindow(mywin);
                    317:     if (use_quickdraw)
                    318:     {  DisposeGWorld(gOffscreenBuffer);
                    319:     }
                    320:     else DisposePtr((Ptr)(gfxvidinfo.bufmem));
                    321: }
                    322: 
                    323: static int next_line_double;
                    324: static int next_line_pos = 0;
                    325: 
                    326: void flush_screen ()
                    327: {      short   y,x,y1=0;
                    328:     unsigned char *winbaseaddr;
                    329:     long *src,*dest;
                    330:     unsigned long winrowbytes;
                    331:     PixMapHandle       ph;
                    332:     CGrafPtr   oldPort;
                    333:        GDHandle oldDevice;
                    334: 
                    335:        if (TickCount() < refresh + 4) return;
                    336:        if (!redraw) return;
                    337:        if (FrontWindow() != mywin) return;
                    338:        if (inhibit_frame) return;
1.1.1.3   root      339: 
                    340:        GetGWorld(&oldPort,&oldDevice);
1.1       root      341:        SetGWorld((CWindowPtr) mywin, oldDevice);
                    342:     if (use_quickdraw)
                    343:     {  ForeColor(blackColor);  /* Prevents colorizing mode */
                    344:            BackColor(whiteColor);      /* Prevents colorizing mode */
1.1.1.3   root      345:        (*((*gOffscreenPixels)->pmTable))->ctSeed = (*((*((*(GetGDevice()))->gdPMap))->pmTable))->ctSeed;
                    346:        CopyBits((BitMap *)(*gOffscreenPixels), &(mywin->portBits), &gOffscreenRect, &gDrawRect, srcCopy, (RgnHandle) 0L);
1.1       root      347:     }
                    348:     else
                    349:     {  ph=GetGWorldPixMap((CGrafPort *) mywin);
                    350:            winbaseaddr=( unsigned char *) GetPixBaseAddr(ph);
                    351:            winrowbytes=(*ph)->rowBytes & 0x3FFF;
                    352:            winbaseaddr-=((**ph).bounds.left);
                    353:                winbaseaddr-=(((**ph).bounds.top)*winrowbytes);
                    354:            dest=(long *)winbaseaddr;
                    355:            src=(long *)(gfxvidinfo.bufmem)+CenterScreen;
1.1.1.3   root      356: 
1.1       root      357:                y=0;
                    358:            if ((dont_want_aspect == 0 && mBarState == true && y < 20)) y=20;
                    359:            dest=(long *)(winbaseaddr+(y*winrowbytes));
                    360:                src=(long *)(gfxvidinfo.bufmem+(y*gfxvidinfo.rowbytes))+CenterScreen;
                    361:                for (; y< screenV; y++)
                    362:                {       for (x=0;x < ((screenH*gfxvidinfo.pixbytes)/sizeof(long));x++) *dest++ = *src++;
                    363:                dest=(long *)(winbaseaddr+(y*winrowbytes));
                    364:                src=(long *)(gfxvidinfo.bufmem+(y*gfxvidinfo.rowbytes))+CenterScreen;
                    365:            }
                    366:        }
                    367:        SetGWorld(oldPort, oldDevice);
                    368: }
                    369: 
                    370: void flush_block (int start_y, int end_y)
                    371: {      short   y,x,y1=0;
                    372:     unsigned char *winbaseaddr;
                    373:     long *src,*dest;
                    374:     unsigned long winrowbytes;
                    375:     PixMapHandle       ph;
                    376:     Rect                       srcRect,dstRect;
                    377:     CGrafPtr   oldPort;
                    378:        GDHandle oldDevice;
                    379: 
                    380:        if (TickCount() < refresh + 4) return;
                    381:        if (!redraw) return;
                    382:        if (FrontWindow() != mywin) return;
                    383:        if (inhibit_frame) return;
1.1.1.3   root      384: 
                    385:        if (end_y > screenV) end_y=screenV;
                    386:        GetGWorld(&oldPort,&oldDevice);
1.1       root      387:        SetGWorld((CWindowPtr) mywin, oldDevice);
                    388:     if (use_quickdraw)
1.1.1.3   root      389:     {
                    390:        srcRect.top=start_y;
                    391:        srcRect.bottom=end_y;
                    392:        srcRect.left=gOffscreenRect.left;
                    393:        srcRect.right=gOffscreenRect.right;
                    394:        dstRect.top=start_y;
                    395:        dstRect.bottom=end_y;
                    396:        dstRect.left=gDrawRect.left;
                    397:        dstRect.right=gDrawRect.right;
                    398: 
                    399:        /* Taken from my favorite book:
                    400:           "It is significant, if not surprising, that the Mac and PC cannot come
                    401:           to an agreement over the most fundamental issue in the universe: the
                    402:           distinction between black and white. On the PC, the pixel value 0
                    403:           indicates a pixel of zero intensity, or black. On the Mac, 0 indicates
                    404:           a page wich has not been written on, wich leaves it white."
                    405: 
                    406:                                                                                        Eric Johnston.
                    407:                                                                Tricks of the Mac Game Programming Gurus.
                    408: 
                    409:        Check set_palette and line_to_scr8() on how i fixed that.
                    410:        If you know a better way let me know.
                    411:        */
                    412: 
                    413:        ForeColor(blackColor);  /* Prevents colorizing mode */
1.1       root      414:            BackColor(whiteColor);      /* Prevents colorizing mode */
1.1.1.3   root      415:        (*((*gOffscreenPixels)->pmTable))->ctSeed = (*((*((*(GetGDevice()))->gdPMap))->pmTable))->ctSeed;
                    416:        CopyBits((BitMap *)(*gOffscreenPixels), &(mywin->portBits), &srcRect, &dstRect, srcCopy, (RgnHandle) 0L);
1.1       root      417:     }
                    418:     else
                    419:     {  ph=GetGWorldPixMap((CGrafPort *) mywin);
                    420:            winbaseaddr=( unsigned char *) GetPixBaseAddr(ph);
                    421:            winrowbytes=(*ph)->rowBytes & 0x3FFF;
                    422:            winbaseaddr-=((**ph).bounds.left);
                    423:                winbaseaddr-=(((**ph).bounds.top)*winrowbytes);
                    424:            dest=(long *)winbaseaddr;
                    425:            src=(long *)(gfxvidinfo.bufmem)+CenterScreen;
1.1.1.3   root      426: 
1.1       root      427:                y=start_y;
                    428:            if ((dont_want_aspect == 0 && mBarState == true && y < 20)) y=20;
                    429:            dest=(long *)(winbaseaddr+(y*winrowbytes));
                    430:                src=(long *)(gfxvidinfo.bufmem+(y*gfxvidinfo.rowbytes))+CenterScreen;
                    431:                for (; y <= end_y; y++)
                    432:                {       for (x=0;x < ((screenH*gfxvidinfo.pixbytes)/sizeof(long));x++) *dest++ = *src++;
                    433:                dest=(long *)(winbaseaddr+(y*winrowbytes));
                    434:                src=(long *)(gfxvidinfo.bufmem+(y*gfxvidinfo.rowbytes))+CenterScreen;
                    435:            }
                    436:        }
                    437:        SetGWorld(oldPort, oldDevice);
                    438: }
                    439: 
                    440: void flush_line(int line_num)
                    441: {
                    442:     long i;
                    443:     char *dst,*src;
                    444:     CGrafPtr oldPort;
                    445:     GDHandle oldDevice;
1.1.1.3   root      446: 
1.1       root      447:        if (use_quickdraw)
                    448:        {       GetGWorld(&oldPort, &oldDevice);
                    449:            SetGWorld(gOffscreenBuffer, NULL);
1.1.1.3   root      450:        dst=(char *)gOffscreenBaseAddr;
1.1       root      451:                dst+=(char *)((line_num)*gOffscreenRowBytes);
                    452:                src=(char *)xlinebuffer;
                    453:                BlockMove(src,dst,gOffscreenRowBytes);
                    454:                if (next_line_double)
                    455:                {       dst=(char *)gOffscreenBaseAddr;
                    456:                        dst+=(char *)((line_num+1)*gOffscreenRowBytes);
                    457:                        src=(char *)xlinebuffer;
                    458:                        BlockMove(src,dst,gOffscreenRowBytes);
                    459:                }
                    460:                SetGWorld(oldPort, oldDevice);
                    461:        }
                    462:        else
                    463:        {       if (line_num < 481)
                    464:                {       dst=(char *)gfxvidinfo.bufmem+((line_num)*gfxvidinfo.rowbytes);
                    465:                        src=(char *)xlinebuffer;
                    466:                        BlockMove(src,dst,gfxvidinfo.rowbytes);
                    467:                }
1.1.1.3   root      468:        if (next_line_double)
                    469:        {
                    470:                if (line_num < 481)
1.1       root      471:                        {   dst=(char *)gfxvidinfo.bufmem+((line_num+1)*gfxvidinfo.rowbytes);
                    472:                                src=(char *)xlinebuffer;
                    473:                        BlockMove(src,dst,gfxvidinfo.rowbytes);
                    474:                        }
1.1.1.3   root      475:        }
1.1       root      476:     }
                    477: }
                    478: 
1.1.1.3   root      479: /* Decode KeySyms. This function knows about all keys that are common
1.1       root      480:  * between different keyboard languages.
                    481:  */
                    482: static int kc_decode (long ks)
1.1.1.3   root      483: {
1.1       root      484:     switch (ks)
                    485:     {
                    486:      case kAKeyMap: return AK_A;
                    487:      case kBKeyMap: return AK_B;
                    488:      case kCKeyMap: return AK_C;
                    489:      case kDKeyMap: return AK_D;
                    490:      case kEKeyMap: return AK_E;
                    491:      case kFKeyMap: return AK_F;
                    492:      case kGKeyMap: return AK_G;
                    493:      case kHKeyMap: return AK_H;
                    494:      case kIKeyMap: return AK_I;
                    495:      case kJKeyMap: return AK_J;
                    496:      case kKKeyMap: return AK_K;
                    497:      case kLKeyMap: return AK_L;
                    498:      case kMKeyMap: return AK_M;
                    499:      case kNKeyMap: return AK_N;
                    500:      case kOKeyMap: return AK_O;
                    501:      case kPKeyMap: return AK_P;
                    502:      case kQKeyMap: return AK_Q;
                    503:      case kRKeyMap: return AK_R;
                    504:      case kSKeyMap: return AK_S;
                    505:      case kTKeyMap: return AK_T;
                    506:      case kUKeyMap: return AK_U;
                    507:      case kVKeyMap: return AK_V;
                    508:      case kWKeyMap: return AK_W;
                    509:      case kXKeyMap: return AK_X;
1.1.1.3   root      510: 
1.1       root      511:      case k0KeyMap: return AK_0;
                    512:      case k1KeyMap: return AK_1;
                    513:      case k2KeyMap: return AK_2;
                    514:      case k3KeyMap: return AK_3;
                    515:      case k4KeyMap: return AK_4;
                    516:      case k5KeyMap: return AK_5;
                    517:      case k6KeyMap: return AK_6;
                    518:      case k7KeyMap: return AK_7;
                    519:      case k8KeyMap: return AK_8;
                    520:      case k9KeyMap: return AK_9;
1.1.1.3   root      521: 
1.1       root      522:      case kKP0KeyMap: return AK_NP0;
                    523:      case kKP1KeyMap: return AK_NP1;
                    524:      case kKP2KeyMap: return AK_NP2;
                    525:      case kKP3KeyMap: return AK_NP3;
                    526:      case kKP4KeyMap: return AK_NP4;
                    527:      case kKP5KeyMap: return AK_NP5;
                    528:      case kKP6KeyMap: return AK_NP6;
                    529:      case kKP7KeyMap: return AK_NP7;
                    530:      case kKP8KeyMap: return AK_NP8;
                    531:      case kKP9KeyMap: return AK_NP9;
1.1.1.3   root      532: 
1.1       root      533:      case kF1KeyMap: return AK_F1;
                    534:      case kF2KeyMap: return AK_F2;
                    535:      case kF3KeyMap: return AK_F3;
                    536:      case kF4KeyMap: return AK_F4;
                    537:      case kF5KeyMap: return AK_F5;
                    538:      case kF6KeyMap: return AK_F6;
                    539:      case kF7KeyMap: return AK_F7;
                    540:      case kF8KeyMap: return AK_F8;
                    541:      case kF9KeyMap: return AK_F9;
                    542:      case kF10KeyMap: return AK_F10;
1.1.1.3   root      543: 
1.1       root      544:      case kBackSpaceKeyMap: return AK_BS;
                    545:      case kTabKeyMap: return AK_TAB;
                    546:      case kReturnKeyMap: return AK_RET;
                    547:      case kEscapeKeyMap: return AK_ESC;
1.1.1.3   root      548: 
1.1       root      549:      case kSpaceBarMap:  return AK_SPC;
1.1.1.3   root      550: 
1.1       root      551:      case kUpArrowKeyMap: return AK_UP;
                    552:      case kDownArrowKeyMap: return AK_DN;
                    553:      case kLeftArrowKeyMap: return AK_LF;
                    554:      case kRightArrowKeyMap: return AK_RT;
1.1.1.3   root      555: 
1.1       root      556:      case kF11KeyMap: return AK_inhibit;
                    557: 
                    558:      case kF12KeyMap: return AK_mousestuff;
                    559: 
                    560:      case kPgUpKeyMap: return AK_RAMI;
                    561:      case kPgDnKeyMap: return AK_LAMI;
                    562:      case kBackSlash: return AK_BACKSLASH;
                    563:     }
                    564:     return -1;
                    565: }
                    566: 
                    567: static int decode_us(long ks)
                    568: {
                    569:     switch(ks) {
                    570:        /* US specific */
                    571: 
                    572:      case kYKeyMap: return AK_Y;
                    573:      case kZKeyMap: return AK_Z;
                    574:      case kLBracketKeyMap: return AK_LBRACKET;
                    575:      case kRBracketKeyMap: return AK_RBRACKET;
                    576:      case kCommaKeyMap: return AK_COMMA;
                    577:      case kPeriodKeyMap: return AK_PERIOD;
                    578:      case kSlashKeyMap: return AK_SLASH;
                    579:      case kSemiColonKeyMap: return AK_SEMICOLON;
                    580:      case kMinusKeyMap: return AK_MINUS;
                    581:      case kEqualKeyMap: return AK_EQUAL;
                    582:      case kQuoteKeyMap: return AK_QUOTE;
                    583:     }
                    584: 
                    585:     return -1;
                    586: }
                    587: 
                    588: static int decode_de(long ks)
                    589: {
                    590:     switch(ks) {
                    591: /* DE specific
                    592:      case XK_Y: case XK_y: return AK_Z;
                    593:      case XK_Z: case XK_z: return AK_Y;
                    594:      case XK_Odiaeresis: case XK_odiaeresis: return AK_SEMICOLON;
                    595:      case XK_Adiaeresis: case XK_adiaeresis: return AK_QUOTE;
                    596:      case XK_Udiaeresis: case XK_udiaeresis: return AK_LBRACKET;
                    597:      case XK_plus: case XK_asterisk: return AK_RBRACKET;
                    598:      case XK_comma: return AK_COMMA;
                    599:      case XK_period: return AK_PERIOD;
                    600:      case XK_less: case XK_greater: return AK_LTGT;
                    601:      case XK_numbersign: return AK_NUMBERSIGN;
                    602:      case XK_ssharp: return AK_MINUS;
                    603:      case XK_apostrophe: return AK_EQUAL;
                    604:      case XK_asciicircum: return AK_00;
1.1.1.3   root      605:      case XK_minus: return AK_SLASH;
1.1       root      606: */
                    607:     }
                    608: 
                    609:     return -1;
                    610: }
                    611: 
                    612: static int keycode2amiga(long code)
                    613: {
                    614:     long ks;
                    615:     int as;
1.1.1.3   root      616: 
1.1       root      617:     ks = (code & keyCodeMask) >> 8;
                    618:     as = kc_decode (ks);
1.1.1.3   root      619: 
                    620:     if (as == -1) {
1.1       root      621:        switch(keyboard_lang) {
                    622:         case KBD_LANG_US:
                    623:            as = decode_us(ks);
                    624:            break;
1.1.1.3   root      625: 
1.1       root      626:         case KBD_LANG_DE:
                    627:            as = decode_de(ks);
                    628:            break;
1.1.1.3   root      629: 
1.1       root      630:         default:
                    631:            as = -1;
                    632:            break;
                    633:        }
                    634:     }
                    635:     if(-1 != as)
                    636:        return as;
                    637:     return -1;
                    638: }
                    639: 
                    640: void handle_events()
                    641: {      WindowPeek      wp;
                    642:        short           windowPart;
                    643:        Boolean repeat;
                    644:     Boolean itHappened;
                    645:     Point   mpos;
                    646:     EventRecord event;
                    647:     int kc,i,count;
                    648:     char       osKind;
                    649:     GrafPtr    oldSave;
1.1.1.3   root      650: 
1.1       root      651:        GetPort(&oldSave);
                    652:        if ((redraw) && mywin != FrontWindow()) SelectWindow(mywin);
1.1.1.3   root      653: 
1.1       root      654:     SetEventMask(-1);
1.1.1.3   root      655: 
1.1       root      656:     if (diskInit)
                    657:     {  macDiskStatus[0]=!disk_empty(0);
                    658:                SetMenuItemText(GetMenuHandle(kDrivesMenuID), 1, macDiskStatus[0] ? "\pEject Disk in DF0:" : "\pInsert Disk in DF0:");
1.1.1.3   root      659:        macDiskStatus[1]=!disk_empty(1);
1.1       root      660:                SetMenuItemText(GetMenuHandle(kDrivesMenuID), 2, macDiskStatus[1] ? "\pEject Disk in DF1:" : "\pInsert Disk in DF1:");
1.1.1.3   root      661:        macDiskStatus[2]=!disk_empty(2);
1.1       root      662:                SetMenuItemText(GetMenuHandle(kDrivesMenuID), 3, macDiskStatus[2] ? "\pEject Disk in DF2:" : "\pInsert Disk in DF2:");
1.1.1.3   root      663:        macDiskStatus[3]=!disk_empty(3);
1.1       root      664:                SetMenuItemText(GetMenuHandle(kDrivesMenuID), 4, macDiskStatus[3] ? "\pEject Disk in DF3:" : "\pInsert Disk in DF3:");
1.1.1.3   root      665:        diskInit=false;
1.1       root      666:     }
1.1.1.3   root      667: 
1.1       root      668:        if (redraw)
                    669:        {       gui_update_leds();
                    670:                macHandleCursors();
                    671:        }
1.1.1.3   root      672: 
1.1       root      673:     GetKeys(keys);
                    674:     if (BitTst(&keys, kCommandRawKey))
                    675:        buttonstate[2] = 1;
                    676:     else
                    677:        buttonstate[2] = 0;
1.1.1.3   root      678: 
1.1       root      679:     if (BitTst(&keys, kShiftRawKey))
1.1.1.3   root      680:     {
1.1       root      681:        if (!keystate[AK_LSH]) {
                    682:            keystate[AK_LSH] = 1;
                    683:            record_key (AK_LSH << 1);
                    684:            goto label1;
                    685:        }
                    686:     } else {
                    687:        if (keystate[AK_LSH]) {
                    688:            keystate[AK_LSH] = 0;
                    689:            record_key ((AK_LSH << 1) | 1);
                    690:            goto label1;
                    691:        }
                    692:     }
                    693:     if (BitTst(&keys, kControlRawKey))
1.1.1.3   root      694:     {
1.1       root      695:        if (!keystate[AK_CTRL]) {
                    696:            keystate[AK_CTRL] = 1;
                    697:            record_key (AK_CTRL << 1);
                    698:            goto label1;
                    699:        }
1.1.1.3   root      700:     } else {
1.1       root      701:        if (keystate[AK_CTRL]) {
                    702:            keystate[AK_CTRL] = 0;
                    703:            record_key ((AK_CTRL << 1) | 1);
                    704:            goto label1;
                    705:        }
                    706:     }
                    707:     if (BitTst(&keys, kCapsRawKey))
1.1.1.3   root      708:     {
1.1       root      709:        if (!keystate[AK_CAPSLOCK]) {
                    710:            keystate[AK_CAPSLOCK] = 1;
                    711:            record_key (AK_CAPSLOCK << 1);
                    712:            goto label1;
                    713:        }
                    714:     } else {
                    715:        if (keystate[AK_CAPSLOCK]) {
                    716:            keystate[AK_CAPSLOCK] = 0;
                    717:            record_key ((AK_CAPSLOCK << 1) | 1);
                    718:            goto label1;
                    719:        }
                    720:     }
                    721:     if (BitTst(&keys, kOptionRawKey))
1.1.1.3   root      722:     {
1.1       root      723:        if (!keystate[AK_LALT]) {
                    724:            keystate[AK_LALT] = 1;
                    725:            record_key (AK_LALT << 1);
                    726:            goto label1;
                    727:        }
                    728:     } else {
                    729:        if (keystate[AK_LALT]) {
                    730:            keystate[AK_LALT] = 0;
                    731:            record_key ((AK_LALT << 1) | 1);
                    732:            goto label1;
                    733:        }
                    734:     }
                    735:     do {
                    736:        repeat = 0;
                    737:        newmousecounters=0;
                    738:        itHappened=WaitNextEvent(-1,&event,0L,(*mywin).visRgn);
                    739: 
                    740:        switch(event.what) {
                    741:         case keyDown:
                    742:         case autoKey: {
1.1.1.3   root      743:                 if ((event.modifiers & cmdKey) != 0)
                    744:                 {      HandleMenu(MenuKey((char) (event.message & charCodeMask)));
                    745:                 }
                    746:                 else
                    747:                 {      int kc = keycode2amiga(event.message);
                    748:                    if (kc == -1) break;
1.1       root      749:                     switch (kc)
                    750:                     {  case AK_mousestuff:
1.1.1.3   root      751:                                   togglemouse();
                    752:                                         break;
                    753: 
1.1       root      754:                            case AK_inhibit:
1.1.1.3   root      755:                                         inhibit_frame ^= 1;
                    756:                                         break;
                    757: 
1.1       root      758:                            default:
1.1.1.3   root      759:                                 if (!keystate[kc])
                    760:                                 {      keystate[kc] = 1;
                    761:                                        record_key (kc << 1);
                    762:                                         }
                    763:                                         break;
1.1       root      764:                         }
                    765:                }
1.1.1.3   root      766:                break;
1.1       root      767:         }
                    768:         case keyUp: {
                    769:             kc = keycode2amiga(event.message);
                    770:             if (kc == -1) break;
                    771:             keystate[kc] = 0;
                    772:             record_key ((kc << 1) | 1);
                    773:             break;
                    774:         }
                    775:         case mouseDown:
1.1.1.3   root      776:                windowPart = FindWindow (event.where, (WindowPtr*) &wp);
                    777:                if (windowPart == inMenuBar) HandleMenu(MenuSelect(event.where));
                    778:                else
                    779:                if (windowPart == inSysWindow) SystemClick (&event, (WindowPtr) wp);
1.1       root      780:            else buttonstate[0] = 1;
                    781:            break;
1.1.1.3   root      782: 
1.1       root      783:         case osEvt:
1.1.1.3   root      784:                osKind=(event.message) >> 24;
                    785:                if (osKind == suspendResumeMessage)
                    786:                {       osKind=(event.message)&1;
                    787:                        if (osKind)
                    788:                        {       redraw=true; // Resume
                    789:                                flush_screen();
                    790:                                if (dont_want_aspect || screen_res == 2)
1.1       root      791:                            {   SelectWindow(mywin);
1.1.1.3   root      792:                                printStatusLine();
1.1       root      793:                            }
                    794:                        }
1.1.1.3   root      795:                        else redraw=false; // Suspend
                    796:                }
                    797:                break;
1.1       root      798:         case mouseUp:
                    799:            buttonstate[0] = 0;
                    800:            buttonstate[2] = 0;
                    801:            break;
                    802:        }
                    803:        if (redraw)
                    804:        {       GetMouse(&mpos);
                    805:                if (mpos.h != lastmx) { lastmx=mpos.h; /* repeat = 1;*/ }
                    806:                if (mpos.v != lastmy) { lastmy=mpos.v; /*repeat = 1;*/ }
                    807:        }
                    808:     } while (repeat);
1.1.1.3   root      809: 
1.1       root      810: label1:
                    811:     /* "Affengriff" */
                    812:     if(keystate[AK_CTRL] && keystate[AK_LAMI] && keystate[AK_RAMI])
1.1.1.3   root      813:        m68k_reset();
1.1       root      814:     SetPort(oldSave);
                    815: }
                    816: 
                    817: int debuggable()
                    818: {
                    819:     return 1;
                    820: }
                    821: 
                    822: int needmousehack()
                    823: {
                    824:     return 1;
                    825: }
                    826: 
                    827: void LED(int on)
                    828: {
                    829: }
                    830: 
                    831: void parse_cmdline ()
                    832: {
                    833:     /* No commandline on the Mac. */
                    834: }
                    835: 
                    836: static void PStrCat ( StringPtr p1, StringPtr p2)
                    837: {
                    838:        register int len;
                    839:        register int total;
                    840:        StringPtr       p3;
1.1.1.3   root      841: 
1.1       root      842:        len = *p1++;
                    843:        total = len +*p2;
1.1.1.3   root      844: 
1.1       root      845:        p3=p2;
                    846:        p2=p2+ (*p2 + 1);
1.1.1.3   root      847: 
1.1       root      848:        while (--len>=0) *p2++=*p1++;
                    849:        *p3=total;
                    850: }
                    851: 
                    852: static void PStrCopy ( StringPtr p1, StringPtr p2)
                    853: {
                    854:        register int len;
1.1.1.3   root      855: 
1.1       root      856:        len = *p2++ = *p1++;
                    857:        while (--len>=0) *p2++=*p1++;
                    858: }
                    859: 
                    860: short vRefNum=0;
                    861: long dirID=0;
                    862: 
                    863: static void HandleMenu (long mSelect)
                    864: {      short           menuID;
                    865:        short           menuItem;
                    866:        Str32           name;
                    867:        GrafPtr         savePort;
                    868:        WindowPtr       batchWin;
                    869:        Str255          batchStr,batchStr2;
                    870:        StandardFileReply               inputReply;
                    871:        char            strSize,i;
                    872:        long            count;
                    873:        FILE            *outFile;
                    874:        char            fileBuf[512];
                    875:        int                     backup=0;
                    876: 
                    877:        menuID = HiWord(mSelect);
                    878:        menuItem = LoWord(mSelect);
                    879: 
                    880:        if (menuID == 0) return;
                    881:        switch (menuID)
                    882:        {       case kAppleMenuID:
1.1.1.3   root      883:                        if (menuItem == 1)
                    884:                        {       if (!macCursorState) ShowCursor();
1.1       root      885:                                macCursorState=true;
1.1.1.3   root      886:                                Alert(kAboutDialogID,0); // About Box
                    887:                                if (dont_want_aspect || screen_res == 2) printStatusLine();
                    888:                        }
                    889:                        else
                    890:                        {       GetPort(&savePort);
                    891:                                GetItem(GetMenuHandle(kAppleMenuID), menuItem, name);
1.1       root      892:                                OpenDeskAcc(name);
                    893:                                SystemTask();
                    894:                                SetPort(savePort);
                    895:                        }
                    896:                        break;
1.1.1.3   root      897: 
                    898:                case kFileMenuID:
1.1       root      899:                        switch (menuItem)
                    900:                        {       case 1:
                    901:                                        m68k_reset();
                    902:                                break;
1.1.1.3   root      903: 
1.1       root      904:                                case 3:
                    905:                                        if (dont_want_aspect == 0)
                    906:                                        {       if (mBarState) HideMenuBar(mywin);
                    907:                                                else ShowMenuBar(mywin);
                    908:                                                mBarState=!mBarState;
                    909:                                        }
                    910:                                break;
1.1.1.3   root      911: 
1.1       root      912:                                case 5:
1.1.1.3   root      913:                                        activate_debugger();
1.1       root      914:                                break;
1.1.1.3   root      915: 
1.1       root      916:                                case 7:
                    917:                                        inhibit_frame ^= 1;
                    918:                                        if (inhibit_frame) SetMenuItemText(GetMenuHandle(kFileMenuID), 7, "\pTurn Screen Update On");
                    919:                                        else SetMenuItemText(GetMenuHandle(kFileMenuID), 7, "\pTurn Screen Update Off");
                    920:                                break;
1.1.1.3   root      921: 
1.1       root      922:                                case 9:
                    923:                                        produce_sound= !produce_sound;
                    924:                                        if (produce_sound) SetMenuItemText(GetMenuHandle(kFileMenuID), 9, "\pTurn Sound Off");
                    925:                                        else SetMenuItemText(GetMenuHandle(kFileMenuID), 9, "\pTurn Sound On");
                    926:                                        WritePrefs(0);
                    927:                                break;
1.1.1.3   root      928: 
1.1       root      929:                                case 11:
                    930:                                        fake_joystick= !fake_joystick;
                    931:                                        if (fake_joystick) SetMenuItemText(GetMenuHandle(kFileMenuID), 11, "\pTurn Joystick Off");
                    932:                                        else SetMenuItemText(GetMenuHandle(kFileMenuID), 11, "\pTurn Joystick On");
                    933:                                        WritePrefs(0);
                    934:                                break;
1.1.1.3   root      935: 
1.1       root      936:                                case 13:
                    937:                                        broken_in = 1;
                    938:                                        regs.spcflags |= SPCFLAG_BRK;
                    939:                                        quit_program=1;
                    940:                                break;
                    941:                        }
                    942:                        break;
1.1.1.3   root      943: 
1.1       root      944:                case kDrivesMenuID:
                    945:                        if (menuItem >= 1 && menuItem <= 4)
                    946:                        {       if (macDiskStatus[menuItem-1]) disk_eject(menuItem-1);
                    947:                                        else
                    948:                                        {       if (!macCursorState) ShowCursor();
                    949:                                                if (!mBarState) ShowMenuBar(mywin);
                    950:                                                macCursorState=true;
                    951:                                                StandardGetFile(nil,-1L,nil,&inputReply);
                    952:                                                if (inputReply.sfGood)
                    953:                                                {       vRefNum=inputReply.sfFile.vRefNum;
                    954:                                                        dirID=inputReply.sfFile.parID;
                    955:                                                        disk_insert (menuItem-1, p2cstr(inputReply.sfFile.name));
                    956:                                                }
                    957:                                                else macDiskStatus[menuItem-1] = !macDiskStatus[menuItem-1];
                    958:                                                if (!mBarState) HideMenuBar(mywin);
                    959:                                        }
                    960:                                        macDiskStatus[menuItem-1] = !macDiskStatus[menuItem-1];
                    961:                                        if (macDiskStatus[menuItem-1]) PStrCopy("\pEject Disk in DF",batchStr);
                    962:                                        else PStrCopy("\pInsert Disk in DF",batchStr);
                    963:                                        NumToString((long)(menuItem-1),batchStr2);
                    964:                                        PStrCat(batchStr2,batchStr);
                    965:                                        PStrCat("\p:",batchStr);
                    966:                                        SetMenuItemText(GetMenuHandle(kDrivesMenuID), menuItem, batchStr);
1.1.1.3   root      967: 
1.1       root      968:                        }
                    969:                        if (menuItem == 6)
                    970:                        {       if (!macCursorState) ShowCursor();
                    971:                                macCursorState=true;
                    972:                                for (count=0;count<512;count++) fileBuf[count]=0;
                    973:                                errno=0;
                    974:                                outFile=fopen("hardfile","wb");
                    975:                                if (outFile != 0)
                    976:                                {       for (count=0;count<16384;count++)
                    977:                                        {       fwrite(fileBuf, sizeof(char), 512, outFile);
                    978:                                                if (errno != 0)
                    979:                                                {       ParamAString("\pError generating the hardfile!.\n Make sure you have at least 8Mb of free storage on your Harddrive.");
                    980:                                                        DisplayError(kQuitError);
                    981:                                                }
                    982:                                        }
                    983:                                        fclose(outFile);
                    984:                                        Alert(kHardfileDialogID,0);
                    985:                                }
                    986:                                else
                    987:                                {       ParamAString("\pCan't create the hardfile!.\n Make sure your Harddrive isnt either software or hardware locked.");
                    988:                                        DisplayError(kQuitError);
                    989:                                }
                    990:                        }
                    991:                        if (menuItem == 7)
                    992:                        {       my_automount_uaedev=!my_automount_uaedev;
                    993:                                WritePrefs(0);
                    994:                                ParamAString("\pChanges will take effect the next time you run UAE.");
                    995:                                DisplayError(kQuitError);
                    996:                                CheckItem(GetMenuHandle(kDrivesMenuID),7,my_automount_uaedev ? false : true);
                    997:                        }
                    998:                        if (menuItem == 9)
                    999:                        {       if (!macCursorState) ShowCursor();
                   1000:                                macCursorState=true;
                   1001:                                Share_main();
                   1002:                        }
                   1003:                break;
1.1.1.3   root     1004: 
1.1       root     1005:                case kMemoryMenuID:
                   1006:                        if (menuItem == 1) use_slow_mem = !use_slow_mem;
                   1007:                        WritePrefs(0);
                   1008:                        ParamAString("\pChanges will take effect the next time you run UAE.");
                   1009:                        DisplayError(kQuitError);
                   1010:                        if (use_slow_mem) SetMenuItemText(GetMenuHandle(kMemoryMenuID), 1, "\pDisable 1 Mb (SlowMem)");
                   1011:                        else SetMenuItemText(GetMenuHandle(kMemoryMenuID), 1, "\pEnable 1 Mb (SlowMem)");
                   1012:                break;
1.1.1.3   root     1013: 
1.1       root     1014:                case kResMenuID:
                   1015:                        my_screen_res=(int)menuItem-1;
                   1016:                        WritePrefs(0);
                   1017:                        CheckItem(GetMenuHandle(kResMenuID),screen_res+1,false);
                   1018:                        CheckItem(GetMenuHandle(kResMenuID),my_screen_res+1,true);
                   1019:                        ParamAString("\pChanges will take effect the next time you run UAE.");
                   1020:                        DisplayError(kQuitError);
                   1021:                break;
1.1.1.3   root     1022: 
1.1       root     1023:                case kRateMenuID:
                   1024:                        for (count=1;count<5;count++) CheckItem(GetMenuHandle(kRateMenuID),count,false);
                   1025:                        if (menuItem == 1) framerate=1;
                   1026:                        if (menuItem == 2) framerate=3;
                   1027:                        if (menuItem == 3) framerate=5;
                   1028:                        if (menuItem == 4) framerate=7;
                   1029:                        CheckItem(GetMenuHandle(kRateMenuID),menuItem,true);
                   1030:                        WritePrefs(0);
                   1031:                break;
1.1.1.3   root     1032: 
1.1       root     1033:                case kVideoMenuID:
                   1034:                if (menuItem == 5)
                   1035:                {       my_use_quickdraw = !my_use_quickdraw;
                   1036:                        WritePrefs(0);
                   1037:                        CheckItem(GetMenuHandle(kVideoMenuID),5,my_use_quickdraw ? true : false);
                   1038:                        ParamAString("\pChanges will take effect the next time you run UAE.");
                   1039:                        DisplayError(kQuitError);
                   1040:                }
                   1041:                if (menuItem == 7)
                   1042:                {       my_use_gfxlib = !my_use_gfxlib;
                   1043:                        WritePrefs(0);
                   1044:                        CheckItem(GetMenuHandle(kVideoMenuID),7,my_use_gfxlib ? true : false);
                   1045:                        ParamAString("\pChanges will take effect the next time you run UAE.");
                   1046:                        DisplayError(kQuitError);
                   1047:                }
                   1048:                break;
1.1.1.3   root     1049: 
1.1       root     1050:                default:
                   1051:                        break;
                   1052:        }
                   1053:        HiliteMenu(0);
                   1054:        flush_screen();
                   1055:        if (dont_want_aspect  || screen_res == 2) printStatusLine();
                   1056: }
                   1057: 
                   1058: static void macHandleCursors(void)
                   1059: {      Point   mpos;
                   1060: 
                   1061:        if (redraw)
                   1062:        {       GetMouse(&mpos);
                   1063:                if (!dont_want_aspect && mBarState && screen_res == 4)
                   1064:                {       if (mpos.v < 20)
                   1065:                        {       ShowCursor();
                   1066:                                macCursorState=true;
                   1067:                        }
                   1068:                        else
                   1069:                        {       if (macCursorState)
                   1070:                                {       HideCursor();
                   1071:                                        macCursorState=false;
                   1072:                                }
                   1073:                        }
                   1074:                }
                   1075:                else
                   1076:                if (PtInRect(mpos,&(mywin->portRect)))
                   1077:                {       if (macCursorState)
                   1078:                        {       HideCursor();
                   1079:                                macCursorState=false;
                   1080:                        }
                   1081:                }
                   1082:                else
                   1083:                {       if (!macCursorState)
                   1084:                        {       ShowCursor();
                   1085:                                macCursorState=true;
                   1086:                        }
                   1087:                }
                   1088:        }
                   1089: }
                   1090: 
                   1091: // Check Minimal System Configuration and Setup
                   1092: static Boolean CheckForSetup (void)
                   1093: {      Boolean                 retvalue=false;
                   1094:        SysEnvRec               env;
1.1.1.3   root     1095: 
1.1       root     1096:        oldDepth=0;
                   1097:        SysEnvirons( 2, &env );
1.1.1.3   root     1098: 
1.1       root     1099:        if ( env.systemVersion < 0x0700 )
                   1100:        {       ParamAString("\pUAE requires System 7 or later!\n Press Ok to Quit...");
                   1101:                DisplayError(kQuitError);
                   1102:                retvalue=true;
                   1103:        }
                   1104:        if ( !env.hasColorQD)
                   1105:        {       ParamAString("\pUAE requires Color QuickDraw!\n Press Ok to Quit...");
                   1106:                DisplayError(kQuitError);
                   1107:                retvalue=true;
                   1108:        }
                   1109:        curDevice = GetMainDevice();
                   1110:        gfxvidinfo.pixbytes=((*(*curDevice)->gdPMap)->pixelSize)/8;
                   1111:        return(retvalue);
                   1112: }
                   1113: 
                   1114: // Shows up the standard error alert;
                   1115: static int DisplayError(int ID)
                   1116: {      int     ret=0;
                   1117: 
                   1118:        InitCursor();
                   1119:        ret=Alert(ID,0);
                   1120: 
                   1121:        return (ret);
                   1122: }
                   1123: 
                   1124: // Parses a Pascal string for error display
                   1125: static void ParamAString( ConstStr255Param theStr )
                   1126: {
                   1127:        ParamText(theStr, "\p", "\p", "\p");
                   1128: }
                   1129: 
                   1130: static void printStatusLine (void)
                   1131: {      GrafPtr savePort;
                   1132:        Rect    updateRect;
                   1133: 
                   1134:        updateRect.top=screenV;
                   1135:        updateRect.bottom=screenV+38;
                   1136:        updateRect.left=0;
                   1137:        updateRect.right=screenH;
                   1138:        GetPort(&savePort);
                   1139:        SetPort(mywin);
                   1140:        EraseRect(&updateRect);
                   1141:        MoveTo(10,screenV+10);
                   1142:        TextFont(monaco);
                   1143:        TextSize(9);
                   1144:        if (screen_res >= 3)
                   1145:        DrawString("\pPower LED:        Drive LEDs:  DF0:        DF1:        DF2:        DF3:");
                   1146:        else DrawString("\pPower:      DF0:      DF1:      DF2:      DF3:");
                   1147:        TextFont(0);
1.1.1.3   root     1148:        TextSize(0);
                   1149:        SetPort(savePort);
1.1       root     1150: }
                   1151: 
                   1152: typedef struct {
                   1153:        StandardFileReply *replyPtr;
                   1154:        FSSpec oldSelection;
                   1155: } SFData, *SFDataPtr;
                   1156: 
                   1157: /* constants */
                   1158: 
                   1159: #define        kSelectItem                     10
                   1160: #define        kSFDlg                          128
                   1161: #define        kCanSelectDesktop       true
                   1162: #define        kSelectStrRsrc          128
                   1163: #define kDefaultSelectString "\pSelect"
                   1164: #define        kDeskStrRsrc            129
                   1165: #define        kDefaultDeskString      "\pDesktop"
                   1166: #define        kSelectKey                      's'
                   1167: 
                   1168: /* globals */
                   1169: 
                   1170: Boolean gHasFindFolder;
                   1171: FSSpec gDeskFolderSpec;
                   1172: Str255 gSelectString;
                   1173: Str255 gDesktopFName;
                   1174: 
                   1175: FileFilterYDUPP Share_FilterAllFiles_UPP;
                   1176: DlgHookYDUPP Share_MyDlgHook_UPP;
                   1177: ModalFilterYDUPP Share_MyModalFilter_UPP;
                   1178: 
                   1179: /* prototypes */
                   1180: 
                   1181: static void Share_Init(void);
                   1182: static Boolean Share_CustomGet(FSSpec *fSpec);
                   1183: static pascal short Share_MyDlgHook(short item,DialogPtr theDlg,Ptr userData);
                   1184: static pascal Boolean Share_MyModalFilter(DialogPtr theDlg,EventRecord *ev,short *itemHit,Ptr myData);
                   1185: static void Share_HitButton(DialogPtr theDlg,short item);
                   1186: static pascal Boolean Share_FilterAllFiles(CInfoPBPtr pb, Ptr myDataPtr);
                   1187: static void Share_SetSelectButtonName(StringPtr selName,Boolean hilited,DialogPtr theDlg);
                   1188: static Boolean Share_SameFile(FSSpec *file1,FSSpec *file2);
                   1189: static Boolean Share_GetFSSpecPartialName(FSSpec *file,StringPtr fName);
                   1190: static OSErr Share_GetDeskFolderSpec(FSSpec *fSpec,short vRefNum);
                   1191: static OSErr Share_MakeCanonFSSpec(FSSpec *fSpec);
                   1192: static Boolean Share_ShouldHiliteSelect(FSSpec *fSpec);
                   1193: 
                   1194: 
                   1195: static void Share_main(void)
                   1196: {      FSSpec fSpec;
                   1197:        Boolean good;
                   1198:        GrafPtr oldPort;
                   1199:        char share_path[1024];
                   1200:        Handle  share_handle;
                   1201:        short backup;
1.1.1.3   root     1202: 
1.1       root     1203:        GetPort(&oldPort);
                   1204:        Share_Init();
1.1.1.3   root     1205: 
1.1       root     1206:        good = Share_CustomGet(&fSpec);
1.1.1.3   root     1207: 
1.1       root     1208:        if (good)
                   1209:        {       Share_ResolvePath(&fSpec,share_path);
                   1210:                backup=filesys_vRefNum;
                   1211:                filesys_vRefNum=fSpec.vRefNum;
                   1212:                WritePrefs(share_path);
                   1213:                filesys_vRefNum=backup;
                   1214:        }
                   1215:        SetPort(oldPort);
                   1216: }
                   1217: 
                   1218: static void Share_Init(void)
                   1219: {
                   1220:        Handle strHndl;
1.1.1.3   root     1221: 
1.1       root     1222:        gHasFindFolder = true;
1.1.1.3   root     1223: 
1.1       root     1224:        Share_FilterAllFiles_UPP=NewFileFilterYDProc(Share_FilterAllFiles);
                   1225:        Share_MyDlgHook_UPP=NewDlgHookYDProc(Share_MyDlgHook);
                   1226:        Share_MyModalFilter_UPP=NewModalFilterYDProc(Share_MyModalFilter);
1.1.1.3   root     1227: 
1.1       root     1228:        strHndl = Get1Resource('STR ',kSelectStrRsrc);
                   1229:        if (ResError()!=noErr || !strHndl || !*strHndl)
                   1230:                BlockMove(kDefaultSelectString,gSelectString,kDefaultSelectString[0]+1);
                   1231:        else {
                   1232:                BlockMove(*strHndl,&gSelectString,(long)((unsigned char *)(*strHndl)[0]+1));
                   1233:                ReleaseResource(strHndl);
                   1234:        }
                   1235: 
                   1236:        strHndl = Get1Resource('STR ',kDeskStrRsrc);
                   1237:        if (ResError()!=noErr || !strHndl || !*strHndl)
                   1238:                BlockMove(kDefaultDeskString,gDesktopFName,kDefaultSelectString[0]+1);
                   1239:        else {
                   1240:                BlockMove(*strHndl,&gDesktopFName,(long)((unsigned char *)(*strHndl)[0]+1));
                   1241:                ReleaseResource(strHndl);
                   1242:        }
                   1243: }
                   1244: 
                   1245: 
                   1246: /* do getfile */
                   1247: 
                   1248: static Boolean Share_CustomGet(FSSpec *fSpec)
                   1249: {
                   1250:        Point where = {-1,-1};
                   1251:        SFReply reply;
                   1252:        DialogPtr theDialog;
                   1253:        short item;
                   1254:        StandardFileReply sfReply;
                   1255:        SFData sfUserData;
                   1256:        OSErr err;
                   1257:        Boolean targetIsFolder,wasAliased;
1.1.1.3   root     1258: 
1.1       root     1259:        /* initialize user data area */
1.1.1.3   root     1260: 
1.1       root     1261:        sfUserData.replyPtr = &sfReply;
                   1262:        sfUserData.oldSelection.vRefNum = -9999;        /* init to ridiculous value */
1.1.1.3   root     1263: 
1.1       root     1264:        CustomGetFile(Share_FilterAllFiles_UPP,-1,nil,&sfReply,kSFDlg,where,Share_MyDlgHook_UPP,
                   1265:                                        Share_MyModalFilter_UPP,nil,nil,&sfUserData);
1.1.1.3   root     1266: 
1.1       root     1267:        if (sfReply.sfGood) {
                   1268:                err = ResolveAliasFile(&sfReply.sfFile,true,&targetIsFolder,&wasAliased);
                   1269:                if (err!=noErr)
                   1270:                        return false;
                   1271:        }
1.1.1.3   root     1272: 
1.1       root     1273:        err = FSMakeFSSpec(sfReply.sfFile.vRefNum,sfReply.sfFile.parID,sfReply.sfFile.name,fSpec);
                   1274:        if (err!=noErr)
                   1275:                return false;
1.1.1.3   root     1276: 
1.1       root     1277:        return sfReply.sfGood;
                   1278: }
                   1279: 
                   1280: static pascal short Share_MyDlgHook(short item,DialogPtr theDlg,Ptr userData)
                   1281: {
                   1282:        SFDataPtr sfUserData;
                   1283:        Boolean hiliteButton;
                   1284:        FSSpec curSpec;
                   1285:        OSType refCon;
1.1.1.3   root     1286: 
1.1       root     1287:        refCon = GetWRefCon(theDlg);
                   1288:        if (refCon!=sfMainDialogRefCon)
                   1289:                return item;
1.1.1.3   root     1290: 
1.1       root     1291:        sfUserData = (SFDataPtr) userData;
1.1.1.3   root     1292: 
1.1       root     1293:        if (item==sfHookFirstCall || item==sfHookLastCall)
                   1294:                return item;
1.1.1.3   root     1295: 
1.1       root     1296:        if (item==sfItemVolumeUser) {
                   1297:                sfUserData->replyPtr->sfFile.name[0] = '\0';
                   1298:                sfUserData->replyPtr->sfFile.parID = 2;
                   1299:                sfUserData->replyPtr->sfIsFolder = false;
                   1300:                sfUserData->replyPtr->sfIsVolume = false;
                   1301:                sfUserData->replyPtr->sfFlags = 0;
                   1302:                item = sfHookChangeSelection;
                   1303:        }
1.1.1.3   root     1304: 
1.1       root     1305:        if (!Share_SameFile(&sfUserData->replyPtr->sfFile,&sfUserData->oldSelection)) {
                   1306:                BlockMove(&sfUserData->replyPtr->sfFile,&curSpec,sizeof(FSSpec));
                   1307:                Share_MakeCanonFSSpec(&curSpec);
1.1.1.3   root     1308: 
1.1       root     1309:                if (curSpec.vRefNum!=sfUserData->oldSelection.vRefNum)
1.1.1.3   root     1310:                        Share_GetDeskFolderSpec(&gDeskFolderSpec,curSpec.vRefNum);
1.1       root     1311:                Share_SetSelectButtonName(curSpec.name,Share_ShouldHiliteSelect(&curSpec),theDlg);
1.1.1.3   root     1312: 
1.1       root     1313:                BlockMove(&sfUserData->replyPtr->sfFile,&sfUserData->oldSelection,sizeof(FSSpec));
                   1314:        }
1.1.1.3   root     1315: 
1.1       root     1316:        if (item==kSelectItem)
                   1317:                item = sfItemOpenButton;
1.1.1.3   root     1318: 
1.1       root     1319:        return item;
                   1320: }
                   1321: 
                   1322: 
                   1323: static pascal Boolean Share_MyModalFilter(DialogPtr theDlg,EventRecord *ev,short *itemHit,Ptr myData)
                   1324: {
                   1325:        Boolean evHandled;
                   1326:        char keyPressed;
                   1327:        OSType refCon;
1.1.1.3   root     1328: 
1.1       root     1329:        refCon = GetWRefCon(theDlg);
                   1330:        if (refCon!=sfMainDialogRefCon)
                   1331:                return false;
1.1.1.3   root     1332: 
1.1       root     1333:        evHandled = false;
1.1.1.3   root     1334: 
1.1       root     1335:        switch (ev->what) {
                   1336:                case keyDown:
                   1337:                case autoKey:
                   1338:                        keyPressed = ev->message & charCodeMask;
                   1339:                        if ((ev->modifiers & cmdKey) != 0) {
                   1340:                                switch (keyPressed) {
                   1341:                                        case kSelectKey:
                   1342:                                                Share_HitButton(theDlg,kSelectItem);
                   1343:                                                *itemHit = kSelectItem;
                   1344:                                                evHandled = true;
                   1345:                                                break;
                   1346:                                }
                   1347:                        }
                   1348:                        break;
                   1349:        }
1.1.1.3   root     1350: 
1.1       root     1351:        return evHandled;
                   1352: }
                   1353: 
                   1354: 
                   1355: static void Share_HitButton(DialogPtr theDlg,short item)
                   1356: {
                   1357:        short iType;
                   1358:        Handle iHndl;
                   1359:        Rect iRect;
                   1360:        long fTicks;
1.1.1.3   root     1361: 
1.1       root     1362:        GetDItem(theDlg,item,&iType,&iHndl,&iRect);
                   1363:        HiliteControl((ControlHandle)iHndl,inButton);
                   1364:        Delay(5,&fTicks);
                   1365:        HiliteControl((ControlHandle)iHndl,0);
                   1366: }
                   1367: 
                   1368: 
                   1369: static pascal Boolean Share_FilterAllFiles(CInfoPBPtr pb, Ptr myDataPtr)
                   1370: {
                   1371:        if (pb->hFileInfo.ioFlAttrib & (1<<4))  /* file is a directory */
                   1372:                return false;
                   1373: 
                   1374:        return true;
                   1375: }
                   1376: 
                   1377: 
                   1378: static void Share_SetSelectButtonName(StringPtr selName,Boolean hilited,DialogPtr theDlg)
                   1379: {
                   1380:        ControlHandle selectButton;
                   1381:        short iType;
                   1382:        Handle iHndl;
                   1383:        Rect iRect;
                   1384:        Str255 storeName,tempLenStr,tempSelName;
                   1385:        short btnWidth;
1.1.1.3   root     1386: 
1.1       root     1387:        BlockMove(selName,tempSelName,selName[0]+1);
                   1388:        GetDItem(theDlg,kSelectItem,&iType,&iHndl,&iRect);
1.1.1.3   root     1389: 
1.1       root     1390:        /* truncate select name to fit in button */
1.1.1.3   root     1391: 
1.1       root     1392:        btnWidth = iRect.right - iRect.left;
                   1393:        BlockMove(gSelectString,tempLenStr,gSelectString[0]+1);
                   1394:        p2cstr(tempLenStr);
                   1395:        strcat((char *)tempLenStr," ��  ");
                   1396:        c2pstr((char *)tempLenStr);
                   1397:        btnWidth -= StringWidth(tempLenStr);
                   1398:        TruncString(btnWidth,tempSelName,smTruncMiddle);
1.1.1.3   root     1399: 
1.1       root     1400:        BlockMove(gSelectString,storeName,gSelectString[0]+1);
                   1401:        p2cstr(storeName);
                   1402:        p2cstr(tempSelName);
                   1403:        strcat((char *)storeName," �");
                   1404:        strcat((char *)storeName,(char *)tempSelName);
                   1405:        strcat((char *)storeName,"�");
1.1.1.3   root     1406: 
1.1       root     1407:        c2pstr((char *)storeName);
                   1408:        c2pstr((char *)tempSelName);
                   1409:        SetCTitle((ControlHandle)iHndl,storeName);
1.1.1.3   root     1410: 
1.1       root     1411:        SetDItem(theDlg,kSelectItem,iType,iHndl,&iRect);
                   1412: 
                   1413:        if (hilited)
                   1414:                HiliteControl((ControlHandle)iHndl,0);
                   1415:        else
1.1.1.3   root     1416:                HiliteControl((ControlHandle)iHndl,255);
1.1       root     1417: }
                   1418: 
                   1419: 
                   1420: static Boolean Share_SameFile(FSSpec *file1,FSSpec *file2)
                   1421: {
                   1422:        if (file1->vRefNum != file2->vRefNum)
                   1423:                return false;
                   1424:        if (file1->parID != file2->parID)
                   1425:                return false;
                   1426:        if (!EqualString(file1->name,file2->name,false,true))
                   1427:                return false;
1.1.1.3   root     1428: 
1.1       root     1429:        return true;
                   1430: }
                   1431: 
                   1432: 
                   1433: static OSErr Share_GetDeskFolderSpec(FSSpec *fSpec,short vRefNum)
                   1434: {
                   1435:        DirInfo infoPB;
                   1436:        OSErr err;
1.1.1.3   root     1437: 
1.1       root     1438:        if (!gHasFindFolder) {
                   1439:                fSpec->vRefNum = -9999;
                   1440:                return -1;
                   1441:        }
1.1.1.3   root     1442: 
1.1       root     1443:        fSpec->name[0] = '\0';
                   1444:        err = FindFolder(vRefNum,kDesktopFolderType,kDontCreateFolder,
                   1445:                                                &fSpec->vRefNum,&fSpec->parID);
                   1446:        if (err!=noErr)
                   1447:                return err;
1.1.1.3   root     1448: 
1.1       root     1449:        return Share_MakeCanonFSSpec(fSpec);
                   1450: }
                   1451: 
                   1452: 
                   1453: static Boolean Share_ShouldHiliteSelect(FSSpec *fSpec)
                   1454: {
                   1455:        if (Share_SameFile(fSpec,&gDeskFolderSpec)) {
                   1456:                BlockMove(gDesktopFName,fSpec->name,gDesktopFName[0]+1);
                   1457:                return kCanSelectDesktop;
                   1458:        }
                   1459:        else
                   1460:                return true;
                   1461: }
                   1462: 
                   1463: static OSErr Share_MakeCanonFSSpec(FSSpec *fSpec)
                   1464: {
                   1465:        CInfoPBRec infoPB;
                   1466:        OSErr err;
                   1467: 
                   1468:        if (fSpec->name[0] != '\0')
                   1469:                return;
1.1.1.3   root     1470: 
1.1       root     1471:        infoPB.dirInfo.ioNamePtr = fSpec->name;
                   1472:        infoPB.dirInfo.ioVRefNum = fSpec->vRefNum;
                   1473:        infoPB.dirInfo.ioDrDirID = fSpec->parID;
                   1474:        infoPB.dirInfo.ioFDirIndex = -1;
                   1475:        err = PBGetCatInfo(&infoPB,false);
                   1476:        fSpec->parID = infoPB.dirInfo.ioDrParID;
1.1.1.3   root     1477: 
1.1       root     1478:        return err;
                   1479: }
                   1480: 
                   1481: static void Share_ResolvePath (FSSpec *fSpec, char *path)
                   1482: {      char volname[128];
                   1483:        char dirname[128];
                   1484:        char path_copy[1024];
                   1485:        short the_vRefNum;
                   1486:        long  the_parID;
                   1487:        CInfoPBRec infoPB;
                   1488: 
                   1489:        volname[0]=0;
                   1490:        strcpy(dirname,(char *)fSpec->name);
                   1491:        p2cstr((unsigned char *)dirname);
1.1.1.3   root     1492: 
1.1       root     1493:        strcpy(path,dirname);
1.1.1.3   root     1494: 
1.1       root     1495:        the_vRefNum=(fSpec->vRefNum);
                   1496:        the_parID=(fSpec->parID);
                   1497: 
                   1498:        infoPB.dirInfo.ioNamePtr = (unsigned char *)volname;
                   1499:        infoPB.dirInfo.ioVRefNum = the_vRefNum;
                   1500:        infoPB.dirInfo.ioDrDirID = fsRtDirID;
                   1501:        infoPB.dirInfo.ioFDirIndex = -1;
                   1502:        PBGetCatInfo(&infoPB,false);
                   1503: 
                   1504:        p2cstr((unsigned char *)volname);
                   1505: 
                   1506:        while (strcmp(volname,dirname) != 0)
1.1.1.3   root     1507:        {
1.1       root     1508:                infoPB.dirInfo.ioNamePtr = (unsigned char *)dirname;
                   1509:                infoPB.dirInfo.ioVRefNum = the_vRefNum;
                   1510:                infoPB.dirInfo.ioDrDirID = the_parID;
                   1511:                infoPB.dirInfo.ioFDirIndex = -1;
                   1512:                PBGetCatInfo(&infoPB,false);
                   1513:                the_parID = infoPB.dirInfo.ioDrParID;
1.1.1.3   root     1514: 
1.1       root     1515:                p2cstr((unsigned char *)dirname);
                   1516:                strcpy(path_copy,dirname);
                   1517:                strcat(path_copy,":");
                   1518:                strcat(path_copy,path);
                   1519:                strcpy(path,path_copy);
                   1520:        }
                   1521: }
                   1522: 
                   1523: Boolean ReadPrefs (char *share_path)
                   1524: {      OSErr err=noErr;
                   1525:        short prefsFolder;
                   1526:        Str255 prefsName="\pUAE Preferences";
                   1527:        long prefDirID;
                   1528:        short prefvRefNum;
                   1529:        FSSpec spec;
                   1530:        short home,preffile;
                   1531:        Handle share_handle;
                   1532:        Handle config_handle;
                   1533:        int config_sets[128],count;
                   1534: 
                   1535:        home = CurResFile();
                   1536:        preffile=0;
                   1537:        *share_path=0;
1.1.1.3   root     1538: 
1.1       root     1539:        err=FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &prefvRefNum, &prefDirID);
                   1540:        if (err != noErr) return false;
                   1541:        FSMakeFSSpec(prefvRefNum, prefDirID, prefsName, &spec);
                   1542: 
                   1543:        preffile=FSpOpenResFile(&spec, fsRdWrPerm);
                   1544:        if (ResError() != noErr) return false;
                   1545: 
                   1546:        UseResFile(preffile);
                   1547: 
                   1548:        if (share_path != 0)
                   1549:        {       share_handle = Get1Resource('STR ',128);
                   1550:                if (ResError() == noErr && share_handle !=0 && *share_handle !=0)
                   1551:                {       strcpy(share_path,*share_handle);
                   1552:                        ReleaseResource(share_handle);
                   1553:                }
                   1554:        }
                   1555: 
                   1556:        config_handle = Get1Resource('PREF',128);
                   1557:        if (ResError() == noErr && config_handle !=0)
                   1558:        {       BlockMove((Ptr) *config_handle,(Ptr) config_sets,128);
                   1559:                ReleaseResource(config_handle);
1.1.1.3   root     1560: 
1.1       root     1561:                framerate=config_sets[0];
                   1562:                use_slow_mem=config_sets[1];
                   1563:                use_gfxlib=config_sets[2];
                   1564:                automount_uaedev=config_sets[3];
                   1565:                produce_sound=config_sets[4];
                   1566:                fake_joystick=config_sets[5];
                   1567:                screen_res=config_sets[6];
                   1568:                use_quickdraw=config_sets[7];
                   1569:                filesys_vRefNum=config_sets[8];
                   1570:        }
                   1571: 
                   1572:        UseResFile(home);
                   1573:        CloseResFile(preffile);
                   1574:        return true;
                   1575: }
                   1576: 
                   1577: void CreatePrefs (void)
                   1578: {      OSErr err=noErr;
                   1579:        short prefsFolder;
                   1580:        Str255 prefsName="\pUAE Preferences";
                   1581:        long prefDirID;
                   1582:        short prefvRefNum;
                   1583:        FSSpec spec;
                   1584:        short home,preffile;
1.1.1.3   root     1585: 
1.1       root     1586:        home = CurResFile();
                   1587:        preffile=0;
1.1.1.3   root     1588: 
1.1       root     1589:        err=FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &prefvRefNum, &prefDirID);
                   1590:        if (err != noErr) return;
                   1591:        FSMakeFSSpec(prefvRefNum, prefDirID, prefsName, &spec);
1.1.1.3   root     1592: 
1.1       root     1593:        err=FSpCreate(&spec, 'mUAE', 'pref', 0);
                   1594:        if (err != noErr) return;
1.1.1.3   root     1595: 
1.1       root     1596:        FSpCreateResFile(&spec, 'mUAE', 'pref', 0);
                   1597: }
                   1598: 
                   1599: void WritePrefs (char *share_path)
                   1600: {      OSErr err=noErr;
                   1601:        short prefsFolder;
                   1602:        Str255 prefsName="\pUAE Preferences";
                   1603:        long prefDirID;
                   1604:        short prefvRefNum;
                   1605:        FSSpec spec;
                   1606:        short home,preffile;
                   1607:        Handle share_handle;
                   1608:        Handle config_handle;
                   1609:        int config_sets[128],count;
1.1.1.3   root     1610: 
1.1       root     1611:        home = CurResFile();
                   1612:        preffile=0;
1.1.1.3   root     1613: 
1.1       root     1614:        err=FindFolder(kOnSystemDisk, kPreferencesFolderType, true, &prefvRefNum, &prefDirID);
                   1615:        if (err != noErr) return;
                   1616:        FSMakeFSSpec(prefvRefNum, prefDirID, prefsName, &spec);
1.1.1.3   root     1617: 
1.1       root     1618:        preffile=FSpOpenResFile(&spec, fsRdWrPerm);
                   1619:        if (ResError() != noErr) return;
1.1.1.3   root     1620: 
1.1       root     1621:        for (count=0;count < 64;count++) config_sets[count]=0;
1.1.1.3   root     1622: 
1.1       root     1623:        config_sets[0]=framerate;
                   1624:        config_sets[1]=use_slow_mem;
                   1625:        config_sets[2]=my_use_gfxlib;
                   1626:        config_sets[3]=my_automount_uaedev;
                   1627:        config_sets[4]=produce_sound;
                   1628:        config_sets[5]=fake_joystick;
                   1629:        config_sets[6]=my_screen_res;
                   1630:        config_sets[7]=my_use_quickdraw;
                   1631:        config_sets[8]=filesys_vRefNum;
1.1.1.3   root     1632: 
1.1       root     1633:        UseResFile(preffile);
1.1.1.3   root     1634: 
                   1635: 
1.1       root     1636:        if (share_path != 0)
                   1637:        {       share_handle=Get1Resource('STR ',128);
                   1638:                if (ResError() != noErr || share_handle == 0)
                   1639:                {       share_handle=NewHandleClear(1024);
                   1640:                        strcpy(*share_handle,share_path);
                   1641:                        AddResource(share_handle,'STR ',128, "\pMac/Amiga sharing path");
                   1642:                        WriteResource(share_handle);
                   1643:                        DetachResource(share_handle);
                   1644:                }
                   1645:                else
                   1646:                {       strcpy(*share_handle,share_path);
                   1647:                        ChangedResource(share_handle);
                   1648:                        WriteResource(share_handle);
                   1649:                        ReleaseResource(share_handle);
                   1650:                }
                   1651:        }
1.1.1.3   root     1652: 
1.1       root     1653:        config_handle=Get1Resource('PREF',128);
                   1654:        if (ResError() != noErr || config_handle == 0)
                   1655:        {       config_handle=NewHandleClear(1024);
                   1656:                BlockMove((Ptr) config_sets,(Ptr) *config_handle,128);
                   1657:                AddResource(config_handle,'PREF',128, "\pUAE Preferences");
                   1658:                WriteResource(config_handle);
                   1659:                DetachResource(config_handle);
                   1660:        }
                   1661:        else
                   1662:        {       BlockMove((Ptr) config_sets,(Ptr) *config_handle,128);
                   1663:                ChangedResource(config_handle);
                   1664:                WriteResource(config_handle);
                   1665:                ReleaseResource(config_handle);
                   1666:        }
1.1.1.3   root     1667: 
1.1       root     1668:        UseResFile(home);
                   1669:        CloseResFile(preffile);
                   1670: }

unix.superglobalmegacorp.com

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