commit 44bed30da01f1d71594070fed9d12e72ee724dbe Author: Benjamin Date: Fri Feb 26 12:09:25 2021 +0100 add motor diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b14d2bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build-cg/* +*.g3a diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..370dbbb --- /dev/null +++ b/Makefile @@ -0,0 +1,208 @@ +#! /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 "$(TARGET_FX)" .g1a).elf +BIN_FX := $(ELF_FX:.elf=.bin) + +ELF_CG := build-cg/$(shell basename "$(TARGET_CG)" .g3a).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 $@ +build-cg/%.s.o: %.s + @ mkdir -p $(dir $@) + $(TOOLCHAIN_CG)-gcc -c $< -o $@ + +# Preprocessed assembler sources +build-fx/%.S.o: %.S + @ mkdir -p $(dir $@) + $(TOOLCHAIN_FX)-gcc -c $< -o $@ $(INCLUDE_FX) +build-cg/%.S.o: %.S + @ mkdir -p $(dir $@) + $(TOOLCHAIN_CG)-gcc -c $< -o $@ $(INCLUDE_CG) + +# 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.$*) + +# Custom conversions +build-fx/assets/%.o: assets-fx/% + @ mkdir -p $(dir $@) + fxconv --custom $< -o $@ $(FXCONVFX) type:$(subst /,,$(dir $*)) name:$(subst /,_,$(basename $*)) +build-cg/assets/%.o: assets-cg/% + @ mkdir -p $(dir $@) + fxconv --custom $< -o $@ $(FXCONVCG) type:$(subst /,,$(dir $*)) name:$(subst /,_,$(basename $*)) + +# +# 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) + @ while [[ ! -h /dev/Prizm1 ]]; do sleep 0.25; done + @ while ! mount /dev/Prizm1; do sleep 0.25; done + @ rm -f /mnt/prizm/$< + @ cp $< /mnt/prizm + @ umount /dev/Prizm1 + @- eject /dev/Prizm1 + +.PHONY: all all-fx all-cg clean distclean install-fx install-cg diff --git a/assets-cg/icon-cg-sel.png b/assets-cg/icon-cg-sel.png new file mode 100644 index 0000000..7137b50 Binary files /dev/null and b/assets-cg/icon-cg-sel.png differ diff --git a/assets-cg/icon-cg-uns.png b/assets-cg/icon-cg-uns.png new file mode 100644 index 0000000..3c99f62 Binary files /dev/null and b/assets-cg/icon-cg-uns.png differ diff --git a/assets-cg/img/1.png b/assets-cg/img/1.png new file mode 100644 index 0000000..458f21a Binary files /dev/null and b/assets-cg/img/1.png differ diff --git a/assets-cg/img/10.png b/assets-cg/img/10.png new file mode 100644 index 0000000..60c6204 Binary files /dev/null and b/assets-cg/img/10.png differ diff --git a/assets-cg/img/11.png b/assets-cg/img/11.png new file mode 100644 index 0000000..6d25b9d Binary files /dev/null and b/assets-cg/img/11.png differ diff --git a/assets-cg/img/2.png b/assets-cg/img/2.png new file mode 100644 index 0000000..7fa6380 Binary files /dev/null and b/assets-cg/img/2.png differ diff --git a/assets-cg/img/3.png b/assets-cg/img/3.png new file mode 100644 index 0000000..cc1eb51 Binary files /dev/null and b/assets-cg/img/3.png differ diff --git a/assets-cg/img/4.png b/assets-cg/img/4.png new file mode 100644 index 0000000..03eeda1 Binary files /dev/null and b/assets-cg/img/4.png differ diff --git a/assets-cg/img/5.png b/assets-cg/img/5.png new file mode 100644 index 0000000..2f10840 Binary files /dev/null and b/assets-cg/img/5.png differ diff --git a/assets-cg/img/6.png b/assets-cg/img/6.png new file mode 100644 index 0000000..548c751 Binary files /dev/null and b/assets-cg/img/6.png differ diff --git a/assets-cg/img/7.png b/assets-cg/img/7.png new file mode 100644 index 0000000..552b28a Binary files /dev/null and b/assets-cg/img/7.png differ diff --git a/assets-cg/img/8.png b/assets-cg/img/8.png new file mode 100644 index 0000000..1fcae03 Binary files /dev/null and b/assets-cg/img/8.png differ diff --git a/assets-cg/img/9.png b/assets-cg/img/9.png new file mode 100644 index 0000000..090dd11 Binary files /dev/null and b/assets-cg/img/9.png differ diff --git a/include/define.h b/include/define.h new file mode 100644 index 0000000..5fa31e1 --- /dev/null +++ b/include/define.h @@ -0,0 +1,3 @@ +#define tile 16 //width / 2 +#define level_width 10 +#define player_view 10 diff --git a/include/drawiso.h b/include/drawiso.h new file mode 100644 index 0000000..abc9aea --- /dev/null +++ b/include/drawiso.h @@ -0,0 +1,3 @@ +void draw_map_at(int map[], int taillex, int tailley, int width); +void draw_iso(int i, int j, int posx, int posy, bopti_image_t *image); +void draw_from_bottom(int i, int j, int posx, int posy, bopti_image_t *image, int height); diff --git a/project.cfg b/project.cfg new file mode 100644 index 0000000..78dd8c4 --- /dev/null +++ b/project.cfg @@ -0,0 +1,88 @@ +#--- +# fxSDK project configuration file for isometri +#--- + +# Project name, should be at most 8 bytes long. +# (You can also specify NAME_G1A or NAME_G3A to override individually.) +NAME := isometri + +# 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 := ISOME + +# 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-fx.png +# fx-CG 50 icon locations +ICON_CG_UNS = assets-cg/icon-cg-uns.png +ICON_CG_SEL = assets-cg/icon-cg-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 -Wno-missing-field-initializers -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 +INCLUDE_CG = -I include + +# 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 := +LIBS_CG := + +# 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 := + +# Additional platform-specific linker flags. +LDFLAGS_FX += -Wl,-Map=build-fx/map +LDFLAGS_CG += -Wl,-Map=build-cg/map + +#--- +# File conversion parameters +#--- + +# Here you can add fxconv options for each converted file, individually. +# The syntax is ".". For example, to specify the parameters for a +# font named "hexa.png", you might write: +# +# FONT.hexa.png = charset:print grid.size:3x5 grid.padding:1 diff --git a/src/drawiso.c b/src/drawiso.c new file mode 100644 index 0000000..41e42d5 --- /dev/null +++ b/src/drawiso.c @@ -0,0 +1,41 @@ +#include + +#include "drawiso.h" +#include "define.h" + +extern bopti_image_t img_1; +extern bopti_image_t img_2; +extern bopti_image_t img_3; +extern bopti_image_t img_9; + +void draw_map_at(int map[], int posx, int posy, int width) { + int j = 0; + int x = 0; + for(int i=0; i < width; i++) { + switch(map[i]) { + case 1: + draw_iso(x,j,posx,posy,&img_1); + break; + case 2: + draw_iso(x,j,posx,posy,&img_2); + break; + case 3: + draw_from_bottom(x,j,posx,posy,&img_3,16); + break; + case 9: + draw_iso(x,j,posx,posy,&img_9); + break; + } + x++; + if(!(i%level_width) && i != 0) { j++; x = 0; } + } + dupdate(); +} + +void draw_iso(int i, int j, int posx, int posy, bopti_image_t *image) { + dimage(posx+(-j*tile+i*tile),posy+((i*tile/2)+(j*tile/2)),image); +} + +void draw_from_bottom(int i, int j, int posx, int posy, bopti_image_t *image, int height) { + draw_iso(i,j,posx,posy-height,image); +} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..7e1ad26 --- /dev/null +++ b/src/main.c @@ -0,0 +1,30 @@ +#include +#include + +#include "drawiso.h" + +int main(void) +{ + dclear(C_WHITE); + int map[51] = + {9,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3r,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,3,2,1,3,0,0,1,1,0,0,9}; + + int x = 10; + int y = 10; + + while(1) + { + dclear(C_WHITE); + draw_map_at(map,x,y,51); + pollevent(); + if(keydown(KEY_EXIT)) + { + break; + } + if(keydown(KEY_RIGHT)) x+=3; + if(keydown(KEY_LEFT)) x-=3; + if(keydown(KEY_UP)) y-=3; + if(keydown(KEY_DOWN)) y+=3; + } + return 0; +}