cake
/
libcasio
Archived
1
1
Fork 0

More corrections.

This commit is contained in:
Thomas Touhey 2018-04-25 04:05:13 +02:00
parent 9f79156be6
commit aa937aca7b
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
15 changed files with 368 additions and 50 deletions

3
.gitignore vendored
View File

@ -3,7 +3,8 @@
/obj
/lib*.so*
/lib*.dll*
/man
/man/*.[1-9]
/man/*.gz
/docs/_build
build

View File

@ -213,7 +213,7 @@ $(eval $(call make-obj-rule,$(src))))
define make-util-rules
./build/$1$(if $(FOR_WINDOWS),.exe): $(U_OBJ_$1) \
$(if $(filter libcasio,$(U_DEPS_$1)),./build/lib$(LIB).so) | ./build/
$(if $(filter libcasio,$(U_DEPS_$1)),$(L_AS_DEP)) | ./build/
$(call bcmd,ld,$$@,$(LD) -o $$@ $(U_OBJ_$1) $(U_LDFLAGS_$1))
all-$1: ./build/$1$(if $(FOR_WINDOWS),.exe)

View File

@ -113,13 +113,13 @@ endif
# imagemagick, for image manipulation.
DEP_magick_CFLAGS := $(shell $(PKGCONFIG) MagickCore --cflags)
DEP_magick_LIBS := $(shell $(PKGCONFIG) MagickCore --libs)
DEP_magick_CFLAGS := $(shell $(PKGCONFIG) MagickCore --cflags 2>/dev/null)
DEP_magick_LIBS := $(shell $(PKGCONFIG) MagickCore --libs 2>/dev/null)
# SDL, for simple graphical utilities.
DEP_sdl_CFLAGS := $(shell $(PKGCONFIG) sdl --cflags)
DEP_sdl_LIBS := $(shell $(PKGCONFIG) sdl --libs)
DEP_sdl_CFLAGS := $(shell $(PKGCONFIG) sdl2 --cflags 2>/dev/null)
DEP_sdl_LIBS := $(shell $(PKGCONFIG) sdl2 --libs 2>/dev/null)
# ---
# Informations about the library.
@ -145,6 +145,9 @@ endif
L_ANAMES := ./build/lib$(LIB).lib ./build/lib$(LIB).a \
./build/lib$(LIB).dll.a
L_AS_DEP := $(if $(STATIC),$(L_ANAME),$(if \
$(FOR_WINDOWS),./build/$(L_SONAME),./build/lib$(LIB).so))
# Files.
L_SRC := $(patsubst $(L_SRCDIR)/%,%,$(wildcard $(L_SRCDIR)/*.c \

View File

@ -32,6 +32,7 @@ Runtime dependencies
- `libusb <http://libusb.info/>`_ (>= 1.0).
- `zlib <http://zlib.net/>`_ (>= 1.2.8).
- `SDL <https://www.libsdl.org/>`_ (>= 2.0).
Configuring
-----------

View File

@ -78,7 +78,7 @@ CASIO_EXTERN int CASIO_EXPORT casio_opencom_windows
CASIO_EXTERN int CASIO_EXPORT casio_open_posix_fs
OF((casio_fs_t **casio__filesystem));
# else
# define LIBCASIO_DISABLED_POSIX_FS
# define LIBCASIO_DISABLED_POSIX_FS 1
# endif
/* Make a Windows API filesystem interface. */

View File

@ -18,7 +18,7 @@
* ************************************************************************* */
#define PATHS_FTW
#include "posix.h"
#ifndef LIBCASIO_DISABLED_POSIX
#ifndef LIBCASIO_DISABLED_POSIX_FS
/**
* casio_posix_delete:

View File

@ -18,7 +18,7 @@
* ************************************************************************* */
#define PATHS_FTW
#include "posix.h"
#ifndef LIBCASIO_DISABLED_POSIX
#ifndef LIBCASIO_DISABLED_POSIX_FS
/**
* casio_posix_make:

25
man/libcasio.3.txt Normal file
View File

@ -0,0 +1,25 @@
LIBCASIO(3)
===========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libcasio
:man manual: libcasio manual
NAME
----
libcasio - library for using CASIO's protocols and file formats
DESCRIPTION
-----------
libcasio is a community effort at using protocols and file formats defined
by CASIO for its graphical calculators, produced from the 90s to to this day.
It is part of a project named the P7 project, and is a personal project of
Thomas Touhey, also known as “Cakeisalie5”, from Planète Casio.
See more at <https://p7.planet-casio.com/>.
SEE ALSO
--------
*p7*(1),
*p7screen*(1),
*mcsfile*(1)

37
man/mcsfile.1.txt Normal file
View File

@ -0,0 +1,37 @@
MCSFILE(1)
==========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: p7utils
:man manual: p7utils manual
NAME
----
mcsfile - list subfiles in a CASIO MCS archive file
SYNOPSIS
--------
[source,bash]
----
mcsfile [--help] [--version] <archive.g1m>
----
DESCRIPTION
-----------
mcsfile is a simple utility that looks like *file*(1), excepts it lists
subfiles in a CASIO MCS archive file (things with extensions like *g1m*
or *g2r*).
OPTIONS
-------
Options start with one or two dashes. Some of the options require an additional
value next to them.
*-h, --help*::
Display command/subcommand help page and quit.
*-v, --version*::
Display version and quit.
SEE ALSO
--------
*libcasio*(3)

86
man/p7.1.txt Normal file
View File

@ -0,0 +1,86 @@
P7(1)
=====
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: p7utils
:man manual: p7utils manual
NAME
----
p7 - command-line utility to communicate with casio calculators
SYNOPSIS
--------
[source,bash]
----
p7 [-h|--help] [-v|--version] [<command> [<args>]]
----
DESCRIPTION
-----------
p7 is a command-line utility to communicate with machines using casio's
communication protocol 7.00, like (almost only, not gonna lie) CASIO
fx calculators. For now, it only implements file sending/getting functions
on flash memories.
Available submenus are:
*send [-f] [-o oncalc.ext] [-d oncalcdir] local.ext*::
Send a file to the calculator.
*get [-o local.ext] [-d oncalcdir] oncalc.ext*::
Get a file from calculator.
*copy [-d sourcedir] [-t destdir] source.ext dest.ext*::
Copies a file into another on the calculator.
*del [-d oncalcdir] oncalc.ext*::
Delete a file on the calculator.
*ls*::
List files on the calculator.
*reset*::
Reset a filesystem on the calculator.
*optimize*::
Optimize the distant filesystem (defragment).
*info*::
Dumps information about the calculator.
OPTIONS
-------
Options start with one or two dashes. Some of the options require an additional
value next to them.
*-h, --help*::
Display command/subcommand help page and quit.
*-v, --version*::
Display version and quit.
*--com <device>*::
The serial device, if you want to communicate with a calculator connected
using a USB-to-serial cable.
::
If this option isn't used, the program will look for a calculator connected
using direct USB.
*--storage abc0*::
The storage device with which to interact.
*--no-term, --no-exit*::
Do not terminate connection when action is completed.
*--no-start, --no-init*::
Do not initialize connection -- should only be used when
*--no-term*/*--no-exit* was used last time p7 was called.
*-d DIR, --directory=DIR*::
The on-calc directory to work in.
Default for this option is device root.
*-t DDIR, --to=DIR*::
The destination directory (for file copying/moving).
Default for this option is device root.
*-o OUT, --output=OUT*::
For the *get* subcommand, the local file path to store in the output (or
'-' for stdout). For the *send* subcommand, the distant filename. For the
two subcommands, default is adapted from the input parameter.
*-f, --force*::
For the *send* subcommand, force overwrite (default is interactive
confirmation from user).
*-#*::
Displays a nice little loading bar for *send* and *get* subcommands. If
command is *get* and output is stdout, loading bar won't be displayed.
SEE ALSO
--------
*libcasio*(3)

61
man/p7os.1.txt Normal file
View File

@ -0,0 +1,61 @@
P7OS(1)
=======
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: p7utils
:man manual: p7utils manual
NAME
----
p7os - backup and setup CASIO calculator's software components using protocol 7
SYNOPSIS
--------
[source,bash]
----
p7os [-h|--help] [-v|--version] [--no-prepare] [--uexe <path>]
[<subcommand> [<args>]]
----
DESCRIPTION
-----------
p7os is a command-line utility to get and upload an OS on CASIO fx calculators,
using its communication protocol 7.00 and OS update mode.
Available submenus are :
*prepare-only*::
Sends the update program, but leave it for other programs to interact
with it.
*get [-o os.bin]*::
Backup the bootcode, CASIOWIN entry and OS.
You have to *prepare* before doing any other action. Preparing means sending
a P7 server on the calculator that will be able to execute commands required
by other subcommands.
OPTIONS
-------
Options start with one or two dashes. Some of the options require an additional
value next to them.
*-h, --help*::
Display command/subcommand help page and quit.
*-v, --version*::
Display version and quit.
*--com <device>*::
The serial device, if you want to communicate with a calculator connected
using a USB-to-serial cable.
::
If this option isn't used, the program will look for a calculator connected
using direct USB.
*--no-prepare*::
Use the current environment, instead of uploading one.
*--uexe <path>*::
Use a custom update program.
*-o OUT, --output=OUT*::
When getting something, where to store.
SEE ALSO
--------
*libcasio*(3)

39
man/p7screen.1.txt Normal file
View File

@ -0,0 +1,39 @@
P7SCREEN(1)
===========
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: p7utils
:man manual: p7utils manual
NAME
----
p7screen - display streamed screen from casio fx calculator
SYNOPSIS
--------
[source,bash]
----
p7screen [-h|--help] [-v|--version]
----
DESCRIPTION
-----------
p7screen is a command-line utility to display streamed screen from casio fx
calculator, using its communication protocol 7.00 and screenstreaming mode.
OPTIONS
-------
Options start with one or two dashes. Some of the options require an additional
value next to them.
*-h, --help*::
Display help page and quit.
*-v, --version*::
Display version and quit.
*-z ZOOM, --zoom=ZOOM*::
Change the zoom (will change the window size too).
SEE ALSO
--------
*p7*(1),
*libcasio*(3)

View File

@ -145,7 +145,7 @@ int parse_args(int ac, char **av, int *zoom)
case 'z':
*zoom = atoi(optarg);
if (*zoom <= 0 || *zoom > 16) {
log("-z, --zoom: should be between 1 and 16");
fprintf(stderr, "-z, --zoom: should be between 1 and 16");
return (1);
}
break;
@ -157,7 +157,7 @@ int parse_args(int ac, char **av, int *zoom)
/* error (ignore) */
case '?':
if (optopt == 'z')
log("-z, --zoom: expected an argument\n");
fprintf(stderr, "-z, --zoom: expected an argument\n");
else
break;
return (1);

View File

@ -17,7 +17,6 @@
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#include "main.h"
#include <string.h>
#include <SDL.h>
/* ************************************************************************** */
@ -64,47 +63,102 @@ static int zoom;
static void display_callback(void *vcookie,
int w, int h, casio_uint32_t **pixels)
{
static SDL_Surface *screen = NULL;
static SDL_Window *window = NULL;
static SDL_Renderer *rendr = NULL;
static SDL_Texture *texture = NULL;
static int saved_w = 0, saved_h = 0;
(void)vcookie;
/* Create screen if there isn't one. */
if (!screen || saved_w != w || saved_h != h) {
/* Create the window. */
if (!(screen = SDL_SetVideoMode(w * zoom, h * zoom, 32,
SDL_SWSURFACE | SDL_DOUBLEBUF))) {
log("Couldn't set video mode: %s\n", SDL_GetError());
if (!window) {
int ret;
/* We haven't got a window, our objective is to create one,
* with a renderer and a texture. First, let's create the window. */
window = SDL_CreateWindow("p7screen",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
w * zoom, h * zoom, 0);
if (!window) {
fprintf(stderr, "Couldn't create the window: %s\n",
SDL_GetError());
return ;
}
/* Then let's create the renderer. */
rendr = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (!rendr) {
SDL_DestroyWindow(window);
window = NULL;
fprintf(stderr, "Couldn't create the renderer: %s\n",
SDL_GetError());
return ;
}
/* Finally, create the texture we're gonna use for drawing
* the picture as a classic ARGB pixel matric (8 bits per
* component). */
texture = SDL_CreateTexture(rendr, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, w * zoom, h * zoom);
if (!texture) {
SDL_DestroyRenderer(rendr);
rendr = NULL;
SDL_DestroyWindow(window);
window = NULL;
fprintf(stderr, "Couldn't create the texture: %s\n",
SDL_GetError());
return ;
}
SDL_WM_SetCaption("P7screen", NULL);
/* Save data and display message. */
saved_w = w; saved_h = h;
puts("Turn off your calculator (SHIFT+AC) when you have finished.");
}
/* Lock the screen. */
SDL_LockSurface(screen);
saved_w = w;
saved_h = h;
puts("Turn off your calculator (SHIFT+AC) when you have finished.");
} else if (saved_w != w || saved_h != h) {
/* The dimensions have changed somehow, we're gonna manage it!
* FIXME: one day. */
return ;
}
/* Copy the data. */
uint32_t *px = (uint32_t*)screen->pixels;
int linesize = w * zoom;
for (int y = 0; y < h; y++) {
uint32_t *refline = px;
for (int x = 0; x < w; x++) {
uint32_t pixel = pixels[y][x];
for (int zx = 0; zx < zoom; zx++)
*px++ = pixel;
}
for (int zy = 1; zy < zoom; zy++) {
memcpy(px, refline, linesize * sizeof(uint32_t));
px += linesize;
{
Uint32 *px;
int pitch;
int linesize = w * zoom;
SDL_LockTexture(texture, NULL, (void **)&px, &pitch);
for (int y = 0; y < h; y++) {
Uint32 *refline = px;
for (int x = 0; x < w; x++) {
Uint32 pixel = pixels[y][x];
for (int zx = 0; zx < zoom; zx++)
*px++ = pixel;
}
for (int zy = 1; zy < zoom; zy++) {
memcpy(px, refline, linesize * sizeof(uint32_t));
px += linesize;
}
}
SDL_UnlockTexture(texture);
}
/* Unlock the screen, and flippin' flip it. */
SDL_UnlockSurface(screen);
SDL_Flip(screen);
/* Flippin' flip the screen! */
SDL_RenderCopy(rendr, texture, NULL, NULL);
SDL_RenderPresent(rendr);
}
/* ************************************************************************** */
/* Main function */
@ -130,9 +184,15 @@ int main(int ac, char **av)
if ((err = casio_open_usb(&handle, 0))) {
/* display error */
switch (err) {
case casio_error_nocalc: log(error_noconnexion); break;
case casio_error_noaccess: log(error_noaccess); break;
default: log(error_unplanned, casio_strerror(err)); break;
case casio_error_nocalc:
fprintf(stderr, error_noconnexion);
break;
case casio_error_noaccess:
fprintf(stderr, error_noaccess);
break;
default:
fprintf(stderr, error_unplanned, casio_strerror(err));
break;
}
/* return */
@ -141,7 +201,7 @@ int main(int ac, char **av)
/* Initialize SDL */
if (SDL_Init(SDL_INIT_VIDEO)) {
log("Failed to initialize SDL: %s\n", SDL_GetError());
fprintf(stderr, "Failed to initialize SDL: %s\n", SDL_GetError());
return (3);
}
atexit(SDL_Quit);
@ -150,8 +210,12 @@ int main(int ac, char **av)
if ((err = casio_getscreen(handle, &display_callback, NULL))
&& err != casio_error_nocalc) {
switch (err) {
case casio_error_timeout: log(error_noconnexion); break;
default: log(error_unplanned, casio_strerror(err)); break;
case casio_error_timeout:
fprintf(stderr, error_noconnexion);
break;
default:
fprintf(stderr, error_unplanned, casio_strerror(err));
break;
}
return (1);
}

View File

@ -16,17 +16,18 @@
* You should have received a copy of the GNU General Public License
* along with p7utils; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************** */
#ifndef MAIN_H
# define MAIN_H
#ifndef MAIN_H
# define MAIN_H 1
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <libcasio.h>
# define Q(x) #x
# define QUOTE(x) Q(x)
# define log(S, ...) fprintf(stderr, S, ##__VA_ARGS__)
/* all functions */
/* Prototypes. */
int parse_args(int ac, char **av, int *zoom);
#endif /* MAIN_H */