-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jni: WIP High-level binding wrappers
- Attempt to implement simple, high-level Java wrappers - Supports building most of RVVM machine & device configurations, except explicitly specifying device addresses and IRQs (Only auto building is supported) - Supports framebuffers, mouse/keyboard input, GPIO, NVMe, RTL8169 and many basic devices - No support for custom MMIO/PCI/I2C/Chardev devices implemented on Java side yet. This will be worked on later (See class MMIOBase) - This likely should allow proper Android RVVM port (With native GUI), also will also be used for another side project - For Android app, some kind of VT emulation is needed, and probably support for Java-side character devices. I am working on a chardev_vt implementation for RVVM in the meantime, with a special VT API so we can emulate VT on RVVM side (and also suspend them properly), and then render the provided character display on the outside. - Willing for advice on improving this
- Loading branch information
Showing
18 changed files
with
657 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class Framebuffer extends MMIODevice { | ||
protected int width; | ||
protected int height; | ||
protected int bpp; | ||
protected ByteBuffer buff; | ||
|
||
public static final int BPP_R5G6B5 = 16; | ||
public static final int BPP_R8G8B8 = 24; | ||
public static final int BPP_A8R8G8B8 = 32; | ||
|
||
public Framebuffer(RVVMMachine machine, int x, int y) { | ||
this(machine, x, y, BPP_A8R8G8B8); | ||
} | ||
|
||
public Framebuffer(RVVMMachine machine, int x, int y, int bpp) { | ||
super(machine); | ||
this.width = x; | ||
this.height = y; | ||
this.bpp = bpp; | ||
this.buff = ByteBuffer.allocateDirect(x * y * (bpp / 8)); | ||
if (machine.isValid()) { | ||
this.mmio_handle = RVVMNative.framebuffer_init_auto(machine.machine, this.buff, x, y, bpp); | ||
} | ||
} | ||
|
||
public ByteBuffer getBuffer() { | ||
return buff; | ||
} | ||
public int getWidth() { | ||
return width; | ||
} | ||
public int getHeight() { | ||
return height; | ||
} | ||
public int getBpp() { | ||
return bpp; | ||
} | ||
} |
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,38 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
public class GPIODevice extends MMIODevice { | ||
protected long gpio_dev; | ||
|
||
public GPIODevice(RVVMMachine machine) { | ||
super(machine); | ||
if (machine.isValid()) { | ||
gpio_dev = RVVMNative.gpio_dev_create(); | ||
} else { | ||
gpio_dev = 0; | ||
} | ||
} | ||
|
||
public boolean write_pins(int offset, int pins) { | ||
if (gpio_dev != 0) return RVVMNative.gpio_write_pins(gpio_dev, offset, pins); | ||
return false; | ||
} | ||
|
||
public int read_pins(int offset) { | ||
if (gpio_dev != 0) return RVVMNative.gpio_read_pins(gpio_dev, offset); | ||
return 0; | ||
} | ||
|
||
public boolean write_pins(int pins) { | ||
return write_pins(0, pins); | ||
} | ||
|
||
public int read_pins() { | ||
return read_pins(0); | ||
} | ||
} |
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,16 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
public class GoldfishRTC extends MMIODevice { | ||
public GoldfishRTC(RVVMMachine machine) { | ||
super(machine); | ||
if (machine.isValid()) { | ||
this.mmio_handle = RVVMNative.rtc_goldfish_init_auto(machine.machine); | ||
} | ||
} | ||
} |
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,170 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
public class HIDKeyboard { | ||
private RVVMMachine machine; | ||
private final long hid_keyboard; | ||
|
||
// Keyboard keycode definitions | ||
public static final byte HID_KEY_NONE = 0x00; | ||
|
||
// Typing keys | ||
public static final byte HID_KEY_A = 0x04; | ||
public static final byte HID_KEY_B = 0x05; | ||
public static final byte HID_KEY_C = 0x06; | ||
public static final byte HID_KEY_D = 0x07; | ||
public static final byte HID_KEY_E = 0x08; | ||
public static final byte HID_KEY_F = 0x09; | ||
public static final byte HID_KEY_G = 0x0a; | ||
public static final byte HID_KEY_H = 0x0b; | ||
public static final byte HID_KEY_I = 0x0c; | ||
public static final byte HID_KEY_J = 0x0d; | ||
public static final byte HID_KEY_K = 0x0e; | ||
public static final byte HID_KEY_L = 0x0f; | ||
public static final byte HID_KEY_M = 0x10; | ||
public static final byte HID_KEY_N = 0x11; | ||
public static final byte HID_KEY_O = 0x12; | ||
public static final byte HID_KEY_P = 0x13; | ||
public static final byte HID_KEY_Q = 0x14; | ||
public static final byte HID_KEY_R = 0x15; | ||
public static final byte HID_KEY_S = 0x16; | ||
public static final byte HID_KEY_T = 0x17; | ||
public static final byte HID_KEY_U = 0x18; | ||
public static final byte HID_KEY_V = 0x19; | ||
public static final byte HID_KEY_W = 0x1a; | ||
public static final byte HID_KEY_X = 0x1b; | ||
public static final byte HID_KEY_Y = 0x1c; | ||
public static final byte HID_KEY_Z = 0x1d; | ||
|
||
// Number keys | ||
public static final byte HID_KEY_1 = 0x1e; | ||
public static final byte HID_KEY_2 = 0x1f; | ||
public static final byte HID_KEY_3 = 0x20; | ||
public static final byte HID_KEY_4 = 0x21; | ||
public static final byte HID_KEY_5 = 0x22; | ||
public static final byte HID_KEY_6 = 0x23; | ||
public static final byte HID_KEY_7 = 0x24; | ||
public static final byte HID_KEY_8 = 0x25; | ||
public static final byte HID_KEY_9 = 0x26; | ||
public static final byte HID_KEY_0 = 0x27; | ||
|
||
// Control keys | ||
public static final byte HID_KEY_ENTER = 0x28; | ||
public static final byte HID_KEY_ESC = 0x29; | ||
public static final byte HID_KEY_BACKSPACE = 0x2a; | ||
public static final byte HID_KEY_TAB = 0x2b; | ||
public static final byte HID_KEY_SPACE = 0x2c; | ||
public static final byte HID_KEY_MINUS = 0x2d; | ||
public static final byte HID_KEY_EQUAL = 0x2e; | ||
public static final byte HID_KEY_LEFTBRACE = 0x2f; // Button [ { | ||
public static final byte HID_KEY_RIGHTBRACE = 0x30; // Button ] } | ||
public static final byte HID_KEY_BACKSLASH = 0x31; | ||
public static final byte HID_KEY_HASHTILDE = 0x32; // Button # ~ (Huh? Never seen one.) | ||
public static final byte HID_KEY_SEMICOLON = 0x33; // Button ; : | ||
public static final byte HID_KEY_APOSTROPHE = 0x34; // Button ' " | ||
public static final byte HID_KEY_GRAVE = 0x35; // Button ` ~ (For dummies: Quake console button) | ||
public static final byte HID_KEY_COMMA = 0x36; // Button , < | ||
public static final byte HID_KEY_DOT = 0x37; // Button . > | ||
public static final byte HID_KEY_SLASH = 0x38; | ||
public static final byte HID_KEY_CAPSLOCK = 0x39; | ||
|
||
public static final byte HID_KEY_LEFTCTRL = (byte)0xe0; | ||
public static final byte HID_KEY_LEFTSHIFT = (byte)0xe1; | ||
public static final byte HID_KEY_LEFTALT = (byte)0xe2; | ||
public static final byte HID_KEY_LEFTMETA = (byte)0xe3; // The one with the ugly Windows icon | ||
public static final byte HID_KEY_RIGHTCTRL = (byte)0xe4; | ||
public static final byte HID_KEY_RIGHTSHIFT = (byte)0xe5; | ||
public static final byte HID_KEY_RIGHTALT = (byte)0xe6; | ||
public static final byte HID_KEY_RIGHTMETA = (byte)0xe7; | ||
|
||
// Function keys | ||
public static final byte HID_KEY_F1 = 0x3a; | ||
public static final byte HID_KEY_F2 = 0x3b; | ||
public static final byte HID_KEY_F3 = 0x3c; | ||
public static final byte HID_KEY_F4 = 0x3d; | ||
public static final byte HID_KEY_F5 = 0x3e; | ||
public static final byte HID_KEY_F6 = 0x3f; | ||
public static final byte HID_KEY_F7 = 0x40; | ||
public static final byte HID_KEY_F8 = 0x41; | ||
public static final byte HID_KEY_F9 = 0x42; | ||
public static final byte HID_KEY_F10 = 0x43; | ||
public static final byte HID_KEY_F11 = 0x44; | ||
public static final byte HID_KEY_F12 = 0x45; | ||
|
||
public static final byte HID_KEY_F13 = 0x68; | ||
public static final byte HID_KEY_F14 = 0x69; | ||
public static final byte HID_KEY_F15 = 0x6a; | ||
public static final byte HID_KEY_F16 = 0x6b; | ||
public static final byte HID_KEY_F17 = 0x6c; | ||
public static final byte HID_KEY_F18 = 0x6d; | ||
public static final byte HID_KEY_F19 = 0x6e; | ||
public static final byte HID_KEY_F20 = 0x6f; | ||
public static final byte HID_KEY_F21 = 0x70; | ||
public static final byte HID_KEY_F22 = 0x71; | ||
public static final byte HID_KEY_F23 = 0x72; | ||
public static final byte HID_KEY_F24 = 0x73; | ||
|
||
// Editing keys | ||
public static final byte HID_KEY_SYSRQ = 0x46; // Print Screen (REISUB, anyone?) | ||
public static final byte HID_KEY_SCROLLLOCK = 0x47; | ||
public static final byte HID_KEY_PAUSE = 0x48; | ||
public static final byte HID_KEY_INSERT = 0x49; | ||
public static final byte HID_KEY_HOME = 0x4a; | ||
public static final byte HID_KEY_PAGEUP = 0x4b; | ||
public static final byte HID_KEY_DELETE = 0x4c; | ||
public static final byte HID_KEY_END = 0x4d; | ||
public static final byte HID_KEY_PAGEDOWN = 0x4e; | ||
public static final byte HID_KEY_RIGHT = 0x4f; // Right Arrow | ||
public static final byte HID_KEY_LEFT = 0x50; // Left Arrow | ||
public static final byte HID_KEY_DOWN = 0x51; // Down Arrow | ||
public static final byte HID_KEY_UP = 0x52; // Up Arrow | ||
|
||
// Numpad keys | ||
public static final byte HID_KEY_NUMLOCK = 0x53; | ||
public static final byte HID_KEY_KPSLASH = 0x54; | ||
public static final byte HID_KEY_KPASTERISK = 0x55; // Button * | ||
public static final byte HID_KEY_KPMINUS = 0x56; | ||
public static final byte HID_KEY_KPPLUS = 0x57; | ||
public static final byte HID_KEY_KPENTER = 0x58; | ||
public static final byte HID_KEY_KP1 = 0x59; | ||
public static final byte HID_KEY_KP2 = 0x5a; | ||
public static final byte HID_KEY_KP3 = 0x5b; | ||
public static final byte HID_KEY_KP4 = 0x5c; | ||
public static final byte HID_KEY_KP5 = 0x5d; | ||
public static final byte HID_KEY_KP6 = 0x5e; | ||
public static final byte HID_KEY_KP7 = 0x5f; | ||
public static final byte HID_KEY_KP8 = 0x60; | ||
public static final byte HID_KEY_KP9 = 0x61; | ||
public static final byte HID_KEY_KP0 = 0x62; | ||
public static final byte HID_KEY_KPDOT = 0x63; | ||
|
||
// Special keys | ||
public static final byte HID_KEY_POWER = 0x66; | ||
public static final byte HID_KEY_MENU = 0x76; | ||
public static final byte HID_KEY_MUTE = 0x7f; | ||
public static final byte HID_KEY_VOLUMEUP = (byte)0x80; | ||
public static final byte HID_KEY_VOLUMEDOWN = (byte)0x81; | ||
|
||
public HIDKeyboard(RVVMMachine machine) { | ||
if (machine.isValid()) { | ||
this.machine = machine; | ||
this.hid_keyboard = RVVMNative.hid_keyboard_init_auto(machine.machine); | ||
} else { | ||
this.machine = null; | ||
this.hid_keyboard = 0; | ||
} | ||
} | ||
|
||
public void press(byte key) { | ||
if (hid_keyboard != 0) RVVMNative.hid_keyboard_press(hid_keyboard, key); | ||
} | ||
public void release(byte key) { | ||
if (hid_keyboard != 0) RVVMNative.hid_keyboard_release(hid_keyboard, key); | ||
} | ||
} | ||
|
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,50 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
public class HIDMouse { | ||
private RVVMMachine machine; | ||
private final long hid_mouse; | ||
|
||
public static final byte HID_BTN_NONE = 0; | ||
public static final byte HID_BTN_LEFT = 1; | ||
public static final byte HID_BTN_RIGHT = 2; | ||
public static final byte HID_BTN_MIDDLE = 4; | ||
|
||
public static final int HID_SCROLL_UP = -1; | ||
public static final int HID_SCROLL_DOWN = 1; | ||
|
||
public HIDMouse(RVVMMachine machine) { | ||
if (machine.isValid()) { | ||
this.machine = machine; | ||
this.hid_mouse = RVVMNative.hid_mouse_init_auto(machine.machine); | ||
} else { | ||
this.machine = null; | ||
this.hid_mouse = 0; | ||
} | ||
} | ||
|
||
public void move(int x, int y) { | ||
if (hid_mouse != 0) RVVMNative.hid_mouse_move(hid_mouse, x, y); | ||
} | ||
public void place(int x, int y) { | ||
if (hid_mouse != 0) RVVMNative.hid_mouse_place(hid_mouse, x, y); | ||
} | ||
public void resolution(int x, int y) { | ||
if (hid_mouse != 0) RVVMNative.hid_mouse_resolution(hid_mouse, x, y); | ||
} | ||
public void press(byte btns) { | ||
if (hid_mouse != 0) RVVMNative.hid_mouse_press(hid_mouse, btns); | ||
} | ||
public void release(byte btns) { | ||
if (hid_mouse != 0) RVVMNative.hid_mouse_release(hid_mouse, btns); | ||
} | ||
public void scroll(int offset) { | ||
if (hid_mouse != 0) RVVMNative.hid_mouse_scroll(hid_mouse, offset); | ||
} | ||
} | ||
|
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,22 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
public class I2CBus { | ||
protected final RVVMMachine machine; | ||
protected final long i2c_bus; | ||
|
||
public I2CBus(RVVMMachine machine) { | ||
if (machine.isValid()) { | ||
this.machine = machine; | ||
i2c_bus = RVVMNative.i2c_bus_init_auto(machine.machine); | ||
} else { | ||
this.machine = null; | ||
i2c_bus = 0; | ||
} | ||
} | ||
} |
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,25 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class MMIOBase { | ||
public long region_addr = 0; | ||
public long region_size = 0; | ||
public long min_op_size = 1; | ||
public long max_op_size = 8; | ||
|
||
ByteBuffer mapping; | ||
|
||
public void remove() {} | ||
public void update() {} | ||
public void reset() {} | ||
|
||
public boolean read(ByteBuffer data, long offset, byte size) { return true; } | ||
public boolean write(ByteBuffer data, long offset, byte size) { return true;} | ||
} |
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,20 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package lekkit.rvvm; | ||
|
||
public class MMIODevice { | ||
protected RVVMMachine machine; | ||
protected int mmio_handle = -1; | ||
|
||
public MMIODevice(RVVMMachine machine) { | ||
this.machine = machine; | ||
} | ||
|
||
public void detach() { | ||
if (mmio_handle != -1) RVVMNative.detach_mmio(machine.machine, mmio_handle, true); | ||
} | ||
} |
Oops, something went wrong.