Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/waterbox/gpgx/core/ntsc/sms_ntsc.c
2 views
1
/* sms_ntsc 0.2.3. http://www.slack.net/~ant/ */
2
3
/* Modified for use with Genesis Plus GX -- EkeEke */
4
5
#include "shared.h"
6
#include "sms_ntsc.h"
7
8
/* Copyright (C) 2006-2007 Shay Green. This module is free software; you
9
can redistribute it and/or modify it under the terms of the GNU Lesser
10
General Public License as published by the Free Software Foundation; either
11
version 2.1 of the License, or (at your option) any later version. This
12
module is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
15
details. You should have received a copy of the GNU Lesser General Public
16
License along with this module; if not, write to the Free Software Foundation,
17
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
18
19
sms_ntsc_setup_t const sms_ntsc_monochrome = { 0,-1, 0, 0,.2, 0, .2,-.2,-.2,-1, 0, 0 };
20
sms_ntsc_setup_t const sms_ntsc_composite = { 0, 0, 0, 0, 0, 0,.25, 0, 0, 0, 0, 0 };
21
sms_ntsc_setup_t const sms_ntsc_svideo = { 0, 0, 0, 0, 0, 0,.25, -1, -1, 0, 0, 0 };
22
sms_ntsc_setup_t const sms_ntsc_rgb = { 0, 0, 0, 0,.2, 0,.70, -1, -1,-1, 0, 0 };
23
24
#define alignment_count 3
25
#define burst_count 1
26
#define rescale_in 8
27
#define rescale_out 7
28
29
#define artifacts_mid 0.4f
30
#define artifacts_max 1.2f
31
#define fringing_mid 0.8f
32
#define std_decoder_hue 0
33
34
#define gamma_size 16
35
36
#include "sms_ntsc_impl.h"
37
38
/* 3 input pixels -> 8 composite samples */
39
pixel_info_t const sms_ntsc_pixels [alignment_count] = {
40
{ PIXEL_OFFSET( -4, -9 ), { 1, 1, .6667f, 0 } },
41
{ PIXEL_OFFSET( -2, -7 ), { .3333f, 1, 1, .3333f } },
42
{ PIXEL_OFFSET( 0, -5 ), { 0, .6667f, 1, 1 } },
43
};
44
45
static void correct_errors( sms_ntsc_rgb_t color, sms_ntsc_rgb_t* out )
46
{
47
unsigned i;
48
for ( i = 0; i < rgb_kernel_size / 2; i++ )
49
{
50
sms_ntsc_rgb_t error = color -
51
out [i ] - out [(i+12)%14+14] - out [(i+10)%14+28] -
52
out [i + 7] - out [i + 5 +14] - out [i + 3 +28];
53
CORRECT_ERROR( i + 3 + 28 );
54
}
55
}
56
57
void sms_ntsc_init( sms_ntsc_t* ntsc, sms_ntsc_setup_t const* setup )
58
{
59
int entry;
60
init_t impl;
61
if ( !setup )
62
setup = &sms_ntsc_composite;
63
init( &impl, setup );
64
65
for ( entry = 0; entry < sms_ntsc_palette_size; entry++ )
66
{
67
float bb = impl.to_float [entry >> 8 & 0x0F];
68
float gg = impl.to_float [entry >> 4 & 0x0F];
69
float rr = impl.to_float [entry & 0x0F];
70
71
float y, i, q = RGB_TO_YIQ( rr, gg, bb, y, i );
72
73
int r, g, b = YIQ_TO_RGB( y, i, q, impl.to_rgb, int, r, g );
74
sms_ntsc_rgb_t rgb = PACK_RGB( r, g, b );
75
76
if ( setup->palette_out )
77
RGB_PALETTE_OUT( rgb, &setup->palette_out [entry * 3] );
78
79
if ( ntsc )
80
{
81
gen_kernel( &impl, y, i, q, ntsc->table [entry] );
82
correct_errors( rgb, ntsc->table [entry] );
83
}
84
}
85
}
86
87
#ifndef CUSTOM_BLITTER
88
void sms_ntsc_blit( sms_ntsc_t const* ntsc, SMS_NTSC_IN_T const* table, unsigned char* input,
89
int in_width, int vline)
90
{
91
int const chunk_count = in_width / sms_ntsc_in_chunk;
92
93
/* handle extra 0, 1, or 2 pixels by placing them at beginning of row */
94
int const in_extra = in_width - chunk_count * sms_ntsc_in_chunk;
95
unsigned const extra2 = (unsigned) -(in_extra >> 1 & 1); /* (unsigned) -1 = ~0 */
96
unsigned const extra1 = (unsigned) -(in_extra & 1) | extra2;
97
98
/* use palette entry 0 for unused pixels */
99
SMS_NTSC_IN_T border = table[0];
100
101
SMS_NTSC_BEGIN_ROW( ntsc, border,
102
(SMS_NTSC_ADJ_IN( table[input[0]] )) & extra2,
103
(SMS_NTSC_ADJ_IN( table[input[extra2 & 1]] )) & extra1 );
104
105
sms_ntsc_out_t* restrict line_out = (sms_ntsc_out_t*)(&bitmap.data[(vline * bitmap.pitch)]);
106
107
int n;
108
input += in_extra;
109
110
for ( n = chunk_count; n; --n )
111
{
112
/* order of input and output pixels must not be altered */
113
SMS_NTSC_COLOR_IN( 0, ntsc, SMS_NTSC_ADJ_IN( table[*input++] ) );
114
SMS_NTSC_RGB_OUT( 0, *line_out++ );
115
SMS_NTSC_RGB_OUT( 1, *line_out++ );
116
117
SMS_NTSC_COLOR_IN( 1, ntsc, SMS_NTSC_ADJ_IN( table[*input++] ) );
118
SMS_NTSC_RGB_OUT( 2, *line_out++ );
119
SMS_NTSC_RGB_OUT( 3, *line_out++ );
120
121
SMS_NTSC_COLOR_IN( 2, ntsc, SMS_NTSC_ADJ_IN( table[*input++] ) );
122
SMS_NTSC_RGB_OUT( 4, *line_out++ );
123
SMS_NTSC_RGB_OUT( 5, *line_out++ );
124
SMS_NTSC_RGB_OUT( 6, *line_out++ );
125
}
126
127
/* finish final pixels */
128
SMS_NTSC_COLOR_IN( 0, ntsc, border );
129
SMS_NTSC_RGB_OUT( 0, *line_out++ );
130
SMS_NTSC_RGB_OUT( 1, *line_out++ );
131
132
SMS_NTSC_COLOR_IN( 1, ntsc, border );
133
SMS_NTSC_RGB_OUT( 2, *line_out++ );
134
SMS_NTSC_RGB_OUT( 3, *line_out++ );
135
136
SMS_NTSC_COLOR_IN( 2, ntsc, border );
137
SMS_NTSC_RGB_OUT( 4, *line_out++ );
138
SMS_NTSC_RGB_OUT( 5, *line_out++ );
139
SMS_NTSC_RGB_OUT( 6, *line_out++ );
140
}
141
#endif
142
143