]> git.sesse.net Git - pistorm/blob - config_file/config_file.h
Merge remote-tracking branch 'niklasekstrom/autoconfig_a314' into wip-crap
[pistorm] / config_file / config_file.h
1 // SPDX-License-Identifier: MIT
2
3 #ifndef _CONFIG_FILE_H
4 #define _CONFIG_FILE_H
5
6 #include "m68k.h"
7
8 #include <unistd.h>
9
10 #define MAX_NUM_MAPPED_ITEMS 8
11 #define SIZE_KILO 1024
12 #define SIZE_MEGA (1024 * 1024)
13 #define SIZE_GIGA (1024 * 1024 * 1024)
14
15 typedef enum {
16   MAPTYPE_NONE,
17   MAPTYPE_ROM,
18   MAPTYPE_RAM,
19   MAPTYPE_REGISTER,
20   MAPTYPE_RAM_NOALLOC,
21   MAPTYPE_NUM,
22 } map_types;
23
24 typedef enum {
25   MAPCMD_UNKNOWN,
26   MAPCMD_TYPE,
27   MAPCMD_ADDRESS,
28   MAPCMD_SIZE,
29   MAPCMD_RANGE,
30   MAPCMD_FILENAME,
31   MAPCMD_OVL_REMAP,
32   MAPCMD_MAP_ID,
33   MAPCMD_NUM,
34 } map_cmds;
35
36 typedef enum {
37   CONFITEM_NONE,
38   CONFITEM_CPUTYPE,
39   CONFITEM_MAP,
40   CONFITEM_LOOPCYCLES,
41   CONFITEM_MOUSE,
42   CONFITEM_KEYBOARD,
43   CONFITEM_PLATFORM,
44   CONFITEM_SETVAR,
45   CONFITEM_KBFILE,
46   CONFITEM_NUM,
47 } config_items;
48
49 typedef enum {
50   OP_TYPE_BYTE,
51   OP_TYPE_WORD,
52   OP_TYPE_LONGWORD,
53   OP_TYPE_MEM,
54   OP_TYPE_NUM,
55 } map_op_types;
56
57 struct emulator_config {
58   unsigned int cpu_type;
59
60   unsigned char map_type[MAX_NUM_MAPPED_ITEMS];
61   unsigned long map_offset[MAX_NUM_MAPPED_ITEMS];
62   unsigned long map_high[MAX_NUM_MAPPED_ITEMS];
63   unsigned int map_size[MAX_NUM_MAPPED_ITEMS];
64   unsigned int rom_size[MAX_NUM_MAPPED_ITEMS];
65   unsigned char *map_data[MAX_NUM_MAPPED_ITEMS];
66   unsigned int map_mirror[MAX_NUM_MAPPED_ITEMS];
67   char *map_id[MAX_NUM_MAPPED_ITEMS];
68
69   struct platform_config *platform;
70
71   char *mouse_file, *keyboard_file;
72
73   char mouse_toggle_key, keyboard_toggle_key;
74   unsigned char mouse_enabled, mouse_autoconnect, keyboard_enabled, keyboard_grab, keyboard_autoconnect;
75
76   unsigned int loop_cycles;
77   unsigned int mapped_low, mapped_high;
78   unsigned int custom_low, custom_high;
79 };
80
81 struct platform_config {
82   char *subsys;
83   unsigned char id;
84
85   int (*custom_read)(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
86   int (*custom_write)(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type);
87
88   int (*register_read)(unsigned int addr, unsigned char type, unsigned int *val);
89   int (*register_write)(unsigned int addr, unsigned int value, unsigned char type);
90
91   int (*platform_initial_setup)(struct emulator_config *cfg);
92   void (*handle_reset)(struct emulator_config *cfg);
93   void (*shutdown)(struct emulator_config *cfg);
94   void (*setvar)(struct emulator_config *cfg, char *var, char *val);
95 };
96
97 unsigned int get_m68k_cpu_type(char *name);
98 struct emulator_config *load_config_file(char *filename);
99 void free_config_file(struct emulator_config *cfg);
100
101 int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
102 int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type);
103 int get_named_mapped_item(struct emulator_config *cfg, char *name);
104 int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
105 void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id);
106 unsigned int get_int(char *str);
107
108 #endif /* _CONFIG_FILE_H */