diff options
author | root <root@t60.home.remexre.com> | 2024-11-18 10:45:20 -0600 |
---|---|---|
committer | root <root@t60.home.remexre.com> | 2024-11-18 10:45:20 -0600 |
commit | 62e41dcb40d0450d493a804e7f0ac3e32f35aabf (patch) | |
tree | 0744f1af53ac605868d8b85cd5446264820a4ca1 | |
parent | 943a6597b2bcd1b3ed208458a5cba61ad5b4051c (diff) |
Adds Linux support.
-rwxr-xr-x | mk.sh | 4 | ||||
-rw-r--r-- | src/Makefile | 22 | ||||
-rw-r--r-- | src/main.c | 60 | ||||
-rw-r--r-- | src/platform/3ds.c | 64 | ||||
-rw-r--r-- | src/platform/3ds.mk | 18 | ||||
-rw-r--r-- | src/platform/linux.c | 0 | ||||
-rw-r--r-- | src/platform/linux.mk | 1 |
7 files changed, 92 insertions, 77 deletions
@@ -4,6 +4,9 @@ set -euo pipefail repo=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) srcdir="$repo/src" +platform="$1" +shift + if [[ "$(pwd -P)" = "$repo" ]]; then test ! -d build || rm -r build mkdir build @@ -12,6 +15,7 @@ fi cat >config.mak <<EOF CONFIGURED = 1 +platform = $platform srcdir = $srcdir EOF ln -s "$srcdir/Makefile" diff --git a/src/Makefile b/src/Makefile index 07f1cb5..0f4841b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,3 @@ -ifeq ($(strip $(DEVKITPRO)),) -$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO") -endif - SRCS = $(sort $(wildcard $(srcdir)/*.c)) OBJS = $(patsubst $(srcdir)/%.c,obj/%.o,$(SRCS)) DEPS = $(patsubst $(srcdir)/%.c,obj/%.d,$(SRCS)) @@ -10,11 +6,9 @@ CFLAGS = CPPFLAGS = LDFLAGS = -CC = $(DEVKITPRO)/devkitARM/bin/arm-none-eabi-gcc - -CFLAGS_AUTO = -D__3DS__ -ffunction-sections -flto -g -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mword-relocations -O3 -std=c11 -Wall -Werror=implicit-function-declaration -LDFLAGS_AUTO = -L$(DEVKITPRO)/libctru/lib -specs=3dsx.specs -LDLIBS_AUTO = -lctru -lm +CFLAGS_AUTO = -fdata-sections -ffunction-sections -flto -g -O3 -std=c11 -Wall -Werror=implicit-function-declaration +LDFLAGS_AUTO = +LDLIBS_AUTO = -lm CFLAGS_ALL = $(CPPFLAGS) $(CFLAGS_AUTO) $(CFLAGS) LDFLAGS_ALL = $(LDFLAGS_AUTO) $(LDFLAGS) @@ -30,15 +24,9 @@ all: else -all: imb3.3dsx -3dslink: imb3.3dsx - $(DEVKITPRO)/tools/bin/3dslink $< -.PHONY: 3dslink - -imb3.3dsx: imb3.elf - 3dsxtool $< $@ +include $(srcdir)/platform/$(platform).mk -imb3.elf: $(OBJS) obj/gc/gc.o obj/platform/3ds.o +imb3.elf: $(OBJS) obj/gc/gc.o obj/platform/$(platform).o $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -o $@ $^ $(LDLIBS_ALL) obj/%.o: $(srcdir)/%.c @@ -1,66 +1,6 @@ #include "gc.h" #include "util.h" -#include <3ds.h> -#include <inttypes.h> -#include <stdio.h> int main(int argc, char **argv) { - gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false); - - gc_init(); - bootstrap(); - - // Initialize console on top screen. Using NULL as the second argument tells - // the console library to use the internal console structure as current one - consoleInit(GFX_TOP, NULL); - - // Move the cursor to row 15 and column 19 and then prints "Hello World!" - // To move the cursor you have to print "\x1b[r;cH", where r and c are - // respectively the row and column where you want your cursor to move The top - // screen has 30 rows and 50 columns The bottom screen has 30 rows and 40 - // columns - printf("\x1b[16;20HHello World!"); - - printf("\x1b[29;16HPress Start to exit.\n"); - - // Main loop - while (aptMainLoop()) { - // 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 - if (kDown & KEY_A) - todo("GM"); - - circlePosition pos; - hidCircleRead(&pos); - printf("\x1b[0;0H\x1b[K(%" PRId16 ", %" PRId16 ")\n", pos.dx, pos.dy); - - // Get the bottom screen's frame buffer - u16 w, h; - u8 *fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &w, &h); - - for (u16 j = 0; j < h; j++) { - for (u16 i = 0; i < w; i++) { - *fb++ = (u8)(((float)i / (float)w) * 255.0); - *fb++ = (u8)(((float)j / (float)h) * 255.0); - *fb++ = 0x00; - } - } - - // Flush and swap framebuffers - gfxFlushBuffers(); - gfxSwapBuffers(); - - // Wait for VBlank - gspWaitForVBlank(); - } - - gfxExit(); return 0; } diff --git a/src/platform/3ds.c b/src/platform/3ds.c index 888baf7..5683422 100644 --- a/src/platform/3ds.c +++ b/src/platform/3ds.c @@ -1,6 +1,9 @@ #include <3ds.h> +#include "../gc.h" #include "../platform.h" +#include "../util.h" +#include <inttypes.h> #include <stdio.h> #include <stdlib.h> @@ -31,3 +34,64 @@ noreturn void panic_end(void) { gfxExit(); exit(1); } + +int main(int argc, char **argv) { + gfxInit(GSP_BGR8_OES, GSP_BGR8_OES, false); + + gc_init(); + bootstrap(); + + // Initialize console on top screen. Using NULL as the second argument tells + // the console library to use the internal console structure as current one + consoleInit(GFX_TOP, NULL); + + // Move the cursor to row 15 and column 19 and then prints "Hello World!" + // To move the cursor you have to print "\x1b[r;cH", where r and c are + // respectively the row and column where you want your cursor to move The top + // screen has 30 rows and 50 columns The bottom screen has 30 rows and 40 + // columns + printf("\x1b[16;20HHello World!"); + + printf("\x1b[29;16HPress Start to exit.\n"); + + // Main loop + while (aptMainLoop()) { + // 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 + if (kDown & KEY_A) + todo("GM"); + + circlePosition pos; + hidCircleRead(&pos); + printf("\x1b[0;0H\x1b[K(%" PRId16 ", %" PRId16 ")\n", pos.dx, pos.dy); + + // Get the bottom screen's frame buffer + u16 w, h; + u8 *fb = gfxGetFramebuffer(GFX_BOTTOM, GFX_LEFT, &w, &h); + + for (u16 j = 0; j < h; j++) { + for (u16 i = 0; i < w; i++) { + *fb++ = (u8)(((float)i / (float)w) * 255.0); + *fb++ = (u8)(((float)j / (float)h) * 255.0); + *fb++ = 0x00; + } + } + + // Flush and swap framebuffers + gfxFlushBuffers(); + gfxSwapBuffers(); + + // Wait for VBlank + gspWaitForVBlank(); + } + + gfxExit(); + return 0; +} diff --git a/src/platform/3ds.mk b/src/platform/3ds.mk new file mode 100644 index 0000000..cbe7e0b --- /dev/null +++ b/src/platform/3ds.mk @@ -0,0 +1,18 @@ +ifeq ($(strip $(DEVKITPRO)),) +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPRO") +endif + +CC = $(DEVKITPRO)/devkitARM/bin/arm-none-eabi-gcc + +CFLAGS_AUTO += -D__3DS__ -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -mword-relocations +LDFLAGS_AUTO += -L$(DEVKITPRO)/libctru/lib -specs=3dsx.specs +LDLIBS_AUTO += -lctru + +all: imb3.3dsx + +3dslink: imb3.3dsx + $(DEVKITPRO)/tools/bin/3dslink $< +.PHONY: 3dslink + +imb3.3dsx: imb3.elf + 3dsxtool $< $@ diff --git a/src/platform/linux.c b/src/platform/linux.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/platform/linux.c diff --git a/src/platform/linux.mk b/src/platform/linux.mk new file mode 100644 index 0000000..6c82e6b --- /dev/null +++ b/src/platform/linux.mk @@ -0,0 +1 @@ +all: imb3.elf |