mirror of https://github.com/stella-emu/stella.git
Started cleaning up Blargg code:
- Converted some stuff to C++ - PAL colour-loss now works with Blargg enabled, but not yet for phosphor mode
This commit is contained in:
parent
a7b3ee4448
commit
4a2e4b666c
|
@ -39,6 +39,7 @@ void NTSCFilter::setTIAPalette(const TIASurface& tiaSurface, const uInt32* palet
|
|||
// the Blargg code assumes 128 colours
|
||||
uInt8* ptr = myTIAPalette;
|
||||
|
||||
#if 0
|
||||
// Set palette for phosphor effect
|
||||
for(int i = 0; i < 256; i+=2)
|
||||
{
|
||||
|
@ -56,8 +57,9 @@ void NTSCFilter::setTIAPalette(const TIASurface& tiaSurface, const uInt32* palet
|
|||
*ptr++ = tiaSurface.getPhosphor(bi, bj);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// Set palette for normal fill
|
||||
for(int i = 0; i < 256; i+=2)
|
||||
for(int i = 0; i < 256; ++i)
|
||||
{
|
||||
*ptr++ = (palette[i] >> 16) & 0xff;
|
||||
*ptr++ = (palette[i] >> 8) & 0xff;
|
||||
|
|
|
@ -109,16 +109,16 @@ class NTSCFilter
|
|||
// In the current implementation, the source pitch is always the
|
||||
// same as the actual width
|
||||
inline void blit_single(uInt8* src_buf, int src_width, int src_height,
|
||||
uInt32* dest_buf, long dest_pitch)
|
||||
uInt32* dest_buf, int dest_pitch)
|
||||
{
|
||||
atari_ntsc_blit_single(&myFilter, src_buf, src_width, src_width, src_height,
|
||||
atari_ntsc_blit_single(&myFilter, src_buf, src_width, src_height,
|
||||
dest_buf, dest_pitch);
|
||||
}
|
||||
inline void blit_double(uInt8* src_buf, uInt8* src_back_buf,
|
||||
int src_width, int src_height,
|
||||
uInt32* dest_buf, long dest_pitch)
|
||||
uInt32* dest_buf, int dest_pitch)
|
||||
{
|
||||
atari_ntsc_blit_double(&myFilter, src_buf, src_back_buf, src_width, src_width,
|
||||
atari_ntsc_blit_double(&myFilter, src_buf, src_back_buf, src_width,
|
||||
src_height, dest_buf, dest_pitch);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,10 +54,10 @@ pixel_info_t const atari_ntsc_pixels [alignment_count] = {
|
|||
{ PIXEL_OFFSET( 0, -5 ), { 1, 1, 1, 1 } },
|
||||
};
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
static void correct_errors( atari_ntsc_rgb_t color, atari_ntsc_rgb_t* out )
|
||||
{
|
||||
unsigned i;
|
||||
for ( i = 0; i < rgb_kernel_size / 2; i++ )
|
||||
for ( uInt32 i = 0; i < rgb_kernel_size / 2; i++ )
|
||||
{
|
||||
atari_ntsc_rgb_t error = color -
|
||||
out [i ] - out [(i+10)%14+14] -
|
||||
|
@ -66,17 +66,17 @@ static void correct_errors( atari_ntsc_rgb_t color, atari_ntsc_rgb_t* out )
|
|||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void atari_ntsc_init( atari_ntsc_t* ntsc, atari_ntsc_setup_t const* setup,
|
||||
atari_ntsc_in_t const* palette )
|
||||
{
|
||||
int entry;
|
||||
init_t impl;
|
||||
if ( !setup )
|
||||
setup = &atari_ntsc_composite;
|
||||
init( &impl, setup );
|
||||
|
||||
// Palette stores R/G/B data for 'atari_ntsc_palette_size' entries
|
||||
for ( entry = 0; entry < atari_ntsc_palette_size; entry++ )
|
||||
for ( uInt32 entry = 0; entry < atari_ntsc_palette_size; ++entry )
|
||||
{
|
||||
float r = impl.to_float [*palette++];
|
||||
float g = impl.to_float [*palette++];
|
||||
|
@ -97,32 +97,29 @@ void atari_ntsc_init( atari_ntsc_t* ntsc, atari_ntsc_setup_t const* setup,
|
|||
}
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
void atari_ntsc_blit_single( atari_ntsc_t const* ntsc,
|
||||
atari_ntsc_in_t const* atari_in,
|
||||
long in_row_width, int in_width, int in_height,
|
||||
void* rgb_out, long out_pitch )
|
||||
atari_ntsc_in_t const* atari_in, uInt32 in_width, uInt32 in_height,
|
||||
void* rgb_out, uInt32 out_pitch )
|
||||
{
|
||||
#define TO_SINGLE(pixel) ((1<<14)+(pixel>>1))
|
||||
|
||||
int const chunk_count = (in_width - 1) / atari_ntsc_in_chunk;
|
||||
uInt32 const chunk_count = (in_width - 1) / atari_ntsc_in_chunk;
|
||||
while ( in_height-- )
|
||||
{
|
||||
atari_ntsc_in_t const* line_in = atari_in;
|
||||
ATARI_NTSC_BEGIN_ROW( ntsc, TO_SINGLE(atari_ntsc_black), TO_SINGLE(line_in[0]) );
|
||||
ATARI_NTSC_BEGIN_ROW( ntsc, atari_ntsc_black, line_in[0] );
|
||||
atari_ntsc_out_t* restrict line_out = static_cast<atari_ntsc_out_t*>(rgb_out);
|
||||
int n;
|
||||
++line_in;
|
||||
|
||||
for ( n = chunk_count; n; --n )
|
||||
for ( uInt32 n = chunk_count; n; --n )
|
||||
{
|
||||
/* order of input and output pixels must not be altered */
|
||||
ATARI_NTSC_COLOR_IN( 0, ntsc, TO_SINGLE(line_in[0]) );
|
||||
ATARI_NTSC_COLOR_IN( 0, ntsc, line_in[0] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 0, line_out[0] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 1, line_out[1] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 2, line_out[2] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 3, line_out[3] );
|
||||
|
||||
ATARI_NTSC_COLOR_IN( 1, ntsc, TO_SINGLE(line_in[1]) );
|
||||
ATARI_NTSC_COLOR_IN( 1, ntsc, line_in[1] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 4, line_out[4] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 5, line_out[5] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 6, line_out[6] );
|
||||
|
@ -132,30 +129,29 @@ void atari_ntsc_blit_single( atari_ntsc_t const* ntsc,
|
|||
}
|
||||
|
||||
/* finish final pixels */
|
||||
ATARI_NTSC_COLOR_IN( 0, ntsc, TO_SINGLE(atari_ntsc_black) );
|
||||
ATARI_NTSC_COLOR_IN( 0, ntsc, atari_ntsc_black );
|
||||
ATARI_NTSC_RGB_OUT_8888( 0, line_out[0] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 1, line_out[1] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 2, line_out[2] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 3, line_out[3] );
|
||||
|
||||
ATARI_NTSC_COLOR_IN( 1, ntsc, TO_SINGLE(atari_ntsc_black) );
|
||||
ATARI_NTSC_COLOR_IN( 1, ntsc, atari_ntsc_black );
|
||||
ATARI_NTSC_RGB_OUT_8888( 4, line_out[4] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 5, line_out[5] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 6, line_out[6] );
|
||||
|
||||
atari_in += in_row_width;
|
||||
atari_in += in_width;
|
||||
rgb_out = static_cast<char*>(rgb_out) + out_pitch;
|
||||
}
|
||||
}
|
||||
|
||||
void atari_ntsc_blit_double( atari_ntsc_t const* ntsc,
|
||||
atari_ntsc_in_t const* atari_in1, atari_ntsc_in_t const* atari_in2,
|
||||
long in_row_width, int in_width, int in_height,
|
||||
void* rgb_out, long out_pitch )
|
||||
uInt32 in_width, uInt32 in_height, void* rgb_out, uInt32 out_pitch )
|
||||
{
|
||||
#define TO_DOUBLE(pixel1, pixel2) (((pixel1>>1)<<7)+(pixel2>>1))
|
||||
|
||||
int const chunk_count = (in_width - 1) / atari_ntsc_in_chunk;
|
||||
uInt32 const chunk_count = (in_width - 1) / atari_ntsc_in_chunk;
|
||||
while ( in_height-- )
|
||||
{
|
||||
atari_ntsc_in_t const* line_in1 = atari_in1;
|
||||
|
@ -164,11 +160,10 @@ void atari_ntsc_blit_double( atari_ntsc_t const* ntsc,
|
|||
TO_DOUBLE(atari_ntsc_black, atari_ntsc_black),
|
||||
TO_DOUBLE(line_in1[0], line_in2[0]) );
|
||||
atari_ntsc_out_t* restrict line_out = static_cast<atari_ntsc_out_t*>(rgb_out);
|
||||
int n;
|
||||
++line_in1;
|
||||
++line_in2;
|
||||
|
||||
for ( n = chunk_count; n; --n )
|
||||
for ( uInt32 n = chunk_count; n; --n )
|
||||
{
|
||||
/* order of input and output pixels must not be altered */
|
||||
ATARI_NTSC_COLOR_IN( 0, ntsc,
|
||||
|
@ -203,8 +198,8 @@ void atari_ntsc_blit_double( atari_ntsc_t const* ntsc,
|
|||
ATARI_NTSC_RGB_OUT_8888( 5, line_out[5] );
|
||||
ATARI_NTSC_RGB_OUT_8888( 6, line_out[6] );
|
||||
|
||||
atari_in1 += in_row_width;
|
||||
atari_in2 += in_row_width;
|
||||
atari_in1 += in_width;
|
||||
atari_in2 += in_width;
|
||||
rgb_out = static_cast<char*>(rgb_out) + out_pitch;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,8 +20,10 @@
|
|||
#ifndef ATARI_NTSC_H
|
||||
#define ATARI_NTSC_H
|
||||
|
||||
typedef unsigned char atari_ntsc_in_t;
|
||||
typedef unsigned int atari_ntsc_out_t;
|
||||
#include "bspf.hxx"
|
||||
|
||||
using atari_ntsc_in_t = uInt8;
|
||||
using atari_ntsc_out_t = uInt32;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -29,7 +31,7 @@ typedef unsigned int atari_ntsc_out_t;
|
|||
|
||||
/* Image parameters, ranging from -1.0 to 1.0. Actual internal values shown
|
||||
in parenthesis and should remain fairly stable in future versions. */
|
||||
typedef struct atari_ntsc_setup_t
|
||||
struct atari_ntsc_setup_t
|
||||
{
|
||||
/* Basic parameters */
|
||||
double hue; /* -1 = -180 degrees +1 = +180 degrees */
|
||||
|
@ -45,7 +47,7 @@ typedef struct atari_ntsc_setup_t
|
|||
double fringing; /* color artifacts caused by brightness changes */
|
||||
double bleed; /* color bleed (color resolution reduction) */
|
||||
float const* decoder_matrix; /* optional RGB decoder matrix, 6 elements */
|
||||
} atari_ntsc_setup_t;
|
||||
};
|
||||
|
||||
/* Video format presets */
|
||||
extern atari_ntsc_setup_t const atari_ntsc_composite; /* color bleeding + artifacts */
|
||||
|
@ -53,7 +55,7 @@ extern atari_ntsc_setup_t const atari_ntsc_svideo; /* color bleeding only */
|
|||
extern atari_ntsc_setup_t const atari_ntsc_rgb; /* crisp image */
|
||||
extern atari_ntsc_setup_t const atari_ntsc_bad; /* badly adjusted TV */
|
||||
|
||||
enum { atari_ntsc_palette_size = 129 * 128 };
|
||||
enum { atari_ntsc_palette_size = 256 };
|
||||
|
||||
/* Initializes and adjusts parameters. Can be called multiple times on the same
|
||||
atari_ntsc_t object. Can pass NULL for either parameter. */
|
||||
|
@ -65,13 +67,11 @@ void atari_ntsc_init( atari_ntsc_t* ntsc, atari_ntsc_setup_t const* setup,
|
|||
In_row_width is the number of pixels to get to the next input row. Out_pitch
|
||||
is the number of *bytes* to get to the next output row. */
|
||||
void atari_ntsc_blit_single( atari_ntsc_t const* ntsc,
|
||||
atari_ntsc_in_t const* atari_in,
|
||||
long in_row_width, int in_width, int in_height,
|
||||
void* rgb_out, long out_pitch );
|
||||
atari_ntsc_in_t const* atari_in, uInt32 in_width, uInt32 in_height,
|
||||
void* rgb_out, uInt32 out_pitch );
|
||||
void atari_ntsc_blit_double( atari_ntsc_t const* ntsc,
|
||||
atari_ntsc_in_t const* atari_in1, atari_ntsc_in_t const* atari_in2,
|
||||
long in_row_width, int in_width, int in_height,
|
||||
void* rgb_out, long out_pitch );
|
||||
uInt32 in_width, uInt32 in_height, void* rgb_out, uInt32 out_pitch );
|
||||
|
||||
/* Number of output pixels written by blitter for given input width. Width might
|
||||
be rounded down slightly; use ATARI_NTSC_IN_WIDTH() on result to find rounded
|
||||
|
@ -116,7 +116,7 @@ enum { atari_ntsc_black = 0 }; /* palette index for black */
|
|||
|
||||
/* private */
|
||||
enum { atari_ntsc_entry_size = 2 * 14 };
|
||||
typedef unsigned long atari_ntsc_rgb_t;
|
||||
using atari_ntsc_rgb_t = uInt32;
|
||||
struct atari_ntsc_t {
|
||||
atari_ntsc_rgb_t table [atari_ntsc_palette_size] [atari_ntsc_entry_size];
|
||||
};
|
||||
|
@ -133,7 +133,7 @@ struct atari_ntsc_t {
|
|||
atari_ntsc_rgb_t const* kernelx1 = kernel0
|
||||
|
||||
/* common ntsc macros */
|
||||
#define atari_ntsc_rgb_builder ((1L << 21) | (1 << 11) | (1 << 1))
|
||||
#define atari_ntsc_rgb_builder ((1 << 21) | (1 << 11) | (1 << 1))
|
||||
#define atari_ntsc_clamp_mask (atari_ntsc_rgb_builder * 3 / 2)
|
||||
#define atari_ntsc_clamp_add (atari_ntsc_rgb_builder * 0x101)
|
||||
#define ATARI_NTSC_CLAMP_( io, shift ) {\
|
||||
|
|
Loading…
Reference in New Issue