150 lines
5.3 KiB
C
150 lines
5.3 KiB
C
/* *****************************************************************************
|
|
* libg1m/mcs.h -- libg1m main memory header.
|
|
* 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_MCS_H
|
|
# define LIBG1M_MCS_H
|
|
# include <libg1m/bcd.h>
|
|
# include <libg1m/picture.h>
|
|
# include <inttypes.h>
|
|
# define g1m_theta 27
|
|
# define g1m_r 28
|
|
# define g1m_ans 29
|
|
|
|
/* ************************************************************************** */
|
|
/* Main Memory Types */
|
|
/* ************************************************************************** */
|
|
/* MCS file type */
|
|
# define PRIuMCSTYPE "lu"
|
|
# define PRIxMCSTYPE "lx"
|
|
# define PRIXMCSTYPE "lX"
|
|
typedef long unsigned int g1m_mcsfile_type_t;
|
|
typedef g1m_mcsfile_type_t g1m_mcstype_t;
|
|
|
|
/* MCS file types */
|
|
# define g1m_mcstype_unknown 0x00000000
|
|
# define g1m_mcstype_program 0x00000001
|
|
# define g1m_mcstype_list 0x00000002
|
|
# define g1m_mcstype_mat 0x00000004
|
|
# define g1m_mcstype_pict 0x00000008
|
|
# define g1m_mcstype_capt 0x00000010
|
|
# define g1m_mcstype_ssheet 0x00000020
|
|
# define g1m_mcstype_string 0x00000040
|
|
# define g1m_mcstype_setup 0x00000080
|
|
# define g1m_mcstype_var 0x00000100
|
|
# define g1m_mcstype_vct 0x00000200
|
|
# define g1m_mcstype_end 0x00000400
|
|
|
|
/* MCS file type aliases */
|
|
# define g1m_mcstype_matrix g1m_mcstype_mat
|
|
# define g1m_mcstype_pic g1m_mcstype_pict
|
|
# define g1m_mcstype_picture g1m_mcstype_pict
|
|
# define g1m_mcstype_capture g1m_mcstype_capt
|
|
# define g1m_mcstype_spreadsheet g1m_mcstype_ssheet
|
|
# define g1m_mcstype_vector g1m_mcstype_vct
|
|
# define g1m_mcstype_alpha g1m_mcstype_var
|
|
# define g1m_mcstype_alphamem g1m_mcstype_var
|
|
# define g1m_mcstype_variable g1m_mcstype_var
|
|
# define g1m_mcstype_variables g1m_mcstype_var
|
|
|
|
/* MCS file platform */
|
|
typedef unsigned int g1m_mcsinfo_t;
|
|
# define g1m_mcsinfo_none 0x0000
|
|
# define g1m_mcsinfo_mcs 0x0001
|
|
# define g1m_mcsinfo_cas40 0x0002
|
|
# define g1m_mcsinfo_cas g1m_mcsinfo_cas40
|
|
# define g1m_mcsinfo_cas50 0x0004
|
|
# define g1m_mcsinfo_caspro g1m_mcsinfo_cas50
|
|
# define g1m_mcsinfo_cas100 0x0008
|
|
# define g1m_mcsinfo_graph100 g1m_mcsinfo_cas100
|
|
|
|
/* Macros to check if the type uses the ID, and to interact with it */
|
|
# define g1m_mcshead_uses_id(H) (((H)->type & (\
|
|
g1m_mcstype_list | g1m_mcstype_mat | g1m_mcstype_vct | \
|
|
g1m_mcstype_pict | g1m_mcstype_capt | g1m_mcstype_string) || \
|
|
((H)->type == g1m_mcstype_var && (H)->count == 1)))
|
|
# define g1m_get_id_major(I) ((I) >> 5)
|
|
# define g1m_get_id_minor(I) ((I) & 31)
|
|
/* ************************************************************************** */
|
|
/* Helpers */
|
|
/* ************************************************************************** */
|
|
/* MCS cell flags */
|
|
# define g1m_mcscellflag_used 0x0001
|
|
|
|
/* List, Matrix, Vector and Spreadsheet cell. */
|
|
typedef struct g1m_mcs_cell_s {
|
|
g1m_bcd_t real, imgn;
|
|
unsigned int flags;
|
|
} g1m_mcscell_t;
|
|
/* ************************************************************************** */
|
|
/* Main structures */
|
|
/* ************************************************************************** */
|
|
/* mcs file special flags */
|
|
# define g1m_mcsflag_unfinished 0x8000 /* is there still parts to read? */
|
|
# define g1m_mcsflag_multiple 0x4000 /* is a group */
|
|
# define g1m_mcsflag_request 0x2000 /* is a request */
|
|
|
|
/* mcs file content flags */
|
|
# define g1m_mcsflag_complex 0x0001 /* is a complex variable */
|
|
|
|
/* mcs file head */
|
|
typedef struct g1m_mcshead_s {
|
|
/* file main information */
|
|
g1m_mcstype_t type;
|
|
g1m_mcsinfo_t info;
|
|
char name[13]; int id;
|
|
unsigned int flags;
|
|
|
|
/* content size */
|
|
int count;
|
|
unsigned int width, height;
|
|
uint_fast32_t size;
|
|
|
|
/* mcs-related raw data */
|
|
unsigned int _rawtype;
|
|
unsigned char _group[17], _dirname[9];
|
|
|
|
/* cas-related raw data */
|
|
unsigned char _appname[4], _datatype[3];
|
|
g1m_pictureformat_t _picformat;
|
|
|
|
/* the program password */
|
|
char password[9];
|
|
} g1m_mcshead_t;
|
|
|
|
/* mcs file */
|
|
# define g1m_has_password(F) (F)->head.password[0]
|
|
# define g1m_remove_password(F) (F)->head.password[0] = 0
|
|
typedef struct g1m_mcsfile_s {
|
|
/* head */
|
|
g1m_mcshead_t head;
|
|
|
|
/* content (useful when not read) */
|
|
char *content;
|
|
|
|
/* variables */
|
|
g1m_mcscell_t var;
|
|
g1m_mcscell_t *vars;
|
|
g1m_mcscell_t **cells;
|
|
|
|
/* for pictures and captures */
|
|
uint32_t **pic; /* 0x0RGB */
|
|
uint32_t ***pics;
|
|
} g1m_mcsfile_t;
|
|
|
|
#endif /* LIBG1M_MCS_H */
|