src/state.h

Wed, 29 Dec 2010 01:38:54 +0000

author
Philip Pemberton <philpem@philpem.me.uk>
date
Wed, 29 Dec 2010 01:38:54 +0000
changeset 74
51cbc7a44cd9
parent 62
c895256b528d
child 80
9581358e92b0
permissions
-rw-r--r--

add first cut keyboard driver

     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		*base_ram;			///< Base RAM data buffer
    33 	size_t		base_ram_size;		///< Size of Base RAM buffer in bytes
    34 	uint8_t		*exp_ram;			///< Expansion RAM data buffer
    35 	size_t		exp_ram_size;		///< Size of Expansion RAM buffer in bytes
    37 	/// Video RAM
    38 	uint8_t		vram[0x8000];
    40 	/// Map RAM
    41 	uint8_t		map[0x800];
    43 	//// Registers
    44 	uint16_t	genstat;			///< General Status Register
    45 	uint16_t	bsr0;				///< Bus Status Register 0
    46 	uint16_t	bsr1;				///< Bus Status Register 1
    48 	//// MISCELLANEOUS CONTROL REGISTER
    49 	bool		dma_reading;		///< True if Disc DMA reads from the controller, false otherwise
    50 	uint8_t		leds;				///< LED status, 1=on, in order red3/green2/yellow1/red0 from bit3 to bit0
    52 	//// GENERAL CONTROL REGISTER
    53 	/// GENCON.ROMLMAP -- false ORs the address with 0x800000, forcing the
    54 	/// 68010 to access ROM instead of RAM when booting. TRM page 2-36.
    55 	bool		romlmap;
    56 	/// GENCON.PIE -- Parity Error Check Enable
    57 	bool		pie;
    59 	/// DMA Address Register
    60 	uint32_t	dma_address;
    62 	/// DMA count
    63 	uint32_t	dma_count;
    65 	/// DMA direction
    66 	bool		idmarw;
    67 	/// DMA enable
    68 	bool		dmaen;
    69 	bool		dmaenb;
    71 	/// Floppy disc controller context
    72 	WD2797_CTX	fdc_ctx;
    73 } S_state;
    75 // Global emulator state. Yes, I know global variables are evil, please don't
    76 // email me and lecture me about it.  -philpem
    77 #ifndef _STATE_C
    78 extern S_state state;
    79 #else
    80 S_state state;
    81 #endif
    83 /**
    84  * @brief	Initialise system state
    85  *
    86  * @param	base_ram_size		Base RAM size in bytes -- must be a multiple of 512KiB, min 512KiB, max 2MiB.
    87  * @param	exp_ram_size		Expansion RAM size in bytes -- must be a multiple of 512KiB, min 0, max 2MiB.
    88  *
    89  * Initialises the emulator's internal state.
    90  */
    91 int state_init(size_t base_ram_size, size_t exp_ram_size);
    93 /**
    94  * @brief Deinitialise system state
    95  *
    96  * Deinitialises the saved state, and frees all memory. Call this function
    97  * before exiting your program to avoid memory leaks.
    98  */
    99 void state_done();
   101 #endif