1 // license:BSD-3-Clause
2 // copyright-holders:Angelo Salese, Pierpaolo Prazzoli, Bryan McPhail
3 /****************************************************************************************
4
5 Competition Golf Final Round
6 video hardware emulation
7
8 ****************************************************************************************/
9
10 #include "emu.h"
11 #include "includes/compgolf.h"
12
13
compgolf_palette(palette_device & palette) const14 void compgolf_state::compgolf_palette(palette_device &palette) const
15 {
16 uint8_t const *const color_prom = memregion("proms")->base();
17
18 for (int i = 0; i < palette.entries(); i++)
19 {
20 int bit0,bit1,bit2;
21 bit0 = (color_prom[i] >> 0) & 0x01;
22 bit1 = (color_prom[i] >> 1) & 0x01;
23 bit2 = (color_prom[i] >> 2) & 0x01;
24 int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
25 bit0 = (color_prom[i] >> 3) & 0x01;
26 bit1 = (color_prom[i] >> 4) & 0x01;
27 bit2 = (color_prom[i] >> 5) & 0x01;
28 int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
29 bit0 = 0;
30 bit1 = (color_prom[i] >> 6) & 0x01;
31 bit2 = (color_prom[i] >> 7) & 0x01;
32 int const b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
33
34 palette.set_pen_color(i, rgb_t(r, g, b));
35 }
36 }
37
compgolf_video_w(offs_t offset,uint8_t data)38 void compgolf_state::compgolf_video_w(offs_t offset, uint8_t data)
39 {
40 m_videoram[offset] = data;
41 m_text_tilemap->mark_tile_dirty(offset / 2);
42 }
43
compgolf_back_w(offs_t offset,uint8_t data)44 void compgolf_state::compgolf_back_w(offs_t offset, uint8_t data)
45 {
46 m_bg_ram[offset] = data;
47 m_bg_tilemap->mark_tile_dirty(offset / 2);
48 }
49
TILE_GET_INFO_MEMBER(compgolf_state::get_text_info)50 TILE_GET_INFO_MEMBER(compgolf_state::get_text_info)
51 {
52 tile_index <<= 1;
53 tileinfo.set(2, m_videoram[tile_index + 1] | (m_videoram[tile_index] << 8), m_videoram[tile_index] >> 2, 0);
54 }
55
TILEMAP_MAPPER_MEMBER(compgolf_state::back_scan)56 TILEMAP_MAPPER_MEMBER(compgolf_state::back_scan)
57 {
58 /* logical (col,row) -> memory offset */
59 return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x10) << 4) + ((row & 0x10) << 5);
60 }
61
TILE_GET_INFO_MEMBER(compgolf_state::get_back_info)62 TILE_GET_INFO_MEMBER(compgolf_state::get_back_info)
63 {
64 int attr = m_bg_ram[tile_index * 2];
65 int code = m_bg_ram[tile_index * 2 + 1] + ((attr & 1) << 8);
66 int color = (attr & 0x3e) >> 1;
67
68 tileinfo.set(1, code, color, 0);
69 }
70
video_start()71 void compgolf_state::video_start()
72 {
73 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(compgolf_state::get_back_info)), tilemap_mapper_delegate(*this, FUNC(compgolf_state::back_scan)), 16, 16, 32, 32);
74 m_text_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(compgolf_state::get_text_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
75
76 m_text_tilemap->set_transparent_pen(0);
77 }
78
79 /*
80 preliminary sprite list:
81 0 1 2 3
82 xx------ xxxxxxxx -------- -------- sprite code
83 ---x---- -------- -------- -------- Double Height
84 ----x--- -------- -------- -------- Color,all of it?
85 -------- -------- xxxxxxxx -------- Y pos
86 -------- -------- -------- xxxxxxxx X pos
87 -----x-- -------- -------- -------- Flip X
88 -------- -------- -------- -------- Flip Y(used?)
89 */
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)90 void compgolf_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
91 {
92 int offs, fx, fy, x, y, color, sprite;
93
94 for (offs = 0; offs < 0x60; offs += 4)
95 {
96 sprite = m_spriteram[offs + 1] + (((m_spriteram[offs] & 0xc0) >> 6) * 0x100);
97 x = 240 - m_spriteram[offs + 3];
98 y = m_spriteram[offs + 2];
99 color = (m_spriteram[offs] & 8)>>3;
100 fx = m_spriteram[offs] & 4;
101 fy = 0; /* ? */
102
103 m_gfxdecode->gfx(0)->transpen(bitmap,cliprect,
104 sprite,
105 color,fx,fy,x,y,0);
106
107 /* Double Height */
108 if(m_spriteram[offs] & 0x10)
109 {
110 m_gfxdecode->gfx(0)->transpen(bitmap,cliprect,
111 sprite + 1,
112 color, fx, fy, x, y + 16, 0);
113 }
114 }
115 }
116
screen_update_compgolf(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)117 uint32_t compgolf_state::screen_update_compgolf(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
118 {
119 int scrollx = m_scrollx_hi + m_scrollx_lo;
120 int scrolly = m_scrolly_hi + m_scrolly_lo;
121
122 m_bg_tilemap->set_scrollx(0, scrollx);
123 m_bg_tilemap->set_scrolly(0, scrolly);
124
125 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
126 m_text_tilemap->draw(screen, bitmap, cliprect, 0, 0);
127 draw_sprites(bitmap, cliprect);
128 return 0;
129 }
130