summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/mouser.cpp
blob: 09896fc4bf061e9aea4392b8127a3907cb13975d (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
// license:BSD-3-Clause
// copyright-holders:Frank Palazzolo
/*******************************************************************************

     Mouser - Video Hardware:

     Character map with scrollable rows, 1024 possible characters.
        - index = byte from videoram + 2 bits from colorram)
        - (if row is scrolled, videoram is offset, colorram is not)
        - 16 4-color combinations for each char, from colorram

     15 Sprites controlled by 4-byte records
        - 16 4-color combinations
        - 2 banks of 64 sprite characters each

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

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

void mouser_state::mouser_palette(palette_device &palette) const
{
	uint8_t const *const color_prom = memregion("proms")->base();

	for (int i = 0; i < palette.entries(); i++)
	{
		int bit0, bit1, bit2;

		// red component
		bit0 = BIT(color_prom[i], 0);
		bit1 = BIT(color_prom[i], 1);
		bit2 = BIT(color_prom[i], 2);
		int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		// green component
		bit0 = BIT(color_prom[i], 3);
		bit1 = BIT(color_prom[i], 4);
		bit2 = BIT(color_prom[i], 5);
		int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;

		// blue component
		bit0 = BIT(color_prom[i], 6);
		bit1 = BIT(color_prom[i], 7);
		int const b = 0x4f * bit0 + 0xa8 * bit1;

		palette.set_pen_color(i, rgb_t(r, g, b));
	}
}

WRITE_LINE_MEMBER(mouser_state::flip_screen_x_w)
{
	flip_screen_x_set(!state);
}

WRITE_LINE_MEMBER(mouser_state::flip_screen_y_w)
{
	flip_screen_y_set(!state);
}

uint32_t mouser_state::screen_update_mouser(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	uint8_t const *const spriteram = m_spriteram;

	// for every character in the Video RAM
	for (int offs = 0x3ff; offs >= 0; offs--)
	{
		int sx = offs % 32;
		if (flip_screen_x())
			sx = 31 - sx;

		int sy = offs / 32;
		if (flip_screen_y())
			sy = 31 - sy;

		/* This bit of spriteram appears to be for row scrolling */
		/* Note: this is dependant on flipping in y */
		int const scrolled_y_position = (256 + 8*sy - spriteram[offs%32])%256;
		/* I think we still need to fetch the colorram bits to from the ram underneath, which is not scrolled */
		/* Ideally we would merge these on a pixel-by-pixel basis, but it's ok to do this char-by-char, */
		/* Since it's only for the MOUSER logo and it looks fine */
		/* Note: this is _not_ dependant on flipping */
		int const color_offs = offs % 32 + ((256 + 8 * (offs / 32) - spriteram[offs % 32] )% 256) / 8 * 32;

		m_gfxdecode->gfx(0)->opaque(bitmap,cliprect,
				m_videoram[offs] | (m_colorram[color_offs] >> 5) * 256 | ((m_colorram[color_offs] >> 4) & 1) * 512,
				m_colorram[color_offs]%16,
				flip_screen_x(),flip_screen_y(),
				8*sx,scrolled_y_position);
	}

	// There seem to be two sets of sprites, each decoded identically

	// This is the first set of 7 sprites
	for (int offs = 0x0084; offs < 0x00a0; offs += 4)
	{
		if (BIT(spriteram[offs + 1], 4))
		{
			int flipx = BIT(spriteram[offs], 6);
			int flipy = BIT(spriteram[offs], 7);

			int sx = spriteram[offs + 3];
			if (flip_screen_x())
			{
				flipx = !flipx;
				sx = 240 - sx;
			}

			int sy = 0xef - spriteram[offs + 2];
			if (flip_screen_y())
			{
				flipy = !flipy;
				sy = 238 - sy;
			}

			m_gfxdecode->gfx(1+((spriteram[offs+1]&0x20)>>5))->transpen(bitmap,cliprect,
					spriteram[offs]&0x3f,
					spriteram[offs+1]%16,
					flipx,flipy,
					sx,sy,0);
		}
	}

	// This is the second set of 8 sprites
	for (int offs = 0x00c4; offs < 0x00e4; offs += 4)
	{
		if (BIT(spriteram[offs + 1], 4))
		{
			int flipx = BIT(spriteram[offs], 6);
			int flipy = BIT(spriteram[offs], 7);

			int sx = spriteram[offs + 3];
			if (flip_screen_x())
			{
				flipx = !flipx;
				sx = 240 - sx;
			}

			int sy = 0xef - spriteram[offs + 2];
			if (flip_screen_y())
			{
				flipy = !flipy;
				sy = 238 - sy;
			}

			m_gfxdecode->gfx(1+((spriteram[offs+1]&0x20)>>5))->transpen(bitmap,cliprect,
					spriteram[offs]&0x3f,
					spriteram[offs+1]%16,
					flipx,flipy,
					sx,sy,0);
		}
	}

	return 0;
}