summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/includes/nes.h
blob: 451c901de9ca30c3e129290b05c505db3328fc75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*****************************************************************************

	nes.h

	Nintendo Entertainment System (Famicom)

 ****************************************************************************/

#ifndef NES_H_
#define NES_H_

#include "includes/nes_mmc.h"


/***************************************************************************
    CONSTANTS
***************************************************************************/

#define NTSC_CLOCK           N2A03_DEFAULTCLOCK     /* 1.789772 MHz */
#define PAL_CLOCK	           (26601712.0/16)        /* 1.662607 MHz */

#define NES_BATTERY_SIZE 0x2000


/***************************************************************************
    TYPE DEFINITIONS
***************************************************************************/

struct nes_input
{
	UINT32 shift;
	UINT32 i0, i1, i2;
};

/*PPU fast banking constants and structures */

#define CHRROM 0
#define CHRRAM 1


/*PPU nametable fast banking constants and structures */

#define CIRAM 0
#define ROM 1
#define EXRAM 2
#define MMC5FILL 3
#define CART_NTRAM 4

#define NES_BATTERY 0
#define NES_WRAM 1


class nes_state : public nes_carts_state
{
public:
	nes_state(const machine_config &mconfig, device_type type, const char *tag)
	: nes_carts_state(mconfig, type, tag) { }

	/* input_related - this part has to be cleaned up (e.g. in_2 and in_3 are not really necessary here...) */
	nes_input m_in_0, m_in_1, m_in_2, m_in_3;
	UINT8 m_fck_scan, m_fck_mode;

	/* video-related */
	int m_nes_vram_sprite[8]; /* Used only by mmc5 for now */
	int m_last_frame_flip;

	void init_nes_core();
	void pcb_handlers_setup();
	int pcb_initialize(int idx);
	int nes_pcb_reset();
	void update_prg_banks(int prg_bank_start, int prg_bank_end);

	DECLARE_WRITE8_MEMBER(nes_chr_w);
	DECLARE_READ8_MEMBER(nes_chr_r);
	DECLARE_WRITE8_MEMBER(nes_nt_w);
	DECLARE_READ8_MEMBER(nes_nt_r);
	DECLARE_WRITE8_MEMBER(nes_low_mapper_w);
	DECLARE_READ8_MEMBER(nes_low_mapper_r);

	/* misc */
	write8_delegate   m_mmc_write_low;
	write8_delegate   m_mmc_write_mid;
	write8_delegate   m_mmc_write;
	read8_delegate    m_mmc_read_low;
	read8_delegate    m_mmc_read_mid;
	read8_delegate    m_mmc_read;

	/***** FDS-floppy related *****/

	int     m_disk_expansion;

	UINT8   m_fds_sides;
	UINT8   *m_fds_data;	// here, we store a copy of the disk
	UINT8   *m_fds_ram;	// here, we emulate the RAM adapter

	/* Variables which can change */
	UINT8   m_fds_motor_on;
	UINT8   m_fds_door_closed;
	UINT8   m_fds_current_side;
	UINT32  m_fds_head_position;
	UINT8   m_fds_status0;
	UINT8   m_fds_read_mode;
	UINT8   m_fds_write_reg;

	/* these are used in the mapper 20 handlers */
	int     m_fds_last_side;
	int     m_fds_count;
	DECLARE_READ8_MEMBER(nes_IN0_r);
	DECLARE_READ8_MEMBER(nes_IN1_r);
	DECLARE_WRITE8_MEMBER(nes_IN0_w);
	DECLARE_WRITE8_MEMBER(nes_IN1_w);
	DECLARE_READ8_MEMBER(nes_fds_r);
	DECLARE_WRITE8_MEMBER(nes_fds_w);
	DECLARE_WRITE8_MEMBER(nes_vh_sprite_dma_w);
	DECLARE_DRIVER_INIT(famicom);
	virtual void machine_start();
	virtual void machine_stop();
	virtual void machine_reset();
	virtual void video_start();
	virtual void palette_init();
	UINT32 screen_update_nes(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	TIMER_CALLBACK_MEMBER(nes_irq_callback);
	TIMER_CALLBACK_MEMBER(lightgun_tick);
	DECLARE_READ8_MEMBER(psg_4015_r);
	DECLARE_WRITE8_MEMBER(psg_4015_w);
	DECLARE_WRITE8_MEMBER(psg_4017_w);

private:
	/* devices */
//  cpu_device        *m_maincpu;
//  ppu2c0x_device    *m_ppu;
//  device_t          *m_sound;
	device_t          *m_cart;
//  emu_timer         *m_irq_timer;
	ioport_port       *m_io_ctrlsel;
	memory_bank       *m_prg_bank_mem[5];
};

/*----------- defined in machine/nes.c -----------*/


/* protos */

DEVICE_IMAGE_LOAD(nes_cart);
DEVICE_START(nes_disk);
DEVICE_IMAGE_LOAD(nes_disk);
DEVICE_IMAGE_UNLOAD(nes_disk);

int nes_ppu_vidaccess( device_t *device, int address, int data );

void nes_partialhash(hash_collection &dest, const unsigned char *data, unsigned long length, const char *functions);


#endif /* NES_H_ */