]> git.sesse.net Git - pistorm/blob - config_file/config_file.h
Add not-so-simple config switching from Amiga side
[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_NUM,
21 } map_types;
22
23 typedef enum {
24   MAPCMD_UNKNOWN,
25   MAPCMD_TYPE,
26   MAPCMD_ADDRESS,
27   MAPCMD_SIZE,
28   MAPCMD_RANGE,
29   MAPCMD_FILENAME,
30   MAPCMD_OVL_REMAP,
31   MAPCMD_MAP_ID,
32   MAPCMD_NUM,
33 } map_cmds;
34
35 typedef enum {
36   CONFITEM_NONE,
37   CONFITEM_CPUTYPE,
38   CONFITEM_MAP,
39   CONFITEM_LOOPCYCLES,
40   CONFITEM_MOUSE,
41   CONFITEM_KEYBOARD,
42   CONFITEM_PLATFORM,
43   CONFITEM_SETVAR,
44   CONFITEM_KBFILE,
45   CONFITEM_NUM,
46 } config_items;
47
48 typedef enum {
49   OP_TYPE_BYTE,
50   OP_TYPE_WORD,
51   OP_TYPE_LONGWORD,
52   OP_TYPE_MEM,
53   OP_TYPE_NUM,
54 } map_op_types;
55
56 struct emulator_config {
57   unsigned int cpu_type;
58
59   unsigned char map_type[MAX_NUM_MAPPED_ITEMS];
60   unsigned long map_offset[MAX_NUM_MAPPED_ITEMS];
61   unsigned long map_high[MAX_NUM_MAPPED_ITEMS];
62   unsigned int map_size[MAX_NUM_MAPPED_ITEMS];
63   unsigned int rom_size[MAX_NUM_MAPPED_ITEMS];
64   unsigned char *map_data[MAX_NUM_MAPPED_ITEMS];
65   unsigned int map_mirror[MAX_NUM_MAPPED_ITEMS];
66   char *map_id[MAX_NUM_MAPPED_ITEMS];
67
68   struct platform_config *platform;
69
70   char *mouse_file, *keyboard_file;
71
72   char mouse_toggle_key, keyboard_toggle_key;
73   unsigned char mouse_enabled, mouse_autoconnect, keyboard_enabled, keyboard_grab, keyboard_autoconnect;
74
75   unsigned int loop_cycles;
76   unsigned int mapped_low, mapped_high;
77   unsigned int custom_low, custom_high;
78 };
79
80 struct platform_config {
81   char *subsys;
82   unsigned char id;
83
84   int (*custom_read)(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
85   int (*custom_write)(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type);
86
87   int (*register_read)(unsigned int addr, unsigned char type, unsigned int *val);
88   int (*register_write)(unsigned int addr, unsigned int value, unsigned char type);
89
90   int (*platform_initial_setup)(struct emulator_config *cfg);
91   void (*handle_reset)(struct emulator_config *cfg);
92   void (*shutdown)(struct emulator_config *cfg);
93   void (*setvar)(struct emulator_config *cfg, char *var, char *val);
94 };
95
96 unsigned int get_m68k_cpu_type(char *name);
97 struct emulator_config *load_config_file(char *filename);
98 void free_config_file(struct emulator_config *cfg);
99
100 int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
101 int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type);
102 int get_named_mapped_item(struct emulator_config *cfg, char *name);
103 int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
104 unsigned int get_int(char *str);
105
106 #endif /* _CONFIG_FILE_H */