1 // license:BSD-3-Clause
2 // copyright-holders:Zsolt Vasvari
3 /***************************************************************************
4
5 video.c
6
7 Functions to emulate the video hardware of the machine.
8
9 ***************************************************************************/
10
11 #include "emu.h"
12 #include "video/resnet.h"
13 #include "includes/sbasketb.h"
14
15 /***************************************************************************
16
17 Convert the color PROMs into a more useable format.
18
19 Super Basketball has three 256x4 palette PROMs (one per gun) and two 256x4
20 lookup table PROMs (one for characters, one for sprites).
21 I don't know for sure how the palette PROMs are connected to the RGB
22 output, but it's probably the usual:
23
24 bit 3 -- 220 ohm resistor -- RED/GREEN/BLUE
25 -- 470 ohm resistor -- RED/GREEN/BLUE
26 -- 1 kohm resistor -- RED/GREEN/BLUE
27 bit 0 -- 2.2kohm resistor -- RED/GREEN/BLUE
28
29 ***************************************************************************/
30
sbasketb_palette(palette_device & palette) const31 void sbasketb_state::sbasketb_palette(palette_device &palette) const
32 {
33 const uint8_t *color_prom = memregion("proms")->base();
34 static constexpr int resistances[4] = { 2000, 1000, 470, 220 };
35
36 // compute the color output resistor weights
37 double rweights[4], gweights[4], bweights[4];
38 compute_resistor_weights(0, 255, -1.0,
39 4, resistances, rweights, 1000, 0,
40 4, resistances, gweights, 1000, 0,
41 4, resistances, bweights, 1000, 0);
42
43 // create a lookup table for the palette
44 for (int i = 0; i < 0x100; i++)
45 {
46 int bit0, bit1, bit2, bit3;
47
48 // red component
49 bit0 = BIT(color_prom[i | 0x000], 0);
50 bit1 = BIT(color_prom[i | 0x000], 1);
51 bit2 = BIT(color_prom[i | 0x000], 2);
52 bit3 = BIT(color_prom[i | 0x000], 3);
53 int const r = combine_weights(rweights, bit0, bit1, bit2, bit3);
54
55 // green component
56 bit0 = BIT(color_prom[i | 0x100], 0);
57 bit1 = BIT(color_prom[i | 0x100], 1);
58 bit2 = BIT(color_prom[i | 0x100], 2);
59 bit3 = BIT(color_prom[i | 0x100], 3);
60 int const g = combine_weights(gweights, bit0, bit1, bit2, bit3);
61
62 // blue component
63 bit0 = BIT(color_prom[i | 0x200], 0);
64 bit1 = BIT(color_prom[i | 0x200], 1);
65 bit2 = BIT(color_prom[i | 0x200], 2);
66 bit3 = BIT(color_prom[i | 0x200], 3);
67 int const b = combine_weights(bweights, bit0, bit1, bit2, bit3);
68
69 palette.set_indirect_color(i, rgb_t(r, g, b));
70 }
71
72 // color_prom now points to the beginning of the lookup table
73 color_prom += 0x300;
74
75 // characters use colors 0xf0-0xff
76 for (int i = 0; i < 0x100; i++)
77 {
78 uint8_t const ctabentry = (color_prom[i] & 0x0f) | 0xf0;
79 palette.set_pen_indirect(i, ctabentry);
80 }
81
82 // sprites use colors 0-256 (?) in 16 banks
83 for (int i = 0; i < 0x100; i++)
84 {
85 for (int j = 0; j < 0x10; j++)
86 {
87 uint8_t const ctabentry = (j << 4) | (color_prom[i + 0x100] & 0x0f);
88 palette.set_pen_indirect(0x100 + ((j << 8) | i), ctabentry);
89 }
90 }
91 }
92
sbasketb_videoram_w(offs_t offset,uint8_t data)93 void sbasketb_state::sbasketb_videoram_w(offs_t offset, uint8_t data)
94 {
95 m_videoram[offset] = data;
96 m_bg_tilemap->mark_tile_dirty(offset);
97 }
98
sbasketb_colorram_w(offs_t offset,uint8_t data)99 void sbasketb_state::sbasketb_colorram_w(offs_t offset, uint8_t data)
100 {
101 m_colorram[offset] = data;
102 m_bg_tilemap->mark_tile_dirty(offset);
103 }
104
WRITE_LINE_MEMBER(sbasketb_state::flipscreen_w)105 WRITE_LINE_MEMBER(sbasketb_state::flipscreen_w)
106 {
107 flip_screen_set(state);
108 machine().tilemap().mark_all_dirty();
109 }
110
WRITE_LINE_MEMBER(sbasketb_state::spriteram_select_w)111 WRITE_LINE_MEMBER(sbasketb_state::spriteram_select_w)
112 {
113 m_spriteram_select = state;
114 }
115
TILE_GET_INFO_MEMBER(sbasketb_state::get_bg_tile_info)116 TILE_GET_INFO_MEMBER(sbasketb_state::get_bg_tile_info)
117 {
118 int code = m_videoram[tile_index] + ((m_colorram[tile_index] & 0x20) << 3);
119 int color = m_colorram[tile_index] & 0x0f;
120 int flags = ((m_colorram[tile_index] & 0x40) ? TILE_FLIPX : 0) | ((m_colorram[tile_index] & 0x80) ? TILE_FLIPY : 0);
121
122 tileinfo.set(0, code, color, flags);
123 }
124
video_start()125 void sbasketb_state::video_start()
126 {
127 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(sbasketb_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
128 m_bg_tilemap->set_scroll_cols(32);
129
130 save_item(NAME(m_spriteram_select));
131 }
132
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)133 void sbasketb_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
134 {
135 uint8_t *spriteram = m_spriteram;
136 int offs = m_spriteram_select ? 0x100 : 0;
137 int i;
138
139 for (i = 0; i < 64; i++, offs += 4)
140 {
141 int sx = spriteram[offs + 2];
142 int sy = spriteram[offs + 3];
143
144 if (sx || sy)
145 {
146 int code = spriteram[offs + 0] | ((spriteram[offs + 1] & 0x20) << 3);
147 int color = (spriteram[offs + 1] & 0x0f) + 16 * *m_palettebank;
148 int flipx = spriteram[offs + 1] & 0x40;
149 int flipy = spriteram[offs + 1] & 0x80;
150
151 if (flip_screen())
152 {
153 sx = 240 - sx;
154 sy = 240 - sy;
155 flipx = !flipx;
156 flipy = !flipy;
157 }
158
159
160 m_gfxdecode->gfx(1)->transpen(bitmap,cliprect,
161 code, color,
162 flipx, flipy,
163 sx, sy, 0);
164 }
165 }
166 }
167
screen_update_sbasketb(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)168 uint32_t sbasketb_state::screen_update_sbasketb(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
169 {
170 int col;
171
172 for (col = 6; col < 32; col++)
173 m_bg_tilemap->set_scrolly(col, *m_scroll);
174
175 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
176 draw_sprites(bitmap, cliprect);
177 return 0;
178 }
179