cake
/
libcasio
Archived
1
1
Fork 0

Starting implementing setup.

This commit is contained in:
Thomas Touhey 2017-06-21 19:37:13 +02:00
parent a774fa21ea
commit 9cc56194fe
22 changed files with 846 additions and 159 deletions

View File

@ -106,7 +106,6 @@ typedef void casio_link_list_t OF((void *casio__cookie,
# define CASIO_LINKFLAG_TERM 0x00000004 /* terminate */
# define CASIO_LINKFLAG_NODISC 0x00000008 /* if we are checking,
* no environment discovery */
CASIO_BEGIN_DECLS
/* Cross-platform initialization. */
@ -123,14 +122,24 @@ CASIO_EXTERN int CASIO_EXPORT casio_open_link
unsigned long casio__flags, casio_stream_t *casio__stream,
const casio_streamattrs_t *casio__attributes));
/* Get things. */
/* De-initialize. */
CASIO_EXTERN void CASIO_EXPORT casio_close_link
OF((casio_link_t *casio__h));
/* Lock and unlock the associated mutex. */
CASIO_EXTERN int CASIO_EXPORT casio_lock_link
OF((casio_link_t *casio__h));
CASIO_EXTERN int CASIO_EXPORT casio_trylock_link
OF((casio_link_t *casio__h));
CASIO_EXTERN void CASIO_EXPORT casio_unlock_link
OF((casio_link_t *casio__h));
/* Getters. */
CASIO_EXTERN const casio_link_info_t* CASIO_EXPORT casio_get_link_info
OF((casio_link_t *casio__handle));
/* De-initialize. */
CASIO_EXTERN void CASIO_EXPORT casio_close_link
OF((casio_link_t *casio__h));
/* ************************************************************************* */
/* Run servers. */
/* ************************************************************************* */

View File

@ -21,6 +21,7 @@
# include "cdefs.h"
# include "number.h"
# include "picture.h"
# include "setup.h"
# define casio_theta 27
# define casio_r 28
@ -163,82 +164,6 @@ typedef struct casio_mcscell_s {
casio_bcd_t casio_mcscell_imgn;
} casio_mcscell_t;
/* ************************************************************************* */
/* Setup */
/* ************************************************************************* */
/* The real setup from the calculator is either a group of 100/200 entries,
* or a string-byte map (e.g. "Axes" -> 0x01). This structure reduces this
* big bulky thing to a single usable structure.
*
* There are different type of flags and options.
* First, the input flags. */
# define casio_setupiflag_shift 0x0001 /* SHIFT is pressed */
# define casio_setupiflag_alpha 0x0002 /* ALPHA is pressed */
# define casio_setupiflag_insert 0x0004 /* Insert/overwrite mode */
# define casio_setupiflag_math 0x0008 /* Math input mode, not linear */
/* Then, the window flags. */
# define casio_setupwflag_grid 0x0001 /* Grid */
# define casio_setupwflag_axes 0x0002 /* Axes */
# define casio_setupwflag_plot 0x0004 /* Draw Plot Type instead of Con */
# define casio_setupwflag_coord 0x0010 /* Coord */
# define casio_setupwflag_sigma 0x0020 /* Sigma Display */
# define casio_setupwflag_stat 0x0040 /* Stat Window */
# define casio_setupwflag_graph 0x0080 /* Graph Function */
# define casio_setupwflag_simul 0x0100 /* Simul Graph */
# define casio_setupwflag_slope 0x0200 /* Slope */
/* Then, miscallaneous flags. */
# define casio_setupmflag_deriv 0x0001 /* Derivative */
# define casio_setupmflag_label 0x0002 /* label */
# define casio_setupmflag_date360 0x0004 /* 360 Date Mode, instead of 365 */
# define casio_setupmflag_complex 0x0008 /* Complex answer instead of real */
# define casio_setupmflag_simp 0x0010 /* Auto Simplify (not Manual) */
# define casio_setupmflag_dynamic 0x0020 /* Continue Dynamic Type
* (not Stop) */
# define casio_setupmflag_payment 0x0040 /* Begin Payment (not End) */
# define casio_setupmflag_autocalc 0x0080 /* Auto Calc */
# define casio_setupmflag_cformula 0x0100 /* Show Cell Formula (not Value) */
# define casio_setupmflag_dpfix 0x1000 /* Display Fix instead of Sci */
# define casio_setupmflag_dpnorm 0x2000 /* Display Norm */
# define casio_setupmflag_dpemode 0x4000 /* Toggle /E-mode */
/* Here are some values that cannot be reduced to simple flags.
* It works just as the `c_cc` member in termios, where `NCCS` is
* `casio_setup_nvals`. */
# define casio_setup_nvals 6
# define casio_setupval_number 0 /* 0 being comp, 2,8,10,16 being
* the base */
# define casio_setupval_function 1 /* -> 0x18 */
# define casio_setupval_listfile 2 /* List File 1-6, 0 being none */
# define casio_setupval_bg 3 /* Background picture ID, 0 being none */
# define casio_setupval_dispid 4 /* Display ID, see dpfix/dpnorm/dpemode */
# define casio_setupval_residlist 5 /* Resid List */
/* Here are the function types you can encounter/use.
* TODO: why are they here? */
# define casio_functype_yequ 0 /* Y= */
# define casio_functype_requ 1 /* r= */
# define casio_functype_param 2 /* Param */
# define casio_functype_xequc 3 /* X=c */
# define casio_functype_ygt 4 /* Y> */
# define casio_functype_ylt 5 /* Y< */
# define casio_functype_yge 6 /* Y>= */
# define casio_functype_yle 7 /* Y<= */
/* Main structure */
typedef struct casio_setup_s {
unsigned int casio_setup_iflags;
unsigned int casio_setup_wflags;
unsigned int casio_setup_mflags;
unsigned char casio_setup_vals[casio_setup_nvals];
} casio_setup_t;
/* ************************************************************************* */
/* Main memory file head */
/* ************************************************************************* */
/* Filenames and directory names are not the only things which characterize

View File

@ -22,15 +22,15 @@
typedef int casio_mutex_t;
CASIO_EXTERN void CASIO_EXPORT casio_init_mutex
CASIO_EXTERN void CASIO_EXPORT casio_init_lock
OF((casio_mutex_t *casio__mutex));
CASIO_EXTERN int CASIO_EXPORT casio_lock_mutex
CASIO_EXTERN int CASIO_EXPORT casio_lock
OF((casio_mutex_t *casio__mutex));
CASIO_EXTERN int CASIO_EXPORT casio_trylock_mutex
CASIO_EXTERN int CASIO_EXPORT casio_trylock
OF((casio_mutex_t *casio__mutex));
CASIO_EXTERN void CASIO_EXPORT casio_unlock_mutex
CASIO_EXTERN void CASIO_EXPORT casio_unlock
OF((casio_mutex_t *casio__mutex));
#endif /* LIBCASIO_MUTEX_H */

View File

@ -112,6 +112,14 @@ CASIO_EXTERN int CASIO_EXPORT casio_seven_send_cmdsys_setlink
/* Send one file's information */
# define casio_seven_cmdmcs_fileinfo 0x2E
/* Send a setup entry */
# define casio_seven_cmdmcs_putsetup 0x32
/* Request all setup entries. */
# define casio_seven_cmdmcs_reqallsetup 0x33
# define casio_seven_send_cmdmcs_reqallsetup(CASIO__HANDLE) \
casio_seven_send_cmd(CASIO__HANDLE, 0x33)
/* ************************************************************************* */
/* Storage commands */
/* ************************************************************************* */

135
include/libcasio/setup.h Normal file
View File

@ -0,0 +1,135 @@
/* ****************************************************************************
* libcasio/setup.h -- main memory setup.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_SETUP_H
# define LIBCASIO_SETUP_H
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
/* ************************************************************************* */
/* Description */
/* ************************************************************************* */
/* The real setup from the calculator is either a group of 100/200 byte
* register, or a string-byte map (e.g. "Axes" -> 0x01).
* This structure reduces this big bulky thing to a single usable structure.
*
* There are different type of flags and options.
* First, the input flags. */
# define casio_setupiflag_shift 0x0001 /* SHIFT is pressed */
# define casio_setupiflag_alpha 0x0002 /* ALPHA is pressed */
# define casio_setupiflag_insert 0x0004 /* Insert/overwrite mode */
# define casio_setupiflag_math 0x0008 /* Math input mode, not linear */
/* Then, the window flags. */
# define casio_setupwflag_grid 0x0001 /* Grid */
# define casio_setupwflag_axes 0x0002 /* Axes */
# define casio_setupwflag_coord 0x0010 /* Coord */
# define casio_setupwflag_sigma 0x0020 /* Sigma Display */
# define casio_setupwflag_stat 0x0040 /* Stat Window */
# define casio_setupwflag_graph 0x0080 /* Graph Function */
# define casio_setupwflag_simul 0x0100 /* Simul Graph */
# define casio_setupwflag_slope 0x0200 /* Slope */
/* Then, miscallaneous flags. */
# define casio_setupmflag_deriv 0x0001 /* Derivative */
# define casio_setupmflag_label 0x0002 /* label */
# define casio_setupmflag_date360 0x0004 /* 360 Date Mode, instead of 365 */
# define casio_setupmflag_complex 0x0008 /* Complex answer instead of real */
# define casio_setupmflag_simp 0x0010 /* Auto Simplify (not Manual) */
# define casio_setupmflag_dynamic 0x0020 /* Continue Dynamic Type
* (not Stop) */
# define casio_setupmflag_payment 0x0040 /* Begin Payment (not End) */
# define casio_setupmflag_autocalc 0x0080 /* Auto Calc */
# define casio_setupmflag_cformula 0x0100 /* Show Cell Formula (not Value) */
# define casio_setupmflag_dpfix 0x1000 /* Display Fix instead of Sci */
# define casio_setupmflag_dpnorm 0x2000 /* Display Norm */
# define casio_setupmflag_dpemode 0x4000 /* Toggle /E-mode */
/* Here are some values that cannot be reduced to simple flags.
* It works just as the `c_cc` member in termios, where `NCCS` is
* `casio_setup_nvals`. */
# define casio_setup_nvals 7
# define casio_setupval_number 0 /* 0 being comp, 2,8,10,16 being
* the base */
# define casio_setupval_function 1 /* function type */
# define casio_setupval_draw 2 /* draw type */
# define casio_setupval_listfile 3 /* List File 1-6, 0 being none */
# define casio_setupval_background 4 /* Background picture ID, 0 being none */
# define casio_setupval_dispid 5 /* Display ID, see dpfix/dpnorm/dpemode */
# define casio_setupval_residlist 6 /* Resid List */
/* Here are the function types you can encounter/use.
* TODO: why are they here? */
# define casio_functype_yequ 0 /* Y= */
# define casio_functype_requ 1 /* r= */
# define casio_functype_param 2 /* Param */
# define casio_functype_xequc 3 /* X=c */
# define casio_functype_ygt 4 /* Y> */
# define casio_functype_ylt 5 /* Y< */
# define casio_functype_yge 6 /* Y>= */
# define casio_functype_yle 7 /* Y<= */
/* Here are the draw types you can encounter/use. */
# define casio_drawtype_con 0
# define casio_drawtype_plot 1
/* Main structure */
typedef struct casio_setup_s {
unsigned int casio_setup_iflags;
unsigned int casio_setup_wflags;
unsigned int casio_setup_mflags;
unsigned char casio_setup_vals[casio_setup_nvals];
} casio_setup_t;
/* ************************************************************************* */
/* Methods */
/* ************************************************************************* */
CASIO_BEGIN_DECLS
/* Initialize the structure. */
CASIO_EXTERN void CASIO_EXPORT casio_init_setup
OF((casio_setup_t *casio__setup));
/* Feed the structure. */
CASIO_EXTERN int CASIO_EXPORT casio_feed_setup_seven
OF((casio_setup_t *casio__setup, const char *casio__name, int casio__val));
CASIO_EXTERN int CASIO_EXPORT casio_feed_setup_mcs
OF((casio_setup_t *casio__setup, int casio__id, int casio__val));
/* Export settings into a map. */
# if 0
typedef void casio_setup_export_t
OF((void *casio__cookie, const char *casio__name, int casio__value));
CASIO_EXTERN void CASIO_EXPORT casio_export_setup
OF((casio_setup_t *casio__setup, casio_setup_export_t *casio__export,
void *casio__cookie));
# endif
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_SETUP_H */

View File

@ -46,6 +46,9 @@ struct casio_link_s {
/* stream settings */
casio_stream_t *casio_link_stream;
/* lock */
casio_mutex_t casio_link_lock;
/* protocol 7.00-related core things */
casio_seven_env_t casio_link_env; /* see `protocol/seven/devices.c` */
casio_seven_packet_t casio_link_response;

57
src/link/lock.c Normal file
View File

@ -0,0 +1,57 @@
/* ****************************************************************************
* link/lock.c -- manage the link lock.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "link.h"
/**
* casio_lock_link:
* Lock a link.
*
* @arg handle the link handle to lock.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_lock_link(casio_link_t *handle)
{
return (casio_lock(&handle->casio_link_lock));
}
/**
* casio_trylock_link:
* Try to lock a link.
*
* @arg handle the link handle to lock.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_trylock_link(casio_link_t *handle)
{
return (casio_trylock(&handle->casio_link_lock));
}
/**
* casio_unlock_link:
* Unlock a link.
*
* @arg handle the link handle.
*/
void CASIO_EXPORT casio_unlock_link(casio_link_t *handle)
{
casio_unlock(&handle->casio_link_lock);
}

View File

@ -52,6 +52,7 @@ int CASIO_EXPORT casio_open_link(casio_link_t **h, unsigned long flags,
/* initialize handle */
handle = *h; memset(handle, 0, sizeof(casio_link_t)); /* important! */
casio_init_lock(&handle->casio_link_lock);
handle->casio_link_stream = stream;
/* initialize flags */

View File

@ -15,9 +15,14 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
*
* FIXME: add the special cases of setup and alpha memory.
* ************************************************************************* */
#include "seven_mcs.h"
/* ************************************************************************* */
/* Protocol 7.00 MCS file gathering */
/* ************************************************************************* */
struct thecookie {
int _called;
int _err;
@ -28,7 +33,7 @@ struct thecookie {
};
/**
* get_file:
* receive_file:
* Get the main memory file.
*
* @arg cookie the cookie (uncasted).
@ -36,7 +41,7 @@ struct thecookie {
* @return the error code (0 if ok).
*/
CASIO_LOCAL int get_file(struct thecookie *cookie, casio_link_t *handle)
CASIO_LOCAL int receive_file(struct thecookie *cookie, casio_link_t *handle)
{
casio_stream_t *data_stream = NULL;
casio_mcshead_t *head = cookie->_head;
@ -63,6 +68,182 @@ CASIO_LOCAL int get_file(struct thecookie *cookie, casio_link_t *handle)
return (casio_seven_send_ack(handle, 1));
}
/**
* get_setup_entry:
* Get a setup entry.
*
* @arg setup the setup to feed.
* @arg handle the link handle.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int get_setup_entry(casio_setup_t *setup, casio_link_t *handle)
{
if (response.casio_seven_packet_args[0]
&& response.casio_seven_packet_args[1]) {
unsigned int value = (unsigned int)casio_getascii(
(void*)response.casio_seven_packet_args[1], 2);
casio_feed_setup_seven(setup,
response.casio_seven_packet_args[0], value);
}
/* Once the setup has been fed, send the ACK. */
return (casio_seven_send_ack(handle, 1));
}
/* ************************************************************************* */
/* File request function */
/* ************************************************************************* */
/**
* request_file:
* Request a file.
*
* @arg cookie the interface cookie.
* @arg mcsfile the MCS file to get.
* @arg head the MCS head.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int request_file(sevenmcs_t *cookie,
casio_mcsfile_t **mcsfile, casio_mcshead_t *head)
{
int err; casio_link_t *handle = cookie->sevenmcs_link;
struct thecookie thecookie;
/* Send the command. */
msg((ll_info, "Sending the file request."));
err = casio_seven_send_cmd_data(handle,
casio_seven_cmdmcs_reqfile, 0, head->casio_mcshead_rawtype, 0,
head->casio_mcshead_dirname, head->casio_mcshead_name,
head->casio_mcshead_group, NULL, NULL, NULL);
if (err) return (err);
/* Check the answer. */
if (response.casio_seven_packet_type == casio_seven_type_nak
&& response.casio_seven_packet_code == casio_seven_err_other)
return (casio_error_notfound);
else if (response.casio_seven_packet_type != casio_seven_type_ack)
return (casio_error_unknown);
/* Prepare the cookie. */
thecookie._called = 0;
thecookie._err = 0;
thecookie._mcsfile = mcsfile;
thecookie._head = head;
thecookie._disp = NULL;
thecookie._disp_cookie = NULL;
msg((ll_info, "Running the server."));
err = casio_seven_serve(handle, handle->casio_link_seven_callbacks,
&thecookie);
if (err) return (err);
/* Check if the function was called. */
return (thecookie._called ? thecookie._err : casio_error_unknown);
}
/* ************************************************************************* */
/* Special types */
/* ************************************************************************* */
/**
* request_alphamem:
* Get the alpha memory.
*
* @arg cookie the interface cookie.
* @arg mcsfile the MCS file to get.
* @return the error code (0 if ok).
*/
CASIO_LOCAL const char *variable_names[] = {
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
/* theta */ "\xCE", /* r: */ "\xCD", /* Ans: */ "\xC0"};
CASIO_LOCAL int request_alphamem(sevenmcs_t *cookie, casio_mcsfile_t **mcsfile)
{
int err, i;
casio_mcscell_t *vars;
casio_mcshead_t varhead = {
casio_mcsfor_mcs, 0, 0,
1, 0, 0, 0,
0x00, 0, 0,
/* var name (will be completed in the loop): */ "", "",
/* group: */ "ALPHA MEM",
/* dirname: */ "$GLOBAL",
"", ""
};
/* Allocate the alpha memory file. */
err = casio_make_mcsfile(mcsfile, &casio_sevenmcs_list_alpha_entry);
if (err) return (err);
vars = (*mcsfile)->casio_mcsfile_vars;
/* Get each variable. */
for (i = 0; i < 29; i++) {
casio_mcsfile_t *varfile = NULL;
/* Request the variable file. */
strcpy(varhead.casio_mcshead_name, variable_names[i]);
msg((ll_info, "Requesting variable %d/29", i + 1));
err = request_file(cookie, &varfile, &varhead);
if (err) goto fail;
/* Copy the variable. */
memcpy(&vars[i], &varfile->casio_mcsfile_var, sizeof(casio_mcscell_t));
/* Free the file. */
casio_free_mcsfile(varfile);
}
return (0);
fail:
casio_free_mcsfile(*mcsfile);
*mcsfile = NULL;
return (err);
}
/**
* request_setup:
* Get the calculator settings.
*
* @arg cookie the interface cookie.
* @arg mcsfile the MCS file to get.
* @return the error code (0 if ok).
*/
CASIO_LOCAL int request_setup(sevenmcs_t *cookie, casio_mcsfile_t **mcsfile)
{
int err; casio_setup_t *setup;
casio_link_t *handle = cookie->sevenmcs_link;
/* Allocate the alpha memory file. */
err = casio_make_mcsfile(mcsfile, &casio_sevenmcs_list_setup_entry);
if (err) return (err);
setup = &(*mcsfile)->casio_mcsfile_setup;
/* Request all setup entries. */
err = casio_seven_send_cmdmcs_reqallsetup(handle);
if (err) goto fail;
/* Setup the server and go! */
handle->casio_link_seven_callbacks[casio_seven_cmdmcs_sendfile] = NULL;
handle->casio_link_seven_callbacks[casio_seven_cmdmcs_putsetup] =
(casio_seven_server_func_t*)&get_setup_entry;
/* Run the server. */
err = casio_seven_serve(handle, handle->casio_link_seven_callbacks,
setup);
if (err) goto fail;
/* We're done! */
return (0);
fail:
casio_free_mcsfile(*mcsfile);
*mcsfile = NULL;
return (err);
}
/* ************************************************************************* */
/* Main function */
/* ************************************************************************* */
/**
* casio_sevenmcs_get:
* Get a file from a Protocol 7.00 main memory interface.
@ -76,9 +257,17 @@ CASIO_LOCAL int get_file(struct thecookie *cookie, casio_link_t *handle)
int CASIO_EXPORT casio_sevenmcs_get(sevenmcs_t *cookie,
casio_mcsfile_t **mcsfile, casio_mcshead_t *mcshead)
{
int err; casio_mcshead_t head;
casio_mcshead_t head;
casio_link_t *handle = cookie->sevenmcs_link;
struct thecookie ccookie;
/* MCS file not gathered by default. */
*mcsfile = NULL;
/* Prepare the callbacks. */
memset(handle->casio_link_seven_callbacks, 0,
256 * sizeof(casio_seven_server_func_t*));
handle->casio_link_seven_callbacks[casio_seven_cmdmcs_sendfile] =
(casio_seven_server_func_t*)&receive_file;
/* Correct the head. */
msg((ll_info, "Correcting the head."));
@ -86,38 +275,18 @@ int CASIO_EXPORT casio_sevenmcs_get(sevenmcs_t *cookie,
if (casio_correct_mcshead(&head, casio_mcsfor_mcs))
return (casio_error_notfound);
/* Send the command. */
msg((ll_info, "Sending the file request."));
err = casio_seven_send_cmd_data(handle,
casio_seven_cmdmcs_reqfile, 0, head.casio_mcshead_rawtype, 0,
head.casio_mcshead_dirname, head.casio_mcshead_name,
head.casio_mcshead_group, NULL, NULL, NULL);
if (err) return (err);
/* Check if we ought to get the alpha memory.
* XXX: should we check the directory name? */
if (!strcmp(head.casio_mcshead_group, "ALPHA MEM")
&& !strcmp(head.casio_mcshead_name, "ALPHA MEM"))
return (request_alphamem(cookie, mcsfile));
/* Check the answer. */
if (response.casio_seven_packet_type == casio_seven_type_nak
&& response.casio_seven_packet_code == casio_seven_err_other)
return (casio_error_notfound);
else if (response.casio_seven_packet_type != casio_seven_type_ack)
return (casio_error_unknown);
/* Check if we ought to get the setup.
* XXX: should we check the directory name? */
if (!strcmp(head.casio_mcshead_group, "SETUP")
&& !strcmp(head.casio_mcshead_name, "SETUP"))
return (request_setup(cookie, mcsfile));
/* Prepare the cookie. */
ccookie._called = 0;
ccookie._err = 0;
ccookie._mcsfile = mcsfile;
ccookie._head = &head;
ccookie._disp = NULL;
ccookie._disp_cookie = NULL;
msg((ll_info, "Preparing the callbacks and running the server."));
memset(handle->casio_link_seven_callbacks, 0,
256 * sizeof(casio_seven_server_func_t*));
handle->casio_link_seven_callbacks[casio_seven_cmdmcs_sendfile] =
(casio_seven_server_func_t*)&get_file;
err = casio_seven_serve(handle, handle->casio_link_seven_callbacks,
&ccookie);
if (err) return (err);
/* Check if the function was called. */
return (ccookie._called ? ccookie._err : casio_error_unknown);
/* Request the file. */
return (request_file(cookie, mcsfile, &head));
}

View File

@ -40,24 +40,58 @@ CASIO_LOCAL int file_info(struct thecookie *cookie, casio_link_t *handle)
head.casio_mcshead_flags = casio_mcsfor_mcs;
head.casio_mcshead_size = response.casio_seven_packet_filesize;
head.casio_mcshead_rawtype = response.casio_seven_packet_mcstype;
strncpy(head.casio_mcshead_dirname,
response.casio_seven_packet_args[0], 8);
head.casio_mcshead_dirname[8] = 0;
strncpy(head.casio_mcshead_name,
response.casio_seven_packet_args[1], 12);
head.casio_mcshead_name[12] = 0;
strncpy(head.casio_mcshead_group,
response.casio_seven_packet_args[2], 16);
head.casio_mcshead_group[16] = 0;
if (response.casio_seven_packet_args[0]) {
strncpy(head.casio_mcshead_dirname,
response.casio_seven_packet_args[0], 8);
head.casio_mcshead_dirname[8] = 0;
} else head.casio_mcshead_dirname[0] = 0;
if (response.casio_seven_packet_args[1]) {
strncpy(head.casio_mcshead_name,
response.casio_seven_packet_args[1], 12);
head.casio_mcshead_name[12] = 0;
} else head.casio_mcshead_name[0] = 0;
if (response.casio_seven_packet_args[2]) {
strncpy(head.casio_mcshead_group,
response.casio_seven_packet_args[2], 16);
head.casio_mcshead_group[16] = 0;
} else head.casio_mcshead_group[0] = 0;
/* Try to make abstract information out of the raw information. */
casio_correct_mcshead(&head, 0);
/* Return this head to the user, and end the command response. */
(*cookie->_mcslist)(cookie->_mcookie, &head);
return (0);
/* If these are not special files we want to ignore,
* return this head to the user, and end the command response. */
if (!(head.casio_mcshead_type
& (casio_mcstype_alpha | casio_mcstype_setup)))
(*cookie->_mcslist)(cookie->_mcookie, &head);
/* Don't forget the ack! */
return (casio_seven_send_ack(handle, 1));
}
/* Alpha memory and settings are two special entries that are not explicitely
* listed and got/sent as files, we ought to make an abstraction powerful
* enough to treat them as they are. */
const casio_mcshead_t CASIO_EXPORT casio_sevenmcs_list_alpha_entry = {
0, casio_mcstype_alphamem, 0,
/* count: */ 29, 0, 0, 0,
/* rawtype: */ 0x00, 0, 0,
/* name: */ "ALPHA MEM", "",
/* group: */ "ALPHA MEM",
/* dirname: */ "$GLOBAL",
"", ""
};
const casio_mcshead_t CASIO_EXPORT casio_sevenmcs_list_setup_entry = {
0, casio_mcstype_setup, 0,
0, 0, 0, 100,
/* rawtype: */ 0x14, 0, 0,
/* name: */ "SETUP", "",
/* group: */ "SETUP",
/* dirname: */ "$GLOBAL",
"", ""
};
/**
* casio_sevenmcs_list:
* List a Protocol 7.00 MCS.
@ -84,6 +118,10 @@ int CASIO_EXPORT casio_sevenmcs_list(sevenmcs_t *cookie,
thecookie._mcslist = mcslist;
thecookie._mcookie = mcookie;
/* Call the callbacks with the default entries. */
(*mcslist)(mcookie, &casio_sevenmcs_list_alpha_entry);
(*mcslist)(mcookie, &casio_sevenmcs_list_setup_entry);
msg((ll_info, "Preparing the callbacks and running the server."));
memset(handle->casio_link_seven_callbacks, 0,
256 * sizeof(casio_seven_server_func_t*));

View File

@ -38,4 +38,11 @@ CASIO_EXTERN int CASIO_EXPORT casio_sevenmcs_list
OF((sevenmcs_t *casio__cookie, casio_mcslist_t *casio__mcslist,
void *casio__mcslist_cookie));
/* Other globals. */
CASIO_EXTERN const casio_mcshead_t CASIO_EXPORT
casio_sevenmcs_list_setup_entry;
CASIO_EXTERN const casio_mcshead_t CASIO_EXPORT
casio_sevenmcs_list_alpha_entry;
#endif /* LINK_SEVEN_MCS_H */

View File

@ -28,7 +28,7 @@ typedef int mcs_decode_func_t OF((casio_mcsfile_t**, casio_stream_t*,
/* Correspondance type */
struct mcs_corresp {
unsigned int type;
casio_mcstype_t type;
mcs_decode_func_t *decode;
};
@ -131,39 +131,41 @@ int CASIO_EXPORT casio_decode_mcsfile_head(casio_mcshead_t *head,
*/
int CASIO_EXPORT casio_decode_mcsfile(casio_mcsfile_t **handle,
const casio_mcshead_t *head, casio_stream_t *buffer)
const casio_mcshead_t *mcshead, casio_stream_t *buffer)
{
int err = 0;
mcs_decode_func_t *decode;
casio_mcshead_t h;
casio_mcshead_t head;
/* check that the head is there */
if (!head) return (casio_error_op);
h = *head;
/* check that the head is there, correct it */
if (!mcshead) return (casio_error_op);
memcpy(&head, mcshead, sizeof(casio_mcshead_t));
casio_correct_mcshead(&head, 0);
/* look for the decoding function */
decode = lookup_mcsfile_decode(head->casio_mcshead_type);
decode = lookup_mcsfile_decode(head.casio_mcshead_type);
if (!decode) {
msg((ll_error,
"No dedicated decoding function for this type was found!"));
"No dedicated decoding function for type 0x%08lX was found!",
head.casio_mcshead_type));
goto notparsing;
}
/* decode */
if (!head->casio_mcshead_size)
err = (*decode)(handle, buffer, &h);
if (!head.casio_mcshead_size)
err = (*decode)(handle, buffer, &head);
else {
casio_stream_t *lbuf;
int alterr;
/* Open the limited buffer. */
msg((ll_info, "Making a limited buffer out of the buffer."));
err = casio_open_limited(&lbuf, buffer, head->casio_mcshead_size);
err = casio_open_limited(&lbuf, buffer, head.casio_mcshead_size);
if (err) goto fail;
/* Call the decode error. */
msg((ll_info, "Decoding the file with the specific function."));
err = (*decode)(handle, lbuf, &h);
err = (*decode)(handle, lbuf, &head);
alterr = casio_empty_limited(lbuf);
casio_close(lbuf);
@ -178,15 +180,15 @@ int CASIO_EXPORT casio_decode_mcsfile(casio_mcsfile_t **handle,
notparsing:
/* allocate enough space */
if ((err = casio_make_mcsfile(handle, &h)))
if ((err = casio_make_mcsfile(handle, &head)))
return (err);
/* read the content */
GREAD((*handle)->casio_mcsfile_content, h.casio_mcshead_size)
GREAD((*handle)->casio_mcsfile_content, head.casio_mcshead_size)
/* log */
msg((ll_info, "File content:"));
mem((ll_info, (*handle)->casio_mcsfile_content, h.casio_mcshead_size));
mem((ll_info, (*handle)->casio_mcsfile_content, head.casio_mcshead_size));
/* saved normally */
return (0);

View File

@ -56,7 +56,7 @@ int CASIO_EXPORT casio_decode_mcs_setup(casio_mcsfile_t **h,
/* get window flags */
if (content[0x1C]) sp->casio_setup_wflags |= casio_setupwflag_grid;
if (content[0x1D]) sp->casio_setup_wflags |= casio_setupwflag_axes;
if (content[0x19]) sp->casio_setup_wflags |= casio_setupwflag_plot;
sp->casio_setup_vals[casio_setupval_draw] = content[0x19];
/* TODO: decode more options! */
/* no error! */

View File

@ -47,6 +47,9 @@ int CASIO_EXPORT casio_decode_mcs_var(casio_mcsfile_t **handle,
if (err) return (err);
h = *handle;
/* check the count */
ifmsg(head->casio_mcshead_count, (ll_info, "Is a single variable!"));
/* copy */
for (b = (void*)buf, i = 0; i < head->casio_mcshead_count; i++) {
casio_bcd_frommcs(&h->casio_mcsfile_vars[i].casio_mcscell_real, b++);

View File

@ -121,9 +121,13 @@ int CASIO_EXPORT casio_prepare_mcsfile(casio_mcsfile_t *handle,
head->casio_mcshead_width, head->casio_mcshead_height)
break;
/* prepare setup */
case casio_mcstype_setup:
casio_init_setup(&handle->casio_mcsfile_setup);
break;
/* allocate nothing */
case casio_mcstype_end:
case casio_mcstype_setup:
case casio_mcstype_string: /* TEMPORARY XXX */
break;

View File

@ -274,7 +274,7 @@ CASIO_LOCAL const struct group_corresp mcs_groups[] = {
CASIO_LOCAL int get_number(const char *s, int *num, int isnum)
{
if (!strcmp(s, "Ans"))
if (!strcmp(s, "\xC0") || !strcmp(s, "Ans"))
*num = casio_ans;
else if (!strcmp(s, "\xCE"))
*num = casio_theta;

34
src/setup/export.c.draft Normal file
View File

@ -0,0 +1,34 @@
/* ****************************************************************************
* setup/export.c -- export setup entries for Protocol 7.00.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "setup.h"
/**
* casio_export_setup:
* Export a setup.
*
* @arg setup the setup to export.
* @arg export the export callback.
* @arg ecookie the export callback cookie.
*/
void CASIO_EXPORT casio_export_setup(casio_setup_t *setup,
casio_setup_export_t *export, void *ecookie)
{
/* TODO */
}

145
src/setup/feed_mcs.c Normal file
View File

@ -0,0 +1,145 @@
/* ****************************************************************************
* setup/feed_mcs.c -- setup entries through an MCS setup file.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "setup.h"
/**
* casio_feed_setup_mcs:
* Feed setup using an ID.
*
* @arg setup the setup.
* @arg id the MCS setting ID.
* @arg value the setting value.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_feed_setup_mcs(casio_setup_t *setup, int id, int value)
{
switch (id) {
case 0x14: /* "Mode" */
setup->casio_setup_iflags &=
~(casio_setupiflag_shift | casio_setupiflag_alpha);
if (value == 0x01 || value == 0x84)
setup->casio_setup_iflags |= casio_setupiflag_shift;
if (value == 0x04 || value == 0x84)
setup->casio_setup_iflags |= casio_setupiflag_alpha;
break;
case 0x15: /* Insert/overwrite */
if (value - 1) setup->casio_setup_iflags |= casio_setupiflag_insert;
else setup->casio_setup_iflags &= ~casio_setupiflag_insert;
break;
case 0x17: /* Number mode */
switch (value) {
case 1:
setup->casio_setup_vals[casio_setupval_number] = 2;
break;
case 7:
setup->casio_setup_vals[casio_setupval_number] = 8;
break;
case 9:
setup->casio_setup_vals[casio_setupval_number] = 10;
break;
case 16:
setup->casio_setup_vals[casio_setupval_number] = 16;
break;
default:
setup->casio_setup_vals[casio_setupval_number] = 0;
}
break;
case 0x18: /* "Func Type" */
setup->casio_setup_vals[casio_setupval_function] = value;
break;
case 0x19: /* "Draw Type" */
setup->casio_setup_vals[casio_setupval_draw] = value;
break;
case 0x1A: /* "Derivative" */
if (value) setup->casio_setup_mflags |= casio_setupmflag_deriv;
else setup->casio_setup_mflags &= ~casio_setupmflag_deriv;
break;
case 0x1B: /* "Coord" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_coord;
else setup->casio_setup_wflags &= ~casio_setupwflag_coord;
break;
case 0x1C: /* "Grid" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_grid;
else setup->casio_setup_wflags &= ~casio_setupwflag_grid;
break;
case 0x1D: /* "Axes" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_axes;
else setup->casio_setup_wflags &= ~casio_setupwflag_axes;
break;
case 0x1E: /* "Label" */
if (value) setup->casio_setup_wflags |= casio_setupmflag_label;
else setup->casio_setup_wflags &= ~casio_setupmflag_label;
break;
case 0x20: /* "Stat Wind" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_simul;
else setup->casio_setup_wflags &= ~casio_setupwflag_simul;
break;
case 0x21: /* "Dynamic Type" */
if (value) setup->casio_setup_mflags &= ~casio_setupmflag_dynamic;
else setup->casio_setup_mflags |= casio_setupmflag_dynamic;
break;
/* TODO: "Dual Screen" */
case 0x23: /* "Simul Graph" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_simul;
else setup->casio_setup_wflags &= ~casio_setupwflag_simul;
break;
case 0x24: /* "Dynamic Type" */
if (value) setup->casio_setup_mflags &= ~casio_setupmflag_dynamic;
else setup->casio_setup_mflags |= casio_setupmflag_dynamic;
break;
case 0x25: /* "SigmaDisplay" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_sigma;
else setup->casio_setup_wflags &= ~casio_setupwflag_sigma;
break;
case 0x26: /* "Slope" */
if (value) setup->casio_setup_wflags |= casio_setupwflag_slope;
else setup->casio_setup_wflags &= ~casio_setupwflag_slope;
break;
case 0x27: /* "Payment" */
if (value) setup->casio_setup_mflags |= casio_setupmflag_payment;
else setup->casio_setup_mflags &= ~casio_setupmflag_payment;
break;
case 0x28: /* "Date Mode" */
if (value) setup->casio_setup_mflags |= casio_setupmflag_date360;
else setup->casio_setup_mflags &= ~casio_setupmflag_date360;
break;
case 0x29: /* "Answer Type" */
if (value) setup->casio_setup_mflags |= casio_setupmflag_complex;
else setup->casio_setup_mflags &= ~casio_setupmflag_complex;
break;
/* TODO: Complex Mode, Display */
case 0x2C: /* "Background" */
setup->casio_setup_vals[casio_setupval_background] = value;
break;
case 0x2D: /* "Resid List" */
setup->casio_setup_vals[casio_setupval_residlist] = value;
break;
case 0x2E: /* "List File" */
setup->casio_setup_vals[casio_setupval_listfile] = value;
break;
/* TODO: "Variable" */
default: return (casio_error_op);
}
return (0);
}

91
src/setup/feed_seven.c Normal file
View File

@ -0,0 +1,91 @@
/* ****************************************************************************
* setup/feed_seven.c -- setup entries through Protocol 7.00.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "setup.h"
struct corresp {
const char *name;
int offset;
};
CASIO_LOCAL struct corresp correspondances[] = {
{"Angle", 0x13},
{"Mode", 0x14},
{"Func Type", 0x18},
{"Draw Type", 0x19},
{"Derivative", 0x1A},
{"Coord", 0x1B},
{"Grid", 0x1C},
{"Axes", 0x1D},
{"Label", 0x1E},
{"Stat Wind", 0x20},
{"Graph Func", 0x21},
{"Dual Screen", 0x22},
{"Simul Graph", 0x23},
{"Dynamic Type", 0x24},
{"SigmaDisplay", 0x25},
{"Slope", 0x26},
{"Payment", 0x27},
{"Date Mode", 0x28},
{"Answer Type", 0x29},
{"Complex Mode", 0x2A},
{"Display", 0x2B},
{"Background", 0x2C},
{"Resid List", 0x2D},
{"List File", 0x2E},
{"Variable", 0x2F},
{"Recur Dual", 0x31},
{"Auto Calc", 0x4E},
{"Show Sell", 0x4F},
{"Move", 0x50},
{"Sub Name", 0x51},
{"Input Mode", 0x53},
{"Locus", 0x54},
{"Y=Draw Speed", 0x55},
{"Sketch Line", 0x56},
{"Frac Result", 0x57},
{"Recur Type", 0x30},
{"Inequa Type", 0x5D},
{"Periods YR", 0x5E},
{"Q1Q3 Type", 0x5C},
{"Simplify", 0x5F},
{NULL, 0}
};
/**
* casio_feed_setup_seven:
* Feed a setup using a Protocol 7.00 setting.
*
* @arg setup the setup.
* @arg name the setting name.
* @arg value the setting value.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_feed_setup_seven(casio_setup_t *setup,
const char *name, int value)
{
struct corresp *c;
for (c = correspondances; c->name && strcmp(name, c->name); c++);
if (!c->name) return (casio_error_op);
return (casio_feed_setup_mcs(setup, c->offset, value));
}

31
src/setup/init.c Normal file
View File

@ -0,0 +1,31 @@
/* ****************************************************************************
* setup/init.c -- initialize the setup.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "setup.h"
/**
* casio_init_setup:
* Initialize a setup.
*
* @arg setup the setup object.
*/
void CASIO_EXPORT casio_init_setup(casio_setup_t *setup)
{
memset(setup, 0, sizeof(casio_setup_t));
}

25
src/setup/setup.h Normal file
View File

@ -0,0 +1,25 @@
/* ****************************************************************************
* setup/setup.h -- setup internals.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libcasio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LOCAL_SETUP_H
# define LOCAL_SETUP_H
# include "../internals.h"
/* No need for internals, for now. */
#endif /* LOCAL_SETUP_H */

View File

@ -19,26 +19,26 @@
#include "../internals.h"
/**
* casio_init_mutex:
* casio_init_lock:
* Initialize a mutex.
*
* @arg mutex the mutex to initialize.
*/
void CASIO_EXPORT casio_init_mutex(casio_mutex_t *mutex)
void CASIO_EXPORT casio_init_lock(casio_mutex_t *mutex)
{
*mutex = 0;
}
/**
* casio_lock_mutex:
* casio_lock:
* Lock a mutex.
*
* @arg mutex the mutex to lock.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_lock_mutex(casio_mutex_t *mutex)
int CASIO_EXPORT casio_lock(casio_mutex_t *mutex)
{
int err;
@ -53,14 +53,14 @@ unlocked:
}
/**
* casio_trylock_mutex:
* casio_trylock:
* Try to lock a mutex.
*
* @arg mutex the mutex to lock.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_trylock_mutex(casio_mutex_t *mutex)
int CASIO_EXPORT casio_trylock(casio_mutex_t *mutex)
{
if (*mutex) return (casio_error_lock);
*mutex = 1;
@ -74,7 +74,7 @@ int CASIO_EXPORT casio_trylock_mutex(casio_mutex_t *mutex)
* @arg mutex the mutex to unlock.
*/
void CASIO_EXPORT casio_unlock_mutex(casio_mutex_t *mutex)
void CASIO_EXPORT casio_unlock(casio_mutex_t *mutex)
{
*mutex = 0;
}