cake
/
libg1m
Archived
1
0
Fork 0

Reorganized headers.

This commit is contained in:
Thomas Touhey 2017-02-28 17:08:52 +01:00
parent aba8d1db06
commit ec87751909
16 changed files with 471 additions and 335 deletions

View File

@ -20,116 +20,47 @@
# define LIBG1M_FORMAT_H
# include <stdint.h>
/* 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 <libg1m/format/cas.h>
/* ************************************************************************** */
/* 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 <libg1m/format/fxi.h>
/* ************************************************************************** */
/* 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 <libg1m/format/addin.h>
# include <libg1m/format/eact.h>
# include <libg1m/format/mcs.h>
# include <libg1m/format/storage.h>
# include <libg1m/format/picture.h>
# include <libg1m/format/lang.h>
# include <libg1m/format/fkey.h>
# include <libg1m/format/std.h>
#endif /* LIBG1M_FORMAT_H */

View File

@ -0,0 +1,49 @@
/* *****************************************************************************
* libg1m/format/mcs/list.h -- description of the MCS list format.
* 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/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_MCS_LIST_H
# define LIBG1M_FORMAT_MCS_LIST_H
# include <libg1m/bcd.h>
# 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 */

View File

@ -0,0 +1,53 @@
/* *****************************************************************************
* libg1m/format/mcs/matrix.h -- description of the MCS matrix format.
* 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/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_MCS_MATRIX_H
# define LIBG1M_FORMAT_MCS_MATRIX_H
# include <libg1m/bcd.h>
# 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 */

View File

@ -0,0 +1,41 @@
/* *****************************************************************************
* libg1m/format/mcs/picture.h -- description of the MCS picture format.
* 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/>.
* ************************************************************************** */
#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 */

View File

@ -0,0 +1,37 @@
/* *****************************************************************************
* libg1m/format/mcs/program.h -- description of the MCS program format.
* 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/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_MCS_PROGRAM_H
# define LIBG1M_FORMAT_MCS_PROGRAM_H
# include <libfontcharacter.h>
# 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 */

View File

@ -0,0 +1,74 @@
/* *****************************************************************************
* libg1m/format/mcs/setup.h -- description of the MCS setup file format.
* 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/>.
* ************************************************************************** */
#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<T);
* [0x2B] Display (0x00: Norm1, 0x10: Norm2, 0x20-0x29: Fix[0-9],
* 0x30-0x39: Sci[0-9] -- bit 0x80 toggles /E mode);
* [0x2C] Background (0x00: None, 0x01-0x14: Pict[1-20]);
* [0x2D] Resid List (0x00: None, 0x01-0x1A: List[1-26]);
* [0x2E] List File (0x01-0x06: File[1-6]);
* [0x2F] Variable (0x00: Range, 0x01-0x26: List[1-26]);
* [0x31] Recur Dual (Dual Screen) (0x00: T+G, 0x01: OFF);
* [0x4E] Auto Calc;
* [0x4F] Show Sell (Show cell) (0x00: Formula, 0x01: Value);
* [0x50] Move (0x00: Lower, 0x01: Right);
* [0x51] Sub Name (0x00: ON, 0x01: OFF);
* [0x53] Input Mode (0x00: Math, 0x01: Linear);
* [0x54] Locus;
* [0x55] Y=Draw Speed (0x00: Norm, 0x01: High);
* [0x56] Sketch Line (0x00: Norm, 0x01: Thick, 0x02: Broken, 0x03: Dot);
* [0x57] Frac Result (0x00: d/c, 0x01: a+b/c);
* [0x5C] Q1Q3 Type (0x00: Std, 0x01: OnD [STAT]);
* [0x5D] Ineq Type (0x00: Intersect (And), 0x01: Union (Or) [GRAPH]);
* [0x5E] Periods/Yr. (0x00: Annu, 0x01: Semi [TVM]);
* [0x5F] Simplify (0x00: Auto, 0x01: Manual);
*
* When options aren't given, it's 0x00 for ON, and 0x01 for OFF. */
#endif /* LIBG1M_FORMAT_MCS_SETUP_H */

View File

@ -0,0 +1,64 @@
/* *****************************************************************************
* libg1m/format/mcs/spreadsheet.h -- description of the MCS spreadsheet format.
* 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/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_MCS_SPREADSHEET_H
# define LIBG1M_FORMAT_MCS_SPREADSHEET_H
# include <libg1m/bcd.h>
# 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 */

View File

@ -1,213 +0,0 @@
/* *****************************************************************************
* libg1m/format/mcsfile.h -- description of the MCS subfiles formats.
* 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/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_MCSFILE_H
# define LIBG1M_FORMAT_MCSFILE_H
# include <libg1m/format/mcs.h>
# include <libg1m/bcd.h>
# 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<T);
* [0x2B] Display (0x00: Norm1, 0x10: Norm2, 0x20-0x29: Fix[0-9],
* 0x30-0x39: Sci[0-9] -- bit 0x80 toggles /E mode);
* [0x2C] Background (0x00: None, 0x01-0x14: Pict[1-20]);
* [0x2D] Resid List (0x00: None, 0x01-0x1A: List[1-26]);
* [0x2E] List File (0x01-0x06: File[1-6]);
* [0x2F] Variable (0x00: Range, 0x01-0x26: List[1-26]);
* [0x31] Recur Dual (Dual Screen) (0x00: T+G, 0x01: OFF);
* [0x4E] Auto Calc;
* [0x4F] Show Sell (Show cell) (0x00: Formula, 0x01: Value);
* [0x50] Move (0x00: Lower, 0x01: Right);
* [0x51] Sub Name (0x00: ON, 0x01: OFF);
* [0x53] Input Mode (0x00: Math, 0x01: Linear);
* [0x54] Locus;
* [0x55] Y=Draw Speed (0x00: Norm, 0x01: High);
* [0x56] Sketch Line (0x00: Norm, 0x01: Thick, 0x02: Broken, 0x03: Dot);
* [0x57] Frac Result (0x00: d/c, 0x01: a+b/c);
* [0x5C] Q1Q3 Type (0x00: Std, 0x01: OnD [STAT]);
* [0x5D] Ineq Type (0x00: Intersect (And), 0x01: Union (Or) [GRAPH]);
* [0x5E] Periods/Yr. (0x00: Annu, 0x01: Semi [TVM]);
* [0x5F] Simplify (0x00: Auto, 0x01: Manual);
*
* When options aren't given, it's 0x00 for ON, and 0x01 for OFF. */
/* ************************************************************************** */
/* Spreadsheets */
/* ************************************************************************** */
/* 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. */
/* ************************************************************************** */
/* Captures */
/* ************************************************************************** */
/* 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 */
/* ************************************************************************** */
/* Pictures don't have any header: it's just two 128x64 images (packed 1-bit)
* and that's all. */
/* ************************************************************************** */
/* Lists */
/* ************************************************************************** */
/* 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! */
/* ************************************************************************** */
/* Matrixes and vectors */
/* ************************************************************************** */
/* 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_MCSFILE_H */

View File

@ -0,0 +1,96 @@
/* *****************************************************************************
* libg1m/format/std.h -- the CASIO "standard" file format description.
* 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/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_STD_H
# define LIBG1M_FORMAT_STD_H
# include <stdint.h>
# 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 <libg1m/format/std/addin.h>
# include <libg1m/format/std/eact.h>
# include <libg1m/format/std/mcs.h>
# include <libg1m/format/std/storage.h>
# include <libg1m/format/std/picture.h>
# include <libg1m/format/std/lang.h>
# include <libg1m/format/std/fkey.h>
#endif /* LIBG1M_FORMAT_STD_H */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_ADDIN_H
# define LIBG1M_FORMAT_ADDIN_H
#ifndef LIBG1M_FORMAT_STD_ADDIN_H
# define LIBG1M_FORMAT_STD_ADDIN_H
# include <stdint.h>
# pragma pack(1)
@ -200,4 +200,4 @@ struct c1a_subheader {
};
# pragma pack()
#endif /* LIBG1M_FORMAT_ADDIN_H */
#endif /* LIBG1M_FORMAT_STD_ADDIN_H */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_EACT_H
# define LIBG1M_FORMAT_EACT_H
#ifndef LIBG1M_FORMAT_STD_EACT_H
# define LIBG1M_FORMAT_STD_EACT_H
# include <stdint.h>
/* 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 */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_FKEY_H
# define LIBG1M_FORMAT_FKEY_H
#ifndef LIBG1M_FORMAT_STD_FKEY_H
# define LIBG1M_FORMAT_STD_FKEY_H
# include <libg1m.h>
# 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 */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_LANG_H
# define LIBG1M_FORMAT_LANG_H
#ifndef LIBG1M_FORMAT_STD_LANG_H
# define LIBG1M_FORMAT_STD_LANG_H
# include <libg1m.h>
# 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 */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_MCS_H
# define LIBG1M_FORMAT_MCS_H
# include <libg1m.h>
#ifndef LIBG1M_FORMAT_STD_MCS_H
# define LIBG1M_FORMAT_STD_MCS_H
# include <stdint.h>
# 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 <libg1m/format/mcsfile.h>
#endif /* LIBG1M_FORMAT_MCS_H */
# include <libg1m/format/mcs/list.h>
# include <libg1m/format/mcs/matrix.h>
# include <libg1m/format/mcs/picture.h>
# include <libg1m/format/mcs/program.h>
# include <libg1m/format/mcs/setup.h>
# include <libg1m/format/mcs/spreadsheet.h>
#endif /* LIBG1M_FORMAT_STD_MCS_H */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef LIBG1M_FORMAT_PICTURE_H
# define LIBG1M_FORMAT_PICTURE_H
#ifndef LIBG1M_FORMAT_STD_PICTURE_H
# define LIBG1M_FORMAT_STD_PICTURE_H
# include <stdint.h>
/* ************************************************************************** */
@ -181,4 +181,4 @@ struct c2p_footer {
};
# pragma pack()
#endif /* LIBG1M_FORMAT_PICTURE_H */
#endif /* LIBG1M_FORMAT_STD_PICTURE_H */

View File

@ -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 <thomas@touhey.fr>
*
* 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 <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#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 */