1 // license:BSD-3-Clause
2 // copyright-holders:Brad Oliver
3 /***************************************************************************
4
5 tankbatt.c
6
7 Functions to emulate the video hardware of the machine.
8
9 ***************************************************************************/
10
11 #include "emu.h"
12 #include "includes/tankbatt.h"
13
14
15 /***************************************************************************
16
17 Convert the color PROMs into a more useable format.
18
19 ***************************************************************************/
tankbatt_palette(palette_device & palette) const20 void tankbatt_state::tankbatt_palette(palette_device &palette) const
21 {
22 uint8_t const *const color_prom = memregion("proms")->base();
23
24 constexpr int RES_1 = 0xc0; // this is a guess
25 constexpr int RES_2 = 0x3f; // this is a guess
26
27 // create a lookup table for the palette
28 for (int i = 0; i < 0x100; i++)
29 {
30 int const bit0 = BIT(color_prom[i], 0); // intensity
31 int const bit1 = BIT(color_prom[i], 1); // red
32 int const bit2 = BIT(color_prom[i], 2); // green
33 int const bit3 = BIT(color_prom[i], 3); // blue
34
35 // red component
36 int const r = bit1 * (RES_1 + (RES_2 * bit0));
37
38 // green component
39 int const g = bit2 * (RES_1 + (RES_2 * bit0));
40
41 // blue component
42 int const b = bit3 * (RES_1 + (RES_2 * bit0));
43
44 palette.set_indirect_color(i, rgb_t(r, g, b));
45 }
46
47 for (int i = 0; i < 0x200; i += 2)
48 {
49 palette.set_pen_indirect(i + 0, 0);
50 palette.set_pen_indirect(i + 1, i >> 1);
51 }
52 }
53
videoram_w(offs_t offset,uint8_t data)54 void tankbatt_state::videoram_w(offs_t offset, uint8_t data)
55 {
56 m_videoram[offset] = data;
57 m_bg_tilemap->mark_tile_dirty(offset);
58 }
59
TILE_GET_INFO_MEMBER(tankbatt_state::get_bg_tile_info)60 TILE_GET_INFO_MEMBER(tankbatt_state::get_bg_tile_info)
61 {
62 int code = m_videoram[tile_index];
63 int color = m_videoram[tile_index] | 0x01;
64
65 tileinfo.set(0, code, color, 0);
66 }
67
video_start()68 void tankbatt_state::video_start()
69 {
70 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tankbatt_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
71 }
72
draw_bullets(bitmap_ind16 & bitmap,const rectangle & cliprect)73 void tankbatt_state::draw_bullets(bitmap_ind16 &bitmap, const rectangle &cliprect)
74 {
75 for (int offs = 0; offs < m_bulletsram.bytes(); offs += 2)
76 {
77 int const color = 0xff; // cyan, same color as the tanks
78 int const x = m_bulletsram[offs + 1];
79 int const y = 255 - m_bulletsram[offs] - 2;
80
81 m_gfxdecode->gfx(1)->opaque(bitmap,cliprect,
82 0, // this is just a square, generated by the hardware
83 color,
84 0, 0,
85 x, y);
86 }
87 }
88
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)89 uint32_t tankbatt_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
90 {
91 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
92 draw_bullets(bitmap, cliprect);
93 return 0;
94 }
95