Skip to content

Commit

Permalink
fix bugs; add color support to rewinding; add 2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaklyy committed Nov 26, 2023
1 parent 2618c05 commit 9405dbf
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 50 deletions.
130 changes: 83 additions & 47 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// each span is followed by one set of 5/10/15 bits for each pixel representing color, depending on the color read bits

// global variables because im lazy
u32 filebuffer = 0;
u32 filebuffer = 0; // life would be so much easier if this were 64 bit but i cba to figure out why changing that keeps breaking
u32 pointer = 0;
u8 shift = 0;

Expand All @@ -28,7 +28,7 @@ u32 readData(u32 buffer, const u8 bytes)
{
for (int i = 0; i < bytes; i++)
{
if (pointer >= rastertest_data_size) return;
if (pointer >= rastertest_data_size) return buffer << 8;

buffer <<= 8;
buffer |= rastertest_data[pointer];
Expand All @@ -39,22 +39,37 @@ u32 readData(u32 buffer, const u8 bytes)

u32 writeBuffer(u32 buffer, const int value, const u8 bits)
{
*buffer <<= bits;
*buffer |= value;
buffer <<= bits;
buffer |= value;
shift += bits;

return buffer;
}

void writeFile(FILE* dat)
{
while (shift >= 8)
{
u8 tempbuffer = (filebuffer >> (shift-8)) & 0xFF;
u8 tempbuffer = ((filebuffer >> (shift-8)) & 0xFF);
fwrite(&tempbuffer, 1, 1, dat);
shift -= 8;
}
}

u8 getSpanPoint()
{
u8 ret = ((filebuffer >> (24-shift)) & 0xFF);
shift += 8;
return ret;
}

u16 getColor(const u8 bits, const u16 mask)
{
u8 ret = ((filebuffer >> ((32-bits)-shift)) & mask);
shift += bits;
return ret;
}

u16 waitForInput(u16* prevkeys)
{
while(1)
Expand Down Expand Up @@ -141,12 +156,32 @@ void rewindData(const int iteration)
filebuffer = readData(filebuffer, 1);
shift -=8;
}
if ((filebuffer & (1 << (31 - shift))) == 0)
shift++;
else if (!(Dataset[i].PolyAttr & Opaque))
shift += 33;
if ((filebuffer & (1 << (31 - shift))) == 0) shift++;
else if (Dataset[i].ColorMode == 0)
{
if (!(Dataset[i].PolyAttr & Opaque)) shift += 33;
else shift += 17;
}
else
shift += 17;
{
shift++;
u8 bits = Dataset[i].ColorMode * 5;
for (int k = 0; k <= (!(Dataset[i].PolyAttr & Opaque)); k++)
{
u8 start = getSpanPoint();
u8 end = getSpanPoint();
if (k == 1 && start == 0) break;
for (; start <= end; start++)
{
shift += bits;
while (shift >= 8)
{
filebuffer = readData(filebuffer, 1);
shift -=8;
}
}
}
}
}
}
}
Expand Down Expand Up @@ -196,20 +231,6 @@ void drawPoly(const int iteration)
//=TESTING================================================================================
//========================================================================================

u8 getSpanPoint()
{
u8 ret = ((filebuffer >> (24-shift)) & 0xFF);
shift += 8;
return ret;
}

u16 getColor(const u8 bits, const u16 mask)
{
u8 ret = ((filebuffer >> (32-bits-shift)) & mask);
shift += bits;
return ret;
}

bool test(const bool wireframe, const u8 colormode)
{
u16 mask;
Expand Down Expand Up @@ -254,7 +275,6 @@ bool test(const bool wireframe, const u8 colormode)
{
for (int i = 0; i < 2; i++)
{

filebuffer = readData(filebuffer, 1);
shift -=8;
}
Expand All @@ -264,32 +284,35 @@ bool test(const bool wireframe, const u8 colormode)
}

u16 offset = y * 256 + x;
u16 currcolor = VRAM_A[offset];
u16 currcolor = VRAM_A[offset] & 0x7FFF;
if (currcolor == ColorVoid)
{
if (!(x < startspan || x > endspan))
{
VRAM_A[offset] = ColorMissing;
VRAM_A[offset] = (VRAM_A[offset] & ~0x7FFF) | ColorMissing;
errorfound = true;
}
}
else if (x < startspan || x > endspan)
{
VRAM_A[offset] = ColorOverdraw;
VRAM_A[offset] = (VRAM_A[offset] & ~0x7FFF) | ColorOverdraw;
errorfound = true;
}
else
{
if (colormode)
if (colormode != 0)
{
if (bits > 8) filebuffer = readData(filebuffer, 2);
else filebuffer = readData(filebuffer, 1);
while (bits+shift > 32)
{
filebuffer = readData(filebuffer, 1);
shift -= 8;
}
u16 color = getColor(bits, mask);

color = getColor(bits, mask);
if ((currcolor & mask) != color) VRAM_A[offset] = ColorTextureER;
else ColorMatch;
if ((currcolor & mask) != color) VRAM_A[offset] = (VRAM_A[offset] & ~0x7FFF) | ColorTextureER;
else VRAM_A[offset] = (VRAM_A[offset] & ~0x7FFF) | ColorMatch;
}
else VRAM_A[offset] = ColorMatch;
else VRAM_A[offset] = (VRAM_A[offset] & ~0x7FFF) | ColorMatch;
}
}
}
Expand All @@ -303,7 +326,7 @@ bool test(const bool wireframe, const u8 colormode)
u16 currcolor = VRAM_A[offset] & 0x7FFF;
if (currcolor != ColorVoid)
{
VRAM_A[offset] = ColorOverdraw;
VRAM_A[offset] = (VRAM_A[offset] & ~0x7FFF) | ColorOverdraw;
errorfound = true;
}
}
Expand Down Expand Up @@ -340,16 +363,27 @@ void record(FILE* dat, const bool wireframe, const u8 colormode)
}

u16 colorbuffer[256];
for (int y = 0; y < 128; y++)
for (int y = 0; y < 192; y++)
{
s16 start;
s16 end;
for (int i = 0, x = 0;; i++)
int x = 0;
bool nospan = false;
for (int i = 0;; i++)
{
if (i != 0)
{
writeFile(dat);
if (start == -1) filebuffer = writeBuffer(filebuffer, 0, 1);
if (start == -1)
{
if (i == 1)
{
nospan = true;
filebuffer = writeBuffer(filebuffer, 0, 1);
}
else if (nospan == false) filebuffer = writeBuffer(filebuffer, 0, 16);
writeFile(dat);
}
else
{
if (end == -1)
Expand All @@ -358,9 +392,9 @@ void record(FILE* dat, const bool wireframe, const u8 colormode)
writeFile(dat);
}

if (colormode)
if (colormode != 0)
{
for (int j = start; j <= end; j++)
for (; start <= end; start++)
{
filebuffer = writeBuffer(filebuffer, colorbuffer[start], bits);
writeFile(dat);
Expand All @@ -376,27 +410,29 @@ void record(FILE* dat, const bool wireframe, const u8 colormode)
bool prevpixel = 0;
for (; x < 256; x++)
{
u16 color = VRAM_A[y*256+x];
u16 color = VRAM_A[y*256+x] & 0x7FFF;
if (color == ColorVoid)
if (prevpixel)
{
if (prevpixel != 0)
{
end = x-1;
filebuffer = writeBuffer(filebuffer, x-1, 8);
x++;
break;
}
}
else
{
if (!prevpixel)
if (prevpixel == 0)
{
if (!i) filebuffer = writeBuffer(filebuffer, 1, 1);
if (i == 0) filebuffer = writeBuffer(filebuffer, 1, 1);

start = x;
filebuffer = writeBuffer(filebuffer, x, 8);
prevpixel = 1;
}

if (colormode)
colorbuffer[x] = color & mask;
if (colormode != 0) colorbuffer[x] = color & mask;
}
}
}
Expand Down
15 changes: 12 additions & 3 deletions source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ constexpr u32 Wireframe = (0 << 16);
constexpr u16 ColorMissing = 0b000000000011111; // red
constexpr u16 ColorOverdraw = 0b111110000011111; // neon pink
constexpr u16 ColorMatch = 0b000001111100000; // green
constexpr u16 ColorTextureER= 0b011110011111111; // light pink (purple?)
constexpr u16 ColorTextureER= 0b111110000000000; // blue
constexpr u16 ColorVoid = 0b000000000000000; // black

// only increment if the actual tests change, (only do on releases?)
Expand All @@ -42,7 +42,7 @@ constexpr Dataset Dataset[] =
{{{-32, -32, 0}, {32, -32, 0}, {32, 16, 0}, {-512, -512, 0}},
Opaque | POLY_CULL_NONE,
0,
0},
1},
// Left Pos. Diagonal - fill
{{{-32, -32, 0}, {32, -32, 0}, {32, 32, 0}, {-512, -512, 0}},
Opaque | POLY_CULL_NONE,
Expand Down Expand Up @@ -153,7 +153,7 @@ constexpr Dataset Dataset[] =
{{{-32, -32, 0}, {32, -32, 0}, {32, 16, 0}, {-512, -512, 0}},
Wireframe | POLY_CULL_NONE,
0,
0},
1},
// Anti-Aliasing - Fill
{{{-32, -32, 0}, {32, -32, 0}, {32, 16, 0}, {-512, -512, 0}},
Opaque | POLY_CULL_NONE,
Expand Down Expand Up @@ -299,6 +299,10 @@ constexpr Dataset Dataset[] =
Trans | POLY_CULL_NONE,
GL_BLEND,
0},
{{{72, 45, 0}, {-63, 65}, {65, 65, 0}, {65, -63, 0}},
Trans | POLY_CULL_NONE,
GL_BLEND,
0},

// Category: Anti-Aliasing ===================================

Expand Down Expand Up @@ -385,6 +389,11 @@ constexpr Dataset Dataset[] =
Opaque | POLY_CULL_NONE,
0,
0},
// Evil square
{{{-32, -32, 0}, {-32, 33, 0}, {32, 32, 0}, {32, -32, 0}},
Opaque | POLY_CULL_NONE,
0,
0},
// pointer never goes backwards
{{{-30, -14, 0}, {20, 15, 0}, {52, 15, 0}, {-51, 10, 0}},
Opaque | POLY_CULL_NONE,
Expand Down

0 comments on commit 9405dbf

Please sign in to comment.