diff --git a/Makefile b/Makefile index c42ed081ab2..429011fe0b8 100644 --- a/Makefile +++ b/Makefile @@ -31,13 +31,7 @@ ifeq ($(filter reader,$(apps_list)),) HAS_READER := 1 endif -# Remove the external apps for the n0100 -ifeq (${MODEL}, n0100) - apps_list = $(foreach i, ${EPSILON_APPS}, $(if $(filter external, $(i)),,$(i))) -else - apps_list = ${EPSILON_APPS} -endif - +apps_list = ${EPSILON_APPS} ifdef FORCE_EXTERNAL apps_list = ${EPSILON_APPS} endif diff --git a/apps/external/Makefile b/apps/external/Makefile index 0929e8d218c..b26f5b4e587 100644 --- a/apps/external/Makefile +++ b/apps/external/Makefile @@ -1,53 +1,16 @@ -ifdef HOME_DISPLAY_EXTERNALS - -app_external_src = $(addprefix apps/external/,\ - extapp_api.cpp \ - archive.cpp \ -) - $(eval $(call depends_on_image,apps/home/controller.cpp,apps/external/external_icon.png)) -else - -apps += External::App -app_headers += apps/external/app.h - -app_external_src = $(addprefix apps/external/,\ - app.cpp \ - extapp_api.cpp \ - archive.cpp \ - main_controller.cpp \ - pointer_text_table_cell.cpp \ -) - -$(eval $(call depends_on_image,apps/external/app.cpp,apps/external/external_icon.png)) - -endif - SFLAGS += -Iapps/external/ EXTAPP_PATH ?= apps/external/app/ + ifeq ($(PLATFORM),device) +# FIXME: Should be handled by Ion, since external apps are managed by Ion SFLAGS += -DDEVICE else include $(EXTAPP_PATH)/sources.mak endif -ifdef EXTERNAL_BUILTIN -SFLAGS += -DEXTERNAL_BUILTIN -endif - apps_src += $(app_external_src) -i18n_files += $(addprefix apps/external/,\ - base.de.i18n\ - base.en.i18n\ - base.es.i18n\ - base.fr.i18n\ - base.pt.i18n\ - base.it.i18n\ - base.nl.i18n\ - base.hu.i18n\ - base.universal.i18n\ -) - +i18n_files += $(call i18n_without_universal_for,external/base) diff --git a/apps/external/app.cpp b/apps/external/app.cpp deleted file mode 100644 index fba8ffccc97..00000000000 --- a/apps/external/app.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "app.h" -#include "external_icon.h" -#include - -namespace External { - -I18n::Message App::Descriptor::name() { - return I18n::Message::ExternalApp; -} - -I18n::Message App::Descriptor::upperName() { - return I18n::Message::ExternalAppCapital; -} - -App::Descriptor::ExaminationLevel App::Descriptor::examinationLevel() { - return App::Descriptor::ExaminationLevel::Basic; -} - -const Image * App::Descriptor::icon() { - return ImageStore::ExternalIcon; -} - -App * App::Snapshot::unpack(Container * container) { - return new (container->currentAppBuffer()) App(this); -} - -App::Descriptor * App::Snapshot::descriptor() { - static Descriptor descriptor; - return &descriptor; -} - -void App::didBecomeActive(Window * window) { - ::App::didBecomeActive(window); - m_window = window; -} - -void App::redraw() { - m_window->redraw(true); -} - -App::App(Snapshot * snapshot) : - ::App(snapshot, &m_stackViewController), - m_mainController(&m_stackViewController, this), - m_stackViewController(&m_modalViewController, &m_mainController) -{ -} - -} diff --git a/apps/external/app.h b/apps/external/app.h deleted file mode 100644 index d1d38487b9f..00000000000 --- a/apps/external/app.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef EXTERNAL_APP_H -#define EXTERNAL_APP_H - -#include -#include "main_controller.h" - -namespace External { - -class App : public ::App { -public: - class Descriptor : public ::App::Descriptor { - public: - I18n::Message name() override; - I18n::Message upperName() override; - App::Descriptor::ExaminationLevel examinationLevel() override; - const Image * icon() override; - }; - class Snapshot : public ::App::Snapshot { - public: - App * unpack(Container * container) override; - Descriptor * descriptor() override; - }; - void redraw(); - virtual void didBecomeActive(Window * window); - int heapSize() { return k_externalHeapSize; } - char * heap() { return m_externalHeap; } -private: - App(Snapshot * snapshot); - MainController m_mainController; - StackViewController m_stackViewController; - Window * m_window; - static constexpr int k_externalHeapSize = 99000; - char m_externalHeap[k_externalHeapSize]; -}; - -} - -#endif diff --git a/apps/external/app/sources.mak b/apps/external/app/sources.mak index 3f285e23a47..88cb7cbd024 100644 --- a/apps/external/app/sources.mak +++ b/apps/external/app/sources.mak @@ -1,3 +1,3 @@ -app_external_src += $(addprefix apps/external/app/,\ +app_external_src += $(addprefix $(EXTAPP_PATH),\ sample.c \ -) \ No newline at end of file +) diff --git a/apps/external/base.de.i18n b/apps/external/base.de.i18n index 28dd31e4e4d..5b12c77ab69 100644 --- a/apps/external/base.de.i18n +++ b/apps/external/base.de.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "API stimmt nicht überein" ExternalAppExecError = "Datei kann nicht ausgeführt werden" -ExternalNotCompatible = "Externe App ist nicht kompatibel" -WithSimulator = "mit dem Simulator" -WithN0100 = "mit N0100" -GetMoreAppsAt = "Weitere Apps abrufen bei" -NoAppsInstalled = "Keine Apps installiert" \ No newline at end of file diff --git a/apps/external/base.en.i18n b/apps/external/base.en.i18n index 49b8a217333..6f3739050aa 100644 --- a/apps/external/base.en.i18n +++ b/apps/external/base.en.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "API mismatch" ExternalAppExecError = "Cannot execute file" -ExternalNotCompatible = "External is not compatible" -WithSimulator = "with the simulator" -WithN0100 = "with n0100" -GetMoreAppsAt = "Get more apps at" -NoAppsInstalled = "No apps installed" diff --git a/apps/external/base.es.i18n b/apps/external/base.es.i18n index 7513cd076f7..a190200497c 100644 --- a/apps/external/base.es.i18n +++ b/apps/external/base.es.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "Discordancia de API" ExternalAppExecError = "No se puede ejecutar el archivo" -ExternalNotCompatible = "Externo no es compatible" -WithSimulator = "con el simulador" -WithN0100 = "con n0100" -GetMoreAppsAt = "Obtenga más aplicaciones en" -NoAppsInstalled = "No hay aplicaciones instaladas" diff --git a/apps/external/base.fr.i18n b/apps/external/base.fr.i18n index 626444a1b8c..98f4e698040 100644 --- a/apps/external/base.fr.i18n +++ b/apps/external/base.fr.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "Décalage API" ExternalAppExecError = "Le fichier ne peut pas être exécuté" -ExternalNotCompatible = "External n'est pas compatible" -WithSimulator = "avec le simulateur" -WithN0100 = "avec n0100" -GetMoreAppsAt = "Télécharge d'autres apps sur" -NoAppsInstalled = "Aucune applications installées" diff --git a/apps/external/base.hu.i18n b/apps/external/base.hu.i18n index e984edc511d..73a6c0f11a9 100644 --- a/apps/external/base.hu.i18n +++ b/apps/external/base.hu.i18n @@ -1,9 +1,2 @@ -ExternalApp = "Külsö" -ExternalAppCapital = "KÜLSÖ" -ExternalAppApiMismatch = "API eltérés" -ExternalAppExecError = "A fájl nem futtatható" -ExternalNotCompatible = "Externál nem kompatibilis" -WithSimulator = "Szimulátorral" -WithN0100 = "n0100-al" -GetMoreAppsAt = "Mégtöbb alkalmazás itt :" -NoAppsInstalled = "Nincs letöltött externál" +ExternalAppApiMismatch = "API eltérés" +ExternalAppExecError = "A fájl nem futtatható" diff --git a/apps/external/base.it.i18n b/apps/external/base.it.i18n index 49b8a217333..6f3739050aa 100644 --- a/apps/external/base.it.i18n +++ b/apps/external/base.it.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "API mismatch" ExternalAppExecError = "Cannot execute file" -ExternalNotCompatible = "External is not compatible" -WithSimulator = "with the simulator" -WithN0100 = "with n0100" -GetMoreAppsAt = "Get more apps at" -NoAppsInstalled = "No apps installed" diff --git a/apps/external/base.nl.i18n b/apps/external/base.nl.i18n index 49b8a217333..6f3739050aa 100644 --- a/apps/external/base.nl.i18n +++ b/apps/external/base.nl.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "API mismatch" ExternalAppExecError = "Cannot execute file" -ExternalNotCompatible = "External is not compatible" -WithSimulator = "with the simulator" -WithN0100 = "with n0100" -GetMoreAppsAt = "Get more apps at" -NoAppsInstalled = "No apps installed" diff --git a/apps/external/base.pt.i18n b/apps/external/base.pt.i18n index ae08d747879..6f3739050aa 100644 --- a/apps/external/base.pt.i18n +++ b/apps/external/base.pt.i18n @@ -1,9 +1,2 @@ -ExternalApp = "External" -ExternalAppCapital = "EXTERNAL" ExternalAppApiMismatch = "API mismatch" ExternalAppExecError = "Cannot execute file" -ExternalNotCompatible = "Externo no es compatiblee" -WithSimulator = "con el simulador" -WithN0100 = "con n0100" -GetMoreAppsAt = "Obtenga más aplicaciones en" -NoAppsInstalled = "No hay aplicaciones instaladas" diff --git a/apps/external/base.universal.i18n b/apps/external/base.universal.i18n index bd64604ea1a..e69de29bb2d 100644 --- a/apps/external/base.universal.i18n +++ b/apps/external/base.universal.i18n @@ -1 +0,0 @@ -URL = "zardam.github.io/nw-external-apps/" \ No newline at end of file diff --git a/apps/external/extapp_api.h b/apps/external/extapp_api.h index 9a98e5526d4..bc654f7281f 100644 --- a/apps/external/extapp_api.h +++ b/apps/external/extapp_api.h @@ -1,261 +1,2 @@ -#ifndef EXTERNAL_API_H -#define EXTERNAL_API_H - -#include -#include -#include - -#define API_VERSION 2 - -#ifdef __cplusplus -#define EXTERNC extern "C" -#else -#define EXTERNC -#endif - -#define LCD_WIDTH 320 -#define LCD_HEIGHT 240 - -#define EXTAPP_RAM_FILE_SYSTEM 0 -#define EXTAPP_FLASH_FILE_SYSTEM 1 -#define EXTAPP_BOTH_FILE_SYSTEM 2 - -#define SCANCODE_Left ((uint64_t)1 << 0) -#define SCANCODE_Up ((uint64_t)1 << 1) -#define SCANCODE_Down ((uint64_t)1 << 2) -#define SCANCODE_Right ((uint64_t)1 << 3) -#define SCANCODE_OK ((uint64_t)1 << 4) -#define SCANCODE_Back ((uint64_t)1 << 5) -#define SCANCODE_Home ((uint64_t)1 << 6) -#define SCANCODE_OnOff (((uint64_t)1 << 7) || ((uint64_t)1 << 8)) -#define SCANCODE_Shift ((uint64_t)1 << 12) -#define SCANCODE_Alpha ((uint64_t)1 << 13) -#define SCANCODE_XNT ((uint64_t)1 << 14) -#define SCANCODE_Var ((uint64_t)1 << 15) -#define SCANCODE_Toolbox ((uint64_t)1 << 16) -#define SCANCODE_Backspace ((uint64_t)1 << 17) -#define SCANCODE_Exp ((uint64_t)1 << 18) -#define SCANCODE_Ln ((uint64_t)1 << 19) -#define SCANCODE_Log ((uint64_t)1 << 20) -#define SCANCODE_Imaginary ((uint64_t)1 << 21) -#define SCANCODE_Comma ((uint64_t)1 << 22) -#define SCANCODE_Power ((uint64_t)1 << 23) -#define SCANCODE_Sine ((uint64_t)1 << 24) -#define SCANCODE_Cosine ((uint64_t)1 << 25) -#define SCANCODE_Tangent ((uint64_t)1 << 26) -#define SCANCODE_Pi ((uint64_t)1 << 27) -#define SCANCODE_Sqrt ((uint64_t)1 << 28) -#define SCANCODE_Square ((uint64_t)1 << 29) -#define SCANCODE_Seven ((uint64_t)1 << 30) -#define SCANCODE_Eight ((uint64_t)1 << 31) -#define SCANCODE_Nine ((uint64_t)1 << 32) -#define SCANCODE_LeftParenthesis ((uint64_t)1 << 33) -#define SCANCODE_RightParenthesis ((uint64_t)1 << 34) -#define SCANCODE_Four ((uint64_t)1 << 36) -#define SCANCODE_Five ((uint64_t)1 << 37) -#define SCANCODE_Six ((uint64_t)1 << 38) -#define SCANCODE_Multiplication ((uint64_t)1 << 39) -#define SCANCODE_Division ((uint64_t)1 << 40) -#define SCANCODE_One ((uint64_t)1 << 42) -#define SCANCODE_Two ((uint64_t)1 << 43) -#define SCANCODE_Three ((uint64_t)1 << 44) -#define SCANCODE_Plus ((uint64_t)1 << 45) -#define SCANCODE_Minus ((uint64_t)1 << 46) -#define SCANCODE_Zero ((uint64_t)1 << 48) -#define SCANCODE_Dot ((uint64_t)1 << 49) -#define SCANCODE_EE ((uint64_t)1 << 50) -#define SCANCODE_Ans ((uint64_t)1 << 51) -#define SCANCODE_EXE ((uint64_t)1 << 52) -#define SCANCODE_None ((uint64_t)1 << 54) - -// Character codes -#define KEY_CHAR_0 0x30 -#define KEY_CHAR_1 0x31 -#define KEY_CHAR_2 0x32 -#define KEY_CHAR_3 0x33 -#define KEY_CHAR_4 0x34 -#define KEY_CHAR_5 0x35 -#define KEY_CHAR_6 0x36 -#define KEY_CHAR_7 0x37 -#define KEY_CHAR_8 0x38 -#define KEY_CHAR_9 0x39 -#define KEY_CHAR_DP 0x2e -#define KEY_CHAR_EXP 0x0f -#define KEY_CHAR_PMINUS 30200 -#define KEY_CHAR_PLUS 43 -#define KEY_CHAR_MINUS 45 -#define KEY_CHAR_MULT 42 -#define KEY_CHAR_DIV 47 -#define KEY_CHAR_FRAC 0xbb -#define KEY_CHAR_LPAR 0x28 -#define KEY_CHAR_RPAR 0x29 -#define KEY_CHAR_COMMA 0x2c -#define KEY_CHAR_STORE 0x0e -#define KEY_CHAR_LOG 0x95 -#define KEY_CHAR_LN 0x85 -#define KEY_CHAR_SIN 0x81 -#define KEY_CHAR_COS 0x82 -#define KEY_CHAR_TAN 0x83 -#define KEY_CHAR_SQUARE 0x8b -#define KEY_CHAR_POW 0xa8 -#define KEY_CHAR_IMGNRY 0x7f50 -#define KEY_CHAR_LIST 0x7f51 -#define KEY_CHAR_MAT 0x7f40 -#define KEY_CHAR_EQUAL 0x3d -#define KEY_CHAR_PI 0xd0 -#define KEY_CHAR_ANS 0xc0 -#define KEY_SHIFT_ANS 0xc1 -#define KEY_CHAR_LBRCKT 0x5b -#define KEY_CHAR_RBRCKT 0x5d -#define KEY_CHAR_LBRACE 0x7b -#define KEY_CHAR_RBRACE 0x7d -#define KEY_CHAR_CR 0x0d -#define KEY_CHAR_CUBEROOT 0x96 -#define KEY_CHAR_RECIP 0x9b -#define KEY_CHAR_ANGLE 0x7f54 -#define KEY_CHAR_EXPN10 0xb5 -#define KEY_CHAR_EXPN 0xa5 -#define KEY_CHAR_ASIN 0x91 -#define KEY_CHAR_ACOS 0x92 -#define KEY_CHAR_ATAN 0x93 -#define KEY_CHAR_ROOT 0x86 -#define KEY_CHAR_POWROOT 0xb8 -#define KEY_CHAR_SPACE 0x20 -#define KEY_CHAR_DQUATE 0x22 -#define KEY_CHAR_VALR 0xcd -#define KEY_CHAR_THETA 0xce -#define KEY_CHAR_FACTOR 0xda -#define KEY_CHAR_NORMAL 0xdb -#define KEY_CHAR_A 0x41 -#define KEY_CHAR_B 0x42 -#define KEY_CHAR_C 0x43 -#define KEY_CHAR_D 0x44 -#define KEY_CHAR_E 0x45 -#define KEY_CHAR_F 0x46 -#define KEY_CHAR_G 0x47 -#define KEY_CHAR_H 0x48 -#define KEY_CHAR_I 0x49 -#define KEY_CHAR_J 0x4a -#define KEY_CHAR_K 0x4b -#define KEY_CHAR_L 0x4c -#define KEY_CHAR_M 0x4d -#define KEY_CHAR_N 0x4e -#define KEY_CHAR_O 0x4f -#define KEY_CHAR_P 0x50 -#define KEY_CHAR_Q 0x51 -#define KEY_CHAR_R 0x52 -#define KEY_CHAR_S 0x53 -#define KEY_CHAR_T 0x54 -#define KEY_CHAR_U 0x55 -#define KEY_CHAR_V 0x56 -#define KEY_CHAR_W 0x57 -#define KEY_CHAR_X 0x58 -#define KEY_CHAR_Y 0x59 -#define KEY_CHAR_Z 0x5a - -// Control codes -#define KEY_CTRL_NOP 30202 -#define KEY_CTRL_EXE 30201 -#define KEY_CTRL_DEL 30025 -#define KEY_CTRL_AC 30070 -#define KEY_CTRL_FD 30046 -#define KEY_CTRL_UNDO 30045 -#define KEY_CTRL_XTT 30001 -#define KEY_CTRL_EXIT 5 -#define KEY_CTRL_OK 4 -#define KEY_CTRL_SHIFT 30006 -#define KEY_CTRL_ALPHA 30007 -#define KEY_CTRL_OPTN 30008 -#define KEY_CTRL_VARS 30030 -#define KEY_CTRL_UP 1 -#define KEY_CTRL_DOWN 2 -#define KEY_CTRL_LEFT 0 -#define KEY_CTRL_RIGHT 3 -#define KEY_CTRL_F1 30009 -#define KEY_CTRL_F2 30010 -#define KEY_CTRL_F3 30011 -#define KEY_CTRL_F4 30012 -#define KEY_CTRL_F5 30013 -#define KEY_CTRL_F6 30014 -#define KEY_CTRL_F7 30015 -#define KEY_CTRL_F8 30016 -#define KEY_CTRL_F9 30017 -#define KEY_CTRL_F10 30018 -#define KEY_CTRL_F11 30019 -#define KEY_CTRL_F12 30020 -#define KEY_CTRL_F13 30021 -#define KEY_CTRL_F14 30022 -#define KEY_CTRL_CATALOG 30100 -#define KEY_CTRL_CAPTURE 30055 -#define KEY_CTRL_CLIP 30050 -#define KEY_CTRL_CUT 30250 -#define KEY_CTRL_PASTE 30036 -#define KEY_CTRL_INS 30033 -#define KEY_CTRL_MIXEDFRAC 30054 -#define KEY_CTRL_FRACCNVRT 30026 -#define KEY_CTRL_QUIT 30029 -#define KEY_CTRL_PRGM 30028 -#define KEY_CTRL_SETUP 30037 -#define KEY_CTRL_PAGEUP 30052 -#define KEY_CTRL_PAGEDOWN 30053 -#define KEY_CTRL_MENU 30003 -#define KEY_SHIFT_OPTN 30059 -#define KEY_CTRL_RESERVE1 30060 -#define KEY_CTRL_RESERVE2 30061 -#define KEY_SHIFT_LEFT 30062 -#define KEY_SHIFT_RIGHT 30063 - -#define KEY_PRGM_ACON 10 -#define KEY_PRGM_DOWN 37 -#define KEY_PRGM_EXIT 47 -#define KEY_PRGM_F1 79 -#define KEY_PRGM_F2 69 -#define KEY_PRGM_F3 59 -#define KEY_PRGM_F4 49 -#define KEY_PRGM_F5 39 -#define KEY_PRGM_F6 29 -#define KEY_PRGM_LEFT 38 -#define KEY_PRGM_NONE 0 -#define KEY_PRGM_RETURN 31 -#define KEY_PRGM_RIGHT 27 -#define KEY_PRGM_UP 28 -#define KEY_PRGM_1 72 -#define KEY_PRGM_2 62 -#define KEY_PRGM_3 52 -#define KEY_PRGM_4 73 -#define KEY_PRGM_5 63 -#define KEY_PRGM_6 53 -#define KEY_PRGM_7 74 -#define KEY_PRGM_8 64 -#define KEY_PRGM_9 54 -#define KEY_PRGM_A 76 -#define KEY_PRGM_F 26 -#define KEY_PRGM_ALPHA 77 -#define KEY_PRGM_SHIFT 78 -#define KEY_PRGM_MENU 48 - -EXTERNC uint64_t extapp_millis(); -EXTERNC void extapp_msleep(uint32_t ms); -EXTERNC uint64_t extapp_scanKeyboard(); -EXTERNC void extapp_pushRect(int16_t x, int16_t y, uint16_t w, uint16_t h, const uint16_t * pixels); -EXTERNC void extapp_pushRectUniform(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color); -EXTERNC void extapp_pullRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t * pixels); -EXTERNC int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake); -EXTERNC int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake); -EXTERNC bool extapp_waitForVBlank(); -EXTERNC void extapp_clipboardStore(const char *text); -EXTERNC const char * extapp_clipboardText(); -EXTERNC int extapp_fileListWithExtension(const char ** filenames, int maxrecords, const char * extension, int storage); -EXTERNC bool extapp_fileExists(const char * filename, int storage); -EXTERNC bool extapp_fileErase(const char * filename, int storage); -EXTERNC const char * extapp_fileRead(const char * filename, size_t *len, int storage); -EXTERNC bool extapp_fileWrite(const char * filename, const char * content, size_t len, int storage); -EXTERNC void extapp_lockAlpha(); -EXTERNC void extapp_resetKeyboard(); -EXTERNC int extapp_getKey(int allowSuspend, bool *alphaWasActive); -EXTERNC bool extapp_isKeydown(int key); -EXTERNC int extapp_restoreBackup(int mode); // Keep for compatibility with KhiCAS on Khi -EXTERNC bool extapp_eraseSector(void * ptr); -EXTERNC bool extapp_writeMemory(unsigned char * dest,const unsigned char * data,size_t length); - -#endif +// This is a dummy file to keep compatibility with sample app without editing +#include diff --git a/apps/external/external_icon.png b/apps/external/external_icon.png deleted file mode 100644 index 297dc31c6cc..00000000000 Binary files a/apps/external/external_icon.png and /dev/null differ diff --git a/apps/external/main_controller.cpp b/apps/external/main_controller.cpp deleted file mode 100644 index acf837441ef..00000000000 --- a/apps/external/main_controller.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "main_controller.h" -#include -#include -#include -#include "archive.h" -#include "app.h" -#include -#include - -using namespace Poincare; - -namespace External { - -using namespace Archive; - -MainController::MainController(Responder * parentResponder, ::App * app) : - ViewController(parentResponder), - m_selectableTableView(this) -{ - m_app = app; -} - -View * MainController::view() { - return &m_selectableTableView; -} - -void MainController::didBecomeFirstResponder() { - if (selectedRow() < 0) { - selectCellAtLocation(0, 0); - } - Container::activeApp()->setFirstResponder(&m_selectableTableView); -} - -bool MainController::handleEvent(Ion::Events::Event event) { - if ((event == Ion::Events::OK || event == Ion::Events::EXE) && ((selectedRow() < k_numberOfCells - 2) && numberOfFiles() > 0)) { - uint32_t res = executeFile(m_cells[selectedRow()].text(), ((App *)m_app)->heap(), ((App *)m_app)->heapSize()); - ((App*)m_app)->redraw(); - switch(res) { - case 0: - break; - case 1: - Container::activeApp()->displayWarning(I18n::Message::ExternalAppApiMismatch); - break; - case 2: - Container::activeApp()->displayWarning(I18n::Message::StorageMemoryFull1); - break; - default: - Container::activeApp()->displayWarning(I18n::Message::ExternalAppExecError); - break; - } - return true; - } - return false; -} - -int MainController::numberOfRows() const { - return k_numberOfCells; -}; - -KDCoordinate MainController::rowHeight(int j) { - return Metric::ParameterCellHeight; -} - -KDCoordinate MainController::cumulatedHeightFromIndex(int j) { - return j*rowHeight(0); -} - -int MainController::indexFromCumulatedHeight(KDCoordinate offsetY) { - return offsetY/rowHeight(0); -} - -HighlightCell * MainController::reusableCell(int index, int type) { - assert(index < k_numberOfCells); - return &m_cells[index]; -} - -int MainController::reusableCellCount(int type) { - return k_numberOfCells; -} - -int MainController::typeAtLocation(int i, int j) { - return 0; -} - -void MainController::willDisplayCellForIndex(HighlightCell * cell, int index) { - PointerTextTableCell * myTextCell = (PointerTextTableCell *)cell; - myTextCell->setHighlighted(myTextCell->isHighlighted()); - struct File f; - #if defined(DEVICE) || defined(EXTERNAL_BUILTIN) - #if defined(DEVICE_N0100) && !defined(EXTERNAL_BUILTIN) - if(index == 0){ - myTextCell->setText(I18n::translate(I18n::Message::ExternalNotCompatible)); - myTextCell->setTextColor(Palette::Red); - } else { - myTextCell->setText(I18n::translate(I18n::Message::WithN0100)); - myTextCell->setTextColor(Palette::Red); - } - #else - if(index == k_numberOfCells-1){ - myTextCell->setText(I18n::translate(I18n::Message::URL)); - myTextCell->setTextColor(Palette::AccentText); - return; - } - if(index == k_numberOfCells-2){ - myTextCell->setText(I18n::translate(I18n::Message::GetMoreAppsAt)); - myTextCell->setTextColor(Palette::AccentText); - return; - } - if(index == 0 && numberOfFiles() == 0){ - myTextCell->setText(I18n::translate(I18n::Message::NoAppsInstalled)); - myTextCell->setTextColor(Palette::Red); - } - if(numberOfFiles() > 0){ - if(fileAtIndex(index, f)) { - myTextCell->setText(f.name); - myTextCell->setTextColor(f.isExecutable ? Palette::PrimaryText : Palette::Palette::SecondaryText); - } - } - #endif - #else - if(index == 0){ - myTextCell->setText(I18n::translate(I18n::Message::ExternalNotCompatible)); - myTextCell->setTextColor(Palette::Red); - } else { - myTextCell->setText(I18n::translate(I18n::Message::WithSimulator)); - myTextCell->setTextColor(Palette::Red); - } - #endif -} - -void MainController::viewWillAppear() { - int count; - #if defined(DEVICE) || defined(EXTERNAL_BUILTIN) - #if !defined(DEVICE_N0110) && !defined(EXTERNAL_BUILTIN) - count = 2; - #else - if(numberOfFiles() > 0){ - count = numberOfFiles()+2; - } else { - count = 3; - } - #endif - - #else - count = 2; - #endif - k_numberOfCells = count <= k_maxNumberOfCells ? count : k_maxNumberOfCells; - m_selectableTableView.reloadData(); -} - -} diff --git a/apps/external/main_controller.h b/apps/external/main_controller.h deleted file mode 100644 index bdb6d275bd0..00000000000 --- a/apps/external/main_controller.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef EXTERNAL_MAIN_CONTROLLER_H -#define EXTERNAL_MAIN_CONTROLLER_H - -#include -#include "pointer_text_table_cell.h" - -namespace External { - -class MainController : public ViewController, public ListViewDataSource, public SelectableTableViewDataSource { -public: - MainController(Responder * parentResponder, App * app); - View * view() override; - bool handleEvent(Ion::Events::Event event) override; - void didBecomeFirstResponder() override; - int numberOfRows() const override; - KDCoordinate rowHeight(int j) override; - KDCoordinate cumulatedHeightFromIndex(int j) override; - int indexFromCumulatedHeight(KDCoordinate offsetY) override; - HighlightCell * reusableCell(int index, int type) override; - int reusableCellCount(int type) override; - int typeAtLocation(int i, int j) override; - void willDisplayCellForIndex(HighlightCell * cell, int index) override; - void viewWillAppear() override; -private: - App * m_app; - SelectableTableView m_selectableTableView; - int k_numberOfCells = 1; - constexpr static int k_maxNumberOfCells = 16; - PointerTextTableCell m_cells[k_maxNumberOfCells]; -}; - -} - -#endif diff --git a/apps/external/pointer_text_table_cell.cpp b/apps/external/pointer_text_table_cell.cpp deleted file mode 100644 index 00967fafb60..00000000000 --- a/apps/external/pointer_text_table_cell.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "pointer_text_table_cell.h" -#include -#include -#include - -PointerTextTableCell::PointerTextTableCell(const char * text, const KDFont * font, Layout layout) : - TableCell(layout), - m_pointerTextView(font, text, 0, 0.5, KDColorBlack, KDColorWhite) -{ -} - -View * PointerTextTableCell::labelView() const { - return (View *)&m_pointerTextView; -} - -const char * PointerTextTableCell::text() const { - return m_pointerTextView.text(); -} - -void PointerTextTableCell::setHighlighted(bool highlight) { - HighlightCell::setHighlighted(highlight); - KDColor backgroundColor = highlight? Palette::ListCellBackgroundSelected : Palette::ListCellBackground; - m_pointerTextView.setBackgroundColor(backgroundColor); -} - -void PointerTextTableCell::setText(const char * text) { - m_pointerTextView.setText(text); - layoutSubviews(); -} - -void PointerTextTableCell::setTextColor(KDColor color) { - m_pointerTextView.setTextColor(color); -} - -void PointerTextTableCell::setTextFont(const KDFont * font) { - m_pointerTextView.setFont(font); - layoutSubviews(); -} diff --git a/apps/external/pointer_text_table_cell.h b/apps/external/pointer_text_table_cell.h deleted file mode 100644 index 2ed0b9d5294..00000000000 --- a/apps/external/pointer_text_table_cell.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef ESCHER_POINTER_TEXT_TABLE_CELL_H -#define ESCHER_POINTER_TEXT_TABLE_CELL_H - -#include -#include - -class PointerTextTableCell : public TableCell { -public: - PointerTextTableCell(const char * text = "", const KDFont * font = KDFont::SmallFont, Layout layout = Layout::HorizontalLeftOverlap); - View * labelView() const override; - const char * text() const override; - virtual void setHighlighted(bool highlight) override; - void setText(const char * text); - virtual void setTextColor(KDColor color); - void setTextFont(const KDFont * font); -private: - PointerTextView m_pointerTextView; -}; - -#endif diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index a79700b3f0d..c5910959b25 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -11,7 +11,7 @@ extern "C" { #ifdef HOME_DISPLAY_EXTERNALS #include "../external/external_icon.h" -#include "../external/archive.h" +#include #include #endif @@ -77,10 +77,10 @@ Controller::Controller(Responder * parentResponder, SelectableTableViewDataSourc #ifdef HOME_DISPLAY_EXTERNALS - int index = External::Archive::indexFromName("wallpaper.obm"); + int index = Ion::External::Archive::indexFromName("wallpaper.obm"); if(index > -1) { - External::Archive::File image; - External::Archive::fileAtIndex(index, image); + Ion::External::Archive::File image; + Ion::External::Archive::fileAtIndex(index, image); m_view.backgroundView()->setBackgroundImage(image.data); } #endif @@ -96,9 +96,9 @@ bool Controller::handleEvent(Ion::Events::Event event) { if (GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Dutch || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSymNoText || GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::NoSym) { App::app()->displayWarning(I18n::Message::ForbiddenAppInExamMode1, I18n::Message::ForbiddenAppInExamMode2); } else { - External::Archive::File executable; - if (External::Archive::executableAtIndex(index - container->numberOfApps(), executable)) { - uint32_t res = External::Archive::executeFile(executable.name, ((App *)m_app)->heap(), ((App *)m_app)->heapSize()); + Ion::External::Archive::File executable; + if (Ion::External::Archive::executableAtIndex(index - container->numberOfApps(), executable)) { + uint32_t res = Ion::External::Archive::executeFile(executable.name, ((App *)m_app)->heap(), ((App *)m_app)->heapSize()); ((App*)m_app)->redraw(); switch(res) { case 0: @@ -197,19 +197,19 @@ void Controller::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { int appIndex = (j * k_numberOfColumns + i) + 1; if (appIndex >= container->numberOfApps()) { #ifdef HOME_DISPLAY_EXTERNALS - External::Archive::File app_file; + Ion::External::Archive::File app_file; - if (External::Archive::executableAtIndex(appIndex - container->numberOfApps(), app_file)) { + if (Ion::External::Archive::executableAtIndex(appIndex - container->numberOfApps(), app_file)) { char temp_name_buffer[100]; strlcpy(temp_name_buffer, app_file.name, 94); strlcat(temp_name_buffer, ".icon", 99); - int img_index = External::Archive::indexFromName(temp_name_buffer); + int img_index = Ion::External::Archive::indexFromName(temp_name_buffer); if (img_index != -1) { - External::Archive::File image_file; - if (External::Archive::fileAtIndex(img_index, image_file)) { + Ion::External::Archive::File image_file; + if (Ion::External::Archive::fileAtIndex(img_index, image_file)) { // const Image* img = new Image(55, 56, image_file.data, image_file.dataLength); appCell->setExtAppDescriptor(app_file.name, image_file.data, image_file.dataLength); } else { @@ -237,7 +237,7 @@ int Controller::numberOfIcons() const { AppsContainer * container = AppsContainer::sharedAppsContainer(); assert(container->numberOfApps() > 0); #ifdef HOME_DISPLAY_EXTERNALS - return container->numberOfApps() - 1 + External::Archive::numberOfExecutables(); + return container->numberOfApps() - 1 + Ion::External::Archive::numberOfExecutables(); #else return container->numberOfApps() - 1; #endif diff --git a/apps/reader/list_book_controller.h b/apps/reader/list_book_controller.h index 3250b173f80..5a71c69fe87 100644 --- a/apps/reader/list_book_controller.h +++ b/apps/reader/list_book_controller.h @@ -2,7 +2,7 @@ #define __LIST_BOOK_CONTROLLER_H__ #include -#include +#include #include "read_book_controller.h" @@ -30,7 +30,7 @@ class ListBookController : public ViewController, public SimpleListViewDataSourc private: SelectableTableView m_tableView; static const int k_maxFilesNumber = 20; - External::Archive::File m_files[k_maxFilesNumber]; + Ion::External::Archive::File m_files[k_maxFilesNumber]; int m_txtFilesNumber; int m_urtFilesNumber; static const int k_cellsNumber = 6; diff --git a/apps/reader/read_book_controller.cpp b/apps/reader/read_book_controller.cpp index 85ef0b77c23..9b3f8b15aff 100644 --- a/apps/reader/read_book_controller.cpp +++ b/apps/reader/read_book_controller.cpp @@ -14,7 +14,7 @@ View * ReadBookController::view() { return &m_readerView; } -void ReadBookController::setBook(const External::Archive::File& file, bool isRichTextFile) { +void ReadBookController::setBook(const Ion::External::Archive::File& file, bool isRichTextFile) { m_file = &file; loadPosition(); m_readerView.setText(reinterpret_cast(file.data), file.dataLength, isRichTextFile); diff --git a/apps/reader/read_book_controller.h b/apps/reader/read_book_controller.h index 7fb42b16587..63db9a82580 100644 --- a/apps/reader/read_book_controller.h +++ b/apps/reader/read_book_controller.h @@ -2,7 +2,7 @@ #define _READ_BOOK_CONTROLLER_H_ #include -#include "apps/external/archive.h" +#include "ion/external.h" #include "word_wrap_view.h" namespace Reader { @@ -11,7 +11,7 @@ class ReadBookController : public ViewController { public: ReadBookController(Responder * parentResponder); View * view() override; - void setBook(const External::Archive::File& file, bool isRichTextFile); + void setBook(const Ion::External::Archive::File& file, bool isRichTextFile); bool handleEvent(Ion::Events::Event event) override; void viewDidDisappear() override; void savePosition() const; @@ -19,7 +19,7 @@ class ReadBookController : public ViewController { void throwError(); private: WordWrapTextView m_readerView; - const External::Archive::File* m_file; + const Ion::External::Archive::File* m_file; }; } diff --git a/apps/reader/utility.cpp b/apps/reader/utility.cpp index c29c28f1f29..efcfe671631 100644 --- a/apps/reader/utility.cpp +++ b/apps/reader/utility.cpp @@ -46,12 +46,12 @@ void stringNCopy(char* dest, int max, const char* src, int len) { #ifdef DEVICE -int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) { - size_t nbTotalFiles = External::Archive::numberOfFiles(); +int filesWithExtension(const char* extension, Ion::External::Archive::File* files, int filesSize) { + size_t nbTotalFiles = Ion::External::Archive::numberOfFiles(); int nbFiles = 0; for(size_t i=0; i < nbTotalFiles; ++i) { - External::Archive::File file; - External::Archive::fileAtIndex(i, file); + Ion::External::Archive::File file; + Ion::External::Archive::fileAtIndex(i, file); if(stringEndsWith(file.name, extension)) { files[nbFiles] = file; nbFiles++; @@ -63,7 +63,7 @@ int filesWithExtension(const char* extension, External::Archive::File* files, in } #else -static void fillFileData(External::Archive::File& file) { +static void fillFileData(Ion::External::Archive::File& file) { file.data = nullptr; file.dataLength = 0; @@ -87,7 +87,7 @@ static void fillFileData(External::Archive::File& file) { file.dataLength = info.st_size; } -int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize) { +int filesWithExtension(const char* extension, Ion::External::Archive::File* files, int filesSize) { dirent *file; DIR *d = opendir("."); int nb = 0; diff --git a/apps/reader/utility.h b/apps/reader/utility.h index 61aabbf2cf6..794c7f17f98 100644 --- a/apps/reader/utility.h +++ b/apps/reader/utility.h @@ -1,7 +1,7 @@ #ifndef __UTILITY_H__ #define __UTILITY_H__ -#include +#include #include #include @@ -9,7 +9,7 @@ namespace Reader { bool stringEndsWith(const char* str, const char* end); -int filesWithExtension(const char* extension, External::Archive::File* files, int filesSize); +int filesWithExtension(const char* extension, Ion::External::Archive::File* files, int filesSize); void stringNCopy(char* dest, int max, const char* src, int len); const char * EndOfPrintableWord(const char * word, const char * end); const char * StartOfPrintableWord(const char * word, const char * start); diff --git a/escher/src/background_view.cpp b/escher/src/background_view.cpp index 3711185c080..392bcd16272 100644 --- a/escher/src/background_view.cpp +++ b/escher/src/background_view.cpp @@ -5,7 +5,6 @@ #include "apps/home/controller.h" #ifdef HOME_DISPLAY_EXTERNALS #include "apps/external/external_icon.h" -#include "apps/external/archive.h" #include #endif diff --git a/ion/Makefile b/ion/Makefile index 96797fba26f..3647e054310 100644 --- a/ion/Makefile +++ b/ion/Makefile @@ -31,6 +31,7 @@ ion_src += $(addprefix ion/src/shared/, \ events.cpp \ events_keyboard.cpp \ events_modifier.cpp \ + extapp_api.cpp \ rtc.cpp \ stack_position.cpp \ storage.cpp \ diff --git a/ion/include/ion/extapp_api.h b/ion/include/ion/extapp_api.h new file mode 100644 index 00000000000..2f6f25f1c61 --- /dev/null +++ b/ion/include/ion/extapp_api.h @@ -0,0 +1,415 @@ +#ifndef EXTERNAL_API_H +#define EXTERNAL_API_H + +#include +#include +#include + +#define API_VERSION 2 + +#ifdef __cplusplus +#define EXTERNC extern "C" +#else +#define EXTERNC extern +#endif + +// Screen size +// The screen width +#define LCD_WIDTH 320 +// The screen height +#define LCD_HEIGHT 240 + +// Files systems +// The RAM file system, which can be written, and it is used by the system applications, +// this storage is erased on reset +#define EXTAPP_RAM_FILE_SYSTEM 0 +// The flash file system, which is written by the external application website, +// used for big files storing, and roms, this storage is kept after a reset +#define EXTAPP_FLASH_FILE_SYSTEM 1 +#define EXTAPP_BOTH_FILE_SYSTEM 2 + +// The code of the keys, returned by `extapp_scanKeyboard()` +#define SCANCODE_Left ((uint64_t)1 << 0) +#define SCANCODE_Up ((uint64_t)1 << 1) +#define SCANCODE_Down ((uint64_t)1 << 2) +#define SCANCODE_Right ((uint64_t)1 << 3) +#define SCANCODE_OK ((uint64_t)1 << 4) +#define SCANCODE_Back ((uint64_t)1 << 5) +#define SCANCODE_Home ((uint64_t)1 << 6) +#define SCANCODE_OnOff (((uint64_t)1 << 7) || ((uint64_t)1 << 8)) +#define SCANCODE_Shift ((uint64_t)1 << 12) +#define SCANCODE_Alpha ((uint64_t)1 << 13) +#define SCANCODE_XNT ((uint64_t)1 << 14) +#define SCANCODE_Var ((uint64_t)1 << 15) +#define SCANCODE_Toolbox ((uint64_t)1 << 16) +#define SCANCODE_Backspace ((uint64_t)1 << 17) +#define SCANCODE_Exp ((uint64_t)1 << 18) +#define SCANCODE_Ln ((uint64_t)1 << 19) +#define SCANCODE_Log ((uint64_t)1 << 20) +#define SCANCODE_Imaginary ((uint64_t)1 << 21) +#define SCANCODE_Comma ((uint64_t)1 << 22) +#define SCANCODE_Power ((uint64_t)1 << 23) +#define SCANCODE_Sine ((uint64_t)1 << 24) +#define SCANCODE_Cosine ((uint64_t)1 << 25) +#define SCANCODE_Tangent ((uint64_t)1 << 26) +#define SCANCODE_Pi ((uint64_t)1 << 27) +#define SCANCODE_Sqrt ((uint64_t)1 << 28) +#define SCANCODE_Square ((uint64_t)1 << 29) +#define SCANCODE_Seven ((uint64_t)1 << 30) +#define SCANCODE_Eight ((uint64_t)1 << 31) +#define SCANCODE_Nine ((uint64_t)1 << 32) +#define SCANCODE_LeftParenthesis ((uint64_t)1 << 33) +#define SCANCODE_RightParenthesis ((uint64_t)1 << 34) +#define SCANCODE_Four ((uint64_t)1 << 36) +#define SCANCODE_Five ((uint64_t)1 << 37) +#define SCANCODE_Six ((uint64_t)1 << 38) +#define SCANCODE_Multiplication ((uint64_t)1 << 39) +#define SCANCODE_Division ((uint64_t)1 << 40) +#define SCANCODE_One ((uint64_t)1 << 42) +#define SCANCODE_Two ((uint64_t)1 << 43) +#define SCANCODE_Three ((uint64_t)1 << 44) +#define SCANCODE_Plus ((uint64_t)1 << 45) +#define SCANCODE_Minus ((uint64_t)1 << 46) +#define SCANCODE_Zero ((uint64_t)1 << 48) +#define SCANCODE_Dot ((uint64_t)1 << 49) +#define SCANCODE_EE ((uint64_t)1 << 50) +#define SCANCODE_Ans ((uint64_t)1 << 51) +#define SCANCODE_EXE ((uint64_t)1 << 52) +#define SCANCODE_None ((uint64_t)1 << 54) + +// Keys, returned by `extapp_getKey()` +// Character codes +#define KEY_CHAR_0 0x30 +#define KEY_CHAR_1 0x31 +#define KEY_CHAR_2 0x32 +#define KEY_CHAR_3 0x33 +#define KEY_CHAR_4 0x34 +#define KEY_CHAR_5 0x35 +#define KEY_CHAR_6 0x36 +#define KEY_CHAR_7 0x37 +#define KEY_CHAR_8 0x38 +#define KEY_CHAR_9 0x39 +#define KEY_CHAR_DP 0x2e +#define KEY_CHAR_EXP 0x0f +#define KEY_CHAR_PMINUS 30200 +#define KEY_CHAR_PLUS 43 +#define KEY_CHAR_MINUS 45 +#define KEY_CHAR_MULT 42 +#define KEY_CHAR_DIV 47 +#define KEY_CHAR_FRAC 0xbb +#define KEY_CHAR_LPAR 0x28 +#define KEY_CHAR_RPAR 0x29 +#define KEY_CHAR_COMMA 0x2c +#define KEY_CHAR_STORE 0x0e +#define KEY_CHAR_LOG 0x95 +#define KEY_CHAR_LN 0x85 +#define KEY_CHAR_SIN 0x81 +#define KEY_CHAR_COS 0x82 +#define KEY_CHAR_TAN 0x83 +#define KEY_CHAR_SQUARE 0x8b +#define KEY_CHAR_POW 0xa8 +#define KEY_CHAR_IMGNRY 0x7f50 +#define KEY_CHAR_LIST 0x7f51 +#define KEY_CHAR_MAT 0x7f40 +#define KEY_CHAR_EQUAL 0x3d +#define KEY_CHAR_PI 0xd0 +#define KEY_CHAR_ANS 0xc0 +#define KEY_SHIFT_ANS 0xc1 +#define KEY_CHAR_LBRCKT 0x5b +#define KEY_CHAR_RBRCKT 0x5d +#define KEY_CHAR_LBRACE 0x7b +#define KEY_CHAR_RBRACE 0x7d +#define KEY_CHAR_CR 0x0d +#define KEY_CHAR_CUBEROOT 0x96 +#define KEY_CHAR_RECIP 0x9b +#define KEY_CHAR_ANGLE 0x7f54 +#define KEY_CHAR_EXPN10 0xb5 +#define KEY_CHAR_EXPN 0xa5 +#define KEY_CHAR_ASIN 0x91 +#define KEY_CHAR_ACOS 0x92 +#define KEY_CHAR_ATAN 0x93 +#define KEY_CHAR_ROOT 0x86 +#define KEY_CHAR_POWROOT 0xb8 +#define KEY_CHAR_SPACE 0x20 +#define KEY_CHAR_DQUATE 0x22 +#define KEY_CHAR_VALR 0xcd +#define KEY_CHAR_THETA 0xce +#define KEY_CHAR_FACTOR 0xda +#define KEY_CHAR_NORMAL 0xdb +#define KEY_CHAR_A 0x41 +#define KEY_CHAR_B 0x42 +#define KEY_CHAR_C 0x43 +#define KEY_CHAR_D 0x44 +#define KEY_CHAR_E 0x45 +#define KEY_CHAR_F 0x46 +#define KEY_CHAR_G 0x47 +#define KEY_CHAR_H 0x48 +#define KEY_CHAR_I 0x49 +#define KEY_CHAR_J 0x4a +#define KEY_CHAR_K 0x4b +#define KEY_CHAR_L 0x4c +#define KEY_CHAR_M 0x4d +#define KEY_CHAR_N 0x4e +#define KEY_CHAR_O 0x4f +#define KEY_CHAR_P 0x50 +#define KEY_CHAR_Q 0x51 +#define KEY_CHAR_R 0x52 +#define KEY_CHAR_S 0x53 +#define KEY_CHAR_T 0x54 +#define KEY_CHAR_U 0x55 +#define KEY_CHAR_V 0x56 +#define KEY_CHAR_W 0x57 +#define KEY_CHAR_X 0x58 +#define KEY_CHAR_Y 0x59 +#define KEY_CHAR_Z 0x5a + +// Control codes +#define KEY_CTRL_NOP 30202 +#define KEY_CTRL_EXE 30201 +#define KEY_CTRL_DEL 30025 +#define KEY_CTRL_AC 30070 +#define KEY_CTRL_FD 30046 +#define KEY_CTRL_UNDO 30045 +#define KEY_CTRL_XTT 30001 +#define KEY_CTRL_EXIT 5 +#define KEY_CTRL_OK 4 +#define KEY_CTRL_SHIFT 30006 +#define KEY_CTRL_ALPHA 30007 +#define KEY_CTRL_OPTN 30008 +#define KEY_CTRL_VARS 30030 +#define KEY_CTRL_UP 1 +#define KEY_CTRL_DOWN 2 +#define KEY_CTRL_LEFT 0 +#define KEY_CTRL_RIGHT 3 +#define KEY_CTRL_F1 30009 +#define KEY_CTRL_F2 30010 +#define KEY_CTRL_F3 30011 +#define KEY_CTRL_F4 30012 +#define KEY_CTRL_F5 30013 +#define KEY_CTRL_F6 30014 +#define KEY_CTRL_F7 30015 +#define KEY_CTRL_F8 30016 +#define KEY_CTRL_F9 30017 +#define KEY_CTRL_F10 30018 +#define KEY_CTRL_F11 30019 +#define KEY_CTRL_F12 30020 +#define KEY_CTRL_F13 30021 +#define KEY_CTRL_F14 30022 +#define KEY_CTRL_CATALOG 30100 +#define KEY_CTRL_CAPTURE 30055 +#define KEY_CTRL_CLIP 30050 +#define KEY_CTRL_CUT 30250 +#define KEY_CTRL_PASTE 30036 +#define KEY_CTRL_INS 30033 +#define KEY_CTRL_MIXEDFRAC 30054 +#define KEY_CTRL_FRACCNVRT 30026 +#define KEY_CTRL_QUIT 30029 +#define KEY_CTRL_PRGM 30028 +#define KEY_CTRL_SETUP 30037 +#define KEY_CTRL_PAGEUP 30052 +#define KEY_CTRL_PAGEDOWN 30053 +#define KEY_CTRL_MENU 30003 +#define KEY_SHIFT_OPTN 30059 +#define KEY_CTRL_RESERVE1 30060 +#define KEY_CTRL_RESERVE2 30061 +#define KEY_SHIFT_LEFT 30062 +#define KEY_SHIFT_RIGHT 30063 + +#define KEY_PRGM_ACON 10 +#define KEY_PRGM_DOWN 37 +#define KEY_PRGM_EXIT 47 +#define KEY_PRGM_F1 79 +#define KEY_PRGM_F2 69 +#define KEY_PRGM_F3 59 +#define KEY_PRGM_F4 49 +#define KEY_PRGM_F5 39 +#define KEY_PRGM_F6 29 +#define KEY_PRGM_LEFT 38 +#define KEY_PRGM_NONE 0 +#define KEY_PRGM_RETURN 31 +#define KEY_PRGM_RIGHT 27 +#define KEY_PRGM_UP 28 +#define KEY_PRGM_1 72 +#define KEY_PRGM_2 62 +#define KEY_PRGM_3 52 +#define KEY_PRGM_4 73 +#define KEY_PRGM_5 63 +#define KEY_PRGM_6 53 +#define KEY_PRGM_7 74 +#define KEY_PRGM_8 64 +#define KEY_PRGM_9 54 +#define KEY_PRGM_A 76 +#define KEY_PRGM_F 26 +#define KEY_PRGM_ALPHA 77 +#define KEY_PRGM_SHIFT 78 +#define KEY_PRGM_MENU 48 + +// External API functions +/** + * Get the current date, in milliseconds, from the boot, excluding suspended time + * @return uint64_t, the current date from the boot in milliseconds + */ +EXTERNC uint64_t extapp_millis(); +/** + * Sleep ms milliseconds + * @param ms uint32_t, the number of milliseconds to sleep + */ +EXTERNC void extapp_msleep(uint32_t ms); +// Scan the keyboard, and return a key that can be identified by SCANCODE_* constants (like SCANCODE_Left) +EXTERNC uint64_t extapp_scanKeyboard(); +/** + * Push a buffer of pixels to the screen + * @param x uint16_t, the x position of the buffer to display on the screen + * @param y uint16_t, the y position of the buffer to display on the screen + * @param w uint16_t, the width of the buffer to display on the screen + * @param h uint16_t, the height of the buffer to display on the screen + * @param pixels const uint16_t *, the buffer to display on the screen + */ +EXTERNC void extapp_pushRect(int16_t x, int16_t y, uint16_t w, uint16_t h, const uint16_t * pixels); +/** + * Push a colored rectangle on the screen + * @param x uint16_t, the x position of the rectangle + * @param y uint16_t, the y position of the rectangle + * @param w uint16_t, the width of the rectangle + * @param h uint16_t, the height of the rectangle + * @param color uint16_t, the color of the rectangle + */ +EXTERNC void extapp_pushRectUniform(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color); +/** + * Push a rectangle from the screen + * @param x uint16_t, the x position of the rectangle + * @param y uint16_t, the y position of the rectangle + * @param w uint16_t, the width of the rectangle + * @param h uint16_t, the height of the rectangle + * @param pixels uint16_t *, the pointer to the buffer to store the pixel rect + */ +EXTERNC void extapp_pullRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t * pixels); +/** + * Display large text + * @param text const char *t, the text to display + * @param x int16_t, the x position of the text to display + * @param y int16_t, the y position of the text to display + * @param fg uint16_t, the color of the foreground + * @param bg uint16_t, the color of the background + * @param fake bool, whether to not display the text, just return the size of the text + * @return uint16_t, the width of the text + */ +EXTERNC int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake); +/** + * Display small text + * @param text const char *t, the text to display + * @param x int16_t, the x position of the text to display + * @param y int16_t, the y position of the text to display + * @param fg uint16_t, the color of the foreground + * @param bg uint16_t, the color of the background + * @param fake bool, whether to not display the text, just return the size of the text + * @return uint16_t, the width of the text + */ +EXTERNC int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake); +/** + * Wait for screen refresh + */ +EXTERNC bool extapp_waitForVBlank(); +/** + * Set text into clipboard + * @param text const char *t, the text to copy + */ +EXTERNC void extapp_clipboardStore(const char *text); +/** + * Get clipboard contents + * @return const char *, the contents of the clipboard + */ +EXTERNC const char * extapp_clipboardText(); +/** + * Get a list of files in "storage", filtered by extension + * @param filename const char **, an array that must to be a equal to + * the maxrecords variable, to avoid buffer overflow + * @param maxrecords int, the maximum number of records that can be retrieved, + * it should be equal to the length of the filenames array, + * to avoid buffer overflow + * @param extension const char *, the extension of the filename to retrieve, + * it work only with RAM file system for now + * @param storage int, the storage to use (like EXTAPP_FLASH_FILE_SYSTEM) + * @return int, the number of retrieved records + */ +EXTERNC int extapp_fileListWithExtension(const char ** filenames, int maxrecords, const char * extension, int storage); +/** + * Return if "filename" exist in "storage" + * @param filename const char *, the file to check existing + * @param storage int, the storage to use (like EXTAPP_FLASH_FILE_SYSTEM) + * @return bool, true if the operation is successful + */ +EXTERNC bool extapp_fileExists(const char * filename, int storage); +/** + * Erase "filename" in "storage" + * @param filename const char *, the file to remove + * @param storage int, the storage to use (like EXTAPP_RAM_FILE_SYSTEM) + * @return bool, true if the operation is successful + */ +EXTERNC bool extapp_fileErase(const char * filename, int storage); +/** + * Read "filename" from "storage" + * @param filename const char *, the file to read + * @param len, size_t, a pointer to a size_t variable, to store the file length + * @param storage int, the storage to use (like EXTAPP_FLASH_FILE_SYSTEM) + * @return const char *, the file content + */ +EXTERNC const char * extapp_fileRead(const char * filename, size_t *len, int storage); +/** + * Write "content" into "filename" in "storage" + * @param filename const char *, the file to write + * @param content, const char *, the content of the file to write + * @param len, size_t, the length of the file to write + * @param storage int, the storage to use (like EXTAPP_FLASH_FILE_SYSTEM) + * @return bool, true if the operation is successful + */ +EXTERNC bool extapp_fileWrite(const char * filename, const char * content, size_t len, int storage); +/** + * Enable alpha lock + */ +EXTERNC void extapp_lockAlpha(); +/** + * Reset keyboard status, like alpha lock + */ +EXTERNC void extapp_resetKeyboard(); +/** + * Get pressed keys + * @param allowSuspend bool, whether to allow suspending the calculator + * @param alphaWasActive bool, a pointer to a bool to store if the alpha (lock) was active + * @return int, the code of the pressed key, like KEY_CHAR_0 or KEY_CTRL_EXE + */ +EXTERNC int extapp_getKey(int allowSuspend, bool *alphaWasActive); +/** + * If given key is pressed + * @param key int, the key to check + * @return bool, true if the key is pressed + */ +EXTERNC bool extapp_isKeydown(int key); +/** + * Restore the exam mode backup, created by KhiCAS and Khi + * @param mode int, the mode to restore (TODO: Improve this) + * @return int, higher than 0 if the operation is successful + */ +EXTERNC int extapp_restorebackup(int mode); // currently works only with mode==-1 to restore scriptstore after exam mode +/** + * Erase flash sector, works only when "Write allowed" is enabled in the calculator + * @param ptr void *, the sector to erase + * @return bool, true if the operation is successful + */ +EXTERNC bool extapp_erasesector(void * ptr); +/** + * Write flash sector, works only when "Write allowed" is enabled in the calculator + * @param dest unsigned char *, the destination address + * @param data unsigned char *, the data to write + * @param length size_t, the length of the data to write + */ +EXTERNC bool extapp_writesector(unsigned char * dest,const unsigned char * data,size_t length); +/** + * Get if the exam mode is active + * @return bool, true if the exam mode is active + */ +EXTERNC bool extapp_inexammode(); +EXTERNC uint32_t _heap_size; +EXTERNC void *_heap_base; +EXTERNC void *_heap_ptr; +#endif \ No newline at end of file diff --git a/apps/external/archive.h b/ion/include/ion/external.h similarity index 86% rename from apps/external/archive.h rename to ion/include/ion/external.h index de96e6d204f..f384873a030 100644 --- a/apps/external/archive.h +++ b/ion/include/ion/external.h @@ -1,9 +1,12 @@ -#ifndef EXTERNAL_ARCHIVE_H -#define EXTERNAL_ARCHIVE_H +#ifndef ION_EXTERNAL_H +#define ION_EXTERNAL_H +extern "C" { #include #include +} +namespace Ion { namespace External { namespace Archive { @@ -24,6 +27,7 @@ size_t numberOfExecutables(); bool executableAtIndex(size_t index, File &entry); uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize); +} } } diff --git a/ion/src/blackbox/Makefile b/ion/src/blackbox/Makefile index b4ed4aec5c1..522678c7055 100644 --- a/ion/src/blackbox/Makefile +++ b/ion/src/blackbox/Makefile @@ -13,6 +13,7 @@ ion_src += $(addprefix ion/src/shared/, \ power.cpp \ random.cpp \ timing.cpp \ + dummy/archive.cpp \ dummy/backlight.cpp \ dummy/battery.cpp \ dummy/rtc.cpp \ diff --git a/ion/src/device/bootloader/Makefile b/ion/src/device/bootloader/Makefile index c5d7208f7ab..f0822cb2285 100644 --- a/ion/src/device/bootloader/Makefile +++ b/ion/src/device/bootloader/Makefile @@ -1,5 +1,6 @@ ion_device_src += $(addprefix ion/src/device/bootloader/drivers/, \ + archive.cpp \ board.cpp \ cache.cpp \ external_flash_tramp.cpp \ diff --git a/apps/external/archive.cpp b/ion/src/device/bootloader/drivers/archive.cpp similarity index 53% rename from apps/external/archive.cpp rename to ion/src/device/bootloader/drivers/archive.cpp index 285e262a586..419f83f8ff4 100644 --- a/apps/external/archive.cpp +++ b/ion/src/device/bootloader/drivers/archive.cpp @@ -1,42 +1,101 @@ -#include "archive.h" -#include "extapp_api.h" -#include "../global_preferences.h" +#include "apps/global_preferences.h" +#include +#include -#include #include +#include +namespace Ion { namespace External { namespace Archive { -#ifdef DEVICE - -struct TarHeader -{ /* byte offset */ - char name[100]; /* 0 */ - char mode[8]; /* 100 */ - char uid[8]; /* 108 */ - char gid[8]; /* 116 */ - char size[12]; /* 124 */ - char mtime[12]; /* 136 */ - char chksum[8]; /* 148 */ - char typeflag; /* 156 */ - char linkname[100]; /* 157 */ - char magic[8]; /* 257 */ - char uname[32]; /* 265 */ - char gname[32]; /* 297 */ - char devmajor[8]; /* 329 */ - char devminor[8]; /* 337 */ - char padding[167]; /* 345 */ +size_t numberOfFiles() { + File dummy{}; + size_t count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) {;} + + return count; +} + +int indexFromName(const char *name) { + File entry{}; + + for (int i = 0; fileAtIndex(i, entry); i++) { + if (entry.readable && strcmp(name, entry.name) == 0) { + return i; + } + } + + return -1; +} + +bool executableAtIndex(size_t index, File &entry) { + File dummy{}; + size_t count = 0; + size_t final_count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) { + if (dummy.isExecutable) { + if (final_count == index) { + entry.name = dummy.name; + entry.data = dummy.data; + entry.dataLength = dummy.dataLength; + entry.isExecutable = dummy.isExecutable; + entry.readable = dummy.readable; + return true; + } + final_count++; + } + } + return false; +} + +size_t numberOfExecutables() { + if (!GlobalPreferences::sharedGlobalPreferences()->externalAppShown()) { + return 0U; + } + File dummy{}; + size_t count = 0; + size_t final_count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) { + if (dummy.isExecutable) { + final_count++; + } + } + + return final_count; +} + +struct TarHeader { /* byte offset */ + char name[100]; /* 0 */ + char mode[8]; /* 100 */ + char uid[8]; /* 108 */ + char gid[8]; /* 116 */ + char size[12]; /* 124 */ + char mtime[12]; /* 136 */ + char chksum[8]; /* 148 */ + char typeflag; /* 156 */ + char linkname[100]; /* 157 */ + char magic[8]; /* 257 */ + char uname[32]; /* 265 */ + char gname[32]; /* 297 */ + char devmajor[8]; /* 329 */ + char devminor[8]; /* 337 */ + char padding[167]; /* 345 */ } __attribute__((packed)); static_assert(sizeof(TarHeader) == 512); -bool isSane(const TarHeader* tar) { - return !memcmp(tar->magic, "ustar ", 8) && tar->name[0] != '\x00' && tar->name[0] != '\xFF'; +bool isSane(const TarHeader *tar) { + return !memcmp(tar->magic, "ustar ", 8) && tar->name[0] != '\x00' && + tar->name[0] != '\xFF'; } -bool isExamModeAndFileNotExecutable(const TarHeader* tar) { - return GlobalPreferences::sharedGlobalPreferences()->isInExamMode() && (tar->mode[4] & 0x01) == 0; +bool isExamModeAndFileNotExecutable(const TarHeader *tar) { + return GlobalPreferences::sharedGlobalPreferences()->isInExamMode() && + (tar->mode[4] & 0x01) == 0; } bool fileAtIndex(size_t index, File &entry) { @@ -44,7 +103,7 @@ bool fileAtIndex(size_t index, File &entry) { return false; } - const TarHeader* tar = reinterpret_cast(0x90200000); + const TarHeader * tar = reinterpret_cast(0x90200000); unsigned size = 0; // Sanity check. @@ -56,13 +115,14 @@ bool fileAtIndex(size_t index, File &entry) { * TAR files are comprised of a set of records aligned to 512 bytes boundary * followed by data. */ - - for(;;) { + + for (;;) { // Calculate the size size = 0; - for (int i = 0; i < 11; i++) + for (int i = 0; i < 11; i++) { size = size * 8 + (tar->size[i] - '0'); - + } + // Check if we found our file. if (index == 0) { // If yes, check for sanity and for exam mode stuff @@ -72,7 +132,7 @@ bool fileAtIndex(size_t index, File &entry) { // File entry found, copy data out. entry.name = tar->name; - entry.data = reinterpret_cast(tar) + sizeof(TarHeader); + entry.data = reinterpret_cast(tar) + sizeof(TarHeader); entry.dataLength = size; entry.isExecutable = (tar->mode[4] & 0x01) == 1; // TODO: Handle the trash @@ -83,7 +143,8 @@ bool fileAtIndex(size_t index, File &entry) { // move to the next TAR header. unsigned stride = (sizeof(TarHeader) + size + 511); stride = (stride >> 9) << 9; - tar = reinterpret_cast(reinterpret_cast(tar) + stride); + tar = reinterpret_cast( + reinterpret_cast(tar) + stride); // Sanity check. if (!isSane(tar)) { @@ -92,109 +153,29 @@ bool fileAtIndex(size_t index, File &entry) { } index--; } - + // Achievement unlock: How did we get there ? return false; } -extern "C" void (* const apiPointers[])(void); -typedef uint32_t (*entrypoint)(const uint32_t, const void *, void *, const uint32_t); +extern "C" void (*const apiPointers[])(void); +typedef uint32_t (*entrypoint)(const uint32_t, const void *, void *, + const uint32_t); -uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize) { +uint32_t executeFile(const char *name, void *heap, const uint32_t heapSize) { File entry; - if(fileAtIndex(indexFromName(name), entry)) { - if(!entry.isExecutable) { + if (fileAtIndex(indexFromName(name), entry)) { + if (!entry.isExecutable) { return 0; } - uint32_t ep = *reinterpret_cast(entry.data); - if(ep >= 0x90200000 && ep < 0x90800000) { + uint32_t ep = *reinterpret_cast(entry.data); + if (ep >= 0x90200000 && ep < 0x90800000) { return ((entrypoint)ep)(API_VERSION, apiPointers, heap, heapSize); } } return -1; } - -#else - -bool fileAtIndex(size_t index, File &entry) { - if (index != 0) { - return false; - } - - entry.name = "Built-in"; - entry.data = NULL; - entry.dataLength = 0; - entry.isExecutable = true; - entry.readable = true; - return true; } - -extern "C" void extapp_main(void); - -uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize) { - extapp_main(); - return 0; -} - -#endif - -size_t numberOfFiles() { - File dummy; - size_t count; - - for (count = 0; fileAtIndex(count, dummy); count++); - - return count; -} - -int indexFromName(const char *name) { - File entry; - - for (int i = 0; fileAtIndex(i, entry); i++) { - if (entry.readable && strcmp(name, entry.name) == 0) { - return i; - } - } - - return -1; -} - -bool executableAtIndex(size_t index, File &entry) { - File dummy; - size_t count; - size_t final_count = 0; - - for (count = 0; fileAtIndex(count, dummy); count++) { - if (dummy.isExecutable) { - if (final_count == index) { - entry.name = dummy.name; - entry.data = dummy.data; - entry.dataLength = dummy.dataLength; - entry.isExecutable = dummy.isExecutable; - entry.readable = dummy.readable; - return true; - } - final_count++; - } - } - return false; -} - -size_t numberOfExecutables() { - if (!GlobalPreferences::sharedGlobalPreferences()->externalAppShown()) { - return false; - } - File dummy; - size_t count; - size_t final_count = 0; - - for (count = 0; fileAtIndex(count, dummy); count++) - if (dummy.isExecutable) - final_count++; - - return final_count; -} - } } diff --git a/ion/src/device/n0110/Makefile b/ion/src/device/n0110/Makefile index 24b1a720469..c39f28bf39f 100644 --- a/ion/src/device/n0110/Makefile +++ b/ion/src/device/n0110/Makefile @@ -1,4 +1,5 @@ ion_device_src += $(addprefix ion/src/device/n0110/drivers/, \ + archive.cpp \ cache.cpp \ external_flash.cpp \ led.cpp \ diff --git a/ion/src/device/n0110/drivers/archive.cpp b/ion/src/device/n0110/drivers/archive.cpp new file mode 100644 index 00000000000..419f83f8ff4 --- /dev/null +++ b/ion/src/device/n0110/drivers/archive.cpp @@ -0,0 +1,181 @@ +#include "apps/global_preferences.h" +#include +#include + +#include +#include + +namespace Ion { +namespace External { +namespace Archive { + +size_t numberOfFiles() { + File dummy{}; + size_t count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) {;} + + return count; +} + +int indexFromName(const char *name) { + File entry{}; + + for (int i = 0; fileAtIndex(i, entry); i++) { + if (entry.readable && strcmp(name, entry.name) == 0) { + return i; + } + } + + return -1; +} + +bool executableAtIndex(size_t index, File &entry) { + File dummy{}; + size_t count = 0; + size_t final_count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) { + if (dummy.isExecutable) { + if (final_count == index) { + entry.name = dummy.name; + entry.data = dummy.data; + entry.dataLength = dummy.dataLength; + entry.isExecutable = dummy.isExecutable; + entry.readable = dummy.readable; + return true; + } + final_count++; + } + } + return false; +} + +size_t numberOfExecutables() { + if (!GlobalPreferences::sharedGlobalPreferences()->externalAppShown()) { + return 0U; + } + File dummy{}; + size_t count = 0; + size_t final_count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) { + if (dummy.isExecutable) { + final_count++; + } + } + + return final_count; +} + +struct TarHeader { /* byte offset */ + char name[100]; /* 0 */ + char mode[8]; /* 100 */ + char uid[8]; /* 108 */ + char gid[8]; /* 116 */ + char size[12]; /* 124 */ + char mtime[12]; /* 136 */ + char chksum[8]; /* 148 */ + char typeflag; /* 156 */ + char linkname[100]; /* 157 */ + char magic[8]; /* 257 */ + char uname[32]; /* 265 */ + char gname[32]; /* 297 */ + char devmajor[8]; /* 329 */ + char devminor[8]; /* 337 */ + char padding[167]; /* 345 */ +} __attribute__((packed)); + +static_assert(sizeof(TarHeader) == 512); + +bool isSane(const TarHeader *tar) { + return !memcmp(tar->magic, "ustar ", 8) && tar->name[0] != '\x00' && + tar->name[0] != '\xFF'; +} + +bool isExamModeAndFileNotExecutable(const TarHeader *tar) { + return GlobalPreferences::sharedGlobalPreferences()->isInExamMode() && + (tar->mode[4] & 0x01) == 0; +} + +bool fileAtIndex(size_t index, File &entry) { + if (index == -1) { + return false; + } + + const TarHeader * tar = reinterpret_cast(0x90200000); + unsigned size = 0; + + // Sanity check. + if (!isSane(tar) || isExamModeAndFileNotExecutable(tar)) { + return false; + } + + /** + * TAR files are comprised of a set of records aligned to 512 bytes boundary + * followed by data. + */ + + for (;;) { + // Calculate the size + size = 0; + for (int i = 0; i < 11; i++) { + size = size * 8 + (tar->size[i] - '0'); + } + + // Check if we found our file. + if (index == 0) { + // If yes, check for sanity and for exam mode stuff + if (!isSane(tar) || isExamModeAndFileNotExecutable(tar)) { + return false; + } + + // File entry found, copy data out. + entry.name = tar->name; + entry.data = reinterpret_cast(tar) + sizeof(TarHeader); + entry.dataLength = size; + entry.isExecutable = (tar->mode[4] & 0x01) == 1; + // TODO: Handle the trash + entry.readable = true; + + return true; + } else { + // move to the next TAR header. + unsigned stride = (sizeof(TarHeader) + size + 511); + stride = (stride >> 9) << 9; + tar = reinterpret_cast( + reinterpret_cast(tar) + stride); + + // Sanity check. + if (!isSane(tar)) { + return false; + } + } + index--; + } + + // Achievement unlock: How did we get there ? + return false; +} + +extern "C" void (*const apiPointers[])(void); +typedef uint32_t (*entrypoint)(const uint32_t, const void *, void *, + const uint32_t); + +uint32_t executeFile(const char *name, void *heap, const uint32_t heapSize) { + File entry; + if (fileAtIndex(indexFromName(name), entry)) { + if (!entry.isExecutable) { + return 0; + } + uint32_t ep = *reinterpret_cast(entry.data); + if (ep >= 0x90200000 && ep < 0x90800000) { + return ((entrypoint)ep)(API_VERSION, apiPointers, heap, heapSize); + } + } + return -1; +} + +} +} +} diff --git a/ion/src/shared/dummy/archive.cpp b/ion/src/shared/dummy/archive.cpp new file mode 100644 index 00000000000..b1e092295b0 --- /dev/null +++ b/ion/src/shared/dummy/archive.cpp @@ -0,0 +1,93 @@ +#include "apps/global_preferences.h" +#include + +#include +#include + +namespace Ion { +namespace External { +namespace Archive { + +size_t numberOfFiles() { + File dummy{}; + size_t count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) {;} + + return count; +} + +int indexFromName(const char *name) { + File entry{}; + + for (int i = 0; fileAtIndex(i, entry); i++) { + if (entry.readable && strcmp(name, entry.name) == 0) { + return i; + } + } + + return -1; +} + +bool executableAtIndex(size_t index, File &entry) { + File dummy{}; + size_t count = 0; + size_t final_count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) { + if (dummy.isExecutable) { + if (final_count == index) { + entry.name = dummy.name; + entry.data = dummy.data; + entry.dataLength = dummy.dataLength; + entry.isExecutable = dummy.isExecutable; + entry.readable = dummy.readable; + return true; + } + final_count++; + } + } + return false; +} + +size_t numberOfExecutables() { + if (!GlobalPreferences::sharedGlobalPreferences()->externalAppShown()) { + return 0U; + } + File dummy{}; + size_t count = 0; + size_t final_count = 0; + + for (count = 0; fileAtIndex(count, dummy); count++) { + if (dummy.isExecutable) { + final_count++; + } + } + + return final_count; +} + + +bool fileAtIndex(size_t index, File &entry) { + if (index != 0) { + return false; + } + + entry.name = "Built-in"; + entry.data = nullptr; + entry.dataLength = 0; + entry.isExecutable = true; + entry.readable = true; + return true; +} + +extern "C" void extapp_main(void); + +uint32_t executeFile(const char * name, void * heap, const uint32_t heapSize) { + extapp_main(); + return 0; +} + +} +} +} diff --git a/apps/external/extapp_api.cpp b/ion/src/shared/extapp_api.cpp similarity index 95% rename from apps/external/extapp_api.cpp rename to ion/src/shared/extapp_api.cpp index 23254ab9146..f769b3ac11d 100644 --- a/apps/external/extapp_api.cpp +++ b/ion/src/shared/extapp_api.cpp @@ -4,10 +4,10 @@ #include #include #include -#include "archive.h" -#include "extapp_api.h" -#include "../apps_container.h" -#include "../global_preferences.h" +#include +#include +#include "apps/apps_container.h" +#include "apps/global_preferences.h" #ifdef DEVICE #include @@ -15,12 +15,6 @@ #include #endif -#include - -extern "C" { -#include -} - uint64_t extapp_millis() { return Ion::Timing::millis(); } @@ -128,11 +122,11 @@ int extapp_fileListWithExtension(const char ** filenames, int maxrecords, const // Don't read external files the exam mode is enabled if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) return j; if (storage == EXTAPP_FLASH_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) { - int n = External::Archive::numberOfFiles(); + int n = Ion::External::Archive::numberOfFiles(); for (int i = 0; i < n && j < maxrecords; i++) { - External::Archive::File entry; + Ion::External::Archive::File entry; // Filter extension - if (External::Archive::fileAtIndex(i, entry) && match(entry.name, extension)) { + if (Ion::External::Archive::fileAtIndex(i, entry) && match(entry.name, extension)) { filenames[j] = entry.name; ++j; } @@ -147,7 +141,7 @@ bool extapp_fileExists(const char * filename, int storage) { return true; } if (storage == EXTAPP_FLASH_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) { - return External::Archive::indexFromName(filename) >= 0; + return Ion::External::Archive::indexFromName(filename) >= 0; } return false; } @@ -178,10 +172,10 @@ const char * extapp_fileRead(const char * filename, size_t * len, int storage) { } } if (storage == EXTAPP_FLASH_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) { - int index = External::Archive::indexFromName(filename); + int index = Ion::External::Archive::indexFromName(filename); if (index >= 0) { - External::Archive::File entry; - External::Archive::fileAtIndex(index, entry); + Ion::External::Archive::File entry; + Ion::External::Archive::fileAtIndex(index, entry); if (len) { *len = entry.dataLength; } diff --git a/ion/src/simulator/Makefile b/ion/src/simulator/Makefile index caa9c1028a8..54b8b47fe1c 100644 --- a/ion/src/simulator/Makefile +++ b/ion/src/simulator/Makefile @@ -1,4 +1,5 @@ ion_src += $(addprefix ion/src/shared/dummy/, \ + archive.cpp \ backlight.cpp \ board.cpp \ battery.cpp \