Skip to content

Commit

Permalink
[Ports] Merge Nspire port and Fxcg improvements
Browse files Browse the repository at this point in the history
Close #327
  • Loading branch information
Yaya-Cout committed Jun 6, 2023
1 parent a124ed7 commit 6a85597
Show file tree
Hide file tree
Showing 47 changed files with 4,139 additions and 28 deletions.
1 change: 1 addition & 0 deletions apps/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ apps_src += $(addprefix apps/,\
exam_mode_configuration_official.cpp:+official \
exam_mode_configuration_non_official.cpp:-official \
global_preferences.cpp \
host_filemanager.cpp \
i18n.py \
lock_view.cpp \
main.cpp \
Expand Down
62 changes: 62 additions & 0 deletions apps/calculation/calculation_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@
#include "../exam_mode_configuration.h"
#include <assert.h>

#if defined _FXCG || defined NSPIRE_NEWLIB
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <apps/shared/global_context.h>

static KDCoordinate dummyHeight(::Calculation::Calculation * c, bool expanded) {
bool b;
Poincare::Layout l = c->createExactOutputLayout(&b);
if (!b) {
l=c->createInputLayout();
}
KDSize s = l.layoutSize();
const int bordersize = 10;
int h = s.height() + bordersize;
const int maxheight = 64;
if (h > maxheight) {
return maxheight;
}
return h;
}

extern void * last_calculation_history;
void * last_calculation_history = 0;
const char * retrieve_calc_history();

#endif

using namespace Poincare;
using namespace Shared;

Expand All @@ -21,10 +54,39 @@ CalculationStore::CalculationStore(char * buffer, int size) :
{
assert(m_buffer != nullptr);
assert(m_bufferSize > 0);
#if defined _FXCG || defined NSPIRE_NEWLIB
if (last_calculation_history == 0){
// Restore from scriptstore
const char * buf=retrieve_calc_history();
if (buf) {
Shared::GlobalContext globalContext;
char * ptr=(char *)buf;
for (;*ptr;) {
for (;*ptr;++ptr) {
if (*ptr=='\n') {
break;
}
}
char c = *ptr;
*ptr=0;
if (ptr > buf) {
push(buf,&globalContext, dummyHeight);
}
*ptr = c;
++ptr;
buf = ptr;
}
}
last_calculation_history = (void *) this;
}
#endif
}

// Returns an expiring pointer to the calculation of index i, and ignore the trash
ExpiringPointer<Calculation> CalculationStore::calculationAtIndex(int i) {
#if defined _FXCG || defined NSPIRE_NEWLIB
last_calculation_history = (void *) this;
#endif
if (m_trashIndex == -1 || i < m_trashIndex) {
return realCalculationAtIndex(i);
} else {
Expand Down
18 changes: 17 additions & 1 deletion apps/code/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <ion/unicode/utf8_helper.h>
#include <apps/apps_container.h>

#if defined _FXCG || defined NSPIRE_NEWLIB
extern "C" int calculator;
extern "C" const int prizm_heap_size;
extern "C" char prizm_heap[];
#endif

namespace Code {

I18n::Message App::Descriptor::name() {
Expand Down Expand Up @@ -150,7 +156,17 @@ bool App::textInputDidReceiveEvent(InputEventHandler * textInput, Ion::Events::E

void App::initPythonWithUser(const void * pythonUser) {
if (!m_pythonUser) {
MicroPython::init(m_pythonHeap, m_pythonHeap + k_pythonHeapSize);
#if defined _FXCG || defined NSPIRE_NEWLIB
if (calculator == 1) { // fxcg50
MicroPython::init( (void *) 0x8c200000, (void *)(0x8c200000+ 0x2e0000));
} else if (calculator >= 1 && calculator <=4 ) {
MicroPython::init( prizm_heap, prizm_heap+prizm_heap_size);
} else {
#endif
MicroPython::init(m_pythonHeap, m_pythonHeap + k_pythonHeapSize);
#if defined _FXCG || defined NSPIRE_NEWLIB
}
#endif
}
m_pythonUser = pythonUser;
}
Expand Down
9 changes: 9 additions & 0 deletions apps/external/app/sample.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#include <extapp_api.h>

#if defined _FXCG || defined NSPIRE_NEWLIB
// On the port, we use the Built-in file manager to import files.
void host_filemanager();
void extapp_main() {
host_filemanager();
}
#else
// Elsewhere, just draw a rectangle to test the extapp API.
void extapp_main() {
extapp_pushRectUniform(10, 10, LCD_WIDTH-20, LCD_HEIGHT-20, 0);
extapp_msleep(1000);
}
#endif
Loading

0 comments on commit 6a85597

Please sign in to comment.