summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/sei_crtc.c
blob: 423c76109f83257df7e32f6d745f1c4d5cad957f (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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
/******************************************************************************************

Seibu Custom "CRT Controller" emulation

by Angelo Salese,based off the old D-Con video HW part by Bryan McPhail

The (likely) custom Seibu CRTC is used at least in the following games:
Raiden (probably the first game to use it)
*Sengoku Mahjong
*Good e Jong
*Tottemo de Jong
Blood Bros.
Sky Smasher
D-Con
SD Gundam Psycho Salamander no Kyoui
(all games in legionna.c)
(all games in raiden2.c)

The name "Seibu CRTC" is actually an agglomerate of all the Seibu Customs that are on the
single boards, most if not all of them are shared video chips in the aforementioned games.

TODO:
- Dynamic Resolution Change (xx10 register?)
- Dynamic Paging register probably incorrect,needs further investigation;
- Merge the aforementioned games and clean-up the code in these drivers;
- Merge the gfxdecode too?
- Fully understand remaining video registers;
- Are the xx80/xxc0 in some games (D-Con/Sengoku Mahjong) another bunch of registers?
- Investigate about the real name(s) of this Seibu "CRT Controller",and if it is really
  custom.

===========================================================================================

List of default vregs (title screen):

*Sengoku Mahjong:
8000:  000F 0013 009F 00BF 00FA 000F 00FA 00FF
8010:  007D 0006 0000 0002 0000 0000 0000 0000
8020:  0000 0000 0004 0000 0000 0000 0040 01FF
8030:  003E 01FF 003F 01FF 0040 0001 0034 0035
8040:  0000 A8A8 0003 1C37 0001 0000 0000 0000

*Tottemo de Jong
8000:  000F 000F 009F 00BF 00FA 000F 00FA 00FF
8010:  0076 0006 0000 0002 0000 0002 0006 0000
8020:  0000 0000 0000 0000 0000 0000 01C0 01FF
8030:  003E 01FF 003F 01FF 00C0 01FF 0034 003F
8040:  0000 A8A8 0003 1830 0001 0000 0000 0000

*Good e Jong
8040:  000F 000F 009F 00BF 00FA 000F 00FA 00FF
8050:  0076 0006 0000 0002 0000 0002 0006 0000
8060:  0000 00FA 0000 0000 0000 0000 01C0 01FF
8070:  003E 01FF 003F 01FF 00C0 01FF 0034 003F
8080:  0000 0000 0000 0000 0000 0000 0000 0000

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

#include "emu.h"
#include "includes/sei_crtc.h"

static tilemap_t *sc0_tilemap,*sc2_tilemap,*sc1_tilemap,*sc3_tilemap_0,*sc3_tilemap_1;
UINT16 *seibucrtc_sc0vram,*seibucrtc_sc1vram,*seibucrtc_sc2vram,*seibucrtc_sc3vram;
UINT16 *seibucrtc_vregs;
UINT16 seibucrtc_sc0bank;

/*******************************
*
* Macros for the video registers
*
*******************************/

/*******************************
* 0x1a - Layer Dynamic Paging?
*******************************/
#define SEIBU_CRTC_DYN_PAGING	(seibucrtc_vregs[0x001a/2])
#define SEIBU_CRTC_SC3_PAGE_SEL (SEIBU_CRTC_DYN_PAGING & 0x0002)

/*******************************
* 0x1c - Layer Enable
*******************************/
#define SEIBU_CRTC_LAYER_EN 	(seibucrtc_vregs[0x001c/2])
#define SEIBU_CRTC_ENABLE_SC0   (!(SEIBU_CRTC_LAYER_EN & 0x0001))
#define SEIBU_CRTC_ENABLE_SC2   (!(SEIBU_CRTC_LAYER_EN & 0x0002))
#define SEIBU_CRTC_ENABLE_SC1   (!(SEIBU_CRTC_LAYER_EN & 0x0004))
#define SEIBU_CRTC_ENABLE_SC3   (!(SEIBU_CRTC_LAYER_EN & 0x0008))
#define SEIBU_CRTC_ENABLE_SPR   (!(SEIBU_CRTC_LAYER_EN & 0x0010))

/************************************
* 0x20 - Screen 0 (BG) scroll x
************************************/
#define SEIBU_CRTC_SC0_SX	(seibucrtc_vregs[0x0020/2])

/************************************
* 0x22 - Screen 0 (BG) scroll y
************************************/
#define SEIBU_CRTC_SC0_SY	(seibucrtc_vregs[0x0022/2])

/************************************
* 0x24 - Screen 1 (FG) scroll x
************************************/
#define SEIBU_CRTC_SC1_SX	(seibucrtc_vregs[0x0024/2])

/************************************
* 0x26 - Screen 1 (FG) scroll y
************************************/
#define SEIBU_CRTC_SC1_SY	(seibucrtc_vregs[0x0026/2])

/************************************
* 0x28 - Screen 2 (MD) scroll x
************************************/
#define SEIBU_CRTC_SC2_SX	(seibucrtc_vregs[0x0028/2])

/************************************
* 0x2a - Screen 2 (MD) scroll y
************************************/
#define SEIBU_CRTC_SC2_SY	(seibucrtc_vregs[0x002a/2])

/************************************
* 0x2c - Fix screen scroll x (global)
************************************/
#define SEIBU_CRTC_FIX_SX	(seibucrtc_vregs[0x002c/2])

/************************************
* 0x2e - Fix screen scroll y (global)
************************************/
#define SEIBU_CRTC_FIX_SY	(seibucrtc_vregs[0x002e/2])


/*******************************
*
* Write RAM accesses
*
*******************************/

WRITE16_HANDLER( seibucrtc_sc0vram_w )
{
	COMBINE_DATA(&seibucrtc_sc0vram[offset]);
	tilemap_mark_tile_dirty(sc0_tilemap,offset);
}

WRITE16_HANDLER( seibucrtc_sc2vram_w )
{
	COMBINE_DATA(&seibucrtc_sc2vram[offset]);
	tilemap_mark_tile_dirty(sc2_tilemap,offset);
}

WRITE16_HANDLER( seibucrtc_sc1vram_w )
{
	COMBINE_DATA(&seibucrtc_sc1vram[offset]);
	tilemap_mark_tile_dirty(sc1_tilemap,offset);
}

WRITE16_HANDLER( seibucrtc_sc3vram_w )
{
	COMBINE_DATA(&seibucrtc_sc3vram[offset]);
	tilemap_mark_tile_dirty(sc3_tilemap_0,offset);
	tilemap_mark_tile_dirty(sc3_tilemap_1,offset);
}

WRITE16_HANDLER( seibucrtc_vregs_w )
{
	COMBINE_DATA(&seibucrtc_vregs[offset]);
}

/* Actually external from the CRTC */
void seibucrtc_sc0bank_w(UINT16 data)
{
	seibucrtc_sc0bank = data & 1;
	tilemap_mark_all_tiles_dirty(sc0_tilemap);
}


/*******************************
*
* Tilemap info accesses
*
*******************************/

static TILE_GET_INFO( seibucrtc_sc0_tile_info )
{
	int tile = seibucrtc_sc0vram[tile_index] & 0xfff;
	int color = (seibucrtc_sc0vram[tile_index] >> 12) & 0x0f;
	tile+=(seibucrtc_sc0bank<<12);
	SET_TILE_INFO(1, tile, color, 0);
}

static TILE_GET_INFO( seibucrtc_sc2_tile_info )
{
	int tile = seibucrtc_sc2vram[tile_index] & 0xfff;
	int color = (seibucrtc_sc2vram[tile_index] >> 12) & 0x0f;
	SET_TILE_INFO(2, tile, color, 0);
}

static TILE_GET_INFO( seibucrtc_sc1_tile_info )
{
	int tile = seibucrtc_sc1vram[tile_index] & 0xfff;
	int color = (seibucrtc_sc1vram[tile_index] >> 12) & 0x0f;
	SET_TILE_INFO(3, tile, color, 0);
}

static TILE_GET_INFO( seibucrtc_sc3_tile_info )
{
	int tile = seibucrtc_sc3vram[tile_index] & 0xfff;
	int color = (seibucrtc_sc3vram[tile_index] >> 12) & 0x0f;
	SET_TILE_INFO(4, tile, color, 0);
}

static void draw_sprites(running_machine &machine, bitmap_t *bitmap,const rectangle *cliprect,int pri)
{
	UINT16 *spriteram16 = reinterpret_cast<UINT16 *>(memory_get_shared(machine, "spriteram"));
	int offs,fx,fy,x,y,color,sprite;
	int dx,dy,ax,ay;

	for (offs = 0x400-4;offs >= 0;offs -= 4)
	{
		if ((spriteram16[offs+0]&0x8000)!=0x8000) continue;
		sprite = spriteram16[offs+1];
		if ((sprite>>14)!=pri) continue;
		sprite &= 0x1fff;

		y = spriteram16[offs+3];
		x = spriteram16[offs+2];

		if (x&0x8000) x=0-(0x200-(x&0x1ff));
		else x&=0x1ff;
		if (y&0x8000) y=0-(0x200-(y&0x1ff));
		else y&=0x1ff;

		color = spriteram16[offs+0]&0x3f;
		fx = spriteram16[offs+0]&0x4000;
		fy = spriteram16[offs+0]&0x2000;
		dy=((spriteram16[offs+0]&0x0380)>>7)+1;
		dx=((spriteram16[offs+0]&0x1c00)>>10)+1;

		for (ax=0; ax<dx; ax++)
			for (ay=0; ay<dy; ay++) {
				if (!fx)
					drawgfx_transpen(bitmap,cliprect,machine.gfx[0],
						sprite++,
						color,fx,fy,x+ax*16,y+ay*16,15);
				else
					drawgfx_transpen(bitmap,cliprect,machine.gfx[0],
						sprite++,
						color,fx,fy,x+(dx-1-ax)*16,y+ay*16,15);
			}
	}
}

/***********************************
*
* VIDEO_START/VIDEO_UPDATE functions
*
***********************************/

VIDEO_START( seibu_crtc )
{
	sc0_tilemap = tilemap_create(machine, seibucrtc_sc0_tile_info,tilemap_scan_rows,16,16,32,32);
	sc2_tilemap = tilemap_create(machine, seibucrtc_sc2_tile_info,tilemap_scan_rows,16,16,32,32);
	sc1_tilemap = tilemap_create(machine, seibucrtc_sc1_tile_info,tilemap_scan_rows,16,16,32,32);
	sc3_tilemap_0 = tilemap_create(machine, seibucrtc_sc3_tile_info,tilemap_scan_rows, 8, 8,32,32);
	sc3_tilemap_1 = tilemap_create(machine, seibucrtc_sc3_tile_info,tilemap_scan_rows, 8, 8,64,32);

	tilemap_set_transparent_pen(sc2_tilemap,15);
	tilemap_set_transparent_pen(sc1_tilemap,15);
	tilemap_set_transparent_pen(sc3_tilemap_0,15);
	tilemap_set_transparent_pen(sc3_tilemap_1,15);

	seibucrtc_sc0bank = 0;
}

SCREEN_UPDATE( seibu_crtc )
{
	bitmap_fill(bitmap, cliprect, screen->machine().pens[0x7ff]); //black pen

	tilemap_set_scrollx( sc0_tilemap,0, (SEIBU_CRTC_SC0_SX + SEIBU_CRTC_FIX_SX+64) & 0x1ff );
	tilemap_set_scrolly( sc0_tilemap,0, (SEIBU_CRTC_SC0_SY + SEIBU_CRTC_FIX_SY+1) & 0x1ff );
	tilemap_set_scrollx( sc2_tilemap,0, (SEIBU_CRTC_SC2_SX + SEIBU_CRTC_FIX_SX+64) & 0x1ff );
	tilemap_set_scrolly( sc2_tilemap,0, (SEIBU_CRTC_SC2_SY + SEIBU_CRTC_FIX_SY+1) & 0x1ff );
	tilemap_set_scrollx( sc1_tilemap,0, (SEIBU_CRTC_SC1_SX + SEIBU_CRTC_FIX_SX+64) & 0x1ff );
	tilemap_set_scrolly( sc1_tilemap,0, (SEIBU_CRTC_SC1_SY + SEIBU_CRTC_FIX_SY+1) & 0x1ff );
	tilemap_set_scrollx( SEIBU_CRTC_SC3_PAGE_SEL ? sc3_tilemap_0 : sc3_tilemap_1,0, (SEIBU_CRTC_FIX_SX+64) & 0x1ff );
	tilemap_set_scrolly( SEIBU_CRTC_SC3_PAGE_SEL ? sc3_tilemap_0 : sc3_tilemap_1,0, (SEIBU_CRTC_FIX_SY+1) & 0x1ff );

	if(SEIBU_CRTC_ENABLE_SC0) { tilemap_draw(bitmap,cliprect,sc0_tilemap,0,0); }
	if(SEIBU_CRTC_ENABLE_SPR) { draw_sprites(screen->machine(), bitmap,cliprect, 2); }
	if(SEIBU_CRTC_ENABLE_SC2) { tilemap_draw(bitmap,cliprect,sc2_tilemap,0,0); }
	if(SEIBU_CRTC_ENABLE_SPR) { draw_sprites(screen->machine(), bitmap,cliprect, 1); }
	if(SEIBU_CRTC_ENABLE_SC1) { tilemap_draw(bitmap,cliprect,sc1_tilemap,0,0); }
	if(SEIBU_CRTC_ENABLE_SPR) { draw_sprites(screen->machine(), bitmap,cliprect, 0); }
	if(SEIBU_CRTC_ENABLE_SC3) { tilemap_draw(bitmap,cliprect,SEIBU_CRTC_SC3_PAGE_SEL ? sc3_tilemap_0 : sc3_tilemap_1,0,0); }
	if(SEIBU_CRTC_ENABLE_SPR) { draw_sprites(screen->machine(), bitmap,cliprect, 3); }

	return 0;
}