1 // license:BSD-3-Clause
2 // copyright-holders:Paul Leaman
3 #include "emu.h"
4 #include "includes/gunsmoke.h"
5
6 /***************************************************************************
7
8 Convert the color PROMs into a more useable format.
9
10 Gunsmoke has three 256x4 palette PROMs (one per gun) and a lot ;-) of
11 256x4 lookup table PROMs.
12 The palette PROMs are connected to the RGB output this way:
13
14 bit 3 -- 220 ohm resistor -- RED/GREEN/BLUE
15 -- 470 ohm resistor -- RED/GREEN/BLUE
16 -- 1 kohm resistor -- RED/GREEN/BLUE
17 bit 0 -- 2.2kohm resistor -- RED/GREEN/BLUE
18
19 ***************************************************************************/
20
gunsmoke_palette(palette_device & palette) const21 void gunsmoke_state::gunsmoke_palette(palette_device &palette) const
22 {
23 const uint8_t *color_prom = memregion("proms")->base();
24
25 // create a lookup table for the palette
26 for (int i = 0; i < 0x100; i++)
27 {
28 int const r = pal4bit(color_prom[i + 0x000]);
29 int const g = pal4bit(color_prom[i + 0x100]);
30 int const b = pal4bit(color_prom[i + 0x200]);
31
32 palette.set_indirect_color(i, rgb_t(r, g, b));
33 }
34
35 // color_prom now points to the beginning of the lookup table
36 color_prom += 0x300;
37
38 // characters use colors 0x40-0x4f
39 for (int i = 0; i < 0x80; i++)
40 {
41 uint8_t const ctabentry = color_prom[i] | 0x40;
42 palette.set_pen_indirect(i, ctabentry);
43 }
44
45 // background tiles use colors 0-0x3f
46 for (int i = 0x100; i < 0x200; i++)
47 {
48 uint8_t const ctabentry = color_prom[i] | ((color_prom[i + 0x100] & 0x03) << 4);
49 palette.set_pen_indirect(i - 0x80, ctabentry);
50 }
51
52 // sprites use colors 0x80-0xff
53 for (int i = 0x300; i < 0x400; i++)
54 {
55 uint8_t const ctabentry = color_prom[i] | ((color_prom[i + 0x100] & 0x07) << 4) | 0x80;
56 palette.set_pen_indirect(i - 0x180, ctabentry);
57 }
58 }
59
gunsmoke_videoram_w(offs_t offset,uint8_t data)60 void gunsmoke_state::gunsmoke_videoram_w(offs_t offset, uint8_t data)
61 {
62 m_videoram[offset] = data;
63 m_fg_tilemap->mark_tile_dirty(offset);
64 }
65
gunsmoke_colorram_w(offs_t offset,uint8_t data)66 void gunsmoke_state::gunsmoke_colorram_w(offs_t offset, uint8_t data)
67 {
68 m_colorram[offset] = data;
69 m_fg_tilemap->mark_tile_dirty(offset);
70 }
71
gunsmoke_c804_w(uint8_t data)72 void gunsmoke_state::gunsmoke_c804_w(uint8_t data)
73 {
74 /* bits 0 and 1 are for coin counters */
75 machine().bookkeeping().coin_counter_w(1, data & 0x01);
76 machine().bookkeeping().coin_counter_w(0, data & 0x02);
77
78 /* bits 2 and 3 select the ROM bank */
79 membank("bank1")->set_entry((data & 0x0c) >> 2);
80
81 /* bit 5 resets the sound CPU? - we ignore it */
82
83 /* bit 6 flips screen */
84 flip_screen_set(data & 0x40);
85
86 /* bit 7 enables characters? */
87 m_chon = data & 0x80;
88 }
89
gunsmoke_d806_w(uint8_t data)90 void gunsmoke_state::gunsmoke_d806_w(uint8_t data)
91 {
92 /* bits 0-2 select the sprite 3 bank */
93 m_sprite3bank = data & 0x07;
94
95 /* bit 4 enables bg 1? */
96 m_bgon = data & 0x10;
97
98 /* bit 5 enables sprites? */
99 m_objon = data & 0x20;
100 }
101
TILE_GET_INFO_MEMBER(gunsmoke_state::get_bg_tile_info)102 TILE_GET_INFO_MEMBER(gunsmoke_state::get_bg_tile_info)
103 {
104 uint8_t *tilerom = memregion("gfx4")->base();
105
106 int offs = tile_index * 2;
107 int attr = tilerom[offs + 1];
108 int code = tilerom[offs] + ((attr & 0x01) << 8);
109 int color = (attr & 0x3c) >> 2;
110 int flags = TILE_FLIPYX((attr & 0xc0) >> 6);
111
112 tileinfo.set(1, code, color, flags);
113 }
114
TILE_GET_INFO_MEMBER(gunsmoke_state::get_fg_tile_info)115 TILE_GET_INFO_MEMBER(gunsmoke_state::get_fg_tile_info)
116 {
117 int attr = m_colorram[tile_index];
118 int code = m_videoram[tile_index] + ((attr & 0xe0) << 2);
119 int color = attr & 0x1f;
120
121 tileinfo.group = color;
122
123 tileinfo.set(0, code, color, 0);
124 }
125
video_start()126 void gunsmoke_state::video_start()
127 {
128 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(gunsmoke_state::get_bg_tile_info)), TILEMAP_SCAN_COLS, 32, 32, 2048, 8);
129 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(gunsmoke_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
130
131 m_fg_tilemap->configure_groups(*m_gfxdecode->gfx(0), 0x4f);
132 }
133
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)134 void gunsmoke_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
135 {
136 uint8_t *spriteram = m_spriteram;
137 int offs;
138
139 for (offs = m_spriteram.bytes() - 32; offs >= 0; offs -= 32)
140 {
141 int attr = spriteram[offs + 1];
142 int bank = (attr & 0xc0) >> 6;
143 int code = spriteram[offs];
144 int color = attr & 0x0f;
145 int flipx = 0;
146 int flipy = attr & 0x10;
147 int sx = spriteram[offs + 3] - ((attr & 0x20) << 3);
148 int sy = spriteram[offs + 2];
149
150 if (bank == 3)
151 bank += m_sprite3bank;
152
153 code += 256 * bank;
154
155 if (flip_screen())
156 {
157 sx = 240 - sx;
158 sy = 240 - sy;
159 flipx = !flipx;
160 flipy = !flipy;
161 }
162
163 m_gfxdecode->gfx(2)->transpen(bitmap,cliprect, code, color, flipx, flipy, sx, sy, 0);
164 }
165 }
166
screen_update_gunsmoke(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)167 uint32_t gunsmoke_state::screen_update_gunsmoke(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
168 {
169 m_bg_tilemap->set_scrollx(0, m_scrollx[0] + 256 * m_scrollx[1]);
170 m_bg_tilemap->set_scrolly(0, m_scrolly[0]);
171
172 if (m_bgon)
173 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
174 else
175 bitmap.fill(m_palette->black_pen(), cliprect);
176
177 if (m_objon)
178 draw_sprites(bitmap, cliprect);
179
180 if (m_chon)
181 m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
182
183 return 0;
184 }
185