/* ***************************************************************************** * libp7/types.h -- types brought to you by libp7. * Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey * * 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 . * * This header contain the main types libp7 uses. * ************************************************************************** */ #ifndef LIBP7_TYPES_H # define LIBP7_TYPES_H # include # if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) \ && !defined(__WINDOWS__) # define __WINDOWS__ # endif # include # include # include # ifdef __WINDOWS__ # include # else # include # endif # include # 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*); /* ************************************************************************** */ /* Useful types */ /* ************************************************************************** */ /* An OS version. Must be of ASCII-DEC format MM.mm.ffff, where MM is the * major, mm is the minor and ffff is the revision (flags). */ typedef struct { unsigned int major; unsigned int minor; unsigned int rev; } p7_version_t; /* 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 */ p7_version_t version; /* Syscall table address */ p7uint_t 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 { /* main information */ char product_id[17], username[17]; char hwid[9], cpuid[17]; /* preprogrammed ROM info */ int preprog_rom_wiped; p7uint_t preprog_rom_capacity; p7_version_t preprog_rom_version; /* flash ROM and RAM info */ p7uint_t flash_rom_capacity, ram_capacity; /* bootcode info */ int bootcode_wiped; p7_version_t bootcode_version; p7uint_t bootcode_offset, bootcode_size; /* OS information */ int os_wiped; p7_version_t os_version; p7uint_t os_offset, os_size; /* addresses - for serving */ const unsigned char *flash_rom, *ram; const unsigned char *casiowin_entry, *bootcode; } p7_server_t; /* And here is the filesystem structure for serving using a classical * Protocol 7.00 server (see `libp7/server.h`). * It contains the static information, the callbacks and the working * information (fields used while serving). */ typedef struct { /* filesystem metadata */ const char *name; void *cookie; /* directory commands */ int (*directory_exists)(void *cookie, const char *dirname); int (*create_directory)(void *cookie, const char *dirname); int (*delete_directory)(void *cookie, const char *dirname); int (*rename_directory)(void *cookie, const char *dirname, const char *newdir); /* working things - only libp7 should manipulate those */ char *working_directory, _wd[257]; } p7_filesystem_t; # ifdef __cplusplus } # endif # include #endif /* LIBP7_TYPES_H */