cake
/
libcasio
Archived
1
1
Fork 0

Documenting and rationalizing the library interface.

This commit is contained in:
Thomas Touhey 2019-05-25 03:36:14 +02:00
parent 8b3192b45f
commit 54217c4447
No known key found for this signature in database
GPG Key ID: 2ECEB0517AD947FB
83 changed files with 2516 additions and 2243 deletions

6
docs/.gitignore vendored
View File

@ -1,6 +0,0 @@
_site
.sass-cache
.jekyll-metadata
Gemfile.lock
/vendor
/.bundle

1
docs/.python-version Normal file
View File

@ -0,0 +1 @@
3.7.2

View File

@ -1,25 +0,0 @@
source "https://rubygems.org"
ruby RUBY_VERSION
# Hello! This is where you manage which Jekyll version is used to run.
# When you want to use a different version, change it below, save the
# file and run `bundle install`. Run Jekyll with `bundle exec`, like so:
#
# bundle exec jekyll serve
#
# This will help ensure the proper Jekyll version is running.
# Happy Jekylling!
gem "jekyll", "= 3.4.3"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-assets"
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

65
docs/Makefile Executable file → Normal file
View File

@ -1,39 +1,44 @@
#!/usr/bin/make -f
#*****************************************************************************#
# Target for the end user #
#*****************************************************************************#
# Make it.
all: -all
# Minimal makefile for Sphinx documentation
#
# Preview in local how it will render.
preview prev: -all-watch
# You can set these variables from the command line.
# Upload it to production (only for maintainers).
show: -all -install
PE = pipenv run
SPHINXOPTS =
SPHINXBUILD = $(PE) sphinx-build
SPHINXWATCH = $(PE) sphinx-autobuild
SOURCEDIR = .
BUILDDIR = _build
WEBROOT = libcasio.touhey.pro:libcasio_doc
.PHONY: preview prev
#*****************************************************************************#
# Internal #
#*****************************************************************************#
JEK := bundle exec jekyll
ROOT := libcasio.touhey.pro:libcasio_doc
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Prepare the bundle.
-prepare:
bundle check || bundle install --path vendor/bundle
.PHONY: help Makefile
# Make it all.
-all: -prepare
$(JEK) build $(JEKYLL_OPT)
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Make and watch.
-all-watch: -prepare
$(JEK) serve --watch $(JEKYLL_OPT)
# Install everything with pipenv.
prepare:
pipenv install
# Upload.
-install:
find _site -type f -exec chmod 644 {} \;
rsync -Prlt --delete _site/ "$(ROOT)"
.PHONY: prepare
# Livehtml build.
livehtml:
$(SPHINXWATCH) -b html $(SPHINXOPTS) . $(BUILDDIR)/html
.PHONY: livehtml
# Send the website content (Linux-only).
show: clean html
find _build/html -type f -exec chmod 644 {} \;
rsync -Prlt --delete _build/html/ "$(WEBROOT)"
.PHONY: show
.PHONY: -prepare -all -all-watch -install
# End of file.

13
docs/Pipfile Normal file
View File

@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true
[dev-packages]
[packages]
sphinx = "*"
sphinx-rtd-theme = "*"
[requires]
python_version = "3.7"

225
docs/Pipfile.lock generated Normal file
View File

@ -0,0 +1,225 @@
{
"_meta": {
"hash": {
"sha256": "ad49cdffc75c09b6abfb00f80a96f9c4967858dfc7153f34febb993592308482"
},
"pipfile-spec": 6,
"requires": {
"python_version": "3.7"
},
"sources": [
{
"name": "pypi",
"url": "https://pypi.org/simple",
"verify_ssl": true
}
]
},
"default": {
"alabaster": {
"hashes": [
"sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359",
"sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02"
],
"version": "==0.7.12"
},
"babel": {
"hashes": [
"sha256:6778d85147d5d85345c14a26aada5e478ab04e39b078b0745ee6870c2b5cf669",
"sha256:8cba50f48c529ca3fa18cf81fa9403be176d374ac4d60738b839122dfaaa3d23"
],
"version": "==2.6.0"
},
"certifi": {
"hashes": [
"sha256:59b7658e26ca9c7339e00f8f4636cdfe59d34fa37b9b04f6f9e9926b3cece1a5",
"sha256:b26104d6835d1f5e49452a26eb2ff87fe7090b89dfcaee5ea2212697e1e1d7ae"
],
"version": "==2019.3.9"
},
"chardet": {
"hashes": [
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
],
"version": "==3.0.4"
},
"docutils": {
"hashes": [
"sha256:02aec4bd92ab067f6ff27a38a38a41173bf01bed8f89157768c1573f53e474a6",
"sha256:51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274",
"sha256:7a4bd47eaf6596e1295ecb11361139febe29b084a87bf005bf899f9a42edc3c6"
],
"version": "==0.14"
},
"idna": {
"hashes": [
"sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407",
"sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c"
],
"version": "==2.8"
},
"imagesize": {
"hashes": [
"sha256:3f349de3eb99145973fefb7dbe38554414e5c30abd0c8e4b970a7c9d09f3a1d8",
"sha256:f3832918bc3c66617f92e35f5d70729187676313caa60c187eb0f28b8fe5e3b5"
],
"version": "==1.1.0"
},
"jinja2": {
"hashes": [
"sha256:065c4f02ebe7f7cf559e49ee5a95fb800a9e4528727aec6f24402a5374c65013",
"sha256:14dd6caf1527abb21f08f86c784eac40853ba93edb79552aa1e4b8aef1b61c7b"
],
"version": "==2.10.1"
},
"markupsafe": {
"hashes": [
"sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473",
"sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161",
"sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235",
"sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5",
"sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff",
"sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b",
"sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1",
"sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e",
"sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183",
"sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66",
"sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1",
"sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1",
"sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e",
"sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b",
"sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905",
"sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735",
"sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d",
"sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e",
"sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d",
"sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c",
"sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21",
"sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2",
"sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5",
"sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b",
"sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6",
"sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f",
"sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f",
"sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7"
],
"version": "==1.1.1"
},
"packaging": {
"hashes": [
"sha256:0c98a5d0be38ed775798ece1b9727178c4469d9c3b4ada66e8e6b7849f8732af",
"sha256:9e1cbf8c12b1f1ce0bb5344b8d7ecf66a6f8a6e91bcb0c84593ed6d3ab5c4ab3"
],
"version": "==19.0"
},
"pygments": {
"hashes": [
"sha256:31cba6ffb739f099a85e243eff8cb717089fdd3c7300767d9fc34cb8e1b065f5",
"sha256:5ad302949b3c98dd73f8d9fcdc7e9cb592f120e32a18e23efd7f3dc51194472b"
],
"version": "==2.4.0"
},
"pyparsing": {
"hashes": [
"sha256:1873c03321fc118f4e9746baf201ff990ceb915f433f23b395f5580d1840cb2a",
"sha256:9b6323ef4ab914af344ba97510e966d64ba91055d6b9afa6b30799340e89cc03"
],
"version": "==2.4.0"
},
"pytz": {
"hashes": [
"sha256:303879e36b721603cc54604edcac9d20401bdbe31e1e4fdee5b9f98d5d31dfda",
"sha256:d747dd3d23d77ef44c6a3526e274af6efeb0a6f1afd5a69ba4d5be4098c8e141"
],
"version": "==2019.1"
},
"requests": {
"hashes": [
"sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4",
"sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31"
],
"version": "==2.22.0"
},
"six": {
"hashes": [
"sha256:3350809f0555b11f552448330d0b52d5f24c91a322ea4a15ef22629740f3761c",
"sha256:d16a0141ec1a18405cd4ce8b4613101da75da0e9a7aec5bdd4fa804d0e0eba73"
],
"version": "==1.12.0"
},
"snowballstemmer": {
"hashes": [
"sha256:919f26a68b2c17a7634da993d91339e288964f93c274f1343e3bbbe2096e1128",
"sha256:9f3bcd3c401c3e862ec0ebe6d2c069ebc012ce142cce209c098ccb5b09136e89"
],
"version": "==1.2.1"
},
"sphinx": {
"hashes": [
"sha256:423280646fb37944dd3c85c58fb92a20d745793a9f6c511f59da82fa97cd404b",
"sha256:de930f42600a4fef993587633984cc5027dedba2464bcf00ddace26b40f8d9ce"
],
"index": "pypi",
"version": "==2.0.1"
},
"sphinx-rtd-theme": {
"hashes": [
"sha256:00cf895504a7895ee433807c62094cf1e95f065843bf3acd17037c3e9a2becd4",
"sha256:728607e34d60456d736cc7991fd236afb828b21b82f956c5ea75f94c8414040a"
],
"index": "pypi",
"version": "==0.4.3"
},
"sphinxcontrib-applehelp": {
"hashes": [
"sha256:edaa0ab2b2bc74403149cb0209d6775c96de797dfd5b5e2a71981309efab3897",
"sha256:fb8dee85af95e5c30c91f10e7eb3c8967308518e0f7488a2828ef7bc191d0d5d"
],
"version": "==1.0.1"
},
"sphinxcontrib-devhelp": {
"hashes": [
"sha256:6c64b077937330a9128a4da74586e8c2130262f014689b4b89e2d08ee7294a34",
"sha256:9512ecb00a2b0821a146736b39f7aeb90759834b07e81e8cc23a9c70bacb9981"
],
"version": "==1.0.1"
},
"sphinxcontrib-htmlhelp": {
"hashes": [
"sha256:4670f99f8951bd78cd4ad2ab962f798f5618b17675c35c5ac3b2132a14ea8422",
"sha256:d4fd39a65a625c9df86d7fa8a2d9f3cd8299a3a4b15db63b50aac9e161d8eff7"
],
"version": "==1.0.2"
},
"sphinxcontrib-jsmath": {
"hashes": [
"sha256:2ec2eaebfb78f3f2078e73666b1415417a116cc848b72e5172e596c871103178",
"sha256:a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153e0c4b8"
],
"version": "==1.0.1"
},
"sphinxcontrib-qthelp": {
"hashes": [
"sha256:513049b93031beb1f57d4daea74068a4feb77aa5630f856fcff2e50de14e9a20",
"sha256:79465ce11ae5694ff165becda529a600c754f4bc459778778c7017374d4d406f"
],
"version": "==1.0.2"
},
"sphinxcontrib-serializinghtml": {
"hashes": [
"sha256:c0efb33f8052c04fd7a26c0a07f1678e8512e0faec19f4aa8f2473a8b81d5227",
"sha256:db6615af393650bf1151a6cd39120c29abaf93cc60db8c48eb2dddbfdc3a9768"
],
"version": "==1.1.3"
},
"urllib3": {
"hashes": [
"sha256:a53063d8b9210a7bdec15e7b272776b9d42b2fd6816401a0d43006ad2f9902db",
"sha256:d363e3607d8de0c220d31950a8f38b18d5ba7c0830facd71a1c6b1036b7ce06c"
],
"version": "==1.25.2"
}
},
"develop": {}
}

View File

@ -1,37 +0,0 @@
#******************************************************************************
# _config.yml -- Documentation variables definition.
#
# For technical reasons, this file is *NOT* reloaded automatically when
# you use 'bundle exec jekyll serve'. If you change this file, please
# restart the server process.
#
# The theme is based on the jekyll-docs-template theme:
# https://github.com/bruth/jekyll-docs-template
#******************************************************************************
# Site settings.
title: libcasio
description: >-
Documentation for libcasio.
url: "https://libcasio.touhey.pro"
baseurl: "/docs"
# Build settings.
output: web
destination: _site
gems:
- jekyll-assets
exclude:
- Gemfile
- Gemfile.lock
- Makefile
- README.md
- vendor
# Markdown settings.
markdown: kramdown
# SASS settings.
sass:
style: :expanded
# End of file.

View File

@ -1,48 +0,0 @@
-
name: Introduction
uri: /
-
name: Getting started
uri: /getting-started.html
-
sname: User documentation
docs:
-
sname: The basics
docs:
-
name: Logging
uri: /logging.html
-
name: Error management
uri: /errors.html
-
name: Chararacter encoding
uri: /char.html
-
name: Streams
uri: /streams.html
-
sname: The specifics
docs:
-
name: Filesystems
uri: /filesystems.html
-
name: Main filesystems
uri: /mcs.html
-
name: Links and protocols
uri: /link.html
-
name: Decoding files
uri: /file.html
-
sname: Developer documentation
docs:
-
name: File organization
uri: /file-organization.html
-
name: Logging internals
uri: /logging-internals.html

View File

@ -1,55 +0,0 @@
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">
<title>{{ site.title }}{% if page.title %} : {{ page.title }}{% endif %}</title>
<meta name="description" content="{{ site.subtitle }}">
<link rel="icon" href="favicon.png">
<!--[if IE]>
<link rel="shortcut icon" href="favicon.ico">
<[endif]-->
<link rel="stylesheet" href="assets/bootstrap.min.css?upd">
<link rel="stylesheet" href="assets/syntax.css?upd">
<link rel="stylesheet" href="assets/main.css?upd">
</head><body>
<div class="container">
<div class="row"><div id="header" class="col-sm-12">
<h4><a class="brand" href="{{ site.baseurl }}/">{{ site.title }}</a>
{% if site.subtitle %}<small>{{ site.subtitle }}</small>{% endif %}
</h4>
</div></div>
<div class="row">
<div id="navigation" class="col-sm-2"><ul class="nav nav-list">
{% for element in site.data.sections %}
{% if element.name %}
<li><a href="{{ site.baseurl }}{{ element.uri }}">{{ element.name }}</a></li>
{% else %}
<li><p>{{ element.sname }}</p></li>
{% for document in element.docs %}
{% if document.name %}
<li><a href="{{ site.baseurl }}{{ document.uri }}">{{ document.name }}</a></li>
{% else %}
<li><p>» {{ document.sname }}</p></li>
{% for sdoc in document.docs %}
<li><a href="{{ site.baseurl }}{{ sdoc.uri }}">{{ sdoc.name }}</a></li>
{% endfor %}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
</ul></div>
<div id="content" class="col-sm-10">
{{ content }}
</div>
</div>
<div class="row"><div id="footer" class="col-sm-12">
<p>Copyright (C) 2017 - {{ site.time | date: "%Y" }} Thomas Touhey &lt;<a href="mailto:thomas@touhey.fr">thomas@touhey.fr</a>&gt;</p>
</div></div>
</div></body></html>

View File

@ -1,11 +0,0 @@
---
layout: default
---
<div class="page-header">
<h2>{{ page.title | capitalize }}
{% if page.subtitle %}<small>{{ page.subtitle }}</small>{% endif %}
</h2>
</div>
{{ content }}

File diff suppressed because one or more lines are too long

View File

@ -1,121 +0,0 @@
body {
font-weight: 400;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.7);
overflow-y: scroll;
}
pre, code, pre code {
border: none;
border-radius: 0;
background-color: #f9f9f9;
font-size: 0.85em;
tab-size: 4;
-moz-tab-size: 4;
-o-tab-size: 4;
}
.highlight {
margin: 20px 0 10px;
}
.highlight > pre, .highlight > pre > code {
background-color: transparent;
padding: 0;
}
.highlight table {
width: 100%;
}
.highlight table td.gl {
width: 0;
}
.highlight table td {
padding: 0;
}
.highlight table pre {
margin: 0;
}
pre {
font-size: 1em;
}
code {
color: inherit;
}
#header {
border-bottom: 1px solid #eee;
margin-bottom: 20px;
}
#header a:hover {
text-decoration: none;
}
#footer {
margin: 20px 0;
font-size: 0.85em;
color: #999;
text-align: center;
}
#content > .page-header:first-child {
margin-top: 0;
}
#content > .page-header:first-child h2 {
margin-top: 0;
}
#navigation {
font-size: 0.9em;
}
#navigation li {
padding-left: 0;
}
#navigation li p {
font-weight: bold;
}
#navigation li a, #navigation li p {
padding: 10px;
margin: 0;
}
#navigation .nav-header {
padding-left: 0;
padding-right: 0;
}
body.rtl {
direction: rtl;
}
body.rtl #header .brand {
float: right;
margin-left: 5px;
}
body.rtl .row-fluid [class*="span"] {
float: right !important;
margin-left: 0;
margin-right: 2.564102564102564%;
}
body.rtl .row-fluid [class*="span"]:first-child {
margin-right: 0;
}
body.rtl ul, body.rtl ol {
margin: 0 25px 10px 0;
}
table {
margin-bottom: 1rem;
border: 1px solid #e5e5e5;
border-collapse: collapse;
}
td, th {
padding: .25rem .5rem;
border: 1px solid #e5e5e5;
}

View File

@ -1,61 +0,0 @@
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */

View File

@ -1,92 +0,0 @@
---
layout: page
title: character encoding and conversions
---
libcasio has its own portable character encoding conversion, resembling
iconv. It supports Unicode transformation formats (UTF-8, UTF-16, UTF-32)
and CASIO's proprietary character encoding named FONTCHARACTER according to
the SDK it published in 2006 for the fx-9860G.
The character conversion utilities are defined in `<libcasio/char.h>`,
but as usual, including `<libcasio.h>` for everything is recommended.
### Opening and closing a conversion descriptor
The conversion descriptor is the main object that will keep track of
the conversion steps and status. Here are the main functions to manage it:
{% highlight c linenos %}
int casio_open_conv(casio_conv_t *cd, const char *to, const char *from);
int casio_close_conv(casio_conv_t cd);
{% endhighlight %}
The `to` and `from` parameters of the `casio_open_conv()` function are the
string identifiers of the source and destination encodings for the conversion.
For example, use `casio_open_conv(&cd, "utf-8", "utf-32")` to open a descriptor
that will be able to convert UTF-32 encoded data into UTF-8 encoded data.
### Converting formats
Once the conversion descriptor is opened, you can use the `casio_conv()`
function, defined this way:
{% highlight c linenos %}
int casio_conv(casio_conv_t cd,
const char **in_buffer, size_t *in_left,
const char **out_buffer, size_t *out_left);
{% endhighlight %}
In the same fashion than iconv, this function is made for being called
several times, usually because you read from a stream and write to another
stream — although you can use it to convert data all at once.
Here is a simple example using two buffers:
{% highlight c linenos %}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <libcasio.h>
int main(void)
{
int err = 0; casio_conv_t cd = NULL;
uint32_t buf0[] = {'H', 'e', 'l', 'l', 'o'};
size_t buf0_size = 5 * sizeof(uint32_t);
uint32_t buf1[] = {' ', 'w', 'o', 'r', 'l', 'd', '!'};
size_t buf1_size = 7 * sizeof(uint32_t);
char bufdata[30], *buf = &bufdata;
size_t outsize = 29; /* let space for the end zero */
/* Open the conversion descriptor. */
err = casio_open_conv(&cd, "utf-8", "utf-32");
if (err) {
fprintf(stderr, "Could not open the conversion desc.: %s",
casio_strerror(err));
goto fail;
}
/* Convert the first buffer. */
err = casio_conv(cd, &buf0, &buf0_size, &buf, &outsize);
if (err) {
fprintf(stderr, "Could not convert the first buffer: %s",
casio_strerror(err));
goto fail;
}
/* Convert the second buffer. */
err = casio_conv(cd, &buf1, &buf1_size, &buf, &outsize);
if (err) {
fprintf(stderr, "Could not convert the second buffer: %s",
casio_strerror(err));
goto fail;
}
/* Print the buffer. */
*buf = '\0';
fputs(bufdata, stdout);
fail:
/* Close the conversion descriptor. */
casio_close_conv(cd);
return (err != 0);
}
{% endhighlight %}

78
docs/conf.py Normal file
View File

@ -0,0 +1,78 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'libcasio'
copyright = '2019, Thomas Touhey'
author = 'Thomas Touhey'
# The full version, including alpha/beta/rc tags
def _get_release():
import re
from os.path import dirname, join
path = join(dirname(__file__), '..', 'Makefile.vars')
content = open(path).read()
major = re.search(r'\s*MAJOR\s* \:?\= [^\S\r\n]*([0-9]+)\s*', content,
re.I | re.X).group(1)
minor = re.search(r'\s*MINOR\s* \:?\= [^\S\r\n]*([0-9]+)\s*', content,
re.I | re.X).group(1)
indev = re.search(r'\s*INDEV\s* \:?\= [^\S\r\n]*([0-9a-z]*)\s*', content,
re.I | re.X).group(1)
release = f"{major}.{minor}{'-indev' if indev else ''}"
return release
release = _get_release()
# -- General configuration ---------------------------------------------------
primary_domain = 'c'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
html_baseurl = "/docs"
html_favicon = "favicon.png"
html_logo = "logo.png"
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

12
docs/devel.rst Normal file
View File

@ -0,0 +1,12 @@
Developer documentation
=======================
You've read :ref:`user` and want to contribute the
project? You're very welcome! This chapter regroups everything you need to
know.
.. toctree::
:maxdepth: 2
devel/concepts
devel/logging-internals

164
docs/devel/concepts.rst Normal file
View File

@ -0,0 +1,164 @@
Development concepts for libcasio
=================================
As a follow-up for :ref:`user-concepts` in the user guide, here's a few
concepts and decisions that have been taken for the development.
File organization
-----------------
There are many, many files in libcasio, and that's because I try to keep the
project clean and organized. This file is an attempt at describing how
the files are organized and where you can find or should put anything here.
There are a few main files and folders:
``docs/``
The library documentation, written using Sphinx.
``include/``
The public headers to use with the library (not including
internal headers).
``src/``
The sources and internal headers.
``tools/``, ``configure``, ``Makefile``, ``Makefile.vars``, ``Makefile.msg``
Build utilities.
``README.md``, ``CONTRIBUTING.md``, ``LICENSE.md``
Basic to-read files.
In the ``include/`` folder, there is the main header the user is supposed to
include, ``libcasio.h``, and a subfolder, which contains all of the headers
specific to modules. It is organized as in ``src/``, in modules which represent
the abstraction the module defines. For example, ``src/stream/`` and
``include/libcasio/stream.h`` are related to the libcasio-specific stream which
defines platform-agnostic functions to the system-specific utilities.
In the source folder, the ``internals.h`` header is the general internal header
which is included in every source file in the project (sometimes using a
module or submodule specific header which defines some more specific things
afterwards). It contains general utilities such as reliable endian management
macros, reliable integer types, and so on.
Function declarations and definitions
-------------------------------------
For portability (e.g. call conventions and other compiler-specific mess),
libcasio uses a few macros for declaring and defining functions that you are
expected to use if you ought to add some stuff:
.. function:: OF(ARGS)
This is a macro originally from `Zlib <https://www.zlib.net/>`_. It is
used on function declarations for compatibility with K&R (pre-ANSI) C,
which didn't support arguments definition for them. Without the macro,
you might have done:
.. code-block:: c
#if defined(__STDC__) && __STDC__
int my_function(int arg, char const *carg);
#else
int my_function(); /* K&R */
#endif
Instead, with this macro, you can just do:
.. code-block:: c
int my_function
OF((int arg, char const *carg));
.. function:: CASIO_EXTERN(TYPE)
Declare or define a function exported or ought to be. For example, with
a declaration and a definition:
.. code-block:: c
CASIO_EXTERN(int) my_function
OF((int arg1, int arg2));
CASIO_EXTERN(int) my_function(int arg1, int arg2)
{
return (arg1 + arg2);
}
Which can be resolved as one of the following (not exhaustive):
.. code-block:: c
/* Within normal circumstances. */
extern int my_function(int arg1, int arg2);
/* Oh, we're on good ol' Windows! Let's set a call convention
* explicitely so we don't run into problems. */
extern int WINAPI my_function(int arg1, int arg2);
.. function:: CASIO_NORETURN
Use instead of :c:func:`CASIO_EXTERN` for functions that are not supposed
to return, e.g. if they ``exit()`` or ``abort()``. For example:
.. code-block:: c
CASIO_NORETURN panic_and_set_fire_to_the_computer
OF((char const *msg));
.. function:: CASIO_LOCAL(TYPE)
Use for defining a function internal to the file. For example, with
a declaration and a definition:
.. code-block:: c
CASIO_LOCAL(int) my_function(int arg1, int arg2);
CASIO_LOCAL(int) my_function(int arg1, int arg2)
{
return (arg1 - arg2);
}
Which can be resolved as one of the following (not exhaustive):
.. code-block:: c
/* Within normal circumstances. */
static int my_function(int arg1, int arg2);
.. function:: CASIO_HOOK(TYPE)
Equivalent of :c:func:`CASIO_LOCAL` for functions that ought to be used
as hooks, i.e. callbacks for libcasio.
.. function:: CASIO_HOOK_TYPE(TYPE)
Extern function as a type, for using hook functions as callbacks within
``typedef`` or other type definitions. For example:
.. code-block:: c
typedef CASIO_EXTERN_TYPE(int) my_function_t
OF((int arg1, int arg2));
.. function:: CASIO_EXTERN_TYPE(TYPE)
Equivalent of :c:func:`CASIO_HOOK_TYPE` for exported functions to be
used and stored as hooks.
.. function:: CASIO_DEPRECATED
Prefix for function declarations and definitions which will be marked as
deprecated for the compiler (if it supports it). For example:
.. code-block:: c
CASIO_DEPRECATED CASIO_EXTERN(char const *) do_not_use_this_function
OF((char const *s));
CASIO_DEPRECATED CASIO_EXTERN(char const *) do_not_use_this_function(char const *s)
{
return (s + strlen(s));
}

View File

@ -0,0 +1,40 @@
Logging internals
=================
To use the libcasio logging interface, just include ``internals.h`` at source
root, or include something that ends up including it, directly or indirectly.
If the interface looks weird to you, that may be because this has been an
experiment to make a logging system compatible with K&R and ANSI C (which
explains the double parenthesis).
There are two different types of logging in libcasio: message logging, and
memory logging (which end up being the same to the user).
First, message logging. The main macro for this is
``msg((LEVEL, FORMAT, ...))``. The level is of the form ``ll_<level>``,
so ``ll_info``, ``ll_warn``, ``ll_error`` or ``ll_fatal``. The format and
arguments are for the printf-like function behind, so you can use
``msg((ll_info, "%d + %s", 5, "coucou"))`` for example.
If you are doing a condition only for a logging instruction, with no
``else if`` or ``else`` clause in the same state behind, you can use the
``ifmsg``, ``elifmsg`` and ``elsemsg`` macros. ``ifmsg`` and ``elifmsg`` take
the condition and the arguments for the ``msg`` function. For example:
.. code-block:: c
if (something.cool > 0) {
/* do something because it is cool */
}
elifmsg(something.cool == 0, (ll_warn, "The thing is not cool."))
elsemsg((ll_error, "The thing has NEGATIVE coolness, that's not cool."))
The memory logging family are organized the same, except the names are
``mem``, ``ifmem``, ``elifmem`` and ``elsemem``, and instead of the format and
format arguments, you have the pointer and the memory area size, e.g.:
.. code-block:: c
char cooldude = "COOLDUD\x7F";
msg((ll_info, "Cool dude magic:"));
mem((ll_info, cooldude, 8));

View File

@ -1,30 +0,0 @@
---
layout: page
title: error management
---
Almost all functions that can fail in libcasio return an `int`, even if
they open a handle or descriptor of some kind (which is usually passed by
using a pointer to it as a first argument). This integer corresponds to the
error that occured in the function, or zero, representing the "everything
went fine" error.
The errors that can happen in libcasio are defined in `<libcasio/error.h>`,
although as usual, you should include `<libcasio.h>` to access the code
and utilities.
Some errors are "relative", which means their significance depends on the
function that returned it, when others are not. For example, `casio_error_op`
means the function has received arguments that it doesn't manage (sometimes,
yet), and it should not be transmitted as is, while `casio_error_read` can
be transmitted without any risk.
To get the full list of errors, you should read the header directly.
If you simply want to get the error string, you can use the `casio_strerror()`
function, which has the following prototype:
{% highlight c linenos %}
const char *casio_strerror(int err);
{% endhighlight %}
This string should only be used for displaying the error, as it could be
translated in future versions of the library.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 66 KiB

View File

@ -1,31 +0,0 @@
---
layout: page
title: file organization
---
There are many, many files in libcasio, and that's because I try to keep the
project clean and organized. This file is an attempt at describing how
the files are organized and where you can find or should put anything here.
There are a few main files and folders:
- `docs/`: a statically generated website using Jekyll, in which the page
you're currently reading is written;
- `include/`: the public headers to use with the library (not including
internal headers);
- `src/`: the sources and internal headers;
- `tools/`, `configure`, `Makefile`, `Makefile.vars`, `Makefile.msg`:
build utilities;
- `README.md`, `CONTRIBUTING.md`, `LICENSE.md`: basic to-read files.
In the `include/` folder, there is the main header the user is supposed to
include, `libcasio.h`, and a subfolder, which contains all of the headers
specific to modules. It is organized as in `src/`, in modules which represent
the abstraction the module defines. For example, `src/stream/` and
`include/libcasio/stream.h` are related to the libcasio-specific stream which
defines platform-agnostic functions to the system-specific utilities.
In the source folder, the `internals.h` header is the general internal header
which is included in every source file in the project (sometimes using a
module or submodule specific header which defines some more specific things
afterwards). It contains general utilities such as reliable endian management
macros, reliable integer types, and so on.

View File

@ -1,4 +0,0 @@
---
layout: page
title: decoding files
---

View File

@ -1,4 +0,0 @@
---
layout: page
title: filesystems
---

View File

@ -1,35 +0,0 @@
---
layout: page
title: getting started
---
The libcasio development happens [on the Touhey forge][gh].
There is currently no mailing-list.
The release tarballs are available [here][pub].
libcasio is a development library, either shared or static.
There are many configuration options for adapting the library to your
platform and needs.
To configure, use `./configure <options>`. Options are used as
`--<name>=<value>`. The following are some build options:
- `--target=<target>`: the target for which to produce the library (by default,
native);
- `--static`: produce a static library (by default, shared);
- `--windows`: use the Windows versions of the final formats (dll instead of
elf, lib instead of coff);
- `--no-libusb`: do not use (and link against) libusb;
- `--no-file`: do not use the standard I/O library (probably because there
aren't any);
- `--no-log`, `--loglevel=<level>`: if we should include debugging content
(but keep the interface), and if yes, what the default library log level.
See [Logging](logging.html) for more information;
- `--maintainer`: alias for `--loglevel=info`, also introduces more
compilation warnings.
Other options are packaging options (todo: add info about them here).
[gh]: https://forge.touhey.org/casio/libcasio.git/
[pub]: https://libcasio.touhey.pro/pub/

View File

@ -1,19 +0,0 @@
---
layout: page
title: introduction
---
This is the libcasio documentation. It targets library users and library
developers.
libcasio ought to become the _de facto_ standard when it comes to manipulating
protocols and file formats used with CASIO calculators. Most of it is
platform-agnostic, although it contains stream and filesystem interfaces with
the most common systems such as Microsoft Windows, GNU/Linux distributions
or Apple's OS X.
The C "namespace" the library reserves are `casio_`, `CASIO_`, `libcasio_`
and `LIBCASIO_`; consider the use of anything starting with one of these
prefixes as having an undefined behaviour (so you really shouldn't do that).
There are many objects in libcasio. Choose what fits your need(s) in the
sidebar!

26
docs/index.rst Normal file
View File

@ -0,0 +1,26 @@
Welcome to libcasio's documentation!
====================================
libcasio ought to become the *de facto* standard when it comes to manipulating
protocols and file formats used with CASIO calculators. Most of it is
platform-agnostic, although it contains stream and filesystem interfaces with
the most common systems such as Microsoft Windows, GNU/Linux distributions
or Apple's OS X.
This is the libcasio documentation. It targets library users and library
developers. The development happens on `the Touhey forge <libcasio source_>`_,
and is distributed from the `libcasio distribution point`_. For more links,
check out the `libcasio website`_.
There is currently no mailing-list.
.. toctree::
:maxdepth: 2
install
user
devel
.. _libcasio source: https://forge.touhey.org/casio/libcasio.git/
.. _libcasio website: https://libcasio.touhey.pro/
.. _libcasio distribution point: https://libcasio.touhey.pro/pub/

34
docs/install.rst Normal file
View File

@ -0,0 +1,34 @@
.. _installing:
Installation guide
==================
libcasio is either built as a static or shared library, and is made to be
interfaced with C programs. The method of installing or building depends on
the system you're using: pick the one that fits yours!
POSIX systems (manual build)
----------------------------
To configure, use ``./configure <options>``. Options are used as
``--<name>=<value>``. The following are some build options:
``--target=<target>``
The target for which to produce the library (by default, native).
``--static``
Produce a static library (by default, shared).
``--windows``
Use the Windows versions of the final formats (dll instead of elf,
lib instead of coff).
``--no-log``, ``--loglevel=<level>``:
If we should include debugging content (but keep the interface), and if
yes, what the default library log level. See :ref:`logging` for more
information.
``--maintainer``
Alias for ``--loglevel=info``, also introduces more compilation warnings.
Other options are packaging options (todo: add more info about them here).

View File

@ -1,4 +0,0 @@
---
layout: page
title: links and protocols
---

View File

@ -1,40 +0,0 @@
---
layout: page
title: logging internals
---
To use the libcasio logging interface, just include `internals.h` at source
root, or include something that ends up including it, directly or indirectly.
If the interface looks weird to you, that may be because this has been an
experiment to make a logging system compatible with K&R and ANSI C (which
explains the double parenthesis).
There are two different types of logging in libcasio: message logging, and
memory logging (which end up being the same to the user).
First, message logging. The main macro for this is `msg((LEVEL, FORMAT, ...))`.
The level is of the form `ll_<level>`, so `ll_info`, `ll_warn`, `ll_error`
or `ll_fatal`. The format and arguments are for the printf-like function
behind, so you can use `msg((ll_info, "%d + %s", 5, "coucou"))` for example.
If you are doing a condition only for a logging instruction, with no `else if`
or `else` clause in the same state behind, you can use the `ifmsg`, `elifmsg`
and `elsemsg` macros. `ifmsg` and `elifmsg` take the condition and the
arguments for the `msg` function. For example:
{% highlight c linenos %}
if (something.cool > 0) {
/* do something because it is cool */
}
elifmsg(something.cool == 0, (ll_warn, "The thing is not cool."))
elsemsg((ll_error, "The thing has NEGATIVE coolness, that's not cool."))
{% endhighlight %}
The memory logging family are organized the same, except the names are
`mem`, `ifmem`, `elifmem` and `elsemem`, and instead of the format and
format arguments, you have the pointer and the memory area size, e.g.:
{% highlight c linenos %}
char cooldude = "COOLDUD\x7F";
msg((ll_info, "Cool dude magic:"));
mem((ll_info, cooldude, 8));
{% endhighlight %}

View File

@ -1,69 +0,0 @@
---
layout: page
title: logging
---
**This document only describes the library user control interface, which**
**doesn't cover the actual logging, aimed at library developers.**
For debugging purposes, libcasio has a debugging interface that allows
displaying messages in the debug stream (usually `stderr`) with four
different levels (plus a special one):
- `info` (debug information);
- `warn` (warnings);
- `error` (non-fatal errors);
- `fatal` (fatal errors);
- `none` (special log level to tell not to print messages).
Each level includes the message from the levels below in the list.
The log level used to be hardcoded into the library (with the configure
script), but it appeared that some users wanted to be able to control it
from the utilities using the library (with a `--log` option).
This interface is declared in `<libcasio/log.h>`. For forward compatibility
purposes, it works with strings.
To set the loglevel, use `casio_setlog()`, and to get a pointer to the current
loglevel, use `casio_getlog()`.
{% highlight c linenos %}
void casio_setlog(const char *level);
const char *casio_getlog(void);
{% endhighlight %}
Setting an unknown log level will simply result in setting the log level
to `none`.
Before setting the log level, you should list the recognized log levels.
For this, use the `casio_setlog()` function:
{% highlight c linenos %}
typedef void casio_log_list_t(void *cookie, const char *str);
void casio_listlog(casio_log_list_t *callback, void *cookie);
{% endhighlight %}
The callback will be called for every recognized log level. It is possible
for the function to call the callback only once (see the `--no-log` option
in [Getting started](getting-started.html)).
An example log level listing is the following:
{% highlight c linenos %}
#include <stdio.h>
#include <stdlib.h>
#include <libcasio.h>
void callback(void *cookie, const char *str)
{
(void)cookie; /* no, cookie, we don't want to use you */
printf("- %s\n", str);
}
int main(void)
{
printf("Available log levels:\n");
casio_listlog(&callback, NULL);
return (0);
}
{% endhighlight %}

BIN
docs/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

35
docs/make.bat Normal file
View File

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
:end
popd

View File

@ -1,4 +0,0 @@
---
layout: page
title: main filesystems
---

View File

@ -1,102 +0,0 @@
---
layout: page
title: streams
---
Streams are the abstractions for exchanging data with anything: a local or
distant file, a device through serial or USB communications, local memory
(usually for simulation), etc.
When it wasn't libcasio yet (at the time, communication-related objects were
in libp7), libusb usage used to be hardcoded in the Protocol 7.00 management
functions (sending, receiving); then, it used FILE streams from the GNU libc
implementation, but that still wasn't platform-agnostic enough, so what has
finally be decided is that the library would use its own stream object.
The stream object is usable both by the library and the user. The library
defines some useful platform-agnostic streams it uses itself, such as the
checksum stream (which calculates the checksum as the file content is read),
and some platform-specific streams for platforms defining a macro (for
example, CASIOWIN doesn't).
This document describes how to use and make a libcasio stream. Notice that
for the examples in this document, you shall include `<libcasio.h>`, or
the stream-specific header, `<libcasio/stream.h>`.
### Opening and closing a stream
There are three ways to open a stream:
- with a specialized function, such as `casio_open_stream_streams()` for
POSIX or `casio_opencom_windows()` for the Windows API;
- with a multi-stream function, such as `casio_open_usb_stream()` for
USB-connected calculators, or `casio_open_com_stream()` for
serial-connected calculators;
- with the core function, `casio_open_stream()`, which you will use when
you will want to define your own streams.
All of the stream opening functions shall take a reference to the stream
pointer you'll use as the stream handle as the first parameter, and return
the libcasio error code that occured (or 0 if no error has occured).
Once you are done with the stream, you shall close it, so that all of the
allocated resources can be free'd properly. In order to do this,
you can simply use `casio_close()`.
{% highlight c linenos %}
int casio_open_any_stream(casio_stream_t **stream, ...);
int casio_close(casio_stream_t *stream);
{% endhighlight %}
So here's a simple example using the `casio_open_memory()` function
(which makes a stream out of memory), for opening a stream and directly
closing it:
{% highlight c linenos %}
#include <libcasio.h>
void do_something()
{
int err;
casio_stream_t *stream = NULL;
char zone[6];
err = casio_open_memory(&stream, zone, 6);
if (err) {
/* an error has occured! */
return ;
}
/* do something here, if an error occurs, make sure to
close the stream anyway, or use the 'fail' label here */
fail:
err = casio_close(stream);
/* you can check the error if you want, but the stream will always
be closed at this point, more or less properly */
}
{% endhighlight %}
### Opening modes
libcasio streams have different features that are activated by a flag in the
open mode. Here are the existing ones:
- `CASIO_OPENMODE_READ`: reading bytes from the stream is allowed (the
`casio_read()` and `casio_skip()` functions can be used);
- `CASIO_OPENMODE_WRITE`: writing bytes to the stream is allowed (the
`casio_write()` and `casio_write_char()` can be used);
- `CASIO_OPENMODE_SEEK`: seeking in the stream is allowed (the
`casio_seek()` can be used);
- `CASIO_OPENMODE_SERIAL`: setting the serial properties of the stream is
allowed (the `casio_streamfuncs_setattrs` callback will be used);
- `CASIO_OPENMODE_SCSI`: SCSI operations on the stream are allowed (the
`casio_streamfuncs_scsi` callback will be used);
- `CASIO_OPENMODE_USB`: USB operations on the stream are allowed (no
callback corresponding to this is done yet).
Notice that even if `CASIO_OPENMODE_SEEK` is not allowed, `casio_tell()` will
work and tell the
There also are a few open modes that aren't used by the core functions
themselves but that above opening functions can use when appropriate:
- `CASIO_OPENMODE_TRUNC`: the file will be truncated;
- `CASIO_OPENMODE_APPEND`: will append to the file.

18
docs/user.rst Normal file
View File

@ -0,0 +1,18 @@
.. _user:
User documentation
==================
This chapter describes the library interface and concepts, which library
developers must also know in order to contribute to the project.
.. toctree::
:maxdepth: 2
user/concepts
user/character
user/picture
user/link
user/mcs
user/file
user/logging

98
docs/user/character.rst Normal file
View File

@ -0,0 +1,98 @@
Character encoding and conversions
==================================
libcasio has its own portable character encoding conversion, resembling
iconv. It supports Unicode transformation formats (UTF-8, UTF-16, UTF-32)
and CASIO's proprietary character encoding named FONTCHARACTER according to
the SDK it published in 2006 for the fx-9860G.
The character conversion utilities are defined in ``<libcasio/char.h>``,
but as usual, including ``<libcasio.h>`` for everything is recommended.
Opening and closing a conversion descriptor
-------------------------------------------
The conversion descriptor is the main object that will keep track of
the conversion steps and status. Here are the main functions to manage it:
.. c:type:: casio_conv_t
The conversion descriptor type.
.. c:function:: int casio_open_conv(casio_conv_t *cd, char const *to, \
char const *from)
Open the conversion descriptor.
The ``to`` and ``from`` parameters are the string identifiers of the
source and destination encodings for the conversion.
For example, use ``casio_open_conv(&cd, "utf-8", "utf-32")`` to open a
descriptor that will be able to convert UTF-32 encoded data into UTF-8
encoded data.
Converting formats
------------------
Once the conversion descriptor is opened, you can use the following
function:
.. c:function:: int casio_conv(casio_conv_t cd, \
char const **in_buffer, size_t *in_left, \
char **out_buffer, size_t *out_left)
In the same fashion than iconv, this function is made for being called
several times, usually because you read from a stream and write to another
stream — although you can use it to convert data all at once.
Here is a simple example using two buffers:
.. code-block:: c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <libcasio.h>
int main(void)
{
int err = 0; casio_conv_t cd = NULL;
uint32_t buf0[] = {'H', 'e', 'l', 'l', 'o'};
size_t buf0_size = 5 * sizeof(uint32_t);
uint32_t buf1[] = {' ', 'w', 'o', 'r', 'l', 'd', '!'};
size_t buf1_size = 7 * sizeof(uint32_t);
char bufdata[30], *buf = &bufdata;
size_t outsize = 29; /* let space for the end zero */
/* Open the conversion descriptor. */
err = casio_open_conv(&cd, "utf-8", "utf-32");
if (err) {
fprintf(stderr, "Could not open the conversion desc.: %s",
casio_strerror(err));
goto fail;
}
/* Convert the first buffer. */
err = casio_conv(cd, &buf0, &buf0_size, &buf, &outsize);
if (err) {
fprintf(stderr, "Could not convert the first buffer: %s",
casio_strerror(err));
goto fail;
}
/* Convert the second buffer. */
err = casio_conv(cd, &buf1, &buf1_size, &buf, &outsize);
if (err) {
fprintf(stderr, "Could not convert the second buffer: %s",
casio_strerror(err));
goto fail;
}
/* Print the buffer. */
*buf = '\0';
fputs(bufdata, stdout);
fail:
/* Close the conversion descriptor. */
casio_close_conv(cd);
return (err != 0);
}

80
docs/user/concepts.rst Normal file
View File

@ -0,0 +1,80 @@
.. _user-concepts:
libcasio concepts
=================
The library interface follows a certain amount of concepts which makes it
consistent.
Namespace
---------
In order to interfere as little as possible with user definitions, the library
uses a “namespace” which is represented by prefixes for all of its
external declarations, definitions and macros. Even for code that uses
libcasio, avoid defining anything with any of these prefixes or you'll get
an undefined behaviour.
The reserved prefixes are ``casio_``, ``CASIO_``, ``libcasio_`` and
``LIBCASIO_``.
Structure namespaces
--------------------
For structures you can access the members, these have as prefixes the
structure name in order, once again, to not interfere with user code.
For example, if a ``struct casio_my_type`` is defined, all member names will
start with ``casio_my_type_``, for example:
.. code-block:: c
#include <libcasio/cdefs.h>
CASIO_STRUCT(casio_my_type, casio_my_type_t)
struct casio_my_type {
int casio_my_type_a;
char const *casio_my_type_b;
};
Objects
-------
The library is based around objects and functions for using and managing them.
The objects are defined as anonymous structures, which means you can't access
the content of these objects directly, you need to use some getters
for compatibility.
Errors
------
Almost all functions that can fail in libcasio return an :c:type:`int`, even if
they open a handle or descriptor of some kind (which is usually passed by
using a pointer to it as a first argument). This integer corresponds to the
error that occured in the function, or zero, representing the "everything
went fine" error.
The errors that can happen in libcasio are defined in ``<libcasio/error.h>``,
although as usual, you should include ``<libcasio.h>`` to access the code
and utilities.
Some errors are "relative", which means their significance depends on the
function that returned it, when others are not. For example, ``casio_error_op``
means the function has received arguments that it doesn't manage (sometimes,
yet), and it should not be transmitted as is, while ``casio_error_unknown`` can
be transmitted without any risk.
To get the full list of errors, you should read the header directly.
If you simply want to get the error name or description, you can use the
following functions:
.. c:function:: char const *casio_error_name(int code)
Get a pointer to the error name (which you shall not free).
.. c:function:: char const *casio_error_desc(int code)
Get a pointer to the error description (which you shall not free).
The description string should only be used for displaying the error, as it
could be translated in future versions of the library.

164
docs/user/file.rst Normal file
View File

@ -0,0 +1,164 @@
File management
===============
libcasio manages the file formats through a file API where you can open and
decode a file, and export data into a file. A file is primarily represented
by its type and platform:
.. c:type:: casio_filetype_t
An enumeration defining various file types that file formats libcasio
can read and write can represent. The values in this enumeration are
defined as flags so that such a value can also represent multiple
file types with no ambiguity.
.. c:macro:: casio_filetype_addin
An add-in, i.e. a binary application which executes natively onto
the calculator from the storage filesystem(s). The platform cannot
be :c:macro:`casio_filefor_none` for this type.
.. c:macro:: casio_filetype_add_in
An alias for :c:macro:`casio_filetype_addin`.
.. c:macro:: casio_filetype_mcs
A main memory backup, see :ref:`mcs` for more details about
what a main memory is.
.. c:macro:: casio_filetype_eact
An e-activity, i.e. rich document for storing courses for example.
.. c:macro:: casio_filetype_e_activity
An alias for :c:macro:`casio_filetype_eact`.
.. c:macro:: casio_filetype_eactivity
An alias for :c:macro:`casio_filetype_eact`.
.. c:macro:: casio_filetype_picture
A picture, e.g. ``*.g3p`` files.
.. c:macro:: casio_filetype_pict
An alias for :c:macro:`casio_filetype_picture`.
.. c:macro:: casio_filetype_lang
A language file, which contains message translations with IDs,
e.g. ``*.g1l`` or ``*.g3l`` files.
.. c:macro:: casio_filetype_fkey
A function key file, which contains function key pictures with IDs
in the same fashion than language files, e.g. ``*.g1n`` files.
.. c:macro:: casio_filetype_storage
A storage filesystem backup, typically ``*.g1s`` files.
.. c:type:: casio_filefor_t
An enumeration defining various platforms for which the file formats
libcasio can read and write can be made for. The values in this enumeration
are defined as flags so that such a value can also represent multiple
file platforms with no ambiguity.
.. c:macro:: casio_filefor_none
No platform in particular; this value always evaluates as zero, so
that any other value in this enumeration can make it precise.
.. c:macro:: casio_filefor_fx
The fx-9860G family of calculators, OS 1.x and OS 2.x.
.. c:macro:: casio_filefor_cp
The Classpad family of calculators, e.g. the fx-CP400.
.. c:macro:: casio_filefor_cg
The Prizm family of calculators, including the fx-CG10, fx-CG20
and fx-CG50 (Graph 90+E).
.. c:macro:: casio_filefor_cas
Ancient calculators supporting the CAS40 and CAS50 protocols.
.. c:macro:: casio_filefor_casemul
The CasEmul software.
It is represented by the following object:
.. c:type:: casio_file_t
A decoded file of one of the supported file formats by libcasio.
Creating and freeing a file
---------------------------
A file can be created using one of the following functions:
.. c:function:: int casio_make_picture(casio_file_t **filep, \
unsigned int width, unsigned int height)
Create a picture file using the given dimensions.
.. c:function:: int casio_make_mcs(casio_file_t **filep)
Create a main memory backup file.
.. c:function:: int casio_make_fkey(casio_file_t **filep, \
casio_filefor_t filefor, int count)
Create a function key file for the platform given in ``filefor``,
with ``count`` slots.
.. c:function:: int casio_make_lang(casio_file_t **filep, \
casio_filefor_t filefor, int count)
Create a language file for the platform given in ``filefor``,
with ``count`` slots.
.. c:function:: int casio_make_addin(casio_file_t **filep, \
casio_filefor_t filefor, size_t size, char const *name, \
char const *internal, casio_version_t const *versionp, \
time_t const *created)
Create an add-in file for the platform given in ``filefor``,
with ``size`` bytes for the code, ``name`` as the public name,
``internal`` as the internal name (usually starting with ``@``),
``versionp`` pointing to the version structure, and ``created``
being the time of creation.
Once you're done using a file, you shall use the following function:
.. c:function:: void casio_free_file(casio_file_t *file)
Free the file and all of its related resources.
Decoding a file
---------------
A file is decoded from a generic stream, using the following function:
.. c:function:: int casio_decode(casio_file_t **filep, \
char const *filename, tio_stream_t *buffer, \
casio_filetype_t expected_types)
Create a file from the stream in ``buffer``, into ``filep``. If you
have the filename, you shall pass it in ``filename`` (if not, just pass
``NULL``), this function will also try to guess the file type using the
detected extension or filename (which has a significance for some
file formats, e.g. ancient file formats managed by CaS).
If you don't know what format you expect, pass zero to ``expected_types``.
Otherwise, use the types as flags, e.g.
``casio_filetype_picture | casio_filetype_mcs | casio_filetype_storage``
if you expect to find some pictures (main memory can contain pictures).

240
docs/user/link.rst Normal file
View File

@ -0,0 +1,240 @@
Calculator links
================
A link in libcasio represents a calculator over a stream, i.e. the application
level. It is an abstraction which proposes everything the protocols CASIO
calculator use offer, although some operations might not be implemented
behind.
Links can take the following callbacks:
.. c:type:: int casio_link_confirm_t(void *cookie)
The process or the device on the other end requires a confirmation from
the user, for which such as function is called. It shall return ``0`` if
the user has not confirmed, or anything else if it is.
.. c:type:: void casio_link_progress_t(void *cookie, unsigned int id, \
unsigned int total)
Is used for displaying the progress of an operation when it goes
further on.
Managing a link
---------------
Only the library is able to implement link functions, in order to encourage
users to contribute in the library development. Use the following functions to
open and close a link:
.. c:function:: int casio_open_link(casio_link_t **handlep, \
unsigned long flags, tio_stream_t *stream)
Open a link on the given stream. By default, uses the type of the stream
to find out what behaviour to adopt:
- if the stream is a generic stream, it will try to communicate using P7.
- if the stream is a serial stream, it will try to communicate using CAS50,
and if that failed, it will try to communicate using P7.
- if the stream is a USB stream, it will get the vendor, product,
class, subclass and protocol identifiers:
- if the protocol is found to be SCSI using the class/subclass/protocol,
then we shall try to communicate using SCSI.
- if the vendor identifier is ``0x07cf`` (“Casio Computer Co., Ltd”),
the product identifier is ``0x6101`` (“fx-9750gII”) and the device
protocol is ``0`` (vendor-specific), then we shall try to communicate
using protocol 7 (P7).
All of these behaviours are tweakable through the following flags:
.. c:macro:: CASIO_LINKFLAG_P7
We want to enforce protocol 7 on generic and serial streams (and skip
the CAS40 check).
.. c:macro:: CASIO_LINKFLAG_CAS40
We want to speak CAS40 as we know it's an ancient calculator on the
other side (around 1990).
.. c:macro:: CASIO_LINKFLAG_CAS50
We only want to try out CAS50, and not skip to protocol 7 if it
doesn't work.
.. c:macro:: CASIO_LINKFLAG_CAS100
We want to speak CAS50 as we're guessing it's an AFX on the other
side.
.. c:macro:: CASIO_LINKFLAG_SCSI
We want to speak SCSI on all kind of devices, through bulk-only
transport on USB and plain SCSI writing on generic streams.
This flag will be ignored on serial streams.
For protocol 7 streams, by default:
- we start off as the active device, i.e. the one that will send commands
to the other one.
- we send a check then a discovery packet, in order to find out to what
device we're speaking to and trying to guess what commands are supported
or not.
- if the device is identified to be connected through USB, we shift
packets on data streams in order to go faster.
- we terminate the connection at the end.
All of these behaviours are tweakable through the following flags:
.. c:macro:: CASIO_LINKFLAG_PASSIVE
We want to start out as the passive device (emulate a calculator).
This will of course disable checks, discovery, packet shifting
and terminating connections as we depend on the other side to
make decisions.
.. c:macro:: CASIO_LINKFLAG_NOCHECK
We suppose the connection has already been made by a previous link
(possibly on a previous process) and do not issue the check.
.. c:macro:: CASIO_LINKFLAG_NODISC
We do not want to discover what kind of device we have on the other
side, and use fallbacks to guess what commands are supported. Notice
that you shall only use this flag for devices that do not support the
discovery command, as this can be made on an already established link.
.. c:macro:: CASIO_LINKFLAG_NOSHIFT
We do not want to do packet shifting on USB devices. This is usually
done for sensitive data packet exchanges, as packet shifting can
theoretically go really bad and make the link irrecoverable, but
that's yet to be seen in practice.
Packet shifting is not enabled on serial devices because it doesn't
speed up the process at all.
.. c:macro:: CASIO_LINKFLAG_TERM
We want to terminate the connection when the link is closed.
.. c:function:: int casio_open_serial(casio_link_t **handlep, \
unsigned long flags, char const *name, tio_serial_attrs_t const *attrs)
Open a serial port using :c:func:`tio_open_serial_port` and the
given serial attributes, and open a link onto it.
.. c:function:: int casio_open_usb(casio_link_t **handlep, \
unsigned long flags, int bus, int address)
Open a USB device using :c:func:`tio_open_usb`, and open a link onto it.
.. c:function:: void casio_close_link(casio_link_t *handle)
Close the link and free all the related resources.
Link-related operations
-----------------------
In order to get the link information, you shall use the following function:
.. c:function:: casio_link_info_t const \
*casio_get_link_info(casio_link_t *handle)
Get the link information, i.e. the information on the device on the
other side. This function will return generic information in case the
discovery has been disabled.
For managing serial settings, the following function has your back:
.. c:function:: int casio_setlink(casio_link_t *handle, \
tio_serial_attrs_t const *attrs)
Agrees on serial settings with the device and changes the stream serial
properties on the underlying stream. Not all properties will be read,
generally only the speed, stop bits and parity.
Screenstreaming
---------------
The logic for screenstreaming management in libcasio is kind of an infinite
iterator, using the following function:
.. c:function:: int casio_get_screen(casio_link_t *handle, \
casio_picture_t **screenp)
.. warning::
Initialize ``*screenp`` to either ``NULL`` or a valid picture
**before** calling this function!
Get the next screen that the calculator has sent us. Depending on
``*screenp``:
- if it is ``NULL``, then the picture will be allocated and ``*screenp``
will be set to the newly allocated picture.
- if it is not ``NULL``, then it points to a valid picture which is
either modified if the dimensions of the received screen are the same
as its dimensions, or reallocated if not.
System-related operations
-------------------------
CASIO calculators used to provide legit ways to backup different parts of the
system on flash and upload and run special executables using protocol 7,
although it has been removed on modern calculators. These functions implement
these procedures:
.. c:function:: int casio_backup_rom(casio_link_t *handle, \
tio_stream_t *buffer, casio_link_progress_t *progress, \
void *progress_cookie)
Backup the ROM into the given buffer.
.. c:function:: int casio_upload_and_run(casio_link_t *handle, \
tio_stream_t *buffer, unsigned long loadaddr, unsigned long straddr, \
casio_link_progress_t *progress, void *progress_cookie)
Upload and run an executable from a stream. The stream is expected to
be a generic stream where the size can be determined by using
:c:func:`tio_get_size`.
``loadaddr`` represents where in the calculator's memory the program
shall be loaded (e.g. ``0x88030000``), and ``straddr`` is where the
program shall be started (e.g. ``0x88030000``). Both should be on
32-bits.
This function is usually used for uploading code that replaces the
flash's content, but the uploaded code can also serve other purposes
such as simply installing programs, displaying the calculator's info
or run a program to back up the calculator's memory. It is not
dangerous in itself, it's the uploaded code which can be, so as usual,
be careful with what you run on the calculator.
Main memory-related operations
------------------------------
All CASIO calculators have at least a main memory, whatever its format is (for
more about main memories, check out :ref:`mcs`). You can get the function that
manages it through the link using the following:
.. c:function:: int casio_get_link_mcs(casio_link_t *handle, \
casio_mcs_t **mcsp)
Get the main memory management object for the given link.
Protocol-specific functions
---------------------------
While libcasio offers you an abstract interface to any calculator whatever
protocol it is using, you can use the protocols directly for operations it
does not manage. For this, see the following pages:
.. toctree::
:maxdepth: 1
link/cas
link/seven

5
docs/user/link/cas.rst Normal file
View File

@ -0,0 +1,5 @@
Using the CAS protocols
=======================
You can't communicate directly with devices that use the CAS protocols. This
will come very soon.

177
docs/user/link/seven.rst Normal file
View File

@ -0,0 +1,177 @@
Using protocol 7
================
You can communicate directly with your device on a link that uses protocol
seven. This protocol is not linked directly to the file formats used on
storage or main memories, on the contrary to the CAS protocols.
This interface hides you some of the horrors the protocol uses, such as
the escaping method, but you know… it can't hide 'em all.
Packet representation
---------------------
Everything starts with the packet representation:
.. c:type:: casio_seven_packet_t
A protocol seven packet, as an abstract object.
That packet can have several types:
.. c:type:: casio_seven_type_t
A protocol seven packet type, as an enumeration with the following values:
.. c:macro:: casio_seven_type_cmd
Ask something to the passive device, and initialize a packet flow
relative to the issued command.
.. c:macro:: casio_seven_type_data
Send data as a flow.
.. c:macro:: casio_seven_type_swp
Swap roles between the active and passive device (but the device
which becomes active has a very specific role defined by the
previously issued command and its packet flow).
.. c:macro:: casio_seven_type_chk
Check if there's an interlocutor, and initiate the connection by
the way (as the passive device is not supposed to answer to any
command until it has received a check packet and responded to it).
.. c:macro:: casio_seven_type_ack
Acknowledge, i.e. say “I have received and understood your message”
and, in case of a command, “I am willing to do what you're ordering
me to”.
.. c:macro:: casio_seven_type_ohp
Send a screen capture while in screenstreaming. The name “ohp”
comes from the original representation of such a mode, as the
“overhead projector” mode.
.. c:macro:: casio_seven_type_nak
Acknowledge negatively, i.e. say “I have received but not understood
your message” or, in case of a command, “I am not willing to do what
you're ordering me to”. Such a packet usually says a little bit more
about what the error is about.
.. c:macro:: casio_seven_type_end
Terminate the communication from the active side, to which, before
it is terminated, the passive side must acknowledge.
There are several check types:
.. c:type:: casio_seven_chk_t
The check packet subtype represents the context in which the check
packet is sent:
.. c:macro:: casio_seven_chk_ini
The check is the initial check to see if there is a device right
at the beginning of the communication.
.. c:macro:: casio_seven_chk_wait
The check is a timeout check, to see if the device is still there
and processing the command or if it has been disconnected. This
was made for serial lines where you could not see if there was
still a device on the other end or not, whether on USB you can
(but this type of check packets still exists on it).
There also are several error types:
.. c:type:: casio_seven_err_t
The error packet subtypes represents the errors.
.. c:macro:: casio_seven_err_default
The default error type (probably unused?).
.. c:macro:: casio_seven_err_resend
There was a checksum or timeout error, this packet is used for
asking a packet resend. Please don't use this packet directly, and
let the library manage this for you.
.. c:macro:: casio_seven_err_overwrite
The server wants a confirmation, either an ACK packet of type
:c:macro:`casio_seven_ack_ow` or an error packet of type
:c:macro:`casio_seven_error_dont_overwrite`.
.. c:macro:: casio_seven_err_dont_overwrite
When the passive device sends :c:macro:`casio_seven_err_overwrite`,
you can choose to say no by sending an error packet of this type.
.. c:macro:: casio_seven_err_other
This error type is the generic error type that can mean many things:
invalid or unsupported command, invalid argument, etc.
.. c:macro:: casio_seven_err_fullmem
When you try to create a file and the calculator hasn't got enough
memory left, it sends this error and immediately terminates the
connection (without the terminate packet).
There also are several acknowledge types:
.. c:type:: casio_seven_ack_t
The acknowledge type can be used in various contexts:
.. c:macro:: casio_seven_ack_normal
The normal acknowledge kind, accepts the command and report a
successful execution or respond to check, data, terminate or
role swap packets.
.. c:macro:: casio_seven_ack_ow
When the passive device has responded to a command with
:c:macro:`casio_seven_err_overwrite`, the active device sends the
passive device an acknowledge packet with such a subtype to confirm
the overwrite.
.. c:macro:: casio_seven_ack_ext
Respond to a discovery command with device information.
.. c:macro:: casio_seven_ack_term
Used to acknowledge a terminate packet.
There also are several terminate types:
.. c:type:: casio_seven_term_t
The terminate type is the reason why the connection was terminated:
.. c:macro:: casio_seven_term_default
Normal termination.
.. c:macro:: casio_seven_term_user
The user has terminated the connection (by pressing AC on the
calculator, usually).
.. c:macro:: casio_seven_term_timeouts
Terminated due to timeouts or checksums.
.. c:macro:: casio_seven_term_overwrite
In response to ``ow_terminate``.

78
docs/user/logging.rst Normal file
View File

@ -0,0 +1,78 @@
.. _logging:
Logging
=======
.. warning::
This document only describes the library user control interface, which
doesn't cover the actual logging, aimed at library developers.
For debugging purposes, libcasio has a debugging interface that allows
displaying messages in the debug stream (usually ``stderr``) with four
different levels (plus a special one):
``info``
Debug information.
``warn``
Warnings.
``error``
Non-fatal errors.
``fatal``
Fatal errors.
``none``
Special log level not to print messages.
Each level includes the message from the levels below in the list.
The log level used to be hardcoded into the library (with the configure
script), but it appeared that some users wanted to be able to control it
from the utilities using the library (with a ``--log`` option).
This interface is declared in ``<libcasio/log.h>``. For forward compatibility
purposes, it works with strings.
.. c:function:: void casio_setlog(char const *level)
Set the log level using its name. Setting a log level unknown to the
library will result in setting the log level to ``none``.
.. c:function:: char const *casio_getlog(void)
Get a pointer to the current log level (which you shall not free).
Before setting the log level, you should list the recognized log levels. It
is recommended to iterate on them using the following functions for this:
.. c:function:: int casio_iter_log(tio_iter_t **iter)
Get a log level iterator.
.. c:function:: int casio_next_log(tio_iter_t *iter, char const **ptr)
Get the next log level on the iterator.
An example log level listing is the following:
.. code-block:: c
#include <stdio.h>
#include <stdlib.h>
#include <libcasio.h>
void callback(void *cookie, const char *str)
{
(void)cookie; /* no, cookie, we don't want to use you */
printf("- %s\n", str);
}
int main(void)
{
printf("Available log levels:\n");
casio_listlog(&callback, NULL);
return (0);
}

9
docs/user/mcs.rst Normal file
View File

@ -0,0 +1,9 @@
.. _mcs:
Main filesystems
================
CASIO calculators have a main filesystem, also called “main memory” and “MCS”
(for “Main Control Structure”) that contains all the little files
necessary to the main functions, such as programming, working on lists,
matrixes, spreadsheets, pictures, strings, and so on.

252
docs/user/picture.rst Normal file
View File

@ -0,0 +1,252 @@
Picture management
==================
libcasio manages picture formats.
The pixel
---------
.. c:type:: casio_pixel_t
A pixel represented as a 32-bit integer, encoded as 0x00RRGGBB using
native endianness, which is used as the canonical form of representing
a picture in libcasio.
.. c:function:: casio_pixel_t casio_pixel(int r, int g, int b)
Function-like macro to create a pixel.
.. c:function:: casio_pixel_t casio_pixel_with_r(casio_pixel_t pix, int r)
Replace the red component of a pixel with the given value.
.. c:function:: casio_pixel_t casio_pixel_with_g(casio_pixel_t pix, int g)
Replace the green component of a pixel with the given value.
.. c:function:: casio_pixel_t casio_pixel_with_b(casio_pixel_t pix, int b)
Replace the blue component of a pixel with the given value.
.. c:function:: int casio_pixel_r(casio_pixel_t pix)
Get the red component of a pixel.
.. c:function:: int casio_pixel_g(casio_pixel_t pix)
Get the green component of a pixel.
.. c:function:: int casio_pixel_b(casio_pixel_t pix)
Get the blue component of a pixel.
Picture encodings
-----------------
.. c:type:: casio_colorcode_t
Color codes for the :c:macro:`casio_pictureformat_4bit_code` picture
encoding.
.. c:macro:: casio_colorcode_black
Black: 0x000000.
.. c:macro:: casio_colorcode_blue
Blue: 0x0000FF.
.. c:macro:: casio_colorcode_green
Green: 0x00FF00.
.. c:macro:: casio_colorcode_cyan
Cyan: 0x00FFFF.
.. c:macro:: casio_colorcode_red
Red: 0xFF0000.
.. c:macro:: casio_colorcode_magenta
Magenta: 0xFF00FF.
.. c:macro:: casio_colorcode_yellow
Yellow: 0xFFFF00.
.. c:macro:: casio_colorcode_white
White: 0xFFFFFF.
.. c:type:: casio_pictureformat_t
The picture format type.
By default, the pixels of a picture are defined top to bottom, left to
right.
.. c:macro:: casio_pictureformat_1bit
In this format, each bit represents a pixel (so one byte contains
eight pixels). If the width is not divisible by eight, then the
last bits of the last byte of the line are unused (fill bits), and
the next line starts at the beginning of the next byte; this makes
the navigation between lines easier, but takes up more space.
An off bit (0b0) represents a white pixel, and an on bit (0b1)
represents a black pixel.
For calculating the size of such pictures, calculate the
number of bytes a line occupies (usually ``ceil(w / 8)``)
and multiply it by the number of lines.
.. c:macro:: casio_pictureformat_1bit_r
Same as :c:macro:`casio_pictureformat_1bit`, except an off bit (0b0)
represents a black pixel, and an on bit (0b1) represents a white
pixel.
.. c:macro:: casio_pictureformat_1bit_packed
Packed monochrome pictures are basically the same as the format
described for :c:macro:`casio_pictureformat_1bit`, except there
are no fill bits: if a picture width is 6 pixels, then the second
line will start at the seventh bit of the first byte (where it
would start at the first bit of the second byte with fill bits).
The navigation to a line is less easy as it takes at least one
division.
For calculating the size of such pictures, calculate the
total number ``P`` of pixels (``w * h``) and divide it by
the size of a byte (``ceil(p / 8)``).
.. c:macro:: casio_pictureformat_1bit_packed_r
Same as :c:macro:`casio_pictureformat_1bit_packed`, with the
differences described in :c:macro:`casio_pictureformat_1bit_r`.
.. c:macro:: casio_pictureformat_1bit_old
The old monochrome format used by CASIO is basically a normal
monochrome format (the width is usually 96 or 128, so no need for
fill bits), except that it starts with the last byte (where the
bits are in left to right), but it goes right to left,
bottom to top.
The size is the same as for :c:macro:`casio_pictureformat_1bit`,
except the byte order changes.
.. c:macro:: casio_pictureformat_2bit_dual
This is the format used for the Prizm's projector mode. It is
composed of two monochrome pictures (with sizes divisible by
eight). It is basically gray pictures, with white, gray, dark gray
and black.
To calculate the size, well, just multiply the size of such a
picture in the :c:macro:`casio_pictureformat_1bit` per 2.
.. c:macro:: casio_pictureformat_4bit
This is a 4 bit per pixel format. There is no need for fill nibbles.
Each nibble (group of 4 bits) is made of the following:
- one bit for red (OR by 0xFF0000).
- one bit for green (OR by 0x00FF00).
- one bit for blue (OR by 0x0000FF).
- one alignment bit.
To calculate the size, divide the number of pixels (``w * h``) by 2.
.. c:macro:: casio_pictureformat_4bit_code
In this encoding, each nibble for a pixel represents one of the
colors defined in :c:type:`casio_colorcode_t` or, in case of an
illegal value (8 and above), plain black.
The size is calculated the same way as for
:c:macro:`casio_pictureformat_4bit`.
.. c:macro:: casio_pictureformat_4bit_color
This format is used by old CASIO models. It is made of four monochrome
pictures (no need for fill bits), where the palettes are orange,
green, blue, white (bg).
To get the size, just multiply the size of a VRAM (see
:c:macro:`casio_pictureformat_1bit`) by 4.
.. c:macro:: casio_pictureformat_4bit_mono
Same as :c:macro:`casio_pictureformat_4bit_color`, except the
palette are (unused), (unused), black, white (bg).
.. c:macro:: casio_pictureformat_casemul
This format is used by CasEmul. It is basically arbitrary color codes,
1 byte per code, where, for example, 1 is orange. You can check the
full color codes in ``lib/picture.c``.
The size in bytes is the number of pixels.
.. c:macro:: casio_pictureformat_16bit
This format is used for the Prizm's VRAM. Each pixel is two bytes
long, where:
- the first five bytes represents the high five (clap!) bits of
the red part.
- the next six bits represent the high six bits of the green part.
- the last five bits represent the high five (re-clap!) bits of
the blue part.
The size in bytes is the number of pixels times 2.
Managing a picture
------------------
You cannot make a picture directly, you have to decode it.
.. c:function:: void casio_free_picture(casio_picture_t *picture)
Free the picture. Any related resource (such as the pixel matrix)
will also be free'd, so be careful.
.. c:function:: int casio_get_picture_dimensions(casio_picture_t *picture, \
unsigned int *widthp, unsigned int *heightp)
Get the picture width and height.
.. c:function:: int casio_access_pixels(casio_picture_t *picture, \
casio_pixel_t ***pixels)
Access the pixels as a pixel matrix.
Encoding and decoding a picture
-------------------------------
.. c:function:: int casio_decode_picture(casio_picture_t **picturep, \
unsigned int width, unsigned int height, \
casio_pictureformat_t format, tio_stream_t *stream)
Create a picture out of a readable stream, with the width and height.
.. c:function:: int casio_decode_picture_buffer(casio_picture_t **picturep, \
unsigned int width, unsigned int height, \
casio_pictureformat_t format, void const *data, size_t data_size)
Create a picture out of raw data, with the width and height.
.. c:function:: int casio_get_picture_encoded_size(casio_picture_t *picture, \
casio_pictureformat_t format, size_t *sizep)
Get the required size for encoding the picture in a given format.
.. c:function:: int casio_encode_picture(casio_picture_t *picture, \
casio_pictureformat_t format, void *buf, size_t size)
Get the encoded form of a picture, using a given format and encoding
into the given buffer.

View File

@ -20,11 +20,9 @@
# define LIBCASIO_H
# include "libcasio/cdefs.h"
# include "libcasio/error.h"
# include "libcasio/mutex.h"
# include "libcasio/log.h"
# include "libcasio/number.h"
# include "libcasio/misc.h"
# include "libcasio/link.h"
# include "libcasio/file.h"

View File

@ -24,9 +24,9 @@
#if defined(OF)
#elif defined(__STDC__) && __STDC__
# define OF(CASIO_ARGS) CASIO_ARGS
# define OF(CASIO__ARGS) CASIO__ARGS
#else
# define OF(CASIO_ARGS) ()
# define OF(CASIO__ARGS) ()
#endif
/* "Normal start" of the file is here. */
@ -66,95 +66,18 @@
# define CASIO_MSC_PREREQ(CASIO__MAJ, CASIO__MIN) 0
# endif
/* ---
* Check for subsystems.
* --- */
/* Macros defined by the `libcasio/config.h` header:
* - `LIBCASIO_DISABLED_FILE`: can we use the standard FILE operations?
* - `LIBCASIO_DISABLED_LIBUSB`: can we use libusb? */
/* Can we use the Linux and the MacOS/OS X listing?
* XXX: what about Linux distributions not using the Linux standard
* filesystem? */
# if defined(__linux__)
# else
# define LIBCASIO_DISABLED_LINUX_SERIAL
# endif
# if defined(__APPLE__) && defined(__MACH__)
# else
# define LIBCASIO_DISABLED_MAC_SERIAL
# endif
/* Can we use the POSIX (STREAMS) interface? */
# if defined(__linux__) || (defined(__APPLE__) && defined(__MACH__))
# else
# define LIBCASIO_DISABLED_STREAMS
# endif
/* Can we use the Windows (Win32/Win64) API? */
# if defined(_WIN16) || defined(_WIN32) || defined(_WIN64) \
|| defined(__WINDOWS__)
# else
# define LIBCASIO_DISABLED_WINDOWS
# endif
/* ---
* Extern functions.
* --- */
/* Some platforms require more than simply 'extern'.
* Here are macros to control this. */
/* Warn if the function is deprecated. */
# define CASIO_EXTERN extern
# define CASIO_EXPORT
# define CASIO_LOCAL static
/* ---
* Enumerations.
* --- */
/* Enumerations can be great thanks to the compiler: better warnings,
* better debug, better coding! */
# if defined(LIBCASIO_USE_ENUMS)
# elif defined(__STDC__) && __STDC__
# define LIBCASIO_USE_ENUMS 1
# else /* K&R C, no enums! */
# define LIBCASIO_USE_ENUMS 0
# endif
/* ---
* C++ declarations and namespaces management.
* --- */
/* libcasio is made in C. */
# if 0 /* hey, what about this? */
# define CASIO_BEGIN_NAMESPACE namespace casio {
# define CASIO_END_NAMESPACE }
# endif
# ifdef __cplusplus
# define CASIO_BEGIN_NAMESPACE
# define CASIO_BEGIN_DECLS extern "C" {
# define CASIO_END_DECLS }
# define CASIO_END_NAMESPACE
# if CASIO_GNUC_PREREQ(3, 0)
# define CASIO_DEPRECATED __attribute__((deprecated))
# else
# define CASIO_BEGIN_NAMESPACE
# define CASIO_BEGIN_DECLS
# define CASIO_END_DECLS
# define CASIO_END_NAMESPACE
# define CASIO_DEPRECATED
# endif
/* ---
* Various function attributes.
* --- */
/* Warn if the result is unused.
* To do that, we'll use the `CASIO_WUR` attribute. */
@ -167,14 +90,67 @@
# define CASIO_WUR
# endif
/* Warn if the function is deprecated. */
/* Some platforms require more than simply 'extern'.
* Here are macros to control this. */
# if CASIO_GNUC_PREREQ(3, 0)
# define CASIO_DEPRECATED __attribute__((deprecated))
# define CASIO_EXTERN(TYPE) \
extern TYPE
# define CASIO_NORETURN \
__attribute__((noreturn)) extern void
# define CASIO_LOCAL(TYPE) \
static TYPE
# define CASIO_HOOK(TYPE) \
static TYPE
# define CASIO_EXTERN_TYPE(TYPE) \
TYPE
# define CASIO_HOOK_TYPE(TYPE) \
TYPE
# define CASIO_LOCAL_DATA(TYPE) \
static TYPE
/* ---
* C++ declarations and namespaces management.
* --- */
/* libcasio is made in C. */
# ifdef __cplusplus
# define CASIO_BEGIN_NAMESPACE namespace "libcasio" {
# define CASIO_BEGIN_DECLS extern "C" {
# define CASIO_END_DECLS }
# define CASIO_END_NAMESPACE }
# else
# define CASIO_DEPRECATED
# define CASIO_BEGIN_NAMESPACE
# define CASIO_BEGIN_DECLS
# define CASIO_END_DECLS
# define CASIO_END_NAMESPACE
# endif
/* Forward declare a structure. */
# define CASIO_STRUCT(CASIO__STRUCT_NAME, CASIO__STRUCT_TYPEDEF) \
struct CASIO__STRUCT_NAME; \
typedef struct CASIO__STRUCT_NAME CASIO__STRUCT_TYPEDEF;
/* ---
* Utilities.
* --- */
CASIO_BEGIN_NAMESPACE
CASIO_BEGIN_DECLS
/* Cross-platform allocation functions. They are defined just in case. */
CASIO_EXTERN(void *) casio_alloc
OF((size_t casio__num_elements, size_t casio__element_size));
CASIO_EXTERN(void) casio_free
OF((void *casio__ptr));
CASIO_END_DECLS
CASIO_END_NAMESPACE
# include "cdefs/integers.h"
# include "cdefs/endian.h"
#endif /* LIBCASIO_CDEFS_H */

View File

@ -24,22 +24,22 @@
* does not have any equivalent function (or has one but indicates that
* fact badly). */
CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_be16toh
CASIO_EXTERN(casio_uint16_t) casio_be16toh
OF((casio_uint16_t casio__x));
CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_le16toh
CASIO_EXTERN(casio_uint16_t) casio_le16toh
OF((casio_uint16_t casio__x));
CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_be32toh
CASIO_EXTERN(casio_uint32_t) casio_be32toh
OF((casio_uint32_t casio__x));
CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_le32toh
CASIO_EXTERN(casio_uint32_t) casio_le32toh
OF((casio_uint32_t casio__x));
CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_htobe16
CASIO_EXTERN(casio_uint16_t) casio_htobe16
OF((casio_uint16_t casio__x));
CASIO_EXTERN casio_uint16_t CASIO_EXPORT casio_htole16
CASIO_EXTERN(casio_uint16_t) casio_htole16
OF((casio_uint16_t casio__x));
CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_htobe32
CASIO_EXTERN(casio_uint32_t) casio_htobe32
OF((casio_uint32_t casio__x));
CASIO_EXTERN casio_uint32_t CASIO_EXPORT casio_htole32
CASIO_EXTERN(casio_uint32_t) casio_htole32
OF((casio_uint32_t casio__x));
# if defined(__APPLE__)

View File

@ -62,19 +62,19 @@
* character length (1 to 2 bytes) and FONTCHAR-16 is the FONTCHARACTER
* encoding with fixed-width big-endian 16-bit characters. */
CASIO_EXTERN int CASIO_EXPORT casio_fontchar8_to_utf32
CASIO_EXTERN(int) casio_fontchar8_to_utf32
OF((casio_uint8_t **casio__inbuf, size_t *casio__inleft,
casio_uint32_t **casio__outbuf, size_t *casio__outleft));
CASIO_EXTERN int CASIO_EXPORT casio_fontchar16_to_utf32
CASIO_EXTERN(int) casio_fontchar16_to_utf32
OF((FONTCHARACTER **casio__inbuf, size_t *casio__inleft,
casio_uint32_t **casio__outbuf, size_t *casio__outleft));
CASIO_EXTERN int CASIO_EXPORT casio_utf32_to_fontchar8
CASIO_EXTERN(int) casio_utf32_to_fontchar8
OF((casio_uint32_t **casio__inbuf, size_t *casio__inleft,
casio_uint8_t **casio__outbuf, size_t *casio__outleft));
CASIO_EXTERN int CASIO_EXPORT casio_utf32_to_fontchar16
CASIO_EXTERN(int) casio_utf32_to_fontchar16
OF((casio_uint32_t **casio__inbuf, size_t *casio__inleft,
FONTCHARACTER **casio__outbuf, size_t *casio__outleft));

View File

@ -27,9 +27,9 @@ CASIO_BEGIN_NAMESPACE
CASIO_BEGIN_DECLS
CASIO_EXTERN int CASIO_EXPORT casio_decode_date
CASIO_EXTERN(int) casio_decode_date
OF((time_t *casio__date, char const *casio__raw));
CASIO_EXTERN int CASIO_EXPORT casio_encode_date
CASIO_EXTERN(int) casio_encode_date
OF((char *casio__raw, time_t const *casio__date));
CASIO_END_DECLS

View File

@ -104,14 +104,14 @@ typedef int casio_error_t;
/* Get a string describing the error. */
CASIO_EXTERN char const* CASIO_EXPORT casio_error_strings[];
CASIO_BEGIN_DECLS
CASIO_EXTERN char const* CASIO_EXPORT casio_strerror
CASIO_EXTERN(char const *) casio_error_name
OF((int casio__error));
CASIO_EXTERN(char const *) casio_error_desc
OF((int casio__error));
# ifndef LIBCASIO_NO_STRERROR
# define casio_strerror(CASIO_N) casio_error_strings[(CASIO_N)]
# endif
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_ERROR_H */

View File

@ -23,6 +23,9 @@
# include "version.h"
# include "date.h"
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_file, casio_file_t)
/* ---
* Description.
* --- */
@ -43,6 +46,7 @@ typedef unsigned int casio_filetype_t;
# define casio_filetype_storage 0x0040
/* (with aliases) */
# define casio_filetype_pict casio_filetype_picture
# define casio_filetype_eactivity casio_filetype_eact
# define casio_filetype_e_activity casio_filetype_eact
@ -65,26 +69,31 @@ typedef unsigned int casio_filefor_t;
* The elements can be initialized or uninitialized depending on the
* file type. */
typedef struct casio_file_s {
struct casio_file {
/* file type, destination platform */
casio_filetype_t casio_file_type;
casio_filefor_t casio_file_for;
/* Add-in related data */
time_t casio_file_creation_date;
unsigned char *casio_file_content;
size_t casio_file_size;
/* Lists for various purposes */
int casio_file_count;
int casio_file__size;
char **casio_file_messages;
casio_pixel_t ***casio_file_fkeys;
/* Main memory */
casio_mcs_t *casio_file_mcs;
/* Picture-related data (also used for add-in icons) */
int casio_file_width;
int casio_file_height;
casio_pixel_t **casio_file_pixels; /* 0x0RGB */
@ -92,33 +101,36 @@ typedef struct casio_file_s {
casio_pixel_t **casio_file_icon_sel; /* 0x0RGB */
/* Other string data */
char casio_file_title[17];
char casio_file_intname[12];
casio_version_t casio_file_version;
} casio_file_t;
};
/* ---
* Methods.
* --- */
CASIO_BEGIN_DECLS
/* Make a file. */
CASIO_EXTERN int CASIO_EXPORT casio_make_picture
CASIO_EXTERN(int) casio_make_picture
OF((casio_file_t **casio__handle,
unsigned int casio__width, unsigned int casio__height));
CASIO_EXTERN int CASIO_EXPORT casio_make_mcs
OF((casio_file_t **casio__handle, int casio__count));
CASIO_EXTERN(int) casio_make_mcs
OF((casio_file_t **casio__handle));
CASIO_EXTERN int CASIO_EXPORT casio_make_fkey
CASIO_EXTERN(int) casio_make_fkey
OF((casio_file_t **casio__handle,
casio_filefor_t casio__for, int casio__count));
CASIO_EXTERN int CASIO_EXPORT casio_make_lang
CASIO_EXTERN(int) casio_make_lang
OF((casio_file_t **casio__handle,
casio_filefor_t casio__for, int casio__count));
CASIO_EXTERN int CASIO_EXPORT casio_make_addin
CASIO_EXTERN(int) casio_make_addin
OF((casio_file_t **casio__handle,
casio_filefor_t casio__for, size_t casio__size,
char const *casio__name, char const *casio__internal,
@ -126,20 +138,66 @@ CASIO_EXTERN int CASIO_EXPORT casio_make_addin
/* Free a file. */
CASIO_EXTERN void CASIO_EXPORT casio_free_file
CASIO_EXTERN(void) casio_free_file
OF((casio_file_t *casio__handle));
/* Decode a file. */
CASIO_EXTERN int CASIO_EXPORT casio_decode
CASIO_EXTERN(int) casio_decode
OF((casio_file_t **casio__handle,
char const *casio__path, tio_stream_t *casio__buffer,
char const *casio__filename, tio_stream_t *casio__buffer,
casio_filetype_t casio__expected_types));
/* Open and decode a file. */
/* General management functions for files */
CASIO_EXTERN int CASIO_EXPORT casio_open_file
OF((casio_file_t **casio__handle,
char const *casio__path, casio_filetype_t casio__expected_types));
CASIO_EXTERN(int) casio_get_file_type
OF((casio_file_t *casio__handle, casio_filetype_t *casio__type));
CASIO_EXTERN(int) casio_get_file_for
OF((casio_file_t *casio__handle, casio_filefor_t *casio__for));
/* Management functions for add-in functions. */
CASIO_EXTERN(int) casio_get_addin_code
OF((casio_file_t *casio__handle, void **casio__codep,
size_t *casio__sizep));
CASIO_EXTERN(int) casio_set_addin_code
OF((casio_file_t *casio__handle, void *casio__code, size_t casio__size));
CASIO_EXTERN(int) casio_get_addin_time
OF((casio_file_t *casio__handle, time_t *casio__timep));
CASIO_EXTERN(int) casio_set_addin_time
OF((casio_file_t *casio__handle, time_t const *casio__timep));
CASIO_EXTERN(int) casio_get_addin_name
OF((casio_file_t *casio__handle, char const **casio__name));
CASIO_EXTERN(int) casio_set_addin_name
OF((casio_file_t *casio__handle, char const *casio__name));
CASIO_EXTERN(int) casio_get_addin_internal_name
OF((casio_file_t *casio__handle, char const **casio__intname));
CASIO_EXTERN(int) casio_set_addin_internal_name
OF((casio_file_t *casio__handle, char const *casio__intname));
CASIO_EXTERN(int) casio_get_addin_version
OF((casio_file_t *casio__handle, casio_version_t const **casio__version));
CASIO_EXTERN(int) casio_set_addin_version
OF((casio_file_t *casio__handle, casio_version_t const *casio__version));
/* Management functions for main memory files. */
CASIO_EXTERN(int) casio_get_file_mcs
OF((casio_file_t *casio__handle, casio_mcs_t **casio__mcs));
CASIO_EXTERN(int) casio_set_file_mcs
OF((casio_file_t *casio__handle, casio_mcs_t *casio__mcs));
/* Management functions for e-activities.
* TODO */
/* Management functions for pictures. */
CASIO_EXTERN(int) casio_get_file_picture
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_FILE_H */

View File

@ -20,17 +20,24 @@
# define LIBCASIO_FONTCHAR_H
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
typedef casio_uint16_t FONTCHARACTER;
/* A multi-character should resolve as a maximum of 16 characters. */
# define CASIO_FONTCHAR_MULTI_MAX 16
CASIO_EXTERN int CASIO_EXPORT casio_is_fontchar_lead
CASIO_BEGIN_DECLS
CASIO_EXTERN(int) casio_is_fontchar_lead
OF((int casio__code));
CASIO_EXTERN int CASIO_EXPORT casio_fontchar_to_uni
CASIO_EXTERN(int) casio_fontchar_to_uni
OF((casio_uint16_t casio__code, casio_uint32_t *casio__uni));
CASIO_EXTERN int CASIO_EXPORT casio_uni_to_fontchar
CASIO_EXTERN(int) casio_uni_to_fontchar
OF((casio_uint32_t const *casio__uni, casio_uint16_t casio__code));
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_CHAR_H */

View File

@ -20,80 +20,7 @@
# define LIBCASIO_ITER_H 2018050901
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
/* Many things in libcasio work with iterators. This is the centralized
* iterator interface. */
struct casio_iter_s;
typedef struct casio_iter_s casio_iter_t;
/* ---
* Define something.
* --- */
/* The way this is done:
*
* When `casio_next()` is called, if there was a previous element,
* the `casio_nextfree_t` callback, if not NULL, will be called to free
* it, then in all cases, the `casio_next_t` callback will be called to
* get the next element. If the `casio_next_t` callback returns
* `casio_error_iter`, all following calls to `casio_next()` with this
* iterator won't call the callbacks and directly return the same error.
*
* When `casio_end()` is called, the `casio_end_t` callback, if not NULL,
* will be called. */
typedef int CASIO_EXPORT casio_next_t
OF((void *casio__cookie, void **casio__ptr));
typedef void CASIO_EXPORT casio_nextfree_t
OF((void *casio__cookie, void *casio__ptr));
typedef void CASIO_EXPORT casio_end_t
OF((void *casio__cookie));
typedef struct casio_iter_funcs_s {
casio_next_t *casio_iterfunc_next;
casio_nextfree_t *casio_iterfunc_nextfree;
casio_end_t *casio_iterfunc_end;
} casio_iter_funcs_t;
/* ---
* Functions.
* --- */
CASIO_BEGIN_DECLS
/* Start an iterator with `casio_iter_<whatever>(&iter, <other data>)`,
* with `iter` being of the `casio_iter_t *` type.
* Get the next element through `casio_next_<whatever>(iter, &ptr)`,
* which is usually a macro or function defined as
* `casio_next(iter, (void **)(PTRP))`.
* Then end the iterator using `casio_end(iter)`.
*
* Beware: any time you use `casio_next()` or `casio_end()`, the previous
* element might be free'd or re-used, so if you are interested in what is
* in it, copy the data before using one of the previous functions. */
CASIO_EXTERN int CASIO_EXPORT casio_iter
OF((casio_iter_t **casio__iterp, void *casio__cookie,
casio_iter_funcs_t const *casio__funcs));
CASIO_EXTERN int CASIO_EXPORT casio_next
OF((casio_iter_t *casio__iter, void **casio__ptr));
CASIO_EXTERN void CASIO_EXPORT casio_end
OF((casio_iter_t *casio__iter));
/* You can make a “super iterator” that makes an iterator out of two
* iterators! It will empty the first one, then the second one.
* It will also take care of closing them. */
CASIO_EXTERN int CASIO_EXPORT casio_combine_iterators
OF((casio_iter_t **casio__iterp,
casio_iter_t *casio__first,
casio_iter_t *casio__second));
CASIO_END_DECLS
CASIO_END_NAMESPACE
/* Actually libcasio uses libtio's iterators. */
# include <libtio.h>
#endif

View File

@ -30,6 +30,9 @@
# endif
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_link, casio_link_t)
CASIO_STRUCT(casio_link_info, casio_link_info_t)
CASIO_STRUCT(casio_screen, casio_screen_t)
/* ---
* Link and link information.
@ -39,9 +42,6 @@ CASIO_BEGIN_NAMESPACE
* You should only manipulate pointers to it (unless you're contributing
* to libcasio). */
struct casio_link_s;
typedef struct casio_link_s casio_link_t;
/* Link information.
* This is basically the identification information sent by the calculator,
* only in Protocol 7.00 (Graph 85 and following) and CAS100 (AFX,
@ -53,7 +53,7 @@ typedef struct casio_link_s casio_link_t;
# define casio_link_info_flag_bootcode 0x0002
# define casio_link_info_flag_os 0x0004
typedef struct casio_link_info_s {
struct casio_link_info {
unsigned long casio_link_info_flags;
/* Preprogrammed ROM information. */
@ -84,7 +84,7 @@ typedef struct casio_link_info_s {
char casio_link_info_username[17];
char casio_link_info_hwid[9];
char casio_link_info_cpuid[17];
} casio_link_info_t;
};
/* ---
* Basic callbacks.
@ -92,7 +92,7 @@ typedef struct casio_link_info_s {
/* The user shall confirm or not a link action. */
typedef int CASIO_EXPORT casio_link_confirm_t
typedef CASIO_HOOK_TYPE(int) casio_link_confirm_t
OF((void *casio__cookie));
/* This callback is for displaying the progress of an operation (usually
@ -100,46 +100,15 @@ typedef int CASIO_EXPORT casio_link_confirm_t
* packets. For initialization of the display, this callback is called
* with a packet ID superior to the number of packets. */
typedef void CASIO_EXPORT casio_link_progress_t
typedef CASIO_HOOK_TYPE(void) casio_link_progress_t
OF((void *casio__cookie, unsigned int casio__id,
unsigned int casio__total));
/* List files. */
typedef void CASIO_EXPORT casio_link_list_t
OF((void *casio__cookie, char const *casio__path,
const casio_stat_t *casio__stat));
/* ---
* Other structures.
* --- */
/* Screen. */
typedef struct casio_screen_s {
unsigned int casio_screen_width;
unsigned int casio_screen_height;
unsigned int casio_screen_realwidth;
unsigned int casio_screen_realheight;
casio_pixel_t **casio_screen_pixels;
} casio_screen_t;
/* ---
* Basic link handle operations.
* --- */
/* Useful flags for when opening a link.
*
* Here are the various transport protocols, which isn't given by the available
* operations on the stream (as it could be USB but we may not be able
* to do USB operations because of drivers such as the CESG502 driver
* on Microsoft Windows):
*
* `CASIO_LINKFLAG_SERIAL`: serial connexion.
* `CASIO_LINKFLAG_USB`: USB.
* `CASIO_LINKFLAG_SCSI`: SCSI operations.
*
* These are read if the connexion is serial (which means that the
* protocol cannot be determined and that the user needs to say which one
@ -152,65 +121,56 @@ typedef struct casio_screen_s {
*
* These are read if the protocol is protocol 7.00:
*
* `CASIO_LINKFLAG_ACTIVE`: start off as active.
* `CASIO_LINKFLAG_CHECK`: check (initial packet).
* `CASIO_LINKFLAG_TERM`: terminate.
* `CASIO_LINKFLAG_NODISC`: if we are checking, no environment discovery. */
* `CASIO_LINKFLAG_PASSIVE`: start off as active.
* `CASIO_LINKFLAG_NOCHECK`: check (initial packet).
* `CASIO_LINKFLAG_NODISC`: if we are checking, no environment discovery.
* `CASIO_LINKFLAG_TERM`: terminate. */
# define CASIO_LINKFLAG_SERIAL 0x00000000
# define CASIO_LINKFLAG_USB 0x00001000
# define CASIO_LINKFLAG_SCSI 0x00002000
# define CASIO_LINKFLAG_P7 0x00000100
# define CASIO_LINKFLAG_CAS40 0x00000200
# define CASIO_LINKFLAG_CAS50 0x00000400
# define CASIO_LINKFLAG_CAS100 0x00000600
# define CASIO_LINKFLAG_SCSI 0x00000800
# define CASIO_LINKFLAG_P7 0x00000000
# define CASIO_LINKFLAG_CAS40 0x00000100
# define CASIO_LINKFLAG_CAS50 0x00000200
# define CASIO_LINKFLAG_CAS100 0x00000300
# define CASIO_LINKFLAG_ACTIVE 0x00000001
# define CASIO_LINKFLAG_CHECK 0x00000002
# define CASIO_LINKFLAG_TERM 0x00000004
# define CASIO_LINKFLAG_NODISC 0x00000008
# define CASIO_LINKFLAG_PASSIVE 0x00000001
# define CASIO_LINKFLAG_NOCHECK 0x00000002
# define CASIO_LINKFLAG_NODISC 0x00000004
# define CASIO_LINKFLAG_NOSHIFT 0x00000008
# define CASIO_LINKFLAG_TERM 0x00000010
CASIO_BEGIN_DECLS
/* Open a serial link. */
/* Open a link. */
CASIO_EXTERN int CASIO_EXPORT casio_open_serial
OF((casio_link_t **casio__h, unsigned long casio__flags,
char const *casio__path,
tio_serial_attrs_t const *casio__attributes));
/* Open a USB link. */
CASIO_EXTERN int CASIO_EXPORT casio_open_usb
OF((casio_link_t **casio__h, unsigned long casio__flags,
int casio__bus, int casio__address));
/* Initialize a handle using a custom stream.
* This function will check if the stream is a USB stream by looking
* at the open mode of the stream. */
CASIO_EXTERN int CASIO_EXPORT casio_open_link
CASIO_EXTERN(int) casio_open_link
OF((casio_link_t **casio__h, unsigned long casio__flags,
tio_stream_t *casio__stream));
CASIO_EXTERN(int) casio_open_serial
OF((casio_link_t **casio__h, unsigned long casio__flags,
char const *casio__path, tio_serial_attrs_t const *casio__attributes));
CASIO_EXTERN(int) casio_open_usb
OF((casio_link_t **casio__h, unsigned long casio__flags,
int casio__bus, int casio__address));
/* De-initialize. */
CASIO_EXTERN void CASIO_EXPORT casio_close_link
CASIO_EXTERN(void) casio_close_link
OF((casio_link_t *casio__h));
/* Lock and unlock the associated mutex. */
CASIO_EXTERN int CASIO_EXPORT casio_lock_link
CASIO_EXTERN(int) casio_lock_link
OF((casio_link_t *casio__h));
CASIO_EXTERN int CASIO_EXPORT casio_trylock_link
CASIO_EXTERN(int) casio_trylock_link
OF((casio_link_t *casio__h));
CASIO_EXTERN void CASIO_EXPORT casio_unlock_link
CASIO_EXTERN(void) casio_unlock_link
OF((casio_link_t *casio__h));
/* Getters. */
CASIO_EXTERN const casio_link_info_t* CASIO_EXPORT casio_get_link_info
CASIO_EXTERN(casio_link_info_t const *) casio_get_link_info
OF((casio_link_t *casio__handle));
/* ---
@ -219,46 +179,37 @@ CASIO_EXTERN const casio_link_info_t* CASIO_EXPORT casio_get_link_info
/* Set the link settings. */
CASIO_EXTERN int CASIO_EXPORT casio_setlink
OF((casio_link_t *casio__handle, const tio_serial_attrs_t *casio__attrs));
CASIO_EXTERN(int) casio_setlink
OF((casio_link_t *casio__handle, tio_serial_attrs_t const *casio__attrs));
/* Receive and free a screen streaming frame.
* The screen is a double pointer because it is allocated or reallocated
* when required only. */
CASIO_EXTERN int CASIO_EXPORT casio_get_screen
OF((casio_link_t *casio__handle, casio_screen_t **casio__screen));
CASIO_EXTERN int CASIO_EXPORT casio_make_screen
OF((casio_screen_t **casio__screen, unsigned int casio__width,
unsigned int casio__height));
CASIO_EXTERN int CASIO_EXPORT casio_free_screen
OF((casio_screen_t *casio__screen));
CASIO_EXTERN(int) casio_get_screen
OF((casio_link_t *casio__handle, casio_picture_t **casio__screen));
/* Backup the ROM. */
CASIO_EXTERN int CASIO_EXPORT casio_backup_rom
OF((casio_link_t *casio__handle,
tio_stream_t *casio__buffer, casio_link_progress_t *casio__progress,
void *casio__pcookie));
CASIO_EXTERN(int) casio_backup_rom
OF((casio_link_t *casio__handle, tio_stream_t *casio__buffer,
casio_link_progress_t *casio__progress, void *casio__pcookie));
# ifndef LIBCASIO_DISABLED_FILE
CASIO_EXTERN int CASIO_EXPORT casio_backup_rom_file
OF((casio_link_t *casio__handle,
FILE *casio__file, casio_link_progress_t *casio__progress,
void *casio__pcookie));
# ifndef LIBTIO_DISABLED_FILE
CASIO_EXTERN(int) casio_backup_rom_file
OF((casio_link_t *casio__handle, FILE *casio__file,
casio_link_progress_t *casio__progress, void *casio__pcookie));
# endif
/* Upload and run an executable. */
CASIO_EXTERN int CASIO_EXPORT casio_upload_and_run
OF((casio_link_t *casio__handle,
tio_stream_t *casio__buffer, tio_off_t casio__size,
CASIO_EXTERN(int) casio_upload_and_run
OF((casio_link_t *casio__handle, tio_stream_t *casio__buffer,
unsigned long casio__loadaddr, unsigned long casio__straddr,
casio_link_progress_t *casio__disp, void *casio__pcookie));
# ifndef LIBCASIO_DISABLED_FILE
CASIO_EXTERN int CASIO_EXPORT casio_upload_and_run_file
# ifndef LIBTIO_DISABLED_FILE
CASIO_EXTERN(int) casio_upload_and_run_file
OF((casio_link_t *casio__handle, FILE *casio__program,
unsigned long casio__loadaddr, unsigned long casio__straddr,
casio_link_progress_t *casio__disp, void *casio__pcookie));

View File

@ -25,25 +25,26 @@ CASIO_BEGIN_DECLS
/* Get and set the log level at runtime. */
CASIO_EXTERN void CASIO_EXPORT casio_setlog
CASIO_EXTERN(void) casio_setlog
OF((const char *casio__level));
CASIO_EXTERN char const* CASIO_EXPORT casio_getlog
CASIO_EXTERN(char const *) casio_getlog
OF((void));
/* List log levels (deprecated interface) */
typedef void casio_log_list_t OF((void *casio__cookie,
char const *casio__str));
typedef CASIO_HOOK_TYPE(void) casio_log_list_t
OF((void *casio__cookie, char const *casio__str));
CASIO_EXTERN CASIO_DEPRECATED void CASIO_EXPORT casio_listlog
CASIO_DEPRECATED CASIO_EXTERN(void) casio_listlog
OF((casio_log_list_t *casio__callback, void *casio__cookie));
/* List log levels (new interface).
* This iterator yields strings (`const char *`). */
CASIO_EXTERN int CASIO_EXPORT casio_iter_log
OF((casio_iter_t **casio__iter));
# define casio_next_log(ITER, PTRP) (casio_next((ITER), (void **)(PTRP)))
CASIO_EXTERN(int) casio_iter_log
OF((tio_iter_t **casio__iter));
# define casio_next_log(ITER, PTRP) \
(tio_next((ITER), (void **)(char const **)(PTRP)))
CASIO_END_DECLS
CASIO_END_NAMESPACE

View File

@ -21,14 +21,10 @@
# include "cdefs.h"
# include "mcsfile.h"
# include "iter.h"
CASIO_BEGIN_NAMESPACE
/* Forward structure declarations (don't mind). */
struct casio_mcs_s;
typedef struct casio_mcs_s casio_mcs_t;
struct casio_mcsfuncs_s;
typedef struct casio_mcsfuncs_s casio_mcsfuncs_t;
CASIO_STRUCT(casio_mcs, casio_mcs_t)
CASIO_STRUCT(casio_mcsfuncs, casio_mcsfuncs_t)
/* ---
* Main Memory filesystem description.
@ -45,23 +41,23 @@ typedef struct casio_mcsfuncs_s casio_mcsfuncs_t;
*
* Here are the callbacks you should set: */
typedef int CASIO_EXPORT casio_mcs_get_t
typedef CASIO_HOOK_TYPE(int) casio_mcs_get_t
OF((void *casio__cookie, casio_mcsfile_t **casio__mcsfile,
casio_mcshead_t *casio__mcshead));
typedef int CASIO_EXPORT casio_mcs_put_t
typedef CASIO_HOOK_TYPE(int) casio_mcs_put_t
OF((void *casio__cookie, casio_mcsfile_t *casio__mcsfile));
typedef int CASIO_EXPORT casio_mcs_delete_t
typedef CASIO_HOOK_TYPE(int) casio_mcs_delete_t
OF((void *casio__cookie, casio_mcshead_t *casio__mcshead));
typedef int CASIO_EXPORT casio_mcs_iter_t
typedef CASIO_HOOK_TYPE(int) casio_mcs_iter_t
OF((void *casio__cookie, casio_iter_t **casio__iter));
typedef int CASIO_EXPORT casio_mcs_close_t
typedef CASIO_HOOK_TYPE(int) casio_mcs_close_t
OF((void *casio__cookie));
struct casio_mcsfuncs_s {
struct casio_mcsfuncs {
casio_mcs_get_t *casio_mcsfuncs_get;
casio_mcs_put_t *casio_mcsfuncs_put;
casio_mcs_delete_t *casio_mcsfuncs_delete;
@ -77,55 +73,57 @@ CASIO_BEGIN_DECLS
/* Open and close. */
CASIO_EXTERN int CASIO_EXPORT casio_open_mcs
CASIO_EXTERN(int) casio_open_mcs
OF((casio_mcs_t **casio__mcs, void *casio__cookie,
casio_mcsfuncs_t const *casio__funcs));
CASIO_EXTERN int CASIO_EXPORT casio_close_mcs
CASIO_EXTERN(int) casio_close_mcs
OF((casio_mcs_t *casio__mcs));
/* Get and put an MCS file. */
CASIO_EXTERN int CASIO_EXPORT casio_get_mcsfile
CASIO_EXTERN(int) casio_get_mcsfile
OF((casio_mcs_t *casio__mcs, casio_mcsfile_t **casio__mcsfile,
casio_mcshead_t *casio__mcshead));
CASIO_EXTERN int CASIO_EXPORT casio_put_mcsfile
CASIO_EXTERN(int) casio_put_mcsfile
OF((casio_mcs_t *casio__mcs, casio_mcsfile_t *casio__mcsfile,
int casio__change_ownership));
/* Transfer an MCS file. */
CASIO_EXTERN int CASIO_EXPORT casio_transfer_mcsfile
CASIO_EXTERN(int) casio_transfer_mcsfile
OF((casio_mcs_t *casio__dest, casio_mcs_t *casio__source,
casio_mcshead_t *casio__mcshead));
/* Delete an MCS file. */
CASIO_EXTERN int CASIO_EXPORT casio_delete_mcsfile
CASIO_EXTERN(int) casio_delete_mcsfile
OF((casio_mcs_t *casio__mcs, casio_mcshead_t *casio__mcshead));
/* List MCS files (the deprecated way). */
typedef void CASIO_EXPORT casio_mcslist_t
typedef CASIO_HOOK_TYPE(void) casio_mcslist_t
OF((void *casio__cookie, casio_mcshead_t const *casio__mcshead));
CASIO_EXTERN CASIO_DEPRECATED int CASIO_EXPORT casio_list_mcsfiles
CASIO_DEPRECATED CASIO_EXTERN(int) casio_list_mcsfiles
OF((casio_mcs_t *casio__mcs, casio_mcslist_t *casio__mcslist,
void *casio__mcookie));
/* Iterate on MCS entries. */
CASIO_EXTERN int CASIO_EXPORT casio_iter_mcsfiles
OF((casio_iter_t **casio__iter, casio_mcs_t *casio__mcs));
CASIO_EXTERN(int) casio_iter_mcsfiles
OF((tio_iter_t **casio__iter, casio_mcs_t *casio__mcs));
# define casio_next_mcshead(ITER, MCSFILEP) \
(casio_next((ITER), (void **)(casio_mcshead_t **)(MCSFILEP)))
(tio_next((ITER), (void **)(casio_mcshead_t **)(MCSFILEP)))
/* Make a temporary main memory. */
/* Make a temporary main memory or copy an existing main memory into
* one. */
CASIO_EXTERN int CASIO_EXPORT casio_open_local_mcs
CASIO_EXTERN(int) casio_open_local_mcs
OF((casio_mcs_t **casio__mcs));
CASIO_EXTERN(int) casio_copy_mcs
OF((casio_mcs_t **casio__mcs, casio_mcs_t *casio__source_mcs));
CASIO_END_DECLS
CASIO_END_NAMESPACE

View File

@ -26,7 +26,11 @@
# define casio_theta 27
# define casio_r 28
# define casio_ans 29
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_mcscell, casio_mcscell_t)
CASIO_STRUCT(casio_mcshead, casio_mcshead_t)
CASIO_STRUCT(casio_mcsfile, casio_mcsfile_t)
/* A lot of CASIO calculators (like the fx-9xxx, fx-CGxx, fx-CPxxx) have
* a main memory, also called MCS (for Main Control Structure).
@ -166,11 +170,11 @@ typedef unsigned int casio_mcsinfo_t;
/* And the main structure: */
typedef struct casio_mcscell_s {
struct casio_mcscell {
unsigned int casio_mcscell_flags;
casio_bcd_t casio_mcscell_real;
casio_bcd_t casio_mcscell_imgn;
} casio_mcscell_t;
};
/* ---
* Main Memory file head.
@ -191,7 +195,7 @@ typedef struct casio_mcscell_s {
*
* Here is the main structure. Don't be afraid, it doesn't bite. */
typedef struct casio_mcshead_s {
struct casio_mcshead {
# define casio_mcshead_for casio_mcshead_flags
unsigned long casio_mcshead_flags;
@ -217,7 +221,7 @@ typedef struct casio_mcshead_s {
char casio_mcshead_dirname[9];
char casio_mcshead_cas_app[4];
char casio_mcshead_datatype[3];
} casio_mcshead_t;
};
/* ---
* Main Memory file.
@ -225,7 +229,7 @@ typedef struct casio_mcshead_s {
/* Here is the file data. Its content depends on what's in the head. */
typedef struct casio_mcsfile_s {
struct casio_mcsfile {
/* head */
casio_mcshead_t casio_mcsfile_head;
@ -243,7 +247,7 @@ typedef struct casio_mcsfile_s {
/* for settings */
casio_setup_t casio_mcsfile_setup;
} casio_mcsfile_t;
};
/* Some macros to manipulate the password. */
@ -260,65 +264,66 @@ CASIO_BEGIN_DECLS
/* Make a main memory file, prepare it, and free it. */
CASIO_EXTERN int CASIO_EXPORT casio_make_mcsfile
CASIO_EXTERN(int) casio_make_mcsfile
OF((casio_mcsfile_t **casio__handle, casio_mcshead_t const *casio__head));
CASIO_EXTERN int CASIO_EXPORT casio_prepare_mcsfile
CASIO_EXTERN(int) casio_prepare_mcsfile
OF((casio_mcsfile_t *casio__handle, casio_mcshead_t const *casio__head));
CASIO_EXTERN void CASIO_EXPORT casio_free_mcsfile
CASIO_EXTERN(void) casio_free_mcsfile
OF((casio_mcsfile_t *casio__handle));
/* Copy or duplicate a main memory file. */
CASIO_EXTERN int CASIO_EXPORT casio_duplicate_mcsfile
CASIO_EXTERN(int) casio_duplicate_mcsfile
OF((casio_mcsfile_t **casio__handle, casio_mcsfile_t *casio__old));
CASIO_EXTERN int CASIO_EXPORT casio_copy_mcsfile
CASIO_EXTERN(int) casio_copy_mcsfile
OF((casio_mcsfile_t *casio__handle, casio_mcsfile_t *casio__old));
/* Decode and encode an MCS file from an MCS archive. */
CASIO_EXTERN int CASIO_EXPORT casio_decode_mcsfile_head
CASIO_EXTERN(int) casio_decode_mcsfile_head
OF((casio_mcshead_t *casio__head, int casio__raw_type,
unsigned char const *casio__groupname,
unsigned char const *casio__dirname,
unsigned char const *casio__filename,
unsigned long casio__filesize));
CASIO_EXTERN int CASIO_EXPORT casio_decode_mcsfile
CASIO_EXTERN(int) casio_decode_mcsfile
OF((casio_mcsfile_t **casio__handle,
casio_mcshead_t const *casio__head,
tio_stream_t *casio__buffer));
CASIO_EXTERN int CASIO_EXPORT casio_decode_mcsfile_data
CASIO_EXTERN(int) casio_decode_mcsfile_data
OF((casio_mcsfile_t **casio__handle,
casio_mcshead_t const *casio__head,
void const *casio__data, size_t casio__size));
CASIO_EXTERN int CASIO_EXPORT casio_encode_mcsfile
CASIO_EXTERN(int) casio_encode_mcsfile
OF((casio_mcsfile_t *casio__handle, tio_stream_t *casio__buffer));
/* Decode and encode an MCS file from a CASIOLINK environment. */
CASIO_EXTERN int CASIO_EXPORT casio_decode_casfile_head
CASIO_EXTERN(int) casio_decode_casfile_head
OF((casio_mcshead_t *casio__head, tio_stream_t *casio__buffer));
CASIO_EXTERN int CASIO_EXPORT casio_decode_casfile_part
CASIO_EXTERN(int) casio_decode_casfile_part
OF((casio_mcsfile_t *casio__file, tio_stream_t *casio__stream));
CASIO_EXTERN int CASIO_EXPORT casio_encode_casfile_head
CASIO_EXTERN(int) casio_encode_casfile_head
OF((casio_mcshead_t *casio__head, tio_stream_t *casio__buffer));
CASIO_EXTERN int CASIO_EXPORT casio_encode_casfile_part
CASIO_EXTERN(int) casio_encode_casfile_part
OF((casio_mcsfile_t *casio__file, tio_stream_t *casio__buffer));
/* Correct a head (add raw data). */
CASIO_EXTERN int CASIO_EXPORT casio_correct_mcshead
CASIO_EXTERN(int) casio_correct_mcshead
OF((casio_mcshead_t *casio__head, unsigned long casio__mcsfor));
/* Compare MCS files (for ordering). */
CASIO_EXTERN int CASIO_EXPORT casio_match_mcsfiles
CASIO_EXTERN(int) casio_match_mcsfiles
OF((casio_mcshead_t *casio__first, casio_mcshead_t *casio__second));
CASIO_EXTERN int CASIO_EXPORT casio_compare_mcsfiles
CASIO_EXTERN(int) casio_compare_mcsfiles
OF((casio_mcshead_t *casio__first, casio_mcshead_t *casio__second));
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_MCSFILE_H */

View File

@ -1,81 +0,0 @@
/* ****************************************************************************
* libcasio/misc.h -- libcasio miscallaneous utilities.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_MISC_H
# define LIBCASIO_MISC_H 2018051601
# include "cdefs.h"
# include "stream.h"
# include "fs.h"
CASIO_BEGIN_NAMESPACE
CASIO_BEGIN_DECLS
/* As there is no portable sleep function, libcasio implements one.
* It takes a callback, of the following form: */
CASIO_EXTERN int CASIO_EXPORT casio_sleep
OF((unsigned long casio__ms));
/* If the default function is not good enough for you, just change it
* using the following function. */
typedef void casio_sleep_t OF((unsigned long casio__ms));
CASIO_EXTERN void CASIO_EXPORT casio_set_sleep_func
OF((casio_sleep_t *casio__func));
/* As for time and timeouts management, here are functions to time
* anything in libcasio. Times are expressed in milliseconds. */
struct casio_timer_s;
typedef struct casio_timer_s casio_timer_t;
CASIO_EXTERN int CASIO_EXPORT casio_get_timer
OF((casio_timer_t **casio__timer));
CASIO_EXTERN void CASIO_EXPORT casio_free_timer
OF((casio_timer_t *casio__timer));
CASIO_EXTERN int CASIO_EXPORT casio_get_spent_time
OF((casio_timer_t *casio__timer, unsigned long *casio__spent));
/* You can change these functions too! */
typedef int CASIO_EXPORT casio_get_timer_t
OF((casio_timer_t **casio__timer));
typedef void CASIO_EXPORT casio_free_timer_t
OF((casio_timer_t *casio__timer));
typedef int CASIO_EXPORT casio_get_spent_time_t
OF((casio_timer_t *casio__timer, unsigned long *casio__spent));
CASIO_EXTERN int CASIO_EXPORT casio_set_timer_funcs
OF((casio_get_timer_t *casio__get_timer,
casio_free_timer_t *casio__free_timer,
casio_get_spent_time_t *casio__get_spent_time));
/* And here are cross-platform allocation functions.
* They are defined just in case. */
CASIO_EXTERN void* CASIO_EXPORT casio_alloc
OF((size_t casio__num_elements, size_t casio__element_size));
CASIO_EXTERN void CASIO_EXPORT casio_free
OF((void *casio__ptr));
CASIO_END_DECLS
CASIO_END_NAMESPACE
#endif /* LIBCASIO_MISC_H */

View File

@ -1,36 +0,0 @@
/* ****************************************************************************
* libcasio/mutex.h -- libcasio mutexes.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#ifndef LIBCASIO_MUTEX_H
# define LIBCASIO_MUTEX_H 1
# include <libcasio/cdefs.h>
typedef int casio_mutex_t;
CASIO_EXTERN void CASIO_EXPORT casio_init_lock
OF((casio_mutex_t *casio__mutex));
CASIO_EXTERN int CASIO_EXPORT casio_lock
OF((casio_mutex_t *casio__mutex));
CASIO_EXTERN int CASIO_EXPORT casio_trylock
OF((casio_mutex_t *casio__mutex));
CASIO_EXTERN void CASIO_EXPORT casio_unlock
OF((casio_mutex_t *casio__mutex));
#endif /* LIBCASIO_MUTEX_H */

View File

@ -25,7 +25,11 @@
#ifndef LIBCASIO_NUMBER_H
# define LIBCASIO_NUMBER_H
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_bcd, casio_bcd_t)
CASIO_STRUCT(casio_casbcd, casio_casbcd_t)
CASIO_STRUCT(casio_mcsbcd, casio_mcsbcd_t)
# define CASIO_BCD_MANTISSA_SIZE 16
# define CASIO_BCD_EXPMIN -99
@ -68,11 +72,11 @@ CASIO_BEGIN_NAMESPACE
# define casio_make_bcdflags(SPE, NEG, PREC) \
(((SPE) << 7) | ((NEG) << 6) | (PREC))
typedef struct casio_bcd_s {
struct casio_bcd {
unsigned char casio_bcd_flags;
char casio_bcd_exp;
char casio_bcd_mant[CASIO_BCD_MANTISSA_SIZE];
} casio_bcd_t;
};
/* ---
* Raw formats.
@ -92,11 +96,11 @@ typedef struct casio_bcd_s {
# define casio_casbcdflag_negative 0x50
# define casio_casbcdflag_pow_neg 0x01
typedef struct casio_casbcd_s {
struct casio_casbcd {
unsigned char casio_casbcd_mant[8];
unsigned char casio_casbcd_flags;
unsigned char casio_casbcd_exp;
} casio_casbcd_t;
};
/* MCS BCD -- the most recent BCD format.
* Only the first 9 bytes are significant.
@ -110,10 +114,10 @@ typedef struct casio_casbcd_s {
* The other values (from the fourth nibble) are the packed BCD mantissa.
* It starts at 10^0. */
typedef struct casio_mcsbcd_s {
struct casio_mcsbcd {
unsigned char casio_mcsbcd_BCDval[9];
unsigned char casio_mcsbcd__align[3];
} casio_mcsbcd_t;
};
/* ---
* Conversion utilities.
@ -123,28 +127,28 @@ CASIO_BEGIN_DECLS
/* From and to MCS BCD. */
CASIO_EXTERN int CASIO_EXPORT casio_bcd_frommcs
CASIO_EXTERN(int) casio_bcd_frommcs
OF((casio_bcd_t *casio__bcd, casio_mcsbcd_t const *casio__raw));
CASIO_EXTERN int CASIO_EXPORT casio_bcd_tomcs
CASIO_EXTERN(int) casio_bcd_tomcs
OF((casio_mcsbcd_t *casio__raw, casio_bcd_t const *casio__bcd));
/* From and to CAS BCD. */
CASIO_EXTERN int CASIO_EXPORT casio_bcd_fromcas
CASIO_EXTERN(int) casio_bcd_fromcas
OF((casio_bcd_t *casio__bcd, casio_casbcd_t const *casio__raw));
CASIO_EXTERN int CASIO_EXPORT casio_bcd_tocas
CASIO_EXTERN(int) casio_bcd_tocas
OF((casio_casbcd_t *casio__raw, casio_bcd_t const *casio__bcd));
/* From and to C-double */
CASIO_EXTERN void CASIO_EXPORT casio_bcd_fromdouble
CASIO_EXTERN(void) casio_bcd_fromdouble
OF((casio_bcd_t *casio__bcd, double casio__raw));
CASIO_EXTERN double CASIO_EXPORT casio_bcd_todouble
CASIO_EXTERN(double) casio_bcd_todouble
OF((casio_bcd_t const *casio__bcd));
/* Make a string out of a BCD */
CASIO_EXTERN size_t CASIO_EXPORT casio_bcdtoa
CASIO_EXTERN(size_t) casio_bcdtoa
OF((char *casio__buf, size_t casio__len, casio_bcd_t const *casio__bcd));
CASIO_END_DECLS

View File

@ -19,19 +19,16 @@
#ifndef LIBCASIO_PICTURE_H
# define LIBCASIO_PICTURE_H
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
/* This file describes the picture formats CASIO has used for various purposes
* (screenshots, pictures, screenstreaming), and that libcasio is able to
* decode.
*
* libcasio decodes from, encodes to, and converts using 32-bit pixels, which
* are basically 0x00RRGGBB. */
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_picture, casio_picture_t)
/* Pixel definition, with utilities. */
typedef casio_uint32_t casio_pixel_t;
# define casio_pixel(CASIO__R, CASIO__G, CASIO__B) \
((((CASIO__R) & 0xFF) << 16) | (((CASIO__G) & 0xFF) << 8) \
((casio_pixel_t)(((CASIO__R) & 0xFF) << 16) | (((CASIO__G) & 0xFF) << 8) \
| ((CASIO__B) & 0xFF))
# define casio_set_pixel(CASIO__PIX, CASIO__R, CASIO__G, CASIO__B) \
(CASIO__PIX = casio_pixel(CASIO__R, CASIO__G, CASIO__B))
@ -50,186 +47,86 @@ typedef casio_uint32_t casio_pixel_t;
# define casio_set_pixel_b(CASIO__PIX, CASIO__VAL) \
(CASIO__PIX = casio_pixel_with_b(CASIO__PIX, CASIO__VAL))
# define casio_get_pixel_r(CASIO__PIX, CASIO__VAL) \
(((CASIO__PIX) >> 16) & 0xFF)
# define casio_get_pixel_g(CASIO__PIX, CASIO__VAL) \
(((CASIO__PIX) >> 8) & 0xFF)
# define casio_get_pixel_b(CASIO__PIX, CASIO__VAL) \
( (CASIO__PIX) & 0xFF)
# define casio_pixel_r(CASIO__PIX) \
((int)((CASIO__PIX) >> 16) & 0xFF)
# define casio_pixel_g(CASIO__PIX) \
((int)((CASIO__PIX) >> 8) & 0xFF)
# define casio_pixel_b(CASIO__PIX) \
((int) (CASIO__PIX) & 0xFF)
/* The format pictures this file describes fit in a `casio_pictureformat_t`.
* The (arbitrary) codes for them is more or less 0xBBVS, where 'BB' is the
* number of bits each pixel occupy (in total), 'V' is the variation for
* this number of bits, and 'S' is the special hex digit (e.g. reverse).
/* Color code definitions. */
typedef int casio_colorcode_t;
# define casio_colorcode_black 0x0 /* 0x000000 */
# define casio_colorcode_blue 0x1 /* 0x0000FF */
# define casio_colorcode_green 0x2 /* 0x00FF00 */
# define casio_colorcode_cyan 0x3 /* 0x00FFFF */
# define casio_colorcode_red 0x4 /* 0xFF0000 */
# define casio_colorcode_magenta 0x5 /* 0xFF00FF */
# define casio_colorcode_yellow 0x6 /* 0xFFFF00 */
# define casio_colorcode_white 0x7 /* 0xFFFFFF */
/* Picture format definitions.
*
* Do not use the format described above other than to define your own
* formats, as it might change! */
* The rule of thumb for the values defined here is that they should be more
* or less `0xBBVS`, where `BB` is the number of bits each pixel
* occupy (in total), `V` is the variation for this number of bits,
* and `S` is the special hex digit (e.g. reverse); this rule might change
* later, so don't rely on it. */
typedef unsigned int casio_pictureformat_t;
/* ---
* Monochrome pictures with fill bits.
* --- */
/* In this format, each bit represents a pixel (so one byte contains eight
* pixels). If the width is not divisible by eight, then the last bits of the
* last byte of the line are unused (fill bits), and the next line starts at
* the beginning of the next byte ; this makes the navigation between lines
* easier, but takes up more space.
*
* An off bit (0b0) represents a white pixel, and an on bit (0b1) represents
* a black pixel. Reverse white and black in the `_r` special type. */
# define casio_pictureformat_1bit 0x0100
# define casio_pictureformat_1bit_r 0x0101
/* To calculate the size, it's simple: just calculate the number of bytes
* a line occupies, then multiply it by the number of lines. */
/* ---
* Packed monochrome pictures.
* --- */
/* Packed monochrome pictures is basically the same than the previous format,
* except there are no fill bits: if a picture width is 6 pixels, then the
* second line will start at the seventh bit of the first byte (where it would
* start at the first bit of the second byte with fill bits).
*
* The navigation to a line is less easy as it takes at least one division. */
# define casio_pictureformat_1bit 0x0100
# define casio_pictureformat_1bit_r 0x0101
# define casio_pictureformat_1bit_packed 0x0110
# define casio_pictureformat_1bit_packed_r 0x0111
/* To calculate the size, find out the number of occupied bits, divide by
* eight to get the bytes, and make sure to keep an extra byte if there are
* left bits. */
/* ---
* Old monochrome format.
* --- */
/* The old monochrome format used by CASIO is basically a normal monochrome
* format (the width is usually 96 or 128, so no need for fill bits), except
* that it starts with the last byte (where the bits are in left to right
* order), but then it goes from right to left, and from bottom to top. */
# define casio_pictureformat_1bit_old 0x0120
/* The size is the same as for normal 1-bit monochrome pictures, only the
* byte order changes. */
/* ---
* Dual monochrome format.
* --- */
/* This is the format used for the Prizm's projector mode. It is composed of
* two monochrome pictures (with sizes divisible by eight).
* It is basically gray pictures, with white, light gray, dark gray and
* black. */
# define casio_pictureformat_2bit_dual 0x0200
/* To calculate the size, well, we just have two monochrome screens. */
/* ---
* 4-bit RGB_ format.
* --- */
/* This is a 4 bit per pixel format. There is no need for fill nibbles.
* Each nibble (group of 4 bits) is made of the following:
* - one bit for red (OR by 0xFF0000);
* - one bit for green (OR by 0x00FF00);
* - one bit for blue (OR by 0x0000FF);
* - one alignment bit. */
# define casio_pictureformat_4bit 0x0400
# define casio_pictureformat_4bit_rgb 0x0400
/* Calculating the size is trivial: just divide the number of pixels by two. */
/* ---
* 4-bit code format.
* --- */
/* In this encoding, each nibble for a pixel represents one of these colors: */
# define casio_color_black 0x0 /* 0x000000 */
# define casio_color_blue 0x1 /* 0x0000FF */
# define casio_color_green 0x2 /* 0x00FF00 */
# define casio_color_cyan 0x3 /* 0x00FFFF */
# define casio_color_red 0x4 /* 0xFF0000 */
# define casio_color_magenta 0x5 /* 0xFF00FF */
# define casio_color_yellow 0x6 /* 0xFFFF00 */
# define casio_color_white 0x7 /* 0xFFFFFF */
/* Here is the encoding code: */
# define casio_pictureformat_4bit_code 0x0410
/* The size is calculated the same way as previously. */
/* ---
* Quad-monochrome VRAM formats.
* --- */
/* This format is used by old CASIO models. It is made of four monochrome
* pictures (no need for fill bits), where the palettes are:
* - for the `color` variant: [orange, green, blue, white (bg)]
* - for the `mono` variant: [(unused), (unused), black, white (bg)] */
# define casio_pictureformat_4bit_color 0x0420
# define casio_pictureformat_4bit_mono 0x0421
/* To get the size, just multiply the size of a VRAM by four. */
/* ---
* Casemul format.
* --- */
/* This format is used by Casemul.
* It is basically arbitrary color codes, where, for example, 1 is orange.
* You can check the full color codes in `src/picture.c`. */
# define casio_pictureformat_casemul 0x0800
/* Each pixel takes one byte. */
/* ---
* 16-bit R5G6B5 format.
* --- */
/* This is the format of the Prizm's VRAM. Each pixel is two bytes long,
* the first five bits represent the high five (clap!) bits of the red part,
* the next six bits represent the high six bits of the green part,
* the last five bits represent the high five (re-clap!) bits of the blue
* part. */
# define casio_pictureformat_16bit 0x1000
/* Two bytes per pixel. */
# define casio_pictureformat_1bit_old 0x0120
# define casio_pictureformat_2bit_dual 0x0200
# define casio_pictureformat_4bit 0x0400
# define casio_pictureformat_4bit_rgb 0x0400
# define casio_pictureformat_4bit_code 0x0410
# define casio_pictureformat_4bit_color 0x0420
# define casio_pictureformat_4bit_mono 0x0421
# define casio_pictureformat_casemul 0x0800
# define casio_pictureformat_16bit 0x1000
/* ---
* Utilities.
* --- */
/* Here are the functions to decode/encode pictures using this format: */
CASIO_BEGIN_DECLS
CASIO_EXTERN size_t CASIO_EXPORT casio_get_picture_size
OF((casio_pixel_t **casio__pixels,
casio_pictureformat_t casio__format,
unsigned int casio__width, unsigned int casio__height));
/* Picture management. */
CASIO_EXTERN int CASIO_EXPORT casio_decode_picture
OF((casio_pixel_t **casio__pixels,
void const *casio__raw, casio_pictureformat_t casio__format,
unsigned int casio__width, unsigned casio__height));
CASIO_EXTERN(void) casio_free_picture
OF((casio_picture_t *casio__picture));
CASIO_EXTERN int CASIO_EXPORT casio_encode_picture
OF((void *casio__raw, casio_pixel_t const * const *casio__pixels,
casio_pictureformat_t casio__format,
unsigned int casio__width, unsigned casio__height));
CASIO_EXTERN(int) casio_get_picture_dimensions
OF((casio_picture_t *casio__picture, unsigned int casio__widthp,
unsigned int casio__heightp));
CASIO_EXTERN(int) casio_access_pixels
OF((casio_picture_t *casio__picture, casio_pixel_t ***casio__pixelsp));
/* Picture encoding and decoding. */
CASIO_EXTERN(int) casio_decode_picture
OF((casio_picture_t **casio__picturep, unsigned int casio__width,
unsigned int casio__height, casio_pictureformat_t casio__format,
tio_stream_t *casio__buffer));
CASIO_EXTERN(int) casio_decode_picture_buffer
OF((casio_picture_t **casio__picturep, unsigned int casio__width,
unsigned int casio__height, casio_pictureformat_t casio__format,
void const *casio__data, size_t casio__data_size));
CASIO_EXTERN(int) casio_get_picture_encoded_size
OF((casio_picture_t *casio__picture, casio_pictureformat_t casio__format,
size_t *casio__sizep));
CASIO_EXTERN(int) casio_encode_picture
OF((casio_picture_t *casio__picture,
void *casio__buf, size_t casio__buf_size));
CASIO_END_DECLS
CASIO_END_NAMESPACE

View File

@ -52,7 +52,7 @@
* The passive side then answers with either an ACK (0x06), or
* an overwrite error (0x21) if the file already exists.
*
* If we, as te active side, are in an overwrite confirmation situation,
* If we, as the active side, are in an overwrite confirmation situation,
* we can either send an ABORT (0x15) to not overwrite, or an ACK if it
* accepts. If we have something else than an ACK after the overwrite
* confirmation, then this means that the passive side cannot overwrite.

View File

@ -21,6 +21,7 @@
# include "../cdefs.h"
# include "../link.h"
# include "typz.h"
CASIO_BEGIN_NAMESPACE
/* ---
@ -33,7 +34,7 @@ CASIO_BEGIN_NAMESPACE
*
* Here are the known packet types: */
typedef unsigned int casio_seven_type_t;
typedef int casio_seven_type_t;
# define casio_seven_type_cmd 0x01 /* ask something (initiate packet flow) */
# define casio_seven_type_data 0x02 /* send some data */
@ -47,11 +48,15 @@ typedef unsigned int casio_seven_type_t;
/* The subtype has a different meaning according to the type it is used with.
* For check packets, it can mean: */
typedef int casio_seven_chk_t;
# define casio_seven_chk_ini 0x00 /* initial check */
# define casio_seven_chk_wait 0x01 /* in-communication check, while waiting */
/* For ACK packets: */
typedef int casio_seven_ack_t;
# define casio_seven_ack_normal 0x00 /* normal ACK */
# define casio_seven_ack_ow 0x01 /* confirm overwrite */
# define casio_seven_ack_ext 0x02 /* extended ACK */
@ -59,7 +64,7 @@ typedef unsigned int casio_seven_type_t;
/* For NAK packets (error packets): */
typedef unsigned int casio_seven_err_t;
typedef int casio_seven_err_t;
# define casio_seven_err_default 0x00 /* default error (unused?) */
# define casio_seven_err_resend 0x01 /* checksum/timeout error,

View File

@ -35,7 +35,7 @@ CASIO_BEGIN_NAMESPACE
* - RM2: 2-bit mode?
*
* Once the SIZE field (of 6 or 8 characters depending on the type) is
* made of the following: */
* passed, the header is made of the following: */
typedef struct casio_typz_s {
/* Dimensions. */
@ -43,7 +43,7 @@ typedef struct casio_typz_s {
unsigned char casio_typz_height[4];
unsigned char casio_typz_width[4];
/* One: we are number one but it is in ascii (always "1") */
/* One: we are number one but it is in ascii (always '1') */
unsigned char casio_typz_one;

View File

@ -19,7 +19,10 @@
#ifndef LIBCASIO_SETUP_H
# define LIBCASIO_SETUP_H
# include "cdefs.h"
CASIO_BEGIN_NAMESPACE
CASIO_STRUCT(casio_setup, casio_setup_t)
CASIO_STRUCT(casio_setup_export, casio_setup_export_t)
/* The real setup from the calculator is either a group of 100/200 byte
* register, or a string-byte map (e.g. "Axes" -> 0x01).
@ -94,12 +97,12 @@ CASIO_BEGIN_NAMESPACE
/* Main structure. */
typedef struct casio_setup_s {
struct casio_setup {
unsigned int casio_setup_iflags;
unsigned int casio_setup_wflags;
unsigned int casio_setup_mflags;
unsigned char casio_setup_vals[casio_setup_nvals];
} casio_setup_t;
};
/* ---
* Utilities.
@ -109,39 +112,26 @@ CASIO_BEGIN_DECLS
/* Initialize the structure. */
CASIO_EXTERN void CASIO_EXPORT casio_init_setup
CASIO_EXTERN(void) casio_init_setup
OF((casio_setup_t *casio__setup));
/* Feed the structure. */
CASIO_EXTERN int CASIO_EXPORT casio_feed_setup_seven
CASIO_EXTERN(int) casio_feed_setup_seven
OF((casio_setup_t *casio__setup, char const *casio__name, int casio__val));
CASIO_EXTERN int CASIO_EXPORT casio_feed_setup_mcs
CASIO_EXTERN(int) casio_feed_setup_mcs
OF((casio_setup_t *casio__setup, int casio__id, int casio__val));
/* Export settings into a map. */
# if 0
typedef void casio_setup_export_t
OF((void *casio__cookie, const char *casio__name, int casio__value));
CASIO_EXTERN void CASIO_EXPORT casio_export_setup
OF((casio_setup_t *casio__setup, casio_setup_export_t *casio__export,
void *casio__cookie));
-- or --
struct casio_setup_export {
char const *casio_setup_export_name;
int casio_setup_export_code;
int casio_setup_export_val;
};
typedef struct casio_setup_export_seven casio_setup_export_seven_t;
CASIO_EXTERN casio_iter_t *CASIO_EXPORT casio_export_setup_seven
CASIO_EXTERN(tio_iter_t *) casio_export_setup_seven
OF((casio_setup_t *casio__setup));
# endif
CASIO_END_DECLS
CASIO_END_NAMESPACE

View File

@ -34,26 +34,19 @@ CASIO_BEGIN_DECLS
/* Make a stream out of another, while calculating a 32-bit checksum. */
CASIO_EXTERN int CASIO_EXPORT casio_open_csum32
CASIO_EXTERN(int) casio_open_csum32
OF((tio_stream_t **casio__stream, tio_stream_t *casio__original,
casio_uint32_t *casio__csum));
/* ---
* Find devices.
* --- */
/* On serial buses. */
typedef int CASIO_EXPORT casio_iter_serial_t
OF((casio_iter_t **));
/* Find devices on serial buses. */
# define casio_next_serial(ITER, NEXTP) \
casio_next((ITER), (void **)(char const **)(NEXTP))
CASIO_EXTERN int CASIO_EXPORT casio_iter_serial
CASIO_EXTERN(int) casio_iter_serial
OF((casio_iter_t **casio__iterp));
/* On USB buses. */
/* Find devices on USB buses. */
# define CASIO_USB_TYPE_UNKNOWN 0 /* Unknown type (not a calculator?) */
# define CASIO_USB_TYPE_LEGACY 1 /* Protocol 7.00 over bulk transfers */
@ -69,21 +62,9 @@ typedef struct casio_usb_entry_s {
# define casio_next_usb(ITER, NEXTP) \
casio_next((ITER), (void **)(casio_usb_entry_t **)(NEXTP))
CASIO_EXTERN int CASIO_EXPORT casio_iter_usb
CASIO_EXTERN(int) casio_iter_usb
OF((casio_iter_t **casio__iterp));
/* ---
* Open streams.
* --- */
CASIO_EXTERN int CASIO_EXPORT casio_open_serial_stream
OF((tio_stream_t **casio__stream, char const *casio__path,
tio_serial_attrs_t const *casio__attributes));
CASIO_EXTERN int CASIO_EXPORT casio_open_usb_stream
OF((tio_stream_t **casio__stream,
int casio__bus, int casio__address));
CASIO_END_DECLS
CASIO_END_NAMESPACE

118
lib/error.c Normal file
View File

@ -0,0 +1,118 @@
/* ****************************************************************************
* errors.c -- error strings.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#define LIBCASIO_NO_STRERROR
#include "internals.h"
#define ARR_SIZE 0x74
#define UNKNOWN NULL, NULL
const char* CASIO_EXPORT casio_error_strings[128] = {
/* Miscallaneous errors. */
"casio_error_none", "no error has occured",
"casio_error_unknown", "an unknown error has occured",
"casio_error_alloc", "a memory allocation has failed",
"casio_error_op", "this operation is unsupported",
"casio_error_arg", "an argument was invalid",
"casio_error_lock", "mutex is locked",
"casio_error_iter", "no more elements in the iterator",
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* Stream errors. */
"casio_error_stream", "the stream is invalid/no (more) stream",
"casio_error_read", "a read operation on the stream has failed",
"casio_error_write", "a write operation on the stream has failed",
"casio_error_seek", "a seek operation on the stream has failed",
"casio_error_timeout", "a timeout has occurred",
"casio_error_access", "could not get access to the device",
"casio_error_eof", "an end of file event has occured",
"casio_error_scsi", "a SCSI operation on the stream has failed",
"casio_error_usb", "a USB operation on the stream has failed",
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN,
/* Link errors. */
"casio_error_init", "the link was uninitialized",
"casio_error_shift", "illegal double shifting",
"casio_error_damned", "irrecoverable link error",
"casio_error_int", "interrupted by user",
"casio_error_active", "not in active/passive mode",
"casio_error_noow", "denied overwrite",
"casio_error_command", "unsupported command",
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
/* Filesystem errors. */
"casio_error_device", "unsupported storage device",
"casio_error_fullmem", "full memory",
"casio_error_notfound", "file not found",
"casio_error_empty", "empty files aren't allowed",
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,
/* Decoding errors. */
"casio_error_magic", "corrupted or unknown file format",
"casio_error_csum", "invalid checksum",
"casio_error_wrong", "not one of the allowed file types",
"casio_error_seq", "sequence error",
"casio_error_noeq", "character does not translate"
};
/* ---
* Public functions.
* --- */
/* `casio_error_name()`: get the error name. */
CASIO_EXTERN(char const *) casio_error_name(int code)
{
char const *nm;
if (code >= ARR_SIZE || !(nm = errors[code + code]))
return ("(unknown libcasio error)");
return (nm);
}
/* `casio_error_desc()`: get the error description. */
CASIO_EXTERN(char const *) casio_error_desc(int code)
{
char const *ds;
if (code >= ARR_SIZE || !(ds = errors[code + code + 1]))
return ("(unknown libcasio error)");
return (ds);
}

View File

@ -1,89 +0,0 @@
/* ****************************************************************************
* errors.c -- error strings.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#define LIBCASIO_NO_STRERROR
#include "internals.h"
const char* CASIO_EXPORT casio_error_strings[128] = {
/* Miscallaneous errors. */
"no error has occured",
"an unknown error has occured",
"a memory allocation has failed",
"this operation is unsupported",
"an argument was invalid",
"no more elements in the iterator",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
/* Stream errors. */
"the stream is invalid/no (more) stream",
"a read operation on the stream has failed",
"a write operation on the stream has failed",
"a seek operation on the stream has failed",
"a timeout has occurred",
"could not get access to the device",
"an end of file event has occured",
"a SCSI operation on the stream has failed",
"a USB operation on the stream has failed",
NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
/* Link errors. */
"the link was uninitialized",
"illegal double shifting",
"irrecoverable link error",
"interrupted by user",
"not in active/passive mode",
"denied overwrite",
"unsupported command",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
/* Filesystem errors. */
"unsupported storage device",
"full memory",
"file not found",
"empty files aren't allowed",
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL,
/* Decoding errors. */
"corrupted or unknown file format",
"invalid checksum",
"was recognized but not one of the allowed file types."
};
/**
* casio_strerror:
* Get the error string.
*
* @arg error the error code.
* @return the error string.
*/
const char* CASIO_EXPORT casio_strerror(int error)
{
return (casio_error_strings[error]);
}

View File

@ -61,14 +61,12 @@ int CASIO_EXPORT casio_make_picture(casio_file_t **h,
* Make an MCS file.
*
* @arg h pointer to the handle to create.
* @arg count the number of slots in the index.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_make_mcs(casio_file_t **h, int count)
int CASIO_EXPORT casio_make_mcs(casio_file_t **h)
{
int err; casio_file_t *handle;
(void)count; /* TODO: use this parameter? */
/* make the handle */
mkhandle();

View File

@ -1,130 +0,0 @@
/* ****************************************************************************
* iter/iter.c -- iterator internals.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../internals.h"
/* Internal structure of an iterator. */
struct casio_iter_s {
int stopped, has_last;
void *last;
void *cookie;
casio_next_t *next;
casio_nextfree_t *nextfree;
casio_end_t *end;
};
/* `default_next()`: default next function. */
CASIO_LOCAL int default_next(void *cookie, void **ptr)
{
(void)cookie;
(void)ptr;
return (casio_error_iter);
}
/* `default_nextfree()`: default nextfree function. */
CASIO_LOCAL void default_nextfree(void *cookie, void *ptr)
{
/* Do not free. */
(void)cookie;
(void)ptr;
}
/* `default_end()`: default iterator end function. */
CASIO_LOCAL void default_end(void *cookie)
{
(void)cookie;
}
/* `casio_iter()`: create an iterator. */
int CASIO_EXPORT casio_iter(casio_iter_t **iterp, void *cookie,
casio_iter_funcs_t const *funcs)
{
casio_iter_t *iter;
/* Allocate the iterator. */
iter = casio_alloc(1, sizeof(*iter));
if (!iter) {
if (funcs->casio_iterfunc_end)
(*funcs->casio_iterfunc_end)(cookie);
return (casio_error_alloc);
}
/* Prepare the iterator. */
iter->stopped = 0;
iter->has_last = 0;
iter->cookie = cookie;
iter->next = funcs->casio_iterfunc_next;
if (!iter->next)
iter->next = &default_next;
iter->nextfree = funcs->casio_iterfunc_nextfree;
if (!iter->nextfree)
iter->nextfree = &default_nextfree;
iter->end = funcs->casio_iterfunc_end;
if (!iter->end)
iter->end = &default_end;
*iterp = iter;
return (0);
}
/* `casio_next()`: get the next element from an iterator. */
int CASIO_EXPORT casio_next(casio_iter_t *iter, void **ptrp)
{
int err;
if (iter->stopped)
return (casio_error_iter);
if (iter->has_last) {
(*iter->nextfree)(iter->cookie, iter->last);
iter->has_last = 0;
}
err = (*iter->next)(iter->cookie, ptrp);
if (err == casio_error_iter) {
iter->stopped = 1;
return (err);
} else if (err)
return (err);
iter->has_last = 1;
iter->last = *ptrp;
return (0);
}
/* `casio_end()`: end and free the iterator. */
void CASIO_EXPORT casio_end(casio_iter_t *iter)
{
if (iter->has_last) {
(*iter->nextfree)(iter->cookie, iter->last);
iter->has_last = 0;
}
(*iter->end)(iter->cookie);
casio_free(iter);
}

View File

@ -1,96 +0,0 @@
/* ****************************************************************************
* iter/super.c -- super-iterator, for super-iterating.
* Copyright (C) 2018 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../internals.h"
typedef struct {
int i, len;
casio_iter_t *its[2];
} supercookie_t;
/* `next_super()`: next element from the super iterator. */
CASIO_LOCAL int next_super(supercookie_t *cookie, void **ptr)
{
int err;
if (cookie->i == cookie->len)
return (casio_error_iter);
while (cookie->i < cookie->len - 1) {
if ((err = casio_next(cookie->its[cookie->i], ptr))
!= casio_error_iter)
return (err);
casio_end(cookie->its[cookie->i++]);
}
if ((err = casio_next(cookie->its[cookie->i], ptr)) != casio_error_iter)
return (err);
casio_end(cookie->its[cookie->i++]);
return (casio_error_iter);
}
/* `end_super()`: end the super-iterator. */
CASIO_LOCAL void end_super(supercookie_t *cookie)
{
int i;
for (i = cookie->i; i < cookie->len; i++)
casio_end(cookie->its[i]);
free(cookie);
}
/* Callbacks. */
CASIO_LOCAL casio_iter_funcs_t const super_funcs = {
(casio_next_t *)next_super,
NULL,
(casio_end_t *)end_super
};
/**
* casio_combine_iterator:
* Make a super iterator.
*
* @arg iterp the super-iterator to create.
* @arg first the first iterator to put into the super-iterator.
* @arg second the second one.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_combine_iterators(casio_iter_t **iterp,
casio_iter_t *first, casio_iter_t *second)
{
supercookie_t *cookie;
if (!(cookie = malloc(sizeof(supercookie_t)))) {
casio_end(first);
casio_end(second);
return (casio_error_alloc);
}
cookie->len = 2;
cookie->i = 0;
cookie->its[0] = first;
cookie->its[1] = second;
return (casio_iter(iterp, cookie, &super_funcs));
}

View File

@ -62,19 +62,4 @@
# define DWRITE(CASIO__OBJECT) \
WRITE(&(CASIO__OBJECT), sizeof(CASIO__OBJECT))
/* ---
* Picture utilities.
* --- */
# define alloc_pixels(W, H) \
casio_alloc(sizeof(casio_pixel_t*) \
* (H) + sizeof(casio_pixel_t) * (W) * (H), 1)
# define prepare_pixels(I, W, H) { \
unsigned int PIXPREP_y; \
casio_pixel_t *PIXPREP_line = (casio_pixel_t*)&(I)[(H)]; \
for (PIXPREP_y = 0; PIXPREP_y < (H); PIXPREP_y++) { \
(I)[PIXPREP_y] = PIXPREP_line; \
PIXPREP_line += (W); \
}}
#endif

View File

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "picture.h"
#include "internals.h"
/* The dual 2-bit format colors. */
@ -51,26 +51,28 @@ CASIO_LOCAL const casio_uint32_t casemul_colors[256] = {
/* other colours are black, i.e. casio_pixel(0, 0, 0) == 0x000000 */
};
/**
* casio_decode_picture:
* Decode a picture.
*
* @arg pixels the pixels to fill.
* @arg format the format to use.
* @arg raw the raw bytes to decode from.
* @arg width the width.
* @arg height the height.
* @return the error code (0 if ok).
*/
/* `casio_decode_picture()`: decode a picture out of a buffer.
* Reads while checking the required size. */
int CASIO_EXPORT casio_decode_picture(casio_pixel_t **pixels,
const void *vraw, casio_pictureformat_t format,
unsigned int width, unsigned int height)
CASIO_EXTERN(int) casio_decode_picture(casio_picture_t **picturep,
unsigned int width, unsigned int height, casio_pictureformat_t format,
tio_stream_t *buffer)
{
const unsigned char *raw = (const void*)vraw;
unsigned char *raw;
const unsigned char *o, *g, *b, *r2; /* pointers on the data */
int msk, bit; size_t off; /* mask and offset */
unsigned int y, x, bx; /* coordinates */
size_t size; int err = casio_ok;
if ((err = casio_get_picture_estimated_size(format, width, height,
&size)))
return (err);
if (!(raw = casio_alloc(size, 1)))
return (casio_error_alloc);
if ((terr = (tio_read(buffer, raw, size)))) {
casio_free(raw);
return (casio_error_read);
}
switch (format) {
case casio_pictureformat_1bit:
@ -260,9 +262,34 @@ int CASIO_EXPORT casio_decode_picture(casio_pixel_t **pixels,
default:
/* unknown format! */
return (casio_error_op);
err = casio_error_op;
}
/* everything went well :) */
return (0);
casio_free(raw);
return (err);
}
/* `casio_decode_picture_buffer()`: decode a picture out of a buffer.
* Reads while checking the required size. */
CASIO_EXTERN(int) casio_decode_picture_buffer(casio_picture_t **picturep,
unsigned int width, unsigned int height, casio_pictureformat_t format,
void const *data, size_t data_size)
{
tio_stream_t *stream;
int err, terr;
if ((terr = tio_open_memory(&stream, data, data_size))) switch (terr) {
case tio_error_alloc:
return (casio_error_alloc);
case tio_error_arg:
return (casio_error_arg);
default:
return (casio_error_unknown);
}
err = casio_decode_picture(picturep, width, height, format, stream);
tio_close(stream);
return (err);
}

View File

@ -18,24 +18,35 @@
* ************************************************************************* */
#include "picture.h"
/**
* casio_encode_picture:
* Encode the picture.
*
* @arg pixels the pixels to encode.
* @arg format the format.
* @arg raw the destination buffer.
* @arg width the picture width.
* @arg height the picture height.
*/
/* `casio_get_picture_encoded_size()`: get the size in bytes of a picture
* encoded in a certain format. */
int CASIO_EXPORT casio_encode_picture(void *vraw,
casio_pixel_t const * const *pixels, casio_pictureformat_t format,
unsigned int width, unsigned int height)
CASIO_EXTERN(int) casio_get_picture_encoded_size(casio_picture_t *picture,
casio_pictureformat_t format, size_t *sizep)
{
if (!sizep)
return (casio_error_arg);
return (casio_get_picture_estimated_size(format, picture->width,
picture->height, sizep));
}
/* `casio_encode_picture()`: encode a picture. */
CASIO_EXTERN(int) casio_encode_picture(casio_picture_t *picture,
casio_pictureformat_t format, void *buf, size_t size)
{
int msk;
unsigned int y, x;
unsigned char *raw = (void*)vraw;
size_t estim;
casio_get_picture_estimated_size(format, picture->width,
picture->height, &estim);
if (size < estim) {
msg((ll_error, "too little space to write"));
return (casio_error_arg);
}
switch (format) {
case casio_pictureformat_1bit:
@ -116,5 +127,5 @@ int CASIO_EXPORT casio_encode_picture(void *vraw,
}
/* everything went well :) */
return (0);
return (casio_ok);
}

View File

@ -16,4 +16,21 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../internals.h"
#ifndef LOCAL_PICTURE_H
# define LOCAL_PICTURE_H 20190523
# include "../internals.h"
struct casio_picture {
unsigned int width, height;
casio_pixel_t **pixels;
};
/* Get the expected size out of a width, a height and a picture format. */
CASIO_EXTERN(int) casio_prepare_picture
OF((casio_picture_t **picturep, unsigned int width, unsigned int height));
CASIO_EXTERN(int) casio_get_picture_estimated_size
OF((casio_pictureformat_t format,
unsigned int width, unsigned int height, size_t *sizep));
#endif /* LOCAL_PICTURE_H */

75
lib/picture/manage.c Normal file
View File

@ -0,0 +1,75 @@
/* ****************************************************************************
* picture/manage.c -- picture management.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "internals.h"
# define alloc_pixels(W, H) \
casio_alloc(sizeof(casio_pixel_t*) \
* (H) + sizeof(casio_pixel_t) * (W) * (H), 1)
# define prepare_pixels(I, W, H) { \
unsigned int PIXPREP_y; \
casio_pixel_t *PIXPREP_line = (casio_pixel_t*)&(I)[(H)]; \
for (PIXPREP_y = 0; PIXPREP_y < (H); PIXPREP_y++) { \
(I)[PIXPREP_y] = PIXPREP_line; \
PIXPREP_line += (W); \
}}
CASIO_EXTERN(int) casio_prepare_picture(casio_picture_t **picturep,
unsigned int width, unsigned int height)
{
casio_pixel_t **pixels;
casio_picture_t *picture;
if (!(pixels = alloc_pixels(width, height)))
return (casio_error_alloc);
if (!(*picturep = (picture = (casio_alloc(1, sizeof(casio_picture_t)))))) {
casio_free(pixels);
return (casio_error_alloc);
}
picture->width = width;
picture->height = height;
picture->pixels = pixels;
prepare_pixels(pixels, width, height)
return (casio_ok);
}
CASIO_EXTERN(void) casio_free_picture(casio_picture_t *picture)
{
if (!picture)
return ;
casio_free(picture->pixels);
casio_free(picture);
}
CASIO_EXTERN(int) casio_get_picture_dimensions(casio_picture_t *picture,
unsigned int *widthp, unsigned int *heightp)
{
*widthp = picture->width;
*heightp = picture->height;
return (casio_ok);
}
CASIO_EXTERN(int) casio_access_pixels(casio_picture_t *picture,
casio_pixel_t ***pixelsp)
{
*pixelsp = picture->pixels;
return (casio_ok);
}

View File

@ -18,49 +18,42 @@
* ************************************************************************* */
#include "picture.h"
/**
* casio_get_picture_size:
* Get a 'raw' picture size.
*
* @arg pixels the picture.
* @arg fmt the picture format.
* @arg width the picture width.
* @arg height the picture height.
* @return the raw size.
*/
/* `casio_get_picture_estimated_size()`: get the estimated size of a picture
* in bytes out of its format and dimensions. */
size_t CASIO_EXPORT casio_get_picture_size(casio_pixel_t **pixels,
casio_pictureformat_t fmt, unsigned int width, unsigned int height)
CASIO_EXTERN(int) casio_get_picture_estimated_size(casio_pictureformat_t fmt,
unsigned int width, unsigned int height, size_t *sizep)
{
(void)pixels;
switch (fmt) {
case casio_pictureformat_1bit: /* FALLTHRU */
case casio_pictureformat_1bit_r: /* FALLTHRU */
case casio_pictureformat_1bit_old:
return (((width / 8) + !!(width % 8)) * height);
*sizep = ((width / 8) + !!(width % 8)) * height;
case casio_pictureformat_1bit_packed: /* FALLTHRU */
case casio_pictureformat_1bit_packed_r:
return ((width * height / 8) + !!(width * height % 8));
*sizep = (width * height / 8) + !!(width * height % 8);
case casio_pictureformat_2bit_dual:
return (((width / 8) + !!(width % 8)) * height * 2);
*sizep = ((width / 8) + !!(width % 8)) * height * 2;
case casio_pictureformat_4bit: /* FALLTHRU */
case casio_pictureformat_4bit_code:
return (width * height / 2);
*sizep = width * height / 2;
case casio_pictureformat_4bit_color: /* FALLTHRU */
case casio_pictureformat_4bit_mono:
return (((width / 8) + !!(width % 8)) * height * 4);
*sizep = ((width / 8) + !!(width % 8)) * height * 4;
case casio_pictureformat_casemul:
return (width * height);
*sizep = width * height;
case casio_pictureformat_16bit:
return (width * height * 2);
*sizep = width * height * 2;
default:
return (casio_error_op);
}
return (0);
return (casio_ok);
}

View File

@ -16,7 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "builtin.h"
#include "stream.h"
/* ---
* Cookie structure.

View File

@ -16,34 +16,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../stream.h"
#if !defined(LIBCASIO_DISABLED_LIBUSB)
# define OUF &casio_open_libusb_usb
#elif !defined(LIBCASIO_DISABLED_WINDOWS)
# define OUF &casio_open_windows_usb
#else
# define OUF NULL
#endif
CASIO_LOCAL casio_open_native_usb_stream_t *open_native_usb_stream_func = OUF;
/**
* casio_set_open_native_usb_stream_func:
* Set the USB streams opener.
*
* NULL rests the function to its default.
*
* @arg function the function pointer to set.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_set_open_native_usb_stream_func(
casio_open_native_usb_stream_t *func)
{
open_native_usb_stream_func = func ? func : OUF;
return (0);
}
#include "stream.h"
/**
* casio_open_native_usb_stream:

View File

@ -19,4 +19,47 @@
* ************************************************************************* */
#include "stream.h"
/* TODO */
TIO_HOOK(void) serial_usb_close(void *cookie)
{
/* Nothing. */
}
TIO_HOOK(int) serial_usb_read(void *cookie, unsigned char *buffer, size_t size)
{
/* Nothing. */
}
TIO_HOOK(int) serial_usb_write(void *cookie,
unsigned char const *buffer, size_t size)
{
/* Nothing. */
}
CASIO_LOCAL tio_functions_t const serial_usb_funcs = {
(tio_close_t *)&serial_usb_close,
(tio_read_t *)&serial_usb_read,
(tio_write_t *)&serial_usb_write,
NULL
};
int CASIO_EXPORT casio_open_serial_usb_stream(tio_stream_t **streamp,
tio_stream_t *original)
{
int terr;
if (tio_get_type(original) != TIO_TYPE_USB) {
msg((ll_error, "original stream wasn't a usb stream"));
return (casio_error_arg);
}
terr = tio_open(streamp, original, NULL,
TIO_OPENFLAG_READ | TIO_OPENFLAG_WRITE, &serial_usb_funcs, 0);
if (terr) {
msg((ll_error, "tio_open failed with error %s: %s",
tio_error_name(terr), tio_error_desc(terr)));
return (casio_error_unknown);
}
return (0);
}

View File

@ -1,80 +0,0 @@
/* ****************************************************************************
* utils/mutex.c -- mutex internals.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../internals.h"
/**
* casio_init_lock:
* Initialize a mutex.
*
* @arg mutex the mutex to initialize.
*/
void CASIO_EXPORT casio_init_lock(casio_mutex_t *mutex)
{
*mutex = 0;
}
/**
* casio_lock:
* Lock a mutex.
*
* @arg mutex the mutex to lock.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_lock(casio_mutex_t *mutex)
{
int err;
if (!*mutex) goto unlocked;
if ((err = casio_sleep(0))) return (err);
while (*(volatile casio_mutex_t*)mutex)
casio_sleep(5);
unlocked:
*mutex = 1;
return (0);
}
/**
* casio_trylock:
* Try to lock a mutex.
*
* @arg mutex the mutex to lock.
* @return the error code (0 if ok).
*/
int CASIO_EXPORT casio_trylock(casio_mutex_t *mutex)
{
if (*mutex) return (casio_error_lock);
*mutex = 1;
return (0);
}
/**
* casio_unlock_mutex:
* Unlock a mutex.
*
* @arg mutex the mutex to unlock.
*/
void CASIO_EXPORT casio_unlock(casio_mutex_t *mutex)
{
*mutex = 0;
}

View File

@ -1,89 +0,0 @@
/* ****************************************************************************
* utils/sleep.c -- Sleep in a cross-platform way.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../internals.h"
/* ---
* Microsoft Windows environment.
* --- */
#if defined(__WINDOWS__)
# define default_callback &casio_winsleep
# include <windows.h>
CASIO_LOCAL void casio_winsleep(unsigned long ms)
{
Sleep(ms);
}
/* ---
* UNIX-like environments.
* --- */
#elif defined(__unix__) || defined(__unix)
# define default_callback &casio_unixsleep
# include <unistd.h>
# include <time.h>
CASIO_LOCAL void casio_unixsleep(unsigned long ms)
{
struct timespec requested_timestamp;
requested_timestamp.tv_sec = ms / 1000;
requested_timestamp.tv_nsec = (ms % 1000) * 1000000;
nanosleep(&requested_timestamp, NULL);
}
/* ---
* Default and main function.
* --- */
#else
# define default_callback NULL
#endif
CASIO_LOCAL casio_sleep_t *casio_sleep_callback = default_callback;
/**
* casio_set_sleep_func:
* Set the sleep function.
*
* @arg func the function to set.
*/
void CASIO_EXPORT casio_set_sleep_func(casio_sleep_t *func)
{
casio_sleep_callback = func;
}
/**
* casio_sleep:
* Sleep.
*
* @arg ms the milliseconds.
*/
int CASIO_EXPORT casio_sleep(unsigned long ms)
{
if (!casio_sleep_callback)
return (casio_error_op);
if (!ms) return (0);
(*casio_sleep_callback)(ms);
return (0);
}

View File

@ -1,115 +0,0 @@
/* ****************************************************************************
* utils/timer.c -- timer internals.
* Copyright (C) 2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libcasio.
* libcasio 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.
*
* libcasio 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 libcasio; if not, see <http://www.gnu.org/licenses/>.
* ************************************************************************* */
#include "../internals.h"
/* ---
* Default functions for UNIX.
* --- */
#if _POSIX_C_SOURCE >= 199309L
# include <time.h>
struct casio_timer_s {
clockid_t clk_id;
struct timespec initial;
};
CASIO_LOCAL int default_get_timer(casio_timer_t **timerp)
{
casio_timer_t *timer;
if (!(timer = casio_alloc(sizeof(*timer), 1)))
return (casio_error_alloc);
#ifdef __linux__
timer->clk_id = CLOCK_MONOTONIC_COARSE;
#else
timer->clk_id = CLOCK_MONOTONIC;
#endif
if (clock_gettime(timer->clk_id, &timer->initial) < 0) {
casio_free(timer);
return (casio_error_unknown);
}
*timerp = timer;
return (0);
}
CASIO_LOCAL void default_free_timer(casio_timer_t *timer)
{
casio_free(timer);
}
CASIO_LOCAL int default_get_spent_time(casio_timer_t *timer,
unsigned long *spent)
{
struct timespec ts;
if (clock_gettime(timer->clk_id, &ts) < 0)
return (casio_error_unknown);
*spent = (ts.tv_sec - timer->initial.tv_sec) * 1000
+ (ts.tv_nsec - timer->initial.tv_nsec) / 1000000;
return (0);
}
#else
# define NO_DEFAULTS 1
#endif
/* ---
* Public API functions.
* --- */
#if NO_DEFAULTS
CASIO_LOCAL casio_get_timer_t *gettimer = NULL;
CASIO_LOCAL casio_get_spent_time_t *getspenttime = NULL;
#else
CASIO_LOCAL casio_get_timer_t *gettimer = &default_get_timer;
CASIO_LOCAL casio_get_spent_time_t *getspenttime = &default_get_spent_time;
#endif
#if NO_DEFAULTS || NO_TIMERFREE
CASIO_LOCAL casio_free_timer_t *freetimer = NULL;
#else
CASIO_LOCAL casio_free_timer_t *freetimer = &default_free_timer;
#endif
int CASIO_EXPORT casio_get_timer(casio_timer_t **timerp)
{
if (!gettimer)
return (casio_error_op);
return ((*gettimer)(timerp));
}
void CASIO_EXPORT casio_free_timer(casio_timer_t *timer)
{
if (!freetimer)
return ;
(*freetimer)(timer);
}
int CASIO_EXPORT casio_get_spent_time(casio_timer_t *timer,
unsigned long *spent)
{
if (!getspenttime)
return (casio_error_op);
return ((*getspenttime)(timer, spent));
}