inital commit

This commit is contained in:
yoruka
2025-04-23 22:32:58 +02:00
commit cdea49064b
15 changed files with 488 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
build
.cache
*.3dsx
*.elf
*.smdh

11
LICENSE Normal file
View File

@@ -0,0 +1,11 @@
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Yoruka
Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.

229
Makefile Normal file
View File

@@ -0,0 +1,229 @@
#---------------------------------------------------------------------------------
.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 \
-ffunction-sections \
$(ARCH)
CFLAGS += $(INCLUDE) -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 %.shbin
#---------------------------------------------------------------------------------
%.t3x.o %_t3x.h : %.t3x
#---------------------------------------------------------------------------------
$(SILENTMSG) $(notdir $<)
$(bin2o)
#---------------------------------------------------------------------------------
%.shbin.o %_shbin.h : %.shbin
#---------------------------------------------------------------------------------
$(SILENTMSG) $(notdir $<)
$(bin2o)
-include $(DEPSDIR)/*.d
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------

2
README.md Normal file
View File

@@ -0,0 +1,2 @@
# pukeko-3ds

27
compile_commands.json Normal file
View File

@@ -0,0 +1,27 @@
[
{
"arguments": [
"/opt/devkitpro//devkitARM/bin/arm-none-eabi-gcc",
"-g",
"-Wall",
"-O2",
"-mword-relocations",
"-ffunction-sections",
"-march=armv6k",
"-mtune=mpcore",
"-mfloat-abi=hard",
"-mtp=soft",
"-I/home/taigo/code/pers/pukeko-3ds/include",
"-I/opt/devkitpro//libctru/include",
"-I/home/taigo/code/pers/pukeko-3ds/build",
"-D__3DS__",
"-c",
"-o",
"input.o",
"/home/taigo/code/pers/pukeko-3ds/source/input.c"
],
"directory": "/home/taigo/code/pers/pukeko-3ds/build",
"file": "/home/taigo/code/pers/pukeko-3ds/source/input.c",
"output": "/home/taigo/code/pers/pukeko-3ds/build/input.o"
}
]

6
include/debug.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef DEBUG_H
#define DEBUG_H
void print_debug_menu();
#endif // !DEBUG_H

16
include/include.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef INCLUDE_H
#define INCLUDE_H
#include <3ds.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "input.h"
extern int user_money;
extern int held_pukekos;
#endif // !INCLUDE_H

7
include/input.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef INPUT_H
#define INPUT_H
void waitForKey(char key);
int print_select_menu(char menu_items[10][32], int items_length);
#endif // !INPUT_H

6
include/main_menu.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef MAIN_MENU_H
#define MAIN_MENU_H
void print_main_menu();
#endif //MAIN_MENU_H

7
include/pukeko.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef PUKEKO_H
#define PUKEKO_H
void print_game_screen();
#endif // !PUKEKO_H

23
source/debug.c Normal file
View File

@@ -0,0 +1,23 @@
#include "include.h"
#include "debug.h"
void print_debug_menu() {
int items_length = 2;
char menu_items[10][32] = {
"add money (500)",
"back"
};
while (true) {
int selection = print_select_menu(menu_items, items_length);
switch (selection) {
case 1:
user_money = user_money + 500;
break;
case 0:
case 2:
return;
}
}
}

53
source/input.c Normal file
View File

@@ -0,0 +1,53 @@
#include "include.h"
void waitForKey(char key) {
while (true) {
hidScanInput();
u32 key_down = hidKeysDown();
if (key_down & key) break;
}
}
int cursor_select(int items) {
int cursor_position = 1;
printf("\x1b[%d;1H>", cursor_position);
while (true) {
hidScanInput();
u32 key_down = hidKeysDown();
if (key_down & KEY_DDOWN) {
printf("\x1b[%d;1H ", cursor_position);
cursor_position = (cursor_position >= items) ? 1 : cursor_position + 1;
printf("\x1b[%d;1H>", cursor_position);
}
if (key_down & KEY_DUP) {
printf("\x1b[%d;1H ", cursor_position);
cursor_position = (cursor_position <= 1) ? items : cursor_position - 1;
printf("\x1b[%d;1H>", cursor_position);
}
if (key_down & KEY_B) {
return 0;
}
if (key_down & KEY_A) {
break;
}
printf("\x1b[10;16Hcursorpos: %d", cursor_position);
}
return cursor_position;
}
void print_menu(char menu_items[10][32], int items_length) {
for (int i = 0; i < items_length; i = i + 1) {
printf("\x1b[%d;2H%s", i+1, menu_items[i]);
}
}
int print_select_menu(char menu_items[10][32], int items_length) {
consoleClear();
print_menu(menu_items, items_length);
int selection = cursor_select(items_length);
return selection;
}

21
source/main.c Normal file
View File

@@ -0,0 +1,21 @@
#include <stdlib.h>
#include "include.h"
#include "main_menu.h"
int user_money = 0;
int held_pukekos = 0;
int main(int argc, char **argv) {
srand(time(NULL));
gfxInitDefault();
consoleInit(GFX_TOP, NULL);
//printf("\x1b[15;13HPress the start button to start...");
//waitForKey(KEY_START);
consoleClear();
print_main_menu();
return 0;
}

31
source/main_menu.c Normal file
View File

@@ -0,0 +1,31 @@
#include "main_menu.h"
#include "include.h"
#include "pukeko.h"
#include "debug.h"
void print_main_menu() {
int items_length = 3;
char menu_items[10][32] = {
"Catch pukekos",
"Debugging",
"Quit"
};
while (true) {
int selection = print_select_menu(menu_items, items_length);
switch (selection) {
case 1:
consoleClear();
print_game_screen();
break;
case 2:
print_debug_menu();
break;
case 3:
return;
}
}
}

44
source/pukeko.c Normal file
View File

@@ -0,0 +1,44 @@
#include "include.h"
#include "pukeko.h"
void print_top_info() {
printf("\x1b[1;1H(A) Catch Pukeko!!!");
printf("\x1b[2;1H(Y) Sell Pukeko... :(");
printf("\x1b[30;1H(B) Go back");
}
void print_bottom_info() {
consoleInit(GFX_BOTTOM, NULL);
printf("\x1b[1;1HMoney: %d", user_money);
printf("\x1b[3;1HPukekos: %d", held_pukekos);
consoleInit(GFX_TOP, NULL);
}
void catch_pukeko() {
int random_number = rand() % 5 + 1;
printf("\x1b[1;1HDAMN!!! ");
held_pukekos = held_pukekos + random_number;
sleep(2);
print_bottom_info();
print_top_info();
printf("\x1b[1;1H(A) Catch Pukeko!!!");
}
void print_game_screen() {
print_bottom_info();
print_top_info();
while (true) {
hidScanInput();
u32 key_down = hidKeysDown();
if (key_down & KEY_A) {
catch_pukeko();
}
if (key_down & KEY_B) {
return;
}
}
}