From ec87751909e1b4c5aa3d1bc4bf21e293db81ad9a Mon Sep 17 00:00:00 2001 From: "Thomas \"Cakeisalie5\" Touhey" Date: Tue, 28 Feb 2017 17:08:52 +0100 Subject: [PATCH] Reorganized headers. --- include/libg1m/format.h | 115 +++--------- include/libg1m/format/mcs/list.h | 49 +++++ include/libg1m/format/mcs/matrix.h | 53 ++++++ include/libg1m/format/mcs/picture.h | 41 +++++ include/libg1m/format/mcs/program.h | 37 ++++ include/libg1m/format/mcs/setup.h | 74 ++++++++ include/libg1m/format/mcs/spreadsheet.h | 64 +++++++ include/libg1m/format/mcsfile.h | 213 ---------------------- include/libg1m/format/std.h | 96 ++++++++++ include/libg1m/format/{ => std}/addin.h | 8 +- include/libg1m/format/{ => std}/eact.h | 8 +- include/libg1m/format/{ => std}/fkey.h | 8 +- include/libg1m/format/{ => std}/lang.h | 8 +- include/libg1m/format/{ => std}/mcs.h | 16 +- include/libg1m/format/{ => std}/picture.h | 8 +- include/libg1m/format/{ => std}/storage.h | 8 +- 16 files changed, 471 insertions(+), 335 deletions(-) create mode 100644 include/libg1m/format/mcs/list.h create mode 100644 include/libg1m/format/mcs/matrix.h create mode 100644 include/libg1m/format/mcs/picture.h create mode 100644 include/libg1m/format/mcs/program.h create mode 100644 include/libg1m/format/mcs/setup.h create mode 100644 include/libg1m/format/mcs/spreadsheet.h delete mode 100644 include/libg1m/format/mcsfile.h create mode 100644 include/libg1m/format/std.h rename include/libg1m/format/{ => std}/addin.h (96%) rename include/libg1m/format/{ => std}/eact.h (95%) rename include/libg1m/format/{ => std}/fkey.h (93%) rename include/libg1m/format/{ => std}/lang.h (95%) rename include/libg1m/format/{ => std}/mcs.h (86%) rename include/libg1m/format/{ => std}/picture.h (96%) rename include/libg1m/format/{ => std}/storage.h (97%) diff --git a/include/libg1m/format.h b/include/libg1m/format.h index 52b247c..2bfe51c 100644 --- a/include/libg1m/format.h +++ b/include/libg1m/format.h @@ -20,116 +20,47 @@ # define LIBG1M_FORMAT_H # include -/* Welcome on this new episode of the Monster Circus show! Today we'll present - * to you the different formats surrounding CASIO calculators: open or closed, - * legacy or legacy, obfuscated or not, I hope you'll enjoy them as much - * as I don't! */ +/* Welcome on this new episode of the Monster Circus show! Today we'll present + * to you the different formats surrounding CASIO calculators: open or closed, + * legacy or legacy, obfuscated or not, I hope you'll enjoy them as much + * as I don't! */ /* ************************************************************************** */ /* The CASIOLINK (CAS) format */ /* ************************************************************************** */ -/* This is the basic file format that CASIO used until around 2004, when the - * fx-9860G (Graph 85) came out. It is linked with the legacy protocol, which - * cannot be implemented with a good management of this format. +/* This is the basic file format that CASIO used until around 2004, when the + * fx-9860G (Graph 85) came out. It is linked with the legacy protocol, which + * cannot be implemented with a good management of this format. * - * All of the useful structures and constants are in the specific header. - * The function to get the libg1m MCS type out of the string types is in - * `libg1m/formatutils.h`. */ + * All of the useful structures and constants are in the specific header. + * The function to get the libg1m MCS type out of the string types is in + * `libg1m/formatutils.h`. */ # include /* ************************************************************************** */ /* The FXI format */ /* ************************************************************************** */ -/* fx-Interface, an old but well done proprietary interface by CASIO, has its - * own format: the FXI format. It's an obfuscated format (althrough the - * obfuscation algorithm has been found). +/* fx-Interface, an old but well done proprietary interface by CASIO, has its + * own format: the FXI format. It's an obfuscated format (althrough the + * obfuscation algorithm has been found). * - * It starts with the following obfuscated string: */ + * It starts with the following obfuscated string: */ # define FXI_OBF_MAGIC "\x32\x30" "\xF8\xA1" # define FXI_DEC_MAGIC "\xD5\xD7" "\x1F\x46" "FX-INTERFACE - YELLOW COMPUTING" -/* Followed by loads of zero, then, the content. The description of the rest - * of the format is described in this header: */ +/* Followed by loads of zero, then, the content. The description of the rest + * of the format is described in this header: */ //# include /* ************************************************************************** */ -/* The G1M format */ +/* The G1M/STD format */ /* ************************************************************************** */ -/* The most recent format is made by CASIO: we call it the G1M format. +/* Since around 2004, CASIO has adopted a single "superformat"; we call it + * CASIO's standard format, or the G1M format (it doesn't really have a + * *public* name, other than its magics, like USBPower or CASIO). * - * This format is used by CASIO with its calculator for storing things - * like add-ins (compiled programs), MCS (main memory saves), and others. - * In fact, there is no name for the general format, only names for the - * "subformats" based on this one. - * - * It all starts with a header, called Standard Header by Simon Lothar. - * This Standard Header contains the total filesize, the G1M type (add-in, - * MCS, e-acts), some data that will be useful for the MCS type, and some - * magic and control bytes. - * - * For some reason, this StandardHeader is INVERTED on every file it's on, - * you will have to apply a NOT operation on its bytes for it to make sense. - * - * Keep in mind that, everywhere in the header, multi-bytes integers - * are BIG ENDIAN. - * - * The LSB is the Least Significant Byte: once adapted to the host endianness, - * it can simply be obtained by bitwise-AND-ing with 0xff. */ + * It doesn't have a single magic string, but a few. But the standard header + * has the same format, so we consider it as the same format. */ -# pragma pack(1) - -struct standard_header { - /* the file identifier */ - uint8_t main_id[8]; - - /* our subtype! */ - uint8_t subtype[6]; - - /* first control byte: filesize LSB + 0x41 */ - uint8_t control; - - /* said to be 0x01, but doesn't need to */ - uint8_t align_one; - - /* total filesize */ - uint32_t filesize; - - /* second control byte: filesize LSB + 0xb8 */ - uint8_t control2; - - /* alignment */ - uint8_t align[8]; - - /* is obfuscated - useful for G3P */ - uint8_t obfuscated; - - /* number of objects contained (useful for MCS filetype) */ - uint16_t number; -}; - -/* At the beginning, we thought "USBPower" was some magic sequence we would - * systematically find in the "main_id" field. But counter examples came: - * the G3L, whose main ID was "Ly755 ", and the C2P. - * - * We also thought the subtype was only one-byte long, but the C2P came along - * with its "c2p\0\0\0" subtype. - * - * All main ID/types correspondances are in the `src/utils/type.c` file. - * From a user program, you can use the functions - * in `include/libg1m/formatutils.h`. */ - -# pragma pack() - -/* After the Standard Header is read and the type is read, we have parts, - * each with their own subheaders and their own subtilities. - * - * Where do you want to start? Pick your poison. */ - -# include -# include -# include -# include -# include -# include -# include +# include #endif /* LIBG1M_FORMAT_H */ diff --git a/include/libg1m/format/mcs/list.h b/include/libg1m/format/mcs/list.h new file mode 100644 index 0000000..606dba4 --- /dev/null +++ b/include/libg1m/format/mcs/list.h @@ -0,0 +1,49 @@ +/* ***************************************************************************** + * libg1m/format/mcs/list.h -- description of the MCS list format. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_MCS_LIST_H +# define LIBG1M_FORMAT_MCS_LIST_H +# include +# pragma pack(1) + +/* Lists start with a header: */ + +struct mcs_listheader { + /* probably the title */ + uint8_t title[8]; + + /* the elements count */ + uint16_t element_count; + + /* undocumented (always 0?) */ + uint8_t undocumented[5]; + + /* undocumented (either 0x00 or 0x4F) */ + uint8_t undocumented2; +}; + +/* Then there is the list of real parts of the elements. + * If the complex bit is present on at least one of the elements (highest bit + * of the first nibble, which is the highest nibble of the exponent), then it + * is followed by the list of the imaginary parts of the elements. + * + * If the imaginary parts is here, only read the imaginary part of an element + * if his highest bit is set: it might contain complete crap! */ + +# pragma pack() +#endif /* LIBG1M_FORMAT_MCS_LIST_H */ diff --git a/include/libg1m/format/mcs/matrix.h b/include/libg1m/format/mcs/matrix.h new file mode 100644 index 0000000..7521dc0 --- /dev/null +++ b/include/libg1m/format/mcs/matrix.h @@ -0,0 +1,53 @@ +/* ***************************************************************************** + * libg1m/format/mcs/matrix.h -- description of the MCS matrix format. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_MCS_MATRIX_H +# define LIBG1M_FORMAT_MCS_MATRIX_H +# include +# pragma pack(1) + +/* Matrixes and vectors have exactly the same format; it's just that the OS + * refuses to have more that one row for vectors. + * + * They have this simple header: */ + +struct mcs_matheader { + /* undocumented */ + uint8_t undocumented[8]; + + /* height */ + uint16_t height; + + /* width */ + uint16_t width; + + /* re-undocumented */ + uint8_t undocumented2[4]; +}; + +/* Then we have width*height BCD cells, which corresponds to the real parts, + * grouped by height. + * + * If at least one of the cells has an imaginary part (highest bit of the + * first nibble set), it is followed by a list of the imaginary parts, that + * has the same size that the real parts list, that is grouped the same way and + * that contains actual things (and not crap) only if the complex bit is set + * on the real part. */ + +# pragma pack() +#endif /* LIBG1M_FORMAT_MCS_MATRIX_H */ diff --git a/include/libg1m/format/mcs/picture.h b/include/libg1m/format/mcs/picture.h new file mode 100644 index 0000000..2b212f3 --- /dev/null +++ b/include/libg1m/format/mcs/picture.h @@ -0,0 +1,41 @@ +/* ***************************************************************************** + * libg1m/format/mcs/picture.h -- description of the MCS picture format. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_MCS_PICTURE_H +# define LIBG1M_FORMAT_MCS_PICTURE_H +# pragma pack(1) + +/* Captures start with a simple header: */ + +struct mcs_captureheader { + /* the width (0x80) */ + uint16_t width; + + /* the height (0x40) */ + uint16_t height; +}; + +/* Then the image follows (0x400 for a 0x80*0x40px image). + * A picture is the same that an capture, but without the header and containing + * two 128x64 images (0x800 bytes). + * + * Pictures don't have any header: it's just two 128x64 images (packed 1-bit) + * and that's all. */ + +# pragma pack() +#endif /* LIBG1M_FORMAT_MCS_PICTURE_H */ diff --git a/include/libg1m/format/mcs/program.h b/include/libg1m/format/mcs/program.h new file mode 100644 index 0000000..82573bf --- /dev/null +++ b/include/libg1m/format/mcs/program.h @@ -0,0 +1,37 @@ +/* ***************************************************************************** + * libg1m/format/mcs/program.h -- description of the MCS program format. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_MCS_PROGRAM_H +# define LIBG1M_FORMAT_MCS_PROGRAM_H +# include +# pragma pack(1) + +/* Programs have a simple header: */ + +struct mcs_programheader { + /* the program password. not encrypted, anything */ + uint8_t password[8]; + + /* and some alignment. */ + uint8_t align[2]; +}; + +/* Then comes their content, multi-byte FONTCHARACTER encoded. */ + +# pragma pack() +#endif /* LIBG1M_FORMAT_MCS_PROGRAM_H */ diff --git a/include/libg1m/format/mcs/setup.h b/include/libg1m/format/mcs/setup.h new file mode 100644 index 0000000..63c786c --- /dev/null +++ b/include/libg1m/format/mcs/setup.h @@ -0,0 +1,74 @@ +/* ***************************************************************************** + * libg1m/format/mcs/setup.h -- description of the MCS setup file format. + * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_MCS_SETUP_H +# define LIBG1M_FORMAT_MCS_SETUP_H + +/* Setup files have no headers, they are just a bunch of bytes you can copy. + * Legacy fx setup files have 100 entries (100 bytes), fx-CG setup files + * have twice as much (even though the first 100 entries have the same + * signification in the two). + * + * Known settings are: + * [0x13] Angle (0x00: degrees, 0x01: radians, 0x02: gradians); + * [0x14] SHIFT/Alpha status (0x00: both off, 0x01: shift only on, + * 0x04: alpha only on, 0x84: both on); + * [0x15] Insert/Overwrite status (0x01: overwrite, 0x02: insert); + * [0x17] Number mode (0x00: Comp, 0x01: Bin, 0x07: Oct, 0x09: Dec, 0x0F: Hex); + * [0x18] Function type (0x00: Y=, 0x01: r=, 0x02: Param, 0x03: X=c, + * 0x04: Y>, 0x05: Y<, 0x06: Y>=, 0x07: Y<=); + * [0x19] Draw type (0x00: Con, 0x01: Plot); + * [0x1A] Derivative; + * [0x1B] Coord; + * [0x1C] Grid; + * [0x1D] Axes; + * [0x1E] Label; + * [0x20] Stat Wind (0x00: Auto, 0x01: Manual); + * [0x21] Graph Func; + * [0x22] Dual Screen (0x03: OFF); + * [0x24] Dynamic Type (0x00: Cont, 0x01: Stop); + * [0x25] SigmaDisplay; + * [0x26] Slope; + * [0x27] Payment (0x00: Bgn, 0x01: End); + * [0x28] Date Mode (0x00: 365, 0x01: 360); + * [0x29] Answer Type (0x00: Real, 0x01: Complex); + * [0x2A] Complex Mode (0x00: Real, 0x01: a+bi, 0x02: r + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_MCS_SPREADSHEET_H +# define LIBG1M_FORMAT_MCS_SPREADSHEET_H +# include +# pragma pack(1) + +/* Spreadsheets are more complicated than that. + * + * For normal ones, there is a header: */ + +struct mcs_spreadsheetheader { + /* has subheader: 0x01 if yes */ + uint8_t has_subheader; + + /* column count (max: 26), on 24 bits and non-aligned */ + uint32_t column_count : 24; +}; + +/* Then, if it is a normal spreadsheet, there is a subheader, + * a column directory and a column definition table. + * + * Here's the subheader: */ + +struct mcs_spreadsheet_subheader { + /* alignment or magic? {0, 0, 0, 0} */ + uint8_t align[4]; + + /* number of column definitions */ + uint32_t defs_size; + + /* alignment or magic II? {0, 0, 0, 0} */ + uint8_t align2[4]; +}; + +/* The column definition table is the main definition. It contains the row + * directory, which is a 80-bytes long bitfield indicating if cells are empty + * or not, and the list of non-empty cells. + * + * Each cell is a BCD structure (the real part of the number). Numbers in + * spreadsheets can't have imaginary parts. + * + * The column directory is just a list of 4-bytes sizes of each column, + * counting the row directory and the cells. It's easier to naviguate to + * a column quicker. */ + +# pragma pack() +#endif /* LIBG1M_FORMAT_MCS_SPREADSHEET_H */ diff --git a/include/libg1m/format/mcsfile.h b/include/libg1m/format/mcsfile.h deleted file mode 100644 index aad6e34..0000000 --- a/include/libg1m/format/mcsfile.h +++ /dev/null @@ -1,213 +0,0 @@ -/* ***************************************************************************** - * libg1m/format/mcsfile.h -- description of the MCS subfiles formats. - * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey - * - * 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 . - * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_MCSFILE_H -# define LIBG1M_FORMAT_MCSFILE_H -# include -# include -# pragma pack(1) - -/* ************************************************************************** */ -/* Programs */ -/* ************************************************************************** */ -/* Programs have a simple header: */ - -struct mcs_programheader { - /* the program password. not encrypted, anything */ - uint8_t password[8]; - - /* and some alignment. */ - uint8_t align[2]; -}; - -/* Then comes their content, multi-byte FONTCHARACTER encoded. */ -/* ************************************************************************** */ -/* Setup */ -/* ************************************************************************** */ -/* Setup files have no headers, they are just a bunch of bytes you can copy. - * Legacy fx setup files have 100 entries (100 bytes), fx-CG setup files - * have twice as much (even though the first 100 entries have the same - * signification in the two). - * - * Known settings are: - * [0x13] Angle (0x00: degrees, 0x01: radians, 0x02: gradians); - * [0x14] SHIFT/Alpha status (0x00: both off, 0x01: shift only on, - * 0x04: alpha only on, 0x84: both on); - * [0x15] Insert/Overwrite status (0x01: overwrite, 0x02: insert); - * [0x17] Number mode (0x00: Comp, 0x01: Bin, 0x07: Oct, 0x09: Dec, 0x0F: Hex); - * [0x18] Function type (0x00: Y=, 0x01: r=, 0x02: Param, 0x03: X=c, - * 0x04: Y>, 0x05: Y<, 0x06: Y>=, 0x07: Y<=); - * [0x19] Draw type (0x00: Con, 0x01: Plot); - * [0x1A] Derivative; - * [0x1B] Coord; - * [0x1C] Grid; - * [0x1D] Axes; - * [0x1E] Label; - * [0x20] Stat Wind (0x00: Auto, 0x01: Manual); - * [0x21] Graph Func; - * [0x22] Dual Screen (0x03: OFF); - * [0x24] Dynamic Type (0x00: Cont, 0x01: Stop); - * [0x25] SigmaDisplay; - * [0x26] Slope; - * [0x27] Payment (0x00: Bgn, 0x01: End); - * [0x28] Date Mode (0x00: 365, 0x01: 360); - * [0x29] Answer Type (0x00: Real, 0x01: Complex); - * [0x2A] Complex Mode (0x00: Real, 0x01: a+bi, 0x02: r + * + * 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 . + * ************************************************************************** */ +#ifndef LIBG1M_FORMAT_STD_H +# define LIBG1M_FORMAT_STD_H +# include +# pragma pack(1) + +/* This format is used by CASIO with its calculator for storing things + * like add-ins (compiled programs), MCS (main memory saves), and others. + * In fact, there is no name for the general format, only names for the + * "subformats" based on this one. + * + * It all starts with a header, called Standard Header by Simon Lothar. + * This Standard Header contains the total filesize, the G1M type (add-in, + * MCS, e-acts), some data that will be useful for the MCS type, and some + * magic and control bytes. + * + * For some reason, this StandardHeader is INVERTED on every file it's on, + * you will have to apply a NOT operation on its bytes for it to make sense. + * + * Keep in mind that, everywhere in the header, multi-bytes integers + * are BIG ENDIAN. + * + * The LSB is the Least Significant Byte: once adapted to the host endianness, + * it can simply be obtained by bitwise-AND-ing with 0xff. */ + +struct standard_header { + /* the file identifier */ + uint8_t main_id[8]; + + /* our subtype! */ + uint8_t subtype[6]; + + /* first control byte: filesize LSB + 0x41 */ + uint8_t control; + + /* said to be 0x01, but doesn't need to */ + uint8_t align_one; + + /* total filesize */ + uint32_t filesize; + + /* second control byte: filesize LSB + 0xb8 */ + uint8_t control2; + + /* alignment */ + uint8_t align[8]; + + /* is obfuscated - useful for G3P */ + uint8_t obfuscated; + + /* number of objects contained (useful for MCS filetype) */ + uint16_t number; +}; + +/* At the beginning, we thought "USBPower" was some magic sequence we would + * systematically find in the "main_id" field. But counter examples came: + * the G3L, whose main ID was "Ly755 ", and the C2P. + * + * We also thought the subtype was only one-byte long, but the C2P came along + * with its "c2p\0\0\0" subtype. + * + * All main ID/types correspondances are in the `src/utils/type.c` file. + * From a user program, you can use the functions + * in `include/libg1m/formatutils.h`. + * + * After the Standard Header is read and the type is read, we have parts, + * each with their own subheaders and their own subtilities. + * + * Where do you want to start? Pick your poison. */ + +# pragma pack() +# include +# include +# include +# include +# include +# include +# include +#endif /* LIBG1M_FORMAT_STD_H */ diff --git a/include/libg1m/format/addin.h b/include/libg1m/format/std/addin.h similarity index 96% rename from include/libg1m/format/addin.h rename to include/libg1m/format/std/addin.h index e5244ab..8fed069 100644 --- a/include/libg1m/format/addin.h +++ b/include/libg1m/format/std/addin.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/addin.h -- the G1M add-in format description. + * libg1m/format/std/addin.h -- the G1M add-in format description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_ADDIN_H -# define LIBG1M_FORMAT_ADDIN_H +#ifndef LIBG1M_FORMAT_STD_ADDIN_H +# define LIBG1M_FORMAT_STD_ADDIN_H # include # pragma pack(1) @@ -200,4 +200,4 @@ struct c1a_subheader { }; # pragma pack() -#endif /* LIBG1M_FORMAT_ADDIN_H */ +#endif /* LIBG1M_FORMAT_STD_ADDIN_H */ diff --git a/include/libg1m/format/eact.h b/include/libg1m/format/std/eact.h similarity index 95% rename from include/libg1m/format/eact.h rename to include/libg1m/format/std/eact.h index b10bd32..8c516ca 100644 --- a/include/libg1m/format/eact.h +++ b/include/libg1m/format/std/eact.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/eact.h -- the G1M e-activity format description. + * libg1m/format/std/eact.h -- the G1M e-activity format description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_EACT_H -# define LIBG1M_FORMAT_EACT_H +#ifndef LIBG1M_FORMAT_STD_EACT_H +# define LIBG1M_FORMAT_STD_EACT_H # include /* E-Activities are the format CASIO uses for in-calc documents. @@ -131,4 +131,4 @@ struct line_descriptor { * * Which means in each node, there can be a content to parse. */ -#endif /* LIBG1M_FORMAT_EACT_H */ +#endif /* LIBG1M_FORMAT_STD_EACT_H */ diff --git a/include/libg1m/format/fkey.h b/include/libg1m/format/std/fkey.h similarity index 93% rename from include/libg1m/format/fkey.h rename to include/libg1m/format/std/fkey.h index 527b93c..0b36ec0 100644 --- a/include/libg1m/format/fkey.h +++ b/include/libg1m/format/std/fkey.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/fkey.h -- the G1M function keys file format description. + * libg1m/format/std/fkey.h -- the G1M function keys file format description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_FKEY_H -# define LIBG1M_FORMAT_FKEY_H +#ifndef LIBG1M_FORMAT_STD_FKEY_H +# define LIBG1M_FORMAT_STD_FKEY_H # include # pragma pack(1) @@ -65,4 +65,4 @@ struct g1n_subheader { # define FKEY3_WIDTH 64 # define FKEY3_HEIGHT 24 # pragma pack() -#endif /* LIBG1M_FORMAT_FKEY_H */ +#endif /* LIBG1M_FORMAT_STD_FKEY_H */ diff --git a/include/libg1m/format/lang.h b/include/libg1m/format/std/lang.h similarity index 95% rename from include/libg1m/format/lang.h rename to include/libg1m/format/std/lang.h index fbd4dc6..d55a17c 100644 --- a/include/libg1m/format/lang.h +++ b/include/libg1m/format/std/lang.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/lang.h -- the G1M language file format description. + * libg1m/format/std/lang.h -- the G1M language file format description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_LANG_H -# define LIBG1M_FORMAT_LANG_H +#ifndef LIBG1M_FORMAT_STD_LANG_H +# define LIBG1M_FORMAT_STD_LANG_H # include # pragma pack(1) @@ -140,4 +140,4 @@ struct g3l_footer { /* This footer is not counted as part of the file. */ # pragma pack() -#endif /* LIBG1M_FORMAT_LANG_H */ +#endif /* LIBG1M_FORMAT_STD_LANG_H */ diff --git a/include/libg1m/format/mcs.h b/include/libg1m/format/std/mcs.h similarity index 86% rename from include/libg1m/format/mcs.h rename to include/libg1m/format/std/mcs.h index b391250..6c55c8e 100644 --- a/include/libg1m/format/mcs.h +++ b/include/libg1m/format/std/mcs.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/mcs.h -- the G1M MCS file format description. + * libg1m/format/std/mcs.h -- the G1M MCS file format description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,9 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_MCS_H -# define LIBG1M_FORMAT_MCS_H -# include +#ifndef LIBG1M_FORMAT_STD_MCS_H +# define LIBG1M_FORMAT_STD_MCS_H # include # pragma pack(1) @@ -72,5 +71,10 @@ struct mcs_fileheader { /* Beneath the file header, the file have different structures according to * their group name and MCS type. Pick your poison, once again! */ -# include -#endif /* LIBG1M_FORMAT_MCS_H */ +# include +# include +# include +# include +# include +# include +#endif /* LIBG1M_FORMAT_STD_MCS_H */ diff --git a/include/libg1m/format/picture.h b/include/libg1m/format/std/picture.h similarity index 96% rename from include/libg1m/format/picture.h rename to include/libg1m/format/std/picture.h index 5c2097a..e55cffd 100644 --- a/include/libg1m/format/picture.h +++ b/include/libg1m/format/std/picture.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/picture.h -- the G1M picture formats description. + * libg1m/format/std/picture.h -- the picture formats description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_PICTURE_H -# define LIBG1M_FORMAT_PICTURE_H +#ifndef LIBG1M_FORMAT_STD_PICTURE_H +# define LIBG1M_FORMAT_STD_PICTURE_H # include /* ************************************************************************** */ @@ -181,4 +181,4 @@ struct c2p_footer { }; # pragma pack() -#endif /* LIBG1M_FORMAT_PICTURE_H */ +#endif /* LIBG1M_FORMAT_STD_PICTURE_H */ diff --git a/include/libg1m/format/storage.h b/include/libg1m/format/std/storage.h similarity index 97% rename from include/libg1m/format/storage.h rename to include/libg1m/format/std/storage.h index e1abd6d..7324074 100644 --- a/include/libg1m/format/storage.h +++ b/include/libg1m/format/std/storage.h @@ -1,5 +1,5 @@ /* ***************************************************************************** - * libg1m/format/storage.h -- the G1M storage file format description. + * libg1m/format/std/storage.h -- the storage file format description. * Copyright (C) 2017 Thomas "Cakeisalie5" Touhey * * This file is part of libg1m. @@ -16,8 +16,8 @@ * You should have received a copy of the GNU Lesser General Public License * along with libg1m; if not, see . * ************************************************************************** */ -#ifndef LIBG1M_FORMAT_STORAGE_H -# define LIBG1M_FORMAT_STORAGE_H +#ifndef LIBG1M_FORMAT_STD_STORAGE_H +# define LIBG1M_FORMAT_STD_STORAGE_H /* Storage backup files (G1S) contain backups of the storage memory. * It corresponds exactly to the on-calc storage memory structure. @@ -182,4 +182,4 @@ struct storage_fragment { uint16_t data_length; }; -#endif /* LIBG1M_FORMAT_STORAGE_H */ +#endif /* LIBG1M_FORMAT_STD_STORAGE_H */