Mercurial > repos > blastem
comparison blastem.c @ 469:5f3344d0d42f
Fix argument handling so that the rom filename does not need to be specified first
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 11 Sep 2013 19:26:35 -0700 |
parents | 140af5509ce7 |
children | 541c1ae8abf3 |
comparison
equal
deleted
inserted
replaced
468:949c7d875693 | 469:5f3344d0d42f |
---|---|
1 /* | 1 /* |
2 Copyright 2013 Michael Pavone | 2 Copyright 2013 Michael Pavone |
3 This file is part of BlastEm. | 3 This file is part of BlastEm. |
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. | 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
5 */ | 5 */ |
6 #include "68kinst.h" | 6 #include "68kinst.h" |
7 #include "m68k_to_x86.h" | 7 #include "m68k_to_x86.h" |
8 #include "z80_to_x86.h" | 8 #include "z80_to_x86.h" |
1729 } | 1729 } |
1730 | 1730 |
1731 int main(int argc, char ** argv) | 1731 int main(int argc, char ** argv) |
1732 { | 1732 { |
1733 if (argc < 2) { | 1733 if (argc < 2) { |
1734 fputs("Usage: blastem ROMFILE [OPTIONS] [WIDTH] [HEIGHT]\n", stderr); | 1734 fputs("Usage: blastem [OPTIONS] ROMFILE [WIDTH] [HEIGHT]\n", stderr); |
1735 return 1; | 1735 return 1; |
1736 } | 1736 } |
1737 config = load_config(argv[0]); | 1737 config = load_config(argv[0]); |
1738 detect_region(); | 1738 detect_region(); |
1739 int width = -1; | 1739 int width = -1; |
1740 int height = -1; | 1740 int height = -1; |
1741 int debug = 0; | 1741 int debug = 0; |
1742 int ym_log = 0; | 1742 int ym_log = 0; |
1743 int loaded = 0; | 1743 int loaded = 0; |
1744 uint8_t force_version = 0; | |
1745 char * romfname = NULL; | |
1744 FILE *address_log = NULL; | 1746 FILE *address_log = NULL; |
1745 char * statefile = NULL; | 1747 char * statefile = NULL; |
1746 uint8_t fullscreen = 0; | 1748 uint8_t fullscreen = 0; |
1747 for (int i = 1; i < argc; i++) { | 1749 for (int i = 1; i < argc; i++) { |
1748 if (argv[i][0] == '-') { | 1750 if (argv[i][0] == '-') { |
1771 } | 1773 } |
1772 switch (argv[i][0]) | 1774 switch (argv[i][0]) |
1773 { | 1775 { |
1774 case 'j': | 1776 case 'j': |
1775 case 'J': | 1777 case 'J': |
1776 version_reg = NO_DISK | JAP; | 1778 force_version = NO_DISK | JAP; |
1777 break; | 1779 break; |
1778 case 'u': | 1780 case 'u': |
1779 case 'U': | 1781 case 'U': |
1780 version_reg = NO_DISK | USA; | 1782 force_version = NO_DISK | USA; |
1781 break; | 1783 break; |
1782 case 'e': | 1784 case 'e': |
1783 case 'E': | 1785 case 'E': |
1784 version_reg = NO_DISK | EUR; | 1786 force_version = NO_DISK | EUR; |
1785 break; | 1787 break; |
1786 default: | 1788 default: |
1787 fprintf(stderr, "'%c' is not a valid region character for the -r option\n", argv[i][0]); | 1789 fprintf(stderr, "'%c' is not a valid region character for the -r option\n", argv[i][0]); |
1788 return 1; | 1790 return 1; |
1789 } | 1791 } |
1799 case 'y': | 1801 case 'y': |
1800 ym_log = 1; | 1802 ym_log = 1; |
1801 break; | 1803 break; |
1802 case 'h': | 1804 case 'h': |
1803 puts( | 1805 puts( |
1804 "Usage: blastem ROMFILE [OPTIONS] [WIDTH] [HEIGHT]\n" | 1806 "Usage: blastem [OPTIONS] ROMFILE [WIDTH] [HEIGHT]\n" |
1805 "Options:\n" | 1807 "Options:\n" |
1806 " -h Print this help text\n" | 1808 " -h Print this help text\n" |
1807 " -r (J|U|E) Force region to Japan, US or Europe respectively\n" | 1809 " -r (J|U|E) Force region to Japan, US or Europe respectively\n" |
1808 " -f Start in fullscreen mode\n" | 1810 " -f Start in fullscreen mode\n" |
1809 " -s FILE Load a GST format savestate from FILE\n" | 1811 " -s FILE Load a GST format savestate from FILE\n" |
1818 fprintf(stderr, "Unrecognized switch %s\n", argv[i]); | 1820 fprintf(stderr, "Unrecognized switch %s\n", argv[i]); |
1819 return 1; | 1821 return 1; |
1820 } | 1822 } |
1821 } else if (!loaded) { | 1823 } else if (!loaded) { |
1822 if(!load_rom(argv[i])) { | 1824 if(!load_rom(argv[i])) { |
1823 fprintf(stderr, "Failed to open %s for reading\n", argv[1]); | 1825 fprintf(stderr, "Failed to open %s for reading\n", argv[i]); |
1824 return 1; | 1826 return 1; |
1825 } | 1827 } |
1828 romfname = argv[i]; | |
1826 loaded = 1; | 1829 loaded = 1; |
1827 } else if (width < 0) { | 1830 } else if (width < 0) { |
1828 width = atoi(argv[i]); | 1831 width = atoi(argv[i]); |
1829 } else if (height < 0) { | 1832 } else if (height < 0) { |
1830 height = atoi(argv[i]); | 1833 height = atoi(argv[i]); |
1831 } | 1834 } |
1832 } | 1835 } |
1833 if (!loaded) { | 1836 if (!loaded) { |
1834 fputs("You must specify a ROM filename!\n", stderr); | 1837 fputs("You must specify a ROM filename!\n", stderr); |
1835 return 1; | 1838 return 1; |
1839 } | |
1840 if (force_version) { | |
1841 version_reg = force_version; | |
1836 } | 1842 } |
1837 update_title(); | 1843 update_title(); |
1838 int def_width = 0; | 1844 int def_width = 0; |
1839 char *config_width = tern_find_ptr(config, "videowidth"); | 1845 char *config_width = tern_find_ptr(config, "videowidth"); |
1840 if (config_width) { | 1846 if (config_width) { |
1881 gen.vdp = &v_context; | 1887 gen.vdp = &v_context; |
1882 gen.ym = &y_context; | 1888 gen.ym = &y_context; |
1883 gen.psg = &p_context; | 1889 gen.psg = &p_context; |
1884 genesis = &gen; | 1890 genesis = &gen; |
1885 | 1891 |
1886 int fname_size = strlen(argv[1]); | 1892 int fname_size = strlen(romfname); |
1887 sram_filename = malloc(fname_size+6); | 1893 sram_filename = malloc(fname_size+6); |
1888 memcpy(sram_filename, argv[1], fname_size); | 1894 memcpy(sram_filename, romfname, fname_size); |
1889 int i; | 1895 int i; |
1890 for (i = fname_size-1; fname_size >= 0; --i) { | 1896 for (i = fname_size-1; fname_size >= 0; --i) { |
1891 if (sram_filename[i] == '.') { | 1897 if (sram_filename[i] == '.') { |
1892 strcpy(sram_filename + i + 1, "sram"); | 1898 strcpy(sram_filename + i + 1, "sram"); |
1893 break; | 1899 break; |