source: buchla-emu/emu/main.c@ b909777

Last change on this file since b909777 was b909777, checked in by Thomas Lopatic <thomas@…>, 5 years ago

Parse command line options. Load BIOS file.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 * Copyright (C) 2017 The Contributors
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or (at
7 * your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * A copy of the GNU General Public License can be found in the file
15 * "gpl-v3.txt" in the top directory of this repository.
16 */
17
18#include <all.h>
19
20typedef struct {
21 const char *name;
22 bool *flag;
23} verb_flag_t;
24
25static verb_flag_t verb_flags[] = {
26 { "sdl", &sdl_verbose },
27 { "cpu", &cpu_verbose },
28 { "fpu", &fpu_verbose },
29 { "vid", &vid_verbose },
30 { "tim", &tim_verbose },
31 { "lcd", &lcd_verbose },
32 { "ser", &ser_verbose },
33 { "mid", &mid_verbose },
34 { "fdd", &fdd_verbose },
35 { "snd", &snd_verbose },
36 { "led", &led_verbose },
37 { "kbd", &kbd_verbose }
38};
39
40static const char *bios = "bios.abs";
41
42static void usage(FILE *fh)
43{
44 fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios]\n");
45 fprintf(fh, "where comp is one of: ");
46
47 for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
48 fprintf(fh, "%s, ", verb_flags[i].name);
49 }
50
51 fprintf(fh, "all\n");
52}
53
54static void parse_args(int32_t argc, char *argv[])
55{
56 for (int32_t i = 0; i < argc; ++i) {
57 if (strcmp(argv[i], "-h") == 0) {
58 usage(stdout);
59 exit(0);
60 }
61
62 if (strcmp(argv[i], "-b") == 0) {
63 if (++i == argc) {
64 usage(stderr);
65 fprintf(stderr, "missing argument to -b\n");
66 exit(1);
67 }
68
69 bios = argv[i];
70 continue;
71 }
72
73 if (strcmp(argv[i], "-v") == 0) {
74 if (++i == argc) {
75 usage(stderr);
76 fprintf(stderr, "missing argument to -v\n");
77 exit(1);
78 }
79
80 int32_t k;
81
82 if (strcmp(argv[i], "all") == 0) {
83 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
84 *verb_flags[k].flag = true;
85 }
86
87 continue;
88 }
89
90 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
91 if (strcmp(argv[i], verb_flags[k].name) == 0) {
92 *verb_flags[k].flag = true;
93 break;
94 }
95 }
96
97 if (k == ARRAY_COUNT(verb_flags)) {
98 usage(stderr);
99 fprintf(stderr, "invalid argument to -v: %s\n", argv[i]);
100 exit(1);
101 }
102
103 continue;
104 }
105 }
106}
107
108int32_t main(int32_t argc, char *argv[])
109{
110 parse_args(argc, argv);
111 sdl_init();
112
113 cpu_loop(bios);
114
115 sdl_quit();
116 return 0;
117}
Note: See TracBrowser for help on using the repository browser.