From 403e466ac279414554d751524cae489daa4156c6 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 10 Jul 2025 20:12:33 +1000 Subject: [PATCH 1/5] Refactor Saturn makefile, fix PSP build --- misc/dreamcast/Makefile | 3 +- misc/psp/Makefile | 36 ++++---- misc/saturn/Makefile | 141 +++++++++++++++++++++++++---- src/psp/Graphics_PSP.c | 11 +-- src/psp/Platform_PSP.c | 20 ++-- src/psp/Window_PSP.c | 26 +++--- src/{ => saturn}/Graphics_Saturn.c | 12 +-- src/{ => saturn}/Platform_Saturn.c | 25 +++-- src/{ => saturn}/Window_Saturn.c | 25 +++-- 9 files changed, 191 insertions(+), 108 deletions(-) rename src/{ => saturn}/Graphics_Saturn.c (99%) rename src/{ => saturn}/Platform_Saturn.c (94%) rename src/{ => saturn}/Window_Saturn.c (94%) diff --git a/misc/dreamcast/Makefile b/misc/dreamcast/Makefile index 1d041e5c4..a0fd9607a 100644 --- a/misc/dreamcast/Makefile +++ b/misc/dreamcast/Makefile @@ -26,7 +26,8 @@ INCLUDES = S_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.S)) C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c)) OBJS := $(addprefix $(BUILD_DIR)/, $(notdir $(C_FILES:%.c=%.o) $(S_FILES:%.S=%.o))) -CFLAGS := -g -DNDEBUG -O3 -fipa-pta -fno-pie -flto=auto -fomit-frame-pointer -fbuiltin -ffast-math -ffp-contract=fast -mfsrra -mfsca -pipe -fno-math-errno + +CFLAGS = -g -DNDEBUG -O3 -fipa-pta -fno-pie -flto=auto -fomit-frame-pointer -fbuiltin -ffast-math -ffp-contract=fast -mfsrra -mfsca -pipe -fno-math-errno LDFLAGS = -g # Dependency tracking diff --git a/misc/psp/Makefile b/misc/psp/Makefile index 8e310e5c6..b0464b278 100644 --- a/misc/psp/Makefile +++ b/misc/psp/Makefile @@ -1,11 +1,9 @@ -ifeq ($(strip $(PSPSDK)),) -$(warning "Please set PSPSDK variables in your environment. For example:") -$(warning export PSPSDK=/usr/local/pspsk/psp/sdk) -$(warning export PATH=/usr/local/pspsk/bin:$$PATH) -$(warning Or) -$(warning export PSPSDK=$$(shell psp-config --pspsdk-path)) +ifeq ($(strip $(PSPDEV)),) +$(warning "Please set PSPDEV variables in your environment. For example:") +$(warning export PSPDEV=/usr/local/pspsdk) $(error Failed to find PSPSDK installation) endif +PSPSDK=$(PSPDEV)/psp/sdk #--------------------------------------------------------------------------------- @@ -36,13 +34,10 @@ S_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.S)) C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c)) OBJS := $(addprefix $(BUILD_DIR)/, $(notdir $(C_FILES:%.c=%.o) $(S_FILES:%.S=%.o))) -INCDIR := $(PSPDEV)/psp/include $(PSPSDK)/include -LIBDIR := $(PSPDEV)/psp/lib $(PSPSDK)/lib +CFLAGS := -I$(PSPSDK)/include -g -O1 -fno-math-errno -D_PSP_FW_VERSION=600 +ASFLAGS := -I$(PSPSDK)/include -g -CFLAGS := $(addprefix -I,$(INCDIR)) -g -O1 -fno-math-errno -D_PSP_FW_VERSION=600 -ASFLAGS := $(addprefix -I,$(INCDIR)) -g - -LDFLAGS := $(addprefix -L,$(LIBDIR)) -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx -Wl,-zmax-page-size=128 +LDFLAGS := -L$(PSPSDK)/lib -specs=$(PSPSDK)/lib/prxspecs -Wl,-q,-T$(PSPSDK)/lib/linkfile.prx -Wl,-zmax-page-size=128 LIBS := -lm -lpspgum -lpspgu -lpspge -lpspdisplay -lpspctrl -lpspdebug -lpspnet -lpspnet_apctl # Dependency tracking @@ -53,12 +48,13 @@ DEPFILES := $(OBJS:%.o=%.d) #--------------------------------------------------------------------------------- # Compiler tools #--------------------------------------------------------------------------------- -CC = psp-gcc -AS = psp-gcc -LD = psp-gcc -MKSFO = mksfoex -PACK_PBP = pack-pbp -FIXUP = psp-fixup-imports +CC = $(PSPDEV)/bin/psp-gcc +AS = $(PSPDEV)/bin/psp-gcc +LD = $(PSPDEV)/bin/psp-gcc +MKSFO = $(PSPDEV)/bin/mksfoex +PACK_PBP = $(PSPDEV)/bin/pack-pbp +FIXUP = $(PSPDEV)/bin/psp-fixup-imports +PRXGEN = $(PSPDEV)/bin/psp-prxgen #--------------------------------------------------------------------------------- @@ -81,7 +77,7 @@ $(TARGET).elf: $(OBJS) $(FIXUP) $@ $(TARGET).prx: $(TARGET).elf - psp-prxgen $< $@ + $(PRXGEN) $< $@ $(PSP_EBOOT_SFO): $(MKSFO) -d MEMSIZE=1 '$(PSP_EBOOT_TITLE)' $@ @@ -99,7 +95,7 @@ $(BUILD_DIR)/%.o : src/%.c $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ $(BUILD_DIR)/%.o : src/psp/%.c - $(VITA_CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ + $(CC) $(CFLAGS) $(DEPFLAGS) -c $< -o $@ $(BUILD_DIR)/%.o : third_party/bearssl/%.c $(CC) $(CFLAGS) -c $< -o $@ diff --git a/misc/saturn/Makefile b/misc/saturn/Makefile index 3fc2acc31..856d6938c 100644 --- a/misc/saturn/Makefile +++ b/misc/saturn/Makefile @@ -2,28 +2,131 @@ ifeq ($(strip $(YAUL_INSTALL_ROOT)),) $(error Undefined YAUL_INSTALL_ROOT (install root directory)) endif -SH_BUILD_DIR := build-saturn -include $(YAUL_INSTALL_ROOT)/share/build.pre.mk +#--------------------------------------------------------------------------------- +# Configurable options +#--------------------------------------------------------------------------------- +# Directory where object files are placed +BUILD_DIR = build/saturn +# List of directories containing source code +SOURCE_DIRS = src src/saturn +# Name of the final output +TARGET = ClassiCube-saturn -# Each asset follows the format: ;. Duplicates are removed -BUILTIN_ASSETS= +IP_VERSION = V1.370 +IP_RELEASE_DATE = 20250101 +IP_AREAS = JTUBKAEL +IP_PERIPHERALS = JAMKST +IP_TITLE = ClassiCube +#IP_MASTER_STACK_ADDR = 0x06004000 +IP_MASTER_STACK_ADDR = 0x06100000 +IP_SLAVE_STACK_ADDR = 0x06001E00 +IP_1ST_READ_ADDR = 0x06004000 +IP_1ST_READ_SIZE = 0 -SH_PROGRAM := ClassiCube-saturn -SH_SRCS := $(wildcard src/*.c) +CD_PATH = $(BUILD_DIR)/cd +AUDIO_TRACKS_DIRECTORY = audio-tracks +IMAGE_1ST_READ_BIN = A.BIN -SH_CFLAGS+= -Os -I. -DPLAT_SATURN -Wno-sign-compare -Wno-unused-parameter -Wno-missing-field-initializers -SH_LDFLAGS+= -IP_VERSION:= V1.000 -IP_RELEASE_DATE:= 20230101 -IP_AREAS:= JTUBKAEL -IP_PERIPHERALS:= JAMKST -IP_TITLE:= ClassiCube -#IP_MASTER_STACK_ADDR:= 0x06004000 -IP_MASTER_STACK_ADDR:= 0x06100000 -IP_SLAVE_STACK_ADDR:= 0x06001E00 -IP_1ST_READ_ADDR:= 0x06004000 -IP_1ST_READ_SIZE:= 0 +#--------------------------------------------------------------------------------- +# Code generation +#--------------------------------------------------------------------------------- +S_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.S)) +C_FILES := $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.c)) +SH_OBJS := $(addprefix $(BUILD_DIR)/, $(notdir $(C_FILES:%.c=%.o) $(S_FILES:%.S=%.o))) -include $(YAUL_INSTALL_ROOT)/share/build.post.iso-cue.mk +SH_CFLAGS = -Os -DPLAT_SATURN -Wstrict-aliasing \ + -I$(YAUL_INSTALL_ROOT)/$(YAUL_ARCH_SH_PREFIX)/include/yaul + +SH_LDFLAGS = -static -Wl,--gc-sections \ + -Wl,--defsym=___master_stack=$(IP_MASTER_STACK_ADDR) \ + -Wl,--defsym=___slave_stack=$(IP_SLAVE_STACK_ADDR) + +SH_SPECS = yaul.specs yaul-main.specs + +# Dependency tracking +DEPFLAGS = -MT $@ -MMD -MP -MF $(BUILD_DIR)/$*.d +DEPFILES := $(SH_OBJS:%.o=%.d) + + +#--------------------------------------------------------------------------------- +# Compiler tools +#--------------------------------------------------------------------------------- +SH_AS:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_SH_PREFIX)-as +SH_CC:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_SH_PREFIX)-gcc +SH_LD:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_SH_PREFIX)-gcc +SH_OBJCOPY:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_SH_PREFIX)-objcopy + +M68K_AS:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_M68K_PREFIX)-as +M68K_CC:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_M68K_PREFIX)-gcc +M68K_LD:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_M68K_PREFIX)-gcc +M68K_OBJCOPY:= $(YAUL_INSTALL_ROOT)/bin/$(YAUL_ARCH_M68K_PREFIX)-objcopy + + +#--------------------------------------------------------------------------------- +# Main targets +#--------------------------------------------------------------------------------- +default: $(BUILD_DIR) $(TARGET).cue + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +clean: + rm -f $(SH_OBJS) $(TARGET).bin $(TARGET).cue $(TARGET).iso \ + $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin $(BUILD_DIR)/IP.BIN + + +#--------------------------------------------------------------------------------- +# executable generation +#--------------------------------------------------------------------------------- +$(BUILD_DIR)/$(TARGET).elf: $(SH_OBJS) + $(SH_LD) $(foreach specs,$(SH_SPECS),-specs=$(specs)) $(SH_OBJS) $(SH_LDFLAGS) -o $@ + +$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf + $(SH_OBJCOPY) -O binary $< $@ + @[ -z "${SILENT}" ] && du -hs $@ | awk '{ print $$1; }' || true + +$(TARGET).bin: $(BUILD_DIR)/$(TARGET).bin + cp $< $@ + +$(BUILD_DIR)/IP.BIN: $(TARGET).bin + $(YAUL_INSTALL_ROOT)/bin/make-ip \ + "$(BUILD_DIR)/$(TARGET).bin" \ + $(IP_VERSION) $(IP_RELEASE_DATE) $(IP_AREAS) $(IP_PERIPHERALS) \ + '"$(IP_TITLE)"' \ + $(IP_MASTER_STACK_ADDR) $(IP_SLAVE_STACK_ADDR) \ + $(IP_1ST_READ_ADDR) $(IP_1ST_READ_SIZE) + +$(TARGET).iso: $(TARGET).bin $(BUILD_DIR)/IP.BIN + mkdir -p $(CD_PATH) + cp $(TARGET).bin $(CD_PATH)/$(IMAGE_1ST_READ_BIN) + printf "empty\n" > $(CD_PATH)/"ABS.TXT" + printf "empty\n" > $(CD_PATH)/"BIB.TXT" + printf "empty\n" > $(CD_PATH)/"CPY.TXT" + $(YAUL_INSTALL_ROOT)/bin/make-iso $(CD_PATH) $(BUILD_DIR)/IP.BIN . $(TARGET) + +$(TARGET).cue: $(TARGET).iso + mkdir -p $(AUDIO_TRACKS_DIRECTORY) + $(YAUL_INSTALL_ROOT)/bin/make-cue $(AUDIO_TRACKS_DIRECTORY) $(TARGET).iso + + +#--------------------------------------------------------------------------------- +# object generation +#--------------------------------------------------------------------------------- +$(BUILD_DIR)/%.o : src/%.c + $(SH_CC) $(SH_CFLAGS) $(DEPFLAGS) $(foreach specs,$(SH_SPECS),-specs=$(specs)) -c $< -o $@ + +$(BUILD_DIR)/%.o : src/saturn/%.c + $(SH_CC) $(SH_CFLAGS) $(DEPFLAGS) $(foreach specs,$(SH_SPECS),-specs=$(specs)) -c $< -o $@ + +$(BUILD_DIR)/%.o : src/saturn/%.S + $(SH_CC) $(SH_CFLAGS) $(DEPFLAGS) -c $< -o $@ + + +#--------------------------------------------------------------------------------- +# Dependency tracking +#--------------------------------------------------------------------------------- +$(DEPFILES): + +include $(wildcard $(DEPFILES)) diff --git a/src/psp/Graphics_PSP.c b/src/psp/Graphics_PSP.c index ea2aa1da6..d93c2556d 100644 --- a/src/psp/Graphics_PSP.c +++ b/src/psp/Graphics_PSP.c @@ -1,9 +1,7 @@ -#include "Core.h" -#if defined CC_BUILD_PSP -#include "_GraphicsBase.h" -#include "Errors.h" -#include "Logger.h" -#include "Window.h" +#include "../_GraphicsBase.h" +#include "../Errors.h" +#include "../Logger.h" +#include "../Window.h" #include #include @@ -454,4 +452,3 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { sceGuDrawArray(GU_TRIANGLES, gfx_fields | GU_INDEX_16BIT, ICOUNT(verticesCount), gfx_indices, gfx_vertices + startVertex * SIZEOF_VERTEX_TEXTURED); } -#endif diff --git a/src/psp/Platform_PSP.c b/src/psp/Platform_PSP.c index 090b2038a..adf48ab32 100644 --- a/src/psp/Platform_PSP.c +++ b/src/psp/Platform_PSP.c @@ -1,14 +1,11 @@ -#include "Core.h" -#if defined CC_BUILD_PSP - #define CC_XTEA_ENCRYPTION -#include "_PlatformBase.h" -#include "Stream.h" -#include "ExtMath.h" -#include "Funcs.h" -#include "Window.h" -#include "Utils.h" -#include "Errors.h" +#include "../_PlatformBase.h" +#include "../Stream.h" +#include "../ExtMath.h" +#include "../Funcs.h" +#include "../Window.h" +#include "../Utils.h" +#include "../Errors.h" #include #include @@ -22,7 +19,7 @@ #include #include #include -#include "_PlatformConsole.h" +#include "../_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used const cc_result ReturnCode_FileNotFound = ENOENT; @@ -496,4 +493,3 @@ static cc_result GetMachineID(cc_uint32* key) { Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1); return 0; } -#endif diff --git a/src/psp/Window_PSP.c b/src/psp/Window_PSP.c index 6d4e1eae2..ef2b6f5d3 100644 --- a/src/psp/Window_PSP.c +++ b/src/psp/Window_PSP.c @@ -1,16 +1,15 @@ -#include "Core.h" -#if defined CC_BUILD_PSP -#include "Window.h" -#include "Platform.h" -#include "Input.h" -#include "Event.h" -#include "Graphics.h" -#include "String.h" -#include "Funcs.h" -#include "Bitmap.h" -#include "Errors.h" -#include "ExtMath.h" -#include "VirtualKeyboard.h" +#include "../Window.h" +#include "../Platform.h" +#include "../Input.h" +#include "../Event.h" +#include "../Graphics.h" +#include "../String.h" +#include "../Funcs.h" +#include "../Bitmap.h" +#include "../Errors.h" +#include "../ExtMath.h" +#include "../VirtualKeyboard.h" + #include #include #include @@ -201,4 +200,3 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { return ERR_NOT_SUPPORTED; } -#endif diff --git a/src/Graphics_Saturn.c b/src/saturn/Graphics_Saturn.c similarity index 99% rename from src/Graphics_Saturn.c rename to src/saturn/Graphics_Saturn.c index 6af491780..14b8c2276 100644 --- a/src/Graphics_Saturn.c +++ b/src/saturn/Graphics_Saturn.c @@ -1,11 +1,10 @@ -#include "Core.h" -#if defined CC_BUILD_SATURN -#include "_GraphicsBase.h" -#include "Errors.h" -#include "Window.h" +#include "../_GraphicsBase.h" +#include "../Errors.h" +#include "../Window.h" +#include "../_BlockAlloc.h" + #include #include -#include "_BlockAlloc.h" #define SCREEN_WIDTH 320 #define SCREEN_HEIGHT 224 @@ -790,4 +789,3 @@ void Gfx_End2D(void) { Gfx_SetAlphaBlending(false); gfx_rendering2D = false; } -#endif diff --git a/src/Platform_Saturn.c b/src/saturn/Platform_Saturn.c similarity index 94% rename from src/Platform_Saturn.c rename to src/saturn/Platform_Saturn.c index 08419a60c..4c8cd4f33 100644 --- a/src/Platform_Saturn.c +++ b/src/saturn/Platform_Saturn.c @@ -1,16 +1,14 @@ -#include "Core.h" -#if defined PLAT_SATURN - #define CC_XTEA_ENCRYPTION -#include "_PlatformBase.h" -#include "Stream.h" -#include "ExtMath.h" -#include "Funcs.h" -#include "Window.h" -#include "Utils.h" -#include "Errors.h" -#include "Options.h" -#include "PackedCol.h" +#include "../_PlatformBase.h" +#include "../Stream.h" +#include "../ExtMath.h" +#include "../Funcs.h" +#include "../Window.h" +#include "../Utils.h" +#include "../Errors.h" +#include "../Options.h" +#include "../PackedCol.h" + #include #include #include @@ -24,7 +22,7 @@ void* calloc(size_t num, size_t size) { return ptr; } -#include "_PlatformConsole.h" +#include "../_PlatformConsole.h" const cc_result ReturnCode_FileShareViolation = 1000000000; // not used const cc_result ReturnCode_FileNotFound = 99999; @@ -308,4 +306,3 @@ static cc_result GetMachineID(cc_uint32* key) { Mem_Copy(key, MACHINE_KEY, sizeof(MACHINE_KEY) - 1); return 0; } -#endif diff --git a/src/Window_Saturn.c b/src/saturn/Window_Saturn.c similarity index 94% rename from src/Window_Saturn.c rename to src/saturn/Window_Saturn.c index 902cf4e39..c4ee28a94 100644 --- a/src/Window_Saturn.c +++ b/src/saturn/Window_Saturn.c @@ -1,16 +1,14 @@ -#include "Core.h" -#if defined CC_BUILD_SATURN -#include "Window.h" -#include "Platform.h" -#include "Input.h" -#include "Event.h" -#include "Graphics.h" -#include "String.h" -#include "Funcs.h" -#include "Bitmap.h" -#include "Errors.h" -#include "ExtMath.h" -#include "Logger.h" +#include "../Window.h" +#include "../Platform.h" +#include "../Input.h" +#include "../Event.h" +#include "../Graphics.h" +#include "../String.h" +#include "../Funcs.h" +#include "../Bitmap.h" +#include "../Errors.h" +#include "../ExtMath.h" + #include #include #include @@ -274,4 +272,3 @@ cc_result Window_OpenFileDialog(const struct OpenFileDialogArgs* args) { cc_result Window_SaveFileDialog(const struct SaveFileDialogArgs* args) { return ERR_NOT_SUPPORTED; } -#endif From 2741a33a155d6f041bd84a3085aa54870906fa32 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 10 Jul 2025 22:20:28 +1000 Subject: [PATCH 2/5] 3DS: Try to use VRAM for textures when possible --- .github/workflows/build_dreamcast.yml | 8 +- .github/workflows/build_msdos.yml | 7 +- .github/workflows/build_n64.yml | 7 +- .github/workflows/build_nds.yml | 7 +- .github/workflows/build_ps1.yml | 7 +- .github/workflows/build_ps2.yml | 5 +- .github/workflows/build_ps3.yml | 7 +- .github/workflows/build_psp.yml | 6 +- .github/workflows/build_saturn.yml | 7 +- .github/workflows/build_symbian.yml | 1 + .github/workflows/build_wiigc.yml | 1 - .github/workflows/build_xbox.yml | 5 +- .github/workflows/build_xbox360.yml | 7 +- src/3ds/Graphics_3DS.c | 70 +++++++-------- third_party/citro3d.c | 123 -------------------------- 15 files changed, 85 insertions(+), 183 deletions(-) diff --git a/.github/workflows/build_dreamcast.yml b/.github/workflows/build_dreamcast.yml index 809630752..059030acf 100644 --- a/.github/workflows/build_dreamcast.yml +++ b/.github/workflows/build_dreamcast.yml @@ -19,14 +19,18 @@ jobs: image: ghcr.io/kos-builds/kos-dc:sha-20149ee-14.2.0 steps: - uses: actions/checkout@v4 - - name: Compile Dreamcast build - id: compile + - name: Install prerequisites shell: bash run: | apt-get update apt-get -y install genisoimage wget https://github.com/ClassiCube/rpi-compiling-stuff/raw/main/cdi4dc -O /opt/toolchains/dc/kos/utils/cdi4dc chmod +x /opt/toolchains/dc/kos/utils/cdi4dc + + - name: Compile Dreamcast build + id: compile + shell: bash + run: | export PATH=/opt/toolchains/dc/kos/utils/:$PATH make dreamcast diff --git a/.github/workflows/build_msdos.yml b/.github/workflows/build_msdos.yml index 4607d115e..a6a80e141 100644 --- a/.github/workflows/build_msdos.yml +++ b/.github/workflows/build_msdos.yml @@ -19,11 +19,14 @@ jobs: image: ghcr.io/volkertb/debian-djgpp steps: - uses: actions/checkout@v4 - - name: Compile MS dos build - id: compile + - name: Install prerequisites run: | apt-get update apt-get -y install curl + + - name: Compile MS dos build + id: compile + run: | make CC=gcc dos RELEASE=1 diff --git a/.github/workflows/build_n64.yml b/.github/workflows/build_n64.yml index 5678b3c28..524264208 100644 --- a/.github/workflows/build_n64.yml +++ b/.github/workflows/build_n64.yml @@ -19,11 +19,14 @@ jobs: image: ghcr.io/dragonminded/libdragon:preview steps: - uses: actions/checkout@v4 - - name: Compile N64 build - id: compile + - name: Install prerequisites run: | apt-get update apt-get -y install curl + + - name: Compile N64 build + id: compile + run: | REAL_DIR=`pwd` cd /tmp git clone -b opengl https://github.com/DragonMinded/libdragon.git --depth=1 diff --git a/.github/workflows/build_nds.yml b/.github/workflows/build_nds.yml index 0d9fedcd5..9ffd175fd 100644 --- a/.github/workflows/build_nds.yml +++ b/.github/workflows/build_nds.yml @@ -19,11 +19,14 @@ jobs: image: skylyrac/blocksds:dev-latest steps: - uses: actions/checkout@v4 - - name: Compile NDS build - id: compile + - name: Install prerequisites run: | apt-get update apt-get -y install curl + + - name: Compile NDS build + id: compile + run: | make ds export BUILD_DSI=1 make ds diff --git a/.github/workflows/build_ps1.yml b/.github/workflows/build_ps1.yml index 0aa57190d..f96be84bf 100644 --- a/.github/workflows/build_ps1.yml +++ b/.github/workflows/build_ps1.yml @@ -19,11 +19,14 @@ jobs: image: ghcr.io/classicube/minimal-psn00b:latest steps: - uses: actions/checkout@v4 - - name: Compile PS1 build - id: compile + - name: Install prerequisites run: | apt-get update apt-get install -y curl + + - name: Compile PS1 build + id: compile + run: | export PSN00BSDK_ROOT=/usr/local/psnoob make ps1 diff --git a/.github/workflows/build_ps2.yml b/.github/workflows/build_ps2.yml index 248646694..432b0b374 100644 --- a/.github/workflows/build_ps2.yml +++ b/.github/workflows/build_ps2.yml @@ -19,10 +19,13 @@ jobs: image: ghcr.io/ps2dev/ps2sdk:latest steps: - uses: actions/checkout@v4 + - name: Install prerequisites + run: | + apk add make mpc1 curl + - name: Compile PS2 build id: compile run: | - apk add make mpc1 curl make ps2 diff --git a/.github/workflows/build_ps3.yml b/.github/workflows/build_ps3.yml index fd893a7bc..69bcba4af 100644 --- a/.github/workflows/build_ps3.yml +++ b/.github/workflows/build_ps3.yml @@ -19,11 +19,14 @@ jobs: image: ghcr.io/classicube/minimal-psl1ght:latest steps: - uses: actions/checkout@v4 - - name: Compile PS3 build - id: compile + - name: Install prerequisites run: | apt-get update apt-get install -y curl + + - name: Compile PS3 build + id: compile + run: | export PS3DEV=/usr/local/ps3dev export PSL1GHT=/usr/local/ps3dev export PATH=$PATH:$PS3DEV/bin diff --git a/.github/workflows/build_psp.yml b/.github/workflows/build_psp.yml index f932584e8..f87effee4 100644 --- a/.github/workflows/build_psp.yml +++ b/.github/workflows/build_psp.yml @@ -19,11 +19,13 @@ jobs: image: pspdev/pspdev:latest steps: - uses: actions/checkout@v4 + - name: Install prerequisites + run: | + apk add curl curl-dev + - name: Compile PSP build id: compile run: | - apk add curl curl-dev - export PSPSDK=$(psp-config --pspsdk-path) make psp diff --git a/.github/workflows/build_saturn.yml b/.github/workflows/build_saturn.yml index 3db14aa40..dba9c85b2 100644 --- a/.github/workflows/build_saturn.yml +++ b/.github/workflows/build_saturn.yml @@ -19,11 +19,14 @@ jobs: image: ijacquez/yaul:1.0.10 steps: - uses: actions/checkout@v4 - - name: Compile Saturn build - id: compile + - name: Install prerequisites run: | apt-get update apt-get -y install curl + + - name: Compile Saturn build + id: compile + run: | make saturn - uses: ./.github/actions/notify_failure diff --git a/.github/workflows/build_symbian.yml b/.github/workflows/build_symbian.yml index 8f9f76e6a..92c41a744 100644 --- a/.github/workflows/build_symbian.yml +++ b/.github/workflows/build_symbian.yml @@ -23,6 +23,7 @@ jobs: run: Invoke-WebRequest https://nnp.nnchan.ru/dl/symbiansr1_gcce_workflow.zip -OutFile symbiansdk.zip - name: Extract Symbian SDK run: Expand-Archive symbiansdk.zip -DestinationPath . + - name: Compile Symbian build id: compile run: | diff --git a/.github/workflows/build_wiigc.yml b/.github/workflows/build_wiigc.yml index 7ff45bb4c..3d6a6deb5 100644 --- a/.github/workflows/build_wiigc.yml +++ b/.github/workflows/build_wiigc.yml @@ -23,7 +23,6 @@ jobs: id: compile run: | make wii - make clean make gamecube - name: Create Wii homebrew diff --git a/.github/workflows/build_xbox.yml b/.github/workflows/build_xbox.yml index 371867d06..523ab31e0 100644 --- a/.github/workflows/build_xbox.yml +++ b/.github/workflows/build_xbox.yml @@ -19,10 +19,13 @@ jobs: image: ghcr.io/xboxdev/nxdk:git-e955705a steps: - uses: actions/checkout@v4 + - name: Install prerequisites + run: | + apk add curl curl-dev + - name: Compile Xbox build id: compile run: | - apk add curl curl-dev eval $(/usr/src/nxdk/bin/activate -s) make xbox diff --git a/.github/workflows/build_xbox360.yml b/.github/workflows/build_xbox360.yml index 0e40e1866..e562895d6 100644 --- a/.github/workflows/build_xbox360.yml +++ b/.github/workflows/build_xbox360.yml @@ -19,12 +19,15 @@ jobs: image: free60/libxenon steps: - uses: actions/checkout@v4 - - name: Compile 360 build - id: compile + - name: Install prerequisites run: | sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list apt-get update apt-get install -y curl + + - name: Compile 360 build + id: compile + run: | export DEVKITXENON=/usr/local/xenon export PATH=$PATH:$DEVKITXENON/bin:$DEVKITXENON/usr/bin make xbox360 diff --git a/src/3ds/Graphics_3DS.c b/src/3ds/Graphics_3DS.c index 7e0e4e922..dcc98c791 100644 --- a/src/3ds/Graphics_3DS.c +++ b/src/3ds/Graphics_3DS.c @@ -159,6 +159,13 @@ static void InitCitro3D(void) { C3D_RenderTargetColor(&bottomTarget, GPU_RB_RGBA8); C3D_RenderTargetSetOutput(&bottomTarget, GFX_BOTTOM, GFX_LEFT, DISPLAY_TRANSFER_FLAGS); + // Allocate right framebuffer (for stereoscopic 3D) in advance even when it doesn't actually used + // Although this means a bit less VRAM available for textures, this ensures that if the user later + // turns on stereoscopic 3D, don't have to try handling the case when insufficient VRAM for it + C3D_RenderTargetInit(&topTargetRight, 240, 400); + C3D_RenderTargetColor(&topTargetRight, GPU_RB_RGBA8); + C3D_RenderTargetDepth(&topTargetRight, GPU_RB_DEPTH24); + gfxSetDoubleBuffering(GFX_TOP, true); SetDefaultState(); AllocShaders(); @@ -178,6 +185,7 @@ void Gfx_Create(void) { Gfx.Created = true; gfx_vsync = true; + Gfx.NonPowTwoTexturesSupport = GFX_NONPOW2_UPLOAD; Gfx_RestoreState(); } @@ -239,9 +247,6 @@ void Gfx_Set3DRight(struct Matrix* proj, struct Matrix* view) { Calc3DProjection(+1, proj); if (!createdTopTargetRight) { - C3D_RenderTargetInit(&topTargetRight, 240, 400); - C3D_RenderTargetColor(&topTargetRight, GPU_RB_RGBA8); - C3D_RenderTargetDepth(&topTargetRight, GPU_RB_DEPTH24); C3D_RenderTargetSetOutput(&topTargetRight, GFX_TOP, GFX_RIGHT, DISPLAY_TRANSFER_FLAGS); createdTopTargetRight = true; } @@ -292,7 +297,13 @@ static void GPUTexture_Unref(GfxResourceID* resource) { } static void GPUTexture_Free(struct GPUTexture* tex) { - C3D_TexDelete(&tex->texture); + void* addr = tex->texture.data; + if (addrIsVRAM(addr)) { + vramFree(addr); + } else { + linearFree(addr); + } + Mem_Free(tex); } @@ -330,10 +341,13 @@ static void GPUTextures_DeleteUnreferenced(void) { /*########################################################################################################################* *---------------------------------------------------------Textures--------------------------------------------------------* *#########################################################################################################################*/ -static bool CreateNativeTexture(C3D_Tex* tex, u32 width, u32 height) { +static bool CreateNativeTexture(C3D_Tex* tex, u32 width, u32 height, int vram) { + width = Math_NextPowOf2(width); + height = Math_NextPowOf2(height); u32 size = width * height * 4; - //tex->data = p.onVram ? vramAlloc(total_size) : linearAlloc(total_size); - tex->data = linearAlloc(size); + + tex->data = vram ? vramAlloc(size) : NULL; + if (!tex->data) tex->data = linearAlloc(size); if (!tex->data) return false; tex->width = width; @@ -351,29 +365,6 @@ static bool CreateNativeTexture(C3D_Tex* tex, u32 width, u32 height) { return true; } -static void TryTransferToVRAM(C3D_Tex* tex) { - return; - // NOTE: the linearFree below results in broken texture. maybe no DMA? - void* vram = vramAlloc(tex->size); - if (!vram) return; - - C3D_SyncTextureCopy((u32*)tex->data, 0, (u32*)vram, 0, tex->size, 8); - linearFree(tex->data); - tex->data = vram; -} - -/*static inline cc_uint32 CalcZOrder(cc_uint32 x, cc_uint32 y) { - // Simplified "Interleave bits by Binary Magic Numbers" from - // http://graphics.stanford.edu/~seander/bithacks.html#InterleaveTableObvious - // TODO: Simplify to array lookup? - x = (x | (x << 2)) & 0x33; - x = (x | (x << 1)) & 0x55; - - y = (y | (y << 2)) & 0x33; - y = (y | (y << 1)) & 0x55; - - return x | (y << 1); -}*/ static inline cc_uint32 CalcZOrder(cc_uint32 a) { // Simplified "Interleave bits by Binary Magic Numbers" from // http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN @@ -390,28 +381,29 @@ static inline cc_uint32 CalcZOrder(cc_uint32 a) { // four 4x4 subtiles, which are in turn composed of four 2x2 subtiles static void ToMortonTexture(C3D_Tex* tex, int originX, int originY, struct Bitmap* bmp, int rowWidth) { - unsigned int pixel, mortonX, mortonY; + unsigned int mortonX, mortonY; unsigned int dstX, dstY, tileX, tileY; - int width = bmp->width, height = bmp->height; + int src_w = bmp->width, dst_w = tex->width; + int src_h = bmp->height, dst_h = tex->height; cc_uint32* dst = tex->data; cc_uint32* src = bmp->scan0; - for (int y = 0; y < height; y++) + for (int y = 0; y < src_h; y++) { - dstY = tex->height - 1 - (y + originY); + dstY = dst_h - 1 - (y + originY); tileY = dstY & ~0x07; mortonY = CalcZOrder(dstY & 0x07) << 1; - for (int x = 0; x < width; x++) + for (int x = 0; x < src_w; x++) { dstX = x + originX; tileX = dstX & ~0x07; mortonX = CalcZOrder(dstX & 0x07); - pixel = src[x + (y * rowWidth)]; - dst[(mortonX | mortonY) + (tileX * 8) + (tileY * tex->width)] = pixel; + dst[(mortonX | mortonY) + (tileX * 8) + (tileY * dst_w)] = src[x]; } + src += rowWidth; } // TODO flush data cache GSPGPU_FlushDataCache } @@ -419,11 +411,11 @@ static void ToMortonTexture(C3D_Tex* tex, int originX, int originY, GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { struct GPUTexture* tex = GPUTexture_Alloc(); - bool success = CreateNativeTexture(&tex->texture, bmp->width, bmp->height); + int can_vram = !(flags & TEXTURE_FLAG_DYNAMIC); + bool success = CreateNativeTexture(&tex->texture, bmp->width, bmp->height, can_vram); if (!success) return NULL; ToMortonTexture(&tex->texture, 0, 0, bmp, rowWidth); - if (!(flags & TEXTURE_FLAG_DYNAMIC)) TryTransferToVRAM(&tex->texture); return tex; } diff --git a/third_party/citro3d.c b/third_party/citro3d.c index fbe49684e..d81d3a550 100644 --- a/third_party/citro3d.c +++ b/third_party/citro3d.c @@ -97,66 +97,7 @@ typedef struct }; } C3D_Tex; -static void C3D_TexLoadImage(C3D_Tex* tex, const void* data, GPU_TEXFACE face, int level); -static void C3D_TexGenerateMipmap(C3D_Tex* tex, GPU_TEXFACE face); static void C3D_TexBind(int unitId, C3D_Tex* tex); -static void C3D_TexFlush(C3D_Tex* tex); -static void C3D_TexDelete(C3D_Tex* tex); - -static inline int C3D_TexCalcMaxLevel(u32 width, u32 height) -{ - return (31-__builtin_clz(width < height ? width : height)) - 3; // avoid sizes smaller than 8 -} - -static inline u32 C3D_TexCalcLevelSize(u32 size, int level) -{ - return size >> (2*level); -} - -static inline u32 C3D_TexCalcTotalSize(u32 size, int maxLevel) -{ - /* - S = s + sr + sr^2 + sr^3 + ... + sr^n - Sr = sr + sr^2 + sr^3 + ... + sr^(n+1) - S-Sr = s - sr^(n+1) - S(1-r) = s(1 - r^(n+1)) - S = s (1 - r^(n+1)) / (1-r) - - r = 1/4 - 1-r = 3/4 - - S = 4s (1 - (1/4)^(n+1)) / 3 - S = 4s (1 - 1/4^(n+1)) / 3 - S = (4/3) (s - s/4^(n+1)) - S = (4/3) (s - s/(1<<(2n+2))) - S = (4/3) (s - s>>(2n+2)) - */ - return (size - C3D_TexCalcLevelSize(size,maxLevel+1)) * 4 / 3; -} - -static inline void* C3D_TexGetImagePtr(C3D_Tex* tex, void* data, int level, u32* size) -{ - if (size) *size = level >= 0 ? C3D_TexCalcLevelSize(tex->size, level) : C3D_TexCalcTotalSize(tex->size, tex->maxLevel); - if (!level) return data; - return (u8*)data + (level > 0 ? C3D_TexCalcTotalSize(tex->size, level-1) : 0); -} - -static inline void* C3D_Tex2DGetImagePtr(C3D_Tex* tex, int level, u32* size) -{ - return C3D_TexGetImagePtr(tex, tex->data, level, size); -} - -static inline void C3D_TexUpload(C3D_Tex* tex, const void* data) -{ - C3D_TexLoadImage(tex, data, GPU_TEXFACE_2D, 0); -} - - - - - - - static void C3D_DepthMap(bool bIsZBuffer, float zScale, float zOffset); @@ -257,7 +198,6 @@ typedef enum static u32 C3D_CalcColorBufSize(u32 width, u32 height, GPU_COLORBUF fmt); static u32 C3D_CalcDepthBufSize(u32 width, u32 height, GPU_DEPTHBUF fmt); -static C3D_FrameBuf* C3D_GetFrameBuf(void); static void C3D_SetFrameBuf(C3D_FrameBuf* fb); static void C3D_FrameBufClear(C3D_FrameBuf* fb, C3D_ClearBits clearBits, u32 clearColor, u32 clearDepth); static void C3D_FrameBufTransfer(C3D_FrameBuf* fb, gfxScreen_t screen, gfx3dSide_t side, u32 transferFlags); @@ -337,8 +277,6 @@ static inline void C3D_RenderTargetClear(C3D_RenderTarget* target, C3D_ClearBits C3D_FrameBufClear(&target->frameBuf, clearBits, clearColor, clearDepth); } -static void C3D_SyncTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags); - @@ -818,14 +756,6 @@ static u32 C3D_CalcDepthBufSize(u32 width, u32 height, GPU_DEPTHBUF fmt) return size*(2+depthFmtSizes[fmt]); } -static C3D_FrameBuf* C3D_GetFrameBuf(void) -{ - C3D_Context* ctx = C3Di_GetContext(); - - ctx->flags |= C3DiF_FrameBuf; - return &ctx->fb; -} - static void C3D_SetFrameBuf(C3D_FrameBuf* fb) { C3D_Context* ctx = C3Di_GetContext(); @@ -1205,32 +1135,6 @@ static void C3D_RenderTargetSetOutput(C3D_RenderTarget* target, gfxScreen_t scre } } -static void C3Di_SafeTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags) -{ - C3Di_WaitAndClearQueue(-1); - inSafeTransfer = true; - GX_TextureCopy(inadr, indim, outadr, outdim, size, flags); - gxCmdQueueRun(&C3Di_GetContext()->gxQueue); -} - -static void C3D_SyncTextureCopy(u32* inadr, u32 indim, u32* outadr, u32 outdim, u32 size, u32 flags) -{ - if (inFrame) - { - C3D_FrameSplit(0); - GX_TextureCopy(inadr, indim, outadr, outdim, size, flags); - } else - { - C3Di_SafeTextureCopy(inadr, indim, outadr, outdim, size, flags); - gspWaitForPPF(); - } -} - - - - - - static void C3Di_TexEnvBind(int id, C3D_TexEnv* env) { @@ -1241,18 +1145,6 @@ static void C3Di_TexEnvBind(int id, C3D_TexEnv* env) - -static void C3D_TexLoadImage(C3D_Tex* tex, const void* data, GPU_TEXFACE face, int level) -{ - u32 size = 0; - void* out = C3D_TexGetImagePtr(tex, tex->data, level, &size); - - if (!addrIsVRAM(out)) - memcpy(out, data, size); - else - C3D_SyncTextureCopy((u32*)data, 0, (u32*)out, 0, size, 8); -} - static void C3D_TexBind(int unitId, C3D_Tex* tex) { C3D_Context* ctx = C3Di_GetContext(); @@ -1261,21 +1153,6 @@ static void C3D_TexBind(int unitId, C3D_Tex* tex) ctx->tex[unitId] = tex; } -static void C3D_TexFlush(C3D_Tex* tex) -{ - if (!addrIsVRAM(tex->data)) - GSPGPU_FlushDataCache(tex->data, C3D_TexCalcTotalSize(tex->size, tex->maxLevel)); -} - -static void C3D_TexDelete(C3D_Tex* tex) -{ - void* addr = tex->data; - if (addrIsVRAM(addr)) - vramFree(addr); - else - linearFree(addr); -} - static void C3Di_SetTex(int unit, C3D_Tex* tex) { u32 reg[10]; From 3ca40dae177d5a7f922e815396a726a02bdadc04 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 10 Jul 2025 23:28:01 +1000 Subject: [PATCH 3/5] Vita: Change DPAD to instead be for flying up/down and cycling hotbar slot 3DS: Use optimised twiddled index calculation --- src/3ds/Graphics_3DS.c | 61 +++++++++++++++++++++++--------------- src/psvita/Window_PSVita.c | 10 +++---- 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/3ds/Graphics_3DS.c b/src/3ds/Graphics_3DS.c index dcc98c791..9ec7dc877 100644 --- a/src/3ds/Graphics_3DS.c +++ b/src/3ds/Graphics_3DS.c @@ -365,44 +365,57 @@ static bool CreateNativeTexture(C3D_Tex* tex, u32 width, u32 height, int vram) { return true; } -static inline cc_uint32 CalcZOrder(cc_uint32 a) { - // Simplified "Interleave bits by Binary Magic Numbers" from - // http://graphics.stanford.edu/~seander/bithacks.html#InterleaveBMN - // TODO: Simplify to array lookup? - a = (a | (a << 2)) & 0x33; - a = (a | (a << 1)) & 0x55; - return a; - // equivalent to return (a & 1) | ((a & 2) << 1) | (a & 4) << 2; - // but compiles to less instructions -} - // Pixels are arranged in a recursive Z-order curve / Morton offset // They are arranged into 8x8 tiles, where each 8x8 tile is composed of // four 4x4 subtiles, which are in turn composed of four 2x2 subtiles +// http://problemkaputt.de/gbatek-3ds-video-texture-swizzling.htm +static CC_INLINE void TwiddleCalcFactors(unsigned w, unsigned h, + unsigned* maskX, unsigned* maskY) { + *maskX = 0b010101; // 3 interleaved X bits + *maskY = 0b101010; // 3 interleaved Y bits + + // Lower 3 X and Y bits are always interleaved + w >>= 4; + h >>= 4; + int shift = 6; + + for (; w > 0; w >>= 1) { + *maskX += 0x01 << shift; + shift += 1; + } + + for (; h > 0; h >>= 1) { + *maskY += 0x01 << shift; + shift += 1; + } +} + static void ToMortonTexture(C3D_Tex* tex, int originX, int originY, - struct Bitmap* bmp, int rowWidth) { - unsigned int mortonX, mortonY; - unsigned int dstX, dstY, tileX, tileY; - + struct Bitmap* bmp, int rowWidth) { int src_w = bmp->width, dst_w = tex->width; int src_h = bmp->height, dst_h = tex->height; cc_uint32* dst = tex->data; cc_uint32* src = bmp->scan0; + unsigned maskX, maskY; + TwiddleCalcFactors(dst_w, dst_h, &maskX, &maskY); + + unsigned begX = 0, begY = 0; + // Calculate start twiddled X and Y values + for (int x = 0; x < originX; x++) { begX = (begX - maskX) & maskX; } + for (int y = 0; y < originY; y++) { begY = (begY - maskY) & maskY; } + + unsigned Y = begY; for (int y = 0; y < src_h; y++) { - dstY = dst_h - 1 - (y + originY); - tileY = dstY & ~0x07; - mortonY = CalcZOrder(dstY & 0x07) << 1; - + unsigned X = begX; for (int x = 0; x < src_w; x++) { - dstX = x + originX; - tileX = dstX & ~0x07; - mortonX = CalcZOrder(dstX & 0x07); - - dst[(mortonX | mortonY) + (tileX * 8) + (tileY * dst_w)] = src[x]; + // need to flip image vertically + dst[X | (maskY - Y)] = src[x]; + X = (X - maskX) & maskX; } + Y = (Y - maskY) & maskY; src += rowWidth; } // TODO flush data cache GSPGPU_FlushDataCache diff --git a/src/psvita/Window_PSVita.c b/src/psvita/Window_PSVita.c index 6cc8e773d..eb4d09c05 100644 --- a/src/psvita/Window_PSVita.c +++ b/src/psvita/Window_PSVita.c @@ -142,10 +142,6 @@ void Window_DisableRawMouse(void) { Input.RawMode = false; } *-------------------------------------------------------Gamepads----------------------------------------------------------* *#########################################################################################################################*/ static const BindMapping vita_padbinds[BIND_COUNT] = { - [BIND_FORWARD] = { CCPAD_UP }, - [BIND_BACK] = { CCPAD_DOWN }, - [BIND_LEFT] = { CCPAD_LEFT }, - [BIND_RIGHT] = { CCPAD_RIGHT }, [BIND_JUMP] = { CCPAD_1 }, [BIND_SET_SPAWN] = { CCPAD_START }, [BIND_CHAT] = { CCPAD_4 }, @@ -154,10 +150,12 @@ static const BindMapping vita_padbinds[BIND_COUNT] = { [BIND_SPEED] = { CCPAD_2, CCPAD_L }, [BIND_NOCLIP] = { CCPAD_2, CCPAD_3 }, [BIND_FLY] = { CCPAD_2, CCPAD_R }, - [BIND_FLY_UP] = { CCPAD_2, CCPAD_UP }, - [BIND_FLY_DOWN] = { CCPAD_2, CCPAD_DOWN }, [BIND_PLACE_BLOCK] = { CCPAD_L }, [BIND_DELETE_BLOCK] = { CCPAD_R }, + [BIND_FLY_UP] = { CCPAD_UP }, + [BIND_FLY_DOWN] = { CCPAD_DOWN }, + [BIND_HOTBAR_LEFT] = { CCPAD_LEFT }, + [BIND_HOTBAR_RIGHT] = { CCPAD_RIGHT }, }; static cc_bool circle_main; From 07026d593c64bdd62ec21a6ac658fb42ce0bfd6f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Jul 2025 19:24:26 +1000 Subject: [PATCH 4/5] Refactor CopyTextureData to allow customising rows/pixelsPerRow --- src/Graphics_D3D9.c | 8 ++++++-- src/Graphics_N64.c | 20 +++++--------------- src/Graphics_SoftGPU.c | 11 +++++++---- src/Graphics_WiiU.c | 10 ++++++---- src/Graphics_Xbox360.c | 5 +++-- src/_GLShared.h | 5 +++-- src/_GraphicsBase.h | 12 +++++++----- src/ps2/Graphics_PS2.c | 10 ++++++---- src/psp/Graphics_PSP.c | 11 +++++++---- 9 files changed, 50 insertions(+), 42 deletions(-) diff --git a/src/Graphics_D3D9.c b/src/Graphics_D3D9.c index b42b34fc2..861ea6080 100644 --- a/src/Graphics_D3D9.c +++ b/src/Graphics_D3D9.c @@ -260,7 +260,9 @@ static void D3D9_SetTextureData(IDirect3DTexture9* texture, struct Bitmap* bmp, cc_result res = IDirect3DTexture9_LockRect(texture, lvl, &rect, NULL, 0); if (res) Process_Abort2(res, "D3D9_LockTextureData"); - CopyTextureData(rect.pBits, rect.Pitch, bmp, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(rect.pBits, rect.Pitch, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); res = IDirect3DTexture9_UnlockRect(texture, lvl); if (res) Process_Abort2(res, "D3D9_UnlockTextureData"); @@ -276,7 +278,9 @@ static void D3D9_SetTexturePartData(IDirect3DTexture9* texture, int x, int y, co res = IDirect3DTexture9_LockRect(texture, lvl, &rect, &part, 0); if (res) Process_Abort2(res, "D3D9_LockTexturePartData"); - CopyTextureData(rect.pBits, rect.Pitch, bmp, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(rect.pBits, rect.Pitch, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); res = IDirect3DTexture9_UnlockRect(texture, lvl); if (res) Process_Abort2(res, "D3D9_UnlockTexturePartData"); diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index 5b011cb6e..6b7a9061e 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -96,7 +96,7 @@ void Gfx_BeginFrame(void) { surface_t* disp = display_get(); rdpq_attach(disp, &zbuffer); - Platform_LogConst("GFX ctx beg"); + Platform_LogConst("== BEGIN frame"); } extern void __rdpq_autosync_change(int mode); @@ -120,9 +120,7 @@ void Gfx_ClearColor(PackedCol color) { } void Gfx_EndFrame(void) { - Platform_LogConst("GFX ctx end"); rdpq_detach_show(); - //Platform_LogConst("GFX END"); //rspq_profile_dump(); //rspq_profile_next_frame(); @@ -154,9 +152,7 @@ void Gfx_BindTexture(GfxResourceID texId) { static void UploadTexture(CCTexture* tex, rdpq_texparms_t* params) { rspq_block_begin(); - rdpq_tex_multi_begin(); rdpq_tex_upload(TILE0, &tex->surface, params); - rdpq_tex_multi_end(); tex->upload_block = rspq_block_end(); } @@ -189,8 +185,9 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, } } else { // 32 bpp can just be copied straight across - CopyTextureData(fb->buffer, fb->stride, - bmp, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(fb->buffer, fb->stride, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); } rdpq_texparms_t params = @@ -205,6 +202,7 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) { CCTexture* tex = (CCTexture*)texId; surface_t* fb = &tex->surface; + cc_uint32* src = (cc_uint32*)part->scan0 + x; cc_uint8* dst = (cc_uint8*)fb->buffer + (x * 4) + (y * fb->stride); @@ -214,14 +212,6 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i src + srcY * rowWidth, part->width * 4); } - - rdpq_texparms_t params = (rdpq_texparms_t){ - .s.repeats = REPEAT_INFINITE, - .t.repeats = REPEAT_INFINITE, - }; - - rdpq_call_deferred((void (*)(void*))rspq_block_free, tex->upload_block); - UploadTexture(tex, ¶ms); } void Gfx_DeleteTexture(GfxResourceID* texId) { diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index f0d40f27a..ded68ac82 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -106,8 +106,10 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, tex->width = bmp->width; tex->height = bmp->height; - CopyTextureData(tex->pixels, bmp->width * BITMAPCOLOR_SIZE, - bmp, rowWidth * BITMAPCOLOR_SIZE); + + CopyPixels(tex->pixels, bmp->width * BITMAPCOLOR_SIZE, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); return tex; } @@ -115,8 +117,9 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i CCTexture* tex = (CCTexture*)texId; BitmapCol* dst = (tex->pixels + x) + y * tex->width; - CopyTextureData(dst, tex->width * BITMAPCOLOR_SIZE, - part, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(dst, tex->width * BITMAPCOLOR_SIZE, + part->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); } void Gfx_EnableMipmaps(void) { } diff --git a/src/Graphics_WiiU.c b/src/Graphics_WiiU.c index 2ee95a51d..fec7b881f 100644 --- a/src/Graphics_WiiU.c +++ b/src/Graphics_WiiU.c @@ -207,8 +207,9 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, tex->surface.image = MEMAllocFromDefaultHeapEx(tex->surface.imageSize, tex->surface.alignment); if (!tex->surface.image) { Mem_Free(tex); return NULL; } - CopyTextureData(tex->surface.image, tex->surface.pitch << 2, - bmp, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(tex->surface.image, tex->surface.pitch << 2, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, tex->surface.image, tex->surface.imageSize); return tex; } @@ -217,8 +218,9 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i GX2Texture* tex = (GX2Texture*)texId; uint32_t* dst = (uint32_t*)tex->surface.image + (y * tex->surface.pitch) + x; - CopyTextureData(dst, tex->surface.pitch << 2, - part, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(dst, tex->surface.pitch << 2, + part->scan0, rowWidth * BITMAPCOLOR_SIZE, + part->width, part->height); GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, tex->surface.image, tex->surface.imageSize); } diff --git a/src/Graphics_Xbox360.c b/src/Graphics_Xbox360.c index 9c1e6f8d0..38a9cba8d 100644 --- a/src/Graphics_Xbox360.c +++ b/src/Graphics_Xbox360.c @@ -96,8 +96,9 @@ static void Gfx_RestoreState(void) { static void SetTextureData(struct XenosSurface* xtex, int x, int y, const struct Bitmap* bmp, int rowWidth, int lvl) { void* dst = Xe_Surface_LockRect(xe, xtex, x, y, bmp->width, bmp->height, XE_LOCK_WRITE); - CopyTextureData(dst, bmp->width * BITMAPCOLOR_SIZE, - bmp, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(dst, bmp->width * BITMAPCOLOR_SIZE, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); Xe_Surface_Unlock(xe, xtex); } diff --git a/src/_GLShared.h b/src/_GLShared.h index 55845f95a..978de97ec 100644 --- a/src/_GLShared.h +++ b/src/_GLShared.h @@ -163,8 +163,9 @@ static CC_NOINLINE void UpdateTextureSlow(int x, int y, struct Bitmap* part, int ptr = Mem_Alloc(count, 4, "Gfx_UpdateTexture temp"); } - CopyTextureData(ptr, part->width * BITMAPCOLOR_SIZE, - part, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(ptr, part->width * BITMAPCOLOR_SIZE, + part->scan0, rowWidth * BITMAPCOLOR_SIZE, + part->width, part->height); if (full) { CallTexImage2D(0, part->width, part->height, ptr); diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index aba23fff6..a4b404196 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -321,17 +321,19 @@ void Gfx_UpdateTexturePart(GfxResourceID texId, int x, int y, struct Bitmap* par Gfx_UpdateTexture(texId, x, y, part, part->width, mipmaps); } -static CC_INLINE void CopyTextureData(void* dst, int dstStride, const struct Bitmap* src, int srcStride) { - cc_uint8* src_ = (cc_uint8*)src->scan0; +static CC_INLINE void CopyPixels(void* dst, int dstStride, + const void* src, int srcStride, + int pixelsPerRow, int rows) { + cc_uint8* src_ = (cc_uint8*)src; cc_uint8* dst_ = (cc_uint8*)dst; int y; if (srcStride == dstStride) { - Mem_Copy(dst_, src_, Bitmap_DataSize(src->width, src->height)); + Mem_Copy(dst_, src_, Bitmap_DataSize(pixelsPerRow, rows)); } else { /* Have to copy scanline by scanline */ - for (y = 0; y < src->height; y++) { - Mem_Copy(dst_, src_, src->width * BITMAPCOLOR_SIZE); + for (y = 0; y < rows; y++) { + Mem_Copy(dst_, src_, pixelsPerRow * BITMAPCOLOR_SIZE); src_ += srcStride; dst_ += dstStride; } diff --git a/src/ps2/Graphics_PS2.c b/src/ps2/Graphics_PS2.c index 226da92e6..73200cd7a 100644 --- a/src/ps2/Graphics_PS2.c +++ b/src/ps2/Graphics_PS2.c @@ -377,8 +377,9 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, ConvertTexture_Palette((cc_uint8*)tex->pixels, bmp, rowWidth, palette, pal_count); } else { tex->format = GS_PSM_32; - CopyTextureData(tex->pixels, bmp->width * BITMAPCOLOR_SIZE, - bmp, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(tex->pixels, bmp->width * BITMAPCOLOR_SIZE, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); } return tex; } @@ -436,8 +437,9 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i CCTexture* tex = (CCTexture*)texId; BitmapCol* dst = (tex->pixels + x) + y * tex->width; - CopyTextureData(dst, tex->width * BITMAPCOLOR_SIZE, - part, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(dst, tex->width * BITMAPCOLOR_SIZE, + part->scan0, rowWidth * BITMAPCOLOR_SIZE, + part->width, part->height); } void Gfx_EnableMipmaps(void) { } diff --git a/src/psp/Graphics_PSP.c b/src/psp/Graphics_PSP.c index d93c2556d..3c5902df1 100644 --- a/src/psp/Graphics_PSP.c +++ b/src/psp/Graphics_PSP.c @@ -118,8 +118,10 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, tex->width = bmp->width; tex->height = bmp->height; - CopyTextureData(tex->pixels, bmp->width * BITMAPCOLOR_SIZE, - bmp, rowWidth * BITMAPCOLOR_SIZE); + + CopyPixels(tex->pixels, bmp->width * BITMAPCOLOR_SIZE, + bmp->scan0, rowWidth * BITMAPCOLOR_SIZE, + bmp->width, bmp->height); return tex; } @@ -127,8 +129,9 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i CCTexture* tex = (CCTexture*)texId; BitmapCol* dst = (tex->pixels + x) + y * tex->width; - CopyTextureData(dst, tex->width * BITMAPCOLOR_SIZE, - part, rowWidth * BITMAPCOLOR_SIZE); + CopyPixels(dst, tex->width * BITMAPCOLOR_SIZE, + part->scan0, rowWidth * BITMAPCOLOR_SIZE, + part->width, part->height); // TODO: Do line by line and only invalidate the actually changed parts of lines? sceKernelDcacheWritebackInvalidateRange(dst, (tex->width * part->height) * 4); } From 167f501a1ac1a41a44882b8414058b0b7f150022 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Fri, 11 Jul 2025 23:09:30 +1000 Subject: [PATCH 5/5] N64: Still enable Z when depth write is enabled --- misc/n64/gpu.c | 2 +- src/Graphics_N64.c | 15 +++++++++++---- src/Graphics_SoftGPU.c | 2 +- src/_GraphicsBase.h | 3 ++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/misc/n64/gpu.c b/misc/n64/gpu.c index b65fd63e1..eb5b33ec5 100644 --- a/misc/n64/gpu.c +++ b/misc/n64/gpu.c @@ -95,7 +95,7 @@ static int gpu_stride; #define GPU_ATTR_TEX (1 << 9) #define GPU_ATTR_SHADE (1 << 10) #define GPU_ATTR_EDGE (1 << 11) -static bool gpu_attr_z, gpu_attr_tex; +static uint8_t gpu_attr_z, gpu_attr_tex; static void gpuUpdateFormat(void) { diff --git a/src/Graphics_N64.c b/src/Graphics_N64.c index 6b7a9061e..1ea54c9d8 100644 --- a/src/Graphics_N64.c +++ b/src/Graphics_N64.c @@ -19,8 +19,8 @@ void Gfx_Create(void) { rspq_init(); //rspq_profile_start(); rdpq_init(); - //rdpq_debug_start(); // TODO debug - //rdpq_debug_log(true); + //rdpq_debug_start(); // TODO debug + //rdpq_debug_log(true); rdpq_set_mode_standard(); __rdpq_mode_change_som(SOM_TEXTURE_PERSP, SOM_TEXTURE_PERSP); @@ -96,7 +96,7 @@ void Gfx_BeginFrame(void) { surface_t* disp = display_get(); rdpq_attach(disp, &zbuffer); - Platform_LogConst("== BEGIN frame"); + //Platform_LogConst("== BEGIN frame"); } extern void __rdpq_autosync_change(int mode); @@ -251,14 +251,21 @@ static void SetColorWrite(cc_bool r, cc_bool g, cc_bool b, cc_bool a) { //gpuColorMask(r, g, b, a); TODO } +#define FLAG_Z_WRITE 0x02 void Gfx_SetDepthWrite(cc_bool enabled) { __rdpq_mode_change_som(SOM_Z_WRITE, enabled ? SOM_Z_WRITE : 0); + + gpu_attr_z &= ~FLAG_Z_WRITE; + gpu_attr_z |= enabled ? FLAG_Z_WRITE : 0; + gpuUpdateFormat(); } +#define FLAG_Z_READ 0x01 void Gfx_SetDepthTest(cc_bool enabled) { __rdpq_mode_change_som(SOM_Z_COMPARE, enabled ? SOM_Z_COMPARE : 0); - gpu_attr_z = enabled; + gpu_attr_z &= ~FLAG_Z_READ; + gpu_attr_z |= enabled ? FLAG_Z_READ : 0; gpuUpdateFormat(); } diff --git a/src/Graphics_SoftGPU.c b/src/Graphics_SoftGPU.c index ded68ac82..54c3cc413 100644 --- a/src/Graphics_SoftGPU.c +++ b/src/Graphics_SoftGPU.c @@ -119,7 +119,7 @@ void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, i CopyPixels(dst, tex->width * BITMAPCOLOR_SIZE, part->scan0, rowWidth * BITMAPCOLOR_SIZE, - bmp->width, bmp->height); + part->width, part->height); } void Gfx_EnableMipmaps(void) { } diff --git a/src/_GraphicsBase.h b/src/_GraphicsBase.h index a4b404196..7ad71ab29 100644 --- a/src/_GraphicsBase.h +++ b/src/_GraphicsBase.h @@ -332,7 +332,8 @@ static CC_INLINE void CopyPixels(void* dst, int dstStride, Mem_Copy(dst_, src_, Bitmap_DataSize(pixelsPerRow, rows)); } else { /* Have to copy scanline by scanline */ - for (y = 0; y < rows; y++) { + for (y = 0; y < rows; y++) + { Mem_Copy(dst_, src_, pixelsPerRow * BITMAPCOLOR_SIZE); src_ += srcStride; dst_ += dstStride;