]> git.sesse.net Git - pistorm/blob - config_file/config_file.h
841f802747cd1aed8182ba90a71e3e66cbaff6ed
[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_AUTODUMP_FILE,
34   MAPCMD_AUTODUMP_MEM,
35   MAPCMD_NUM,
36 } map_cmds;
37
38 typedef enum {
39   CONFITEM_NONE,
40   CONFITEM_CPUTYPE,
41   CONFITEM_MAP,
42   CONFITEM_LOOPCYCLES,
43   CONFITEM_MOUSE,
44   CONFITEM_KEYBOARD,
45   CONFITEM_PLATFORM,
46   CONFITEM_SETVAR,
47   CONFITEM_KBFILE,
48   CONFITEM_NUM,
49 } config_items;
50
51 typedef enum {
52   OP_TYPE_BYTE,
53   OP_TYPE_WORD,
54   OP_TYPE_LONGWORD,
55   OP_TYPE_MEM,
56   OP_TYPE_NUM,
57 } map_op_types;
58
59 struct emulator_config {
60   unsigned int cpu_type;
61
62   unsigned char map_type[MAX_NUM_MAPPED_ITEMS];
63   unsigned long map_offset[MAX_NUM_MAPPED_ITEMS];
64   unsigned long map_high[MAX_NUM_MAPPED_ITEMS];
65   unsigned int map_size[MAX_NUM_MAPPED_ITEMS];
66   unsigned int rom_size[MAX_NUM_MAPPED_ITEMS];
67   unsigned char *map_data[MAX_NUM_MAPPED_ITEMS];
68   unsigned int map_mirror[MAX_NUM_MAPPED_ITEMS];
69   char *map_id[MAX_NUM_MAPPED_ITEMS];
70
71   struct platform_config *platform;
72
73   char *mouse_file, *keyboard_file;
74
75   char mouse_toggle_key, keyboard_toggle_key;
76   unsigned char mouse_enabled, mouse_autoconnect, keyboard_enabled, keyboard_grab, keyboard_autoconnect;
77
78   unsigned int loop_cycles;
79   unsigned int mapped_low, mapped_high;
80   unsigned int custom_low, custom_high;
81 };
82
83 struct platform_config {
84   char *subsys;
85   unsigned char id;
86
87   int (*custom_read)(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
88   int (*custom_write)(struct emulator_config *cfg, unsigned int addr, unsigned int val, unsigned char type);
89
90   int (*register_read)(unsigned int addr, unsigned char type, unsigned int *val);
91   int (*register_write)(unsigned int addr, unsigned int value, unsigned char type);
92
93   int (*platform_initial_setup)(struct emulator_config *cfg);
94   void (*handle_reset)(struct emulator_config *cfg);
95   void (*shutdown)(struct emulator_config *cfg);
96   void (*setvar)(struct emulator_config *cfg, char *var, char *val);
97 };
98
99 #ifdef __cplusplus
100 extern "C" int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
101 #else
102 unsigned int get_m68k_cpu_type(char *name);
103 struct emulator_config *load_config_file(char *filename);
104 void free_config_file(struct emulator_config *cfg);
105
106 int handle_mapped_read(struct emulator_config *cfg, unsigned int addr, unsigned int *val, unsigned char type);
107 int handle_mapped_write(struct emulator_config *cfg, unsigned int addr, unsigned int value, unsigned char type);
108 int get_named_mapped_item(struct emulator_config *cfg, char *name);
109 int get_mapped_item_by_address(struct emulator_config *cfg, uint32_t address);
110 uint8_t *get_mapped_data_pointer_by_address(struct emulator_config *cfg, uint32_t address);
111 void add_mapping(struct emulator_config *cfg, unsigned int type, unsigned int addr, unsigned int size, int mirr_addr, char *filename, char *map_id, unsigned int autodump);
112 unsigned int get_int(char *str);
113 #endif
114
115 #endif /* _CONFIG_FILE_H */