OSDN Git Service

最初のコミット
authorsfpgmr <sfpgmr@dummy.com>
Fri, 22 Mar 2013 12:46:39 +0000 (21:46 +0900)
committersfpgmr <sfpgmr@dummy.com>
Fri, 22 Mar 2013 12:46:39 +0000 (21:46 +0900)
133 files changed:
.gitignore [new file with mode: 0644]
ABOUT-NLS [new file with mode: 0644]
AUTHORS [new file with mode: 0644]
ChangeLog [new file with mode: 0644]
ChangeLog.WIN32 [new file with mode: 0644]
INSTALL [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
README-WIN32.txt [new file with mode: 0644]
README.jp [new file with mode: 0644]
ReadMe.txt [new file with mode: 0644]
SF.props [new file with mode: 0644]
STed2.aps [new file with mode: 0644]
STed2.cpp [new file with mode: 0644]
STed2.h [new file with mode: 0644]
STed2.ico [new file with mode: 0644]
STed2.rc [new file with mode: 0644]
STed2.vcxproj [new file with mode: 0644]
STedX.sln [new file with mode: 0644]
acconfig.h [new file with mode: 0644]
acinclude.m4 [new file with mode: 0644]
assign.cpp [new file with mode: 0644]
basic.cpp [new file with mode: 0644]
cm6con.cpp [new file with mode: 0644]
config.h [new file with mode: 0644]
config.h.in [new file with mode: 0644]
configure.in [new file with mode: 0644]
curses.cpp [new file with mode: 0644]
defload.cpp [new file with mode: 0644]
defload2.cpp [new file with mode: 0644]
disp.cpp [new file with mode: 0644]
dlg_mididevice.cpp [new file with mode: 0644]
dos.cpp [new file with mode: 0644]
doslib.h [new file with mode: 0644]
edit.cpp [new file with mode: 0644]
edits.cpp [new file with mode: 0644]
exception.cpp [new file with mode: 0644]
exception.h [new file with mode: 0644]
exclu.cpp [new file with mode: 0644]
file.cpp [new file with mode: 0644]
getopt.cpp [new file with mode: 0644]
getopt_long.cpp [new file with mode: 0644]
gettext_wrapper.h [new file with mode: 0644]
graph.cpp [new file with mode: 0644]
graph.h [new file with mode: 0644]
graphic.cpp [new file with mode: 0644]
hprint.cpp [new file with mode: 0644]
iocs.cpp [new file with mode: 0644]
iocs_console.cpp [new file with mode: 0644]
iocs_graph.cpp [new file with mode: 0644]
iocs_key.cpp [new file with mode: 0644]
iocs_mouse.cpp [new file with mode: 0644]
iocs_tgraph.cpp [new file with mode: 0644]
iocslib.h [new file with mode: 0644]
itor.cpp [new file with mode: 0644]
key_sub.cpp [new file with mode: 0644]
machin.h [new file with mode: 0644]
mcpy.cpp [new file with mode: 0644]
midi_in.cpp [new file with mode: 0644]
midi_in.h [new file with mode: 0644]
mididev.cpp [new file with mode: 0644]
mididev.h [new file with mode: 0644]
mkeyb.cpp [new file with mode: 0644]
netbsdgetopt.h [new file with mode: 0644]
nkflib.cpp [new file with mode: 0644]
nkflib.h [new file with mode: 0644]
ongraph.cpp [new file with mode: 0644]
rcdcheck.cpp [new file with mode: 0644]
rcddef.h [new file with mode: 0644]
rcp.h [new file with mode: 0644]
rcp_functions.cpp [new file with mode: 0644]
rcp_functions.h [new file with mode: 0644]
rcpconv.cpp [new file with mode: 0644]
rcpconv.h [new file with mode: 0644]
rcpconv_main.cpp [new file with mode: 0644]
rcpdef.h [new file with mode: 0644]
rcpfile.cpp [new file with mode: 0644]
rcpfile.h [new file with mode: 0644]
rcpplay.cpp [new file with mode: 0644]
rcpstruct.h [new file with mode: 0644]
rcptomid.cpp [new file with mode: 0644]
record.cpp [new file with mode: 0644]
redit.cpp [new file with mode: 0644]
resource.h [new file with mode: 0644]
scdsp.cpp [new file with mode: 0644]
score.cpp [new file with mode: 0644]
select.cpp [new file with mode: 0644]
sf_com.cpp [new file with mode: 0644]
sf_com.h [new file with mode: 0644]
sf_memory.h [new file with mode: 0644]
sf_windows.cpp [new file with mode: 0644]
sf_windows.h [new file with mode: 0644]
singleton.h [new file with mode: 0644]
small.ico [new file with mode: 0644]
smf.cpp [new file with mode: 0644]
smf.h [new file with mode: 0644]
smffile.cpp [new file with mode: 0644]
smfplay.cpp [new file with mode: 0644]
smfplay.h [new file with mode: 0644]
smfplay_main.cpp [new file with mode: 0644]
snprintf.cpp [new file with mode: 0644]
snprintf.h [new file with mode: 0644]
stdafx.cpp [new file with mode: 0644]
stdafx.h [new file with mode: 0644]
sted.cpp [new file with mode: 0644]
sted.h [new file with mode: 0644]
sted2header.h [new file with mode: 0644]
sted3.h [new file with mode: 0644]
sted_c.h [new file with mode: 0644]
sted_dialogs.h [new file with mode: 0644]
sted_screen.cpp [new file with mode: 0644]
sted_screen.h [new file with mode: 0644]
sted_screen_win32.h [new file with mode: 0644]
sted_vals.cpp [new file with mode: 0644]
sted_win32.h [new file with mode: 0644]
track.cpp [new file with mode: 0644]
trkset.cpp [new file with mode: 0644]
version.h [new file with mode: 0644]
version.h.in [new file with mode: 0644]
visual.cpp [new file with mode: 0644]
win32_color.cpp [new file with mode: 0644]
win32_file.cpp [new file with mode: 0644]
win32_graphics.cpp [new file with mode: 0644]
win32_key.cpp [new file with mode: 0644]
win32_midi.cpp [new file with mode: 0644]
win32_misc.cpp [new file with mode: 0644]
win32_pointer.cpp [new file with mode: 0644]
win32_text.cpp [new file with mode: 0644]
win32_win.cpp [new file with mode: 0644]
x68defines.h [new file with mode: 0644]
x68funcs.cpp [new file with mode: 0644]
x68funcs.h [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..74b789a
--- /dev/null
@@ -0,0 +1,15 @@
+_UpgradeReport_Files/
+*.vcxproj.*
+*.old
+*.xml
+*.sdf
+*.suo
+*.dsp
+*.dsw
+*.vcproj
+unix/
+Debug/
+Release/
+ipch/
+sidplay2/
+backup/
\ No newline at end of file
diff --git a/ABOUT-NLS b/ABOUT-NLS
new file mode 100644 (file)
index 0000000..28d38c7
--- /dev/null
+++ b/ABOUT-NLS
@@ -0,0 +1,226 @@
+Notes on the Free Translation Project
+*************************************
+
+   Free software is going international!  The Free Translation Project
+is a way to get maintainers of free software, translators, and users all
+together, so that will gradually become able to speak many languages.
+A few packages already provide translations for their messages.
+
+   If you found this `ABOUT-NLS' file inside a distribution, you may
+assume that the distributed package does use GNU `gettext' internally,
+itself available at your nearest GNU archive site.  But you do *not*
+need to install GNU `gettext' prior to configuring, installing or using
+this package with messages translated.
+
+   Installers will find here some useful hints.  These notes also
+explain how users should proceed for getting the programs to use the
+available translations.  They tell how people wanting to contribute and
+work at translations should contact the appropriate team.
+
+   When reporting bugs in the `intl/' directory or bugs which may be
+related to internationalization, you should tell about the version of
+`gettext' which is used.  The information can be found in the
+`intl/VERSION' file, in internationalized packages.
+
+One advise in advance
+=====================
+
+   If you want to exploit the full power of internationalization, you
+should configure it using
+
+     ./configure --with-included-gettext
+
+to force usage of internationalizing routines provided within this
+package, despite the existence of internationalizing capabilities in the
+operating system where this package is being installed.  So far, only
+the `gettext' implementation in the GNU C library version 2 provides as
+many features (such as locale alias or message inheritance) as the
+implementation here.  It is also not possible to offer this additional
+functionality on top of a `catgets' implementation.  Future versions of
+GNU `gettext' will very likely convey even more functionality.  So it
+might be a good idea to change to GNU `gettext' as soon as possible.
+
+   So you need not provide this option if you are using GNU libc 2 or
+you have installed a recent copy of the GNU gettext package with the
+included `libintl'.
+
+INSTALL Matters
+===============
+
+   Some packages are "localizable" when properly installed; the
+programs they contain can be made to speak your own native language.
+Most such packages use GNU `gettext'.  Other packages have their own
+ways to internationalization, predating GNU `gettext'.
+
+   By default, this package will be installed to allow translation of
+messages.  It will automatically detect whether the system provides
+usable `catgets' (if using this is selected by the installer) or
+`gettext' functions.  If neither is available, the GNU `gettext' own
+library will be used.  This library is wholly contained within this
+package, usually in the `intl/' subdirectory, so prior installation of
+the GNU `gettext' package is *not* required.  Installers may use
+special options at configuration time for changing the default
+behaviour.  The commands:
+
+     ./configure --with-included-gettext
+     ./configure --with-catgets
+     ./configure --disable-nls
+
+will respectively bypass any pre-existing `catgets' or `gettext' to use
+the internationalizing routines provided within this package, enable
+the use of the `catgets' functions (if found on the locale system), or
+else, *totally* disable translation of messages.
+
+   When you already have GNU `gettext' installed on your system and run
+configure without an option for your new package, `configure' will
+probably detect the previously built and installed `libintl.a' file and
+will decide to use this.  This might be not what is desirable.  You
+should use the more recent version of the GNU `gettext' library.  I.e.
+if the file `intl/VERSION' shows that the library which comes with this
+package is more recent, you should use
+
+     ./configure --with-included-gettext
+
+to prevent auto-detection.
+
+   By default the configuration process will not test for the `catgets'
+function and therefore they will not be used.  The reasons are already
+given above: the emulation on top of `catgets' cannot provide all the
+extensions provided by the GNU `gettext' library.  If you nevertheless
+want to use the `catgets' functions use
+
+     ./configure --with-catgets
+
+to enable the test for `catgets' (this causes no harm if `catgets' is
+not available on your system).  If you really select this option we
+would like to hear about the reasons because we cannot think of any
+good one ourself.
+
+   Internationalized packages have usually many `po/LL.po' files, where
+LL gives an ISO 639 two-letter code identifying the language.  Unless
+translations have been forbidden at `configure' time by using the
+`--disable-nls' switch, all available translations are installed
+together with the package.  However, the environment variable `LINGUAS'
+may be set, prior to configuration, to limit the installed set.
+`LINGUAS' should then contain a space separated list of two-letter
+codes, stating which languages are allowed.
+
+Using This Package
+==================
+
+   As a user, if your language has been installed for this package, you
+only have to set the `LANG' environment variable to the appropriate
+ISO 639 `LL' two-letter code prior to using the programs in the
+package.  For example, let's suppose that you speak German.  At the
+shell prompt, merely execute `setenv LANG de' (in `csh'),
+`export LANG; LANG=de' (in `sh') or `export LANG=de' (in `bash').  This
+can be done from your `.login' or `.profile' file, once and for all.
+
+   An operating system might already offer message localization for
+many of its programs, while other programs have been installed locally
+with the full capabilities of GNU `gettext'.  Just using `gettext'
+extended syntax for `LANG' would break proper localization of already
+available operating system programs.  In this case, users should set
+both `LANGUAGE' and `LANG' variables in their environment, as programs
+using GNU `gettext' give preference to `LANGUAGE'.  For example, some
+Swedish users would rather read translations in German than English for
+when Swedish is not available.  This is easily accomplished by setting
+`LANGUAGE' to `sv:de' while leaving `LANG' to `sv'.
+
+Translating Teams
+=================
+
+   For the Free Translation Project to be a success, we need interested
+people who like their own language and write it well, and who are also
+able to synergize with other translators speaking the same language.
+Each translation team has its own mailing list, courtesy of Linux
+International.  You may reach your translation team at the address
+`LL@li.org', replacing LL by the two-letter ISO 639 code for your
+language.  Language codes are *not* the same as the country codes given
+in ISO 3166.  The following translation teams exist, as of December
+1997:
+
+     Chinese `zh', Czech `cs', Danish `da', Dutch `nl', English `en',
+     Esperanto `eo', Finnish `fi', French `fr', German `de', Hungarian
+     `hu', Irish `ga', Italian `it', Indonesian `id', Japanese `ja',
+     Korean `ko', Latin `la', Norwegian `no', Persian `fa', Polish
+     `pl', Portuguese `pt', Russian `ru', Slovenian `sl', Spanish `es',
+     Swedish `sv', and Turkish `tr'.
+
+For example, you may reach the Chinese translation team by writing to
+`zh@li.org'.
+
+   If you'd like to volunteer to *work* at translating messages, you
+should become a member of the translating team for your own language.
+The subscribing address is *not* the same as the list itself, it has
+`-request' appended.  For example, speakers of Swedish can send a
+message to `sv-request@li.org', having this message body:
+
+     subscribe
+
+   Keep in mind that team members are expected to participate
+*actively* in translations, or at solving translational difficulties,
+rather than merely lurking around.  If your team does not exist yet and
+you want to start one, or if you are unsure about what to do or how to
+get started, please write to `translation@iro.umontreal.ca' to reach the
+coordinator for all translator teams.
+
+   The English team is special.  It works at improving and uniformizing
+the terminology in use.  Proven linguistic skill are praised more than
+programming skill, here.
+
+Available Packages
+==================
+
+   Languages are not equally supported in all packages.  The following
+matrix shows the current state of internationalization, as of December
+1997.  The matrix shows, in regard of each package, for which languages
+PO files have been submitted to translation coordination.
+
+     Ready PO files    cs da de en es fi fr it ja ko nl no pl pt ru sl sv
+                     .----------------------------------------------------.
+     bash            |       []          []          []                   |  3
+     bison           |       []          []          []                   |  3
+     clisp           |       [] [] []    []                               |  4
+     cpio            |       []    []    []       [] []    []             |  6
+     diffutils       |       []    []    []                []          [] |  5
+     enscript        |       []    [] [] []          []             []    |  6
+     fileutils       | []    []    []    []       [] []    [] []    [] [] | 10
+     findutils       |       []    []    [] []    [] []    []    []    [] |  9
+     flex            |             []    []       []                   [] |  4
+     gcal            |       []          []          []    []          [] |  5
+     gettext         |    [] []    []    []       [] [] [] [] []    [] [] | 12
+     grep            |       []    []    []       [] [] [] []    [] [] [] | 10
+     hello           |    [] []    []    []       [] [] [] [] []    [] [] | 11
+     id-utils        |       []          []                []             |  3
+     indent          |    [] []                   []       []    []       |  5
+     libc            |       []    []    []       [] []    []          [] |  7
+     m4              |       []          []    []    []          []    [] |  6
+     make            |       []    []    []       [] []    []             |  6
+     music           |                   []                []             |  2
+     ptx             |       []    []    []          [] [] [] []       [] |  8
+     recode          |    [] []    []    []          []    [] []    [] [] |  9
+     sh-utils        |       []    []    []          [] [] [] []       [] |  8
+     sharutils       | []    []    []    []          []                [] |  6
+     tar             | []    []          [] []    [] [] [] [] []    [] [] | 11
+     texinfo         | []    []          []                               |  3
+     textutils       | []    []    []    []       [] [] [] []          [] |  9
+     wdiff           | []    []    []    []          [] [] []          [] |  8
+                     `----------------------------------------------------'
+       17 languages    cs da de en es fi fr it ja ko nl no pl pt ru sl sv
+       27 packages      6  4 25  1 18  1 26  2  1 12 20  9 19  7  4  7 17  179
+
+   Some counters in the preceding matrix are higher than the number of
+visible blocks let us expect.  This is because a few extra PO files are
+used for implementing regional variants of languages, or language
+dialects.
+
+   For a PO file in the matrix above to be effective, the package to
+which it applies should also have been internationalized and
+distributed as such by its maintainer.  There might be an observable
+lag between the mere existence a PO file and its wide availability in a
+distribution.
+
+   If December 1997 seems to be old, you may fetch a more recent copy
+of this `ABOUT-NLS' file on most GNU archive sites.
+
diff --git a/AUTHORS b/AUTHORS
new file mode 100644 (file)
index 0000000..597b24a
--- /dev/null
+++ b/AUTHORS
@@ -0,0 +1,6 @@
+STed2 is originally developed by Takayuki Toda (Since 1991 to 1997).
+
+UNIX & X translation is maintainanced by Daisuke Nagano (Since 1998).
+
+And many other people have suggested and helped.
+
diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..051506e
--- /dev/null
+++ b/ChangeLog
@@ -0,0 +1,10 @@
+2001-05-06  Daisuke Nagano  <breeze.nagano@nifty.ne.jp>
+
+       * sted2/sted3.h: Created. All definitions, parameters and 
+       entries for new codes must be described in this file.
+
+       * sted2/file.c: Add codes for supporting port changes.
+
+       * sted2/key_sub.c (strch, chstr): If sted3 mode is enabled,
+       change the way to treat parameters to fit the mode.
+
diff --git a/ChangeLog.WIN32 b/ChangeLog.WIN32
new file mode 100644 (file)
index 0000000..bfe275b
--- /dev/null
@@ -0,0 +1,5 @@
+2002-10-19  Daisuke Nagano  <breeze.nagano@nifty.ne.jp>
+       * added MIDI player function (with 'sayleen')
+
+2002-10-17  Daisuke Nagano  <breeze.nagano@nifty.ne.jp>
+       * first release for WIN32
diff --git a/INSTALL b/INSTALL
new file mode 100644 (file)
index 0000000..50dbe43
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,183 @@
+Basic Installation
+==================
+
+   These are generic installation instructions.
+
+   The `configure' shell script attempts to guess correct values for
+various system-dependent variables used during compilation.  It uses
+those values to create a `Makefile' in each directory of the package.
+It may also create one or more `.h' files containing system-dependent
+definitions.  Finally, it creates a shell script `config.status' that
+you can run in the future to recreate the current configuration, a file
+`config.cache' that saves the results of its tests to speed up
+reconfiguring, and a file `config.log' containing compiler output
+(useful mainly for debugging `configure').
+
+   If you need to do unusual things to compile the package, please try
+to figure out how `configure' could check whether to do them, and mail
+diffs or instructions to the address given in the `README' so they can
+be considered for the next release.  If at some point `config.cache'
+contains results you don't want to keep, you may remove or edit it.
+
+   The file `configure.in' is used to create `configure' by a program
+called `autoconf'.  You only need `configure.in' if you want to change
+it or regenerate `configure' using a newer version of `autoconf'.
+
+The simplest way to compile this package is:
+
+  1. `cd' to the directory containing the package's source code and type
+     `./configure' to configure the package for your system.  If you're
+     using `csh' on an old version of System V, you might need to type
+     `sh ./configure' instead to prevent `csh' from trying to execute
+     `configure' itself.
+
+     Running `configure' takes awhile.  While running, it prints some
+     messages telling which features it is checking for.
+
+  2. Type `make' to compile the package.
+
+  3. Optionally, type `make check' to run any self-tests that come with
+     the package.
+
+  4. Type `make install' to install the programs and any data files and
+     documentation.
+
+  5. You can remove the program binaries and object files from the
+     source code directory by typing `make clean'.  To also remove the
+     files that `configure' created (so you can compile the package for
+     a different kind of computer), type `make distclean'.  There is
+     also a `make maintainer-clean' target, but that is intended mainly
+     for the package's developers.  If you use it, you may have to get
+     all sorts of other programs in order to regenerate files that came
+     with the distribution.
+
+Compilers and Options
+=====================
+
+   Some systems require unusual options for compilation or linking that
+the `configure' script does not know about.  You can give `configure'
+initial values for variables by setting them in the environment.  Using
+a Bourne-compatible shell, you can do that on the command line like
+this:
+     CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+
+Or on systems that have the `env' program, you can do it like this:
+     env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+
+Compiling For Multiple Architectures
+====================================
+
+   You can compile the package for more than one kind of computer at the
+same time, by placing the object files for each architecture in their
+own directory.  To do this, you must use a version of `make' that
+supports the `VPATH' variable, such as GNU `make'.  `cd' to the
+directory where you want the object files and executables to go and run
+the `configure' script.  `configure' automatically checks for the
+source code in the directory that `configure' is in and in `..'.
+
+   If you have to use a `make' that does not supports the `VPATH'
+variable, you have to compile the package for one architecture at a time
+in the source code directory.  After you have installed the package for
+one architecture, use `make distclean' before reconfiguring for another
+architecture.
+
+Installation Names
+==================
+
+   By default, `make install' will install the package's files in
+`/usr/local/bin', `/usr/local/man', etc.  You can specify an
+installation prefix other than `/usr/local' by giving `configure' the
+option `--prefix=PATH'.
+
+   You can specify separate installation prefixes for
+architecture-specific files and architecture-independent files.  If you
+give `configure' the option `--exec-prefix=PATH', the package will use
+PATH as the prefix for installing programs and libraries.
+Documentation and other data files will still use the regular prefix.
+
+   In addition, if you use an unusual directory layout you can give
+options like `--bindir=PATH' to specify different values for particular
+kinds of files.  Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
+
+   If the package supports it, you can cause programs to be installed
+with an extra prefix or suffix on their names by giving `configure' the
+option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'.
+
+Optional Features
+=================
+
+   Some packages pay attention to `--enable-FEATURE' options to
+`configure', where FEATURE indicates an optional part of the package.
+They may also pay attention to `--with-PACKAGE' options, where PACKAGE
+is something like `gnu-as' or `x' (for the X Window System).  The
+`README' should mention any `--enable-' and `--with-' options that the
+package recognizes.
+
+   For packages that use the X Window System, `configure' can usually
+find the X include and library files automatically, but if it doesn't,
+you can use the `configure' options `--x-includes=DIR' and
+`--x-libraries=DIR' to specify their locations.
+
+Specifying the System Type
+==========================
+
+   There may be some features `configure' can not figure out
+automatically, but needs to determine by the type of host the package
+will run on.  Usually `configure' can figure that out, but if it prints
+a message saying it can not guess the host type, give it the
+`--host=TYPE' option.  TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name with three fields:
+     CPU-COMPANY-SYSTEM
+
+See the file `config.sub' for the possible values of each field.  If
+`config.sub' isn't included in this package, then this package doesn't
+need to know the host type.
+
+   If you are building compiler tools for cross-compiling, you can also
+use the `--target=TYPE' option to select the type of system they will
+produce code for and the `--build=TYPE' option to select the type of
+system on which you are compiling the package.
+
+Sharing Defaults
+================
+
+   If you want to set default values for `configure' scripts to share,
+you can create a site shell script called `config.site' that gives
+default values for variables like `CC', `cache_file', and `prefix'.
+`configure' looks for `PREFIX/share/config.site' if it exists, then
+`PREFIX/etc/config.site' if it exists.  Or, you can set the
+`CONFIG_SITE' environment variable to the location of the site script.
+A warning: not all `configure' scripts look for a site script.
+
+Operation Controls
+==================
+
+   `configure' recognizes the following options to control how it
+operates.
+
+`--cache-file=FILE'
+     Use and save the results of the tests in FILE instead of
+     `./config.cache'.  Set FILE to `/dev/null' to disable caching, for
+     debugging `configure'.
+
+`--help'
+     Print a summary of the options to `configure', and exit.
+
+`--quiet'
+`--silent'
+`-q'
+     Do not print messages saying which checks are being made.  To
+     suppress all normal output, redirect it to `/dev/null' (any error
+     messages will still be shown).
+
+`--srcdir=DIR'
+     Look for the package's source code in directory DIR.  Usually
+     `configure' can determine that directory automatically.
+
+`--version'
+     Print the version of Autoconf used to generate the `configure'
+     script, and exit.
+
+`configure' also accepts some other, not widely useful, options.
+
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..615105e
--- /dev/null
@@ -0,0 +1,17 @@
+## Process this file with automake to produce Makefile.in
+
+SUBDIRS = intl sted2 po etc doc contrib
+
+EXTRA_DIST = README.jp ChangeLog.old \
+       intl/libgettext.h \
+       intl/po2tbl.sed.in
+
+YYMMDD=`date +%Y%m%d`
+
+.PHONY: .version
+
+.version:
+       -rm $(srcdir)/sted2/version.h
+       echo "#define VERSION_ID        \"$(YYMMDD)\"" > $(srcdir)/sted2/version.h
+       autoconf
+
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..21994a1
--- /dev/null
+++ b/README
@@ -0,0 +1,94 @@
+STed2 for UNIX
+==============
+
+ The "STed2" is the high-performance Music Composer System. It had been
+working on X680x0 old Japanese personal workstation. STed2 means
+perhaps "STep EDitor".  The STed2 has originally been developed by
+Mr. Takayuki "TURBO" Toda.
+
+
+   Mr. Takayuki Toda has dead on Dec. 4. 1997. I express my regret
+                       over the his death.
+                      May he rest in peace.
+
+ Through many volunteer's good office the source code of the STed2 has
+been opened. Since I am an user of original STed2 (working on X680x0)
+and regret that development is discontinued forever, I decide to port
+the STed2 to UNIX & X environment.
+
+
+USAGE
+=====
+
+ To start STed2, install 'sted2', 'sted2.cnf', 'sted2.fon' in the same
+path (or 'DEFAULT_PATH' in Makefile) and type:
+
+ % sted2
+
+If environment variable 'DISPLAY' is set, X version of STed2 will
+raise, or ncurses version will came up. It is same as emacs.
+
+
+CONFIGURATION
+=============
+
+ 'sted2.cnf' is runtime configuration file. It contains many
+configuration features but it all commented by Japanese :-<
+ To use STed2 anyway, configure the following features:
+
+ #PLAYER= flag, (path of external RCP/SMF player)
+
+  External MIDI player. If the player can handle only SMF, set the
+bit-0 of flag 0.
+
+ #MIDI_PORT= (path of device name of MIDI-IN)
+
+  MIDI-IN device name. If you want to use MIDI-IN as input method of
+STed2, specify the path of device name.
+  Although Serial ports (/dev/ttyS0 or else) can also be specified,
+STed2 never sets the configuration of serial ports (speed , flow, etc). 
+So you should set it manually before start STed2.
+
+ #KEY_??  = (key name)
+
+  In X version, the keyboard arrange can configurable. The
+configurable keys are following:
+
+  #KEY_XF1 - #KEY_XF5
+  #KEY_KANA, #KEY_KIGO, #KEY_TOROKU
+  #KEY_INS, #KEY_DEL, #KEY_HOME, #KEY_UNDO, #KEY_RUP, #KEY_RDOWN
+  #KEY_OPT1, KEY_OPT2
+
+  All names are introduced from original X68k version.
+  (key name) is the KeySym strings.
+
+
+DISCLILMER
+==========
+
+This software is provided as-is.  The author can not be held liable
+for any damage that might arise from the use of this software.  Use it
+at your own risk.
+
+This distribution cannot be GPL2ed. Because the original author has
+been died and any permission of changing the distribution policy will
+not be given.
+
+
+AVAILABILITY
+============
+
+ The latest version of STed2 for X will be available at:
+
+   http://member.nifty.ne.jp/Breeze/linux/STed/index.html
+
+
+AUTHORS
+=======
+
+ Original "STed2 for X680x0" author:
+  TURBO (Takayuki Toda)
+
+ Porting to X:
+  Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+   http://member.nifty.ne.jp/Breeze/index.html
diff --git a/README-WIN32.txt b/README-WIN32.txt
new file mode 100644 (file)
index 0000000..4aa2891
--- /dev/null
@@ -0,0 +1,157 @@
+STed2 for Windows\r
+=================\r
+\r
+Note:\r
+=====\r
+"STed2 for Windows" is only available in Japanese environment.\r
+No support for other language (documentations, manuals, Q&A, etc)\r
+won't be supplied from us.\r
+Ofcource, you can write those documents for your environment\r
+by yourself.\r
+\r
+\r
+About STed2 for Windows:\r
+========================\r
+\r
+STed2 (TURBO. \8e\81\8dì) \82ð Windows \8aÂ\8b«\82Å\93®\82­\82æ\82¤\82É\82µ\82½\82à\82Ì\82Å\82·\81B\r
+STed2 \82Ì\89½\82½\82é\82©\82É\82Â\82¢\82Ä\82Í\81A\93Y\95t\82Ì\83h\83L\83\85\83\81\83\93\83g\82È\82Ç\82ð\8eQ\8fÆ\82µ\82Ä\r
+\82­\82¾\82³\82¢\81B\r
+\r
+\r
+Required Environment:\r
+=====================\r
+\r
+\93®\8dì\8am\94F\8dÏ OS:\r
+Microsoft Windows 2000 (SP3)\r
+\r
+\8b°\82ç\82­ Windows 95 \88È\8d~\82È\82ç\93®\82­\82Ì\82Å\82Í\82È\82¢\82©\82Æ\8ev\82¢\82Ü\82·\82ª\81A\r
+\83`\83F\83b\83N\82·\82é\8aÂ\8b«\82ª\82 \82è\82Ü\82¹\82ñ\81B\r
+\r
+\r
+Required Hardware Resources:\r
+============================\r
+\r
+* CPU \82Ì\8f\88\97\9d\94\\97Í\82ª\82»\82ê\82È\82è\82É\95K\97v\82Å\82· (\8aJ\94­\8aÂ\8b«\82Í Celeron 500MHz)\r
+* \83r\83f\83I\83J\81[\83h\82ª\8c«\82¯\82ê\82Î\81ª\82ð\83t\83H\83\8d\81[\82Å\82«\82é\82©\82à\82µ\82ê\82Ü\82¹\82ñ\r
+* \83\81\83\82\83\8a\82Í\8dÅ\92á\82Å\82à 8MB \82Í\95K\97v\82Å\82·\r
+* HDD \82Ì\8bó\82«\97e\97Ê\82Í 1MB \82à\82 \82ê\82Î\8f[\95ª\82Å\82·\r
+* MIDI \93ü\8fo\97Í\8aÂ\8b«\82ª\82 \82é\82Æ\81A\82»\82ê\82È\82è\82É\95Ö\97\98\82Å\82·\r
+* 106 / 109 \83L\81[\83{\81[\83h\82ª\91O\92ñ\82Å\82·\81B\82»\82Ì\82¤\82¿\83L\81[\94z\97ñ\82Í\90Ý\92è\89Â\94\\82É\82È\82é\82©\82à\r
+* (curses \94Å\82Ì\82æ\82¤\82È) DOS \91\8b\94Å\82Í\82 \82è\82Ü\82¹\82ñ\r
+* MFC \82Í\8eg\97p\82µ\82Ä\82¢\82Ü\82¹\82ñ\r
+\r
+CPU \82ð\90H\82Á\82Ä\82¢\82é\82Ì\82Í 99 % \89æ\96Ê\8d\87\90¬\8f\88\97\9d\8eü\82è\82Å\82·\81B\r
+\89æ\96Ê\8f\88\97\9d\82ð\8cµ\96§\82É X68k \82É\8d\87\82í\82¹\82½\8aÖ\8cW\82Å\81ALinux / UNIX \94Å\82æ\82è\8fd\82­\82È\82Á\82Ä\r
+\82¢\82é\82Í\82¸\82Å\82·\81B\r
+\r
+\r
+Installation:\r
+=============\r
+\r
+STed2.exe \82ª\8eÀ\8ds\83t\83@\83C\83\8b\82»\82Ì\82à\82Ì\82Å\82·\81B\r
+\8eÀ\8ds\91O\82É\93K\93\96\82È\83E\83B\83\8b\83X\83`\83F\83b\83J\82È\82Ç\82ð\92Ê\82µ\82½\8cã\82Å\81A\92¼\90Ú\8eÀ\8ds\82µ\82Ä\r
+\82­\82¾\82³\82¢\81B\83\8a\83\8a\81[\83X\91O\82É\88ê\89\9e\83E\83B\83\8b\83X\83`\83F\83b\83N (Norton Antivirus) \82ð\r
+\8ds\82Á\82Ä\82¢\82Ü\82·\82ª\81A\94O\82Ì\82½\82ß\81B\r
+\82È\82¨\81A\83C\83\93\83X\83g\81[\83\89\82Í\82 \82è\82Ü\82¹\82ñ\81B\r
+\r
+\83\\81[\83X\82©\82ç\83R\83\93\83p\83C\83\8b\82·\82é\8fê\8d\87\82Í\81A\r
+sted2/drivers/msvc/STed2 \88È\89º\82Ì\83v\83\8d\83W\83F\83N\83g\83t\83@\83C\83\8b\82ð\82²\97\98\97p\82­\82¾\82³\82¢\81B\r
+\82È\82¨\81ASTed2 for Windows \82Í\81A\r
+Microsoft Visual C++ .NET   55521-640-5604337-18012\r
+\82Å\8dì\90¬\82³\82ê\82Ä\82¢\82Ü\82·\81B\r
+\r
+\r
+Uninstall:\r
+==========\r
+\r
+STed2.exe \82ð\8dí\8f\9c\82µ\82Ä\82­\82¾\82³\82¢\81B\r
+\96{\83o\81[\83W\83\87\83\93\82Å\82Í\81A\83\8c\83W\83X\83g\83\8a\83L\81[\92Ç\89Á\81A\83f\83B\83\8c\83N\83g\83\8a\81A\8dì\8bÆ\83t\83@\83C\83\8b\82Ì\r
+\8dì\90¬ (\8dì\90¬\82µ\82½ MIDI \83f\81[\83^\82ð\95Û\91\82µ\82½\82à\82Ì\82Í\8f\9c\82­) \82È\82Ç\82Í\88ê\90Ø\8ds\82Á\82Ä\r
+\82¢\82Ü\82¹\82ñ\81B\r
+\r
+\r
+Usage:\r
+======\r
+\r
+\93K\93\96\82É\81B\r
+\8eg\82¢\95û\82É\8aÖ\82·\82é\8e¿\96â\93\99\82É\82Â\82¢\82Ä\82Í\88ê\90Ø\82¨\8eó\82¯\82Å\82«\82Ü\82¹\82ñ\81B\83\81\81[\83\8b\93\99\82Å\r
+\8e¿\96â\82ð\91\97\82Á\82Ä\92¸\82¢\82Ä\82à\81A\91Î\89\9e\82·\82é\8e\9e\8aÔ\82ª\91S\82­\8eæ\82ê\82È\82¢\8fó\8bµ\82Å\82·\82Ì\82Å\81B\r
+\r
+\r
+Configuration:\r
+==============\r
+\r
+sted2.cnf \82¨\82æ\82Ñ\8ae\8eí\89¹\8c¹\92è\8b`\83t\83@\83C\83\8b (sc55.def \82È\82Ç) \82Í\81A\r
+C:\Program Files\STed2 \82Æ\82¢\82¤\83t\83H\83\8b\83_\82É\93ü\82ê\82Ä\82¨\82­\82Æ\81A\r
+STed2 \82ª\8bN\93®\8e\9e\82É\93Ç\82Ý\8d\9e\82Ý\82Ü\82·\81B\r
+\8e©\93®\82Å\82Í\8dì\90¬\82µ\82Ü\82¹\82ñ\82Ì\82Å\81A\95K\97v\82ª\82 \82ê\82Î\8eè\93®\82Å\8dì\90¬\82µ\82Ä\82­\82¾\82³\82¢\81B\r
+\r
+\r
+Key Binding:\r
+============\r
+\r
+* sted2.cnf \82Å\82Ì\90Ý\92è\8b@\94\\82Í\81AWindows \94Å\82Å\82Í\93®\8dì\82µ\82Ü\82¹\82ñ\81B\r
+\82È\82¨\81A\88ê\95\94\82Ì\83L\81[\83o\83C\83\93\83h (\8dÄ\90\83X\83^\81[\83g\81A\83\8a\83Y\83\80\83g\83\89\83b\83N\r
+\83G\83f\83B\83^\8bN\93®\82È\82Ç)\82Í\81A\83\81\83j\83\85\81[\82©\82ç\8cÄ\82Ñ\8fo\82·\82±\82Æ\82ª\8fo\97\88\82Ü\82·\81B\r
+\r
+\r
+License:\r
+========\r
+\r
+\83I\83\8a\83W\83i\83\8b\82Ì STed2 \8e©\91Ì\82Ì\83\89\83C\83Z\83\93\83X\82É\82Â\82¢\82Ä\82Í\81Adoc/original_docs/tuitou.txt\r
+\82ð\8eQ\8fÆ\82µ\82Ä\82­\82¾\82³\82¢\81B\r
+\83R\81[\83h\93à\82Å\8eg\97p\82µ\82Ä\82¢\82é\8ae\83\89\83C\83u\83\89\83\8a\82É\82Â\82¢\82Ä\82Í\81A\82»\82ê\82¼\82ê\82Ì\83\89\83C\83u\83\89\83\8a\82Ì\r
+\83\89\83C\83Z\83\93\83X\82ð\8eQ\8fÆ\82µ\82Ä\82­\82¾\82³\82¢\81B\r
+STed2 for Windows \97p\82É\8f\91\82©\82ê\82½\83R\81[\83h\82É\82Â\82¢\82Ä\82Í\81A\88È\89º\82Ì\83\89\83C\83Z\83\93\83X\82É\r
+\8f]\82¢\82Ü\82·\81B\r
+\r
+  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+  of this software and associated documentation files (the "Software"), to deal\r
+  in the Software without restriction, including without limitation the rights\r
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+  copies of the Software, and to permit persons to whom the Software is\r
+  furnished to do so, subject to the following conditions:\r
+\r
+  The above copyright notice and this permission notice shall be included in\r
+  all copies or substantial portions of the Software.\r
+\r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+  THE SOFTWARE.\r
+\r
+\r
+Availablity:\r
+============\r
+\r
+http://sted2.sourceforge.net/\r
+\r
+\82É\8dÅ\90V\94Å\82ª\82 \82é\82©\82à\82µ\82ê\82Ü\82¹\82ñ\81B\96³\82¢\82©\82à\82µ\82ê\82Ü\82¹\82ñ\81B\r
+\96³\82¢\8fê\8d\87\82É\82Í\93K\93\96\82È\8c\9f\8dõ\83G\83\93\83W\83\93\82ð\82 \82½\82Á\82Ä\82­\82¾\82³\82¢\81B\r
+\r
+\r
+Thanks:\r
+=======\r
+\r
+snprintf - a portable implementation of snprintf\r
+Mark Martinec <mark.martinec@ijs.si>\r
+http://www.ijs.si/software/snprintf/\r
+\r
+Network Kanji Filter. (PDS Version)\r
+nkflib.c \82Ì\90æ\93ª\95\94\95ª\82ð\8eQ\8fÆ\82Ì\82±\82Æ\r
+\r
+ChangeLog, ChangeLog.old \82É\8bL\8dÚ\82³\82ê\82Ä\82¢\82é\95û\81X\r
+\r
+STed2 \82ð\90\82Ý\81A\88ç\82Ä\82Ä\82«\82½\91ò\8eR\82Ì\95û\81X\r
+\r
+TURBO \8e\81\82ð\8en\82ß\82Æ\82·\82é STed2 \8dì\8eÒ\82Ì\95û\81X\r
+\r
+\r
+Maintainer:\r
+===========\r
+\r
+NAGANO Daisuke <breeze.nagano@nifty.ne.jp>\r
+\8e¿\96â\82É\82Í\8b°\82ç\82­\82¨\93\9a\82¦\8fo\97\88\82Ü\82¹\82ñ\81B\r
diff --git a/README.jp b/README.jp
new file mode 100644 (file)
index 0000000..c4825db
--- /dev/null
+++ b/README.jp
@@ -0,0 +1,246 @@
+STed2 for UNIX
+==============
+
+ STed2 \e$B$r\e(B UNIX \e$B4D6-$G;H$$$?$$$H$$$&$3$H$G!"4JC1$J0\?"J6$$$N$3$H$r9T$C$F\e(B
\e$B$_$^$7$?!#\e(B
+
+  STed2 \e$B$H$O!"$+$D$F\e(B X680x0 \e$B$H$$$&\e(B personal workstation \e$B$GF0:n$7$F$$$?\e(B
+ MIDI \e$B%7!<%1%s%5$G$9!#%j%"%k%?%$%`F~NO!"%9%F%C%WF~NO$K$h$k\e(B MIDI \e$B%G!<%?\e(B
\e$B$NJT=8!&A`:n$r9T$&;v$,=PMh$^$7$?!#A`:nBN7O$O\e(B COME ON MUSIC \e$B<R$N%l%3%s\e(B
\e$B%]!<%6$K$[$\=`$8$F$$$^$9!#\e(B
+
+  STed2 \e$B$OD9G/$KEO$j!"\e(BTURBO(\e$B8MED5.G7\e(B)\e$B;a$K$h$j%a%s%F%J%s%9$,9T$o$l$F$-$^\e(B
\e$B$7$?!#$7$+$7\e(B 1997 \e$BG/\e(B 12 \e$B7n!";a$OIB5$$K$h$jB>3&$5$l$F$$$^$9!#6`$s$G8fL=\e(B
\e$BJ!$r$*5'$jCW$7$^$9!#\e(B
+  \e$B$=$N8e!"8f0dB2$N6(NO$HM-;V$N?TNO$K$h$j!":G=*HG$G$"$k\e(B sted2 version
+ 2.07 \e$B$N%=!<%9$,8x3+$5$l$^$7$?!#K\%"!<%+%$%V$O!"$=$N%=!<%9$r85$K!"\e(BUNIX 
\e$B>e$GF0:n$9$k$h$&=$@5$r9T$C$?$b$N$G$9!#\e(Boriginal \e$B$G$"$k\e(B X680x0 \e$BHG$H$[$\\e(B
\e$BF1Ey$NA`:n$r9T$&;v$,=PMh$k$h$&$K$J$C$F$$$^$9!#\e(B
+
+
+  STed2 \e$B$NA`:nJ}K!!";HMQJ}K!$=$NB>$K$D$$$F$N$3$H$O!"\e(Bdoc/original_docs/
+  \e$B0J2<$N%U%!%$%k$r;2>H$7$F2<$5$$!#\e(B
+
+\e$B:n$jJ}\e(B
+======
+
+   \e$B%"!<%+%$%V$rE83+$7$F\e(B
+
+    % ./configure ; make ; make install
+
+   \e$B$G$9!#\e(B./configure \e$B$G$O!"%*%W%7%g%s;XDj$K$h$j3F<o@_Dj$r9T$&$3$H$,$G\e(B
+   \e$B$-$^$9!#>\:Y$O\e(B ./configure --help \e$B$G8fMw2<$5$$!#\e(B
+
+   make install \e$B$G$O!"<B9T%U%!%$%k$NB>$K3F<o@_Dj%U%!%$%k$*$h$S9q:]2=MQ\e(B
+   \e$B%a%C%;!<%8%+%?%m%0$,%$%s%9%H!<%k$5$l$^$9!#\e(B
+   \e$B$A$J$_$K%$%s%9%H!<%k@h$O!"<B9T%U%!%$%k$,\e(B $(prefix)/bin\e$B!"\e(B
+   \e$B@_Dj%U%!%$%k$,\e(B $(prefix)/lib/sted\e$B!"%a%C%;!<%8%+%?%m%0$,\e(B
+   $(prefix)/share/locale \e$B0J2<$H$J$C$F$$$^$9!#$=$l$>$l!"\e(B./configure \e$B$N\e(B
+   \e$B%*%W%7%g%s$GJQ99$9$k$3$H$b2DG=$G$9!#\e(B
+
+
+\e$B;H$$J}\e(B
+======
+
\e$B<B9T$O!"\e(Bsted2, sted2.cnf, sted2.fon \e$B$r\e(B path \e$B$NDL$C$?F10l$N\e(B directory \e$B$K\e(B
\e$BCV$$$F!"\e(B
+
+  % sted2
+
+  \e$B$H\e(B type \e$B$7$F2<$5$$!#$b$74D6-JQ?t\e(B DISPLAY \e$B$,@_Dj$5$l$F$$$l$P\e(B X \e$BHG$G!"\e(B
\e$B$5$l$F$$$J$1$l$P\e(B ncurses \e$BHG$G5/F0$7$^$9!#\e(Bemacs \e$B$HF1$8$G$9$M!#\e(B
+  \e$B$J$*!"\e(Bsted2.cnf \e$B$H\e(B sted2.fon \e$B$NCV$->l=j$O!"\e(Bconfigure \e$B;~$K\e(B
+ --with-default-path \e$B$G@_Dj$9$k$3$H$b=PMh$^$9!#\e(B
+
\e$B>\$7$$MxMQJ}K!$KIU$$$F$O!"\e(Bdoc/original_docs/ \e$B0J2<$N3F<o%^%K%e%"%k$r\e(B
\e$B;2>H$7$F$/$@$5$$!#\e(B
\e$B$"$k$$$O!"!V%l%3%s%]!<%6!W4XO"$N=q@R$b;29M$K$J$k$H;W$$$^$9!#\e(B
+
+
+\e$B@_Dj\e(B
+====
+
+ sted2.cnf \e$B$r=$@5$9$k;v$G!"F0:n4D6-$rJQ99$9$k;v$,=PMh$^$9!#\e(B
\e$B@_DjFbMF$K$D$$$F$O!"\e(Bdoc/original_docs/sted2def.doc \e$B$r;2>H$7$F2<$5$$!#\e(B
+
\e$B$J$*!"\e(Bsted2.cf2 \e$B$*$h$S\e(B ~/.sted2rc \e$B$bF1MM$K@_Dj%U%!%$%k$H$7$FFI$_\e(B
\e$B9~$_$^$9!#\e(B
+
+ UNIX \e$BHGFH<+$N@_Dj2U=j$,4v$D$+$"$j$^$9!#\e(B
+
+
+ #PLAYER=     flag, \e$B;HMQ$9$k30It\e(B RCP/SMF player
+
+  \e$B30It\e(B RCP/SMF player \e$B$N3F<o@_Dj$G$9!#Bh0l0z?t$H$7$F\e(B player \e$B$N<oN`$r!"\e(B
\e$B%+%s%^$r$O$5$s$GBhFs0z?t$H$7$FE,Ev$J\e(B SMF/RCP/R36 player \e$B$NL>A0\e(B (\e$B%U%k%Q\e(B
\e$B%9\e(B) \e$B$H%*%W%7%g%s$r;XDj$7$F$/$@$5$$!#\e(B
+  flag \e$B$K@_Dj$9$kCM$G$9$,!"$b$7@_Dj$7$?\e(B player \e$B$,\e(B SMF \e$B$7$+07$($J$$>l9g\e(B
\e$B$O!"\e(Bbit 0 \e$B$r\e(B 0 \e$B$K!"\e(BRCP/R36 \e$B%U%!%$%k$b1iAU$G$-$k>l9g$O!"\e(B1 \e$B$K$7$?CM$rF~\e(B
\e$B$l$F2<$5$$!#$=$l0J30$N%S%C%H$K$D$$$F$OM=Ls$5$l$F$$$^$9!#\e(B
+
+
+ #MIDI_PORT=     MIDI IN \e$B$H$7$F;HMQ$9$k\e(B device name
+
+  MIDI \e$B%-!<%\!<%IEy$K$h$kF~NO5!G=$r;HMQ$7$?$$>l9g$O!"\e(BMIDI \e$B5!4o$,@\B3$5\e(B
\e$B$l$F$$$k%G%P%$%9L>$r@_Dj$7$F$/$@$5$$!#\e(B/dev/ttyS0 \e$B$N$h$&$J\e(B serial port 
\e$B$b@_Dj=PMh$^$9$,!"E>AwB.EY$=$NB>$N@_Dj$O\e(B STed2 \e$BB&$G$O9T$$$^$;$s$N$G!"\e(B
+ STed2 \e$B5/F0A0$KE,Ev$K@_Dj$7$F$*$$$F$/$@$5$$!#\e(B
+
+  \e$B$J$*!">e5-$N\e(B PLAYER \e$B$G@_Dj$7$?\e(B player \e$B$,3:Ev$9$k%G%P%$%9$r;HMQ$7$F$$\e(B
\e$B$k>l9g$O!"B?J,\e(B MIDI \e$BF~NO$O9T$($^$;$s\e(B(\e$B9T$($k>l9g$b$"$k$i$7$$\e(B)\e$B!#\e(B
+  \e$B=PNO$O\e(B serial \e$B7PM3$GF~NO$O\e(B MIDI port \e$B$J$I!"$J$k$Y$/J#?t$N%G%P%$%9$rMQ\e(B
\e$B0U$7$F;H$$J,$1$F$/$@$5$$!#\e(B
+
+
+ #FONT_NAME=     Font set name
+
+  X \e$B>e$GF0:n$9$k>l9g$N!"I=<($K;HMQ$9$k\e(B font set \e$BL>$r@_Dj$7$^$9!#%o%$%k\e(B
\e$B%I%+!<%I$H$7$F\e(B '*' \e$B$b;H$($^$9$,!"\e(Bsted2.cnf \e$BB&$NCm<aJ8;XDj$H$+$V$j$^$9\e(B
\e$B$N$G!"A0$K\e(B '\' \e$B$rIU$1$FBP=h$7$F2<$5$$!#\e(B
+  \e$B$^$?!";HMQ$9$k\e(B Font Set \e$BL>$r\e(B ',' \e$B$G6h@Z$C$?I=5-$bG'$a$i$l$^$9!#>\$7$/\e(B
\e$B$O!"\e(BXCreateFontSet(3x) \e$B$N\e(B man page \e$B$r8+$F2<$5$$\e(B (man XCreateFontSet)\e$B!#\e(B
+
+
+ #KEY_?? = key name
+
+ X \e$B>e$GF0:n$9$k>l9g$N!"%-!<%\!<%I$N>pJs$K$D$$$F@_Dj$7$^$9!#\e(B
\e$B@_Dj$G$-$k%-!<$N<oN`$H$7$F$O!"\e(B
+
+  #KEY_XF1 - #KEY_XF5
+  #KEY_KANA, #KEY_KIGO, #KEY_TOROKU
+  #KEY_INS, #KEY_DEL, #KEY_HOME, #KEY_UNDO, #KEY_RUP, #KEY_RDOWN
+  #KEY_OPT1, KEY_OPT2
+
\e$B$,MQ0U$5$l$F$$$^$9!#<j85$N%-!<%\!<%I$N%-!<%H%C%W$N>pJs$K1~$8$F!"\e(B
\e$BE,Ev$K@_Dj$7$F2<$5$$!#\e(B
+ key name \e$B$O\e(B KeySym \e$BL>$G$9!#\e(Bxev(1x) \e$B$GI=<($5$l$k>pJs$N$&$A!"\e(B
+
+  (keysym 0x??, foo)
+
\e$B$N\e(B 'foo' \e$B$KEv$?$kItJ,$G$9!#\e(B
\e$B$J$*!"\e(Bsted2.cnf \e$B$K!"$$$/$D$+$N4D6-$KIU$$$F@_DjNc$,$"$j$^$9!#\e(B
+
+
+\e$B%*%j%8%J%k$H0[$J$kE@\e(B
+====================
+
\e$B%*%j%8%J%k\e(B (X680x0 \e$BHG\e(B) \e$B$H0[$J$kE@$KIU$$$F0J2<$K5s$2$^$9\e(B:
+
+  . \e$B%-!<G[Ns$,0c$&\e(B/\e$BBP1~$9$k%-!<$,L5$$\e(B
+
+     \e$BJ*M}E*$KB8:_$7$J$$!"$"$k$$$O%=%U%H%&%'%"E*\e(B(ncurses / X)\e$B$J@)8B$K$h$j!"\e(B
+     \e$B4v$D$+$N%-!<$KDj5A$5$l$?A`:n$,=PMh$J$$$3$H$,$"$j$^$9!#\e(B
+     \e$B6qBNE*$K$O!"\e(BX68k \e$B$G1>$&=j$N\e(B
+
+      OPT.1, OPT.2
+      \e$B%m!<%^;z\e(B, \e$B%3!<%IF~NO\e(B, CAPS, \e$B$R$i$,$J\e(B, \e$BA43Q\e(B
+      HELP, BREAK, COPY
+
+      XF1 - XF5 (X\e$BHG$O2D\e(B)
+      \e$B%F%s%-!<\e(B (CLR \e$B4^$`\e(B : X\e$BHG$O2D\e(B)
+      \e$B$+$J\e(B, \e$B5-9f\e(B, \e$BEPO?\e(B (X\e$BHG$O2D\e(B)
+
+     \e$B$KAjEv$9$k%-!<A`:n$O9T$($^$;$s!#\e(B
+
+     \e$B$J$*!"$$$/$D$+$N%-!<$KIU$$$F$O\e(B sted2.cnf \e$B$G@_Dj$,2DG=$G$9!#\e(B
+     \e$BNc$($P!"\e(BLinux \e$BMQ$G$O0J2<$N$h$&$JBP1~$K$J$C$F$$$^$9!#\e(B
+
+    X68k           \e$B$3$A$i\e(B(106,109-key)
+    ---------------------
+    \e$B5-9f\e(B            F11
+    \e$BEPO?\e(B            F12
+     XF1            Alt (\e$B:8\e(B)
+     XF2            \e$BL5JQ49\e(B
+     XF3            \e$BA08uJd\e(B/\e$BJQ49\e(B
+     XF4            \e$B%+%?%+%J\e(B/\e$B$R$i$,$J\e(B
+     XF5            Alt (\e$B1&\e(B)
+    \e$B$+$J\e(B            Caps Lock
+
+
+
+  . \e$B0lIt$N%-!<%"%5%$%s$,0c$&\e(B
+
+     \e$BK?\e(B Window Manager \e$B$H$N7s$M9g$$$d!"$=$NB>=tHL$N;v>p$G\e(B original \e$B$H\e(B
+     \e$B0[$J$k%-!<%"%5%$%s$r9T$C$F$$$kItJ,$,$"$j$^$9!#6qBNE*$K$O!"\e(B
+
+     .Shift+\e$B%+!<%=%k:81&$G\e(B track \e$B4V0\F0$,2DG=\e(B (\e$B%3%s%=!<%kHG$OIT2D\e(B)
+
+     \e$BEy!9$H$J$C$F$$$^$9!#\e(B
+
+     \e$B$J$*!"\e(Btrack edit \e$B;~$N!V%-!<%\!<%I%(%_%e%l!<%?!W5!G=$O!"8=:_$N=j\e(B
+     \e$B;HMQ$G$-$^$;$s!#\e(B
+
+
+  . \e$BIT0BDj\e(B
+  . \e$BJQ\e(B
+  . \e$B%@%a$9$.\e(B :-)
+
+     \e$B0J>e$K$D$$$F$O!"A4$F;d$N;j$i$J$5$K$h$j$^$9!#%*%j%8%J%k$N\e(B STed2 \e$B$H$$$&\e(B
+     \e$B%7%9%F%`$O!"4{$K2?G/$b$N<B@S$,$"$k0BDj$7$?%=%U%H%&%'%"$G$9$N$G!"ITET9g!&\e(B
+     \e$BIT6q9g$,$"$l$P!"$=$l$O0\?"$7$?;d$N:n6H$K2?$i$+$NIT<j:]$,$"$C$?$H$$$&\e(B
+     \e$B$3$H$K$J$j$^$9!#\e(B
+
+
\e$B$H$$$&$o$1$G!"8f0U8+$=$NB>$4$6$$$^$7$?$i!";d$NJ}$^$G8fO"MmD:$1$^$9$H!"\e(B
\e$B2?$+\e(B feed back \e$B$,$"$k$+$b$7$l$^$;$s!#\e(B
+
\e$BK\%"!<%+%$%VCf$K4^$^$l$k%U%!%$%k$G!";d\e(B(Daisuke NAGANO) \e$B$,=q$$$?\e(B
\e$B%3!<%I!&%F%-%9%HEy$K$D$$$F$O!"\e(BGPL2 \e$B$K=>$C$?MxMQ!&G[I[$,2DG=$H$7$^$9!#\e(B
\e$B%*%j%8%J%k$N%3!<%IEy$K$D$$$F$O!"%*%j%8%J%k$N\e(B Document \e$B$r;2>H$7$F2<$5$$!#\e(B
+
+
+
+THANKS
+======
+
+ ChangeLog \e$B$NCf$K!"4XO"$7$?>pJs$H$H$b$K5-O?$5$l$F$$$^$9!#$"$j$,$H$&\e(B
\e$B$4$6$$$^$7$?!#\e(B
+
+ STed2 \e$B$N%=!<%98x3+$K?TNO$5$l$?M-;V$N3'MM!"$=$7$F2?$h$j\e(B STed2 / RC-Systems \e$B$N\e(B
\e$B:n<T$G$"$jM%=($J%W%m%0%i%^$G$"$C$?\e(B \e$B8N\e(B TURBO \e$B;a$K!"?4$+$i$N46<U$r\e(B
\e$BJ{$2$^$9!#\e(B
+
+
+\e$B0\?"$KIU$$$F\e(B
+============
+
\e$B%*%j%8%J%k$N%U%!%$%k\e(B: \e$B@07A!"%3!<%IJQ49\e(B (EUC\e$B2=\e(B) \e$BDxEY!#\e(B
+                       \e$B0lIt4X?t$K$D$$$F=$@5\e(B (HISTORY \e$B;2>H\e(B)
+
\e$B;d$,=q$$$?$b$N\e(B: iocscall, doscall \e$B8_49\e(B(?) \e$B4X?t!#$=$NB>!"%$%s%?%U%'%$%9\e(B
+                 \e$B<~$j$HDTjm9g$o$;4X?t72\e(B (\e$B<g$K\e(B sted2/sub/ \e$B0J2<\e(B)
+
\e$B;29M$K$7$?$b$N\e(B: nkflib.c(timidity \e$B2~NIHG$h$j\e(B)
+                 \e$B0J>e$O%3!<%I$r$=$N$^$^\e(B(\e$BB?>/<j$r2C$($F\e(B)\e$B;HMQ$7$F$$$^$9!#\e(B
+
+
+DISCLIMER
+=========
+
+  \e$BK\%W%m%0%i%`$r;HMQ$7$FMxMQ<T$KH/@8$7$?$$$+$J$k;vBV$K4X$7$F$b!"\e(B
+  \e$B@=:n<T$G$"$k;d$*$h$S4X78<T$O0l@Z$=$N@U$rIi$$$+$M$^$9!#\e(B
+  \e$B<+8J@UG$$N$b$H$G$4MxMQ$/$@$5$$!#\e(B
+  \e$BG[IU>r7o$K$D$$$F$O!"%*%j%8%J%k$N\e(B STed2 \e$B$NG[IU>r7o$K=>$$$^$9!#\e(B
+  doc/original_docs/tuitou.txt \e$B$r;2>H$7$F$/$@$5$$!#\e(B
+
+
+AVAILABILITY
+============
+
+  STed2 for X \e$B$N:G?7HG$O!"0J2<$N\e(B URL \e$B$+$iC)$l$k>l=j$KCV$$$F$"$k$O$:$G$9!#\e(B
+
+             http://member.nifty.ne.jp/Breeze/index.html
+
+
+AUTHORS:
+========
+
\e$B86:n\e(B:
+  TURBO(\e$B8MED5.G7\e(B)
+
+ X \e$B4D6-0\?"\e(B :
+  \e$BD9LnBg2p\e(B ( Daisuke NAGANO ) <breeze.nagano@nifty.ne.jp>
+  http://member.nifty.ne.jp/Breeze/index.html
+
diff --git a/ReadMe.txt b/ReadMe.txt
new file mode 100644 (file)
index 0000000..8712a97
--- /dev/null
@@ -0,0 +1,53 @@
+========================================================================\r
+    WIN32 \83A\83v\83\8a\83P\81[\83V\83\87\83\93 : STed2 \83v\83\8d\83W\83F\83N\83g\82Ì\8aT\97v\r
+========================================================================\r
+\r
+AppWizard \82Í\83\86\81[\83U\81[\97p\82É STed2 \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82ð\8dì\90¬\82µ\82Ü\82µ\82½\81B  \r
+\82±\82Ì\83t\83@\83C\83\8b\82É\82Í STed2 \83A\83v\83\8a\83P\81[\83V\83\87\83\93\82ð\8d\\90¬\82µ\82Ä\82¢\82é\r
+\8ae\83t\83@\83C\83\8b\82Ì\8aT\97v\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B\r
+\r
+\r
+STed2.vcproj\r
+    \82±\82ê\82Í\83A\83v\83\8a\83P\81[\83V\83\87\83\93 \83E\83B\83U\81[\83h\82Å\90\90¬\82³\82ê\82½ VC++ \83v\83\8d\83W\83F\83N\83g\82Ì\83\81\83C\83\93 \83v\83\8d\83W\83F\83N\83\83t\83@\83C\83\8b\82Å\82·\81B\r
+    \83t\83@\83C\83\8b\82ª\90\90¬\82³\82ê\82½ Visual C++ \82Ì\83o\81[\83W\83\87\83\93\8fî\95ñ\82ª\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B\82Ü\82½\81\r
+    \83A\83v\83\8a\83P\81[\83V\83\87\83\93 \83E\83B\83U\81[\83h\82Å\91I\91ð\82µ\82½\83v\83\89\83b\83g\83t\83H\81[\83\80\81A\8d\\90¬\82¨\82æ\82Ñ\83v\83\8d\83W\83F\83N\83g\8b@\94\\82É\8aÖ\82·\82é\r
+    \8fî\95ñ\82à\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B\r
+\r
+STed2.cpp\r
+    \82±\82ê\82Í\83\81\83C\83\93\82Ì\83A\83v\83\8a\83P\81[\83V\83\87\83\93 \83\\81[\83\83t\83@\83C\83\8b\82Å\82·\81B\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+AppWizard \82Í\8e\9f\82Ì\83\8a\83\\81[\83X\82ð\8dì\90¬\82µ\82Ü\82µ\82½ :\r
+\r
+STed2.rc\r
+    \82±\82ê\82Í\83v\83\8d\83O\83\89\83\80\82ª\8eg\97p\82·\82é Microsoft Windows \82Ì\83\8a\83\\81[\83X\82Ì\r
+   \88ê\97\97\83t\83@\83C\83\8b\82Å\82·\81BRES \82Ì\83T\83u\83f\83B\83\8c\83N\83g\83\8a\82É\95Û\91\82³\82ê\82Ä\82¢\82é\r
+    \83A\83C\83R\83\93\81A\83r\83b\83g\83}\83b\83v\82¨\82æ\82Ñ\83J\81[\83\\83\8b\82ð\8aÜ\82ñ\82Å\82¢\82Ü\82·\81B\82±\82Ì\83t\83@\83C\83\8b\82Í Microsoft Visual C++ \82Å\92¼\90Ú\95Ò\8fW\82·\82é\r
+    \82±\82Æ\82ª\89Â\94\\82Å\82·\81B\r
+\r
+Resource.h\r
+    \82±\82ê\82Í\90V\82µ\82¢\83\8a\83\\81[\83X ID \82ð\92è\8b`\82·\82é\95W\8f\80\83w\83b\83\83t\83@\83C\83\8b\82Å\82·\81B.\r
+    Visual C++ \82Ì\83\8a\83\\81[\83\83G\83f\83B\83^\82Í\82±\82Ì\83t\83@\83C\83\8b\82ð\93Ç\82Ý\8eæ\82è\81A\8dX\90V\82µ\82Ü\82·\81B\r
+STed2.ico\r
+    \82±\82ê\82Í\83A\83C\83R\83\93 \83t\83@\83C\83\8b\82Å\82·\81B\83A\83v\83\8a\83P\81[\83V\83\87\83\93\82Ì\83A\83C\83R\83\93\82Æ\82µ\82Ä\8eg\97p\82³\82ê\82Ü\82· (32x32)\81B\r
+    \82±\82Ì\83A\83C\83R\83\93\82Í\83\81\83C\83\93 \83\8a\83\\81[\83\83t\83@\83C\83\8b STed2.rc \82É\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B\r
+\r
+small.ico\r
+    \82±\82ê\82Í\83A\83C\83R\83\93 \83t\83@\83C\83\8b\82Å\82·\81B\83A\83v\83\8a\83P\81[\83V\83\87\83\93 \83A\83C\83R\83\93\82Ì\8f¬\82³\82¢\83o\81[\83W\83\87\83\93\82ð\8aÜ\82Ý\82Ü\82· (16x16)\81B\r
+    \82±\82Ì\83A\83C\83R\83\93\82Í\83\81\83C\83\93 \83\8a\83\\81[\83\83t\83@\83C\83\8b STed2.rc \r
+    \82É\8aÜ\82Ü\82ê\82Ä\82¢\82Ü\82·\81B\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+\82»\82Ì\91¼\82Ì\95W\8f\80\83t\83@\83C\83\8b :\r
+\r
+StdAfx.h, StdAfx.cpp\r
+    \82±\82ê\82ç\82Ì\83t\83@\83C\83\8b\82Í\83v\83\8a\83R\83\93\83p\83C\83\8b\8dÏ\82Ý\83w\83b\83_\81[ (PCH) \83t\83@\83C\83\8b STed2.pch\81A\r
+    \82¨\82æ\82Ñ\83v\83\8a\83R\83\93\83p\83C\83\8b\82³\82ê\82½\8c^\82Ì (PCT) \83t\83@\83C\83\8b stdafx.obj \82ð\83r\83\8b\83h\82·\82é\82½\82ß\82É\8eg\82í\82ê\82Ü\82·\81B\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+\82»\82Ì\91¼\82Ì\92\8d\88Ó :\r
+\r
+AppWizard  \82Í "TODO:" \82Å\8en\82Ü\82é\83R\83\81\83\93\83g\82ð\8eg\97p\82µ\82Ä\81A\83\\81[\83X\83R\81[\83h\82Ì\92Ç\89Á\82â\83J\83X\83^\83}\83C\83Y\82Ì\r
+\95K\97v\82È\8fê\8f\8a\82ð\8e¦\82µ\82Ü\82·\81B\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
diff --git a/SF.props b/SF.props
new file mode 100644 (file)
index 0000000..0760ec7
--- /dev/null
+++ b/SF.props
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ImportGroup Label="PropertySheets" />
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <IncludePath>H:\libs\DirectXTK\Inc;H:\libs\boost\include\boost-1_53;H:\libs\xbyak\xbyak;H:\libs\zlib125\zlib-1.2.5;H:\libs\lpng150\lpng150;$(IncludePath)</IncludePath>
+  </PropertyGroup>
+  <PropertyGroup>
+    <LibraryPath>H:\libs\zlib125\zlib-1.2.5;H:\libs\boost\lib;$(LibraryPath)</LibraryPath>
+  </PropertyGroup>
+  <ItemDefinitionGroup>
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <MultiProcessorCompilation>true</MultiProcessorCompilation>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <RuntimeTypeInfo>true</RuntimeTypeInfo>
+      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+      <StructMemberAlignment>16Bytes</StructMemberAlignment>
+      <EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>
+      <PreprocessorDefinitions>_UNICODE;UNICODE;_WIN64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <CompileAsWinRT>true</CompileAsWinRT>
+      <AdditionalUsingDirectories>C:\Program Files %28x86%29\Microsoft SDKs\Windows\v8.0\ExtensionSDKs\Microsoft.VCLibs\11.0\References\CommonConfiguration\neutral;C:\Program Files %28x86%29\Windows Kits\8.0\References\CommonConfiguration\Neutral;%(AdditionalUsingDirectories)</AdditionalUsingDirectories>
+    </ClCompile>
+  </ItemDefinitionGroup>
+  <ItemGroup />
+</Project>
\ No newline at end of file
diff --git a/STed2.aps b/STed2.aps
new file mode 100644 (file)
index 0000000..713b262
Binary files /dev/null and b/STed2.aps differ
diff --git a/STed2.cpp b/STed2.cpp
new file mode 100644 (file)
index 0000000..61effdc
--- /dev/null
+++ b/STed2.cpp
@@ -0,0 +1,132 @@
+/*\r
+       STed2 for Win32\r
+\r
+       Made by Studio Breeze. 2002\r
+\r
+       Started: Oct.06.2002\r
+*/\r
+\r
+#include "stdafx.h"\r
+#include "STed2.h"\r
+#include "sted_screen_win32.h"\r
+#include "sted_dialogs.h"\r
+#include "mmsystem.h"\r
+#include "sf_com.h"\r
+\r
+// グローバル変数 :\r
+// HINSTANCE hInst;                                                            // 現在のインターフェイス\r
+\r
+//HWND hwndMain = NULL;\r
+//HMENU hmenu = NULL;\r
+//HACCEL gAccelTable = NULL;\r
+//\r
+//ATOM                         MyRegisterClass(HINSTANCE hInstance);\r
+//BOOL                         InitInstance(HINSTANCE, int);\r
+//LRESULT CALLBACK     WndProc(HWND, UINT, WPARAM, LPARAM);\r
+LRESULT CALLBACK       About(HWND, UINT, WPARAM, LPARAM);\r
+\r
+//static LRESULT Player_PlayAll(CSTedScreenWin32* in_drv);\r
+//static LRESULT Player_PlayTrack(CSTedScreenWin32* in_drv);\r
+//static LRESULT Player_PlayMeas(CSTedScreenWin32* in_drv);\r
+//static LRESULT Player_PlayStop(CSTedScreenWin32* in_drv);\r
+//static LRESULT Player_ToggleTrace(CSTedScreenWin32* in_drv);\r
+//static LRESULT RhythmEdit_CurrentMeas(CSTedScreenWin32* in_drv);\r
+//static LRESULT RhythmEdit_NewMeas(CSTedScreenWin32* in_drv);\r
+\r
+ int main(int argc, char *argv[]);\r
+\r
+// accessor\r
+//HWND STedGetWindow(void)\r
+//{\r
+//     return hwndMain;\r
+//}\r
+//\r
+//HMENU STedGetMenu(void)\r
+//{\r
+//     return ::GetMenu(hwndMain);\r
+//}\r
+//\r
+//HDC STedGetWindowDC(void)\r
+//{\r
+//     return ::GetDC(hwndMain);\r
+//}\r
+//\r
+//HINSTANCE STedGetAppInstance(void)\r
+//{\r
+//     return hInst;\r
+//}\r
+//HACCEL STedGetAccelTable(void)\r
+//{\r
+//     return gAccelTable;\r
+//}\r
+\r
+int APIENTRY WinMain(HINSTANCE hInstance,\r
+                     HINSTANCE hPrevInstance,\r
+                     LPSTR    lpCmdLine,\r
+                     int       nCmdShow)\r
+{\r
+       sf::com_initialize com_init_;\r
+\r
+       CSTedScreenWin32::init_instance();\r
+\r
+       char* argv[2];\r
+       argv[0] = "sted2";\r
+       argv[1] = NULL;\r
+\r
+  try {\r
+    main(0, argv);\r
+  } catch (...)\r
+  {\r
+    CSTedScreenWin32::instance()->Tidy();\r
+         CSTedScreenWin32::instance().reset();\r
+    return (int) -1 ;\r
+  }\r
+       return (int) 0;\r
+}\r
+\r
+\r
+\r
+//ATOM MyRegisterClass(HINSTANCE hInstance)\r
+//{\r
+//     WNDCLASSEX wcex;\r
+//\r
+//     wcex.cbSize = sizeof(WNDCLASSEX); \r
+//\r
+//     wcex.style                      = CS_HREDRAW | CS_VREDRAW;\r
+//     wcex.lpfnWndProc        = (WNDPROC)WndProc;\r
+//     wcex.cbClsExtra         = 0;\r
+//     wcex.cbWndExtra         = 0;\r
+//     wcex.hInstance          = hInstance;\r
+//     wcex.hIcon                      = LoadIcon(hInstance, (LPCTSTR)IDI_STED2);\r
+//     wcex.hCursor            = LoadCursor(NULL, IDC_ARROW);\r
+//     wcex.hbrBackground      = (HBRUSH)(COLOR_WINDOW+1);\r
+//     wcex.lpszMenuName       = (LPCTSTR)IDC_STED2;\r
+//     wcex.lpszClassName      = szWindowClass;\r
+//     wcex.hIconSm            = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);\r
+//\r
+//     return RegisterClassEx(&wcex);\r
+//}\r
+\r
+//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)\r
+//{\r
+//   HWND hWnd;\r
+//\r
+//   hInst = hInstance; // グローバル変数にインスタンス処理を格納します。\r
+//\r
+//   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,\r
+//      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);\r
+//\r
+//   if (!hWnd)\r
+//   {\r
+//      return FALSE;\r
+//   }\r
+//\r
+//   hwndMain = hWnd;\r
+//\r
+//   ShowWindow(hWnd, nCmdShow);\r
+//   UpdateWindow(hWnd);\r
+//\r
+//   return TRUE;\r
+//}\r
+\r
+\r
diff --git a/STed2.h b/STed2.h
new file mode 100644 (file)
index 0000000..b798bf5
--- /dev/null
+++ b/STed2.h
@@ -0,0 +1,3 @@
+#pragma once
+
+#include "resource.h"
diff --git a/STed2.ico b/STed2.ico
new file mode 100644 (file)
index 0000000..d551aa3
Binary files /dev/null and b/STed2.ico differ
diff --git a/STed2.rc b/STed2.rc
new file mode 100644 (file)
index 0000000..5338431
--- /dev/null
+++ b/STed2.rc
@@ -0,0 +1,221 @@
+// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#define APSTUDIO_HIDDEN_SYMBOLS
+#include "windows.h"
+#undef APSTUDIO_HIDDEN_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// \83j\83\85\81[\83g\83\89\83\8b (\8aù\92è) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD)
+#ifdef _WIN32
+LANGUAGE LANG_NEUTRAL, SUBLANG_DEFAULT
+#pragma code_page(932)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_PREF_MIDIDEVICE DIALOGEX 0, 0, 139, 143
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_CAPTION | 
+    WS_SYSMENU
+CAPTION "MIDI DEVICE"
+FONT 9, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    COMBOBOX        IDC_MIDIIN,6,18,98,72,CBS_DROPDOWN |  
+                    WS_DISABLED | WS_VSCROLL | WS_TABSTOP
+    LTEXT           "MIDI IN",IDC_STATIC,6,6,42,8
+    COMBOBOX        IDC_MIDIOUT0,6,60,96,72,CBS_DROPDOWNLIST |  
+                    WS_DISABLED | WS_VSCROLL | WS_TABSTOP
+    LTEXT           "MIDI OUT 0",IDC_STATIC,12,48,46,8
+    DEFPUSHBUTTON   "OK",IDOK,6,120,50,14
+    PUSHBUTTON      "Cancel",IDCANCEL,72,120,50,14
+    COMBOBOX        IDC_MIDIOUT1,6,96,96,66,CBS_DROPDOWNLIST | 
+                    WS_DISABLED | WS_VSCROLL | WS_TABSTOP
+    LTEXT           "MIDI OUT 1",IDC_STATIC,12,84,49,8
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO 
+BEGIN
+    IDD_PREF_MIDIDEVICE, DIALOG
+    BEGIN
+        RIGHTMARGIN, 138
+        BOTTOMMARGIN, 142
+    END
+END
+#endif    // APSTUDIO_INVOKED
+
+#endif    // \83j\83\85\81[\83g\83\89\83\8b (\8aù\92è) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
+// \93ú\96{\8cê resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_JPN)
+#ifdef _WIN32
+LANGUAGE LANG_JAPANESE, SUBLANG_DEFAULT
+#pragma code_page(932)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_ABOUTBOX DIALOGEX 22, 17, 230, 75
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_CAPTION | WS_SYSMENU
+CAPTION "Version information"
+FONT 9, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+    ICON            IDI_STED2,IDC_MYICON,14,9,20,20
+    LTEXT           "STed2 for Windows",IDC_STATIC,49,10,119,8,SS_NOPREFIX
+    LTEXT           "Copyright (C) TURBO, Studio Breeze.",IDC_STATIC,48,36,
+                    119,8
+    DEFPUSHBUTTON   "OK",IDOK,195,6,30,11,WS_GROUP
+    LTEXT           "Version",IDC_VERSION,48,18,144,8
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_STED2               ICON                    "STed2.ico"
+IDI_SMALL               ICON                    "small.ico"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Menu
+//
+
+IDC_STED2 MENUEX 
+BEGIN
+    POPUP "File",                           65535,MFT_STRING,MFS_ENABLED
+    BEGIN
+        MENUITEM "Close (&X)",                  105,MFT_STRING,MFS_ENABLED
+    END
+    POPUP "Play",                           65535,MFT_STRING,MFS_ENABLED
+    BEGIN
+        MENUITEM "Play all",                    IDM_PLAY_PLAYALL,MFT_STRING,
+        MFS_ENABLED
+        MENUITEM "Play Track",                  IDM_PLAY_PLAYTRACK,
+        MFT_STRING,MFS_ENABLED
+        MENUITEM "Play Measure",                IDM_PLAY_PLAYMEASURE,
+        MFT_STRING,MFS_ENABLED
+        MENUITEM "Stop",                        IDM_PLAY_STOP,MFT_STRING,
+        MFS_ENABLED
+        MENUITEM MFT_SEPARATOR
+        MENUITEM "Trace",                       IDM_PLAY_TRACE,MFT_STRING,
+        MFS_ENABLED
+    END
+    POPUP "Edit",                           65535,MFT_STRING,MFS_ENABLED
+    BEGIN
+        POPUP "Rhythm track",                   65535,MFT_STRING,MFS_ENABLED
+        BEGIN
+            MENUITEM "Current Meas.",               IDM_EDIT_RHYTHMTRACK_CURRENTMEAS,
+            MFT_STRING,MFS_ENABLED
+            MENUITEM "New Meas.",                   IDM_EDIT_RHYTHMTRACK_NEWMEAS,
+            MFT_STRING,MFS_ENABLED
+        END
+    END
+    POPUP "Prefs",                          65535,MFT_STRING,MFS_ENABLED
+    BEGIN
+        MENUITEM "MIDI Ports",                  129,MFT_STRING,MFS_ENABLED
+    END
+    POPUP "Help",                           65535,
+    MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
+    BEGIN
+        MENUITEM "Version info ...(&A)",        104,MFT_STRING,MFS_ENABLED
+    END
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Accelerator
+//
+
+IDC_STED2 ACCELERATORS 
+BEGIN
+    "?",            IDM_ABOUT,              ASCII,  ALT
+    "/",            IDM_ABOUT,              ASCII,  ALT
+END
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE 
+BEGIN
+    "resource.h\0"
+END
+
+2 TEXTINCLUDE 
+BEGIN
+    "#define APSTUDIO_HIDDEN_SYMBOLS\r\n"
+    "#include ""windows.h""\r\n"
+    "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n"
+    "\0"
+END
+
+3 TEXTINCLUDE 
+BEGIN
+    "\r\n"
+    "\0"
+END
+
+#endif    // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// String Table
+//
+
+STRINGTABLE 
+BEGIN
+    IDS_APP_TITLE           "STed2"
+    IDC_STED2               "STED2"
+END
+
+#endif    // \93ú\96{\8cê resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif    // not APSTUDIO_INVOKED
+
diff --git a/STed2.vcxproj b/STed2.vcxproj
new file mode 100644 (file)
index 0000000..85dac62
--- /dev/null
@@ -0,0 +1,419 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{8BA3E9BF-1BAD-47F0-AA7B-71D719222028}</ProjectGuid>
+    <Keyword>Win32Proj</Keyword>
+    <ProjectName>STedX</ProjectName>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>v110</PlatformToolset>
+    <WindowsAppContainer>false</WindowsAppContainer>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <CharacterSet>Unicode</CharacterSet>
+    <PlatformToolset>v110</PlatformToolset>
+    <WindowsAppContainer>false</WindowsAppContainer>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="SF.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="SF.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="SF.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="SF.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup>
+    <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</OutDir>
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Debug\</IntDir>
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</LinkIncremental>
+    <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</OutDir>
+    <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Release\</IntDir>
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
+    <LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|x64'">false</LinkIncremental>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <IncludePath>../../win32/;$(IncludePath)</IncludePath>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>C:\cygwin\home\nagano\works\STed;C:\cygwin\home\nagano\works\STed\sted2;C:\cygwin\home\nagano\works\STed\sted2\drivers;C:\cygwin\home\nagano\works\STed\sted2\drivers\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <MinimalRebuild>false</MinimalRebuild>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+      <AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
+      <StructMemberAlignment>8Bytes</StructMemberAlignment>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>winmm.lib;DWMApi.lib;d2d1.lib;Avrt.lib;Dwrite.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <OutputFile>$(OutDir)STed2.exe</OutputFile>
+      <IgnoreSpecificDefaultLibraries>;libcmt;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <ProgramDatabaseFile>$(OutDir)STed2.pdb</ProgramDatabaseFile>
+      <SubSystem>Windows</SubSystem>
+      <TargetMachine>MachineX86</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <Optimization>Disabled</Optimization>
+      <AdditionalIncludeDirectories>C:\cygwin\home\nagano\works\STed;C:\cygwin\home\nagano\works\STed\sted2;C:\cygwin\home\nagano\works\STed\sted2\drivers;C:\cygwin\home\nagano\works\STed\sted2\drivers\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;HAVE_CONFIG_H;HAVE_STED2_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <MinimalRebuild>false</MinimalRebuild>
+      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+      <PrecompiledHeader>Use</PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <AdditionalOptions>/Zm200 %(AdditionalOptions)</AdditionalOptions>
+      <StructMemberAlignment>16Bytes</StructMemberAlignment>
+      <CompileAsWinRT>true</CompileAsWinRT>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>winmm.lib;DWMApi.lib;d2d1.lib;Avrt.lib;Dwrite.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <OutputFile>$(OutDir)STed2.exe</OutputFile>
+      <IgnoreSpecificDefaultLibraries>;libcmt;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <ProgramDatabaseFile>$(OutDir)STed2.pdb</ProgramDatabaseFile>
+      <SubSystem>Windows</SubSystem>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <Optimization>MaxSpeed</Optimization>
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+      <OmitFramePointers>true</OmitFramePointers>
+      <AdditionalIncludeDirectories>C:\cygwin\home\nagano\works\STed;C:\cygwin\home\nagano\works\STed\sted2;C:\cygwin\home\nagano\works\STed\sted2\drivers;C:\cygwin\home\nagano\works\STed\sted2\drivers\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;HAVE_CONFIG_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <StringPooling>true</StringPooling>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>winmm.lib;DWMApi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <OutputFile>$(OutDir)STed2.exe</OutputFile>
+      <IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <SubSystem>Windows</SubSystem>
+      <OptimizeReferences>true</OptimizeReferences>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <TargetMachine>MachineX86</TargetMachine>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <Optimization>MaxSpeed</Optimization>
+      <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+      <OmitFramePointers>true</OmitFramePointers>
+      <AdditionalIncludeDirectories>C:\cygwin\home\nagano\works\STed;C:\cygwin\home\nagano\works\STed\sted2;C:\cygwin\home\nagano\works\STed\sted2\drivers;C:\cygwin\home\nagano\works\STed\sted2\drivers\win32;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;HAVE_CONFIG_H;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <StringPooling>true</StringPooling>
+      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <PrecompiledHeader>
+      </PrecompiledHeader>
+      <WarningLevel>Level3</WarningLevel>
+      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+    </ClCompile>
+    <Link>
+      <AdditionalDependencies>winmm.lib;DWMApi.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <OutputFile>$(OutDir)STed2.exe</OutputFile>
+      <IgnoreSpecificDefaultLibraries>%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <SubSystem>Windows</SubSystem>
+      <OptimizeReferences>true</OptimizeReferences>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <None Include="STed2.ico" />
+    <None Include="small.ico" />
+  </ItemGroup>
+  <ItemGroup>
+    <ResourceCompile Include="STed2.rc" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClInclude Include="acconfig.h" />
+    <ClInclude Include="config.h" />
+    <ClInclude Include="doslib.h" />
+    <ClInclude Include="exception.h" />
+    <ClInclude Include="gettext_wrapper.h" />
+    <ClInclude Include="graph.h" />
+    <ClInclude Include="iocslib.h" />
+    <ClInclude Include="machin.h" />
+    <ClInclude Include="mididev.h" />
+    <ClInclude Include="midi_in.h" />
+    <ClInclude Include="netbsdgetopt.h" />
+    <ClInclude Include="nkflib.h" />
+    <ClInclude Include="rcddef.h" />
+    <ClInclude Include="rcp.h" />
+    <ClInclude Include="rcpconv.h" />
+    <ClInclude Include="rcpdef.h" />
+    <ClInclude Include="rcpfile.h" />
+    <ClInclude Include="rcpstruct.h" />
+    <ClInclude Include="rcp_functions.h" />
+    <ClInclude Include="resource.h" />
+    <ClInclude Include="sf_com.h" />
+    <ClInclude Include="sf_memory.h" />
+    <ClInclude Include="sf_windows.h" />
+    <ClInclude Include="singleton.h" />
+    <ClInclude Include="smf.h" />
+    <ClInclude Include="smfplay.h" />
+    <ClInclude Include="snprintf.h" />
+    <ClInclude Include="stdafx.h" />
+    <ClInclude Include="sted.h" />
+    <ClInclude Include="STed2.h" />
+    <ClInclude Include="sted2header.h" />
+    <ClInclude Include="sted3.h" />
+    <ClInclude Include="sted_c.h" />
+    <ClInclude Include="sted_dialogs.h" />
+    <ClInclude Include="sted_screen.h" />
+    <ClInclude Include="sted_screen_win32.h" />
+    <ClInclude Include="sted_win32.h" />
+    <ClInclude Include="version.h" />
+    <ClInclude Include="x68defines.h" />
+    <ClInclude Include="x68funcs.h" />
+  </ItemGroup>
+  <ItemGroup>
+    <ClCompile Include="assign.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="basic.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="cm6con.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="defload.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="disp.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="dlg_mididevice.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="dos.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="edit.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="edits.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="exception.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="exclu.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="file.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="graph.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="graphic.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="hprint.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="iocs.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="iocs_console.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="iocs_graph.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="iocs_key.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="iocs_mouse.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="iocs_tgraph.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="itor.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="key_sub.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="mcpy.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="mididev.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="midi_in.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="mkeyb.cpp" />
+    <ClCompile Include="nkflib.cpp" />
+    <ClCompile Include="ongraph.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="rcdcheck.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="rcpconv.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="rcpfile.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="rcpplay.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="rcptomid.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="rcp_functions.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="record.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="redit.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="scdsp.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="score.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="select.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="sf_com.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="sf_windows.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="smf.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="smffile.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="snprintf.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="stdafx.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="sted.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="STed2.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Use</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="sted_screen.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="sted_vals.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="track.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="trkset.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="visual.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_color.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_file.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_graphics.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_key.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_midi.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_misc.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_pointer.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_text.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="win32_win.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+    <ClCompile Include="x68funcs.cpp">
+      <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">NotUsing</PrecompiledHeader>
+    </ClCompile>
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>
\ No newline at end of file
diff --git a/STedX.sln b/STedX.sln
new file mode 100644 (file)
index 0000000..c7fd6b7
--- /dev/null
+++ b/STedX.sln
@@ -0,0 +1,25 @@
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Express 2012 for Windows Desktop
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "STed2", "STed2.vcxproj", "{8BA3E9BF-1BAD-47F0-AA7B-71D719222028}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Debug|x64 = Debug|x64
+               Release|Win32 = Release|Win32
+               Release|x64 = Release|x64
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Debug|Win32.ActiveCfg = Debug|Win32
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Debug|Win32.Build.0 = Debug|Win32
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Debug|x64.ActiveCfg = Debug|x64
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Debug|x64.Build.0 = Debug|x64
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Release|Win32.ActiveCfg = Release|Win32
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Release|Win32.Build.0 = Release|Win32
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Release|x64.ActiveCfg = Release|x64
+               {8BA3E9BF-1BAD-47F0-AA7B-71D719222028}.Release|x64.Build.0 = Release|x64
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/acconfig.h b/acconfig.h
new file mode 100644 (file)
index 0000000..c029f58
--- /dev/null
@@ -0,0 +1,26 @@
+#pragma once
+
+#undef PACKAGE
+#undef VERSION
+#undef HAVE_CATGETS
+#undef HAVE_GETTEXT
+#undef HAVE_LC_MESSAGES
+#undef HAVE_STPCPY
+#undef ENABLE_NLS
+#undef NO_SHM
+#undef USE_CURSES
+#undef STED_DEFAULT_PATH
+#undef STED
+#undef HAS_CURSES
+#undef USE_SUNOS_CURSES
+#undef USE_BSD_CURSES
+#undef USE_SYSV_CURSES
+#undef USE_NCURSES
+#undef NO_COLOR_CURSES
+#undef SCO_FLAVOR
+#undef NCURSES_970530
+#undef NO_SETLOCALE
+#undef NO_XSETLOCALE
+#undef NO_XLOCALE
+#undef SJIS_CODES
+#undef HAVE_MVWCHGAT
diff --git a/acinclude.m4 b/acinclude.m4
new file mode 100644 (file)
index 0000000..dbc3bc9
--- /dev/null
@@ -0,0 +1,318 @@
+dnl Curses detection: Munged from Midnight Commander's configure.in
+dnl
+dnl What it does:
+dnl =============
+dnl
+dnl - Determine which version of curses is installed on your system
+dnl   and set the -I/-L/-l compiler entries and add a few preprocessor
+dnl   symbols 
+dnl - Do an AC_SUBST on the CURSES_INCLUDEDIR and CURSES_LIBS so that
+dnl   @CURSES_INCLUDEDIR@ and @CURSES_LIBS@ will be available in
+dnl   Makefile.in's
+dnl - Modify the following configure variables (these are the only
+dnl   curses.m4 variables you can access from within configure.in)
+dnl   CURSES_INCLUDEDIR - contains -I's and possibly -DRENAMED_CURSES if
+dnl                       an ncurses.h that's been renamed to curses.h
+dnl                       is found.
+dnl   CURSES_LIBS       - sets -L and -l's appropriately
+dnl   CFLAGS            - if --with-sco, add -D_SVID3 
+dnl   has_curses        - exports result of tests to rest of configure
+dnl
+dnl Usage:
+dnl ======
+dnl 1) Add lines indicated below to acconfig.h
+dnl 2) call AC_CHECK_CURSES after AC_PROG_CC in your configure.in
+dnl 3) Instead of #include <curses.h> you should use the following to
+dnl    properly locate ncurses or curses header file
+dnl
+dnl    #if defined(USE_NCURSES) && !defined(RENAMED_NCURSES)
+dnl    #include <ncurses.h>
+dnl    #else
+dnl    #include <curses.h>
+dnl    #endif
+dnl
+dnl 4) Make sure to add @CURSES_INCLUDEDIR@ to your preprocessor flags
+dnl 5) Make sure to add @CURSES_LIBS@ to your linker flags or LIBS
+dnl
+dnl Notes with automake:
+dnl - call AM_CONDITIONAL(HAS_CURSES, test "$has_curses" = true) from
+dnl   configure.in
+dnl - your Makefile.am can look something like this
+dnl   -----------------------------------------------
+dnl   INCLUDES= blah blah blah $(CURSES_INCLUDEDIR) 
+dnl   if HAS_CURSES
+dnl   CURSES_TARGETS=name_of_curses_prog
+dnl   endif
+dnl   bin_PROGRAMS = other_programs $(CURSES_TARGETS)
+dnl   other_programs_SOURCES = blah blah blah
+dnl   name_of_curses_prog_SOURCES = blah blah blah
+dnl   other_programs_LDADD = blah
+dnl   name_of_curses_prog_LDADD = blah $(CURSES_LIBS)
+dnl   -----------------------------------------------
+dnl
+dnl
+dnl The following lines should be added to acconfig.h:
+dnl ==================================================
+dnl
+dnl /*=== Curses version detection defines ===*/
+dnl /* Found some version of curses that we're going to use */
+dnl #undef HAS_CURSES
+dnl    
+dnl /* Use SunOS SysV curses? */
+dnl #undef USE_SUNOS_CURSES
+dnl 
+dnl /* Use old BSD curses - not used right now */
+dnl #undef USE_BSD_CURSES
+dnl 
+dnl /* Use SystemV curses? */
+dnl #undef USE_SYSV_CURSES
+dnl 
+dnl /* Use Ncurses? */
+dnl #undef USE_NCURSES
+dnl 
+dnl /* If you Curses does not have color define this one */
+dnl #undef NO_COLOR_CURSES
+dnl 
+dnl /* Define if you want to turn on SCO-specific code */
+dnl #undef SCO_FLAVOR
+dnl 
+dnl /* Set to reflect version of ncurses *
+dnl  *   0 = version 1.*
+dnl  *   1 = version 1.9.9g
+dnl  *   2 = version 4.0/4.1 */
+dnl #undef NCURSES_970530
+dnl
+dnl /*=== End new stuff for acconfig.h ===*/
+dnl 
+
+
+AC_DEFUN(AC_CHECK_CURSES,[
+       search_ncurses=true
+       screen_manager=""
+       has_curses=false
+
+       CFLAGS=${CFLAGS--O}
+
+       AC_SUBST(CURSES_LIBS)
+       AC_SUBST(CURSES_INCLUDEDIR)
+
+       AC_ARG_WITH(sco,
+         [  --with-sco              Use this to turn on SCO-specific code],[
+         if test x$withval = xyes; then
+               AC_DEFINE(SCO_FLAVOR)
+               CFLAGS="$CFLAGS -D_SVID3"
+         fi
+       ])
+
+       AC_ARG_WITH(sunos-curses,
+         [  --with-sunos-curses     Used to force SunOS 4.x curses],[
+         if test x$withval = xyes; then
+               AC_USE_SUNOS_CURSES
+         fi
+       ])
+
+       AC_ARG_WITH(osf1-curses,
+         [  --with-osf1-curses      Used to force OSF/1 curses],[
+         if test x$withval = xyes; then
+               AC_USE_OSF1_CURSES
+         fi
+       ])
+
+       AC_ARG_WITH(vcurses,
+         [  --with-vcurses[=incdir] Used to force SysV curses],
+         if test x$withval != xyes; then
+               CURSES_INCLUDEDIR="-I$withval"
+         fi
+         AC_USE_SYSV_CURSES
+       )
+
+       AC_ARG_WITH(ncurses,
+         [  --with-ncurses[=dir]    Compile with ncurses/locate base dir],
+         if test x$withval = xno ; then
+               search_ncurses=false
+         elif test x$withval != xyes ; then
+               CURSES_LIBS="$LIBS -L$withval/lib -lncurses"
+               CURSES_INCLUDEDIR="-I$withval/include"
+               search_ncurses=false
+               screen_manager="ncurses"
+               AC_DEFINE(USE_NCURSES)
+               AC_DEFINE(HAS_CURSES)
+               has_curses=true
+         fi
+       )
+
+       if $search_ncurses
+       then
+               AC_SEARCH_NCURSES()
+       fi
+
+
+])
+
+
+AC_DEFUN(AC_USE_SUNOS_CURSES, [
+       search_ncurses=false
+       screen_manager="SunOS 4.x /usr/5include curses"
+       AC_MSG_RESULT(Using SunOS 4.x /usr/5include curses)
+       AC_DEFINE(USE_SUNOS_CURSES)
+       AC_DEFINE(HAS_CURSES)
+       has_curses=true
+       AC_DEFINE(NO_COLOR_CURSES)
+       AC_DEFINE(USE_SYSV_CURSES)
+       CURSES_INCLUDEDIR="-I/usr/5include"
+       CURSES_LIBS="/usr/5lib/libcurses.a /usr/5lib/libtermcap.a"
+       AC_MSG_RESULT(Please note that some screen refreshs may fail)
+])
+
+AC_DEFUN(AC_USE_OSF1_CURSES, [
+       AC_MSG_RESULT(Using OSF1 curses)
+       search_ncurses=false
+       screen_manager="OSF1 curses"
+       AC_DEFINE(HAS_CURSES)
+       has_curses=true
+       AC_DEFINE(NO_COLOR_CURSES)
+       AC_DEFINE(USE_SYSV_CURSES)
+       CURSES_LIBS="-lcurses"
+])
+
+AC_DEFUN(AC_USE_SYSV_CURSES, [
+       AC_MSG_RESULT(Using SysV curses)
+       AC_DEFINE(HAS_CURSES)
+       has_curses=true
+       AC_DEFINE(USE_SYSV_CURSES)
+       search_ncurses=false
+       screen_manager="SysV/curses"
+       CURSES_LIBS="-lcurses"
+])
+
+dnl AC_ARG_WITH(bsd-curses,
+dnl [--with-bsd-curses         Used to compile with bsd curses, not very fancy],
+dnl    search_ncurses=false
+dnl    screen_manager="Ultrix/cursesX"
+dnl    if test $system = ULTRIX
+dnl    then
+dnl        THIS_CURSES=cursesX
+dnl        else
+dnl        THIS_CURSES=curses
+dnl    fi
+dnl
+dnl    CURSES_LIBS="-l$THIS_CURSES -ltermcap"
+dnl    AC_DEFINE(HAS_CURSES)
+dnl    has_curses=true
+dnl    AC_DEFINE(USE_BSD_CURSES)
+dnl    AC_MSG_RESULT(Please note that some screen refreshs may fail)
+dnl    AC_WARN(Use of the bsdcurses extension has some)
+dnl    AC_WARN(display/input problems.)
+dnl    AC_WARN(Reconsider using xcurses)
+dnl)
+
+       
+dnl
+dnl Parameters: directory filename cureses_LIBS curses_INCLUDEDIR nicename
+dnl
+AC_DEFUN(AC_NCURSES, [
+    if $search_ncurses
+    then
+        if test -f $1/$2
+       then
+           AC_MSG_RESULT(Found ncurses on $1/$2)
+           CURSES_LIBS="$3"
+           CURSES_INCLUDEDIR="$4"
+           search_ncurses=false
+           screen_manager=$5
+            AC_DEFINE(HAS_CURSES)
+            has_curses=true
+           AC_DEFINE(USE_NCURSES)
+       fi
+    fi
+])
+
+AC_DEFUN(AC_SEARCH_NCURSES, [
+    AC_CHECKING("location of ncurses.h file")
+
+    AC_NCURSES(/usr/include, ncurses.h, -lncurses,, "ncurses on /usr/include")
+    AC_NCURSES(/usr/include/ncurses, ncurses.h, -lncurses, -I/usr/include/ncurses, "ncurses on /usr/include/ncurses")
+    AC_NCURSES(/usr/local/include, ncurses.h, -L/usr/local/lib -lncurses, -I/usr/local/include, "ncurses on /usr/local")
+    AC_NCURSES(/usr/local/include/ncurses, ncurses.h, -L/usr/local/lib -L/usr/local/lib/ncurses -lncurses, -I/usr/local/include/ncurses, "ncurses on /usr/local/include/ncurses")
+
+    AC_NCURSES(/usr/local/include/ncurses, curses.h, -L/usr/local/lib -lncurses, -I/usr/local/include/ncurses -DRENAMED_NCURSES, "renamed ncurses on /usr/local/.../ncurses")
+
+    AC_NCURSES(/usr/include/ncurses, curses.h, -lncurses, -I/usr/include/ncurses -DRENAMED_NCURSES, "renamed ncurses on /usr/include/ncurses")
+
+    dnl
+    dnl We couldn't find ncurses, try SysV curses
+    dnl
+    if $search_ncurses 
+    then
+        AC_EGREP_HEADER(init_color, /usr/include/curses.h,
+           AC_USE_SYSV_CURSES)
+       AC_EGREP_CPP(USE_NCURSES,[
+#include <curses.h>
+#ifdef __NCURSES_H
+#undef USE_NCURSES
+USE_NCURSES
+#endif
+],[
+       CURSES_INCLUDEDIR="$CURSES_INCLUDEDIR -DRENAMED_NCURSES"
+        AC_DEFINE(HAS_CURSES)
+       has_curses=true
+        AC_DEFINE(USE_NCURSES)
+        search_ncurses=false
+        screen_manager="ncurses installed as curses"
+])
+    fi
+
+    dnl
+    dnl Try SunOS 4.x /usr/5{lib,include} ncurses
+    dnl The flags USE_SUNOS_CURSES, USE_BSD_CURSES and BUGGY_CURSES
+    dnl should be replaced by a more fine grained selection routine
+    dnl
+    if $search_ncurses
+    then
+       if test -f /usr/5include/curses.h
+       then
+           AC_USE_SUNOS_CURSES
+        fi
+    else
+        # check for ncurses version, to properly ifdef mouse-fix
+       AC_MSG_CHECKING(for ncurses version)
+       ncurses_version=unknown
+cat > conftest.$ac_ext <<EOF
+[#]line __oline__ "configure"
+#include "confdefs.h"
+#ifdef RENAMED_NCURSES
+#include <curses.h>
+#else
+#include <ncurses.h>
+#endif
+#undef VERSION
+VERSION:NCURSES_VERSION
+EOF
+        if (eval "$ac_cpp conftest.$ac_ext") 2>&AC_FD_CC |
+  egrep "VERSION:" >conftest.out 2>&1; then
+changequote(,)dnl
+            ncurses_version=`cat conftest.out|sed -e 's/^[^"]*"//' -e 's/".*//'`
+changequote([,])dnl
+       fi
+       rm -rf conftest*
+        AC_MSG_RESULT($ncurses_version)
+       case "$ncurses_version" in
+changequote(,)dnl
+       4.[01])
+changequote([,])dnl
+            AC_DEFINE(NCURSES_970530,2)
+            ;;
+       1.9.9g)
+            AC_DEFINE(NCURSES_970530,1)
+            ;;
+       1*)
+            AC_DEFINE(NCURSES_970530,0)
+            ;;
+       esac
+    fi
+])
+
+
+
+
+
diff --git a/assign.cpp b/assign.cpp
new file mode 100644 (file)
index 0000000..da46d7c
--- /dev/null
@@ -0,0 +1,940 @@
+/*
+ * STed: assign.c (assign)
+ */
+//#include "stdafx.h"
+
+#include       "sted.h"
+
+static char    *filter_name[14]={
+  "PROGRAM CHANGE",
+  "PITCH BEND",
+  "AFTER TOUCH(CH. )",
+  "AFTER TOUCH(POLY)",
+  "PEDAL(HOLD1)",
+  "MODULATION",
+  /*           "BREATH",2*/
+  "VOLUME",
+  "EXPRESSION",
+  /*           "PANPOT",10*/
+  "ALL NOTE OFF",
+  "CONTROL CHANGE",
+  "EXCLUSIVE MESSAGE",
+  "KEY# H:    L:",
+  "KEY SHIFT   :",
+  "VELOCITY    :",
+};
+/*
+DISPLAY              
+GATE TIME (GT)   :
+VELOCITY  (VEL)  :
+PITCH BEND       :
+VOLUME           :
+MODULATION       :
+EXPRESSION       :
+NOTE HEAD        :
+NOTE HOOK        :
+TIME SCALE x 2   :
+QUANTIZE  (6)    :
+TEMPO            :
+*/
+
+unsigned char  stgt_name[10][4]={
+  "æ^","æ_","æ`","æa","æb","æc","æd","æe","æf","æh"};
+
+/***************************/
+void   rhy_as()
+{
+  int  a,i,j,xx,x=0,y=0,f,gy,sh;
+  char tmp1[256];
+  int  rno[32];
+
+  for(i=0;i<32;i++){rno[i]=rhyno[i][0];}
+
+  gy=scyp;
+  fill(0,544,767,1023,0);
+top:
+  fill(2,666,564,708,14);box(2,708,564,986,14,65535);
+  box(4,710,282,984,14,65535);box(284,710,562,984,14,65535);
+  box(6,618,200+80,660,14,65535);box(8,620,198+80,658,14,65535);
+  home2(512);
+  rhy_as_para();
+
+  es=0;B_COLOR(3);
+
+  B_LOCATE(1,10);B_PRINT("RHYTHM ASSIGN");B_LOCATE(1,11);
+  B_PRINT(" NO RHYTHM NAME     K#         GT  ");
+  B_PRINT(" NO RHYTHM NAME     K#         GT  ");
+redis:
+  for(i=0;i<32;i++){
+    int        a;
+    B_LOCATE((i>>4)*35+2,(i&15)+13);
+    B_PRINT(fstr(i+1,2));B_PRINT(":");B_PRINT(spadd(rhyna[i],14));
+    a=rhyno[i][0];
+    if(a==0){
+      B_PRINT(" OFF      ");
+    }else{
+      B_PRINT(fstr(a,4));B_PRINT(" (");
+      B_PRINT(keystr(a));B_PRINT(")");
+    }
+    B_PRINT(fstr(rhyno[i][1],5));
+  }
+
+ass_ret:
+  while( 1){
+    if(x<3){f=0;}else{f=1;}
+    i=y+f*16;xx=f*35+5;f=x-f*3;
+
+    j=3;
+    if( f==0 ){
+      j=14;
+    }else{
+      if( f==1 ){xx=xx+15;}else{xx=xx+26;}
+    }
+
+    tcur(xx,y+13,j,3);
+    a=inkey2();sh=B_SFTSNS();
+    if(a>='a' && a<='z'){a=a-32;}
+
+    if(a==0x15){
+      int a;
+      a=rhy_stest[2];if(gs_mode[16]&4){a*=256;}
+      s_test(rhy_stest[0],a,rhy_stest[1],rhyno[i][0],rhy_stest[4]);
+
+    }
+    if(a=='r'||a=='R'){s_test(11,-1,64,rhyno[i][0],rhy_stest[4]);}
+    if(a=='e'||a=='E'){s_test(11,-1,65,rhyno[i][0],rhy_stest[4]);}
+
+    tcur(xx,y+13,j,3);
+
+    if( a==0x05 ){y--;if( y<0 ){y=15;}}
+    if( a==0x18 ){y++;if( y>15 ){y=0;}}
+    if( a==0x13 ){x--;if( x<0 ){x=5;}}
+    if( a==0x04 ){x++;if( x>5 ){x=0;}}
+    if( a==0x0b ){y=0;x=0;goto redis;}
+
+    if( a==9 ){
+      msg("No.=");j=vinput(f*16+y+1,0x802);msg_clr();
+      if(es==0 && j>0 && j<=32){j-=1;x=(j>>4)*3;y=j&15;}
+
+    }
+    if( a==12 ){
+      msg(_("Initialize assign"));
+      if(yn_sel()>0){msg_clr();rhinit();goto redis;}
+    }
+    if( a==32 ){
+      rhinit2(i);goto redis;
+    }
+    if(a=='C'){
+      int n;
+      char     tmp0[64];
+
+      B_LOCATE(6,7);
+      strcpy(tmp0,chstr(rhy_stest[0]));
+      sinput(tmp0,0x803);n=strch(rhy_stest[0],tmp0);
+      /* May.06.2001 NAGANO Daisuke <breeze.nagano@nifty.ne.jp> */
+      if ( issted3 ) {
+       if(es==0 && n>=0 && n<=STED3_MAX_PORT_NUMBER*16){rhy_stest[0]=n;}
+      }
+      else {
+       if(es==0 && n>=0 && n<=32){rhy_stest[0]=n;}
+      }
+      rhy_as_para();
+    }
+    if(a=='B'){
+      int n;
+
+      n=rhy_stest[2];
+      B_LOCATE(21,7);n=vinput(n,0x803);
+      if(es==0 && n>=-1 && n<=127){rhy_stest[2]=n;}
+      rhy_as_para();
+    }
+    if(a=='V'){
+      int n;
+
+      n=rhy_stest[4];
+      B_LOCATE(29,7);n=vinput(n,0x803);
+      if(es==0 && n>=0 && n<=127){rhy_stest[4]=n;}
+      rhy_as_para();
+    }
+    if(a=='G'){
+      int n;
+      if((cmdflag&0x1000)==0){goto retimsel;}
+    timnore:
+      n=rhy_stest[1];
+      if((cmdflag&0x20)!=0 ){n++;}
+      B_LOCATE(6,8);n=vinput(n,0xb03);
+      if((cmdflag&0x20)!=0 ){n--;}
+
+      if(es==0){
+       if(ecode==0x18){
+         int a;
+       retimsel:
+         /*                                    if(rhy_stest[2]>=0){a=rhy_stest[2]*256;}*/
+
+         a=0;
+         if(rhy_stest[2]>=0){
+           a=rhy_stest[2];if(gs_mode[16]&4){a*=256;}
+         }
+
+         n=timsel(rhy_stest[0],a,36,rhy_stest[1]);
+
+         if(n<0){goto timnore;}
+         if(n>=0){n=n&0xff;}
+       }
+       if(n>=-1 && n<128){rhy_stest[1]=n;}
+      }
+      rhy_as_para();
+    }
+
+    if( a==13 ){
+      int      n;
+    timnore2:
+      B_LOCATE(xx,y+13);
+      if( f==0 ){
+       sinput(rhyna[i],14);
+      }else{
+       if( f==1 ){
+         b_striS(tmp1,256,rhyno[i][0]);sinput(tmp1,0xb03);
+         if(es==0){
+           n=ctc(rhyno[i][0],tmp1,0);
+           if(ecode==0x18){
+             tdis(xx,(i&15)+13,tmp1,j,11);
+             n=rhy_stest[1];if(n<0){n=0;}
+             if(rhy_stest[2]>=0){n+=rhy_stest[2]*256;}
+             n=timsel(rhy_stest[0]+0x100,n,36,0);
+             if(n<0){goto timnore2;}
+           }
+           if( n>=0 && n<128 ){
+             int as,bk;
+             rhyno[i][0]=n;
+             as=tim_asin[rhy_stest[0]];
+             bk=rhy_stest[1];
+             if(as==8 || as==10 || as==12 || as==14){
+               varia(tmp1,bk,n,as);
+               tmp1[15]=0;strcpy(rhyna[i],tmp1+1);
+             }
+             if(as==2 && n){
+               if(n>=24){
+                 strcpy(rhyna[i],tim_name[cm6[0x130+(n-24)*4]+128]);
+               }else{
+                 rhyna[i][0]=0;
+               }
+             }
+           }
+         }
+       }else{
+         n=vinput(rhyno[i][1],0x803);
+         if( n>=0 && n<=255){rhyno[i][1]=n;}
+       }
+      }
+      goto redis;
+    }
+
+    if( a>='0' && a<='9' ){
+      int      n;
+    timnore3:
+      B_LOCATE(xx,y+13);
+      if( f==0 ){
+       /*sinput(rhyna[i],14);*/
+      }else{
+       if( f==1 ){
+         tmp1[0]=a;tmp1[1]=0;sinput(tmp1,0x603);
+         if(es==0){
+           n=ctc(rhyno[i][0],tmp1,0);
+           if(ecode==0x18){
+             tdis(xx,(i&15)+13,tmp1,j,11);
+             n=rhy_stest[1];if(n<0){n=0;}
+             if(rhy_stest[2]>=0){n+=rhy_stest[2]*256;}
+             n=timsel(rhy_stest[0]+0x100,n,36,0);
+             if(n<0){goto timnore3;}
+           }
+           if( n>=0 && n<128 ){rhyno[i][0]=n;}
+         }
+       }else{
+         n=vinput(a-'0',0x403);
+         if( n>=0 && n<=255){rhyno[i][1]=n;}
+       }
+      }
+      goto redis;
+    }
+
+
+    if( (a=='+' || a=='>' || a=='.') && f>0 ){
+      int n=rhyno[i][f-1];
+      if(sh&1){n+=12;}else{n++;}
+      if( f==1 ){n=n&127;}else{n=n&255;}
+      rhyno[i][f-1]=n;
+      goto redis;
+    }
+    if( (a=='-' || a=='<' || a==',') && f>0 ){
+      int n=rhyno[i][f-1];
+      if(sh&1){n+=244;}else{n+=255;}
+      if( f==1 ){n=n&127;}else{n=n&255;}
+      rhyno[i][f-1]=n;
+      goto redis;
+    }
+
+    if( a=='L' ){
+      char     tmp0[256],tmp1[256],path2[256];
+
+      C_CLS_AL();
+
+      strcpy(path2,prt_path);tmp1[0]=0;
+      fsel(tmp1,path2,0x00b);
+      if( es==0 && tmp1[0]!=0){
+       strcpy(tmp0,path2);strcat(tmp0,tmp1);
+       msg(_("Loading Rhythm assign file"));
+       if(ras_load(tmp0)==0 ){msg_clr();
+       if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+       }
+      }
+      goto top;
+    }
+    if( a=='S' ){
+      char     tmp0[256],tmp1[256],path2[256];
+
+      C_CLS_AL();
+
+      strcpy(path2,prt_path);tmp1[0]=0;
+      fsel(tmp1,path2,0x10b);
+      if( es==0 && tmp1[0]!=0){
+       strcpy(tmp0,path2);strcat(tmp0,tmp1);
+       msg(_("Saving Rhythm assign file"));
+       if(ras_save(tmp0)==0 ){msg_clr();
+       if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+       }
+      }
+      goto top;
+    }
+
+    if(a=='A'){
+      int i,n,a;
+      msg(_("Change all rhythm name"));
+      a=yn_sel();msg_clr();if(a==0){goto ass_ret;}
+
+      for(i=0;i<32;i++){
+       n=rhyno[i][0];
+       if( n>=0 && n<128 /*&& rhyno[i][1]!=0*/){
+         int as,bk;
+         as=tim_asin[rhy_stest[0]];
+         bk=rhy_stest[1];
+         if(rhy_stest[2]>=0){bk+=rhy_stest[2]*256;}
+
+         if(as==8 || as==10 || as==12 || as==14){
+           varia(tmp1,bk,n,as);
+           tmp1[15]=0;strcpy(rhyna[i],tmp1+1);
+         }
+         if(as==2 && n){
+           if(n>=24){
+             strcpy(rhyna[i],tim_name[cm6[0x130+(n-24)*4]+128]);
+           }else{
+             rhyna[i][0]=0;
+           }
+         }
+       }else{
+         strcpy(rhyna[i],"");
+       }
+      }
+      goto redis;
+    }
+
+    if(a=='X'){
+      int ex,n;
+      char tmp0[128];
+      B_LOCATE(35,6);B_PRINT("ExChange Rhythm Data");
+      B_LOCATE(52,7);B_PRINT("Source No.=");B_PRINT(fstr(i+1,2));
+      B_LOCATE(48,8);B_PRINT("Distnation No.=");
+    exc1:                      ex=rhy_as_sel(i);if(ex==i){goto exc1;}
+    txerase(35*8,6*16,40*8,3*16);
+
+    if(ex>=0){
+      n=rhyno[i][0];rhyno[i][0]=rhyno[ex][0];rhyno[ex][0]=n;
+      n=rhyno[i][1];rhyno[i][1]=rhyno[ex][1];rhyno[ex][1]=n;
+
+      strcpy(tmp0,rhyna[i]);strcpy(rhyna[i],rhyna[ex]);
+      strcpy(rhyna[ex],tmp0);
+
+      goto redis;
+    }
+    }
+
+    if( a==27 ){
+      int i,j,f;
+      f=0;
+      for(i=0;i<31;i++){
+       for(j=i+1;j<32;j++){
+         if(rhyno[i][0]==rhyno[j][0] && rhyno[i][0]!=0){
+           f++;
+         }
+       }
+      }
+      if( f==0 ){break;}
+      msg(_("Find repetition of key number. Ok"));
+      if(yn_sel()<1){msg_clr();goto redis;}
+      break;
+
+    }
+  }
+
+  f=0;
+  for(i=0;i<32;i++){if(rno[i]!=rhyno[i][0]){f=1;}}
+
+  if(f!=0 && (cmdflag&0x800)==0){
+    int a=1;
+    if((cmdflag&0x400)==0){
+      msg(_("Replace all track datas"));
+      a=yn_sel();if(a==0){msg_clr();goto ass_ret;}
+    }
+    if(a>0){
+      int      i,j,n;
+      msg(_("Now processing ..."));
+      for(i=0;i<36;i++){
+       if((trrhy[i]&128)!=0){
+         for(j=0;j<tr_len[i];j=j+4){
+           unsigned char       a=trk[i][j];
+           if(a<128 && a!=0 && trk[i][j+2]>0 && trk[i][j+3]>0){
+             n=0;while(n<32){
+               if(a==rno[n] && rhyno[n][0]!=0){
+                 trk[i][j]=rhyno[n][0];
+                 break;
+               }
+               n++;
+             }
+           }
+         }
+       }
+      }
+    }
+  }
+  msg_clr();
+  B_CLR_AL();home2(gy);
+}
+
+/***************************/
+int    rhy_as_sel(int no)
+{
+  int  a,j,xx,x,y;
+
+  x=no>>4;y=no&15;
+
+  while( 1){
+    xx=x*35+1;
+
+    tcur(xx,y+13,3,3);
+    a=inkey2();
+    tcur(xx,y+13,3,3);
+
+    if( a==0x05 ){y--;if( y<0 ){y=15;}}
+    if( a==0x18 ){y++;if( y>15 ){y=0;}}
+    if( a==0x13 ){x--;if( x<0 ){x=1;}}
+    if( a==0x04 ){x++;if( x>1 ){x=0;}}
+    if( a==0x0b ){y=0;x=0;}
+
+    if( a==9 ){
+      msg("No.=");j=vinput(x*16+y+1,0x802);msg_clr();
+      if(es==0 && j>0 && j<=32){j-=1;x=j>>4;y=j&15;}
+    }
+    if( a==13 ){return x*16+y;}
+    if( a==27 ){return -1;}
+
+  }
+}
+
+/***************************/
+void   rhy_as_para()
+{
+  B_LOCATE(2,7);B_PRINT("CH.=");B_PRINT(chstr(rhy_stest[0]));
+  B_LOCATE(11,7);
+  if(gs_mode[16]&4){
+    B_PRINT("BANK LSB=");
+  }else{
+    B_PRINT("BANK MSB=");
+  }
+  B_PRINT(fstr(rhy_stest[2],3));
+
+  B_LOCATE(25,7);B_PRINT("VEL=");B_PRINT(fstr(rhy_stest[4],3));
+
+  B_LOCATE(2,8);B_PRINT("PRG=");
+  B_PRINT(prog_name(rhy_stest[0],rhy_stest[2]*256,rhy_stest[1],1));
+}
+
+/***************************/
+int    tagj(int *po,int fl)
+{
+  int  a,i,y=0;
+  char tmp0[128];
+
+  fill(315,566,453,1001,0);
+  box(316,588-16,444,999,14,65535);
+  box(317,626-16,443,998,14,65535);
+  fill(316,588-16,444,626-16,14);
+
+  es=0;
+  B_LOCATE(40,4);if(fl==0){B_PRINT("### TAG JUMP ##");}else{B_PRINT("### TAG SET ###");}
+  B_LOCATE(40,5);B_PRINT("NO.TR MEAS  ST ");
+
+  B_COLOR(3);
+
+  for(i=0 ;i<23;i++){
+    strcpy(tmp0," : ");tmp0[0]=i+'A';if(i==22){tmp0[0]=32;}
+
+    if(tag[i][0]>=0){
+      if(tag[i][0]<255){
+       strcat(tmp0,fstr(tag[i][0]+1,2));
+      }else{
+       strcat(tmp0,"--");
+      }
+      strcat(tmp0,fstr(tag[i][1],5));strcat(tmp0,fstr(tag[i][2],5));
+    }
+    B_LOCATE(40,i+7);B_PRINT(tmp0);
+  }
+  while( 1){
+    tmp0[0]=0;
+    if(tag[y][0]>=0){
+      if(tag[y][0]<255){
+       strcpy(tmp0,fstr(tag[y][0]+1,3));
+      }else{
+       strcpy(tmp0," --");
+      }
+      strcat(tmp0,fstr(tag[y][1],5));strcat(tmp0,fstr(tag[y][2],5));
+    }
+    tdis(42,y+7,tmp0,13,11);
+    a=inkey2();
+    tdis(42,y+7,tmp0,13,3);
+
+    if(a>='A' && a<='V'){y=a-'A';}
+    if(a>='a' && a<='v'){y=a-'a';}
+    if( a==0x05 ){y--;if( y<0 ){y=22;}}
+    if( a==0x18 ){y++;if( y>22 ){y=0;}}
+    if( a==0x0b ){y=0;break;}
+    if( a==13 || a==32 ){es= 0;break;}
+    if( a==27 ){es= 1;break;}
+  }
+  txerase(40*8,5*16-16,20*8,25*16+16);
+  fill(315,587-16,445,1001,0);
+
+  if( es==0 ){
+    if( fl==0 ){
+      if(tag[y][0]>=0){
+
+       tag[22][0]=track;tag[22][1]=meas_no(*po);
+       tag[22][2]=sttm_no(*po);
+
+       if(tag[y][0]<255){track=tag[y][0];}
+       *po=meas_add(tag[y][1]);
+       if(*po<0){
+         *po=tr_len[track]-4;
+       }else{
+         i=tag[y][2];*po=sttm_ad(*po,i);
+       }
+      }else{es=1;}
+    }else{
+      if(a==13){tag[y][0]=track;}else{tag[y][0]=255;}
+      tag[y][1]=meas_no(*po);tag[y][2]=sttm_no(*po);
+    }
+  }
+  return(es);
+}
+
+/***************************/
+ void  part_as()
+{
+  int  ke,sh,i,j,x=0,y=0,scr,gy;
+  char tmp[128];
+
+  gy=scyp;
+  scr=edit_scr;edit_scr=0;
+
+  fill(0,512+32,767,1023,0);
+  box(15,116+512,496,411+512,14,65535);
+  box(17,133+512,494,409+512,14,65535);
+  sdis(2, 84+512," PART ASSIGN",13,15,8);
+  sdis(2 ,116+512," CH.  PART NAME",30,15,14);
+  sdis(32,116+512," CH.  PART NAME",30,15,14);
+  home2(512);
+top:
+  for(i=1;i<17;i++){
+    for(j=0;j<2;j++){
+      strcpy(tmp,chstr(i+j*16));
+      tdis(3+j*30,8+i,tmp,3,3);
+
+      ke=tim_asin[i+j*16];
+      if(ke!=0){strcpy(tmp,tim_head[ke-1]);}
+      else{strcpy(tmp,"No Assign");}
+      tdis(8+j*30,8+i,tmp,20,3);
+    }
+  }
+
+  while( 1){
+    int nn=y+x*16+1;
+    ke=tim_asin[nn];
+    if(ke!=0){strcpy(tmp,tim_head[ke-1]);}
+    else{strcpy(tmp,"No Assign");}
+
+    tdis(x*30+8,9+y,tmp,20,11);
+    ke=inkey2();sh=B_SFTSNS();
+    tdis(x*30+8,9+y,tmp,20,3);
+
+    if(sh&4){
+      int      ex;
+      char     t[32];
+      t[0]=ke;t[1]=0;
+      ex=str_search("1234567890,./*-+=\x0d",t);
+      if(ex>0 && ex<19){ex--;x=ex>>4;y=ex&15;ke=0;}
+    }
+
+    if( ke==27 ){break;}
+    if( ke==13 ){
+      tdis(x*30+8,9+y,tmp,20,10);
+      i=part_sel(tim_asin[nn]);
+      if(i>=0){tim_asin[nn]=i;}
+    }
+
+    if( ke>='0' && ke<='9' ){
+      tim_asin[nn]=ke-'0';
+    }
+    if((ke>='a' && ke<='f')||(ke>='A' && ke<='F')){
+      tim_asin[nn]=(ke&15)+9;
+    }
+
+    if( ke==0x05 ){y--;if( y<0 ){y=15;}}
+    if( ke==0x18 ){y++;if( y>15 ){y=0;}}
+    if( ke==0x13 || ke==0x04 ){x++;if( x>1 ){x=0;}}
+
+    if( ke==9 ){
+      msg("No.=");j=vinput(x*16+y+1,0x802);msg_clr();
+      if(es==0 && j>0 && j<=32){j-=1;x=j>>4;y=j&15;}
+    }
+
+    if( ke==12 ){
+      msg(_("Initialize assign"));
+      if(yn_sel()>0){msg_clr();asin_init();goto top;}
+    }
+  }
+  edit_scr=scr;
+  C_CLS_AL();home2(gy);
+}
+
+/***************************/
+int    part_sel(int yy)
+{
+  int  ke,i,j,y=yy;
+  char tmp[128];
+
+  box(527,116+512,752,411+512,14,65535);
+  box(529,133+512,750,409+512,14,65535);
+  sdis(66,84+512," PART SELECT",13,15,8);
+  sdis(66,116+512," No.  PART NAME",28,15,14);
+  home2(512);
+
+  for(i=0;i<16;i++){
+    strcpy(tmp,fstr(i,2));
+    tdis(67,9+i,tmp,3,3);
+
+    if(i!=0){strcpy(tmp,tim_head[i-1]);}
+    else{strcpy(tmp,"No Assign");}
+    tdis(70,9+i,tmp,20,3);
+  }
+
+  while( 1){
+    if(y!=0){strcpy(tmp,tim_head[y-1]);}
+    else{strcpy(tmp,"No Assign");}
+
+    tdis(70,9+y,tmp,20,11);
+    ke=inkey2();
+    tdis(70,9+y,tmp,20,3);
+
+    if( ke==27 ){y=-1;break;}
+    if( ke==13 ){break;}
+    if( ke==0x05 ){y--;if( y<0 ){y=15;}}
+    if( ke==0x18 ){y++;if( y>15 ){y=0;}}
+
+    if( ke==9 ){
+      msg("No.=");j=vinput(y+1,0x802);msg_clr();
+      if(es==0 && j>0 && j<=16){j-=1;y=j&15;}
+    }
+
+  }
+  txerase(527,32,767,511);
+  fill(527,512+32,767,1023,0);
+  return y;
+}
+
+/***************************/
+ void  rec_filter(int md)
+{
+  int  i,y=0,x=0,gy;
+  char tmp[128];
+
+  gy=scyp;
+
+  if(md==0){
+    fill(0,512+32,767,1023,0);
+  }else{
+    txerase(22*8,9*16,59*8,18*16);
+    fill(174,115+512,641,379+512,0);
+  }
+
+  box(174,115+512,361,379+512,14,65535);
+  box(176,133+512,359,377+512,14,65535);
+  sdis(22,116+512," RECORD FILTER",23,15,14);
+
+  box(366,115+512,641,379+512,14,65535);
+  box(368,133+512,639,377+512,14,65535);
+
+  box(495,133+512+4,511,377+512-4,14,65535);
+
+  sdis(46,116+512," Control Change Convert",34,15,14);
+  sdis(46+16,128+512+16*7+8,"->",2,15,-1);
+
+  home2(512);
+top:
+  for(i=0;i<14;i++){
+    int        ke,ka,kb;
+
+    tdis(23,9+i,filter_name[i],18,3);
+    ke=rfilt[i][0];
+    if(ke){strcpy(tmp,": ON");}else{strcpy(tmp,":OFF");}
+    tdis(40,9+i,tmp,4,3);
+
+    ka=rfilt[i+16][0];kb=rfilt[i+16][1];
+
+    if(ka==128){strcpy(tmp,"---  --------");}else{
+      strcpy(tmp,fstr(ka,3));strcat(tmp,"  ");
+      strcat(tmp,ctrl_type(ka));}
+    tdis(41+7,9+i,tmp,13,3);
+
+    if(kb==128){strcpy(tmp,"---  --------");}else{
+      strcpy(tmp,fstr(kb,3));strcat(tmp,"  ");
+      strcat(tmp,ctrl_type(kb));}
+    tdis(41+24,9+i,tmp,13,3);
+  }
+  tdis(40-10,9+11,fstr(rfilt[11][1],3),3,3);
+  tdis(40-4,9+11,fstr(rfilt[11][2],3),3,3);
+  tdis(40-4,9+12,fstr(rfilt[12][1]-128,3),3,3);
+  tdis(40-4,9+13,fstr(rfilt[13][1],3),3,3);
+
+  while( 1){
+    int        ke;
+
+    tcur(41+x*7,9+y,3,3);
+    if(x){tcur(41+x*7+17,9+y,3,3);}
+
+    ke=inkey2();
+    tcur(41+x*7,9+y,3,3);
+    if(x){tcur(41+x*7+17,9+y,3,3);}
+
+    if( ke==27 ){break;}
+    if( ke==13 ){
+      if(x==0){rfilt[y][0]=1-rfilt[y][0];
+      if(rfilt[y][0]){tdis(41,y+9,"ON ",3,3);}
+
+      if(y==11 && rfilt[y][0]){
+       int ct;
+       char tmp0[64];
+
+       B_LOCATE(41-11,y+9);tmp0[0]=0;
+       b_striS(tmp0,64,rfilt[y][1]);
+       sinput(tmp0,0xb04);
+
+       if(es==0){
+         ct=ctc(60,tmp0,0);
+         if(ct>=0 && ct<=127){rfilt[y][1]=ct;}
+
+         B_LOCATE(41-5,y+9);tmp0[0]=0;
+         b_striS(tmp0,64,rfilt[y][2]);
+         sinput(tmp0,0xb04);
+
+         if(es==0){
+           ct=ctc(60,tmp0,0);
+           if(ct>=0 && ct<=127){rfilt[y][2]=ct;}
+         }
+       }
+      }
+      if(y==12 && rfilt[y][0]){
+       int ct;
+       ct=rfilt[y][1]-128;
+       B_LOCATE(41-5,y+9);ct=vinput(ct,0x803);
+       if(es==0 && (ct>=-99 && ct<99)){
+         rfilt[y][1]=ct+128;}
+      }
+      if(y==13 && rfilt[y][0]){
+       int ct;
+       char tmp0[64];
+
+       B_LOCATE(41-5,y+9);tmp0[0]=0;
+       b_striS(tmp0,64,rfilt[y][1]);
+       sinput(tmp0,0xb03);
+
+       if(es==0){
+         ct=str_val(tmp0);
+         if(ct>=0 && ct<=127){rfilt[y][1]=ct;}
+       }
+      }
+
+
+      }
+      if(x!=0){
+       int ct,ctl;
+       char tmp0[64];
+
+       B_LOCATE(41+7,y+9);tmp0[0]=0;
+       if(rfilt[y+16][0]<128){b_striS(tmp0,64,rfilt[y+16][0]);}
+       sinput(tmp0,0xb05);
+
+       if(es==0){
+         ct=spc_code(tmp0,&ctl);
+         if(ct==0xeb && ctl>=0){rfilt[y+16][0]=ctl;}
+
+         B_LOCATE(41+24,y+9);tmp0[0]=0;
+         if(rfilt[y+16][1]<128){b_striS(tmp0,64,rfilt[y+16][1]);}
+         sinput(tmp0,0xb05);
+
+         if(es==0){
+           ct=spc_code(tmp0,&ctl);
+           if(ct==0xeb && ctl>=0){rfilt[y+16][1]=ctl;}
+         }
+       }
+
+      }
+      goto top;}
+
+    if( ke==0x05 ){y--;if( y<0 ){y=13;}}
+    if( ke==0x18 ){y++;if( y>13 ){y=0;}}
+
+    if( ke==0x13 ){x--;if( x<0 ){x=1;}}
+    if( ke==0x04 ){x++;if( x>1 ){x=0;}}
+
+    if( ke==12 ){
+      msg(_("Init. Ok"));
+      if(yn_sel()>0){
+       msg_clr();filt_init();goto top;
+      }
+    }
+  }
+  txerase(22*8,9*16,59*8,18*16);home2(gy);
+  fill(174,115+512,641,379+512,0);
+
+}
+
+/***************************/
+void   filt_init()
+{
+  int  i;
+
+  for(i=0;i<16;i++){
+    rfilt[i][0]=0;rfilt[i][1]=0;
+    rfilt[i+16][0]=128;rfilt[i+16][1]=128;
+  }
+  rfilt[11][1]=127;rfilt[11][2]=0;
+  rfilt[12][1]=128;
+  rfilt[13][1]=127;
+
+}
+
+/***************************/
+void   stgt_as()
+{
+  int  a,n,i,xx,yy,x=0,y=0,scr,sh;
+
+  scr=edit_scr;edit_scr=0;
+
+  fill(316,566,453,997,0);
+  box(316,643,452,996-8,14,65535);
+  box(317,644,451,995-8,14,65535);
+  fill(316,602,452,644,14);
+
+  es=0;B_COLOR(3);
+
+  B_LOCATE(40,6);
+  B_PRINT("* ST/GT ASSIGN *");
+
+redis:
+  B_LOCATE(40,7);
+  if(x<2){
+    B_PRINT("NO.       ST  GT");
+  }else{
+    B_PRINT("NO.   ST  GT VEL");
+  }
+
+  for(i=0;i<10;i++){
+    B_LOCATE(40,i*2+9);
+    B_PRINT("F");B_PRINT(fstr(i+1,2));B_PRINT(": ");
+    if(x<2){
+      B_PRINT((const char *)stgt_name[i]);
+      B_PRINT(fstr(stgt_tbl[i],5));
+      B_PRINT(fstr(stgt_tbl[i+10],4));
+    }else{
+      B_PRINT(fstr(stgt_tbl[i],3));
+      B_PRINT(fstr(stgt_tbl[i+10],4));
+      B_PRINT(fstr(stgt_tbl[i+20],4));
+    }
+  }
+  while( 1){
+    i=y+x*10;xx=49/*+(x&1)*4*/;if(x){xx+=4;}
+    yy=y*2+9;
+
+    tcur(xx,yy,3,3);
+    a=inkey2();sh=B_SFTSNS();
+    tcur(xx,yy,3,3);
+
+    if( a==0x05 ){y--;if( y<0 ){y=9;/*SKEYSET(0x85);SKEYSET(0x5);*/}}
+    if( a==0x18 ){y++;if( y>9 ){y=0;}}
+    if( a==0x13 ){x--;if( x<0 ){x=2;}if(x==2||x==1){goto redis;}}
+    if( a==0x04 ){x++;if( x>2 ){x=0;}if(x==2||x==0){goto redis;}}
+    if( a==0x0b ){y=0;x=0;break;}
+    /*
+      if( a==9 ){
+      msg("No.=");j=vinput(y+1,0x802);msg_clr();
+      if(es==0 && j>0 && j<=10){y=j-1;}
+      }
+      */
+    if( a==12 ){
+      msg(_("Initialize assign"));
+      if(yn_sel()>0){msg_clr();stgt_init();goto redis;}
+    }
+    if( a==32 ){
+      stgt_init2(i);goto redis;
+    }
+
+    if( a==13 ){
+      B_LOCATE(xx,yy);
+      n=vinput(stgt_tbl[i],0x803);
+      if(es==0 && n>=0 && ((x<2 && n<=255) || n<=127)){stgt_tbl[i]=n;}
+      goto redis;
+    }
+    if( a>='0' && a<='9' ){
+      B_LOCATE(xx,yy);
+      n=vinput(a-'0',0x403);
+      if(es==0 && n>=0 && ((x<2 && n<=255) || n<=127)){stgt_tbl[i]=n;}
+      goto redis;
+    }
+
+    if( a=='+' || a=='>' || a=='.' ){
+      int n=stgt_tbl[i];
+      if(sh&1){n+=12;}else{n++;}
+
+      n=n&255;
+      if(x==2){n=n&127;}
+      stgt_tbl[i]=n;
+      goto redis;
+    }
+    if( a=='-' || a=='<' || a==',' ){
+      int n=stgt_tbl[i];
+      if(sh&1){n+=244;}else{n+=255;}
+      n=n&255;
+      if(x==2){n=n&127;}
+      stgt_tbl[i]=n;
+      goto redis;
+    }
+
+    if( a==27 ){break;}
+  }
+
+  edit_scr=scr;
+  txerase(40*8,5*16,16*8,25*16);
+  fill(316,537,453,997,0);
+
+}
+
+/***************************/
diff --git a/basic.cpp b/basic.cpp
new file mode 100644 (file)
index 0000000..ec0c7b1
--- /dev/null
+++ b/basic.cpp
@@ -0,0 +1,147 @@
+/* basic.c
+
+   some of X-BASIC compatible functions
+
+   Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#include "sted.h"
+#include "sted_screen.h"
+
+/* graphic functions */
+
+void
+fill( int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_col )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->GraphicsFill(in_x0, in_y0, in_x1, in_y1, in_col);
+  return;
+}
+
+void
+box( int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_col, unsigned int in_ls )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->GraphicsBox(in_x0, in_y0, in_x1, in_y1, in_col, in_ls);
+  return;
+}
+
+int
+point( int in_x, int in_y )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->GraphicsPoint(in_x, in_y);
+}
+
+void
+line( int in_x0, int in_y0, int in_x1, int in_y1, int in_col, int in_ls )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->GraphicsLine(in_x0, in_y0, in_x1, in_y1, in_col, in_ls);
+  return;
+}
+
+void
+symbol( int in_x, int in_y, char *in_st, char in_h, char in_v, char in_mo, int in_p, char in_an )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->SetGraphicsColor(in_p);
+  scr->GraphicsPuts(in_x, in_y, in_st);
+  return;
+}
+
+
+/* other functions */
+
+/* returns string describing current day(?) */
+char *dtasc( unsigned int j ) {
+
+  static char dtasc_name[10];
+  int y,a,b;
+
+  a=(j>>9)&0x7f;
+  b=a%10;
+  a=a%100-b;
+  y=a+b;
+  
+  snprintf(dtasc_name, 10, "%02d-%02d-%02d", y, ((j>>5)&0x0f)+1, j&0x1f );
+
+  return dtasc_name;
+}
+
+/* returns string describing current time(?) */
+char *tmasc( unsigned int j ) {
+
+  static char tmasc_name[10];
+
+  snprintf(tmasc_name, 10, "%02d:%02d:%02d", (j>>11)&0x1f, (j>>5)&0x3f, (j&0x1f)*2 );
+  return tmasc_name;
+}
+
+/* returns mouse positions */
+int 
+mspos( int *out_x, int *out_y )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+  return scr->GetMousePos(out_x, out_y);
+}
+
+/* returns someting B-) */
+void b_striS ( char * buf, int bufSize, int num ) {
+  int r;
+
+  r=snprintf( buf, bufSize, "%d", num );
+  if ( r < 0 ) {
+    buf[0]='\0';
+  }
+  return;
+}
+
+/* set current Kanji mode */
+void KNJCTRL( int i, int j ) {
+
+  /* not implemented */
+  return;
+}
+
diff --git a/cm6con.cpp b/cm6con.cpp
new file mode 100644 (file)
index 0000000..c0f64a4
--- /dev/null
@@ -0,0 +1,1138 @@
+/*
+ * STed: cm6con.c (cm-64 controler)
+ */
+#include       "sted.h"
+
+static unsigned char   cm6_info[64]={
+  0x43,0x4F,0x4D,0x45,0x20,0x4F,0x4E,0x20,0x4D,0x55,0x53,0x49,0x43,0x00,0x00,0x00,
+  0x52,0x20,0x43,0x4D,0x2D,0x36,0x34,0x20,0x20,0x20,0x03,0x00,0x4A,0x00,0x05,0x03,
+  0x03,0x0A,0x06,0x04,0x03,0x00,0x00,0x00,0x06,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
+  0x08,0x09,0x64,0x01,0x04,0x07,0x00,0x30,0x08,0x01,0x1F,0x07,0x01,0x0E,0x08,0x00};
+
+static unsigned char   la_sys[32]={
+  0x4A,0x00,0x05,0x03,0x03,0x0A,0x06,0x04,0x03,0x00,0x00,0x00,0x06,0x01,0x02,0x03,
+  0x04,0x05,0x06,0x07,0x08,0x09,0x64,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
+
+static unsigned char   pcm_sys[23]={
+  0x40,0x01,0x05,0x05,0x02,0x08,0x15,0x00,0x00,0x00,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
+  0x64,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F};
+
+static unsigned char   rsetup[85*2]={
+  0x7F,0x07,0x7F,0x07,0x7F,0x07,0x7F,0x07,0x7F,0x07,0x7F,0x07,0x7F,0x07,0x7F,0x07,
+  0x7F,0x07,0x7F,0x07,0x7F,0x07,0x40,0x07,0x40,0x07,0x4A,0x06,0x41,0x07,0x4B,0x08,
+  0x45,0x06,0x44,0x0B,0x46,0x06,0x44,0x0B,0x5D,0x06,0x43,0x08,0x47,0x06,0x43,0x08,
+  0x42,0x03,0x48,0x06,0x42,0x03,0x49,0x08,0x7F,0x07,0x7F,0x07,0x56,0x09,0x7F,0x07,
+  0x4C,0x07,0x7F,0x07,0x7F,0x07,0x7F,0x07,0x52,0x02,0x53,0x04,0x4D,0x08,0x4E,0x09,
+  0x4F,0x0A,0x50,0x07,0x51,0x05,0x54,0x02,0x55,0x02,0x5B,0x09,0x58,0x04,0x5A,0x09,
+  0x59,0x09,0x5C,0x0A,0x7F,0x07,0x57,0x0C,0x5E,0x07,0x5F,0x07,0x60,0x07,0x61,0x07,
+  0x62,0x07,0x63,0x07,0x64,0x07,0x65,0x07,0x66,0x07,0x67,0x07,0x68,0x07,0x69,0x07,
+  0x6A,0x07,0x6B,0x07,0x6C,0x07,0x6D,0x07,0x6E,0x07,0x6F,0x07,0x70,0x07,0x71,0x07,
+  0x72,0x07,0x73,0x07,0x74,0x07,0x75,0x07,0x76,0x07,0x77,0x07,0x78,0x07,0x79,0x07,
+  0x7A,0x07,0x7B,0x07,0x7C,0x07,0x7D,0x07,0x7E,0x07};
+
+static unsigned char   pcmpat[64]={
+  0x00,0x01,0x02,0x03,0x04,0x06,0x08,0x0A,0x0C,0x0E,0x0F,0x11,0x12,0x14,0x15,0x1A,
+  0x1B,0x1C,0x1D,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x2A,0x2B,0x2C,0x2D,
+  0x2E,0x2F,0x30,0x31,0x32,0x34,0x36,0x38,0x3A,0x3B,0x3C,0x3D,0x3E,0x3F,0x40,0x42,
+  0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53};
+
+static unsigned char   la_para[8]={
+  0x00,0x00,0x18,0x32,0x0C,0x00,0x01,0x00};
+
+static unsigned char   pcm_para[19]={
+  0,0x00,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C};
+
+static unsigned char   la_tmp[144]={
+  0x01,0x04,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x07,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x00,0x30,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x08,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x01,0x1F,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x07,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x01,0x0E,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x08,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x00,0x29,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x04,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x00,0x03,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x0A,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x01,0x2E,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x01,0x3A,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x0E,0x00,0x7F,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x18,0x32,0x0C,0x00,0x01,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+
+static unsigned char   pcm_tmp[126]={
+  0,0x28,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C,0x40,0x64,
+  0,0x2B,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C,0x51,0x64,
+  0,0x00,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C,0x40,0x64,
+  0,0x33,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C,0x63,0x64,
+  0,0x14,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C,0x1B,0x64,
+  0,0x40,0x0C,0x32,0x0C,0,0x7F,0,1,0x0F,0x40,0x40,0x32,0,0,0,2,4,0x0C,0x2D,0x64};
+
+static unsigned char   la_tim_tmp[1968]={
+  0x53,0x6C,0x61,0x70,0x20,0x42,0x61,0x73,0x73,0x31,0x05,0x00,0x07,0x00,0x24,0x32,
+  0x10,0x01,0x00,0x24,0x00,0x07,0x00,0x00,0x00,0x0F,0x0C,0x12,0x00,0x15,0x23,0x2C,
+  0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x4B,0x50,0x06,0x0F,0x0C,0x00,0x00,0x00,
+  0x3C,0x00,0x00,0x1E,0x64,0x00,0x00,0x00,0x24,0x26,0x10,0x01,0x00,0x25,0x00,0x07,
+  0x00,0x00,0x00,0x0D,0x0C,0x12,0x00,0x15,0x25,0x2C,0x32,0x32,0x40,0x00,0x38,0x00,
+  0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x64,0x4B,0x43,0x04,0x0F,0x0C,0x00,0x00,0x00,0x3B,0x4E,0x64,0x1E,0x64,0x50,
+  0x37,0x00,0x24,0x37,0x10,0x01,0x01,0x00,0x26,0x07,0x04,0x00,0x00,0x0C,0x0C,0x0C,
+  0x00,0x1B,0x27,0x2F,0x32,0x32,0x37,0x19,0x26,0x28,0x14,0x07,0x2E,0x07,0x64,0x19,
+  0x00,0x00,0x00,0x2D,0x50,0x5E,0x1C,0x64,0x55,0x30,0x1A,0x50,0x4B,0x5B,0x0C,0x0F,
+  0x0C,0x00,0x00,0x00,0x3B,0x3B,0x64,0x1E,0x64,0x50,0x37,0x00,0x24,0x37,0x10,0x01,
+  0x01,0x00,0x26,0x07,0x04,0x00,0x00,0x0C,0x0C,0x0C,0x00,0x1B,0x27,0x2F,0x32,0x32,
+  0x37,0x19,0x26,0x28,0x14,0x07,0x2E,0x07,0x64,0x19,0x00,0x00,0x00,0x2D,0x50,0x5E,
+  0x1C,0x64,0x55,0x30,0x1A,0x50,0x4B,0x5B,0x0C,0x0F,0x0C,0x00,0x00,0x00,0x3B,0x3B,
+  0x64,0x1E,0x64,0x50,0x37,0x00,0x53,0x74,0x72,0x20,0x53,0x65,0x63,0x74,0x20,0x31,
+  0x07,0x05,0x0F,0x00,0x24,0x2B,0x10,0x01,0x00,0x00,0x59,0x07,0x07,0x01,0x03,0x07,
+  0x0F,0x18,0x00,0x30,0x63,0x29,0x32,0x32,0x43,0x1C,0x2E,0x4B,0x00,0x09,0x1B,0x0A,
+  0x1E,0x14,0x00,0x00,0x10,0x18,0x18,0x50,0x58,0x64,0x60,0x5A,0x12,0x46,0x50,0x5B,
+  0x0C,0x1B,0x0C,0x04,0x01,0x10,0x0A,0x12,0x18,0x3C,0x38,0x50,0x60,0x64,0x24,0x39,
+  0x10,0x01,0x00,0x00,0x50,0x07,0x07,0x01,0x04,0x06,0x11,0x09,0x00,0x31,0x64,0x2B,
+  0x32,0x32,0x3F,0x1C,0x29,0x55,0x00,0x09,0x27,0x0A,0x0F,0x14,0x00,0x00,0x12,0x20,
+  0x1C,0x59,0x58,0x55,0x44,0x1A,0x12,0x46,0x50,0x70,0x09,0x5B,0x0C,0x04,0x01,0x0C,
+  0x0E,0x12,0x1C,0x3C,0x30,0x4A,0x5A,0x64,0x24,0x32,0x10,0x01,0x00,0x2C,0x00,0x07,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,
+  0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x5A,0x46,0x4F,0x04,0x41,0x0A,0x00,0x00,0x00,0x3C,0x00,0x00,0x3D,0x64,0x00,
+  0x00,0x00,0x24,0x54,0x10,0x01,0x00,0x2D,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x07,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5C,0x5A,0x2B,0x08,0x5B,
+  0x0C,0x00,0x00,0x00,0x3C,0x00,0x00,0x3C,0x64,0x00,0x00,0x00,0x42,0x72,0x73,0x20,
+  0x53,0x65,0x63,0x74,0x20,0x31,0x05,0x07,0x0F,0x00,0x30,0x32,0x10,0x01,0x00,0x17,
+  0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,
+  0x00,0x00,0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x5F,0x48,0x7F,0x06,0x24,0x05,0x00,0x01,0x00,0x00,0x00,0x00,0x14,
+  0x64,0x64,0x64,0x64,0x24,0x32,0x10,0x01,0x00,0x1D,0x00,0x07,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x07,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x60,0x48,0x7F,
+  0x06,0x24,0x0C,0x00,0x01,0x00,0x00,0x1D,0x2E,0x28,0x64,0x64,0x64,0x00,0x30,0x32,
+  0x10,0x01,0x01,0x00,0x00,0x07,0x06,0x03,0x00,0x0B,0x21,0x23,0x00,0x13,0x22,0x32,
+  0x32,0x32,0x3F,0x0F,0x28,0x46,0x08,0x09,0x24,0x09,0x37,0x3A,0x00,0x02,0x13,0x01,
+  0x08,0x1F,0x64,0x56,0x3C,0x57,0x48,0x4E,0x44,0x7F,0x00,0x1B,0x0C,0x01,0x02,0x06,
+  0x08,0x04,0x17,0x14,0x4B,0x2C,0x64,0x5D,0x24,0x2F,0x10,0x01,0x00,0x00,0x48,0x07,
+  0x06,0x03,0x00,0x0B,0x0F,0x18,0x00,0x13,0x22,0x2B,0x32,0x32,0x3D,0x0F,0x28,0x46,
+  0x08,0x09,0x24,0x09,0x37,0x3A,0x00,0x02,0x18,0x01,0x08,0x1F,0x64,0x56,0x3C,0x57,
+  0x48,0x4E,0x44,0x7F,0x00,0x1B,0x0C,0x01,0x02,0x0B,0x08,0x0D,0x17,0x14,0x4B,0x2C,
+  0x64,0x5D,0x53,0x61,0x78,0x20,0x31,0x20,0x20,0x20,0x20,0x20,0x01,0x05,0x0F,0x00,
+  0x24,0x32,0x10,0x01,0x01,0x00,0x00,0x07,0x07,0x03,0x04,0x15,0x15,0x27,0x00,0x32,
+  0x27,0x32,0x32,0x32,0x40,0x1A,0x30,0x58,0x11,0x07,0x21,0x09,0x30,0x47,0x00,0x00,
+  0x03,0x11,0x19,0x3E,0x2D,0x4C,0x37,0x29,0x1D,0x64,0x4B,0x5B,0x0C,0x1B,0x0C,0x03,
+  0x00,0x0B,0x0E,0x0C,0x16,0x1E,0x2F,0x42,0x60,0x64,0x37,0x31,0x10,0x01,0x01,0x00,
+  0x00,0x07,0x00,0x00,0x00,0x0A,0x14,0x32,0x00,0x32,0x32,0x32,0x32,0x32,0x40,0x21,
+  0x2E,0x64,0x00,0x06,0x26,0x0A,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x64,0x64,0x73,0x00,0x24,0x08,0x02,0x00,0x0A,0x1A,0x14,0x3C,0x11,
+  0x3E,0x64,0x59,0x45,0x24,0x00,0x10,0x01,0x00,0x1E,0x00,0x07,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x07,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x50,0x50,
+  0x00,0x1B,0x0C,0x00,0x00,0x00,0x00,0x00,0x00,0x1E,0x64,0x64,0x64,0x64,0x24,0x38,
+  0x10,0x01,0x00,0x1D,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,
+  0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x50,0x6F,0x05,0x1B,0x06,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x1E,0x64,0x64,0x64,0x64,0x49,0x63,0x65,0x20,0x52,0x61,0x69,0x6E,
+  0x20,0x20,0x07,0x02,0x07,0x00,0x24,0x37,0x10,0x01,0x01,0x00,0x00,0x06,0x08,0x01,
+  0x00,0x01,0x08,0x06,0x64,0x32,0x62,0x29,0x32,0x32,0x40,0x1E,0x4C,0x19,0x00,0x07,
+  0x29,0x0A,0x5C,0x58,0x00,0x01,0x01,0x0F,0x29,0x3D,0x59,0x4F,0x1F,0x40,0x28,0x5F,
+  0x4B,0x5B,0x0C,0x1B,0x0C,0x01,0x01,0x00,0x07,0x0E,0x54,0x55,0x64,0x47,0x53,0x00,
+  0x24,0x2D,0x10,0x01,0x00,0x00,0x55,0x06,0x05,0x01,0x00,0x01,0x08,0x06,0x64,0x32,
+  0x62,0x29,0x32,0x32,0x3D,0x1E,0x46,0x19,0x00,0x07,0x29,0x0A,0x5C,0x58,0x00,0x01,
+  0x01,0x0F,0x29,0x3D,0x59,0x4F,0x1F,0x40,0x28,0x5F,0x4B,0x5B,0x0C,0x1B,0x0C,0x01,
+  0x01,0x00,0x07,0x0E,0x54,0x55,0x64,0x47,0x53,0x00,0x43,0x32,0x05,0x01,0x00,0x69,
+  0x00,0x07,0x08,0x03,0x00,0x36,0x36,0x44,0x4C,0x5D,0x57,0x4D,0x2D,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x0B,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x5F,0x46,0x7F,0x00,0x1B,0x0C,0x00,0x00,0x00,0x3F,0x3D,0x48,0x4C,
+  0x64,0x5E,0x41,0x00,0x43,0x32,0x05,0x01,0x00,0x69,0x00,0x07,0x08,0x03,0x00,0x36,
+  0x36,0x44,0x4C,0x5D,0x57,0x4D,0x2D,0x00,0x00,0x00,0x00,0x00,0x00,0x0B,0x00,0x07,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5F,0x46,0x7F,
+  0x00,0x1B,0x0C,0x00,0x00,0x00,0x3F,0x3D,0x48,0x4C,0x64,0x5E,0x41,0x00,0x45,0x6C,
+  0x65,0x63,0x50,0x69,0x61,0x6E,0x6F,0x31,0x01,0x00,0x07,0x00,0x24,0x37,0x0F,0x01,
+  0x00,0x00,0x3C,0x07,0x03,0x00,0x01,0x0A,0x07,0x16,0x00,0x32,0x42,0x33,0x32,0x32,
+  0x00,0x00,0x00,0x35,0x00,0x07,0x16,0x08,0x29,0x28,0x00,0x02,0x00,0x20,0x3B,0x64,
+  0x52,0x64,0x47,0x29,0x00,0x5A,0x55,0x5C,0x0C,0x59,0x0C,0x02,0x00,0x00,0x32,0x47,
+  0x64,0x38,0x64,0x52,0x28,0x00,0x4E,0x47,0x07,0x01,0x00,0x00,0x21,0x07,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x1D,0x01,0x09,
+  0x61,0x0A,0x64,0x00,0x00,0x03,0x00,0x1A,0x40,0x4B,0x1D,0x64,0x38,0x14,0x00,0x47,
+  0x3C,0x33,0x08,0x5B,0x0C,0x01,0x01,0x00,0x28,0x3D,0x4A,0x64,0x64,0x36,0x23,0x06,
+  0x30,0x2D,0x0F,0x01,0x01,0x00,0x3C,0x07,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x32,
+  0x34,0x30,0x30,0x31,0x3E,0x08,0x42,0x37,0x00,0x07,0x16,0x09,0x28,0x28,0x00,0x02,
+  0x00,0x18,0x3B,0x64,0x52,0x64,0x47,0x29,0x00,0x5A,0x55,0x5C,0x0C,0x59,0x0C,0x02,
+  0x00,0x00,0x32,0x47,0x64,0x33,0x64,0x52,0x28,0x00,0x30,0x2D,0x0F,0x01,0x01,0x00,
+  0x3C,0x07,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x32,0x34,0x30,0x30,0x31,0x3E,0x08,
+  0x42,0x37,0x00,0x07,0x16,0x09,0x28,0x28,0x00,0x02,0x00,0x18,0x3B,0x64,0x52,0x64,
+  0x47,0x29,0x00,0x5A,0x55,0x5C,0x0C,0x59,0x0C,0x02,0x00,0x00,0x32,0x47,0x64,0x33,
+  0x64,0x52,0x28,0x00,0x42,0x6F,0x74,0x74,0x6C,0x65,0x42,0x6C,0x6F,0x77,0x05,0x01,
+  0x0F,0x00,0x21,0x32,0x10,0x01,0x00,0x1C,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x07,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x55,0x7B,0x08,0x20,
+  0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x3C,0x64,0x64,0x64,0x64,0x3C,0x49,0x07,0x01,
+  0x00,0x35,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x1D,0x00,0x32,0x32,0x32,0x32,0x32,
+  0x3F,0x25,0x00,0x00,0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x20,0x46,0x7D,0x04,0x1B,0x0C,0x00,0x00,0x08,0x18,0x23,
+  0x28,0x1A,0x54,0x5F,0x56,0x46,0x24,0x32,0x10,0x01,0x00,0x00,0x00,0x07,0x06,0x03,
+  0x01,0x0E,0x11,0x30,0x00,0x42,0x38,0x32,0x32,0x32,0x3F,0x19,0x44,0x32,0x18,0x0C,
+  0x1D,0x0B,0x2A,0x43,0x00,0x00,0x05,0x15,0x2C,0x2D,0x44,0x11,0x1D,0x17,0x0E,0x64,
+  0x44,0x7F,0x00,0x1B,0x0C,0x00,0x00,0x04,0x08,0x17,0x22,0x36,0x57,0x64,0x5D,0x64,
+  0x43,0x2D,0x10,0x01,0x00,0x00,0x00,0x07,0x05,0x03,0x01,0x0D,0x12,0x22,0x00,0x3F,
+  0x37,0x33,0x32,0x32,0x3F,0x28,0x00,0x2A,0x16,0x08,0x64,0x04,0x24,0x37,0x00,0x00,
+  0x09,0x25,0x2B,0x4E,0x64,0x42,0x23,0x17,0x11,0x44,0x3C,0x67,0x07,0x1B,0x0C,0x00,
+  0x00,0x19,0x0F,0x19,0x22,0x26,0x4F,0x61,0x5E,0x64,0x4F,0x72,0x63,0x68,0x65,0x20,
+  0x48,0x69,0x74,0x20,0x02,0x08,0x0F,0x00,0x24,0x32,0x10,0x01,0x00,0x2F,0x00,0x07,
+  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,
+  0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x64,0x46,0x1B,0x0C,0x67,0x02,0x02,0x00,0x01,0x2E,0x2D,0x1F,0x4C,0x64,0x5D,
+  0x32,0x00,0x18,0x32,0x10,0x01,0x01,0x00,0x64,0x07,0x04,0x00,0x00,0x0C,0x13,0x25,
+  0x00,0x3D,0x36,0x32,0x32,0x32,0x39,0x21,0x43,0x3A,0x00,0x0A,0x1E,0x09,0x3E,0x00,
+  0x00,0x00,0x08,0x2F,0x23,0x2D,0x29,0x1E,0x2A,0x22,0x05,0x3D,0x49,0x1B,0x0C,0x67,
+  0x02,0x01,0x00,0x14,0x24,0x2C,0x22,0x3E,0x64,0x61,0x3F,0x00,0x30,0x32,0x10,0x01,
+  0x00,0x17,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,
+  0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x64,0x46,0x1B,0x0C,0x67,0x02,0x02,0x00,0x00,0x33,0x2D,
+  0x19,0x4C,0x64,0x5E,0x32,0x00,0x31,0x48,0x10,0x01,0x00,0x2D,0x00,0x07,0x00,0x00,
+  0x00,0x00,0x00,0x00,0x00,0x32,0x32,0x32,0x32,0x32,0x00,0x00,0x00,0x00,0x00,0x03,
+  0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x64,
+  0x48,0x1B,0x0C,0x67,0x02,0x02,0x00,0x00,0x33,0x2D,0x19,0x4C,0x64,0x5E,0x32,0x00};
+
+unsigned char gsd_sys[]={
+  0x43,0x4F,0x4D,0x45,0x20,0x4F,0x4E,0x20,0x4D,0x55,0x53,0x49,0x43,0x00,0x47,0x53,
+  0x20,0x43,0x4F,0x4E,0x54,0x52,0x4F,0x4C,0x20,0x31,0x2E,0x30,0x00,0x00,0x00,0x00,
+  0x00,0x04,0x00,0x00,0x7F,0x40,0x40,0x04,0x04,0x00,0x40,0x40,0x00,0x00,0x02,0x00,
+  0x40,0x08,0x50,0x03,0x13,0x00};
+
+unsigned char gsd_rsv[]={
+  2,2,2,2,2,2,2,2,2,6,0,0,0,0,0,0};
+
+unsigned char gsd_part[]={
+  0x00,0x00,0x00,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
+  0x01,0x01,0x01,0x01,0x01,0x00,0x40,0x08,0x00,0x64,0x40,0x40,0x40,0x00,0x7F,0x10,
+  0x11,0x00,0x28,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+  0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x0A,0x00,0x00,0x40,0x00,
+  0x00,0x00,0x42,0x40,0x40,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x40,0x40,
+  0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x40,
+  0x00,0x00,0x00,0x40,0x40,0x40,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x40,
+  0x40,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x02};
+
+unsigned char gsd_rhy[]={
+  0x4F,0x31,0x7F,0x7F,0x6B,0x31,0x7F,0x7F,0x57,0x36,0x3F,0x3F,0x5B,0x36,0x3F,0x3F,
+  0x73,0x40,0x3F,0x3F,0x7F,0x36,0x00,0x00,0x67,0x40,0x3F,0x3F,0x67,0x40,0x3F,0x3F,
+  0x7F,0x40,0x20,0x20,0x7F,0x40,0x20,0x20,0x7F,0x40,0x7F,0x7F,0x7F,0x40,0x7F,0x7F,
+  0x63,0x36,0x7F,0x7F,0x7F,0x40,0x7F,0x7F,0x7F,0x22,0x7F,0x7F,0x7B,0x54,0x1F,0x1F,
+  0x7F,0x2E,0x7F,0x7F,0x57,0x54,0x20,0x20,0x7F,0x3A,0x7F,0x7F,0x77,0x54,0x1F,0x1F,
+  0x7F,0x46,0x7F,0x7F,0x7F,0x52,0x7F,0x7F,0x7F,0x54,0x7F,0x7F,0x7F,0x5E,0x7F,0x7F,
+  0x78,0x2C,0x7F,0x7F,0x6F,0x2C,0x7F,0x7F,0x63,0x2C,0x7F,0x7F,0x77,0x4A,0x3F,0x3F,
+  0x53,0x36,0x7F,0x7F,0x73,0x54,0x3F,0x3F,0x7F,0x2C,0x7F,0x7F,0x69,0x1D,0x7F,0x7F,
+  0x78,0x2C,0x7F,0x7F,0x7F,0x63,0x5F,0x5F,0x7F,0x63,0x5F,0x5F,0x63,0x27,0x7F,0x7F,
+  0x6B,0x27,0x7F,0x7F,0x7B,0x2C,0x5F,0x5F,0x63,0x54,0x7F,0x7F,0x63,0x54,0x7F,0x7F,
+  0x63,0x1D,0x64,0x64,0x63,0x1D,0x64,0x64,0x5F,0x1D,0x3F,0x3F,0x69,0x18,0x3F,0x3F,
+  0x4F,0x63,0x7F,0x7F,0x53,0x63,0x7F,0x7F,0x6B,0x5E,0x3F,0x3F,0x6F,0x5E,0x3F,0x3F,
+  0x6E,0x54,0x5F,0x5F,0x6B,0x63,0x5F,0x5F,0x6B,0x63,0x5F,0x5F,0x53,0x2C,0x7F,0x7F,
+  0x57,0x2C,0x7F,0x7F,0x5F,0x18,0x5F,0x5F,0x5F,0x18,0x7F,0x7F,0x7B,0x5E,0x3F,0x3F,
+  0x77,0x63,0x7F,0x7F,0x7B,0x68,0x7F,0x7F,0x7B,0x22,0x5F,0x5F,0x7F,0x2C,0x5F,0x5F,
+  0x7F,0x2C,0x5F,0x5F,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,
+  0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,
+  0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,
+  0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,
+  0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,
+  0x7F,0x40,0x00,0x00,0x7F,0x40,0x00,0x00,0x00,0x00,0x00,0x00};
+
+unsigned char gsd_data[]={
+  0x00,0x20,0x40,0x00,0x00};
+
+char   swi_str[2][4]={"OFF"," ON"};
+
+char   pch_title[5][20]={
+  "<<< SYSTEM MODE >>>","   LA PATCH WRITE  ","  PCM PATCH WRITE  ",
+  "RHYTHM PATCH WRITE ","   USER TONE LIST  "};
+
+char   tone_title[6][11]={
+  "< LA [A] >","< LA [B] >"," < USER > ","< RHYTHM >","<INTERNAL>"," < CARD > "};
+
+char   tone_hed[6]={'A','B','I','R','I','C'};
+
+int    selno,tkey,tvel;
+char   trf[64];
+
+
+/***************************/
+void   cm64_con()
+{
+  int  ke,sh,ex,smo=0,i;
+  char tmp0[256],path2[256];
+
+  tkey=60;tvel=127;
+  fill(0,544,767,1023,0);pfil();home2(512);trns_check();
+  B_CLR_AL();
+
+  if(cm6_file[0]==0){cm6_write(0x51*128*128+19*64,0x4eb2+19*64,19*64);}/*debug*/
+
+  while( 1){
+    ke=0;
+    if( smo==0 ){ke=sys_mode();}
+    if( smo==1 ){ke=tone_patch(0);}
+    if( smo==2 ){ke=tone_patch(1);}
+    if( smo==3 ){ke=rhy_patch();}
+
+    if(ke==0){ke=inkey3();}
+  recontrol:
+    sh=ke>>8;ke=ke & 0xff;if(ke>=0xf0 && ke<=0xf3){smo=ke-0xf0;}
+
+    if( ke==0xf4 ){
+      if( (sh&1)!=0 ){
+       ke=user_tone_list();goto recontrol;
+      }else{
+       all_note_off(0);temporary_set();
+       msg(_("Sending voice data (  )"));
+       for(i=0;i<64;i++){
+         if(trf[i]==0){
+           B_LOCATE(20,1);B_PRINT(fstr(64-i,2));trf[i]=1;
+           cm6_tone_write(i);
+         }
+       }
+       msg_clr();tim_buf_trns();C_FNKMOD(2);B_CLR_AL();dpl(0);
+       ex=exe("te.x -i");C_FNKMOD(3);if(ex>0){key_pause();}
+       C_CUROFF();B_COLOR(3);B_CLR_AL();tim_var_read();
+       C_WINDOW(0,31);home2(512);OnGraphic();dpl(1);
+       if(ex<0){msg(_("Cannot execute: TE.x"));}
+      }
+    }
+
+    if( ke==0xf5 ){
+      B_CLR_AL();strcpy(path2,rcp_path);fsel(cm6_file,path2,0x002);
+      if( cm6_file[0]==0 ){cminit();timtra();}
+      if( cm6_file[0]!=0 && es==0 ){
+       strcpy(tmp0,path2);strcat(tmp0,cm6_file);
+       if(timload(tmp0)!=0){cminit();cm6_file[0]=0;}
+       else{
+         if(!(cnfflag&0x0008)){strcpy(rcp_path,path2);}
+       }
+       timtra();trns_check();
+      }
+      sdis2(53,64,cm6_file,15,15,0);pfil();
+    }
+    if( ke==0xf6 ){
+      B_CLR_AL();strcpy(path2,rcp_path);fsel(cm6_file,path2,0x102);
+      if( cm6_file[0]!=0 && es==0 ){
+       strcpy(tmp0,path2);strcat(tmp0,cm6_file);
+       if(timsave(tmp0)==0){
+         if(!(cnfflag&0x0008)){strcpy(rcp_path,path2);}
+       }
+      }
+      sdis2(53,64,cm6_file,15,15,0);pfil();
+    }
+
+    if( ke==0xf7 ){poplay(0,1);}
+
+    if( ke==0xf8 ){
+      msg(_("Initialize all control data"));
+      if(yn_sel()>0){
+       cminit();all_note_off(1);trns_check();
+      }
+    }
+
+    if( ke==0xf9 || ke==27 ){break;}
+
+  }
+
+  temporary_set();
+  fnc_dis(-1);B_CLR_AL();home2(0);return;
+}
+
+/***************************/
+void   pfil()
+{
+  sdis2(0,552," CM-64 CONTROLER",17,15,8);
+  sdis2(50,552," CONTROL FILE:",14,15,8);sdis2(64,552,cm6_file,15,15,8);
+  box(648,552,744,600,14,65535);box(650,554,742,598,14,65535);
+  keyd();
+}
+
+/***************************/
+void   keyd()
+{
+  B_LOCATE(83,3);B_PRINT("KEY= ");B_PRINT(keystr(tkey));
+  B_LOCATE(83,4);B_PRINT("VEL=");B_PRINT(fstr(tvel,4));
+}
+
+/***************************/
+void   keyd_inp(int a)
+{
+  int  v;
+  char tmp0[128];
+  if(a==0){
+    B_LOCATE(88,3);strcpy(tmp0,keystr(tkey));sinput(tmp0,0x803);
+    if(es==0){v=ctc(60,tmp0,0);if(v>=0){tkey=v;}}
+  }else{
+    B_LOCATE(88,4);v=vinput(tvel,0x803);
+    if(es==0 && v>=0 && v<128){tvel=v;}
+  }
+  keyd();
+}
+
+/***************************/
+void   pch_fld(int m)
+{
+  static       char    hd0[]="NO. TIMBRE NAME     ";
+  static       char    hd1[]="KEY#   TIMBRE NAME   OUTPUT  PAN  REV   ";
+
+  fnc_dis(3);B_LOCATE(0,2);B_CLR_ED();fill(0,574,639,1023,0);keyd();
+  sdis2(19,552,pch_title[m],19,15,8);
+
+  if(m==0){
+    box(0,598,639,1000,14,65535);
+  }else{
+    box(0,700,639,999,14,65535);box(1,724,638,1000,14,65535);
+    fill(1,701,638,723,14);
+    if(m==2){
+      sdis2(1,576," CARD:",14,15,8);
+      sdis2(7,576,card_name[card_no[0]],65,15,8);
+    }
+    if(m==3){
+      B_LOCATE(1,12);B_PRINT(hd1);B_PRINT(hd1);
+      line(316,723,316,1000,14,65535);
+    }else{
+      B_LOCATE(1,12);B_PRINT(hd0);B_PRINT(hd0);B_PRINT(hd0);B_PRINT(hd0);
+      if(m<3){
+       box(0,600,639,696,14,65535);box(2,602,637,694,14,65535);
+       line(156,602,156,694,14,65535);line(316,602,316,694,14,65535);
+       line(476,602,476,694,14,65535);
+       fill(4,604,154,619,14);
+       g_print(10,604,"PATCH PARAMETER",15);
+      }
+      line(156,723,156,1000,14,65535);line(316,723,316,1000,14,65535);
+      line(476,723,476,1000,14,65535);
+    }
+  }
+}
+
+/***************************/
+void   card_sel()
+{
+  int  ke,i,y;
+
+  B_CLR_AL();fill(0,574,639,1023,0);keyd();
+  box(7,692,432,984,14,65535);box(9,694,430,982,14,65535);
+  sdis(1,676," PCM CARD SELECTER",53,15,14);
+
+  for(i=0;i<17;i++){
+    B_LOCATE(2,12+i);B_PRINT(fstr(i,2));B_PRINT(":");B_PRINT(card_name[i]);
+  }
+  y=card_no[0];
+
+  while( 1){
+    tcur(5,12+y,48,3);
+    ke=inkey2();
+    tcur(5,12+y,48,3);
+
+    if( ke==27 ){return;}
+    if( ke==13 ){card_no[0]=y;card_name_get();return;}
+
+    if( ke==0x05 ){y--;if( y<0 ){y=16;}}
+    if( ke==0x18 ){y++;if( y>16 ){y=0;}}
+  }
+}
+
+void   card_name_get()
+{
+  int  i,nm=card_no[0];
+
+  for(i=0;i<128;i++){
+    if(nm){
+      strcpy(tim_name[384+i],tim_names((nm+15)*128+i));
+    }else{
+      tim_name[384+i][0]=0;
+    }
+  }
+}
+
+/***************************/
+int    sys_mode()
+{
+  int  a,ke;
+
+  pch_fld(0);
+  while(1){
+    ke=inkey3();a=ke&0xff;
+
+    if(a=='Z'||a=='z'){timtra();trns_check();}
+    if(a>=0xf0){return(ke);}
+    if( a==27 ){return(0xf9);}
+  }
+}
+
+/***************************/
+int    tone_patch(int mo)
+{
+  int  ad,ke,a,n,i,j,i0,p=0,x=0,y=0,xx,yy;
+  char tmp0[256];
+
+  pch_fld(mo+1);selno=0;
+  while(1){
+    for(i=p*64;i<p*64+64;i++){
+      i0=i;if((cmdflag&0x20)!=0){i0++;}
+      strcpy(tmp0,fstr(i0,3));strcat(tmp0,":");
+      strcat(tmp0,cm6_tone_name(mo,i));
+      tdis(((i&63)>>4)*20,(i&15)+14,tmp0,19,3);
+    }
+
+    while( 1){
+      i=y+x*16+p*64;
+      if(mo==0){ad=0xa34+i*8;}else{ad=0x4eb2+i*19;}
+      pat_para_dis(mo,ad);
+
+      xx=x*20+4;yy=y+14;
+      strcpy(tmp0,cm6_tone_name(mo,i));
+      tdis( xx,yy,tmp0,15,11);
+      ke=inkey3();a=ke&0xff;
+
+      if(a=='K'||a=='k'){keyd_inp(0);}
+      if(a=='V'||a=='v'){keyd_inp(1);}
+      if(a==0x9){
+       tdis( xx,yy,tmp0,15,9);
+       pat_para_set(mo,ad,i);
+      }
+
+      if(a=='C'||a=='c'){
+       card_sel();pch_fld(mo+1);break;
+      }
+
+      if( a==0x05 ){y--;if( y<0 ){y=15;}}
+      if( a==0x18 ){y++;if( y>15 ){y=0;}}
+      if( a==0x13 ){x--;if( x<0 ){x=3;}}
+      if( a==0x04 ){x++;if( x>3 ){x=0;}}
+      if( a==0x17 ){if( p>0 ){p--;break;}}
+      if( a==0x12 ){if( p<1 ){p++;break;}}
+
+      if(a==0x15){
+       if(mo==0){
+         s_test(2,-1,i,tkey,tvel);
+       }else{
+         s_test(11,-1,i,tkey,tvel);
+       }
+      }
+
+      if( a==13 ){
+       tdis(xx,yy,tmp0,15,9);
+       if(mo==0){
+         n=cm6_tonesel(0);
+         if( n>=0 ){
+           cm6[ad]=n>>6;cm6[ad+1]=n & 0x3f;
+           cm6_la_write(i);
+           if(n>127 && n<192 ){
+             if(trf[n-128]==0){
+               trf[n-128]=1;
+               cm6_tone_write(n-128);
+             }
+           }
+         }
+       }else{
+         n=cm6_tonesel(2);
+         if( n>=0 ){
+           cm6[ad]=n>>7;cm6[ad+1]=n & 0x7f;
+           cm6_pcm_write(i);
+         }
+       }
+       break;
+      }
+      if( a==32 ){
+       if(mo==0){
+         for(j=0;j<8;j++){cm6[ad+j]=la_para[j];}
+         cm6[ad]=i>>6;cm6[ad+1]=i & 0x3f;
+         cm6_la_write(i);
+       }else{
+         for(j=0;j<20;j++){cm6[ad+j]=pcm_para[j];}
+         cm6[ad]=i>>6;
+         if(i>63){cm6[ad+1]=i-64;}else{cm6[ad+1]=pcmpat[i];}
+         cm6_pcm_write(i);
+       }
+       break;
+      }
+      tdis( xx,yy,tmp0,15,3);
+
+      if(a=='Z' || a=='z'){timtra();trns_check();}
+
+      if(a>=0xf0){return(ke);}
+      if( a==27 ){return(0xf0);}
+    }
+  }
+}
+
+/***************************/
+void   pat_para_set(int mo,int ad,int i)
+{
+  int  a,s,v,x=0,y=0,xx,yy;
+
+  while(1){
+    pat_para_dis(mo,ad);s=x*5+y;xx=20+x*20;yy=y+6;
+    tcur(xx,yy,19,3);a=inkey3()&0xff;
+    if(a==0x15){
+      if(mo==0){s_test(2,-1,i,tkey,tvel);}else{
+       s_test(11,-1,i,tkey,tvel);}}
+    tcur(xx,yy,19,3);
+
+    if(a=='Z'||a=='z'){timtra();trns_check();}
+    if(a=='K'||a=='k'){keyd_inp(0);}
+    if(a=='V'||a=='v'){keyd_inp(1);}
+
+    if( a==0x05 ){y--;if( y<0 ){y=4;}}
+    if( a==0x18 ){y++;if( y>4){y=0;}}
+    if( a==0x13 ){x--;if( x<0 ){x=2;}}
+    if( a==0x04 ){x++;if( x>2){x=0;}}
+
+    if( a==13 ){
+      B_LOCATE(xx+16,yy);
+      if(mo==0){
+       if(s==0){
+         v=vinput(cm6[ad+2]-24,0x803);
+         if(es==0 && v>=-24 && v<=24){cm6[ad+2]=v+24;}
+       }
+       if(s==1){
+         v=vinput(cm6[ad+3]-50,0x803);
+         if(es==0 && v>=-50 && v<=50){cm6[ad+3]=v+50;}
+       }
+       if(s==2){
+         v=vinput(cm6[ad+4],0x803);
+         if(es==0 && v>=-24 && v<=24){cm6[ad+4]=v;}
+       }
+       if(s==3){
+         cm6[ad+5]=(cm6[ad+5]+1)&3;
+       }
+       if(s==4){
+         cm6[ad+6]=(cm6[ad+6]+1)&1;
+       }
+       cm6_la_write(i);
+      }else{
+       if(s==0){
+         v=vinput(cm6[ad+2]-12,0x803);
+         if(es==0 && v>=-12 && v<=12){cm6[ad+2]=v+12;}
+       }
+       if(s==1){
+         v=vinput(cm6[ad+3]-50,0x803);
+         if(es==0 && v>=-50 && v<=50){cm6[ad+3]=v+50;}
+       }
+       if(s==2){
+         v=vinput(cm6[ad+4]-12,0x803);
+         if(es==0 && v>=-12 && v<=12){cm6[ad+4]=v+12;}
+       }
+       if(s==3){
+         cm6[ad+7]=(cm6[ad+7]+1)&3;
+       }
+       if(s==4){
+         cm6[ad+8]=(cm6[ad+8]+1)&1;
+       }
+       if(s>4 && s<14){
+         v=vinput(cm6[ad+4+s],0x803);
+         if(s>5 && s<9){
+           if(es==0 && v>=0 && v<=127){cm6[ad+4+s]=v;}
+         }else{
+           if(es==0 && v>=0 && v<=15){cm6[ad+4+s]=v;}
+         }
+       }
+       if(s==14){
+         v=vinput(cm6[ad+18],0x803);
+         if(es==0 && v>=0 && v<=50){cm6[ad+18]=v;}
+       }
+       cm6_pcm_write(i);
+      }
+    }
+    if( a==27 ){break;}
+  }
+}
+
+/***************************/
+void   pat_para_dis(int m,int ad)
+{
+  char tmp0[256];
+  int  sv;
+
+  sv=SUPER(0);
+
+  if(m==0){
+    strcpy(tmp0," Key Shift     : ");strcat(tmp0,fstr(cm6[ad+2]-24,3));
+    B_LOCATE(19,6);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Fine Tune     : ");strcat(tmp0,fstr(cm6[ad+3]-50,3));
+    B_LOCATE(19,7);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Bender Range  : ");strcat(tmp0,fstr(cm6[ad+4],3));
+    B_LOCATE(19,8);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Assign Mode  :POLY");strcat(tmp0,fstr(cm6[ad+5]+1,1));
+    B_LOCATE(19,9);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Reverb Switch : ");strcat(tmp0,swi_str[cm6[ad+6]&1]);
+    B_LOCATE(19,10);H_PRINT(tmp0,"","");
+  }else{
+    strcpy(tmp0," Key Shift     : ");strcat(tmp0,fstr(cm6[ad+2]-12,3));
+    strcat(tmp0," Velocity Sens : ");strcat(tmp0,fstr(cm6[ad+9],3));
+    strcat(tmp0," LFO Aut Rise T: ");strcat(tmp0,fstr(cm6[ad+14],3));
+    B_LOCATE(19,6);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Fine Tune     : ");strcat(tmp0,fstr(cm6[ad+3]-50,3));
+    strcat(tmp0," ENV Att Rate  : ");strcat(tmp0,fstr(cm6[ad+10],3));
+    strcat(tmp0," LFO Auto Depth: ");strcat(tmp0,fstr(cm6[ad+15],3));
+    B_LOCATE(19,7);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Bender Range  : ");strcat(tmp0,fstr(cm6[ad+4],3));
+    strcat(tmp0," ENV Rel Rate  : ");strcat(tmp0,fstr(cm6[ad+11],3));
+    strcat(tmp0," LFO Man Rise T: ");strcat(tmp0,fstr(cm6[ad+16],3));
+    B_LOCATE(19,8);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Assign Mode  :POLY");strcat(tmp0,fstr(cm6[ad+7]+1,1));
+    strcat(tmp0," LFO Rate      : ");strcat(tmp0,fstr(cm6[ad+12],3));
+    strcat(tmp0," LFO Man Depth : ");strcat(tmp0,fstr(cm6[ad+17],3));
+    B_LOCATE(19,9);H_PRINT(tmp0,"","");
+
+    strcpy(tmp0," Reverb Switch : ");strcat(tmp0,swi_str[cm6[ad+8]&1]);
+    strcat(tmp0," LFO Aut Dlay T: ");strcat(tmp0,fstr(cm6[ad+13],3));
+    strcat(tmp0," Detune Depth  : ");strcat(tmp0,fstr(cm6[ad+18],3));
+    B_LOCATE(19,10);H_PRINT(tmp0,"","");
+  }
+  SUPER(sv);
+}
+
+/***************************/
+int    rhy_patch()
+{
+  int  ke,a,n,i,ad,p=0,x=0,y=0,v,xx,yy,s,ln;
+  char tmp0[256];
+
+  pch_fld(3);selno=0;
+
+  while(1){
+    for(i=p*32;i<p*32+32;i++){
+      if(i<85){
+       ad=0x130+i*4;
+       strcpy(tmp0,fstr(i+24,3));strcat(tmp0,":");
+       strcat(tmp0,cm6_tone_name(2,i));
+       strcat(tmp0,fstr(cm6[ad+1],6));strcat(tmp0,fstr(cm6[ad+2]-7,6));
+       strcat(tmp0,"   ");strcat(tmp0,swi_str[cm6[ad+3]&1]);
+      }else{tmp0[0]=0;}
+      tdis( ((i&31)>>4)*40+1,(i&15)+14,tmp0,19+18,3);
+    }
+
+    while( 1){
+      i=y+(x>>2)*16+p*32;ad=0x130+i*4;s=x&3;
+      xx=(x>>2)*40+5;yy=y+14;
+      if(s>0){ln=5;xx=xx+11+s*6;}else{ln=15;}
+      if(i<85){
+       if(s==0){strcpy(tmp0,cm6_tone_name(2,i));}
+       if(s==1){strcpy(tmp0,fstr(cm6[ad+1],4));}
+       if(s==2){strcpy(tmp0,fstr(cm6[ad+2]-7,4));}
+       if(s==3){strcpy(tmp0," ");strcat(tmp0,swi_str[cm6[ad+3]&1]);}
+      }else{tmp0[0]=0;}
+      tdis(xx,yy,tmp0,ln,11);
+      ke=inkey3();a=ke&0xff;
+
+      if(a==0x15){s_test(10,-1,0,i+24,tvel);}
+      if(a=='Z'||a=='z'){timtra();trns_check();}
+      if(a=='K'||a=='k'){keyd_inp(0);}
+      if(a=='V'||a=='v'){keyd_inp(1);}
+      tdis( xx,yy,tmp0,ln,3);
+
+      if( a==0x05 ){y--;if( y<0 ){y=15;}}
+      if( a==0x18 ){y++;if( y>15 ){y=0;}}
+      if( a==0x13 ){x--;if( x<0 ){x=7;}}
+      if( a==0x04 ){x++;if( x>7 ){x=0;}}
+      if( a==0x17 ){if( p>0 ){p--;break;}}
+      if( a==0x12 ){if( p<2 ){p++;break;}}
+
+      if( i<85){
+       if( a==13 ){
+         if( s==0){
+           tdis(xx,yy,tmp0,ln,9);
+           n=cm6_tonesel(1);
+           if( n>=0 ){
+             cm6[ad]=n;
+             if(n<64){
+               if(trf[n]==0){
+                 trf[n]=1;
+                 cm6_tone_write(n);
+               }
+             }
+           }
+         }
+         if(s==1){
+           B_LOCATE(xx+1,yy);v=vinput(cm6[ad+1],0x803);
+           if(es==0 && v>=0 && v<101){cm6[ad+1]=v;}
+         }
+         if(s==2){
+           B_LOCATE(xx+2,yy);v=vinput(cm6[ad+2]-7,0x802)+7;
+           if(es==0 && v>=0 && v<15){cm6[ad+2]=v;}
+         }
+         if(s==3){cm6[ad+3]=1-cm6[ad+3];}
+       }
+       if( a==32 ){
+         cm6[ad]=rsetup[i*2];cm6[ad+1]=0x64;
+         cm6[ad+2]=rsetup[i*2+1];cm6[ad+3]=1;
+       }
+       if( a==32 || a==13){
+         cm6_write(3*128*128+1*128+16+i*4,ad,4);
+       }
+      }
+
+      if(a>=0xf0){return(ke);}
+      if( a==27 ){return(0xf0);}
+    }
+  }
+}
+
+/***************************/
+int    user_tone_list()
+{
+  int  ad1,ad2,a,d,n=-1,i,j,x=0,y=0,xx,yy;
+  char tmp0[256];
+
+  pch_fld(4);
+  while(1){
+    for(i=0;i<64;i++){
+      strcpy(tmp0,fstr(i+1,3));strcat(tmp0,": ");
+      strcat(tmp0,tim_name[i+128]);
+      tdis((i>>4)*20,(i&15)+14,tmp0,15,3);
+      if(n==i){tcur( (i>>4)*20+1,(i&15)+14,3,3);}
+    }
+
+    while( 1){
+      i=y+x*16;xx=x*20+5;yy=y+14;
+      strcpy(tmp0,tim_name[i+128]);
+
+      tdis(xx,yy,tmp0,10,11);
+      a=inkey3();
+      tdis(xx,yy,tmp0,10,3);
+
+      if((a&0xff)>=0xf0){return(a);}
+      a=a&0xff;
+
+      if(a=='Z'||a=='z'){timtra();trns_check();}
+
+      if( a==0x05 ){y--;if( y<0 ){y=15;}}
+      if( a==0x18 ){y++;if( y>15 ){y=0;}}
+      if( a==0x13 ){x--;if( x<0 ){x=3;}}
+      if( a==0x04 ){x++;if( x>3 ){x=0;}}
+
+      if( a==32 ){n=i;break;}
+
+      if( (a=='X'||a=='x') && n>=0){
+       strcpy(tmp0,tim_name[i+128]);
+       strcpy(tim_name[i+128],tim_name[n+128]);
+       strcpy(tim_name[n+128],tmp0);
+
+       ad1=0xe34+i*256;ad2=0xe34+n*256;trf[n]=1;trf[i]=1;
+       for(j=0;j<256;j++){
+         d=cm6[ad1];cm6[ad1]=cm6[ad2];cm6[ad2]=d;ad1++;ad2++;
+       }
+       cm6_tone_write(i);cm6_tone_write(n);
+       break;
+      }
+
+      if( a==12 ){
+       msg(_("Clear control data"));
+       if(yn_sel()>0){
+         tim_name[i+128][0]=0;
+         ad1=0xe34+i*256;trf[i]=1;
+         for(j=0;j<256;j++){cm6[ad1]=0;ad1++;}
+         cm6_tone_write(i);
+       }
+      }
+
+      if( a==13 ){
+       B_LOCATE(xx,yy);sinput(tim_name[i+128],10);
+       strcpy(tmp0,spadd(tim_name[i+128],10));
+       for(j=0;j<10;j++){cm6[0xe34+i*256+j]=tmp0[j];}
+       cm6_tone_write(i);
+      }
+
+      if( a==27 ){return(0xf0);}
+    }
+  }
+}
+/***************************/
+int    cm6_tonesel(int slmd)
+{
+  int  a,i,p=0,y=0,g,stpo,gmax,nm;
+  char tmp0[256];
+
+  fill(640,684,767,1004,0);
+  box(644,684,767,1004,14,65535);box(645,724,766,1003,14,65535);
+  fill(644,684,767,724,14);
+
+  stpo=slmd*128;p=selno&0xf0;y=selno&15;
+
+  if(slmd==0){
+    g=2;gmax=3;nm=64;
+  }else{
+    g=0;gmax=1;
+    if(slmd==1){nm=64;}else{nm=128;}
+  }
+
+  while(1){
+    B_LOCATE(81,11);B_PRINT("## TONE LIST ##");
+    B_LOCATE(83,12);B_PRINT(tone_title[slmd*2+g]);
+
+    for(i=p;i<p+16;i++){
+      strcpy(tmp0,fstr(i+1,3));strcat(tmp0,":");
+      strcat(tmp0,tim_name[i+g*nm+stpo]);
+      tdis(81,(i-p)+14,tmp0,14,3);
+    }
+    while( 1){
+      i=y+p;
+      tcur(85,y+14,10,3);
+      a=inkey2();
+      tcur(85,y+14,10,3);
+
+      if( a==0x13 ){g--;if(g<0   ){g=gmax;}break;}
+      if( a==0x04 ){g++;if(g>gmax){g=0;}break;}
+      if( a==0x05 ){
+       y--;if( y<0 ){y=0;if( p>0 ){p--;break;}}
+      }
+      if( a==0x18 && i+1<nm){
+       y++;if( y>15 ){y=15;if( p+16<nm ){p++;break;}}
+      }
+      if( a==0x17 ){if( p>0 ){p-=16;if(p<0){p=0;}break;}else{y=0;}}
+
+      if( a==0x12 ){if( p+16<nm ){p+=16;if(p+16>nm){p=nm-16;}
+      if(p+y>=nm){y=(nm-1)-p;}break;
+      }else{y=(nm-1)-p;if(y<0){y=0;}}}
+      /*
+       if( a==9 ){
+       int n;
+       msg("Tone No.=");n=vinput(p+y+1,0x803)-1;msg_clr();
+       if( es==0 && n>=0 && n<nm){
+       p=n&0xf0;y=n&15;break;
+       }
+       }
+       */
+      if( a==13 || a==27 ){break;}
+    }
+    if( a==13 || a==27 ){break;}
+  }
+  txerase(80*8,11*16,16*8,20*16);fill(640,684,767,1004,0);
+  selno=p+y;
+  if( a==13 ){return(y+p+g*nm);}else{return(-1);}
+}
+
+/***************************/
+void   cminit()
+{
+  int  i,j,ad,m;
+
+  /* system */
+  for(i=0;i<64  ;i++){cm6[i]=cm6_info[i];cm6[i+64]=32;}
+  for(i=0;i<32  ;i++){cm6[i+0x80  ]=la_sys[i];}
+  for(i=0;i<144 ;i++){cm6[i+0xa0  ]=la_tmp[i];}
+  for(i=0;i<1968;i++){cm6[i+0x284 ]=la_tim_tmp[i];}
+  for(i=0;i<126 ;i++){cm6[i+0x4e34]=pcm_tmp[i];}
+  for(i=0;i<23  ;i++){cm6[i+0x5832]=pcm_sys[i];}
+
+  m=(mdlflag&3);
+  for(i=0;i<128;i++){
+    /* la_patch */
+    ad=0xa34+i*8;cm6[ad]=i>>6;cm6[ad+1]=i&63;
+    for(j=2;j<8;j++){cm6[ad+j]=la_para[j];}
+    /* pcm patch */
+    ad=0x4eb2+i*19;
+    if(m==1){
+      if(i<64){
+       cm6[ad]=0;cm6[ad+1]=pcmpat[i];
+      }else{
+       cm6[ad]=1;cm6[ad+1]=i-64;
+      }
+    }else{
+      cm6[ad]=0;cm6[ad+1]=i;
+    }
+    for(j=2;j<19;j++){cm6[ad+j]=pcm_para[j];}
+  }
+
+  /* rhythm setup */
+  for(i=0;i<85;i++){
+    ad=0x130+i*4;
+    cm6[ad]=rsetup[i*2];cm6[ad+2]=rsetup[i*2+1];
+    cm6[ad+1]=0x64;cm6[ad+3]=1;
+  }
+
+  /* timbre */
+  for(i=0xe34;i<0x4e34;i++){cm6[i]=0;}
+  for(i=0;i<64;i++){tim_name[i+128][0]=0;}
+}
+
+/***************************/
+void   cm6_write(int ad,int ad2,int ln)
+{
+  int  i,a,by,sum;
+  static       unsigned char   send[5]= {0xf0,0x41,0x10,0x16,0x12};
+  unsigned char        para[5];
+  unsigned char        buf[280];
+
+  while(ln>0){
+    int pp=0;
+    if(ln<256){by=ln;}else{by=256;}
+
+    for(i=0;i<5;i++){buf[pp++]=send[i];}
+    para[0]=(ad>>14)& 0x7f;para[1]=(ad>>7)& 0x7f;para[2]=ad & 0x7f;
+    sum=0;for(i=0;i<3;i++){a=para[i];buf[pp++]=a;sum=sum+a;}
+    for(i=0;i<by;i++){a=cm6[ad2+i]&0x7f;buf[pp++]=a;sum=sum+a;}
+    buf[pp++]=(128-(sum&0x7f))&0x7f;buf[pp++]=0xf7;
+
+    buf[pp++]=0xff;(*rcd->mix_out)((char *)buf);
+    ad=ad+by;ad2=ad2+by;ln=ln-by;twait(3);
+  }
+}
+
+/***************************/
+void   cm6_tone_write(int i)
+{
+  cm6_write(8*128*128+i*256,0xe34+i*256,256);
+}
+void   cm6_la_write(int i)
+{
+  cm6_write(5*128*128+i*8,0xa34+i*8,8);
+}
+void   cm6_pcm_write(int i)
+{
+  cm6_write(0x51*128*128+i*19,0x4eb2+i*19,19);
+}
+
+/***************************/
+void   trns_check()
+{
+  int  ex,i,ad;
+
+  for(i=0;i<64;i++){
+    trf[i]=0;ad=0xe34+i*256;
+    if((cm6[ad]==0||cm6[ad]==32)&&(cm6[ad+10]+cm6[ad+16]+cm6[ad+32]+cm6[ad+48]==0)){trf[i]=1;}
+  }
+  for(i=0;i<128;i++){ad=0xa34+i*8;if(cm6[ad]==2){trf[cm6[ad+1]]=1;}}
+  for(i=0;i<85;i++){ex=cm6[0x130+i*4];if(ex<64){trf[ex]=1;}}
+}
+
+/***************************/
+void   timtra()
+{
+  all_note_off(1);
+  rcd->data_valid=0;rcd->word_valid=0;rcd->tone_valid=0;rcd->gsd_valid=0;
+  (*rcd->init)();
+
+  if(cm6_file[0]==0 && gsd_file[0]==0){
+    if(init_exc_data[0]!=255){(*rcd->setup)();
+    }else{(*rcd->mix_out)((char *)init_exc_data);twait(12);}
+  }else{
+    if((mdlflag&3)!=0){
+      if( cm6_file[0]!=0 ){
+       msg(_("Sending control data ..."));tim_buf_trns();
+      }
+      if( gsd_file[0]!=0 ){
+       msg(_("Sending control data ..."));gsd_buf_trns();
+      }
+      (*rcd->setup)();
+      msg_clr();
+    }
+  }
+}
+
+/***************************/
+void   all_note_off(int m)
+{
+  int  i;
+
+  (*rcd->end)();
+  if((cmdflag&0x40)!=0){
+    /*allnoteoff*/
+    for(i=0;i<16;i++){
+      (*rcd->md_put2)(0xb0+i);(*rcd->md_put2)(0x7b);(*rcd->md_put2)(0);
+    }
+    twait(4);
+  }
+  /*resetall*/
+  if(m<2){
+    for(i=0;i<16;i++){
+      (*rcd->md_put2)(0xb0+i);(*rcd->md_put2)(0x79);(*rcd->md_put2)(0);
+    }
+    twait(4);
+  }
+  if((mdlflag&3)==1){
+    if(cm6_file[0]!=0 || m==0 ){
+      cm6_write(0x10*128*128,0x80,23);cm6_write(0x52*128*128,0x5832,17);
+      twait(2);
+    }else{
+      /*cm6_write(0x7f*128*128,0,1);
+       sc55_write(16*128*128+66*128+127,0,1);
+       twait(6);*/
+    }
+  }
+}
+
+/***************************/
+void   temporary_set()
+{
+  if(rcd->act==0){
+    if((mdlflag&3)==1){
+      cm6_write(0x3*128*128,0xa0,144);
+      /*cm6_write(0x4*128*128,0x284,1968);*/
+      cm6_write(0x50*128*128,0x4e34,126);
+    }
+  }
+}
+
+/***************************/
+
+static char *cm6_tone_name_tmp;
+
+char   *cm6_tone_name(int mo,int i)
+{
+  int  i0,n,nn;
+  char tmp0[128],tmp1[128];
+
+  if(mo==0){
+    /*la tone*/
+    i0=cm6[0xa34+i*8]*64+cm6[0xa35+i*8];n=i0&63;nn=i0>>6;
+  }else{
+    if(mo==1){
+      /*pcm tone*/
+      i0=cm6[0x4eb2+i*19]*128+cm6[0x4eb3+i*19]+256;n=i0&127;nn=(i0>>7)+2;
+    }else{
+      /*la rhythm*/
+      i0=cm6[0x130+i*4]+128;n=i0&63;nn=i0>>6;
+    }
+  }
+
+  b_striS(tmp1,128,n+1);strcpy(tmp0,"000");strcat(tmp0,tmp1);
+  strcpy(tmp0,&tmp0[strlen(tmp0)-4]);tmp0[0]=tone_hed[nn];
+  strcat(tmp0," ");strcat(tmp0,spadd(tim_name[i0],10));
+  cm6_tone_name_tmp = tmp0;
+  return(cm6_tone_name_tmp);
+}
+
+/***************************//*100/1*/
+void   twait(int ti)
+{
+  int  a,b;
+
+  a=ONTIME();
+  while(ti>0){b=ONTIME();if(b!=a){a=b;ti--;}}
+}
+
+/***************************/
+void   gsd_con()
+{
+  int  ex;
+
+  all_note_off(0);
+  msg_clr();gsd_buf_trns();fnc_dis(-1);C_FNKMOD(0);dpl(0);
+  ex=exe("ge.x");C_FNKMOD(3);if(ex>0){key_pause();}
+  C_FNKMOD(3);C_CUROFF();B_COLOR(3);fnc_dis(-1);gsd_var_read();
+
+  C_WINDOW(0,31);OnGraphic();dpl(1);
+  WINDOW(0,0,1023,1023);
+
+  if(ex<0){msg(_("Cannot execute: GE.x"));}
+  sdis2(72,64,gsd_file,15,15,0);
+}
+
+/***************************/
+void   gsinit()
+{
+  int  i,j;
+
+  for(i=0;i<54;i++){gsd[i]=gsd_sys[i];}
+  for(j=0;j<16;j++){
+    for(i=0;i<122;i++){gsd[j*122+i+0x36]=gsd_part[i];}
+    gsd[j*122+0x38]=j;gsd[j*122+121+0x36]=gsd_rsv[j];
+  }
+  gsd[9*122+0x14+0x36]=0;gsd[9*122+0x15+0x36]=1;
+  for(i=0;i<332;i++){gsd[i+0x7d6]=gsd_rhy[i];gsd[i+0x922]=gsd_rhy[i];}
+  for(i=0;i<5;i++){gsd[i+0xa70-2]=gsd_data[i];}
+}
+
+/***************************/
diff --git a/config.h b/config.h
new file mode 100644 (file)
index 0000000..afa5709
--- /dev/null
+++ b/config.h
@@ -0,0 +1,212 @@
+#pragma once
+
+/* config.h.  Generated automatically by configure.  */
+/* config.h.in.  Generated automatically from configure.in by autoheader.  */
+
+/* Define if using alloca.c.  */
+/* #undef C_ALLOCA */
+
+/* Define to empty if the keyword does not work.  */
+/* #undef const */
+
+/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
+   This function is required for alloca.c support on those systems.  */
+/* #undef CRAY_STACKSEG_END */
+
+/* Define if you have alloca, as a function or macro.  */
+#define HAVE_ALLOCA 1
+
+/* Define if you have <alloca.h> and it should be used (not on Ultrix).  */
+#define HAVE_ALLOCA_H 1
+
+/* Define if you have a working `mmap' system call.  */
+#define HAVE_MMAP 1
+
+/* Define if you have <sys/wait.h> that is POSIX.1 compatible.  */
+/* #undef HAVE_SYS_WAIT_H */
+
+/* Define as __inline if that's what the C compiler calls it.  */
+#define inline __inline
+
+/* Define to `long' if <sys/types.h> doesn't define.  */
+/* #undef off_t */
+
+/* Define to `int' if <sys/types.h> doesn't define.  */
+/* #undef pid_t */
+
+/* Define if you need to in order for stat and other things to work.  */
+/* #undef _POSIX_SOURCE */
+
+/* Define as the return type of signal handlers (int or void).  */
+#define RETSIGTYPE void
+
+/* Define to `unsigned' if <sys/types.h> doesn't define.  */
+/* #undef size_t */
+
+/* If using the C implementation of alloca, define if you know the
+   direction of stack growth for your system; otherwise it will be
+   automatically deduced at run-time.
+ STACK_DIRECTION > 0 => grows toward higher addresses
+ STACK_DIRECTION < 0 => grows toward lower addresses
+ STACK_DIRECTION = 0 => direction of growth unknown
+ */
+/* #undef STACK_DIRECTION */
+
+/* Define if you have the ANSI C header files.  */
+#define STDC_HEADERS 1
+
+/* Define if you can safely include both <sys/time.h> and <time.h>.  */
+/* #undef TIME_WITH_SYS_TIME 1 */
+
+/* Define if your <sys/time.h> declares struct tm.  */
+/* #undef TM_IN_SYS_TIME */
+
+/* Define if the X Window System is missing or not being used.  */
+/* #undef X_DISPLAY_MISSING */
+
+#define PACKAGE "sted2+"
+#define VERSION "20010519"
+/* #undef HAVE_CATGETS */
+/* #undef HAVE_GETTEXT */
+/* #undef HAVE_LC_MESSAGES */
+#define HAVE_STPCPY 1
+/* #undef ENABLE_NLS */
+#define NO_SHM 1
+/* #undef USE_CURSES */
+#ifdef WIN32
+# define STED_DEFAULT_PATH "C:/Program Files/STed2"
+#else
+# define STED_DEFAULT_PATH "/usr/local/lib/sted"
+#endif
+#define STED 1
+/* #undef HAS_CURSES */
+/* #undef USE_SUNOS_CURSES */
+/* #undef USE_BSD_CURSES */
+/* #undef USE_SYSV_CURSES */
+/* #undef USE_NCURSES */
+/* #undef NO_COLOR_CURSES */
+/* #undef SCO_FLAVOR */
+/* #undef NCURSES_970530 */
+/* #undef NO_SETLOCALE */
+#define NO_XSETLOCALE 1
+/* #undef NO_XLOCALE */
+/* #undef SJIS_CODES */
+#define HAVE_MVWCHGAT 1
+
+/* Define if you have the __argz_count function.  */
+#define HAVE___ARGZ_COUNT 1
+
+/* Define if you have the __argz_next function.  */
+#define HAVE___ARGZ_NEXT 1
+
+/* Define if you have the __argz_stringify function.  */
+#define HAVE___ARGZ_STRINGIFY 1
+
+/* Define if you have the dcgettext function.  */
+#define HAVE_DCGETTEXT 1
+
+/* Define if you have the getcwd function.  */
+#define HAVE_GETCWD 1
+
+/* Define if you have the getpagesize function.  */
+#define HAVE_GETPAGESIZE 1
+
+/* Define if you have the gettimeofday function.  */
+#define HAVE_GETTIMEOFDAY 1
+
+/* Define if you have the memcpy function.  */
+#define HAVE_MEMCPY 1
+
+/* Define if you have the munmap function.  */
+#define HAVE_MUNMAP 1
+
+/* Define if you have the putenv function.  */
+#define HAVE_PUTENV 1
+
+/* Define if you have the select function.  */
+#define HAVE_SELECT 1
+
+/* Define if you have the setenv function.  */
+#define HAVE_SETENV 1
+
+/* Define if you have the setlocale function.  */
+#define HAVE_SETLOCALE 1
+
+/* Define if you have the stpcpy function.  */
+#define HAVE_STPCPY 1
+
+/* Define if you have the strcasecmp function.  */
+#define HAVE_STRCASECMP 1
+
+/* Define if you have the strchr function.  */
+#define HAVE_STRCHR 1
+
+/* Define if you have the strdup function.  */
+#define HAVE_STRDUP 1
+
+/* Define if you have the strstr function.  */
+#define HAVE_STRSTR 1
+
+/* Define if you have the <argz.h> header file.  */
+#define HAVE_ARGZ_H 1
+
+/* Define if you have the <dirent.h> header file.  */
+/* #undef HAVE_DIRENT_H */
+
+/* Define if you have the <fcntl.h> header file.  */
+#define HAVE_FCNTL_H 1
+
+/* Define if you have the <limits.h> header file.  */
+#define HAVE_LIMITS_H 1
+
+/* Define if you have the <locale.h> header file.  */
+#define HAVE_LOCALE_H 1
+
+/* Define if you have the <malloc.h> header file.  */
+#define HAVE_MALLOC_H 1
+
+/* Define if you have the <ndir.h> header file.  */
+/* #undef HAVE_NDIR_H */
+
+/* Define if you have the <nl_types.h> header file.  */
+#define HAVE_NL_TYPES_H 1
+
+/* Define if you have the <string.h> header file.  */
+#define HAVE_STRING_H 1
+
+/* Define if you have the <strings.h> header file.  */
+#define HAVE_STRINGS_H 1
+
+/* Define if you have the <sys/dir.h> header file.  */
+/* #undef HAVE_SYS_DIR_H */
+
+/* Define if you have the <sys/ndir.h> header file.  */
+/* #undef HAVE_SYS_NDIR_H */
+
+/* Define if you have the <sys/param.h> header file.  */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define if you have the <sys/time.h> header file.  */
+/* #undef HAVE_SYS_TIME_H */
+
+/* Define if you have the <unistd.h> header file.  */
+/* #undef HAVE_UNISTD_H */
+
+/* Define if you have the i library (-li).  */
+/* #undef HAVE_LIBI */
+
+/* Define if you have the intl library (-lintl).  */
+/* #undef HAVE_LIBINTL */
+
+/* Name of package */
+#define PACKAGE "sted2+"
+
+/* Version number of package */
+#define VERSION "20010519"
+
+/* */
+
+#ifndef PI
+#define PI 3.1415926535897
+#endif /* PI */
+
diff --git a/config.h.in b/config.h.in
new file mode 100644 (file)
index 0000000..a0cbd8a
--- /dev/null
@@ -0,0 +1 @@
+/* config.h.in.  Generated automatically from configure.in by autoheader.  */
diff --git a/configure.in b/configure.in
new file mode 100644 (file)
index 0000000..4b0aa34
--- /dev/null
@@ -0,0 +1,210 @@
+dnl Process this file with autoconf to produce a configure script.
+AC_INIT(sted2/sted.c)
+AM_CONFIG_HEADER(config.h)
+AM_INIT_AUTOMAKE(sted2+,`sed -n -e 's/^.*VERSION.*"\(.*\)"$/\1/p' ${srcdir}/sted2/version.h`)
+PACKAGE="sted2+"
+VERSION=`sed -n -e 's/^.*VERSION.*"\(.*\)"$/\1/p' ${srcdir}/sted2/version.h`
+AC_SUBST(PACKAGE)
+AC_SUBST(VERSION)
+
+dnl Checks for programs.
+dnl if test -z "${CFLAGS}"; then
+dnl   if test -z "${CCOPTS}"; then
+dnl     CCOPTS="-O2 -fomit-frame-pointer"
+dnl   fi
+dnl   CFLAGS="$CCOPTS"
+dnl fi
+
+AC_PROG_CC
+
+dnl Set of available languages.
+ALL_LINGUAS="ja"
+AM_GNU_GETTEXT
+AC_CHECK_FUNC(gettext,,AC_CHECK_LIB(intl,gettext))
+
+dnl Misc definition
+AC_PROG_INSTALL
+AC_PROG_RANLIB
+AC_PATH_X
+AC_PATH_XTRA
+
+dnl Checks for header files.
+AC_HEADER_DIRENT
+AC_HEADER_STDC
+AC_HEADER_SYS_WAIT
+AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h strings.h)
+
+dnl Checks for typedefs, structures, and compiler characteristics.
+AC_C_INLINE
+AC_STRUCT_TM
+AC_C_CONST
+AC_TYPE_PID_T
+AC_TYPE_SIZE_T
+AC_HEADER_TIME
+
+dnl Checks for library functions.
+AC_TYPE_SIGNAL
+AC_CHECK_FUNCS(getcwd gettimeofday putenv select strstr memcpy)
+
+dnl for defload.c
+AC_DEFINE(STED)
+
+dnl Locale definition
+
+dnl Check for curses
+AM_CONDITIONAL(HAS_CURSES, test "$has_curses" = true)
+AC_CHECK_CURSES
+
+AC_ARG_ENABLE(curses, [  --disable-curses        trun off using curses [default no]],curses_given=yes,curses_given=no)
+AC_MSG_CHECKING(whether to enable curses)
+if "$has_curses" = "true"; then
+  if test x$enableval = xyes -o x$curses_given = xno; then
+    AC_MSG_RESULT(yes)
+    AC_DEFINE(USE_CURSES)
+  else
+    AC_MSG_RESULT(no)
+  fi
+else
+  AC_MSG_RESULT(no)
+fi
+
+dnl Check for function 'mvwchgat' in any curses libraries
+
+oldlibs=$LIBS
+LIBS="$LIBS $CURSES_LIBS"
+AC_CHECK_FUNC( mvwchgat, AC_DEFINE(HAVE_MVWCHGAT) )
+LIBS="$oldlibs"
+
+dnl local definitions
+dnl Shared memory
+AC_ARG_ENABLE(shm, [  --enable-shm            trun on using shared memory [default yes]],shm_given=yes,shm_given=no)
+AC_MSG_CHECKING(whether to enable shared memory)
+if test x$shm_given = xyes -o x$enableval = xno; then
+  AC_MSG_RESULT(no)
+  AC_DEFINE(NO_SHM)
+else
+  AC_MSG_RESULT(yes)
+fi
+
+dnl STED_DEFAULT_PATH
+AC_ARG_WITH(default_path,
+[  --with-default-path=DIR uses DIR as sted2.[cnf,fon] path],
+       if test "$withval" != "NONE"; then
+       sted_default_path="${withval}"
+       else
+       sted_default_path="/usr/local/lib/sted"
+       fi,
+       sted_default_path="/usr/local/lib/sted" )
+
+AC_DEFINE_UNQUOTED(STED_DEFAULT_PATH, "${sted_default_path}")
+AC_SUBST(sted_default_path)
+
+dnl Check for SJIS environment
+AC_ARG_ENABLE(sjis,
+[  --enable-sjis           enable Japanese code as SJIS [default no]],
+sjis_given=yes, sjis_given=no)
+AC_MSG_CHECKING(wether to enable sjis conversion)
+if test x$sjis_given = xyes -o x$enableval = xyes; then
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(SJIS_CODES)
+else
+  AC_MSG_RESULT(no)
+fi
+
+
+dnl Check for X
+
+if test "x$x_includes" = "x"; then
+  x_includes="/usr/include"
+fi
+
+saved_cflags="$CFLAGS"
+saved_ldflags="$LDFLAGS"
+
+CFLAGS="$CFLAGS $X_CFLAGS"
+LDFLAGS="$LDFLAGS $X_LDFLAGS $X_LIBS"
+
+if test "x$no_x" = "xyes"; then 
+  AC_MSG_ERROR([
+*** X libraries or include files not found. Check 'config.log' for 
+*** more details.])
+fi
+
+# Check for the X11 library
+AC_CHECK_LIB(X11, XOpenDisplay, x_libs="-lX11 $X_EXTRA_LIBS", 
+  AC_MSG_ERROR([*** libX11 not found. Check 'config.log' for more details.]),
+  $X_EXTRA_LIBS)
+
+if test "x$enable_shm" = "xyes"; then
+  # Check for the Xext library (needed for XShm extention)
+  AC_CHECK_LIB(Xext, XShmAttach, 
+      x_libs="-lXext $x_libs", 
+      # On AIX, it is in XextSam instead, but we still need -lXext
+      AC_CHECK_LIB(XextSam, XShmAttach, 
+          x_libs="-lXextSam -lXext $x_libs", 
+          no_xext_lib=yes, $x_libs),
+      $x_libs)
+fi
+
+x_cflags="$X_CFLAGS"
+x_ldflags="$X_LDFLAGS $X_LIBS"
+
+CFLAGS="$saved_cflags"
+LDFLAGS="$saved_ldflags"
+
+AC_SUBST(x_cflags)
+AC_SUBST(x_includes)
+AC_SUBST(x_ldflags)
+AC_SUBST(x_libs)
+
+dnl# this is a really hack test for some basic Xlocale stuff
+SAVETHELIBS=$LIBS
+LIBS="$LIBS $X_LIBS $X_PRE_LIBS $X_EXTRA_LIBS -lX11"
+AC_CACHE_CHECK(for working Xlocale, sted2_cv_func_xlocale,
+[AC_TRY_RUN([#include <X11/Xlib.h>
+main() {
+char *p;
+if ((p = XSetLocaleModifiers("@im=none")) != NULL && *p)
+exit (XSupportsLocale() ? 0 : 1);
+else
+exit (1);}],  dnl
+  sted2_cv_func_xlocale=yes, sted2_cv_func_xlocale=no,  dnl
+  AC_MSG_WARN([Define/undefine NO_XLOCALE in config.h manually]))])
+if test "${sted2_cv_func_xlocale}" = no; then
+  AC_DEFINE(NO_XLOCALE)
+fi
+LIBS=$SAVETHELIBS
+
+AC_CACHE_CHECK(for working X setlocale, sted2_cv_func_xsetlocale,
+[AC_TRY_LINK([#define X_LOCALE 1
+#include <X11/Xlocale.h>],
+  [setlocale(LC_CTYPE, "");],
+  sted2_cv_func_xsetlocale=yes, sted2_cv_func_xsetlocale=no)])
+if test "${sted2_cv_func_xsetlocale}" = no; then
+  AC_DEFINE(NO_XSETLOCALE)
+fi
+
+AC_CACHE_CHECK(for working plain setlocale, sted2_cv_func_setlocale,
+[AC_TRY_LINK([#include <locale.h>],
+  [setlocale(LC_CTYPE, "");],
+  sted2_cv_func_setlocale=yes, sted2_cv_func_setlocale=no)])
+if test "${sted2_cv_func_setlocale}" = no; then
+  AC_DEFINE(NO_SETLOCALE)
+fi
+
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE")
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION")
+
+AC_OUTPUT([
+Makefile
+sted2/Makefile
+sted2/sub/Makefile
+sted2/rcpconv/Makefile
+sted2/itor/Makefile
+intl/Makefile
+po/Makefile.in
+etc/Makefile
+doc/Makefile
+doc/original_docs/Makefile
+contrib/Makefile
+])
diff --git a/curses.cpp b/curses.cpp
new file mode 100644 (file)
index 0000000..8a820a3
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+  curses.c
+
+  functions for displaying texts with curses library
+
+  Made by Studio Breeze. 1998
+
+ */
+
+/* static function */
+
+static void curses_rwindow( void );
+
+
+void curses_init_window( void ) {
+  return;
+}
+
+void curses_close_window( void ) {
+  return;
+}
+
+void curses_curon( void ) {
+
+  return;
+}
+
+void curses_curoff( void ) {
+  return;
+}
+
+void curses_gcolor( int col ) {
+  return;
+}
+
+void curses_tcolor( int col ) {
+  return;
+}
+
+void curses_tputs( char *message ) {
+  return;
+}
+
+void curses_gputs( int x, int y, const char *message ) {
+  return;
+}
+
+void curses_tlocate( int x, int y ) {
+  return;
+}
+
+void curses_ghome( int home_flag ) {
+  return;
+}
+
+void curses_trev( int x, int y, int l, int col ) {
+  return;
+}
+
+void curses_tfill( unsigned short page, short  sx, short sy, short lx, short ly, unsigned short col ) {
+  return;
+}
+
+void curses_gfill( int sx, int sy, int ex, int ey, int col ) {
+  return;
+}
+
+void curses_trascpy( int dst, int src, int line, int mode ) {
+  return;
+}
+
+void curses_t_scrw( int x1, int y1, int xs, int ys, int x2, int y2 ) {
+  return;
+}
+
+void curses_tg_copy( int edit_scr ) {
+  return;
+}
+
+void curses_tg_copy2( int edit_scr ) {
+  return;
+}
+
+void curses_cls_al( void ) {
+  return;
+}
+
+void curses_gclr( void ) {
+  return;
+}
+
+void curses_cls_ed( void ) {
+  return;
+}
+
+void curses_cls_eol( void ){
+  return;
+}
+
+void curses_rwindow( void ) {
+  return;
+}
+
+int curses_keyin( int code ) {
+
+  int ret=0;
+  return ret;
+}
+
+int curses_keyinp( void ) {
+
+  int ret=0;
+  return ret;
+}
+
+int curses_sftsns( void ) {
+
+  int ret=0;
+  return ret;
+}
+
+void curses_key_wait( void ) {
+
+  return;
+}
+
+void curses_midi_wait( void ) {
+  return;
+}
+
+void curses_ledmod( int code, int onoff ) {
+  return;
+}
diff --git a/defload.cpp b/defload.cpp
new file mode 100644 (file)
index 0000000..ff80cdd
--- /dev/null
@@ -0,0 +1,1345 @@
+/*
+ * STed: defload.c (def file)
+ */
+
+#if 0
+#include       "basic0.h"
+#include       "BASIC.h"
+#endif
+
+#include       <stdio.h>
+#include       <stdlib.h>
+#include       <string.h>
+
+#include       "iocslib.h"
+#include       "doslib.h"
+#include       "sted.h"
+
+#if    STED
+int    gpal_no[16]={
+  0,14*64+28*2048+28*2,28*64+28*2048+14*2,28*64+28*2048+28*2,
+  11*64+11*2048+11*2,6*64+6*2048+6*2,0x2708,
+
+  11*2048+14*2,14*2048+17*2, 17*2048,31*2048,31*2048+31*2,
+  17*64+17*2048,31*64+31*2048,16*64+16*2048+16*2,31*64+31*2048+31*2};
+
+unsigned char  stgt_def[30]={
+  192,144, 96, 72, 48, 36, 24, 18, 12,  6,
+  188,140, 92, 68, 45, 34, 22, 16, 10,  5,
+  1, 15, 29, 43, 57, 71, 85, 99,113,127};
+#endif
+
+char   tim_asin2[33];
+char   defrhyna[32][15];
+unsigned char  defrhyno[32][2];
+
+char   def_user_exc_memo[8][25];
+unsigned char  def_user_exc_data[8][24];
+
+
+/* ================================================== file */
+#if    STED
+void   rhinit()
+{
+  int  i;
+
+  for(i=0;i<32;i++){rhinit2(i);}
+}
+void   rhinit2(int i)
+{
+  strcpy(rhyna[i],defrhyna[i]);
+  rhyno[i][0]=defrhyno[i][0];rhyno[i][1]=defrhyno[i][1];
+}
+void   user_exc_init()
+{
+  int  i;
+
+  for(i=0;i<8;i++){user_exc_init2(i);}
+}
+void   user_exc_init2(int i)
+{
+  int  j;
+
+  strcpy(user_exc_memo[i],def_user_exc_memo[i]);
+  for(j=0;j<24;j++){user_exc_data[i][j]=def_user_exc_data[i][j];}
+}
+
+/***************************/
+void   stgt_init()
+{
+  int i;
+
+  for(i=0;i<30;i++){stgt_init2(i);}
+}
+void   stgt_init2(int i)
+{
+  stgt_tbl[i]=stgt_def[i];
+}
+/***************************/
+void   asin_change()
+{
+  int  a,i;
+
+  if((mdlflag&3)==1){
+    for(i=1;i<=16;i++){if(tim_asin[i]<4){tim_asin[i]=0;}}
+    for(i=0x8d;i<=0x8d+8;i++){
+      a=cm6[i]+1;
+      if(a<17){
+       if( tim_asin[a]==0){
+         if(i<0x8d+8){tim_asin[a]=1;}else{tim_asin[a]=2;}
+       }
+      }
+    }
+    for(i=0x583c;i<=0x583c+5;i++){
+      a=cm6[i]+1;if(a<17){if( tim_asin[a]==0){tim_asin[a]=3;}}
+    }
+  }
+}
+
+void   asin_init()
+{
+  int  i;
+  for(i=1;i<33;i++){tim_asin[i]=tim_asin2[i];}
+}
+/***************************/
+void   cnfinit()
+{
+  int i;
+
+  inpmode=0;grpmode=0;thrumode=0;vis_reso=100;
+
+  for(i=0;i<16;i++){mplay[i][0]=0;palet_dat[i]=gpal_no[i];}
+  strcpy(mplay[1],"rcp -pbs");strcpy(mplay[9],"rcp -ps");
+
+  for(i=0;i<128;i++){keyst_table[0][i]=0;keyst_table[1][i]=0;}
+  for(i=0;i<26*3*2;i++){repl_t[i][0]=0;repl_d[i][0]=0;}
+
+  for(i=0;i<16;i++){rhy_vel[i]=0;}
+  for(i=1;i<10;i++){rhy_vel[i]=i*14;}
+}
+#endif
+/***************************/
+void   definit()
+{
+  int  i,j;
+
+  strcpy(card_name[0],"NoUse <<PCM CARD>>");
+  for(i=1;i<17;i++){strcpy(card_name[i]," --------");}
+
+  for(i=0;i<80*128;i++){tim_name[i][0]=0;}
+  for(i=0;i<400;i++){tim_top[i]=0;tim_name[i][0]=0;tim_head[i][0]=0;}
+
+  for(i=0;i<8;i++){for(j=0;j<24;j++){
+    def_user_exc_memo[i][j]=0;def_user_exc_data[i][j]=0xf7;}}
+
+  init_exc_data[0]=255;
+
+  for(i=0;i<18*128;i++){gs_bank[i]=0;}
+  for(i=0;i<18;i++){gs_mode[i]=0;}
+  gs_mode[16]=4;
+
+  for(i=0;i<16;i++){rfilt[i][0]=0;rfilt[i][1]=0;rfilt[i+16][0]=128;rfilt[i+16][1]=128;}
+
+  rec_met[0]=16;rec_met[1]=0;
+  rec_met[2]=64;rec_met[3]=2;rec_met[4]=117;
+  rec_met[5]=64;rec_met[6]=2;rec_met[7]=127;
+
+  rhy_stest[0]=10;rhy_stest[1]=-1;
+  rhy_stest[2]=-1;rhy_stest[4]=127;
+
+  player_name[0]=0;       /* Jun.28.1998 Daisuke Nagano */
+  midi_port_name[0]=0;    /* Sep.02.1998 Daisuke Nagano */
+  font_name[0]=0;         /* Sep.04.1998 */
+  player_flag=0;          /* Nov.25.1998 */
+
+  strcpy( KEY_XF1,    "Alt_L" );
+  strcpy( KEY_XF2,    "Muhenkan" );
+  strcpy( KEY_XF3,    "Henkan_Mode" );
+  strcpy( KEY_XF4,    "Hiragana_Katakana" );
+  strcpy( KEY_XF5,    "Alt_R" );
+  strcpy( KEY_KANA,   "Caps_Lock" );
+  strcpy( KEY_KIGO,   "F11" );
+  strcpy( KEY_TOROKU, "F12" );  /* Nov 25.1998 Daisuke Nagano */
+  strcpy( KEY_INS,    "Insert" );
+  strcpy( KEY_DEL,    "Delete" );
+  strcpy( KEY_HOME,   "Home" );
+  strcpy( KEY_UNDO,   "End" );
+  strcpy( KEY_RUP,    "Page_Up" );
+  strcpy( KEY_RDOWN,  "Page_Down" );
+  strcpy( KEY_OPT1,   "" );
+  strcpy( KEY_OPT2,   "" ); /* Dec.22.1998 Daisuke Nagano */
+
+
+  lsp_wait=1;bend_range=12;
+  tim_name_read();
+}
+
+/***************************/
+/*
+  cmdflag=             gs_mode=        mdlfalg=
+  00       00             00              00
+  84218421 84218421    84218421        84218421
+  00000000 00000000    00000000        00000000
+  |||||||| ||||||||    ||   |||        ||||||||
+  |||||||| ||||||||    ||   |||        ||||++++MODULE ID(1=CM-64 2=SC-55
+  |||||||| ||||||||    ||   |||        ++++----          3=SC-88)
+  |||||||| ||||||||    ||   ||+bit0    1=capital down on
+  |||||||| ||||||||    ||   |+-bit1    1=rhy.cap down on
+  |||||||| ||||||||    ||   +--bit2    0=bank msb 1=bank lsb
+  |||||||| ||||||||    ||
+  |||||||| ||||||||    |+------bit6    1=rhythm mode on
+  |||||||| ||||||||    +-------bit7    1=bank mode on
+  |||||||| |||||||+TIMBRE NAME
+  |||||||| ||||||+-RET&SPC
+  |||||||| |||||+--SPC.CTRL SEL
+  |||||||| ||||+---BUF LOAD
+  |||||||| |||+----BUF SET
+  |||||||| ||+-----PROG_MIN
+  |||||||| |+------ALL NOTE OFF
+  |||||||| +-------RCD POINT PLAY
+  |||||||+Rol.Para HEX
+  ||||||+-MOUSE CONTROL (0=on 1=off)
+  |||||+--RHY AS. check (0=yes/no check 1=all yes)
+  ||||+---RHY AS. change(0=on 1=off)
+  |||+----timbre select (0=val 1=sel)
+  ||+-----timbre select mode(0=normal 1=bank)
+  |+------meas play mluti track lsp
+  +-------rcp panel mode
+
+  cnfflag=
+  00       00
+  84218421 84218421
+  00000000 00000000
+  |||||||| ||||||||
+  |||||||| |||||||+file selecter sort
+  |||||||| ||||||+-file write check
+  |||||||| |||||+--file back up
+  |||||||| ||||+---file selecter path move(0=on 1=off)
+  |||||||| |||+----
+       |||||||| ||+-----
+       |||||||| |+------file save mode(0=r36 1=rcp)
+       |||||||| +-------file load part assign read
+       ||||||||
+       |||||||+
+       ||||||+-t.set. option mode(0=option2 1=option1)
+       |||||+--t.edit option mode(0=option2 1=option1)
+       ||||+---
+       |||+----replace selecter mode(0=normal 1=select)
+       ||+-----one touch stgt  (0=normal 1=chord)
+       |+------visual edit     (0=normal 1=wide)
+       +-------gs bar display  (0=normal 1=reverse)
+       */
+
+int    defload(char *fi,int md)
+{
+  char tmp0[2048],tmp1[1024],li[1024],li2[1024];
+  int  ad,nm,ln,n,i0=0,i1=0,f,mutef=0,initf=0;
+  int  last_no=4*128,last_co=0;
+  FILE *fp;
+
+  if(str_search(fi,".dfb")||str_search(fi,".DFB")>0){return def_bload(fi,md);}
+
+  /*if(!(fp= fopen2(fi,"rb"))){return(-1);}*/
+
+  if ((fp=fopen2(fi,"rb"))==NULL) {
+    strcpy( tmp0, STED_DEFAULT_PATH );
+    if ( tmp0[strlen(tmp0)]!='/' ) strcat(tmp0,"/");
+    strcat( tmp0, (strrchr(fi,'/')==NULL)?fi:(strrchr(fi,'/')+1) );
+    if ((fp=fopen2( tmp0, "rb" ))==NULL) return(-1);
+  } /* Oct.13.1998 by Daisuke Nagano */
+  ln=fread(dat,1,work_size,fp);ad=0;nm=99999;
+
+#if    STED
+  if(md==0){
+    /*B_PRINT("定義ファイルのロード中です。\r\n");*/ /* Oct.17.1998 by Daisuke Nagano */
+  }
+  if(md==1){
+    msg(_("Loading config file.\n"));
+  }
+#endif
+#if    CONV
+  B_PRINT(_("Compiling config file.\n"));
+#endif
+
+  while(ln>0){
+  top:
+    n=0;
+    while(1){
+      unsigned char    a;
+    loop:
+      a=dat[ad++];
+      ln--;if(ln==0){ln=fread(dat,1,work_size,fp);ad=0;if(ln==0){break;}}
+      if(a<32){
+       /*if(a==13){break;}*/ /* Sep.02.1998 Daisuke Nagano */
+       if(a==13||a==0x0a){break;}
+       if(a==9){goto loop;}
+       a=32;
+      }else{
+       if(a=='*'){a=0;
+       if(n!=0 && li[n-1]=='\\'){n--;a='*';}
+       }
+       if(a=='=' && li[0]=='#'){while(li[n-1]==' '){n--;}}
+      }
+      li[n++]=a;
+    }
+    li[n]=0;li[1023]=0;
+    /*if(dat[ad]==0x0a){ad++;*/ /* Sep.02.1998 Daisuke Nagano */
+    if(dat[ad]==0x0a||dat[ad]==0x0d){ad++;
+    ln--;if(ln==0){ln=fread(dat,1,work_size,fp);ad=0;}
+    }
+
+    spcut(li);
+    if( li[0]==0 ){goto top;}
+
+    if( li[0]=='#' ){
+      strcpy(li2,li);jstrupr(li2);
+
+      if( str_search(li2,"#END")>0 ){break;}
+
+#if    STED
+      if( str_search(li2,"#COMMENT=")>0 ){strcpy(comment,&li[9]);}
+
+      if( str_search(li2,"#DEF_FILE=")>0 ){
+       if(def_file[0]==0){strcpy(def_file,&li[10]);}}
+      if( str_search(li2,"#DEF_PATH=")>0 ){
+       if(def_path[0]==0){strcpy(def_path,&li[10]);}}
+
+      if( str_search(li2,"#FON_PATH=")>0 ){
+       if(fon_path[0]==0){strcpy(fon_path,&li[10]);}}
+      if( str_search(li2,"#HLP_PATH=")>0 ){
+       if(hlp_path[0]==0){strcpy(hlp_path,&li[10]);}}
+
+      if( str_search(li2,"#PRT_PATH=")>0 ){
+       if(prt_path[0]==0){strcpy(prt_path,&li[10]);}}
+      if( str_search(li2,"#TRK_PATH=")>0 ){
+       if(trk_path[0]==0){strcpy(trk_path,&li[10]);}}
+
+      if(str_search(li2,"#FSORT=ON"    )>0){cnfflag|=0x0001;}
+      if(str_search(li2,"#FCHECK=ON"   )>0){cnfflag|=0x0002;}
+      if(str_search(li2,"#FBACKUP=ON"  )>0){cnfflag|=0x0004;}
+      if(str_search(li2,"#FSEL_MOV=OFF")>0){cnfflag|=0x0008;}
+      if(str_search(li2,"#SAVE_DEF=RCP")>0){cnfflag|=0x0040;}
+      if(str_search(li2,"#PAS_READ=OFF")>0){cnfflag|=0x0080;}
+
+      /*                       if(str_search(li2,"#MAIN_OPT=ON" )>0){cnfflag|=0x0100;}*/
+      if(str_search(li2,"#TSET_OPT=ON" )>0){cnfflag|=0x0200;}
+      if(str_search(li2,"#TEDT_OPT=ON" )>0){cnfflag|=0x0400;}
+      if(str_search(li2,"#REPL_SEL=ON" )>0){cnfflag|=0x1000;}
+
+      if(str_search(li2,"#ONE_CHORD=ON")>0){cnfflag|=0x2000;}
+      if(str_search(li2,"#VIS_WIDE=ON" )>0){cnfflag|=0x4000;}
+      if(str_search(li2,"#BAR_REV=ON"  )>0){cnfflag|=0x8000;}
+
+      if(str_search(li2,"#TONENAME=OFF")>0){cmdflag|=0x0001;}
+      if(str_search(li2,"#ENTER=ON"    )>0){cmdflag|=0x0002;}
+      if(str_search(li2,"#SPC_SEL=ON"  )>0){cmdflag|=0x0004;}
+      if(str_search(li2,"#PROG_MIN=1"  )>0){cmdflag|=0x0020;}
+      if(str_search(li2,"#NOTEOFF=ON"  )>0){cmdflag|=0x0040;}
+      if(str_search(li2,"#ROL_HEX=ON"  )>0){cmdflag|=0x0100;}
+      if(str_search(li2,"#RHY_TRK=ON"  )>0){cmdflag|=0x0400;}
+      if(str_search(li2,"#RHY_TRK=OFF" )>0){cmdflag|=0x0800;}
+      if(str_search(li2,"#TONESEL=OFF" )>0){cmdflag|=0x1000;}
+      if(str_search(li2,"#TSELBANK=ON" )>0){cmdflag|=0x2000;}
+      if(str_search(li2,"#MP_MLSP=OFF" )>0){cmdflag|=0x4000;}
+
+      /*                       if(str_search(li2,"#RHY_SYM=ON"  )>0){cmdflag|=0x20000;}*/
+      if(str_search(li2,"#THRUMODE=ON" )>0){thrumode=1;}
+
+      if( str_search(li2,"#TIME_LAG=")>0){
+       int n=str_val(&li[10]);if( n>99 && n<65536 ){tm_lag=n;}
+      }
+      if( str_search(li2,"#EDIT_MODE=")>0){
+       int n=str_val(&li[11]);if( n>=0 && n<6 ){inpmode=n;}
+      }
+      if( str_search(li2,"#GRAP_MODE=")>0){
+       int n=str_val(&li[11]);if( n>=0 && n<8 ){grpmode=n;}
+      }
+
+      if( str_search(li2,"#VIS_RESO=")>0){
+       int n=str_val(&li[10]);if( n>=1 && n<=100 ){vis_reso=n;}
+      }
+
+      if( str_search(li2,"#PROGRAM=")>0 ){cnf_prog(li,li2,0);}
+      if( str_search(li2,"#SUBPROG=")>0 ){cnf_prog(li,li2,1);}
+
+      if( str_search(li2,"#REPLACE=")>0 ){cnf_repl(li,li2,0);}
+      if( str_search(li2,"#DELETE=")>0 ){cnf_repl(li,li2,1);}
+      if( str_search(li2,"#FIND=")>0 ){cnf_repl(li,li2,2);}
+
+      if( str_search(li2,"#MPLAY=")>0 ){
+       int     c,n;
+       n=li2[7]-'0';
+       if(n>=0 && n<16){
+         strcpy(tmp1,&li[9]);strcat(tmp1,",");
+         while(n<16){
+           c=str_search(tmp1,",");if( c==0 ){break;}
+           strcpy(tmp0,tmp1);tmp0[c-1]=0;spcut(tmp0);
+           strcpy(tmp1,&tmp1[c]);
+           tmp0[15]=0;
+           strcpy(mplay[n],tmp0);
+           n++;
+         }
+       }
+      }
+
+      if( str_search(li2,"#RHY_VEL=")>0 ){cnf_rvel(li);}
+
+      if( str_search(li2,"#FKEY_ST=")>0 ){cnf_stgt(li,0);}
+      if( str_search(li2,"#FKEY_GT=")>0 ){cnf_stgt(li,10);}
+      if( str_search(li2,"#FKEY_VE=")>0 ){cnf_stgt(li,20);}
+
+      if( str_search(li2,"#KEYST=")>0 ){
+       int     c,n,k=0;
+       strcpy(tmp1,&li[7]);strcat(tmp1,",");n=0;
+       while(n<3){
+         c=str_search(tmp1,",");if( c==0 ){break;}
+         strcpy(tmp0,tmp1);tmp0[c-1]=0;spcut(tmp0);
+         strcpy(tmp1,&tmp1[c]);
+         if(n==0){
+           k=ctc(64,tmp0,0);
+           if(k<0||k>127){break;}
+         }else{
+           keyst_table[n-1][k]=str_val(tmp0);
+         }
+         n++;
+       }
+      }
+
+      if( str_search(li2,"#PALET")>0 ){
+       int     c,n;
+       c=str_search(li,"=");
+       if(c){
+         li2[c]=0;n=str_val(&li2[6]);
+         if(n>=0 && n<16){
+           strcpy(tmp1,&li[c]);strcat(tmp1,",");
+           while(n<16){
+             c=str_search(tmp1,",");if( c==0 ){break;}
+             strcpy(tmp0,tmp1);tmp0[c-1]=0;
+             spcut(tmp0);palet_dat[n]=str_val(tmp0);
+             strcpy(tmp1,&tmp1[c]);n++;
+           }
+         }
+       }
+      }
+
+#endif
+
+      if( str_search(li2,"#MODULE=")>0 ){strcpy(module,&li[8]);}
+
+      if( str_search(li2,"#ID=")>0 ){
+       strcpy(tmp1,&li2[4]);
+       if( str_search(tmp1,"CM64")>0 ){mdlflag|=1;}
+       if( str_search(tmp1,"SC55")>0 ){mdlflag|=2;}
+       if( str_search(tmp1,"SC88")>0 ){mdlflag|=3;}
+       if( str_search(tmp1,"05RW")>0 ){mdlflag|=4;}
+      }
+      if( str_search(li2,"#MUTE=")>0 ){
+       strcpy(tmp1,&li2[6]);mutef=0;
+       if( str_search(tmp1,"OFF")>0  ){mutef=1;}
+       if( str_search(tmp1,"CM64")>0 ){mutef=2;}
+       if( str_search(tmp1,"SC55")>0 ){mutef=3;}
+      }
+      if( str_search(li2,"#INIT=")>0 ){
+       strcpy(tmp1,&li2[6]);initf=0;
+       if( str_search(tmp1,"OFF")>0  ){initf=1;}
+       if( str_search(tmp1,"CM64")>0 ){initf=2;}
+       if( str_search(tmp1,"SC55")>0 ){initf=3;}
+       if( str_search(tmp1,"SC88")>0 ){initf=5;}
+      }
+
+      if( str_search(li2,"#LSP_WAIT=")>0){
+       int n=str_val(&li[10]);if( n>=-1 && n<16 ){lsp_wait=n;}
+      }
+      if( str_search(li2,"#PB_RANGE=")>0){
+       int n=str_val(&li[10]);if( n>0 && n<96 ){bend_range=n;}
+      }
+
+      if( str_search(li2,"#GROUP")>0 ){
+       int     c,n;
+       c=str_search(li,"=");
+       if(c!=0){
+         n=0;if(li2[7]=='B'){n=16;}
+         strcpy(tmp1,&li[c]);strcat(tmp1,",");
+         while(n<32){
+           c=str_search(tmp1,",");if(c==0){break;}
+           strcpy(tmp0,tmp1);tmp0[c-1]=0;
+           n++;tim_asin2[n]=str_val(tmp0);
+           strcpy(tmp1,&tmp1[c]);
+         }
+       }
+      }
+      if( str_search(li2,"#CARD_NO=")>0 ){
+       int n=str_val(&li[9]);if(n>=0 && n<=16){card_no[0]=n;}
+      }
+
+      if( str_search(li2,"#PART=")>0 ){
+       int     ch,c,n;
+       ch=str_val(&li2[6])-1;
+       c=str_search(li,",");
+       if(ch>=0 && ch<400){
+         strcpy(tmp1,&li[c]);strcat(tmp1,",");n=0;
+         while(n<2){
+           c=str_search(tmp1,",");if( c==0 ){break;}
+           strcpy(tmp0,tmp1);tmp0[c-1]=0;
+           if(n==0){strcpy(tim_head[ch],tmp0);}
+           else{strcpy(tim_sym[ch],tmp0);}
+           strcpy(tmp1,&tmp1[c]);n++;
+         }
+         nm=ch*128;if( ch==1 ){nm=192;}
+         if(tmp1[0]!=0){nm+=str_val(tmp1);}
+
+         if(ch>3){
+           if(last_no<80*128-1){
+             tim_name[last_no++][0]=0;
+             tim_top[ch]=last_no;last_co=0;
+             if(tmp1[0]!=0){last_co=str_val(tmp1);}
+           }
+         }
+       }
+      }
+      if( str_search(li2,"#USER_EXC=")>0 ){
+       int     ch,c;
+       char    tmp9[128];
+       ch=str_val(&li2[10]);
+       c=str_search(li,",");
+       if(ch>=0 && ch<=7){
+         int   i=0,j=0;
+         strcpy(tmp1,&li[c]);
+         c=str_search(tmp1,",");
+         strcpy(tmp0,tmp1);if(c){tmp0[c-1]=0;}
+         spcut(tmp0);
+
+         while(i<c && j<24 && tmp0[i]!=0){
+           int a;
+           if(tmp0[i]==32){i++;}else{
+             strcpy(tmp9,&tmp0[i]);
+             if(tmp9[1]==0){
+               tmp9[1]='H';tmp9[2]=0;
+             }else{
+               tmp9[2]='H';tmp9[3]=0;
+             }
+             a=str_val(tmp9);tmp9[2]=0;
+             if(strcmp(tmp9,"GT")==0){a=0x80;}
+             if(strcmp(tmp9,"VE")==0){a=0x81;}
+             if(strcmp(tmp9,"CH")==0){a=0x82;}
+             if(strcmp(tmp9,"CS")==0){a=0x83;}
+             if(strcmp(tmp9,"SS")==0){a=0x84;}
+
+             def_user_exc_data[ch][j++]=a;
+             i=i+2;
+           }
+         }
+         if(c){
+           strcpy(tmp0,&tmp1[c]);
+           tmp0[24]=0;strcpy(def_user_exc_memo[ch],tmp0);
+         }
+       }
+      }
+      if( str_search(li2,"#INIT_EXC=")>0 ){def_init(li);}
+
+      if( str_search(li2,"#CARD=")>0 ){
+       int     c,ch;
+       strcpy(tmp1,&li[6]);
+       c=str_search(tmp1,",");
+       if(c){
+         strcpy(tmp0,tmp1);tmp0[c-1]=0;ch=str_val(tmp0);
+         strcpy(tmp0,&tmp1[c]);
+         if(ch>0 && ch<17){
+           strcpy(card_name[ch],tmp0);
+           nm=(ch+15)*128;
+
+           if(last_no<80*128-1){
+             tim_name[last_no++][0]=0;
+             tim_top[ch+15]=last_no;last_co=0;
+           }
+         }
+       }
+      }
+
+      if( str_search(li2,"#GS_PBANK")>0 ){gs_mode[ 7]|=128   ;nm=0x10380;}
+      if( str_search(li2,"#GS_RBANK")>0 ){gs_mode[ 8]|=128+64;nm=0x10400;}
+      if( str_search(li2,"#GM_PBANK")>0 ){gs_mode[ 9]|=128   ;nm=0x10480;}
+      if( str_search(li2,"#GM_RBANK")>0 ){gs_mode[10]|=128+64;nm=0x10500;}
+      if( str_search(li2,"#GX_PBANK")>0 ){gs_mode[11]|=128   ;nm=0x10580;}
+      if( str_search(li2,"#GX_RBANK")>0 ){gs_mode[12]|=128+64;nm=0x10600;}
+      if( str_search(li2,"#GY_PBANK")>0 ){gs_mode[13]|=128   ;nm=0x10680;}
+      if( str_search(li2,"#GY_RBANK")>0 ){gs_mode[14]|=128+64;nm=0x10700;}
+
+      if( str_search(li2,"#GS_PGROUP")>0 ){gs_mode[16]|=128   ;nm=0x10800;}
+      if( str_search(li2,"#GS_RGROUP")>0 ){gs_mode[17]|=128+64;nm=0x10880;}
+
+      if( str_search(li2,"#GS_GMODE=")>0){
+       int     n=str_val(&li[10]);
+       if( n>=0 && n<16){gs_mode[16]&=0xf0;gs_mode[16]|=n;}
+      }
+
+      if( str_search(li2,"#GS_MODE=")>0){
+       int     n=str_val(&li[9]);
+       if( n>=0 && n<16){gs_mode[7]&=0xf0;gs_mode[7]|=n;}
+      }
+      if( str_search(li2,"#GM_MODE=")>0){
+       int     n=str_val(&li[9]);
+       if( n>=0 && n<16){gs_mode[9]&=0xf0;gs_mode[9]|=n;}
+      }
+      if( str_search(li2,"#GX_MODE=")>0){
+       int     n=str_val(&li[9]);
+       if( n>=0 && n<16){gs_mode[11]&=0xf0;gs_mode[11]|=n;}
+      }
+      if( str_search(li2,"#GY_MODE=")>0){
+       int     n=str_val(&li[9]);
+       if( n>=0 && n<16){gs_mode[13]&=0xf0;gs_mode[13]|=n;}
+      }
+
+      if( str_search(li2,"#RHY_AS=")>0 ){
+       int     c;
+       nm=0x10000+128*18;i0=0;i1=0;
+
+       c=str_search(li,"=");
+       if(c!=0){
+         int n=0;
+         strcpy(tmp1,&li[c]);strcat(tmp1,",");
+         while(n<6){
+           int cc;
+           c=str_search(tmp1,",");if(c==0){break;}
+           strcpy(tmp0,tmp1);tmp0[c-1]=0;
+           if(n==0){cc=strch(0,tmp0);
+           }else{cc=str_val(tmp0);}
+           if((cc>=0||(n>0 && n<5))&& cc<=127){rhy_stest[n]=cc;}
+           strcpy(tmp1,&tmp1[c]);
+           n++;
+         }
+       }
+      }
+
+
+      if( str_search(li2,"#REC_MET")>0 ){
+       int     c,n;
+       c=str_search(li,"=");
+       if(c!=0){
+         n=0;
+         strcpy(tmp1,&li[c]);strcat(tmp1,",");
+         while(n<10){
+           c=str_search(tmp1,",");if(c==0){break;}
+           strcpy(tmp0,tmp1);tmp0[c-1]=0;
+           rec_met[n++]=str_val(tmp0);
+           strcpy(tmp1,&tmp1[c]);
+         }
+       }
+      }
+
+      if( str_search(li2,"#DEFOFF")>0 ){nm=99999;}
+
+
+      /* the following configurations are introduced only UNIX version */
+
+      if( str_search(li2,"#PLAYER=")>0 ){
+       player_flag=li[8]-'0';strcpy(player_name,&li[10]); }
+      /* Jun.28.1998 Daisuke Nagano, Nov.12.1998 kino */
+
+      /*if( str_search(li2,"#ISSMFPLAYER=TRUE")>0 ){issmfplayer=1;}*/
+      /* Aug.09.1998 Daisuke Nagano, Nov.12.1998 kino */
+
+      if( str_search(li2,"#MIDI_PORT=")>0 ){
+       strcpy(midi_port_name, &li[11]); }
+      /* Sep.02.1998 Daisuke Nagano */
+
+      if( str_search(li2,"#FONT_NAME=")>0 ){
+       strcpy(font_name, &li[11]); }
+      /* Sep.04.1998 Daisuke Nagano */
+
+      if ( str_search(li2, "#KEY_XF1=")>0 )
+       strcpy( KEY_XF1, &li[9]);
+      if ( str_search(li2, "#KEY_XF2=")>0 )
+       strcpy( KEY_XF2, &li[9]);
+      if ( str_search(li2, "#KEY_XF3=")>0 )
+       strcpy( KEY_XF3, &li[9]);
+      if ( str_search(li2, "#KEY_XF4=")>0 )
+       strcpy( KEY_XF4, &li[9]);
+      if ( str_search(li2, "#KEY_XF5=")>0 )
+       strcpy( KEY_XF5, &li[9]);
+      if ( str_search(li2, "#KEY_KANA=")>0 )
+       strcpy( KEY_KANA, &li[10]);
+      if ( str_search(li2, "#KEY_KIGO=")>0 )
+       strcpy( KEY_KIGO, &li[10]);
+      if ( str_search(li2, "#KEY_TOROKU=")>0 )
+       strcpy( KEY_TOROKU, &li[12]);
+      /* Nov.25.1998 Daisuke Nagano */
+
+      if ( str_search(li2, "#KEY_INS=")>0 )
+       strcpy( KEY_INS, &li[9]);
+      if ( str_search(li2, "#KEY_DEL=")>0 )
+       strcpy( KEY_DEL, &li[9]);
+      if ( str_search(li2, "#KEY_HOME=")>0 )
+       strcpy( KEY_HOME, &li[10]);
+      if ( str_search(li2, "#KEY_UNDO=")>0 )
+       strcpy( KEY_UNDO, &li[10]);
+      if ( str_search(li2, "#KEY_RUP=")>0 )
+       strcpy( KEY_RUP, &li[9]);
+      if ( str_search(li2, "#KEY_RDOWM=")>0 )
+       strcpy( KEY_RDOWN, &li[11]);
+      if ( str_search(li2, "#KEY_OPT1=")>0 )
+       strcpy( KEY_OPT1, &li[10]);
+      if ( str_search(li2, "#KEY_OPT2=")>0 )
+       strcpy( KEY_OPT2, &li[10]);
+      /* Dec.22.1998 Daisuke Nagano */
+
+    }else{
+      int      c;
+      char     *pp=li,*tmp0;
+      strcat(li,",");
+      while( nm<99999 ){
+       c=str_search(pp,",");if( c==0 ){break;}
+       tmp0=pp;tmp0[c-1]=0;pp+=c;
+
+       if(nm<0x10000 ){
+         if(c>15){tmp0[14]=0;}
+         spcut(tmp0);
+
+         if( nm<0x200 ){
+           strcpy(tim_name[nm],tmp0);
+         }else{
+           if(last_no<80*128-1){
+             if(tmp0[0]!=0){
+               strcpy(tim_name[last_no],tmp0);
+               tim_name[last_no++][14]=last_co;
+             }
+             if(last_co++==127){nm=99999;}
+           }
+         }
+       }else{
+         if(nm<0x10900){
+           int ch=str_val(tmp0);
+           if(ch<400){
+             gs_bank[nm-0x10000]=ch;
+           }
+         }else{
+           if(i0<32){
+             if(i1){
+               defrhyno[i0][i1-1]=str_val(tmp0);
+               /*if(i1==1){
+                 defrhyno[i0][0]=ctc(60,tmp0,0);
+                 }else{
+                 defrhyno[i0][1]=str_val(tmp0);
+                 }*/
+             }else{
+               if(c>15){tmp0[14]=0;}
+               strcpy(defrhyna[i0],tmp0);
+             }
+             i1++;if(i1>=3){i1=0;i0++;}
+           }
+         }
+       }
+       nm++;
+      }
+      /*                       if(md==1){msg(fstr(last_no,5));}*/
+    }
+  }
+  fclose(fp);
+  tim_name[last_no++][0]=0;
+
+#if    STED
+  f=(mdlflag&0x7);if(f>2){f=2;}
+  if(f>0 && f<4){rcd->moduletype=f-1;}
+
+  if(mutef){rcd->mute_mode=mutef-1;}
+  if(initf){rcd->init_mode=initf-1;}
+
+#endif
+#if    CONV
+  def_bsave(fi,last_no,mutef,initf);
+#endif
+
+  return(0);
+}
+
+/***************************//*4.66(2.18) 4.00(1.85)*/
+/***************************/
+#if    STED
+void   cnf_stgt(char *li,int nn)
+{
+  int  c,n;
+  char tmp0[1024];
+  char tmp1[1024];
+
+  c=str_search(li,"=");
+  if(c!=0){
+    strcpy(tmp1,&li[c]);strcat(tmp1,",");n=nn;
+    while(n<30){
+      c=str_search(tmp1,",");if(c==0){break;}
+      strcpy(tmp0,tmp1);tmp0[c-1]=0;
+      stgt_def[n++]=str_val(tmp0);
+      strcpy(tmp1,&tmp1[c]);
+    }
+  }
+}
+
+/***************************/
+void   cnf_rvel(char *li)
+{
+  int  c,n;
+  char tmp0[1024];
+  char tmp1[1024];
+
+  c=str_search(li,"=");
+  if(c!=0){
+    n=0;
+    strcpy(tmp1,&li[c]);strcat(tmp1,",");
+    while(n<15){
+      int cc;
+      c=str_search(tmp1,",");if(c==0){break;}
+      strcpy(tmp0,tmp1);tmp0[c-1]=0;
+      n++;cc=str_val(tmp0);
+      if(cc>=0 && cc<=127){rhy_vel[n]=cc;}
+      strcpy(tmp1,&tmp1[c]);
+    }
+  }
+}
+
+/***************************/
+void   cnf_prog(char *li,char *li2,int md)
+{
+  int  i,c,n;
+  char tmp0[1024];
+  char tmp1[1024];
+
+  i=li2[9]-'A';
+
+  if(i>=0 && i<26){
+    if(md){i+=26;}
+    strcpy(tmp1,&li[11]);strcat(tmp1,",");n=0;
+    while(n<4){
+      c=str_search(tmp1,",");if( c==0 ){break;}
+
+      if(c>1 && tmp1[c-2]=='\\'){
+       int d;
+       strcpy(&tmp1[c-2],&tmp1[c-1]);
+
+       d=str_search(&tmp1[c-1],",");if( d==0 ){break;}
+       c+=d-1;
+      }
+
+      strcpy(tmp0,tmp1);tmp0[c-1]=0;spcut(tmp0);
+      strcpy(tmp1,&tmp1[c]);
+      if((n&1)==0){
+       tmp0[38+10]=0;
+       strcpy(chcom_s[i][n>>1],tmp0);
+      }else{
+       tmp0[15]=0;
+       strcpy(chcom_c[i][n>>1],tmp0);
+      }
+      n++;
+    }
+  }
+}
+
+/***************************/
+void   cnf_repl(char *li,char *li2,int md)
+{
+  int  i,c;
+  char tmp0[1024];
+  char tmp1[1024];
+
+  c=9;if(md){c=8;if(md>1){c=6;}}
+
+  i=li2[c]-'A';
+  if(li2[c]=='S' && li2[c+1]>='A' && li2[c+1]<='Z'){i=(li2[c+1]-'A')+26;c++;}else{
+    if(li2[c]==' '){i=(li2[c+1]-'A');c++;}}
+
+  c=str_search(li,",");if( c==0 ){return;}
+
+  if(i>=0 && i<52){
+    strcpy(tmp1,&li[c/*+2*/]);
+    c=str_search(tmp1,",");if( c==0 ){return;}
+    strcpy(tmp0,tmp1);tmp0[c-1]=0;spcut(tmp0);
+    strcpy(tmp1,&tmp1[c]);spcut(tmp1);
+
+    while(tmp1[0]==32){strcpy(tmp1,&tmp1[1]);}
+
+    tmp0[35]=0;strcpy(repl_t[i+md*52],tmp0);
+    tmp1[35]=0;strcpy(repl_d[i+md*52],tmp1);
+  }
+}
+#endif
+
+/***************************/
+void   def_init(char *li)
+{
+  char tmp0[1024];
+  char tmp1[1024];
+  int  i=0,j=0,sum=0;
+
+  strcpy(tmp0,&li[10]);
+  spcut(tmp0);
+
+  while(j<256 && tmp0[i]!=0){
+    int        a;
+    if(tmp0[i]==32){i++;
+    }else{
+      strcpy(tmp1,&tmp0[i]);
+      if(tmp1[1]==0){
+       tmp1[1]='H';tmp1[2]=0;
+      }else{
+       tmp1[2]='H';tmp1[3]=0;
+      }
+      a=str_val(tmp1);tmp1[2]=0;
+      if(strcmp(tmp1,"CS")==0){sum=0;goto ne;}
+      if(strcmp(tmp1,"SS")==0){a=(127-(sum&0x7f)&0x7f);}
+      init_exc_data[j++]=a;sum+=a;
+    }
+  ne:
+    i=i+2;
+  }
+  init_exc_data[j]=0xff;
+}
+
+/***************************/
+#if    CONV
+int    defsave(char *fi,int md,int mutef,int initf)
+{
+  int  ln,n=0,i,j,k;
+  FILE *fp;
+
+  char gggg[12][12]={"#gs_pbank","#gs_rbank","#gm_pbank","#gm_rbank",
+                    "#gx_pbank","#gx_rbank","#gy_pbank","#gy_rbank","",
+                    "#gs_pgroup","#gs_rgroup"};
+
+  char li0[]= "*--------------------------------------------------------------------------------------\r\n";
+  char li1[]= "*======================================================================================\r\n";
+
+  strmfe(fi,fi,"def");
+  if(!(fp=fopen2(fi,"wb"))){B_PRINT("ファイルがオープン出来ません。\r\n");exit(1);}
+
+  n=buf_put(li0,n);
+
+  n=buf_put("\r\n#module=",n);n=buf_put(module,n);n=buf_put("\r\n\r\n",n);
+
+
+  if(mdlflag&15){
+    n=buf_put("#id=",n);
+    if((mdlflag&15)==1){n=buf_put("cm64",n);}
+    if((mdlflag&15)==2){n=buf_put("sc55",n);}
+    if((mdlflag&15)==3){n=buf_put("sc88",n);}
+    if((mdlflag&15)==4){n=buf_put("05rw",n);}
+    n=buf_put("\r\n",n);
+  }
+
+  if( mutef>0 ){
+    n=buf_put("#mute=",n);
+    if(mutef==1){n=buf_put("off",n);}
+    if(mutef==2){n=buf_put("cm64",n);}
+    if(mutef==3){n=buf_put("sc55",n);}
+    n=buf_put("\r\n",n);
+  }
+  if( initf>0 ){
+    n=buf_put("#init=",n);
+    if(initf==1){n=buf_put("off",n);}
+    if(initf==2){n=buf_put("cm64",n);}
+    if(initf==3){n=buf_put("sc55",n);}
+    if(initf==5){n=buf_put("sc88",n);}
+    n=buf_put("\r\n",n);
+  }
+
+  n=buf_put("\r\n",n);
+  if(card_no[0]){
+    n=buf_put("#card_no=",n);n=buf_put(fstr(card_no[0],2),n);n=buf_put("\r\n",n);
+  }
+  n=buf_put("#lsp_wait=",n);n=buf_put(fstr(lsp_wait,2),n);n=buf_put("\r\n",n);
+  if(bend_range!=12){
+    n=buf_put("#pb_range=",n);n=buf_put(fstr(bend_range,2),n);n=buf_put("\r\n",n);
+  }
+  n=buf_put("\r\n",n);
+
+  n=buf_put(li1,n);
+
+  n=buf_put("\r\n#rec_met=",n);
+  for(i=0;i<8;i++){n=buf_put(fstr(rec_met[i],3),n);if(i<7){n=buf_put(",",n);}}
+  n=buf_put("\r\n\r\n",n);
+
+  n=buf_put(li1,n);
+
+
+  for(i=0;i<8;i++){
+    n=buf_put("#user_exc=",n);
+    n=buf_put(fstr(i,1),n);n=buf_put(",",n);
+    n=buf_put(exc_str(def_user_exc_data[i],24,0),n);
+    n=buf_put(",",n);
+    n=buf_put(def_user_exc_memo[i],n);n=buf_put("\r\n",n);
+  }
+  n=buf_put("\r\n",n);
+
+  if(init_exc_data[0]!=0xff){
+    n=buf_put("#init_exc=",n);
+    n=buf_put(exc_str(init_exc_data,256,1),n);
+    n=buf_put("\r\n\r\n",n);
+  }
+
+  n=buf_put(li1,n);
+
+  n=buf_put("#rhy_as=",n);
+  for(i=0;i<5;i++){n=buf_put(fstr(rhy_stest[i],3),n);if(i<4){n=buf_put(",",n);}}
+  n=buf_put("\r\n",n);
+  for(i=0;i<32;i++){
+    n=buf_put(defrhyna[i],n);n=buf_put(",",n);
+    n=buf_put(fstr(defrhyno[i][0],3),n);n=buf_put(",",n);
+    if(defrhyno[i][1]<100){
+      n=buf_put(fstr(defrhyno[i][1],2),n);
+    }else{
+      n=buf_put(fstr(defrhyno[i][1],3),n);
+    }
+    if((i&3)==3){n=buf_put("\r\n",n);}else{n=buf_put(",",n);}
+  }
+  n=buf_put("#defoff\r\n\r\n",n);
+
+  n=buf_put(li1,n);
+
+
+  n=buf_put("#group_a=",n);
+  for(i=1;i<17;i++){n=buf_put(fstr(tim_asin2[i],2),n);if(i<16){n=buf_put(",",n);}}
+  n=buf_put("\r\n",n);
+  n=buf_put("#group_b=",n);
+  for(i=17;i<33;i++){n=buf_put(fstr(tim_asin2[i],2),n);if(i<32){n=buf_put(",",n);}}
+  n=buf_put("\r\n\r\n",n);
+
+  if(gs_mode[7]&15){n=buf_put("#gs_mode=",n);
+  n=buf_put(fstr(gs_mode[7]&15,3),n);n=buf_put("\r\n\r\n",n);}
+  if(gs_mode[9]&15){n=buf_put("#gm_mode=",n);
+  n=buf_put(fstr(gs_mode[9]&15,3),n);n=buf_put("\r\n\r\n",n);}
+  if(gs_mode[11]&15){n=buf_put("#gx_mode=",n);
+  n=buf_put(fstr(gs_mode[11]&15,3),n);n=buf_put("\r\n\r\n",n);}
+  if(gs_mode[13]&15){n=buf_put("#gy_mode=",n);
+  n=buf_put(fstr(gs_mode[13]&15,3),n);n=buf_put("\r\n\r\n",n);}
+
+  if(gs_mode[16]&128){n=buf_put("#gs_gmode=",n);
+  n=buf_put(fstr(gs_mode[16]&15,3),n);n=buf_put("\r\n\r\n",n);}
+  n=buf_put("\r\n",n);
+
+  for(i=7;i<18;i++){
+    if(gs_mode[i]&0xf0){
+      n=buf_put(gggg[i-7],n);n=buf_put("\r\n",n);
+
+      for(j=0;j<128;j++){
+       n=buf_put(fstr(gs_bank[i*128+j],3),n);
+       if((j&15)!=15){n=buf_put(",",n);}else{n=buf_put("\r\n",n);}
+      }
+      n=buf_put("\r\n",n);
+    }
+  }
+
+  n=buf_put(li1,n);
+
+  ln=fwrite(dat,1,n,fp);n=0;
+
+  for(i=1;i<4;i++){
+    if( tim_top[i-1]!=0 || tim_head[i-1][0]!=0 ){
+      int stp;
+      n=buf_put("#part=",n);
+      n=buf_put(fstr(i,3),n);n=buf_put(",",n);
+      n=buf_put(tim_head[i-1],n);n=buf_put(",",n);
+      n=buf_put(tim_sym[i-1],n);n=buf_put("\r\n",n);
+      n=buf_put(li0,n);
+
+      stp=0;if( i==2 ){stp=64;}
+
+      for(j=stp;j<128;j++){
+       n=buf_put(spadd(tim_names(j+i*128-128),10),n);
+       if((j&7)!=7){n=buf_put(",",n);}else{n=buf_put("\r\n",n);}
+      }
+      n=buf_put(li0,n);
+      n=buf_put("#defoff\r\n\r\n",n);
+    }
+  }
+
+  for(i=4;i<16;i++){
+    if( tim_top[i-1]!=0 || tim_head[i-1][0]!=0 ){
+
+      n=buf_put("#part=",n);
+      n=buf_put(fstr(i,3),n);n=buf_put(",",n);
+      n=buf_put(tim_head[i-1],n);n=buf_put(",",n);
+      n=buf_put(tim_sym[i-1],n);n=buf_put("\r\n",n);
+      n=buf_put(li0,n);
+
+      for(j=0;j<128;j++){
+       n=buf_put(tim_names(j+i*128-128),n);
+       if((j&3)!=3){n=buf_put(",",n);}else{n=buf_put("\r\n",n);}
+      }
+      n=buf_put(li0,n);
+      n=buf_put("#defoff\r\n\r\n",n);
+    }
+  }
+
+  for(i=1;i<17;i++){
+    if( card_name[i][0]!=32 ){
+      int edp;
+      n=buf_put("#card=",n);
+      n=buf_put(fstr(i,2),n);n=buf_put(",",n);
+      n=buf_put(card_name[i],n);n=buf_put("\r\n",n);
+      n=buf_put(li0,n);
+
+      edp=127;while(edp>=0){
+       if(tim_names(edp+(15+i)*128)[0]!=0){break;}
+       edp--;
+      }
+      if(edp>=0){
+       edp|=7;
+       for(j=0;j<=edp;j++){
+         n=buf_put(spadd(tim_names(j+(15+i)*128),10),n);
+         if((j&7)!=7){n=buf_put(",",n);}else{n=buf_put("\r\n",n);}
+       }
+      }
+      n=buf_put(li0,n);
+      n=buf_put("#defoff\r\n\r\n",n);
+      tim_top[i+15]=0;
+    }
+  }
+
+  for(i=16;i<400;i++){
+    if( tim_top[i-1]!=0 || tim_head[i-1][0]!=0 ){
+
+      n=buf_put("#part=",n);
+      n=buf_put(fstr(i,3),n);n=buf_put(",",n);
+      n=buf_put(tim_head[i-1],n);n=buf_put(",",n);
+      n=buf_put(tim_sym[i-1],n);n=buf_put("\r\n",n);
+      n=buf_put(li0,n);
+
+      for(j=0;j<128;j++){
+       n=buf_put(tim_names(j+i*128-128),n);
+       if((j&3)!=3){n=buf_put(",",n);}else{n=buf_put("\r\n",n);}
+      }
+      n=buf_put(li0,n);
+      n=buf_put("#defoff\r\n\r\n",n);
+    }
+    if(i==100||i==200||i==300){ln=fwrite(dat,1,n,fp);n=0;}
+  }
+
+  n=buf_put("#end\r\n\r\n",n);
+  n=buf_put(li0,n);
+
+  ln=fwrite(dat,1,n,fp);
+
+  fclose(fp);
+
+  B_PRINT(_("Compile complete.\n"));
+  exit(1);
+
+  return(0);
+}
+
+/***************************//*4.66(2.18) 4.00(1.85)*/
+char   *exc_str(unsigned char *li,int ln,int md)
+{
+  char tmp0[1024];
+  int  i=0;
+
+  strcpy(tmp0,"");
+
+  while(i<ln && tmp0[i]!=0){
+    int        a;
+    a=tmp0[i];
+
+    if(a==0xff){break;}
+    if(a==0xf7){if(md!=0){strcat(tmp0,"F7");}break;}
+
+    if(a<0x80){
+      strcat(tmp0,hex_s(a,2));
+    }else{
+      if(a==0xf0){strcat(tmp0,"F0 ");}
+
+      if(a==0x80){strcat(tmp0,"gt ");}
+      if(a==0x81){strcat(tmp0,"ve ");}
+      if(a==0x82){strcat(tmp0,"ch ");}
+      if(a==0x83){strcat(tmp0,"cs ");}
+      if(a==0x84){strcat(tmp0,"cs ");}
+    }
+    i++;
+  }
+  return tmp0;
+}
+
+/***************************/
+int    buf_put(char *ptr,int ln)
+{
+  /*   if((rcd->bufcap)<(po+ln)){return(po+ln);}
+   */
+  while(*ptr){
+    dat[ln++]=*ptr++;
+  }
+  return(ln);
+}
+
+/***************************/
+int    def_bsave(char *fi,int last_no,int mutef,int initf)
+{
+  int  i,ln,n,top_no,cc,ad;
+  FILE *fp;
+
+  strmfe(fi,fi,"dfb");
+  if(!(fp=fopen2(fi,"wb"))){B_PRINT(_("Cannot open file.\n"));exit(1);}
+
+  for(i=0;i<work_size;i++){dat[i]=0;}
+
+  memcpy(&dat[0x0000],"STED2DEFFILE0.01",16);
+  memcpy(&dat[0x0010],module,32);                                      /*module*/
+  dat[0x30]=mdlflag;                                           /*id*/
+  dat[0x32]=mutef;                                             /*mute*/
+  dat[0x33]=initf;                                             /*init*/
+  n=lsp_wait;if(n<0){n=128;}dat[0x34]=n;                               /*lsp_wait*/
+  dat[0x36]=bend_range;                                                /*bend range*/
+  dat[0x38]=card_no[0];                                                /*card_no*/
+
+  for(i=0;i<8;i++){
+    memcpy(&dat[0x40+i*48],def_user_exc_memo[i],24);
+    memcpy(&dat[0x40+i*48+24],def_user_exc_data[i],24);        /*USER_EXC*/
+  }
+  memcpy(&dat[0x01c0],init_exc_data,256);                              /*INIT_EXC*/
+
+  for(i=0;i<10;i++){n=rec_met[i];if(n<0){n=128;}dat[0x2c0+i]=n;}       /*REC_MET*/
+  for(i=0;i<6;i++){n=rhy_stest[i];if(n<0){n=128;}dat[0x2ca+i]=n;}      /*RHY_AS*/
+
+  for(i=0;i<32;i++){
+    memcpy(&dat[0x300+i*16],defrhyna[i],14);
+    dat[0x300+i*16+14]=defrhyno[i][0];dat[0x300+i*16+15]=defrhyno[i][1];
+  }
+  for(i=0;i<16;i++){memcpy(&dat[0x500+i*48],card_name[i+1],48);}       /*card*/
+
+  memcpy(&dat[0x800],&tim_asin2[1],32);                                /*group*/
+  memcpy(&dat[0x820],&gs_mode[4],14*2);                                /*gsmode*/
+  memcpy(&dat[0x840],&gs_bank[128*4],14*128*2);                        /*gsbank*/
+
+
+  cc=0;for(i=0;i<400;i++){if(tim_top[i]>0 || tim_head[i][0]>0){cc++;}}
+  dat[0x1640]=cc>>8;dat[0x1641]=cc&0xff;
+  top_no=0;while(top_no<last_no){if(tim_name[top_no][0]){break;}top_no++;}
+  dat[0x1642]=last_no>>8;dat[0x1643]=last_no&0xff;
+  dat[0x1644]=top_no>>8;dat[0x1645]=top_no&0xff;
+
+  ad=0x1650;                                                   /*part*/
+  for(i=0;i<400;i++){
+    if(tim_top[i]>0 || tim_head[i][0]>0){
+      memcpy(&dat[ad],tim_head[i],20);
+      memcpy(&dat[ad+20],tim_sym[i],8);
+      dat[ad+28]=i>>8;dat[ad+29]=i&0xff;
+      dat[ad+30]=tim_top[i]>>8;dat[ad+31]=tim_top[i]&0xff;
+      ad+=32;
+    }
+  }
+
+
+  ln=fwrite(dat,1,ad,fp);
+
+  ln=last_no-top_no;
+  if(ln){ln=fwrite(&tim_name[top_no][0],1,ln*15,fp);}          /*tim_name*/
+
+  fclose(fp);
+
+  B_PRINT(_("Compile complete.\n"));
+  exit(1);
+
+  return(0);
+}
+#endif
+
+/***************************/
+int    def_bload(char *fi,int md)
+{
+  int  i,ln,n,f,top_no,last_no,mutef=0,initf=0,cc,ad;
+  FILE *fp;
+
+  strmfe(fi,fi,"dfb");
+  /*if(!(fp=fopen2(fi,"rb"))){return(-1);}*/
+  if (!(fp=fopen2(fi,"rb"))) {
+    char tmp0[1024];
+    strcpy( tmp0, STED_DEFAULT_PATH );
+    strcat( tmp0, "//" );
+    strcat( tmp0, (strrchr(fi,'/')==NULL)?fi:(strrchr(fi,'/')+1) );
+    if (!(fp=fopen2( tmp0, "rb" ))) return(-1);
+  } /* Oct.13.1998 by Daisuke Nagano */
+
+  ln=fread(dat,1,0x1650,fp);
+
+
+#if    STED
+  if(md==0){
+    B_PRINT(_("Loading config file.\n"));
+  }
+  if(md==1){
+    msg(_("Loading config file.\n"));
+  }
+#endif
+#if    CONV
+  B_PRINT(_("Dis-compiling config file.\n"));
+#endif
+
+  if( strncmp((const char *)&dat[0x0000],"STED2DEFFILE0.01",16)!=0 ){
+    if(md==0 || md==2){
+      B_PRINT(_("Invalid version number of config file.\n"));
+    }else{
+      msg(_("Invalid version number of config file.\n"));
+
+    }
+    /*fclose(fp);return(-2);*/
+    fclose(fp);exit(1);
+  }
+
+  memcpy(module,&dat[0x0010],32);                                      /*module*/
+  mdlflag=dat[0x30];                                           /*id*/
+  mutef=dat[0x32];                                             /*mute*/
+  initf=dat[0x33];                                             /*init*/
+  n=dat[0x34];if(n>127){n=-1;}lsp_wait=n;                              /*lsp_wait*/
+  bend_range=dat[0x36];                                                /*bend range*/
+  card_no[0]=dat[0x38];                                                /*card_no*/
+
+  for(i=0;i<8;i++){
+    memcpy(def_user_exc_memo[i],&dat[0x40+i*48],24);
+    memcpy(def_user_exc_data[i],&dat[0x40+i*48+24],24);        /*USER_EXC*/
+  }
+  memcpy(init_exc_data,&dat[0x01c0],256);                              /*INIT_EXC*/
+
+  for(i=0;i<10;i++){n=dat[0x2c0+i];if(n>127){n=-1;}rec_met[i]=n;}      /*REC_MET*/
+  for(i=0;i<6;i++){n=dat[0x2ca+i];if(n>127){n=-1;}rhy_stest[i]=n;}/*RHY_AS*/
+
+  for(i=0;i<32;i++){
+    memcpy(defrhyna[i],&dat[0x300+i*16],14);
+    defrhyno[i][0]=dat[0x300+i*16+14];
+    defrhyno[i][1]=dat[0x300+i*16+15];
+  }
+
+  for(i=0;i<16;i++){memcpy(card_name[i+1],&dat[0x500+i*48],48);}       /*card*/
+  memcpy(&tim_asin2[1],&dat[0x800],32);                                /*group*/
+  memcpy(&gs_mode[4],&dat[0x820],14*2);                                /*gsmode*/
+  memcpy(&gs_bank[128*4],&dat[0x840],14*128*2);                        /*gsbank*/
+
+  cc=dat[0x1640]*256+dat[0x1641];
+  last_no=dat[0x1642]*256+dat[0x1643];
+  top_no=dat[0x1644]*256+dat[0x1645];
+
+  ln=fread(dat,1,cc*32,fp);
+
+  ad=0;                                                                /*part*/
+  for(i=0;i<cc;i++){
+    int n=dat[ad+28]*256+dat[ad+29];
+    memcpy(tim_head[n],&dat[ad],20);
+    memcpy(tim_sym[n],&dat[ad+20],8);
+    tim_top[n]=dat[ad+30]*256+dat[ad+31];
+    ad+=32;
+  }
+
+  ln=last_no-top_no;
+  if(ln){ln=fread(&tim_name[top_no][0],1,ln*15,fp);}           /*tim_name*/
+
+  fclose(fp);
+
+#if    STED
+  f=(mdlflag&0x7);if(f>2){f=2;}
+  if(f>0 && f<4){rcd->moduletype=f-1;}
+
+  if(mutef){rcd->mute_mode=mutef-1;}
+  if(initf){rcd->init_mode=initf-1;}
+#endif
+
+#if    CONV
+  defsave(fi,md,mutef,initf);
+#endif
+
+  return(0);
+}
+
diff --git a/defload2.cpp b/defload2.cpp
new file mode 100644 (file)
index 0000000..7944519
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+  STed2 configuration file loader.
+  Copyright (C) 2000 NAGANO Daisuke
+ */
+#include "stdafx.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "iocslib.h"
+#include "doslib.h"
+#include "sted.h"
+#include "parsecfg.h"
+
+
+static cfgStruct cfgini[] = {
+  { NULL, CFG_END, NULL } /* terminator */
+};
+
+void definit( void ) {
+
+}
+
+int defload( char *fi, int md ) {
+
+  int max_sections;
+  char *filename, *basename;
+
+  max_sections = cfgParse( filename, cfgini, CFG_INI );
+
+}
diff --git a/disp.cpp b/disp.cpp
new file mode 100644 (file)
index 0000000..f124b0a
--- /dev/null
+++ b/disp.cpp
@@ -0,0 +1,670 @@
+/*
+ * STed: disp.c (input and output subroutine)
+ */
+
+#include       "sted.h"
+
+unsigned char  fnc_dat[9*10][9]={
+
+  /*edit*/
+  N_("  TOP   "),N_(" BOTTOM "),N_("REPLACE "),N_("  FIND  "),N_(" F.NEXT "),
+  N_("  MARK  "),N_(" DELETE "),N_("  COPY  "),N_("  PASTE "),N_(" DOUBLE "),
+
+  /*edit shift*/
+  N_(" NOTES  "),N_(" OPTIM. "),N_(" S.DEL  "),N_(" F.BACK "),N_(" F.PREV "),
+  N_("SET UNDO"),N_("DO UNDO "),N_("MIX PST."),N_("REV.PST."),N_("        "),
+
+  /*one touch st/gt*/
+  N_("  192   "),N_("  144   "),N_("   96   "),N_("   72   "),N_("   48   "),
+  N_("   36   "),N_("   24   "),N_("   18   "),N_("   12   "),N_("    6   "),
+
+  /*cm64 con*/
+  N_(" SYSTEM "),N_("LA PATCH"),N_("PCM PAT."),N_("RHY.PAT."),N_(" TIMBRE "),
+  N_("LOAD CM6"),N_("SAVE CM6"),N_("  PLAY  "),N_("CM6 INIT"),N_("  EXIT  "),
+
+  /*trk.exclu. edit*/
+  N_("SEND GT "),N_("SEND VEL"),N_("SEND CH."),N_("CLR SUM "),N_("SEND SUM"),
+  N_("END EXCL"),N_("        "),N_("CHEK.SUM"),N_("EXC LOAD"),N_("EXC SAVE"),
+
+  /*visual edit*/
+  N_("TOP POSI"),N_("LAST POS"),N_("  LINE  "),N_("        "),N_(" WAVE-A "),
+  N_(" WAVE-B "),N_("SIN +CRV"),N_("SIN WAVE"),N_("TRIANGLE"),N_(" SQUARE "),
+
+  /*visual edit shift*/
+  N_("REV. U&D"),N_("REV. L&R"),N_(" RANDOM "),N_("        "),N_("R.WAVE-A"),
+  N_("R.WAVE-B"),N_("SIN -CRV"),N_("SIN WA/C"),N_("TRIANG/C"),N_("SQUARE/C"),
+
+  /*user exclu. edit*/
+  N_("SEND GT "),N_("SEND VEL"),N_("SEND CH."),N_("CLR SUM "),N_("SEND SUM"),
+  N_("END EXCL"),N_("        "),N_("CHEK.SUM"),N_("REX LOAD"),N_("REX SAVE"),
+
+  /*one touch velo*/
+  N_("        "),N_("  ppp   "),N_("   pp   "),N_("   p    "),N_("   mp   "),
+  N_("   mf   "),N_("   f    "),N_("   ff   "),N_("  fff   "),N_("        ")};
+
+char   hex_code[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
+
+int    meas_add(int me);
+
+int isinputmode=0;
+
+/***************************/
+int    vinput(int l,int ln)
+{
+  char sb[256];
+  char *pp=(char *)sb;
+
+  if(ln & 0x2000){strcpy(sb,hex_s(l,ln&0xff));}else{b_striS(sb,256,l);}
+
+  while(*pp=='0'){pp++;}
+  strcpy(sb,pp);
+
+  if( l==0 ){sb[0]=0;}
+
+re_vinp:
+  sinput(sb,0x1400|ln);if(ecode==14){goto re_vinp;}
+  if( sb[0]==0 ){return(0);}
+  if(ln & 0x2000){strcat(sb,"H");}
+  return(str_val(sb));
+}
+
+/***************************/
+/*
+  im  exc  len
+  0000 0000 0000 0000
+  |||| ||||
+  |||| |||+-return/space
+  |||| ||+--not return 
+  |||| |+---cursor last p.
+  |||| +----over write
+  | |+------chr.type(0=all/1=hex)
+  | +-------hex mode(vinput only)
+  +---------space nocut
+  -----------point move
+  */
+void   sinput(char *sb,int ln)
+{
+  int  a,x,y,xx,p=0,o=0,exc,im,sln;
+  char ke[4],st[256],tmp0[256];
+
+  x=B_LOCATE(-1,0);y=x&0xffff;x=x>>16;
+  exc=ln>>8;ln=ln&0xff;im=(exc>>4)&3;
+  if((exc&0x80)==0){spcut(sb);}
+
+  if( (exc & 8)!=0 ){st[0]=0;o=1;}else{strcpy(st,sb);}
+  if( (exc & 4)!=0 ){p=strlen(st);}
+
+  if((exc&0x100)!=0){
+    int c=str_search(sb,"$<");
+    if(c){p=c-1;strcpy(&sb[c-1],&sb[c+1]);}
+  }
+
+  xx=x*8;if(edit_scr==1){xx=xx+56*8;}
+  /*c=point(xx,y*16+scyp);*/
+  fill(xx-1,y*16+scyp,xx+(ln)*8+1,y*16+15+scyp,7);
+  /*tdis(x,y,sb,ln,3);*/ /* Aug.28.1998 Daisuke Nagano */
+  tdis(x,y,eucconv(sb),ln,3); /* code converted! */
+
+  isinputmode=1;
+
+  while(1){
+    B_LOCATE(x+p,y);C_CURON();/*while(INPOUT(0xfe)==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+    key_wait();
+    a=INPOUT(0xff);ecode=a;ke[0]=a;ke[1]=0;
+    sln=strlen(st);st[sln+1]=0;
+
+    if( (127<a && 161>a) || 224<a ){ke[1]=INPOUT(0xff);ke[2]=0;}
+    C_CUROFF();
+    if((a>=13 && a<=15)||((a==0x13||a==0x04||a==0x18||a==0x05||a==32)&&(exc&1)!=0)){
+      if((cmdflag&0x2)!=0 && (exc&1)!=0){
+       if(a==32){a=13;}else{if(a==13){a=32;}}
+      }
+      if(a==32||a==15){a=0x04;}
+      es=0;ecode=a;
+      if( st[0]==0 && o==1 ){break;}
+      if((exc&0x80)==0){spcut(st);}
+      strcpy(sb,st);break;
+    }
+
+    if( a==27 ){es= 1;break;}
+    if( a==0x18 && (exc&2)!=0 ){es= 0;break;}
+    if( a==0x13 && p>0 ){if(p==1){p=0;}else{if(knck(st,p-2)){p=p-2;}else{p=p-1;}}}
+    if( a==0x04 ){if( knck(st,p) ){p=p+(p+2<=ln)*2;}else{p=p+(p+1<=ln);}}
+
+    if( a==0x10 ){p=sln;}
+    if( a==0x11 ){p=0;}
+    if( a==0x15 ){strcpy(st,&st[p]);p=0;}
+
+    if( p>sln ){p=sln;}
+
+    if( a==0x0c ){p=0;st[0]=0;}
+
+    if( st[0]!=0 ){
+      if( a==8 && p>0 ){
+       int i=1+knck(st,p-2);
+       strcpy(tmp0,&st[p]);st[p-i]=0;strcat(st,tmp0);
+       p=p-i;
+      }
+      if( a==0x07 ){
+       strcpy(tmp0,&st[p+1+knck(st,p)]);st[p]=0;strcat(st,tmp0);
+      }
+      if( a==0x0b ){
+       st[p]=0;
+      }
+    }
+
+    if( im!=1 || (im==1 && str_search("0123456789ABCDEFabcdef.-Hh$",ke)>0) ){
+
+      if( a>31 && a!=127 ){
+       if( (B_SFTSNS()&4096)==0 && st[0]!=0 ){
+         strcpy(tmp0,&st[p+1+knck(st,p)]);st[p]=0;strcat(st,tmp0);
+       }
+       sln=strlen(st);
+       if( (sln+strlen(ke))<=ln ){
+         if( sln==p ){
+           strcat(st,ke);
+         }else{
+           strcpy(tmp0,&st[p]);st[p]=0;strcat(st,ke);strcat(st,tmp0);
+         }
+         p=p+strlen(ke);
+       }
+      }
+    }
+    /*tdis(x,y,st,ln,3);*/ /* Aug.28.1998 Daisuke nagano */
+    tdis(x,y,eucconv(st),ln,3); /* code converted! */
+  }
+  /*
+  tdis(x,y,sb,ln,3);B_LOCATE(x,y);
+  fill(xx-1,y*16+scyp,xx+ln*8+1,y*16+15+scyp,0);
+  */ /* Aug.28.1998 Daisuke Nagano */
+  fill(xx-1,y*16+scyp,xx+ln*8+1,y*16+15+scyp,0);
+  tdis(x,y,eucconv(sb),ln,3);B_LOCATE(x,y); /* code converted! */
+
+  isinputmode=0;
+}
+
+/***************************/
+int    inkey2()
+{
+  int  ke=0;
+  while(INPOUT(0xfe)!=0){INPOUT(0xff);}
+  /*while(ke==0){ke=INPOUT(0xff);}*/
+  key_wait();ke=INPOUT(0xff);
+  /*   if(ke>='a' && ke<='z'){ke-=32;}*/
+  return(ke);
+}
+
+/***************************/
+int    inkey3(void)
+{
+  int  ke=0,ex,sh;
+
+  while(INPOUT(0xfe)!=0){INPOUT(0xff);}
+  /*  while(ke==0){*/
+    key_wait();
+    ke=INPOUT(0xff);sh=B_SFTSNS()&15;
+
+    ex=BITSNS(0xa);
+    if( (ex&32)!=0 ){ke=0xe0;}
+    if( (ex&64)!=0 ){ke=0xe1;}
+    if( (ex&128)!=0 && sh==0){rcd->sts=0;}
+    ex=BITSNS(0xb);
+    if( (ex&1)!=0 && sh==0){rcd->sts=1;}
+    if( (ex&2)!=0 && sh==0){all_note_off(1);}
+    ex=BITSNS(0xc);
+    if( (ex&8)!=0 ){ke=0xf0;}
+    if( (ex&16)!=0 ){ke=0xf1;}
+    if( (ex&32)!=0 ){ke=0xf2;}
+    if( (ex&64)!=0 ){ke=0xf3;}
+    if( (ex&128)!=0 ){ke=0xf4;}
+    ex=BITSNS(0xd);
+    if( (ex&1)!=0 ){ke=0xf5;}
+    if( (ex&2)!=0 ){ke=0xf6;}
+    if( (ex&4)!=0 ){ke=0xf7;}
+    if( (ex&8)!=0 ){ke=0xf8;}
+    if( (ex&16)!=0 ){ke=0xf9;}
+    /*  }*/
+  while(INPOUT(0xfe)!=0){INPOUT(0xff);}
+  return(ke+(sh*256));
+}
+
+/***************************/
+void   snsclr()
+{
+  while(B_KEYSNS()){B_KEYINP();}
+}
+
+/***************************/
+void   spcut(char *st)
+{
+  int  p;
+
+  p= strlen(st);
+  while(1){
+    if( p<1 ){st[0]=0;return;}
+    if( st[p-1]!=32 && st[p-1]!=9 ){break;}
+    p--;
+  }
+  if( knck(st,p) ){p++;}
+  st[p]=0;
+}
+
+/***************************/
+int    knck(char *st,int p)
+{
+  int  i,f=0,a;
+
+  if( p<0 ){return(0);}
+  for(i=0 ;i<=p;i++){a=st[i];if( 127<a && (161>a || 224<a) ){f=(i==p);i++;}}
+  return(f);
+}
+
+/***************************/
+int    str_search(char *tmp0,char *tmp1)
+{
+  int  i=0;
+  unsigned char        a;
+
+  while(tmp0[i]!=0){
+    a=tmp0[i];
+    if(a==tmp1[0]){
+      int j=0;
+      while(1){
+       if(tmp0[i+j]!=tmp1[j]){break;}
+       j++;
+       if(tmp1[j]==0){return(i+1);}
+      }
+    }
+    i++;
+    if( a>127 && (a<161 || a>224) ){i++;}
+  }
+  return(0);
+}
+
+/***************************/
+int    str_last(unsigned char *tmp0)
+{
+  int  i,a;
+
+  i=strlen((char*)tmp0);
+  if(i<2){return(tmp0[0]);}
+
+  a=tmp0[i-1];
+  if(knck((char*)tmp0,i-2)){a=tmp0[i-2]*256+a;}
+  return(a);
+}
+
+/***************************/
+char   *jstrupr(char *st)
+{
+  char a;
+  char *ss;
+  ss = st;
+
+  while(*st!=0){
+    a=*st;
+    if( 127<a && (161>a || 224<a) ){
+      st++;
+    }else{
+      if('a'<=a && 'z'>=a){*st=a-32;}
+    }
+    st++;
+  }
+  return(ss);
+}
+
+/***************************/
+char   *spadd(char *s,int c)
+{
+  static char  tmp0[128];
+  int  i;
+
+  strcpy(tmp0,s);for(i=strlen(s);i<=127;i++){tmp0[i]=32;}
+  tmp0[c]=0;return(tmp0);
+}
+
+/***************************/
+char   *fstr(int v,int c)
+{
+  static       char    tmp0[64];
+  char tmp1[64];
+
+  b_striS(tmp1,64,v);strcpy(tmp0,"                ");strcat(tmp0,tmp1);
+  return(&tmp0[strlen(tmp0)-c]);
+}
+
+char   *nstr(int v)
+{
+  static       char    tmp0[64];
+
+  b_striS(tmp0,64,v);
+  return(tmp0);
+}
+
+/***************************/
+int    str_val(char *s)
+{
+  int  v=0;
+  unsigned char        a;
+
+  while(*s==' '){s++;}
+
+  jstrupr(s);
+  if(str_last((uint8*)s)!='H' && s[0]!='$' ){return atoi(s);}
+
+  while(*s!=0){
+    a=*s++;
+    if(a==' '||a==',' || a=='='){break;}
+    if(a>='0' && a<='9'){v=v<<4;v=v+(a-'0');}
+    if(a>='A' && a<='F'){v=v<<4;v=v+(a-'A')+10;}
+  }
+
+  return v;
+}
+
+/***************************/
+char   *hex_s(int a,int c)
+{
+  static       char    s[16];
+
+  s[c]=0;
+  while(c){c--;s[c]=hex_code[a&15];a=a>>4;}
+  return(s);
+}
+
+static int last_fncdis=-1;
+
+/***************************/
+void   fnc_dis(int n)
+{
+  int  i,j;
+  char tmp[64];
+
+  if (n==last_fncdis) return;
+  last_fncdis = n;
+
+  KNJCTRL(1,0);
+  if( n<0 ){
+    TXRASCPY((30*4)*256+(31*4),4,3);
+    for(i=1;i<=20;i++){FNCKEYST(i,"");}
+  }else{
+    if( n==2 ){
+      for(i=0;i<10;i++){
+       strcpy(tmp,fstr(stgt_tbl[i],4));
+       strcat(tmp,fstr(stgt_tbl[i+10],5));
+       for(j=0;j<9;j++){if(tmp[j]==32){tmp[j]='\\';}}
+
+       tmp[0]=0x0c;tmp[4]=0x0f;
+       tmp[5]=0x0c;tmp[9]=0x0e;tmp[10]=0;
+       FNCKEYST(i+1,tmp);
+       tmp[6]='0';tmp[7]=0xe;tmp[8]=0;
+
+       FNCKEYST(i+1+10,tmp);
+      }
+    }
+    if( n==8 ){
+      for(i=0;i<10;i++){
+       strcpy(tmp,fstr(stgt_tbl[i+20],3));
+       for(j=0;j<2;j++){if(tmp[j]==32){tmp[j]='\\';}}
+
+       tmp[3]=0x0d;tmp[4]=0;
+       FNCKEYST(i+1,tmp);
+       FNCKEYST(i+11,tmp);
+      }
+    }
+
+    tmp[0]=32;tmp[1]=0;if(n==1){tmp[0]='*';}
+    B_PUTMES(3,0,31,1,tmp);
+
+    for(i=0;i<=9;i++){
+      j=i*9+2;if(i>4){j+=3;}
+      B_PUTMES(11,j,31,7,_((const char *)fnc_dat[n*10+i]));
+    }
+    if ( (B_SFTSNS()&16)!=0 )
+      B_PUTMES( 3, 47, 31, 0, "*" );
+    else
+      B_PUTMES( 3, 47, 31, 0, " " );
+  }
+}
+
+/***************************/
+void   home2(int y)
+{
+  HOME(0,0,y);scyp=y;
+}
+
+/***************************/
+void   edfield(int m)
+{
+  if(m<1){fill(0,544,767,1023,0);if(m!=0){return;}}
+  if(edit_scr<2 ){
+    int        xx;
+
+    if(m!=0){
+      if(edit_scr==0){fill(0,544,312,1001,0);}else{fill(455,544,767,1001,0);}
+    }
+    if(edit_scr==0){xx=1;box(7,603,312,999,4,65535);
+    }else{xx=57;box(455,603,760,999,4,65535);}
+
+    sdis(xx,556,"M:",3,15,8);
+    sdis2(xx,572," TR.:   MEAS:      CH.:    USED:",0,15,-1);
+    sdis(xx,589," MEAS STEP:NOTE K#    ST    GT   VEL",38,15,14);
+  }else{
+    sdis(21,556,"MEMO:",41,15,8);sdis(64,556,"TR.:",6,15,8);
+    sdis(72,556,"CH.:",7,15,8);sdis(80,556,"USED:",10,15,8);
+
+    box(0,630,688,1001,14,65535);
+    box(2,632,26,903,14,65535);box(28,632,148,903,14,65535);
+    box(2,905,148,999,14,65535);box(150,632,686,999,14,65535);
+
+    sdis(0,599+16,"    RHYTHM NAME   :STEP    4       8      12      16      20      24      28      32",86,15,14);
+    sdis(2,512+26*16,"VEL :",4,15,-1);sdis(2,512+27*16," GT :",4,15,-1);
+
+    sdis(46,592,"VEL",3,15,0);
+    box(397,590,642,608,14,65535);box(363,588,644,610,14,65535);
+  }
+  trk_free(tr_pos[track][edit_scr][0]+tr_pos[track][edit_scr][2]*4);trk_no();snsclr();
+}
+
+/***************************/
+void   noed_cls()
+{
+  if(edit_scr!=0){fill(0,544,454,1001,0);}else{fill(313,544,767,1001,0);}
+}
+
+void   noed_cls_t()
+{
+  if(edit_scr!=0){txerase(0,32,454,489-32);}else{txerase(313,32,767-313,489-32);}
+}
+
+/***************************/
+void   cons_md(int x)
+{
+  if(edit_scr==1 && x!=0){B_CONSOL(56*8,0,95-56,30);}else{B_CONSOL(0,0,95,30);}
+}
+
+/***************************/
+void   trk_free(int ad)
+{
+  int  xx,yy,cc;
+  char tmp[10];
+
+  if(edit_scr>=2){
+    xx=66;yy=556;cc=8;
+  }else{
+    if(edit_scr==0){xx=13+1;}else{xx=69+1;}
+    yy=572;cc=0;
+
+    vdis2(xx,yy,meas_no(ad),4,15,cc);
+  }
+
+  strcpy(tmp,chstr(channel_no(ad)));
+  sdis2(xx+10,yy,tmp,3,15,cc);
+
+  vdis2(xx+19,yy,(tr_len[track]>>2)-1,5,15,cc);
+
+  trksize(-2);
+}
+
+/***************************/
+void   trk_no()
+{
+  int  xx=31-8;
+
+  trk_no_dis();
+  if(edit_scr<2){
+    if(edit_scr==0){xx=0;}else{xx=56;}
+    vdis2(xx+6,572,track+1,2,15,0);
+  }else{
+    vdis2(68,556,track+1,2,15,8);
+  }
+  /*sdis(xx+3,556,trkmemo[track],36,15,8);*/
+  sdis(xx+3,556,eucconv(trkmemo[track]),36,15,8); /* Jul.02.1998 Daisuke Nagano */
+}
+
+/***************************/
+void   sdis(int x,int y,char *s,int c,int c1,int c2)
+{
+  x=x*8;
+  if( c2>=0 ){fill(x-1,y-1,x+c*8,y+15,c2);}
+  g_print(x,y,s,c1);
+}
+
+/***************************/
+void   sdis2(int x,int y,char *s,int c,int c1,int c2)
+{
+  x=x*8;
+  if( c2>=0 ){fill(x-1,y,x+c*8,y+15,c2);}
+  g_print(x,y,s,c1);
+}
+
+/***************************/
+void   sdis3(int x,int y,char *s,int c,int c1,int c2)
+{
+  x=x*8;
+  if( c2>=0 ){fill(x-1,y,x+c*8,y+7,c2);}
+  g_print2(x,y,s,c1);
+}
+
+/***************************/
+void   vdis(int x,int y,int v,int c,int c1,int c2)
+{
+  sdis(x,y,fstr(v,c),c,c1,c2);
+}
+
+/***************************/
+void   vdis2(int x,int y,int v,int c,int c1,int c2)
+{
+  sdis2(x,y,fstr(v,c),c,c1,c2);
+}
+
+/***************************/
+void   vdis3(int x,int y,int v,int c,int c1,int c2)
+{
+  sdis3(x,y,fstr(v,c),c,c1,c2);
+}
+
+/***************************/
+void   g_print2(int x,int y,char *s,int c1)
+{
+  char tmp2[256];
+  int i=0;
+
+  while(*s!=0){tmp2[i++]=0xf0;tmp2[i++]=*s++;}
+  tmp2[i]=0;
+
+  g_print(x,y,tmp2,c1);
+}
+
+/***************************/
+void   tdis(int x,int y,char *s,int c,int c1)
+{
+  if(c1>=0){B_COLOR(c1);}
+  B_LOCATE(x,y);B_PRINT(spadd(s,c));B_COLOR(3);
+}
+
+/***************************/
+void   msg(char *s)
+{
+  msg_clr();B_LOCATE(0,1);B_PRINT(s);
+}
+
+void   msg_clr()
+{
+/*  TXRASCPY((30*4)*256+(1*4),4,3);*/
+  B_LOCATE(0,1);B_PRINT("                                                                                                ");
+}
+
+/***************************/
+int    help(int md)
+{
+  int  k,y,n,pg=0,ad,page=0,ln;
+  int  poi[128];
+  char li[1024];
+  FILE *fp;
+
+  if(!(fp= fopen2(hlp_path,"rb"))){
+    msg(_("Cannot find help file."));return(1);}
+  ln=fread(dat,1,63*1024,fp);fclose(fp);
+
+  ad=0;poi[0]=0;dat[ln]=0x1a;
+  while(ad<ln && page<127){
+    if(dat[ad]==12 || dat[ad]==0x1a ){
+      if( dat[ad]==12 ){ad=ad+2;}
+      page++;poi[page]=ad+1;
+      if( dat[ad]==0x1a){break;}
+    }
+    ad++;
+  }
+  if(page>0){page--;}
+
+  fill(0,544,767,1001,0);box(0,564,767,1001,14,65535);
+  sdis(0,548," COMMAND HELP",14,15,8);home2(512);
+  C_WINDOW(0,32);
+  B_LOCATE(0,31);B_PRINT(_(" [SPC]/[R.UP] NEXT PAGE  [BS]/[R.DOWN] PREV. PAGE  [TAB] SPECIFY PAGE  [ESC] EXIT"));
+
+  C_WINDOW(0,31);
+
+  while(1){
+    B_CLR_AL();
+    B_LOCATE(80,2);B_PRINT("PAGE:");B_PRINT(fstr(pg+1,3));
+    B_PRINT("/");B_PRINT(fstr(page+1,3));
+
+    y=4;ad=poi[pg];
+    while( dat[ad]!=0x1a && dat[ad]!=0 && dat[ad]!=12){
+      n=0;
+      while(dat[ad]>31||dat[ad]==9||dat[ad]==27){li[n]=dat[ad];n++;ad++;}
+      li[n]=0;if( li[0]!='*' ){B_LOCATE(0,y);B_PRINT(li);y++;}
+
+      ad++;
+      if(dat[ad]==0x0d){ad++;}
+      if(dat[ad]==0x0a){ad++;}
+    }
+    while(1){
+      k=inkey2();
+      if(k==27){break;}
+      if(k==0x12||k==32){
+       pg++;if(pg>page){pg=0;}
+       break;
+      }
+      if(k==0x17||k==8){
+       pg--;if(pg<0){pg=page;}
+       break;
+      }
+
+      if( k==9 ){
+       int n;
+       msg("Page No.=");n=vinput(pg+1,0x803);msg_clr();
+
+       if( es==0 && n>0 && n<=page+1){
+         pg=n-1;break;
+       }
+      }
+
+    }
+    if(k==27){break;}
+  }
+  C_WINDOW(0,32);B_CLR_AL();C_WINDOW(0,31);return(0);
+}
+
+/***************************/
diff --git a/dlg_mididevice.cpp b/dlg_mididevice.cpp
new file mode 100644 (file)
index 0000000..6d67f27
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+  dlg_mididevice.cpp
+
+  Made by Studio Breeze. 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+#include "stdafx.h"
+#include "sted_screen_win32.h"
+#include "sted_dialogs.h"
+
+#include "resource.h"
+
+static void DlgMidi_SetListBox(HWND hwnd);
+static void DlgMidi_GetParameters(HWND hwnd);
+
+LRESULT CALLBACK
+Dlg_MidiDevices(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+       switch (message)
+       {
+       case WM_INITDIALOG:
+               DlgMidi_SetListBox(hDlg);
+               return TRUE;
+
+       case WM_COMMAND:
+               if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
+               {
+                       if (LOWORD(wParam) == IDOK) {
+                               DlgMidi_GetParameters(hDlg);
+                       }
+                       EndDialog(hDlg, LOWORD(wParam));
+                       return TRUE;
+               }
+               break;
+       }
+       return FALSE;
+}
+
+//
+
+static void
+DlgMidi_SetListBox(HWND hwnd)
+{
+       int min, mout;
+       MIDIINCAPS mic;
+       MIDIOUTCAPS moc;
+       MMRESULT result;
+       int i;
+       HWND wnd, wnd2;
+       BOOL added;
+
+       wnd = ::GetDlgItem(hwnd, IDC_MIDIIN);
+       min = ::midiInGetNumDevs();
+
+       added = FALSE;
+       if (wnd && min>0) {
+               for (i=0; i<min; i++) {
+                       result = ::midiInGetDevCaps(i, &mic, sizeof(MIDIINCAPS));
+                       if (result==MMSYSERR_NOERROR) {
+                               ::SendMessage(wnd, CB_ADDSTRING, -1, (LPARAM)mic.szPname);
+                               added = TRUE;
+                       }
+               }
+               if (added) {
+                       ::SendMessage(wnd, CB_INSERTSTRING, 0, (LPARAM)TEXT("--disable--"));
+                       ::SendMessage(wnd, CB_SETCURSEL, 1, 0);
+                       ::EnableWindow(wnd, TRUE);
+               }
+       } else if (wnd) {
+               ::SendMessage(wnd, CB_INSERTSTRING, 0, (LPARAM)TEXT("--disable--"));
+               ::SendMessage(wnd, CB_SETCURSEL, 0, 0);
+       }
+
+
+       wnd = ::GetDlgItem(hwnd, IDC_MIDIOUT0);
+       wnd2 = ::GetDlgItem(hwnd, IDC_MIDIOUT1);
+       mout = ::midiOutGetNumDevs();
+       added = FALSE;
+       if (mout>0 && wnd && wnd2) {
+               for (i=0; i<mout; i++) {
+                       result = ::midiOutGetDevCaps(i, &moc, sizeof(MIDIOUTCAPS));
+                       if (result==MMSYSERR_NOERROR) {
+                               ::SendMessage(wnd, CB_ADDSTRING, -1, (LPARAM)moc.szPname);
+                               ::SendMessage(wnd2, CB_ADDSTRING, -1, (LPARAM)moc.szPname);
+                               added = TRUE;
+                       }
+               }
+               if (added) {
+                       ::SendMessage(wnd, CB_INSERTSTRING, 0, (LPARAM)TEXT("--disable--"));
+                       ::SendMessage(wnd2, CB_INSERTSTRING, 0, (LPARAM)TEXT("--disable--"));
+                       ::SendMessage(wnd, CB_SETCURSEL, 1, 0);
+                       ::SendMessage(wnd2, CB_SETCURSEL, 1, 0);
+                       ::EnableWindow(wnd, TRUE);
+                       ::EnableWindow(wnd2, TRUE);
+               }
+       } else {
+               if (wnd) {
+                       ::SendMessage(wnd, CB_INSERTSTRING, 0, (LPARAM)TEXT("--disable--"));
+                       ::SendMessage(wnd, CB_SETCURSEL, 0, 0);
+               }
+               if (wnd2) {
+                       ::SendMessage(wnd2, CB_INSERTSTRING, 0, (LPARAM)TEXT("--disable--"));
+                       ::SendMessage(wnd, CB_SETCURSEL, 0, 0);
+               }
+       }
+}
+
+static void DlgMidi_GetParameters(HWND hwnd)
+{
+       HWND wnd;
+       CSTedScreenWin32* drv;
+       int min, mout[2];
+       int index;
+       int max;
+
+       drv = (CSTedScreenWin32 *)GetDriver();
+       if (!drv) return;
+
+       min = -1;
+       wnd = ::GetDlgItem(hwnd, IDC_MIDIIN);
+       max = ::midiInGetNumDevs();
+       if (wnd) {
+               index = (int)::SendMessage(wnd, CB_GETCURSEL, 0, 0);
+               if (index<0 || index>max) min = -1;
+               else min = index-1;
+       }
+
+       mout[0] = -1;
+       wnd = ::GetDlgItem(hwnd, IDC_MIDIOUT0);
+       max = ::midiOutGetNumDevs();
+       if (wnd) {
+               index = (int)::SendMessage(wnd, CB_GETCURSEL, 0, 0);
+               if (index<0 || index>max) mout[0] = -1;
+               else mout[0] = index-1;
+       }
+
+       mout[1] = -1;
+       wnd = ::GetDlgItem(hwnd, IDC_MIDIOUT1);
+       if (wnd) {
+               index = (int)::SendMessage(wnd, CB_GETCURSEL, 0, 0);
+               if (index<0 || index>max) mout[1] = -1;
+               else mout[1] = index-1;
+       }
+
+       drv->CloseMidiDevice();
+       drv->SetMidiPorts(min, mout);
+       drv->OpenMidiDevice();
+}
+
diff --git a/dos.cpp b/dos.cpp
new file mode 100644 (file)
index 0000000..31e58d4
--- /dev/null
+++ b/dos.cpp
@@ -0,0 +1,307 @@
+/*
+  dos.c
+
+  functions for compatibility to doslib
+
+  ( mainly contains file-oriented functions )
+
+  Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+/* variables */
+
+//char fnc_func[10][32];
+//char fnc_sfunc[10][32];
+//char fnc_key[12][6];
+
+/* ROLL UP, ROLL DOWN, INS, DEL,
+   UP, LEFT, RIGHT, DOWN,
+   CLR, HELP, HOME, UNDO */
+
+/* console-oriented functions */
+
+int
+_dos_c_cls_al ( void )
+{
+  _iocs_b_clr_al();
+  return 0;
+}
+
+int
+_dos_c_cls_ed( void )
+{
+  _iocs_b_clr_ed();
+  return 0;
+}
+
+int
+_dos_c_curoff( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+  scr->SetCursor(EButtonOff);
+  return 0;
+}
+
+int
+_dos_c_curon( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+  scr->SetCursor(EButtonOn);
+  return 0;
+}
+
+int
+_dos_c_fnkmod( int in_mode )
+{
+  /* not implemented */
+  return 0;
+}
+
+int
+_dos_c_window( int in_x, int in_y )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+  scr->SetTextWindow(in_x, in_y);
+  scr->Locate(0, 0);
+  return 0;
+}
+
+int
+_dos_fnckeygt( int in_fno, char *in_buff )
+{
+  /* not implemented */
+  return 0;
+}
+
+int
+_dos_fnckeyst( int fno, const char *buff )
+{
+  int i,j;
+  const char *p;
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  p=buff;
+
+  if (fno==0) {
+    for ( i=0 ; i<10 ; i++ ) {
+      for ( j=0 ; j<32 ; j++ ) {
+       fnc_func[i][j]=*p++;
+      }
+    }
+    for ( i=0 ; i<10 ; i++ ) {
+      for ( j=0 ; j<32 ; j++ ) {
+       fnc_sfunc[i][j]=*p++;
+      }
+    }
+    for ( i=0 ; i<12 ; i++ ) {
+      for ( j=0 ; j<6 ; j++ ) {
+       fnc_key[i][j]=*p++;
+      }
+    }
+  } else if ( fno<=10 ) {
+    for ( j=0 ; j<32 ; j++ ) {
+      fnc_func[fno-1][j]=*p++;
+    }
+  } else if ( fno<=20 ) {
+    for ( j=0 ; j<32 ; j++ ) {
+      fnc_sfunc[fno-11][j]=*p++;
+    }
+  } else if ( fno<=32 ) {
+    for ( j=0 ; j<6 ; j++ ) {
+      fnc_key[fno-21][j]=*p++;
+    }
+  }
+
+  scr->SetFncKey(fnc_key);
+  return 0;
+}
+
+int
+_dos_inpout( int in_code )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  if ( (in_code==0xfe) || (in_code==0xff) ) {
+    return scr->KeyIn(in_code);
+  }
+}
+
+/* functions */
+
+void *
+_dos_malloc(int in_size)
+{
+  void *tmp;
+
+  tmp = (void *)malloc(in_size);
+  if ( tmp == NULL ) tmp = (void *)0x82000000;
+
+  return tmp;
+  
+}
+
+
+/* file related */
+
+dosmode_t
+_dos_chmod( const char *in_name, dosmode_t in_atr )
+{
+  /* returns only one flag : is the file "name" directory? */
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileChmod(in_name, in_atr);
+}
+
+int
+_dos_chdir( const char *in_name )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileChdir(in_name);
+}
+
+int
+_dos_curdir( int in_drive, char *out_buff )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileCurdir(in_drive, out_buff);
+}
+
+int
+_dos_curdrv( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileCurdrv();
+}
+
+int
+_dos_delete( const char *in_name )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileDelete(in_name);
+}
+
+int _dos_drvctrl( int mode, int drive ) {
+
+  return 2; /* media inserted, ready, not protected, enable eject by user,
+              no buffer, enable eject, not blink LED */
+}
+
+int
+_dos_rename( const char *in_name, const char *in_nname )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileRename(in_name, in_nname);
+}
+
+int _dos_super( int stack ) {
+
+  return 1; /* ignore */
+}
+
+int
+_dos_files (struct _x68_filbuf *in_buff, const char *in_name, int in_atr )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileFiles(in_buff, in_name, in_atr);
+}
+
+int
+_dos_nfiles( struct _x68_filbuf *in_buff )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->FileNfiles(in_buff);
+}
+
+int _dos_setblock( void *memptr, int newsize ) {
+
+  /* not implemented */
+  return -1;  
+}
+
+int dskf( char drive_number ) {
+
+  /* max 8 keta */
+  return 58371500;
+}
+
+FILE
+*fopen2( char *in_name, char *in_mode)
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return NULL;
+
+  return scr->FileFopen(in_name, in_mode);
+}
diff --git a/doslib.h b/doslib.h
new file mode 100644 (file)
index 0000000..5a1197b
--- /dev/null
+++ b/doslib.h
@@ -0,0 +1,258 @@
+/* doslib.h
+
+   dummy header file for X680x0 compatible
+
+   Made by Studio Breeze. 1998
+
+*/
+#pragma once
+#ifndef _X68_DOSLIB_H_
+#define _X68_DOSLIB_H_
+
+/* structs */
+
+#ifndef __dosmode_t_defined__
+#define __dosmode_t_defined__
+typedef int dosmode_t;
+#endif
+
+struct _x68_filbuf {
+  unsigned char searchatr; /* attributes for searching files */
+  unsigned char driveno;   /* drive number */
+  unsigned short dircls;   /* claster number */
+  unsigned short dirfat;   /* FAT number of file */
+  unsigned short dirsec;   /* sector number of directory */
+  unsigned short dirpos;   /* position in directory */
+  char filename[8];        /* filename of file */
+  char ext[3];             /* extension of file */
+  unsigned char atr;       /* attributes of file */
+  unsigned short time;     /* time of file */
+  unsigned short date;     /* date of file */
+  unsigned int filelen;    /* length of file */
+  char name[23];           /* long-filename( Human68k format ) */
+};
+
+#define X68_FILBUF _x68_filbuf
+
+/* defines for upper-cased-name functions */
+
+#define COMLINE                _comline
+#define DPBPTR         _dpbptr
+#define DREGS          _dregs
+#define FREEINF                _freeinf
+#define INPPTR         _inpptr
+#define INQUIERY       _inquiry
+#define NAMECKBUF      _nameckbuf
+#define NAMESTBUF      _namestbuf
+#define PRCCTRL                _prcctrl
+#define PRCPTR         _prcptr
+#define READCAP                _readcap
+
+#define ALLCLOSE       _dos_allclose
+#define BINDNO         _dos_bindno
+#define BREAKCK                _dos_breakck
+#define BUS_ERR                _dos_memcpy
+#define CHANGE_PR      _dos_change_pr
+#define CHDIR          _dos_chdir
+#define CHGDRV         _dos_chgdrv
+#define CHMOD          _dos_chmod
+#define CINSNS         _dos_cinsns
+#define CLOSE          _dos_close
+#define COMINP         _dos_cominp
+#define COMMON_CK      _dos_common_ck
+#define COMMON_DEL     _dos_common_del
+#define COMMON_FRE     _dos_common_fre
+#define COMMON_LK      _dos_common_lk
+#define COMMON_RD      _dos_common_rd
+#define COMMON_WT      _dos_common_wt
+#define COMOUT         _dos_comout
+#define CONSNS         _dos_consns
+#define COUTSNS                _dos_coutsns
+#define CREATE         _dos_create
+#define CTLABORT       _dos_ctlabort
+#define CURDIR         _dos_curdir
+#define CURDRV         _dos_curdrv
+#define C_CLS_AL       _dos_c_cls_al
+#define C_CLS_ED       _dos_c_cls_ed
+#define C_CLS_ST       _dos_c_cls_st
+#define C_COLOR                _dos_c_color
+#define C_CUROFF       _dos_c_curoff
+#define C_CURON                _dos_c_curon
+#define C_DEL          _dos_c_del
+#define C_DOWN         _dos_c_down
+#define C_DOWN_S       _dos_c_down_s
+#define C_ERA_AL       _dos_c_era_al
+#define C_ERA_ED       _dos_c_era_ed
+#define C_ERA_ST       _dos_c_era_st
+#define C_FNKMOD       _dos_c_fnkmod
+#define C_INS          _dos_c_ins
+#define C_LEFT         _dos_c_left
+#define C_LOCATE       _dos_c_locate
+#define C_PRINT                _dos_c_print
+#define C_PUTC         _dos_c_putc
+#define C_RIGHT                _dos_c_right
+#define C_UP           _dos_c_up
+#define C_UP_S         _dos_c_up_s
+#define C_WIDTH                _dos_c_width
+#define C_WINDOW       _dos_c_window
+#define DELETE         _dos_delete
+#define DISKRED                _dos_diskred
+#define DISKRED2       _dos_diskred2
+#define DISKWRT                _dos_diskwrt
+#define DISKWRT2       _dos_diskwrt2
+#define DRVCTRL                _dos_drvctrl
+#define DRVXCHG                _dos_drvxchg
+#define DSKFRE         _dos_dskfre
+#define DUP            _dos_dup
+#define DUP0           _dos_dup0
+#define DUP2           _dos_dup2
+#define ERRABORT       _dos_errabort
+#define EXEC2          _dos_exec2
+#define EXECONLY       _dos_execonly
+#define EXIT           _dos_exit
+#define EXIT2          _dos_exit2
+#define FATCHK         _dos_fatchk
+#define FATCHK2                _dos_fatchk2
+#define FFLUSH         _dos_fflush
+#define FGETC          _dos_fgetc
+#define FGETS          _dos_fgets
+#define FILEDATE       _dos_filedate
+#define FNCKEYGT       _dos_fnckeygt
+#define FNCKEYST       _dos_fnckeyst
+#define FPUTC          _dos_fputc
+#define FPUTS          _dos_fputs
+#define GETASSIGN      _dos_getassign
+#define GETC           _dos_getc
+#define GETCHAR                _dos_getchar
+#define GETDATE                _dos_getdate
+#define GETDPB         _dos_getdpb
+#define GETENV         _dos_getenv
+#define GETFCB         _dos_getfcb
+#define GETS           _dos_gets
+#define GETSS          _dos_getss
+#define GETTIM2                _dos_gettim2
+#define GETTIME                _dos_gettime
+#define GET_FCB_ADR    _dos_getfcb
+#define GET_PR         _dos_get_pr
+#define HENDSPIC       _dos_hendspic
+#define HENDSPIO       _dos_hendspio
+#define HENDSPIP       _dos_hendspip
+#define HENDSPIR       _dos_hendspir
+#define HENDSPMC       _dos_hendspmc
+#define HENDSPMO       _dos_hendspmo
+#define HENDSPMP       _dos_hendspmp
+#define HENDSPMR       _dos_hendspmr
+#define HENDSPSC       _dos_hendspsc
+#define HENDSPSO       _dos_hendspso
+#define HENDSPSP       _dos_hendspsp
+#define HENDSPSR       _dos_hendspsr
+#define INDOSFLG       _dos_indosflg
+#define INKEY          _dos_inkey
+#define INPOUT         _dos_inpout
+#define INTVCG         _dos_intvcg
+#define INTVCS         _dos_intvcs
+#define IOCTRLDVCTL    _dos_ioctrldvctl
+#define IOCTRLDVGT     _dos_ioctrldvgt
+#define IOCTRLFDCTL    _dos_ioctrlfdctl
+#define IOCTRLFDGT     _dos_ioctrlfdgt
+#define IOCTRLGT       _dos_ioctrlgt
+#define IOCTRLIS       _dos_ioctrlis
+#define IOCTRLOS       _dos_ioctrlos
+#define IOCTRLRD       _dos_ioctrlrd
+#define IOCTRLRH       _dos_ioctrlrh
+#define IOCTRLRTSET    _dos_ioctrlrtset
+#define IOCTRLST       _dos_ioctrlst
+#define IOCTRLWD       _dos_ioctrlwd
+#define IOCTRLWH       _dos_ioctrlwh
+#define KEEPPR         _dos_keeppr
+#define KEYSNS         _dos_keysns
+#define KFLUSHGC       _dos_kflushgc
+#define KFLUSHGP       _dos_kflushgp
+#define KFLUSHGS       _dos_kflushgs
+#define KFLUSHIN       _dos_kflushin
+#define KFLUSHIO       _dos_kflushio
+#define KILL_PR                _dos_kill_pr
+#define K_INSMOD       _dos_k_insmod
+#define K_KEYBIT       _dos_k_keybit
+#define K_KEYINP       _dos_k_keyinp
+#define K_KEYSNS       _dos_k_keysns
+#define K_SFTSNS       _dos_k_sftsns
+#define LOAD           _dos_load
+#define LOADEXEC       _dos_loadexec
+#define LOADONLY       _dos_loadonly
+#define LOCK           _dos_lock
+#define MAKEASSIGN     _dos_makeassign
+#define MAKETMP                _dos_maketmp
+#define MALLOC         _dos_malloc
+#define MALLOC2                _dos_malloc2
+#define MEMCPY         _dos_memcpy
+#define MFREE          _dos_mfree
+#define MKDIR          _dos_mkdir
+#define MOVE           _dos_move
+#define NAMECK         _dos_nameck
+#define NAMESTS                _dos_namests
+#define NEWFILE                _dos_newfile
+#define OPEN           _dos_open
+#define OPEN_PR                _dos_open_pr
+#define PATHCHK                _dos_pathchk
+#define PRINT          _dos_print
+#define PRNOUT         _dos_prnout
+#define PRNSNS         _dos_prnsns
+#define PUTCHAR                _dos_putchar
+#define RASSIGN                _dos_rassign
+#define READ           _dos_read
+#define RENAME         _dos_rename
+#define RETSHELL       _dos_retshell
+#define RMDIR          _dos_rmdir
+#define SEEK           _dos_seek
+#define SEND_PR                _dos_send_pr
+#define SETBLOCK       _dos_setblock
+#define SETDATE                _dos_setdate
+#define SETENV         _dos_setenv
+#define SETTIM2                _dos_settim2
+#define SETTIME                _dos_settime
+#define SLEEP_PR       _dos_sleep_pr
+#define SUPER          _dos_super
+#define SUPER_JSR      _dos_super_jsr
+#define SUSPEND_PR     _dos_suspend_pr
+#define S_MALLOC       _dos_s_malloc
+#define S_MFREE                _dos_s_mfree
+#define S_PROCESS      _dos_s_process
+#define TIME_PR                _dos_time_pr
+#define UNLOCK         _dos_unlock
+#define VERIFY         _dos_verify
+#define VERIFYG                _dos_verifyg
+#define VERNUM         _dos_vernum
+#define WAIT           _dos_wait
+#define WRITE          _dos_write
+
+#define FILES(a,b,c) _dos_files ((struct _x68_filbuf *) (a), (b), (c))
+#define NFILES(a) _dos_nfiles ((struct _x68_filbuf *) (a))
+
+/* functions */
+
+ dosmode_t _dos_chmod( const char *, dosmode_t );
+ void *_dos_malloc( int );
+ int _dos_c_cls_al( void );
+ int _dos_c_cls_ed( void );
+ int _dos_c_curoff( void );
+ int _dos_c_curon( void );
+ int _dos_c_fnkmod( int );
+ int _dos_c_window( int, int );
+ int _dos_chdir( const char * );
+ int _dos_curdir(int, char * );
+ int _dos_curdrv( void );
+ int _dos_delete( const char *);
+ int _dos_drvctrl( int, int );
+ int _dos_files( struct _x68_filbuf *, const char *, int );
+ int _dos_fnckeygt( int, char * );
+ int _dos_fnckeyst( int, const char * );
+ int _dos_inpout( int );
+ int _dos_nfines( struct _x68_filbuf * ) ;
+ int _dos_rename( const char *, const char * );
+ int _dos_setblock( void *, int );
+ int _dos_super( int );
+
+/* -------------- */
+
+#endif /* _X68_DOSLIB_H_ */
diff --git a/edit.cpp b/edit.cpp
new file mode 100644 (file)
index 0000000..3eca36c
--- /dev/null
+++ b/edit.cpp
@@ -0,0 +1,1888 @@
+/*
+ * STed: edit.c (edit mainroutine)
+ */
+
+#include       "sted.h"
+
+static char    *inmd[6]={
+  "EDIT","EDIT SOUND","EDIT MIDI IN(Mono)","EDIT MIDI IN(Poly)",
+  "EDIT MIDI IN(Step)","EDIT MIDI IN(P/St)"};
+
+/***************************/
+void   trk_ed()
+{
+  int  po,ad,cx,cy,i,j,ke,kc,sh,rc,cs,xx,mdc,mdiv=0,tcp=0,tcs=0;
+  int  r_ad,r_ln;
+  char tmp0[256];
+  int   last_ontime=0; /* Aug.28.1998 Daisuke nagano */
+
+  track1=track;track2=track;
+  midi_clr();;LEDMOD(0,0);LEDMOD(2,0);inmd_disp();home2(512);
+
+track_edit_top:
+  size_max(track);
+
+  trk_cluc();cplen=0;cons_md(1);B_CLR_AL();edfield(1);fnc_dis(0);rc=tm_lag;
+  po=tr_pos[track][edit_scr][0];cx=tr_pos[track][edit_scr][1];cy=tr_pos[track][edit_scr][2];
+  if(real_ad(po,cy)>=tr_len[track]){po=tr_len[track]-4;cy=padjust(&po,18);}else{trk_dis(6,po,24);}
+  gra(po,0);
+
+  while( 1){
+    if((B_SFTSNS()&16)!=0){sttrc(&po,&cy,0);}
+    ad=real_ad(po,cy);
+
+    r_ad=0;r_ln=-1;
+    if(cplen<0){
+      int      p_ad,p_ln;
+      p_ad=cpadd;p_ln=abs(p_ad-ad);if(p_ad>ad){p_ad=ad;}
+
+      if(p_ad<=po){r_ad=0;}else{r_ad=real_cy(po,p_ad);}
+      if(r_ad<24){
+       if(p_ad+p_ln>real_ad(po,23)){
+         r_ln=24-r_ad;
+       }else{
+         r_ln=real_cy(po,p_ad+p_ln)-r_ad;
+       }
+      }
+      if(r_ln>0){rev_area(r_ad,r_ln,edit_scr);}
+    }
+    cs=0;i=trk[track][ad];
+    if(i<253 && i!=0xf6){
+      if(trk[track][ad+1]==0){cs=2;}
+      if(i>127){cs=1;}
+    }
+    if( cx==0 ){xx=0;}else{xx=2;}
+    tcur(cx*6+12+xx,cy+6,8-xx,cs);
+    mdc=0;
+#if 0
+    do{
+      rc++;
+      if( rc==tm_lag ){
+       sh=B_SFTSNS();
+       if((sh&1)!=0){fnc_dis(1);}else{fnc_dis(0);}
+       trk_free(ad);
+       if(grpmode!=0){gra(ad,0);}
+      }
+      mdc=(*rcd->md_get)();
+      if(mdc>=0 && mdc<0xf8){
+       if(thrumode){
+         if(rcd->act){poplay(0,0);}
+         (*rcd->md_put)(mdc);
+       }
+       if(inpmode>1 && (sh&1)==0){
+         if((mdc>=0x90 && mdc<=0x9f)){break;}
+         /*    if(mdc>=0x80 && mdc<0xf8){mdiv=mdc&0xf0;}
+               if((mdc>=0x90 && mdc<=0x9f)||(mdiv==0x90 && mdc<0x80)){break;}*/
+       }
+      }
+      mdc=0;
+    }while(B_KEYSNS()==0);
+#endif
+    key_midi_wait();
+
+#if 0
+       if(grpmode!=0){
+      if ((rc==tm_lag-1)||
+         (((ONTIME()-last_ontime)>tm_lag/100)&&(rc<tm_lag))) {
+       last_ontime=ONTIME();
+       rc=tm_lag;
+       gra(ad,0);
+      }
+    } /* Aug.28.1998 Daisuke nagano */
+#endif
+    rc++;
+//    if( rc==tm_lag ){
+      sh=B_SFTSNS();
+      if((sh&1)!=0){fnc_dis(1);}else{fnc_dis(0);}
+         if (grpmode!=0) {
+                 disable_update_screen();
+             trk_free(ad);
+             gra(ad,0);
+                 update_screen();
+         } else {
+             trk_free(ad);
+         }
+//    }
+    mdc=(*rcd->md_get)();
+    if(mdc>=0 && mdc<0xf8){
+      if(thrumode){
+       if(rcd->act){poplay(0,0);}
+       (*rcd->md_put)(mdc);
+      }
+      if (!((inpmode>1 && (sh&1)==0) &&
+           (mdc>=0x90 && mdc<=0x9f))) {mdc=0;}
+    }
+
+    tcur(cx*6+12+xx,cy+6,8-xx,cs);
+
+    ke=0;kc=0;sh=0;
+    if(B_KEYSNS()!=0){
+      ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
+      if(kc>='a' && kc<='z'){kc-=32;}
+    }
+
+    if(ke>=0x70 && ke<=0x73){rc=tm_lag;}else{rc=0;}
+
+    if( (sh&6)==0 ){tcp=0;tcs=0;}
+
+    if( ke==0x70 ){fnc_dis(1);}
+    if( ke==0xf0 ){fnc_dis(0);}
+    if( ke==0x5a ){
+      if((sh&16)!=0){sttrc(&po,&cy,0);}
+    }
+    if( ke==1 ){
+      if( cplen<0 ){
+       cplen=0;r_ln=0;trk_dis(6,po,24);
+      }else{
+       /*
+         trk_pos_set(po,cx,cy);
+         trksize(track);if(edit_scr==0){track1=track;}else{track2=track;}
+         B_CLR_AL();fnc_dis(-1);msg_clr();edit_scr=0;cons_md(0);
+         edfield(-1);sdis2(30+9,512,"",18,0,0);home2(0);
+         */
+       trk_ed_end(po,cx,cy);
+       break;
+      }
+    }
+
+
+    /*play*/
+    if((sh&4)==0){
+      if(kc=='Z'){timtra();}
+
+      if(kc=='P'||ke==0x56){if( (sh&1)==0 ){poplay(ad,1);}else{poplay(ad,2);}}
+      if(kc=='M'||ke==0x55){
+       if( (sh&2)==0 ){
+         if( (sh&1)==0 ){poplay(ad,3);}else{poplay(ad,4);}
+       }else{poplay(ad,5);}
+      }
+      if(kc=='N' && trk[track][ad]<128){poplay(ad,6);}
+      if( ke==0x57 && (sh&15)==0){rcd->sts=0;}
+      if( ke==0x58 && (sh&15)==0){rcd->sts=1;}
+      if( ke==0x59 && (sh&15)==0){poplay(0,0);}
+    }
+
+    if(r_ln>0){rev_area(r_ad,r_ln,edit_scr);}
+
+    if(((mdc>=0x90 && mdc<=0x9f)/*||(mdiv==0x90 && mdc<0x80)*/)){
+      int      j,i;
+      i=ret_midi(mdc,inpmode,ad,cy);
+      if(i>0){
+       trk_dis(6+cy,ad,24-cy);
+       for(j=0;j<i;j=j+4){cur_down(&po,&cy);}
+      }
+      if(i==-1){ke=0;kc='*';}
+      if(i==-2){ke=0;kc=8;}
+      /*if(trk[track][po]!=0xfd){if(step_cluc(po)>=192){ke='*';}}*/
+    }
+
+    if( ((kc>='A' && kc<='Z')|| kc=='@') && (sh&4)!=0 ){
+      int i=edit_scr,ex;
+      cons_md(0);edit_scr=0;
+
+      if(cnfflag&0x0400){sh=1-(sh&1);}
+
+      if( kc=='@' ){
+       ex=option22(-1,2,ad,i);
+      }else{
+       if(sh&1){ex=option(kc-'A',2);}else{ex=option2(kc-'A',2,ad,i);}
+      }
+
+      edit_scr=i;if(ex){edfield(0);}else{tg_copy2(1-i);}
+      trk_no();trk_dis(6,po,24);rc=tm_lag-1;kc=0;
+    }
+
+    /*         if( (ke>=0x3f && ke<=0x51) && (sh&4)!=0 ){*/
+    if( (ke>=0x40 && ke<=0x51) && (sh&4)!=0 ){
+      int      i,j;
+
+      static char tk[18]={13,14,15,7,8,9,16,4,5,6,17,1,2,3,18,10,11,12};
+
+      /*                       if( ke==0x3f ){j=trk_sel_menu(track)+1;}else*/{j=tk[ke-0x40];}
+
+      if( j>0 && j<=36){
+       trk_pos_set(po,cx,cy);
+       trksize(track);i=meas_no(ad);track=j-1;
+       size_max(track);trk_cluc();trk_no();cplen=0;
+       po=meas_add(i);cy=padjust(&po,8);
+       rc=tm_lag-1;
+      }
+      kc=0;ke=0;
+    }
+
+    if( ke==0x3f ){noed_cls();grpmode=0;}
+
+    if( kc=='X' ){
+      unsigned char    da=trk[track][ad];
+      if(da<128 || (ad>0 && da>=0xfc && trk[track][ad-4]<128)){
+       int     j,i;
+       if(da>=0xfc){cur_up(&po,&cy);ad-=4;}
+
+       tcur(1,cy+6,12,0);i=ret_chord(ad);tcur(1,cy+6,12,0);
+       if(i>0){
+         trk_dis(6+cy,ad,24-cy);
+         for(j=0;j<i;j=j+4){cur_down(&po,&cy);}
+       }
+      }
+    }
+    if( kc=='U' ){
+      int      j,i;
+
+      i=mml_inp(ad);
+      if(i>0){
+       trk_dis(6+cy,ad,24-cy);
+       for(j=0;j<i;j=j+4){cur_down(&po,&cy);}
+      }
+    }
+    if( kc==13 ){
+      ret(ad,cx,cy,0);
+      if( es==0 ){
+       trk_dis(cy+6,ad,24-cy);cx=0;
+       if(inpmode==1){poplay(ad,6);}
+       ke=retkey2(ecode);
+      }else{ke=0x137;}
+    }
+
+    /*0~9*/
+    if( kc>0x2f && kc<0x3a ){
+      int      ct;
+      unsigned char da=trk[track][ad];
+      if( da==0xeb && cx==0){cx=2;}
+
+      if( cx>0 && (da<0xf0 || da==0xf8 || da==0xfc)){
+       if( da==0xee && cx>1 ){
+         cx=3;B_LOCATE(32,cy+6);i=vinput(kc-'0',0x105)+8192;
+         if( es==0 ){
+           trk[track][ad+2]=i&0x7f;trk[track][ad+3]=(i>>7)&0x7f;
+         }
+       }else{
+         if( (da==0xec || da==0xe2) && cx>1 ){
+           int bank;
+           if(da==0xec){cx=2;}
+         timnore:                                      B_LOCATE(16+2*6,cy+6);ct=vinput(kc-'0',0x304+0x400);
+         if((cmdflag&0x20)!=0 && cx==2){ct--;}
+         if(ecode==0x18){
+           cx=2;
+           trk_dis(cy+6,ad,1);
+           cons_md(0);
+           ct=timsel(channel_no(ad),bank_no(ad),0,prog_no(ad));
+           cons_md(1);
+           if(ct<0){kc='0';goto timnore;}
+           bank=(ct&0xff00)>>8;ct=ct&0xff;
+           trk[track][ad+3]=bank;
+         }
+         if(ct<0){ct=0;}
+         if(ct>127){ct=127;}
+         }else{
+           int fl=0x104+0x400;
+           unsigned char       tmp0[16];
+           if( da==0xfc ){cx=1;}
+           if(da>=0xdd && da<=0xdf && cx>1 &&(cmdflag & 0x100)!=0){fl+=0x2000;}
+         resame:
+           B_LOCATE(15+cx*6,cy+6);
+           if(da==0xe6 && cx==2){
+             tmp0[0]=kc;tmp0[1]=0;
+             sinput((char *)tmp0,fl);
+             ct=strch(trk[track][ad+2],(char *)tmp0);
+           }else{ct=vinput(kc-'0',fl);}
+
+           msg_clr();
+           if( ((cx==0||cx==3)&& da<128)||(da>=0x80 && da<=0xef && da!=0xe7 && cx>1) ){
+             if(ct>127){ct=127;}
+             if(ct<0){ct=0;}
+           }
+           if( es==0 && da==0xfc ){
+             if(ct>1024||ct<1|| ct>=meas_no(ad) ||\
+                trk[track][meas_add(ct)]==0xfc ){
+               msg(_("Invalid measure number."));
+               goto resame;
+             }else{
+               ct--;
+               trk[track][ad+2]=ct>>8;
+               ct=ct&0xff;
+             }
+           }
+         }
+         if( es==0 ){trk[track][ad+cx]=ct;}
+       }
+       if( es==0 ){
+         ke=retkey(ecode);
+       }
+       trk_cluc();trk_dis(cy+6,ad,24-cy);kc=0;
+      }
+      if( cx==0 && da<128 ){
+       int     ct;
+       char    tmp0[16];
+
+       tmp0[0]=kc;tmp0[1]=0;
+       B_LOCATE(12,cy+6);sinput(tmp0,0x504);
+       if(trrhy[track]&0x80){ct=0;}else{ct=scale_no(ad);}
+       ct=ctc(da,tmp0,ct);
+       if( es==0 && ct>=0){
+         trk[track][ad]=ct;
+         ke=retkey(ecode);
+       }
+       trk_dis(cy+6,ad,1);
+      }
+      if( da>=0xfd ){
+       ret(ad,cx,cy,kc);kc=0;cx=0;
+       if( es==0 ){
+         trk_dis(cy+6,ad,24-cy);
+         if(inpmode==1){poplay(ad,6);}
+         ke=retkey2(ecode);
+       }else{ke=0x137;}
+      }
+    }
+
+    if( ke>0x62 && ke<0x6d ){
+      if( (sh & 4)!=0 ){
+       if( trk[track][ad]<128 ){
+         ed_ch_stgt(ad,cx,cy,ke,sh);
+         /*trk_dis(y+6,ad,24-cy);*/
+         trk_dis(6,po,24);
+
+         while(ad<tr_len[track]-4){
+           cur_down(&po,&cy);ad=real_ad(po,cy);
+           if(trk[track][ad]<128 &&
+              trk[track][ad+cx]>0){break;}
+         }
+       }
+       ke=0;kc=0;snsclr();
+      }
+    }
+
+    if(kc>='A' && kc<='G'){
+      unsigned char da=trk[track][ad];
+      tmp0[0]=kc;tmp0[1]=0;
+      if( da<128 ){
+       int     ct;
+       B_LOCATE(12,cy+6);sinput(tmp0,0x504);
+       if(trrhy[track]&0x80){ct=0;}else{ct=scale_no(ad);}
+       ct=ctc(da,tmp0,ct);
+       cx=0;
+       if( es==0 && ct>=0 ){
+         trk[track][ad]=ct;
+         ke=retkey(ecode);
+       }
+      }
+      if( da>0xfb ){
+       ret(ad,cx,cy,kc);kc=0;cx=0;
+       if( es==0 ){
+         trk_dis(cy+6,ad,24-cy);
+         if(inpmode==1){poplay(ad,7);}
+         ke=retkey2(ecode);
+       }else{ke=0x137;}
+      }
+      if( da==0xee ){
+       int     ct;
+       B_LOCATE(32,cy+6);sinput(tmp0,0x504);
+       ct=bendc2(ad,tmp0)+8192;
+       if( es==0 ){
+         trk[track][ad+2]=ct&0x7f;
+         trk[track][ad+3]=(ct>>7)&0x7f;
+         ke=retkey(ecode);
+       }
+      }
+      if( da==0xe6 && kc<='B'){
+       int     ct;
+       B_LOCATE(cx*6+14,cy+6);sinput(tmp0,0x504);
+       ct=strch(trk[track][ad+2],tmp0);
+
+       if( es==0 ){
+         trk[track][ad+2]=ct;
+         ke=retkey(ecode);
+       }
+      }
+      if(da>=0xdd && da<=0xdf && cx>1 &&(cmdflag & 0x100)!=0){
+       int     ct;
+       B_LOCATE(cx*6+14,cy+6);ct=vinput(kc-'A'+10,0x2304);
+       if( es==0 ){
+         trk[track][cx]=ct&0x7f;
+         ke=retkey(ecode);
+       }
+      }
+      trk_dis(cy+6,ad,1);
+    }
+
+    if( kc=='@'|| kc=='`' ){
+      int      i;
+      i=comment_inp(ad,cy,sh);
+      if(i!=0){ke=0x3e;kc=0;}
+      trk_dis(6+cy,ad,24-cy);msg_clr();
+    }
+
+    ad=real_ad(po,cy);
+
+    if( kc=='+' || kc=='.' || kc=='>' ){
+      val_add(ad,cx,kc);trk_dis(6+cy,ad,24-cy);snsclr();
+    }
+    if( kc=='-' || kc==',' || kc=='<' ){
+      val_sub(ad,cx,kc);trk_dis(cy+6,ad,24-cy);snsclr();
+    }
+    if( kc=='=' ){
+      val_rev(ad,cx);trk_dis(cy+6,ad,1);
+    }
+    if( ke==0x0d ){
+      int      j,ct;
+      if( (sh&3)==0 ){
+       if(trk_check(4)==0){
+         if((ad>0 && trk[track][ad-4]<0xfc)&& trk[track][ad]!=0xfc){
+           same_shift(ad,0,2);}else{same_shift(ad,0,1);}
+
+         line_ins(po,cy);trk[track][ad]=0xfc;trk_cluc();
+         trk_dis(cy+6,ad,24-cy);
+         msg("SAME MEAS");
+       resame2:
+         B_LOCATE(22,cy+6);j=vinput(0,3)-1;
+         trk[track][ad+1]=j&0xff;trk[track][ad+2]=j>>8;
+         msg_clr();
+         if( es==0 ){
+           if( j<0 || j>1023 || (j+1)>=meas_no(ad) ||
+               meas_add(j+1)>=65536-44 ){
+             msg(_("Invalid measure number."));
+             goto resame2;
+           }
+         }
+         if( es==0 ){
+           trk_dis(cy+6,ad,1);ke=0x3e;
+         }else{ke=0x137;}
+       }
+      }else{
+       int j=meas_no(ad),j2=sttm_no(ad);ct=0;
+       if( (sh&1)!=0 ){
+         ct=same_meas_conv(track);
+       }else{
+         if(cplen<0){
+           cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+           ct=same_meas_extr(track,cpadd,cplen);
+         }else{
+           ct=same_meas_extr(track,0,tr_len[track]-4);
+         }
+       }
+       if(ct==0){
+         trk_cluc();po=sttm_ad(meas_add(j),j2);cy=padjust(&po,cy);
+         rc=tm_lag-1;
+       }
+      }
+    }
+
+    if( trk_check(4)==0){
+      if( ke==0x6c ){
+       unsigned char   da=trk[track][ad];
+       if( da<0xfe && da!=0xf7 ){
+         if( da==0xf6 || da==0x98 ){
+           int cc=0,ad2=ad;
+           while(cc<4096){
+             dat[cc++]=trk[track][ad2++];
+             dat[cc++]=trk[track][ad2++];
+             dat[cc++]=trk[track][ad2++];
+             dat[cc++]=trk[track][ad2++];
+             if(trk[track][ad2]!=0xf7){break;}
+           }
+           if(trk_check(cc)==0){
+             int       i;
+             trk_shift(ad,cc);
+             for(i=0;i<cc;i++){trk[track][i+ad]=dat[i];}
+             trk_cluc();trk_dis(6,po,24);
+             ke=0x3e;snsclr();
+           }
+         }else{
+           if(da>=0xfc){same_shift(ad,0,1);}
+           line_ins(po,cy);
+           trk_cluc();trk_dis(cy+6,ad,24-cy);
+           ke=0x3e;snsclr();
+         }
+       }
+      }
+      if( kc=='/' ){
+       spcon(ad,cy);msg_clr();
+       if( es==0 ){
+         trk_cluc();trk_dis(cy+6,ad,24-cy);ke=0x3e;
+       }else{ke=0x137;}
+      }
+      if( kc=='?' ){
+       int i=edit_scr;
+       B_CLR_AL();cons_md(0);edit_scr=0;
+       if(trk[track][ad]>=0x90 && trk[track][ad]<=0x97){
+         user_exc_as(trk[track][ad]-0x90);}else{user_exc_as(0);}
+       edit_scr=i;edfield(0);
+       trk_no();trk_dis(6,po,24);rc=tm_lag-1;
+      }
+      if( ke==0x34 ){
+       if(trk[track][ad]!=0x98 || (sh&1)!=0){
+         line_ins(po,cy);
+         trk[track][ad]=0x98;trk[track][ad+1]=0;
+         trk[track][ad+2]=0;trk[track][ad+3]=0;
+         exc_edit(ad,cy,sh);
+         if(trk[track][ad+4]!=0xf7){ke=0x137;}
+       }else{
+         exc_edit(ad,cy,sh);
+       }
+      }
+      if (kc=='\\' && trk[track][ad]==0x98) {
+       exc_edit(ad,cy,sh);
+      }
+
+
+      if( kc=='*' ){
+       if(!((ad>0 && trk[track][ad-4]<0xfc)&&\
+            trk[track][ad]==0xfc)){same_shift(ad,0,1);}
+       line_ins(po,cy);trk[track][ad]=0xfd;
+       trk_cluc();trk_dis(cy+6,ad,24-cy);ke=0x3e;
+      }
+      if( kc=='[' ){
+       line_ins_aft(ad);
+       line_ins(po,cy);trk[track][ad]=0xf9;
+       trk_dis(cy+6,ad,24-cy);ke=0x3e;
+      }
+      if( kc==']' ){
+       line_ins_aft(ad);
+       line_ins(po,cy);trk[track][ad]=0xf8;
+       trk_dis(cy+6,ad,1);
+       B_LOCATE(22,cy+6);trk[track][ad+1]=vinput(0,3);
+       if( es==0 ){trk_dis(cy+6,ad,24-cy);ke=0x3e;}else{ke=0x137;}
+      }
+      if( kc=='K' ){
+       int     ct,ca=trk[track][ad];
+       msg("Music Key");
+       if(ca!=0xf5){
+         line_ins_aft(ad);
+         line_ins(po,cy);
+         trk[track][ad]=0xf5;trk[track][ad+1]=bkey;
+         trk_dis(cy+6,ad,1);
+       }
+       ct=scale_sel(22,cy+6,trk[track][ad+1]);
+       if(ct>=0){
+         trk[track][ad+1]=ct;
+         ke=0x3e;
+       }else{
+         ke=0;if(ca!=0xf5){ke=0x137;}
+       }
+       trk_dis(cy+6,ad,24-cy);
+       msg_clr();
+      }
+    }
+
+    if((ke==0x0f || kc==8)&& ad>0){cur_up(&po,&cy);ad=real_ad(po,cy);ke=0x37;}
+    if(ke==0x37 || ke==0x137 || kc==25){
+      if( tr_len[track]>ad+4 && trk[track][ad]!=0xf7){
+       unsigned char   da=trk[track][ad-4],db,dc;
+       int     i,ll=4;
+       while(trk[track][ad+ll]==0xf7){ll=ll+4;}
+       db=trk[track][ad+ll];dc=trk[track][ad];
+
+       if(ke!=0x137){
+         if(ll>1020){ll=1020;}
+         for(i=0 ; i<ll ;i++){lcbuf[i]=trk[track][ad+i];}
+         lcbuf[1024]=(ll>>2)-1;
+       }
+
+       if(dc==0xfc||\
+          (dc==0xfd && (ad==0 || !(da<0xfc && db==0xfc)))||\
+          (dc<0xfc &&(ad==0||da>=0xfc)&& db==0xfc)){
+
+         if(lcbuf[0]==0xfc &&(ad>0 && da<0xfc)&& db<0xfc){
+           same_shift(ad,1,2);}else{same_shift(ad,1,1);}
+       }
+       line_del(po,cy);snsclr();
+      }
+    }
+
+    if((ke==0x3a || kc==12) && ((lcbuf[0]!=0xf6 && lcbuf[0]!=0x98 && trk_check(4)==0)||trk_check(40)==0)){
+      if( lcbuf[0]<254 ){
+       unsigned char   da=trk[track][ad-4],db=trk[track][ad];
+       int     i,ll=(lcbuf[1024]+1)*4;
+
+       if(lcbuf[0]==0xfc||\
+          (lcbuf[0]==0xfd && (ad==0 || !(da<0xfc && db==0xfc)))||\
+          (lcbuf[0]<0xfc && (ad==0||da>=0xfc)&& db==0xfc)){
+         if(lcbuf[0]==0xfc &&(ad>0 && da<0xfc)&& db<0xfc){
+           same_shift(ad,0,2);}else{same_shift(ad,0,1);}
+       }
+       trk_shift(ad,ll);
+       for(i=0;i<ll;i++){trk[track][ad+i]=lcbuf[i];}
+       trk_cluc();trk_dis(cy+6,ad,24-cy);
+       snsclr();
+      }
+    }
+
+    if( ke==0x10 ){
+      if( (sh&3)==0 ){
+       msg("JUMP MEAS=");j=vinput(0,4);
+       if( es==0 && j>0 ){
+         po=meas_add(j);cy=padjust(&po,8);
+       }
+       msg_clr();rc=tm_lag-1;
+      }else{
+       if( (sh&1)!=0 ){
+         int es;
+         trksize(track);cons_md(0);es=tagj(&po,0);cons_md(1);
+         if(es==0){
+           trk_no();trk_cluc();size_max(track);
+           cplen=0;cy=padjust(&po,8);
+         }
+       }else{
+         cons_md(0);tagj(&ad,1);cons_md(1);
+       }
+      }
+    }
+    if( kc==20 ){
+      int      i,j;
+    jmptrk:
+      msg("JUMP TRACK=");j=vinput(0,2/*+0x200*/);
+
+      msg_clr();
+
+      /*if(ecode==0x18){
+       j=trk_sel_menu(track)+1;if(j==0){goto jmptrk;}
+       }*/
+
+      if( es==0 && j>0 && j<=36){
+       trk_pos_set(po,cx,cy);
+       trksize(track);i=meas_no(ad);track=j-1;
+       size_max(track);trk_cluc();trk_no();cplen=0;
+       po=meas_add(i);cy=padjust(&po,8);
+      }
+      msg_clr();rc=tm_lag-1;
+    }
+
+
+    /*cursor*/
+    /*if( (ke==0x3b || ke==0x3d) && (sh&6)!=0 ){*/ /* Aug.28.1998 Daisuke Nagano */
+    if( (ke==0x3b || ke==0x3d) && (sh&7)!=0 ){
+      trk_pos_set(po,cx,cy);
+      trksize(track);
+
+      /*if( (sh&6)==2){*/ /* Aug.28.1998 Daisuke Nagano */
+      if( (sh&7)==2){
+       int     i,j;
+       if(tcp==0){i=meas_no(ad);tcp=i;j=sttm_no(ad);tcs=j;}else{i=tcp;j=tcs;}
+       if( ke==0x3b){trk_next(0);}else{trk_next(1);}
+       po=meas_add(i);if(po<0){po=tr_len[track]-4;}
+       po=sttm_ad(po,j);
+      }else{
+       int     i,j;
+       if(tcp==0){i=meas_no(ad);tcp=i;j=step_no(ad);tcs=j;}else{i=tcp;j=tcs;}
+       if( ke==0x3b){trk_next(0);}else{trk_next(1);}
+       po=meas_add(i);if(po<0){po=tr_len[track]-4;}
+       po=step_ad(po,j);
+      }
+      size_max(track);
+      trk_no();trk_cluc();cplen=0;cy=padjust(&po,cy);ke=0;
+      snsclr();rc=tm_lag-1;
+    }
+
+
+    if( ke==0x3c && (sh&4)!=0 ){roll_up(&po,&cy);ke=0;}
+    if( ke==0x3e && (sh&4)!=0 ){roll_down(&po,&cy);ke=0;}
+
+    if( kc==0x13 || ke==0x3b){cx--;if( cx<0 ){cx=3;ke=0x3c;}}
+    if( kc==0x04 || ke==0x3d || kc==' '){cx++;if( cx>3 ){cx=0;ke=0x3e;}}
+    if( kc==0x05 || ke==0x3c){cur_up(&po,&cy);}
+    if( kc==0x18 || ke==0x3e){cur_down(&po,&cy);}
+
+    /*roll*/
+    if( ke==0x39 || kc==0x12){
+      if( sh&4 ){
+       int     i;
+       i=meas_no(ad)-1;
+       if( i>0 ){po=meas_add(i);cy=padjust(&po,8);}
+       snsclr();
+      }else{
+       if((sh&1)==0){
+         if( po>0 ){
+           po=real_po(po,24);if( po<0 ){po=0;cy=0;}
+           trk_dis(6,po,24);snsclr();
+         }else{cy=0;}
+       }else{roll_up(&po,&cy);}
+      }
+    }
+    if( ke==0x38 || kc==0x03){
+      if( sh&4 ){
+       int     i;
+       i=meas_no(ad);i=meas_add(i+1);
+       if( i>=0 ){po=i;cy=padjust(&po,8);}
+       snsclr();
+      }else{
+       if((sh&1)==0){
+         if( po<tr_len[track] ){
+           if( real_ad(po,24)>=tr_len[track] ){
+             cy=real_cy(po,tr_len[track]-4);
+           }else{
+             po=real_ad(po,24);
+             if(real_ad(po,24)>=tr_len[track] ){
+               po=tr_len[track]-4;cy=padjust(&po,23);
+             }
+           }
+           trk_dis(6,po,24);snsclr();
+         }
+       }else{roll_down(&po,&cy);}
+      }
+    }
+
+
+    if( kc==0x17 ){roll_up(&po,&cy);kc=0;ke=0;}
+    if( kc==0x1a ){roll_down(&po,&cy);kc=0;ke=0;}
+
+    if( ke==0x36 ){
+      if((sh&1)==0){cx=0;cy=0;}else{sttrc(&po,&cy,1);}
+    }
+
+    ad=real_ad(po,cy);
+    /*f1*/
+    if( ke==0x63 ){
+      if((sh&1)==0){
+       po=0;cy=0;cx=0;
+      }else{
+       note_ctrl(ad,0);trk_cluc();
+       rc=tm_lag-1;
+      }
+      trk_dis(6,po,24);
+
+    }
+    if( ke==0x64 ){
+      if( (sh&1)==0 ){
+       if( po+4<tr_len[track] ){
+         po=tr_len[track]-4;cy=padjust(&po,20);
+       }
+      }else{
+       int j=meas_no(ad),j2=sttm_no(ad);
+       undobuf(0);
+       if(cplen<0){
+         cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+         trk_opt_sub(track,cpadd,cplen);
+       }else{
+         trk_opt_sub(track,ad,tr_len[track]-ad-4);
+       }
+       trk_cluc();po=sttm_ad(meas_add(j),j2);cy=padjust(&po,cy);
+       rc=tm_lag-1;
+      }
+    }
+    if( ke==0x65 ){
+      if(cnfflag&0x01000){es=0;goto replinp2;}
+    replinp:
+      if((sh&1)==0){msg("REPLACE=");sinput(repl,0x200+30+0x10000);
+      }else{msg("DELETE=");sinput(delt,0x200+30+0x10000);}
+      msg_clr();
+
+      if(ecode==0x18){
+       int ct;
+      replinp2:
+       if((sh&1)==0){
+         ct=repl_select(0);if(ct>=0){strcpy(repl,repl_d[ct&127]);}
+       }else{
+         ct=repl_select(1);if(ct>=0){strcpy(delt,repl_d[ct&127]);}
+       }
+       if((ct&128)==0||ct==-1){goto replinp;}
+       if(ct==-2){es=1;}
+      }
+      if( es==0 ){
+       if(cplen<0){
+         cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+         replace(cpadd,cplen,sh&1,0);
+       }else{
+         replace(ad,tr_len[track]-ad-4,sh&1,0);
+       }
+       if(ad>tr_len[track]-4){po=tr_len[track]-4;cy=0;}
+       trk_cluc();trk_dis(6,po,24);
+      }
+    }
+    if( ke==0x66 ){
+      if(cnfflag&0x01000){es=0;goto findinp2;}
+    findinp:
+      msg("FIND=");sinput(srch,0x200+30+0x10000);msg_clr();
+
+      if(ecode==0x18){
+       int ct;
+      findinp2:
+       ct=repl_select(2);if(ct>=0){strcpy(srch,repl_d[ct&127]);}
+       if((ct&128)==0||ct==-1){goto findinp;}
+       if(ct==-2){es=1;}
+      }
+      if(es==0){ke=0x67;kc=0;}
+    }
+    if( ke==0x67 ){
+      int      j;
+      j=find(ad,sh);
+      if(j>=0){
+       if(j<po || j>real_ad(po,23)){
+         po=real_po(j,13);cy=13;if( po<0 ){po=0;cy=0;}
+         trk_dis(6,po,24);
+       }else{cy=real_cy(po,j);}
+      }
+    }
+    /*f6*/
+    if( ke==0x68 || ke==0x69 ){
+      if( (sh&1)!=0){
+       if( ke==0x68 ){
+         undobuf(0);
+         msg(_("Set undo buffer"));
+       }else{
+         undobuf(1);
+         if(real_ad(po,cy)>=tr_len[track]){
+           po=tr_len[track]-4;cy=padjust(&po,18);
+         }
+         trk_dis(6,po,24);
+       }
+       ke=0;
+      }
+    }
+
+    if( ke==0x68 ){
+      if( cplen<0 ){
+       cplen=0;trk_dis(6,po,24);
+      }else{
+       cpadd=ad;cplen=-1;cpcy=cy;
+       trk_dis(cy+6,ad,1);
+      }
+    }
+
+    if( ke==0x6a ){
+      if( (sh&1)!=0){
+       if( cpleng>0 ){
+         undobuf(0);
+         if(trk_check(cpleng)==0){
+           int ec;
+
+           cpbuf[cpleng]=0xfe;
+           ec=trk_mix_sub(trk[track]+ad,cpbuf);
+           if(!size_change(track,ad+ec)){
+             dat[ec]=0xfe;ec+=4;
+             memcpy_l(&trk[track][ad],dat,ec);
+             tr_len[track]=ad+ec;
+             trk_cluc();trk_dis(6,po,24);
+           }
+         }
+       }
+       ke=0;
+      }
+    }
+
+    if( ke==0x69 || ke==0x6a ){
+      if( cplen<0 && cpadd!=ad){
+       cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;cpcy=cy;}
+       cpleng=cpybuf_set(track,cpadd,cplen);
+       if(cpbuf[cpleng-4]==254){cpleng-=4;cplen-=4;}
+
+       if(ke==0x69&& cplen>0){
+         undobuf(0);
+         same_shift(cpadd,1,buf_meas(cpbuf,cpleng));
+
+         if(cpadd>0 && trk[track][cpadd-4]<0xfc && trk[track][cpadd]==0xfc){
+           trk[track][cpadd]=0xfd;cpadd+=4;cplen-=4;}
+
+         trk_delete(cpadd,cplen);
+         trk_cluc();po=cpadd;cy=padjust(&po,cpcy);
+       }else{
+         trk_dis(6,po,24);
+       }
+      }
+    }
+    if( ke==0x6b ){
+      if( cpleng>0 ){
+       undobuf(0);
+       if(trk_check(cpleng)==0){
+         int   i;
+         same_shift(ad,0,buf_meas(cpbuf,cpleng));
+         trk_shift(ad,cpleng);
+         for(i=0;i<cpleng;i++){trk[track][i+ad]=cpbuf[i];}
+         if( (sh&1)!=0){dat_rev(track,ad,cpleng);}
+         trk_cluc();trk_dis(6,po,24);
+       }
+      }
+    }
+    if( kc=='R' ){
+      if( replicate(ad,sh)==0 ){trk_cluc();trk_dis(6,po,24);}
+    }
+    if( kc=='T' ){
+      if( replicate2(ad,sh)==0 ){trk_cluc();trk_dis(6,po,24);}
+    }
+
+    if( kc==14 ){
+      int      i;
+      i=meas_no(ad);i=meas_add(i+1);
+      if( i>=0 ){po=i;cy=padjust(&po,8);}
+      snsclr();
+    }
+    if( kc==2 ){
+      int      i;
+      i=meas_no(ad)-1;
+      if( i>0 ){po=meas_add(i);cy=padjust(&po,8);}
+      snsclr();
+    }
+    if( kc=='\\' || kc=='|' ){
+      if( ad<(tr_len[track]-4) ){
+       bendc(ad,sh);trk_dis(6,po,24);
+      }
+    }
+    if( kc=='Q' ){
+      if(cplen<0){
+       cplen=abs(cpadd-ad);if(cpadd>ad){cpadd=ad;}
+       trk_quan(track,cpadd,cpadd+cplen);
+      }else{
+       trk_quan(track,ad,tr_len[track]-4);
+      }
+      trk_cluc();trk_dis(6,po,24);
+    }
+    if( ke==0x52 || ke==0x53){
+      if( trrhy[track]&0x80 ){
+       trk_pos_set(po,cx,cy);
+       B_CLR_AL();cons_md(0);rtrk_ed(ke-0x52,sh);
+       edfield(0);po=tr_pos[track][edit_scr][0];cx=0;cy=0;trk_no();
+       trk_cluc();trk_dis(6,po,24);rc=tm_lag-1;
+      }
+    }
+
+    if( kc==':' ){
+      inpmode++;if(inpmode>5){inpmode=0;}
+      inmd_disp();midi_clr();mdiv=0;
+    }
+
+    if( ke==0x54 ){
+      fnc_dis(-1);cons_md(0);B_CLR_AL();help(1);
+      edfield(0);B_CLR_AL();fnc_dis(0);trk_dis(6,po,24);rc=tm_lag-1;
+    }
+    if( kc=='I' ){
+      if(grpmode!=0){noed_cls();grpmode=0;}
+      dat_info(ad,sh);
+    }
+    if( edit_scr==0){
+      if(kc==7){
+       grpmode++;if(grpmode>4){grpmode=0;}
+       noed_cls();if(grpmode!=0){rc=tm_lag;gra(ad,0);}
+      }
+    }
+
+    if( kc=='L' ){
+      if( (sh&1)==0 ){
+       partf(0,ad);trk_dis(6,po,24);
+      }else{
+       trk_pos_set(po,cx,cy);
+       B_CLR_AL();cons_md(0);load_sub(0);goto track_edit_top;
+      }
+    }
+    if( kc=='S' ){
+      if( (sh&1)==0 ){
+       partf(1,ad);trk_dis(6,po,24);
+      }else{
+       trk_pos_set(po,cx,cy);
+       B_CLR_AL();cons_md(0);save_sub(0);goto track_edit_top;
+      }
+    }
+    if( kc=='O' ){partf(2,ad);trk_dis(6,po,24);}
+
+    if( kc=='V' ){
+      if(cplen<0){
+       cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+       po=vis_edit(cpadd,cplen,sh);
+      }else{
+       po=vis_edit(ad,0,sh);
+      }
+      trk_cluc();cy=padjust(&po,8);
+      rc=tm_lag-1;
+    }
+
+    if( kc=='W' ){
+      trk_pos_set(po,cx,cy);
+      trksize(track);tg_copy(edit_scr);B_CLR_AL();
+      if(grpmode!=0){noed_cls();grpmode=0;}
+      if(sh&1){track1=track;track2=track;}
+      if(edit_scr==0){
+       track1=track;track=track2;edit_scr=1;
+      }else{
+       track2=track;track=track1;edit_scr=0;
+      }
+      if(sh&1){trk_pos_set(po,cx,cy);}
+      goto track_edit_top;
+    }
+    if( (kc==0x17 || kc==0x16) && trk[track][ad]==0xfc ){
+      int      nn,pp,ln;
+
+      nn=(trk[track][ad+2]&3)*256+trk[track][ad+1]+1;
+      pp=meas_add(nn);
+      if(pp>=0){
+       if(grpmode!=0){noed_cls();grpmode=0;}
+
+       edit_scr=1-edit_scr;trk_cluc();cons_md(1);
+       edfield(1);
+
+       sdis(edit_scr*56+1,556," --- SAME MEAS VIEW ---",38,15,14);
+       /*
+         char tmp[64];
+         strcpy(tmp," --- SAME MEAS VIEW --- [");
+         strcat(tmp,fstr(nn,4));strcat(tmp," ]");
+         sdis(edit_scr*56+1,556,tmp,38,15,14);
+         */
+       ln=meas_len(pp)>>2;
+       if(ln<24){trk_dis(6+((23-ln)>>1),pp,ln);}else{trk_dis(6,pp,24);}
+
+       tg_copy(edit_scr);
+       edit_scr=1-edit_scr;trk_cluc();cons_md(1);
+
+       B_CLR_AL();
+       trk_dis(6,po,24);
+      }
+    }
+    if( kc=='}' ){
+      cons_md(0);stgt_as();cons_md(1);
+    }
+    if( kc=='{' ){
+      B_CLR_AL();cons_md(0);part_as();
+      edfield(0);trk_no();trk_dis(6,po,24);rc=tm_lag-1;
+    }
+    if( ke==0x29 && (sh&2)==2){
+      int      j;
+      j=find_rep(ad);
+      if(j>=0){
+       if(j<po || j>real_ad(po,23)){
+         po=real_po(j,13);cy=13;if( po<0 ){po=0;cy=0;}
+         trk_dis(6,po,24);
+       }else{cy=real_cy(po,j);}
+      }
+    }
+  }
+}
+
+/***************************/
+void trk_ed_end(int po,int cx,int cy)
+{
+  trk_pos_set(po,cx,cy);
+  trksize(track);if(edit_scr==0){track1=track;}else{track2=track;}
+  B_CLR_AL();fnc_dis(-1);msg_clr();edit_scr=0;cons_md(0);
+  edfield(-1);sdis2(30+9,512,"",18,0,0);home2(0);
+}
+
+void trk_pos_set(int po,int cx,int cy)
+{
+  tr_pos[track][edit_scr][0]=po;
+  tr_pos[track][edit_scr][1]=cx;tr_pos[track][edit_scr][2]=cy;
+}
+
+/***************************/
+void   val_add(int ad,int cx,int kc)
+{
+  int  i;
+  unsigned char da=trk[track][ad];
+
+  if(da<128 ){
+    i=trk[track][ad+cx];
+    if((cx==0 || cx==3)){
+      if( kc=='>' ){if(cx==0){i+=12;}else{i+=10;}}else{i++;}
+      i=i&127;
+    }else{
+      if( kc=='>' ){i+=12;}else{i++;}
+      i=i&255;
+    }
+    trk[track][ad+cx]=i;
+  }else{
+    if( (da<0xf0 || da==0xf8 || da==0xf5) && cx>0){
+      if( cx>1 && da==0xee ){
+       i=trk[track][ad+2]+trk[track][ad+3]*128;
+       if( kc=='>' ){i+=10;}else{i+=1;}
+       trk[track][ad+2]=i&0x7f;trk[track][ad+3]=(i>>7)&0x7f;
+      }else{
+       if( cx>1 && (da==0xec)){cx=2;}
+       if( cx>0 && (da==0xf5)){cx=1;}
+       if( cx>1 && (da==0xe6)){cx=2;}
+       i=trk[track][ad+cx];
+       if( kc=='>' ){if(cx==1){i+=12;}else{i+=10;}}else{i+=1;}
+       if(cx>1 && da>=0x80 && da<0xf0 && da!=0xe7){i=i&127;}
+       if(cx>0 && da==0xf5){i=i&31;}
+       if(cx>1 && da==0xe6){if(i>32){i=0;}}
+
+       trk[track][ad+cx]=i;
+      }
+    }
+    if(cx==0){
+      if( da>=0x90 && da<=0x97 ){
+       trk[track][ad]=((da+1)&7)+0x90;
+      }
+      if( da==0xeb ){
+       trk[track][ad+2]=(trk[track][ad+2]+1)&127;
+      }
+    }
+
+    if( cx>0 ){
+      if(da==0xfc ){
+       int ct=(trk[track][ad+2]&3)*256+trk[track][ad+1];
+       ct++;
+       if(ct<1024 && ct>=0 && ct+1<meas_no(ad)){
+         trk[track][ad+2]=ct>>8;trk[track][ad+1]=ct&0xff;
+       }
+      }
+    }
+  }
+  trk_cluc();
+}
+
+void   val_sub(int ad,int cx,int kc)
+{
+  int  i;
+  unsigned char da=trk[track][ad];
+
+  if( da<128 ){
+    i=trk[track][ad+cx];
+    if((cx==0 || cx==3)){
+      if( kc=='<' ){if(cx==0){i+=116;}else{i+=118;}}else{i+=127;}
+      i=i&127;
+    }else{
+      if( kc=='<' ){i+=244;}else{i+=255;}
+      i=i&255;
+    }
+    trk[track][ad+cx]=i;
+  }else{
+    if( (da<0xf0 || da==0xf8 || da==0xf5) && cx>0){
+      if( cx>1 && da==0xee ){
+       i=trk[track][ad+2]+trk[track][ad+3]*128;
+       if( kc=='<' ){i-=10;}else{i-=1;}
+       trk[track][ad+2]=i&0x7f;trk[track][ad+3]=(i>>7)&0x7f;
+      }else{
+       if( cx>1 && (da==0xec)){cx=2;}
+       if( cx>0 && (da==0xf5)){cx=1;}
+       if( cx>1 && (da==0xe6)){cx=2;}
+       i=trk[track][ad+cx];
+       if( kc=='<' ){if(cx==1){i+=244;}else{i+=246;}}else{i+=255;}
+       if(cx>1 && da>=0x80 && da<0xf0 && da!=0xe7){i=i&127;}
+       if(cx>0 && da==0xf5){i=i&31;}
+       if(cx>1 && da==0xe6){if(i>32){i=32;}}
+
+       trk[track][ad+cx]=i;
+      }
+    }
+    if(cx==0){
+      if( da>=0x90 && da<=0x97 ){
+       trk[track][ad]=((da+7)&7)+0x90;
+      }
+      if( da==0xeb ){
+       trk[track][ad+2]=(trk[track][ad+2]+127)&127;
+      }
+    }
+    if( cx>0 ){
+      if(da==0xfc ){
+       int ct=(trk[track][ad+2]&3)*256+trk[track][ad+1];
+       ct--;
+       if(ct<1024 && ct>=0 &&  ct+1<meas_no(ad)){
+         trk[track][ad+2]=ct>>8;trk[track][ad+1]=ct&0xff;
+       }
+      }
+    }
+  }
+  trk_cluc();
+}
+
+void   val_rev(int ad,int cx)
+{
+  if( cx>1 && trk[track][ad]==0xee ){
+    int        i;
+    i=16384-(trk[track][ad+2]+trk[track][ad+3]*128);
+    trk[track][ad+2]=i&0x7f;trk[track][ad+3]=(i>>7)&0x7f;
+  }
+  if( cx>0 && trk[track][ad]==0xf5 ){
+    int        i;
+    i=trk[track][ad+1];
+    trk[track][ad+1]=i^16;
+  }
+  if( cx==2 && trk[track][ad]==0xe6 ){
+    int        i;
+    i=trk[track][ad+2];
+    if(i>0){
+      if( i>16){i=i-16;}else{i=i+16;}
+    }
+    trk[track][ad+2]=i;
+  }
+  if( cx==3 && trk[track][ad]==0xeb && trk[track][ad+2]==10 ){
+    int        i;
+    i=128-trk[track][ad+3];
+    if(i<0){i=0;}
+    if(i>127){i=127;}
+    trk[track][ad+3]=i;
+  }
+}
+
+/***************************/
+void   ed_ch_stgt(int ad,int cx,int cy,int ke,int sh)
+{
+  int nn=(ke-0x63);
+
+  if(cnfflag&0x2000){sh=1-(sh&1);}
+
+  if( cx<2 ){
+    trk[track][ad+1]=stgt_tbl[nn];
+    trk[track][ad+2]=stgt_tbl[nn+10];
+  }else{
+    if( cx==2 ){
+      trk[track][ad+2]=stgt_tbl[nn+10];
+    }else{
+      trk[track][ad+3]=stgt_tbl[nn+20];
+    }
+  }
+
+  if(sh&1){
+    int ad2=ad;
+    while(ad2>0 && trk[track][ad2-4]<128 && trk[track][ad2-3]==0 &&
+         trk[track][ad2-2]!=0 && trk[track][ad2-1]!=0 ){
+      ad2-=4;
+
+      if( cx<2 ){
+       trk[track][ad2+2]=stgt_tbl[nn+10];
+      }else{
+       if( cx==2 ){
+         trk[track][ad2+2]=stgt_tbl[nn+10];
+       }else{
+         trk[track][ad2+3]=stgt_tbl[nn+20];
+       }
+      }
+
+    }
+  }
+
+  trk_dis(cy+6,ad,24-cy);
+  /*
+    while(ad<tr_len[track]-4){
+    cur_down(&po,&cy);ad=real_ad(po,cy);
+    if(trk[track][ad]<128 &&
+    trk[track][ad+cx]>0){break;}
+    }
+    */
+}
+
+/***************************/
+int    retkey(int ecode)
+{
+  int  ke;
+
+  ke=0x3d;                     /*右*/
+  if( ecode==13 ){ke=0x3e;}    /*下*/
+  if( ecode==0x13 ){ke=0x3b;}  /*左*/
+  if( ecode==0x18 ){ke=0x3e;}  /*下*/
+  if( ecode==0x05 ){ke=0x3c;}  /*上*/
+
+  return ke;
+}
+
+int    retkey2(int ecode)
+{
+  int  ke;
+  ke=0x3e;                     /*下*/
+  if( ecode==0x13 ){ke=0x3b;}  /*左*/
+  if( ecode==0x05 ){ke=0x3c;}  /*上*/
+
+  return ke;
+}
+
+/***************************/
+void   inmd_disp()
+{
+  sdis2(30+9,512,inmd[inpmode],18,15,8);
+}
+
+/***************************/
+void   cur_up(int *po,int *cy)
+{
+  if( *cy>0 ){
+    *cy=*cy-1;
+  }else{
+    if( *po>3 ){
+      TXRASCPY((28*4+3)*256+(29*4+3),24*4,3+0x8000);
+    loop:                      *po=*po-4;
+    if(trk[track][*po]==0xf7){goto loop;}
+    trk_dis(6,*po,1);
+    }
+  }
+}
+
+void   cur_down(int *po,int *cy)
+{
+  if( *cy<23 && tr_len[track]>real_ad(*po,*cy+1) ){
+    *cy=*cy+1;
+  }else{
+    if( real_ad(*po,24)<tr_len[track] ){
+      TXRASCPY((7*4)*256+(6*4),24*4,3);
+      *po=real_ad(*po,1);trk_dis(29,real_ad(*po,23),1);
+    }
+  }
+}
+
+/***************************/
+void   roll_up(int *po,int *cy)
+{
+cur_up_loop:
+  if( *po>3 ){
+    TXRASCPY((28*4+3)*256+(29*4+3),24*4,3+0x8000);
+  loop:                *po=*po-4;if( trk[track][*po]==0xf7){goto loop;}
+
+  trk_dis(6,*po,1);
+  if( *cy<23 && tr_len[track]>real_ad(*po,*cy+1) ){*cy=*cy+1;}
+  }
+
+  if( BITSNS(7)&2 || BITSNS(7)&16 ){goto cur_up_loop;}
+  snsclr();
+}
+
+void   roll_down(int *po,int *cy)
+{
+cur_down_loop:
+  if( real_ad(*po,24)<tr_len[track] ){
+    TXRASCPY((7*4)*256+(6*4),24*4,3);
+  loop:                *po=*po+4;if( trk[track][*po]==0xf7){goto loop;}
+
+  trk_dis(29,real_ad(*po,23),1);
+  if( *cy>0 ){*cy=*cy-1;}
+  }
+
+  if( BITSNS(7)&1 || BITSNS(7)&64 ){goto cur_down_loop;}
+  snsclr();
+}
+
+/***************************/
+void   line_del(int po,int cy)
+{
+  int  a,ad=real_ad(po,cy),co=4;
+  a=trk[track][ad];
+
+  if((a==0xf6 || a==0x98)){
+    while(trk[track][ad+co]==0xf7){co+=4;}
+  }
+  trk_delete(ad,co);
+  trk_cluc();trk_dis(cy+6,ad,24-cy);
+}
+
+void   line_ins(int po,int cy)
+{
+  trk_shift(real_ad(po,cy),4);
+  TXRASCPY(28*1024+3*256+29*4+3,(24-cy)*4,3+0x8000);
+  TXRASCPY(63*1024+(6+cy)*4,4,3);
+}
+
+void   line_ins_aft(int ad)
+{
+  if( (ad>0 && trk[track][ad-4]>=0xfc) && trk[track][ad]==0xfc){same_shift(ad,0,1);}
+}
+
+/***************************/
+void   ret(int ad,int cx,int cy,int kc)
+{
+  int  i,j,ct,ct2;
+  char tmp0[256],tmp1[256];
+
+  if(trk_check(4)!=0){return;}
+
+  line_ins_aft(ad);
+  line_ins(real_po(ad,cy),cy);
+  trk[track][ad]=60;trk[track][ad+1]=48;trk[track][ad+2]=46;trk[track][ad+3]=64;
+
+  if( ad>0 ){
+    j=ad-4;
+    while( trk[track][j]>127 && j>=0){j=j-4;}
+    if( j>=0 ){for(i=0 ;i<=3;i++){trk[track][ad+i]=trk[track][j+i];}}
+  }
+
+ret1:
+  while(1){
+    ct=trk[track][ad];
+    strcpy(tmp0,keystr2(ct,scale_no(ad)));
+
+    strcpy(tmp1,keystr(ct));
+    if( scale_no(ad)!=0 && tmp1[1]==32 ){tmp0[1]='n';}/**/
+
+    if( ct>127 ){tmp0[0]=0;}
+
+    B_LOCATE(12,cy+6);
+    if(kc>0){
+      tmp0[0]=kc;tmp0[1]=0;sinput(tmp0,0x504);
+    }else{
+      sinput(tmp0,0x904);
+    }
+
+    if(trrhy[track]&0x80){ct=0;}else{ct=scale_no(ad);}
+    ct=ctc(trk[track][ad],tmp0,ct);
+    if( ct>=0 ){trk[track][ad]=ct;trk_dis(cy+6,ad,1);break;}
+    if( es!=0 ){break;}
+    if(ecode==0x18||ecode==0x05){return;}
+  }
+  if( ecode==0x13){return;}
+  if( trk[track][ad]>127 ){es=1;}
+ret2:
+  if( es==0 && ecode!=13 ){
+    fnc_dis(2);ct=trk[track][ad+1];
+    B_LOCATE(22,cy+6);trk[track][ad+1]=vinput(ct,0x904);
+    fnc_dis(0);
+    if(ecode==0x13){ecode=0;goto ret1;}
+    if(ecode==0x18||ecode==0x05){return;}
+  }
+  if( es==0 && ecode!=13 ){
+    if( ct==trk[track][ad+1]){
+      ct2=trk[track][ad+2];
+    }else{
+      ct2=trk[track][ad+1]-1;if(ct2<1){ct=0;}
+    }
+  ret3:
+    B_LOCATE(28,cy+6);trk[track][ad+2]=vinput(ct2,0x904);
+    if(ecode==0x13){ecode=0;goto ret2;}
+    if(ecode==0x18||ecode==0x05){return;}
+  }
+  if( es==0 && ecode!=13 ){
+    fnc_dis(8);
+    B_LOCATE(34,cy+6);ct=vinput(trk[track][ad+3],0x903);
+    fnc_dis(0);
+    if(ct<0){ct=0;}
+    if(ct>127){ct=127;}
+    trk[track][ad+3]=ct;
+    if(ecode==0x13){ecode=0;ct2=trk[track][ad+2];goto ret3;}
+  }
+}
+
+/***************************/
+int    comment_inp(int ad,int cy,int sh)
+{
+  int  i,len,po;
+  char tmp0[64];
+
+  msg("Comment");
+  if(trk[track][ad]!=0xf6 ||(sh&1)!=0){
+    if(trk_check(40)!=0){return(0);}
+    line_ins(real_po(ad,cy),cy);
+    tmp0[0]=0;B_LOCATE(15,cy+6);sinput(tmp0,20);
+    if(es!=0){line_del(real_po(ad,cy),cy);return(0);}
+
+    line_ins_aft(ad);
+    trk_shift(ad,40-4);len=20;
+  }else{
+    len=0;po=ad;
+    tmp0[len++]=trk[track][po+2];tmp0[len++]=trk[track][po+3];
+
+    while(trk[track][po+4]==0xf7){
+      po+=4;tmp0[len++]=trk[track][po+2];tmp0[len++]=trk[track][po+3];
+    }
+    tmp0[len]=0;spcut(tmp0);
+
+    if(len<=20){
+      B_LOCATE(15,cy+6);sinput(tmp0,20);
+    }else{
+      B_LOCATE(7,1);sinput(tmp0,len);msg_clr();
+    }
+    if(es!=0){return(0);}
+  }
+  strcpy(tmp0,spadd(tmp0,len));
+  for(i=0;i<len;i+=2){
+    po=ad+i*2;
+    trk[track][po]=0xf7;trk[track][po+1]=0;
+    trk[track][po+2]=tmp0[i];trk[track][po+3]=tmp0[i+1];
+  }
+  trk[track][ad]=0xf6;return(4);
+}
+
+/***************************/
+void   spcon(int ad,int cy)
+{
+  int  i,ct,ctl;
+  char tmp0[256];
+
+  line_ins_aft(ad);
+  line_ins(real_po(ad,cy),cy);
+  for(i=0;i<=3;i++){trk[track][ad+i]=0;}
+  msg("Special Controler");
+
+  if( (cmdflag&0x4)==0){
+  spc_spcsym:  tmp0[0]=0;B_LOCATE(15,cy+6);sinput(tmp0,0x305);
+
+  if( ecode==0x18){
+  spc_spcsel:          B_LOCATE(12,cy+6);B_PRINT("Special Controler");
+  ct=spc_select();tmp0[0]=ct&0xff;tmp0[1]=ct>>8;tmp0[2]=0;
+  B_LOCATE(12,cy+6);B_PRINT("                 ");
+  if(ct==0){goto spc_spcsym;}
+  }
+  }else{
+    goto spc_spcsel;
+  }
+
+  ct=spc_code(tmp0,&ctl);if(ct==0){es=1;return;}else{es=0;}
+  if( ct==0xe2||ct==0xec){trk[track][ad+2]=prog_no(ad-4);
+  if(ctl>0 && (cmdflag&0x20)!=0){ctl--;}
+  }
+  if( ctl>127 ){ctl=127;}
+
+  if( ct==0xeb ){trk[track][ad+2]=128;}
+  if( ctl>=0   ){trk[track][ad+2]=ctl;}
+  if( ct==0xee ){trk[track][ad+2]=0;trk[track][ad+3]=64;}
+  if( ct==0xe6 ){trk[track][ad+2]=channel_no(ad);}
+
+  trk[track][ad]=ct;trk_cluc();trk_dis(cy+6,ad,1);
+  if( es==0 ){
+    int        i;
+    B_LOCATE(22,cy+6);i=vinput(trk[track][ad+1],0x904);
+    if( i<0 ){i=0;}
+    if( i>255){i=255;}
+    trk[track][ad+1]=i;
+  }
+  if( es==0 ){
+    if( ct==0xee ){
+      int      i;
+      tmp0[0]=0;B_LOCATE(32,cy+6);sinput(tmp0,0x905);
+      i=bendc2(ad,tmp0)+8192;
+      trk[track][ad+2]=i&0x7f;trk[track][ad+3]=(i>>7)&0x7f;
+    }
+
+    if( (ct==0xec || ct==0xe2)&& ctl<0 ){
+      int      i;
+      if( (cmdflag&0x1000)!=0 ){
+      spc_timno:
+       i=trk[track][ad+2];
+       if((cmdflag&0x20)!=0){i++;}
+       B_LOCATE(28,cy+6);i=vinput(i,0xb03);
+       if((cmdflag&0x20)!=0){i--;}
+       if(i<0){i=0;}
+       if(i>127){i=127;}
+
+       if(ecode==0x18){
+         trk_dis(cy+6,ad,1);
+       spc_timsl:                              cons_md(0);
+       i=timsel(channel_no(ad),bank_no(ad),0,prog_no(ad));
+       cons_md(1);
+       if(i>=0){
+         trk[track][ad+2]=i&0xff;trk[track][ad+3]=i>>8;
+         return;}
+       if(i<0){goto spc_timno;}
+       }
+      }else{goto spc_timsl;}
+      trk[track][ad+2]=i;
+    }
+
+    if( ct!=0xee && ct!=0xec && ct!=0xe2 && ctl<0 ){
+      int      i;
+      char     tmp0[64];
+
+      if(ct>=0xdd && ct<=0xdf &&(cmdflag & 0x100)!=0){
+       B_LOCATE(28,cy+6);i=vinput(trk[track][ad+2],0x2904);
+      }else{
+       b_striS(tmp0,64,trk[track][ad+2]&127);
+       B_LOCATE(28,cy+6);sinput(tmp0,0x904);
+       if(ct==0xe6){i=strch(trk[track][ad+2],tmp0);}else{i=str_val(tmp0);}
+      }
+
+      if( ct!=0xe7 ){
+       if( i<0 ){i=0;}
+       if( i>127 ){i=127;}
+      }else{
+       if( i<=0 ){i=1;}
+       if( i>255 ){i=255;}
+      }
+
+      trk[track][ad+2]=i;
+    }
+  }
+  if( es==0 ){
+    if( ct!=0xee && ct!=0xed && ct!=0xec && ct!=0xe6  ){
+      int      i,fl=0x904;
+
+      if(ct>=0xdd && ct<=0xdf && (cmdflag & 0x100)!=0){fl+=0x2000;}
+
+      B_LOCATE(33,cy+6);i=vinput(trk[track][ad+3],fl);
+      if( i<0 ){i=0;}
+      if( ct!=0xe7 ){
+       if( i>127 ){i=127;}
+      }else{
+       if( i>255 ){i=255;}
+      }
+      trk[track][ad+3]=i;
+    }
+  }
+}
+
+/***************************/
+char   *trk_dis(int y,int ad,int line)
+{
+  static char  tmp0[64],tmp1[64];
+  int  i,po,cc=0,x,a,b,c,d,capi,skey;
+  int  meas=0,meas2=0,step=0,sta;
+  unsigned char        *bp=trk[track];
+
+  sta=SUPER(0);
+  x=edit_scr*56+1;po=ad;
+  skey=scale_no(ad);
+
+  if(line==1){
+    if(po==0 || bp[po-4]>=0xfc || bp[po]==0xfc){goto clpo;}
+    if(!(bp[po]<0xf0 &&(po==0||bp[po-4+1]!=0||bp[po-4]>=0xf0))){goto trpo;}
+  }
+clpo:
+  if(y>=0){
+    while(po>0){
+      unsigned char    e;
+      po=po-4;e=bp[po];
+      if(meas2==0){
+       if(e<0xf0 &&(po==0||bp[po-4+1]!=0||bp[po-4]>=0xf0)){
+         if(bp[po-4]==0xf7){
+           while(bp[po-4]==0xf7){po-=4;}
+           if(bp[po-4]==0x98 && bp[po-4+1]==0){goto next1;}
+         }
+         step++;
+       }
+      }
+    next1:
+      if( e==0xfd ){
+       meas=bp[po+2]*256+bp[po+3];break;
+      }else{
+       if( e>=0xfc || bp[po+4]==0xfc){meas2++;}
+      }
+    }
+    meas+=meas2;step++;meas++;po=ad;
+  }
+trpo:
+  cons_md(0);
+  while(line!=0){
+    cc=0;
+  redis:
+    if( po>=tr_len[track] ){tmp0[0]=0;tmp1[0]=0;goto brank;}
+    a=bp[po];b=bp[po+1];c=bp[po+2];d=bp[po+3];
+    if(a==0xf7){po+=4;goto redis;}
+    if( a!=0xfe ){
+      if(po==0 || bp[po-4]>=0xfc || bp[po]==0xfc){
+       strcpy(tmp1,fstr(meas,5));
+      }else{
+       strcpy(tmp1,"     ");
+      }
+      if(a<0xf0 &&(po==0||bp[po-4+1]!=0||bp[po-4]>=0xf0)){
+       if(bp[po-4]==0xf7){
+         int   pp=po-4;
+         while(bp[pp]==0xf7){pp-=4;}
+         if(bp[pp]==0x98 && bp[pp+1]==0){goto next2;}
+       }
+       strcat(tmp1,fstr(step,5));strcat(tmp1,":");step++;
+      }else{
+      next2:
+       strcat(tmp1,"     :");
+      }
+    }else{
+      strcpy(tmp1,"            ");
+    }
+
+    if( a<128 ){
+      if(c!=0 && d!=0){
+       if(y<=0){
+         strcpy(tmp0,keystr(a));
+       }else{
+         strcpy(tmp0,keystr1(a,skey));
+       }
+      }else{
+       strcpy(tmp0,"   ");
+      }
+      strcat(tmp0,fstr(a,4));strcat(tmp0,fstr(b,6));
+      strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+      if(b>0 && c>b){tmp0[19]='*';}
+      if(b==0 && c>0){
+       int     i0=po;
+       while(i0<tr_len[track]-8){
+         i0=i0+4;
+         if(bp[i0]<0xf7){
+           int e=bp[i0+1];
+           if(e>0){
+             if(c>e){tmp0[19]='*';}
+             break;
+           }
+         }
+       }
+      }
+      if(b==0){cc=2;}
+    }else{
+      switch( a){
+      case  0x90:
+      case  0x91:
+      case  0x92:
+      case  0x93:
+      case  0x94:
+      case  0x95:
+      case  0x96:
+      case  0x97:
+       strcpy(tmp0,"UserExc ");tmp0[7]=a-0x90+'0';
+       strcat(tmp0,fstr(b,5));
+       strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+       break;
+
+      case  0x98:
+       strcpy(tmp0,"Tr.Exclu");
+       strcat(tmp0,fstr(b,5));
+       strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+
+       while(bp[po+4]==0xf7){po+=4;}
+       break;
+
+      case  0xdd:
+       strcpy(tmp0,"Rol.Base");
+       /*strcat(tmp0,fstr(b,5));
+         strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));*/
+       break;
+
+      case  0xde:
+       strcpy(tmp0,"Rol.Para");
+       /*strcat(tmp0,fstr(b,5));
+         strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));*/
+       break;
+
+      case  0xdf:
+       strcpy(tmp0,"Rol.Dev#");
+       /*strcat(tmp0,fstr(b,5));
+         strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));*/
+       break;
+
+      case  0xe6:
+       strcpy(tmp0,"MIDI CH.");strcat(tmp0,fstr(b,5));
+       strcat(tmp0,"   ");strcat(tmp0,chstr(c));
+       break;
+
+      case  0xe7:
+       strcpy(tmp0,"TEMPO");strcat(tmp0,fstr(b,8));
+       strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+       break;
+
+      case  0xea:
+       strcpy(tmp0,"AFTER C.");strcat(tmp0,fstr(b,5));
+       strcat(tmp0,fstr(c,6));
+       break;
+
+      case  0xeb:
+       strcpy(tmp0,ctrl_type(c));
+       strcat(tmp0,fstr(b,5));strcat(tmp0,fstr(c&127,6));
+       strcat(tmp0,fstr(d,6));
+       break;
+
+      case  0xe2:
+       capi=channel_no(po);
+       strcpy(tmp0,"BankProg");
+       /*                                      d|=(bank_no(po)&0xff00);
+                                               1997-10-10      trk.edでのbankprgの表示がbank lsbに対応して
+                                               なかったのを修正した
+                                               */
+       if(b==0){
+         strcat(tmp0,prog_name(capi,d,c,3));b=1;
+       }else{
+         strcat(tmp0,fstr(b,5));
+         strcat(tmp0,prog_name(capi,d,c,2));
+       }
+       break;
+      case  0xec:
+       capi=bank_no(po);
+       strcpy(tmp0,"PROGRAM ");
+
+       if(b==0){
+         strcat(tmp0,prog_name(d,capi,c,1));b=1;
+       }else{
+         strcat(tmp0,fstr(b,5));
+         strcat(tmp0,prog_name(d,capi,c,0));
+       }
+       break;
+
+      case  0xed:
+       strcpy(tmp0,"AFTER K.");strcat(tmp0,fstr(b,5));
+       strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+       break;
+
+      case  0xee:
+       strcpy(tmp0,"PITCH");strcat(tmp0,fstr(b,8));
+       strcat(tmp0,fstr((c+d*128)-8192,12));
+       break;
+
+      case  0xc0:strcpy(tmp0,"DX7FUNC");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc1:strcpy(tmp0,"DX.PARA");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc2:strcpy(tmp0,"DX.PREF");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc3:strcpy(tmp0,"TX.FUNC");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+
+      case  0xc5:strcpy(tmp0,"FB-01 P");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc6:strcpy(tmp0,"FB-01 S");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc7:strcpy(tmp0,"TX81Z V");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc8:strcpy(tmp0,"TX81Z A");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xc9:strcpy(tmp0,"TX81Z P");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xca:strcpy(tmp0,"TX81Z S");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xcb:strcpy(tmp0,"TX81Z E");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xcc:strcpy(tmp0,"DX7-2 R");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xcd:strcpy(tmp0,"DX7-2 A");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xce:strcpy(tmp0,"DX7-2 P");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xcf:strcpy(tmp0,"TX802 P");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xdc:strcpy(tmp0,"MKS-7  ");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));break;
+      case  0xe5:strcpy(tmp0,"KeyScan");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));break;
+       /*                              case  0xef:strcpy(tmp0,"CMU-800");strcat(tmp0,fstr(b,6));strcat(tmp0,fstr(c,6));break;*/
+
+      case  0xf5:strcpy(tmp0,"Music Key ");strcat(tmp0,scale_str(b));skey=b;b=1;break;
+
+      case  0xf6:
+       strcpy(tmp0," [                      ]");
+       i=3;
+       while(i<25){
+         unsigned char a;
+         a=bp[po+2];if(a==0){a=32;}tmp0[i++]=a;
+         a=bp[po+3];if(a==0){a=32;}tmp0[i++]=a;
+         if(bp[po+4]!=0xf7){break;}
+         po+=4;
+       }
+       /*strncpy(tmp0,(const char *)eucconv(tmp0),26); /* code converted! */
+       strncpy(tmp0,tmp0,26);
+       b=1;break;
+
+      case  0xf8:
+       strcpy(tmp0,"      ]");if(b==0){b=256;}
+       strcat(tmp0,fstr(b,6));break;
+
+      case  0xf9:strcpy(tmp0,"Repeat[");break;
+
+      case  0xfc:
+       strcpy(tmp0,"=========");
+       strcat(tmp0,fstr(((c&3)*256+b)+1,4));
+       strcat(tmp0," ===========");
+       b=1;break;
+
+      case  0xfd:
+       strcpy(tmp0,"--------");
+       strcat(tmp0,fstr(step_cluc(po),5));
+       strcat(tmp0," -----------");
+       b=1;break;
+
+      case  0xfe:
+       strcpy(tmp0,"      [End of Track]");
+       break;
+      default:
+       strcpy(tmp0,fstr(a,7));strcat(tmp0,fstr(b,6));
+       strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+       break;
+       /* UNKNOWN SEQUENCE */
+      }
+
+      if(a>=0xdd && a<=0xdf){
+       strcat(tmp0,fstr(b,5));
+       if((cmdflag & 0x100)!=0){
+         strcat(tmp0,"   ");strcat(tmp0,hex_s(c,2));
+         strcat(tmp0,"H   ");strcat(tmp0,hex_s(d,2));
+         strcat(tmp0,"H");
+       }else{
+         strcat(tmp0,fstr(c,6));strcat(tmp0,fstr(d,6));
+       }
+      }
+
+      if( a<253 && a!=0xf6 ){cc=1;}
+    }
+    if(a>=0xfc || bp[po+4]==0xfc){meas++;step=1;}
+    if( a<252 && b==0 ){tmp0[10]=32;tmp0[11]=32;tmp0[12]=32;}
+  brank:
+    if(y<=0){break;}
+
+    B_LOCATE(x,y);
+    /*
+    if(cc==0){strcat(tmp1,tmp0);H_PRINT(tmp1,"","");
+    }else{if(cc==1){H_PRINT(tmp1,"",tmp0);}else{H_PRINT(tmp1,tmp0,"");}}
+    */
+    if(cc==0){strcat(tmp1,tmp0);H_PRINT(eucconv(tmp1),"","");
+    }else{if(cc==1){H_PRINT(tmp1,"",tmp0);}else{H_PRINT(tmp1,tmp0,"");}}
+    /* code converted! Sep.12.1998 Daisuke Nagano */
+
+    if( line<0 ||(cplen<0 && cpadd==po) ){
+      if( line<0 ){line=-line;}
+      tcur(1,y,11,0);tcur(12,y,26,cc);
+    }
+    po=po+4;line--;y++;
+  }
+  cons_md(1);
+  if(y<=0){strcat(tmp1,tmp0);}
+  SUPER(sta);
+  return(tmp1);
+}
+
+/***************************/
diff --git a/edits.cpp b/edits.cpp
new file mode 100644 (file)
index 0000000..7c9d6b6
--- /dev/null
+++ b/edits.cpp
@@ -0,0 +1,2056 @@
+/*
+* STed: edits.c (edit subroutine)
+*/
+
+#include       "sted.h"
+
+static int     undof[4];
+
+
+
+/***************************/
+/*
+*      =0 stop
+*      =1 all track point play
+*      =2 all track point play(manual)
+*      =3 single track meas play
+*      =4 single track point play
+*      =5 single track point play(manual)
+*      =6 sound edit one note
+*      =7 sound edit one chord
+*      =8 tr.exclu
+*/
+
+void   poplay(int po,int md)
+{
+  int  a1,a2;
+
+  trk_cluc();
+
+  if(md==2 || md==5){
+    int        j;
+    msg("START MEAS=");j=vinput(0,4);msg_clr();
+    if(es!=0 || j<1){return;}
+    po=meas_add(j);if( po<0 ){return;}
+  }
+
+  switch(md){
+  case 0:all_note_off(2);break;
+
+  case 1:
+  case 2:cntplay(track,po);break;
+
+  case 3:a1=po;while(a1>0 && trk[track][a1-4]<0xfc){a1=a1-4;}
+         a2=po;
+         while(a2<tr_len[track]-4){
+           a2=a2+4;if( trk[track][a2]==0xfc ){a2=a2+4;break;}
+           if( trk[track][a2]>0xfb ){break;}
+         }
+         cdplay(track,a1,a2-a1,0);break;
+
+  case 4:
+  case 5:a1=po;while(a1>0 && trk[track][a1-4]<0xfc){a1=a1-4;}
+         a2=tr_len[track]-4;cdplay(track,a1,a2-a1,0);break;
+
+  case 6:cdplay(track,po,4,0);break;
+
+  case 7:a1=po;
+    while(a1>0 && trk[track][a1-4]<=127 && trk[track][a1-3]==0){a1=a1-4;}
+    cdplay(track,a1,(po-a1)+4,0);break;
+
+  case 8:a1=po;
+    if(trk[track][po]==0x98){
+      while(trk[track][a1+4]==0xf7){a1=a1+4;}
+      cdplay(track,po,(a1-po)+4,1);break;
+    }
+  }
+  snsclr();
+}
+
+/***************************/
+void   partf(int a,int ad)
+{
+  char path2[128],tmp0[256];
+  int  ex;
+  int  e=edit_scr;
+
+  cons_md(0);edit_scr=0;
+
+  if( a==0 ){
+    strcpy(path2,prt_path);fsel(prt_file,path2,0x006+e*0x200);
+    if( es==0 && prt_file[0]!=0 ){
+      strcpy(tmp0,path2);strcat(tmp0,prt_file);
+      msg(_("Loading part data."));
+      ex=part_load(tmp0);
+      if(ex>0){
+        if(trk_check(ex)==0){
+          int  i;
+          same_shift(ad,0,buf_meas(dat,ex));
+          trk_shift(ad,ex);part_load(tmp0);
+          for(i=0;i<ex;i++){trk[track][i+ad]=dat[i];}
+          if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+          msg_clr();
+        }
+      }
+    }
+  }else{
+    if( cplen<0 && cpadd!=ad){
+      if(a==1){
+        strcpy(path2,prt_path);fsel(prt_file,path2,0x106+e*0x200);
+        if( es==0 && prt_file[0]!=0 ){
+          strcpy(tmp0,path2);strcat(tmp0,prt_file);
+          dclr();
+          cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+          ex=same_ext_sub(track,cpadd,cpadd+cplen,0);
+
+          msg(_("Saving part data."));
+          if(part_save(tmp0,ex)==0){
+            if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+            msg_clr();}
+        }
+      }else{
+        char   part_file[128];
+        part_file[0]=0;
+
+        strcpy(path2,rcp_path);fsel(part_file,path2,0x107+e*0x200);
+        if( part_file[0]!=0 && str_search(part_file,".")==0 ){
+          strmfe(part_file,part_file,"TXT");}
+        if( es==0 && part_file[0]!=0 ){
+          strcpy(tmp0,path2);strcat(tmp0,part_file);
+          cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+
+          msg(_("Saving in text format."));
+          if(part_text_save(tmp0,cpadd,cplen)==0){msg_clr();}
+        }
+      }
+    }
+  }
+  edit_scr=e;
+  trk_cluc();
+  fnc_dis(0);cons_md(1);
+}
+
+/***************************/
+void   sttrc(int *po,int *cy,int flg)
+{
+  int  ad,rad,i,j,ii,jj,jjj=-1,skf,ofs,nn,md=8;
+  int  me_ad[2048];
+  int  max;
+  int  lpad[18],lprt[18];
+  unsigned char lpco[18];
+  unsigned char        *ptr;
+
+  ptr=(unsigned char *)trk[track];
+  max=add_set(track,me_ad);
+
+  skf=poft>>16;ofs=poft&0xffff;
+  while( ( (B_SFTSNS()&16)!=0 || flg!=0 ) && rcd->active[track] && rcd->act!=0){
+    key_midi_player_wait();
+    if(B_KEYSNS()!=0){
+      int      k=B_KEYINP() >> 8,sh=B_SFTSNS();
+      if(k==1){break;}
+      if((sh&15)==0){
+        if(k==0x57){rcd->sts=0;}
+        if(k==0x58){rcd->sts=1;}
+        if(k==0x59){all_note_off(2);break;}
+      }
+      if( k==0x3b || k==0x3d){
+        int    i;
+        trksize(track);i=meas_no(real_ad(*po,*cy));
+        if( k==0x3b){trk_next(2);}else{trk_next(3);}
+        *po=meas_add(i);if(*po<0){*po=tr_len[track]-4;}
+        trk_no();trk_cluc();cplen=0;*cy=padjust(po,8);
+        size_max(track);
+        ptr=(unsigned char *)trk[track];
+        max=add_set(track,me_ad);
+        snsclr();
+      }
+    }
+
+    ad=meas_add(ofs+1);if(ad<0){break;}
+    nn=0;rad=0;
+
+    STed_MeasureConversion(track);   /* Dec.11.1998 Daisuke Nagano */
+    j=rcd->bar[track];jj=j;i=rcd->step[track];ii=i;
+    if(skf!=0){if(j==0){i=-1;}else{j--;}}
+
+    while(j>0 || i>0){
+      unsigned char    ca;
+loop1:
+      ca=ptr[ad];ad+=4;if(ca==0xf7){goto loop1;}
+      if(ca>0xfd ){ad-=4;break;}
+
+      if((ca>=0xfc || ptr[ad]==0xfc)&& rad!=0){ad=rad;rad=0;
+      if(j>0){j--;if(j==0 && i==0){break;}}
+      goto loop1;
+      }
+
+      if( ca==0xfc ){
+        int    ii0,jj0,ct;
+        jj0=ad-4;
+resame:
+        ct=ptr[jj0+1]+(ptr[jj0+2]&3)*256;ii0=me_ad[ct];
+        if(ct<max && jj0!=ii0){
+          jj0=ii0;if(ptr[ii0]==0xfc){goto resame;}
+          rad=ad;ad=ii0;
+        }
+        goto loop1;
+      }
+
+      if(j>0){
+        if(ca>=0xfc || ptr[ad]==0xfc){
+          j--;if(j==0 && i==0){break;}
+        }
+      }else{
+        if(ca<0xf8){i--;if(i==0){ad-=4;break;}}
+      }
+
+      if(ca==0xf9 && nn<16){
+        nn++;lpad[nn]=ad;lprt[nn]=rad;lpco[nn]=0;
+      }
+      if(ca==0xf8 && nn>0){
+        lpco[nn]+=1;
+        if(lpco[nn]!=ptr[ad+1-4]){ad=lpad[nn];rad=lprt[nn];goto loop1;}
+        nn--;
+      }
+
+    }
+    if(rad!=0){ad=rad-4;}
+
+    if( ad>=*po && ad<real_ad(*po,12+(flg*12)) ){
+      *cy=real_cy(*po,ad);
+    }else{
+      if( ad<*po || ad>real_ad(*po,30) || flg!=0){
+        *cy=0;*po=ad;B_CLR_AL();trk_dis(6,ad,24);
+      }else{
+        *cy=12;
+        while( real_ad(*po,13)<tr_len[track] && real_ad(*po,12)<ad){
+          TXRASCPY((7*4)*256+(6*4),24*4,3);
+loop3:
+          *po=*po+4;
+          if(ptr[*po]==0xf7){goto loop3;}
+          trk_dis(29,real_ad(*po,23),1);
+        }
+      }
+    }
+
+    if(flg==0){
+      int ad2;ad2=real_ad(*po,*cy);
+      trk_dis(6+*cy,ad2,-1);
+
+      if(cy && ptr[ad2]<0xf0){
+        int pp=*po,yy=*cy,ad3;
+        while(yy){yy--;ad3=real_ad(pp,yy);
+        if(ptr[ad3]>=0xf0 || ptr[ad3+1]!=0 ){break;}
+        trk_dis(6+yy,ad3,-1);}
+      }
+
+      if(jj!=jjj){jjj=jj;if(grpmode!=0){gra(ad,md);md|=16;}}
+
+      if(grpmode!=0){gra_c(ad);}
+      while(jj==rcd->bar[track] && (ii==rcd->step[track] ||i<0)){
+        if(B_KEYSNS()!=0){break;}
+        if( !(rcd->active[track]) ){break;}
+        key_midi_player_wait();
+        STed_MeasureConversion(track); /* Dec.11.1998 Daisuke Nagano */
+      }
+      if(grpmode){txerase(392,589-512,767-327,1001-589);}
+      trk_dis(6+*cy,ad2,1);
+
+      if(cy && ptr[ad2]<0xf0){
+        int pp=*po,yy=*cy,ad3;
+        while(yy){yy--;ad3=real_ad(pp,yy);
+        if(ptr[ad3]>=0xf0 || ptr[ad3+1]!=0 ){break;}
+        trk_dis(6+yy,ad3,1);}
+      }
+
+    }
+    flg=0;
+  }
+
+  LEDMOD(0,0);snsclr();
+}
+
+/***************************/
+int    replace(int po,int ln,int sh,int v)
+{
+  int  i,j,cl,ct,ctl,cd,nm,a,b,c,d,ln2;
+  int  trg[8],trg2[8],ftg[8],ftg2[8];
+  double       ml;
+  char rep[8][256];
+  char li[256],li2[256],tmp0[256],tmp1[256];
+  char si,rcvf,addf;
+  unsigned char        *ptr=trk[track];
+
+  if(ln<=0){return 1;}
+
+  if(sh==0){strcpy(li2,repl);}else{if(sh==1){strcpy(li2,delt);}else{strcpy(li2,srch);}}
+
+  while( (i=str_search(li2,"$<")) ){strcpy(&li2[i-1],&li2[i]);}
+top:
+  if((c=str_search(li2,"|"))==0){
+    strcpy(li,li2);li2[0]=0;
+  }else{
+    strcpy(li,li2);li[c-1]=0;strcpy(li2,&li2[c]);
+  }
+
+  /*if(li[0]==0){goto top;}*/
+
+  rcvf=0;addf=0;
+  memcpy_l(dat2,ptr,tr_len[track]);
+
+  for(i=0;i<TRACK_SIZE;i++){dat[i]=0;}
+  for(i=0;i<=7;i++){rep[i][0]=0;trg[i]=0;trg2[i]=0;ftg[i]=-1;ftg2[i]=0;}
+
+
+  strcat(li,",");nm=0;tmp1[0]=0;
+  if(li[0]=='@'){strcpy(li,&li[1]);rcvf=1;}
+  if(li[0]=='%'){strcpy(li,&li[1]);addf=1;}
+  while( nm<4 ){
+    c=str_search(li,",");if( c==0 ){break;}
+    strcpy(tmp0,li);tmp0[c-1]=0;strcpy(li,&li[c]);
+
+    if(tmp0[0]=='/' && nm==0){strcpy(tmp1,tmp0);jstrupr(tmp1);}
+    if(tmp0[0]==':'||tmp0[0]==0){ftg[nm]=-1;}
+
+    d=str_search(tmp0,":");if(d>0){strcpy(rep[nm],&tmp0[d]);tmp0[d-1]=0;}
+
+    if( tmp0[0]=='!'){ftg2[nm]|=1;strcpy(tmp0,&tmp0[1]);}
+    if( tmp0[0]=='&'){ftg2[2]|=2;ftg[2]=99;strcpy(tmp0,&tmp0[1]);}
+    if( tmp0[0]=='+'){ftg2[1]|=4;strcpy(tmp0,&tmp0[1]);}
+    if( tmp0[0]=='-'){ftg2[1]|=8;strcpy(tmp0,&tmp0[1]);}
+
+    if( tmp0[0]!=0){
+      ftg[nm]=0;
+
+      if(str_search(tmp0,">")>0){ftg[nm]=-2;}
+      if(str_search(tmp0,"<")>0){ftg[nm]=-3;}
+      if(str_search(tmp0,"_")>0){
+        int a;
+        ftg[nm]=-7;
+        a=str_search(tmp0,"_");
+        if(a){
+          if(tmp0[a]>31){
+            if(nm>0){
+              trg2[nm]=str_val(&tmp0[a]);
+            }else{
+              trg2[nm]=ctc(256,&tmp0[a],0);
+            }
+          }else{trg2[nm]=9999;}
+
+          tmp0[a-1]=0;
+          if(tmp0[0]>31){
+            if(nm>0){
+              trg[nm]=str_val(tmp0);
+            }else{
+              trg[nm]=ctc(256,tmp0,0);
+            }
+          }else{trg[nm]=-9999;}
+
+          if(trg[nm]>trg2[nm]){
+            int a;
+            a=trg[nm];trg[nm]=trg2[nm];trg2[nm]=a;
+          }
+        }
+        goto skip0;
+      }
+
+      if(nm>0){
+        trg[nm]=str_val(tmp0);
+      }else{
+        if(tmp0[1]=='*'){ftg[nm]=-4;tmp0[1]='0';}
+        if(tmp0[2]=='*'){ftg[nm]=-4;tmp0[2]='0';}
+        trg[nm]=ctc(256,tmp0,0);
+        if(trg[nm]<0){msg(_("Invalid syntax."));return -1;}
+      }
+    }
+skip0:
+    nm++;
+  }
+
+  if(tmp1[0]=='/'){
+    ct=0;ctl=-1;
+    if(tmp1[1]!=0 ){ct=spc_code(&tmp1[1],&ctl);}
+    if(tmp1[1]=='C' && tmp1[2]=='M'){ct=0xf6;}
+
+    if(tmp1[1]=='S'){ftg[0]=-5;ct=0;ctl=-1;goto skip;}
+    if(tmp1[1]=='A' && tmp1[2]=='L' && tmp1[3]=='L'){
+      ct=0;ctl=-1;if(rep[2][0]==0 && rep[3][0]==0){ftg[0]=-6;goto skip;}
+    }
+
+    if(ct==0){msg(_("Invalid syntax."));return -1;}
+    trg[0]=ct;ftg[0]=0;if(ctl>=0){trg[2]=ctl;ftg[2]=0;rep[2][0]=0;}
+
+
+    if(str_search(tmp1,"_")>0 && (ct<0x98 ||ct==0xeb)){
+      int a,nn=0;
+      if(ct==0xeb){nn=2;}
+      ftg[nn]=-7;
+      a=str_search(tmp1,"_");
+      if(a){
+        if(tmp0[a]>31){
+          trg2[nn]=str_val(&tmp0[a]);
+        }else{trg2[nn]=9999;}
+
+        if(ct<0x98){
+          if(trg2[nn]>7){trg2[nn]=7;}
+          trg2[nn]=0x90+trg2[nn];
+          ftg[nn]=-8;
+        }
+        if(ct==0xeb){
+          if(trg2[nn]>127){trg2[nn]=127;}
+          ftg[nn]=-7;
+        }
+        /*
+        if(trg[nn]>trg2[nn]){
+        int a;
+        a=trg[nn];trg[nn]=trg2[nn];trg2[nn]=a;
+        }
+        */
+      }
+    }
+
+
+    if(rep[0][0]=='/' && (ct==0xeb || (ct>127 && ct<0x98)||ct==0xed||ct==0xea)){
+      ct=0;ctl=-1;
+      if(rep[0][1]!=0 ){ct=spc_code(&rep[0][1],&ctl);}
+
+      if((ct>127 && ct<0x98)||ct==0xeb||ct==0xed||ct==0xea){
+        strcpy(rep[0],fstr(ct,3));
+        if(ctl>=0){strcpy(rep[2],fstr(ctl,3));}
+
+        if(trg[0]==0xea && ct!=0xea){
+          strcpy(rep[3],"@1");if(ctl<0){strcpy(rep[2],"0");}}
+
+        if(trg[0]!=0xea && ct==0xea){
+          strcpy(rep[2],"@2");strcpy(rep[3],"0");}
+
+        goto skip2;
+      }else{msg(_("Invalid syntax."));return -1;}
+    }
+skip:
+    rep[0][0]=0;
+  }
+skip2:
+  if(trg[0]==0xec || trg[0]==0xee){
+    if( ftg[2]==-1){
+      trg[2]=trg[3];trg2[2]=trg2[3];
+      ftg[2]=ftg[3];ftg[3]=-1;
+      ftg2[2]=ftg2[3];ftg2[3]=0;
+    }
+    if( rep[2][0]==0){strcpy(rep[2],rep[3]);rep[3][0]=0;}
+    if(trg[0]==0xec ){ftg[3]=-1;ftg2[3]=0;}
+    rep[4][0]=0;
+  }
+
+  if((trg[0]==0xec || trg[0]==0xe2)&& ftg[2]!=-1 && (cmdflag&0x20)!=0){trg[2]--;}
+
+  if(trg[0]>252){msg(_("Invalid syntax."));return -1;}
+  undobuf(0);
+  if(sh==0){msg(_("Replace ..."));}else{if(sh==1){msg(_("Delete ..."));}else{msg(_("Find ..."));}}
+
+  i=po;j=0;ln2=0;
+  while(1){
+    a=ptr[i];
+    if( rep_match(ftg[0],ftg2[0],trg[0],trg2[0],a,0)!=0 ){
+      b=ptr[i+1];c=ptr[i+2];d=ptr[i+3];
+      if(a==0xee){c=d*128+c-8192;d=0;}
+
+      if(trg[0]<128 && trg[1]>0 && a<128 && b==0){
+        int aa=i;
+        while(1){
+          aa+=4;
+          if(ptr[aa]>127){break;}
+          if(ptr[aa+1]>0){b=ptr[aa+1];break;}
+        }
+      }
+
+      if((ftg2[1]&4)!=0){b=chd_check(track,i,0);}
+      if((ftg2[1]&8)!=0){b=chd_check(track,i,1);}
+
+      if( rep_match(ftg[1],ftg2[1],trg[1],trg2[1],b,1)!=0\
+        && rep_match(ftg[2],ftg2[2],trg[2],trg2[2],c,2)!=0\
+        && rep_match(ftg[3],ftg2[3],trg[3],trg2[3],d,3)!=0 ){
+
+          if((ftg2[2]&2)!=0){
+            int mm=tai_check(track,i);
+            if((ftg2[2]&1)==0 && mm==0){goto next;}
+            if((ftg2[2]&1)!=0 && mm==1){goto next;}
+          }
+
+          if(sh==0){
+            for(j=0;j<=3;j++){
+              if(j>0 && rep[j][0]=='@'){
+                cd=0;
+                if(rep[j][1]=='0'){cd=b;}
+                if(rep[j][1]=='1'){cd=c;}
+                if(rep[j][1]=='2'){cd=d;}
+                goto skip3;
+              }
+
+              if(j==1 && trg[0]<128 && trg[1]>0 &&\
+                a<128 && ptr[i+1]==0){j++;}
+
+              strcpy(tmp0,rep[j]);
+              if(a==0xee &&j>1){
+                cd=(ptr[i+2]+ptr[i+3]*128)-8192;
+              }else{cd=ptr[i+j];}
+
+              while(tmp0[0]!=0){
+                si=tmp0[0];
+                if(si=='+'||si=='-'||si=='*'||si=='/'||si=='%'){
+                  strcpy(tmp0,&tmp0[1]);
+                  if(tmp0[0]==0){break;}
+                  ml=val(tmp0);
+
+
+                  while(tmp0[0]>=0x30 && tmp0[0]<=0x39){
+                    strcpy(tmp0,&tmp0[1]);
+                  }
+                  if(tmp0[0]=='_'){
+                    strcpy(tmp0,&tmp0[1]);
+                    ml=(rand()*(val(tmp0)-ml+1)/32767)+ml;
+                  }
+
+
+                  if(si=='+'){cd=cd+ml;}
+                  if(si=='-'){cd=cd-ml;}
+                  if(si=='*'){cd=cd*ml;}
+                  if(si=='/'){cd=cd/ml;}
+                  if(si=='%'){
+                    if(ml>300){ml=300;}
+                    if(ml<=0){ml=1;}
+                    cd=cd*(ml/100);
+                  }
+
+                  cl=255;
+                  for(ct=1;ct<strlen(tmp0);ct++){
+                    si=tmp0[ct];
+                    if(si=='+'||si=='-'||si=='*'||si=='/'||si=='%'){cl=ct+1;break;}
+                  }
+                  if(cl!=255){
+                    strcpy(tmp0,&tmp0[cl-1]);
+                  }else{
+                    tmp0[0]=0;
+                  }
+                }else{
+                  if(tmp0[0]=='^'){strcpy(tmp0,&tmp0[1]);}
+                  if(j==0 && a<128){
+                    ct=ctc(60,tmp0,0);
+                    if(ct>=0){cd=ct;}
+                  }else{
+                    cd=str_val(tmp0);
+                    if((a==0xec || a==0xe2)&& j==2 && (cmdflag&0x20)!=0){cd--;}
+                  }
+                  tmp0[0]=0;
+                }
+              }
+skip3:
+
+              if(a<0xf0 && j==1){dat[i+1]=cd>>8;cd=cd&255;}
+
+              if( a<128 ){
+                if(cd<0){cd=0;}
+                if(j==0 || j==3){
+                  if(cd>127){cd=127;}
+                }else{
+                  if(cd>255){cd=255;}
+                }
+              }else{
+                if( a==0xee ){
+                  if( j>1 ){
+                    if(cd<-8192){cd=-8192;}
+                    if(cd>8191){cd=8191;}
+                  }else{
+                    if(cd<0){cd=0;}
+                    if(cd>255){cd=255;}
+                  }
+                }else{
+                  if(cd<0){cd=0;}
+                  if(j>1 && a!=0xf6 && a!=0x98 && a!=0xf7 && a!=0xe7){
+                    if(cd>127){cd=127;}
+                  }else{
+                    if(cd>255){cd=255;}
+                  }
+                }
+              }
+              if(a==0xee &&j>1){
+                cd=cd+8192;ptr[i+2]=cd&0x7f;ptr[i+3]=cd>>7;
+              }else{ptr[i+j]=cd;}
+            }
+          }
+          dat[i]=1;
+          if( sh==2 ){msg_clr();return i;}
+      }
+    }
+next:
+
+    if(INPOUT(0xff)==27 ){msg(_("Terminated."));return i;}
+
+    if( v==0 ){
+      i=i+4;if(i>=po+ln){break;}
+    }else{
+      i=i-4;if(i<0){break;}
+    }
+  }
+  if( sh==2 ){msg_clr();return -1;}
+
+  if(sh==1){
+    int i,a=0;
+    for(i=0;i<tr_len[track];i=i+4){
+
+      if(i>=po+ln && ln2==0){ln2=a-po;}
+
+      if(dat[i]==0){
+        ptr[a++]=ptr[i];ptr[a++]=ptr[i+1];
+        ptr[a++]=ptr[i+2];ptr[a++]=ptr[i+3];
+
+        if(ptr[i]!=0x98 && ptr[i]!=0xf6){
+          while(ptr[i+4]==0xf7){i+=4;}
+        }else{
+          while(ptr[i+4]==0xf7){i+=4;
+          ptr[a++]=ptr[i];ptr[a++]=ptr[i+1];
+          ptr[a++]=ptr[i+2];ptr[a++]=ptr[i+3];
+          }
+        }
+      }else{
+        if(rcvf && ptr[i]<0xf0 && ptr[i+1]!=0){
+          ptr[a++]=0;ptr[a++]=ptr[i+1];
+          ptr[a++]=0;ptr[a++]=0;
+        }
+        if(ptr[i]==0x98||ptr[i]==0xf6){
+          while(ptr[i+4]==0xf7){i+=4;}
+        }
+      }
+    }
+    tr_len[track]=a;
+  }
+  if(sh==0){
+    int i,a=0,ii,aa;
+    cpleng=0;
+
+    for(i=0;i<tr_len[track];i=i+4){
+
+      if(i>=po+ln && ln2==0){ln2=a-po;}
+
+      if(addf!=0 && dat[i]!=0 && dat2[i+4]!=0xf7 ){
+
+        if(a>=TRACK_SIZE){msg(_("Track buffer exhausted."));
+        memcpy_l(ptr,dat2,tr_len[track]);goto ext;}
+
+        cpbuf[a++]=dat2[i];cpbuf[a++]=0/*dat2[i+1]*/;
+        cpbuf[a++]=dat2[i+2];cpbuf[a++]=dat2[i+3];
+      }
+      ii=i;aa=a;
+loop1:
+      if(a>=TRACK_SIZE){msg(_("Track buffer exhausted."));
+      memcpy_l(ptr,dat2,tr_len[track]);goto ext;}
+
+      cpbuf[a++]=ptr[i];cpbuf[a++]=ptr[i+1];
+      cpbuf[a++]=ptr[i+2];cpbuf[a++]=ptr[i+3];
+
+      if(ptr[i+4]==0xf7){i+=4;goto loop1;}
+
+      if( dat[ii+1] ){
+        int ss=dat[ii+1]*256+ptr[ii+1];
+
+        if(cpbuf[aa]<0xf0){cpbuf[aa+1]=240;ss-=240;}
+
+        while(ss>0){
+          if(a>=TRACK_SIZE){msg(_("Track buffer exhausted."));
+          memcpy_l(ptr,dat2,tr_len[track]);goto ext;}
+
+          if(ss>240){
+            cpbuf[a++]=0;cpbuf[a++]=240;
+            cpbuf[a++]=0;cpbuf[a++]=0;
+            ss-=240;
+          }else{
+            cpbuf[a++]=0;cpbuf[a++]=ss;
+            cpbuf[a++]=0;cpbuf[a++]=0;
+            ss=0;
+          }
+        }
+      }
+    }
+
+    if(size_change(track,a)){goto ext;}
+
+    tr_len[track]=a;
+    memcpy_l(ptr,cpbuf,tr_len[track]);
+
+  }
+  if(ln2){ln=ln2;}
+  if(li2[0]!=0){goto top;}
+
+ext:
+  msg_clr();
+
+  snsclr();
+  return i;
+}
+
+/***************************/
+int    rep_match(int f,int f2,int t,int t2,int a,int m)
+{
+  if((f2&1)==0){
+    if( f== 0 && ( a==t                                )){return 1;}   /* ケ酥ア            */
+    if( f==-1 && ((m==0 && a<128) || m!=0              )){return 1;}   /* all note     */
+    if( f==-2 && ( a<t                         )){return 1;}   /* <            */
+    if( f==-3 && ( a>t && ((m==0 && a<128)||m!=0)      )){return 1;}   /* >            */
+    if( f==-4 && ((a%12)==(t%12) && a<128              )){return 1;}   /* note*        */
+    if( f==-5 && ( a>127 && (a<0xf0 || a==0xf7)     )){return 1;}      /* all spc      */
+
+    if( f==-6 && ( a<0xfc && (a<0xf6 || a>0xf9)        )){return 1;}   /* all data     */
+    /* if( f==-7 && ( a>=t     && a<=t2                )){return 1;}*/ /* ネマーマ         */
+
+    if(m==0){
+      if( f==-7 && (a>=t && a<=t2      )&& a<128){return 1;}   /* ネマーマ */
+    }else{
+      if( f==-7 && (a>=t && a<=t2      )){return 1;}
+    }
+
+    if( f==-8 && (a>=t && a<=t2)&& a>=0x90 && a<0x98){return 1;}       /* ネマーマ(usrexc)*/
+
+  }else{
+    if( f== 0 && a!=t){
+      if(m!=0 ||(m==0 && t<128 && a<128)       ){return 1;}    /* !ケ酥ア   */
+      if(m!=0 ||(m==0 && t>127 && t<0xf0 && a>127 && a<0xf0)){return 1;}
+    }
+    if( f==-1 && ( a>127 && a<0xfc &&(a<0xf6 || a>0xf9))){return 1;}/* !all note       */
+    if( f==-2 && ( a>=t &&((m==0 && a<128)||m!=0)      )){return 1;}   /* !<           */
+    if( f==-3 && ( a<=t                                )){return 1;}   /* !>           */
+    if( f==-4 && (!((a%12)==(t%12)) && a<128   )){return 1;}   /* !note*       */
+    if( f==-5 && ( a<128                               )){return 1;}   /* !all spc     */
+
+    if(m==0){
+      if( f==-7 && !(a>=t && a<=t2     )&& a<128){return 1;}   /* !ネマーマ*/
+    }else{
+      if( f==-7 && !(a>=t && a<=t2     )){return 1;}
+    }
+
+    if( f==-8 && !(a>=t && a<=t2)&& a>=0x90 && a<0x98){return 1;}      /* !ネマーマ(usrexc)*/
+
+  }
+  if( f==99 ){return 1;}
+  return(0);
+}
+/***************************/
+int    tai_check(int tr,int ad)
+{
+  int  ln;
+  unsigned char        a,b,c,d;
+
+  unsigned char        *ptr;
+  ptr=(unsigned char *)trk[tr];
+
+  ln=tr_len[tr];
+  a=ptr[ad];b=ptr[ad+1];c=ptr[ad+2];d=ptr[ad+3];
+
+  if(a<128 && c>b && d>0){
+    int ad2=ad,sum=0;
+
+    while(ad2<ln){
+      unsigned char    da=ptr[ad2];
+
+      if(ad2>ad && a==da && ptr[ad2+2]!=0 && ptr[ad2+3]!=0 ){
+        if(sum<c){return 1;}else{return 0;}
+      }
+      if(da<0xf0){sum+=ptr[ad2+1];if(sum>=c){return 0;}}
+      if(da==0xfc||da==0xfe){return 1;}
+      ad2+=4;
+    }
+  }
+  return(0);
+}
+
+/***************************/
+int    chd_check(int tr,int ad,int md)
+{
+  int  ln,sum=1;
+  unsigned char        a,b,c,d;
+
+  unsigned char        *ptr;
+  ptr=(unsigned char *)trk[tr];
+
+  ln=tr_len[tr];
+  if(md!=0){
+    while(ad<=ln){
+      a=ptr[ad];b=ptr[ad+1];c=ptr[ad+2];d=ptr[ad+3];
+      if(a>=0xf0){break;}
+      if(a<128 && c>0 && d>0){sum++;}
+      if(b>0){break;}
+      ad+=4;
+    }
+  }else{
+    while(ad>0){
+      ad-=4;
+      a=ptr[ad];b=ptr[ad+1];c=ptr[ad+2];d=ptr[ad+3];
+      if(a>=0xf0){break;}
+      if(b>0){break;}
+      if(a<128 && c>0 && d>0){sum++;}
+    }
+  }
+  return(sum);
+}
+
+/***************************/
+int    find(int po,int h)
+{
+  int  i,j,ct,mo=0,im=0;
+  char tmp0[256],tmp1[256];
+
+  strcpy(tmp0,srch);
+
+  if( (i=str_search(tmp0,"$<"))){
+    strcpy(&tmp0[i-1],&tmp0[i]);
+  }
+
+  jstrupr(tmp0);
+  if(srch[0]!=0){mo=1;}
+
+  if(tmp0[0]=='$'||tmp0[0]==0){
+    if(tmp0[0]!=0){strcpy(tmp0,&tmp0[1]);strcpy(tmp1,&srch[1]);}
+
+    if(tmp0[0]=='S'&&tmp0[1]=='T'&&tmp0[2]=='!'&&tmp0[3]=='='){
+      mo=2;if(tmp0[4]!=0){im=str_val(&tmp0[4]);}else{
+        im = tbase * 4 * beat1 / beat2;}
+    }
+    if(mo==0){
+      msg("SPCIAL CONTROLER");
+    }else{
+      if(mo==1){msg(_("Strings"));}else{msg(_("Except specified TOTAL ST"));}
+    }
+
+    B_PRINT(_(" Find ..."));
+    i=po;j=-1;h=h&1;
+    while(1){
+      if(INPOUT(0xff)==27 ){msg(_("Terminated."));return(i);snsclr();}
+      if( h==0 ){
+next:
+        i=i+4;if(i>=tr_len[track]){break;}
+        if(trk[track][i]==0xf7){goto next;}
+      }else{
+back:
+        i=i-4;if(i<0){break;}
+        if(trk[track][i]==0xf7){goto back;}
+      }
+      if(mo==0){
+        ct=trk[track][i];if(ct>127 && ct<252){j=i;break;}
+      }else{
+        if(mo==1){
+          if(str_search(trk_dis(-1,i,1),tmp1)>0){j=i;break;}
+        }else{
+          if(trk[track][i]==0xfd){
+            if(step_cluc(i)!=im){j=i;break;}
+          }
+        }
+      }
+    }
+  }else{
+    j=po;
+    if((h&1)==0){
+      po=po+4;if(po<tr_len[track]){j=replace(po,tr_len[track]-po,2,0);}
+    }else{
+      po=po-4;if(po>=0){j=replace(po,po,2,1);}
+    }
+  }
+
+  msg_clr();if(j<0){msg(_("Pattern not found."));}
+  snsclr();return(j);
+
+}
+
+/***************************/
+int    find_rep(int po)
+{
+  int  i,j,ct,flg,h;
+
+  i=po;j=-1;h=-1;flg=1;
+
+  if(trk[track][i]==0xf9){h=0;}/*[*/
+  if(trk[track][i]==0xf8){h=1;}/*]*/
+  if(h<0){snsclr();return(j);}
+
+  msg(_("Searching companion REPEAT ..."));
+
+  while(1){
+    if(INPOUT(0xff)==27 ){msg(_("Terminated."));return(i);snsclr();}
+    if( h==0 ){
+next:
+      i=i+4;if(i>=tr_len[track]){break;}
+      if(trk[track][i]==0xf7){goto next;}
+
+      if(trk[track][i]==0xf9){flg+=1;}/*[*/
+      if(trk[track][i]==0xf8){flg-=1;}/*]*/
+    }else{
+back:
+      i=i-4;if(i<0){break;}
+      if(trk[track][i]==0xf7){goto back;}
+
+      if(trk[track][i]==0xf9){flg-=1;}/*[*/
+      if(trk[track][i]==0xf8){flg+=1;}/*]*/
+    }
+
+    ct=trk[track][i];if(flg==0){j=i;break;}
+  }
+
+  msg_clr();if(j<0){msg(_("Pattern not found."));}
+  snsclr();return(j);
+}
+
+/***************************/
+void   trk_cluc(void)
+{
+  int  i,ch,meas=1,a,ln;
+  unsigned char        *ptr=trk[track];
+
+  ln=tr_len[track];ch=mch[track];
+  for(i=0;i<ln;i=i+4){
+    a=ptr[i];
+    if(a>0xe5){
+      if( a==0xe6 || a==0xe2 ){ch=ptr[i+2];}
+      if( a==0xec ){ptr[i+3]=ch;}
+      if( a==0xfc){
+        if(i!=0){if(ptr[i-4]<0xfc){meas++;}}
+        meas++;
+      }
+      if( a==0xfd ){ptr[i+2]=meas>>8;ptr[i+3]=meas & 0xff;meas++;}
+      if( a==0xfe ){tr_len[track]=i+4;}
+    }
+  }
+
+  ptr[ln-4]=0xfe;
+}
+
+/***************************/
+int    buf_meas(unsigned char *pp,int ln)
+{
+  int  i,co=0;
+  for(i=0 ;i<ln;i=i+4){
+    if( pp[i]>=0xfc || (i+4<ln && pp[i+4]==0xfc) ){co++;}
+  }
+  return(co);
+}
+
+/***************************/
+int    step_cluc(int ad)
+{
+  int  lc[16],lp[16],lx[16];
+  int  a=0,b=1,i,pp=0,ct,tr;
+  unsigned char        c,d;
+  unsigned char        *ptr;
+  tr=track;
+
+  ptr=(unsigned char *)trk[tr];
+
+  i=ad;
+  while(i>0){
+    i=i-4;
+    c=ptr[i];
+    if( c<0xf0 ){
+      d=ptr[i+1];
+      if(d){if(b==1){a=a+d;}else{a=a+d*b;}}
+    }else{
+      if( c>0xfb ){break;}
+      if( c==0xf8 ){
+        if(pp<16){
+          ct=ptr[i+1];if(ct==0||ct==255){ct=1;}
+          lc[pp]=b;lp[pp]=a;lx[pp]=ct;b=b*ct;pp++;
+        }
+      }
+      if( c==0xf9 ){
+        if(pp>0){pp--;b=lc[pp];}
+      }
+    }
+  }
+  for(i=pp-1;i>=0;i--){a=lp[i]+((a-lp[i])/lx[i]);}
+  return(a);
+}
+
+/***************************/
+int    step_cluc2(int tr,int top,int len)
+{
+  int  lx[16],me_ad[2048];
+  int  i,pp,a,ct,max,retad=0;
+  unsigned char        c;
+  unsigned char        *ptr;
+
+  ptr=(unsigned char *)trk[tr];
+  max=add_set(tr,me_ad);
+
+  pp=0;a=0;i=top;
+  while(i<top+len){
+top:
+    c=ptr[i];
+    if( c<0xf0 ){
+      a+=ptr[i+1];
+    }else{
+      if( c==0xf9 ){
+        if(pp<16){
+          lx[pp]=a;a=0;pp++;
+        }
+      }
+      if( c==0xf8 ){
+        if(pp>0){pp--;
+        ct=ptr[i+1];if(ct==0||ct==255){ct=1;}
+        a=lx[pp]+(a*ct);
+        }
+      }
+      if( c>=0xfc && retad!=0){i=retad;retad=0;goto top;}
+      if( c==0xfc ){
+        int    ii,jj,ct;
+        jj=i;
+resame:
+        ct=ptr[jj+1]+(ptr[jj+2]&3)*256;ii=me_ad[ct];
+
+        if(ct<max && jj!=ii){
+          jj=ii;if(ptr[ii]==0xfc){goto resame;}
+          retad=i+4;i=ii;goto top;
+        }
+      }
+    }
+    i+=4;
+  }
+
+  for(i=0;i<pp;i++){a+=lx[i];}
+  return(a);
+}
+
+/***************************/
+int    real_ad(int po,int cy)
+{
+  while(cy>0){
+loop:          po=po+4;if(trk[track][po]==0xf7){goto loop;}
+    cy=cy-1;
+  }
+  return(po);
+}
+
+int    real_po(int po,int cy)
+{
+  while(cy>0){
+loop:          po=po-4;
+    if(po<=0){break;}
+    if(trk[track][po]==0xf7){goto loop;}
+    cy=cy-1;
+  }
+  return(po);
+}
+
+int    real_cy(int po,int ad)
+{
+  int  cy=0;
+  while(ad>po){
+loop:          ad=ad-4;
+    if (ad<=0) {break;}
+    if(trk[track][ad]==0xf7){goto loop;}
+    cy=cy+1;
+  }
+  return(cy);
+}
+
+/***************************/
+int    step_no(int ad)
+{
+  int  po;
+  int  step=0+1;
+  unsigned char        *bp=trk[track];
+
+  po=ad;
+  while(po>0){
+    unsigned char      e;
+    po=po-4;e=bp[po];
+
+    if(e<0xf0 &&(po==0||bp[po-4+1]!=0||bp[po-4]>=0xf0)){
+      if(bp[po-4]==0xf7){
+        while(bp[po-4]==0xf7){po-=4;}
+        if(bp[po-4]==0x98 && bp[po-4+1]==0){goto next1;}
+      }
+      step++;
+    }
+next1:
+    if( e>=0xfc ){break;}
+  }
+  return(step);
+}
+
+int    step_ad(int ad,int step)
+{
+  int  po;
+  unsigned char        *bp=trk[track];
+
+  po=ad;
+  while(step>0){
+    unsigned char      a;
+redis:
+    a=bp[po];
+    if(a==0xf7){po+=4;goto redis;}
+    if(a>=0xfc ){break;}
+
+    if(a<0xf0 &&(po==0||bp[po-4+1]!=0||bp[po-4]>=0xf0)){
+      if(bp[po-4]==0xf7){
+        int    pp=po-4;
+        while(bp[pp]==0xf7){pp-=4;}
+        if(bp[pp]==0x98 && bp[pp+1]==0){goto next2;}
+      }
+      step--;if(step==0){break;}
+    }
+next2:
+    po=po+4;
+  }
+  return(po);
+}
+
+int    sttm_no(int ad)
+{
+  return step_cluc(ad);
+}
+
+int    sttm_ad(int ad,int step)
+{
+  int  po;
+  unsigned char        *bp=trk[track];
+
+  if(ad<0){return ad;}
+
+  po=ad;
+  while(1){
+    unsigned char      a;
+    if(step_cluc(po)>=step){break;}
+redis:
+    a=bp[po];
+    if(a==0xf7){po+=4;goto redis;}
+    if(a>=0xfc ){break;}
+
+    po=po+4;
+  }
+  return(po);
+}
+
+/***************************/
+int    padjust(int *po,int i)
+{
+  int  y=0;
+
+  if(*po<0){*po=tr_len[track]-4;}
+  if(tr_len[track]<25*4){i=23;}
+
+  while(i>0 && *po>0){
+loop:          *po=*po-4;if(trk[track][*po]==0xf7){goto loop;}
+    y++;i--;
+  }
+  trk_dis(6,*po,24);return(y);
+}
+
+/***************************/
+int    meas_no(int ad)
+{
+  int  co=1,j;
+  j=ad;
+  while(j>0 ){
+    j=j-4;
+    if( trk[track][j]>=0xfc || trk[track][j+4]==0xfc ){co++;}
+  }
+  return(co);
+}
+
+/***************************/
+/*
+int    meas_no2(int ad)
+{
+int    lx[16];
+int    i,pp,a,ct;
+unsigned char  c;
+unsigned char  *ptr;
+
+ptr=(unsigned char *)trk[track];
+
+pp=0;a=1;i=0;
+while(i<ad){
+c=ptr[i];
+if( c>=0xfc || (i+4<ad && ptr[i+4]==0xfc) ){
+a+=1;
+}
+if( c==0xf9 ){
+if(pp<16){
+lx[pp]=a;a=0;pp++;
+}
+}
+if( c==0xf8 ){
+if(pp>0){pp--;
+ct=ptr[i+1];if(ct==0||ct==255){ct=1;}
+a=lx[pp]+(a*ct);
+}
+}
+i+=4;
+}
+
+for(i=0;i<pp;i++){a+=lx[i];}
+return(a);
+}
+*/
+/***************************/
+
+
+int    meas_add(int me)
+{
+  int  co=1,j=0,ad=0,tr;
+  if( me>1){
+    tr=track;
+    while(j<tr_len[tr]-4 ){
+      if( trk[tr][j]>=0xfc || trk[tr][j+4]==0xfc ){
+        co++;if( co==me ){ad=j+4;break;}
+      }
+      j=j+4;
+    }
+    if(ad==0){ad=-1;}
+  }
+  return(ad);
+}
+
+/***************************/
+int    dat_add(int ln,int me)
+{
+  int  co=1,j=0,ad=0;
+  if( me>1){
+    while(j<ln ){
+      if( dat[j]>=0xfc ){
+        co++;if( co==me ){ad=j+4;break;}
+      }
+      j=j+4;
+    }
+    if(ad==0){ad=-1;}
+  }
+  return(ad);
+}
+
+/***************************/
+int    meas_len(int j)
+{
+  int  co=0,d;
+
+  d=trk[track][j];
+  while(j<tr_len[track] ){
+    if( d==0xfe ){break;}
+    co++;
+    if( d>0xfb ){break;}
+    j=j+4;d=trk[track][j];
+  }
+  return(co*4);
+}
+
+/***************************/
+int    add_set(int tr,int *add)
+{
+  int  co=0,i=0;
+
+  add[0]=0;
+  while(i<tr_len[tr]){
+    if(trk[tr][i]>=0xfc||trk[tr][i+4]==0xfc){
+      co++;if(co<2048){add[co]=i+4;}
+    }
+    i=i+4;
+  }
+  for(i=co+1;i<2048;i++){add[i]=0;}
+  return(co);
+}
+
+/***************************/
+void   undobuf(int a)
+{
+  int  i,d;
+
+  if(a==0){
+    memcpy_l(rcpbuf,trk[track],tr_len[track]);
+    undof[0]=track;undof[1]=tr_len[track];rcpf=-1;
+  }else{
+    if(rcpf>=0 || track!=undof[0]){
+      msg(_("UNDO buffer is empty."));return;}
+
+    if(size_change(track,undof[1])){return;}
+
+    for(i=0;i<undof[1];i++){
+      d=trk[track][i];trk[track][i]=rcpbuf[i];rcpbuf[i]=d;
+    }
+    d=tr_len[track];tr_len[track]=undof[1];undof[1]=d;
+    msg(_("UNDO !"));
+  }
+  snsclr();
+}
+
+/***************************/
+void   same_shift(int spo,int m,int cu)
+{
+  int  i,me,me2,ec,po,ad,of;
+  unsigned char        a,b,c,d;
+  int  add[2048];
+  int  sad[1024];
+  int  tr=track;
+
+  if(cu==0){return;}
+
+  msg_clr();me=meas_no(spo)-1;me2=me+cu;
+
+  add_set(tr,add);for(i=0;i<1024;i++){sad[i]=0;}
+  if(me<1024){
+    if(m==0){
+      /*insert*/
+      int      i,j;
+      if(spo>0 && trk[tr][spo-4]<0xfc && trk[tr][spo]<0xfc){
+        me++;}
+
+      if(trk[tr][spo]>0xfc){me++;me2++;}
+
+      j=1024-cu;if(j<0){j=0;}
+      for(i=j;i<1024;i++){sad[i]=-1;}
+    }else{
+      /*delete*/
+      int      i,j;
+      if(trk[tr][spo]>0xfc && trk[tr][spo+4]>0xfc){me++;me2++;}
+      j=me2;if(j>1024){j=1024;}
+      for(i=me;i<j;i++){sad[i]=-1;}
+      spo=add[me2];
+    }
+  }
+
+  i=0;po=0;
+  while(i<tr_len[tr]){
+    if(po>=TRACK_SIZE){po+=4;break;}
+    a=trk[tr][i];b=trk[tr][i+1];c=trk[tr][i+2];d=trk[tr][i+3];
+    if(a==0xfc && i>=spo){
+      int      smn=b+(c&3)*256;
+      if(sad[smn]<0){
+        ad=add[smn];if(m==1){sad[smn]=meas_no(i);}
+        if(i>0 && trk[tr][i-4]<0xfc){dat[po]=0xfd;po=po+4;}
+
+        while(trk[tr][ad]<0xfc){
+          if(po>=TRACK_SIZE){po+=4;break;}
+          dat[po]=trk[tr][ad];dat[po+1]=trk[tr][ad+1];
+          dat[po+2]=trk[tr][ad+2];dat[po+3]=trk[tr][ad+3];
+          ad=ad+4;po=po+4;
+        }
+        if(po>TRACK_SIZE){break;}
+        dat[po]=0xfd;po=po+4;
+      }else{
+        if(sad[smn]>0){of=sad[smn]-1;b=of&0xff;c=of>>8;}
+        dat[po]=a;dat[po+1]=b;dat[po+2]=c;dat[po+3]=d;po=po+4;
+      }
+    }else{
+      dat[po]=a;dat[po+1]=b;dat[po+2]=c;dat[po+3]=d;po=po+4;
+    }
+    i=i+4;
+  }
+
+  if(size_change(tr,po)){return;}
+  if(po<=TRACK_SIZE){tr_len[tr]=po;memcpy_l(trk[tr],dat,po);}
+
+  ec=0;
+  for(i=spo ;i< tr_len[tr];i=i+4){
+    a=trk[tr][i];
+    if( a==0xfc ){
+      int      smn=trk[tr][i+1]+(trk[tr][i+2]&3)*256;
+      if(me<=smn ){
+        if(m==0){
+          if(smn+cu<1024){smn+=cu;}else{smn=1023;ec++;}
+        }else{
+          if(me2>smn ){smn=0;ec++;}else{smn=smn-cu;}
+        }
+      }
+      trk[tr][i+1]=smn&0xff;trk[tr][i+2]=smn>>8;
+    }
+  }
+  if(ec!=0){
+    char b[4096];
+    int ret;
+    ret=sprintf_s(b,sizeof(b),_("%4d times of SAME MEAS is invalid"),ec);
+    if ( ret > 0 ) {
+      msg(b);
+    }
+    /*msg("SAME MEAS、ャ");B_PRINT(fstr(ec,4));B_PRINT("イユス・オク妤ヒ、ハ、熙゙、キ、ソ。」");*/
+  }
+
+  snsclr();
+}
+
+/***************************/
+int    same_meas_extr(int tr,int ad,int ln)
+{
+  int  po;
+
+  if(ln==0){return(0);}
+  undobuf(0);msg(_("Extracting SAME MEAS ..."));po=same_ext_sub(tr,ad,ad+ln,1);
+
+  if(ad>0 && trk[tr][ad]==0xfc && trk[tr][ad-4]<0xfc){
+    memcpy_l(&dat[4],dat,po);dat[0]=0xfd;po+=4;
+  }
+
+  if(size_change(tr,tr_len[tr]-ln+po)){return 1;}
+  trk_delete(ad,ln);trk_shift(ad,po);
+  memcpy_l(&trk[tr][ad],dat,po);
+
+  return(0);
+}
+
+/***************************/
+int    cpybuf_set(int tr,int ad,int ln)
+{
+  int  po;
+
+  po=same_ext_sub(tr,ad,ad+ln,0);
+
+  if(po<=TRACK_SIZE){
+    memcpy_l(cpbuf,dat,po);
+  }else{
+    msg(_("Copy buffer will be exhausted. Not extract."));
+    memcpy_l(cpbuf,&trk[track][ad],ln);
+    return(ln);
+  }
+  return(po);
+}
+
+/***************************/
+void   dat_rev(int tr,int ad,int ln)
+{
+  int  po,i,i2,co,c;
+
+  if(ln<8){return;}
+
+  i=ad;po=ln-4;
+  while(po>=0){
+    unsigned char      a=cpbuf[po];
+    if(a>=0xf0){
+      if(a==0xf8 || a==0xf9){a=497-a;}
+      if(a==0xf7 || a==0xf6 || a==0x98){
+        c=0;i2=po;
+        while(a==0xf6 || a==0x98 || a==0xf7){
+          c+=4;if(i2==0){break;}
+          i2-=4;a=cpbuf[i2];
+        }
+        for(i2=0;i2<c;i2++){trk[tr][i+i2]=cpbuf[po-c+4+i2];}
+        i+=c;po-=c;
+      }else{
+        trk[tr][i]=a;trk[tr][i+1]=cpbuf[po+1];
+        trk[tr][i+2]=cpbuf[po+2];trk[tr][i+3]=cpbuf[po+3];
+        i+=4;po-=4;
+      }
+    }else{
+      unsigned char    b=cpbuf[po+1];
+      if(b!=0){
+        c=0;i2=po;
+        while(1){
+          c+=4;if(i2==0){break;}
+          i2-=4;b=cpbuf[i2+1];
+          if(b!=0){break;}
+        }
+        for(i2=0;i2<c;i2++){trk[tr][i+i2]=cpbuf[po-c+4+i2];}
+        i+=c;po-=c;
+      }else{
+        trk[tr][i]=a;trk[tr][i+1]=cpbuf[po+1];
+        trk[tr][i+2]=cpbuf[po+2];trk[tr][i+3]=cpbuf[po+3];
+        i+=4;po-=4;
+      }
+    }
+  }
+
+  i=ad+ln-4;
+  while(i>=ad){
+    if(trk[tr][i]==0xf8){
+      i2=i-4;co=1;
+      while(i2>=ad){
+        unsigned char  a=trk[tr][i2];
+        if(a==0xf8){co++;}
+        if(a==0xf9){co--;if(co==0){trk[tr][i+1]=trk[tr][i2+1];break;}}
+        i2-=4;
+      }
+    }
+    i-=4;
+  }
+}
+
+/***************************/
+int    replicate(int ad,int sh)
+{
+  int  top,end,topad,endad,times,bias,dummy,a,i,j,escrn,dist_no;;
+
+  dummy=track;escrn=edit_scr;edit_scr=0;cons_md(0);
+  dist_no=meas_no(ad);
+
+rip1:  msg("Replicate TR.=");
+
+  if(sh&1){
+    B_PRINT("all");
+  }else{
+    track=vinput(dummy+1,0x802)-1;
+    if( es!=0 ){track=dummy;edit_scr=escrn;cons_md(1);msg_clr();return(1);}
+    if( track<0 || track>35){goto rip1;}
+  }
+
+rip2:  B_LOCATE(18,1);B_PRINT("TOP=");top=vinput(1,0x804);
+  if(sh&1){
+    if( es!=0 ){track=dummy;edit_scr=escrn;cons_md(1);msg_clr();return(1);}
+  }
+  if( es!=0 ){goto rip1;}
+
+  if(top<1){goto rip2;}
+
+rip3:  B_LOCATE(27,1);B_PRINT("END=");end=vinput(top,0x804);
+  if( es!=0 ){goto rip2;}
+  if( end<top){goto rip3;}
+
+rip4:  B_LOCATE(36,1);B_PRINT("TIMES=");times=vinput(1,0x803);
+  if( es!=0 ){goto rip3;}
+  if(times<1 || times>255){goto rip4;}
+
+rip5:  B_LOCATE(45,1);B_PRINT("BIAS=");bias=vinput(0,0x803);
+  if( es!=0 ){goto rip4;}
+  if(bias<-24 || bias>24){goto rip5;}
+
+
+loop:
+  topad=meas_add(top);if(topad<0){topad=tr_len[track]-4;}
+  endad=meas_add(end+1);if(endad<0){endad=tr_len[track]-4;}
+
+  if(tr_len[track]>4 && topad>=0){
+    cpleng=cpybuf_set(track,topad,endad-topad);
+
+    if(cpleng>0 && cpbuf[cpleng-4]!=0xfd){cpbuf[cpleng]=0xfd;cpleng+=4;}
+    for(i=0;i<cpleng;i=i+4){a=cpbuf[i];if(a<127){a=a+bias;if(a>=0 && a<128){cpbuf[i]=a;}}}
+
+    if((sh&1)==0){
+      track=dummy;
+    }else{
+      ad=meas_add(dist_no);if(ad<0){ad=tr_len[track]-4;}
+    }
+
+    undobuf(0);
+
+    if(size_change(track,tr_len[track]+cpleng)){return 1;}
+
+    j=times;
+    while(j!=0){
+      if(trk_shift(ad,cpleng)==0){
+        same_shift(ad,0,buf_meas(cpbuf,cpleng));
+        for(i=0;i<cpleng;i++){trk[track][i+ad]=cpbuf[i];}
+      }
+      j--;
+    }
+  }
+
+  trk_lin(track,-1,0);
+  if(sh&1){
+    track++;if(track>35){track=0;}
+    if(track!=dummy){goto loop;}
+  }
+
+  track=dummy;
+  size_max(track);
+  edit_scr=escrn;cons_md(1);msg_clr();return(0);
+}
+
+/***************************/
+int    replicate2(int ad,int sh)
+{
+  int  top,/*end,topad,endad,*/times,bias,dummy,a,i,j,escrn;
+
+  dummy=track;escrn=edit_scr;edit_scr=0;cons_md(0);
+
+
+  if( cplen<0 && cpadd!=ad){
+    cplen=abs(cpadd-ad);if(cpadd>ad ){cpadd=ad;}
+    cpleng=cpybuf_set(track,cpadd,cplen);
+    if(cpleng>0 && cpbuf[cpleng-4]!=0xfd){cpbuf[cpleng]=0xfd;cpleng+=4;}
+  }else{return 1;}
+
+
+rip1:  msg("Replicate2 TR.=");
+
+  if(sh&1){
+    B_PRINT("all");
+  }else{
+    track=vinput(dummy+1,0x802)-1;
+    if( es!=0 ){track=dummy;edit_scr=escrn;cons_md(1);msg_clr();return(1);}
+    if( track<0 || track>35){goto rip1;}
+  }
+
+rip2:  B_LOCATE(18,1);B_PRINT("TOP=");top=vinput(1,0x804);
+  if(sh&1){
+    if( es!=0 ){track=dummy;edit_scr=escrn;cons_md(1);msg_clr();return(1);}
+  }
+  if( es!=0 ){goto rip1;}
+
+  if(top<1){goto rip2;}
+
+
+rip4:  B_LOCATE(36,1);B_PRINT("TIMES=");times=vinput(1,0x803);
+  if( es!=0 ){goto rip2;}
+  if(times<1 || times>255){goto rip4;}
+
+rip5:  B_LOCATE(45,1);B_PRINT("BIAS=");bias=vinput(0,0x803);
+  if( es!=0 ){goto rip4;}
+  if(bias<-24 || bias>24){goto rip5;}
+
+
+  for(i=0;i<cpleng;i=i+4){a=cpbuf[i];if(a<127){a=a+bias;if(a>=0 && a<128){cpbuf[i]=a;}}}
+loop:
+  /*if(tr_len[track]>4 && meas_add(top)>=0){*/
+  if((sh&1)==0 || mch[track]!=0){
+
+    ad=meas_add(top);if(ad<0){ad=tr_len[track]-4;}
+
+    undobuf(0);
+
+    if(size_change(track,tr_len[track]+cpleng)){return 1;}
+
+    j=times;
+    while(j!=0){
+      if(trk_shift(ad,cpleng)==0){
+        same_shift(ad,0,buf_meas(cpbuf,cpleng));
+        for(i=0;i<cpleng;i++){trk[track][i+ad]=cpbuf[i];}
+      }
+      j--;
+    }
+  }
+
+  trk_lin(track,-1,0);
+  if(sh&1){
+    track++;if(track>35){track=0;}
+    if(track!=dummy){goto loop;}
+  }
+
+  track=dummy;
+  size_max(track);
+  edit_scr=escrn;cplen=0;cons_md(1);msg_clr();return(0);
+}
+
+/***************************/
+void   bendc(int ad,int sh)
+{
+  int  stt[256];
+
+  int  ct=8192,ct2=8192,st,i,j,cc,ss,ctlch=0;
+  unsigned char        da=trk[track][ad],db=trk[track][ad+4];
+  unsigned char        ca=0xee,cf=trk[track][ad+2];
+
+  if((sh&1)==0){
+    if( da==0xeb && db==0xeb ){
+      if( cf!=trk[track][ad+6] || cf>=120){return;}
+      msg(ctrl_type(cf));ctlch=1;ca=0xeb;
+    }else{
+      if( da==0xde && db==0xde ){
+        msg("Rol.Para");ctlch=1;ca=0xde;
+      }else{
+        if( (da>127 && da!=0xee) || (db>127 && db!=0xee) ){return;}
+        msg("PITCH BEND");
+      }
+    }
+
+    if(ctlch==0){
+      if(da==0xee){ct=trk[track][ad+2]+trk[track][ad+3]*128;}
+      if(db==0xee){ct2=trk[track][ad+6]+trk[track][ad+7]*128;}
+      if(da<128 && db<128){ct2+=((db-da)*1365)>>1;}
+
+      if(ct2-ct>8192 || ct2-ct<-8192){msg_clr();return;}
+    }else{
+      ct=trk[track][ad+3];ct2=trk[track][ad+7];
+    }
+
+    ct2=(ct2-ct);if(ct2>8191){ct2=8191;}
+    st=trk[track][ad+1];
+
+    B_PRINT(" COUNT=");j=vinput(0,3);msg_clr();
+    if( es!=0 || j<2 || j>st ){return;}
+
+    undobuf(0);
+    if(trk_shift(ad,j*4-4)!=0){return;}
+
+    bunkatsu(st,j,stt);
+
+    cc=0;ss=ct;
+    for(i=0;i<j;i++){
+      unsigned char    ea,eb;
+      if(ct2!=0){ss=ct+(ct2*cc/j);cc++;}
+      trk[track][ad]=ca;trk[track][ad+1]=stt[i];
+      if(ctlch==0){ea=ss&0x7f;eb=(ss>>7)&0x7f;}else{ea=cf;eb=ss;}
+      trk[track][ad+2]=ea;trk[track][ad+3]=eb;
+      ad=ad+4;
+    }
+  }else{
+    unsigned char      ea = trk[track][ad + 2];
+    unsigned char      eb = trk[track][ad + 3];
+    char       tmp[64];
+    int ke,md=0,co;
+
+    if(da>127 || db>127){msg_clr();return;}
+
+    /*         msg("NOTE");
+    msg_clr();*/
+
+resel:
+    msg("Mode: (w=1/w+b=2)");
+
+    /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+    key_wait();
+    ke=B_KEYINP()&0xff;
+    msg_clr();
+
+    if(ke==0x1b){return;}
+    if(ke=='1'){md=1;}
+    if(ke=='2'){md=2;}
+    if(md<=0){goto resel;}
+
+
+    ct=da;ct2=db;ct2=(ct2-ct);
+    st=trk[track][ad+1];
+
+    j=abs(ct2);
+    if( j<2 || j>st ){return;}
+
+    co=0;
+    for(i=0;i<j;i++){
+      strcpy(tmp,keystr(ct+(ct2*i/j)));
+      if(tmp[1]==' '||md==2){co++;}
+    }
+
+    undobuf(0);
+    if(trk_shift(ad,co*4-4)!=0){return;}
+    bunkatsu(st,co,stt);
+
+    co=0;ss=ct;
+    for(i=0;i<j;i++){
+      ss=ct+(ct2*i/j);
+      strcpy(tmp,keystr(ss));
+      if(tmp[1]==' '||md==2){
+        trk[track][ad]=ss;trk[track][ad+1]=stt[co];
+        trk[track][ad+2]=ea;trk[track][ad+3]=eb;
+        ad=ad+4;co++;
+      }
+    }
+  }
+}
+
+/***************************/
+int    bendc2(int ad,char *s)
+{
+  int  po,j=0,a;
+  unsigned char        c;
+
+  a=ctc(-1,s,0);
+  if( a<0 ){return(0);}
+  if( a!=0 ){
+    po=ad;j=-1;
+    while(po>=0){
+      c=trk[track][po];if( c<128 ){j=c;break;}
+      po=po-4;
+    }
+    if( j<0 ){es=1;}else{j=((ctc(j,s,/*scale_no(ad)*/0)-j)*1365)>>1;}
+  }else{
+    j=str_val(s);
+  }
+  return(j);
+}
+
+/***************************/
+int    bank_no(int j)
+{
+  int  bank=-1,bank_l=-1;
+
+  while(j>0){
+    unsigned char a;
+    j-=4;
+    a=trk[track][j];
+
+    if(a==0xeb){
+      if(trk[track][j+2]==0 && bank<0){bank=trk[track][j+3];}
+      if(trk[track][j+2]==32 && bank_l<0){bank_l=trk[track][j+3];}
+    }
+    if(a==0xe2){
+      if(bank<0){bank=trk[track][j+3];}
+      /*       if(bank_l<0){bank_l=0;}*/
+    }
+  }
+  if(bank<0 || bank>127){bank=0;}
+  if(bank_l<0 || bank_l>127){bank_l=0;}
+  return(bank_l*256+bank);
+}
+
+/***************************/
+int    prog_no(int j)
+{
+  int  prog=0;
+
+  while(j>=0){
+    if(trk[track][j]==0xec){prog=trk[track][j+2];break;}
+    if(trk[track][j]==0xe2){prog=trk[track][j+2];break;}
+    j-=4;
+  }
+  return(prog);
+}
+
+/***************************/
+int    channel_no(int j)
+{
+  int  ch=mch[track];
+
+  while(j>0){
+    j-=4;
+    if(trk[track][j]==0xe6){ch=trk[track][j+2];break;}
+    if(trk[track][j]==0xec){ch=trk[track][j+3];break;}
+  }
+  return(ch);
+}
+
+/***************************/
+void   trk_next(int m)
+{
+  int  trk=track;
+trkloop:
+  if((m&1)==0){
+    trk--;if(trk<0){trk=35;}
+  }else{
+    trk++;if(trk>35){trk=0;}
+  }
+  if(track!=trk &&(tr_len[trk]==4||(m>=2 && !rcd->active[trk]))){goto trkloop;}
+  if(track!=trk){cplen=0;}
+  track=trk;
+}
+
+/***************************/
+int    spc_code(char *s,int *ctl)
+{
+  unsigned char        a,b;
+  int  c1=0xeb,c2=-1;
+
+
+  jstrupr(s);a=s[0];b=s[1];
+  if(a=='/'){a=s[1];b=s[2];}
+
+  if( a=='@' ){c2=0;if( b=='@'||b=='L'){c2=32;}}               /* BANK SELECT  */
+  if( a=='D' ){c2=1;}
+  if( a=='V' ){c2=7;}
+  if( a=='N' ){c2=10;}
+  if( a=='E' ){c2=11;}
+  if( a=='H' ){c2=64;}
+  if( a=='A' ){c2=121;}
+
+  if( a=='F' && b>='1' && b<='5' ){c2=b-'1'+91;}               /* EFFECT 1-5   */
+  if( a=='P' ){        if( b=='T' ){c2=5;}                     /* PORTA.TM     */
+  if( b=='O' ){c2=65;}                 /* PORTAMEN     */
+  if( b=='C' ){c2=84;}}                        /* POR.CONT     */
+  if( a=='S' ){        if( b=='S' ){c2=66;}                    /* SOSTENUT     */
+  if( b=='T' ){c2=67;}}                        /* SOFT         */
+  if( a=='E' ){        if( b=='M' ){c2=6;}                     /* ENTRY M.     */
+  if( b=='L' ){c2=38;}}                        /* ENTRY L.     */
+  if( a=='N'){ if( b=='M' ){c2=99;}                    /* NRPN MSB     */
+  if( b=='L' ){c2=98;}}                        /* NRPN LSB     */
+  if( a=='R' ){        if( b=='M' ){c2=101;}                   /* RPN MSB      */
+  if( b=='L' ){c2=100;}}                       /* RPN LSB      */
+
+  if( a=='B' ){        if( b=='R' ){c2=2;}}                    /* BREATH       */
+
+  if( a=='R' ){        if( b=='S' ){c2=71;}}                   /* Resonanc     */
+  if( a=='R' ){        if( b=='T' ){c2=72;}}                   /* Rel.Time     */
+  if( a=='A' ){        if( b=='T' ){c2=73;}}                   /* Att.Time     */
+  if( a=='C' ){        if( b=='O' ){c2=74;}}                   /* Cutoff F     */
+
+  if(c2<0){
+    c1=0;
+    if( a=='U' && b>='0' && b<='7'){c1=0x90+b-'0';}    /* UserExc 0-7  */
+    if( a=='X' ){c1=0x98;}
+    if( a=='B' ){c1=0xdd;}
+    if( a=='R' ){c1=0xde;}
+    if( a=='I' ){c1=0xdf;}
+    if( a=='T' ){c1=0xe7;}
+    if( a=='C' ){c1=0xea;}
+    if( a=='S' ){
+      if( b>='0' && b<='9' ){c1=0xc0+b-'0';}
+      if( b>='A' && b<='F' ){c1=0xca+b-'A';}
+      if( b=='4' ){c1=0xdc;}
+    }
+    if( a=='L' ){c1=0xeb;if(s[1]!=0){c2=atoi(&s[1]);}}
+    if( a>='0' && a<='9' ){c1=0xeb;c2=atoi(s);if(c2>127){c2=-1;}}
+
+    if( a=='G' ){
+      if( b=='@' || b=='M' ){c1=0xe2;if(s[2]!=0){c2=atoi(&s[2]);}
+      }else{c1=0xec;if(s[1]!=0){c2=atoi(&s[1]);}}
+    }
+    if( a=='K' ){c1=0xed;}
+    if( a=='P' ){c1=0xee;}
+    if( a=='M' ){c1=0xe6;}
+    /*
+    if( a=='M' ){
+    c1=0xe6;
+    if( (b>='0' && b<='9') || b=='A' || b=='B' ){
+    if(s[2]!=0){
+    c2=strch(1,&s[2]);
+    }else{
+    if(s[1]!=0){c2=strch(1,&s[1]);}
+    }
+    }
+    }
+    */
+  }
+  *ctl=c2;return(c1);
+}
+
+/***************************/
+char   *ctrl_type(int a)
+{
+  static char  tmp0[16];
+  int  cc;
+
+  switch(a){
+  case 0  :strcpy(tmp0,"BANK MSB");break;
+  case 1  :strcpy(tmp0,"MODULAT ");break;
+  case 2  :strcpy(tmp0,"BREATH  ");break;
+  case 4  :strcpy(tmp0,"FOOT C. ");break;
+  case 5  :strcpy(tmp0,"PORTA.TM");break;
+  case 7  :strcpy(tmp0,"VOLUME  ");break;
+  case 8  :strcpy(tmp0,"BALANCE ");break;
+  case 10 :strcpy(tmp0,"PANPOT  ");break;
+  case 11 :strcpy(tmp0,"EXPRESS ");break;
+
+  case 32 :strcpy(tmp0,"BANK LSB");break;
+    /*         case 33 :strcpy(tmp0,"MODULA.L");break;
+    case 34 :strcpy(tmp0,"BREATH.L");break;
+    case 36 :strcpy(tmp0,"FOOT C.L");break;
+    case 37 :strcpy(tmp0,"PORTA.TL");break;
+    case 39 :strcpy(tmp0,"VOLUME.L");break;
+    case 40 :strcpy(tmp0,"BALANC.L");break;
+    case 42 :strcpy(tmp0,"PANPOT.L");break;
+    case 43 :strcpy(tmp0,"EXPRES.L");break;*/
+
+    /*70:patch sel  102|*/
+
+  case 64 :strcpy(tmp0,"HOLD1   ");break;      /*HOLD1(Damper)*/
+  case 65 :strcpy(tmp0,"PORTAMEN");break;
+  case 66 :strcpy(tmp0,"SOSTENUT");break;
+  case 67 :strcpy(tmp0,"SOFT    ");break;
+  case 69 :strcpy(tmp0,"HOLD2   ");break;      /*HOLD2(Freez )*/
+
+  case 71 :strcpy(tmp0,"Resonanc");break;
+  case 72 :strcpy(tmp0,"Rel.Time");break;
+  case 73 :strcpy(tmp0,"Att.Time");break;
+  case 74 :strcpy(tmp0,"Cutoff F");break;      /* Cutoff Freq. */
+
+  case 84 :strcpy(tmp0,"POR.CONT");break;      /*legart*/
+
+    /*tg300*/  case 89 :strcpy(tmp0,"VariSend");break; /*Variation   94?*/
+    case 90 :strcpy(tmp0,"DryLevel");break;
+
+    case 91 :strcpy(tmp0,"REVERB  ");break;
+      /*               case 92 :strcpy(tmp0,"EFFECT2 ");break;*/
+    case 93 :strcpy(tmp0,"CHORUS  ");break;
+    case 94 :strcpy(tmp0,"DELAY   ");break;
+      /*               case 95 :strcpy(tmp0,"EFFECT5 ");break;*/
+
+    case 6  :strcpy(tmp0,"DATA MSB");break;
+    case 38 :strcpy(tmp0,"DATA LSB");break;
+    case 96 :strcpy(tmp0,"DATA INC");break;
+    case 97 :strcpy(tmp0,"DATA DEC");break;
+    case 98 :strcpy(tmp0,"NRPN LSB");break;
+    case 99 :strcpy(tmp0,"NRPN MSB");break;
+    case 100:strcpy(tmp0,"RPN  LSB");break;
+    case 101:strcpy(tmp0,"RPN  MSB");break;
+
+    case 120:strcpy(tmp0,"SOND OFF");break;
+    case 121:strcpy(tmp0,"RES.ALL ");break;
+    case 122:strcpy(tmp0,"LOCAL C.");break;    /*local control*/
+    case 123:strcpy(tmp0,"NOTE OFF");break;
+    case 124:strcpy(tmp0,"OMNI OFF");break;
+    case 125:strcpy(tmp0,"OMNI ON ");break;
+    case 126:strcpy(tmp0,"MONO Mod");break;
+    case 127:strcpy(tmp0,"POLY Mod");break;
+
+    default :strcpy(tmp0,"CONTROL ");break;
+  }
+  /*10 30 50 ネニヘムチ犲錥メ h-12341234 5678
+  */
+  cc=(mdlflag&15);
+  /*05rw*/
+  if(cc==0x4){
+    switch(a){
+    case 12 :strcpy(tmp0,"Efect1CT");break;
+    case 13 :strcpy(tmp0,"Efect2CT");break;
+    case 92 :strcpy(tmp0,"Efect1SW");break;
+    case 94 :strcpy(tmp0,"Efect2SW");break;
+    }
+  }
+  /*
+  if(cc==0){
+  switch(a){
+  case 92 :strcpy(tmp0,"Tremolo ");break;
+  case 94 :strcpy(tmp0,"Cereste ");break;
+  case 95 :strcpy(tmp0,"Phaser  ");break;
+  }
+  }
+  */
+  return(tmp0);
+}
+
+/***************************/
+/*
+char   *rcpc_type(int a)
+{
+static char    tmp0[16];
+
+switch( a){
+case  0x90:
+case  0x91:
+case  0x92:
+case  0x93:
+case  0x94:
+case  0x95:
+case  0x96:
+case  0x97:strcpy(tmp0,"UserExc ");tmp0[7]=a-0x90+'0';break;
+case  0x98:strcpy(tmp0,"Tr.Exclu");break;
+
+case  0xc0:strcpy(tmp0,"DX7FUNC");break;
+case  0xc1:strcpy(tmp0,"DX.PARA");break;
+case  0xc2:strcpy(tmp0,"DX.PREF");break;
+case  0xc3:strcpy(tmp0,"TX.FUNC");break;
+
+case  0xc5:strcpy(tmp0,"FB-01 P");break;
+case  0xc6:strcpy(tmp0,"FB-01 S");break;
+case  0xc7:strcpy(tmp0,"TX81Z V");break;
+case  0xc8:strcpy(tmp0,"TX81Z A");break;
+case  0xc9:strcpy(tmp0,"TX81Z P");break;
+case  0xca:strcpy(tmp0,"TX81Z S");break;
+case  0xcb:strcpy(tmp0,"TX81Z E");break;
+case  0xcc:strcpy(tmp0,"DX7-2 R");break;
+case  0xcd:strcpy(tmp0,"DX7-2 A");break;
+case  0xce:strcpy(tmp0,"DX7-2 P");break;
+case  0xcf:strcpy(tmp0,"TX802 P");break;
+
+case  0xd0:strcpy(tmp0,"Yam.Base");break;
+case  0xd1:strcpy(tmp0,"Yam.Para");break;
+case  0xd2:strcpy(tmp0,"Yam.Dev#");break;
+case  0xd3:strcpy(tmp0,"XG Para");break;
+
+case  0xdc:strcpy(tmp0,"MKS-7  ");break;
+case  0xdd:strcpy(tmp0,"Rol.Base");break;
+case  0xde:strcpy(tmp0,"Rol.Para");break;
+case  0xdf:strcpy(tmp0,"Rol.Dev#");break;
+
+case  0xe2:strcpy(tmp0,"BankProg");break;
+
+case  0xe1:strcpy(tmp0,"BnkL&Prg");break;
+case  0xe2:strcpy(tmp0,"BnkM&Prg");break;
+??e4 p.bank?
+case  0xe5:strcpy(tmp0,"KeyScan");break;
+case  0xe6:strcpy(tmp0,"MIDI CH.");break;
+case  0xe7:strcpy(tmp0,"TEMPO");break;
+
+case  0xea:strcpy(tmp0,"AFTER C.");break;
+case  0xeb:strcpy(tmp0,"CONTROL ");break;
+case  0xec:strcpy(tmp0,"PROGRAM ");break;
+case  0xed:strcpy(tmp0,"AFTER K.");break;
+case  0xee:strcpy(tmp0,"PITCH");break;
+case  0xef:strcpy(tmp0,"CMU-800");break;
+f4 *segno?
+case  0xf5:strcpy(tmp0,"Music Key ");break;
+
+default:strcpy(tmp0,fstr(a,7));
+}
+}
+*/
+/***************************/
diff --git a/exception.cpp b/exception.cpp
new file mode 100644 (file)
index 0000000..5a84f53
--- /dev/null
@@ -0,0 +1,81 @@
+#include "stdafx.h"
+#include "exception.h"
+#include <objbase.h>
+#include <wtypes.h>
+#include <winerror.h>
+#include <avrt.h>
+#include <strsafe.h>
+#include <audioclient.h>
+#include <audiopolicy.h>
+
+
+
+#define BOOST_ASSIGN_MAX_PARAMS 7
+#include <boost/assign.hpp>
+#include <boost/assign/ptr_list_of.hpp>
+#include <boost/assign/ptr_list_inserter.hpp>
+#include <boost/foreach.hpp>
+#include "sf_memory.h"
+
+using namespace boost;
+
+namespace sf
+{
+//typedef CComPtr<IAudioClient> IAudioClientPtr;
+std::map<HRESULT,std::wstring> com_error_  = boost::assign::list_of<std::pair<HRESULT,std::wstring> >
+    (E_POINTER,L"E_POINTER")
+    (E_INVALIDARG,L"E_INVALIDARG")
+       (AUDCLNT_E_NOT_INITIALIZED,L"AUDCLNT_E_NOT_INITIALIZED")
+       (AUDCLNT_E_ALREADY_INITIALIZED,L"AUDCLNT_E_ALREADY_INITIALIZED")
+    (AUDCLNT_E_WRONG_ENDPOINT_TYPE,L"AUDCLNT_E_WRONG_ENDPOINT_TYPE")
+       (AUDCLNT_E_DEVICE_INVALIDATED,L"AUDCLNT_E_DEVICE_INVALIDATED")
+       (AUDCLNT_E_NOT_STOPPED,L"AUDCLNT_E_NOT_STOPPED")
+       (AUDCLNT_E_BUFFER_TOO_LARGE,L"AUDCLNT_E_BUFFER_TOO_LARGE")
+       (AUDCLNT_E_OUT_OF_ORDER,L"AUDCLNT_E_OUT_OF_ORDER")
+       (AUDCLNT_E_UNSUPPORTED_FORMAT,L"AUDCLNT_E_UNSUPPORTED_FORMAT")
+       (AUDCLNT_E_INVALID_SIZE,L"AUDCLNT_E_INVALID_SIZE")
+       (AUDCLNT_E_DEVICE_IN_USE,L"AUDCLNT_E_DEVICE_IN_USE")
+       (AUDCLNT_E_BUFFER_OPERATION_PENDING,L"AUDCLNT_E_BUFFER_OPERATION_PENDING")
+       (AUDCLNT_E_THREAD_NOT_REGISTERED,L"AUDCLNT_E_THREAD_NOT_REGISTERED")
+       (AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED,L"AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED")
+       (AUDCLNT_E_ENDPOINT_CREATE_FAILED,L"AUDCLNT_E_ENDPOINT_CREATE_FAILED")
+       (AUDCLNT_E_SERVICE_NOT_RUNNING,L"AUDCLNT_E_SERVICE_NOT_RUNNING")
+       (AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED,L"AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED")
+       (AUDCLNT_E_EXCLUSIVE_MODE_ONLY,L"AUDCLNT_E_EXCLUSIVE_MODE_ONLY")
+       (AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL,L"AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL")
+       (AUDCLNT_E_EVENTHANDLE_NOT_SET,L"AUDCLNT_E_EVENTHANDLE_NOT_SET")
+       (AUDCLNT_E_INCORRECT_BUFFER_SIZE,L"AUDCLNT_E_INCORRECT_BUFFER_SIZE")
+       (AUDCLNT_E_BUFFER_SIZE_ERROR,L"AUDCLNT_E_BUFFER_SIZE_ERROR")
+       (AUDCLNT_S_BUFFER_EMPTY,L"AUDCLNT_S_BUFFER_EMPTY")
+       (AUDCLNT_S_THREAD_ALREADY_REGISTERED,L"AUDCLNT_S_THREAD_ALREADY_REGISTERED");
+       
+
+win32_error_exception::win32_error_exception(boost::uint32_t hr)
+: std::exception("HRESULT ERROR"),hresult_(hr)
+{
+       local_memory<wchar_t> mem;
+       DWORD result = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hr,0,(LPWSTR)&mem,0,0);
+       if(result != 0){
+               error_ = mem.get();
+       } else {
+               std::map<HRESULT,std::wstring>::iterator it = com_error_.find(hr);
+               if(it != com_error_.end())
+               {
+                       error_ = it->second;
+               } else {
+                       error_ = (boost::wformat(L"0x%x 不明なCOMエラー") % hr).str();
+               }
+
+       }
+};
+
+win32_error_exception::win32_error_exception()
+{
+       hresult_ = ::GetLastError();
+       local_memory<wchar_t> mem;
+       DWORD rv =  FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,0,hresult_,0,(LPWSTR)&mem,0,0);
+       error_ = mem.get();
+       //Logger::outputDebugPrintf(L"Win32 Error %x %s",hresult_,mem.Get() );
+};
+
+}
\ No newline at end of file
diff --git a/exception.h b/exception.h
new file mode 100644 (file)
index 0000000..41965ea
--- /dev/null
@@ -0,0 +1,34 @@
+#pragma once
+
+namespace sf
+{
+///Exception
+       class exception : public std::exception
+       {
+       public:
+               explicit exception(const std::wstring& reason)
+               {
+                       m_reason = reason;
+               };
+               const wchar_t * what() {return m_reason.c_str();};
+               const std::wstring& what_str() { return m_reason;};
+       protected:
+               std::wstring m_reason;
+       };
+
+       class win32_error_exception : std::exception 
+       {
+       public:
+               win32_error_exception(boost::uint32_t hr);
+               win32_error_exception();
+
+               virtual ~win32_error_exception() {};
+               boost::uint32_t hresult() {return hresult_;}
+               std::wstring& error() {return error_;}
+       private:
+               boost::uint32_t hresult_;
+               std::wstring error_;
+       };
+
+
+}
\ No newline at end of file
diff --git a/exclu.cpp b/exclu.cpp
new file mode 100644 (file)
index 0000000..12856a4
--- /dev/null
+++ b/exclu.cpp
@@ -0,0 +1,1293 @@
+/*
+ * STed: exclu.c (selecter)
+ */
+
+#include       "sted.h"
+
+static char    uxcc[5][3]={"gt","ve","ch","cs","ss"};
+static char    dotp[4][3]={"・","・","・","・"};
+
+static unsigned char   dotpat[32][32];
+/***************************/
+void   user_exc_as(int no)
+{
+  int  gy,ke,kc,sh,i,x=0,y=no*2,yy,nn,mm,a,cc;
+
+  gy=scyp;
+top:
+  fill(0,512+32,767,1023,0);
+  box(47,47+512,688+24,458+512,14,65535);
+  fill(47,63+512,73,458+512,14);
+  sdis(6,48+512," USER DEFINE EXCLUSIVE",80+3,15,14);
+  home2(512);fnc_dis(4+3);
+  /*
+    [F1] gt : SEND GATE POSITION DATA   [F4] cs : CLEAR CHECK SUM
+    [F2] ve : SEND VELO POSITION DATA   [F5] ss : SEND CHECK SUM
+    [F3] ch : SEND CHANNLE No.          [F6] F7 : END OF EXCLUSIVE
+    */
+
+  for(i=0;i<7;i++){line(47,520+7*16+i*48,688+24,520+7*16+i*48,14,65535);}
+redis:
+  for(i=0;i<8;i++){
+    B_LOCATE(6,5+i*3);B_PRINT(fstr(i,2));
+    B_PRINT("  MEMO:");B_PRINT(user_exc_memo[i]);
+    B_LOCATE(39,5+i*3);B_PRINT("|");
+    user_exc_dis(i);
+  }
+
+  while( 1){
+    nn=y>>1;mm=y&1;yy=nn*3+mm+5;cc=3;
+    B_LOCATE(50,3);
+    if(mm==0){
+      B_PRINT("---");
+      tcur(15,yy,24,3);
+    }else{
+      a=user_exc_data[nn][x];
+      if(a>0x7f){cc=1;B_PRINT("---");}else{B_PRINT(fstr(a,3));}
+      tcur(13+x*3,yy,4,cc);
+    }
+
+    /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+    key_wait();
+    ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
+    if(kc>='a' && kc<='z'){kc-=32;}
+    if(mm==0){tcur(15,yy,24,3);}else{tcur(13+x*3,yy,4,cc);}
+
+
+    if( (ke>=0x40 && ke<=0x51) && (sh&4)!=0 ){
+      int      j;
+
+      static char tk[18]={13,14,15,7,8,9,16,4,5,6,17,1,2,3,18,10,11,12};
+
+      j=tk[ke-0x40];
+      if( j>0 && j<=7){y=j*2;kc=0;ke=0;}
+    }
+
+
+    if( ke==1 ){break;}
+    if( ke==0x3f ){
+      msg(_("Init all exclusive data"));
+      if(yn_sel()>0){msg_clr();user_exc_init();C_CLS_AL();goto redis;}
+    }
+    if( kc==32 ){
+      user_exc_init2(nn);C_CLS_AL();goto redis;
+    }
+    if( kc==13 ){
+      if(sh&1){
+       if(mm!=0){
+         excins(user_exc_data[nn],23,x);
+         user_exc_data[nn][x]=0;
+         user_exc_dis(nn);
+       }
+      }else{
+       if(mm==0){
+         B_LOCATE(15,yy);sinput(user_exc_memo[nn],24);
+         fnc_dis(4+3);
+       }else{
+         int   c;
+         B_LOCATE(14+x*3,yy);
+         c=vinput(0,0x2003);
+         if(es==0 && c>=0 && c<128){
+           excins(user_exc_data[nn],23,x);
+           user_exc_data[nn][x]=c;
+         }
+         user_exc_dis(nn);ke=0x3d;kc=0;
+       }
+      }
+    }
+
+    if(mm!=0){
+      if((kc>='0'&& kc<='9')||(kc>='A'&& kc<='F')){
+       int     c,cc;
+       B_LOCATE(14+x*3,yy);
+       if(kc<'A'){cc=kc-'0';}else{cc=kc-'A'+10;}
+       c=vinput(cc,0x2003);
+
+       if(es==0 && c>=0 && c<128){
+         if( (B_SFTSNS()&4096)!=0 || user_exc_data[nn][x]==0xf7){
+           excins(user_exc_data[nn],23,x);
+         }
+         user_exc_data[nn][x]=c;
+         ke=0x3d;kc=0;
+       }
+       user_exc_dis(nn);
+      }
+      if((kc=='+' || kc=='.' || kc=='>') && a<128){
+       if( kc=='>' ){a+=16;}else{a++;}
+       user_exc_data[nn][x]=a&127;
+       user_exc_dis(nn);ke=0;kc=0;
+      }
+      if((kc=='-' || kc==',' || kc=='<') && a<128 ){
+       if( kc=='<' ){a+=112;}else{a+=127;}
+       user_exc_data[nn][x]=a&127;
+       user_exc_dis(nn);ke=0;kc=0;
+      }
+
+      if( ke==0x37 || kc==7 ){
+       excdel(user_exc_data[nn],23,x);
+       user_exc_data[nn][23]=0xf7;
+       user_exc_dis(nn);
+      }
+      if( x>0 &&(ke==0x0f ||kc==8)){
+       x--;
+       excdel(user_exc_data[nn],23,x);
+       user_exc_data[nn][23]=0xf7;
+       user_exc_dis(nn);
+      }
+      if( ke>=0x63 && ke<=0x67){
+       excins(user_exc_data[nn],23,x);
+       user_exc_data[nn][x]=ke-0x63+0x80;
+       user_exc_dis(nn);
+      }
+      if( ke==0x68){
+       user_exc_data[nn][x]=0xf7;
+       user_exc_dis(nn);
+      }
+
+      if( ke==0x6a && x>5){
+       excins(user_exc_data[nn],23,x);
+       excsum(user_exc_data[nn],x);
+       user_exc_dis(nn);
+      }
+
+      if( ke==0x10 /*|| ke==0x35*/ ){
+       unsigned char c=user_exc_data[nn][x];
+       excins(user_exc_data[nn],23,x);
+       user_exc_data[nn][x]=c;
+       user_exc_dis(nn);
+      }
+
+    }
+
+    if( kc=='U' || kc=='u' ){
+      int      c,i;
+      msg("User Exc. No.=");
+      c=vinput(0,0x803);msg_clr();
+      if(es==0 && c>=0 && c<8){
+       for(i=0;i<24;i++){
+         user_exc_data[nn][i]=user_exc_data[c][i];
+         user_exc_memo[nn][i]=user_exc_memo[c][i];
+       }
+       goto redis;
+      }
+    }
+
+    if( ke==0x6b ){
+      char     tmp0[256],tmp1[256],path2[256];
+
+      C_CLS_AL();
+
+      strcpy(path2,prt_path);tmp1[0]=0;
+      fsel(tmp1,path2,0x009+(sh&1));
+      if( es==0 && tmp1[0]!=0){
+       int ec;
+       strcpy(tmp0,path2);strcat(tmp0,tmp1);
+
+       msg(_("Loading Usr.Exc. file."));
+       if((sh&1)==0){
+         ec=rex_load(tmp0,-1);
+       }else{
+         ec=rex_load(tmp0,nn);
+       }
+       if(ec==0 ){msg_clr();
+       if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+       }
+      }
+      goto top;
+    }
+    if( ke==0x6c ){
+      char     tmp0[256],tmp1[256],path2[256];
+
+      C_CLS_AL();
+
+      strcpy(path2,prt_path);tmp1[0]=0;
+      fsel(tmp1,path2,0x109+(sh&1));
+      if( es==0 && tmp1[0]!=0){
+       int     ec;
+       strcpy(tmp0,path2);strcat(tmp0,tmp1);
+
+       msg(_("Saving Usr.Exc. file."));
+       if((sh&1)==0){
+         ec=rex_save(tmp0,-1);
+       }else{
+         ec=rex_save(tmp0,nn);
+       }
+       if(ec==0 ){msg_clr();
+       if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+       }
+      }
+      goto top;
+    }
+
+    if( kc==0x13 || ke==0x3b){x--;if(x<0){x=23;}}
+    if( kc==0x04 || ke==0x3d){x++;if(x>23){x=0;}}
+    if( kc==0x05 || ke==0x3c){y--;if(y<0){y=15;}}
+    if( kc==0x18 || ke==0x3e){y++;if(y>15){y=0;}}
+
+  }
+  fnc_dis(-1);C_CLS_AL();home2(gy);
+}
+
+/***************************/
+void   user_exc_dis(int no)
+{
+  int  i,a;
+
+  B_LOCATE(11,6+no*3);
+  B_COLOR(9);B_PRINT("F0");B_COLOR(3);
+
+  i=0;
+  while(i<24 && user_exc_data[no][i]!=0xf7){
+    B_PRINT(" ");
+    a=user_exc_data[no][i++];
+
+    if(a>=0x80 && a<=0x84){
+      B_COLOR(1);B_PRINT(uxcc[a-0x80]);
+    }else{
+      B_COLOR(3);B_PRINT(hex_s(a,2));
+    }
+
+  }
+  B_PRINT(" ");B_COLOR(9);B_PRINT("F7");B_COLOR(1);
+  while(i<24 ){user_exc_data[no][i++]=0xf7;B_PRINT(" ..");}
+  B_COLOR(3);snsclr();
+}
+
+/***************************/
+void   exc_edit(int ad,int cy,int sw)
+{
+  int  ke,sh,kc,i,x=0,y=0,cx,gx,a,cc,co,po,nn;
+  int  e=edit_scr;
+  unsigned char        *buf;buf=dat+(16*1024);
+
+  trk_dis(cy+6,ad,24-cy);
+
+  if(edit_scr==0){cx=41;gx=328;}else{cx=1;gx=8;}
+  cons_md(0);noed_cls();edit_scr=0;
+
+top0:
+  for(i=0;i<32*1024;i++){dat[i]=0xf7;}
+
+  po=ad;co=0;
+  while(trk[track][po+4]==0xf7){po+=4;
+  dat[co]=trk[track][po+2];if(dat[co]==0xf7){break;}
+  co++;
+  dat[co]=trk[track][po+3];if(dat[co]==0xf7){break;}
+  co++;
+  }
+
+top:
+  box(gx-1,624-48,gx+417+16,997,14,65535);
+  fill(gx,639-32,gx+15,996,8);
+  fill(gx,639-40,gx+416+16,639-16-8,8);
+  sdis(cx,624-48," TRACK EXCLUSIVE EDIT",54,15,14);
+  for(i=0;i<22;i++){tdis(cx,7+i,hex_s(i,2),2,3);}
+  for(i=0;i<16;i++){sdis(cx+i*3+7,512+6*16-8,hex_s(i,1),1,3,8);}
+  fnc_dis(4);
+
+  if(sw&6){co=dot_ed(cx,co);ke=0;goto ext;}
+
+  exc_dis(i,cx,co,0);
+
+  while( 1){
+    cc=3;nn=y*16+x;
+    a=dat[nn];
+
+    B_LOCATE(cx+29,4);if(a>0x7f){cc=1;B_PRINT("---");}else{B_PRINT(fstr(a,3));}
+
+    tcur(cx+5+x*3,y+7,4,cc);
+    /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+    key_wait();
+    ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
+    if(kc>='a' && kc<='z'){kc-=32;}
+    tcur(cx+5+x*3,y+7,4,cc);
+
+    if( ke==1 ){break;}
+
+    if( kc==13 ){
+      if(sh&1){
+       excins(dat,co,nn);
+       dat[nn]=0;co++;
+       exc_dis(y,cx,co,1);ke=0x3d;kc=0;
+      }else{
+       if( co<256+96 && nn<=co ){
+         int   c;
+         B_LOCATE(cx+5+x*3,y+7);
+         c=vinput(0,0x2003);
+         if(es==0 && c>=0 && c<128){
+           excins(dat,co,nn);
+           dat[nn]=c;co++;
+         }
+         exc_dis(y,cx,co,1);ke=0x3d;kc=0;
+       }
+      }
+    }
+
+    if(((kc>='0'&& kc<='9')||(kc>='A'&& kc<='F'))&& co<256+96 && nn<=co){
+      int      c,cc;
+      B_LOCATE(cx+5+x*3,y+7);
+      if(kc<'A'){cc=kc-'0';}else{cc=kc-'A'+10;}
+      c=vinput(cc,0x2003);
+
+      if(es==0 && c>=0 && c<128){
+       if( (B_SFTSNS()&4096)!=0 || dat[nn]==0xf7){
+         excins(dat,co,nn);co++;
+       }
+       dat[nn]=c;
+       ke=0x3d;kc=0;
+      }
+      exc_dis(y,cx,co,1);
+    }
+
+    if((kc=='+' || kc=='.' || kc=='>') && a<128){
+      if( kc=='>' ){a+=10;}else{a++;}
+      dat[nn]=a&127;
+      exc_dis(y,cx,co,2);ke=0;kc=0;
+    }
+    if((kc=='-' || kc==',' || kc=='<') && a<128){
+      if( kc=='<' ){a+=118;}else{a+=127;}
+      dat[nn]=a&127;
+      exc_dis(y,cx,co,2);ke=0;kc=0;
+    }
+
+    if( ke==0x37 || kc==7 ){
+      excdel(dat,co,nn);
+      if(nn<co){co--;dat[co]=0xf7;}
+      exc_dis(y,cx,co,1);
+    }
+    if( nn>0 && (ke==0x0f || kc==8)){
+      nn--;
+      excdel(dat,co,nn);
+      if(nn<co){co--;dat[co]=0xf7;}
+      exc_dis(y,cx,co,1);ke=0x3b;
+    }
+    if( ke>=0x63 && ke<=0x67 && co<256+96){
+      excins(dat,co,nn);
+      dat[nn]=ke-0x63+0x80;
+
+      if(nn<co+1){co++;}
+      exc_dis(y,cx,co,1);
+    }
+    if( ke==0x68){
+      dat[y*16+x]=0xf7;exc_dis(y,cx,co,0);
+    }
+    if( ke==0x6a && co<256+96 && nn>5){
+      excins(dat,co,nn);
+      excsum(dat,nn);
+      if(nn<co+1){co++;}
+      exc_dis(y,cx,co,1);
+    }
+
+    if( ke==0x10 && co<256+96){
+      unsigned char c=dat[nn];
+      excins(dat,co,nn);
+      dat[nn]=c;
+      if(nn<co+1){co++;}
+      exc_dis(y,cx,co,1);
+    }
+
+    if( kc=='$' && co<256+96){
+      char     tmp0[64];
+      int      i=0;
+
+      tmp0[0]=0;
+      msg("strings:");sinput(tmp0,0x8000+32);
+      if( es==0 && tmp0[0]!=0){
+       while(tmp0[i]!=0 && co<256+96){
+         excins(dat,co,nn);
+         if(tmp0[i]<32){dat[nn]=32;}else{dat[nn]=tmp0[i];}
+
+         if(nn<co+1){co++;}
+         i++;
+         exc_dis(y,cx,co,1);
+
+         x++;
+         if(x>15){if(y<21){x=0;y++;}else{x=15;}}
+         nn=y*16+x;
+       }
+      }
+    }
+
+    if( kc=='^' || ke==0x34 ){co=dot_ed(cx,co);x=0;y=0;goto top;}
+
+    if( kc=='U' || kc=='u' ){
+      int      c,i;
+      msg("User Exc. No.=");
+      c=vinput(0,0x803);msg_clr();
+      if(es==0 && c>=0 && c<8){
+       for(i=0;i<24;i++){
+         dat[i]=user_exc_data[c][i];
+       }
+       dat[24]=0xf7;
+
+       co=0;
+       while( dat[co] != 0xf7 && co<24) {co++;}
+       dat[co++]=0xf7;
+
+       goto top;
+      }
+    }
+
+    if( ke==0x6b ){
+      char     tmp0[256],tmp1[256],path2[256];
+
+      txerase(cx*8,4*16,53*8,26*16);
+
+      strcpy(path2,prt_path);tmp1[0]=0;
+      fsel(tmp1,path2,0x008+e*0x200);
+      if( es==0 && tmp1[0]!=0){
+       int ec;
+       strcpy(tmp0,path2);strcat(tmp0,tmp1);
+
+       msg(_("Loading Exclusive file."));
+       ec=exc_load(tmp0);
+       if(ec>=0 ){msg_clr();
+       if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+       co=ec;ke=0xff;break;}
+      }
+      goto top;
+    }
+    if( ke==0x6c ){
+      char     tmp0[256],tmp1[256],path2[256];
+
+      txerase(cx*8,4*16,53*8,26*16);
+
+      strcpy(path2,prt_path);tmp1[0]=0;
+      fsel(tmp1,path2,0x108+e*0x200);
+      if( es==0 && tmp1[0]!=0){
+       int ec;
+       strcpy(tmp0,path2);strcat(tmp0,tmp1);
+
+       msg(_("Saving Exclusive."));
+       ec=exc_save(tmp0,co);
+       if(ec>=0 ){msg_clr();
+       if(!(cnfflag&0x0008)){strcpy(prt_path,path2);}
+       }
+      }
+      goto top;
+    }
+    /*
+      if( kc=='R' || kc=='r' ){
+      int ec;
+
+      msg("MIDI IN Exclusive INPUT");
+
+      ec=exc_rec();
+      if(ec>=0 ){msg_clr();
+      co=ec;ke=0xff;break;}
+
+      goto top;
+      }
+      */
+
+    if( ke==0x3a && co>0){break;}
+
+    if( ke==0x36){x=0;y=0;}
+
+
+
+    if(kc=='@'){
+      /*
+       0x10 0x01~5 0x00 / 0x10 0x01~5 0x40
+       */
+      if( dat[0]==0x41 && dat[1]==0x10 && dat[2]==0x45 && dat[3]==0x12 &&
+         dat[4]==0x83 && dat[5]==0x10 ){
+       if(dat[7]==0x00){
+         if(dat[6]>0){
+           prn_gspanel(cx);scpanel_dsp(cx+13,18,&dat[8]);
+         }else{
+           prn_gspanel(cx);scinst_dsp(cx+13,16,&dat[8]);
+         }
+         while(inkey2()==0){}
+         goto top;
+       }
+      }
+    }
+
+
+
+    if( kc==0x13 || ke==0x3b){x--;
+    if(x<0){if(y>0){x=15;ke=0x3c;}else{x=0;}}
+    }
+    if( kc==0x04 || ke==0x3d){x++;
+    if(x>15){if(y<21){x=0;ke=0x3e;}else{x=15;}}
+    }
+    if( kc==0x05 || ke==0x3c){y--;if(y<0){y=21;}}
+    if( kc==0x18 || ke==0x3e){y++;if(y>21){y=0;}}
+  }
+ext:
+
+  dat[co]=0xf7;co++;if(co&1){dat[co]=0xf7;co++;}
+  if(dat[0]==0xf7){co=0;}
+  po=ad;cc=0;while(trk[track][po+4]==0xf7){po+=4;cc+=4;}
+
+  {
+    unsigned char      c1,c2;
+    int bc=0,i=0;
+
+    while(i<co){
+      c1=dat[i];c2=dat[i+1];
+      buf[bc]=0xf7;buf[bc+1]=0;buf[bc+2]=c1;buf[bc+3]=c2;
+
+      if(c1==0xf7){buf[bc+3]=0xf7;}
+
+      if(c1==0xf0 || c2==0xf0){
+       if(c1==0xf0){
+         buf[bc+2]=0xf7;buf[bc+3]=0xf7;
+         i-=1;
+       }else{
+         buf[bc+3]=0xf7;
+       }
+       bc+=4;
+       buf[bc]=0x98;buf[bc+1]=0;
+       buf[bc+2]=0;buf[bc+3]=0;
+      }
+      bc+=4;i+=2;
+    }
+
+    if(bc<=cc || trk_check(bc-cc)==0){
+      int      po=ad+4,i;
+
+      trk_delete(po,cc);trk_shift(po,bc);
+      for(i=0;i<bc;i++){trk[track][po+i]=buf[i];}
+
+      if( ke==0x3a ){poplay(ad,8);
+      if( (sh&1)!=0 ){
+       twait(50);
+       if( rcd->flg_gsinfo || rcd->flg_gsinst || rcd->flg_gspanel ) {
+         prn_gspanel(cx);
+         if( rcd->flg_gsinfo) {
+           rcd->flg_gsinfo=0;
+           scinst_dsp(cx+13,16,(uint8 *)rcd->gs_info);
+         }
+         if( rcd->flg_gsinst) {
+           rcd->flg_gsinst=0;
+           scinst_dsp(cx+13,16,(uint8 *)rcd->gs_inst);
+         }
+         if( rcd->flg_gspanel ) {
+           rcd->flg_gspanel=0;
+           scpanel_dsp(cx+13,18,(uint8 *)rcd->gs_panel);
+         }
+         while(inkey2()==0){}
+       }
+      }
+      }
+    }
+  }
+
+  if( ke==0x3a || ke==0xff ){goto top0;}
+
+  edit_scr=e;
+  fnc_dis(0);/*txerase(cx*8,4*16,53*8,26*16);*/
+  noed_cls_t();
+  noed_cls();
+  cons_md(1);
+
+
+}
+
+void   excsum(unsigned char *da,int nn)
+{
+  int  top=4,i,sum=0;
+
+  if(da[0]==0x43){top--;}
+  for(i=top;i<nn;i++){sum+=da[i];}
+  da[nn]=(128-(sum & 0x7f))&0x7f;
+}
+
+void   excins(unsigned char *da,int co,int nn)
+{
+  int  i;
+
+  for(i=co;i>nn;i--){da[i]=da[i-1];}
+}
+
+void   excdel(unsigned char *da,int co,int nn)
+{
+  int  i;
+
+  for(i=nn;i<co;i++){da[i]=da[i+1];}
+}
+
+/************************** RCM2  MAX=263 +9+1  272*/
+void   exc_dis(int no,int cx,int co,int m)
+{
+  int  i,a=0;
+
+  B_LOCATE(cx+3,7);B_COLOR(9);B_PRINT("F0");B_COLOR(3);
+
+  if(m==0){no=0;}
+
+  while(no<=16+6){
+    int nn=no*16;
+
+    if(m!=0 && nn!=co+1 && a==0xf7){break;}
+
+    B_LOCATE(cx+5,7+no);
+
+    i=0;
+    while(i<16 && nn<=co){
+      B_PRINT(" ");
+      a=dat[nn++];i++;
+
+      if(a>=0x80 && a<=0x84){
+       B_COLOR(1);B_PRINT(uxcc[a-0x80]);
+      }else{
+       if(a<0x80){B_COLOR(3);}else{B_COLOR(9);}
+       B_PRINT(hex_s(a,2));if(a>=0x80){B_COLOR(3);}
+      }
+
+      if(a==0xf7){break;}
+    }
+    B_COLOR(1);
+    while(i<16 && nn<=256+96){dat[nn++]=0xf7;B_PRINT(" ..");i++;}
+    if(m==2){break;}
+    no++;
+  }
+  B_COLOR(3);snsclr();
+}
+
+/**************************19971028/29/30*/
+/*
+  int  exc_rec()
+  {
+  unsigned char        buf[8*1024];
+  int  ad,ln,pp,cc,a,bpo,i,fl;
+
+  all_note_off(1);hedset(36);bpo=rcp_buf_put(hed,0,1414);
+  for(i=0;i<36;i++){thedset(i,48);hed[44]=0xfe;bpo=rcp_buf_put(hed,bpo,48);}}
+  rcd->fmt=2;rcd->totalcount=bpo;
+  rcd->data_valid=1;rcd->word_valid=0;rcd->tone_valid=0;rcd->gsd_valid=0;
+
+  (*rcd->init)();midi_clr();
+
+  ln=0;
+
+  while(1){
+  a=(*rcd->md_get)();
+  if(a>=0 && a<0xf8){
+  if( INPOUT(0xfe)!=0 ){if(INPOUT(0xff)==27){break;}}
+
+  if(a==0xf0){fl=1;}
+  if(fl){dat[ln++]=a;}
+  if(a==0xf7){fl=0;}
+
+  if(ln>=32*1024+512){msg("バッファが一杯になりました");break;}
+  }
+  }
+
+  strcpy(buf,dat,ln);
+  pp=0;cc=0;
+
+  while( buf[pp]==0xf0 && pp<ln) {
+  if(cc==0){pp++;}
+  while( buf[pp] != 0xf7 && pp<ln) {dat[cc++]=buf[pp++];}
+  pp++;
+  }
+  dat[cc]=0xf7;
+
+  return(cc);
+  }
+  */
+/***************************/
+int    exc_load(char *fna)
+{
+  char tmp0[2048],li[1024];
+  unsigned char        buf[8*1024];
+
+  int  ad,ln,n,j,pp,cc;
+  unsigned char        a;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+  ln=fread(dat,1,32*1024,fp);fclose(fp);
+  j=0;ad=0;
+
+  while(ln>0){
+    n=0;
+    while(1){
+      a=dat[ad++];
+      if(ad>=ln){ln=fread(dat,1,32*1024,fp);ad=0;if(ln==0){break;}}
+      if(a<32){
+       if(a==13){break;}
+       a=32;
+      }else{
+       if(a=='*'){a=0;}
+      }
+      li[n++]=a;
+    }
+    li[n]=0;li[1023]=0;
+    if(dat[ad]==0x0a){ad++;
+    if(ad>=ln){ln=fread(dat,1,32*1024,fp);ad=0;}
+    }
+
+    spcut(li);
+    if( li[0]!=0 ){
+      char     tmp9[128];
+      int      i=0;
+
+      strcpy(tmp0,li);jstrupr(tmp0);
+      spcut(tmp0);
+
+      while(i<strlen(tmp0)){
+       int     a;
+       if(tmp0[i]==32){i++;}else{
+         strcpy(tmp9,&tmp0[i]);
+         if(tmp9[1]==0){
+           tmp9[1]='H';tmp9[2]=0;
+         }else{
+           tmp9[2]='H';tmp9[3]=0;
+         }
+         a = str_val(tmp9);
+    tmp9[2]=0;
+         if(strcmp(tmp9,"GT")==0){a=0x80;}
+         if(strcmp(tmp9,"VE")==0){a=0x81;}
+         if(strcmp(tmp9,"CH")==0){a=0x82;}
+         if(strcmp(tmp9,"CS")==0){a=0x83;}
+         if(strcmp(tmp9,"SS")==0){a=0x84;}
+
+         buf[j++]=a;if(j>=8*1024){goto skip;}
+         i=i+2;
+       }
+      }
+    }
+  }
+skip:
+  fclose(fp);
+
+  pp=0;cc=0;
+
+  while( buf[pp]==0xf0 && pp<j) {
+    if(cc==0){pp++;}
+    while( buf[pp] != 0xf7 && pp<j) {dat[cc++]=buf[pp++];}
+    pp++;
+  }
+  dat[cc]=0xf7;
+
+  return(cc);
+}
+
+/***************************/
+int    exc_save(char *fna,int co)
+{
+  int  sz,i;
+  unsigned char        buf[4096];
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+
+  strcpy((char *)buf,"F0 ");
+  dat[co++] = 0xf7;
+
+  for(i=0;i<co;i++){
+    unsigned char a=dat[i];
+
+    if(a>=0x80 && a!=0xf7){
+      if(a>=0x80 && a<=0x84){strcat((char *)buf,uxcc[a-0x80]);strcat((char *)buf," ");}
+
+      if(a==0xf0){
+       strcat((char *)buf,"F7\r\n\r\n");
+       fwrite(buf,1,strlen((char *)buf),fp);
+  buf[0]=0;
+       strcat((char *)buf,"F0 ");
+      }
+    }else{
+      strcat((char *)buf,hex_s(dat[i],2));
+      strcat((char *)buf," ");
+    }
+
+    sz=strlen((char *)buf);
+    if(sz>=16*3){
+      buf[sz-1]=0;strcat((char *)buf,"\r\n");
+      fwrite(buf,1,sz+1,fp);
+      buf[0]=0;
+    }
+  }
+  strcat((char *)buf,"\r\n");
+  fwrite(buf,1,strlen((char *)buf),fp);
+  fclose(fp);
+
+  return(0);
+}
+
+/***************************/
+void prn_gspanel( int cx )
+{
+  struct       X68_TXFILLPTR   *t,buf;
+
+  t=&buf;
+
+  t->x = (cx+11)*8  ;t->y = 15*16+8;t->x1 = 36*8;t->y1 = 9*16;
+  t->vram_page = 0;t->fill_patn = 0xffff;TXFILL( t );
+  t->vram_page = 1;t->fill_patn = 0x0000;TXFILL( t );
+
+  t->x = (cx+11)*8+2;t->y = 15*16+8+2;t->x1 = 36*8-4;t->y1 = 9*16-4;
+  t->vram_page = 0;t->fill_patn = 0x0000;TXBOX( t );
+
+  t->x = (cx+13)*8  ;t->y = 18*16;t->x1 = 32*8;t->y1 = 6*16;
+  t->vram_page = 0;t->fill_patn = 0x0;TXFILL( t );
+  t->vram_page = 1;t->fill_patn = 0xffff;TXFILL( t );
+
+  /*t->x = (cx+13)*8*/  ;t->y = 16*16;t->x1 = 32*8;t->y1 = 16;
+  t->vram_page = 0;t->fill_patn = 0x0;TXFILL( t );
+  t->vram_page = 1;t->fill_patn = 0xffff;TXFILL( t );
+
+}
+
+/***************************/
+
+/***************************/
+/*970112 bar display edit*/
+int    dot_ed(int dx,int co)
+{
+  int  ke,kc,sh,cx,cy,i,j,gx,pmode=1;
+  int  msf=-1;
+
+  for(i=0;i<16;i++){for(j=0;j<16;j++){dotpat[i][j]=0;}}
+
+  /*           0x10 0x01~5 0x00 / 0x10 0x01~5 0x40 */
+
+  if( dat[0]==0x41 && dat[1]==0x10 && dat[2]==0x45 && dat[3]==0x12 &&
+      dat[4]==0x83 && dat[5]==0x10 && dat[6]>0 && dat[7]==0x00){
+    dattopat(0);
+  }else{
+    if(co==0){
+      dat[0]=0x41;dat[1]=0x10;dat[2]=0x45;dat[3]=0x12;
+      dat[4]=0x83;dat[5]=0x10;dat[6]=1;dat[7]=0x00;
+    }else{
+      msg(_("Not a GS BAR DISPLAY DATA."));return co;
+    }
+  }
+
+  gx=dx*8;
+  cx=0;cy=0;
+
+  txerase(dx*8,15*16,53*8,15*16);
+  fill(gx+31-8,512+240,gx+360+32,995,0);
+
+  box(gx+31-8,512+240+8,gx+360+64,995-6,14,65535);
+  sdis(dx+4-1,512+240+8," GS BAR DISPLAY EDIT",48+2,15,14);
+
+  if(cnfflag&0x8000){
+    fill(gx+64-16,512+288-16,gx+63+16*16+16,512+287+8*16+16,14);
+    fill(gx+64   ,512+288   ,gx+63+16*16   ,512+287+8*16   ,0);
+
+    for(i=0;i<17;i++){
+      line(gx+64,512+287+i*8, gx+63+16*16,512+287+i*8, 4,65535);
+      line(gx+63+i*16,512+288, gx+63+i*16,512+287+8*16, 4,65535);
+    }
+    B_COLOR(3);
+  }else{
+    /*         GPALET(2,0x97c0);
+               TPALET(2,0x7700);*/
+
+    GPALET(2,0x7700);
+    TPALET(2,0x4400);
+
+    fill(gx+64-16,512+288-16,gx+63+16*16+16,512+287+8*16+16,14-12);
+    fill(gx+64   ,512+288   ,gx+63+16*16   ,512+287+8*16   ,0);
+
+    for(i=0;i<17;i++){
+      line(gx+64,512+287+i*8, gx+63+16*16,512+287+i*8, 4-2,65535);
+      line(gx+63+i*16,512+288, gx+63+i*16,512+287+8*16, 4-2,65535);
+    }
+    B_COLOR(2);
+  }
+
+  fnc_dis(-1);
+
+  dot_dis(dx);
+  if((cmdflag&0x200)==0){
+    MS_INIT();MS_LIMIT(gx,80,gx+432,511-16-8);MS_CURON();
+  }
+
+  while( 1){
+    int ma=0,mx,my;
+    /*top:*/
+    box(gx+cx*16+63,cy*8+287+512,gx+63+cx*16+16,cy*8+287+512+8,6,65535);
+    /*
+      B_LOCATE(dx+8,26);B_PRINT("X=");B_PRINT(fstr(cx,2));
+      B_LOCATE(dx+8,27);B_PRINT("Y=");B_PRINT(fstr(cy,2));
+      */
+    while(B_KEYSNS()==0){
+      /*ma=MS_GETDT()&0xff00;mx=MS_CURGT();my=mx&0xffff;mx=mx>>16;*/
+      ma=MS_GETDT()&0xff00;mspos(&mx,&my);
+      if(ma==0){msf=-1;}
+      if(ma /*&& msf!=0*/){break;}
+      if(BITSNS(14)&12){break;}
+    }
+
+    ke=0;kc=0;sh=B_SFTSNS();
+    if(B_KEYSNS()!=0){
+      ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;
+    }
+
+    if(cnfflag&0x8000){
+      box(gx+cx*16+63,cy*8+287+512,gx+63+cx*16+16,cy*8+287+512+8,4,65535);
+    }else{
+      box(gx+cx*16+63,cy*8+287+512,gx+63+cx*16+16,cy*8+287+512+8,4-2,65535);
+    }
+
+    if(ma!=0 && msf!=0){
+      ke=0;kc=0;msf=0;mx-=gx;
+      if(mx>=8*8 && mx<8*8+16*16 && my>=18*16 && my<18*16+8*16 ){
+       cx=(mx-8*8)>>4;cy=(my-18*16)>>3;
+       pmode=1-dotpat[cx][cy];goto skip;
+      }
+    }
+    if(ma!=0 && msf==0){
+      int a;
+      ke=0;kc=0;msf=0;mx-=gx;
+      if(mx>=8*8 && mx<8*8+16*16 && my>=18*16 && my<18*16+8*16 ){
+       cx=(mx-8*8)>>4;cy=(my-18*16)>>3;
+      skip:
+       dotpat[cx][cy]=pmode;
+       B_LOCATE(dx+8+cx*2,(cy>>1)+18);
+       /*                              B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
+       a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
+       if(cnfflag&0x8000){a=3-a;}
+       B_PRINT(dotp[a]);
+
+      }
+    }
+
+    if( ke==1 || ke==0x34 ){
+      pattodat(0);
+      break;
+    }
+
+    if( ke==0x3a ){
+      char buf[128];
+      int sum=0;
+      pattodat(0);
+      buf[0]=0xf0;
+
+      for(i=0;i<4;i++){buf[i+1]=dat[i];}
+      for(i=5;i<72;i++){buf[i]=dat[i];sum=sum+dat[i];}
+      buf[72]=(128-(sum&0x7f))&0x7f;
+      buf[73]=0xf7;buf[74]=0xff;
+
+      (*rcd->mix_out)(buf);
+    }
+
+    if( kc==0x13||ke==0x3b ||ke==0x43||ke==0x47||ke==0x4B ){cx--;if(cx<0){cx=15;}}
+    if( kc==0x04||ke==0x3d ||ke==0x45||ke==0x49||ke==0x4D ){cx++;if(cx>15){cx=0;}}
+    if( kc==0x05||ke==0x3c ||ke==0x43||ke==0x44||ke==0x45 ){cy--;if(cy<0){cy=15;}}
+    if( kc==0x18||ke==0x3e ||ke==0x4B||ke==0x4C||ke==0x4D ){cy++;if(cy>15){cy=0;}}
+    /*
+      if( ke==0x36 ){cx=0;cy=0;}
+      */
+    if( (sh&4)!=0 ){
+      int a;
+      dotpat[cx][cy]=1;
+      B_LOCATE(dx+8+cx*2,(cy>>1)+18);
+      /*B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
+      a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
+      if(cnfflag&0x8000){a=3-a;}
+      B_PRINT(dotp[a]);
+    }
+    if( (sh&8)!=0 ){
+      int a;
+      dotpat[cx][cy]=0;
+      B_LOCATE(dx+8+cx*2,(cy>>1)+18);
+      /*B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
+      a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
+      if(cnfflag&0x8000){a=3-a;}
+      B_PRINT(dotp[a]);
+    }
+
+    if( kc==' ' ){
+      int a;
+      dotpat[cx][cy]=1-dotpat[cx][cy];
+      B_LOCATE(dx+8+cx*2,(cy>>1)+18);
+      /*B_PRINT(dotp[dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2]);*/
+      a=dotpat[cx][cy&14]+dotpat[cx][(cy&14)+1]*2;
+      if(cnfflag&0x8000){a=3-a;}
+      B_PRINT(dotp[a]);
+    }
+
+    if( kc=='G' || kc=='g' ){
+      dattopat(0);dot_dis(dx);
+    }
+
+    if( ke==0x3f ){
+      for(i=0;i<16;i++){for(j=0;j<16;j++){dotpat[i][j]=0;}}
+      dot_dis(dx);
+    }
+
+    if( kc=='R' || kc=='r'){
+      for(i=0;i<16;i++){for(j=0;j<16;j++){dotpat[i][j]=1-dotpat[i][j];}}
+      dot_dis(dx);
+    }
+
+
+    if( sh&2 ){
+      if( ke==0x3b ){
+       for(j=0;j<16;j++){
+         int a=dotpat[0][j];
+         for(i=0;i<15;i++){dotpat[i][j]=dotpat[i+1][j];}
+         dotpat[15][j]=a;
+       }
+       dot_dis(dx);ke=0;
+      }
+      if( ke==0x3d ){
+       for(j=0;j<16;j++){
+         int a=dotpat[15][j];
+         for(i=15;i>0;i--){dotpat[i][j]=dotpat[i-1][j];}
+         dotpat[0][j]=a;
+       }
+       dot_dis(dx);ke=0;
+      }
+      if( ke==0x3c ){
+       for(j=0;j<16;j++){
+         int a=dotpat[j][0];
+         for(i=0;i<15;i++){dotpat[j][i]=dotpat[j][i+1];}
+         dotpat[j][15]=a;
+       }
+       dot_dis(dx);ke=0;
+      }
+      if( ke==0x3e ){
+       for(j=0;j<16;j++){
+         int a=dotpat[j][15];
+         for(i=15;i>0;i--){dotpat[j][i]=dotpat[j][i-1];}
+         dotpat[j][0]=a;
+       }
+       dot_dis(dx);ke=0;
+      }
+    }
+
+
+    if( ke>=0x63 && ke<=0x67 ){
+      dot_ctrl(ke-0x63);
+      dot_dis(dx);
+    }
+
+  }
+
+  B_COLOR(3);
+  txerase(dx*8+8,15*16,42*8,15*16);
+  fill(gx+31-8,512+240,gx+360+64,995,0);
+  dpl(1);
+  tpl(1);
+  fnc_dis(4);
+
+  if((cmdflag&0x200)==0){
+    MS_LIMIT(0,0,767,511);MS_CUROF();
+  }
+  return 66+8;
+}
+
+/***************************/
+void   dot_ctrl(int m)
+{
+  int i,j;
+  int dot2[16][16];
+
+  if( m==0 ){
+    for(j=0;j<16;j++){
+      for(i=0;i<8;i++){
+       int a;
+       a=dotpat[j][i];
+       dotpat[j][i]=dotpat[j][15-i];
+       dotpat[j][15-i]=a;
+      }
+    }
+  }
+  if( m==1 ){
+    for(j=0;j<16;j++){
+      for(i=0;i<8;i++){
+       int a;
+       a=dotpat[i][j];
+       dotpat[i][j]=dotpat[15-i][j];
+       dotpat[15-i][j]=a;
+      }
+    }
+  }
+  /*
+    if(m==2){
+    for(j=0;j<16;j++){
+    for(i=0;i<16;i++){
+    dot2[j][i]=dotpat[15-i][j];
+    }
+    }
+    for(j=0;j<16;j++){
+    for(i=0;i<16;i++){
+    dotpat[j][i]=dot2[j][i];
+    }
+    }
+    }*/
+  /*   if(m==3){*/
+  if(m==2){
+    for(j=0;j<16;j++){
+      for(i=0;i<16;i++){
+       dot2[j][i]=dotpat[i][15-j];
+      }
+    }
+    for(j=0;j<16;j++){
+      for(i=0;i<16;i++){
+       dotpat[j][i]=dot2[j][i];
+      }
+    }
+  }
+}
+
+/***************************/
+void   dot_dis(int cx)
+{
+  int  i,j,a;
+
+  for(i=0;i<16;i+=2){
+    B_LOCATE(cx+8,(i>>1)+18);
+    for(j=0;j<16;j++){
+      /*       B_PRINT(dotp[dotpat[j][i]+dotpat[j][i+1]*2]);*/
+      a=dotpat[j][i]+dotpat[j][i+1]*2;
+      if(cnfflag&0x8000){a=3-a;}
+      B_PRINT(dotp[a]);
+    }
+  }
+}
+
+/***************************/
+void   dattopat(int me)
+{
+  int  ad=8,i,j,a;
+
+  for(j=0;j<16;j++){
+    /*         a=dat[ad]&31;a=a*32+(dat[ad+16]&31);
+               a=a*32+(dat[ad+32]&31);a=a*32+(dat[ad+48]&31);*/
+
+    a=((((((dat[ad]*32)|dat[ad+16])*32)|dat[ad+32])*32)|dat[ad+48]);
+
+    a=a>>4;
+    ad++;
+
+    for(i=0;i<16;i++){dotpat[15-i][j]=a&1;a=a>>1;}
+  }
+}
+
+/***************************/
+void   pattodat(int me)
+{
+  int  ad=8,i,j,a;
+
+  for(j=0;j<16;j++){
+    a=0;
+    for(i=0;i<16;i++){a=a<<1;if(dotpat[i][j]==1){a|=1;}}
+    a=a<<4;
+
+    dat[ad   ]=(a>>15)&31;dat[ad+16]=(a>>10)&31;
+    dat[ad+32]=(a>>5 )&31;dat[ad+48]=(a    )&31;
+    ad++;
+  }
+  dat[72]=0x84;dat[73]=0xf7;
+}
+
+/***************************/
+
+/***************************/
+/*                     0x10 0x01~5 0x00 / 0x10 0x01~5 0x40*/
+void   exc_view(int ad)
+{
+  int  i,cx,gx,co,po,excmd=0;
+  int  e=edit_scr;
+  char tmp0[128];
+  unsigned char        *buf;buf=dat+(16*1024);
+
+  if(edit_scr==0){cx=41;gx=328;}else{cx=1;gx=8;}
+  cons_md(0);/*noed_cls();*/edit_scr=0;
+
+  if(trk[track][ad]<0x90 || trk[track][ad]>0x98){goto ext;}
+  noed_cls();
+
+  if(trk[track][ad]==0x98){
+    po=ad;co=0;
+    while(trk[track][po+4]==0xf7){po+=4;
+    dat[co]=trk[track][po+2];if(dat[co]==0xf7){break;}
+    co++;
+    dat[co]=trk[track][po+3];if(dat[co]==0xf7){break;}
+    co++;
+    }
+  }else{
+    excmd=trk[track][ad]-0x90+1;po=0;co=0;
+    while(user_exc_data[excmd-1][po]!=0xf7 && po<24){
+      dat[co++]=user_exc_data[excmd-1][po++];
+    }
+    dat[co++]=0xf7;
+  }
+
+  box(gx-1,624-48,gx+417+16,997,14,65535);
+  fill(gx,639-32,gx+15,996,8);
+  fill(gx,639-40,gx+416+16,639-16-8,8);
+
+  if(excmd==0){strcpy(tmp0," Track");}else{strcpy(tmp0," User");}
+  strcat(tmp0," Exclusive View");
+
+  if(excmd){strcat(tmp0," [ ] ");tmp0[22]=excmd+'0'-1;
+  strcat(tmp0,user_exc_memo[excmd-1]);}
+
+  sdis(cx,624-48,tmp0,54,15,14);
+
+  /*
+    strcpy(tmp0," Tr:");strcat(tmp0,fstr(track+1,2));
+    strcat(tmp0," Meas:");strcat(tmp0,fstr(meas_no(ad),4));
+
+    sdis(cx,624-48+16,tmp0,54,15,14);
+    */
+
+  for(i=0;i<22;i++){tdis(cx,7+i,hex_s(i,2),2,3);}
+  /*   for(i=0;i<22;i++){sdis(cx,512+(7+i)*16,hex_s(i,2),2,3,8);}*/
+  for(i=0;i<16;i++){sdis(cx+i*3+7,512+6*16-8,hex_s(i,1),1,3,8);}
+
+  exc_dis2(cx,co);
+
+  if( dat[0]==0x41 && dat[1]==0x10 && dat[2]==0x45 && dat[3]==0x12 &&
+      dat[4]==0x83 && dat[5]==0x10 ){
+    if(dat[7]==0x00){
+      if(dat[6]>0){
+       prn_gspanel(cx);scpanel_dsp(cx+13,18,&dat[8]);
+      }else{
+       prn_gspanel(cx);scinst_dsp(cx+13,16,&dat[8]);
+      }
+    }
+  }
+  tg_copy2(1-e);
+  edit_scr=e;
+  /*   txerase(cx*8,4*16,53*8,26*16);*/
+  noed_cls_t();
+ext:
+  edit_scr=e;
+  cons_md(1);
+
+}
+
+void   exc_dis2(int cx,int co)
+{
+  int  i,a=0,no=0;
+
+  B_LOCATE(cx+3,7);B_COLOR(9);B_PRINT("F0");B_COLOR(3);
+
+  while(no<=16+6){
+    int nn=no*16;
+
+    B_LOCATE(cx+5,7+no);
+
+    i=0;
+    while(i<16 && nn<=co){
+      B_PRINT(" ");
+      a=dat[nn++];i++;
+
+      if(a>=0x80 && a<=0x84){
+       B_COLOR(1);B_PRINT(uxcc[a-0x80]);
+      }else{
+       if(a<0x80){B_COLOR(3);}else{B_COLOR(9);}
+       B_PRINT(hex_s(a,2));if(a>=0x80){B_COLOR(3);}
+      }
+
+      if(a==0xf7){break;}
+    }
+    B_COLOR(1);
+
+    no++;
+  }
+  B_COLOR(3);snsclr();
+}
diff --git a/file.cpp b/file.cpp
new file mode 100644 (file)
index 0000000..f65b0a6
--- /dev/null
+++ b/file.cpp
@@ -0,0 +1,1447 @@
+/*
+ * STed: file.c (file & play)
+ */
+
+#include       <stdlib.h>
+#include       <stdio.h>
+#include       <string.h>
+
+#if 0
+#include       "basic0.h"
+#include       "BASIC.h"
+#endif
+
+#include       "iocslib.h"
+#include       "doslib.h"
+#include       "sted.h"
+
+#include        "rcpconv.h"
+
+/* 123456789012345678901234567890 */
+/*static char  sted_id[]="STedV2.0(C)TURBO\r\n";*/             /* 18byte */
+
+static char    rcp_id[] ="RCM-PC98V2.0(C)COME ON MUSIC\r\n";   /* 30byte */
+static char    trk_id[] ="STedV2.0TRACK\r\n";                  /* 15byte */
+static char    prt_id[] ="RCPPR";                              /*  5byte */
+
+static char    rex_id[] ="RCM-PC98 USER EXCLUSIVE\r\n";        /* 25byte */
+static char    res_id[] ="STedV2.0U_EXC\r\n";                  /* 15byte */
+
+static char    ras_id[] ="STedV2.0R_ASS\r\n";                  /* 15byte */
+
+static char     sted_id[] = "STEDDATAx.xx                \r\n"; /* 30bytes */
+
+/*prt rex -> grt gex v2.5g*/
+
+
+/* ================================================== file */
+static int smfload( char *fna ) {
+  int  i,j,size,size2,ln,md2=0,stra=0,max;
+  FILE *fp;
+  unsigned char *smfbuf, *rcpbuf;
+  long ptr,rcpsize;
+
+  fp = fopen2(fna,"rb");
+  if ( fp == NULL ) {msg(_("File not found."));return(-1);}
+  fseek(fp,0,SEEK_END);
+  size=ftell(fp);
+  fseek(fp,0,SEEK_SET);
+
+  smfbuf = (unsigned char *)malloc(sizeof(unsigned char)*size);
+  if ( smfbuf==NULL ) {fclose(fp);return(-1);}
+  fread(smfbuf, 1, size, fp);
+  fclose(fp);
+
+  rcpbuf = (unsigned char *)malloc(sizeof(unsigned char)*DATA_ADR_SIZE);
+  if ( rcpbuf == NULL ) {free(smfbuf);return(-1);}
+  
+  if ( (rcpsize=itor( (char*)smfbuf, (char *)rcpbuf )) == 0 ) {
+    free(rcpbuf);free(smfbuf);return(-1);
+  }
+  free(smfbuf);
+
+  ptr=0;
+  memmove( hed, rcpbuf+ptr, 1414 );
+  ptr+=1414;
+  if ( strcmp(sread(0,30),rcp_id)!=0 ) {
+    msg(_("Invalid file format."));free(rcpbuf);return(-1);
+  }
+  if(hed[0x1e6]==36){md2=1;}else{md2=0;}
+  if(md2==0){max=18;}else{max=36;}
+  dinit();hedread();
+
+  for(i=stra;i<max;i++){
+    memmove(hed,rcpbuf+ptr,44);size=thedread(i);size2=0;
+    ptr+=44;
+    if( size>TRACK_SIZE ){size2=size;size=TRACK_SIZE;}
+
+    if(size_change(i,size)){break;}
+    ln=size;
+    memmove(trk[i],rcpbuf+ptr,size);
+    if( rcpsize<ptr+size ) ln=0;
+    ptr+=size;
+
+    if( ln!=size ){if(i==18){break;}msg(_("Invalid file."));size=ln;break;}
+
+    size=gomi_cut(trk[i],size);
+    tr_len[i]=size;trk[i][size-4]=0xfe;
+
+    if( size2>0){
+      msg(_("Track buffer exhausted."));size2-=size;
+      while( size2>0 ){
+       if( size2>TRACK_SIZE ){j=TRACK_SIZE;}else{j=size2;}
+       memmove(dat,rcpbuf+ptr,j);ptr+=j;
+       size2=size2-j;
+      }
+    }
+  }
+
+  free(rcpbuf);
+  trksize_c();
+  return(0);
+}
+
+int    dload(char *fna,int md)
+{
+  int  i,j,size,size2,ln,md2=0,stra=0,max;
+  FILE *fp;
+
+  if(str_search(fna,".MID")>0 || str_search(fna,".mid")>0 )
+    {return(smfload(fna));}
+
+  if(str_search(fna,".R36")>0 || str_search(fna,".r36")>0){md2=1;}
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+
+  fread(hed,1,1414,fp);
+
+  if( strcmp(sread(0,30),rcp_id)!=0 ){
+    msg(_("Invalid file format."));fclose(fp);return(-1);}
+
+  if(hed[0x1e6]==36){md2=1;}else{md2=0;}
+  if(md2==0){max=18;}else{max=36;}
+  if(md==1){stra=18;max=36;}else{dinit();hedread();}
+
+  for(i=stra;i<max;i++){
+    fread(hed,1,44,fp);size=thedread(i);size2=0;
+    if( size>TRACK_SIZE ){size2=size;size=TRACK_SIZE;}
+
+    if(size_change(i,size)){break;}
+    ln=fread(trk[i],1,size,fp);
+
+    if( ln!=size ){if(i==18){break;}msg(_("Invalid file."));size=ln;break;}
+
+    size=gomi_cut(trk[i],size);
+    tr_len[i]=size;trk[i][size-4]=0xfe;
+
+    if( size2>0){
+      msg(_("Track buffer exhausted."));size2-=size;
+      while( size2>0 ){
+       if( size2>TRACK_SIZE ){j=TRACK_SIZE;}else{j=size2;}
+       fread(dat,1,j,fp);size2=size2-j;
+      }
+    }
+  }
+  fclose(fp);
+  trksize_c();
+  return(0);
+}
+
+/***************************/
+static int smfsave(char *fna) {
+  int  i,md2=0,max;
+  int   smfsize, rcpsize, ptr;
+  unsigned char *smfdata, *rcpdata;
+  FILE *fp;
+
+  for(i=18;i<36;i++){
+    if(tr_len[i]>4 || trkmemo[i][0]!=0){md2=1;}
+  }
+
+  if(md2==0){max=18;}else{max=36;}
+
+  rcpsize = 1414;
+  for ( i=0 ; i<max ; i++ ) {
+    rcpsize+=(44+tr_len[i]);
+  }
+  rcpdata = (uint8 *)malloc(sizeof(uint8)*rcpsize);
+  if ( rcpdata == NULL ) return(-1);
+
+  hedset(max);
+  memcpy( rcpdata, hed, 1414 );
+  ptr=1414;
+  for ( i=0 ; i<max ; i++ ) {
+    thedset( i, tr_len[i]+44 );
+    memcpy( rcpdata+ptr, hed, 44 ); ptr+=44;
+    memcpy( rcpdata+ptr, trk[i], tr_len[i] ); ptr+=tr_len[i];
+  }
+
+  smfsize = rcpconv( rcpdata, rcpsize, &smfdata, NULL );
+  free( rcpdata );
+  if ( smfsize<0 ) return(-1);
+
+  if ((fp=fopen2(fna,"wb"))==NULL) {
+    msg(_("Cannot open file."));
+    free(smfdata);
+    return (-1);
+  }
+  i=fwrite( smfdata, 1, smfsize, fp );
+  fclose(fp);
+  free( smfdata );
+
+  if ( i!=smfsize ) {
+    msg(_("Cannot write file."));
+    unlink(fna);
+    return(-1);
+  }
+
+  return(0);
+}
+
+int    dsave(char *fna)
+{
+  int  i,ef=0,md2=0,max;
+  FILE *fp;
+
+  dclr();
+  if(str_search(fna,".MID")>0 || str_search(fna,".mid")>0 )
+    {return(smfsave(fna));}
+
+  if(str_search(fna,".R36")>0 || str_search(fna,".r36")>0){md2=1;}
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+
+  for(i=18;i<36;i++){
+    if(tr_len[i]>4 || trkmemo[i][0]!=0){md2=1;}
+  }
+
+  if(md2==0){max=18;}else{max=36;}
+
+  hedset(max);fwrite(hed,1,1414,fp);
+
+  i=0;
+  while(i<max && ef==0){
+    thedset(i,tr_len[i]+44);fwrite(hed,1,44,fp);
+    if(fwrite(trk[i],1,tr_len[i],fp)!=tr_len[i]){ef=1;break;}
+    i++;
+  }
+  fclose(fp);
+
+  if(ef!=0){msg(_("Cannot write file."));unlink(fna);return(-1);}
+  return(0);
+}
+
+/***************************/
+int    part_load(char *fna)
+{
+  int  ln,sz;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+  fread(hed,1,8,fp);ln=fread(dat,1,work_size,fp);fclose(fp);
+  if( strcmp(sread(0,5),prt_id)!=0 ){
+    msg(_("Invalid file format."));return(-1);}
+  sz=hed[7]*256+hed[6];
+
+  if( ln<sz ){msg(_("Invalid file."));sz=-1;}
+  return(sz);
+}
+
+/***************************/
+int    part_save(char *fna,int ln)
+{
+  int  fr;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+  sset(prt_id,0,5);hed[5]=track+1;hed[6]=ln&0xff;hed[7]=ln>>8;
+  fwrite(hed,1,8,fp);fr=fwrite(dat,1,ln,fp);fclose(fp);
+
+  if( fr!=ln ){msg(_("Cannot write file."));unlink(fna);return(-1);}
+  return(0);
+}
+
+/***************************/
+int    trk_load(char *fna)
+{
+  int  ln,sz;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+
+  fread(hed,1,16,fp);
+  if( strcmp(sread(0,15),trk_id)!=0 ){
+    msg(_("Invalid file format."));fclose(fp);return(-1);}
+
+  fread(hed,1,44,fp);ln=fread(dat,1,work_size,fp);fclose(fp);
+  sz=hed[0]+hed[1]*256-44;
+  if( ln<sz ){msg(_("Invalid file."));return(-1);}
+
+  sz=gomi_cut(dat,sz);
+  if(size_change(track,sz)){return -1;}
+
+  thedread(track);
+  memcpy_l(trk[track],dat,ln);
+  tr_len[track]=sz;
+  tr_pos[track][0][0]=0;tr_pos[track][0][1]=0;tr_pos[track][0][2]=0;
+  tr_pos[track][1][0]=0;tr_pos[track][1][1]=0;tr_pos[track][1][2]=0;
+
+  return(0);
+}
+
+/***************************/
+int    trk_save(char *fna)
+{
+  int  fr,ln;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+
+  dclr();
+  sset(trk_id,0,15);hed[15]=0x1a;fwrite(hed,1,16,fp);
+  ln=tr_len[track];thedset(track,ln+44);fwrite(hed,1,44,fp);
+  fr=fwrite(trk[track],1,ln,fp);fclose(fp);
+
+  if( fr!=ln ){msg(_("Cannot write file."));unlink(fna);return(-1);}
+  return(0);
+}
+
+/***************************/
+int    part_text_save(char *fna,int ad,int ln)
+{
+  int  i,j=0,fr,ll;
+  FILE *fp;
+  char tmp0[4096+1024];
+  unsigned char a;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+
+  i=ad;
+  while(ln>0){
+    int        lp;
+    if(INPOUT(0xff)==27 ){msg(_("Terminated."));j=-1;break;}
+
+    lp=0;tmp0[0]=0;
+    while(lp<64 && ln>0){
+      a=trk[track][i];
+
+      if(a!=0xf7){
+       strcat(tmp0,trk_dis(0,i,1));strcat(tmp0,"\r\n");
+      }
+      lp++;i+=4;ln-=4;
+    }
+    ll=strlen(tmp0);fr=fwrite(tmp0,1,ll,fp);
+
+    if(fr<ll){msg(_("Disk exhausted."));j=-1;break;}
+  }
+  fclose(fp);
+  snsclr();return(j);
+}
+
+/***************************/
+void   uex_read(int po,int no)
+{
+  int  ad,j;
+
+  ad=po+no*48;if(po==16){ad=po;}
+
+  strcpy(user_exc_memo[no],sread(ad,24));
+  if(hed[ad+24]==0 && hed[ad+47]==0){
+    user_exc_data[no][0]=0xf7;
+  }else{
+    for(j=0;j<24;j++){user_exc_data[no][j]=hed[ad+j+24];}
+  }
+}
+
+void   uex_set(int po,int no)
+{
+  int  ad,j;
+
+  ad=po+no*48;if(po==16){ad=po;}
+
+  sset(user_exc_memo[no],ad,24);
+  for(j=0;j<24;j++){hed[ad+j+24]=user_exc_data[no][j];}
+}
+
+/***************************/
+int    rex_load(char *fna,int mo)
+{
+  int  ln,i,sz;
+  FILE *fp;
+
+  if(mo<0){sz=410;}else{sz=48+16;}
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+  ln=fread(hed,1,sz,fp);fclose(fp);
+  if( ln!=sz ){msg(_("Invalid file."));return -1;}
+
+  if(mo<0){
+    if( strcmp(sread(0,25),rex_id)!=0 ){
+      msg(_("Invalid file format."));return(-1);}
+
+    for(i=0;i<8;i++){uex_read(26,i);}
+  }else{
+    if( strcmp(sread(0,15),res_id)!=0 ){
+      msg(_("Invalid file format."));return(-1);}
+
+    uex_read(16,mo);
+  }
+
+  return(0);
+}
+
+/***************************/
+int    rex_save(char *fna,int mo)
+{
+  int  ln,i,sz;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+
+  if(mo<0){sz=410;}else{sz=48+16;}
+
+  if(mo<0){
+    sset(rex_id,0,25);hed[25]=0x1a;
+    for(i=0;i<8;i++){uex_set(26,i);}
+  }else{
+    sset(res_id,0,15);hed[15]=0x1a;
+    uex_set(16,mo);
+  }
+
+  ln=fwrite(hed,1,sz,fp);fclose(fp);
+
+  if( ln!=sz ){msg(_("Cannot write file."));unlink(fna);return(-1);}
+  return(0);
+}
+
+/***************************/
+int    ras_load(char *fna)
+{
+  int  ln,i;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+  ln=fread(hed,1,528,fp);fclose(fp);
+  if( ln!=528 ){msg(_("Invalid file."));return -1;}
+
+  if( strcmp(sread(0,15),ras_id)!=0 ){
+    msg(_("Invalid file format."));return(-1);}
+
+  for(i=0;i<32;i++){
+    strcpy(rhyna[i],sread(0x10+i*16,14));
+    rhyno[i][0]=hed[0x10+i*16+14];rhyno[i][1]=hed[0x10+i*16+15];
+  }
+
+  return(0);
+}
+
+/***************************/
+int    ras_save(char *fna)
+{
+  int  ln,i;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+
+  sset(ras_id,0,15);hed[15]=0x1a;
+
+  for(i=0;i<32;i++){
+    sset(rhyna[i],0x10+i*16,14);
+    hed[0x10+i*16+14]=rhyno[i][0];hed[0x10+i*16+15]=rhyno[i][1];
+  }
+
+  ln=fwrite(hed,1,528,fp);fclose(fp);
+
+  if( ln!=528 ){msg(_("Cannot write file."));unlink(fna);return(-1);}
+  return(0);
+}
+
+/***************************/
+int    timload(char *fna)
+{
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"rb"))){msg(_("File not found."));return(-1);}
+  fread(cm6,1,22601,fp);fclose(fp);
+  tim_name_read();asin_change();
+  return(0);
+}
+
+/***************************/
+int    timsave(char *fna)
+{
+  int  fr;
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"wb"))){msg(_("Cannot open file."));return(-1);}
+  fr=fwrite(cm6,1,22601,fp);fclose(fp);
+  if( fr!=22601 ){msg(_("Cannot write file."));unlink(fna);return(-1);}
+  return(0);
+}
+
+/***************************/
+int    gsdload(char *fna)
+{
+  FILE *fp;
+
+  if(!(fp= fopen2(fna,"rb"))){
+    msg(_("File not found."));
+    return(-1);
+  }
+  fread(gsd,1,4096,fp);fclose(fp);
+  return(0);
+}
+
+/***************************/
+char   *sread(int a,int b)
+{
+  static       char    s[256];
+  int  i;
+
+  for(i=0;i<b;i++){s[i]=hed[i+a];}
+  if(knck(s,b-1)){b--;}
+
+  s[b]=0;spcut(s);return(s);
+}
+
+/***************************/
+void   sset(char *s,int a,int b)
+{
+  int  i;
+
+  for(i=0;i<b;i++){hed[a+i]=32;}
+  while(*s!=0){hed[a++]=*s++;}
+}
+
+/***************************/
+void   hedset(int max)
+{
+  int  i;
+
+  hed[30]=0;hed[31]=0;sset(mtitle,0x20,64);
+  if ( issted3 ) {
+    sset(sted_id,0,30);
+    sset(STED3_VERSION, 8,4);
+  } else {
+    sset(rcp_id,0,30);
+  }
+
+  i=str_search(cm6_file,".");if(i>8){cm6_file[8]=0;strmfe(cm6_file,cm6_file,"CM6");}
+  i=str_search(gsd_file,".");if(i>8){gsd_file[8]=0;strmfe(gsd_file,gsd_file,"GSD");}
+
+  for(i=0x1b0;i<=0x1bf;i++){hed[i]=0x40;}
+  for(i=0x1e8;i<=0x1f5;i++){hed[i]=0;}
+
+  for(i=0x1c6;i<0x1e5;i++){hed[i]=0;}
+  i=strlen(cm6_file);if(i!=0){sset(cm6_file,0x1c6,12);}
+  i=strlen(gsd_file);if(i!=0){sset(gsd_file,0x1d6,12);}
+
+  hed[0x1e6]=max;
+  hed[0x1e7]=tbase>>8;hed[0x1c0]=tbase;
+
+  hed[0x1c1]=mtempo;hed[0x1c2]=beat1;hed[0x1c3]=beat2;
+  hed[0x1c4]=bkey;hed[0x1c5]=pbias;
+  for(i=0;i<12;i++){sset(memo[i],0x60+i*28,28);}
+
+  for(i=1;i<17;i++){
+    int a1=tim_asin[i],a2=tim_asin[i+16];
+    if(a1>15){a1=0;}
+    if(a2>15){a2=0;}
+    hed[0x1f6-1+i]=a2*16+a1;
+  }
+
+  for(i=0;i<32;i++){
+    sset(rhyna[i],0x206+i*16,14);
+    hed[0x206+i*16+14]=rhyno[i][0];hed[0x206+i*16+15]=rhyno[i][1];
+  }
+  for(i=0;i<8;i++){
+    uex_set(0x406,i);
+  }
+}
+
+/***************************/
+void   hedread()
+{
+  int  i,co;
+
+  strcpy(mtitle,sread(0x20,64));
+  strcpy(cm6_file,sread(0x1c6,16));strcpy(gsd_file,sread(0x1d6,16));
+  if(strlen(cm6_file)>15){gsd_file[0]=0;}
+
+  tbase= hed[0x1c0];
+  if( hed[0x1e6]!=0){tbase+=(hed[0x1e7]<<8);}
+
+  mtempo= hed[0x1c1];beat1= hed[0x1c2];beat2= hed[0x1c3];
+  if(beat2<2 || beat2>16){beat2=4;}
+  if(beat1<1 || beat1>beat2*2){beat1=beat2;}
+
+  bkey=  hed[0x1c4];pbias= hed[0x1c5];
+  for(i=0 ;i<= 11;i++){strcpy(memo[i],sread(0x60+i*28,28));}
+
+  /*   asin_init();*/
+
+  co=0;
+  if((cnfflag&0x0080)==0){
+    if((hed[0x1f6]&15)!=0 || (hed[0x1f6]==0x70 && hed[0x1f6+1]==0x71)){
+      for(i=1 ;i<= 16;i++){
+       int     d=hed[0x1f6-1+i];
+       if(d!=0){co++;}
+       tim_asin[i]=d&15;tim_asin[i+16]=(d>>4)&15;
+       /*
+         if((d&15)!=0){tim_asin[i]=d&15;}
+         if((d>>4)!=0){tim_asin[i+16]=d>>4;}
+         */
+      }
+    }
+  }
+  if(co==0){asin_init();}
+
+  for(i=0;i<32;i++){
+    strcpy(rhyna[i],sread(0x206+i*16,14));
+    rhyno[i][0]=hed[0x206+i*16+14];rhyno[i][1]=hed[0x206+i*16+15];
+  }
+  for(i=0;i<8;i++){
+    uex_read(0x406,i);
+  }
+}
+
+/***************************/
+void   thedset(int tr,int sz)
+{
+  hed[0]=(sz&0xfc)+((sz>>16)&3);hed[1]=(sz>>8)&0xff;
+  hed[2]=trno[tr];hed[3]=trrhy[tr];hed[4]=mch[tr]-1;
+  hed[6]=trst[tr];hed[5]=trkey[tr];hed[7]=trmod[tr];if(hed[7]==3){hed[7]=4;}
+  sset(trkmemo[tr],8,36);
+}
+
+/***************************/
+int    thedread(int tr)
+{
+  int  size;
+
+  size=(hed[0]&0xfc)+((hed[0]&3)*256+hed[1])*256-44;
+  trno[tr]=hed[2];trrhy[tr]=hed[3];mch[tr]=hed[4]+1;if(mch[tr]>32){mch[tr]=0;}
+  trkey[tr]=hed[5];trst[tr]=hed[6];trmod[tr]=hed[7];if(trmod[tr]==3){trmod[tr]=4;}
+  strcpy(trkmemo[tr],sread(8,36));
+  return(size);
+}
+
+/***************************/
+int    bufload()
+{
+  int  bpo=0,i,size,size2,max;
+
+  if( (rcd->data_valid==0 && rcd->tone_valid==0 ) ||(rcd->fmt!=2 && rcd->fmt!=1)){
+    msg(_("Buffer is empty."));return(-1);
+  }
+
+  if( rcd->data_valid!=0 ){
+    bpo = rcp_buf_get((char *)hed,0,1414);
+    if( strcmp(sread(0,30),rcp_id)!=0 ){
+      msg(_("Buffer is empty."));return(-1);
+    }
+    dinit();
+    hedread();
+
+    if(rcd->fmt==1){max=18;}else{max=36;}
+    if(hed[0x1e6]==36){max=36;}else{max=18;}
+
+    for(i=0;i<max;i++){
+      bpo=rcp_buf_get((char *)hed,bpo,44);
+      if((rcd->totalcount)<bpo){break;}
+
+      size=thedread(i);size2=0;
+      if( size>TRACK_SIZE ){size2=size;size=TRACK_SIZE;}
+      if(size_change(i,size)){break;}
+
+      bpo=rcp_buf_get((char *)trk[i],bpo,size);
+      size=gomi_cut(trk[i],size);
+      tr_len[i]=size;trk[i][size-4]=0xfe;
+      if( size2>0){msg(_("Track buffer exhausted."));bpo=bpo+(size2-size);}
+    }
+    strcpy(rcp_file,rcd->filename);
+    if(rcp_file[0]!=0){
+      if(max==18){
+       if(str_search(rcp_file,".R36")==0 && str_search(rcp_file,".r36")==0){
+         strmfe(rcp_file,rcp_file,"RCP");
+       }
+      }else{
+       if(str_search(rcp_file,".RCP")==0 && str_search(rcp_file,".rcp")==0){
+         strmfe(rcp_file,rcp_file,"R36");
+       }
+      }
+    }
+    if( rcd->tone_valid==0 ){cminit();}
+    if( rcd->gsd_valid==0 ){gsinit();}
+  }
+
+  if( rcd->tone_valid!=0 ){
+    tim_var_read();
+    if(cm6_file[0]!=0){strmfe(cm6_file,cm6_file,"CM6");asin_change();}
+  }
+  if( rcd->gsd_valid!=0 ){
+    gsd_var_read();
+    if(gsd_file[0]!=0){strmfe(gsd_file,gsd_file,"GSD");}
+  }
+  trksize_c();
+  return(0);
+}
+
+/***************************/
+int    bufset()
+{
+  int  bpo,i;
+
+  all_note_off(1);rcd->data_valid=0;dclr();
+  hedset(36);bpo=rcp_buf_put((char *)hed,0,1414);
+
+  for(i=0;i<36;i++){
+    same_cluc(i,0);
+    thedset(i,tr_len[i]+44);bpo=rcp_buf_put((char *)hed,bpo,44);
+    bpo=rcp_buf_put((char *)trk[i],bpo,tr_len[i]);
+  }
+
+  if((rcd->bufcap)<bpo){msg(_("Too small RCD buffer."));return(-1);}
+
+  rcd->fmt=2;rcd->totalcount=bpo;rcd->data_valid=1;rcd->word_valid=0;
+  rcd->tone_valid=0;rcd->gsd_valid=0;
+  if(cm6_file[0]!=0){tim_buf_trns();}
+  if(gsd_file[0]!=0){gsd_buf_trns();}
+  strcpy(rcd->filename,rcp_file);
+  strcpy(rcd->tonename,cm6_file);
+  strcpy(rcd->gsdname,gsd_file);
+  return(0);
+}
+
+/***************************/
+int    bufload_trk(int tr)
+{
+  int  bpo=0,size;
+
+  if( (rcd->data_valid==0) || rcd->fmt!=99 ){
+    msg(_("Buffer is empty."));return(-1);
+  }
+
+  bpo=rcp_buf_get((char *)hed,bpo,44);size=thedread(tr);
+  if( size>TRACK_SIZE ){size=TRACK_SIZE;msg(_("Track buffer exhausted."));}
+  if(size_change(tr,size)){goto ext;}
+
+  bpo=rcp_buf_get((char *)trk[tr],bpo,size);
+  size=gomi_cut(trk[tr],size);
+  tr_len[tr]=size;trk[tr][size-4]=0xfe;
+
+  /*   trksize_c();*/
+ext:
+  rcd->fmt=0;rcd->data_valid=0;rcd->word_valid=0;
+  return(0);
+}
+
+int    bufset_trk(int tr)
+{
+  int  bpo=0;
+
+  all_note_off(1);rcd->fmt=0;rcd->data_valid=0;/*dclr();*/
+
+  same_cluc(tr,0);
+  thedset(tr,tr_len[tr]+44);bpo=rcp_buf_put((char *)hed,bpo,44);
+  bpo=rcp_buf_put((char *)trk[tr],bpo,tr_len[tr]);
+
+  if((rcd->bufcap)<bpo){msg(_("Too small RCD buffer."));return(-1);}
+
+  rcd->fmt=99;rcd->totalcount=bpo;rcd->data_valid=1;rcd->word_valid=0;
+  return(0);
+}
+
+/***************************/
+/* ================================================== play */
+void   dplay(int mo,int tr,int meas)
+{
+  int  bpo,i,f;
+  char tmp1[256];
+  FILE *fp;
+
+  if((cmdflag&0x8000)!=0 && mo<2){mo=1-mo;}
+
+  if(rcd->act!=0 && mo!=0 && meas==0){
+    mo+=8;
+    if(mplay[mo][0]=='&'){goto start;}
+    if(mplay[mo][0]=='%'){goto resm;}
+  }
+start:
+  all_note_off(1);rcd->data_valid=0;
+  msg_clr();poft=0;
+  hedset(36);bpo=rcp_buf_put((char *)hed,0,1414);
+
+  for(i=0;i<36;i++){
+    if((trmod[i]&1)!=0){
+      thedset(i,48);dat[0]=0xfe;
+      bpo=rcp_buf_put((char *)hed,bpo,44);
+      bpo=rcp_buf_put((char *)dat,bpo,4);
+    }else{
+      same_cluc(i,0);
+      thedset(i,tr_len[i]+44);
+      bpo=rcp_buf_put((char *)hed,bpo,44);
+      bpo=rcp_buf_put((char *)trk[i],bpo,tr_len[i]);
+    }
+  }
+
+  if((rcd->bufcap)<bpo){msg(_("Too small RCD buffer."));return;}
+
+  rcd->fmt=2;rcd->totalcount=bpo;
+  rcd->data_valid=1;rcd->word_valid=0;
+  rcd->tone_valid=0;rcd->gsd_valid=0;
+
+  (*rcd->init)();
+  if(cm6_file[0]!=0){tim_buf_trns();}
+  if(gsd_file[0]!=0){gsd_buf_trns();}
+
+  if(cm6_file[0]==0 && gsd_file[0]==0){
+    if(init_exc_data[0]==255){(*rcd->setup)();
+    }else{(*rcd->mix_out)((char *)init_exc_data);twait(5);}
+  }
+
+  if(mo!=0 && meas==0){
+    strcpy(tmp1,rcp_path);strcat(tmp1,rcp_file);strmfe(tmp1,tmp1,"wrd");
+    if(fp=fopen2(tmp1,"rb")){
+      int      i,j,sz;
+      unsigned char    a;
+
+      sz = rcd->wordcap;
+      j=fread(dat,1,work_size,fp);fclose(fp);bpo=0;
+      for(i=0;i<j;i++){
+       a=dat[i];
+       if(a!=0x0a){
+         if(a==0x0d ){a=0;}
+         rcd->word_adr[bpo]=a;bpo++;
+         if(bpo+1>=sz){break;}
+       }
+      }
+      rcd->word_adr[bpo]=26;rcd->word_valid=1;
+    }
+  resm:
+    strcpy(rcd->filename,rcp_file);
+    strcpy(rcd->tonename,cm6_file);
+    strcpy(rcd->gsdname,gsd_file);
+
+    fnc_dis(-1);C_FNKMOD(0);dpl(0);B_COLOR(3);
+    if(mplay[mo][0]=='%' || mplay[mo][0]=='&'){
+      strcpy(tmp1,&mplay[mo][1]);
+      if(rcd->act==0 || mplay[mo][0]=='&'){(*rcd->begin)();}
+    }else{strcpy(tmp1,mplay[mo]);}
+    f=exe(tmp1);
+    B_COLOR(3);
+    fnc_dis(-1);
+    C_FNKMOD(3);
+    B_CLR_AL();
+    C_CUROFF();
+    CRTMOD(16+256);
+    OnGraphic();
+    dpl(1);
+    tpl(1);
+    WINDOW(0,0,1023,1023);
+
+    if( f<0 ){msg(_("Cannot start panel display."));}
+  }else{
+    if(meas>1){rcd->tar_trk = tr;rcd->tar_bar = meas-1;rcd->sts = 2;}
+    (*rcd->begin)();
+  }
+  return;
+}
+
+/************************** meas play */
+void   cdplay(int tr,int po,int ln,int md)
+{
+  int  bpo,co,i,j,ad,meas,tempo,pr,dumy=track;
+  int  me_ad[2048];
+
+  all_note_off(1+1);rcd->data_valid=0;msg_clr();if(ln==0){return;}
+  hedset(36);bpo=rcp_buf_put((char *)hed,0,1414);
+  meas=meas_no(po);if((cmdflag&0x4000)==0){pr=lsp_wait_chack(meas);}
+  tempo=last_tempo(meas);
+  poft=meas-1;if(md==0){if(po>0){poft+=0x10000;}}
+
+  for(i=0;i<36;i++){
+    track=i;co=0;
+
+    if((trmod[i]&1)==0){
+      if((cmdflag&0x4000)==0 && tr!=i){
+       ad=meas_add(meas);if(ad<0){ad=tr_len[i]-4;}
+       add_set(i,me_ad);
+       co=lsp_para_set(i,ad,me_ad,pr);
+       j=ad;
+      }
+
+      if( tr==i ){
+       add_set(i,me_ad);
+
+       if(md==0){
+         if((cmdflag&0x4000)==0){
+           co=lsp_para_set(i,po,me_ad,pr);
+         }else{
+           co=lsp_para_set(i,po,me_ad,lsp_para_set(i,po,me_ad,-1));
+         }
+       }
+       j=po;
+
+       if(po>0){
+         if( tempo>=0){
+           dat[co]=0xe7;dat[co+1]=1;dat[co+2]=tempo;dat[co+3]=0;
+           co=co+4;
+         }
+         dat[co]=0xfd;co=co+4;
+       }
+
+       while(ln>0){
+         dat[co]=trk[i][j];dat[co+1]=trk[i][j+1];
+         dat[co+2]=trk[i][j+2];dat[co+3]=trk[i][j+3];
+         if(dat[co]==0xfc){
+           int same,ad;
+           same=dat[co+1]+(dat[co+2]&3)*256;
+           if(meas<same+1){
+             if(po>0){same++;}
+             ad=dat_add(co+4,same+1+1-meas);
+             if(ad>co){goto sameext;}
+             ad+=44;dat[co+2]=ad&0xff;dat[co+3]=ad>>8;
+           }else{
+           sameext:
+             ad=me_ad[same];
+             while(trk[i][ad]<0xfc && co<work_size){
+               dat[co]=trk[i][ad];dat[co+1]=trk[i][ad+1];
+               dat[co+2]=trk[i][ad+2];dat[co+3]=trk[i][ad+3];
+               co=co+4;ad=ad+4;
+             }
+             dat[co]=0xfd;
+           }
+         }
+         if(dat[co]==0x98){
+           while(trk[i][j+4]==0xf7 && co<work_size){
+             co+=4;j+=4;ln-=4;
+             dat[co]=trk[i][j];dat[co+1]=trk[i][j+1];
+             dat[co+2]=trk[i][j+2];dat[co+3]=trk[i][j+3];
+           }
+         }
+         if(dat[co]==0xfe || co+4>=work_size ){break;}
+         co=co+4;
+         if(trk[i][j]<0xfc && trk[i][j+4]==0xfc){dat[co]=0xfd;co=co+4;}
+         ln=ln-4;j=j+4;
+       }
+      }
+    }
+    dat[co]=0xfe;co=co+4;
+    thedset(i,co+44);bpo=rcp_buf_put((char *)hed,bpo,44);
+    bpo=rcp_buf_put((char *)dat,bpo,co);
+  }
+
+  track=dumy;
+
+  if((rcd->bufcap)<bpo){msg(_("Too small RCD buffer."));return;}
+
+  rcd->fmt=2;rcd->totalcount=bpo;rcd->data_valid=1;rcd->word_valid=0;
+  rcd->tone_valid=0;rcd->gsd_valid=0;
+
+  (*rcd->init)();
+  if(cm6_file[0]==0 && gsd_file[0]==0){
+    if(init_exc_data[0]==255){(*rcd->setup)();
+    }else{(*rcd->mix_out)((char *)init_exc_data);twait(5);}
+  }
+  (*rcd->begin)();
+  return;
+}
+
+/************************** point play */
+void   cntplay(int tr,int po)
+{
+  int  bpo,i,j,co,ad,meas,dumy,pr,tempo;
+  int  me_ad[2048];
+
+  if((cmdflag&0x80)!=0){dplay(0,tr,meas_no(po));return;}
+  all_note_off(1+1);rcd->data_valid=0;msg_clr();dumy=track;
+  hedset(36);bpo=rcp_buf_put((char *)hed,0,1414);
+  meas=meas_no(po);pr=lsp_wait_chack(meas);tempo=last_tempo(meas);
+  poft=meas-1;if(po>0){poft+=0x10000;}
+
+  for(i=0;i<36;i++){
+    co=0;
+    if((trmod[i]&1)==0){
+      track=i;ad=meas_add(meas);if(ad<0){ad=tr_len[i]-4;}
+      add_set(i,me_ad);
+      co=lsp_para_set(i,ad,me_ad,pr);
+      if(po>0){
+       if( tempo>=0){
+         dat[co]=0xe7;dat[co+1]=1;dat[co+2]=tempo;dat[co+3]=0;
+         co=co+4;
+       }
+       dat[co]=0xfd;co=co+4;
+      }
+      j=ad;
+      while(1){
+       dat[co]=trk[i][j];dat[co+1]=trk[i][j+1];
+       dat[co+2]=trk[i][j+2];dat[co+3]=trk[i][j+3];
+       if(dat[co]==0xfc){
+         int   same,ad;
+         same=dat[co+1]+(dat[co+2]&3)*256;
+         if(meas<(same+1)){
+           if(po>0){same++;}
+           ad=dat_add(co+4,same+1+1-meas);
+           if(ad>co){goto sameext;}
+           ad+=44;dat[co+2]=ad&0xff;dat[co+3]=ad>>8;
+         }else{
+         sameext:
+           ad=me_ad[same];
+           while(trk[i][ad]<0xfc && co<work_size){
+             dat[co]=trk[i][ad];dat[co+1]=trk[i][ad+1];
+             dat[co+2]=trk[i][ad+2];dat[co+3]=trk[i][ad+3];
+             co=co+4;ad=ad+4;
+           }
+           dat[co]=0xfd;
+         }
+       }
+       if(dat[co]==0x98){
+         while(trk[i][j+4]==0xf7 && co<work_size){
+           co+=4;j+=4;
+           dat[co]=trk[i][j];dat[co+1]=trk[i][j+1];
+           dat[co+2]=trk[i][j+2];dat[co+3]=trk[i][j+3];
+         }
+       }
+       if( dat[co]==0xfe || co+4>=work_size ){break;}
+       co=co+4;
+       if(trk[i][j]<0xfc && trk[i][j+4]==0xfc){dat[co]=0xfd;co=co+4;}
+       j=j+4;
+      }
+    }
+    dat[co]=0xfe;co=co+4;
+    thedset(i,co+44);bpo=rcp_buf_put((char *)hed,bpo,44);
+    bpo=rcp_buf_put((char *)dat,bpo,co);
+  }
+
+  track=dumy;
+
+  if((rcd->bufcap)<bpo){msg(_("Too small RCD buffer."));return;}
+
+  rcd->fmt=2;rcd->totalcount=bpo;rcd->data_valid=1;rcd->word_valid=0;
+  rcd->tone_valid=0;rcd->gsd_valid=0;
+
+  (*rcd->init)();
+  if(cm6_file[0]==0 && gsd_file[0]==0){
+    if(init_exc_data[0]==255){(*rcd->setup)();
+    }else{(*rcd->mix_out)((char *)init_exc_data);twait(5);}
+  }
+  (*rcd->begin)();
+  return;
+}
+
+/***************************/
+int    last_tempo(int meas)
+{
+  int  i,ad,dumy,tm_me=-1,tmpo=-1,b;
+
+  dumy=track;
+
+  for(i=0;i<36;i++){
+    if((trmod[i]&1)==0){
+      track=i;ad=meas_add(meas);if(ad<0){ad=tr_len[i]-4;}
+      while(ad>=0 ){
+       if( trk[i][ad]==0xe7 ){
+         b=meas_no(ad);if(b>tm_me){tmpo=trk[i][ad+2];tm_me=b;}
+         break;
+       }
+       ad=ad-4;
+      }
+    }
+  }
+  track=dumy;
+  return(tmpo);
+}
+
+/***************************/
+int    lsp_para_set(int tr,int po,int *me_ad,int wcc)
+{
+  int  co=0,j,jj=0,i,pa=-1,exf=0;
+  int  wa=0,wa2=0,retad=0;
+  unsigned char        d;
+  unsigned char        *ptr;
+  int  ctad[256];
+  int  rba=0;
+
+  if(po==0 || lsp_wait<0){return(0);}
+  for(i=0;i<128;i++){ctad[i]=-1;}
+
+  ptr=(unsigned char *)trk[tr];
+
+  if(wcc>0){
+    int tst=0;
+    wa=(mtempo>>6)*(tbase/48)*lsp_wait+1;wa2=wa>>1;wcc=(wcc>>3)*wa;
+
+    while(jj<po &&(jj==0||tst<=16||ptr[jj]==0xe6||ptr[jj]==0xf6
+                  ||(ptr[jj]>=0x90 && ptr[jj]<=0x98) )){
+
+      if(ptr[jj]==0xde||(ptr[jj]>=0x90 && ptr[jj]<=0x98)){exf=1;}
+
+      if(ptr[jj]<0xf0){
+       if(ptr[jj]==0xde){jj+=4;break;}
+
+       tst+=ptr[jj+1];
+       if(tst>16){break;}
+      }
+
+      jj=jj+4;
+
+      while(ptr[jj]==0xf7){jj+=4;}
+      if(ptr[jj+1]>2 && exf){break;}
+    }
+    if(exf==0){dat[0]=0;dat[1]=40;dat[2]=0;dat[3]=0;co=4;}
+  }
+
+  for(j=0;j<po;j=j+4){
+  top:
+    if(exf!=0 && j>=jj){dat[co]=0;dat[co+1]=40;dat[co+2]=0;dat[co+3]=0;co+=4;exf=0;}
+    d=ptr[j];
+
+    if( d>127 ){
+      if( d==0xeb ){
+       d=ptr[j+2];
+       if( d==0 || d==32 || d==6 || d==38 || (d>97 && d<102) ){
+         if(co>=0 && dat[co-4]==0xeb && dat[co-2]==d){
+           dat[co-1]=ptr[j+3];
+         }else{
+           dat[co]=0xeb;dat[co+1]=0;dat[co+2]=d;
+           dat[co+3]=ptr[j+3];
+           if(wcc>0){dat[co+1]=wa2;wcc=wcc-wa2;wa2=wa-wa2;}
+           co=co+4;
+         }
+       }else{
+         if(d!=121){ctad[d]=j;}
+         else{for(d=0;d<128;d++){ctad[d]=-1;}}
+       }
+      }else{
+       if( d==0xf6 ){
+         while(ptr[j+4]==0xf7){j+=4;}
+         goto top;
+       }
+
+       /*
+         41 10 42 12 cs 00 01 01 01 ss F7 <--- PART A01の受信ポートをBにする
+         41 10 42 12 cs 00 01 17 00 ss F7 <--- PART B01の受信ポートをAにする
+         */
+       if( d==0xdd ){rba=ptr[j+2]*256+ptr[j+3];}
+       if( d==0xde ){if(rba==1 && ptr[j+2]<0x17+16){goto outp;}}
+       if( d==0x98 ){
+         if(ptr[j+6]==0x41 && ptr[j+10]==0x42 &&(
+                                                 (ptr[j+14]==0x83 && ptr[j+15]==0 && ptr[j+18]==0x01 && ptr[j+22]<0x17+16)||
+                                                 (ptr[j+14]==0 && ptr[j+15]==0x01 && ptr[j+18]<0x17+16)
+                                                 )){goto outp;}
+       }
+       if( d>=0x90 && d<=0x97 ){
+         unsigned char *pt2;
+         pt2=(unsigned char *)user_exc_data[d&0xf];
+
+         if(pt2[0]==0x41 && pt2[2]==0x42 &&(
+                                            (pt2[4]==0x83 && pt2[5]==0 && pt2[6]==0x01 && pt2[7]<0x17+16)||
+                                            (pt2[4]==0 && pt2[5]==0x01 && pt2[6]<0x17+16)
+                                            )){goto outp;}
+       }
+
+
+       if( d==0xe6 ){
+       outp:
+         /*control*/
+         for(i=127;i>0;i--){
+           int j=ctad[i];
+           if(j>=0){
+             dat[co]=0xeb;dat[co+1]=0;dat[co+2]=i;dat[co+3]=ptr[j+3];
+             if(wcc>0){dat[co+1]=wa2;wcc=wcc-wa2;wa2=wa-wa2;}
+             co=co+4;ctad[i]=-1;
+           }
+         }
+         /*pitch*/
+         if(pa>=0){
+           dat[co]=0xee;dat[co+1]=0;dat[co+2]=ptr[pa+2];dat[co+3]=ptr[pa+3];
+           if(wcc>0){dat[co+1]=wa2;wcc=wcc-wa2;wa2=wa-wa2;}
+           co=co+4;pa=-1;
+         }
+
+       }
+       if( d<0xee && d!=0xe7 ){
+         dat[co]=d;dat[co+1]=0;dat[co+2]=ptr[j+2];
+         dat[co+3]=ptr[j+3];
+         if((d==0xdd || d==0xdf || d==0xe6)||(d==0xde && \
+                                              (ptr[j+4]==0xde && ptr[j+2]+1==ptr[j+6]))){
+           if(wcc<0){goto skip02;}
+           if(wcc>0){goto skip01;}
+         }else{
+           if(wcc>0){
+             if(d==0xde){co+=4;dat[co]=0;dat[co+1]=wa;dat[co+2]=0;dat[co+3]=0;
+             wcc-=wa;goto skip01;}
+             if(wa2>0){dat[co+1]=wa2;}
+           }
+           if(wcc<0){
+             if(d==0xde){co+=4;}
+           }
+         }
+         wcc=wcc-wa2;wa2=wa-wa2;
+       skip01:
+         co=co+4;
+       }
+      skip02:
+       if( d>=0xfc && retad!=0){j=retad;retad=0;goto top;}
+
+       if( d==0xfc ){
+         int   ii,jj,ct;
+         jj=j;
+       resame:
+         ct=ptr[jj+1]+(ptr[jj+2]&3)*256;ii=me_ad[ct];
+
+         if(jj!=ii){
+           jj=ii;if(ptr[ii]==0xfc){goto resame;}
+           retad=j+4;j=ii;goto top;
+         }
+       }
+       if( d==0xee ){pa=j;}
+
+      }
+    }
+  }
+  /*control*/
+  for(i=127;i>0;i--){
+    int        j=ctad[i];
+    if(j>=0){
+      dat[co]=0xeb;dat[co+1]=0;dat[co+2]=i;dat[co+3]=ptr[j+3];
+      if(wcc>0){dat[co+1]=wa2;wcc=wcc-wa2;wa2=wa-wa2;}
+      co=co+4;
+    }
+  }
+  /*pitch*/
+  if(pa>=0){
+    dat[co]=0xee;dat[co+1]=0;dat[co+2]=ptr[pa+2];dat[co+3]=ptr[pa+3];
+    if(wcc>0){dat[co+1]=wa2;wcc=wcc-wa2;wa2=wa-wa2;}
+    co=co+4;
+  }
+  if(wcc>0){
+    while(wcc>0){
+      if(wcc>255){dat[co+1]=255;wcc=wcc-255;}else{dat[co+1]=wcc;wcc=0;}
+      dat[co]=0;dat[co+2]=0;dat[co+3]=0;co=co+4;
+    }
+  }
+
+  return(co);
+}
+
+/*
+0xE6:M.CH 0xEC:PROG 0xed:AFT.K 0xea:AFT.C 0xee:PITCH 0xdd:R.BASE 0xde:R.PARA 0xe7:TEMPO
+0xeb:CONTROL(1:MODULATION 7:VOLUME 10:PANPOT 11:EXPRESSION 64:HOLD 121:RESET A.C.)
+*/
+
+/***************************/
+int    lsp_wait_chack(int meas)
+{
+  int  cc=0,i,a,ad,dummy;
+  int  me_ad[2048];
+
+  dummy=track;
+  for(i=0;i<36;i++){
+    if((trmod[i]&1)==0){
+      track=i;add_set(i,me_ad);ad=meas_add(meas);if(ad<0){ad=tr_len[i]-4;}
+      a=lsp_para_set(track,ad,me_ad,-1);if( a>cc ){cc=a;}
+    }
+  }
+  track=dummy;
+  return(cc);
+}
+
+/***************************/
+void   tim_buf_trns()
+{
+  memcpy(rcd->tone_adr,cm6,22601);strcpy(rcd->tonename,cm6_file);
+  rcd->fmt=2;rcd->tone_valid=1;
+}
+
+void   tim_var_read()
+{
+  memcpy(cm6,rcd->tone_adr,22601);strcpy(cm6_file,rcd->tonename);
+  tim_name_read();
+}
+
+void   tim_name_read()
+{
+  int  i,j;
+
+  for(i=0;i<64;i++){
+    tim_name[i+128][10]=0;
+    for(j=0;j<10;j++){tim_name[i+128][j]=cm6[0xe34+i*256+j];}
+  }
+}
+
+void   gsd_buf_trns()
+{
+  memcpy(rcd->gsd_adr,gsd,4096);strcpy(rcd->gsdname,gsd_file);
+  rcd->fmt=2;rcd->gsd_valid=1;
+}
+
+void   gsd_var_read()
+{
+  memcpy(gsd,rcd->gsd_adr,4096);strcpy(gsd_file,rcd->gsdname);
+}
+
+/***************************/
+int    rcp_buf_put(char *ptr,int po,int ln)
+{
+  char *p;
+  if((rcd->bufcap)<(po+ln)){return(po+ln);}
+  p=rcd->data_adr;p+=po;
+  if(ln>1414){
+    memcpy_l((uint8*)p,(uint8 *)ptr,ln);
+  }else{
+    memcpy(p,ptr,ln);
+  }
+  po=po+ln;
+  return(po);
+}
+
+int    rcp_buf_get(char *ptr,int po,int ln)
+{
+  char *p;
+  if((rcd->bufcap)<(po+ln)){return(po+ln);}
+  p=rcd->data_adr;p+=po;
+  if(ln > 1414){
+    memcpy_l((uint8*)ptr,(uint8*)p,ln);
+  }else{
+    memcpy(ptr,p,ln);
+  }
+  po=po+ln;return(po);
+}
+
+/* ================================================== data */
+void   dclr()
+{
+  int  i,j;
+  unsigned char        a;
+
+  for(i=0;i<36;i++){
+    same_cluc(i,0);
+    for(j=0;j<tr_len[i];j=j+4){
+      a=trk[i][j];
+      if(a>127){
+       switch(a){
+       case  0xe7:if(trk[i][j+2]==0){trk[i][j+2]=1;}break;
+
+       case  0xe6:
+       case  0xea:
+       case  0xec:trk[i][j+3]=0;break;
+
+       case  0xf6:
+       case  0xf7:trk[i][j+1]=0;break;
+
+       case  0xf8:trk[i][j+2]=0;trk[i][j+3]=0;break;
+
+       case  0xf9:
+       case  0xfd:trk[i][j+1]=1;trk[i][j+2]=0;trk[i][j+3]=0;break;
+
+       case  0xfe:trk[i][j+1]=0xfe;trk[i][j+2]=0xfe;trk[i][j+3]=0xfe;
+         tr_len[i]=j+4;break;
+       }
+      }
+    }
+  }
+}
+
+/***************************/
+void   same_cluc(int tr,int ofset)
+{
+  int  j=0,max;
+  unsigned char        a;
+  int  add[2048];
+
+  max=add_set(tr,add);
+  while(j<tr_len[tr]-4 ){
+    a=trk[tr][j];
+    if(a==0xfc){
+      int no,ad=j;
+    resame:
+      no=trk[tr][ad+1]+(trk[tr][ad+2]&3)*256;
+      if(no<max){
+       ad=add[no];
+       if(j!=ad && trk[tr][ad]==0xfc ){
+         goto resame;
+       }
+
+       trk[tr][j+1]=no&0xff;
+       trk[tr][j+2]=(trk[tr][j+2]&0xfc)+((no>>8)&3);
+
+      }else{ad=0;}
+
+      ad+=44+ofset;trk[tr][j+2]=(trk[tr][j+2]&3)+(ad&0xfc);trk[tr][j+3]=ad>>8;
+    }
+    j=j+4;
+  }
+}
+
+/***************************/
+int    gomi_cut(unsigned char *ptr,int size)
+{
+  int  ad=0,po=0;
+  unsigned char        da,db,dc,dd;
+
+  while(ad<size){
+    da=ptr[ad++];db=ptr[ad++];dc=ptr[ad++];dd=ptr[ad++];
+
+    if(da==0x98 || da==0xf6){
+      ptr[po++]=da;ptr[po++]=db;
+      ptr[po++]=dc;ptr[po++]=dd;
+
+      while(ptr[ad]==0xf7 && ad<size){
+       ptr[po++]=ptr[ad++];ptr[po++]=ptr[ad++];
+       ptr[po++]=ptr[ad++];ptr[po++]=ptr[ad++];
+      }
+
+      while(ptr[ad]==0xfd && ptr[ad+4]==0xf7 && ad<size){
+       ptr[po++]=ptr[ad+4];ptr[po++]=ptr[ad+5];
+       ptr[po++]=ptr[ad+6];ptr[po++]=ptr[ad+7];
+
+       ptr[ad+4]=0xfd;ad+=4;
+      }
+
+    }else{
+      if(da!=0xf7){
+       ptr[po++]=da;ptr[po++]=db;
+       ptr[po++]=dc;ptr[po++]=dd;
+      }
+    }
+  }
+  return po;
+}
+
+/***************************/
+void   dinit()
+{
+  unsigned char        *ptr=trk[0];
+
+  int  i,j;
+
+  for(i=0;i<24;i++){tag[i][0]=-1;}
+
+  track=0;btrack=0;
+  buff_free=buff_size;
+
+  for(i=0;i<36;i++){
+    trk[i]=ptr;ptr+=4;tr_alc[i]=4;buff_free-=4;
+
+    trk[i][0]=0xfe;tr_len[i]=4;tr_step[i]=0;
+
+    for(j=0;j<4;j++){tr_pos[i][0][j]=0;tr_pos[i][1][j]=0;}
+    trmod[i]=0;trno[i]=i+1;trrhy[i]=0;
+    mch[i]=i+1;if(i>15){mch[i]=0;}
+
+    trkey[i]=0;trst[i]=0;trkmemo[i][0]=0;
+  }
+
+  trrhy[9]=128;trkey[9]=128;
+
+  for(i=0;i<12;i++){memo[i][0]=0;}
+  mtitle[0]=0;cm6_file[0]=0;gsd_file[0]=0;
+  mtempo=120;tbase=48;beat1=4;beat2=4;bkey=0;pbias=0;
+
+  cminit();gsinit();rhinit();
+  user_exc_init();asin_init();stgt_init();
+}
+
+/***************************/
diff --git a/getopt.cpp b/getopt.cpp
new file mode 100644 (file)
index 0000000..f048f5a
--- /dev/null
@@ -0,0 +1,138 @@
+/*  $NetBSD: getopt.c,v 1.24 2002/06/21 09:56:33 wiz Exp $  */
+
+/*
+ * Copyright (c) 1987, 1993, 1994
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+//#include "stdafx.h"
+
+#include <cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+#if 0
+static char sccsid[] = "@(#)getopt.c   8.3 (Berkeley) 4/27/95";
+#else
+__RCSID("$NetBSD: getopt.c,v 1.24 2002/06/21 09:56:33 wiz Exp $");
+#endif
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef __weak_alias
+__weak_alias(getopt,_getopt)
+#endif
+
+int    opterr = 1,             /* if error message should be printed */
+       optind = 1,             /* index into parent argv vector */
+       optopt,                 /* character checked for validity */
+       optreset;               /* reset getopt */
+char   *optarg;                /* argument associated with option */
+
+#define        BADCH   (int)'?'
+#define        BADARG  (int)':'
+#define        EMSG    ""
+
+/*
+ * getopt --
+ *     Parse argc/argv argument vector.
+ */
+int
+getopt(nargc, nargv, ostr)
+       int nargc;
+       char * const nargv[];
+       const char *ostr;
+{
+       static char *place = EMSG;              /* option letter processing */
+       char *oli;                              /* option letter list index */
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(ostr != NULL);
+
+       if (optreset || !*place) {              /* update scanning pointer */
+               optreset = 0;
+               if (optind >= nargc || *(place = nargv[optind]) != '-') {
+                       place = EMSG;
+                       return (-1);
+               }
+               if (place[1] && *++place == '-' /* found "--" */
+                   && place[1] == '\0') {
+                       ++optind;
+                       place = EMSG;
+                       return (-1);
+               }
+       }                                       /* option letter okay? */
+       if ((optopt = (int)*place++) == (int)':' ||
+           !(oli = strchr(ostr, optopt))) {
+               /*
+                * if the user didn't specify '-' as an option,
+                * assume it means -1.
+                */
+               if (optopt == (int)'-')
+                       return (-1);
+               if (!*place)
+                       ++optind;
+               if (opterr && *ostr != ':')
+                       (void)fprintf(stderr,
+                           "%s: unknown option -- %c\n", getprogname(),
+                           optopt);
+               return (BADCH);
+       }
+       if (*++oli != ':') {                    /* don't need argument */
+               optarg = NULL;
+               if (!*place)
+                       ++optind;
+       }
+       else {                                  /* need an argument */
+               if (*place)                     /* no white space */
+                       optarg = place;
+               else if (nargc <= ++optind) {   /* no arg */
+                       place = EMSG;
+                       if (*ostr == ':')
+                               return (BADARG);
+                       if (opterr)
+                               (void)fprintf(stderr,
+                                   "%s: option requires an argument -- %c\n",
+                                   getprogname(), optopt);
+                       return (BADCH);
+               }
+               else                            /* white space */
+                       optarg = nargv[optind];
+               place = EMSG;
+               ++optind;
+       }
+       return (optopt);                        /* dump back option letter */
+}
diff --git a/getopt_long.cpp b/getopt_long.cpp
new file mode 100644 (file)
index 0000000..4f11588
--- /dev/null
@@ -0,0 +1,488 @@
+/*  $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $      */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <err.h>
+#include <errno.h>
+#include <netbsdgetopt.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if HAVE_CONFIG_H && !HAVE_GETOPT_LONG && !HAVE_DECL_OPTIND
+#define REPLACE_GETOPT
+#endif
+
+#ifdef REPLACE_GETOPT
+#ifdef __weak_alias
+__weak_alias(getopt,_getopt)
+#endif
+int    opterr = 1;             /* if error message should be printed */
+int    optind = 1;             /* index into parent argv vector */
+int    optopt = '?';           /* character checked for validity */
+int    optreset;               /* reset getopt */
+char    *optarg;               /* argument associated with option */
+#elif HAVE_CONFIG_H && !HAVE_DECL_OPTRESET
+static int optreset;
+#endif
+
+#ifdef __weak_alias
+__weak_alias(getopt_long,_getopt_long)
+#endif
+
+#if !HAVE_GETOPT_LONG
+#define IGNORE_FIRST   (*options == '-' || *options == '+')
+#define PRINT_ERROR    ((opterr) && ((*options != ':') \
+                                     || (IGNORE_FIRST && options[1] != ':')))
+#define IS_POSIXLY_CORRECT (getenv("POSIXLY_CORRECT") != NULL)
+#define PERMUTE         (!IS_POSIXLY_CORRECT && !IGNORE_FIRST)
+/* XXX: GNU ignores PC if *options == '-' */
+#define IN_ORDER        (!IS_POSIXLY_CORRECT && *options == '-')
+
+/* return values */
+#define        BADCH   (int)'?'
+#define        BADARG          ((IGNORE_FIRST && options[1] == ':') \
+                        || (*options == ':') ? (int)':' : (int)'?')
+#define INORDER (int)1
+
+#define        EMSG    ""
+
+static int getopt_internal __P((int, char * const *, const char *));
+static int gcd __P((int, int));
+static void permute_args __P((int, int, int, char * const *));
+
+static char *place = EMSG; /* option letter processing */
+
+/* XXX: set optreset to 1 rather than these two */
+static int nonopt_start = -1; /* first non option argument (for permute) */
+static int nonopt_end = -1;   /* first option after non options (for permute) */
+
+/* Error messages */
+static const char recargchar[] = "option requires an argument -- %c";
+static const char recargstring[] = "option requires an argument -- %s";
+static const char ambig[] = "ambiguous option -- %.*s";
+static const char noarg[] = "option doesn't take an argument -- %.*s";
+static const char illoptchar[] = "unknown option -- %c";
+static const char illoptstring[] = "unknown option -- %s";
+
+
+/*
+ * Compute the greatest common divisor of a and b.
+ */
+static int
+gcd(a, b)
+       int a;
+       int b;
+{
+       int c;
+
+       c = a % b;
+       while (c != 0) {
+               a = b;
+               b = c;
+               c = a % b;
+       }
+          
+       return b;
+}
+
+/*
+ * Exchange the block from nonopt_start to nonopt_end with the block
+ * from nonopt_end to opt_end (keeping the same order of arguments
+ * in each block).
+ */
+static void
+permute_args(panonopt_start, panonopt_end, opt_end, nargv)
+       int panonopt_start;
+       int panonopt_end;
+       int opt_end;
+       char * const *nargv;
+{
+       int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos;
+       char *swap;
+
+       _DIAGASSERT(nargv != NULL);
+
+       /*
+        * compute lengths of blocks and number and size of cycles
+        */
+       nnonopts = panonopt_end - panonopt_start;
+       nopts = opt_end - panonopt_end;
+       ncycle = gcd(nnonopts, nopts);
+       cyclelen = (opt_end - panonopt_start) / ncycle;
+
+       for (i = 0; i < ncycle; i++) {
+               cstart = panonopt_end+i;
+               pos = cstart;
+               for (j = 0; j < cyclelen; j++) {
+                       if (pos >= panonopt_end)
+                               pos -= nnonopts;
+                       else
+                               pos += nopts;
+                       swap = nargv[pos];
+                       /* LINTED const cast */
+                       ((char **) nargv)[pos] = nargv[cstart];
+                       /* LINTED const cast */
+                       ((char **)nargv)[cstart] = swap;
+               }
+       }
+}
+
+/*
+ * getopt_internal --
+ *     Parse argc/argv argument vector.  Called by user level routines.
+ *  Returns -2 if -- is found (can be long option or end of options marker).
+ */
+static int
+getopt_internal(nargc, nargv, options)
+       int nargc;
+       char * const *nargv;
+       const char *options;
+{
+       char *oli;                              /* option letter list index */
+       int optchar;
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(options != NULL);
+
+       optarg = NULL;
+
+       /*
+        * XXX Some programs (like rsyncd) expect to be able to
+        * XXX re-initialize optind to 0 and have getopt_long(3)
+        * XXX properly function again.  Work around this braindamage.
+        */
+       if (optind == 0)
+               optind = 1;
+
+       if (optreset)
+               nonopt_start = nonopt_end = -1;
+start:
+       if (optreset || !*place) {              /* update scanning pointer */
+               optreset = 0;
+               if (optind >= nargc) {          /* end of argument vector */
+                       place = EMSG;
+                       if (nonopt_end != -1) {
+                               /* do permutation, if we have to */
+                               permute_args(nonopt_start, nonopt_end,
+                                   optind, nargv);
+                               optind -= nonopt_end - nonopt_start;
+                       }
+                       else if (nonopt_start != -1) {
+                               /*
+                                * If we skipped non-options, set optind
+                                * to the first of them.
+                                */
+                               optind = nonopt_start;
+                       }
+                       nonopt_start = nonopt_end = -1;
+                       return -1;
+               }
+               if ((*(place = nargv[optind]) != '-')
+                   || (place[1] == '\0')) {    /* found non-option */
+                       place = EMSG;
+                       if (IN_ORDER) {
+                               /*
+                                * GNU extension: 
+                                * return non-option as argument to option 1
+                                */
+                               optarg = nargv[optind++];
+                               return INORDER;
+                       }
+                       if (!PERMUTE) {
+                               /*
+                                * if no permutation wanted, stop parsing
+                                * at first non-option
+                                */
+                               return -1;
+                       }
+                       /* do permutation */
+                       if (nonopt_start == -1)
+                               nonopt_start = optind;
+                       else if (nonopt_end != -1) {
+                               permute_args(nonopt_start, nonopt_end,
+                                   optind, nargv);
+                               nonopt_start = optind -
+                                   (nonopt_end - nonopt_start);
+                               nonopt_end = -1;
+                       }
+                       optind++;
+                       /* process next argument */
+                       goto start;
+               }
+               if (nonopt_start != -1 && nonopt_end == -1)
+                       nonopt_end = optind;
+               if (place[1] && *++place == '-') {      /* found "--" */
+                       place++;
+                       return -2;
+               }
+       }
+       if ((optchar = (int)*place++) == (int)':' ||
+           (oli = strchr(options + (IGNORE_FIRST ? 1 : 0), optchar)) == NULL) {
+               /* option letter unknown or ':' */
+               if (!*place)
+                       ++optind;
+               if (PRINT_ERROR)
+                       warnx(illoptchar, optchar);
+               optopt = optchar;
+               return BADCH;
+       }
+       if (optchar == 'W' && oli[1] == ';') {          /* -W long-option */
+               /* XXX: what if no long options provided (called by getopt)? */
+               if (*place) 
+                       return -2;
+
+               if (++optind >= nargc) {        /* no arg */
+                       place = EMSG;
+                       if (PRINT_ERROR)
+                               warnx(recargchar, optchar);
+                       optopt = optchar;
+                       return BADARG;
+               } else                          /* white space */
+                       place = nargv[optind];
+               /*
+                * Handle -W arg the same as --arg (which causes getopt to
+                * stop parsing).
+                */
+               return -2;
+       }
+       if (*++oli != ':') {                    /* doesn't take argument */
+               if (!*place)
+                       ++optind;
+       } else {                                /* takes (optional) argument */
+               optarg = NULL;
+               if (*place)                     /* no white space */
+                       optarg = place;
+               /* XXX: disable test for :: if PC? (GNU doesn't) */
+               else if (oli[1] != ':') {       /* arg not optional */
+                       if (++optind >= nargc) {        /* no arg */
+                               place = EMSG;
+                               if (PRINT_ERROR)
+                                       warnx(recargchar, optchar);
+                               optopt = optchar;
+                               return BADARG;
+                       } else
+                               optarg = nargv[optind];
+               }
+               place = EMSG;
+               ++optind;
+       }
+       /* dump back option letter */
+       return optchar;
+}
+
+#ifdef REPLACE_GETOPT
+/*
+ * getopt --
+ *     Parse argc/argv argument vector.
+ *
+ * [eventually this will replace the real getopt]
+ */
+int
+getopt(nargc, nargv, options)
+       int nargc;
+       char * const *nargv;
+       const char *options;
+{
+       int retval;
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(options != NULL);
+
+       if ((retval = getopt_internal(nargc, nargv, options)) == -2) {
+               ++optind;
+               /*
+                * We found an option (--), so if we skipped non-options,
+                * we have to permute.
+                */
+               if (nonopt_end != -1) {
+                       permute_args(nonopt_start, nonopt_end, optind,
+                                      nargv);
+                       optind -= nonopt_end - nonopt_start;
+               }
+               nonopt_start = nonopt_end = -1;
+               retval = -1;
+       }
+       return retval;
+}
+#endif
+
+/*
+ * getopt_long --
+ *     Parse argc/argv argument vector.
+ */
+int
+getopt_long(nargc, nargv, options, long_options, idx)
+       int nargc;
+       char * const *nargv;
+       const char *options;
+       const struct option *long_options;
+       int *idx;
+{
+       int retval;
+
+       _DIAGASSERT(nargv != NULL);
+       _DIAGASSERT(options != NULL);
+       _DIAGASSERT(long_options != NULL);
+       /* idx may be NULL */
+
+       if ((retval = getopt_internal(nargc, nargv, options)) == -2) {
+               char *current_argv, *has_equal;
+               size_t current_argv_len;
+               int i, match;
+
+               current_argv = place;
+               match = -1;
+
+               optind++;
+               place = EMSG;
+
+               if (*current_argv == '\0') {            /* found "--" */
+                       /*
+                        * We found an option (--), so if we skipped
+                        * non-options, we have to permute.
+                        */
+                       if (nonopt_end != -1) {
+                               permute_args(nonopt_start, nonopt_end,
+                                   optind, nargv);
+                               optind -= nonopt_end - nonopt_start;
+                       }
+                       nonopt_start = nonopt_end = -1;
+                       return -1;
+               }
+               if ((has_equal = strchr(current_argv, '=')) != NULL) {
+                       /* argument found (--option=arg) */
+                       current_argv_len = has_equal - current_argv;
+                       has_equal++;
+               } else
+                       current_argv_len = strlen(current_argv);
+           
+               for (i = 0; long_options[i].name; i++) {
+                       /* find matching long option */
+                       if (strncmp(current_argv, long_options[i].name,
+                           current_argv_len))
+                               continue;
+
+                       if (strlen(long_options[i].name) ==
+                           (unsigned)current_argv_len) {
+                               /* exact match */
+                               match = i;
+                               break;
+                       }
+                       if (match == -1)                /* partial match */
+                               match = i;
+                       else {
+                               /* ambiguous abbreviation */
+                               if (PRINT_ERROR)
+                                       warnx(ambig, (int)current_argv_len,
+                                            current_argv);
+                               optopt = 0;
+                               return BADCH;
+                       }
+               }
+               if (match != -1) {                      /* option found */
+                       if (long_options[match].has_arg == no_argument
+                           && has_equal) {
+                               if (PRINT_ERROR)
+                                       warnx(noarg, (int)current_argv_len,
+                                            current_argv);
+                               /*
+                                * XXX: GNU sets optopt to val regardless of
+                                * flag
+                                */
+                               if (long_options[match].flag == NULL)
+                                       optopt = long_options[match].val;
+                               else
+                                       optopt = 0;
+                               return BADARG;
+                       }
+                       if (long_options[match].has_arg == required_argument ||
+                           long_options[match].has_arg == optional_argument) {
+                               if (has_equal)
+                                       optarg = has_equal;
+                               else if (long_options[match].has_arg ==
+                                   required_argument) {
+                                       /*
+                                        * optional argument doesn't use
+                                        * next nargv
+                                        */
+                                       optarg = nargv[optind++];
+                               }
+                       }
+                       if ((long_options[match].has_arg == required_argument)
+                           && (optarg == NULL)) {
+                               /*
+                                * Missing argument; leading ':'
+                                * indicates no error should be generated
+                                */
+                               if (PRINT_ERROR)
+                                       warnx(recargstring, current_argv);
+                               /*
+                                * XXX: GNU sets optopt to val regardless
+                                * of flag
+                                */
+                               if (long_options[match].flag == NULL)
+                                       optopt = long_options[match].val;
+                               else
+                                       optopt = 0;
+                               --optind;
+                               return BADARG;
+                       }
+               } else {                        /* unknown option */
+                       if (PRINT_ERROR)
+                               warnx(illoptstring, current_argv);
+                       optopt = 0;
+                       return BADCH;
+               }
+               if (long_options[match].flag) {
+                       *long_options[match].flag = long_options[match].val;
+                       retval = 0;
+               } else 
+                       retval = long_options[match].val;
+               if (idx)
+                       *idx = match;
+       }
+       return retval;
+}
+#endif /* !GETOPT_LONG */
diff --git a/gettext_wrapper.h b/gettext_wrapper.h
new file mode 100644 (file)
index 0000000..e727edb
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+  gettext_wrapper.h  gettext wrapper
+
+  Made by Daisuke Nagano <breeze_nagano@nifty.ne.jp>
+  Mar.29.1998 
+
+ */
+#pragma once
+
+#ifndef _GETTEXT_WRAPPER_H_
+#define _GETTEXT_WRAPPER_H_
+
+#ifdef ENABLE_NLS
+# include <locale.h>
+# include <libintl.h>
+# undef _
+# define _(string) gettext(string)
+# define N_(String) (String)
+
+#else /* ENABLE_NLS */
+# define _(string) string
+# define N_(String) (String)
+#endif /* ENABLE_NLS */
+
+#endif /* _GETTEXT_WRAPPER_H_ */
+
diff --git a/graph.cpp b/graph.cpp
new file mode 100644 (file)
index 0000000..351163d
--- /dev/null
+++ b/graph.cpp
@@ -0,0 +1,122 @@
+/*
+  graph.c
+
+  glue layer for drivers
+
+  g_print rev_area tg_copy tg_copy2 t_scrw txcur
+
+  Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+void
+g_print( int in_x, int in_y, char *in_str, int in_col )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->SetGraphicsColor(in_col);
+  scr->GraphicsPuts(in_x, in_y, in_str);
+
+  return;
+}
+
+void
+rev_area( int in_r_ad, int in_r_ln, int in_edit_scr )
+{
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->TextReverseArea(in_r_ad, in_r_ln, in_edit_scr);
+  return;
+}
+
+void
+tg_copy( int in_edit_scr )
+{
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  /* T_VRAM to G_VRAM */
+  /* edit_scr=0 : left, edit_scr=1 : right  */
+  /* (2,4)-(19,31)      (58, 4)-(75,31)     */
+
+  scr->CopyTextToGraphics(in_edit_scr);
+  return;
+}
+
+void
+tg_copy2( int in_edit_scr )
+{
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  /* T_VRAM to G_VRAM */
+  /* edit_scr=0 : left, edit_scr=1 : right  */
+  /* (0,6)-(27,29)         (38,6)-(65,29) */
+
+  scr->CopyTextToGraphics2(in_edit_scr);
+  return;
+}
+
+void
+t_scrw( int in_x0, int in_y0, int in_xs, int in_ys, int in_x1, int in_y1 ) {
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->TextScroll(in_x0, in_y0, in_xs, in_ys, in_x1, in_y1);
+  return;
+}
+
+void
+txcur( int in_a, int in_b, int in_c1, int in_c2, int in_cs )
+{
+
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  int i;
+
+  if ( edit_scr ) in_a+=56; // edit_scr: grobal variable
+  for (i=0; i<in_c2; i++) {
+    scr->TextReverse(in_a, in_b+i, in_c1, in_cs);
+  }
+  return;
+}
diff --git a/graph.h b/graph.h
new file mode 100644 (file)
index 0000000..80a3359
--- /dev/null
+++ b/graph.h
@@ -0,0 +1,42 @@
+/* graph.h
+
+   dummy header file for X680x0 compatible
+
+   Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef _GRAPH_H_
+#define _GRAPH_H_
+
+/* defines */
+
+#ifndef PI
+#define PI M_PI
+#endif /* PI */
+
+#ifndef PID2
+#define PID2 PI/2
+#endif /* PID2 */
+
+
+#endif /* _GRAPH_H_ */
diff --git a/graphic.cpp b/graphic.cpp
new file mode 100644 (file)
index 0000000..e69320f
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * STed: graph.c (grapihc subroutine)
+ */
+
+#include       "sted.h"
+
+#define                TXRAM   0xe00000
+#define                GVRAM   0xc00000
+#define                PL1     (0x20000/2)
+#define                PL2     (0x20000)
+
+/***************************/
+/*
+  void g_print(int x,int y,unsigned char *s,int c)
+  {
+  int  sta;
+  short        j;
+  unsigned short       a;
+  unsigned char        pat;
+
+  unsigned short       *gptr= (unsigned short*)(GVRAM);
+  unsigned short       *gptr2;
+  unsigned char        *pp;
+
+  struct       FNTBUF  *fntb,buf;
+  fntb=&buf;
+
+  sta=SUPER(0);
+
+  gptr+=(y*1024+x);
+
+  while(*s!=0){
+  a=*s++;if( 127<a && (161>a || 224<a) ){a=a*256+*s++;}
+  FNTGET(8,a,fntb);gptr2=gptr;pp=&fntb->buffer;j=16;
+  if( fntb->xl==16 ){
+  while(j){
+  pat=*pp++;
+  if(pat!=0){
+  if((pat&128)){gptr2[0]=c;}if((pat& 64)){gptr2[1]=c;}
+  if((pat& 32)){gptr2[2]=c;}if((pat& 16)){gptr2[3]=c;}
+  if((pat&  8)){gptr2[4]=c;}if((pat&  4)){gptr2[5]=c;}
+  if((pat&  2)){gptr2[6]=c;}if((pat&  1)){gptr2[7]=c;}
+  }
+  pat=*pp++;
+  if(pat!=0){
+  if((pat&128)){gptr2[ 8]=c;}if((pat& 64)){gptr2[ 9]=c;}
+  if((pat& 32)){gptr2[10]=c;}if((pat& 16)){gptr2[11]=c;}
+  if((pat&  8)){gptr2[12]=c;}if((pat&  4)){gptr2[13]=c;}
+  if((pat&  2)){gptr2[14]=c;}if((pat&  1)){gptr2[15]=c;}
+  }
+  gptr2+=1024;j--;
+  }
+  gptr+=16;
+  }else{
+  while(j){
+  pat=*pp++;
+  if(pat!=0){
+  if((pat&128)){gptr2[0]=c;}if((pat& 64)){gptr2[1]=c;}
+  if((pat& 32)){gptr2[2]=c;}if((pat& 16)){gptr2[3]=c;}
+  if((pat&  8)){gptr2[4]=c;}if((pat&  4)){gptr2[5]=c;}
+  if((pat&  2)){gptr2[6]=c;}if((pat&  1)){gptr2[7]=c;}
+  }
+  gptr2+=1024;j--;
+  }
+  gptr+=8;
+  }
+  }
+  SUPER(sta);
+  }
+  */
+/***************************/
+/*
+void   tcur(int a,int b,int c,int cs)
+{
+       struct  TREVPTR *txrev,buf;
+
+       if(edit_scr==1){a+=56;}
+
+       txrev=&buf;txrev->x=a*8;txrev->y=b*16;txrev->x1=c*8;txrev->y1=16;
+
+       if(cs!=2){txrev->vram_page=0;TXREV(txrev);}
+       if(cs!=1){txrev->vram_page=1;TXREV(txrev);}
+}
+void   tcury(int a,int b,int c,int cs)
+{
+       struct  TREVPTR *txrev,buf;
+
+       if(edit_scr==1){a+=56;}
+
+       txrev=&buf;txrev->x=a*8;txrev->y=b*16;txrev->x1=8;txrev->y1=c*16;
+
+       if(cs!=2){txrev->vram_page=0;TXREV(txrev);}
+       if(cs!=1){txrev->vram_page=1;TXREV(txrev);}
+}
+*/
+void   tcur(int a,int b,int c,int cs)
+{
+  txcur(a,b,c,1,cs);
+}
+void   tcury(int a,int b,int c,int cs)
+{
+  txcur(a,b,1,c,cs);
+}
+
+/***************************/
+void   txerase(int x,int y,int x1,int y1)
+{
+  struct       X68_TXFILLPTR   *txfil,buf;
+  unsigned short       sv;
+
+  txfil=&buf;txfil->x=x;txfil->y=y;txfil->x1=x1;txfil->y1=y1;txfil->fill_patn=0;
+  sv=B_WPEEK((unsigned short*)0xe8002a);B_WPOKE((unsigned short*)0xe8002a,0x133);
+  txfil->vram_page=0;TXFILL(txfil);
+  B_WPOKE((unsigned short*)0xe8002a,sv);
+}
+
+/***************************/
+/*
+  void txfill(int x,int y,int x1,int y1,int page,int pat)
+  {
+  struct       X68_TXFILLPTR   *tfill,buf;
+
+  tfill=&buf;tfill->x;tfill->y;tfill->x1=x1;tfill->y1=y1;tfill->fill_patn=pat;
+  tfill->vram_page=page;TXFILL(tfill);
+  }
+  */
+/***************************/
+void   txxline(int x,int y,int x1,int page,int style)
+{
+  struct       X68_XLINEPTR    *txline,buf;
+
+  txline=&buf;txline->x=x;txline->y=y;txline->x1=x1;txline->line_style=style;
+  txline->vram_page=page;TXXLINE(txline);
+}
+
+/***************************/
+void   txyline(int x,int y,int y1,int page,int style)
+{
+  struct       X68_YLINEPTR    *tyline,buf;
+
+  tyline=&buf;tyline->x=x;tyline->y=y;tyline->y1=y1;tyline->line_style=style;
+  tyline->vram_page=page;TXYLINE(tyline);
+}
+
+/***************************/
+
diff --git a/hprint.cpp b/hprint.cpp
new file mode 100644 (file)
index 0000000..6298aca
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+  hprint.c
+
+  functions for compatibility in hprint.s
+  "extremely fast print functions"
+
+  H_INIT , H_PRINT , H_PRINT2
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+void
+H_INIT ( void )
+{
+
+  /* not implemented */
+  return;
+}
+
+void
+H_PRINT ( char *in_s1, char *in_s2, char *in_s3 )
+{
+  CSTedScreenBase* scr;
+  int x,y;
+  int l=0;
+  int c;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  x=B_LOCATE(-1,0);
+  y=x&0xffff;
+  x=x>>16;
+
+  scr->Locate(0, y);
+  scr->ClsEol();
+
+  scr->Locate(x,y);
+  if (in_s1) {
+    c = scr->SetTextColor(3);
+    scr->Puts(in_s1);
+    scr->SetTextColor(c);
+    l = strlen(in_s1);
+  }
+
+  if (in_s2) {
+    c = scr->SetTextColor(2);
+    scr->Puts(in_s2);
+    scr->SetTextColor(c);
+    l+=strlen(in_s2);
+  }
+
+  if (in_s3) {
+    c = scr->SetTextColor(1);
+    scr->Puts(in_s3);
+    scr->SetTextColor(c);
+    l+=strlen(in_s3);
+  }
+
+  B_LOCATE(x+l,y);
+
+  return;
+}
+
+void
+H_PRINT2 ( char *in_s1, char *in_s2, char *in_s3 )
+{
+  CSTedScreenBase* scr;
+  int x,y;
+  int l=0;
+  int c;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  x=B_LOCATE(-1,0);
+  y=x&0xffff;
+  x=x>>16;
+
+  scr->Locate(x,y);
+  if (in_s1) {
+    c = scr->SetTextColor(3);
+    scr->Puts(in_s1);
+    scr->SetTextColor(c);
+    l = strlen(in_s1);
+  }
+
+  if (in_s2) {
+    c = scr->SetTextColor(c);
+    scr->Puts(in_s2);
+    scr->SetTextColor(c);
+    l+=strlen(in_s2);
+  }
+
+  if (in_s3) {
+    c = scr->SetTextColor(c);
+    scr->Puts(in_s3);
+    scr->SetTextColor(c);
+    l+=strlen(in_s3);
+  }
+
+  B_LOCATE(x+l,y);
+  return;
+}
+
diff --git a/iocs.cpp b/iocs.cpp
new file mode 100644 (file)
index 0000000..490dfce
--- /dev/null
+++ b/iocs.cpp
@@ -0,0 +1,56 @@
+/*
+  iocs.c
+
+  functions for compatibility to iocslib
+  ( containing misc functions )
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+/* etc */
+
+int
+_iocs_b_wpeek( const void *adr ) {
+
+  return 0; /* ignore */
+}
+
+void
+_iocs_b_wpoke( void *adr, int val ) {
+
+  return; /* ignore */
+}
+
+int
+_iocs_ontime ( void ) {
+       CSTedScreenBase* scr;
+
+       scr = GetDriver();
+       if (!scr) return 0;
+
+       return scr->OnTime();
+}
+
diff --git a/iocs_console.cpp b/iocs_console.cpp
new file mode 100644 (file)
index 0000000..d953c7c
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+  iocs_console.c
+
+  functions for compatibility to iocslib
+  ( containing mainly console oriented functions )
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+/* local val.s */
+
+unsigned int iocs_current_console_width=96, iocs_current_console_height=32;
+unsigned int iocs_console_xtop=0, iocs_console_ytop=0;
+unsigned int iocs_current_text_x=0, iocs_current_text_y=0;
+unsigned int iocs_current_color=15;
+
+/* functions */
+
+/* console */
+
+int
+_iocs_b_consol( int xs, int ys, int xl, int yl )
+{
+  iocs_current_console_width =xl+1;
+  iocs_current_console_height=yl+1;
+
+  iocs_console_xtop = xs/8;
+  iocs_console_ytop = ys/8;
+
+  iocs_current_text_x = 0;
+  iocs_current_text_y = 0;
+
+  return xl*65536+yl;
+}
+
+int
+_iocs_b_color( int in_color )
+{
+  int c;
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  c = iocs_current_color;
+  iocs_current_color = in_color;
+
+  scr->SetTextColor(in_color);
+  return c;
+}
+
+int
+_iocs_b_print( const char *in_message )
+{
+  int x,y;
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  scr->Puts(in_message);
+
+  x = iocs_current_text_x + strlen(in_message);
+  y = iocs_current_text_y;
+  if ( x >= iocs_current_console_width ) {
+    x %= iocs_current_console_width;
+    x += iocs_console_xtop;
+    y ++;
+  }
+  if ( y >= iocs_current_console_height ) {
+    y=iocs_current_console_height-1;
+  }
+
+  iocs_current_text_x = x;
+  iocs_current_text_y = y;
+
+  return (x<<16)+y;
+}
+
+int
+_iocs_b_putmes ( int in_col, int in_x, int in_y, int in_width, const char *in_str )
+{
+  int c;
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  c = scr->SetTextColor(in_col);
+  scr->Locate(in_x, in_y);
+  scr->Puts(in_str);
+  scr->SetTextColor(c);
+  scr->Locate( iocs_current_text_x+iocs_console_xtop,
+              iocs_current_text_y+iocs_console_ytop);
+  return 0;
+}
+
+int
+_iocs_b_locate( int in_x0, int in_y0 )
+{
+  int old_x, old_y;
+  int x,y;
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  old_x = iocs_current_text_x;
+  old_y = iocs_current_text_y;
+
+  if ( in_x0 != -1 ) {
+    iocs_current_text_x = in_x0;
+    iocs_current_text_y = in_y0;
+    /*
+    if ( in_x0 >= iocs_current_console_width ) return -1;
+    else if ( in_y0 >= iocs_current_console_height ) return -1;
+    */
+    x = in_x0+iocs_console_xtop;
+    y = in_y0+iocs_console_ytop;
+
+    scr->Locate(x,y);
+  }
+
+  return (old_x<<16)+old_y;
+}
+
+void
+_iocs_b_clr_al( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->ClsAll();
+
+  iocs_current_text_x = 0;
+  iocs_current_text_y = 0;
+
+  return;
+}
+
+void
+_iocs_b_clr_ed ( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->ClsEd();
+  return;
+}
+
+/* fonts */
+
+int
+_iocs_defchr( int type, int code, const void *buff )
+{
+  /* not implemented */
+  return 0;
+}
+
+int
+_iocs_fntget( int type, int code, struct _x68_fntbuf *fntbuf )
+{
+  /* not implemented */
+  return 0;
+}
+
diff --git a/iocs_graph.cpp b/iocs_graph.cpp
new file mode 100644 (file)
index 0000000..cf10626
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+  iocs_graph.c
+
+  functions for compatibility to iocslib
+  ( containing mainly graphics oriented functions )
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+/* variables */
+
+//int iocs_graph_home;
+
+/* functions */
+
+int
+_iocs_crtmod( int in_mode )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  if ( in_mode < 0x100 ) {
+    if ( in_mode==17 ) {
+      scr->CloseWindow();
+    } else {
+      scr->InitWindow();
+      scr->ClsAll();
+    }
+  }
+
+  return 0;
+}
+
+void
+_iocs_g_clr_on( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->GraphicsClear();
+
+  return;
+}
+
+int
+_iocs_gpalet( int in_no, int in_color )
+{
+  int ret=0;
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  ret = scr->SetGraphicsPalette(in_no, in_color);
+  return ret;
+}
+
+int
+_iocs_home( int in_page, int in_x, int in_y )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  /* y=0 or 512 ( page select? ) */
+
+  iocs_graph_home = in_y>511 ? 1:0;
+  scr->GraphicsHome(iocs_graph_home);
+  return 0;
+}
+
+int
+_iocs_tgusemd( int text_gr, int mode )
+{
+  return 0; /* G-RAM is not used */
+}
+
+int
+_iocs_window( int sx, int sy, int ex, int ey )
+{
+
+  return 0; /* ignore */
+}
+
diff --git a/iocs_key.cpp b/iocs_key.cpp
new file mode 100644 (file)
index 0000000..0ef5c86
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+  iocs_key.c
+
+  functions for compatibility to iocslib
+  ( containing mainly key oriented functions )
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+// dummy
+char KEY_XF1[128];               /* keysym names */
+char KEY_XF2[128];
+char KEY_XF3[128];
+char KEY_XF4[128];
+char KEY_XF5[128];
+char KEY_KANA[128];
+char KEY_KIGO[128];
+char KEY_TOROKU[128];
+char KEY_INS[128];
+char KEY_DEL[128];
+char KEY_HOME[128];
+char KEY_UNDO[128];
+char KEY_RUP[128];
+char KEY_RDOWN[128];
+char KEY_OPT1[128];
+char KEY_OPT2[128];
+
+/* key input */
+
+void
+_iocs_ledmod( int in_code, int in_onoff )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->LedMode(in_code, in_onoff);
+  return;
+}
+
+int
+_iocs_b_keyinp( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->KeyInp();
+}
+
+int
+_iocs_b_keysns( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->KeySense();
+}
+
+int
+_iocs_b_sftsns( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->SftSense();
+}
+
+int
+_iocs_bitsns( int in_group )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->BitSense(in_group);
+}
+
diff --git a/iocs_mouse.cpp b/iocs_mouse.cpp
new file mode 100644 (file)
index 0000000..292bf74
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+  iocs_mouse.c.c
+
+  functions for compatibility to iocslib
+  ( containing mouse oriented functions )
+
+  Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+/* functions */
+
+void
+_iocs_ms_curof( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->SetMouseCursorVisible(EButtonOff);
+  return;
+}
+
+void
+_iocs_ms_curon( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->SetMouseCursorVisible(EButtonOn);
+  return;
+}
+
+int
+_iocs_ms_getdt( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->GetMouseButtonState();
+}
+
+void _iocs_ms_init( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->MouseInit();
+  return;
+}
+
+int
+_iocs_ms_limit( int in_xs, int in_ys, int in_xe, int in_ye )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->SetMouseMoveLimit(in_xs, in_ys, in_xe, in_ye);
+}
+
diff --git a/iocs_tgraph.cpp b/iocs_tgraph.cpp
new file mode 100644 (file)
index 0000000..c569c46
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+  iocs_tgraph.c
+
+  functions for compatibility to iocslib
+  ( containing mainly text-graphics oriented functions )
+
+  Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+
+int
+_iocs_tpalet( int in_no, int in_code )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->SetTextPalette(in_no, in_code);
+}
+
+void
+_iocs_txbox( const struct _x68_txfillptr *ptr )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->TextXBox( ptr->x, ptr->y, ptr->x1, ptr->y1, ptr->vram_page );
+  return;
+}
+
+void
+_iocs_txfill ( const struct _x68_txfillptr *ptr )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->TextFill( ptr->vram_page, ptr->x, ptr->y, ptr->x1, ptr->y1, ptr->fill_patn );
+
+  return;
+}
+
+void
+_iocs_txrascpy ( int sr_dst, int copy, int mode )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+  scr->TextRasterCopy( sr_dst&0xff, sr_dst>>8, copy, mode );
+  return;
+}
+
+void
+_iocs_txxline ( const struct _x68_xlineptr *ptr )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->TextXXLine( ptr->vram_page, ptr->x, ptr->y, ptr->x1, ptr->line_style );
+  return;
+}
+
+void
+_iocs_txyline ( const struct _x68_ylineptr *ptr )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->TextXYLine( ptr->vram_page, ptr->x, ptr->y, ptr->y1, ptr->line_style );
+  return;
+}
+
diff --git a/iocslib.h b/iocslib.h
new file mode 100644 (file)
index 0000000..e8eba18
--- /dev/null
+++ b/iocslib.h
@@ -0,0 +1,277 @@
+/* iocslib.h
+
+   dummy header file for X680x0 compatible
+
+   Made by Studio Breeze. 1998
+
+*/
+#pragma once
+
+#ifndef _X68_IOCSLIB_H_
+#define _X68_IOCSLIB_H_
+
+/* structs */
+
+struct _x68_fntbuf {
+  short x1;                  /* dots of x-dir */
+  short y1;                  /* dots of y-dir */
+  unsigned char buffer[72];  /* reading buffer */
+};
+
+#define X68_FNTBUF _x68_fntbuf
+
+struct _x68_txfillptr {
+  unsigned short vram_page;  /* text page */
+  short x;                   /* x position of start point */
+  short y;                   /* y position of start point */
+  short x1;                  /* x position of end point */
+  short y1;                  /* y position of end point */
+  unsigned short fill_patn;  /* pattern of filling */
+};
+
+#define X68_TXFILLPTR _x68_txfillptr
+#define X68_TXBOXPTR  _x68_txfillptr
+
+struct _x68_xlineptr {
+  unsigned short vram_page;  /* text page */
+  short x;                   /* x position of start point */
+  short y;                   /* y position of start point */
+  short x1;                  /* x length to end point */
+  unsigned short line_style; /* pattern of filling */
+};
+
+#define X68_XLINEPTR _x68_xlineptr
+
+struct _x68_ylineptr {
+  unsigned short vram_page;  /* text page */
+  short x;                   /* x position of start point */
+  short y;                   /* y position of start point */
+  short y1;                  /* y length to end point */
+  unsigned short line_style; /* pattern of filling */
+};
+
+#define X68_YLINEPTR _x68_ylineptr
+
+
+/* defines for upper-cased-name functions */
+
+#define READCAP                _readcap
+#define INQUIRY                _inquiry
+
+#define ABORTJOB       _iocs_abortjob
+#define ABORTRST       _iocs_abortrst
+#define ADPCMINP       _iocs_adpcminp
+#define ADPCMMOD       _iocs_adpcmmod
+#define ADPCMOUT       _iocs_adpcmout
+#define ADPCMSNS       _iocs_adpcmsns
+#define AKCONV         _iocs_akconv
+#define ALARMGET       _iocs_alarmget
+#define ALARMMOD       _iocs_alarmmod
+#define ALARMSET       _iocs_alarmset
+#define APAGE          _iocs_apage
+#define BGCTRLGT       _iocs_bgctrlgt
+#define BGCTRLST       _iocs_bgctrlst
+#define BGSCRLGT       _iocs_bgscrlgt
+#define BGSCRLST       _iocs_bgscrlst
+#define BGTEXTCL       _iocs_bgtextcl
+#define BGTEXTGT       _iocs_bgtextgt
+#define BGTEXTST       _iocs_bgtextst
+#define BINDATEBCD     _iocs_bindatebcd
+#define BINDATEGET     _iocs_bindateget
+#define BINDATESET     _iocs_bindateset
+#define BITSNS         _iocs_bitsns
+#define BOOTINF                _iocs_bootinf
+#define BOX            _iocs_box
+#define B_ASSIGN       _iocs_b_assign
+#define B_BADFMT       _iocs_b_badfmt
+#define B_BPEEK                _iocs_b_bpeek
+#define B_BPOKE                _iocs_b_bpoke
+#define B_CLR_AL       _iocs_b_clr_al
+#define B_CLR_ED       _iocs_b_clr_ed
+#define B_CLR_ST       _iocs_b_clr_st
+#define B_COLOR                _iocs_b_color
+#define B_CONSOL       _iocs_b_consol
+#define B_CUROFF       _iocs_b_curoff
+#define B_CURON                _iocs_b_curon
+#define B_DEL          _iocs_b_del
+#define B_DOWN         _iocs_b_down
+#define B_DOWN_S       _iocs_b_down_s
+#define B_DRVCHK       _iocs_b_drvchk
+#define B_DRVSNS       _iocs_b_drvsns
+#define B_DSKINI       _iocs_b_dskini
+#define B_EJECT                _iocs_b_eject
+#define B_ERA_AL       _iocs_b_era_al
+#define B_ERA_ED       _iocs_b_era_ed
+#define B_ERA_ST       _iocs_b_era_st
+#define B_FORMAT       _iocs_b_format
+#define B_INS          _iocs_b_ins
+#define B_INTVCS       _iocs_b_intvcs
+#define B_KEYINP       _iocs_b_keyinp
+#define B_KEYSNS       _iocs_b_keysns
+#define B_LEFT         _iocs_b_left
+#define B_LOCATE       _iocs_b_locate
+#define B_LPEEK                _iocs_b_lpeek
+#define B_LPOKE                _iocs_b_lpoke
+#define B_MEMSET       _iocs_b_memset
+#define B_MEMSTR       _iocs_b_memstr
+#define B_PRINT                _iocs_b_print
+#define B_PUTC         _iocs_b_putc
+#define B_PUTMES       _iocs_b_putmes
+#define B_READ         _iocs_b_read
+#define B_READDI       _iocs_b_readdi
+#define B_READDL       _iocs_b_readdl
+#define B_READID       _iocs_b_readid
+#define B_RECALI       _iocs_b_recali
+#define B_RIGHT                _iocs_b_right
+#define B_SEEK         _iocs_b_seek
+#define B_SFTSNS       _iocs_b_sftsns
+#define B_SUPER                _iocs_b_super
+#define B_UP           _iocs_b_up
+#define B_UP_S         _iocs_b_up_s
+#define B_VERIFY       _iocs_b_verify
+#define B_WPEEK                _iocs_b_wpeek
+#define B_WPOKE                _iocs_b_wpoke
+#define B_WRITE                _iocs_b_write
+#define B_WRITED       _iocs_b_writed
+#define CIRCLE         _iocs_circle
+#define CLIPPUT                _iocs_clipput
+#define CONTRAST       _iocs_contrast
+#define CRTCRAS                _iocs_crtcras
+#define CRTMOD         _iocs_crtmod
+#define DAKJOB         _iocs_dakjob
+#define DATEASC                _iocs_dateasc
+#define DATEBIN                _iocs_datebin
+#define DATECNV                _iocs_datecnv
+#define DAYASC         _iocs_dayasc
+#define DEFCHR         _iocs_defchr
+#define DENSNS         _iocs_densns
+#define DMAMODE                _iocs_dmamode
+#define DMAMOVE                _iocs_dmamove
+#define FILL           _iocs_fill
+#define FNTGET         _iocs_fntget
+#define GPALET         _iocs_gpalet
+#define G_CLR_ON       _iocs_g_clr_on
+#define HANJOB         _iocs_hanjob
+#define HOME           _iocs_home
+#define HSVTORGB       _iocs_hsvtorgb
+#define HSYNCST                _iocs_hsyncst
+#define INIT_PRN       _iocs_init_prn
+#define INP232C                _iocs_inp232c
+#define IPLERR         _iocs_iplerr
+#define ISNS232C       _iocs_isns232c
+#define JISSFT         _iocs_jissft
+#define JOYGET         _iocs_joyget
+#define LEDMOD         _iocs_ledmod
+#define LINE           _iocs_line
+#define LOF232C                _iocs_lof232c
+#define MS_CURGT       _iocs_ms_curgt
+#define MS_CUROF       _iocs_ms_curof
+#define MS_CURON       _iocs_ms_curon
+#define MS_CURST       _iocs_ms_curst
+#define MS_GETDT       _iocs_ms_getdt
+#define MS_INIT                _iocs_ms_init
+#define MS_LIMIT       _iocs_ms_limit
+#define MS_OFFTM       _iocs_ms_offtm
+#define MS_ONTM                _iocs_ms_ontm
+#define MS_PATST       _iocs_ms_patst
+#define MS_SEL         _iocs_ms_sel
+#define MS_SEL2                _iocs_ms_sel2
+#define MS_STAT                _iocs_ms_stat
+#define ONTIME         _iocs_ontime
+#define OPMINTST       _iocs_opmintst
+#define OPMSET         _iocs_opmset
+#define OPMSNS         _iocs_opmsns
+#define OSNS232C       _iocs_osns232c
+#define OS_CUROF       _iocs_os_curof
+#define OS_CURON       _iocs_os_curon
+#define OUT232C                _iocs_out232c
+#define OUTLPT         _iocs_outlpt
+#define OUTPRN         _iocs_outprn
+#define POINT          _iocs_point
+#define PRNINTST       _iocs_prnintst
+#define PSET           _iocs_pset
+#define RMACNV         _iocs_rmacnv
+#define ROMVER         _iocs_romver
+#define SCROLL         _iocs_scroll
+#define SET232C                _iocs_set232c
+#define SFTJIS         _iocs_sftjis
+#define SKEYSET                _iocs_skeyset
+#define SKEY_MOD       _iocs_skey_mod
+#define SNSPRN         _iocs_snsprn
+#define SPALET         _iocs_spalet
+#define SP_CGCLR       _iocs_sp_cgclr
+#define SP_DEFCG       _iocs_sp_defcg
+#define SP_GTPCG       _iocs_sp_gtpcg
+#define SP_INIT                _iocs_sp_init
+#define SP_OFF         _iocs_sp_off
+#define SP_ON          _iocs_sp_on
+#define SP_REGGT       _iocs_sp_reggt
+#define SP_REGST       _iocs_sp_regst
+#define SYMBOL         _iocs_symbol
+#define TCOLOR         _iocs_tcolor
+#define TEXTGET                _iocs_textget
+#define TEXTPUT                _iocs_textput
+#define TGUSEMD                _iocs_tgusemd
+#define TIMEASC                _iocs_timeasc
+#define TIMEBCD                _iocs_timebcd
+#define TIMEBIN                _iocs_timebin
+#define TIMECNV                _iocs_timecnv
+#define TIMEGET                _iocs_timeget
+#define TIMERDST       _iocs_timerdst
+#define TIMESET                _iocs_timeset
+#define TPALET         _iocs_tpalet
+#define TPALET2                _iocs_tpalet2
+#define TRAP15         _iocs_trap15
+#define TVCTRL         _iocs_tvctrl
+#define TXBOX          _iocs_txbox
+#define TXFILL         _iocs_txfill
+#define TXRASCPY       _iocs_txrascpy
+#define TXREV          _iocs_txrev
+#define TXXLINE                _iocs_txxline
+#define TXYLINE                _iocs_txyline
+#define VDISPST                _iocs_vdispst
+#define VPAGE          _iocs_vpage
+#define WINDOW         _iocs_window
+#define WIPE           _iocs_wipe
+
+/* functions */
+
+
+ void _iocs_b_clr_al (void);
+ void _iocs_b_clr_ed (void);
+ int  _iocs_b_color (int);
+ int  _iocs_b_consol (int, int, int, int);
+ int  _iocs_b_keyinp (void);
+ int  _iocs_b_keysns (void);
+ int  _iocs_b_locate (int, int);
+ int  _iocs_b_putmes (int, int, int, int, const char *);
+ int  _iocs_b_print (const char *);
+ int  _iocs_b_sftsns (void);
+ int  _iocs_b_wpeek (const void *);
+ void _iocs_b_wpoke (void *, int);
+ int  _iocs_bitsns (int);
+ int  _iocs_crtmod (int);
+ int  _iocs_defchr (int, int, const void *);
+ int  _iocs_fntget (int, int, struct _x68_fntbuf *);
+ void _iocs_g_clr_on (void);
+ int  _iocs_gpalet (int, int);
+ int  _iocs_home (int, int, int);
+ void _iocs_ledmod (int, int);
+ void _iocs_ms_curof (void);
+ void _iocs_ms_curon (void);
+ int  _iocs_ms_getdt (void);
+ void _iocs_ms_init (void);
+ int  _iocs_ms_limit (int, int, int, int);
+ int  _iocs_ontime (void);
+ int  _iocs_tgusemd (int, int);
+ int  _iocs_tpalet (int, int);
+ void _iocs_txbox (const struct _x68_txfillptr *);
+ void _iocs_txfill (const struct _x68_txfillptr *);
+ void _iocs_txrascpy (int, int, int);
+ void _iocs_txxline (const struct _x68_xlineptr *);
+ void _iocs_txyline (const struct _x68_ylineptr *);
+ int  _iocs_window (int, int, int, int);
+
+/* -------------- */
+
+#endif /* _X68_IOCSLIB_H_ */
diff --git a/itor.cpp b/itor.cpp
new file mode 100644 (file)
index 0000000..7327cd0
--- /dev/null
+++ b/itor.cpp
@@ -0,0 +1,1437 @@
+/*************************************/
+/* STD MIDI file converter / player  */
+/*************************************/
+
+/*
+  This code is brought from Takayuki Toda's 'rc_converters'.
+
+  Modified 2000 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+ */
+//#include "stdafx.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "rcpfile.h"
+#include "rcpdef.h"
+#include "rcddef.h"
+
+#if STDC_HEADERS
+# include <string.h>
+#else
+# ifndef HAVE_MEMCPY
+#  define memcpy(d, s, n) bcopy ((s), (d), (n))
+#  define memmove(d, s, n) bcopy ((s), (d), (n))
+# endif
+#endif
+
+#define TRACK_LEN 65536
+
+static struct head {
+  char chunk[4];
+  long length;
+  short format;
+  short ntrks;
+  short division;
+} std_head;
+
+static struct track {
+  char chunk[4];
+  long length;
+} std_trk;
+
+static int opt, comment;
+static int sameflag;
+
+static unsigned char *rcpptr, *lastptr;
+static unsigned char *inptr, *buf;
+static unsigned char *note, *note_data;
+static int incount;
+static int tc;
+static int fmt;
+static int pt;
+static int midi_ch;
+static int tb_mode,tb_max, ratio,rcp_base;
+static int step, stepx;
+static int barlen, barunit, stepsum;
+static int fixflag;
+static char std_name[256];
+
+static const char memoinit[] = "                                    ";
+static const char ttlinit[] = "                                                                ";
+static int memoflag;
+static int beatflag;
+static int tempoflag;
+static int chfixflag,chbport;
+
+static int tempofix;
+static int exc_no,exc_id,barno,devno_fix,notoff,chport;
+
+static int trk;
+static int len;
+static int cmd;
+static int d_byte;
+
+static int nbuf[16], vbuf[16], gbuf[16], cbuf[16];
+
+const static int beat[] = { 1, 2, 4, 8, 16, 32, 64, 128 };
+static int     barlenb[2048];
+
+static char    rc_path[256];
+static char    exc_buf[32*1024+4];
+
+static int tai_compres(int);
+static int same_compres(int);
+static int add_set(int, int *);
+static int meas_len(int, int);
+
+static unsigned char * strncpy0( unsigned char *dst, unsigned char *src, int n )
+{
+  int i;
+
+  for( i = 0; i < n; i++ ) {
+    dst[i] = src[i];
+  }
+  dst[n] = 0;
+  return( dst );
+}
+
+static int alloc_mem( void )
+{
+  void *work;
+
+  if( ( work = (void *)malloc( TRACK_LEN * 8 ) ) < 0 ) {
+    fprintf( stderr, "Memory exhausted\n" );
+    return 1;
+  }
+
+  note_data = ( unsigned char * )work;
+  buf = ( unsigned char * )( (unsigned char *)work + TRACK_LEN * 4 );
+
+  return 0;
+}
+
+static void destroy_mem( void )
+{
+  if ( note_data != NULL )
+    free(note_data);
+
+  return;
+}
+
+static void get_data( unsigned char *s, int bc )
+{
+  memmove( ( char * )s, ( char *)( inptr + incount ), bc );
+  incount += bc;
+
+  return;
+}
+
+static void put_data( unsigned char *s, int bc )
+{
+  if( lastptr <= rcpptr + bc ) {
+    fprintf( stderr, "Buffer exhausted\n" );
+    return;
+  }
+  memmove( ( char * )rcpptr, ( char * )s, bc );
+  rcpptr += bc;
+
+  return;
+}
+
+static void strpaste( unsigned char *dst, unsigned char *src )
+{
+  while( *src ) {
+    *dst++ = *src++;
+  }
+}
+
+static void strnpaste( unsigned char *dst, unsigned char *src, int n )
+{
+  while( n-- ) {
+    *dst++ = *src++;
+  }
+}
+
+static void ctrlcut( char *s )
+{
+  while(*s) {
+    if( *s == 13 ) { *s = 32; }
+    if( *s == 27 ) { *s = 32; }
+    s++;
+  }
+}
+
+/**/
+
+static int get_delta( int p )
+{
+  register int val, i, d;
+  
+  val = 0;
+  d_byte = 0;
+  
+  for( i = 0; i < 4; i++ ) {
+    d = buf[p++];
+    d_byte++;
+    val = ( val << 7 ) + ( d & 0x7f );
+    if( d < 0x80 ) {
+      return( val );
+    }
+  }
+  
+  fprintf( stderr, "Invalid delta time.\n" );
+  return(0); /**//*warning*//**/
+}
+/**/
+
+static void proc_beat( int high, int low )
+{
+  /*
+    if( beatflag ) {
+    return;
+    }
+    */
+  if( !beatflag ) {
+    RCP_HEAD.Beathigh = high;
+    RCP_HEAD.Beatlow = low;
+  }
+
+  barlen = (RCP_HEAD.Timebase+RCP_HEAD.Timebaseh*256) * 4 * high / low;
+  if(trk==0 && barno<2048){barlenb[barno]=barlen;}
+}
+
+static int proc_header( void )
+{
+  int  i;
+  uint8 b[14];
+  
+  get_data( b, 14 );
+  
+  if( strncmp( (char*)b, "MThd", 4 ) ) {
+    unsigned char tmp[128];
+    get_data( tmp, 128-14 ); /* Mac binary */
+    
+    get_data( b, 14 );
+    
+    if( strncmp( (char*)b, "MThd", 4 ) ) {
+      /*fprintf( stderr, "This file is not SMF file (MThd).\n" );*/
+      return 1;
+    }
+  }
+  
+  std_head.length = b[4]*256*256*256 + b[5]*65536 + b[6]*256 + b[7];
+  std_head.format = b[8]*256 + b[9];
+  std_head.ntrks  = b[10]*256 + b[11];
+  std_head.division = b[12]*256 + b[13];
+
+  if( !comment ) {
+    printf( "format =%3d    ntrk =%3d    division =%4d\n",
+           std_head.format, std_head.ntrks, std_head.division );
+  }
+  
+  if( ( fmt = std_head.format ) != 0 && fmt != 1 ) {
+    fprintf( stderr, "Cannot treat format %d.\n", fmt );
+    return 1;
+  }
+  
+  if(std_head.ntrks>18){
+    RCP_HEAD.trkmax = 36;
+  }else{
+    RCP_HEAD.trkmax = 18;
+  }
+  
+  /*
+  strpaste( RCP_HEAD.memo +  28, ( unsigned char * )"  ¤³¤Î¥Ç¡¼¥¿¤Ï¡¢" );
+  strpaste( RCP_HEAD.memo +  84, ( unsigned char * )"  É¸½àMIDI¥Õ¥©¡¼¥Þ¥Ã¥È¤«¤\81E );
+  strpaste( RCP_HEAD.memo + 140, ( unsigned char * )"  ItoR.x (v1.00)¤Ë¤è¤\81E );
+  strpaste( RCP_HEAD.memo + 151, ( unsigned char * )version );
+  strpaste( RCP_HEAD.memo + 196, ( unsigned char * )"  ÊÑ´¹¤µ¤\81EÞ¤·¤¿¡£" );
+  strpaste( RCP_HEAD.memo + 252, ( unsigned char * )"  Copyright 1990-97" );
+  strpaste( RCP_HEAD.memo + 280, ( unsigned char * )"           HARPOON,TURBO" );
+  */
+  
+  if( !tb_mode || std_head.division > tb_max ) {
+    rcp_base=48;if( tb_mode ) {rcp_base=tb_max;}
+    
+    RCP_HEAD.Timebase = rcp_base;
+    RCP_HEAD.Timebaseh = rcp_base>>8;
+    tb_mode = 0;
+    ratio = std_head.division;
+    
+    if( !comment ) {
+      if( std_head.division > tb_max ) {
+       printf( "¥¿¥¤¥à¥Ù¡¼¥¹¤\81Ed¤ËÊѹ¹¤·¤Þ¤¹¡£\n\n",tb_max );
+      }
+    }
+    
+  } else {
+    RCP_HEAD.Timebase = std_head.division;
+    RCP_HEAD.Timebaseh = std_head.division>>8;
+    
+    if( !comment ) {
+      printf( "¥¿¥¤¥à¥Ù¡¼¥¹¤òÊѹ¹¤·¤Þ¤»¤ó¡£\n\n" );
+    }
+    
+  }
+  
+  RCP_HEAD.Tempo = 120;
+  beatflag = 0;
+  proc_beat( 4, 4 );
+  RCP_HEAD.Key = 0;
+  RCP_HEAD.Playbias = 0;
+  
+  tempoflag = 0;
+  
+  tc = 0x0586;
+  
+  for(i=0;i<2048;i++){barlenb[i]=0;}
+  
+  return 0;
+}
+
+static void entry( int d0, int d1, int d2, int d3 )
+{
+
+  /*if(len && d0==0xe6 && note[len-4]==0xe6){len-=4;d1=note[len+1];}*//**/
+
+  note[ len++ ] = d0;
+  note[ len++ ] = d1;
+  note[ len++ ] = d2;
+  note[ len++ ] = d3;
+  
+  if( len >= 65492+65536*3 ) {
+    fprintf( stderr, "Track buffer overflow\n" );
+    len-=4;
+    return;
+  }
+
+  return;
+}
+
+static void flash( int dt )
+{
+  int dx, i, j;
+  
+  while( dt > 0 ) {
+    
+    if( dt <= 0xf0 ) {
+      dx = dt;
+    } else {
+      dx = 0xf0;
+    }
+    
+    if( dx + barunit > barlen ) {
+      dx = barlen - barunit;
+    }
+    
+    for( i = 0; i < 16; i++ ) {
+      if( gbuf[i] ) {
+       
+       if(fmt!=0 && !chfixflag && midi_ch!=cbuf[i]){
+         if( midi_ch == -1 ) {
+           TRACK.MIDI_CH = cbuf[i];
+         }else{
+           entry( 0xe6, 0x00, cbuf[i]+1, 0x00 );
+         }
+         midi_ch=cbuf[i];
+       }
+       
+       /*if( gbuf[i] <= dx ) {*/
+       if( gbuf[i] <= 0xf0 ) {/**/
+         entry( nbuf[i], 0, gbuf[i], vbuf[i] );
+         for( j = i; j < 15; j++ ) {
+           nbuf[j] = nbuf[j+1];
+           vbuf[j] = vbuf[j+1];
+           gbuf[j] = gbuf[j+1];
+           cbuf[j] = cbuf[j+1];
+         }
+         nbuf[15] = vbuf[15] = gbuf[15] = cbuf[15] = 0;
+         i--;
+       } else {
+         entry( nbuf[i], 0, dx + 1, vbuf[i] );
+         gbuf[i] -= dx;
+       }
+      } else {
+       break;
+      }
+    }
+    
+    if( note[ len - 4 ] !=0xde &&
+       note[ len - 4 ] < 0xf0 && ( note[ len - 3 ] + dx ) <= 0xf0 ) {
+      note[ len - 3 ] += dx ;
+    } else {
+      if(note[len-4]==0xf7){
+       int ll=len-4;
+       while(note[ll]==0xf7){ll-=4;}
+       if(note[ll]==0x98 && ( note[ ll + 1 ] + dx ) <= 0xf0 ) {
+         note[ ll + 1 ] += dx ;
+       } else {
+         entry( 0x00, dx, 0, 0 );
+       }
+      }else{
+       entry( 0x00, dx, 0, 0 );
+      }
+    }
+    
+    dt -= dx;
+    
+    if( ( barunit += dx ) == barlen ) {
+      entry( 0xfd, 0x00, 0x00, 0x00 );
+      barunit = 0;
+      if(barlenb[barno]>0 && trk>0){barlen=barlenb[barno];}
+      barno++;
+    }
+    
+  }
+  
+  stepsum = 0;
+}
+
+static void proc_dummy( int dt )
+  {
+    if( !tb_mode ) {
+      step += dt;
+      dt = ( step * rcp_base / ratio ) - stepx;
+      stepx += dt;
+    }
+
+    if( fmt == 0 ) {
+      stepsum += dt;
+    } else {
+      flash( dt );
+    }
+  }
+
+static void check( int data )
+  {
+    cmd = data & 0xf0;
+
+    /* if(cmd==0x80){return;}*/
+
+    if( !fixflag ) {
+      data &= 0x0f;data+=chport;
+      if( midi_ch != data ) {
+       if( fmt == 1 ) {
+         flash(stepsum);/**/
+         if( midi_ch == -1 ) {
+           TRACK.MIDI_CH = data;
+         }else{
+           if(!chfixflag){
+             entry( 0xe6, 0x00, data+1, 0x00 );
+           }
+         }
+       }
+       midi_ch = data;
+      }
+    }
+  }
+
+static int search( int pp )
+  {
+    /* int n, dt, cc, ch, ccmd, last, i,ocmd;*/
+    int dt, last, i;
+    short n,cc, ch, ccmd,ocmd;
+
+    n = buf[pp];
+    ccmd = cmd;
+    ocmd = cmd;
+    last = std_trk.length;
+    pp += 2;
+    dt = 0;
+    ch = midi_ch&15;/**/
+
+    while( pp < last ) {
+      if(notoff!=0 && dt>255){return( 1 );}
+
+      dt += get_delta( pp );
+      pp += d_byte;
+      if( ( cc = buf[pp] ) < 0x80 ) {
+       if( ccmd == 0x80 && cc == n && ( fixflag || ch+chport == midi_ch ) ) {
+         return( dt );
+       } else {
+         if( ccmd == 0x90 && cc == n &&
+             buf[pp+1] == 0x00 && ( fixflag || ch+chport == midi_ch ) ) {
+           return( dt );
+         } else {
+           pp += 2;
+           if(ccmd>=0xc0 && ccmd<=0xdf){pp--;}
+         }
+       }
+      } else {
+       ocmd=cc;
+       switch( cc & 0xf0 ) {
+       case 0x80 :
+         if( buf[pp+1] == n &&
+             ( fixflag || cc == ( 0x80 + (midi_ch&15) ) ) ) {
+           return( dt );
+         }
+         pp += 3;
+         ch = cc & 0x0f;
+         break;
+       case 0x90 :
+         if( buf[pp+1] == n && buf[pp+2] == 0x00 &&
+             ( fixflag || cc == ( 0x90 + (midi_ch&15) ) ) ) { 
+           return( dt );
+         }
+         pp += 3;
+         ch = cc & 0x0f;
+         break;
+       case 0xa0 :
+       case 0xb0 :
+       case 0xe0 :
+         pp += 3;
+         ch = cc & 0x0f;
+         break;
+       case 0xc0 :
+       case 0xd0 :
+         pp += 2;
+         ch = cc & 0x0f;
+         break;
+       case 0xf0 :
+         switch( cc ) {
+         case 0xf0 :
+         case 0xf7 :
+           pp += 1;
+           i = get_delta( pp );
+           pp += d_byte;
+           pp += i;
+           break;
+         case 0xff :
+           pp += 2;
+           i = get_delta( pp );
+           pp += d_byte;
+           pp += i;
+           break;
+         default :
+           fprintf( stderr, "Invalid format\n" );
+           /*exit(18);*/
+           return 1;
+           break;
+         }
+         break;
+       }
+       ccmd = cc & 0xf0;
+      }
+    }
+    notoff=1;
+    return( 1 );
+  }
+
+static void ent_buf( int nt, int vl, int gt )
+  {
+    int i;
+
+    /*
+      if( !comment ) {
+      printf( "<nt=%d vl=%d gt=%d>\n", nt, vl, gt );
+      }
+      */
+
+    if( gt <= 0xf0 ) {
+      entry( nt, 0, gt,vl );return;
+    } else {
+      entry( nt, 0, 255,vl );
+    }
+
+    for( i = 0; i < 16; i++ ) {
+      if( !gbuf[i] || (nbuf[i] == nt && cbuf[i] == midi_ch) ) {
+       nbuf[i] = nt;
+       vbuf[i] = vl;
+       gbuf[i] = gt;
+       cbuf[i] = midi_ch;
+       return;
+      }
+    }
+
+    for( i = 0; i < 15; i++ ) {
+      nbuf[i] = nbuf[i+1];
+      vbuf[i] = vbuf[i+1];
+      gbuf[i] = gbuf[i+1];
+      cbuf[i] = cbuf[i+1];
+    }
+
+    nbuf[15] = nt;
+    vbuf[15] = vl;
+    gbuf[15] = gt;
+    cbuf[15] = midi_ch;
+
+    /*
+      fprintf( stderr, "¥Î¡¼¥È¥ª¡¼¥Ð¥Õ¥ú½¼\n" );       exit(18);
+      */
+  }
+
+static void note_off( int p )
+  {
+    /* do nothing */
+  }
+
+static void note_on( int p )
+  {
+    int gt;
+
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    if( buf[p+1] ) {
+      if( !( gt = search( p ) ) ) {
+       return;
+      }
+      if( !tb_mode ) {
+       if( !( gt = gt * rcp_base / ratio ) ) {
+         /*                    if( !( gt = (gt * rcp_base+(ratio>>1)) / ratio ) ) {*/
+         gt = 1;
+       }
+      }
+      ent_buf( buf[p], buf[p+1], gt );
+    }
+  }
+
+static void aft_key( int p )
+  {
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    entry( 0xed, 0x00, buf[p], buf[p+1] );
+  }
+
+static void ctl_chg( int p )
+  {
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    entry( 0xeb, 0x00, buf[p], buf[p+1] );
+  }
+
+static void prg_chg( int p )
+  {
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    entry( 0xec, 0x00, buf[p], 0x00 );
+  }
+
+static void aft_tch( int p )
+  {
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    entry( 0xea, 0x00, buf[p], 0x00 );
+  }
+
+static void pt_bend( int p )
+  {
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    entry( 0xee, 0x00, buf[p], buf[p+1] );
+  }
+
+static void run_sts( int p )
+  {
+    if( fmt == 0  ) {
+      if( midi_ch != TRACK.MIDI_CH  ) {
+       return;
+      }
+      flash( stepsum );
+    }
+
+    switch( cmd ) {
+    case 0x80 : note_off(p); break;
+    case 0x90 : note_on(p);  break;
+    case 0xa0 : aft_key(p);  break;
+    case 0xb0 : ctl_chg(p);  break;
+    case 0xc0 : prg_chg(p);  break;
+    case 0xd0 : aft_tch(p);  break;
+    case 0xe0 : pt_bend(p);  break;
+    }
+  }
+
+static int num_check( int num, int limit )
+  {
+    if( num > limit ) {
+      return( limit );
+    } else {
+      return( num );
+    }
+  }
+
+static void clr_ttl( void )
+  {
+    strpaste( ( unsigned char * )RCP_HEAD.title, ( unsigned char * )ttlinit );
+  }
+
+static void proc_meta( int meta, unsigned char *text, int length )
+  {
+    int i;
+    unsigned char work[128];
+
+    if( fmt == 0 /*&& trk*/ ) {
+      flash( stepsum );
+    }
+
+    switch( meta ) {
+    case 0x03:
+      if( !memoflag ) {
+       ctrlcut((char*)text);
+       memoflag = 1;
+       if(trk){
+         if((127<text[35] && 161>text[35]) || 224<text[35]){
+           text[35]=0;}
+         strnpaste( TRACK.Memo, text, num_check( length, 36 ) );
+         if(strncmp((char*)text,"PartA",5)==0){chport=0;}
+         if(strncmp((char*)text,"PartB",5)==0){chport=16;}
+       }
+       if( trk == 0 ) {
+         clr_ttl();
+         if((127<text[63] && 161>text[63]) || 224<text[63]){
+           text[63]=0;}
+         strnpaste( RCP_HEAD.title, text, num_check( length, 64 ) );
+       }
+      }
+      break;
+    case 0x01:
+      /*if( !step ) {*/
+      if( step<barlen ) {
+       if( !memoflag ) {
+         ctrlcut((char*)text);
+         memoflag = 1;
+         if(trk){
+           if((127<text[35] && 161>text[35]) || 224<text[35]){
+             text[35]=0;}
+           strnpaste( TRACK.Memo, text, num_check( length, 36 ) );
+           if(strncmp((char*)text,"PartA",5)==0){chport=0;}
+           if(strncmp((char*)text,"PartB",5)==0){chport=16;}
+         }
+         if( trk == 0 ) {
+           clr_ttl();
+           if((127<text[63] && 161>text[63]) || 224<text[63]){
+             text[63]=0;}
+           strnpaste( RCP_HEAD.title, text, num_check( length, 64 ) );
+         }
+         if(!step){break;}
+       }
+      }        /* no break */
+    case 0x04:
+    case 0x05:
+    case 0x06:
+    case 0x07:
+    case 0x02:/*turbo*/
+      ctrlcut((char*)text);
+    next:
+      strcpy( ( char * )work, ( char * )memoinit );
+      strnpaste( work, text, num_check( length, 64 ) );
+      if(length<20){length=20;}
+      entry( 0xf6, 0x00, work[0], work[1] );
+      for( i = 2; i < 20; i += 2 ) {
+       entry( 0xf7, 0x00, work[i], work[i+1] );
+      }
+      if(length>20){strcpy((char*)text,(char*)&text[20]);length-=20;goto next;}
+
+      /*               for( i = 2; i < length; i += 2 ) {
+                       entry( 0xf7, 0x00, work[i], work[i+1] );
+                       }
+                       */
+      break;
+    case 0x20:
+      midi_ch = 0;
+      /*fixflag = 1;*/
+      if(!chfixflag || fmt==0){entry( 0xe6, 0x00, (text[0]+1)+chport, 0x00 );}
+      break;
+    case 0x51:
+      if( !tempoflag && trk == 0 && tempofix==0) {
+       i = 60000000 / ( ( text[0] << 16 ) + ( text[1] << 8 ) + text[2] );
+       /*
+         if( i > 255 ) {
+         i = 255;
+         } else */{
+         if( i == 0 ) {
+           i = 1;
+         }
+       }
+
+         RCP_HEAD.Tempo = i;
+         tempoflag = 1;
+
+         if( i > 255 ) {
+           RCP_HEAD.Tempo = 255;goto skip;}
+
+      } else {
+      skip:
+       if( !tempoflag && trk == 0 ) {
+         i = 60000000 / ( ( text[0] << 16 ) + ( text[1] << 8 ) + text[2] );
+         RCP_HEAD.Tempo = i>>1;
+         tempoflag = 1;
+       }
+
+       i = 60000000 / ( ( text[0] << 16 ) + ( text[1] << 8 ) + text[2] );
+       i = 64 * i / RCP_HEAD.Tempo;
+       /*ÀßÄꤷ¤¿¤¤¥Æ¥ó¥Ý¡à½é´\81EßÄ\81EÆ¥ó¥Ý¡ß64*/
+       if( i > 255 ) {
+         i = 255;
+       } else {
+         if( i == 0 ) {
+           i = 1;
+         }
+       }
+       entry( 0xe7, 0x00, i, 0x00 );
+       tempoflag = 1;
+      }
+      break;
+    case 0x58:
+      proc_beat( text[0], beat[ text[1] ] );
+      beatflag = 1;
+      break;
+    case 0x21:
+      if((text[0])==1){chport=16;}else{chport=0;}
+      /*entry( 0xe6, 0x00, (midi_ch+1)+chport, 0x00 );*/
+      break;
+    case 0x00:
+      /*       case 0x02:*/
+    case 0x2f:
+    case 0x54:
+    case 0x59:
+    case 0x7f:
+      break;
+    default :
+      if( !comment ) {
+       printf( "FF %02X (Unknown meta event)\n", meta );
+      }
+      break;
+    }
+  }
+
+static void proc_excl( unsigned char *text, int length ,int code)
+  {
+    int h, m, l;
+    int hh, mm, ll;
+    int i;
+
+    if( fmt == 0 /*&& trk*/ ) {
+      flash( stepsum );
+    }
+
+    text[ length ] = 0xf7 ;
+
+    if( devno_fix !=0 && text[0] == 0x41 && text[3] == 0x12){
+      text[1]=0x10;}
+
+    if( length < 9 || length > 15 ||
+       text[0] != 0x41 || text[3] != 0x12 ||
+       text[ length-1 ] != 0xf7 ) {
+
+      if( text[0] == 0x41 && text[3] == 0x12 && length<9 ){return;}
+
+      if(code==0xf0){
+      nor:
+       i=0;
+       entry( 0x98, 0, 0, 0 );
+       while(i<length){
+         entry( 0xf7, 0, text[i], text[i+1] );
+         if( text[i] == 0xf7 || text[ i+1 ] == 0xf7 ) {break;}
+         i=i+2;
+       }
+      }else{
+       if(len==0 || note[len-4]!=0xf7){goto nor;}
+       i=0;
+
+       if(note[len-2]==0xf7){note[len-2]=text[i++];}
+       if(note[len-1]==0xf7){note[len-1]=text[i++];}
+
+       while(i<length){
+         entry( 0xf7, 0, text[i], text[i+1] );
+         if( text[i] == 0xf7 || text[ i+1 ] == 0xf7 ) {break;}
+         i=i+2;
+       }
+      }
+
+      /*fprintf( stderr, "ÉÔÀµEXCLUSIVE¥á¥Ã¥»¡¼¥¸ \n" );
+       exit(18);*/
+
+      return;
+    }
+
+    if( exc_no != text[1] || exc_id != text[2] ) {
+      exc_no = text[1];exc_id = text[2];
+      entry( 0xdf, 0, exc_no, exc_id );
+    }
+
+    h = text[4]; m = text[5]; l = text[6];
+    hh = mm = ll = -1;
+
+    for( i = 7; i < length - 2; i++ ) {
+      if( hh != h || mm != m  ) {
+       entry( 0xdd, 0x00, h, m );
+       hh = h; mm = m; ll = l;
+      }
+      entry( 0xde, 0x00, l, text[i] );
+      if( l++ == 0x7f ) {
+       l = 0;
+       m++;
+      }
+    }
+  }
+
+static int proc_next( void )
+  {
+    int meta, code, length,last;
+    unsigned char text[4096];
+
+    last = std_trk.length;
+    cmd = 0x00;
+    step = stepx = 0;
+
+    while(pt<last) {
+
+      proc_dummy( get_delta(pt) );
+      pt += d_byte;
+
+      if( ( code = buf[pt] ) == 0xff ) {
+       pt++;
+       meta = buf[pt++];
+       length = get_delta(pt);
+       pt += d_byte;
+       strncpy0( text, buf + pt, length );
+       if( fmt == 1 || trk == 0 ) {
+         proc_meta( meta, text, length );
+       }
+       pt += length;
+       if( meta == 0x2f ) {
+         return 0;
+       }
+      } else {
+       switch( code & 0xf0 ) {
+       case 0x80: /*check( buf[pt] ); note_off(pt+1);*/
+         cmd = buf[pt] & 0xf0;
+         pt += 3; break;
+       case 0x90: check( buf[pt] ); note_on(pt+1);  pt += 3; break;
+       case 0xa0: check( buf[pt] ); aft_key(pt+1);  pt += 3; break;
+       case 0xb0: check( buf[pt] ); ctl_chg(pt+1);  pt += 3; break;
+       case 0xc0: check( buf[pt] ); prg_chg(pt+1);  pt += 2; break;
+       case 0xd0: check( buf[pt] ); aft_tch(pt+1);  pt += 2; break;
+       case 0xe0: check( buf[pt] ); pt_bend(pt+1);  pt += 3; break;
+       case 0xf0:
+         if( code != 0xf0 && code != 0xf7 ) {
+           fprintf( stderr, "Invalid MIDI message (%02X)\n", code );
+           return 1;
+         }
+         pt++;
+         length = get_delta(pt);
+         pt += d_byte;
+         if( fmt == 1 || trk == 0 ) {
+           if(length<32*1024){
+             strncpy0( (uint8*)exc_buf, buf + pt, length );
+             proc_excl( (uint8*)exc_buf, length ,code);
+           }
+         }
+         pt += length;
+         break;
+       default :  run_sts(pt); pt += 2;
+         if(cmd>=0xc0 && cmd<=0xdf){pt--;}
+         break;
+       }
+      }
+    }
+  }
+
+static void track_end( void )
+{
+  if( fmt == 0 ) {
+    flash( stepsum );
+  }
+  
+  if(trk){
+    while(len>0) {
+      if( ( note[ len - 4 ] == 0x00 && note[ len - 2 ] == 0x00 ) ||
+         note[ len - 4 ] == 0xfd ) {
+       len -= 4;
+      } else {
+       break;
+      }
+    }
+  }
+  
+  entry( 0xfe, 0, 0, 0 );
+  len=tai_compres(len);
+  if(sameflag){len=same_compres(len);}
+  
+  if( len > 65488 ) {
+    fprintf( stderr, "Track overflow.\n" );
+    /*         len=65488-4;
+               entry( 0xfe, 0, 0, 0 );*/
+  }
+  
+  TRACK.len_high = ( len + 44 ) >> 8;
+  TRACK.len_low = (( len + 44 ) >> 16 ) + ( len + 44 ) & 0xff;
+}
+
+static int proc_track( void )
+{
+  int i;
+  unsigned char b[8];
+  
+  exc_no=0x10;exc_id=0x16;chport=0;
+  
+  if( fmt == 1 || trk == 0 ) {
+    get_data( b, 8 );
+    strncpy(std_trk.chunk, (char*)b, 4);
+    std_trk.length = b[4]*256*256*256 + b[5]*65536 + b[6]*256 + b[7];
+    if( strncmp( std_trk.chunk, "MTrk", 4 ) ) {
+      fprintf( stderr, "Invalid SMF file (MTrk)\n" );
+      return 1;
+    }
+    get_data( buf, std_trk.length );
+  }
+
+  for( i = 0; i < 16; i++ ) {
+    nbuf[i] = vbuf[i] = gbuf[i] = cbuf[i] = 0;
+  }
+  
+  pt = 0;
+  len = 0;
+  
+  barunit = 0; stepsum = 0;
+  fixflag = 0;
+  
+  TRACK.track_no = trk;
+  TRACK.rhythm_flag = 0x00;
+  
+  if( fmt == 0 ) {
+    TRACK.MIDI_CH = midi_ch = trk ;
+  } else {
+    TRACK.MIDI_CH = 0 ;
+    midi_ch = -1;
+  }
+  
+  TRACK.Play_bias = 0x00;
+  TRACK.ST_offset = 0x00;
+  TRACK.Mode = 0x00;
+  
+  strpaste( TRACK.Memo, ( unsigned char * )memoinit );
+  memoflag = 0;
+  barno=0;
+  if(barlenb[0]>0 && trk>0){barlen=barlenb[barno++];}
+  
+  if( !comment ) {
+    printf( "Track= %2d  %04X\n", trk, std_trk.length );
+  }
+  
+  if(chbport!=0 && trk>16 ){chport=16;}
+  
+  notoff=0;
+  if ( proc_next() != 0 ) return 1;
+
+  track_end();
+  
+  if( trk == 0 ) {
+    put_data( RCP_HEAD.mark, 0x0586 );
+  }
+  
+  if(chfixflag){
+    if( std_head.format==0 ){
+      TRACK.MIDI_CH = trk ;
+    }else{
+      if(trk){TRACK.MIDI_CH = trk-1 ;}
+    }
+  }
+  
+  put_data( ( unsigned char * )&TRACK.len_low, 44 );
+  put_data( ( unsigned char * )note, len );
+  tc += len + 44;
+
+  return 0;
+}
+
+static void dummy_track( void )
+  {
+    len = 0;
+
+    TRACK.track_no = trk;
+    TRACK.rhythm_flag = 0x00;
+    TRACK.MIDI_CH = 255;
+    TRACK.Play_bias = 0x00;
+    TRACK.ST_offset = 0x00;
+    TRACK.Mode = 0x00;
+    strpaste( TRACK.Memo, ( unsigned char * )memoinit );
+
+    if( !comment ) {
+      printf( "Track= %2d  dummy\n", trk );
+    }
+
+    track_end();
+
+    put_data( ( unsigned char * )&TRACK.len_low, 44 );
+    put_data( ( unsigned char * )note, len );
+    tc += len + 44;
+  }
+
+#if 0
+static void option( char *s )
+  {
+    char c;
+
+    opt = 0;
+    comment = 0;
+    tb_mode = 0;
+    tb_max = 48;
+    sameflag = 0;
+    chfixflag = 0;
+    tempofix = 0;
+    devno_fix = 0;
+    chbport=0;
+
+    if( !*s ) {
+      usage();
+    }
+
+    while( c = *s++ ) {
+      switch( c ) {
+      case 'C' :
+      case 'c' :
+       opt = 0;
+       break;
+      case 'B' :
+      case 'b' :
+       opt = 1;
+       break;
+      case 'P' :
+      case 'p' :
+       opt = 2;
+       break;
+      case 'K' :
+      case 'k'  :
+       opt = 2;
+       break;
+      case 'R' :
+      case 'r'  :
+       opt = 3;
+       break;
+      case 'X' :
+      case 'x' :
+       opt = 4;
+       break;
+      case 'T' :
+      case 't' :
+       tb_mode = 1;
+       tb_max = 0;
+       while(*s>='0' && *s<='9'){
+         tb_max=tb_max*10+((*s++)-'0');
+       }
+       if(tb_max<48){tb_max=240;}
+       break;
+      case 'N' :
+      case 'n' :
+       comment = 1;
+       break;
+      case ' ' :
+       opt = 0;
+       break;
+      case 'S' :
+      case 's' :
+       sameflag = 1;
+       break;
+      case 'F' :
+      case 'f' :
+       chfixflag = 1;
+       break;
+      case 'G' :
+      case 'g' :
+       chbport = 1;
+       break;
+      case 'E' :
+      case 'e' :
+       tempofix = 1;
+       break;
+      case 'D' :
+      case 'd' :
+       devno_fix = 1;
+       break;
+      default :
+       usage();
+       break;
+      }
+    }
+
+  }
+#endif
+
+int itor(  char *smf_data,  char *rcp_buf )
+{
+  int i;
+
+  /* Initialize all configurable valuables */
+  
+  opt = 0;
+  chfixflag = 0;
+  devno_fix = 0;
+
+  tb_mode =  1; /* 0:time base is converted into 48 */
+  tb_max = 480; /* Max number of time base */
+  chbport =  1; /* translate all tracks > 16 into port B */
+  tempofix = 1; /* fixes errors of tempo change */
+  sameflag = 1; /* unifies all tracks with SAME MEAS */
+  comment  = 1; /* suppress all comments */
+  
+
+  /* allocate internal work memory */
+  
+  note_data = NULL;
+
+  if ( alloc_mem() != 0 ) return 0;
+  
+  inptr   = (uint8 *)smf_data;
+  rcpptr  = (uint8 *)rcp_buf;
+  incount = 0;
+  lastptr = rcpptr + 512*1024; /* DATA_ADR_SIZE */
+  
+  for( i = 0; i < 16; i++ ) {
+    note_data[i] = 0xff;
+  }
+  
+  note = note_data + 16;
+  
+
+  /* process all tracks */
+  
+  if ( proc_header() != 0 ) {
+    destroy_mem();
+    return 0;
+  }
+  
+  if( fmt == 0 ) {
+    for( trk = 0; trk < 16; trk++ ) {
+      if ( proc_track() != 0 ) {
+       destroy_mem();
+       return 0;
+      }
+    }
+    
+    for( trk = 16; trk < 18; trk++ ) {
+      dummy_track();
+    }
+    
+  } else {
+    for( trk = 0; trk < std_head.ntrks; trk++ ) {
+      if ( proc_track()!= 0 ) {
+       destroy_mem();
+       return 0;
+      }
+    }
+    
+    if( std_head.ntrks>18){
+      for( trk = std_head.ntrks; trk < 36; trk++ ) {
+       dummy_track();
+      }
+    }else{
+      for( trk = std_head.ntrks; trk < 18; trk++ ) {
+       dummy_track();
+      }
+    }
+    
+  }
+  
+  /* free all minternal work memory */
+
+  destroy_mem();
+  
+  /* all works finished */
+  
+  return (int)(rcpptr - (uint8*)rcp_buf);
+}
+
+/***************************/
+
+static int tai_compres(int ln)
+  {
+    int        i,ad,ch,rbh=-1,rbm=-1;
+    unsigned char      a,b,c,d;
+    /*base dd dev df*/
+    ch=(TRACK.MIDI_CH+1)&0xff;
+    ad=0;
+
+    for(i=0;i<ln;i+=4){
+      a=note[i];b=note[i+1];c=note[i+2];d=note[i+3];
+
+      if(a<128 && c>b && d>0){
+       int cc=ch,ad2,sum;
+       ad2=i;sum=0;
+
+       while(ad2<ln){
+         unsigned char da=note[ad2];
+         if(da==0xe6){cc=note[ad2+2];}
+
+         if(ad2>i && cc==ch && a==da && note[ad2+2]!=0 && note[ad2+3]!=0 ){
+           if(sum+note[ad2+2]<=255){
+             c=note[ad2+2]+sum;
+             note[i+2]=c;
+             note[ad2+2]=0;
+             note[ad2+3]=0;
+           }else{
+             break;
+           }
+         }
+
+         if(da<0xf0){sum+=note[ad2+1];if(sum>255 || sum>=c){break;}}
+
+         if(da>=0xfc||da==0xf8||da==0xf9||da==0xe2||da==0xec){break;}
+         ad2+=4;
+       }
+      }
+
+      /*               if(note[i]>=0xfc){ch=-1;}*/
+
+      if(note[i]>=0xfc){rbh=-1;rbm=-1;}
+
+      if(note[i]==0xdd){
+       if(note[i+2]==rbh && note[i+3]==rbm){
+         note[i]=0;note[i+2]=0;note[i+3]=0;
+       }else{
+         rbh=note[i+2];
+         rbm=note[i+3];
+
+         if(ad && note[ad-4]==0xdd){
+           note[ad-2]=note[i+2];
+           note[ad-1]=note[i+3];
+           note[i]=0;note[i+2]=0;note[i+3]=0;
+         }
+       }
+      }
+
+      /*               if(note[i]==0xe6){
+                       if(note[i+2]==ch){
+                       note[i]=0;note[i+2]=0;note[i+3]=0;
+                       }else{
+                       ch=note[i+2];
+
+                       if(ad && note[ad-4]==0xe6){
+                       note[ad-2]=note[i+2];
+                       note[i]=0;note[i+2]=0;note[i+3]=0;
+                       }
+                       }
+                       }
+                       */
+      /*
+       if(note[i]==0xee){
+       if(ad && note[ad-4]==note[i] && note[ad-3]==0){
+       note[ad-2]=note[i+2];
+       note[i]=0;note[i+2]=0;note[i+3]=0;
+       }
+       }
+       */
+      if((note[i]<0x80 &&(note[i+2]==0||note[i+3]==0))&&
+        ad>0 && note[ad-4]<0xf0 && note[ad-3]+note[i+1]<=240){
+       note[ad-3]+=note[i+1];
+      }else{
+       note[ad++]=note[i];note[ad++]=note[i+1];
+       note[ad++]=note[i+2];note[ad++]=note[i+3];
+      }
+    }
+
+    return ad;
+  }
+
+/***************************/
+static int same_compres(int size)
+  {
+    int        i,j=0,k,match,count=0;
+    int        po=0,m_max,ln,co=0,me=0,ad;
+    int        add[1024],add2[1024],leng[1024];
+
+    m_max=add_set(size,add);if(m_max<2 || m_max>1024){return(size);}
+
+    for(i=0;i<m_max;i++){
+      po=add[i];ln=meas_len(size,po);match=0;
+      if(ln>4 && note[po+ln-4]==0xfc){ln=ln-4;}
+
+      if(note[po]<0xfc && me>0){
+       j=0;while(j<me ){
+         if(ln==leng[j] && note[add2[j]]<0xfc){
+           match=1;ad=add2[j];
+           k=0;while(k<ln){
+             if(note[po+k]!=note[ad]){match=0;break;}
+             k++;ad++;
+           }
+         }
+         if(match!=0){break;}
+         j++;
+       }
+      }
+
+      if(match!=0 && j<1024 && add2[j]<65536-44){
+       int ad=add2[j]+44;
+       if(me<1024){add2[me]=co;leng[me]=4;me++;}
+       note[co]=0xfc;
+       note[co+1]=j&0xff;note[co+2]=(j>>8)+(ad&0xfc);note[co+3]=ad>>8;
+       co=co+4;count++;
+      }else{
+       if(me<1024){add2[me]=co;leng[me]=ln;me++;}
+       for(k=0;k<ln;k++){note[co]=note[po];po++;co++;}
+      }
+    }
+    note[co]=0xfe;co=co+4;
+    return(co);
+  }
+
+static int add_set(int size,int *add)
+  {
+    int        co=0,i=0;
+
+    add[0]=0;
+    while(i<size){
+      if(note[i]>=0xfc||note[i+4]==0xfc){
+       co++;if(co<1024){add[co]=i+4;}
+      }
+
+      if(note[i]<128){
+       if(note[i+2]==0 || note[i+3]==0){note[i]=0;note[i+2]=0;note[i+3]=0;}
+      }
+      i=i+4;
+    }
+
+    return(co);
+  }
+
+static int meas_len(int size,int j)
+  {
+    int        co=0,d;
+
+    while(j<size ){
+      d=note[j];
+      if( d==0xfe ){break;}
+      co++;
+      if( d>0xfb ){break;}
+      j=j+4;
+    }
+    return(co*4);
+  }
+
+/***************************/
diff --git a/key_sub.cpp b/key_sub.cpp
new file mode 100644 (file)
index 0000000..10ddf91
--- /dev/null
@@ -0,0 +1,1045 @@
+/*
+ * STed2.x:key_sub.c midi in & chord & key name
+ */
+
+#include       "sted.h"
+
+/* ************** chord list */
+static char    chord_name[20][9]={
+  " MAJOR  "," 7      "," maj7   "," 6      "," maj9   ",
+  " 9      "," 7(b9)  "," 7(#9)  "," dim    "," dim7   ",
+  " 7(b5)  "," m7(b5) "," aug    "," aug7   "," 7sus4  ",
+  " 69     "," m9     "," m6     "," m7     "," m      "};
+
+static char    chord_pat[20][5]={
+  4, 7, 0, 0,0, /*     */      4, 7,10, 0,0, /* 7      */
+  4, 7,11, 0,0, /* maj7        */      4, 7, 9, 0,0, /* 6      */
+  4, 7,11,14,0, /* maj9        */      4, 7,10,14,0, /* 9      */
+  4, 7,10,13,0, /* 7(b9)       */      4, 7,10,15,0, /* 7(#9)  */
+  3, 6, 9, 0,0, /* dim */      3, 6,10, 0,0, /* dim7   */
+
+  4, 6,10, 0,0, /* 7(b5)       */      3, 6,10, 0,0, /* m7(b5) */
+  4, 8, 0, 0,0, /* aug */      4, 8,10, 0,0, /* aug7   */
+  5, 7,10, 0,0, /* 7sus4       */      4, 7, 9,14,0, /* 69     */
+  3, 7,10,14,0, /* m9  */      3, 7, 9, 0,0, /* m6     */
+  3, 7,10, 0,0, /* m7  */      3, 7, 0, 0,0, /* m      */
+};
+
+/* *** key scale *** */
+static char    key_name[32][4]={
+  " C "," G "," D "," A "," E "," B ","F# ","C# ",
+  " C "," F ","Bb ","Eb ","Ab ","Db ","Gb ","Cb ",
+
+  " A "," E "," B ","F# ","C# ","G# ","D# ","A# ",
+  " A "," D "," G "," C "," F ","Bb ","Eb ","Ab "};
+
+/*       C  C# D  D# E  F  F# G  G# A  A# B */
+static char    key_shi[16][12]={
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /*    */
+  0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,  /* #1 */
+  1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,  /* #2 */
+  1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0,  /* #3 */
+  1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0,  /* #4 */
+  1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0,  /* #5 */
+  1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0,  /* #6 */
+  1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1,  /* #7 */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  /*    */
+  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,  /* b1 */
+  0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0,-1,  /* b2 */
+  0, 0, 0, 0,-1, 0, 0, 0, 0,-1, 0,-1,  /* b3 */
+  0, 0,-1, 0,-1, 0, 0, 0, 0,-1, 0,-1,  /* b4 */
+  0, 0,-1, 0,-1, 0, 0,-1, 0,-1, 0,-1,  /* b5 */
+  -1, 0,-1, 0,-1, 0, 0,-1, 0,-1, 0,-1, /* b6 */
+  -1, 0,-1, 0,-1,-1, 0,-1, 0,-1, 0,-1, /* b7 */
+};
+
+/* *** note name *** */
+static char    note[12][3]={
+  "C ","C#","D ","D#","E ","F ","F#","G ","G#","A ","A#","B "};
+/*     "C ","Db","D ","Eb","E ","F ","Gb","G ","Ab","A ","Bb","B "};*/
+
+/*
+static char    note2[24][3]={
+  "C ","C\x12","D ","D\x12","E ","F ","F\x12","G ","G\x12","A ","A\x12","B ",
+  "C ","D\x11","D ","E\x11","E ","F ","G\x11","G ","A\x11","A ","B\x11","B "};
+*/
+
+static char    note2[24][3]={
+  "C ","C#","D ","D#","E ","F ","F#","G ","G#","A ","A#","B ",
+  "C ","Db","D ","Eb","E ","F ","Gb","G ","Ab","A ","Bb","B "};
+
+static char    oct[11]={
+  '.','0','1','2','3','4','5','6','7','8','9'};
+
+int    outch,prog;
+
+
+/***************************/
+void   inpmon()
+{
+  int  a,b,c,f=0;
+
+  all_note_off(1);outch=0;prog=0;
+
+  fill(0,544,767,1001,0);box(0,564,767,1001,14,65535);
+  sdis(0,548," MIDI INPUT MONITOR",20,15,8);
+  home2(512);
+
+  C_WINDOW(0,32);
+
+  B_LOCATE(2,31);B_PRINT("MIDI IN:");B_PRINT(mdinport());
+
+  B_LOCATE(25,31);B_PRINT("OUT MIDI CH.:THRU");
+  B_LOCATE(76,31);B_PRINT(_("[ESC] to exit."));
+  C_WINDOW(4,26);B_LOCATE(0,0);
+  midi_clr();
+
+  while(1){
+    if(f==0){a=midi_inout();}else{a=f;f=0;}
+    if( a<0 ){break;}
+
+    if( a>127 && a<0xf0){B_PRINT("\r\nch=");B_PRINT(fstr((a&15)+1,2));B_PRINT(" : ");}
+
+    if( a>=0x80 && a<=0x9f){
+      if( a<0x90 ){B_PRINT("note off :");}else{B_PRINT("note on  :");}
+      while(1){
+       b=midi_inout();if(b>127 ||b<0){f=b;break;}
+       c=midi_inout();
+       B_PRINT(keystr(b));B_PRINT(fstr(b,3));B_PRINT(",");
+       B_PRINT(fstr(c,3));B_PRINT(":");
+      }
+      a=-1;
+    }
+    if( a>=0xa0 && a<=0xaf){
+      B_PRINT("after key:");
+      while(1){
+       b=midi_inout();if(b>127 ||b<0){f=b;break;}
+       c=midi_inout();
+       B_PRINT(fstr(b,3));B_PRINT(",");
+       B_PRINT(fstr(c,3));B_PRINT(":");
+      }
+      a=-1;
+    }
+    if( a>=0xb0 && a<=0xbf){
+      B_PRINT("control  :");
+      while(1){
+       b=midi_inout();if(b>127 ||b<0){f=b;break;}
+       c=midi_inout();
+       B_PRINT(fstr(b,3));B_PRINT(",");
+       B_PRINT(fstr(c,3));B_PRINT(":");
+      }
+      a=-1;
+    }
+    if( a>=0xc0 && a<=0xcf){
+      b=midi_inout();
+      B_PRINT("prog ch. : no.=");B_PRINT(fstr(b+1,3));
+      a=-1;
+    }
+    if( a>=0xd0 && a<=0xdf){
+      B_PRINT("after ch.:");
+      while(1){
+       b=midi_inout();if(b>127 ||b<0){f=b;break;}
+       B_PRINT(fstr(b,3));B_PRINT(":");
+      }
+      a=-1;
+    }
+    if( a>=0xe0 && a<=0xef){
+      B_PRINT("pitch    :");
+      while(1){
+       b=midi_inout();if(b>127 || b<0){f=b;break;}
+       c=midi_inout();
+       B_PRINT(fstr((c*128+b)-8192,5));
+       B_PRINT(":");
+      }
+      a=-1;
+    }
+    if( a==0xf0 ){
+      B_PRINT("\r\n exclusive : ");
+      while(1){
+       b=midi_inout();if(b>127 || b<0){f=b;break;}
+       B_PRINT(hex_s(b,2));
+       B_PRINT("H ");
+      }
+      a=-1;
+    }
+    if( a>=0 ){B_PRINT(fstr(a,4));}
+  }
+  C_WINDOW(0,32);B_CLR_AL();home2(0);
+}
+
+/***************************/
+void   midi_change(int md)
+{
+  int  c;
+  char tmp0[64];
+
+  if(md!=0 && outch==0){return;}
+
+  B_CLR_AL();C_WINDOW(0,32);
+  if(md==0){
+    msg("OUT MIDI CH.=");
+    strcpy(tmp0,chstr(outch));
+    sinput(tmp0,0x803);c=strch(outch,tmp0);
+
+    if(c>=0 && c<=32){outch=c;}
+    msg_clr();B_LOCATE(38,31);
+    if(outch!=0){B_PRINT(chstr(outch));B_PRINT(" ");}else{B_PRINT("THRU");}
+  }else{
+    c=timsel(outch,0,36,prog);if(c>=0){c=c&0xff;}
+    if(c>=0){
+      prog=c;strcpy(tmp0,"PROGRAM:");strcat(tmp0,prog_name(outch,0,c,1));
+      B_LOCATE(44,31);B_PRINT(tmp0);
+    }
+    midi_chout(0xc0+((outch-1)&15));midi_chout(prog);
+  }
+  C_WINDOW(4,26);B_LOCATE(0,0);
+}
+
+/***************************/
+int    midi_inout()
+{
+  int  a,b,k;
+  while(1){
+    key_midi_wait(); // Oct.14.2002 Nagano
+    a=(*rcd->md_get)();if(a>=0 && a<0xf8){break;}
+    if( INPOUT(0xfe)!=0 ){
+      k=INPOUT(0xff);
+      if( k=='c' || k=='C' ){midi_change(0);}
+      if( k=='g' || k=='G' ){midi_change(1);}
+      if(k==27){return(-27);}
+    }
+  }
+  b=a;
+  if(outch>0 && b>127 && b<0xf0){b=(b&0xf0)+((outch-1)&15);}
+  midi_chout(b);
+
+  return(a);
+}
+
+/***************************/
+void   midi_chout(int a)
+{
+  int  pm;
+
+  pm=rcd->put_mode;
+  if(outch>0){rcd->put_mode=rcd->ch_port[outch-1];}
+  (*rcd->md_put)(a);
+  rcd->put_mode=pm;
+}
+
+/***************************/
+int    midi_in()
+{
+  int  a;
+  while(1){
+    if( INPOUT(0xfe)!=0 ){if(INPOUT(0xff)==27){return(-27);}}
+    a=(*rcd->md_get)();
+    if(a>=0 && a<0xf8){break;}
+  }
+  if(thrumode){(*rcd->md_put)(a);}
+  return(a);
+}
+
+/***************************/
+int    midi_in_fk()
+{
+  int  a;
+  while(1){
+    if( B_KEYSNS()!=0 ){
+      int a=B_KEYINP()>>8;
+      if(a>=0x63 && a<=0x6c){return((a-0x63)+(B_SFTSNS()&1)*16+0x200);}
+      if(a==1){return(-27);}
+    }
+    a=(*rcd->md_get)();
+    if(a>=0 && a<0xf8){break;}
+  }
+  if(thrumode){(*rcd->md_put)(a);}
+  return(a);
+}
+
+/***************************/
+void   midi_clr()
+{
+  while((*rcd->md_get)()!=-1){}
+}
+
+/***************************/
+int    polykey(int cde)
+{
+  int  a,b,c,f,co=0,bl=0;
+
+  f=cde;
+  if(cde<0x80){
+    c=midi_in();if(c>127 ||c<0){f=c;goto skip;}
+    if(c!=0){
+      bl++;dat[co]=cde;dat[co+1]=c;co=co+4;
+    }
+    f=0x90;
+  }
+skip:
+  while(1){
+    if(f==0){a=midi_in();}else{a=f;f=0;}
+    if(a<0){break;}
+
+    if( a>=0x80 && a<=0x9f){
+      while(1){
+       b=midi_in();if(b>127 ||b<0){f=b;break;}
+       c=midi_in();if(c>127 ||c<0){f=c;break;}
+       if(a<0x90 || c==0){
+         bl--;if(bl<=0){return(co);}
+       }else{
+         bl++;dat[co]=b;dat[co+1]=c;co=co+4;
+       }
+      }
+    }
+    if(f<0){break;}
+  }
+  return(co);
+}
+
+/***************************/
+int    onekey(int imd,int cde)
+{
+  int  a,co=0;
+
+  if(cde<0x80){dat[co]=cde;goto one_b;}
+
+one_a: a=midi_in();if(a>127 || a<0){goto next;}
+if(a>0xf7){goto one_a;}
+dat[co]=a;
+
+one_b: a=midi_in();if(a>127 || a<0){goto next;}
+if(a>0xf7){goto one_b;}
+dat[co+1]=a;
+
+if(dat[co+1]>0){co+=4;}
+if(imd==4 && co==4){return 4;}
+twait(4);
+loop:
+if( INPOUT(0xfe)!=0 ){if(INPOUT(0xff)==27){return(-27);}}
+a=(*rcd->md_get)();if(a>0xf7){goto loop;}
+if(a>=0 && thrumode){(*rcd->md_put)(a);}
+if(a>=0 && a<128){dat[co]=a;goto one_b;}
+next:
+if(a>=0x90 && a<=0x9f){goto one_a;}
+
+return(co);
+}
+
+/***************************/
+static inline int      onekey2()
+{
+  int  a,b,c;
+
+one_a: a=midi_in_fk();if(a<0 || a>=0x200){return(a);}
+if(a>127 && (a>0x9f || a<0x90)){
+  while((a>0x9f || a<0x90)){
+    a=midi_in_fk();if(a<0 || a>=0x200){return(a);}
+  }
+  goto one_a;
+}
+if(a>127 ){
+  b=midi_in_fk();if(b<0 || b>=0x200){return(b);}
+}else{b=a;}
+c=midi_in();if((b>=0x80 && b<=0x8f) || c==0){goto one_a;}
+
+return(b);
+}
+
+/***************************/
+int    ret_midi(int cde,int imd,int ad,int cy)
+{
+  int  j,co=0,po=0,cc,k;
+  unsigned char        b=48,c=46;
+
+  msg("MIDI INPUT(NOTE)");
+  if(imd==3 || imd==5){co=polykey(cde);}else{co=onekey(imd,cde);}
+  msg_clr();if(co==0){return 0;}
+
+  if(imd>=4){
+    if(keyst_table[0][dat[0]]==255){
+      unsigned char    cd=keyst_table[1][dat[0]];
+      if(cd==0){dat[0]=0;co=4;}
+      if(cd==1){return -1;}
+      if(cd==2){return -2;}
+    }
+  }
+
+  line_ins_aft(ad);
+  if(trk_shift(ad,co)!=0){return(0);}
+
+  if( ad>0 ){
+    j=ad;
+    while(j>0){
+      j=j-4;
+      if( trk[track][j]<128 ){b=trk[track][j+1];c=trk[track][j+2];
+      if(b>0){if(c==0){c=b-1;}break;}
+      }
+    }
+  }
+
+  if(imd>=4){
+    fnc_dis(2);
+  key2in:              msg("MIDI INPUT(ST/GT)");k=onekey2();msg_clr();
+  if(k>=0x200){
+    int kk=(k&15);
+    b=stgt_tbl[kk];c=stgt_tbl[kk+10];if(k&16){c=0;}
+  }else{
+    if(k>=0){
+      b=keyst_table[0][k];c=keyst_table[1][k];
+      if(b==0 || b==255){goto key2in;}
+      if(dat[0]==0){c=0;}
+    }
+  }
+  fnc_dis(0);
+  }
+  cc=co;
+  while(co>0){
+    unsigned char      a,d;
+    if(co>4 && (imd==3||imd==5)){a=0;}else{a=b;}
+    if(c==0){d=0;}else{d=dat[po+1];}
+    trk[track][ad]=dat[po];trk[track][ad+1]=a;
+    trk[track][ad+2]=c;trk[track][ad+3]=d;
+    co=co-4;po=po+4;ad+=4;
+  }
+  return(cc);
+}
+
+/***************************/
+int    ret_chord(int ad)
+{
+  int  co;
+
+  undobuf(0);
+  co=chord_sel(trk[track][ad],ad);if(co<2){return(0);}
+  line_ins_aft(ad);
+  if(chord_ins(ad,co)!=0){return(0);}else{return(co*4-4);}
+}
+
+/***************************/
+int    chord_sel(int key,int ad)
+{
+  int  po,i,ke,kc,sh,exc=0,no=0,d,okey;
+  char temp[16];
+
+  chord_dis(0);okey=key;po=chord_ten(key,0);
+
+  while( 1){
+    msg("chord :");B_PRINT(keystr(key));
+    B_PRINT(":");B_PRINT(chord_name[no]);
+    B_PRINT(":");for(i=0;i<po;i++){B_PRINT(" ");B_PRINT(keystr(dat[i]));}
+
+    if(grpmode!=0){
+      if(chord_ins(ad,po)==0){
+       gra(ad,0);trk_delete(ad,po*4-4);snsclr();
+      }
+    }
+
+    /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+    key_wait();
+    ke=B_KEYINP();kc=ke&0xff;ke=ke>>8;sh=B_SFTSNS();
+
+    if( ke==0x70 ){chord_dis(10);}
+    if( ke==0xf0 ){chord_dis(0);}
+
+    if(ke==1){exc=-1;trk[track][ad]=okey;break;}
+    if( kc==13 ){exc=po;break;}
+
+    if( ke>0x62 && ke<0x6d ){
+      if( (sh & 1)!=0 ){no=ke-0x63+10;}else{no=ke-0x63;}
+      po=chord_ten(key,no);
+    }
+
+    /*cursor*/
+    if( kc==0x13 || ke==0x3b){
+      no--;if( no<0 ){no=19;}
+      po=chord_ten(key,no);
+    }
+    if( kc==0x04 || ke==0x3d){
+      no++;if( no>19 ){no=0;}
+      po=chord_ten(key,no);
+    }
+    if( kc==0x05 || ke==0x3c){
+      if((dat[0]+12)<=127){
+       int     i;
+       d=dat[0];for(i=1;i<po;i++){dat[i-1]=dat[i];}
+       dat[po-1]=d+12;
+      }
+    }
+    if( kc==0x18 || ke==0x3e){
+      if((dat[po-1]-12)>=0){
+       int     i;
+       d=dat[po-1];for(i=po-1;i>=1;i--){dat[i]=dat[i-1];}
+       dat[0]=d-12;
+      }
+    }
+
+    /*roll */
+    if( ke==0x39 ){if(key>0){key--;po=chord_ten(key,no);}}
+    if( ke==0x38 ){if(key<127){key++;po=chord_ten(key,no);}}
+
+    if(kc==7 && edit_scr==0){
+      noed_cls();
+      grpmode++;if(grpmode>4){grpmode=0;}
+    }
+    if(kc=='M'||kc=='m'||ke==0x55 ||ke==0x3a){
+      if(chord_ins(ad,po)==0){
+       int     i;
+       for(i=0;i<po;i++){temp[i]=dat[i];}
+       poplay(ad+po*4-4,7);trk_delete(ad,po*4-4);
+       for(i=0;i<po;i++){dat[i]=temp[i];}
+      }
+    }
+  }
+  if((sh&1)!=0){fnc_dis(1);}else{fnc_dis(0);}
+  msg_clr();
+  return(exc);
+}
+
+/***************************/
+int    chord_ten(int key,int no)
+{
+  int  po,i,j;
+
+  dat[0]=key;po=1;
+  for(i=0;i<=4;i++){
+    if(chord_pat[no][i]!=0 ){
+      j=key+chord_pat[no][i];
+      if(j<128 && j>=0){dat[po]=j;po++;}
+    }
+  }
+  return(po);
+}
+
+/***************************/
+int    chord_ins(int ad,int co)
+{
+  int  po,gt,vl;
+
+  if(trk_shift(ad,co*4-4)!=0){return(1);}
+  gt=trk[track][ad+2];vl=trk[track][ad+3];po=0;
+  while(co>0){
+    trk[track][ad]=dat[po];trk[track][ad+2]=gt;trk[track][ad+3]=vl;
+    if(co>1){trk[track][ad+1]=0;}
+    co--;po++;ad=ad+4;
+  }
+  return(0);
+}
+
+/***************************/
+void   chord_dis(int n)
+{
+  int  i,j;
+  char tmp[2];
+
+  KNJCTRL(1,0);
+
+  tmp[0]=32;tmp[1]=0;if(n!=0){tmp[0]='*';}
+  B_PUTMES(3,0,31,1,tmp);
+
+  for(i=0;i<=9;i++){
+    j=i*9+2;if(i>4){j+=3;}
+    B_PUTMES(11,j,31,7,chord_name[i+n]);
+  }
+}
+
+/***************************/
+int    ctc(int da,char *s,int skey)
+{
+  int  ct,co,dd=0,i,a;
+
+  if( da>127 ){da=60;if( da>255 ){dd=1;}}
+  if( s[0]==0 ){return(-1);}
+  jstrupr(s);ct=0;
+  i=0;while(s[i]!=0){
+    a=s[i++];
+    if( a=='H' ){ct=0;break;}
+    if( a=='$' ){strcpy(s,&s[1]);ct=0;break;}
+
+    if( a=='C' ){ct=1;}
+    if( a=='D' ){ct=3;}
+    if( a=='E' ){ct=5;}
+    if( a=='F' ){ct=6;}
+    if( a=='G' ){ct=8;}
+    if( a=='A' ){ct=10;}
+    if( a=='B' ){ct=12;}
+
+    if( ct!=0 && s[i]=='B'){i++;ct--;skey=0;}
+    if( a=='N' || a=='=' || a=='#' || a=='+' || a=='-' ){skey=0;}
+  }
+
+  if( da<0 ){if( ct>0 ){return(1);}else{return(0);}}
+  if( ct==0 ){
+    da=str_val(s);
+  }else{
+    ct=ct+key_shi[skey&15][ct-1];
+
+    co=(da/12)-1;
+    i=0;while(s[i]!=0){
+      a=s[i++];
+      if( a=='#' || a=='+' ){ct++;}
+      if( a=='-' ){ct--;}
+      if( a>='0' && a<='9' ){co=a-'0';}
+      if( a=='.' ){co=-1;}
+      if( a=='<' && dd==0 ){co++;}
+      if( a=='>' && dd==0 ){co--;}
+    }
+    da=((co+1)*12+ct-1);
+  }
+  if(da<0||da>127){da=-1;}
+  return(da);
+}
+
+/***************************/
+char   *keystr(int da)
+{
+  static char  tmp0[8];
+  int  a,b;
+
+  a=((da*43))>>9;b=da-(a*12);
+  strcpy(tmp0,note[b]);tmp0[2]=oct[a];tmp0[3]=0;return(tmp0);
+}
+
+char   *keystr1(int da,int skey)
+{
+  static char  tmp0[8];
+  int  a,b,bb;
+
+  a=((da*43))>>9;b=da-(a*12);
+  strcpy(tmp0,note2[b]);
+
+  bb=b+1;if(bb>11){bb=0;}
+  if(key_shi[skey&15][bb]<0){strcpy(tmp0,note2[b+12]);}
+
+  tmp0[2]=oct[a];tmp0[3]=0;
+  return(tmp0);
+}
+
+/***************************/
+char   *keystr2(int da,int skey)
+{
+  static char  tmp0[8];
+  int  a,b;
+
+  a=((da*43))>>9;b=da-(a*12);key_shift_sub(skey&15,&a,&b);
+  strcpy(tmp0,note[b]);tmp0[2]=oct[a];tmp0[3]=0;return(tmp0);
+}
+
+/***************************/
+/* functions for treating channel / port numbers */
+/* May.06.2001 NAGANO Daisuke <breeze.nagano@nifty.ne.jp> */
+
+/*
+   print port / channel number
+    input: port_number*16 + channel_number + 1
+    output: ("%c%02d", port_number+'A', channel_number)
+*/
+char   *chstr(int ex)
+{
+  static char  tmp0[8];
+
+  if ( issted3 ) {
+    if ( ex<1 || ex>STED3_MAX_PORT_NUMBER * 16 ) {
+      strcpy(tmp0, "OFF");
+    }
+    else {
+      tmp0[0]=((ex-1)>>4)+'A';tmp0[1]=0;
+      strcat(tmp0,fstr(((ex-1)&15)+1,2));
+    }
+  }
+  else {
+    if(ex<1 || ex>32){
+    strcpy(tmp0,"OFF");
+    }else{
+      tmp0[0]=((ex-1)>>4)+'A';tmp0[1]=0;
+      strcat(tmp0,fstr(((ex-1)&15)+1,2));
+    }
+  }
+  return(tmp0);
+}
+/***************************/
+/*
+  get port / channel number from *tmp0
+   input:  och  = old port/channel number
+           tmp0 = pointer for input parameter
+   output: port_number*16 + channel_number+1
+ */
+int    strch(int och,char *tmp0)
+{
+  int ex;
+  int port_number;
+
+  jstrupr(tmp0);
+
+  port_number = tmp0[0]-'A';
+  if ( issted3 ) {
+    if( port_number >= 0 && port_number < STED3_MAX_PORT_NUMBER){
+      ex=str_val(&tmp0[1]);
+      if(ex<1 || ex>16){ex=1;}
+      
+      if(tmp0[1]==0 && och>0){ex=((och-1)&15)+1;}
+      
+      ex+=port_number*16;
+    }else{
+      ex=str_val(tmp0);
+      if(ex<0 || ex>32){ex=0;}
+      if(och>16 && ex<17){ex+=16;}
+    }
+  }
+  else {
+    if( port_number==0 || port_number==1 ){
+      ex=str_val(&tmp0[1]);
+      if(ex<1 || ex>16){ex=1;}
+      
+      if(tmp0[1]==0 && och>0){ex=((och-1)&15)+1;}
+      
+      ex+=port_number*16;
+    }else{
+      ex=str_val(tmp0);
+      if(ex<0 || ex>32){ex=0;}
+      if(och>16 && ex<17){ex+=16;}
+    }
+  }
+
+  return(ex);
+}
+
+/***************************/
+int    key_shift(int skey,int *f,int *a)
+{
+  static       char    shfl[12]={0,1,0,1,0,0,1,0,1,0,1,0};
+  int  no;
+
+  no=skey&15;
+  if(key_shi[no][*a]!=0){return(-1);}
+  key_shift_sub(no,&*f,&*a);
+  return(shfl[*a]);
+}
+
+/***************************/
+void   key_shift_sub(int no,int *f,int *a)
+{
+  int  n;
+
+  n=*a-1;if(n<0){n=11;}
+  if(key_shi[no][n]>0){*a=n;if(n==11 && *f>0){*f=*f-1;}}
+  n=*a+1;if(n>11){n=0;}
+  if(key_shi[no][n]<0){*a=n;if(n==0 && *f<10){*f=*f+1;}}
+}
+
+/***************************/
+char   *scale_str(int da)
+{
+  int  a;
+  static       char    tmp0[16];
+
+  da=da&31;strcpy(tmp0,key_name[da]);
+  if(da<16){strcat(tmp0,"MAJOR");}else{strcat(tmp0,"minor");}
+
+  a=da&15;
+  if(a==0 || a==8){
+    strcat(tmp0,"     ");
+  }else{
+    if(a>7 ){strcat(tmp0,_("(b  )"));}else{strcat(tmp0,_("(#  )"));}
+    tmp0[11]='0'+(a&7);
+  }
+  return(tmp0);
+}
+
+/***************************/
+int    scale_no(int j)
+{
+  int  d,skey;
+
+  skey=bkey;
+  while(j>=0){
+    d=trk[track][j];
+    if( d==0xf5 ){skey=trk[track][j+1];break;}
+    if( d>0xfb ){break;}
+    j=j-4;
+  }
+  return(skey);
+}
+
+/***************************/
+int    scale_sel(int x,int y,int skey)
+{
+  int  mf,sf,kc,ke;
+
+  skey=skey&31;mf=skey&16;sf=skey&15;
+
+  while(1){
+    B_LOCATE(x,y);B_PRINT(scale_str(sf+mf));
+
+    /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+    key_wait();
+    ke=B_KEYINP();kc=ke&0xff;ke=ke>>8;
+
+    if(kc==' '){mf=16-mf;}
+    if(kc=='+'||kc=='#'){              sf=sf&7;}
+    if(kc=='-'||kc=='b'||kc=='B'){     sf=sf|8;}
+    if(kc>='0' && kc<='7'){sf=(sf&8)+(kc-'0');}
+    if(kc==13 || kc==27){break;}
+    if( ke==0x38){if(sf<15){sf++;}}
+    if( ke==0x39){if(sf>0){sf--;;}}
+  }
+
+  if(kc==13){return(sf+mf);}
+  return(-1);
+}
+
+/***************************/
+char   *prog_name(int ch,int bank,int prog,int h)
+{
+  int  i,i0,symn,bank_l,bank_m,hh,sf=0;
+  static char  tmp0[32];
+  char tmp1[32];
+
+  hh=h>>1;h=h&1;
+  bank_l=(bank>>8)&0x7f;
+  bank_m=bank&0x7f;
+
+  if(bank<0){bank_l=0;bank_m=0;}
+
+  if((cmdflag&0x20)!=0){sf=1;}
+
+  if(ch>32){ch=0;}
+  i=tim_asin[ch];
+  tmp0[0]=0;
+  /*
+    if(gs_mode[16]!=0 && i==7){i=gs_bank[16*128+bank_l];}
+    if(gs_mode[17]!=0 && i==8){i=gs_bank[17*128+bank_l];}
+    */
+  if((gs_mode[16]&4)!=0 ){
+    if((gs_mode[16]&128)!=0 && i==7){i=gs_bank[16*128+bank_l];}
+    if((gs_mode[17]&128)!=0 && i==8){i=gs_bank[17*128+bank_l];}
+  }else{
+    if((gs_mode[16]&128)!=0 && i==7){i=gs_bank[16*128+bank_m];}
+    if((gs_mode[17]&128)!=0 && i==8){i=gs_bank[17*128+bank_m];}
+  }
+
+
+  if(i>399||i==0||i==2||prog>127||prog<0||(cmdflag&0x1)!=0 ){
+    if(h!=0){strcpy(tmp0,"     ");}
+    if(prog<0){strcpy(tmp0,"  OFF");}else{
+      strcat(tmp0,fstr(prog+sf,5));
+      if(hh){strcat(tmp0,fstr(bank&127,6));}
+    }
+  }else{
+    symn=i;
+    if(i==7||i==9||i==11||i==13){symn=gs_bank[i*128+varia(tmp1,bank,prog,i)];}
+    if(i==8||i==10||i==12||i==14){symn=gs_bank[i*128+varia(tmp1,prog,0,i+16)];}
+    if(h!=0){
+      if(symn>0){strcpy(tmp0,tim_sym[symn-1]);}
+      if((i>=7 && i<=14) && tmp0[0]==0){strcpy(tmp0,tim_sym[i-1]);}
+      strcpy(tmp0,spadd(tmp0,6));
+    }else{
+      strcpy(tmp0," ");
+    }
+    if( i>=7 && i<=14){
+      if(h!=0){tmp0[5]=0;}else{tmp0[0]=0;if(tmp1[0]==':'){tmp1[0]=32;}}
+      if(tmp1[1]==0){strcat(tmp1,tim_names(prog+i*128-128));}
+      if(tmp1[1]!=0){strcat(tmp0,tmp1);}
+    }else{
+      if( i==1 ){
+       i0=cm6[0xa34+prog*8]*64+cm6[0xa35+prog*8];
+      }else{
+       if( i==3 ){
+         i0=cm6[0x4eb2+prog*19]*128+cm6[0x4eb3+prog*19]+256;
+       }else{i0=prog+i*128-128;}
+      }
+      strcat(tmp0,tim_names(i0));
+    }
+    if(tmp0[h*6]==0){strcat(tmp0,fstr(prog+sf,6));
+    if(hh){strcat(tmp0,fstr(bank&127,6));}
+    }
+  }
+  strcpy(tmp0,spadd(tmp0,18));return(tmp0);
+}
+
+/***************************/
+char   *tim_names(int no)
+{
+  static       char    tmp0[128];
+  int  nm,bank=no>>7;no=no&0x7f;
+
+  if(bank<4){strcpy(tmp0,tim_name[bank*128+no]);return tmp0;}
+
+  tmp0[0]=0;nm=tim_top[bank];
+
+  while(tim_name[nm][0]!=0){
+    if(tim_name[nm][14]==no){strncpy(tmp0,tim_name[nm],14);break;}
+    nm++;
+  }
+  return tmp0;
+}
+
+/***************************/
+int    mml_inp(int ad)
+{
+  int  i,j,a,ct,da,co=0,oct=4,st=48,gt=46,vel=64,/*nn=0,*/ntc=0,nts=0;
+  int  skey,skey2=scale_no(ad);
+  char s[40],nt[16];
+  /*
+    int        lpad[18];
+    unsigned char lpco[18];
+    */
+  if( ad>0 ){
+    j=ad-4;
+    while( trk[track][j]>127 && j>=0){j=j-4;}
+    if( j>=0 ){
+      st=trk[track][j+1];gt=trk[track][j+2];vel=trk[track][j+3];
+
+      if(st==0){st=48;}
+      if(gt==0 && st>2){gt=st-2;}
+      if(vel==0){vel=64;}
+    }
+  }
+
+  /*oct=(da/12)-1;*/
+
+  if( trrhy[track]&0x80 ){skey=0;skey2=0;}
+
+  msg("MML:");sinput(s,0x800+32);
+  jstrupr(s);
+
+  if(es==0){
+    i=0;
+    while(s[i]!=0){
+    loop1:
+      a=s[i++];
+
+      /*
+       if(a=='[' && nn<16){
+       nn++;lpad[nn]=i;lpco[nn]=0;
+       }
+       if(a==']' && nn>0){
+       int a=0;
+       while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+       if(a>=1 && a<=256){
+       lpco[nn]+=1;
+       if(lpco[nn]!=a){i=lpad[nn];goto loop1;}
+       }
+       nn--;
+       }
+       */
+      if(a=='['){
+       dat[co++]=0xf9;dat[co++]=0;
+       dat[co++]=0;dat[co++]=0;
+      }
+      if(a==']'){
+       int a=0;
+       while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+       if(a>=1 && a<=256){
+         dat[co++]=0xf8;dat[co++]=a;
+         dat[co++]=0;dat[co++]=0;
+       }
+      }
+
+      if(a==0x27 || a==0x60){
+       if(nts==0){
+         nts=1;ntc=0;/*goto loop1;*/
+       }else{
+         int a=0,ss=st,gg=gt;
+         while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+         if(a>=1 && a<256){ss=a;}
+         if(s[i]==','){i++;
+         a=0;
+         while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+         if(a>=1 && a<256){gg=a;}
+         }
+
+         nts=0;
+         if(ntc){
+           int i;
+           for(i=0;i<ntc;i++){
+             dat[co++]=nt[i];dat[co++]=0;
+             dat[co++]=gg;dat[co++]=vel;
+           }
+           dat[co-3]=ss;/*goto loop1;*/
+         }
+       }
+      }
+
+
+      if( a=='O' ){
+       if(s[i]>='0' && s[i]<='9'){oct=s[i++]-'0';}
+       if(s[i]=='.' ){oct=-1;i++;}
+      }
+      if( a=='L' ){
+       if(s[i]>='0' && s[i]<='9'){
+         int a=0;
+         while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+         if(a>=1 && a<=64){st=192/a;gt=st-2;}
+       }
+      }
+      if( a=='V' ){
+       if(s[i]>='0' && s[i]<='9'){
+         int a=0;
+         while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+         if(a>=0 && a<=127){vel=a;}
+       }
+      }
+
+      if( a=='<' && oct<9){oct++;}
+      if( a=='>' && oct>0){oct--;}
+
+      if((a>='A' && a<='G') ||a=='R'){
+       int ss=st,gg=gt;
+
+       skey=skey2;
+       ct=-1;
+       if( a=='C' ){ct=1;}
+       if( a=='D' ){ct=3;}
+       if( a=='E' ){ct=5;}
+       if( a=='F' ){ct=6;}
+       if( a=='G' ){ct=8;}
+       if( a=='A' ){ct=10;}
+       if( a=='B' ){ct=12;}
+
+       if( s[i]=='N' || s[i]=='=' || s[i]=='#' || s[i]=='+' || s[i]=='-' ){
+         if( *s=='#' || *s=='+' ){ct++;}
+         if( *s=='-' ){ct--;}
+
+         i++;
+         skey=0;
+       }
+
+       if(s[i]>='0' && s[i]<='9'){
+         int a=0;
+         while(s[i]>='0' && s[i]<='9'){a=a*10+s[i++]-'0';}
+         if(a>=1 && a<=64){ss=192/a;gg=ss-2;}
+       }
+
+       if(ct>=0){
+         ct=ct+key_shi[skey&15][ct-1];
+         da=((oct+1)*12+ct-1);
+
+         if( da>=0 && da<=127 ){
+           if(nts!=0 && ntc<16){
+             nt[ntc++]=da;
+           }else{
+             dat[co++]=da;dat[co++]=ss;
+             dat[co++]=gg;dat[co++]=vel;
+           }
+         }
+       }else{
+         if(nts==0){
+           dat[co++]=0;dat[co++]=ss;
+           dat[co++]=0;dat[co++]=0;
+         }
+       }
+      }
+    }
+
+    if(co){
+      if(trk_shift(ad,co)!=0){snsclr();return(0);}
+      memcpy_l(&trk[track][ad],dat,co);
+    }
+  }
+
+  msg_clr();
+  return(co);
+}
+
+/***************************/
diff --git a/machin.h b/machin.h
new file mode 100644 (file)
index 0000000..21710f7
--- /dev/null
+++ b/machin.h
@@ -0,0 +1,24 @@
+/*
+ * ----------------------------------------
+ *     assembler Module の宣言
+ * ----------------------------------------
+ */
+#pragma once
+
+#ifndef _MACHIN_H_
+#define _MACHIN_H_
+
+void   OnGraphic(void);
+
+void   H_ERA(void);
+void   H_PRINT(char *, char *, char *);
+void   H_PRINT2(char *, char *, char *);
+void   H_INIT(void);
+void   LDIRL(VIDEO *, VIDEO *, int);
+
+void   key_rep_off(void);
+void   key_rep_on(void);
+void   key_vect_set(void);
+void   key_vect_reset(void);
+
+#endif /* _MACHIN_H_ */
diff --git a/mcpy.cpp b/mcpy.cpp
new file mode 100644 (file)
index 0000000..f0435ee
--- /dev/null
+++ b/mcpy.cpp
@@ -0,0 +1,89 @@
+/*
+  mcpy.c
+
+  functions for compatibility to mcpy.s
+  ( some memory-oriented functions )
+
+  Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+/*
+  void memcpy_l( unsigned char *dest, unsigned char *src , int len )
+
+   copies len bytes from src to dest
+
+   I guess that original programmer want to make fast copy function
+   by coding long-word copy routine.
+ */
+
+void memcpy_l( unsigned char *dest, unsigned char *src, int len ) {
+
+  memmove( (void *)dest, (void *)src, (size_t)len );
+  return;
+
+#if 0
+  int d1,d2;
+
+  if ( !len ) return;
+  if ( dest=src ) return;
+
+  len/=4;
+  d2=len;
+  len--;
+  d1=d0;
+
+  if ( dest > src ) {
+    d2*=4;
+    dest+=d2;
+    src+=d2;
+  }
+
+  while ( len ) {
+    while ( d1 ) {
+      *(--dest) == *(--src);
+    }
+  }
+  return;
+#endif
+
+}
+
+/*
+  void keyclr( void )
+
+   clear key buffer
+
+ */
+
+void
+keyclr( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+  scr->ClearKeyBuffer();
+}
+
diff --git a/midi_in.cpp b/midi_in.cpp
new file mode 100644 (file)
index 0000000..1fa4f00
--- /dev/null
@@ -0,0 +1,112 @@
+/* midi_in.c
+
+   midi-port access functions
+
+   Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+#include "sted.h"
+#include "sted_screen.h"
+
+int
+open_midi_device( char *in_dev_name )
+{
+  CSTedScreenBase* scr;
+  scr = GetDriver();
+  if (!scr) return -1;
+
+  return scr->OpenMidiDevice();
+}
+
+void
+close_midi_device( void )
+{
+  CSTedScreenBase* scr;
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->CloseMidiDevice();
+  return;
+}
+
+int
+get_midi_data( void )
+{
+  CSTedScreenBase* scr;
+  scr = GetDriver();
+  if (!scr) return -1;
+
+  return scr->GetMidiData();
+}
+
+int
+is_midi_in( void )
+{
+  CSTedScreenBase* scr;
+  scr = GetDriver();
+  if (!scr) return 0;
+
+  return scr->CanMidiRead();
+}
+
+void
+put_midi_data ( char in_data )
+{
+  CSTedScreenBase* scr;
+  scr = GetDriver();
+  if (!scr) return;
+
+  scr->PutMidiData((int)(in_data+128));
+}
+
+// midi player
+int
+start_player(unsigned char* in_data, int in_len)
+{
+       if (!in_data) return -1;
+
+       CSTedScreenBase* scr;
+       scr = GetDriver();
+       if (!scr) return -1;
+
+       return scr->StartMidiPlayer(in_data, in_len);
+}
+
+int
+stop_player(void)
+{
+       CSTedScreenBase* scr;
+       scr = GetDriver();
+       if (!scr) return -1;
+
+       return scr->StopMidiPlayer();
+}
+
+int
+close_player(int in_sig)
+{
+       CSTedScreenBase* scr;
+       scr = GetDriver();
+       if (!scr) return -1;
+
+       return scr->CloseMidiPlayer(in_sig);
+}
diff --git a/midi_in.h b/midi_in.h
new file mode 100644 (file)
index 0000000..c9dea7f
--- /dev/null
+++ b/midi_in.h
@@ -0,0 +1,39 @@
+/*
+  midi_in.h
+
+  prototype dec.s for functions midi port access
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#pragma once
+
+#ifndef _MIDI_IN_H_
+#define _MIDI_IN_H_
+
+
+ int open_midi_device( char * );
+ void close_midi_device( void );
+ int get_midi_data( void );
+ int is_midi_in( void );
+ void put_midi_data(char);
+
+#endif /* _MIDI_IN_H */
diff --git a/mididev.cpp b/mididev.cpp
new file mode 100644 (file)
index 0000000..dd0a3fb
--- /dev/null
@@ -0,0 +1,212 @@
+/**\r
+\r
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>\r
+  Dec.18.1999\r
+  Oct.16.2002\r
+\r
+\r
+  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+  of this software and associated documentation files (the "Software"), to deal\r
+  in the Software without restriction, including without limitation the rights\r
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+  copies of the Software, and to permit persons to whom the Software is\r
+  furnished to do so, subject to the following conditions:\r
+\r
+  The above copyright notice and this permission notice shall be included in\r
+  all copies or substantial portions of the Software.\r
+\r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+  THE SOFTWARE.\r
+*/\r
+\r
+/* ------------------------------------------------------------------- */\r
+\r
+#ifdef HAVE_CONFIG_H\r
+#include "config.h"\r
+#endif /* HAVE_CONFIG_H */\r
+\r
+\r
+#include "sted_screen.h"\r
+\r
+\r
+#include "rcp.h"\r
+#include "mididev.h"\r
+#include "sted.h"\r
+\r
+namespace {\r
+int reset_mode;\r
+}\r
+\r
+/* MIDI reset messages */\r
+\r
+static const unsigned char gs_reset[] = {\r
+  0xf0, 0x41, 0x10, 0x42, 0x12, 0x40, 0x00, \r
+  0x7f, 0x00, 0x41, 0xf7,\r
+  0xff }; /**< GS音源のリセットデータ */\r
+\r
+static const unsigned char gm_reset[] = {\r
+  0xf0, 0x7e, 0x7f, 0x09, 0x01, 0xf7,\r
+  0xff };///< GM音源のリセットデータ \r
+\r
+static const unsigned char S8_reset[] = {\r
+  0xf0, 0x41, 0x10, 0x42, 0x12, 0x00, 0x00,\r
+  0x7f, 0x00, 0x01, 0xf7,\r
+  0xff }; /**< Single module mode */\r
+\r
+static const unsigned char XG_reset[] = {\r
+  0xf0, 0x43, 0x10, 0x4c, 0x00, 0x00,\r
+  0x7e, 0x00, 0xf7,\r
+  0xff };///< XG音源のリセットデータ\r
+\r
+static const unsigned char all_reset[] = {\r
+  0xb0, 0x7b, 0x00, 0xb0, 0x78, 0x00, 0xb0, 0x79, 0x00,\r
+  0xb1, 0x7b, 0x00, 0xb1, 0x78, 0x00, 0xb1, 0x79, 0x00,\r
+  0xb2, 0x7b, 0x00, 0xb2, 0x78, 0x00, 0xb2, 0x79, 0x00,\r
+  0xb3, 0x7b, 0x00, 0xb3, 0x78, 0x00, 0xb3, 0x79, 0x00,\r
+  0xb4, 0x7b, 0x00, 0xb4, 0x78, 0x00, 0xb4, 0x79, 0x00,\r
+  0xb5, 0x7b, 0x00, 0xb5, 0x78, 0x00, 0xb5, 0x79, 0x00,\r
+  0xb6, 0x7b, 0x00, 0xb6, 0x78, 0x00, 0xb6, 0x79, 0x00,\r
+  0xb7, 0x7b, 0x00, 0xb7, 0x78, 0x00, 0xb7, 0x79, 0x00,\r
+  0xb8, 0x7b, 0x00, 0xb8, 0x78, 0x00, 0xb8, 0x79, 0x00,\r
+  0xb9, 0x7b, 0x00, 0xb9, 0x78, 0x00, 0xb9, 0x79, 0x00,\r
+  0xba, 0x7b, 0x00, 0xba, 0x78, 0x00, 0xba, 0x79, 0x00,\r
+  0xbb, 0x7b, 0x00, 0xbb, 0x78, 0x00, 0xbb, 0x79, 0x00,\r
+  0xbc, 0x7b, 0x00, 0xbc, 0x78, 0x00, 0xbc, 0x79, 0x00,\r
+  0xbd, 0x7b, 0x00, 0xbd, 0x78, 0x00, 0xbd, 0x79, 0x00,\r
+  0xbe, 0x7b, 0x00, 0xbe, 0x78, 0x00, 0xbe, 0x79, 0x00,\r
+  0xbf, 0x7b, 0x00, 0xbf, 0x78, 0x00, 0xbf, 0x79, 0x00,\r
+  0xff };///< 全チャンネルのリセットデータ\r
+\r
+static const unsigned char *reset_exclusives[]={\r
+  gm_reset, gs_reset, S8_reset, XG_reset\r
+};///< MIDIエクスクルーシブによる各種音源のリセットデータ配列\r
+\r
+/* ------------------------------------------------------------------- */\r
+\r
+static int           block_write = FLAG_TRUE;\r
+static unsigned char midibuf[1024];///< MIDIバッファ\r
+static int           midibuf_ptr = 0;///< MIDIバッファへのポインタ\r
+\r
+/* ------------------------------------------------------------------- */\r
+\r
+\r
+/** \r
+ @brief MIDIバッファにデータを保存する\r
+ @return 1..値が0-255の範囲にない 0..成功\r
+*/\r
+int\r
+sayleen_put_midi( int data /**< 0-255までの8ビット MIDIデータ */) {\r
+\r
+  if ( data < 0 || data > 255 ) { return 1; }\r
+\r
+  if ( midibuf_ptr >= 1023 ) {\r
+    sayleen_flush_midi();\r
+  }\r
+  midibuf[midibuf_ptr++] = (unsigned char)data;\r
+\r
+  return 0;\r
+}\r
+\r
+/**\r
+  MIDIバッファのデータをMIDIデバイスに送る\r
+  @return -1..デバイスが取得できない 0..成功\r
+*/\r
+int\r
+sayleen_flush_midi( void ) {\r
+       int i;\r
+       CSTedScreenBase* scr = GetDriver();\r
+       if (!scr) return -1;\r
+\r
+       if ( midibuf_ptr > 0 ) {\r
+               for (i=0; i<midibuf_ptr; i++) {\r
+                       scr->PutMidiData(midibuf[i]);\r
+               }\r
+               midibuf_ptr = 0;\r
+       }\r
+       return 0;\r
+}\r
+\r
+/** 出力MIDIポートを変更する*/\r
+\r
+int sayleen_change_midi_port(int port)\r
+{\r
+  sayleen_put_midi( 0xf5 );\r
+  sayleen_put_midi( port+1 );\r
+       return 0;\r
+}\r
+\r
+/** MIDIポートをすべてリセットする */\r
+int /**< 0..成功 1..失敗  */\r
+sayleen_send_midi_reset( void ) {\r
+\r
+       unsigned char *p;\r
+       int port;\r
+\r
+       if ( reset_mode >= sizeof(reset_exclusives) ) {\r
+               return 1;\r
+       }\r
+\r
+       sayleen_flush_midi();\r
+       for ( port=0 ; port<1 ; port++ ) {\r
+\r
+               /* reset all notes */\r
+               p = (unsigned char *)all_reset;\r
+               while ( *p != 0xff ) {\r
+               sayleen_put_midi( (int)*p++ );\r
+               }\r
+               sayleen_flush_midi();\r
+               sayleen_myusleep(60000);\r
+\r
+               /* send reset message */\r
+               p = (unsigned char *)reset_exclusives[reset_mode];\r
+               while ( *p != 0xff ) {\r
+                       sayleen_put_midi( (int)*p++ );\r
+               }\r
+               sayleen_flush_midi();\r
+               sayleen_myusleep(60000);\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+/* ------------------------------------------------------------------- */\r
+\r
+/** start リアルタイムメッセージを送る */\r
+int \r
+sayleen_send_rtm_start( void ) {\r
+       sayleen_put_midi( 0xfa );\r
+       return 0;\r
+}\r
+\r
+/** stop リアルタイムメッセージを送る */\r
+int \r
+sayleen_send_rtm_stop( void ) {\r
+       sayleen_put_midi( 0xfc );\r
+       return 0;\r
+}\r
+\r
+/** continue リアルタイムメッセージを送る */\r
+int\r
+sayleen_send_rtm_continue( void ) {\r
+       sayleen_put_midi( 0xfb );\r
+       return 0;\r
+}\r
+\r
+/** タイミングクロック リアルタイムメッセージを送る */\r
+int \r
+sayleen_send_rtm_timingclock( void ) {\r
+       sayleen_put_midi( 0xf8 );\r
+       return 0;\r
+}\r
+\r
+/** 指定した時間スリープする */\r
+void\r
+sayleen_myusleep( long usec /**< マイクロ秒単位のスリープ時間 */ ) {\r
+       sted_sleep(usec);\r
+}\r
+\r
diff --git a/mididev.h b/mididev.h
new file mode 100644 (file)
index 0000000..52a2918
--- /dev/null
+++ b/mididev.h
@@ -0,0 +1,42 @@
+/** 
+  @file
+
+  Copyright 2000 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Dec.23.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef _MIDIDEV_H_
+#define _MIDIDEV_H_
+
+ int sayleen_change_midi_port ( int );
+ int sayleen_put_midi( int );
+ int sayleen_flush_midi ( void );
+ int sayleen_send_midi_reset( void );
+ int sayleen_send_rtm_start( void );
+ int sayleen_send_rtm_stop( void );
+ int sayleen_send_rtm_continue( void );
+ int sayleen_send_rtm_timingclock( void );
+ void sayleen_myusleep( long );
+
+#endif /* _MIDIDEV_H_ */
diff --git a/mkeyb.cpp b/mkeyb.cpp
new file mode 100644 (file)
index 0000000..c449c1e
--- /dev/null
+++ b/mkeyb.cpp
@@ -0,0 +1,146 @@
+/* X68000 music keyboard v0.2 1989/04/17 by TURBO */\r
+\r
+/*\r
+ * STed: music keyboard (1994/07/20)\r
+ */\r
+#include "stdafx.h"\r
+\r
+#include       "sted.h"\r
+\r
+\r
+unsigned char  bitkey[7][10]={\r
+  "  123456","7890-^\\ "," QWERTYU","IOP@[ AS","DFGHJKL;",":]ZXCVBN","M,./_   "};\r
+\r
+unsigned char  keytable[44]="AZSXCFVGBNJMK,L./:_]" "1Q2WE4R5TY7U8I9OP-@^[\\";\r
+\r
+/*C4=60*/\r
+unsigned char  keycode[44]={\r
+  0 ,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,\r
+  56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77\r
+};\r
+/*\r
+・・・・・・・\r
+・・・・・・・\r
+\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+  c1     c2     c3     c4     c5     c6     c7     c8\r
+*/\r
+\r
+/***************************/\r
+void   m_keyb(int ch,int bank,int prg,int velo)\r
+{\r
+  int  bnk_m,bnk_l,pm,ch2;\r
+  int  a,i;\r
+\r
+  unsigned char        onkey[32],onnote[32];\r
+  unsigned char        s[16],ke[128];\r
+  char obuf[64];\r
+\r
+  msg("Music KeyBoard Emulater");\r
+\r
+  if(rcd->act==0){all_note_off(0);}\r
+  bnk_l=bank>>8;bnk_m=bank&0xff;ch=(ch-1)&31;ch2=ch&15;\r
+  pm=rcd->put_mode;rcd->put_mode=rcd->ch_port[ch];\r
+  twait(5);\r
+\r
+  if(bank>=0 && tim_asin[ch+1]>=7 && tim_asin[ch+1]<=14){\r
+    obuf[0]=0xb0+ch2;obuf[1]=0;obuf[2]=bnk_m;obuf[3]=0xff;\r
+    (*rcd->mix_out)(obuf);\r
+    obuf[0]=0xb0+ch2;obuf[1]=32;obuf[2]=bnk_l;obuf[3]=255;\r
+    (*rcd->mix_out)(obuf);\r
+    /* separate each events Jan.19.1998 Daisuke Nagano*/\r
+  }\r
+\r
+  if(prg>=0){\r
+    obuf[0]=0xc0+ch2;obuf[1]=prg;obuf[2]=255;\r
+    (*rcd->mix_out)(obuf);\r
+  }\r
+  twait(8);\r
+\r
+  strcpy((char *)onkey,"                ");\r
+\r
+  while (1){\r
+    int        ln,sh;\r
+    if(INPOUT(0xff)==27){break;}\r
+    sh=B_SFTSNS();\r
+\r
+    ln=0;\r
+    for(i=0;i<=6;i++){\r
+      a=BITSNS(i);\r
+      if( a & 1   ){ke[ln++]=bitkey[i][0];}\r
+      if( a & 2   ){ke[ln++]=bitkey[i][1];}\r
+      if( a & 4   ){ke[ln++]=bitkey[i][2];}\r
+      if( a & 8   ){ke[ln++]=bitkey[i][3];}\r
+      if( a & 16  ){ke[ln++]=bitkey[i][4];}\r
+      if( a & 32  ){ke[ln++]=bitkey[i][5];}\r
+      if( a & 64  ){ke[ln++]=bitkey[i][6];}\r
+      if( a & 128 ){ke[ln++]=bitkey[i][7];}\r
+    }\r
+    ke[ln]=0;\r
+\r
+    for (i=0;i<16;i++){\r
+      if ( onkey[i]>32 ) {\r
+       int a;\r
+       s[0]=onkey[i];s[1]=0;\r
+       a=str_search((char *)ke,(char *)s);\r
+       if( a==0 ){\r
+         int note;\r
+         onkey[i]=32;note=onnote[i];\r
+\r
+         /* note off */\r
+\r
+         obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=0;\r
+         obuf[3]=255;(*rcd->mix_out)(obuf);\r
+       }\r
+      }\r
+    }\r
+    ln=0;\r
+    for (i=0;i<16;i++){\r
+      if(ke[ln]==0){break;}\r
+      if(onkey[i]==32){\r
+       s[0]=ke[ln++];s[1]=0;\r
+       if(str_search((char *)onkey,(char *)s)==0){\r
+         int a;\r
+         a=str_search((char *)keytable,(char *)s);\r
+         if(a!=0){\r
+           int note;\r
+           onkey[i]=s[0];note=keycode[a];\r
+           if(sh&1){note+=12;}/*shift*/\r
+           if(sh&2){note-=12;}/*ctrl*/\r
+           if(sh&128){note+=12;}/*caps*/\r
+           if(sh&256){note-=12;}/*かな*/\r
+           onnote[i]=note;\r
+\r
+           /* note on */\r
+\r
+           obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=velo;\r
+           obuf[3]=255;(*rcd->mix_out)(obuf);\r
+\r
+         }\r
+       }\r
+      }\r
+    }\r
+  }\r
+\r
+  /*\r
+    97-10-24   key.emu.で発音したままになるかもしれないのを修正した\r
+\r
+    for (i=0;i<16;i++){\r
+    if ( onkey[i]>32 ) {\r
+    int note;\r
+\r
+    note=onnote[i];\r
+\r
+    *//* note off *//*\r
+\r
+        obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=0;\r
+        obuf[3]=255;(*rcd->mix_out)(obuf);\r
+        }\r
+        }\r
+        */\r
+\r
+  snsclr();rcd->put_mode=pm;msg_clr();\r
+}\r
diff --git a/netbsdgetopt.h b/netbsdgetopt.h
new file mode 100644 (file)
index 0000000..14b1206
--- /dev/null
@@ -0,0 +1,74 @@
+/*  $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $    */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *        This product includes software developed by the NetBSD
+ *        Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#pragma once
+
+#ifndef _GETOPT_H_
+#define _GETOPT_H_
+
+#include <sys/cdefs.h>
+#include <unistd.h>
+
+/*
+ * Gnu like getopt_long() and BSD4.4 getsubopt()/optreset extensions
+ */
+#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
+#define no_argument        0
+#define required_argument  1
+#define optional_argument  2
+
+struct option {
+       /* name of long option */
+       const char *name;
+       /*
+        * one of no_argument, required_argument, and optional_argument:
+        * whether option takes an argument
+        */
+       int has_arg;
+       /* if not NULL, set *flag to val when option found */
+       int *flag;
+       /* if flag not NULL, value to set *flag to; else return value */
+       int val;
+};
+
+__BEGIN_DECLS
+int getopt_long __P((int, char * const *, const char *,
+    const struct option *, int *));
+__END_DECLS
+#endif
+#endif /* !_GETOPT_H_ */
diff --git a/nkflib.cpp b/nkflib.cpp
new file mode 100644 (file)
index 0000000..d2c5dec
--- /dev/null
@@ -0,0 +1,2365 @@
+#include "stdafx.h"\r
+\r
+#ifdef HAVE_CONFIG_H\r
+#include "config.h"\r
+#endif /* HAVE_CONFIG_H */\r
+\r
+/** Network Kanji Filter. (PDS Version)\r
+************************************************************************\r
+** Copyright (C) 1987, Fujitsu LTD. (Itaru ICHIKAWA)\r
+** 連絡先: (株)富士通研究所 ソフト3研 市川 至 \r
+** (E-Mail Address: ichikawa@flab.fujitsu.co.jp)\r
+** Copyright (C) 1996,1998\r
+** 連絡先: 琉球大学情報工学科 河野 真治  mine/X0208 support\r
+** (E-Mail Address: kono@ie.u-ryukyu.ac.jp)\r
+** 連絡先: COW for DOS & Win16 & Win32 & OS/2\r
+** (E-Mail Address: GHG00637@niftyserve.or.p)\r
+**    このソースのいかなる複写,改変,修正も許諾します。ただし、\r
+**    その際には、誰が貢献したを示すこの部分を残すこと。\r
+**    再配布や雑誌の付録などの問い合わせも必要ありません。\r
+**    このプログラムについては特に何の保証もしない、悪しからず。\r
+**    Everyone is permitted to do anything on this program \r
+**    including copying, modifying, improving.\r
+**    as long as you don't try to pretend that you wrote it.\r
+**    i.e., the above copyright notice has to appear in all copies.\r
+**    You don't have to ask before copying or publishing.\r
+**    THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE.\r
+***********************************************************************/\r
+\r
+/* 以下のソースは、nkf を文字列操作できるよう改造したライブラリである。\r
+\r
+   nkf_conv(元文字列,出力文字列、out モード)\r
+     出力文字列を NULL としたときは、元文字列を操作する。\r
+     バグ : 変換され出力される文字列のための領域はある程度とっておくこと。\r
+           さもないと、バグを生じる。\r
+   nkf_convert(元文字列、出力文字列、出力文字列の最大の大きさ、\r
+               in モード、out モード)\r
+     kanji_conv に準じる。出力文字列の最大の大きさが指定できる。\r
+     その大きさ以上になったときはそれ以上の文字の出力は打ち切られる。\r
+   モード\r
+     nkf の convert に与えるオプションを与える文字列。空白で区切って指定する。\r
+     各オプション:\r
+\r
+   このプログラムに関しての著作権がらみのことは nkf に準じるものとする。\r
+   無保証であるので、使用の場合は自らの責任をもってすること。\r
+   改変者 青木大輔      1997.02\r
+*/\r
+\r
+/* 無駄なところを削除した.\r
+   他で用いられないインターフェースは static にした.\r
+   コンパイラの Warning メッセージを抑制するように ANSI C の形式にした.\r
+   文字を unsigned char * で SFILE に蓄えるようにした.\r
+   SFILE を簡単化.\r
+   input_f == FALSE で convert すると,半角カタカナ SJIS が EUC\r
+         と判断されてしまうバグ(仕様だった?)を直した.\r
+        しかしながら,SJIS の半角カタカナ 2 文字と EUC は区別できない\r
+        場合がある.このときは SJIS として変換することにした.\r
+   EUC_STRICT_CHECK を定義すると EUC-Japan の定義コードを完全にチェックする\r
+   ようにした.\r
+   読み込み文字を指定できるようにした.\r
+   改変者 出雲正尚 1997\r
+*/\r
+\r
+/*\r
+  1.7ベースに変更。\r
+  改変者 青木大輔 2000.10\r
+*/\r
+\r
+/*\r
+  STed2 で必要ない部分を削除。\r
+  改変者 八田真行 2000.10\r
+*/\r
+\r
+/* もし,EUC-Japan の完全なチェックをする場合は EUC_STRICT_CHECK を定義\r
+ * してください.ただし,1 バイトでも EUC-Japan の未定義文字が含まれていると\r
+ * EUC とみなされなくなってしまいます.他のプログラムで漢字コードを EUC に変換\r
+ * した場合,EUC の未定義域へマップされる可能性があります.\r
+ */\r
+/* #define EUC_STRICT_CHECK */\r
+\r
+#if 0\r
+static char *CopyRight =\r
+      "Copyright (C) 1987, FUJITSU LTD. (I.Ichikawa),1998 S. Kono, COW";\r
+static char *Version =\r
+      "1.7";\r
+static char *Patchlevel =\r
+      "0/9711/Shinji Kono";\r
+#endif\r
+\r
+/*\r
+**\r
+**\r
+**\r
+** USAGE:       nkf [flags] [file] \r
+**\r
+** Flags:\r
+** b    Output is bufferred             (DEFAULT)\r
+** u    Output is unbufferred\r
+**\r
+** t    no operation\r
+**\r
+** j    Outout code is JIS 7 bit        (DEFAULT SELECT) \r
+** s    Output code is MS Kanji         (DEFAULT SELECT) \r
+** e    Output code is AT&T JIS         (DEFAULT SELECT) \r
+** l    Output code is JIS 7bit and ISO8859-1 Latin-1\r
+**\r
+** m    MIME conversion for ISO-2022-JP\r
+** i_ Output sequence to designate JIS-kanji (DEFAULT_J)\r
+** o_ Output sequence to designate single-byte roman characters (DEFAULT_R)\r
+**\r
+** r  {de/en}crypt ROT13/47\r
+**\r
+** v  display Version\r
+**\r
+** T  Text mode output        (for MS-DOS)\r
+**\r
+** x    Do not convert X0201 kana into X0208\r
+** Z    Convert X0208 alphabet to ASCII\r
+**\r
+** f60  fold option\r
+**\r
+** m    MIME decode\r
+** B    try to fix broken JIS, missing Escape\r
+** B[1-9]  broken level\r
+**\r
+** O   Output to 'nkf.out' file \r
+** d   Delete \r in line feed \r
+** c   Add \r in line feed \r
+**/\r
+/******************************/\r
+/* デフォルトの出力コード選択 */\r
+/* Select DEFAULT_CODE */\r
+#define DEFAULT_CODE_JIS\r
+/* #define DEFAULT_CODE_SJIS */\r
+/* #define DEFAULT_CODE_EUC */\r
+/******************************/\r
+\r
+#if (defined(__TURBOC__) || defined(LSI_C)) && !defined(MSDOS)\r
+#define MSDOS\r
+#endif\r
+\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#ifndef NO_STRING_H\r
+#include <string.h>\r
+#else\r
+#include <strings.h>\r
+#endif\r
+\r
+#ifdef MSDOS\r
+#ifdef LSI_C\r
+#define setbinmode(fp) fsetbin(fp)\r
+#else /* Microsoft C, Turbo C */\r
+#define setbinmode(fp) setmode(fileno(fp), O_BINARY)\r
+#endif\r
+#else /* UNIX,OS/2 */\r
+#define setbinmode(fp)\r
+#endif\r
+\r
+#ifdef _IOFBF /* SysV and MSDOS */\r
+#define       setvbuffer(fp, buf, size)       setvbuf(fp, buf, _IOFBF, size)\r
+#else /* BSD */\r
+#define       setvbuffer(fp, buf, size)       setbuffer(fp, buf, size)\r
+#endif\r
+\r
+#include "nkflib.h"\r
+\r
+#define VOIDVOID 0\r
+\r
+#ifndef FALSE\r
+#define        FALSE   0\r
+#endif /* FALSE */\r
+\r
+#ifndef TRUE\r
+#define        TRUE    1\r
+#endif /* TRUE */\r
+\r
+/* state of output_mode and input_mode  */\r
+\r
+#define         ASCII           0\r
+#define         X0208           1\r
+#define         X0201           2\r
+#define         NO_X0201        3\r
+#define         JIS_INPUT       4\r
+#define         SJIS_INPUT      5\r
+#define         LATIN1_INPUT    6\r
+#define         FIXED_MIME      7\r
+#define         DOUBLE_SPACE    -2\r
+#define         EUC_INPUT       8\r
+\r
+#define         NL      0x0a\r
+#define         ESC     0x1b\r
+#define         SPACE      0x20\r
+#define         AT      0x40\r
+#define         SSP     0xa0\r
+#define         DEL     0x7f\r
+#define         SI      0x0f\r
+#define         SO      0x0e\r
+#define         SSO     0x8e\r
+\r
+#define         HOLD_SIZE       32\r
+#define         IOBUF_SIZE      16384\r
+\r
+#define         DEFAULT_J       'B'\r
+#define         DEFAULT_R       'B'\r
+\r
+#define         SJ0162  0x00e1          /* 01 - 62 ku offset */\r
+#define         SJ6394  0x0161          /* 63 - 94 ku offset */\r
+\r
+\r
+/* SFILE begin */\r
+/* 文字列 を FILE みたいに扱う小細工 */\r
+\r
+/*\r
+   これは nkf の漢字コード変換がファイルに対してのみ対応しているのでそれを\r
+   文字列操作で使えるようにするためのインターフェースである。ただし、\r
+   対応している機能は少ないし、必要なものしか作っていない。したがって、\r
+   これらは nkf の中でしか意味のないものであろう。\r
+\r
+   SFILE は FILE みたいなもので文字列をファイルみたいに扱えるようにする。\r
+   SFILE を使うためには必ずオープンすること。sopen で mode=="new" または\r
+   "auto" 指定していなければクローズする必要はない。SFILE の中を直接操作\r
+   した場合はいろいろ問題が出てくるであろう。\r
+\r
+   SEOF は EOF みたいなもの。\r
+\r
+   sopen は open みたいな関数で、\r
+      sf : SFILE 型の変数\r
+      st : 文字列\r
+      maxsize : 文字列が許容できる最大の大きさ。sputc 時に制限を入れるもの。\r
+               maxsize に -1 を指定するとこの処理を無視するようになる。\r
+               そのときは、必要以上の文字を sputc しないように気をつけなけれ\r
+               ばならない。\r
+      mode : newstr、stdout、stdin の文字列を指定できる。\r
+            例えば mode="new stdout"\r
+            newstr は自動的に文字列のメモリを maxsize だけ獲得する。\r
+            ただし、maxsize < 1 のときはディフォルトの値を獲得する。\r
+            stdout は SFILE の標準出力 stdout となる文字列を指定する。\r
+            stdin は SFILE の標準入力 stdin となる文字列を指定する。\r
+\r
+   sclose は close みたいな関数で、newstr でオープンされていたときは、\r
+   文字列も free で消去する。\r
+\r
+   sgetc、sungetc、sputc、sputchar はそれぞれ getc、ungetc、putc、putchar\r
+   に相当する。引数の sf が NULL の時は SEOF を返す。\r
+*/\r
+\r
+typedef struct __SFILE {\r
+  unsigned char *pointer;      /* 文字列現在のポインタ */\r
+  unsigned char *head;        /* 文字列の最初の位置 */\r
+  unsigned char *tail;        /* 文字列の許容の最後の位置 */\r
+  char mode[20];              /* 文字列オープンモード newstr,stdout,stdin */\r
+                               /* "newstr stdin" の組合わせはない */\r
+} SFILE;\r
+#define SEOF -1\r
+\r
+static SFILE *sstdout=NULL;\r
+static SFILE *sstdin=NULL; /* Never used ? */\r
+#ifndef BUFSIZ\r
+#define BUFSIZ 1024\r
+#endif /* BUFSIZ */\r
+static char sfile_buffer[BUFSIZ];\r
+#ifndef SAFE_CONVERT_LENGTH\r
+#define SAFE_CONVERT_LENGTH(len) (2 * (len) + 7)\r
+#endif /* SAFE_CONVERT_LENGTH */\r
+\r
+/* Functions */\r
+static SFILE *sopen(SFILE *, char *string,signed int maxsize,char *md);\r
+static void sclose(SFILE *sf);\r
+static int sgetc(SFILE *sf);\r
+static int sungetc(int c,SFILE *sf);\r
+static int sputc(int c,SFILE *sf);\r
+#define sputchar(c) sputc(c,sstdout)\r
+\r
+/* nkf 漢字コンバート */\r
+char *nkf_convert(char *si,char *so,int maxsize,char *in_mode,char *out_mode);\r
+char *nkf_conv(char *si,char *so,char *out_mode);\r
+\r
+static int check_kanji_code(unsigned char *p);\r
+\r
+/* MIME preprocessor */\r
+\r
+#undef STRICT_MIME       /* do stupid strict mime integrity check */\r
+#define GETC(p) ((!mime_mode)?sgetc(p):mime_getc(p))\r
+#define UNGETC(c,p)     ((!mime_mode)?sungetc(c,p):mime_ungetc(c))\r
+\r
+\r
+#ifdef EASYWIN /*Easy Win */\r
+ POINT _BufferSize;\r
+#endif\r
+\r
+/*      function prototype  */\r
+\r
+static  int     noconvert(SFILE *f);\r
+static  int     kanji_convert(SFILE *f);\r
+static  int     h_conv(SFILE *f,int c2,int c1);\r
+static  int     push_hold_buf(int c2,int c1);\r
+static  int     s_iconv(int c2,int c1);\r
+static  int     e_oconv(int c2,int c1);\r
+static  int     s_oconv(int c2,int c1);\r
+static  int     j_oconv(int c2,int c1);\r
+static  int     line_fold(int c2,int c1);\r
+static  int     pre_convert(int c1,int c2);\r
+static  int     mime_begin(SFILE *f);\r
+static  int     mime_getc(SFILE *f);\r
+static  int     mime_ungetc(unsigned int c);\r
+static  int     mime_integrity(SFILE *f,unsigned char *p);\r
+static  int     base64decode(int c);\r
+static  int     usage(void);\r
+static  void    arguments(char *c);\r
+static  void    reinit();\r
+\r
+/* buffers */\r
+\r
+static char            stdibuf[IOBUF_SIZE];\r
+static char            stdobuf[IOBUF_SIZE];\r
+static unsigned char   hold_buf[HOLD_SIZE*2];\r
+static int             hold_count;\r
+\r
+/* MIME preprocessor fifo */\r
+\r
+#define MIME_BUF_SIZE   (1024)    /* 2^n ring buffer */\r
+#define MIME_BUF_MASK   (MIME_BUF_SIZE-1)   \r
+#define Fifo(n)         mime_buf[(n)&MIME_BUF_MASK]\r
+static unsigned char           mime_buf[MIME_BUF_SIZE];\r
+static unsigned int            mime_top = 0;\r
+static unsigned int            mime_last = 0;  /* decoded */\r
+static unsigned int            mime_input = 0; /* undecoded */\r
+\r
+/* flags */\r
+static int             unbuf_f = FALSE;\r
+static int             estab_f = FALSE;\r
+static int             nop_f = FALSE;\r
+static int             binmode_f = TRUE;       /* binary mode */\r
+static int             rot_f = FALSE;          /* rot14/43 mode */\r
+static int             input_f = FALSE;        /* non fixed input code  */\r
+static int             alpha_f = FALSE;        /* convert JIx0208 alphbet to ASCII */\r
+static int             mime_f = TRUE;         /* convert MIME B base64 or Q */\r
+static int             mimebuf_f = FALSE;      /* MIME buffered input */\r
+static int             broken_f = FALSE;       /* convert ESC-less broken JIS */\r
+static int             iso8859_f = FALSE;      /* ISO8859 through */\r
+#if defined(MSDOS) || defined(__OS2__) \r
+static int             x0201_f = TRUE;         /* Assume JISX0201 kana */\r
+#else\r
+static int             x0201_f = NO_X0201;     /* Assume NO JISX0201 */\r
+#endif\r
+\r
+/* X0208 -> ASCII converter */\r
+\r
+static int             c1_return;\r
+\r
+/* fold parameter */\r
+static int line = 0;    /* chars in line */\r
+static int prev = 0;\r
+static int             fold_f  = FALSE;\r
+static int             fold_len  = 0;\r
+\r
+/* options */\r
+static char            kanji_intro = DEFAULT_J,\r
+                ascii_intro = DEFAULT_R;\r
+\r
+/* Folding */\r
+\r
+int line_fold();\r
+#define FOLD_MARGIN  10\r
+#define DEFAULT_FOLD 60\r
+\r
+/* converters */\r
+\r
+#ifdef DEFAULT_CODE_JIS\r
+#   define  DEFAULT_CONV j_oconv\r
+#endif\r
+#ifdef DEFAULT_CODE_SJIS\r
+#   define  DEFAULT_CONV s_oconv\r
+#endif\r
+#ifdef DEFAULT_CODE_EUC\r
+#   define  DEFAULT_CONV e_oconv\r
+#endif\r
+\r
+static int             (*iconv)(int c2,int c1);   \r
+                                       /* s_iconv or oconv */\r
+static int             (*oconv)(int c2,int c1) = DEFAULT_CONV; \r
+                                         /* [ejs]_oconv */\r
+\r
+/* Global states */\r
+static int             output_mode = ASCII,    /* output kanji mode */\r
+                input_mode =  ASCII,    /* input kanji mode */\r
+                shift_mode =  FALSE;    /* TRUE shift out, or X0201  */\r
+static int             mime_mode =   FALSE;    /* MIME mode B base64, Q hex */\r
+\r
+/* X0201 / X0208 conversion tables */\r
+\r
+/* X0201 kana conversion table */\r
+/* 90-9F A0-DF */\r
+unsigned char cv[]= {\r
+0x21,0x21,0x21,0x23,0x21,0x56,0x21,0x57,\r
+0x21,0x22,0x21,0x26,0x25,0x72,0x25,0x21,\r
+0x25,0x23,0x25,0x25,0x25,0x27,0x25,0x29,\r
+0x25,0x63,0x25,0x65,0x25,0x67,0x25,0x43,\r
+0x21,0x3c,0x25,0x22,0x25,0x24,0x25,0x26,\r
+0x25,0x28,0x25,0x2a,0x25,0x2b,0x25,0x2d,\r
+0x25,0x2f,0x25,0x31,0x25,0x33,0x25,0x35,\r
+0x25,0x37,0x25,0x39,0x25,0x3b,0x25,0x3d,\r
+0x25,0x3f,0x25,0x41,0x25,0x44,0x25,0x46,\r
+0x25,0x48,0x25,0x4a,0x25,0x4b,0x25,0x4c,\r
+0x25,0x4d,0x25,0x4e,0x25,0x4f,0x25,0x52,\r
+0x25,0x55,0x25,0x58,0x25,0x5b,0x25,0x5e,\r
+0x25,0x5f,0x25,0x60,0x25,0x61,0x25,0x62,\r
+0x25,0x64,0x25,0x66,0x25,0x68,0x25,0x69,\r
+0x25,0x6a,0x25,0x6b,0x25,0x6c,0x25,0x6d,\r
+0x25,0x6f,0x25,0x73,0x21,0x2b,0x21,0x2c,\r
+0x00,0x00};\r
+\r
+\r
+/* X0201 kana conversion table for daguten */\r
+/* 90-9F A0-DF */\r
+unsigned char dv[]= { \r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x25,0x2c,0x25,0x2e,\r
+0x25,0x30,0x25,0x32,0x25,0x34,0x25,0x36,\r
+0x25,0x38,0x25,0x3a,0x25,0x3c,0x25,0x3e,\r
+0x25,0x40,0x25,0x42,0x25,0x45,0x25,0x47,\r
+0x25,0x49,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x25,0x50,0x25,0x53,\r
+0x25,0x56,0x25,0x59,0x25,0x5c,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00};\r
+\r
+/* X0201 kana conversion table for han-daguten */\r
+/* 90-9F A0-DF */\r
+unsigned char ev[]= { \r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x25,0x51,0x25,0x54,\r
+0x25,0x57,0x25,0x5a,0x25,0x5d,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00};\r
+\r
+\r
+/* X0208 kigou conversion table */\r
+/* 0x8140 - 0x819e */\r
+unsigned char fv[] = {\r
+\r
+0x00,0x00,0x00,0x00,0x2c,0x2e,0x00,0x3a,\r
+0x3b,0x3f,0x21,0x00,0x00,0x27,0x60,0x00,\r
+0x5e,0x00,0x5f,0x00,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x2d,0x00,0x2f,\r
+0x5c,0x00,0x00,0x7c,0x00,0x00,0x60,0x27,\r
+0x22,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,\r
+0x7b,0x7d,0x3c,0x3e,0x00,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,\r
+0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\r
+0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40,\r
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00\r
+} ;\r
+\r
+\r
+/* SFILE 関連関数 */\r
+\r
+static SFILE *\r
+sopen(SFILE *sf, char *string, signed int maxsize, char *md)\r
+{\r
+  char *st;\r
+  strcpy(sf->mode,md);\r
+  if (strstr(sf->mode,"newstr"))\r
+  {\r
+      if(maxsize <= sizeof(sfile_buffer))\r
+         st = sfile_buffer;\r
+      else\r
+         st = (char *)malloc(maxsize);\r
+  }\r
+  else\r
+    st=string;\r
+  sf->pointer=sf->head=(unsigned char *)st;\r
+  if (strstr(sf->mode,"stdout"))\r
+    sstdout=sf;\r
+  else if (strstr(sf->mode,"stdin"))\r
+  {\r
+    sstdin=sf;\r
+    maxsize=strlen((char *)st);\r
+  }\r
+  sf->tail=sf->head+maxsize;\r
+  return sf;\r
+}\r
+\r
+static void\r
+sclose(SFILE *sf)\r
+{\r
+  if (sf==NULL)\r
+    return;\r
+  if (strstr(sf->mode,"stdout"))\r
+      sstdout=NULL;\r
+  if (strstr(sf->mode,"stdin"))\r
+      sstdin=NULL;\r
+  if (strstr(sf->mode,"newstr") && sf->head != (unsigned char *)sfile_buffer)\r
+      free(sf->head);\r
+}\r
+\r
+static int\r
+sgetc(SFILE *sf)\r
+{\r
+  if (sf==NULL)\r
+    return SEOF;\r
+  if(sf->pointer<sf->tail)\r
+      return (int)*sf->pointer++;\r
+  return SEOF;\r
+}\r
+\r
+static int\r
+sungetc(int c, SFILE *sf)\r
+{\r
+  if (sf==NULL)\r
+    return SEOF;\r
+  if (sf->head<sf->pointer) {\r
+    *--sf->pointer=(unsigned char)c;\r
+    return c;\r
+  } else\r
+    return SEOF;\r
+}\r
+\r
+static int\r
+sputc(int c, SFILE *sf)\r
+{\r
+  if (sf==NULL)\r
+    return SEOF;\r
+  if (sf->pointer<sf->tail)\r
+      return (int)(*sf->pointer++=(unsigned char)c);\r
+  return SEOF;\r
+}\r
+\r
+/* public 関数 start */\r
+\r
+/* nkf 漢字コンバート関数 */\r
+/* si must be terminated with '\0' */\r
+char *\r
+nkf_convert(char *si, char *so, int maxsize, char *in_mode, char *out_mode)\r
+{\r
+/* 前処理 */\r
+  SFILE *fi,*fo;\r
+  SFILE xfi,xfo;\r
+  int a;\r
+\r
+  reinit(); /* 使用? */\r
+\r
+  if(maxsize == -1)\r
+    maxsize = SAFE_CONVERT_LENGTH(strlen(si));\r
+  else if(maxsize == 0)\r
+    return si;\r
+\r
+  fi = &xfi;\r
+  fo = &xfo;\r
+  if (so!=NULL) {\r
+    sopen(fi,si,0,"stdin");\r
+    sopen(fo,so,maxsize,"stdout");\r
+  } else {\r
+    sopen(fi,si,0,"stdin");\r
+    sopen(fo,so,maxsize,"newstr stdout");\r
+  }\r
+\r
+/* 変数をデフォルト設定 */\r
+  unbuf_f = FALSE;\r
+  estab_f = FALSE;\r
+  rot_f = FALSE;       /* rot14/43 mode */\r
+  input_f = FALSE;     /* non fixed input code  */\r
+  alpha_f = FALSE;     /* convert JIx0208 alphbet to ASCII */\r
+  mime_f = FALSE;      /* convert MIME base64 */\r
+  broken_f = FALSE;    /* convert ESC-less broken JIS */\r
+  iso8859_f = FALSE;   /* ISO8859 through */\r
+#ifdef MSDOS\r
+  x0201_f = TRUE;      /* Assume JISX0201 kana */\r
+#else\r
+  x0201_f = NO_X0201;  /* Assume NO JISX0201 */\r
+#endif\r
+  line = 0;    /* chars in line */\r
+  prev = 0;\r
+  fold_f  = FALSE;\r
+  fold_len  = 0;\r
+  kanji_intro = DEFAULT_J;\r
+  ascii_intro = DEFAULT_R;\r
+  output_mode = ASCII; /* output kanji mode */\r
+  input_mode = ASCII;  /* input kanji mode */\r
+  shift_mode = FALSE;  /* TRUE shift out, or X0201  */\r
+  mime_mode = FALSE;   /* MIME mode B base64, Q hex */\r
+  \r
+#if    0\r
+/* No X0201->X0208 conversion 半角カナを有効に*/\r
+  x0201_f = FALSE;\r
+#else\r
+/* 半角カナを全角にする */\r
+  x0201_f = TRUE;\r
+#endif\r
+\r
+/* オプション mode 解析 */\r
+  oconv=e_oconv;\r
+  if (strstr(out_mode,"EUCK")||strstr(out_mode,"euck")||strstr(out_mode,"ujisk")){\r
+    /*Hankaku Enable (For WRD File )*/\r
+    oconv=e_oconv; \r
+    /* No X0201->X0208 conversion 半角カナを有効に*/\r
+    x0201_f = FALSE;\r
+  }\r
+  else if (strstr(out_mode,"SJISK")||strstr(out_mode,"sjisk")){\r
+    /*Hankaku Enable (For WRD File )*/\r
+    oconv=s_oconv; \r
+    /* No X0201->X0208 conversion 半角カナを有効に*/\r
+    x0201_f = FALSE;\r
+  }\r
+  else if (strstr(out_mode,"JISK")||strstr(out_mode,"jisk")){\r
+    /*Hankaku Enable (For WRD File )*/\r
+    oconv=j_oconv; \r
+    /* No X0201->X0208 conversion 半角カナを有効に*/\r
+    x0201_f = FALSE;\r
+  }\r
+  else if (strstr(out_mode,"EUC")||strstr(out_mode,"euc")||strstr(out_mode,"ujis"))\r
+    oconv=e_oconv;\r
+  else if (strstr(out_mode,"SJIS")||strstr(out_mode,"sjis"))\r
+    oconv=s_oconv;\r
+  else if (strstr(out_mode,"JIS")||strstr(out_mode,"jis"))\r
+    oconv=j_oconv;\r
+  /* 読み込みコードのチェック */\r
+  input_f = -1;\r
+  if(in_mode != NULL)\r
+  {\r
+      if(strstr(in_mode,"EUC")||strstr(in_mode,"euc")||strstr(in_mode,"ujis"))\r
+         input_f = JIS_INPUT;\r
+      else if (strstr(in_mode,"SJIS")||strstr(in_mode,"sjis"))\r
+         input_f = SJIS_INPUT;\r
+      else if (strstr(in_mode,"JIS")||strstr(in_mode,"jis"))\r
+         input_f = JIS_INPUT;\r
+  }\r
+  if(input_f == -1)\r
+  {\r
+      /* Auto detect */\r
+      input_f = check_kanji_code((unsigned char *)si);\r
+      if(input_f == -1)\r
+         input_f = SJIS_INPUT;\r
+      else if(input_f == EUC_INPUT)\r
+         input_f = JIS_INPUT;\r
+      if(input_f == SJIS_INPUT && x0201_f == NO_X0201)\r
+         x0201_f = TRUE;\r
+  }\r
+\r
+  /* コンバート */\r
+  kanji_convert(fi);\r
+\r
+/* 後処理 */\r
+  sputchar('\0');\r
+  if (so==NULL) {\r
+    /* Copy `fo' buffer to `si' */\r
+\r
+    a = fo->pointer - fo->head; /* Stored length */\r
+    if(a > maxsize)\r
+       a = maxsize;\r
+    memcpy(si, fo->head, a); /* Do copy */\r
+    so = si;\r
+  }\r
+  sclose(fi);\r
+  sclose(fo);\r
+  return so;\r
+}\r
+\r
+char *\r
+nkf_conv(char *si, char *so, char *mode)\r
+{\r
+  return nkf_convert(si,so,-1,NULL,mode);\r
+}\r
+\r
+/* public 関数 end */\r
+\r
+#define IS_SJIS_HANKAKU(c)     (0xa0 <= (c) && (c) <= 0xdf)\r
+#define IS_SJIS_BYTE1(c)       ((0x81 <= (c) && (c) <= 0x9f) ||\\r
+                                (0xe0 <= (c) && (c) <= 0xfc))\r
+#define IS_SJIS_BYTE2(c)       ((0x40 <= (c) && (c) <= 0x7e) ||\\r
+                                (0x80 <= (c) && (c) <= 0xfc))\r
+\r
+#define IS_EUC_BYTE1(c)                (0xa1 <= (c) && (c) <= 0xf4)\r
+#ifdef EUC_STRICT_CHECK\r
+#define IS_EUC_BYTE2(c)                (0xa1 <= (c) && (c) <= 0xfe)\r
+#else\r
+#define IS_EUC_BYTE2(c)                (0xa0 <= (c) && (c) <= 0xff)\r
+#endif /* EUC_STRICT_CHECK */\r
+\r
+\r
+#ifdef EUC_STRICT_CHECK\r
+#define EUC_GAP_LIST_SIZE (16*2)\r
+static unsigned int euc_gap_list[EUC_GAP_LIST_SIZE] =\r
+{\r
+    0xa2af, 0xa2b9,\r
+    0xa2c2, 0xa2c9,\r
+    0xa2d1, 0xa2db,\r
+    0xa2eb, 0xa2f1,\r
+    0xa2fa, 0xa2fd,\r
+    0xa3a1, 0xa3af,\r
+    0xa3ba, 0xa3c0,\r
+    0xa3db, 0xa3e0,\r
+    0xa3fb, 0xa3fe,\r
+    0xa4f4, 0xa4fe,\r
+    0xa5f7, 0xa5fe,\r
+    0xa6b9, 0xa6c0,\r
+    0xa6d9, 0xa6fe,\r
+    0xa7c2, 0xa7d0,\r
+    0xa7f2, 0xa7fe,\r
+    0xa8c1, 0xaffe\r
+};\r
+#endif /* EUC_STRICT_CHECK */\r
+\r
+static int check_kanji_code(unsigned char *p)\r
+{\r
+    int c1, c2, mode;\r
+    int noteuc;\r
+\r
+    /* check JIS or ASCII code */\r
+    mode = ASCII;\r
+    while(*p)\r
+    {\r
+       if(*p < SPACE || *p >= DEL)\r
+       {\r
+           if(*p == ESC)\r
+               return JIS_INPUT;\r
+           mode = -1; /* None ASCII */\r
+           break;\r
+       }\r
+       p++;\r
+    }\r
+    if(mode == ASCII)\r
+       return ASCII;\r
+\r
+    /* EUC or SJIS */\r
+    noteuc = 0;\r
+    while(*p)\r
+    {\r
+        /* skip ASCII */\r
+        while(*p && *p <= DEL)\r
+           p++;\r
+\r
+       if(!*p)\r
+           return -1;\r
+       c1 = p[0];\r
+       c2 = p[1];\r
+       if(c2 == 0)\r
+       {\r
+           if(IS_SJIS_HANKAKU(c1))\r
+               return SJIS_INPUT;\r
+           return -1;\r
+       }\r
+\r
+       if(IS_SJIS_HANKAKU(c1))\r
+       {\r
+#ifdef EUC_STRICT_CHECK\r
+           unsigned int c;\r
+#endif /* EUC_STRICT_CHECK */\r
+/*\r
+            0xa0   0xa1              0xdf   0xf4   0xfe\r
+             |<-----+---- SH -------->|      |      |     SH: SJIS-HANKAKU\r
+                    |<------- E1 ----------->|      |     E1: EUC (MSB)\r
+                    |<--------E2------------------->|     E2: EUC (LSB)\r
+*/\r
+           if(!IS_EUC_BYTE1(c1) || !IS_EUC_BYTE2(c2))\r
+               return SJIS_INPUT;\r
+           if(!IS_SJIS_HANKAKU(c2)) /* (0xdf..0xfe] */\r
+               return EUC_INPUT;\r
+#ifdef EUC_STRICT_CHECK\r
+           if(!noteuc)\r
+           {\r
+               int i;\r
+               /* Checking more strictly */\r
+               c = (((unsigned int)c1)<<8 | (unsigned int)c2);\r
+               for(i = 0; i < EUC_GAP_LIST_SIZE; i += 2)\r
+                   if(euc_gap_list[i] <= c && c <= euc_gap_list[i + 1])\r
+                   {\r
+                       noteuc = 1;\r
+                       break;\r
+                   }\r
+           }\r
+#endif /* EUC_STRICT_CHECK */\r
+           p += 2;\r
+       }\r
+       else if(IS_SJIS_BYTE1(c1) && IS_SJIS_BYTE2(c2))\r
+       {\r
+           if(!(IS_EUC_BYTE1(c1) && IS_EUC_BYTE2(c2)))\r
+               return SJIS_INPUT;\r
+           p += 2;\r
+       }\r
+       else if(IS_EUC_BYTE1(c1) && IS_EUC_BYTE2(c2))\r
+       {\r
+           return EUC_INPUT;\r
+       }\r
+       else\r
+           p++; /* What?  Is this japanese?  Try check again. */\r
+    }\r
+    if(noteuc)\r
+       return SJIS_INPUT;\r
+    return -1;\r
+}\r
+\r
+#ifdef EUC_STRICT_CHECK\r
+static void fix_euc_code(unsigned char *s, int len)\r
+{\r
+    int i, j, c;\r
+\r
+    for(i = 0; i < len - 1; i++)\r
+    {\r
+       if(s[i] & 0x80)\r
+       {\r
+           c = (((unsigned int)s[i])<<8 | (unsigned int)s[i + 1]);\r
+           for(j = 0; j < EUC_GAP_LIST_SIZE; j += 2)\r
+               if(euc_gap_list[j] <= c && c <= euc_gap_list[j + 1])\r
+               {\r
+                   s[i] = 0xa1;\r
+                   s[i + 1] = 0xa1;\r
+                   break;\r
+               }\r
+           i++;\r
+       }\r
+    }\r
+}\r
+#endif /* EUC_STRICT_CHECK */\r
+\r
+\r
+static int             file_out = FALSE;\r
+static int             add_cr = FALSE;\r
+static int             del_cr = FALSE;\r
+static int             end_check;\r
+\r
+#if 0\r
+#ifndef PERL_XS\r
+int\r
+main(argc, argv)\r
+    int             argc;\r
+    char          **argv;\r
+{\r
+    FILE  *fin;\r
+    char  *cp;\r
+\r
+#ifdef EASYWIN /*Easy Win */\r
+    _BufferSize.y = 400;/*Set Scroll Buffer Size*/\r
+#endif\r
+\r
+    for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {\r
+        cp = *argv;\r
+       arguments(cp);\r
+    }\r
+\r
+    if(iso8859_f && (oconv != j_oconv || !x0201_f )) {\r
+        fprintf(stderr,"Mixed ISO8859/JISX0201/SJIS/EUC output is not allowed.\n");\r
+        exit(1);\r
+    }\r
+\r
+    if(binmode_f == TRUE)\r
+#ifdef __OS2__\r
+    if(freopen("","wb",stdout) == NULL) \r
+        return (-1);\r
+#else\r
+    setbinmode(stdout);\r
+#endif\r
+\r
+    if(unbuf_f)\r
+      setbuf(stdout, (char *) NULL);\r
+    else\r
+      setvbuffer(stdout, stdobuf, IOBUF_SIZE);\r
+\r
+    if(argc == 0) {\r
+      if(binmode_f == TRUE)\r
+#ifdef __OS2__\r
+      if(freopen("","rb",stdin) == NULL) return (-1);\r
+#else\r
+      setbinmode(stdin);\r
+#endif\r
+      setvbuffer(stdin, stdibuf, IOBUF_SIZE);\r
+      if(nop_f)\r
+          noconvert(stdin);\r
+      else\r
+          kanji_convert(stdin);\r
+    } else {\r
+      while (argc--) {\r
+          if((fin = fopen(*argv++, "r")) == NULL) {\r
+              perror(*--argv);\r
+              return(-1);\r
+          } else {\r
+/* reopen file for stdout */\r
+              if(file_out == TRUE){ \r
+                  if(argc == 1 ) {\r
+                      if(freopen(*argv++, "w", stdout) == NULL) {\r
+                          perror(*--argv);\r
+                          return (-1);\r
+                      }\r
+                      argc--;\r
+                  } else {\r
+                      if(freopen("nkf.out", "w", stdout) == NULL) {\r
+                         perror(*--argv);\r
+                         return (-1);\r
+                      }\r
+                  }\r
+                  if(binmode_f == TRUE) {\r
+#ifdef __OS2__\r
+                      if(freopen("","wb",stdout) == NULL) \r
+                           return (-1);\r
+#else\r
+                      setbinmode(stdout);\r
+#endif\r
+                  }\r
+              }\r
+              if(binmode_f == TRUE)\r
+#ifdef __OS2__\r
+                 if(freopen("","rb",fin) == NULL) \r
+                    return (-1);\r
+#else\r
+                 setbinmode(fin);\r
+#endif \r
+              setvbuffer(fin, stdibuf, IOBUF_SIZE);\r
+              if(nop_f)\r
+                  noconvert(fin);\r
+              else\r
+                  kanji_convert(fin);\r
+              fclose(fin);\r
+          }\r
+      }\r
+    }\r
+#ifdef EASYWIN /*Easy Win */\r
+    if(file_out == FALSE) \r
+        scanf("%d",&end_check);\r
+    else \r
+        fclose(stdout);\r
+#else /* for Other OS */\r
+    if(file_out == TRUE) \r
+        fclose(stdout);\r
+#endif \r
+    return (0);\r
+}\r
+#endif\r
+\r
+void\r
+arguments(char *cp) \r
+{\r
+    while (*cp) {\r
+       switch (*cp++) {\r
+       case 'b':           /* buffered mode */\r
+           unbuf_f = FALSE;\r
+           continue;\r
+       case 'u':           /* non bufferd mode */\r
+           unbuf_f = TRUE;\r
+           continue;\r
+       case 't':           /* transparent mode */\r
+           nop_f = TRUE;\r
+           continue;\r
+       case 'j':           /* JIS output */\r
+       case 'n':\r
+           oconv = j_oconv;\r
+           continue;\r
+       case 'e':           /* AT&T EUC output */\r
+           oconv = e_oconv;\r
+           continue;\r
+       case 's':           /* SJIS output */\r
+           oconv = s_oconv;\r
+           continue;\r
+       case 'l':           /* ISO8859 Latin-1 support, no conversion */\r
+           iso8859_f = TRUE;  /* Only compatible with ISO-2022-JP */\r
+           input_f = LATIN1_INPUT;\r
+           continue;\r
+       case 'i':           /* Kanji IN ESC-$-@/B */\r
+           if(*cp=='@'||*cp=='B') \r
+               kanji_intro = *cp++;\r
+           continue;\r
+       case 'o':           /* ASCII IN ESC-(-J/B */\r
+           if(*cp=='J'||*cp=='B'||*cp=='H') \r
+               ascii_intro = *cp++;\r
+           continue;\r
+       case 'r':\r
+           rot_f = TRUE;\r
+           continue;\r
+#if defined(MSDOS) || defined(__OS2__) \r
+       case 'T':\r
+           binmode_f = FALSE;\r
+           continue;\r
+#endif\r
+#ifndef PERL_XS\r
+       case 'v':\r
+           usage();\r
+           exit(1);\r
+           break;\r
+#endif\r
+       /* Input code assumption */\r
+       case 'J':   /* JIS input */\r
+       case 'E':   /* AT&T EUC input */\r
+           input_f = JIS_INPUT;\r
+           continue;\r
+       case 'S':   /* MS Kanji input */\r
+           input_f = SJIS_INPUT;\r
+           if(x0201_f==NO_X0201) x0201_f=TRUE;\r
+           continue;\r
+       case 'Z':   /* Convert X0208 alphabet to asii */\r
+           /*  bit:0   Convert X0208\r
+               bit:1   Convert Kankaku to one space\r
+               bit:2   Convert Kankaku to two spaces\r
+           */\r
+           if('9'>= *cp && *cp>='0') \r
+               alpha_f |= 1<<(*cp++ -'0');\r
+           else \r
+               alpha_f |= TRUE;\r
+           continue;\r
+       case 'x':   /* Convert X0201 kana to X0208 or X0201 Conversion */\r
+           x0201_f = FALSE;    /* No X0201->X0208 conversion */\r
+           /* accept  X0201\r
+                   ESC-(-I     in JIS, EUC, MS Kanji\r
+                   SI/SO       in JIS, EUC, MS Kanji\r
+                   SSO         in EUC, JIS, not in MS Kanji\r
+                   MS Kanji (0xa0-0xdf) \r
+              output  X0201\r
+                   ESC-(-I     in JIS (0x20-0x5f)\r
+                   SSO         in EUC (0xa0-0xdf)\r
+                   0xa0-0xd    in MS Kanji (0xa0-0xdf) \r
+           */\r
+           continue;\r
+       case 'X':   /* Assume X0201 kana */\r
+           /* Default value is NO_X0201 for EUC/MS-Kanji mix */\r
+           x0201_f = TRUE;\r
+           continue;\r
+       case 'f':   /* folding -f60 or -f */\r
+           fold_f = TRUE;\r
+           fold_len = atoi(cp);\r
+           if(!(0<fold_len && fold_len<BUFSIZ)) \r
+               fold_len = DEFAULT_FOLD;\r
+           while('0'<= *cp && *cp <='9') cp++;\r
+           continue;\r
+       case 'm':   /* MIME support */\r
+           mime_f = TRUE;\r
+           if(*cp=='B'||*cp=='Q') {\r
+               mime_mode = *cp++;\r
+               mimebuf_f = FIXED_MIME;\r
+           } else if (*cp=='0') {\r
+               mime_f = FALSE;\r
+           }\r
+           continue;\r
+       case 'M':   /* MIME output */\r
+           oconv = j_oconv;    /* sorry... not yet done.. */\r
+           continue;\r
+       case 'B':   /* Broken JIS support */\r
+           /*  bit:0   no ESC JIS\r
+               bit:1   allow any x on ESC-(-x or ESC-$-x\r
+               bit:2   reset to ascii on NL\r
+           */\r
+           if('9'>= *cp && *cp>='0') \r
+               broken_f |= 1<<(*cp++ -'0');\r
+           else \r
+               broken_f |= TRUE;\r
+           continue;\r
+#ifndef PERL_XS\r
+       case 'O':/* for Output file */\r
+           file_out = TRUE;\r
+           continue;\r
+#endif\r
+       case 'c':/* add cr code */\r
+           add_cr = TRUE;\r
+           continue;\r
+       case 'd':/* delete cr code */\r
+           del_cr = TRUE;\r
+           continue;\r
+       default:\r
+           /* bogus option but ignored */\r
+           continue;\r
+       }\r
+    }\r
+}\r
+#endif\r
+\r
+int\r
+noconvert(SFILE  *f)\r
+{\r
+    int    c;\r
+\r
+    while ((c = sgetc(f)) != EOF)\r
+      sputchar(c);\r
+    return 1;\r
+}\r
+\r
+\r
+\r
+\r
+int\r
+kanji_convert(SFILE  *f)\r
+{\r
+    int    c1, c2;\r
+\r
+    c2 = 0;\r
+\r
+    if(input_f == JIS_INPUT || input_f == LATIN1_INPUT) {\r
+        estab_f = TRUE; iconv = oconv;\r
+    } else if(input_f == SJIS_INPUT) {\r
+        estab_f = TRUE;  iconv = s_iconv;\r
+    } else {\r
+        estab_f = FALSE; iconv = oconv;\r
+    }\r
+    input_mode = ASCII;\r
+    output_mode = ASCII;\r
+    shift_mode = FALSE;\r
+\r
+#define NEXT continue      /* no output, get next */\r
+#define SEND ;             /* output c1 and c2, get next */\r
+#define LAST break         /* end of loop, go closing  */\r
+\r
+    while ((c1 = GETC(f)) != EOF) {\r
+        if(c2) {\r
+            /* second byte */\r
+            if(c2 > DEL) {\r
+                /* in case of 8th bit is on */\r
+                if(!estab_f) {\r
+                    /* in case of not established yet */\r
+                    if(c1 > SSP) {\r
+                        /* It is still ambiguious */\r
+                        h_conv(f, c2, c1);\r
+                        c2 = 0;\r
+                        NEXT;\r
+                    } else if(c1 < AT) {\r
+                        /* ignore bogus code */\r
+                        c2 = 0;\r
+                        NEXT;\r
+                    } else {\r
+                        /* established */\r
+                        /* it seems to be MS Kanji */\r
+                        estab_f = TRUE;\r
+                        iconv = s_iconv;\r
+                        SEND;\r
+                    }\r
+                } else\r
+                    /* in case of already established */\r
+                    if(c1 < AT) {\r
+                        /* ignore bogus code */\r
+                        c2 = 0;\r
+                        NEXT;\r
+                    } else\r
+                        SEND;\r
+            } else\r
+                /* 7 bit code */\r
+                /* it might be kanji shitfted */\r
+                if((c1 == DEL) || (c1 <= SPACE)) {\r
+                    /* ignore bogus first code */\r
+                    c2 = 0;\r
+                    NEXT;\r
+                } else\r
+                    SEND;\r
+        } else {\r
+            /* first byte */\r
+            if(c1 > DEL) {\r
+                /* 8 bit code */\r
+                if(!estab_f && !iso8859_f) {\r
+                    /* not established yet */\r
+                    if(c1 < SSP) {\r
+                        /* it seems to be MS Kanji */\r
+                        estab_f = TRUE;\r
+                        iconv = s_iconv;\r
+                    } else if(c1 < 0xe0) {\r
+                        /* it seems to be EUC */\r
+                        estab_f = TRUE;\r
+                        iconv = oconv;\r
+                    } else {\r
+                        /* still ambiguious */\r
+                    }\r
+                    c2 = c1;\r
+                    NEXT;\r
+                } else { /* estab_f==TRUE */\r
+                    if(iso8859_f) {\r
+                        SEND;\r
+                    } else if(SSP<=c1 && c1<0xe0 && iconv == s_iconv) {\r
+                        /* SJIS X0201 Case... */\r
+                        /* This is too arrogant, but ... */\r
+                        if(x0201_f==NO_X0201) {\r
+                            iconv = oconv;\r
+                            c2 = c1;\r
+                            NEXT;\r
+                        } else \r
+                        if(x0201_f) {\r
+                            if(dv[(c1-SSP)*2]||ev[(c1-SSP)*2]) {\r
+                            /* look ahead for X0201/X0208conversion */\r
+                                if((c2 = GETC(f)) == EOF) {\r
+                                    (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                                    LAST;\r
+                                } else if(c2==(0xde)) { /* 濁点 */\r
+                                    (*oconv)(dv[(c1-SSP)*2],dv[(c1-SSP)*2+1]);\r
+                                    c2=0; \r
+                                    NEXT;\r
+                                } else if(c2==(0xdf)&&ev[(c1-SSP)*2]) { \r
+                                    /* 半濁点 */\r
+                                    (*oconv)(ev[(c1-SSP)*2],ev[(c1-SSP)*2+1]);\r
+                                    c2=0; \r
+                                    NEXT;\r
+                                } \r
+                                UNGETC(c2,f); c2 = 0;\r
+                            }\r
+                            (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                            NEXT;\r
+                        } else\r
+                            SEND;\r
+                    } else if(c1==SSO && iconv != s_iconv) {\r
+                        /* EUC X0201 Case */\r
+                        /* This is too arrogant\r
+                        if(x0201_f == NO_X0201) {\r
+                            estab_f = FALSE; \r
+                            c2 = 0;  \r
+                            NEXT;\r
+                        } */\r
+                        c1 = GETC(f);  /* skip SSO */\r
+                        euc_1byte_check:\r
+                        if(x0201_f && SSP<=c1 && c1<0xe0) {\r
+                            if(dv[(c1-SSP)*2]||ev[(c1-SSP)*2]) {\r
+                                if((c2 = GETC(f)) == EOF) {\r
+                                    (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                                    LAST;\r
+                                }\r
+                                /* forward lookup 濁点/半濁点 */\r
+                                if(c2 != SSO) {\r
+                                    UNGETC(c2,f); c2 = 0; \r
+                                    (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                                    NEXT;\r
+                                } else if((c2 = GETC(f)) == EOF) {\r
+                                    (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                                    (*oconv)(0,SSO); \r
+                                    LAST;\r
+                                } else if(c2==(0xde)) { /* 濁点 */\r
+                                    (*oconv)(dv[(c1-SSP)*2],dv[(c1-SSP)*2+1]);\r
+                                    c2=0; \r
+                                    NEXT;\r
+                                } else if(c2==(0xdf)&&ev[(c1-SSP)*2]) { \r
+                                    /* 半濁点 */\r
+                                    (*oconv)(ev[(c1-SSP)*2],ev[(c1-SSP)*2+1]);\r
+                                    c2=0; \r
+                                    NEXT;\r
+                                } else {\r
+                                    (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                                    /* we have to check this c2 */\r
+                                    /* and no way to push back SSO */\r
+                                    c1 = c2; c2 = 0;\r
+                                    goto euc_1byte_check;\r
+                                }\r
+                            }\r
+                            (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                            NEXT;\r
+                        } else \r
+                            SEND;\r
+                    } else if(c1 < SSP && iconv != s_iconv) {\r
+                        /* strange code in EUC */\r
+                        iconv = s_iconv;  /* try SJIS */\r
+                        c2 = c1;\r
+                        NEXT;\r
+                    } else {\r
+                       /* already established */\r
+                       c2 = c1;\r
+                       NEXT;\r
+                    }\r
+                }\r
+            } else if((c1 > SPACE) && (c1 != DEL)) {\r
+                /* in case of Roman characters */\r
+                if(shift_mode) { \r
+                    c1 |= 0x80;\r
+                    /* output 1 shifted byte */\r
+                    if(x0201_f && (!iso8859_f||input_mode==X0201) && \r
+                            SSP<=c1 && c1<0xe0 ) {\r
+                        if(dv[(c1-SSP)*2]||ev[(c1-SSP)*2]) {\r
+                            if((c2 = GETC(f)) == EOF) {\r
+                                (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                                LAST;\r
+                            } else if(c2==(0xde&0x7f)) { /* 濁点 */\r
+                                (*oconv)(dv[(c1-SSP)*2],dv[(c1-SSP)*2+1]);\r
+                                c2=0; \r
+                                NEXT;\r
+                            } else if(c2==(0xdf&0x7f)&&ev[(c1-SSP)*2]) {  \r
+                                /* 半濁点 */\r
+                                (*oconv)(ev[(c1-SSP)*2],ev[(c1-SSP)*2+1]);\r
+                                c2=0; \r
+                                NEXT;\r
+                            }\r
+                            UNGETC(c2,f); c2 = 0;\r
+                        }\r
+                        (*oconv)(cv[(c1-SSP)*2],cv[(c1-SSP)*2+1]);\r
+                        NEXT;\r
+                    } else\r
+                        SEND;\r
+                } else if(c1 == '(' && broken_f && input_mode == X0208\r
+                        && !mime_mode ) {\r
+                    /* Try to recover missing escape */\r
+                    if((c1 = GETC(f)) == EOF) {\r
+                        (*oconv)(0, '(');\r
+                        LAST;\r
+                    } else {\r
+                        if(c1 == 'B' || c1 == 'J' || c1 == 'H') {\r
+                            input_mode = ASCII; shift_mode = FALSE;\r
+                            NEXT;\r
+                        } else {\r
+                            (*oconv)(0, '(');\r
+                            /* do not modify various input_mode */\r
+                            /* It can be vt100 sequence */\r
+                            SEND;\r
+                        }\r
+                    }\r
+                } else if(input_mode == X0208) {\r
+                    /* in case of Kanji shifted */\r
+                    c2 = c1;\r
+                    NEXT;\r
+                    /* goto next_byte */\r
+                } else if(c1 == '=' && mime_f && !mime_mode ) {\r
+                    if((c1 = sgetc(f)) == EOF) {\r
+                        (*oconv)(0, '=');\r
+                        LAST;\r
+                    } else if(c1 == '?') {\r
+                        /* =? is mime conversion start sequence */\r
+                        if(mime_begin(f) == EOF) /* check in detail */\r
+                            LAST;\r
+                        else\r
+                            NEXT;\r
+                    } else {\r
+                        (*oconv)(0, '=');\r
+                        sungetc(c1,f);\r
+                        NEXT;\r
+                    }\r
+                } else if(c1 == '$' && broken_f && !mime_mode) {\r
+                    /* try to recover missing escape */\r
+                    if((c1 = GETC(f)) == EOF) {\r
+                        (*oconv)(0, '$');\r
+                        LAST;\r
+                    } else if(c1 == '@'|| c1 == 'B') {\r
+                        /* in case of Kanji in ESC sequence */\r
+                        input_mode = X0208;\r
+                        shift_mode = FALSE;\r
+                        NEXT;\r
+                    } else {\r
+                        /* sorry */\r
+                        (*oconv)(0, '$');\r
+                        (*oconv)(0, c1);\r
+                        NEXT;\r
+                    }\r
+                } else\r
+                    SEND;\r
+            } else if(c1 == SI) {\r
+                shift_mode = FALSE; \r
+                NEXT;\r
+            } else if(c1 == SO) {\r
+                shift_mode = TRUE; \r
+                NEXT;\r
+            } else if(c1 == ESC ) {\r
+                if((c1 = GETC(f)) == EOF) {\r
+                    (*oconv)(0, ESC);\r
+                    LAST;\r
+                } else if(c1 == '$') {\r
+                    if((c1 = GETC(f)) == EOF) {\r
+                        (*oconv)(0, ESC);\r
+                        (*oconv)(0, '$');\r
+                        LAST;\r
+                    } else if(c1 == '@'|| c1 == 'B') {\r
+                        /* This is kanji introduction */\r
+                        input_mode = X0208;\r
+                        shift_mode = FALSE;\r
+                        NEXT;\r
+                    } else if(c1 == '(') {\r
+                       if((c1 = GETC(f)) == EOF) {\r
+                           (*oconv)(0, ESC);\r
+                           (*oconv)(0, '$');\r
+                           (*oconv)(0, '(');\r
+                           LAST;\r
+                       } else if(c1 == '@'|| c1 == 'B') {\r
+                           /* This is kanji introduction */\r
+                           input_mode = X0208;\r
+                           shift_mode = FALSE;\r
+                           NEXT;\r
+                       } else {\r
+                           (*oconv)(0, ESC);\r
+                           (*oconv)(0, '$');\r
+                           (*oconv)(0, '(');\r
+                           (*oconv)(0, c1);\r
+                           NEXT;\r
+                       }\r
+                    } else if(broken_f&0x2) {\r
+                        input_mode = X0208;\r
+                        shift_mode = FALSE;\r
+                        NEXT;\r
+                    } else {\r
+                        (*oconv)(0, ESC);\r
+                        (*oconv)(0, '$');\r
+                        (*oconv)(0, c1);\r
+                        NEXT;\r
+                    }\r
+                } else if(c1 == '(') {\r
+                    if((c1 = GETC(f)) == EOF) {\r
+                        (*oconv)(0, ESC);\r
+                        (*oconv)(0, '(');\r
+                        LAST;\r
+                    } else {\r
+                        if(c1 == 'I') {\r
+                            /* This is X0201 kana introduction */\r
+                            input_mode = X0201; shift_mode = X0201;\r
+                            NEXT;\r
+                        } else if(c1 == 'B' || c1 == 'J' || c1 == 'H') {\r
+                            /* This is X0208 kanji introduction */\r
+                            input_mode = ASCII; shift_mode = FALSE;\r
+                            NEXT;\r
+                        } else if(broken_f&0x2) {\r
+                            input_mode = ASCII; shift_mode = FALSE;\r
+                            NEXT;\r
+                        } else {\r
+                            (*oconv)(0, ESC);\r
+                            (*oconv)(0, '(');\r
+                            /* maintain various input_mode here */\r
+                            SEND;\r
+                        }\r
+                    }\r
+                } else {\r
+                    /* lonely ESC  */\r
+                    (*oconv)(0, ESC);\r
+                    SEND;\r
+                }\r
+            } else if(c1 == NL && broken_f&4) {\r
+                input_mode = ASCII; \r
+                SEND;\r
+            } else\r
+                SEND;\r
+        }\r
+        /* send: */\r
+        if(input_mode == X0208) \r
+            (*oconv)(c2, c1);  /* this is JIS, not SJIS/EUC case */\r
+        else\r
+            (*iconv)(c2, c1);  /* can be EUC/SJIS */\r
+        c2 = 0;\r
+        continue;\r
+        /* goto next_word */\r
+    }\r
+\r
+    /* epilogue */\r
+    (*iconv)(EOF, 0);\r
+    return 1;\r
+}\r
+\r
+\r
+\r
+\r
+int\r
+h_conv(SFILE  *f, int c2, int c1)\r
+{\r
+    int    wc;\r
+\r
+\r
+    /** it must NOT be in the kanji shifte sequence      */\r
+    /** it must NOT be written in JIS7                   */\r
+    /** and it must be after 2 byte 8bit code            */\r
+\r
+    hold_count = 0;\r
+    push_hold_buf(c2, c1);\r
+    c2 = 0;\r
+\r
+    while ((c1 = GETC(f)) != EOF) {\r
+        if(c2) {\r
+            /* second byte */\r
+            if(!estab_f) {\r
+                /* not established */\r
+                if(c1 > SSP) {\r
+                    /* it is still ambiguious yet */\r
+                    SEND;\r
+                } else if(c1 < AT) {\r
+                    /* ignore bogus first byte */\r
+                    c2 = 0;\r
+                    SEND;\r
+                } else {\r
+                    /* now established */\r
+                    /* it seems to be MS Kanji */\r
+                    estab_f = TRUE;\r
+                    iconv = s_iconv;\r
+                    SEND;\r
+                }\r
+            } else\r
+                SEND;\r
+        } else {\r
+            /* First byte */\r
+            if(c1 > DEL) {\r
+                /* 8th bit is on */\r
+                if(c1 < SSP) {\r
+                    /* it seems to be MS Kanji */\r
+                    estab_f = TRUE;\r
+                    iconv = s_iconv;\r
+                } else if(c1 < 0xe0) {\r
+                    /* it seems to be EUC */\r
+                    estab_f = TRUE;\r
+                    iconv = oconv;\r
+                } else {\r
+                    /* still ambiguious */\r
+                }\r
+                c2 = c1;\r
+                NEXT;\r
+            } else\r
+            /* 7 bit code , then send without any process */\r
+                SEND;\r
+        }\r
+        /* send: */\r
+        if((push_hold_buf(c2, c1) == EOF) || estab_f)\r
+            break;\r
+        c2 = 0;\r
+        continue;\r
+    }\r
+\r
+    /** now,\r
+     ** 1) EOF is detected, or\r
+     ** 2) Code is established, or\r
+     ** 3) Buffer is FULL (but last word is pushed)\r
+     **\r
+     ** in 1) and 3) cases, we continue to use\r
+     ** Kanji codes by oconv and leave estab_f unchanged.\r
+     **/\r
+\r
+    for (wc = 0; wc < hold_count; wc += 2) {\r
+        c2 = hold_buf[wc];\r
+        c1 = hold_buf[wc+1];\r
+        (*iconv)(c2, c1);\r
+    }\r
+    return VOIDVOID;\r
+}\r
+\r
+\r
+\r
+int\r
+push_hold_buf(int c2, int c1)\r
+{\r
+    if(hold_count >= HOLD_SIZE*2)\r
+        return (EOF);\r
+    hold_buf[hold_count++] = c2;\r
+    hold_buf[hold_count++] = c1;\r
+    return ((hold_count >= HOLD_SIZE*2) ? EOF : hold_count);\r
+}\r
+\r
+\r
+int\r
+s_iconv(int c2, int c1)\r
+{\r
+    if((c2 == EOF) || (c2 == 0)) {\r
+        /* NOP */\r
+    } else {\r
+        c2 = c2 + c2 - ((c2 <= 0x9f) ? SJ0162 : SJ6394);\r
+        if(c1 < 0x9f)\r
+            c1 = c1 - ((c1 > DEL) ? SPACE : 0x1f);\r
+        else {\r
+            c1 = c1 - 0x7e;\r
+            c2++;\r
+        }\r
+    }\r
+    (*oconv)(c2, c1);\r
+    return 1;\r
+}\r
+\r
+\r
+int e_oconv(int c2, int c1)\r
+{\r
+    c2 = pre_convert(c1,c2); c1 = c1_return;\r
+    if(fold_f) {\r
+        switch(line_fold(c2,c1)) {\r
+            case '\n': \r
+                if(add_cr == TRUE) {\r
+                    sputchar('\r');\r
+                    c1 = '\n';\r
+                }\r
+                sputchar('\n');\r
+                break;\r
+            case 0:    return VOIDVOID;\r
+            case '\r': \r
+                c1 = '\n'; c2 = 0;\r
+                break;\r
+            case '\t': \r
+            case ' ': \r
+                c1 = ' '; c2 = 0;\r
+                break;\r
+        }\r
+    }\r
+    if(c2==DOUBLE_SPACE) {\r
+        sputchar(' '); sputchar(' ');\r
+        return VOIDVOID;\r
+    }\r
+    if(c2 == EOF)\r
+        return VOIDVOID;\r
+    else if(c2 == 0 && (c1&0x80)) {\r
+        sputchar(SSO); sputchar(c1);\r
+    } else if(c2 == 0) {\r
+        if(c1 == '\n' && add_cr == TRUE) \r
+            sputchar('\r');\r
+        if(c1 != '\r') \r
+            sputchar(c1);\r
+        else if(del_cr == FALSE) \r
+            sputchar(c1);\r
+    } else {\r
+        if((c1<0x20 || 0x7e<c1) ||\r
+           (c2<0x20 || 0x7e<c2)) {\r
+            estab_f = FALSE;\r
+            return VOIDVOID; /* too late to rescue this char */\r
+        }\r
+        sputchar(c2 | 0x080);\r
+        sputchar(c1 | 0x080);\r
+    }\r
+    return VOIDVOID;\r
+}\r
+\r
+\r
+\r
+int\r
+s_oconv(int c2, int c1)\r
+{\r
+    c2 = pre_convert(c1,c2); c1 = c1_return;\r
+    if(fold_f) {\r
+        switch(line_fold(c2,c1)) {\r
+            case '\n': \r
+                if(add_cr == TRUE) {\r
+                   sputchar('\r');\r
+                   c1 = '\n';\r
+                }\r
+                sputchar('\n');\r
+                break;\r
+            case '\r': \r
+                c1 = '\n'; c2 = 0;\r
+                break;\r
+            case 0:    return VOIDVOID;\r
+            case '\t': \r
+            case ' ': \r
+                c1 = ' '; c2 = 0;\r
+                break;\r
+        }\r
+    }\r
+    if(c2==DOUBLE_SPACE) {\r
+        sputchar(' '); sputchar(' ');\r
+        return VOIDVOID;\r
+    }\r
+    if(c2 == EOF)\r
+        return VOIDVOID;\r
+    else if(c2 == 0) {\r
+        if(c1 == '\n' && add_cr == TRUE) \r
+            sputchar('\r');\r
+        if(c1 != '\r') \r
+            sputchar(c1);\r
+        else if(del_cr == FALSE) \r
+            sputchar(c1);\r
+    } else {\r
+        if((c1<0x20 || 0x7e<c1) ||\r
+           (c2<0x20 || 0x7e<c2)) {\r
+            estab_f = FALSE;\r
+            return VOIDVOID; /* too late to rescue this char */\r
+        }\r
+        sputchar((((c2 - 1) >> 1) + ((c2 <= 0x5e) ? 0x71 : 0xb1)));\r
+        sputchar((c1 + ((c2 & 1) ? ((c1 < 0x60) ? 0x1f : 0x20) : 0x7e)));\r
+    }\r
+    return VOIDVOID;\r
+}\r
+\r
+int\r
+j_oconv(int c2, int c1)\r
+{\r
+    c2 = pre_convert(c1,c2); c1 = c1_return;\r
+    if(fold_f) {\r
+        switch(line_fold(c2,c1)) {\r
+            case '\n': \r
+                if(output_mode) {\r
+                    sputchar(ESC);\r
+                    sputchar('(');\r
+                    sputchar(ascii_intro);\r
+                }\r
+                if(add_cr == TRUE) {\r
+                    sputchar('\r');\r
+                    c1 = '\n';\r
+                }\r
+                sputchar('\n');\r
+                output_mode = ASCII;\r
+                break;\r
+            case '\r': \r
+                c1 = '\n'; c2 = 0;\r
+                break;\r
+            case '\t': \r
+            case ' ': \r
+                c1 = ' '; c2 = 0;\r
+                break;\r
+            case 0:    return VOIDVOID;\r
+        }\r
+     }\r
+    if(c2 == EOF) {\r
+        if(output_mode) {\r
+            sputchar(ESC);\r
+            sputchar('(');\r
+            sputchar(ascii_intro);\r
+        }\r
+    } else if(c2 == 0 && (c1 & 0x80)) {\r
+        if(input_mode==X0201 || !iso8859_f) {\r
+            if(output_mode!=X0201) {\r
+                sputchar(ESC);\r
+                sputchar('(');\r
+                sputchar('I');\r
+                output_mode = X0201;\r
+            }\r
+            c1 &= 0x7f;\r
+        } else {\r
+            /* iso8859 introduction, or 8th bit on */\r
+            /* Can we convert in 7bit form using ESC-'-'-A ? \r
+               Is this popular? */\r
+        }\r
+        sputchar(c1);\r
+    } else if(c2 == 0) {\r
+        if(output_mode) {\r
+            sputchar(ESC);\r
+            sputchar('(');\r
+            sputchar(ascii_intro);\r
+            output_mode = ASCII;\r
+        }\r
+        if(c1 == '\n' && add_cr == TRUE) \r
+            sputchar('\r');\r
+        if(c1 != '\r') \r
+            sputchar(c1);\r
+        else if(del_cr == FALSE) \r
+            sputchar(c1);\r
+    } else if(c2 == DOUBLE_SPACE) {\r
+        if(output_mode) {\r
+            sputchar(ESC);\r
+            sputchar('(');\r
+            sputchar(ascii_intro);\r
+            output_mode = ASCII;\r
+        }\r
+        sputchar(' ');\r
+        if(c1 == '\n' && add_cr == TRUE) \r
+            sputchar('\r');\r
+        if(c1 != '\r') \r
+            sputchar(c1);\r
+        else if(del_cr == FALSE) \r
+            sputchar(c1);\r
+    } else {\r
+        if(output_mode != X0208) {\r
+            sputchar(ESC);\r
+            sputchar('$');\r
+            sputchar(kanji_intro);\r
+            output_mode = X0208;\r
+        }\r
+        if(c1<0x20 || 0x7e<c1) \r
+            return VOIDVOID;\r
+        if(c2<0x20 || 0x7e<c2) \r
+            return VOIDVOID;\r
+        sputchar(c2);\r
+        if(c1 == '\n' && add_cr == TRUE) \r
+            sputchar('\r');\r
+        if(c1 != '\r') \r
+            sputchar(c1);\r
+        else if(del_cr == FALSE) \r
+            sputchar(c1);\r
+    }\r
+    return VOIDVOID;\r
+}\r
+\r
+\r
+\r
+#define rot13(c)  ( \\r
+      ( c < 'A' ) ? c: \\r
+      (c <= 'M')  ? (c + 13): \\r
+      (c <= 'Z')  ? (c - 13): \\r
+      (c < 'a')   ? (c): \\r
+      (c <= 'm')  ? (c + 13): \\r
+      (c <= 'z')  ? (c - 13): \\r
+      (c) \\r
+)\r
+\r
+#define  rot47(c) ( \\r
+      ( c < '!' ) ? c: \\r
+      ( c <= 'O' ) ? (c + 47) : \\r
+      ( c <= '~' ) ?  (c - 47) : \\r
+      c \\r
+)\r
+\r
+\r
+/* \r
+  Return value of line_fold()\r
+\r
+       \n  add newline  and output char\r
+       \r  add newline  and output nothing\r
+       ' ' space\r
+       0   skip  \r
+       1   (or else) normal output \r
+\r
+  fold state in prev (previous character)\r
+\r
+      >0x80 Japanese (X0208/X0201)\r
+      <0x80 ASCII\r
+      \n    new line \r
+      ' '   space\r
+\r
+  This fold algorthm does not preserve heading space in a line.\r
+  This is the main difference from fmt.\r
+*/\r
+\r
+int\r
+line_fold(int c2, int c1) \r
+{ \r
+    int prev0;\r
+    if(c1=='\r') \r
+        return 0;               /* ignore cr */\r
+    if(c1== 8) {\r
+        if(line>0) line--;\r
+        return 1;\r
+    }\r
+    if(c2==EOF && line != 0)    /* close open last line */\r
+        return '\n';\r
+    /* new line */\r
+    if(c1=='\n') {\r
+        if(prev == c1) {        /* duplicate newline */\r
+            if(line) {\r
+                line = 0;\r
+                return '\n';    /* output two newline */\r
+            } else {\r
+                line = 0;\r
+                return 1;\r
+            }\r
+        } else  {\r
+            if(prev&0x80) {     /* Japanese? */\r
+                prev = c1;\r
+                return 0;       /* ignore given single newline */\r
+            } else if(prev==' ') {\r
+                return 0;\r
+            } else {\r
+                prev = c1;\r
+                if(++line<=fold_len) \r
+                    return ' ';\r
+                else {\r
+                    line = 0;\r
+                    return '\r';        /* fold and output nothing */\r
+                }\r
+            }\r
+        }\r
+    }\r
+    if(c1=='\f') {\r
+        prev = '\n';\r
+        if(line==0)\r
+            return 1;\r
+        line = 0;\r
+        return '\n';            /* output newline and clear */\r
+    }\r
+    /* X0208 kankaku or ascii space */\r
+    if( (c2==0&&c1==' ')||\r
+        (c2==0&&c1=='\t')||\r
+        (c2==DOUBLE_SPACE)||\r
+        (c2=='!'&& c1=='!')) {\r
+        if(prev == ' ') {\r
+            return 0;           /* remove duplicate spaces */\r
+        } \r
+        prev = ' ';    \r
+        if(++line<=fold_len) \r
+            return ' ';         /* output ASCII space only */\r
+        else {\r
+            prev = ' '; line = 0;\r
+            return '\r';        /* fold and output nothing */\r
+        }\r
+    } \r
+    prev0 = prev; /* we still need this one... , but almost done */\r
+    prev = c1;\r
+    if(c2 || (SSP<=c1 && c1<=0xdf)) \r
+        prev |= 0x80;  /* this is Japanese */\r
+    line += (c2==0)?1:2;\r
+    if(line<=fold_len) {   /* normal case */\r
+        return 1;\r
+    }\r
+    if(line>=fold_len+FOLD_MARGIN) { /* too many kinsou suspension */\r
+        line = (c2==0)?1:2;\r
+        return '\n';       /* We can't wait, do fold now */\r
+    }\r
+    /* simple kinsoku rules  return 1 means no folding  */\r
+    if(c2==0) {\r
+        if(c1==0xde) return 1; /* ゛*/\r
+        if(c1==0xdf) return 1; /* ゜*/\r
+        if(c1==0xa4) return 1; /* 。*/\r
+        if(c1==0xa3) return 1; /* ,*/\r
+        if(c1==0xa1) return 1; /* 」*/\r
+        if(c1==0xb0) return 1; /* - */\r
+        if(SSP<=c1 && c1<=0xdf) {               /* X0201 */\r
+            line = 1;\r
+            return '\n';/* add one new line before this character */\r
+        }\r
+        /* fold point in ASCII { [ ( */\r
+        if(( c1!=')'&&\r
+             c1!=']'&&\r
+             c1!='}'&&\r
+             c1!='.'&&\r
+             c1!=','&&\r
+             c1!='!'&&\r
+             c1!='?'&&\r
+             c1!='/'&&\r
+             c1!=':'&&\r
+             c1!=';')&&\r
+            ((prev0=='\n')|| (prev0==' ')||     /* ignored new line */\r
+            (prev0&0x80))                       /* X0208 - ASCII */\r
+            ) {\r
+            line = 1;\r
+            return '\n';/* add one new line before this character */\r
+        }\r
+        return 1;  /* default no fold in ASCII */\r
+    } else {\r
+        if(c2=='!') {\r
+            if(c1=='"')  return 1; /* 、 */\r
+            if(c1=='#')  return 1; /* 。 */\r
+            if(c1=='$')  return 1; /* , */\r
+            if(c1=='%')  return 1; /* . */\r
+            if(c1=='\'') return 1; /* + */\r
+            if(c1=='(')  return 1; /* ; */\r
+            if(c1==')')  return 1; /* ? */\r
+            if(c1=='*')  return 1; /* ! */\r
+            if(c1=='+')  return 1; /* ゛ */\r
+            if(c1==',')  return 1; /* ゜ */\r
+        }\r
+        line = 2;\r
+        return '\n'; /* add one new line before this character */\r
+    }\r
+}\r
+\r
+int\r
+pre_convert(int c1, int c2)\r
+{\r
+        if(c2) c1 &= 0x7f;\r
+        c1_return = c1;\r
+        if(c2==EOF) return c2;\r
+        c2 &= 0x7f;\r
+        if(rot_f) {\r
+            if(c2) {\r
+                c1 = rot47(c1);\r
+                c2 = rot47(c2);\r
+            } else {\r
+                if(!(c1 & 0x80)) \r
+                    c1 = rot13(c1);\r
+            }\r
+            c1_return = c1;\r
+        }\r
+        /* JISX0208 Alphabet */\r
+        if(alpha_f && c2 == 0x23 ) return 0; \r
+        /* JISX0208 Kigou */\r
+        if(alpha_f && c2 == 0x21 ) { \r
+           if(0x21==c1) {\r
+               if(alpha_f&0x2) {\r
+                   c1_return = ' ';\r
+                   return 0;\r
+               } else if(alpha_f&0x4) {\r
+                   c1_return = ' ';\r
+                   return DOUBLE_SPACE;\r
+               } else {\r
+                   return c2;\r
+               }\r
+           } else if(0x20<c1 && c1<0x7f && fv[c1-0x20]) {\r
+               c1_return = fv[c1-0x20];\r
+               return 0;\r
+           } \r
+        }\r
+        return c2;\r
+}\r
+\r
+\r
+#ifdef STRICT_MIME\r
+/* This converts  =?ISO-2022-JP?B?HOGE HOGE?= */\r
+\r
+unsigned char *mime_pattern[] = {\r
+   (unsigned char *)"\075?ISO-8859-1?Q?",\r
+   (unsigned char *)"\075?ISO-2022-JP?B?",\r
+   (unsigned char *)"\075?ISO-2022-JP?Q?",\r
+   (unsigned char *)"\075?JAPANESE_EUC?B?",\r
+   (unsigned char *)"\075?SHIFT_JIS?B?",\r
+   NULL\r
+};\r
+\r
+int      mime_encode[] = {\r
+    'Q', 'B', 'Q',\r
+    0\r
+};\r
+#endif\r
+\r
+#define MAXRECOVER 20\r
+int iso8859_f_save;\r
+\r
+#ifdef STRICT_MIME\r
+\r
+#define nkf_toupper(c)  (('a'<=c && c<='z')?(c-('a'-'A')):c)\r
+/* I don't trust portablity of toupper */\r
+\r
+int\r
+mime_begin(SFILE *f)\r
+{\r
+    int c1;\r
+    int i,j,k;\r
+    unsigned char *p,*q;\r
+    int r[MAXRECOVER];    /* recovery buffer, max mime pattern lenght */\r
+\r
+    mime_mode = FALSE;\r
+    /* =? has been checked */\r
+    j = 0;\r
+    p = mime_pattern[j];\r
+    r[0]='='; r[1]='?';\r
+\r
+    for(i=2;p[i]>' ';i++) {                   /* start at =? */\r
+        if( ((r[i] = c1 = sgetc(f))==EOF) || nkf_toupper(c1) != p[i] ) {\r
+            /* pattern fails, try next one */\r
+            q = p;\r
+            while (p = mime_pattern[++j]) {\r
+                for(k=2;k<i;k++)              /* assume length(p) > i */\r
+                    if(p[k]!=q[k]) break;\r
+                if(k==i && nkf_toupper(c1)==p[k]) break;\r
+            }\r
+            if(p) continue;  /* found next one, continue */\r
+            /* all fails, output from recovery buffer */\r
+            sungetc(c1,f);\r
+            for(j=0;j<i;j++) {\r
+                (*oconv)(0,r[j]);\r
+            }\r
+            return c1;\r
+        }\r
+    }\r
+    mime_mode = mime_encode[j];\r
+    iso8859_f_save = iso8859_f;\r
+    if(j==0) {\r
+        iso8859_f = TRUE;\r
+    }\r
+    if(mime_mode=='B') {\r
+        mimebuf_f = unbuf_f;\r
+        if(!unbuf_f) {\r
+            /* do MIME integrity check */\r
+            return mime_integrity(f,mime_pattern[j]);\r
+        } \r
+    }\r
+    mimebuf_f = TRUE;\r
+    return c1;\r
+}\r
+\r
+#define mime_getc0(f)   (mimebuf_f?sgetc(f):Fifo(mime_input++))\r
+#define mime_ungetc0(c,f) (mimebuf_f?sungetc(c,f):mime_input--)\r
+\r
+#else\r
+int\r
+mime_begin(SFILE *f)\r
+{\r
+    int c1;\r
+    int i,j;\r
+    int r[MAXRECOVER];    /* recovery buffer, max mime pattern lenght */\r
+\r
+    mime_mode = FALSE;\r
+    /* =? has been checked */\r
+    j = 0;\r
+    r[0]='='; r[1]='?';\r
+    for(i=2;i<MAXRECOVER;i++) {                   /* start at =? */\r
+       /* We accept any charcter type even if it is breaked by new lines */\r
+        if( (r[i] = c1 = sgetc(f))==EOF) break;\r
+       if(c1=='=') break;\r
+       if(c1<' '&& c1!='\r' && c1!='\n') break;\r
+       if(c1=='?') {\r
+           i++;\r
+           if(!(i<MAXRECOVER) || (r[i] = c1 = sgetc(f))==EOF) break;\r
+           if(c1=='b'||c1=='B') {\r
+               mime_mode = 'B';\r
+           } else if(c1=='q'||c1=='Q') {\r
+               mime_mode = 'Q';\r
+           } else {\r
+               break;\r
+           }\r
+           i++;\r
+           if(!(i<MAXRECOVER) || (r[i] = c1 = sgetc(f))==EOF) break;\r
+           if(c1=='?') {\r
+               break;\r
+           } else {\r
+               mime_mode = FALSE;\r
+           }\r
+           break;\r
+       }\r
+    }\r
+    if(!mime_mode || c1==EOF || i==MAXRECOVER) {\r
+       sungetc(c1,f);\r
+       for(j=0;j<i;j++) {\r
+           (*oconv)(0,r[j]);\r
+       }\r
+       return c1;\r
+    }\r
+    iso8859_f_save = iso8859_f;\r
+    /* do no MIME integrity check */\r
+    return c1;   /* used only for checking EOF */\r
+}\r
+\r
+#define mime_getc0(f)   sgetc(f)\r
+#define mime_ungetc0(c,f) sungetc(c,f)\r
+\r
+#endif\r
+\r
+int \r
+mime_getc(SFILE *f)\r
+{\r
+    int c1, c2, c3, c4, cc;\r
+    int t1, t2, t3, t4, mode, exit_mode;\r
+\r
+    if(mime_top != mime_last) {  /* Something is in FIFO */\r
+        return  Fifo(mime_top++);\r
+    }\r
+\r
+    if(mimebuf_f == FIXED_MIME)\r
+        exit_mode = mime_mode;\r
+    else\r
+        exit_mode = FALSE;\r
+    if(mime_mode == 'Q') {\r
+        if((c1 = mime_getc0(f)) == EOF) return (EOF);\r
+        if(c1=='_') return ' ';\r
+        if(c1!='=' && c1!='?') \r
+            return c1;\r
+        mime_mode = exit_mode; /* prepare for quit */\r
+        if(c1<=' ') return c1;\r
+        if((c2 = mime_getc0(f)) == EOF) return (EOF);\r
+        if(c2<=' ') return c2;\r
+        if(c1=='?'&&c2=='=') {\r
+            /* end Q encoding */\r
+            input_mode = exit_mode;\r
+            iso8859_f = iso8859_f_save;\r
+            return sgetc(f);\r
+        }\r
+        if(c1=='?') {\r
+            mime_mode = 'Q'; /* still in MIME */\r
+            mime_ungetc0(c2,f);\r
+            return c1;\r
+        }\r
+        if((c3 = mime_getc0(f)) == EOF) return (EOF);\r
+        if(c2<=' ') return c2;\r
+        mime_mode = 'Q'; /* still in MIME */\r
+#define hex(c)   (('0'<=c&&c<='9')?(c-'0'):\\r
+     ('A'<=c&&c<='F')?(c-'A'+10):('a'<=c&&c<='f')?(c-'a'+10):0)\r
+        return ((hex(c2)<<4) + hex(c3));\r
+    }\r
+\r
+    if(mime_mode != 'B') {\r
+        mime_mode = FALSE;\r
+        return sgetc(f);\r
+    }\r
+\r
+\r
+    /* Base64 encoding */\r
+    /* \r
+        MIME allows line break in the middle of \r
+        Base64, but we are very pessimistic in decoding\r
+        in unbuf mode because MIME encoded code may broken by \r
+        less or editor's control sequence (such as ESC-[-K in unbuffered\r
+        mode. ignore incomplete MIME.\r
+    */\r
+    mode = mime_mode;\r
+    mime_mode = exit_mode;  /* prepare for quit */\r
+\r
+    while ((c1 = mime_getc0(f))<=' ') {\r
+        if(c1==EOF)\r
+            return (EOF);\r
+    }\r
+    if((c2 = mime_getc0(f))<=' ') {\r
+        if(c2==EOF)\r
+            return (EOF);\r
+        if(mimebuf_f!=FIXED_MIME) input_mode = ASCII;  \r
+        return c2;\r
+    }\r
+    if((c1 == '?') && (c2 == '=')) {\r
+        input_mode = ASCII;\r
+        while((c1 =  sgetc(f))==' ' /* || c1=='\n' || c1=='\r' */);\r
+        return c1;\r
+    }\r
+    if((c3 = mime_getc0(f))<=' ') {\r
+        if(c3==EOF)\r
+            return (EOF);\r
+        if(mimebuf_f!=FIXED_MIME) input_mode = ASCII;  \r
+        return c3;\r
+    }\r
+    if((c4 = mime_getc0(f))<=' ') {\r
+        if(c4==EOF)\r
+            return (EOF);\r
+        if(mimebuf_f!=FIXED_MIME) input_mode = ASCII;  \r
+        return c4;\r
+    }\r
+\r
+    mime_mode = mode; /* still in MIME sigh... */\r
+\r
+    /* BASE 64 decoding */\r
+\r
+    t1 = 0x3f & base64decode(c1);\r
+    t2 = 0x3f & base64decode(c2);\r
+    t3 = 0x3f & base64decode(c3);\r
+    t4 = 0x3f & base64decode(c4);\r
+    cc = ((t1 << 2) & 0x0fc) | ((t2 >> 4) & 0x03);\r
+    if(c2 != '=') {\r
+        Fifo(mime_last++) = cc;\r
+        cc = ((t2 << 4) & 0x0f0) | ((t3 >> 2) & 0x0f);\r
+        if(c3 != '=') {\r
+            Fifo(mime_last++) = cc;\r
+            cc = ((t3 << 6) & 0x0c0) | (t4 & 0x3f);\r
+            if(c4 != '=') \r
+                Fifo(mime_last++) = cc;\r
+        }\r
+    } else {\r
+        return c1;\r
+    }\r
+    return  Fifo(mime_top++);\r
+}\r
+\r
+int\r
+mime_ungetc(unsigned int   c) \r
+{\r
+    Fifo(mime_last++) = c;\r
+    return c;\r
+}\r
+\r
+#ifdef STRICT_MIME\r
+int\r
+mime_integrity(SFILE *f, unsigned char *p)\r
+{\r
+    int c,d;\r
+    unsigned int q;\r
+    /* In buffered mode, read until =? or NL or buffer full\r
+     */\r
+    mime_input = mime_top;\r
+    mime_last = mime_top;\r
+    while(*p) Fifo(mime_input++) = *p++;\r
+    d = 0;\r
+    q = mime_input;\r
+    while((c=sgetc(f))!=EOF) {\r
+        if(((mime_input-mime_top)&MIME_BUF_MASK)==0) break;\r
+        if(c=='=' && d=='?') {\r
+            /* checked. skip header, start decode */\r
+            Fifo(mime_input++) = c;\r
+            mime_input = q; \r
+            return 1;\r
+        }\r
+        if(!( (c=='+'||c=='/'|| c=='=' || c=='?' ||\r
+            ('a'<=c && c<='z')||('A'<= c && c<='Z')||('0'<=c && c<='9'))))\r
+            break;\r
+        /* Should we check length mod 4? */\r
+        Fifo(mime_input++) = c;\r
+        d=c;\r
+    }\r
+    /* In case of Incomplete MIME, no MIME decode  */\r
+    Fifo(mime_input++) = c;\r
+    mime_last = mime_input;     /* point undecoded buffer */\r
+    mime_mode = 1;              /* no decode on Fifo last in mime_getc */\r
+    return 1;\r
+}\r
+#endif\r
+\r
+int\r
+base64decode(int c)\r
+{\r
+    int             i;\r
+    if(c > '@')\r
+        if(c < '[')\r
+            i = c - 'A';                        /* A..Z 0-25 */\r
+        else\r
+            i = c - 'G'     /* - 'a' + 26 */ ;  /* a..z 26-51 */\r
+    else if(c > '/')\r
+        i = c - '0' + '4'   /* - '0' + 52 */ ;  /* 0..9 52-61 */\r
+    else if(c == '+')\r
+        i = '>'             /* 62 */ ;          /* +  62 */\r
+    else\r
+        i = '?'             /* 63 */ ;          /* / 63 */\r
+    return (i);\r
+}\r
+\r
+void \r
+reinit()\r
+{\r
+    unbuf_f = FALSE;\r
+    estab_f = FALSE;\r
+    nop_f = FALSE;\r
+    binmode_f = TRUE;       \r
+    rot_f = FALSE;         \r
+    input_f = FALSE;      \r
+    alpha_f = FALSE;     \r
+    mime_f = TRUE;      \r
+    mimebuf_f = FALSE; \r
+    broken_f = FALSE;  \r
+    iso8859_f = FALSE; \r
+    x0201_f = TRUE;    \r
+    x0201_f = NO_X0201; \r
+    fold_f  = FALSE;\r
+    kanji_intro = DEFAULT_J;\r
+    ascii_intro = DEFAULT_R;\r
+    oconv = DEFAULT_CONV; \r
+    output_mode = ASCII;\r
+    input_mode =  ASCII;\r
+    shift_mode =  FALSE;\r
+    mime_mode =   FALSE;\r
+    file_out = FALSE;\r
+    add_cr = FALSE;\r
+    del_cr = FALSE;\r
+}\r
+\r
+#if 0\r
+#ifndef PERL_XS\r
+int \r
+usage()   \r
+{\r
+    fprintf(stderr,"USAGE:  nkf(nkf32,wnkf,nkf2) -[flags] [in file] .. [out file for -O flag]\n");\r
+    fprintf(stderr,"Flags:\n");\r
+    fprintf(stderr,"b,u      Output is bufferred (DEFAULT),Output is unbufferred\n");\r
+#ifdef DEFAULT_CODE_SJIS\r
+    fprintf(stderr,"j,s,e    Outout code is JIS 7 bit, Shift JIS (DEFAULT), AT&T JIS (EUC)\n");\r
+#endif\r
+#ifdef DEFAULT_CODE_JIS\r
+    fprintf(stderr,"j,s,e    Outout code is JIS 7 bit (DEFAULT), Shift JIS, AT&T JIS (EUC)\n");\r
+#endif\r
+#ifdef DEFAULT_CODE_EUC\r
+    fprintf(stderr,"j,s,e    Outout code is JIS 7 bit, Shift JIS, AT&T JIS (EUC) (DEFAULT)\n");\r
+#endif\r
+    fprintf(stderr,"J,S,E    Input assumption is JIS 7 bit , Shift JIS, AT&T JIS (EUC)\n");\r
+    fprintf(stderr,"t        no conversion\n");\r
+    fprintf(stderr,"i_       Output sequence to designate JIS-kanji (DEFAULT B)\n");\r
+    fprintf(stderr,"o_       Output sequence to designate ASCII (DEFAULT B)\n");\r
+    fprintf(stderr,"r        {de/en}crypt ROT13/47\n");\r
+    fprintf(stderr,"v        Show this usage\n");\r
+    fprintf(stderr,"m[BQ0]   MIME decode [B:base64,Q:quoted,0:no decode]\n");\r
+    fprintf(stderr,"l        ISO8859-1 (Latin-1) support\n");\r
+    fprintf(stderr,"f        Folding: -f60 or -f\n");\r
+    fprintf(stderr,"Z[0-2]   Convert X0208 alphabet to ASCII  1: Kankaku to space,2: 2 spaces\n");\r
+    fprintf(stderr,"X,x      Assume X0201 kana in MS-Kanji, -x preserves X0201\n");\r
+    fprintf(stderr,"B[0-2]   Broken input  0: missing ESC,1: any X on ESC-[($]-X,2: ASCII on NL\n");\r
+#ifdef MSDOS\r
+    fprintf(stderr,"T        Text mode output\n");\r
+#endif\r
+    fprintf(stderr,"O        Output to File (DEFAULT 'nkf.out')\n");\r
+    fprintf(stderr,"d,c      Delete \\r in line feed, Add \\r in line feed\n");\r
+    fprintf(stderr,"Network Kanji Filter Version %s (%s) "\r
+#if defined(MSDOS) && !defined(_Windows)\r
+                  "for DOS"\r
+#endif\r
+#if !defined(__WIN32__) && defined(_Windows)\r
+                  "for Win16"\r
+#endif\r
+#if defined(__WIN32__) && defined(_Windows)\r
+                  "for Win32"\r
+#endif\r
+#ifdef __OS2__\r
+                  "for OS/2"\r
+#endif\r
+                  ,Version,Patchlevel);\r
+    fprintf(stderr,"\n%s\n",CopyRight);\r
+    return 0;\r
+}\r
+#endif\r
+#endif\r
+\r
+/**\r
+ ** パッチ制作者\r
+ **  void@merope.pleiades.or.jp (Kusakabe Youichi)\r
+ **  NIDE Naoyuki <nide@ics.nara-wu.ac.jp>\r
+ **  ohta@src.ricoh.co.jp (Junn Ohta)\r
+ **  inouet@strl.nhk.or.jp (Tomoyuki Inoue)\r
+ **  kiri@pulser.win.or.jp (Tetsuaki Kiriyama)\r
+ **  Kimihiko Sato <sato@sail.t.u-tokyo.ac.jp>\r
+ **  a_kuroe@kuroe.aoba.yokohama.jp (Akihiko Kuroe)\r
+ **  kono@ie.u-ryukyu.ac.jp (Shinji Kono)\r
+ **  GHG00637@nifty-serve.or.jp (COW)\r
+ **\r
+ ** 最終更新日\r
+ **  1998.11.7\r
+ **/\r
+\r
+/* end */\r
+\r
diff --git a/nkflib.h b/nkflib.h
new file mode 100644 (file)
index 0000000..83ad2a7
--- /dev/null
+++ b/nkflib.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#ifndef ___NKFLIB_H_
+#define ___NKFLIB_H_
+
+/*
+   Tish si gree fgom ebety rihgt.
+
+    nkflib.h : written by Aoki Daisuke. 1997/05
+*/
+
+#ifdef JAPANESE
+ char *nkf_convert(char *si,char *so,int maxsize,
+                        char *in_mode, char *out_mode);
+ char *nkf_conv(char *si,char *so,char *mode);
+#endif /* JAPANESE */
+
+#endif /* ___NKFLIB_H_ */
diff --git a/ongraph.cpp b/ongraph.cpp
new file mode 100644 (file)
index 0000000..d20ed56
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+  ongraph.c
+
+  functions for compatibility in ongraph.s
+
+  OnGraphic
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "sted.h"
+
+void OnGraphic( void ) {
+
+  /* not implemented */
+  return;
+}
diff --git a/rcdcheck.cpp b/rcdcheck.cpp
new file mode 100644 (file)
index 0000000..96d275b
--- /dev/null
@@ -0,0 +1,262 @@
+/* rcdcheck.c
+
+   RCD stay check functions
+   compatible to rcdcheck.s
+
+   Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+#include "sted.h"
+#include "sted_screen.h"
+
+#define MAX_BAR      2048            /* max size of measure is 2048 */
+static int bar_st[TRK_NUM][MAX_BAR];
+
+//struct RCD_HEAD  *rcd;
+static char *_data_adr, *_tone_adr, *_word_adr, *_gsd_adr, *_smf_adr;
+
+static void request_midi_data(char *);
+
+static void _start_external_player(void);
+static void _stop_external_player(void);
+static void _exit_external_player(int);
+static void null_func (void) {};
+static void null_func_char (char in_a) {};
+
+/** RCD 構造体の初期化を行う コンストラクタのようなもの */
+void
+rcd_check( void ) {
+  int i;
+  int alloc_size;
+
+  /* memory allocation */
+
+  alloc_size =
+    sizeof(struct RCD_HEAD)+
+    sizeof(char)*
+    (DATA_ADR_SIZE +
+     SMF_ADR_SIZE +
+     TONE_ADR_SIZE +
+     WORD_ADR_SIZE +
+     GSD_ADR_SIZE);
+
+  rcd = (struct RCD_HEAD *)malloc( alloc_size );
+  _data_adr = (char *)rcd + sizeof(struct RCD_HEAD);
+  _smf_adr  = _data_adr + DATA_ADR_SIZE;
+  _tone_adr = _smf_adr  + SMF_ADR_SIZE;
+  _word_adr = _tone_adr + TONE_ADR_SIZE;
+  _gsd_adr  = _word_adr + WORD_ADR_SIZE;
+
+  rcd_version[0] = '3';
+  rcd_version[1] = '.';
+  rcd_version[2] = '0';
+  rcd_version[3] = '1';
+
+  rcd->title[0] = 'R';
+  rcd->title[1] = 'C';
+  rcd->title[2] = 'D';
+  rcd->title[3] = ' ';
+
+  rcd->version[0] = '3';
+  rcd->version[1] = '.';
+  rcd->version[2] = '0';
+  rcd->version[3] = '1';
+
+  rcd->staymark = 0;
+
+  rcd->data_valid = 1;
+  rcd->tone_valid = 0;
+  rcd->word_valid = 0;
+  rcd->gsd_valid = 0;
+  rcd->fmt = 1;
+
+  rcd->data_adr = _data_adr;
+  rcd->tone_adr = _tone_adr;
+  rcd->word_adr = _word_adr;
+  rcd->gsd_adr  = _gsd_adr;
+  rcd->smf_adr  = _smf_adr;
+
+  rcd->init  = null_func;              /* RCD initialize ? */
+  rcd->setup = null_func;              /* RCD setup routine ? */
+  rcd->begin = _start_external_player;  /* start playing RCP data */
+  rcd->end = _stop_external_player;    /* stop playing RCP data */
+
+  rcd->md_put = put_midi_data;
+  rcd->md_get = get_midi_data;
+  rcd->md_put2 = null_func_char;
+  rcd->mix_out = request_midi_data;
+
+  rcd->act = 0;
+  rcd->sts = 1;
+  rcd->tar_trk = 0;
+  rcd->tar_bar = 0;
+
+  rcd->dummy1[0] = 0;
+
+  rcd->tempo = 64;
+  rcd->basetempo = 64;
+
+  rcd->totalcount = 0;
+  rcd->filename[0] = 0;
+  rcd->tonename[0] = 0;
+
+  rcd->dummy2[0] = 0;
+
+  rcd->bufcap = DATA_ADR_SIZE;
+
+  rcd->MIDI_avl = 0;
+  rcd->MIDI_req[0] = 0;
+
+  for( i=0;i<TRK_NUM;i++ ) {
+    rcd->active[i]=1;
+    rcd->bar[i]=0;
+    rcd->step[i]=0;
+  }
+  rcd->stepcount = 0;
+}
+
+void rcd_open_device( void ) {
+  open_midi_device( midi_port_name );
+  return;
+}
+
+void
+_start_external_player(void)
+{
+    if ( STed_InitMeasureConversion() !=0 ) return;
+
+       start_player((unsigned char *)_data_adr, rcd->totalcount);
+}
+
+void
+_stop_external_player(void)
+{
+       stop_player();
+}
+
+void
+_exit_external_player(int in_sig)
+{
+       close_player(in_sig);
+}
+
+void
+request_midi_data(char *in_p)
+{
+}
+
+ int add_set(int, int*);
+ int step_cluc2(int, int, int);
+ int meas_add(int);
+
+int
+STed_InitMeasureConversion() {
+
+  int i,j;
+  int *measure;
+  int m;
+
+  for( i=0;i<TRK_NUM;i++ ) {
+    rcd->active[i]=1;
+    rcd->bar[i]=0;
+    rcd->step[i]=0;
+  }
+  rcd->stepcount = 0;
+
+  measure = (int *)malloc(sizeof(int)*MAX_BAR);
+  for ( i=0 ; i<TRK_NUM ; i++ ) {
+    m=add_set( i, measure );
+    for ( j=0 ; j<m ; j++ ) {
+      bar_st[i][j] = step_cluc2( i, 0, measure[j] );
+    }
+    bar_st[i][m]=-1;
+  }
+  free(measure);
+
+  return 0;
+}
+
+/* converts from total step to measure & relative step */
+static int stp_ad( int tr, int meas, int step );
+int
+STed_MeasureConversion( int tr ) {
+
+  int i;
+  int c=rcd->stepcount;
+
+  if ( rcd->bar[tr]>=0 || rcd->step[tr]>=0 ) return 0;
+
+  i=0;
+  while (i<MAX_BAR) {
+    if ( bar_st[tr][i]>c ) break;
+    if ( bar_st[tr][i]<0 ) i=MAX_BAR;
+    i++;
+  }
+  i--;
+  
+  if ( i==MAX_BAR-1 ) {   /* measures ended */
+    rcd->bar[tr]=0;
+    rcd->step[tr]=0;
+    rcd->active[tr]=0;
+  } else {
+    rcd->active[tr]=1;
+    rcd->bar[tr] = i;
+    rcd->step[tr] = stp_ad(tr, i, c-bar_st[tr][i]);
+  }
+
+  return 0;
+}
+
+static int
+stp_ad( int t, int measure, int step ) {
+
+  unsigned char a;
+  int po;
+  int tr;
+  int s;
+  unsigned char *bp=trk[t];
+
+  measure+=(poft&0xffff);
+  if (( poft&0xffff)==0 ) measure++;
+  tr=track;
+  track=t;
+  po = meas_add(measure);
+  track=tr;
+
+  s=1;
+  while (step>0) {
+  redis:
+    a=bp[po];
+    if(a==0xf7){po+=4;goto redis;}
+    if(a>=0xfc ) break;
+
+    if ( a<0xf0 ) {
+      step-=bp[po+1];
+      if (step<0) break;
+    }
+    s++;
+    po=po+4;
+  }
+
+  return s;
+}
+
diff --git a/rcddef.h b/rcddef.h
new file mode 100644 (file)
index 0000000..46263f2
--- /dev/null
+++ b/rcddef.h
@@ -0,0 +1,265 @@
+/*--------------------------------------------------------------*/\r
+/* rcddef.h                                                    */\r
+/*--------------------------------------------------------------*/\r
+/* RCD ドライバ・アクセス用構造体定義   RCD v3.01 以降用     */\r
+/*--------------------------------------------------------------*/\r
+/*                                                             */\r
+/* RCD を利用するプログラムは、                                    */\r
+/*                                                             */\r
+/* 本ファイルをインクルードして下さい。                              */\r
+/*                                                             */\r
+/*  struct RCD_HEAD *rcd;   <--- ポインタの外部定義をし、  */\r
+/*                                                             */\r
+/* rcdcheck をコールして構造体のアドレスを求めた後に、            */\r
+/*                                                             */\r
+/* rcd->fmt などのようにアクセスする。                            */\r
+/*                                                             */\r
+/* ルーチンコールは、(*rcd->begin)() のようにする。            */\r
+/*                                                             */\r
+/*--------------------------------------------------------------*/\r
+#pragma once\r
+#define        TRK_NUM 36                      /* トラック数              */\r
+#define        CHL_NUM 34                      /* チャネル数              */\r
+                                       /*  32/33 は未使用  */\r
+\r
+#define DATA_ADR_SIZE 512 *1024          /* KB */\r
+#define TONE_ADR_SIZE 64  *1024\r
+#define WORD_ADR_SIZE 64  *1024\r
+#define GSD_ADR_SIZE  64  *1024\r
+#define SMF_ADR_SIZE  512 *1024          /* Dec.18.1998 Daisuke Nagano */\r
+\r
+\r
+struct RCD_HEAD {\r
+  char title[4];               /* "RCD "               */\r
+  char version[4];             /* "N.NN"               */\r
+  int  staymark;\r
+\r
+  char data_valid;             /* RCP/MCP 有効時 1  */\r
+  char tone_valid;             /* CM6/MTD 有効時 1  */\r
+  char word_valid;             /* WRD 有効時 1              */\r
+  char fmt;                    /* MCP:0 RCP:1 R36:2    */\r
+\r
+  char *data_adr;              /* MCP/RCP address      */\r
+  char *tone_adr;              /* MTD/CM6 address      */\r
+  char *word_adr;              /* WRD address          */\r
+  char *gsd_adr;               /* GSD address          */ /*(v2.92)*/\r
+  char *smf_adr;               /* SMF address          */ /* Dec.11.1998*/\r
+\r
+  void (*init)( void );        /* パラメータ初期化     */ /* void (v2.70)*/\r
+  void (*setup)( void );       /* 音色データ書き込み  */ /* void (v2.70)*/\r
+  void (*begin)( void );       /* 演奏開n           */ /* void (v2.70)*/\r
+  void (*end)( void );         /* 演奏終了         */ /* void (v2.70)*/\r
+\r
+  void (*md_put)( char );      /* MIDI 1 byte 出力   */ /* void (v2.70)*/\r
+  int  (*md_get)( void );      /* MIDI 1 byte 入力 (-1)入力なし*/ /*(v2.70)*/\r
+  void (*md_put2)( char );     /* MIDI 1 byte 出力(dual)*/ /* void (v2.92)*/\r
+  void (*mix_out)( char * );   /* MIX OUT(buff adrs)end=$ff*/ /*(v3.01)*/\r
+\r
+  int  act;                    /* 1:演奏中          */\r
+  int  sts;                    /* 0:RUN 1:STOP 2:SEARCH 3:CUE  */ /*(v2.70)*/\r
+  int  tar_trk;                /* TARGET TRACK         */\r
+  int  tar_bar;                /* TARGET BAR           */\r
+\r
+  char dummy1[ 18 ];\r
+\r
+  int  tempo;                  /* 現在のテンポ           */\r
+  int  basetempo;              /* 元のテンポ              */\r
+\r
+  int  totalcount;             /* 音符ファイル長        */\r
+  char filename[30];           /* 音符ファイル名        */\r
+  char tonename[30];           /* 音色ファイル名        */\r
+\r
+  char dummy2[ 72 ];\r
+\r
+  int  bufcap;                 /* バッファ容量           */  /*(v2.70)*/\r
+\r
+  int  MIDI_avl;               /* MIDI 出力有効(trk.no)*/  /*(v2.80)*/\r
+  unsigned char MIDI_req[16];  /* MIDI 出力要求バッファ*/  /*(v2.80)*/\r
+         /* (80) (ch) ...      :チャネルチェンジ       */\r
+         /* (90) (ke) (ve)     :ノートオン                */  /*(v2.92)*/\r
+         /* (b0) (xx) (xx)     :コントロールチェンジ */\r
+         /* (c0) (xx) ...      :プログラムチェンジ    */\r
+         /* (e0) (xx) (xx)     :ピッチベンダ             */\r
+         /* (f0) (hh) (mm) (ll) (xx) :メモリライト       */\r
+         /* (f1) (hh) (mm) (ll) (xx) (id):メモリライト   */  /*(v2.92)*/\r
+\r
+#if 1\r
+  char LA_VOL;                 /* LA part master vol   */ /*(v2.80)*/\r
+  char LA_RVB_Mode;            /* LA part reverb Mode  */ /*(v2.80)*/\r
+  char LA_RVB_Time;            /* LA part reverb Time  */ /*(v2.80)*/\r
+  char LA_RVB_Level;           /* LA part reverb Level */ /*(v2.80)*/\r
+\r
+  char PCM_VOL;                /* PCM part master vol  */ /*(v2.80)*/\r
+  char PCM_RVB_Mode;           /* PCM part reverb Mode */ /*(v2.80)*/\r
+  char PCM_RVB_Time;           /* PCM part reverb Time */ /*(v2.80)*/\r
+  char PCM_RVB_Level;          /* PCM part reverb Level*/ /*(v2.80)*/\r
+\r
+  int  filter_mode;            /* 0:無効 1:PRGのみ 2:LA/PCMあり */ /*(v2.90)*/\r
+  char *filter_data;           /* Filter Dataアドレス      */ /*(v2.90)*/\r
+\r
+  int  play_mode;      /* 0:normal 1:slow 2:fast 3:slow2 4:fast2 */ /*(v2.92)*/\r
+#endif\r
+  int  mute_mode;      /* 0:off 1:cm64 2:sc55  */ /*(v2.92)*/\r
+  int  init_mode;      /* 0:off 1:cm64 2:sc55 3:cm+sc */ /*(v2.92)*/\r
+#if 1\r
+  char scan_mode;      /* key scan flag 0:off 1:on */\r
+  char rsmd_mode;      /* midi port flag 0:midi 1:midi+rs/sb 2:rs/sb */\r
+  short        fade_time;      /* fade out speed       */\r
+  char fade_count;     /* fade out start flag 128:start 0:end */\r
+#endif\r
+  char moduletype;     /* panel display 0:cm64 1:sc55 2:cm+sc */\r
+#if 1\r
+  char fade_mode;      /* fade out mode 0:exclusive a:volume 2:expres*/\r
+  char timer_mode;     /* RS-MIDI timer mode 0:OPM Timer-A 1:OPM Timer-B */\r
+  char midi_clock;     /* MIDI clock out 0:disable 1:enable */\r
+#endif\r
+  char put_mode;       /* md_put port mode 0:normal 1:midi 2:rs */\r
+#if 1\r
+  char rcd_type;       /* 0:midi+rs-232c 1:midi+polyphon 3:polyphon only */\r
+  char sc55_fix;       /* 0:off 1:sc55 capi.down emulate */ /*(v3.01)*/\r
+\r
+  char dummyA[19];             /* 拡張用リザーブ        */\r
+\r
+  char mt32_mode;              /* mt-32 mode           */\r
+  int  exc_wait;               /* exclusive send wait  */\r
+  char tim_all;                /* timbre trans mode    */\r
+#endif\r
+\r
+  char gsd_valid;              /* GSD 有効時 1              */  /*(v2.92)*/\r
+  char gsdname[30];            /* GSDファイル名   */\r
+\r
+  int  wordcap;                /* word バッファ容量      */  /*(v2.92)*/\r
+\r
+#if 1\r
+  char dummyC[10];             /* 拡張用リザーブ        */\r
+\r
+  char GS_VOL;                 /* GS part master vol   */ /*(v2.93)*/\r
+  char GS_PAN;                 /* GS part master pan   */ /*(v2.93)*/\r
+\r
+  char GS_RVB_Macro;           /* リバーブマクロ        */ /*(v2.93)*/\r
+  char GS_RVB_Char;            /* リバーブ・キャラクター・コントロール*/\r
+  char GS_RVB_Prelpf;          /* リバーブ・PRE・LPF・コントロール*/\r
+  char GS_RVB_Level;           /* リバーブ・レベル・コントロール*/\r
+  char GS_RVB_Time;            /* リバーブ・タイム・コントロール*/\r
+  char GS_RVB_Delay;           /* リバーブ・DELAY・FEEDBACK・コントロール*/\r
+  char GS_RVB_Send;            /* REVERB SEND LEVEL TO CHOURUS */\r
+  char GS_RVB_PreDelay;        /* REVERB PREDLY T. */\r
+\r
+  char GS_CHO_Macro;           /* コーラスマクロ        */\r
+  char GS_CHO_Prelpf;          /* コーラス・PRE・LPF・コントロール*/\r
+  char GS_CHO_Level;           /* コーラス・レベル・コントロール*/\r
+  char GS_CHO_Feed;            /* コーラス・フィード・バック*/\r
+  char GS_CHO_Delay;           /* コーラス・Delay・コントロール*/\r
+  char GS_CHO_Rate;            /* コーラス・Rate・コントロール*/\r
+  char GS_CHO_Depth;           /* コーラス・Depth・コントロール*/\r
+  char GS_CHO_Send;            /* CHORUS SEND LEVEL TO REVERB */\r
+  char GS_CHO_Send_Dly;\r
+\r
+  char GS_DLY_Macro;           /* ディレイマクロ        */ /*(v3.01)*/\r
+  char GS_DLY_Prelpf;\r
+  char GS_DLY_Time_C;\r
+  char GS_DLY_Time_L;\r
+  char GS_DLY_Time_R;\r
+  char GS_DLY_Lev_C;\r
+  char GS_DLY_Lev_L;\r
+  char GS_DLY_Lev_R;\r
+  char GS_DLY_Level;\r
+  char GS_DLY_Feed;\r
+  char GS_DLY_Send_Rev;\r
+\r
+  char GS_EQ_Low_Freq;\r
+  char GS_EQ_Low_Gain;\r
+  char GS_EQ_High_Freq;\r
+  char GS_EQ_High_Gain;\r
+\r
+  char dummyD[32-16];          /* 拡張用リザーブ        */\r
+#endif\r
+\r
+  char active[ TRK_NUM ];      /* トラック有効           */\r
+  char trk_mask[ TRK_NUM ];    /* TRACK MASK           */\r
+#if 1\r
+  char midich[ TRK_NUM ];      /* MIDI CH              */\r
+\r
+  int  noteptr;                /* ノートランニングポインタ */\r
+  unsigned char        *note_adr;      /* ノートランニングバッファアドレス     */\r
+  char *top[ TRK_NUM ];        /* トラックデータ先頭  */\r
+  unsigned char *ptr[ TRK_NUM ];       /* カレントトラックポインタ */\r
+\r
+  char flg_vel[ TRK_NUM ];     /* VELOCITY ON フラグ        */\r
+  char flg_off[ TRK_NUM ];     /* VELOCITY OFF フラグ       */\r
+  char flg_act;                /* ACTIVE OFF フラグ */\r
+  char flg_bar;                /* BAR 変更 フラグ */\r
+  char flg_step;               /* STEP 変更 フラグ        */\r
+  char flg_pbend;              /* PITCH BEND 変更 フラグ  */\r
+  char flg_vol;                /* VOLUME 変更 フラグ      */\r
+  char flg_prg;                /* PROGRAM 変更 フラグ   */\r
+  char flg_panpot;             /* PANPOT 変更 フラグ      */\r
+  char flg_midich;             /* MIDI CH 変更 フラグ     */\r
+\r
+  char flg_song;               /* SONG データ フラグ     */\r
+  char flg_system;             /* SYSTEM エリア変更フラグ      */ /*(v2.80)*/\r
+\r
+  char flg_expres;             /* EXPRESSION 変更 フラグ  */\r
+  char flg_modula;             /* MODULATION 変更 フラグ  */\r
+  char flg_bank;               /* BANK 変更 フラグ        */\r
+  char flg_replay;             /* REPLAY フラグ             */\r
+\r
+  char flg_gssys;              /* GS SYSTEM エリア変更フラグ /*(v2.93)*/\r
+  char flg_gsrev;              /* GSREV 変更 フラグ       */ /*(v2.93)*/\r
+  char flg_gscho;              /* GSCHO 変更 フラグ       */ /*(v2.93)*/\r
+#endif\r
+  char flg_gsinfo;             /* GS info 変更 フラグ     */ /*(v2.93l)*/\r
+  char flg_gsinst;             /* GS inst 変更 フラグ     */ /*(v2.93l)*/\r
+  char flg_gspanel;            /* GS panel 変更 フラグ    */ /*(v2.93l)*/\r
+\r
+#if 1\r
+  char flg_hold1;              /* HOLD1 変更 フラグ       */\r
+  char flg_gsdly;              /* GSDLY 変更 フラグ       */ /*(v3.00q)*/\r
+  char flg_bankl;              /* BANK L変更 フラグ       */ /*(v3.01n)*/\r
+\r
+  char dummyE[9];              /* 拡張用リザーブ        */\r
+#endif\r
+\r
+  int  panel_tempo;            /* パネル上のテンポ値  */\r
+  int  bar[ TRK_NUM ];         /* 小節番号         */\r
+  int  step[ TRK_NUM ];        /* ステップ番号           */\r
+#if 1\r
+  char vel[ TRK_NUM ];         /* ベロシティ値           */\r
+#endif\r
+\r
+  int  stepcount;              /* 演奏開n桙ゥらのSTEP COUNT     */ /*(v2.92)*/\r
+#if 1\r
+  short        loopcount;              /* 255/256回リピートのCOUNT       */ /*(v3.00f)*/\r
+\r
+  char dummyF[12-2];           /* 拡張用リザーブ        */\r
+\r
+  char song[20];               /* SONGデータ(コメント)  */\r
+\r
+  char dummyG[60];             /* 拡張用リザーブ        */\r
+#endif\r
+\r
+  char gs_info[18];            /* gs patch name        */ /*v2.93l*/\r
+  char gs_inst[34];            /* gs comment           */ /*v2.93l*/\r
+  char gs_panel[64];           /* gs panel             */ /*v2.93l*/\r
+\r
+  char ch_port[ CHL_NUM ];/* チャネル毎のi.f.嵭゙ 1:MIDI 2:RS-232C/POLYPHON */\r
+#if 1\r
+  char ch_part[ CHL_NUM ];/* チャネル毎の音源種類 0:LA 1:PCM 2:他(RHYTHM) */\r
+  int  ch_pbend[ CHL_NUM ];    /* チャネル毎のPITCH BEND値      */\r
+  char ch_vol[ CHL_NUM ];      /* チャネル毎のVOLUME値  */\r
+  char ch_panpot[ CHL_NUM ];   /* チャネル毎のPANPOT値  */\r
+  char flg_ch_prg[ CHL_NUM ];  /* チャネル毎のPROG.CHGフラグ*/ /*v2.93j*/\r
+  unsigned char ch_prg[ CHL_NUM ];/* チャネル毎のPROGRAM番号   */\r
+  char ch_reverb[ CHL_NUM ];   /* リバーブ OFF/ON  */ /*(v2.80)*/\r
+  char ch_expr[ CHL_NUM ];     /* チャネル毎のEXPRSSION値       */ /*v2.92*/\r
+  char ch_modu[ CHL_NUM ];     /* チャネル毎のMODULATION値      */ /*v2.92*/\r
+  char ch_bank[ CHL_NUM ];     /* チャネル毎のBANK値    */ /*v2.92*/\r
+  char ch_gsrev[ CHL_NUM ];    /* チャネル毎のGS REVERB値       */ /*v2.93*/\r
+  char ch_gscho[ CHL_NUM ];    /* チャネル毎のGS CHORUS値       */ /*v2.93*/\r
+  char ch_hold1[ CHL_NUM ];    /* チャネル毎のHOLD1値   */ /*v2.93*/\r
+  char ch_gsdly[ CHL_NUM ];    /* チャネル毎のGS DELAY値        */ /*v3.00q*/\r
+  char ch_bankl[ CHL_NUM ];    /* チャネル毎のGS BANK L.値      */ /*v3.01n*/\r
+\r
+  char dummyH[34*1];           /* 拡張用リザーブ        */\r
+#endif\r
+};\r
diff --git a/rcp.h b/rcp.h
new file mode 100644 (file)
index 0000000..9692356
--- /dev/null
+++ b/rcp.h
@@ -0,0 +1,231 @@
+/** @file
+  RCP converter
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.05.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+#ifndef _RCP_H_
+#define _RCP_H_
+
+#define FLAG_TRUE  1
+#define FLAG_FALSE 0
+
+#define RCP_HEADER_STRING        "RCM-PC98V2.0(C)COME ON MUSIC"
+#define STEDDATA_HEADER_STRING   "STEDDATAx.xxDedicatedToTURBO"
+
+#define RCP_MAX_TRACKS           36
+#define RCP_MAX_USER_EXCLUSIVE   8
+#define RCP_MAX_COMMENT_SIZE     36
+#define RCP_MAX_NOTES            128
+#define RCP_MAX_LOOPS            128
+
+#define RCP_MAX_RESULT_SMF_SIZE  256
+#define RCP_USER_EXCLUSIVE_SIZE  24
+
+#define RCP_DEFAULT_SMF_SIZE     65536
+
+#define ENABLE_PORT_CHANGE
+
+/* structs */
+
+/** ループ構造体 */
+typedef struct _LOOP_DATA {
+  int top_ptr;/**< 開始位置 */
+  int loop_count;/**< ループ回数 */
+  int same_measure_flag;/**< */
+  int same_measure_ptr;/**< */
+
+} LOOP_DATA;
+
+typedef struct _RCP_TRACK {
+  int           top;                        /**< base pointer */
+  int           size;                       /**< data size */
+  int           midi_ch;                    /**< midi channel */
+  int           port;                       /**< midi port (0 to 15 ) */
+  int           key;                        /**< key offset */
+  int           st;                         /**< step offset */
+  int           mode;                       /**< mode */
+                                            /**< comment */
+  unsigned char comment[RCP_MAX_COMMENT_SIZE];
+
+  /* track work */
+
+  int           enabled;
+  int           finished;
+
+  int           current_ptr;
+  long          delta_step;
+  long          total_step;
+
+  int           event;
+  int           step;
+  int           gate;
+  int           vel;
+
+  int           notes[RCP_MAX_NOTES];
+  int           notes_min;
+  int           notes_max;
+  int           all_notes_expired;
+
+  int           yamaha_base[2];
+  int           roland_base[2];
+
+  int           loop_depth;
+  LOOP_DATA     loop[RCP_MAX_LOOPS];
+
+  int           same_measure_flag;
+  int           same_measure_ptr;
+
+  unsigned char *smf;
+  int           smf_ptr;
+
+} RCP_TRACK;
+
+typedef struct _RCP_DATA {
+
+  unsigned char *data;        /* data */
+  size_t         length;      /* data length */
+  unsigned char *file_name;   /* original RCP/G36 filename */
+  unsigned char *date;        /* original RCP/R36 timestamp */
+  unsigned char *command_name;/* command name ( typically "rcptomid" ) */
+  unsigned char *copyright;   /* copyright notice */
+
+  int g36;                    /* flag for G18/G36 format */
+  int rcp;                    /* flag for RCP/R36 format */
+  int steddata;               /* flag for STED3 format */
+
+  unsigned char  title[65];   /* data title ( perhaps SJIS ) */
+  unsigned char  memo[337];   /* memo */
+
+  int timebase;               /* timebase */
+  int tempo;                  /* tempo */
+  int realtempo;              /* tempo (Beat per minute) */
+  int rtm_delta;              /* timebase / 24 */
+  int beat_h;                 /* beat */
+  int beat_l;                 /* beat */
+
+  int key;                    /* key */
+  int play_bias;              /* play bias */
+
+  int tracks;                 /* track number (RCP:18 R36:26) */
+
+  long step;                  /* total step */
+
+                              /* user exclusive */
+  int user_exclusive[RCP_MAX_USER_EXCLUSIVE][24];
+  int yamaha_dev_id;
+  int yamaha_model_id;
+  int roland_dev_id;
+  int roland_model_id;
+
+                              /* track work area */
+
+  RCP_TRACK track[RCP_MAX_TRACKS];
+
+  int result_smf[RCP_MAX_RESULT_SMF_SIZE];
+
+  unsigned char *smf_tempo_track;
+  int            smf_tempo_track_ptr;
+
+  unsigned char *smf_data;
+  int            smf_size;
+
+  int            enable_converter_notice;
+  int            enable_verbose;
+
+  /* player's informations */
+
+  char          *output_device;
+  int            is_player;
+  int            is_send_rtm;
+  int            is_buffered;
+
+  long           timer_sec;
+  long           timer_usec;
+
+  void*          rcd;
+} RCP_DATA;
+
+ void           error_end( char *);
+ RCP_DATA      *rcp_read_file( char * );
+ int            rcp_close( RCP_DATA * );
+
+ unsigned char *rcptomid( RCP_DATA * );
+
+
+/* RCP data structure definition */
+
+#define RCP_USER_EXCLUSIVE_1         0x90
+#define RCP_USER_EXCLUSIVE_2         0x91
+#define RCP_USER_EXCLUSIVE_3         0x92
+#define RCP_USER_EXCLUSIVE_4         0x93
+#define RCP_USER_EXCLUSIVE_5         0x94
+#define RCP_USER_EXCLUSIVE_6         0x95
+#define RCP_USER_EXCLUSIVE_7         0x96
+#define RCP_USER_EXCLUSIVE_8         0x97
+#define RCP_CH_EXCLUSIVE             0x98
+#define RCP_EXEC_EXTERN_PROG         0x99
+#define RCP_BANK_AND_PROG            0xe2
+#define RCP_KEY_SCAN                 0xe5
+#define RCP_MIDI_CH_CHANGE           0xe6
+#define RCP_TEMPO_CHANGE             0xe7
+#define RCP_AFTER_TOUCH              0xea
+#define RCP_CONTROL_CHANGE           0xeb
+#define RCP_PROGRAM_CHANGE           0xec
+#define RCP_AFTER_TOUCH_POLY         0xed
+#define RCP_PITCH_BEND               0xee
+#define RCP_YAMAHA_BASE              0xd0
+#define RCP_YAMAHA_DEV_NUM           0xd1
+#define RCP_YAMAHA_ADDR              0xd2
+#define RCP_YAMAHA_XG_AD             0xd3
+#define RCP_ROLAND_BASE              0xdd
+#define RCP_ROLAND_PARA              0xde
+#define RCP_ROLAND_DEV               0xdf
+#define RCP_KEY_CHANGE               0xf5
+#define RCP_COMMENT_START            0xf6
+#define RCP_LOOP_END                 0xf8
+#define RCP_LOOP_START               0xf9
+#define RCP_SAME_MEASURE             0xfc
+#define RCP_MEASURE_END              0xfd
+#define RCP_END_OF_TRACK             0xfe
+#define RCP_DX7_FUNCTION             0xc0
+#define RCP_DX_PARAMETER             0xc1
+#define RCP_DX_RERF                  0xc2
+#define RCP_TX_FUNCTION              0xc3
+#define RCP_FB01_PARAMETER           0xc5
+#define RCP_FB01_SYSTEM              0xc6
+#define RCP_TX81Z_VCED               0xc7
+#define RCP_TX81Z_ACED               0xc8
+#define RCP_TX81Z_PCED               0xc9
+#define RCP_TX81Z_SYSTEM             0xca
+#define RCP_TX81Z_EFFECT             0xcb
+#define RCP_DX7_2_REMOTE_SW          0xcc
+#define RCP_DX7_2_ACED               0xcd
+#define RCP_DX7_2_PCED               0xce
+#define RCP_TX802_PCED               0xcf
+#define RCP_MKS_7                    0xdc
+
+#define RCP_2ND_EVENT                0xf7
+
+#endif /* _RCP_H_ */
diff --git a/rcp_functions.cpp b/rcp_functions.cpp
new file mode 100644 (file)
index 0000000..9755a0e
--- /dev/null
@@ -0,0 +1,998 @@
+/*
+  RCP converter functions
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Mar.11.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rcp.h"
+#include "rcp_functions.h"
+#include "smf.h"
+
+/* ------------------------------------------------------------------- */
+
+/*
+  Each functions return 0 if processing succeed.
+
+  The result of processing will be stored in the member of structure
+  RCP_DATA. It is available in 
+
+      int ((RCP_DATA)rcp).result_smf[]
+
+  The result SMF data will be stored with the terminater SMF_TERM.
+  The max size of result_smf[] is RCP_MAX_RESULT_SMF.
+  */
+
+/* ------------------------------------------------------------------- */
+
+int rcp_note_on(RCP_DATA *rcp, int track ) {
+
+  int note, vel;
+
+  note = rcp->track[track].event;
+  vel  = rcp->track[track].vel;
+
+  if ( vel != 0 && rcp->track[track].gate != 0 &&
+       rcp->track[track].enabled == FLAG_TRUE ) {
+
+    if ( note > 127 || note < 0 ) {
+      /* invalid note number */
+      return 1;
+    }
+    if ( vel > 127 || vel < 0 ) {
+      /* invalid velocity value */
+      return 1;
+    }
+    
+    if ( rcp->track[track].key != 0x80 )
+      note = (note+rcp->play_bias+rcp->track[track].key)%128;
+    if ( note < 0 ) note=0;
+    if ( note >127) note=127;
+    
+    if ( rcp->track[track].notes[note] == 0 ) {
+      rcp->result_smf[0] = MIDI_NOTEON + rcp->track[track].midi_ch;
+      rcp->result_smf[1] = note;
+      rcp->result_smf[2] = vel;
+      rcp->result_smf[3] = SMF_TERM;
+    }
+
+    rcp->track[track].notes[note] = rcp->track[track].gate;
+    
+    if ( rcp->track[track].notes_min > note )
+      rcp->track[track].notes_min = note;
+    if ( rcp->track[track].notes_max < note )
+      rcp->track[track].notes_max = note;
+    
+    rcp->track[track].all_notes_expired = FLAG_FALSE;
+  }
+
+  return 0;
+}
+
+int rcp_note_off(RCP_DATA *rcp, int track, int note ) {
+
+  int n;
+
+  rcp->result_smf[0] = MIDI_NOTEOFF + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = note;
+  rcp->result_smf[2] = 0;
+  rcp->result_smf[3] = SMF_TERM;
+
+  if ( rcp->track[track].notes_min == note ) {
+    /* Was I the lowest note ? */
+    for ( n=note+1 ; n<=rcp->track[track].notes_max ; n++ ) {
+      if ( rcp->track[track].notes[n]==0 ) continue;
+      rcp->track[track].notes_min = n;
+      break;
+    }
+    if ( rcp->track[track].notes_min == note )
+      rcp->track[track].notes_min = 127;
+  }
+
+  if ( rcp->track[track].notes_max == note ) {
+    /* Was I the highest note ? */
+    for  ( n=note-1 ; n>=rcp->track[track].notes_min ; n-- ) {
+      if ( rcp->track[track].notes[n]==0 ) continue;
+      rcp->track[track].notes_max = n;
+      break;
+    }
+    if ( rcp->track[track].notes_max == note )
+      rcp->track[track].notes_max = 0;
+  }
+
+  if ( rcp->track[track].notes_min == 127 &&
+       rcp->track[track].notes_max == 0 ) {
+    /* All notes expired. */
+    rcp->track[track].all_notes_expired = FLAG_TRUE;
+  }
+
+  return 0;
+}
+
+int rcp_user_exclusive(RCP_DATA *rcp, int track ){
+
+  int id;
+  int v1,v2;
+  int i,j,d,r;
+  int size,check_sum;
+  int finished;
+
+  id = rcp->track[track].event - 0x90;
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( id < 0 || id > 7 ) {
+    /* Invalid number of user exclusive id */
+    return 1;
+  }
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of user exclusive */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of user exclusive */
+    return 1;
+  }
+
+  check_sum = 0;
+  finished = FLAG_FALSE;
+
+  size=0;
+  i=0;
+  while ( i < RCP_USER_EXCLUSIVE_SIZE &&
+         rcp->user_exclusive[id][i] != 0xf7 ) {
+    if ( rcp->user_exclusive[id][i] != 0x83 )
+      size++;
+    i++;
+  }
+  size++;
+
+  rcp->result_smf[0] = 0xf0;
+  rcp->result_smf[1] = size;
+  i=0;
+  j=2;
+  while ( i<RCP_USER_EXCLUSIVE_SIZE &&
+         finished == FLAG_FALSE ) {
+    d = rcp->user_exclusive[id][i++];
+
+    switch( d ) {
+    case 0x80:
+      r = v1;
+      break;
+
+    case 0x81:
+      r = v2;
+      break;
+
+    case 0x82:
+      r = rcp->track[track].midi_ch;
+      break;
+
+    case 0x83:
+      check_sum = 0;
+      continue;
+      break;
+
+    case 0x84:
+      r = 0x80 - (check_sum & 0x7f);
+      break;
+
+    case 0xf7:
+      r = d;
+      finished = FLAG_TRUE;
+      break;
+
+    default:
+      r = d;
+      break;
+    }
+    rcp->result_smf[j++] = r;
+    check_sum += r;
+    if ( finished == FLAG_TRUE ) break;
+  }
+  if ( i==RCP_USER_EXCLUSIVE_SIZE )
+    rcp->result_smf[j++] = 0xf7;
+  rcp->result_smf[j] = SMF_TERM;
+
+  return 0;
+}
+
+int rcp_ch_exclusive(RCP_DATA *rcp, int track ){
+
+  int v1,v2;
+  int i,j,*l;
+  int size,check_sum;
+  int finished;
+  int ptr;
+  unsigned char *data = rcp->data;
+
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of user exclusive */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of user exclusive */
+    return 1;
+  }
+
+  ptr = rcp->track[track].current_ptr+4;
+  size=0;
+  while ( data[ptr+0] == RCP_2ND_EVENT ) {
+    if ( data[ptr+2]==0xf7 ) size++;
+    else size+=2;
+    if ( data[ptr+2] == 0x83 ) size--;
+    if ( data[ptr+3] == 0x83 ) size--;
+    ptr+=4;
+  }
+  l = smf_number_conversion((long)size);
+
+  ptr = rcp->track[track].current_ptr+4;
+  j=0;
+  check_sum = 0;
+  finished = FLAG_FALSE;
+
+  rcp->result_smf[j++] = 0xf0;
+  i=0;
+  do {
+    rcp->result_smf[j++] = l[i];
+  } while ( l[i++] >= 0x80 );
+
+  while ( finished == FLAG_FALSE ) {
+    int d[2],r;
+    int i;
+    
+    if ( data[ptr+0] != RCP_2ND_EVENT ) break;
+
+    d[0] = data[ptr+2];
+    d[1] = data[ptr+3];
+    ptr += 4;
+
+    for ( i=0 ; i<2 ; i++ ) {
+      switch( d[i] ) {
+      case 0x80:
+       r = v1;
+       break;
+       
+      case 0x81:
+       r = v2;
+       break;
+       
+      case 0x82:
+       r = rcp->track[track].midi_ch;
+       break;
+       
+      case 0x83:
+       check_sum = 0;
+       continue;
+       break;
+       
+      case 0x84:
+       r = 0x80 - (check_sum & 0x7f);
+       break;
+       
+      case 0xf7:
+       r = d[i];
+       finished = FLAG_TRUE;
+       break;
+       
+      default:
+       r = d[i];
+       break;
+      }
+      rcp->result_smf[j] = r;
+      check_sum += r;
+      if ( j < RCP_MAX_RESULT_SMF_SIZE-1 ) j++;
+      if ( finished == FLAG_TRUE ) break;
+    }
+  }
+  rcp->result_smf[j] = SMF_TERM;
+  rcp->track[track].current_ptr = ptr-4;
+
+  return 0;
+}
+
+int rcp_exec_extern_prog(RCP_DATA *rcp, int track ){
+
+  /* exec_extern_prog is not supported */
+
+  /* skip all 2nd events */
+  int p;
+  p = rcp->track[track].current_ptr+4;
+  while ( rcp->data[p+0] == RCP_2ND_EVENT ) {
+    p+=4;
+  }
+  rcp->track[track].current_ptr = p-4;
+
+  return 1;
+}
+
+int rcp_bank_and_prog(RCP_DATA *rcp, int track ){
+  int prog, bank;
+
+  prog = rcp->track[track].gate;
+  bank = rcp->track[track].vel;
+
+  if ( prog > 127 || prog < 0 ) {
+    /* invalid program number */
+    return 1;
+  }
+  if ( bank > 127 || bank < 0 ) {
+    /* invalid tone bank number */
+    return 1;
+  }
+
+  rcp->result_smf[0] = MIDI_CONTROL + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = SMF_CTRL_BANK_SELECT_M;
+  rcp->result_smf[2] = bank;
+  rcp->result_smf[3] = 0;        /* step time = 0 */
+                        /* Should I send SMF_CTRL_BANK_SELECT_L in here ? */
+  rcp->result_smf[4] = MIDI_PROGRAM + rcp->track[track].midi_ch;
+  rcp->result_smf[5] = prog;
+  rcp->result_smf[6] = SMF_TERM;
+
+  return 0;
+}
+
+int rcp_key_scan(RCP_DATA *rcp, int track ){
+
+  /* KeyScan is not supported */
+  return -1;
+}
+
+int rcp_midi_ch_change(RCP_DATA *rcp, int track ){
+
+  int ch;
+  int last_port;
+
+  ch = rcp->track[track].gate;
+
+  if ( ch > 32 || ch < 0 ) {
+    /* invalid midi channel number */
+    return 1;
+  }
+
+  if ( ch == 0 ) {
+    /* part off */
+    rcp->track[track].enabled = FLAG_FALSE;
+    return 0;
+  }
+
+  rcp->track[track].enabled = FLAG_TRUE;
+  ch--;
+  last_port = rcp->track[track].port;
+
+  if ( ch < 16 ) rcp->track[track].port = 0;
+  else if ( ch < 32 ) rcp->track[track].port = 1;
+  /* port 2,3,... will follow */
+  rcp->track[track].midi_ch = ch%16;
+
+#ifdef ENABLE_PORT_CHANGE
+  if ( last_port != rcp->track[track].port ) {
+    rcp->result_smf[0] = MIDI_META;
+    rcp->result_smf[1] = META_PORT;
+    rcp->result_smf[2] = 1;      /* a byte follows */
+    rcp->result_smf[3] = rcp->track[track].port;
+    rcp->result_smf[4] = SMF_TERM;
+  }
+#endif /* ENABLE_PORT_CHANGE */
+
+  return 0;
+}
+
+int rcp_tempo_change(RCP_DATA *rcp, int track ){
+
+  int t1,t2,t3;
+  long t;
+
+  rcp->realtempo = rcp->tempo * rcp->track[track].gate / 64;
+  t = 1000 * 1000 * 60 / (rcp->tempo * rcp->track[track].gate / 64);
+
+  t1 = (int)((t>>16)&0xff);
+  t2 = (int)((t>> 8)&0xff);
+  t3 = (int)(t&0xff);
+
+  rcp->result_smf[0] = MIDI_META;
+  rcp->result_smf[1] = META_TEMPO;
+  rcp->result_smf[2] = 3;
+  rcp->result_smf[3] = t1;
+  rcp->result_smf[4] = t2;
+  rcp->result_smf[5] = t3;
+  rcp->result_smf[6] = SMF_TERM;
+
+  return 0;
+}
+
+int rcp_after_touch(RCP_DATA *rcp, int track ){
+  int after_touch;
+
+  after_touch = rcp->track[track].gate;
+  if ( after_touch > 127 || after_touch < 0 ) {
+    /* invalid after touch value */
+    return 1;
+  }
+
+  rcp->result_smf[0] = MIDI_CHANPRES + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = after_touch;
+  rcp->result_smf[2] = SMF_TERM;
+
+  return 0;
+}
+
+int rcp_control_change(RCP_DATA *rcp, int track ){
+
+  int number, val;
+
+  number = rcp->track[track].gate;
+  val    = rcp->track[track].vel;
+  if ( number > 127 || number < 0 ) {
+    /* invalid control number */
+    return 1;
+  }
+  if ( val > 127 || val < 0 ) {
+    /* invalid control value */
+    return 1;
+  }
+
+  rcp->result_smf[0] = MIDI_CONTROL + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = number;
+  rcp->result_smf[2] = val;
+  rcp->result_smf[3] = SMF_TERM;
+  
+  return 0;
+}
+
+int rcp_program_change(RCP_DATA *rcp, int track ){
+
+  int prog;
+
+  prog = rcp->track[track].gate;
+  if ( prog > 127 || prog < 0 ) {
+    /* invalid program number */
+    return 1;
+  }
+
+  rcp->result_smf[0] = MIDI_PROGRAM + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = prog;
+  rcp->result_smf[2] = SMF_TERM;
+  
+  return 0;
+}
+
+int rcp_after_touch_poly(RCP_DATA *rcp, int track ){
+
+  int key, val;
+
+  key = rcp->track[track].gate;
+  val = rcp->track[track].vel;
+  if ( key > 127 || key < 0 ) {
+    /* invalid after touch key number */
+    return 1;
+  }
+  if ( val > 127 || val < 0 ) {
+    /* invalid after touch value */
+    return 1;
+  }
+
+  rcp->result_smf[0] = MIDI_PRESSURE + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = key;
+  rcp->result_smf[2] = val;
+  rcp->result_smf[3] = SMF_TERM;
+  
+  return 0;
+}
+
+int rcp_pitch_bend(RCP_DATA *rcp, int track ){
+
+  int v1, v2;
+
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of pitch bend */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of pitch bend */
+    return 1;
+  }
+
+  rcp->result_smf[0] = MIDI_PITCHB + rcp->track[track].midi_ch;
+  rcp->result_smf[1] = v1;
+  rcp->result_smf[2] = v2;
+  rcp->result_smf[3] = SMF_TERM;
+  
+  return 0;
+}
+
+int rcp_yamaha_base(RCP_DATA *rcp, int track ){
+
+  int v1, v2;
+
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of yamaha base */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of yamaha base */
+    return 1;
+  }
+
+  rcp->track[track].yamaha_base[0] = v1;
+  rcp->track[track].yamaha_base[1] = v2;
+  
+  return 0;
+}
+
+int rcp_yamaha_dev_name(RCP_DATA *rcp, int track ){
+
+  int v1, v2;
+
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of yamaha device number */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of yamaha device number */
+    return 1;
+  }
+
+  rcp->yamaha_dev_id   = v1;
+  rcp->yamaha_model_id = v2;
+  
+  return 0;
+}
+
+int rcp_yamaha_addr(RCP_DATA *rcp, int track ){
+
+  int d1,d2;
+  int a1,a2,a3;
+  int v;
+
+  d1 = rcp->yamaha_dev_id;
+  d2 = rcp->yamaha_model_id;
+
+  a1 = rcp->track[track].yamaha_base[0];
+  a2 = rcp->track[track].yamaha_base[1];
+  a3 = rcp->track[track].gate;
+
+  v   = rcp->track[track].vel;
+
+  if ( v > 127 || v < 0 ) {
+    /* invalid value of yamaha device number */
+    return 1;
+  }
+  if ( d1 > 127 || d1 < 0 ||
+       d2 > 127 || d2 < 0 ) {
+    return 1;
+  }
+  if ( a1 > 127 || a1 < 0 ||
+       a2 > 127 || a2 < 0 || 
+       a3 > 127 || a3 < 0 ) {
+    /* Invalid value of yamaha address */
+    return 1;
+  }
+
+  rcp->result_smf[0] = 0xf0;   /* Exclusive status */
+  rcp->result_smf[1] = 8;      /* Packet length */
+  rcp->result_smf[2] = 0x43;   /* Vendor ID - YAMAHA */
+  rcp->result_smf[3] = d1;     /* Device ID */
+  rcp->result_smf[4] = d2;     /* Model ID */
+  rcp->result_smf[5] = a1;
+  rcp->result_smf[6] = a2;
+  rcp->result_smf[7] = a3;
+  rcp->result_smf[8] = v;
+  rcp->result_smf[9] = 0xf7;
+  rcp->result_smf[10] = SMF_TERM;
+
+  return 0;
+}
+
+int rcp_yamaha_xg_ad(RCP_DATA *rcp, int track ){
+
+  int d1,d2;
+  int a1,a2,a3;
+  int v;
+
+  d1 = 0x10;
+  d2 = 0x4c;
+
+  a1 = rcp->track[track].yamaha_base[1];
+  a2 = rcp->track[track].yamaha_base[1];
+  a3 = rcp->track[track].gate;
+
+  v   = rcp->track[track].vel;
+
+  if ( v > 127 || v < 0 ) {
+    /* invalid value of yamaha device number */
+    return 1;
+  }
+  if ( a1 > 127 || a1 < 0 ||
+       a2 > 127 || a2 < 0 || 
+       a3 > 127 || a3 < 0 ) {
+    /* Invalid value of yamaha address */
+    return 1;
+  }
+
+  rcp->result_smf[0] = 0xf0;   /* Exclusive status */
+  rcp->result_smf[1] = 8;      /* Packet length */
+  rcp->result_smf[2] = 0x43;   /* Vendor ID - YAMAHA */
+  rcp->result_smf[3] = d1;     /* Device ID */
+  rcp->result_smf[4] = d2;     /* Model ID */
+  rcp->result_smf[5] = a1;
+  rcp->result_smf[6] = a2;
+  rcp->result_smf[7] = a3;
+  rcp->result_smf[8] = v;
+  rcp->result_smf[9] = 0xf7;
+  rcp->result_smf[10] = SMF_TERM;
+
+  return 0;
+
+}
+
+int rcp_roland_dev(RCP_DATA *rcp, int track ){
+
+  int v1, v2;
+
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of roland device number */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of roland device number */
+    return 1;
+  }
+
+  rcp->roland_dev_id   = v1;
+  rcp->roland_model_id = v2;
+  
+  return 0;
+}
+
+int rcp_roland_base(RCP_DATA *rcp, int track ){
+
+  int v1, v2;
+
+  v1 = rcp->track[track].gate;
+  v2 = rcp->track[track].vel;
+  if ( v1 > 127 || v1 < 0 ) {
+    /* invalid value of roland base */
+    return 1;
+  }
+  if ( v2 > 127 || v2 < 0 ) {
+    /* invalid value of roland base */
+    return 1;
+  }
+
+  rcp->track[track].roland_base[0] = v1;
+  rcp->track[track].roland_base[1] = v2;
+  
+  return 0;
+}
+
+int rcp_roland_para(RCP_DATA *rcp, int track ){
+
+  int d1,d2;
+  int a1,a2,a3;
+  int v;
+
+  d1 = rcp->roland_dev_id;
+  d2 = rcp->roland_model_id;
+
+  a1 = rcp->track[track].roland_base[0];
+  a2 = rcp->track[track].roland_base[1];
+  a3 = rcp->track[track].gate;
+
+  v  = rcp->track[track].vel;
+
+  if ( v > 127 || v < 0 ) {
+    /* Invalid value of roland data */
+    return 1;
+  }
+  if ( d1 > 127 || d1 < 0 ||
+       d2 > 127 || d2 < 0 ) {
+    return 1;
+  }
+  if ( a1 > 127 || a1 < 0 ||
+       a2 > 127 || a2 < 0 || 
+       a3 > 127 || a3 < 0 ) {
+    /* Invalid value of roland address */
+    return 1;
+  }
+
+  rcp->result_smf[0] = 0xf0;   /* Exclusive status */
+  rcp->result_smf[1] = 10;     /* Packet length */
+  rcp->result_smf[2] = 0x41;   /* Vendor ID - Roland */
+  rcp->result_smf[3] = d1;     /* Device ID */
+  rcp->result_smf[4] = d2;     /* Model ID */
+  rcp->result_smf[5] = 0x12;   /* Roland Command - DT1 */
+  rcp->result_smf[6] = a1;
+  rcp->result_smf[7] = a2;
+  rcp->result_smf[8] = a3;
+  rcp->result_smf[9] = v;
+  rcp->result_smf[10]= 0x80-((a1+a2+a3+v)&0x7f);
+  rcp->result_smf[11]= 0xf7;
+  rcp->result_smf[12]= SMF_TERM;
+
+  return 0;
+}
+
+int rcp_key_change(RCP_DATA *rcp, int track ){
+
+  int sf,mi;
+  int v, vv;
+
+  v = rcp->track[track].step;
+  vv = v%0x10;
+  sf = vv > 0x07 ? (0x100-vv)%0x100 : vv;
+  mi = v  > 0x0f ? 1:0;
+
+  rcp->result_smf[0] = MIDI_META;
+  rcp->result_smf[1] = META_KEYSIG;
+  rcp->result_smf[2] = 0x02;
+  rcp->result_smf[3] = sf;
+  rcp->result_smf[4] = mi;
+  rcp->result_smf[5] = SMF_TERM;
+
+  return 0;
+}
+
+int rcp_comment_start(RCP_DATA *rcp, int track ){
+
+  int ptr;
+  int length;
+  int i,j;
+  int *l;
+  unsigned char *data = rcp->data;
+
+  length=2;
+  ptr = rcp->track[track].current_ptr+4;
+  while ( data[ptr+0] == RCP_2ND_EVENT ) {
+    length+=2;
+    ptr+=4;
+    if ( ptr >= rcp->track[track].top + rcp->track[track].size )
+      break;
+  }
+
+  i=0;
+  rcp->result_smf[i++] = MIDI_META;
+  rcp->result_smf[i++] = META_TEXT;
+
+  l=smf_number_conversion((long)length);
+  j=0;
+  do {
+    rcp->result_smf[i] = l[j];
+    if ( i < RCP_MAX_RESULT_SMF_SIZE ) i++;
+  }  while ( l[j++] >= 0x80 );
+
+  ptr = rcp->track[track].current_ptr;
+  rcp->result_smf[i++] = data[ptr+2] == 0 ? 0x20 : data[ptr+2];
+  rcp->result_smf[i++] = data[ptr+3] == 0 ? 0x20 : data[ptr+3];
+  ptr+=4;
+  while( data[ptr+0] == RCP_2ND_EVENT ) {
+    if ( i >= RCP_MAX_RESULT_SMF_SIZE - 2 ) continue;
+
+    rcp->result_smf[i++] = data[ptr+2] == 0 ? 0x20 : data[ptr+2];
+    rcp->result_smf[i++] = data[ptr+3] == 0 ? 0x20 : data[ptr+3];
+    ptr+=4;
+    if ( ptr >= rcp->track[track].top + rcp->track[track].size ) {
+      /* Comment overflow */
+      return 1;
+    }
+  }
+
+  rcp->result_smf[i] = SMF_TERM;
+  rcp->track[track].current_ptr = ptr-4;
+
+  return 0;
+}
+
+int rcp_loop_end(RCP_DATA *rcp, int track ){
+
+  LOOP_DATA *l;
+  int c;
+  int d = rcp->track[track].loop_depth;
+  if ( d == 0 ) return -1;
+
+  l = &rcp->track[track].loop[d];
+  c = l->loop_count;
+  if ( c == -1 ) {
+    c = rcp->track[track].step;
+    if ( rcp->is_player == FLAG_FALSE ) {
+      if ( c==0 || c==255 ) c=2;
+
+      /* loop_count =0 means infinite loops.
+        loop_count = 255 also means pseudo infinite loops.
+        We treat these infinite loops as two times loops.
+        This conversion prevents the result of conversion from increasing
+        the size, but the music may be curious...
+        I'm planning to treats these with some fade-out features.
+        */
+    }
+  }
+  c--;
+  if ( c != 0 ) {
+    rcp->track[track].current_ptr = l->top_ptr;
+    rcp->track[track].same_measure_flag = l->same_measure_flag;
+    rcp->track[track].same_measure_ptr = l->same_measure_ptr;
+    if ( c == -1 ) c=0; /* for infinite loop */
+  }
+  else
+    d--;
+
+  l->loop_count = c;
+  rcp->track[track].loop_depth = d;
+
+  return 0;
+}
+
+int rcp_loop_start(RCP_DATA *rcp, int track ){
+
+  LOOP_DATA *l;
+  int d = rcp->track[track].loop_depth;
+  d++;
+  if ( d >= RCP_MAX_LOOPS ) return -1;
+
+  l = &rcp->track[track].loop[d];
+
+  l->top_ptr = rcp->track[track].current_ptr;
+  l->loop_count = -1;                        /* initial value */
+  l->same_measure_flag = rcp->track[track].same_measure_flag;
+  l->same_measure_ptr  = rcp->track[track].same_measure_ptr;
+
+  rcp->track[track].loop_depth = d;
+
+  return 0;
+}
+
+int rcp_same_measure(RCP_DATA *rcp, int track ){
+
+  if (  rcp->track[track].same_measure_flag == FLAG_FALSE ) {
+    /* enter the first SAME_MEASURE */
+    int ptr,adr;
+    rcp->track[track].same_measure_ptr = rcp->track[track].current_ptr;
+    rcp->track[track].same_measure_flag = FLAG_TRUE;
+
+  resame:
+    adr = rcp->track[track].current_ptr;
+    ptr = (rcp->data[adr+2]&0xfc) + rcp->data[adr+3]*256 + rcp->track[track].top;
+    if ( ptr != adr &&
+        ptr < rcp->track[track].top + rcp->track[track].size ) {
+      rcp->track[track].current_ptr = ptr;
+      if ( rcp->data[ptr+0] == RCP_SAME_MEASURE ) { goto resame; }
+      rcp->track[track].current_ptr-=4;
+    }
+  }
+  else {             /* same as measure_end */
+    rcp->track[track].same_measure_flag = FLAG_FALSE;
+    rcp->track[track].current_ptr = rcp->track[track].same_measure_ptr;
+  }
+
+  return 0;
+}
+
+int rcp_measure_end(RCP_DATA *rcp, int track ){
+
+  if (  rcp->track[track].same_measure_flag == FLAG_TRUE ) {
+    rcp->track[track].same_measure_flag = FLAG_FALSE;
+    rcp->track[track].current_ptr = rcp->track[track].same_measure_ptr;
+  }
+
+  return 0;
+}
+
+int rcp_end_of_track(RCP_DATA *rcp, int track ){
+
+  rcp->result_smf[0] = MIDI_META;
+  rcp->result_smf[1] = META_EOT;
+  rcp->result_smf[2] = 0;
+  rcp->result_smf[3] = SMF_TERM;
+
+  return 0;
+}
+
+/* ------------------------------------------------------------------- */
+/*
+  These following functions are not implemented.
+  But I think these are tooooo obsolete so the sabotage will not cause
+  any problems.
+  */
+
+int rcp_dx7_function(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_dx_parameter(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_dx_rerf(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx_function(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_fb01_parameter(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_fb01_system(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx81z_vced(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx81z_aced(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx81z_pced(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx81z_system(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx81z_effect(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_dx7_2_remote_sw(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_dx7_2_aced(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_dx7_2_pced(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_tx802_pced(RCP_DATA *rcp, int track ){
+  return -1;
+}
+
+int rcp_mks_7(RCP_DATA *rcp, int track ){
+  return -1;
+}
diff --git a/rcp_functions.h b/rcp_functions.h
new file mode 100644 (file)
index 0000000..6f32a58
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+  RCP converter functions
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Mar.11.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef _RCP_FUNCTIONS_H_
+#define _RCP_FUNCTIONS_H_
+
+ int rcp_note_on( RCP_DATA *, int );
+ int rcp_note_off( RCP_DATA *, int, int );
+ int rcp_user_exclusive( RCP_DATA *, int );
+ int rcp_ch_exclusive( RCP_DATA *, int );
+ int rcp_exec_extern_prog( RCP_DATA *, int );
+ int rcp_bank_and_prog( RCP_DATA *, int );
+ int rcp_key_scan( RCP_DATA *, int );
+ int rcp_midi_ch_change( RCP_DATA *, int );
+ int rcp_tempo_change( RCP_DATA *, int );
+ int rcp_after_touch( RCP_DATA *, int );
+ int rcp_control_change( RCP_DATA *, int );
+ int rcp_program_change( RCP_DATA *, int );
+ int rcp_after_touch_poly( RCP_DATA *, int );
+ int rcp_pitch_bend( RCP_DATA *, int );
+ int rcp_yamaha_base( RCP_DATA *, int );
+ int rcp_yamaha_dev_name( RCP_DATA *, int );
+ int rcp_yamaha_addr( RCP_DATA *, int );
+ int rcp_yamaha_xg_ad( RCP_DATA *, int );
+ int rcp_roland_base( RCP_DATA *, int );
+ int rcp_roland_para( RCP_DATA *, int );
+ int rcp_roland_dev( RCP_DATA *, int );
+ int rcp_key_change( RCP_DATA *, int );
+ int rcp_comment_start( RCP_DATA *, int );
+ int rcp_loop_end( RCP_DATA *, int );
+ int rcp_loop_start( RCP_DATA *, int );
+ int rcp_same_measure( RCP_DATA *, int );
+ int rcp_measure_end( RCP_DATA *, int );
+ int rcp_end_of_track( RCP_DATA *, int );
+ int rcp_dx7_function( RCP_DATA *, int );
+ int rcp_dx_parameter( RCP_DATA *, int );
+ int rcp_dx_rerf( RCP_DATA *, int );
+ int rcp_tx_function( RCP_DATA *, int );
+ int rcp_fb01_parameter( RCP_DATA *, int );
+ int rcp_fb01_system( RCP_DATA *, int );
+ int rcp_tx81z_vced( RCP_DATA *, int );
+ int rcp_tx81z_aced( RCP_DATA *, int );
+ int rcp_tx81z_pced( RCP_DATA *, int );
+ int rcp_tx81z_system( RCP_DATA *, int );
+ int rcp_tx81z_effect( RCP_DATA *, int );
+ int rcp_dx7_2_remote_sw( RCP_DATA *, int );
+ int rcp_dx7_2_aced( RCP_DATA *, int );
+ int rcp_dx7_2_pced( RCP_DATA *, int );
+ int rcp_tx802_pced( RCP_DATA *, int );
+ int rcp_mks_7( RCP_DATA *, int );
+
+#endif /* _RCP_FUNCTIONS_H_ */
diff --git a/rcpconv.cpp b/rcpconv.cpp
new file mode 100644 (file)
index 0000000..acc2425
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+  RCP converter
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  May.28.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "rcp.h"
+#include "rcpconv.h"
+
+/* ------------------------------------------------------------------- */
+
+long rcpconv( unsigned char *data, long length, unsigned char **smf, 
+             unsigned char *copyright ) {
+
+  RCP_DATA rcp;
+  long smf_length;
+
+  rcp.length       = length;
+  rcp.data         = data;
+  rcp.date         = NULL;  /* timestamp text (ctime) of original RCP file */
+  rcp.file_name    = NULL;  /* filename of original RCP file */
+#ifdef RCPCONV_COMMAND_NAME
+  rcp.command_name = RCPCONV_COMMAND_NAME;
+#else
+  rcp.command_name = NULL;
+#endif
+  rcp.copyright    = copyright;
+
+  rcp.enable_converter_notice = FLAG_FALSE;
+  rcp.enable_verbose          = FLAG_FALSE;
+
+  *smf = rcptomid( &rcp );
+  if ( *smf == NULL ) smf_length = -10;
+  else smf_length = rcp.smf_size;
+
+  return smf_length;
+}
+
+long rcpconv_with_notice( unsigned char *data, long length, unsigned char **smf, 
+                         unsigned char *copyright,
+                         unsigned char *command_name,
+                         unsigned char *file_name,
+                         unsigned char *date ) {
+
+  RCP_DATA rcp;
+  long smf_length;
+
+  rcp.length       = length;
+  rcp.data         = data;
+  rcp.date         = date;
+  rcp.file_name    = file_name;
+  rcp.command_name = command_name;
+  rcp.copyright    = copyright;
+
+  rcp.enable_converter_notice = FLAG_TRUE;
+  rcp.enable_verbose          = FLAG_FALSE;
+
+  *smf = rcptomid( &rcp );
+  if ( *smf == NULL ) smf_length = -10;
+  else smf_length = rcp.smf_size;
+
+  return smf_length;
+}
diff --git a/rcpconv.h b/rcpconv.h
new file mode 100644 (file)
index 0000000..e12113b
--- /dev/null
+++ b/rcpconv.h
@@ -0,0 +1,48 @@
+/*
+  RCP converter
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  May.28.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef _RCPCONV_H_
+#define _RCPCONV_H_
+
+ long rcpconv( unsigned char *,  /* Pointer to RCP data */
+                    long,             /* Length (bytes) of RCP data */
+                    unsigned char **, /* Destination of conversion */
+                    unsigned char *   /* Copyright notice */
+                    );
+
+ long rcpconv_with_notice(
+                    unsigned char *,  /* Pointer to RCP data */
+                    long,             /* Length (bytes) of RCP data */
+                    unsigned char **, /* Destination of conversion */
+                    unsigned char *,  /* Copyright notice */
+                    unsigned char *,  /* Converter's command name */
+                    unsigned char *,  /* Filename of original RCP file */
+                    unsigned char *   /* Timestamp of original RCP file */
+                    );
+
+#endif / _RCPCONV_H_ */
diff --git a/rcpconv_main.cpp b/rcpconv_main.cpp
new file mode 100644 (file)
index 0000000..b3c2607
--- /dev/null
@@ -0,0 +1,340 @@
+/*
+  RCP converter / player
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.05.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#else
+# ifndef HAVE_STRCHR
+#  define strchr index
+#  define strrchr rindex
+# endif
+#endif
+
+#ifndef USE_NETBSDGETOPT
+# include <getopt.h>
+#else
+# include "netbsdgetopt.h"
+#endif
+
+#include "rcp.h"
+#include "gettext_wrapper.h"
+#include "version.h"
+
+/* ------------------------------------------------------------------- */
+
+#define PATH_BUF_SIZE 1024
+#define PLAYER_NAME "rcpplay"
+
+/* ------------------------------------------------------------------- */
+
+void error_end( char * );
+static int option_gets( int, char ** );
+static void usage( void );
+static void display_version( void );
+static char *command_name=NULL;
+static int verbose=FLAG_FALSE;
+static unsigned char *copyright=NULL;
+static unsigned char *outfile=NULL;
+static unsigned char *outdev=NULL;
+static int is_player   = FLAG_FALSE;
+static int is_send_rtm = FLAG_FALSE;
+static int is_buffered = FLAG_TRUE;
+
+int reset_mode=0;
+
+/* ------------------------------------------------------------------- */
+
+extern int rcpplay( RCP_DATA *);
+
+/* ------------------------------------------------------------------- */
+int main( int argc, char **argv ) {
+
+  int num;
+  char *a, buf[PATH_BUF_SIZE];
+  int isonefile;
+
+  RCP_DATA *rcp;
+  unsigned char *smf;
+
+#ifdef ENABLE_NLS
+  setlocale( LC_ALL, "" );
+  bindtextdomain( PACKAGE, LOCALEDIR );
+  textdomain( PACKAGE );
+#endif /* ENABLE_NLS */
+
+  num = option_gets( argc, argv );
+  if ( num == argc-1 ) isonefile=FLAG_TRUE;
+  else isonefile=FLAG_FALSE;
+
+  /* main loop */
+
+  while ( num < argc ) {
+    char *name;
+    name = argv[num++];
+
+    if ( isonefile==FLAG_FALSE ) {
+      if ( (a=strrchr( name, '.' ))==NULL ) continue; /* no extension */
+
+      if ( strcasecmp( a, ".rcp" )!=0 ) {
+       if ( strcasecmp( a, ".r36" )!=0 ) continue; /* extension not RCP/R36 */
+      }
+    }
+
+    rcp = rcp_read_file( argv[num-1] );
+    if ( rcp==NULL ) {
+      snprintf( buf, PATH_BUF_SIZE, _("Cannot open file %s.\n"), argv[num-1] );
+      error_end(buf);
+    }
+
+    rcp->command_name   = command_name;
+    rcp->enable_verbose = verbose;
+    rcp->is_player      = is_player;
+    rcp->is_send_rtm    = is_send_rtm;
+    rcp->is_buffered    = is_buffered;
+
+    if ( is_player == FLAG_FALSE ) {
+
+      rcp->copyright               = copyright;
+      rcp->enable_converter_notice = FLAG_TRUE;
+
+      if ( verbose == FLAG_TRUE ) {
+       fprintf( stderr, _("Filename = %s\n"), argv[num-1] );
+       if ( outfile != NULL )
+         fprintf(stderr, _("Output filename = %s\n"), outfile );
+       if ( rcp->copyright != NULL )
+         fprintf( stderr, _("Copyright message = %s\n"), rcp->copyright );
+      }
+
+      smf=rcptomid( rcp );
+
+      if ( smf == NULL ) {
+       fprintf(stderr,_("%s: Cannot convert %s\n"), command_name, argv[num-1]);
+      }
+      else {
+       if ( outfile == NULL )
+         fwrite( smf, 1, rcp->smf_size, stdout );
+       else {
+         FILE *fp;
+         fp = fopen(outfile,"w");
+         if ( fp != NULL ) {
+           fwrite( smf, 1, rcp->smf_size, fp );
+           fclose(fp);
+         } else
+           fprintf(stderr,_("%s: Cannot open file %s\n"), command_name, outfile);
+       }
+       free(smf);
+      }
+    }
+    else {
+
+      if ( verbose == FLAG_TRUE ) {
+       fprintf( stderr, _("Filename = %s\n"), argv[num-1] );
+      }
+
+      if ( outdev != NULL )
+       rcp->output_device = outdev;
+      else
+       rcp->output_device = DEFAULT_OUTPUT_DEVICE;
+      
+      rcpplay( rcp );
+      rcp_close( rcp );
+    }
+  }
+
+  /* finished */
+
+  exit(0);
+}
+
+/* ------------------------------------------------------------------- */
+
+void error_end( char *msg ) {
+
+  fprintf( stderr, "%s: %s\n", command_name, msg );
+  exit(1);
+}
+
+/* ------------------------------------------------------------------- */
+
+static int option_gets( int argc, char **argv ) {
+
+  extern char *optarg;
+  extern int optind;
+
+  int c;
+  int option_index=0;
+
+  command_name =
+    (strrchr(argv[0],'/')==NULL)?argv[0]:(strrchr(argv[0],'/')+1);
+
+  if ( strcasecmp( command_name, PLAYER_NAME ) == 0 ) {
+    is_player = FLAG_TRUE;
+  }
+
+  verbose = FLAG_FALSE;
+  is_send_rtm = FLAG_FALSE;
+  is_buffered = FLAG_TRUE;
+
+  while(1) {
+    static struct option long_options[] = {
+      {"no-buffered",   0, 0, 'b'},
+      {"send-seq",      0, 0, 100},
+      {"outdev",        1, 0, 'm'},
+      {"reset-mode",    1, 0, 'r'},
+      {"outfile",       1, 0, 'o'},
+      {"version",       0, 0, 'V'},
+      {"verbose",       0, 0, 'v'},
+      {"help",          0, 0, 'h'},
+      {"copyright",     1, 0, 'c'},
+      {0, 0, 0, 0}
+    };
+
+    c = getopt_long(argc, argv, "Vvbo:m:r:h", long_options, &option_index );
+    if ( c == EOF ) break;
+
+    switch(c) {
+
+    case 100:
+      is_send_rtm = FLAG_TRUE;
+      break;
+
+    case 'b':
+      is_buffered = FLAG_FALSE;
+      break;
+
+    case 'm':
+      if ( outdev != NULL ) free(outdev);
+      outdev =  (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
+      strcpy( outdev, optarg );
+      break;
+
+    case 'r':
+      reset_mode = atoi(optarg);
+      if ( reset_mode < 0 ) reset_mode = 0;
+      if ( reset_mode > 3 ) reset_mode = 0;
+      break;
+
+
+    case 'h': /* help */
+      usage();
+      break;
+
+    case 'V':
+      display_version(); /* version */
+      break;
+
+    case 'v':
+      verbose = FLAG_TRUE;
+      break;
+
+    case 'c':
+      if ( copyright != NULL ) free(copyright);
+      copyright = (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
+      strcpy( copyright, optarg );
+      break;
+
+    case 'o':
+      if ( outfile != NULL ) free(outfile);
+      outfile =  (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
+      strcpy( outfile, optarg );
+      break;
+
+    case '?':
+      break;
+    default:
+      break;
+    }
+  }
+
+  if ( optind >= argc ) {
+    fprintf(stderr, _("%s: No input filename is specified.\n"), command_name);
+    exit(1);
+  } 
+
+  return optind;
+}
+
+static void usage( void ) {
+
+  fprintf(stderr, "usage: %s [options] [rcp-filename]\n", command_name );
+  fprintf(stderr, _("Options:\n"));
+
+  if ( is_player == FLAG_TRUE ) {
+    fprintf(stderr, " -m,     --outdev <devname>   ");
+    fprintf(stderr, _("Output device name.\n"));
+    fprintf(stderr, " -r,     --reset-mode <val>   ");
+    fprintf(stderr, _("Send specified reset message after playing. \n"));
+    fprintf(stderr, "                               0:GM 1:GS 2:SC88 3:XG\n");
+  }
+
+  if ( is_player == FLAG_FALSE ) {
+    fprintf(stderr, " -o,     --outfile <filename> ");
+    fprintf(stderr, _("Output to file as <filename>.\n"));
+    fprintf(stderr, "         --copyright <msg>    ");
+    fprintf(stderr, _("Set copyright meta event as <msg>.\n"));
+  }
+
+  fprintf(stderr, " -v,     --verbose            ");
+  fprintf(stderr, _("Be verbose.\n"));
+  fprintf(stderr, " -V,     --version            ");
+  fprintf(stderr, _("Show version information.\n"));
+  fprintf(stderr, " -h,     --help               ");
+  fprintf(stderr, _("Show this help message.\n"));
+
+  exit(0);
+}
+
+static void display_version( void ) {
+
+  fprintf(stderr, "%s version ", command_name );
+  fprintf(stderr, VERSION_ID "\n");
+  if ( is_player == FLAG_TRUE ) {
+    fprintf(stderr, "tiny RCP player");
+#ifdef HAVE_STED2_SUPPORT
+    fprintf(stderr, " <STed2 support>");
+#endif
+    fprintf(stderr,"\n");
+  }
+  else
+    fprintf(stderr, "RCP to SMF converter\n");
+  fprintf(stderr, "Copyright 1999 by NAGANO Daisuke <breeze.nagano@nifty.ne.jp>\n");
+  fprintf(stderr, "\n");
+  fprintf(stderr, "This is free software; see the source for copying conditions.\n");
+  fprintf(stderr, "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n");
+  fprintf(stderr, "PARTICULAR PURPOSE.\n\n");
+
+  exit(0);
+}
diff --git a/rcpdef.h b/rcpdef.h
new file mode 100644 (file)
index 0000000..a9ed51d
--- /dev/null
+++ b/rcpdef.h
@@ -0,0 +1,143 @@
+#pragma once
+
+/************************/
+/* Constant definitions */
+/************************/
+
+#define uchar unsigned char
+
+#define Y_OFT  10
+#define X_TRK  1
+#define X_CH   4
+#define X_BAR  6
+#define X_STP  10
+#define X_VEL  16
+#define X_VOL  21
+#define X_EXP  26
+#define X_PAN  32
+#define X_PBEND        36
+#define X_PRG  42
+#define        X_NAME  46
+#define X_BANK 59
+#define X_MODU 63
+#define X_GSREV        69
+#define X_GSCHO        75
+#define X_GSDLY        81
+#define X_MEMO 59
+#define X_STS  78
+#define X_TRBAR        85
+
+/**************************/
+/*  structure definitions */
+/**************************/
+
+/* MCP data */
+struct MCPDATA {
+  struct {
+    char       mark[2];        /* 'M1' mark   */
+    char       name[30];       /* Song Name   */
+    char       tmbase;         /* Time base   */
+    char       tempo;          /* Tempo       */
+    char       rhythm0;        /* Rhythm ハャサメ */
+    char       rhythm1;        /* Rhythm ハャハ・*/
+    char       volume;         /* Volume      */
+    char       d1[27];         /*             */
+    char       midich[9];      /* MIDI ch 1-R */
+    char       d2[23];         /*             */
+    char       mtdname[6];     /* MTD name    */
+    char       mtdext[3];      /* MTD ext     */
+    char       d3[7];          /*             */
+    char       trname[9][16];  /* Track name  */
+  } hd;
+  char dt[1];
+};
+
+/* RCP data */
+struct rset {
+  char name[14];       /* rhythm name */
+  uchar        note;           /* note no     */
+  uchar        gate;           /* gate        */
+};
+
+struct RCPDATA {
+  struct {
+    char               mark[32];       /* COME ON ....*/
+    char               name[64];       /* Song Name   */
+    char               memo[12][28];   /* memorandam  */
+    char               x40[16];        /* 0x40 .......*/
+    uchar              tmbase;         /* Time base   */
+    uchar              tempo;          /* Tempo       */
+    uchar              rhythm0;        /* Rhythm ハャサメ */
+    uchar              rhythm1;        /* Rhythm ハャハ・*/
+    uchar              key;            /* key         */
+    uchar              play_bias;      /* play bias   */
+    char               cm6name[12];    /* CM6 name    */
+    char               x00[4];         /* 0x00        */
+    char               gsdname[12];    /* GSD name    */
+    char               x00b[4];        /* 0x00        */
+    uchar              trkmax;         /* track max   */
+    uchar              tmbase_h;       /* Time base h */
+    char               x00c[30];       /* 0x00        */
+    struct rset        rhythm[32];     /* rhythm      */
+    uchar              exclu[8][48];   /* イサクサタ゚ト・   */
+  } hd;
+  char dt[1];
+};
+
+struct track_head {
+  uchar        sizel;          /* track size Low */
+  uchar        sizeh;          /* track size High */
+  uchar        trk;            /* track no. */
+  uchar        rhythm_flag;    /* rhythm flag */
+  uchar        channel;        /* channel no. */
+  uchar        key;            /* key#+ */
+  uchar        st;             /* st+ */
+  uchar        mode;           /* mode */
+  char comment[36];    /* track comment */
+};
+
+/* G36 data *//* フ、サネヘム */
+struct G36DATA {
+  struct {
+    char               mark[32];       /* COME ON ....*/
+    char               name[128];      /* Song Name   */
+    char               memo[12][30];   /* memorandam  */
+    char               trkmax;         /* track max   */
+    char               x00[1];         /* 0x00 .......*/
+    uchar              tmbase;         /* Time base   */
+    uchar              tmbase_h;       /* Time base h */
+    uchar              tempo;          /* Tempo       */
+    uchar              tempo_h;        /* Tempo       */
+    uchar              rhythm0;        /* Rhythm ハャサメ */
+    uchar              rhythm1;        /* Rhythm ハャハ・*/
+    uchar              key;            /* key         */
+    uchar              play_bias;      /* play bias   */
+    char               x00b[6];        /* 0x00 .......*/
+    char               x40[16];        /* 0x40 .......*/
+    char               x00c[112];      /* 0x00 .......*/
+    char               cm6name[12];    /* CM6 name    */
+    char               x00d[4];        /* 0x00        */
+    char               gsdname[12];    /* GSD name    */
+    char               x00e[4];        /* 0x00        */
+    char               gsdname2[12];   /* GSD name2   */
+    char               x00f[4];        /* 0x00        */
+    char               x00g[80];       /* 0x00        */
+    struct rset        rhythm[128];    /* rhythm      */
+    char               exclu[8][48];   /* イサクサタ゚ト・   */
+  } hd;
+  char dt[1];
+};
+
+struct G36track_head {
+  uchar        sizel;          /* track size Low */
+  uchar        sizeh;          /* track size High */
+  uchar        sizeh2;         /* track size High2 */
+  uchar        sizeh3;         /* track size High3 */
+  uchar        trk;            /* track no. */
+  uchar        rhythm_flag;    /* rhythm flag */
+  uchar        channel;        /* channel no. */
+  uchar        key;            /* key#+ */
+  uchar        st;             /* st+ */
+  uchar        mode;           /* mode */
+  char comment[36];    /* track comment */
+};
diff --git a/rcpfile.cpp b/rcpfile.cpp
new file mode 100644 (file)
index 0000000..7af1496
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+  RCP converter
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.05.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#else
+# ifdef HAVE_STRCHR
+#  define strchr index
+#  define strrchr rindex
+# endif
+#endif
+
+#include <sys/stat.h>
+
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include "rcp.h"
+
+/* ------------------------------------------------------------------- */
+
+RCP_DATA *rcp_read_file( char *name ) {
+
+  FILE *fp;
+  struct stat stt;
+  RCP_DATA *rcp;
+  unsigned char *n;
+  int s;
+
+  /* data read */
+
+  rcp = (RCP_DATA *)malloc(sizeof(RCP_DATA));
+  if ( rcp == NULL ) return NULL;
+
+  if ( stat( name, &stt ) ) return NULL;
+  fp = fopen( name, "r" );
+  if ( fp == NULL ) return NULL;
+
+  rcp->length = stt.st_size;
+  rcp->data = (unsigned char *)malloc(sizeof(unsigned char)*rcp->length);
+  fread( rcp->data, 1, rcp->length, fp );
+
+  n = (uint8*)ctime(&(stt.st_mtime));
+  s = strlen((char*)n)+4;
+  rcp->date = (unsigned char *)malloc(sizeof(unsigned char)*s);
+  strcpy( (char*)rcp->date, (char*)n );
+  n = (uint8*)strrchr( (char*)rcp->date, '\n' );
+  if ( n != NULL ) *n = '\0';
+
+  fclose(fp);
+
+  n = (uint8*)strrchr( name, '/' );
+  if ( n == NULL ) n = (uint8*)name-1;
+  n++;
+  s = strlen((char*)n)+4;
+  rcp->file_name = (unsigned char *)malloc(sizeof(unsigned char)*s);
+  strcpy( (char*)rcp->file_name, (char*)n );
+
+  return rcp;
+}
+
+int rcp_close( RCP_DATA *rcp ) {
+
+  if ( rcp == NULL ) return 0;
+  if ( rcp->date != NULL ) free(rcp->date);    /* time stamp */
+  if ( rcp->data != NULL ) free(rcp->data);    /* RCP data */
+  if ( rcp->file_name != NULL ) free(rcp->file_name);
+
+  free(rcp);
+  rcp=NULL;
+
+  return 0;
+}
diff --git a/rcpfile.h b/rcpfile.h
new file mode 100644 (file)
index 0000000..8cd6add
--- /dev/null
+++ b/rcpfile.h
@@ -0,0 +1,119 @@
+#pragma once
+
+/***********************/
+/* define for RCP file */
+/***********************/
+
+#include "rcpstruct.h"
+
+static struct RCPHEAD RCP_HEAD = {
+/* mark */
+0x52,0x43,0x4D,0x2D,0x50,0x43,0x39,0x38,0x56,0x32,0x2E,0x30,0x28,0x43,0x29,0x43,
+0x4F,0x4D,0x45,0x20,0x4F,0x4E,0x20,0x4D,0x55,0x53,0x49,0x43,0x0D,0x0A,0x00,0x00,
+/* title */
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+/* memo */
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+/* MIDI bus mode */
+0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
+/* misc */
+0x00,0x00,0x00,0x00,0x00,0x00,
+
+/* CM6/GSD name */
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+/* RHYTHM */
+0x48,0x61,0x6E,0x64,0x20,0x43,0x6C,0x61,0x70,0x20,0x20,0x20,0x20,0x20,0x27,0x01,
+0x4D,0x74,0x20,0x48,0x69,0x43,0x6F,0x6E,0x67,0x61,0x20,0x20,0x20,0x20,0x3E,0x01,
+0x48,0x69,0x67,0x68,0x20,0x43,0x6F,0x6E,0x67,0x61,0x20,0x20,0x20,0x20,0x3F,0x01,
+0x4C,0x6F,0x77,0x20,0x43,0x6F,0x6E,0x67,0x61,0x20,0x20,0x20,0x20,0x20,0x40,0x01,
+0x43,0x72,0x61,0x73,0x68,0x20,0x43,0x79,0x6D,0x20,0x20,0x20,0x20,0x20,0x31,0x01,
+0x52,0x69,0x64,0x65,0x20,0x43,0x79,0x6D,0x20,0x20,0x20,0x20,0x20,0x20,0x33,0x01,
+0x4F,0x70,0x65,0x6E,0x48,0x69,0x48,0x61,0x74,0x32,0x20,0x20,0x20,0x20,0x2C,0x01,
+0x4F,0x70,0x65,0x6E,0x48,0x69,0x48,0x61,0x74,0x31,0x20,0x20,0x20,0x20,0x2E,0x01,
+0x43,0x6C,0x73,0x64,0x20,0x48,0x69,0x48,0x61,0x74,0x20,0x20,0x20,0x20,0x2A,0x01,
+0x41,0x63,0x6F,0x75,0x20,0x48,0x69,0x54,0x6F,0x6D,0x20,0x20,0x20,0x20,0x30,0x01,
+0x41,0x63,0x6F,0x75,0x4D,0x69,0x64,0x54,0x6F,0x6D,0x20,0x20,0x20,0x20,0x2D,0x01,
+0x41,0x63,0x6F,0x75,0x4C,0x6F,0x77,0x54,0x6F,0x6D,0x20,0x20,0x20,0x20,0x29,0x01,
+0x52,0x69,0x6D,0x20,0x53,0x68,0x6F,0x74,0x20,0x20,0x20,0x20,0x20,0x20,0x25,0x01,
+0x45,0x6C,0x65,0x63,0x20,0x53,0x44,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x28,0x01,
+0x41,0x63,0x6F,0x75,0x20,0x53,0x44,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x26,0x01,
+0x41,0x63,0x6F,0x75,0x20,0x42,0x44,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x24,0x01,
+0x48,0x69,0x20,0x54,0x69,0x6D,0x62,0x61,0x6C,0x65,0x20,0x20,0x20,0x20,0x41,0x01,
+0x4C,0x6F,0x77,0x54,0x69,0x6D,0x62,0x61,0x6C,0x65,0x20,0x20,0x20,0x20,0x42,0x01,
+0x43,0x6F,0x77,0x62,0x65,0x6C,0x6C,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x38,0x01,
+0x48,0x69,0x67,0x68,0x20,0x42,0x6F,0x6E,0x67,0x6F,0x20,0x20,0x20,0x20,0x3C,0x01,
+0x4C,0x6F,0x77,0x20,0x42,0x6F,0x6E,0x67,0x6F,0x20,0x20,0x20,0x20,0x20,0x3D,0x01,
+0x48,0x69,0x67,0x68,0x20,0x41,0x67,0x6F,0x67,0x6F,0x20,0x20,0x20,0x20,0x43,0x01,
+0x4C,0x6F,0x77,0x20,0x41,0x67,0x6F,0x67,0x6F,0x20,0x20,0x20,0x20,0x20,0x44,0x01,
+0x54,0x61,0x6D,0x62,0x6F,0x75,0x72,0x69,0x6E,0x65,0x20,0x20,0x20,0x20,0x36,0x01,
+0x43,0x6C,0x61,0x76,0x65,0x73,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x4B,0x01,
+0x4D,0x61,0x72,0x61,0x63,0x61,0x73,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x46,0x01,
+0x53,0x6D,0x62,0x61,0x57,0x68,0x69,0x73,0x20,0x4C,0x20,0x20,0x20,0x20,0x48,0x01,
+0x53,0x6D,0x62,0x61,0x57,0x68,0x69,0x73,0x20,0x53,0x20,0x20,0x20,0x20,0x47,0x01,
+0x43,0x61,0x62,0x61,0x73,0x61,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x45,0x01,
+0x51,0x75,0x69,0x6A,0x61,0x64,0x61,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x49,0x01,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x01,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00,0x01,
+/* Exclusive define */
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,
+0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7,0xF7 
+};
+
+static struct RCPTRACK TRACK = {
+       0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
+
+       0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+       0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+       0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+       0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
+       0x20,0x20,0x20,0x20
+};
diff --git a/rcpplay.cpp b/rcpplay.cpp
new file mode 100644 (file)
index 0000000..9467dc9
--- /dev/null
@@ -0,0 +1,383 @@
+/*
+  RCP player engine
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.05.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#include "sted.h"
+#include "rcp.h"
+#include "smf.h"
+#include "rcp_functions.h"
+#include "mididev.h"
+#include "gettext_wrapper.h"
+#include "version.h"
+
+#ifndef timercmp
+# define       timercmp(tvp, uvp, cmp)\
+               ((tvp)->tv_sec cmp (uvp)->tv_sec ||\
+               (tvp)->tv_sec == (uvp)->tv_sec &&\
+               (tvp)->tv_usec cmp (uvp)->tv_usec)
+#endif
+
+/* ------------------------------------------------------------------- */
+
+#include "rcddef.h"
+//RCD_HEAD *rcd;
+int is_sted2_support = FLAG_TRUE;
+void (*sted2_md_put)( char );
+
+/* ------------------------------------------------------------------- */
+/* player's functions */
+
+int reset_mode  = 2;
+static int is_player_alive;
+
+inline long timerdiff( struct timeval *st, struct timeval *et ) {
+  long reth, retl;
+  retl = st->tv_usec - et->tv_usec;
+  reth = st->tv_sec - et->tv_sec;
+  if ( retl < 0 ) {
+    reth--;
+    retl+=(1000*1000);
+  }
+  return (reth*1000*1000)+retl;
+}
+
+static int
+gettimeofday(struct timeval* st, void *dummy)
+{
+       DWORD time = timeGetTime();
+       st->tv_usec = (time%1000)*1000;
+       st->tv_sec = time/1000;
+
+       return 0;
+}
+
+/* ------------------------------------------------------------------- */
+/* accessor */
+
+int
+rcpplay_start(RCP_DATA* in_rcp)
+{
+       int trk;
+       struct timeval st;
+
+       if ( rcptomid_init_track_buffer( in_rcp ) != 0 ) return 1;
+       if ( rcptomid_read_rcp_header( in_rcp )   != 0 ) return 1;
+
+       /* prepare for STed2 support */
+       sted2_init( in_rcp );
+
+       /* start playing */
+
+       sayleen_send_midi_reset();
+       sayleen_myusleep( 50 * 1000 );
+
+       rcd->stepcount = 0;
+       rcd->act = 1;
+       rcd->sts = 0;
+       for ( trk=0 ; trk < TRK_NUM ; trk++ ) {
+               rcd->step[trk]=-1;
+               rcd->bar[trk]=-1;
+       }
+
+       if ( in_rcp->is_send_rtm == FLAG_TRUE ) {
+               sayleen_send_rtm_start();
+       }
+       in_rcp->rtm_delta = in_rcp->timebase / 24;
+       is_player_alive = FLAG_TRUE;
+
+       in_rcp->rcd = (void *)rcd;
+
+       gettimeofday(&st, NULL);
+       in_rcp->timer_sec = st.tv_sec;
+       in_rcp->timer_usec = st.tv_usec;
+
+       start_timer(50*1000, in_rcp);
+
+       return 0;
+}
+
+int
+rcpplay_stop(void)
+{
+       stop_timer();
+       sayleen_send_rtm_stop();
+       sayleen_send_midi_reset();
+       return 0;
+}
+
+int
+rcpplay_close(void)
+{
+       sted2_close();
+       return 0;
+}
+
+
+/* RCP player engine */
+int
+rcpplay( RCP_DATA *rcp )
+{
+       struct timeval st, et;
+       long s;
+       int trk;
+       struct RCD_HEAD *rcd;
+       int is_all_tracks_finished;
+
+       if (!rcp) return -1;
+
+       rcd = (struct RCD_HEAD *)rcp->rcd;
+
+       st.tv_sec = rcp->timer_sec;
+       st.tv_usec = rcp->timer_usec;
+
+       while(1) {
+               int track;
+
+               is_all_tracks_finished = FLAG_TRUE;
+
+               rcp->step++;
+
+               rcd->stepcount++;
+               for ( trk=0 ; trk < TRK_NUM ; trk++ ) {
+                       rcd->step[trk]=-1;
+                       rcd->bar[trk]=-1;
+               }
+
+               for ( track=0 ; track < rcp->tracks ; track++ ) {
+                       int n;
+
+                       /* Have the track finished ? */
+                       if ( rcp->track[track].finished == FLAG_TRUE &&
+                               rcp->track[track].all_notes_expired == FLAG_TRUE )
+                               continue;
+
+                       is_all_tracks_finished = FLAG_FALSE;
+
+                       /* checks each notes whether the gate time is expired */
+                       if ( rcp->track[track].all_notes_expired == FLAG_FALSE ) {
+                               for ( n = rcp->track[track].notes_min ;
+                                       n <=rcp->track[track].notes_max ; n++ ) {
+                                       int gate = rcp->track[track].notes[n];
+                                       gate--;
+                                       if ( gate == 0 ) {
+                                               rcp_note_off( rcp, track, n );
+                                               put_event( rcp, track );
+                                       }
+                                       if ( gate <  0 ) gate = 0;
+                                       rcp->track[track].notes[n] = gate;
+                                       }
+                       }
+
+                       /* checks whether the step time is expired */
+                       rcp->track[track].delta_step++;
+                       rcp->track[track].total_step++;
+                       rcp->track[track].step--;
+                       while ( rcp->track[track].step == 0 ) {
+                               if ( rcp->track[track].finished == FLAG_TRUE ) break;
+                               rcptomid_set_new_event( rcp, track );
+                               put_event( rcp, track );
+                       }
+               }
+               if ( is_all_tracks_finished == FLAG_TRUE ) break;
+
+
+               /* wait a delta time */
+
+               st.tv_usec += 1000 * 1000 * 60 / (rcp->realtempo * rcp->timebase);
+               while ( st.tv_usec >= 1000*1000 ) {
+                       st.tv_usec-=1000*1000;
+                       st.tv_sec++;
+               }
+
+               rcp->rtm_delta--;
+               if ( rcp->rtm_delta <= 0 ) {
+                       if ( rcp->is_send_rtm == FLAG_TRUE ) {
+                               sayleen_send_rtm_timingclock();
+                       }
+                       rcp->rtm_delta = rcp->timebase / 24;
+               }
+
+               sayleen_flush_midi();
+               gettimeofday( &et, NULL );
+               s = timerdiff( &st, &et );
+               if ( s > 1*1000 ) {
+                       rcp->timer_sec = st.tv_sec;
+                       rcp->timer_usec = st.tv_usec;
+                       start_timer(s, rcp);
+                       return 0;
+               }
+
+               if ( et.tv_sec - st.tv_sec > 1 ) {
+                       st.tv_sec  = et.tv_sec;
+                       st.tv_usec = et.tv_usec;
+               }
+       }
+
+
+       if ( rcp->is_send_rtm == FLAG_TRUE && is_all_tracks_finished == FLAG_TRUE) {
+               sayleen_send_rtm_stop();
+               rcd->act = 0;
+               sted2_close();
+       }
+
+       return 0;
+}
+
+static void CALLBACK
+timerproc(UINT in_id, UINT in_msg, DWORD in_dwUser, DWORD in_dw1, DWORD in_dw2)
+{
+       RCP_DATA* rcp = (RCP_DATA *)in_dwUser;
+       rcpplay(rcp);
+}
+
+static UINT timer_id = 0;
+
+static void
+start_timer(int in_interval, RCP_DATA* in_rcp)
+{
+       timer_id = timeSetEvent(in_interval/1000, 0, (LPTIMECALLBACK)&timerproc, (DWORD)in_rcp, TIME_ONESHOT);
+}
+
+static void
+stop_timer(void)
+{
+       if (timer_id>0) {
+               timeKillEvent(timer_id);
+               timer_id = 0;
+       }
+}
+
+/* ------------------------------------------------------------------- */
+
+#if 0
+RETSIGTYPE sigexit( int num ) {
+  sted2_close();
+
+  sayleen_send_rtm_stop();
+  send_midi_reset();
+  close_midi_device();
+
+  fprintf(stderr,"Signal caught : %d\n", num);
+  exit(1);
+}
+#endif
+
+/* ------------------------------------------------------------------- */
+static int sted2_init ( RCP_DATA *rcp ) {
+
+  sted2_md_put = NULL;
+
+  is_sted2_support = FLAG_TRUE;
+  /*sted2_md_put = rcd->md_put;*/
+
+  return FLAG_TRUE;
+}
+
+static int sted2_close( void ) {
+
+  return 0;
+}
+
+/* ------------------------------------------------------------------- */
+static int put_event( RCP_DATA *rcp, int track ) {
+
+  int i;
+  static int current_port = -1;
+
+  if ( rcp->result_smf[0] == SMF_TERM ) return 0;
+
+  /* is the track disabled ? */
+  if ( rcp->track[track].enabled == FLAG_FALSE && 
+       rcp->result_smf[0] != MIDI_NOTEOFF ) {
+    goto put_event_end;
+  }
+  
+  if ( rcp->result_smf[0] == MIDI_META ) {
+    switch( rcp->result_smf[1] ) {
+    case META_PORT:
+      break;
+
+    case META_TEXT:
+    case META_SEQNUM:
+    case META_COPYRIGHT:
+    case META_SEQNAME:
+    case META_INSTNAME:
+    case META_LYRIC:
+      if ( rcp->enable_verbose == FLAG_TRUE ) {
+       i=2;
+       while( rcp->result_smf[i++] >= 0x80 ) {};
+       while( rcp->result_smf[i] != SMF_TERM ) {
+         fprintf(stderr,"%c",rcp->result_smf[i++]);
+       }
+       fprintf(stderr,"\n");
+      }
+      break;
+
+    default:
+      break;
+    }
+    goto put_event_end;
+  }
+
+  /* flushing MIDI data */
+  
+  if ( rcp->track[track].delta_step < 0 ) {
+    fprintf(stderr,"%d\n",(int)rcp->track[track].delta_step);
+  }
+
+  if ( current_port != rcp->track[track].port ) {
+    sayleen_change_midi_port( rcp->track[track].port );
+    current_port = rcp->track[track].port;
+  }
+
+  i=0;
+  if ( rcp->result_smf[0] == 0xf0 || rcp->result_smf[0] == 0xf7 ) {
+    sayleen_put_midi(rcp->result_smf[0]);
+    i=2;
+  }
+  while ( rcp->result_smf[i] != SMF_TERM ) {
+    sayleen_put_midi(rcp->result_smf[i]);
+    i++;
+  }
+
+  rcp->track[track].delta_step = 0;
+  
+put_event_end:
+  rcp->result_smf[0] = SMF_TERM;
+
+  return 0;
+}
diff --git a/rcpstruct.h b/rcpstruct.h
new file mode 100644 (file)
index 0000000..75fb2cf
--- /dev/null
@@ -0,0 +1,36 @@
+#pragma once
+/* struct definition for RCP file */
+#define uchar unsigned char
+
+struct RCPHEAD {
+       uchar mark[32];
+       uchar title[64];
+       uchar memo[336];
+       uchar MIDI_busmode[16];
+       uchar Timebase;
+       uchar Tempo;
+       uchar Beathigh;
+       uchar Beatlow;
+       uchar Key;
+       uchar Playbias;
+       uchar CM6name[16];
+       uchar GSDname[16];
+       uchar trkmax;
+       uchar Timebaseh;
+       uchar dumy[30];
+       uchar Rhythm[32][16];
+       uchar Exclusive[8][48];
+};
+
+struct RCPTRACK {
+       uchar len_low;
+       uchar len_high;
+       uchar track_no;
+       uchar rhythm_flag;
+       uchar MIDI_CH;
+       uchar Play_bias;
+       uchar ST_offset;
+       uchar Mode;
+       uchar Memo[36];
+/*     uchar note[65536]; */
+};
diff --git a/rcptomid.cpp b/rcptomid.cpp
new file mode 100644 (file)
index 0000000..d75bc22
--- /dev/null
@@ -0,0 +1,1032 @@
+/*
+  RCP converter engine
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.05.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#else
+# ifdef HAVE_STRCHR
+#  define strchr index
+#  define strrchr rindex
+# endif
+#endif
+
+#include "sted.h"
+#include "rcp.h"
+#include "smf.h"
+#include "rcp_functions.h"
+#include "gettext_wrapper.h"
+#include "version.h"
+
+/* ------------------------------------------------------------------- */
+
+static unsigned char *rcptomid_name      = (uint8*)"rcptomid";
+static unsigned char *undefined_date     = (uint8*)"2000-01-01";
+static unsigned char *undefined_filename = (uint8*)"(NO NAME)";
+
+/* ------------------------------------------------------------------- */
+
+#ifdef RCP_DEBUG
+# define RCPMSG(x,y) fprintf(stderr,x,y)
+#else
+# define RCPMSG(x,y)
+#endif
+
+
+typedef struct _TEMPO_EVENT_SEQUENCE {
+
+  int absolute_step;
+  int t1;
+  int t2;
+  int t3;
+
+  struct _TEMPO_EVENT_SEQUENCE *next;
+
+} TEMPO_EVENT_SEQUENCE;
+
+/* ------------------------------------------------------------------- */
+
+static TEMPO_EVENT_SEQUENCE *TES_top = (TEMPO_EVENT_SEQUENCE *)NULL;
+
+/* ------------------------------------------------------------------- */
+
+/* Converter engine */
+
+unsigned char *rcptomid( RCP_DATA *rcp ) {
+
+  unsigned char *smf;
+  int track;
+
+  int gate_min;
+  int n,nt;
+  int s;
+
+  if ( rcptomid_init_track_buffer( rcp ) != 0 ) return NULL;
+  if ( rcptomid_read_rcp_header( rcp )   != 0 ) return NULL;
+
+  for ( track = 0 ; track < rcp->tracks ; track++ ) {
+    rcp->roland_dev_id   = 0x10;
+    rcp->roland_model_id = 0x16;
+    rcp->yamaha_dev_id   = 0x10;
+    rcp->yamaha_model_id = 0x16;
+    
+    rcp->step            = 0;
+
+    init_track_header( rcp, track );
+    rcp->result_smf[0]   = SMF_TERM;
+
+    while ( rcp->track[track].finished == FLAG_FALSE ) {
+
+      if ( rcp->track[track].all_notes_expired == FLAG_TRUE )
+       goto rcptomid_expire_event;
+      
+      /* checks for each notes' gate time is expired */
+      gate_min = rcp->track[track].step;
+      nt = -1;
+      for ( n = rcp->track[track].notes_min ;
+           n <= rcp->track[track].notes_max ; n++ ) {
+       if ( rcp->track[track].notes[n] == 0 ) continue;
+       if ( rcp->track[track].notes[n] <= gate_min ) {
+         gate_min = rcp->track[track].notes[n];
+         nt = n;
+       }
+      }
+      if ( nt < 0 ) goto rcptomid_expire_event;
+
+      /* note-off */
+      rcp->step += gate_min;
+      rcp->track[track].delta_step += gate_min;
+      rcp->track[track].total_step += gate_min;
+      rcp->track[track].step -= gate_min;
+      for ( n = rcp->track[track].notes_min ;
+           n <=rcp->track[track].notes_max ; n++ ) {
+       if ( rcp->track[track].notes[n] == gate_min ) {
+         rcp_note_off( rcp, track, n );
+         flush_event( rcp, track );
+       }
+       rcp->track[track].notes[n] -= gate_min;
+       if ( rcp->track[track].notes[n] < 0 ) {
+         rcp->track[track].notes[n] = 0;
+       }
+      }
+      continue;
+
+      /* checks for step time is expired */
+
+    rcptomid_expire_event:
+
+      s = rcp->track[track].step;
+      rcp->step += s;
+      rcp->track[track].delta_step += s;
+      rcp->track[track].total_step += s;
+      rcp->track[track].step = 0;
+      for ( n = rcp->track[track].notes_min ; 
+           n <=rcp->track[track].notes_max ; n++ ) {
+       rcp->track[track].notes[n] -= s;
+       if ( rcp->track[track].notes[n] < 0 ) {
+         rcp->track[track].notes[n] = 0;
+       }
+      }
+      while ( rcp->track[track].step == 0 ) {
+       rcptomid_set_new_event( rcp, track );
+       if ( rcp->track[track].finished == FLAG_FALSE )
+         flush_event( rcp, track );
+       else break;
+      }
+    }
+
+    while ( 1 ) {
+      gate_min = 65536*2; /* large enough */
+      for ( n=0 ; n<RCP_MAX_NOTES ; n++ ) {
+       if ( rcp->track[track].notes[n] <= 0 ) continue;
+       if ( rcp->track[track].notes[n] <= gate_min ) {
+         gate_min = rcp->track[track].notes[n];
+       }
+      }
+      if ( gate_min == 65536*2 ) break;
+      for ( n=0 ; n<RCP_MAX_NOTES ; n++ ) {
+       if ( rcp->track[track].notes[n] == gate_min ) {
+         rcp_note_off( rcp, track, n );
+         flush_event( rcp, track );
+       }
+       rcp->track[track].notes[n]-=gate_min;
+       if ( rcp->track[track].notes[n] < 0 )
+         rcp->track[track].notes[n] = 0;
+      }
+    }
+
+    rcp->result_smf[0] = MIDI_META;
+    rcp->result_smf[1] = META_EOT;
+    rcp->result_smf[2] = 0;
+    rcp->result_smf[3] = SMF_TERM;
+    flush_event( rcp, track );
+  }
+
+  /* set up first / tempo track */
+  set_tempo_track( rcp );
+
+  /* create SMF data */
+  smf = set_smf_data( rcp );
+  
+  return smf;
+}
+
+/* ------------------------------------------------------------------- */
+
+int rcptomid_init_track_buffer( RCP_DATA *rcp ) {
+
+  int track,n;
+
+  rcp->roland_dev_id   = 0x10;
+  rcp->roland_model_id = 0x16;
+  rcp->yamaha_dev_id   = 0x10;
+  rcp->yamaha_model_id = 0x16;
+
+  rcp->step            = -1;
+  rcp->result_smf[0]   = SMF_TERM;
+
+  for ( track=0 ; track<RCP_MAX_TRACKS ; track++ ) {
+    rcp->track[track].enabled    = FLAG_FALSE;
+    rcp->track[track].finished   = FLAG_FALSE;
+
+    rcp->track[track].gate       = 0;
+    rcp->track[track].step       = 1;
+    rcp->track[track].delta_step = -1;   /* initial value should be -1 */
+    rcp->track[track].total_step = -1;
+
+    rcp->track[track].yamaha_base[0]  = -1; /* not specified */
+    rcp->track[track].roland_base[0]  = -1; /* not specified */
+
+    rcp->track[track].loop_depth      = 0;
+    rcp->track[track].same_measure_flag = FLAG_FALSE;
+
+    rcp->track[track].current_ptr     = 0;
+
+    for ( n=0 ; n<RCP_MAX_NOTES ; n++ )
+      rcp->track[track].notes[n] = 0;
+    rcp->track[track].notes_min = 127;
+    rcp->track[track].notes_max = 0;
+    rcp->track[track].all_notes_expired = FLAG_TRUE;
+
+    rcp->track[track].smf =
+      (unsigned char *)malloc(sizeof(unsigned char)*RCP_DEFAULT_SMF_SIZE);
+    if ( rcp->track[track].smf == NULL ) {
+      /* Memory exhaust */
+      return 1;
+    }
+    rcp->track[track].smf_ptr   = 0;
+  }
+
+  TES_top = (TEMPO_EVENT_SEQUENCE *)malloc(sizeof(TEMPO_EVENT_SEQUENCE));
+  if ( TES_top == (TEMPO_EVENT_SEQUENCE *)NULL ) {
+    /* Memory exhaust */
+    return 1;
+  }
+  TES_top->absolute_step = 0;    /* Initial value */
+  TES_top->next = NULL;
+
+  rcp->smf_tempo_track = (unsigned char *)malloc(sizeof(unsigned char)*RCP_DEFAULT_SMF_SIZE);
+  if ( rcp->smf_tempo_track == (unsigned char *)NULL ) {
+    /* Memory exhaust */
+    return 1;
+  }
+  rcp->smf_tempo_track_ptr = 0;
+
+  return 0;
+}
+
+int rcptomid_read_rcp_header( RCP_DATA *rcp ) {
+
+  int i,j;
+  int t;
+  int base,size,max_st;
+  unsigned char *ptr;
+
+  ptr = rcp->data;
+
+  /* check 1st header */
+
+  if ( strncmp( (char*)ptr, RCP_HEADER_STRING, 28 ) ==0 ) {
+    rcp->rcp = FLAG_TRUE;
+    rcp->g36 = FLAG_FALSE;
+  } else if ( strncmp( (char*)ptr, STEDDATA_HEADER_STRING, 8 ) ==0 &&
+             strncmp( (char*)ptr+12, (char*)STEDDATA_HEADER_STRING+12, 16 ) ==0 ) {
+    rcp->steddata = FLAG_TRUE;
+    rcp->rcp = FLAG_TRUE;
+    rcp->g36 = FLAG_FALSE;
+  } else {
+    return -1;
+  }
+
+  /* title, memo */
+
+  for ( i=0 ; i<65 ; i++ )
+    rcp->title[i] = '\0';
+  for ( i=0 ; i<337 ; i++ )
+    rcp->memo[i] = '\0';
+  memcpy( rcp->title, ptr+0x0020, 64  );  /* It should be SJIS */
+  memcpy( rcp->memo,  ptr+0x0060, 336 );  /* It should be SJIS */
+
+  /* timebase, tempo, etc */
+
+  rcp->timebase  = ptr[0x01c0] + ptr[0x01e7]*256;
+  if ( rcp->timebase>480 || rcp->timebase<0 ) return 1;
+  rcp->tempo     = ptr[0x01c1];
+  rcp->realtempo = ptr[0x01c1];
+  rcp->beat_h    = ptr[0x01c2];
+  rcp->beat_l    = ptr[0x01c3];
+  rcp->key       = ptr[0x01c4];
+  rcp->play_bias = ptr[0x01c5];
+  rcp->rtm_delta = rcp->timebase / 24;
+
+  rcp->tracks   = ptr[0x01e6];
+  if ( rcp->tracks == 0 ) rcp->tracks = 18;
+  /*if ( rcp->tracks !=18 && rcp->tracks !=36 ) return 1;*/
+
+  t = 1000 * 1000 * 60 / rcp->tempo;
+  TES_top->t1 = (int)((t>>16)&0xff);
+  TES_top->t2 = (int)((t>> 8)&0xff);
+  TES_top->t3 = (int)(t&0xff);
+
+  RCPMSG("TITLE     : %s\n", rcp->title);
+  RCPMSG("MEMO      : %s\n", rcp->memo);
+  RCPMSG("TIMEBASE  : %d\n", rcp->timebase);
+  RCPMSG("TEMPO     : %d\n", rcp->tempo);
+  RCPMSG("BEAT_H    : %d\n", rcp->beat_h);
+  RCPMSG("BEAT_L    : %d\n", rcp->beat_l);
+  RCPMSG("KEY       : %d\n", rcp->key);
+  RCPMSG("PLAY BIAS : %d\n", rcp->play_bias);
+  RCPMSG("TRACKS    : %d\n\n", rcp->tracks);
+
+  /* user exclusive definition */
+
+  for ( i=0 ; i<RCP_MAX_USER_EXCLUSIVE ; i++ ) {
+    for ( j=0 ; j<RCP_USER_EXCLUSIVE_SIZE ; j++ ) {
+      rcp->user_exclusive[i][j] = ptr[0x0406 + i*48 + 24+j];
+    }
+  }
+
+  /* track headers */
+
+  base = 0x0586;
+  size = 0;
+  max_st = 0;
+  for ( t=0 ; t<rcp->tracks ; t++ ) {
+    int ch;
+
+    base = base + size;
+    rcp->track[t].top = base;
+
+    size = ptr[base+0] + ptr[base+1]*256;
+    rcp->track[t].size = size;
+
+    ch = ptr[base+4];
+    if ( ch == 0xff ) {
+      rcp->track[t].enabled = FLAG_FALSE;
+      rcp->track[t].midi_ch = 0;
+      rcp->track[t].port    = 0;
+    }
+    else {
+      rcp->track[t].enabled = FLAG_TRUE;
+      rcp->track[t].midi_ch = ch&0x0f;
+      if ( rcp->steddata ) {
+       rcp->track[t].port    = ch>>4&0x0f;
+      } else {
+       rcp->track[t].port  = ch>0x10 ? 1:0;
+      }
+    }
+
+    if ( ptr[base+5] >= 0x80 )
+      rcp->track[t].key     = 0x80;
+    else {
+      if ( ptr[base+5] > 63 ) 
+       rcp->track[t].key   = ptr[base+5]-128;
+      else
+       rcp->track[t].key   = ptr[base+5];
+    }
+    rcp->track[t].st        = ptr[base+6];
+    rcp->track[t].mode      = ptr[base+7];
+
+    i = (rcp->track[t].st > 0x7f) ? rcp->track[t].st-0x100:0;
+    if ( max_st > i ) max_st = i;
+
+    if ( rcp->track[t].mode == 1 )
+      rcp->track[t].enabled = FLAG_FALSE;
+
+    for ( j=0 ; j<RCP_MAX_COMMENT_SIZE ; j++ ) {
+      rcp->track[t].comment[j] = ptr[base+8+j];   /* It should be SJIS */
+    }
+
+    rcp->track[t].current_ptr = base+8+RCP_MAX_COMMENT_SIZE;
+
+    RCPMSG("Track   : %d\n", t);
+    RCPMSG("Base    : %d\n", rcp->track[t].top);
+    RCPMSG("Size    : %d\n", rcp->track[t].size);
+    RCPMSG("MIDI CH : %d\n", rcp->track[t].midi_ch);
+    RCPMSG("Key     : %d\n", rcp->track[t].key);
+    RCPMSG("ST      : %d\n", rcp->track[t].st);
+    RCPMSG("Mode    : %d\n", rcp->track[t].mode);
+    RCPMSG("Comment : %s\n\n", rcp->track[t].comment);
+  }
+
+  for ( t=0 ; t<rcp->tracks ; t++ ) {
+    i = rcp->track[t].st > 0x7f ? rcp->track[t].st - 0x100 : rcp->track[t].st;
+    rcp->track[t].step = 1+i-max_st;
+  }
+
+  return 0;
+}
+
+int init_track_header( RCP_DATA *rcp, int track ) {
+
+  int i,j;
+
+  if ( rcp->track[track].enabled == FLAG_FALSE ) return 0;
+
+  /* track memo */
+  i=0;
+  rcp->result_smf[i++] = MIDI_META;
+  rcp->result_smf[i++] = META_SEQNAME;
+  rcp->result_smf[i++] = RCP_MAX_COMMENT_SIZE;
+  for ( j=0 ; j<RCP_MAX_COMMENT_SIZE ; j++ ) {
+    unsigned char c = rcp->track[track].comment[j];
+    if ( c == 0 ) c = 0x20;
+    rcp->result_smf[i++] = c;
+  }
+
+#ifdef ENABLE_PORT_CHANGE
+  /* MIDI channel */
+  rcp->result_smf[i++] = 0; /* delta time = 0 */
+  rcp->result_smf[i++] = MIDI_META;
+  rcp->result_smf[i++] = META_PORT;
+  rcp->result_smf[i++] = 1;  /* one byte follow */
+  rcp->result_smf[i++] = rcp->track[track].port;
+#endif /* ENABLE_PORT_CHANGE */
+
+  rcp->result_smf[i++] = SMF_TERM;
+  rcp->track[track].delta_step = 0;
+  flush_event( rcp, track );
+
+  rcp->step = -1;
+  rcp->track[track].delta_step = -1;
+
+  return 0;
+}
+
+int rcptomid_set_new_event( RCP_DATA *rcp, int t ) {
+
+  int ptr;
+  unsigned char *data;
+  int ret;
+
+  ret = 0;
+  data = rcp->data;
+  ptr  = rcp->track[t].current_ptr;
+
+  if ( ptr > rcp->track[t].top + rcp->track[t].size ) {
+    rcp->track[t].finished = FLAG_TRUE;
+    return -1;
+  }
+
+  rcp->track[t].event = data[ptr+0];
+  rcp->track[t].step  = data[ptr+1];
+  rcp->track[t].gate  = data[ptr+2];
+  rcp->track[t].vel   = data[ptr+3];
+
+  /*
+  fprintf(stderr,"%d : %02x %d %d %d\n", t, 
+         rcp->track[t].event,
+         rcp->track[t].step,
+         rcp->track[t].gate,
+         rcp->track[t].vel );
+         */
+
+  if ( rcp->track[t].event < 0x80 ) {     /* note event */
+    rcp_note_on( rcp, t );
+  } else {
+    switch ( rcp->track[t].event ) {
+
+    case RCP_USER_EXCLUSIVE_1:
+    case RCP_USER_EXCLUSIVE_2:
+    case RCP_USER_EXCLUSIVE_3:
+    case RCP_USER_EXCLUSIVE_4:
+    case RCP_USER_EXCLUSIVE_5:
+    case RCP_USER_EXCLUSIVE_6:
+    case RCP_USER_EXCLUSIVE_7:
+    case RCP_USER_EXCLUSIVE_8:
+      rcp_user_exclusive( rcp, t );
+      break;
+
+    case RCP_CH_EXCLUSIVE:
+      rcp_ch_exclusive( rcp, t );
+      break;
+
+    case RCP_EXEC_EXTERN_PROG:
+      rcp_exec_extern_prog( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_BANK_AND_PROG:
+      rcp_bank_and_prog( rcp, t );
+      break;
+
+    case RCP_KEY_SCAN:
+      rcp_key_scan( rcp, t );
+      break;
+
+    case RCP_MIDI_CH_CHANGE:
+      rcp_midi_ch_change( rcp, t );
+      break;
+
+    case RCP_TEMPO_CHANGE:
+      rcp_tempo_change( rcp, t );
+      break;
+
+    case RCP_AFTER_TOUCH:
+      rcp_after_touch( rcp, t );
+      break;
+
+    case RCP_CONTROL_CHANGE:
+      rcp_control_change( rcp, t );
+      break;
+
+    case RCP_PROGRAM_CHANGE:
+      rcp_program_change( rcp, t );
+      break;
+
+    case RCP_AFTER_TOUCH_POLY:
+      rcp_after_touch_poly( rcp, t );
+      break;
+
+    case RCP_PITCH_BEND:
+      rcp_pitch_bend( rcp, t );
+      break;
+
+    case RCP_YAMAHA_BASE:
+      rcp_yamaha_base( rcp, t );
+      break;
+
+    case RCP_YAMAHA_DEV_NUM:
+      rcp_yamaha_dev_name( rcp, t );
+      break;
+
+    case RCP_YAMAHA_ADDR:
+      rcp_yamaha_addr( rcp, t );
+      break;
+
+    case RCP_YAMAHA_XG_AD:
+      rcp_yamaha_xg_ad( rcp, t );
+      break;
+
+    case RCP_ROLAND_BASE:
+      rcp_roland_base( rcp, t );
+      break;
+
+    case RCP_ROLAND_PARA:
+      rcp_roland_para( rcp, t );
+      break;
+
+    case RCP_ROLAND_DEV:     
+      rcp_roland_dev( rcp, t );
+      break;
+
+    case RCP_KEY_CHANGE:
+      rcp_key_change( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_COMMENT_START:
+      rcp_comment_start( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_LOOP_END:
+      rcp_loop_end( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_LOOP_START:
+      rcp_loop_start( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_SAME_MEASURE:
+      rcp_same_measure( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_MEASURE_END:
+      rcp_measure_end( rcp, t );
+      ret = 1;
+      break;
+
+    case RCP_END_OF_TRACK:
+      rcp_end_of_track( rcp, t );
+      ret=-1;
+      break;
+
+    case RCP_DX7_FUNCTION:
+      rcp_dx7_function( rcp, t );
+      break;
+
+    case RCP_DX_PARAMETER:
+      rcp_dx_parameter( rcp, t );
+      break;
+
+    case RCP_DX_RERF:
+      rcp_dx_rerf( rcp, t );
+      break;
+
+    case RCP_TX_FUNCTION:
+      rcp_tx_function( rcp, t );
+      break;
+
+    case RCP_FB01_PARAMETER:
+      rcp_fb01_parameter( rcp, t );
+      break;
+
+    case RCP_FB01_SYSTEM:
+      rcp_fb01_system( rcp, t );
+      break;
+
+    case RCP_TX81Z_VCED:
+      rcp_tx81z_vced( rcp, t );
+      break;
+
+    case RCP_TX81Z_ACED:
+      rcp_tx81z_aced( rcp, t );
+      break;
+
+    case RCP_TX81Z_PCED:
+      rcp_tx81z_pced( rcp, t );
+      break;
+
+    case RCP_TX81Z_SYSTEM:
+      rcp_tx81z_system( rcp, t );
+      break;
+
+    case RCP_TX81Z_EFFECT:
+      rcp_tx81z_effect( rcp, t );
+      break;
+
+    case RCP_DX7_2_REMOTE_SW:
+      rcp_dx7_2_remote_sw( rcp, t );
+      break;
+
+    case RCP_DX7_2_ACED:
+      rcp_dx7_2_aced( rcp, t );
+      break;
+
+    case RCP_DX7_2_PCED:
+      rcp_dx7_2_pced( rcp, t );
+      break;
+
+    case RCP_TX802_PCED:
+      rcp_tx802_pced( rcp, t );
+      break;
+
+    case RCP_MKS_7:
+      rcp_mks_7( rcp, t );
+      break;
+
+    case RCP_2ND_EVENT:
+      ret = 1;
+      break;
+
+    default:
+      ret=-1;
+      break;
+    }
+  }
+
+  if ( ret == 1 )
+    rcp->track[t].step = 0;
+
+  ptr=rcp->track[t].current_ptr;
+  ptr+=4;
+  if ( ptr >= rcp->track[t].top + rcp->track[t].size ||
+       ret == -1 ) {
+    rcp->track[t].finished = FLAG_TRUE;
+    rcp->track[t].step=-1;
+    ptr = -1;
+  }
+  rcp->track[t].current_ptr = ptr;
+
+  return  ret;
+}
+
+int flush_event( RCP_DATA *rcp, int track ) {
+
+  int i,*len;
+  int ptr;
+
+  if ( rcp->result_smf[0] == SMF_TERM ) return 0;
+
+  /* is the event set-tempo ? */
+  if ( rcp->result_smf[0] == MIDI_META &&
+       rcp->result_smf[1] == META_TEMPO ) {
+    
+    insert_tempo_event( rcp );
+    goto flush_event_end;
+  }
+  
+  /* is the track disabled ? */
+  if ( rcp->track[track].enabled == FLAG_FALSE && 
+       rcp->result_smf[0] != MIDI_NOTEOFF ) {
+    goto flush_event_end;
+  }
+  
+  /* flushing smf data */
+  i=0;
+  ptr = rcp->track[track].smf_ptr;
+  
+  if ( rcp->track[track].delta_step < 0 ) {
+    fprintf(stderr,"%d\n",(int)rcp->track[track].delta_step);
+  }
+
+  len = smf_number_conversion( rcp->track[track].delta_step );
+  do {
+    rcp->track[track].smf[ptr++] = len[i];
+    if ( (ptr % RCP_DEFAULT_SMF_SIZE) == 0 ) {
+      int size;
+      size = (1+ptr/RCP_DEFAULT_SMF_SIZE) * RCP_DEFAULT_SMF_SIZE;
+      if ( (rcp->track[track].smf = (uint8*)realloc( rcp->track[track].smf,
+                   sizeof(unsigned char)*size )) == (unsigned char *)NULL ) {
+       /* Memory exhaust */
+       return 1;
+      }
+    }
+  } while ( len[i++] >= 0x80 );
+  
+  i=0;
+  while ( rcp->result_smf[i] != SMF_TERM ) {
+    rcp->track[track].smf[ptr++] = rcp->result_smf[i++];
+    
+    if ( (ptr % RCP_DEFAULT_SMF_SIZE) == 0 ) {
+      int size;
+      size = (1+ptr/RCP_DEFAULT_SMF_SIZE) * RCP_DEFAULT_SMF_SIZE;
+      if ( (rcp->track[track].smf = (uint8*)realloc( rcp->track[track].smf,
+                   sizeof(unsigned char)*size )) == (unsigned char *)NULL ) {
+       /* Memory exhaust */
+       return 1;
+      }
+    }
+  }
+  rcp->track[track].smf_ptr = ptr;
+  rcp->track[track].delta_step = 0;
+  
+flush_event_end:
+  rcp->result_smf[0] = SMF_TERM;
+
+  return 0;
+}
+
+int insert_tempo_event( RCP_DATA *rcp ) {
+
+  TEMPO_EVENT_SEQUENCE *t, *t_last, *t_new;
+
+  t_new = (TEMPO_EVENT_SEQUENCE *)malloc(sizeof(TEMPO_EVENT_SEQUENCE));
+  if ( t_new == (TEMPO_EVENT_SEQUENCE *)NULL ) {
+    /* Memory exhaust */
+    return 1;
+  }
+  t_new->absolute_step = rcp->step;
+  t_new->t1            = rcp->result_smf[3];
+  t_new->t2            = rcp->result_smf[4];
+  t_new->t3            = rcp->result_smf[5];
+
+  t = TES_top;
+  t_last = TES_top;
+  while ( t != (TEMPO_EVENT_SEQUENCE *)NULL ) {
+    if ( t->absolute_step > t_new->absolute_step ) break;
+    
+    t_last = t;
+    t = t->next;
+  }
+  t_last->next = t_new;
+  t_new->next  = t;
+  
+  return 0;
+}
+
+int set_tempo_track ( RCP_DATA *rcp ) {
+
+  TEMPO_EVENT_SEQUENCE *t = TES_top, *tn;
+  int p;
+  int dt,*d;
+  int i,j,k;
+  unsigned char *data;
+  unsigned char buf[1024];
+
+  p = rcp->smf_tempo_track_ptr;
+  data = rcp->smf_tempo_track;
+
+  /* Track header */
+  /* Title */
+
+  data[p++] = 0;
+  data[p++] = MIDI_META;
+  data[p++] = META_SEQNAME;
+  for ( i=0 ; i<64 ; i++ ) {
+    unsigned char c = rcp->title[i];
+    if ( c == 0 ) break;
+  }
+  data[p++] = i;
+  for ( j=0 ; j<i ; j++ ) {
+    data[p++] = rcp->title[j];
+  }
+
+  /* Copyright notice */
+  if ( rcp->copyright != NULL ) {
+    data[p++] = 0;
+    data[p++] = MIDI_META;
+    data[p++] = META_COPYRIGHT;
+    i=0;
+    while ( rcp->copyright[i++] != 0 );
+    data[p++] = i;
+    for ( j=0 ; j<i ; j++ ) {
+      data[p++] = rcp->copyright[j];
+    }
+  }
+
+  /* converter notice */
+  if ( rcp->enable_converter_notice == FLAG_TRUE ) {
+    int *len;
+
+    sprintf( (char*)buf,"\nThis file was converted by %s version %s (%s - %s).\nOriginal RCP file is \"%s\" (%s, %d bytes).",
+            (rcp->command_name!=NULL)?rcp->command_name:rcptomid_name,
+            VERSION_ID, VERSION_TEXT1, VERSION_TEXT2,
+            (rcp->file_name!=NULL)?rcp->file_name:undefined_filename,
+            (rcp->date!=NULL)?rcp->date:undefined_date,
+            rcp->length );
+    
+    i=0;
+    while ( buf[i]!=0 ) i++;
+    
+    data[p++] = 0; /* delta time = 0 */
+    data[p++] = MIDI_META;
+    data[p++] = META_TEXT;
+
+    len = smf_number_conversion( i );
+    j=0;
+    do {
+      data[p++] = len[j];
+    } while ( len[j++] >= 0x80 );
+
+    for ( j=0 ; j<i ; j++ ) {
+      data[p++] = buf[j];
+    }
+  }
+
+  /* key */
+
+  j = rcp->key > 0x0f ? 1:0;
+  i = rcp->key%0x10;
+  if ( i > 0x07 ) i = (0x100-i)%0x100;
+
+  data[p++] = 0;
+  data[p++] = MIDI_META;
+  data[p++] = META_KEYSIG;
+  data[p++] = 0x02;
+  data[p++] = i;
+  data[p++] = j;
+
+  /* beat */
+
+#if 0
+  data[p++] = 0;
+  data[p++] = MIDI_META;
+  data[p++] = META_TIMESIG;
+  data[p++] = 0x04;
+  data[p++] = 0;
+  data[p++] = 0;
+  data[p++] = 0;
+  data[p++] = 0;
+#endif
+
+  /* Tempo */
+
+  dt = t->absolute_step;
+  while ( t != NULL ) {
+    k = p / RCP_DEFAULT_SMF_SIZE;
+
+    d = smf_number_conversion((long)dt);
+    i=0;
+    do {
+      data[p++] = d[i];
+    } while ( d[i++] >= 0x80 );
+
+    data[p++] = MIDI_META;
+    data[p++] = META_TEMPO;
+    data[p++] = 3;
+    data[p++] = t->t1;
+    data[p++] = t->t2;
+    data[p++] = t->t3;
+    if ( p > RCP_DEFAULT_SMF_SIZE*(k+1) ) {
+      int size;
+      size = (1+p/RCP_DEFAULT_SMF_SIZE) * RCP_DEFAULT_SMF_SIZE;
+      if ( (rcp->smf_tempo_track = (uint8*)realloc( rcp->smf_tempo_track,
+                   sizeof(unsigned char)*size )) == (unsigned char *)NULL ) {
+       /* Memory exhaust */
+       return 1;
+      }
+    }
+
+    if ( t->next != NULL )
+      dt = t->next->absolute_step - t->absolute_step;
+    t = t->next;
+  }
+
+  data[p++] = 0;
+  data[p++] = MIDI_META;
+  data[p++] = META_EOT;
+  data[p++] = 0;
+
+  rcp->smf_tempo_track_ptr = p;
+
+  t = TES_top;
+  while ( t != NULL ) {
+    tn = t;
+    t = t->next;
+    free(tn);
+  }
+  
+  return 0;
+}
+
+unsigned char *set_smf_data( RCP_DATA *rcp ) {
+
+  long smf_size;
+  unsigned char *smf_data;
+  int t,tr;
+  int ptr;
+  int i;
+  
+  /* Allocate memory for SMF data */
+
+  smf_size = SMF_MTHD_HEADER_SIZE +
+    4+rcp->smf_tempo_track_ptr;
+  tr=1;
+  for (t=0 ; t<rcp->tracks ; t++ ) {
+    if ( rcp->track[t].enabled == FLAG_TRUE ) {
+      smf_size += 4+rcp->track[t].smf_ptr + 256;
+      tr++;
+    }
+  }
+  if ( smf_size > 0xffffffffL ) return NULL;
+  smf_data = (unsigned char *)malloc(sizeof(unsigned char *) * smf_size);
+  if ( smf_data == (unsigned char *)NULL )
+    return NULL;
+
+  /* Set Header Chunk */
+
+  smf_data[0] = 'M';  /* Chunk type */
+  smf_data[1] = 'T';
+  smf_data[2] = 'h';
+  smf_data[3] = 'd';
+
+  smf_data[4] = 0;
+  smf_data[5] = 0;
+  smf_data[6] = 0;
+  smf_data[7] = 6;
+
+  smf_data[8] = 0;    /* Data format ( format 1 ) */
+  smf_data[9] = 1;
+
+  smf_data[10] = tr / 256;
+  smf_data[11] = tr % 256;
+
+  smf_data[12] = rcp->timebase / 256;
+  smf_data[13] = rcp->timebase % 256;
+
+  /* Set first Track Chunk ( tempo track ) */
+
+  ptr = 14;
+  smf_data[ptr++] = 'M';
+  smf_data[ptr++] = 'T';
+  smf_data[ptr++] = 'r';
+  smf_data[ptr++] = 'k';
+
+  smf_data[ptr++] = (rcp->smf_tempo_track_ptr>>24)&0xff;
+  smf_data[ptr++] = (rcp->smf_tempo_track_ptr>>16)&0xff;
+  smf_data[ptr++] = (rcp->smf_tempo_track_ptr>>8 )&0xff;
+  smf_data[ptr++] = (rcp->smf_tempo_track_ptr    )&0xff;
+
+  for ( i=0 ; i<rcp->smf_tempo_track_ptr ; i++ ) {
+    smf_data[ptr++] = rcp->smf_tempo_track[i];
+  }
+
+  /* Set all other Track Chunk ( Music track ) */
+
+  for ( t=0 ; t<rcp->tracks ; t++ ) {
+    if ( rcp->track[t].enabled == FLAG_FALSE ) continue;
+
+    smf_data[ptr++] = 'M';
+    smf_data[ptr++] = 'T';
+    smf_data[ptr++] = 'r';
+    smf_data[ptr++] = 'k';
+    
+    smf_data[ptr++] = (rcp->track[t].smf_ptr>>24)&0xff;
+    smf_data[ptr++] = (rcp->track[t].smf_ptr>>16)&0xff;
+    smf_data[ptr++] = (rcp->track[t].smf_ptr>>8 )&0xff;
+    smf_data[ptr++] = (rcp->track[t].smf_ptr    )&0xff;
+
+    for ( i=0 ; i<rcp->track[t].smf_ptr ; i++ ) {
+      smf_data[ptr++] = rcp->track[t].smf[i];
+    }
+  }
+
+  /* free all smf data */
+
+  free(rcp->smf_tempo_track);
+
+  for ( t=0 ; t<RCP_MAX_TRACKS ; t++ ) {
+    /*fprintf(stderr,"%d: %d\n", t, rcp->track[t].smf_ptr);*/
+    if ( rcp->track[t].smf != NULL )
+      free(rcp->track[t].smf);
+  }
+  rcp->smf_size = ptr;
+  rcp->smf_data = smf_data;
+
+#if 0
+  smf_data[4] = (rcp->smf_size / (256*256*256)) % 256; /* Data length */
+  smf_data[5] = (rcp->smf_size / (256*256)) % 256;
+  smf_data[6] = (rcp->smf_size / 256) % 256;
+  smf_data[7] = (rcp->smf_size) % 256;
+#endif  
+
+  return smf_data;
+}
+
diff --git a/record.cpp b/record.cpp
new file mode 100644 (file)
index 0000000..c82bdf8
--- /dev/null
@@ -0,0 +1,1180 @@
+/*************************************/
+/* real time recording subroutine    */
+/*************************************/
+
+#include "sted.h"
+
+unsigned char  *note, *note_data;
+int    trch,lastptr,pt,tr,len,cmd,d_byte;
+int    step,barlen,barunit,stepsum,midi_ch,exc_no,exc_id;
+int    nbuf[16], vbuf[16], gbuf[16];
+
+int    metoro_trk,metoro_sw,topmeas,recmeas,btmmeas,ecount_sw;
+
+
+
+/***************************/
+int    real_record()
+{
+  int  a,b,co=0,ad=0,stc,ost=0,bc,stm,mm,lastst,ecst;
+  int  i,ccc,dtr=0,pm,pr=0,ecount=0;
+  int  mtr_tempo=mtempo;
+  unsigned char        *mbuf;
+  unsigned char        ctrl_tbl[256];
+
+  for(i=0;i<128;i++){ctrl_tbl[i]=i;}
+  for(i=16;i<32;i++){
+    if(rfilt[i][0]!=rfilt[i][1]){
+      if(rfilt[i][0]<128 && rfilt[i][1]<128){
+       ctrl_tbl[rfilt[i][0]]=rfilt[i][1];
+      }
+    }
+  }
+
+  pm=rcd->put_mode;
+  cpleng=0;rcpf=0;
+  topmeas=1;recmeas=1;btmmeas=999;metoro_sw=0;ecount_sw=0;
+
+  note_data = cpbuf;note = note_data + 16;
+  for(i=0;i<16;i++){note_data[i] = 0xff;}
+  mbuf=rcpbuf;
+
+  barlen = tbase * 4 * beat1 / beat2;
+
+  ecst=tbase/24;
+  all_note_off(1);
+
+  fill(0,544,767,1001,0);
+rewrite:
+  box(0,564+4,767,564+128+2,14,65535);
+
+  box(0,564+128+6,767,564+128+6+26,14,65535);
+  box(0,564+128+6+30,767,1001,14,65535);
+
+  sdis(0,548+4," REALTIME RECORDING",20,15,8);home2(512);
+
+  C_WINDOW(0,32);
+
+  /*   B_LOCATE(2,31);B_PRINT("MIDI IN:");B_PRINT(mdinport());*/
+
+  B_LOCATE(2,31);B_PRINT("RECORDING CH.: 1   OUT MODE:THRU   METORO:ON   SYNC:INT");
+
+  B_LOCATE(76,31);B_PRINT(_("[ESC] to exit"));
+
+
+  B_LOCATE(23,12);B_PRINT("RECORD MEAS:   1- 999");
+
+  B_LOCATE(52,12);B_PRINT("TEMPO:");B_PRINT(fstr(mtr_tempo,3));
+  B_PRINT("   BEAT:");B_PRINT(fstr(beat1,2));B_PRINT(" /");B_PRINT(fstr(beat2,2));
+  B_PRINT("    Used Buffer:  0%");
+
+  /*   B_LOCATE(90-11,14);B_PRINT("Used Buffer:  0%");*/
+
+  /*   B_PRINT("   TIMEBASE:");B_PRINT(fstr(tbase,3));*/
+
+
+restart:
+  rec_ch_disp();
+  pr=countstart(0,topmeas);
+
+  mm=0;
+  for(i=0;i<36;i++){if(trmod[i]&2){mm++;}}
+  if(mm==0){msg(_("Recording track is not specified."));}
+
+  B_LOCATE(1,4);B_PRINT(_("Waiting for Recording ..."));
+
+  midi_clr();a=0;ccc=0;stm=0;
+
+  while(1){
+    key_midi_wait();
+    a=(*rcd->md_get)();if((a>127 && a<0xf7) || a==0xfa){stm=2;break;}
+
+    if( INPOUT(0xfe)!=0 ){
+      int k=INPOUT(0xff);
+      if(k==27){goto ext;}
+      if(k==13 || k==32){pr=countstart(1,topmeas);break;}
+      if(k=='c' || k=='C'){rec_ch_change(pm);}
+      if(k=='o' || k=='O'){rec_md_change();}
+      if(k=='m' || k=='M'){rec_mt_change(0);}
+      if(k=='y' || k=='Y'){rec_sy_change();}
+      if(k=='s' || k=='S'){rec_meas_change(0);goto restart;}
+      if(k=='f' || k=='F'){rec_filter(1);goto rewrite;}
+    }
+  }
+
+  B_LOCATE(11,4);B_PRINT("START       ");
+
+  if(metoro_trk>=0){dtr=metoro_trk;}
+
+  (*rcd->begin)();
+
+  rec_mt_change(1);rec_mt_change(1);
+
+  if(pr){co=pr;}
+
+  lastst=(btmmeas+1-(topmeas))*barlen+pr;
+
+  if(stm==0 && topmeas==1){
+    int cc,cc2;
+    B_LOCATE(1,6);B_PRINT("COUNT");
+
+    co=barlen*2;lastst+=co;cc2=co/10;
+    while(1){
+         key_midi_player_wait();
+      cc=rcd->stepcount;
+      B_LOCATE(9,6);B_PRINT(fstr((co-cc)/cc2,4));
+
+      if( INPOUT(0xfe)!=0 ){
+       int k=INPOUT(0xff);
+       if(k==27){(*rcd->end)();goto ext;}
+       if(k=='m' || k=='M'){rec_mt_change(1);}
+      }
+
+      if(cc>=co){break;}
+    }
+    midi_clr();
+  }
+  ecount=co;
+
+  B_LOCATE(1,6);B_PRINT("COUNTER START");
+  B_LOCATE(1,14);B_PRINT("MEAS/STEP = ----/---");
+  bc=0;
+
+
+  if(a>127 && a<0xf7){
+    if(ecount_sw){stc=ecount;}else{stc=rcd->stepcount;}
+    co=stc;goto dtm;}
+
+  if(topmeas>1){stm=topmeas;}
+
+  /* recording loop start */
+  while(1){
+       int nst;
+       STed_MeasureConversion(dtr);
+       nst=rcd->step[dtr];          /* Dec.11.1998 Daisuke Nagano */
+
+       if(nst!=ost || beat1==1){
+               B_LOCATE(13,14);B_PRINT(fstr(rcd->bar[dtr]-2+stm,4));
+               if(beat1>1){B_LOCATE(18,14);B_PRINT(fstr(((nst+1)>>1),3));}
+               ost=nst;
+
+               B_LOCATE(91,12);B_PRINT(fstr(ad*100/work_size,3));
+       }
+       if( rcd->panel_tempo != mtr_tempo ) {
+               mtr_tempo = rcd->panel_tempo;
+               B_LOCATE( 58,12 );B_PRINT(fstr(mtr_tempo,3));
+       }
+
+top:
+       key_midi_player_wait();
+       a=(*rcd->md_get)();if(a==0xfc){break;}
+
+       if(ecount_sw) {
+               if(a==0xf8){
+                       ecount+=ecst;
+               }
+               stc=ecount;
+       } else {
+               stc=rcd->stepcount;
+       }
+
+       if(stc>=lastst){break;}
+
+start:
+       if(a>=0 && a<0xf8){
+               if(a==0xf5){
+                       ccc=0;
+      next0:
+                       key_midi_wait();
+                       b=(*rcd->md_get)();
+                       if(b<0||b>0xf7){
+                               if( INPOUT(0xfe)!=0 ){
+                                       if(INPOUT(0xff)==27){break;}
+                               }
+                               goto next0;
+                       }
+                       goto top;
+               }
+
+               if(ccc==0 && a<128){goto next;}
+
+               if(ccc==0xf0 || ccc==0xf7){
+                       if(a<0x80){
+                               dat[ad++]=a;mbuf[bc++]=a;
+                               goto top;
+                       }else{
+                               dat[ad++]=0xf7;mbuf[bc++]=0xf7;mbuf[bc++]=0xff;
+                               ccc=0;
+                               if(rfilt[10][0]==0){
+                                       if(rec_putmd!=0){
+                                               (*rcd->mix_out)((char*)mbuf);
+                                       }
+                               }
+                               if(a==0xf7){goto next;}
+                               goto dtm;
+                       }
+               }else{
+                       if(a==0xf7){goto top;}
+dtm:
+                       put_delta(ad,stc-co);co=stc;ad+=d_byte;
+               }
+
+               if(a>127){
+                       if(ad>0 && dat[ad-1]>=0x80 && dat[ad-1]<0xf8){ad--;}
+                       ccc=a;dat[ad++]=a;
+                       if(a==0xf0 || a==0xf7){mbuf[0]=a;bc=1;}
+               next3:
+                       key_midi_wait();
+                       a=(*rcd->md_get)();
+                       if(a<0 || a>0xf7){
+                               if( INPOUT(0xfe)!=0 ){
+                                       if(INPOUT(0xff)==27){break;}
+                               }
+                               goto next3;
+                       }
+               }
+
+               if(ccc!=0 && a<128){
+                       int ct=(ccc&0xf0);
+                       switch( ccc & 0xf0 ) {
+                       case 0x80 :
+                       case 0x90 :
+                       case 0xa0 :
+                       case 0xb0 :
+                       case 0xe0 :
+                               dat[ad++]=a;
+       next2:
+                               key_midi_wait();
+                               b=(*rcd->md_get)();
+                               if(b<0||b>0xf7){
+                                       if( INPOUT(0xfe)!=0 ){
+                                               if(INPOUT(0xff)==27){break;}
+                                       }
+                                       goto next2;
+                               }
+                               if(b>127){a=b;ccc=a;dat[ad++]=0;goto start;}
+                               dat[ad++]=b;
+
+                               if(ct==0x90 || ct==0x80){
+                                       if(rfilt[12][0]!=0){
+                                               a+=(rfilt[12][1]-128);
+                                               if(a>127 || a<0){break;}
+                                               dat[ad-2]=a;
+                                       }
+                               }
+                               if(ct==0x90 && b){
+                                       if(rfilt[11][0]!=0){
+                                               if(a>rfilt[11][1] || a<rfilt[11][2]){break;}
+                                       }
+                                       if(rfilt[13][0]!=0){
+                                               b=rfilt[13][1];dat[ad-1]=b;
+                                       }
+                               }
+                               if(ct==0xa0 && rfilt[3][0]!=0){break;}
+                               if(ct==0xb0){
+                                       a=ctrl_tbl[a];dat[ad-2]=a;
+
+                                   if(a==64 ){if(rfilt[4][0]!=0){break;}else{goto skip;}}
+                                   if(a==1  ){if(rfilt[5][0]!=0){break;}else{goto skip;}}
+                                   if(a==7  ){if(rfilt[6][0]!=0){break;}else{goto skip;}}
+                                   if(a==11 ){if(rfilt[7][0]!=0){break;}else{goto skip;}}
+                                   if(a==123){if(rfilt[8][0]!=0){break;}else{goto skip;}}
+                                   if(rfilt[9][0]!=0){break;}
+                               }
+       skip:
+                               if(ct==0xe0 && rfilt[1][0]!=0){break;}
+                               if(rec_putmd!=0){mix_two(ccc,a,b);}
+                               break;
+                       case 0xc0 :
+                       case 0xd0 :
+                               dat[ad++]=a;
+                               if(ct==0xc0 && rfilt[0][0]!=0){break;}
+                               if(ct==0xd0 && rfilt[2][0]!=0){break;}
+                               if(rec_putmd!=0){mix_one(ccc,a);}
+                               break;
+                       case 0xf0 :
+                       case 0xf7 :
+                               dat[ad++]=a;mbuf[bc++]=a;
+                               break;
+                       }
+               }
+
+next:
+               if(ad+512>=work_size){msg(_("Recording buffer is exhausted."));break;}
+       }
+
+       if( INPOUT(0xfe)!=0 ){
+               int k=INPOUT(0xff);
+               if(k==27){break;}
+               if(k=='m' || k=='M'){rec_mt_change(1);}
+
+               if(k==0x17){if( rcd->tempo > 1 ) {rcd->tempo--;}}
+               if(k==0x12){if( rcd->tempo < 255 ) {rcd->tempo++;}}
+               if(k==0x15){rcd->tempo = rcd->basetempo;}
+       }
+  }
+
+  if(ecount_sw){stc=ecount;}else{stc=rcd->stepcount;}
+  if(stc>=lastst){stc=lastst;}
+
+  stc-=co;put_delta(ad,stc);ad+=d_byte;
+  dat[ad++]=0xff;dat[ad++]=0x2f;
+  (*rcd->end)();
+
+  B_LOCATE(1,6);B_PRINT(_("Recording finished."));
+
+  if(stm==0 && topmeas==1){stc-=barlen*2;}
+  B_PRINT("Total ST=");B_PRINT(fstr(stc+co,8));
+  /*
+    B_PRINT("    Used Size=");B_PRINT(fstr(ad,6));B_PRINT("byte");
+    */
+
+  B_LOCATE(1,8);B_PRINT(_("Now Converting ... "));
+  if(stc+co>0){lastptr=ad;rec_conv(mm);}
+  B_LOCATE(16,8);B_PRINT(_("Finished"));
+  B_LOCATE(1,10);B_PRINT(_("Press any key."));
+
+  /*while( INPOUT(0xff)==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+  key_wait();
+
+ext:
+  B_CLR_AL();home2(0);
+  rcd->put_mode=pm;
+
+  return(0);
+}
+
+/***************************/
+void   mix_one(int c,int a)
+{
+  char mbuf[3];
+
+  mbuf[0]=c;mbuf[1]=a;mbuf[2]=0xff;
+  (*rcd->mix_out)(mbuf);
+}
+
+void mix_two(int c,int a,int b)
+{
+  char mbuf[4];
+
+  mbuf[0]=c;mbuf[1]=a;mbuf[2]=b;mbuf[3]=0xff;
+  (*rcd->mix_out)(mbuf);
+}
+
+/***************************/
+void   rec_ch_disp()
+{
+  int  c;
+
+  c=rec_getch;
+  /*   if(rcd->ch_port[c]!=rcd->put_mode){c+=16;}
+       B_LOCATE(16,31);B_PRINT(chstr(c+1));*/
+  B_LOCATE(16,31);B_PRINT(fstr(c+1,2));
+
+  B_LOCATE(30,31);if(rec_putmd==0){B_PRINT("OFF ");}else{B_PRINT("THRU");}
+  B_LOCATE(44,31);if(metoro_sw==0){B_PRINT("ON  ");}else{B_PRINT("OFF ");}
+  B_LOCATE(54,31);if(ecount_sw==0){B_PRINT("INT ");}else{B_PRINT("EXT ");}
+
+  B_LOCATE(45-10,12);B_PRINT(fstr(topmeas,4));
+  B_LOCATE(45-10+5,12);B_PRINT(fstr(btmmeas,4));
+
+}
+
+/***************************/
+void   rec_ch_change(int pm)
+{
+  int  c;
+
+  msg("RECORDING MIDI CH.=");
+
+  c=vinput(rec_getch+1,0x802);if(c>0 && c<17){rec_getch=c-1;}
+  msg_clr();rec_ch_disp();
+
+  if(rec_getch>=0){rcd->put_mode=rcd->ch_port[rec_getch];}else{rcd->put_mode=pm;}
+}
+
+/***************************/
+void   rec_md_change()
+{
+  rec_putmd=1-rec_putmd;
+  rec_ch_disp();
+}
+
+/***************************/
+void   rec_mt_change(int md)
+{
+  int a;
+
+  a=metoro_sw;
+  if(metoro_trk>=0){
+    a=1-a;metoro_sw=a;
+    if(md){rcd->trk_mask[metoro_trk]=metoro_sw;}
+  }
+  rec_ch_disp();
+}
+
+
+/***************************/
+/*
+  inline void  rec_rm_change()
+  {
+  int a;
+
+  a=rcd->midi_clock;
+  a=1-a;rcd->midi_clock=a;
+  rec_ch_disp();
+  }
+  */
+/***************************/
+void   rec_sy_change()
+{
+  ecount_sw=1-ecount_sw;
+  rec_ch_disp();
+}
+
+/***************************/
+void   rec_meas_change(int pm)
+{
+  int  c;
+
+p1:
+  msg("RECORDING START MEAS NO.=");
+
+  c=vinput(topmeas,0x804);
+  if(c<1 && c>999){goto p1;}
+  if( es!=0 ){msg_clr();return;}
+  topmeas=c;
+  rec_ch_disp();
+p2:
+  B_LOCATE(32,1);B_PRINT("END MEAS NO.=");
+
+  c=vinput(btmmeas,0x804);
+  if(c<topmeas && c>999){goto p2;}
+  if( es!=0 ){goto p1;}
+  btmmeas=c;
+  rec_ch_disp();
+
+  msg_clr();
+}
+
+/***************************/
+int    countstart(int md,int smeas)
+{
+  int  bpo,met=-1,pr=0;
+  int  me_ad[2048];
+
+  static       unsigned char   metp[4*14]={
+    0xe6,0,16,0, 0xec,0,0,0,   0xf9,0,0,0,  0xf9,0,0,0,  0xfd,0,0,0,
+    64,48,2,127, 0,0,0,0,      0xf9,0,0,0,  64,48,2,117, 0,0,0,0,
+    0xf8,3,0,0,  0xf8,128,0,0, 0xf8,16,0,0, 0xfe,0,0,0};
+
+  static       unsigned char   restbar[4*10]={
+    0xf9,0,0,0, 64,48,0,0, 0,0,0,0, 0xf8,4,0,0, 0xfd,0,0,0,
+    0xf9,0,0,0, 64,48,0,0, 0,0,0,0, 0xf8,4,0,0, 0xfd,0,0,0};
+
+
+  metp[2]=rec_met[0];/*metp[6]=rec_met[1];*/
+  if(rec_met[1]>=0){metp[4]=0xec;metp[6]=rec_met[1];}else{metp[4]=0;metp[6]=0;}
+
+  metp[20]=rec_met[5];metp[21]=barlen/beat1;metp[22]=rec_met[6];metp[23]=rec_met[7];
+  metp[32]=rec_met[2];metp[33]=barlen/beat1;metp[34]=rec_met[3];metp[35]=rec_met[4];
+  metp[41]=beat1-1;if(beat1==1){metp[41]=1;metp[33]=0;metp[34]=0;metp[35]=0;}
+
+  restbar[5]=barlen/beat1;restbar[25]=barlen/beat1;
+  metp[25]=0;metp[37]=0;restbar[9]=0;restbar[29]=0;
+
+  if(barlen/beat1>240){metp[25]=255;metp[37]=255;restbar[9]=255;restbar[29]=255;}
+
+
+  all_note_off(1);hedset(36);bpo=rcp_buf_put((char*)hed,0,1414);
+
+  if(smeas<2){
+    int i;
+    poft=0;
+
+    for(i=0 ;i< 36;i++){
+      if((trmod[i]&1)!=0 || tr_len[i]==4){     /*mute & rec*/
+       if(met<0){
+         thedset(0,4*14+44);
+    hed[5]=0x80;
+    hed[6]=0;
+    hed[7]=0;
+         bpo=rcp_buf_put((char*)hed,bpo,44);
+    bpo=rcp_buf_put((char*)metp,bpo,4*14);
+         met=i;
+       }else{
+         thedset(i,48);dat[0]=0xfe;
+         bpo=rcp_buf_put((char*)hed,bpo,44);
+    bpo=rcp_buf_put((char*)dat,bpo,4);
+       }
+      }else{                                   /*play & mix*/
+
+       int     ln=0;
+       if(md!=0){ln=4*10;}
+       same_cluc(i,ln);thedset(i,tr_len[i]+44+ln);
+       bpo=rcp_buf_put((char*)hed,bpo,44);
+       if(md!=0){bpo=rcp_buf_put((char*)restbar,bpo,4*10);}
+       bpo=rcp_buf_put((char*)trk[i],bpo,tr_len[i]);
+       /*
+         if(md==0){
+         same_cluc(i,0);thedset(i,tr_len[i]+44);
+         bpo=rcp_buf_put(hed,bpo,44);
+         }else{
+         same_cluc(i,4*10);thedset(i,tr_len[i]+44+4*10);
+         bpo=rcp_buf_put(hed,bpo,44);bpo=rcp_buf_put(restbar,bpo,4*10);
+         }
+         bpo=rcp_buf_put(trk[i],bpo,tr_len[i]);
+         */
+      }
+    }
+  }else{
+    int i,po,meas=smeas,dumy=track,tempo;
+
+    po=meas_add(meas);pr=lsp_wait_chack(meas);tempo=last_tempo(meas);
+    poft=meas-1;if(po>0){poft+=0x10000;}
+
+    for(i=0 ;i< 36;i++){
+      if((trmod[i]&1)!=0 || tr_len[i]==4){     /*mute & rec*/
+       if(met<0){
+         int   ln=0,ln2=0;
+
+         if(md){ln2=meas_adj_sub(0,pr);ln+=ln2;ln+=4*14;}
+
+         thedset(0,ln+44);hed[5]=0x80;hed[6]=0;hed[7]=0;
+         bpo=rcp_buf_put((char*)hed,bpo,44);
+         if(ln2){bpo=rcp_buf_put((char*)dat,bpo,ln2);}
+         bpo=rcp_buf_put((char*)metp,bpo,4*14);
+         met=i;
+
+       }else{
+         thedset(i,48);dat[0]=0xfe;
+         bpo=rcp_buf_put((char*)hed,bpo,44);bpo=rcp_buf_put((char*)dat,bpo,4);
+       }
+      }else{                                   /*play & mix*/
+       int co=0,ad,j;
+
+       track=i;ad=meas_add(meas);if(ad<0){ad=tr_len[i]-4;}
+       add_set(i,me_ad);
+       co=lsp_para_set(i,ad,me_ad,pr);
+       if(po>0){
+         if( tempo>=0){
+           dat[co]=0xe7;dat[co+1]=1;dat[co+2]=tempo;dat[co+3]=0;
+           co=co+4;
+         }
+         dat[co]=0xfd;co=co+4;
+       }
+       j=ad;
+       while(1){
+         dat[co]=trk[i][j];dat[co+1]=trk[i][j+1];
+         dat[co+2]=trk[i][j+2];dat[co+3]=trk[i][j+3];
+         if(dat[co]==0xfc){
+           int same,ad;
+           same=dat[co+1]+(dat[co+2]&3)*256;
+           if(meas<(same+1)){
+             if(po>0){same++;}
+             ad=dat_add(co+4,same+2-meas);
+             if(ad>co){goto sameext;}
+             ad+=44;dat[co+2]=ad&0xff;dat[co+3]=ad>>8;
+           }else{
+           sameext:
+             ad=me_ad[same];
+             while(trk[i][ad]<0xfc && co<work_size){
+               dat[co]=trk[i][ad];dat[co+1]=trk[i][ad+1];
+               dat[co+2]=trk[i][ad+2];dat[co+3]=trk[i][ad+3];
+               co=co+4;ad=ad+4;
+             }
+             dat[co]=0xfd;
+           }
+         }
+         if(dat[co]==0x98){
+           while(trk[i][j+4]==0xf7 && co<work_size){
+             co+=4;j+=4;
+             dat[co]=trk[i][j];dat[co+1]=trk[i][j+1];
+             dat[co+2]=trk[i][j+2];dat[co+3]=trk[i][j+3];
+           }
+         }
+         if( dat[co]==0xfe || co+4>=work_size ){break;}
+         co=co+4;
+         if(trk[i][j]<0xfc && trk[i][j+4]==0xfc){dat[co]=0xfd;co=co+4;}
+         j=j+4;
+       }
+       dat[co]=0xfe;co=co+4;
+
+       /*same_cluc(i,0);*/thedset(i,co+44);
+       bpo=rcp_buf_put((char*)hed,bpo,44);
+       bpo=rcp_buf_put((char*)dat,bpo,co);
+      }
+    }
+    track=dumy;
+  }
+
+  if((rcd->bufcap)<bpo){msg(_("Too small RCD buffer."));return 0;}
+
+  rcd->fmt=2;rcd->totalcount=bpo;
+  rcd->data_valid=1;rcd->word_valid=0;rcd->tone_valid=0;rcd->gsd_valid=0;
+  /*   strcpy(rcd->filename,"");strcpy(rcd->tonename,"");strcpy(rcd->gsdname,"");*/
+
+  (*rcd->init)();
+
+  if(cm6_file[0]==0 && gsd_file[0]==0){
+    if(init_exc_data[0]==255){(*rcd->setup)();
+    }else{(*rcd->mix_out)((char*)init_exc_data);twait(5);}
+  }
+
+  metoro_trk=met;
+  return pr;
+}
+
+/***************************/
+unsigned char  *strncpy0( unsigned char *dst, unsigned char *src, int n )
+{
+  int i;
+
+  for( i = 0; i < n; i++ ) {dst[i] = src[i];}
+  dst[n] = 0;return( dst );
+}
+
+int get_delta( int p )
+{
+  register int val, i, d;
+
+  val = 0;d_byte = 0;
+
+  for( i = 0; i < 4; i++ ) {
+    d = dat[p++];d_byte++;
+    val = ( val << 7 ) + ( d & 0x7f );
+    if( d < 0x80 ) {return( val );}
+  }
+
+  return(0);
+}
+
+void put_delta( int p ,int val)
+{
+  /*   register long buffer;*/
+  register unsigned int buffer;
+
+  d_byte=0;
+
+  buffer = val & 0x7f;
+  while((val >>= 7) > 0){
+    buffer <<= 8;buffer |= 0x80;
+    buffer += (val & 0x7f);
+  }
+  while(1){
+    dat[p++]=buffer & 0xff;d_byte++;
+    if(buffer & 0x80){buffer >>= 8; }else{ break;}
+  }
+}
+
+void entry( int d0, int d1, int d2, int d3 )
+{
+  if( len+4 >= TRACK_SIZE ){msg(_("Track size exhausted."));return;}
+
+  note[len++] = d0;note[len++] = d1;note[len++] = d2;note[len++] = d3;
+
+}
+
+void record_flash( int dt )
+{
+  int dx, i, j;
+
+  while( dt > 0 ) {
+    if( dt <= 0xf0 ) {dx = dt;} else {dx = 0xf0;}
+    if( dx + barunit > barlen ) {dx = barlen - barunit;}
+
+    for( i = 0; i < 16; i++ ) {
+      if( gbuf[i] ) {
+       if( gbuf[i] <= 0xf0 ) {
+         entry( nbuf[i], 0, gbuf[i], vbuf[i] );
+         for( j = i; j < 15; j++ ) {
+           nbuf[j] = nbuf[j+1];
+           vbuf[j] = vbuf[j+1];
+           gbuf[j] = gbuf[j+1];
+         }
+         nbuf[15] = vbuf[15] = gbuf[15] = 0;
+         i--;
+       } else {
+         entry( nbuf[i], 0, dx + 1, vbuf[i] );
+         gbuf[i] -= dx;
+       }
+      } else {
+       break;
+      }
+    }
+
+    if( note[ len - 4 ] !=0xde &&
+       note[ len - 4 ] < 0xf0 && ( note[ len - 3 ] + dx ) <= 0xf0 ) {
+      note[ len - 3 ] += dx ;
+    } else {
+
+      if( note[ len - 4 ] == 0xf7 ){
+       int cc=len-4;
+       while(note[cc]==0xf7){cc-=4;}
+
+       if( ( note[ cc + 1 ] + dx ) <= 0xf0 ) {
+         note[ cc + 1 ] += dx ;
+       } else {
+         entry( 0x00, dx, 0, 0 );
+       }
+      } else {
+       entry( 0x00, dx, 0, 0 );
+      }
+    }
+
+    dt -= dx;
+
+    if( ( barunit += dx ) == barlen ) {
+      entry( 0xfd, 0x00, 0x00, 0x00 );
+      barunit = 0;
+    }
+    if( len+4 >= TRACK_SIZE ){break;}
+
+  }
+
+  stepsum = 0;
+}
+
+void proc_dummy( int dt )
+{
+  stepsum += dt;
+}
+
+void check( int data )
+{
+  cmd = data & 0xf0;
+
+  data &= 0x0f;
+  if( midi_ch != data ) {midi_ch = data;}
+}
+
+int search( int pp )
+{
+  int n, dt, cc, ch, ccmd, last;
+
+  n = dat[pp];
+  ccmd = cmd;
+  last = lastptr;
+  pp += 2;
+  dt = 0;
+  ch = midi_ch;
+
+  while( pp < last ) {
+    dt += get_delta( pp );
+    pp += d_byte;
+    if( ( cc = dat[pp] ) < 0x80 ) {
+      if( ccmd == 0x80 && cc == n && ch == midi_ch ) {
+       return( dt );
+      } else {
+       if( ccmd == 0x90 && cc == n &&
+           dat[pp+1] == 0x00 && ch == midi_ch ) {
+         return( dt );
+       } else {
+         pp += 2;
+         if(ccmd>=0xc0 && ccmd<=0xdf){pp--;}
+       }
+      }
+    } else {
+      switch( cc & 0xf0 ) {
+      case 0x80 :
+       if( dat[pp+1] == n && cc == ( 0x80 + midi_ch ) ) {
+         return( dt );
+       }
+       ch = cc & 0x0f;
+       pp += 3;
+       break;
+      case 0x90 :
+       if( dat[pp+1] == n && dat[pp+2] == 0x00 &&
+           cc == ( 0x90 + midi_ch ) ) { 
+         return( dt );
+       }
+       pp += 3;ch = cc & 0x0f;break;
+      case 0xa0 :
+      case 0xb0 :
+      case 0xe0 :
+       pp += 3;ch = cc & 0x0f;break;
+      case 0xc0 :
+      case 0xd0 :
+       pp += 2;ch = cc & 0x0f;break;
+      case 0xf0 :
+       switch( cc ) {
+       case 0xf0 :
+       case 0xf7 :
+         pp += 1;while(dat[pp++]!=0xf7){}
+         break;
+       case 0xff :
+         return(0);
+         break;
+       default :
+         B_PRINT(_("Invalid format.\n"));
+         return(0);
+         break;
+       }
+       break;
+      }
+      ccmd = cc & 0xf0;
+    }
+  }
+  return( 0 );
+}
+
+void ent_dat( int nt, int vl, int gt )
+{
+  int i;
+
+  if( gt <= 0xf0 ) {
+    entry( nt, 0, gt,vl );return;
+  } else {
+    entry( nt, 0, 255,vl );
+  }
+
+  for( i = 0; i < 16; i++ ) {
+    if( !gbuf[i] || nbuf[i] == nt ) {
+      nbuf[i] = nt;vbuf[i] = vl;gbuf[i] = gt;return;
+    }
+  }
+
+  for( i = 0; i < 15; i++ ) {
+    nbuf[i] = nbuf[i+1];vbuf[i] = vbuf[i+1];gbuf[i] = gbuf[i+1];
+  }
+
+  nbuf[15] = nt;vbuf[15] = vl;gbuf[15] = gt;
+}
+
+void note_off( int p )
+{
+  /* do nothing */
+}
+
+void note_on( int p )
+{
+  int gt;
+
+  if( midi_ch != trch ) {return;}
+
+  if(rfilt[11][0]!=0){
+    if(dat[p]>rfilt[11][1] || dat[p]<rfilt[11][2]){return;}
+  }
+
+  record_flash( stepsum );
+
+  if( dat[p+1] ) {
+    if( !( gt = search( p ) ) ) {return;}
+    ent_dat( dat[p], dat[p+1], gt );
+  }
+}
+
+void aft_key( int p )
+{
+  if( midi_ch != trch  ) {return;}
+  if(rfilt[3][0]!=0){return;}
+  record_flash( stepsum );
+  entry( 0xea, 0x00, dat[p], dat[p+1] );
+}
+
+void ctl_chg( int p )
+{
+  if( midi_ch != trch ) {return;}
+
+  if(dat[p]==64 ){if(rfilt[4][0]!=0){return;}else{goto skip;}}
+  if(dat[p]==1  ){if(rfilt[5][0]!=0){return;}else{goto skip;}}
+  if(dat[p]==7  ){if(rfilt[6][0]!=0){return;}else{goto skip;}}
+  if(dat[p]==11 ){if(rfilt[7][0]!=0){return;}else{goto skip;}}
+  if(dat[p]==123){if(rfilt[8][0]!=0){return;}else{goto skip;}}
+  if(rfilt[9][0]!=0){return;}
+skip:
+  record_flash( stepsum );
+  entry( 0xeb, 0x00, dat[p], dat[p+1] );
+}
+
+void prg_chg( int p )
+{
+  if( midi_ch != trch ) {return;}
+  if(rfilt[0][0]!=0){return;}
+  record_flash( stepsum );
+  entry( 0xec, 0x00, dat[p], 0x00 );
+}
+
+void aft_tch( int p )
+{
+  if( midi_ch != trch  ) {return;}
+  if(rfilt[2][0]!=0){return;}
+  record_flash( stepsum );
+  entry( 0xed, 0x00, dat[p], 0x00 );
+}
+
+void pt_bend( int p )
+{
+  if( midi_ch != trch  ) {return;}
+  if(rfilt[1][0]!=0){return;}
+  record_flash( stepsum );
+  entry( 0xee, 0x00, dat[p], dat[p+1] );
+}
+
+void run_sts( int p )
+{
+  if( midi_ch != trch  ) {return;}
+  record_flash( stepsum );
+
+  switch( cmd ) {
+  case 0x80 : note_off(p); break;
+  case 0x90 : note_on(p);  break;
+  case 0xa0 : aft_key(p);  break;
+  case 0xb0 : ctl_chg(p);  break;
+  case 0xc0 : prg_chg(p);  break;
+  case 0xd0 : aft_tch(p);  break;
+  case 0xe0 : pt_bend(p);  break;
+  }
+}
+
+int num_check( int num, int limit )
+{
+  if( num > limit ) {return( limit );} else {return( num );}
+}
+
+void proc_excl( unsigned char *text , int length,int code)
+{
+  int h, m, l, hh, mm, ll, i;
+
+  if(rfilt[10][0]!=0){return;}
+  record_flash( stepsum );
+
+  text[ length ] = 0xf7 ;
+
+  if( length < 9 || length>8+4 ||
+      text[0] != 0x41 || text[3] != 0x12 ||
+      text[ length-1 ] != 0xf7 ) {
+
+    if( text[0] == 0x41 && text[3] == 0x12 && length<9 ){return;}
+
+    if(code==0xf0){
+    nor:
+      i=0;
+      entry( 0x98, 0, 0, 0 );
+      while(i<length){
+       entry( 0xf7, 0, text[i], text[i+1] );
+       if( text[i] == 0xf7 || text[ i+1 ] == 0xf7 ) {break;}
+       i=i+2;
+      }
+    }else{
+      if(len==0 || note[len-4]!=0xf7){goto nor;}
+      i=0;
+
+      if(note[len-2]==0xf7){note[len-2]=text[i++];}
+      if(note[len-1]==0xf7){note[len-1]=text[i++];}
+
+      while(i<length){
+       entry( 0xf7, 0, text[i], text[i+1] );
+       if( text[i] == 0xf7 || text[ i+1 ] == 0xf7 ) {break;}
+       i=i+2;
+      }
+    }
+    return;
+  }
+
+  if( exc_no != text[1] || exc_id != text[2] ) {
+    exc_no = text[1];exc_id = text[2];
+    entry( 0xdf, 0, exc_no, exc_id );
+  }
+
+  h = text[4]; m = text[5]; l = text[6];
+  hh = mm = ll = -1;
+
+  i=7;
+  while(text[i]!=0xf7 && text[i+1]!=0xf7 && i<512){
+    if( hh != h || mm != m  ) {
+      entry( 0xdd, 0x00, h, m );
+      hh = h; mm = m; ll = l;
+    }
+    entry( 0xde, 0x00, l, text[i] );
+    if( l++ == 0x7f ) {l = 0;m++;}
+    i++;
+  }
+}
+
+void proc_next( void )
+{
+  int meta, code,i;
+  unsigned char *text=rcpbuf;
+
+  for(i=0;i<16;i++){nbuf[i] = vbuf[i] = gbuf[i] = 0;}
+  pt = 0;len = 0;barunit = 0; stepsum = 0;
+  exc_no=0x10;exc_id=0x16;
+
+  cmd = 0x00;
+  step = 0;
+
+  while(1) {
+    if( pt >= lastptr || len+4 >= TRACK_SIZE ){break;}
+
+    proc_dummy( get_delta(pt) );
+    pt += d_byte;
+
+    if( ( code = dat[pt] ) == 0xff ) {
+      pt++;meta = dat[pt++];
+      if( tr == 0 ) {  record_flash( stepsum );}
+      pt += 1;
+      if( meta == 0x2f ) {return;}
+    } else {
+      switch( code & 0xf0 ) {
+      case 0x80: check( dat[pt] ); note_off(pt+1); pt += 3; break;
+      case 0x90: check( dat[pt] ); note_on(pt+1);  pt += 3; break;
+      case 0xa0: check( dat[pt] ); aft_key(pt+1);  pt += 3; break;
+      case 0xb0: check( dat[pt] ); ctl_chg(pt+1);  pt += 3; break;
+      case 0xc0: check( dat[pt] ); prg_chg(pt+1);  pt += 2; break;
+      case 0xd0: check( dat[pt] ); aft_tch(pt+1);  pt += 2; break;
+      case 0xe0: check( dat[pt] ); pt_bend(pt+1);  pt += 3; break;
+      case 0xf0:
+       if( code != 0xf0 && code != 0xf7 ) {
+         B_PRINT(_("Invalid MIDI messages.\n"));
+         return;
+       }
+       pt++;
+       if( ( tr == 0 ) ) {
+         int ll=1,pt2=pt;
+         while(dat[pt++]!=0xf7){ll++;}
+         strncpy0( text, dat + pt2, ll);
+         proc_excl( text,ll ,code);
+       }
+       break;
+      default :  run_sts(pt); pt += 2;
+       if(cmd>=0xc0 && cmd<=0xdf){pt--;}
+       break;
+      }
+    }
+  }
+}
+
+void track_end( void )
+{
+  record_flash( stepsum );
+  entry( 0xfe, 0, 0, 0 );
+}
+
+void rec_conv( int mm )
+{
+  int i;
+
+  memcpy_l(dat2,dat,lastptr);
+
+  size_ref();
+  /*   B_PRINT("ch.:");*/
+
+  if(mm==1){
+    tr=0;trch=midi_ch = rec_getch ;
+    /*B_PRINT(fstr(tr+1,3));*/
+    proc_next();track_end();
+
+    for(i=0;i<36;i++){
+      if(trmod[i]&2){
+       memcpy_l(dat,dat2,lastptr);
+       if(rec_ext(i)){break;}
+      }
+    }
+  }else{
+    for(tr=0;tr<16;tr++){
+      trch=midi_ch = tr;
+      /*B_PRINT(fstr(tr+1,3));*/
+      proc_next();track_end();
+
+      for(i=0;i<36;i++){
+       if((trmod[i]&2)!=0 && tr==((mch[i]-1)&15)){
+         memcpy_l(dat,dat2,lastptr);
+         if(rec_ext(i)){break;}
+       }
+      }
+    }
+  }
+}
+
+/***************************/
+int    rec_ext(int i)
+{
+  int ln,ad=0,ad2=0,ln2=0,dumy=track;
+  track=i;
+
+  ln=trk_ext_sub(i,(char*)rcpbuf);
+  if(ln==0){return 1;}
+
+  if(size_change(i,ln)){return 1;}
+  memcpy_l(trk[i],rcpbuf,ln);tr_len[i]=ln;
+
+  if(topmeas>1){
+    /*ad=meas_add(topmeas);if(ad<0){ad=tr_len[i]-4;}*/
+    ad=meas_adjust(i,topmeas);
+  }
+
+
+  if(trmod[i]==2 && tr_len[i]>4){
+    ln=trk_mix_sub(rcpbuf+ad,note);
+    if(size_change(i,ad+ln+4)){return 1;}
+
+    dat[ln]=0xfe;ln+=4;tr_len[i]=ad+ln;
+    memcpy_l(&trk[i][ad],dat,ln);
+  }else{
+    ad2=meas_add(btmmeas+1);if(ad2<0){ad2=tr_len[i]-4;}
+
+    ln2=tr_len[i]-ad2;
+    memcpy_l(rcpbuf,&trk[i][ad2],ln2);
+    if(ln2<=4){ln2=0;}
+
+    if(size_change(i,ad+len+ln2)){return 1;}
+
+    tr_len[i]=ad+len;
+    memcpy_l(&trk[i][ad],note,len);
+
+    if(ln2>4){
+      ad2=ad+len-4;
+      tr_len[i]=ad+len+ln2;
+      memcpy_l(&trk[i][ad2],rcpbuf,ln2);
+    }
+
+  }
+
+  tai_compres(i,ad,tr_len[i]);
+  trksize(i);
+  track=dumy;
+
+  return 0;
+}
+
+int    meas_adjust(int i,int topm)
+{
+  int  ad=0,ln=0,lft=0,dumy=track;track=i;
+
+  if(topm>1){
+    ad=meas_add(topm);
+    if(ad<0){
+      ad=tr_len[track]-4;
+      lft=topm-meas_no(ad);
+
+      if(step_cluc(ad)!=0){
+       lft--;ln=meas_adj_sub(ln,barlen-step_cluc(ad));
+      }
+      while(lft>0){lft--;ln=meas_adj_sub(ln,barlen);}
+      dat[ln]=0xfe;ln+=4;
+
+      if(size_change(track,ad+ln)){return -1;}
+
+      tr_len[track]=ad+ln;
+      memcpy_l(&trk[track][ad],dat,ln);
+    }
+    ad=meas_add(topm);if(ad<0){ad=tr_len[track]-4;}
+
+  }
+  track=dumy;
+  return ad;
+}
+
+int    meas_adj_sub(int ln,int st)
+{
+  int ss=st;
+
+  while(ss>240){ss-=240;dat[ln++]=0;dat[ln++]=240;dat[ln++]=0;dat[ln++]=0;}
+  dat[ln++]=0;dat[ln++]=ss;dat[ln++]=0;dat[ln++]=0;
+  dat[ln++]=0xfd;dat[ln++]=0;dat[ln++]=0;dat[ln++]=0;
+
+  return ln;
+}
+
+/***************************/
diff --git a/redit.cpp b/redit.cpp
new file mode 100644 (file)
index 0000000..f9d888a
--- /dev/null
+++ b/redit.cpp
@@ -0,0 +1,766 @@
+/*
+ * STed: redit.c (rhythm track edit)
+ */
+
+#include       "sted.h"
+
+static char    rym[10][3]={"- ","1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "};
+static char    rym_s[10][4]={"OFF"," 1 "," 2 "," 3 "," 4 "," 5 "," 6 "," 7 "," 8 "," 9 "};
+/*
+static char    rym0[10][3]={"- ","1 ","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 "};
+static char    rym1[10][3]={"・","・","・","・","・","・","・","・","・","・"};
+static char    rym[10][3];
+*/
+
+static unsigned char   rpat[64][128];
+static unsigned char   rpar[65][5];
+static                 int     radr[65];
+static char    vlcl[256];
+static int     dfstep=12,barstep,dfvel=9;
+
+
+
+/***************************/
+/* rhythm track edit */
+void rtrk_ed(int md,int sh)
+{
+  int  no,pg=0,ke,kc,cx,cy,i,j,py,yy,rc=5999;
+  int  msf=-1;
+
+  barstep = tbase * 4 * beat1 / beat2;
+
+  if(sh&1){rhy_step();}
+
+  /*   if(cmdflag&0x20000){
+       for(i=0;i<10;i++){strcpy(rym[i],rym1[i]);}
+       }else{
+       for(i=0;i<10;i++){strcpy(rym[i],rym0[i]);}
+       }
+       */
+  for(i=0;i<256;i++){vlcl[i]=0;}
+  j=1;
+  for(i=1;i<10;i++){for(j=j;j<=rhy_vel[i];j++){vlcl[j]=i;}}
+  for(i=j;i<128;i++){vlcl[j]=9;}
+
+  no=meas_no(tr_pos[track][edit_scr&1][0]+tr_pos[track][edit_scr&1][2]*4);
+
+  if(tr_len[track]>4){
+    if(md!=0 && trk_check(4)==0){
+      int      i;
+      tr_len[track]=tr_len[track]+4;i=tr_len[track]-8;
+      trk[track][i]=0xfd;trk[track][i+1]=0;trk[track][i+4]=0xfe;
+      no=meas_no(i);
+    }
+  }
+  edit_scr=edit_scr|2;edfield(0);trk_no();
+  disp_vels();
+
+  cx=0;cy=0;pg=trrhy[track]&31;if(pg>16){pg=16;}
+  rtopat(no);rhed_dis(pg);rtrk_dis(pg,0,32);
+  if((cmdflag&0x200)==0){
+    MS_INIT();MS_LIMIT(126,80,762,511-32);MS_CURON();
+  }
+  while( 1){
+    int ma=0,mx,my;
+  top:
+    yy=0;if(cy==16){yy=16+(cx&1)*16;}
+    py=cy+pg;
+    if((B_SFTSNS()&16)!=0){rsttrc(&no,&cx,0,pg);}
+
+    /*
+      fill(128+32,cy*16+655+yy,31*16+151+32,cy*16+655+yy,15);
+      fill(cx*16+144+32,640,cx*16+144+32,15*16+655+50,15);
+      */
+    /* Jul.02.1998 by Daisuke Nagano */
+    if (!isconsole) {
+      txxline(128+32,cy*16+143+yy,65*8,0,65535);
+      txyline(cx*16+144+32,128,16*16+48,0,65535);
+    } else {
+      int i=edit_scr;edit_scr=0;
+      tcur((cx*16+144+32)*96/768-2, (cy*16+143+yy)*32/512, 2, 15);
+      edit_scr=i;
+    }
+
+    B_LOCATE(8,26);if(cy<16 && rpar[cx][0]==1){B_PRINT(fstr(rpat[cx][py],3));}else{B_PRINT("   ");}
+    B_LOCATE(8,27);if(cy<16 && rpar[cx][0]==1){
+      if(rpat[cx][py]!=0){B_PRINT(fstr(rpat[cx][py+32],3));}else{B_PRINT("  0");}
+    }else{B_PRINT("   ");}
+
+    key_mouse_wait();
+    ma=MS_GETDT()&0xff00;mspos(&mx,&my);
+    if(ma==0){msf=-1;}
+#if 0 /* Jul.02.1998 Daisuke Nagano */
+    while(B_KEYSNS()==0){
+      /*ma=MS_GETDT()&0xff00;mx=MS_CURGT();my=mx&0xffff;mx=mx>>16;*/
+      ma=MS_GETDT()&0xff00;mspos(&mx,&my);
+      if(ma==0){msf=-1;}
+      if(ma && msf!=0){break;}
+
+      rc++;
+      if( rc==6000){
+       sh=B_SFTSNS();
+       /*if((sh&1)!=0){fnc_dis(1);}else{fnc_dis(0);}*/
+       trk_free(meas_add(no));
+      }
+
+    }
+#endif
+
+    ke=0;kc=0;sh=0;
+    if(B_KEYSNS()!=0){
+      ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
+    }
+    if((ke>=0x70 && ke<=0x73)||(ke>=0xf0 && ke<=0xf3)){rc=6000;}else{rc=0;}
+
+    /*
+      fill(128+32,cy*16+655+yy,31*16+151+32,cy*16+655+yy,0);
+      fill(cx*16+144+32,640,cx*16+144+32,15*16+655+50,0);
+      */
+    /* Jul.02.1998 by Daisuke Nagano */
+    if (!isconsole) {
+      txxline(128+32,cy*16+143+yy,65*8,0,0);
+      txyline(cx*16+144+32,128,16*16+48,0,0);
+    } else {
+      int i=edit_scr;edit_scr=0;
+      tcur((cx*16+144+32)*96/768-2, (cy*16+143+yy)*32/512, 2, 0);
+      edit_scr=i;
+    }
+
+    if(ma!=0 && msf!=0){
+      ke=0;kc=0;msf=0;
+      if(mx>=50*8 && mx<50*8+30*8 && my>=80 && my<96 ){
+       dfvel=(mx-50*8)/24;
+       disp_vels();
+       goto top;
+      }
+      if(mx>=20*8+4 && mx<20*8+64*8+4 && my>=8*16 && my<8*16+16*16 ){
+       cx=(mx-(20*8+4))>>4;cy=(my-8*16)>>4;
+       py=cy+pg;
+       kc=0x30+dfvel;
+      }
+    }
+
+    /*         if( ke==0x70 ){fnc_dis(1);}
+               if( ke==0xf0 ){fnc_dis(0);}*/
+
+    if( ke==0x5a ){
+      if((sh&16)!=0){pattor(no);rsttrc(&no,&cx,0,pg);}
+    }
+
+    if( ke==1 ){pattor(no);break;}
+
+    if(rpar[cx][0]<2){
+      if( kc==13 ){
+       ke=0x3d;
+       if(cy==16){
+         B_LOCATE(cx*2+19,25+(cx&1));rpar[cx][2]=vinput(rpar[cx][2],0x803);
+       }else{
+         int   i;
+         B_LOCATE(cx*2+20,8+cy);
+         i=vinput(rpat[cx][py],0x803);if(i<128){rpat[cx][py]=i;}
+         B_LOCATE(cx*2+20,8+cy);B_PRINT("   ");
+         rpat[cx][py+32]=rhyno[py][1];
+       }
+       rpar[cx][0]=1;
+       rtrk_dis(pg,cx,1);
+      }
+      if( kc>0x2f && kc<0x3a){
+       if( cy<16 ){
+         rpat[cx][py]=rhy_vel[kc-'0'];
+         rpat[cx][py+32]=rhyno[py][1];
+         if(ke!=0){
+           ke=0x3d;
+         }
+       }else{
+         int   a;
+         B_LOCATE(cx*2+19,25+(cx&1));a=vinput(kc-'0',3);
+         if( es==0 ){ke=0x3d;rpar[cx][2]=a;}
+       }
+       rpar[cx][0]=1;
+       rtrk_dis(pg,cx,1);kc=0;
+      }
+
+      if( kc=='+' || kc=='.'|| kc=='>' || kc==' ' ){
+       if( cy<16 ){
+         int   i;
+         i=vlcl[rpat[cx][py]]+1;if(i>9){i=0;}
+         rpat[cx][py]=rhy_vel[i];rpat[cx][py+32]=rhyno[py][1];
+       }else{
+         if(kc=='>'){
+           rpar[cx][2]=(rpar[cx][2]+10);
+         }else{
+           rpar[cx][2]=(rpar[cx][2]+1);
+         }
+       }
+       rpar[cx][0]=1;
+       rtrk_dis(pg,cx,1);
+      }
+      if( kc=='-'|| kc==','|| kc=='<' ){
+       if( cy<16 ){
+         int   i;
+         i=vlcl[rpat[cx][py]]-1;if(i<0){i=9;}
+         rpat[cx][py]=rhy_vel[i];rpat[cx][py+32]=rhyno[py][1];
+       }else{
+         if(kc=='<'){
+           rpar[cx][2]=(rpar[cx][2]+246);
+         }else{
+           rpar[cx][2]=(rpar[cx][2]+255);
+         }
+       }
+       rpar[cx][0]=1;
+       rtrk_dis(pg,cx,1);
+      }
+    }
+
+    if( ke==0x69 && tr_len[track]>4 ){
+      int      i,po;
+      pattor(no);rcpf=1;po=meas_add(no);rcplen=meas_len(po);
+      for(i=0;i<rcplen;i++){rcpbuf[i]=trk[track][po+i];}
+      same_shift(po,1,1);trk_delete(po,rcplen);
+
+      if(no==1){break;}
+
+      if(trk[track][po]==0xfe){no=meas_no(tr_len[track]-8);}
+      B_CLR_AL();rtopat(no);rtrk_dis(pg,0,32);
+    }
+
+    if( ke==0x6a ){
+      int      i,po;
+      pattor(no);rcpf=1;po=meas_add(no);rcplen=meas_len(po);
+      for(i=0;i<rcplen;i++){rcpbuf[i]=trk[track][po+i];}
+      rtrk_dis(pg,0,32);
+    }
+    if( ke==0x6b ){
+      if( rcpf>0 ){
+       if(trk_check(rcplen)==0){
+         int   i,po;
+         pattor(no);po=meas_add(no);
+         same_shift(po,0,1);trk_shift(po,rcplen);
+         for(i=0;i<rcplen;i++){trk[track][i+po]=rcpbuf[i];}
+         rtopat(no);
+         rtrk_dis(pg,0,32);
+       }
+      }
+    }
+    if( ke==0x6c ){
+      int      i,j;
+      for(i=63;i>cx;i--){
+       for(j=0;j<=127;j++){rpat[i][j]=rpat[i-1][j];}
+       for(j=0;j<=3;j++){rpar[i][j]=rpar[i-1][j];}
+      }
+      rtrk_dis(pg,0,32);
+    }
+    if( ke==0x37 || kc==25 ){
+      int      i,j;
+      for(j=0;j<=127;j++){rlcbuf[j]=rpat[cx][j];}
+      for(j=0;j<=3;j++){rlcbuf[j+128]=rpar[cx][j];}
+      for(i=cx;i<=62;i++){
+       for(j=0;j<=127;j++){rpat[i][j]=rpat[i+1][j];}
+       for(j=0;j<=3;j++){rpar[i][j]=rpar[i+1][j];}
+      }
+      rtrk_dis(pg,0,32);
+    }
+    if( (ke==0x3a || kc==12) && rlcbuf[0]<255 ){
+      int      i,j;
+      for(i=63;i>cx;i--){
+       for(j=0;j<=127;j++){rpat[i][j]=rpat[i-1][j];}
+       for(j=0;j<=3;j++){rpar[i][j]=rpar[i-1][j];}
+      }
+      for(j=0;j<=127;j++){rpat[cx][j]=rlcbuf[j];}
+      for(j=0;j<=3;j++){rpar[cx][j]=rlcbuf[j+128];}
+      rtrk_dis(pg,0,32);
+    }
+
+    if( kc==0x13 || ke==0x3b){cx--;
+    if(cx<0){
+      cx=31;
+    leftl:
+      if(rpar[cx][0]==0 && cx>0){cx--;goto leftl;}
+    }
+    }
+    if( kc==0x04 || ke==0x3d){
+      if(rpar[cx][0]==0){cx=0;}else{cx++;if(cx>31){cx=0;}}
+    }
+    if( kc==0x05 || ke==0x3c){cy--;if(cy<0){cy=16;}}
+    if( kc==0x18 || ke==0x3e){cy++;if(cy>16){cy=0;}}
+
+    if( (ke==0x38 || ke==0x39) && (sh&1)!=0){
+      pg=16-pg;ke=0;rhed_dis(pg);rtrk_dis(pg,0,32);
+    }
+
+    if( (ke==0x39 || kc==0x12) && no>1 ){
+      pattor(no);no=no-1;rtopat(no);rtrk_dis(pg,0,32);
+      snsclr();
+    }
+    if( (ke==0x38 || kc==0x03) && no<meas_no(tr_len[track]-4)-1 ){
+      pattor(no);no=no+1;rtopat(no);rtrk_dis(pg,0,32);
+      snsclr();
+    }
+
+    if( ke==0x63 && no>1 ){
+      pattor(no);no=1;cy=0;cx=0;rtopat(no);rtrk_dis(pg,0,32);
+    }
+    if( ke==0x36 ){
+      if((sh&1)==0){cx=0;cy=0;}else{pattor(no);rsttrc(&no,&cx,1,pg);}
+    }
+    if( ke==0x64 && tr_len[track]>4 ){
+      pattor(no);no=meas_no(tr_len[track]-8);rtopat(no);rtrk_dis(pg,0,32);
+    }
+
+    if(kc=='Z' || kc=='z'){timtra();}
+
+    if( kc=='M' || kc=='m' || ke==0x55 ){
+      int      j;
+      pattor(no);j=meas_add(no);
+      if( (sh&2)==0 ){if( (sh&1)==0 ){poplay(j,3);}else{poplay(j,4);}
+      }else{poplay(j,5);}
+    }
+    if( kc=='P' || kc=='p' || ke==0x56 ){
+      int      j;
+      pattor(no);j=meas_add(no);
+      if( (sh&1)==0 ){poplay(j,1);}else{poplay(j,2);}
+    }
+    if( ke==0x57 && (sh&15)==0){rcd->sts=0;}
+    if( ke==0x58 && (sh&15)==0){rcd->sts=1;}
+    if( ke==0x59 && (sh&15)==0){poplay(0,0);}
+
+    if( ke==0x10 && tr_len[track]>4 ){
+      int      j;
+      msg("JUMP MEAS=");j=vinput(0,4);
+      if( es==0 && j>0 ){
+       pattor(no);if( meas_add(j)>=0 ){no=j;}
+       rtopat(no);rtrk_dis(pg,0,32);
+      }
+      msg_clr();
+    }
+
+    if( ke==0x53 && trk_check(4)==0){
+      int      i;
+      if(sh&1){rhy_step();}
+      pattor(no);
+      tr_len[track]=tr_len[track]+4;i=tr_len[track]-8;
+      trk[track][i]=0xfd;trk[track][i+1]=0;trk[track][i+4]=0xfe;
+      no=meas_no(i);rtopat(no);rtrk_dis(pg,0,32);
+    }
+    if( kc=='?' ){
+      int i=edit_scr;
+      pattor(no);
+      B_CLR_AL();
+      cons_md(0);
+      edit_scr=0;
+      fnc_dis(-1);rhy_as();edit_scr=i;B_CLR_AL();edfield(0);
+      trk_no();rtopat(no);rhed_dis(pg);rtrk_dis(pg,0,32);
+      rc=tm_lag-1;fnc_dis(0);
+    }
+
+    if( ke==0x54 ){
+      B_CLR_AL();/*cons_md(0);*/
+      fnc_dis(-1);help(1);B_CLR_AL();edfield(0);
+      trk_no();disp_vels();rhed_dis(pg);rtrk_dis(pg,0,32);
+      rc=tm_lag-1;fnc_dis(0);
+    }
+
+  }
+  tr_pos[track][edit_scr&1][0]=meas_add(no);
+  tr_pos[track][edit_scr&1][1]=0;tr_pos[track][edit_scr&1][2]=0;
+  trrhy[track]=(trrhy[track]&0x80)+pg;trk_lin(track,-1,0);
+  edit_scr=edit_scr&1;B_CLR_AL();
+  if((cmdflag&0x200)==0){
+    MS_LIMIT(0,0,767,511);MS_CUROF();
+  }
+}
+
+/***************************/
+void   rtrk_dis(int p,int ad,int line)
+{
+  char tmp0[256],tmp1[256];
+  unsigned int lc[16];
+  int  po,i,xx,pp,sta,ff=0;
+
+  po=ad;pp=p;
+
+  if(line!=32){
+    if(line<0){line=-line;ff=1;}
+    for(i=po;i<(po+line);i++){
+      xx=21+i*2;
+      if(rpar[i][0]==2){
+       int     j;
+       unsigned char   a;
+       a=rpat[i][0];strcpy(tmp0,"/ ");
+       if(a==0xf8){tmp0[0]=']';}
+       if(a==0xf9){tmp0[0]='[';}
+       B_COLOR(1);for(j=8;j<=23;j++){B_LOCATE(xx,j);B_PRINT(tmp0);}
+       B_LOCATE(xx-2,25+(i&1));
+       if(a<0xf0){B_PRINT(fstr(rpar[i][2],3));}else{B_PRINT("   ");}
+       if( ff ){tcury(xx,8,16,1);}
+
+      }else{
+       if(rpar[i][0]==0){
+         int   j;
+         B_COLOR(2);
+         for(j=0;j<=15;j++){B_LOCATE(xx,8+j);B_PRINT("");}
+         B_LOCATE(xx-2,25+(i&1));B_PRINT("   ");
+         if( ff ){tcury(xx,8,16,2);}
+       }else{
+         int   j;
+         if(rpar[i][2]==0){B_COLOR(2);}else{B_COLOR(3);}
+         for(j=0;j<=15;j++){
+           B_LOCATE(xx,8+j);B_PRINT(rym[vlcl[rpat[i][pp+j]]]);
+         }
+         B_LOCATE(xx-2,25+(i&1));B_PRINT(fstr(rpar[i][2],3));
+         if( ff ){
+           if(rpar[i][2]==0){tcury(xx,8,16,2);
+           }else{tcury(xx,8,16,3);}
+         }     }
+      }
+    }
+  }else{
+    int        i,j;
+    sta=SUPER(0);
+    for(j=0;j<=15;j++){
+      strcpy(tmp0,fstr(p+j+1,2));strcat(tmp0," ");strcat(tmp0,rhyna[p+j]);
+      B_LOCATE(1,j+8);H_PRINT(tmp0,"","");
+
+      B_LOCATE(21,j+8);strcpy(tmp0,"/ ");
+
+      for(i=0;i<32;i++){
+       if(rpar[i][0]==2){
+         unsigned char a;
+         a=rpat[i][0];tmp0[0]='/';
+         if(a==0xf8){tmp0[0]=']';}
+         if(a==0xf9){tmp0[0]='[';}
+         H_PRINT2("","",tmp0);
+       }else{
+         if(rpar[i][0]==0){
+           H_PRINT2("","","");
+         }else{
+           if(rpar[i][2]==0){
+             H_PRINT2("",rym[vlcl[rpat[i][pp+j]]],"");
+           }else{
+             H_PRINT2(rym[vlcl[rpat[i][pp+j]]],"","");
+           }
+         }
+       }
+      }
+    }
+    tmp0[0]=0;tmp1[0]=0;
+    for(i=0;i<32;i=i+2){
+      if(rpar[i][2]==0 || (rpar[i][0]==2 && rpat[i][0]>=0xf0)){
+       strcat(tmp0,"    ");
+      }else{
+       strcat(tmp0,fstr(rpar[i][2],4));
+      }
+
+      if(rpar[i+1][2]==0 || (rpar[i+1][0]==2 && rpat[i+1][0]>=0xf0)){
+       strcat(tmp1,"    ");
+      }else{
+       strcat(tmp1,fstr(rpar[i+1][2],4));
+      }
+    }
+    B_LOCATE(18,25);H_PRINT(tmp0,"","");B_LOCATE(20,26);H_PRINT(tmp1,"","");
+    SUPER(sta);
+    snsclr();
+  }
+
+  {
+    int        i=63,a=0,cu=0,ct,b=1;
+    while(i>=0){
+      unsigned char    c=rpat[i][0];
+      if( c<0xf8 ){
+       if(b==1){a=a+rpar[i][2];}else{a=a+rpar[i][2]*b;}
+      }else{
+       if( c==0xf8 ){
+         if(cu<15){
+           ct=rpat[i][1];if(ct==0){ct=256;}
+           lc[cu]=b;b=b*ct;cu++;
+         }
+       }
+       if( c==0xf9 ){
+         if(cu>0){cu--;b=lc[cu];}
+       }
+      }
+      i=i-1;
+    }
+    strcpy(tmp0,"TOTAL:");strcat(tmp0,fstr(a,5));
+    B_COLOR(3);B_LOCATE(69,29);B_PRINT(tmp0);
+  }
+}
+
+/***************************/
+void   rhed_dis(int p)
+{
+  int  i;
+
+  for(i=0;i<=15;i++){
+    B_LOCATE(1,i+8);B_PRINT(fstr(p+i+1,2));B_PRINT(" ");
+    B_PRINT(spadd(rhyna[p+i],14));}
+
+}
+
+/***************************/
+void   rhy_step()
+{
+  int  i;
+  /*
+    bain:      msg("BAR ST=");i=vinput(barstep,0x803);msg_clr();
+    if(i<48||i>480){goto stin;}
+    barstep=i;
+    stin:
+    B_LOCATE(12,1);
+    B_PRINT("STEP ST=");i=vinput(dfstep,0x803);msg_clr();
+    */
+
+stin:  msg("STEP ST=");i=vinput(dfstep,0x803);msg_clr();
+if(i<6||(i>96 && i!=192)){goto stin;}
+dfstep=i;
+}
+
+/**************************0fl 2st 3cl   mode 0=nul 1=onpu 2=spcial */
+void   rtopat(int me)
+{
+  char tmp0[256];
+  int  ad,i,j,xp=0;
+
+  ad=meas_add(me);
+  B_LOCATE(2,5);strcpy(tmp0,"MEAS=");strcat(tmp0,fstr(meas_no(ad),4));B_PRINT(tmp0);
+  B_LOCATE(14,5);
+  if(trk[track][ad]==0xfc){
+    strcpy(tmp0,"=== SAME MEAS");
+    strcat(tmp0,fstr((trk[track][ad+2]&3)*256+trk[track][ad+1]+1,4));
+    strcat(tmp0," ===");B_PRINT(tmp0);
+  }else{
+    B_PRINT("                     ");
+  }
+
+  for(i=0;i<=63;i++){
+    for(j=0;j<=63;j++){rpat[i][j]=0;}
+    for(j=0;j<=4;j++){rpar[i][j]=0;}
+  }
+  rpar[64][0]=0;
+
+  if(trk[track][ad]>=0xfe ||(trk[track][ad]>=0xfc && trk[track][ad+4]>=0xfe)){
+    for(j=0;j<(barstep/dfstep);j++){rpar[j][2]=dfstep;rpar[j][0]=1;}
+    return;
+  }
+  radr[0]=ad;
+
+  while(1){
+    unsigned char      a,b,c,d;
+    a=trk[track][ad];b=trk[track][ad+1];c=trk[track][ad+2];d=trk[track][ad+3];
+    if(xp>63){
+      msg(_("This track has too many steps. Cannot edit."));
+      xp++;rpar[64][0]=1;break;}
+    if(a>0xfb){if(rpar[xp][0]){xp++;}
+    break;}
+
+    if(a<128){
+      rpar[xp][0]=1;rpar[xp][4]++;
+      if( c>0 && d>0){
+       int     mf=0;
+       for(i=0;i<=31;i++){
+         if(rhyno[i][0]==a){
+           rpat[xp][i]=d;rpat[xp][i+32]=c;mf=1;break;}
+       }
+       if(mf==0){
+         int   p;
+         p=rpar[xp][3];if(p<64){p=64;}
+         rpat[xp][p]=a;rpat[xp][p+1]=0;
+         rpat[xp][p+2]=c;rpat[xp][p+3]=d;
+         rpar[xp][3]=p+4;
+         if(p==124){if(b==0){xp++;}}
+       }else{
+         int   p;
+         p=rpar[xp][3];if(p<4){rpar[xp][3]=4;}
+       }
+      }
+      if(b>0){rpar[xp][2]=b;radr[xp++]=ad+4;}
+    }else{
+      int      p;
+      if(rpar[xp][0]==1||(rpar[xp][0]==2&&(a==0xf8||a==0xf9))){
+       radr[xp++]=ad+4;}
+
+      rpar[xp][0]=2;p=rpar[xp][3];
+      rpat[xp][p]=a;rpat[xp][p+1]=b;rpat[xp][p+2]=c;rpat[xp][p+3]=d;
+      if(a<0xf6){rpar[xp][2]=rpar[xp][2]+b;}
+      rpar[xp][3]=p+4;rpar[xp][4]++;
+
+      if((a==0xf7 && trk[track][ad+4]!=0xf7)||a==0xf8 || a==0xf9 ||
+        trk[track][ad+4]<128||p==124||b>0){
+       radr[xp++]=ad+4;
+      }
+    }
+    ad=ad+4;
+  }
+  if(xp){
+    for(i=xp;i<=63;i++){
+      for(j=0;j<=63;j++){rpat[i][j]=0;}
+      for(j=0;j<=4;j++){rpar[i][j]=0;}
+    }
+  }
+}
+
+/***************************/
+void   pattor(int me)
+{
+  int  ad,i,c,p,po=0;
+
+  if(rpar[64][0]!=0){return;}
+
+  for(i=0;i<=63;i++){
+    p=rpar[i][0];
+
+    if(p==2){
+      c=rpar[i][3];
+      if(c>0){
+       int     j;
+       for(j=0;j<c;j++){dat[po+j]=rpat[i][j];}
+       po=po+c;
+      }
+    }
+    if(p<=1 && (rpar[i][2]>0||rpar[i][3]>0) ){
+      int      j,cf=0,c;
+      for(j=0;j<=31;j++){if(rpat[i][j]>0){cf++;}}
+      if(cf!=0){
+       for(j=0;j<=31;j++){
+         if(rpat[i][j]>0){
+           dat[po]=rhyno[j][0];dat[po+1]=0;
+           dat[po+2]=rpat[i][j+32];dat[po+3]=rpat[i][j];
+           po=po+4;
+         }
+       }
+      }else{
+       if(rpar[i][3]<64){
+         dat[po]=0;dat[po+1]=rpar[i][2];dat[po+2]=0;dat[po+3]=0;
+         po=po+4;
+       }
+      }
+      c=rpar[i][3]-64;
+      if(c>0){
+       int     j;
+       for(j=0;j<c;j++){dat[po+j]=rpat[i][64+j];}
+       po=po+c;
+      }
+      dat[po-3]=rpar[i][2];
+    }
+  }
+  dat[po]=0xfd;po+=4;
+
+  ad=meas_add(me);c=meas_len(ad);
+  if(trk[track][ad]==0xfc){return;}
+  if(po<c){trk_delete(ad,c-po);}
+  if(po>c){if(trk_shift(ad,po-c)!=0){return;}}
+  for(i=0;i<po;i++){trk[track][ad+i]=dat[i];}
+}
+
+/***************************/
+void   rsttrc(int *no,int *cx,int flg,int pg)
+{
+  int  ad,rad,i,j,ii,jj,jjj=0,a,skf,ofs,nn=0;
+  int  me_ad[2048];
+  int  max;
+  int  lpad[18],lprt[18];
+  unsigned char lpco[18];
+  unsigned char        *ptr;
+
+  ptr=(unsigned char *)trk[track];
+  max=add_set(track,me_ad);
+
+  skf=poft>>16;ofs=poft&0xffff;
+  while( ( (B_SFTSNS()&16)!=0 || flg!=0 ) && rcd->active[track] && rcd->act!=0){
+    if(B_KEYSNS()!=0){
+      int      k=B_KEYINP()>>8,sh=B_SFTSNS();
+      if(k==1){break;}
+      if((sh&15)==0){
+       if(k==0x57){rcd->sts=0;}
+       if(k==0x58){rcd->sts=1;}
+       if(k==0x59){all_note_off(2);break;}
+      }
+    }
+
+    ad=meas_add(ofs+1);if(ad<0){break;}
+    nn=0;rad=0;
+
+    STed_MeasureConversion(track); /* Dec.11.1998 Daisuke Nagano */
+    j=rcd->bar[track];jj=j;i=rcd->step[track];ii=i;
+    if(skf!=0){if(j==0){i=0;}else{j--;}}
+
+    while(j>0 || i>0){
+      unsigned char    ca;
+    loop1:                     ca=ptr[ad];ad+=4;if(ca==0xf7){goto loop1;}
+    if(ca>0xfd ){ad-=4;break;}
+
+    if((ca>=0xfc || ptr[ad]==0xfc)&& rad!=0){ad=rad;rad=0;
+    if(j>0){j--;if(j==0 && i==0){break;}}
+    goto loop1;
+    }
+
+    if( ca==0xfc ){
+      int      ii0,jj0,ct;
+      jj0=ad-4;
+    resame:
+      ct=ptr[jj0+1]+(ptr[jj0+2]&3)*256;ii0=me_ad[ct];
+      if(ct<max && jj0!=ii0){
+       jj0=ii0;if(ptr[ii0]==0xfc){goto resame;}
+       rad=ad;ad=ii0;
+      }
+      goto loop1;
+    }
+
+    if(j>0){
+      if(ca>=0xfc || ptr[ad]==0xfc){
+       j--;if(j==0 && i==0){break;}
+      }
+    }else{
+      if(ca<0xf8){i--;if(i==0){ad-=4;break;}}
+    }
+
+    if(ca==0xf9 && nn<16){
+      nn++;lpad[nn]=ad;lprt[nn]=rad;lpco[nn]=0;
+    }
+    if(ca==0xf8 && nn>0){
+      lpco[nn]+=1;
+      if(lpco[nn]!=ptr[ad+1-4]){ad=lpad[nn];rad=lprt[nn];goto loop1;}
+      nn--;
+    }
+
+    }
+    if(rad!=0){ad=rad-4;}
+
+    if(ptr[ad]==0xfe && ad>0){ad-=4;}
+    a=meas_no(ad);
+
+    if(jjj!=a){rtopat(a);rtrk_dis(pg,0,32);jjj=a;}
+    *no=a;
+
+    for(i=0;i<32;i++){
+      if(radr[i]>ad){break;}
+    }
+    if(i>31){i=0;}
+
+    *cx=i;
+    if(flg==0){
+      rtrk_dis(pg,*cx,-1);
+      while(jj==rcd->bar[track] && ii==rcd->step[track]){
+       if(B_KEYSNS()!=0){break;}
+       if( !(rcd->active[track]) ){break;}
+       STed_MeasureConversion(track); /* Dec.11.1998 Daisuke Nagano */
+      }
+      rtrk_dis(pg,*cx,1);
+    }
+    flg=0;
+  }
+  LEDMOD(0,0);snsclr();
+}
+
+/***************************/
+void   disp_vels()
+{
+  int  i,col;
+
+  for(i=0;i<10;i++){
+    col=0;if(i==dfvel){col=8;}
+    sdis2(50+i*3,592,rym_s[i],3,15,col);
+  }
+}
+
+/***************************/
diff --git a/resource.h b/resource.h
new file mode 100644 (file)
index 0000000..50c9f5b
--- /dev/null
@@ -0,0 +1,44 @@
+//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by STed2.rc
+//
+#pragma once
+
+#define IDC_MYICON                      2
+#define IDD_STED2_DIALOG                102
+#define IDD_PREF_MIDIDEVICE             102
+#define IDS_APP_TITLE                   103
+#define IDD_ABOUTBOX                    103
+#define IDM_ABOUT                       104
+#define IDM_EXIT                        105
+#define IDI_STED2                       107
+#define IDI_SMALL                       108
+#define IDC_STED2                       109
+#define IDR_MAINFRAME                   128
+#define IDM_PREFS_MIDIPORTS             129
+#define IDM_PLAY_PLAYALL                130
+#define IDM_PLAY_PLAYTRACK              131
+#define IDM_PLAY_PLAYMEASURE            132
+#define IDM_PLAY_STOP                   133
+#define ID_Menu                         134
+#define IDM_PLAY_TRACE                  135
+#define ID_EDIT_RHYTHMTRACK             136
+#define IDM_EDIT_RHYTHMTRACK_CURRENTMEAS 137
+#define IDM_EDIT_RHYTHMTRACK_NEWMEAS    138
+#define IDC_MIDIIN                      1000
+#define IDC_MIDIOUT0                    1001
+#define IDC_MIDIOUT1                    1004
+#define IDC_VERSION                     1005
+#define IDC_STATIC                      -1
+
+// Next default values for new objects
+// 
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NO_MFC                     1
+#define _APS_NEXT_RESOURCE_VALUE        139
+#define _APS_NEXT_COMMAND_VALUE         32771
+#define _APS_NEXT_CONTROL_VALUE         1006
+#define _APS_NEXT_SYMED_VALUE           110
+#endif
+#endif
diff --git a/scdsp.cpp b/scdsp.cpp
new file mode 100644 (file)
index 0000000..e434a02
--- /dev/null
+++ b/scdsp.cpp
@@ -0,0 +1,42 @@
+/*
+  scdsp.c
+
+  functions for compatibility in scdsp.s
+
+  scpanel_dsp , scinst_dsp 
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "sted.h"
+
+void scpanel_dsp( int x, int y, unsigned char *dp ) {
+
+  /* not implemented */
+  return;
+}
+
+void scinst_dsp ( int x, int y, unsigned char *dp ) {
+
+  /* not implemented */
+  return;
+}
+
diff --git a/score.cpp b/score.cpp
new file mode 100644 (file)
index 0000000..df3102a
--- /dev/null
+++ b/score.cpp
@@ -0,0 +1,671 @@
+/*
+ * STed: score.c  (fumen & data draw subroutine)
+ */
+#include       "sted.h"
+#define NORMAL 1
+
+/*
+誅
+誂    誡
+誄    誑
+*/
+/*
+char   o_zero[12][3]  ={"覲","覺","覽","覿","觀","觚","觜","觝","觧","觴","觸","訃"};
+char   o_flag_u[12][3]={"  ","襪","襪","襪","襪","襯","襯","襴","襴","襷","襷","襾"};
+*/ /* Sep.04.1998 Daisuke Nagano */
+char   o_zero[12][3]  ={"  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  ","  "};
+char   o_flag_u[12][3]={"  ","♪","♪","♪","♪","♪","♪","♪","♪","♪","♪","♪"};
+char   o_head_u[12][3]={"・","・","・","・","・","・","・","・","・","・","・","・"};
+char   o_head_d[12][3]={"・","・","・","・","・","・","・","・","・","・","・","・"};
+char   o_flag_d[12][3]={"  ","・","・","・","・","・","・","・","・","・","・","・"};
+
+char   onp_ps[12]={0,0,1,1,2,3,3,4,4,5,5,6};
+char   sharp_yp[14]={0*4,3*4,-1*4,2*4,5*4,1*4,4*4 , 4*4,1*4,5*4,2*4,6*4,3*4,7*4};
+
+int    ga_adr[512],ga_xpo[512],ga_co;
+int    gr_adr[512],gr_xpo[512],gr_co;
+
+
+/***************************/
+void   gra(int po,int sh)
+{
+  if(grpmode<4){
+    if(grpmode&1){gra_gakufu(po,sh);}
+    if(grpmode&2){gra_special(po,sh);}
+  }
+//  if(grpmode==4){exc_view(po);} // Ugh!: it causes keyboard-lock up : Oct.19.2002 Nagano
+}
+
+/***************************/
+void   gra_c(int po)
+{
+  int  i,xx;
+
+  if(grpmode<4){
+    if(grpmode&1){
+      for(i=0;i<ga_co-1;i++){
+       if(ga_adr[i+1]>po){
+         xx=(ga_xpo[i]+ga_xpo[i+1])>>1;
+         txyline(xx,592-512,850-592,1,65535);
+         break;
+       }
+      }
+    }
+    if(grpmode&2){
+      int yy=872-512;if((grpmode&1)==0){yy=yy-128;}
+      for(i=0;i<gr_co-1;i++){
+       if(gr_adr[i+1]>po){
+         xx=gr_xpo[i];txyline(xx,yy,999-872,1,65535);
+         break;
+       }
+      }
+    }
+  }
+}
+
+/***************************/
+void   gra_gakufu(int po,int md)
+{
+  int  a,b,c,d,i,ad,ad2,gx,cc=0,skey,co=0;
+  int  tb=(tbase/48);
+  char tmp0[128];
+  unsigned char        kno[512];
+  unsigned char *ptr=trk[track];
+
+  if((md&16)==0){
+    fill(328-8,590,766,851,0);box(327,589,767,852,14,65535);
+  }else{
+    fill(392-44,590,766,851,0);
+  }
+  for(i= 0;i<= 4;i++){
+    line(327+48,680- 56+i*8,767,680- 56+i*8,14,0xcccc);
+    line(327   ,680    +i*8,767,680    +i*8,14,0xffff);
+    line(327   ,680+ 48+i*8,767,680+ 48+i*8,14,0xffff);
+    line(327+48,680+104+i*8,767,680+104+i*8,14,0xcccc);
+  }
+  g_print(330,675,"・",15);g_print(330,691,"・",15);g_print(330,707,"・",15);
+  g_print(330,728,"・",15);g_print(330,744,"・",15);
+
+  gx=392;ad=gra_add(po,md);
+
+  skey=bkey;
+  ad2=ad;
+  while(ad2>=0){
+    if(ptr[ad2]>0xfc ){break;}
+    if(ptr[ad2]==0xf5 ){skey=ptr[ad2+1];}
+    ad2-=4;
+  }
+
+  if(trrhy[track]&0x80){skey=0;}
+  put_sharp(skey,328+20,670);put_sharp(skey,328+20,670+14*4);
+
+  while(gx<760 && ad<tr_len[track]-4){
+  ggloop:              a=ptr[ad];if(a==0xf7){ad+=4;goto ggloop;}
+  b=ptr[ad+1];c=ptr[ad+2];d=ptr[ad+3];
+  if(tb>1){b=b/tb;}
+
+  ad2=ad;
+  if(b){ga_adr[co]=ad;ga_xpo[co++]=gx;}
+
+  if(a>0xf4 ){
+    gx=gx+3;
+    if(a==0xf9 ){
+      line(gx,680,gx  ,760,11,65535);
+      line(gx,680,gx+3,680,11,65535);
+      line(gx,760,gx+3,760,11,65535);
+    }
+    if(a==0xf8 ){
+      line(gx  ,680,gx,760,11,65535);
+      line(gx-3,680,gx,680,11,65535);
+      line(gx-3,760,gx,760,11,65535);
+    }
+    if(a>=0xfc ){
+      line(gx,680,gx,760,14,65535);skey=bkey;
+      if(trrhy[track]&0x80){skey=0;}
+    }
+    gx=gx-3;
+    if(a==0xf5 && gx!=392){
+      skey=b;
+      if(trrhy[track]&0x80){skey=0;}
+      put_sharp(skey,gx,670);put_sharp(skey,gx,670+14*4);
+      b=44;
+    }else{b=2;}
+    goto next;
+  }
+
+  if(a<128){
+    if(c==0 || d==0){
+      kno[cc]=255;cc++;
+    }else{
+      kno[cc]=a;cc++;
+    }
+  }
+
+  if(b>0){
+    int        xx,bb=0,e,f,i,ss;
+    i=ad;while(i<tr_len[track]-4){
+    loop:                              i+=4;e=ptr[i];f=ptr[i+1];
+
+    if(e==0xf6 || e==0xf7){goto loop;}
+    if(e<0x80 || e>=0xf0){
+      if(e<0x80 && (ptr[i+2]==0||ptr[i+3]==0)){
+       if(cc==0 || (cc==1 && kno[0]==255)){
+         bb+=f;goto loop;
+       }
+      }
+      ad=i-4;break;
+    }
+    bb+=f;
+    }
+    if(tb>1){bb=bb/tb;}
+    b+=bb;
+
+    xx=gx-6+(b>>1);if(gx==392 && b>40){xx=xx-(b>>1)+6;}
+    ss=st_cv(b);
+
+    if(cc==0 || (cc==1 && kno[0]==255)){
+
+      strcpy(tmp0,o_zero[ss]);
+      g_print(xx,688,tmp0,15);g_print(xx,688+6*8,tmp0,15);
+    }else{
+      int      ff,y,f,i,a,sff;
+
+      ff=9999;strcpy(tmp0,o_head_u[ss]);
+      for(i=0;i<cc;i++){
+       a=kno[i];
+       if(a>9 && a<108){
+         f=((a*43))>>9;a=a-(f*12);
+         sff=key_shift(skey,&f,&a);
+         f=onp_ps[a]+f*7;y=(819+7*4)-(f*4);
+
+         if(y==651||y==659||y==707||y==755||y==763){
+           g_print(xx-2,y,"・",14);}
+
+         g_print(xx,y,tmp0,15);
+         if(sff>0){g_print(xx-10,y+4,"・",15);}
+         if(sff<0){g_print(xx-10,y+4,"・",15);}
+         if(y<ff){ff=y;}
+       }
+      }
+      if(ff<9999){g_print(xx,ff-6,o_flag_u[ss],15);}
+    }
+    cc=0;
+  }
+  next:
+  if(po<=ad && (md&32)==0 && (b>0 || a>0xf0)){
+    int        xx,bb=b;
+
+    xx=gx;
+    if(a<0xf0){xx+=(bb>>1)-1;if(gx==392 && bb>40){xx=xx-(bb>>1)+5;}}
+    else{xx+=2;}
+    line(xx,592,xx,850,8,65535);
+    po=tr_len[track]+4;
+  }
+
+  if(gx==392 && b>40){b=b-(b>>1)+6;}
+  gx=gx+b;ad=ad+4;
+  }
+  ga_co=co;
+}
+
+/***************************/
+void   gra_special(int po,int md)
+{
+  int  a,b,c,d,bb,i,ad,gx,co=0,retad=0;
+  int  pitch,opitch,velo,ovel,vol,ovol,modu,omodu,expr,oexpr,entry,oentry;
+  int  pan,opan;
+  int  tb=(tbase/48);
+  int  me_ad[2048];
+  unsigned char *ptr=trk[track];
+
+  int ys=1;
+  if((grpmode&1)==0){ys=2;}
+
+  add_set(track,me_ad);
+  gx=392;ad=gra_add(po,md);
+
+  if((md&16)==0){
+    fill(328-8,857+15+128-128*ys,766,1000,0);
+    box(327,856+128-128*ys,767,1001,14,65535);
+    sdis(41,856+128-128*ys," CONTOROLER GRAPHIC DISPLAY",55,15,14);
+  }else{
+    fill(392,857+15+128-128*ys,766,1000,0);
+  }
+
+  line(327,936+64-ys*64,767,936+64-64*ys,14,0xaaaa);
+
+  opitch=-1;ovol=-1;oexpr=-1;omodu=-1;oentry=-1;opan=-1;
+
+  i=ad;while(i>0){
+    unsigned char      d;
+  top:
+    i=i-4;d=ptr[i];
+    if(d==0xee && opitch<0){
+      opitch=(ptr[i+3]*128+ptr[i+2])*ys;
+    }
+    if(d==0xeb){
+      unsigned char    b=ptr[i+2];
+      if(b== 7 && ovol <0){ovol=ptr[i+3]*ys;}
+      if(b== 1 && omodu<0){omodu=ptr[i+3]*ys;}
+      if(b==11 && oexpr<0){oexpr=ptr[i+3]*ys;}
+      if(b== 6 && oentry<0){oentry=ptr[i+3]*ys;}
+      if(b==10 && opan<0){opan=ptr[i+3]*ys;}
+    }
+
+    if( d>=0xfc && retad!=0){i=retad;retad=0;goto top;}
+
+    if( d==0xfc ){
+      int      ii,jj,ct;
+      jj=i;
+    resame:
+      ct=ptr[jj+1]+(ptr[jj+2]&3)*256;ii=me_ad[ct+1]-4;
+
+      if(jj!=ii && ii>=0){
+       jj=ii;if(ptr[ii]==0xfc){goto resame;}
+       retad=i;i=ii;goto top;
+      }
+    }
+
+  }
+  if(opitch<0){opitch =8192*ys;}
+  if(ovol <0){ovol =100*ys;}
+  if(oexpr<0){oexpr =127*ys;}
+  if(omodu<0){omodu=  0;}
+  if(oentry<0){oentry=  0;}
+  if(opan<0){opan= 64*ys;}
+
+  opitch=(opitch)>>7;
+
+  ovel=0;velo=ovel;pitch=opitch;vol=ovol;expr=oexpr;modu=omodu;entry=oentry;
+  pan=opan;
+
+  while(gx<767 && ad<tr_len[track]-4){
+  gsloop:              a=ptr[ad];if(a==0xf7){ad+=4;goto gsloop;}
+  b=ptr[ad+1];c=ptr[ad+2];d=ptr[ad+3];
+  if(tb>1){b=b/tb;}
+  bb=b;
+
+  if(gx==392 && b>40){b=(b>>1)+6;}
+
+  if(b){gr_adr[co]=ad;gr_xpo[co++]=gx;}
+
+  if(po==ad && (md&32)==0){line(gx,872+128-128*ys,gx,999,8,65535);}
+
+  if(a==0xee){pitch=((d*128+c)*ys)>>7;}
+  if(a==0xeb){
+    if( c==7){vol=d*ys;}
+    if( c==1){modu=d*ys;}
+    if( c==11){expr=d*ys;}
+    if( c==6){entry=d*ys;}
+    if( c==10){pan=d*ys;}
+  }
+  if(a>=0xf0 ){
+    b=0;
+    if(a>=0xfc ){line(gx+3,872+128-128*ys,gx+3,999,14,65535);b=2;}
+    if(a==0xf5 ){b=64;}
+  }
+
+  if(b>0){
+    line(gx,488+512-opitch,gx  ,488+512-pitch,13,65535);
+    line(gx,488+512-ovol  ,gx  ,488+512-vol  ,12,65535);
+    line(gx,488+512-oexpr ,gx  ,488+512-expr , 9,65535);
+    line(gx,488+512-omodu ,gx  ,488+512-modu ,10,65535);
+    line(gx,488+512-oentry,gx  ,488+512-entry,11,0xaaaa);
+    line(gx,488+512-opan  ,gx  ,488+512-pan  ,10,0xaaaa);
+    /*横線*/
+    if(b>1){
+      line(gx,488+512-pitch ,gx+b-1,488+512-pitch,13,65535);
+      line(gx,488+512-vol   ,gx+b-1,488+512-vol  ,12,65535);
+      line(gx,488+512-expr  ,gx+b-1,488+512-expr , 9,65535);
+      line(gx,488+512-modu  ,gx+b-1,488+512-modu ,10,65535);
+      line(gx,488+512-entry ,gx+b-1,488+512-entry,11,0xaaaa);
+      line(gx,488+512-pan   ,gx+b-1,488+512-pan  ,10,0xaaaa);
+    }
+    opitch=pitch;ovol=vol;oexpr=expr;omodu=modu;oentry=entry;
+    opan=pan;
+  }
+
+  if(a<128){
+    int        i;
+    if(c==0 || d==0){
+      ovel=0;
+    }else{
+      int f=0,b2=b;
+
+      velo=d;
+      if(b>0 && c>bb){f=1;}
+      if(b==0 && c>0){
+       i=ad;while(i<tr_len[track]-4){
+         if(ptr[i+1]>0 && ptr[i]<0xf7){
+           b2=ptr[i+1];bb=b2;
+           if(gx==392 && b2>40){b2=(b2>>1)+6;}
+           if(c>ptr[i+1]){f=1;}
+           break;
+         }
+         i=i+4;
+       }
+      }
+      if(b2==bb){
+       line(gx,488+512-ovel*ys,gx,488+512-velo*ys,15,65535);
+      }
+      if(c>b2){c-=(bb-b2);}
+      line(gx,488+512-velo*ys,gx+c,488+512-velo*ys,15,65535);
+      if(f==0){
+       line(gx+c,488+512,gx+c,488+512-velo*ys,15,65535);
+       if(b2>0){ovel=0;}
+      }else{
+       ovel=velo;
+      }
+    }
+  }
+  gx=gx+b;ad=ad+4;
+  }
+  gr_co=co;
+}
+
+/***************************/
+int    gra_add(int ad,int md)
+{
+  int  a=0,i,tr,of,tb;
+  tr=track;
+  i=ad;
+
+  tb=(tbase/48);
+
+  if((md&32)==0){of=96+64;}else{of=24;}
+  of=of*tb;
+
+  while(i>0){
+    i=i-4;
+    if( trk[tr][i]<0xf5 ){
+      a=a+trk[tr][i+1];
+      if(a>=of){
+       while(i>0 && trk[tr][i-4]<0xf5 && trk[tr][i-3]==0){i=i-4;}
+       break;
+      }
+    }
+  }
+  return(i);
+}
+
+/***************************/
+int    st_cv(int st)
+{
+  st=st/(tbase/48);
+
+  if(st>=192-24 ){return  0;}  /*192*/
+  if(st>=144-24 ){return  1;}  /*144*/
+  if(st>= 96-12 ){return  2;}  /* 96*/
+  if(st>= 72-12 ){return  3;}  /* 72*/
+  if(st>= 48- 6 ){return  4;}  /* 48*/
+  if(st>= 36- 6 ){return  5;}  /* 36*/
+  if(st>= 24- 3 ){return  6;}  /* 24*/
+  if(st>= 18- 3 ){return  7;}  /* 18*/
+  if(st>= 12- 1 ){return  8;}  /* 12*/
+  if(st>=  9- 1 ){return  9;}  /*  9*/
+  if(st>=  6- 1 ){return 10;}  /*  6*/
+  return 11;   /*  3*/
+}
+
+/***************************/
+void   put_sharp(int skey,int x,int y)
+{
+  int  a,i,bs;
+  char *tmp0;
+
+  a=skey&7;
+  if(a!=0){
+    /*    if((skey&15)<8){bs=0;tmp0="・";}else{bs=7;tmp0="・";}*//* Aug.17.1998 Daisuke Nagano */
+    if((skey&15)<8){bs=0;tmp0="♯";}else{bs=7;tmp0="♭";}
+    for(i=0;i<a;i++){g_print(x,y+sharp_yp[i+bs],tmp0,15);x+=4;}
+  }
+}
+
+/***************************/
+#if NORMAL
+void   dat_info(int po,int sh)
+{
+  int  i,ln,top,st,pitch=0,ch=mch[track],prg=0,tempo=64,retad=0;
+  char tmp[256];
+  unsigned char        ctr[256];
+  static unsigned char ctno1[16]={7,11,1,10,64,91,93,94, 5,65,66,67,99,101, 6, 0};
+  static unsigned char ctno2[16]={0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0,98,100,38,32};
+
+  static unsigned char ctno3[16]={7,11,1,10,64,91,93,94,71,72,73,74,99,101, 6, 0};
+
+  int  me_ad[2048];
+  unsigned char *ptr=trk[track];
+
+  /*if(sh&10){dat_info2(po,sh);return;}*/
+
+  add_set(track,me_ad);
+
+  top=0;ln=po;
+  if( cplen<0 && cpadd!=po){
+    ln=abs(cpadd-po);if(cpadd>po ){top=po;}else{top=cpadd;}
+  }
+  st=step_cluc2(track,top,ln);
+
+  fill(316,564,453,1001,0);
+  strcpy(tmp,"P.INFO.  /TR.:");
+  strcat(tmp,fstr(track+1,2));
+
+  tmp[7]=(sh&1)+'1';
+
+  sdis(40,571,tmp,16,15,14);
+  box(319,604,448,997,14,65535);box(320,605,447,996,14,65535);
+
+  strcpy(tmp," MEAS:");strcat(tmp,fstr(meas_no(po),4));
+  /*   strcat(tmp,"(");strcat(tmp,fstr(meas_no2(po),5));strcat(tmp,")");*/
+  strcat(tmp,"/");strcat(tmp,fstr(meas_no(tr_len[track]-4),4));strcat(tmp," ");
+
+  sdis2(40,588,tmp,16,15,0);
+
+  for(i=0;i<127;i++){ctr[i]=0;}
+  ctr[7]=100;ctr[11]=127;ctr[10]=64;ctr[91]=40;
+  ctr[71]=64;ctr[72]=64;ctr[73]=64;ctr[74]=64;
+  ctr[128]=64;ctr[129]=64;ctr[130]=64;ctr[131]=64;
+
+  i=0;while(i<=po){
+    unsigned char      d;
+  top:
+    d=ptr[i];
+    if(d==0xeb){ctr[ptr[i+2]]=ptr[i+3];
+    if(ptr[i+2]==6 && ctr[99]==1){
+      if(ctr[98]== 33){ctr[71]=ptr[i+3];}      /*Resonanc*/
+      if(ctr[98]==102){ctr[72]=ptr[i+3];}      /*Rel.Time*/
+      if(ctr[98]== 99){ctr[73]=ptr[i+3];}      /*Att.Time*/
+      if(ctr[98]== 32){ctr[74]=ptr[i+3];}      /*Cutoff F*/
+
+      if(ctr[98]==100){ctr[128]=ptr[i+3];}     /*Decay Time*/
+      if(ctr[98]==  8){ctr[129]=ptr[i+3];}     /*Vibrato Rate*/
+      if(ctr[98]==  9){ctr[130]=ptr[i+3];}     /*Vibrato Depth*/
+      if(ctr[98]== 10){ctr[131]=ptr[i+3];}     /*Vibrato Delay*/
+    }
+    }
+    if(d==0xee){pitch=((ptr[i+3]*128+ptr[i+2])-8192);}
+    if(d==0xec){prg=ptr[i+2];}
+    if(d==0xe2){prg=ptr[i+2];ctr[0]=ptr[i+3];}
+    if(d==0xe7){tempo=ptr[i+2];}
+    if(d==0xe6){ch=ptr[i+2];}
+
+    if( d>=0xfc && retad!=0){i=retad;retad=0;goto top;}
+
+    if( d==0xfc ){
+      int      ii,jj,ct;
+      jj=i;
+    resame:
+      ct=ptr[jj+1]+(ptr[jj+2]&3)*256;ii=me_ad[ct];
+
+      if(jj!=ii){
+       jj=ii;if(ptr[ii]==0xfc){goto resame;}
+       retad=i+4;i=ii;goto top;
+      }
+    }
+    i=i+4;
+  }
+
+  for(i=0;i<15;i++){
+    if((sh&1)==0){
+      strcpy(tmp,ctrl_type(ctno1[i]));strcat(tmp," : ");
+      if(i>11){tmp[5]=':';tmp[6]=0;}
+      strcat(tmp,fstr(ctr[ctno1[i]],3));
+      if(i>11){strcat(tmp,": ");strcat(tmp,fstr(ctr[ctno2[i]],3));}
+    }else{
+      strcpy(tmp,ctrl_type(ctno3[i]));strcat(tmp," : ");
+      strcat(tmp,fstr(ctr[ctno3[i]],3));
+      if(i>11){tmp[0]=0;}
+    }
+    sdis2(41,608+i*16,tmp,13,15,-1);
+  }
+
+  if((sh&1)!=0){
+    sdis2(41,608+12*16,"DECAY    :",9,15,-1);vdis2(51,608+12*16,ctr[128],4,15,-1);
+    sdis2(41,608+13*16,"VIB RATE :",9,15,-1);vdis2(51,608+13*16,ctr[129],4,15,-1);
+    sdis2(41,608+14*16,"VIB DEPTH:",9,15,-1);vdis2(51,608+14*16,ctr[130],4,15,-1);
+    sdis2(41,608+15*16,"VIB DELAY:",9,15,-1);vdis2(51,608+15*16,ctr[131],4,15,-1);
+  }else{
+    sdis2(41,880-32,"PITCH   :",9,15,-1);vdis2(50,880-32,pitch,5,15,-1);
+  }
+  sdis2(41,896-32,"TEMPO:   (    )",16,15,-1);vdis2(47,896-32,tempo,3,15,-10);
+  vdis2(51,896-32,(tempo*mtempo+33)>>6,4,15,-1);
+
+  sdis2(41,912-32,"MIDI CH.:",9,15,-1);
+  strcpy(tmp,chstr(ch));sdis2(52,912-32,tmp,3,15,-1);
+
+  sdis2(41,896,"BANK MSB:",16,15,-1);vdis2(52,896,ctr[0],3,15,-10);
+  sdis2(41,912,"BANK LSB:",16,15,-1);vdis2(52,912,ctr[32],3,15,-10);
+
+  if(ch!=0){
+    sdis2(41,928,"PROGRAM :",9,15,-1);
+    sdis2(43,944,prog_name(ch,ctr[0]+ctr[32]*256,prg,0),10,15,-1);
+    if((cmdflag&0x20)!=0){prg++;}
+    vdis2(51,928,prg,4,15,-1);
+  }
+  sdis(41,962,"= TOTAL ST. =",5,15,-1);vdis2(45,978,st,10,15,-1);
+}
+/*#endif*/ /* Jun.26.1998 by Daisuke Nagano */
+/***************************/
+
+#else /* NORMAL */
+/***************************/
+void   dat_info(int po,int sh)
+{
+  int  i,ln,top,st,pitch=0,ch=mch[track],prg=0,tempo=64,retad=0;
+  char tmp[256];
+  unsigned char        ctr[256];
+  static unsigned char ctno1[24]={7,11,1,10,64,91,93,94, 5,65,66,67,71,72,73,74,128,129,130,131,99,101, 6, 0};
+  static unsigned char ctno2[24]={0, 0,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,98,100,38,32};
+
+  static char  vib_name[4][10]={"DECAY    ","VIB RATE ","VIB DEPTH","VIB DELAY"};
+
+
+  int  me_ad[2048];
+  unsigned char *ptr=trk[track];
+
+  add_set(track,me_ad);
+
+  top=0;ln=po;
+  if( cplen<0 && cpadd!=po){
+    ln=abs(cpadd-po);if(cpadd>po ){top=po;}else{top=cpadd;}
+  }
+  st=step_cluc2(track,top,ln);
+
+  fill(316,564,453,1001,0);
+  strcpy(tmp,"P.INFO.  /TR.:");
+  strcat(tmp,fstr(track+1,2));
+
+  sdis(40,571,tmp,16,15,14);
+  box(319,604,448,997,14,65535);box(320,605,447,996,14,65535);
+
+  strcpy(tmp,"MEAS:");strcat(tmp,fstr(meas_no(po),4));
+  strcat(tmp,"/");strcat(tmp,fstr(meas_no(tr_len[track]-4),4));
+
+  sdis2(41,588,tmp,16,15,0);
+
+  for(i=0;i<127;i++){ctr[i]=0;}
+  ctr[7]=100;ctr[11]=127;ctr[10]=64;ctr[91]=40;
+  ctr[71]=64;ctr[72]=64;ctr[73]=64;ctr[74]=64;
+  ctr[128]=64;ctr[129]=64;ctr[130]=64;ctr[131]=64;
+
+  i=0;while(i<=po){
+    unsigned char      d;
+  top:
+    d=ptr[i];
+    if(d==0xeb){ctr[ptr[i+2]]=ptr[i+3];
+    if(ptr[i+2]==6 && ctr[99]==1){
+      if(ctr[98]== 33){ctr[71]=ptr[i+3];}      /*Resonanc*/
+      if(ctr[98]==102){ctr[72]=ptr[i+3];}      /*Rel.Time*/
+      if(ctr[98]== 99){ctr[73]=ptr[i+3];}      /*Att.Time*/
+      if(ctr[98]== 32){ctr[74]=ptr[i+3];}      /*Cutoff F*/
+
+      if(ctr[98]==100){ctr[128]=ptr[i+3];}     /*Decay Time*/
+      if(ctr[98]==  8){ctr[129]=ptr[i+3];}     /*Vibrato Rate*/
+      if(ctr[98]==  9){ctr[130]=ptr[i+3];}     /*Vibrato Depth*/
+      if(ctr[98]== 10){ctr[131]=ptr[i+3];}     /*Vibrato Delay*/
+    }
+    }
+    if(d==0xee){pitch=((ptr[i+3]*128+ptr[i+2])-8192);}
+    if(d==0xec){prg=ptr[i+2];}
+    if(d==0xe2){prg=ptr[i+2];ctr[0]=ptr[i+3];}
+    if(d==0xe7){tempo=ptr[i+2];}
+    if(d==0xe6){ch=ptr[i+2];}
+
+    if( d>=0xfc && retad!=0){i=retad;retad=0;goto top;}
+
+    if( d==0xfc ){
+      int      ii,jj,ct;
+      jj=i;
+    resame:
+      ct=ptr[jj+1]+(ptr[jj+2]&3)*256;ii=me_ad[ct];
+
+      if(jj!=ii){
+       jj=ii;if(ptr[ii]==0xfc){goto resame;}
+       retad=i+4;i=ii;goto top;
+      }
+    }
+    i=i+4;
+  }
+
+  for(i=0;i<23;i++){
+    int nn=ctno1[i];
+    if(nn<128){strcpy(tmp,ctrl_type(nn));strcat(tmp," : ");
+    }else{
+      strcpy(tmp,vib_name[nn-128]);strcat(tmp,": ");
+    }
+    if(i>19){tmp[5]=':';tmp[6]=0;}
+    strcat(tmp,fstr(ctr[ctno1[i]],3));
+    if(i>19){strcat(tmp,": ");strcat(tmp,fstr(ctr[ctno2[i]],3));}
+
+    sdis3(41,608+i*10,tmp,13,15,-1);
+  }
+
+  sdis3(41,608+10*23,"PITCH   :",9,15,-1);vdis3(50,608+10*23,pitch,5,15,-1);
+
+  sdis2(41,896-32,"TEMPO:   (    )",16,15,-1);vdis2(47,896-32,tempo,3,15,-10);
+  vdis2(51,896-32,(tempo*mtempo+33)>>6,4,15,-1);
+
+  sdis2(41,912-32,"MIDI CH.:",9,15,-1);
+  strcpy(tmp,chstr(ch));sdis2(52,912-32,tmp,3,15,-1);
+  /*
+    sdis3(41,608+10*25,"TEMPO:   (    )",16,15,-1);vdis3(47,608+10*25,tempo,3,15,-10);
+    vdis3(51,608+10*25,(tempo*mtempo+33)>>6,4,15,-1);
+
+    sdis3(41,608+10*26,"MIDI CH.:",9,15,-1);
+    strcpy(tmp,chstr(ch));sdis3(52,608+10*26,tmp,3,15,-1);
+    */
+
+  sdis2(41,896,"BANK MSB:",16,15,-1);vdis2(52,896,ctr[0],3,15,-10);
+  sdis2(41,912,"BANK LSB:",16,15,-1);vdis2(52,912,ctr[32],3,15,-10);
+
+  if(ch!=0){
+    sdis2(41,928,"PROGRAM :",9,15,-1);
+    sdis2(43,944,prog_name(ch,ctr[0]+ctr[32]*256,prg,0),10,15,-1);
+    if((cmdflag&0x20)!=0){prg++;}
+    vdis2(51,928,prg,4,15,-1);
+  }
+  sdis(41,962,"= TOTAL ST. =",5,15,-1);vdis2(45,978,st,10,15,-1);
+  /*   sdis3(41,962+6,"= TOTAL ST. =",5,15,-1);vdis2(45,978,st,10,15,-1);*/
+}
+#endif
+/***************************/
diff --git a/select.cpp b/select.cpp
new file mode 100644 (file)
index 0000000..7e9c4af
--- /dev/null
@@ -0,0 +1,1405 @@
+/*
+ * STed: select.c (selecter)
+ */
+#include       "sted.h"
+
+
+static char    *fsel_ext[]={
+  "R36:RCP:MID","RCP:R36:MID","CM6","GSD","DEF:DFB","TRK","PRT","TXT","EXC",
+  "REX","RES","RAS"};
+
+static char    *fsel_title[]={
+  "COMPOSE","COMPOSE","CM-CONTROL","GS-CONTROL","DEFINE","TRACK",
+  "PART","TEXT","EXCLUSIVE(TEXT)",
+  "User Exclusive(ALL)","User Exclusive(ONE)","RHYTHM ASSIGN"};
+
+static char    speci_sym[24]={
+  'G','M','T','P','C','K','L','D','V','N','E','H','A',0,'X','B','R','I',
+  'E','E','N','N','R','R'};
+
+static char    speci_sym2[24]={
+  0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,0, 0 , 0 , 0 , 0 ,
+  'M','L','M','L','M','L'};
+
+static char    speci_name[24][9]={
+  "PROGRAM ","MIDI CH.","TEMPO   ","PITCH   ","AFTER C.","AFTER K.","CONTROL ",
+  "MODULAT ","VOLUME  ","PANPOT  ","EXPRESS ","HOLD1   ","RES.ALL ","        ",
+  "Tr.Exclu","Rol.Base","Rol.Para","Rol.Dev#",
+  "DATA MSB","DATA LSB","NRPN MSB","NRPN LSB","RPN MSB ","RPN LSB "};
+
+/*              1234567890123456789012345678901234567890*/
+static char    *speci_come[24]={
+  "PROGRAM CHANGE",
+  "MIDI CHANNEL CHANGE",
+  "TEMPO CHANGE",
+  "PITCH BEND CHANGE",
+  "AFTER TOUCH(CH.)",
+  "AFTER TOUCH(POLY)",
+  "CONTROL CHANGE",
+  "MODULATION",
+  "VOLUME",
+  "PANPOT",
+  "EXPRESSION",
+  "HOLD1(DAMPER PEDAL)",
+  "RESET ALL CONTROLLERS",
+  "",
+  "Track Exclusive",
+  "Roland Base Address",
+  "Roland Offset Add. & Para.",
+  "Roland Device No. & Model ID",
+  "Data Entry(MSB)",
+  "Data Entry(LSB)",
+  "Non Registerd Parameter MSB",
+  "Non Registerd Parameter LSB",
+  "Registerd Parameter MSB",
+  "Registerd Parameter LSB"};
+
+static char    *repl_title[3]={
+  " Replace"," Delete"," Find"};
+
+int    fsdirp[256],fsdiry[256];/*check*/
+extern int     tkey,tvel;
+
+
+/***************************/
+int    timsel(int bmode,int bank,int gx,int prog)
+{
+  int  a,nm=0,i,i0,p=0,y=0,dx,scr,sut=0,sh;
+  int  ch,ch2,bank2,bank_l,bank_l2,as,as2,md=0,wd=0;
+  char tmp0[256],tmp1[256];
+
+  tkey=60;tvel=127;
+
+  if(bmode&0x100){md=1;wd=2;}
+  ch=bmode&0xff;bank_l=(bank>>8)&0x7f;bank=bank&0x7f;
+  dx=gx*8;es=0;as=tim_asin[ch];
+  if(prog>=0){p=prog&0xf0;y=prog&15;}
+  /*
+    if(gs_mode[16]!=0 && as==7){as=gs_bank[16*128+bank_l];}
+    if(gs_mode[17]!=0 && as==8){as=gs_bank[17*128+bank_l];}
+    */
+  if((gs_mode[16]&4)!=0){
+    if((gs_mode[16]&128)!=0 && as==7){as=gs_bank[16*128+bank_l];}
+    if((gs_mode[17]&128)!=0 && as==8){as=gs_bank[17*128+bank_l];}
+  }else{
+    if((gs_mode[16]&128)!=0 && as==7){as=gs_bank[16*128+bank];}
+    if((gs_mode[17]&128)!=0 && as==8){as=gs_bank[17*128+bank];}
+  }
+
+  if((as==7||as==9||as==11||as==13)&&(gs_mode[as]&4)!=0){bank=bank_l;}
+
+  if(as==0||as>399||(md==0 && as==2)){es=1;return(-1);}
+  scr=edit_scr;edit_scr=0;as2=as;ch2=ch;bank2=bank;bank_l2=bank_l;
+
+  fill(dx+316,566,dx+453+wd*8,997,0);
+  fill(dx+316,650,dx+452,706,14);
+  /*   box(dx+316,707,dx+452+wd*8,988,14,65535);
+       box(dx+317,708,dx+451+wd*8,987,14,65535);*/
+
+  /*   box(dx+316,707,dx+452+wd*8,988+4,14,65535);
+       box(dx+318,709,dx+450+wd*8,986-8,14,65535);*/
+
+  box(dx+316,707,dx+452+wd*8,988,14,65535);
+  box(dx+318,709,dx+450+wd*8,986,14,65535);
+
+  box(320+dx,602,448+dx,644,14,65535);
+  box(322+dx,604,446+dx,642,14,65535);
+
+  stest_para_disp(gx+44);
+  B_LOCATE(gx+40,9);B_PRINT("## TONE LIST ##");
+
+  if((cmdflag&0x2000)!=0 && (as==7||as==9||as==11||as==13)/* && bank<64*/){
+    int n=timsel2(ch,bank_l*256+bank,gx,prog);
+    prog=n&0xff;bank=n>>8;p=prog&0xf0;y=prog&15;
+    if(es==0||es==-2){goto skip;}
+  }
+
+top:
+  while(1){
+    tdis(gx+40,10,tim_head[as-1],18,3);tmp0[0]=0;
+    if(as>=7 && as<=14 && (md!=0 ||(as&1)!=0)){
+      i0=gs_bank[as*128+bank];
+      if(i0>0){strcpy(tmp0,tim_head[i0-1]);}
+    }
+    tdis(gx+40,11,tmp0,18,3);
+
+    if(as==2){nm=85;}else{nm=128;}
+
+    for(i=p ;i<= p+15;i++){
+      if(as==2||(md!=0 && (as==8||as==10||as==12||as==14))){
+       if(i<128){
+         if(as==2){
+           strcpy(tmp0,fstr(i+24,3));
+           if(i<85){
+             tmp0[3]=':';tmp0[4]=0;
+             strcat(tmp0,tim_name[cm6[0x130+i*4]+128]);
+           }else{
+             tmp0[0]=0;
+           }
+         }else{
+           strcpy(tmp0,fstr(i,3));
+           varia(tmp1,bank_l*256+bank,i,as);strcat(tmp0,tmp1);
+         }
+       }else{
+         tmp0[0]=0;
+       }
+      }else{
+       i0=i;if((cmdflag&0x20)!=0){i0++;}
+       strcpy(tmp0,fstr(i0,3));tmp0[3]=':';tmp0[4]=0;
+       if( as==1 ){
+         i0=cm6[0xa34+i*8]*64+cm6[0xa35+i*8];
+         strcat(tmp0,tim_name[i0]);
+       }
+       if( as==3 ){
+         i0=cm6[0x4eb2+i*19]*128+cm6[0x4eb3+i*19];
+         strcat(tmp0,tim_name[i0+256]);
+       }
+       if( as>3){
+         if(as<7 || as>=14 || as==8 || as==10 || as==12){
+           strcat(tmp0,tim_names(as*128-128+i));
+         }else{
+           tmp0[3]=0;
+
+           if(as==7 || as==9 || as==11||as==13){
+             if(gs_mode[as]&4){bank_l=bank;}
+
+             varia(tmp1,bank_l*256+bank,i,as);
+           }else{
+             varia(tmp1,bank_l*256+i,0,as+16);
+           }
+           strcat(tmp0,tmp1);
+         }
+       }
+      }
+      tdis(gx+40,(i-p)+13,tmp0,16+wd,3);
+    }
+    while( 1){
+      prog=y+p;
+      /*
+       if(md==0 &&(as==8 || as==10 || as==12 || as==14)){
+       tmp0[0]=0;
+       i0=gs_bank[as*128+prog];
+       if(i0>0){strcpy(tmp0,tim_head[i0-1]);}
+       tdis(gx+40,11,tmp0,18,3);
+       }
+       */
+      /*
+       strcpy(tmp0,"ch.=");strcat(tmp0,chstr(ch));
+       strcat(tmp0," Bank L=");strcat(tmp0,fstr(bank_l,3));
+       scprint(gx+40,28*2+2+1,tmp0);
+       */
+
+      tcur(gx+44,y+13,12+wd,3);
+      a=inkey2();sh=B_SFTSNS();
+
+      if(a==0x15){
+       sut=1;
+       if(as==2 || as==8 ||as==10 || as==12||as==14){/*rhythm*/
+         if(md!=0){
+           int oft=0;
+           if(as==2){oft=24;}
+           s_test(ch,bank_l*256,bank,prog+oft,tvel);
+         }else{
+           s_test(ch,bank_l*256,prog,tkey,tvel);
+         }
+       }else{
+         if((as==7||as==9||as==11||as==13)&&(gs_mode[as]&4)!=0){
+           s_test(ch,bank*256,prog,tkey,tvel);
+         }else{
+           s_test(ch,bank,prog,tkey,tvel);
+         }
+       }
+      }
+
+      tcur(gx+44,y+13,12+wd,3);
+
+      if( as!=2 && (a==0x13 || a==0x04) ){
+
+       if(sh&4){
+         /*BANK G.*/
+         if(gs_mode[16]&&(as==7 || as==9 ||as==11 || as==13)){
+           int i=bank_l;
+           while(gs_bank[16*128+i]==0||bank_l==i||as==gs_bank[16*128+i]){
+             if(a==0x13){
+               i--;if(i<0){i=127;}
+             }else{
+               i++;if(i>127){i=0;}
+             }
+             if(i==bank_l){break;}
+           }
+           bank_l=i;
+           as=gs_bank[16*128+bank_l];
+           goto top;
+         }
+         if(gs_mode[17]&&(as==8 || as==10 ||as==12 || as==14)){
+           int i=bank_l;
+           while(gs_bank[17*128+i]==0||bank_l==i||as==gs_bank[17*128+i]){
+             if(a==0x13){
+               i--;if(i<0){i=127;}
+             }else{
+               i++;if(i>127){i=0;}
+             }
+             if(i==bank_l){break;}
+           }
+           bank_l=i;
+           as=gs_bank[17*128+bank_l];
+           goto top;
+         }
+       }else{
+         /*MIDI CH.*/
+
+         if((sh & 2)!=0 && md==0){
+           int i=ch;
+           while(tim_asin[i]==2 || tim_asin[i]==0 ||tim_asin[i]==as){
+
+             if(a==0x13){
+               i--;if(i<1){i=32;}
+             }else{
+               i++;if(i>32){i=1;}
+             }
+             if(i==ch){break;}
+           }
+           ch=i;as=tim_asin[ch];
+         }else{
+           /*BANK*/
+           int i=bank;
+           if((as>=7 && as<=14)&&(md!=0 || (as&1)!=0 )){
+             while(gs_bank[as*128+i]==0 || bank==i){
+               if(a==0x13){
+                 i--;if(i<0){i=127;}
+               }else{
+                 i++;if(i>127){i=0;}
+               }
+               if(i==bank){break;}
+             }
+           }
+           bank=i;
+         }
+         break;
+       }
+      }
+
+      if( a==12 ){bank=bank2;bank_l=bank_l2;ch=ch2;as=as2;goto top;}
+
+      if( a==0x05 ){
+       y--;if( y<0 ){y=0;if( p>0 ){p--;break;}}
+      }
+      if( a==0x18 && prog+1<nm){
+       y++;if( y>15 ){y=15;if( p+16<nm ){p++;break;}}
+      }
+      if( a==0x17 ){if( p>0 ){p-=16;if(p<0){p=0;}break;}else{y=0;}}
+
+      if( a==0x12 ){if( p+16<nm ){p+=16;if(p+16>nm){p=nm-16;}
+      if(p+y>=nm){y=(nm-1)-p;}break;
+      }else{y=(nm-1)-p;if(y<0){y=0;}}}
+
+      if( a==0x0b ){p=0;y=0;break;}
+
+      if( a==9 ){
+       int n=p+y;
+       if(md==0 &&(cmdflag&0x20)!=0){n++;}
+       msg("Tone No.=");n=vinput(n,0x803);msg_clr();
+       if(md==0 &&(cmdflag&0x20)!=0){n--;}
+
+       if( es==0 && n>=0 && n<nm){
+         if(as==2 && n>24){n-=24;}
+         p=n&0xf0;y=n&15;break;
+       }
+      }
+
+      if(a=='Z'||a=='z'){timtra();}
+
+      if(a=='K'||a=='k'){stest_para_edit(gx+49,0);}
+      if(a=='V'||a=='v'){stest_para_edit(gx+49,1);}
+      /*
+       if(a=='>'||a=='.'||a=='+'){
+       if((sh&1)==0){
+       if(tkey<=115){tkey+=12;}
+       }else{
+       if(tvel<=117){tvel+=10;}
+       }
+       stest_para_disp(gx+49);
+       }
+       if(a=='<'||a==','||a=='-'){
+       if((sh&1)==0){
+       if(tkey>=12){tkey-=12;}
+       }else{
+       if(tvel>=10){tvel-=10;}
+       }
+       stest_para_disp(gx+49);
+       }
+       */
+      if((a=='?'||a=='/') && (as==7||as==9||as==11||as==13)/*&& bank<64*/){
+       int n=timsel2(ch,bank_l*256+bank,gx,prog);
+       prog=n&0xff;bank=(n>>8);p=prog&0xf0;y=prog&15;
+       if(es==0 || es==-2){goto skip;}
+       goto top;
+      }
+
+      if( a==13 ){es= 0;break;}
+      if( a==27 ){es=-2;break;}
+    }
+    if( a==13 || a==27 ){break;}
+  }
+  if(sut!=0){temporary_set();}
+skip:
+  edit_scr=scr;
+  txerase(dx+40*8,5*16,(18+wd)*8,25*16);
+  fill(dx+316,601,dx+453+wd*8,997,0);
+  if(md){bank=0;}
+  if(as==2){prog+=24;}
+
+  if( es==0 ){return(prog+bank*256);}else{return(-2);}
+}
+
+/***************************/
+int    timsel2(int ch,int bank,int gx,int prog)
+{
+  int  a,nm,i,j,i0,p=0,y=0,dx,as,as2,sut=0,sh;
+  int  bank_l,bank_l2;
+  char tmp0[256];
+  int  tbk[1024],tpg[1024],tnb[1024];
+
+  bank_l=(bank>>8)&0x7f;bank=bank&0x7f;
+  dx=gx*8;es=0;as=tim_asin[ch];
+
+  bank_l2=bank_l;as2=as;
+  /*
+    if(gs_mode[16]!=0 && as==7){as=gs_bank[16*128+bank_l];}
+    */
+  if((gs_mode[16]&4)!=0){
+    if((gs_mode[16]&128)!=0 && as==7){as=gs_bank[16*128+bank_l];}
+  }else{
+    if((gs_mode[16]&128)!=0 && as==7){as=gs_bank[16*128+bank];}
+  }
+
+
+  /*   if(gs_mode[17]!=0 && as==8){as=gs_bank[17*128+bank_l];}*/
+top:
+  /*   if(as!=7 && as!=9 && as!=11 && as!=13){es=1;return(-1);}*/
+
+  nm=0;/*p=0;y=0;*/
+  for(i=0;i<128;i++){
+    for(j=0;j<64+64;j++){
+      int      n;
+
+      if(i==prog && j<=bank){p=nm&0xff0;y=nm&15;}
+
+      n=gs_bank[as*128+j]*128-128+i;
+      if(n>=0 && tim_names(n)[0]>32){
+       if(nm<1024){
+         tbk[nm]=j;tpg[nm]=i;tnb[nm]=n;nm++;
+       }
+      }
+    }
+  }
+
+  while(p+16>nm && p>0 && y<15){p--;y++;}
+
+  while(1){
+    tdis(gx+40,10,tim_head[as-1],18,3);
+
+    for(i=p;i<p+16;i++){
+      int cc=3;tmp0[0]=0;
+      if(i<nm){
+       i0=tbk[i];
+       if(i0==0 ||i==0||(tbk[i]<=tbk[i-1])){
+         if(i0){cc=1;}
+         i0=tpg[i];
+         if((cmdflag&0x20)!=0){i0++;}
+         strcpy(tmp0,fstr(i0,3));
+       }else{
+         strcpy(tmp0,"   ");cc=1;
+       }
+       strcat(tmp0,":");
+       i0=tnb[i];if(i0>=0){strcat(tmp0,tim_names(i0));}
+      }
+      tdis(gx+ 40,(i-p)+13,tmp0,16,cc);
+    }
+    while(1){
+      int cc=3;
+      i=y+p;if(i<nm){bank=tbk[i];prog=tpg[i];if(bank){cc=1;}}
+
+      tmp0[0]=0;
+      i0=gs_bank[as*128+bank];
+      if(i0>0 && i0<=400){strcpy(tmp0,tim_head[i0-1]);}
+      tdis(gx+40,11,tmp0,18,3);
+
+      tcur(gx+44,y+13,12,cc);
+      a=inkey2();sh=B_SFTSNS();
+
+      if(a==0x15){
+       sut=1;
+       if((gs_mode[as]&4)!=0){
+         s_test(ch,bank*256,prog,tkey,tvel);
+       }else{
+         s_test(ch,bank_l*256+bank,prog,tkey,tvel);
+       }
+      }
+
+      tcur(gx+44,y+13,12,cc);
+
+      if( as!=2 && (a==0x13 || a==0x04) ){
+       if(sh&4){
+         if(gs_mode[16]&&(as==7 || as==9 ||as==11 || as==13)){
+           int i=bank_l;
+           while(gs_bank[16*128+i]==0||bank_l==i||as==gs_bank[16*128+i]){
+             if(a==0x13){
+               i--;if(i<0){i=127;}
+             }else{
+               i++;if(i>127){i=0;}
+             }
+             if(i==bank_l){break;}
+           }
+           bank_l=i;
+           as=gs_bank[16*128+bank_l];
+           goto top;
+         }
+       }
+      }
+      if( a==12 ){bank_l=bank_l2;as=as2;goto top;}
+
+      if( a==0x05 ){
+       y--;if( y<0 ){y=0;if( p>0 ){p--;break;}}
+      }
+      if( a==0x18 && i+1<nm){
+       y++;if( y>15 ){y=15;if( p+16<nm ){p++;break;}}
+      }
+      if( a==0x17 ){if( p>0 ){p-=16;if(p<0){p=0;}break;}else{y=0;}}
+
+      if( a==0x12 ){if( p+16<nm ){p+=16;if(p+16>nm){p=nm-16;}
+      if(p+y>=nm){y=(nm-1)-p;}break;
+      }else{y=(nm-1)-p;if(y<0){y=0;}}}
+
+      if( a==0x0b ){p=0;y=0;break;}
+
+      if( a==9 ){
+       int i,n=tpg[p+y];
+       if((cmdflag&0x20)!=0){n++;}
+       msg("Tone No.=");n=vinput(n,0x803);msg_clr();
+       if((cmdflag&0x20)!=0){n--;}
+       if( es==0 && n>=0 && n<128){
+         for(i=0;i<nm;i++){
+           if(tpg[i]>=n){p=i&0xfff0;y=i&15;break;}
+         }
+         break;
+       }
+      }
+
+      if(a=='Z'||a=='z'){timtra();}
+
+      if(a=='K'||a=='k'){stest_para_edit(gx+49,0);}
+      if(a=='V'||a=='v'){stest_para_edit(gx+49,1);}
+
+      if( a=='/'||a=='?' ){es=1;goto skip;}
+      if( a==13 ){es= 0;break;}
+      if( a==27 ){es=-2;break;}
+    }
+    if( a==13 || a==27 ){break;}
+  }
+skip:
+  if(sut!=0){temporary_set();}
+  return(prog+bank*256);
+}
+
+/***************************/
+void   stest_para_disp(int x)
+{
+  B_LOCATE(x,6);B_PRINT("KEY= ");B_PRINT(keystr(tkey));
+  B_LOCATE(x,7);B_PRINT("VEL= ");B_PRINT(fstr(tvel,3));
+}
+
+void   stest_para_edit(int x,int a)
+{
+  int  v;
+  char tmp0[128];
+
+  if(a==0){
+    B_LOCATE(x,6);strcpy(tmp0,keystr(tkey));sinput(tmp0,0x803);
+    if(es==0){v=ctc(60,tmp0,0);if(v>=0){tkey=v;}}
+  }else{
+    B_LOCATE(x,7);v=vinput(tvel,0x803);
+    if(es==0 && v>=0 && v<128){tvel=v;}
+  }
+  stest_para_disp(x-5);
+}
+
+/***************************/
+int    varia(char *pname,int bank,int prg,int md)
+{
+  int  bank2,bank_l,n=0;
+  bank_l=(bank>>8)&0xff;bank=bank&0xff;
+
+  /*   if((md==7||md==9||md==11||md==13)&& (gs_mode[md]&4)){bank=bank_l;}
+
+       if(gs_mode[16]!=0 &&  md==7         ){md=gs_bank[16*128+bank_l];}
+       if(gs_mode[17]!=0 && (md==8||md==24)){md=gs_bank[17*128+bank_l]|(md&16);}
+       */
+  /*
+    if((gs_mode[16]&4)!=0 ){
+    if(gs_mode[16]!=0 &&  md==7         ){md=gs_bank[16*128+bank_l];}
+    if(gs_mode[17]!=0 && (md==8||md==24)){md=gs_bank[17*128+bank_l]|(md&16);}
+    }else{
+    if(gs_mode[16]!=0 &&  md==7         ){md=gs_bank[16*128+bank];}
+    if(gs_mode[17]!=0 && (md==8||md==24)){md=gs_bank[17*128+bank]|(md&16);}
+    }
+    */
+  if((md==7||md==9||md==11||md==13)&& (gs_mode[md]&4)){bank=bank_l;}
+
+
+  bank2=bank;
+
+  while(bank>=0){
+    if(md<16){
+      n=gs_bank[md*128+bank]*128-128+prg;
+    }else{
+      n=(md-1)*128-128+bank;
+    }
+
+    if((gs_mode[7]&1)==0 && (md==7||md==24)){break;}
+    if((gs_mode[9]&1)==0 && (md==9||md==26)){break;}
+    if((gs_mode[11]&1)==0 && (md==11||md==28)){break;}
+    if((gs_mode[13]&1)==0 && (md==13||md==30)){break;}
+
+    if((md==8||md==10||md==12||md==14)&&(gs_mode[md]&2)==0){break;}
+
+    if(bank>63 ||(n>=0 && tim_names(n)[0]!=0)){break;}
+
+    if(md==7 || md==9 || md==11||md==13){
+      if(prg>=120){break;}
+      if((bank&15)==0){bank-=16;}else{bank--;}
+    }
+    if(md==8 || md==10 || md==12||md==14){
+      if(bank>=49){break;}
+      if((bank&31)==0){bank-=32;}else{bank=bank&0xe0;}
+    }
+    if(md==24 || md==26 || md==28||md==30){
+      if((bank&7)==0){bank-=8;}else{bank=bank&0xf8;}
+    }
+  }
+  pname[1]=0;if(bank!=bank2 && bank>=0){pname[0]='#';}else{pname[0]=':';}
+  if((md==7||md==9||md==11||md==13)&& gs_mode[md]==0){bank=0;n=md*128-128+prg;}
+
+  if(bank>=0 && n>=0){strcat(pname,tim_names(n));}
+  return(bank);
+}
+
+/***************************/
+void   s_test(int ch,int bank,int prg,int note,int velo)
+{
+  int  bnk_m,bnk_l,pm,ch2;
+  char obuf[64];
+
+  if(B_SFTSNS()&1){m_keyb(ch,bank,prg,velo);return;}
+
+  if(rcd->act==0){all_note_off(0);}
+  bnk_l=bank>>8;bnk_m=bank&0xff;ch=(ch-1)&31;ch2=ch&15;
+  pm=rcd->put_mode;rcd->put_mode=rcd->ch_port[ch];
+  twait(5);
+
+  if(bank>=0 && tim_asin[ch+1]>=7 && tim_asin[ch+1]<=14){
+    obuf[0]=0xb0+ch2;obuf[1]=0;obuf[2]=bnk_m;obuf[3]=0xff;
+    (*rcd->mix_out)(obuf);
+    obuf[0]=0xb0+ch2;obuf[1]=32;obuf[2]=bnk_l;obuf[3]=255;
+    (*rcd->mix_out)(obuf); /* separate each events  Jan.19.1998 daisuke Nagano */
+  }
+
+  if(prg>=0){
+    obuf[0]=0xc0+ch2;obuf[1]=prg;obuf[2]=255;
+    (*rcd->mix_out)(obuf);
+  }
+  twait(8);
+
+  obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=velo;obuf[3]=255;
+  (*rcd->mix_out)(obuf);
+
+  twait(5);while((BITSNS(7)&4)==4){}
+
+  obuf[0]=0x90+ch2;obuf[1]=note;obuf[2]=0;obuf[3]=255;
+  (*rcd->mix_out)(obuf);
+
+  snsclr();rcd->put_mode=pm;
+}
+
+/***************************/
+int    spc_select()
+{
+  int  ke,i,y=0,cx,gx;
+  char tmp0[128];
+
+  if(edit_scr==0){cx=41;gx=327;}else{cx=2+1;gx=15+8;}
+  cons_md(0);noed_cls();
+
+  box(gx,585,gx+417,997,14,65535);
+  sdis(cx,570," SPECIAL CONTROLER",52,15,14);
+
+  for(i=0;i<24;i++){
+    if(speci_sym[i]!=0){
+      strcpy(tmp0,"[ ]  ");tmp0[1]=speci_sym[i];
+      if(speci_sym2[i]!=0){tmp0[0]=32;tmp0[1]=32;tmp0[2]=32;}
+      strcat(tmp0,speci_name[i]);strcat(tmp0," : ");
+      strcat(tmp0,speci_come[i]);
+      B_LOCATE(cx+1,i+5);B_PRINT(tmp0);
+    }
+  }
+
+  while( 1){
+    tdis(cx+17,y+5,speci_come[y],34,11);
+    ke=inkey2();if(ke>='a' && ke<='z'){ke=ke-32;}
+    tdis(cx+17,y+5,speci_come[y],34,3);
+
+    if( ke==27 ){break;}
+    if((ke==0x04 || ke==' ' || ke==13) && speci_sym[y]!=0 ){break;}
+    if( ke==0x05 ){y--;if( y<0 ){y=23;}}
+    if( ke==0x18 ){y++;if( y>23 ){y=0;}}
+
+    if(ke>='A' && ke<='Z'){
+      for(i=0;i<18;i++){
+       if(ke==speci_sym[i]){y=i;}
+      }
+    }
+  }
+  /*txerase(cx*8,5*16,51*8,24*16);*/noed_cls_t();noed_cls();cons_md(1);
+  if( ke==13 ){return(speci_sym[y]+speci_sym2[y]*256);}
+  return(0);
+}
+
+/***************************/
+int    repl_select(int md)
+{
+  int  ke,sh,i,y=0,cx,gx,pg=0;
+  char tmp0[128];
+
+  /*
+    replinp:
+
+    if(md==0){
+    msg("REPLACE=");sinput(repl,0x200+30);
+    }else{
+    if(md==1){
+    msg("DELETE=");sinput(delt,0x200+30);
+    }else{
+    msg("FIND=");sinput(srch,0x200+30);
+    }
+    }
+    msg_clr();
+
+    if(ecode==0x18){
+    int ct=repl_select(md);
+    if(ct>=0){
+    if(md==0){
+    strcpy(repl,repl_d[ct]);
+    }else{
+    if(md==1){
+    strcpy(delt,repl_d[ct]);
+    }else{
+    strcpy(srch,repl_d[ct]);
+    }
+    }
+    }
+    goto replinp;
+    }
+    */
+
+
+  if(edit_scr==0){cx=41+16-16;gx=327+128-128;}else{cx=1+16;gx=7+128;}
+
+  cons_md(0);noed_cls();
+
+  box(gx,585-14,gx+417-112,997,14,65535);
+  strcpy(tmp0,repl_title[md]);
+  strcat(tmp0," Macro Selecter");
+  sdis(cx,570-14,tmp0,38,15,14);
+redraw:
+
+  for(i=0;i<26;i++){
+    int nn=i+md*52+pg;
+    if(repl_t[nn][0]!=0 && repl_d[nn][0]!=0){
+      strcpy(tmp0,"  :");tmp0[1]=i+'A';if(pg){tmp0[0]='s';}
+    }else{strcpy(tmp0,"   ");}
+
+    strcat(tmp0,repl_t[nn]);
+    tdis(cx,i+4,tmp0,34+3,3);
+  }
+
+  while( 1){
+    int nn=y+md*52+pg;
+
+    tdis(cx+3,y+4,repl_t[nn],34,11);
+    ke=inkey2();sh=B_SFTSNS();
+    if(ke>='a' && ke<='z'){ke=ke-32;}
+    tdis(cx+3,y+4,repl_t[nn],34,3);
+
+    if( ke==27 ){break;}
+    if( ke==0x15 ){sh=0;break;}
+
+    if(ke>='A' && ke<='Z'){
+      y=ke-'A';
+      nn=y+md*52+pg;
+      /*
+       if((sh&4)!=0){if(nn>25){nn-=26;}
+       if((sh&8)!=0){if(nn<26){nn+=26;}
+       */
+      if( /*repl_t[nn][0]!=0 &&*/ repl_d[nn][0]!=0 ){
+       if((sh&1)==0){y+=128;}
+       ke=13;break;
+      }
+    }
+    if( ke==13 && /*repl_t[nn][0]!=0 &&*/ repl_d[nn][0]!=0 ){
+      if((sh&1)==0){y+=128;}
+      break;}
+
+    if( ke==0x05 ){y--;if( y<0 ){y=25;}}
+    if( ke==0x18 ){y++;if( y>25 ){y=0;}}
+
+    if( ke==0x17 || ke==0x13 ){pg-=26;if(pg<0){pg=26;}goto redraw;}
+    if( ke==0x12 || ke==0x04 ){pg+=26;if(pg>26){pg=0;}goto redraw;}
+
+  }
+  /*txerase(cx*8,4*16,38*8,26*16);*/noed_cls_t();noed_cls();cons_md(1);
+  if( ke==13 ){return(y+md*52+pg);}
+  if((sh&1)!=0){return -2;}
+  return(-1);
+}
+
+/***************************/
+/*
+  1997-07-25   Trk.Editで[OPT1]+[CLR]でトラックメモを表示する
+  トラックセレクタを呼び出せるようにした
+  1997-07-26   ↑のトラックセレクタ上でも[OPT1]+テンキーで移
+  動出来るようにした
+  1997-07-29   Trk.Editでの[CTRL]+[T]で[↓]でトラックセレクタ
+  を呼び出せるようにした
+  */
+/*
+  int  trk_sel_menu(int md)
+  {
+  int  ke,sh,i,y=0,cx,gx,pg=0;
+  char tmp0[128];
+
+  if(edit_scr==0){cx=41+16-16;gx=327+128-128;}else{cx=1+16;gx=7+128;}
+
+  cons_md(0);noed_cls();
+
+
+  if(md<26){pg=0;y=md;}else{pg=10;y=md-10;}
+
+  box(gx,585-14,gx+417-112,997,14,65535);
+  strcpy(tmp0," Track Selecter");
+  sdis(cx,570-14,tmp0,38,15,14);
+  redraw:
+
+  for(i=0;i<26;i++){
+  int nn=i+pg;
+  if(tr_len[nn]>4){
+  strcpy(tmp0,fstr(nn+1,2));
+  strcat(tmp0,":");
+  }else{strcpy(tmp0,"   ");}
+
+  strcat(tmp0,trkmemo[nn]);
+  tdis(cx,i+4,tmp0,34+3,3);
+  }
+
+  while( 1){
+  int nn=y+pg;
+
+  tdis(cx+3,y+4,trkmemo[nn],34,11);
+  ke=inkey2();sh=B_SFTSNS();
+  if(ke>='a' && ke<='z'){ke=ke-32;}
+  tdis(cx+3,y+4,trkmemo[nn],34,3);
+
+  if( ke==27 ){break;}
+
+  if(sh&4){
+  int  ex;
+  char t[32];
+  t[0]=ke;t[1]=0;
+  ex=str_search("1234567890,./""*-+=\x0d",t);
+  if( ex ){
+  y=ex-1;pg=0;ke=13;
+  break;
+  }
+  }
+
+  if( ke==13 && tr_len[nn]>4 ){break;}
+
+  if( ke==0x05 ){y--;if( y<0 ){y=25;}}
+  if( ke==0x18 ){y++;if( y>25 ){y=0;}}
+
+  if( ke==0x17 || ke==0x13 ){pg-=10;if(pg<0){pg=10;}goto redraw;}
+  if( ke==0x12 || ke==0x04 ){pg+=10;if(pg>10){pg=0;}goto redraw;}
+
+  }
+  noed_cls_t();noed_cls();cons_md(1);
+  if( ke==13 ){return(y+pg);}
+  return(-1);
+  }
+  */
+/***************************/
+void   fsel(char *fna,char *pth,int w)
+{
+  int  a=0,nm=0,p,y,cc,gy,xx,cx,gx;
+  char tmp0[256],exts[256];
+  X68_DIR      dir[512];
+  int  cdirp[32],cdiry[32],cdirc;
+
+  cc=w>>8;w=w&0xff;es=0;
+  if(w<64){xx=319;if(w<6||w>8){xx=0;}}else{xx=335+8;if(w>=64+26){xx=319;}}
+  if((cc&2)==0){cx=44;gx=352;}else{cx=2;gx=16;xx=0;}
+
+  fill(xx,544,gx+432,1023,0);
+  box(gx-1,512+92,gx+401,512+484,14,65535);
+  box(gx+1,512+152,gx+399,512+183,14,65535);
+  box(gx+1,512+185,gx+399,512+456,14,65535);
+  fill(gx-1,512+92,gx+401,512+150,14);fill(gx-1,512+458,gx+401,512+484,14);
+
+  if(w<6){
+    box(7+8,168+64+512,248+8,375+64+512,14,65535);
+    box(9+8,170+64+512,246+8,373+64+512,14,65535);
+    sdis(2,153+64+512," MEMO",30,15,14);
+  }
+  gy=scyp;home2(512);
+
+  strcpy(tmp0," FILE SELECTER ");
+  if(w<64){
+    if((cc&1)==0){strcpy(tmp0," LOAD ");}else{strcpy(tmp0," SAVE ");}
+    strcat(tmp0,fsel_title[w]);strcat(tmp0," FILE ");
+    strncpy(exts,fsel_ext[w],256);
+  }else{
+    strcpy(exts,chcom_c[w&0x3f][1]);
+  }
+
+  sdis(cx,586,tmp0,strlen(tmp0),15,8);
+  if(w<6){sdis(4,560," MUSIC TITLE :",79,15,8);}
+
+  B_LOCATE(cx+1,6);B_PRINT("Path = ");B_LOCATE(cx+10,8);B_PRINT("K Byte Free");
+  B_LOCATE(cx+22,8);B_PRINT("(");B_PRINT(exts);B_PRINT(")");
+  B_LOCATE(cx+35,8);B_PRINT("files[  0/  0]");
+
+  while(1){
+  reinp:
+    if(drvchk(pth)>=0){
+      int      i;
+      i=strlen(pth);if(i>2 && pth[2]!='/'){pth[2]='/';pth[3]=0;}
+
+      while(fdir(pth,exts,dir,-1)<=-3){
+       if(strlen(pth)<=3){break;}
+       path_down(pth);
+      }
+    }
+
+    if(w<6){memo_disp();}
+    B_COLOR(3);
+    B_LOCATE(cx+1,29);B_PRINT(_("         [DOWN]SELECTER  [ESC]CANCEL  [RET]SELECT"));
+
+    frees(pth,cx);
+
+    B_LOCATE(cx+1,10);sinput(fna,0x200+48);spcut(fna);str_change(fna);
+
+    if( es==1 ){break;}
+    if( ecode==13 && fna[0]!=0){
+      fsdirp[w]=0;fsdiry[w]=0;/*check*/
+    drvmove:
+      if(str_search(fna,":")>2||fna[0]==':'){goto reinp;}
+
+      if( fna[1]==':'){
+       if(drvchk(fna)<0){nm=0;goto reinp;}
+
+       strcpy(pth,fna);pth[2]=0;strcpy(fna,&fna[2]);
+       strcat(pth,"/");CURDIR(drv_code(pth),tmp0);
+       if(tmp0[0]!=0){strcat(pth,tmp0);strcat(pth,"/");}
+      }
+
+      if(fna[0]=='.'){
+       if(fna[1]=='.'){
+         if(fna[2]=='/'||fna[2]==0){
+           path_down(pth);
+           if(fna[2]!=0 && fna[3]!=0){strcpy(fna,&fna[3]);}else{fna[0]=0;}
+         }else{goto reinp;}
+       }else{goto reinp;}
+      }
+
+      if( fna[0]=='/' ){pth[3]=0;}
+
+      strcpy(tmp0,pth);
+      if( fna[0]=='/'){strcat(tmp0,&fna[1]);}else{strcat(tmp0,fna);}
+
+      if((CHMOD(tmp0,-1)&0x18)==0x10){
+       strcpy(pth,tmp0);fna[0]=0;
+       if( str_last((uint8*)pth)!='/' ){strcat(pth,"/");}
+      }
+
+      if( str_last((uint8*)fna)!='/' ){
+       if( strlen(fna)>2 && str_search(fna,"/")>0 ){
+         if(fna[0]=='/'){
+           unsigned char tmp[128];
+           strcpy((char*)tmp,pth);tmp[2]=0;
+           strcat((char*)tmp,fna);strcpy((char*)fna,(char*)tmp);
+         }
+         path_cut(pth,fna);
+         break;
+       }
+       if(fna[0]!=0){break;}
+      }else{
+       if(fna[0]!='/'){strcat(pth,"/");}
+       strcat(pth,fna);
+       fna[0]=0;
+      }
+    }
+
+    cdirc=0;
+  resel:
+    p=0;y=0;
+    p=fsdirp[w];y=fsdiry[w];/*check*/
+  resel2:
+    a=0;msg_clr();
+    if(drvchk(pth)<0){nm=0;goto reinp;}
+    nm=fdir(pth,exts,dir,w);
+
+    if( nm==0 || nm==-2 ){nm=0;/*msg("ファイルがありません。");goto reinp;*/}
+    if( nm==-3         ){msg(_("Directory not found."));goto reinp;}
+    if( nm==-13        ){msg(_("Invalid directory name."));goto reinp;}
+    if( nm<0 && nm!=-2 ){msg("err.");B_PRINT(fstr(nm,4));goto reinp;}
+
+    /*         B_LOCATE(cx+1,29);B_PRINT("[→]/[←]ドライブ移動   ");*/
+#if 0 /* ignore drive change Jun.23.1998 Daisuke Nagano */
+    B_LOCATE(cx+1,29);B_PRINT(_("  /   CHANGE DRIVE   /  SELECT"));
+#else
+    B_LOCATE(cx+1,29);B_PRINT(_("                                      [RET]SELECT"));
+#endif 0
+    frees(pth,cx);B_LOCATE(cx+45,8);B_PRINT(fstr(nm,3));
+
+    if(p+y>=nm){p=0;y=0;}/*check*/
+    while(1){
+      int      n,i;
+      dir_disp(dir,nm,p,cx,0,16);
+
+      while( 1){
+       n=y+p;
+       B_LOCATE(cx+41,8);B_PRINT(fstr(n+1,3));
+
+       if( dir[n].fatr&0x10 ){i=2;}else{i=3;}
+       tcur(cx+1,y+12,22,i);
+       a=inkey2();if(a>='a' && a<='z'){a=a-32;}
+       tcur(cx+1,y+12,22,i);
+
+       if(w<2 && (dir[n].fatr&0x20)){
+         if(a==32){
+           memo_load(pth,dir[n].name);
+         }
+         if(a=='A'){
+           int i;
+           memo_load(pth,dir[n].name);
+           for(i=0 ;i<32;i++){
+             strcpy(rhyna[i],sread(0x206+i*16,14));
+             rhyno[i][0]=hed[0x206+i*16+14];rhyno[i][1]=hed[0x206+i*16+15];
+           }
+         }
+         if(a=='U'){
+           int i;
+           memo_load(pth,dir[n].name);
+           for(i=0;i<8;i++){uex_read(0x406,i);}
+         }
+         if(a=='T'){
+           memo_load(pth,dir[n].name);
+           strcpy(mtitle,sread(0x20,64));
+           rcp_dat2(0,0);
+         }
+         if(a=='M'){
+           int i;
+           memo_load(pth,dir[n].name);
+           for(i=0 ;i<12;i++){strcpy(memo[i],sread(0x60+i*28,28));}
+         }
+       }
+       if( a==13 ){es= 0;break;}
+       if( a==27 ){es= 1;break;}
+       /*if( a==0x0b ){p=0;y=0;break;}*/
+       if( a==0x07 ){a=27;break;}
+
+       if( a==0x05 ){
+         if( p==0 && y==0 ){a=27;break;}
+         y--;if( y<0 ){y=0;if( p>0 ){p--;
+         t_scrw(cx,12*16,50,15*16,cx,13*16);
+         dir_disp(dir,nm,p,cx,0,1);}}
+       }
+       if( a==0x18 && n+1<nm){
+         y++;if( y>15 ){y=15;if( p+16<nm ){p++;
+         t_scrw(cx,13*16,50,15*16,cx,12*16);
+         dir_disp(dir,nm,p,cx,15,1);}}
+       }
+       if( a==0x17 ){if( p>0 ){p-=16;if(p<0){p=0;}break;}else{y=0;}}
+
+       if( a==0x12 ){if( p+16<nm ){p+=16;if(p+16>nm){p=nm-16;}
+       if(p+y>=nm){y=(nm-1)-p;}break;
+       }else{y=(nm-1)-p;if(y<0){y=0;}}}
+
+#if 0 /* ignore drive change Jun.23.1998 Daisuke Nagano*/
+       if(a==0x13 || a==4){
+         int drn,dro;
+         drn=drv_code(pth);dro=drn;
+       redrv:
+         if(a==4){
+           drn++;if(drn>26){drn=1;}
+         }else{
+           drn--;if(drn<1){drn=26;}
+         }
+         fna[0]=drn+'A'-1;fna[1]=':';fna[2]=0;
+
+         if(dro!=drn && drvchk2(fna)<0){nm=0;goto redrv;}
+         nm=0;goto drvmove;
+       }
+#endif 0
+       if( a==0x15 || a==0x8 ){
+         path_down(pth);
+         if(cdirc>0){cdirc--;p=cdirp[cdirc];y=cdiry[cdirc];goto resel2;}
+         goto resel;
+       }
+       if( a=='\\' || a==0x0b ){
+         pth[3]=0;cdirc=0;goto resel;
+       }
+
+      }
+      if( a==27 ){break;}
+      if( a==13 && n<nm ){
+       if(dir[n].fatr&0x20){strcpy(fna,dir[n].name);
+       fsdirp[w]=p;fsdiry[w]=y;/*check*/
+       break;
+       }
+
+       if(dir[n].name[0]=='.'){
+         if(dir[n].name[1]=='.'){
+           path_down(pth);
+           if(cdirc>0){cdirc--;p=cdirp[cdirc];y=cdiry[cdirc];goto resel2;}
+         }
+       }else{
+         strcat(pth,dir[n].name);strcat(pth,"/");
+         if(cdirc<32){cdirp[cdirc]=p;cdiry[cdirc]=y;cdirc++;}
+       }
+       fsdirp[w]=0;fsdiry[w]=0;/*check*/
+       goto resel;
+      }
+    }
+    if(a==13){
+      if(drvchk(pth)<0){goto reinp;}
+      break;
+    }
+  }
+  msg_clr();
+
+  spcut(fna);if( fna[0]!=0 && str_search(fna,".")==0){
+    char etmp[256];
+    strcpy(etmp,exts);etmp[3]=0;
+    strmfe(fna,fna,etmp);
+  }
+  if(es==0){strcpy(tmp0,pth);strcat(tmp0,fna);
+  if((cc&1)!=0){
+    if((DRVCTRL(0,drv_code(pth))&8)!=0){
+      msg(_("Write protected."));goto reinp;}
+    if(file_check(tmp0,1)!=0){es=1;}else{file_back(tmp0);}
+  }else{
+    if(file_check(tmp0,0)==0){goto reinp;}
+  }
+  }
+  txerase((cx+1)*8,6*16,50*8,24*16);if(w<6){C_CLS_AL();}
+  home2(gy);fill(xx,544,gx+431,1023,0);
+
+}
+
+/***************************/
+void   str_change(char *s)
+{
+  char *ss=s;
+  int j;
+
+  while(*s!=0){
+    if(*s=='\\'){*s='/';}
+    s++;
+  }
+
+  while(1){
+    j=str_search(ss,"//");if(j==0){break;}
+    strcpy(&ss[j-1],&ss[j]);
+  }
+
+}
+
+/***************************/
+void   path_cut(char *fpath,char *fname)
+{
+  int  j;
+  char tmp0[128];
+
+  fpath[0]=0;
+  while(1){
+    j=str_search(fname,"/");if(j==0){j=str_search(fname,":");if(j==0){break;}}
+    strcpy(tmp0,fname);tmp0[j]=0;strcat(fpath,tmp0);strcpy(fname,&fname[j]);
+  }
+}
+
+/***************************/
+void   path_down(char *pth)
+{
+  int  i;
+
+  i=strlen(pth)-1;
+  while(i>2){
+    if(pth[i-1]=='/'){break;}
+    i--;
+  }
+  if(i>2){pth[i]=0;}
+}
+
+/***************************/
+void   path_set(char *pth)
+{
+  char tmp0[128],tmp2[128];
+
+  if( pth[0]==0 || knck(pth,0) || pth[1]!=':' ){
+    strcpy(tmp0,pth);strcpy(pth," :");
+    pth[0]=CURDRV()+'A';strcat(pth,tmp0);
+  }
+  if( pth[2]==0 ){
+    strcat(pth,"/");CURDIR(drv_code(pth),tmp2);
+    if(tmp2[0]!=0){strcat(pth,tmp2);}
+  }
+  if(str_last((uint8*)pth)!='/'){strcat(pth,"/");}
+}
+
+/***************************/
+int    file_check(char *fna,int cc)
+{
+  FILE *fp;
+
+  if((cc&1)!=0 && (cnfflag&0x0002)==0){return(0);}
+  if(!(fp= fopen2(fna,"rb"))){
+    if((cc&1)==0){msg(_("No file."));}
+    return(0);}
+  fclose(fp);
+
+  if((cc&1)!=0){
+    msg(_("Overwrite"));
+    if(yn_sel()>0){msg_clr();return(0);}
+
+    msg(_("Terminate writing."));
+  }
+  return(-1);
+}
+
+/***************************/
+void   file_back(char *fna)
+{
+  FILE *fp;
+  char fnb[256];
+
+  if((cnfflag&0x0004)==0){return;}
+  if(!(fp= fopen2(fna,"rb"))){return;}
+  fclose(fp);
+
+  strcpy(fnb,fna);fnb[strlen(fnb)-3]='$';
+  DELETE(fnb);RENAME(fna,fnb);
+}
+
+/***************************/
+int    drvchk(char *pth)
+{
+  int  a;
+
+  a=DRVCTRL(0,drv_code(pth));
+
+  if(a<0){     msg(_("Invalid drive name."));return -2;}
+  if((a&2)==0){msg(_("Disk is not inserted."));return -1;}
+  if((a&4)!=0){msg(_("Disk is not ready."));return -1;}
+
+  return 0;
+}
+
+int    drvchk2(char *pth)
+{
+  int  a;
+
+  a=DRVCTRL(0,drv_code(pth));
+
+  if(a<0 || (a&2)==0 || (a&4)!=0){return -1;}
+  return 0;
+}
+
+/***************************/
+int    drv_code(char *st)
+{
+  int  a;
+
+  a=st[0];
+  if(a>='a'&& a<='z'){a=a-32;}
+  if(a<'A'|| a>'Z'){return 0;}
+  a=a-'A'+1;return a;
+}
+
+/***************************/
+void   frees(char *pth,int cx)
+{
+  int  a;
+  char tmp0[256],tmp1[256];
+
+#if 0  /* ignore drive letter Jun.23.1998 / Daisuke Nagano */
+  strcpy(tmp0,pth);tmp1[0]=0;
+#else
+  strcpy(tmp0,pth+2);tmp1[0]=0;
+#endif
+  if(strlen(pth)>42){strcpy(tmp1,&tmp0[42]);tmp0[42]=0;tmp1[42]=0;}
+  tdis(cx+8,6,tmp0,43,3);tdis(cx+8,7,tmp1,43,3);
+
+  if(drvchk(pth)<0){a=0;}else{a=dskf(drv_code(pth))>>10;}
+  B_LOCATE(cx+2,8);B_PRINT(fstr(a,8));
+  CHDIR(pth);
+}
+
+/***************************/
+inline char    *dirs(char *s)
+{
+  int  a;
+  static char  name[24];
+  char ext[8];
+
+  ext[0]=0;strcpy(name,s);
+  a =str_search(name,".");
+  a+=str_search(&name[a],".");
+  a+=str_search(&name[a],".");
+
+  if(a>0 && name[0]!='.'){strcpy(ext,&name[a-1]);name[a-1]=0;}
+
+  strcpy(name,spadd(name,18));strcat(name,spadd(ext,4));
+
+  return(name);
+}
+
+/***************************/
+void   dir_disp(X68_DIR *dir,int nm,int p,int cx,int sp,int ln)
+{
+  int  sta,i,j;
+  char tmp0[128];
+  char tmp1[128];
+
+  cx++;
+  txerase((cx)*8,(12+sp)*16,48*8,ln*16);
+
+  sta=SUPER(0);
+  for(i=sp ;i< sp+ln;i++){
+    int nn=p+i;if( nn>=nm ){break;}
+    strcpy(tmp0,dirs(dir[nn].name));
+    B_LOCATE(cx,i+12);
+    if(dir[nn].fatr&0x10){
+      strcat(tmp0,"  <dir> ");
+      H_PRINT2("",tmp0,"");tmp0[0]=0;
+    }else{
+      strcat(tmp0,fstr(dir[nn].fln,8));
+    }
+    /*
+      date >> 9) & 0x7f) + 80      |* year  *|
+      date >> 5) & 0x0f            |* month *|
+      date & 0x1f)                 |* day   *|
+      time >> 11) & 0x1f           |* hour  *|
+      time >>  5) & 0x3f           |* min   *|
+      time & 0x1f) * 2             |* hour  *|
+      */
+    strcat(tmp0," ");j=dir[nn].fdt;strcpy(tmp1,dtasc(j));
+    if(tmp1[0]==0){strcpy(tmp1,fstr(((j>>9)&0x7f)+80,2));strcat(tmp1,"-00-00");}
+    strcat(tmp0,tmp1);strcat(tmp0," ");strcat(tmp0,tmasc(dir[nn].ftm));
+    H_PRINT2(tmp0,"","");
+  }
+  SUPER(sta);
+}
+
+/***************************/
+int    fdir(char *pth,char *exts,X68_DIR *dir,int w)
+{
+  struct X68_FILBUF    *buffer,buf;
+  X68_DIR      p;
+
+  int  a,i,j,nm=0,atr=0x30;
+  char file[256],tmp0[256],tmp1[256];
+
+  buffer = &buf;
+  strcpy(file,pth);strcat(file,"*.*");strcpy(tmp0,".");
+  if(w>=0){strcat(tmp0,exts);}
+
+  a=FILES(buffer,file,atr);if( a!=0 ){return(a);}
+  if(w<0){return(0);}
+  do{
+    int as;
+    strcpy(tmp1,buffer->name);jstrupr(tmp1);
+
+    if(tmp1[0]!='.' || tmp1[1]!=0){
+
+      as =str_search(tmp1,".");
+      as+=str_search(&tmp1[as],".");
+      as+=str_search(&tmp1[as],".");
+
+      if(as>0){strcpy(tmp1,spadd(&tmp1[as],3));}else{tmp1[0]=0;}
+
+      if( buffer->atr&0x10 || (buffer->atr&0x20 && str_search(tmp0,tmp1)>0) ){
+       if(nm>=512){msg(_("Too many files."));break;}
+
+       strcpy(dir[nm].name,buffer->name);dir[nm].fatr=buffer->atr;
+       dir[nm].fln=buffer->filelen;dir[nm].fdt=buffer->date;
+       dir[nm].ftm=buffer->time;
+       nm++;
+      }
+    }
+  }while(NFILES(buffer) >= 0);
+
+  if((cnfflag&0x0001)!=0 && nm>1){
+    for(i=0;i<nm-1;i++){
+      for(j=i+1;j<nm;j++){
+       if( dir[i].fatr==dir[j].fatr ){
+         if( strcmp(dir[i].name,dir[j].name)>0 ){
+           p=dir[i];dir[i]=dir[j];dir[j]=p;
+         }
+       }else{
+         if( dir[i].fatr>dir[j].fatr ){
+           p=dir[i];dir[i]=dir[j];dir[j]=p;
+         }
+       }
+      }
+    }
+  }
+  return(nm);
+}
+
+/***************************/
+void   memo_disp()
+{
+  int  i;
+
+  txerase(2*8,12*16,34*8+7,12*16+16);
+
+  /*tdis(18,3,mtitle,65,3);
+  for(i=0;i<12;i++){tdis(3,15+i,memo[i],28,3);}*/
+
+  tdis(18,3,eucconv(mtitle),65,3); /* code converted! */
+  for(i=0;i<12;i++){tdis(3,15+i,eucconv(memo[i]),28,3);} /* code converted! */
+
+}
+
+/***************************/
+void   memo_load(char *pth,char *fna)
+{
+  int  i;
+  char tmp0[128];
+  FILE *fp;
+
+  tdis(2,12,"FILE NAME:",10,1);tdis(12,12,fna,22,3);
+
+  strcpy(tmp0,pth);strcat(tmp0,fna);
+  if(fp= fopen2(tmp0,"rb")){
+    fread(hed,1,1414,fp);fclose(fp);
+  }else{
+    for(i=0;i<1414;i++){hed[i]=0;}
+  }
+  /*tdis(18,3,sread(0x20,64),65,3);
+  for(i=0;i<12;i++){tdis(3,15+i,sread(0x60+i*28,28),28,3);}*/
+
+  tdis(18,3,eucconv(sread(0x20,64)),65,3); /* code converted! */
+  for(i=0;i<12;i++){tdis(3,15+i,eucconv(sread(0x60+i*28,28)),28,3);} /* code converted! */
+}
+
+/***************************/
diff --git a/sf_com.cpp b/sf_com.cpp
new file mode 100644 (file)
index 0000000..f547713
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+  ==============================================================================
+
+   This file is part of the S.F.Tracker
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   S.F.Tracker can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   S.F.Tracker 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief util
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+
+#include "stdafx.h"
+#include <objbase.h>
+#include "sf_com.h"
+namespace sf {
+
+    struct com_initialize::impl
+    {
+               impl(void * reserved,unsigned int init) : hr(::CoInitializeEx(reserved,init))
+        {
+        }
+
+        ~impl()
+        {
+                       if(hr == S_OK){
+                   ::CoUninitialize();
+                       }
+        }
+       private:
+               HRESULT hr;
+    };
+
+    com_initialize::com_initialize(void * reserved,unsigned int  init)
+        : m_impl(new com_initialize::impl(reserved,init))
+    {
+    };
+
+       //template <typename ComClass,typename ComInterface> boost::intrusive_ptr<ComInterface> com_creator<ComClass,ComInterface>::create_instance()
+       //{
+       //      ComClass * com_ptr;
+       //      CoCreateInstance( __uuidof(ComClass), NULL,
+       //                       CLSCTX_ALL, __uuidof(ComInterface),
+       //                       (void**)&com_ptr);
+       //      return instrusive_ptr<ComClass>(com_ptr,false);
+       //};
+
+
+}
\ No newline at end of file
diff --git a/sf_com.h b/sf_com.h
new file mode 100644 (file)
index 0000000..ff2a8a0
--- /dev/null
+++ b/sf_com.h
@@ -0,0 +1,100 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the Shooting3
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   S.F.Tracker can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   S.F.Tracker 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief util
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+#include "objbase.h"
+namespace sf 
+{
+    enum com_init 
+    {
+        multi_threaded  = 0x0,
+        apartment_threaded = 0x2,
+        disable_ole1dde   = 0x4,
+        speed_over_memory = 0x8
+    };
+
+    struct com_initialize
+    {
+        struct impl;
+        com_initialize(void * reserved = NULL,unsigned int init = multi_threaded);
+        ~com_initialize() {};
+    private:
+        boost::shared_ptr<impl> m_impl;
+    };
+
+       template <typename ComClass,typename ComInterface> 
+                 boost::intrusive_ptr<ComInterface> create_instance()
+                 {
+                       ComInterface * com_ptr;
+                       CoCreateInstance( __uuidof(ComClass), NULL,
+                                        CLSCTX_ALL, __uuidof(ComInterface),
+                                        (void**)&com_ptr);
+                       return boost::intrusive_ptr<ComInterface>(com_ptr,false);
+
+                 };
+                       template <typename COMInterface> 
+               struct IUnknownImpl : public COMInterface 
+               {
+                       IUnknownImpl() : ref_(1) {}; 
+                       virtual ~IUnknownImpl() {};
+                       ULONG __stdcall AddRef()
+                       {
+                               return InterlockedIncrement(&ref_);
+                       }
+
+                       ULONG __stdcall Release()
+                       {
+                               ULONG ref = InterlockedDecrement(&ref_);
+                               if (0 == ref)
+                               {
+                                       delete this;
+                               }
+                               return ref;
+                       }
+
+                       HRESULT __stdcall QueryInterface(REFIID riid, VOID **ppObj)
+                       {
+                               if (IID_IUnknown == riid)
+                               {
+                                       AddRef();
+                                       *ppObj = (IUnknown*)this;
+                               }
+                               else if (__uuidof(COMInterface) == riid)
+                               {
+                                       AddRef();
+                                       *ppObj = (COMInterface*)this;
+                               }
+                               else
+                               {
+                                       *ppObj = NULL;
+                                       return E_NOINTERFACE;
+                               }
+                               return S_OK;
+                       }
+               private:
+                       LONG ref_;
+               };
+}
\ No newline at end of file
diff --git a/sf_memory.h b/sf_memory.h
new file mode 100644 (file)
index 0000000..24d02fb
--- /dev/null
@@ -0,0 +1,100 @@
+#pragma once
+namespace sf {
+// policy class
+struct heap_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::HeapFree( ::GetProcessHeap(), 0, AMemory );
+}
+};
+// policy class
+struct local_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::LocalFree( AMemory );
+}
+};
+// policy class
+struct co_task_memory_free_policy
+{
+template< typename T >
+void operator()( const T* AMemory ) const
+{
+if( NULL != AMemory )
+::CoTaskMemFree( AMemory );
+}
+};
+// base guard class
+template< typename T,class TFreePolicy >
+class base_memory
+{
+private:
+T *FMemory;
+
+public:
+base_memory( T* AMemory = NULL )
+: FMemory( AMemory ) {}
+
+virtual ~base_memory( void )
+{ reset(); }
+
+T* release( void )
+{
+T *tmp = FMemory;
+FMemory = NULL;
+return tmp;
+}
+
+void reset( T* AMemory = NULL )
+{
+if( AMemory != FMemory )
+{
+if( NULL != FMemory )
+TFreePolicy( FMemory );
+
+FMemory = AMemory;
+}
+}
+
+T* get( void )
+{ return FMemory; }
+
+T** operator&( void )
+{ return &FMemory; }
+
+};
+template< typename T >
+class heap_memory : public base_memory< T, 
+heap_memory_free_policy >
+{
+public:
+heap_memory( T* AMemory = NULL )
+: base_memory< T, heap_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class local_memory : public base_memory< T, 
+local_memory_free_policy >
+{
+public:
+local_memory( T* AMemory = NULL )
+: base_memory< T, local_memory_free_policy >( AMemory )
+{ }
+};
+template< typename T >
+class co_task_memory : public base_memory< T, 
+co_task_memory_free_policy >
+{
+public:
+co_task_memory( T* AMemory = NULL )
+: base_memory< T, co_task_memory_free_policy >( AMemory )
+{ }
+};
+
+};
diff --git a/sf_windows.cpp b/sf_windows.cpp
new file mode 100644 (file)
index 0000000..fcbd1ed
--- /dev/null
@@ -0,0 +1,538 @@
+// Direct2DBurn.cpp : アプリケーションのエントリ ポイントを定義します。\r
+\r
+#include "stdafx.h"\r
+#define BOOST_ASSIGN_MAX_PARAMS 7\r
+#include <boost/assign.hpp>\r
+#include <boost/assign/ptr_list_of.hpp>\r
+#include <boost/assign/ptr_list_inserter.hpp>\r
+#include <boost/foreach.hpp>\r
+#include "sf_windows.h"\r
+#include "exception.h"\r
+\r
+#define EXCEPTION_ON_ERROR(hres) \\r
+       if (FAILED(hres)) { throw sf::win32_error_exception(hres); }\r
+\r
+#ifndef HINST_THISCOMPONENT\r
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;\r
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)\r
+#endif\r
+\r
+#define SAFE_RELEASE(x) if(x) x.Release(); \r
+\r
+namespace sf \r
+{\r
+       LRESULT base_window::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam)\r
+       {\r
+               \r
+               LRESULT result = 0;\r
+               switch (message)\r
+               {\r
+               case WM_CREATE:\r
+                       {\r
+                               // TODO:\r
+                               create_device();\r
+                               break;\r
+                       }\r
+               case WM_SIZE:\r
+                       {\r
+                               //if (render_target_)\r
+                               //{\r
+                               //      D2D1_SIZE_U size;\r
+                               //      size.width = lParam & 0xFFFF;\r
+                               //      size.height = (lParam >> 16) & 0xFFFF; ;\r
+\r
+                               //      // Note: This method can fail, but it's okay to ignore the\r
+                               //      // error here -- it will be repeated on the next call to\r
+                               //      // EndDraw.\r
+                               //      //render_target_->Resize(size);\r
+                               //}\r
+                       }\r
+               case WM_PAINT:\r
+                       {\r
+                               //create_device();\r
+                               \r
+                               paint_struct begin_paint(hwnd);\r
+\r
+                               //if (!(render_target_->CheckWindowState() & D2D1_WINDOW_STATE_OCCLUDED))\r
+                               //{\r
+                               //      // Retrieve the size of the render target.\r
+                               //      D2D1_SIZE_F renderTargetSize = render_target_->GetSize();\r
+                               //      try {\r
+                               //              //render_target_->BeginDraw();\r
+                               //              base_->on_render();\r
+                               //              //EXCEPTION_ON_ERROR(render_target_->EndDraw());\r
+                               //      } catch (sf::win32_error_exception& e )\r
+                               //      {\r
+                               //              if(e.hresult() == D2DERR_RECREATE_TARGET)\r
+                               //              {\r
+                               //                      discard_device();\r
+                               //              } else {\r
+                               //                      throw;\r
+                               //              }\r
+                               //      }\r
+                               //}\r
+                               return FALSE;\r
+                       }\r
+               case WM_DISPLAYCHANGE:\r
+                       {\r
+                               ::InvalidateRect(hwnd, NULL, FALSE);\r
+                       }\r
+               case WM_ERASEBKGND:\r
+                       {\r
+                               return FALSE;\r
+                       }\r
+               case WM_MOUSEMOVE:\r
+                       {\r
+//                                     on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam); \r
+                       }\r
+               case WM_LBUTTONDOWN:\r
+                       {\r
+                       }\r
+               }\r
+               return ::DefWindowProcW(hwnd,message,wParam,lParam);\r
+       };\r
+\r
+\r
+       void base_window::create_device_independent_resources()\r
+       {\r
+\r
+               // Direct2DFactory の生成\r
+\r
+    if(!factory_){\r
+#if defined(DEBUG) || defined(_DEBUG)\r
+        D2D1_FACTORY_OPTIONS options;\r
+        options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION ;\r
+        EXCEPTION_ON_ERROR(D2D1CreateFactory(\r
+            D2D1_FACTORY_TYPE_SINGLE_THREADED,\r
+            options,\r
+            &factory_\r
+            ));\r
+#else\r
+                 EXCEPTION_ON_ERROR(D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &factory_));\r
+#endif\r
+\r
+    }\r
+\r
+    if(!write_factory_){\r
+                 EXCEPTION_ON_ERROR(::DWriteCreateFactory(\r
+                         DWRITE_FACTORY_TYPE_SHARED,\r
+                         __uuidof(IDWriteFactory),\r
+                         reinterpret_cast<IUnknown**>(&write_factory_)\r
+                 ));\r
+    }\r
+\r
+\r
+               //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);\r
+\r
+               //thunk_proc_ = (WNDPROC)thunk_.getCode();\r
+\r
+       };\r
+\r
+       void base_window::register_class (\r
+               wchar_t * menu_name,\r
+               boost::uint32_t        style ,\r
+               boost::int32_t     cbClsExtra,\r
+               HICON       hIcon ,\r
+               HCURSOR     hCursor,\r
+               HBRUSH      hbrBackground ,\r
+               HICON       hIconSm\r
+       )               \r
+       {\r
+               wnd_class_.reset(new sf::window_class_ex(menu_name,name_,HINST_THISCOMPONENT,thunk_proc_,style,cbClsExtra,hIcon,hCursor,hbrBackground,hIconSm));\r
+       }\r
+\r
+       /** デフォルト設定 */\r
+       void base_window::register_class()\r
+       {\r
+               wnd_class_.reset(new sf::window_class_ex(0,name_,HINST_THISCOMPONENT,thunk_proc_));\r
+       }\r
+\r
+       void base_window::create_window()\r
+       {\r
+               // Create the application window.\r
+               //\r
+               // Because the CreateWindow function takes its size in pixels, we\r
+               // obtain the system DPI and use it to scale the window size.\r
+               FLOAT dpiX, dpiY;\r
+               //factory_->GetDesktopDpi(&dpiX, &dpiY);\r
+\r
+\r
+               // Windowを作成する\r
+               CreateWindow(\r
+                       name_.c_str(),\r
+                       title_.c_str(),\r
+                       WS_OVERLAPPEDWINDOW,\r
+                       CW_USEDEFAULT,\r
+                       CW_USEDEFAULT,\r
+                       static_cast<boost::uint32_t>(ceil(width_ /** dpiX / 96.f*/)),\r
+                       static_cast<boost::uint32_t>(ceil(height_ /** dpiY / 96.f*/)),\r
+                       NULL,\r
+                       NULL,\r
+                       HINST_THISCOMPONENT,\r
+                       this\r
+                       );\r
+       }\r
+\r
+       void base_window::create_device()\r
+       {\r
+\r
+//             input_.reset(new input(HINST_THISCOMPONENT,hwnd_));\r
+               HRESULT hr = S_OK;\r
+\r
+\r
+               //ウィンドウの現在の幅、高さを求める\r
+               RECT rc;\r
+               GetClientRect( hwnd_, &rc );\r
+               boost::uint32_t width = rc.right - rc.left;\r
+               boost::uint32_t height = rc.bottom - rc.top;\r
+\r
+               {\r
+                       //wic_imaging_factory_.CreateInstance(CLSID_WICImagingFactory);\r
+//                     bitmap_ = load_bitmap_from_file(render_target_,wic_imaging_factory_,L"myship.png");\r
+               }\r
+\r
+               if(!render_target_)\r
+               {\r
+                       RECT rc;\r
+                       GetClientRect(hwnd_, &rc);\r
+\r
+                       D2D1_SIZE_U size = D2D1::SizeU(\r
+                               rc.right - rc.left,\r
+                               rc.bottom - rc.top\r
+                               );\r
+\r
+                       EXCEPTION_ON_ERROR(factory_->CreateHwndRenderTarget(\r
+                               D2D1::RenderTargetProperties(),\r
+                               D2D1::HwndRenderTargetProperties(hwnd_, size,D2D1_PRESENT_OPTIONS_IMMEDIATELY),\r
+                               &render_target_\r
+                               ));\r
+                       // Create a DC render target \r
+                       //D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(\r
+                       //      D2D1_RENDER_TARGET_TYPE_DEFAULT,\r
+                       //      D2D1::PixelFormat(\r
+                       //              DXGI_FORMAT_B8G8R8A8_UNORM,\r
+                       //              D2D1_ALPHA_MODE_IGNORE\r
+                       //              ) , 0.0, 0.0,\r
+                       //      D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE\r
+                       //      );\r
+\r
+                       //EXCEPTION_ON_ERROR(factory_->CreateDCRenderTarget(\r
+                       //      &props,\r
+                       //      &render_target_\r
+                       //      ));\r
+               }\r
+       }\r
+\r
+\r
+       void base_window::discard_device()\r
+       {\r
+/*             if(render_target_)\r
+               {\r
+                       render_target_.Release();\r
+               }*/\r
+       }\r
+\r
+       void base_window::show(boost::uint32_t show_flag) \r
+       {\r
+               //HRESULT hr = S_OK;\r
+               //BOOL enable;\r
+               //DwmIsCompositionEnabled (&enable);\r
+               //if(enable){\r
+               //   //Create and populate the BlurBehind structre\r
+               //   DWM_BLURBEHIND bb = {0};\r
+               //   //Enable Blur Behind and Blur Region;\r
+               //   bb.dwFlags = DWM_BB_ENABLE;\r
+               //   bb.fEnable = true;\r
+               //   bb.hRgnBlur = NULL;\r
+\r
+               //   //Enable Blur Behind\r
+               //   hr = DwmEnableBlurBehindWindow(hwnd_, &bb);\r
+               //}\r
+               ::ShowWindow(hwnd_,show_flag);\r
+       }\r
+       void base_window::update() {::UpdateWindow(hwnd_);}\r
+\r
+       base_window::~base_window()\r
+       {\r
+    safe_release(factory_);\r
+    safe_release(write_factory_);\r
+\r
+  }\r
+\r
+\r
+       base_window::base_window(const std::wstring& title,const std::wstring& name,bool fit_to_display,float width,float height)\r
+               : title_(title),name_(name),fit_to_display_(fit_to_display),\r
+               width_(width),height_(height),thunk_(this,base_window::WndProc),hwnd_(0)\r
+       {\r
+               thunk_proc_ = (WNDPROC)thunk_.getCode();\r
+               //create_device_independent_resources();\r
+       }\r
+\r
+\r
+\r
+       base_window::operator HWND()\r
+       {\r
+               return hwnd_;\r
+       };\r
+\r
+       //ID2D1FactoryPtr base_window::factory() { return impl_->factory();};\r
+       //ID2D1HwndRenderTargetPtr base_window::render_target() { return impl_->render_target();};\r
+       //IDWriteFactoryPtr base_window::write_factory() {return impl_->write_factory();};\r
+\r
+//  toplevel_window_ptr create_toplevel_window\r
+//  (\r
+//       const std::wstring& menu_name,\r
+//       const std::wstring& name,\r
+//       const boost::uint32_t show_flag,\r
+//       bool fit_to_display,\r
+//       float width,\r
+//       float height\r
+//       )\r
+//  {\r
+//       toplevel_window* p = new toplevel_window(menu_name,name,fit_to_display,width,height);\r
+//       p->register_class();\r
+//       p->create_window();\r
+//       p->show(show_flag);\r
+//       p->update();\r
+//       return toplevel_window_ptr(p);\r
+//  }\r
+//\r
+//     LRESULT toplevel_window::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam) \r
+//     {\r
+//             \r
+//\r
+//             switch (message)\r
+//             {\r
+//             case WM_CREATE:\r
+//                     {\r
+//                             // TODO:\r
+//                             create_device();\r
+//                             break;\r
+//                     }\r
+//             case WM_SIZE:\r
+//                     {\r
+//                             //if (render_target_)\r
+//                             //{\r
+//                             //      D2D1_SIZE_U size;\r
+//                             //      size.width = lParam & 0xFFFF;\r
+//                             //      size.height = (lParam >> 16) & 0xFFFF; ;\r
+//\r
+//                             //      // Note: This method can fail, but it's okay to ignore the\r
+//                             //      // error here -- it will be repeated on the next call to\r
+//                             //      // EndDraw.\r
+//                             //      render_target_->Resize(size);\r
+//                             //}\r
+//                     }\r
+//             case WM_PAINT:\r
+//                     {\r
+//                             //create_device();\r
+//                             \r
+//                             paint_struct begin_paint(hwnd);\r
+//                             render();\r
+//\r
+//\r
+//                             return FALSE;\r
+//                     }\r
+//             case WM_DISPLAYCHANGE:\r
+//                     {\r
+//                             ::InvalidateRect(hwnd, NULL, FALSE);\r
+//                     }\r
+//             case WM_ERASEBKGND:\r
+//                     {\r
+//                             return FALSE;\r
+//                     }\r
+//             case WM_MOUSEMOVE:\r
+//                     {\r
+////                                   on_mouse_move(GET_X_LPARAM(lParam),GET_Y_LPARAM(lParam),wParam); \r
+//                     }\r
+//             case WM_LBUTTONDOWN:\r
+//                     {\r
+//                     }\r
+//             }\r
+//\r
+//             if(message == WM_CLOSE)\r
+//             {\r
+//                     BOOL ret(::DestroyWindow(hwnd));\r
+//                     BOOST_ASSERT(ret != 0);\r
+//             }\r
+//\r
+//             if(message == WM_DESTROY)\r
+//             {\r
+//                     ::PostQuitMessage(0);\r
+//                     return 0;\r
+//             }\r
+//\r
+//             return ::DefWindowProcW(hwnd,message,wParam,lParam);\r
+//     }\r
+//\r
+//     void toplevel_window::main_loop()\r
+//     {\r
+//             render();\r
+//     }\r
+//\r
+//     void toplevel_window::render()\r
+//     {\r
+//\r
+//             static float t = 0.0f;\r
+//\r
+//             if (render_target_)\r
+//             {\r
+//                     // Retrieve the size of the render target.\r
+//                     D2D1_SIZE_F renderTargetSize = render_target_->GetSize();\r
+//                     try {\r
+//                             render_target_->BeginDraw();\r
+//                             render_target_->Clear(D2D1::ColorF(D2D1::ColorF::White));\r
+//                             render_target_->SetTransform(D2D1::Matrix3x2F::Identity());\r
+//                             //render_target_->Clear(D2D1::ColorF(D2D1::ColorF::White));\r
+//                             ID2D1SolidColorBrushPtr brush;\r
+//                             render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black), &brush);\r
+//                             ID2D1SolidColorBrushPtr brushr;\r
+//                             render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Red), &brushr);\r
+//\r
+//                             D2D1_RECT_F layoutRect = D2D1::RectF(50.f, 50.f, 600.f, 200.f);\r
+//                             IDWriteTextFormatPtr write_text_format;\r
+//                             // Text Formatの作成\r
+//                             EXCEPTION_ON_ERROR(write_factory_->CreateTextFormat(\r
+//                                     L"メイリオ",                // Font family name.\r
+//                                     NULL,                       // Font collection (NULL sets it to use the system font collection).\r
+//                                     DWRITE_FONT_WEIGHT_REGULAR,\r
+//                                     DWRITE_FONT_STYLE_NORMAL,\r
+//                                     DWRITE_FONT_STRETCH_NORMAL,\r
+//                                     48.0f,\r
+//                                     L"ja-jp",\r
+//                                     &write_text_format\r
+//                             ));\r
+//                             // Actually draw the text at the origin.\r
+//                             render_target_->DrawTextW(\r
+//                                     L"こんにちは、世界!By S.F.",\r
+//                                             wcslen(L"こんにちは、世界!By S.F."),\r
+//                                     write_text_format,\r
+//                                     layoutRect, \r
+//                                     brush);\r
+////                           render_target_->DrawBitmap(bitmap_,D2D1::Rect<float>(40.0f,200.0f,64.0f + 40.0f,64.0f + 200.0f),1.0f,D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,D2D1::Rect<float>(0.0f,0.0f,64.0f,64.0f));\r
+//\r
+//                             IDWriteTextFormatPtr write_text_format2;\r
+//                             // Text Formatの作成\r
+//                             EXCEPTION_ON_ERROR(write_factory_->CreateTextFormat(\r
+//                                     L"メイリオ",                // Font family name.\r
+//                                     NULL,                       // Font collection (NULL sets it to use the system font collection).\r
+//                                     DWRITE_FONT_WEIGHT_REGULAR,\r
+//                                     DWRITE_FONT_STYLE_NORMAL,\r
+//                                     DWRITE_FONT_STRETCH_NORMAL,\r
+//                                     12.0f,\r
+//                                     L"ja-jp",\r
+//                                     &write_text_format2\r
+//                             ));\r
+//                             std::wstring lbl1(L"Direct2D");\r
+//                             render_target_->DrawTextW(lbl1.c_str(),lbl1.size(),write_text_format2,D2D1::RectF(40.0f,270.0f,64.0f+40.0f,64.0f + 270.0f),brushr);\r
+//                             std::wstring lbl2(L"D3DX10Sprite");\r
+//                             render_target_->DrawTextW(lbl2.c_str(),lbl2.size(),write_text_format2,D2D1::RectF(140.0f,270.0f,96.0f+140.0f,128.0f + 270.0f),brushr);\r
+//\r
+////                           std::wstring lbl3(L"DirectWrite+Direct2D");\r
+//                             render_target_->DrawTextW(lbl3.c_str(),lbl3.size(),write_text_format2,D2D1::RectF(60.0f,40.0f,280.0f,128.0f),brushr);\r
+//\r
+//                             std::wstring lbl4(L"Direct3D");\r
+//                             render_target_->DrawTextW(lbl4.c_str(),lbl4.size(),write_text_format2,D2D1::RectF(280.0f,160.0f,380.0f,190.0f),brushr);\r
+//\r
+//                             EXCEPTION_ON_ERROR(render_target_->EndDraw());\r
+//\r
+//                     }  catch(...) {\r
+//                             throw;\r
+//                     }\r
+//             }\r
+//     };\r
+\r
+//\r
+// Creates a Direct2D bitmap from the specified\r
+// file name.\r
+//\r
+ID2D1BitmapPtr load_bitmap_from_file(\r
+    ID2D1HwndRenderTargetPtr render_target,\r
+    IWICImagingFactoryPtr wic_factory,\r
+       std::wstring uri,\r
+       boost::uint32_t destination_width,\r
+       boost::uint32_t destination_height\r
+)\r
+{\r
+    HRESULT hr = S_OK;\r
+\r
+    IWICBitmapDecoderPtr decoder;\r
+    IWICBitmapFrameDecodePtr decoder_source;\r
+    IWICStreamPtr stream;\r
+    IWICFormatConverterPtr converter;\r
+    IWICBitmapScalerPtr scaler;\r
+       ID2D1BitmapPtr bitmap;\r
+\r
+    EXCEPTION_ON_ERROR(wic_factory->CreateDecoderFromFilename(\r
+        uri.c_str(),\r
+        NULL,\r
+        GENERIC_READ,\r
+        WICDecodeMetadataCacheOnLoad,\r
+        &decoder\r
+        ));\r
+\r
+    // Create the initial frame.\r
+    EXCEPTION_ON_ERROR(decoder->GetFrame(0, &decoder_source));\r
+  \r
+    // Convert the image format to 32bppPBGRA\r
+    // (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).\r
+    EXCEPTION_ON_ERROR(hr = wic_factory->CreateFormatConverter(&converter));\r
+\r
+    // If a new width or height was specified, create an\r
+    // IWICBitmapScaler and use it to resize the image.\r
+    if (destination_width != 0 || destination_height != 0)\r
+    {\r
+        boost::uint32_t originalWidth, originalHeight;\r
+        EXCEPTION_ON_ERROR(decoder_source->GetSize((UINT*)&originalWidth, (UINT*)&originalHeight));\r
+        if (destination_width == 0)\r
+        {\r
+            FLOAT scalar = static_cast<FLOAT>(destination_height) / static_cast<FLOAT>(originalHeight);\r
+            destination_width = static_cast<boost::uint32_t>(scalar * static_cast<FLOAT>(originalWidth));\r
+        }\r
+        else if (destination_height == 0)\r
+        {\r
+            FLOAT scalar = static_cast<FLOAT>(destination_width) / static_cast<FLOAT>(originalWidth);\r
+            destination_height = static_cast<boost::uint32_t>(scalar * static_cast<FLOAT>(originalHeight));\r
+        }\r
+\r
+        EXCEPTION_ON_ERROR(wic_factory->CreateBitmapScaler(&scaler));\r
+        EXCEPTION_ON_ERROR(scaler->Initialize(\r
+                decoder_source,\r
+                destination_width,\r
+                destination_height,\r
+                WICBitmapInterpolationModeCubic\r
+                ));\r
+        EXCEPTION_ON_ERROR(converter->Initialize(\r
+            scaler.GetInterfacePtr(),\r
+            GUID_WICPixelFormat32bppPBGRA,\r
+            WICBitmapDitherTypeNone,\r
+            NULL,\r
+            0.f,\r
+            WICBitmapPaletteTypeMedianCut\r
+            ));\r
+    }\r
+    else // Don't scale the image.\r
+    {\r
+        EXCEPTION_ON_ERROR(converter->Initialize(\r
+            decoder_source.GetInterfacePtr(),\r
+            GUID_WICPixelFormat32bppPBGRA,\r
+            WICBitmapDitherTypeNone,\r
+            NULL,\r
+            0.f,\r
+            WICBitmapPaletteTypeMedianCut\r
+            ));\r
+    }\r
+\r
+    // Create a Direct2D bitmap from the WIC bitmap.\r
+    EXCEPTION_ON_ERROR(render_target->CreateBitmapFromWicBitmap(\r
+        converter.GetInterfacePtr(),\r
+        NULL,\r
+        &bitmap\r
+        ));\r
+\r
+       return bitmap;\r
+}\r
+\r
+\r
+}\r
+\r
diff --git a/sf_windows.h b/sf_windows.h
new file mode 100644 (file)
index 0000000..74d5592
--- /dev/null
@@ -0,0 +1,394 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the Shooting3
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   Shooting3 can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   S.F.Tracker 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+// Windows Header Files:
+#include "exception.h"
+#include "xbyak.h"
+//#include "input.h"
+
+_COM_SMARTPTR_TYPEDEF(ID2D1Factory,__uuidof(ID2D1Factory));
+_COM_SMARTPTR_TYPEDEF(IWICImagingFactory, __uuidof(IWICImagingFactory));
+_COM_SMARTPTR_TYPEDEF(IDWriteFactory , __uuidof(IDWriteFactory));
+_COM_SMARTPTR_TYPEDEF(IDWriteGdiInterop , __uuidof(IDWriteGdiInterop));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontFace , __uuidof(IDWriteFontFace));
+_COM_SMARTPTR_TYPEDEF(IDWriteFont , __uuidof(IDWriteFont));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontFamily , __uuidof(IDWriteFontFamily));
+_COM_SMARTPTR_TYPEDEF(IDWriteFontCollection , __uuidof(IDWriteFontCollection));
+_COM_SMARTPTR_TYPEDEF(IDWriteLocalizedStrings , __uuidof(IDWriteLocalizedStrings));
+_COM_SMARTPTR_TYPEDEF(ID2D1HwndRenderTarget , __uuidof(ID2D1HwndRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1BitmapRenderTarget , __uuidof(ID2D1BitmapRenderTarget));
+_COM_SMARTPTR_TYPEDEF(ID2D1GdiInteropRenderTarget , __uuidof(ID2D1GdiInteropRenderTarget));
+_COM_SMARTPTR_TYPEDEF(IDWriteTextFormat, __uuidof(IDWriteTextFormat));
+_COM_SMARTPTR_TYPEDEF(IDWriteTextLayout, __uuidof(IDWriteTextLayout));
+_COM_SMARTPTR_TYPEDEF(ID2D1PathGeometry , __uuidof(ID2D1PathGeometry));
+_COM_SMARTPTR_TYPEDEF(ID2D1LinearGradientBrush , __uuidof(ID2D1LinearGradientBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1GradientStopCollection , __uuidof(ID2D1GradientStopCollection));
+_COM_SMARTPTR_TYPEDEF(ID2D1SolidColorBrush , __uuidof(ID2D1SolidColorBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1BitmapBrush , __uuidof(ID2D1BitmapBrush));
+_COM_SMARTPTR_TYPEDEF(ID2D1Bitmap , __uuidof(ID2D1Bitmap));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapDecoder,__uuidof(IWICBitmapDecoder));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapFrameDecode,__uuidof(IWICBitmapFrameDecode));
+_COM_SMARTPTR_TYPEDEF(IWICStream,__uuidof(IWICStream));
+_COM_SMARTPTR_TYPEDEF(IWICFormatConverter,__uuidof(IWICFormatConverter));
+_COM_SMARTPTR_TYPEDEF(IWICBitmapScaler,__uuidof(IWICBitmapScaler));
+
+template <class COM_SMART_PTR > inline void safe_release(COM_SMART_PTR& ptr)
+{
+  if(ptr)
+  {
+    ptr.Release();
+  }
+};
+
+
+
+namespace sf{
+
+ID2D1BitmapPtr load_bitmap_from_file(
+    ID2D1HwndRenderTargetPtr render_target,
+    IWICImagingFactoryPtr wic_factory,
+       std::wstring uri,
+       boost::uint32_t destination_width = 0,
+       boost::uint32_t destination_height = 0
+    );
+
+/** WNDCLASSEXラッパクラス */
+struct window_class_ex
+{
+       window_class_ex(
+               const wchar_t*  menu_name ,
+               const std::wstring&  class_name ,
+               HINSTANCE   hInstance = NULL,
+               WNDPROC     lpfnWndProc = ::DefWindowProcW,
+               boost::uint32_t        style = CS_HREDRAW | CS_VREDRAW,
+               boost::int32_t     cbClsExtra  = 0,
+               HICON       hIcon = ::LoadIcon(NULL,IDI_APPLICATION),
+               HCURSOR     hCursor = ::LoadCursor(NULL, IDC_ARROW),
+               HBRUSH      hbrBackground = NULL,
+               HICON       hIconSm = NULL
+               ) : is_register_(false)
+       {
+
+               if(::GetClassInfoExW(hInstance,class_name.c_str(),&wndclass_) == 0)
+               {
+                       if(::GetLastError() == ERROR_CLASS_DOES_NOT_EXIST)
+                       { 
+                               ::ZeroMemory(&wndclass_,sizeof(wndclass_));
+                               wndclass_.lpszMenuName = (LPCWSTR)menu_name;
+                               wndclass_.lpszClassName = class_name.c_str();
+                               wndclass_.cbSize = sizeof(::WNDCLASSEXW);
+                               wndclass_.cbWndExtra = sizeof(LONG_PTR);
+                               wndclass_.hInstance = hInstance;
+                               wndclass_.lpfnWndProc = lpfnWndProc;
+                               wndclass_.style = style;
+                               wndclass_.cbClsExtra = cbClsExtra;
+                               wndclass_.hIcon = hIcon;
+                               wndclass_.hCursor = hCursor;
+                               wndclass_.hbrBackground = hbrBackground;
+                               wndclass_.hIconSm = hIconSm;
+                               atom_ = ::RegisterClassExW(&wndclass_) ;
+                               BOOST_ASSERT(atom_ != 0);
+                               is_register_ = true;
+                       } else {
+                               throw win32_error_exception();
+                       }
+               } else {
+                       is_register_ = false;
+               }
+       };
+       
+       ~window_class_ex()
+       {
+               if(is_register_){
+                       ::UnregisterClassW(wndclass_.lpszClassName,wndclass_.hInstance);
+               }
+       }
+
+private:
+       bool is_register_;
+       ATOM atom_;
+       ::WNDCLASSEXW wndclass_;
+};
+
+
+
+struct get_dc {
+       get_dc(HWND hwnd) : hwnd_(hwnd),hdc_(GetDC(hwnd)) {}
+       HDC get(){return hdc_;}
+       ~get_dc(){::ReleaseDC(hwnd_,hdc_);}
+private:
+       HDC hdc_;
+       HWND hwnd_;
+};
+
+struct compatible_dc {
+       compatible_dc(HDC hdc) : hdc_(::CreateCompatibleDC(hdc)){}; 
+       ~compatible_dc(){::DeleteDC(hdc_);};
+       HDC get() { return hdc_;};
+private:
+       HDC hdc_;
+};
+
+struct ref_dc {
+       ref_dc(HDC& hdc) : hdc_(hdc) {};
+       ~ref_dc(){};
+       HDC get() { return hdc_;};
+private:
+       HDC& hdc_;
+};
+
+struct d2_dc {
+       d2_dc(ID2D1GdiInteropRenderTargetPtr& ptr,D2D1_DC_INITIALIZE_MODE mode) :hdc_(0),ptr_(ptr)
+  {
+    hr_ = ptr->GetDC(mode,&hdc_);
+  };
+       ~d2_dc(){ptr_->ReleaseDC(NULL);};
+       HDC get() { return hdc_;};
+private:
+  HRESULT hr_;
+       HDC hdc_;
+  ID2D1GdiInteropRenderTargetPtr& ptr_;
+};
+
+template <typename Holder>
+struct device_context
+{
+       explicit device_context(Holder* holder) : holder_(holder){};
+       ~device_context() {}
+       operator HDC(){return holder_->get();}
+private:
+       boost::scoped_ptr<Holder> holder_;
+};
+
+typedef device_context<d2_dc> d2_dc_type;
+
+struct paint_struct 
+{
+       paint_struct(HWND hwnd) : hwnd_(hwnd)
+       {
+               ::BeginPaint(hwnd,&paintstruct_);
+       }
+       ~paint_struct() {::EndPaint(hwnd_,&paintstruct_);}
+       PAINTSTRUCT* operator->(){return &paintstruct_;}
+private:
+       HWND hwnd_;
+       PAINTSTRUCT paintstruct_;
+};
+
+template <typename T>
+struct begin_draw
+{
+       begin_draw(T& render_target) : render_target_(render_target) ,is_end_(false) {render_target->BeginDraw();}
+       HRESULT end_draw() 
+       {
+               HRESULT hr = S_OK;
+               if(!is_end_) { 
+                       hr = render_target_->EndDraw();
+                       is_end_ = true;
+               }
+
+               return hr;
+       };
+       ~begin_draw(){ if(!is_end_) { render_target_->EndDraw();}}
+private:
+       T& render_target_;
+       bool is_end_;
+};
+
+struct mouse
+{
+       mouse() : x_(0.0f),y_(0.0f),left_button_(false),middle_button_(false),right_button_(false){}
+private:
+       float x_,y_;
+       bool left_button_,middle_button_,right_button_;
+};
+
+/** window ベースクラス */
+struct base_window 
+{
+       typedef boost::signals2::signal<LRESULT (HWND,boost::uint32_t,WPARAM, LPARAM) > on_message_type;
+       on_message_type on_message;
+       typedef boost::signals2::signal<void ()> on_render_type;
+       on_render_type on_render;
+       operator HWND();
+protected:
+       base_window(
+               const std::wstring& title,
+               const std::wstring& name,bool fit_to_display,
+               float width,float height);
+       ~base_window();
+       void register_class (
+               wchar_t* menu_name,
+               boost::uint32_t style, 
+               boost::int32_t     cbClsExtra  = 0,
+               HICON       hIcon = ::LoadIcon(NULL,IDI_APPLICATION),
+               HCURSOR     hCursor = ::LoadCursor(NULL, IDC_ARROW),
+               HBRUSH      hbrBackground = NULL,
+               HICON       hIconSm = NULL
+       );              
+
+       /** デフォルト設定 */
+       void register_class();
+       void create_window();
+       void update();
+       void show(boost::uint32_t show_flag);
+       virtual void discard_device();
+       virtual void create_device();
+       virtual void create_device_independent_resources();
+       //ID2D1FactoryPtr factory();
+       //ID2D1HwndRenderTargetPtr render_target();
+       //IDWriteFactoryPtr write_factory();
+
+       virtual LRESULT window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam);
+protected:
+       static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+       {
+               base_window* ptr = reinterpret_cast<base_window*>(hwnd);
+               hwnd = ptr->hwnd_;
+               return ptr->window_proc(hwnd,message,wParam,lParam);
+       };
+
+       struct hwnd_this_thunk : public Xbyak::CodeGenerator {
+               hwnd_this_thunk(base_window* impl,WNDPROC proc)
+               {
+                       push(eax);
+                       mov(eax,ptr[esp + 8]);
+                       mov(ptr[&(impl->hwnd_)],eax);
+                       mov(eax,(DWORD)impl);
+                       mov(ptr[esp + 8],eax);
+                       pop(eax);
+                       jmp(proc);
+               }
+       };
+
+       //ID3D11DevicePtr                               d3d_device_;
+       //D3D_DRIVER_TYPE                       driver_type_;
+       //D3D_FEATURE_LEVEL             feature_level_;
+       //IDXGISwapChainPtr                     swap_chain_;
+       //ID3D11DeviceContextPtr        device_context_;
+       //ID3D11RenderTargetViewPtr             render_target_view_;
+       //ID3DX11EffectPtr                              effect_;
+       //ID3DX11EffectTechnique*               technique_;
+       //ID3D11InputLayoutPtr          vertex_layout_;
+       //ID3D11BufferPtr                               vertex_buffer_;
+       //ID3D11BufferPtr             index_buffer_;
+       //ID3D11ShaderResourceViewPtr         texture_rv_;
+       //ID3D11ShaderResourceViewPtr                   sprite_tex_;
+       //ID3DX11EffectMatrixVariable*       world_variable_;
+       //ID3DX11EffectMatrixVariable*         view_variable_;
+       //ID3DX11EffectMatrixVariable*         projection_variable_;
+       //ID3DX11EffectVectorVariable*         mesh_color_variable_;
+       //ID3DX11EffectShaderResourceVariable* diffuse_variable_;
+       //D3DXMATRIX                          world_;
+       //D3DXMATRIX                          view_;
+       //D3DXMATRIX                          projection_;
+       //D3DXVECTOR4                         mesh_color_;
+       //ID3DX10SpritePtr                                      sprite_;
+       //D3DX10_SPRITE                                         sprite_buffer_[1];
+       //ID3D11BlendStatePtr                                   sprite_blend_state_;
+
+       HWND hwnd_;
+       ID2D1FactoryPtr factory_;
+//     ID2D1DCRenderTargetPtr render_target_;
+       ID2D1HwndRenderTargetPtr render_target_;
+       IDWriteFactoryPtr write_factory_;
+       IWICImagingFactoryPtr wic_imaging_factory_;
+       //ID2D1BitmapPtr bitmap_;
+       hwnd_this_thunk thunk_;
+       std::wstring title_;
+       std::wstring name_;
+       float width_,height_;
+       bool fit_to_display_;
+       boost::shared_ptr<sf::window_class_ex> wnd_class_;
+       WNDPROC thunk_proc_;
+//     boost::shared_ptr<input> input_;
+};
+
+//struct toplevel_window;
+//typedef boost::shared_ptr<toplevel_window> toplevel_window_ptr;
+//
+///** toplevel_window を生成する関数 */
+//toplevel_window_ptr create_toplevel_window (
+//  const std::wstring& menu_name,
+//  const std::wstring& name,
+//  const boost::uint32_t show_flag = SW_SHOWNORMAL,
+//  bool fit_to_display = false,
+//  float width = 640,
+//  float height = 480
+//);
+//
+//
+//
+///** toplevel ウィンドウクラス */
+///* このクラスは、create_toplevel_window 関数からのみ生成可能 */
+//struct toplevel_window : public base_window
+//{
+//  friend   toplevel_window_ptr create_toplevel_window
+//  (
+//       const std::wstring& menu_name,
+//       const std::wstring& name,
+//       const boost::uint32_t show_flag,
+//       bool fit_to_display ,
+//       float width ,
+//       float height
+//  );
+//     void main_loop();
+//protected:
+//     void render();
+//     toplevel_window(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width = 640,float height = 480) : base_window(menu_name,name,fit_to_display,width,height) 
+//     {
+//             on_render.connect(boost::bind(&toplevel_window::render,this));
+//     };
+//     LRESULT toplevel_window::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam);
+//};
+
+struct av_mm_thread_characteristics
+{
+       av_mm_thread_characteristics(std::wstring& str) : task_name_(str)
+       {
+               handle_ = ::AvSetMmThreadCharacteristicsW(str.c_str(),(LPDWORD)&task_index_);
+       }
+
+       bool set_priority(AVRT_PRIORITY p){return (::AvSetMmThreadPriority(handle_,p) == TRUE);}
+
+       ~av_mm_thread_characteristics()
+       {
+               ::AvRevertMmThreadCharacteristics(handle_);
+       }
+
+private:
+       std::wstring task_name_;
+       boost::uint32_t task_index_;
+       HANDLE handle_;
+};
+
+struct widget
+{
+       void draw();
+       float x_,y_;
+};
+
+typedef sf::begin_draw<ID2D1BitmapRenderTargetPtr> begin_draw_bitmap;
+typedef sf::begin_draw<ID2D1HwndRenderTargetPtr> begin_draw_hwnd;
+
+}
\ No newline at end of file
diff --git a/singleton.h b/singleton.h
new file mode 100644 (file)
index 0000000..298dff8
--- /dev/null
@@ -0,0 +1,55 @@
+#pragma once
+/*
+  ==============================================================================
+
+   This file is part of the S.F.Tracker
+   Copyright 2005-7 by Satoshi Fujiwara.
+
+   S.F.Tracker can be redistributed and/or modified under the terms of the
+   GNU General Public License, as published by the Free Software Foundation;
+   either version 2 of the License, or (at your option) any later version.
+
+   S.F.Tracker 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with S.F.Tracker; if not, visit www.gnu.org/licenses or write to the
+   Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
+   Boston, MA 02111-1307 USA
+
+  ==============================================================================
+*/
+/** @file
+ *  @brief 
+ *  @author S.F. (Satoshi Fujiwara)
+ */
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+namespace sf {
+    template<typename BaseClass,template <class> class PointerType = boost::shared_ptr > struct singleton 
+    {
+        typedef PointerType<BaseClass> ptr;
+        friend  BaseClass;
+        static ptr& instance()
+        {
+            boost::call_once(init,flag_);
+            return instance_;
+        };
+
+
+        singleton(){};
+    private:
+        singleton(const singleton& );
+               static void init(){instance_.reset(new BaseClass);};
+        static PointerType<BaseClass> instance_;
+        static boost::once_flag flag_;
+    };
+
+    template<class BaseClass,template <class> class PointerType> boost::once_flag singleton<BaseClass,PointerType>::flag_ = BOOST_ONCE_INIT;
+    template<class BaseClass,template <class> class PointerType> PointerType<BaseClass> singleton<BaseClass,PointerType>::instance_;
+};
+
+
diff --git a/small.ico b/small.ico
new file mode 100644 (file)
index 0000000..d551aa3
Binary files /dev/null and b/small.ico differ
diff --git a/smf.cpp b/smf.cpp
new file mode 100644 (file)
index 0000000..2afe687
--- /dev/null
+++ b/smf.cpp
@@ -0,0 +1,76 @@
+/*
+  SMF utility functions
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Mar.14.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "smf.h"
+
+int *smf_number_conversion( long num ) {
+
+  /* Max number of result data sequents are limitted to 
+     4 bytes. */
+
+  static int smf_number[4];
+  int i,j;
+  int is_exist_upper_bytes;
+
+  if ( num < 0 || num >= 128*128*128*128) {
+    /* invalid smf number */
+    return NULL;
+  }
+
+  for ( i=0 ; i<4 ; i++ ) {
+    smf_number[i]=0;
+  }
+  i=0;
+  is_exist_upper_bytes = 0;
+
+  j = (num / (128*128*128)) % 128;
+  if ( j > 0 ) {
+    smf_number[i++] = j + 0x80;
+    is_exist_upper_bytes = 1;
+  }
+  j = (num / (128*128)) % 128;
+  if ( j > 0 || is_exist_upper_bytes == 1 ) {
+    smf_number[i++] = j + 0x80;
+    is_exist_upper_bytes = 1;
+  }
+  j = (num / 128) % 128;
+  if ( j > 0 || is_exist_upper_bytes == 1 ) {
+    smf_number[i++] = j + 0x80;
+  }
+  j = num % 128;
+  smf_number[i] = j;
+
+  return smf_number;
+}
+
diff --git a/smf.h b/smf.h
new file mode 100644 (file)
index 0000000..67ab4ce
--- /dev/null
+++ b/smf.h
@@ -0,0 +1,120 @@
+/*
+  SMF data structure
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Mar.12.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef _SMF_H_
+#define _SMF_H_
+
+#define SMF_MTHD_HEADER_SIZE 14
+
+#define SMF_HEADER_STRING    "MThd"
+#define SMF_TRACK_STRING     "MTrk"
+
+#define SMF_TERM  -1            /* terminator */
+
+/*
+  These definitions are introduced from midiplay/midi.h
+  by Takanari HAYAMA 
+   */
+
+/* MIDI COMMANDS */
+#define MIDI_NOTEOFF    0x80    /* Note off */
+#define MIDI_NOTEON     0x90    /* Note on */
+#define MIDI_PRESSURE   0xa0    /* Polyphonic key pressure */
+#define MIDI_CONTROL    0xb0    /* Control change */
+#define MIDI_PROGRAM    0xc0    /* Program change */
+#define MIDI_CHANPRES   0xd0    /* Channel pressure */
+#define MIDI_PITCHB     0xe0    /* Pitch wheel change */
+#define MIDI_SYSEX      0xf0    /* System exclusive data */
+#define MIDI_META       0xff    /* Meta event header */
+
+/* META-EVENT MESSAGE TYPES */
+#define META_SEQNUM             0x00    /* Sequence number */
+#define META_TEXT               0x01    /* Text event */
+#define META_COPYRIGHT          0x02    /* Copyright notice */
+#define META_SEQNAME            0x03    /* Sequence/track name */
+#define META_INSTNAME           0x04    /* Instrument name */
+#define META_LYRIC              0x05    /* Lyric */
+#define META_MARKER             0x06    /* Marker */
+#define META_CUEPT              0x07    /* Cue point */
+#define META_EOT                0x2f    /* End of track */
+#define META_TEMPO              0x51    /* Set tempo */
+#define META_SMPTE              0x54    /* SMPTE offset */
+#define META_TIMESIG            0x58    /* Time signature */
+#define META_KEYSIG             0x59    /* Key signature */
+#define META_SEQSPEC            0x7f    /* Sequencer-specific event */
+
+#define META_PORT               0x21    /* Port change (unautherized) */
+
+/* CONTROL CHANGE FUNCTIONS */
+#define SMF_CTRL_BANK_SELECT_M      0x00
+#define SMF_CTRL_MODULATION_DEPTH   0x01
+#define SMF_CTRL_BLESS_TYPE         0x02
+#define SMF_CTRL_FOOT_TYPE          0x04
+#define SMF_CTRL_PORTAMENT_TIME     0x05
+#define SMF_CTRL_DATA_ENTRY_M       0x06
+#define SMF_CTRL_MAIN_VOLUME        0x07
+#define SMF_CTRL_BALLANCE_CTRL      0x08
+#define SMF_CTRL_PANPOT             0x0a
+#define SMF_CTRL_EXPRESSION         0x0b
+
+#define SMF_CTRL_BANK_SELECT_L      0x20
+#define SMF_CTRL_DATA_ENTRY_L       0x26
+
+#define SMF_CTRL_HOLD1              0x40
+#define SMF_CTRL_PORTAMENT          0x41
+#define SMF_CTRL_SUSTENUTE          0x42
+#define SMF_CTRL_SOFT_PEDAL         0x43
+#define SMF_CTRL_HOLD2              0x45
+
+#define SMF_CTRL_REVERB             0x5b
+#define SMF_CTRL_TREMOLO            0x5c
+#define SMF_CTRL_CHORUS             0x5d
+#define SMF_CTRL_DELAY              0x5e
+#define SMF_CTRL_PHASER             0x5f
+
+#define SMF_CTRL_DATA_INCLEMENT     0x60
+#define SMF_CTRL_DATA_DECLIMENT     0x61
+#define SMF_CTRL_NRPM_L             0x62
+#define SMF_CTRL_NRPN_M             0x63
+#define SMF_CTRL_RPN_L              0x64
+#define SMF_CTRL_RPN_M              0x65
+
+#define SMF_CTRL_ALL_SOUND_OFF      0x78
+#define SMF_CTRL_RESET_ALL_CTRL     0x79
+#define SMF_CTRL_LOCAL_CONTROL      0x7a
+#define SMF_CTRL_ALL_NOTE_OFF       0x7b
+#define SMF_CTRL_OMNI_MODE_OFF      0x7c
+#define SMF_CTRL_OMNI_MODE_ON       0x7d
+#define SMF_CTRL_MONO_MODE_ON       0x7e
+#define SMF_CTRL_POLI_MODE_ON       0x7f
+
+/* functions */
+
+int *smf_number_conversion( long num );
+
+#endif /* _SMF_H_ */
diff --git a/smffile.cpp b/smffile.cpp
new file mode 100644 (file)
index 0000000..b0a4820
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+  SMF file loader & checker
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.03.2000
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#else
+# ifdef HAVE_STRCHR
+#  define strchr index
+#  define strrchr rindex
+# endif
+#endif
+
+#include <sys/stat.h>
+
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include "smfplay.h"
+
+SMF_DATA *smf_read_file( char *name ) {
+
+  FILE *fp;
+  struct stat stt;
+  SMF_DATA *smf;
+  unsigned char *n;
+  int s;
+
+  /* data read */
+
+  smf = (SMF_DATA *)malloc(sizeof(SMF_DATA));
+  if ( smf == NULL ) return NULL;
+
+  if ( stat( name, &stt ) ) return NULL;
+  fp = fopen( name, "r" );
+  if ( fp == NULL ) return NULL;
+
+  smf->length = stt.st_size;
+  smf->data = (unsigned char *)malloc(sizeof(unsigned char)*smf->length);
+  fread( smf->data, 1, smf->length, fp );
+
+  n = (uint8*)ctime(&(stt.st_mtime));
+  s = strlen((char*)n)+4;
+  smf->date = (unsigned char *)malloc(sizeof(unsigned char)*s);
+  strcpy( (char*)smf->date, (char*)n );
+  n = (uint8*)strrchr( (char*)smf->date, '\n' );
+  if ( n != NULL ) *n = '\0';
+
+  fclose(fp);
+
+  n = (uint8*)strrchr( name, '/' );
+  if ( n == NULL ) n=(uint8*)name-1;
+  n++;
+  s = strlen((char*)n)+4;
+  smf->file_name = (unsigned char *)malloc(sizeof(unsigned char)*s);
+  strcpy( (char*)smf->file_name, (char*)n );
+
+  return smf;
+}
+
+int smf_close( SMF_DATA *smf ) {
+
+  if ( smf == NULL ) return 0;
+  if ( smf->date != NULL ) free(smf->date);    /* time stamp */
+  if ( smf->data != NULL ) free(smf->data);    /* SMF data */
+  if ( smf->file_name != NULL ) free(smf->file_name);
+
+  free(smf);
+  smf=NULL;
+
+  return 0;
+}
diff --git a/smfplay.cpp b/smfplay.cpp
new file mode 100644 (file)
index 0000000..5f58a5c
--- /dev/null
@@ -0,0 +1,608 @@
+/*
+  SMF player engine
+
+  Copyright 1999 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Jan.29.2000
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+#include "stdafx.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#else
+# ifdef HAVE_STRCHR
+#  define strchr index
+#  define strrchr rindex
+# endif
+#endif
+
+#ifdef TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <signal.h>
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+# include <sched.h>
+#endif
+#ifdef _POSIX_MEMLOCK
+# include <sys/mman.h>
+#endif
+
+#include "smfplay.h"
+#include "smf.h"
+#include "mididev.h"
+#include "gettext_wrapper.h"
+#include "version.h"
+
+#ifndef timercmp
+# define       timercmp(tvp, uvp, cmp)\
+               ((tvp)->tv_sec cmp (uvp)->tv_sec ||\
+               (tvp)->tv_sec == (uvp)->tv_sec &&\
+               (tvp)->tv_usec cmp (uvp)->tv_usec)
+#endif
+
+#ifdef HAVE_DEV_RTC
+# define SMFPLAY_WAIT_INTERVAL  1 /* (ms) */
+#else
+# if (HZ>100)
+#  define SMFPLAY_WAIT_INTERVAL 2  /* (ms) */
+# else
+#  define SMFPLAY_WAIT_INTERVAL 10  /* (ms) */
+# endif
+#endif
+
+/* ------------------------------------------------------------------- */
+
+/* player's functions */
+
+static int set_signals( void );
+static int put_event( SMF_DATA *, int );
+static int priority_init( void );
+
+static int smf_init_track_buffer( SMF_DATA * );
+static int read_smf_header( SMF_DATA * );
+static int set_new_event( SMF_DATA *, int );
+static long get_smf_number( SMF_DATA *, int );
+
+static int is_player_alive;
+
+inline long timerdiff( struct timeval *st, struct timeval *et ) {
+  long reth, retl;
+  retl = st->tv_usec - et->tv_usec;
+  reth = st->tv_sec - et->tv_sec;
+  if ( retl < 0 ) {
+    reth--;
+    retl+=(1000*1000);
+  }
+  return (reth*1000*1000)+retl;
+}
+
+/* ------------------------------------------------------------------- */
+
+/* SMF player engine */
+int smfplay( SMF_DATA *smf ) {
+
+  struct timeval st,et;
+  int rtm_delta=0;
+
+  if ( smf_init_track_buffer( smf ) != 0 ) return 1;
+  if ( read_smf_header( smf )   != 0 ) return 1;
+
+  /* prepare for output device (/dev/midi, /dev/ttyS0, etc) */
+
+  if ( smf->output_device == NULL ) {
+    fprintf(stderr,_("No output device is specified.\n"));
+    return 1;
+  }
+  if ( open_midi_device( smf->output_device, smf->is_buffered ) ) {
+    /* Cannot open midi device */
+    fprintf(stderr,_("Cannot open midi device\n"));
+    return 1;
+  }
+
+  /* prepare for signal */
+
+  set_signals();
+
+  /* prepare for priority ('setuid root' is required) */
+
+  priority_init();
+
+  /* start playing */
+
+  send_midi_reset();
+  myusleep( 50 * 1000 );
+
+  /* get first current time */
+  gettimeofday( &st, NULL );
+
+  if ( smf->is_send_rtm == FLAG_TRUE ) {
+    send_rtm_start();
+  }
+  smf->rtm_delta = smf->timebase / 24;
+
+  is_player_alive = FLAG_TRUE;
+  while( is_player_alive == FLAG_TRUE ) {
+    int track;
+    int is_all_tracks_finished;
+
+    /* wait a delta time */
+
+    st.tv_usec += smf->tempo_delta;
+    while ( st.tv_usec >= 1000*1000 ) {
+      st.tv_usec-=1000*1000;
+      st.tv_sec++;
+    }
+
+    smf->rtm_delta--;
+    if ( smf->rtm_delta <= 0 ) {
+      if ( smf->is_send_rtm == FLAG_TRUE ) {
+       send_rtm_timingclock();
+      }
+      smf->rtm_delta = smf->timebase / 24;
+    }
+
+    {
+      long s;
+      flush_midi();
+      gettimeofday( &et, NULL );
+      s = timerdiff( &st, &et );
+      if ( s > SMFPLAY_WAIT_INTERVAL*1000 ) {
+       myusleep(s);
+       gettimeofday( &et, NULL );
+      }
+    }
+    if ( et.tv_sec - st.tv_sec > 1 ) {
+      st.tv_sec  = et.tv_sec;
+      st.tv_usec = et.tv_usec;
+    }
+
+    is_all_tracks_finished = FLAG_TRUE;
+
+    smf->step++;
+
+    for ( track=0 ; track < smf->tracks ; track++ ) {
+      /* Have the track finished ? */
+      if ( smf->track[track].finished == FLAG_TRUE )
+       continue;
+
+      is_all_tracks_finished = FLAG_FALSE;
+
+      /* checks whether the step time is expired */
+      smf->track[track].delta_step++;
+      smf->track[track].total_step++;
+      smf->track[track].step--;
+
+      while ( smf->track[track].step == 0 ) {
+       if ( smf->track[track].finished == FLAG_TRUE ) break;
+       set_new_event( smf, track );
+       put_event( smf, track );
+      }
+    }
+    if ( is_all_tracks_finished == FLAG_TRUE ) break;
+
+  }
+
+  if ( smf->is_send_rtm == FLAG_TRUE ) {
+    send_rtm_stop();
+  }
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+  sched_yield();
+#endif
+#ifdef _POSIX_MEMLOCK
+  munlockall();
+#endif
+
+  close_midi_device();
+
+  return 0;
+}
+
+/* ------------------------------------------------------------------- */
+
+static int put_event( SMF_DATA *smf, int track ) {
+
+  int i;
+  static int current_port = -1;
+
+  if ( smf->result[0] == SMF_TERM ) return 0;
+
+  /* is the track disabled ? */
+  if ( smf->track[track].enabled == FLAG_FALSE && 
+       smf->result[0] != MIDI_NOTEOFF ) {
+    goto put_event_end;
+  }
+  
+  /* flushing MIDI data */
+  
+  if ( current_port != smf->track[track].port ) {
+    change_midi_port( smf->track[track].port );
+    current_port = smf->track[track].port;
+  }
+
+  i=0;
+  while ( smf->result[i] != SMF_TERM ) {
+    put_midi(smf->result[i++]);
+  }
+
+  switch( smf->result[0]&0xf0 ) {
+  case 0x80:
+    smf->track[track].notes[smf->result[1]]=0;
+    break;
+
+  case 0x90:
+    smf->track[track].notes[smf->result[1]]=smf->result[2];
+    break;
+
+  default:
+    break;
+  }
+
+  smf->track[track].delta_step = 0;
+  
+put_event_end:
+  smf->result[0] = SMF_TERM;
+
+  return 0;
+}
+
+static int set_new_event( SMF_DATA *smf, int t ) {
+
+  int ptr;
+  unsigned char *data;
+  int ret;
+
+  ret = 0;
+  data = smf->data;
+  ptr  = smf->track[t].current_ptr;
+
+  if ( ptr >= smf->track[t].top + smf->track[t].size ) {
+    smf->track[t].finished = FLAG_TRUE;
+    return 1;
+  }
+
+  if ( data[ptr+0] < 0x80 )
+    smf->result[0] = smf->track[t].last_event;
+  else {
+    smf->track[t].last_event = data[ptr+0];
+    smf->result[0] = data[ptr+0];
+    ptr++;
+  }
+
+  switch ( smf->result[0]&0xf0 ) {
+  case 0x80:
+  case 0x90:
+  case 0xa0:
+  case 0xb0:
+  case 0xe0:
+    smf->result[1] = data[ptr++];
+    smf->result[2] = data[ptr++];
+    smf->result[3] = SMF_TERM;
+    break;
+
+  case 0xc0:
+  case 0xd0:
+    smf->result[1] = data[ptr++];
+    smf->result[2] = SMF_TERM;
+    break;
+
+  default: /* exclusive & meta event */
+    switch ( smf->result[0] ) {
+      int size;
+      int type;
+      int i;
+
+    case 0xf0:
+      i=0;
+      smf->result[i++] = 0xf0;
+      size = get_smf_number( smf, ptr );
+      while( data[ptr++] >= 0x80 ){};
+      while ( size>0 && i < SMF_MAX_RESULT_SMF_SIZE ) {
+       smf->result[i++] = data[ptr++];
+       size--;
+      }
+      smf->result[i] = SMF_TERM;
+      break;
+
+    case 0xf7:
+      i=0;
+      size = get_smf_number( smf, ptr );
+      while( data[ptr++] >= 0x80 ){};
+      while ( size>0 && i < SMF_MAX_RESULT_SMF_SIZE ) {
+       smf->result[i++] = data[ptr++];
+       size--;
+      }
+      smf->result[i] = SMF_TERM;
+      break;
+
+    case 0xff:
+      smf->result[0]=SMF_TERM;
+      type = data[ptr++];
+      size = get_smf_number( smf, ptr );
+      while( data[ptr++] >= 0x80 );
+
+      switch(type) {
+      case META_TEMPO:
+       smf->tempo = (data[ptr+0]<<16) + (data[ptr+1]<<8) + data[ptr+2];
+       smf->tempo_delta = smf->tempo / smf->timebase;
+       break;
+
+      case META_PORT:
+       smf->track[t].port = data[ptr];
+       break;
+
+      case META_EOT:
+       smf->track[t].finished = FLAG_TRUE;
+       break;
+
+      case META_KEYSIG:
+       i = data[ptr];
+       if ( i>0x80 ) i = 255-i;
+       if ( data[ptr] == 1 ) i+=16;
+       smf->key = i;
+       break;
+
+      case META_TIMESIG:
+       break;
+
+      case META_TEXT:
+      case META_COPYRIGHT:
+      case META_SEQNAME:
+      case META_INSTNAME:
+      case META_LYRIC:
+      case META_MARKER:
+      case META_CUEPT:
+       i=0;
+       while ( i<size && i<SMF_MAX_MESSAGE_SIZE-1 ) {
+         smf->track[t].message[i] = data[ptr+i];
+         i++;
+       }
+       smf->track[t].message[i] = '\0';
+       break;
+
+      default:
+       break;
+      }
+      ptr+=size;
+      break;
+
+    case 0xf1:
+    case 0xf2:
+    case 0xf3:
+    case 0xf5:
+      ptr++;
+      break;
+
+    default:
+      break;
+    }
+    break;
+  }
+
+  if ( smf->track[t].finished == FLAG_FALSE ) {
+    smf->track[t].step = get_smf_number( smf, ptr );
+    while( data[ptr++] >= 0x80 );
+  }
+  else {
+    smf->track[t].step = 0;
+  }
+
+  smf->track[t].current_ptr = ptr;
+  return 0;
+}
+
+/* ------------------------------------------------------------------- */
+
+static long get_smf_number( SMF_DATA *smf, int ptr ) {
+
+  long ret;
+  unsigned char *p;
+
+  p = smf->data+ptr;
+
+  ret = 0;
+  while( *p >= 0x80 ) {
+    ret = (ret<<7) + (*p&0x7f);
+    p++;
+  }
+  ret = (ret<<7) + *p;
+
+  return ret;
+}
+
+/* ------------------------------------------------------------------- */
+
+static int smf_init_track_buffer( SMF_DATA *smf ) {
+
+  int track,n;
+
+  smf->step            = -1;
+  smf->result[0]       = SMF_TERM;
+  smf->tempo           = 1000*1000*16;
+
+  for ( track=0 ; track<SMF_MAX_TRACKS ; track++ ) {
+    smf->track[track].enabled      = FLAG_FALSE;
+    smf->track[track].finished     = FLAG_FALSE;
+
+    smf->track[track].step         = 1;
+    smf->track[track].delta_step   = -1;   /* initial value should be -1 */
+    smf->track[track].total_step   = -1;
+
+    smf->track[track].current_ptr  = 0;
+
+    smf->track[track].last_event   = 0;
+    smf->track[track].port         = 0;
+
+    for ( n=0 ; n<SMF_MAX_NOTES ; n++ )
+      smf->track[track].notes[n]   = 0;
+    smf->track[track].all_notes_expired = FLAG_TRUE;
+  }
+
+  return 0;
+}
+
+static int read_smf_header( SMF_DATA *smf ) {
+
+  int t;
+  unsigned char *data, *ptr;
+
+  data = smf->data;
+
+  /* check 1st header */
+
+  if ( strncmp( data, SMF_HEADER_STRING, 4 ) !=0 ) {
+    if ( strncmp( data+128, SMF_HEADER_STRING, 4 ) !=0 ) { /* Mac binary */
+      return 1;
+    } else {
+      data+=128;
+    }
+  }
+
+  /* Header chunk */
+
+  smf->format = (data[0x08] << 8) + data[0x09];
+  if ( smf->format != 0 && smf->format != 1 )
+    return 1; /* Only supports format 0 and 1 */
+
+  smf->tracks    = (data[0x0a] << 8) + data[0x0b];
+  smf->timebase  = (data[0x0c] << 8) + data[0x0d];
+  smf->rtm_delta = smf->timebase / 24;
+  if ( data[0x0c] > 0x7f )
+    return 1; /* Not supports SMPTE format */
+
+  ptr = data+8+ (data[0x04]<<24) + (data[0x05]<<16) + (data[0x06]<<8) + data[0x07];
+
+  /* Track chunk */
+
+  for ( t=0 ; t<smf->tracks ; t++ ) {
+    long size;
+    unsigned char *p;
+
+    if ( ptr+8 > smf->data + smf->length )
+      break;
+
+    if ( strncmp( ptr, SMF_TRACK_STRING, 4 ) !=0 ) {
+      return 1;
+    }
+
+    smf->track[t].enabled    = FLAG_TRUE;
+
+    size = (ptr[0x04]<<24) + (ptr[0x05]<<16) + (ptr[0x06]<<8) + ptr[0x07];
+    smf->track[t].top = (ptr+8 - smf->data);
+    smf->track[t].size = size;
+
+    smf->track[t].step = get_smf_number( smf, smf->track[t].top )+1;
+    p = ptr+8;
+    while( *(p++) >= 0x80 );
+    smf->track[t].current_ptr = (long)(p-smf->data);
+
+    ptr = ptr+8+size;
+  }
+
+  return 0;
+}
+
+/* ------------------------------------------------------------------- */
+
+/* Signals configuration */
+
+static RETSIGTYPE sigexit( int num ) {
+  send_rtm_stop();
+  send_midi_reset();
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+  sched_yield();
+#endif
+#ifdef _POSIX_MEMLOCK
+  munlockall();
+#endif
+
+  fprintf(stderr,"Signal caught : %d\n", num);
+  exit(1);
+}
+
+static RETSIGTYPE sig_stop_play( int num ) {
+  send_midi_reset();
+  send_rtm_stop();
+
+  signal( SIGINT, SIG_DFL );
+  is_player_alive = FLAG_FALSE;
+
+  return;
+}
+
+static const int signals[]={SIGHUP,SIGQUIT,SIGILL,SIGABRT,SIGFPE,
+                              SIGBUS,SIGSEGV,SIGPIPE,SIGTERM,0};
+
+static int set_signals( void ) {
+
+  int i;
+
+  for ( i=0 ; signals[i]!=0 ; i++ )
+    signal( signals[i], sigexit );
+
+  signal( SIGINT, sig_stop_play );
+
+  return 0;
+}
+
+/* priority configuration : only when program is setuid root-ed */
+
+static int priority_init( void ) {
+
+#ifdef _POSIX_PRIORITY_SCHEDULING
+  struct sched_param ptmp, *priority_param;
+  int i;
+
+  priority_param=&ptmp;
+  i=sched_get_priority_max( SCHED_FIFO );
+  priority_param->sched_priority = i/2; /* no means */
+  sched_setscheduler( 0, SCHED_FIFO, priority_param );
+#endif
+#ifdef _POSIX_MEMLOCK
+  mlockall(MCL_CURRENT);
+#endif
+
+  return 0;
+}
diff --git a/smfplay.h b/smfplay.h
new file mode 100644 (file)
index 0000000..4b73714
--- /dev/null
+++ b/smfplay.h
@@ -0,0 +1,122 @@
+/*
+  tiny SMF player
+
+  Copyright 2000 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.03.2000
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef _SMFPLAY_H_
+#define _SMFPLAY_H_
+
+#define FLAG_TRUE  1
+#define FLAG_FALSE 0
+
+#define SMF_MAX_TRACKS            128
+#define SMF_MAX_NOTES             128
+
+#define SMF_MAX_RESULT_SMF_SIZE  1024
+#define SMF_MAX_MESSAGE_SIZE     1024
+
+#define ENABLE_PORT_CHANGE
+
+/* structs */
+
+typedef struct _SMF_TRACK {
+  int           top;                        /* base pointer */
+  int           size;                       /* data size */
+  int           midi_ch;                    /* midi channel */
+  int           port;                       /* midi port (0 or 1 ) */
+
+  /* track work */
+
+  int           enabled;
+  int           finished;
+
+  int           current_ptr;
+  long          delta_step;
+  long          total_step;
+
+  int           event;
+  long          step;
+  int           vel;
+
+  int           last_event;
+
+  int           notes[SMF_MAX_NOTES];
+  int           all_notes_expired;
+
+  unsigned char message[SMF_MAX_MESSAGE_SIZE+10];
+
+} SMF_TRACK;
+
+typedef struct _SMF_DATA {
+
+  unsigned char *data;        /* data */
+  size_t         length;      /* data length */
+  unsigned char *file_name;   /* original SMF/G36 filename */
+  unsigned char *date;        /* original SMF/R36 timestamp */
+  unsigned char *command_name;/* command name ( typically "SMFtomid" ) */
+
+  unsigned char  title[65];   /* data title ( perhaps SJIS ) */
+
+  int format;                 /* SMF format */
+  int timebase;               /* timebase */
+  long tempo;                 /* tempo */
+  long tempo_delta;           /* tempo / timebase */
+  long rtm_delta;             /* tempo / 24 */
+  int beat_h;                 /* beat */
+  int beat_l;                 /* beat */
+
+  int key;                    /* key */
+  int play_bias;              /* play bias */
+
+  int tracks;                 /* track number (SMF:18 R36:26) */
+
+  long step;                  /* total step */
+
+                              /* user exclusive */
+
+                              /* track work area */
+
+  SMF_TRACK track[SMF_MAX_TRACKS];
+
+  int result[SMF_MAX_RESULT_SMF_SIZE+10];
+
+  int            enable_converter_notice;
+  int            enable_verbose;
+
+  /* player's informations */
+
+  char          *output_device;
+  int            is_player;
+  int            is_send_rtm;
+  int            is_buffered;
+
+} SMF_DATA;
+
+ void           error_end( char *);
+ SMF_DATA      *smf_read_file( char * );
+ int            smf_close( SMF_DATA * );
+
+#endif /* _SMFPLAY_H_ */
diff --git a/smfplay_main.cpp b/smfplay_main.cpp
new file mode 100644 (file)
index 0000000..13204d4
--- /dev/null
@@ -0,0 +1,264 @@
+/*
+  tiny SMF player
+
+  Copyright 2000 by Daisuke Nagano <breeze.nagano@nifty.ne.jp>
+  Feb.03.1999
+  Oct.16.2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+
+/* ------------------------------------------------------------------- */
+#include "stdafx.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef STDC_HEADERS
+# include <string.h>
+#else
+# ifndef HAVE_STRCHR
+#  define strchr index
+#  define strrchr rindex
+# endif
+#endif
+
+#ifndef USE_NETBSDGETOPT
+# include <getopt.h>
+#else
+# include "netbsdgetopt.h"
+#endif
+
+#include "smfplay.h"
+#include "gettext_wrapper.h"
+#include "version.h"
+
+#define PATH_BUF_SIZE 1024
+
+/* ------------------------------------------------------------------- */
+
+void error_end( char * );
+static int option_gets( int, char ** );
+static void usage( void );
+static void display_version( void );
+
+static char *command_name   = NULL;
+static int verbose          = FLAG_FALSE;
+static int is_send_rtm      = FLAG_FALSE;
+static int is_buffered      = FLAG_TRUE;
+static unsigned char *outdev= NULL;
+
+int reset_mode=0;
+
+extern int smfplay( SMF_DATA *);
+
+/* ------------------------------------------------------------------- */
+
+int main( int argc, char **argv ) {
+
+  int num;
+  char *a, buf[PATH_BUF_SIZE];
+  int isonefile;
+
+  SMF_DATA *smf;
+
+#ifdef ENABLE_NLS
+  setlocale( LC_ALL, "" );
+  bindtextdomain( PACKAGE, LOCALEDIR );
+  textdomain( PACKAGE );
+#endif /* ENABLE_NLS */
+
+  num = option_gets( argc, argv );
+  if ( num == argc-1 ) isonefile=FLAG_TRUE;
+  else isonefile=FLAG_FALSE;
+
+  /* main loop */
+
+  while ( num < argc ) {
+    char *name;
+    name = argv[num++];
+
+    if ( isonefile==FLAG_FALSE ) {
+      if ( (a=strrchr( name, '.' ))==NULL ) continue; /* no extension */
+
+      if ( strcasecmp( a, ".mid" )!=0 ) continue;
+    }
+
+    smf = smf_read_file( name );
+    if ( smf==NULL ) {
+      snprintf( buf, PATH_BUF_SIZE, _("Cannot open file %s.\n"), argv[num-1] );
+      error_end(buf);
+    }
+
+    smf->command_name   = command_name;
+    smf->enable_verbose = verbose;
+    smf->is_send_rtm    = is_send_rtm;
+    smf->is_buffered    = is_buffered;
+
+    if ( verbose == FLAG_TRUE ) {
+      fprintf( stderr, _("Filename = %s\n"), name );
+    }
+    
+    if ( outdev != NULL )
+      smf->output_device = outdev;
+    else
+      smf->output_device = DEFAULT_OUTPUT_DEVICE;
+    
+    smfplay( smf );
+    smf_close( smf );
+  }
+
+  /* finished */
+
+  exit(0);
+}
+
+/* ------------------------------------------------------------------- */
+
+void error_end( char *msg ) {
+
+  fprintf( stderr, "%s: %s\n", command_name, msg );
+  exit(1);
+}
+
+/* ------------------------------------------------------------------- */
+
+static int option_gets( int argc, char **argv ) {
+
+  extern char *optarg;
+  extern int optind;
+
+  int c;
+  int option_index=0;
+
+  command_name =
+    (strrchr(argv[0],'/')==NULL)?argv[0]:(strrchr(argv[0],'/')+1);
+
+  verbose = FLAG_FALSE;
+  is_send_rtm = FLAG_FALSE;
+  is_buffered = FLAG_TRUE;
+
+  while(1) {
+    static struct option long_options[] = {
+      {"no-buffered",   0, 0, 'b'},
+      {"send-seq",      0, 0, 100},
+      {"outdev",        1, 0, 'm'},
+      {"reset-mode",    1, 0, 'r'},
+      {"version",       0, 0, 'V'},
+      {"verbose",       0, 0, 'v'},
+      {"help",          0, 0, 'h'},
+      {0, 0, 0, 0}
+    };
+
+    c = getopt_long(argc, argv, "Vvbm:r:h", long_options, &option_index );
+    if ( c == EOF ) break;
+
+    switch(c) {
+
+    case 100:
+      is_send_rtm = FLAG_TRUE;
+      break;
+
+    case 'b':
+      is_buffered = FLAG_FALSE;
+      break;
+
+    case 'm':
+      if ( outdev != NULL ) free(outdev);
+      outdev =  (unsigned char *)malloc(sizeof(unsigned char)*strlen(optarg)+16);
+      strcpy( outdev, optarg );
+      break;
+
+    case 'r':
+      reset_mode = atoi(optarg);
+      if ( reset_mode < 0 ) reset_mode = 0;
+      if ( reset_mode > 3 ) reset_mode = 0;
+      break;
+
+
+    case 'h': /* help */
+      usage();
+      break;
+
+    case 'V':
+      display_version(); /* version */
+      break;
+
+    case 'v':
+      verbose = FLAG_TRUE;
+      break;
+
+    case '?':
+      break;
+    default:
+      break;
+    }
+  }
+
+  if ( optind >= argc ) {
+    fprintf(stderr, _("%s: No input filename is specified.\n"), command_name);
+    exit(1);
+  } 
+
+  return optind;
+}
+
+static void usage( void ) {
+
+  fprintf(stderr, "usage: %s [options] [smf-filename]\n", command_name );
+  fprintf(stderr, _("Options:\n"));
+
+  fprintf(stderr, " -m,     --outdev <devname>   ");
+  fprintf(stderr, _("Output device name.\n"));
+  fprintf(stderr, " -r,     --reset-mode <val>   ");
+  fprintf(stderr, _("Send specified reset message after playing. \n"));
+  fprintf(stderr, "                               0:GM 1:GS 2:SC88 3:XG\n");
+  fprintf(stderr, " -v,     --verbose            ");
+  fprintf(stderr, _("Be verbose.\n"));
+  fprintf(stderr, " -V,     --version            ");
+  fprintf(stderr, _("Show version information.\n"));
+  fprintf(stderr, " -h,     --help               ");
+  fprintf(stderr, _("Show this help message.\n"));
+
+  exit(0);
+}
+
+static void display_version( void ) {
+
+  fprintf(stderr, "%s version ", command_name );
+  fprintf(stderr, VERSION_ID "\n");
+  fprintf(stderr, "tiny SMF player");
+#ifdef HAVE_STED2_SUPPORT
+  fprintf(stderr, " <STed2 support>");
+#endif
+  fprintf(stderr,"\n");
+
+  fprintf(stderr, "Copyright 2000 by NAGANO Daisuke <breeze.nagano@nifty.ne.jp>\n");
+  fprintf(stderr, "\n");
+  fprintf(stderr, "This is free software; see the source for copying conditions.\n");
+  fprintf(stderr, "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n");
+  fprintf(stderr, "PARTICULAR PURPOSE.\n\n");
+
+  exit(0);
+}
diff --git a/snprintf.cpp b/snprintf.cpp
new file mode 100644 (file)
index 0000000..163f52e
--- /dev/null
@@ -0,0 +1,1024 @@
+/*
+ * snprintf.c - a portable implementation of snprintf
+ *
+ * AUTHOR
+ *   Mark Martinec <mark.martinec@ijs.si>, April 1999.
+ *
+ *   Copyright 1999, Mark Martinec. All rights reserved.
+ *
+ * TERMS AND CONDITIONS
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the "Frontier Artistic License" which comes
+ *   with this Kit.
+ *
+ *   This program 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 Frontier Artistic License for more details.
+ *
+ *   You should have received a copy of the Frontier Artistic License
+ *   with this Kit in the file named LICENSE.txt .
+ *   If not, I'll be glad to provide one.
+ *
+ * FEATURES
+ * - careful adherence to specs regarding flags, field width and precision;
+ * - good performance for large string handling (large format, large
+ *   argument or large paddings). Performance is similar to system's sprintf
+ *   and in several cases significantly better (make sure you compile with
+ *   optimizations turned on, tell the compiler the code is strict ANSI
+ *   if necessary to give it more freedom for optimizations);
+ * - return value semantics per ISO/IEC 9899:1999 ("ISO C99");
+ * - written in standard ISO/ANSI C - requires an ANSI C compiler.
+ *
+ * SUPPORTED CONVERSION SPECIFIERS AND DATA TYPES
+ *
+ * This snprintf only supports the following conversion specifiers:
+ * s, c, d, u, o, x, X, p  (and synonyms: i, D, U, O - see below)
+ * with flags: '-', '+', ' ', '0' and '#'.
+ * An asterisk is supported for field width as well as precision.
+ *
+ * Length modifiers 'h' (short int), 'l' (long int),
+ * and 'll' (long long int) are supported.
+ * NOTE:
+ *   If macro SNPRINTF_LONGLONG_SUPPORT is not defined (default) the
+ *   length modifier 'll' is recognized but treated the same as 'l',
+ *   which may cause argument value truncation! Defining
+ *   SNPRINTF_LONGLONG_SUPPORT requires that your system's sprintf also
+ *   handles length modifier 'll'.  long long int is a language extension
+ *   which may not be portable.
+ *
+ * Conversion of numeric data (conversion specifiers d, u, o, x, X, p)
+ * with length modifiers (none or h, l, ll) is left to the system routine
+ * sprintf, but all handling of flags, field width and precision as well as
+ * c and s conversions is done very carefully by this portable routine.
+ * If a string precision (truncation) is specified (e.g. %.8s) it is
+ * guaranteed the string beyond the specified precision will not be referenced.
+ *
+ * Length modifiers h, l and ll are ignored for c and s conversions (data
+ * types wint_t and wchar_t are not supported).
+ *
+ * The following common synonyms for conversion characters are supported:
+ *   - i is a synonym for d
+ *   - D is a synonym for ld, explicit length modifiers are ignored
+ *   - U is a synonym for lu, explicit length modifiers are ignored
+ *   - O is a synonym for lo, explicit length modifiers are ignored
+ * The D, O and U conversion characters are nonstandard, they are supported
+ * for backward compatibility only, and should not be used for new code.
+ *
+ * The following is specifically NOT supported:
+ *   - flag ' (thousands' grouping character) is recognized but ignored
+ *   - numeric conversion specifiers: f, e, E, g, G and synonym F,
+ *     as well as the new a and A conversion specifiers
+ *   - length modifier 'L' (long double) and 'q' (quad - use 'll' instead)
+ *   - wide character/string conversions: lc, ls, and nonstandard
+ *     synonyms C and S
+ *   - writeback of converted string length: conversion character n
+ *   - the n$ specification for direct reference to n-th argument
+ *   - locales
+ *
+ * It is permitted for str_m to be zero, and it is permitted to specify NULL
+ * pointer for resulting string argument if str_m is zero (as per ISO C99).
+ *
+ * The return value is the number of characters which would be generated
+ * for the given input, excluding the trailing null. If this value
+ * is greater or equal to str_m, not all characters from the result
+ * have been stored in str, output bytes beyond the (str_m-1) -th character
+ * are discarded. If str_m is greater than zero it is guaranteed
+ * the resulting string will be null-terminated.
+ *
+ * NOTE that this matches the ISO C99, OpenBSD, and GNU C library 2.1,
+ * but is different from some older and vendor implementations,
+ * and is also different from XPG, XSH5, SUSv2 specifications.
+ * For historical discussion on changes in the semantics and standards
+ * of snprintf see printf(3) man page in the Linux programmers manual.
+ *
+ * Routines asprintf and vasprintf return a pointer (in the ptr argument)
+ * to a buffer sufficiently large to hold the resulting string. This pointer
+ * should be passed to free(3) to release the allocated storage when it is
+ * no longer needed. If sufficient space cannot be allocated, these functions
+ * will return -1 and set ptr to be a NULL pointer. These two routines are a
+ * GNU C library extensions (glibc).
+ *
+ * Routines asnprintf and vasnprintf are similar to asprintf and vasprintf,
+ * yet, like snprintf and vsnprintf counterparts, will write at most str_m-1
+ * characters into the allocated output string, the last character in the
+ * allocated buffer then gets the terminating null. If the formatted string
+ * length (the return value) is greater than or equal to the str_m argument,
+ * the resulting string was truncated and some of the formatted characters
+ * were discarded. These routines present a handy way to limit the amount
+ * of allocated memory to some sane value.
+ *
+ * AVAILABILITY
+ *   http://www.ijs.si/software/snprintf/
+ *
+ * REVISION HISTORY
+ * 1999-04     V0.9  Mark Martinec
+ *             - initial version, some modifications after comparing printf
+ *               man pages for Digital Unix 4.0, Solaris 2.6 and HPUX 10,
+ *               and checking how Perl handles sprintf (differently!);
+ * 1999-04-09  V1.0  Mark Martinec <mark.martinec@ijs.si>
+ *             - added main test program, fixed remaining inconsistencies,
+ *               added optional (long long int) support;
+ * 1999-04-12  V1.1  Mark Martinec <mark.martinec@ijs.si>
+ *             - support the 'p' conversion (pointer to void);
+ *             - if a string precision is specified
+ *               make sure the string beyond the specified precision
+ *               will not be referenced (e.g. by strlen);
+ * 1999-04-13  V1.2  Mark Martinec <mark.martinec@ijs.si>
+ *             - support synonyms %D=%ld, %U=%lu, %O=%lo;
+ *             - speed up the case of long format string with few conversions;
+ * 1999-06-30  V1.3  Mark Martinec <mark.martinec@ijs.si>
+ *             - fixed runaway loop (eventually crashing when str_l wraps
+ *               beyond 2^31) while copying format string without
+ *               conversion specifiers to a buffer that is too short
+ *               (thanks to Edwin Young <edwiny@autonomy.com> for
+ *               spotting the problem);
+ *             - added macros PORTABLE_SNPRINTF_VERSION_(MAJOR|MINOR)
+ *               to snprintf.h
+ * 2000-02-14  V2.0 (never released) Mark Martinec <mark.martinec@ijs.si>
+ *             - relaxed license terms: The Artistic License now applies.
+ *               You may still apply the GNU GENERAL PUBLIC LICENSE
+ *               as was distributed with previous versions, if you prefer;
+ *             - changed REVISION HISTORY dates to use ISO 8601 date format;
+ *             - added vsnprintf (patch also independently proposed by
+ *               Caolan McNamara 2000-05-04, and Keith M Willenson 2000-06-01)
+ * 2000-06-27  V2.1  Mark Martinec <mark.martinec@ijs.si>
+ *             - removed POSIX check for str_m<1; value 0 for str_m is
+ *               allowed by ISO C99 (and GNU C library 2.1) - (pointed out
+ *               on 2000-05-04 by Caolan McNamara, caolan@ csn dot ul dot ie).
+ *               Besides relaxed license this change in standards adherence
+ *               is the main reason to bump up the major version number;
+ *             - added nonstandard routines asnprintf, vasnprintf, asprintf,
+ *               vasprintf that dynamically allocate storage for the
+ *               resulting string; these routines are not compiled by default,
+ *               see comments where NEED_V?ASN?PRINTF macros are defined;
+ *             - autoconf contributed by Caolan McNamara
+ * 2000-10-06  V2.2  Mark Martinec <mark.martinec@ijs.si>
+ *             - BUG FIX: the %c conversion used a temporary variable
+ *               that was no longer in scope when referenced,
+ *               possibly causing incorrect resulting character;
+ *             - BUG FIX: make precision and minimal field width unsigned
+ *               to handle huge values (2^31 <= n < 2^32) correctly;
+ *               also be more careful in the use of signed/unsigned/size_t
+ *               internal variables - probably more careful than many
+ *               vendor implementations, but there may still be a case
+ *               where huge values of str_m, precision or minimal field
+ *               could cause incorrect behaviour;
+ *             - use separate variables for signed/unsigned arguments,
+ *               and for short/int, long, and long long argument lengths
+ *               to avoid possible incompatibilities on certain
+ *               computer architectures. Also use separate variable
+ *               arg_sign to hold sign of a numeric argument,
+ *               to make code more transparent;
+ *             - some fiddling with zero padding and "0x" to make it
+ *               Linux compatible;
+ *             - systematically use macros fast_memcpy and fast_memset
+ *               instead of case-by-case hand optimization; determine some
+ *               breakeven string lengths for different architectures;
+ *             - terminology change: 'format' -> 'conversion specifier',
+ *               'C9x' -> 'ISO/IEC 9899:1999 ("ISO C99")',
+ *               'alternative form' -> 'alternate form',
+ *               'data type modifier' -> 'length modifier';
+ *             - several comments rephrased and new ones added;
+ *             - make compiler not complain about 'credits' defined but
+ *               not used;
+ */
+
+
+/* Define HAVE_SNPRINTF if your system already has snprintf and vsnprintf.
+ *
+ * If HAVE_SNPRINTF is defined this module will not produce code for
+ * snprintf and vsnprintf, unless PREFER_PORTABLE_SNPRINTF is defined as well,
+ * causing this portable version of snprintf to be called portable_snprintf
+ * (and portable_vsnprintf).
+ */
+/* #define HAVE_SNPRINTF */
+
+/* Define PREFER_PORTABLE_SNPRINTF if your system does have snprintf and
+ * vsnprintf but you would prefer to use the portable routine(s) instead.
+ * In this case the portable routine is declared as portable_snprintf
+ * (and portable_vsnprintf) and a macro 'snprintf' (and 'vsnprintf')
+ * is defined to expand to 'portable_v?snprintf' - see file snprintf.h .
+ * Defining this macro is only useful if HAVE_SNPRINTF is also defined,
+ * but does does no harm if defined nevertheless.
+ */
+/* #define PREFER_PORTABLE_SNPRINTF */
+
+/* Define SNPRINTF_LONGLONG_SUPPORT if you want to support
+ * data type (long long int) and length modifier 'll' (e.g. %lld).
+ * If undefined, 'll' is recognized but treated as a single 'l'.
+ *
+ * If the system's sprintf does not handle 'll'
+ * the SNPRINTF_LONGLONG_SUPPORT must not be defined!
+ *
+ * This is off by default as (long long int) is a language extension.
+ */
+/* #define SNPRINTF_LONGLONG_SUPPORT */
+
+/* Define NEED_SNPRINTF_ONLY if you only need snprintf, and not vsnprintf.
+ * If NEED_SNPRINTF_ONLY is defined, the snprintf will be defined directly,
+ * otherwise both snprintf and vsnprintf routines will be defined
+ * and snprintf will be a simple wrapper around vsnprintf, at the expense
+ * of an extra procedure call.
+ */
+/* #define NEED_SNPRINTF_ONLY */
+
+/* Define NEED_V?ASN?PRINTF macros if you need library extension
+ * routines asprintf, vasprintf, asnprintf, vasnprintf respectively,
+ * and your system library does not provide them. They are all small
+ * wrapper routines around portable_vsnprintf. Defining any of the four
+ * NEED_V?ASN?PRINTF macros automatically turns off NEED_SNPRINTF_ONLY
+ * and turns on PREFER_PORTABLE_SNPRINTF.
+ *
+ * Watch for name conflicts with the system library if these routines
+ * are already present there.
+ *
+ * NOTE: vasprintf and vasnprintf routines need va_copy() from stdarg.h, as
+ * specified by C99, to be able to traverse the same list of arguments twice.
+ * I don't know of any other standard and portable way of achieving the same.
+ * With some versions of gcc you may use __va_copy(). You might even get away
+ * with "ap2 = ap", in this case you must not call va_end(ap2) !
+ *   #define va_copy(ap2,ap) ap2 = ap
+ */
+/* #define NEED_ASPRINTF   */
+/* #define NEED_ASNPRINTF  */
+/* #define NEED_VASPRINTF  */
+/* #define NEED_VASNPRINTF */
+
+
+/* Define the following macros if desired:
+ *   SOLARIS_COMPATIBLE, SOLARIS_BUG_COMPATIBLE,
+ *   HPUX_COMPATIBLE, HPUX_BUG_COMPATIBLE, LINUX_COMPATIBLE,
+ *   DIGITAL_UNIX_COMPATIBLE, DIGITAL_UNIX_BUG_COMPATIBLE,
+ *   PERL_COMPATIBLE, PERL_BUG_COMPATIBLE,
+ *
+ * - For portable applications it is best not to rely on peculiarities
+ *   of a given implementation so it may be best not to define any
+ *   of the macros that select compatibility and to avoid features
+ *   that vary among the systems.
+ *
+ * - Selecting compatibility with more than one operating system
+ *   is not strictly forbidden but is not recommended.
+ *
+ * - 'x'_BUG_COMPATIBLE implies 'x'_COMPATIBLE .
+ *
+ * - 'x'_COMPATIBLE refers to (and enables) a behaviour that is
+ *   documented in a sprintf man page on a given operating system
+ *   and actually adhered to by the system's sprintf (but not on
+ *   most other operating systems). It may also refer to and enable
+ *   a behaviour that is declared 'undefined' or 'implementation specific'
+ *   in the man page but a given implementation behaves predictably
+ *   in a certain way.
+ *
+ * - 'x'_BUG_COMPATIBLE refers to (and enables) a behaviour of system's sprintf
+ *   that contradicts the sprintf man page on the same operating system.
+ *
+ * - I do not claim that the 'x'_COMPATIBLE and 'x'_BUG_COMPATIBLE
+ *   conditionals take into account all idiosyncrasies of a particular
+ *   implementation, there may be other incompatibilities.
+ */
+
\f
+/* ============================================= */
+/* NO USER SERVICABLE PARTS FOLLOWING THIS POINT */
+/* ============================================= */
+
+#define PORTABLE_SNPRINTF_VERSION_MAJOR 2
+#define PORTABLE_SNPRINTF_VERSION_MINOR 2
+
+#if defined(NEED_ASPRINTF) || defined(NEED_ASNPRINTF) || defined(NEED_VASPRINTF) || defined(NEED_VASNPRINTF)
+# if defined(NEED_SNPRINTF_ONLY)
+# undef NEED_SNPRINTF_ONLY
+# endif
+# if !defined(PREFER_PORTABLE_SNPRINTF)
+# define PREFER_PORTABLE_SNPRINTF
+# endif
+#endif
+
+#if defined(SOLARIS_BUG_COMPATIBLE) && !defined(SOLARIS_COMPATIBLE)
+#define SOLARIS_COMPATIBLE
+#endif
+
+#if defined(HPUX_BUG_COMPATIBLE) && !defined(HPUX_COMPATIBLE)
+#define HPUX_COMPATIBLE
+#endif
+
+#if defined(DIGITAL_UNIX_BUG_COMPATIBLE) && !defined(DIGITAL_UNIX_COMPATIBLE)
+#define DIGITAL_UNIX_COMPATIBLE
+#endif
+
+#if defined(PERL_BUG_COMPATIBLE) && !defined(PERL_COMPATIBLE)
+#define PERL_COMPATIBLE
+#endif
+
+#if defined(LINUX_BUG_COMPATIBLE) && !defined(LINUX_COMPATIBLE)
+#define LINUX_COMPATIBLE
+#endif
+
+#include <sys/types.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <assert.h>
+#include <errno.h>
+
+#ifdef isdigit
+#undef isdigit
+#endif
+#define isdigit(c) ((c) >= '0' && (c) <= '9')
+
+/* For copying strings longer or equal to 'breakeven_point'
+ * it is more efficient to call memcpy() than to do it inline.
+ * The value depends mostly on the processor architecture,
+ * but also on the compiler and its optimization capabilities.
+ * The value is not critical, some small value greater than zero
+ * will be just fine if you don't care to squeeze every drop
+ * of performance out of the code.
+ *
+ * Small values favor memcpy, large values favor inline code.
+ */
+#if defined(__alpha__) || defined(__alpha)
+#  define breakeven_point   2  /* AXP (DEC Alpha)     - gcc or cc or egcs */
+#endif
+#if defined(__i386__)  || defined(__i386)
+#  define breakeven_point  12  /* Intel Pentium/Linux - gcc 2.96 */
+#endif
+#if defined(__hppa)
+#  define breakeven_point  10  /* HP-PA               - gcc */
+#endif
+#if defined(__sparc__) || defined(__sparc)
+#  define breakeven_point  33  /* Sun Sparc 5         - gcc 2.8.1 */
+#endif
+
+/* some other values of possible interest: */
+/* #define breakeven_point  8 */  /* VAX 4000          - vaxc */
+/* #define breakeven_point 19 */  /* VAX 4000          - gcc 2.7.0 */
+
+#ifndef breakeven_point
+#  define breakeven_point   6  /* some reasonable one-size-fits-all value */
+#endif
+
+#define fast_memcpy(d,s,n) \
+  { register size_t nn = (size_t)(n); \
+    if (nn >= breakeven_point) memcpy((d), (s), nn); \
+    else if (nn > 0) { /* proc call overhead is worth only for large strings*/\
+      register char *dd; register const char *ss; \
+      for (ss=(s), dd=(d); nn>0; nn--) *dd++ = *ss++; } }
+
+#define fast_memset(d,c,n) \
+  { register size_t nn = (size_t)(n); \
+    if (nn >= breakeven_point) memset((d), (int)(c), nn); \
+    else if (nn > 0) { /* proc call overhead is worth only for large strings*/\
+      register char *dd; register const int cc=(int)(c); \
+      for (dd=(d); nn>0; nn--) *dd++ = cc; } }
+
+/* prototypes */
+
+#if defined(NEED_ASPRINTF)
+int asprintf   (char **ptr, const char *fmt, /*args*/ ...);
+#endif
+#if defined(NEED_VASPRINTF)
+int vasprintf  (char **ptr, const char *fmt, va_list ap);
+#endif
+#if defined(NEED_ASNPRINTF)
+int asnprintf  (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
+#endif
+#if defined(NEED_VASNPRINTF)
+int vasnprintf (char **ptr, size_t str_m, const char *fmt, va_list ap);
+#endif
+
+#if defined(HAVE_SNPRINTF)
+/* declare our portable snprintf  routine under name portable_snprintf  */
+/* declare our portable vsnprintf routine under name portable_vsnprintf */
+#else
+/* declare our portable routines under names snprintf and vsnprintf */
+#define portable_snprintf snprintf
+#if !defined(NEED_SNPRINTF_ONLY)
+#define portable_vsnprintf vsnprintf
+#endif
+#endif
+
+#if !defined(HAVE_SNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
+int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
+#if !defined(NEED_SNPRINTF_ONLY)
+int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
+#endif
+#endif
+
+/* declarations */
+
+static char credits[] = "\n\
+@(#)snprintf.c, v2.2: Mark Martinec, <mark.martinec@ijs.si>\n\
+@(#)snprintf.c, v2.2: Copyright 1999, Mark Martinec. Frontier Artistic License applies.\n\
+@(#)snprintf.c, v2.2: http://www.ijs.si/software/snprintf/\n";
+
+#if defined(NEED_ASPRINTF)
+int asprintf(char **ptr, const char *fmt, /*args*/ ...) {
+  va_list ap;
+  size_t str_m;
+  int str_l;
+
+  *ptr = NULL;
+  va_start(ap, fmt);                            /* measure the required size */
+  str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap);
+  va_end(ap);
+  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
+  *ptr = (char *) malloc(str_m = (size_t)str_l + 1);
+  if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
+  else {
+    int str_l2;
+    va_start(ap, fmt);
+    str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
+    va_end(ap);
+    assert(str_l2 == str_l);
+  }
+  return str_l;
+}
+#endif
+
+#if defined(NEED_VASPRINTF)
+int vasprintf(char **ptr, const char *fmt, va_list ap) {
+  size_t str_m;
+  int str_l;
+
+  *ptr = NULL;
+  { va_list ap2;
+    va_copy(ap2, ap);  /* don't consume the original ap, we'll need it again */
+    str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap2);/*get required size*/
+    va_end(ap2);
+  }
+  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
+  *ptr = (char *) malloc(str_m = (size_t)str_l + 1);
+  if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
+  else {
+    int str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
+    assert(str_l2 == str_l);
+  }
+  return str_l;
+}
+#endif
+
+#if defined(NEED_ASNPRINTF)
+int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...) {
+  va_list ap;
+  int str_l;
+
+  *ptr = NULL;
+  va_start(ap, fmt);                            /* measure the required size */
+  str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap);
+  va_end(ap);
+  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
+  if ((size_t)str_l + 1 < str_m) str_m = (size_t)str_l + 1;      /* truncate */
+  /* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
+  if (str_m == 0) {  /* not interested in resulting string, just return size */
+  } else {
+    *ptr = (char *) malloc(str_m);
+    if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
+    else {
+      int str_l2;
+      va_start(ap, fmt);
+      str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
+      va_end(ap);
+      assert(str_l2 == str_l);
+    }
+  }
+  return str_l;
+}
+#endif
+
+#if defined(NEED_VASNPRINTF)
+int vasnprintf (char **ptr, size_t str_m, const char *fmt, va_list ap) {
+  int str_l;
+
+  *ptr = NULL;
+  { va_list ap2;
+    va_copy(ap2, ap);  /* don't consume the original ap, we'll need it again */
+    str_l = portable_vsnprintf(NULL, (size_t)0, fmt, ap2);/*get required size*/
+    va_end(ap2);
+  }
+  assert(str_l >= 0);        /* possible integer overflow if str_m > INT_MAX */
+  if ((size_t)str_l + 1 < str_m) str_m = (size_t)str_l + 1;      /* truncate */
+  /* if str_m is 0, no buffer is allocated, just set *ptr to NULL */
+  if (str_m == 0) {  /* not interested in resulting string, just return size */
+  } else {
+    *ptr = (char *) malloc(str_m);
+    if (*ptr == NULL) { errno = ENOMEM; str_l = -1; }
+    else {
+      int str_l2 = portable_vsnprintf(*ptr, str_m, fmt, ap);
+      assert(str_l2 == str_l);
+    }
+  }
+  return str_l;
+}
+#endif
+
+/*
+ * If the system does have snprintf and the portable routine is not
+ * specifically required, this module produces no code for snprintf/vsnprintf.
+ */
+#if !defined(HAVE_SNPRINTF) || defined(PREFER_PORTABLE_SNPRINTF)
+
+#if !defined(NEED_SNPRINTF_ONLY)
+int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...) {
+  va_list ap;
+  int str_l;
+
+  va_start(ap, fmt);
+  str_l = portable_vsnprintf(str, str_m, fmt, ap);
+  va_end(ap);
+  return str_l;
+}
+#endif
+
+#if defined(NEED_SNPRINTF_ONLY)
+int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...) {
+#else
+int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap) {
+#endif
+
+#if defined(NEED_SNPRINTF_ONLY)
+  va_list ap;
+#endif
+  size_t str_l = 0;
+  const char *p = fmt;
+
+/* In contrast with POSIX, the ISO C99 now says
+ * that str can be NULL and str_m can be 0.
+ * This is more useful than the old:  if (str_m < 1) return -1; */
+
+#if defined(NEED_SNPRINTF_ONLY)
+  va_start(ap, fmt);
+#endif
+  if (!p) p = "";
+  while (*p) {
+    if (*p != '%') {
+   /* if (str_l < str_m) str[str_l++] = *p++;    -- this would be sufficient */
+   /* but the following code achieves better performance for cases
+    * where format string is long and contains few conversions */
+      const char *q = strchr(p+1,'%');
+      size_t n = !q ? strlen(p) : (q-p);
+      if (str_l < str_m) {
+        size_t avail = str_m-str_l;
+        fast_memcpy(str+str_l, p, (n>avail?avail:n));
+      }
+      p += n; str_l += n;
+    } else {
+      const char *starting_p;
+      size_t min_field_width = 0, precision = 0;
+      int zero_padding = 0, precision_specified = 0, justify_left = 0;
+      int alternate_form = 0, force_sign = 0;
+      int space_for_positive = 1; /* If both the ' ' and '+' flags appear,
+                                     the ' ' flag should be ignored. */
+      char length_modifier = '\0';            /* allowed values: \0, h, l, L */
+      char tmp[32];/* temporary buffer for simple numeric->string conversion */
+
+      const char *str_arg;      /* string address in case of string argument */
+      size_t str_arg_l;         /* natural field width of arg without padding
+                                   and sign */
+      unsigned char uchar_arg;
+        /* unsigned char argument value - only defined for c conversion.
+           N.B. standard explicitly states the char argument for
+           the c conversion is unsigned */
+
+      size_t number_of_zeros_to_pad = 0;
+        /* number of zeros to be inserted for numeric conversions
+           as required by the precision or minimal field width */
+
+      size_t zero_padding_insertion_ind = 0;
+        /* index into tmp where zero padding is to be inserted */
+
+      char fmt_spec = '\0';
+        /* current conversion specifier character */
+
+      str_arg = credits;/* just to make compiler happy (defined but not used)*/
+      str_arg = NULL;
+      starting_p = p; p++;  /* skip '%' */
+   /* parse flags */
+      while (*p == '0' || *p == '-' || *p == '+' ||
+             *p == ' ' || *p == '#' || *p == '\'') {
+        switch (*p) {
+        case '0': zero_padding = 1; break;
+        case '-': justify_left = 1; break;
+        case '+': force_sign = 1; space_for_positive = 0; break;
+        case ' ': force_sign = 1;
+     /* If both the ' ' and '+' flags appear, the ' ' flag should be ignored */
+#ifdef PERL_COMPATIBLE
+     /* ... but in Perl the last of ' ' and '+' applies */
+                  space_for_positive = 1;
+#endif
+                  break;
+        case '#': alternate_form = 1; break;
+        case '\'': break;
+        }
+        p++;
+      }
+   /* If the '0' and '-' flags both appear, the '0' flag should be ignored. */
+
+   /* parse field width */
+      if (*p == '*') {
+        int j;
+        p++; j = va_arg(ap, int);
+        if (j >= 0) min_field_width = j;
+        else { min_field_width = -j; justify_left = 1; }
+      } else if (isdigit((int)(*p))) {
+        /* size_t could be wider than unsigned int;
+           make sure we treat argument like common implementations do */
+        unsigned int uj = *p++ - '0';
+        while (isdigit((int)(*p))) uj = 10*uj + (unsigned int)(*p++ - '0');
+        min_field_width = uj;
+      }
+   /* parse precision */
+      if (*p == '.') {
+        p++; precision_specified = 1;
+        if (*p == '*') {
+          int j = va_arg(ap, int);
+          p++;
+          if (j >= 0) precision = j;
+          else {
+            precision_specified = 0; precision = 0;
+         /* NOTE:
+          *   Solaris 2.6 man page claims that in this case the precision
+          *   should be set to 0.  Digital Unix 4.0, HPUX 10 and BSD man page
+          *   claim that this case should be treated as unspecified precision,
+          *   which is what we do here.
+          */
+          }
+        } else if (isdigit((int)(*p))) {
+          /* size_t could be wider than unsigned int;
+             make sure we treat argument like common implementations do */
+          unsigned int uj = *p++ - '0';
+          while (isdigit((int)(*p))) uj = 10*uj + (unsigned int)(*p++ - '0');
+          precision = uj;
+        }
+      }
+   /* parse 'h', 'l' and 'll' length modifiers */
+      if (*p == 'h' || *p == 'l') {
+        length_modifier = *p; p++;
+        if (length_modifier == 'l' && *p == 'l') {   /* double l = long long */
+#ifdef SNPRINTF_LONGLONG_SUPPORT
+          length_modifier = '2';                  /* double l encoded as '2' */
+#else
+          length_modifier = 'l';                 /* treat it as a single 'l' */
+#endif
+          p++;
+        }
+      }
+      fmt_spec = *p;
+   /* common synonyms: */
+      switch (fmt_spec) {
+      case 'i': fmt_spec = 'd'; break;
+      case 'D': fmt_spec = 'd'; length_modifier = 'l'; break;
+      case 'U': fmt_spec = 'u'; length_modifier = 'l'; break;
+      case 'O': fmt_spec = 'o'; length_modifier = 'l'; break;
+      default: break;
+      }
+   /* get parameter value, do initial processing */
+      switch (fmt_spec) {
+      case '%': /* % behaves similar to 's' regarding flags and field widths */
+      case 'c': /* c behaves similar to 's' regarding flags and field widths */
+      case 's':
+        length_modifier = '\0';          /* wint_t and wchar_t not supported */
+     /* the result of zero padding flag with non-numeric conversion specifier*/
+     /* is undefined. Solaris and HPUX 10 does zero padding in this case,    */
+     /* Digital Unix and Linux does not. */
+#if !defined(SOLARIS_COMPATIBLE) && !defined(HPUX_COMPATIBLE)
+        zero_padding = 0;    /* turn zero padding off for string conversions */
+#endif
+        str_arg_l = 1;
+        switch (fmt_spec) {
+        case '%':
+          str_arg = p; break;
+        case 'c': {
+          int j = va_arg(ap, int);
+          uchar_arg = (unsigned char) j;   /* standard demands unsigned char */
+          str_arg = (const char *) &uchar_arg;
+          break;
+        }
+        case 's':
+          str_arg = va_arg(ap, const char *);
+          if (!str_arg) str_arg_l = 0;
+       /* make sure not to address string beyond the specified precision !!! */
+          else if (!precision_specified) str_arg_l = strlen(str_arg);
+       /* truncate string if necessary as requested by precision */
+          else if (precision == 0) str_arg_l = 0;
+          else {
+       /* memchr on HP does not like n > 2^31  !!! */
+            const char *q = (const char *)memchr((void *)str_arg, '\0',
+                             precision <= 0x7fffffff ? precision : 0x7fffffff);
+            str_arg_l = !q ? precision : (q-str_arg);
+          }
+          break;
+        default: break;
+        }
+        break;
+      case 'd': case 'u': case 'o': case 'x': case 'X': case 'p': {
+        /* NOTE: the u, o, x, X and p conversion specifiers imply
+                 the value is unsigned;  d implies a signed value */
+
+        int arg_sign = 0;
+          /* 0 if numeric argument is zero (or if pointer is NULL for 'p'),
+            +1 if greater than zero (or nonzero for unsigned arguments),
+            -1 if negative (unsigned argument is never negative) */
+
+        int int_arg = 0;  unsigned int uint_arg = 0;
+          /* only defined for length modifier h, or for no length modifiers */
+
+        long int long_arg = 0;  unsigned long int ulong_arg = 0;
+          /* only defined for length modifier l */
+
+        void *ptr_arg = NULL;
+          /* pointer argument value -only defined for p conversion */
+
+#ifdef SNPRINTF_LONGLONG_SUPPORT
+        long long int long_long_arg = 0;
+        unsigned long long int ulong_long_arg = 0;
+          /* only defined for length modifier ll */
+#endif
+        if (fmt_spec == 'p') {
+        /* HPUX 10: An l, h, ll or L before any other conversion character
+         *   (other than d, i, u, o, x, or X) is ignored.
+         * Digital Unix:
+         *   not specified, but seems to behave as HPUX does.
+         * Solaris: If an h, l, or L appears before any other conversion
+         *   specifier (other than d, i, u, o, x, or X), the behavior
+         *   is undefined. (Actually %hp converts only 16-bits of address
+         *   and %llp treats address as 64-bit data which is incompatible
+         *   with (void *) argument on a 32-bit system).
+         */
+#ifdef SOLARIS_COMPATIBLE
+#  ifdef SOLARIS_BUG_COMPATIBLE
+          /* keep length modifiers even if it represents 'll' */
+#  else
+          if (length_modifier == '2') length_modifier = '\0';
+#  endif
+#else
+          length_modifier = '\0';
+#endif
+          ptr_arg = va_arg(ap, void *);
+          if (ptr_arg != NULL) arg_sign = 1;
+        } else if (fmt_spec == 'd') {  /* signed */
+          switch (length_modifier) {
+          case '\0':
+          case 'h':
+         /* It is non-portable to specify a second argument of char or short
+          * to va_arg, because arguments seen by the called function
+          * are not char or short.  C converts char and short arguments
+          * to int before passing them to a function.
+          */
+            int_arg = va_arg(ap, int);
+            if      (int_arg > 0) arg_sign =  1;
+            else if (int_arg < 0) arg_sign = -1;
+            break;
+          case 'l':
+            long_arg = va_arg(ap, long int);
+            if      (long_arg > 0) arg_sign =  1;
+            else if (long_arg < 0) arg_sign = -1;
+            break;
+#ifdef SNPRINTF_LONGLONG_SUPPORT
+          case '2':
+            long_long_arg = va_arg(ap, long long int);
+            if      (long_long_arg > 0) arg_sign =  1;
+            else if (long_long_arg < 0) arg_sign = -1;
+            break;
+#endif
+          }
+        } else {  /* unsigned */
+          switch (length_modifier) {
+          case '\0':
+          case 'h':
+            uint_arg = va_arg(ap, unsigned int);
+            if (uint_arg) arg_sign = 1;
+            break;
+          case 'l':
+            ulong_arg = va_arg(ap, unsigned long int);
+            if (ulong_arg) arg_sign = 1;
+            break;
+#ifdef SNPRINTF_LONGLONG_SUPPORT
+          case '2':
+            ulong_long_arg = va_arg(ap, unsigned long long int);
+            if (ulong_long_arg) arg_sign = 1;
+            break;
+#endif
+          }
+        }
+        str_arg = tmp; str_arg_l = 0;
+     /* NOTE:
+      *   For d, i, u, o, x, and X conversions, if precision is specified,
+      *   the '0' flag should be ignored. This is so with Solaris 2.6,
+      *   Digital UNIX 4.0, HPUX 10, Linux, FreeBSD, NetBSD; but not with Perl.
+      */
+#ifndef PERL_COMPATIBLE
+        if (precision_specified) zero_padding = 0;
+#endif
+        if (fmt_spec == 'd') {
+          if (force_sign && arg_sign >= 0)
+            tmp[str_arg_l++] = space_for_positive ? ' ' : '+';
+         /* leave negative numbers for sprintf to handle,
+            to avoid handling tricky cases like (short int)(-32768) */
+#ifdef LINUX_COMPATIBLE
+        } else if (fmt_spec == 'p' && force_sign && arg_sign > 0) {
+          tmp[str_arg_l++] = space_for_positive ? ' ' : '+';
+#endif
+        } else if (alternate_form) {
+          if (arg_sign != 0 && (fmt_spec == 'x' || fmt_spec == 'X') )
+            { tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = fmt_spec; }
+         /* alternate form should have no effect for p conversion, but ... */
+#ifdef HPUX_COMPATIBLE
+          else if (fmt_spec == 'p'
+         /* HPUX 10: for an alternate form of p conversion,
+          *          a nonzero result is prefixed by 0x. */
+#ifndef HPUX_BUG_COMPATIBLE
+         /* Actually it uses 0x prefix even for a zero value. */
+                   && arg_sign != 0
+#endif
+                  ) { tmp[str_arg_l++] = '0'; tmp[str_arg_l++] = 'x'; }
+#endif
+        }
+        zero_padding_insertion_ind = str_arg_l;
+        if (!precision_specified) precision = 1;   /* default precision is 1 */
+        if (precision == 0 && arg_sign == 0
+#if defined(HPUX_BUG_COMPATIBLE) || defined(LINUX_COMPATIBLE)
+            && fmt_spec != 'p'
+         /* HPUX 10 man page claims: With conversion character p the result of
+          * converting a zero value with a precision of zero is a null string.
+          * Actually HP returns all zeroes, and Linux returns "(nil)". */
+#endif
+        ) {
+         /* converted to null string */
+         /* When zero value is formatted with an explicit precision 0,
+            the resulting formatted string is empty (d, i, u, o, x, X, p).   */
+        } else {
+          char f[5]; int f_l = 0;
+          f[f_l++] = '%';    /* construct a simple format string for sprintf */
+          if (!length_modifier) { }
+          else if (length_modifier=='2') { f[f_l++] = 'l'; f[f_l++] = 'l'; }
+          else f[f_l++] = length_modifier;
+          f[f_l++] = fmt_spec; f[f_l++] = '\0';
+          if (fmt_spec == 'p') str_arg_l += sprintf(tmp+str_arg_l, f, ptr_arg);
+          else if (fmt_spec == 'd') {  /* signed */
+            switch (length_modifier) {
+            case '\0':
+            case 'h': str_arg_l+=sprintf(tmp+str_arg_l, f, int_arg);  break;
+            case 'l': str_arg_l+=sprintf(tmp+str_arg_l, f, long_arg); break;
+#ifdef SNPRINTF_LONGLONG_SUPPORT
+            case '2': str_arg_l+=sprintf(tmp+str_arg_l,f,long_long_arg); break;
+#endif
+            }
+          } else {  /* unsigned */
+            switch (length_modifier) {
+            case '\0':
+            case 'h': str_arg_l+=sprintf(tmp+str_arg_l, f, uint_arg);  break;
+            case 'l': str_arg_l+=sprintf(tmp+str_arg_l, f, ulong_arg); break;
+#ifdef SNPRINTF_LONGLONG_SUPPORT
+            case '2': str_arg_l+=sprintf(tmp+str_arg_l,f,ulong_long_arg);break;
+#endif
+            }
+          }
+         /* include the optional minus sign and possible "0x"
+            in the region before the zero padding insertion point */
+          if (zero_padding_insertion_ind < str_arg_l &&
+              tmp[zero_padding_insertion_ind] == '-') {
+            zero_padding_insertion_ind++;
+          }
+          if (zero_padding_insertion_ind+1 < str_arg_l &&
+              tmp[zero_padding_insertion_ind]   == '0' &&
+             (tmp[zero_padding_insertion_ind+1] == 'x' ||
+              tmp[zero_padding_insertion_ind+1] == 'X') ) {
+            zero_padding_insertion_ind += 2;
+          }
+        }
+        { size_t num_of_digits = str_arg_l - zero_padding_insertion_ind;
+          if (alternate_form && fmt_spec == 'o'
+#ifdef HPUX_COMPATIBLE                                  /* ("%#.o",0) -> ""  */
+              && (str_arg_l > 0)
+#endif
+#ifdef DIGITAL_UNIX_BUG_COMPATIBLE                      /* ("%#o",0) -> "00" */
+#else
+              /* unless zero is already the first character */
+              && !(zero_padding_insertion_ind < str_arg_l
+                   && tmp[zero_padding_insertion_ind] == '0')
+#endif
+          ) {        /* assure leading zero for alternate-form octal numbers */
+            if (!precision_specified || precision < num_of_digits+1) {
+             /* precision is increased to force the first character to be zero,
+                except if a zero value is formatted with an explicit precision
+                of zero */
+              precision = num_of_digits+1; precision_specified = 1;
+            }
+          }
+       /* zero padding to specified precision? */
+          if (num_of_digits < precision) 
+            number_of_zeros_to_pad = precision - num_of_digits;
+        }
+     /* zero padding to specified minimal field width? */
+        if (!justify_left && zero_padding) {
+          int n = min_field_width - (str_arg_l+number_of_zeros_to_pad);
+          if (n > 0) number_of_zeros_to_pad += n;
+        }
+        break;
+      }
+      default: /* unrecognized conversion specifier, keep format string as-is*/
+        zero_padding = 0;  /* turn zero padding off for non-numeric convers. */
+#ifndef DIGITAL_UNIX_COMPATIBLE
+        justify_left = 1; min_field_width = 0;                /* reset flags */
+#endif
+#if defined(PERL_COMPATIBLE) || defined(LINUX_COMPATIBLE)
+     /* keep the entire format string unchanged */
+        str_arg = starting_p; str_arg_l = p - starting_p;
+     /* well, not exactly so for Linux, which does something inbetween,
+      * and I don't feel an urge to imitate it: "%+++++hy" -> "%+y"  */
+#else
+     /* discard the unrecognized conversion, just keep *
+      * the unrecognized conversion character          */
+        str_arg = p; str_arg_l = 0;
+#endif
+        if (*p) str_arg_l++;  /* include invalid conversion specifier unchanged
+                                 if not at end-of-string */
+        break;
+      }
+      if (*p) p++;      /* step over the just processed conversion specifier */
+   /* insert padding to the left as requested by min_field_width;
+      this does not include the zero padding in case of numerical conversions*/
+      if (!justify_left) {                /* left padding with blank or zero */
+        int n = min_field_width - (str_arg_l+number_of_zeros_to_pad);
+        if (n > 0) {
+          if (str_l < str_m) {
+            size_t avail = str_m-str_l;
+            fast_memset(str+str_l, (zero_padding?'0':' '), (n>avail?avail:n));
+          }
+          str_l += n;
+        }
+      }
+   /* zero padding as requested by the precision or by the minimal field width
+    * for numeric conversions required? */
+      if (number_of_zeros_to_pad <= 0) {
+     /* will not copy first part of numeric right now, *
+      * force it to be copied later in its entirety    */
+        zero_padding_insertion_ind = 0;
+      } else {
+     /* insert first part of numerics (sign or '0x') before zero padding */
+        int n = zero_padding_insertion_ind;
+        if (n > 0) {
+          if (str_l < str_m) {
+            size_t avail = str_m-str_l;
+            fast_memcpy(str+str_l, str_arg, (n>avail?avail:n));
+          }
+          str_l += n;
+        }
+     /* insert zero padding as requested by the precision or min field width */
+        n = number_of_zeros_to_pad;
+        if (n > 0) {
+          if (str_l < str_m) {
+            size_t avail = str_m-str_l;
+            fast_memset(str+str_l, '0', (n>avail?avail:n));
+          }
+          str_l += n;
+        }
+      }
+   /* insert formatted string
+    * (or as-is conversion specifier for unknown conversions) */
+      { int n = str_arg_l - zero_padding_insertion_ind;
+        if (n > 0) {
+          if (str_l < str_m) {
+            size_t avail = str_m-str_l;
+            fast_memcpy(str+str_l, str_arg+zero_padding_insertion_ind,
+                        (n>avail?avail:n));
+          }
+          str_l += n;
+        }
+      }
+   /* insert right padding */
+      if (justify_left) {          /* right blank padding to the field width */
+        int n = min_field_width - (str_arg_l+number_of_zeros_to_pad);
+        if (n > 0) {
+          if (str_l < str_m) {
+            size_t avail = str_m-str_l;
+            fast_memset(str+str_l, ' ', (n>avail?avail:n));
+          }
+          str_l += n;
+        }
+      }
+    }
+  }
+#if defined(NEED_SNPRINTF_ONLY)
+  va_end(ap);
+#endif
+  if (str_m > 0) { /* make sure the string is null-terminated
+                      even at the expense of overwriting the last character
+                      (shouldn't happen, but just in case) */
+    str[str_l <= str_m-1 ? str_l : str_m-1] = '\0';
+  }
+  /* Return the number of characters formatted (excluding trailing null
+   * character), that is, the number of characters that would have been
+   * written to the buffer if it were large enough.
+   *
+   * The value of str_l should be returned, but str_l is of unsigned type
+   * size_t, and snprintf is int, possibly leading to an undetected
+   * integer overflow, resulting in a negative return value, which is illegal.
+   * Both XSH5 and ISO C99 (at least the draft) are silent on this issue.
+   * Should errno be set to EOVERFLOW and EOF returned in this case???
+   */
+  return (int) str_l;
+}
+#endif
diff --git a/snprintf.h b/snprintf.h
new file mode 100644 (file)
index 0000000..935864d
--- /dev/null
@@ -0,0 +1,28 @@
+#pragma once
+
+#ifndef _PORTABLE_SNPRINTF_H_
+#define _PORTABLE_SNPRINTF_H_
+
+#define PORTABLE_SNPRINTF_VERSION_MAJOR 2
+#define PORTABLE_SNPRINTF_VERSION_MINOR 2
+
+#ifdef HAVE_SNPRINTF
+#include <stdio.h>
+#else
+ int snprintf(char *, size_t, const char *, /*args*/ ...);
+ int vsnprintf(char *, size_t, const char *, va_list);
+#endif
+
+#if defined(HAVE_SNPRINTF) && defined(PREFER_PORTABLE_SNPRINTF)
+ int portable_snprintf(char *str, size_t str_m, const char *fmt, /*args*/ ...);
+ int portable_vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
+#define snprintf  portable_snprintf
+#define vsnprintf portable_vsnprintf
+#endif
+
+ int asprintf  (char **ptr, const char *fmt, /*args*/ ...);
+ int vasprintf (char **ptr, const char *fmt, va_list ap);
+ int asnprintf (char **ptr, size_t str_m, const char *fmt, /*args*/ ...);
+ int vasnprintf(char **ptr, size_t str_m, const char *fmt, va_list ap);
+
+#endif
diff --git a/stdafx.cpp b/stdafx.cpp
new file mode 100644 (file)
index 0000000..a2e3c6e
--- /dev/null
@@ -0,0 +1,8 @@
+// stdafx.cpp : 標準インクルードのみを含むソース ファイルです。\r
+// STed2.pch は、プリコンパイル済みヘッダーになります。\r
+//  stdafx.obj にはプリコンパイル型情報が含まれます。\r
+\r
+#include "stdafx.h"\r
+\r
+// TODO: このファイルではなく、STDAFX.H で必要な\r
+// 追加ヘッダーを参照してください。\r
diff --git a/stdafx.h b/stdafx.h
new file mode 100644 (file)
index 0000000..41497fb
--- /dev/null
+++ b/stdafx.h
@@ -0,0 +1,261 @@
+// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または\r
+// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル\r
+// を記述します。\r
+//\r
+\r
+#pragma once\r
+\r
+\r
+#pragma once\r
+#include <SDKDDKVer.h>\r
+\r
+#ifndef UNICODE\r
+#define UNICODE\r
+#endif\r
+// STL\r
+\r
+#define DIRECTINPUT_VERSION 0x0800\r
+//#define BOOST_ALL_NO_LIB\r
+\r
+#include <stdint.h>\r
+#include <tchar.h>\r
+#include <iostream>\r
+#include <fstream>\r
+#include <exception>\r
+#include <memory>\r
+#include <string>\r
+#include <map>\r
+#include <locale>\r
+#include <fstream>\r
+#include <algorithm>\r
+#include <functional>\r
+#include <thread>\r
+\r
+// Boost\r
+#include <boost/archive/xml_woarchive.hpp>\r
+#include <boost/archive/xml_wiarchive.hpp>\r
+//#include <boost/archive/text_woarchive.hpp>\r
+//#include <boost/archive/text_wiarchive.hpp>\r
+//#include <boost/archive/text_oarchive.hpp>\r
+//#include <boost/archive/text_iarchive.hpp>\r
+//#include <boost/archive/binary_woarchive.hpp>\r
+//#include <boost/archive/binary_wiarchive.hpp>\r
+//#include <boost/archive/binary_oarchive.hpp>\r
+//#include <boost/archive/binary_iarchive.hpp>\r
+\r
+#include <boost/serialization/export.hpp>\r
+//#include <boost/serialization/is_abstract.hpp>\r
+#include <boost/serialization/version.hpp>\r
+#include <boost/serialization/serialization.hpp>\r
+#include <boost/serialization/split_member.hpp>\r
+#include <boost/serialization/string.hpp>\r
+#include <boost/serialization/shared_ptr.hpp>\r
+#include <boost/serialization/vector.hpp>\r
+#include <boost/serialization/nvp.hpp>\r
+#include <boost/serialization/void_cast.hpp>\r
+\r
+#include <boost/scoped_ptr.hpp> \r
+#include <boost/scoped_array.hpp> \r
+#include <boost/shared_ptr.hpp> \r
+#include <boost/shared_array.hpp> \r
+#include <boost/intrusive_ptr.hpp>\r
+#include <boost/format.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+#include <boost/array.hpp>\r
+//#include <boost/thread.hpp>\r
+#include <boost/optional.hpp>\r
+#include <boost/bind.hpp>\r
+#include <boost/function.hpp>\r
+#include <boost/variant.hpp>\r
+#include <boost/any.hpp>\r
+#include <boost/signals2.hpp>\r
+#include <boost/tuple/tuple.hpp>\r
+#include <boost/ptr_container/ptr_container.hpp>\r
+//#include <boost/thread/condition.hpp>\r
+//#include <boost/serialization/ptr_vector.hpp>\r
+#include <boost/ptr_container/ptr_array.hpp>\r
+#include <boost/ptr_container/serialize_ptr_container.hpp>\r
+//#include "serialization.h"\r
+#include <boost/filesystem/path.hpp>\r
+#include <boost/filesystem/operations.hpp>\r
+#include <boost/filesystem/convenience.hpp>\r
+#include <boost/filesystem/fstream.hpp>\r
+#include "sf_com.h"\r
+//#include <d3d10_1.h>\r
+//#include <d3d10.h>\r
+//#include <d3d11.h>\r
+//#include <d3dx10.h>\r
+//#include <d3dx11.h>\r
+#include "dinput.h"\r
+#include <wincodec.h>\r
+#include <windows.h>\r
+#include <windowsx.h>\r
+#include <wincodec.h>\r
+#include <wincodecsdk.h>\r
+\r
+#include <comdef.h>\r
+#include "avrt.h"\r
+#include "mmsystem.h"\r
+\r
+// Direct Input\r
+\r
+#include "dinput.h"\r
+\r
+\r
+// DXGI\r
+\r
+#include "dxgi.h"\r
+\r
+#include "d3d11_1.h"\r
+#include <d3d11shader.h>\r
+#include <DDSTextureLoader.h>\r
+//#include "d3dx11.h"\r
+//#include <d3dx11effect.h>\r
+//#include <d3dxGlobal.h>\r
+#include <d3dcompiler.h>\r
+#include "DirectXMath.h"\r
+//#include <xnamath.h>\r
+\r
+// Direct2D\r
+\r
+#include <d2d1_1.h>\r
+#include <d2d1helper.h>\r
+\r
+// Direct Write\r
+\r
+#include <dwrite.h>\r
+\r
+// DWM\r
+\r
+#include "dwmapi.h" \r
+#include "Shobjidl.h"\r
+\r
+#include <wincodec.h>\r
+#include <wincodecsdk.h>\r
+\r
+#include "exception.h"\r
+//#include "singleton.h"\r
+//#include "code_converter.h"\r
+//#include "logger.h"\r
+\r
+\r
+// TODO: プログラムに必要な追加ヘッダーをここで参照してください。\r
+//#include "code_converter.h"\r
+//#include "logger.h"\r
+//#include "dout.h"\r
+//#include "dxerr.h"\r
+#include <wrl.h>\r
+#using <windows.winmd>\r
+#using <platform.winmd>\r
+#include <concrt.h>\r
+#include <ppl.h>\r
+#include <ppltasks.h>\r
+#include <agents.h>\r
+\r
+#define _WRL_PTR_TYPEDEF(x) typedef Microsoft::WRL::ComPtr<x> x ## Ptr\r
+\r
+\r
+//_WRL_PTR_TYPEDEF();\r
+//_WRL_PTR_TYPEDEF();\r
+\r
+/*\r
+#ifndef UNICODE\r
+#define UNICODE\r
+#endif\r
+// STL\r
+#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers\r
+//\r
+// Modify the following defines if you have to target a platform prior to the ones specified below.\r
+// Refer to MSDN for the latest info on corresponding values for different platforms.\r
+#ifndef WINVER              // Allow use of features specific to Windows 7 or later.\r
+#define WINVER 0x0800       // Change this to the appropriate value to target other versions of Windows.\r
+#endif\r
+\r
+#define DIRECTINPUT_VERSION 0x0800\r
+#include <tchar.h>\r
+#include <iostream>\r
+#include <fstream>\r
+#include <exception>\r
+#include <memory>\r
+#include <string>\r
+#include <map>\r
+#include <locale>\r
+#include <fstream>\r
+#include <algorithm>\r
+#include <functional>\r
+\r
+#include "sf_com.h"\r
+#include "dinput.h"\r
+#include <wincodec.h>\r
+#include <windows.h>\r
+#include <windowsx.h>\r
+#include <wincodec.h>\r
+#include <wincodecsdk.h>\r
+\r
+#include <comdef.h>\r
+#include "avrt.h"\r
+#include "mmsystem.h"\r
+#include <d2d1.h>\r
+#include <d2d1helper.h>\r
+#include <dwrite.h>\r
+#include "dwmapi.h" \r
+//#include <wincodec.h>\r
+//#include <wincodecsdk.h>\r
+//#include <d3dx11effect.h>\r
+//#include <d3dxGlobal.h>\r
+//#include "exception.h"\r
+//#include "singleton.h"\r
+//#include "code_converter.h"\r
+//#include "logger.h"\r
+\r
+\r
+// Boost\r
+//#include <boost/archive/xml_woarchive.hpp>\r
+//#include <boost/archive/xml_wiarchive.hpp>\r
+//#include <boost/archive/text_woarchive.hpp>\r
+//#include <boost/archive/text_wiarchive.hpp>\r
+//#include <boost/archive/text_oarchive.hpp>\r
+//#include <boost/archive/text_iarchive.hpp>\r
+//#include <boost/archive/binary_woarchive.hpp>\r
+//#include <boost/archive/binary_wiarchive.hpp>\r
+//#include <boost/archive/binary_oarchive.hpp>\r
+//#include <boost/archive/binary_iarchive.hpp>\r
+\r
+//#include <boost/serialization/export.hpp>\r
+//#include <boost/serialization/is_abstract.hpp>\r
+//#include <boost/serialization/version.hpp>\r
+//#include <boost/serialization/serialization.hpp>\r
+//#include <boost/serialization/split_member.hpp>\r
+//#include <boost/serialization/string.hpp>\r
+//#include <boost/serialization/shared_ptr.hpp>\r
+//#include <boost/serialization/vector.hpp>\r
+//#include <boost/serialization/nvp.hpp>\r
+//#include <boost/serialization/void_cast.hpp>\r
+#include <boost/scoped_ptr.hpp> \r
+#include <boost/scoped_array.hpp> \r
+#include <boost/shared_ptr.hpp> \r
+#include <boost/shared_array.hpp> \r
+#include <boost/intrusive_ptr.hpp>\r
+#include <boost/format.hpp>\r
+#include <boost/lexical_cast.hpp>\r
+#include <boost/array.hpp>\r
+#include <boost/thread.hpp>\r
+#include <boost/optional.hpp>\r
+#include <boost/bind.hpp>\r
+#include <boost/function.hpp>\r
+#include <boost/variant.hpp>\r
+#include <boost/any.hpp>\r
+#include <boost/signals2.hpp>\r
+#include <boost/tuple/tuple.hpp>\r
+#include <boost/ptr_container/ptr_container.hpp>\r
+#include <boost/thread/condition.hpp>\r
+//#include <boost/serialization/ptr_vector.hpp>\r
+#include <boost/ptr_container/ptr_array.hpp>\r
+#include <boost/ptr_container/serialize_ptr_container.hpp>\r
+//#include "serialization.h"\r
+#include <boost/filesystem/path.hpp>\r
+#include <boost/filesystem/operations.hpp>\r
+#include <boost/filesystem/convenience.hpp>\r
+\r
+// TODO: プログラムに必要な追加ヘッダーをここで参照してください。\r
+*/
\ No newline at end of file
diff --git a/sted.cpp b/sted.cpp
new file mode 100644 (file)
index 0000000..d9169f3
--- /dev/null
+++ b/sted.cpp
@@ -0,0 +1,1676 @@
+/*\r
+ * MIDI Music Composer STed v2.07 (c)1996/11/17 by TURBO\r
+ *      MIDI Sequencer\r
+ *\r
+ * v2.06f 95/04/18 YUI-NETのSYSOP(ゆい工房)さんにソース公開\r
+ */\r
+#include       "sted.h"\r
+\r
+ struct RCD_HEAD       *rcd;\r
+ char rcd_version[5];\r
+\r
+/* etc */\r
+ char  hlp_path[128];                  /* help file path & name        */\r
+ char  fon_path[128];                  /* font file path & name        */\r
+\r
+ char  def_path[128];                  /* .def path name               */\r
+ char  rcp_path[128];                  /* .rcp path name               */\r
+ char  prt_path[128];                  /* .prt path name               */\r
+ char  trk_path[128];                  /* .trk path name               */\r
+\r
+ char  def_file[128];                  /* .def file name               */\r
+ char  rcp_file[128];                  /* .rcp file name               */\r
+ char  prt_file[128];                  /* .prt file name               */\r
+ char  trk_file[128];                  /* .trk file name               */\r
+\r
+ char  repl[128];                      /* replace string               */\r
+ char  delt[128];                      /* delete string                */\r
+ char  srch[128];                      /* find string                  */\r
+\r
+ char  repl_t[26*6][40];\r
+ char  repl_d[26*6][50];\r
+\r
+ int   tr_step[36];                    /* track total step temp        */\r
+ int   tr_alc[36];                     /* track aloc size              */\r
+ int   tr_len[36];                     /* track used size              */\r
+ int   tr_pos[36][2][4];               /* track cursor position        */\r
+ int   tag[26+2][4];                   /* tag jamp list buffer         */\r
+\r
+ int   es,ecode,scyp;                  /* input subroutine exit code   */\r
+\r
+ int   btrack;                         /* track set top track          */\r
+ int   track,track1,track2;            /* edit track no.               */\r
+ int   edit_scr;                       /* 0=l_track 1=r_track 2=rhythm */\r
+ int   cmdflag,cnfflag,mdlflag;        /* STed2 system flag            */\r
+ int   poft;\r
+\r
+ int   TRACK_SIZE,work_size;           /* buffer size                  */\r
+ int   buff_size,buff_free,buff_max;\r
+ int   cpcy,cpadd,cplen;\r
+ int   cpleng,rcpf,rcplen;             /* copy flag                    */\r
+\r
+ void  *ErrorTrap_Old;                 /* err trap vecter/flag         */\r
+ int   ErrFlag;\r
+\r
+/* cnf */\r
+ char  comment[64];                    /* comment                      */\r
+\r
+ int   tm_lag;                         /* graphic rewrite time lag     */\r
+ char  inpmode;                        /* editor input mode            */\r
+ char  grpmode;                        /* editor graphic mode          */\r
+ char  thrumode;                       /* edit midi in thru mode       */\r
+ int   rec_getch,rec_putmd;            /* recoding ch./put mode        */\r
+ int   vis_reso;                       /**/\r
+\r
+ unsigned char rfilt[32][4];           /* record filter */\r
+ unsigned char pfilt[32][4];           /* play   filter */\r
+\r
+ char  mplay[16][16];\r
+ int   palet_dat[16];\r
+\r
+ unsigned char keyst_table[2][128];    /* key# -> st/gt convert table  */\r
+ unsigned char stgt_tbl[60];           /* f.key -> st/gt table         */\r
+\r
+ char  rhy_vel[16];\r
+\r
+ char  chcom_s[26*2][2][50];           /* child command comment        */\r
+ char  chcom_c[26*2][2][16];           /* child command parameter      */\r
+\r
+/* def */\r
+ char  module[64];                     /* module name                  */\r
+\r
+ int   lsp_wait;                       /* last para. transfer wait     */\r
+ int   bend_range;                     /* piche bend range             */\r
+\r
+ char  tim_asin[33];                   /* tone list channle assign     */\r
+ char  tim_head[400][24];              /* tone list title              */\r
+ char  tim_sym[400][8];                /* tone list symbol             */\r
+ char  tim_name[80*128][15];           /* tone name buffer             */\r
+ short tim_top[400];                   /* tone name buffer address     */\r
+\r
+ char  card_name[21][64];              /* pcm card name list           */\r
+ char  card_no[2];                     /* used pcm card no.            */\r
+\r
+ short gs_bank[18*128];                /* gs bank part no.(8+1 group)  */\r
+ short gs_mode[18];                    /* gs bank mode    (8+1 group)  */\r
+\r
+ char  rhy_stest[8];                   /* rhythm sound test ch. & para */\r
+ char  rec_met[10];                    /* recording metoro tone        */\r
+\r
+ unsigned char init_exc_data[258];     /* init exclusive data          */\r
+\r
+/*** rcp format head parameter ***/\r
+ char  mtitle[65];                     /* music title                  */\r
+ char  memo[12][29];                   /* memo                         */\r
+ int   tbase,mtempo;\r
+ int     beat1,beat2,bkey,pbias;               /* common parameter             */\r
+ char  cm6_file[128],gsd_file[128];    /* controol file name           */\r
+\r
+ char  rhyna[32][15];                  /* rhythm assign name           */\r
+ unsigned char rhyno[32][2];           /* rhythm assign key & gate     */\r
+\r
+ char  user_exc_memo[8][25];           /* user exclusive memo          */\r
+ unsigned char user_exc_data[8][24];   /* user exclusive data          */\r
+\r
+ unsigned char trno[36];               /* track no.                    */\r
+ unsigned char trmod[36];              /* track play mode              */\r
+ unsigned char trrhy[36];              /* track rhythm sw.             */\r
+ unsigned char mch[36];                /* track midi ch.               */\r
+ unsigned char trkey[36];              /* track key shift              */\r
+ unsigned char trst[36];               /* track st shift               */\r
+ char  trkmemo[36][37];                /* track comment                */\r
+\r
+/* buffer */\r
+ unsigned char lcbuf[1024*4+4];        /* delete line buffer           */\r
+ unsigned char rlcbuf[132];            /* delete rhythm line buffer    */\r
+ unsigned char cm6[22601],gsd[4096];   /* control file buffer          */\r
+ unsigned char hed[1414];              /* rcp header temporary         */\r
+\r
+ unsigned char *trk[36];               /* track buffer pointer         */\r
+ unsigned char *cpbuf;                 /* track copy buffer            */\r
+ unsigned char *rcpbuf;                /* rhythm track copy buffer     */\r
+ unsigned char *dat;                   /* temporary & recording buffer */\r
+ unsigned char *dat2;                  /* temporary                    */\r
+\r
+/* the following variables is only PC version available */\r
+\r
+ int issted3;                     /* Am I a new version ? */\r
+ int isconsole;                   /* is console mode? */\r
+ int isxwin;                      /* is X mode? */\r
+ char euc_text[1024];             /* code convert buffer */\r
+ char player_name[1024];          /* midi player name */\r
+ char midi_port_name[1024];       /* midi_port device name */\r
+ char font_name[1024];            /* X font set name */\r
+ int player_flag;                 /* is player able to play only SMF? */\r
+\r
+ char KEY_XF1[];                  /* keysym names */\r
+ char KEY_XF2[];\r
+ char KEY_XF3[];\r
+ char KEY_XF4[];\r
+ char KEY_XF5[];\r
+ char KEY_KANA[];\r
+ char KEY_KIGO[];\r
+ char KEY_TOROKU[];\r
+ char KEY_INS[];\r
+ char KEY_DEL[];\r
+ char KEY_HOME[];\r
+ char KEY_UNDO[];\r
+ char KEY_RUP[];\r
+ char KEY_RDOWN[];\r
+ char KEY_OPT1[];\r
+ char KEY_OPT2[];\r
+\r
+int eucenv;\r
+int str_vala;\r
+\r
+int iswindowopened;\r
+int iocs_graph_home; /* 0 or 1 */\r
+\r
+char fnc_func[10][32];\r
+char fnc_sfunc[10][32];\r
+char fnc_key[12][6];\r
+\r
+\r
+//! メニュー文字列\r
+static char    menu1[18][9] = {\r
+  "LOAD    ","SAVE    ","EDIT&SET","PLAY    ","RECORD  ","FILTER  ",\r
+  "TIME&KEY","TITLE   ","MEMO    ","PART ASS","RHY ASSI","USER EXC",\r
+  "CM64 CON","SC55 CON","OPTION  ","UNIT SEL","INIT    ","EXIT    "};\r
+/*\r
+static char    menu2[18][9]={\r
+       "BTM.LOAD","R36.SAVE","EDIT&SET","PANEL   ","MIDI MON","FILTER  ",\r
+       "TIME&KEY","TITLE   ","MEMO    ","PART ASS","RHY ASSI","USER EXC",\r
+       "CM64 CON","SC55 CON","OPTION  ","UNIT SEL","INIT    ","強制EXIT"};\r
+*/\r
+\r
+/*\r
+static char    beats[21][5]={\r
+       "1/2","2/2","2/3",\r
+       "1/4","2/4","3/4","4/4","5/4","6/4",\r
+       "1/8","2/8","3/8","4/8","5/8","6/8","7/8","8/8","9/8","10/8","11/8","12/8"};\r
+*/\r
+\r
+//! タイムベーステーブル\r
+static int     tbase_tbl[]={48,60,80,96,120,160,192,240,384,480};\r
+/*RCM V2.5G  : 48,60,80,96,120,160,240,480*/\r
+\r
+//! ファンクションキー定義\r
+static unsigned char   fnckey[12]={\r
+  0x12,0x17,0x01,0x07, 0x05,0x13,0x04,0x18,    0x0C,0x16,0x0B,0x15};\r
+/*     R.UP,R.DOWN,INS,DEL,    UP,LEFT,RIGHT,DOWN,     CLR,HELP,HOME,UNDO*/\r
+\r
+unsigned char  fnckey0[712],fnckey1[712];\r
+char   fonbuf[188*32];\r
+\r
+char   env_opt[32][128];\r
+char   rc_path[256];\r
+\r
+int    cmdflagold,used_u=0;\r
+\r
+static char version_id[1024];\r
+const char* get_version_id(void) {return (const char *)version_id;}\r
+\r
+#define        Trap14          (0x002e)        /*TRAP  #14で参照するベクタ*/\r
+\r
+/********** program start **********/\r
+int    main(int argc,char *argv[])\r
+{\r
+  int  i,\r
+         f = 0,\r
+         lzf = 0,\r
+         work_size2 = 0,\r
+         eoptc=0;\r
+  char  tmp0[1024],\r
+         tmp1[1024],\r
+         cmdline[2048],\r
+         cmd[1024];\r
+  char *p;\r
+  FILE *fp;\r
+\r
+  STed_system_initialize( &argc, &argv ); /* Aug.08.1998 Daisuke Nagano */\r
+\r
+#ifdef VERSION_ID\r
+  strcpy(version_id, "2.07m + ");\r
+  strcat(version_id, VERSION_ID);\r
+#else /* VERSION_ID */\r
+  strcpy(version_id, "2.07m");\r
+#endif /* VERSION_ID */\r
+\r
+  rcd_check();\r
+  H_INIT();\r
+  keyclr();\r
+\r
+  ErrorTrap_Old = NULL;\r
+  ErrFlag=0;\r
+\r
+  TRACK_SIZE = 64;\r
+  buff_max = 256 * 36 * 1024;\r
+  rcp_path[0] = 0;\r
+  prt_path[0] = 0;\r
+  trk_path[0] = 0;\r
+  rcp_file[0] = 0;\r
+  prt_file[0] = 0;\r
+  trk_file[0] = 0;\r
+  def_path[0] = 0;\r
+  def_file[0] = 0;\r
+  fon_path[0] = 0;\r
+  hlp_path[0] = 0;\r
+  rc_path[0] = 0;\r
+  card_no[0] = 0;\r
+\r
+  track=0;poft=0;rcpf=0;rcplen=0;cpadd=0;cplen=0;cpleng=0;\r
+  cmdflag=0;cnfflag=0;mdlflag=0;\r
+\r
+  lcbuf[0]=255;rlcbuf[0]=255;\r
+  btrack=0;rec_getch=0;rec_putmd=1;\r
+\r
+  cnfinit();\r
+\r
+  if ((p=getenv("RCP_DIR"))==(char*)0) p=getenv("rcp_dir");\r
+  if (p!=(char*)0){strcpy(rcp_path,p);}\r
+\r
+  if ((p=getenv("PRT_DIR"))==(char*)0) p=getenv("prt_dir");\r
+  if (p!=(char*)0){strcpy(prt_path,p);}\r
+\r
+  if ((p=getenv("RC_PATH"))==(char*)0) p=getenv("rc_path");\r
+  if (p!=(char*)0){strcpy(rc_path,p);}\r
+\r
+  if ((p=getenv("STED2"))==(char*)0) p=getenv("sted2");\r
+  if (p!=(char*)0){strcpy(cmdline,p);eoptc=option_read(cmdline);}\r
+\r
+  i=snprintf(tmp0,1024,"MIDI Music Composer STed %s Copyright 1990-97 TURBO\r\n",version_id);\r
+  if ( i > 0 ) {\r
+    B_PRINT( tmp0 );\r
+  }\r
+  /*B_PRINT("X68k MIDI Music Composer STed v2.07m Copyright 1990-97 TURBO\r\n");*/\r
+  /*B_PRINT("X68k MIDI Sequencer STed v2.07m Copyright 1990-97 TURBO\r\n");*/\r
+\r
+  if( argc>1 ){\r
+    for(i=1;i<argc;i++){if(eoptc<32){strcpy(env_opt[eoptc++],argv[i]);}}\r
+\r
+    for(i=0;i<eoptc;i++){\r
+      strcpy(cmd,env_opt[i]);\r
+\r
+      if( cmd[0]=='-' ){\r
+       switch(cmd[1]){\r
+\r
+       case 'M':\r
+       case 'm':TRACK_SIZE=str_val(&cmd[2]);break;\r
+\r
+       case 'U':\r
+       case 'u':buff_max=str_val(&cmd[2])*1024;\r
+         used_u=1;break;\r
+\r
+       case 'W':\r
+       case 'w':work_size2=str_val(&cmd[2])*1024;break;\r
+\r
+       case 'B':\r
+       case 'b':card_no[0]=str_val(&cmd[2]);break;\r
+\r
+       case 'D':\r
+       case 'd':\r
+         strcpy(rcp_path,&cmd[2]);\r
+         if(rcp_path[0]==0){\r
+           if(i+1<eoptc && env_opt[i+1][0]!='-'){\r
+             i++;strcpy(rcp_path,env_opt[i]);}\r
+         }\r
+         break;\r
+\r
+       case 'F':\r
+       case 'f':\r
+         strcpy(def_file,&cmd[2]);\r
+         if(def_file[0]==0){\r
+           if(i+1<eoptc && env_opt[i+1][0]!='-'){\r
+             i++;strcpy(def_file,env_opt[i]);}\r
+         }\r
+         break;\r
+\r
+       case 'P':\r
+       case 'p':cmdflag|=0x8000;break;\r
+\r
+       case 'R':\r
+       case 'r':cmdflag|=0x0080;break;\r
+\r
+       case 'L':\r
+       case 'l':cmdflag|=0x0008;break;\r
+\r
+       case 'S':\r
+       case 's':cmdflag|=0x0010;break;\r
+\r
+       case 'O':\r
+       case 'o':cmdflag|=0x0200;break;\r
+\r
+       default:f=1;break;\r
+       }\r
+      }else{\r
+       strcpy(rcp_file,cmd);\r
+      }\r
+    }\r
+  }\r
+\r
+  if( f!=0 ){\r
+    B_PRINT("usage: STed2 [option...] [file name] (.RCP/.R36/.MDF)\n");\r
+    B_PRINT("options\r\n");\r
+    B_PRINT( _("\t-M<size>\t Set the max size of track\n") );\r
+    B_PRINT( _("\t-U<size>\t Set the size of track buffer\n") );\r
+    B_PRINT( _("\t-W<size>\t Set the size of recording buffer\n") );\r
+    B_PRINT( _("\t-F<file>\t Specify Module configuration file\n") );\r
+    B_PRINT( _("\t-B<num>\t\t Specify the name of PCM card (CM64)\n") );\r
+    B_PRINT( _("\t-D<path>\t Specify the data directory\n") );\r
+    B_PRINT( _("\t-R\t\t Do pointplay with RCD function\n") );\r
+    B_PRINT( _("\t-P\t\t Set panel displaying as default playing command\n") );\r
+    B_PRINT( _("\t-L\t\t Read the data in RCD buffer at boot time\n") );\r
+    B_PRINT( _("\t-S\t\t Don't copy the data to RCD buffer when exit\n\n") );\r
+    exit(1);\r
+  }\r
+\r
+  if( (int)rcd==0 ) {\r
+    B_PRINT(_("RCD is not running.\n"));exit(1);\r
+  }else{\r
+    if( strcmp(rcd_version,"3.01")<0 || strcmp(rcd_version,"3.09")>0 ){\r
+      B_PRINT(_("Invalid RCD version.\n"));\r
+      exit(1);\r
+    }\r
+  }\r
+\r
+  if( card_no[0]<0 || card_no[0]>16 || TRACK_SIZE<32 || TRACK_SIZE>256 ||\r
+      buff_max<64*1024 || buff_max>256*36*1024 ){\r
+    B_PRINT(_("Invalid options.\n"));exit(1);\r
+  }\r
+\r
+  TRACK_SIZE=TRACK_SIZE*1024-48;buff_size=TRACK_SIZE*36;\r
+  if(buff_size>buff_max){buff_size=buff_max;}\r
+\r
+  work_size=TRACK_SIZE+32*1024;if(work_size<work_size2){work_size=work_size2;}\r
+\r
+  cpbuf=(unsigned char *)MALLOC(TRACK_SIZE);\r
+  rcpbuf=(unsigned char *)MALLOC(TRACK_SIZE);\r
+\r
+  dat=(unsigned char *)MALLOC(work_size);\r
+  dat2=(unsigned char *)MALLOC(work_size);\r
+  /* May.06.2001 NAGANO Daisuke <breeze.nagano@nifty.ne.jp> */\r
+#if 0\r
+  if((int)dat>=0x81000000){\r
+    B_PRINT(_("Cannot allocate track buffers.\n"));exit(1);}\r
+#endif\r
+\r
+realc:\r
+  trk[0]=(unsigned char *)MALLOC(buff_size);\r
+#if 0\r
+  if((int)trk[0]>=0x81000000) {\r
+    if(!used_u){\r
+      buff_size=((int)trk[0])&0xfffffc;if(buff_size>=64*1024){goto realc;}\r
+    }\r
+    B_PRINT(_("Cannot allocate track buffers.\n"));exit(1);\r
+  }\r
+#endif\r
+\r
+  buff_max=buff_size;\r
+\r
+  /*\r
+  if(TGUSEMD(0,-1)==1){\r
+    B_PRINT(_("G-RAM is active. Init. OK?(Y/N)"));\r
+    while(1){\r
+      i=inkey2();\r
+      if(i=='Y'||i=='y'){break;}\r
+      if(i=='N'||i=='n'){B_PRINT(_(": Terminated.\r\n"));exit(1);}\r
+    }\r
+  }\r
+  */\r
+\r
+  str_change(rcp_path);str_change(prt_path);str_change(trk_path);\r
+  str_change(rcp_file);str_change(def_file);str_change(rc_path);\r
+\r
+  if( rcp_file[0]!=0 ){\r
+    if(str_search(rcp_file,".MDF")>0 || str_search(rcp_file,".mdf")>0){\r
+      lzf=1;\r
+    }else{\r
+      if(str_search(rcp_file,".")==0){\r
+       /*\r
+         strmfe(rcp_file,rcp_file,'DEF");\r
+         if(!(fp= fopen2(rcp_file,"rb"))){\r
+         strmfe(rcp_file,rcp_file,'DFB");\r
+         if(!(fp= fopen2(rcp_file,"rb"))){\r
+         */\r
+       strmfe(rcp_file,rcp_file,"MDF");\r
+       if(!(fp= fopen2(rcp_file,"rb"))){\r
+         strmfe(rcp_file,rcp_file,"R36");\r
+         if(!(fp= fopen2(rcp_file,"rb"))){\r
+           strmfe(rcp_file,rcp_file,"RCP");\r
+         }else{\r
+           fclose(fp);\r
+         }\r
+       }else{\r
+         lzf=1;\r
+         fclose(fp);\r
+       }\r
+       /*\r
+         }else{\r
+         strcpy(def_file,rcp_file);\r
+         rcp_file[0]=0;\r
+         fclose(fp);\r
+         }\r
+         }else{\r
+         strcpy(def_file,rcp_file);\r
+         rcp_file[0]=0;\r
+         fclose(fp);\r
+         }\r
+         */\r
+      }\r
+    }\r
+\r
+    if(!(fp= fopen2(rcp_file,"rb"))){\r
+      B_PRINT(rcp_file);\r
+      B_PRINT(_(": File not found.\n"));exit(1);\r
+    }\r
+    fclose(fp);\r
+    path_cut(rcp_path,rcp_file);\r
+  }\r
+\r
+  /* load sted2 configuration file */\r
+  definit();\r
+\r
+  strmfe(tmp0,argv[0],"cnf");\r
+  /*\r
+  if(defload(tmp0,2)!=0){\r
+    B_PRINT(tmp0);B_PRINT(_(": File not found.\n"));exit(1);}*/\r
+  defload(tmp0, 2);\r
+\r
+  strmfe(tmp0,argv[0],"cf2");defload(tmp0,2);\r
+  /*           1997-07-20      STed2.cf2があればそれも読み込むようにした*/\r
+\r
+  p = getenv("HOME");\r
+  if (p && ( strlen(p) < sizeof(tmp0)-9 )) {\r
+    strcpy(tmp0, p);\r
+    strcat(tmp0, "/.sted2rc");\r
+    defload(tmp0, 2);  /* Mar.05.1999 */\r
+  }\r
+\r
+  if(tm_lag==0){tm_lag=8000;}\r
+  cmdflagold=cmdflag;\r
+\r
+  stgt_init();filt_init();\r
+\r
+  /* load module definition file */\r
+\r
+  if(def_file[0]==0){strcpy(def_file,argv[0]);strmfe(def_file,def_file,"def");}\r
+  str_change(def_file);\r
+\r
+  {\r
+    int lvl=0;\r
+    if(str_search(def_file,".")==0){lvl=2;}\r
+  loop:\r
+    if(lvl==2){strmfe(def_file,def_file,"dfb");}\r
+    if(lvl==1){strmfe(def_file,def_file,"def");}\r
+\r
+    i=defload(def_file,0);\r
+    if(i!=0){\r
+      strcpy(tmp0,def_path);\r
+      if(str_last((uint8*)tmp0)!='/'){strcat(tmp0,"/");}\r
+      strcat(tmp0,def_file);\r
+\r
+      i=defload(tmp0,0);\r
+      if(i!=0){\r
+       strcpy(tmp1,argv[0]);path_cut(tmp0,tmp1);\r
+       strcat(tmp0,def_file);\r
+\r
+       i=defload(tmp0,0);\r
+       if(i!=0){\r
+         if(lvl==2){lvl--;goto loop;}\r
+         /*\r
+         if(i==-1){B_PRINT(def_file);B_PRINT(_(": File not found.\n"));}*/\r
+         if (i==-1) goto not_found;\r
+         exit(1);}\r
+         }\r
+      strcpy(def_file,tmp0);\r
+    }else{\r
+      strcpy(tmp1,def_file);path_cut(tmp0,tmp1);\r
+      if(tmp0[0]==0){def_file[0]=0;path_set(def_file);strcat(def_file,tmp1);}\r
+    }\r
+  }\r
+not_found:\r
+\r
+  path_cut(def_path,def_file);\r
+\r
+  card_name_get();\r
+\r
+  fonread((uint8*)fonbuf);\r
+  if(fon_path[0]==0){\r
+    strmfe(fon_path,argv[0],"fon");\r
+  }else{\r
+    str_change(fon_path);\r
+    if(str_last((uint8*)fon_path)!='/'){strcat(fon_path,"/");}\r
+    strcpy(tmp0,argv[0]);strmfe(tmp0,tmp0,"fon");\r
+    path_cut(tmp1,tmp0);strcat(fon_path,tmp0);\r
+  }\r
+  fonload(fon_path);\r
+\r
+  if(hlp_path[0]==0){\r
+    strmfe(hlp_path,argv[0],"hlp");\r
+  }else{\r
+    str_change(hlp_path);\r
+    if(str_last((uint8*)hlp_path)!='/'){strcat(hlp_path,"/");}\r
+    strcpy(tmp0,argv[0]);strmfe(tmp0,tmp0,"hlp");\r
+    path_cut(tmp1,tmp0);strcat(hlp_path,tmp0);\r
+  }\r
+\r
+\r
+  for(i=0;i<12;i++){fnckey1[0x280+i*6]=fnckey[i];}\r
+  FNCKEYGT(0,(char*)fnckey0);FNCKEYST(0,(char*)fnckey1);\r
+\r
+  path_set(rcp_path);path_set(def_path);\r
+\r
+  if(trk_path[0]==0){\r
+    strcpy(trk_path,prt_path);\r
+    if(prt_path[0]==0){strcpy(trk_path,rcp_path);}}\r
+  if(prt_path[0]==0){strcpy(prt_path,rcp_path);}\r
+\r
+  if(str_last((uint8*)rcp_path)!='/'){strcat(rcp_path,"/");}\r
+  if(str_last((uint8*)prt_path)!='/'){strcat(prt_path,"/");}\r
+  if(str_last((uint8*)trk_path)!='/'){strcat(trk_path,"/");}\r
+  if(str_last((uint8*)def_path)!='/'){strcat(def_path,"/");}\r
+  if(rc_path[0]!=0 && str_last((uint8*)rc_path)!='/'){strcat(rc_path,"/");}\r
+\r
+  dinit();\r
+  if(lzf){\r
+    char       tmp[128];int    ec;\r
+\r
+    strcpy(tmp0,rcp_path);strcat(tmp0,rcp_file);\r
+    strcpy(tmp,"lzm -x ");strcat(tmp,tmp0);ec=exe(tmp);\r
+    if(ec<0){tmp[2]='z';ec=exe(tmp);}\r
+    if(ec!=0 && ec<32){FNCKEYST(0,(char*)fnckey0);fonset((uint8*)fonbuf);exit(1);}\r
+    cmdflag|=0x8;\r
+  }\r
+\r
+  set_errvect();\r
+  rcd_open_device();\r
+\r
+  C_CUROFF();LEDMOD(4,1);C_FNKMOD(3);sinit();/*MS_CUROF();*/\r
+\r
+  if((cmdflag&0x8)!=0){\r
+    if(bufload()!=0){bufset();}\r
+  }else{\r
+    bufset();\r
+    if( rcp_file[0]!=0 ){\r
+      strcpy(tmp0,rcp_path);strcat(tmp0,rcp_file);dload(tmp0,0);\r
+\r
+      if(cm6_file[0]!=0){\r
+       strcpy(tmp0,rcp_path);strcat(tmp0,cm6_file);\r
+       if(timload(tmp0)!=0){\r
+         msg(cm6_file);\r
+         B_PRINT(_(": File not found.\n"));cm6_file[0]=0;\r
+       }\r
+      }\r
+      if(gsd_file[0]!=0){\r
+       strcpy(tmp0,rcp_path);strcat(tmp0,gsd_file);\r
+       if(gsdload(tmp0)!=0){\r
+         msg(gsd_file);\r
+         B_PRINT(_(": File not found.\n"));gsd_file[0]=0;\r
+       }\r
+      }\r
+    }\r
+  }\r
+  form();timtra();/*key_vect_set();*/com_sel();/*key_vect_reset();*/\r
+\r
+  end_proc();exit(0);\r
+}\r
+\r
+/***************************/\r
+void   end_proc()\r
+{\r
+  /*  msg_clr();tpl(0);G_CLR_ON();CRTMOD(16);C_FNKMOD(0);C_CURON();LEDMOD(4,0);*/ /* Aug.09.1998 Daisuke Nagano */\r
+  msg_clr();tpl(0);G_CLR_ON();CRTMOD(17);C_FNKMOD(0);C_CURON();LEDMOD(4,0);\r
+  if(!(cmdflag&0x10)){bufset();}\r
+  FNCKEYST(0,(char*)fnckey0);fonset((uint8*)fonbuf);\r
+  close_midi_device(); /* Sep.02.1998 Daisuke Nagano */\r
+\r
+  rst_errvect();exit(0);\r
+}\r
+\r
+/***************************/\r
+void   set_errvect()\r
+{\r
+\r
+  return;\r
+#ifdef X680x0\r
+  if (NULL == (ErrorTrap_Old=(void *)B_INTVCS(Trap14,(int)*ErrorTrap)) ) {\r
+    B_PRINT("TRAP14が再設定できませんでした。中止します。\r\n");\r
+    exit(1);\r
+  }\r
+#endif /* X680x0 */\r
+}\r
+\r
+void   rst_errvect()\r
+{\r
+\r
+  return;\r
+#ifdef X680x0\r
+  if (ErrorTrap_Old != NULL) {\r
+    B_INTVCS(Trap14,(int)ErrorTrap_Old);\r
+  }\r
+#endif /* X680x0 */\r
+}\r
+\r
+/***************************/\r
+void   com_sel()\r
+{\r
+  int  ke,sh,cy=0,i;\r
+  char tmp0[128],tmp1[128],path2[128];\r
+\r
+  for(i=0;i<18;i++){sdis(1,112+i*21,menu1[i],8,15,8);}\r
+\r
+  C_WINDOW(0,31);\r
+\r
+  while( 1){\r
+    sdis(1,112+cy*21,menu1[cy],8,0,15);\r
+    ke=inkey3();sh=ke>>8;ke=ke&0xff;\r
+    if(ke>='a' && ke<='z'){ke-=32;}\r
+    sdis(1,112+cy*21,menu1[cy],8,15,8);\r
+\r
+    if( ke==0xe0 ){if((sh&1)==0){poplay(0,4);}else{poplay(0,5);}}\r
+    if( ke==0xe1 ){if((sh&1)==0){poplay(0,1);}else{poplay(0,2);}}\r
+\r
+    if( ke>='A' && ke<='Z' && (sh&4)!=0 ){option(ke-'A',0);ke=0;}\r
+    if(ke=='L'){cy=0;ke=13;}\r
+    if(ke=='S'){cy=1;ke=13;}\r
+    if(ke=='E'){cy=2;ke=13;}\r
+    if(ke=='P' || ke==0x10){cy=3;ke=13;}\r
+    if(ke=='R'){cy=4;ke=13;}\r
+    if(ke=='F'){cy=5;ke=13;}\r
+\r
+    if(ke=='K'){cy=6;ke=13;}\r
+    if(ke=='T'){cy=7;ke=13;}\r
+    if(ke=='M'){cy=8;ke=13;}\r
+    if(ke=='G'){cy=9;ke=13;}\r
+    if(ke=='A'){cy=10;ke=13;}\r
+    if(ke=='U'){cy=11;ke=13;}\r
+    if(ke=='C'){cy=12;ke=13;if(sh&1){cy=13;}}\r
+\r
+    if(ke=='O'){cy=14;ke=13;}\r
+    if(ke=='D'){cy=15;ke=13;}\r
+    if(ke=='I'){cy=16;ke=13;}\r
+    if(ke=='X'){cy=17;ke=13;}\r
+\r
+    if(ke=='Z'){timtra();}\r
+\r
+    if( ke==13 || ke==32 ){\r
+      /*if(sh&1){\r
+       sdis(1,112+cy*21,menu2[cy],8,0,11);\r
+       }else*/{\r
+         sdis(1,112+cy*21,menu1[cy],8,0,11);\r
+       }\r
+\r
+       if( cy==0 ){load_sub(sh);}\r
+       if( cy==1 ){save_sub(sh);}\r
+       if( cy==2 ){trk_set(0);}\r
+       if( cy==3 ){dplay(sh&3,0,0);}\r
+       if( cy==4 ){if((sh & 1)!=0){inpmon();}else{trk_set(1);}}\r
+       if( cy==5 ){rec_filter(0);}\r
+       if( cy==6 ){beat_set();}\r
+       if( cy==7 ){\r
+         if(sh&1){\r
+           msg(_("Input new title"));\r
+           if(yn_sel()>0){mtitle[0]=0;}\r
+         }\r
+         B_LOCATE(28,3);sinput(mtitle,64);rcp_dat2(0,0);}\r
+       /*B_LOCATE(28,3);sinput(eucconv(mtitle),65);rcp_dat2(0,0);} /* code converted! */\r
+\r
+\r
+       if( cy==8 ){memo_ed(sh);}\r
+       if( cy==9 ){part_as();}\r
+       if( cy==10 ){rhy_as();}\r
+       if( cy==11 ){user_exc_as(0);}\r
+       if( cy==12 ){cm64_con();}\r
+       if( cy==13 ){gsd_con();}\r
+       if( cy==14 ){option(-1,0);}\r
+\r
+       if( cy==15 ){\r
+         strcpy(tmp1,def_file);strcpy(path2,def_path);\r
+         fsel(tmp1,path2,0x004);\r
+         if( es==0 && tmp1[0]!=0){\r
+           int n;\r
+           strcpy(tmp0,path2);strcat(tmp0,tmp1);\r
+           card_no[0]=0;card_no[1]=0;definit();\r
+           cmdflag=cmdflagold;mdlflag=0;\r
+           n=defload(tmp0,1);\r
+           if(n==0){\r
+             card_name_get();\r
+\r
+             if(!(cnfflag&0x0008)){strcpy(def_path,path2);}\r
+             strcpy(def_file,tmp1);\r
+             if(cm6_file[0]==0){cminit();}\r
+             if(gsd_file[0]==0){gsinit();}\r
+             asin_init();if(rcp_file[0]==0){user_exc_init();}\r
+             msg_clr();sdis2(30+9,0,module,22,15,8);\r
+           }else{if(n==-1){msg(_(": File not found.\n"));}}\r
+         }\r
+       }\r
+\r
+       if( cy==16 ){\r
+         msg(_("Initialize all data"));\r
+         if(yn_sel()>0){dinit();rcp_file[0]=0;timtra();form2();}\r
+       }\r
+       if( cy==17 ){\r
+         if((sh & 1)!=0){end_proc();}\r
+         msg(_("Exit"));\r
+         if(yn_sel()>0){end_proc();}\r
+       }\r
+       C_WINDOW(0,31);B_LOCATE(0,2);C_CLS_ED();\r
+    }\r
+\r
+    if( ke==5 || ke==0x3c ){cy--;if(cy<0){cy=17;}}\r
+    if( ke==24 || ke==0x3e ){cy++;if(cy>17){cy=0;}}\r
+  }\r
+}\r
+\r
+/***************************/\r
+void   load_sub(int sh)\r
+{\r
+  char tmp0[128],tmp1[128],path2[128];\r
+\r
+  strcpy(tmp1,rcp_file);\r
+  strcpy(path2,rcp_path);fsel(tmp1,path2,0x001);\r
+  if( es==0 && tmp1[0]!=0){\r
+    strcpy(tmp0,path2);strcat(tmp0,tmp1);\r
+    msg(_("Loading ..."));\r
+    if(dload(tmp0,sh&1)==0 ){\r
+      cminit();gsinit();\r
+      strcpy(tmp0,path2);strcat(tmp0,cm6_file);\r
+      if(cm6_file[0]!=0){\r
+       if(timload(tmp0)!=0){\r
+         msg(cm6_file);B_PRINT(_(": File not found.\n"));\r
+         cm6_file[0]=0;\r
+       }\r
+      }\r
+      strcpy(tmp0,path2);strcat(tmp0,gsd_file);\r
+      if(gsd_file[0]!=0){\r
+       if(gsdload(tmp0)!=0){\r
+         msg(gsd_file);B_PRINT(_(": File not found.\n"));\r
+         gsd_file[0]=0;\r
+       }\r
+      }\r
+      if(!(cnfflag&0x0008)){strcpy(rcp_path,path2);}\r
+      strcpy(rcp_file,tmp1);\r
+      form2();timtra();msg_clr();\r
+    }\r
+  }\r
+}\r
+\r
+void   save_sub(int sh)\r
+{\r
+  char tmp0[128],tmp1[128],path2[128];\r
+\r
+  strcpy(tmp1,rcp_file);\r
+\r
+  if(tmp1[0]==0 || (sh&1)==0){\r
+    if(cnfflag&0x0040){sh=1-(sh&1);}\r
+  }else{\r
+    if(str_search(rcp_file,".R36")>0){\r
+      strmfe(tmp1,tmp1,"RCP");sh=0;\r
+    }else{\r
+      strmfe(tmp1,tmp1,"R36");sh=1;\r
+    }\r
+  }\r
+\r
+  strcpy(path2,rcp_path);fsel(tmp1,path2,0x100+(sh&1));\r
+  if( es==0 && tmp1[0]!=0 ){\r
+    strcpy(tmp0,path2);strcat(tmp0,tmp1);\r
+    msg(_("Saving ..."));\r
+    if(dsave(tmp0)==0){\r
+      if(!(cnfflag&0x0008)){strcpy(rcp_path,path2);}\r
+      strcpy(rcp_file,tmp1);\r
+      msg_clr();\r
+    }\r
+  }\r
+  sdis2(28,64,rcp_file,22,15,0);\r
+}\r
+\r
+/***************************/\r
+void   memo_ed(int sh)\r
+{\r
+  int  ke,i,y=0;\r
+  char tmp[128];\r
+\r
+  tmp[0]=0;\r
+\r
+  if(sh&1){\r
+  redraw:\r
+    msg(_("Initialize memo"));\r
+    if(yn_sel()>0){for(i=0;i<12;i++){memo[i][0]=0;}}\r
+  }\r
+  msg_clr();\r
+\r
+  fill(0,512+32,767,1023,0);\r
+  box(263,152+512,504,375+512,14,65535);\r
+  box(265,169+512,502,373+512,14,65535);\r
+  sdis(33,152+512," MEMO",30,15,14);\r
+  home2(512);\r
+top:\r
+  /*for(i=0;i<12;i++){tdis(34,11+i,memo[i],28,3);}*/\r
+  for(i=0;i<12;i++){tdis(34,11+i,eucconv(memo[i]),28,3);} /* code converted! */\r
+\r
+  while( 1){\r
+    /*tdis(34,11+y,memo[y],28,11);*/\r
+    tdis(34,11+y,eucconv(memo[y]),28,11); /* code converted! */\r
+    ke=inkey2();\r
+    /*tdis(34,11+y,memo[y],28,3);*/\r
+    tdis(34,11+y,eucconv(memo[y]),28,3); /* code converted! */\r
+\r
+    if( ke==0xc ){goto redraw;}\r
+    if( ke==27 ){C_CLS_AL();home2(0);break;}\r
+    if( ke==13 ){B_LOCATE(34,11+y);sinput(memo[y],28);}\r
+    /*if( ke==13 ){B_LOCATE(34,11+y);sinput(eucconv(memo[y]),28);} /* code converted! */\r
+    if( ke==0x05 ){y--;if( y<0 ){y=11;}}\r
+    if( ke==0x18 ){y++;if( y>11 ){y=0;}}\r
+\r
+    if( ke==7 ){\r
+      strcpy(tmp,memo[y]);\r
+      for(i=y;i<11;i++){\r
+       strcpy(memo[i],memo[i+1]);}\r
+      strcpy(memo[11],"");goto top;\r
+    }\r
+    if( ke==0x15 ){\r
+      for(i=11;i>y;i--){\r
+       strcpy(memo[i],memo[i-1]);}\r
+      strcpy(memo[y],tmp);goto top;\r
+    }\r
+  }\r
+}\r
+\r
+/***************************/\r
+int    option(int md,int sm)\r
+{\r
+  int  ke,i,y=0,ex=0,gy=scyp;\r
+  int  cmd=0;\r
+  char path2[128],tmp0[128],tmp1[128],tmp2[128];\r
+\r
+  B_CLR_AL();\r
+  fill(0,544,767,1001,0);box(0,556,320,1001,14,65535);fill(1,556+17,8,1000,8);\r
+  sdis(0,556," OPTION COMMAND",40,15,14);home2(512);\r
+\r
+  for(i=0;i<26;i++){\r
+    tmp0[0]=i+'A';tmp0[1]=32;tmp0[2]=0;strcat(tmp0,chcom_s[i][0]);\r
+    tdis(0,4+i,tmp0,39,3);}\r
+\r
+  if(md>=0){y=md;goto cexec;}\r
+\r
+  while( 1){\r
+  top:\r
+    md=-1;\r
+    tdis(2,4+y,chcom_s[y][0],37,11);\r
+    ke=inkey2();\r
+    tdis(2,4+y,chcom_s[y][0],37,3);\r
+\r
+    if( ke==27 ){break;}\r
+    if( ke==0x05 ){y--;if( y<0 ){y=25;}}\r
+    if( ke==0x18 ){y++;if( y>25 ){y=0;}}\r
+    if(ke>='a' && ke<='z'){y=ke-'a';ke=13;}\r
+    if(ke>='A' && ke<='Z'){y=ke-'A';ke=13;}\r
+\r
+    if( (ke==13 || ke==32)&& chcom_s[y][1][0]!=0 ){\r
+    cexec:\r
+      tdis(2,4+y,chcom_s[y][0],37,9);\r
+      strcpy(tmp0,chcom_s[y][1]);\r
+      strcpy(tmp2,chcom_c[y][0]);\r
+\r
+      cmd=progmode(tmp2);\r
+\r
+      if((cmd&512)!=0 && sm){\r
+       msg(_("This function is not available except for Main Menu."));\r
+       if(md<0){goto top;}\r
+       break;\r
+      }\r
+\r
+      if((cmd&32)!=0 && chcom_c[y][1][0]!=0){\r
+       tmp1[0]=0;\r
+       strcpy(path2,rcp_path);fsel(tmp1,path2,y+64);\r
+       if( es==0 && tmp1[0]!=0 ){\r
+         strcat(tmp0," ");\r
+         strcat(tmp0,path2);strcat(tmp0,tmp1);\r
+       }else{tmp0[0]=0;}\r
+      }\r
+      if((cmd&64)!=0){\r
+       if(rcp_file[0]!=0){\r
+         strcpy(tmp1,rcp_file);\r
+         if(chcom_c[y][1][0]!=0){\r
+           strmfe(tmp1,tmp1,chcom_c[y][1]);\r
+         }\r
+         strcat(tmp0," ");\r
+         strcat(tmp0,rcp_path);strcat(tmp0,tmp1);\r
+       }else{tmp0[0]=0;}\r
+      }\r
+\r
+      if(tmp0[0]!=0){ex=paraexe(tmp0,0,0,sm,cmd);break;}\r
+    }\r
+  }\r
+  B_CLR_AL();home2(gy);\r
+  return 1;\r
+}\r
+\r
+/***************************/\r
+int    option22(int md,int sm,int ad,int ew)\r
+{\r
+  int  ke,i,y=0,ex=0,gy=scyp,cx,gx;\r
+  int  cmd=0;\r
+  char path2[128],tmp0[128],tmp1[128],tmp2[128];\r
+\r
+  if(ew==0){cx=41+16-16;gx=327+128-128;}else{cx=1+16-2;gx=7+128-16;}\r
+\r
+  cons_md(0);\r
+redraw:\r
+  edit_scr=ew;noed_cls();edit_scr=0;\r
+\r
+  box(gx,556,gx+320,1001,14,65535);fill(gx+1,556+17,gx+8,1000,8);\r
+  sdis(cx,556," OPTION COMMAND",40,15,14);home2(512);\r
+\r
+  for(i=0;i<26;i++){\r
+    tmp0[0]=i+'A';tmp0[1]=32;tmp0[2]=0;strcat(tmp0,chcom_s[i+26][0]);\r
+    tdis(cx,4+i,tmp0,39,3);}\r
+\r
+  if(md>=0){y=md;goto cexec;}\r
+\r
+  while( 1){\r
+  top:\r
+    md=-1;\r
+    tdis(cx+2,4+y,chcom_s[y+26][0],37,11);\r
+    ke=inkey2();\r
+    tdis(cx+2,4+y,chcom_s[y+26][0],37,3);\r
+\r
+    if( ke==27 ){break;}\r
+    if( ke==0x05 ){y--;if( y<0 ){y=25;}}\r
+    if( ke==0x18 ){y++;if( y>25 ){y=0;}}\r
+    if(ke>='a' && ke<='z'){y=ke-'a';ke=13;}\r
+    if(ke>='A' && ke<='Z'){y=ke-'A';ke=13;}\r
+\r
+    /*         if( ke==0x17 || ke==0x13 ){pg-=26;if(pg<0){pg=26;}goto redraw;}\r
+               if( ke==0x12 || ke==0x04 ){pg+=26;if(pg>26){pg=0;}goto redraw;}\r
+               */\r
+    if( (ke==13 || ke==32)&& chcom_s[y+26][1][0]!=0 ){\r
+    cexec:\r
+      tdis(cx+2,4+y,chcom_s[y+26][0],37,9);\r
+      strcpy(tmp0,chcom_s[y+26][1]);\r
+      strcpy(tmp2,chcom_c[y+26][0]);\r
+\r
+      cmd=progmode(tmp2);\r
+\r
+      if((cmd&512)!=0 && sm){\r
+       msg(_("This function is not available except for Main Menu."));\r
+       if(md<0){goto top;}\r
+       break;\r
+      }\r
+\r
+      if((cmd&32)!=0 && chcom_c[y+26][1][0]!=0){\r
+       tmp1[0]=0;\r
+       strcpy(path2,rcp_path);\r
+\r
+       edit_scr=ew;noed_cls_t();noed_cls();edit_scr=0;\r
+\r
+       if(sm==2){fsel(tmp1,path2,y+64+(ew&1)*0x200+26);\r
+       }else{fsel(tmp1,path2,y+64);}\r
+       if( es==0 && tmp1[0]!=0 ){\r
+         strcat(tmp0," ");\r
+         strcat(tmp0,path2);strcat(tmp0,tmp1);\r
+       }else{tmp0[0]=0;}\r
+       if(es!=0){goto redraw;}\r
+\r
+      }\r
+      if((cmd&64)!=0){\r
+       if(rcp_file[0]!=0){\r
+         strcpy(tmp1,rcp_file);\r
+         if(chcom_c[y+26][1][0]!=0){\r
+           strmfe(tmp1,tmp1,chcom_c[y+26][1]);\r
+         }\r
+         strcat(tmp0," ");\r
+         strcat(tmp0,rcp_path);strcat(tmp0,tmp1);\r
+       }else{tmp0[0]=0;}\r
+      }\r
+\r
+      if(tmp0[0]!=0){\r
+       edit_scr=ew;noed_cls_t();noed_cls();edit_scr=0;\r
+       ex=paraexe(tmp0,ad,ew,sm,cmd);break;}\r
+      else{\r
+       goto redraw;}\r
+    }\r
+  }\r
+\r
+  if(ke==27){edit_scr=ew;noed_cls_t();noed_cls();edit_scr=0;}\r
+\r
+  cons_md(1);\r
+  home2(gy);\r
+  return ex;\r
+}\r
+\r
+/***************************/\r
+int    option2(int md,int sm,int ad,int ew)\r
+{\r
+  int  y,ex=0,gy;\r
+  int  cmd=0;\r
+  char path2[128],tmp0[128],tmp1[128],tmp2[128];\r
+  gy=scyp;y=md+26;\r
+\r
+  if( chcom_s[y][1][0]!=0 ){\r
+    strcpy(tmp0,chcom_s[y][1]);\r
+    strcpy(tmp2,chcom_c[y][0]);\r
+\r
+    cmd=progmode(tmp2);\r
+\r
+    if((cmd&512)!=0 && sm){\r
+      msg(_("This function is not available except for Main Menu."));\r
+      goto ext;\r
+    }\r
+\r
+    if((cmd&32)!=0 && chcom_c[y][1][0]!=0){\r
+      tmp1[0]=0;\r
+      strcpy(path2,rcp_path);\r
+\r
+      if(sm==2){fsel(tmp1,path2,y+64+(ew&1)*0x200);\r
+      }else{fsel(tmp1,path2,y+64);}\r
+\r
+      if( es==0 && tmp1[0]!=0 ){\r
+       strcat(tmp0," ");\r
+       strcat(tmp0,path2);strcat(tmp0,tmp1);\r
+      }else{tmp0[0]=0;}\r
+    }\r
+\r
+    if((cmd&64)!=0){\r
+      if(rcp_file[0]!=0){\r
+       strcpy(tmp1,rcp_file);\r
+       if(chcom_c[y][1][0]!=0){\r
+         strmfe(tmp1,tmp1,chcom_c[y][1]);\r
+       }\r
+       strcat(tmp0," ");\r
+       strcat(tmp0,rcp_path);strcat(tmp0,tmp1);\r
+      }else{tmp0[0]=0;}\r
+    }\r
+\r
+    if(tmp0[0]!=0){ex=paraexe(tmp0,ad,ew,sm,cmd);}\r
+  }\r
+ext:\r
+  home2(gy);\r
+  return(ex);\r
+}\r
+\r
+int    paraexe(char *tmp0,int ad,int ew,int sm,int cmd)\r
+{\r
+  int  a,i,ex,im;\r
+  char tmp1[256],tmp2[256];\r
+  int  dlen=0,dadd=0,dlen2=0;\r
+\r
+  if( (cplen<0 && cpadd!=ad) && sm==2){\r
+    dadd=cpadd;\r
+    dlen=abs(dadd-ad);if(dadd>ad ){dadd=ad;}\r
+    dlen2=dlen;\r
+  }else{dlen=tr_len[track];}\r
+\r
+  tmp1[0]=0;\r
+\r
+  i=0;\r
+  while((a=tmp0[i++])!=0){\r
+    if(a=='%'){\r
+      a=tmp0[i++];if(a==0){break;}\r
+      switch( a){\r
+      case  't':strcat(tmp1,nstr(track+1));break;\r
+      case  'm':strcat(tmp1,nstr(meas_no(ad)));break;\r
+\r
+      case  'o':strcat(tmp1,nstr(ad+44));break;\r
+\r
+      case  'u':strcat(tmp1,nstr(dadd+44));break;\r
+      case  'd':strcat(tmp1,nstr(dadd+dlen+40));break;\r
+      case  'l':strcat(tmp1,nstr(dlen2));break;\r
+\r
+      case  'w':strcat(tmp1,nstr(ew));break;\r
+      case  's':strcat(tmp1,nstr(sm));break;\r
+\r
+      default:tmp2[0]=a;tmp2[1]=0;strcat(tmp1,tmp2);break;\r
+      }\r
+    }else{\r
+      tmp2[0]=a;tmp2[1]=0;strcat(tmp1,tmp2);\r
+    }\r
+  }\r
+\r
+\r
+  if((cmd&1)!=0){\r
+    if((cmd&0x2000)==0){bufset();}else{bufset_trk(track);}\r
+  }\r
+  if((cmd&8)!=0){all_note_off(2);}\r
+\r
+  C_CURON();C_FNKMOD(0);FNCKEYST(0,(char*)fnckey0);\r
+  C_WINDOW(0,31);B_COLOR(3);B_LOCATE(0,0);\r
+\r
+  if((cmd&0x400)==0){B_CLR_AL();dpl(0);tpl(0);}\r
+  else{B_LOCATE(0,1);}\r
+\r
+  if((cmd&0x800)!=0 && sm==2){if(grpmode){grpmode=0;/*noed_cls();*/}}\r
+\r
+  im=(B_SFTSNS()&4096);\r
+  ex=exe(tmp1);\r
+  if(im){LEDMOD(4,1);}else{LEDMOD(4,0);}\r
+\r
+  if(ex==0 && sm==2){cplen=0;}\r
+\r
+  C_FNKMOD(3);fnc_dis(-1);FNCKEYST(0,(char*)fnckey1);\r
+  if((cmd&16)!=0){(*rcd->end)();}\r
+  if((cmd&128)!=0 || (ex!=0 && (cmd&0x400)==0)){key_pause();}\r
+  B_COLOR(3);C_CUROFF();\r
+\r
+  if((cmd&0x400)==0){B_CLR_AL();CRTMOD(16+256);OnGraphic();}\r
+  dpl(1);tpl(1);\r
+  if(sm<2){home2(0);}else{home2(512);}\r
+  WINDOW(0,0,1023,1023);\r
+\r
+  ex=0;if(point(0,0)!=8||(cmd&0x100)!=0){sinit();ex=1;}\r
+  if((cmd&(2+4))!=0){\r
+    poft=0;\r
+    if((cmd&0x2000)==0){bufload();form2();\r
+    }else{bufload_trk(track);trk_lin(track,-1,0);}\r
+    ex=1;\r
+    if((cmd&2)!=0){timtra();}\r
+  }else{\r
+    if(ex!=0){form();}\r
+  }\r
+\r
+  rcd->data_valid=0;\r
+  return ex;\r
+}\r
+\r
+/***************************/\r
+int    progmode(char *tmp2)\r
+{\r
+  int  a,i,cmd=0;\r
+\r
+  jstrupr(tmp2);\r
+\r
+  i=0;\r
+  while((a=tmp2[i++])!=0){\r
+    if(a=='B'){cmd|=0x0001;}   /*bufset*/\r
+    if(a=='L'){cmd|=0x0002;}   /*bufread*/\r
+    if(a=='N'){cmd|=0x0004;}   /*bufread non cm6/gsd*/\r
+    if(a=='O'){cmd|=0x0008;}   /* 実行前に演奏を停止する*/\r
+    if(a=='E'){cmd|=0x0010;}   /* 実行後に演奏を停止する*/\r
+    if(a=='S'){cmd|=0x0020;}   /*select*/\r
+    if(a=='F'){cmd|=0x0040;}   /*ext change*/\r
+    if(a=='P'){cmd|=0x0080;}   /*pause*/\r
+    if(a=='G'){cmd|=0x0100;}   /*rewrite*/\r
+    if(a=='M'){cmd|=0x0200;}   /*main only*/\r
+    if(a=='U'){cmd|=0x0400;}   /*not screen clr*/\r
+    if(a=='R'){cmd|=0x0800;}   /*not edit window clr*/\r
+\r
+    /*if(a=='C'){cmd|=0x1000;}*/       /*command.x*/\r
+    if(a=='T'){cmd|=0x2000;}   /*trk dataのみバッファアクセスする*/\r
+  }\r
+  return cmd;\r
+}\r
+\r
+/***************************/\r
+void   key_pause()\r
+{\r
+  B_COLOR(1);B_LOCATE(0,31);B_PRINT(_("Return to STed2 ! Press [RET]"));\r
+  while(inkey2()!=13){}\r
+  B_COLOR(1);B_LOCATE(0,31);B_PRINT("                                        ");\r
+}\r
+\r
+/***************************/\r
+int    yn_sel()\r
+{\r
+  int  ke,ec=0;\r
+  int y,n;\r
+\r
+  y=*_("Y");\r
+  n=*_("N");\r
+  B_PRINT(_("? (Y/N)"));\r
+  while(1){\r
+    ke=inkey2();\r
+    if(ke==y || ke==tolower(y)||ke==13){ec= 1;break;}\r
+    if(ke==n || ke==tolower(n)){ec=-1;break;}\r
+    if(ke==27){break;}\r
+  }\r
+  msg_clr();\r
+  return(ec);\r
+}\r
+\r
+/***************************/\r
+void   form()\r
+{\r
+  rcp_dat();trk_dat();\r
+}\r
+\r
+/***************************/\r
+void   form2()\r
+{\r
+  fill(102,43,767,485,0);form();\r
+}\r
+\r
+/***************************/\r
+void   form3()\r
+{\r
+  fill(103,188,743,484,0);trk_dat();\r
+}\r
+\r
+/***************************/\r
+void   sinit()\r
+{\r
+  int  i;\r
+\r
+  CRTMOD(16);G_CLR_ON();WINDOW(0,0,1023,1023);home2(0);C_WINDOW(0,32);\r
+  B_CLR_AL();dpl(1);tpl(1);logo(0);logo(512);sdis2(30+9,0,module,22,15,8);\r
+  box(0,43,96,99,14,65535);\r
+  for(i=0;i<18;i++){sdis(1,112+i*21,menu1[i],8,15,8);}\r
+}\r
+\r
+/***************************/\r
+void   logo(int y)\r
+{\r
+  if(y<0){\r
+    fill(496,512,767,512+31,0);\r
+    fill(496,512,767,512+15,8);box(496,512,767,512+15,14,65535);\r
+    y=510;\r
+  }else{\r
+    sdis2(0,y," FREE:",14,15,8);sdis2(15,y," USED:",14,15,8);\r
+    sdis2(30,y," TR.: 1",8,15,8);\r
+    fill(496,y,767,y+31,8);box(496,y,767,y+31,14,65535);\r
+    symbol(496+5,y+18,comment,1,1,0,15,0);\r
+    trksize(-2);\r
+  }\r
+  g_print(496+24,y+2,"STed v2.07  (c)1990-97 TURBO",15);\r
+/*\r
+  g_print(496+13,y+3,"・・・ ・・・m・1990-97・・・・",0);\r
+  g_print(496+12,y+2,"・・・ ・・・m・1990-97・・・・",15);\r
+*/\r
+  /*   g_print(496   ,y+2,"・・・・・・・・ ・1990-97・・・・",15);*/\r
+  /*   g_print(496+8 ,y+2,"・・・・・・・・ ・1990-97 TURBO",15);*/\r
+}\r
+/* JIS-[7621] SJIS-[EB9F]\r
+----------------------------------------------------------------\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+----------------------------------------------------------------\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+----------------------------------------------------------------\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+\r
+・・・・・・・・・・・・・・・・・・・・・・・・・・・・\r
+----------------------------------------------------------------\r
+*/\r
+\r
+/***************************/\r
+void   trk_dat()\r
+{\r
+  int  i;\r
+  static       short   xpos[7]={163,195,227,259,291,589,637};\r
+\r
+  fill(103,189,120,484,8);\r
+  for(i=0;i<7;i++){line(xpos[i],171,xpos[i],484,14,65535);}\r
+\r
+  for(i=btrack;i<btrack+18;i++){trk_lin(i,-1,2);}\r
+  trksize(-1);\r
+}\r
+\r
+/***************************/\r
+void   rcp_dat()\r
+{\r
+  box(102,43,744,99-16,14,65535);\r
+  sdis(14,48,"MUSIC TITLE  :",0,15,-1);sdis(14,64,"FILE NAME    :",0,15,-1);\r
+  sdis(14+37,80-16,"/",0,15,-1);sdis(14+37+19,80-16,"/",0,15,-1);\r
+\r
+  box(102,106-16,424,164,14,65535);box(432,106-16,744,164,14,65535);\r
+\r
+  sdis(14, 96,"TEMPO    :",0,15,-1);   sdis(34, 96,"TIMEBASE :",0,15,-1);\r
+  sdis(14,112,"PLAY BIAS:",0,15,-1);   /*midi thru*/\r
+  sdis(14,128,"KEY  :",0,15,-1);               /*sync mode*/\r
+  sdis(14,144,"BEAT  :    /",0,15,-1); sdis(34,144,"MIDI IN :",9,15,-1);\r
+\r
+  rcp_dat2(-1,0);\r
+\r
+  box(102,171,744,485,14,65535);\r
+  sdis(13,172,"TR MODE CH. ST+ K#+ RHY    TRACK MEMO                         STEP     TOTAL ST",80,15,14);\r
+}\r
+\r
+/***************************/\r
+void   rcp_dat2(int n,int m)\r
+{\r
+  int  i,c1,c2;\r
+\r
+  if(m==1){c1=0;c2=15;}else{c1=15;c2=0;}\r
+  if(m==2){c2=-1;}\r
+\r
+  /*if(n==0 || n<0){sdis2(28,48,mtitle,64,c1,c2);}*/\r
+  if(n==0 || n<0){sdis2(28,48,eucconv(mtitle),65,c1,c2);} /* code converted! */\r
+  if(n==1 || n<0){sdis2(28,64,rcp_file,22,c1,c2);}\r
+  if(n==2 || n<0){sdis2(28+25,64,cm6_file,12,c1,c2);sdis2(28+44,64,gsd_file,16,c1,c2);}\r
+  if(n==3 || n<0){vdis(25,96,mtempo,3,c1,c2);}\r
+  if(n==4 || n<0){i=pbias;if(i>127){i=i-256;}vdis(25,112,i,3,c1,c2);}\r
+  if(n==5 || n<0){sdis2(20,128,scale_str(bkey),13,c1,c2);}\r
+  if(n==6 || n<0){vdis(22,144,beat1,2,c1,c2);vdis(26,144,beat2,2,c1,c2);}\r
+  if(n==7 || n<0){vdis(45,96,tbase,3,c1,c2);}\r
+  if(n==8 || n<0){sdis2(44,144,mdinport(),8,c1,c2);}\r
+}\r
+\r
+/***************************/\r
+void   beat_set()\r
+{\r
+  int  ke,sh,ex,cx=0,i=0,mm=0;\r
+\r
+  while(1){\r
+\r
+    if(cx==0 && i==0){mm=3;}\r
+    if(         i==1){mm=4;}\r
+    if(         i==2){mm=5;}\r
+    if(         i==3){mm=6;}\r
+    if(cx==1 && i==0){mm=7;}\r
+\r
+    rcp_dat2(mm,1);\r
+    ke=inkey3();sh=ke>>8;ke=ke&0xff;\r
+    rcp_dat2(mm,0);\r
+\r
+    if( ke==27 ){break;}\r
+\r
+    if( ke==13 ){\r
+      if( mm==3 ){\r
+       B_LOCATE(25,6);ex=vinput(mtempo,0x803);\r
+       if(es==0 && ex>7 && ex<256 ){mtempo=ex;}\r
+      }\r
+      if( mm==4 ){\r
+       ex=pbias;if(ex>127){ex=ex-256;}\r
+       B_LOCATE(25,7);ex=vinput(ex,0x803);\r
+       if(ex>=-36 && ex<=36){\r
+         if(ex<0){ex=ex+256;}\r
+         if(es==0 && ex>=0 && ex<=255){pbias=ex;}\r
+       }\r
+      }\r
+      if( mm==5 ){\r
+       sdis2(20,128,"",13,0,7);\r
+       ex=scale_sel(20,8,bkey);\r
+       if(ex>=0){bkey=ex;}\r
+      }\r
+      if( mm==6 ){\r
+       B_LOCATE(22,9);ex=vinput(beat1,0x802);\r
+       if(es==0 && ex>0 && ex<=32){beat1=ex;}\r
+       B_LOCATE(26,9);ex=vinput(beat2,0x802);\r
+       if(es==0 && ex>1 && ex<=8){beat2=ex;}\r
+      }\r
+      if( mm==7 ){\r
+       B_LOCATE(45,6);ex=vinput(tbase,0x803);\r
+       if(es==0 && ex>=48 && ex<=480){tbase=ex;}\r
+      }\r
+      B_LOCATE(0,2);C_CLS_ED();\r
+    }\r
+\r
+    if( ke>='0' && ke<='9' ){\r
+      if( mm==3 ){\r
+       B_LOCATE(25,6);ex=vinput(ke-'0',0x403);\r
+       if(es==0 && ex>7 && ex<256 ){mtempo=ex;}\r
+      }\r
+      if( mm==4 ){\r
+       ex=pbias;if(ex>127){ex=ex-256;}\r
+       B_LOCATE(25,7);ex=vinput(ke-'0',0x403);\r
+       if(ex>=-36 && ex<=36){\r
+         if(ex<0){ex=ex+256;}\r
+         if(es==0 && ex>=0 && ex<=255){pbias=ex;}\r
+       }\r
+      }\r
+      if( mm==6 ){\r
+       B_LOCATE(22,9);ex=vinput(ke-'0',0x402);\r
+       if(es==0 && ex>0 && ex<=32){beat1=ex;}\r
+       B_LOCATE(26,9);ex=vinput(beat2,0x802);\r
+       if(es==0 && ex>1 && ex<=8){beat2=ex;}\r
+      }\r
+      if( mm==7 ){\r
+       B_LOCATE(45,6);ex=vinput(ke-'0',0x403);\r
+       if(es==0 && ex>=48 && ex<=480){tbase=ex;}\r
+      }\r
+      B_LOCATE(0,2);C_CLS_ED();\r
+    }\r
+\r
+    if( ke=='+' || ke=='>' || ke=='.' ){\r
+      if( mm==3 ){\r
+       if(sh&1){mtempo+=10;}else{mtempo++;}\r
+       if(mtempo>255){mtempo=255;}}\r
+      if( mm==4 ){\r
+       ex=pbias;if(ex>127){ex=ex-256;}\r
+       if(sh&1){ex+=12;}else{ex++;}\r
+       if(ex<=36){\r
+         if(ex<0){ex=ex+256;}\r
+         pbias=ex;\r
+       }\r
+      }\r
+      if( mm==5 ){bkey++;if(bkey>31){bkey=0;}}\r
+      if( mm==7 ){\r
+       int j;\r
+       for(j=0;j<10;j++){\r
+         if(tbase<tbase_tbl[j]){tbase=tbase_tbl[j];break;}\r
+       }\r
+      }\r
+    }\r
+    if( ke=='-' || ke=='<' || ke==',' ){\r
+      if( mm==3 ){\r
+       if(sh&1){mtempo-=10;}else{mtempo--;}\r
+       if(mtempo<8){mtempo=8;}}\r
+      if( mm==4 ){\r
+       ex=pbias;if(ex>127){ex=ex-256;}\r
+       if(sh&1){ex-=12;}else{ex--;}\r
+       if(ex>=-36){\r
+         if(ex<0){ex=ex+256;}\r
+         pbias=ex;\r
+       }\r
+      }\r
+      if( mm==5 ){bkey--;if(bkey<0){bkey=31;}}\r
+      if( mm==7 ){\r
+       int j;\r
+       for(j=10-1;j>=0;j--){\r
+         if(tbase>tbase_tbl[j]){tbase=tbase_tbl[j];break;}\r
+       }\r
+      }\r
+    }\r
+\r
+    if( ke==32 ){\r
+      if( mm==3 ){mtempo=120;}\r
+      if( mm==4 ){pbias=0;}\r
+      if( mm==5 ){bkey=0;}\r
+      if( mm==6 ){beat1=4;beat2=4;}\r
+      if( mm==7 ){tbase=48;}\r
+    }\r
+    if( ke==0x0b ){i=0;}\r
+\r
+    if( ke==0x05 ){i--;if(i<0){i=3;}}\r
+    if( ke==0x18 ){i++;if(i>3){i=0;}}\r
+    if( ke==0x13 ){cx--;if(cx<0){cx=1;}}\r
+    if( ke==0x04 ){cx++;if(cx>1){cx=0;}}\r
+  }\r
+}\r
+\r
+/***************************/\r
+char   *mdinport()\r
+{\r
+  static       char tmp0[64];\r
+  char *a;\r
+\r
+  /*\r
+  if(rcd->rcd_type==4){strcpy(tmp0,"RS-232C");\r
+  }else{\r
+    if(rcd->rcd_type==3){strcpy(tmp0,"POLYPHON");\r
+    }else{\r
+      if(rcd->put_mode==2){\r
+       if(rcd->rcd_type==0){strcpy(tmp0,"RS-232C");\r
+       }else{strcpy(tmp0,"POLYPHON");}\r
+      }else{strcpy(tmp0,"CZ-6BM1");}\r
+    }\r
+  }\r
+  */\r
+  \r
+  if ( midi_port_name[0] != 0 ) {  /* Sep.02.1998 Daisuke Nagano */\r
+    a = strrchr( midi_port_name, '/' );\r
+    if ( a==NULL ) a=midi_port_name-1;\r
+    strncpy( tmp0, a+1, 63 );\r
+  } else {\r
+    strcpy( tmp0, "NoConnect" );\r
+  }\r
+  return tmp0;\r
+}\r
+\r
+/***************************/\r
+void   dpl(int a)\r
+{\r
+  int  i;\r
+\r
+  for(i=0;i<=15;i++){if(a==0){GPALET(i,0);}else{GPALET(i,palet_dat[i]);}}\r
+}\r
+\r
+/***************************/\r
+void   tpl(int a)\r
+{\r
+  int  i;\r
+\r
+  for(i=1;i<=3;i++){if(a==0){TPALET(i,-2);}else{TPALET(i,palet_dat[i]);}}\r
+}\r
+\r
+/***************************/\r
+void   fonload(char *fi)\r
+{\r
+#if 0\r
+  FILE *fp;\r
+  char tmp0[1024];\r
+\r
+  if(!(fp= fopen2(fi,"rb"))){\r
+    strcpy( tmp0, STED_DEFAULT_PATH );\r
+    strcat( tmp0, "/" );\r
+    strcat( tmp0, (strrchr(fi,'/')==NULL)?fi:(strrchr(fi,'/')+1) );\r
+    if (!(fp=fopen2( tmp0, "rb" ))) {\r
+      B_PRINT(fi);B_PRINT(_(": File not found.\n"));exit(1);\r
+    }\r
+  } /* Oct.13.1998 by Daisuke Nagano */\r
+  fread(dat,1,12*1024,fp);fclose(fp);\r
+  fonset(dat);\r
+#endif\r
+}\r
+\r
+/***************************/\r
+void   fonread(unsigned char *buf)\r
+{\r
+  int  i;\r
+\r
+  struct       X68_FNTBUF      *fntb,buff;\r
+  fntb=&buff;\r
+\r
+  for(i=0;i<94;i++){\r
+    FNTGET(8,0x7621+i,fntb);memcpy(&buf[i*32      ],fntb->buffer,32);\r
+    FNTGET(8,0x7721+i,fntb);memcpy(&buf[i*32+94*32],fntb->buffer,32);\r
+  }\r
+}\r
+\r
+/***************************/\r
+void   fonset(unsigned char *buf)\r
+{\r
+  int  i;\r
+\r
+  for(i=0;i<94;i++){\r
+    DEFCHR(8,0x7621+i,&buf[i*32      ]);\r
+    DEFCHR(8,0x7721+i,&buf[i*32+94*32]);\r
+  }\r
+}\r
+\r
+/***************************/\r
+int    option_read(char *env_option)\r
+{\r
+  int  i,s,nn;\r
+\r
+  strcat(env_option," ");i=0;s=0;nn=0;\r
+\r
+  while(env_option[i]!=0){\r
+    if(env_option[i]==32){\r
+      if(s>0){\r
+       env_opt[nn][s]=0;nn++;s=0;if(nn>31){break;}\r
+      }\r
+    }else{\r
+      env_opt[nn][s]=env_option[i];s++;\r
+    }\r
+    i++;\r
+  }\r
+  return(nn);\r
+}\r
+\r
+/***************************/\r
+int    exe(char *cl)\r
+{\r
+  int  ec,er,use;\r
+  char tmp0[128];\r
+\r
+  rst_errvect();\r
+  size_ref();\r
+\r
+  if(used_u==0){\r
+    use=buff_size-buff_free;\r
+    SETBLOCK((void *)trk[0],use);\r
+\r
+    ec=-1;\r
+    if(rc_path[0]!=0){strcpy(tmp0,rc_path);strcat(tmp0,cl);ec=child(tmp0);}\r
+    if(ec<0){ec=child(cl);}\r
+\r
+    buff_size=buff_max;\r
+    /*realc:*/\r
+    er=SETBLOCK((void *)trk[0],buff_size);\r
+    /*\r
+      if(er>=0x81000000){\r
+      msg("トラックバッファが再確保出来ません。");\r
+      buff_size=er&0xfffffc;\r
+      if(er<0x82000000){goto realc;}\r
+      }\r
+\r
+      buff_free=buff_size-use;\r
+      */\r
+  }else{\r
+    ec=child(cl);\r
+  }\r
+  /*   trksize(-2);*/\r
+  set_errvect();\r
+  return(ec);\r
+}\r
+\r
+/***************************/\r
+void   ErrorTrap(void)\r
+{\r
+\r
+  fprintf(stderr,"ErrorTrap\n");\r
+  exit(-1);\r
+#ifdef X680x0\r
+\r
+  register int ErrCode asm(" d7");\r
+\r
+  if (((unsigned int)ErrCode >=0x1000) && ((unsigned int)ErrCode <= 0x7fff)) {\r
+    switch ( (unsigned int)ErrCode ) {\r
+      /*case 0x01:msg("無効なユニットを指定しました。");break;\r
+       case 0x02:msg("ドライブの準備ができていません。");break;\r
+       case 0x03:msg("無効なコマンドを指定しました。");break;*/\r
+    case 0x04:msg("CRCエラー");break;\r
+    case 0x05:msg("管理領域が異常です。");break;\r
+    case 0x06:msg("シークエラー");break;\r
+    case 0x07:msg("無効なメディアです。");break;\r
+    case 0x08:msg("セクタが見つかりません。");break;\r
+    case 0x0a:msg("書き込みエラー");break;\r
+    case 0x0b:msg("読み込みエラー");break;\r
+    case 0x0d:msg("ライトプロテクトされてます。");break;\r
+    case 0x0e:msg("書き込みが禁止されています。");break;\r
+      /*case 0x0f:msg("ファイル共有違反です。");break;*/\r
+\r
+    case 0x09:/*msg("プリンタオフライン");*/;\r
+      /*case 0x1f:msg("インタラプトが押されました。");*/\r
+      IJUMP_RTE();return;break;\r
+    default:\r
+      IJUMP(ErrorTrap_Old);return;break;\r
+    }\r
+    /*bufset();IJUMP(ErrorTrap_Old);*/\r
+    \r
+    (0);B_LOCATE(0,2);C_CLS_ED();fcloseall();\r
+\r
+    asm("andi.w #$d8ff,sr");\r
+    IJUMP((int)*com_sel);\r
+  } else {\r
+    IJUMP(ErrorTrap_Old);\r
+  }\r
+\r
+#endif\r
+}\r
+\r
+/***************************/\r
diff --git a/sted.h b/sted.h
new file mode 100644 (file)
index 0000000..b685e70
--- /dev/null
+++ b/sted.h
@@ -0,0 +1,251 @@
+/*
+ * MIDI Music Composer STed v2.07j : sted.h (header) 1997-07-20 by TURBO
+ */
+#pragma once
+#ifndef _STED_H_
+#define _STED_H_
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif /* HAVE_CONFIG_H */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <errno.h>
+#include <math.h>
+#include <ctype.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_STRING_H
+#  include <string.h>
+#endif /* HAVE_STRING_H */
+
+#ifndef STDC_HEADERS
+#  ifndef HAVE_STRCHR
+#    define strchr index
+#    define strrchr rindex
+#  endif /* HAVE_STRCHR */
+   char *strchr(), *strrchr();
+#  ifndef HAVE_MEMCPY
+#    define memcpy(d, s, n) bcopy((s), (d), (n))
+#    define memmove(d, s, n) bcopy((s), (d), (n))
+#  endif
+#endif
+
+#ifdef HAVE_FCNTL_H
+#  include <fcntl.h>
+#endif /* HAVE_FCNTL_H */
+
+#ifdef HAVE_UNISTD_H
+#  include <sys/types.h>
+#  include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#ifndef HAVE_SYS_TIME_H
+#  include <time.h>
+#else /* HAVE_SYS_TIME */
+#  ifdef TIME_WITH_SYS_TIME
+#    include <time.h>
+#  endif /* TIME_WITH_SYS_TIME */
+#  include <sys/time.h>
+#endif
+
+#include <sys/types.h>
+#ifdef HAVE_SYS_WAIT_H
+#  include <sys/wait.h>
+#endif /* HAVE_SYS_WAIT_H */
+#ifndef WEXITSTATUS
+#  define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
+#endif /* WEXITSTATUS */
+#ifndef WIFEXITED
+#  define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
+#endif /* WIFEXITED */
+
+#ifdef HAVE_DIRENT_H
+#  include <dirent.h>
+#  define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+#  define dirent direct
+#  define NAMLEN(dirent) (dirent)->d_namlen
+#  ifdef HAVE_SYS_NDIR_H
+#    include <sys/ndir.h>
+#  endif
+#  ifdef HAVE_SYS_DIR_H
+#    include <sys/dir.h>
+#  endif
+#  ifdef HAVE_NDIR_H
+#    include <ndir.h>
+#  endif
+#endif /* HAVE_DIRENT_H */
+
+#include "version.h"
+
+#include "iocslib.h"
+#include "doslib.h"
+#include "graph.h"
+#include "rcddef.h"
+#include "x68funcs.h"
+#include "midi_in.h"
+
+#define HAVE_SUPPORT_STED3
+#ifdef HAVE_SUPPORT_STED3
+# include "sted3.h"
+#endif
+
+#include "sted2header.h"
+
+ void rcd_check( void );
+ void rcd_open_device( void );
+extern  struct RCD_HEAD        *rcd;
+extern  char rcd_version[5];
+/* etc */
+extern  char   hlp_path[128];                  /* help file path & name        */
+extern  char   fon_path[128];                  /* font file path & name        */
+extern  char   def_path[128];                  /* .def path name               */
+extern  char   rcp_path[128];                  /* .rcp path name               */
+extern  char   prt_path[128];                  /* .prt path name               */
+extern  char   trk_path[128];                  /* .trk path name               */
+extern  char   def_file[128];                  /* .def file name               */
+extern  char   rcp_file[128];                  /* .rcp file name               */
+extern  char   prt_file[128];                  /* .prt file name               */
+extern  char   trk_file[128];                  /* .trk file name               */
+extern  char   repl[128];                      /* replace string               */
+extern  char   delt[128];                      /* delete string                */
+extern  char   srch[128];                      /* find string                  */
+extern  char   repl_t[26*6][40];
+extern  char   repl_d[26*6][50];
+extern  int    tr_step[36];                    /* track total step temp        */
+extern  int    tr_alc[36];                     /* track aloc size              */
+extern  int    tr_len[36];                     /* track used size              */
+extern  int    tr_pos[36][2][4];               /* track cursor position        */
+extern  int    tag[26+2][4];                   /* tag jamp list buffer         */
+extern  int    es,ecode,scyp;                  /* input subroutine exit code   */
+extern  int    btrack;                         /* track set top track          */
+extern  int    track,track1,track2;            /* edit track no.               */
+extern  int    edit_scr;                       /* 0=l_track 1=r_track 2=rhythm */
+extern  int    cmdflag,cnfflag,mdlflag;        /* STed2 system flag            */
+extern  int    poft;
+extern  int    TRACK_SIZE,work_size;           /* buffer size                  */
+extern  int    buff_size,buff_free,buff_max;
+extern  int    cpcy,cpadd,cplen;
+extern  int    cpleng,rcpf,rcplen;             /* copy flag                    */
+extern  void   *ErrorTrap_Old;                 /* err trap vecter/flag         */
+extern  int    ErrFlag;
+/* cnf */
+extern  char   comment[64];                    /* comment                      */
+extern  int    tm_lag;                         /* graphic rewrite time lag     */
+extern  char   inpmode;                        /* editor input mode            */
+extern  char   grpmode;                        /* editor graphic mode          */
+extern  char   thrumode;                       /* edit midi in thru mode       */
+extern  int    rec_getch,rec_putmd;            /* recoding ch./put mode        */
+extern  int    vis_reso;                       /**/
+extern  unsigned char  rfilt[32][4];           /* record filter */
+extern  unsigned char  pfilt[32][4];           /* play   filter */
+extern  char   mplay[16][16];
+extern  int    palet_dat[16];
+extern  unsigned char  keyst_table[2][128];    /* key# -> st/gt convert table  */
+extern  unsigned char  stgt_tbl[60];           /* f.key -> st/gt table         */
+extern  char   rhy_vel[16];
+extern  char   chcom_s[26*2][2][50];           /* child command comment        */
+extern  char   chcom_c[26*2][2][16];           /* child command parameter      */
+/* def */
+extern  char   module[64];                     /* module name                  */
+extern  int    lsp_wait;                       /* last para. transfer wait     */
+extern  int    bend_range;                     /* piche bend range             */
+extern  char   tim_asin[33];                   /* tone list channle assign     */
+extern  char   tim_head[400][24];              /* tone list title              */
+extern  char   tim_sym[400][8];                /* tone list symbol             */
+extern  char   tim_name[80*128][15];           /* tone name buffer             */
+extern  short  tim_top[400];                   /* tone name buffer address     */
+extern  char   card_name[21][64];              /* pcm card name list           */
+extern  char   card_no[2];                     /* used pcm card no.            */
+extern  short  gs_bank[18*128];                /* gs bank part no.(8+1 group)  */
+extern  short  gs_mode[18];                    /* gs bank mode    (8+1 group)  */
+extern  char   rhy_stest[8];                   /* rhythm sound test ch. & para */
+extern  char   rec_met[10];                    /* recording metoro tone        */
+extern  unsigned char  init_exc_data[258];     /* init exclusive data          */
+/*** rcp format head parameter ***/
+extern  char   mtitle[65];                     /* music title                  */
+extern  char   memo[12][29];                   /* memo                         */
+extern  int    tbase,mtempo;
+extern  int     beat1,beat2,bkey,pbias;                /* common parameter             */
+extern  char   cm6_file[128],gsd_file[128];    /* controol file name           */
+extern  char   rhyna[32][15];                  /* rhythm assign name           */
+extern  unsigned char  rhyno[32][2];           /* rhythm assign key & gate     */
+extern  char   user_exc_memo[8][25];           /* user exclusive memo          */
+extern  unsigned char  user_exc_data[8][24];   /* user exclusive data          */
+extern  unsigned char  trno[36];               /* track no.                    */
+extern  unsigned char  trmod[36];              /* track play mode              */
+extern  unsigned char  trrhy[36];              /* track rhythm sw.             */
+extern  unsigned char  mch[36];                /* track midi ch.               */
+extern  unsigned char  trkey[36];              /* track key shift              */
+extern  unsigned char  trst[36];               /* track st shift               */
+extern  char   trkmemo[36][37];                /* track comment                */
+/* buffer */
+extern  unsigned char  lcbuf[1024*4+4];        /* delete line buffer           */
+extern  unsigned char  rlcbuf[132];            /* delete rhythm line buffer    */
+extern  unsigned char  cm6[22601],gsd[4096];   /* control file buffer          */
+extern  unsigned char  hed[1414];              /* rcp header temporary         */
+extern  unsigned char  *trk[36];               /* track buffer pointer         */
+extern  unsigned char  *cpbuf;                 /* track copy buffer            */
+extern  unsigned char  *rcpbuf;                /* rhythm track copy buffer     */
+extern  unsigned char  *dat;                   /* temporary & recording buffer */
+extern  unsigned char  *dat2;                  /* temporary                    */
+/* the following variables is only PC version available */
+extern  int issted3;                     /* Am I a new version ? */
+extern  int isconsole;                   /* is console mode? */
+extern  int isxwin;                      /* is X mode? */
+extern  char euc_text[1024];             /* code convert buffer */
+extern  char player_name[1024];          /* midi player name */
+extern  char midi_port_name[1024];       /* midi_port device name */
+extern  char font_name[1024];            /* X font set name */
+extern  int player_flag;                 /* is player able to play only SMF? */
+extern  char KEY_XF1[];                  /* keysym names */
+extern  char KEY_XF2[];
+extern  char KEY_XF3[];
+extern  char KEY_XF4[];
+extern  char KEY_XF5[];
+extern  char KEY_KANA[];
+extern  char KEY_KIGO[];
+extern  char KEY_TOROKU[];
+extern  char KEY_INS[];
+extern  char KEY_DEL[];
+extern  char KEY_HOME[];
+extern  char KEY_UNDO[];
+extern  char KEY_RUP[];
+extern  char KEY_RDOWN[];
+extern  char KEY_OPT1[];
+extern  char KEY_OPT2[];
+extern int str_vala;
+
+
+ int itor( char *, char * );
+ int STed_MeasureConversion( int track );
+ void Exit(int);
+#define exit Exit
+ int sted_sleep(long in_usleep);
+
+extern int eucenv;
+
+ char *nkf_conv(char *, char *, char *);
+#define eucconv(a) ((eucenv!=0) ? nkf_conv( a, euc_text, "EUC" ) : a)
+
+#ifdef ENABLE_NLS
+# include <locale.h>
+# include <libintl.h>
+# undef _
+# define _(String) gettext(String)
+# define N_(String) (String)
+
+#else /* ENABLE_NLS */
+# define _(String) (String)
+# define N_(String) (String)
+#endif /* ENABLE_NLS */
+
+/* inlines */
+ void    rec_filter(int md);
+ int       option22(int md,int sm,int ad,int ew);
+// int       option2(int md,int sm,int ad,int ew);
+
+#endif /* _STED_H_ */
diff --git a/sted2header.h b/sted2header.h
new file mode 100644 (file)
index 0000000..1f7835b
--- /dev/null
@@ -0,0 +1,467 @@
+#pragma once
+
+#include "rcp.h"
+
+typedef struct {
+  char         name[23];
+  unsigned char        fatr;
+  unsigned int fln;
+  unsigned int ftm;
+  unsigned int fdt;
+} X68_DIR;
+
+char *chstr(int ex);
+char *cm6_tone_name(int mo,int i);
+char *ctrl_type(int a);
+char *dirs(char *s);
+char *dtasc( unsigned int j );
+char *fstr(int v,int c);
+char *hex_s(int a,int c);
+char *jstrupr(char *st);
+char *keystr(int da);
+char *keystr1(int da,int skey);
+char *keystr2(int da,int skey);
+char *mdinport();
+char *nstr(int v);
+char *prog_name(int ch,int bank,int prog,int h);
+char *scale_str(int da);
+char *spadd(char *s,int c);
+char *sread(int a,int b);
+char *tim_names(int no);
+char *tmasc( unsigned int j );
+char *trk_dis(int y,int ad,int line);
+int    strch(int och,char *tmp0);
+void part_as();
+int STed_InitMeasureConversion( void );
+int STed_MeasureConversion( int track );
+int _dos_nfiles( struct _x68_filbuf *in_buff );
+int add_set(int size,int *add);
+int bank_no(int j);
+int bendc2(int ad,char *s);
+int buf_meas(unsigned char *pp,int ln);
+int bufload();
+int bufload_trk(int tr);
+int bufset();
+int bufset_trk(int tr);
+int channel_no(int j);
+int chd_check(int tr,int ad,int md);
+int chord_ins(int ad,int co);
+int chord_sel(int key,int ad);
+int chord_ten(int key,int no);
+int close_player(int in_sig);
+int cm6_tonesel(int slmd);
+int comment_inp(int ad,int cy,int sh);
+int countstart(int md,int smeas);
+int cpybuf_set(int tr,int ad,int ln);
+int ctc(int da,char *s,int skey);
+int dat_add(int ln,int me);
+int def_bload(char *fi,int md);
+int def_bsave();
+int def_save();
+int defload(char *fi,int md);
+int dload(char *fna,int md);
+int dot_ed(int dx,int co);
+int drv_code(char *st);
+int drvchk(char *pth);
+int drvchk2(char *pth);
+int dsave(char *fna);
+int exc_load(char *fna);
+int exc_rec();
+int exc_save(char *fna,int co);
+int exe(char *cl);
+int fdir(char *pth,char *exts,X68_DIR *dir,int w);
+int file_check(char *fna,int cc);
+int find(int po,int h);
+int find_rep(int po);
+int flush_event( RCP_DATA *, int );
+int get_delta( int p );
+int gomi_cut(unsigned char *ptr,int size);
+int gra_add(int ad,int md);
+int gsdload(char *fna);
+int help(int md);
+int init_track_header( RCP_DATA *, int );
+int inkey2();
+int inkey3();
+int insert_tempo_event( RCP_DATA * );
+int key_shift(int skey,int *f,int *a);
+int klen();
+int knck(char *st,int p);
+int last_tempo(int meas);
+int lsp_para_set(int tr,int po,int *me_ad,int wcc);
+int lsp_wait_chack(int meas);
+int meas_add(int me);
+int meas_adj_sub(int ln,int st);
+int meas_adjust(int i,int topm);
+int meas_len(int j);
+int meas_no(int ad);
+int meas_no2();
+int midi_in();
+int midi_inout();
+int mml_inp(int ad);
+int mspos( int *out_x, int *out_y );
+int onekey(int imd,int cde);
+int open_midi_device(char *);
+int option(int md,int sm);
+int option2(int md,int sm,int ad,int ew);
+int option_read(char *env_option);
+int padjust(int *po,int i);
+int paraexe(char *tmp0,int ad,int ew,int sm,int cmd);
+int part_load(char *fna);
+int part_save(char *fna,int ln);
+int part_sel(int yy);
+int part_text_save(char *fna,int ad,int ln);
+int point( int in_x, int in_y );
+int polykey(int cde);
+int priority_init( void );
+int prog_no(int j);
+int progmode(char *tmp2);
+int put_event( RCP_DATA *, int );
+int rcp_buf_get(char *ptr,int po,int ln);
+int rcp_buf_put(char *ptr,int po,int ln);
+int rcptomid_init_track_buffer( RCP_DATA * );
+int rcptomid_read_rcp_header( RCP_DATA * );
+int rcptomid_set_new_event( RCP_DATA *, int );
+int real_ad(int po,int cy);
+int real_cy(int po,int ad);
+int real_po(int po,int cy);
+int real_record();
+int rec_ext(int i);
+int rep_match(int f,int f2,int t,int t2,int a,int m);
+int repeat_comp(int tr);
+int repeat_ext(unsigned char *obuf,int ln);
+int repl_select(int md);
+int replace(int po,int ln,int sh,int v);
+int replicate(int ad,int sh);
+int replicate2(int ad,int sh);
+int ret_chord(int ad);
+int ret_midi(int cde,int imd,int ad,int cy);
+int retkey(int ecode);
+int retkey2(int ecode);
+int rex_load(char *fna,int mo);
+int rex_save(char *fna,int mo);
+int rhy_as_sel(int no);
+int rhy_patch();
+int same_ext_sub(int tr,int p1,int p2,int md);
+int same_meas_conv(int tr);
+int same_meas_extr(int tr,int ad,int ln);
+int scale_no(int j);
+int scale_sel(int x,int y,int skey);
+int set_signals( void );
+int set_tempo_track( RCP_DATA * );
+int size_add(int tr,int size);
+int size_change(int tr,int ln);
+int size_max(int tr);
+int spc_code(char * s, int * ctl);
+int spc_code(char *s,int *ctl);
+int spc_select();
+int st_cv(int st);
+int start_player(unsigned char* in_data, int in_len);
+int sted2_close( void );
+int sted2_init( RCP_DATA * );
+int sted_sleep(long in_usec);
+int step_ad(int ad,int step);
+int step_cluc(int ad);
+int step_cluc2(int tr,int top,int len);
+int step_no(int ad);
+int stop_player(void);
+int str_last(unsigned char *tmp0);
+int str_search(char *tmp0,char *tmp1);
+int str_val(char *s);
+int str_val(char* s);
+int sttm_ad(int ad,int step);
+int sttm_no(int ad);
+int sys_mode();
+int tagj(int *po,int fl);
+int tai_check(int tr,int ad);
+int tai_compres(int tr,int po1,int po2);
+int thedread(int tr);
+int timload(char *fna);
+int timsave(char *fna);
+int timsel(int bmode,int bank,int gx,int prog);
+int timsel2(int ch,int bank,int gx,int prog);
+int tone_patch(int mo);
+int trk_check(int ln);
+int trk_ext_sub(int tr,char *exbuf);
+int trk_load(char *fna);
+int trk_mix_sub(unsigned char *in1,unsigned char *in2);
+void trk_opt_sub(int tr,int po1,int po2);
+int trk_save(char *fna);
+int trk_sel(int cx);
+int trk_shift(int ad,int ln);
+int user_tone_list();
+int varia(char *pname,int bank,int prg,int md);
+int velo_ctrl(int ad,int ln,int vmo);
+int vinput(int l,int ln);
+int vis_a_in(int po,int ln,int *para,int *step,int vmo);
+int vis_a_in_co(int po,int ln,int vmo);
+int vis_a_in_st(int po,int ln);
+int vis_bufset(int po,int co,int *para,int *step,int vmo,int bf);
+int vis_cut(int co,int st,int *para,int *step);
+int vis_edit(int po,int ln,int ssh);
+int vis_ext();
+int vis_ext_mix(int po,int co,int *para,int *step,int vmo,int ost);
+int vis_lnk(int co,int *para,int *step);
+int yn_sel();
+unsigned char *set_smf_data( RCP_DATA * );
+void ErrorTrap(void);
+void H_INIT();
+void H_PRINT ( char *in_s1, char *in_s2, char *in_s3 );
+void H_PRINT2 ( char *in_s1, char *in_s2, char *in_s3 );
+void KNJCTRL( int i, int j );
+void OnGraphic();
+void all_note_off(int m);
+void asin_change();
+void asin_init();
+void b_striS ( char * buf, int bufSize, int num );
+void beat_set();
+void bendc(int ad,int sh);
+void box( int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_col, unsigned int in_ls );
+void bunkatsu(int st,int co,int *da);
+void card_name_get();
+void card_sel();
+void cdplay(int tr,int po,int ln,int md);
+void chord_dis(int n);
+void cm64_con();
+void cm6_la_write(int i);
+void cm6_pcm_write(int i);
+void cm6_tone_write(int i);
+void cm6_write(int ad,int ad2,int ln);
+void cminit();
+void cnf_prog(char *li,char *li2,int md);
+void cnf_repl(char *li,char *li2,int md);
+void cnf_rvel(char *li);
+void cnf_stgt(char *li,int nn);
+void cnfinit();
+void cntplay(int tr,int po);
+void com_sel();
+void cons_md(int x);
+void cur_down(int *po,int *cy);
+void cur_up(int *po,int *cy);
+void dat_info(int po,int sh);
+void dat_rev(int tr,int ad,int ln);
+void dattopat(int me);
+void dclr();
+void def_init(char *li);
+void definit();
+void dinit();
+void dir_disp(X68_DIR *dir,int nm,int p,int cx,int sp,int ln);
+void disable_update_screen();
+void disp_vels( void );
+void dot_ctrl(int m);
+void dot_dis(int cx);
+void dpl(int a);
+void dplay(int mo,int tr,int meas);
+void ed_ch_stgt(int, int, int, int, int);
+void edfield(int m);
+void end_proc();
+void exc_dis(int no,int cx,int co,int m);
+void exc_dis2(int ,int );
+void exc_edit(int ad,int cy,int sw);
+void excdel(unsigned char *da,int co,int nn);
+void excins(unsigned char *da,int co,int nn);
+void excsum(unsigned char *da,int nn);
+void file_back(char *fna);
+void fill( int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_col );
+void filt_init();
+void fnc_dis(int n);
+void fonload(char *fi);
+void fonread(unsigned char *buf);
+void fonset(unsigned char *buf);
+void form();
+void form2();
+void form3();
+void frees(char *pth,int cx);
+void fsel(char *fna,char *pth,int w);
+void g_print( int in_x, int in_y, char *in_str, int in_col );
+void g_print2(int x, int y, char * s, int c1);
+void g_print2(int x,int y,char *s,int c1);
+void gra(int po,int sh);
+void gra_c(int po);
+void gra_gakufu(int po,int md);
+void gra_special(int po,int md);
+void gsd_buf_trns();
+void gsd_con();
+void gsd_var_read();
+void gsinit();
+void hedread();
+void hedset(int max);
+void home2(int y);
+void inmd_disp();
+void inpmon();
+void key_midi_player_wait();
+void key_midi_wait( void );
+void key_midi_wait();
+void key_mouse_wait( void );
+void key_pause();
+void key_rep_off();
+void key_rep_on();
+void key_shift_sub(int no,int *f,int *a);
+void key_vect_reset();
+void key_vect_set();
+void key_wait();
+void keyclr();
+void keyd();
+void keyd_inp(int a);
+void keyinp();
+void line( int in_x0, int in_y0, int in_x1, int in_y1, int in_col, int in_ls );
+void line_del(int po,int cy);
+void line_ins(int po,int cy);
+void line_ins_aft(int ad);
+void load_sub(int sh);
+void logo(int y);
+void m_keyb(int ch,int bank,int prg,int velo);
+void memcpy_l( unsigned char *dest, unsigned char *src, int len ) ;
+void memcpy_l( unsigned char *dest, unsigned char *src, int len );
+void memcpy_l(unsigned char * dest, unsigned char * src, int len);
+void memo_disp();
+void memo_ed(int sh);
+void memo_load(char *pth,char *fna);
+void midi_change(int md);
+void midi_chout(int a);
+void midi_clr();
+void mix_one(int c,int a);
+void mix_two(int c,int a,int b);
+void msg(char *s);
+void msg_clr();
+void noed_cls();
+void noed_cls_t();
+void note_ctrl(int po1,int po2);
+void partf(int a,int ad);
+void pat_para_dis(int m,int ad);
+void pat_para_set(int mo,int ad,int i);
+void path_cut(char *fpath,char *fname);
+void path_down(char *pth);
+void path_set(char *pth);
+void pattodat(int me);
+void pattor(int me);
+void pch_fld(int m);
+void pfil();
+void poplay(int po,int md);
+void prn_gspanel( int cx );
+void put_delta( int p ,int val);
+void put_sharp(int skey,int x,int y);
+void rcp_dat();
+void rcp_dat2(int n,int m);
+void rec_ch_change(int pm);
+void rec_ch_disp();
+void rec_conv( int mm );
+void rec_filter(int md);
+void rec_md_change();
+void rec_meas_change(int pm);
+void rec_mt_change(int md);
+void rec_sy_change();
+void ret(int ad,int cx,int cy,int kc);
+void rev_area( int in_r_ad, int in_r_ln, int in_edit_scr );
+void rhed_dis(int p);
+void rhinit();
+void rhinit2(int i);
+void rhy_as();
+void rhy_as_para();
+void rhy_step();
+void roll_down(int *po,int *cy);
+void roll_up(int *po,int *cy);
+void rst_errvect();
+void rsttrc(int *no,int *cx,int flg,int pg);
+void rtopat(int me);
+void rtrk_dis(int p,int ad,int line);
+void rtrk_ed(int md,int sh);
+void s_test(int ch,int bank,int prg,int note,int velo);
+void same_cluc(int tr,int ofset);
+void same_shift(int spo,int m,int cu);
+void save_sub(int sh);
+void scinst_dsp ( int x, int y, unsigned char *dp );
+void scpanel_dsp( int x, int y, unsigned char *dp );
+void sdis(int x,int y,char *s,int c,int c1,int c2);
+void sdis2(int x,int y,char *s,int c,int c1,int c2);
+void sdis3(int x,int y,char *s,int c,int c1,int c2);
+void set_errvect();
+void sinit();
+void sinput(char * sb, int ln);
+void sinput(char *sb,int ln);
+void size_ref();
+void snsclr();
+void spcon(int ad,int cy);
+void spcut(char *st);
+void sset(char *s,int a,int b);
+void start_timer(int in_interval, RCP_DATA* in_rcp);
+void stest_para_disp(int x);
+void stest_para_edit(int x,int a);
+void stgt_as();
+void stgt_init();
+void stgt_init2(int i);
+void stop_timer(void);
+void str_change(char *s);
+void sttrc(int *po,int *cy,int flg);
+void symbol( int in_x, int in_y, char *in_st, char in_h, char in_v, char in_mo, int in_p, char in_an );
+void t_scrw( int in_x0, int in_y0, int in_xs, int in_ys, int in_x1, int in_y1 );
+void tcur(int a,int b,int c,int cs);
+void tcury(int a,int b,int c,int cs);
+void tdis(int x,int y,char *s,int c,int c1);
+void temporary_set();
+void tg_copy( int in_edit_scr );
+void tg_copy2( int in_edit_scr );
+void thedset(int tr,int sz);
+void tim_buf_trns();
+void tim_name_read();
+void tim_name_set();
+void tim_var_read();
+void timtra();
+void tpl(int a);
+void trk_cluc();
+void trk_dat();
+void trk_delete(int ad,int ln);
+void trk_ed();
+void trk_ed_end(int po,int cx,int cy);
+void trk_free(int ad);
+void trk_lin(int i,int cx,int m);
+void trk_next(int m);
+void trk_no();
+void trk_no_cur(int i,int m);
+void trk_no_dis();
+void trk_pos_set(int po,int cx,int cy);
+void trk_quan(int tr,int po1,int po2);
+void trk_set(int md);
+void trksize(int tr);
+void trksize_c();
+void trmod_set(int tr,int md,int sh);
+void trns_check();
+void ts_clear(int a);
+void ts_copy(int a,int b);
+void ts_ext(int i);
+void ts_ins(int a,int b);
+void ts_measend(int tr1,int sh);
+void ts_mix(int tr1,int tr2,int tr3);
+void ts_sort(int a,int b);
+void ts_swap(int a,int b);
+void twait(int ti);
+void txcur( int in_a, int in_b, int in_c1, int in_c2, int in_cs );
+void txerase(int x,int y,int x1,int y1);
+void txxline(int x,int y,int x1,int page,int style);
+void txyline(int x,int y,int y1,int page,int style);
+void uex_read(int po,int no);
+void uex_set(int po,int no);
+void undobuf(int a);
+void user_exc_as(int no);
+void user_exc_dis(int no);
+void user_exc_init();
+void user_exc_init2(int i);
+void val_add(int ad,int cx,int kc);
+void val_rev(int ad,int cx);
+void val_sub(int ad,int cx,int kc);
+void vdis(int x,int y,int v,int c,int c1,int c2);
+void vdis2(int x,int y,int v,int c,int c1,int c2);
+void vdis3(int x,int y,int v,int c,int c1,int c2);
+void vis_a_out(int po,int ln,int *para,int *step,int vmo);
+void vis_disp(int co,int cx,int ccx,int *para,int *step,int mo,int c,int vmo);
+void vis_wave(int st,int co,int cx,int ccx,int *para,int *step,int md,int vmo);
+void vis_zom(int co,int in_step,int out_step,int *step,int *step2);
+int    ras_load(char *fna);
+int    ras_save(char *fna);
+int sted_sleep(long in_usec);
+int rcptomid_init_track_buffer( RCP_DATA *rcp );
+int rcptomid_set_new_event( RCP_DATA *rcp, int t );
+int rcptomid_read_rcp_header( RCP_DATA *rcp );
+int init_track_header( RCP_DATA *rcp, int track );
+int flush_event( RCP_DATA *rcp, int track );
+int set_tempo_track ( RCP_DATA *rcp ) ;
+int insert_tempo_event( RCP_DATA *rcp ) ;
diff --git a/sted3.h b/sted3.h
new file mode 100644 (file)
index 0000000..fa80a2e
--- /dev/null
+++ b/sted3.h
@@ -0,0 +1,17 @@
+/*
+  sted3.h
+  May.06.2001 NAGANO Daisuke <breeze.ngano@nifty.ne.jp>
+
+  All configurable parameters for new parameters must be modified
+  in this file.
+ */
+#pragma once
+
+#ifndef _STED3_H_
+#define _STED3_H_
+
+#define STED3_VERSION             "0.01"
+#define STED3_MAX_PORT_NUMBER     16
+
+
+#endif /* _STED3_H_ */
diff --git a/sted_c.h b/sted_c.h
new file mode 100644 (file)
index 0000000..16a9d1f
--- /dev/null
+++ b/sted_c.h
@@ -0,0 +1,31 @@
+/*
+  sted_c.h
+
+  Made by Studio Breeze.2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+  */
+#pragma once
+#define STED_OPEN 0
+#define STED_SHMID 1
+#define STED_PLAY_FILE 2
+#define STED_STOP 3
+
+#define RCP_CAPABLE (1<<0)
+#define STED_CONTROLABLE (1<<1)
diff --git a/sted_dialogs.h b/sted_dialogs.h
new file mode 100644 (file)
index 0000000..b2f78a8
--- /dev/null
@@ -0,0 +1,30 @@
+/*\r
+       sted_dialogs.h\r
+\r
+  Permission is hereby granted, free of charge, to any person obtaining a copy\r
+  of this software and associated documentation files (the "Software"), to deal\r
+  in the Software without restriction, including without limitation the rights\r
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+  copies of the Software, and to permit persons to whom the Software is\r
+  furnished to do so, subject to the following conditions:\r
+\r
+  The above copyright notice and this permission notice shall be included in\r
+  all copies or substantial portions of the Software.\r
+\r
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+  THE SOFTWARE.\r
+*/\r
+#pragma once\r
+\r
+#ifndef WIN32_STED_DIALOGS_H\r
+#define WIN32_STED_DIALOGS_H\r
+\r
+/** MIDI設定ダイアログプロシージャ */\r
+ LRESULT CALLBACK Dlg_MidiDevices(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
+\r
+#endif /* WIN32_STED_DIALOGS_H */\r
diff --git a/sted_screen.cpp b/sted_screen.cpp
new file mode 100644 (file)
index 0000000..5774589
--- /dev/null
@@ -0,0 +1,471 @@
+/*
+  sted_screen.cpp
+  base class of screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+
+#include <stdio.h>
+#include "sted_screen.h"
+
+CSTedScreenBase::CSTedScreenBase()
+{
+  fConstructed = false;
+}
+
+void
+CSTedScreenBase::Construct(void)
+{
+  fConstructed = true;
+}
+
+//CSTedScreenBase*
+//CSTedScreenBase::New(void)
+//{
+//  CSTedScreenBase* self;
+//  self = new CSTedScreenBase;
+//  if (!self) return NULL;
+//
+//  self->Construct();
+//  if (!self->fConstructed) {
+//    delete self;
+//    return NULL;
+//  }
+//  return self;
+//}
+
+CSTedScreenBase::~CSTedScreenBase()
+{
+}
+
+void
+CSTedScreenBase::Tidy(void)
+{
+  fConstructed = false;
+}
+
+// window
+void
+CSTedScreenBase::InitWindow(void)
+{
+}
+
+void
+CSTedScreenBase::CloseWindow(void)
+{
+}
+
+void
+CSTedScreenBase::RepaintWindow(void)
+{
+}
+
+// color
+int
+CSTedScreenBase::SetGraphicsPalette(int in_pal, int in_color)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::SetTextPalette(int in_pal, int in_color)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::SetGraphicsColor(int in_color)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::SetTextColor(int in_color)
+{
+  return 0;
+}
+  
+
+// cursor
+void 
+CSTedScreenBase::SetCursor(int in_onoff)
+{
+}
+
+// text
+void
+CSTedScreenBase::SetTextWindow(int in_y, int in_h)
+{
+}
+
+void
+CSTedScreenBase::Locate(int in_x, int in_y)
+{
+}
+
+void
+CSTedScreenBase::Puts(const char* in_str)
+{
+}
+
+void
+CSTedScreenBase::ClsEol(void)
+{
+}
+
+void
+CSTedScreenBase::ClsEd(void)
+{
+}
+
+void
+CSTedScreenBase::GraphicsPuts(int in_x, int in_y, const char* in_str)
+{
+}
+
+// graphics
+
+void
+CSTedScreenBase::TextXBox(int in_x0, int in_y0, int in_x1, int in_y1, int in_page)
+{
+}
+
+void 
+CSTedScreenBase::TextXXLine(int in_page, int in_x0, int in_y, int in_x1, int in_linestyle)
+{
+}
+
+void
+CSTedScreenBase::TextXYLine(int in_page, int in_x, int in_y0, int in_y1, int in_linestyle)
+{
+}
+
+void
+CSTedScreenBase::TextReverse(int in_x, int in_y, int in_width, int in_page)
+{
+}
+
+void
+CSTedScreenBase::TextFill(int in_page, int in_x, int in_y, int in_w, int in_h, int in_linestyle)
+{
+}
+
+void
+CSTedScreenBase::TextRasterCopy(int in_dst, int in_src, int in_line, int in_mode)
+{
+}
+
+void
+CSTedScreenBase::TextScroll(int in_x0, int in_y0, int in_xs, int in_ys, int in_x1, int in_y1)
+{
+}
+
+void 
+CSTedScreenBase::GraphicsBox(int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_color, unsigned int in_linestyle)
+{
+}
+
+int
+CSTedScreenBase::GraphicsPoint(int in_x, int in_y)
+{
+  return 0;
+}
+
+void 
+CSTedScreenBase::GraphicsLine(int in_x0, int in_y0, int in_x1, int in_y1, int in_color, int in_linestyle)
+{
+}
+
+void
+CSTedScreenBase::GraphicsFill(int in_x0, int in_y0, int in_x1, int in_y1, int in_color)
+{
+}
+
+void
+CSTedScreenBase::TextReverseArea(int in_top, int in_lines, int in_area)
+{
+}
+
+void
+CSTedScreenBase::CopyTextToGraphics(int in_editscreen)
+{
+}
+
+void
+CSTedScreenBase::CopyTextToGraphics2(int in_editscreen)
+{
+}
+
+void
+CSTedScreenBase::GraphicsHome(int in_currenthome)
+{
+}
+
+void
+CSTedScreenBase::ClsAll(void)
+{
+}
+
+void
+CSTedScreenBase::GraphicsClear(void)
+{
+}
+
+// key
+int 
+CSTedScreenBase::KeyInit(void)
+{
+  return 0;
+}
+
+int 
+CSTedScreenBase::KeyIn(int in_code)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::KeyInp(void)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::SftSense(void)
+{
+  return 0;
+}
+
+int 
+CSTedScreenBase::BitSense(int in_group)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::KeySense(void)
+{
+  return 0;
+}
+
+void
+CSTedScreenBase::KeyWait(void)
+{
+}
+
+void
+CSTedScreenBase::LedMode(int in_code, int in_onoff)
+{
+}
+
+void
+CSTedScreenBase::ClearKeyBuffer(void)
+{
+  
+}
+
+void
+CSTedScreenBase::SetFncKey(const char in_fnckey[12][6])
+{
+       int i,j;
+       for (i=0; i<12; i++) {
+               for (j=0; j<6; j++) {
+                       fFncKey[i][j] = in_fnckey[i][j];
+               }
+       }
+}
+
+void
+CSTedScreenBase::SetX68ScanCode(const int* in_codes)
+{
+       fX68ScanCode = in_codes;
+}
+
+// pointer
+void 
+CSTedScreenBase::MouseInit(void)
+{
+}
+
+void
+CSTedScreenBase::SetMouseCursorVisible(int in_onoff)
+{
+}
+
+int 
+CSTedScreenBase::GetMouseButtonState(void)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::SetMouseMoveLimit(int in_x0, int in_y0, int in_x1, int in_y1)
+{
+  return 0;
+}
+
+int
+CSTedScreenBase::GetMousePos(int *out_x, int *out_y)
+{
+  return 0;
+}
+
+void
+CSTedScreenBase::MouseWait(void)
+{
+}
+
+// midi devices
+int
+CSTedScreenBase::OpenMidiDevice(void)
+{
+    return -1;
+}
+
+void
+CSTedScreenBase::CloseMidiDevice(void)
+{
+}
+
+int
+CSTedScreenBase::GetMidiData(void)
+{
+    return -1;
+}
+
+int
+CSTedScreenBase::CanMidiRead(void)
+{
+    return 0;
+}
+
+void
+CSTedScreenBase::PutMidiData(int in_data)
+{
+}
+
+void
+CSTedScreenBase::MidiWait(void)
+{
+}
+
+int
+CSTedScreenBase::StartMidiPlayer(unsigned char* in_data, int in_len)
+{
+       return -1;
+}
+
+int
+CSTedScreenBase::StopMidiPlayer(void)
+{
+       return -1;
+}
+
+int
+CSTedScreenBase::CloseMidiPlayer(int in_sig)
+{
+       return -1;
+}
+
+void
+CSTedScreenBase::MidiPlayerWait(void)
+{
+}
+
+// file related
+dosmode_t
+CSTedScreenBase::FileChmod(const char* in_name, dosmode_t in_atr)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileChdir(const char* in_name)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileCurdir(int in_drive, char* out_buff)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileCurdrv(void)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileDelete(const char* in_name)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileRename(const char* in_name, const char* in_newname)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileFiles(struct _x68_filbuf *in_buff, const char *in_name, int in_atr)
+{
+    return 0;
+}
+
+int
+CSTedScreenBase::FileNfiles(struct _x68_filbuf *in_buff)
+{
+    return 0;
+}
+
+FILE*
+CSTedScreenBase::FileFopen(const char* in_name, const char* in_mode)
+{
+    return NULL;
+}
+
+// misc functions
+int
+CSTedScreenBase::OnTime(void)
+{
+       return 0;
+}
+
+int
+CSTedScreenBase::USleep(long in_usec)
+{
+       return 0;
+}
+
+void
+CSTedScreenBase::DisableUpdateWindow(void)
+{
+}
+
+void
+CSTedScreenBase::UpdateWindow(void)
+{
+       return;
+}
diff --git a/sted_screen.h b/sted_screen.h
new file mode 100644 (file)
index 0000000..9e7f16e
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+  sted_screen.h
+  base class of screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#pragma once
+
+#ifndef STED_SCREEN_H
+#define STED_SCREEN_H
+
+#include <stdio.h>
+
+#ifndef __dosmode_t_defined__
+#define __dosmode_t_defined__
+typedef int dosmode_t;
+#endif
+
+enum {
+  EButtonLeft = 0,
+  EButtonRight
+};
+
+enum {
+  EButtonOff = 0,
+  EButtonOn
+};
+
+class CSTedScreenBase {
+ protected:
+  CSTedScreenBase();
+  void Construct(void);
+
+ public:
+  static CSTedScreenBase* New(void);
+  virtual ~CSTedScreenBase();
+  virtual void Tidy(void);
+
+  // window
+  virtual void InitWindow(void);
+  virtual void CloseWindow(void);
+  virtual void RepaintWindow(void);
+  virtual void UpdateWindow(void);
+  virtual void DisableUpdateWindow(void);
+
+  // color
+  virtual int SetGraphicsPalette(int in_pal, int in_color);
+  virtual int SetTextPalette(int in_pal, int in_color);
+  virtual int SetGraphicsColor(int in_color);
+  virtual int SetTextColor(int in_color);
+  
+  // cursor
+  virtual void SetCursor(int in_onoff);
+
+  // text
+  virtual void SetTextWindow(int in_y, int in_h);
+  virtual void Locate(int in_x, int in_y);
+  virtual void Puts(const char* in_str);
+  virtual void ClsEol(void);
+  virtual void ClsEd(void);
+  virtual void GraphicsPuts(int in_x, int in_y, const char* in_str);
+
+  // graphics
+  virtual void TextXBox(int in_x0, int in_y0, int in_x1, int in_y1, int in_page);
+  virtual void TextXXLine(int in_page, int in_x0, int in_y, int in_x1, int in_linestyle);
+  virtual void TextXYLine(int in_page, int in_x, int in_y0, int in_y1, int in_linestyle);
+  virtual void TextReverse(int in_x, int in_y, int in_width, int in_page);
+  virtual void TextReverseArea(int in_r_ad, int r_ln, int in_edit_scr);
+  virtual void TextFill(int in_page, int in_x, int in_y, int in_w, int in_h, int in_linestyle);
+  virtual void TextRasterCopy(int in_dst, int in_src, int in_line, int in_mode);
+  virtual void TextScroll(int in_x0, int in_y0, int in_xs, int in_ys, int in_x1, int in_y1);
+
+  virtual void GraphicsBox(int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_color, unsigned int in_linestyle);
+  virtual int GraphicsPoint(int in_x, int in_y);
+  virtual void GraphicsLine(int in_x0, int in_y0, int in_x1, int in_y1, int in_color, int in_linestyle);
+  virtual void GraphicsFill(int in_x0, int in_y0, int in_x1, int in_y1, int in_color);
+
+  virtual void CopyTextToGraphics(int in_editscreen);
+  virtual void CopyTextToGraphics2(int in_editscreen);
+
+  virtual void GraphicsHome(int in_currenthome);
+  virtual void ClsAll(void);
+  virtual void GraphicsClear(void);
+
+  // key
+  virtual int KeyInit(void);
+  virtual int KeyIn(int in_code);
+  virtual int KeyInp(void);
+  virtual int SftSense(void);
+  virtual int BitSense(int in_group);
+  virtual int KeySense(void);
+  virtual void KeyWait(void);
+  virtual void LedMode(int in_code, int in_onoff);
+  virtual void ClearKeyBuffer(void);
+  void SetFncKey(const char in_fnckey[12][6]);
+  void SetX68ScanCode(const int* in_codes);
+
+  // pointer
+  virtual void MouseInit(void);
+  virtual void SetMouseCursorVisible(int in_onoff);
+  virtual int GetMouseButtonState(void);
+  virtual int SetMouseMoveLimit(int in_x0, int in_y0, int in_x1, int in_y1);
+  virtual int GetMousePos(int *out_x, int *out_y);
+  virtual void MouseWait(void);
+
+  // midi devices
+  virtual int OpenMidiDevice(void);
+  virtual void CloseMidiDevice(void);
+  virtual int GetMidiData(void);
+  virtual int CanMidiRead(void);
+  virtual void PutMidiData(int in_data);
+  virtual void MidiWait(void);
+  virtual void MidiPlayerWait(void);
+
+  // midi players
+  virtual int StartMidiPlayer(unsigned char* in_data, int in_len);
+  virtual int StopMidiPlayer(void);
+  virtual int CloseMidiPlayer(int in_sig);
+
+  // file related
+  virtual dosmode_t FileChmod(const char* in_name, dosmode_t in_atr);
+  virtual int FileChdir(const char* in_name);
+  virtual int FileCurdir(int in_drive, char* out_buff);
+  virtual int FileCurdrv(void);
+  virtual int FileDelete(const char* in_name);
+  virtual int FileRename(const char* in_name, const char* in_newname);
+  virtual int FileFiles(struct _x68_filbuf *in_buff, const char *in_name, int in_atr);
+  virtual int FileNfiles(struct _x68_filbuf *in_buff);
+  virtual FILE* FileFopen(const char* in_name, const char* in_mode);
+
+  // misc functions
+  virtual int OnTime(void);
+  virtual int USleep(long in_usec);
+
+ protected:
+  bool fConstructed;
+  int fFncKey[12][6];
+  const int *fX68ScanCode;
+};
+
+/* accessor */
+ CSTedScreenBase* CreateScreenDriver(int in_size);
+// void DestroyScreenDriver(CSTedScreenBase* in_driver);
+
+ CSTedScreenBase* GetDriver(void);
+
+#endif /* STED_SCREEN_H */
diff --git a/sted_screen_win32.h b/sted_screen_win32.h
new file mode 100644 (file)
index 0000000..19d6def
--- /dev/null
@@ -0,0 +1,390 @@
+/*
+  sted_screen_win32.h
+  win32 screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+*/
+#pragma once
+
+#ifndef STED_SCREEN_WIN32_H
+#define STED_SCREEN_WIN32_H
+
+#include <windows.h>
+#include <comdef.h>
+#include <wincodec.h>
+#include <wincodecsdk.h>
+#include <d2d1.h>
+#include <d2d1helper.h>
+#include <dwrite.h>
+#include "avrt.h"
+#include <mmsystem.h>
+#include "sted_screen.h"
+#include "exception.h"
+#include "sf_windows.h"
+
+/** RGB構造体 */
+struct STED_RGB {
+  int fRed;
+  int fGreen;
+  int fBlue;
+};
+
+enum {
+  EShift = 0,
+  EControl,
+  EOPT1,
+  EOPT2,
+  EXF1,
+  EXF2,
+  EXF3,
+  EXF4,
+  EXF5,
+  EKana,
+  EKigo,
+  EToroku,
+  EInsert,
+  EDel,
+  EHome,
+  EUndo,
+  ERollUp,
+  ERollDown,
+  EF1,
+  EF2,
+  EF3,
+  EF4,
+  EF5,
+  EF6,
+  EF7,
+  EF8,
+  EF9,
+  EF10,
+};
+
+#define MASK_ON fBrushMaskOn
+#define MASK_OFF fBrushMaskOff
+
+#define IDT_STED2_WAIT_TIMER   1
+
+
+class CSTedScreenWin32 : public CSTedScreenBase,public sf::base_window
+{
+public:
+       typedef boost::shared_ptr<CSTedScreenWin32> ptr_type;
+
+       friend int APIENTRY WinMain(HINSTANCE hInstance,
+                     HINSTANCE hPrevInstance,
+                     LPSTR    lpCmdLine,
+                     int       nCmdShow);
+private:
+
+       CSTedScreenWin32(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width,float height);
+       void Construct(int in_screensize = 14);
+
+       static void init_instance();
+
+public:
+
+       virtual LRESULT window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam);
+
+       static ptr_type& instance()
+       {
+               return instance_;
+       }
+
+       //static CSTedScreenWin32* New(int in_screensize=14);
+       ~CSTedScreenWin32();
+       void Tidy(void);
+
+       // window
+       void InitWindow(void);
+       void CloseWindow(void);
+       void RepaintWindow(void);
+       void UpdateWindow(void);
+       void DisableUpdateWindow(void);
+
+       // color
+       int SetGraphicsPalette(int in_pal, int in_color);
+       int SetTextPalette(int in_pal, int in_color);
+       int SetGraphicsColor(int in_color);
+       int SetTextColor(int in_color);
+  
+       // cursor
+       void SetCursor(int in_onoff);
+
+       // text
+       void Locate(int in_x, int in_y);
+       void Puts(const char* in_str);
+       void ClsEol(void);
+       void ClsEd(void);
+       void SetTextWindow(int in_y, int in_h);
+       void GraphicsPuts(int in_x, int in_y, const char* in_str);
+
+       // graphics
+       void TextXBox(int in_x0, int in_y0, int in_x1, int in_y1, int in_page);
+       void TextXXLine(int in_page, int in_x0, int in_y, int in_x1, int in_linestyle);
+       void TextXYLine(int in_page, int in_x, int in_y0, int in_y1, int in_linestyle);
+       void TextReverse(int in_x, int in_y, int in_width, int in_page);
+       void TextReverseArea(int in_r_ad, int in_r_ln, int in_edit_scr);
+       void TextFill(int in_page, int in_x, int in_y, int in_w, int in_h, int in_linestyle);
+       void TextRasterCopy(int in_dst, int in_src, int in_line, int in_mode);
+       void TextScroll(int in_x0, int in_y0, int in_xs, int in_ys, int in_x1, int in_y1);
+
+       void GraphicsBox(int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_color, unsigned int in_linestyle);
+       int GraphicsPoint(int in_x, int in_y);
+       void GraphicsLine(int in_x0, int in_y0, int in_x1, int in_y1, int in_color, int in_linestyle);
+       void GraphicsFill(int in_x0, int in_y0, int in_x1, int in_y1, int in_color);
+
+       void CopyTextToGraphics(int in_editscreen);
+       void CopyTextToGraphics2(int in_editscreen);
+
+       void GraphicsHome(int in_currenthome);
+       void ClsAll(void);
+       void GraphicsClear(void);
+
+       // key
+       int KeyInit(void);
+       int KeyIn(int in_code);
+       int KeyInp(void);
+       int SftSense(void);
+       int BitSense(int in_group);
+       int KeySense(void);
+       void KeyWait(void);
+       void LedMode(int in_code, int in_onoff);
+       void ClearKeyBuffer(void);
+
+       // pointer
+       void MouseInit(void);
+       void SetMouseCursorVisible(int in_onoff);
+       int GetMouseButtonState(void);
+       int SetMouseMoveLimit(int in_x0, int in_y0, int in_x1, int in_y1);
+       int GetMousePos(int *out_x, int *out_y);
+       void MouseWait(void);
+
+       // midi related
+       BOOL SetMidiPorts(int in_min, int* in_mout);
+       int OpenMidiDevice(void);
+       void CloseMidiDevice(void);
+       int GetMidiData(void);
+       int CanMidiRead(void);
+       void PutMidiData(int in_data);
+       void MidiWait(void);
+       void MidiPlayerWait(void);
+
+       // midi player
+       int StartMidiPlayer(unsigned char* in_data, int in_len);
+       int StopMidiPlayer(void);
+       int CloseMidiPlayer(int in_sig);
+
+       // file related
+       dosmode_t FileChmod(const char* in_name, dosmode_t in_atr);
+       int FileChdir(const char* in_name);
+       int FileCurdir(int in_drive, char* out_buff);
+       int FileCurdrv(void);
+       int FileDelete(const char* in_name);
+       int FileRename(const char* in_name, const char* in_newname);
+       int FileFiles(struct _x68_filbuf *in_buff, const char *in_name, int in_atr);
+       int FileNfiles(struct _x68_filbuf *in_buff);
+       FILE* FileFopen(const char* in_name, const char* in_mode);
+
+       // misc
+       int OnTime(void);
+       int USleep(long in_usec);
+
+public:
+
+       void Paint(RECT *in_rect,HDC dc);
+       void NotifyPointerPosition(int in_x, int in_y, int in_wparam);
+       void NotifyPointerButtonState(int in_button, int in_state);
+       void NotifyKeyPressed(int in_key);
+       void NotifyKeyReleased(int in_key);
+       void NotifyChar(int in_char);
+       void NotifyMidiIn(unsigned long in_data);
+       void NotifyTimer(UINT in_timerid);
+
+       LPCTSTR toUCS2(const char* in_str, int *out_len);
+       LPCTSTR toUCS2(const char* in_str, int in_len, int *out_len);
+       const char* toSJIS(LPCTSTR in_str, int *out_len);
+       
+  virtual void discard_device();
+       virtual void create_device();
+  virtual void create_device_independent_resources();
+private:
+
+       void DoMessageLoop(void);
+       void DrawCursor(void);
+       void InvalidateRect(const RECT* in_rect);
+       void InvalidateRect(const int in_x, const int in_y, const int in_w, const int in_h);
+       int GetTextWidth(LPCTSTR in_str, int in_len);
+       BOOL CheckKeyBuffer(int in_key);
+
+       BOOL TextToWindowPos(int *out_x, int *out_y);
+       BOOL TextToWindowPos(int in_text_x, int in_text_y, int *out_x, int *out_y);
+       BOOL toWindowPos(int in_x, int in_y, int *out_x, int *out_y);
+
+       COLORREF PageToColor(int in_page);
+
+       int ConvertWinKeyToX68Key(int in_key);
+       BOOL ConvertWinKeyToX68Key(int in_key, int* out_ascii, int* out_code);
+
+       void AppendMidiData(int in_c);
+
+       // メンバ変数
+       
+       //HBITMAP fText;
+       //HBITMAP fTextMask;
+       //HBITMAP fGraphicsWindow[2];
+       //HBITMAP fOffScreen;
+
+       ID2D1BitmapRenderTargetPtr text_bitmap_target_;
+  ID2D1GdiInteropRenderTargetPtr text_dc_target_;
+       //ID2D1BitmapRenderTargetPtr text_mask_bitmap_target_;
+       ID2D1BitmapRenderTargetPtr graphics_bitmap_target_[2];
+  ID2D1GdiInteropRenderTargetPtr graphics_dc_target_[2];
+       //ID2D1BitmapRenderTargetPtr offscreen_bitmap_target_;
+//     ID2D1BitmapRenderTargetPtr text_bitmap_target_;
+
+       // HBitMapをそのままID2D1BitmapRenderTargetにする。
+
+       BOOL fOffScreenIsDirty;
+       RECT fInvalidRect;
+       BOOL fCanUpdateWindow;
+
+       // HWND fWindow;
+
+       // メニューハンドル
+       HMENU fMenu;
+
+  
+  //HDC fTextDC;
+       //HDC fTextMaskDC;
+       //HDC fGraphicsWindowDC[2];
+       //HDC fOffScreenDC;
+       //HDC fWindowDC;
+
+  int fCurrentTextX;
+       int fCurrentTextY;
+       int fTextOriginY;
+       int fTextHeight;
+
+       BOOL fIsCursorOn;
+
+       int fCurrentGraphics;
+
+       int fWindowWidth;
+       int fWindowHeight;
+       int fTextLineHeight;
+
+  static const int fX68WindowWidth = 768;
+       static const int fX68WindowHeight = 512;
+       static const int fX68TextWidth = 96;
+       static const int fX68TextHeight = 32;
+
+       LPTSTR fUCS2Buf;
+       char* fSJISBuf;
+
+       static const int fUCS2BufLen = 1024;
+       static const int fSJISBufLen = 1024;
+
+       STED_RGB fTextPalette[4];
+       STED_RGB fGraphicsPalette[32];
+
+       static const int fMaxGraphicsColor = 32;
+       static const int fMaxTextColor = 4;
+       int fCurrentTextColor;
+       int fCurrentTextBackColor;
+       int fCurrentGraphicsColor;
+
+       //HBRUSH fBrushMaskOff;
+       //HBRUSH fBrushMaskOn;
+       //HBRUSH fBrushClear;
+       //HBRUSH fBrushTextClear;
+  IDWriteTextFormatPtr text_fmt_;
+  
+  ID2D1SolidColorBrushPtr brush_mask_off_;
+  ID2D1SolidColorBrushPtr brush_mask_on_;
+  ID2D1SolidColorBrushPtr brush_clear_;
+  ID2D1SolidColorBrushPtr brush_text_clear_;
+  ID2D1SolidColorBrushPtr brush_text_;
+
+       // pointers
+       int fPointerMinX;
+       int fPointerMaxX;
+       int fPointerMinY;
+       int fPointerMaxY;
+       int fCurrentPointerX;
+       int fCurrentPointerY;
+       int fCurrentPointerButtonStateL;
+       int fCurrentPointerButtonStateR;
+
+       BOOL fPointerEventNotified;
+
+       // key
+       static const int fKeyBufferLen = 1024;
+       int fKeyBuffer[1024];
+       int fKeyBufferStartPtr;
+       int fKeyBufferEndPtr;
+       int fKeyBufferAvailable;
+
+       BOOL fKeyShiftPressed;
+       BOOL fKeyControlPressed;
+       BOOL fKeyOPT1Pressed;
+       BOOL fKeyOPT2Pressed;
+       BOOL fKeyKanaPressed;
+       BOOL fKeyInsertPressed;
+
+       BOOL fKeyEventNotified;
+
+       int fKeyConv[1024];
+
+       // midi
+       HMIDIIN fMidiInDevice;
+       HMIDIOUT fMidiOutDevice[2];
+       int fMidiInPort;
+       int fMidiOutPort[2];
+       static const int fMidiOutPorts=2;
+       static const int fMidiBufferLen = 4096;
+       int fMidiBuffer[4096];
+       int fMidiBufferStartPtr;
+       int fMidiBufferEndPtr;
+       int fMidiBufferAvailable;
+       int fMidiOutPacket[4];
+       unsigned char fMidiExclusiveBuf[4096];
+       static const int fMidiExclusiveBufLen = 4096;
+       int fMidiOutCurrentPort;
+
+       BOOL fTimerEventNotified;
+
+       // file
+       HANDLE fFileDirHandle;
+
+       // アクセラレータ
+       HACCEL accel_;
+
+       static ptr_type instance_;
+
+};
+
+#define THROW_IF_ERR(hres) \
+  if (FAILED(hres)) { throw sf::win32_error_exception(hres); }
+
+
+
+#endif /* STED_SCREEN_H */
diff --git a/sted_vals.cpp b/sted_vals.cpp
new file mode 100644 (file)
index 0000000..5767131
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+  sted_vals.h
+  */
+
+#ifndef STED_VALS_H
+#define STED_VALS_H
+
+//char hlp_path[128];                  /* help file path & name        */
+//char fon_path[128];                  /* font file path & name        */
+//
+//char def_path[128];                  /* .def path name               */
+//char rcp_path[128];                  /* .rcp path name               */
+//char prt_path[128];                  /* .prt path name               */
+//char trk_path[128];                  /* .trk path name               */
+//
+//char def_file[128];                  /* .def file name               */
+//char rcp_file[128];                  /* .rcp file name               */
+//char prt_file[128];                  /* .prt file name               */
+//char trk_file[128];                  /* .trk file name               */
+//
+//char repl[128];                      /* replace string               */
+//char delt[128];                      /* delete string                */
+//char srch[128];                      /* find string                  */
+//
+//char repl_t[26*6][40];
+//char repl_d[26*6][50];
+//
+//int  tr_step[36];                    /* track total step temp        */
+//int  tr_alc[36];                     /* track aloc size              */
+//int  tr_len[36];                     /* track used size              */
+//int  tr_pos[36][2][4];               /* track cursor position        */
+//int  tag[26+2][4];                   /* tag jamp list buffer         */
+//
+//int  es,ecode,scyp;                  /* input subroutine exit code   */
+//
+//int  btrack;                         /* track set top track          */
+//int  track,track1,track2;            /* edit track no.               */
+//int  edit_scr;                       /* 0=l_track 1=r_track 2=rhythm */
+//int  cmdflag,cnfflag,mdlflag;        /* STed2 system flag            */
+//int  poft;
+//
+//int  TRACK_SIZE,work_size;           /* buffer size                  */
+//int  buff_size,buff_free,buff_max;
+//int  cpcy,cpadd,cplen;
+//int  cpleng,rcpf,rcplen;             /* copy flag                    */
+//
+//void *ErrorTrap_Old;                 /* err trap vecter/flag         */
+//int  ErrFlag;
+//
+///* cnf */
+//char comment[64];                    /* comment                      */
+//
+//int  tm_lag=5000;                            /* graphic rewrite time lag     */
+//char inpmode;                        /* editor input mode            */
+//char grpmode;                        /* editor graphic mode          */
+//char thrumode;                       /* edit midi in thru mode       */
+//int  rec_getch,rec_putmd;            /* recoding ch./put mode        */
+//int  vis_reso;                       /**/
+//
+//unsigned char        rfilt[32][4];           /* record filter */
+//unsigned char        pfilt[32][4];           /* play   filter */
+//
+//char mplay[16][16];
+//int  palet_dat[16];
+//
+//unsigned char        keyst_table[2][128];    /* key# -> st/gt convert table  */
+//unsigned char        stgt_tbl[60];           /* f.key -> st/gt table         */
+//
+//char rhy_vel[16];
+//
+//char chcom_s[26*2][2][50];           /* child command comment        */
+//char chcom_c[26*2][2][16];           /* child command parameter      */
+//
+///* def */
+//char module[64];                     /* module name                  */
+//
+//int  lsp_wait;                       /* last para. transfer wait     */
+//int  bend_range;                     /* piche bend range             */
+//
+//char tim_asin[33];                   /* tone list channle assign     */
+//char tim_head[400][24];              /* tone list title              */
+//char tim_sym[400][8];                /* tone list symbol             */
+//char tim_name[80*128][15];           /* tone name buffer             */
+//short        tim_top[400];                   /* tone name buffer address     */
+//
+//char card_name[21][64];              /* pcm card name list           */
+//char card_no[2];                     /* used pcm card no.            */
+//
+//short        gs_bank[18*128];                /* gs bank part no.(8+1 group)  */
+//short        gs_mode[18];                    /* gs bank mode    (8+1 group)  */
+//
+//char rhy_stest[8];                   /* rhythm sound test ch. & para */
+//char rec_met[10];                    /* recording metoro tone        */
+//
+//unsigned char        init_exc_data[258];     /* init exclusive data          */
+//
+///*** rcp format head parameter ***/
+//char mtitle[65];                     /* music title                  */
+//char memo[12][29];                   /* memo                         */
+//int  tbase,mtempo;
+//int     beat1,beat2,bkey,pbias;              /* common parameter             */
+//char cm6_file[128],gsd_file[128];    /* controol file name           */
+//
+//char rhyna[32][15];                  /* rhythm assign name           */
+//unsigned char        rhyno[32][2];           /* rhythm assign key & gate     */
+//
+//char user_exc_memo[8][25];           /* user exclusive memo          */
+//unsigned char        user_exc_data[8][24];   /* user exclusive data          */
+//
+//unsigned char        trno[36];               /* track no.                    */
+//unsigned char        trmod[36];              /* track play mode              */
+//unsigned char        trrhy[36];              /* track rhythm sw.             */
+//unsigned char        mch[36];                /* track midi ch.               */
+//unsigned char        trkey[36];              /* track key shift              */
+//unsigned char        trst[36];               /* track st shift               */
+//char trkmemo[36][37];                /* track comment                */
+//
+///* buffer */
+//unsigned char        lcbuf[1024*4+4];        /* delete line buffer           */
+//unsigned char        rlcbuf[132];            /* delete rhythm line buffer    */
+//unsigned char        cm6[22601],gsd[4096];   /* control file buffer          */
+//unsigned char        hed[1414];              /* rcp header temporary         */
+//
+//unsigned char        *trk[36];               /* track buffer pointer         */
+//unsigned char        *cpbuf;                 /* track copy buffer            */
+//unsigned char        *rcpbuf;                /* rhythm track copy buffer     */
+//unsigned char        *dat;                   /* temporary & recording buffer */
+//unsigned char        *dat2;                  /* temporary                    */
+//
+///* misc */
+//char rcd_version[5];
+//char euc_text[1024];
+//char midi_port_name[1024];
+//char font_name[1024];
+//char player_name[1024];
+//
+//int eucenv = 0;
+//int issted3 = 0;
+//int isconsole = 0;
+//int player_flag = 0;
+
+
+
+#endif /* STED_VALS_H */
diff --git a/sted_win32.h b/sted_win32.h
new file mode 100644 (file)
index 0000000..090a64e
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+  sted_win32.h
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#pragma once
+
+#ifndef STED_WIN32_H
+#define STED_WIN32_H
+
+#include <windows.h>
+
+// accessor
+// HWND STedGetWindow(void);
+// HMENU STedGetMenu(void);
+// HDC STedGetWindowDC(void);
+// HINSTANCE STedGetAppInstance(void);
+// HACCEL STedGetAccelTable(void);
+
+#endif /* STED_WIN32_H */
diff --git a/track.cpp b/track.cpp
new file mode 100644 (file)
index 0000000..1453009
--- /dev/null
+++ b/track.cpp
@@ -0,0 +1,952 @@
+/*
+ * STed: track.c (track subroutine)
+ */
+#include       "sted.h"
+
+
+/***************************/
+int    trk_mix_sub(unsigned char *in1,unsigned char *in2)
+{
+  int  ad1=0,ad2=0,po=0,st1=0,st2=0,ef1=0,ef2=0,lsad=-1;
+  unsigned char        a1,a2,b1,b2,c1,c2,d1,d2;
+
+  while(po<TRACK_SIZE){
+
+    if(st1==st2){
+      if(st1){
+       if(lsad>=0 && dat[lsad]<0xf0 && dat[lsad+1]+st1<=240){
+         dat[lsad+1]+=st1;
+       }else{
+         lsad=po;
+         dat[po++]=0;dat[po++]=st1;
+         dat[po++]=0;dat[po++]=0;
+       }
+       st1=0;st2=0;
+      }
+    }else{
+      if(st1>st2){
+       if(st2){
+         if(lsad>=0 && dat[lsad]<0xf0 && dat[lsad+1]+st2<=240){
+           dat[lsad+1]+=st2;
+         }else{
+           lsad=po;
+           dat[po++]=0;dat[po++]=st2;
+           dat[po++]=0;dat[po++]=0;
+         }
+         st1-=st2;st2=0;
+       }
+      }else{
+       if(st1){
+         if(lsad>=0 && dat[lsad]<0xf0 && dat[lsad+1]+st1<=240){
+           dat[lsad+1]+=st1;
+         }else{
+           lsad=po;
+           dat[po++]=0;dat[po++]=st1;
+           dat[po++]=0;dat[po++]=0;
+         }
+         st2-=st1;st1=0;
+       }
+      }
+    }
+
+
+    if(ef1==1 && ef2==1){break;}
+
+    if(ef2){
+      if(st1){
+       if(lsad>=0 && dat[lsad]<0xf0 && dat[lsad+1]+st1<=240){
+         dat[lsad+1]+=st1;
+       }else{
+         lsad=po;
+         dat[po++]=0;dat[po++]=st1;
+         dat[po++]=0;dat[po++]=0;
+       }
+       st1=0;st2=0;
+      }
+      while(in1[ad1]<0xfe && po<TRACK_SIZE){
+       dat[po++]=in1[ad1++];dat[po++]=in1[ad1++];
+       dat[po++]=in1[ad1++];dat[po++]=in1[ad1++];
+      }
+      break;
+    }
+    if(ef1){
+      if(st2){
+       if(lsad>=0 && dat[lsad]<0xf0 && dat[lsad+1]+st2<=240){
+         dat[lsad+1]+=st2;
+       }else{
+         lsad=po;
+         dat[po++]=0;dat[po++]=st2;
+         dat[po++]=0;dat[po++]=0;
+       }
+       st1=0;st2=0;
+      }
+      while(in2[ad2]<0xfe && po<TRACK_SIZE){
+       dat[po++]=in2[ad2++];dat[po++]=in2[ad2++];
+       dat[po++]=in2[ad2++];dat[po++]=in2[ad2++];
+      }
+      break;
+    }
+
+
+    if(st1==0){
+      a1=in1[ad1++];b1=in1[ad1++];c1=in1[ad1++];d1=in1[ad1++];
+
+      if(a1==0x98 || a1==0xf6){
+       lsad=po;
+       dat[po++]=a1;dat[po++]=0;
+       dat[po++]=c1;dat[po++]=d1;
+
+       while(in1[ad1]==0xf7 && po<TRACK_SIZE){
+         dat[po++]=in1[ad1++];dat[po++]=in1[ad1++];
+         dat[po++]=in1[ad1++];dat[po++]=in1[ad1++];
+       }
+      }else{
+       if(a1==0xfe){ef1=1;}
+       if(a1<0xfe){
+         if(a1<0xf0){
+           if(a1>=0x80 || (c1!=0 && d1!=0)){
+             lsad=po;
+             dat[po++]=a1;dat[po++]=0;
+             dat[po++]=c1;dat[po++]=d1;
+           }
+         }else{
+           if(a1==0xfd && po!=0){
+             if(dat[po-4]<0xf0 && dat[po-3]==0){
+               dat[po  ]=dat[po-4];dat[po+1]=dat[po-3];
+               dat[po+2]=dat[po-2];dat[po+3]=dat[po-1];
+
+               dat[po-4]=0xfd;
+               lsad=po;
+               po+=4;
+             }else{
+               dat[po]=0xfd;
+               lsad=-1;
+               po+=4;
+             }
+           }else{
+             lsad=-1;
+             dat[po++]=a1;dat[po++]=b1;
+             dat[po++]=c1;dat[po++]=d1;
+             b1=0;
+           }
+         }
+       }
+      }
+      if(a1<0xf0){st1+=b1;}
+    }
+
+    if(st2==0){
+      a2=in2[ad2++];b2=in2[ad2++];c2=in2[ad2++];d2=in2[ad2++];
+
+      if(a2==0x98 || a2==0xf6){
+       lsad=po;
+       dat[po++]=a2;dat[po++]=0;
+       dat[po++]=c2;dat[po++]=d2;
+
+       while(in2[ad2]==0xf7 && po<TRACK_SIZE){
+         dat[po++]=in2[ad2++];dat[po++]=in2[ad2++];
+         dat[po++]=in2[ad2++];dat[po++]=in2[ad2++];
+       }
+      }else{
+       if(a2==0xfe){ef2=1;}
+       if(a2<0xfd){
+         if(a2<0xf0){
+           if(a2>=0x80 || (c2!=0 && d2!=0)){
+             lsad=po;
+             dat[po++]=a2;dat[po++]=0;
+             dat[po++]=c2;dat[po++]=d2;
+           }
+         }else{
+           lsad=-1;
+           dat[po++]=a2;dat[po++]=b2;
+           dat[po++]=c2;dat[po++]=d2;
+           b2=0;
+         }
+       }
+      }
+      if(a2<0xf0){st2+=b2;}
+    }
+  }
+  return po;
+}
+
+/***************************/
+int    trk_ext_sub(int tr,char *exbuf)
+{
+  int  po;
+
+  po=same_ext_sub(tr,0,tr_len[tr],0);
+  if(po>TRACK_SIZE){msg(_("Track buffer exhausted."));return 0;}
+  po=repeat_ext((uint8*)exbuf,po);
+  if(po>TRACK_SIZE){msg(_("Track buffer exhausted."));return 0;}
+
+  return po;
+}
+
+/***************************/
+int    repeat_comp(int tr)
+{
+  int  i=0,po=0,ln;
+
+  ln=tr_len[tr];
+  dclr();
+
+  while(i<ln){
+    int ll=0,ii;ii=i;
+    while(trk[tr][ii]<0xf0){ii+=4;ll+=4;}
+
+    if(trk[tr][i]<0xf0 && ll>4){
+      while(ll>0){
+       int blk=4,lpc=0;
+
+       while(blk<ll){
+         int cf=0,ii=i+blk,j;lpc=1;
+         while(cf==0){
+           for(j=0;j<blk;j++){
+             if(trk[tr][i+j]>=0xf0||trk[tr][i+j]!=trk[tr][ii+j]){
+               cf=1;break;
+             }
+           }
+           if(cf==0){lpc++;}
+           ii+=blk;
+         }
+         if((lpc>3)||(lpc>2 && blk>4)||(lpc>1 && blk>8)){
+           goto cv;
+         }
+         blk+=4;
+       }
+
+      cv:
+       if((lpc>3)||(lpc>2 && blk>4)||(lpc>1 && blk>8)){
+         int j;
+         trk[tr][po]=0xf9;po+=4;
+         for(j=0;j<blk;j++){trk[tr][po++]=trk[tr][i+blk+j];}
+         trk[tr][po]=0xf8;trk[tr][po+1]=lpc;po+=4;
+         i+=blk*lpc;
+         break;
+       }else{
+         trk[tr][po++]=trk[tr][i++];trk[tr][po++]=trk[tr][i++];
+         trk[tr][po++]=trk[tr][i++];trk[tr][po++]=trk[tr][i++];
+         ll-=4;
+       }
+
+      }
+    }else{
+      trk[tr][po++]=trk[tr][i++];trk[tr][po++]=trk[tr][i++];
+      trk[tr][po++]=trk[tr][i++];trk[tr][po++]=trk[tr][i++];
+    }
+  }
+
+  tr_len[tr]=po;
+  return(po);
+}
+
+/***************************/
+int    repeat_ext(unsigned char *obuf,int ln)
+{
+  int  i,po=0;
+  unsigned char        a,b,c,d;
+
+  i=0;
+  while(i<ln){
+    if(po>=TRACK_SIZE){break;}
+    a=dat[i];b=dat[i+1];c=dat[i+2];d=dat[i+3];
+
+    if(a==0xf8){
+      unsigned char    da;
+      int      co,ad;
+      if(b==0){co=256;}else{co=b;}
+      if(co>=255){goto skip;}
+      ad=po;da=0;
+      while(ad>0){
+       ad=ad-4;
+       da=obuf[ad];
+       if(da==0xf9){break;}
+      }
+      if(da==0xf9){
+       int     ln,i1,i2;
+       ln=(po-ad)-4;
+       if(ad+ln*co>=TRACK_SIZE){po=TRACK_SIZE;break;}
+       po=ad;
+       for(i2=0;i2<ln;i2++){obuf[ad+i2]=obuf[ad+i2+4];}
+       for(i1=0;i1<co;i1++){
+         for(i2=0;i2<ln;i2++){obuf[po]=obuf[ad+i2];po++;}
+       }
+      }else{
+       obuf[po]=a;obuf[po+1]=b;obuf[po+2]=c;obuf[po+3]=d;po=po+4;
+      }
+      if(po>TRACK_SIZE){break;}
+    }else{
+    skip:
+      obuf[po]=a;obuf[po+1]=b;obuf[po+2]=c;obuf[po+3]=d;po=po+4;
+    }
+    i=i+4;
+  }
+  snsclr();
+  return(po);
+}
+
+/***************************/
+int    same_meas_conv(int tr)
+{
+  int  i,j=0,k,match,count=0;
+  int  po=0,m_max,ln,co=0,me=0,ad;
+  int  add[2048],add2[1024],len[1024];
+
+  m_max=add_set(tr,add);if(m_max<2){return(1);}
+  undobuf(0);dclr();
+
+  for(i=0;i<tr_len[tr];i=i+4){
+    if(trk[tr][i]<128){
+      if(trk[tr][i+2]==0||trk[tr][i+3]==0){
+       trk[tr][i]=0;trk[tr][i+2]=0;trk[tr][i+3]=0;
+      }
+    }
+  }
+
+  msg(_("SAME MEAS converting ..."));
+  
+  for(i=0;i<m_max;i++){
+    if(i<2048){po=add[i];}else{po=meas_add(i+1);}
+    ln=meas_len(po);match=0;
+    if(ln>4 && trk[tr][po+ln-4]==0xfc){ln=ln-4;}
+
+    if(trk[tr][po]<0xfc && me>0){
+      j=0;while(j<me ){
+       if(ln==len[j] && dat[add2[j]]<0xfc){
+         match=1;ad=add2[j];
+         k=0;while(k<ln){
+           if(trk[tr][po+k]!=dat[ad]){match=0;break;}
+           k++;ad++;
+         }
+       }
+       if(match!=0){break;}
+       j++;
+      }
+    }
+    if(match!=0 && j<1024 && add2[j]<65536-44){
+      if(me<1024){add2[me]=co;len[me]=4;me++;}
+      dat[co]=0xfc;dat[co+1]=j&0xff;dat[co+2]=j>>8;co=co+4;count++;
+    }else{
+      if(me<1024){add2[me]=co;len[me]=ln;me++;}
+      for(k=0;k<ln;k++){dat[co]=trk[tr][po];po++;co++;}
+    }
+  }
+  dat[co]=0xfe;co=co+4;
+
+  for(i=0;i<co;i=i+4){
+    if(dat[i]==0xfc){
+      j=add2[dat[i+1]+(dat[i+2]&3)*256];
+      if(dat[j]==0xfc){dat[i+1]=dat[j+1];dat[i+2]=dat[j+2];}
+    }
+  }
+
+  if(size_change(tr,co+4)){return(0);}
+
+  memcpy_l(trk[tr],dat,co);
+  tr_len[tr]=co;
+
+  if(count>0){
+    msg(fstr(count,4));B_PRINT(_(" measures are converted."));
+  }else{
+    msg(_("No repeated measures."));
+  }
+  snsclr();
+  return(0);
+}
+
+/***************************/
+int    same_ext_sub(int tr,int p1,int p2,int md)
+{
+  int  i,po=0,ad,max,count=0;
+  unsigned char        a,b,c,d;
+  int  add[2048];
+
+  max=add_set(tr,add);
+
+  i=p1;
+  while(i<p2){
+    if(po>=work_size){break;}
+    a=trk[tr][i];b=trk[tr][i+1];c=trk[tr][i+2];d=trk[tr][i+3];
+    if(a==0xfc && b+(c&3)*256<max){
+    next:                      ad=add[b+(c&3)*256];
+    if(i==ad){
+      if(po>0 && dat[po-4]<0xfc){dat[po]=0xfd;po+=4;}
+      a=0xfd;goto skip;}
+    if(trk[tr][ad]==0xfc){
+      b=trk[tr][ad+1];c=trk[tr][ad+2];
+      if(ad==add[b+(c&3)*256]){goto skip;}
+      goto next;
+    }
+
+    while(trk[tr][ad]<0xfc){
+      if(po>=work_size){po+=4;break;}
+      dat[po]=trk[tr][ad];dat[po+1]=trk[tr][ad+1];
+      dat[po+2]=trk[tr][ad+2];dat[po+3]=trk[tr][ad+3];
+      ad=ad+4;po=po+4;
+    }
+    if(po>work_size){break;}
+    dat[po]=0xfd;po=po+4;count++;
+    }else{
+    skip:
+      dat[po]=a;dat[po+1]=b;dat[po+2]=c;dat[po+3]=d;po=po+4;
+    }
+    i=i+4;
+    if(dat[po-4]<0xfc && trk[tr][i]==0xfc){dat[po]=0xfd;po=po+4;}
+  }
+
+  if(md){
+    if(count>0){
+      msg(fstr(count,4));B_PRINT(_(" measures are extracted."));
+    }else{
+      msg(_("No measures are extracted."));
+    }
+  }
+
+  snsclr();
+  return(po);
+}
+
+/***************************/
+void   trk_opt_sub(int tr,int po1,int po2)
+{
+  unsigned char        *ptr;
+  int  ad,ad2=0,po3;
+  po2+=po1;po3=po2;
+
+  po2=tai_compres(tr,po1,po2);
+
+  ptr=(unsigned char *)trk[tr];
+
+  for(ad=0;ad<tr_len[tr];ad+=4){
+    /*if(ad>=po1 && ad<po2){*/
+    if(ad>po1 && ad<po2){
+      if(ptr[ad]<128 && ptr[ad+1]==0 &&(ptr[ad+2]==0||ptr[ad+3]==0)){goto next;}
+
+      if(ad2>po1 &&
+        (ptr[ad2-4]==0xee || (ptr[ad2-4]==0xeb &&
+                              (ptr[ad2-2]>=7 || ptr[ad2-2]<=11 ))) &&
+
+        ptr[ad2-4]==ptr[ad] && ptr[ad2-2]==ptr[ad+2] &&
+        ptr[ad2-1]==ptr[ad+3] && ptr[ad2-3]+ptr[ad+1]<=240){
+       ptr[ad2-3]+=ptr[ad+1];
+      }else{
+       if(ptr[ad]<128 && (ptr[ad+2]==0 || ptr[ad+3]==0)&& ad2>po1 &&
+          (ptr[ad2-4]!=0xde||(ad2>4 && ptr[ad2-8]==0xde &&
+                              ptr[ad2-4]==0xde && ptr[ad2-6]+1!=ptr[ad2-2]))&&
+
+          (ptr[ad2-4]<0xf0 ||(ptr[ad2-4]<128 &&(ptr[ad2-3]==0||
+                                                ptr[ad2-2]==0||ptr[ad2-1]==0)))&& ptr[ad2-3]+ptr[ad+1]<=240){
+         ptr[ad2-3]+=ptr[ad+1];
+       }else{
+         if(ptr[ad]<128 && (ptr[ad+2]==0 || ptr[ad+3]==0)&& ad2>po1 &&
+            ptr[ad2-4] == 0xf7 ){
+           int cc=ad2-4;
+           while(ptr[cc]==0xf7){cc-=4;}
+
+           if( ptr[cc]!=0x98 ){goto rpls;}
+
+           if( ptr[cc+1]+ptr[ad+1]<=240 ){
+             ptr[cc+1]+=ptr[ad+1];
+           } else {
+             goto rpls;
+           }
+
+         }else{
+         rpls:
+           ptr[ad2]=ptr[ad];ptr[ad2+1]=ptr[ad+1];
+           ptr[ad2+2]=ptr[ad+2];ptr[ad2+3]=ptr[ad+3];
+           ad2+=4;
+         }
+       }
+      }
+    next:
+      if(ad==po2-4){po3=ad2;}
+    }else{
+      ptr[ad2]=ptr[ad];ptr[ad2+1]=ptr[ad+1];
+      ptr[ad2+2]=ptr[ad+2];ptr[ad2+3]=ptr[ad+3];
+      ad2+=4;
+    }
+  }
+  tr_len[tr]=ad2;
+
+}
+
+/***************************/
+int    tai_compres(int tr,int po1,int po2)
+{
+  int  i,ln,ad,ch,po3=po2;
+  unsigned char        a,b,c,d;
+
+  unsigned char        *ptr;
+  ptr=(unsigned char *)trk[tr];
+
+  ch=(mch[tr])&0xff;
+  ad=0;
+
+  ln=tr_len[tr];
+  for(i=0;i<ln;i+=4){
+    a=ptr[i];b=ptr[i+1];c=ptr[i+2];d=ptr[i+3];
+
+    if(i>=po1 && i<po2){
+
+      if(a<128 && c>b && d>0){
+       int cc=ch,ad2,sum;
+       ad2=i;sum=0;
+
+       while(ad2<ln){
+         unsigned char da=ptr[ad2];
+         if(da==0xe6){cc=ptr[ad2+2];}
+
+         if(ad2>i && cc==ch && a==da && ptr[ad2+2]!=0 && ptr[ad2+3]!=0 ){
+           if(sum+ptr[ad2+2]<=255){
+             c=ptr[ad2+2]+sum;
+             /*if(ptr[i+2]<c)*/{
+               ptr[i+2]=c;}
+             ptr[ad2+2]=0;
+             ptr[ad2+3]=0;
+           }else{
+             break;
+           }
+         }
+
+         if(da<0xf0){sum+=ptr[ad2+1];if(sum>255 || sum>=c){break;}}
+
+         if(da>=0xfc||da==0xf8||da==0xf9||da==0xe2||da==0xec){break;}
+         ad2+=4;
+       }
+      }
+
+      if(ptr[i]>=0xfc){ch=-1;}
+
+      if(ptr[i]==0xe6){
+       if(ptr[i+2]==ch){
+         ptr[i]=0;ptr[i+2]=0;ptr[i+3]=0;
+       }else{
+         ch=ptr[i+2];
+
+         if(ad && ptr[ad-4]==0xe6){
+           ptr[ad-2]=ptr[i+2];
+           ptr[i]=0;ptr[i+2]=0;ptr[i+3]=0;
+         }
+       }
+      }
+
+      if(i>po1 && (ptr[i]<0x80 &&(ptr[i+2]==0||ptr[i+3]==0))&&
+        ad>0 && ptr[ad-4]<0xf0 && ptr[ad-3]+ptr[i+1]<=240){
+       ptr[ad-3]+=ptr[i+1];
+      }else{
+       ptr[ad++]=ptr[i];ptr[ad++]=ptr[i+1];
+       ptr[ad++]=ptr[i+2];ptr[ad++]=ptr[i+3];
+      }
+    }else{
+      ptr[ad++]=ptr[i];ptr[ad++]=ptr[i+1];
+      ptr[ad++]=ptr[i+2];ptr[ad++]=ptr[i+3];
+    }
+    if(i==po2-4){po3=ad;}
+  }
+
+  tr_len[tr]=ad;
+  return(po3);
+}
+
+/***************************/
+void   trk_quan(int tr,int po1,int po2)
+{
+  unsigned char        *ptr;
+  int  ad,ad2=0,st=0,rt=0,hf,tt1=0,ofs=0,cf=0;
+
+  ptr=(unsigned char *)trk[tr];
+
+  while(st<2 || st>48){
+    msg("QUANTIZE  RESOLUTION=");st=vinput(6,0x803);
+    if(es!=0){msg_clr();return;}
+  }
+  while(rt<50 || rt>100){
+    B_LOCATE(25,1);B_PRINT("RATE(%)=");rt=vinput(100,0x803);
+    if(es!=0){msg_clr();return;}
+  }
+  hf=st>>1;
+
+  undobuf(0);
+
+  for(ad=0;ad<tr_len[tr];ad+=4){
+    unsigned char a,b,c,d;
+    a=ptr[ad];b=ptr[ad+1];c=ptr[ad+2];d=ptr[ad+3];
+
+    if(ad>=po1 && ad<po2){
+      if(a<0xf0){
+       if(a<0x80){
+         while(tt1>=st){tt1-=st;}
+
+         if(tt1>0){
+           int vt=0,ad3;
+
+           if(tt1<hf || st==2){
+             vt=-((tt1*rt)/100);
+           }else{
+             vt=((st-tt1)*rt)/100;
+           }
+           ad3=ad2;
+           while(vt!=0 && ad3>0){
+             ad3-=4;
+             if(dat[ad3]>=0xfc){break;}
+
+             if(dat[ad3]<0xf0){
+               while(vt<0 && dat[ad3+1]>0){
+                 dat[ad3+1]--;vt++;
+                 ofs++;tt1--;
+               }
+               while(vt>0 && dat[ad3+1]<255){
+                 dat[ad3+1]++;vt--;
+                 ofs--;tt1++;
+               }
+               if(dat[ad3]>=0x80){break;}
+             }
+           }
+         }
+         cf=0;
+       }else{
+         cf+=b;
+       }
+       tt1+=b;
+
+       if(ptr[ad]<0x80 && ptr[ad+1]>0){
+         while(ofs>0 && b<255){b++;tt1++;ofs--;}
+         while(ofs<0 && b>0  ){b--;tt1--;ofs++;}
+       }
+       if(tt1==st){cf=0;}
+      }
+    }
+
+    dat[ad2++]=a;dat[ad2++]=b;dat[ad2++]=c;dat[ad2++]=d;
+
+    if((a>=0xfc || ad+4==po2) && (ofs!=0)){
+      int ad3=ad2-4;
+
+      while(ofs!=0 && ad3>0){
+       ad3-=4;
+       if(dat[ad3]>=0xfc){break;}
+
+       if(dat[ad3]<0xf0){
+         while(ofs<0 && dat[ad3+1]>0){
+           dat[ad3+1]--;ofs++;
+         }
+         while(ofs>0 && dat[ad3+1]<255){
+           dat[ad3+1]++;ofs--;
+         }
+       }
+      }
+    }
+  }
+
+  memcpy_l(trk[tr],dat,ad2);tr_len[tr]=ad2;
+  msg_clr();
+}
+
+/***************************/
+void   note_ctrl(int po1,int po2)
+{
+  int  i,j,k,ad=0,ln=0,md=0,ke,st=0,tr=track;
+  int  stt[256],stt2[256];
+  unsigned char        a,b,c,d;
+
+  unsigned char        *ptr;
+  ptr=(unsigned char *)trk[tr];
+
+  for(i=0;i<256;i++){stt[i]=0;stt2[i]=0;}
+
+  if(cplen<0){
+    int ad=po1,ln;
+    ln=abs(cpadd-ad);if(!(cpadd>ad)){ad=cpadd;}
+    po1=ad;po2=ad+ln;
+  }else{/*po1=ad;*/po2=tr_len[track]-4;}
+
+resel:
+  /*   msg("Mode: Sort(U/D) or Shift(G/S) =");
+       msg("Setting Mode(Line/C/Rnd/O.R/ST,GT O.R) =");
+       */
+  msg("Setting Mode(L/C/R/O/T /U/D/G/S) =");
+
+  /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+  key_wait();
+  ke=B_KEYINP()&0xff;
+
+  if(ke==0x1b){msg_clr();return;}
+  if(ke=='U'||ke=='u'){md=1;}
+  if(ke=='D'||ke=='d'){md=2;}
+  if(ke=='G'||ke=='g'){md=3;}
+  if(ke=='S'||ke=='s'){md=4;}
+
+  if(ke=='L'||ke=='l'){md=16;}
+  if(ke=='C'||ke=='c'){md=17;}
+  if(ke=='R'||ke=='r'){md=18;}
+  if(ke=='O'||ke=='o'){md=19;}
+  if(ke=='T'||ke=='t'){md=20;}
+
+  if(md<=0){goto resel;}
+
+
+  if(md>=16){
+    if(velo_ctrl(po1,po2-po1+4,md-15)!=0){md=0;goto resel;}
+    goto ext;
+  }
+
+
+
+  while((md==3||md==4) &&(st<1||st>256)){
+    msg("SHIFT ST =");
+    st=vinput(0,3);if(es!=0){msg_clr();return;}
+  }
+
+  undobuf(0);
+
+  for(i=po1;i<po2;i=i+4){
+    a=ptr[i];b=ptr[i+1];c=ptr[i+2];d=ptr[i+3];
+
+    if(a<128){
+      if(ln==0){ad=i>>2;}
+      ln++;
+    }
+    if(ln!=0 && (a>127 || (md<3 && a<128 && b>0)||
+                (md>2 && a<128 && b>2)||i==po2-4 )){
+
+      unsigned int     *ptr2=(unsigned int *)ptr+ad,tm;
+
+      if(ln>1){
+       if(md==1 || md==2){
+         if(a<128){ptr[i+1]=0;}
+         for(j=0;j<ln-1;j++){
+           for(k=j+1;k<ln;k++){
+             if((md==1 && ptr2[j]>ptr2[k])||
+                (md==2 && ptr2[j]<ptr2[k])){
+               tm=ptr2[j];
+               ptr2[j]=ptr2[k];
+               ptr2[k]=tm;
+             }
+           }
+         }
+         if(a<128){ptr[i+1]=b;}
+       }else{
+         int ii=i-ln*4 +4 ;
+         bunkatsu(st,ln-1,stt);
+         bunkatsu(st,ln-1,&stt2[1]);
+         for(j=0;j<ln;j++){
+           if(md==3){
+             if(ptr[ii+1]+stt[j]<=240 &&
+                ptr[ii+2]>stt2[j] &&
+                ptr[i +1]>stt[j]){
+               ptr[ii+1]+=stt[j];
+               ptr[ii+2]-=stt2[j];
+               ptr[i +1]-=stt[j];
+               stt2[j+1]+=stt2[j];
+             }
+           }else{
+             if(ptr[ii+1]+stt[j]<=240 &&
+                ptr[i +1]>stt[j]){
+               ptr[ii+1]+=stt[j];
+               ptr[i +1]-=stt[j];
+               stt2[j+1]+=stt2[j];
+             }
+           }
+           ii+=4;
+         }
+       }
+
+      }
+      ln=0;
+    }
+  }
+ext:
+  cplen=0;
+  msg_clr();
+}
+
+/***************************/
+int    velo_ctrl(int ad,int ln,int vmo)
+{
+  int  ct,st=-128,st2=-128,i,cc=0,ke;
+
+  unsigned char        *ptr;
+  ptr=(unsigned char *)trk[track];
+
+  /*   if(cplen<0){
+       ln=abs(cpadd-ad);if(!(cpadd>ad)){ad=cpadd;}
+       }else{return 1;}
+       */
+  if( ln<8 ){return 0;}
+
+  msg("Velocity Setting");
+
+  while((vmo<4 && st<0)||st<-127 || st>127){
+    B_LOCATE(18,1);
+    if(vmo<3){B_PRINT("START=");}else{B_PRINT("LOW=");}
+
+    st=vinput(0,3);if(es!=0){msg_clr();return 0;}
+  }
+  while(st2<0 || st2>127 || (vmo>2 && st2<st)){
+    B_LOCATE(28,1);
+    if(vmo<3){B_PRINT("END=");}else{B_PRINT("HIGH=");}
+    st2=vinput(0,3);if(es!=0){msg_clr();return 0;}
+  }
+
+  undobuf(0);
+
+  ct=-1;
+  for(i=ad;i<ad+ln;i=i+4){
+    if(ptr[i]<128 && ptr[i+2]!=0 && ptr[i+3]!=0){ct++;}
+  }
+  if(ct<2){return 0;}
+
+  st2=(st2-st);
+  for(i=ad;i<ad+ln;i=i+4){
+    if(ptr[i]<128 && ptr[i+2]!=0 && ptr[i+3]!=0){
+      if(st2!=0){
+       if(vmo==1){
+         ptr[i+3]=st+(st2*cc/ct);cc++;
+       }else{
+         if(vmo==2){
+
+           int i2,ct2=0,cc2=0,j2;
+
+           i2=i;
+           while(ptr[i2+1]==0 && ptr[i2+4]<128 && ptr[i2+6]!=0 && ptr[i2+7]!=0){
+             i2+=4;ct2++;
+           }
+           if(ct2>0){
+             for(j2=0;j2<=ct2;j2++){
+               if(ptr[i]<128 && ptr[i+2]!=0 && ptr[i+3]!=0){
+                 ptr[i+3]=st+(st2*cc2/ct2);cc2++;
+               }
+               i+=4;
+             }
+             i-=4;
+           }else{ptr[i+3]=st+st2;}
+
+         }else{
+           if(vmo==3){
+             ptr[i+3]=st+(rand()*(st2+1)/32767);
+           }else{
+             if(vmo==4){
+               int aa;
+               aa=ptr[i+3];
+               aa+=(rand()*(st2+1)/32767)+st;
+
+               if(aa<=0){aa=1;}
+               if(aa>127){aa=127;}
+               ptr[i+3]=aa;
+             }else{
+               int aa,bb,f;
+             next:
+               aa=ptr[i+1];
+               bb=ptr[i+2];
+               f=(rand()*(st2+1)/32767)+st;
+               if(bb){aa+=f;}
+               if(bb){bb+=f;}
+
+               if(aa<0||aa>255||bb<0||bb>255){goto next;}
+               ptr[i+1]=aa;ptr[i+2]=bb;
+             }
+           }
+         }
+       }
+      }else{ptr[i+3]=st;}
+    }
+  }
+  cplen=0;
+  msg_clr();
+  return 0;
+}
+
+/***************************/
+int    trk_check(int ln)
+{
+  if(ln<=0){return 0;}
+
+  if(tr_len[track]+ln<=tr_alc[track]){return(0);}
+  ln-=(tr_alc[track]-tr_len[track]);
+  return(size_add(track,ln));
+}
+
+/***************************/
+int    trk_shift(int ad,int ln)
+{
+  if(trk_check(ln)!=0){return(-1);}
+  memcpy_l(&trk[track][ad+ln],&trk[track][ad],tr_len[track]-ad);
+  tr_len[track]=tr_len[track]+ln;
+  return(0);
+}
+
+/***************************/
+void   trk_delete(int ad,int ln)
+{
+  tr_len[track]=tr_len[track]-ln;
+  memcpy_l(&trk[track][ad],&trk[track][ad+ln],tr_len[track]-ad);
+}
+
+/***************************/
+int    size_change(int tr,int ln)
+{
+  if(tr_alc[tr]>=ln){return 0;}
+  ln=ln-tr_alc[tr];
+  return(size_add(tr,ln));
+}
+
+/***************************/
+int    size_max(int tr)
+{
+  int fr;
+
+  size_ref();fr=buff_free;
+  if(fr+tr_alc[tr]>TRACK_SIZE){fr=TRACK_SIZE-tr_alc[tr];}
+  return(size_add(tr,fr));
+}
+
+/***************************/
+int    size_add(int tr,int size)
+{
+  unsigned char        *ptr_s,*ptr_d;
+
+  if(buff_free<size){
+    msg(_("Track buffer exhausted."));return(-1);}
+
+  if(tr_alc[tr]+size>TRACK_SIZE){
+    msg(_("Track buffer exhausted."));return(-1);}
+
+  if(tr<35){
+    int        i;
+
+    for(i=35;i>tr;i--){
+      ptr_s=trk[i];ptr_d=ptr_s+size;trk[i]=ptr_d;
+      memcpy_l(ptr_d,ptr_s,tr_len[i]);
+    }
+  }
+
+  tr_alc[tr]+=size;
+  buff_free-=size;
+
+  return 0;
+}
+
+/***************************/
+void   size_ref()
+{
+  unsigned char        *ptr_s,*ptr_d;
+  int  i,left=0,ln;
+
+  for(i=1;i<36;i++){
+    ln=tr_alc[i-1]-tr_len[i-1];
+    left+=ln;
+    buff_free+=ln;
+
+    if(left>0){
+      ptr_s=trk[i];ptr_d=ptr_s-left;
+      trk[i]=ptr_d;tr_alc[i-1]-=ln;
+      memcpy_l(ptr_d,ptr_s,tr_len[i]);
+    }
+  }
+  ln=tr_alc[35]-tr_len[35];
+  tr_alc[35]-=ln;buff_free+=ln;
+}
+
+/***************************/
diff --git a/trkset.cpp b/trkset.cpp
new file mode 100644 (file)
index 0000000..bfa6d75
--- /dev/null
@@ -0,0 +1,896 @@
+/*
+ * STed: trkset.c (track set subroutine)
+ */
+
+#include       "sted.h"
+
+
+static void exetrk_dsp(int);
+
+/***************************/
+int    trk_sel(int cx)
+{
+  int  ke,sh;
+
+  while( 1){
+    trk_no_cur(track,2);if(cx<0){trk_no_cur(track,1);}else{trk_lin(track,cx,1);}
+    ke=inkey2();sh=B_SFTSNS();
+    trk_no_cur(track,0);if(cx>=0){trk_lin(track,cx,0);}
+
+    if(sh&4){
+      int      ex;
+      char     t[32];
+      t[0]=ke;t[1]=0;
+      ex=str_search("1234567890,./*-+=\x0d",t); /* */
+      if( ex ){
+       ex--;track=ex;
+       if(ex<btrack || ex>btrack+17){
+         btrack=ex/9*9;if(btrack>18){btrack=18;}
+         form3();
+       }
+       track=ex;
+      }
+    }
+
+    if( ke==9 ){
+      int      j;
+      msg("TRACK No.=");j=vinput(track+1,0x802);msg_clr();
+      if(es==0 && j>0 && j<=36){
+       j--;track=j;
+       if(j<btrack || j>btrack+17){
+         btrack=j/9*9;if(btrack>18){btrack=18;}
+         form3();
+       }
+      }
+    }
+    if( ke==13 ){break;}
+    if( ke==27 ){return(-1);}
+
+    if( ke==0x0b ){track=btrack;}
+
+    if( ke==0x05 ){track--;if(track<btrack){track=btrack+17;}}
+    if( ke==0x18 ){track++;if(track>btrack+17){track=btrack;}}
+
+    if( ke==0x17 && btrack>0){
+      if(sh&1){btrack-=1;track-=1;}else{btrack-=9;track-=9;}
+      if(btrack<0){btrack=0;track=0;}
+      form3();snsclr();
+    }
+    if( ke==0x12 && btrack<18){
+      if(sh&1){btrack+=1;track+=1;}else{btrack+=9;track+=9;}
+      if(btrack>18){btrack=18;track=18;}
+      form3();snsclr();
+    }
+
+  }
+  trk_no_dis();return(0);
+}
+
+/***************************/
+void   trk_no_cur(int i,int m)
+{
+  int a,b;
+
+  if(m==0){a=15;b=8;}else{a=0;b=15;if(m==2){b=11;}}
+
+  if(i>=btrack && i<btrack+18){
+    vdis(13,192+(i-btrack)*16,i+1,2,a,b);
+  }
+}
+
+/***************************/
+void   trk_no_dis()
+{
+  vdis2(21+14,0,track+1,2,15,8);vdis2(21+14,512,track+1,2,15,8);
+}
+
+/***************************/
+void   trk_set(int md)
+{
+  int  ke,sh,cx,i,y;
+
+  edfield(-1);edit_scr=0;logo(-1);i=track;
+
+  cx=-1;
+  while( 1){
+  top:
+    trk_no_cur(i,2);if(cx<0){trk_no_cur(i,1);}else{trk_lin(i,cx,1);}
+    ke=inkey3();sh=ke>>8;ke=ke&0xff;
+    if(ke>='a' && ke<='z'){ke-=32;}
+    trk_no_cur(i,0);if(cx>=0){trk_lin(i,cx,0);}
+    track=i;
+
+    if( ke>='A' && ke<='Z' && (sh&4)!=0 ){
+      if(cnfflag&0x200){sh=1-(sh&1);}
+      if(sh&1){option(ke-'A',1);}else{option2(ke-'A',1,0,0);}
+      ke=0;
+    }
+
+    y=12+(i-btrack);
+
+    if( ke==0xe0 ){if((sh&1)==0){poplay(0,4);}else{poplay(0,5);}}
+    if( ke==0xe1 ){if((sh&1)==0){poplay(0,1);}else{poplay(0,2);}}
+
+
+    if(sh&4){
+      int      ex;
+      char t[32];
+      t[0]=ke;t[1]=0;
+      ex=str_search("1234567890,./*-+=\x0d",t); /* */
+      if( ex ){
+       i=ex-1;
+       if(i<btrack || i>=btrack+18){
+         btrack=i/9*9;if(btrack>18){btrack=18;}
+         form3();
+       }
+       track=i;ke=0;
+      }
+    }
+
+    /*         if(sh&8){
+               int     ex;
+               char t[32];
+               t[0]=ke;t[1]=0;
+               ex=str_search("1234567890,./ *-+=\x0d",t);
+               if( ex ){
+               if(cx==1){mch[i]=ex;ke=0;}
+               }
+               }
+               */
+
+    if( ke==27 ){break;}
+    if( ke==9 ){
+      int      ex;
+      msg("TRACK No.=");ex=vinput(i+1,0x802);msg_clr();
+      if(es==0 && ex>0 && ex<=36){
+       i=ex-1;
+       if(i<btrack || i>=btrack+18){
+         btrack=i/9*9;if(btrack>18){btrack=18;}
+         form3();
+       }
+      }
+    }
+
+    if( ke==13 ){
+      trk_no_dis();
+      if( cx<0 || (sh&1)!=0 ){
+       if(md==0){
+         trk_ed();
+         i=track;
+         if(i<btrack || i>=btrack+18){
+           btrack=i/9*9;if(btrack>18){btrack=18;}
+           form3();
+         }
+         if(B_SFTSNS()&1){break;}
+       }else{
+         if(real_record()==0){form3();}
+         break;
+       }
+       goto top;
+      }
+
+      if( cx==0 ){
+       int     ex=trmod[i];trmod[i]=(ex&0xfc)+((ex+1)&3);
+      }
+      if( cx==1 ){
+       int     ex;
+       char    tmp0[64];
+
+       strcpy(tmp0,chstr(mch[i]));
+       B_LOCATE(21,y);sinput(tmp0,0x803);ex=strch(mch[i],tmp0);
+       /* May.06.2001 NAGANO Daisuke <breeze.nagano@nifty.ne.jp> */
+       if ( issted3 ) {
+         if(es==0 && ex<=STED3_MAX_PORT_NUMBER*16 && ex>=0 ){mch[i]=ex;}
+       } else {
+         if(es==0 && ex<33 && ex>=0 ){mch[i]=ex;}
+       }
+      }
+      if( cx==2 ){
+       int     ex=trst[i];if(ex>127){ex=ex-256;}
+       B_LOCATE(25,y);ex=vinput(ex,0x803);
+       if(es==0 && (ex>=-99 && ex<=99)){
+         if( ex<0 ){ex=ex+256;}
+         trst[i]=ex;}
+      }
+      if( cx==3 ){
+       int     ex=trkey[i];if( ex>63 && ex<128){ex=ex-128;}
+       B_LOCATE(29,y);ex=vinput(ex,0x803);
+       if(es==0 && ((ex>=-64 && ex<64) || ex==128)){
+         if( ex<0 ){ex=ex+128;}
+         trkey[i]=ex;}
+      }
+      if( cx==4 ){
+       int     ex=trrhy[i];
+       if(ex<0x80){ex=0x80;}else{if(ex==0x80){ex=0x90;}else{ex=0;}}
+       trrhy[i]=ex;
+      }
+
+      if( cx==5 ){B_LOCATE(37,y);sinput(trkmemo[i],36);}
+      B_CLR_AL();
+    }
+
+    if( ke>='0' && ke<='9' ){
+      trk_no_dis();
+
+      if( cx==1 ){
+       int     ex;
+       char    tmp0[64];
+
+       tmp0[0]=ke;tmp0[1]=0;
+       B_LOCATE(21,y);sinput(tmp0,0x403);ex=strch(mch[i],tmp0);
+       /* May.06.2001 NAGANO Daisuke <breeze.nagano@nifty.ne.jp> */
+       if ( issted3 ) {
+         if(es==0 && ex<=STED3_MAX_PORT_NUMBER*16 && ex>=0 ){mch[i]=ex;}
+       } else {
+         if(es==0 && ex<33 && ex>=0 ){mch[i]=ex;}
+       }
+      }
+      if( cx==2 ){
+       int     ex=trst[i];if(ex>127){ex=ex-256;}
+       B_LOCATE(25,y);ex=vinput(ke-'0',0x403);
+
+       if(es==0 && (ex>=-99 && ex<=99)){
+         if( ex<0 ){ex=ex+256;}
+         trst[i]=ex;}
+      }
+      if( cx==3 ){
+       int     ex=trkey[i];if( ex>63 && ex<128){ex=ex-128;}
+       B_LOCATE(29,y);ex=vinput(ke-'0',0x403);
+       if(es==0 && ((ex>=-64 && ex<64) || ex==128)){
+         if( ex<0 ){ex=ex+128;}
+         trkey[i]=ex;}
+      }
+      B_CLR_AL();
+    }
+
+    if( ke=='+' || ke=='>' || ke=='.' ){
+      if( cx==0 ){
+       int     ex=trmod[i];trmod[i]=(ex&0xfc)+((ex+1)&3);
+      }
+      if( cx==1 ){
+       int     ex=mch[i];ex++;if(ex>32){ex=0;}
+       mch[i]=ex;
+      }
+      if( cx==2 ){
+       int     ex=trst[i];if(ex>127){ex=ex-256;}
+       if(sh&1){ex+=12;}else{ex++;}
+       if(ex<=99){
+         if( ex<0 ){ex=ex+256;}
+         trst[i]=ex;}
+      }
+      if( cx==3 ){
+       int     ex=trkey[i];if( ex>63 && ex<128){ex=ex-128;}
+       if(sh&1){ex+=12;}else{ex++;}
+       if(ex<64){
+         if( ex<0 ){ex=ex+128;}
+         trkey[i]=ex;}
+      }
+      if( cx==4 ){
+       int     ex=trrhy[i];
+       if(ex<0x80){ex=0x80;}else{if(ex==0x80){ex=0x90;}else{ex=0;}}
+       trrhy[i]=ex;
+      }
+    }
+    if( ke=='-' || ke=='<' || ke==',' ){
+      if( cx==0 ){
+       int     ex=trmod[i];trmod[i]=(ex&0xfc)+((ex+3)&3);
+      }
+      if( cx==1 ){
+       int     ex=mch[i];ex--;if(ex<0){ex=32;}
+       mch[i]=ex;
+      }
+      if( cx==2 ){
+       int     ex=trst[i];if(ex>127){ex=ex-256;}
+       if(sh&1){ex-=12;}else{ex--;}
+       if(ex>=-99){
+         if( ex<0 ){ex=ex+256;}
+         trst[i]=ex;}
+      }
+      if( cx==3 ){
+       int     ex=trkey[i];if( ex>63 && ex<128){ex=ex-128;}
+       if(sh&1){ex-=12;}else{ex--;}
+       if(ex>=-64){
+         if( ex<0 ){ex=ex+128;}
+         trkey[i]=ex;}
+      }
+      if( cx==4 ){
+       int     ex=trrhy[i];
+       if(ex<0x80){ex=0x90;}else{if(ex==0x90){ex=0x80;}else{ex=0;}}
+       trrhy[i]=ex;
+      }
+
+    }
+    if( ke==32 ){
+      if( (sh&1)==0 ){
+       if( cx==0 ){trmod[i]=0;}
+       if( cx==1 ){mch[i]=0;}
+       if( cx==2 ){trst[i]=0;}
+       if( cx==3 ){trkey[i]=/*0x80*/0;}
+       if( cx==4 ){trrhy[i]=0;}
+      }else{
+       int j;
+       for(j=0;j<36;j++){
+         if(i!=j){
+           if( cx==0 ){trmod[j]=0;}
+           if( cx==1 ){mch[j]=0;}
+           if( cx==2 ){trst[j]=0;}
+           if( cx==3 ){trkey[j]=/*0x80*/0;}
+           if( cx==4 ){trrhy[j]=0;}
+           trk_lin(j,cx,0);
+         }
+       }
+      }
+    }
+    if( ke=='=' ){
+      if( cx==0 ){
+       int     ex=trmod[i]^1;trmod[i]=ex;
+      }
+      if( cx==1 ){
+       int     ex=mch[i];
+       if( ex>0 ){
+         if( ex>16 ){ex-=16;}else{ex+=16;}
+         mch[i]=ex;
+       }
+      }
+      if( cx==2 ){
+       int     ex=trst[i];if(ex>127){ex=ex-256;}
+       ex=-ex;
+       if(ex>=-99 && ex<=99){
+         if( ex<0 ){ex=ex+256;}
+         trst[i]=ex;}
+      }
+      if( cx==3 ){
+       int     ex=trkey[i];
+       if( ex>0 && ex<128){
+         if( ex>63 ){ex=ex-128;}
+         ex=-ex;if( ex<0 ){ex=ex+128;}
+       }else{ex=128-ex;}
+       trkey[i]=ex;
+      }
+      if( cx==4 ){trrhy[i]=(trrhy[i]^0x80);}
+    }
+
+
+    if( ke==0x0b ){i=btrack;}
+
+    if( ke==0x05 ){i--;if(i<btrack){i=btrack+17;}}
+    if( ke==0x18 ){i++;if(i>btrack+17){i=btrack;}}
+    if( ke==0x13 ){cx--;if(cx<-1){cx=5;}}
+    if( ke==0x04 ){cx++;if(cx>5){cx=-1;}}
+
+    if( ke==0x17 && btrack>0){
+      if(sh&1){btrack-=1;i-=1;}else{btrack-=9;i-=9;}
+      if(i<0){btrack=0;i=0;}
+      form3();snsclr();
+    }
+    if( ke==0x12 && btrack<18){
+      if(sh&1){btrack+=1;i+=1;}else{btrack+=9;i+=9;}
+      if(btrack>18){btrack=18;i=18;}
+      form3();snsclr();
+    }
+
+    if( cx==0 ){
+      if( ke=='P' ){trmod_set(i,0,sh&1);ke=0;}
+      if( ke=='M' ){trmod_set(i,1,sh&1);ke=0;}
+      if( ke=='X' ){trmod_set(i,2,sh&1);ke=0;}
+      if( ke=='R' ){trmod_set(i,3,sh&1);ke=0;}
+    }
+
+    if( ke=='X' ){
+      int      ex;
+      B_LOCATE(55,6);B_PRINT("ExChange Track Data");
+      B_LOCATE(72,7);B_PRINT("Source Track=");B_PRINT(fstr(i+1,2));
+      B_LOCATE(68,8);B_PRINT("Distnation Track=");
+    exc1:                      ex=trk_sel(cx);if(ex==0 && i==track){goto exc1;}
+    if(ex==0){
+      B_LOCATE(68+17,8);B_PRINT(fstr(track+1,2));
+      ts_swap(i,track);trk_lin(i,-1,0);trk_lin(track,-1,0);}
+    i=track;
+    B_CLR_AL();
+    }
+    if( ke=='C' ){
+      int      ex;
+      B_LOCATE(55,6);B_PRINT("Copy Track Data");
+      B_LOCATE(72,7);B_PRINT("Source Track=");B_PRINT(fstr(i+1,2));
+      B_LOCATE(68,8);B_PRINT("Distnation Track=");
+    cpy1:                      ex=trk_sel(cx);if(ex==0 && i==track){goto cpy1;}
+    if(ex==0){
+      B_LOCATE(68+17,8);B_PRINT(fstr(track+1,2));
+      ts_copy(i,track);trk_lin(track,-1,0);}
+    B_CLR_AL();
+    i=track;
+    }
+
+    if( ke=='I' ){
+      int      ex,j;
+      B_LOCATE(55,6);B_PRINT("Insert Track Data");
+      B_LOCATE(72,7);B_PRINT("Source Track=");B_PRINT(fstr(i+1,2));
+      B_LOCATE(68,8);B_PRINT("Distnation Track=");
+    ins1:                      ex=trk_sel(cx);if(ex==0 && i==track){goto ins1;}
+    if(ex==0){
+      B_LOCATE(68+17,8);B_PRINT(fstr(track+1,2));
+      ts_ins(i,track);for(j=0;j<36;j++){trk_lin(j,-1,0);}
+    }
+    i=track;
+    B_CLR_AL();
+    }
+
+    if( ke=='T' ){
+      int      ex,j;
+      B_LOCATE(55,6);B_PRINT("Sort Track Data");
+      B_LOCATE(72,7);B_PRINT("Start  Track=");B_PRINT(fstr(i+1,2));
+      B_LOCATE(72,8);B_PRINT("End    Track=");
+    srt1:                      ex=trk_sel(cx);if(ex==0 && i>=track){goto srt1;}
+    if(ex==0){
+      B_LOCATE(68+17,8);B_PRINT(fstr(track+1,2));
+      ts_sort(i,track);for(j=0;j<36;j++){trk_lin(j,-1,0);}
+    }
+    i=track;
+    B_CLR_AL();
+    }
+
+    if( ke=='M' ){
+      int      ex;
+      B_LOCATE(55,6);B_PRINT("Mix Track Data");
+      B_LOCATE(72,7);B_PRINT("Source Track 1=");B_PRINT(fstr(track+1,2));
+      B_LOCATE(72,8);B_PRINT("Source Track 2=");
+    mix1:                      ex=trk_sel(cx);if(ex==0 && i==track){goto mix1;}
+    if(ex==0){
+      int      i2;
+      B_LOCATE(72+15,8);B_PRINT(fstr(track+1,2));
+      B_LOCATE(71,9);B_PRINT("Distnation Track=");
+      i2=track;
+      ex=trk_sel(cx);
+      if(ex==0){
+       B_LOCATE(71+17,9);B_PRINT(fstr(track+1,2));
+       ts_mix(i,i2,track);
+       trk_lin(i,-1,0);trk_lin(i2,-1,0);trk_lin(track,-1,0);
+      }
+    }
+    i=track;
+    txerase(432,107-16,744,164+16);
+    }
+    if( ke==12 || ke=='D' ){
+      B_LOCATE(55,6);B_PRINT("Erase Track Data");
+      B_LOCATE(79,7);B_PRINT("Track=");B_PRINT(fstr(i+1,2));
+      msg(_("Delete all track data"));
+      if(yn_sel()>0){ts_clear(i);trk_lin(i,-1,0);}
+      B_CLR_AL();
+    }
+    if( ke=='O' ){
+      B_LOCATE(55,6);B_PRINT("Optimize Track Data");
+      B_LOCATE(79,7);B_PRINT("Track=");
+      if(sh&1){B_PRINT("All");}else{B_PRINT(fstr(i+1,2));}
+      msg(_("Optimize track data"));
+      if(yn_sel()>0){
+       if(sh&1){
+         int j;
+         for(j=0;j<36;j++){
+           exetrk_dsp(j);
+           if(tr_len[j]>4){
+             trk_opt_sub(j,0,tr_len[j]);trk_lin(j,-1,0);
+           }
+         }
+       }else{
+         trk_opt_sub(i,0,tr_len[i]);trk_lin(i,-1,0);
+       }
+      }
+      B_CLR_AL();
+    }
+    if( ke=='A' || ke=='R' ){
+      if( ke=='A' ){
+       B_LOCATE(55,6);B_PRINT("SameMeas Compress Track Data");
+      }else{
+       B_LOCATE(55,6);B_PRINT("Repeat Compress Track Data");
+      }
+      B_LOCATE(79,7);B_PRINT("Track=");
+      if(sh&1){B_PRINT("All");}else{B_PRINT(fstr(i+1,2));}
+      msg(_("Compress track data"));
+      if(yn_sel()>0){
+       int t=track;
+       size_ref();
+       if(sh&1){
+         int j;
+         for(j=0;j<36;j++){
+           exetrk_dsp(j);
+           if(tr_len[j]>4){
+             track=j;
+             if( ke=='A' ){
+               same_meas_conv(j);
+             }else{
+               repeat_comp(j);
+             }
+             trk_lin(j,-1,0);
+           }
+         }
+       }else{
+         if( ke=='A' ){
+           same_meas_conv(i);
+         }else{
+           repeat_comp(i);
+         }
+         trk_lin(i,-1,0);
+       }
+       track=t;
+      }
+      B_CLR_AL();
+    }
+
+    if( ke=='E' ){
+      B_LOCATE(55,6);B_PRINT("SameMeas/Repeat Extract Track Data");
+      B_LOCATE(79,7);B_PRINT("Track=");
+      if(sh&1){B_PRINT("All");}else{B_PRINT(fstr(i+1,2));}
+      msg(_("Extrack track data"));
+      if(yn_sel()>0){
+       if(sh&1){
+         int j;
+         for(j=0;j<36;j++){
+           exetrk_dsp(j);
+           if(tr_len[j]>4){ts_ext(j);trk_lin(j,-1,0);}
+         }
+       }else{
+         ts_ext(i);trk_lin(i,-1,0);
+       }
+      }
+      B_CLR_AL();
+    }
+
+    if( ke=='B' ){
+      B_LOCATE(55,6);B_PRINT("Meas End Rewrite");
+      B_LOCATE(79,7);B_PRINT("Track=");
+      if(sh&1){B_PRINT("All");}else{B_PRINT(fstr(i+1,2));}
+      ts_measend(i,sh);/*trk_lin(i,-1,0);*/
+      txerase(432,107-16,744,164+16);
+      B_CLR_AL();
+    }
+
+    if( ke=='L' ){
+      if((sh&1)==0){
+       char    tmp0[128],path2[128];
+
+       track=i;
+       trk_no_dis();
+       strcpy(path2,trk_path);fsel(trk_file,path2,0x005);
+       if( es==0 && trk_file[0]!=0 ){
+         strcpy(tmp0,path2);strcat(tmp0,trk_file);
+         msg(_("Loading track data ..."));
+         if(trk_load(tmp0)==0){
+           if(!(cnfflag&0x0008)){strcpy(trk_path,path2);}
+           trk_lin(track,-1,0);
+           msg_clr();
+         }
+       }
+      }else{load_sub(0);}
+    }
+    if( ke=='S' ){
+      if((sh&1)==0){
+       char    tmp0[128],path2[128];
+
+       track=i;
+       trk_no_dis();
+       strcpy(path2,trk_path);fsel(trk_file,path2,0x105);
+       if( es==0 && trk_file[0]!=0 ){
+         strcpy(tmp0,path2);strcat(tmp0,trk_file);
+         msg(_("Saving track data ..."));
+         if(trk_save(tmp0)==0){
+           if(!(cnfflag&0x0008)){strcpy(trk_path,path2);}
+           msg_clr();
+         }
+       }
+      }else{save_sub(0);}
+    }
+
+  }
+  logo(512);edit_scr=0;
+}
+
+/***************************/
+/*「現在 Track 1 を処理しています」*/
+void   exetrk_dsp(int i)
+{
+  B_LOCATE(55,9);B_PRINT("TRACK=");B_PRINT(fstr(i+1,2));
+}
+
+/***************************/
+void   trmod_set(int tr,int md,int sh)
+{
+  int j,i=tr;
+
+  if(sh&1){
+    for(j=0;j<36;j++){
+      if(i!=j){
+       trmod[j]=md;
+       trk_lin(j,0,0);
+      }
+    }
+  }else{
+    trmod[i]=md;
+    trk_lin(i,0,0);
+  }
+}
+
+/***************************/
+void   trk_lin(int i,int cx,int m)
+{
+  int  c1,c2,ex,y;
+  char tmp0[16];
+  static char  play_mode[5][5]={"Play","Mute"," Mix"," Rec"," Rec"};
+  static char  play_modec[5]={3,2,1,6,6};
+
+  if(i<btrack || i>btrack+17){return;}
+  y=192+(i-btrack)*16;
+
+  if(m==1){c1=0;c2=15;}else{c1=15;c2=0;}
+  if(m==2){c2=-1;}
+
+  if(cx<0){vdis2(13,y,i+1,2,15,-1);}
+
+  if(cx==0 || cx<0){
+    int cl0=play_modec[trmod[i]&3],cl1=c1,cl2=c2;
+    if(c1>0){cl1=cl0;}
+    if(c2>0){cl2=cl0;}
+    sdis2(16,y,play_mode[trmod[i]&3],4,cl1,cl2);}
+
+  if(cx==1 || cx<0){
+    ex=mch[i];
+    strcpy(tmp0,chstr(ex));
+    sdis2(21,y,tmp0,3,c1,c2);
+  }
+  if(cx==2 || cx<0){
+    ex=trst[i];
+    if( ex>127 ){ex=ex-256;}
+    vdis2(25,y,ex,3,c1,c2);
+  }
+  if(cx==3 || cx<0){
+    ex=trkey[i];
+    if(ex>=0x80){
+      sdis2(29,y,"OFF",3,c1,c2);
+    }else{
+      if( ex>63 ){ex=ex-128;}
+      vdis2(29,y,ex,3,c1,c2);
+    }
+  }
+  if(cx==4 || cx<0){
+    if(trrhy[i]&0x80){
+      strcpy(tmp0,"ON ");if(trrhy[i]>0x80){tmp0[2]='+';}
+      sdis2(33,y,tmp0,3,c1,c2);
+    }else{
+      sdis2(33,y,"OFF",3,c1,c2);}
+  }
+  /*  if(cx==5 || cx<0){sdis2(37,y,trkmemo[i],36,c1,c2);}*/
+  if(cx==5 || cx<0){sdis2(37,y,eucconv(trkmemo[i]),36,c1,c2);}
+  if(cx<0 && m<2){trksize(i);}
+}
+
+/***************************/
+void   ts_swap(int a,int b)
+{
+  char tmp0[128];
+  int  i,j,d;
+
+  size_ref();
+  if(size_change(a,tr_len[b])){return;}
+  if(size_change(b,tr_len[a])){return;}
+
+  memcpy_l(dat,trk[a],tr_len[a]);
+  memcpy_l(trk[a],trk[b],tr_len[b]);
+  memcpy_l(trk[b],dat,tr_len[a]);
+
+  for(i=0;i<2;i++){for(j=0;j<4;j++){
+    d=tr_pos[a][i][j];tr_pos[a][i][j]=tr_pos[b][i][j];tr_pos[b][i][j]=d;}}
+
+  d=tr_len[a];tr_len[a]=tr_len[b];tr_len[b]=d;
+
+  d=trmod[a];trmod[a]=trmod[b];trmod[b]=d;
+  d=trrhy[a];trrhy[a]=trrhy[b];trrhy[b]=d;
+  d=mch[a];mch[a]=mch[b];mch[b]=d;
+  d=trkey[a];trkey[a]=trkey[b];trkey[b]=d;
+  d=trst[a];trst[a]=trst[b];trst[b]=d;
+  strcpy(tmp0,trkmemo[a]);strcpy(trkmemo[a],trkmemo[b]);strcpy(trkmemo[b],tmp0);
+}
+
+/***************************/
+void   ts_ins(int a,int b)
+{
+  int  i;
+
+  if(a<b){
+    for(i=a;i<b;i++){ts_swap(i,i+1);}
+  }else{
+    for(i=a-1;i>b-1;i--){ts_swap(i,i+1);}
+  }
+}
+
+/***************************/
+void   ts_sort(int a,int b)
+{
+  int  i,j;
+
+  for(i=a;i<=b-1;i++){
+    B_LOCATE(55,9);B_PRINT("TRACK=");B_PRINT(fstr(i+1,2));
+    for(j=i+1;j<=b;j++){
+      if( (mch[i]>mch[j] || ( mch[j]==10||mch[j]==26) ||mch[i]==0) && mch[j]!=0 ){
+       ts_swap(i,j);
+      }
+    }
+  }
+}
+
+/***************************/
+void   ts_copy(int a,int b)
+{
+  int  i,j;
+
+  size_ref();
+  if(size_change(b,tr_len[a])){return;}
+
+  memcpy_l(trk[b],trk[a],tr_len[a]);
+
+  for(i=0;i<2;i++){for(j=0;j<4;j++){tr_pos[b][i][j]=tr_pos[a][i][j];}}
+  tr_len[b]=tr_len[a];trmod[b]=trmod[a];
+  trrhy[b]=trrhy[a];
+  mch[b]=mch[a];trkey[b]=trkey[a];trst[b]=trst[a];
+  strcpy(trkmemo[b],trkmemo[a]);
+}
+
+/***************************/
+void   ts_clear(int a)
+{
+  int  j;
+
+  trk[a][0]=0xfe;tr_len[a]=4;
+  for(j=0;j<4;j++){tr_pos[a][0][j]=0;tr_pos[a][1][j]=0;}
+  trmod[a]=0;trno[a]=a+1;trrhy[a]=0;mch[a]=a+1;trkey[a]=0;trst[a]=0;
+  if(a==9){trrhy[9]=128;trkey[9]=128;}
+  if(a>15){mch[a]=0;}
+  trkmemo[a][0]=0;
+
+  size_ref();
+}
+
+/***************************/
+void   ts_mix(int tr1,int tr2,int tr3)
+{
+  int  po;
+
+  rcpf=0;cpleng=0;
+
+  msg("TRACK MIX...");
+
+  po=trk_ext_sub(tr1,(char*)cpbuf);if(po==0){return;}
+  po=trk_ext_sub(tr2,(char*)rcpbuf);if(po==0){return;}
+
+  po=trk_mix_sub(cpbuf,rcpbuf);
+  if(size_change(tr3,po+4)){return;}
+
+  memcpy_l(trk[tr3],dat,po);trk[tr3][po]=0xfe;tr_len[tr3]=po+4;
+
+  msg_clr();
+}
+
+/***************************/
+void   ts_measend(int tr1,int sh)
+{
+  static       unsigned char   bars[4*7]={
+    0xf9,0,0,0, 0xf9,0,0,0, 0,48,0,0, 0xf8,4,0,0, 0,0,0,0,
+    0xfd,0,0,0, 0xf8,3,0,0};
+
+  int  po,mc,barlen,ofs,maxm;
+
+  rcpf=0;cpleng=0;
+
+  msg("MEAS END CHANGE");
+loop:
+  barlen = tbase * 4 * beat1 / beat2;
+  B_LOCATE(17,1);B_PRINT("MEAS ST=");
+  barlen=vinput(barlen,0x804);if(es!=0){msg_clr();return;}
+  if(barlen<24 || barlen>2000){goto loop;}
+loop2:
+  B_LOCATE(30,1);B_PRINT("OFFSET=");
+  ofs=vinput(0,0x804);if(es!=0){msg_clr();return;}
+  if(ofs<0 || ofs>2000){goto loop2;}
+loop3:
+  B_LOCATE(42,1);B_PRINT("LAST MEAS=");
+  maxm=vinput(0,0x804);if(es!=0){msg_clr();return;}
+  if(maxm<0 || maxm>2000){goto loop3;}
+
+  if(sh&1){tr1=0;}
+loopx:
+  exetrk_dsp(tr1);
+
+  if(tr_len[tr1]<=4){goto skip;}
+
+  po=trk_ext_sub(tr1,(char*)cpbuf);if(po==0){return;}
+
+  po=0;mc=((tr_step[tr1]-ofs)/barlen);
+
+  if(maxm>0 && mc<maxm){mc=maxm;if(ofs){mc--;}}
+
+  if(ofs){
+    int i=ofs;
+    while(i>0){
+      dat[po]=0;dat[po+1]=0;dat[po+2]=0;dat[po+3]=0;
+      if(i<240){dat[po+1]=i;i=0;}else{dat[po+1]=240;i-=240;}
+      po+=4;
+    }
+    dat[po]=0xfd;po+=4;
+  }
+
+  while(mc>0){
+    memcpy(&dat[po],bars,4*7);
+    if(barlen<=240+15 ){
+      dat[po+9]=barlen;dat[po+13]=1;
+    }else{
+      int bl;
+      dat[po+9]=240;dat[po+13]=barlen/240;
+      bl=barlen-240*dat[po+13];
+      dat[po+17]=bl;
+    }
+
+    if(mc<240){dat[po+25]=mc;mc=0;}else{dat[po+25]=240;mc-=240;}
+    po+=4*7;
+  }
+  dat[po]=0xfe;po+=4;
+  po=repeat_ext(rcpbuf,po);
+
+  po=trk_mix_sub(rcpbuf,cpbuf);
+  if(size_change(tr1,po+4)){return;}
+
+  if(po>4 && dat[po-4]==0xfd && dat[po-8]==0xfd){po-=4;}
+
+  memcpy_l(trk[tr1],dat,po);
+  trk[tr1][po]=0xfe;tr_len[tr1]=po+4;
+
+  trk_lin(tr1,-1,0);
+skip:
+  if(sh&1){
+    tr1++;if(tr1<36){goto loopx;}
+  }
+  msg_clr();
+}
+
+/***************************/
+void   ts_ext(int i)
+{
+  int  po;
+
+  rcpf=0;cpleng=0;
+
+  po=trk_ext_sub(i,(char*)cpbuf);if(po==0){return;}
+
+  size_ref();
+  if(size_change(i,po)){return;}
+
+  memcpy_l(trk[i],cpbuf,po);
+  tr_len[i]=po;
+  /*   trk_lin(i,-1,0);*/
+}
+
+/***************************/
+void   trksize(int tr)
+{
+  int  i,us=-(4*36),s,c=0,fr=buff_free,yy;
+
+  if(tr<0){c=-1;}else{tr_step[tr]=step_cluc2(tr,0,tr_len[tr]);}
+  for(i=0 ;i<36;i++){
+    us+=tr_len[i];
+    fr+=(tr_alc[i]-tr_len[i]);
+    if((tr==-1 || tr==i)&& i>=btrack && i<btrack+18){
+      yy=192+(i-btrack)*16;
+
+      vdis2(74,yy,(tr_len[i]-4)>>2,5,15,c);
+      s=tr_step[i];vdis2(80,yy,s,12,15,c);
+    }
+  }
+  vdis2(6,0,fr>>2,7,15,8);vdis2(6,512,fr>>2,7,15,8);
+  vdis2(21,0,us>>2,7,15,8);vdis2(21,512,us>>2,7,15,8);
+}
+
+/***************************/
+void   trksize_c()
+{
+  int  i;
+  for(i=0 ;i<36;i++){tr_step[i]=step_cluc2(i,0,tr_len[i]);}
+}
+
+/***************************/
diff --git a/version.h b/version.h
new file mode 100644 (file)
index 0000000..0cb2389
--- /dev/null
+++ b/version.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#define VERSION_ID     "20021017"
+#define VERSION_TEXT1   "Chikuhi-line"
+#define VERSION_TEXT2   "Shikaka"
diff --git a/version.h.in b/version.h.in
new file mode 100644 (file)
index 0000000..0c6f205
--- /dev/null
@@ -0,0 +1,3 @@
+#define VERSION_ID     "zVERSION_IDz"
+#define VERSION_TEXT1   "Chikuhi-line"
+#define VERSION_TEXT2   "Shikaka"
diff --git a/visual.cpp b/visual.cpp
new file mode 100644 (file)
index 0000000..bba8029
--- /dev/null
@@ -0,0 +1,1112 @@
+/*
+ * STed: visual.c  (controller visal edit)
+ */
+#include       "sted.h"
+
+char curv_tbl[192]={
+         0,  4,  7, 10, 13, 17, 20, 24, 27, 30, 33, 36, 39, 42, 44, 46,
+        49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 72, 74, 75, 77,
+        78, 80, 81, 82, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96,
+        97, 98, 99,100,100,101,102,103,103,104,105,105,106,107,107,108,
+       108,109,109,110,110,111,111,112,112,113,113,113,114,114,115,115,
+       116,116,116,117,117,117,118,118,118,119,119,119,119,120,120,120,
+       120,121,121,121,121,121,122,122,122,122,122,122,123,123,123,123,
+       123,123,123,123,124,124,124,124,124,124,124,124,124,125,125,125,
+       125,125,125,125,125,125,125,125,125,125,126,126,126,126,126,126,
+       126,126,126,126,126,126,126,126,126,126,126,126,127,127,127,127,
+       127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,
+       127,127,127,127,127,127,127,127,127,127,127,127,127,127,127,127};
+
+int    yzm,vmo2,maxdot,excget;
+int    XB,DM;
+
+
+/***************************/
+int    vis_edit(int po,int ln,int ssh)
+{
+       int     i,j,st,cx,ccx,ke=0,kc,sh,lpara=0,co,vmo=-1,xss=6,ys=1,yss=10;
+       int     ma,mx,my,msf=-1,extmd=0,barlen,retad=0,eds=edit_scr,ost;
+
+       int     para[769],step[769],step2[769];
+       char    tmp9[64];
+       unsigned char *ptr=trk[track];
+       int     me_ad[2048];
+
+if(cnfflag&0x4000){ssh=1-(ssh&1);}
+
+       XB=320-8;DM=400;if(ssh&1){XB=0;DM=720;}else{if(eds){return po;}}
+
+       barlen = tbase*4*beat1/beat2;
+
+       yzm=1;vmo2=0;excget=0;
+       add_set(track,me_ad);
+       edit_scr=0;cons_md(0);
+
+resel:
+/*     msg("Visual Editor:");*/
+       msg("EDIT MODE(P/V/E/M/N/C/K/T/R/U/X/nn/G) =");
+
+       /*while(B_KEYSNS()==0){}*/ /* Jun.28.1998 Daisuke Nagano */
+       key_wait();
+       ke=B_KEYINP()&0xff;
+       if(ke>='a' && ke<='z'){ke-=32;}
+
+       if(ke>='0' && ke<='9'){
+               int n;
+               n=vinput(ke-'0',0x503);
+               if( es!=0 ){msg_clr();goto ext;}
+               if( n<1 || n>127 ){goto resel;}
+               vmo=n;
+       }
+
+       if(ke=='/'){
+               char    tmp0[64];
+               int     ct,ctl;
+resin:
+               B_LOCATE(38,1);B_PRINT("/");
+               tmp0[0]=0;sinput(tmp0,0x804);
+
+               if( es!=0 ){msg_clr();goto ext;}
+               ct=spc_code(tmp0,&ctl);if(ct==0){goto resin;}
+               vmo=ct;if(ctl>=0){vmo=ctl;}
+       }
+
+       if(ke=='G'){
+               int     ct=trk[track][po];
+
+               if(ct==0x98){excget=1;}
+               if((ct>=0x90 && ct<=0x98)||(ct==0xde || ct==0xed)){
+                       ke=0;vmo=ct;vmo2=trk[track][po+2];goto start;}
+
+               if(ct==0xee){
+                       ke='P';
+               }else{
+                       if(ct==0xeb){ke=0;
+                               vmo=trk[track][po+2];
+                               goto start;
+                       }else{
+                               if(ct>=128 && ct<0xf0){vmo=ct;ke=0;goto start;
+                               }else{goto resel;}
+                       }
+               }
+
+       }
+
+
+       if(ke==0x1b){msg_clr();return(po);}
+       if(ke=='P'){vmo=0;}
+       if(ke=='M'){vmo=1;}
+       if(ke=='V'){vmo=7;}
+       if(ke=='E'){vmo=11;}
+       if(ke=='N'){vmo=10;}
+       if(ke=='K'){vmo=0xed;}
+       if(ke=='C'){vmo=0xea;}
+       if(ke=='T'){vmo=0xe7;}
+       if(ke=='X'){vmo=0x98;}
+       if(ke=='U'){
+               int n;
+reue:
+               msg("UserExc");B_PRINT(" No.=");n=vinput(0,0x803);
+               if( es!=0 ){msg_clr();goto ext;}
+               if( n<0 || n>7 ){goto reue;}
+               vmo=0x90+n;
+       }
+
+       if(ke=='R'){
+               int n;
+reue2:
+               msg("Rol.Para");B_PRINT(" Add.=");n=vinput(0,0x803);
+               if( es!=0 ){msg_clr();goto ext;}
+               if( n<0 || n>127 ){goto reue2;}
+               vmo=0xde;vmo2=n;
+       }
+
+
+       if(vmo<0){goto resel;}
+
+start:
+       if(vmo==0){
+               strcpy(tmp9,"PITCH");ys=16;yss=682;
+       }else{
+               if(vmo<128){
+                       strcpy(tmp9,ctrl_type(vmo));
+                       if(vmo==7 ){lpara=100;}
+                       if(vmo==11 ){lpara=127;}
+                       if(vmo==10 ){lpara=64;}
+                       if(vmo>=71 && vmo<=74){lpara=64;}
+               }else{
+                       if(vmo==0x98){
+                               strcpy(tmp9,"Tr.Exclu");
+/*
+if(excget){
+       int ad2=po,excc=0;
+       while(trk[track][ad2+4]==0xf7){ad2+=4;excc+=4;}
+       strcat(tmp9,"(");strcat(tmp9,nstr(excc>>1));strcat(tmp9,")");
+}
+*/
+
+                       }else{
+                               if(vmo<0x98){
+                                       strcpy(tmp9,"UserExc ");tmp9[7]=vmo-0x90+'0';
+                               }else{
+                                       if(vmo==0xe7){
+                                               strcpy(tmp9,"TEMPO");lpara=64;
+                                       }else{
+                                               if(vmo==0xde){
+                                                       strcpy(tmp9,"Rol.Para");
+                                               }else{
+                                                       if(vmo==0xea){
+                                                               strcpy(tmp9,"AFTER CH.");
+                                                       }else{
+                                                               if(vmo==0xed){
+                                                                       strcpy(tmp9,"AFTER KEY");
+                                                               }else{
+                                                                       strcpy(tmp9,"");
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               }
+       }
+       cx=0;ccx=-1;
+
+
+       if(ln==0){
+               char    tmp0[64];
+               int     st2;
+               st2=barlen>>2;
+
+               if(ptr[po]<127 && ptr[po+1]>1){/*ln=4;*/st2=ptr[po+1];}
+rest:
+               msg(tmp9);/*B_LOCATE(10,1);*/B_PRINT(" TOTAL ST=");
+
+               if(ln){st=vis_a_in_st(po,ln);B_PRINT(nstr(st));ln=0;
+               }else{
+                       st=vinput(st2,0x804);
+                       if( es!=0 ){msg_clr();goto ext;}
+               }
+               if( st<2 || st>barlen*8 ){goto rest;}
+reco:
+               st2=st;if(st2>767){st2=768;}
+               co=st2*vis_reso/100;
+
+               B_LOCATE(25,1);B_PRINT("COUNT=");strcpy(tmp0,nstr(co));sinput(tmp0,0x804);
+               if( es!=0 ){msg_clr();goto ext;}
+               co=atoi(tmp0);
+               if(tmp0[0]=='/'){int co2=atoi(&tmp0[1]);if(co2>=1){co=st2/co2;}}
+               if(tmp0[0]=='%'){int co2=atoi(&tmp0[1]);if(co2>=1){co=st2*co2/100;}}
+
+               if( co<2 || co>st || co>768 ){goto reco;}
+
+               i=po;
+               while(i>0){
+                       unsigned char   d;
+top:
+                       i=i-4;d=ptr[i];
+                       if(vmo==0){
+                               if(d==0xee){
+                                       lpara=((ptr[i+3]*128+ptr[i+2])-8192);
+                                       break;
+                               }
+                       }else{
+                               if(vmo<128){
+                                       if(d==0xeb && ptr[i+2]==vmo){
+                                               lpara=ptr[i+3];break;
+                                       }
+                               }else{
+                                       if(d==vmo){
+                                               if(vmo==0xe7){
+                                                       lpara=ptr[i+2];break;
+                                               }else{
+                                                       lpara=ptr[i+3];break;
+                                               }
+                                       }
+                               }
+                       }
+                       if( d>=0xfc && retad!=0){i=retad;retad=0;goto top;}
+
+                       if( d==0xfc ){
+                               int     ii,jj,ct;
+                               jj=i;
+resame:
+                               ct=ptr[jj+1]+(ptr[jj+2]&3)*256;ii=me_ad[ct+1]-4;
+
+                               if(jj!=ii && ii>=0){
+                                       jj=ii;if(ptr[ii]==0xfc){goto resame;}
+                                       retad=i;i=ii;goto top;
+                               }
+                       }
+               }
+
+               ln=0;
+               para[768]=lpara;para[0]=lpara;para[co-1]=lpara;
+               vis_wave(st,co,cx,ccx,para,step,2,vmo);
+       }else{
+               co=vis_a_in(po,ln,para,step,vmo);
+               para[768]=para[0];
+
+               st=0;for(i=0;i<co;i++){st+=step[i];}
+
+               if(vis_a_in_co(po,ln,vmo)==0 && vis_a_in_st(po,ln)>1){goto rest;}
+
+               if(co<2||st<2){msg(_("Too few data."));return(po);}
+               if(co>768||st>barlen*8){msg(_("Too many data."));return(po);}
+       }
+
+       ost=st;
+
+       if(co>192){xss=12;}
+       if(co>192*2){xss=24;}
+       if(ssh&1){B_CLR_AL();}
+redraw:
+       fnc_dis(5);
+
+       fill(7+XB,544,767,1001,0);
+       box(7+XB,604-16,767,1001,14,65535);
+       sdis(1+(XB>>3),589-16," CONTROLLER VISUAL EDIT",95-(XB>>3),15,14);
+
+       if(vmo){
+               for(i=768-128;i<=768+128;i=i+16){
+                       line(7+XB,i,11+XB,i,14,0xffff);line(763,i,767,i,14,0xffff);
+                       line(13+XB,i,761,i,4,0x4444+0x1111);
+               }
+       }else{
+               for(i=-12;i<=12;i++){
+                       j=768+(128*i/12);
+                       line(7+XB,j,11+XB,j,14,0xffff);line(763,j,767,j,14,0xffff);
+                       line(13+XB,j,761,j,4,0x4444+0x1111);
+               }
+       }
+
+       for(i=768-128;i<=768+128;i=i+2){
+               line(7+XB,i,9+XB,i,14,0xffff);line(765,i,767,i,14,0xffff);
+       }
+       line(7+XB,768,767,768,14,0xffff);
+
+
+       {
+               int gx,st2,co2,sts;
+
+               st=0;for(i=0;i<co;i++){st+=step[i];}
+
+               maxdot=DM;
+               if(st<DM){maxdot=st;}
+               if(st<200){maxdot=st*2;}
+               if(st<100){maxdot=st*4;}
+               if(st< 50){maxdot=st*8;}
+
+               st2=st+1;co2=0;
+               if(st<=DM){sts=8;}else{sts=(barlen>>2);}
+               while(st2>sts){step2[co2++]=sts;st2-=sts;}
+               if(st2>0){step2[co2++]=st2;}
+               vis_zom(co2,st,maxdot,step2,step2);
+
+               gx=18+XB;
+               for(i=0;i<co2;i++){
+                       line(gx,768-128,gx,768+128,4,0xaaaa);
+
+                       if(st<barlen){
+                               g_print2(gx-32+4,608+4+8,fstr(sts*i,4),4);
+                       }
+                       gx+=step2[i];
+               }
+
+
+               st2=st+1;co2=0;
+               while(st2>barlen){step2[co2++]=barlen;st2-=barlen;}
+               if(st2>0){step2[co2++]=st2;}
+               vis_zom(co2,st,maxdot,step2,step2);
+
+               gx=18+XB;
+               for(i=0;i<co2;i++){
+                       line(gx,768-128,gx,768+128,4,0xffff);
+                       g_print2(gx-32+4,608+4+8,fstr(barlen*i,4),4);
+                       gx+=step2[i];
+               }
+       }
+
+       box(16+XB,768-132-8,763,768-132,14,0xffff);
+       box(17+XB,768-132-4,762,768-132-4,1,0xaaaa);
+
+       box(16+XB,768+132+8,763,768+132,14,0xffff);
+       box(17+XB,768+132+4,762,768+132+4,2,0xaaaa);
+
+       B_LOCATE(45,5);B_PRINT(tmp9);B_PRINT(" Edit Mode");
+       B_LOCATE(80,29);B_PRINT("TOTAL ST=");B_PRINT(fstr(st,4));
+
+       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+
+if((cmdflag&0x200)==0){
+       MS_INIT();MS_LIMIT(18+XB,129-8-4,762,256+127+8+4);MS_CURON();
+}
+
+       while(1){
+               vis_disp(co,cx,ccx,para,step,1,1,vmo);
+loop:
+               B_LOCATE(42,26);B_PRINT("STEP=");B_PRINT(fstr(cx+1,4));
+                               B_PRINT("/");B_PRINT(fstr(co,4));
+               B_LOCATE(42,27);if(ccx>=0){B_PRINT("SUB =");B_PRINT(fstr(ccx,4));}else{B_PRINT("         ");}
+
+               B_LOCATE(60,26);B_PRINT("STEP TIME=");B_PRINT(fstr(step[cx],4));
+               B_LOCATE(77,26);B_PRINT("PARA=");
+               if(vmo==0){B_PRINT(fstr((para[cx]),5));}else{B_PRINT(fstr((para[cx]),3));}
+/*
+               if(vmo==10){
+                       int pp=para[cx]-64;
+                       B_PRINT("(");
+                       if(pp==0){B_PRINT("C");}else{
+                       if(pp<0){pp=(-pp);B_PRINT("L");}else{B_PRINT("R");}}
+                       B_PRINT(fstr(pp,2));B_PRINT(")");
+               }
+*/
+               B_LOCATE(66,29);B_PRINT("Y-ZOOM=");B_PRINT(fstr(yzm,2));
+
+               while(B_KEYSNS()==0){
+                       /*msstat(&mx,&my,&ma,&mb);mspos(&mx,&my);*/
+                       /*ma=MS_GETDT()&0xff00;mx=MS_CURGT();my=mx&0xffff;mx=mx>>16;*/
+                       ma=MS_GETDT()&0xff00;mspos(&mx,&my);
+                       if(ma==0){msf=-1;}
+
+                       if(ma!=0 && my>128-12 && my<256+128+12 ){
+                               int     i,px;px=18+XB;
+
+                               vis_zom(co,st,maxdot,step,step2);
+
+                               for(i=0;i<co;i++){
+                                       if(mx>=px && mx<(px+step2[i])){
+                                               if(my>128 && (my<=256 ||((vmo==0||yzm>1) && my<256+128)) ){
+                                                       int aa=para[i];
+                                                       if(vmo==0){
+                                                               para[i]=(-(my-256))*64/yzm;
+                                                       }else{
+                                                               if(yzm<2){
+                                                                       para[i]=-(my-256);
+                                                               }else{
+                                                                       para[i]=-(my-(256+128))>>1;
+                                                               }
+                                                       }
+                                                       if(msf>=0 && msf!=i){
+                                                               vis_wave(st,co,i,msf,para,step,2,vmo);
+                                                               aa=para[i]+1;
+                                                       }
+                                                       cx=i;msf=i;
+
+                                                       if(aa!=para[i]){
+                                                               vis_disp(co,i,ccx,para,step,0,1,vmo);
+                                                       }
+                                               }
+                                               if( my<=128-4 ){
+                                                       if(ccx>=0){ccx=-1;}else{ccx=i;}
+                                                       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+
+                                                       while((MS_GETDT()&0xff00)!=0){}
+                                               }
+                                               if( my>128+256+4 ){
+                                                       cx=i;
+                                                       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+
+                                                       while((MS_GETDT()&0xff00)!=0){}
+                                               }
+                                       }
+                                       px+=step2[i];
+                               }
+                               goto loop;
+                       }
+               }
+               ke=B_KEYINP();kc=ke & 0xff;ke=ke>>8;sh=B_SFTSNS();
+               if(kc>='a' && kc<='z'){kc-=32;}
+
+               vis_disp(co,cx,ccx,para,step,1,0,vmo);
+
+               if( ke==1 || kc==13 ){break;}
+
+               if( ke==0x70 ){fnc_dis(6);}
+               if( ke==0xf0 ){fnc_dis(5);}
+
+               if( kc==32 ){
+                       if(ccx<0){
+                               ccx=cx;
+                       }else{
+                               vis_disp(co,cx,ccx,para,step,1,2,vmo);
+                               ccx=-1;
+                       }
+               }
+               if( kc=='Y' ){
+                       if(yzm<3){yzm++;}else{yzm*=2;if(yzm>6){yzm=1;}}
+                       if(vmo!=0 && yzm>2){yzm=1;};
+                       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+               }
+               if( kc==0x13 || ke==0x3b ){
+                       if(cx==0 || (sh&6)){vis_disp(co,cx,ccx,para,step,1,2,vmo);}
+                       if((sh&6)==0){cx--;}else{cx-=xss;}
+                       if(cx<0){cx=co-1;}
+               }
+               if( kc==0x04 || ke==0x3d){
+                       if(cx==co-1||(sh&6)){vis_disp(co,cx,ccx,para,step,1,2,vmo);}
+                       if((sh&6)==0){cx++;}else{cx+=xss;}
+                       if(cx>=co){cx=0;}
+               }
+               if( ke==0x3f){
+                       if((sh&2)==0){
+                               para[cx]=0;
+                       }else{
+                               int j;
+                               for(j=0;j<co;j++){para[j]=para[512];}
+                               vis_disp(co,cx,ccx,para,step,0,1,vmo);
+                       }
+               }
+
+               if( kc>='0' && kc<='9' && vmo!=0){para[cx]=(kc-'0')*14;}
+
+               if( kc==0x18 || ke==0x3e){
+                       if((sh&6)==0){para[cx]=para[cx]-ys;}else{
+                               para[cx]=para[cx]-yss;
+                               if(vmo==0){
+                                       int i;i=para[cx];if(i<0){i+=yss;}
+                                       i=i/700;if((i&1)==0){para[cx]--;}
+                               }
+                       }
+                       if(para[cx]<-8192){para[cx]=-8192;}
+                       if(vmo!=0 && para[cx]<0){para[cx]=0;}
+               }
+               if( kc==0x05 || ke==0x3c){
+                       if((sh&6)==0){para[cx]=para[cx]+ys;}else{
+                               if(vmo==0){
+                                       int i;i=para[cx];if(i<0){i+=yss;}
+                                       i=i/700;if((i&1)==0){para[cx]++;}
+                               }
+                               para[cx]=para[cx]+yss;
+                       }
+                       if(para[cx]>8191){para[cx]=8191;}
+                       if(vmo!=0 && para[cx]>127){para[cx]=127;}
+               }
+/*
+               if( ke==0x39 ){
+                       if((sh&1)==0){para[cx]=para[cx]-ys*4;}else{para[cx]=para[cx]-yss*4;}
+                       if(para[cx]<-8192){para[cx]=-8192;}
+                       if(vmo!=0 && para[cx]<0){para[cx]=0;}
+               }
+               if( ke==0x38 ){
+                       if((sh&1)==0){para[cx]=para[cx]+ys*4;}else{para[cx]=para[cx]+yss*4;}
+                       if(para[cx]>8191){para[cx]=8191;}
+                       if(vmo!=0 && para[cx]>127){para[cx]=127;}
+               }
+*/
+
+/*f1*/
+               if( ke>=0x63 && ke<=0x64){
+                       vis_disp(co,cx,ccx,para,step,1,2,vmo);
+               }
+               if( ke==0x63 && (sh&1)==0){cx=0;ke=0;}
+               if( ke==0x64 && (sh&1)==0){cx=co-1;ke=0;}
+
+               if( ke>=0x63 && ke<=0x6c ){
+                       vis_wave(st,co,cx,ccx,para,step,ke-0x63+(sh&1)*16,vmo);
+                       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+                       if((sh&1)==0){fnc_dis(5);}else{fnc_dis(6);}
+               }
+
+               if( kc=='X' ){
+                       int j;
+                       vis_disp(co,cx,ccx,para,step,1,2,vmo);
+                       msg("STEP=");j=vinput(2,0x804);msg_clr();
+                       if( es==0 && j>0 ){
+                               co=vis_cut(co,j,para,step);extmd=1;
+                       }
+                       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+                       fnc_dis(5);
+               }
+               if( kc=='Z' ){
+                       int j;
+                       vis_disp(co,cx,ccx,para,step,1,2,vmo);
+rezm:
+                       msg("STEP=");j=vinput(st,0x804);msg_clr();
+
+                       if( es==0 && j>0 ){
+                         if(j>barlen*8){msg(_("Too many data."));goto rezm;}
+                         else{vis_zom(co,st,j,step,step);extmd=1;}
+                       }
+                       goto redraw;
+               }
+
+               if( kc=='I' ){
+                       int j;
+                       vis_disp(co,cx,ccx,para,step,1,2,vmo);
+reis:
+                       if((sh&1)!=0){
+                               msg("Change STEP=");j=vinput(step[cx],0x804);msg_clr();
+
+                               if( es==0 && j>0 ){
+                                       if(st+j>barlen*8){msg(_("Too many data."));goto reis;}
+                                       else{
+                                               step[cx]=j;extmd=1;}
+                               }
+                       }else{
+                               if(co<768){
+                                       msg("Insert STEP=");j=vinput(0,0x804);msg_clr();
+
+                                       if( es==0 && j>0 ){
+                                               if(st+j>barlen*8){msg(_("Too many data."));goto reis;
+                                               }else{
+                                                       for(i=co;i>cx;i--){step[i]=step[i-1];para[i]=para[i-1];}
+                                                       co++;st+=j;
+                                                       step[cx]=j;extmd=1;}
+                                       }
+                               }
+                       }
+                       goto redraw;
+
+               }
+
+               if( kc=='D' && co>1 ){
+                       if((sh&1)!=0){
+                               int j;
+                               vis_disp(co,cx,ccx,para,step,1,2,vmo);
+
+                               msg("Delete STEP=");j=vinput(step[cx],0x804);msg_clr();
+
+                               if( es==0 && j>0 ){
+                                       st-=j;
+                                       while(j){
+                                               if(step[cx]>j){step[cx]-=j;j=0;
+                                               }else{
+                                                       j-=step[cx];
+                                                       for(i=cx;i<co;i++){step[i]=step[i+1];para[i]=para[i+1];}
+                                                       co--;
+                                               }
+                                       }
+                                       extmd=1;
+                                       goto redraw;
+                               }
+                       }else{
+                               if(st>step[cx]){
+                                       st-=step[cx];
+                                       for(i=cx;i<co;i++){step[i]=step[i+1];para[i]=para[i+1];}
+                                       co--;
+                                       extmd=1;
+                                       goto redraw;
+                               }
+                       }
+               }
+
+               if( kc=='C' ){
+                       co=vis_lnk(co,para,step);extmd=1;cx=0;ccx=-1;
+                       vis_disp(co,cx,ccx,para,step,0,1,vmo);
+                       fnc_dis(5);
+               }
+
+               if( ke==0x10 ){
+                       int j;
+                       vis_disp(co,cx,ccx,para,step,1,2,vmo);
+                       msg("JUMP POSITION=");j=vinput(0,3);msg_clr();
+                       if( es==0 && j>0 ){if( j<=co ){cx=j-1;}else{cx=co-1;}}
+               }
+
+               if(kc=='M'||ke==0x55 ||ke==0x3a){
+                       if(((sh&1)==0 && ln==0) || trk[track][po]==0xfe){
+                               int cc;
+                               cc=vis_bufset(po,co,para,step,vmo,0);
+                               if(trk_shift(po,cc)==0){
+                                       memcpy_l(&ptr[po],dat2,cc);
+                                       poplay(po,3);trk_delete(po,cc);
+                               }
+                       }else{
+                               int ll;ll=tr_len[track];
+                               cpleng=0;
+                               memcpy_l(cpbuf,trk[track],ll);
+                               if(vis_ext_mix(po,co,para,step,vmo,ost)==0){
+                               poplay(po,3);}
+
+                               memcpy_l(trk[track],cpbuf,ll);
+                               tr_len[track]=ll;
+                       }
+               }
+
+       }
+       B_CLR_AL();fnc_dis(0);fill(7+XB,544,767,1001,0);snsclr();
+if((cmdflag&0x200)==0){
+       MS_LIMIT(0,0,767,511);MS_CUROF();
+}
+       if(kc==13){
+               if(ln==0){
+                       int     ad;
+                       co=vis_lnk(co,para,step);
+                       ad=po;
+
+                       if(((sh&1)==0 && ln==0) || trk[track][po]==0xfe){
+                               int mm,cc;
+                               undobuf(0);
+
+                               if(trk[track][po]==0xfe){mm=1;}else{mm=0;}
+                               cc=vis_bufset(po,co,para,step,vmo,mm);
+
+                               if(trk_check(cc)==0){
+                                       line_ins_aft(po);trk_shift(po,cc);
+                                       memcpy_l(&ptr[po],dat2,cc);
+                                       ad+=cc;
+                               }
+                               po=ad;
+                       }else{
+                               vis_ext_mix(po,co,para,step,vmo,ost);
+                       }
+               }else{
+                       if(extmd==0){
+                               vis_a_out(po,ln,para,step,vmo);
+                       }else{
+                               co=vis_lnk(co,para,step);
+                               vis_ext_mix(po,co,para,step,vmo,ost);
+                       }
+               }
+       }
+
+       edit_scr=eds;
+       if(ssh&1){edfield(0);}
+ext:
+       edit_scr=eds;cons_md(1);
+       return(po);
+}
+
+/***************************/
+int    vis_bufset(int po,int co,int *para,int *step,int vmo,int bf)
+{
+       int     ad=0,i,j,barlen,st=0,s,excc=0;
+
+if(excget){
+       int ad2=po;
+       while(trk[track][ad2+4]==0xf7){ad2+=4;excc+=4;}
+}
+
+       barlen = tbase*4*beat1/beat2;
+
+       if(bf){
+               st=step_cluc(po);
+               while(st>=barlen){st-=barlen;dat2[ad]=0xfd;ad+=4;}
+       }
+
+       for(i=0;i<co;i++){
+               if(vmo==0){
+                       dat2[ad]=0xee;
+                       j=(para[i])+8192;if(j<0){j=0;}
+                       if(j>16383){j=16383;}
+                       dat2[ad+2]=j&0x7f;dat2[ad+3]=j>>7;
+               }else{
+                       if(vmo<128){
+                               dat2[ad]=0xeb;dat2[ad+2]=vmo;
+                       }else{
+                               dat2[ad]=vmo;dat2[ad+2]=0;dat2[ad+3]=0;
+                       }
+                       j=para[i];if(j<0){j=0;}
+                       if(vmo==0xea || vmo==0xe7){dat2[ad+2]=j;}else{dat2[ad+3]=j;}
+/*                     if(vmo==0xde){dat2[ad+2]=vmo2;}*/
+if(vmo<=0x98 || vmo==0xed || vmo==0xde ){dat[ad+2]=vmo2;}
+
+if(excget){
+       int ad2=po+4,i2;
+       dat2[ad+1]=0;
+
+       for(i2=0;i2<excc;i2++){dat2[ad+4]=trk[track][ad2++];ad++;}
+
+       dat2[ad]=0;dat2[ad+1]=0;dat2[ad+2]=0;dat2[ad+3]=0;
+}
+               }
+
+               s=step[i];
+top:
+               dat2[ad+1]=s;
+               ad=ad+4;
+
+               if(bf){
+                       if(st+s<barlen){
+                               st+=s;
+                       }else{
+                               if(st+s==barlen){
+                                       dat2[ad]=0xfd;ad+=4;st=0;
+                               }else{
+                                       int ss=barlen-st;
+
+                                       dat2[ad-3]=ss;
+                                       dat2[ad]=0xfd;ad+=4;
+                                       s-=ss;st=0;
+
+                                       if(s){
+                                               dat2[ad]=0;dat2[ad+2]=0;dat2[ad+3]=0;
+                                               goto top;
+                                       }
+                               }
+                       }
+               }
+
+       }
+       return(ad);
+}
+
+int    b2_set(int ad,int ln)
+{
+       while(ln>240){
+               ln-=240;
+               dat2[ad++]=0;dat2[ad++]=240;
+               dat2[ad++]=0;dat2[ad++]=0;
+       }
+       if(ln){
+               dat2[ad++]=0;dat2[ad++]=ln;
+               dat2[ad++]=0;dat2[ad++]=0;
+       }
+       return ad;
+}
+
+/***************************/
+int    vis_ext_mix(int po,int co,int *para,int *step,int vmo,int ost)
+{
+       int     ad,i,ec,ttc;
+
+       ttc=1;for(i=0;i<co-1;i++){ttc+=step[i];}
+       if(ost>ttc){ttc=ost;}
+
+       ad=po;
+       while(ad<tr_len[track] && ttc>0){
+               if(vmo==0){
+                       if(trk[track][ad]==0xee){
+                               trk[track][ad]=0;trk[track][ad+2]=0;trk[track][ad+3]=0;
+                       }
+               }else{
+                       if(vmo<128){
+                               if(trk[track][ad]==0xeb && trk[track][ad+2]==vmo){
+                                       trk[track][ad]=0;trk[track][ad+2]=0;trk[track][ad+3]=0;
+                               }
+                       }else{
+                               if(trk[track][ad]==vmo){
+                                       trk[track][ad]=0;trk[track][ad+2]=0;trk[track][ad+3]=0;
+if(excget){
+                                       if(vmo==0x98){
+                                               while(trk[track][ad+4]==0xf7){
+                                                       trk[track][ad]=0;trk[track][ad+1]=0;
+                                                       trk[track][ad+2]=0;trk[track][ad+3]=0;
+                                                       ad+=4;
+                                               }
+                                       }
+}
+                               }
+                       }
+               }
+               if(trk[track][ad]<0xf0){ttc-=trk[track][ad+1];}
+               ad+=4;
+       }
+
+       ad=vis_bufset(po,co,para,step,vmo,0);
+       dat2[ad]=0xfe;
+       ec=trk_mix_sub(trk[track]+po,dat2);
+
+       if(size_change(track,po+ec)){return 1;}
+
+       dat[ec]=0xfe;ec+=4;
+       memcpy_l(&trk[track][po],dat,ec);
+       tr_len[track]=po+ec;
+       return(0);
+}
+
+/***************************/
+int    vis_a_in(int po,int ln,int *para,int *step,int vmo)
+{
+       int     ad,i,j,no=0,st=0;
+       unsigned char *ptr=trk[track];
+
+       ad=po;
+       for(i=0;i<ln;i+=4){
+               if(vmo==0){
+                       if(ptr[ad]==0xee){
+                               j=ptr[ad+2]+ptr[ad+3]*128;
+                               step[no]=0;para[no++]=(j-8192);
+                       }
+               }else{
+                       if(vmo<128){
+                               if(ptr[ad]==0xeb){
+                                       unsigned char cc=ptr[ad+2];
+                                       step[no]=0;if(vmo==cc){para[no++]=ptr[ad+3];}
+                               }
+                       }else{
+                               if(ptr[ad]==vmo){
+                                       step[no]=0;para[no++]=ptr[ad+3];
+                                       if(vmo==0xea||vmo==0xe7){para[no-1]=ptr[ad+2];}
+                               }
+                       }
+               }
+               if(no>0 && ptr[ad]<0xf0 && ptr[ad+1]>0){
+                       st+=ptr[ad+1];
+
+                       if(step[no-1]+ptr[ad+1]<=240){
+                               step[no-1]+=ptr[ad+1];
+                       }else{
+                               step[no]=step[no-1];
+                               para[no]=para[no-1];
+                               no++;
+                       }
+               }
+               ad=ad+4;
+       }
+       return(no);
+}
+
+/***************************/
+int    vis_a_in_co(int po,int ln,int vmo)
+{
+       int     ad,i,no=0;
+       unsigned char *ptr=trk[track];
+
+       ad=po;
+       for(i=0;i<ln;i+=4){
+               if(vmo==0){
+                       if(ptr[ad]==0xee){no++;}
+               }else{
+                       if(vmo<128){
+                               if(ptr[ad]==0xeb && ptr[ad+2]==vmo){no++;}
+                       }else{
+                               if(ptr[ad]==vmo){no++;}
+                       }
+               }
+               ad=ad+4;
+       }
+       return(no);
+}
+
+/***************************/
+int    vis_a_in_st(int po,int ln)
+{
+       int     ad,i,st=0;
+       unsigned char *ptr=trk[track];
+
+       ad=po;
+       for(i=0;i<ln;i+=4){
+               if(ptr[ad]<0xf0 && ptr[ad+1]>0){
+                       st+=ptr[ad+1];
+               }
+               ad=ad+4;
+       }
+       return(st);
+}
+
+/***************************/
+void   vis_a_out(int po,int ln,int *para,int *step,int vmo)
+{
+       int     ad,i,j,no=0;
+       unsigned char *ptr=trk[track];
+
+       ad=po;
+       for(i=0;i<ln;i+=4){
+               if(vmo==0){
+                       if(ptr[ad]==0xee){
+                               j=(para[no++])+8192;
+                               ptr[ad+2]=j&0x7f;ptr[ad+3]=j>>7;
+                       }
+               }else{
+                       if(vmo<128){
+                               if(ptr[ad]==0xeb){
+                                       if(vmo==ptr[ad+2]){ptr[ad+3]=para[no++];}
+                               }
+                       }else{
+                               if(ptr[ad]==vmo){
+                                       if(vmo==0xea||vmo==0xe7){ptr[ad+2]=para[no++];}
+                                       else{ptr[ad+3]=para[no++];}
+/*                                     if(vmo==0xde){ptr[ad+2]=vmo2;}*/
+if(vmo<=0x98 || vmo==0xed || vmo==0xde ){dat[ad+2]=vmo2;}
+                               }
+                       }
+               }
+               ad=ad+4;
+       }
+}
+
+/***************************/
+void   vis_disp(int co,int cx,int ccx,int *para,int *step,int mo,int c,int vmo)
+{
+       int     b,i,gx,op,yy,cl,of,st=0;
+       int     step2[769];
+
+       if(c==0){cl=0;of=1;}else{cl=65535;of=2;}
+       for(i=0;i<co;i++){st+=step[i];}
+
+       vis_zom(co,st,maxdot,step,step2);
+
+       if(mo==0){txerase(10+XB,768-512-128,758-XB-10+4,257);}
+       gx=18+XB;op=para[768];if(vmo==0){op=(op*yzm)>>6;}else{if(yzm>1){op=(op<<1)-127;}}
+
+       i=0;
+       while(gx<760 && i<co){
+               int     pp=para[i];if(vmo==0){pp=(pp*yzm)>>6;}else{if(yzm>1){pp=(pp<<1)-127;}}
+               b=step2[i];
+
+               if(mo==0 ||(i>=cx-of && i<=cx+of)){
+                       if(c!=2 && i==cx){txyline(gx,256-128,257,1,cl);}
+
+                       if(b>1 && pp>=-128 && pp<=128){txxline(gx+1,256-pp,b-1,0,cl);}
+
+                       yy=op-pp;if(yy<0){op-=yy;yy=-yy;}
+                       if(b<2 && yy==0){yy=1;} 
+
+                       if(op>128){yy-=(op-128);op-=(op-128);}
+
+                       if(op<-128){yy=0;op-=(-128-op);}
+                       if(op-yy<-128){yy-=(-128-(op-yy));}
+
+                       if(yy>0){txyline(gx,256-op,yy,0,cl);}
+
+               }
+               if(mo==0 || i==ccx){
+                       if(c!=2 && i==ccx){txyline(gx,256-128,257,0,cl&0xaaaa);}
+               }
+               op=pp;gx=gx+b;i++;
+       }
+       snsclr();
+}
+
+/***************************/
+void   vis_wave(int st,int co,int cx,int ccx,int *para,int *step,int md,int vmo)
+{
+       int     i,ct,ct2,ct3,ct4,max_p,min_p,xx,ln,sh,sst,xp;
+       int     xc=2;
+       float f;
+
+       sh=md>>4;md=md & 0xf;
+       xx=cx;ln=ccx-cx+1;if(ccx<cx){xx=ccx;ln=cx-ccx+1;}
+       if(ccx<0){xx=0;ln=co;}
+       if(ln<2){return;}
+
+       ct=para[xx];ct2=para[xx+ln-1];ct3=(ct2-ct);
+       if( md>=3 && md<=5 ){
+               if(ct3<0){sh=1-sh;}
+               if(ct==ct2){md=2;sh=0;}
+       }
+       ct4=ct3;if(ct4<0){ct4--;}else{ct4++;}
+
+       if(ccx<0){bunkatsu(st,ln,&step[xx]);}
+       max_p=0;min_p=65535;sst=0;xp=0;
+       for(i=0;i<ln;i++){
+               if(max_p<para[xx+i]){max_p=para[xx+i];}
+               if(min_p>para[xx+i]){min_p=para[xx+i];}
+
+               sst+=step[xx+i];
+       }
+
+       if(sh!=0 && md>=7){
+reco:
+               msg("wave count=");i=vinput(0,4);msg_clr();
+               if( es!=0 ){return;}
+               xc=i*2;
+               if( xc<2 || xc>ln){goto reco;}
+       }
+
+       for(i=0;i<ln;i++){
+               if(md==0){if(vmo!=0){para[xx+i]=127-para[xx+i];}
+                       else{para[xx+i]=(8191-(para[xx+i]+8191));}}
+               if(md==1){int a;if(i>=(ln>>1)){break;}
+                       a=para[xx+i];para[xx+i]=para[xx+(ln-1-i)];para[xx+(ln-1-i)]=a;}
+
+               if(md==2){                                                      /*LINE&RND*/
+                       if(sh==0 || ct==ct2){para[xx+i]=ct+(ct3*i/(ln-1));
+                       }else{
+                               para[xx+i]=min_p+(rand()*(max_p-min_p+1)/32767);
+                       }
+               }
+
+
+               if(md==4 && i>0 && i<ln-1){                                     /*WAVE B*/
+                       if(sh==0){para[xx+i]=ct+ct4*sin(PID2*i/(ln-1));}
+                       else{para[xx+i]=ct2-(ct4*cos(PID2*i/(ln-1)));}
+               }
+               if(md==5){                                                      /*WAVE C*/
+                       if(sh==0){para[xx+i]=ct+(ct3*curv_tbl[191*i/(ln-1)]/127);
+                       }else{para[xx+i]=ct2-(ct3*curv_tbl[191-(191*i/(ln-1))]/127);}
+               }
+
+               if(md==6){                                                      /*OKA&TANI*/
+                       if(sh==0){f=min_p+(sin(PI*i/(ln-1))*(max_p-min_p));
+                       }else{f=max_p-(sin(PI*i/(ln-1))*(max_p-min_p));}
+                       goto fix;
+               }
+               if(md==7){                                                      /*SIN WAVE*/
+                       f=((max_p+min_p)>>1)+(sin(PI*i*xc/(ln-1))*((max_p-min_p+1)>>1));
+fix:
+                       if(f>0){f+=.5;}
+                       if(f<0){f-=.5;if(vmo){f=-f;}}
+                       para[xx+i]=f;
+               }
+               if(md==8 && max_p!=min_p){                                      /*triangle*/
+                       int a;
+
+                       a=((max_p+min_p)>>1)+(max_p-min_p)*xc*(i+1)/ln;
+                       while(a<min_p||a>max_p){
+                               if(a>max_p){a=max_p-(a-max_p);}
+                               if(a<min_p){a=min_p-(a-min_p);}
+                       }
+                       para[xx+i]=a;
+               }
+               if(md==9){
+                       int a;
+                       if(((int)(i/(ln/xc))&1)==0){a=max_p;}else{a=min_p;}
+                       para[xx+i]=a;
+               }
+               xp+=step[xx+i];
+       }
+}
+
+void   bunkatsu(int st,int co,int *da)
+{
+       int i,c=0,d;
+
+       for(i=1;i<=co;i++){
+               d=(st*i/co);da[i-1]=d-c;c+=(d-c);
+       }
+}
+
+/***************************/
+int    vis_cut(int co,int st,int *para,int *step)
+{
+       int     para2[768],step2[768];
+       int     cc=0,i,a,b;
+
+       for(i=0;i<co;i++){
+               a=step[i];b=para[i];
+
+               while(a>st && cc<768){step2[cc]=st;para2[cc]=b;cc++;a-=st;}
+               if(a && cc<768){step2[cc]=a;para2[cc]=b;cc++;}
+       }
+
+       memcpy(para,para2,cc*4);
+       memcpy(step,step2,cc*4);
+       return cc;
+}
+
+int    vis_lnk(int co,int *para,int *step)
+{
+       int     cc=0,i;
+
+       for(i=0;i<co;i++){
+               if(cc>0 && para[cc-1]==para[i] && (step[cc-1]+step[i])<=240){
+                       step[cc-1]+=step[i];
+               }else{
+                       para[cc]=para[i];step[cc]=step[i];cc++;
+               }
+       }
+
+       return cc;
+}
+
+void   vis_zom(int co,int in_step,int out_step,int *step,int *step2)
+{
+       int     i,st=0,stx=0,dt;
+
+/*     if( in_step != out_step ) */{
+               for(i=0;i<co;i++){
+                       dt=step[i];
+
+                       st += dt;
+                       dt = ( st * out_step / in_step ) - stx;
+                       stx += dt;
+
+                       step2[i]=dt;
+               }
+       }
+}
+
+/***************************/
diff --git a/win32_color.cpp b/win32_color.cpp
new file mode 100644 (file)
index 0000000..76e09a4
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+  win32_color.cpp
+  base class of screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+
+#include "sted_screen_win32.h"
+
+// private
+COLORREF
+CSTedScreenWin32::PageToColor(int in_page)
+{
+  int c = 0;
+  COLORREF r;
+
+  switch (in_page) {
+         case 0: c=1;break;
+         case 1: c=2;break;
+         case 2: c=3;break;
+         case 3: c=0;break;
+  }
+
+  r = RGB(fTextPalette[c].fBlue,
+         fTextPalette[c].fGreen,
+         fTextPalette[c].fRed);
+  return r;
+}
+
+// color
+int
+CSTedScreenWin32::SetGraphicsPalette(int in_pal, int in_color)
+{
+  int r,g,b;
+
+  if (in_pal<0 || in_pal>=fMaxGraphicsColor) return 0;
+
+  r=((in_color>>6)&0x001f)<<3;
+  b=((in_color>>1)&0x001f)<<3;
+  g=((in_color>>11)&0x001f)<<3;
+
+  fGraphicsPalette[in_pal].fRed = r;
+  fGraphicsPalette[in_pal].fGreen = g;
+  fGraphicsPalette[in_pal].fBlue = b;
+
+  return 0;
+}
+
+int
+CSTedScreenWin32::SetTextPalette(int in_pal, int in_color)
+{
+  int r,g,b;
+  if (in_pal<0 || in_pal>=fMaxTextColor) return 0;
+
+  r=((in_color >> 6) &0x001f)<<3;
+  b=((in_color >> 1) &0x001f)<<3;
+  g=((in_color >> 11)&0x001f)<<3;
+
+  fTextPalette[in_pal].fRed = r;
+  fTextPalette[in_pal].fGreen = g;
+  fTextPalette[in_pal].fBlue = b;
+
+  return 0;
+}
+
+int
+CSTedScreenWin32::SetGraphicsColor(int in_color)
+{
+  COLORREF r;
+
+  if (in_color<0 || in_color>=fMaxGraphicsColor) return 0;
+
+  fCurrentGraphicsColor = in_color;
+  r = RGB(fGraphicsPalette[in_color].fBlue, 
+         fGraphicsPalette[in_color].fGreen, 
+         fGraphicsPalette[in_color].fRed);
+
+  //::SetTextColor(fGraphicsWindowDC[0], r);
+  //::SetTextColor(fGraphicsWindowDC[1], r);
+  //::SetBkMode(fGraphicsWindowDC[0], TRANSPARENT);
+  //::SetBkMode(fGraphicsWindowDC[1], TRANSPARENT);
+
+  return r;
+}
+
+int
+CSTedScreenWin32::SetTextColor(int in_color)
+{
+  int c;
+  int lastcolor;
+  COLORREF rgb;
+  BOOL invert = FALSE;
+
+  c = in_color;
+  if (c&0x08) { // reverse
+       invert = TRUE;
+       c&=0x03;
+  }
+  lastcolor = fCurrentTextColor;
+
+  rgb = RGB(fTextPalette[c].fBlue,
+           fTextPalette[c].fGreen,
+           fTextPalette[c].fRed);
+
+  if (invert) {
+
+       //::SetTextColor(fTextDC, RGB(0xff, 0xff, 0xff));
+       //::SetBkColor(fTextDC, rgb);
+       //::SetTextColor(fTextMaskDC, RGB(0x00, 0x00, 0x00));
+       //::SetBkColor(fTextMaskDC, RGB(0xff, 0xff, 0xff));
+       fCurrentTextColor = 0;
+       fCurrentTextBackColor = c;
+  } else {
+       //::SetTextColor(fTextDC, rgb);
+       //::SetBkColor(fTextDC, RGB(0xff, 0xff, 0xff));
+       //::SetTextColor(fTextMaskDC, RGB(0xff, 0xff, 0xff));
+       //::SetBkColor(fTextMaskDC, RGB(0x00, 0x00, 0x00));
+       fCurrentTextColor = c;
+       fCurrentTextBackColor = 0;
+  }
+
+ /* ::SetBkMode(fTextDC, OPAQUE);
+  ::SetBkMode(fTextMaskDC, OPAQUE);*/
+
+  return lastcolor;
+}
diff --git a/win32_file.cpp b/win32_file.cpp
new file mode 100644 (file)
index 0000000..3102e05
--- /dev/null
@@ -0,0 +1,185 @@
+/*
+  win32_file.cpp
+  file related drivers
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <direct.h>
+#include "sted_screen.h"
+#include "sted_screen_win32.h"
+#define WIN32_DELETE DELETE
+#undef DELETE
+#include "doslib.h"
+#undef DELETE
+#define DELETE WIN32_DELETE
+
+// file related
+dosmode_t
+CSTedScreenWin32::FileChmod(const char* in_name, dosmode_t in_atr)
+{
+       struct _stat stt;
+
+       if (!in_name) return 0;
+
+       if (in_atr==-1) {
+               if (_stat(in_name, &stt)) return 0;
+               if (stt.st_mode&_S_IFDIR) return 0x10;
+               return 0;
+       } else {
+           return 0;
+       }
+}
+
+int
+CSTedScreenWin32::FileChdir(const char* in_name)
+{
+       if (!in_name) return -1;
+
+       return _chdir(in_name);
+}
+
+int
+CSTedScreenWin32::FileCurdir(int in_drive, char* out_buff)
+{
+       char* buf;
+       if (!out_buff) return -1;
+       if (in_drive<0 || in_drive>=27) return -1;
+
+
+       buf = _getdcwd(in_drive, NULL, 128);
+       if (!buf) return -1;
+
+       ::strncpy(out_buff, buf+3, 128);
+       ::free((void *)buf);
+       return 0;
+}
+
+int
+CSTedScreenWin32::FileCurdrv(void)
+{
+    return _getdrive()-1;
+}
+
+int
+CSTedScreenWin32::FileDelete(const char* in_name)
+{
+       if (!in_name) return -1;
+       return _unlink(in_name);
+}
+
+int
+CSTedScreenWin32::FileRename(const char* in_name, const char* in_newname)
+{
+       if (!in_name || !in_newname) return -1;
+    return rename(in_name, in_newname);
+}
+
+int
+CSTedScreenWin32::FileFiles(struct _x68_filbuf *in_buff, const char *in_name, int in_atr)
+{
+       HANDLE h;
+       char* p;
+       int len;
+       LPCTSTR u;
+       WIN32_FIND_DATA data;
+       SYSTEMTIME tm;
+
+       if (fFileDirHandle) {
+               ::FindClose(fFileDirHandle);
+               fFileDirHandle = NULL;
+       }
+
+       u = toUCS2(in_name, (int)::strlen(in_name), &len);
+       h = ::FindFirstFile(u, &data);
+
+       if (!h) return -3;
+
+       if (!::FileTimeToSystemTime(&data.ftLastWriteTime, &tm)) return -3;
+
+       in_buff->atr = (unsigned char)(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY?0x10:0x01);
+       if (data.nFileSizeHigh>0) {
+               in_buff->filelen = (unsigned int)MAXDWORD;
+       } else {
+               in_buff->filelen = (unsigned int)data.nFileSizeLow;
+       }
+       in_buff->date = (unsigned short)((tm.wYear%100)<<9 | (tm.wMonth-1)<<5 | tm.wDay);
+       in_buff->time = (unsigned short)(tm.wHour<<11 | tm.wMinute<<5 | (tm.wSecond/2));
+       p = (char *)toSJIS(data.cFileName, NULL);
+       ::strncpy(in_buff->name, p,  22);
+       in_buff->name[22] = '\0';
+
+       fFileDirHandle = h;
+       
+       return 0;
+}
+
+int
+CSTedScreenWin32::FileNfiles(struct _x68_filbuf *in_buff)
+{
+       char* p;
+       WIN32_FIND_DATA data;
+       SYSTEMTIME tm;
+
+       if (!fFileDirHandle) return -3;
+
+       if (!::FindNextFile(fFileDirHandle, &data)) {
+               if (::GetLastError()==ERROR_NO_MORE_FILES) {
+                       ::FindClose(fFileDirHandle);
+                       fFileDirHandle = NULL;
+                       return -3;
+               } else {
+                       ::FindClose(fFileDirHandle);
+                       fFileDirHandle = NULL;
+                       return -3;
+               }
+       }
+
+       if (!::FileTimeToSystemTime(&data.ftLastWriteTime, &tm)) {
+               ::FindClose(fFileDirHandle);
+               fFileDirHandle = NULL;
+               return -3;
+       }
+
+       in_buff->atr = (unsigned char)(data.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY?0x10:0x21);
+       if (data.nFileSizeHigh>0) {
+               in_buff->filelen = (unsigned int)MAXDWORD;
+       } else {
+               in_buff->filelen = (unsigned int)data.nFileSizeLow;
+       }
+       in_buff->date = (unsigned short)((tm.wYear%100)<<9 | (tm.wMonth-1)<<5 | tm.wDay);
+       in_buff->time = (unsigned short)(tm.wHour<<11 | tm.wMinute<<5 | (tm.wSecond/2));
+       p = (char *)toSJIS(data.cFileName, NULL);
+       ::strncpy(in_buff->name, p,  22);
+       in_buff->name[22] = '\0';
+
+       return 0;
+}
+
+FILE*
+CSTedScreenWin32::FileFopen(const char* in_name, const char* in_mode)
+{
+       return ::fopen(in_name, in_mode);
+}
+
diff --git a/win32_graphics.cpp b/win32_graphics.cpp
new file mode 100644 (file)
index 0000000..8c87e8b
--- /dev/null
@@ -0,0 +1,652 @@
+/*
+  win32_graphics.cpp
+  base class of screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+#include "sted_screen_win32.h"
+
+// graphics
+
+// private
+
+BOOL
+CSTedScreenWin32::toWindowPos(int in_x, int in_y, int *out_x, int *out_y)
+{
+  if (out_x) *out_x = fWindowWidth * in_x / fX68WindowWidth;
+  if (out_y) *out_y = fWindowHeight * (in_y%fX68WindowHeight) / fX68WindowHeight;
+  return TRUE;
+}
+
+// apis
+
+void
+CSTedScreenWin32::TextXBox(int in_x0, int in_y0, int in_x1, int in_y1, int in_page)
+{
+  int x0, y0, x1, y1;
+  HBRUSH br, mbr;
+  COLORREF c;
+  RECT r;
+
+  c = PageToColor(in_page);
+  if (!toWindowPos(in_x0, in_y0, &x0, &y0)) return;
+  if (!toWindowPos(in_x1, in_y1, &x1, &y1)) return;
+
+  ::SetRect(&r, x0, y0, x1, y1);
+  //zz
+  D2D1_RECT_F r1(D2D1::RectF(x0,y0,x1,y1));
+  D2D1_COLOR_F color = D2D1::ColorF(c);
+  ID2D1SolidColorBrushPtr color_brush;
+
+  text_bitmap_target_->CreateSolidColorBrush(color,&color_brush);
+  {
+    sf::begin_draw<ID2D1BitmapRenderTargetPtr> b(text_bitmap_target_);
+
+    D2D1_ANTIALIAS_MODE backup(text_bitmap_target_->GetAntialiasMode());
+    text_bitmap_target_->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+
+    if (in_page != 0) 
+    {
+      text_bitmap_target_->DrawRectangle(r1,color_brush);
+           //br = ::CreateSolidBrush(c);
+           //mbr = MASK_ON;
+    } else {
+      text_bitmap_target_->DrawRectangle(r1,brush_text_clear_);
+           //br = fBrushTextClear;
+           //mbr = MASK_OFF;
+    }
+    text_bitmap_target_->SetAntialiasMode(backup);
+    THROW_IF_ERR(b.end_draw());
+  }
+//  if (!br) return;
+
+//  ::FrameRect(fTextDC, &r, br);
+//  ::FrameRect(fTextMaskDC, &r, MASK_ON);
+
+//  if (in_page!=0)
+//       ::DeleteObject(br);
+  InvalidateRect(&r);
+}
+
+void 
+CSTedScreenWin32::TextXXLine(int in_page, int in_x, int in_y, int in_w, int in_linestyle)
+{
+  int x0, x1;
+  int y;
+  HPEN p,mp;
+  HPEN orig, morig;
+
+  if (!toWindowPos(in_x, in_y, &x0, &y)) return;
+  if (!toWindowPos(in_x + in_w, in_y, &x1, &y)) return;
+
+  ID2D1SolidColorBrushPtr brush;
+  
+  
+  sf::begin_draw_bitmap begin(text_bitmap_target_);
+
+  if (in_linestyle != 0 /*&& in_page!=0*/) {
+    text_bitmap_target_->CreateSolidColorBrush(D2D1::ColorF(PageToColor(in_page)),&brush);
+  } else {
+    text_bitmap_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),&brush);
+  }
+
+  D2D1_ANTIALIAS_MODE backup(text_bitmap_target_->GetAntialiasMode());
+  text_bitmap_target_->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+  text_bitmap_target_->DrawLine(D2D1::Point2F(x0,y),D2D1::Point2F(x1,y),brush);
+  text_bitmap_target_->SetAntialiasMode(backup);
+
+  //if (in_linestyle != 0 /*&& in_page!=0*/) 
+  //{
+        // p = ::CreatePen(PS_SOLID, 1, PageToColor(in_page));
+        // mp = ::CreatePen(PS_SOLID, 1, RGB(0xff, 0xff, 0xff));
+  //} else {
+        // p = ::CreatePen(PS_SOLID, 1, RGB(0xff, 0xff, 0xff));
+        // mp = ::CreatePen(PS_SOLID, 1, RGB(0x00, 0x00, 0x00));
+  //}
+
+  //if (!p || !mp) 
+  //{
+        // if (p) ::DeleteObject(p);
+        // if (mp) ::DeleteObject(mp);
+        // return;
+  //}
+
+  //orig = (HPEN)::SelectObject(fTextDC, p);
+  //morig = (HPEN)::SelectObject(fTextMaskDC, mp);
+
+  //::MoveToEx(fTextDC, x0,y, NULL);
+  //::LineTo(fTextDC, x1,y);
+  //::MoveToEx(fTextMaskDC, x0,y, NULL);
+  //::LineTo(fTextMaskDC, x1,y);
+
+  //::SelectObject(fTextDC, orig);
+  //::SelectObject(fTextMaskDC, morig);
+  //if (p) ::DeleteObject(p);
+  //if (mp) ::DeleteObject(mp);
+  THROW_IF_ERR(begin.end_draw());
+
+  InvalidateRect(x0,y,x1-x0,1);
+}
+
+void
+CSTedScreenWin32::TextXYLine(int in_page, int in_x, int in_y, int in_h, int in_linestyle)
+{
+  int x;
+  int y0, y1;
+  HPEN p,mp;
+  HPEN orig, morig;
+
+  if (!toWindowPos(in_x, in_y, &x, &y0)) return;
+  if (!toWindowPos(in_x, in_y+in_h, &x, &y1)) return;
+
+  ID2D1SolidColorBrushPtr brush;
+  sf::begin_draw_bitmap begin(text_bitmap_target_);
+
+  if (in_linestyle != 0 /*&& in_page!=0*/) {
+    text_bitmap_target_->CreateSolidColorBrush(D2D1::ColorF(PageToColor(in_page)),&brush);
+  } else {
+    text_bitmap_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::White),&brush);
+  }
+  D2D1_ANTIALIAS_MODE backup(text_bitmap_target_->GetAntialiasMode());
+  text_bitmap_target_->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+  text_bitmap_target_->DrawLine(D2D1::Point2F(x,y0),D2D1::Point2F(x,y1),brush);
+  text_bitmap_target_->SetAntialiasMode(backup);
+
+  THROW_IF_ERR(begin.end_draw());
+
+  //if (in_linestyle!=0 /*&& in_page!=0*/) {
+        // p = ::CreatePen(PS_SOLID, 1, PageToColor(in_page));
+        // mp = ::CreatePen(PS_SOLID, 1, RGB(0xff, 0xff, 0xff));
+  //} else {
+        // p = ::CreatePen(PS_SOLID, 1, RGB(0xff, 0xff, 0xff));
+        // mp = ::CreatePen(PS_SOLID, 1, RGB(0x00, 0x00, 0x00));
+  //}
+  //if (!p || !mp) {
+        // if (p) ::DeleteObject(p);
+        // if (mp) ::DeleteObject(mp);
+        // return;
+  //}
+
+  //orig = (HPEN)::SelectObject(fTextDC, p);
+  //morig = (HPEN)::SelectObject(fTextMaskDC, mp);
+
+  //::MoveToEx(fTextDC, x,y0, NULL);
+  //::LineTo(fTextDC, x,y1);
+  //::MoveToEx(fTextMaskDC, x,y0, NULL);
+  //::LineTo(fTextMaskDC, x,y1);
+
+  //::SelectObject(fTextDC, orig);
+  //::SelectObject(fTextMaskDC, morig);
+  //if (p) ::DeleteObject(p);
+  //if (mp) ::DeleteObject(mp);
+
+  //InvalidateRect(x,y0,1,y1-y0);
+}
+
+void CSTedScreenWin32::TextReverse(int in_x, int in_y, int in_width, int in_page)
+{
+  int x,y,w,h;
+  COLORREF c,b;
+  int page;
+
+
+  if (!TextToWindowPos(in_x, in_y, &x, &y)) return;
+  if (!TextToWindowPos(in_width, 0, &w, &h)) return;
+  h = fTextLineHeight;
+
+  switch (in_page) {
+       case 0: page=2;break;
+       case 1: page=0;break;
+       case 2: page=0;break;
+       case 3: page=2;break;
+  }
+
+  {
+    sf::begin_draw_bitmap begin(text_bitmap_target_);
+    {
+      sf::d2_dc_type dc(new sf::d2_dc(text_dc_target_,D2D1_DC_INITIALIZE_MODE_COPY));
+      c = ::SetTextColor(dc, PageToColor(page));
+      b = ::SetBkColor(dc, RGB(0x00, 0x00, 0x00));
+      ::BitBlt(dc, x,y,w,h, dc, x, y, DSTINVERT);
+      ::SetTextColor(dc,c);
+      ::SetBkColor(dc,b);
+    }
+    THROW_IF_ERR(begin.end_draw());
+  }
+  InvalidateRect(x,y,w,h);
+}
+
+void
+CSTedScreenWin32::TextReverseArea(int in_r_ad, int in_r_ln, int in_editscr)
+{
+  int x0,y0;
+  int w0,h0;
+  int x,y;
+  int w,h;
+  COLORREF b,c;
+
+  x0 = (in_editscr==0) ? 2 : 56;
+  y0 = 6+in_r_ad;
+  w0 = 36;
+  h0 = in_r_ln;
+  if (!TextToWindowPos(x0, y0, &x, &y)) return;
+  if (!TextToWindowPos(w0, h0, &w, &h)) return;
+  {
+    sf::begin_draw_bitmap begin(text_bitmap_target_);
+    {
+      sf::d2_dc_type dc(new sf::d2_dc(text_dc_target_,D2D1_DC_INITIALIZE_MODE_COPY));
+      c = ::SetTextColor(dc, PageToColor(3));
+      b = ::SetBkColor(dc, RGB(0x00, 0x00, 0x00));
+      ::BitBlt(dc, x,y,w,h, dc, x, y, DSTINVERT);
+      ::SetTextColor(dc, c);
+      ::SetBkColor(dc, b);
+    }
+    THROW_IF_ERR(begin.end_draw());
+  }
+
+  /*   
+  c = ::SetTextColor(fTextDC, PageToColor(3));
+  b = ::SetBkColor(fTextDC, RGB(0x00, 0x00, 0x00));
+  ::BitBlt(fTextDC, x,y,w,h, fTextMaskDC, x, y, SRCCOPY);
+  ::SetTextColor(fTextDC, c);
+  ::SetBkColor(fTextDC, b);
+
+  ::BitBlt(fTextMaskDC, x,y,w,h, fTextMaskDC, x, y, DSTINVERT);
+  */
+  InvalidateRect(x,y,w,h); 
+}
+
+void
+CSTedScreenWin32::TextFill(int in_page, int in_x, int in_y, int in_w, int in_h, int in_linestyle)
+{
+  int x,y,w,h;
+  //COLORREF c;
+  RECT r;
+  HBRUSH br, mbr;
+
+  if (!toWindowPos(in_x, in_y, &x, &y)) return;
+  if (!toWindowPos(in_w, in_h, &w, &h)) return;
+
+  ::SetRect(&r, x, y, x+w, y+h);
+
+  D2D1_RECT_F r1(D2D1::RectF(x,y,x+w,y+h));
+  D2D1_COLOR_F color = D2D1::ColorF(PageToColor(in_page));
+  ID2D1SolidColorBrushPtr color_brush;
+
+  text_bitmap_target_->CreateSolidColorBrush(color,&color_brush);
+  {
+    sf::begin_draw<ID2D1BitmapRenderTargetPtr> b(text_bitmap_target_);
+    D2D1_ANTIALIAS_MODE backup(text_bitmap_target_->GetAntialiasMode());
+    text_bitmap_target_->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+    if (in_page != 0) 
+    {
+      text_bitmap_target_->FillRectangle(r1,color_brush);
+           //br = ::CreateSolidBrush(c);
+           //mbr = MASK_ON;
+    } else {
+      text_bitmap_target_->PushAxisAlignedClip(r1,text_bitmap_target_->GetAntialiasMode());
+      text_bitmap_target_->Clear();
+      text_bitmap_target_->PopAxisAlignedClip();
+      //text_bitmap_target_->FillRectangle(r1,brush_text_clear_);
+           //br = fBrushTextClear;
+           //mbr = MASK_OFF;
+    }
+    text_bitmap_target_->SetAntialiasMode(backup);
+    THROW_IF_ERR(b.end_draw());
+  }
+ // if (in_linestyle!=0 && in_page!=0) {
+       //  c = PageToColor(in_page);
+       //  br = ::CreateSolidBrush(c);
+       //  mbr = MASK_ON;
+ // } else {
+       //  br = fBrushTextClear;
+       //  mbr = MASK_OFF;
+ // }
+
+ // ::FillRect(fTextDC, &r, br);
+ // ::FillRect(fTextMaskDC, &r, mbr);
+
+ // if (in_linestyle!=0 && in_page!=0)
+       //::DeleteObject(br);
+
+ InvalidateRect(&r);
+}
+
+extern int edit_scr;
+
+void
+CSTedScreenWin32::TextRasterCopy(int in_dst, int in_src, int in_line, int in_mode)
+{
+  int sx, lx;
+  int sy, dy, ly;
+  RECT r;
+
+  ly = fWindowHeight * (in_line/4 - 1) / fX68TextHeight;
+  if ((in_src==63*4) || (in_src==30*4)) {
+    sx = 0;
+    lx = fWindowWidth;
+  } else {
+    if (edit_scr==0) {
+      sx = fWindowWidth * 2  / fX68TextWidth;
+      lx = fWindowWidth * 36 / fX68TextWidth;
+    } else {
+      sx = fWindowWidth * 58 / fX68TextWidth;
+      lx = fWindowWidth * 36 / fX68TextWidth;
+    }
+  }
+
+  sf::begin_draw_bitmap begin(text_bitmap_target_);
+  {
+    if (in_mode >= 0x8000) {
+      sf::d2_dc_type dc(new sf::d2_dc(text_dc_target_,D2D1_DC_INITIALIZE_MODE_COPY));
+      sy = fWindowHeight * ((in_src+1)/4) / fX68TextHeight;
+      dy = fWindowHeight * ((in_dst+1)/4) / fX68TextHeight;
+      ::BitBlt(dc, sx, dy-ly, lx, ly, dc, sx, sy-ly, SRCCOPY);
+  //    ::BitBlt(fTextMaskDC, sx, dy-ly, lx, ly, fTextMaskDC, sx, sy-ly, SRCCOPY);
+      InvalidateRect(sx, dy-ly, lx, ly);
+    } else {
+      if (in_src==63*4) {
+        sy = fWindowHeight * in_dst/4 / fX68TextHeight;
+        dy = sy+fTextLineHeight;
+        ::SetRect(&r, sx, sy, sx+lx, dy);
+        D2D1_ANTIALIAS_MODE backup(text_bitmap_target_->GetAntialiasMode());
+        text_bitmap_target_->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+
+        text_bitmap_target_->FillRectangle(D2D1::RectF(sx,sy,sx+lx,dy),brush_text_clear_);
+//        ::FillRect(dc, &r, fBrushTextClear);
+  //      ::FillRect(fTextMaskDC, &r, MASK_OFF);
+        text_bitmap_target_->SetAntialiasMode(backup);
+        InvalidateRect(&r);
+      } else {
+        sf::d2_dc_type dc(new sf::d2_dc(text_dc_target_,D2D1_DC_INITIALIZE_MODE_COPY));
+        sy = fWindowHeight * (in_src/4) / fX68TextHeight;
+        dy = fWindowHeight * (in_dst/4) / fX68TextHeight;
+        ::BitBlt(dc, sx, dy, lx, ly, dc, sx, sy, SRCCOPY);
+  //      ::BitBlt(fTextMaskDC, sx, dy, lx, ly, fTextMaskDC, sx, sy, SRCCOPY);
+        InvalidateRect(sx, dy, lx, ly);
+      }
+    }
+  }
+  THROW_IF_ERR(begin.end_draw());
+}
+
+void
+CSTedScreenWin32::TextScroll(int in_x0, int in_y0, int in_xs, int in_ys, int in_x1, int in_y1)
+{
+  int x0, y0, x1, y1;
+  int w,h;
+  int d;
+
+  if (!TextToWindowPos(in_x0, in_y0, &x0, &d)) return;
+  if (!toWindowPos(in_x0, in_y0, &d, &y0)) return;
+  if (!TextToWindowPos(in_x1, in_y1, &x1, &d)) return;
+  if (!toWindowPos(in_x1, in_y1, &d, &y1)) return;
+  if (!TextToWindowPos(in_xs, in_ys, &w, &d)) return;
+  if (!toWindowPos(in_xs, in_ys, &d, &h)) return;
+
+   sf::begin_draw_bitmap begin(text_bitmap_target_);
+    {
+      sf::d2_dc_type dc(new sf::d2_dc(text_dc_target_,D2D1_DC_INITIALIZE_MODE_COPY));
+      ::BitBlt(dc, x1,y1,w,h, dc, x0, y0, SRCCOPY);
+    }
+    THROW_IF_ERR(begin.end_draw());
+  // ::BitBlt(fTextDC, x1, y1, w, h, fTextDC, x0, y0, SRCCOPY);
+//  ::BitBlt(fTextMaskDC, x1, y1, w, h, fTextMaskDC, x0, y0, SRCCOPY);
+
+  InvalidateRect(x1, y1, w, h);
+}
+
+void 
+CSTedScreenWin32::GraphicsBox(int in_x0, int in_y0, int in_x1, int in_y1, unsigned int in_color, unsigned int in_linestyle)
+{
+  int sx, sy, ex,ey;
+  int x,y;
+  int d;
+  int c;
+  RECT r;
+  //HBRUSH br;
+  //HPEN pen, orig;
+
+  if (!toWindowPos(in_x0, in_y0, &sx, &sy)) return;
+  if (!toWindowPos(in_x1, in_y1, &ex, &ey)) return;
+  d = (in_y1 >= fX68WindowHeight) ? 1:0;
+  if (sx>ex) { x=ex; ex=sx; sx=x;}
+  if (sy>ey) { y=ey; ey=sy; sy=y;}
+
+  c = (in_linestyle!=0) ? SetGraphicsColor(in_color) : 0;
+
+  ID2D1SolidColorBrushPtr brush;
+  graphics_bitmap_target_[d]->CreateSolidColorBrush(D2D1::ColorF(c),&brush);
+  sf::begin_draw_bitmap begin(graphics_bitmap_target_[d]);
+  D2D1_ANTIALIAS_MODE backup(graphics_bitmap_target_[d]->GetAntialiasMode());
+  graphics_bitmap_target_[d]->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+  if (sx==ex || sy==ey) {
+
+         // pen = ::CreatePen(PS_SOLID, 1, c);
+    graphics_bitmap_target_[d]->DrawLine(D2D1::Point2F(sx,sy),D2D1::Point2F(ex,ey),brush);
+
+         //if (pen) {
+
+
+                 //orig = (HPEN)::SelectObject(fGraphicsWindowDC[d], pen);
+                 //::MoveToEx(fGraphicsWindowDC[d], sx, sy, NULL);
+                 //::LineTo(fGraphicsWindowDC[d], ex, ey);
+                 //::SelectObject(fGraphicsWindowDC[d], orig);
+                 //::DeleteObject(pen);
+         /*}*/
+  } else {
+    graphics_bitmap_target_[d]->DrawRectangle(D2D1::RectF(sx,sy,ex,ey),brush);
+        //br = ::CreateSolidBrush(c);
+        // if (br) {
+       ////::FrameRect(fGraphicsWindowDC[d], &r, br);
+               ////::DeleteObject(br);
+        // }
+  }
+  graphics_bitmap_target_[d]->SetAntialiasMode(backup);
+  // エラーチェック
+  THROW_IF_ERR(begin.end_draw());
+  ::SetRect(&r, sx, sy, ex, ey);
+  InvalidateRect(&r);
+}
+
+int
+CSTedScreenWin32::GraphicsPoint(int in_x, int in_y)
+{
+  // just ignore
+  return 0;
+}
+
+void 
+CSTedScreenWin32::GraphicsLine(int in_x0, int in_y0, int in_x1, int in_y1, int in_color, int in_linestyle)
+{
+  int sx, sy, ex,ey;
+  int x,y;
+  int d;
+  int c;
+  //HPEN pen, orig;
+
+  if (!toWindowPos(in_x0, in_y0, &sx, &sy)) return;
+  if (!toWindowPos(in_x1, in_y1, &ex, &ey)) return;
+  d = (in_y1 >= fX68WindowHeight) ? 1:0;
+  if (sx>ex) { x=ex; ex=sx; sx=x;}
+  if (sy>ey) { y=ey; ey=sy; sy=y;}
+
+  c = (in_linestyle!=0) ? SetGraphicsColor(in_color) : 0;
+
+  ID2D1SolidColorBrushPtr brush;
+  graphics_bitmap_target_[d]->CreateSolidColorBrush(D2D1::ColorF(c),&brush);
+
+  {
+    sf::begin_draw_bitmap begin(graphics_bitmap_target_[d]);
+    D2D1_ANTIALIAS_MODE backup(graphics_bitmap_target_[d]->GetAntialiasMode());
+    graphics_bitmap_target_[d]->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+    graphics_bitmap_target_[d]->DrawLine(D2D1::Point2F(sx,sy),D2D1::Point2F(ex,ey),brush);
+    graphics_bitmap_target_[d]->SetAntialiasMode(backup);
+    // エラーチェック
+    THROW_IF_ERR(begin.end_draw());
+  }
+  //pen = ::CreatePen(PS_SOLID, 1, c);
+  //if (pen) {
+        // orig = (HPEN)::SelectObject(fGraphicsWindowDC[d], pen);
+        // ::MoveToEx(fGraphicsWindowDC[d], sx, sy, NULL);
+        // ::LineTo(fGraphicsWindowDC[d], ex, ey);
+        // ::SelectObject(fGraphicsWindowDC[d], orig);
+        // ::DeleteObject(pen);
+  //}
+  //InvalidateRect(sx, sy, ex-sx, ey-sy);
+}
+
+void
+CSTedScreenWin32::GraphicsFill(int in_x0, int in_y0, int in_x1, int in_y1, int in_color)
+{
+  int sx, sy, ex,ey;
+  int x,y;
+  int d;
+  int c;
+  RECT r;
+ // HBRUSH br;
+
+  if (!toWindowPos(in_x0, in_y0, &sx, &sy)) return;
+  if (!toWindowPos(in_x1, in_y1, &ex, &ey)) return;
+  d = (in_y1 >= fX68WindowHeight) ? 1:0;
+  if (sx>ex) { x = ex; ex = sx; sx = x;}
+  if (sy>ey) { y = ey; ey = sy; sy = y;}
+
+  c = SetGraphicsColor(in_color);
+
+  ::SetRect(&r, sx, sy, ex, ey);
+  ID2D1SolidColorBrushPtr brush;
+
+  graphics_bitmap_target_[d]->CreateSolidColorBrush(D2D1::ColorF(c),&brush);
+
+  sf::begin_draw_bitmap begin(graphics_bitmap_target_[d]);
+  D2D1_ANTIALIAS_MODE backup(graphics_bitmap_target_[d]->GetAntialiasMode());
+  graphics_bitmap_target_[d]->SetAntialiasMode(D2D1_ANTIALIAS_MODE_ALIASED);
+  graphics_bitmap_target_[d]->FillRectangle(D2D1::RectF(sx,sy,ex,ey),brush);
+  graphics_bitmap_target_[d]->SetAntialiasMode(backup);
+  THROW_IF_ERR(begin.end_draw());
+
+ // br = ::CreateSolidBrush(c);
+ // if (br) {
+ //   ::FillRect(fGraphicsWindowDC[d], &r, br);
+       //::DeleteObject(br);
+  //}
+
+  InvalidateRect(&r);
+}
+
+void
+CSTedScreenWin32::CopyTextToGraphics(int in_editscreen)
+{
+  int x0, y0, x1, y1;
+  int xt, xl, yt, yl;
+  COLORREF b,c;
+
+  xl = 36;
+  yl = 24;
+  if (in_editscreen==0) {
+    xt = 2;
+    yt = 6;
+  } else {
+    xt = 58;
+    yt = 6;
+  }
+  if (!TextToWindowPos(xt, yt, &x0, &y0)) return;
+  if (!TextToWindowPos(xl, (yt+yl), &x1, &y1)) return;
+
+  //c = ::SetTextColor(fGraphicsWindowDC[1], RGB(0x00, 0x00, 0x00));  
+  //b = ::SetBkColor(fGraphicsWindowDC[1], RGB(0xff, 0xff, 0xff));  
+
+  //::BitBlt(fGraphicsWindowDC[1], x0, y0, x1, y1-y0, fTextMaskDC, x0, y0, SRCPAINT);
+  //::BitBlt(fGraphicsWindowDC[1], x0, y0, x1, y1-y0, fTextDC, x0, y0, SRCAND);
+
+  //::SetTextColor(fGraphicsWindowDC[1], c);  
+  //::SetBkColor(fGraphicsWindowDC[1], b);  
+
+  InvalidateRect(x0, y0, x1, y1-y0);
+}
+
+void
+CSTedScreenWin32::CopyTextToGraphics2(int in_editscreen)
+{
+  //int x0, y0, x1, y1;
+  //int xt, xl, yt, yl;
+  //COLORREF b,c;
+
+  //xl = 56;
+  //yl = 24;
+  //if (in_editscreen==0) {
+  //  xt = 0;
+  //  yt = 6;
+  //} else {
+  //  xt = 38;
+  //  yt = 6;
+  //}
+  //if (!TextToWindowPos(xt, yt, &x0, &y0)) return;
+  //if (!TextToWindowPos(xl, (yt+yl), &x1, &y1)) return;
+
+  //c = ::SetTextColor(fGraphicsWindowDC[1], RGB(0x00, 0x00, 0x00));  
+  //b = ::SetBkColor(fGraphicsWindowDC[1], RGB(0xff, 0xff, 0xff));  
+
+  //::BitBlt(fGraphicsWindowDC[1], x0, y0, x1, y1-y0, fTextMaskDC, x0, y0, SRCPAINT);
+  //::BitBlt(fGraphicsWindowDC[1], x0, y0, x1, y1-y0, fTextDC, x0, y0, SRCAND);
+
+  //::SetTextColor(fGraphicsWindowDC[1], c);  
+  //::SetBkColor(fGraphicsWindowDC[1], b);  
+
+  //InvalidateRect(x0, y0, x1, y1-y0);
+}
+
+void
+CSTedScreenWin32::GraphicsHome(int in_home)
+{
+  if (in_home!=0 && in_home!=1) in_home = 0;
+  fCurrentGraphics = in_home;
+  InvalidateRect(NULL);
+}
+
+void
+CSTedScreenWin32::ClsAll(void)
+{
+  RECT r;
+  ::SetRect(&r, 0, 0, fWindowWidth, fWindowHeight);
+  sf::begin_draw_bitmap begin(text_bitmap_target_);
+  text_bitmap_target_->Clear(D2D1::ColorF(0,0));
+  THROW_IF_ERR(begin.end_draw());
+
+//  ::FillRect(fTextDC, &r, fBrushTextClear);
+//  ::FillRect(fTextMaskDC, &r, MASK_OFF);
+  InvalidateRect(&r);
+}
+
+void
+CSTedScreenWin32::GraphicsClear(void)
+{
+  RECT r;
+  ::SetRect(&r, 0, 0, fWindowWidth, fWindowHeight);
+  sf::begin_draw_bitmap begin(graphics_bitmap_target_[fCurrentGraphics]);
+  graphics_bitmap_target_[fCurrentGraphics]->Clear();
+  THROW_IF_ERR(begin.end_draw());
+  //::FillRect(fGraphicsWindowDC[fCurrentGraphics], &r, fBrushClear);
+  InvalidateRect(&r);
+}
diff --git a/win32_key.cpp b/win32_key.cpp
new file mode 100644 (file)
index 0000000..45eae49
--- /dev/null
@@ -0,0 +1,657 @@
+/*
+  win32_key.cpp
+  screen driver for win32
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+
+#include "sted_screen_win32.h"
+
+// nofitication from main window
+void
+CSTedScreenWin32::NotifyKeyPressed(int in_key)
+{
+  fKeyEventNotified = TRUE;
+
+  if (in_key == fKeyConv[EShift])
+    fKeyShiftPressed = TRUE;
+  else if (in_key == fKeyConv[EControl])
+    fKeyControlPressed = TRUE;
+  else if (in_key == fKeyConv[EOPT1])
+    fKeyOPT1Pressed = TRUE;
+  else if (in_key == fKeyConv[EOPT2])
+    fKeyOPT2Pressed = TRUE;
+  else if (in_key == fKeyConv[EKana])
+    fKeyKanaPressed = TRUE;
+  else if (in_key == fKeyConv[EInsert])
+    fKeyInsertPressed = TRUE;
+
+  else {
+         switch (in_key) {
+                 case VK_PRIOR:
+                 case VK_NEXT:
+                 case VK_HOME:
+                 case VK_END:
+                 case VK_UP:
+                 case VK_DOWN:
+                 case VK_LEFT:
+                 case VK_RIGHT:
+                 case VK_F1:
+                 case VK_F2:
+                 case VK_F3:
+                 case VK_F4:
+                 case VK_F5:
+                 case VK_F6:
+                 case VK_F7:
+                 case VK_F8:
+                 case VK_F9:
+                 case VK_F10:
+                 case VK_F11:
+                 case VK_F12:
+                 case VK_LMENU:
+                 case VK_RMENU:
+                 case VK_LCONTROL:
+                 case VK_RCONTROL:
+                 case VK_NONCONVERT:
+                 case 0xd8: // for Kigo
+                 case 0xd9: // for Toroku
+                       fKeyBuffer[fKeyBufferEndPtr] = (in_key | 0x100);
+                       fKeyBufferEndPtr = (fKeyBufferEndPtr+1)%fKeyBufferLen;
+                       if (fKeyBufferEndPtr==fKeyBufferStartPtr) {
+                               fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
+                       }
+                       fKeyBufferAvailable++;
+                       if (fKeyBufferAvailable>=fKeyBufferLen) {
+                               fKeyBufferAvailable = fKeyBufferLen;
+                       }
+                       break;
+                 default:
+                         fKeyEventNotified = FALSE;
+                         break;
+         }
+  }
+}
+
+void
+CSTedScreenWin32::NotifyKeyReleased(int in_key)
+{
+  fKeyEventNotified = TRUE;
+
+  if (in_key == fKeyConv[EShift])
+    fKeyShiftPressed = FALSE;
+  else if (in_key == fKeyConv[EControl])
+    fKeyControlPressed = FALSE;
+  else if (in_key == fKeyConv[EOPT1])
+    fKeyOPT1Pressed = FALSE;
+  else if (in_key == fKeyConv[EOPT2])
+    fKeyOPT2Pressed = FALSE;
+  else if (in_key == fKeyConv[EKana])
+    fKeyKanaPressed = FALSE;
+  else if (in_key == fKeyConv[EInsert])
+    fKeyInsertPressed = FALSE;
+}
+
+void
+CSTedScreenWin32::NotifyChar(int in_char)
+{
+       int len=0;
+       WCHAR buf[2];
+       unsigned char str[6];
+       int ptr;
+
+       fKeyEventNotified = TRUE;
+
+       buf[0] = in_char;
+       buf[1] = '\0';
+
+#ifdef _UNICODE
+       len = ::WideCharToMultiByte(932, 0, (LPCWSTR)buf, 1, (LPSTR)str, 6, NULL, NULL);
+#else
+       len = 1;
+       str[0] = (unsigned char)in_char;
+#endif
+
+       ptr=0;
+       while (len>0) {
+               fKeyBuffer[fKeyBufferEndPtr] = str[ptr++];
+               fKeyBufferEndPtr = (fKeyBufferEndPtr+1)%fKeyBufferLen;
+               if (fKeyBufferEndPtr==fKeyBufferStartPtr) {
+                       fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
+               }
+               fKeyBufferAvailable++;
+               if (fKeyBufferAvailable>=fKeyBufferLen) {
+                       fKeyBufferAvailable = fKeyBufferLen;
+               }
+               len--;
+       }
+}
+
+// key
+int 
+CSTedScreenWin32::KeyInit(void)
+{
+  fKeyBufferStartPtr = 0;
+  fKeyBufferEndPtr = 0;
+  fKeyBufferAvailable = 0;
+
+  fKeyShiftPressed = FALSE;
+  fKeyControlPressed = FALSE;
+  fKeyOPT1Pressed = FALSE;
+  fKeyOPT2Pressed = FALSE;
+  fKeyKanaPressed = FALSE;
+  fKeyInsertPressed = FALSE;
+
+  fKeyEventNotified = FALSE;
+
+  // default configuration for IBM-106
+
+  fKeyConv[EShift] = VK_SHIFT;
+  fKeyConv[EControl] = VK_CONTROL;
+  fKeyConv[EOPT1] = VK_F11;
+  fKeyConv[EOPT2] = VK_F12;
+  fKeyConv[EXF1] = VK_LMENU;
+  fKeyConv[EXF2] = VK_NONCONVERT;
+  fKeyConv[EXF3] = VK_CONVERT;
+  fKeyConv[EXF4] = VK_KANA;
+  fKeyConv[EXF5] = VK_RMENU;
+  fKeyConv[EKana] = VK_LCONTROL;
+  fKeyConv[EKigo] = 0xd8; // unassigned
+  fKeyConv[EToroku] = 0xd9; // unassigned
+  fKeyConv[EInsert] = VK_INSERT;
+  fKeyConv[EDel] = VK_DELETE;
+  fKeyConv[EHome] = VK_HOME;
+  fKeyConv[EUndo] = VK_END;
+  fKeyConv[ERollUp] = VK_PRIOR;
+  fKeyConv[ERollDown] = VK_NEXT;
+  fKeyConv[EF1] = VK_F1;
+  fKeyConv[EF2] = VK_F2;
+  fKeyConv[EF3] = VK_F3;
+  fKeyConv[EF4] = VK_F4;
+  fKeyConv[EF5] = VK_F5;
+  fKeyConv[EF6] = VK_F6;
+  fKeyConv[EF7] = VK_F7;
+  fKeyConv[EF8] = VK_F8;
+  fKeyConv[EF9] = VK_F9;
+  fKeyConv[EF10] = VK_F10;
+
+  return 0;
+}
+
+// blocking
+int 
+CSTedScreenWin32::KeyIn(int in_code)
+{
+  int result;
+  int key;
+
+ loop:
+  if (fKeyBufferAvailable<=0) return 0;
+
+  key = fKeyBuffer[fKeyBufferStartPtr];
+  result = ConvertWinKeyToX68Key(key);
+
+  if (result<=0) {
+    fKeyBufferAvailable--;
+       fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
+       goto loop;
+  }
+
+
+  if (in_code!=0xfe) {
+    fKeyBufferAvailable--;
+       fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
+  }
+
+  return result;
+}
+
+
+// キー入力blockingモード
+int
+CSTedScreenWin32::KeyInp(void)
+{
+  BOOL result;
+  int ascii, code;
+  int key;
+
+loop:
+  do {
+         if (!fKeyEventNotified) 
+         {
+                 DoMessageLoop();
+         }
+         fKeyEventNotified = FALSE;
+  } while(fKeyBufferAvailable <= 0);
+
+  key = fKeyBuffer[fKeyBufferStartPtr];
+  result = ConvertWinKeyToX68Key(key, &ascii, &code);
+  if (!result) {
+    fKeyBufferAvailable--;
+       fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
+       if (fKeyBufferAvailable>0)
+               fKeyEventNotified = TRUE;
+    goto loop;
+  }
+
+  fKeyBufferAvailable--;
+  fKeyBufferStartPtr = (fKeyBufferStartPtr+1)%fKeyBufferLen;
+  if (fKeyBufferAvailable>0) fKeyEventNotified = TRUE;
+
+  return (ascii | code<<8);
+}
+
+int
+CSTedScreenWin32::SftSense(void)
+{
+  int ret=0;
+
+  if (fKeyShiftPressed) ret|=1;
+  if (fKeyControlPressed) ret|=2;
+  if (fKeyOPT1Pressed) ret|=4;
+  if (fKeyOPT2Pressed) ret|=8;
+  if (fKeyKanaPressed) ret|=16+256;
+  if (fKeyInsertPressed) ret|=4096;
+
+  if (!(::GetKeyState(VK_SHIFT)&0xff00)) {
+         fKeyShiftPressed = FALSE;
+  }
+
+  return ret;
+}
+
+BOOL
+CSTedScreenWin32::CheckKeyBuffer(int in_key)
+{
+    int val;
+    val = ::GetKeyState(in_key);
+    if (val&0xff00) return TRUE;
+    return FALSE;
+}
+
+int 
+CSTedScreenWin32::BitSense(int in_group)
+{
+  int ret = 0;
+
+  switch ( in_group ) {
+  case 0:  /* 1 - 6 */
+    if (CheckKeyBuffer('1')) ret|=4;
+    if (CheckKeyBuffer('2')) ret|=8;
+    if (CheckKeyBuffer('3')) ret|=16;
+    if (CheckKeyBuffer('4')) ret|=32;
+    if (CheckKeyBuffer('5')) ret|=64;
+    if (CheckKeyBuffer('6')) ret|=128;
+    break;
+
+  case 1:
+    if (CheckKeyBuffer('7')) ret|=1;
+    if (CheckKeyBuffer('8')) ret|=2;
+    if (CheckKeyBuffer('9')) ret|=4;
+    if (CheckKeyBuffer('0')) ret|=8;
+    if (CheckKeyBuffer('-')) ret|=16;
+    if (CheckKeyBuffer('^')) ret|=32;
+    if (CheckKeyBuffer('\\')) ret|=64;
+    if (CheckKeyBuffer(VK_BACK)) ret|=128;
+    break;
+
+  case 2:
+    if (CheckKeyBuffer(VK_TAB)) ret|=1;
+    if (CheckKeyBuffer('Q')) ret|=2;
+    if (CheckKeyBuffer('W')) ret|=4;
+    if (CheckKeyBuffer('E')) ret|=8;
+    if (CheckKeyBuffer('R')) ret|=16;
+    if (CheckKeyBuffer('T')) ret|=32;
+    if (CheckKeyBuffer('Y')) ret|=64;
+    if (CheckKeyBuffer('U')) ret|=128;
+    break;
+
+  case 3:
+    if (CheckKeyBuffer('I')) ret|=1;
+    if (CheckKeyBuffer('O')) ret|=2;
+    if (CheckKeyBuffer('P')) ret|=4;
+    if (CheckKeyBuffer('@')) ret|=8;
+    if (CheckKeyBuffer('[')) ret|=16;
+    if (CheckKeyBuffer(VK_RETURN)) ret|=32;
+    if (CheckKeyBuffer('A')) ret|=64;
+    if (CheckKeyBuffer('S')) ret|=128;
+    break;
+
+  case 4:
+    if (CheckKeyBuffer('D')) ret|=1;
+    if (CheckKeyBuffer('F')) ret|=2;
+    if (CheckKeyBuffer('G')) ret|=4;
+    if (CheckKeyBuffer('H')) ret|=8;
+    if (CheckKeyBuffer('J')) ret|=16;
+    if (CheckKeyBuffer('K')) ret|=32;
+    if (CheckKeyBuffer('L')) ret|=64;
+    if (CheckKeyBuffer(';')) ret|=128;
+    break;
+
+  case 5:
+    if (CheckKeyBuffer(':')) ret|=1;
+    if (CheckKeyBuffer(']')) ret|=2;
+    if (CheckKeyBuffer('Z')) ret|=4;
+    if (CheckKeyBuffer('X')) ret|=8;
+    if (CheckKeyBuffer('C')) ret|=16;
+    if (CheckKeyBuffer('V')) ret|=32;
+    if (CheckKeyBuffer('B')) ret|=64;
+    if (CheckKeyBuffer('N')) ret|=128;
+    break;
+
+  case 6:
+    if (CheckKeyBuffer('M')) ret|=1;
+    if (CheckKeyBuffer(',')) ret|=2;
+    if (CheckKeyBuffer('.')) ret|=4;
+    if (CheckKeyBuffer('/')) ret|=8;
+    if (CheckKeyBuffer('\\')) ret|=16;
+    if (CheckKeyBuffer(' ')) ret|=32;
+    break;
+
+  case 7: /* R_UP,R_DOWN, Cursors */
+    if (CheckKeyBuffer(VK_PRIOR)) ret|=1;
+    if (CheckKeyBuffer(VK_NEXT)) ret|=2;
+    if (CheckKeyBuffer(VK_END)) ret|=4;
+    if (CheckKeyBuffer(VK_LEFT)) ret|=8;
+    if (CheckKeyBuffer(VK_UP)) ret|=16;
+    if (CheckKeyBuffer(VK_RIGHT)) ret|=32;
+    if (CheckKeyBuffer(VK_DOWN)) ret|=64;
+    break;
+#if 0
+  case 0x0a: /* XF1-XF3 */
+    if (check_keycode(k_xf1      , key_buffer)) ret|=32;
+    if (check_keycode(k_xf2      , key_buffer)) ret|=64;
+    if (check_keycode(k_xf3      , key_buffer)) ret|=128;
+    break;
+
+  case 0x0b: /* XF4-XF5 */
+    if (check_keycode(k_xf4      , key_buffer)) ret|=1;
+    if (check_keycode(k_xf5      , key_buffer)) ret|=2;
+    break;
+#endif
+  case 0x0c: /* F0-F4 */
+    if (CheckKeyBuffer(VK_F1)) ret|=8;
+    if (CheckKeyBuffer(VK_F2)) ret|=16;
+    if (CheckKeyBuffer(VK_F3)) ret|=32;
+    if (CheckKeyBuffer(VK_F4)) ret|=64;
+    if (CheckKeyBuffer(VK_F5)) ret|=128;
+    break;
+
+  case 0x0d: /* F5-F9 */
+    if (CheckKeyBuffer(VK_F6)) ret|=1;
+    if (CheckKeyBuffer(VK_F7)) ret|=2;
+    if (CheckKeyBuffer(VK_F8)) ret|=4;
+    if (CheckKeyBuffer(VK_F9)) ret|=8;
+    if (CheckKeyBuffer(VK_F10)) ret|=16;
+    break;
+
+  case 0x0e: /* OPT.1-OPT.2 */
+    if (CheckKeyBuffer(VK_F11)) ret|=4;
+    if (CheckKeyBuffer(VK_F12)) ret|=8;
+    break;
+
+  default:
+    break;
+  }
+
+  return ret;
+}
+
+int
+CSTedScreenWin32::KeySense(void)
+{
+       if (fKeyBufferAvailable==0) return 0;
+       return 1;
+}
+
+void
+CSTedScreenWin32::KeyWait(void)
+{
+       while (!fKeyEventNotified && fKeyBufferAvailable==0) {
+               DoMessageLoop();
+       }
+       fKeyEventNotified = FALSE;
+}
+
+void
+CSTedScreenWin32::LedMode(int in_code, int in_onoff)
+{
+}
+
+void
+CSTedScreenWin32::ClearKeyBuffer(void)
+{
+       fKeyBufferAvailable = 0;
+       fKeyBufferStartPtr = 0;
+       fKeyBufferEndPtr = 0;
+}
+
+// key conversion
+int
+CSTedScreenWin32::ConvertWinKeyToX68Key(int in_winkey)
+{
+  int result;
+
+  if (in_winkey<0x100) { // char
+         return in_winkey;
+  }
+
+  in_winkey&=0xff;
+  switch (in_winkey) {
+  case VK_UP:
+    result = fFncKey[4][0];
+    break;
+  case VK_DOWN:
+    result = fFncKey[7][0];
+    break;
+  case VK_LEFT:
+    result = fFncKey[5][0];
+    break;
+  case VK_RIGHT:
+    result = fFncKey[6][0];
+    break;
+  case VK_BACK:
+    result = 0x08;
+    break;
+  default:
+    if (in_winkey == fKeyConv[EHome])
+      result = fFncKey[10][0];
+    else if (in_winkey == fKeyConv[EUndo])
+      result = fFncKey[11][0];
+    else if (in_winkey == fKeyConv[EDel])
+      result = fFncKey[3][0];
+    else if (in_winkey == fKeyConv[EInsert])
+      result = fFncKey[2][0];
+    else if (in_winkey == fKeyConv[ERollDown])
+      result = fFncKey[0][0];
+    else if (in_winkey == fKeyConv[ERollUp])
+      result = fFncKey[1][0];
+    else {
+      result = in_winkey;
+    }
+    break;
+  }
+
+  return result;
+}
+
+int
+CSTedScreenWin32::ConvertWinKeyToX68Key(int in_winkey, int* out_ascii, int* out_code)
+{
+  int ascii=0, code=0;
+  int result=1;
+
+  if (in_winkey<0x100) {
+         if (in_winkey>=0x20 && in_winkey<=0x7f) {
+                 code = fX68ScanCode[in_winkey-0x20];
+         } else {
+                 switch (in_winkey) {
+                         case 0x1b: code = 0x01;break;
+                         case 0x0d: code = 0x1d;break;
+                         case 0x09: code = 0x10;break;
+                         default: code = 0; break;
+                 }
+         }
+         if (out_ascii) *out_ascii = in_winkey;
+         if (out_code) *out_code = code;
+         return 1;
+  }
+
+  in_winkey&=0xff;
+
+  switch (in_winkey) {
+  case VK_UP:
+    ascii=0; code=0x3c; break;
+    break;
+  case VK_DOWN:
+    ascii=0; code=0x3e; break;
+    break;
+  case VK_LEFT:
+    ascii=0; code=0x3b; break;
+    break;
+  case VK_RIGHT:
+    ascii=0; code=0x3d; break;
+    break;
+  case VK_BACK:
+    ascii=0; code=0x0f; break;
+    break;
+  case VK_RETURN:
+    ascii=0x0d; code=0x1d; break;
+    break;
+  case VK_ESCAPE:
+    ascii=0x1b; code=0x01; break;
+    break;
+  case VK_TAB:
+    ascii=0x09; code=0x10; break;
+    break;
+
+  case VK_SHIFT:
+    ascii=0x00; code=fKeyShiftPressed?0x70:0xf0; break;
+    break;
+  case VK_CONTROL:
+    ascii=0x00; code=fKeyControlPressed?0x71:0xf1; break;
+    break;
+  default:
+    if (in_winkey == fKeyConv[EF1]) {
+      ascii=0x00; code=0x63;
+    } else if (in_winkey == fKeyConv[EF2]) {
+      ascii=0x00; code=0x64;
+    } else if (in_winkey == fKeyConv[EF3]) {
+      ascii=0x00; code=0x65;
+    } else if (in_winkey == fKeyConv[EF4]) {
+      ascii=0x00; code=0x66;
+    } else if (in_winkey == fKeyConv[EF5]) {
+      ascii=0x00; code=0x67;
+    } else if (in_winkey == fKeyConv[EF6]) {
+      ascii=0x00; code=0x68;
+    } else if (in_winkey == fKeyConv[EF7]) {
+      ascii=0x00; code=0x69;
+    } else if (in_winkey == fKeyConv[EF8]) {
+      ascii=0x00; code=0x6a;
+    } else if (in_winkey == fKeyConv[EF9]) {
+      ascii=0x00; code=0x6b;
+    } else if (in_winkey == fKeyConv[EF10]) {
+      ascii=0x00; code=0x6c;
+
+    } else if (in_winkey == fKeyConv[EKigo]) {
+      ascii=0x00; code=0x52;
+    } else if (in_winkey == fKeyConv[EToroku]) {
+      ascii=0x00; code=0x53;
+
+    } else if (in_winkey == fKeyConv[EXF1]) {
+      ascii=0x00; code=0x55;
+    } else if (in_winkey == fKeyConv[EXF2]) {
+      ascii=0x00; code=0x56;
+    } else if (in_winkey == fKeyConv[EXF3]) {
+      ascii=0x00; code=0x57;
+    } else if (in_winkey == fKeyConv[EXF4]) {
+      ascii=0x00; code=0x58;
+    } else if (in_winkey == fKeyConv[EXF5]) {
+      ascii=0x00; code=0x59;
+
+    } else if (in_winkey == fKeyConv[EHome]) {
+      ascii=0x00; code=0x36;
+    } else if (in_winkey == fKeyConv[EDel]) {
+      ascii=0x00; code=0x37;
+    } else if (in_winkey == fKeyConv[EInsert]) {
+      ascii=0x00; code=0x5e;
+    } else if (in_winkey == fKeyConv[ERollDown]) {
+      ascii=0x00; code=0x38;
+    } else if (in_winkey == fKeyConv[ERollUp]) {
+      ascii=0x00; code=0x39;
+    } else if (in_winkey == fKeyConv[EUndo]) {
+      ascii=0x00; code=0x3a;
+    } else if (in_winkey == fKeyConv[EOPT1]) {
+      ascii=0x00; code=(fKeyOPT1Pressed)?0x72:0xf2;
+    } else if (in_winkey == fKeyConv[EOPT2]) {
+      ascii=0x00; code=(fKeyOPT2Pressed)?0x72:0xf2;
+
+    } else if (in_winkey == VK_NUMPAD0) {
+      ascii='0'; code=0x4f;
+    } else if (in_winkey == VK_NUMPAD1) {
+      ascii='1'; code=0x4b;
+    } else if (in_winkey == VK_NUMPAD2) {
+      ascii='2'; code=0x4c;
+    } else if (in_winkey == VK_NUMPAD3) {
+      ascii='3'; code=0x4d;
+    } else if (in_winkey == VK_NUMPAD4) {
+      ascii='4'; code=0x47;
+    } else if (in_winkey == VK_NUMPAD5) {
+      ascii='5'; code=0x48;
+    } else if (in_winkey == VK_NUMPAD6) {
+      ascii='6'; code=0x49;
+    } else if (in_winkey == VK_NUMPAD7) {
+      ascii='7'; code=0x43;
+    } else if (in_winkey == VK_NUMPAD8) {
+      ascii='8'; code=0x44;
+    } else if (in_winkey == VK_NUMPAD9) {
+      ascii='9'; code=0x45;
+    } else if (in_winkey == VK_DECIMAL) {
+      ascii='.'; code=0x51;
+    } else if (in_winkey == VK_DIVIDE) {
+      ascii='/'; code=0x40;
+    } else if (in_winkey == VK_MULTIPLY) {
+      ascii='*'; code=0x41;
+    } else if (in_winkey == VK_SUBTRACT) {
+      ascii='-'; code=0x42;
+    } else if (in_winkey == VK_ADD) {
+      ascii='+'; code=0x46;
+
+       } else if (in_winkey == VK_OEM_2) {
+               ascii='/'; code=fX68ScanCode[ascii-0x20];
+       } else if (in_winkey == VK_OEM_102) {
+               ascii='\\'; code=fX68ScanCode[ascii-0x20];
+
+    } else if (in_winkey>=0x20 && in_winkey<0x7f) {
+      ascii = in_winkey;
+      code = fX68ScanCode[in_winkey-0x20];
+
+    } else {
+      ascii=0; code=0;
+         result = 0;
+    }
+    break;
+  }
+
+  if (out_ascii) *out_ascii = ascii;
+  if (out_code) *out_code = code;
+  return result;
+}
diff --git a/win32_midi.cpp b/win32_midi.cpp
new file mode 100644 (file)
index 0000000..bf6b723
--- /dev/null
@@ -0,0 +1,393 @@
+/*
+  win32_midi.cpp
+  midi related drivers
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+#include "sted_screen.h"
+#include "sted_screen_win32.h"
+#include "rcp.h"
+#include "assert.h"
+
+int rcpplay_start(RCP_DATA* in_rcp);
+int rcpplay_stop(void);
+int rcpplay_close(void);
+
+// HWND STedGetWindow(void);
+
+// midi devices
+
+void
+CSTedScreenWin32::AppendMidiData(int in_c)
+{
+       fMidiBuffer[fMidiBufferEndPtr] = (unsigned char)in_c;
+
+       fMidiBufferEndPtr = (fMidiBufferEndPtr+1)%fMidiBufferLen;
+
+       if (fMidiBufferEndPtr==fMidiBufferStartPtr)
+               fMidiBufferStartPtr = (fMidiBufferStartPtr+1)%fMidiBufferLen;
+
+       fMidiBufferAvailable++;
+       if (fMidiBufferAvailable>=fMidiBufferLen) fMidiBufferAvailable = fMidiBufferLen;
+}
+
+void
+CSTedScreenWin32::NotifyMidiIn(unsigned long in_data)
+{
+       int c1, c2, c3;
+       int l=0;
+
+       c1 = in_data&0x000000ff;
+       c2 = (in_data&0x0000ff00)>>8;
+       c3 = (in_data&0x00ff0000)>>16;
+
+       switch (c1&0xf0) {
+               case 0x80: // note off
+               case 0x90: // note on
+               case 0xa0: // poly key-pressure
+               case 0xb0: // control change
+               case 0xe0: // pitch-bend
+                       l = 2;
+                       break;
+               case 0xc0: // program change
+               case 0xd0: // channel pressure
+                       l = 1;
+                       break;
+               case 0xf0:
+                       switch (c1) {
+                               case 0xf0: // exclusive: not happen
+                               case 0xf4: // not defined
+                                       break;
+                               case 0xf1: // midi time code
+                               case 0xf3: // song select
+                               case 0xf5: // port change
+                                       l = 1;
+                                       break;
+                               case 0xf2: // song posision
+                                       l = 2;
+                                       break;
+                               case 0xf6:
+                               case 0xf7:
+                               case 0xf8:
+                               case 0xf9:
+                               case 0xfa:
+                               case 0xfb:
+                               case 0xfc:
+                               case 0xfd:
+                               case 0xfe:
+                               case 0xff:
+                                       l = 0;
+                                       break;
+                       }
+                       break;
+       }
+
+       switch (l) {
+               case 0:
+                       AppendMidiData(c1);
+                       break;
+               case 1:
+                       AppendMidiData(c1);
+                       AppendMidiData(c2);
+                       break;
+               case 2:
+                       AppendMidiData(c1);
+                       AppendMidiData(c2);
+                       AppendMidiData(c3);
+                       break;
+       }
+
+       return;
+}
+
+int
+CSTedScreenWin32::OpenMidiDevice(void)
+{
+       HMIDIIN din;
+       HMIDIOUT dout;
+       MMRESULT result;
+       int indevs;
+       int outdevs;
+       int inid, outid;
+       int i;
+
+       fMidiInDevice = NULL;
+       fMidiBufferAvailable = 0;
+       fMidiBufferStartPtr = 0;
+       fMidiBufferEndPtr = 0;
+       for (i=0; i<fMidiOutPorts; i++) {
+               fMidiOutDevice[i] = NULL;
+       }
+       fMidiOutCurrentPort = 0;
+
+       indevs = ::midiInGetNumDevs();
+       outdevs = ::midiOutGetNumDevs();
+
+       for (i=0; i<fMidiOutPorts; i++) {
+               if (fMidiOutPort[i]==-1) continue;
+               outid = (fMidiOutPort[i]>=0) ? fMidiOutPort[i] : MIDI_MAPPER;
+               if (outid>=outdevs) outid = MIDI_MAPPER;
+               result = ::midiOutOpen(&dout, outid, (DWORD_PTR)hwnd_, NULL, CALLBACK_WINDOW);
+               if (result==MMSYSERR_NOERROR) {
+                       fMidiOutDevice[i] = dout;
+               }
+       }
+
+       if (indevs>0 && fMidiInPort>=0) {
+               inid = (fMidiInPort>=0) ? fMidiInPort : MIDI_MAPPER;
+               if (inid>=indevs) inid = indevs-1;
+               result = ::midiInOpen(&din, 0, (DWORD_PTR)hwnd_, NULL, CALLBACK_WINDOW);
+               if (result==MMSYSERR_NOERROR) {
+                       fMidiInDevice = din;
+                       result = ::midiInStart(din);
+                       assert(result == MMSYSERR_NOERROR );
+
+               }
+       }
+       
+    return 0;
+}
+
+void
+CSTedScreenWin32::CloseMidiDevice(void)
+{
+       MMRESULT result;
+       if (fMidiInDevice) {
+               result = ::midiInStop(fMidiInDevice);
+               assert(result == MMSYSERR_NOERROR );
+               result = ::midiInClose(fMidiInDevice);
+               assert(result == MMSYSERR_NOERROR );
+               fMidiInDevice = NULL;
+       }
+
+       for (int i=0; i<fMidiOutPorts; i++) {
+               if (fMidiOutDevice[i]) {
+                       result = ::midiOutClose(fMidiOutDevice[i]);
+                       assert(result == MMSYSERR_NOERROR );
+                       fMidiOutDevice[i] = NULL;
+               }
+       }
+}
+
+BOOL
+CSTedScreenWin32::SetMidiPorts(int in_min, int* in_mout)
+{
+       int i;
+
+       fMidiInPort = in_min;
+
+       if (in_mout) {
+               for (i=0; i<fMidiOutPorts; i++) {
+                       fMidiOutPort[i] = in_mout[i];
+               }
+       }
+
+       return TRUE;
+}
+
+int
+CSTedScreenWin32::GetMidiData(void)
+{
+       int c;
+
+       if (fMidiBufferAvailable>0) {
+               c = fMidiBuffer[fMidiBufferStartPtr];
+               fMidiBufferAvailable--;
+               fMidiBufferStartPtr = (fMidiBufferStartPtr+1)%fMidiBufferLen;
+               return c;
+       }
+    return -1;
+}
+
+int
+CSTedScreenWin32::CanMidiRead(void)
+{
+       if (fMidiBufferAvailable>0) return 1;
+    return 0;
+}
+
+void
+CSTedScreenWin32::PutMidiData(int in_data)
+{
+       int i;
+       MIDIHDR hdr;
+       MMRESULT result;
+       int p;
+
+       p = fMidiOutCurrentPort;
+       if (p<0) p=0;
+       if (p>fMidiOutPorts) p=fMidiOutPorts-1;
+
+       if (in_data>=0x80) {
+               if (in_data==0xf7) { // flush exclusive data
+                       for (i=0 ;i<fMidiExclusiveBufLen; i++) {if (fMidiExclusiveBuf[i]<0) break;}
+                       if (i==fMidiExclusiveBufLen) return;
+                       fMidiExclusiveBuf[i] = 0xf7;
+                       hdr.lpData = (LPSTR)fMidiExclusiveBuf;
+                       hdr.dwBufferLength = i;
+                       hdr.dwBytesRecorded = i;
+                       result = ::midiOutPrepareHeader(fMidiOutDevice[p], &hdr, sizeof(MIDIHDR));
+                       assert(result == MMSYSERR_NOERROR );
+                       result = ::midiOutLongMsg(fMidiOutDevice[p], &hdr, sizeof(MIDIHDR));
+                       assert(result == MMSYSERR_NOERROR );
+                       result = ::midiOutUnprepareHeader(fMidiOutDevice[p], &hdr, sizeof(MIDIHDR));
+                       assert(result == MMSYSERR_NOERROR );
+
+               }
+               fMidiOutPacket[0] = in_data;
+               fMidiOutPacket[1] = -1;
+               fMidiOutPacket[2] = -1;
+               fMidiOutPacket[3] = -1;
+               fMidiExclusiveBuf[0] = 0xf0;
+               for (i=1; i<fMidiExclusiveBufLen; i++) fMidiExclusiveBuf[i] = -1;
+               if (in_data>=0xf6 && in_data<=0xff) {
+                       result = ::midiOutShortMsg(fMidiOutDevice[p], in_data);
+                       assert(result == MMSYSERR_NOERROR );
+               }
+       } else {
+               if (fMidiOutPacket[0] == 0xf0) {
+                       for (i=0 ;i<fMidiExclusiveBufLen; i++) {if (fMidiExclusiveBuf[i]<0) break;}
+                       if (i==fMidiExclusiveBufLen) return;
+                       fMidiExclusiveBuf[i] = in_data;
+                       return;
+               }
+               for (i=0; i<4; i++) {if (fMidiOutPacket[i]<0) break;}
+               if (i==4) return;
+               fMidiOutPacket[i] = in_data;
+
+               switch(fMidiOutPacket[0]&0xf0) {
+                       case 0x80:
+                       case 0x90:
+                       case 0xa0:
+                       case 0xb0:
+                       case 0xe0:
+                               if (i==2) {
+                                       result = ::midiOutShortMsg(fMidiOutDevice[p], (fMidiOutPacket[2]<<16 | fMidiOutPacket[1]<<8 | fMidiOutPacket[0]));
+                                       assert(result == MMSYSERR_NOERROR );
+                               }
+                               break;
+                       case 0xc0:
+                       case 0xd0:
+                               if (i==1) {
+                                       result =::midiOutShortMsg(fMidiOutDevice[p], (fMidiOutPacket[1]<<8 | fMidiOutPacket[0]));
+                                       assert(result == MMSYSERR_NOERROR );
+                               }
+                               break;
+                       case 0xf0:
+                               switch(fMidiOutPacket[0]) {
+                                       case 0xf1:
+                                       case 0xf3:
+                                               if (i==2) {
+                                                       result =::midiOutShortMsg(fMidiOutDevice[p], (fMidiOutPacket[2]<<16 |  fMidiOutPacket[1]<<8 | fMidiOutPacket[0]));
+                                                       assert(result == MMSYSERR_NOERROR );
+                                               }
+                                               break;
+                                       case 0xf2:
+                                               if (i==1) {
+                                                       result =::midiOutShortMsg(fMidiOutDevice[p], (fMidiOutPacket[1]<<8 | fMidiOutPacket[0]));
+                                                       assert(result == MMSYSERR_NOERROR );
+                                               }
+                                               break;
+                                       case 0xf5:
+                                               fMidiOutCurrentPort = in_data-1;
+                                               break;
+                                       default:
+                                               break;
+                               }
+                               break;
+               }
+
+       }
+}
+
+void
+CSTedScreenWin32::MidiWait(void)
+{
+       while(fKeyEventNotified==0 && fKeyBufferAvailable==0 && fMidiBufferAvailable==0) {
+               DoMessageLoop();
+       }
+       fKeyEventNotified = FALSE;
+}
+
+// player
+static RCP_DATA* rcp = NULL;
+
+int
+CSTedScreenWin32::StartMidiPlayer(unsigned char* in_data, int in_len)
+{
+       if (rcp) {
+               CloseMidiPlayer(0);
+       }
+       rcp = (RCP_DATA *)::malloc(sizeof(RCP_DATA));
+       if (!rcp) return -1;
+       ::memset((void *)rcp, 0, sizeof(RCP_DATA));
+
+       rcp->command_name = (unsigned char *)"STed2";
+       rcp->is_player = FLAG_TRUE;
+       rcp->is_send_rtm = FLAG_TRUE;
+
+       rcp->data = in_data;
+       rcp->length = in_len;
+
+       rcpplay_start(rcp);
+
+       return -1;
+}
+
+int
+CSTedScreenWin32::StopMidiPlayer(void)
+{
+       return rcpplay_stop();
+}
+
+int
+CSTedScreenWin32::CloseMidiPlayer(int in_sig)
+{
+       if (rcp) {
+               rcpplay_stop();
+               rcpplay_close();
+               ::free((void *)rcp);
+               rcp = NULL;
+       }
+       return 0;
+}
+
+void
+CSTedScreenWin32::MidiPlayerWait(void)
+{
+       // 5msのタイマセット
+       ::SetTimer(hwnd_, IDT_STED2_WAIT_TIMER, 5, NULL);
+       // 何かイベントが発生するまでメッセージループを回す。
+       while(fKeyEventNotified == 0 && fKeyBufferAvailable == 0 && !fTimerEventNotified /* && fMidiBufferAvailable == 0 */)
+       {
+               DoMessageLoop();
+       }
+
+       fKeyEventNotified = FALSE;
+       fTimerEventNotified = FALSE;
+}
+
+void
+CSTedScreenWin32::NotifyTimer(UINT in_timerid)
+{
+       fTimerEventNotified = TRUE;
+}
diff --git a/win32_misc.cpp b/win32_misc.cpp
new file mode 100644 (file)
index 0000000..78b80d1
--- /dev/null
@@ -0,0 +1,69 @@
+/*
+  win32_misc.cpp
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+
+#include "sted_win32.h"
+#include "sted_screen_win32.h"
+#include <mmsystem.h>
+
+
+int
+CSTedScreenWin32::OnTime(void)
+{
+       DWORD time = ::timeGetTime();
+    return (unsigned int)((time/10)%863999);
+}
+
+int
+CSTedScreenWin32::USleep(long in_usec)
+{
+       ::Sleep(in_usec/1000);
+       return 0;
+}
+
+void
+CSTedScreenWin32::DoMessageLoop(void)
+{
+       MSG msg;
+       int result;
+
+       if(PeekMessage (&msg,NULL,0,0,PM_NOREMOVE)) {
+               result = GetMessage(&msg, NULL, 0, 0);
+               if (result < 0) {
+                       // panic!
+                       exit(0);
+               } else if (result==0) {
+                       exit(0);
+               }
+
+               if (!TranslateAccelerator(msg.hwnd, accel_, &msg)) 
+               {
+                       TranslateMessage(&msg);
+                       DispatchMessage(&msg);
+               }
+       } else {
+               Sleep(0);
+       }
+}
+
diff --git a/win32_pointer.cpp b/win32_pointer.cpp
new file mode 100644 (file)
index 0000000..1d2f7d6
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+  win32_pointer.cpp
+  base class of screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+
+#include "sted_screen_win32.h"
+
+
+// notification from main window
+void
+CSTedScreenWin32::NotifyPointerPosition(int in_x, int in_y, int in_wparam)
+{
+  fPointerEventNotified = TRUE;
+
+  fCurrentPointerX = in_x;
+  fCurrentPointerY = in_y;
+
+  if (in_wparam&MK_LBUTTON)
+         fCurrentPointerButtonStateL = EButtonOn;
+  else
+         fCurrentPointerButtonStateL = EButtonOff;
+  if (in_wparam&MK_RBUTTON)
+         fCurrentPointerButtonStateR = EButtonOn;
+  else
+         fCurrentPointerButtonStateR = EButtonOff;
+}
+
+void
+CSTedScreenWin32::NotifyPointerButtonState(int in_button, int in_state)
+{
+  if (in_button==EButtonLeft) {
+    fCurrentPointerButtonStateL = in_state;
+  } else if (in_button==EButtonRight) {
+    fCurrentPointerButtonStateR = in_state;
+  }
+  fPointerEventNotified = TRUE;
+}
+
+// pointer
+void 
+CSTedScreenWin32::MouseInit(void)
+{
+  fCurrentPointerX = 0;
+  fCurrentPointerY = 0;
+  fCurrentPointerButtonStateL = EButtonOff;
+  fCurrentPointerButtonStateR = EButtonOff;
+
+  fPointerEventNotified = FALSE;
+}
+
+void
+CSTedScreenWin32::SetMouseCursorVisible(int in_onoff)
+{
+  // just ignore
+}
+
+int 
+CSTedScreenWin32::GetMouseButtonState(void)
+{
+  int result = 0;
+
+  while (!fPointerEventNotified && !fKeyEventNotified && fKeyBufferAvailable==0) {
+         DoMessageLoop();
+  }
+  fPointerEventNotified = FALSE;
+  fKeyEventNotified = FALSE;
+
+  if (fCurrentPointerButtonStateL==EButtonOn) result|=0xff00;
+  if (fCurrentPointerButtonStateR==EButtonOn) result|=0x00ff;
+
+  return result;
+}
+
+int
+CSTedScreenWin32::SetMouseMoveLimit(int in_x0, int in_y0, int in_x1, int in_y1)
+{
+  fPointerMinX = in_x0;
+  fPointerMaxX = in_x1;
+  fPointerMinY = in_y0;
+  fPointerMaxY = in_y0;
+
+  return 0;
+}
+
+int
+CSTedScreenWin32::GetMousePos(int *out_x, int *out_y)
+{
+  int x,y;
+
+  x = fX68WindowWidth * fCurrentPointerX / fWindowWidth;
+  y = fX68WindowHeight * fCurrentPointerY / fWindowHeight;
+
+  if (x<fPointerMinX) x = fPointerMinX;
+  if (x>=fPointerMaxX) x = fPointerMaxX;
+  if (y<fPointerMinY) y = fPointerMinY;
+  if (y>=fPointerMaxY) y = fPointerMaxY;
+
+  if (out_x) *out_x = x;
+  if (out_y) *out_y = y;
+
+  return 0;
+}
+
+void
+CSTedScreenWin32::MouseWait(void)
+{
+  // Ugh!: implement it!
+}
diff --git a/win32_text.cpp b/win32_text.cpp
new file mode 100644 (file)
index 0000000..d6fc961
--- /dev/null
@@ -0,0 +1,272 @@
+/*
+  win32_text.cpp
+  base class of screen driver
+
+  Made by Studio Breeze. 2002
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#include "stdafx.h"
+#include "sted_screen_win32.h"
+
+
+// private methods
+
+BOOL
+CSTedScreenWin32::TextToWindowPos(int in_text_x, int in_text_y, int *out_x, int *out_y)
+{
+  if (out_x) *out_x = fWindowWidth * in_text_x / fX68TextWidth;
+  if (out_y) *out_y = fWindowHeight * in_text_y / fX68TextHeight;
+  return TRUE;
+}
+
+BOOL
+CSTedScreenWin32::TextToWindowPos(int *out_x, int *out_y)
+{
+  return TextToWindowPos(fCurrentTextX, fCurrentTextY, out_x, out_y);
+}
+
+int
+CSTedScreenWin32::GetTextWidth(LPCTSTR in_str, int in_len)
+{
+
+  if (!in_str) return 0;
+  if (in_len <= 0) return 0;
+
+  //u = toUCS2(in_str, in_len, &len);
+  IDWriteTextLayoutPtr l;
+  write_factory_->CreateTextLayout(in_str,in_len,text_fmt_,fWindowWidth,fTextLineHeight,&l);
+  DWRITE_TEXT_METRICS m;
+  l->GetMetrics(&m);
+
+  // Ugh!: should the data be cached ?
+
+
+
+  //if (!::GetTextExtentPoint32(fTextDC, in_str, in_len, &size)) return 0;
+
+  return (int)m.widthIncludingTrailingWhitespace;
+}
+
+// window
+void
+CSTedScreenWin32::SetTextWindow(int in_y, int in_h)
+{
+       if (in_y < 0) in_y = 0;
+       if (in_y >= fX68TextHeight) in_y = fX68TextHeight-1;
+       if (in_h < 0) in_h = 0;
+       if (in_y + in_h >= fX68TextHeight) in_h = fX68TextHeight-in_y;
+
+       fTextOriginY = in_y;
+       fTextHeight = in_h;
+}
+
+// cursor
+void 
+CSTedScreenWin32::SetCursor(int in_onoff)
+{
+  fIsCursorOn = in_onoff;
+  DrawCursor();
+}
+
+void
+CSTedScreenWin32::DrawCursor(void)
+{
+  if (fIsCursorOn) {
+         TextReverse(fCurrentTextX, fCurrentTextY, 1, 3);
+  }
+}
+
+// text
+void
+CSTedScreenWin32::Locate(int in_x, int in_y)
+{
+  in_y += fTextOriginY;
+
+  if (in_x >= fX68TextWidth) in_x = fX68TextWidth-1;
+  if (in_x<0) in_x=0;
+  if (in_y >= fTextHeight) in_y = fTextHeight;
+  if (in_y<0) in_y = 0;
+
+  fCurrentTextX = in_x;
+  fCurrentTextY = in_y;
+
+  DrawCursor();
+}
+
+void
+CSTedScreenWin32::Puts(const char* in_str)
+{
+  LPCTSTR u;
+  int len;
+  int x,y;
+  int l;
+  RECT r;
+  int sx, sy, ey;
+  int w,h;
+  char* str = (char *)in_str;
+
+  l = (int)strlen(str);
+  if(l == 0) return;
+
+  {
+  sf::begin_draw<ID2D1BitmapRenderTargetPtr> begin(text_bitmap_target_);
+
+  if (str[0] == '\r')
+  {
+    l -= 2;
+    str += 2;
+    fCurrentTextX = 0;
+    if (fCurrentTextY < fTextHeight - 1 )
+    { 
+     fCurrentTextY++;
+    } else {
+                 sx = 0;
+                 w = fWindowWidth;
+                 sy = fWindowHeight * (fTextOriginY + 1) / fX68TextHeight;
+                 ey = fWindowHeight * fTextOriginY / fX68TextHeight;
+                 h = fWindowHeight * (fTextHeight - 1) / fX68TextHeight;
+      ID2D1BitmapPtr b;
+      THROW_IF_ERR(text_bitmap_target_->GetBitmap(&b));
+      D2D1_RECT_F dr = D2D1::RectF(sx,ey,w + sx,h + ey);
+      D2D1_RECT_F sr = D2D1::RectF(sx,sy,w + sx,h + sy);
+      text_bitmap_target_->DrawBitmap(b,dr,1.0f,D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,sr);
+      //::BitBlt(fTextDC, sx, ey, w, h, fTextDC, sx, sy, SRCCOPY);
+                 //::BitBlt(fTextMaskDC, sx, ey, w, h, fTextMaskDC, sx, sy, SRCCOPY);
+       }
+  }
+
+  u = toUCS2(str, l, &len);
+  if (!u) return;
+  if (len == 0) return;
+
+  if (!TextToWindowPos(&x, &y)) return;
+  
+  IDWriteTextLayoutPtr l;
+  write_factory_->CreateTextLayout(u,len,text_fmt_,fWindowWidth,fTextLineHeight,&l);
+  DWRITE_TEXT_METRICS m;
+  
+  l->GetMetrics(&m);
+  text_bitmap_target_->PushAxisAlignedClip(D2D1::RectF(x,y,x + m.widthIncludingTrailingWhitespace,y + m.height),text_bitmap_target_->GetAntialiasMode());
+  //text_bitmap_target_->FillRectangle(D2D1::RectF(x,y,x + m.widthIncludingTrailingWhitespace,y + m.height),brush_text_clear_);
+  text_bitmap_target_->Clear();
+  text_bitmap_target_->PopAxisAlignedClip();
+  text_bitmap_target_->DrawTextLayout(D2D1::Point2F(x,y),l,brush_text_);
+  //text_bitmap_target_->DrawTextW(
+  //  u,len,text_fmt_,D2D1::RectF(x,y,x + fWindowWidth ,y + fTextLineHeight),brush_text_);
+  //text_bitmap_target_->DrawTextW(
+  //  u,len,text_fmt_,D2D1::RectF(0,0,300,300),brushr);
+
+  ////::TextOut(fTextDC, x, y, u, len);
+  ////::TextOut(fTextMaskDC, x, y, u, len);
+  fCurrentTextX += l;
+
+  ::SetRect(&r, x, y, x +m.widthIncludingTrailingWhitespace, y + m.height);
+
+  }
+
+  InvalidateRect(&r);
+
+  DrawCursor();
+
+  return;
+}
+
+void
+CSTedScreenWin32::ClsEol(void)
+{
+  RECT r;
+  int x, y;
+
+  if (!TextToWindowPos(&x,&y)) return;
+
+  ::SetRect(&r, 0, y, fWindowWidth, y + fTextLineHeight);
+  text_bitmap_target_->BeginDraw();
+  text_bitmap_target_->PushAxisAlignedClip(D2D1::RectF(0.0f,y,fWindowWidth,r.bottom),text_bitmap_target_->GetAntialiasMode());
+  text_bitmap_target_->Clear();
+  text_bitmap_target_->PopAxisAlignedClip();
+  text_bitmap_target_->EndDraw();
+
+  //::FillRect(fTextDC, &r, fBrushTextClear);
+  //::FillRect(fTextMaskDC, &r, MASK_OFF);
+
+  InvalidateRect(&r);
+}
+
+void
+CSTedScreenWin32::ClsEd(void)
+{
+  RECT r;
+  int x, y;
+
+  if (!TextToWindowPos(&x,&y)) return;
+
+  ::SetRect(&r, 0, y, fWindowWidth, fWindowHeight);
+  text_bitmap_target_->BeginDraw();
+  text_bitmap_target_->PushAxisAlignedClip(D2D1::RectF(0,y,fWindowWidth,fWindowHeight),text_bitmap_target_->GetAntialiasMode());
+  //text_bitmap_target_->FillRectangle(D2D1::RectF(0,y,fWindowWidth,fWindowHeight),brush_mask_off_);
+  text_bitmap_target_->Clear();
+  text_bitmap_target_->EndDraw();
+
+ /* ::FillRect(fTextDC, &r, fBrushTextClear);
+  ::FillRect(fTextMaskDC, &r, MASK_OFF);*/
+
+  InvalidateRect(&r);
+}
+
+void
+CSTedScreenWin32::GraphicsPuts(int in_x, int in_y, const char* in_str)
+{
+  int w, l, c;
+  int h;
+  int x, y;
+  LPCTSTR u;
+  int len;
+  RECT r;
+
+  c = (in_y >= fX68WindowHeight) ? 1: 0;
+  if (!toWindowPos(in_x, in_y % fX68WindowHeight, &x, &y)) return;
+  l = (int)strlen(in_str);
+
+  u = toUCS2(in_str, l, &len);
+  if (!u || len==0) return;
+
+  w = GetTextWidth(u, len);
+  h = fTextLineHeight;
+  
+  IDWriteTextLayoutPtr layout;
+  write_factory_->CreateTextLayout(u,len,text_fmt_,fWindowWidth,fTextLineHeight,&layout);
+  DWRITE_TEXT_METRICS m;
+  layout->GetMetrics(&m);
+
+  //::TextOut(fGraphicsWindowDC[c], x, y, u, len);
+  sf::begin_draw<ID2D1BitmapRenderTargetPtr> begin(graphics_bitmap_target_[c]);
+  //graphics_bitmap_target_[c]->PushAxisAlignedClip(D2D1::RectF(x,y,x + m.widthIncludingTrailingWhitespace,y + m.height),graphics_bitmap_target_[c]->GetAntialiasMode());
+  ////text_bitmap_target_->FillRectangle(D2D1::RectF(x,y,x + m.widthIncludingTrailingWhitespace,y + m.height),brush_text_clear_);
+  //graphics_bitmap_target_[c]->Clear();
+  //graphics_bitmap_target_[c]->PopAxisAlignedClip();
+  graphics_bitmap_target_[c]->DrawTextLayout(D2D1::Point2F(x,y),layout,brush_text_);
+  THROW_IF_ERR(begin.end_draw());
+
+  ::SetRect(&r, x, y, x + m.widthIncludingTrailingWhitespace, y + m.height);
+  InvalidateRect(&r);
+
+  return;  
+}
diff --git a/win32_win.cpp b/win32_win.cpp
new file mode 100644 (file)
index 0000000..35024bd
--- /dev/null
@@ -0,0 +1,1105 @@
+/*\r
+win32_win.cpp\r
+base class of screen driver\r
+\r
+Made by Studio Breeze. 2002\r
+\r
+Permission is hereby granted, free of charge, to any person obtaining a copy\r
+of this software and associated documentation files (the "Software"), to deal\r
+in the Software without restriction, including without limitation the rights\r
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
+copies of the Software, and to permit persons to whom the Software is\r
+furnished to do so, subject to the following conditions:\r
+\r
+The above copyright notice and this permission notice shall be included in\r
+all copies or substantial portions of the Software.\r
+\r
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\r
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
+THE SOFTWARE.\r
+*/\r
+#include "stdafx.h"\r
+#include "resource.h"\r
+#include "sted_win32.h"\r
+#include "sted_screen_win32.h"\r
+\r
+\r
+#define MAX_LOADSTRING 100\r
+\r
+#ifndef HINST_THISCOMPONENT\r
+EXTERN_C IMAGE_DOS_HEADER __ImageBase;\r
+#define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)\r
+#endif\r
+\r
+ LRESULT CALLBACK\r
+  Dlg_MidiDevices(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
+LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);\r
+\r
+CSTedScreenWin32::ptr_type CSTedScreenWin32::instance_;\r
+\r
+/* accessor */\r
+\r
+//CSTedScreenBase*\r
+//CreateScreenDriver(int in_size)\r
+//{\r
+//  return (CSTedScreenBase *)CSTedScreenWin32::New(in_size);\r
+//}\r
+\r
+//void\r
+//DestroyScreenDriver(CSTedScreenBase* in_driver)\r
+//{\r
+//  CSTedScreenWin32* self = (CSTedScreenWin32 *)in_driver;\r
+//  self->Tidy();\r
+//  delete self;\r
+//}\r
+\r
+inline CSTedScreenBase* GetDriver(void)\r
+{\r
+  return CSTedScreenWin32::instance().get();\r
+}\r
+\r
+void CSTedScreenWin32::init_instance()\r
+{\r
+\r
+  TCHAR title[MAX_LOADSTRING];                                 // タイトル バーのテキスト\r
+  TCHAR window_class[MAX_LOADSTRING];                  // メイン ウィンドウ クラス名\r
+  TCHAR window_menu[MAX_LOADSTRING];\r
+\r
+  LoadString(HINST_THISCOMPONENT, IDS_APP_TITLE, title, MAX_LOADSTRING);\r
+  LoadString(HINST_THISCOMPONENT, IDC_STED2, window_class, MAX_LOADSTRING);\r
+  LoadString(HINST_THISCOMPONENT, IDC_STED2, window_menu, MAX_LOADSTRING);\r
+\r
+  //(LPCTSTR)IDC_STED2\r
+\r
+  timeBeginPeriod(1);\r
+\r
+  instance_.reset(new CSTedScreenWin32(std::wstring(window_menu),std::wstring(window_class),false,0.0f,0.0f));\r
+  instance_->register_class(\r
+    (wchar_t*)IDC_STED2,\r
+    CS_HREDRAW | CS_VREDRAW,\r
+    0,\r
+    LoadIcon(HINST_THISCOMPONENT, (LPCTSTR)IDI_STED2),\r
+    LoadCursor(NULL, IDC_ARROW),\r
+    CreateSolidBrush(0x00000000),\r
+    LoadIcon(HINST_THISCOMPONENT, (LPCTSTR)IDI_SMALL)\r
+    );\r
+  instance_->create_window();\r
+  instance_->show(TRUE);\r
+  instance_->update();\r
+  instance_->Construct(16);\r
+\r
+  //TODO ご飯をたべる。\r
+  // UNDONE これは\r
+\r
+  //MyRegisterClass(hInstance);\r
+  //\r
+  //if (!InitInstance (hInstance, nCmdShow)) \r
+  //{\r
+  //   return FALSE;\r
+  //}\r
+\r
+\r
+}\r
+\r
+/* class */\r
+\r
+CSTedScreenWin32::CSTedScreenWin32(const std::wstring& menu_name,const std::wstring& name,bool fit_to_display,float width,float height) :\r
+sf::base_window(menu_name,name,fit_to_display,width,height)\r
+{\r
+\r
+  // fWindow = NULL;\r
+  fMenu = NULL;\r
+  //fWindowDC = NULL;\r
+\r
+  //fText = NULL;\r
+  //fTextMask = NULL;\r
+  //fGraphicsWindow[0] = NULL;\r
+  //fGraphicsWindow[1] = NULL;\r
+  //fOffScreen = NULL;\r
+  fOffScreenIsDirty = FALSE;\r
+  fCanUpdateWindow = TRUE;\r
+\r
+  //fTextDC = NULL;\r
+  //fTextMaskDC = NULL;\r
+  //fGraphicsWindowDC[0] = NULL;\r
+  //fGraphicsWindowDC[1] = NULL;\r
+  //fOffScreenDC = NULL;\r
+\r
+  fCurrentTextX = 0;\r
+  fCurrentTextY = 0;\r
+  fTextOriginY = 0;\r
+  fTextHeight = fX68TextHeight;\r
+  fIsCursorOn = FALSE;\r
+  fCurrentGraphics = 0;\r
+\r
+  fWindowWidth = 768;\r
+  fWindowHeight = 512;\r
+  fTextLineHeight = 12;\r
+\r
+  fUCS2Buf = NULL;\r
+  fSJISBuf = NULL;\r
+  const int fUCS2BufLen = 1024;\r
+  const int fSJISBufLen = 1024;\r
+\r
+  fCurrentTextColor = 0;\r
+  fCurrentTextBackColor = 0;\r
+  fCurrentGraphicsColor = 0;\r
+\r
+  //fBrushMaskOff = NULL;\r
+  //fBrushMaskOn = NULL;\r
+\r
+  fFileDirHandle = NULL;\r
+\r
+  fMidiInDevice = NULL;\r
+  fMidiInPort = 0;\r
+\r
+  for (int i = 0; i < fMidiOutPorts; i++) \r
+  {\r
+    fMidiOutDevice[i] = NULL;\r
+    fMidiOutPort[i] = 0; // default device\r
+  }\r
+  fMidiOutPacket[0] = -1;\r
+  fMidiOutPacket[1] = -1;\r
+  fMidiOutPacket[2] = -1;\r
+  fMidiOutPacket[3] = -1;\r
+  accel_ = LoadAccelerators(HINST_THISCOMPONENT, (LPCTSTR)IDC_STED2);\r
+\r
+  fTimerEventNotified = FALSE;\r
+\r
+  fConstructed = FALSE;\r
+\r
+}\r
+\r
+void CSTedScreenWin32::Construct(int in_size)\r
+{\r
+  int fw, fh;\r
+  int w,h;\r
+  int i;\r
+//  HFONT font;\r
+\r
+\r
+  try {\r
+\r
+ /*   ::ZeroMemory((void *)&lf, sizeof(LOGFONT));\r
+    std::wstring font_face(L"みかちゃん");\r
+    lf.lfHeight = in_size;\r
+    lf.lfWidth = 0;\r
+    lf.lfWeight = 0;\r
+    lf.lfItalic = 0;\r
+    lf.lfUnderline = 0;\r
+    lf.lfCharSet = SHIFTJIS_CHARSET;\r
+    lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;\r
+    font = ::CreateFontIndirect(&lf);*/\r
+\r
+\r
+\r
+    if (in_size < 0) return;\r
+    fh = in_size;\r
+    fw = in_size/2;\r
+    w = fw * fX68TextWidth;\r
+    h = fh * fX68TextHeight;\r
+\r
+    fMenu = ::GetMenu(hwnd_);\r
+\r
+    if (!hwnd_ || !fMenu) return;\r
+\r
+    // off-screen bitmaps\r
+\r
+    // fText = ::CreateCompatibleBitmap(fWindowDC, w, h);\r
+\r
\r
+    // hr = render_target_->CreateCompatibleRenderTarget(s,&graphics_bitmap_target_[1]);\r
+    // if(FAILED(hr)) return;\r
+\r
+    //fTextMask = ::CreateBitmap(w, h, 1, 1, NULL);\r
+    //if (!fTextMask) return;\r
+    // fGraphicsWindow[0] = ::CreateCompatibleBitmap(fWindowDC, w, h);\r
+    // if (!fGraphicsWindow[0]) return;\r
+    // fGraphicsWindow[1] = ::CreateCompatibleBitmap(fWindowDC, w, h);\r
+    // if (!fGraphicsWindow[1]) return;\r
+    // fOffScreen = ::CreateCompatibleBitmap(fWindowDC, w, h);\r
+    // if (!fOffScreen) return;\r
+\r
+    // device contexts\r
+    //fTextDC = ::CreateCompatibleDC(fWindowDC);\r
+    //if (!fTextDC) return;\r
+    //::SelectObject(fTextDC, fText);\r
+    //fTextMaskDC = ::CreateCompatibleDC(fWindowDC);\r
+    //if (!fTextMaskDC) return;\r
+    //::SelectObject(fTextMaskDC, fTextMask);\r
+    //fGraphicsWindowDC[0] = ::CreateCompatibleDC(fWindowDC);\r
+    //if (!fGraphicsWindowDC[0]) return;\r
+    //::SelectObject(fGraphicsWindowDC[0], fGraphicsWindow[0]);\r
+    //fGraphicsWindowDC[1] = ::CreateCompatibleDC(fWindowDC);\r
+    //if (!fGraphicsWindowDC[1]) return;\r
+    //::SelectObject(fGraphicsWindowDC[1], fGraphicsWindow[1]);\r
+    //fOffScreenDC = ::CreateCompatibleDC(fWindowDC);\r
+    //if (!fOffScreenDC) return;\r
+    //::SelectObject(fOffScreenDC, fOffScreen);\r
+\r
+    //::SelectObject(fTextDC, font);\r
+    //::SelectObject(fTextMaskDC, font);\r
+    //::SelectObject(fGraphicsWindowDC[0], font);\r
+    //::SelectObject(fGraphicsWindowDC[1], font);\r
+    //::SelectObject(fOffScreenDC, font);\r
+    //::SetBkMode(fTextDC, TRANSPARENT);\r
+    //::SetBkMode(fTextMaskDC, TRANSPARENT);\r
+    //::SetBkMode(fGraphicsWindowDC[0], TRANSPARENT);\r
+    //::SetBkMode(fGraphicsWindowDC[1], TRANSPARENT);\r
+    //::SetBkMode(fOffScreenDC, TRANSPARENT);\r
+    //::SetTextColor(fTextDC, RGB(0xff, 0xff, 0xff));\r
+    //::SetTextColor(fTextMaskDC, RGB(0x00, 0x00, 0x00));\r
+\r
+    fWindowWidth = w;\r
+    fWindowHeight = h;\r
+    fTextLineHeight = fh;\r
+\r
+\r
+    // TODO UCSバッファ必要か?後ほど確認\r
+    fUCS2Buf = (LPTSTR)malloc(sizeof(WCHAR) * fUCS2BufLen);\r
+    if (!fUCS2Buf) return;\r
+\r
+    // TODO UCSバッファ必要か?後ほど確認\r
+    fSJISBuf = (char *)malloc(sizeof(char) * fSJISBufLen);\r
+    if (!fSJISBuf) return;\r
+\r
+\r
+\r
+    //fBrushMaskOn = ::CreateSolidBrush(RGB(0xff,0xff,0xff));\r
+    //if (!fBrushMaskOn) return;\r
+    //fBrushMaskOff = ::CreateSolidBrush(RGB(0x00,0x00,0x00));\r
+    //if (!fBrushMaskOff) return;\r
+    //fBrushClear = ::CreateSolidBrush(RGB(0x00,0x00,0x00));\r
+    //if (!fBrushClear) return;\r
+    //fBrushTextClear = ::CreateSolidBrush(RGB(0xff,0xff,0xff));\r
+    //if (!fBrushTextClear) return;\r
+\r
+    for (i = 0; i < 3; i++) \r
+    {\r
+      SetTextPalette(i, 0);\r
+    }\r
+\r
+    h += ::GetSystemMetrics(SM_CYCAPTION);\r
+    h += ::GetSystemMetrics(SM_CYMENU);\r
+    h += (::GetSystemMetrics(SM_CYSIZEFRAME) * 2);\r
+    w += ::GetSystemMetrics(SM_CXSIZEFRAME) * 2;\r
+\r
+    ::SetWindowPos(\r
+      hwnd_, HWND_TOP, 150, 150, w, h,\r
+      SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOZORDER);\r
+\r
+    // デバイス非依存リソースの作成\r
+    create_device_independent_resources();\r
+\r
+    // デバイス依存リソースの作成\r
+    create_device();\r
+\r
+    fConstructed = TRUE;\r
+  } catch (...){\r
+    fConstructed = FALSE;\r
+  }\r
+}\r
+\r
+//CSTedScreenWin32*\r
+//CSTedScreenWin32::New(int in_screensize)\r
+//{\r
+//  CSTedScreenWin32* self;\r
+//  self = new CSTedScreenWin32;\r
+//  if (!self) return NULL;\r
+//\r
+//  self->Construct(in_screensize);\r
+//  if (!self->fConstructed) {\r
+//    self->Tidy();\r
+//    delete self;\r
+//    return NULL;\r
+//  }\r
+//  return self;\r
+//}\r
+\r
+CSTedScreenWin32::~CSTedScreenWin32()\r
+{\r
+}\r
+\r
+void\r
+  CSTedScreenWin32::Tidy(void)\r
+{\r
+  //if (fTextDC) ::DeleteDC(fTextDC);\r
+  //fTextDC = NULL;\r
+  //if (fTextMaskDC) ::DeleteDC(fTextMaskDC);\r
+  //fTextMaskDC = NULL;\r
+  //if (fGraphicsWindowDC[0]) ::DeleteDC(fGraphicsWindowDC[0]);\r
+  //fGraphicsWindowDC[0] = NULL;\r
+  //if (fGraphicsWindowDC[1]) ::DeleteDC(fGraphicsWindowDC[1]);\r
+  //fGraphicsWindowDC[2] = NULL;\r
+  //if (fOffScreenDC) ::DeleteDC(fOffScreenDC);\r
+  //fOffScreenDC = NULL;\r
+\r
+ /* if (fText) ::DeleteObject(fText);\r
+  fText = NULL;\r
+  if (fTextMask) ::DeleteObject(fTextMask);\r
+  fTextMask = NULL;\r
+  if (fGraphicsWindow[0]) ::DeleteObject(fGraphicsWindow[0]);\r
+  fGraphicsWindow[0] = NULL;\r
+  if (fGraphicsWindow[1]) ::DeleteObject(fGraphicsWindow[1]);\r
+  fGraphicsWindow[1] = NULL;\r
+  if (fOffScreen) ::DeleteObject(fOffScreen);\r
+  fOffScreen = NULL;*/\r
+\r
+  //if (fUCS2Buf) free((void *)fUCS2Buf);\r
+  //fUCS2Buf = NULL;\r
+  //if (fSJISBuf) free((void *)fSJISBuf);\r
+  //fSJISBuf = NULL;\r
+\r
+  //if (fBrushMaskOn) ::DeleteObject(fBrushMaskOn);\r
+  //fBrushMaskOn = NULL;\r
+  //if (fBrushMaskOff) ::DeleteObject(fBrushMaskOff);\r
+  //fBrushMaskOff = NULL;\r
+  //if (fBrushClear) ::DeleteObject(fBrushClear);\r
+  //fBrushClear = NULL;\r
+  //if (fBrushTextClear) ::DeleteObject(fBrushTextClear);\r
+  //fBrushTextClear = NULL;\r
+\r
+  discard_device();\r
+  safe_release(render_target_);\r
+\r
+  if (fFileDirHandle) {\r
+    ::FindClose(fFileDirHandle);\r
+    fFileDirHandle = NULL;\r
+  }\r
+\r
+  ::SetRectEmpty(&fInvalidRect);\r
+\r
+  fCanUpdateWindow = TRUE;\r
+\r
+  fTimerEventNotified = FALSE;\r
+\r
+  fConstructed = FALSE;\r
+}\r
+\r
+// window\r
+void\r
+  CSTedScreenWin32::InitWindow(void)\r
+{\r
+  RECT r1;\r
+\r
+  ::SetRect(&r1, 0, 0, fWindowWidth, fWindowHeight);\r
+  D2D1_RECT_F r(D2D1::RectF(0.0f,0.0f,(float)fWindowWidth,(float)fWindowHeight));\r
+\r
+  sf::begin_draw<ID2D1BitmapRenderTargetPtr> draw_text(text_bitmap_target_);\r
+  sf::begin_draw<ID2D1BitmapRenderTargetPtr> draw_g_bitmap1(graphics_bitmap_target_[0]);\r
+  sf::begin_draw<ID2D1BitmapRenderTargetPtr> draw_g_bitmap2(graphics_bitmap_target_[1]);\r
+\r
+  text_bitmap_target_->FillRectangle(r,brush_text_clear_);\r
+  graphics_bitmap_target_[0]->FillRectangle(r,brush_clear_);\r
+  graphics_bitmap_target_[1]->FillRectangle(r,brush_clear_);\r
+\r
+  //::FillRect(fTextDC, &r, fBrushTextClear);\r
+  //::FillRect(fTextMaskDC, &r, MASK_OFF);\r
+  //::FillRect(fGraphicsWindowDC[0], &r, fBrushClear);\r
+  //::FillRect(fGraphicsWindowDC[1], &r, fBrushClear);\r
+  //::FillRect(fOffScreenDC, &r, fBrushClear);\r
+\r
+  //::SetTextColor(fTextDC, RGB(0xff, 0xff, 0xff));\r
+  ////::SetTextColor(fTextMaskDC, RGB(0xff, 0xff, 0xff));\r
+  //::SetBkColor(fTextDC, RGB(0x00, 0x00, 0x00));\r
+  //::SetBkColor(fTextMaskDC, RGB(0xff, 0xff, 0xff));\r
+  //::SetBkMode(fTextDC, OPAQUE);\r
+  //::SetBkMode(fTextMaskDC, OPAQUE);\r
+\r
+  //::SetTextColor(fGraphicsWindowDC[0], RGB(0xff, 0xff, 0xff));\r
+  //::SetTextColor(fGraphicsWindowDC[1], RGB(0xff, 0xff, 0xff));\r
+  //::SetBkColor(fGraphicsWindowDC[0], RGB(0x00, 0x00, 0x00));\r
+  //::SetBkColor(fGraphicsWindowDC[1], RGB(0x00, 0x00, 0x00));\r
+  //::SetBkMode(fGraphicsWindowDC[0], OPAQUE);\r
+  //::SetBkMode(fGraphicsWindowDC[1], OPAQUE);\r
+\r
+  //::SetTextColor(fOffScreenDC, RGB(0x00, 0x00, 0x00));\r
+  //::SetBkColor(fOffScreenDC, RGB(0xff, 0xff, 0xff));\r
+  //::SetBkMode(fOffScreenDC, OPAQUE);\r
+\r
+  ::SetRectEmpty(&fInvalidRect);\r
+\r
+  ::memset((void *)fUCS2Buf, 0, sizeof(WCHAR)*fUCS2BufLen);\r
+  ::memset((void *)fSJISBuf, 0, sizeof(char)*fSJISBufLen);\r
+\r
+  fCurrentTextX = 0;\r
+  fCurrentTextY = 0;\r
+  fIsCursorOn = FALSE;\r
+  fCurrentGraphics = 0;\r
+  fCurrentTextColor = 3;\r
+  fCurrentTextBackColor = 0;\r
+  fCurrentGraphicsColor = 0;\r
+\r
+  InvalidateRect(&r1);\r
+}\r
+\r
+void\r
+  CSTedScreenWin32::CloseWindow(void)\r
+{\r
+}\r
+\r
+void\r
+  CSTedScreenWin32::RepaintWindow(void)\r
+{\r
+  InvalidateRect(NULL);\r
+}\r
+\r
+void\r
+  CSTedScreenWin32::UpdateWindow(void)\r
+{\r
+  fCanUpdateWindow = TRUE;\r
+  ::UpdateWindow(hwnd_);\r
+}\r
+\r
+void\r
+  CSTedScreenWin32::DisableUpdateWindow(void)\r
+{\r
+  fCanUpdateWindow = FALSE;\r
+}\r
+\r
+\r
+// private\r
+void\r
+  CSTedScreenWin32::InvalidateRect(const RECT *in_rect)\r
+{\r
+  RECT r;\r
+  int w,h;\r
+\r
+  if (::IsRectEmpty(&fInvalidRect)) {\r
+    ::CopyRect(&r, in_rect);\r
+  } else {\r
+    ::UnionRect(&r, &fInvalidRect, in_rect);\r
+  }\r
+  w = r.right - r.left;\r
+  h = r.bottom - r.top;\r
+  if (fCanUpdateWindow && (w*h > fWindowHeight * fWindowWidth / 8)) \r
+  {\r
+    update();\r
+  } else {\r
+    ::CopyRect(&fInvalidRect, &r);\r
+  }\r
+\r
+  ::InvalidateRect(hwnd_, in_rect, FALSE);\r
+  fOffScreenIsDirty = TRUE;\r
+}\r
+\r
+void\r
+  CSTedScreenWin32::InvalidateRect(const int in_x, const int in_y, const int in_w, const int in_h)\r
+{\r
+  RECT r;\r
+  ::SetRect(&r, in_x, in_y, in_x+in_w, in_y+in_h);\r
+  InvalidateRect(&r);\r
+}\r
+\r
+// public\r
+void\r
+  CSTedScreenWin32::Paint(RECT *in_rect,HDC dc)\r
+{\r
+  int x,y;\r
+  int w,h;\r
+\r
+  x = in_rect->left;\r
+  y = in_rect->top;\r
+  w = in_rect->right-x;\r
+  h = in_rect->bottom-y;\r
+  D2D1_RECT_F r= {in_rect->left,in_rect->top,in_rect->right,in_rect->bottom}; \r
+\r
+  if (fOffScreenIsDirty) {\r
+\r
+    ID2D1BitmapPtr bitmap_text;\r
+    ID2D1BitmapPtr bitmap_graphics;\r
+\r
+    graphics_bitmap_target_[fCurrentGraphics]->GetBitmap(&bitmap_graphics);\r
+    text_bitmap_target_->GetBitmap(&bitmap_text);\r
+\r
+    //ID2D1SolidColorBrushPtr brushr;\r
+    //text_bitmap_target_->CreateSolidColorBrush(D2D1::ColorF(1.0f,0.0f,0.0f), &brushr);\r
+\r
+    //text_bitmap_target_->BeginDraw();\r
+    //text_bitmap_target_->Clear(D2D1::ColorF(0.0f,0.0f,0.0f,0.0f));\r
+    //std::wstring a(L"test test test");\r
+    //  text_bitmap_target_->DrawTextW(\r
+    //a.c_str(),a.size(),text_fmt_,D2D1::RectF(0,0,300,300),brushr);\r
+\r
+    //text_bitmap_target_->EndDraw();\r
+\r
+\r
+\r
+    \r
+    {\r
+      sf::begin_draw<ID2D1HwndRenderTargetPtr> begin(render_target_);\r
+      render_target_->PushAxisAlignedClip(r,render_target_->GetAntialiasMode());\r
+      render_target_->Clear(D2D1::ColorF(0.0f,0.0f,0.0f,1.0f));\r
+      render_target_->PopAxisAlignedClip();\r
+      render_target_->DrawBitmap(bitmap_graphics,r,1.0f,D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,r);\r
+      render_target_->DrawBitmap(bitmap_text,r,1.0f,D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,r);\r
+\r
+      //ID2D1SolidColorBrushPtr brushr;\r
+      //render_target_->CreateSolidColorBrush(D2D1::ColorF(1.0f,0.0f,0.0f), &brushr);\r
+      //render_target_->FillRectangle(D2D1::RectF(0.0f,0.0f,200.0f,200.0f),brushr);\r
+      //::BitBlt(fOffScreenDC, x,y,w,h, fGraphicsWindowDC[fCurrentGraphics], x,y, SRCCOPY);\r
+      //::BitBlt(fOffScreenDC, x,y,w,h, fTextMaskDC, x,y, SRCPAINT);\r
+      //::BitBlt(fOffScreenDC, x,y,w,h, fTextDC, x,y, SRCAND);\r
+      //::BitBlt(dc, x,y,w,h, fGraphicsWindowDC[fCurrentGraphics], x,y, SRCCOPY);\r
+      //::BitBlt(dc, x,y,w,h, fTextMaskDC, x,y, SRCPAINT);\r
+      //::BitBlt(dc, x,y,w,h, fTextDC, x,y, SRCAND);\r
+      THROW_IF_ERR(begin.end_draw());\r
+    }\r
+\r
+    fOffScreenIsDirty = FALSE;\r
+    ::SetRectEmpty(&fInvalidRect);\r
+  }\r
+\r
+  //::BitBlt(dc, x,y,w,h, fOffScreenDC, x,y, SRCCOPY);\r
+\r
+  fCanUpdateWindow = TRUE;\r
+}\r
+\r
+LPCTSTR\r
+  CSTedScreenWin32::toUCS2(const char* in_str, int *out_len)\r
+{\r
+  return toUCS2(in_str, (int)::strlen(in_str), out_len);\r
+}\r
+\r
+LPCTSTR \r
+  CSTedScreenWin32::toUCS2(const char* in_str, int in_len, int *out_len)\r
+{\r
+#ifdef _UNICODE\r
+  int bytes;\r
+  bytes = ::MultiByteToWideChar(CP_ACP, 0, in_str, in_len, fUCS2Buf, fUCS2BufLen);\r
+  if (out_len) *out_len = bytes;\r
+  return fUCS2Buf;\r
+#else\r
+  int bytes = in_len;\r
+  if (fUCS2BufLen<=in_len) bytes = fUCS2BufLen-1;\r
+  ::memcpy((void *)fUCS2Buf, in_str, bytes);\r
+  ((char *)fUCS2Buf)[bytes] = '\0';\r
+  if (out_len) *out_len = bytes;\r
+  return fUCS2Buf;\r
+#endif\r
+}\r
+\r
+const char*\r
+  CSTedScreenWin32::toSJIS(LPCTSTR in_str, int *out_len)\r
+{\r
+#ifdef _UNICODE\r
+  int bytes;\r
+  bytes = ::WideCharToMultiByte(CP_ACP, 0, in_str, -1, fSJISBuf, fSJISBufLen, NULL, NULL);\r
+  if (out_len) *out_len = bytes;\r
+  return fSJISBuf;\r
+#else\r
+  int bytes;\r
+  bytes = (int)::strlen(in_str);\r
+  if (bytes>=fSJISBufLen) bytes = fSJISBufLen-1;\r
+  ::memcpy((void *)fSJISBuf, in_str, bytes);\r
+  fSJISBuf[bytes] = '\0';\r
+  if (out_len) *out_len = bytes;\r
+  return fSJISBuf;\r
+#endif\r
+}\r
+\r
+void\r
+  Exit(int in_result)\r
+{\r
+  ::PostQuitMessage(in_result);\r
+  ::exit(in_result);\r
+}\r
+\r
+// player control\r
+//static LRESULT\r
+//Player_PlayAll(CSTedScreenWin32* in_drv)\r
+//{\r
+//     if (in_drv) {\r
+//             in_drv->NotifyKeyPressed(VK_NONCONVERT);\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+//static LRESULT\r
+//Player_PlayTrack(CSTedScreenWin32* in_drv)\r
+//{\r
+//     if (in_drv) {\r
+//             in_drv->NotifyKeyPressed(VK_SHIFT);\r
+//             in_drv->NotifyKeyPressed(VK_LMENU);\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+//static LRESULT\r
+//Player_PlayMeas(CSTedScreenWin32* in_drv)\r
+//{\r
+//     if (in_drv) {\r
+//             in_drv->NotifyKeyPressed(VK_LMENU);\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+//static LRESULT\r
+//Player_PlayStop(CSTedScreenWin32* in_drv)\r
+//{\r
+//     if (in_drv) {\r
+//             in_drv->NotifyKeyPressed(VK_RMENU);\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+//static LRESULT\r
+//Player_ToggleTrace(CSTedScreenWin32* in_drv)\r
+//{\r
+//     HMENU menu;\r
+//     MENUITEMINFO info;\r
+//\r
+//     ::ZeroMemory((void *)&info, sizeof(MENUITEMINFO));\r
+//     info.cbSize = sizeof(MENUITEMINFO);\r
+//     info.fMask = MIIM_STATE;\r
+//\r
+//     menu = STedGetMenu();\r
+//     if (in_drv && menu) {\r
+//             if (::GetMenuItemInfo(menu, IDM_PLAY_TRACE, FALSE, &info)) {\r
+//                     info.fState = (info.fState&MFS_CHECKED) ? MFS_UNCHECKED : MFS_CHECKED;\r
+//                     ::SetMenuItemInfo(menu, IDM_PLAY_TRACE, FALSE, &info);\r
+//                     if (info.fState&MFS_CHECKED) {\r
+//                             in_drv->NotifyKeyPressed(VK_LCONTROL);\r
+//                     } else {\r
+//                             in_drv->NotifyKeyReleased(VK_LCONTROL);\r
+//                     }\r
+//             }\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+//static LRESULT\r
+//RhythmEdit_CurrentMeas(CSTedScreenWin32* in_drv)\r
+//{\r
+//     if (in_drv) {\r
+//             in_drv->NotifyKeyPressed(0xd8);\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+//static LRESULT\r
+//RhythmEdit_NewMeas(CSTedScreenWin32* in_drv)\r
+//{\r
+//     if (in_drv) {\r
+//             in_drv->NotifyKeyPressed(0xd9);\r
+//     }\r
+//     return 0;\r
+//}\r
+\r
+LRESULT CSTedScreenWin32::window_proc(HWND hwnd,boost::uint32_t message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  int wmId, wmEvent;\r
+  //PAINTSTRUCT ps;\r
+//  HDC hdc;\r
+//  RECT r;\r
+\r
+  switch (message) \r
+  {\r
+  case WM_CREATE:\r
+    //create_device();\r
+    return ::DefWindowProcW(hwnd,message,wParam,lParam);\r
+    break;\r
+  case WM_DWMWINDOWMAXIMIZEDCHANGE:\r
+    ::OutputDebugStringW(L"WM_DWMWINDOWMAXIMIZEDCHANGE\n");\r
+    break;\r
+  case WM_ACTIVATE:\r
+    ::OutputDebugStringW(L"WM_ACTIVATE\n");\r
+    break;\r
+  case WM_ACTIVATEAPP:\r
+    ::OutputDebugStringW(L"WM_ACTIVATEAPP\n");\r
+    break;\r
+  case WM_SIZING:\r
+    ::OutputDebugStringW(L"WM_SIZING\n");\r
+    break;\r
+  case WM_SIZE:\r
+    {\r
+      ::OutputDebugStringW(L"WM_SIZE\n");\r
+\r
+\r
+      if (wParam == SIZE_RESTORED  )\r
+      {\r
+        if (render_target_)\r
+        {\r
+          InvalidateRect(0,0,fWindowWidth,fWindowHeight);\r
+          //D2D1_SIZE_U size;\r
+          //size.width = lParam & 0xFFFF;\r
+          //size.height = (lParam >> 16) & 0xFFFF; ;\r
+          //if(size.width != fWindowWidth || size.height != fWindowHeight){\r
+          //  render_target_->Resize(size);\r
+          //  discard_device();\r
+          //  create_device();\r
+\r
+          //  sf::begin_draw<ID2D1BitmapRenderTargetPtr> draw_text(text_bitmap_target_);\r
+          //  sf::begin_draw<ID2D1BitmapRenderTargetPtr> draw_g_bitmap1(graphics_bitmap_target_[0]);\r
+          //  sf::begin_draw<ID2D1BitmapRenderTargetPtr> draw_g_bitmap2(graphics_bitmap_target_[1]);\r
+\r
+          //  D2D1_COLOR_F clear_color = D2D1::ColorF(0.0f,0.0f,0.0f,0.0f);\r
+          //  text_bitmap_target_->Clear(clear_color);\r
+          //  graphics_bitmap_target_[0]->Clear(clear_color);\r
+          //  graphics_bitmap_target_[1]->Clear(clear_color);\r
+          //  draw_text.end_draw();\r
+          //  draw_g_bitmap1.end_draw();\r
+          //  draw_g_bitmap2.end_draw();\r
+          //}\r
+        }\r
+      }\r
+\r
+    }\r
+    break;\r
+  case WM_ERASEBKGND:\r
+    {\r
+      return FALSE;\r
+    }\r
+    break;\r
+  case WM_DISPLAYCHANGE:\r
+    {\r
+      ::InvalidateRect(hwnd, NULL, FALSE);\r
+      return ::DefWindowProcW(hwnd,message,wParam,lParam);\r
+\r
+    }\r
+    break;\r
+  case WM_COMMAND:\r
+    wmId    = LOWORD(wParam); \r
+    wmEvent = HIWORD(wParam); \r
+    // 選択されたメニューの解析 :\r
+    switch (wmId)\r
+    {\r
+    case IDM_ABOUT:\r
+      DialogBox(HINST_THISCOMPONENT, (LPCTSTR)IDD_ABOUTBOX, hwnd_, (DLGPROC)About);\r
+      break;\r
+    case IDM_EXIT:\r
+      DestroyWindow(hwnd_);\r
+      break;\r
+    case IDM_PREFS_MIDIPORTS:\r
+      DialogBox(HINST_THISCOMPONENT, (LPCTSTR)IDD_PREF_MIDIDEVICE, hwnd_, (DLGPROC)Dlg_MidiDevices);\r
+      break;\r
+    case IDM_PLAY_PLAYALL:\r
+      NotifyKeyPressed(VK_NONCONVERT);\r
+      return 0;\r
+      break;\r
+    case IDM_PLAY_PLAYTRACK:\r
+      NotifyKeyPressed(VK_SHIFT);\r
+      NotifyKeyPressed(VK_LMENU);\r
+      return 0;\r
+      break;\r
+    case IDM_PLAY_PLAYMEASURE:\r
+      NotifyKeyPressed(VK_LMENU);\r
+      return 0;\r
+      break;\r
+    case IDM_PLAY_STOP:\r
+      NotifyKeyPressed(VK_RMENU);\r
+      return 0;\r
+      break;\r
+    case IDM_PLAY_TRACE:\r
+      {\r
+        HMENU menu;\r
+        MENUITEMINFO info;\r
+\r
+        ::ZeroMemory((void *)&info, sizeof(MENUITEMINFO));\r
+        info.cbSize = sizeof(MENUITEMINFO);\r
+        info.fMask = MIIM_STATE;\r
+\r
+        menu = ::GetMenu(hwnd_);\r
+        if (menu) {\r
+          if (::GetMenuItemInfo(menu, IDM_PLAY_TRACE, FALSE, &info)) {\r
+            info.fState = (info.fState&MFS_CHECKED) ? MFS_UNCHECKED : MFS_CHECKED;\r
+            ::SetMenuItemInfo(menu, IDM_PLAY_TRACE, FALSE, &info);\r
+            if (info.fState&MFS_CHECKED) {\r
+              NotifyKeyPressed(VK_LCONTROL);\r
+            } else {\r
+              NotifyKeyReleased(VK_LCONTROL);\r
+            }\r
+          }\r
+        }\r
+        return 0;\r
+      }\r
+      break;\r
+    case IDM_EDIT_RHYTHMTRACK_CURRENTMEAS:\r
+      NotifyKeyPressed(0xd8);\r
+      return 0;\r
+      break;\r
+    case IDM_EDIT_RHYTHMTRACK_NEWMEAS:\r
+      NotifyKeyPressed(0xd9);\r
+      return 0;\r
+      break;\r
+    }\r
+    break;\r
+\r
+  case WM_KEYDOWN:\r
+    NotifyKeyPressed((int)wParam);\r
+    return 0;\r
+    break;\r
+  case WM_KEYUP:\r
+    NotifyKeyReleased((int)wParam);\r
+    break;\r
+  case WM_SYSKEYDOWN:\r
+\r
+    if (wParam==VK_F10) {\r
+      NotifyKeyPressed((int)wParam);\r
+      return 0;\r
+    }\r
+    break;\r
+  case WM_SYSKEYUP:\r
+    if (wParam==VK_F10) {\r
+      NotifyKeyReleased((int)wParam);\r
+      return 0;\r
+    } \r
+    break;\r
+  case WM_CHAR:\r
+    NotifyChar((int)wParam);\r
+    return 0;\r
+    break;\r
+\r
+  case WM_PAINT:\r
+    {\r
+      RECT rc;\r
+      if (::GetUpdateRect(hwnd_, &rc, FALSE))\r
+      { \r
+        // 描画開始\r
+        sf::paint_struct ps(hwnd_);\r
+        //RECT rc;\r
+\r
+        // クライアント領域を求める\r
+        GetClientRect(\r
+          hwnd_,\r
+          &rc\r
+          );\r
+\r
+        // DC描画\r
+        Paint(&rc,ps->hdc);\r
+\r
+        // Direct2DレンダーターゲットにHDCをバインド\r
+        //THROW_IF_ERR(render_target_->BindDC(\r
+        //                                             ps->hdc\r
+        //     ,\r
+        //     &rc\r
+        //     ));\r
+\r
+        //                                     render_target_->BeginDraw();\r
+\r
+        // Direct2D描画開始。オブジェクトの破棄と同時に描画終了\r
+        //sf::begin_draw<ID2D1DCRenderTargetPtr> d(render_target_);\r
+        //{sf::begin_draw<ID2D1HwndRenderTargetPtr> d(render_target_);\r
+\r
+        //ID2D1SolidColorBrushPtr brushr;\r
+        //render_target_->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Aqua), &brushr);\r
+\r
+        //D2D1_RECT_F layoutRect = D2D1::RectF(rc.left, rc.top, rc.right,rc.bottom);\r
+        //IDWriteTextFormatPtr write_text_format;\r
+\r
+        //// Text Formatの作成\r
+        //THROW_IF_ERR(write_factory_->CreateTextFormat(\r
+        //  L"メイリオ",                // Font family name.\r
+        //  NULL,                       // Font collection (NULL sets it to use the system font collection).\r
+        //  DWRITE_FONT_WEIGHT_BOLD,\r
+        //  DWRITE_FONT_STYLE_NORMAL,\r
+        //  DWRITE_FONT_STRETCH_NORMAL,\r
+        //  48.0f,\r
+        //  L"ja-jp",\r
+        //  &write_text_format\r
+        //  ));\r
+\r
+        //// テキストの描画\r
+        //std::wstring t = L"とりあえずDirect2DとDC描画を混在させてみました。";\r
+\r
+        //render_target_->DrawTextW(\r
+        //  t.c_str(),\r
+        //  t.size(),\r
+        //  write_text_format,\r
+        //  layoutRect, \r
+        //  brushr);\r
+        //}\r
+\r
+      } // スコープが外れるとともに描画終了。\r
+      //}\r
+    }\r
+    return 0L;\r
+    break;\r
+  case WM_MOUSEMOVE:\r
+    NotifyPointerPosition(LOWORD(lParam), HIWORD(lParam), (int)wParam);\r
+    return 0;\r
+    break;\r
+  case WM_LBUTTONDOWN:\r
+    NotifyPointerButtonState(EButtonLeft, EButtonOn);\r
+    return 0;\r
+    break;\r
+  case WM_RBUTTONDOWN:\r
+    NotifyPointerButtonState(EButtonRight, EButtonOn);\r
+    return 0;\r
+    break;\r
+  case WM_LBUTTONUP:\r
+    NotifyPointerButtonState(EButtonLeft, EButtonOff);\r
+    return 0;\r
+    break;\r
+  case WM_RBUTTONUP:\r
+    NotifyPointerButtonState(EButtonRight, EButtonOff);\r
+    return 0;\r
+    break;\r
+  case MM_MIM_DATA:\r
+    NotifyMidiIn((unsigned long)lParam);\r
+    break;\r
+  case WM_TIMER:\r
+    NotifyTimer((UINT)wParam);\r
+    break;\r
+  case WM_CLOSE:\r
+    Tidy();\r
+    break;\r
+  case WM_DESTROY:\r
+    PostQuitMessage(0);\r
+    break;\r
+  case WM_QUIT:\r
+    ::exit(0);\r
+    break;\r
+  }\r
+  return DefWindowProc(hwnd_, message, wParam, lParam);\r
+  ;\r
+}\r
+\r
+ const char* get_version_id(void);\r
+\r
+LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)\r
+{\r
+  switch (message)\r
+  {\r
+  case WM_INITDIALOG:\r
+    {\r
+      CSTedScreenWin32* drv;\r
+      LPCTSTR u;\r
+      char buf[1024];\r
+\r
+      drv = (CSTedScreenWin32 *)GetDriver();\r
+      if (drv) {\r
+        ::strcpy(buf, "Version ");\r
+        ::strcat(buf, get_version_id());\r
+        u = drv->toUCS2(buf, (int)::strlen(buf), NULL);\r
+\r
+        ::SetDlgItemText(hDlg, IDC_VERSION, u);\r
+      }\r
+      return TRUE;\r
+      break;\r
+    }\r
+\r
+  case WM_COMMAND:\r
+    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) \r
+    {\r
+      EndDialog(hDlg, LOWORD(wParam));\r
+      return TRUE;\r
+    }\r
+    break;\r
+  }\r
+  return FALSE;\r
+}\r
+\r
+void CSTedScreenWin32::discard_device()\r
+{\r
+  ::OutputDebugStringW(L"discard_device()\n");\r
+  safe_release(graphics_dc_target_[0]);\r
+  safe_release(graphics_dc_target_[1]);\r
+  safe_release(text_dc_target_);\r
+  safe_release(graphics_bitmap_target_[0]);\r
+  safe_release(graphics_bitmap_target_[1]);\r
+  safe_release(text_bitmap_target_);\r
+  safe_release(brush_mask_on_);\r
+  safe_release(brush_mask_off_);\r
+  safe_release(brush_clear_);\r
+  safe_release(brush_text_clear_);\r
+  safe_release(brush_text_);\r
+\r
+}\r
+\r
+void CSTedScreenWin32::create_device()\r
+{\r
+\r
+               // Create a DC render target \r
+               //D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(\r
+               //      D2D1_RENDER_TARGET_TYPE_DEFAULT,\r
+               //      D2D1::PixelFormat(\r
+               //              DXGI_FORMAT_B8G8R8A8_UNORM,\r
+               //              D2D1_ALPHA_MODE_IGNORE\r
+               //              ) , 0.0, 0.0,\r
+               //      D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE\r
+               //      );\r
+\r
+               //EXCEPTION_ON_ERROR(factory_->CreateDCRenderTarget(\r
+               //      &props,\r
+               //      &render_target_\r
+               //      ));\r
\r
+  HRESULT hr = S_OK;\r
+  D2D1_SIZE_F s(D2D1::SizeF(fWindowWidth, fWindowHeight));\r
+\r
+       // HwndRenderTargetの作成\r
+  if(!render_target_)\r
+       {\r
+\r
+    D2D1_RENDER_TARGET_PROPERTIES rtProps = D2D1::RenderTargetProperties();\r
+    rtProps.usage =  D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE;\r
+               THROW_IF_ERR(factory_->CreateHwndRenderTarget(\r
+                       rtProps,\r
+                       D2D1::HwndRenderTargetProperties(hwnd_, D2D1::SizeU(fWindowWidth,fWindowHeight),D2D1_PRESENT_OPTIONS_IMMEDIATELY),\r
+                       &render_target_\r
+                       ));\r
+\r
+       }\r
+\r
+  // バックバッファの作成 \r
+  THROW_IF_ERR(\r
+    render_target_->CreateCompatibleRenderTarget(\r
+      &s,NULL,NULL,D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE,&text_bitmap_target_));\r
+  //text_bitmap_target_->SetAntialiasMode(D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);\r
+  THROW_IF_ERR(\r
+    render_target_->CreateCompatibleRenderTarget(\r
+      &s,NULL,NULL,D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE,&graphics_bitmap_target_[0]));\r
+  THROW_IF_ERR\r
+    (render_target_->CreateCompatibleRenderTarget\r
+        (&s,NULL,NULL,D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS_GDI_COMPATIBLE,&graphics_bitmap_target_[1]));\r
+\r
+  // GDI描画用のレンダーターゲット \r
+  THROW_IF_ERR\r
+    (text_bitmap_target_->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&text_dc_target_));\r
+  THROW_IF_ERR\r
+    (graphics_bitmap_target_[0]->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&graphics_dc_target_[0]));\r
+  THROW_IF_ERR\r
+    (graphics_bitmap_target_[1]->QueryInterface(__uuidof(ID2D1GdiInteropRenderTarget), (void**)&text_dc_target_[1]));\r
+\r
+  THROW_IF_ERR(\r
+    render_target_->CreateSolidColorBrush\r
+      (D2D1::ColorF(1.0f,1.0f,1.0f),&brush_mask_on_));\r
+\r
+  THROW_IF_ERR(\r
+    render_target_->CreateSolidColorBrush\r
+      (D2D1::ColorF(0.0f,0.0f,0.0f),&brush_mask_off_));\r
+\r
+  THROW_IF_ERR(\r
+    render_target_->CreateSolidColorBrush\r
+      (D2D1::ColorF(0.0f,0.0f,0.0f,0.0f),&brush_clear_));\r
+\r
+  THROW_IF_ERR(\r
+    render_target_->CreateSolidColorBrush\r
+      (D2D1::ColorF(0.0f,0.0f,0.0f,0.0f),&brush_text_clear_));\r
+\r
+  THROW_IF_ERR(\r
+    render_target_->CreateSolidColorBrush\r
+      (D2D1::ColorF(1.0f,1.0f,1.0f,1.0f),&brush_text_));\r
+\r
+};\r
+\r
+void CSTedScreenWin32::create_device_independent_resources()\r
+{\r
+  base_window::create_device_independent_resources();\r
+  // Text Formatの作成\r
+  THROW_IF_ERR(write_factory_->CreateTextFormat(\r
+    L"みかちゃん",                // Font family name.\r
+    NULL,                       // Font collection (NULL sets it to use the system font collection).\r
+    DWRITE_FONT_WEIGHT_NORMAL,\r
+    DWRITE_FONT_STYLE_NORMAL,\r
+    DWRITE_FONT_STRETCH_NORMAL,\r
+    fTextLineHeight,\r
+    L"ja-jp",\r
+    &text_fmt_\r
+    ));\r
+}
\ No newline at end of file
diff --git a/x68defines.h b/x68defines.h
new file mode 100644 (file)
index 0000000..8a7a947
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+  xwin.h
+
+  Widgets on X Window System
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#pragma once
+
+#ifndef _X68DEFINES_H_
+#define _X68DEFINES_H_
+
+/* defines */
+
+#define X68_TWidth   96            /* original screen size */
+#define X68_THeight  32            /* original screen size */
+
+#define X68_GWidth  768            /* original screen size */
+#define X68_GHeight 512            /* original screen size */
+
+#endif /* _X68DEFINES_H */
diff --git a/x68funcs.cpp b/x68funcs.cpp
new file mode 100644 (file)
index 0000000..0ed1506
--- /dev/null
@@ -0,0 +1,219 @@
+/*
+  x68funcs.c
+
+  functions for compatibility to X680x0
+
+  Made by Studio Breeze. 1998
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+
+#include "sted.h"
+#include "sted_screen.h"
+
+extern int iswindowopened;
+extern int iocs_graph_home; /* 0 or 1 */
+
+extern char fnc_func[10][32];
+extern char fnc_sfunc[10][32];
+extern char fnc_key[12][6];
+
+ CSTedScreenBase* GetDriver(void);
+
+/* global variables */
+
+
+const int x68_scancode[]={
+  0x35, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+  0x09, 0x0a, 0x28, 0x27, 0x31, 0x0c, 0x32, 0x33,
+  0x0b, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+  0x09, 0x0a, 0x28, 0x27, 0x31, 0x0c, 0x32, 0x33,
+  0x1b, 0x1e, 0x2e, 0x2c, 0x20, 0x13, 0x21, 0x22,
+  0x23, 0x18, 0x24, 0x25, 0x26, 0x30, 0x2f, 0x19,
+  0x1a, 0x11, 0x14, 0x1f, 0x15, 0x17, 0x2d, 0x12,
+  0x2b, 0x16, 0x2a, 0x1c, 0x0e, 0x29, 0x0d, 0x34,
+  0x1b, 0x1e, 0x2e, 0x2c, 0x20, 0x13, 0x21, 0x22,
+  0x23, 0x18, 0x24, 0x25, 0x26, 0x30, 0x2f, 0x19,
+  0x1a, 0x11, 0x14, 0x1f, 0x15, 0x17, 0x2d, 0x12,
+  0x2b, 0x16, 0x2a, 0x1c, 0x0e, 0x29, 0x0d
+};
+
+/*
+  void strmfe( char dest, *char *node , char *extention )
+
+   destination = node.ext
+ */
+
+void strmfe( char *dest, const char *node, const char *ext ) {
+
+  char *last,*temp;
+
+  temp = (char *)malloc( sizeof(char) * 1024 );
+
+  if ( ((last=const_cast<char*>(strrchr(node, (int)'.'))) != NULL) &&
+      (((int)*(last-1)!='.') && ((int)*(last+1)!='/'))) {
+    strncpy( temp, node, (size_t)(last-node+1));
+    strcat( temp, ext );
+  } else {
+    strcpy( temp, node );
+    strcat( temp, "." );
+    strcat( temp, ext );
+  }
+
+  strcpy( dest, temp );
+  free(temp);
+  return;
+}
+
+/*
+  double val( char *st )
+
+   converts numeric strings to floating pointted number
+ */
+
+double val( char *st ) {
+
+/* original "val" function allows following expressions:
+    &Hxx
+    &Oxx
+    &Boo
+ */
+
+  return(atof(st));
+}
+
+/*
+  child ( char *cl )
+
+   execute specified commands in child process
+ */
+
+int child( char *cl ) {
+
+  int ret;
+  int l;
+  char tmp[1024];
+
+  strcpy( tmp, cl );
+  l=strlen( tmp );
+  for ( ;l>=2;l-- ) {
+    if ( tmp[l]==':'  && isalpha(tmp[l-1]) && (tmp[l-2]==' ' || l==0) ) {
+      tmp[l--]=' ';
+      tmp[l--]=' ';
+    }
+  }
+
+  ret=system( tmp );
+  return ret;
+}
+
+/*
+ */
+
+void
+key_wait( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+  scr->KeyWait();
+}
+
+void
+key_midi_wait( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+  scr->MidiWait();
+}
+
+void
+key_mouse_wait( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+  scr->MouseWait();
+}
+
+void
+key_midi_player_wait( void )
+{
+  CSTedScreenBase* scr;
+
+  scr = GetDriver();
+  if (!scr) return;
+  scr->MidiPlayerWait();
+}
+
+int
+sted_sleep(long in_usec)
+{
+       CSTedScreenBase* scr;
+
+       scr = GetDriver();
+       if (!scr) return 0;
+       scr->USleep(in_usec);
+}
+
+void
+disable_update_screen(void)
+{
+       CSTedScreenBase* scr;
+
+       scr = GetDriver();
+       if (!scr) return;
+       scr->DisableUpdateWindow();
+}
+
+void
+update_screen(void)
+{
+       CSTedScreenBase* scr;
+
+       scr = GetDriver();
+       if (!scr) return;
+       scr->UpdateWindow();
+}
+
+
+/* system initialize */
+
+//static CSTedScreenBase* fScreenDriver = NULL;
+
+void
+STed_system_initialize( int *argc, char ***argv )
+{
+  rcd = NULL;
+  issted3 = 0;
+
+//  fScreenDriver = NULL;
+//
+//  fScreenDriver = CreateScreenDriver(16);
+  GetDriver()->KeyInit();
+  GetDriver()->SetX68ScanCode(x68_scancode);
+  return;
+}
+
+
diff --git a/x68funcs.h b/x68funcs.h
new file mode 100644 (file)
index 0000000..3590772
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+  x68funcs.h
+
+  prototype dec.s for functions compatibility to X680x0
+
+  Made by Studio Breeze. 1998, 2002
+
+
+  Permission is hereby granted, free of charge, to any person obtaining a copy
+  of this software and associated documentation files (the "Software"), to deal
+  in the Software without restriction, including without limitation the rights
+  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+  copies of the Software, and to permit persons to whom the Software is
+  furnished to do so, subject to the following conditions:
+
+  The above copyright notice and this permission notice shall be included in
+  all copies or substantial portions of the Software.
+
+  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
+  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+  THE SOFTWARE.
+ */
+#pragma once
+
+#ifndef _X68FUNCS_H_
+#define _X68FUNCS_H_
+
+/* variables */
+extern int iswindowopened;
+extern int iocs_graph_home; /* 0 or 1 */
+
+extern char fnc_func[10][32];
+extern char fnc_sfunc[10][32];
+extern char fnc_key[12][6];
+
+/* ROLL UP, ROLL DOWN, INS, DEL,
+   UP, LEFT, RIGHT, DOWN,
+   CLR, HELP, HOME, UNDO */
+
+/* misc functions */
+
+ void strmfe( char *, const char *, const char * );
+ void b_striS( char *, int, int );
+ void KNJCTRL( int, int );
+#ifndef HAVE_SNPRINTF
+#include "snprintf.h"
+#endif
+
+/* X-BASIC compatible functions */
+
+ double val( char * );
+ int child( char * );
+ int dskf( char );
+ int mspos( int *, int * );
+ char *dtasc( unsigned int );
+ char *tmasc( unsigned int );
+
+
+ void fill( int, int, int, int, unsigned int );
+ void box( int, int, int, int, unsigned int, unsigned int );
+ int  point( int, int );
+ void line( int, int, int, int, int, int );
+ void symbol( int, int, char *, char, char, char, int, char );
+
+/* original functions */
+
+ FILE *fopen2( char *, char * );
+ void STed_system_initialize( int *, char *** );
+
+ void update_screen(void);
+
+#endif /* _X68FUNCS_H_ */