Thu, 02 Dec 2010 17:01:34 +0000
Implement memory mapping and access checking
1 #ifndef _STATE_H
2 #define _STATE_H
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <stdbool.h>
8 // Maximum size of the Boot PROMs. Must be a binary power of two.
9 #define ROM_SIZE 32768
11 /**
12 * @brief Emulator state storage
13 *
14 * This structure stores the internal state of the emulator.
15 */
16 typedef struct {
17 // Boot PROM can be up to 32Kbytes total size
18 uint8_t rom[ROM_SIZE]; ///< Boot PROM data buffer
20 // Main system RAM
21 uint8_t *ram; ///< RAM data buffer
22 size_t ram_size; ///< Size of RAM buffer in bytes
24 // Video RAM
25 uint8_t vram[0x8000]; ///< Video RAM
27 // Map RAM
28 uint8_t map[0x800]; ///< Map RAM
30 // General Status Register
31 uint16_t genstat;
33 // GENERAL CONTROL REGISTER
34 /// GENCON.ROMLMAP -- false ORs the address with 0x800000, forcing the
35 /// 68010 to access ROM instead of RAM when booting. TRM page 2-36.
36 bool romlmap;
37 } S_state;
39 // Global emulator state. Yes, I know global variables are evil, please don't
40 // email me and lecture me about it. -philpem
41 #ifndef _STATE_C
42 extern S_state state;
43 #else
44 S_state state;
45 #endif
47 /**
48 * @brief Initialise system state
49 *
50 * @param ramsize RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 4MiB.
51 *
52 * Initialises the emulator's internal state.
53 */
54 int state_init(size_t ramsize);
56 /**
57 * @brief Deinitialise system state
58 *
59 * Deinitialises the saved state, and frees all memory. Call this function
60 * before exiting your program to avoid memory leaks.
61 */
62 void state_done();
64 #endif