2016-12-01 13:34:10 +01:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* _____ _ */
|
|
|
|
/* utils/type.c |_ _|__ _ _| |__ ___ _ _ */
|
|
|
|
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
|
|
/* Last updated: 2016/12/01 13:33:41 |___/ */
|
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
#include <libg1m/internals.h>
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
/* Local types */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
/* Subtype correspondance type */
|
|
|
|
struct type_info {
|
|
|
|
/* identification */
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
/* info */
|
|
|
|
const char *info;
|
|
|
|
|
|
|
|
/* actions */
|
|
|
|
int (*read)(g1m_t*, FILE*, struct standard_header*);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Main type correspondance type */
|
|
|
|
struct main_info {
|
|
|
|
/* identification */
|
|
|
|
const char *type;
|
|
|
|
|
|
|
|
/* subtypes */
|
|
|
|
struct type_info *subtypes;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
/* Correspondances */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
/* Common magic types */
|
|
|
|
#define magic_common "\x00\x10\x00\x10\x00"
|
|
|
|
#define cp_magic "\x00\x01\x00\x01\x00"
|
|
|
|
|
|
|
|
/* USBPower subtypes */
|
|
|
|
static struct type_info usbpower_types[] = {
|
|
|
|
/* add-ins */
|
|
|
|
{"\xf3" magic_common,
|
|
|
|
"add-in", g1m_parse_addin},
|
|
|
|
{"\x2c" cp_magic,
|
|
|
|
"fx-CG add-in", g1m_parse_addin_cg},
|
|
|
|
|
|
|
|
/* MCS */
|
|
|
|
{"\x31" magic_common,
|
|
|
|
"mcs", g1m_parse_mcs},
|
|
|
|
{"\x62" magic_common,
|
|
|
|
"mcs (g2r)", g1m_parse_mcs},
|
|
|
|
{"\x75" magic_common,
|
|
|
|
"mcs (fx-CG)", g1m_parse_mcs},
|
|
|
|
|
|
|
|
/* Language */
|
|
|
|
{"\x12" magic_common,
|
|
|
|
"fx language file", g1m_parse_lang},
|
|
|
|
|
|
|
|
/* E-Activities */
|
|
|
|
{"\x49" magic_common,
|
|
|
|
"e-activity (document)", g1m_parse_eact},
|
|
|
|
|
|
|
|
/* Pictures */
|
|
|
|
{"\x7d" magic_common,
|
|
|
|
"fx-CG picture", g1m_parse_g3p},
|
|
|
|
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Ly755 subtypes */
|
|
|
|
static struct type_info ly755_types[] = {
|
|
|
|
{"\x2c" cp_magic,
|
|
|
|
"fx-CG language file", g1m_parse_lang_cg},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* CASIO subtypes */
|
|
|
|
static struct type_info casio_types[] = {
|
|
|
|
{"c2p\0\0\0",
|
|
|
|
"Classpad picture", g1m_parse_c2p},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2016-12-01 16:04:05 +01:00
|
|
|
/* Blank subtypes */
|
|
|
|
static struct type_info blank_types[] = {
|
|
|
|
{"\xFF\xFF\xFF\xFF\xFF\xFF",
|
|
|
|
"CASIO archive", g1m_parse_g1s},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2016-12-01 13:34:10 +01:00
|
|
|
/* Main types */
|
|
|
|
static struct main_info types[] = {
|
|
|
|
{"USBPower", usbpower_types},
|
|
|
|
{"Ly755 ", ly755_types},
|
|
|
|
{"CASIO\0\0\0", casio_types},
|
2016-12-01 16:04:05 +01:00
|
|
|
{"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF", blank_types},
|
2016-12-01 13:34:10 +01:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
/* Main functions */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
/**
|
|
|
|
* g1m_get_type_info:
|
|
|
|
* Get type info.
|
|
|
|
*
|
|
|
|
* @arg main_id The main ID (at least 8 bytes).
|
|
|
|
* @arg subtype The subtype (at least 6 bytes).
|
|
|
|
* @arg info Pointer to the info string to set.
|
|
|
|
* @arg read Pointer to the read callback to set.
|
|
|
|
* @return If there was an error.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int g1m_get_type_info(unsigned char *main_id, unsigned char *subtype,
|
|
|
|
const char **info, int (**rd)(g1m_t*, FILE*, struct standard_header*))
|
|
|
|
{
|
|
|
|
/* look for main_id */
|
|
|
|
struct main_info *mt = types;
|
|
|
|
while (mt->type) {
|
|
|
|
if (!memcmp(mt->type, main_id, 8))
|
|
|
|
break ;
|
|
|
|
mt++;
|
|
|
|
}
|
|
|
|
if (!mt->type) {
|
|
|
|
log_fatal("Main ID not recognized:");
|
|
|
|
logm_info(main_id, 8);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look for subtype */
|
|
|
|
struct type_info *sub = mt->subtypes;
|
|
|
|
while (sub->type) {
|
|
|
|
if (!memcmp(sub->type, subtype, 6))
|
|
|
|
break ;
|
|
|
|
sub++;
|
|
|
|
}
|
|
|
|
if (!sub->type) {
|
|
|
|
log_fatal("Type not managed (yet?):");
|
|
|
|
logm_info(subtype, 6);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fill in info and return */
|
|
|
|
if (info) *info = sub->info;
|
|
|
|
if (rd) *rd = sub->read;
|
|
|
|
return (0);
|
|
|
|
}
|