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
|
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
video.c
Functions to emulate the video hardware of the machine.
***************************************************************************/
#include "emu.h"
#include "video/resnet.h"
#include "includes/tp84.h"
/*
-The colortable is divided in 2 part:
-The characters colors
-The sprites colors
-The characters colors are indexed like this:
-2 bits from the characters
-4 bits from the attribute in tp84_bg_colorram
-2 bits from palette_bank (d3-d4)
-3 bits from palette_bank (d0-d1-d2)
-So, there is 2048 bytes for the characters
-The sprites colors are indexed like this:
-4 bits from the sprites (16 colors)
-4 bits from the attribute of the sprites
-3 bits from palette_bank (d0-d1-d2)
-So, there is 2048 bytes for the sprites
*/
/*
The RGB signals are generated by 3 proms 256X4 (prom 2C, 2D and 1E)
The resistors values are:
1K ohm
470 ohm
220 ohm
100 ohm
*/
void tp84_state::tp84_palette(palette_device &palette) const
{
const uint8_t *color_prom = memregion("proms")->base();
static constexpr int resistances[4] = { 1000, 470, 220, 100 };
// compute the color output resistor weights
double weights[4];
compute_resistor_weights(0, 255, -1.0,
4, resistances, weights, 470, 0,
0, nullptr, nullptr, 0, 0,
0, nullptr, nullptr, 0, 0);
// create a lookup table for the palette
for (int i = 0; i < 0x100; i++)
{
int bit0, bit1, bit2, bit3;
// red component
bit0 = BIT(color_prom[i | 0x000], 0);
bit1 = BIT(color_prom[i | 0x000], 1);
bit2 = BIT(color_prom[i | 0x000], 2);
bit3 = BIT(color_prom[i | 0x000], 3);
int const r = combine_weights(weights, bit0, bit1, bit2, bit3);
// green component
bit0 = BIT(color_prom[i | 0x100], 0);
bit1 = BIT(color_prom[i | 0x100], 1);
bit2 = BIT(color_prom[i | 0x100], 2);
bit3 = BIT(color_prom[i | 0x100], 3);
int const g = combine_weights(weights, bit0, bit1, bit2, bit3);
// blue component
bit0 = BIT(color_prom[i | 0x200], 0);
bit1 = BIT(color_prom[i | 0x200], 1);
bit2 = BIT(color_prom[i | 0x200], 2);
bit3 = BIT(color_prom[i | 0x200], 3);
int const b = combine_weights(weights, bit0, bit1, bit2, bit3);
palette.set_indirect_color(i, rgb_t(r, g, b));
}
// color_prom now points to the beginning of the lookup table
color_prom += 0x300;
// characters use colors 0x80-0xff, sprites use colors 0-0x7f
for (int i = 0; i < 0x200; i++)
{
for (int j = 0; j < 8; j++)
{
uint8_t const ctabentry = ((~i & 0x100) >> 1) | (j << 4) | (color_prom[i] & 0x0f);
palette.set_pen_indirect(((i & 0x100) << 3) | (j << 8) | (i & 0xff), ctabentry);
}
}
}
void tp84_state::tp84_spriteram_w(offs_t offset, uint8_t data)
{
/* the game multiplexes the sprites, so update now */
// m_screen->update_now();
m_screen->update_partial(m_screen->vpos());
m_spriteram[offset] = data;
}
uint8_t tp84_state::tp84_scanline_r()
{
/* reads 1V - 128V */
return m_screen->vpos();
}
TILE_GET_INFO_MEMBER(tp84_state::get_bg_tile_info)
{
int code = ((m_bg_colorram[tile_index] & 0x30) << 4) | m_bg_videoram[tile_index];
int color = ((*m_palette_bank & 0x07) << 6) |
((*m_palette_bank & 0x18) << 1) |
(m_bg_colorram[tile_index] & 0x0f);
int flags = TILE_FLIPYX(m_bg_colorram[tile_index] >> 6);
tileinfo.set(0, code, color, flags);
}
TILE_GET_INFO_MEMBER(tp84_state::get_fg_tile_info)
{
int code = ((m_fg_colorram[tile_index] & 0x30) << 4) | m_fg_videoram[tile_index];
int color = ((*m_palette_bank & 0x07) << 6) |
((*m_palette_bank & 0x18) << 1) |
(m_fg_colorram[tile_index] & 0x0f);
int flags = TILE_FLIPYX(m_fg_colorram[tile_index] >> 6);
tileinfo.set(0, code, color, flags);
}
void tp84_state::video_start()
{
m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tp84_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(tp84_state::get_fg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
}
void tp84_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
{
int offs;
int palette_base = ((*m_palette_bank & 0x07) << 4);
for (offs = 0x5c; offs >= 0; offs -= 4)
{
int x = m_spriteram[offs];
int y = 240 - m_spriteram[offs + 3];
int code = m_spriteram[offs + 1];
int color = palette_base | (m_spriteram[offs + 2] & 0x0f);
int flip_x = ~m_spriteram[offs + 2] & 0x40;
int flip_y = m_spriteram[offs + 2] & 0x80;
m_gfxdecode->gfx(1)->transmask(bitmap,cliprect, code, color, flip_x, flip_y, x, y,
m_palette->transpen_mask(*m_gfxdecode->gfx(1), color, palette_base));
}
}
uint32_t tp84_state::screen_update_tp84(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
rectangle clip = cliprect;
const rectangle &visarea = screen.visible_area();
if (cliprect.min_y == screen.visible_area().min_y)
{
machine().tilemap().mark_all_dirty();
m_bg_tilemap->set_scrollx(0, *m_scroll_x);
m_bg_tilemap->set_scrolly(0, *m_scroll_y);
machine().tilemap().set_flip_all((m_flipscreen_x ? TILEMAP_FLIPX : 0) |
(m_flipscreen_y ? TILEMAP_FLIPY : 0));
}
m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
draw_sprites(bitmap, cliprect);
/* draw top status region */
clip.min_x = visarea.min_x;
clip.max_x = visarea.min_x + 15;
m_fg_tilemap->draw(screen, bitmap, clip, 0, 0);
/* draw bottom status region */
clip.min_x = visarea.max_x - 15;
clip.max_x = visarea.max_x;
m_fg_tilemap->draw(screen, bitmap, clip, 0, 0);
return 0;
}
|