[ion/simulator] Headless simulator maps Ion::Console to stdio

This commit is contained in:
Romain Goyet
2020-09-17 20:12:54 -04:00
committed by Léa Saviot
parent a834c954b8
commit 2f2e45a6a5
9 changed files with 101 additions and 53 deletions

View File

@@ -25,7 +25,6 @@ initializer_list = $(shell echo $(1) | sed "s/\(.\)/'\1',/g")0
$(call object_for,ion/src/shared/platform_info.cpp): SFLAGS += -DPATCH_LEVEL="$(call initializer_list,$(PATCH_LEVEL))" -DEPSILON_VERSION="$(call initializer_list,$(EPSILON_VERSION))"
ion_src += $(addprefix ion/src/shared/, \
console_display.cpp:+consoledisplay \
console_line.cpp \
crc32_eat_byte.cpp \
decompress.cpp \

View File

@@ -5,6 +5,8 @@ ion_device_src += $(addprefix ion/src/device/shared/drivers/, \
board.cpp \
clipboard.cpp \
console_uart.cpp:+consoleuart \
console_display.cpp:+consoledisplay \
console_dummy.cpp:-consoledisplay \
console_dummy.cpp:-consoleuart \
crc32.cpp \
display.cpp \

View File

@@ -0,0 +1,39 @@
#include "console.h"
#include <ion/console.h>
#include <kandinsky/ion_context.h>
namespace Ion {
namespace Console {
char readChar() {
return 0;
}
void writeChar(char c) {
KDIonContext::putchar(c);
}
bool transmissionDone() {
return true;
}
}
}
namespace Ion {
namespace Device {
namespace Console {
void init() {
}
void shutdown() {
}
bool peerConnected() {
return false;
}
}
}
}

View File

@@ -1,4 +1,22 @@
#include "console.h"
#include <ion/console.h>
namespace Ion {
namespace Console {
char readChar() {
return 0;
}
void writeChar(char c) {
}
bool transmissionDone() {
return true;
}
}
}
namespace Ion {
namespace Device {

View File

@@ -1,29 +0,0 @@
#include <ion/console.h>
#include <kandinsky.h>
#include <ion/display.h>
namespace Ion {
namespace Console {
char readChar() {
return '\0';
}
static KDPoint cursor = KDPointZero;
void writeChar(char c) {
char text[2] = {c, 0};
KDContext * ctx = KDIonContext::sharedContext();
cursor = ctx->drawString(text, cursor);
if (cursor.y() > Ion::Display::Height) {
cursor = KDPoint(cursor.x(), 0);
}
}
bool transmissionDone() {
// Always true because we flush after each writeChar
return true;
}
}
}

View File

@@ -0,0 +1,31 @@
#include <ion/console.h>
#include "window.h"
#include <kandinsky/ion_context.h>
#include <stdio.h>
namespace Ion {
namespace Console {
char readChar() {
if (Simulator::Window::isHeadless()) {
return getchar();
} else {
return 0;
}
}
void writeChar(char c) {
if (Simulator::Window::isHeadless()) {
putchar(c);
fflush(stdout);
} else {
KDIonContext::putchar(c);
}
}
bool transmissionDone() {
return true;
}
}
}

View File

@@ -1,22 +0,0 @@
#include <ion/console.h>
#include <stdio.h>
namespace Ion {
namespace Console {
char readChar() {
return getchar();
}
void writeChar(char c) {
putchar(c);
fflush(stdout);
}
bool transmissionDone() {
// Always true because we flush after each writeChar
return true;
}
}
}

View File

@@ -6,6 +6,7 @@
class KDIonContext : public KDContext {
public:
static KDIonContext * sharedContext();
static void putchar(char c);
private:
KDIonContext();
void pushRect(KDRect rect, const KDColor * pixels) override;

View File

@@ -1,5 +1,5 @@
#include <kandinsky/ion_context.h>
#include <ion.h>
#include <ion/display.h>
KDIonContext * KDIonContext::sharedContext() {
static KDIonContext context;
@@ -23,3 +23,12 @@ void KDIonContext::pushRectUniform(KDRect rect, KDColor color) {
void KDIonContext::pullRect(KDRect rect, KDColor * pixels) {
Ion::Display::pullRect(rect, pixels);
}
void KDIonContext::putchar(char c) {
static KDPoint cursor = KDPointZero;
char text[2] = {c, 0};
cursor = sharedContext()->drawString(text, cursor);
if (cursor.y() > Ion::Display::Height) {
cursor = KDPoint(cursor.x(), 0);
}
}