cake
/
libp7
Archived
1
0
Fork 1

Started integrating libg1m usage, reorganized.

This commit is contained in:
Thomas Touhey 2017-02-25 10:55:27 +01:00
parent 318790903c
commit c0d9590ce0
22 changed files with 133 additions and 36 deletions

View File

@ -28,10 +28,10 @@
VERSION := $(MAJOR).$(MINOR)$(if $(INDEV),-indev)
# Runtime libs (later: libg1m and libfontcharacter)
RLIBS :=
RLIBS := libg1m
# Compilation time libs
LIBS := zlib $(RLIBS)
LIBS := zlib $(if $(USE_LIBUSB),libusb-1.0) $(RLIBS)
#******************************************************************************#
# Project directories #
@ -62,9 +62,6 @@
ANAME := $(if $(FOR_WINDOWS),lib$(NAME).lib,lib$(NAME).a)
ANAMES := lib$(NAME).lib lib$(NAME).a lib$(NAME).dll.a
# Required libs
LIBS := $(if $(USE_LIBUSB),libusb-1.0)
#******************************************************************************#
# Binary utilities #
#******************************************************************************#

View File

@ -45,6 +45,7 @@ I took these as a reference because these are the ones I work with.
| Name | Version |
| -------------------------------------------------- | -------- |
| [libusb](http://libusb.info/) | >= 1.0 |
| [libg1m](https://github.com/cakeisalie5/libg1m/) | >= 1.0 |
## Configuring
First of all, the configure script has a help message where all of the

View File

@ -110,8 +110,16 @@ int p7_comlist(void (*callback)(void*, const char*), void *cookie);
/* De-initialization */
void p7_exit(p7_handle_t *handle);
/* ************************************************************************** */
/* Protocol */
/* 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,
@ -164,6 +172,12 @@ 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));
@ -202,9 +216,6 @@ int p7_sendexe_mem(p7_handle_t *handle,
/* Display streamed screen */
int p7_getscreen(p7_handle_t *handle, int (*callback)(int, int, uint32_t**));
/* Poke the calculator in order to keep it happy */
int p7_poke(p7_handle_t *handle);
# ifdef __cplusplus
}
# endif

View File

@ -23,7 +23,9 @@
#ifndef LIBP7_INTERNALS_H
# define LIBP7_INTERNALS_H
/* Microsoft Windows minimal version (Vista) */
# undef _WIN32_WINNT
# ifdef _WIN32_WINNT
# undef _WIN32_WINNT
# endif
# define _WIN32_WINNT 0x0600
# include <libp7.h>
@ -122,16 +124,16 @@ struct p7_handle_s {
p7_server_t _server;
const p7_env_t *_env;
/* is a serial connexion */
int _serial;
/* active status */
int _active;
/* shift status */
int _shifted;
/* was terminated */
int _terminated;
/* should terminate */
int _term;
/* head of the current MCS file */
g1m_mcshead_t mcshead;
/* various flags */
int _serial; /* is a serial connexion */
int _active; /* active status */
int _shifted; /* shift status */
int _terminated; /* was terminated */
int _term; /* should terminate at exit */
/* last sent command */
p7ushort_t _last_sent_command;
/* response */

View File

@ -186,6 +186,7 @@ static inline int p7_send_cmd##C(p7_handle_t *handle, \
* Remember that these are only for the ease of use; you can use the macros
* to implement more commands without putting them here. */
p7cmd(sys_getinfo, 0x01)
p7cmd(mcs_reqallinfo, 0x2D)
p7cmd(bak_reqram, 0x2F)
p7cmd(bak_putram, 0x30)
p7cmd_dir(fls_mkdir, 0x40)

View File

@ -19,6 +19,7 @@
#ifndef LIBP7_TYPES_H
# define LIBP7_TYPES_H
# include <libp7/config.h>
# include <libg1m.h>
# if (defined(_WIN16) || defined(_WIN32) || defined(_WIN64)) \
&& !defined(__WINDOWS__)
# define __WINDOWS__

84
src/mcs/list.c Normal file
View File

@ -0,0 +1,84 @@
/* *****************************************************************************
* mcs/list.c -- list the elements on the main memory.
* 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/>.
* ************************************************************************** */
#include <libp7/internals.h>
/**
* p7_mcs_list:
* List files on the main memory.
*
* @arg handle the libp7 handle.
* @arg callback the callback.
* @arg cookie something to send to the callback.
* @return if it worked.
*/
int p7_mcs_list(p7_handle_t *handle,
void (*callback)(void*, const g1m_mcshead_t *head), void *cookie)
{
int err;
/* make checks */
chk_handle(handle);
chk_active(handle);
/* send command packet */
log_info("sending file transfer request");
if ((err = p7_send_cmdmcs_reqallinfo(handle))) {
log_fatal("couldn't send transfer request");
return (err);
} else if (response.type != p7_pt_ack) {
log_fatal("didn't receive ack...");
return (p7_error_unknown);
}
/* swap roles */
log_info("sending roleswap");
if ((err = p7_send_roleswp(handle))) {
log_fatal("couldn't swap roles");
return (err);
}
/* - Note: we are now in passive mode - */
g1m_mcshead_t head;
while (1) switch (response.type) {
/* if answer is roleswap, we are done */
case p7_pt_roleswp: return (0);
/* if it is command, should be another file info */
case p7_pt_cmd:
/* check args */
if (g1m_decode_mcsfile_head(&head, response.mcstype,
(unsigned char*)response.args[2], (unsigned char*)response.args[0],
(unsigned char*)response.args[1], response.filesize))
continue;
(*callback)(cookie, &head);
/* send ack to continue */
log_info("sending ack to continue");
if ((err = p7_send_ack(handle, 1))) {
log_fatal("unable to send ack");
return (err);
}
break;
default: /* wtf? */
log_fatal("wtf?!");
return (p7_error_unknown);
}
}

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/backup.c -- backup software elements of the calculator.
* misc/backup.c -- backup software elements of the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/getscreen.c -- receive the streamed screen from the calculator.
* misc/getscreen.c -- receive the streamed screen from the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/poke.c -- poke the calculator so the communication doesn't stop.
* misc/poke.c -- poke the calculator so the communication doesn't stop.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/sendexe.c -- send an update.exe to the calculator.
* misc/sendexe.c -- send an update.exe to the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/server.c -- set up a protocol 7 server.
* misc/server.c -- set up a protocol 7 server.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/setlink.c -- set link settings.
* misc/setlink.c -- set link settings.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/copy.c -- copy a file on the calculator.
* storage/copy.c -- copy a file on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/createdir.c -- create a directory on the calculator.
* storage/createdir.c -- create a directory on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/delete.c -- delete a file/directory on the calculator.
* storage/delete.c -- delete a file/directory on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/getfreemem.c -- get the amount of free memory on the calculator.
* storage/getfreemem.c -- get the amount of free memory on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/list.c -- list the elements on the calculator.
* storage/list.c -- list the elements on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.
@ -20,7 +20,7 @@
/**
* p7_list:
* Requests a file.
* List files.
*
* @arg handle the libp7 handle
* @arg devname the device name

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/optimize.c -- optimize a filesystem on the calculator.
* storage/optimize.c -- optimize a filesystem on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/request.c -- request a file from the calculator.
* storage/request.c -- request a file from the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/reset.c -- reset a filesystem on the calculator.
* storage/reset.c -- reset a filesystem on the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.

View File

@ -1,5 +1,5 @@
/* *****************************************************************************
* protocol/send.c -- send a file to the calculator.
* storage/send.c -- send a file to the calculator.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.