229 lines
8.5 KiB
C
229 lines
8.5 KiB
C
/* *****************************************************************************
|
|
* libp7/types.h -- types brought to you by libp7.
|
|
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
|
|
*
|
|
* This file is part of libp7.
|
|
* libp7 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.
|
|
*
|
|
* libp7 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 libp7; if not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
* This header contain the main types libp7 uses.
|
|
* ************************************************************************** */
|
|
#ifndef LIBP7_TYPES_H
|
|
# define LIBP7_TYPES_H
|
|
# include <libp7/config.h>
|
|
# if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) \
|
|
&& !defined(__WINDOWS__)
|
|
# define __WINDOWS__
|
|
# endif
|
|
# include <stdio.h>
|
|
# include <stdlib.h>
|
|
# include <stdint.h>
|
|
# ifdef __WINDOWS__
|
|
# include <malloc.h>
|
|
# else
|
|
# include <alloca.h>
|
|
# endif
|
|
# include <libg1m.h>
|
|
# include <libp7/cdefs.h>
|
|
# ifdef __cplusplus
|
|
extern "C" {
|
|
# endif
|
|
|
|
/* ************************************************************************** */
|
|
/* Base types */
|
|
/* ************************************************************************** */
|
|
/* The integer types used by libp7.
|
|
* They used to be defined as `uint_fast16_t` and `uint_fast32_t`, but in
|
|
* the end, I got bored and just chose the equivalents of `uint_least16_t`
|
|
* and `uint_least32_t`, which are `unsigned int` and `unsigned long`. */
|
|
|
|
typedef unsigned int p7ushort_t;
|
|
typedef unsigned long p7uint_t;
|
|
|
|
/* Also, if you want to print them using printf without knowing what's behind
|
|
* them, use these macros, it makes you 20% cooler. */
|
|
|
|
# define PRIuP7SHORT "u"
|
|
# define PRIxP7SHORT "x"
|
|
# define PRIXP7SHORT "X"
|
|
# define PRIuP7INT "lu"
|
|
# define PRIxP7INT "lx"
|
|
# define PRIXP7INT "lX"
|
|
|
|
/* And here are size_t printf formats. Oh yeah, because "zu" is not in
|
|
* the Microsoft Windows libc. Too bad, huh? */
|
|
|
|
# ifndef PRIuSIZE
|
|
# if defined(_WIN64)
|
|
# define PRIuSIZE "l64u"
|
|
# elif defined(_WIN32)
|
|
# define PRIuSIZE "u"
|
|
# else
|
|
# define PRIuSIZE "zu"
|
|
# endif
|
|
# endif
|
|
|
|
/* The handle is actually a private structure (one less cause of compatibility
|
|
* breaking!). But here are enough things to use pointers on it anyway,
|
|
* and the size of one for stack allocation using `alloca`. */
|
|
|
|
struct p7_handle_s;
|
|
typedef struct p7_handle_s p7_handle_t;
|
|
extern const size_t p7_handle_size;
|
|
|
|
/* And here is an easy macro for using alloca with this size: */
|
|
|
|
# define p7_alloca_handle() (alloca(p7_handle_size))
|
|
/* ************************************************************************** */
|
|
/* Callbacks */
|
|
/* ************************************************************************** */
|
|
/* p7_list_device_t:
|
|
* This callback is for serial devices listing; for each device found, the
|
|
* callback is found with its device. */
|
|
|
|
typedef void p7_list_device_t(void*, const char*);
|
|
|
|
/* p7_screenfunc_t:
|
|
* This callback is for `p7_getscreen`: when a screen is received, it is called
|
|
* with the width, the height and the pixels, and returns either 1 if we should
|
|
* continue, or 0 if we should stop. */
|
|
|
|
typedef int p7_screenfunc_t(int, int, uint32_t**);
|
|
|
|
/* p7_disp_t:
|
|
* This callback is for displaying the progress of an operation (usually
|
|
* file/data transfer). It receives the packet ID and the total number of
|
|
* packets. For initialization of the display, this callback is called with
|
|
* a packet ID superior to the number of packets. */
|
|
|
|
typedef void p7_disp_t(p7ushort_t, p7ushort_t);
|
|
|
|
/* p7_confirm_t:
|
|
* This callback is for if a confirmation needs to be obtained from the user
|
|
* (usually before overwriting a file). Returns 0 if the user has denied,
|
|
* and something else if he has confirmed. */
|
|
|
|
typedef int p7_confirm_t(void);
|
|
|
|
/* p7_list_t:
|
|
* This callback is for storage file listing.
|
|
* The first argument is the cookie, the second argument is the
|
|
* directory name (NULL if the file is as root), the third argument is the
|
|
* file name (NULL if the entry is a directory), and the last argument
|
|
* is the filesize, if the entry is a file. */
|
|
|
|
typedef void p7_list_t(void*, const char*, const char*, p7uint_t);
|
|
|
|
/* p7_mcslist_t:
|
|
* Basically the same as the previous one, but with the main memory.
|
|
* The MCS head given by libg1m contains the complementary information. */
|
|
|
|
typedef void p7_mcslist_t(void*, const g1m_mcshead_t*);
|
|
|
|
/* p7_server_callback_t:
|
|
* A basic server callback, for direct server. */
|
|
|
|
typedef int p7_server_callback_t(void *cookie, p7_handle_t *handle);
|
|
/* ************************************************************************** */
|
|
/* Useful types */
|
|
/* ************************************************************************** */
|
|
/* A CASIOWIN entry, which is the 0x80 bytes long entry at the beginning of
|
|
* the OS the bootcode reads for recognizing and running the OS. */
|
|
|
|
typedef struct {
|
|
/* OS version */
|
|
g1m_version_t p7_casiowin_entry_version;
|
|
|
|
/* Syscall table address */
|
|
p7uint_t p7_casiowin_entry_syscall_table_offset;
|
|
} p7_casiowin_entry_t;
|
|
/* ************************************************************************** */
|
|
/* Server information */
|
|
/* ************************************************************************** */
|
|
/* This is the information an OS can provide using extended ACK in
|
|
* Protocol 7.00 (see `protocol/seven/eack.c` for the raw format).
|
|
* Some of the members (at the end of the structure) are for serving using
|
|
* a classical server - see `libp7/server.h`. */
|
|
|
|
typedef struct {
|
|
/* preprogrammed ROM info */
|
|
int p7_server_preprog_rom_wiped;
|
|
p7uint_t p7_server_preprog_rom_capacity;
|
|
g1m_version_t p7_server_preprog_rom_version;
|
|
|
|
/* flash ROM and RAM info */
|
|
p7uint_t p7_server_flash_rom_capacity;
|
|
p7uint_t p7_server_ram_capacity;
|
|
|
|
/* bootcode info */
|
|
int p7_server_bootcode_wiped;
|
|
g1m_version_t p7_server_bootcode_version;
|
|
p7uint_t p7_server_bootcode_offset;
|
|
p7uint_t p7_server_bootcode_size;
|
|
|
|
/* OS information */
|
|
int p7_server_os_wiped;
|
|
g1m_version_t p7_server_os_version;
|
|
p7uint_t p7_server_os_offset;
|
|
p7uint_t p7_server_os_size;
|
|
|
|
/* addresses - for serving */
|
|
const unsigned char *p7_server_flash_rom;
|
|
const unsigned char *p7_server_ram;
|
|
const unsigned char *p7_server_casiowin_entry;
|
|
const unsigned char *p7_server_bootcode;
|
|
|
|
/* main information */
|
|
char p7_server_product_id[17];
|
|
char p7_server_username[17];
|
|
char p7_server_hwid[9];
|
|
char p7_server_cpuid[17];
|
|
} p7_server_t;
|
|
/* ************************************************************************** */
|
|
/* Server filesystem structure, for serving */
|
|
/* ************************************************************************** */
|
|
/* And here, we define the filesystem structure for serving using a classical
|
|
* Protocol 7.00 server (see `libp7/server.h`).
|
|
* First, here are the callbacks: */
|
|
|
|
typedef int p7_filesystem_directory_exists_t(void*, const char *p7_arg_dirname);
|
|
typedef int p7_filesystem_create_directory_t(void*, const char *p7_arg_dirname);
|
|
typedef int p7_filesystem_delete_directory_t(void*, const char *p7_arg_dirname);
|
|
typedef int p7_filesystem_rename_directory_t(void*, const char *p7_arg_dirname,
|
|
const char *p7_arg_newdir);
|
|
|
|
/* Then, here is the filesystem structure.
|
|
* It contains the static information, the callbacks and the working
|
|
* information (fields used while serving). */
|
|
|
|
typedef struct {
|
|
const char *p7_filesystem_name;
|
|
void *p7_filesystem_cookie;
|
|
|
|
/* directory commands */
|
|
p7_filesystem_directory_exists_t *p7_filesystem_directory_exists;
|
|
p7_filesystem_create_directory_t *p7_filesystem_create_directory;
|
|
p7_filesystem_delete_directory_t *p7_filesystem_delete_directory;
|
|
p7_filesystem_rename_directory_t *p7_filesystem_rename_directory;
|
|
|
|
/* working things - only libp7 should manipulate those */
|
|
char *p7_filesystem_working_directory;
|
|
char p7_filesystem__wd[257];
|
|
} p7_filesystem_t;
|
|
|
|
# ifdef __cplusplus
|
|
}
|
|
# endif
|
|
# include <libp7/buffer.h>
|
|
#endif /* LIBP7_TYPES_H */
|