[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";
|
---|
[b909777] | 43 |
|
---|
[bdd5a63] | 44 | SDL_atomic_t run;
|
---|
| 45 |
|
---|
[b909777] | 46 | static void usage(FILE *fh)
|
---|
[d54045b] | 47 | {
|
---|
[1efc42c] | 48 | fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk]\n");
|
---|
[b909777] | 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 |
|
---|
| 58 | static 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 | }
|
---|
[ff8d800] | 76 |
|
---|
[1efc42c] | 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 |
|
---|
[b909777] | 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) {
|
---|
[4c71d39] | 99 | ++*verb_flags[k].flag;
|
---|
[b909777] | 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) {
|
---|
[4c71d39] | 107 | ++*verb_flags[k].flag;
|
---|
[b909777] | 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 |
|
---|
[bdd5a63] | 123 | static int32_t cpu_thread(void *data)
|
---|
| 124 | {
|
---|
| 125 | (void)data;
|
---|
| 126 |
|
---|
| 127 | cpu_loop();
|
---|
| 128 | return 0;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[7cc6ac0] | 131 | static int32_t gdb_thread(void *data)
|
---|
| 132 | {
|
---|
| 133 | (void)data;
|
---|
| 134 |
|
---|
| 135 | gdb_loop();
|
---|
| 136 | return 0;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[b909777] | 139 | int32_t main(int32_t argc, char *argv[])
|
---|
| 140 | {
|
---|
| 141 | parse_args(argc, argv);
|
---|
[ff8d800] | 142 | sdl_init();
|
---|
[7cc6ac0] | 143 | gdb_init();
|
---|
[bdd5a63] | 144 | cpu_init();
|
---|
[ff8d800] | 145 |
|
---|
[bdd5a63] | 146 | SDL_AtomicSet(&run, 1);
|
---|
[7cc6ac0] | 147 | SDL_Thread *thr_cpu = SDL_CreateThread(cpu_thread, "cpu", NULL);
|
---|
[bdd5a63] | 148 |
|
---|
[7cc6ac0] | 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) {
|
---|
[bdd5a63] | 156 | fail("SDL_CreateThread() failed: %s", SDL_GetError());
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | sdl_loop();
|
---|
[7cc6ac0] | 160 |
|
---|
| 161 | SDL_WaitThread(thr_cpu, NULL);
|
---|
| 162 | SDL_WaitThread(thr_gdb, NULL);
|
---|
[ff8d800] | 163 |
|
---|
[bdd5a63] | 164 | cpu_quit();
|
---|
[7cc6ac0] | 165 | gdb_quit();
|
---|
[ff8d800] | 166 | sdl_quit();
|
---|
[d54045b] | 167 | return 0;
|
---|
| 168 | }
|
---|