cake
/
libp7
Archived
1
0
Fork 1
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.
libp7/include/libp7.h

233 lines
9.1 KiB
C
Raw Normal View History

/* *****************************************************************************
* 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/>.
2017-02-23 19:20:53 +01:00
*
* 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>.
* ************************************************************************** */
2016-08-16 21:33:44 +02:00
#ifndef LIBP7_H
# define LIBP7_H
2017-02-07 17:54:11 +01:00
# include <libp7/types.h>
2017-03-11 14:17:44 +01:00
# include <libp7/stream.h>
# ifdef __cplusplus
extern "C" {
# endif
2016-08-18 06:01:06 +02:00
/* ************************************************************************** */
/* libp7 errors */
/* ************************************************************************** */
2017-02-15 11:03:06 +01:00
/* WARNING: Whenever you add/remove errors, think about updating core/strerror!
* ---
* First, the none error. */
# define p7_noerror 0x00
2017-03-11 14:17:44 +01:00
# define p7_error_none 0x00
# define p7_error_success 0x00
2016-08-20 19:47:31 +02:00
2017-02-15 11:03:06 +01:00
/* Other errors */
# define p7_error_unknown 0x01
# define p7_error_unsupported 0x02
# define p7_error_unsupported_device 0x03
# define p7_error_alloc 0x04
2016-08-19 00:56:56 +02:00
2017-02-15 11:03:06 +01:00
/* 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
2016-10-08 22:30:35 +02:00
2017-02-15 11:03:06 +01:00
/* 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
2017-02-15 11:03:06 +01:00
/* 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
2017-02-15 11:03:06 +01:00
/* Error type -- for compatibility with old programs using enum */
typedef int p7_error_t;
2016-08-17 00:04:19 +02:00
2016-09-25 22:01:42 +02:00
/* Message getting macro */
2016-10-05 22:31:01 +02:00
extern const char *p7_error_strings[];
2017-01-26 14:25:43 +01:00
# define p7_strerror(N) p7_error_strings[N]
# define p7_geterror(N) p7_error_strings[N]
/* ************************************************************************** */
2017-01-13 13:33:09 +01:00
/* Random stuff */
/* ************************************************************************** */
/* Filename and dirname */
2017-03-23 15:39:47 +01:00
extern int p7_validate_filename(const char *filename);
extern int p7_validate_dirname(const char *dirname);
2016-08-18 06:01:06 +02:00
/* ************************************************************************** */
/* Core functions */
/* ************************************************************************** */
2017-03-23 15:39:47 +01:00
/* Initialization flags */
# define p7_flag_active 0x00000001
# define p7_flag_check 0x00000002
# define p7_flag_term 0x00000004
/* Protocol */
# define p7_mask_protocol 0x00030000
2017-03-25 16:35:34 +01:00
# define p7_protocol_cas40 0x00010000
# define p7_protocol_cas50 0x00020000
2017-03-23 15:39:47 +01:00
# 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
2017-01-26 14:25:43 +01:00
2017-01-13 13:33:09 +01:00
/* "Normal" initialization */
2017-03-23 15:39:47 +01:00
extern int p7_init(p7_handle_t **handle, unsigned int flags);
2017-03-24 16:03:27 +01:00
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);
2017-01-13 13:33:09 +01:00
2016-10-28 14:39:51 +02:00
/* De-initialization */
2017-03-23 15:39:47 +01:00
extern void p7_exit(p7_handle_t *handle);
/* ************************************************************************** */
/* MCS interaction */
2016-08-18 07:31:24 +02:00
/* ************************************************************************** */
/* List files */
2017-03-23 15:39:47 +01:00
extern int p7_mcs_list(p7_handle_t *handle, p7_mcslist_t callback,
void *cookie);
2017-02-25 11:53:47 +01:00
/* Request a file */
2017-03-23 15:39:47 +01:00
extern int p7_mcs_request(p7_handle_t *handle, g1m_mcsfile_t **file,
2017-03-03 17:06:19 +01:00
g1m_mcshead_t *head, p7_disp_t disp);
/* ************************************************************************** */
/* Storage memory interaction */
2016-08-18 07:31:24 +02:00
/* ************************************************************************** */
2017-02-05 20:12:25 +01:00
/* Send a file using buffer */
2017-03-23 15:39:47 +01:00
extern int p7_send(p7_handle_t *handle, const p7_buffer_t *buffer,
2016-10-05 22:31:01 +02:00
const char *dirname, const char *filename, const char *devname,
int overwrite, p7_confirm_t confirm, p7_disp_t disp);
2017-02-05 20:12:25 +01:00
/* Receive a file using buffer */
2017-03-23 15:39:47 +01:00
extern int p7_request(p7_handle_t *handle, const p7_buffer_t *buffer,
2017-02-05 20:12:25 +01:00
const char *dirname, const char *filename, const char *devname,
p7_disp_t disp);
2017-02-05 20:12:25 +01:00
/* FILE version of the two previous functions */
# ifndef P7_DISABLED_FILE
2017-03-23 15:39:47 +01:00
extern int p7_sendfile(p7_handle_t *handle, FILE *file,
2016-10-05 22:31:01 +02:00
const char *dirname, const char *filename, const char *devname,
int overwrite, p7_confirm_t confirm, p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_reqfile(p7_handle_t *handle, FILE *file,
2016-10-05 22:31:01 +02:00
const char *dirname, const char *filename, const char *devname,
p7_disp_t disp);
# endif
/* Memory version of the send function */
2017-03-23 15:39:47 +01:00
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);
2017-01-27 15:20:41 +01:00
/* Create a directory */
2017-03-23 15:39:47 +01:00
extern int p7_createdir(p7_handle_t *handle, const char *dirname,
const char *devname);
2017-01-27 15:20:41 +01:00
2016-08-22 16:37:26 +02:00
/* Delete distant file */
2017-03-23 15:39:47 +01:00
extern int p7_delete(p7_handle_t *handle,
2016-10-05 22:31:01 +02:00
const char *dirname, const char *filename, const char *devname);
2016-08-22 16:37:26 +02:00
2016-09-05 01:43:26 +02:00
/* Copy file on distant device */
2017-03-23 15:39:47 +01:00
extern int p7_copy(p7_handle_t *handle,
2016-10-05 22:31:01 +02:00
const char *dirname, const char *filename,
const char *newdir, const char *newname, const char *devname);
2016-09-05 01:43:26 +02:00
/* List files */
2017-03-23 15:39:47 +01:00
extern int p7_list(p7_handle_t *handle, const char *devname,
p7_list_t callback, void *cookie);
/* Get the free memory amount */
2017-03-23 15:39:47 +01:00
extern int p7_getfreemem(p7_handle_t *handle, const char *devname,
2017-01-27 15:20:41 +01:00
p7uint_t *capacity);
/* Reset filesystem on a distant device */
2017-03-23 15:39:47 +01:00
extern int p7_reset(p7_handle_t *handle, const char *devname);
2016-12-17 22:08:49 +01:00
/* Optimize distant device */
2017-03-23 15:39:47 +01:00
extern int p7_optimize(p7_handle_t *handle, const char *devname);
/* ************************************************************************** */
/* Miscallenous interactions */
/* ************************************************************************** */
/* Poke the calculator in order to keep it happy */
2017-03-23 15:39:47 +01:00
extern int p7_poke(p7_handle_t *handle);
2016-09-28 05:24:00 +02:00
/* Send an update.exe */
2017-03-23 15:39:47 +01:00
extern int p7_sendexe(p7_handle_t *handle, const p7_buffer_t *buffer,
2017-02-05 20:12:25 +01:00
p7uint_t loadaddr, p7uint_t straddr, void (*disp)(p7ushort_t, p7ushort_t));
/* Backup the flash ROM, bootcode and CASIOWIN entry */
2017-03-23 15:39:47 +01:00
extern int p7_backup_rom(p7_handle_t *handle, const p7_buffer_t *buffer,
p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_backup_ram(p7_handle_t *handle, const p7_buffer_t *buffer,
p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_backup_boot(p7_handle_t *handle, const p7_buffer_t *buffer,
p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_backup_casiowin_entry(p7_handle_t *handle,
p7_casiowin_entry_t *entry);
2016-09-28 05:24:00 +02:00
/* set link settings */
2017-03-23 15:39:47 +01:00
extern int p7_setlink(p7_handle_t *handle, const p7_streamsettings_t *settings);
2017-02-05 20:12:25 +01:00
/* FILE version of the previous functions */
# ifndef P7_DISABLED_FILE
/* Send an update.exe */
2017-03-23 15:39:47 +01:00
extern int p7_sendexe_file(p7_handle_t *handle,
2017-02-05 20:12:25 +01:00
FILE *exe, p7uint_t loadaddr, p7uint_t straddr,
p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_backup_romfile(p7_handle_t *handle, FILE *file,
p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_backup_ramfile(p7_handle_t *handle, FILE *file,
p7_disp_t disp);
2017-03-23 15:39:47 +01:00
extern int p7_backup_bootfile(p7_handle_t *handle, FILE *file,
p7_disp_t disp);
# endif
2016-10-09 16:52:16 +02:00
/* Memory version of the previous functions */
2017-03-23 15:39:47 +01:00
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);
2016-09-06 19:01:37 +02:00
/* Display streamed screen */
2017-03-23 15:39:47 +01:00
extern int p7_getscreen(p7_handle_t *handle, p7_screenfunc_t callback);
2016-09-06 19:01:37 +02:00
# ifdef __cplusplus
}
# endif
# include <libp7/server.h>
2016-08-16 21:33:44 +02:00
#endif /* LIBP7_H */