source: buchla-emu/emu/main.c@ 8967dbc

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

Load floppy disk image file.

  • Property mode set to 100644
File size: 2.7 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 { "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
40const char *bios = "bios.abs";
41const char *disk = "buchla.disk";
42
43static void usage(FILE *fh)
44{
45 fprintf(fh, "usage: buchla [-h] [-v comp [-v comp [...]]] [-b bios] [-d disk]\n");
46 fprintf(fh, "where comp is one of: ");
47
48 for (int32_t i = 0; i < ARRAY_COUNT(verb_flags); ++i) {
49 fprintf(fh, "%s, ", verb_flags[i].name);
50 }
51
52 fprintf(fh, "all\n");
53}
54
55static void parse_args(int32_t argc, char *argv[])
56{
57 for (int32_t i = 0; i < argc; ++i) {
58 if (strcmp(argv[i], "-h") == 0) {
59 usage(stdout);
60 exit(0);
61 }
62
63 if (strcmp(argv[i], "-b") == 0) {
64 if (++i == argc) {
65 usage(stderr);
66 fprintf(stderr, "missing argument to -b\n");
67 exit(1);
68 }
69
70 bios = argv[i];
71 continue;
72 }
73
74 if (strcmp(argv[i], "-d") == 0) {
75 if (++i == argc) {
76 usage(stderr);
77 fprintf(stderr, "missing argument to -d\n");
78 exit(1);
79 }
80
81 disk = argv[i];
82 continue;
83 }
84
85 if (strcmp(argv[i], "-v") == 0) {
86 if (++i == argc) {
87 usage(stderr);
88 fprintf(stderr, "missing argument to -v\n");
89 exit(1);
90 }
91
92 int32_t k;
93
94 if (strcmp(argv[i], "all") == 0) {
95 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
96 ++*verb_flags[k].flag;
97 }
98
99 continue;
100 }
101
102 for (k = 0; k < ARRAY_COUNT(verb_flags); ++k) {
103 if (strcmp(argv[i], verb_flags[k].name) == 0) {
104 ++*verb_flags[k].flag;
105 break;
106 }
107 }
108
109 if (k == ARRAY_COUNT(verb_flags)) {
110 usage(stderr);
111 fprintf(stderr, "invalid argument to -v: %s\n", argv[i]);
112 exit(1);
113 }
114
115 continue;
116 }
117 }
118}
119
120int32_t main(int32_t argc, char *argv[])
121{
122 parse_args(argc, argv);
123 sdl_init();
124
125 cpu_loop();
126
127 sdl_quit();
128 return 0;
129}
Note: See TracBrowser for help on using the repository browser.