From d78fb8ed21283dfb98f68619f598a46b64391022 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 13 Apr 2024 19:47:03 +1000 Subject: [PATCH] PS1: Texturing sort of works technically --- src/Graphics_PS1.c | 13 ++++++++----- src/Platform_PS1.c | 7 +++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Graphics_PS1.c b/src/Graphics_PS1.c index 286949f9c..92e70b930 100644 --- a/src/Graphics_PS1.c +++ b/src/Graphics_PS1.c @@ -88,7 +88,7 @@ void Gfx_RestoreState(void) { // 2x2 dummy white texture struct Bitmap bmp; - BitmapCol pixels[4] = { BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE }; + BitmapCol pixels[4] = { BitmapColor_RGB(255, 0, 0), BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE, BITMAPCOLOR_WHITE }; Bitmap_Init(bmp, 2, 2, pixels); white_square = Gfx_CreateTexture(&bmp, 0, false); } @@ -211,18 +211,21 @@ static void* AllocTextureAt(int i, struct Bitmap* bmp) { int page = TPAGE_START_HOR + (line / TPAGE_HEIGHT); // In bottom half of VRAM? Need to offset horizontally again - if (page >= TPAGES_PER_HALF) page += TPAGE_START_HOR; + if (page >= TPAGES_PER_HALF) page += TPAGE_START_HOR; + + int pageX = page % TPAGES_PER_HALF; + int pageY = page / TPAGES_PER_HALF; for (int i = tex->line; i < tex->line + tex->height; i++) { VRAM_SetUsed(i); } - tex->tpage = page; + tex->tpage = (2 << 7) | (pageY << 4) | pageX; Platform_Log4("%i x %i = %i,%i", &bmp->width, &bmp->height, &line, &page); RECT rect; - rect.x = ((page % TPAGES_PER_HALF)) * TPAGE_WIDTH; - rect.y = ((page / TPAGES_PER_HALF)) * TPAGE_HEIGHT + (line % TPAGE_HEIGHT); + rect.x = pageX * TPAGE_WIDTH; + rect.y = pageY * TPAGE_HEIGHT + (line % TPAGE_HEIGHT); rect.w = bmp->width; rect.h = bmp->height; diff --git a/src/Platform_PS1.c b/src/Platform_PS1.c index 46b5c7e73..e076d2fff 100644 --- a/src/Platform_PS1.c +++ b/src/Platform_PS1.c @@ -18,6 +18,13 @@ #include #include void exit(int code) { _boot(); } + +// The SDK calloc doesn't zero memory, so need to override it +void* calloc(size_t num, size_t size) { + void* ptr = malloc(num * size); + if (ptr) memset(ptr, 0, num * size); + return ptr; +} #include "_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used