]> git.sesse.net Git - pistorm/blob - platforms/platforms.c
4d301b4f085edefcc47a19f227624f49b1db2f04
[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_dummy(struct platform_config *cfg, char *subsys);
28
29 struct platform_config *make_platform_config(char *name, char *subsys) {
30     struct platform_config *cfg = NULL;
31     int platform_id = get_platform_index(name);
32
33     if (platform_id == -1) {
34         // Display a warning if no match is found for the config name, in case it was mistyped.
35         printf("No match found for platform name \'%s\', defaulting to none/generic.\n", name);
36         platform_id = PLATFORM_NONE;
37     }
38     else {
39         printf("Creating platform config for %s...\n", name);
40     }
41
42     cfg = (struct platform_config *)malloc(sizeof(struct platform_config));
43     if (!cfg) {
44         printf("Failed to allocate memory for new platform config!.\n");
45         return NULL;
46     }
47     memset(cfg, 0x00, sizeof(struct platform_config));
48
49     switch(platform_id) {
50         case PLATFORM_AMIGA:
51             create_platform_amiga(cfg, subsys);
52             break;
53         case PLATFORM_NONE:
54         case PLATFORM_MAC:
55         case PLATFORM_X68000:
56         default:
57             create_platform_dummy(cfg, subsys);
58             break;
59     }
60
61     return cfg;
62 }