forked from MrCrayfish/MrCrayfishDeviceMod
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
331 changed files
with
4,573 additions
and
1,285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
common/src/api/java/dev/ultreon/devices/api/bios/Bios.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
47
common/src/api/java/dev/ultreon/devices/api/bios/BiosCallType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
common/src/api/java/dev/ultreon/devices/api/bios/BiosInterruptType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} |
36 changes: 36 additions & 0 deletions
36
common/src/api/java/dev/ultreon/devices/api/bios/FrameBufferCall.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.