summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/includes/sms.h
blob: 2dafd6a0022237982394321a6c2784b97f86560a (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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*****************************************************************************
 *
 * includes/sms.h
 *
 ****************************************************************************/

#ifndef SMS_H_
#define SMS_H_

#define LOG_REG
#define LOG_PAGING
#define LOG_COLOR

#define NVRAM_SIZE             (0x08000)
#define CPU_ADDRESSABLE_SIZE   (0x10000)

#define MAX_CARTRIDGES        16

#include "machine/sega8_slot.h"


class sms_state : public driver_device
{
public:
	enum
	{
		TIMER_RAPID_FIRE,
		TIMER_LIGHTGUN_TICK,
		TIMER_LPHASER_1,
		TIMER_LPHASER_2
	};

	sms_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
		m_maincpu(*this, "maincpu"),
		m_vdp(*this, "sms_vdp"),
		m_ym(*this, "ym2413"),
		m_main_scr(*this, "screen"),
		m_mainram(*this, "mainram"),
		m_cartslot(*this, "slot"),
		m_card(*this, "mycard"),
		m_region_maincpu(*this, "maincpu"),
		m_port_dd(*this, "PORT_DD"),
		m_port_dc(*this, "PORT_DC"),
		m_port_pause(*this, "PAUSE"),
		m_port_reset(*this, "RESET"),
		m_port_start(*this, "START"),
		m_port_ctrlsel(*this, "CTRLSEL"),
		m_port_lphas0(*this, "LPHASER0"),
		m_port_lphas1(*this, "LPHASER1"),
		m_port_lphas2(*this, "LPHASER2"),
		m_port_lphas3(*this, "LPHASER3"),
		m_port_rfu(*this, "RFU"),
		m_port_paddle0(*this, "PADDLE0"),
		m_port_paddle1(*this, "PADDLE1"),
		m_port_ctrlipt(*this, "CTRLIPT"),
		m_port_sport0(*this, "SPORT0"),
		m_port_sport1(*this, "SPORT1"),
		m_port_sport2(*this, "SPORT2"),
		m_port_sport3(*this, "SPORT3"),
		m_port_scope(*this, "SEGASCOPE"),
		m_port_persist(*this, "PERSISTENCE"),
		m_is_gamegear(0),
		m_is_region_japan(0),
		m_is_sdisp(0),
		m_has_bios_0400(0),
		m_has_bios_2000(0),
		m_has_bios_full(0),
		m_has_bios(0),
		m_has_fm(0) { }

	// devices
	required_device<cpu_device> m_maincpu;
	required_device<sega315_5124_device> m_vdp;
	optional_device<ym2413_device> m_ym;
	required_device<screen_device> m_main_scr;
	required_shared_ptr<UINT8> m_mainram;
	required_device<sega8_cart_slot_device> m_cartslot;
	optional_device<sega8_card_slot_device> m_card;
	required_memory_region m_region_maincpu;
	required_ioport m_port_dd;
	required_ioport m_port_dc;
	optional_ioport m_port_pause;
	optional_ioport m_port_reset;
	optional_ioport m_port_start;
	optional_ioport m_port_ctrlsel;
	optional_ioport m_port_lphas0;
	optional_ioport m_port_lphas1;
	optional_ioport m_port_lphas2;
	optional_ioport m_port_lphas3;
	optional_ioport m_port_rfu;
	optional_ioport m_port_paddle0;
	optional_ioport m_port_paddle1;
	optional_ioport m_port_ctrlipt;
	optional_ioport m_port_sport0;
	optional_ioport m_port_sport1;
	optional_ioport m_port_sport2;
	optional_ioport m_port_sport3;
	optional_ioport m_port_scope;
	optional_ioport m_port_persist;

	device_t *m_left_lcd;
	device_t *m_right_lcd;
	address_space *m_space;
	
	UINT8 m_bios_page_count;
	UINT8 m_fm_detect;
	UINT8 m_ctrl_reg;
	int m_paused;
	UINT8 m_bios_port;
	UINT8 *m_BIOS;
	UINT8 m_mapper[4];
	UINT8 m_input_port0;
	UINT8 m_input_port1;
	UINT8 m_gg_sio[5];
	
	// [0] for 0x400-0x3fff, [1] for 0x4000-0x7fff, [2] for 0x8000-0xffff, [3] for 0x0000-0x0400
	int m_bank_enabled[4];
	UINT8 m_bios_page[4];
	
	// for gamegear LCD persistence hack
	bitmap_rgb32 m_prev_bitmap;

	// for 3D glass binocular hack
	bitmap_rgb32 m_prevleft_bitmap;
	bitmap_rgb32 m_prevright_bitmap;

	// model identifiers
	UINT8 m_is_gamegear;
	UINT8 m_is_region_japan;
	UINT8 m_is_sdisp;
	UINT8 m_has_bios_0400;
	UINT8 m_has_bios_2000;
	UINT8 m_has_bios_full;
	UINT8 m_has_bios;
	UINT8 m_has_fm;

	// Data needed for Rapid Fire Unit support
	emu_timer *m_rapid_fire_timer;
	UINT8 m_rapid_fire_state_1;
	UINT8 m_rapid_fire_state_2;

	// Data needed for Paddle Control controller
	UINT32 m_last_paddle_read_time;
	UINT8 m_paddle_read_state;

	// Data needed for Sports Pad controller
	UINT32 m_last_sports_pad_time_1;
	UINT32 m_last_sports_pad_time_2;
	UINT8 m_sports_pad_state_1;
	UINT8 m_sports_pad_state_2;
	UINT8 m_sports_pad_last_data_1;
	UINT8 m_sports_pad_last_data_2;
	UINT8 m_sports_pad_1_x;
	UINT8 m_sports_pad_1_y;
	UINT8 m_sports_pad_2_x;
	UINT8 m_sports_pad_2_y;

	// Data needed for Light Phaser
	emu_timer *m_lphaser_1_timer;
	emu_timer *m_lphaser_2_timer;
	UINT8 m_lphaser_1_latch;
	UINT8 m_lphaser_2_latch;
	int m_lphaser_x_offs;   /* Needed to 'calibrate' lphaser; set at cart loading */

	// Data needed for SegaScope (3D glasses)
	UINT8 m_sscope_state;
	UINT8 m_frame_sscope_state;

	// these are only used by the Store Display unit, but we keep them here temporarily to avoid the need of separate start/reset
	UINT8 m_store_control;	
	int m_current_cartridge;
	sega8_cart_slot_device *m_slots[16];
	sega8_card_slot_device *m_cards[16];

	/* Cartridge slot info */
	DECLARE_WRITE8_MEMBER(sms_input_write);
	DECLARE_WRITE8_MEMBER(sms_fm_detect_w);
	DECLARE_READ8_MEMBER(sms_fm_detect_r);
	DECLARE_WRITE8_MEMBER(sms_io_control_w);
	DECLARE_READ8_MEMBER(sms_count_r);
	DECLARE_READ8_MEMBER(sms_input_port_0_r);
	DECLARE_READ8_MEMBER(sms_input_port_1_r);
	DECLARE_WRITE8_MEMBER(sms_ym2413_register_port_0_w);
	DECLARE_WRITE8_MEMBER(sms_ym2413_data_port_0_w);
	DECLARE_READ8_MEMBER(gg_input_port_2_r);
	DECLARE_READ8_MEMBER(sms_sscope_r);
	DECLARE_WRITE8_MEMBER(sms_sscope_w);
	DECLARE_READ8_MEMBER(sms_mapper_r);

	DECLARE_READ8_MEMBER(read_0000);
	DECLARE_READ8_MEMBER(read_4000);
	DECLARE_READ8_MEMBER(read_8000);
	DECLARE_WRITE8_MEMBER(write_cart);

	DECLARE_WRITE8_MEMBER(sms_mapper_w);
	DECLARE_WRITE8_MEMBER(sms_bios_w);
	DECLARE_WRITE8_MEMBER(gg_sio_w);
	DECLARE_READ8_MEMBER(gg_sio_r);
	DECLARE_DRIVER_INIT(sg1000m3);
	DECLARE_DRIVER_INIT(gamegear);
	DECLARE_DRIVER_INIT(gamegeaj);
	DECLARE_DRIVER_INIT(sms2kr);
	DECLARE_DRIVER_INIT(smsj);
	DECLARE_DRIVER_INIT(sms1);
	DECLARE_MACHINE_START(sms);
	DECLARE_MACHINE_RESET(sms);
	DECLARE_VIDEO_START(gamegear);
	DECLARE_VIDEO_START(sms1);
	UINT32 screen_update_gamegear(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
	UINT32 screen_update_sms(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
	UINT32 screen_update_sms1(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
	void screen_vblank_sms1(screen_device &screen, bool state);
	DECLARE_INPUT_CHANGED_MEMBER(lgun1_changed);
	DECLARE_INPUT_CHANGED_MEMBER(lgun2_changed);
	TIMER_CALLBACK_MEMBER(rapid_fire_callback);
	TIMER_CALLBACK_MEMBER(lightgun_tick);
	TIMER_CALLBACK_MEMBER(lphaser_1_callback);
	TIMER_CALLBACK_MEMBER(lphaser_2_callback);
	DECLARE_WRITE_LINE_MEMBER(sms_int_callback);
	DECLARE_WRITE_LINE_MEMBER(sms_pause_callback);

protected:
	void setup_bios();
	void setup_rom();
	void setup_sms_cart();
	void lphaser_hcount_latch(int hpos);
	void lphaser1_sensor_check();
	void lphaser2_sensor_check();
	UINT16 screen_hpos_nonscaled(int scaled_hpos);
	UINT16 screen_vpos_nonscaled(int scaled_vpos);
	int lgun_bright_aim_area(emu_timer *timer, int lgun_x, int lgun_y);
	void sms_get_inputs(address_space &space);
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
};

class smssdisp_state : public sms_state
{
public:
	smssdisp_state(const machine_config &mconfig, device_type type, const char *tag)
	: sms_state(mconfig, type, tag),
	m_control_cpu(*this, "control")
	{ }
	
	required_device<cpu_device> m_control_cpu;

	DECLARE_READ8_MEMBER(sms_store_cart_select_r);
	DECLARE_WRITE8_MEMBER(sms_store_cart_select_w);
	DECLARE_READ8_MEMBER(sms_store_select1);
	DECLARE_READ8_MEMBER(sms_store_select2);
	DECLARE_READ8_MEMBER(sms_store_control_r);
	DECLARE_WRITE8_MEMBER(sms_store_control_w);
	DECLARE_DRIVER_INIT(smssdisp);
	
	DECLARE_READ8_MEMBER(store_read_0000);
	DECLARE_READ8_MEMBER(store_read_4000);
	DECLARE_READ8_MEMBER(store_read_8000);
	DECLARE_READ8_MEMBER(store_cart_peek);
	DECLARE_WRITE8_MEMBER(store_write_cart);
	
	DECLARE_WRITE_LINE_MEMBER(sms_store_int_callback);
};


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

#define IO_EXPANSION    (0x80)  /* Expansion slot enable (1= disabled, 0= enabled) */
#define IO_CARTRIDGE    (0x40)  /* Cartridge slot enable (1= disabled, 0= enabled) */
#define IO_CARD         (0x20)  /* Card slot disabled (1= disabled, 0= enabled) */
#define IO_WORK_RAM     (0x10)  /* Work RAM disabled (1= disabled, 0= enabled) */
#define IO_BIOS_ROM     (0x08)  /* BIOS ROM disabled (1= disabled, 0= enabled) */
#define IO_CHIP         (0x04)  /* I/O chip disabled (1= disabled, 0= enabled) */

#endif /* SMS_H_ */