[Ports] Merge Nspire port and Fxcg improvements

Close #327
This commit is contained in:
Yaya-Cout
2023-06-06 21:25:07 +02:00
parent a124ed72b5
commit 73450419bb
47 changed files with 4139 additions and 28 deletions

View File

@@ -22,8 +22,11 @@ public:
static constexpr char expExtension[] = "exp";
static constexpr char funcExtension[] = "func";
static constexpr char seqExtension[] = "seq";
#ifdef _FXCG
constexpr static size_t k_storageSize = 65500;
#else
constexpr static size_t k_storageSize = 60000;
#endif
static_assert(UINT16_MAX >= k_storageSize, "record_size_t not big enough");
constexpr static char k_dotChar = '.';
@@ -195,7 +198,7 @@ public:
class StorageHelper {
public:
static uint16_t unalignedShort(char * address) {
#if (defined __EMSCRIPTEN__) || (defined _FXCG)
#if (defined __EMSCRIPTEN__) || (defined _FXCG) || defined NSPIRE_NEWLIB
uint8_t f1 = *(address);
uint8_t f2 = *(address+1);
uint16_t f = (uint16_t)f1 + (((uint16_t)f2)<<8);
@@ -205,7 +208,7 @@ public:
#endif
}
static void writeUnalignedShort(uint16_t value, char * address) {
#if (defined __EMSCRIPTEN__) || (defined _FXCG)
#if (defined __EMSCRIPTEN__) || (defined _FXCG) || defined NSPIRE_NEWLIB
*((uint8_t *)address) = (uint8_t)(value & ((1 << 8) - 1));
*((uint8_t *)address+1) = (uint8_t)(value >> 8);
#else

View File

@@ -0,0 +1,2 @@
undefine sdl_src
undefine ion_simulator_sdl_src

View File

@@ -221,11 +221,11 @@ State scan() {
if (menuHeldFor > 30) {
Simulator::FXCGMenuHandler::openMenu();
dupdate();
// Wait until EXE is released
// Wait until EXE and MENU are released
do {
sleep_ms(10);
clearevents();
} while (keydown(KEY_EXE));
} while (keydown(KEY_EXE) || keydown(KEY_MENU));
}
} else {
menuHeldFor = 0;
@@ -259,4 +259,4 @@ namespace Keyboard {
}
}
}
}

View File

@@ -4,6 +4,8 @@
#include <gint/display-cg.h>
#include <gint/gint.h>
#include <gint/display.h>
#include <gint/keyboard.h>
#include <stddef.h>
#include <stdio.h>
@@ -13,15 +15,60 @@
#include <ion.h>
#include <ion/events.h>
#include "menuHandler.h"
using namespace Ion::Simulator::Main;
constexpr static const char * storage_name="nwstore.nws";
int save_state(const char * fname); // apps/home/controller.cpp
extern "C" {
int main() {
Ion::Simulator::Main::init();
ion_main(0, NULL);
Ion::Simulator::Main::quit();
extern const int prizm_heap_size;
const int prizm_heap_size = 192 * 1024;
__attribute__((aligned(4))) char prizm_heap[prizm_heap_size];
return 0;
}
CalculatorType calculator = CalculatorType::Unchecked;
int main() {
/* Allow the user to use memory past the 2 MB line on tested OS versions */
char const * os_version = (char const *)0x80020020;
if (!strncmp(os_version, "03.", 3) && os_version[3] <= '8'){ // 3.80 or earlier
char buf[256];
strncpy(buf,os_version,8);
buf[8]=0;
} else {
char buf1[10], buf[256];
// sprintf(buf,"%i",availram);
strncpy(buf1,os_version,8);
buf1[8]=0;
sprintf(buf,"OS %s not checked",buf1);
calculator = CalculatorType::Unchecked;
dclear(C_WHITE);
dtext(1,10,C_BLACK,buf);
dtext(1,27,C_BLACK,"F6: continue anyway");
dupdate();
int key = getkey().key;
if (key != KEY_F6){
Ion::Simulator::FXCGMenuHandler::openMenu();
}
}
bool is_emulator = *(volatile uint32_t *)0xff000044 == 0x00000000;
uint32_t stack;
__asm__("mov r15, %0" : "=r"(stack));
// Check if the calculator is a Prizm or an emulator
if (stack < 0x8c000000) {
calculator = is_emulator ? CalculatorType::Emulator : CalculatorType::Other;
} else {
calculator = CalculatorType::Physical; // 0x8c200000, size 0x300000 is free
}
Ion::Simulator::Main::init();
ion_main(0, nullptr);
Ion::Simulator::Main::quit();
return 0;
}
}
namespace Ion {
@@ -53,7 +100,7 @@ void quit() {
Ion::Simulator::Display::quit();
}
void EnableStatusArea(int opt) {
void EnableStatusArea(int /*opt*/) {
__asm__ __volatile__ (
".align 2 \n\t"
"mov.l 2f, r2 \n\t"
@@ -106,6 +153,9 @@ void worldSwitchHandler(void (*worldSwitchFunction)(), bool prepareVRAM) {
}
void runPowerOffSafe(void (*powerOffSafeFunction)(), bool prepareVRAM) {
gint_world_switch(GINT_CALL(save_state,storage_name));
gint_world_switch(GINT_CALL(worldSwitchHandler, powerOffSafeFunction, prepareVRAM));
}

View File

@@ -1,5 +1,6 @@
#ifndef ION_SIMULATOR_MAIN_H
#define ION_SIMULATOR_MAIN_H
#include <stdint.h>
namespace Ion {
namespace Simulator {
@@ -13,6 +14,14 @@ void refresh();
void runPowerOffSafe(void (*powerOffSafeFunction)(), bool prepareVRAM);
enum class CalculatorType : uint8_t {
Unchecked = (uint8_t)-1,
Unknown = 0,
Physical = 1,
Emulator = 2,
Other = 3
};
}
}
}

View File

@@ -0,0 +1,53 @@
ion_src += $(addprefix ion/src/simulator/nspire/, \
main.cpp \
clipboard.cpp \
display.cpp \
framebuffer.cpp \
telemetry_init.cpp \
keyboard.cpp \
events_keyboard.cpp \
events.cpp \
timing.cpp \
console.cpp \
backlight.cpp \
power.cpp \
k_csdk.c \
)
liba_src += $(addprefix liba/src/, \
strlcat.c \
strlcpy.c \
)
ion_src += ion/src/shared/collect_registers.cpp
sdl_simu_needs_to_be_removed += $(addprefix ion/src/simulator/shared/, \
main.cpp \
clipboard.cpp \
display.cpp \
framebuffer.cpp \
keyboard.cpp \
events_keyboard.cpp \
events_platform.cpp \
events.cpp \
layout.cpp \
actions.cpp \
window.cpp \
timing.cpp \
console.cpp \
)
sdl_simu_needs_to_be_removed += $(addprefix ion/src/shared/dummy/, \
backlight.cpp \
power.cpp \
)
# Remove the dummy diaplay (re-implemented) and the SDL simulator stuff.
ion_src := $(filter-out $(sdl_simu_needs_to_be_removed),$(ion_src))
SFLAGS := $(filter-out -Iion/src/simulator/external/sdl/include,$(SFLAGS))
SFLAGS += -marm -DNSPIRE_NEWLIB -I/Users/parisse/Ndless-r2015/ndless-sdk/ndless/include -I/Users/parisse/Ndless-r2015/ndless-sdk/toolchain/install/include -fno-strict-aliasing -I. -I.. -fno-exceptions -ffreestanding -nostdlib -fstrict-volatile-bitfields -g -Os
LDFLAGS += -Wl,--nspireio,--gc-sections -L/Users/parisse/Ndless-r2015/ndless-sdk/lib -L/Users/parisse/Ndless-r2015/ndless-sdk/toolchain/install/lib -nostdlib -lc -lm -lstdc++ -lgcc

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,24 @@
#include <ion/backlight.h>
namespace Ion {
namespace Backlight {
uint8_t brightness() {
return 128;
}
void setBrightness(uint8_t b) {
}
void init() {
}
bool isInitialized() {
return true;
}
void shutdown() {
}
}
}

View File

@@ -0,0 +1,15 @@
#include <ion/clipboard.h>
#include <ion.h>
#include <string.h>
namespace Ion {
namespace Clipboard {
void write(const char * text) {}
const char * read() {
return nullptr;
}
}
}

View File

@@ -0,0 +1,24 @@
#include <ion/console.h>
#include "main.h"
#include <kandinsky/ion_context.h>
#include <stdio.h>
namespace Ion {
namespace Console {
char readChar() {
return 0;
}
void writeChar(char c) {
// fxlibc conflicts with this
#undef putchar
KDIonContext::putchar(c);
}
bool transmissionDone() {
return true;
}
}
}

View File

@@ -0,0 +1,47 @@
#include "display.h"
#include "framebuffer.h"
#include <kandinsky/color.h>
#include <stdint.h>
#include <ion/display.h>
#include <string.h>
#include <stdio.h>
#include "k_csdk.h"
#include <libndls.h>
namespace Ion {
namespace Simulator {
namespace Display {
void init() {
}
void quit() {
}
void draw() {
// copy framebuffer
const short unsigned int * ptr = (const short unsigned int *) Ion::Simulator::Framebuffer::address();
Gc * gcptr = get_gc();
for (int j = 0; j < LCD_HEIGHT_PX; ++j) {
for (int i = 0; i < LCD_WIDTH_PX;){
int c = *ptr;
int k = 1;
for (; k+i < LCD_WIDTH_PX; ++k) {
if (ptr[k]!=c) {
break;
}
}
gui_gc_setColor(*gcptr,c_rgb565to888(c));
gui_gc_drawRect(*gcptr,i,j,k-1,0);
ptr += k;
i += k;
}
}
sync_screen();
}
}
}
}

View File

@@ -0,0 +1,19 @@
#ifndef ION_SIMULATOR_DISPLAY_H
#define ION_SIMULATOR_DISPLAY_H
#include <kandinsky.h>
namespace Ion {
namespace Simulator {
namespace Display {
void init();
void quit();
void draw();
}
}
}
#endif

View File

@@ -0,0 +1,23 @@
#include "events.h"
#include <ion/events.h>
namespace Ion {
namespace Events {
void didPressNewKey() {
}
char * sharedExternalTextBuffer() {
static char buffer[sharedExternalTextBufferSize];
return buffer;
}
const char * Event::text() const {
if (*this == ExternalText) {
return const_cast<const char *>(sharedExternalTextBuffer());
}
return defaultText();
}
}
}

View File

@@ -0,0 +1,24 @@
#ifndef ION_SIMULATOR_EVENTS_H
#define ION_SIMULATOR_EVENTS_H
#include <ion/events.h>
namespace Ion {
namespace Simulator {
namespace Events {
void dumpEventCount(int i);
void logAfter(int numberOfEvents);
}
}
namespace Events {
static constexpr int sharedExternalTextBufferSize = 2;
char * sharedExternalTextBuffer();
}
}
#endif

View File

@@ -0,0 +1,15 @@
#include <ion/events.h>
namespace Ion {
namespace Events {
Event getPlatformEvent() {
Event result = None;
return result;
}
}
}

View File

@@ -0,0 +1,53 @@
#include "framebuffer.h"
#include <ion/display.h>
#include "main.h"
#include <stdio.h>
static KDColor sPixels[Ion::Display::Width * Ion::Display::Height];
static_assert(sizeof(KDColor) == sizeof(uint16_t), "KDColor is not 16 bits");
static bool sFrameBufferActive = true;
namespace Ion {
namespace Display {
static KDFrameBuffer sFrameBuffer = KDFrameBuffer(sPixels, KDSize(Ion::Display::Width, Ion::Display::Height));
void pushRect(KDRect r, const KDColor * pixels) {
if (sFrameBufferActive) {
Simulator::Main::setNeedsRefresh();
sFrameBuffer.pushRect(r, pixels);
}
}
void pushRectUniform(KDRect r, KDColor c) {
if (sFrameBufferActive) {
Simulator::Main::setNeedsRefresh();
sFrameBuffer.pushRectUniform(r, c);
}
}
void pullRect(KDRect r, KDColor * pixels) {
if (sFrameBufferActive) {
sFrameBuffer.pullRect(r, pixels);
}
}
}
}
namespace Ion {
namespace Simulator {
namespace Framebuffer {
const KDColor * address() {
return sPixels;
}
void setActive(bool enabled) {
sFrameBufferActive = enabled;
}
}
}
}

View File

@@ -0,0 +1,17 @@
#ifndef ION_SIMULATOR_FRAMEBUFFER_H
#define ION_SIMULATOR_FRAMEBUFFER_H
#include <kandinsky.h>
namespace Ion {
namespace Simulator {
namespace Framebuffer {
const KDColor * address();
void setActive(bool enabled);
}
}
}
#endif

View File

@@ -0,0 +1,61 @@
#ifndef GINT_H
#define GINT_H
#include "k_defs.h"
#define KEY_DOWN KEY_CTRL_DOWN
#define KEY_LEFT KEY_CTRL_LEFT
#define KEY_RIGHT KEY_CTRL_RIGHT
#define KEY_UP KEY_CTRL_UP
#define KEY_EXIT KEY_CTRL_EXIT
#define KEY_MENU KEY_CTRL_MENU
#define KEY_SHIFT KEY_CTRL_SHIFT
#define KEY_ALPHA KEY_CTRL_ALPHA
#define KEY_XOT KEY_CTRL_XTT
#define KEY_VARS KEY_CTRL_VARS
#define KEY_OPTN KEY_CTRL_OPTN
#define KEY_DEL KEY_CTRL_DEL
#define KEY_OPTN KEY_CTRL_OPTN
#define KEY_DEL KEY_CTRL_DEL
#define KEY_LN KEY_CHAR_LN
#define KEY_LOG KEY_CHAR_LOG
#define KEY_0 KEY_CHAR_0
#define KEY_COMMA KEY_CHAR_COMMA
#define KEY_SIN KEY_CHAR_SIN
#define KEY_COS KEY_CHAR_COS
#define KEY_TAN KEY_CHAR_TAN
#define KEY_EXP KEY_CHAR_EXP
#define KEY_SQUARE KEY_CHAR_SQUARE
#define KEY_7 KEY_CHAR_7
#define KEY_8 KEY_CHAR_8
#define KEY_9 KEY_CHAR_9
#define KEY_LEFTP KEY_CHAR_LPAR
#define KEY_RIGHTP KEY_CHAR_RPAR
#define KEY_4 KEY_CHAR_4
#define KEY_5 KEY_CHAR_5
#define KEY_6 KEY_CHAR_6
#define KEY_MUL KEY_CHAR_MULT
#define KEY_DIV KEY_CHAR_DIV
#define KEY_FRAC KEY_CHAR_FRAC
#define KEY_1 KEY_CHAR_1
#define KEY_2 KEY_CHAR_2
#define KEY_3 KEY_CHAR_3
#define KEY_ADD KEY_CHAR_PLUS
#define KEY_PLUS KEY_CHAR_PLUS
#define KEY_SUB KEY_CHAR_MINUS
#define KEY_MINUS KEY_CHAR_MINUS
#define KEY_NEG KEY_CHAR_PMINUS
#define KEY_0 KEY_CHAR_0
#define KEY_DOT KEY_CHAR_DP
#define KEY_EXE KEY_CTRL_EXE
#define KEY_ACON KEY_CTRL_AC
#define KEY_POWER KEY_CHAR_POW
#define KEY_STORE KEY_CHAR_STORE
#define KEY_F1 KEY_CTRL_F1
#define KEY_F2 KEY_CTRL_F2
#define KEY_F3 KEY_CTRL_F3
#define KEY_F4 KEY_CTRL_F4
#define KEY_F5 KEY_CTRL_F5
#define KEY_F6 KEY_CTRL_F6
#define KEY_FD KEY_CTRL_FD
#define KEY_ARROW KEY_CTRL_SD
#define KEY_TIMES KEY_CHAR_MULT
#endif // GINT_H

1556
ion/src/simulator/nspire/k_csdk.c Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,255 @@
/* C header for Khicas interface with calculator OS */
#ifndef K_CSDK_H
#define K_CSDK_H
#include "gint.h"
#include "k_defs.h"
// Defaults parameters do not work if included from C
#define SDK_BLACK 0
#define SDK_WHITE 65535
// C58 is the pixel y coordinate where soft keys menus legends are written
#define C24 24
#define C18 18
#define C10 18
#define C6 6
#define COLOR_SELECTED ((15<<11)|(15<<5)|15)
#if defined FX
#define LCD_WIDTH_PX 128
#define LCD_HEIGHT_PX 64
#elseif defined FXCG
#define LCD_WIDTH_PX 384
#define LCD_HEIGHT_PX 128
#else
#define LCD_WIDTH_PX 320
#define LCD_HEIGHT_PX 240
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include "stdio.h"
#ifdef TICE
#define C58 214
#include "dbg.h"
#define max_heap_size 60
#define COLOR_WHITE SDK_WHITE
#define TEXT_COLOR_WHITE SDK_WHITE
#define COLOR_BLACK SDK_BLACK
#define COLOR_ORANGE ((31<<11)|(7<<5)|31)
#define COLOR_CYAN ((63<<5)|31)
#define COLOR_GREEN (63<<5)
#define TEXT_COLOR_GREEN (63<<5)
#define COLOR_MAGENTA ((31<<11)|31)
#define COLOR_RED (31<<11)
#define TEXT_COLOR_RED (31<<11)
#define COLOR_BLUE 31
#define TEXT_COLOR_BLACK 0
#define TEXT_COLOR_PURPLE ((15<<11)| 24)
#define TEXT_COLOR_BLUE 3
#define COLOR_BROWN ((15<<11)|(15<<5))
#define TEXT_MODE_NORMAL 0
#define TEXT_MODE_INVERT 1
#define MINI_REV 4
#define false 0
#define true 1
void sdk_init(void);
void sdk_end(void);
void clear_screen(void);
#else //TICE
#ifdef NSPIRE_NEWLIB
void sdk_init(void);
void sdk_end(void);
#else
inline void sdk_init(void){}
inline void sdk_end(void){}
#endif
#endif
extern short exam_mode,nspire_exam_mode;
// nspire_exam_mode==0 normal mode
// ==1 led are blinking
// ==2 OS exam mode is on but led are not blinking
// Set the Nspire in normal exam mode at home, transfer ndless and khicas
// activate khicas: will detect led blinking (mode ==1)
// prepare exam mode with Khicas menu item (clear led, mode==2),
// in that mode menu menu will not leave KhiCAS anymore but
// will clean data and do a hardware reset (launch again exam mode and leds)
extern unsigned exam_start;
extern int exam_duration;
int ext_main();
int waitforvblank();
int back_key_pressed() ;
// next 3 functions may be void if not inside a window class hierarchy
void os_show_graph(); // show graph inside Python shell (Numworks), not used
void os_hide_graph(); // hide graph, not used anymore
void os_redraw(); // force redraw of window class hierarchy
#ifdef NUMWORKS
#define max_heap_size 96
void raisememerr();
extern unsigned _heap_size;
extern void * _heap_ptr;
extern void * _heap_base;
int inexammode();
int extapp_restorebackup(int mode);
void numworks_set_pixel(int x,int y,int c);
int numworks_get_pixel(int x,int y);
void numworks_fill_rect(int x,int y,int w,int h,int c);
#ifdef __cplusplus
int numworks_draw_string(int x,int y,int c,int bg,const char * s,int fake=false);
int numworks_draw_string_small(int x,int y,int c,int bg,const char * s,int fake=0);
#else
int numworks_draw_string(int x,int y,int c,int bg,const char * s,int fake);
int numworks_draw_string_small(int x,int y,int c,int bg,const char * s,int fake);
#endif
void numworks_show_graph();
void numworks_hide_graph();
void numworks_redraw();
void numworks_wait_1ms(int ms);
// access to Numworks OS, defined in port.cpp (or modkandinsky.cpp)
inline void os_set_pixel(int x,int y,int c){
numworks_set_pixel(x,y,c);
}
inline int os_get_pixel(int x,int y){
return numworks_get_pixel(x,y);
}
inline void os_fill_rect(int x,int y,int w,int h,int c){
numworks_fill_rect(x,y,w,h,c);
}
inline int os_draw_string(int x,int y,int c,int bg,const char * s,int fake){
return numworks_draw_string(x,y,c,bg,s,fake);
}
inline int os_draw_string_small(int x,int y,int c,int bg,const char * s,int fake){
return numworks_draw_string_small(x,y,c,bg,s,fake);
}
inline void os_shaw_graph(){ return numworks_show_graph(); }
inline void os_hide_graph(){ return numworks_hide_graph(); }
inline void os_redraw(){ return numworks_redraw(); }
inline void os_wait_1ms(int ms) { numworks_wait_1ms(ms); }
int getkey_raw(int allow_suspend); // Numworks scan code
inline void sync_screen(){}
#endif // NUMWORKS
void os_wait_1ms(int ms);
int os_set_angle_unit(int mode);
int os_get_angle_unit();
double millis(); //extern int time_shift;
void get_time(int *h,int *m);
void set_time(int h,int m);
int file_exists(const char * filename);
int erase_file(const char * filename);
const char * read_file(const char * filename);
#ifdef __cplusplus
int write_file(const char * filename,const char * s,int len=0);
#else
int write_file(const char * filename,const char * s,int len);
#endif
#define MAX_NUMBER_OF_FILENAMES 255
int os_file_browser(const char ** filenames,int maxrecords,const char * extension,int storage);
void sync_screen();
void os_set_pixel(int x,int y,int c);
void os_fill_rect(int x,int y,int w,int h,int c);
inline void drawRectangle(int x,int y,int w,int h,int c){
if (w>=0 && h>=0)
os_fill_rect(x,y,w,h,c);
}
int os_get_pixel(int x,int y);
/* returns new x position */
#ifdef __cplusplus
int os_draw_string(int x,int y,int c,int bg,const char * s,int fake=0);
#else
int os_draw_string(int x,int y,int c,int bg,const char * s,int fake);
#endif
inline int os_draw_string_(int x,int y,const char * s){ return os_draw_string(x,y,SDK_BLACK,SDK_WHITE,s,0);}
#ifdef __cplusplus
int os_draw_string_small(int x,int y,int c,int bg,const char * s,int fake=0);
#else
int os_draw_string_small(int x,int y,int c,int bg,const char * s,int fake);
#endif
inline int os_draw_string_small_(int x,int y,const char * s){ return os_draw_string_small(x,y,SDK_BLACK,SDK_WHITE,s,0);}
#ifdef __cplusplus
#ifdef NUMWORKS
inline int os_draw_string_medium(int x,int y,int c,int bg,const char * s,int fake=0){ return os_draw_string_small(x,y,c,bg,s,fake);}
#else
int os_draw_string_medium(int x,int y,int c,int bg,const char * s,int fake=0);
#endif
#else
#ifdef NUMWORKS
inline int os_draw_string_medium(int x,int y,int c,int bg,const char * s,int fake){ return os_draw_string_small(x,y,c,bg,s,fake);}
#else
int os_draw_string_medium(int x,int y,int c,int bg,const char * s,int fake);
#endif
#endif
inline int os_draw_string_medium_(int x,int y,const char * s){ return os_draw_string_medium(x,y,SDK_BLACK,SDK_WHITE,s,0);}
inline void Printmini(int x,int y,const char * s,int i){
// dbg_printf("Printmini %i %i %s %i\n",x,y,s,i);
#if defined FX || defined FXCG
os_draw_string_small(x,y,i?0xffff:0,i?0:0xffff,s,false);
#else
os_draw_string_small(x,y,SDK_BLACK,i?COLOR_SELECTED:SDK_WHITE,s,false);
#endif
}
inline void Printxy(int x,int y,const char * s,int i){ os_draw_string_medium(x,y,0,i?COLOR_SELECTED:0xffff,s,false);}
inline void PrintXY(int x,int y,const char * s,int i){ Printxy(3*x,3*y,s,i);}
void GetKey(int * key);
int getkey(int allow_suspend); // transformed
inline void ck_getkey(int *key){ GetKey(key);}
void enable_back_interrupt();
inline void set_abort(){ enable_back_interrupt(); }
void disable_back_interrupt();
inline void clear_abort(){ disable_back_interrupt(); }
int isalphaactive();
int alphawasactive(int * key);
void lock_alpha();
void reset_kbd();
int handle_f5();
void statuslinemsg(const char * msg);
#ifdef __cplusplus
void statusline(int mode=0);
#else
void statusline(int mode);
#endif
void statusflags(void);
#ifdef NUMWORKS
inline int iskeydown(int key){ return getkey(key | 0x80000000); }
#else
int iskeydown(int key);
#endif
#if defined NSPIRE || defined NSPIRE_NEWLIB
extern int nspire_shift,nspire_ctrl;
double loopsleep(int ms);
#include <libndls.h>
Gc * get_gc();
int c_rgb565to888(int c);
int nspire_scan(int * adaptive_cursor_state);
#define max_heap_size 60
extern int nspireemu;
extern char nspire_filebuf[NSPIRE_FILEBUFFER];
extern int on_key_enabled;
void get_hms(int *h,int *m,int *s);
void reset_gc();
#endif
extern int (*shutdown)(); // function called after 2 hours of idle
extern short int shutdown_state;
inline void Bdisp_PutDisp_DD(void){ sync_screen(); }
inline void sprint_int(char * c,int i){ sprintf(c,"%d",i);}
inline void sprint_double(char * c,double d){ sprintf(c,"%.4g",d);}
int GetSetupSetting(int k);
inline int Setup_GetEntry(int k){ return GetSetupSetting(k); }
void SetQuitHandler( void (*f)(void));
#define RTC_GetTicks millis
#ifndef TICE
inline void clear_screen(void){os_fill_rect(0,0,LCD_WIDTH_PX,LCD_HEIGHT_PX,SDK_WHITE);}
#endif
inline void Bdisp_AllClr_VRAM(void){ clear_screen(); }
#ifdef __cplusplus
}
#endif
#endif // K_CSDK_H

211
ion/src/simulator/nspire/k_defs.h Executable file
View File

@@ -0,0 +1,211 @@
#ifndef K_DEFS_H
#define K_DEFS_H
#define NSPIRE_FILEBUFFER 512*1024
// 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_SHIFTMINUS 0xdc
#define KEY_CHAR_CROCHETS 0xdd
#define KEY_CHAR_ACCOLADES 0xde
#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_FORMAT 30203
#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 30915
#define KEY_CTRL_F8 30916
#define KEY_CTRL_F9 30917
#define KEY_CTRL_F10 30918
#define KEY_CTRL_F11 30919
#define KEY_CTRL_F12 30920
#define KEY_CTRL_F13 30921
#define KEY_CTRL_F14 30922
#define KEY_CTRL_F15 30923
#define KEY_CTRL_F16 30924
#define KEY_CTRL_F17 30925
#define KEY_CTRL_F18 30926
#define KEY_CTRL_F19 30927
#define KEY_CTRL_F20 30928
#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_UP_CTRL 31060
#define KEY_DOWN_CTRL 31061
#define KEY_LEFT_CTRL 31062
#define KEY_RIGHT_CTRL 31063
#define KEY_CALCULATOR 31064
#define KEY_SAVE 31065
#define KEY_LOAD 31066
#define KEY_CTRL_A 31001
#define KEY_CTRL_D 31004
#define KEY_CTRL_E 31005
#define KEY_CTRL_H 31008 // help?
#define KEY_CTRL_M 31011 // doc menu
#define KEY_CTRL_N 31012
#define KEY_CTRL_R 31018
#define KEY_CTRL_S 31019
#define KEY_CTRL_T 31020
#define KEY_EQW_TEMPLATE 31100
#define KEY_AFFECT 31101
#define KEY_FLAG 31102
#define KEY_BOOK 31103
//#define KEY_CTRL_APPS 31104
#define KEY_CTRL_SYMB 31105
//#define KEY_CTRL_NUM 31106
//#define KEY_CTRL_PLOT 31107
#define KEY_SELECT_LEFT 31200
#define KEY_SELECT_UP 31201
#define KEY_SELECT_DOWN 31202
#define KEY_SELECT_RIGHT 31203
#define KEY_SHUTDOWN 32109
#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
#define KEY_CTRL_SD 39990
#endif

View File

@@ -0,0 +1,276 @@
#include <stdlib.h>
#include <unistd.h>
#include <ion/keyboard.h>
#include <ion/events.h>
#include <ion/power.h>
#include "layout_keyboard.h"
#include "main.h"
#include "k_csdk.h"
using namespace Ion::Keyboard;
class KeyPair {
public:
constexpr KeyPair(Key key, bool numworksShift, bool numworksAlpha, int gintKey, bool gintShift, bool gintAlpha, bool ignoreShiftAlpha = false) :
m_key(key),
m_numworksShift(numworksShift),
m_numworksAlpha(numworksAlpha),
m_gintKey(gintKey),
m_gintShift(gintShift),
m_gintAlpha(gintAlpha),
m_ignoreShiftAlpha(ignoreShiftAlpha)
{}
Key key() const { return m_key; }
bool numworksShift() const { return m_numworksShift; }
bool numworksAlpha() const { return m_numworksAlpha; }
int gintKey() const { return m_gintKey; }
bool gintShift() const { return m_gintShift; }
bool gintAlpha() const { return m_gintAlpha; }
bool ignoreShiftAlpha() const { return m_ignoreShiftAlpha; }
private:
Key m_key;
bool m_numworksShift;
bool m_numworksAlpha;
int m_gintKey;
bool m_gintShift;
bool m_gintAlpha;
bool m_ignoreShiftAlpha;
};
constexpr static KeyPair sKeyPairs[] = {
KeyPair(Key::Down, false, false, KEY_DOWN, false, false, true),
KeyPair(Key::Left, false, false, KEY_LEFT, false, false, true),
KeyPair(Key::Right, false, false, KEY_RIGHT, false, false, true),
KeyPair(Key::Up, false, false, KEY_UP, false, false, true),
KeyPair(Key::Back, false, false, KEY_EXIT, false, false),
KeyPair(Key::Home, false, false, KEY_MENU, false, false),
KeyPair(Key::Shift, false, false, KEY_SHIFT, false, false, true),
KeyPair(Key::Alpha, false, false, KEY_ALPHA, false, false, true),
KeyPair(Key::XNT, false, false, KEY_XOT, false, false),
KeyPair(Key::Var, false, false, KEY_VARS, false, false),
KeyPair(Key::Toolbox, false, false, KEY_CTRL_CATALOG, false, false),
KeyPair(Key::Backspace, false, false, KEY_DEL, false, false),
KeyPair(Key::Exp, false, false, KEY_CHAR_EXPN, false, false),
KeyPair(Key::Ln, false, false, KEY_LN, false, false),
KeyPair(Key::Log, false, false, KEY_LOG, false, false),
KeyPair(Key::Imaginary, false, false, KEY_CHAR_IMGNRY, false, false),
KeyPair(Key::Comma, false, false, KEY_COMMA, false, false),
KeyPair(Key::Power, false, false, '^', false, false),
KeyPair(Key::Sine, false, false, KEY_SIN, false, false),
KeyPair(Key::Cosine, false, false, KEY_COS, false, false),
KeyPair(Key::Tangent, false, false, KEY_TAN, false, false),
KeyPair(Key::Pi, false, false, KEY_CHAR_PI, false, false),
KeyPair(Key::Sqrt, false, false, KEY_CHAR_ROOT, false, false),
KeyPair(Key::Square, false, false, KEY_SQUARE, false, false),
KeyPair(Key::Seven, false, false, KEY_7, false, false),
KeyPair(Key::Eight, false, false, KEY_8, false, false),
KeyPair(Key::Nine, false, false, KEY_9, false, false),
KeyPair(Key::LeftParenthesis, false, false, KEY_LEFTP, false, false),
KeyPair(Key::RightParenthesis, false, false, KEY_RIGHTP, false, false),
KeyPair(Key::Four, false, false, KEY_4, false, false),
KeyPair(Key::Five, false, false, KEY_5, false, false),
KeyPair(Key::Six, false, false, KEY_6, false, false),
KeyPair(Key::Multiplication, false, false, KEY_MUL, false, false),
KeyPair(Key::Division, false, false, KEY_DIV, false, false),
KeyPair(Key::Division, false, false, KEY_FRAC, false, false),
KeyPair(Key::One, false, false, KEY_1, false, false),
KeyPair(Key::Two, false, false, KEY_2, false, false),
KeyPair(Key::Three, false, false, KEY_3, false, false),
KeyPair(Key::Plus, false, false, KEY_ADD, false, false),
KeyPair(Key::Minus, false, false, KEY_SUB, false, false),
KeyPair(Key::Zero, false, false, KEY_0, false, false),
KeyPair(Key::Dot, false, false, KEY_DOT, false, false),
KeyPair(Key::EE, false, false, KEY_CHAR_EXP, false, false),
KeyPair(Key::Ans, false, false, KEY_CHAR_ANS, true, false),
KeyPair(Key::EXE, false, false, KEY_EXE, false, false, true),
KeyPair(Key::OnOff, false, false, KEY_ACON, false, false),
// Cut
KeyPair(Key::XNT, true, false, KEY_CTRL_CUT, false, false),
// Copy
KeyPair(Key::Var, true, false, KEY_CTRL_CLIP, false, false),
// Paste
KeyPair(Key::Toolbox, true, false, KEY_CTRL_PASTE, false, false),
// Clear
KeyPair(Key::Backspace, true, false, KEY_ACON, false, false),
// [
KeyPair(Key::Exp, true, false, KEY_CHAR_CROCHETS, false, false),
// ]
KeyPair(Key::Ln, true, false, KEY_CTRL_F13, false, false),
// {
KeyPair(Key::Log, true, false, KEY_CHAR_ACCOLADES, false, false),
// }
KeyPair(Key::Imaginary, true, false, KEY_CTRL_F14, false, false),
// _
KeyPair(Key::Comma, true, false, KEY_NEG, false, false),
// ->
KeyPair(Key::Power, true, false, KEY_STORE, false, true),
// asin
KeyPair(Key::Sine, true, false, KEY_CHAR_ASIN, true, false),
// acos
KeyPair(Key::Cosine, true, false, KEY_CHAR_ACOS, true, false),
// atan
KeyPair(Key::Tangent, true, false, KEY_CHAR_ATAN, true, false),
// =
KeyPair(Key::Pi, true, false, KEY_CHAR_EQUAL, false, false),
// <
KeyPair(Key::Sqrt, true, false, '<', false, false),
// >
KeyPair(Key::Square, true, false, '>', false, false),
// :
KeyPair(Key::XNT, false, true, ':', false, false),
// ;
KeyPair(Key::Var, false, true, ';', false, false),
// "
KeyPair(Key::Toolbox, false, true, KEY_CHAR_DQUATE, false, true),
// %
KeyPair(Key::Backspace, false, true, '%', false, false),
// A
KeyPair(Key::Exp, false, true, 'a', false, false),
// B
KeyPair(Key::Ln, false, true, 'b', false, false),
// C
KeyPair(Key::Log, false, true, 'c', false, false),
// D
KeyPair(Key::Imaginary, false, true, 'd', false, false),
// E
KeyPair(Key::Comma, false, true, 'e', false, false),
// F
KeyPair(Key::Power, false, true, 'f', false, false),
// G
KeyPair(Key::Sine, false, true, 'g', false, false),
// H
KeyPair(Key::Cosine, false, true, 'h', false, false),
// I
KeyPair(Key::Tangent, false, true, 'i', false, false),
// J
KeyPair(Key::Pi, false, true, 'j', false, false),
// K
KeyPair(Key::Sqrt, false, true,'k', false, false),
// L
KeyPair(Key::Square, false, true, 'l', false, false),
// M
KeyPair(Key::Seven, false, true, 'm', false, false),
// N
KeyPair(Key::Eight, false, true, 'n', false, false),
// O
KeyPair(Key::Nine, false, true, 'o', false, false),
// P
KeyPair(Key::LeftParenthesis, false, true, 'p', false, false),
// Q
KeyPair(Key::RightParenthesis, false, true, 'q', false, false),
// R
KeyPair(Key::Four, false, true, 'r', false, false),
// S
KeyPair(Key::Five, false, true, 's', false, false),
// T
KeyPair(Key::Six, false, true, 't', false, false),
// U
KeyPair(Key::Multiplication, false, true, 'u', false, false),
// V
KeyPair(Key::Division, false, true, 'v', false, false),
// W
KeyPair(Key::One, false, true, 'w', false, false),
// X
KeyPair(Key::Two, false, true, 'x', false, false),
// Y
KeyPair(Key::Three, false, true, 'y', false, false),
// Z
KeyPair(Key::Plus, false, true, 'z', false, false),
// Space
KeyPair(Key::Minus, false, true, KEY_CHAR_SPACE, false, false),
// ?
KeyPair(Key::Zero, false, true, KEY_F6, true, false),
// !
KeyPair(Key::Dot, false, true, KEY_F6, false, false),
// Brightness control shortcut in Upsilon
KeyPair(Key::Plus, true, false, KEY_ADD, false, true),
KeyPair(Key::Minus, true, false, KEY_SUB, false, true),
};
constexpr int sNumberOfKeyPairs = sizeof(sKeyPairs)/sizeof(KeyPair);
namespace Ion {
namespace Keyboard {
int menuHeldFor = 0;
State scan() {
State state = 0;
// Grab this opportunity to refresh the display if needed
Simulator::Main::refresh();
if (!any_key_pressed())
return state;
if (isKeyPressed(KEY_NSPIRE_HOME)){
state.setKey(Key::Home); return state;
}
if (isKeyPressed(KEY_NSPIRE_ENTER)){
state.setKey(Key::EXE);
return state;
}
if (isKeyPressed(KEY_NSPIRE_LEFT)){
state.setKey(Key::Left);
return state;
}
if (isKeyPressed(KEY_NSPIRE_RIGHT)){
state.setKey(Key::Right);
return state;
}
if (isKeyPressed(KEY_NSPIRE_UP)){
state.setKey(Key::Up);
return state;
}
if (isKeyPressed(KEY_NSPIRE_DOWN)){
state.setKey(Key::Down);
return state;
}
int shiftstate;
int scancode=nspire_scan(&shiftstate);
if (scancode==0) {
return state;
}
switch (scancode){
case -2: case -1:
return state;
case KEY_CTRL_EXIT:
state.setKey(Key::Back);
return state;
case KEY_CTRL_EXE:
state.setKey(Key::EXE);
return state;
case KEY_CTRL_MENU:
state.setKey(Key::Home);
return state;
}
nspire_ctrl=nspire_shift=0;
for (int i = 0; i < sNumberOfKeyPairs; i++) {
const KeyPair & keyPair = sKeyPairs[i];
if (scancode==keyPair.gintKey()) {
state.setSimulatedShift(keyPair.numworksShift() ? ModSimState::ForceOn : ModSimState::ForceOff);
state.setSimulatedAlpha(keyPair.numworksAlpha() ? ModSimState::ForceOn : ModSimState::ForceOff);
state.setKey(keyPair.key());
return state;
}
}
return state;
}
}
}
namespace Ion {
namespace Simulator {
namespace Keyboard {
}
}
}

View File

@@ -0,0 +1,15 @@
#ifndef ION_SIMULATOR_KEYBOARD_H
#define ION_SIMULATOR_KEYBOARD_H
#include <ion/keyboard.h>
// #include <libndls.h>
namespace Ion {
namespace Simulator {
namespace Keyboard {
}
}
}
#endif

View File

@@ -0,0 +1,97 @@
#include "main.h"
#include "display.h"
#include "platform.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <ion.h>
#include <ion/events.h>
#include "k_csdk.h"
static const char * storage_name="nwstore.nws";
int save_state(const char * fname); // apps/home/controller.cpp
extern "C" {
extern const int prizm_heap_size;
const int prizm_heap_size=1024*1024;
__attribute__((aligned(4))) char prizm_heap[prizm_heap_size];
int calculator=4; // -1 means OS not checked, 0 unknown, 1 cg50 or 90, 2 emu 50 or 90, 3 other
int main() {
sdk_init();
Ion::Simulator::Main::init();
ion_main(0, NULL);
Ion::Simulator::Main::quit();
sdk_end();
return 0;
}
}
namespace Ion {
namespace Simulator {
namespace Main {
static bool sNeedsRefresh = false;
void init() {
Ion::Simulator::Display::init();
setNeedsRefresh();
}
void setNeedsRefresh() {
sNeedsRefresh = true;
}
void refresh() {
if (!sNeedsRefresh) {
return;
}
Display::draw();
sNeedsRefresh = false;
}
void quit() {
Ion::Simulator::Display::quit();
}
void runPowerOffSafe(void (*powerOffSafeFunction)(), bool prepareVRAM) {
// somewhat OFF by setting LCD to 0
unsigned NSPIRE_CONTRAST_ADDR=is_cx2?0x90130014:0x900f0020;
unsigned oldval=*(volatile unsigned *)NSPIRE_CONTRAST_ADDR,oldval2;
if (is_cx2){
oldval2=*(volatile unsigned *) (NSPIRE_CONTRAST_ADDR+4);
*(volatile unsigned *) (NSPIRE_CONTRAST_ADDR+4)=0xffff;
}
*(volatile unsigned *)NSPIRE_CONTRAST_ADDR=is_cx2?0xffff:0x100;
static volatile uint32_t *lcd_controller = (volatile uint32_t*) 0xC0000000;
lcd_controller[6] &= ~(0b1 << 11);
loopsleep(20);
lcd_controller[6] &= ~ 0b1;
unsigned NSPIRE_RTC_ADDR=0x90090000;
unsigned offtime=* (volatile unsigned *) NSPIRE_RTC_ADDR;
for (int n=0;!on_key_pressed();++n){
loopsleep(100);
idle();
}
lcd_controller[6] |= 0b1;
loopsleep(20);
lcd_controller[6]|= 0b1 << 11;
if (is_cx2)
*(volatile unsigned *)(NSPIRE_CONTRAST_ADDR+4)=oldval2;
*(volatile unsigned *)NSPIRE_CONTRAST_ADDR=oldval;
sync_screen();
}
}
}
}

View File

@@ -0,0 +1,20 @@
#ifndef ION_SIMULATOR_MAIN_H
#define ION_SIMULATOR_MAIN_H
namespace Ion {
namespace Simulator {
namespace Main {
void init();
void quit();
void setNeedsRefresh();
void refresh();
void runPowerOffSafe(void (*powerOffSafeFunction)(), bool prepareVRAM);
}
}
}
#endif

View File

@@ -0,0 +1,23 @@
#ifndef ION_SIMULATOR_PLATFORM_H
#define ION_SIMULATOR_PLATFORM_H
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Those functions should be implemented per-platform.
* They are defined as C function for easier interop. */
const char * IonSimulatorGetLanguageCode();
void IonSimulatorKeyboardKeyDown(int keyNumber);
void IonSimulatorKeyboardKeyUp(int keyNumber);
void IonSimulatorEventsPushEvent(int eventNumber);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,23 @@
#include <ion/power.h>
#include <stdint.h>
#include <string.h>
#include "main.h"
void powerOff(void){
}
namespace Ion {
namespace Power {
void suspend(bool checkIfOnOffKeyReleased) {
Simulator::Main::runPowerOffSafe(powerOff, true);
}
void standby() {
Simulator::Main::runPowerOffSafe(powerOff, true);
}
}
}

View File

@@ -0,0 +1,15 @@
#include "platform.h"
namespace Ion {
namespace Simulator {
namespace Telemetry {
void init() {
}
void shutdown() {
}
}
}
}

View File

@@ -0,0 +1,21 @@
#include <ion/timing.h>
#include <chrono>
#include "k_csdk.h"
namespace Ion {
namespace Timing {
uint64_t millis() {
return ::millis();
}
void usleep(uint32_t us) {
os_wait_1ms(us/1000); // sleep_us(us);
}
void msleep(uint32_t ms) {
os_wait_1ms(ms); // sleep_us(ms * 1000);
}
}
}