diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c3266f1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,123 @@ +# gintctl: gint's control application + +cmake_minimum_required(VERSION 3.18) +project(gintctl VERSION 2.2.1 LANGUAGES C ASM) + +include(GenerateG1A) +include(GenerateG3A) +include(Fxconv) + +find_package(Gint 2.1 REQUIRED) +find_package(LibProf 2.1 REQUIRED) +find_package(LibImg 2.1 REQUIRED) + +set(SOURCES + src/gintctl.c + src/menu.c + src/plot.c + src/util.c + src/gint/bopti.c + src/gint/dma.c + src/gint/dsp.c + src/gint/dsp.s + src/gint/dump.c + src/gint/gray.c + src/gint/hardware.c + src/gint/keyboard.c + src/gint/ram.c + src/gint/rtc.c + src/gint/spuram.c + src/gint/switch.c + src/gint/timer.c + src/gint/timer_callbacks.c + src/gint/tlb.c + src/gint/topti.c + src/libs/libimg.c + src/libs/memory.c + src/libs/openlibm.c + src/libs/printf.c + src/libs/tinymt.c + src/mem/mem.c + src/perf/cpucache.c + src/perf/cpucache.S + src/perf/interrupt.c + src/perf/libprof.c + src/perf/memory.c + src/perf/memory.s + src/perf/render.c + src/regs/regs.c +) +set(ASSETS_fx + assets-fx/fonts/hexa.png + assets-fx/fonts/uf5x7 + assets-fx/img/bopti_1col.png + assets-fx/img/bopti_2col.png + assets-fx/img/bopti_3col.png + assets-fx/img/keypress.png + assets-fx/img/keyrelease.png + assets-fx/img/libimg_swords.png + assets-fx/img/opt_dump.png + assets-fx/img/opt_gint_bopti.png + assets-fx/img/opt_gint_gray.png + assets-fx/img/opt_gint_ram.png + assets-fx/img/opt_gint_rtc.png + assets-fx/img/opt_gint_spuram.png + assets-fx/img/opt_gint_timer_callbacks.png + assets-fx/img/opt_gint_timers.png + assets-fx/img/opt_gint_tlb.png + assets-fx/img/opt_main.png + assets-fx/img/opt_mem.png + assets-fx/img/opt_perf_libprof.png + assets-fx/img/opt_perf_render.png + assets-fx/img/opt_switch_ctx.png + assets-fx/img/opt_switch_ctx_sh3.png + assets-fx/img/opt_switch.png + assets-fx/img/profile_gray_alpha.png + assets-fx/img/profile_gray.png + assets-fx/img/profile_mono_alpha.png + assets-fx/img/profile_mono.png + assets-fx/img/rtc_arrows.png + assets-fx/img/rtc_segments.png + assets-fx/img/tlb_cells.png +) +set(ASSETS_cg + assets-cg/fonts/font8x9_bold.png + assets-cg/img/applejack_31x27.png + assets-cg/img/applejack_36x25.png + assets-cg/img/kbd_pressed.png + assets-cg/img/kbd_released.png + assets-cg/img/libimg_even_odd.png + assets-cg/img/libimg_odd_even.png + assets-cg/img/libimg_sq_even.png + assets-cg/img/libimg_sq_odd.png + assets-cg/img/libimg_train.png + assets-cg/img/potion_17x22.png + assets-cg/img/potion_18x22.png + assets-cg/img/potion_21x22.png + assets-cg/img/rtc_arrows.png + assets-cg/img/rtc_segments.png + assets-cg/img/swift.png + assets-cg/img/swords.png +) + +fxconv_declare_assets(${ASSETS_fx} ${ASSETS_cg} WITH_METADATA) + +add_executable(gintctl ${SOURCES} ${ASSETS_${FXSDK_PLATFORM}}) + +target_compile_options(gintctl PRIVATE + -Wall -Wextra -Os) +target_link_options(gintctl PRIVATE + -Wl,-Map=map -Wl,--print-memory-usage) +target_include_directories(gintctl PRIVATE + "${CMAKE_CURRENT_SOURCE_DIR}/include" + "${FXSDK_COMPILER_INSTALL}/include/openlibm") +target_link_libraries(gintctl + Gint::Gint LibProf::LibProf LibImg::LibImg -lopenlibm) + +if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) + generate_g1a(TARGET gintctl OUTPUT "gintctl.g1a" + NAME "gintctl" INTERNAL "@GINTCTL" ICON assets-fx/icon.png) +elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) + generate_g3a(TARGET gintctl OUTPUT "gintctl.g3a" + NAME "" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) +endif() diff --git a/Makefile b/Makefile deleted file mode 100644 index 9bc53bb..0000000 --- a/Makefile +++ /dev/null @@ -1,198 +0,0 @@ -#! /usr/bin/make -f -# Default Makefile for fxSDK add-ins. This file was probably copied there by -# the [fxsdk] program. -#--- - -# -# Configuration -# - -include project.cfg - -# Compiler flags -CFLAGSFX = $(CFLAGS) $(CFLAGS_FX) $(INCLUDE_FX) -CFLAGSCG = $(CFLAGS) $(CFLAGS_CG) $(INCLUDE_CG) - -# Linker flags -LDFLAGSFX := $(LDFLAGS) $(LDFLAGS_FX) -LDFLAGSCG := $(LDFLAGS) $(LDFLAGS_CG) - -# Dependency list generation flags -depflags = -MMD -MT $@ -MF $(@:.o=.d) -MP -# ELF to binary flags -BINFLAGS := -R .bss -R .gint_bss - -# G1A and G3A generation flags -NAME_G1A ?= $(NAME) -NAME_G3A ?= $(NAME) -G1AF := -i "$(ICON_FX)" -n "$(NAME_G1A)" --internal="$(INTERNAL)" -G3AF := -n basic:"$(NAME_G3A)" -i uns:"$(ICON_CG_UNS)" -i sel:"$(ICON_CG_SEL)" - -ifeq "$(TOOLCHAIN_FX)" "" -TOOLCHAIN_FX := sh3eb-elf -endif - -ifeq "$(TOOLCHAIN_CG)" "" -TOOLCHAIN_CG := sh4eb-elf -endif - -# fxconv flags -FXCONVFX := --fx --toolchain=$(TOOLCHAIN_FX) -FXCONVCG := --cg --toolchain=$(TOOLCHAIN_CG) - -# Determine the compiler install and include path -GCC_BASE_FX := $(shell $(TOOLCHAIN_FX)-gcc --print-search-dirs | grep install | sed 's/install: //') -GCC_BASE_CG := $(shell $(TOOLCHAIN_CG)-gcc --print-search-dirs | grep install | sed 's/install: //') -GCC_INCLUDE_FX := $(GCC_BASE_FX)/include -GCC_INCLUDE_CG := $(GCC_BASE_CG)/include - -# -# File listings -# - -NULL := -TARGET := $(subst $(NULL) $(NULL),-,$(NAME)) - -ifeq "$(TARGET_FX)" "" -TARGET_FX := $(TARGET).g1a -endif - -ifeq "$(TARGET_CG)" "" -TARGET_CG := $(TARGET).g3a -endif - -ELF_FX := build-fx/$(shell basename -s .g1a $(TARGET_FX)).elf -BIN_FX := $(ELF_FX:.elf=.bin) - -ELF_CG := build-cg/$(shell basename -s .g3a $(TARGET_CG)).elf -BIN_CG := $(ELF_CG:.elf=.bin) - -# Source files -src := $(wildcard src/*.[csS] \ - src/*/*.[csS] \ - src/*/*/*.[csS] \ - src/*/*/*/*.[csS]) -assets-fx := $(wildcard assets-fx/*/*) -assets-cg := $(wildcard assets-cg/*/*) - -# Object files -obj-fx := $(src:%=build-fx/%.o) \ - $(assets-fx:assets-fx/%=build-fx/assets/%.o) -obj-cg := $(src:%=build-cg/%.o) \ - $(assets-cg:assets-cg/%=build-cg/assets/%.o) - -# Additional dependencies -deps-fx := $(ICON_FX) -deps-cg := $(ICON_CG_UNS) $(ICON_CG_SEL) - -# All targets -all := -ifneq "$(wildcard build-fx)" "" -all += all-fx -endif -ifneq "$(wildcard build-cg)" "" -all += all-cg -endif - -# -# Build rules -# - -all: $(all) - -all-fx: $(TARGET_FX) -all-cg: $(TARGET_CG) - -$(TARGET_FX): $(obj-fx) $(deps-fx) - @ mkdir -p $(dir $@) - $(TOOLCHAIN_FX)-gcc -o $(ELF_FX) $(obj-fx) $(CFLAGSFX) $(LDFLAGSFX) - $(TOOLCHAIN_FX)-objcopy -O binary $(BINFLAGS) $(ELF_FX) $(BIN_FX) - fxg1a $(BIN_FX) -o $@ $(G1AF) - -$(TARGET_CG): $(obj-cg) $(deps-cg) - @ mkdir -p $(dir $@) - $(TOOLCHAIN_CG)-gcc -o $(ELF_CG) $(obj-cg) $(CFLAGSCG) $(LDFLAGSCG) - $(TOOLCHAIN_CG)-objcopy -O binary $(BINFLAGS) $(ELF_CG) $(BIN_CG) - mkg3a $(G3AF) $(BIN_CG) $@ - -# C sources -build-fx/%.c.o: %.c - @ mkdir -p $(dir $@) - $(TOOLCHAIN_FX)-gcc -c $< -o $@ $(CFLAGSFX) $(depflags) -build-cg/%.c.o: %.c - @ mkdir -p $(dir $@) - $(TOOLCHAIN_CG)-gcc -c $< -o $@ $(CFLAGSCG) $(depflags) - -# Assembler sources -build-fx/%.s.o: %.s - @ mkdir -p $(dir $@) - $(TOOLCHAIN_FX)-gcc -c $< -o $@ -Wa,--dsp -build-cg/%.s.o: %.s - @ mkdir -p $(dir $@) - $(TOOLCHAIN_CG)-gcc -c $< -o $@ -Wa,--dsp - -# Preprocessed assembler sources -build-fx/%.S.o: %.S - @ mkdir -p $(dir $@) - $(TOOLCHAIN_FX)-gcc -c $< -o $@ $(INCLUDE_FX) -Wa,--dsp -build-cg/%.S.o: %.S - @ mkdir -p $(dir $@) - $(TOOLCHAIN_CG)-gcc -c $< -o $@ $(INCLUDE_CG) -Wa,--dsp - -# Images -build-fx/assets/img/%.o: assets-fx/img/% - @ mkdir -p $(dir $@) - fxconv --bopti-image $< -o $@ $(FXCONVFX) name:img_$(basename $*) $(IMG.$*) -build-cg/assets/img/%.o: assets-cg/img/% - @ mkdir -p $(dir $@) - fxconv --bopti-image $< -o $@ $(FXCONVCG) name:img_$(basename $*) $(IMG.$*) - -# Fonts -build-fx/assets/fonts/%.o: assets-fx/fonts/% - @ mkdir -p $(dir $@) - fxconv -f $< -o $@ $(FXCONVFX) name:font_$(basename $*) $(FONT.$*) -build-cg/assets/fonts/%.o: assets-cg/fonts/% - @ mkdir -p $(dir $@) - fxconv -f $< -o $@ $(FXCONVCG) name:font_$(basename $*) $(FONT.$*) - -# Binaries -build-fx/assets/bin/%.o: assets-fx/bin/% - @ mkdir -p $(dir $@) - fxconv -b $< -o $@ $(FXCONVFX) name:bin_$(basename $*) $(BIN.$*) -build-cg/assets/bin/%.o: assets-cg/bin/% - @ mkdir -p $(dir $@) - fxconv -b $< -o $@ $(FXCONVCG) name:bin_$(basename $*) $(BIN.$*) - -# -# Cleaning and utilities -# - -# Dependency information --include $(shell find build* -name *.d 2> /dev/null) -build-fx/%.d: ; -build-cg/%.d: ; -.PRECIOUS: build-fx build-cg build-fx/%.d build-cg/%.d %/ - -clean-fx: - @ rm -rf build-fx/ -clean-cg: - @ rm -rf build-cg/ - -distclean-fx: clean-fx - @ rm -f $(TARGET_FX) -distclean-cg: clean-cg - @ rm -f $(TARGET_CG) - -clean: clean-fx clean-cg - -distclean: distclean-fx distclean-cg - -install-fx: $(TARGET_FX) - p7 send -f $< -install-cg: $(TARGET_CG) - @ prizm-mount - @ rm -f /mnt/prizm/$< - @ cp $< /mnt/prizm - @ prizm-eject - -.PHONY: all all-fx all-cg clean distclean install-fx install-cg diff --git a/assets-cg/fonts/fxconv-metadata.txt b/assets-cg/fonts/fxconv-metadata.txt new file mode 100644 index 0000000..5609a79 --- /dev/null +++ b/assets-cg/fonts/fxconv-metadata.txt @@ -0,0 +1,8 @@ +font8x9_bold.png: + type: font + name: font_font8x9_bold + charset: print + grid.size: 8x11 + grid.padding: 1 + grid.border: 0 + proportional: true diff --git a/assets-cg/img/fxconv-metadata.txt b/assets-cg/img/fxconv-metadata.txt new file mode 100644 index 0000000..37bb681 --- /dev/null +++ b/assets-cg/img/fxconv-metadata.txt @@ -0,0 +1,15 @@ +*: + type: bopti-image + name_regex: (.*).png img_\1 + +libimg_*.png: + type: libimg-image + +swift.png: + profile: p4 +swords.png: + profile: p8 +kbd_pressed.png: + profile: p4 +kbd_released.png: + profile: p4 diff --git a/assets-cg/swift-half.png b/assets-cg/swift-half.png deleted file mode 100644 index 7a4fee4..0000000 Binary files a/assets-cg/swift-half.png and /dev/null differ diff --git a/assets-cg/swords2.png b/assets-cg/swords2.png deleted file mode 100644 index fb122ee..0000000 Binary files a/assets-cg/swords2.png and /dev/null differ diff --git a/assets-fx/fonts/fxconv-metadata.txt b/assets-fx/fonts/fxconv-metadata.txt new file mode 100644 index 0000000..c0613ab --- /dev/null +++ b/assets-fx/fonts/fxconv-metadata.txt @@ -0,0 +1,13 @@ +hexa.png: + type: font + name: font_hexa + charset: print + grid.size: 3x5 + grid.padding: 1 + +uf5x7: + type: font + name: font_uf5x7 + charset: unicode + grid.size: 5x7 + grid.padding: 1 diff --git a/assets-fx/img/fxconv-metadata.txt b/assets-fx/img/fxconv-metadata.txt new file mode 100644 index 0000000..189ae37 --- /dev/null +++ b/assets-fx/img/fxconv-metadata.txt @@ -0,0 +1,6 @@ +*: + type: bopti-image + name_regex: (.*)\.png img_\1 + +libimg_swords.png: + type: libimg-image diff --git a/assets-fx/pattern.png b/assets-fx/pattern.png deleted file mode 100644 index 24c799f..0000000 Binary files a/assets-fx/pattern.png and /dev/null differ diff --git a/assets-fx/pattern2.png b/assets-fx/pattern2.png deleted file mode 100644 index 364d1e2..0000000 Binary files a/assets-fx/pattern2.png and /dev/null differ diff --git a/project.cfg b/project.cfg deleted file mode 100644 index 8f31e8a..0000000 --- a/project.cfg +++ /dev/null @@ -1,103 +0,0 @@ -#--- -# fxSDK project configuration file for gintctl -#--- - -# Project name, should be at most 8 bytes long. -# (You can also specify NAME_G1A or NAME_G3A to override individually.) -NAME := gintctl -NAME_G3A := - -# Internal name, should be '@' followed by at most 7 uppercase letters. -# WARNING: If this convention is not followed, the add-in might not appear in -# the main menu of the calculator! -INTERNAL := @GINTCTL - -# Output file name. The default is to take , replace spaces with dashes, -# and add .g1a (or .g3a). You can specify a different folder if you want. -TARGET_FX := -TARGET_CG := - -# fx-9860G icon location -ICON_FX = assets-fx/icon.png -# fx-CG 50 icon locations -ICON_CG_UNS = assets-cg/icon-uns.png -ICON_CG_SEL = assets-cg/icon-sel.png - -#--- -# Toolchain selection -#--- - -# Toolchain for fx9860g. Please see also CFLAGS_FX below. -TOOLCHAIN_FX := sh-elf - -# Toolchain for fxcg50. Please see also CFLAGS_CG below. -TOOLCHAIN_CG := sh-elf - -#--- -# Compiler flags -#--- - -# Base compiler flags for the fxSDK, you usually want to keep these. -CFLAGS := -mb -ffreestanding -nostdlib -fstrict-volatile-bitfields - -# Platform-specific compiler flags. -# <> If you are using sh3eb-elf, use -m3. (You can do this on both FX and CG.) -# <> If you are using sh4eb-elf, use -m4-nofpu. (Not ideal on FX but works.) -# <> If you are using sh4eb-nofpu-elf, then your compiler will likely use the -# FPU and cause problems on the calculator. Consider another configuration. -# <> If you are using an sh-elf with several targets, specify whichever you -# support. I recommend -m3 on FX and -m4-nofpu on CG. -# Please see also TOOLCHAIN_FX and TOOLCHAIN_CG above. -CFLAGS_FX := -D FX9860G -m3 -CFLAGS_CG := -D FXCG50 -m4-nofpu - -# Additional compiler flags, change to your own taste! -CFLAGS += -Wall -Wextra -Os - -# Include paths. Add one -I option for each folder from which you want to -# be able to include files with #include<>. The Makefile provides a variable -# GCC_INCLUDE_FX/GCC_INCLUDE_CG that represents the default include folder, -# which is useful for some libraries such as OpenLibm. -INCLUDE_FX = -I include -I $(GCC_INCLUDE_FX)/openlibm -INCLUDE_CG = -I include -I $(GCC_INCLUDE_CG)/openlibm - -# Libraries. Add one -l option for each library you are using, and also -# suitable -L options if you have library files in custom folders. To use -# fxlib, add libfx.a to the project directory and use "-L . -lfx". -LIBS_FX := -lprof -limg-fx -lopenlibm -LIBS_CG := -lprof -limg-cg -lopenlibm - -# Base linker flags for the fxSDK, you usually want to keep these. -LDFLAGS_FX := -T fx9860g.ld -lgint-fx $(LIBS_FX) -lgint-fx -lgcc -LDFLAGS_CG := -T fxcg50.ld -lgint-cg $(LIBS_CG) -lgint-cg -lgcc - -# Additional linker flags, if you need any. -LDFLAGS := -Wl,--print-memory-usage - -# Additional platform-specific linker flags. -LDFLAGS_FX += -Wl,-Map=build-fx/map -LDFLAGS_CG += -Wl,-Map=build-cg/map - -#--- -# File conversion parameters -#--- - -# Parameters for the hexadecimal font on fx9860g -FONT.hexa.png = charset:print grid.size:3x5 grid.padding:1 -FONT.font8x9_bold.png = charset:print grid.size:8x11 grid.padding:1 \ - grid.border:0 proportional:true -FONT.uf5x7 = charset:unicode grid.size:5x7 grid.padding:1 - -IMG.swift.png = profile:p4 -IMG.swords.png = profile:p8 - -IMG.kbd_pressed.png = profile:p4 -IMG.kbd_released.png = profile:p4 - -IMG.libimg_even_odd.png = type:libimg-image -IMG.libimg_odd_even.png = type:libimg-image -IMG.libimg_sq_even.png = type:libimg-image -IMG.libimg_sq_odd.png = type:libimg-image -IMG.libimg_train.png = type:libimg-image - -IMG.libimg_swords.png = type:libimg-image