2010-08-09 13:28:56 +00:00
|
|
|
Video video;
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
Video::Video() {
|
2015-11-16 08:38:05 +00:00
|
|
|
palette = new uint32[1 << 19]();
|
2015-11-14 00:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Video::~Video() {
|
|
|
|
delete[] palette;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto Video::generate_palette(Emulator::Interface::PaletteMode mode) -> void {
|
|
|
|
for(auto color : range(1 << 19)) {
|
2013-12-21 10:45:58 +00:00
|
|
|
if(mode == Emulator::Interface::PaletteMode::Literal) {
|
2013-12-20 11:40:39 +00:00
|
|
|
palette[color] = color;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
uint l = (color >> 15) & 15;
|
|
|
|
uint b = (color >> 10) & 31;
|
|
|
|
uint g = (color >> 5) & 31;
|
|
|
|
uint r = (color >> 0) & 31;
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
|
2013-12-21 10:45:58 +00:00
|
|
|
if(mode == Emulator::Interface::PaletteMode::Channel) {
|
|
|
|
l = image::normalize(l, 4, 16);
|
|
|
|
r = image::normalize(r, 5, 16);
|
|
|
|
g = image::normalize(g, 5, 16);
|
|
|
|
b = image::normalize(b, 5, 16);
|
|
|
|
palette[color] = interface->videoColor(color, l, r, g, b);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-12-20 11:40:39 +00:00
|
|
|
if(mode == Emulator::Interface::PaletteMode::Emulation) {
|
2013-12-07 09:12:37 +00:00
|
|
|
r = gamma_ramp[r];
|
|
|
|
g = gamma_ramp[g];
|
|
|
|
b = gamma_ramp[b];
|
|
|
|
} else {
|
2013-12-21 10:45:58 +00:00
|
|
|
r = image::normalize(r, 5, 8);
|
|
|
|
g = image::normalize(g, 5, 8);
|
|
|
|
b = image::normalize(b, 5, 8);
|
2013-12-07 09:12:37 +00:00
|
|
|
}
|
|
|
|
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
double L = (1.0 + l) / 16.0;
|
|
|
|
if(l == 0) L *= 0.5;
|
2015-11-14 00:52:51 +00:00
|
|
|
uint R = L * image::normalize(r, 8, 16);
|
|
|
|
uint G = L * image::normalize(g, 8, 16);
|
|
|
|
uint B = L * image::normalize(b, 8, 16);
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
|
2013-12-21 10:45:58 +00:00
|
|
|
palette[color] = interface->videoColor(color, 0, R, G, B);
|
2011-10-27 13:30:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//internal
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
const uint8 Video::gamma_ramp[32] = {
|
2013-12-07 09:12:37 +00:00
|
|
|
0x00, 0x01, 0x03, 0x06, 0x0a, 0x0f, 0x15, 0x1c,
|
|
|
|
0x24, 0x2d, 0x37, 0x42, 0x4e, 0x5b, 0x69, 0x78,
|
|
|
|
0x88, 0x90, 0x98, 0xa0, 0xa8, 0xb0, 0xb8, 0xc0,
|
|
|
|
0xc8, 0xd0, 0xd8, 0xe0, 0xe8, 0xf0, 0xf8, 0xff,
|
|
|
|
};
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
const uint8 Video::cursor[15 * 15] = {
|
2010-08-09 13:28:56 +00:00
|
|
|
0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,
|
|
|
|
0,0,0,0,1,1,2,2,2,1,1,0,0,0,0,
|
|
|
|
0,0,0,1,2,2,1,2,1,2,2,1,0,0,0,
|
|
|
|
0,0,1,2,1,1,0,1,0,1,1,2,1,0,0,
|
|
|
|
0,1,2,1,0,0,0,1,0,0,0,1,2,1,0,
|
|
|
|
0,1,2,1,0,0,1,2,1,0,0,1,2,1,0,
|
|
|
|
1,2,1,0,0,1,1,2,1,1,0,0,1,2,1,
|
|
|
|
1,2,2,1,1,2,2,2,2,2,1,1,2,2,1,
|
|
|
|
1,2,1,0,0,1,1,2,1,1,0,0,1,2,1,
|
|
|
|
0,1,2,1,0,0,1,2,1,0,0,1,2,1,0,
|
|
|
|
0,1,2,1,0,0,0,1,0,0,0,1,2,1,0,
|
|
|
|
0,0,1,2,1,1,0,1,0,1,1,2,1,0,0,
|
|
|
|
0,0,0,1,2,2,1,2,1,2,2,1,0,0,0,
|
|
|
|
0,0,0,0,1,1,2,2,2,1,1,0,0,0,0,
|
|
|
|
0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,
|
|
|
|
};
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto Video::draw_cursor(uint16 color, int x, int y) -> void {
|
|
|
|
uint32* data = (uint32*)ppu.output;
|
2010-08-22 00:44:27 +00:00
|
|
|
if(ppu.interlace() && ppu.field()) data += 512;
|
|
|
|
|
2010-08-09 13:28:56 +00:00
|
|
|
for(int cy = 0; cy < 15; cy++) {
|
|
|
|
int vy = y + cy - 7;
|
|
|
|
if(vy <= 0 || vy >= 240) continue; //do not draw offscreen
|
|
|
|
|
|
|
|
bool hires = (line_width[vy] == 512);
|
|
|
|
for(int cx = 0; cx < 15; cx++) {
|
|
|
|
int vx = x + cx - 7;
|
|
|
|
if(vx < 0 || vx >= 256) continue; //do not draw offscreen
|
2015-11-16 08:38:05 +00:00
|
|
|
uint8 pixel = cursor[cy * 15 + cx];
|
2010-08-09 13:28:56 +00:00
|
|
|
if(pixel == 0) continue;
|
2015-11-16 08:38:05 +00:00
|
|
|
uint32 pixelcolor = (15 << 15) | ((pixel == 1) ? 0 : color);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
if(hires == false) {
|
2015-11-16 08:38:05 +00:00
|
|
|
*((uint32*)data + vy * 1024 + vx) = pixelcolor;
|
2010-08-09 13:28:56 +00:00
|
|
|
} else {
|
2015-11-16 08:38:05 +00:00
|
|
|
*((uint32*)data + vy * 1024 + vx * 2 + 0) = pixelcolor;
|
|
|
|
*((uint32*)data + vy * 1024 + vx * 2 + 1) = pixelcolor;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto Video::update() -> void {
|
2015-11-10 11:02:29 +00:00
|
|
|
switch(configuration.controllerPort2) {
|
|
|
|
case Device::ID::SuperScope:
|
|
|
|
if(dynamic_cast<SuperScope*>(device.controllerPort2)) {
|
2015-11-16 08:38:05 +00:00
|
|
|
auto& controller = (SuperScope&)*device.controllerPort2;
|
2015-11-10 11:02:29 +00:00
|
|
|
draw_cursor(0x7c00, controller.x, controller.y);
|
2011-06-24 10:43:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-10 11:02:29 +00:00
|
|
|
case Device::ID::Justifier:
|
|
|
|
case Device::ID::Justifiers:
|
|
|
|
if(dynamic_cast<Justifier*>(device.controllerPort2)) {
|
2015-11-16 08:38:05 +00:00
|
|
|
auto& controller = (Justifier&)*device.controllerPort2;
|
2015-11-10 11:02:29 +00:00
|
|
|
draw_cursor(0x001f, controller.player1.x, controller.player1.y);
|
|
|
|
if(!controller.chained) break;
|
|
|
|
draw_cursor(0x02e0, controller.player2.x, controller.player2.y);
|
2011-06-24 10:43:29 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto data = (uint32*)ppu.output;
|
2010-08-22 00:44:27 +00:00
|
|
|
if(ppu.interlace() && ppu.field()) data += 512;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-04-30 13:12:15 +00:00
|
|
|
if(hires) {
|
2010-08-09 13:28:56 +00:00
|
|
|
//normalize line widths
|
|
|
|
for(unsigned y = 0; y < 240; y++) {
|
|
|
|
if(line_width[y] == 512) continue;
|
2015-11-14 00:52:51 +00:00
|
|
|
uint32* buffer = data + y * 1024;
|
2010-08-09 13:28:56 +00:00
|
|
|
for(signed x = 255; x >= 0; x--) {
|
|
|
|
buffer[(x * 2) + 0] = buffer[(x * 2) + 1] = buffer[x];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Update to v088r15 release.
byuu says:
Changelog:
- default placement of presentation window optimized for 1024x768
displays or larger (sorry if yours is smaller, move the window
yourself.)
- Direct3D waits until a previous Vblank ends before waiting for the
next Vblank to begin (fixes video timing analysis, and ---really---
fast computers.)
- Window::setVisible(false) clears modality, but also fixed in Browser
code as well (fixes loading images on Windows hanging)
- Browser won't consume full CPU resources (but timing analysis will,
I don't want stalls to affect the results.)
- closing settings window while analyzing stops analysis
- you can load the SGB BIOS without a game (why the hell you would want
to ...)
- escape closes the Browser window (it won't close other dialogs, it has
to be hooked up per-window)
- just for fun, joypad hat up/down moves in Browser file list, any
joypad button loads selected game [not very useful, lacks repeat, and
there aren't GUI load file open buttons]
- Super Scope and Justifier crosshairs render correctly (probably
doesn't belong in the core, but it's not something I suspect people
want to do themselves ...)
- you can load GB, SGB, GB, SGB ... without problems (not happy with how
I did this, but I don't want to add an Interface::setInterface()
function yet)
- PAL timing works as I want now (if you want 50fps on a 60hz monitor,
you must not use sync video) [needed to update the DSP frequency when
toggling video/audio sync]
- not going to save input port selection for now (lot of work), but it
will properly keep your port setting across cartridge loads at least
[just goes to controller on emulator restart]
- SFC overscan on and off both work as expected now (off centers image,
on shows entire image)
- laevateinn compiles properly now
- ethos goes to ~/.config/bsnes now that target-ui is dead [honestly,
I recommend deleting the old folder and starting over]
- Emulator::Interface callbacks converted to virtual binding structure
that GUI inherits from (simplifies binding callbacks)
- this breaks Super Game Boy for a bit, I need to rethink
system-specific bindings without direct inheritance
Timing analysis works spectacularly well on Windows, too. You won't get
your 100% perfect rate (unless maybe you leave the analysis running
overnight?), but it'll get really freaking close this way.
2012-05-07 23:29:03 +00:00
|
|
|
//overscan: when disabled, shift image down (by scrolling video buffer up) to center image onscreen
|
|
|
|
//(memory before ppu.output is filled with black scanlines)
|
|
|
|
interface->videoRefresh(
|
2013-12-20 11:40:39 +00:00
|
|
|
video.palette,
|
Update to v088r15 release.
byuu says:
Changelog:
- default placement of presentation window optimized for 1024x768
displays or larger (sorry if yours is smaller, move the window
yourself.)
- Direct3D waits until a previous Vblank ends before waiting for the
next Vblank to begin (fixes video timing analysis, and ---really---
fast computers.)
- Window::setVisible(false) clears modality, but also fixed in Browser
code as well (fixes loading images on Windows hanging)
- Browser won't consume full CPU resources (but timing analysis will,
I don't want stalls to affect the results.)
- closing settings window while analyzing stops analysis
- you can load the SGB BIOS without a game (why the hell you would want
to ...)
- escape closes the Browser window (it won't close other dialogs, it has
to be hooked up per-window)
- just for fun, joypad hat up/down moves in Browser file list, any
joypad button loads selected game [not very useful, lacks repeat, and
there aren't GUI load file open buttons]
- Super Scope and Justifier crosshairs render correctly (probably
doesn't belong in the core, but it's not something I suspect people
want to do themselves ...)
- you can load GB, SGB, GB, SGB ... without problems (not happy with how
I did this, but I don't want to add an Interface::setInterface()
function yet)
- PAL timing works as I want now (if you want 50fps on a 60hz monitor,
you must not use sync video) [needed to update the DSP frequency when
toggling video/audio sync]
- not going to save input port selection for now (lot of work), but it
will properly keep your port setting across cartridge loads at least
[just goes to controller on emulator restart]
- SFC overscan on and off both work as expected now (off centers image,
on shows entire image)
- laevateinn compiles properly now
- ethos goes to ~/.config/bsnes now that target-ui is dead [honestly,
I recommend deleting the old folder and starting over]
- Emulator::Interface callbacks converted to virtual binding structure
that GUI inherits from (simplifies binding callbacks)
- this breaks Super Game Boy for a bit, I need to rethink
system-specific bindings without direct inheritance
Timing analysis works spectacularly well on Windows, too. You won't get
your 100% perfect rate (unless maybe you leave the analysis running
overnight?), but it'll get really freaking close this way.
2012-05-07 23:29:03 +00:00
|
|
|
ppu.output - (ppu.overscan() ? 0 : 7 * 1024),
|
|
|
|
4 * (1024 >> ppu.interlace()),
|
|
|
|
256 << hires,
|
|
|
|
240 << ppu.interlace()
|
|
|
|
);
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2011-04-30 13:12:15 +00:00
|
|
|
hires = false;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto Video::scanline() -> void {
|
|
|
|
uint y = cpu.vcounter();
|
2010-08-09 13:28:56 +00:00
|
|
|
if(y >= 240) return;
|
|
|
|
|
2011-04-30 13:12:15 +00:00
|
|
|
hires |= ppu.hires();
|
2015-11-14 00:52:51 +00:00
|
|
|
uint width = (ppu.hires() == false ? 256 : 512);
|
2010-08-09 13:28:56 +00:00
|
|
|
line_width[y] = width;
|
|
|
|
}
|
|
|
|
|
2015-11-14 00:52:51 +00:00
|
|
|
auto Video::init() -> void {
|
2011-04-30 13:12:15 +00:00
|
|
|
hires = false;
|
2013-05-05 09:21:30 +00:00
|
|
|
for(auto& n : line_width) n = 256;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|