--- uae/src/main.c 2018/04/24 16:38:39 1.1 +++ uae/src/main.c 2018/04/24 16:39:02 1.1.1.2 @@ -12,9 +12,12 @@ #include "config.h" #include "options.h" +#include "uae.h" +#include "events.h" #include "memory.h" #include "custom.h" #include "serial.h" +#include "readcpu.h" #include "newcpu.h" #include "disk.h" #include "debug.h" @@ -24,6 +27,7 @@ #include "gui.h" #include "zfile.h" #include "autoconf.h" +#include "osemu.h" #include "compiler.h" int version = 100*UAEMAJOR + 10*UAEMINOR + UAEURSAMINOR; @@ -32,21 +36,28 @@ int use_debugger = 0; int illegal_mem = 0; int use_gfxlib = 0; int no_xhair = 0; -int use_lores = 0; int use_serial = 0; int automount_uaedev = 1; int produce_sound = 0; int fake_joystick = 0; KbdLang keyboard_lang = KBD_LANG_US; -int screen_res = 4; int correct_aspect = 0; int color_mode = 0; int sound_desired_bits = 16; +#ifdef AMIGA +int sound_desired_freq = 11025; +#else int sound_desired_freq = 44100; +#endif int sound_desired_bsiz = 8192; int allow_save = 0; int no_gui = 0; - +int emul_accuracy = 2; +int test_drawing_speed = 0; +int gfx_requested_width = 800, gfx_requested_height = 600, gfx_requested_lores = 0; +int gfx_requested_linedbl = 0, gfx_requested_correct_aspect = 0; +int gfx_requested_xcenter = 0, gfx_requested_ycenter = 0; +int immediate_blits = 0, blits_32bit_enabled = 0; long hardfile_size = 0; ULONG fastmem_size = 0x000000; @@ -67,62 +78,106 @@ char optionsfile[256]; * The printer support was only tested with the driver "PostScript" on * Amiga side, using apsfilter for linux to print ps-data. * - * Note for the DOS-Port: Maybe it's only neccesary to use a - * -p LPT1: or -p PRN: to print in a DOSBOX. I don't know, - * I do not use DOS... (please try) -=SR=- + * Under DOS it ought to be -p LPT1: or -p PRN: but you'll need a + * PostScript printer or ghostscript -=SR=- */ /* People must provide their own name for this */ char sername[256] = ""; -/* And again: Serial lines work under Linux. I don't know - * how this behaves in other OSes. This is work for the porting - * people -=SR=- - */ +static void fix_options(void) +{ +} void usage(void) { printf("UAE - The Un*x Amiga emulator\n"); printf("Summary of command-line options:\n"); - printf(" -h : Print help\n"); - printf(" -m VOLNAME:mount_point : mount file system at as AmigaDOS\n" - " volume VOLNAME:\n"); - printf(" -M VOLNAME:mount_point : like -m, but mount read-only\n"); - printf(" -s n : Emulate n*256 KB slow memory at 0xC00000\n"); - printf(" -c n : Emulate n*512 KB chip memory at 0x000000\n"); - printf(" -F n : Emulate n MB fast memory at 0x200000\n"); - printf(" -a : Add no expansion devices (disables fastmem and\n" - " harddisk support.\n"); - printf(" -J : Fake joystick emulation with the numeric pad.\n"); - printf(" -f n : Set the frame rate to 1/n\n"); - printf(" -D : Start up the built-in debugger\n"); - printf(" -i : Print illegal memory accesses\n"); - printf(" -o : Allow options to be saved\n"); - printf(" -G : Disable user interface\n"); - printf(" -[0123] file : Use file instead of df[0123].adf as disk image.e\n"); - printf(" -r file : Use file as ROM image instead of kick.rom\n"); + printf(" -h : Print help\n"); + printf(" -m VOL:dir : mount directory called as AmigaDOS volume VOL:\n"); + printf(" -M VOL:dir : like -m, but mount read-only\n"); + printf(" -s n : Emulate n*256 KB slow memory at 0xC00000\n"); + printf(" -c n : Emulate n*512 KB chip memory at 0x000000\n"); + printf(" -F n : Emulate n MB fast memory at 0x200000\n"); + printf(" -a : Add no expansion devices (disables fastmem and\n" + " harddisk support\n"); + printf(" -J : Fake joystick emulation with the numeric pad\n"); + printf(" -f n : Set the frame rate to 1/n\n"); + printf(" -D : Start up the built-in debugger\n"); + printf(" -i : Print illegal memory accesses\n"); + printf(" -o : Allow options to be saved\n"); + printf(" -G : Disable user interface\n"); + printf(" -A n : Set emulator accuracy to n (0, 1 or 2)\n"); + printf(" -[0123] file : Use file instead of df[0123].adf as disk image\n"); + printf(" -r file : Use file as ROM image instead of kick.rom\n"); target_specific_usage(); -/* printf(" -g : Turn on gfx-lib replacement (EXPERIMENTAL).\n");*/ - printf(" -d mode : Select resolution with the mode parameter.\n"); - printf(" -H mode : Set the number of colors with the mode parameter.\n"); - printf(" -C : Use correct aspect display mode.\n"); - printf("\n"); - printf("Valid resolutions: 0 (320x200); 1 (320x240); 2 (320x400); 3 (640x480);\n" - " 4 (800x600)\n" +/* printf(" -g : Turn on gfx-lib replacement (EXPERIMENTAL).\n");*/ +/* printf(" -d mode : OBSOLETE: Use \"-O\".\n"); + printf(" -C : OBSOLETE: use \"-O\"\n"); */ + printf(" -n parms : Set blitter parameters: 'i' enables immediate blits,\n" + " '3' enables 32 bit blits (may crash RISC machines)\n"); + printf(" -O modespec : Define graphics mode (see below).\n"); + printf(" -H mode : Set the color mode (see below).\n"); + printf("\n" "Valid color modes: 0 (256 colors); 1 (32768 colors); 2 (65536 colors)\n" " 3 (256 colors, with dithering for better results)\n" " 4 (16 colors, dithered); 5 (16 million colors)\n" - "UAE may choose to ignore the color mode/resolution setting.\n"); + "The format for the modespec parameter of \"-O\" is as follows:\n" + " -O width:height:modifiers\n" + " \"width\" and \"height\" specify the dimensions of the picture.\n" + " \"modifiers\" is a string that contains zero or more of the following\n" + " characters:\n" + " l: Treat the display as lores, drawing only every second pixel\n" + " x, y: Center the screen horizontally or vertically.\n" + " d: Draw every line twice unless in interlace: this doubles the height\n" + " of the display (this is the old -C parameter).\n" + " c: Correct aspect ratio (this is _not_ the old -C parameter).\n" + "UAE may choose to ignore the color mode setting and/or adjust the\n" + "video mode setting to reasonable values.\n"); } -#ifdef __unix +static void parse_gfx_specs (char *spec) +{ + char *x0 = my_strdup (spec); + char *x1, *x2; + + x1 = strchr (x0, ':'); + if (x1 == 0) + goto argh; + x2 = strchr (x1+1, ':'); + if (x2 == 0) + goto argh; + *x1++ = 0; *x2++ = 0; + + gfx_requested_width = atoi (x0); + gfx_requested_height = atoi (x1); + gfx_requested_lores = strchr (x2, 'l') != 0; + gfx_requested_xcenter = strchr (x2, 'x') != 0 ? 1 : strchr (x2, 'X') != 0 ? 2 : 0; + gfx_requested_ycenter = strchr (x2, 'y') != 0 ? 1 : strchr (x2, 'Y') != 0 ? 2 : 0; + gfx_requested_linedbl = strchr (x2, 'd') != 0; + gfx_requested_correct_aspect = strchr (x2, 'c') != 0; + + free (x0); + return; + + argh: + fprintf (stderr, "Bad display mode specification.\n"); + fprintf (stderr, "The format to use is: \"width:height:modifiers\"\n"); + free (x0); +} + +#if defined(__unix)||defined(AMIGA) void parse_cmdline(int argc, char **argv) { int c; extern char *optarg; - - while(((c = getopt(argc, argv, "l:Dif:gd:hxF:as:c:S:Jm:M:0:1:2:3:r:H:p:CI:b:R:B:oG")) != EOF)) +#ifdef __BEOS__ + if (argc < 2) + return; +#endif + /* Help! We're running out of letters! */ + while(((c = getopt(argc, argv, "l:Dif:gd:hxF:as:c:S:Jm:M:0:1:2:3:r:H:p:C:I:b:R:B:oGA:tO:n:")) != EOF)) switch(c) { case 'h': usage(); exit(0); @@ -161,15 +216,32 @@ void parse_cmdline(int argc, char **argv case 'S': produce_sound = atoi(optarg); break; case 'f': framerate = atoi(optarg); break; + case 'A': emul_accuracy = atoi(optarg); break; case 'x': no_xhair = 1; break; case 'D': use_debugger = 1; break; case 'i': illegal_mem = 1; break; case 'J': fake_joystick = 1; break; case 'a': automount_uaedev = 0; break; case 'g': use_gfxlib = 1; break; - case 'C': correct_aspect = 1; break; case 'o': allow_save = 1; break; case 'G': no_gui = 1; break; + case 't': test_drawing_speed = 1; break; + + case 'n': + if (strchr (optarg, '3') != 0) + blits_32bit_enabled = 1; + if (strchr (optarg, 'i') != 0) + immediate_blits = 0; + break; + + case 'C': + fprintf (stderr, "The -C option is obsolete, please use -O.\n"); + correct_aspect = atoi(optarg); + if (correct_aspect < 0 || correct_aspect > 2) { + fprintf(stderr, "Bad parameter for -C !\n"); + correct_aspect = 0; + } + break; case 'F': fastmem_size = atoi(optarg) * 0x100000; @@ -194,7 +266,8 @@ void parse_cmdline(int argc, char **argv case 'c': chipmem_size = atoi(optarg) * 0x80000; if (chipmem_size != 0x80000 && chipmem_size != 0x100000 - && chipmem_size != 0x200000) + && chipmem_size != 0x200000 && chipmem_size != 0x400000 + && chipmem_size != 0x800000) { chipmem_size = 0x200000; fprintf(stderr, "Unsupported chipmem size!\n"); @@ -213,13 +286,33 @@ void parse_cmdline(int argc, char **argv keyboard_lang = KBD_LANG_FR; else if (0 == strcasecmp(optarg, "it")) keyboard_lang = KBD_LANG_IT; + else if (0 == strcasecmp(optarg, "es")) + keyboard_lang = KBD_LANG_ES; break; + case 'O': parse_gfx_specs (optarg); break; case 'd': - screen_res = atoi(optarg); - if (screen_res < 0 || screen_res > MAX_SCREEN_MODES) { + fprintf (stderr, "Note: The -d option is obsolete, please use the new -O format.\n"); + c = atoi(optarg); + switch (c) { + case 0: + parse_gfx_specs("320:200:lx"); + break; + case 1: + parse_gfx_specs("320:240:lx"); + break; + case 2: + parse_gfx_specs("320:400:lx"); + break; + case 3: + parse_gfx_specs("640:300:x"); + break; + default: fprintf(stderr, "Bad video mode selected. Using default.\n"); - screen_res = 3; + /* fall through */ + case 4: + parse_gfx_specs("800:600:"); + break; } break; @@ -238,8 +331,6 @@ void parse_cmdline(int argc, char **argv } #endif -#ifndef __bebox__ /* BeOS needs its own startup code */ - static void parse_cmdline_and_init_file(int argc, char **argv) { FILE *f; @@ -268,7 +359,14 @@ static void parse_cmdline_and_init_file( strcat(optionsfile, "uae.rc"); #endif - f = fopen(optionsfile,"r"); + f = fopen(optionsfile,"rb"); +#ifndef __DOS__ +/* sam: if not found in $HOME then look in current directory */ + if (f == NULL) { + f = fopen(".uaerc","rb"); + } +#endif + if (f == NULL) { parse_cmdline(argc, argv); return; @@ -330,72 +428,124 @@ static void parse_cmdline_and_init_file( parse_cmdline(new_argc, new_argv); } -static int ARE_YOU_NUTS = 0; +#define ARE_YOU_NUTS 0 -int main(int argc, char **argv) +/* Okay, this stuff looks strange, but it is here to encourage people who + * port UAE to re-use as much of this code as possible. Functions that you + * should be using are do_start_program() and do_leave_program(), as well + * as real_main(). Some OSes don't call main() (which is braindamaged IMHO, + * but unfortunately very common), so you need to call real_main() from + * whatever entry point you have. You may want to write your own versions + * of start_program() and leave_program() if you need to do anything special. + * Add #ifdefs around these as appropriate. + */ + +void do_start_program(void) +{ +#ifdef USE_EXECLIB + if (ARE_YOU_NUTS && use_gfxlib) + execlib_sysinit(); + else +#endif + m68k_go(1); +} + +void do_leave_program(void) +{ + graphics_leave(); + close_joystick(); + dump_counts(); + serial_exit(); + zfile_exit(); + if (!no_gui) + gui_exit(); +} + +void start_program(void) +{ + do_start_program(); +} + +void leave_program(void) +{ + do_leave_program(); +} + +void real_main(int argc, char **argv) { FILE *hf; hf = fopen("hardfile", "rb"); if (hf == NULL) - hardfile_size = 0; + hardfile_size = 0; else { - fseek(hf, 0, SEEK_END); - hardfile_size = ftell(hf); - fclose(hf); + fseek(hf, 0, SEEK_END); + hardfile_size = ftell(hf); + fclose(hf); } + rtarea_init (); hardfile_install (); parse_cmdline_and_init_file(argc, argv); + if (!init_sound()) { fprintf(stderr, "Sound driver unavailable: Sound output disabled\n"); produce_sound = 0; } + init_joystick(); - if (!no_gui && gui_init() < 0) { - fprintf(stderr, "Failed to initialize the GUI\n"); - /* abort()? Maybe. */ + if (!no_gui) { + int err = gui_init(); + if (err == -1) { + fprintf(stderr, "Failed to initialize the GUI\n"); + } else if (err == -2) { + exit(0); + } } - init_joystick(); + + fix_options(); + + /* Install resident module to get 8MB chipmem, if requested */ + rtarea_setup(); + keybuf_init(); expansion_init (); memory_init(); filesys_install(); +#ifdef USE_EXECLIB execlib_install(); +#endif gfxlib_install(); emulib_install(); + trackdisk_install(); custom_init(); serial_init(); DISK_init(); init_m68k(); compiler_init(); - - /* We ought to know this by now */ - use_lores = screen_res < 3; + gui_update(); if (graphics_init()) { + customreset(); m68k_reset(); setup_brkhandler(); if (use_debugger && debuggable()) activate_debugger(); - if (ARE_YOU_NUTS) - execlib_sysinit(); - else - m68k_go(1); - - graphics_leave(); - close_joystick(); + + start_program(); } - dump_counts(); - serial_exit(); - zfile_exit(); - if (!no_gui) - gui_exit(); + leave_program(); +} + +#ifndef __BEOS__ /* BeOS needs its own startup code */ +int main(int argc, char **argv) +{ + real_main(argc, argv); return 0; } -#endif /* not __bebox__ */ +#endif /* not __BEOS__ */