source: buchla-emu/emu/main.c@ 7cc6ac0

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

Successfully attached GDB.

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