diff --git a/build/targets.blackbox.mak b/build/targets.blackbox.mak new file mode 100644 index 000000000..b6e804a79 --- /dev/null +++ b/build/targets.blackbox.mak @@ -0,0 +1,16 @@ +epsilon.$(EXE): $(objs) $(app_objs) $(app_image_objs) $(addprefix ion/src/blackbox/, boot.o events.o) + +.PHONY: epsilon.lib +epsilon.lib: libepsilon_${EPSILON_LIB_PREFIX}.dylib + + +ion/src/blackbox/library.o: SFLAGS += -D EPSILON_LIB_PREFIX=${EPSILON_LIB_PREFIX} + +libepsilon_${EPSILON_LIB_PREFIX}.dylib: LDFLAGS += -exported_symbols_list ion/src/blackbox/lib_export_list.txt +libepsilon_${EPSILON_LIB_PREFIX}.dylib: $(objs) $(app_objs) $(app_image_objs) ion/src/blackbox/library.o + @echo "LD $@" + $(Q) $(LD) $^ $(LDFLAGS) -shared -s -o $@ + +compare.elf: ion/src/blackbox/compare.o libepsilon_first.dylib libepsilon_second.dylib + @echo "LD $@" + $(Q) $(LD) $< $(LDFLAGS) -L. -lepsilon_first -lepsilon_second -o $@ diff --git a/ion/src/blackbox/Makefile b/ion/src/blackbox/Makefile index 82d051496..c84301bbd 100644 --- a/ion/src/blackbox/Makefile +++ b/ion/src/blackbox/Makefile @@ -1,8 +1,6 @@ objs += $(addprefix ion/src/blackbox/, \ - boot.o \ ion.o \ display.o \ - events.o \ ) objs += $(addprefix ion/src/shared/, \ diff --git a/ion/src/blackbox/display.cpp b/ion/src/blackbox/display.cpp index b82663240..dc4cb94e2 100644 --- a/ion/src/blackbox/display.cpp +++ b/ion/src/blackbox/display.cpp @@ -39,6 +39,10 @@ namespace Ion { namespace Display { namespace Blackbox { +const KDColor * frameBufferAddress() { + return sPixels; +} + void setFrameBufferActive(bool enabled) { sFrameBufferActive = enabled; } diff --git a/ion/src/blackbox/display.h b/ion/src/blackbox/display.h index b7b9da376..0ec0f2618 100644 --- a/ion/src/blackbox/display.h +++ b/ion/src/blackbox/display.h @@ -1,10 +1,13 @@ #ifndef ION_BLACKBOX_DISPLAY_H #define ION_BLACKBOX_DISPLAY_H +#include + namespace Ion { namespace Display { namespace Blackbox { +const KDColor * frameBufferAddress(); void setFrameBufferActive(bool enabled); void writeFrameBufferToFile(const char * filename); diff --git a/ion/src/blackbox/lib_export_list.txt b/ion/src/blackbox/lib_export_list.txt new file mode 100644 index 000000000..08c6e797c --- /dev/null +++ b/ion/src/blackbox/lib_export_list.txt @@ -0,0 +1,3 @@ +_*epsilon_frame_buffer +_*epsilon_main +_*epsilon_send_event diff --git a/ion/src/blackbox/library.cpp b/ion/src/blackbox/library.cpp new file mode 100644 index 000000000..1fa360786 --- /dev/null +++ b/ion/src/blackbox/library.cpp @@ -0,0 +1,66 @@ +// Turn Epsilon into a library +#include "library.h" +#include "display.h" +#include +#include +#include + +void PREFIXED(main)() { + ion_main(0, nullptr); +} + +static Ion::Events::Event sEventAvailable = Ion::Events::None; +std::mutex eventAvailableMutex; +std::condition_variable eventAvailableConditionVariable; +static bool sEventProcessed = false; +std::mutex eventProcessedMutex; +std::condition_variable eventProcessedConditionVariable; + +Ion::Events::Event Ion::Events::getEvent(int * timeout) { + // Notify the eventProcessed condition + { + std::unique_lock lock(eventProcessedMutex); + sEventProcessed = true; + } + eventProcessedConditionVariable.notify_one(); + + // Wait for the eventAvailable condition + std::unique_lock lock(eventAvailableMutex); + eventAvailableConditionVariable.wait(lock, []{return sEventAvailable != Ion::Events::None;}); + Ion::Events::Event e = sEventAvailable; + sEventAvailable = Ion::Events::None; + lock.unlock(); + eventAvailableConditionVariable.notify_one(); + + return e; +} + +void PREFIXED(send_event)(int c) { + Ion::Events::Event e = Ion::Events::None; + if (c == EOF) { + e = Ion::Events::Termination; + } else { + e = Ion::Events::Event(c); + if (!(e.isDefined() && e.isKeyboardEvent())) { + return; + } + } + + // Notify the eventAvailable condition + { + std::unique_lock lock(eventAvailableMutex); + sEventAvailable = e; + } + eventAvailableConditionVariable.notify_one(); + + // Wait the eventProcessed condition + std::unique_lock lock(eventProcessedMutex); + eventProcessedConditionVariable.wait(lock, []{return sEventProcessed; }); + sEventProcessed = false; + lock.unlock(); + eventProcessedConditionVariable.notify_one(); +} + +const KDColor * PREFIXED(frame_buffer)() { + return Ion::Display::Blackbox::frameBufferAddress(); +} diff --git a/ion/src/blackbox/library.h b/ion/src/blackbox/library.h new file mode 100644 index 000000000..78704b748 --- /dev/null +++ b/ion/src/blackbox/library.h @@ -0,0 +1,19 @@ +// Turn Epsilon into a library + +#include + +#ifndef EPSILON_LIB_PREFIX +#error EPSILON_LIB_PREFIX must be defined +#endif + +#define CAT_I(a,b) a ## _epsilon_ ## b +#define CAT(a,b) CAT_I(a, b) +#define PREFIXED(name) CAT(EPSILON_LIB_PREFIX, name) + +extern "C" { + +void PREFIXED(main)(); +void PREFIXED(send_event)(int c); +const KDColor * PREFIXED(frame_buffer)(); + +}