foxygit / fake-08-xbox360 Log in
commit d08e6c1df0452ecc92278b572e0eb443a67fe2eb
Author:     Jon Bell <jondbell@protonmail.com>
AuthorDate: Tue Apr 7 23:04:43 2020 -0600
Commit:     Jon Bell <jondbell@protonmail.com>
CommitDate: Tue Apr 7 23:04:43 2020 -0600

    Initial commit. Rect fill sort of working
---
 .gitignore             |   6 ++
 Makefile               | 255 +++++++++++++++++++++++++++++++++++++++++++++++++
 oldsource/main.cpp.bak |  50 ++++++++++
 source/fakecart.c      |   8 ++
 source/fakecart.h      |   1 +
 source/graphics.c      | 126 ++++++++++++++++++++++++
 source/graphics.h      |  36 +++++++
 source/main.c          |  54 +++++++++++
 8 files changed, 536 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7257fd2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*.3dsx
+*.elf
+*.smdh
+bin/
+.vscode/
+build/
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a86e57e
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,255 @@
+#---------------------------------------------------------------------------------
+.SUFFIXES:
+#---------------------------------------------------------------------------------
+
+ifeq ($(strip $(DEVKITARM)),)
+$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
+endif
+
+TOPDIR ?= $(CURDIR)
+include $(DEVKITARM)/3ds_rules
+
+#---------------------------------------------------------------------------------
+# 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
+# DATA is a list of directories containing data files
+# INCLUDES is a list of directories containing header files
+# GRAPHICS is a list of directories containing graphics files
+# GFXBUILD is the directory where converted graphics files will be placed
+#   If set to $(BUILD), it will statically link in the converted
+#   files as if they were data files.
+#
+# NO_SMDH: if set to anything, no SMDH file is generated.
+# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional)
+# APP_TITLE is the name of the app stored in the SMDH file (Optional)
+# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
+# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
+# ICON is the filename of the icon (.png), relative to the project folder.
+#   If not set, it attempts to use one of the following (in this order):
+#     - <Project name>.png
+#     - icon.png
+#     - <libctru folder>/default_icon.png
+#---------------------------------------------------------------------------------
+TARGET		:=	$(notdir $(CURDIR))
+BUILD		:=	build
+SOURCES		:=	source
+DATA		:=	data
+INCLUDES	:=	include
+GRAPHICS	:=	gfx
+GFXBUILD	:=	$(BUILD)
+#ROMFS		:=	romfs
+#GFXBUILD	:=	$(ROMFS)/gfx
+
+#---------------------------------------------------------------------------------
+# options for code generation
+#---------------------------------------------------------------------------------
+ARCH	:=	-march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft
+
+CFLAGS	:=	-g -Wall -O2 -mword-relocations \
+			-fomit-frame-pointer -ffunction-sections \
+			$(ARCH)
+
+CFLAGS	+=	$(INCLUDE) -DARM11 -D_3DS
+
+CXXFLAGS	:= $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
+
+ASFLAGS	:=	-g $(ARCH)
+LDFLAGS	=	-specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
+
+LIBS	:= -lctru -lm
+
+#---------------------------------------------------------------------------------
+# list of directories containing libraries, this must be the top level containing
+# include and lib
+#---------------------------------------------------------------------------------
+LIBDIRS	:= $(CTRULIB)
+
+
+#---------------------------------------------------------------------------------
+# 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,$(GRAPHICS),$(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)))
+SFILES		:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
+PICAFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
+SHLISTFILES	:=	$(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
+GFXFILES	:=	$(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s)))
+BINFILES	:=	$(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
+
+#---------------------------------------------------------------------------------
+# use CXX for linking C++ projects, CC for standard C
+#---------------------------------------------------------------------------------
+ifeq ($(strip $(CPPFILES)),)
+#---------------------------------------------------------------------------------
+	export LD	:=	$(CC)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+	export LD	:=	$(CXX)
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+#---------------------------------------------------------------------------------
+ifeq ($(GFXBUILD),$(BUILD))
+#---------------------------------------------------------------------------------
+export T3XFILES :=  $(GFXFILES:.t3s=.t3x)
+#---------------------------------------------------------------------------------
+else
+#---------------------------------------------------------------------------------
+export ROMFS_T3XFILES	:=	$(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES))
+export T3XHFILES		:=	$(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES))
+#---------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------
+
+export OFILES_SOURCES 	:=	$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
+
+export OFILES_BIN	:=	$(addsuffix .o,$(BINFILES)) \
+			$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \
+			$(addsuffix .o,$(T3XFILES))
+
+export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
+
+export HFILES	:=	$(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \
+			$(addsuffix .h,$(subst .,_,$(BINFILES))) \
+			$(GFXFILES:.t3s=.h)
+
+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)
+
+export _3DSXDEPS	:=	$(if $(NO_SMDH),,$(OUTPUT).smdh)
+
+ifeq ($(strip $(ICON)),)
+	icons := $(wildcard *.png)
+	ifneq (,$(findstring $(TARGET).png,$(icons)))
+		export APP_ICON := $(TOPDIR)/$(TARGET).png
+	else
+		ifneq (,$(findstring icon.png,$(icons)))
+			export APP_ICON := $(TOPDIR)/icon.png
+		endif
+	endif
+else
+	export APP_ICON := $(TOPDIR)/$(ICON)
+endif
+
+ifeq ($(strip $(NO_SMDH)),)
+	export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
+endif
+
+ifneq ($(ROMFS),)
+	export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS)
+endif
+
+.PHONY: all clean
+
+#---------------------------------------------------------------------------------
+all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES)
+	@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
+$(BUILD):
+	@mkdir -p $@
+
+ifneq ($(GFXBUILD),$(BUILD))
+$(GFXBUILD):
+	@mkdir -p $@
+endif
+
+ifneq ($(DEPSDIR),$(BUILD))
+$(DEPSDIR):
+	@mkdir -p $@
+endif
+
+#---------------------------------------------------------------------------------
+clean:
+	@echo clean ...
+	@rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD)
+
+#---------------------------------------------------------------------------------
+$(GFXBUILD)/%.t3x	$(BUILD)/%.h	:	%.t3s
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x
+
+#---------------------------------------------------------------------------------
+else
+
+#---------------------------------------------------------------------------------
+# main targets
+#---------------------------------------------------------------------------------
+$(OUTPUT).3dsx	:	$(OUTPUT).elf $(_3DSXDEPS)
+
+$(OFILES_SOURCES) : $(HFILES)
+
+$(OUTPUT).elf	:	$(OFILES)
+
+#---------------------------------------------------------------------------------
+# you need a rule like this for each extension you use as binary data
+#---------------------------------------------------------------------------------
+%.bin.o	%_bin.h :	%.bin
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+#---------------------------------------------------------------------------------
+.PRECIOUS	:	%.t3x
+#---------------------------------------------------------------------------------
+%.t3x.o	%_t3x.h :	%.t3x
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@$(bin2o)
+
+#---------------------------------------------------------------------------------
+# rules for assembling GPU shaders
+#---------------------------------------------------------------------------------
+define shader-as
+	$(eval CURBIN := $*.shbin)
+	$(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
+	echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
+	echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
+	echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
+	echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
+	picasso -o $(CURBIN) $1
+	bin2s $(CURBIN) | $(AS) -o $*.shbin.o
+endef
+
+%.shbin.o %_shbin.h : %.v.pica %.g.pica
+	@echo $(notdir $^)
+	@$(call shader-as,$^)
+
+%.shbin.o %_shbin.h : %.v.pica
+	@echo $(notdir $<)
+	@$(call shader-as,$<)
+
+%.shbin.o %_shbin.h : %.shlist
+	@echo $(notdir $<)
+	@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))
+
+#---------------------------------------------------------------------------------
+%.t3x	%.h	:	%.t3s
+#---------------------------------------------------------------------------------
+	@echo $(notdir $<)
+	@tex3ds -i $< -H $*.h -d $*.d -o $*.t3x
+
+-include $(DEPSDIR)/*.d
+
+#---------------------------------------------------------------------------------------
+endif
+#---------------------------------------------------------------------------------------
diff --git a/oldsource/main.cpp.bak b/oldsource/main.cpp.bak
new file mode 100644
index 0000000..4cf8c93
--- /dev/null
+++ b/oldsource/main.cpp.bak
@@ -0,0 +1,50 @@
+#ifndef M_PI
+    #define M_PI 3.14159265358979323846
+#endif
+
+#include <3ds.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+int main()
+{
+  int time = 0;
+
+	gfxInitDefault();
+
+	while (aptMainLoop())
+	{
+		gspWaitForVBlank();
+		hidScanInput();
+
+		u32 keysPressed = hidKeysDown();
+		if (keysPressed & KEY_START)
+			break;
+
+		u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
+
+		memset(fb, 0, 240*400*3);
+
+    int x, y;
+    for(x = 0; x < 400; x++) {
+      for(y = 0; y < 240; y++) {
+        float b = (((sin(y*sin(time/40.0)*M_PI*10.0/400.0)+1)/4) + ((sin(x*sin(time/77.0)*M_PI*13.0/400.0)+1)/4));
+        float g = (((sin(y*sin(time/53.0)*M_PI*23.0/400.0)+1)/4) + ((sin(x*sin(time/97.0)*M_PI*17.0/400.0)+1)/4));
+        float r = (((sin(y*sin(time/27.0)*M_PI*17.0/400.0)+1)/4) + ((sin(x*sin(time/27.0)*M_PI*31.0/400.0)+1)/4));
+        fb[((x*240)+y)*3+0] = (int)(b*255);
+        fb[((x*240)+y)*3+1] = (int)(g*255);
+        fb[((x*240)+y)*3+2] = (int)(r*255);
+      }
+    }
+
+    time++;
+
+		gfxFlushBuffers();
+		gfxSwapBuffers();
+	}
+
+	gfxExit();
+	return 0;
+}
diff --git a/source/fakecart.c b/source/fakecart.c
new file mode 100644
index 0000000..bbecfa6
--- /dev/null
+++ b/source/fakecart.c
@@ -0,0 +1,8 @@
+#include <3ds.h>
+#include "graphics.h"
+
+void draw() {
+    rect(10, 10, 50, 50, 2);
+
+    rectfill(60, 60, 100, 100, 3);
+}
\ No newline at end of file
diff --git a/source/fakecart.h b/source/fakecart.h
new file mode 100644
index 0000000..2db46ba
--- /dev/null
+++ b/source/fakecart.h
@@ -0,0 +1 @@
+void draw();
\ No newline at end of file
diff --git a/source/graphics.c b/source/graphics.c
new file mode 100644
index 0000000..02cc664
--- /dev/null
+++ b/source/graphics.c
@@ -0,0 +1,126 @@
+#include <math.h>
+#include <3ds.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "graphics.h"
+
+
+/*
+typedef struct Point{
+	char X;
+	char Y;
+};
+
+typedef struct Dimensions{
+	char Width;
+	char Height;
+};
+*/
+
+const Color BgGray = BG_GRAY_COLOR;
+
+const Color PaletteColors[] = {
+	COLOR_00,
+	COLOR_01,
+	COLOR_02,
+	COLOR_03,
+	COLOR_04,
+	COLOR_05,
+	COLOR_06,
+	COLOR_07,
+	COLOR_08,
+	COLOR_09,
+	COLOR_10,
+	COLOR_11,
+	COLOR_12,
+	COLOR_13,
+	COLOR_14,
+	COLOR_15
+};
+
+
+uint16_t _pico8_fb[128*128];
+
+void clearscreen(u8* fb, int time) {
+    int x, y;
+    for(x = 0; x < 400; x++) {
+    	for(y = 0; y < 240; y++) {
+			if (x < 128 && y < 128) {
+				/*
+				float b = (((sin(y*sin(time/40.0)*M_PI*10.0/400.0)+1)/4) + ((sin(x*sin(time/77.0)*M_PI*13.0/400.0)+1)/4));
+				float g = (((sin(y*sin(time/53.0)*M_PI*23.0/400.0)+1)/4) + ((sin(x*sin(time/97.0)*M_PI*17.0/400.0)+1)/4));
+				float r = (((sin(y*sin(time/27.0)*M_PI*17.0/400.0)+1)/4) + ((sin(x*sin(time/27.0)*M_PI*31.0/400.0)+1)/4));
+				fb[((x*240)+y)*3+0] = (int)(b*255);
+				fb[((x*240)+y)*3+1] = (int)(g*255);
+				fb[((x*240)+y)*3+2] = (int)(r*255);
+				*/
+				fb[((x*240)+y)*3+0] = 0;
+				fb[((x*240)+y)*3+1] = 0;
+				fb[((x*240)+y)*3+2] = 0;
+			}
+			else {
+				//gray
+				fb[((x*240)+y)*3+0] = BgGray.Red;
+				fb[((x*240)+y)*3+1] = BgGray.Green;
+				fb[((x*240)+y)*3+2] = BgGray.Blue;
+			}
+    	}
+    }
+}
+
+void rect(char x, char y, char x1, char y1, uint16_t col) {
+	/*
+	char w = x1 - x;
+	char h = y1 - y;
+
+	char currentX = 0;
+	char currentY = 0;
+	*/
+
+
+}
+
+void rectfill(char x, char y, char x1, char y1, uint16_t col) {
+	char holder;
+	if (x1 < x) {
+		holder = x;
+		x = x1;
+		x1 = holder;
+	}
+	if (y1 < y) {
+		holder = y;
+		y = y1;
+		y1 = holder;
+	}
+
+	int width = x1 - x;
+	int height = y1 - y;
+
+	for (int i = 0; i < width; i++) {
+		for (int j = 0; j < height; j++) {
+			if (x < 128 && y < 128) {
+				_pico8_fb[((x + i) * 128) + (y + j)] = col;
+			}
+		}
+	}
+}
+
+void flipBuffer(u8* fb) {
+	int x, y;
+    for(x = 0; x < 400; x++) {
+    	for(y = 0; y < 240; y++) {
+			if (x < 128 && y < 128) {
+				uint16_t c = _pico8_fb[x*128 + y];
+				Color col = PaletteColors[c];
+
+				fb[((x*240)+y)*3+0] = col.Red;
+				fb[((x*240)+y)*3+1] = col.Green;
+				fb[((x*240)+y)*3+2] = col.Blue;
+			}
+    	}
+    }
+
+}
+
+
diff --git a/source/graphics.h b/source/graphics.h
new file mode 100644
index 0000000..9ea61a7
--- /dev/null
+++ b/source/graphics.h
@@ -0,0 +1,36 @@
+
+
+#define COLOR_00 {  0,   0,   0, 255}
+#define COLOR_01 { 29,  43,  83, 255}
+#define COLOR_02 {126,  37,  83, 255}
+#define COLOR_03 {  0, 135,  81, 255}
+#define COLOR_04 {171,  82,  54, 255}
+#define COLOR_05 { 95,  87,  79, 255}
+#define COLOR_06 {194, 195, 199, 255}
+#define COLOR_07 {255, 241, 232, 255}
+#define COLOR_08 {255,   0,  77, 255}
+#define COLOR_09 {255, 163,   0, 255}
+#define COLOR_10 {255, 240,  36, 255}
+#define COLOR_11 {  0, 231,  86, 255}
+#define COLOR_12 { 41, 173, 255, 255}
+#define COLOR_13 {131, 118, 156, 255}
+#define COLOR_14 {255, 119, 168, 255}
+#define COLOR_15 {255, 204, 170, 255}
+
+#define BG_GRAY_COLOR {128, 128, 128, 255}
+
+
+typedef struct {
+	char Red;
+	char Green;
+	char Blue;
+	char Alpha;
+} Color;
+
+
+void clearscreen(u8* fb, int time);
+
+void rect(char x0, char y0, char x1, char y1, uint16_t col);
+void rectfill(char x, char y, char x1, char y1, uint16_t col);
+
+void flipBuffer(u8* fb);
\ No newline at end of file
diff --git a/source/main.c b/source/main.c
new file mode 100644
index 0000000..5f3e264
--- /dev/null
+++ b/source/main.c
@@ -0,0 +1,54 @@
+/*
+	Hello World example made by Aurelio Mannara for ctrulib
+	This code was modified for the last time on: 12/12/2014 21:00 UTC+1
+*/
+
+
+#include <3ds.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "graphics.h"
+#include "fakecart.h"
+
+int main(int argc, char **argv)
+{
+	int frames = 0;
+	gfxInitDefault();
+
+	// Main loop
+	while (aptMainLoop())
+	{
+		gspWaitForVBlank();
+
+		//Scan all the inputs. This should be done once for each frame
+		hidScanInput();
+
+		//hidKeysDown returns information about which buttons have been just pressed (and they weren't in the previous frame)
+		u32 kDown = hidKeysDown();
+
+		if (kDown & KEY_START) break; // break in order to return to hbmenu
+
+		// Flush and swap framebuffers
+		gfxFlushBuffers();
+		gfxSwapBuffers();
+
+		u8* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
+
+		//clear framebuffer
+		memset(fb, 0, 240*400*3);
+
+    	clearscreen(fb, frames);
+
+		draw();
+
+		flipBuffer(fb);
+
+    	frames++;
+
+	}
+
+	gfxExit();
+	return 0;
+}