mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[ion/simulator] Headless simulator maps Ion::Console to stdio
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
39
ion/src/device/shared/drivers/console_display.cpp
Normal file
39
ion/src/device/shared/drivers/console_display.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
31
ion/src/simulator/shared/console.cpp
Normal file
31
ion/src/simulator/shared/console.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user