Fri, 18 Apr 2014 01:34:20 -0600
added RTC emulation (attempts to set the date are ignored, and the year is currently hardcoded to 1987 because UNIX PC SysV has a few Y2K bugs)
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"
10 #include "tc8250.h"
13 // Maximum size of the Boot PROMs. Must be a binary power of two.
14 #define ROM_SIZE 32768
16 /**
17 * State error codes
18 */
19 typedef enum {
20 STATE_E_OK = 0, ///< Operation succeeded
21 STATE_E_BAD_RAMSIZE = -1, ///< Bad RAM size specified (not a multiple of 512K, or less than 512K)
22 STATE_E_NO_MEMORY = -2, ///< Out of memory while allocating state variables
23 STATE_E_ROM_LOAD_FAIL = -3 ///< Error loading ROMs
24 } STATE_ERR;
26 /**
27 * @brief Emulator state storage
28 *
29 * This structure stores the internal state of the emulator.
30 */
31 typedef struct {
32 // Boot PROM can be up to 32Kbytes total size
33 uint8_t rom[ROM_SIZE]; ///< Boot PROM data buffer
35 //// Main system RAM
36 uint8_t *base_ram; ///< Base RAM data buffer
37 size_t base_ram_size; ///< Size of Base RAM buffer in bytes
38 uint8_t *exp_ram; ///< Expansion RAM data buffer
39 size_t exp_ram_size; ///< Size of Expansion RAM buffer in bytes
41 /// Video RAM
42 uint8_t vram[0x8000];
44 /// Map RAM
45 uint8_t map[0x800];
47 //// Registers
48 uint16_t genstat; ///< General Status Register
49 uint16_t bsr0; ///< Bus Status Register 0
50 uint16_t bsr1; ///< Bus Status Register 1
52 //// MISCELLANEOUS CONTROL REGISTER
53 bool dma_reading; ///< True if Disc DMA reads from the controller, false otherwise
54 uint8_t leds; ///< LED status, 1=on, in order red3/green2/yellow1/red0 from bit3 to bit0
56 bool timer_enabled;
57 bool timer_asserted;
59 //// GENERAL CONTROL REGISTER
60 /// GENCON.ROMLMAP -- false ORs the address with 0x800000, forcing the
61 /// 68010 to access ROM instead of RAM when booting. TRM page 2-36.
62 bool romlmap;
63 /// GENCON.PIE -- Parity Error Check Enable
64 bool pie;
65 /// GENCON.EE -- Error Enable
66 bool ee;
68 /// DMA Address Register
69 uint32_t dma_address;
71 /// DMA count
72 uint32_t dma_count;
74 /// DMA direction
75 bool idmarw;
76 /// DMA enable
77 bool dmaen;
78 bool dmaenb;
80 /// DMA device selection flags
81 bool fd_selected;
82 bool hd_selected;
83 /// Floppy disc controller context
84 WD2797_CTX fdc_ctx;
85 /// Current disc image file
86 FILE *fdc_disc;
88 /// Hard disc controller context
89 WD2010_CTX hdc_ctx;
90 FILE *hdc_disc0;
91 FILE *hdc_disc1;
93 /// Keyboard controller context
94 KEYBOARD_STATE kbd;
96 /// Real time clock context
97 TC8250_CTX rtc_ctx;
98 } S_state;
100 // Global emulator state. Yes, I know global variables are evil, please don't
101 // email me and lecture me about it. -philpem
102 #ifndef _STATE_C
103 extern S_state state;
104 #else
105 S_state state;
106 #endif
108 /**
109 * @brief Initialise system state
110 *
111 * @param base_ram_size Base RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 2MiB.
112 * @param exp_ram_size Expansion RAM size in bytes -- must be a multiple of 512KiB, min 0, max 2MiB.
113 *
114 * Initialises the emulator's internal state.
115 */
116 int state_init(size_t base_ram_size, size_t exp_ram_size);
118 /**
119 * @brief Deinitialise system state
120 *
121 * Deinitialises the saved state, and frees all memory. Call this function
122 * before exiting your program to avoid memory leaks.
123 */
124 void state_done();
126 #endif