141 lines
4.1 KiB
C
141 lines
4.1 KiB
C
/* *****************************************************************************
|
|
* type/cas/app.c -- get the CAS app out of raw identification data.
|
|
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libg1m.
|
|
* libg1m 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.
|
|
*
|
|
* libg1m 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 libg1m; if not, see <http://www.gnu.org/licenses/>.
|
|
* ************************************************************************** */
|
|
#include <libg1m/internals.h>
|
|
|
|
/* ************************************************************************** */
|
|
/* Local types */
|
|
/* ************************************************************************** */
|
|
/* Correspondance type */
|
|
struct app_corresp {
|
|
/* identification */
|
|
const char *name;
|
|
|
|
/* things: nothing yet */
|
|
};
|
|
|
|
/* Extension */
|
|
struct ext_corresp {
|
|
/* identification */
|
|
int value;
|
|
|
|
/* things */
|
|
g1m_mcsinfo_t info;
|
|
|
|
/* app correspondances */
|
|
struct app_corresp *apps;
|
|
};
|
|
/* ************************************************************************** */
|
|
/* Correspondances */
|
|
/* ************************************************************************** */
|
|
/* App correspondances. Remarks:
|
|
* - Correspondances with a NULL data type means the data type isn't to be
|
|
* read. */
|
|
|
|
#define ETERM {NULL}
|
|
static struct ext_corresp apps[] = {
|
|
/* CFX-9850G headers (very first headers with this extension system?) */
|
|
{casdyn_ext_9850, g1m_mcsinfo_cas50, (struct app_corresp[]){
|
|
{"TXT"}, /* editor */
|
|
{"VAL"}, /* RUN? */
|
|
{"IMG"}, /* screen shooter? */
|
|
|
|
ETERM
|
|
}},
|
|
|
|
/* CFX-9850G header alias, used with the END packet only */
|
|
{casdyn_ext_end, g1m_mcsinfo_cas50, (struct app_corresp[]){
|
|
{"END"}, /* end packet... used in the same period than 9850G packets? */
|
|
|
|
ETERM
|
|
}},
|
|
|
|
/* Graph 100 (Algebra FX) headers */
|
|
{casdyn_ext_g100, g1m_mcsinfo_cas100, (struct app_corresp[]){
|
|
{"MDL"}, /* Model, initialize */
|
|
{"END"}, /* Terminate */
|
|
{"REQ"}, /* Receive */
|
|
{"ADN"}, /* Send */
|
|
|
|
{"FMV"}, /* ? */
|
|
{"FCL"}, /* ? */
|
|
{"MCS"}, /* ? */
|
|
|
|
ETERM
|
|
}},
|
|
|
|
/* Graph 100 (Algebra FX) alternate headers */
|
|
{casdyn_ext_g100b, g1m_mcsinfo_cas100, (struct app_corresp[]){
|
|
{"ADN"}, /* Send (bis) */
|
|
{"REQ"}, /* Request (bis) */
|
|
|
|
ETERM
|
|
}},
|
|
|
|
/* sentinel */
|
|
{0, 0, NULL}
|
|
};
|
|
|
|
/* ************************************************************************** */
|
|
/* Main functions */
|
|
/* ************************************************************************** */
|
|
/**
|
|
* g1m_maketype_casapp:
|
|
* Get the CAS application from raw CASDYN identification data.
|
|
*
|
|
* @arg head the head to fill.
|
|
* @arg ext the extension value.
|
|
* @arg app the application name.
|
|
* @return the error (if any).
|
|
*/
|
|
|
|
int g1m_maketype_casapp(g1m_mcshead_t *head,
|
|
int ext, const char *app)
|
|
{
|
|
/* look for the extension */
|
|
struct ext_corresp *e;
|
|
for (e = apps; e->apps; e++) {
|
|
if (e->value == ext)
|
|
break;
|
|
} if (!e->apps)
|
|
goto notfound;
|
|
|
|
/* look for the application */
|
|
struct app_corresp *a;
|
|
for (a = e->apps; a->name; a++) {
|
|
if (!strncmp(a->name, app, 3))
|
|
break;
|
|
} if (!a->name) goto notfound;
|
|
|
|
/* copy raw information */
|
|
memset(head, 0, sizeof(g1m_mcshead_t));
|
|
head->info = e->info; /* FIXME */
|
|
log_info("Head info is 0x%04X", e->info);
|
|
strncpy((char*)head->_appname, app, 3);
|
|
head->_appname[3] = 0;
|
|
|
|
/* fill in info and return */
|
|
return (0);
|
|
|
|
notfound:
|
|
log_error("Type with 0x%02X extension and '%.3s' app name was not "
|
|
"implemented or recognized", ext, app);
|
|
head->type = 0;
|
|
return (1);
|
|
}
|