summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/divebomb.cpp
blob: 275ef64e1730ab0c646abb97d5317dfa0d95106e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// license:BSD-3-Clause
// copyright-holders:David Haywood, Phil Bennett
/*************************************************************************

    Kyuukoukabakugekitai - Dive Bomber Squad

*************************************************************************/

#include "emu.h"
#include "includes/divebomb.h"
#include "video/resnet.h"



/*************************************
 *
 *  Tilemap callbacks
 *
 *************************************/

TILE_GET_INFO_MEMBER(divebomb_state::get_fg_tile_info)
{
    UINT32 code = m_fgram[tile_index + 0x000];
    UINT32 attr = m_fgram[tile_index + 0x400];
    UINT32 colour = attr >> 4;

    code |= (attr & 0x3) << 8;

    SET_TILE_INFO_MEMBER(0, code, colour, 0);
}



/*************************************
 *
 *  K051316 callbacks
 *
 *************************************/

K051316_CB_MEMBER(divebomb_state::zoom_callback_1)
{
    *code |= (*color & 0x03) << 8;
    *color = 0 + ((roz_pal >> 4) & 3);
}


K051316_CB_MEMBER(divebomb_state::zoom_callback_2)
{
    *code |= (*color & 0x03) << 8;
    *color = 4 + (roz_pal & 3);
}



/*************************************
 *
 *  Video hardware handlers
 *
 *************************************/

WRITE8_MEMBER(divebomb_state::fgram_w)
{
    m_fgram[offset] = data;
    m_fg_tilemap->mark_tile_dirty(offset & 0x3ff);
}


WRITE8_MEMBER(divebomb_state::rozcpu_wrap1_enable_w)
{
    roz1_wrap = !(data & 1);
}


WRITE8_MEMBER(divebomb_state::rozcpu_enable1_w)
{
    roz1_enable = !(data & 1);
}


WRITE8_MEMBER(divebomb_state::rozcpu_enable2_w)
{
    roz2_enable = !(data & 1);
}


WRITE8_MEMBER(divebomb_state::rozcpu_wrap2_enable_w)
{
    roz2_wrap = !(data & 1);
}


WRITE8_MEMBER(divebomb_state::rozcpu_pal_w)
{
    //.... ..xx  K051316 1 palette select
    //..xx ....  K051316 2 palette select

    roz_pal = data;
    
    m_k051316_2->mark_tmap_dirty();
    m_k051316_1->mark_tmap_dirty();
    
    if (data & 0xcc)
        logerror("rozcpu_port50_w %02x\n", data);
}



/*************************************
 *
 *  Video hardware init
 *
 *************************************/

void divebomb_state::decode_proms(const UINT8 * rgn, int size, int index, bool inv)
{
    static const int resistances[4] = { 2000, 1000, 470, 220 };

    double rweights[4], gweights[4], bweights[4];
    
    /* compute the color output resistor weights */
    compute_resistor_weights(0, 255, -1.0,
                             4, resistances, rweights, 0, 0,
                             4, resistances, gweights, 0, 0,
                             4, resistances, bweights, 0, 0);
    
    /* create a lookup table for the palette */
    for (UINT32 i = 0; i < size; ++i)
    {
        UINT32 rdata = rgn[i + size*2] & 0x0f;
        UINT32 r = combine_4_weights(rweights, BIT(rdata, 0), BIT(rdata, 1), BIT(rdata, 2), BIT(rdata, 3));
        
        UINT32 gdata = rgn[i + size] & 0x0f;
        UINT32 g = combine_4_weights(gweights, BIT(gdata, 0), BIT(gdata, 1), BIT(gdata, 2), BIT(gdata, 3));
        
        UINT32 bdata = rgn[i] & 0x0f;
        UINT32 b = combine_4_weights(bweights, BIT(bdata, 0), BIT(bdata, 1), BIT(bdata, 2), BIT(bdata, 3));
        
        if (!inv)
            m_palette->set_pen_color(index + i, rgb_t(r, g, b));
        else
            m_palette->set_pen_color(index + (i ^ 0xff), rgb_t(r, g, b));
    }
}


PALETTE_INIT_MEMBER(divebomb_state, divebomb)
{
    decode_proms(memregion("spr_proms")->base(), 0x100, 0x400 + 0x400 + 0x400, false);
    decode_proms(memregion("fg_proms")->base(), 0x400, 0x400 + 0x400, false);
    decode_proms(memregion("k051316_1_pr")->base(), 0x400, 0, true);
    decode_proms(memregion("k051316_2_pr")->base(), 0x400, 0x400, true);
}


VIDEO_START_MEMBER(divebomb_state,divebomb)
{
    m_fg_tilemap = &machine().tilemap().create(m_gfxdecode, tilemap_get_info_delegate(FUNC(divebomb_state::get_fg_tile_info),this), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
    m_fg_tilemap->set_transparent_pen(0);
    m_fg_tilemap->set_scrolly(0, 16);
}



/*************************************
 *
 *  Main update
 *
 *************************************/

void divebomb_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
    const UINT8 *spriteram = m_spriteram;
    
    for (UINT32 i = 0; i < m_spriteram.bytes(); i += 4)
    {
        UINT32 sy = spriteram[i + 3];
        UINT32 sx = spriteram[i + 0];
        UINT32 code = spriteram[i + 2];
        UINT32 attr = spriteram[i + 1];
        
        code += (attr & 0x0f) << 8;
        
        UINT32 colour = attr >> 4;

        m_gfxdecode->gfx(1)->transpen(bitmap, cliprect, code, colour, 0, 0, sx, sy, 0);
        m_gfxdecode->gfx(1)->transpen(bitmap, cliprect, code, colour, 0, 0, sx, sy-256, 0);
    }
}


UINT32 divebomb_state::screen_update_divebomb(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
    m_k051316_1->wraparound_enable(roz1_wrap);
    m_k051316_2->wraparound_enable(roz2_wrap);

    bitmap.fill(m_palette->black_pen(), cliprect);

    if (roz2_enable)
        m_k051316_2->zoom_draw(screen, bitmap, cliprect, 0, 0);
    
    if (roz1_enable)
        m_k051316_1->zoom_draw(screen, bitmap, cliprect, 0, 0);

    draw_sprites(bitmap, cliprect);

    m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);

    return 0;
}