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

Last change on this file since c9d372a was 0edef06, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Configurable font file.

  • Property mode set to 100644
File size: 3.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.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
47static void usage(FILE *fh)
48{
49 fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font]\n");
50 fprintf(fh, "where comp is one of: ");
51
52 for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
53 fprintf(fh, "%s, ", verb_flags[i].name);
54 }
55
56 fprintf(fh, "all\n");
57}
58
59static void parse_args(int32_t argc, char *argv[])
60{
61 for (int32_t i = 0; i < argc; ++i) {
62 if (strcmp(argv[i], "-h") == 0) {
63 usage(stdout);
64 exit(0);
65 }
66
67 if (strcmp(argv[i], "-b") == 0) {
68 if (++i == argc) {
69 usage(stderr);
70 fprintf(stderr, "missing argument to -b\n");
71 exit(1);
72 }
73
74 bios = argv[i];
75 continue;
76 }
77
78 if (strcmp(argv[i], "-d") == 0) {
79 if (++i == argc) {
80 usage(stderr);
81 fprintf(stderr, "missing argument to -d\n");
82 exit(1);
83 }
84
85 disk = argv[i];
86 continue;
87 }
88
89 if (strcmp(argv[i], "-f") == 0) {
90 if (++i == argc) {
91 usage(stderr);
92 fprintf(stderr, "missing argument to -f\n");
93 exit(1);
94 }
95
96 font = argv[i];
97 continue;
98 }
99
100 if (strcmp(argv[i], "-v") == 0) {
101 if (++i == argc) {
102 usage(stderr);
103 fprintf(stderr, "missing argument to -v\n");
104 exit(1);
105 }
106
107 int32_t k;
108
109 if (strcmp(argv[i], "all") == 0) {
110 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
111 ++*verb_flags[k].flag;
112 }
113
114 continue;
115 }
116
117 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
118 if (strcmp(argv[i], verb_flags[k].name) == 0) {
119 ++*verb_flags[k].flag;
120 break;
121 }
122 }
123
124 if (k == ARRAY_COUNT(verb_flags)) {
125 usage(stderr);
126 fprintf(stderr, "invalid argument to -v: %s\n", argv[i]);
127 exit(1);
128 }
129
130 continue;
131 }
132 }
133}
134
135static int32_t cpu_thread(void *data)
136{
137 (void)data;
138
139 cpu_loop();
140 return 0;
141}
142
143static int32_t gdb_thread(void *data)
144{
145 (void)data;
146
147 gdb_loop();
148 return 0;
149}
150
151int32_t main(int32_t argc, char *argv[])
152{
153 parse_args(argc, argv);
154 sdl_init();
155 gdb_init();
156 cpu_init();
157
158 SDL_AtomicSet(&run, 1);
159 SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
160
161 if (thr_cpu == NULL) {
162 fail("SDL_CreateThread() failed: %s", SDL_GetError());
163 }
164
165 SDL_Thread *thr_gdb = SDL_CreateThread(gdb_thread, "gdb", NULL);
166
167 if (thr_gdb == NULL) {
168 fail("SDL_CreateThread() failed: %s", SDL_GetError());
169 }
170
171 sdl_loop();
172
173 SDL_WaitThread(thr_cpu, NULL);
174 SDL_WaitThread(thr_gdb, NULL);
175
176 cpu_quit();
177 gdb_quit();
178 sdl_quit();
179 return 0;
180}
Note: See TracBrowser for help on using the repository browser.