85 lines
2.5 KiB
C++
85 lines
2.5 KiB
C++
#include "internal.hpp"
|
|
#include "SharedMemoryAccess.hpp"
|
|
#include "vkvm.hpp"
|
|
|
|
#include <csignal>
|
|
|
|
namespace vkvm {
|
|
|
|
Impl impl;
|
|
|
|
auto sendSignal(pid_t pid, int signalNumber) -> void {
|
|
kill(pid, signalNumber);
|
|
}
|
|
|
|
auto onSignal(int signalNumber, void(*callback)(int)) -> void {
|
|
signal(signalNumber, callback);
|
|
}
|
|
|
|
auto getInterruptTable() -> InterruptEntry * {
|
|
return reinterpret_cast<InterruptEntry *>(getSharedMemory() + sizeof(Registers) + impl.reservedSize);
|
|
}
|
|
|
|
auto getRegisters() -> Registers * {
|
|
return reinterpret_cast<Registers *>(getSharedMemory());
|
|
}
|
|
|
|
auto getTextArea() -> char * {
|
|
return ((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
|
|
sizeof(InterruptEntry) * impl.interruptEntyCount);
|
|
}
|
|
|
|
auto getPixelArea() -> char * {
|
|
return (((getSharedMemory() + sizeof(Registers) + impl.reservedSize) +
|
|
sizeof(InterruptEntry) * impl.interruptEntyCount) +
|
|
getCharactersPerRow() * getCharactersPerColumn());
|
|
}
|
|
|
|
auto callEvent(EventType type) -> bool {
|
|
auto ivt = getInterruptTable();
|
|
for(int i = 0; i < impl.interruptEntrysPerEventType;i++){
|
|
auto &entry= ivt[type * impl.interruptEntrysPerEventType + i];
|
|
if (entry.pid != 0) {
|
|
sendSignal(entry.pid, entry.signum);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
auto setLayoutVersion(LayoutVersion newValue) -> void {
|
|
lockSharedMemory();
|
|
getRegisters()->layout_version = newValue;
|
|
unlockSharedMemory();
|
|
}
|
|
|
|
auto setCharactersPerColumn(int newValue) -> void {
|
|
lockSharedMemory();
|
|
getRegisters()->characters_per_column = newValue;
|
|
unlockSharedMemory();
|
|
}
|
|
|
|
auto setCharactersPerRow(int newValue) -> void {
|
|
lockSharedMemory();
|
|
getRegisters()->characters_per_row = newValue;
|
|
unlockSharedMemory();
|
|
}
|
|
|
|
auto setMousePosition(int x, int y) -> void {
|
|
lockSharedMemory();
|
|
getRegisters()->mouse_pos_x = x;
|
|
getRegisters()->mouse_pos_y = y;
|
|
unlockSharedMemory();
|
|
}
|
|
|
|
auto buttonPressed(KeyCode keyCode) -> void {
|
|
lockSharedMemory();
|
|
auto reg = getRegisters();
|
|
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
|
|
if (reg->keyboardBuffer_index_write >= keyboardBufferSize) {
|
|
reg->keyboardBuffer_index_write = 0;
|
|
}
|
|
unlockSharedMemory();
|
|
}
|
|
|
|
}
|