Skip to content

Commit 382d1b2

Browse files
PS1: Implement 2D coloured polygons, support wider textures, change placeholder texture to grey
1 parent 8b51e47 commit 382d1b2

File tree

6 files changed

+64
-43
lines changed

6 files changed

+64
-43
lines changed

misc/wiiu/ps_textured_exp.psh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@
2525
; -------- Disassembly --------------------
2626
00 TEX: ADDR(48) CNT(1) VALID_PIX
2727
0 SAMPLE R2, R2.xy0x, t0, s0
28-
01 ALU: ADDR(32) CNT(4)
29-
1 x: MUL ____, R1.y, R2.y
30-
y: MUL ____, R1.x, R2.x
31-
z: MUL ____, R1.z, R2.z
32-
w: MUL R2.w, R1.w, R2.w
33-
t: RCP_sat ____, R0.w
34-
2 x: ADD R1.x, PV1.x, -C0.y
35-
y: ADD R1.y, PV1.y, -C0.x
36-
w: ADD R0.w, PV1.z, -C0.z
37-
t: RCP_e ____, PS1
38-
3 w: MUL ____, PS2, C1.x
39-
4 t: EXP_e ____, PV3.w CLAMP
40-
5 x: MULADD R2.x, R1.y, PS4, C0.x
41-
y: MULADD R2.y, R1.x, PS4, C0.y
42-
z: MULADD R2.z, R0.w, PS4, C0.z
28+
01 ALU: ADDR(32) CNT(14)
29+
1 x: MUL ____, R1.y, R2.y
30+
y: MUL ____, R1.x, R2.x
31+
z: MUL ____, R1.z, R2.z
32+
w: MUL R2.w, R1.w, R2.w
33+
t: RECIP_CLAMPED ____, R0.w
34+
2 x: ADD R1.x, PV1.x, -C0.y
35+
y: ADD R1.y, PV1.y, -C0.x
36+
w: ADD R0.w, PV1.z, -C0.z
37+
t: RCP_e ____, PS1
38+
3 w: MUL ____, PS2, C1.x
39+
4 t: EXP_e ____, PV3.w CLAMP
40+
5 x: MULADD R2.x, R1.y, PS4, C0.x
41+
y: MULADD R2.y, R1.x, PS4, C0.y
42+
z: MULADD R2.z, R0.w, PS4, C0.z
4343
02 EXP_DONE: PIX0, R2
4444
END_OF_PROGRAM

misc/wiiu/ps_textured_lin.psh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@
2525
; -------- Disassembly --------------------
2626
00 TEX: ADDR(48) CNT(1) VALID_PIX
2727
0 SAMPLE R2, R2.xy0x, t0, s0
28-
01 ALU: ADDR(32) CNT(4)
29-
1 x: MUL ____, R1.x, R2.x
30-
y: MUL ____, R1.z, R2.z
31-
z: MUL ____, R1.y, R2.y
32-
w: MUL R2.w, R1.w, R2.w
33-
t: RCP_sat ____, R0.w
34-
2 x: ADD R1.x, PV1.z, -C0.y
35-
y: ADD R1.y, PV1.x, -C0.x
36-
w: ADD R0.w, PV1.y, -C0.z
37-
t: RCP_e ____, PS1
38-
3 z: MULADD R127.z, -PS2, C1.y, 1.0f CLAMP
39-
4 x: MULADD R2.x, R1.y, PV3.z, C0.x
40-
y: MULADD R2.y, R1.x, PV3.z, C0.y
41-
z: MULADD R2.z, R0.w, PV3.z, C0.z
28+
01 ALU: ADDR(32) CNT(14)
29+
1 x: MUL ____, R1.x, R2.x
30+
y: MUL ____, R1.z, R2.z
31+
z: MUL ____, R1.y, R2.y
32+
w: MUL R2.w, R1.w, R2.w
33+
t: RECIP_CLAMPED ____, R0.w
34+
2 x: ADD R1.x, PV1.z, -C0.y
35+
y: ADD R1.y, PV1.x, -C0.x
36+
w: ADD R0.w, PV1.y, -C0.z
37+
t: RECIP_IEEE ____, PS1
38+
3 z: MULADD R127.z, -PS2, C1.y, 1.0f CLAMP
39+
4 x: MULADD R2.x, R1.y, PV3.z, C0.x
40+
y: MULADD R2.y, R1.x, PV3.z, C0.y
41+
z: MULADD R2.z, R0.w, PV3.z, C0.z
4242
02 EXP_DONE: PIX0, R2
4343
END_OF_PROGRAM
4444

misc/wiiu/textured_exp.gsh

0 Bytes
Binary file not shown.

misc/wiiu/textured_lin.gsh

0 Bytes
Binary file not shown.

src/Graphics_PS1.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ static cc_bool cullingEnabled;
158158
void Gfx_RestoreState(void) {
159159
InitDefaultResources();
160160

161-
// 2x2 dummy white texture
161+
// dummy texture (grey works better in menus than white)
162162
struct Bitmap bmp;
163-
BitmapCol pixels[4] = { BitmapColor_RGB(255, 0, 0), BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE };
163+
BitmapCol pixels[4] = { BitmapColor_RGB(130, 130, 130), BitmapColor_RGB(130, 130, 130), BitmapColor_RGB(130, 130, 130), BitmapColor_RGB(130, 130, 130) };
164164
Bitmap_Init(bmp, 2, 2, pixels);
165165
white_square = Gfx_CreateTexture(&bmp, 0, false);
166166
}
@@ -171,7 +171,7 @@ void Gfx_FreeState(void) {
171171
}
172172

173173
void Gfx_Create(void) {
174-
Gfx.MaxTexWidth = 128;
174+
Gfx.MaxTexWidth = 256;
175175
Gfx.MaxTexHeight = 256;
176176
Gfx.Created = true;
177177
Gfx.Limitations = GFX_LIMIT_MAX_VERTEX_SIZE;
@@ -338,7 +338,7 @@ typedef struct GPUTexture {
338338
cc_uint16 width, height;
339339
cc_uint8 u_shift, v_shift;
340340
cc_uint8 xOffset, yOffset;
341-
cc_uint16 tpage, line;
341+
cc_uint16 tpage, clut, line;
342342
} GPUTexture;
343343
static GPUTexture textures[TEXTURES_MAX_COUNT];
344344
static GPUTexture* curTex;
@@ -370,6 +370,7 @@ static void* AllocTextureAt(int i, struct Bitmap* bmp, int rowWidth) {
370370
int pageX = (page % TPAGES_PER_HALF);
371371
int pageY = (page / TPAGES_PER_HALF);
372372
tex->tpage = (2 << 7) | (pageY << 4) | pageX;
373+
tex->clut = 0;
373374

374375
VRAM_AllocBlock(line, bmp->width, bmp->height);
375376
if (bmp->height > bmp->width) {
@@ -539,8 +540,8 @@ static void PreprocessTexturedVertices(void) {
539540
dst->xx = x >> 8;
540541
dst->yy = y >> 8;
541542

542-
u = src->U * 0.99f;
543-
v = src->V == 1.0f ? 0.99f : src->V;
543+
u = src->U * 0.999f;
544+
v = src->V == 1.0f ? 0.999f : src->V;
544545

545546
dst->u = UVFixed(u);
546547
dst->v = UVFixed(v);
@@ -733,14 +734,13 @@ static void DrawColouredQuads2D(int verticesCount, int startVertex) {
733734
struct PS1VertexColoured* v = (struct PS1VertexColoured*)gfx_vertices + startVertex;
734735
struct PSX_POLY_F4* poly = next_packet;
735736
cc_uint8* max = next_packet_end - sizeof(*poly);
736-
return;
737737

738738
for (int i = 0; i < verticesCount; i += 4, v += 4)
739739
{
740740
if ((cc_uint8*)poly > max) break;
741741

742742
setlen(poly, POLY_LEN_F4);
743-
poly->rgbc = v->rgbc;
743+
poly->rgbc = v->rgbc | POLY_CMD_SEMITRNS;
744744

745745
poly->x0 = v[1].xx; poly->y0 = v[1].yy;
746746
poly->x1 = v[0].xx; poly->y1 = v[0].yy;
@@ -762,6 +762,7 @@ static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
762762
struct PS1VertexTextured* v = (struct PS1VertexTextured*)gfx_vertices + startVertex;
763763
int uOffset = curTex->xOffset, vOffset = curTex->yOffset;
764764
int uShift = curTex->u_shift, vShift = curTex->v_shift;
765+
int tpage = curTex->tpage, clut = curTex->clut;
765766

766767
struct PSX_POLY_FT4* poly = next_packet;
767768
cc_uint8* max = next_packet_end - sizeof(*poly);
@@ -772,8 +773,8 @@ static void DrawTexturedQuads2D(int verticesCount, int startVertex) {
772773

773774
setlen(poly, POLY_LEN_FT4);
774775
poly->rgbc = v->rgbc;
775-
poly->tpage = curTex->tpage;
776-
poly->clut = 0;
776+
poly->tpage = tpage;
777+
poly->clut = clut;
777778

778779
poly->x0 = v[1].xx; poly->y0 = v[1].yy;
779780
poly->x1 = v[0].xx; poly->y1 = v[0].yy;
@@ -848,7 +849,7 @@ static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
848849
int uShift = curTex->u_shift;
849850
int vShift = curTex->v_shift;
850851

851-
int page = curTex->tpage;
852+
int tpage = curTex->tpage, clut = curTex->clut;
852853
uint32_t* ot = cur_buffer->ot;
853854

854855
struct PSX_POLY_FT4* poly = next_packet;
@@ -895,8 +896,8 @@ static void DrawTexturedQuads3D(int verticesCount, int startVertex) {
895896
poly->u3 = (v3->u >> uShift) + uOffset;
896897
poly->v3 = (v3->v >> vShift) + vOffset;
897898

898-
poly->tpage = page;
899-
poly->clut = 0;
899+
poly->tpage = tpage;
900+
poly->clut = clut;
900901
addPrim(&ot[p >> 2], poly);
901902
poly++;
902903
}

src/Window_PS1.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,26 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; }
137137
/*########################################################################################################################*
138138
*-------------------------------------------------------Gamepads----------------------------------------------------------*
139139
*#########################################################################################################################*/
140+
// 1 = Circle, 2 = Cross, 3 = Square, 4 = Triangle
141+
static const BindMapping pad_defaults[BIND_COUNT] = {
142+
[BIND_FORWARD] = { CCPAD_UP, 0 },
143+
[BIND_BACK] = { CCPAD_DOWN, 0 },
144+
[BIND_LEFT] = { CCPAD_LEFT, 0 },
145+
[BIND_RIGHT] = { CCPAD_RIGHT, 0 },
146+
[BIND_JUMP] = { CCPAD_1, 0 },
147+
[BIND_SET_SPAWN] = { CCPAD_START, 0 },
148+
[BIND_CHAT] = { CCPAD_4, 0 },
149+
[BIND_INVENTORY] = { CCPAD_3, 0 },
150+
[BIND_SEND_CHAT] = { CCPAD_START, 0 },
151+
[BIND_SPEED] = { CCPAD_2, CCPAD_L },
152+
[BIND_NOCLIP] = { CCPAD_2, CCPAD_3 },
153+
[BIND_FLY] = { CCPAD_2, CCPAD_R },
154+
[BIND_FLY_UP] = { CCPAD_2, CCPAD_UP },
155+
[BIND_FLY_DOWN] = { CCPAD_2, CCPAD_DOWN },
156+
[BIND_PLACE_BLOCK] = { CCPAD_L, 0 },
157+
[BIND_DELETE_BLOCK] = { CCPAD_R, 0 },
158+
};
159+
140160
static char pad_buff[2][34];
141161

142162
void Gamepads_Init(void) {
@@ -198,7 +218,7 @@ static void ProcessPadInput(int port, PADTYPE* pad, float delta) {
198218

199219
void Gamepads_Process(float delta) {
200220
PADTYPE* pad = (PADTYPE*)&pad_buff[0][0];
201-
int port = Gamepad_Connect(0x503E, PadBind_Defaults);
221+
int port = Gamepad_Connect(0x503E, pad_defaults);
202222

203223
if (pad->stat == 0) ProcessPadInput(port, pad, delta);
204224
}

0 commit comments

Comments
 (0)