use keyboard handling like x48ng; press F11 to load zeldahp.dir on stack

This commit is contained in:
Gwenhael Le Moine 2024-04-18 13:22:46 +02:00
parent 6a3cfc81d7
commit 8f761334ce
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 748 additions and 442 deletions

402
src/gui.c
View file

@ -5,11 +5,11 @@
#include <SDL2/SDL_image.h> #include <SDL2/SDL_image.h>
#include <SDL2/SDL_ttf.h> #include <SDL2/SDL_ttf.h>
#include "config.h" #include "config.h" /* config.ui_* */
#include "keyboard.h" #include "keyboard.h" /* press_*(); release_*() */
#include "gui.h" #include "emulator.h" /* for please_exit */
#include "emulator.h" /* for please_exit */ #include "display.h" /* LCD_HEIGHT; LCD_WIDTH; shouldRender; lcdScreenGS[] */
#include "display.h" #include "persistence.h" /* load_file_on_stack(); */
#define PANEL_FLAG_VISIBLE 0x01 #define PANEL_FLAG_VISIBLE 0x01
@ -38,8 +38,6 @@
#define UI_KB_HEIGHT ( config.ui_scale * Y_LINE( 9 ) ) #define UI_KB_HEIGHT ( config.ui_scale * Y_LINE( 9 ) )
#define NB_KEYS 50
/* Button flags: /* Button flags:
* Use BUTTON_B1RELEASE for normal buttons. * Use BUTTON_B1RELEASE for normal buttons.
* Use BUTTON_B1RELEASE | BUTTON_B2TOGGLE for calculator buttons. * Use BUTTON_B1RELEASE | BUTTON_B2TOGGLE for calculator buttons.
@ -66,8 +64,7 @@ typedef struct {
char* label_Rshift; char* label_Rshift;
char* label_letter; char* label_letter;
char* label_below; char* label_below;
void ( *down )( void ); int hpkey;
void ( *up )( void );
} Button; } Button;
typedef struct { typedef struct {
@ -118,8 +115,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "A", .label_letter = "A",
.label_below = "", .label_below = "",
.down = press_A, .hpkey = HPKEY_A },
.up = release_A },
{.index = 1, {.index = 1,
.x = X_COL( 1 ), .x = X_COL( 1 ),
.y = Y_LINE( 0 ), .y = Y_LINE( 0 ),
@ -131,8 +127,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "B", .label_letter = "B",
.label_below = "", .label_below = "",
.down = press_B, .hpkey = HPKEY_B },
.up = release_B },
{.index = 2, {.index = 2,
.x = X_COL( 2 ), .x = X_COL( 2 ),
.y = Y_LINE( 0 ), .y = Y_LINE( 0 ),
@ -144,8 +139,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "C", .label_letter = "C",
.label_below = "", .label_below = "",
.down = press_C, .hpkey = HPKEY_C },
.up = release_C },
{.index = 3, {.index = 3,
.x = X_COL( 3 ), .x = X_COL( 3 ),
.y = Y_LINE( 0 ), .y = Y_LINE( 0 ),
@ -157,8 +151,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "D", .label_letter = "D",
.label_below = "", .label_below = "",
.down = press_D, .hpkey = HPKEY_D },
.up = release_D },
{.index = 4, {.index = 4,
.x = X_COL( 4 ), .x = X_COL( 4 ),
.y = Y_LINE( 0 ), .y = Y_LINE( 0 ),
@ -170,8 +163,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "E", .label_letter = "E",
.label_below = "", .label_below = "",
.down = press_E, .hpkey = HPKEY_E },
.up = release_E },
{.index = 5, {.index = 5,
.x = X_COL( 5 ), .x = X_COL( 5 ),
.y = Y_LINE( 0 ), .y = Y_LINE( 0 ),
@ -183,8 +175,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "F", .label_letter = "F",
.label_below = "", .label_below = "",
.down = press_F, .hpkey = HPKEY_F },
.up = release_F },
{.index = 6, {.index = 6,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -197,8 +188,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "POLAR", .label_Rshift = "POLAR",
.label_letter = "G", .label_letter = "G",
.label_below = "", .label_below = "",
.down = press_MTH, .hpkey = HPKEY_MTH },
.up = release_MTH },
{.index = 7, {.index = 7,
.x = X_COL( 1 ), .x = X_COL( 1 ),
.y = Y_LINE( 1 ), .y = Y_LINE( 1 ),
@ -210,8 +200,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "CHARS", .label_Rshift = "CHARS",
.label_letter = "H", .label_letter = "H",
.label_below = "", .label_below = "",
.down = press_PRG, .hpkey = HPKEY_PRG },
.up = release_PRG },
{.index = 8, {.index = 8,
.x = X_COL( 2 ), .x = X_COL( 2 ),
.y = Y_LINE( 1 ), .y = Y_LINE( 1 ),
@ -223,8 +212,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "MODES", .label_Rshift = "MODES",
.label_letter = "I", .label_letter = "I",
.label_below = "", .label_below = "",
.down = press_CST, .hpkey = HPKEY_CST },
.up = release_CST },
{.index = 9, {.index = 9,
.x = X_COL( 3 ), .x = X_COL( 3 ),
.y = Y_LINE( 1 ), .y = Y_LINE( 1 ),
@ -236,8 +224,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "MEMORY", .label_Rshift = "MEMORY",
.label_letter = "J", .label_letter = "J",
.label_below = "", .label_below = "",
.down = press_VAR, .hpkey = HPKEY_VAR },
.up = release_VAR },
{.index = 10, {.index = 10,
.x = X_COL( 4 ), .x = X_COL( 4 ),
.y = Y_LINE( 1 ), .y = Y_LINE( 1 ),
@ -249,8 +236,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "STACK", .label_Rshift = "STACK",
.label_letter = "K", .label_letter = "K",
.label_below = "", .label_below = "",
.down = press_UP, .hpkey = HPKEY_UP },
.up = release_UP },
{.index = 11, {.index = 11,
.x = X_COL( 5 ), .x = X_COL( 5 ),
.y = Y_LINE( 1 ), .y = Y_LINE( 1 ),
@ -262,8 +248,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "MENU", .label_Rshift = "MENU",
.label_letter = "L", .label_letter = "L",
.label_below = "", .label_below = "",
.down = press_NXT, .hpkey = HPKEY_NXT },
.up = release_NXT },
{.index = 12, {.index = 12,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -276,8 +261,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "HOME", .label_Rshift = "HOME",
.label_letter = "M", .label_letter = "M",
.label_below = "", .label_below = "",
.down = press_QUOTE, .hpkey = HPKEY_QUOTE },
.up = release_QUOTE },
{.index = 13, {.index = 13,
.x = X_COL( 1 ), .x = X_COL( 1 ),
.y = Y_LINE( 2 ), .y = Y_LINE( 2 ),
@ -289,8 +273,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "RCL", .label_Rshift = "RCL",
.label_letter = "N", .label_letter = "N",
.label_below = "", .label_below = "",
.down = press_STO, .hpkey = HPKEY_STO },
.up = release_STO },
{.index = 14, {.index = 14,
.x = X_COL( 2 ), .x = X_COL( 2 ),
.y = Y_LINE( 2 ), .y = Y_LINE( 2 ),
@ -302,8 +285,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "UNDO", .label_Rshift = "UNDO",
.label_letter = "O", .label_letter = "O",
.label_below = "", .label_below = "",
.down = press_EVAL, .hpkey = HPKEY_EVAL },
.up = release_EVAL },
{.index = 15, {.index = 15,
.x = X_COL( 3 ), .x = X_COL( 3 ),
.y = Y_LINE( 2 ), .y = Y_LINE( 2 ),
@ -315,8 +297,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "PICTURE", .label_Rshift = "PICTURE",
.label_letter = "P", .label_letter = "P",
.label_below = "", .label_below = "",
.down = press_LEFT, .hpkey = HPKEY_LEFT },
.up = release_LEFT },
{.index = 16, {.index = 16,
.x = X_COL( 4 ), .x = X_COL( 4 ),
.y = Y_LINE( 2 ), .y = Y_LINE( 2 ),
@ -328,8 +309,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "VIEW", .label_Rshift = "VIEW",
.label_letter = "Q", .label_letter = "Q",
.label_below = "", .label_below = "",
.down = press_DOWN, .hpkey = HPKEY_DOWN },
.up = release_DOWN },
{.index = 17, {.index = 17,
.x = X_COL( 5 ), .x = X_COL( 5 ),
.y = Y_LINE( 2 ), .y = Y_LINE( 2 ),
@ -341,8 +321,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "SWAP", .label_Rshift = "SWAP",
.label_letter = "R", .label_letter = "R",
.label_below = "", .label_below = "",
.down = press_RIGHT, .hpkey = HPKEY_RIGHT },
.up = release_RIGHT },
{.index = 18, {.index = 18,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -355,8 +334,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "\u2202", .label_Rshift = "\u2202",
.label_letter = "S", .label_letter = "S",
.label_below = "", .label_below = "",
.down = press_SIN, .hpkey = HPKEY_SIN },
.up = release_SIN },
{.index = 19, {.index = 19,
.x = X_COL( 1 ), .x = X_COL( 1 ),
.y = Y_LINE( 3 ), .y = Y_LINE( 3 ),
@ -368,8 +346,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "T", .label_letter = "T",
.label_below = "", .label_below = "",
.down = press_COS, .hpkey = HPKEY_COS },
.up = release_COS },
{.index = 20, {.index = 20,
.x = X_COL( 2 ), .x = X_COL( 2 ),
.y = Y_LINE( 3 ), .y = Y_LINE( 3 ),
@ -381,8 +358,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "\u03a3", .label_Rshift = "\u03a3",
.label_letter = "U", .label_letter = "U",
.label_below = "", .label_below = "",
.down = press_TAN, .hpkey = HPKEY_TAN },
.up = release_TAN },
{.index = 21, {.index = 21,
.x = X_COL( 3 ), .x = X_COL( 3 ),
.y = Y_LINE( 3 ), .y = Y_LINE( 3 ),
@ -394,8 +370,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "x√y", .label_Rshift = "x√y",
.label_letter = "V", .label_letter = "V",
.label_below = "", .label_below = "",
.down = press_SQRT, .hpkey = HPKEY_SQRT },
.up = release_SQRT },
{.index = 22, {.index = 22,
.x = X_COL( 4 ), .x = X_COL( 4 ),
.y = Y_LINE( 3 ), .y = Y_LINE( 3 ),
@ -407,8 +382,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "LOG", .label_Rshift = "LOG",
.label_letter = "W", .label_letter = "W",
.label_below = "", .label_below = "",
.down = press_POW, .hpkey = HPKEY_POWER },
.up = release_POW },
{.index = 23, {.index = 23,
.x = X_COL( 5 ), .x = X_COL( 5 ),
.y = Y_LINE( 3 ), .y = Y_LINE( 3 ),
@ -420,8 +394,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "LN", .label_Rshift = "LN",
.label_letter = "X", .label_letter = "X",
.label_below = "", .label_below = "",
.down = press_INV, .hpkey = HPKEY_INV },
.up = release_INV },
{.index = 24, {.index = 24,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -434,8 +407,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "MATRIX", .label_Rshift = "MATRIX",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_ENTER, .hpkey = HPKEY_ENTER },
.up = release_ENTER },
{.index = 25, {.index = 25,
.x = X_COL( 2 ), .x = X_COL( 2 ),
.y = Y_LINE( 4 ), .y = Y_LINE( 4 ),
@ -447,8 +419,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "CMD", .label_Rshift = "CMD",
.label_letter = "Y", .label_letter = "Y",
.label_below = "", .label_below = "",
.down = press_NEG, .hpkey = HPKEY_NEG },
.up = release_NEG },
{.index = 26, {.index = 26,
.x = X_COL( 3 ), .x = X_COL( 3 ),
.y = Y_LINE( 4 ), .y = Y_LINE( 4 ),
@ -460,8 +431,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "ARG", .label_Rshift = "ARG",
.label_letter = "Z", .label_letter = "Z",
.label_below = "", .label_below = "",
.down = press_EEX, .hpkey = HPKEY_EEX },
.up = release_EEX },
{.index = 27, {.index = 27,
.x = X_COL( 4 ), .x = X_COL( 4 ),
.y = Y_LINE( 4 ), .y = Y_LINE( 4 ),
@ -473,8 +443,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "CLEAR", .label_Rshift = "CLEAR",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_DEL, .hpkey = HPKEY_DEL },
.up = release_DEL },
{.index = 28, {.index = 28,
.x = X_COL( 5 ), .x = X_COL( 5 ),
.y = Y_LINE( 4 ), .y = Y_LINE( 4 ),
@ -486,8 +455,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "DROP", .label_Rshift = "DROP",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_BKSP, .hpkey = HPKEY_BS },
.up = release_BKSP },
{.index = 29, {.index = 29,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -500,8 +468,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "ENTRY", .label_Rshift = "ENTRY",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_ALPHA, .hpkey = HPKEY_ALPHA },
.up = release_ALPHA },
{.index = 30, {.index = 30,
.x = X2_COL( 1 ), .x = X2_COL( 1 ),
.y = Y_LINE( 5 ), .y = Y_LINE( 5 ),
@ -513,8 +480,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "SOLVE", .label_Rshift = "SOLVE",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_7, .hpkey = HPKEY_7 },
.up = release_7 },
{.index = 31, {.index = 31,
.x = X2_COL( 2 ), .x = X2_COL( 2 ),
.y = Y_LINE( 5 ), .y = Y_LINE( 5 ),
@ -526,8 +492,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "PLOT", .label_Rshift = "PLOT",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_8, .hpkey = HPKEY_8 },
.up = release_8 },
{.index = 32, {.index = 32,
.x = X2_COL( 3 ), .x = X2_COL( 3 ),
.y = Y_LINE( 5 ), .y = Y_LINE( 5 ),
@ -539,8 +504,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "SYMBOLIC", .label_Rshift = "SYMBOLIC",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_9, .hpkey = HPKEY_9 },
.up = release_9 },
{.index = 33, {.index = 33,
.x = X2_COL( 4 ) + 2, .x = X2_COL( 4 ) + 2,
.y = Y_LINE( 5 ), .y = Y_LINE( 5 ),
@ -552,8 +516,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "#", .label_Rshift = "#",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_DIV, .hpkey = HPKEY_DIV },
.up = release_DIV },
{.index = 34, {.index = 34,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -566,8 +529,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_LSHIFT, .hpkey = HPKEY_SHL },
.up = release_LSHIFT },
{.index = 35, {.index = 35,
.x = X2_COL( 1 ), .x = X2_COL( 1 ),
.y = Y_LINE( 6 ), .y = Y_LINE( 6 ),
@ -579,8 +541,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "TIME", .label_Rshift = "TIME",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_4, .hpkey = HPKEY_4 },
.up = release_4 },
{.index = 36, {.index = 36,
.x = X2_COL( 2 ), .x = X2_COL( 2 ),
.y = Y_LINE( 6 ), .y = Y_LINE( 6 ),
@ -592,8 +553,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "STAT", .label_Rshift = "STAT",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_5, .hpkey = HPKEY_5 },
.up = release_5 },
{.index = 37, {.index = 37,
.x = X2_COL( 3 ), .x = X2_COL( 3 ),
.y = Y_LINE( 6 ), .y = Y_LINE( 6 ),
@ -605,8 +565,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "UNITS", .label_Rshift = "UNITS",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_6, .hpkey = HPKEY_6 },
.up = release_6 },
{.index = 38, {.index = 38,
.x = X2_COL( 4 ) + 2, .x = X2_COL( 4 ) + 2,
.y = Y_LINE( 6 ), .y = Y_LINE( 6 ),
@ -618,8 +577,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "_", .label_Rshift = "_",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_MULT, .hpkey = HPKEY_MUL },
.up = release_MULT },
{.index = 39, {.index = 39,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -632,8 +590,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "", .label_Rshift = "",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_RSHIFT, .hpkey = HPKEY_SHR },
.up = release_RSHIFT },
{.index = 40, {.index = 40,
.x = X2_COL( 1 ), .x = X2_COL( 1 ),
.y = Y_LINE( 7 ), .y = Y_LINE( 7 ),
@ -645,8 +602,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "I/O", .label_Rshift = "I/O",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_1, .hpkey = HPKEY_1 },
.up = release_1 },
{.index = 41, {.index = 41,
.x = X2_COL( 2 ), .x = X2_COL( 2 ),
.y = Y_LINE( 7 ), .y = Y_LINE( 7 ),
@ -658,8 +614,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "LIBRARY", .label_Rshift = "LIBRARY",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_2, .hpkey = HPKEY_2 },
.up = release_2 },
{.index = 42, {.index = 42,
.x = X2_COL( 3 ), .x = X2_COL( 3 ),
.y = Y_LINE( 7 ), .y = Y_LINE( 7 ),
@ -671,8 +626,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "EQ LIB", .label_Rshift = "EQ LIB",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_3, .hpkey = HPKEY_3 },
.up = release_3 },
{.index = 43, {.index = 43,
.x = X2_COL( 4 ) + 2, .x = X2_COL( 4 ) + 2,
.y = Y_LINE( 7 ), .y = Y_LINE( 7 ),
@ -684,8 +638,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "\" \"", .label_Rshift = "\" \"",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_MINUS, .hpkey = HPKEY_MINUS },
.up = release_MINUS },
{.index = 44, {.index = 44,
.x = X_COL( 0 ), .x = X_COL( 0 ),
@ -698,8 +651,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "OFF", .label_Rshift = "OFF",
.label_letter = "", .label_letter = "",
.label_below = "CANCEL", .label_below = "CANCEL",
.down = press_ON, .hpkey = HPKEY_ON },
.up = release_ON },
{.index = 45, {.index = 45,
.x = X2_COL( 1 ), .x = X2_COL( 1 ),
.y = Y_LINE( 8 ), .y = Y_LINE( 8 ),
@ -711,8 +663,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "\u2192", .label_Rshift = "\u2192",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_0, .hpkey = HPKEY_0 },
.up = release_0 },
{.index = 46, {.index = 46,
.x = X2_COL( 2 ), .x = X2_COL( 2 ),
.y = Y_LINE( 8 ), .y = Y_LINE( 8 ),
@ -724,8 +675,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "\u2ba0", .label_Rshift = "\u2ba0",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_PERIOD, .hpkey = HPKEY_PERIOD},
.up = release_PERIOD },
{.index = 47, {.index = 47,
.x = X2_COL( 3 ), .x = X2_COL( 3 ),
.y = Y_LINE( 8 ), .y = Y_LINE( 8 ),
@ -737,8 +687,7 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = "\u29a8", .label_Rshift = "\u29a8",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_SPC, .hpkey = HPKEY_SPC },
.up = release_SPC },
{.index = 48, {.index = 48,
.x = X2_COL( 4 ) + 2, .x = X2_COL( 4 ) + 2,
.y = Y_LINE( 8 ), .y = Y_LINE( 8 ),
@ -750,22 +699,21 @@ static Button gui_buttons[ NB_KEYS ] = {
.label_Rshift = ": :", .label_Rshift = ": :",
.label_letter = "", .label_letter = "",
.label_below = "", .label_below = "",
.down = press_PLUS, .hpkey = HPKEY_PLUS },
.up = release_PLUS },
{.index = 49, /* {.index = 49, */
.x = X_COL( 0 ), /* .x = X_COL( 0 ), */
.y = Y_LINE( 9 ), /* .y = Y_LINE( 9 ), */
.w = 40, /* .w = 40, */
.h = UI_K_HEIGHT_2, /* .h = UI_K_HEIGHT_2, */
.flags = std_flags, /* .flags = std_flags, */
.label = "load file", /* .label = "load file", */
.label_Lshift = "", /* .label_Lshift = "", */
.label_Rshift = "", /* .label_Rshift = "", */
.label_letter = "", /* .label_letter = "", */
.label_below = "", /* .label_below = "", */
.down = press_LoadFile, /* .down = press_LoadFile, */
.up = release_LoadFile}, /* .up = release_LoadFile}, */
}; };
static colors_t gui_colors = { static colors_t gui_colors = {
@ -965,19 +913,16 @@ static inline void _button_mouse_down( int mouse_x, int mouse_y, int mouse_butto
if ( gui_buttons[ bindex ].flags & BUTTON_PUSHED ) { if ( gui_buttons[ bindex ].flags & BUTTON_PUSHED ) {
gui_buttons[ bindex ].flags &= ~BUTTON_PUSHED; gui_buttons[ bindex ].flags &= ~BUTTON_PUSHED;
if ( gui_buttons[ bindex ].up ) release_key( gui_buttons[ bindex ].hpkey );
gui_buttons[ bindex ].up();
} else { } else {
gui_buttons[ bindex ].flags |= BUTTON_PUSHED; gui_buttons[ bindex ].flags |= BUTTON_PUSHED;
if ( gui_buttons[ bindex ].down ) press_key( gui_buttons[ bindex ].hpkey );
gui_buttons[ bindex ].down();
} }
} else if ( mouse_button == 1 && !( gui_buttons[ bindex ].flags & BUTTON_PUSHED ) ) { } else if ( mouse_button == 1 && !( gui_buttons[ bindex ].flags & BUTTON_PUSHED ) ) {
gui_buttons[ bindex ].flags |= BUTTON_PUSHED; gui_buttons[ bindex ].flags |= BUTTON_PUSHED;
if ( gui_buttons[ bindex ].down ) press_key( gui_buttons[ bindex ].hpkey );
gui_buttons[ bindex ].down();
} }
} }
@ -991,8 +936,7 @@ static inline void _button_mouse_up( int mouse_x, int mouse_y, int mouse_button
if ( mouse_button == 1 && ( gui_buttons[ bindex ].flags & BUTTON_PUSHED ) && !( gui_buttons[ bindex ].flags & BUTTON_B1TOGGLE ) ) { if ( mouse_button == 1 && ( gui_buttons[ bindex ].flags & BUTTON_PUSHED ) && !( gui_buttons[ bindex ].flags & BUTTON_B1TOGGLE ) ) {
gui_buttons[ bindex ].flags &= ~BUTTON_PUSHED; gui_buttons[ bindex ].flags &= ~BUTTON_PUSHED;
if ( gui_buttons[ bindex ].up ) press_key( gui_buttons[ bindex ].hpkey );
gui_buttons[ bindex ].up();
} }
} }
if ( mouse_button == 1 ) { if ( mouse_button == 1 ) {
@ -1000,8 +944,7 @@ static inline void _button_mouse_up( int mouse_x, int mouse_y, int mouse_button
if ( ( gui_buttons[ bindex ].flags & ( BUTTON_B1RELEASE | BUTTON_PUSHED ) ) == ( BUTTON_B1RELEASE | BUTTON_PUSHED ) ) { if ( ( gui_buttons[ bindex ].flags & ( BUTTON_B1RELEASE | BUTTON_PUSHED ) ) == ( BUTTON_B1RELEASE | BUTTON_PUSHED ) ) {
gui_buttons[ bindex ].flags &= ~BUTTON_PUSHED; gui_buttons[ bindex ].flags &= ~BUTTON_PUSHED;
if ( gui_buttons[ bindex ].up ) release_key( gui_buttons[ bindex ].hpkey );
gui_buttons[ bindex ].up();
} }
/* } */ /* } */
} }
@ -1083,168 +1026,175 @@ bool gui_events()
switch ( event.key.keysym.scancode ) { switch ( event.key.keysym.scancode ) {
case SDL_SCANCODE_KP_0: case SDL_SCANCODE_KP_0:
case SDL_SCANCODE_0: case SDL_SCANCODE_0:
press_0(); press_key( HPKEY_0 );
break; break;
case SDL_SCANCODE_KP_1: case SDL_SCANCODE_KP_1:
case SDL_SCANCODE_1: case SDL_SCANCODE_1:
press_1(); press_key( HPKEY_1 );
break; break;
case SDL_SCANCODE_KP_2: case SDL_SCANCODE_KP_2:
case SDL_SCANCODE_2: case SDL_SCANCODE_2:
press_2(); press_key( HPKEY_2 );
break; break;
case SDL_SCANCODE_KP_3: case SDL_SCANCODE_KP_3:
case SDL_SCANCODE_3: case SDL_SCANCODE_3:
press_3(); press_key( HPKEY_3 );
break; break;
case SDL_SCANCODE_KP_4: case SDL_SCANCODE_KP_4:
case SDL_SCANCODE_4: case SDL_SCANCODE_4:
press_4(); press_key( HPKEY_4 );
break; break;
case SDL_SCANCODE_KP_5: case SDL_SCANCODE_KP_5:
case SDL_SCANCODE_5: case SDL_SCANCODE_5:
press_5(); press_key( HPKEY_5 );
break; break;
case SDL_SCANCODE_KP_6: case SDL_SCANCODE_KP_6:
case SDL_SCANCODE_6: case SDL_SCANCODE_6:
press_6(); press_key( HPKEY_6 );
break; break;
case SDL_SCANCODE_KP_7: case SDL_SCANCODE_KP_7:
case SDL_SCANCODE_7: case SDL_SCANCODE_7:
press_7(); press_key( HPKEY_7 );
break; break;
case SDL_SCANCODE_KP_8: case SDL_SCANCODE_KP_8:
case SDL_SCANCODE_8: case SDL_SCANCODE_8:
press_8(); press_key( HPKEY_8 );
break; break;
case SDL_SCANCODE_KP_9: case SDL_SCANCODE_KP_9:
case SDL_SCANCODE_9: case SDL_SCANCODE_9:
press_9(); press_key( HPKEY_9 );
break; break;
case SDL_SCANCODE_KP_PERIOD: case SDL_SCANCODE_KP_PERIOD:
press_PERIOD(); press_key( HPKEY_PERIOD );
break; break;
case SDL_SCANCODE_SPACE: case SDL_SCANCODE_SPACE:
press_SPC(); press_key( HPKEY_SPC );
break; break;
case SDL_SCANCODE_ESCAPE: case SDL_SCANCODE_ESCAPE:
case SDL_SCANCODE_F5: case SDL_SCANCODE_F5:
press_ON(); press_key( HPKEY_ON );
break; break;
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_RETURN:
case SDL_SCANCODE_KP_ENTER: case SDL_SCANCODE_KP_ENTER:
case SDL_SCANCODE_F1: case SDL_SCANCODE_F1:
press_ENTER(); press_key( HPKEY_ENTER );
break; break;
case SDL_SCANCODE_BACKSPACE: case SDL_SCANCODE_BACKSPACE:
press_BKSP(); press_key( HPKEY_BS );
break; break;
case SDL_SCANCODE_KP_PLUS: case SDL_SCANCODE_KP_PLUS:
press_PLUS(); press_key( HPKEY_PLUS );
break; break;
case SDL_SCANCODE_KP_MINUS: case SDL_SCANCODE_KP_MINUS:
press_MINUS(); press_key( HPKEY_MINUS );
break; break;
case SDL_SCANCODE_KP_MULTIPLY: case SDL_SCANCODE_KP_MULTIPLY:
press_MULT(); press_key( HPKEY_MUL );
break; break;
case SDL_SCANCODE_KP_DIVIDE: case SDL_SCANCODE_KP_DIVIDE:
press_DIV(); press_key( HPKEY_DIV );
break; break;
case SDL_SCANCODE_A: case SDL_SCANCODE_A:
press_A(); press_key( HPKEY_A );
break; break;
case SDL_SCANCODE_B: case SDL_SCANCODE_B:
press_B(); press_key( HPKEY_B );
break; break;
case SDL_SCANCODE_C: case SDL_SCANCODE_C:
press_C(); press_key( HPKEY_C );
break; break;
case SDL_SCANCODE_D: case SDL_SCANCODE_D:
press_D(); press_key( HPKEY_D );
break; break;
case SDL_SCANCODE_E: case SDL_SCANCODE_E:
press_E(); press_key( HPKEY_E );
break; break;
case SDL_SCANCODE_F: case SDL_SCANCODE_F:
press_F(); press_key( HPKEY_F );
break; break;
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
press_MTH(); press_key( HPKEY_MTH );
break; break;
case SDL_SCANCODE_H: case SDL_SCANCODE_H:
press_PRG(); press_key( HPKEY_PRG );
break; break;
case SDL_SCANCODE_I: case SDL_SCANCODE_I:
press_CST(); press_key( HPKEY_CST );
break; break;
case SDL_SCANCODE_J: case SDL_SCANCODE_J:
press_VAR(); press_key( HPKEY_VAR );
break; break;
case SDL_SCANCODE_K: case SDL_SCANCODE_K:
case SDL_SCANCODE_UP: case SDL_SCANCODE_UP:
press_UP(); press_key( HPKEY_UP );
break; break;
case SDL_SCANCODE_L: case SDL_SCANCODE_L:
press_NXT(); press_key( HPKEY_NXT );
break; break;
case SDL_SCANCODE_M: case SDL_SCANCODE_M:
press_QUOTE(); press_key( HPKEY_QUOTE );
break; break;
case SDL_SCANCODE_N: case SDL_SCANCODE_N:
press_STO(); press_key( HPKEY_STO );
break; break;
case SDL_SCANCODE_O: case SDL_SCANCODE_O:
press_EVAL(); press_key( HPKEY_EVAL );
break; break;
case SDL_SCANCODE_P: case SDL_SCANCODE_P:
case SDL_SCANCODE_LEFT: case SDL_SCANCODE_LEFT:
press_LEFT(); press_key( HPKEY_LEFT );
break; break;
case SDL_SCANCODE_Q: case SDL_SCANCODE_Q:
case SDL_SCANCODE_DOWN: case SDL_SCANCODE_DOWN:
press_DOWN(); press_key( HPKEY_DOWN );
break; break;
case SDL_SCANCODE_R: case SDL_SCANCODE_R:
case SDL_SCANCODE_RIGHT: case SDL_SCANCODE_RIGHT:
press_RIGHT(); press_key( HPKEY_RIGHT );
break; break;
case SDL_SCANCODE_S: case SDL_SCANCODE_S:
press_SIN(); press_key( HPKEY_SIN );
break; break;
case SDL_SCANCODE_T: case SDL_SCANCODE_T:
press_COS(); press_key( HPKEY_COS );
break; break;
case SDL_SCANCODE_U: case SDL_SCANCODE_U:
press_TAN(); press_key( HPKEY_TAN );
break; break;
case SDL_SCANCODE_V: case SDL_SCANCODE_V:
press_SQRT(); press_key( HPKEY_SQRT );
break; break;
case SDL_SCANCODE_W: case SDL_SCANCODE_W:
press_POW(); press_key( HPKEY_POWER );
break; break;
case SDL_SCANCODE_X: case SDL_SCANCODE_X:
press_INV(); press_key( HPKEY_INV );
break; break;
case SDL_SCANCODE_Y: case SDL_SCANCODE_Y:
press_NEG(); press_key( HPKEY_NEG );
break; break;
case SDL_SCANCODE_Z: case SDL_SCANCODE_Z:
press_EEX(); press_key( HPKEY_EEX );
break; break;
case SDL_SCANCODE_F2: case SDL_SCANCODE_F2:
press_LSHIFT(); press_key( HPKEY_SHL );
break; break;
case SDL_SCANCODE_F3: case SDL_SCANCODE_F3:
press_RSHIFT(); press_key( HPKEY_SHR );
break; break;
case SDL_SCANCODE_F4: case SDL_SCANCODE_F4:
press_ALPHA(); press_key( HPKEY_ALPHA );
break; break;
case SDL_SCANCODE_F7: case SDL_SCANCODE_F7:
please_exit = true; please_exit = true;
break; break;
case SDL_SCANCODE_F11:
{
load_file_on_stack( "zeldahp.dir" );
}
break;
default: default:
break; break;
} }
@ -1254,164 +1204,164 @@ bool gui_events()
switch ( event.key.keysym.scancode ) { switch ( event.key.keysym.scancode ) {
case SDL_SCANCODE_KP_0: case SDL_SCANCODE_KP_0:
case SDL_SCANCODE_0: case SDL_SCANCODE_0:
release_0(); release_key( HPKEY_0 );
break; break;
case SDL_SCANCODE_KP_1: case SDL_SCANCODE_KP_1:
case SDL_SCANCODE_1: case SDL_SCANCODE_1:
release_1(); release_key( HPKEY_1 );
break; break;
case SDL_SCANCODE_KP_2: case SDL_SCANCODE_KP_2:
case SDL_SCANCODE_2: case SDL_SCANCODE_2:
release_2(); release_key( HPKEY_2 );
break; break;
case SDL_SCANCODE_KP_3: case SDL_SCANCODE_KP_3:
case SDL_SCANCODE_3: case SDL_SCANCODE_3:
release_3(); release_key( HPKEY_3 );
break; break;
case SDL_SCANCODE_KP_4: case SDL_SCANCODE_KP_4:
case SDL_SCANCODE_4: case SDL_SCANCODE_4:
release_4(); release_key( HPKEY_4 );
break; break;
case SDL_SCANCODE_KP_5: case SDL_SCANCODE_KP_5:
case SDL_SCANCODE_5: case SDL_SCANCODE_5:
release_5(); release_key( HPKEY_5 );
break; break;
case SDL_SCANCODE_KP_6: case SDL_SCANCODE_KP_6:
case SDL_SCANCODE_6: case SDL_SCANCODE_6:
release_6(); release_key( HPKEY_6 );
break; break;
case SDL_SCANCODE_KP_7: case SDL_SCANCODE_KP_7:
case SDL_SCANCODE_7: case SDL_SCANCODE_7:
release_7(); release_key( HPKEY_7 );
break; break;
case SDL_SCANCODE_KP_8: case SDL_SCANCODE_KP_8:
case SDL_SCANCODE_8: case SDL_SCANCODE_8:
release_8(); release_key( HPKEY_8 );
break; break;
case SDL_SCANCODE_KP_9: case SDL_SCANCODE_KP_9:
case SDL_SCANCODE_9: case SDL_SCANCODE_9:
release_9(); release_key( HPKEY_9 );
break; break;
case SDL_SCANCODE_KP_PERIOD: case SDL_SCANCODE_KP_PERIOD:
release_PERIOD(); release_key( HPKEY_PERIOD );
break; break;
case SDL_SCANCODE_SPACE: case SDL_SCANCODE_SPACE:
release_SPC(); release_key( HPKEY_SPC );
break; break;
case SDL_SCANCODE_ESCAPE: case SDL_SCANCODE_ESCAPE:
case SDL_SCANCODE_F5: case SDL_SCANCODE_F5:
release_ON(); release_key( HPKEY_ON );
break; break;
case SDL_SCANCODE_RETURN: case SDL_SCANCODE_RETURN:
case SDL_SCANCODE_KP_ENTER: case SDL_SCANCODE_KP_ENTER:
case SDL_SCANCODE_F1: case SDL_SCANCODE_F1:
release_ENTER(); release_key( HPKEY_ENTER );
break; break;
case SDL_SCANCODE_BACKSPACE: case SDL_SCANCODE_BACKSPACE:
release_BKSP(); release_key( HPKEY_BS );
break; break;
case SDL_SCANCODE_KP_PLUS: case SDL_SCANCODE_KP_PLUS:
release_PLUS(); release_key( HPKEY_PLUS );
break; break;
case SDL_SCANCODE_KP_MINUS: case SDL_SCANCODE_KP_MINUS:
release_MINUS(); release_key( HPKEY_MINUS );
break; break;
case SDL_SCANCODE_KP_MULTIPLY: case SDL_SCANCODE_KP_MULTIPLY:
release_MULT(); release_key( HPKEY_MUL );
break; break;
case SDL_SCANCODE_KP_DIVIDE: case SDL_SCANCODE_KP_DIVIDE:
release_DIV(); release_key( HPKEY_DIV );
break; break;
case SDL_SCANCODE_A: case SDL_SCANCODE_A:
release_A(); release_key( HPKEY_A );
break; break;
case SDL_SCANCODE_B: case SDL_SCANCODE_B:
release_B(); release_key( HPKEY_B );
break; break;
case SDL_SCANCODE_C: case SDL_SCANCODE_C:
release_C(); release_key( HPKEY_C );
break; break;
case SDL_SCANCODE_D: case SDL_SCANCODE_D:
release_D(); release_key( HPKEY_D );
break; break;
case SDL_SCANCODE_E: case SDL_SCANCODE_E:
release_E(); release_key( HPKEY_E );
break; break;
case SDL_SCANCODE_F: case SDL_SCANCODE_F:
release_F(); release_key( HPKEY_F );
break; break;
case SDL_SCANCODE_G: case SDL_SCANCODE_G:
release_MTH(); release_key( HPKEY_MTH );
break; break;
case SDL_SCANCODE_H: case SDL_SCANCODE_H:
release_PRG(); release_key( HPKEY_PRG );
break; break;
case SDL_SCANCODE_I: case SDL_SCANCODE_I:
release_CST(); release_key( HPKEY_CST );
break; break;
case SDL_SCANCODE_J: case SDL_SCANCODE_J:
release_VAR(); release_key( HPKEY_VAR );
break; break;
case SDL_SCANCODE_K: case SDL_SCANCODE_K:
case SDL_SCANCODE_UP: case SDL_SCANCODE_UP:
release_UP(); release_key( HPKEY_UP );
break; break;
case SDL_SCANCODE_L: case SDL_SCANCODE_L:
release_NXT(); release_key( HPKEY_NXT );
break; break;
case SDL_SCANCODE_M: case SDL_SCANCODE_M:
release_QUOTE(); release_key( HPKEY_QUOTE );
break; break;
case SDL_SCANCODE_N: case SDL_SCANCODE_N:
release_STO(); release_key( HPKEY_STO );
break; break;
case SDL_SCANCODE_O: case SDL_SCANCODE_O:
release_EVAL(); release_key( HPKEY_EVAL );
break; break;
case SDL_SCANCODE_P: case SDL_SCANCODE_P:
case SDL_SCANCODE_LEFT: case SDL_SCANCODE_LEFT:
release_LEFT(); release_key( HPKEY_LEFT );
break; break;
case SDL_SCANCODE_Q: case SDL_SCANCODE_Q:
case SDL_SCANCODE_DOWN: case SDL_SCANCODE_DOWN:
release_DOWN(); release_key( HPKEY_DOWN );
break; break;
case SDL_SCANCODE_R: case SDL_SCANCODE_R:
case SDL_SCANCODE_RIGHT: case SDL_SCANCODE_RIGHT:
release_RIGHT(); release_key( HPKEY_RIGHT );
break; break;
case SDL_SCANCODE_S: case SDL_SCANCODE_S:
release_SIN(); release_key( HPKEY_SIN );
break; break;
case SDL_SCANCODE_T: case SDL_SCANCODE_T:
release_COS(); release_key( HPKEY_COS );
break; break;
case SDL_SCANCODE_U: case SDL_SCANCODE_U:
release_TAN(); release_key( HPKEY_TAN );
break; break;
case SDL_SCANCODE_V: case SDL_SCANCODE_V:
release_SQRT(); release_key( HPKEY_SQRT );
break; break;
case SDL_SCANCODE_W: case SDL_SCANCODE_W:
release_POW(); release_key( HPKEY_POWER );
break; break;
case SDL_SCANCODE_X: case SDL_SCANCODE_X:
release_INV(); release_key( HPKEY_INV );
break; break;
case SDL_SCANCODE_Y: case SDL_SCANCODE_Y:
release_NEG(); release_key( HPKEY_NEG );
break; break;
case SDL_SCANCODE_Z: case SDL_SCANCODE_Z:
release_EEX(); release_key( HPKEY_EEX );
break; break;
case SDL_SCANCODE_F2: case SDL_SCANCODE_F2:
release_LSHIFT(); release_key( HPKEY_SHL );
break; break;
case SDL_SCANCODE_F3: case SDL_SCANCODE_F3:
release_RSHIFT(); release_key( HPKEY_SHR );
break; break;
case SDL_SCANCODE_F4: case SDL_SCANCODE_F4:
release_ALPHA(); release_key( HPKEY_ALPHA );
break; break;
default: default:
break; break;

View file

@ -1,6 +1,7 @@
#include "types.h" #include "types.h"
#include "cpu.h" #include "cpu.h"
#include "persistence.h"
#include "keyboard.h"
bool kbd_on; bool kbd_on;
@ -39,7 +40,7 @@ static void update_in( void )
void kbd_out_changed( void ) { update_in(); } void kbd_out_changed( void ) { update_in(); }
void kbd_key_pressed( int row, int col ) static void kbd_key_pressed( int row, int col )
{ {
bool no_key = !cpu.in[ 0 ] && !cpu.in[ 1 ] && !cpu.in[ 3 ]; bool no_key = !cpu.in[ 0 ] && !cpu.in[ 1 ] && !cpu.in[ 3 ];
kbd_row[ row ] |= 1 << col; kbd_row[ row ] |= 1 << col;
@ -58,7 +59,7 @@ void kbd_key_pressed( int row, int col )
cpu.keyintp = false; cpu.keyintp = false;
} }
void kbd_key_released( int row, int col ) static void kbd_key_released( int row, int col )
{ {
kbd_row[ row ] &= ~( 1 << col ); kbd_row[ row ] &= ~( 1 << col );
update_in(); update_in();
@ -66,120 +67,512 @@ void kbd_key_released( int row, int col )
cpu.keyintp = false; cpu.keyintp = false;
} }
void press_PLUS( void ) { kbd_key_pressed( 0, 0 ); } void press_key( int hpkey )
void release_PLUS( void ) { kbd_key_released( 0, 0 ); }
void press_SPC( void ) { kbd_key_pressed( 0, 1 ); }
void release_SPC( void ) { kbd_key_released( 0, 1 ); }
void press_PERIOD( void ) { kbd_key_pressed( 0, 2 ); }
void release_PERIOD( void ) { kbd_key_released( 0, 2 ); }
void press_0( void ) { kbd_key_pressed( 0, 3 ); }
void release_0( void ) { kbd_key_released( 0, 3 ); }
void press_QUOTE( void ) { kbd_key_pressed( 0, 4 ); }
void release_QUOTE( void ) { kbd_key_released( 0, 4 ); }
void press_MINUS( void ) { kbd_key_pressed( 1, 0 ); }
void release_MINUS( void ) { kbd_key_released( 1, 0 ); }
void press_3( void ) { kbd_key_pressed( 1, 1 ); }
void release_3( void ) { kbd_key_released( 1, 1 ); }
void press_2( void ) { kbd_key_pressed( 1, 2 ); }
void release_2( void ) { kbd_key_released( 1, 2 ); }
void press_1( void ) { kbd_key_pressed( 1, 3 ); }
void release_1( void ) { kbd_key_released( 1, 3 ); }
void press_A( void ) { kbd_key_pressed( 1, 4 ); }
void release_A( void ) { kbd_key_released( 1, 4 ); }
void press_RSHIFT( void ) { kbd_key_pressed( 1, 5 ); }
void release_RSHIFT( void ) { kbd_key_released( 1, 5 ); }
void press_MULT( void ) { kbd_key_pressed( 2, 0 ); }
void release_MULT( void ) { kbd_key_released( 2, 0 ); }
void press_6( void ) { kbd_key_pressed( 2, 1 ); }
void release_6( void ) { kbd_key_released( 2, 1 ); }
void press_5( void ) { kbd_key_pressed( 2, 2 ); }
void release_5( void ) { kbd_key_released( 2, 2 ); }
void press_4( void ) { kbd_key_pressed( 2, 3 ); }
void release_4( void ) { kbd_key_released( 2, 3 ); }
void press_MTH( void ) { kbd_key_pressed( 2, 4 ); }
void release_MTH( void ) { kbd_key_released( 2, 4 ); }
void press_LSHIFT( void ) { kbd_key_pressed( 2, 5 ); }
void release_LSHIFT( void ) { kbd_key_released( 2, 5 ); }
void press_DIV( void ) { kbd_key_pressed( 3, 0 ); }
void release_DIV( void ) { kbd_key_released( 3, 0 ); }
void press_9( void ) { kbd_key_pressed( 3, 1 ); }
void release_9( void ) { kbd_key_released( 3, 1 ); }
void press_8( void ) { kbd_key_pressed( 3, 2 ); }
void release_8( void ) { kbd_key_released( 3, 2 ); }
void press_7( void ) { kbd_key_pressed( 3, 3 ); }
void release_7( void ) { kbd_key_released( 3, 3 ); }
void press_SIN( void ) { kbd_key_pressed( 3, 4 ); }
void release_SIN( void ) { kbd_key_released( 3, 4 ); }
void press_ALPHA( void ) { kbd_key_pressed( 3, 5 ); }
void release_ALPHA( void ) { kbd_key_released( 3, 5 ); }
void press_BKSP( void ) { kbd_key_pressed( 4, 0 ); }
void release_BKSP( void ) { kbd_key_released( 4, 0 ); }
void press_DEL( void ) { kbd_key_pressed( 4, 1 ); }
void release_DEL( void ) { kbd_key_released( 4, 1 ); }
void press_EEX( void ) { kbd_key_pressed( 4, 2 ); }
void release_EEX( void ) { kbd_key_released( 4, 2 ); }
void press_NEG( void ) { kbd_key_pressed( 4, 3 ); }
void release_NEG( void ) { kbd_key_released( 4, 3 ); }
void press_ENTER( void ) { kbd_key_pressed( 4, 4 ); }
void release_ENTER( void ) { kbd_key_released( 4, 4 ); }
void press_INV( void ) { kbd_key_pressed( 5, 0 ); }
void release_INV( void ) { kbd_key_released( 5, 0 ); }
void press_POW( void ) { kbd_key_pressed( 5, 1 ); }
void release_POW( void ) { kbd_key_released( 5, 1 ); }
void press_SQRT( void ) { kbd_key_pressed( 5, 2 ); }
void release_SQRT( void ) { kbd_key_released( 5, 2 ); }
void press_TAN( void ) { kbd_key_pressed( 5, 3 ); }
void release_TAN( void ) { kbd_key_released( 5, 3 ); }
void press_COS( void ) { kbd_key_pressed( 5, 4 ); }
void release_COS( void ) { kbd_key_released( 5, 4 ); }
void press_RIGHT( void ) { kbd_key_pressed( 6, 0 ); }
void release_RIGHT( void ) { kbd_key_released( 6, 0 ); }
void press_DOWN( void ) { kbd_key_pressed( 6, 1 ); }
void release_DOWN( void ) { kbd_key_released( 6, 1 ); }
void press_LEFT( void ) { kbd_key_pressed( 6, 2 ); }
void release_LEFT( void ) { kbd_key_released( 6, 2 ); }
void press_EVAL( void ) { kbd_key_pressed( 6, 3 ); }
void release_EVAL( void ) { kbd_key_released( 6, 3 ); }
void press_STO( void ) { kbd_key_pressed( 6, 4 ); }
void release_STO( void ) { kbd_key_released( 6, 4 ); }
void press_NXT( void ) { kbd_key_pressed( 7, 0 ); }
void release_NXT( void ) { kbd_key_released( 7, 0 ); }
void press_UP( void ) { kbd_key_pressed( 7, 1 ); }
void release_UP( void ) { kbd_key_released( 7, 1 ); }
void press_VAR( void ) { kbd_key_pressed( 7, 2 ); }
void release_VAR( void ) { kbd_key_released( 7, 2 ); }
void press_CST( void ) { kbd_key_pressed( 7, 3 ); }
void release_CST( void ) { kbd_key_released( 7, 3 ); }
void press_PRG( void ) { kbd_key_pressed( 7, 4 ); }
void release_PRG( void ) { kbd_key_released( 7, 4 ); }
void press_F( void ) { kbd_key_pressed( 8, 0 ); }
void release_F( void ) { kbd_key_released( 8, 0 ); }
void press_E( void ) { kbd_key_pressed( 8, 1 ); }
void release_E( void ) { kbd_key_released( 8, 1 ); }
void press_D( void ) { kbd_key_pressed( 8, 2 ); }
void release_D( void ) { kbd_key_released( 8, 2 ); }
void press_C( void ) { kbd_key_pressed( 8, 3 ); }
void release_C( void ) { kbd_key_released( 8, 3 ); }
void press_B( void ) { kbd_key_pressed( 8, 4 ); }
void release_B( void ) { kbd_key_released( 8, 4 ); }
void press_ON( void )
{ {
bool no_key = !cpu.in[ 3 ]; switch ( hpkey ) {
kbd_on = true; case HPKEY_ON:
cpu.in[ 3 ] |= 8; {
if ( cpu.shutdown && no_key ) bool no_key = !cpu.in[ 3 ];
cpu.shutdown = false; kbd_on = true;
cpu.in[ 3 ] |= 8;
if ( cpu.shutdown && no_key )
cpu.shutdown = false;
if ( cpu.inte && no_key ) if ( cpu.inte && no_key )
cpu_interrupt(); cpu_interrupt();
}
break;
case HPKEY_PLUS:
{
kbd_key_pressed( 0, 0 );
}
break;
case HPKEY_SPC:
{
kbd_key_pressed( 0, 1 );
}
break;
case HPKEY_PERIOD:
{
kbd_key_pressed( 0, 2 );
}
break;
case HPKEY_0:
{
kbd_key_pressed( 0, 3 );
}
break;
case HPKEY_QUOTE:
{
kbd_key_pressed( 0, 4 );
}
break;
case HPKEY_MINUS:
{
kbd_key_pressed( 1, 0 );
}
break;
case HPKEY_3:
{
kbd_key_pressed( 1, 1 );
}
break;
case HPKEY_2:
{
kbd_key_pressed( 1, 2 );
}
break;
case HPKEY_1:
{
kbd_key_pressed( 1, 3 );
}
break;
case HPKEY_A:
{
kbd_key_pressed( 1, 4 );
}
break;
case HPKEY_SHR:
{
kbd_key_pressed( 1, 5 );
}
break;
case HPKEY_MUL:
{
kbd_key_pressed( 2, 0 );
}
break;
case HPKEY_6:
{
kbd_key_pressed( 2, 1 );
}
break;
case HPKEY_5:
{
kbd_key_pressed( 2, 2 );
}
break;
case HPKEY_4:
{
kbd_key_pressed( 2, 3 );
}
break;
case HPKEY_MTH:
{
kbd_key_pressed( 2, 4 );
}
break;
case HPKEY_SHL:
{
kbd_key_pressed( 2, 5 );
}
break;
case HPKEY_DIV:
{
kbd_key_pressed( 3, 0 );
}
break;
case HPKEY_9:
{
kbd_key_pressed( 3, 1 );
}
break;
case HPKEY_8:
{
kbd_key_pressed( 3, 2 );
}
break;
case HPKEY_7:
{
kbd_key_pressed( 3, 3 );
}
break;
case HPKEY_SIN:
{
kbd_key_pressed( 3, 4 );
}
break;
case HPKEY_ALPHA:
{
kbd_key_pressed( 3, 5 );
}
break;
case HPKEY_BS:
{
kbd_key_pressed( 4, 0 );
}
break;
case HPKEY_DEL:
{
kbd_key_pressed( 4, 1 );
}
break;
case HPKEY_EEX:
{
kbd_key_pressed( 4, 2 );
}
break;
case HPKEY_NEG:
{
kbd_key_pressed( 4, 3 );
}
break;
case HPKEY_ENTER:
{
kbd_key_pressed( 4, 4 );
}
break;
case HPKEY_INV:
{
kbd_key_pressed( 5, 0 );
}
break;
case HPKEY_POWER:
{
kbd_key_pressed( 5, 1 );
}
break;
case HPKEY_SQRT:
{
kbd_key_pressed( 5, 2 );
}
break;
case HPKEY_TAN:
{
kbd_key_pressed( 5, 3 );
}
break;
case HPKEY_COS:
{
kbd_key_pressed( 5, 4 );
}
break;
case HPKEY_RIGHT:
{
kbd_key_pressed( 6, 0 );
}
break;
case HPKEY_DOWN:
{
kbd_key_pressed( 6, 1 );
}
break;
case HPKEY_LEFT:
{
kbd_key_pressed( 6, 2 );
}
break;
case HPKEY_EVAL:
{
kbd_key_pressed( 6, 3 );
}
break;
case HPKEY_STO:
{
kbd_key_pressed( 6, 4 );
}
break;
case HPKEY_NXT:
{
kbd_key_pressed( 7, 0 );
}
break;
case HPKEY_UP:
{
kbd_key_pressed( 7, 1 );
}
break;
case HPKEY_VAR:
{
kbd_key_pressed( 7, 2 );
}
break;
case HPKEY_CST:
{
kbd_key_pressed( 7, 3 );
}
break;
case HPKEY_PRG:
{
kbd_key_pressed( 7, 4 );
}
break;
case HPKEY_F:
{
kbd_key_pressed( 8, 0 );
}
break;
case HPKEY_E:
{
kbd_key_pressed( 8, 1 );
}
break;
case HPKEY_D:
{
kbd_key_pressed( 8, 2 );
}
break;
case HPKEY_C:
{
kbd_key_pressed( 8, 3 );
}
break;
case HPKEY_B:
{
kbd_key_pressed( 8, 4 );
}
break;
}
} }
void release_ON( void ) void release_key( int hpkey )
{ {
kbd_on = false; switch ( hpkey ) {
cpu.in[ 3 ] &= ~8; case HPKEY_ON:
{
kbd_on = false;
cpu.in[ 3 ] &= ~8;
}
break;
case HPKEY_PLUS:
{
kbd_key_released( 0, 0 );
}
break;
case HPKEY_SPC:
{
kbd_key_released( 0, 1 );
}
break;
case HPKEY_PERIOD:
{
kbd_key_released( 0, 2 );
}
break;
case HPKEY_0:
{
kbd_key_released( 0, 3 );
}
break;
case HPKEY_QUOTE:
{
kbd_key_released( 0, 4 );
}
break;
case HPKEY_MINUS:
{
kbd_key_released( 1, 0 );
}
break;
case HPKEY_3:
{
kbd_key_released( 1, 1 );
}
break;
case HPKEY_2:
{
kbd_key_released( 1, 2 );
}
break;
case HPKEY_1:
{
kbd_key_released( 1, 3 );
}
break;
case HPKEY_A:
{
kbd_key_released( 1, 4 );
}
break;
case HPKEY_SHR:
{
kbd_key_released( 1, 5 );
}
break;
case HPKEY_MUL:
{
kbd_key_released( 2, 0 );
}
break;
case HPKEY_6:
{
kbd_key_released( 2, 1 );
}
break;
case HPKEY_5:
{
kbd_key_released( 2, 2 );
}
break;
case HPKEY_4:
{
kbd_key_released( 2, 3 );
}
break;
case HPKEY_MTH:
{
kbd_key_released( 2, 4 );
}
break;
case HPKEY_SHL:
{
kbd_key_released( 2, 5 );
}
break;
case HPKEY_DIV:
{
kbd_key_released( 3, 0 );
}
break;
case HPKEY_9:
{
kbd_key_released( 3, 1 );
}
break;
case HPKEY_8:
{
kbd_key_released( 3, 2 );
}
break;
case HPKEY_7:
{
kbd_key_released( 3, 3 );
}
break;
case HPKEY_SIN:
{
kbd_key_released( 3, 4 );
}
break;
case HPKEY_ALPHA:
{
kbd_key_released( 3, 5 );
}
break;
case HPKEY_BS:
{
kbd_key_released( 4, 0 );
}
break;
case HPKEY_DEL:
{
kbd_key_released( 4, 1 );
}
break;
case HPKEY_EEX:
{
kbd_key_released( 4, 2 );
}
break;
case HPKEY_NEG:
{
kbd_key_released( 4, 3 );
}
break;
case HPKEY_ENTER:
{
kbd_key_released( 4, 4 );
}
break;
case HPKEY_INV:
{
kbd_key_released( 5, 0 );
}
break;
case HPKEY_POWER:
{
kbd_key_released( 5, 1 );
}
break;
case HPKEY_SQRT:
{
kbd_key_released( 5, 2 );
}
break;
case HPKEY_TAN:
{
kbd_key_released( 5, 3 );
}
break;
case HPKEY_COS:
{
kbd_key_released( 5, 4 );
}
break;
case HPKEY_RIGHT:
{
kbd_key_released( 6, 0 );
}
break;
case HPKEY_DOWN:
{
kbd_key_released( 6, 1 );
}
break;
case HPKEY_LEFT:
{
kbd_key_released( 6, 2 );
}
break;
case HPKEY_EVAL:
{
kbd_key_released( 6, 3 );
}
break;
case HPKEY_STO:
{
kbd_key_released( 6, 4 );
}
break;
case HPKEY_NXT:
{
kbd_key_released( 7, 0 );
}
break;
case HPKEY_UP:
{
kbd_key_released( 7, 1 );
}
break;
case HPKEY_VAR:
{
kbd_key_released( 7, 2 );
}
break;
case HPKEY_CST:
{
kbd_key_released( 7, 3 );
}
break;
case HPKEY_PRG:
{
kbd_key_released( 7, 4 );
}
break;
case HPKEY_F:
{
kbd_key_released( 8, 0 );
}
break;
case HPKEY_E:
{
kbd_key_released( 8, 1 );
}
break;
case HPKEY_D:
{
kbd_key_released( 8, 2 );
}
break;
case HPKEY_C:
{
kbd_key_released( 8, 3 );
}
break;
case HPKEY_B:
{
kbd_key_released( 8, 4 );
}
break;
}
} }
void press_LoadFile( void ) {}
void release_LoadFile( void ) { load_file_on_stack( "zeldahp.dir" ); }

View file

@ -3,111 +3,74 @@
#include <stdbool.h> #include <stdbool.h>
// Keys
#define HPKEY_A 0
#define HPKEY_B 1
#define HPKEY_C 2
#define HPKEY_D 3
#define HPKEY_E 4
#define HPKEY_F 5
#define HPKEY_MTH 6
#define HPKEY_PRG 7
#define HPKEY_CST 8
#define HPKEY_VAR 9
#define HPKEY_UP 10
#define HPKEY_NXT 11
#define HPKEY_QUOTE 12
#define HPKEY_STO 13
#define HPKEY_EVAL 14
#define HPKEY_LEFT 15
#define HPKEY_DOWN 16
#define HPKEY_RIGHT 17
#define HPKEY_SIN 18
#define HPKEY_COS 19
#define HPKEY_TAN 20
#define HPKEY_SQRT 21
#define HPKEY_POWER 22
#define HPKEY_INV 23
#define HPKEY_ENTER 24
#define HPKEY_NEG 25
#define HPKEY_EEX 26
#define HPKEY_DEL 27
#define HPKEY_BS 28
#define HPKEY_ALPHA 29
#define HPKEY_7 30
#define HPKEY_8 31
#define HPKEY_9 32
#define HPKEY_DIV 33
#define HPKEY_SHL 34
#define HPKEY_4 35
#define HPKEY_5 36
#define HPKEY_6 37
#define HPKEY_MUL 38
#define HPKEY_SHR 39
#define HPKEY_1 40
#define HPKEY_2 41
#define HPKEY_3 42
#define HPKEY_MINUS 43
#define HPKEY_ON 44
#define HPKEY_0 45
#define HPKEY_PERIOD 46
#define HPKEY_SPC 47
#define HPKEY_PLUS 48
#define FIRST_HPKEY HPKEY_A
#define LAST_HPKEY HPKEY_PLUS
#define NB_KEYS ( LAST_HPKEY + 1 )
extern bool kbd_on; extern bool kbd_on;
extern void kbd_out_changed( void ); extern void kbd_out_changed( void );
extern void kbd_key_pressed( int row, int col );
extern void kbd_key_released( int row, int col );
extern void press_PLUS( void ); extern void press_key( int hpkey );
extern void release_PLUS( void ); extern void release_key( int hpkey );
extern void press_SPC( void );
extern void release_SPC( void );
extern void press_PERIOD( void );
extern void release_PERIOD( void );
extern void press_0( void );
extern void release_0( void );
extern void press_QUOTE( void );
extern void release_QUOTE( void );
extern void press_MINUS( void );
extern void release_MINUS( void );
extern void press_3( void );
extern void release_3( void );
extern void press_2( void );
extern void release_2( void );
extern void press_1( void );
extern void release_1( void );
extern void press_A( void );
extern void release_A( void );
extern void press_RSHIFT( void );
extern void release_RSHIFT( void );
extern void press_MULT( void );
extern void release_MULT( void );
extern void press_6( void );
extern void release_6( void );
extern void press_5( void );
extern void release_5( void );
extern void press_4( void );
extern void release_4( void );
extern void press_MTH( void );
extern void release_MTH( void );
extern void press_LSHIFT( void );
extern void release_LSHIFT( void );
extern void press_DIV( void );
extern void release_DIV( void );
extern void press_9( void );
extern void release_9( void );
extern void press_8( void );
extern void release_8( void );
extern void press_7( void );
extern void release_7( void );
extern void press_SIN( void );
extern void release_SIN( void );
extern void press_ALPHA( void );
extern void release_ALPHA( void );
extern void press_BKSP( void );
extern void release_BKSP( void );
extern void press_DEL( void );
extern void release_DEL( void );
extern void press_EEX( void );
extern void release_EEX( void );
extern void press_NEG( void );
extern void release_NEG( void );
extern void press_ENTER( void );
extern void release_ENTER( void );
extern void press_INV( void );
extern void release_INV( void );
extern void press_POW( void );
extern void release_POW( void );
extern void press_SQRT( void );
extern void release_SQRT( void );
extern void press_TAN( void );
extern void release_TAN( void );
extern void press_COS( void );
extern void release_COS( void );
extern void press_RIGHT( void );
extern void release_RIGHT( void );
extern void press_DOWN( void );
extern void release_DOWN( void );
extern void press_LEFT( void );
extern void release_LEFT( void );
extern void press_EVAL( void );
extern void release_EVAL( void );
extern void press_STO( void );
extern void release_STO( void );
extern void press_NXT( void );
extern void release_NXT( void );
extern void press_UP( void );
extern void release_UP( void );
extern void press_VAR( void );
extern void release_VAR( void );
extern void press_CST( void );
extern void release_CST( void );
extern void press_PRG( void );
extern void release_PRG( void );
extern void press_F( void );
extern void release_F( void );
extern void press_E( void );
extern void release_E( void );
extern void press_D( void );
extern void release_D( void );
extern void press_C( void );
extern void release_C( void );
extern void press_B( void );
extern void release_B( void );
extern void press_ON( void );
extern void release_ON( void );
extern void press_LoadFile( void );
extern void release_LoadFile( void );
#endif #endif