2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2010-08-09 13:28:56 +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
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
|
2010-08-09 13:28:56 +00:00
|
|
|
namespace nall {
|
|
|
|
|
2016-08-09 11:07:18 +00:00
|
|
|
template<uint bits> inline auto uclamp(const uintmax x) -> uintmax {
|
|
|
|
enum : uintmax { b = 1ull << (bits - 1), y = b * 2 - 1 };
|
2013-05-02 11:25:45 +00:00
|
|
|
return y + ((x - y) & -(x < y)); //min(x, y);
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-08-09 11:07:18 +00:00
|
|
|
template<uint bits> inline auto uclip(const uintmax x) -> uintmax {
|
|
|
|
enum : uintmax { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
2013-05-02 11:25:45 +00:00
|
|
|
return (x & m);
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-08-09 11:07:18 +00:00
|
|
|
template<uint bits> inline auto sclamp(const intmax x) -> intmax {
|
|
|
|
enum : intmax { b = 1ull << (bits - 1), m = b - 1 };
|
2013-05-02 11:25:45 +00:00
|
|
|
return (x > m) ? m : (x < -b) ? -b : x;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2016-08-09 11:07:18 +00:00
|
|
|
template<uint bits> inline auto sclip(const intmax x) -> intmax {
|
|
|
|
enum : uintmax { b = 1ull << (bits - 1), m = b * 2 - 1 };
|
2013-05-02 11:25:45 +00:00
|
|
|
return ((x & m) ^ b) - b;
|
|
|
|
}
|
2012-03-27 11:02:57 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
namespace bit {
|
2016-08-09 11:07:18 +00:00
|
|
|
constexpr inline auto mask(const char* s, uintmax sum = 0) -> uintmax {
|
2013-05-02 11:25:45 +00:00
|
|
|
return (
|
|
|
|
*s == '0' || *s == '1' ? mask(s + 1, (sum << 1) | 1) :
|
|
|
|
*s == ' ' || *s == '_' ? mask(s + 1, sum) :
|
|
|
|
*s ? mask(s + 1, sum << 1) :
|
|
|
|
sum
|
|
|
|
);
|
|
|
|
}
|
2012-03-27 11:02:57 +00:00
|
|
|
|
2016-08-09 11:07:18 +00:00
|
|
|
constexpr inline auto test(const char* s, uintmax sum = 0) -> uintmax {
|
2013-05-02 11:25:45 +00:00
|
|
|
return (
|
|
|
|
*s == '0' || *s == '1' ? test(s + 1, (sum << 1) | (*s - '0')) :
|
|
|
|
*s == ' ' || *s == '_' ? test(s + 1, sum) :
|
|
|
|
*s ? test(s + 1, sum << 1) :
|
|
|
|
sum
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
//lowest(0b1110) == 0b0010
|
2016-08-09 11:07:18 +00:00
|
|
|
constexpr inline auto lowest(const uintmax x) -> uintmax {
|
2013-05-02 11:25:45 +00:00
|
|
|
return x & -x;
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
//clear_lowest(0b1110) == 0b1100
|
2016-08-09 11:07:18 +00:00
|
|
|
constexpr inline auto clearLowest(const uintmax x) -> uintmax {
|
2013-05-02 11:25:45 +00:00
|
|
|
return x & (x - 1);
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
//set_lowest(0b0101) == 0b0111
|
2016-08-09 11:07:18 +00:00
|
|
|
constexpr inline auto setLowest(const uintmax x) -> uintmax {
|
2013-05-02 11:25:45 +00:00
|
|
|
return x | (x + 1);
|
|
|
|
}
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
//count number of bits set in a byte
|
2016-08-09 11:07:18 +00:00
|
|
|
inline auto count(uintmax x) -> uint {
|
Update to v098r11 release.
byuu says:
Changelog:
- fixed nall/path.hpp compilation issue
- fixed ruby/audio/xaudio header declaration compilation issue (again)
- cleaned up xaudio2.hpp file to match my coding syntax (12.5% of the
file was whitespace overkill)
- added null terminator entry to nall/windows/utf8.hpp argc[] array
- nall/windows/guid.hpp uses the Windows API for generating the GUID
- this should stop all the bug reports where two nall users were
generating GUIDs at the exact same second
- fixed hiro/cocoa compilation issue with uint# types
- fixed major higan/sfc Super Game Boy audio latency issue
- fixed higan/sfc CPU core bug with pei, [dp], [dp]+y instructions
- major cleanups to higan/processor/r65816 core
- merged emulation/native-mode opcodes
- use camel-case naming on memory.hpp functions
- simplify address masking code for memory.hpp functions
- simplify a few opcodes themselves (avoid redundant copies, etc)
- rename regs.* to r.* to match modern convention of other CPU cores
- removed device.order<> concept from Emulator::Interface
- cores will now do the translation to make the job of the UI easier
- fixed plurality naming of arrays in Emulator::Interface
- example: emulator.ports[p].devices[d].inputs[i]
- example: vector<Medium> media
- probably more surprises
Major show-stoppers to the next official release:
- we need to work on GB core improvements: LY=153/0 case, multiple STAT
IRQs case, GBC audio output regs, etc.
- we need to re-add software cursors for light guns (Super Scope,
Justifier)
- after the above, we need to fix the turbo button for the Super Scope
I really have no idea how I want to implement the light guns. Ideally,
we'd want it in higan/video, so we can support the NES Zapper with the
same code. But this isn't going to be easy, because only the SNES knows
when its output is interlaced, and its resolutions can vary as
{256,512}x{224,240,448,480} which requires pixel doubling that was
hard-coded to the SNES-specific behavior, but isn't appropriate to be
exposed in higan/video.
2016-05-25 11:13:02 +00:00
|
|
|
uint count = 0;
|
2013-05-02 11:25:45 +00:00
|
|
|
do count += x & 1; while(x >>= 1);
|
|
|
|
return count;
|
|
|
|
}
|
2012-02-27 00:18:50 +00:00
|
|
|
|
2014-01-05 09:59:17 +00:00
|
|
|
//return index of the first bit set (or zero of no bits are set)
|
|
|
|
//first(0b1000) == 3
|
2016-08-09 11:07:18 +00:00
|
|
|
inline auto first(uintmax x) -> uint {
|
Update to v098r11 release.
byuu says:
Changelog:
- fixed nall/path.hpp compilation issue
- fixed ruby/audio/xaudio header declaration compilation issue (again)
- cleaned up xaudio2.hpp file to match my coding syntax (12.5% of the
file was whitespace overkill)
- added null terminator entry to nall/windows/utf8.hpp argc[] array
- nall/windows/guid.hpp uses the Windows API for generating the GUID
- this should stop all the bug reports where two nall users were
generating GUIDs at the exact same second
- fixed hiro/cocoa compilation issue with uint# types
- fixed major higan/sfc Super Game Boy audio latency issue
- fixed higan/sfc CPU core bug with pei, [dp], [dp]+y instructions
- major cleanups to higan/processor/r65816 core
- merged emulation/native-mode opcodes
- use camel-case naming on memory.hpp functions
- simplify address masking code for memory.hpp functions
- simplify a few opcodes themselves (avoid redundant copies, etc)
- rename regs.* to r.* to match modern convention of other CPU cores
- removed device.order<> concept from Emulator::Interface
- cores will now do the translation to make the job of the UI easier
- fixed plurality naming of arrays in Emulator::Interface
- example: emulator.ports[p].devices[d].inputs[i]
- example: vector<Medium> media
- probably more surprises
Major show-stoppers to the next official release:
- we need to work on GB core improvements: LY=153/0 case, multiple STAT
IRQs case, GBC audio output regs, etc.
- we need to re-add software cursors for light guns (Super Scope,
Justifier)
- after the above, we need to fix the turbo button for the Super Scope
I really have no idea how I want to implement the light guns. Ideally,
we'd want it in higan/video, so we can support the NES Zapper with the
same code. But this isn't going to be easy, because only the SNES knows
when its output is interlaced, and its resolutions can vary as
{256,512}x{224,240,448,480} which requires pixel doubling that was
hard-coded to the SNES-specific behavior, but isn't appropriate to be
exposed in higan/video.
2016-05-25 11:13:02 +00:00
|
|
|
uint first = 0;
|
2014-01-05 09:59:17 +00:00
|
|
|
while(x) { if(x & 1) break; x >>= 1; first++; }
|
|
|
|
return first;
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
//round up to next highest single bit:
|
|
|
|
//round(15) == 16, round(16) == 16, round(17) == 32
|
2016-08-09 11:07:18 +00:00
|
|
|
inline auto round(uintmax x) -> uintmax {
|
2013-05-02 11:25:45 +00:00
|
|
|
if((x & (x - 1)) == 0) return x;
|
|
|
|
while(x & (x - 1)) x &= x - 1;
|
|
|
|
return x << 1;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-02 11:25:45 +00:00
|
|
|
}
|