diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index 8320b8b..a64f36a 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -1,16 +1,24 @@ { "configurations": [ { - "name": "Linux", + "name": "nspire", "includePath": [ - "${workspaceFolder}/**", + "/home/franchioping/NSpire/Nespire/**", "/home/franchioping/NSpire/Ndless/ndless-sdk/include/*" ], "defines": [], - "compilerPath": "/usr/bin/clang", + "compilerPath": "/home/franchioping/NSpire/Ndless/ndless-sdk/bin/nspire-gcc", "cStandard": "c17", "cppStandard": "c++17", - "intelliSenseMode": "linux-gcc-arm" + "compilerPathInCppPropertiesJson": "/home/franchioping/NSpire/Ndless/ndless-sdk/bin/nspire-gcc", + "mergeConfigurations": false, + "browse": { + "path": [ + "/home/franchioping/NSpire/Ndless/ndless-sdk/include/*", + "${workspaceFolder}" + ], + "limitSymbolsToIncludedHeaders": true + } } ], "version": 4 diff --git a/.vscode/settings.json b/.vscode/settings.json index c2462c1..ea35c0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,7 @@ { - "makefile.makefilePath": "" + "makefile.makefilePath": "", + "files.associations": { + "platform-nspire.h": "c", + "*.inc": "c" + } } \ No newline at end of file diff --git a/source/.buildver b/source/.buildver new file mode 100644 index 0000000..b8626c4 --- /dev/null +++ b/source/.buildver @@ -0,0 +1 @@ +4 diff --git a/source/Makefile b/source/Makefile index 124b661..ad359f7 100644 --- a/source/Makefile +++ b/source/Makefile @@ -1,22 +1,60 @@ -PREFIX=nspire- +DEBUG = FALSE -all: nes_emu.tns clean_p - @echo DONE +BLD_FILE ?= .buildver -nes_emu.tns : nespire.elf - genzehn --input $< --output $@ --name "nes_emu" - make-prg $@ ./nes_emu.prg.tns +# Initiate BLD_FILE if not exists +buildver_create := $(shell if ! test -f $(BLD_FILE); then echo 0 > $(BLD_FILE); fi) -nespire.elf : main.o cpu.o debug.o memory.o ppu.o rom.o menu.o - $(PREFIX)ld main.o cpu.o debug.o memory.o ppu.o rom.o menu.o -o $@ +# Prepare callable function. This function updates BLD_FILE +buildver = $(shell echo $$(($$(cat $(BLD_FILE)) + 1)) > $(BLD_FILE)) -%.o : %.S - $(PREFIX)gcc -Wall -W -marm -Os -c $< -o $@ +VER = buildver + +GCC = nspire-gcc +AS = nspire-as +GXX = nspire-g++ +LD = nspire-ld +GENZEHN = genzehn + +EXE = nespire$(shell cat $(BLD_FILE)) -clean_p: - @rm -f *.o nespire.elf +GCCFLAGS = -Wall -W -marm +LDFLAGS = +ZEHNFLAGS = --name "$(EXE)" + +ifeq ($(DEBUG),FALSE) + GCCFLAGS += -Os +else + GCCFLAGS += -O0 -g +endif + +OBJS = $(patsubst %.c, %.o, $(shell find . -name \*.c)) +OBJS += $(patsubst %.cpp, %.o, $(shell find . -name \*.cpp)) +OBJS += $(patsubst %.S, %.o, $(shell find . -name \*.S)) +DISTDIR = builds -clean: clean_p - @rm -f nes_emu.tns nes_emu.prg.tns +all:$(DISTDIR)/$(EXE).tns + +%.o: %.c + $(GCC) $(GCCFLAGS) -c $< -o $@ + +%.o: %.cpp + $(GXX) $(GCCFLAGS) -c $< -o $@ + +%.o: %.S + $(AS) -c $< -o $@ + +$(DISTDIR)/$(EXE).elf: $(OBJS) + mkdir -p $(DISTDIR) + $(LD) $^ -o $@ $(LDFLAGS) + +$(DISTDIR)/$(EXE).tns: $(DISTDIR)/$(EXE).elf + $(GENZEHN) --input $^ --output $@.zehn $(ZEHNFLAGS) + $(call buildver) + make-prg $@.zehn $@ + rm $@.zehn + +clean: + rm -f $(OBJS) diff --git a/source/builds/nespire2.elf b/source/builds/nespire2.elf new file mode 100755 index 0000000..f82b09e Binary files /dev/null and b/source/builds/nespire2.elf differ diff --git a/source/nes_emu.prg.tns b/source/builds/nespire2.tns similarity index 83% rename from source/nes_emu.prg.tns rename to source/builds/nespire2.tns index df80bd0..97fde8d 100644 Binary files a/source/nes_emu.prg.tns and b/source/builds/nespire2.tns differ diff --git a/testing/nespire_mod_5.elf b/source/builds/nespire3.elf similarity index 52% rename from testing/nespire_mod_5.elf rename to source/builds/nespire3.elf index 243373d..23e8b99 100755 Binary files a/testing/nespire_mod_5.elf and b/source/builds/nespire3.elf differ diff --git a/source/nes_emu.tns b/source/builds/nespire3.tns similarity index 81% rename from source/nes_emu.tns rename to source/builds/nespire3.tns index 2836f02..a473eb7 100644 Binary files a/source/nes_emu.tns and b/source/builds/nespire3.tns differ diff --git a/source/builds/nespire_mod_0.elf b/source/builds/nespire_mod_0.elf new file mode 100755 index 0000000..f82b09e Binary files /dev/null and b/source/builds/nespire_mod_0.elf differ diff --git a/source/builds/nespire_mod_0.tns b/source/builds/nespire_mod_0.tns new file mode 100644 index 0000000..b96bc99 Binary files /dev/null and b/source/builds/nespire_mod_0.tns differ diff --git a/source/builds/nespire_mod_1.elf b/source/builds/nespire_mod_1.elf new file mode 100755 index 0000000..f82b09e Binary files /dev/null and b/source/builds/nespire_mod_1.elf differ diff --git a/source/builds/nespire_mod_1.tns b/source/builds/nespire_mod_1.tns new file mode 100644 index 0000000..8cecd24 Binary files /dev/null and b/source/builds/nespire_mod_1.tns differ diff --git a/source/main.S b/source/main.S index af709f2..5a74c13 100644 --- a/source/main.S +++ b/source/main.S @@ -373,6 +373,8 @@ touchpad_read_input: .pool +.extern write_save_state + save_state: str lr, saved_state_cpu_status+56 adr lr, saved_state_cpu_status @@ -392,8 +394,11 @@ save_state: cmp r1, #0 bne sstate_loop - mov r0, #1 - str r0, save_state_exists + + + mov r0, saved_state_cpu_status + str r1, saved_state_cpu_cpsr + bl write_save_state ldr lr, saved_state_cpu_status+56 // subroutine return diff --git a/source/save_state.c b/source/save_state.c new file mode 100644 index 0000000..d76b361 --- /dev/null +++ b/source/save_state.c @@ -0,0 +1,25 @@ +#include +#include +#include +#include + + +#define s_SIZE 0x4600; + +void write_save_state(uint32_t saved_state_cpu_status_addr, uint32_t saved_state_cpu_cpsr); + +void write_save_state(uint32_t saved_state_cpu_status_addr, uint32_t saved_state_cpu_cpsr){ + size_t lenght = s_SIZE; + + size_t data_size = s_SIZE + sizeof(uint32_t); + uint32_t *data = malloc(data_size); + + + memcpy(data, saved_state_cpu_status_addr, lenght); + + data[data_size-1] = saved_state_cpu_cpsr; + + FILE* savefile = fopen("/documents/ndless/test.tns", "wb"); + fwrite(data, data_size, 1, savefile); + fclose(savefile); +} \ No newline at end of file diff --git a/source/save_state.o b/source/save_state.o new file mode 100644 index 0000000..09d7d11 Binary files /dev/null and b/source/save_state.o differ diff --git a/testing/.buildver b/testing/.buildver index 1e8b314..f599e28 100644 --- a/testing/.buildver +++ b/testing/.buildver @@ -1 +1 @@ -6 +10 diff --git a/testing/Makefile b/testing/Makefile index e0b1951..8ad730d 100644 --- a/testing/Makefile +++ b/testing/Makefile @@ -32,11 +32,10 @@ endif OBJS = $(patsubst %.c, %.o, $(shell find . -name \*.c)) OBJS += $(patsubst %.cpp, %.o, $(shell find . -name \*.cpp)) OBJS += $(patsubst %.S, %.o, $(shell find . -name \*.S)) -DISTDIR = . -vpath %.tns $(DISTDIR) -vpath %.elf $(DISTDIR) +DISTDIR = builds -all: $(EXE).tns + +all:$(DISTDIR)/$(EXE).tns %.o: %.c $(GCC) $(GCCFLAGS) -c $< -o $@ @@ -47,15 +46,15 @@ all: $(EXE).tns %.o: %.S $(AS) -c $< -o $@ -$(EXE).elf: $(OBJS) +$(DISTDIR)/$(EXE).elf: $(OBJS) mkdir -p $(DISTDIR) $(LD) $^ -o $@ $(LDFLAGS) -$(EXE).tns: $(EXE).elf +$(DISTDIR)/$(EXE).tns: $(DISTDIR)/$(EXE).elf $(GENZEHN) --input $^ --output $@.zehn $(ZEHNFLAGS) $(call buildver) make-prg $@.zehn $@ rm $@.zehn clean: - rm -f $(OBJS) $(DISTDIR)/$(EXE).tns $(DISTDIR)/$(EXE).elf $(DISTDIR)/$(EXE).zehn nespire_mod_*.elf nespire_mod_*.tns + rm -f $(OBJS) diff --git a/testing/builds/nespire_mod_7.elf b/testing/builds/nespire_mod_7.elf new file mode 100755 index 0000000..bc1e21a Binary files /dev/null and b/testing/builds/nespire_mod_7.elf differ diff --git a/testing/builds/nespire_mod_7.tns b/testing/builds/nespire_mod_7.tns new file mode 100644 index 0000000..02566a1 Binary files /dev/null and b/testing/builds/nespire_mod_7.tns differ diff --git a/testing/builds/nespire_mod_8.elf b/testing/builds/nespire_mod_8.elf new file mode 100755 index 0000000..bf18794 Binary files /dev/null and b/testing/builds/nespire_mod_8.elf differ diff --git a/testing/builds/nespire_mod_8.tns b/testing/builds/nespire_mod_8.tns new file mode 100644 index 0000000..4a65e6d Binary files /dev/null and b/testing/builds/nespire_mod_8.tns differ diff --git a/testing/builds/nespire_mod_9.elf b/testing/builds/nespire_mod_9.elf new file mode 100755 index 0000000..f200b6f Binary files /dev/null and b/testing/builds/nespire_mod_9.elf differ diff --git a/testing/builds/nespire_mod_9.tns b/testing/builds/nespire_mod_9.tns new file mode 100644 index 0000000..6c70e53 Binary files /dev/null and b/testing/builds/nespire_mod_9.tns differ diff --git a/testing/nespire_mod_5.tns b/testing/nespire_mod_5.tns deleted file mode 100644 index 9d10c29..0000000 Binary files a/testing/nespire_mod_5.tns and /dev/null differ diff --git a/testing/util.c b/testing/util.c index dd14451..55bf031 100644 --- a/testing/util.c +++ b/testing/util.c @@ -1,22 +1,24 @@ -#include -#include -#include -#include +#include #include +#include -void util_stuff(); +void util_stuff(int argc, char **argv); -int KEYS_TO_QUIT = 2; +void util_stuff(int argc, char **argv){ -void util_stuff(){ - - printf("Hello World!\n"); - puts("TEST"); - - - for(int i = 0; i < KEYS_TO_QUIT; i++){ - wait_key_pressed(); + // init console + nio_console console; + nio_init(&console, NIO_MAX_COLS , NIO_MAX_ROWS, 0, 0, NIO_COLOR_BLACK, NIO_COLOR_WHITE, true); + nio_set_default(&console); + nio_printf("test\n"); + nio_printf("argc: %d\n", argc); + for(int i = 0; i < argc; i++){ + nio_printf("arg %d: %s\n", i, argv[i]); } + + wait_key_pressed(); return; -} \ No newline at end of file +} + + diff --git a/testing/util.o b/testing/util.o index fc6df97..40c134c 100644 Binary files a/testing/util.o and b/testing/util.o differ