From c52ecb03d0a0fa7645df3b24a922ec544ad7a22e Mon Sep 17 00:00:00 2001 From: Stephanie Gawroriski Date: Sun, 31 Mar 2024 03:07:34 +0000 Subject: [PATCH] Cherry pick changes from wip-scritchui which should be mainline. --- .fossil-settings/ignore-glob | 3 + .../plugin/general/cmake/CMakeBuildTask.java | 24 +- .../plugin/general/cmake/CMakeBuildTaskAction.java | 4 +- .../cc/squirreljme/plugin/multivm/VMHelpers.java | 2 +- emulators/emulator-base/build.gradle | 7 +- .../emulator-base/{ => src/main}/CMakeLists.txt | 37 +- emulators/nanocoat-vm/build.gradle | 4 +- .../main/java/cc/squirreljme/jvm/Framebuffer.java | 378 --------------------- .../squirreljme/runtime/cldc/util/MathUtils.java | 47 +++ .../src/test/java/io/MarkableInputStreamTest.java | 1 - modules/lcdui-demo/build.gradle | 4 +- .../net/multiphasicapps/lcduidemo/Mystify.java | 9 +- nanocoat/.idea/misc.xml | 3 +- nanocoat/CMakeLists.txt | 13 +- nanocoat/cmake/fixes.cmake | 39 +++ nanocoat/cmake/hardening.cmake | 20 ++ nanocoat/cmake/utils.cmake | 3 + nanocoat/frontend/emulator/CMakeLists.txt | 22 +- nanocoat/frontend/libjvm/CMakeLists.txt | 7 +- nanocoat/frontend/libretro/CMakeLists.txt | 36 +- nanocoat/include/sjme/dylib.h | 86 +++++ nanocoat/src/CMakeLists.txt | 1 + nanocoat/src/dylib.c | 47 +++ 23 files changed, 315 insertions(+), 482 deletions(-) rename emulators/emulator-base/{ => src/main}/CMakeLists.txt (79%) delete mode 100644 modules/cldc-compact/src/main/java/cc/squirreljme/jvm/Framebuffer.java create mode 100644 modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/MathUtils.java create mode 100644 nanocoat/cmake/hardening.cmake create mode 100644 nanocoat/include/sjme/dylib.h create mode 100644 nanocoat/src/dylib.c diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob index dbcf27086d..30c2180d34 100644 --- a/.fossil-settings/ignore-glob +++ b/.fossil-settings/ignore-glob @@ -91,6 +91,9 @@ build-dir/ CMakeFiles CTestTestfile.cmake CMakeCache.txt +nanocoat/cc/cmake-build-debug +ratufacoat/cmake-build-release +ratufacoat/cmake-build-release nanocoat/cmake-build-release nanocoat/cmake-build-debug nanocoat/cmake-build-* diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTask.java b/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTask.java index 894de1f35b..266e4d62a3 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTask.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTask.java @@ -12,10 +12,7 @@ package cc.squirreljme.plugin.general.cmake; import java.nio.file.Path; import java.nio.file.Paths; import javax.inject.Inject; -import lombok.Getter; import org.gradle.api.DefaultTask; -import org.gradle.api.tasks.Input; -import org.gradle.api.tasks.OutputFile; /** * Task for building CMake projects. @@ -32,7 +29,7 @@ public class CMakeBuildTask public final Path cmakeBuild; /** The output library we want. */ - public final Path cmakeOutLibrary; + public final Path cmakeOutFile; /** The rule to use. */ public final String cmakeRule; @@ -41,16 +38,16 @@ public class CMakeBuildTask * Initializes the build task. * * @param __source The project source directory. - * @param __outputLib The output library we want. + * @param __outputFile The output library we want. * @param __rule The rule to execute. * @since 2024/03/15 */ @Inject - public CMakeBuildTask(Path __source, String __outputLib, + public CMakeBuildTask(Path __source, String __outputFile, String __rule) throws NullPointerException { - if (__source == null || __outputLib == null || __rule == null) + if (__source == null || __outputFile == null || __rule == null) throw new NullPointerException("NARG"); // Set source for later @@ -59,19 +56,16 @@ public class CMakeBuildTask // The build root is based on the task this.cmakeBuild = this.getProject().getBuildDir().toPath() - .resolve("cmake"); + .resolve("cmake-" + this.getName()); - // The desired library we want - this.cmakeOutLibrary = this.cmakeBuild.resolve( - Paths.get(System.mapLibraryName(__outputLib))); + // The desired output we want + this.cmakeOutFile = this.cmakeBuild.resolve( + Paths.get(__outputFile)); // Description this.setGroup("squirreljme"); this.setDescription("Performs a CMake build."); - // Only build if CMake is available - /*this.onlyIf(new CMakeOnlyIf());*/ - // Check if out of date this.getOutputs().upToDateWhen(new CMakeUpToDateWhen()); @@ -80,7 +74,7 @@ public class CMakeBuildTask this.getInputs().files( this.cmakeSource.resolve("CMakeLists.txt")); this.getOutputs().dirs(this.cmakeBuild); - this.getOutputs().files(this.cmakeOutLibrary); + this.getOutputs().files(this.cmakeOutFile); // What to do for this this.doFirst(new CMakeBuildTaskAction()); diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTaskAction.java b/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTaskAction.java index d97100dbe9..a732b41336 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTaskAction.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/general/cmake/CMakeBuildTaskAction.java @@ -58,10 +58,10 @@ public class CMakeBuildTaskAction "-t", from.cmakeRule); // Was the output file even created? - if (!Files.exists(from.cmakeOutLibrary)) + if (!Files.exists(from.cmakeOutFile)) throw new FileNotFoundException( "Could not find output library: " + - from.cmakeOutLibrary); + from.cmakeOutFile); } catch (IOException __e) { diff --git a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java index cad20c0338..ecc34d2689 100644 --- a/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java +++ b/buildSrc/src/main/java/cc/squirreljme/plugin/multivm/VMHelpers.java @@ -507,7 +507,7 @@ public final class VMHelpers .getByName("libNativeEmulatorBase"); // Use the resultant library - return cmake.cmakeOutLibrary; + return cmake.cmakeOutFile; } /** diff --git a/emulators/emulator-base/build.gradle b/emulators/emulator-base/build.gradle index bd3ef5f216..ce4bea8a1c 100644 --- a/emulators/emulator-base/build.gradle +++ b/emulators/emulator-base/build.gradle @@ -31,11 +31,12 @@ dependencies api project(":modules:debug-jdwp-vm-host") } +// Native emulator support library Provider libNativeEmulatorBase = tasks.register( "libNativeEmulatorBase", CMakeBuildTask.class, - project.getProjectDir().toPath(), - "emulator-base", + project.getProjectDir().toPath().resolve("src").resolve("main"), + System.mapLibraryName("emulator-base"), "libEmulatorBase") Provider mimeDecode =tasks.register( @@ -58,7 +59,7 @@ mimeDecode.get().dependsOn(libNativeEmulatorBase) jar { dependsOn libNativeEmulatorBase - from libNativeEmulatorBase.get().cmakeOutLibrary.toFile() + from libNativeEmulatorBase.get().cmakeOutFile.toFile() into "/" } diff --git a/emulators/emulator-base/CMakeLists.txt b/emulators/emulator-base/src/main/CMakeLists.txt similarity index 79% rename from emulators/emulator-base/CMakeLists.txt rename to emulators/emulator-base/src/main/CMakeLists.txt index 6d7e38d20f..85ccff8b23 100644 --- a/emulators/emulator-base/CMakeLists.txt +++ b/emulators/emulator-base/src/main/CMakeLists.txt @@ -19,7 +19,7 @@ find_package(JNI QUIET) if(NOT JNI_FOUND) # Where are the headers? set(JNI_INCLUDE_DIRS - "src/main/headers/jni") + "headers/jni") # Set as found set(JNI_FOUND ON) @@ -27,26 +27,27 @@ endif() # Declare library add_library(libEmulatorBase SHARED - src/main/c/mle_debug.c - src/main/c/mle_form.c - src/main/c/mle_jar.c - src/main/c/mle_math.c - src/main/c/mle_midi.c - src/main/c/mle_nativearchive.c - src/main/c/mle_object.c - src/main/c/mle_pencil.c - src/main/c/mle_reflection.c - src/main/c/mle_runtime.c - src/main/c/mle_task.c - src/main/c/mle_terminal.c - src/main/c/mle_thread.c - src/main/c/mle_type.c - src/main/c/nativebinding.c - src/main/c/utils.c) + c/mle_debug.c + c/mle_form.c + c/mle_jar.c + c/mle_math.c + c/mle_midi.c + c/mle_nativearchive.c + c/mle_object.c + c/mle_pencil.c + c/mle_reflection.c + c/mle_runtime.c + c/mle_task.c + c/mle_terminal.c + c/mle_thread.c + c/mle_type.c + c/nativebinding.c + c/utils.c) # Includes for the build target_include_directories(libEmulatorBase PUBLIC - "src/main/headers" + "headers" + "${CMAKE_SOURCE_DIR}/../../nanocoat/include" ${JNI_INCLUDE_DIRS}) # It is easier to find this when it is in the build root diff --git a/emulators/nanocoat-vm/build.gradle b/emulators/nanocoat-vm/build.gradle index 5ba2221637..341170c2a7 100644 --- a/emulators/nanocoat-vm/build.gradle +++ b/emulators/nanocoat-vm/build.gradle @@ -27,7 +27,7 @@ Provider libNativeNanoCoat = tasks.register( "libNativeNanoCoat", CMakeBuildTask.class, gradle.rootProject.projectDir.toPath().resolve("nanocoat"), - "emulator-nanocoat", + System.mapLibraryName("emulator-nanocoat"), "libEmulator") libNativeNanoCoat.configure { taskIsh -> @@ -51,7 +51,7 @@ jar { dependsOn libNativeNanoCoat // Include library into the root - from libNativeNanoCoat.get().cmakeOutLibrary.toFile() + from libNativeNanoCoat.get().cmakeOutFile.toFile() into "/" } diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/Framebuffer.java b/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/Framebuffer.java deleted file mode 100644 index 8b6c572b07..0000000000 --- a/modules/cldc-compact/src/main/java/cc/squirreljme/jvm/Framebuffer.java +++ /dev/null @@ -1,378 +0,0 @@ -// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- -// --------------------------------------------------------------------------- -// SquirrelJME -// Copyright (C) Stephanie Gawroriski -// --------------------------------------------------------------------------- -// SquirrelJME is under the Mozilla Public License Version 2.0. -// See license.mkd for licensing and copyright information. -// --------------------------------------------------------------------------- - -package cc.squirreljme.jvm; - -/** - * This is used to get/set the property of the framebuffer. - * - * @since 2019/06/20 - */ -public interface Framebuffer -{ - /** - * Returns the address of the framebuffer. - * - * @squirreljme.syscallreturn The framebuffer address. - */ - byte CONTROL_ADDRESS = - 1; - - /** - * Returns the width of the framebuffer. - * - * @squirreljme.syscallreturn The framebuffer width. - */ - byte CONTROL_WIDTH = - 2; - - /** - * Returns the height of the framebuffer. - * - * @squirreljme.syscallreturn The framebuffer height. - */ - byte CONTROL_HEIGHT = - 3; - - /** - * Returns the scanline length. - * - * @squirreljme.syscallreturn The framebuffer scanline length. - */ - byte CONTROL_SCANLEN = - 4; - - /** - * Flush the display because it has been drawn. - */ - byte CONTROL_FLUSH = - 5; - - /** - * Returns the pixel format of the screen. - * - * @squirreljme.syscallreturn The pixel format of the screen. - */ - byte CONTROL_FORMAT = - 6; - - /** - * Returns the scanline length in bytes. - * - * @squirreljme.syscallreturn The scanline length in bytes. - */ - byte CONTROL_SCANLEN_BYTES = - 7; - - /** - * Returns the number of bytes per pixel. - * - * @squirreljme.syscallreturn The bytes per pixel. - */ - byte CONTROL_BYTES_PER_PIXEL = - 8; - - /** - * Returns the number of available pixels. - * - * @squirreljme.syscallreturn The number of pixels. - */ - byte CONTROL_NUM_PIXELS = - 9; - - /** - * Bits per pixel. - * - * @squirreljme.syscallreturn The bits per pixel. - */ - byte CONTROL_BITS_PER_PIXEL = - 10; - - /** - * Get backlight level. - * - * @squirreljme.syscallreturn The current backlight level. - */ - byte CONTROL_BACKLIGHT_LEVEL_GET = - 11; - - /** - * Set backlight level. - * - * @squirreljme.syscallparam 1 The level to set. - */ - byte CONTROL_BACKLIGHT_LEVEL_SET = - 12; - - /** - * Maximum backlight level. - * - * @squirreljme.syscallreturn The maximum backlight level. - */ - byte CONTROL_BACKLIGHT_LEVEL_MAX = - 13; - - /** - * Uploads an integer array of pixel data to the framebuffer. - * - * @squirreljme.syscallparam 1 The address of the array to upload. - * @since 2019/12/21 - */ - byte CONTROL_UPLOAD_ARRAY_INT = - 14; - - /** - * The array which backs the framebuffer, if there is one. - * - * @squirreljme.syscallreturn The backing array object, if there is one. - * @since 2019/12/28 - */ - byte CONTROL_BACKING_ARRAY_OBJECT = - 15; - - /** - * Returns the capabilities of the display. - * - * @squirreljme.syscallreturn The display capabilities. - * @since 2020/01/10 - */ - byte CONTROL_GET_CAPABILITIES = - 16; - - /** - * Query acceleration function. - * - * @squirreljme.syscallparam 1 The graphics function. - * @squirreljme.syscallreturn A non-zero value if this is supported. - * @since 2020/01/10 - */ - byte CONTROL_ACCEL_FUNC_QUERY = - 17; - - /** - * Perform acceleration function. - * - * @squirreljme.syscallparam 1 The graphics function. - * @squirreljme.syscallparam ... Parameters to the function. - * @squirreljme.syscallreturn A value that is according to the invoked - * function, if it is supported or possible. - * @since 2020/01/10 - */ - byte CONTROL_ACCEL_FUNC_INVOKE = - 18; - - /** - * Requests that the framebuffer be repainted. - * - * @squirreljme.syscallparam 1 The X coordinate. - * @squirreljme.syscallparam 2 The Y coordinate. - * @squirreljme.syscallparam 3 The width. - * @squirreljme.syscallparam 4 The height. - * @squirreljme.syscallreturn Returns {@code 0} if the repaint was not - * queued and it must be handled by the code running the application, - * @since 2020/01/15 - */ - byte CONTROL_REPAINT_REQUEST = - 19; - - /** - * Sets the title of the framebuffer if applicable. - * - * @squirreljme.syscallparam 1 Char buffer pointer (high). - * @squirreljme.syscallparam 2 Char buffer pointer (low). - * @since 2020/01/15 - */ - byte CONTROL_SET_TITLE = - 20; - - /** The number of framebuffer controls. */ - byte NUM_CONTROLS = - 21; - - /** Screen is RGB 32-bit. */ - byte FORMAT_INTEGER_RGB888 = - 0; - - /** Screen is 8-bit indexed. */ - byte FORMAT_BYTE_INDEXED = - 1; - - /** Screen is 16-bit RGB565. */ - byte FORMAT_SHORT_RGB565 = - 2; - - /** Screen is packed 1 bit values. */ - byte FORMAT_PACKED_ONE = - 3; - - /** Screen is packed 2 bit values. */ - byte FORMAT_PACKED_TWO = - 4; - - /** Screen is packed 4 bit values. */ - byte FORMAT_PACKED_FOUR = - 5; - - /** Has touch-screen. */ - byte CAPABILITY_TOUCH = - 0x01; - - /** Has keyboard. */ - byte CAPABILITY_KEYBOARD = - 0x02; - - /** The JVM pushes to the IPC handler when events happen. */ - byte CAPABILITY_IPC_EVENTS = - 0x04; - - /** Has screen flipping? */ - byte CAPABILITY_SCREEN_FLIP = - 0x08; - - /** Screen has color that is not just a single shade. */ - byte CAPABILITY_COLOR = - 0x10; - - /** Set color. */ - byte ACCEL_FUNC_SET_COLOR = - 0; - - /** Draw line. */ - byte ACCEL_FUNC_DRAW_LINE = - 1; - - /** Get the X clip. */ - byte ACCEL_FUNC_GET_CLIP_X = - 2; - - /** Get the Y clip. */ - byte ACCEL_FUNC_GET_CLIP_Y = - 3; - - /** Get the width clip. */ - byte ACCEL_FUNC_GET_CLIP_WIDTH = - 4; - - /** Get the height clip. */ - byte ACCEL_FUNC_GET_CLIP_HEIGHT = - 5; - - /** Set the clip. */ - byte ACCEL_FUNC_SET_CLIP = - 6; - - /** Draw rectangle. */ - byte ACCEL_FUNC_DRAW_RECT = - 7; - - /** Get the alpha color. */ - byte ACCEL_FUNC_GET_ALPHA_COLOR = - 8; - - /** Set the alpha color. */ - byte ACCEL_FUNC_SET_ALPHA_COLOR = - 9; - - /** Fill rectangle. */ - byte ACCEL_FUNC_FILL_RECT = - 10; - - /** Sets the fonts for the graphics. */ - byte ACCEL_FUNC_SET_FONT = - 11; - - /** Gets the font to use for drawing. */ - byte ACCEL_FUNC_GET_FONT = - 12; - - /** Draw sub-characters. */ - byte ACCEL_FUNC_DRAW_SUB_CHARS = - 13; - - /** Draw text. */ - byte ACCEL_FUNC_DRAW_TEXT = - 14; - - /** Get stroke style. */ - byte ACCEL_FUNC_GET_STROKE_STYLE = - 15; - - /** Set stroke style. */ - byte ACCEL_FUNC_SET_STROKE_STYLE = - 16; - - /** Copy area. */ - byte ACCEL_FUNC_COPY_AREA = - 17; - - /** Draw arc. */ - byte ACCEL_FUNC_DRAW_ARC = - 18; - - /** Draw ARGB16. */ - byte ACCEL_FUNC_DRAW_ARGB16 = - 19; - - /** Draw character. */ - byte ACCEL_FUNC_DRAW_CHAR = - 20; - - /** Draw characters. */ - byte ACCEL_FUNC_DRAW_CHARS = - 21; - - /** Draw RGB. */ - byte ACCEL_FUNC_DRAW_RGB = - 22; - - /** Draw RGB16. */ - byte ACCEL_FUNC_DRAW_RGB16 = - 23; - - /** Draw round rectangle. */ - byte ACCEL_FUNC_DRAW_ROUND_RECT = - 24; - - /** Fill arc. */ - byte ACCEL_FUNC_FILL_ARC = - 25; - - /** Fill round rectangle. */ - byte ACCEL_FUNC_FILL_ROUND_RECT = - 26; - - /** Fill triangle. */ - byte ACCEL_FUNC_FILL_TRIANGLE = - 27; - - /** Get blending mode. */ - byte ACCEL_FUNC_GET_BLENDING_MODE = - 28; - - /** Get display color. */ - byte ACCEL_FUNC_GET_DISPLAY_COLOR = - 29; - - /** Set blending mode. */ - byte ACCEL_FUNC_SET_BLENDING_MODE = - 30; - - /** Draw region. */ - byte ACCEL_FUNC_DRAW_REGION = - 31; - - /** Number of acceleration functions. */ - byte NUM_ACCEL_FUNC = - 32; - - /** The IPC ID for the graphics callbacks. */ - int IPC_ID = - 0x47665821; -} - diff --git a/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/MathUtils.java b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/MathUtils.java new file mode 100644 index 0000000000..9c13e17087 --- /dev/null +++ b/modules/cldc-compact/src/main/java/cc/squirreljme/runtime/cldc/util/MathUtils.java @@ -0,0 +1,47 @@ +// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// Multi-Phasic Applications: SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the Mozilla Public License Version 2.0. +// See license.mkd for licensing and copyright information. +// --------------------------------------------------------------------------- + +package cc.squirreljme.runtime.cldc.util; + +import cc.squirreljme.runtime.cldc.annotation.SquirrelJMEVendorApi; + +/** + * Math utilities. + * + * @since 2024/03/17 + */ +@SquirrelJMEVendorApi +public final class MathUtils +{ + /** + * Not used. + * + * @since 2024/03/17 + */ + private MathUtils() + { + } + + + /** + * Rounds to the nearest power of two. + * + * @param __val The value to round. + * @return The resultant rounded value. + * @since 2024/03/17 + */ + public static int nearestPowerOfTwo(int __val) + { + int hi = Math.max(1, Integer.highestOneBit(__val)); + int mask = Math.max(1, hi - 1); + if ((__val & mask) >= (hi >>> 1)) + return hi << 1; + return hi; + } +} diff --git a/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java b/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java index bb1b782946..3379fd1c1e 100644 --- a/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java +++ b/modules/cldc-compact/src/test/java/io/MarkableInputStreamTest.java @@ -9,7 +9,6 @@ package io; -import cc.squirreljme.jvm.Framebuffer; import cc.squirreljme.runtime.cldc.io.MarkableInputStream; import cc.squirreljme.runtime.cldc.util.StreamUtils; import java.io.ByteArrayInputStream; diff --git a/modules/lcdui-demo/build.gradle b/modules/lcdui-demo/build.gradle index 7b675aed9f..92820b539e 100644 --- a/modules/lcdui-demo/build.gradle +++ b/modules/lcdui-demo/build.gradle @@ -11,10 +11,10 @@ squirreljme swmType = JavaMEMidletType.APPLICATION swmName = "LCDUI Graphics Demo" swmVendor = "Stephanie Gawroriski" - midlets += new JavaMEMidlet("Font Demo", "fonts.xpm", - "net.multiphasicapps.lcduidemo.Fonts") midlets += new JavaMEMidlet("Mystify Demo", "mystify.xpm", "net.multiphasicapps.lcduidemo.Mystify") + midlets += new JavaMEMidlet("Font Demo", "fonts.xpm", + "net.multiphasicapps.lcduidemo.Fonts") midlets += new JavaMEMidlet("Events Demo", "event.xpm", "net.multiphasicapps.lcduidemo.Events") midlets += new JavaMEMidlet("List Demo", "list.xpm", diff --git a/modules/lcdui-demo/src/main/java/net/multiphasicapps/lcduidemo/Mystify.java b/modules/lcdui-demo/src/main/java/net/multiphasicapps/lcduidemo/Mystify.java index 7e8812d3a5..30a3005a14 100644 --- a/modules/lcdui-demo/src/main/java/net/multiphasicapps/lcduidemo/Mystify.java +++ b/modules/lcdui-demo/src/main/java/net/multiphasicapps/lcduidemo/Mystify.java @@ -79,9 +79,6 @@ public class Mystify // Set display to the canvas Display.getDisplay(this).setCurrent(cv); - - // Setup thread to force repaints on canvas - new RepaintTimer(cv, Mystify.DELAY_TIME).start(); } /** @@ -209,7 +206,8 @@ public class Mystify this._lockflag = false; // Update some other time in the future - this._nextnano = System.nanoTime() + Mystify.DELAY_TIME_NS; + this._nextnano = System.nanoTime() + + Mystify.DELAY_TIME_NS; } } @@ -227,6 +225,9 @@ public class Mystify __g.drawLine(a.x, a.y, b.x, b.y); } } + + // Request repaint to paint as fast as possible + this.repaint(); } /** diff --git a/nanocoat/.idea/misc.xml b/nanocoat/.idea/misc.xml index c2f631cbfa..e2bb6c7932 100644 --- a/nanocoat/.idea/misc.xml +++ b/nanocoat/.idea/misc.xml @@ -19,10 +19,11 @@ + - \ No newline at end of file + diff --git a/nanocoat/CMakeLists.txt b/nanocoat/CMakeLists.txt index 6508e64877..d5199acfa7 100644 --- a/nanocoat/CMakeLists.txt +++ b/nanocoat/CMakeLists.txt @@ -44,6 +44,9 @@ endif() # Fixes and otherwise for compatibility squirreljme_include("fixes.cmake") +# Hardening options +squirreljme_include("hardening.cmake") + # CMake Utilities, compiled and used during build squirreljme_include("utils.cmake") @@ -87,13 +90,21 @@ if(SQUIRRELJME_IS_DEBUG) endif() endif() -# Valgrind Support on UNIX OSes, if debugging +# Valgrind Support on UNIX OSes, if debugging is enabled if(ANDROID OR SQUIRRELJME_IS_UNIX) if(SQUIRRELJME_IS_DEBUG) squirreljme_include("valgrind.cmake") endif() endif() +# Where should dynamic libraries go when output? +if(NOT DEFINED SQUIRRELJME_DYLIB_OUTPUT_DIR) + set(SQUIRRELJME_DYLIB_OUTPUT_DIR + "${CMAKE_BINARY_DIR}" PARENT_SCOPE) + set(SQUIRRELJME_DYLIB_OUTPUT_DIR + "${CMAKE_BINARY_DIR}") +endif() + # Enable support for testing, this is needed here otherwise testing will not # work at all! Major headache this has caused... # From: https://cmake.org/cmake/help/v3.13/command/enable_testing.html diff --git a/nanocoat/cmake/fixes.cmake b/nanocoat/cmake/fixes.cmake index d202d1f57c..6bdebc020a 100644 --- a/nanocoat/cmake/fixes.cmake +++ b/nanocoat/cmake/fixes.cmake @@ -244,3 +244,42 @@ macro(squirreljme_static_executable target) # "/NODEFAULTLIB:library") endif() endmacro() + +# Force a specific name for the output resultant binary +macro(squirreljme_target_binary_name target what) + # Base properties + set_target_properties(${target} PROPERTIES + RUNTIME_OUTPUT_NAME "${what}" + LIBRARY_OUTPUT_NAME "${what}" + ARCHIVE_OUTPUT_NAME "${what}") + + # Then for each configuration + foreach(outputConfig ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER "${outputConfig}" outputConfig) + + set_target_properties(${target} PROPERTIES + RUNTIME_OUTPUT_NAME_${outputConfig} "${what}" + LIBRARY_OUTPUT_NAME_${outputConfig} "${what}" + ARCHIVE_OUTPUT_NAME_${outputConfig} "${what}") + endforeach() +endmacro() + +# Need to set specific locations for output libraries? +# Note that RUNTIME_OUTPUT_DIRECTORY is needed for the Windows build to output +# directories since .DLL files are output there and not where shared libraries +# go??? No idea really. +macro(squirreljme_target_binary_output target where) + set_target_properties(${target} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY "${where}" + LIBRARY_OUTPUT_DIRECTORY "${where}" + ARCHIVE_OUTPUT_DIRECTORY "${where}") + + foreach(outputConfig ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER "${outputConfig}" outputConfig) + + set_target_properties(${target} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY_${outputConfig} "${where}" + LIBRARY_OUTPUT_DIRECTORY_${outputConfig} "${where}" + ARCHIVE_OUTPUT_DIRECTORY_${outputConfig} "${where}") + endforeach() +endmacro() diff --git a/nanocoat/cmake/hardening.cmake b/nanocoat/cmake/hardening.cmake new file mode 100644 index 0000000000..f6b6547f7c --- /dev/null +++ b/nanocoat/cmake/hardening.cmake @@ -0,0 +1,20 @@ +# --------------------------------------------------------------------------- +# SquirrelJME +# Copyright (C) Stephanie Gawroriski +# --------------------------------------------------------------------------- +# SquirrelJME is under the Mozilla Public License Version 2.0. +# See license.mkd for licensing and copyright information. +# --------------------------------------------------------------------------- +# DESCRIPTION: Various hardening options. + +# For RetroArch disable specific features so they cannot be used +if(LIBRETRO) + # Disable dynamic library support, we do not want to allow loading + # native libraries of any kind + add_compile_definitions(SJME_CONFIG_HAS_NO_DYLIB_SUPPORT=1) + + # Disable ScritchUI dynamic libraries + add_custom_command(SJME_CONFIG_SCRITCHUI_NO_DYLIB=1) + set(SQUIRRELJME_SCRITCHUI_NO_DYLIB ON) + set(SQUIRRELJME_SCRITCHUI_NO_DYLIB ON PARENT_SCOPE) +endif() diff --git a/nanocoat/cmake/utils.cmake b/nanocoat/cmake/utils.cmake index 27bd7de9b3..cf29c7a7fd 100644 --- a/nanocoat/cmake/utils.cmake +++ b/nanocoat/cmake/utils.cmake @@ -37,6 +37,7 @@ if(NOT EXISTS "${SQUIRRELJME_UTIL_DIR}" OR # Note message(STATUS "Bootstrapping utils into " "${SQUIRRELJME_UTIL_DIR}...") + message(STATUS "Current generator is ${CMAKE_GENERATOR}...") # Run nested CMake to build the utilities if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.13") @@ -60,6 +61,7 @@ if(NOT EXISTS "${SQUIRRELJME_UTIL_DIR}" OR "--unset=LDFLAGS" "${CMAKE_COMMAND}" "-DCMAKE_BUILD_TYPE=Debug" + "-G" "${CMAKE_GENERATOR}" "-S" "${SQUIRRELJME_UTIL_SOURCE_DIR}" "-B" "${SQUIRRELJME_UTIL_DIR}" RESULT_VARIABLE cmakeUtilBuildResult) @@ -85,6 +87,7 @@ if(NOT EXISTS "${SQUIRRELJME_UTIL_DIR}" OR "--unset=LDFLAGS" "${CMAKE_COMMAND}" "-DCMAKE_BUILD_TYPE=Debug" + "-G" "${CMAKE_GENERATOR}" "${SQUIRRELJME_UTIL_SOURCE_DIR}" WORKING_DIRECTORY "${SQUIRRELJME_UTIL_DIR}" RESULT_VARIABLE cmakeUtilConfigResult) diff --git a/nanocoat/frontend/emulator/CMakeLists.txt b/nanocoat/frontend/emulator/CMakeLists.txt index 785b2b6531..049d4342bc 100644 --- a/nanocoat/frontend/emulator/CMakeLists.txt +++ b/nanocoat/frontend/emulator/CMakeLists.txt @@ -40,25 +40,9 @@ target_include_directories(libEmulator PUBLIC ${JNI_INCLUDE_DIRS}) # It is easier to find this when it is in the build root -set_target_properties(libEmulator PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") - -foreach(outputConfig ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER "${outputConfig}" outputConfig) - - set_target_properties(libEmulator PROPERTIES - RUNTIME_OUTPUT_DIRECTORY_${outputConfig} "${CMAKE_BINARY_DIR}" - LIBRARY_OUTPUT_DIRECTORY_${outputConfig} "${CMAKE_BINARY_DIR}" - ARCHIVE_OUTPUT_DIRECTORY_${outputConfig} "${CMAKE_BINARY_DIR}") -endforeach() +squirreljme_target_binary_output(libEmulator + "${SQUIRRELJME_DYLIB_OUTPUT_DIR}") # Use a simpler name for the library -set_target_properties(libEmulator PROPERTIES - RUNTIME_OUTPUT_NAME - "emulator-nanocoat" - LIBRARY_OUTPUT_NAME - "emulator-nanocoat" - ARCHIVE_OUTPUT_NAME +squirreljme_target_binary_name(libEmulator "emulator-nanocoat") diff --git a/nanocoat/frontend/libjvm/CMakeLists.txt b/nanocoat/frontend/libjvm/CMakeLists.txt index dac08a42b6..20da31440c 100644 --- a/nanocoat/frontend/libjvm/CMakeLists.txt +++ b/nanocoat/frontend/libjvm/CMakeLists.txt @@ -33,11 +33,6 @@ target_include_directories(libJvm PUBLIC ${JNI_INCLUDE_DIRS}) # Use a conforming name for the library -set_target_properties(libJvm PROPERTIES - RUNTIME_OUTPUT_DIRECTORY - "jvm" - LIBRARY_OUTPUT_NAME - "jvm" - ARCHIVE_OUTPUT_NAME +squirreljme_target_binary_name(libJvm "jvm") diff --git a/nanocoat/frontend/libretro/CMakeLists.txt b/nanocoat/frontend/libretro/CMakeLists.txt index 43103cb249..06dc579306 100644 --- a/nanocoat/frontend/libretro/CMakeLists.txt +++ b/nanocoat/frontend/libretro/CMakeLists.txt @@ -56,23 +56,12 @@ add_dependencies(squirreljme_libretro ${libRetroCore}) # Name must be specifically set for RetroArch for it to work properly -if(ANDROID OR - (DEFINED ANDROID_PLATFORM AND ANDROID_PLATFORM)) - set_target_properties(squirreljme_libretro PROPERTIES - RUNTIME_OUTPUT_DIRECTORY - "squirreljme_libretro_android" - LIBRARY_OUTPUT_NAME - "squirreljme_libretro_android" - ARCHIVE_OUTPUT_NAME - "squirreljme_libretro_android") +if(ANDROID OR (DEFINED ANDROID_PLATFORM AND ANDROID_PLATFORM)) + squirreljme_target_binary_name(squirreljme_libretro + "squirreljme_libretro_android") else() - set_target_properties(squirreljme_libretro PROPERTIES - RUNTIME_OUTPUT_NAME - "squirreljme_libretro${LIBRETRO_SUFFIX}" - LIBRARY_OUTPUT_NAME - "squirreljme_libretro${LIBRETRO_SUFFIX}" - ARCHIVE_OUTPUT_NAME - "squirreljme_libretro${LIBRETRO_SUFFIX}") + squirreljme_target_binary_name(squirreljme_libretro + "squirreljme_libretro${LIBRETRO_SUFFIX}") endif() # Library location must be placed in the build output for the RetroArch @@ -80,19 +69,8 @@ endif() # Note that RUNTIME_OUTPUT_DIRECTORY is needed for the Windows build to output # directories since .DLL files are output there and not where shared libraries # go??? No idea really. -set_target_properties(squirreljme_libretro PROPERTIES - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") - -foreach(outputConfig ${CMAKE_CONFIGURATION_TYPES}) - string(TOUPPER "${outputConfig}" outputConfig) - - set_target_properties(squirreljme_libretro PROPERTIES - RUNTIME_OUTPUT_DIRECTORY_${outputConfig} "${CMAKE_BINARY_DIR}" - LIBRARY_OUTPUT_DIRECTORY_${outputConfig} "${CMAKE_BINARY_DIR}" - ARCHIVE_OUTPUT_DIRECTORY_${outputConfig} "${CMAKE_BINARY_DIR}") -endforeach() +squirreljme_target_binary_output(squirreljme_libretro + "${SQUIRRELJME_DYLIB_OUTPUT_DIR}") # RetroArch does not use any prefixes like "lib" for the cores set_target_properties(squirreljme_libretro PROPERTIES diff --git a/nanocoat/include/sjme/dylib.h b/nanocoat/include/sjme/dylib.h new file mode 100644 index 0000000000..2b1349aa98 --- /dev/null +++ b/nanocoat/include/sjme/dylib.h @@ -0,0 +1,86 @@ +/* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the Mozilla Public License Version 2.0. +// See license.mkd for licensing and copyright information. +// -------------------------------------------------------------------------*/ + +/** + * Dynamic Library loading. + * + * @since 2024/03/27 + */ + +#ifndef SQUIRRELJME_DYLIB_H +#define SQUIRRELJME_DYLIB_H + +#include "sjme/nvm.h" + +/* Anti-C++. */ +#ifdef __cplusplus + #ifndef SJME_CXX_IS_EXTERNED + #define SJME_CXX_IS_EXTERNED + #define SJME_CXX_SQUIRRELJME_DYLIB_H +extern "C" { + #endif /* #ifdef SJME_CXX_IS_EXTERNED */ +#endif /* #ifdef __cplusplus */ + +/*--------------------------------------------------------------------------*/ + +/** + * Opaque dynamic library type. + * + * @since 2024/03/27 + */ +typedef void* sjme_dylib; + +/** + * Closes the given dynamic library. + * + * @param inLib The library to close. + * @return Any error if it occurs. + * @since 2024/03/27 + */ +sjme_errorCode sjme_dylib_close( + sjme_attrInNotNull sjme_dylib inLib); + +/** + * Looks up the given symbol in the library. + * + * @param inLib The library to look within. + * @param inSymbol The symbol to obtain from the library. + * @param outPtr The resultant pointer of the symbol. + * @return Any error if it occurs. + * @since 2024/03/27 + */ +sjme_errorCode sjme_dylib_lookup( + sjme_attrInNotNull sjme_dylib inLib, + sjme_attrInNotNull sjme_lpcstr inSymbol, + void* outPtr); + +/** + * Opens a dynamic library. + * + * @param libPath The path to the library to open. + * @param outLib The resultant opened library. + * @return Any error if it occurs. + * @since 2024/03/27 + */ +sjme_errorCode sjme_dylib_open( + sjme_attrInNotNull sjme_lpcstr libPath, + sjme_attrInOutNotNull sjme_dylib* outLib); + +/*--------------------------------------------------------------------------*/ + +/* Anti-C++. */ +#ifdef __cplusplus + #ifdef SJME_CXX_SQUIRRELJME_DYLIB_H +} + #undef SJME_CXX_SQUIRRELJME_DYLIB_H + #undef SJME_CXX_IS_EXTERNED + #endif /* #ifdef SJME_CXX_SQUIRRELJME_DYLIB_H */ +#endif /* #ifdef __cplusplus */ + +#endif /* SQUIRRELJME_DYLIB_H */ diff --git a/nanocoat/src/CMakeLists.txt b/nanocoat/src/CMakeLists.txt index 4372e1c0dc..d0d7f30412 100644 --- a/nanocoat/src/CMakeLists.txt +++ b/nanocoat/src/CMakeLists.txt @@ -16,6 +16,7 @@ list(APPEND coreSources comparator.c debug.c descriptor.c + dylib.c error.c except.c gfx.c diff --git a/nanocoat/src/dylib.c b/nanocoat/src/dylib.c new file mode 100644 index 0000000000..e18deb8a4d --- /dev/null +++ b/nanocoat/src/dylib.c @@ -0,0 +1,47 @@ +/* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*- +// --------------------------------------------------------------------------- +// SquirrelJME +// Copyright (C) Stephanie Gawroriski +// --------------------------------------------------------------------------- +// SquirrelJME is under the Mozilla Public License Version 2.0. +// See license.mkd for licensing and copyright information. +// -------------------------------------------------------------------------*/ + +#include "sjme/dylib.h" +#include "sjme/debug.h" + +sjme_errorCode sjme_dylib_close( + sjme_attrInNotNull sjme_dylib inLib) +{ +#if defined(SJME_CONFIG_HAS_NO_DYLIB_SUPPORT) + return SJME_ERROR_UNSUPPORTED_OPERATION; +#else + sjme_todo("Impl?"); + return SJME_ERROR_NOT_IMPLEMENTED; +#endif +} + +sjme_errorCode sjme_dylib_lookup( + sjme_attrInNotNull sjme_dylib inLib, + sjme_attrInNotNull sjme_lpcstr inSymbol, + void* outPtr) +{ +#if defined(SJME_CONFIG_HAS_NO_DYLIB_SUPPORT) + return SJME_ERROR_UNSUPPORTED_OPERATION; +#else + sjme_todo("Impl?"); + return SJME_ERROR_NOT_IMPLEMENTED; +#endif +} + +sjme_errorCode sjme_dylib_open( + sjme_attrInNotNull sjme_lpcstr libPath, + sjme_attrInOutNotNull sjme_dylib* outLib) +{ +#if defined(SJME_CONFIG_HAS_NO_DYLIB_SUPPORT) + return SJME_ERROR_UNSUPPORTED_OPERATION; +#else + sjme_todo("Impl?"); + return SJME_ERROR_NOT_IMPLEMENTED; +#endif +} -- 2.11.4.GIT