1 // license:BSD-3-Clause
2 // copyright-holders:Ernesto Corvi
3 #include "emu.h"
4 #include "includes/exprraid.h"
5
6
exprraid_videoram_w(offs_t offset,uint8_t data)7 void exprraid_state::exprraid_videoram_w(offs_t offset, uint8_t data)
8 {
9 m_videoram[offset] = data;
10 m_fg_tilemap->mark_tile_dirty(offset);
11 }
12
exprraid_colorram_w(offs_t offset,uint8_t data)13 void exprraid_state::exprraid_colorram_w(offs_t offset, uint8_t data)
14 {
15 m_colorram[offset] = data;
16 m_fg_tilemap->mark_tile_dirty(offset);
17 }
18
exprraid_flipscreen_w(uint8_t data)19 void exprraid_state::exprraid_flipscreen_w(uint8_t data)
20 {
21 if (flip_screen() != (data & 0x01))
22 {
23 flip_screen_set(data & 0x01);
24 machine().tilemap().mark_all_dirty();
25 }
26 }
27
exprraid_bgselect_w(offs_t offset,uint8_t data)28 void exprraid_state::exprraid_bgselect_w(offs_t offset, uint8_t data)
29 {
30 if (m_bg_index[offset] != data)
31 {
32 m_bg_index[offset] = data;
33 m_bg_tilemap->mark_all_dirty();
34 }
35 }
36
exprraid_scrollx_w(offs_t offset,uint8_t data)37 void exprraid_state::exprraid_scrollx_w(offs_t offset, uint8_t data)
38 {
39 m_bg_tilemap->set_scrollx(offset, data);
40 }
41
exprraid_scrolly_w(offs_t offset,uint8_t data)42 void exprraid_state::exprraid_scrolly_w(offs_t offset, uint8_t data)
43 {
44 m_bg_tilemap->set_scrolly(0, data);
45 }
46
TILE_GET_INFO_MEMBER(exprraid_state::get_bg_tile_info)47 TILE_GET_INFO_MEMBER(exprraid_state::get_bg_tile_info)
48 {
49 uint8_t *tilerom = memregion("gfx4")->base();
50
51 int data, attr, bank, code, color, flags;
52 int quadrant = 0, offs;
53
54 int sx = tile_index % 32;
55 int sy = tile_index / 32;
56
57 if (sx >= 16) quadrant++;
58 if (sy >= 16) quadrant += 2;
59
60 offs = (sy % 16) * 16 + (sx % 16) + (m_bg_index[quadrant] & 0x3f) * 0x100;
61
62 data = tilerom[offs];
63 attr = tilerom[offs + 0x4000];
64 bank = (2 * (attr & 0x03) + ((data & 0x80) >> 7)) + 2;
65 code = data & 0x7f;
66 color = (attr & 0x18) >> 3;
67 flags = (attr & 0x04) ? TILE_FLIPX : 0;
68
69 tileinfo.category = ((attr & 0x80) ? 1 : 0);
70
71 tileinfo.set(bank, code, color, flags);
72 }
73
TILE_GET_INFO_MEMBER(exprraid_state::get_fg_tile_info)74 TILE_GET_INFO_MEMBER(exprraid_state::get_fg_tile_info)
75 {
76 int attr = m_colorram[tile_index];
77 int code = m_videoram[tile_index] + ((attr & 0x07) << 8);
78 int color = (attr & 0x10) >> 4;
79
80 tileinfo.set(0, code, color, 0);
81 }
82
video_start()83 void exprraid_state::video_start()
84 {
85 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(exprraid_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 16, 16, 32, 32);
86 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(exprraid_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
87
88 m_bg_tilemap->set_scroll_rows(2);
89 m_fg_tilemap->set_transparent_pen(0);
90 }
91
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)92 void exprraid_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
93 {
94 int offs;
95
96 for (offs = 0; offs < m_spriteram.bytes(); offs += 4)
97 {
98 int attr = m_spriteram[offs + 1];
99 int code = m_spriteram[offs + 3] + ((attr & 0xe0) << 3);
100 int color = (attr & 0x03) + ((attr & 0x08) >> 1);
101 int flipx = (attr & 0x04);
102 int flipy = 0;
103 int sx = ((248 - m_spriteram[offs + 2]) & 0xff) - 8;
104 int sy = m_spriteram[offs];
105
106 if (flip_screen())
107 {
108 sx = 240 - sx;
109 sy = 240 - sy;
110 flipx = !flipx;
111 flipy = !flipy;
112 }
113
114 m_gfxdecode->gfx(1)->transpen(bitmap,cliprect,
115 code, color,
116 flipx, flipy,
117 sx, sy, 0);
118
119 /* double height */
120
121 if (attr & 0x10)
122 {
123 m_gfxdecode->gfx(1)->transpen(bitmap,cliprect,
124 code + 1, color,
125 flipx, flipy,
126 sx, sy + (flip_screen() ? -16 : 16), 0);
127 }
128 }
129 }
130
screen_update_exprraid(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)131 uint32_t exprraid_state::screen_update_exprraid(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
132 {
133 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
134 draw_sprites(bitmap, cliprect);
135 m_bg_tilemap->draw(screen, bitmap, cliprect, 1, 0);
136 m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
137 return 0;
138 }
139