Skip to content

Commit

Permalink
Debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudMracek committed Nov 13, 2022
1 parent 4f66b90 commit 9dec35c
Show file tree
Hide file tree
Showing 12 changed files with 254 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
build/
.vscode/
LICENSE*.DAT
*.frag
*.vert
*.lua
pcsx.json
*.mcd
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,30 @@ cmake_minimum_required(VERSION 3.20)

project(
BWHorror
LANGUAGES C
LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "Bandwidth horror game"
HOMEPAGE_URL "https://www.youtube.com/channel/UCzp1RaZ3HmejKl723qlKOAw"
)

psn00bsdk_add_executable(horror STATIC src/main.c src/display.c)
file(GLOB TEXTURES textures/*.tim)


psn00bsdk_add_executable(horror STATIC
src/main.c
src/display.c
src/mesh.c
src/texture.c
)

psn00bsdk_target_incbin(horror PRIVATE bandwidth_face textures/bandwidth_face.tim)

foreach(TEXTURE ${TEXTURES})
get_filename_component(BARENAME ${TEXTURE} NAME)
string(REGEX REPLACE "\\.[^.]*$" "" TEXTURE_NAME ${BARENAME})
psn00bsdk_target_incbin(horror PRIVATE ${TEXTURE_NAME} ${TEXTURE})
endforeach()


psn00bsdk_add_cd_image(
iso # Target name
Expand Down
84 changes: 84 additions & 0 deletions meshes/cube.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <psxgte.h>
#include "../src/display.h"

int cube_num_faces = 6;

const SVECTOR cube_verts[] = {
{75,-75,75},
{75,-75,-75},
{75,75,75},
{75,75,-75},
{-75,-75,75},
{-75,-75,-75},
{-75,75,75},
{-75,75,-75}
};

const SVECTOR cube_norms[] = {
{0.0,-0.0,1.0},
{0.0,-1.0,0.0},
{-1.0,-0.0,0.0},
{0.0,-0.0,-1.0},
{1.0,-0.0,0.0},
{0.0,1.0,0.0}
};

const INDEX cube_vertex_indices[] = {
{0,4,2,6},
{3,2,7,6},
{7,6,5,4},
{5,1,7,3},
{1,0,3,2},
{5,4,1,0}
};

const INDEX cube_uv_indices[] = {
{0,1,3,2},
{4,5,6,2},
{7,8,10,9},
{11,12,6,13},
{14,15,17,16},
{11,1,19,18}
};

const int cube_normal_indices[] = {
2,
7,
5,
7,
3,
1};

const SVECTOR cube_uv[] = {
{0,0},
{127,0},
{127,127},
{0,127},
{0,0},
{127,0},
{0,127},
{0,0},
{127,0},
{127,127},
{0,127},
{0,0},
{127,0},
{127,127},
{0,0},
{127,0},
{127,127},
{0,127},
{127,127},
{0,127}
};

void fillMesh_cube(MESH* mesh) {
mesh->faces_num = cube_num_faces;

mesh->normal_data = &cube_norms;
mesh->normal_indices = &cube_normal_indices;
mesh->uv_data = &cube_uv;
mesh->uv_indices = &cube_uv_indices;
mesh->vertex_data = &cube_verts;
mesh->vertex_indices = &cube_vertex_indices;
}
75 changes: 75 additions & 0 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ int db_active = 0;
char *db_nextpri;
RECT screen_clip;

MATRIX omtx, mtx;

void (*callback)();

void initDisplay(void) {
Expand Down Expand Up @@ -78,4 +80,77 @@ void display(void) {

void setGameLoopCallback(void (*ptr)()) {
callback = ptr;
}

void sortObject(OBJECT *obj) {
int i, p;
QUAD *pol4;

RotMatrix(&obj->rot, &omtx);
TransMatrix(&omtx, &obj->pos);

CompMatrixLV(&mtx, &omtx, &omtx);

PushMatrix();

gte_SetRotMatrix(&omtx);
gte_SetTransMatrix(&omtx);

pol4 = (QUAD *)db_nextpri;
printf("test %d\n", obj->mesh->vertex_data[0].vx);
for (i = 0; i < obj->mesh->faces_num; i++) {
printf("test1\n");
gte_ldv3(&obj->mesh->vertex_data[obj->mesh->vertex_indices[i].v0],
&obj->mesh->vertex_data[obj->mesh->vertex_indices[i].v1],
&obj->mesh->vertex_data[obj->mesh->vertex_indices[i].v2]);
gte_rtpt();
gte_nclip();
gte_stopz(&p);

// Skip drawing this quad if the first 3 vertices are aligned (p = 0)
// or in counterclockwise (p < 0) order.
if (p <= 0)
continue;

gte_avsz3();
gte_stotz(&p);

// Skip drawing this face if it's too far from or too close to the
// camera and wouldn't fit in the OT.
if (((p >> 2) <= 0) || ((p >> 2) >= OT_LEN))
continue;

gte_stsxy0(&pol4->x0);
gte_stsxy1(&pol4->x1);
gte_stsxy2(&pol4->x2);
gte_ldv0(&obj->mesh->vertex_data[obj->mesh->vertex_indices[i].v3]);
gte_rtps();
gte_stsxy(&pol4->x3);

gte_ldrgb(&pol4->r0);
gte_ldv0(&obj->mesh->normal_data[obj->mesh->normal_indices[i]]);
gte_ncs();
gte_strgb(&pol4->r0);

pol4->tpage =
getTPage(obj->texture->tim->mode, 0, obj->texture->tim->prect->x, obj->texture->tim->prect->y);
setClut(pol4, obj->texture->tim->crect->x, obj->texture->tim->crect->y);
setUV4(pol4,
obj->mesh->uv_data[obj->mesh->uv_indices[i].v0].vx, obj->texture->texture_size-1-obj->mesh->uv_data[obj->mesh->uv_indices[i].v0].vy,
obj->mesh->uv_data[obj->mesh->uv_indices[i].v1].vx, obj->texture->texture_size-1-obj->mesh->uv_data[obj->mesh->uv_indices[i].v1].vy,
obj->mesh->uv_data[obj->mesh->uv_indices[i].v2].vx, obj->texture->texture_size-1-obj->mesh->uv_data[obj->mesh->uv_indices[i].v2].vy,
obj->mesh->uv_data[obj->mesh->uv_indices[i].v3].vx, obj->texture->texture_size-1-obj->mesh->uv_data[obj->mesh->uv_indices[i].v3].vy);
setRGB0( pol4, 255, 255, 255 );
gte_avsz4();
gte_stotz(&p);
addPrim(&(db[db_active].ot)[p >> 2], pol4);

pol4++;
//if (pol4 >= (db_nextpri + PACKET_LEN))
//break;
printf("test3");
}

db_nextpri = (char *)pol4;
PopMatrix();
}
30 changes: 29 additions & 1 deletion src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,35 @@

#include "options.h"

typedef struct {
short v0,v1,v2,v3;
} INDEX;

typedef struct {
TIM_IMAGE* tim;
int texture_size;
} TEXTURE;

typedef struct {
int faces_num;
SVECTOR *vertex_data;
SVECTOR *normal_data;
SVECTOR *uv_data;
INDEX *vertex_indices;
INDEX *uv_indices;
int *normal_indices;
} MESH;

typedef struct {
VECTOR pos;
SVECTOR rot;
MESH *mesh;
TEXTURE *texture;
} OBJECT;

void setGameLoopCallback(void (*ptr)());

void initDisplay(void);
void display(void);
void display(void);

void sortObject(OBJECT *obj);
21 changes: 20 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@
#include <psxgpu.h>

#include "display.h"
#include "texture.h"

#include "../meshes/cube.c"

extern const uint32_t bandwidth_face[];

int i = 0;

OBJECT cube;
VECTOR cubePos = {0, 0, 0};
SVECTOR cubeRot = {0, 0, 0};

void gameInit() {
loadTexture(bandwidth_face, &cube.texture);
fillMesh_cube(cube.mesh);
cube.pos = cubePos;
cube.rot = cubeRot;
}

void gameLoop() {
sortObject(&cube);
FntPrint(-1, "TEST %d", i);
i++;
if(i > 50) {
Expand All @@ -18,10 +35,12 @@ void gameLoop() {

int main(int argc, const char *argv[])
{
setGameLoopCallback(gameLoop);
initDisplay();
gameInit();
setGameLoopCallback(&gameLoop);

while(true) {

display();
}
}
Empty file added src/mesh.c
Empty file.
Empty file added src/mesh.h
Empty file.
6 changes: 5 additions & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ changing common variables like screen resolution */

#pragma once

#include <stdio.h>

#define LOAD_FONT

#define OT_LEN 4096
Expand All @@ -13,4 +15,6 @@ changing common variables like screen resolution */
#define SCREEN_YRES 240

#define CENTERX (SCREEN_XRES / 2)
#define CENTERY (SCREEN_YRES / 2)
#define CENTERY (SCREEN_YRES / 2)

typedef POLY_FT4 QUAD;
13 changes: 13 additions & 0 deletions src/texture.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "texture.h"

void loadTexture(uint32_t* textureData, TEXTURE* texture) {
GetTimInfo(textureData, texture->tim);

LoadImage(texture->tim->prect, texture->tim->paddr);
DrawSync(0);

if (texture->tim->mode & 8) {
LoadImage(texture->tim->crect, texture->tim->caddr);
DrawSync(0);
}
}
4 changes: 4 additions & 0 deletions src/texture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "display.h"

void loadTexture(uint32_t* textureData, TEXTURE* texture);

Binary file added textures/bandwidth_face.tim
Binary file not shown.

0 comments on commit 9dec35c

Please sign in to comment.