1 // license:BSD-3-Clause
2 // copyright-holders:Manuel Abadia
3 #include "emu.h"
4 #include "includes/xorworld.h"
5 
6 
7 /***************************************************************************
8 
9   Convert the color PROMs into a more useable format.
10 
11   Xor World has three 256x4 palette PROMs (one per gun).
12   The palette PROMs are connected to the RGB output this way:
13 
14   bit 3 -- 220 ohm resistor  -- RED/GREEN/BLUE
15         -- 460 ohm resistor  -- RED/GREEN/BLUE
16         -- 1  kohm resistor  -- RED/GREEN/BLUE
17   bit 0 -- 2.2kohm resistor  -- RED/GREEN/BLUE
18 
19 ***************************************************************************/
20 
xorworld_palette(palette_device & palette) const21 void xorworld_state::xorworld_palette(palette_device &palette) const
22 {
23 	const uint8_t *color_prom = memregion("proms")->base();
24 
25 	for (int i = 0; i < palette.entries(); i++)
26 	{
27 		int bit0, bit1, bit2, bit3;
28 
29 		// red component
30 		bit0 = BIT(color_prom[0], 0);
31 		bit1 = BIT(color_prom[0], 1);
32 		bit2 = BIT(color_prom[0], 2);
33 		bit3 = BIT(color_prom[0], 3);
34 		int const r = 0x0e*bit0 + 0x1e*bit1 + 0x44*bit2 + 0x8f*bit3;
35 		// green component
36 		bit0 = BIT(color_prom[palette.entries()], 0);
37 		bit1 = BIT(color_prom[palette.entries()], 1);
38 		bit2 = BIT(color_prom[palette.entries()], 2);
39 		bit3 = BIT(color_prom[palette.entries()], 3);
40 		int const g = 0x0e*bit0 + 0x1e*bit1 + 0x44*bit2 + 0x8f*bit3;
41 		// blue component
42 		bit0 = BIT(color_prom[2 * palette.entries()], 0);
43 		bit1 = BIT(color_prom[2 * palette.entries()], 1);
44 		bit2 = BIT(color_prom[2 * palette.entries()], 2);
45 		bit3 = BIT(color_prom[2 * palette.entries()], 3);
46 		int const b = 0x0e*bit0 + 0x1e * bit1 + 0x44*bit2 + 0x8f*bit3;
47 		palette.set_pen_color(i, rgb_t(r, g, b));
48 
49 		color_prom++;
50 	}
51 }
52 
videoram_w(offs_t offset,uint16_t data,uint16_t mem_mask)53 void xorworld_state::videoram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
54 {
55 	COMBINE_DATA(&m_videoram[offset]);
56 	m_bg_tilemap->mark_tile_dirty(offset);
57 }
58 
59 /*
60     Tile format
61     -----------
62 
63     Word | Bit(s)            | Description
64     -----+-FEDCBA98-76543210-+--------------------------
65       0  | ----xxxx xxxxxxxx | code
66       0  | xxxx---- -------- | color
67 */
68 
TILE_GET_INFO_MEMBER(xorworld_state::get_bg_tile_info)69 TILE_GET_INFO_MEMBER(xorworld_state::get_bg_tile_info)
70 {
71 	int data = m_videoram[tile_index];
72 	int code = data & 0x0fff;
73 
74 	tileinfo.set(0, code, data >> 12, 0);
75 }
76 
video_start()77 void xorworld_state::video_start()
78 {
79 	m_bg_tilemap = &machine().tilemap().create(
80 			*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(xorworld_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS,
81 			8, 8, 32, 32);
82 }
83 
84 /*
85     Sprite Format
86     -------------
87 
88     Word | Bit(s)            | Description
89     -----+-FEDCBA98-76543210-+--------------------------
90       0  | -------- xxxxxxxx | x position
91       0  | xxxxxxxx -------- | y position
92       1  | -------- ------xx | flipxy? (not used)
93       1  | ----xxxx xxxxxx-- | sprite number
94       1  | xxxx---- -------- | sprite color
95 */
96 
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)97 void xorworld_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect )
98 {
99 	for (int i = 0; i < 0x40; i += 2)
100 	{
101 		int sx = m_spriteram[i] & 0x00ff;
102 		int sy = 240 - (((m_spriteram[i] & 0xff00) >> 8) & 0xff);
103 		int code = (m_spriteram[i+1] & 0x0ffc) >> 2;
104 		int color = (m_spriteram[i+1] & 0xf000) >> 12;
105 
106 		m_gfxdecode->gfx(1)->transpen(bitmap,cliprect, code, color, 0, 0, sx, sy, 0);
107 	}
108 }
109 
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)110 uint32_t xorworld_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
111 {
112 	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
113 	draw_sprites(bitmap, cliprect);
114 	return 0;
115 }
116