Get string operations working on 3ds

This commit is contained in:
Andrew Glaze
2025-12-07 12:45:22 -05:00
parent d943c2d074
commit 0acb7c74db
21 changed files with 30432 additions and 23 deletions

13
day01/.gitignore vendored
View File

@@ -1,13 +0,0 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
.sourcekit-lsp/
build/
*.3dsx
*.elf
*.smdh

View File

@@ -40,7 +40,9 @@ GRAPHICS := gfx
GFXBUILD := $(BUILD)
#ROMFS := romfs
#GFXBUILD := $(ROMFS)/gfx
APP_TITLE := $(Target)
APP_TITLE := Hello Swift
APP_DESCRIPTION := Built with Embedded Swift, devkitARM & libctru
APP_AUTHOR := Dmitry Serov
#---------------------------------------------------------------------------------
# options for code generation
@@ -58,9 +60,8 @@ 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
LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -L../../Shared/lib
LIBS := -lctru -lm -lShared
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing

View File

@@ -37,10 +37,10 @@ struct Day01 {
}
static func parseInput(_ input: String) -> [(Direction, Int)] {
input.utf8.split(separator: "\n".utf8.first!).map({ line in
input.split(separator: "\n").map({ line in
return (
Direction(line.first!),
atoi(line.dropFirst())
Int(line.dropFirst())!
)
})
}
@@ -87,20 +87,6 @@ struct Day01 {
}
print("Part 2: \(count)")
}
static func atoi(_ str: Substring.UTF8View) -> Int {
var result = 0
for char in str {
if char >= 0x30 && char <= 0x39 {
result = result * 10 + (Int(char) - 0x30)
} else {
break
}
}
return result
}
}
@@ -108,10 +94,10 @@ enum Direction {
case Left
case Right
init(_ char: UInt8) {
init(_ char: Character) {
self = switch char {
case "L".utf8.first: Direction.Left
case "R".utf8.first: Direction.Right
case "L": Direction.Left
case "R": Direction.Right
default: fatalError()
}
}

View File

@@ -1,18 +0,0 @@
#include <stdlib.h>
#include <malloc.h>
#include <errno.h>
int posix_memalign(void **res, size_t align, size_t len) {
if (align < sizeof(void *)) return 22;
void *mem = memalign(align, len);
if (!mem) return errno;
*res = mem;
return 0;
}
int getentropy(void *buffer, size_t length) {
for (int i = 0; i < length; i++) {
((int*)buffer)[i] = rand();
}
return 0;
}