improve for out-of-tree usage

This commit is contained in:
Zack Buhman 2024-12-03 10:43:08 -06:00
parent 671fe92b12
commit e36735f6c2
7 changed files with 103 additions and 97 deletions

View File

@ -1,44 +1,14 @@
all: $(patsubst %.cpp,%.elf,$(wildcard example/*.cpp)) all: $(patsubst %.cpp,%.elf,$(wildcard example/*.cpp))
phony: include base.mk
example/arm/%.bin: phony
make -C example/arm $*.bin
include common.mk include common.mk
include headers.mk
geometry/%.hpp: geometry/%.obj MAKEFILE_PATH := $(patsubst %/,%,$(dir $(abspath $(firstword $(MAKEFILE_LIST)))))
PYTHONPATH=regs/gen python tools/obj_to_cpp.py $< > $@.tmp CFLAGS += -I$(MAKEFILE_PATH)
mv $@.tmp $@ LIB ?= $(MAKEFILE_PATH)
%.data.h: %.data include ip.mk
$(BUILD_BINARY_H)
%.data.pal.h: %.data.pal
$(BUILD_BINARY_H)
%.alpha.h: %.alpha
$(BUILD_BINARY_H)
%.alpha.o: %.alpha
$(BUILD_BINARY_O)
%.alpha.pal.h: %.alpha.pal
$(BUILD_BINARY_H)
%.alpha.pal.o: %.alpha.pal
$(BUILD_BINARY_O)
%.vq.h: %.vq
$(BUILD_BINARY_H)
%.vq.o: %.vq
$(BUILD_BINARY_O)
build-fonts:
./tools/ttf_outline 20 7f 20 0 little /usr/share/fonts/dejavu/DejaVuSans.ttf font/dejavusansmono/dejavusansmono.data
./tools/ttf_outline 20 7f 20 1 little /usr/share/fonts/dejavu/DejaVuSans.ttf font/dejavusansmono/dejavusansmono_mono.data
./tools/ttf_outline 20 7f 20 1 little /usr/share/fonts/terminus/ter-u20n.otb font/ter_u20n/ter_u20n.data
include example/example.mk include example/example.mk
include chess/chess.mk include chess/chess.mk

46
base.mk
View File

@ -34,19 +34,35 @@ define BUILD_BINARY_O
$< $@ $< $@
endef endef
makefile_path := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) makefile_path := $(dir $(abspath $(firstword $(MAKEFILE_LIST))))
makefile_relative = $(shell realpath --relative-to $(makefile_path) $(1)) makefile_relative = $(shell realpath --relative-to $(makefile_path) $(1))
as_obj_binary = _binary_$(subst .,_,$(subst /,_,$(subst .h,,$(call makefile_relative,$(1))))) as_obj_binary = _binary_$(subst .,_,$(subst /,_,$(subst .h,,$(call makefile_relative,$(1)))))
define BUILD_BINARY_H define BUILD_BINARY_H
@echo gen $(call makefile_relative,$@) @echo gen $(call makefile_relative,$@)
@echo '#pragma once' > $@ @echo '#pragma once' > $@
@echo '#include <cstdint>' >> $@ @echo '' >> $@
@echo '#include <stdint.h>' >> $@
@echo '' >> $@
@echo '#ifdef __cplusplus' >> $@
@echo 'extern "C" {' >> $@
@echo '#endif' >> $@
@echo '' >> $@
@echo 'extern uint32_t $(call as_obj_binary,$@)_start __asm("$(call as_obj_binary,$@)_start");' >> $@ @echo 'extern uint32_t $(call as_obj_binary,$@)_start __asm("$(call as_obj_binary,$@)_start");' >> $@
@echo 'extern uint32_t $(call as_obj_binary,$@)_end __asm("$(call as_obj_binary,$@)_end");' >> $@ @echo 'extern uint32_t $(call as_obj_binary,$@)_end __asm("$(call as_obj_binary,$@)_end");' >> $@
@echo 'extern uint32_t $(call as_obj_binary,$@)_size __asm("$(call as_obj_binary,$@)_size");' >> $@ @echo 'extern uint32_t $(call as_obj_binary,$@)_size __asm("$(call as_obj_binary,$@)_size");' >> $@
@echo '' >> $@
@echo '#ifdef __cplusplus' >> $@
@echo '}' >> $@
@echo '#endif' >> $@
endef endef
%.txt.o: %.txt
$(BUILD_BINARY_O)
%.txt.h: %.txt
$(BUILD_BINARY_H)
%.bin.o: %.bin %.bin.o: %.bin
$(BUILD_BINARY_O) $(BUILD_BINARY_O)
@ -56,9 +72,33 @@ endef
%.data.o: %.data %.data.o: %.data
$(BUILD_BINARY_O) $(BUILD_BINARY_O)
%.data.h: %.data
$(BUILD_BINARY_H)
%.data.pal.o: %.data.pal %.data.pal.o: %.data.pal
$(BUILD_BINARY_O) $(BUILD_BINARY_O)
%.data.pal.h: %.data.pal
$(BUILD_BINARY_H)
%.alpha.h: %.alpha
$(BUILD_BINARY_H)
%.alpha.o: %.alpha
$(BUILD_BINARY_O)
%.alpha.pal.h: %.alpha.pal
$(BUILD_BINARY_H)
%.alpha.pal.o: %.alpha.pal
$(BUILD_BINARY_O)
%.vq.h: %.vq
$(BUILD_BINARY_H)
%.vq.o: %.vq
$(BUILD_BINARY_O)
%.o: %.s %.o: %.s
$(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@ $(AS) $(AARCH) $(AFLAGS) $(DEBUG) $< -o $@
@ -69,7 +109,7 @@ endef
$(CXX) $(CARCH) $(CFLAGS) $(CXXFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ $(CXX) $(CARCH) $(CFLAGS) $(CXXFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@
%.elf: %.elf:
$(LD) $(LDFLAGS) -T $(LDSCRIPT) $^ -o $@ $(LD) $(LDFLAGS) -L $(LIB) -T $(LDSCRIPT) $^ -o $@
%.bin: %.elf %.bin: %.elf
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@

View File

@ -1,7 +1,3 @@
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
DIR := $(dir $(MAKEFILE_PATH))
LIB ?= .
OPT ?= -O2 OPT ?= -O2
GENERATED ?= GENERATED ?=
@ -9,7 +5,6 @@ AARCH = --isa=sh4 --little
CARCH = -m4-single-only -ml CARCH = -m4-single-only -ml
CFLAGS += -mfsca -funsafe-math-optimizations -ffast-math CFLAGS += -mfsca -funsafe-math-optimizations -ffast-math
CFLAGS += -I"$(dir $(MAKEFILE_PATH))"
CXXFLAGS += -std=c++23 CXXFLAGS += -std=c++23
@ -18,41 +13,18 @@ OBJARCH = -O elf32-shl -B sh4
TARGET = sh4-none-elf- TARGET = sh4-none-elf-
START_OBJ = \ START_OBJ = \
start.o \ $(LIB)/start.o \
runtime.o \ $(LIB)/runtime.o \
sh7091/cache.o $(LIB)/sh7091/cache.o
IP_OBJ = \ geometry/%.hpp: geometry/%.obj
systemid.o \ PYTHONPATH=regs/gen python tools/obj_to_cpp.py $< > $@.tmp
toc.o \ mv $@.tmp $@
sg/sg_sec.o \
sg_arejp.o \
sg_areus.o \
sg_areec.o \
sg_are00.o \
sg_are01.o \
sg_are02.o \
sg_are03.o \
sg_are04.o \
$(START_OBJ) \
example/serial_transfer.o \
sh7091/serial.o \
serial_load.o \
maple/maple.o \
font/portfolio_6x8/portfolio_6x8.data.o \
crc32.o
#sg_ini.o \
#aip.o
%.o: %.obj build-fonts:
$(OBJCOPY) -g \ ./tools/ttf_outline 20 7f 20 0 little /usr/share/fonts/dejavu/DejaVuSans.ttf font/dejavusansmono/dejavusansmono.data
--rename-section IP=.text.$* \ ./tools/ttf_outline 20 7f 20 1 little /usr/share/fonts/dejavu/DejaVuSans.ttf font/dejavusansmono/dejavusansmono_mono.data
$< $@ ./tools/ttf_outline 20 7f 20 1 little /usr/share/fonts/terminus/ter-u20n.otb font/ter_u20n/ter_u20n.data
ip.elf: $(IP_OBJ)
$(LD) --orphan-handling=error --print-memory-usage -T $(LIB)/ip.lds $^ -o $@
include base.mk
sine.pcm: common.mk sine.pcm: common.mk
sox \ sox \
@ -92,18 +64,18 @@ sine.pcm: common.mk
/=./pcm/ELEC.PCM \ /=./pcm/ELEC.PCM \
/=./pcm/ECCLESIA.PCM /=./pcm/ECCLESIA.PCM
include headers.mk
clean: clean:
find -P \ find -P \
-regextype posix-egrep \ -regextype posix-egrep \
-regex '.*\.(iso|o|d|bin|elf|cue|gch|scramble)$$' \ -regex '.*\.(iso|o|d|bin|elf|cue|gch|scramble)$$' \
-exec rm {} \; -exec rm {} \;
phony:
.SUFFIXES: .SUFFIXES:
.INTERMEDIATE: .INTERMEDIATE:
.SECONDARY: .SECONDARY:
.PHONY: all clean .PHONY: all clean phony
%: RCS/%,v %: RCS/%,v
%: RCS/% %: RCS/%

View File

@ -1,3 +1,6 @@
example/arm/%.bin: phony
make -C example/arm $*.bin
VIDEO_OUTPUT_OBJ = \ VIDEO_OUTPUT_OBJ = \
example/video_output.o \ example/video_output.o \
holly/video_output.o \ holly/video_output.o \

View File

@ -28,6 +28,8 @@
#include "model/sheik/material.h" #include "model/sheik/material.h"
#include "model/sheik/model.h" #include "model/sheik/model.h"
#include "memory.hpp"
void transfer_scene(float theta) void transfer_scene(float theta)
{ {
const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume const uint32_t parameter_control_word = para_control::para_type::polygon_or_modifier_volume
@ -122,23 +124,13 @@ void transfer_scene(float theta)
sq_transfer_32byte(ta_fifo_polygon_converter); sq_transfer_32byte(ta_fifo_polygon_converter);
} }
template <typename T>
inline void copy(T * dst, const T * src, const int32_t n) noexcept
{
int32_t n_t = n / (sizeof (T));
while (n_t > 0) {
*dst++ = *src++;
n_t--;
}
}
void texture_init() void texture_init()
{ {
int length = (sizeof (material)) / (sizeof (material[0])); int length = (sizeof (material)) / (sizeof (material[0]));
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
uint32_t offset = texture_memory_alloc::texture.start + material[i].pixel.vram_offset; uint32_t offset = texture_memory_alloc::texture.start + material[i].pixel.vram_offset;
copy<volatile uint32_t>(&texture_memory64[offset / 4], memory::copy<volatile uint32_t>(&texture_memory64[offset / 4],
reinterpret_cast<uint32_t *>(material[i].pixel.start), reinterpret_cast<uint32_t *>(material[i].pixel.start),
material[i].pixel.size); material[i].pixel.size);
} }

29
ip.mk Normal file
View File

@ -0,0 +1,29 @@
IP_OBJ = \
systemid.o \
toc.o \
sg/sg_sec.o \
sg_arejp.o \
sg_areus.o \
sg_areec.o \
sg_are00.o \
sg_are01.o \
sg_are02.o \
sg_are03.o \
sg_are04.o \
$(START_OBJ) \
example/serial_transfer.o \
sh7091/serial.o \
serial_load.o \
maple/maple.o \
font/portfolio_6x8/portfolio_6x8.data.o \
crc32.o
#sg_ini.o \
#aip.o
%.o: %.obj
$(OBJCOPY) -g \
--rename-section IP=.text.$* \
$< $@
ip.elf: $(IP_OBJ)
$(LD) --orphan-handling=error --print-memory-usage -T $(LIB)/ip.lds $^ -o $@

View File

@ -1,23 +1,23 @@
namespace memory { namespace memory {
template <typename T> template <typename T>
void move(T * dst, const T * src, const uint32_t n) void move(T * dst, const T * src, uint32_t n)
{ {
if (dst < src) { if (dst < src) {
while (n > 0) { while (n > 0) {
*d++ = *s++; *dst++ = *src++;
n--; n--;
} }
} else { } else {
while (n > 0) { while (n > 0) {
n--; n--;
d[n] = s[n]; dst[n] = src[n];
} }
} }
} }
template <typename T> template <typename T>
inline void copy(T * dst, const T * src, const uint32_t n) inline void copy(T * dst, const T * src, uint32_t n)
{ {
while (n > 0) { while (n > 0) {
*dst++ = *src++; *dst++ = *src++;