cake
/
libg1m
Archived
1
0
Fork 0
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libg1m/include/libg1m/mcs.h

144 lines
5.1 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 PRIXMCSTYPE "lX"
# define PRIxMCSTYPE "lx"
# define PRIuMCSTYPE "lu"
typedef long unsigned int g1m_mcsfile_type_t;
typedef g1m_mcsfile_type_t g1m_mcstype_t;
# 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_alphamem g1m_mcstype_var
# define g1m_mcstype_variable g1m_mcstype_var
# define g1m_mcstype_variables g1m_mcstype_var
/* 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 */
/* ************************************************************************** */
/* List, Matrix, Vector and Spreadsheet cell. */
typedef struct g1m_mcs_cell_s {
g1m_bcd_t real;
g1m_bcd_t imgn;
int used;
} g1m_mcs_cell_t;
/* ************************************************************************** */
/* Main structures */
/* ************************************************************************** */
/* mcs file head 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 */
# define g1m_mcsflag_complex 0x0001 /* is a complex variable */
/* mcs file type -- what type of raw information is there
* e.g. `head.flags & g1m_mcsmask_info == g1m_mcsinfo_g1m` */
# define g1m_mcsinfo(H) ((H)->flags & g1m_mcsmask_info)
# define g1m_mcsmask_info 0x0600
# define g1m_mcsinfo_none 0x0000
# define g1m_mcsinfo_mcs 0x0200
# define g1m_mcsinfo_cas 0x0400
# define g1m_mcsinfo_caspro 0x0600
/* mcs file head */
typedef struct g1m_mcshead_s {
/* file main information */
g1m_mcstype_t type;
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];
unsigned char _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_mcs_cell_t var;
g1m_mcs_cell_t *vars;
g1m_mcs_cell_t **cells;
/* for pictures and captures */
uint32_t **pic; /* 0x0RGB */
uint32_t ***pics;
} g1m_mcsfile_t;
#endif /* LIBG1M_MCS_H */