Annotation of uae/src/mac.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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