224 lines
8.4 KiB
C
224 lines
8.4 KiB
C
/* *****************************************************************************
|
|
* libp7.h -- libp7 main public header.
|
|
* 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/>.
|
|
*
|
|
* WARNING: Do NOT include this header using <libp7-(version)/libp7.h>!
|
|
* Compile with either `libp7-config --cflags` or `pkg-config libp7 --cflags`,
|
|
* and include using <libp7.h>.
|
|
* ************************************************************************** */
|
|
#ifndef LIBP7_H
|
|
# define LIBP7_H
|
|
# include <libp7/types.h>
|
|
|
|
/* allocate handle in stack */
|
|
# ifdef __WINDOWS__
|
|
# include <malloc.h>
|
|
# else
|
|
# include <alloca.h>
|
|
# endif
|
|
# define p7_alloca_handle() (alloca(p7_handle_size))
|
|
|
|
# ifdef __cplusplus
|
|
extern "C" {
|
|
# endif
|
|
|
|
/* ************************************************************************** */
|
|
/* libp7 errors */
|
|
/* ************************************************************************** */
|
|
/* WARNING: Whenever you add/remove errors, think about updating core/strerror!
|
|
* ---
|
|
* First, the none error. */
|
|
# define p7_noerror 0x00
|
|
|
|
/* Other errors */
|
|
# define p7_error_unknown 0x01
|
|
# define p7_error_unsupported 0x02
|
|
# define p7_error_unsupported_device 0x03
|
|
# define p7_error_alloc 0x04
|
|
|
|
/* Basic communication errors */
|
|
# define p7_error_uninitialized 0x10
|
|
# define p7_error_nocalc 0x11
|
|
# define p7_error_noaccess 0x12
|
|
# define p7_error_nochar 0x13
|
|
# define p7_error_com 0x14
|
|
# define p7_error_timeout 0x15
|
|
# define p7_error_checksum 0x16
|
|
# define p7_error_irrecoverable 0x17
|
|
# define p7_error_interrupted 0x18
|
|
# define p7_error_terminated 0x19
|
|
|
|
/* Stream errors */
|
|
# define p7_error_nostream 0x20
|
|
# define p7_error_nobuffer 0x20
|
|
# define p7_error_nobuf 0x20
|
|
# define p7_error_noread 0x21
|
|
# define p7_error_nowrite 0x22
|
|
# define p7_error_noseek 0x23
|
|
|
|
/* User interface errors */
|
|
# define p7_error_active 0x30
|
|
# define p7_error_doubleshift 0x31
|
|
# define p7_error_empty 0x32
|
|
# define p7_error_filename 0x34
|
|
# define p7_error_dirname 0x35
|
|
# define p7_error_fullmem 0x36
|
|
# define p7_error_notfound 0x37
|
|
# define p7_error_denied_overwrite 0x38
|
|
|
|
/* Error type -- for compatibility with old programs using enum */
|
|
typedef int p7_error_t;
|
|
|
|
/* Message getting macro */
|
|
extern const char *p7_error_strings[];
|
|
# define p7_strerror(N) p7_error_strings[N]
|
|
# define p7_geterror(N) p7_error_strings[N]
|
|
|
|
/* ************************************************************************** */
|
|
/* Random stuff */
|
|
/* ************************************************************************** */
|
|
/* Filename and dirname */
|
|
int p7_validate_filename(const char *filename);
|
|
int p7_validate_dirname(const char *dirname);
|
|
|
|
/* ************************************************************************** */
|
|
/* Core functions */
|
|
/* ************************************************************************** */
|
|
/* Initialization and exit flags */
|
|
# define P7_ACTIVE 1
|
|
# define P7_CHECK 2
|
|
# define P7_TERM 4
|
|
|
|
/* "Normal" initialization */
|
|
int p7_init(p7_handle_t **handle, unsigned int flags);
|
|
int p7_cominit(p7_handle_t **handle, unsigned int flags, const char *path);
|
|
int p7_comlist(void (*callback)(void*, const char*), void *cookie);
|
|
|
|
/* De-initialization */
|
|
void p7_exit(p7_handle_t *handle);
|
|
|
|
/* ************************************************************************** */
|
|
/* MCS interaction */
|
|
/* ************************************************************************** */
|
|
/* List files */
|
|
int p7_mcs_list(p7_handle_t *handle,
|
|
void (*callback)(void*, const g1m_mcshead_t *head), void *cookie);
|
|
|
|
/* ************************************************************************** */
|
|
/* Storage memory interaction */
|
|
/* ************************************************************************** */
|
|
/* Send a file using buffer */
|
|
int p7_send(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
const char *dirname, const char *filename, const char *devname,
|
|
int overwrite, p7_confirm_t confirm, p7_disp_t disp);
|
|
|
|
/* Receive a file using buffer */
|
|
int p7_request(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
const char *dirname, const char *filename, const char *devname,
|
|
p7_disp_t disp);
|
|
|
|
/* FILE version of the two previous functions */
|
|
# ifndef P7_DISABLED_FILE
|
|
int p7_sendfile(p7_handle_t *handle, FILE *file,
|
|
const char *dirname, const char *filename, const char *devname,
|
|
int overwrite, p7_confirm_t confirm, p7_disp_t disp);
|
|
int p7_reqfile(p7_handle_t *handle, FILE *file,
|
|
const char *dirname, const char *filename, const char *devname,
|
|
p7_disp_t disp);
|
|
# endif
|
|
|
|
/* Memory version of the send function */
|
|
int p7_sendmem(p7_handle_t *handle, const void *mem, size_t size,
|
|
const char *dirname, const char *filename, const char *devname,
|
|
int overwrite, p7_confirm_t confirm, p7_disp_t disp);
|
|
|
|
/* Create a directory */
|
|
int p7_createdir(p7_handle_t *handle, const char *dirname, const char *devname);
|
|
|
|
/* Delete distant file */
|
|
int p7_delete(p7_handle_t *handle,
|
|
const char *dirname, const char *filename, const char *devname);
|
|
|
|
/* Copy file on distant device */
|
|
int p7_copy(p7_handle_t *handle,
|
|
const char *dirname, const char *filename,
|
|
const char *newdir, const char *newname, const char *devname);
|
|
|
|
/* List files */
|
|
int p7_list(p7_handle_t *handle, const char *devname,
|
|
p7_list_t callback, void *cookie);
|
|
|
|
/* Get the free memory amount */
|
|
int p7_getfreemem(p7_handle_t *handle, const char *devname,
|
|
p7uint_t *capacity);
|
|
|
|
/* Reset filesystem on a distant device */
|
|
int p7_reset(p7_handle_t *handle, const char *devname);
|
|
|
|
/* Optimize distant device */
|
|
int p7_optimize(p7_handle_t *handle, const char *devname);
|
|
|
|
/* ************************************************************************** */
|
|
/* Miscallenous interactions */
|
|
/* ************************************************************************** */
|
|
/* Poke the calculator in order to keep it happy */
|
|
int p7_poke(p7_handle_t *handle);
|
|
|
|
/* Send an update.exe */
|
|
int p7_sendexe(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7uint_t loadaddr, p7uint_t straddr, void (*disp)(p7ushort_t, p7ushort_t));
|
|
|
|
/* Backup the flash ROM, bootcode and CASIOWIN entry */
|
|
int p7_backup_rom(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7_disp_t disp);
|
|
int p7_backup_ram(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7_disp_t disp);
|
|
int p7_backup_boot(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7_disp_t disp);
|
|
int p7_backup_casiowin_entry(p7_handle_t *handle, p7_casiowin_entry_t *entry);
|
|
|
|
/* set link settings */
|
|
int p7_setlink(p7_handle_t *handle, int baudrate, int parity, int stopbits);
|
|
|
|
/* FILE version of the previous functions */
|
|
# ifndef P7_DISABLED_FILE
|
|
/* Send an update.exe */
|
|
int p7_sendexe_file(p7_handle_t *handle,
|
|
FILE *exe, p7uint_t loadaddr, p7uint_t straddr,
|
|
p7_disp_t disp);
|
|
int p7_backup_romfile(p7_handle_t *handle, FILE *file,
|
|
p7_disp_t disp);
|
|
int p7_backup_ramfile(p7_handle_t *handle, FILE *file,
|
|
p7_disp_t disp);
|
|
int p7_backup_bootfile(p7_handle_t *handle, FILE *file,
|
|
p7_disp_t disp);
|
|
# endif
|
|
|
|
/* Memory version of the previous functions */
|
|
int p7_sendexe_mem(p7_handle_t *handle,
|
|
const void *mem, size_t size, p7uint_t loadaddr, p7uint_t straddr,
|
|
p7_disp_t disp);
|
|
|
|
/* Display streamed screen */
|
|
int p7_getscreen(p7_handle_t *handle, int (*callback)(int, int, uint32_t**));
|
|
|
|
# ifdef __cplusplus
|
|
}
|
|
# endif
|
|
# include <libp7/server.h>
|
|
#endif /* LIBP7_H */
|