commit fef3b086445b5179312c30d239656c556e18434f
Author: DPS2004 <dpsophinos@gmail.com>
AuthorDate: Tue Feb 15 18:48:45 2022 -0500
Commit: DPS2004 <dpsophinos@gmail.com>
CommitDate: Mon Apr 11 11:28:35 2022 -0400
load carts from appdata folder
---
Makefile | 12 ++-
platform/windows/Makefile | 119 ++++++++++++++++++++++++
platform/windows/source/SDL2Host.cpp | 174 +++++++++++++++++++++++++++++++++++
3 files changed, 302 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index e8db1b8..19d2add 100644
--- a/Makefile
+++ b/Makefile
@@ -15,11 +15,11 @@ export APP_VERSION = v$(V_MAJOR).$(V_MINOR).$(V_PATCH).$(V_BUILD)
export SOURCES = ../../source ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng ../../libs/simpleini ../../libs/miniz
export INCLUDES = ../../include ../../libs/z8lua ../../libs/utf8-util ../../libs/lodepng ../../libs/simpleini ../../libs/miniz
-.PHONY: all 3ds switch wiiu vita sdl2 sdl clean clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl
+.PHONY: all 3ds switch wiiu vita sdl2 sdl windows clean clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-windows
-all: 3ds switch wiiu vita bittboy
+all: 3ds switch wiiu vita bittboy windows
-clean: clean-tests clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-bittboy
+clean: clean-tests clean-3ds clean-switch clean-wiiu clean-vita clean-sdl2 clean-sdl clean-bittboy clean-windows
clean-3ds:
@$(MAKE) -C platform/3ds clean
@@ -45,6 +45,9 @@ clean-bittboy:
clean-miyoomini:
@$(MAKE) -C platform/miyoomini clean
+clean-windows:
+ @$(MAKE) -C platform/miyoomini clean
+
3ds:
@$(MAKE) -C platform/3ds
@@ -72,6 +75,9 @@ bittboy:
miyoomini:
@$(MAKE) -C platform/miyoomini
+windows:
+ @$(MAKE) -C platform/windows
+
clean-tests:
@$(MAKE) -C test clean
diff --git a/platform/windows/Makefile b/platform/windows/Makefile
new file mode 100644
index 0000000..d31a594
--- /dev/null
+++ b/platform/windows/Makefile
@@ -0,0 +1,119 @@
+
+#---------------------------------------------------------------------------------
+# TARGET is the name of the output
+# BUILD is the directory where object files & intermediate files will be placed
+# SOURCES is a list of directories containing source code
+# INCLUDES is a list of directories containing header files
+#
+#---------------------------------------------------------------------------------
+TARGET := FAKE08
+BUILD := build
+SOURCES := ${SOURCES} ../SDL2Common/source source
+INCLUDES := ${INCLUDES}
+
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+CC = $(CXX)
+
+CFLAGS := -g -Wall -Wno-deprecated -ffunction-sections -std=c++17 \
+ $(DEFINES)
+
+CFLAGS += $(INCLUDE) -DVER_STR=\"$(APP_VERSION)\"
+
+CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions
+#-std=gnu++11 was used before... not sure of difference
+
+LIBS := -lSDL2
+
+LDFLAGS := $(LIBS)
+
+
+#---------------------------------------------------------------------------------
+# no real need to edit anything past this point unless you need to add additional
+# rules for different file extensions
+#---------------------------------------------------------------------------------
+ifneq ($(BUILD),$(notdir $(CURDIR)))
+#---------------------------------------------------------------------------------
+
+export OUTPUT := $(CURDIR)/$(TARGET)
+export TOPDIR := $(CURDIR)
+
+export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
+ $(foreach dir,$(DATA),$(CURDIR)/$(dir))
+
+export DEPSDIR := $(CURDIR)/$(BUILD)
+
+CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
+CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+ export LD := $(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+ export LD := $(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+export OFILES_BIN := $(addsuffix .o,$(BINFILES))
+export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+export OFILES := $(OFILES_BIN) $(OFILES_SRC)
+export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
+
+export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
+ $(foreach dir,$(LIBDIRS),-I$(dir)/include) \
+ -I$(CURDIR)/$(BUILD)
+
+export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+
+
+.PHONY: $(BUILD) clean all
+
+#---------------------------------------------------------------------------------
+all: $(BUILD)
+
+$(BUILD):
+ @[ -d $@ ] || mkdir -p $@
+ @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+#---------------------------------------------------------------------------------
+clean:
+ @echo clean ...
+ @rm -fr $(BUILD) $(TARGET)
+
+
+#---------------------------------------------------------------------------------
+else
+.PHONY: all
+
+DEPENDS := $(OFILES:.o=.d)
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+all : $(OUTPUT)
+
+$(OUTPUT) : $(OFILES)
+ $(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
+
+$(OFILES_SRC) : $(HFILES_BIN)
+
+#---------------------------------------------------------------------------------
+# you need a rule like this for each extension you use as binary data
+#---------------------------------------------------------------------------------
+%.bin.o %_bin.h : %.bin
+#---------------------------------------------------------------------------------
+ @echo $(notdir $<)
+ @$(bin2o)
+
+-include $(DEPENDS)
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
diff --git a/platform/windows/source/SDL2Host.cpp b/platform/windows/source/SDL2Host.cpp
new file mode 100644
index 0000000..74bb4d1
--- /dev/null
+++ b/platform/windows/source/SDL2Host.cpp
@@ -0,0 +1,174 @@
+
+#include <stdio.h>
+#include <string.h>
+#include <dirent.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <fstream>
+#include <iostream>
+using namespace std;
+
+#include "../../SDL2Common/source/sdl2basehost.h"
+#include "../../../source/hostVmShared.h"
+#include "../../../source/nibblehelpers.h"
+#include "../../../source/filehelpers.h"
+#include "../../../source/logger.h"
+
+// sdl
+#include <SDL2/SDL.h>
+
+#define WINDOW_SIZE_X 1280
+#define WINDOW_SIZE_Y 720
+
+#define WINDOW_FLAGS 0
+
+#define RENDERER_FLAGS SDL_RENDERER_ACCELERATED
+#define PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
+
+SDL_Event event;
+
+
+string _desktopSdl2SettingsDir = "fake08";
+string _desktopSdl2SettingsPrefix = "fake08/";
+string _desktopSdl2customBiosLua = "cartpath = \"AppData\"\n"
+ "selectbtn = \"z\"\n"
+ "pausebtn = \"esc\"\n"
+ "exitbtn = \"close window\"\n"
+ "sizebtn = \"\"";
+
+Host::Host()
+{
+ struct stat st = {0};
+
+ int res = chdir(getenv("HOME"));
+ if (res == 0 && stat(_desktopSdl2SettingsDir.c_str(), &st) == -1) {
+ res = mkdir(_desktopSdl2SettingsDir.c_str(), 0777);
+ }
+
+ string cartdatadir = _desktopSdl2SettingsPrefix + "cdata";
+ if (res == 0 && stat(cartdatadir.c_str(), &st) == -1) {
+ res = mkdir(cartdatadir.c_str(), 0777);
+ }
+
+ std::string home = SDL_GetPrefPath("FAKE-08", "FAKE-08"); // C:\Users\(username)\AppData\Roaming\FAKE-08\FAKE-08\p8carts
+
+ std::string fullCartDir = home + "/p8carts";
+
+ setPlatformParams(
+ WINDOW_SIZE_X,
+ WINDOW_SIZE_Y,
+ WINDOW_FLAGS,
+ RENDERER_FLAGS,
+ PIXEL_FORMAT,
+ _desktopSdl2SettingsPrefix,
+ _desktopSdl2customBiosLua,
+ fullCartDir
+ );
+}
+
+
+InputState_t Host::scanInput(){
+ currKDown = 0;
+ currKHeld = 0;
+ stretchKeyPressed = false;
+
+ while (SDL_PollEvent(&event)) {
+ switch (event.type) {
+ case SDL_KEYDOWN:
+ switch (event.key.keysym.sym)
+ {
+ case SDLK_ESCAPE:currKDown |= P8_KEY_PAUSE; break;
+ case SDLK_LEFT: currKDown |= P8_KEY_LEFT; break;
+ case SDLK_RIGHT: currKDown |= P8_KEY_RIGHT; break;
+ case SDLK_UP: currKDown |= P8_KEY_UP; break;
+ case SDLK_DOWN: currKDown |= P8_KEY_DOWN; break;
+ case SDLK_z: currKDown |= P8_KEY_X; break;
+ case SDLK_x: currKDown |= P8_KEY_O; break;
+ case SDLK_c: currKDown |= P8_KEY_X; break;
+ case SDLK_r: stretchKeyPressed = true; break;
+ }
+ break;
+
+ case SDL_QUIT:
+ quit = 1;
+ break;
+ }
+ }
+
+ int mouseX = 0;
+ int mouseY = 0;
+ uint32_t sdlMouseBtnState = SDL_GetMouseState(&mouseX, &mouseY);
+ //adjust for scale
+ mouseX -= mouseOffsetX;
+ mouseY -= mouseOffsetY;
+ mouseX /= scaleX;
+ mouseY /= scaleY;
+ uint8_t picoMouseState = 0;
+ if (sdlMouseBtnState & SDL_BUTTON(SDL_BUTTON_LEFT)) {
+ picoMouseState |= 1;
+ }
+ if (sdlMouseBtnState & SDL_BUTTON(SDL_BUTTON_MIDDLE)) {
+ picoMouseState |= 4;
+ }
+ if (sdlMouseBtnState & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
+ picoMouseState |= 2;
+ }
+
+ const Uint8* keystate = SDL_GetKeyboardState(NULL);
+
+ //continuous-response keys
+ if(keystate[SDL_SCANCODE_LEFT]){
+ currKHeld |= P8_KEY_LEFT;
+ }
+ if(keystate[SDL_SCANCODE_RIGHT]){
+ currKHeld |= P8_KEY_RIGHT;;
+ }
+ if(keystate[SDL_SCANCODE_UP]){
+ currKHeld |= P8_KEY_UP;
+ }
+ if(keystate[SDL_SCANCODE_DOWN]){
+ currKHeld |= P8_KEY_DOWN;
+ }
+ if(keystate[SDL_SCANCODE_Z]){
+ currKHeld |= P8_KEY_X;
+ }
+ if(keystate[SDL_SCANCODE_X]){
+ currKHeld |= P8_KEY_O;
+ }
+ if(keystate[SDL_SCANCODE_C]){
+ currKHeld |= P8_KEY_X;
+ }
+
+ return InputState_t {
+ currKDown,
+ currKHeld,
+ (int16_t)mouseX,
+ (int16_t)mouseY,
+ picoMouseState
+ };
+}
+
+vector<string> Host::listcarts(){
+ vector<string> carts;
+
+ DIR *dir;
+ struct dirent *ent;
+ if ((dir = opendir (_cartDirectory.c_str())) != NULL) {
+ /* print all the files and directories within directory */
+ while ((ent = readdir (dir)) != NULL) {
+ if (isCartFile(ent->d_name)){
+ carts.push_back(ent->d_name);
+ }
+ }
+ closedir (dir);
+ } else {
+ /* could not open directory */
+ perror ("");
+ }
+
+ return carts;
+}
+