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