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

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