commit 1865c6d720ef2c79549253e1c76108ab749c4c9c
parent 3d325d0ec55fbe4c90f1c3af682b57d87cec76f9
Author: root <root@lunarcry>
Date: Sat, 2 Nov 2024 20:02:00 +0000
- Add good debug logging
- Modified makefile to work on windows (probably)
Diffstat:
5 files changed, 53 insertions(+), 81 deletions(-)
diff --git a/makefile b/makefile
@@ -1,2 +1,5 @@
-build:
- cc -O3 -g src/*.c -o bin/ultimecia -I/usr/local/include -L/usr/local/lib -lSDL2
+bsd:
+ cc -O3 -g src/*.c -o bin/ultimecia -I/usr/local/include -L/usr/local/lib -lprofiler -lSDL2
+
+win:
+ cc -O3 -g src/*.c -o bin/ultimecia -I/mingw64/include/SDL2 -L/mingw64/lib -lmingw32 -lSDL2main -lSDL2
diff --git a/src/defs.h b/src/defs.h
@@ -1,7 +1,22 @@
#pragma once
+static const int debug = 0; // Set to 0 to disable debug prints
+
#define LOG_ERR(x) fprintf(stderr, (x))
/* #define PANIC(...) do { fprintf(stderr, __VA_ARGS__); exit(EXIT_FAILURE); } while(0) */
+/* We should get rid of this */
#define DEBUG 1;
+
+#define LOG_NONE 0
+#define LOG_DEBUG 1
+#define LOG_INFO 2
+#define LOG_WARN 3
+#define LOG_ERROR 4
+
+// Set the current log level
+#define CURRENT_LOG_LEVEL LOG_ERROR
+
+#define LOG(level, fmt, ...) \
+ do { if (level >= CURRENT_LOG_LEVEL) fprintf(stderr, fmt, __VA_ARGS__); } while (0)
diff --git a/src/gpu.c b/src/gpu.c
@@ -350,7 +350,7 @@ GPU_gp0_mask_bit_setting(GPU* gpu)
void
GPU_gp0_quad_mono_opaque(GPU* gpu)
{
- fprintf(stdout, "Draw quad pls\n");
+ LOG(LOG_DEBUG, "Draw quad pls\n", NULL);
}
void
@@ -369,19 +369,19 @@ GPU_gp0_triangle_shaded_opaque(GPU* gpu)
REN_push_triangle(gpu->ren, positions, colors);
- fprintf(stdout, "Draw triangle shaded\n");
+ LOG(LOG_DEBUG, "Draw triangle shaded\n", NULL);
}
void
GPU_gp0_quad_texture_blend_opaque(GPU* gpu)
{
- fprintf(stdout, "Draw quad texture blending\n");
+ LOG(LOG_DEBUG, "Draw quad texture blending\n", NULL);
}
void
GPU_gp0_quad_shaded_opaque(GPU* gpu)
{
- fprintf(stdout, "Draw quad shaded\n");
+ LOG(LOG_DEBUG, "Draw quad shaded\n", NULL);
}
void
diff --git a/src/interconnect.c b/src/interconnect.c
@@ -153,7 +153,8 @@ INTER_load32(Interconnect* inter, u32 addr)
contains = UTIL_contains(GPU_START, GPU_SIZE, abs_addr, &offset);
if (contains)
{
- printf("GPU read %08X\n", abs_addr);
+
+ LOG(LOG_DEBUG, "GPU read %08X\n", abs_addr);
switch(offset)
{
@@ -323,12 +324,12 @@ INTER_store32(Interconnect* inter, u32 addr, u32 val)
contains = UTIL_contains(GPU_START, GPU_SIZE, abs_addr, &offset);
if (contains)
{
- fprintf(stdout, "GPU write %08X to address %08X\n", val, offset);
- switch (offset) {
- case 0: GPU_gp0(inter->gpu, val); break;
- case 4: GPU_gp1(inter->gpu, val); break;
- default: fprintf(stderr, "GPU write %08X: %08X", offset, val); exit(EXIT_FAILURE);
- }
+ LOG(LOG_DEBUG, "GPU write %08X to address %08X\n", val, offset);
+ switch (offset) {
+ case 0: GPU_gp0(inter->gpu, val); break;
+ case 4: GPU_gp1(inter->gpu, val); break;
+ default: fprintf(stderr, "GPU write %08X: %08X", offset, val); exit(EXIT_FAILURE);
+ }
return;
}
diff --git a/src/sr.c b/src/sr.c
@@ -9,6 +9,7 @@
#include "types.h"
#include "sr.h"
+#include "defs.h"
ivec2
@@ -206,84 +207,36 @@ REN_triangle(REN* ren, ivec2 verts[3], C colors[3]) {
}
}
-//void
-//REN_triangle(REN* ren, ivec2 verts[3], C colors[3]) {
-// // SORT the vertices, t0, t1, t2 lower−to−upper (bubblesort yay!)
-// ivec2 temp, t0, t1, t2;
-// i32 first_half, second_half;
-// t0 = verts[0]; t1 = verts[1]; t2 = verts[2];
-//
-// if (t0.y>t1.y) VEC2I_SWAP(t0, t1);
-// if (t0.y>t2.y) VEC2I_SWAP(t0, t2);
-// if (t1.y>t2.y) VEC2I_SWAP(t1, t2);
-//
-// i32 total_height = t2.y - t0.y;
-// i32 height_first_half = t1.y - t0.y;
-// i32 height_second_half = t2.y - t1.y;
-// float alpha_step = 1.0f / total_height;
-// float alpha = 0.0f;
-//
-// for (i32 i = 0; i < total_height; i++, alpha += alpha_step) {
-// i32 second_half = (i > height_first_half) || (t1.y == t0.y);
-// i32 segment_height = second_half ? height_second_half : height_first_half;
-// float beta = (float)(i - (second_half ? height_first_half : 0)) / segment_height;
-//
-// ivec2 A = {
-// t0.x + (t2.x - t0.x) * alpha,
-// t0.y + i
-// };
-//
-// ivec2 B = second_half
-// ? (ivec2){ t1.x + (t2.x - t1.x) * beta, t1.y + (i - height_first_half) }
-// : (ivec2){ t0.x + (t1.x - t0.x) * beta, t0.y + i };
-//
-// if (A.x > B.x) VEC2I_SWAP(A, B);
-//
-// i32 row_buffer[W*4];
-// i32 row_index = 0;
-// for (i32 x = A.x; x <= B.x; x++) {
-// row_buffer[row_index++] = x;
-// }
-//
-// for (i32 j = 0; j < row_index; j++) {
-// REN_FB_set(ren, row_buffer[j], A.y, colors[j%3]);
-// }
-// }
-//
-//}
-
void
REN_push_triangle(REN* ren, ivec2 verts[3], C colors[3])
{
- u8 i;
- ivec2 tmp[3];
-
- if (ren->nvertices + 3 > 10) {
- printf("Vertex attribute buffer full, forcing draw... and NVERTICES IS %d\n", ren->nvertices);
- for(int i = 0; i < ren->nvertices-3; i+=3) {
- REN_triangle(ren, ren->verts+i, ren->colors+1);
- printf("Drawing... %d\n", i/3);
- }
- ren->nvertices=0;
- }
+ u8 i;
+ ivec2 tmp[3];
+
+ if (ren->nvertices + 3 > 10) {
+ LOG(LOG_DEBUG, "Vertex attribute buffer full, forcing draw... and NVERTICES IS %d\n", ren->nvertices);
+ for(int i = 0; i < ren->nvertices-3; i+=3)
+ REN_triangle(ren, ren->verts+i, ren->colors+1);
+ ren->nvertices=0;
+ }
- ren->verts = realloc(ren->verts, sizeof(ivec2) * (ren->nvertices + 3));
- ren->colors = realloc(ren->colors, sizeof(C) * (ren->nvertices + 3));
+ ren->verts = realloc(ren->verts, sizeof(ivec2) * (ren->nvertices + 3));
+ ren->colors = realloc(ren->colors, sizeof(C) * (ren->nvertices + 3));
- for (i = 0; i < 3; i++) {
- ren->verts[ren->nvertices] = verts[i];
- ren->colors[ren->nvertices] = colors[i];
- ren->nvertices++;
- }
+ for (i = 0; i < 3; i++) {
+ ren->verts[ren->nvertices] = verts[i];
+ ren->colors[ren->nvertices] = colors[i];
+ ren->nvertices++;
+ }
}
void
REN_draw(REN* ren)
{
- SDL_SetRenderDrawColor(ren->renderer, 0x33, 0x33, 0x33, 0xff);
- SDL_RenderClear(ren->renderer);
- SDL_UpdateTexture(ren->tex, NULL, ren->fb, W * sizeof(u32));
- SDL_RenderCopy(ren->renderer, ren->tex, NULL, NULL);
+ SDL_SetRenderDrawColor(ren->renderer, 0x33, 0x33, 0x33, 0xff);
+ SDL_RenderClear(ren->renderer);
+ SDL_UpdateTexture(ren->tex, NULL, ren->fb, W * sizeof(u32));
+ SDL_RenderCopy(ren->renderer, ren->tex, NULL, NULL);
}
void