src/state.h

Sun, 12 Dec 2010 23:47:35 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Sun, 12 Dec 2010 23:47:35 +0000
changeset 55
ba6b8e570062
parent 53
e1693c4b8a0c
child 60
96f3df0b3cbb
permissions
-rw-r--r--

improve error and DMA handling

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@18 8
philpem@18 9 // Maximum size of the Boot PROMs. Must be a binary power of two.
philpem@18 10 #define ROM_SIZE 32768
philpem@18 11
philpem@18 12 /**
philpem@55 13 * State error codes
philpem@55 14 */
philpem@55 15 typedef enum {
philpem@55 16 STATE_E_OK = 0, ///< Operation succeeded
philpem@55 17 STATE_E_BAD_RAMSIZE = -1, ///< Bad RAM size specified (not a multiple of 512K, or less than 512K)
philpem@55 18 STATE_E_NO_MEMORY = -2, ///< Out of memory while allocating state variables
philpem@55 19 STATE_E_ROM_LOAD_FAIL = -3 ///< Error loading ROMs
philpem@55 20 } STATE_ERR;
philpem@55 21
philpem@55 22 /**
philpem@18 23 * @brief Emulator state storage
philpem@18 24 *
philpem@18 25 * This structure stores the internal state of the emulator.
philpem@18 26 */
philpem@18 27 typedef struct {
philpem@18 28 // Boot PROM can be up to 32Kbytes total size
philpem@18 29 uint8_t rom[ROM_SIZE]; ///< Boot PROM data buffer
philpem@18 30
philpem@52 31 //// Main system RAM
philpem@18 32 uint8_t *ram; ///< RAM data buffer
philpem@18 33 size_t ram_size; ///< Size of RAM buffer in bytes
philpem@18 34
philpem@52 35 /// Video RAM
philpem@52 36 uint8_t vram[0x8000];
philpem@24 37
philpem@52 38 /// Map RAM
philpem@52 39 uint8_t map[0x800];
philpem@26 40
philpem@52 41 //// Registers
philpem@37 42 uint16_t genstat; ///< General Status Register
philpem@37 43 uint16_t bsr0; ///< Bus Status Register 0
philpem@37 44 uint16_t bsr1; ///< Bus Status Register 1
philpem@32 45
philpem@52 46 //// MISCELLANEOUS CONTROL REGISTER
philpem@52 47 bool dma_reading; ///< True if Disc DMA reads from the controller, false otherwise
philpem@46 48 uint8_t leds; ///< LED status, 1=on, in order red3/green2/yellow1/red0 from bit3 to bit0
philpem@46 49
philpem@52 50 //// GENERAL CONTROL REGISTER
philpem@18 51 /// GENCON.ROMLMAP -- false ORs the address with 0x800000, forcing the
philpem@18 52 /// 68010 to access ROM instead of RAM when booting. TRM page 2-36.
philpem@24 53 bool romlmap;
philpem@44 54 /// GENCON.PIE -- Parity Error Check Enable
philpem@44 55 bool pie;
philpem@52 56
philpem@52 57 /// DMA Address Register
philpem@52 58 uint32_t dma_address;
philpem@52 59
philpem@53 60 /// DMA count
philpem@53 61 uint32_t dma_count;
philpem@53 62
philpem@53 63 /// DMA direction
philpem@53 64 bool idmarw;
philpem@53 65 /// DMA enable
philpem@53 66 bool dmaen;
philpem@53 67 bool dmaenb;
philpem@53 68
philpem@52 69 /// Floppy disc controller context
philpem@52 70 WD2797_CTX fdc_ctx;
philpem@18 71 } S_state;
philpem@18 72
philpem@18 73 // Global emulator state. Yes, I know global variables are evil, please don't
philpem@18 74 // email me and lecture me about it. -philpem
philpem@18 75 #ifndef _STATE_C
philpem@18 76 extern S_state state;
philpem@18 77 #else
philpem@18 78 S_state state;
philpem@18 79 #endif
philpem@18 80
philpem@18 81 /**
philpem@18 82 * @brief Initialise system state
philpem@18 83 *
philpem@18 84 * @param ramsize RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 4MiB.
philpem@18 85 *
philpem@18 86 * Initialises the emulator's internal state.
philpem@18 87 */
philpem@18 88 int state_init(size_t ramsize);
philpem@18 89
philpem@18 90 /**
philpem@18 91 * @brief Deinitialise system state
philpem@18 92 *
philpem@18 93 * Deinitialises the saved state, and frees all memory. Call this function
philpem@18 94 * before exiting your program to avoid memory leaks.
philpem@18 95 */
philpem@18 96 void state_done();
philpem@18 97
philpem@18 98 #endif