2019-11-13 13:37:49 +01:00
|
|
|
#include "internal.hpp"
|
|
|
|
#include "SharedMemoryAccess.hpp"
|
|
|
|
#include "vkvm.hpp"
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-06 12:47:34 +01:00
|
|
|
#include <csignal>
|
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
namespace vkvm {
|
2019-11-06 12:47:34 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
Impl impl;
|
2019-11-06 13:41:24 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto sendSignal(pid_t pid, int signalNumber) -> void {
|
|
|
|
kill(pid, signalNumber);
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto onSignal(int signalNumber, void(*callback)(int)) -> void {
|
|
|
|
signal(signalNumber, callback);
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto getInterrupTable() -> InterruptEntry * {
|
|
|
|
return reinterpret_cast<InterruptEntry *>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto getRegisters() -> Registers * {
|
|
|
|
return reinterpret_cast<Registers *>(getSharedMemory());
|
|
|
|
}
|
2019-11-06 13:41:24 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto getTextArea() -> char * {
|
|
|
|
return ((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
|
|
|
|
sizeof(InterruptEntry) * impl.interruptEntyCount);
|
2019-11-06 13:41:24 +01:00
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto getPixelArea() -> char * {
|
|
|
|
return (((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
|
|
|
|
sizeof(InterruptEntry) * impl.interruptEntyCount) +
|
|
|
|
getCharactersPerRow() * getCharactersPerColumn());
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto callEvent(EventType type) -> bool {
|
|
|
|
auto ivt = getInterrupTable();
|
2019-11-19 11:56:18 +01:00
|
|
|
for(int i = 0; i < impl.interruptEntrysPerEventType;i++){
|
|
|
|
auto &entry= ivt[type * impl.interruptEntrysPerEventType + i];
|
|
|
|
if (entry.pid != 0) {
|
|
|
|
sendSignal(entry.pid, entry.signum);
|
|
|
|
}
|
2019-11-13 13:37:49 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto setLayoutVersion(LayoutVersion newValue) -> void {
|
|
|
|
lockSharedMemory();
|
|
|
|
getRegisters()->layout_version = newValue;
|
|
|
|
unlockSharedMemory();
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto setCharactersPerColumn(int newValue) -> void {
|
|
|
|
lockSharedMemory();
|
|
|
|
getRegisters()->characters_per_column = newValue;
|
|
|
|
unlockSharedMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
auto setCharactersPerRow(int newValue) -> void {
|
|
|
|
lockSharedMemory();
|
|
|
|
getRegisters()->characters_per_row = newValue;
|
|
|
|
unlockSharedMemory();
|
|
|
|
}
|
2019-11-07 16:34:15 +01:00
|
|
|
|
2019-11-13 13:37:49 +01:00
|
|
|
auto setMousePosition(int x, int y) -> void {
|
|
|
|
lockSharedMemory();
|
|
|
|
getRegisters()->mouse_pos_x = x;
|
|
|
|
getRegisters()->mouse_pos_y = y;
|
|
|
|
unlockSharedMemory();
|
2019-11-12 14:07:02 +01:00
|
|
|
}
|
2019-11-13 13:37:49 +01:00
|
|
|
|
|
|
|
auto buttonPressed(KeyCode keyCode) -> void {
|
|
|
|
lockSharedMemory();
|
|
|
|
auto reg = getRegisters();
|
2019-11-26 11:49:19 +01:00
|
|
|
if (reg->keyboardBuffer_index_write >= sizeof(reg->keyboardBuffer)) {
|
2019-11-13 13:37:49 +01:00
|
|
|
reg->keyboardBuffer_index_write = 0;
|
|
|
|
}
|
2019-11-21 12:37:52 +01:00
|
|
|
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
|
2019-11-13 13:37:49 +01:00
|
|
|
unlockSharedMemory();
|
|
|
|
}
|
|
|
|
|
2019-11-07 16:34:15 +01:00
|
|
|
}
|