1 // license:BSD-3-Clause
2 // copyright-holders:Uki
3 /*******************************************************************************
4
5 XX Mission (c) 1986 UPL
6
7 Video hardware driver by Uki
8
9 31/Mar/2001 -
10
11 *******************************************************************************/
12
13 #include "emu.h"
14 #include "includes/xxmissio.h"
15
16
scroll_x_w(uint8_t data)17 void xxmissio_state::scroll_x_w(uint8_t data)
18 {
19 m_xscroll = data;
20 }
scroll_y_w(uint8_t data)21 void xxmissio_state::scroll_y_w(uint8_t data)
22 {
23 m_yscroll = data;
24 }
25
flipscreen_w(uint8_t data)26 void xxmissio_state::flipscreen_w(uint8_t data)
27 {
28 m_flipscreen = data & 0x01;
29 }
30
bgram_w(offs_t offset,uint8_t data)31 void xxmissio_state::bgram_w(offs_t offset, uint8_t data)
32 {
33 int x = (offset + (m_xscroll >> 3)) & 0x1f;
34 offset = (offset & 0x7e0) | x;
35
36 m_bgram[offset] = data;
37 }
bgram_r(offs_t offset)38 uint8_t xxmissio_state::bgram_r(offs_t offset)
39 {
40 int x = (offset + (m_xscroll >> 3)) & 0x1f;
41 offset = (offset & 0x7e0) | x;
42
43 return m_bgram[offset];
44 }
45
46 /****************************************************************************/
47
TILE_GET_INFO_MEMBER(xxmissio_state::get_bg_tile_info)48 TILE_GET_INFO_MEMBER(xxmissio_state::get_bg_tile_info)
49 {
50 int code = ((m_bgram[0x400 | tile_index] & 0xc0) << 2) | m_bgram[0x000 | tile_index];
51 int color = m_bgram[0x400 | tile_index] & 0x0f;
52
53 tileinfo.set(2, code, color, 0);
54 }
55
TILE_GET_INFO_MEMBER(xxmissio_state::get_fg_tile_info)56 TILE_GET_INFO_MEMBER(xxmissio_state::get_fg_tile_info)
57 {
58 int code = m_fgram[0x000 | tile_index];
59 int color = m_fgram[0x400 | tile_index] & 0x07;
60
61 tileinfo.set(0, code, color, 0);
62 }
63
video_start()64 void xxmissio_state::video_start()
65 {
66 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(xxmissio_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 16, 8, 32, 32);
67 m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(xxmissio_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS, 16, 8, 32, 32);
68
69 m_bg_tilemap->set_scroll_cols(1);
70 m_bg_tilemap->set_scroll_rows(1);
71 m_bg_tilemap->set_scrolldx(2, 12);
72
73 m_fg_tilemap->set_transparent_pen(0);
74
75 save_item(NAME(m_xscroll));
76 save_item(NAME(m_yscroll));
77 save_item(NAME(m_flipscreen));
78 }
79
BBGGRRII(uint32_t raw)80 rgb_t xxmissio_state::BBGGRRII(uint32_t raw)
81 {
82 uint8_t const i = raw & 3;
83 uint8_t const r = ((raw >> 0) & 0x0c) | i;
84 uint8_t const g = ((raw >> 2) & 0x0c) | i;
85 uint8_t const b = ((raw >> 4) & 0x0c) | i;
86
87 return rgb_t(r | (r << 4), g | (g << 4), b | (b << 4));
88 }
89
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect,gfx_element * gfx)90 void xxmissio_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, gfx_element *gfx)
91 {
92 for (int offs = 0; offs < 0x800; offs += 0x20)
93 {
94 int chr = m_spriteram[offs];
95 int col = m_spriteram[offs+3];
96
97 int const fx = BIT(col, 4) ^ m_flipscreen;
98 int const fy = BIT(col, 5) ^ m_flipscreen;
99
100 int const x = m_spriteram[offs+1]*2;
101 int const y = m_spriteram[offs+2];
102
103 chr += (col & 0x40) << 2;
104 col &= 0x07;
105
106 int px, py;
107 if (!m_flipscreen)
108 {
109 px = x-8;
110 py = y;
111 }
112 else
113 {
114 px = 480-x-6;
115 py = 240-y;
116 }
117
118 px &= 0x1ff;
119
120 gfx->transpen(bitmap,cliprect,
121 chr,
122 col,
123 fx,fy,
124 px,py,0);
125
126 if (px > 0x1e0)
127 gfx->transpen(bitmap,cliprect,
128 chr,
129 col,
130 fx,fy,
131 px-0x200,py,0);
132
133 }
134 }
135
136
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)137 uint32_t xxmissio_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
138 {
139 machine().tilemap().mark_all_dirty();
140 machine().tilemap().set_flip_all(m_flipscreen ? TILEMAP_FLIPX | TILEMAP_FLIPY : 0);
141
142 m_bg_tilemap->set_scrollx(0, m_xscroll * 2);
143 m_bg_tilemap->set_scrolly(0, m_yscroll);
144
145 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
146 draw_sprites(bitmap, cliprect, m_gfxdecode->gfx(1));
147 m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
148
149 return 0;
150 }
151