[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] | 20 | typedef struct {
|
---|
| 21 | const char *name;
|
---|
[4c71d39] | 22 | int32_t *flag;
|
---|
[b909777] | 23 | } verb_flag_t;
|
---|
| 24 |
|
---|
| 25 | static 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] | 41 | const char *bios = "bios.abs";
|
---|
| 42 | const char *disk = "buchla.disk";
|
---|
[0edef06] | 43 | const char *font = "ttf/vera-sans-mono.ttf";
|
---|
[b909777] | 44 |
|
---|
[bdd5a63] | 45 | SDL_atomic_t run;
|
---|
| 46 |
|
---|
[77d8df8] | 47 | uint32_t mid_port = 0;
|
---|
| 48 |
|
---|
[b909777] | 49 | static void usage(FILE *fh)
|
---|
[d54045b] | 50 | {
|
---|
[77d8df8] | 51 | fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font] [-m midiport] \n");
|
---|
[b909777] | 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");
|
---|
[77d8df8] | 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");
|
---|
[b909777] | 61 | }
|
---|
| 62 |
|
---|
| 63 | static 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 | }
|
---|
[ff8d800] | 81 |
|
---|
[1efc42c] | 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 |
|
---|
[0edef06] | 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 |
|
---|
[b909777] | 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) {
|
---|
[4c71d39] | 115 | ++*verb_flags[k].flag;
|
---|
[b909777] | 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) {
|
---|
[4c71d39] | 123 | ++*verb_flags[k].flag;
|
---|
[b909777] | 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 | }
|
---|
[77d8df8] | 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 | }
|
---|
[b909777] | 154 | }
|
---|
| 155 | }
|
---|
| 156 |
|
---|
[bdd5a63] | 157 | static int32_t cpu_thread(void *data)
|
---|
| 158 | {
|
---|
| 159 | (void)data;
|
---|
| 160 |
|
---|
| 161 | cpu_loop();
|
---|
| 162 | return 0;
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[7cc6ac0] | 165 | static int32_t gdb_thread(void *data)
|
---|
| 166 | {
|
---|
| 167 | (void)data;
|
---|
| 168 |
|
---|
| 169 | gdb_loop();
|
---|
| 170 | return 0;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[b909777] | 173 | int32_t main(int32_t argc, char *argv[])
|
---|
| 174 | {
|
---|
| 175 | parse_args(argc, argv);
|
---|
[ff8d800] | 176 | sdl_init();
|
---|
[7cc6ac0] | 177 | gdb_init();
|
---|
[bdd5a63] | 178 | cpu_init();
|
---|
[ff8d800] | 179 |
|
---|
[bdd5a63] | 180 | SDL_AtomicSet(&run, 1);
|
---|
[7cc6ac0] | 181 | SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
|
---|
[bdd5a63] | 182 |
|
---|
[7cc6ac0] | 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) {
|
---|
[bdd5a63] | 190 | fail("SDL_CreateThread() failed: %s", SDL_GetError());
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | sdl_loop();
|
---|
[7cc6ac0] | 194 |
|
---|
| 195 | SDL_WaitThread(thr_cpu, NULL);
|
---|
| 196 | SDL_WaitThread(thr_gdb, NULL);
|
---|
[ff8d800] | 197 |
|
---|
[bdd5a63] | 198 | cpu_quit();
|
---|
[7cc6ac0] | 199 | gdb_quit();
|
---|
[ff8d800] | 200 | sdl_quit();
|
---|
[d54045b] | 201 | return 0;
|
---|
| 202 | }
|
---|