Annotation of uae/src/main.c, revision 1.1.1.24

1.1       root        1:  /*
                      2:   * UAE - The Un*x Amiga Emulator
1.1.1.3   root        3:   *
                      4:   * Main program
                      5:   *
                      6:   * Copyright 1995 Ed Hanway
                      7:   * Copyright 1995, 1996, 1997 Bernd Schmidt
1.1       root        8:   */
                      9: #include "sysconfig.h"
                     10: #include "sysdeps.h"
                     11: #include <assert.h>
                     12: 
                     13: #include "options.h"
1.1.1.15  root       14: #include "threaddep/thread.h"
1.1.1.2   root       15: #include "uae.h"
1.1.1.3   root       16: #include "gensound.h"
1.1.1.13  root       17: #include "audio.h"
1.1.1.3   root       18: #include "sounddep/sound.h"
1.1.1.2   root       19: #include "events.h"
1.1       root       20: #include "memory.h"
                     21: #include "custom.h"
                     22: #include "serial.h"
                     23: #include "newcpu.h"
                     24: #include "disk.h"
                     25: #include "debug.h"
                     26: #include "xwin.h"
1.1.1.20  root       27: #include "inputdevice.h"
1.1       root       28: #include "keybuf.h"
                     29: #include "gui.h"
                     30: #include "zfile.h"
                     31: #include "autoconf.h"
1.1.1.22  root       32: #include "filesys.h"
1.1.1.2   root       33: #include "osemu.h"
1.1.1.3   root       34: #include "picasso96.h"
1.1.1.22  root       35: #include "traps.h"
1.1.1.6   root       36: #include "bsdsocket.h"
1.1.1.3   root       37: #include "uaeexe.h"
1.1.1.8   root       38: #include "native2amiga.h"
                     39: #include "scsidev.h"
1.1.1.22  root       40: #include "romlist.h"
1.1       root       41: 
1.1.1.15  root       42: #ifdef USE_SDL
                     43: #include "SDL.h"
                     44: #endif
                     45: 
1.1.1.6   root       46: struct uae_prefs currprefs, changed_prefs;
1.1.1.21  root       47: struct gfx_params *curr_gfx;
1.1.1.4   root       48: 
1.1.1.6   root       49: int no_gui = 0;
1.1.1.4   root       50: int joystickpresent = 0;
                     51: int cloanto_rom = 0;
                     52: 
1.1.1.11  root       53: struct gui_info gui_data;
                     54: 
1.1.1.4   root       55: char warning_buffer[256];
                     56: 
                     57: char optionsfile[256];
                     58: 
                     59: /* If you want to pipe printer output to a file, put something like
                     60:  * "cat >>printerfile.tmp" above.
                     61:  * The printer support was only tested with the driver "PostScript" on
                     62:  * Amiga side, using apsfilter for linux to print ps-data.
                     63:  *
                     64:  * Under DOS it ought to be -p LPT1: or -p PRN: but you'll need a
                     65:  * PostScript printer or ghostscript -=SR=-
                     66:  */
                     67: 
                     68: /* Slightly stupid place for this... */
                     69: /* ncurses.c might use quite a few of those. */
                     70: char *colormodes[] = { "256 colors", "32768 colors", "65536 colors",
                     71:     "256 colors dithered", "16 colors dithered", "16 million colors",
                     72:     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                     73:     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                     74:     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                     75:     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                     76:     "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""
                     77: };
                     78: 
1.1.1.22  root       79: struct uae_rect *gfx_fullscreen_modes, *gfx_windowed_modes;
                     80: int n_fullscreen_modes, n_windowed_modes;
1.1.1.21  root       81: 
1.1.1.22  root       82: static struct uae_rect default_windowed_modes[] =
1.1.1.21  root       83: {
1.1.1.22  root       84:     { 320, 256 },
                     85:     { 400, 300 },
                     86:     { 640, 512 },
                     87:     { 800, 600 }
                     88: };
                     89: 
                     90: struct config_list *predef_configs;
                     91: int n_predef_configs;
                     92: int predef_configs_space;
1.1.1.21  root       93: 
1.1.1.22  root       94: static int sortfn (const void *a, const void *b)
                     95: {
                     96:     struct config_list *pa = (struct config_list *)a;
                     97:     struct config_list *pb = (struct config_list *)b;
                     98:     return strcmp (pa->sortstr, pb->sortstr);
                     99: }
                    100: 
                    101: static void scan_configs (const char *path)
                    102: {
                    103:     DIR *dir;
                    104:     int pathlen = strlen (path);
                    105:     int bufsz = pathlen + 256;
                    106:     char *buffer;
                    107:     uae_u8 *data;
                    108: 
                    109:     predef_configs_space = 20;
                    110:     predef_configs = malloc (sizeof (struct config_list) * 20);
                    111:     n_predef_configs = 0;
                    112: 
                    113:     dir = opendir (path);
                    114:     if (!dir)
                    115:        return;
                    116: 
                    117:     buffer = malloc (bufsz);
                    118:     if (!buffer)
                    119:        goto out;
                    120:     data = malloc (1024 * 1024);
                    121:     if (!data)
                    122:        goto out1;
                    123: 
                    124:     strcpy (buffer, path);
                    125:     buffer[pathlen++] = '/';
                    126:     buffer[pathlen] = '\0';
                    127:     for (;;) {
                    128:        struct uae_prefs p;
                    129:        struct zfile *f;
                    130:        struct dirent *ent = readdir (dir);
                    131:        int len;
                    132:        struct romdata *rd;
                    133:        long size;
                    134: 
                    135:        if (!ent)
                    136:            break;
                    137: 
                    138:        len = strlen (ent->d_name);
                    139:        if (len + pathlen + 1 >= bufsz) {
                    140:            bufsz = len + pathlen + 200;
                    141:            buffer = realloc (buffer, bufsz);
                    142:            if (!buffer) {
                    143:                free (data);
                    144:                goto out;
                    145:            }
                    146:        }
                    147:        strcpy (buffer + pathlen, ent->d_name);
                    148: 
                    149:        if (n_predef_configs >= predef_configs_space) {
                    150:            predef_configs_space += 20;
                    151:            predef_configs = realloc (predef_configs,
                    152:                                      sizeof (struct config_list) * predef_configs_space);
                    153:        }
                    154:        default_prefs (&p);
                    155:        strcpy (p.description, "");
                    156:        strcpy (p.sortstr, "");
                    157:        cfgfile_load (&p, buffer);
                    158:        if (strlen (p.description) > 0) {
                    159:            predef_configs[n_predef_configs].filename = strdup (buffer);
                    160:            predef_configs[n_predef_configs].description = strdup (p.description);
                    161:            predef_configs[n_predef_configs++].sortstr = strdup (p.sortstr);
                    162:        }
                    163:     }
                    164:     qsort (predef_configs, n_predef_configs, sizeof *predef_configs, sortfn);
                    165:     free (data);
                    166:   out1:
                    167:     free (buffer);
                    168:   out:
                    169:     closedir (dir);
1.1.1.21  root      170: }
                    171: 
1.1.1.6   root      172: void discard_prefs (struct uae_prefs *p)
1.1.1.3   root      173: {
1.1.1.6   root      174:     struct strlist **ps = &p->unknown_lines;
                    175:     while (*ps) {
                    176:        struct strlist *s = *ps;
                    177:        *ps = s->next;
                    178:        free (s->str);
                    179:        free (s);
                    180:     }
                    181:     free_mountinfo (p->mountinfo);
                    182: }
                    183: 
                    184: void default_prefs (struct uae_prefs *p)
                    185: {
                    186:     strcpy (p->description, "UAE default configuration");
                    187: 
                    188:     p->start_gui = 1;
                    189:     p->start_debugger = 0;
                    190: 
                    191:     p->unknown_lines = 0;
1.1.1.4   root      192:     /* Note to porters: please don't change any of these options! UAE is supposed
                    193:      * to behave identically on all platforms if possible. */
1.1.1.6   root      194:     p->illegal_mem = 0;
                    195:     p->use_serial = 0;
                    196:     p->serial_demand = 0;
                    197:     p->parallel_demand = 0;
                    198: 
1.1.1.20  root      199:     p->jport0 = JSEM_MICE;
                    200:     p->jport1 = JSEM_JOYS;
                    201: 
1.1.1.6   root      202:     p->keyboard_lang = KBD_LANG_US;
                    203:     p->emul_accuracy = 2;
                    204:     p->test_drawing_speed = 0;
                    205: 
1.1.1.22  root      206:     p->produce_sound = 3;
1.1.1.18  root      207:     p->sound_stereo = 0;
1.1.1.22  root      208:     p->sound_stereo_separation = 7;
                    209:     p->sound_mixed_stereo_delay = 0;
1.1.1.6   root      210:     p->sound_freq = DEFAULT_SOUND_FREQ;
                    211:     p->sound_maxbsiz = DEFAULT_SOUND_MAXB;
1.1.1.23  root      212:     p->sound_interpol = 2;
1.1.1.22  root      213:     p->sound_filter = FILTER_SOUND_OFF;
                    214:     p->sound_filter_type = FILTER_SOUND_TYPE_A500;
1.1.1.6   root      215: 
1.1.1.8   root      216:     p->gfx_framerate = 1;
1.1.1.21  root      217:     p->gfx_w.width = 800;
                    218:     p->gfx_w.height = 600;
                    219:     p->gfx_w.lores = 0;
                    220:     p->gfx_w.linedbl = 2;
                    221:     p->gfx_w.correct_aspect = 0;
                    222:     p->gfx_w.xcenter = 0;
                    223:     p->gfx_w.ycenter = 0;
                    224:     p->gfx_f = p->gfx_w;
1.1.1.22  root      225:     p->gfx_w.leds_on_screen = 0;
                    226:     p->gfx_f.leds_on_screen = 1;
1.1.1.6   root      227:     p->gfx_afullscreen = 0;
                    228:     p->gfx_pfullscreen = 0;
                    229:     p->color_mode = 0;
                    230: 
                    231:     p->x11_use_low_bandwidth = 0;
                    232:     p->x11_use_mitshm = 0;
                    233:     p->x11_hide_cursor = 1;
                    234: 
1.1.1.8   root      235:     p->svga_no_linear = 0;
                    236: 
1.1.1.10  root      237:     p->curses_reverse_video = 0;
                    238: 
1.1.1.8   root      239:     p->win32_middle_mouse = 0;
                    240:     p->win32_logfile = 0;
                    241:     p->win32_iconified_nospeed = 0;
                    242:     p->win32_iconified_nosound = 0;
1.1.1.16  root      243:     p->win32_no_overlay = 0;
1.1.1.8   root      244: 
1.1.1.6   root      245:     p->immediate_blits = 0;
1.1.1.14  root      246:     p->collision_level = 1;
1.1.1.22  root      247:  
                    248:     p->chipset_mask = CSMASK_ECS_AGNUS;
                    249:     p->cs_rtc = 2;
                    250:     p->cs_a1000ram = 0;
                    251:     p->cs_fatgaryrev = -1;
                    252:     p->cs_ramseyrev = -1;
                    253:     p->cs_ide = 0;
1.1.1.6   root      254: 
                    255:     strcpy (p->df[0], "df0.adf");
                    256:     strcpy (p->df[1], "df1.adf");
                    257:     strcpy (p->df[2], "df2.adf");
                    258:     strcpy (p->df[3], "df3.adf");
                    259: 
                    260:     strcpy (p->romfile, "kick.rom");
                    261:     strcpy (p->keyfile, "");
                    262:     strcpy (p->prtname, DEFPRTNAME);
1.1.1.22  root      263:     p->rom_crc32 = 0;
1.1.1.6   root      264: 
                    265:     strcpy (p->path_rom, "./");
                    266:     strcpy (p->path_floppy, "./");
                    267:     strcpy (p->path_hardfile, "./");
                    268: 
1.1.1.15  root      269:     strcpy (p->prtname, "");
                    270:     strcpy (p->sername, "");
                    271: 
1.1.1.22  root      272:     p->nr_floppies = 2;
                    273:     p->dfxtype[0] = DRV_35_DD;
                    274:     p->dfxtype[1] = DRV_35_DD;
                    275:     p->dfxtype[2] = DRV_NONE;
                    276:     p->dfxtype[3] = DRV_NONE;
                    277: 
1.1.1.11  root      278:     p->m68k_speed = 0;
1.1.1.22  root      279:     p->cpu_model = 68020;
                    280:     p->fpu_model = 0;
1.1.1.6   root      281:     p->address_space_24 = 0;
                    282: 
                    283:     p->fastmem_size = 0x00000000;
1.1.1.22  root      284:     p->mbresmem_low_size = 0x00000000;
                    285:     p->mbresmem_high_size = 0x00000000;
1.1.1.6   root      286:     p->z3fastmem_size = 0x00000000;
                    287:     p->chipmem_size = 0x00200000;
                    288:     p->bogomem_size = 0x00000000;
                    289:     p->gfxmem_size = 0x00000000;
1.1       root      290: 
1.1.1.6   root      291:     p->mountinfo = alloc_mountinfo ();
1.1.1.20  root      292:     inputdevice_default_prefs (p);
1.1.1.22  root      293:     p->bootrom = 1;
1.1.1.4   root      294: }
1.1       root      295: 
1.1.1.22  root      296: int fixup_prefs_dimensions (struct gfx_params *p, struct uae_rect *modes, int n_modes)
1.1.1.4   root      297: {
1.1.1.22  root      298:     int i;
1.1.1.21  root      299:     if (p->width < 320)
                    300:        p->width = 320;
                    301:     if (p->height < 200)
                    302:        p->height = 200;
1.1.1.22  root      303:     for (i = 0; i < n_modes; i++) {
                    304:        if ((modes[i].w >= p->width && modes[i].h >= p->height)
                    305:            || i == n_modes - 1)
                    306:        {
                    307:            p->width = modes[i].w;
                    308:            p->height = modes[i].h;
                    309:            p->lores = p->width <= 512;
                    310:            if (p->height > 300 && !p->linedbl)
                    311:                p->linedbl = 1;
                    312:            return i;
                    313:        }
                    314:     }
                    315:     return n_modes - 1;
                    316: }
                    317: 
1.1.1.24! root      318: static void fixup_sound (struct uae_prefs *p)
1.1.1.22  root      319: {
                    320:     if (p->sound_stereo_separation < 0)
                    321:        p->sound_stereo_separation = 0;
                    322:     if (p->sound_stereo_separation > MIXED_STEREO_MAX)
                    323:        p->sound_stereo_separation = MIXED_STEREO_MAX;
1.1.1.4   root      324: }
1.1.1.3   root      325: 
1.1.1.22  root      326: static void fixup_prefs (struct uae_prefs *p)
1.1.1.2   root      327: {
1.1.1.3   root      328:     int err = 0;
                    329: 
1.1.1.22  root      330:     if ((p->chipmem_size & (p->chipmem_size - 1)) != 0
                    331:        || p->chipmem_size < 0x80000
                    332:        || p->chipmem_size > 0x800000)
1.1.1.3   root      333:     {
1.1.1.22  root      334:        p->chipmem_size = 0x200000;
1.1.1.16  root      335:        write_log ("Unsupported chipmem size!\n");
1.1.1.3   root      336:        err = 1;
                    337:     }
1.1.1.22  root      338:     if ((p->fastmem_size & (p->fastmem_size - 1)) != 0
                    339:        || (p->fastmem_size != 0 && (p->fastmem_size < 0x100000 || p->fastmem_size > 0x800000)))
1.1.1.3   root      340:     {
1.1.1.22  root      341:        p->fastmem_size = 0;
1.1.1.16  root      342:        write_log ("Unsupported fastmem size!\n");
1.1.1.3   root      343:        err = 1;
                    344:     }
1.1.1.22  root      345:     if ((p->gfxmem_size & (p->gfxmem_size - 1)) != 0
                    346:        || (p->gfxmem_size != 0 && (p->gfxmem_size < 0x100000 || p->gfxmem_size > 0x2000000)))
1.1.1.3   root      347:     {
1.1.1.22  root      348:        write_log ("Unsupported graphics card memory size %lx!\n", p->gfxmem_size);
                    349:        p->gfxmem_size = 0;
1.1.1.3   root      350:        err = 1;
                    351:     }
1.1.1.22  root      352:     if ((p->z3fastmem_size & (p->z3fastmem_size - 1)) != 0
1.1.1.24! root      353:        || (p->z3fastmem_size != 0 && (p->z3fastmem_size < 0x100000 || p->z3fastmem_size > 0x10000000)))
1.1.1.3   root      354:     {
1.1.1.22  root      355:        p->z3fastmem_size = 0;
1.1.1.16  root      356:        write_log ("Unsupported Zorro III fastmem size!\n");
1.1.1.3   root      357:        err = 1;
                    358:     }
1.1.1.22  root      359:     if (p->address_space_24 && (p->gfxmem_size != 0 || p->z3fastmem_size != 0)) {
                    360:        p->z3fastmem_size = p->gfxmem_size = 0;
1.1.1.16  root      361:        write_log ("Can't use a graphics card or Zorro III fastmem when using a 24 bit\n"
1.1.1.3   root      362:                 "address space - sorry.\n");
                    363:     }
1.1.1.22  root      364:     if ((p->bogomem_size & (p->bogomem_size - 1)) != 0
                    365:        || (p->bogomem_size != 0 && (p->bogomem_size < 0x80000 || p->bogomem_size > 0x100000)))
1.1.1.3   root      366:     {
1.1.1.22  root      367:        p->bogomem_size = 0;
1.1.1.16  root      368:        write_log ("Unsupported bogomem size!\n");
1.1.1.3   root      369:        err = 1;
                    370:     }
                    371: 
1.1.1.22  root      372:     if (p->chipmem_size > 0x200000 && p->fastmem_size != 0) {
1.1.1.16  root      373:        write_log ("You can't use fastmem and more than 2MB chip at the same time!\n");
1.1.1.22  root      374:        p->fastmem_size = 0;
1.1.1.3   root      375:        err = 1;
                    376:     }
1.1.1.13  root      377: #if 0
1.1.1.22  root      378:     if (p->m68k_speed < -1 || p->m68k_speed > 20) {
1.1.1.16  root      379:        write_log ("Bad value for -w parameter: must be -1, 0, or within 1..20.\n");
1.1.1.22  root      380:        p->m68k_speed = 4;
1.1.1.3   root      381:        err = 1;
                    382:     }
1.1.1.13  root      383: #endif
1.1.1.20  root      384: 
1.1.1.22  root      385:     if (p->produce_sound < 0 || p->produce_sound > 3) {
1.1.1.16  root      386:        write_log ("Bad value for -S parameter: enable value must be within 0..3\n");
1.1.1.22  root      387:        p->produce_sound = 0;
1.1.1.3   root      388:        err = 1;
                    389:     }
1.1.1.22  root      390:     if (p->cpu_model < 68020 && p->z3fastmem_size > 0) {
1.1.1.16  root      391:        write_log ("Z3 fast memory can't be used with a 68000/68010 emulation. It\n"
1.1.1.3   root      392:                 "requires a 68020 emulation. Turning off Z3 fast memory.\n");
1.1.1.22  root      393:        p->z3fastmem_size = 0;
1.1.1.3   root      394:        err = 1;
                    395:     }
1.1.1.22  root      396:     if (p->gfxmem_size > 0 && (p->cpu_model < 68020 || p->address_space_24)) {
1.1.1.16  root      397:        write_log ("Picasso96 can't be used with a 68000/68010 or 68EC020 emulation. It\n"
1.1.1.3   root      398:                 "requires a 68020 emulation. Turning off Picasso96.\n");
1.1.1.22  root      399:        p->gfxmem_size = 0;
1.1.1.3   root      400:        err = 1;
                    401:     }
1.1.1.22  root      402: #ifndef BSDSOCKET
                    403:     if (p->socket_emu) {
1.1.1.16  root      404:        write_log ("Compile-time option of BSDSOCKET_SUPPORTED was not enabled.  You can't use bsd-socket emulation.\n");
1.1.1.22  root      405:        p->socket_emu = 0;
1.1.1.8   root      406:        err = 1;
                    407:     }
                    408: #endif
1.1.1.3   root      409: 
1.1.1.22  root      410:     if (p->nr_floppies < 1 || p->nr_floppies > 4) {
1.1.1.16  root      411:        write_log ("Invalid number of floppies.  Using 4.\n");
1.1.1.22  root      412:        p->nr_floppies = 4;
1.1.1.11  root      413:        err = 1;
                    414:     }
1.1.1.22  root      415:     if (p->collision_level < 0 || p->collision_level > 3) {
1.1.1.16  root      416:        write_log ("Invalid collision support level.  Using 1.\n");
1.1.1.22  root      417:        p->collision_level = 1;
1.1.1.14  root      418:        err = 1;
                    419:     }
1.1.1.11  root      420: 
1.1.1.22  root      421:     fixup_sound (p);
                    422: 
1.1.1.3   root      423:     if (err)
1.1.1.16  root      424:        write_log ("Please use \"uae -h\" to get usage information.\n");
1.1.1.3   root      425: }
                    426: 
                    427: int quit_program = 0;
                    428: 
1.1.1.20  root      429: void uae_reset (int hardreset)
1.1.1.3   root      430: {
1.1.1.20  root      431:     if (quit_program == 0) {
1.1.1.3   root      432:        quit_program = -2;
1.1.1.20  root      433:        if (hardreset)
                    434:            quit_program = -3;
                    435:     }
1.1.1.3   root      436: }
                    437: 
                    438: void uae_quit (void)
                    439: {
                    440:     if (quit_program != -1)
                    441:        quit_program = -1;
1.1.1.2   root      442: }
1.1       root      443: 
1.1.1.6   root      444: #ifndef DONT_PARSE_CMDLINE
1.1.1.3   root      445: 
1.1.1.6   root      446: void usage (void)
                    447: {
1.1.1.3   root      448: }
                    449: 
1.1.1.6   root      450: void parse_cmdline (int argc, char **argv)
                    451: {
1.1.1.8   root      452:     int i;
                    453:     for (i = 1; i < argc; i++) {
                    454:        if (strncmp (argv[i], "-config=", 8) == 0)
                    455:            cfgfile_load (&currprefs, argv[i] + 8);
                    456:        /* Check for new-style "-f xxx" argument, where xxx is config-file */
                    457:        else if (strcmp (argv[i], "-f") == 0) {
                    458:            if (i + 1 == argc)
1.1.1.17  root      459:                write_log ("Missing argument for '-f' option.\n");
1.1.1.8   root      460:            else
                    461:                cfgfile_load (&currprefs, argv[++i]);
                    462:        } else if (strcmp (argv[i], "-s") == 0) {
                    463:            if (i + 1 == argc)
1.1.1.17  root      464:                write_log ("Missing argument for '-s' option.\n");
1.1.1.8   root      465:            else
                    466:                cfgfile_parse_line (&currprefs, argv[++i]);
                    467:        } else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "-help") == 0) {
1.1.1.6   root      468:            usage ();
                    469:            exit (0);
1.1.1.9   root      470:        } else {
                    471:            if (argv[i][0] == '-' && argv[i][1] != '\0') {
                    472:                const char *arg = argv[i] + 2;
1.1.1.10  root      473:                int extra_arg = *arg == '\0';
                    474:                if (extra_arg)
1.1.1.9   root      475:                    arg = i + 1 < argc ? argv[i + 1] : 0;
1.1.1.22  root      476:                if (parse_cmdline_option (&currprefs, argv[i][1], arg) && extra_arg)
1.1.1.10  root      477:                    i++;
1.1.1.9   root      478:            }
1.1.1.3   root      479:        }
1.1       root      480:     }
                    481: }
                    482: #endif
                    483: 
1.1.1.4   root      484: static void parse_cmdline_and_init_file (int argc, char **argv)
1.1       root      485: {
1.1.1.3   root      486:     char *home;
1.1       root      487: 
1.1.1.6   root      488:     strcpy (optionsfile, "");
1.1       root      489: 
1.1.1.3   root      490: #ifdef OPTIONS_IN_HOME
1.1.1.4   root      491:     home = getenv ("HOME");
                    492:     if (home != NULL && strlen (home) < 240)
1.1       root      493:     {
1.1.1.4   root      494:        strcpy (optionsfile, home);
                    495:        strcat (optionsfile, "/");
1.1       root      496:     }
                    497: #endif
                    498: 
1.1.1.4   root      499:     strcat (optionsfile, OPTIONSFILENAME);
1.1       root      500: 
1.1.1.6   root      501:     if (! cfgfile_load (&currprefs, optionsfile)) {
1.1.1.3   root      502: #ifdef OPTIONS_IN_HOME
1.1.1.22  root      503:        /* If not found in $HOME then look in current directory.  However,
                    504:         * don't use the optionsfile variable, so that we will save changes
                    505:         * to the home directory.  */
                    506:        char pwd_optionsfile[256];
1.1.1.3   root      507:        strcpy (optionsfile, OPTIONSFILENAME);
1.1.1.6   root      508:        cfgfile_load (&currprefs, optionsfile);
1.1.1.2   root      509: #endif
1.1.1.17  root      510:     }
1.1.1.2   root      511: 
1.1.1.6   root      512:     parse_cmdline (argc, argv);
1.1       root      513: }
                    514: 
1.1.1.4   root      515: void reset_all_systems (void)
                    516: {
1.1.1.14  root      517:     init_eventtab ();
                    518: 
                    519:     memory_reset ();
1.1.1.6   root      520:     bsdlib_reset ();
1.1.1.4   root      521:     filesys_reset ();
                    522:     filesys_start_threads ();
1.1.1.8   root      523:     scsidev_reset ();
                    524:     scsidev_start_threads ();
1.1.1.4   root      525: }
                    526: 
1.1.1.2   root      527: /* Okay, this stuff looks strange, but it is here to encourage people who
                    528:  * port UAE to re-use as much of this code as possible. Functions that you
                    529:  * should be using are do_start_program() and do_leave_program(), as well
                    530:  * as real_main(). Some OSes don't call main() (which is braindamaged IMHO,
                    531:  * but unfortunately very common), so you need to call real_main() from
                    532:  * whatever entry point you have. You may want to write your own versions
                    533:  * of start_program() and leave_program() if you need to do anything special.
                    534:  * Add #ifdefs around these as appropriate.
                    535:  */
                    536: 
1.1.1.4   root      537: void do_start_program (void)
1.1.1.2   root      538: {
1.1.1.20  root      539:     if (quit_program == -1)
                    540:        return;
                    541:     inputdevice_updateconfig (&currprefs);
                    542: 
1.1.1.3   root      543:     /* Do a reset on startup. Whether this is elegant is debatable. */
1.1.1.20  root      544:     if (quit_program >= 0)
                    545:        quit_program = 2;
1.1.1.4   root      546:     m68k_go (1);
1.1.1.2   root      547: }
                    548: 
1.1.1.4   root      549: void do_leave_program (void)
1.1.1.2   root      550: {
1.1.1.4   root      551:     graphics_leave ();
1.1.1.20  root      552:     inputdevice_close ();
1.1.1.4   root      553:     close_sound ();
                    554:     dump_counts ();
                    555:     serial_exit ();
                    556:     zfile_exit ();
                    557:     if (! no_gui)
                    558:        gui_exit ();
1.1.1.15  root      559: #ifdef USE_SDL
                    560:     SDL_Quit ();
                    561: #endif
                    562:     expansion_cleanup ();
                    563:     memory_cleanup ();
1.1.1.2   root      564: }
                    565: 
1.1.1.4   root      566: void start_program (void)
1.1.1.2   root      567: {
1.1.1.4   root      568:     do_start_program ();
1.1.1.2   root      569: }
                    570: 
1.1.1.4   root      571: void leave_program (void)
1.1.1.2   root      572: {
1.1.1.4   root      573:     do_leave_program ();
1.1.1.2   root      574: }
                    575: 
1.1.1.4   root      576: void real_main (int argc, char **argv)
1.1       root      577: {
                    578:     FILE *hf;
                    579: 
1.1.1.15  root      580: #ifdef USE_SDL
                    581:     SDL_Init (SDL_INIT_EVERYTHING | SDL_INIT_NOPARACHUTE);
                    582: #endif
                    583: 
1.1.1.6   root      584:     default_prefs (&currprefs);
1.1.1.20  root      585: 
1.1.1.22  root      586: #ifdef SYSTEM_CFGDIR
                    587:     scan_configs (SYSTEM_CFGDIR);
                    588: #endif
                    589: 
                    590:     /* Can be overriden in graphics_setup, although there's not much of a
                    591:        point.  Fullscreen modes are filled in by graphics_setup.  */
                    592:     gfx_windowed_modes = default_windowed_modes;
                    593:     n_windowed_modes = sizeof default_windowed_modes / sizeof *default_windowed_modes;
                    594: 
1.1.1.4   root      595:     if (! graphics_setup ()) {
                    596:        exit (1);
1.1       root      597:     }
1.1.1.2   root      598: 
1.1       root      599:     rtarea_init ();
                    600:     hardfile_install ();
1.1.1.8   root      601:     scsidev_install ();
1.1       root      602: 
1.1.1.4   root      603:     parse_cmdline_and_init_file (argc, argv);
1.1.1.2   root      604: 
1.1.1.4   root      605:     machdep_init ();
1.1.1.21  root      606:     init_gtod ();
1.1.1.3   root      607: 
1.1.1.4   root      608:     if (! setup_sound ()) {
1.1.1.16  root      609:        write_log ("Sound driver unavailable: Sound output disabled\n");
1.1.1.3   root      610:        currprefs.produce_sound = 0;
1.1       root      611:     }
1.1.1.20  root      612:     inputdevice_init ();
1.1       root      613: 
1.1.1.15  root      614:     changed_prefs = currprefs;
1.1.1.6   root      615:     no_gui = ! currprefs.start_gui;
1.1.1.4   root      616:     if (! no_gui) {
1.1.1.22  root      617:        int err = gui_init (1);
1.1.1.15  root      618:        currprefs = changed_prefs;
1.1.1.2   root      619:        if (err == -1) {
1.1.1.16  root      620:            write_log ("Failed to initialize the GUI\n");
1.1.1.2   root      621:        } else if (err == -2) {
1.1.1.4   root      622:            exit (0);
1.1.1.2   root      623:        }
1.1       root      624:     }
1.1.1.13  root      625:     if (sound_available && currprefs.produce_sound > 1 && ! init_audio ()) {
1.1.1.16  root      626:        write_log ("Sound driver unavailable: Sound output disabled\n");
1.1.1.3   root      627:        currprefs.produce_sound = 0;
                    628:     }
1.1.1.2   root      629: 
1.1.1.22  root      630:     fixup_prefs (&currprefs);
1.1.1.3   root      631:     changed_prefs = currprefs;
                    632: 
1.1.1.22  root      633: #ifdef SYSTEM_ROMDIR
                    634:     scan_roms (SYSTEM_ROMDIR, ROMLOC_SYSTEM);
                    635: #endif
                    636:     scan_roms (currprefs.path_rom, ROMLOC_USER);
1.1.1.2   root      637:     /* Install resident module to get 8MB chipmem, if requested */
1.1.1.4   root      638:     rtarea_setup ();
1.1.1.3   root      639: 
1.1.1.4   root      640:     keybuf_init (); /* Must come after init_joystick */
1.1.1.3   root      641: 
1.1       root      642:     expansion_init ();
1.1.1.4   root      643:     memory_init ();
                    644: 
                    645:     filesys_install ();
1.1.1.22  root      646:     bsdlib_install ();
1.1.1.4   root      647:     emulib_install ();
                    648:     uaeexe_install ();
1.1.1.8   root      649:     native2amiga_install ();
1.1.1.4   root      650: 
                    651:     custom_init (); /* Must come after memory_init */
                    652:     serial_init ();
                    653:     DISK_init ();
                    654: 
                    655:     reset_frame_rate_hack ();
                    656:     init_m68k(); /* must come after reset_frame_rate_hack (); */
1.1       root      657: 
1.1.1.4   root      658:     gui_update ();
1.1.1.2   root      659: 
1.1.1.3   root      660:     if (graphics_init ()) {
1.1.1.22  root      661:        reset_drawing ();
1.1.1.3   root      662:        setup_brkhandler ();
1.1.1.6   root      663:        if (currprefs.start_debugger && debuggable ())
1.1.1.3   root      664:            activate_debugger ();
                    665: 
                    666:        start_program ();
1.1       root      667:     }
1.1.1.3   root      668:     leave_program ();
1.1.1.2   root      669: }
                    670: 
1.1.1.21  root      671: void uae_abort (const char *msg)
                    672: {
                    673:     write_log ("%s", msg);
                    674:     abort ();
                    675: }
                    676: 
1.1.1.3   root      677: #ifndef NO_MAIN_IN_MAIN_C
1.1.1.4   root      678: int main (int argc, char **argv)
1.1.1.2   root      679: {
1.1.1.4   root      680:     real_main (argc, argv);
1.1       root      681:     return 0;
                    682: }
1.1.1.3   root      683: #endif

unix.superglobalmegacorp.com

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