| 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 |
|
|---|
| 20 | typedef struct {
|
|---|
| 21 | const char *name;
|
|---|
| 22 | int32_t *flag;
|
|---|
| 23 | } verb_flag_t;
|
|---|
| 24 |
|
|---|
| 25 | static verb_flag_t verb_flags[] = {
|
|---|
| 26 | { "sdl", &sdl_verbose },
|
|---|
| 27 | { "cpu", &cpu_verbose },
|
|---|
| 28 | { "fpu", &fpu_verbose },
|
|---|
| 29 | { "vid", &vid_verbose },
|
|---|
| 30 | { "tim", &tim_verbose },
|
|---|
| 31 | { "lcd", &lcd_verbose },
|
|---|
| 32 | { "ser", &ser_verbose },
|
|---|
| 33 | { "mid", &mid_verbose },
|
|---|
| 34 | { "fdd", &fdd_verbose },
|
|---|
| 35 | { "snd", &snd_verbose },
|
|---|
| 36 | { "led", &led_verbose },
|
|---|
| 37 | { "kbd", &kbd_verbose }
|
|---|
| 38 | };
|
|---|
| 39 |
|
|---|
| 40 | const char *bios = "bios.abs";
|
|---|
| 41 | const char *disk = "buchla.disk";
|
|---|
| 42 |
|
|---|
| 43 | SDL_atomic_t run;
|
|---|
| 44 |
|
|---|
| 45 | static void usage(FILE *fh)
|
|---|
| 46 | {
|
|---|
| 47 | fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk]\n");
|
|---|
| 48 | fprintf(fh, "where comp is one of: ");
|
|---|
| 49 |
|
|---|
| 50 | for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
|
|---|
| 51 | fprintf(fh, "%s, ", verb_flags[i].name);
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | fprintf(fh, "all\n");
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | static void parse_args(int32_t argc, char *argv[])
|
|---|
| 58 | {
|
|---|
| 59 | for (int32_t i = 0; i < argc; ++i) {
|
|---|
| 60 | if (strcmp(argv[i], "-h") == 0) {
|
|---|
| 61 | usage(stdout);
|
|---|
| 62 | exit(0);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | if (strcmp(argv[i], "-b") == 0) {
|
|---|
| 66 | if (++i == argc) {
|
|---|
| 67 | usage(stderr);
|
|---|
| 68 | fprintf(stderr, "missing argument to -b\n");
|
|---|
| 69 | exit(1);
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | bios = argv[i];
|
|---|
| 73 | continue;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | if (strcmp(argv[i], "-d") == 0) {
|
|---|
| 77 | if (++i == argc) {
|
|---|
| 78 | usage(stderr);
|
|---|
| 79 | fprintf(stderr, "missing argument to -d\n");
|
|---|
| 80 | exit(1);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | disk = argv[i];
|
|---|
| 84 | continue;
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | if (strcmp(argv[i], "-v") == 0) {
|
|---|
| 88 | if (++i == argc) {
|
|---|
| 89 | usage(stderr);
|
|---|
| 90 | fprintf(stderr, "missing argument to -v\n");
|
|---|
| 91 | exit(1);
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | int32_t k;
|
|---|
| 95 |
|
|---|
| 96 | if (strcmp(argv[i], "all") == 0) {
|
|---|
| 97 | for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
|
|---|
| 98 | ++*verb_flags[k].flag;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | continue;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
|
|---|
| 105 | if (strcmp(argv[i], verb_flags[k].name) == 0) {
|
|---|
| 106 | ++*verb_flags[k].flag;
|
|---|
| 107 | break;
|
|---|
| 108 | }
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | if (k == ARRAY_COUNT(verb_flags)) {
|
|---|
| 112 | usage(stderr);
|
|---|
| 113 | fprintf(stderr, "invalid argument to -v: %s\n", argv[i]);
|
|---|
| 114 | exit(1);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | continue;
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | static int32_t cpu_thread(void *data)
|
|---|
| 123 | {
|
|---|
| 124 | (void)data;
|
|---|
| 125 |
|
|---|
| 126 | cpu_loop();
|
|---|
| 127 | return 0;
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | int32_t main(int32_t argc, char *argv[])
|
|---|
| 131 | {
|
|---|
| 132 | parse_args(argc, argv);
|
|---|
| 133 | sdl_init();
|
|---|
| 134 | cpu_init();
|
|---|
| 135 |
|
|---|
| 136 | SDL_AtomicSet(&run, 1);
|
|---|
| 137 | SDL_Thread *thr = SDL_CreateThread(cpu_thread, "cpu", NULL);
|
|---|
| 138 |
|
|---|
| 139 | if (thr == NULL) {
|
|---|
| 140 | fail("SDL_CreateThread() failed: %s", SDL_GetError());
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | sdl_loop();
|
|---|
| 144 | SDL_WaitThread(thr, NULL);
|
|---|
| 145 |
|
|---|
| 146 | cpu_quit();
|
|---|
| 147 | sdl_quit();
|
|---|
| 148 | return 0;
|
|---|
| 149 | }
|
|---|