Fri, 12 Apr 2013 12:37:13 +0100
Make the page table volatile (it may change behind gcc's back)
1 #ifndef _STATE_H
2 #define _STATE_H
4 #include <stddef.h>
5 #include <stdint.h>
6 #include <stdbool.h>
7 #include "wd279x.h"
8 #include "wd2010.h"
9 #include "keyboard.h"
11 // Maximum size of the Boot PROMs. Must be a binary power of two.
12 #define ROM_SIZE 32768
14 /**
15 * State error codes
16 */
17 typedef enum {
18 STATE_E_OK = 0, ///< Operation succeeded
19 STATE_E_BAD_RAMSIZE = -1, ///< Bad RAM size specified (not a multiple of 512K, or less than 512K)
20 STATE_E_NO_MEMORY = -2, ///< Out of memory while allocating state variables
21 STATE_E_ROM_LOAD_FAIL = -3 ///< Error loading ROMs
22 } STATE_ERR;
24 /**
25 * @brief Emulator state storage
26 *
27 * This structure stores the internal state of the emulator.
28 */
29 typedef struct {
30 // Boot PROM can be up to 32Kbytes total size
31 uint8_t rom[ROM_SIZE]; ///< Boot PROM data buffer
33 //// Main system RAM
34 uint8_t *base_ram; ///< Base RAM data buffer
35 size_t base_ram_size; ///< Size of Base RAM buffer in bytes
36 uint8_t *exp_ram; ///< Expansion RAM data buffer
37 size_t exp_ram_size; ///< Size of Expansion RAM buffer in bytes
39 /// Video RAM
40 uint8_t vram[0x8000];
42 /// Map RAM
43 volatile uint8_t map[0x800];
45 //// Registers
46 uint16_t genstat; ///< General Status Register
47 uint16_t bsr0; ///< Bus Status Register 0
48 uint16_t bsr1; ///< Bus Status Register 1
50 //// MISCELLANEOUS CONTROL REGISTER
51 bool dma_reading; ///< True if Disc DMA reads from the controller, false otherwise
52 uint8_t leds; ///< LED status, 1=on, in order red3/green2/yellow1/red0 from bit3 to bit0
54 bool timer_enabled;
55 bool timer_asserted;
57 //// GENERAL CONTROL REGISTER
58 /// GENCON.ROMLMAP -- false ORs the address with 0x800000, forcing the
59 /// 68010 to access ROM instead of RAM when booting. TRM page 2-36.
60 bool romlmap;
61 /// GENCON.PIE -- Parity Error Check Enable
62 bool pie;
63 /// GENCON.EE -- Error Enable
64 bool ee;
66 /// DMA Address Register
67 uint32_t dma_address;
69 /// DMA count
70 uint32_t dma_count;
72 /// DMA direction
73 bool idmarw;
74 /// DMA enable
75 bool dmaen;
76 bool dmaenb;
78 /// DMA device selection flags
79 bool fd_selected;
80 bool hd_selected;
81 /// Floppy disc controller context
82 WD2797_CTX fdc_ctx;
83 /// Current disc image file
84 FILE *fdc_disc;
86 /// Hard disc controller context
87 WD2010_CTX hdc_ctx;
88 FILE *hdc_disc0;
89 FILE *hdc_disc1;
91 /// Keyboard controller context
92 KEYBOARD_STATE kbd;
93 } S_state;
95 // Global emulator state. Yes, I know global variables are evil, please don't
96 // email me and lecture me about it. -philpem
97 #ifndef _STATE_C
98 extern S_state state;
99 #else
100 S_state state;
101 #endif
103 /**
104 * @brief Initialise system state
105 *
106 * @param base_ram_size Base RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 2MiB.
107 * @param exp_ram_size Expansion RAM size in bytes -- must be a multiple of 512KiB, min 0, max 2MiB.
108 *
109 * Initialises the emulator's internal state.
110 */
111 int state_init(size_t base_ram_size, size_t exp_ram_size);
113 /**
114 * @brief Deinitialise system state
115 *
116 * Deinitialises the saved state, and frees all memory. Call this function
117 * before exiting your program to avoid memory leaks.
118 */
119 void state_done();
121 #endif