summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/zac2650.c
blob: baf218d4e492f9d5150ee9b93727db404605b5e1 (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
/*************************************************************/
/*                                                           */
/* Zaccaria/Zelco S2650 based games video                    */
/*                                                           */
/*************************************************************/

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


/**************************************************************/
/* The S2636 is a standard sprite chip used by several boards */
/* Emulation of this chip may be moved into a separate unit   */
/* once it's workings are fully understood.                   */
/**************************************************************/

WRITE8_MEMBER(zac2650_state::tinvader_videoram_w)
{
	m_videoram[offset] = data;
	m_bg_tilemap->mark_tile_dirty(offset);
}

READ8_MEMBER(zac2650_state::zac_s2636_r)
{
	if(offset!=0xCB) return m_s2636_0_ram[offset];
	else return m_CollisionSprite;
}

WRITE8_MEMBER(zac2650_state::zac_s2636_w)
{
	m_s2636_0_ram[offset] = data;
	m_gfxdecode->gfx(1)->mark_dirty(offset/8);
	m_gfxdecode->gfx(2)->mark_dirty(offset/8);
	if (offset == 0xc7)
	{
		m_s2636->soundport_w(0, data);
	}
}

READ8_MEMBER(zac2650_state::tinvader_port_0_r)
{
	return ioport("1E80")->read() - m_CollisionBackground;
}

/*****************************************/
/* Check for Collision between 2 sprites */
/*****************************************/

int zac2650_state::SpriteCollision(int first,int second)
{
	int Checksum=0;
	int x,y;
	const rectangle &visarea = m_screen->visible_area();

	if((m_s2636_0_ram[first * 0x10 + 10] < 0xf0) && (m_s2636_0_ram[second * 0x10 + 10] < 0xf0))
	{
		int fx     = (m_s2636_0_ram[first * 0x10 + 10] * 4)-22;
		int fy     = (m_s2636_0_ram[first * 0x10 + 12] * 3)+3;
		int expand = (first==1) ? 2 : 1;

		/* Draw first sprite */

		m_gfxdecode->gfx(expand)->opaque(m_spritebitmap,m_spritebitmap.cliprect(),
				first * 2,
				0,
				0,0,
				fx,fy);

		/* Get fingerprint */

		for (x = fx; x < fx + m_gfxdecode->gfx(expand)->width(); x++)
		{
			for (y = fy; y < fy + m_gfxdecode->gfx(expand)->height(); y++)
			{
				if (visarea.contains(x, y))
					Checksum += m_spritebitmap.pix16(y, x);
			}
		}

		/* Blackout second sprite */

		m_gfxdecode->gfx(1)->transpen(m_spritebitmap,m_spritebitmap.cliprect(),
				second * 2,
				1,
				0,0,
				(m_s2636_0_ram[second * 0x10 + 10] * 4)-22,(m_s2636_0_ram[second * 0x10 + 12] * 3) + 3, 0);

		/* Remove fingerprint */

		for (x = fx; x < fx + m_gfxdecode->gfx(expand)->width(); x++)
		{
			for (y = fy; y < fy +m_gfxdecode->gfx(expand)->height(); y++)
			{
				if (visarea.contains(x, y))
					Checksum -= m_spritebitmap.pix16(y, x);
			}
		}

		/* Zero bitmap */

		m_gfxdecode->gfx(expand)->opaque(m_spritebitmap,m_spritebitmap.cliprect(),
				first * 2,
				1,
				0,0,
				fx,fy);
	}

	return Checksum;
}

TILE_GET_INFO_MEMBER(zac2650_state::get_bg_tile_info)
{
	int code = m_videoram[tile_index];

	SET_TILE_INFO_MEMBER(0, code, 0, 0);
}

void zac2650_state::video_start()
{
	m_bg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(zac2650_state::get_bg_tile_info),this), TILEMAP_SCAN_ROWS,
			24, 24, 32, 32);

	m_screen->register_screen_bitmap(m_bitmap);
	m_screen->register_screen_bitmap(m_spritebitmap);

	m_gfxdecode->gfx(1)->set_source(m_s2636_0_ram);
	m_gfxdecode->gfx(2)->set_source(m_s2636_0_ram);

	save_item(NAME(m_bitmap));
	save_item(NAME(m_spritebitmap));
	save_item(NAME(m_CollisionBackground));
	save_item(NAME(m_CollisionSprite));
}

void zac2650_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int offs;
	const rectangle &visarea = m_screen->visible_area();

	/* -------------------------------------------------------------- */
	/* There seems to be a strange setup with this board, in that it  */
	/* appears that the S2636 runs from a different clock than the    */
	/* background generator, When the program maps sprite position to */
	/* character position it only has 6 pixels of sprite for 8 pixels */
	/* of character.                                                  */
	/* -------------------------------------------------------------- */
	/* n.b. The original has several graphic glitches as well, so it  */
	/* does not seem to be a fault of the emulation!                  */
	/* -------------------------------------------------------------- */

	m_CollisionBackground = 0;   /* Read from 0x1e80 bit 7 */

	// for collision detection checking
	copybitmap(m_bitmap,bitmap,0,0,0,0,visarea);

	for(offs=0;offs<0x50;offs+=0x10)
	{
		if((m_s2636_0_ram[offs+10]<0xF0) && (offs!=0x30))
		{
			int spriteno = (offs / 8);
			int expand   = ((m_s2636_0_ram[0xc0] & (spriteno*2))!=0) ? 2 : 1;
			int bx       = (m_s2636_0_ram[offs+10] * 4) - 22;
			int by       = (m_s2636_0_ram[offs+12] * 3) + 3;
			int x,y;

			/* Sprite->Background collision detection */
			m_gfxdecode->gfx(expand)->transpen(bitmap,cliprect,
					spriteno,
					1,
					0,0,
					bx,by, 0);

			for (x = bx; x < bx + m_gfxdecode->gfx(expand)->width(); x++)
			{
				for (y = by; y < by +m_gfxdecode->gfx(expand)->height(); y++)
				{
					if (visarea.contains(x, y))
						if (bitmap.pix16(y, x) != m_bitmap.pix16(y, x))
						{
							m_CollisionBackground = 0x80;
							break;
						}
				}
			}

			m_gfxdecode->gfx(expand)->transpen(bitmap,cliprect,
					spriteno,
					0,
					0,0,
					bx,by, 0);
		}
	}

	/* Sprite->Sprite collision detection */
	m_CollisionSprite = 0;
//  if(SpriteCollision(0,1)) m_CollisionSprite |= 0x20;   /* Not Used */
	if(SpriteCollision(0,2)) m_CollisionSprite |= 0x10;
	if(SpriteCollision(0,4)) m_CollisionSprite |= 0x08;
	if(SpriteCollision(1,2)) m_CollisionSprite |= 0x04;
	if(SpriteCollision(1,4)) m_CollisionSprite |= 0x02;
//  if(SpriteCollision(2,4)) m_CollisionSprite |= 0x01;   /* Not Used */
}

UINT32 zac2650_state::screen_update_tinvader(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
	draw_sprites(bitmap, cliprect);
	return 0;
}