Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizations #123

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
280 changes: 140 additions & 140 deletions ndless-sdk/include/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,148 +29,148 @@ typedef struct {
#define _KEY_DUMMY_ROW 0x1C
#define _KEY_DUMMY_COL 0x400

static const t_key KEY_NSPIRE_RET = KEY_(0x10, 0x001);
static const t_key KEY_NSPIRE_ENTER = KEY_(0x10, 0x002);
static const t_key KEY_NSPIRE_SPACE = KEYTPAD_(0x10, 0x004, 0x10, 0x10);
static const t_key KEY_NSPIRE_NEGATIVE = KEY_(0x10, 0x008);
static const t_key KEY_NSPIRE_Z = KEYTPAD_(0x10, 0x010, 0x10, 0x20);
static const t_key KEY_NSPIRE_PERIOD = KEYTPAD_(0x10, 0x20, 0x1A, 0x010);
static const t_key KEY_NSPIRE_Y = KEY_(0x10, 0x040);
static const t_key KEY_NSPIRE_0 = KEY_(0x10, 0x080);
static const t_key KEY_NSPIRE_X = KEYTPAD_(0x10, 0x100, 0x12, 0x001);
static const t_key KEY_NSPIRE_THETA = KEYTPAD_(0x10, 0x400, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_COMMA = KEYTPAD_(0x12, 0x001, 0x1E, 0x400);
static const t_key KEY_NSPIRE_PLUS = KEYTPAD_(0x12, 0x002, 0x1C, 0x004);
static const t_key KEY_NSPIRE_W = KEYTPAD_(0x12, 0x004, 0x12, 0x002);
static const t_key KEY_NSPIRE_3 = KEY_(0x12, 0x008);
static const t_key KEY_NSPIRE_V = KEYTPAD_(0x12, 0x010, 0x12, 0x004);
static const t_key KEY_NSPIRE_2 = KEYTPAD_(0x12, 0x020, 0x1C, 0x010);
static const t_key KEY_NSPIRE_U = KEYTPAD_(0x12, 0x040, 0x12, 0x010);
static const t_key KEY_NSPIRE_1 = KEY_(0x12, 0x080);
static const t_key KEY_NSPIRE_T = KEYTPAD_(0x12, 0x100, 0x12, 0x020);
static const t_key KEY_NSPIRE_eEXP = KEYTPAD_(0x12, 0x200, 0x16, 0x200);
static const t_key KEY_NSPIRE_PI = KEYTPAD_(0x12, 0x400, 0x12, 0x100);
static const t_key KEY_NSPIRE_QUES = KEYTPAD_(0x14, 0x001, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_QUESEXCL = KEYTPAD_(_KEY_DUMMY_ROW, _KEY_DUMMY_COL, 0x10, 0x100);
static const t_key KEY_NSPIRE_MINUS = KEYTPAD_(0x14, 0x002, 0x1A, 0x004);
static const t_key KEY_NSPIRE_S = KEYTPAD_(0x14, 0x004, 0x12, 0x040);
static const t_key KEY_NSPIRE_6 = KEY_(0x14, 0x008);
static const t_key KEY_NSPIRE_R = KEYTPAD_(0x14, 0x010, 0x14, 0x001);
static const t_key KEY_NSPIRE_5 = KEYTPAD_(0x14, 0x020, 0x1A, 0x040);
static const t_key KEY_NSPIRE_Q = KEYTPAD_(0x14, 0x040, 0x14, 0x002);
static const t_key KEY_NSPIRE_4 = KEY_(0x14, 0x080);
static const t_key KEY_NSPIRE_P = KEYTPAD_(0x14, 0x100, 0x14, 0x004);
static const t_key KEY_NSPIRE_TENX = KEYTPAD_(0x14, 0x200, 0x12, 0x400);
static const t_key KEY_NSPIRE_EE = KEYTPAD_(0x14, 0x400, 0x14, 0x100);
static const t_key KEY_NSPIRE_COLON = KEYTPAD_(0x16, 0x001, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_MULTIPLY = KEYTPAD_(0x16, 0x002, 0x18, 0x100);
static const t_key KEY_NSPIRE_O = KEYTPAD_(0x16, 0x004, 0x14, 0x010);
static const t_key KEY_NSPIRE_9 = KEY_(0x16, 0x008);
static const t_key KEY_NSPIRE_N = KEYTPAD_(0x16, 0x010, 0x14, 0x020);
static const t_key KEY_NSPIRE_8 = KEYTPAD_(0x16, 0x020, 0x1C, 0x040);
static const t_key KEY_NSPIRE_M = KEYTPAD_(0x16, 0x040, 0x14, 0x040);
static const t_key KEY_NSPIRE_7 = KEY_(0x16, 0x080);
static const t_key KEY_NSPIRE_L = KEYTPAD_(0x16, 0x100, 0x16, 0x001);
static const t_key KEY_NSPIRE_SQU = KEYTPAD_(0x16, 0x200, 0x14, 0x200);
static const t_key KEY_NSPIRE_II = KEYTPAD_(0x16, 0x400, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_QUOTE = KEYTPAD_(0x18, 0x001, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_DIVIDE = KEYTPAD_(0x18, 0x002, 0x16, 0x100);
static const t_key KEY_NSPIRE_K = KEYTPAD_(0x18, 0x004, 0x16, 0x002);
static const t_key KEY_NSPIRE_TAN = KEY_(0x18, 0x008);
static const t_key KEY_NSPIRE_J = KEYTPAD_(0x18, 0x010, 0x16, 0x004);
static const t_key KEY_NSPIRE_COS = KEYTPAD_(0x18, 0x020, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_I = KEYTPAD_(0x18, 0x040, 0x16, 0x010);
static const t_key KEY_NSPIRE_SIN = KEYTPAD_(0x18, 0x080, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_H = KEYTPAD_(0x18, 0x100, 0x16, 0x020);
static const t_key KEY_NSPIRE_EXP = KEYTPAD_(0x18, 0x200, 0x18, 0x200);
static const t_key KEY_NSPIRE_GTHAN = KEYTPAD_(0x18, 0x400, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_APOSTROPHE = KEY_(0x1A, 0x001);
static const t_key KEY_NSPIRE_CAT = KEYTPAD_(0x1A, 0x002, 0x1A, 0x080);
static const t_key KEY_NSPIRE_FRAC = KEYTPAD_(_KEY_DUMMY_ROW, _KEY_DUMMY_COL, 0x1A, 0x100);
static const t_key KEY_NSPIRE_G = KEYTPAD_(0x1A, 0x004, 0x16, 0x040);
static const t_key KEY_NSPIRE_RP = KEYTPAD_(0x1A, 0x008, 0x1A, 0x008);
static const t_key KEY_NSPIRE_F = KEYTPAD_(0x1A, 0x010, 0x18, 0x001);
static const t_key KEY_NSPIRE_LP = KEYTPAD_(0x1A, 0x020, 0x1A, 0x020);
static const t_key KEY_NSPIRE_E = KEYTPAD_(0x1A, 0x040, 0x18, 0x002);
static const t_key KEY_NSPIRE_VAR = KEYTPAD_(0x1A, 0x080, 0x1A, 0x002);
static const t_key KEY_NSPIRE_D = KEYTPAD_(0x1A, 0x100, 0x18, 0x004);
static const t_key KEY_NSPIRE_DEL = KEYTPAD_(0x1E, 0x100, 0x1A, 0x200);
static const t_key KEY_NSPIRE_LTHAN = KEYTPAD_(0x1A, 0x400, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
static const t_key KEY_NSPIRE_FLAG = KEY_(0x1C, 0x001);
static const t_key KEY_NSPIRE_CLICK = KEYTPAD_ARROW_(0x1C, 0x002, TPAD_ARROW_CLICK);
static const t_key KEY_NSPIRE_C = KEYTPAD_(0x1C, 0x004, 0x18, 0x010);
static const t_key KEY_NSPIRE_HOME = KEYTPAD_(0x1C, 0x008, 0x10, 0x200);
static const t_key KEY_NSPIRE_B = KEYTPAD_(0x1C, 0x010, 0x18, 0x020);
static const t_key KEY_NSPIRE_MENU = KEY_(0x1C, 0x020);
static const t_key KEY_NSPIRE_A = KEYTPAD_(0x1C, 0x040, 0x18, 0x040);
static const t_key KEY_NSPIRE_ESC = KEY_(0x1C, 0x080);
static const t_key KEY_NSPIRE_BAR = KEY_(0x1C, 0x100);
static const t_key KEY_NSPIRE_TAB = KEY_(0x1C, 0x200);
static const t_key KEY_NSPIRE_EQU = KEYTPAD_(0x1E, 0x400, 0x18, 0x080);
static const t_key KEY_NSPIRE_UP = KEYTPAD_ARROW_(0x1E, 0x001, TPAD_ARROW_UP);
static const t_key KEY_NSPIRE_UPRIGHT = KEYTPAD_ARROW_(0x1E, 0x002, TPAD_ARROW_UPRIGHT);
static const t_key KEY_NSPIRE_RIGHT = KEYTPAD_ARROW_(0x1E, 0x004, TPAD_ARROW_RIGHT);
static const t_key KEY_NSPIRE_RIGHTDOWN = KEYTPAD_ARROW_(0x1E, 0x008, TPAD_ARROW_RIGHTDOWN);
static const t_key KEY_NSPIRE_DOWN = KEYTPAD_ARROW_(0x1E, 0x010, TPAD_ARROW_DOWN);
static const t_key KEY_NSPIRE_DOWNLEFT = KEYTPAD_ARROW_(0x1E, 0x020, TPAD_ARROW_DOWNLEFT);
static const t_key KEY_NSPIRE_LEFT = KEYTPAD_ARROW_(0x1E, 0x040, TPAD_ARROW_LEFT);
static const t_key KEY_NSPIRE_LEFTUP = KEYTPAD_ARROW_(0x1E, 0x080, TPAD_ARROW_LEFTUP);
static const t_key KEY_NSPIRE_SHIFT = KEYTPAD_(0x1A, 0x200, 0x1E, 0x100);
static const t_key KEY_NSPIRE_CTRL = KEY_(0x1E, 0x200);
static const t_key KEY_NSPIRE_DOC = KEYTPAD_(_KEY_DUMMY_ROW, _KEY_DUMMY_COL, 0x1C, 0x008);
static const t_key KEY_NSPIRE_TRIG = KEYTPAD_(_KEY_DUMMY_ROW, _KEY_DUMMY_COL, 0x12, 0x200);
static const t_key KEY_NSPIRE_SCRATCHPAD = KEYTPAD_(_KEY_DUMMY_ROW, _KEY_DUMMY_COL, 0x1A, 0x400);
extern const t_key KEY_NSPIRE_RET;
extern const t_key KEY_NSPIRE_ENTER;
extern const t_key KEY_NSPIRE_SPACE;
extern const t_key KEY_NSPIRE_NEGATIVE;
extern const t_key KEY_NSPIRE_Z;
extern const t_key KEY_NSPIRE_PERIOD;
extern const t_key KEY_NSPIRE_Y;
extern const t_key KEY_NSPIRE_0;
extern const t_key KEY_NSPIRE_X;
extern const t_key KEY_NSPIRE_THETA;
extern const t_key KEY_NSPIRE_COMMA;
extern const t_key KEY_NSPIRE_PLUS;
extern const t_key KEY_NSPIRE_W;
extern const t_key KEY_NSPIRE_3;
extern const t_key KEY_NSPIRE_V;
extern const t_key KEY_NSPIRE_2;
extern const t_key KEY_NSPIRE_U;
extern const t_key KEY_NSPIRE_1;
extern const t_key KEY_NSPIRE_T;
extern const t_key KEY_NSPIRE_eEXP;
extern const t_key KEY_NSPIRE_PI;
extern const t_key KEY_NSPIRE_QUES;
extern const t_key KEY_NSPIRE_QUESEXCL;
extern const t_key KEY_NSPIRE_MINUS;
extern const t_key KEY_NSPIRE_S;
extern const t_key KEY_NSPIRE_6;
extern const t_key KEY_NSPIRE_R;
extern const t_key KEY_NSPIRE_5;
extern const t_key KEY_NSPIRE_Q;
extern const t_key KEY_NSPIRE_4;
extern const t_key KEY_NSPIRE_P;
extern const t_key KEY_NSPIRE_TENX;
extern const t_key KEY_NSPIRE_EE;
extern const t_key KEY_NSPIRE_COLON;
extern const t_key KEY_NSPIRE_MULTIPLY;
extern const t_key KEY_NSPIRE_O;
extern const t_key KEY_NSPIRE_9;
extern const t_key KEY_NSPIRE_N;
extern const t_key KEY_NSPIRE_8;
extern const t_key KEY_NSPIRE_M;
extern const t_key KEY_NSPIRE_7;
extern const t_key KEY_NSPIRE_L;
extern const t_key KEY_NSPIRE_SQU;
extern const t_key KEY_NSPIRE_II;
extern const t_key KEY_NSPIRE_QUOTE;
extern const t_key KEY_NSPIRE_DIVIDE;
extern const t_key KEY_NSPIRE_K;
extern const t_key KEY_NSPIRE_TAN;
extern const t_key KEY_NSPIRE_J;
extern const t_key KEY_NSPIRE_COS;
extern const t_key KEY_NSPIRE_I;
extern const t_key KEY_NSPIRE_SIN;
extern const t_key KEY_NSPIRE_H;
extern const t_key KEY_NSPIRE_EXP;
extern const t_key KEY_NSPIRE_GTHAN;
extern const t_key KEY_NSPIRE_APOSTROPHE;
extern const t_key KEY_NSPIRE_CAT;
extern const t_key KEY_NSPIRE_FRAC;
extern const t_key KEY_NSPIRE_G;
extern const t_key KEY_NSPIRE_RP;
extern const t_key KEY_NSPIRE_F;
extern const t_key KEY_NSPIRE_LP;
extern const t_key KEY_NSPIRE_E;
extern const t_key KEY_NSPIRE_VAR;
extern const t_key KEY_NSPIRE_D;
extern const t_key KEY_NSPIRE_DEL;
extern const t_key KEY_NSPIRE_LTHAN;
extern const t_key KEY_NSPIRE_FLAG;
extern const t_key KEY_NSPIRE_CLICK;
extern const t_key KEY_NSPIRE_C;
extern const t_key KEY_NSPIRE_HOME;
extern const t_key KEY_NSPIRE_B;
extern const t_key KEY_NSPIRE_MENU;
extern const t_key KEY_NSPIRE_A;
extern const t_key KEY_NSPIRE_ESC;
extern const t_key KEY_NSPIRE_BAR;
extern const t_key KEY_NSPIRE_TAB;
extern const t_key KEY_NSPIRE_EQU;
extern const t_key KEY_NSPIRE_UP;
extern const t_key KEY_NSPIRE_UPRIGHT;
extern const t_key KEY_NSPIRE_RIGHT;
extern const t_key KEY_NSPIRE_RIGHTDOWN;
extern const t_key KEY_NSPIRE_DOWN;
extern const t_key KEY_NSPIRE_DOWNLEFT;
extern const t_key KEY_NSPIRE_LEFT;
extern const t_key KEY_NSPIRE_LEFTUP;
extern const t_key KEY_NSPIRE_SHIFT;
extern const t_key KEY_NSPIRE_CTRL;
extern const t_key KEY_NSPIRE_DOC;
extern const t_key KEY_NSPIRE_TRIG;
extern const t_key KEY_NSPIRE_SCRATCHPAD;

/* TI-84+ Keypad Mappings */
static const t_key KEY_84_DOWN = KEY_(0x10, 0x001);
static const t_key KEY_84_LEFT = KEY_(0x10, 0x002);
static const t_key KEY_84_RIGHT = KEY_(0x10, 0x004);
static const t_key KEY_84_UP = KEY_(0x10, 0x008);
static const t_key KEY_84_ENTER = KEY_(0x12, 0x001);
static const t_key KEY_84_PLUS = KEY_(0x12, 0x002);
static const t_key KEY_84_MINUS = KEY_(0x12, 0x004);
static const t_key KEY_84_MULTIPLY = KEY_(0x12, 0x008);
static const t_key KEY_84_DIVIDE = KEY_(0x12, 0x010);
static const t_key KEY_84_EXP = KEY_(0x12, 0x020);
static const t_key KEY_84_CLEAR = KEY_(0x12, 0x040);
static const t_key KEY_84_NEGATIVE = KEY_(0x14, 0x001);
static const t_key KEY_84_3 = KEY_(0x14, 0x002);
static const t_key KEY_84_6 = KEY_(0x14, 0x004);
static const t_key KEY_84_9 = KEY_(0x14, 0x008);
static const t_key KEY_84_RP = KEY_(0x14, 0x010);
static const t_key KEY_84_TAN = KEY_(0x14, 0x020);
static const t_key KEY_84_VARS = KEY_(0x14, 0x040);
static const t_key KEY_84_PERIOD = KEY_(0x16, 0x001);
static const t_key KEY_84_2 = KEY_(0x16, 0x002);
static const t_key KEY_84_5 = KEY_(0x16, 0x004);
static const t_key KEY_84_8 = KEY_(0x16, 0x008);
static const t_key KEY_84_LP = KEY_(0x16, 0x010);
static const t_key KEY_84_COS = KEY_(0x16, 0x020);
static const t_key KEY_84_PRGM = KEY_(0x16, 0x040);
static const t_key KEY_84_STAT = KEY_(0x16, 0x080);
static const t_key KEY_84_0 = KEY_(0x18, 0x001);
static const t_key KEY_84_1 = KEY_(0x18, 0x002);
static const t_key KEY_84_4 = KEY_(0x18, 0x004);
static const t_key KEY_84_7 = KEY_(0x18, 0x008);
static const t_key KEY_84_COMMA = KEY_(0x18, 0x010);
static const t_key KEY_84_SIN = KEY_(0x18, 0x020);
static const t_key KEY_84_APPS = KEY_(0x18, 0x040);
static const t_key KEY_84_X = KEY_(0x18, 0x080);
static const t_key KEY_84_STO = KEY_(0x1A, 0x002);
static const t_key KEY_84_LN = KEY_(0x1A, 0x004);
static const t_key KEY_84_LOG = KEY_(0x1A, 0x008);
static const t_key KEY_84_SQU = KEY_(0x1A, 0x010);
static const t_key KEY_84_INV = KEY_(0x1A, 0x020);
static const t_key KEY_84_MATH = KEY_(0x1A, 0x040);
static const t_key KEY_84_ALPHA = KEY_(0x1A, 0x080);
static const t_key KEY_84_GRAPH = KEY_(0x1C, 0x001);
static const t_key KEY_84_TRACE = KEY_(0x1C, 0x002);
static const t_key KEY_84_ZOOM = KEY_(0x1C, 0x004);
static const t_key KEY_84_WIND = KEY_(0x1C, 0x008);
static const t_key KEY_84_YEQU = KEY_(0x1C, 0x010);
static const t_key KEY_84_2ND = KEY_(0x1C, 0x020);
static const t_key KEY_84_MODE = KEY_(0x1C, 0x040);
static const t_key KEY_84_DEL = KEY_(0x1C, 0x080);
extern const t_key KEY_84_DOWN;
extern const t_key KEY_84_LEFT;
extern const t_key KEY_84_RIGHT;
extern const t_key KEY_84_UP;
extern const t_key KEY_84_ENTER;
extern const t_key KEY_84_PLUS;
extern const t_key KEY_84_MINUS;
extern const t_key KEY_84_MULTIPLY;
extern const t_key KEY_84_DIVIDE;
extern const t_key KEY_84_EXP;
extern const t_key KEY_84_CLEAR;
extern const t_key KEY_84_NEGATIVE;
extern const t_key KEY_84_3;
extern const t_key KEY_84_6;
extern const t_key KEY_84_9;
extern const t_key KEY_84_RP;
extern const t_key KEY_84_TAN;
extern const t_key KEY_84_VARS;
extern const t_key KEY_84_PERIOD;
extern const t_key KEY_84_2;
extern const t_key KEY_84_5;
extern const t_key KEY_84_8;
extern const t_key KEY_84_LP;
extern const t_key KEY_84_COS;
extern const t_key KEY_84_PRGM;
extern const t_key KEY_84_STAT;
extern const t_key KEY_84_0;
extern const t_key KEY_84_1;
extern const t_key KEY_84_4;
extern const t_key KEY_84_7;
extern const t_key KEY_84_COMMA;
extern const t_key KEY_84_SIN;
extern const t_key KEY_84_APPS;
extern const t_key KEY_84_X;
extern const t_key KEY_84_STO;
extern const t_key KEY_84_LN;
extern const t_key KEY_84_LOG;
extern const t_key KEY_84_SQU;
extern const t_key KEY_84_INV;
extern const t_key KEY_84_MATH;
extern const t_key KEY_84_ALPHA;
extern const t_key KEY_84_GRAPH;
extern const t_key KEY_84_TRACE;
extern const t_key KEY_84_ZOOM;
extern const t_key KEY_84_WIND;
extern const t_key KEY_84_YEQU;
extern const t_key KEY_84_2ND;
extern const t_key KEY_84_MODE;
extern const t_key KEY_84_DEL;


#endif // !KEYS_H
15 changes: 14 additions & 1 deletion ndless-sdk/include/libndls.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,23 @@ BOOL isKeyPressed(const t_key *key);
void wait_key_pressed(void);
void wait_no_key_pressed(void);
/* config.c */
struct cfg_entry {
char key[15];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was OK because the only place that wrote to the cfg in code (cfg_register_fileext) also limited the key size to 15. However, this doesn't take into account manual editing of the config file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for the fileext it might apply, but not for other keys. Part of this effort of refactoring this is to make the code more versatile, isn't it? :-)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would one make this a non-static size? A variable and a helper function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely, yes. Alternatively make the fixed size bigger and provide it as a global constant.

// don't write to value_sz or value; instead, use cfg_set_value
size_t value_sz;
char *value;
};

void cfg_open(void);
void cfg_open_file(const char *filepath);
void cfg_close(void);
char *cfg_get(const char *key);
// get/put only work if cfg file is open
struct cfg_entry *cfg_get_entry(const char *key);
void cfg_set_value(struct cfg_entry *entr, const char *val);
const char *cfg_get(const char *key);
struct cfg_entry *cfg_put(const char *key, const char *val);
void cfg_put_fileext(const char *ext, const char *prgm);
// register opens cfg file as always
void cfg_register_fileext(const char *ext, const char *prgm);
void cfg_register_fileext_file(const char *fielpath, const char *ext, const char *prgm);
#define nl_hassyscall(x) _nl_hassyscall(e_##x)
Expand Down
Loading