Initial commit
This commit is contained in:
commit
4b99487f8a
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
build/
|
||||
*.3dsx
|
||||
*.3ds
|
||||
*.elf
|
||||
|
||||
.DS_Store
|
||||
|
||||
.swp
|
151
Makefile
Normal file
151
Makefile
Normal file
@ -0,0 +1,151 @@
|
||||
#---------------------------------------------------------------------------------
|
||||
.SUFFIXES:
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
ifeq ($(strip $(CTRULIB)),)
|
||||
# THIS IS TEMPORARY - in the future it should be at $(DEVKITPRO)/libctru
|
||||
$(error "Please set CTRULIB in your environment. export CTRULIB=<path to>libctru")
|
||||
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
|
||||
# SPECS is the directory containing the important build and link files
|
||||
#---------------------------------------------------------------------------------
|
||||
export TARGET := $(shell basename $(CURDIR))
|
||||
BUILD := build
|
||||
SOURCES := source
|
||||
DATA := data
|
||||
INCLUDES := include
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
ARCH := -march=armv6k -mtune=mpcore
|
||||
|
||||
CFLAGS := -g -Wall -O2 -mword-relocations -save-temps \
|
||||
-fomit-frame-pointer -ffast-math -mfloat-abi=softfp \
|
||||
$(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,$(TARGET).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,$(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)))
|
||||
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
|
||||
#---------------------------------------------------------------------------------
|
||||
|
||||
export OFILES := $(addsuffix .o,$(BINFILES)) \
|
||||
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
|
||||
|
||||
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).3dsx $(TARGET).elf
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
else
|
||||
|
||||
DEPENDS := $(OFILES:.o=.d)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# main targets
|
||||
#---------------------------------------------------------------------------------
|
||||
$(OUTPUT).3dsx : $(OUTPUT).elf
|
||||
$(OUTPUT).elf : $(OFILES)
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# you need a rule like this for each extension you use as binary data
|
||||
#---------------------------------------------------------------------------------
|
||||
%.bin.o : %.bin
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@$(bin2o)
|
||||
|
||||
# not the right way to do this
|
||||
#---------------------------------------------------------------------------------
|
||||
%.vsh.o : %.vsh
|
||||
#---------------------------------------------------------------------------------
|
||||
@echo $(notdir $<)
|
||||
@python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin
|
||||
@bin2s ../$(notdir $<).shbin | arm-none-eabi-as -o $@
|
||||
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
|
||||
@rm ../$(notdir $<).shbin
|
||||
|
||||
-include $(DEPENDS)
|
||||
|
||||
#---------------------------------------------------------------------------------------
|
||||
endif
|
||||
#---------------------------------------------------------------------------------------
|
8
README.md
Normal file
8
README.md
Normal file
@ -0,0 +1,8 @@
|
||||
fs-test
|
||||
=======
|
||||
|
||||
A really shitty homebrew test for the SDMC filesystem.
|
||||
|
||||
Adapted from smea's ftpony.
|
||||
|
||||
Press A to run, press B to close.
|
BIN
data/font.bin
Normal file
BIN
data/font.bin
Normal file
Binary file not shown.
6
source/costable.h
Normal file
6
source/costable.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef COSTABLE_H
|
||||
#define COSTABLE_H
|
||||
|
||||
s32 costable[] = {4096, 4095, 4094, 4093, 4091, 4088, 4084, 4080, 4076, 4071, 4065, 4058, 4051, 4044, 4035, 4026, 4017, 4007, 3996, 3985, 3973, 3960, 3947, 3934, 3919, 3904, 3889, 3873, 3856, 3839, 3821, 3803, 3784, 3765, 3744, 3724, 3703, 3681, 3659, 3636, 3612, 3588, 3564, 3539, 3513, 3487, 3461, 3434, 3406, 3378, 3349, 3320, 3290, 3260, 3229, 3198, 3167, 3135, 3102, 3069, 3035, 3002, 2967, 2932, 2897, 2861, 2825, 2788, 2751, 2714, 2676, 2638, 2599, 2560, 2521, 2481, 2441, 2401, 2360, 2318, 2277, 2235, 2193, 2150, 2107, 2064, 2020, 1976, 1932, 1888, 1843, 1798, 1753, 1707, 1662, 1616, 1569, 1523, 1476, 1429, 1382, 1334, 1287, 1239, 1191, 1143, 1095, 1046, 997, 949, 900, 851, 801, 752, 703, 653, 603, 554, 504, 454, 404, 354, 304, 254, 204, 153, 103, 53, 3, -46, -97, -147, -197, -247, -297, -347, -398, -448, -497, -547, -597, -647, -696, -746, -795, -844, -893, -942, -991, -1040, -1088, -1137, -1185, -1233, -1281, -1328, -1376, -1423, -1470, -1517, -1563, -1610, -1656, -1701, -1747, -1792, -1837, -1882, -1927, -1971, -2015, -2058, -2102, -2144, -2187, -2229, -2271, -2313, -2354, -2395, -2436, -2476, -2516, -2555, -2594, -2633, -2671, -2709, -2747, -2784, -2820, -2857, -2892, -2928, -2963, -2997, -3031, -3065, -3098, -3130, -3163, -3194, -3225, -3256, -3286, -3316, -3345, -3374, -3402, -3430, -3457, -3484, -3510, -3536, -3561, -3585, -3609, -3633, -3656, -3678, -3700, -3721, -3742, -3762, -3782, -3801, -3819, -3837, -3854, -3871, -3887, -3902, -3917, -3932, -3946, -3959, -3971, -3983, -3995, -4005, -4016, -4025, -4034, -4042, -4050, -4057, -4064, -4070, -4075, -4080, -4084, -4087, -4090, -4092, -4094, -4095, -4095, -4095, -4094, -4093, -4091, -4088, -4085, -4081, -4076, -4071, -4066, -4059, -4052, -4045, -4036, -4028, -4018, -4008, -3997, -3986, -3974, -3962, -3949, -3935, -3921, -3906, -3891, -3875, -3858, -3841, -3824, -3805, -3787, -3767, -3747, -3727, -3705, -3684, -3662, -3639, -3615, -3592, -3567, -3542, -3517, -3491, -3464, -3437, -3409, -3381, -3353, -3324, -3294, -3264, -3233, -3202, -3171, -3139, -3106, -3073, -3040, -3006, -2972, -2937, -2902, -2866, -2830, -2793, -2756, -2719, -2681, -2643, -2604, -2565, -2526, -2486, -2446, -2406, -2365, -2324, -2282, -2240, -2198, -2156, -2113, -2069, -2026, -1982, -1938, -1894, -1849, -1804, -1759, -1713, -1668, -1622, -1575, -1529, -1482, -1435, -1388, -1341, -1293, -1245, -1197, -1149, -1101, -1052, -1004, -955, -906, -857, -808, -758, -709, -660, -610, -560, -510, -460, -411, -360, -310, -260, -210, -160, -110, -60, -9, 40, 90, 140, 191, 241, 291, 341, 391, 441, 491, 541, 591, 640, 690, 739, 789, 838, 887, 936, 985, 1033, 1082, 1130, 1179, 1227, 1274, 1322, 1370, 1417, 1464, 1511, 1557, 1604, 1650, 1695, 1741, 1786, 1831, 1876, 1921, 1965, 2009, 2053, 2096, 2139, 2182, 2224, 2266, 2308, 2349, 2390, 2431, 2471, 2511, 2550, 2589, 2628, 2666, 2704, 2742, 2779, 2816, 2852, 2888, 2923, 2958, 2993, 3027, 3060, 3093, 3126, 3158, 3190, 3221, 3252, 3282, 3312, 3342, 3370, 3399, 3426, 3454, 3480, 3507, 3532, 3557, 3582, 3606, 3630, 3653, 3675, 3697, 3718, 3739, 3759, 3779, 3798, 3817, 3835, 3852, 3869, 3885, 3900, 3915, 3930, 3944, 3957, 3970, 3982, 3993, 4004, 4014, 4024, 4033, 4041, 4049, 4056, 4063, 4069, 4074, 4079, 4083, 4087, 4090, 4092, 4094, 4095};
|
||||
|
||||
#endif
|
10
source/font.c
Normal file
10
source/font.c
Normal file
@ -0,0 +1,10 @@
|
||||
#include <3ds.h>
|
||||
#include "font.h"
|
||||
|
||||
font_s fontDefault =
|
||||
{
|
||||
font1Data,
|
||||
font1Desc,
|
||||
16,
|
||||
(u8[]){0xFF,0xFF,0xFF}
|
||||
};
|
18
source/font.h
Normal file
18
source/font.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef FONT_H
|
||||
#define FONT_H
|
||||
|
||||
typedef struct {char c; int x, y, w, h, xo, yo, xa; u8* data;}charDesc_s;
|
||||
typedef struct
|
||||
{
|
||||
u8* data;
|
||||
charDesc_s* desc;
|
||||
u8 height;
|
||||
u8 color[3];
|
||||
}font_s;
|
||||
|
||||
extern u8 font1Data[];
|
||||
extern charDesc_s font1Desc[];
|
||||
|
||||
extern font_s fontDefault;
|
||||
|
||||
#endif
|
261
source/font1.c
Normal file
261
source/font1.c
Normal file
File diff suppressed because one or more lines are too long
114
source/main.c
Normal file
114
source/main.c
Normal file
@ -0,0 +1,114 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <3ds.h>
|
||||
|
||||
#include "costable.h"
|
||||
#include "text.h"
|
||||
#include "output.h"
|
||||
|
||||
char superStr[8192];
|
||||
int cnt;
|
||||
|
||||
s32 pcCos(u16 v)
|
||||
{
|
||||
return costable[v&0x1FF];
|
||||
}
|
||||
|
||||
int countLines(char* str)
|
||||
{
|
||||
if(!str)return 0;
|
||||
int cnt; for(cnt=1;*str=='\n'?++cnt:*str;str++);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
void cutLine(char* str)
|
||||
{
|
||||
if(!str || !*str)return;
|
||||
char* str2=str; for(;*str2&&*(str2+1)&&*str2!='\n';str2++); str2++;
|
||||
memmove(str,str2,strlen(str2)+1);
|
||||
}
|
||||
|
||||
void drawFrame()
|
||||
{
|
||||
u8* bufAdr=gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
|
||||
|
||||
int i, j;
|
||||
for(i=1;i<400;i++)
|
||||
{
|
||||
for(j=1;j<240;j++)
|
||||
{
|
||||
u32 v=(j+i*240)*3;
|
||||
bufAdr[v]=(pcCos(i+cnt)+4096)/32;
|
||||
bufAdr[v+1]=(pcCos(j-256+cnt)+4096)/64;
|
||||
bufAdr[v+2]=(pcCos(i+128-cnt)+4096)/32;
|
||||
}
|
||||
}
|
||||
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, "ftPONY v0.0002\n", 240-fontDefault.height*1, 10);
|
||||
i = countLines(superStr);
|
||||
while(i>240/fontDefault.height-3){cutLine(superStr);i--;}
|
||||
gfxDrawText(GFX_TOP, GFX_LEFT, NULL, superStr, 240-fontDefault.height*3, 20);
|
||||
cnt++;
|
||||
|
||||
gfxFlushBuffers();
|
||||
gfxSwapBuffers();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
srvInit();
|
||||
aptInit();
|
||||
hidInit(NULL);
|
||||
irrstInit(NULL);
|
||||
gfxInit();
|
||||
gfxSet3D(false);
|
||||
|
||||
print("fsInit %08X\n", (unsigned int)
|
||||
fsInit()
|
||||
);
|
||||
|
||||
FS_archive sdmcArchive = (FS_archive) {
|
||||
0x00000009, (FS_path) { PATH_EMPTY, 1, (u8*) "" }
|
||||
};
|
||||
|
||||
print("FSUSER_OpenArchive %08X\n", (unsigned int)
|
||||
FSUSER_OpenArchive(NULL, &sdmcArchive)
|
||||
);
|
||||
|
||||
superStr[0]=0;
|
||||
|
||||
APP_STATUS status;
|
||||
while((status=aptGetStatus()) != APP_EXITING)
|
||||
{
|
||||
if(status == APP_RUNNING)
|
||||
{
|
||||
drawFrame();
|
||||
|
||||
hidScanInput();
|
||||
if (hidKeysDown() & KEY_B) {
|
||||
break;
|
||||
} else if (hidKeysDown() & KEY_A) {
|
||||
print("FSUSER_CreateDirectory %08X\n", (unsigned int)
|
||||
FSUSER_CreateDirectory(NULL, sdmcArchive, FS_makePath(PATH_CHAR, "/new_dir"))
|
||||
);
|
||||
}
|
||||
}
|
||||
else if(status == APP_SUSPENDING)
|
||||
{
|
||||
aptReturnToMenu();
|
||||
}
|
||||
else if (status == APP_SLEEPMODE)
|
||||
{
|
||||
aptWaitStatusEvent();
|
||||
}
|
||||
gspWaitForEvent(GSPEVENT_VBlank0, false);
|
||||
}
|
||||
|
||||
gfxExit();
|
||||
irrstExit();
|
||||
hidExit();
|
||||
aptExit();
|
||||
srvExit();
|
||||
return 0;
|
||||
}
|
9
source/output.h
Normal file
9
source/output.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef OUTPUT_H
|
||||
#define OUTPUT_H
|
||||
|
||||
#define print(...) sprintf(&superStr[strlen(superStr)], __VA_ARGS__); drawFrame()
|
||||
|
||||
void drawFrame();
|
||||
extern char superStr[];
|
||||
|
||||
#endif
|
64
source/text.c
Normal file
64
source/text.c
Normal file
@ -0,0 +1,64 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <3ds.h>
|
||||
#include "text.h"
|
||||
|
||||
#include "font.h"
|
||||
|
||||
//this code is not meant to be readable
|
||||
int drawCharacter(u8* fb, font_s* f, char c, s16 x, s16 y, u16 w, u16 h)
|
||||
{
|
||||
charDesc_s* cd=&f->desc[(int)c];
|
||||
if(!cd->data)return 0;
|
||||
x+=cd->xo; y+=f->height-cd->yo-cd->h;
|
||||
if(x<0 || x+cd->w>=w || y<-cd->h || y>=h+cd->h)return 0;
|
||||
u8* charData=cd->data;
|
||||
int i, j;
|
||||
s16 cy=y, ch=cd->h, cyo=0;
|
||||
if(y<0){cy=0;cyo=-y;ch=cd->h-cyo;}
|
||||
else if(y+ch>h)ch=h-y;
|
||||
fb+=(x*h+cy)*3;
|
||||
const u8 r=f->color[0], g=f->color[1], b=f->color[2];
|
||||
for(i=0;i<cd->w;i++)
|
||||
{
|
||||
charData+=cyo;
|
||||
for(j=0;j<ch;j++)
|
||||
{
|
||||
u8 v=*(charData++);
|
||||
if(v)
|
||||
{
|
||||
fb[0]=(fb[0]*(0xFF-v)+(b*v))>>8;
|
||||
fb[1]=(fb[1]*(0xFF-v)+(g*v))>>8;
|
||||
fb[2]=(fb[2]*(0xFF-v)+(r*v))>>8;
|
||||
}
|
||||
fb+=3;
|
||||
}
|
||||
charData+=(cd->h-(cyo+ch));
|
||||
fb+=(h-ch)*3;
|
||||
}
|
||||
return cd->xa;
|
||||
}
|
||||
|
||||
void drawString(u8* fb, font_s* f, char* str, s16 x, s16 y, u16 w, u16 h)
|
||||
{
|
||||
if(!f || !fb || !str)return;
|
||||
int k; int dx=0, dy=0;
|
||||
int length=strlen(str);
|
||||
for(k=0;k<length;k++)
|
||||
{
|
||||
dx+=drawCharacter(fb,f,str[k],x+dx,y+dy,w,h);
|
||||
if(str[k]=='\n'){dx=0;dy-=f->height;}
|
||||
}
|
||||
}
|
||||
|
||||
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* f, char* str, s16 x, s16 y)
|
||||
{
|
||||
if(!str)return;
|
||||
if(!f)f=&fontDefault;
|
||||
|
||||
u16 fbWidth, fbHeight;
|
||||
u8* fbAdr=gfxGetFramebuffer(screen, side, &fbWidth, &fbHeight);
|
||||
|
||||
drawString(fbAdr, f, str, y, x, fbHeight, fbWidth);
|
||||
}
|
9
source/text.h
Normal file
9
source/text.h
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "font.h"
|
||||
|
||||
int drawCharacter(u8* fb, font_s* f, char c, s16 x, s16 y, u16 w, u16 h);
|
||||
void drawString(u8* fb, font_s* f, char* str, s16 x, s16 y, u16 w, u16 h);
|
||||
void gfxDrawText(gfxScreen_t screen, gfx3dSide_t side, font_s* f, char* str, s16 x, s16 y);
|
Loading…
x
Reference in New Issue
Block a user