diff --git a/ion/drivers/fltkkbd/fltkkbd.cpp b/ion/drivers/fltkkbd/fltkkbd.cpp deleted file mode 100644 index 5fae3759e..000000000 --- a/ion/drivers/fltkkbd/fltkkbd.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "fltkkbd.h" -#include "fltkkbdbutton.h" - -void FltkKbdButtonCallback(Fl_Widget * w, void * context) { - FltkKbd * kbd = (FltkKbd *)context; - FltkKbdButton * button = (FltkKbdButton *)w; - kbd->m_keyStates[button->m_key] = button->value(); -} - -FltkKbd::FltkKbd(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { - for (int i=0; im_key = (ion_key_t)k; - b->when(FL_WHEN_CHANGED); - b->callback(FltkKbdButtonCallback, (void *)this); - } - end(); -} diff --git a/ion/drivers/fltkkbd/fltkkbdbutton.cpp b/ion/drivers/fltkkbd/fltkkbdbutton.cpp deleted file mode 100644 index ca63ffa5b..000000000 --- a/ion/drivers/fltkkbd/fltkkbdbutton.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "fltkkbdbutton.h" - -FltkKbdButton::FltkKbdButton(int x, int y, int w, int h, const char * label) : - Fl_Button(x, y, w, h, label) { -} diff --git a/ion/drivers/fltkkbd/fltkkbdbutton.h b/ion/drivers/fltkkbd/fltkkbdbutton.h deleted file mode 100644 index 9dc009c2d..000000000 --- a/ion/drivers/fltkkbd/fltkkbdbutton.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef ION_FLTK_KBD_BUTTON -#define ION_FLTK_KBD_BUTTON - -#include -extern "C" { -#include -} - -class FltkKbdButton : public Fl_Button { - public: - FltkKbdButton(int x, int y, int w, int h, const char * label = 0); - ion_key_t m_key; -}; - -#endif diff --git a/ion/src/simulator/Makefile b/ion/src/simulator/Makefile index def0cfc01..6903fc7ee 100644 --- a/ion/src/simulator/Makefile +++ b/ion/src/simulator/Makefile @@ -1,5 +1,7 @@ -objs += $(addprefix ion/platform/simulator/, init.o platform.o framebuffer.o) -objs += $(addprefix ion/drivers/, fltklcd/fltklcd.o fltkkbd/fltkkbd.o fltkkbd/fltkkbdbutton.o) +objs += $(addprefix ion/src/simulator/, init.o) +objs += $(addprefix ion/src/simulator/boot/, main.o) +objs += $(addprefix ion/src/simulator/display/, fltklcd.o) +objs += $(addprefix ion/src/simulator/keyboard/, fltkkbd.o) #SFLAGS += -I/usr/local/Cellar/fltk/1.3.3/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT LDFLAGS += -L/usr/local/Cellar/fltk/1.3.3/lib -lfltk -lpthread -framework Cocoa diff --git a/ion/src/simulator/boot/Makefile b/ion/src/simulator/boot/Makefile deleted file mode 100644 index e2f218e22..000000000 --- a/ion/src/simulator/boot/Makefile +++ /dev/null @@ -1 +0,0 @@ -objs += $(addprefix boot/simulator/, main.o) diff --git a/ion/src/simulator/boot/main.c b/ion/src/simulator/boot/main.c index 7a4fb5e80..6def8c345 100644 --- a/ion/src/simulator/boot/main.c +++ b/ion/src/simulator/boot/main.c @@ -1,5 +1,7 @@ -#include +#include +#include "../init.h" int main(int argc, char * argv[]) { - boot(); + init_platform(); + ion_app(); } diff --git a/ion/drivers/fltklcd/fltklcd.cpp b/ion/src/simulator/display/fltklcd.cpp similarity index 100% rename from ion/drivers/fltklcd/fltklcd.cpp rename to ion/src/simulator/display/fltklcd.cpp diff --git a/ion/drivers/fltklcd/fltklcd.h b/ion/src/simulator/display/fltklcd.h similarity index 100% rename from ion/drivers/fltklcd/fltklcd.h rename to ion/src/simulator/display/fltklcd.h diff --git a/ion/src/simulator/framebuffer.c b/ion/src/simulator/framebuffer.c deleted file mode 100644 index cae961c94..000000000 --- a/ion/src/simulator/framebuffer.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "framebuffer.h" -#include -#include - -void ion_set_pixel(uint8_t x, uint8_t y, uint8_t color) { - assert(x <= FRAMEBUFFER_WIDTH); - assert(y <= FRAMEBUFFER_HEIGHT); - - char * byte = FRAMEBUFFER_ADDRESS + ((y*FRAMEBUFFER_WIDTH)+x); - *byte = color; -} diff --git a/ion/src/simulator/framebuffer.h b/ion/src/simulator/framebuffer.h deleted file mode 100644 index 4ffa25513..000000000 --- a/ion/src/simulator/framebuffer.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef ION_SIMULATOR_FRAMEBUFFER_H -#define ION_SIMULATOR_FRAMEBUFFER_H - -extern void * PlatformFramebuffer; - -#define FRAMEBUFFER_ADDRESS PlatformFramebuffer -#define FRAMEBUFFER_WIDTH 320 -#define FRAMEBUFFER_HEIGHT 240 -#define FRAMEBUFFER_BITS_PER_PIXEL 8 - -#endif diff --git a/ion/src/simulator/init.cpp b/ion/src/simulator/init.cpp index 2d1257926..612f007bf 100644 --- a/ion/src/simulator/init.cpp +++ b/ion/src/simulator/init.cpp @@ -3,37 +3,51 @@ extern "C" { #include #include #include +#include "init.h" } -#include "platform.h" -#include "framebuffer.h" #include #include #include -#include -#include -void ion_init() { +#include "display/fltklcd.h" +#include "keyboard/fltkkbd.h" + +static FltkLCD * sDisplay; +static FltkKbd * sKeyboard; + +#define FRAMEBUFFER_ADDRESS (sDisplay->m_framebuffer) +#define FRAMEBUFFER_WIDTH 320 +#define FRAMEBUFFER_HEIGHT 240 +#define FRAMEBUFFER_BITS_PER_PIXEL 8 + +void init_platform() { Fl::visual(FL_RGB); int margin = 10; Fl_Window * window = new Fl_Window(FRAMEBUFFER_WIDTH+2*margin, FRAMEBUFFER_HEIGHT+2*margin+120+2*margin); - FltkLCD * lcd = new FltkLCD(margin, margin, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT); + sDisplay = new FltkLCD(margin, margin, FRAMEBUFFER_WIDTH, FRAMEBUFFER_HEIGHT); assert(FRAMEBUFFER_BITS_PER_PIXEL == 8); - Platform.display = lcd; - PlatformFramebuffer = lcd->m_framebuffer; - FltkKbd * kbd = new FltkKbd(margin,FRAMEBUFFER_HEIGHT+3*margin,FRAMEBUFFER_WIDTH,120); - Platform.keyboard = kbd; - ion_key_states = kbd->m_keyStates; + sKeyboard = new FltkKbd(margin,FRAMEBUFFER_HEIGHT+3*margin,FRAMEBUFFER_WIDTH,120); window->end(); window->show(NULL, NULL); - //Fl::run(); +} + +void ion_set_pixel(uint8_t x, uint8_t y, uint8_t color) { + assert(x <= FRAMEBUFFER_WIDTH); + assert(y <= FRAMEBUFFER_HEIGHT); + char * byte = (char *)(FRAMEBUFFER_ADDRESS) + ((y*FRAMEBUFFER_WIDTH)+x); + *byte = color; +} + +bool ion_key_down(ion_key_t key) { + return sKeyboard->key_down(key); } void ion_sleep() { usleep(1000); - Platform.display->redraw(); + sDisplay->redraw(); Fl::wait(); } diff --git a/ion/src/simulator/init.h b/ion/src/simulator/init.h new file mode 100644 index 000000000..346aed92c --- /dev/null +++ b/ion/src/simulator/init.h @@ -0,0 +1,6 @@ +#ifndef ION_SIMULATOR_PLATFORM_INIT_H +#define ION_SIMULATOR_PLATFORM_INIT_H + +void init_platform(); + +#endif diff --git a/ion/src/simulator/keyboard/fltkkbd.cpp b/ion/src/simulator/keyboard/fltkkbd.cpp new file mode 100644 index 000000000..16a82857b --- /dev/null +++ b/ion/src/simulator/keyboard/fltkkbd.cpp @@ -0,0 +1,12 @@ +#include "fltkkbd.h" + +FltkKbd::FltkKbd(int x, int y, int w, int h) : Fl_Group(x, y, w, h) { + for (int k=0; kvalue(); +} diff --git a/ion/drivers/fltkkbd/fltkkbd.h b/ion/src/simulator/keyboard/fltkkbd.h similarity index 64% rename from ion/drivers/fltkkbd/fltkkbd.h rename to ion/src/simulator/keyboard/fltkkbd.h index 71b88f637..fa60d0572 100644 --- a/ion/drivers/fltkkbd/fltkkbd.h +++ b/ion/src/simulator/keyboard/fltkkbd.h @@ -2,6 +2,7 @@ #define ION_FLTK_KBD #include +#include extern "C" { #include } @@ -9,7 +10,9 @@ extern "C" { class FltkKbd : public Fl_Group { public: FltkKbd(int x, int y, int w, int h); - bool m_keyStates[ION_NUMBER_OF_KEYS]; + bool key_down(ion_key_t key); +private: + Fl_Button * m_buttons[ION_NUMBER_OF_KEYS]; }; #endif diff --git a/ion/src/simulator/platform.cpp b/ion/src/simulator/platform.cpp deleted file mode 100644 index 95a726c46..000000000 --- a/ion/src/simulator/platform.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "platform.h" - -platform_t Platform; -void * PlatformFramebuffer; diff --git a/ion/src/simulator/platform.h b/ion/src/simulator/platform.h deleted file mode 100644 index 4864b6263..000000000 --- a/ion/src/simulator/platform.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef ION_SIMULATOR_PLATFORM_H -#define ION_SIMULATOR_PLATFORM_H - -#include -#include -extern "C" { -#include "framebuffer.h" -} - -typedef struct { - FltkLCD * display; - FltkKbd * keyboard; -} platform_t; - -extern platform_t Platform; - -#endif