source: buchla-emu/emu/main.c@ 77d8df8

Last change on this file since 77d8df8 was 77d8df8, checked in by Alexander Heinrich <alex.heinrich@…>, 6 years ago

Add CLI option for selecting MIDI ports.

  • Property mode set to 100644
File size: 4.0 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.txt" in the top directory of this repository.
16 */
17
18#include <all.h>
19
20typedef struct {
21 const char *name;
22 int32_t *flag;
23} verb_flag_t;
24
25static verb_flag_t verb_flags[] = {
26 { "sdl", &sdl_verbose },
27 { "gdb", &gdb_verbose },
28 { "cpu", &cpu_verbose },
29 { "fpu", &fpu_verbose },
30 { "vid", &vid_verbose },
31 { "tim", &tim_verbose },
32 { "lcd", &lcd_verbose },
33 { "ser", &ser_verbose },
34 { "mid", &mid_verbose },
35 { "fdd", &fdd_verbose },
36 { "snd", &snd_verbose },
37 { "led", &led_verbose },
38 { "kbd", &kbd_verbose }
39};
40
41const char *bios = "bios.abs";
42const char *disk = "buchla.disk";
43const char *font = "ttf/vera-sans-mono.ttf";
44
45SDL_atomic_t run;
46
47uint32_t mid_port = 0;
48
49static void usage(FILE *fh)
50{
51 fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font] [-m midiport] \n");
52 fprintf(fh, "where comp is one of: ");
53
54 for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
55 fprintf(fh, "%s, ", verb_flags[i].name);
56 }
57
58 fprintf(fh, "all\n");
59 fprintf(fh, "and midiport is the number of the desired MIDI port\n");
60 fprintf(fh, "list all available MIDI ports with: buchla [-m list]\n");
61}
62
63static void parse_args(int32_t argc, char *argv[])
64{
65 for (int32_t i = 0; i < argc; ++i) {
66 if (strcmp(argv[i], "-h") == 0) {
67 usage(stdout);
68 exit(0);
69 }
70
71 if (strcmp(argv[i], "-b") == 0) {
72 if (++i == argc) {
73 usage(stderr);
74 fprintf(stderr, "missing argument to -b\n");
75 exit(1);
76 }
77
78 bios = argv[i];
79 continue;
80 }
81
82 if (strcmp(argv[i], "-d") == 0) {
83 if (++i == argc) {
84 usage(stderr);
85 fprintf(stderr, "missing argument to -d\n");
86 exit(1);
87 }
88
89 disk = argv[i];
90 continue;
91 }
92
93 if (strcmp(argv[i], "-f") == 0) {
94 if (++i == argc) {
95 usage(stderr);
96 fprintf(stderr, "missing argument to -f\n");
97 exit(1);
98 }
99
100 font = argv[i];
101 continue;
102 }
103
104 if (strcmp(argv[i], "-v") == 0) {
105 if (++i == argc) {
106 usage(stderr);
107 fprintf(stderr, "missing argument to -v\n");
108 exit(1);
109 }
110
111 int32_t k;
112
113 if (strcmp(argv[i], "all") == 0) {
114 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
115 ++*verb_flags[k].flag;
116 }
117
118 continue;
119 }
120
121 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
122 if (strcmp(argv[i], verb_flags[k].name) == 0) {
123 ++*verb_flags[k].flag;
124 break;
125 }
126 }
127
128 if (k == ARRAY_COUNT(verb_flags)) {
129 usage(stderr);
130 fprintf(stderr, "invalid argument to -v: %s\n", argv[i]);
131 exit(1);
132 }
133
134 continue;
135 }
136
137 if (strcmp(argv[i], "-m") == 0) {
138 if (++i == argc) {
139 usage(stderr);
140 fprintf(stderr, "missing argument to -m\n");
141 exit(1);
142 }
143
144 if (strcmp(argv[i], "list") == 0) {
145 mid_list();
146 exit(0);
147 continue;
148 }
149
150 // TODO: Assign midi port number
151 mid_port = (uint32_t) atoi(argv[i]);
152 continue;
153 }
154 }
155}
156
157static int32_t cpu_thread(void *data)
158{
159 (void)data;
160
161 cpu_loop();
162 return 0;
163}
164
165static int32_t gdb_thread(void *data)
166{
167 (void)data;
168
169 gdb_loop();
170 return 0;
171}
172
173int32_t main(int32_t argc, char *argv[])
174{
175 parse_args(argc, argv);
176 sdl_init();
177 gdb_init();
178 cpu_init();
179
180 SDL_AtomicSet(&run, 1);
181 SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
182
183 if (thr_cpu == NULL) {
184 fail("SDL_CreateThread() failed: %s", SDL_GetError());
185 }
186
187 SDL_Thread *thr_gdb = SDL_CreateThread(gdb_thread, "gdb", NULL);
188
189 if (thr_gdb == NULL) {
190 fail("SDL_CreateThread() failed: %s", SDL_GetError());
191 }
192
193 sdl_loop();
194
195 SDL_WaitThread(thr_cpu, NULL);
196 SDL_WaitThread(thr_gdb, NULL);
197
198 cpu_quit();
199 gdb_quit();
200 sdl_quit();
201 return 0;
202}
Note: See TracBrowser for help on using the repository browser.