233 lines
9.1 KiB
C
233 lines
9.1 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>
|
|
# include <libp7/stream.h>
|
|
# 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
|
|
# define p7_error_none 0x00
|
|
# define p7_error_success 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
|
|
# define p7_error_groupname 0x39
|
|
|
|
/* 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 */
|
|
extern int p7_validate_filename(const char *filename);
|
|
extern int p7_validate_dirname(const char *dirname);
|
|
/* ************************************************************************** */
|
|
/* Core functions */
|
|
/* ************************************************************************** */
|
|
/* Initialization flags */
|
|
# define p7_flag_active 0x00000001
|
|
# define p7_flag_check 0x00000002
|
|
# define p7_flag_term 0x00000004
|
|
|
|
/* Protocol */
|
|
# define p7_mask_protocol 0x00030000
|
|
# define p7_protocol_cas40 0x00010000
|
|
# define p7_protocol_cas50 0x00020000
|
|
# define p7_protocol_seven 0x00000000
|
|
|
|
/* Old flags (for some sort of compatibility) */
|
|
# define P7_ACTIVE p7_flag_active
|
|
# define P7_CHECK p7_flag_check
|
|
# define P7_TERM p7_flag_term
|
|
|
|
/* "Normal" initialization */
|
|
extern int p7_init(p7_handle_t **handle, unsigned int flags);
|
|
extern int p7_cominit(p7_handle_t **handle, unsigned int flags,
|
|
const char *path, const p7_streamsettings_t *settings);
|
|
extern int p7_comlist(p7_list_device_t callback, void *cookie);
|
|
|
|
/* De-initialization */
|
|
extern void p7_exit(p7_handle_t *handle);
|
|
|
|
/* ************************************************************************** */
|
|
/* MCS interaction */
|
|
/* ************************************************************************** */
|
|
/* List files */
|
|
extern int p7_mcs_list(p7_handle_t *handle, p7_mcslist_t callback,
|
|
void *cookie);
|
|
|
|
/* Request a file */
|
|
extern int p7_mcs_request(p7_handle_t *handle, g1m_mcsfile_t **file,
|
|
g1m_mcshead_t *head, p7_disp_t disp);
|
|
/* ************************************************************************** */
|
|
/* Storage memory interaction */
|
|
/* ************************************************************************** */
|
|
/* Send a file using buffer */
|
|
extern 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 */
|
|
extern 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
|
|
extern 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);
|
|
extern 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 */
|
|
extern 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 */
|
|
extern int p7_createdir(p7_handle_t *handle, const char *dirname,
|
|
const char *devname);
|
|
|
|
/* Delete distant file */
|
|
extern int p7_delete(p7_handle_t *handle,
|
|
const char *dirname, const char *filename, const char *devname);
|
|
|
|
/* Copy file on distant device */
|
|
extern int p7_copy(p7_handle_t *handle,
|
|
const char *dirname, const char *filename,
|
|
const char *newdir, const char *newname, const char *devname);
|
|
|
|
/* List files */
|
|
extern int p7_list(p7_handle_t *handle, const char *devname,
|
|
p7_list_t callback, void *cookie);
|
|
|
|
/* Get the free memory amount */
|
|
extern int p7_getfreemem(p7_handle_t *handle, const char *devname,
|
|
p7uint_t *capacity);
|
|
|
|
/* Reset filesystem on a distant device */
|
|
extern int p7_reset(p7_handle_t *handle, const char *devname);
|
|
|
|
/* Optimize distant device */
|
|
extern int p7_optimize(p7_handle_t *handle, const char *devname);
|
|
/* ************************************************************************** */
|
|
/* Miscallenous interactions */
|
|
/* ************************************************************************** */
|
|
/* Poke the calculator in order to keep it happy */
|
|
extern int p7_poke(p7_handle_t *handle);
|
|
|
|
/* Send an update.exe */
|
|
extern 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 */
|
|
extern int p7_backup_rom(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7_disp_t disp);
|
|
extern int p7_backup_ram(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7_disp_t disp);
|
|
extern int p7_backup_boot(p7_handle_t *handle, const p7_buffer_t *buffer,
|
|
p7_disp_t disp);
|
|
extern int p7_backup_casiowin_entry(p7_handle_t *handle,
|
|
p7_casiowin_entry_t *entry);
|
|
|
|
/* set link settings */
|
|
extern int p7_setlink(p7_handle_t *handle, const p7_streamsettings_t *settings);
|
|
|
|
/* FILE version of the previous functions */
|
|
# ifndef P7_DISABLED_FILE
|
|
/* Send an update.exe */
|
|
extern int p7_sendexe_file(p7_handle_t *handle,
|
|
FILE *exe, p7uint_t loadaddr, p7uint_t straddr,
|
|
p7_disp_t disp);
|
|
extern int p7_backup_romfile(p7_handle_t *handle, FILE *file,
|
|
p7_disp_t disp);
|
|
extern int p7_backup_ramfile(p7_handle_t *handle, FILE *file,
|
|
p7_disp_t disp);
|
|
extern int p7_backup_bootfile(p7_handle_t *handle, FILE *file,
|
|
p7_disp_t disp);
|
|
# endif
|
|
|
|
/* Memory version of the previous functions */
|
|
extern 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 */
|
|
extern int p7_getscreen(p7_handle_t *handle, p7_screenfunc_t callback);
|
|
|
|
# ifdef __cplusplus
|
|
}
|
|
# endif
|
|
# include <libp7/server.h>
|
|
#endif /* LIBP7_H */
|