Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
300cf1ac28
@ -50,18 +50,21 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->layout_version = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto setCharactersPerColumn(int newValue) -> void {
|
||||
lockSharedMemory();
|
||||
getRegisters()->characters_per_column = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto setCharactersPerRow(int newValue) -> void {
|
||||
lockSharedMemory();
|
||||
getRegisters()->characters_per_row = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto setMousePosition(int x, int y) -> void {
|
||||
@ -69,16 +72,29 @@ namespace vkvm {
|
||||
getRegisters()->mouse_pos_x = x;
|
||||
getRegisters()->mouse_pos_y = y;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto buttonPressed(KeyCode keyCode) -> void {
|
||||
lockSharedMemory();
|
||||
auto reg = getRegisters();
|
||||
if (reg->keyboardBuffer_index_write >= sizeof(reg->keyboardBuffer)) {
|
||||
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
|
||||
if (reg->keyboardBuffer_index_write >= keyboardBufferSize) {
|
||||
reg->keyboardBuffer_index_write = 0;
|
||||
}
|
||||
reg->keyboardBuffer[reg->keyboardBuffer_index_write++] = keyCode;
|
||||
unlockSharedMemory();
|
||||
}
|
||||
|
||||
auto getRegisteredProcesses(EventType eventType) -> std::vector<int> {
|
||||
std::vector<int> result;
|
||||
auto ivt = getInterruptTable();
|
||||
for(int i = 0; i < impl.interruptEntrysPerEventType;i++){
|
||||
auto &entry= ivt[eventType * impl.interruptEntrysPerEventType + i];
|
||||
if (entry.pid != 0) {
|
||||
result.push_back(entry.pid);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,6 +126,12 @@ constexpr int keyboardBufferSize = 16;
|
||||
*/
|
||||
auto buttonPressed(KeyCode keyCode) -> void;
|
||||
|
||||
/**
|
||||
* get registered Prosesses for a given event type.
|
||||
* @param eventType.
|
||||
*/
|
||||
auto getRegisteredProcesses(EventType eventType) -> std::vector<int>;
|
||||
|
||||
// Shared Memory Layout
|
||||
// --------------------------------------------------------------------
|
||||
// struct ControlRegisters
|
||||
|
23
src/vkvm.cpp
23
src/vkvm.cpp
@ -18,7 +18,6 @@ namespace vkvm {
|
||||
auto setDefaultValues() -> void {
|
||||
impl.localMemoryWarn = false;
|
||||
if (getSharedMemory() != nullptr) {
|
||||
//set default values
|
||||
setMode(GraphicMode::RGB);
|
||||
setCharactersPerRow(60);
|
||||
setCharactersPerColumn(20);
|
||||
@ -64,6 +63,9 @@ namespace vkvm {
|
||||
}
|
||||
|
||||
auto setPixel(int x, int y, Color color) -> bool {
|
||||
if(x < 0 || y < 0){
|
||||
return false;
|
||||
}
|
||||
if (x > getWidth() || y > getHeight()) {
|
||||
return false;
|
||||
}
|
||||
@ -116,6 +118,9 @@ namespace vkvm {
|
||||
}
|
||||
|
||||
auto getPixel(int x, int y) -> Color {
|
||||
if(x < 0 || y < 0) {
|
||||
return getBackgroundColor();
|
||||
}
|
||||
if (x > getWidth() || y > getHeight()) {
|
||||
return getBackgroundColor();
|
||||
}
|
||||
@ -164,7 +169,7 @@ namespace vkvm {
|
||||
auto setText(std::string text) -> bool {
|
||||
lockSharedMemory();
|
||||
char *ptr = getTextArea();
|
||||
for (int i = 0; i < text.size(); i++) {
|
||||
for (int i = 0; i < static_cast<int>(text.size()); i++) {
|
||||
if (i < getCharactersPerColumn() * getCharactersPerRow()) {
|
||||
ptr[i] = text[i];
|
||||
}
|
||||
@ -178,7 +183,9 @@ namespace vkvm {
|
||||
}
|
||||
|
||||
auto getText() -> std::string {
|
||||
return std::string(getTextArea());
|
||||
std::string text = getTextArea();
|
||||
|
||||
return text.substr(0, getCharactersPerColumn() * getCharactersPerRow());
|
||||
}
|
||||
|
||||
auto clearText() -> bool {
|
||||
@ -209,6 +216,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->width_pixels = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getHeight() -> int {
|
||||
@ -219,6 +227,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->height_pixels = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getMode() -> GraphicMode {
|
||||
@ -254,6 +263,7 @@ namespace vkvm {
|
||||
reg->graphicMode = newValue;
|
||||
}
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getRedrawInterval() -> int {
|
||||
@ -264,6 +274,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->autoRedrawInterval = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getTimerInterruptInterval() -> int {
|
||||
@ -274,6 +285,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->timerInterruptInterval = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getBackgroundColor() -> Color {
|
||||
@ -284,6 +296,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->background_color = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getForegroundColor() -> Color {
|
||||
@ -294,6 +307,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->foreground_color = newValue;
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getCharactersPerRow() -> int {
|
||||
@ -314,6 +328,7 @@ namespace vkvm {
|
||||
lockSharedMemory();
|
||||
getRegisters()->textMode_font = newValue.getId();
|
||||
unlockSharedMemory();
|
||||
callEvent(EventType::UpdateControlRegisters);
|
||||
}
|
||||
|
||||
auto getMousePosition() -> Coordinates {
|
||||
@ -326,7 +341,7 @@ namespace vkvm {
|
||||
auto reg = getRegisters();
|
||||
if (reg->keyboardBuffer_index_read != reg->keyboardBuffer_index_write) {
|
||||
keyCode = static_cast<KeyCode>(reg->keyboardBuffer[reg->keyboardBuffer_index_read++]);
|
||||
if (reg->keyboardBuffer_index_read >= sizeof(reg->keyboardBuffer)) {
|
||||
if (reg->keyboardBuffer_index_read >= keyboardBufferSize) {
|
||||
reg->keyboardBuffer_index_read = 0;
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
TEST_CASE("AREA") {
|
||||
vkvm::initialize(0);
|
||||
vkvm::setMode(vkvm::RGB);
|
||||
vkvm::setWidth(200);
|
||||
vkvm::setHeight(200);
|
||||
|
||||
@ -13,10 +12,12 @@ TEST_CASE("AREA") {
|
||||
}
|
||||
|
||||
SECTION("Out of bounds") {
|
||||
|
||||
REQUIRE_FALSE(vkvm::setPixel(400, 400, vkvm::white));
|
||||
REQUIRE(vkvm::getPixel(400, 400) == vkvm::black);
|
||||
|
||||
REQUIRE_FALSE(vkvm::setPixel(-5, -5, vkvm::white));
|
||||
REQUIRE(vkvm::getPixel(-5, -5) == vkvm::black);
|
||||
|
||||
vkvm::setBackgroundColor(vkvm::blue);
|
||||
|
||||
REQUIRE(vkvm::getPixel(400, 400) == vkvm::blue);
|
||||
|
@ -7,26 +7,26 @@ TEST_CASE("Event") {
|
||||
|
||||
SECTION("Register") {
|
||||
bool mouseMove = false;
|
||||
bool timer = false;
|
||||
bool timer2 = false;
|
||||
bool keyup = false;
|
||||
bool keyup2 = false;
|
||||
vkvm::registerEvent(vkvm::MouseMove, [&]() {
|
||||
mouseMove = true;
|
||||
});
|
||||
vkvm::registerEvent(vkvm::Timer, [&]() {
|
||||
timer = true;
|
||||
vkvm::registerEvent(vkvm::KeyUp, [&]() {
|
||||
keyup = true;
|
||||
});
|
||||
vkvm::registerEvent(vkvm::Timer, [&]() {
|
||||
timer2 = true;
|
||||
vkvm::registerEvent(vkvm::KeyUp, [&]() {
|
||||
keyup2 = true;
|
||||
});
|
||||
|
||||
REQUIRE_FALSE(mouseMove);
|
||||
vkvm::callEvent(vkvm::MouseMove);
|
||||
REQUIRE(mouseMove);
|
||||
|
||||
REQUIRE_FALSE(timer);
|
||||
REQUIRE_FALSE(timer2);
|
||||
vkvm::callEvent(vkvm::Timer);
|
||||
REQUIRE(timer);
|
||||
REQUIRE(timer2);
|
||||
REQUIRE_FALSE(keyup);
|
||||
REQUIRE_FALSE(keyup2);
|
||||
vkvm::callEvent(vkvm::KeyUp);
|
||||
REQUIRE(keyup);
|
||||
REQUIRE(keyup2);
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,9 @@ TEST_CASE("Text") {
|
||||
REQUIRE(vkvm::getCharactersPerRow() == 1);
|
||||
|
||||
REQUIRE(vkvm::setText("Hello World"));
|
||||
REQUIRE(vkvm::getText() == "Hello World");
|
||||
REQUIRE(vkvm::getText() == "Hello");
|
||||
|
||||
REQUIRE(vkvm::clearText());
|
||||
|
||||
REQUIRE(vkvm::getText().empty());
|
||||
}
|
Loading…
Reference in New Issue
Block a user