Skip to content

Commit

Permalink
256 colors -> 2 colors is already done in the wad file
Browse files Browse the repository at this point in the history
  • Loading branch information
FrenkelS committed Mar 14, 2024
1 parent 3fa5f74 commit da99714
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 53 deletions.
181 changes: 128 additions & 53 deletions i_vibm.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,54 +101,39 @@ void I_SetPalette(int8_t pal)
}


#if defined __WATCOMC__
#define P0 0x00
#define P1 0x10
#define P2 0x42
#define P3 0x25
#define P4 0x5a
#define P5 0xab
#define P6 0xdb
#define P7 0xef
#define P8 0xff
#else
#define P0 0b00000000
#define P1 0b00010000
#define P2 0b01000010
#define P3 0b00100101
#define P4 0b01011010
#define P5 0b10101011
#define P6 0b11011011
#define P7 0b11101111
#define P8 0b11111111
#endif

static const uint8_t VGA_TO_BW_LUT[256] =
#define B0 (0 << 0)
#define B1 (1 << 0)
#define B2 (3 << 0)

static const uint8_t VGA_TO_BW_LUT_0[256] =
{
P0, P0, P0, P3, P8, P1, P0, P0, P0, P2, P1, P0, P0, P2, P2, P1,
P7, P7, P7, P7, P6, P6, P6, P6, P5, P5, P5, P5, P4, P4, P4, P4,
P3, P3, P3, P2, P2, P2, P2, P1, P1, P1, P1, P1, P1, P0, P0, P0,
P8, P8, P8, P8, P8, P8, P7, P7, P7, P7, P7, P7, P6, P6, P6, P6,
P6, P5, P5, P5, P4, P4, P4, P4, P3, P3, P3, P2, P2, P1, P1, P1,
P8, P8, P8, P8, P8, P7, P7, P7, P7, P7, P6, P6, P6, P6, P6, P6,
P5, P5, P5, P4, P4, P4, P4, P3, P3, P3, P2, P2, P2, P1, P1, P1,
P7, P7, P7, P6, P6, P5, P5, P5, P4, P4, P3, P2, P2, P1, P1, P0,
P6, P6, P6, P6, P6, P5, P5, P5, P5, P4, P4, P4, P3, P3, P3, P3,
P5, P5, P4, P4, P3, P3, P2, P2, P5, P4, P4, P4, P3, P3, P2, P2,
P8, P7, P7, P6, P5, P4, P3, P2, P8, P8, P7, P7, P6, P6, P5, P4,
P3, P3, P3, P2, P2, P2, P2, P2, P1, P1, P1, P1, P1, P1, P0, P0,
P8, P7, P7, P6, P5, P4, P3, P2, P1, P1, P0, P0, P0, P0, P0, P0,
P8, P8, P8, P8, P7, P7, P6, P6, P6, P5, P5, P5, P5, P4, P4, P4,
P8, P8, P8, P8, P8, P8, P8, P8, P3, P3, P3, P2, P2, P2, P1, P1,
P0, P0, P0, P0, P0, P0, P0, P0, P7, P8, P7, P4, P3, P2, P1, P5
B0, B0, B0, B1, B2, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B1, B1, B1, B0, B0, B1, B1, B1, B1, B1, B1, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B2, B2, B2, B2, B2, B2, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0,
B0, B0, B0, B0, B0, B0, B0, B0, B2, B2, B2, B1, B1, B0, B0, B1
};

#undef B0
#undef B1
#undef B2

#define B0 (0 << 0)
#define B1 (1 << 0)
#define B1 (2 << 0)
#define B2 (3 << 0)

static const uint8_t VGA_TO_BW_LUT_0[256] =
static const uint8_t VGA_TO_BW_LUT_0b[256] =
{
B0, B0, B0, B1, B2, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1,
Expand Down Expand Up @@ -200,6 +185,34 @@ static const uint8_t VGA_TO_BW_LUT_1[256] =
#undef B1
#undef B2

#define B0 (0 << 2)
#define B1 (2 << 2)
#define B2 (3 << 2)

static const uint8_t VGA_TO_BW_LUT_1b[256] =
{
B0, B0, B0, B1, B2, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B1, B1, B1, B0, B0, B1, B1, B1, B1, B1, B1, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B2, B2, B2, B2, B2, B2, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0,
B0, B0, B0, B0, B0, B0, B0, B0, B2, B2, B2, B1, B1, B0, B0, B1
};

#undef B0
#undef B1
#undef B2

#define B0 (0 << 4)
#define B1 (1 << 4)
#define B2 (3 << 4)
Expand Down Expand Up @@ -228,6 +241,34 @@ static const uint8_t VGA_TO_BW_LUT_2[256] =
#undef B1
#undef B2

#define B0 (0 << 4)
#define B1 (2 << 4)
#define B2 (3 << 4)

static const uint8_t VGA_TO_BW_LUT_2b[256] =
{
B0, B0, B0, B1, B2, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B1, B1, B1, B0, B0, B1, B1, B1, B1, B1, B1, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B2, B2, B2, B2, B2, B2, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0,
B0, B0, B0, B0, B0, B0, B0, B0, B2, B2, B2, B1, B1, B0, B0, B1
};

#undef B0
#undef B1
#undef B2

#define B0 (0 << 6)
#define B1 (1 << 6)
#define B2 (3 << 6)
Expand All @@ -252,6 +293,39 @@ static const uint8_t VGA_TO_BW_LUT_3[256] =
B0, B0, B0, B0, B0, B0, B0, B0, B2, B2, B2, B1, B1, B0, B0, B1
};

#undef B0
#undef B1
#undef B2

#define B0 (0 << 6)
#define B1 (2 << 6)
#define B2 (3 << 6)

static const uint8_t VGA_TO_BW_LUT_3b[256] =
{
B0, B0, B0, B1, B2, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2, B2,
B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1, B1,
B1, B1, B1, B1, B1, B1, B0, B0, B1, B1, B1, B1, B1, B1, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B2, B2, B2, B2, B2, B2, B1, B1,
B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0, B0, B0, B0, B0,
B2, B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B1, B1, B1, B1,
B2, B2, B2, B2, B2, B2, B2, B2, B1, B1, B1, B0, B0, B0, B0, B0,
B0, B0, B0, B0, B0, B0, B0, B0, B2, B2, B2, B1, B1, B0, B0, B1
};

#undef B0
#undef B1
#undef B2


#define NO_PALETTE_CHANGE 100

static boolean refreshStatusBar;
Expand All @@ -270,18 +344,15 @@ void I_FinishUpdate(void)
uint8_t __far* dst = videomemory;

for (uint_fast8_t y = 0; y < (SCREENHEIGHT - ST_HEIGHT) / 2; y++) {
for (uint_fast8_t x = 0; x < VIEWWINDOWWIDTH; x++) {
*dst++ = VGA_TO_BW_LUT[*src++];
}
_fmemcpy(dst, src, VIEWWINDOWWIDTH);

dst += 0x2000 - VIEWWINDOWWIDTH;
dst += 0x2000;
src += VIEWWINDOWWIDTH;

for (uint_fast8_t x = 0; x < VIEWWINDOWWIDTH; x++) {
uint8_t b = VGA_TO_BW_LUT[*src++];
*dst++ = (b << 4 | b >> 4);
}
_fmemcpy(dst, src, VIEWWINDOWWIDTH);

dst -= 0x2000 - (PLANEWIDTH - VIEWWINDOWWIDTH);
dst -= 0x2000 - PLANEWIDTH;
src += VIEWWINDOWWIDTH;
}

// status bar
Expand All @@ -298,7 +369,7 @@ void I_FinishUpdate(void)
dst += 0x2000 - VIEWWINDOWWIDTH;

for (uint_fast8_t x = 0; x < VIEWWINDOWWIDTH; x++) {
*dst++ = VGA_TO_BW_LUT_3[*src++] | VGA_TO_BW_LUT_2[*src++] | VGA_TO_BW_LUT_1[*src++] | VGA_TO_BW_LUT_0[*src++];
*dst++ = VGA_TO_BW_LUT_3b[*src++] | VGA_TO_BW_LUT_2b[*src++] | VGA_TO_BW_LUT_1b[*src++] | VGA_TO_BW_LUT_0b[*src++];
}

dst -= 0x2000 - (PLANEWIDTH - VIEWWINDOWWIDTH);
Expand Down Expand Up @@ -352,14 +423,18 @@ void R_DrawColumnFlat(int16_t texture, const draw_column_vars_t *dcvars)
if (count <= 0)
return;

const uint8_t color = texture;
const uint8_t color1 = texture;
const uint8_t color2 = (color1 << 4 | color1 >> 4);
const uint8_t colort = color1 + color2;
uint8_t color = (dcvars->yl & 1) ? color1 : color2;

uint8_t __far* dest = _s_viewwindow + (dcvars->yl * VIEWWINDOWWIDTH) + dcvars->x;

while (count--)
{
*dest = color;
dest += VIEWWINDOWWIDTH;
color = colort - color;
}
}

Expand Down Expand Up @@ -449,7 +524,7 @@ void V_DrawPatchNotScaled(int16_t x, int16_t y, const patch_t __far* patch)

for (int16_t col = 0; col < width; col++, desttop++)
{
const column_t __far* column = (const column_t __far*)((const byte __far*)patch + patch->columnofs[col]);
const column_t __far* column = (const column_t __far*)((const byte __far*)patch + (uint16_t)patch->columnofs[col]);

// step through the posts in a column
while (column->topdelta != 0xff)
Expand Down
Binary file modified readme_imgs/doomtd3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit da99714

Please sign in to comment.