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

Hacky SDL controls #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
224 changes: 37 additions & 187 deletions libndls.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#pragma once
#ifdef _TINSPIRE
#include_next <libndls.h>
#else
#ifndef LIBNDLS_H
#define LIBNDLS_H

#include <SDL/SDL_keysym.h>
#include <stdint.h>

typedef enum {
Expand All @@ -16,35 +15,38 @@
SCR_TYPE_COUNT=5
} scr_type_t;

#define isKeyPressed(x) 0
#define lcd_type(x) SCR_320x240_565

#define isKeyPressed(x) 0
typedef enum {
KEY_NSPIRE_ESC = SDLK_ESCAPE,
KEY_NSPIRE_CLICK = SDLK_KP_ENTER,
KEY_NSPIRE_UP = SDLK_UP,
KEY_NSPIRE_DOWN = SDLK_DOWN,
KEY_NSPIRE_RIGHT = SDLK_RIGHT,
KEY_NSPIRE_LEFT = SDLK_LEFT,
KEY_NSPIRE_1 = SDLK_1,
KEY_NSPIRE_2 = SDLK_2,
KEY_NSPIRE_3 = SDLK_3,
KEY_NSPIRE_4 = SDLK_4,
KEY_NSPIRE_5 = SDLK_5,
KEY_NSPIRE_6 = SDLK_6,
KEY_NSPIRE_7 = SDLK_7,
KEY_NSPIRE_8 = SDLK_8,
KEY_NSPIRE_9 = SDLK_9,
KEY_NSPIRE_0 = SDLK_0,
KEY_NSPIRE_MENU = SDLK_TAB,
KEY_NSPIRE_PERIOD = SDLK_PERIOD,
KEY_NSPIRE_MINUS = SDLK_MINUS,
KEY_NSPIRE_PLUS = SDLK_PLUS,
KEY_NSPIRE_CTRL = SDLK_F1,
} t_key;

#define is_classic 0
#define is_cx 1
#define touchpad_scan(x) do{}while(0)
#define is_touchpad 0
#define touchpad_arrow_pressed(x) 0

#ifndef KEYS_H
#define KEYS_H

typedef struct {
unsigned char contact; /* "touched". TRUE or FALSE */
unsigned char proximity;
uint16_t x;
uint16_t y;
unsigned char x_velocity;
unsigned char y_velocity;
uint16_t dummy;
unsigned char pressed; /* "key pressed". TRUE or FALSE */
unsigned char arrow; /* area of the pad currently touched. see tpad_arrow_t. */
} touchpad_report_t;
#define is_touchpad 1

/***********************************
* Keys (key=(offset, 2^bit #)
***********************************/

typedef enum tpad_arrow
typedef enum tpad_arrow
{
TPAD_ARROW_NONE,
TPAD_ARROW_UP, TPAD_ARROW_UPRIGHT,
Expand All @@ -55,165 +57,13 @@
} tpad_arrow_t;

typedef struct {
int row, col, tpad_row, tpad_col;
tpad_arrow_t tpad_arrow;
} t_key;

/* Used when the row and column are the same for both models */
#define KEY_(row, col) {row, col, row, col, TPAD_ARROW_NONE}
#define KEYTPAD_(row, col, tpad_row, tpad_col) {row, col, tpad_row, tpad_col, TPAD_ARROW_NONE}
#define KEYTPAD_ARROW_(row, col, tpad_arrow) {row, col, row, col, tpad_arrow}

/* Used to fill up a nonexistent key on a model */
#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, _KEY_DUMMY_ROW, _KEY_DUMMY_COL);
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);

/* 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);


#endif // !KEYS_H

unsigned char contact;
uint16_t x;
uint16_t y;
unsigned char pressed;
tpad_arrow_t arrow;
} touchpad_report_t;

#endif
extern touchpad_report_t tpad_report;
inline bool touchpad_scan(touchpad_report_t *r) { *r = tpad_report; return true; }
#endif
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int main(int argc, char *argv[])

nglDisplay();

Task::handleEvents();
Task::current_task->logic();
}

Expand Down
47 changes: 47 additions & 0 deletions task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
#include "settingstask.h"
#include "inventory.h"

#ifndef _TINSPIRE
#include <SDL/SDL_events.h>
#include <unistd.h>
touchpad_report_t tpad_report = {};
static bool key_pressed[256] = {};
#endif

//The values have to stay somewhere
Task *Task::current_task;
bool Task::key_held_down, Task::running, Task::background_saved, Task::has_touchpad, Task::keys_inverted;
Expand All @@ -31,10 +38,50 @@ bool Task::keyPressed(const t_key &key)
else
return (*reinterpret_cast<volatile uint16_t*>(0x900E0000 + key.row) & key.col) == 0;
#else
if(key < sizeof(key_pressed)/sizeof(*key_pressed))
return key_pressed[key];
return false;
#endif
}

void Task::handleEvents()
{
#ifndef _TINSPIRE
SDL_Event event;

usleep(30000);

while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
if(event.key.keysym.sym < sizeof(key_pressed)/sizeof(*key_pressed))
key_pressed[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
if(event.key.keysym.sym < sizeof(key_pressed)/sizeof(*key_pressed))
key_pressed[event.key.keysym.sym] = false;
break;

case SDL_MOUSEMOTION:
tpad_report.contact = true;
tpad_report.x = event.motion.x * 25;
tpad_report.y = event.motion.y * -25;
break;

case SDL_QUIT:
running = false;
break;

default:
break;
}
}
#endif
}

void Task::initializeGlobals(const char *savefile)
{
running = true;
Expand Down
1 change: 1 addition & 0 deletions task.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Task
virtual void makeCurrent();

static bool keyPressed(const t_key &key);
static void handleEvents();

static void initializeGlobals(const char *savefile);
static void deinitializeGlobals();
Expand Down