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();
|
|
|
|
if (ivt[type].pid != 0) {
|
|
|
|
sendSignal(ivt[type].pid, ivt[type].signum);
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
if (reg->keyboardBuffer_index_write == sizeof(reg->keyboardBuffer)) {
|
|
|
|
reg->keyboardBuffer_index_write = 0;
|
|
|
|
}
|
|
|
|
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode.getValue();
|
|
|
|
unlockSharedMemory();
|
|
|
|
}
|
|
|
|
|
2019-11-07 16:34:15 +01:00
|
|
|
}
|