1 // license:BSD-3-Clause
2 // copyright-holders:Mirko Buffoni
3 #include "emu.h"
4 #include "includes/solomon.h"
5 
solomon_videoram_w(offs_t offset,uint8_t data)6 void solomon_state::solomon_videoram_w(offs_t offset, uint8_t data)
7 {
8 	m_videoram[offset] = data;
9 	m_fg_tilemap->mark_tile_dirty(offset);
10 }
11 
solomon_colorram_w(offs_t offset,uint8_t data)12 void solomon_state::solomon_colorram_w(offs_t offset, uint8_t data)
13 {
14 	m_colorram[offset] = data;
15 	m_fg_tilemap->mark_tile_dirty(offset);
16 }
17 
solomon_videoram2_w(offs_t offset,uint8_t data)18 void solomon_state::solomon_videoram2_w(offs_t offset, uint8_t data)
19 {
20 	m_videoram2[offset] = data;
21 	m_bg_tilemap->mark_tile_dirty(offset);
22 }
23 
solomon_colorram2_w(offs_t offset,uint8_t data)24 void solomon_state::solomon_colorram2_w(offs_t offset, uint8_t data)
25 {
26 	m_colorram2[offset] = data;
27 	m_bg_tilemap->mark_tile_dirty(offset);
28 }
29 
solomon_flipscreen_w(uint8_t data)30 void solomon_state::solomon_flipscreen_w(uint8_t data)
31 {
32 	if (flip_screen() != (data & 0x01))
33 	{
34 		flip_screen_set(data & 0x01);
35 		machine().tilemap().mark_all_dirty();
36 	}
37 }
38 
TILE_GET_INFO_MEMBER(solomon_state::get_bg_tile_info)39 TILE_GET_INFO_MEMBER(solomon_state::get_bg_tile_info)
40 {
41 	int attr = m_colorram2[tile_index];
42 	int code = m_videoram2[tile_index] + 256 * (attr & 0x07);
43 	int color = ((attr & 0x70) >> 4);
44 	int flags = ((attr & 0x80) ? TILE_FLIPX : 0) | ((attr & 0x08) ? TILE_FLIPY : 0);
45 
46 	tileinfo.set(1, code, color, flags);
47 }
48 
TILE_GET_INFO_MEMBER(solomon_state::get_fg_tile_info)49 TILE_GET_INFO_MEMBER(solomon_state::get_fg_tile_info)
50 {
51 	int attr = m_colorram[tile_index];
52 	int code = m_videoram[tile_index] + 256 * (attr & 0x07);
53 	int color = (attr & 0x70) >> 4;
54 
55 	tileinfo.set(0, code, color, 0);
56 }
57 
video_start()58 void solomon_state::video_start()
59 {
60 	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(solomon_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS,
61 			8, 8, 32, 32);
62 
63 	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(solomon_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS,
64 			8, 8, 32, 32);
65 
66 	m_fg_tilemap->set_transparent_pen(0);
67 }
68 
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)69 void solomon_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect )
70 {
71 	uint8_t *spriteram = m_spriteram;
72 	int offs;
73 
74 	for (offs = m_spriteram.bytes() - 4; offs >= 0; offs -= 4)
75 	{
76 		int code = spriteram[offs] + 16 * (spriteram[offs + 1] & 0x10);
77 		int color = (spriteram[offs + 1] & 0x0e) >> 1;
78 		int flipx = spriteram[offs + 1] & 0x40;
79 		int flipy = spriteram[offs + 1] & 0x80;
80 		int sx = spriteram[offs + 3];
81 		int sy = 241 - spriteram[offs + 2];
82 
83 		if (flip_screen())
84 		{
85 			sx = 240 - sx;
86 			sy = 242 - sy;
87 			flipx = !flipx;
88 			flipy = !flipy;
89 		}
90 
91 
92 			m_gfxdecode->gfx(2)->transpen(bitmap,cliprect,
93 			code, color,
94 			flipx, flipy,
95 			sx, sy, 0);
96 	}
97 }
98 
screen_update_solomon(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)99 uint32_t solomon_state::screen_update_solomon(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
100 {
101 	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
102 	m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
103 	draw_sprites(bitmap, cliprect);
104 	return 0;
105 }
106