PS2: Clearing screen to a colour each frame sorta works

This commit is contained in:
UnknownShadow200 2023-11-22 19:22:26 +11:00
parent 9e4fc869ad
commit 2f58a44e31
11 changed files with 192 additions and 47 deletions

View file

@ -8,7 +8,7 @@ N64_ROM_RTC = true
CFILES := $(notdir $(wildcard src/*.c))
OFILES := $(CFILES:.c=.o)
OBJS := $(addprefix $(BUILD_DIR)/,$(OFILES))
CFLAGS := "-Wno-error=missing-braces -Wno-error=maybe-uninitialized"
CFLAGS := "-Wno-error=missing-braces"
include $(N64_INST)/include/n64.mk

View file

@ -5,7 +5,7 @@ OBJS :=$(patsubst %.c, %.o, $(CFILES))
EE_BIN = ClassiCube-ps2.elf
EE_OBJS = $(OBJS)
EE_LIBS = -lpad -lpacket -ldma -lgraph -ldraw -lc
EE_LIBS = -lpatches -lpad -lpacket -ldma -lgraph -ldraw -lc
EE_CFLAGS = -DPLAT_PS2
all: $(EE_BIN)

View file

@ -20,7 +20,7 @@ void AxisLinesRenderer_Render(void) {
1,2,2, 1,2,4, 3,2,4, 3,2,2, /* Z arrow */
1,2,3, 1,4,3, 3,4,1, 3,2,1, /* Y arrow */
};
static const PackedCol colors[3] = {
static const PackedCol colors[] = {
PackedCol_Make(255, 0, 0, 255), /* Red */
PackedCol_Make( 0, 0, 255, 255), /* Blue */
PackedCol_Make( 0, 255, 0, 255), /* Green */
@ -60,7 +60,8 @@ void AxisLinesRenderer_Render(void) {
v = (struct VertexColoured*)Gfx_LockDynamicVb(axisLines_vb,
VERTEX_FORMAT_COLOURED, AXISLINES_NUM_VERTICES);
for (i = 0; i < count; i++, v++) {
for (i = 0; i < count; i++, v++)
{
v->X = coords[indices[i*3 + 0]].X;
v->Y = coords[indices[i*3 + 1]].Y;
v->Z = coords[indices[i*3 + 2]].Z;

View file

@ -3,7 +3,25 @@
#include "_GraphicsBase.h"
#include "Errors.h"
#include "Window.h"
#include <packet.h>
#include <dma_tags.h>
#include <gif_tags.h>
#include <gs_psm.h>
#include <dma.h>
#include <graph.h>
#include <draw.h>
#include <draw3d.h>
static void* gfx_vertices;
static framebuffer_t fb_color;
static zbuffer_t fb_depth;
// double buffering
static packet_t* packets[2];
static packet_t* current;
static int context;
static qword_t* dma_tag;
static qword_t* q;
void Gfx_RestoreState(void) {
InitDefaultResources();
@ -13,7 +31,60 @@ void Gfx_FreeState(void) {
FreeDefaultResources();
}
static void InitBuffers(void) {
fb_color.width = DisplayInfo.Width;
fb_color.height = DisplayInfo.Height;
fb_color.mask = 0;
fb_color.psm = GS_PSM_32;
fb_color.address = graph_vram_allocate(fb_color.width, fb_color.height, fb_color.psm, GRAPH_ALIGN_PAGE);
fb_depth.enable = DRAW_ENABLE;
fb_depth.mask = 0;
fb_depth.method = ZTEST_METHOD_GREATER_EQUAL;
fb_depth.zsm = GS_ZBUF_32;
fb_depth.address = graph_vram_allocate(fb_color.width, fb_color.height, fb_depth.zsm, GRAPH_ALIGN_PAGE);
graph_initialize(fb_color.address, fb_color.width, fb_color.height, fb_color.psm, 0, 0);
}
static void InitDrawingEnv(void) {
packet_t *packet = packet_init(20, PACKET_NORMAL);
qword_t *q = packet->data;
q = draw_setup_environment(q, 0, &fb_color, &fb_depth);
// GS can render from 0 to 4096, so set primitive origin to centre of that
q = draw_primitive_xyoffset(q, 0, 2048 - DisplayInfo.Width / 2, 2048 - DisplayInfo.Height / 2);
q = draw_finish(q);
dma_channel_send_normal(DMA_CHANNEL_GIF,packet->data,q - packet->data, 0, 0);
dma_wait_fast();
packet_free(packet);
}
static void InitDMABuffers(void) {
packets[0] = packet_init(100, PACKET_NORMAL);
packets[1] = packet_init(100, PACKET_NORMAL);
}
static void FlipContext(void) {
context ^= 1;
current = packets[context];
dma_tag = current->data;
// increment past the dmatag itself
q = dma_tag + 1;
}
void Gfx_Create(void) {
InitBuffers();
InitDrawingEnv();
InitDMABuffers();
context = 1;
FlipContext();
Gfx.MaxTexWidth = 512;
Gfx.MaxTexHeight = 512;
Gfx.Created = true;
@ -58,6 +129,8 @@ void Gfx_DisableMipmaps(void) { }
/*########################################################################################################################*
*------------------------------------------------------State management---------------------------------------------------*
*#########################################################################################################################*/
static int clearR, clearG, clearB;
void Gfx_SetFog(cc_bool enabled) { }
void Gfx_SetFogCol(PackedCol col) { }
void Gfx_SetFogDensity(float value) { }
@ -79,11 +152,16 @@ void Gfx_SetAlphaBlending(cc_bool enabled) {
void Gfx_SetAlphaArgBlend(cc_bool enabled) { }
void Gfx_Clear(void) {
// TODO
q = draw_disable_tests(q, 0, &fb_depth);
q = draw_clear(q, 0, 2048.0f - fb_color.width / 2.0f, 2048.0f - fb_color.height / 2.0f,
fb_color.width, fb_color.height, clearR, clearG, clearB);
q = draw_enable_tests(q, 0, &fb_depth);
}
void Gfx_ClearCol(PackedCol color) {
// TODO
clearR = PackedCol_R(color);
clearG = PackedCol_G(color);
clearB = PackedCol_B(color);
}
void Gfx_SetDepthTest(cc_bool enabled) {
@ -240,17 +318,33 @@ cc_bool Gfx_WarnIfNecessary(void) {
return false;
}
static int FRAME;
void Gfx_BeginFrame(void) {
Platform_LogConst("--- Frame ---");
Gfx_ClearCol(PackedCol_Make(200 + FRAME, 51, 42, 255));
// TODO
FRAME++;
}
void Gfx_EndFrame(void) {
// TODO
q = draw_finish(q);
// Fill out and then send DMA chain
DMATAG_END(dma_tag, (q - current->data) - 1, 0, 0, 0);
dma_wait_fast();
dma_channel_send_chain(DMA_CHANNEL_GIF, current->data, q - current->data, 0, 0);
draw_wait_finish();
if (gfx_vsync) graph_wait_vsync();
if (gfx_minFrameMs) LimitFPS();
FlipContext();
}
void Gfx_SetFpsLimit(cc_bool vsync, float minFrameMs) {
gfx_minFrameMs = minFrameMs;
gfx_vsync = vsync;
gfx_vsync = vsync;
}
void Gfx_OnWindowResize(void) {

View file

@ -1139,48 +1139,54 @@ static void GenLevelScreen_Make(struct GenLevelScreen* s, int i, int def) {
TextInputWidget_Create(&s->inputs[i], 200, &tmp, &desc);
s->inputs[i].base.showCaret = false;
TextWidget_Init(&s->labels[i]);
s->labels[i].col = PackedCol_Make(224, 224, 224, 255);
s->labels[i].color = PackedCol_Make(224, 224, 224, 255);
/* TODO placeholder */
s->inputs[i].onscreenType = KEYBOARD_TYPE_INTEGER;
}
static struct InputWidget* GenLevelScreen_SelectedInput(struct GenLevelScreen* s) {
static struct TextInputWidget* GenLevelScreen_SelectedInput(struct GenLevelScreen* s) {
if (s->selectedI >= 0 && s->selectedI < GENLEVEL_NUM_INPUTS)
return &s->inputs[s->selectedI].base;
return &s->inputs[s->selectedI];
return NULL;
}
static int GenLevelScreen_KeyDown(void* screen, int key) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
struct InputWidget* selected = GenLevelScreen_SelectedInput(s);
struct TextInputWidget* selected = GenLevelScreen_SelectedInput(s);
struct MenuInputDesc* desc;
if (selected && Elem_HandlesKeyDown(selected, key)) return true;
if (selected) {
if (Elem_HandlesKeyDown(&selected->base, key)) return true;
desc = &selected->desc;
if (desc->VTABLE->ProcessInput(desc, &selected->base.text, key)) return true;
}
return Menu_InputDown(s, key);
}
static int GenLevelScreen_KeyPress(void* screen, char keyChar) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
struct InputWidget* selected = GenLevelScreen_SelectedInput(s);
struct TextInputWidget* selected = GenLevelScreen_SelectedInput(s);
if (selected) InputWidget_Append(selected, keyChar);
if (selected) InputWidget_Append(&selected->base, keyChar);
return true;
}
static int GenLevelScreen_TextChanged(void* screen, const cc_string* str) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
struct InputWidget* selected = GenLevelScreen_SelectedInput(s);
struct TextInputWidget* selected = GenLevelScreen_SelectedInput(s);
if (selected) InputWidget_SetText(selected, str);
if (selected) InputWidget_SetText(&selected->base, str);
return true;
}
static int GenLevelScreen_PointerDown(void* screen, int id, int x, int y) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
struct InputWidget* selected;
struct TextInputWidget* selected;
s->selectedI = Screen_DoPointerDown(screen, id, x, y);
selected = GenLevelScreen_SelectedInput(s);
if (selected) Window_SetKeyboardText(&selected->text);
if (selected) Window_SetKeyboardText(&selected->base.text);
return TOUCH_TYPE_GUI;
}
@ -1216,14 +1222,14 @@ static void GenLevelScreen_ContextRecreated(void* screen) {
static void GenLevelScreen_Update(void* screen, double delta) {
struct GenLevelScreen* s = (struct GenLevelScreen*)screen;
struct InputWidget* selected = GenLevelScreen_SelectedInput(s);
struct TextInputWidget* selected = GenLevelScreen_SelectedInput(s);
int i;
for (i = 0; i < GENLEVEL_NUM_INPUTS; i++)
{
s->inputs[i].base.showCaret = i == s->selectedI;
}
if (selected) selected->caretAccumulator += delta;
if (selected) selected->base.caretAccumulator += delta;
}
static void GenLevelScreen_Layout(void* screen) {
@ -3503,7 +3509,7 @@ static void Overlay_InitLabels(struct TextWidget* labels) {
TextWidget_Init(&labels[0]);
for (i = 1; i < 4; i++) {
TextWidget_Init(&labels[i]);
labels[i].col = PackedCol_Make(224, 224, 224, 255);
labels[i].color = PackedCol_Make(224, 224, 224, 255);
}
}
@ -4014,8 +4020,9 @@ static void TouchOnscreen_UpdateColors(struct TouchOnscreenScreen* s) {
PackedCol grey = PackedCol_Make(0x7F, 0x7F, 0x7F, 0xFF);
int i, j;
for (i = 0, j = s->offset; i < ONSCREEN_PAGE_BTNS; i++, j++) {
s->btns[i].col = (Gui._onscreenButtons & (1 << j)) ? PACKEDCOL_WHITE : grey;
for (i = 0, j = s->offset; i < ONSCREEN_PAGE_BTNS; i++, j++)
{
s->btns[i].color = (Gui._onscreenButtons & (1 << j)) ? PACKEDCOL_WHITE : grey;
}
}

View file

@ -25,6 +25,10 @@
#include <timer_alarm.h>
#include <debug.h>
#include <sifrpc.h>
#include <iopheap.h>
#include <loadfile.h>
#include <iopcontrol.h>
#include <sbv_patches.h>
#include "_PlatformConsole.h"
const cc_result ReturnCode_FileShareViolation = 1000000000; // not used
@ -330,6 +334,16 @@ void Waitable_WaitFor(void* handle, cc_uint32 milliseconds) {
}
/*########################################################################################################################*
*-------------------------------------------------------Networking--------------------------------------------------------*
*#########################################################################################################################*/
static void InitNetworking(void) {
//SifExecModuleBuffer(DEV9_irx, size_DEV9_irx, 0, NULL, NULL);
//SifExecModuleBuffer(NETMAN_irx, size_NETMAN_irx, 0, NULL, NULL);
//SifExecModuleBuffer(SMAP_irx, size_SMAP_irx, 0, NULL, NULL);
//NetManInit();
}
/*########################################################################################################################*
*---------------------------------------------------------Socket----------------------------------------------------------*
*#########################################################################################################################*/
@ -364,10 +378,24 @@ cc_result Socket_CheckWritable(cc_socket s, cc_bool* writable) {
/*########################################################################################################################*
*--------------------------------------------------------Platform---------------------------------------------------------*
*#########################################################################################################################*/
// Note that resetting IOP does mean can't debug through ps2client
// https://github.com/libsdl-org/SDL/commit/d355ea9981358a1df335b1f7485ce94768bbf255
// https://github.com/libsdl-org/SDL/pull/6022
static void ResetIOP(void) { // reboots the IOP
SifInitRpc(0);
while (!SifIopReset("", 0)) { }
while (!SifIopSync()) { }
}
void Platform_Init(void) {
//InitDebug();
ResetIOP();
SifInitRpc(0);
//netInitialize();
SifLoadFileInit();
SifInitIopHeap();
sbv_patch_enable_lmb();
InitNetworking();
// Create root directory
Directory_Create(&String_Empty);
}

View file

@ -2241,7 +2241,7 @@ static void TouchScreen_InitButtons(struct TouchScreen* s) {
for (i = 0; i < s->numBtns; i++) {
s->widgets[i + ONSCREEN_MAX_BTNS] = (struct Widget*)&s->btns[i];
ButtonWidget_Init(&s->btns[i], 60, s->descs[i].OnClick);
s->btns[i].col = TOUCHSCREEN_BTN_COL;
s->btns[i].color = TOUCHSCREEN_BTN_COL;
}
}
@ -2376,7 +2376,7 @@ static void TouchScreen_Init(void* screen) {
TouchScreen_InitButtons(s);
ButtonWidget_Init(&s->more, 40, TouchScreen_MoreClick);
s->more.col = TOUCHSCREEN_BTN_COL;
s->more.color = TOUCHSCREEN_BTN_COL;
ThumbstickWidget_Init(&s->thumbstick);
touchInput.GetMovement = TouchScreen_GetMovement;

View file

@ -31,7 +31,7 @@ CC_NOINLINE cc_string String_FromRaw(STRING_REF char* buffer, int capacity);
CC_API cc_string String_FromReadonly(STRING_REF const char* buffer);
/* Constructs a string from a compile time string constant */
#define String_FromConst(text) { text, (sizeof(text) - 1), (sizeof(text) - 1)}
#define String_FromConst(text) { (char*)(text), (sizeof(text) - 1), (sizeof(text) - 1)}
/* Constructs a string from a compile time array */
#define String_FromArray(buffer) { buffer, 0, sizeof(buffer)}
/* Constructs a string from a compile time array, that may have arbitary actual length of data at runtime */

View file

@ -31,7 +31,7 @@ static int Widget_MouseScroll(void* elem, float delta) { return false; }
*#########################################################################################################################*/
static void TextWidget_Render(void* widget, double delta) {
struct TextWidget* w = (struct TextWidget*)widget;
if (w->tex.ID) Texture_RenderShaded(&w->tex, w->col);
if (w->tex.ID) Texture_RenderShaded(&w->tex, w->color);
}
static void TextWidget_Free(void* widget) {
@ -47,7 +47,7 @@ static void TextWidget_Reposition(void* widget) {
static void TextWidget_BuildMesh(void* widget, struct VertexTextured** vertices) {
struct TextWidget* w = (struct TextWidget*)widget;
Gfx_Make2DQuad(&w->tex, w->col, vertices);
Gfx_Make2DQuad(&w->tex, w->color, vertices);
}
static int TextWidget_Render2(void* widget, int offset) {
@ -68,7 +68,7 @@ static const struct WidgetVTABLE TextWidget_VTABLE = {
void TextWidget_Init(struct TextWidget* w) {
Widget_Reset(w);
w->VTABLE = &TextWidget_VTABLE;
w->col = PACKEDCOL_WHITE;
w->color = PACKEDCOL_WHITE;
}
void TextWidget_Set(struct TextWidget* w, const cc_string* text, struct FontDesc* font) {
@ -144,11 +144,11 @@ static void ButtonWidget_Render(void* widget, double delta) {
back.Width = (w->width / 2);
back.uv.U1 = 0.0f; back.uv.U2 = BUTTON_uWIDTH * scale;
Gfx_Draw2DTexture(&back, w->col);
Gfx_Draw2DTexture(&back, w->color);
back.X += (w->width / 2);
back.uv.U1 = BUTTON_uWIDTH * (1.0f - scale); back.uv.U2 = BUTTON_uWIDTH;
Gfx_Draw2DTexture(&back, w->col);
Gfx_Draw2DTexture(&back, w->color);
}
if (!w->tex.ID) return;
@ -176,7 +176,7 @@ static void ButtonWidget_BuildMesh(void* widget, struct VertexTextured** vertice
/* TODO: Does this 400 need to take DPI into account */
if (w->width >= 400) {
/* Button can be drawn normally */
Gfx_Make2DQuad(&back, w->col, vertices);
Gfx_Make2DQuad(&back, w->color, vertices);
*vertices += 4; /* always use up 8 vertices for body */
} else {
/* Split button down the middle */
@ -184,11 +184,11 @@ static void ButtonWidget_BuildMesh(void* widget, struct VertexTextured** vertice
back.Width = (w->width / 2);
back.uv.U1 = 0.0f; back.uv.U2 = BUTTON_uWIDTH * scale;
Gfx_Make2DQuad(&back, w->col, vertices);
Gfx_Make2DQuad(&back, w->color, vertices);
back.X += (w->width / 2);
back.uv.U1 = BUTTON_uWIDTH * (1.0f - scale); back.uv.U2 = BUTTON_uWIDTH;
Gfx_Make2DQuad(&back, w->col, vertices);
Gfx_Make2DQuad(&back, w->color, vertices);
}
color = (w->flags & WIDGET_FLAG_DISABLED) ? disabledColor
@ -223,7 +223,7 @@ void ButtonWidget_Make(struct ButtonWidget* w, int minWidth, Widget_LeftClick on
void ButtonWidget_Init(struct ButtonWidget* w, int minWidth, Widget_LeftClick onClick) {
Widget_Reset(w);
w->VTABLE = &ButtonWidget_VTABLE;
w->col = PACKEDCOL_WHITE;
w->color = PACKEDCOL_WHITE;
w->optName = NULL;
w->flags = WIDGET_FLAG_SELECTABLE;
w->minWidth = Display_ScaleX(minWidth);
@ -1414,6 +1414,9 @@ static int InputWidget_PointerDown(void* widget, int id, int x, int y) {
/*########################################################################################################################*
*-----------------------------------------------------MenuInputDesc-------------------------------------------------------*
*#########################################################################################################################*/
static void MenuInput_NoDefault(struct MenuInputDesc* d, cc_string* value) { }
static cc_bool MenuInput_NoProcess(struct MenuInputDesc* d, cc_string* value, int btn) { return false; }
static void Hex_Range(struct MenuInputDesc* d, cc_string* range) {
String_AppendConst(range, "&7(#000000 - #FFFFFF)");
}
@ -1436,7 +1439,8 @@ static void Hex_Default(struct MenuInputDesc* d, cc_string* value) {
}
const struct MenuInputVTABLE HexInput_VTABLE = {
Hex_Range, Hex_ValidChar, Hex_ValidString, Hex_ValidValue, Hex_Default
Hex_Range, Hex_ValidChar, Hex_ValidString, Hex_ValidValue,
Hex_Default, MenuInput_NoProcess
};
static void Int_Range(struct MenuInputDesc* d, cc_string* range) {
@ -1463,16 +1467,17 @@ static void Int_Default(struct MenuInputDesc* d, cc_string* value) {
}
const struct MenuInputVTABLE IntInput_VTABLE = {
Int_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Int_Default
Int_Range, Int_ValidChar, Int_ValidString, Int_ValidValue,
Int_Default, MenuInput_NoProcess
};
static void Seed_Range(struct MenuInputDesc* d, cc_string* range) {
String_AppendConst(range, "&7(an integer)");
}
static void Seed_NoDefault(struct MenuInputDesc* d, cc_string* value) { }
const struct MenuInputVTABLE SeedInput_VTABLE = {
Seed_Range, Int_ValidChar, Int_ValidString, Int_ValidValue, Seed_NoDefault
Seed_Range, Int_ValidChar, Int_ValidString, Int_ValidValue,
MenuInput_NoDefault, MenuInput_NoProcess
};
static void Float_Range(struct MenuInputDesc* d, cc_string* range) {
@ -1499,7 +1504,8 @@ static void Float_Default(struct MenuInputDesc* d, cc_string* value) {
}
const struct MenuInputVTABLE FloatInput_VTABLE = {
Float_Range, Float_ValidChar, Float_ValidString, Float_ValidValue, Float_Default
Float_Range, Float_ValidChar, Float_ValidString, Float_ValidValue,
Float_Default, MenuInput_NoProcess
};
static void Path_Range(struct MenuInputDesc* d, cc_string* range) {
@ -1513,7 +1519,8 @@ static cc_bool Path_ValidChar(struct MenuInputDesc* d, char c) {
static cc_bool Path_ValidString(struct MenuInputDesc* d, const cc_string* s) { return true; }
const struct MenuInputVTABLE PathInput_VTABLE = {
Path_Range, Path_ValidChar, Path_ValidString, Path_ValidString, Seed_NoDefault
Path_Range, Path_ValidChar, Path_ValidString, Path_ValidString,
MenuInput_NoDefault, MenuInput_NoProcess
};
static void String_Range(struct MenuInputDesc* d, cc_string* range) {
@ -1529,7 +1536,8 @@ static cc_bool String_ValidString(struct MenuInputDesc* d, const cc_string* s) {
}
const struct MenuInputVTABLE StringInput_VTABLE = {
String_Range, String_ValidChar, String_ValidString, String_ValidString, Seed_NoDefault
String_Range, String_ValidChar, String_ValidString, String_ValidString,
MenuInput_NoDefault, MenuInput_NoProcess
};

View file

@ -15,7 +15,7 @@ struct FontDesc;
struct TextWidget {
Widget_Body
struct Texture tex;
PackedCol col;
PackedCol color;
};
#define TEXTWIDGET_MAX 4
@ -33,7 +33,7 @@ typedef void (*Button_Set)(const cc_string* raw);
struct ButtonWidget {
Widget_Body
struct Texture tex;
PackedCol col;
PackedCol color;
int minWidth, minHeight;
const char* optName;
Button_Get GetValue;
@ -181,6 +181,9 @@ struct MenuInputVTABLE {
cc_bool (*IsValidValue)(struct MenuInputDesc* d, const cc_string* s);
/* Gets the default value for this input. */
void (*GetDefault)(struct MenuInputDesc* d, cc_string* value);
/* Whether the given input button was processed */
/* E.g. Int input accepts using lef/right to increment/decrement */
cc_bool (*ProcessInput)(struct MenuInputDesc* d, cc_string* value, int btn);
};
struct MenuInputDesc {

View file

@ -54,7 +54,7 @@ static CC_NOINLINE cc_uint32 CalcMemSize(cc_uint32 numElems, cc_uint32 elemsSize
/*########################################################################################################################*
*------------------------------------------------------Logging/Time-------------------------------------------------------*
*--------------------------------------------------------Logging----------------------------------------------------------*
*#########################################################################################################################*/
void Platform_Log1(const char* format, const void* a1) {
Platform_Log4(format, a1, NULL, NULL, NULL);
@ -78,6 +78,10 @@ void Platform_LogConst(const char* message) {
Platform_Log(message, String_Length(message));
}
/*########################################################################################################################*
*----------------------------------------------------------Misc-----------------------------------------------------------*
*#########################################################################################################################*/
int Stopwatch_ElapsedMS(cc_uint64 beg, cc_uint64 end) {
cc_uint64 raw = Stopwatch_ElapsedMicroseconds(beg, end);
if (raw > Int32_MaxValue) return Int32_MaxValue / 1000;