Skip to content

Commit

Permalink
Keep non-LUT generation; use #elif
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumball2415 committed Jan 18, 2023
1 parent ee6b0f4 commit b664e01
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions crt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ eqf(struct EQF *f, int s)
/* index : 0 1 2 3 4 5 6 */
/* weight: 1 4 7 8 7 4 1 */
return (s + h[6] + ((h[1] + h[5]) * 4) + ((h[2] + h[4]) * 7) + (h[3] * 8)) >> 5;
#elseif USE_6_SAMPLE
#elif USE_6_SAMPLE
/* index : 0 1 2 3 4 5 */
/* weight: 1 3 4 4 3 1 */
return (s + h[5] + 3 * (h[1] + h[4]) + 4 * (h[2] + h[3])) >> 4;
#elseif USE_5_SAMPLE
#elif USE_5_SAMPLE
/* index : 0 1 2 3 4 */
/* weight: 1 2 2 2 1 */
return (s + h[4] + ((h[1] + h[2] + h[3]) << 1)) >> 3;
Expand Down
49 changes: 48 additions & 1 deletion crt_nes.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#include <stdlib.h>
#include <string.h>

#define USE_LUT 0

#if USE_LUT
// Precalculate the low and high signal chosen for each 64 base colors
// with their respective attenuated values
// https://www.nesdev.org/wiki/NTSC_video#Brightness_Levels
const int8_t IRE_levels[2][2][0x40]{
const int IRE_levels[2][2][0x40]{
// waveform low
{
// normal
Expand Down Expand Up @@ -94,6 +97,50 @@ square_sample(int p, int phase)

return IRE_levels[v][e][p & 0x3F];
}
#else
/* generate the square wave for a given 9-bit pixel and phase */
static int
square_sample(int p, int phase)
{
static int active[6] = {
0300, 0100,
0500, 0400,
0600, 0200
};
int bri, hue, v;

hue = (p & 0x0f);

/* last two columns are black */
if (hue >= 0x0e) {
return 0;
}

bri = ((p & 0x30) >> 4) * 300;

switch (hue) {
case 0:
v = bri + 410;
break;
case 0x0d:
v = bri - 300;
break;
default:
v = (((hue + phase) % 12) < 6) ? (bri + 410) : (bri - 300);
break;
}

if (v > 1024) {
v = 1024;
}
/* red 0100, green 0200, blue 0400 */
if ((p & 0700) & active[(phase >> 1) % 6]) {
return (v >> 1) + (v >> 2);
}

return v;
}
#endif

#define NES_OPTIMIZED 0

Expand Down

0 comments on commit b664e01

Please sign in to comment.