mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[ion] Add the ability to build blackbox as a shared library
This commit is contained in:
16
build/targets.blackbox.mak
Normal file
16
build/targets.blackbox.mak
Normal file
@@ -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 $@
|
||||
@@ -1,8 +1,6 @@
|
||||
objs += $(addprefix ion/src/blackbox/, \
|
||||
boot.o \
|
||||
ion.o \
|
||||
display.o \
|
||||
events.o \
|
||||
)
|
||||
|
||||
objs += $(addprefix ion/src/shared/, \
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace Ion {
|
||||
namespace Display {
|
||||
namespace Blackbox {
|
||||
|
||||
const KDColor * frameBufferAddress() {
|
||||
return sPixels;
|
||||
}
|
||||
|
||||
void setFrameBufferActive(bool enabled) {
|
||||
sFrameBufferActive = enabled;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#ifndef ION_BLACKBOX_DISPLAY_H
|
||||
#define ION_BLACKBOX_DISPLAY_H
|
||||
|
||||
#include <kandinsky.h>
|
||||
|
||||
namespace Ion {
|
||||
namespace Display {
|
||||
namespace Blackbox {
|
||||
|
||||
const KDColor * frameBufferAddress();
|
||||
void setFrameBufferActive(bool enabled);
|
||||
void writeFrameBufferToFile(const char * filename);
|
||||
|
||||
|
||||
3
ion/src/blackbox/lib_export_list.txt
Normal file
3
ion/src/blackbox/lib_export_list.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
_*epsilon_frame_buffer
|
||||
_*epsilon_main
|
||||
_*epsilon_send_event
|
||||
66
ion/src/blackbox/library.cpp
Normal file
66
ion/src/blackbox/library.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
// Turn Epsilon into a library
|
||||
#include "library.h"
|
||||
#include "display.h"
|
||||
#include <ion.h>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
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<std::mutex> lock(eventProcessedMutex);
|
||||
sEventProcessed = true;
|
||||
}
|
||||
eventProcessedConditionVariable.notify_one();
|
||||
|
||||
// Wait for the eventAvailable condition
|
||||
std::unique_lock<std::mutex> 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<std::mutex> lock(eventAvailableMutex);
|
||||
sEventAvailable = e;
|
||||
}
|
||||
eventAvailableConditionVariable.notify_one();
|
||||
|
||||
// Wait the eventProcessed condition
|
||||
std::unique_lock<std::mutex> lock(eventProcessedMutex);
|
||||
eventProcessedConditionVariable.wait(lock, []{return sEventProcessed; });
|
||||
sEventProcessed = false;
|
||||
lock.unlock();
|
||||
eventProcessedConditionVariable.notify_one();
|
||||
}
|
||||
|
||||
const KDColor * PREFIXED(frame_buffer)() {
|
||||
return Ion::Display::Blackbox::frameBufferAddress();
|
||||
}
|
||||
19
ion/src/blackbox/library.h
Normal file
19
ion/src/blackbox/library.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// Turn Epsilon into a library
|
||||
|
||||
#include <kandinsky.h>
|
||||
|
||||
#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)();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user