src/state.h

Fri, 18 Apr 2014 01:34:20 -0600

author
andrew@localhost
date
Fri, 18 Apr 2014 01:34:20 -0600
changeset 151
b63a3999e2e7
parent 112
a392eb8f9806
permissions
-rw-r--r--

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)

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