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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
-- license:BSD-3-Clause
-- copyright-holders: Carl
local exports = {}
exports.name = "gdbstub"
exports.version = "0.0.1"
exports.description = "GDB stub plugin"
exports.license = "The BSD 3-Clause License"
exports.author = { name = "Carl" }
local gdbstub = exports
-- percpu mapping of mame registers to gdb register order
local regmaps = {
i386 = {
togdb = {
EAX = 1, ECX = 2, EDX = 3, EBX = 4, ESP = 5, EBP = 6, ESI = 7, EDI = 8, EIP = 9, EFLAGS = 10, CS = 11, SS = 12,
DS = 13, ES = 14, FS = 15, GS = 16 },
fromgdb = {
"EAX", "ECX", "EDX", "EBX", "ESP", "EBP", "ESI", "EDI", "EIP", "EFLAGS", "CS", "SS", "DS", "ES", "FS", "GS" },
regsize = 4,
addrsize = 4,
pcreg = "EIP"
}
}
regmaps.i486 = regmaps.i386
regmaps.pentium = regmaps.i386
function gdbstub.startplugin()
local debugger
local debug
local cpu
local breaks
local watches
local consolelog
local consolelast
local running
emu.register_start(function ()
debugger = manager:machine():debugger()
if not debugger then
print("gdbstub: debugger not enabled")
return
end
cpu = manager:machine().devices[":maincpu"]
if not cpu then
print("gdbstub: maincpu not found")
end
if not regmaps[cpu:shortname()] then
print("gdbstub: no register map for cpu " .. cpu:shortname())
cpu = nil
end
consolelog = debugger.consolelog
consolelast = 0
breaks = {byaddr = {}, byidx = {}}
watches = {byaddr = {}, byidx = {}}
running = false
end)
emu.register_stop(function()
consolelog = nil
cpu = nil
debug = nil
end)
local socket = emu.file("", 7)
local connected = false
socket:open("socket.127.0.0.1:2159")
emu.register_periodic(function ()
if not cpu then
return
end
if running and debugger.execution_state == "stop" then
socket:write("$S05#B8")
running = false
return
elseif debugger.execution_state == "run" then
running = true
end
local function chksum(str)
local sum = 0
str:gsub(".", function(s) sum = sum + s:byte() end)
return string.format("%.2x", sum & 0xff)
end
local function makebestr(val, len)
local str = ""
for count = 0, len - 1 do
str = str .. string.format("%.2x", (val >> (count * 8)) & 0xff)
end
return str
end
local last = consolelast
local msg = consolelog[#consolelog]
consolelast = #consolelog
if #consolelog > last and msg:find("Stopped at", 1, true) then
local point = tonumber(msg:match("Stopped at breakpoint ([0-9]+)"))
local map = regmaps[cpu:shortname()]
running = false
if not point then
point = tonumber(msg:match("Stopped at watchpoint ([0-9]+"))
if not point then
return -- ??
end
local wp = watches.byidx[point]
if wp then
local reply = "T05" .. wp.type .. ":" .. makebestr(wp.addr, map.addrsize)
socket:write("$" .. reply .. "#" .. chksum(reply))
else
socket:write("$S05#B8")
end
return
else
local bp = breaks.byidx[point]
if bp then
local reply = "T05hwbreak:" .. makebestr(cpu.state[map.pcreg].value, map.regsize)
socket:write("$" .. reply .. "#" .. chksum(reply))
else
socket:write("$S05#B8")
end
return
end
end
if running and debugger.execution_state == "stop" then
socket:write("$S05#B8")
running = false
return
elseif debugger.execution_state == "run" then
running = true
end
local data = ""
repeat
local read = socket:read(100)
data = data .. read
until #read == 0
if #data == 0 then
return
end
if data == "\x03" then
debugger.execution_state = "stop"
socket:write("$S05#B8")
running = false
return
end
local packet, checksum = data:match("%$([^#]+)#(%x%x)")
if packet then
packet:gsub("}(.)", function(s) return string.char(string.byte(s) ~ 0x20) end)
local cmd = packet:sub(1, 1)
local map = regmaps[cpu:shortname()]
if cmd == "g" then
local regs = {}
for reg, idx in pairs(map.togdb) do
regs[idx] = makebestr(cpu.state[reg].value, map.regsize)
end
local data = table.concat(regs)
socket:write("+$" .. data .. "#" .. chksum(data))
elseif cmd == "G" then
local count = 0
packet:sub(2):gsub(string.rep("%x", map.regsize * 2), function(s)
count = count + 1
cpu.state[map.fromgdb[count]].value = tonumber(s,16)
end)
socket:write("+$OK#9a")
elseif cmd == "m" then
local addr, len = packet:match("m(%x+),(%x+)")
if addr and len then
addr = tonumber(addr, 16)
len = tonumber(len, 16)
local data = ""
local space = cpu.spaces["program"]
for count = 1, len do
data = data .. string.format("%.2x", space:read_log_u8(addr))
addr = addr + 1
end
socket:write("+$" .. data .. "#" .. chksum(data))
else
socket:write("+$E00#a5") -- fix error
end
elseif cmd == "M" then
local count = 0
local addr, len, data = packet:match("M(%x+),(%x+),(%x+)")
if addr and len and data then
addr = tonumber(addr, 16)
local space = cpu.spaces["program"]
data:gsub("%x%x", function(s) space:write_log_u8(addr + count, tonumber(s, 16)) count = count + 1 end)
socket:write("+$OK#9a")
else
socket:write("+$E00#a5")
end
elseif cmd == "s" then
if #packet == 1 then
cpu:debug():step()
socket:write("+$OK#9a")
socket:write("$S05#B8")
running = false
else
socket:write("+$E00#a5")
end
elseif cmd == "c" then
if #packet == 1 then
cpu:debug():go()
socket:write("+$OK#9a")
else
socket:write("+$E00#a5")
end
elseif cmd == "Z" then
local btype, addr, kind = packet:match("Z([0-4]),(%x+),(.*)")
addr = tonumber(addr, 16)
if btype == "0" then
socket:write("") -- is machine dependant
elseif btype == "1" then
if breaks.byaddr[addr] then
socket:write("+$E00#a5")
return
end
local idx = cpu:debug():bpset(addr)
breaks.byaddr[addr] = idx
breaks.byidx[idx] = addr
socket:write("+$OK#9a")
elseif btype == "2" then
if watches.byaddr[addr] then
socket:write("+$E00#a5")
return
end
local idx = cpu:debug():wpset(cpu.spaces["program"], "w", addr, 1)
watches.byaddr[addr] = idx
watches.byidx[idx] = {addr = addr, type = "watch"}
socket:write("+$OK#9a")
elseif btype == "3" then
if watches.byaddr[addr] then
socket:write("+$E00#a5")
return
end
local idx = cpu:debug():wpset(cpu.spaces["program"], "r", addr, 1)
watches.byaddr[addr] = idx
watches.byidx[idx] = {addr = addr, type = "rwatch"}
socket:write("+$OK#9a")
elseif btype == "4" then
if watches.byaddr[addr] then
socket:write("+$E00#a5")
return
end
local idx = cpu:debug():wpset(cpu.spaces["program"], "rw", addr, 1)
watches.byaddr[addr] = idx
watches.byidx[idx] = {addr = addr, type = "awatch"}
socket:write("+$OK#9a")
end
elseif cmd == "z" then
local btype, addr, kind = packet:match("z([0-4]),(%x+),(.*)")
addr = tonumber(addr, 16)
if btype == "0" then
socket:write("") -- is machine dependent
elseif btype == "1" then
if not breaks.byaddr[addr] then
socket:write("+$E00#a5")
return
end
local idx = breaks.byaddr[addr]
cpu:debug():bpclr(idx)
breaks.byaddr[addr] = nil
breaks.byidx[idx] = nil
socket:write("+$OK#9a")
elseif btype == "2" or btype == "3" or btype == "4" then
if not watches.byaddr[addr] then
socket:write("+$E00#a5")
return
end
local idx = watches.byaddr[addr]
cpu:debug():wpclr(idx)
watches.byaddr[addr] = nil
watches.byidx[idx] = nil
socket:write("+$OK#9a")
end
elseif cmd == "?" then
socket:write("+$S05#B8")
else
socket:write("+$#00")
end
end
end)
end
return exports
pan>
//uint32_t xscroll = scrollregs[0];
uint32_t yscroll = scrollregs[1];
int realline = (scanline + yscroll) & 0xff;
uint32_t tile = spc.read_word(tilemap + realline);
uint16_t palette = 0;
//if (!tile)
// continue;
palette = spc.read_word(palette_map + realline / 2);
if (scanline & 1)
palette >>= 8;
else
palette &= 0x00ff;
//const int linewidth = 320 / 2;
int sourcebase = tile | (palette << 16);
uint32_t ctrl = tilemapregs[1];
if (ctrl & 0x80) // HiColor mode (rad_digi)
{
for (int i = 0; i < 320; i++)
{
const uint16_t data = spc.read_word(sourcebase + i);
if (!(data & 0x8000))
{
dst[i] = m_rgb555_to_rgb888[data & 0x7fff];
}
}
}
else
{
for (int i = 0; i < 320 / 2; i++)
{
uint8_t palette_entry;
uint16_t color;
const uint16_t data = spc.read_word(sourcebase + i);
palette_entry = (data & 0x00ff);
color = paletteram[palette_entry];
if (!(color & 0x8000))
{
dst[(i * 2) + 0] = m_rgb555_to_rgb888[color & 0x7fff];
}
palette_entry = (data & 0xff00) >> 8;
color = paletteram[palette_entry];
if (!(color & 0x8000))
{
dst[(i * 2) + 1] = m_rgb555_to_rgb888[color & 0x7fff];
}
}
}
}
}
// this builds up a line table for the vcmp effect, this is not correct when step is used
void spg_renderer_device::update_vcmp_table()
{
int currentline = 0;
int step = m_video_regs_1e & 0xff;
if (step & 0x80)
step = step - 0x100;
int current_inc_value = (m_video_regs_1c<<4);
int counter = 0;
for (int i = 0; i < 480; i++)
{
if (i < m_video_regs_1d)
{
m_ycmp_table[i] = 0xffffffff;
}
else
{
if ((currentline >= 0) && (currentline < 256))
{
m_ycmp_table[i] = currentline;
}
counter += current_inc_value;
while (counter >= (0x20<<4))
{
currentline++;
current_inc_value += step;
counter -= (0x20<<4);
}
}
}
}
void spg_renderer_device::draw_tilestrip(bool read_from_csspace, uint32_t screenwidth, uint32_t drawwidthmask, spg_renderer_device::blend_enable_t blend, spg_renderer_device::flipx_t flip_x, const rectangle& cliprect, uint32_t* dst, uint32_t tile_h, uint32_t tile_w, uint32_t tilegfxdata_addr, uint32_t tile, uint32_t tile_scanline, int drawx, bool flip_y, uint32_t palette_offset, const uint32_t nc_bpp, const uint32_t bits_per_row, const uint32_t words_per_tile, address_space& spc, uint16_t* paletteram, uint8_t blendlevel)
{
if (blend)
{
if (flip_x)
{
draw_tilestrip<BlendOn, FlipXOn>(read_from_csspace, screenwidth, drawwidthmask, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
else
{
draw_tilestrip<BlendOn, FlipXOff>(read_from_csspace, screenwidth, drawwidthmask, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
}
else
{
if (flip_x)
{
draw_tilestrip<BlendOff, FlipXOn>(read_from_csspace, screenwidth, drawwidthmask, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
else
{
draw_tilestrip<BlendOff, FlipXOff>(read_from_csspace, screenwidth, drawwidthmask, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
}
}
void spg_renderer_device::draw_page(bool read_from_csspace, bool has_extended_tilemaps, bool use_alt_tile_addressing, uint32_t palbank, const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t tilegfxdata_addr, uint16_t* scrollregs, uint16_t* tilemapregs, address_space& spc, uint16_t* paletteram, uint16_t* scrollram, uint32_t which)
{
const uint32_t attr = tilemapregs[0];
const uint32_t ctrl = tilemapregs[1];
if (!(ctrl & 0x0008))
{
return;
}
if (((attr & 0x3000) >> 12) != priority)
{
return;
}
if (ctrl & 0x0001) // Bitmap / Linemap mode! (basically screen width tile mode)
{
draw_linemap(has_extended_tilemaps, cliprect, dst, scanline, priority, tilegfxdata_addr, scrollregs, tilemapregs, spc, paletteram);
return;
}
uint32_t logical_scanline = scanline;
if (ctrl & 0x0040) // 'vertical compression feature' (later models only?)
{
if (m_video_regs_1e != 0x0000)
popmessage("vertical compression mode with non-0 step amount %04x offset %04x step %04x\n", m_video_regs_1c, m_video_regs_1d, m_video_regs_1e);
logical_scanline = m_ycmp_table[scanline];
if (logical_scanline == 0xffffffff)
return;
}
uint32_t total_width;
uint32_t y_mask;
uint32_t screenwidth;
uint32_t drawwidthmask;
if (read_from_csspace && ((attr >> 15) & 0x1))
{
// just a guess based on this being set on the higher resolution tilemaps we've seen, could be 100% incorrect register
total_width = 1024;
y_mask = 0x1ff;
screenwidth = 640;
drawwidthmask = 0x400 - 1;
}
else
{
total_width = 512;
y_mask = 0xff;
screenwidth = 320;
drawwidthmask = 0x200 - 1;
}
const uint32_t xscroll = scrollregs[0];
const uint32_t yscroll = scrollregs[1];
const uint32_t tilemap_rambase = tilemapregs[2];
const uint32_t exattributemap_rambase = tilemapregs[3];
const int tile_width = (attr & 0x0030) >> 4;
const uint32_t tile_h = 8 << ((attr & 0x00c0) >> 6);
const uint32_t tile_w = 8 << (tile_width);
const uint32_t tile_count_x = total_width / tile_w; // tilemaps are 512 or 1024 wide depending on screen mode?
const uint32_t bitmap_y = (logical_scanline + yscroll) & y_mask; // tilemaps are 256 or 512 high depending on screen mode?
const uint32_t y0 = bitmap_y / tile_h;
const uint32_t tile_scanline = bitmap_y % tile_h;
const uint8_t bpp = attr & 0x0003;
const uint32_t nc_bpp = ((bpp)+1) << 1;
const uint32_t bits_per_row = nc_bpp * tile_w / 16;
//const uint32_t words_per_tile = bits_per_row * tile_h;
const bool row_scroll = (ctrl & 0x0010);
uint8_t blendlevel = (m_video_regs_2a & 3) << 6;
uint32_t words_per_tile;
// good for gormiti, smartfp, wrlshunt, paccon, jak_totm, jak_s500, jak_gtg
if (has_extended_tilemaps && use_alt_tile_addressing)
{
words_per_tile = 8;
}
else
{
words_per_tile = bits_per_row * tile_h;
}
int realxscroll = xscroll;
if (row_scroll)
{
// Tennis in My Wireless Sports confirms the need to add the scroll value here rather than rowscroll being screen-aligned
realxscroll += (int16_t)scrollram[(logical_scanline + yscroll) & 0xff];
}
const int upperscrollbits = (realxscroll >> (tile_width + 3));
const int endpos = (screenwidth + tile_w) / tile_w;
int upperpalselect = 0;
if (has_extended_tilemaps && (tilegfxdata_addr & 0x80000000))
upperpalselect = 1;
tilegfxdata_addr &= 0x7ffffff;
for (uint32_t x0 = 0; x0 < endpos; x0++)
{
spg_renderer_device::blend_enable_t blend;
spg_renderer_device::flipx_t flip_x;
bool flip_y;
uint32_t tile;
uint32_t palette_offset;
// get tile info
const int realx0 = (x0 + upperscrollbits) & (tile_count_x - 1);
uint32_t tile_address = realx0 + (tile_count_x * y0);
tile = (ctrl & 0x0004) ? spc.read_word(tilemap_rambase) : spc.read_word(tilemap_rambase + tile_address);
if (!tile)
continue;
uint32_t tileattr = attr;
uint32_t tilectrl = ctrl;
if (has_extended_tilemaps && use_alt_tile_addressing)
{
// in this mode what would be the 'palette' bits get used for extra tile bits (even if the usual 'extended table' mode is disabled?)
// used by smartfp
uint16_t exattribute = (ctrl & 0x0004) ? spc.read_word(exattributemap_rambase) : spc.read_word(exattributemap_rambase + tile_address / 2);
if (realx0 & 1)
exattribute >>= 8;
else
exattribute &= 0x00ff;
tile |= (exattribute & 0x07) << 16;
//blendlevel = 0x1f; // hack
}
else if ((ctrl & 2) == 0)
{ // -(1) bld(1) flip(2) pal(4)
uint16_t exattribute = (ctrl & 0x0004) ? spc.read_word(exattributemap_rambase) : spc.read_word(exattributemap_rambase + tile_address / 2);
if (realx0 & 1)
exattribute >>= 8;
else
exattribute &= 0x00ff;
tileattr &= ~0x000c;
tileattr |= (exattribute >> 2) & 0x000c; // flip
tileattr &= ~0x0f00;
tileattr |= (exattribute << 8) & 0x0f00; // palette
tilectrl &= ~0x0100;
tilectrl |= (exattribute << 2) & 0x0100; // blend
}
blend = ((tileattr & 0x4000 || tilectrl & 0x0100)) ? BlendOn : BlendOff;
flip_x = (tileattr & 0x0004) ? FlipXOn : FlipXOff;
flip_y = (tileattr & 0x0008);
palette_offset = (tileattr & 0x0f00) >> 4;
// got tile info
if (upperpalselect)
palette_offset |= 0x200;
palette_offset >>= nc_bpp;
palette_offset <<= nc_bpp;
const int drawx = (x0 * tile_w) - (realxscroll & (tile_w - 1));
draw_tilestrip(read_from_csspace, screenwidth, drawwidthmask, blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, tile_scanline, drawx, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
}
void spg_renderer_device::draw_sprite(bool read_from_csspace, bool has_extended_sprites, bool alt_extrasprite_hack, uint32_t palbank, bool highres, const rectangle& cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t spritegfxdata_addr, uint32_t base_addr, address_space &spc, uint16_t* paletteram, uint16_t* spriteram)
{
uint32_t tilegfxdata_addr = spritegfxdata_addr;
uint32_t tile = spriteram[base_addr + 0];
int16_t x = spriteram[base_addr + 1];
int16_t y = spriteram[base_addr + 2];
uint16_t attr = spriteram[base_addr + 3];
if (!tile)
{
return;
}
if (((attr & 0x3000) >> 12) != priority)
{
return;
}
uint32_t screenwidth = 320;
// uint32_t screenheight = 240;
uint32_t screenheight = 256;
uint32_t xmask = 0x1ff;
uint32_t ymask = 0x1ff;
if (highres)
{
screenwidth = 640;
// screenheight = 480;
screenheight = 512;
xmask = 0x3ff;
}
const uint32_t tile_h = 8 << ((attr & 0x00c0) >> 6);
const uint32_t tile_w = 8 << ((attr & 0x0030) >> 4);
if (!(m_video_regs_42 & 0x0002))
{
x = ((screenwidth/2) + x) - tile_w / 2;
// y = ((screenheight/2) - y) - (tile_h / 2) + 8;
y = ((screenheight/2) - y) - (tile_h / 2);
}
x &= xmask;
y &= ymask;
int firstline = y;
int lastline = y + (tile_h - 1);
lastline &= ymask;
const spg_renderer_device::blend_enable_t blend = (attr & 0x4000) ? BlendOn : BlendOff;
spg_renderer_device::flipx_t flip_x = (attr & 0x0004) ? FlipXOn : FlipXOff;
const uint8_t bpp = attr & 0x0003;
const uint32_t nc_bpp = ((bpp)+1) << 1;
const uint32_t bits_per_row = nc_bpp * tile_w / 16;
uint8_t blendlevel = (m_video_regs_2a & 3) << 6;
uint32_t words_per_tile;
// good for gormiti, smartfp, wrlshunt, paccon, jak_totm, jak_s500, jak_gtg
if (has_extended_sprites && ((m_video_regs_42 & 0x0010) == 0x10))
{
// paccon and smartfp use this mode
words_per_tile = 8;
if (!alt_extrasprite_hack) // 1 extra word for each sprite
{
// before or after the 0 tile check?
tile |= (spriteram[(base_addr / 4) + 0x400] & 0x01ff) << 16;
blendlevel = ((spriteram[(base_addr / 4) + 0x400] & 0x3e00) >> 9) << 3;
}
else // jak_prft - no /4 to offset in this mode - 4 extra words per sprite instead ? (or is RAM content incorrect for one of these cases?)
{
tile |= spriteram[(base_addr) + 0x400] << 16;
blendlevel = ((spriteram[(base_addr) + 0x400] & 0x3e00) >> 9) << 3;
}
}
else
{
words_per_tile = bits_per_row * tile_h;
}
bool flip_y = (attr & 0x0008);
// various games don't want the flip bits in the usual place, wrlshunt for example, there's probably a bit to control this
// and likewise these bits probably now have a different meaning, so this shouldn't be trusted
if (has_extended_sprites)
{
if (highres || alt_extrasprite_hack)
{
flip_x = FlipXOff;
flip_y = 0;
}
}
uint32_t palette_offset = (attr & 0x0f00) >> 4;
if (has_extended_sprites)
{
// guess, tkmag220 / myac220 don't set this bit and expect all sprite palettes to be from the same bank as background palettes
if (palbank & 1)
palette_offset |= 0x100;
// many other gpl16250 sets have this bit set when they want the upper 256 colours on a per-sprite basis, seems like an extended feature
if (attr & 0x8000)
palette_offset |= 0x200;
}
// the Circuit Racing game in PDC100 needs this or some graphics have bad colours at the edges when turning as it leaves stray lower bits set
palette_offset >>= nc_bpp;
palette_offset <<= nc_bpp;
if (firstline < lastline)
{
int scanx = scanline - firstline;
if ((scanx >= 0) && (scanline <= lastline))
{
draw_tilestrip(read_from_csspace, screenwidth, xmask, blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
}
else
{
// clipped from top
int tempfirstline = firstline - 0x200;
int templastline = lastline;
int scanx = scanline - tempfirstline;
if ((scanx >= 0) && (scanline <= templastline))
{
draw_tilestrip(read_from_csspace, screenwidth, xmask, blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
// clipped against the bottom
tempfirstline = firstline;
templastline = lastline + 0x200;
scanx = scanline - tempfirstline;
if ((scanx >= 0) && (scanline <= templastline))
{
draw_tilestrip(read_from_csspace, screenwidth, xmask, blend, flip_x, cliprect, dst, tile_h, tile_w, tilegfxdata_addr, tile, scanx, x, flip_y, palette_offset, nc_bpp, bits_per_row, words_per_tile, spc, paletteram, blendlevel);
}
}
}
void spg_renderer_device::draw_sprites(bool read_from_csspace, bool has_extended_sprites, bool alt_extrasprite_hack, uint32_t palbank, bool highres, const rectangle &cliprect, uint32_t* dst, uint32_t scanline, int priority, uint32_t spritegfxdata_addr, address_space &spc, uint16_t* paletteram, uint16_t* spriteram, int sprlimit)
{
if (!(m_video_regs_42 & 0x0001))
{
return;
}
// paccon suggests this, does older hardware have similar (if so, starting at what point?) or only GPL16250?
if (sprlimit == -1)
{
sprlimit = (m_video_regs_42 & 0xff00) >> 8;
if (sprlimit == 0)
sprlimit = 0x100;
}
for (uint32_t n = 0; n < sprlimit; n++)
{
draw_sprite(read_from_csspace, has_extended_sprites, alt_extrasprite_hack, palbank, highres, cliprect, dst, scanline, priority, spritegfxdata_addr, 4 * n, spc, paletteram, spriteram);
}
}
void spg_renderer_device::apply_saturation_and_fade(bitmap_rgb32& bitmap, const rectangle& cliprect, int scanline)
{
static const float s_u8_to_float = 1.0f / 255.0f;
static const float s_gray_r = 0.299f;
static const float s_gray_g = 0.587f;
static const float s_gray_b = 0.114f;
const float sat_adjust = (0xff - (m_video_regs_3c & 0x00ff)) / (float)(0xff - 0x20);
const uint16_t fade_offset = m_video_regs_30;
uint32_t* src = &bitmap.pix32(scanline, cliprect.min_x);
for (int x = cliprect.min_x; x <= cliprect.max_x; x++)
{
if ((m_video_regs_3c & 0x00ff) != 0x0020) // apply saturation
{
const uint32_t src_rgb = *src;
const float src_r = (uint8_t)(src_rgb >> 16) * s_u8_to_float;
const float src_g = (uint8_t)(src_rgb >> 8) * s_u8_to_float;
const float src_b = (uint8_t)(src_rgb >> 0) * s_u8_to_float;
const float luma = src_r * s_gray_r + src_g * s_gray_g + src_b * s_gray_b;
const float adjusted_r = luma + (src_r - luma) * sat_adjust;
const float adjusted_g = luma + (src_g - luma) * sat_adjust;
const float adjusted_b = luma + (src_b - luma) * sat_adjust;
const int integer_r = (int)floor(adjusted_r * 255.0f);
const int integer_g = (int)floor(adjusted_g * 255.0f);
const int integer_b = (int)floor(adjusted_b * 255.0f);
*src = (integer_r > 255 ? 0xff0000 : (integer_r < 0 ? 0 : ((uint8_t)integer_r << 16))) |
(integer_g > 255 ? 0x00ff00 : (integer_g < 0 ? 0 : ((uint8_t)integer_g << 8))) |
(integer_b > 255 ? 0x0000ff : (integer_b < 0 ? 0 : (uint8_t)integer_b));
}
if (fade_offset != 0) // apply fade
{
const uint32_t src_rgb = *src;
const uint8_t src_r = (src_rgb >> 16) & 0xff;
const uint8_t src_g = (src_rgb >> 8) & 0xff;
const uint8_t src_b = (src_rgb >> 0) & 0xff;
const uint8_t r = src_r - fade_offset;
const uint8_t g = src_g - fade_offset;
const uint8_t b = src_b - fade_offset;
*src = (r > src_r ? 0 : (r << 16)) |
(g > src_g ? 0 : (g << 8)) |
(b > src_b ? 0 : (b << 0));
}
src++;
}
}
|