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

Last change on this file since e5a7d09 was 6027d76, checked in by Thomas Lopatic <thomas@…>, 6 years ago

Get rid of ttf subdirectory.

  • Property mode set to 100644
File size: 4.4 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 = "vera.ttf";
44
45uint32_t mid_port = 0;
46
47SDL_atomic_t run;
48
49static void usage(FILE *fh)
50{
51 fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font] [-m port]\n");
52 fprintf(fh, "with\n");
53 fprintf(fh, " comp - one of: ");
54
55 for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
56 fprintf(fh, "%s, ", verb_flags[i].name);
57 }
58
59 fprintf(fh, "all\n");
60 fprintf(fh, " bios - BIOS ROM file (default: bios.abs)\n");
61 fprintf(fh, " disk - disk image file (default: buchla.disk)\n");
62 fprintf(fh, " font - console and LCD font (default: vera.ttf)\n");
63 fprintf(fh, " port - number of the desired MIDI port (default: 0)\n");
64 fprintf(fh, " \"list\" instead of a port number lists available ports\n");
65}
66
67static void parse_args(int32_t argc, char *argv[])
68{
69 for (int32_t i = 0; i < argc; ++i) {
70 if (strcmp(argv[i], "-h") == 0) {
71 usage(stdout);
72 exit(0);
73 }
74
75 if (strcmp(argv[i], "-b") == 0) {
76 if (++i == argc) {
77 usage(stderr);
78 fprintf(stderr, "missing argument to -b\n");
79 exit(1);
80 }
81
82 bios = argv[i];
83 continue;
84 }
85
86 if (strcmp(argv[i], "-d") == 0) {
87 if (++i == argc) {
88 usage(stderr);
89 fprintf(stderr, "missing argument to -d\n");
90 exit(1);
91 }
92
93 disk = argv[i];
94 continue;
95 }
96
97 if (strcmp(argv[i], "-f") == 0) {
98 if (++i == argc) {
99 usage(stderr);
100 fprintf(stderr, "missing argument to -f\n");
101 exit(1);
102 }
103
104 font = argv[i];
105 continue;
106 }
107
108 if (strcmp(argv[i], "-v") == 0) {
109 if (++i == argc) {
110 usage(stderr);
111 fprintf(stderr, "missing argument to -v\n");
112 exit(1);
113 }
114
115 int32_t k;
116
117 if (strcmp(argv[i], "all") == 0) {
118 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
119 ++*verb_flags[k].flag;
120 }
121
122 continue;
123 }
124
125 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
126 if (strcmp(argv[i], verb_flags[k].name) == 0) {
127 ++*verb_flags[k].flag;
128 break;
129 }
130 }
131
132 if (k == ARRAY_COUNT(verb_flags)) {
133 usage(stderr);
134 fprintf(stderr, "invalid argument to -v: %s\n", argv[i]);
135 exit(1);
136 }
137
138 continue;
139 }
140
141 if (strcmp(argv[i], "-m") == 0) {
142 if (++i == argc) {
143 usage(stderr);
144 fprintf(stderr, "missing argument to -m\n");
145 exit(1);
146 }
147
148 if (strcmp(argv[i], "list") == 0) {
149 mid_list();
150 exit(0);
151 }
152
153 char *end;
154 int64_t tmp = strtol(argv[i], &end, 10);
155
156 if (*end != 0 || tmp < 0 || tmp > 15) {
157 usage(stderr);
158 fprintf(stderr, "invalid argument to -m: %s\n", argv[i]);
159 exit(1);
160 }
161
162 mid_port = (uint32_t)tmp;
163 continue;
164 }
165 }
166}
167
168static int32_t cpu_thread(void *data)
169{
170 (void)data;
171
172 cpu_loop();
173 return 0;
174}
175
176static int32_t gdb_thread(void *data)
177{
178 (void)data;
179
180 gdb_loop();
181 return 0;
182}
183
184int32_t main(int32_t argc, char *argv[])
185{
186 parse_args(argc, argv);
187 sdl_init();
188 gdb_init();
189 cpu_init();
190
191 SDL_AtomicSet(&run, 1);
192 SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
193
194 if (thr_cpu == NULL) {
195 fail("SDL_CreateThread() failed: %s", SDL_GetError());
196 }
197
198 SDL_Thread *thr_gdb = SDL_CreateThread(gdb_thread, "gdb", NULL);
199
200 if (thr_gdb == NULL) {
201 fail("SDL_CreateThread() failed: %s", SDL_GetError());
202 }
203
204 sdl_loop();
205
206 SDL_WaitThread(thr_cpu, NULL);
207 SDL_WaitThread(thr_gdb, NULL);
208
209 cpu_quit();
210 gdb_quit();
211 sdl_quit();
212 return 0;
213}
Note: See TracBrowser for help on using the repository browser.