1 // license:BSD-3-Clause
2 // copyright-holders:R. Belmont, Andrew Gardner
3 /*
4 Polygonet Commanders (Konami, 1993)
5
6 Video hardware emulation
7
8 Currently contains: TTL text plane (probably not complete, needs banking? colors?)
9 Needs: PSAC2 roz plane, polygons
10 */
11
12 #include "emu.h"
13 #include "includes/plygonet.h"
14 #include "screen.h"
15
16
17 /* TTL text plane */
18
TILE_GET_INFO_MEMBER(polygonet_state::ttl_get_tile_info)19 TILE_GET_INFO_MEMBER(polygonet_state::ttl_get_tile_info)
20 {
21 int attr, code;
22
23 code = m_ttl_vram[tile_index]&0xfff;
24
25 attr = m_ttl_vram[tile_index]>>12; /* palette in all 4 bits? */
26
27 tileinfo.set(m_ttl_gfx_index, code, attr, 0);
28 }
29
TILE_GET_INFO_MEMBER(polygonet_state::roz_get_tile_info)30 TILE_GET_INFO_MEMBER(polygonet_state::roz_get_tile_info)
31 {
32 int attr, code;
33
34 attr = (m_roz_vram[tile_index] >> 12) + 16; /* roz base palette is palette 16 */
35 code = m_roz_vram[tile_index] & 0x3ff;
36
37 tileinfo.set(0, code, attr, 0);
38 }
39
polygonet_ttl_ram_r(offs_t offset)40 uint32_t polygonet_state::polygonet_ttl_ram_r(offs_t offset)
41 {
42 uint32_t *vram = (uint32_t *)m_ttl_vram;
43
44 return vram[offset];
45 }
46
polygonet_ttl_ram_w(offs_t offset,uint32_t data,uint32_t mem_mask)47 void polygonet_state::polygonet_ttl_ram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
48 {
49 uint32_t *vram = (uint32_t *)m_ttl_vram;
50
51 COMBINE_DATA(&vram[offset]);
52
53 m_ttl_tilemap->mark_tile_dirty(offset*2);
54 m_ttl_tilemap->mark_tile_dirty(offset*2+1);
55 }
56
polygonet_roz_ram_r(offs_t offset)57 uint32_t polygonet_state::polygonet_roz_ram_r(offs_t offset)
58 {
59 uint32_t *vram = (uint32_t *)m_roz_vram;
60
61 return vram[offset];
62 }
63
polygonet_roz_ram_w(offs_t offset,uint32_t data,uint32_t mem_mask)64 void polygonet_state::polygonet_roz_ram_w(offs_t offset, uint32_t data, uint32_t mem_mask)
65 {
66 uint32_t *vram = (uint32_t *)m_roz_vram;
67
68 COMBINE_DATA(&vram[offset]);
69
70 m_roz_tilemap->mark_tile_dirty(offset*2);
71 m_roz_tilemap->mark_tile_dirty(offset*2+1);
72 }
73
TILEMAP_MAPPER_MEMBER(polygonet_state::plygonet_scan)74 TILEMAP_MAPPER_MEMBER(polygonet_state::plygonet_scan)
75 {
76 return row * num_cols + (col^1);
77 }
78
TILEMAP_MAPPER_MEMBER(polygonet_state::plygonet_scan_cols)79 TILEMAP_MAPPER_MEMBER(polygonet_state::plygonet_scan_cols)
80 {
81 return col * num_rows + (row^1);
82 }
83
video_start()84 void polygonet_state::video_start()
85 {
86 static const gfx_layout charlayout =
87 {
88 8, 8, /* 8x8 */
89 4096, /* # of tiles */
90 4, /* 4bpp */
91 { 0, 1, 2, 3 }, /* plane offsets */
92 { 0*4, 1*4, 2*4, 3*4, 4*4, 5*4, 6*4, 7*4 }, /* X offsets */
93 { 0*8*4, 1*8*4, 2*8*4, 3*8*4, 4*8*4, 5*8*4, 6*8*4, 7*8*4 }, /* Y offsets */
94 8*8*4
95 };
96
97 /* find first empty slot to decode gfx */
98 for (m_ttl_gfx_index = 0; m_ttl_gfx_index < MAX_GFX_ELEMENTS; m_ttl_gfx_index++)
99 if (m_gfxdecode->gfx(m_ttl_gfx_index) == nullptr)
100 break;
101
102 assert(m_ttl_gfx_index != MAX_GFX_ELEMENTS);
103
104 /* decode the ttl layer's gfx */
105 m_gfxdecode->set_gfx(m_ttl_gfx_index, std::make_unique<gfx_element>(m_palette, charlayout, memregion("gfx1")->base(), 0, m_palette->entries() / 16, 0));
106
107 /* create the tilemap */
108 m_ttl_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(polygonet_state::ttl_get_tile_info)), tilemap_mapper_delegate(*this, FUNC(polygonet_state::plygonet_scan)), 8, 8, 64, 32);
109
110 m_ttl_tilemap->set_transparent_pen(0);
111
112 /* set up the roz t-map too */
113 m_roz_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(polygonet_state::roz_get_tile_info)), tilemap_mapper_delegate(*this, FUNC(polygonet_state::plygonet_scan_cols)), 16, 16, 32, 64);
114 m_roz_tilemap->set_transparent_pen(0);
115
116 /* save states */
117 save_item(NAME(m_ttl_gfx_index));
118 save_item(NAME(m_ttl_vram));
119 save_item(NAME(m_roz_vram));
120 }
121
screen_update_polygonet(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)122 uint32_t polygonet_state::screen_update_polygonet(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
123 {
124 screen.priority().fill(0);
125 bitmap.fill(m_palette->black_pen(), cliprect);
126
127 m_k053936->zoom_draw(screen, bitmap, cliprect, m_roz_tilemap, 0, 0, 0);
128
129 m_ttl_tilemap->draw(screen, bitmap, cliprect, 0, 1<<0);
130 return 0;
131 }
132