First commit! Version 3.2
This commit is contained in:
commit
c036d750c3
|
@ -0,0 +1,272 @@
|
|||
#include "EasyInput.h"
|
||||
|
||||
char *EI_input_string(int string_length, const char *chars_allowed)
|
||||
{
|
||||
char *string = (void*)(0);
|
||||
EI_config *config = (void*)(0);
|
||||
EI_cursor_settings cursor_settings;
|
||||
|
||||
unsigned int key = 0;
|
||||
|
||||
int i;
|
||||
int char_deleted = 0;
|
||||
int text_displacement = 0;
|
||||
int cap = 0;
|
||||
|
||||
char arrow[] = {0xE6, 0x9A, 0};
|
||||
|
||||
|
||||
// Get actual configuration
|
||||
config = (EI_config*)EI_manage_config(EI_GET_ALL, 0);
|
||||
|
||||
// Allocate RAM for string
|
||||
string = (char*)malloc(sizeof(char) * string_length + 1);
|
||||
|
||||
// Initialize string
|
||||
for(i = 0; i <= string_length; i++) string[i] = 0;
|
||||
|
||||
// Setup cursor flash
|
||||
switch(config->align)
|
||||
{
|
||||
default:
|
||||
case EI_ALIGN_LEFT:
|
||||
EI_Cursor_SetPosition(config->column, config->row);
|
||||
break;
|
||||
|
||||
case EI_ALIGN_CENTER:
|
||||
EI_Cursor_SetPosition(config->column + (config->box_length >> 1), config->row);
|
||||
break;
|
||||
|
||||
case EI_ALIGN_RIGHT:
|
||||
EI_Cursor_SetPosition(config->column + config->box_length - 1, config->row);
|
||||
break;
|
||||
}
|
||||
|
||||
if(config->start_mode == EI_ALPHA_LOCKED)
|
||||
{
|
||||
EI_KBD_PutKey(KEY_CTRL_SHIFT, 0);
|
||||
GetKey(&key);
|
||||
}
|
||||
|
||||
if(config->start_mode >= EI_ALPHA)
|
||||
{
|
||||
EI_KBD_PutKey(KEY_CTRL_ALPHA, 0);
|
||||
GetKey(&key);
|
||||
EI_Cursor_SetFlashOn(3);
|
||||
}
|
||||
else
|
||||
{
|
||||
EI_Cursor_SetFlashOn(0);
|
||||
}
|
||||
|
||||
|
||||
// Main loop
|
||||
i = 0;
|
||||
while(key != KEY_CTRL_EXE && key != KEY_CTRL_AC)
|
||||
{
|
||||
EI_Cursor_GetSettings(&cursor_settings);
|
||||
|
||||
if(cursor_settings.flashstyle == 3 && !cap)
|
||||
EI_Cursor_SetFlashOn(4);
|
||||
|
||||
GetKey(&key); // Getting key pressed
|
||||
|
||||
switch(key) // Analyse key pressed
|
||||
{
|
||||
case KEY_CTRL_F1:
|
||||
cap = !cap;
|
||||
break;
|
||||
|
||||
case KEY_CTRL_DEL:
|
||||
if(i > 0)
|
||||
{
|
||||
i--;
|
||||
string[i] = 0;
|
||||
char_deleted = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Give correct value to keys with a non-ascii return values
|
||||
if(key == KEY_CHAR_PLUS) key = '+';
|
||||
if(key == KEY_CHAR_MINUS || key == KEY_CHAR_PMINUS) key = '-';
|
||||
if(key == KEY_CHAR_MULT) key = '*';
|
||||
if(key == KEY_CHAR_DIV) key = '/';
|
||||
if(key == KEY_CHAR_ANS) key = '_';
|
||||
if(key == KEY_CTRL_XTT) key = '#';
|
||||
|
||||
if(key > 127) // KEY_CTRL_***, etc.
|
||||
break;
|
||||
|
||||
if(key >= 'A' && key <= 'Z') key += !cap * 32; // Switch between caps
|
||||
|
||||
if(EI_check_char(key, chars_allowed) && EI_str_length(string) != string_length) // Add char if we can
|
||||
{
|
||||
string[i] = key;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
switch(config->align) // Print string
|
||||
{
|
||||
default:
|
||||
case EI_ALIGN_LEFT:
|
||||
if(EI_str_length(string) < config->box_length)
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column, config->row);
|
||||
Print((unsigned char*)string);
|
||||
if(char_deleted && EI_str_length(string) != config->box_length - 1)
|
||||
{
|
||||
Print((unsigned char*)" ");
|
||||
EI_Cursor_SetPosition(cursor_settings.column - 2, config->row);
|
||||
char_deleted = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column, config->row);
|
||||
Print((unsigned char*)arrow);
|
||||
Print((unsigned char*)(string + EI_str_length(string) - config->box_length + 2));
|
||||
}
|
||||
break;
|
||||
|
||||
case EI_ALIGN_CENTER:
|
||||
if(EI_str_length(string) < config->box_length)
|
||||
{
|
||||
if(char_deleted && EI_str_length(string) != config->box_length - 1 && (config->box_length - EI_str_length(string)) >> 1 != ((config->box_length - EI_str_length(string) - 1) >> 1))
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column + ((config->box_length - EI_str_length(string)) >> 1) - 1, config->row);
|
||||
Print((unsigned char*)" ");
|
||||
Print((unsigned char*)string);
|
||||
char_deleted = 0;
|
||||
}
|
||||
else if(char_deleted && EI_str_length(string) != config->box_length - 1 && (config->box_length - EI_str_length(string)) >> 1 == ((config->box_length - EI_str_length(string) - 1) >> 1))
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column + ((config->box_length - EI_str_length(string)) >> 1), config->row);
|
||||
Print((unsigned char*)string);
|
||||
Print((unsigned char*)" ");
|
||||
EI_Cursor_SetPosition(cursor_settings.column - 2, config->row);
|
||||
char_deleted = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column + ((config->box_length - EI_str_length(string)) >> 1), config->row);
|
||||
Print((unsigned char*)string);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column, config->row);
|
||||
Print((unsigned char*)arrow);
|
||||
Print((unsigned char*)(string + EI_str_length(string) - config->box_length + 2));
|
||||
}
|
||||
break;
|
||||
|
||||
case EI_ALIGN_RIGHT:
|
||||
if(EI_str_length(string) < config->box_length)
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column + config->box_length - EI_str_length(string) - (char_deleted && EI_str_length(string) != config->box_length - 1) - 1, config->row);
|
||||
if(char_deleted && EI_str_length(string) != config->box_length - 1)
|
||||
{
|
||||
Print((unsigned char*)" ");
|
||||
char_deleted = 0;
|
||||
}
|
||||
Print((unsigned char*)string);
|
||||
}
|
||||
else
|
||||
{
|
||||
EI_Cursor_SetPosition(config->column, config->row);
|
||||
Print((unsigned char*)arrow);
|
||||
Print((unsigned char*)(string + EI_str_length(string) - config->box_length + 2));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Set off cursor mode
|
||||
EI_Cursor_SetFlashOff();
|
||||
|
||||
|
||||
// Return NULL in case of an input break
|
||||
if(key == KEY_CTRL_AC)
|
||||
{
|
||||
free(string);
|
||||
return (char*)(0);
|
||||
}
|
||||
|
||||
|
||||
// Return the string
|
||||
return string;
|
||||
}
|
||||
|
||||
const void *EI_manage_config(int parameter, int value)
|
||||
{
|
||||
static EI_config config;
|
||||
|
||||
if(value)
|
||||
{
|
||||
switch(parameter)
|
||||
{
|
||||
case EI_SET_COLUMN: config.column = value - 1;
|
||||
break;
|
||||
case EI_SET_ROW: config.row = value - 1;
|
||||
break;
|
||||
case EI_SET_BOX_LENGTH: config.box_length = (value < 3 ? 3 : value); // Minimal size is 3
|
||||
break;
|
||||
case EI_SET_ALIGN: config.align = value;
|
||||
break;
|
||||
case EI_SET_START_MODE: config.start_mode = value;
|
||||
break;
|
||||
case EI_SET_Aa_KEY: config.Aa_key = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(parameter)
|
||||
{
|
||||
case EI_GET_ALL: return (const void*)(&config);
|
||||
case EI_SET_COLUMN: return (const void*)&config.column;
|
||||
case EI_SET_ROW: return (const void*)&config.row;
|
||||
case EI_SET_BOX_LENGTH: return (const void*)&config.box_length;
|
||||
case EI_SET_ALIGN: return (const void*)&config.align;
|
||||
case EI_SET_START_MODE: return (const void*)&config.start_mode;
|
||||
case EI_SET_Aa_KEY: return (const void*)&config.Aa_key;
|
||||
}
|
||||
}
|
||||
|
||||
return (void*)(0);
|
||||
}
|
||||
|
||||
void EI_init(void)
|
||||
{
|
||||
EI_manage_config(EI_SET_COLUMN, 1);
|
||||
EI_manage_config(EI_SET_ROW, 1);
|
||||
EI_manage_config(EI_SET_ALIGN, EI_ALIGN_LEFT);
|
||||
EI_manage_config(EI_SET_START_MODE, EI_ALPHA_LOCKED);
|
||||
EI_manage_config(EI_SET_BOX_LENGTH, 21);
|
||||
EI_manage_config(EI_SET_Aa_KEY, KEY_CTRL_F1);
|
||||
}
|
||||
|
||||
int EI_str_length(const char *str)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while(str[i]) i++;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
int EI_check_char(char c, const char *chars_allowed)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
while(chars_allowed[i])
|
||||
{
|
||||
if(c == chars_allowed[i])
|
||||
return 1;
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
#ifndef _EASYINPUT
|
||||
#define _EASYINPUT
|
||||
|
||||
#include "fxlib.h"
|
||||
|
||||
enum
|
||||
{
|
||||
EI_NORMAL = 1,
|
||||
EI_ALPHA,
|
||||
EI_ALPHA_LOCKED
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
EI_ALIGN_LEFT = 1,
|
||||
EI_ALIGN_CENTER,
|
||||
EI_ALIGN_RIGHT
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
EI_GET_ALL = -1,
|
||||
EI_SET_COLUMN,
|
||||
EI_SET_ROW,
|
||||
EI_SET_BOX_LENGTH,
|
||||
EI_SET_ALIGN,
|
||||
EI_SET_START_MODE,
|
||||
EI_SET_Aa_KEY
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned int column;
|
||||
unsigned int row;
|
||||
unsigned int box_length;
|
||||
unsigned int align;
|
||||
unsigned int start_mode;
|
||||
unsigned int Aa_key;
|
||||
} EI_config;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int flashstyle; // -1 if not flashing, else flashmode
|
||||
int column; // starts at 1
|
||||
int row; // starts at 1
|
||||
int graphic_mode;
|
||||
} EI_cursor_settings;
|
||||
|
||||
|
||||
char *EI_input_string(int string_length, const char *chars_allowed);
|
||||
const void *EI_manage_config(int parameter, int value);
|
||||
void EI_init(void);
|
||||
int EI_str_length(const char *str);
|
||||
int EI_check_char(char c, const char* chars_allowed);
|
||||
|
||||
void EI_KBD_PutKey(unsigned int keycode, int mode);
|
||||
int EI_Cursor_SetPosition(char column, char row);
|
||||
int EI_Cursor_SetFlashOn(char flashstyle);
|
||||
void EI_Cursor_SetFlashOff(void);
|
||||
int EI_Cursor_GetSettings(EI_cursor_settings *cursor_settings);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,47 @@
|
|||
|
||||
.global _EI_KBD_PutKey
|
||||
.type _EI_KBD_PutKey, @function
|
||||
_EI_KBD_PutKey:
|
||||
mov.l sc_addr, r2
|
||||
mov.l 1f, r0
|
||||
jmp @r2
|
||||
nop
|
||||
1: .long 0x910
|
||||
|
||||
.global _EI_Cursor_SetPosition
|
||||
.type _EI_Cursor_SetPosition, @function
|
||||
_EI_Cursor_SetPosition:
|
||||
mov.l sc_addr, r2
|
||||
mov.l 2f, r0
|
||||
jmp @r2
|
||||
nop
|
||||
2: .long 0x138
|
||||
|
||||
.global _EI_Cursor_SetFlashOn
|
||||
.type _EI_Cursor_SetFlashOn, @function
|
||||
_EI_Cursor_SetFlashStyle:
|
||||
mov.l sc_addr, r2
|
||||
mov.l 3f, r0
|
||||
jmp @r2
|
||||
nop
|
||||
3: .long 0x811
|
||||
|
||||
.global _EI_Cursor_SetFlashOff
|
||||
.type _EI_Cursor_SetFlashOff, @function
|
||||
_EI_Cursor_SetFlashOff:
|
||||
mov.l sc_addr, r2
|
||||
mov.l 5f, r0
|
||||
jmp @r2
|
||||
nop
|
||||
4: .long 0x812
|
||||
|
||||
.global _EI_Cursor_GetSettings
|
||||
.type _EI_Cursor_GetSettings, @function
|
||||
_EI_Cursor_SetFlashOff:
|
||||
mov.l sc_addr, r2
|
||||
mov.l 5f, r0
|
||||
jmp @r2
|
||||
nop
|
||||
5: .long 0x80F
|
||||
|
||||
sc_addr: .long 0x80010070
|
|
@ -0,0 +1,18 @@
|
|||
.SECTION P,CODE,ALIGN=4
|
||||
|
||||
.MACRO SYSCALL FUNO, SYSCALLNAME, TAIL=nop
|
||||
.export \SYSCALLNAME'
|
||||
\SYSCALLNAME'
|
||||
mov.l #h'\FUNO, r0
|
||||
mov.l #H'80010070, r2
|
||||
jmp @r2
|
||||
\TAIL'
|
||||
.ENDM
|
||||
|
||||
SYSCALL 0910, _EI_KBD_PutKey
|
||||
SYSCALL 0138, _EI_Cursor_SetPosition
|
||||
SYSCALL 0811, _EI_Cursor_SetFlashOn
|
||||
SYSCALL 0812, _EI_Cursor_SetFlashOff
|
||||
SYSCALL 080F, _EI_Cursor_GetSettings
|
||||
|
||||
.end
|
|
@ -0,0 +1,82 @@
|
|||
##### INFORMATIONS IMPORTANTES #####
|
||||
Nom : EasyInput
|
||||
Auteur : Dark Storm (L.GATIN)
|
||||
Dernière mise à jour : 16/02/2015
|
||||
Version : 3.2
|
||||
Licence : GNU General Public License
|
||||
####################################
|
||||
|
||||
|
||||
##### Présentation #####
|
||||
|
||||
EasyInput est une librairie de fonctions destinée à simplifier les méthodes de saisie de texte par un utilisateur.
|
||||
Elle est utilisable gratuitement, vous pouvez la télécharger sur http://www.planete-casio.fr, rubrique "Logiciels" puis "Snippets".
|
||||
|
||||
|
||||
##### Utilisation #####
|
||||
--- Fichiers ---
|
||||
Quoi qu'il arrive, vous avez besoin des fichiers <EasyInput.c> et <EasyInput.h>
|
||||
Selon votre compilateur, il vous faut chosir le bon fichier de syscalls :
|
||||
- Pour le Fx9860 SDK : gardez le fichier <EasyInput_.src>
|
||||
- Pour GCC : gardez le fichier <EasyInput_.s>
|
||||
|
||||
--- Initialisation ---
|
||||
Utilisez EI_init() pour mettre toutes les valeurs de configuration par défaut.
|
||||
Ensuite, vous pouvez modifier les paramètres suivants en appelant la fonction EI_manage_config(int parameter, int value) :
|
||||
EI_SET_COLUMN : Un nombre entre 1 et 21 qui correspond à la colonne de début de la zone de texte ;
|
||||
EI_SET_ROW : Idem, mais entre 1 et 8 pour les lignes ;
|
||||
EI_SET_BOX_LENGTH : La longueur de la zone de texte, en caractères, une valeur minimale de 3 est requise pour un bon fonctionnement ;
|
||||
EI_SET_ALIGN : Le mode d'alignement du texte (EI_LEFT, EI_CENTER, EI_RIGHT) ;
|
||||
EI_SET_START_MODE : Le mode de départ du curseur (EI_NORMAL, EI_ALPHA, EI_ALPHA_LOCKED) ;
|
||||
EI_SET_Aa_KEY : Le code de la touche qui servira à changer la casse.
|
||||
Exemple, pour fixer le mode de départ du curseur : EI_manage_config(EI_SET_START_MODE, EI_ALPHA);
|
||||
Si <value> est égale à 0, la fonction retourne un pointeur sur l'élément demandé. Cela permet de récupérer les valeurs de configuration.
|
||||
Exemple, récupérer la valeur de la longueur de la box : longueur = EI_manage_config(EI_SET_LENGHT_BOX, 0);
|
||||
|
||||
--- Appel ---
|
||||
La fonction EI_input_string(int string_length, const char *chars_allowed) retourne un pointeur sur la chaine et doit être appellée de la manière suivante :
|
||||
char *my_string = NULL;
|
||||
my_string = EI_input_string(21, (const char*)".0123456789");
|
||||
La chaine <chars_allowed> contient tout les caractères dont la saisie est autorisée.
|
||||
|
||||
--- Annexes ---
|
||||
Retrouvez plus d'informations ici : http://www.planet-casio.com/Fr/forums/lecture_sujet.php?id=12979
|
||||
|
||||
|
||||
##### CHANGELOG #####
|
||||
--- V3.2 ---
|
||||
- Ajout des caractères `+`, `-`, `*`, `/`, `_`, `#` à la liste de ceux traités.
|
||||
|
||||
--- V3.1 ---
|
||||
- Simplification du système de configuration
|
||||
|
||||
--- V3.0 ---
|
||||
- Réécriture de la boucle principale
|
||||
- Correction des bugs concernant les syscalls à destination de l'OS 2.00 et ultérieur (merci à Nemhardy pour l'info)
|
||||
- Correction des bugs concernant les ajouts de caractères impromptus
|
||||
- Correction des bugs concernant les alignements de texte
|
||||
|
||||
--- V2.3 ---
|
||||
- Refonte du système d'affichage
|
||||
|
||||
--- V2.2 ---
|
||||
- Refonte du système de configuration
|
||||
- Ajout de la gestion des minuscules
|
||||
|
||||
--- V2.1 ---
|
||||
- Ajout de la "regex" pour les caractères autorisés
|
||||
- Correction d'une fuite de mémoire lorsque l'on quitte avec Ac/ON
|
||||
- Passage sous license GNU GPL
|
||||
|
||||
--- V2.0 ---
|
||||
- Modification du mode de retour de la chaine
|
||||
|
||||
--- V1.2 ---
|
||||
- Correction de quelques bugs
|
||||
|
||||
--- V1.1 ---
|
||||
- Correction de bugs
|
||||
- Optimisation de l'entrée
|
||||
|
||||
--- V1.0 ---
|
||||
- Création de la librairie
|
Loading…
Reference in New Issue