summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/includes/wswan.h
blob: f134e1a8018be7755629c3290e26f87325a4621b (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
/*****************************************************************************
 *
 * includes/wswan.h
 *
 ****************************************************************************/

#ifndef WSWAN_H_
#define WSWAN_H_

#define WSWAN_TYPE_MONO 0
#define WSWAN_TYPE_COLOR 1

#define WSWAN_X_PIXELS	(28*8)
#define WSWAN_Y_PIXELS	(18*8)

/* Interrupt flags */
#define WSWAN_IFLAG_STX    0x1
#define WSWAN_IFLAG_KEY    0x2
#define WSWAN_IFLAG_RTC    0x4
#define WSWAN_IFLAG_SRX    0x8
#define WSWAN_IFLAG_LCMP   0x10
#define WSWAN_IFLAG_VBLTMR 0x20
#define WSWAN_IFLAG_VBL    0x40
#define WSWAN_IFLAG_HBLTMR 0x80
/* Interrupts */
#define WSWAN_INT_STX    0
#define WSWAN_INT_KEY    1
#define WSWAN_INT_RTC    2
#define WSWAN_INT_SRX    3
#define WSWAN_INT_LCMP   4
#define WSWAN_INT_VBLTMR 5
#define WSWAN_INT_VBL    6
#define WSWAN_INT_HBLTMR 7

#define INTERNAL_EEPROM_SIZE	1024

#include "emu.h"
#include "cpu/v30mz/v30mz.h"
#include "imagedev/cartslot.h"
#include "machine/nvram.h"


struct EEPROM
{
	UINT8	mode;		/* eeprom mode */
	UINT16	address;	/* Read/write address */
	UINT8	command;	/* Commands: 00, 01, 02, 03, 04, 08, 0C */
	UINT8	start;		/* start bit */
	UINT8	write_enabled;	/* write enabled yes/no */
	int	size;		/* size of eeprom/sram area */
	UINT8	*data;		/* pointer to start of sram/eeprom data */
	UINT8	*page;		/* pointer to current sram/eeprom page */
};

struct RTC
{
	UINT8	present;	/* Is an RTC present */
	UINT8	setting;	/* Timer setting byte */
	UINT8	year;		/* Year */
	UINT8	month;		/* Month */
	UINT8	day;		/* Day */
	UINT8	day_of_week;	/* Day of the week */
	UINT8	hour;		/* Hour, high bit = 0 => AM, high bit = 1 => PM */
	UINT8	minute;		/* Minute */
	UINT8	second;		/* Second */
	UINT8	index;		/* index for reading/writing of current of alarm time */
};

struct SoundDMA
{
	UINT32	source;		/* Source address */
	UINT16	size;		/* Size */
	UINT8	enable;		/* Enabled */
};

struct VDP
{
	UINT8 layer_bg_enable;			/* Background layer on/off */
	UINT8 layer_fg_enable;			/* Foreground layer on/off */
	UINT8 sprites_enable;			/* Sprites on/off */
	UINT8 window_sprites_enable;		/* Sprite window on/off */
	UINT8 window_fg_mode;			/* 0:inside/outside, 1:??, 2:inside, 3:outside */
	UINT8 current_line;			/* Current scanline : 0-158 (159?) */
	UINT8 line_compare;			/* Line to trigger line interrupt on */
	UINT32 sprite_table_address;		/* Address of the sprite table */
	UINT8 sprite_table_buffer[512];
	UINT8 sprite_first;			/* First sprite to draw */
	UINT8 sprite_count;			/* Number of sprites to draw */
	UINT16 layer_bg_address;		/* Address of the background screen map */
	UINT16 layer_fg_address;		/* Address of the foreground screen map */
	UINT8 window_fg_left;			/* Left coordinate of foreground window */
	UINT8 window_fg_top;			/* Top coordinate of foreground window */
	UINT8 window_fg_right;			/* Right coordinate of foreground window */
	UINT8 window_fg_bottom;			/* Bottom coordinate of foreground window */
	UINT8 window_sprites_left;		/* Left coordinate of sprites window */
	UINT8 window_sprites_top;		/* Top coordinate of sprites window */
	UINT8 window_sprites_right;		/* Right coordinate of sprites window */
	UINT8 window_sprites_bottom;		/* Bottom coordinate of sprites window */
	UINT8 layer_bg_scroll_x;		/* Background layer X scroll */
	UINT8 layer_bg_scroll_y;		/* Background layer Y scroll */
	UINT8 layer_fg_scroll_x;		/* Foreground layer X scroll */
	UINT8 layer_fg_scroll_y;		/* Foreground layer Y scroll */
	UINT8 lcd_enable;			/* LCD on/off */
	UINT8 icons;				/* FIXME: What do we do with these? Maybe artwork? */
	UINT8 color_mode;			/* monochrome/color mode */
	UINT8 colors_16;			/* 4/16 colors mode */
	UINT8 tile_packed;			/* layered/packed tile mode switch */
	UINT8 timer_hblank_enable;		/* Horizontal blank interrupt on/off */
	UINT8 timer_hblank_mode;		/* Horizontal blank timer mode */
	UINT16 timer_hblank_reload;		/* Horizontal blank timer reload value */
	UINT16 timer_hblank_count;		/* Horizontal blank timer counter value */
	UINT8 timer_vblank_enable;		/* Vertical blank interrupt on/off */
	UINT8 timer_vblank_mode;		/* Vertical blank timer mode */
	UINT16 timer_vblank_reload;		/* Vertical blank timer reload value */
	UINT16 timer_vblank_count;		/* Vertical blank timer counter value */
	UINT8 *vram;				/* pointer to start of ram/vram (set by MACHINE_RESET) */
	UINT8 *palette_vram;			/* pointer to start of palette area in ram/vram (set by MACHINE_RESET), WSC only */
	int main_palette[8];
	emu_timer *timer;
};

class wswan_state : public driver_device
{
public:
	wswan_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
	m_maincpu(*this, "maincpu")
	{ }

	virtual void video_start();

	UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);

	required_device<cpu_device> m_maincpu;
	DECLARE_READ8_MEMBER(wswan_port_r);
	DECLARE_WRITE8_MEMBER(wswan_port_w);
	DECLARE_READ8_MEMBER(wswan_sram_r);
	DECLARE_WRITE8_MEMBER(wswan_sram_w);
	VDP m_vdp;
	UINT8 m_ws_portram[256];
	UINT8 *m_ROMMap[256];
	UINT32 m_ROMBanks;
	UINT8 m_internal_eeprom[INTERNAL_EEPROM_SIZE];
	UINT8 m_system_type;
	EEPROM m_eeprom;
	RTC m_rtc;
	SoundDMA m_sound_dma;
	UINT8 *m_ws_ram;
	UINT8 *m_ws_bios_bank;
	UINT8 m_bios_disabled;
	int m_pal[16][16];
	bitmap_ind16 m_bitmap;
	UINT8 m_rotate;
	void wswan_clear_irq_line(int irq);
	virtual void machine_start();
	virtual void machine_reset();
	virtual void palette_init();
	DECLARE_MACHINE_START(wscolor);
	DECLARE_PALETTE_INIT(wscolor);
};


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




DEVICE_START(wswan_cart);
DEVICE_IMAGE_LOAD(wswan_cart);


/*----------- defined in video/wswan.c -----------*/

void wswan_refresh_scanline( running_machine &machine );


/*----------- defined in audio/wswan.c -----------*/

class wswan_sound_device : public device_t,
                                  public device_sound_interface
{
public:
	wswan_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
	~wswan_sound_device() { global_free(m_token); }

	// access to legacy token
	void *token() const { assert(m_token != NULL); return m_token; }
protected:
	// device-level overrides
	virtual void device_config_complete();
	virtual void device_start();

	// sound stream update overrides
	virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
private:
	// internal state
	void *m_token;
};

extern const device_type WSWAN;


WRITE8_DEVICE_HANDLER( wswan_sound_port_w );

#endif /* WSWAN_H_ */