[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 |
|
---|
[b909777] | 47 | static void usage(FILE *fh)
|
---|
[d54045b] | 48 | {
|
---|
[0edef06] | 49 | fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk] [-f font]\n");
|
---|
[b909777] | 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 |
|
---|
| 59 | static 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 | }
|
---|
[ff8d800] | 77 |
|
---|
[1efc42c] | 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 |
|
---|
[0edef06] | 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 |
|
---|
[b909777] | 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) {
|
---|
[4c71d39] | 111 | ++*verb_flags[k].flag;
|
---|
[b909777] | 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) {
|
---|
[4c71d39] | 119 | ++*verb_flags[k].flag;
|
---|
[b909777] | 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 |
|
---|
[bdd5a63] | 135 | static int32_t cpu_thread(void *data)
|
---|
| 136 | {
|
---|
| 137 | (void)data;
|
---|
| 138 |
|
---|
| 139 | cpu_loop();
|
---|
| 140 | return 0;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
[7cc6ac0] | 143 | static int32_t gdb_thread(void *data)
|
---|
| 144 | {
|
---|
| 145 | (void)data;
|
---|
| 146 |
|
---|
| 147 | gdb_loop();
|
---|
| 148 | return 0;
|
---|
| 149 | }
|
---|
| 150 |
|
---|
[b909777] | 151 | int32_t main(int32_t argc, char *argv[])
|
---|
| 152 | {
|
---|
| 153 | parse_args(argc, argv);
|
---|
[ff8d800] | 154 | sdl_init();
|
---|
[7cc6ac0] | 155 | gdb_init();
|
---|
[bdd5a63] | 156 | cpu_init();
|
---|
[ff8d800] | 157 |
|
---|
[bdd5a63] | 158 | SDL_AtomicSet(&run, 1);
|
---|
[7cc6ac0] | 159 | SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
|
---|
[bdd5a63] | 160 |
|
---|
[7cc6ac0] | 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) {
|
---|
[bdd5a63] | 168 | fail("SDL_CreateThread() failed: %s", SDL_GetError());
|
---|
| 169 | }
|
---|
| 170 |
|
---|
| 171 | sdl_loop();
|
---|
[7cc6ac0] | 172 |
|
---|
| 173 | SDL_WaitThread(thr_cpu, NULL);
|
---|
| 174 | SDL_WaitThread(thr_gdb, NULL);
|
---|
[ff8d800] | 175 |
|
---|
[bdd5a63] | 176 | cpu_quit();
|
---|
[7cc6ac0] | 177 | gdb_quit();
|
---|
[ff8d800] | 178 | sdl_quit();
|
---|
[d54045b] | 179 | return 0;
|
---|
| 180 | }
|
---|