source: buchla-emu/emu/main.c

0.1
Last change on this file 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
RevLine 
[a06aa8b]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
[2147e53]15 * "gpl.txt" in the top directory of this repository.
[a06aa8b]16 */
17
[ff8d800]18#include <all.h>
[d54045b]19
[b909777]20typedef struct {
21 const char *name;
[4c71d39]22 int32_t *flag;
[b909777]23} verb_flag_t;
24
25static verb_flag_t verb_flags[] = {
26 { "sdl", &sdl_verbose },
[7cc6ac0]27 { "gdb", &gdb_verbose },
[b909777]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
[1efc42c]41const char *bios = "bios.abs";
42const char *disk = "buchla.disk";
[6027d76]43const char *font = "vera.ttf";
[b909777]44
[2cd18e3]45uint32_t mid_port = 0;
[bdd5a63]46
[9ddbf3e]47SDL_atomic_t run;
[77d8df8]48
[b909777]49static void usage(FILE *fh)
[d54045b]50{
[9ddbf3e]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: ");
[b909777]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");
[9ddbf3e]60 fprintf(fh, " bios - BIOS ROM file (default: bios.abs)\n");
61 fprintf(fh, " disk - disk image file (default: buchla.disk)\n");
[6027d76]62 fprintf(fh, " font - console and LCD font (default: vera.ttf)\n");
[9ddbf3e]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");
[b909777]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 }
[ff8d800]85
[1efc42c]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
[0edef06]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
[b909777]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) {
[4c71d39]119 ++*verb_flags[k].flag;
[b909777]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) {
[4c71d39]127 ++*verb_flags[k].flag;
[b909777]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 }
[77d8df8]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
[9ddbf3e]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
[2cd18e3]162 mid_port = (uint32_t)tmp;
[77d8df8]163 continue;
164 }
[b909777]165 }
166}
167
[bdd5a63]168static int32_t cpu_thread(void *data)
169{
170 (void)data;
171
172 cpu_loop();
173 return 0;
174}
175
[7cc6ac0]176static int32_t gdb_thread(void *data)
177{
178 (void)data;
179
180 gdb_loop();
181 return 0;
182}
183
[b909777]184int32_t main(int32_t argc, char *argv[])
185{
186 parse_args(argc, argv);
[ff8d800]187 sdl_init();
[7cc6ac0]188 gdb_init();
[bdd5a63]189 cpu_init();
[ff8d800]190
[bdd5a63]191 SDL_AtomicSet(&run, 1);
[7cc6ac0]192 SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
[bdd5a63]193
[7cc6ac0]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) {
[bdd5a63]201 fail("SDL_CreateThread() failed: %s", SDL_GetError());
202 }
203
204 sdl_loop();
[7cc6ac0]205
206 SDL_WaitThread(thr_cpu, NULL);
207 SDL_WaitThread(thr_gdb, NULL);
[ff8d800]208
[bdd5a63]209 cpu_quit();
[7cc6ac0]210 gdb_quit();
[ff8d800]211 sdl_quit();
[d54045b]212 return 0;
213}
Note: See TracBrowser for help on using the repository browser.