]> git.sesse.net Git - pistorm/blob - platforms/platforms.c
Add some more Mac68k handling stuff
[pistorm] / platforms / platforms.c
1 // SPDX-License-Identifier: MIT
2
3 #include "platforms.h"
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 static char*platform_names[PLATFORM_NUM] = {
9     "none",
10     "amiga",
11     "mac68k",
12     "x68000",
13 };
14
15 int get_platform_index(char *name) {
16     if (!name || strlen(name) == 0)
17         return -1;
18
19     for (int i = 0; i < PLATFORM_NUM; i++) {
20         if (strcmp(name, platform_names[i]) == 0)
21             return i;
22     }
23     return -1;
24 }
25
26 void create_platform_amiga(struct platform_config *cfg, char *subsys);
27 void create_platform_mac68k(struct platform_config *cfg, char *subsys);
28 void create_platform_dummy(struct platform_config *cfg, char *subsys);
29
30 struct platform_config *make_platform_config(char *name, char *subsys) {
31     struct platform_config *cfg = NULL;
32     int platform_id = get_platform_index(name);
33
34     if (platform_id == -1) {
35         // Display a warning if no match is found for the config name, in case it was mistyped.
36         printf("No match found for platform name \'%s\', defaulting to none/generic.\n", name);
37         platform_id = PLATFORM_NONE;
38     }
39     else {
40         printf("Creating platform config for %s...\n", name);
41     }
42
43     cfg = (struct platform_config *)malloc(sizeof(struct platform_config));
44     if (!cfg) {
45         printf("Failed to allocate memory for new platform config!.\n");
46         return NULL;
47     }
48     memset(cfg, 0x00, sizeof(struct platform_config));
49
50     switch(platform_id) {
51         case PLATFORM_AMIGA:
52             create_platform_amiga(cfg, subsys);
53             break;
54         case PLATFORM_MAC:
55             create_platform_mac68k(cfg, subsys);
56             break;
57         case PLATFORM_NONE:
58         case PLATFORM_X68000:
59         default:
60             create_platform_dummy(cfg, subsys);
61             break;
62     }
63
64     return cfg;
65 }