Skip to content

Commit

Permalink
Laggggggg
Browse files Browse the repository at this point in the history
  • Loading branch information
XyperCode committed Aug 8, 2024
1 parent 93ec156 commit b328a91
Show file tree
Hide file tree
Showing 331 changed files with 4,573 additions and 1,285 deletions.
65 changes: 62 additions & 3 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,41 @@ architectury {
common platforms.split(",")
}

sourceSets {
api {
java {
srcDirs += [
"src/api/java"
]
}
}

mineos {
java {
srcDirs += [
"src/mineos/java"
]
}

runtimeClasspath += sourceSets.api.output
compileClasspath += sourceSets.api.output
}

main {
resources {
srcDirs += [
"src/main/generated/resources"
]
}

runtimeClasspath += sourceSets.api.output
compileClasspath += sourceSets.api.output

runtimeClasspath += sourceSets.mineos.output
compileClasspath += sourceSets.mineos.output
}
}

loom {
accessWidenerPath = file "src/main/resources/devices.accesswidener"
}
Expand All @@ -12,25 +47,27 @@ repositories {
}

dependencies {
apiImplementation 'org.jetbrains:annotations:24.0.0'
mineosImplementation 'org.jetbrains:annotations:24.0.0'
mineosImplementation "org.apache.commons:commons-compress:1.26.1"

// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:$fabric_loader_version"
// Remove the next line if you don't want to depend on the API
modApi "dev.architectury:architectury:$architectury_version"

implementation("io.github.ultreon:ubo:1.3.0")

modApi "fuzs.forgeconfigapiport:forgeconfigapiport-common-neoforgeapi:$forgeconfigapiport_version"

implementation project(":api")
implementation "org.jetbrains.kotlin:kotlin-reflect:1.7.10"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10"
// modApi "com.ultreon:ultranlang:0.1.0+6"

modCompileOnly "fuzs.forgeconfigapiport:forgeconfigapiport-common:8.0.0"
modCompileOnly 'com.electronwill.night-config:core:3.6.3'
modCompileOnly 'com.electronwill.night-config:toml:3.6.3'

implementation("de.waldheinz:fat32-lib:0.6.5")
}

sourceSets {
Expand All @@ -44,6 +81,28 @@ sourceSets {
}
}

jar {
from("LICENSE") {
rename { "${it}_${archivesBaseName}" }
}

from(sourceSets.api.output)
}

tasks.register("mineosJar", Jar) {
archiveBaseName = "MineOS"
archiveVersion = "1.0.0"
archiveClassifier = null

duplicatesStrategy = DuplicatesStrategy.EXCLUDE

from("LICENSE") {
rename { "${it}_MineOS" }
}

from(sourceSets.mineos.output)
}

publishing {
publications {
mavenCommon(MavenPublication) {
Expand Down
177 changes: 177 additions & 0 deletions common/src/api/java/dev/ultreon/devices/api/IO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package dev.ultreon.devices.api;

import java.io.EOFException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public interface IO {
IO NULL = new IO() {
@Override
public int get(int index) {
return -1;
}

@Override
public boolean set(int index, int value) {
return false;
}

@Override
public long size() {
return 0;
}
};

default int read(byte[] buffer, int address, int length) throws EOFException {
for (int i = 0; i < length; i++) {
int aByte = get(address + i);
if (aByte == -1) throw new EOFException("End of device reached");
buffer[i] = (byte) aByte;
}
return length;
}

default void write(byte[] buffer, int address, int length) throws EOFException {
for (int i = 0; i < length; i++) {
if (!set(address + i, buffer[i])) {
throw new EOFException("End of device reached");
}
}
}

int get(int index);

default byte getByte(int index) throws IOException {
if (index < 0) {
throw new IOException("Index out of bounds");
}

int b = get(index);
if (b == -1) {
throw new EOFException("End of device reached");
}
return (byte) b;
}
default short getShort(int index) throws IOException {
byte b1 = getByte(index);
byte b2 = getByte(index + 1);
return (short) ((b1 << 8) | (b2 & 0xFF));
}
default int getInt(int index) throws IOException {
byte b1 = getByte(index);
byte b2 = getByte(index + 1);
byte b3 = getByte(index + 2);
byte b4 = getByte(index + 3);
return (b1 << 24) | ((b2 & 0xFF) << 16) | ((b3 & 0xFF) << 8) | (b4 & 0xFF);
}
default long getLong(int index) throws IOException {
byte b1 = getByte(index);
byte b2 = getByte(index + 1);
byte b3 = getByte(index + 2);
byte b4 = getByte(index + 3);
byte b5 = getByte(index + 4);
byte b6 = getByte(index + 5);
byte b7 = getByte(index + 6);
byte b8 = getByte(index + 7);
return ((long) b1 << 56) | ((b2 & 0xFFL) << 48) | ((b3 & 0xFFL) << 40) | ((b4 & 0xFFL) << 32) | ((b5 & 0xFFL) << 24) | ((b6 & 0xFFL) << 16) | ((b7 & 0xFFL) << 8) | (b8 & 0xFFL);
}
default float getFloat(int index) throws IOException {
byte b1 = getByte(index);
byte b2 = getByte(index + 1);
byte b3 = getByte(index + 2);
byte b4 = getByte(index + 3);
return Float.intBitsToFloat((b1 << 24) | ((b2 & 0xFF) << 16) | ((b3 & 0xFF) << 8) | (b4 & 0xFF));
}
default double getDouble(int index) throws IOException {
byte b1 = getByte(index);
byte b2 = getByte(index + 1);
byte b3 = getByte(index + 2);
byte b4 = getByte(index + 3);
byte b5 = getByte(index + 4);
byte b6 = getByte(index + 5);
byte b7 = getByte(index + 6);
byte b8 = getByte(index + 7);

long l = ((long) b1 << 56) | ((b2 & 0xFFL) << 48) | ((b3 & 0xFFL) << 40) | ((b4 & 0xFFL) << 32) | ((b5 & 0xFFL) << 24) | ((b6 & 0xFFL) << 16) | ((b7 & 0xFFL) << 8) | (b8 & 0xFFL);
return Double.longBitsToDouble(l);
}
default char getChar(int index) throws IOException {
byte b1 = getByte(index);
byte b2 = getByte(index + 1);
return (char) ((b1 << 8) | (b2 & 0xFF));
}
default String getString(int index) throws IOException {
int length = getInt(index);
byte[] bytes = getBytes(index + 4, length);
return new String(bytes, StandardCharsets.UTF_8);
}
default byte[] getBytes(int index, int length) throws IOException {
byte[] bytes = new byte[length];
if (read(bytes, index, length) != length) {
throw new EOFException("End of device reached");
}
return bytes;
}

boolean set(int index, int value);

default void setByte(int index, byte value) throws IOException {
if (!set(index, value)) {
throw new EOFException("End of device reached");
}
}
default void setShort(int index, short value) throws IOException {
setByte(index, (byte) (value >> 8));
setByte(index + 1, (byte) (value & 0xFF));
}
default void setInt(int index, int value) throws IOException {
setByte(index, (byte) (value >> 24));
setByte(index + 1, (byte) ((value >> 16) & 0xFF));
setByte(index + 2, (byte) ((value >> 8) & 0xFF));
setByte(index + 3, (byte) (value & 0xFF));
}
default void setLong(int index, long value) throws IOException {
setByte(index, (byte) (value >> 56));
setByte(index + 1, (byte) ((value >> 48) & 0xFF));
setByte(index + 2, (byte) ((value >> 40) & 0xFF));
setByte(index + 3, (byte) ((value >> 32) & 0xFF));
setByte(index + 4, (byte) ((value >> 24) & 0xFF));
setByte(index + 5, (byte) ((value >> 16) & 0xFF));
setByte(index + 6, (byte) ((value >> 8) & 0xFF));
setByte(index + 7, (byte) (value & 0xFF));
}
default void setFloat(int index, float value) throws IOException {
int i = Float.floatToIntBits(value);
setByte(index, (byte) (i >> 24));
setByte(index + 1, (byte) ((i >> 16) & 0xFF));
setByte(index + 2, (byte) ((i >> 8) & 0xFF));
setByte(index + 3, (byte) (i & 0xFF));
}
default void setDouble(int index, double value) throws IOException {
long l = Double.doubleToLongBits(value);
setByte(index, (byte) (l >> 56));
setByte(index + 1, (byte) ((l >> 48) & 0xFF));
setByte(index + 2, (byte) ((l >> 40) & 0xFF));
setByte(index + 3, (byte) ((l >> 32) & 0xFF));
setByte(index + 4, (byte) ((l >> 24) & 0xFF));
setByte(index + 5, (byte) ((l >> 16) & 0xFF));
setByte(index + 6, (byte) ((l >> 8) & 0xFF));
setByte(index + 7, (byte) (l & 0xFF));
}
default void setChar(int index, char value) throws IOException {
setByte(index, (byte) (value >> 8));
setByte(index + 1, (byte) (value & 0xFF));
}
default void setString(int index, String value) throws IOException {
byte[] bytes = value.getBytes(StandardCharsets.UTF_8);
setInt(index, bytes.length);
setBytes(index + 4, bytes);
}
default void setBytes(int index, byte[] value) throws IOException {
for (int i = 0; i < value.length; i++) {
setByte(index + i, value[i]);
}
}

long size();
}
15 changes: 15 additions & 0 deletions common/src/api/java/dev/ultreon/devices/api/bios/Bios.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dev.ultreon.devices.api.bios;

import dev.ultreon.devices.api.bios.efi.VEFI_System;

public interface Bios {
void registerInterrupt(BiosInterruptType interrupt, InterruptHandler handler);

Object call(BiosCallType call, Object[] args);

void enableInterrupts();

void disableInterrupts();

VEFI_System getVEFISystem();
}
47 changes: 47 additions & 0 deletions common/src/api/java/dev/ultreon/devices/api/bios/BiosCallType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package dev.ultreon.devices.api.bios;

import dev.ultreon.devices.api.bios.efi.*;

public enum BiosCallType {
POWER_OFF(void.class),
REBOOT(void.class),
ENTER_SLEEP(void.class),
EXIT_SLEEP(void.class),

REBOOT_TO_FIRMWARE(void.class),

GET_DEVICE_ID(void.class),
GET_RUNNING_OS(String.class),
GET_MAIN_DRIVE(VEFI_DiskInfo.class),
SET_MAIN_DRIVE(void.class, VEFI_DiskInfo.class),
ADD_SYSTEM(void.class, VEFI_File.class),
SEND_NOTIFICATION(VEFI_Notification.class),
GET_DEVICE_INFO(VEFI_DeviceInfo.class),

GET_VIDEO_INFO(VEFI_VideoSize.class),
OPEN_DISPLAY(int.class),
CLOSE_DISPLAY(void.class),
GET_BOOT_DEVICE_ID(VEFI_DeviceID.class),
FRAMEBUFFER_CALL(FrameBufferCall.class),
ENTER_USERSPACE(void.class, String.class, String.class, ClassLoader.class),;

public final Class<?> returnType;
public final Class<?>[] parameters;

BiosCallType(Class<?> returnType) {
this(returnType, new Class<?>[0]);
}

BiosCallType(Class<?> returnType, Class<?>... parameters) {
this.returnType = returnType;
this.parameters = parameters;
}

public Class<?> getReturnType() {
return returnType;
}

public Class<?>[] getParameters() {
return parameters;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package dev.ultreon.devices.api.bios;

public enum BiosInterruptType {
DOUBLE_FAULT,
FAULT,
POWER_BUTTON,
KEYBOARD,
MOUSE,
IO_ERROR,
FRAMEBUFFER_INTERRUPT,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package dev.ultreon.devices.api.bios;

import java.nio.ByteBuffer;

public enum FrameBufferCall {
GET_INFO(FrameBufferInfo.class), // -> FrameBufferInfo
READ_PIXELS(void.class, ByteBuffer.class, int.class, int.class, int.class, int.class), // buffer, x, y, width, height -> void
READ_PIXEL(int.class, short.class, short.class), // x, y -> color
WRITE_PIXEL(void.class, short.class, short.class, int.class), // x, y, color -> void

FILL_RECT(void.class, int.class, int.class, int.class, int.class, int.class), // x, y, width, height, color -> void
DRAW_RECT(void.class, int.class, int.class, int.class, int.class, int.class), // x, y, width, height, color -> void
DRAW_TEXT(void.class, int.class, int.class, String.class, int.class), // x, y, text, color -> void
DRAW_ITEM(void.class, String.class, int.class, int.class, int.class), // registry-name, count, x, y -> void
DRAW_IMAGE(void.class, String.class, int.class, int.class, int.class, int.class), // registry-name, x, y, width, height -> void

CLEAR(void.class),
BLIT(void.class, String.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class, int.class), // id, x, y, width, height, src-x, src-y, src-width, src-height, tex-width, tex-height -> void
;

private final Class<?> returnType;
private final Class<?>[] parameters;

FrameBufferCall(Class<?> returnType, Class<?>... parameters) {
this.returnType = returnType;
this.parameters = parameters;
}

public Class<?> getReturnType() {
return returnType;
}

public Class<?>[] getParameters() {
return parameters;
}
}
Loading

0 comments on commit b328a91

Please sign in to comment.