summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libasap
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libasap')
-rw-r--r--lib/rbcodec/codecs/libasap/CREDITS58
-rw-r--r--lib/rbcodec/codecs/libasap/README148
-rw-r--r--lib/rbcodec/codecs/libasap/README.rockbox22
-rw-r--r--lib/rbcodec/codecs/libasap/SOURCES3
-rw-r--r--lib/rbcodec/codecs/libasap/acpu.c1291
-rw-r--r--lib/rbcodec/codecs/libasap/anylang.h218
-rw-r--r--lib/rbcodec/codecs/libasap/apokeysnd.c599
-rw-r--r--lib/rbcodec/codecs/libasap/asap.c2273
-rw-r--r--lib/rbcodec/codecs/libasap/asap.h328
-rw-r--r--lib/rbcodec/codecs/libasap/asap_internal.h115
-rw-r--r--lib/rbcodec/codecs/libasap/libasap.make18
-rw-r--r--lib/rbcodec/codecs/libasap/players.h1386
12 files changed, 6459 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libasap/CREDITS b/lib/rbcodec/codecs/libasap/CREDITS
new file mode 100644
index 0000000000..387cbb6266
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/CREDITS
@@ -0,0 +1,58 @@
1Authors
2-------
3
4Piotr Fusik {asapwww!<fox@scene.pl>}::
5Creator and main developer.
6
7Atari800 Emulator Developers {asapwww!(http://atari800.sourceforge.net)}::
86502 and POKEY emulation used in 0.x.y versions of ASAP.
9
10Zdenek Eisenhammer {asapwww!<pg@pinknet.cz>}::
11Testing.
12
13Henryk Karpowicz {asapwww!<henkar@poczta.tygrys.net>}::
14CMC routine modified for the CM3 format.
15
16Maciek Konecki {asapwww!<maciusk1@wp.pl>}::
17Porting to C#.
18
19Marek Konopka {asapwww!<konop11@poczta.onet.pl>}::
206502 routine for playing DLT.
21
22Marcin Lewandowski {asapwww!<jaskier@atari8.info>}::
236502 routines for playing CMC, MPT, TMC and TM2.
24
25Adrian Matoga {asapwww!<epi@atari8.info>}::
26COVOX information and test files. Testing.
27
28Perry McFarlane {asapwww!<perry_m@fastmail.fm>}::
29POKEY reverse-engineering.
30
31Kostas Nakos {asapwww!<knakos@gmail.com>}::
32Windows CE testing.
33
34Mariusz Rozwadowski {asapwww!<ramosc64@o2.pl>}::
35Suggested CMS, CM3 and DLT format support.
36
37Slawomir Sledz {asapwww!<slaves@scene.pl>}::
38Testing.
39
40David Spilka::
416502 routine for playing CMS.
42
43Radek Sterba {asapwww!<raster@infos.cz>}::
446502 routine for playing RMT.
45Testing.
46
47Lukasz Sychowicz {asapwww!<xray@scene.pl>}::
48Windows icons.
49Testing.
50
51Pawel Szewczyk {asapwww!<ripek@op.pl>}::
52Windows setup graphics.
53
54Michal Szpilowski {asapwww!<miker@atari.pl>}::
55Testing.
56
57Grzegorz Zyla {asapwww!<gsunr@poczta.onet.pl>}::
58XBMC plugin testing.
diff --git a/lib/rbcodec/codecs/libasap/README b/lib/rbcodec/codecs/libasap/README
new file mode 100644
index 0000000000..d4fbfe6297
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/README
@@ -0,0 +1,148 @@
1ASAP - Another Slight Atari Player
2==================================
3
4// This file is in AsciiDoc format. It is converted to README.html.
5:Compact-Option:
6
7ifdef::asapwww[]
8http://sourceforge.net/projects/asap/files/asap/[Download] |
9http://asap.git.sourceforge.net/git/gitweb.cgi?p=asap/asap;a=summary[Browse source code (Git)] |
10http://sourceforge.net/scm/?type=git&group_id=154391[Get latest source code (Git)] |
11http://sourceforge.net/projects/asap/[SourceForge project page]
12endif::asapwww[]
13
14ASAP is a player of http://en.wikipedia.org/wiki/Atari_8-bit_family[8-bit Atari]
15music for modern computers.
16It emulates the http://en.wikipedia.org/wiki/POKEY[POKEY sound chip]
17and the http://en.wikipedia.org/wiki/6502[6502 processor].
18The project was initially based on the routines from the
19http://atari800.sourceforge.net/[Atari800 emulator],
20but the current version has a completely new original emulation core.
21
22ASAP includes the following programs:
23
24- asapconv - portable command-line converter {asapwin=}
25- WASAP - tiny player for Windows {asapwin=}{asapwince=}
26- plugin for http://koti.welho.com/hylinen/apollo/[Apollo] {asapwin=}
27- plugin for http://audacious-media-player.org/[Audacious]
28- plugin for http://foobar2000.org/[foobar2000] {asapwin=}
29- plugin for http://hp.vector.co.jp/authors/VA032810/[GSPlayer] {asapwin=}{asapwince=}
30- plugin for http://moc.daper.net/[MOC]
31- plugin for http://www.winamp.com/[Winamp] {asapwin=}
32- plugin for http://www.microsoft.com/windows/windowsmedia/player/[Windows Media Player] {asapwin=}
33- plugin for http://xbmc.org/[XBMC] {asapwin=}
34- plugin for http://xmms.org/[XMMS]
35- plugin for http://www.un4seen.com/xmplay.html[XMPlay] {asapwin=}
36- add-on for http://www.un4seen.com/bass.html[BASS] (for http://www.aimp.ru/[AIMP] and http://www.un4seen.com/bass_showcase.php[other players]) {asapwin=}
37- POKEY sound emulation DLL for http://raster.infos.cz/atari/rmt/rmt.htm[Raster Music Tracker] {asapwin=}
38- Windows Explorer extension - shows metadata {asapwin=}
39- Java version of ASAP2WAV - command-line converter to WAV files {asapjava=}
40- Java applet - for web pages {asapjava=}{asapwww?(see link:applet.html[online demo])}
41- Java midlet - for mobile devices {asapjava=}
42- C# version of ASAP2WAV
43- JavaScript version of ASAP2WAV running in http://en.wikipedia.org/wiki/Windows_Script_Host[Windows Script Host], https://developer.mozilla.org/en/Rhino_Shell[Rhino Shell], http://code.google.com/p/v8/[V8 Shell], http://en.wikipedia.org/wiki/JScript_.NET[JScript .NET] and http://en.wikipedia.org/wiki/JaegerMonkey[JaegerMonkey] {asapjavascript=}
44- experimental JavaScript version of ASAP2WAV running in Firefox {asapjavascript=}
45- Flash player - for web pages {asapflash=}{asapwww?(see link:flash.html[online demo])}
46- asapplay - simple command-line player in C#
47- http://www.silverlight.net/[Silverlight] player - for web pages {asapwww?(see link:silverlight.html[online demo])}
48- AndroidASAP - for mobile devices
49
50{asapports}The summary of the differences between the above versions is in link:PORTS.xml[this table].
51
52There are other projects which use ASAP:
53
54- http://mmsap.sourceforge.net/[mmSAP 2] - standalone player for GNU/Linux with GTK+ user interface
55- http://www.rockbox.org/[Rockbox] - open source firmware for MP3 players
56
57
58Input file formats
59------------------
60
61ASAP supports the following file formats (determined by the filename extension):
62
63SAP (Slight Atari Player)::
64The format designed for playing 8-bit Atari music on modern computers.
65All other formats can be converted to SAP.
66http://asma.atari.org/[Atari SAP Music Archive (ASMA)]
67is a single big collection of SAP files.
68
69CMC (Chaos Music Composer)::
70Atari music editor from early 1990s.
71
72CM3 (CMC "3/4")::
73CMC with modified pattern length.
74
75CMR (CMC "Rzog")::
76CMC with modified bass sounds.
77
78CMS (Stereo Double CMC)::
79Stereo CMC.
80
81DMC (DoublePlay CMC)::
82CMC with 6502 routine executed at double rate of the original CMC.
83
84DLT (Delta Music Composer)::
85Atari music editor from 1990s.
86
87MPT (Music ProTracker)::
88Atari music editor from 1990s.
89
90MPD (MPT DoublePlay)::
91MPT with 6502 routine executed at double rate of the original MPT.
92
93RMT (http://raster.infos.cz/atari/rmt/rmt.htm[Raster Music Tracker])::
94Modern Atari music editor running on Windows.
95
96TMC, TM8 (http://jaskier.atari8.info/[Theta Music Composer] 1.x)::
97Atari music editor from late 1990s.
98The two file extensions are treated identically and played in stereo.
99TM8 means it's stereo (8-channel) music while TMC can be either mono or stereo.
100
101TM2 (http://jaskier.atari8.info/[Theta Music Composer] 2.x)::
102Modern Atari music editor.
103
104
105ifdef::asapsrc[]
106include::INSTALL[]
107endif::asapsrc[]
108
109ifdef::asapflash[]
110include::flash/USAGE[]
111endif::asapflash[]
112
113ifdef::asapjava[]
114include::java/USAGE[]
115endif::asapjava[]
116
117ifdef::asapjavascript[]
118include::javascript/USAGE[]
119endif::asapjavascript[]
120
121ifdef::asapwin[]
122include::win32/USAGE[]
123endif::asapwin[]
124
125ifdef::asapwince[]
126include::win32/wince/USAGE[]
127endif::asapwince[]
128
129include::NEWS[]
130
131include::CREDITS[]
132
133
134Feedback
135--------
136
137If you are interested in the ASAP project, please subscribe its
138https://lists.sourceforge.net/lists/listinfo/asap-users[mailing list].
139This list is for users and developers.
140Once you subscribe, you can post comments, ideas and questions about ASAP.
141They will be answered ASAP. ;-)
142
143Use http://sourceforge.net/tracker/?group_id=154391[tracker]
144to submit bug reports, feature requests and small code patches.
145
146ifdef::asapwww[]
147image::http://sflogo.sourceforge.net/sflogo.php?group_id=154391&amp;type=13["Get ASAP - Another Slight Atari Player at SourceForge.net. Fast, secure and Free Open Source software downloads",width=120,height=30,link="http://sourceforge.net/projects/asap/"]
148endif::asapwww[]
diff --git a/lib/rbcodec/codecs/libasap/README.rockbox b/lib/rbcodec/codecs/libasap/README.rockbox
new file mode 100644
index 0000000000..62184822d4
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/README.rockbox
@@ -0,0 +1,22 @@
1Library: asap-2.1.2
2Imported: 2010-02-02 by Dominik Wenger
3Updated: 2010-08-11 by Dominik Wenger
4
5This directory contains a local version of asap (http://asap.sourceforge.net/) for decoding Atari 8bit .sap
6audio streams.
7
8LICENSING INFORMATION
9
10Asap is available under the terms of the GPL v2 or later
11license, which is both an open source and free software license.
12The Licence is the same as the rest of Rockbox.
13
14
15IMPORT DETAILS
16
17The .[ch] files in apps/codec/libasap are copied from ASAP.
18
19players.h (contains binarys of players) was generated and copied
20into Rockbox.
21
22
diff --git a/lib/rbcodec/codecs/libasap/SOURCES b/lib/rbcodec/codecs/libasap/SOURCES
new file mode 100644
index 0000000000..0d1f1f46fa
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/SOURCES
@@ -0,0 +1,3 @@
1acpu.c
2asap.c
3apokeysnd.c
diff --git a/lib/rbcodec/codecs/libasap/acpu.c b/lib/rbcodec/codecs/libasap/acpu.c
new file mode 100644
index 0000000000..0fd5988b83
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/acpu.c
@@ -0,0 +1,1291 @@
1/*
2 * acpu.c - another 6502 CPU emulator
3 *
4 * Copyright (C) 2007-2010 Piotr Fusik
5 *
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
8 *
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/* How 6502 registers are stored in this emulator:
25 All variables are int, because modern processors (and Java bytecode)
26 tend to operate more effectively on these type than narrower ones.
27 pc is really an unsigned 16-bit integer.
28 a, x, y and s are unsigned 8-bit integers.
29 Flags are decomposed into three variables for improved performance.
30 c is either 0 or 1.
31 nz contains 6502 flags N and Z.
32 N is set if (nz >= 0x80). Z is set if ((nz & 0xff) == 0).
33 Usually nz is simply assigned the unsigned 8-bit operation result.
34 There are just a few operations (ADC in decimal mode, BIT, PLP and RTI)
35 where both N and Z may be set. In these cases, N is reflected by the 8th
36 (not 7th) bit of nz.
37 vdi contains rarely used flags V, D and I, as a combination
38 of V_FLAG, D_FLAG and I_FLAG. Other vdi bits are clear.
39
40 "Unofficial" opcodes are not documented as "legal" 6502 opcodes.
41 Their operation has been reverse-engineered on Atari 800XL and Atari 65XE.
42 Unofficial opcodes are identical to C64's 6510, except for 0x8b and 0xab.
43 The operation of "unstable" opcodes is partially uncertain.
44 Explanation is welcome.
45
46 Emulation of POKEY timer interrupts is included.
47
48 Two preprocessor symbols may be used to strip the size of this emulator.
49 Define ACPU_NO_DECIMAL to disable emulation of the BCD mode.
50 Define ACPU_NO_UNOFFICIAL to disable emulation of unofficial opcodes. */
51
52#include "asap_internal.h"
53
54CONST_ARRAY(int, opcode_cycles)
55/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
56 7, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 4, 4, 6, 6, /* 0x */
57 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, /* 1x */
58 6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 4, 4, 6, 6, /* 2x */
59 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, /* 3x */
60 6, 6, 2, 8, 3, 3, 5, 5, 3, 2, 2, 2, 3, 4, 6, 6, /* 4x */
61 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, /* 5x */
62 6, 6, 2, 8, 3, 3, 5, 5, 4, 2, 2, 2, 5, 4, 6, 6, /* 6x */
63 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, /* 7x */
64 2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, /* 8x */
65 2, 6, 2, 6, 4, 4, 4, 4, 2, 5, 2, 5, 5, 5, 5, 5, /* 9x */
66 2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 2, 4, 4, 4, 4, /* Ax */
67 2, 5, 2, 5, 4, 4, 4, 4, 2, 4, 2, 4, 4, 4, 4, 4, /* Bx */
68 2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, /* Cx */
69 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7, /* Dx */
70 2, 6, 2, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, /* Ex */
71 2, 5, 2, 8, 4, 4, 6, 6, 2, 4, 2, 7, 4, 4, 7, 7 /* Fx */
72END_CONST_ARRAY;
73
74#ifdef ACPU_NO_DECIMAL
75
76#define DO_ADC \
77 { \
78 /* binary mode */ \
79 V(int, tmp) = a + data + c; \
80 vdi = (vdi & (D_FLAG | I_FLAG)) + (((~(data ^ a) & (a ^ tmp)) >> 1) & V_FLAG); \
81 c = tmp >> 8; \
82 nz = a = tmp & 0xff; \
83 }
84
85#define DO_SBC \
86 { \
87 /* binary mode */ \
88 V(int, tmp) = a - data - 1 + c; \
89 vdi = (vdi & (D_FLAG | I_FLAG)) + ((((data ^ a) & (a ^ tmp)) >> 1) & V_FLAG); \
90 c = (tmp >= 0) ? 1 : 0; \
91 nz = a = tmp & 0xff; \
92 }
93
94#else /* ACPU_NO_DECIMAL */
95
96#define DO_ADC \
97 { \
98 V(int, tmp) = a + data + c; \
99 nz = tmp & 0xff; \
100 if ((vdi & D_FLAG) == 0) { \
101 /* binary mode */ \
102 vdi = (vdi & (D_FLAG | I_FLAG)) + (((~(data ^ a) & (a ^ tmp)) >> 1) & V_FLAG); \
103 c = tmp >> 8; \
104 a = nz; \
105 } \
106 else { \
107 /* decimal mode */ \
108 V(int, al) = (a & 0x0f) + (data & 0x0f) + c; \
109 if (al >= 10) \
110 tmp += (al < 26) ? 6 : -10; \
111 nz = ((tmp & 0x80) << 1) + (nz != 0 ? 1 : 0); \
112 vdi = (vdi & (D_FLAG | I_FLAG)) + (((~(data ^ a) & (a ^ tmp)) >> 1) & V_FLAG); \
113 if (tmp >= 0xa0) { \
114 c = 1; \
115 a = (tmp + 0x60) & 0xff; \
116 } \
117 else { \
118 c = 0; \
119 a = tmp; \
120 } \
121 } \
122 }
123
124#define DO_SBC \
125 {\
126 V(int, tmp) = a - data - 1 + c; \
127 V(int, al) = (a & 0x0f) - (data & 0x0f) - 1 + c; \
128 vdi = (vdi & (D_FLAG | I_FLAG)) + ((((data ^ a) & (a ^ tmp)) >> 1) & V_FLAG); \
129 c = (tmp >= 0) ? 1 : 0; \
130 nz = a = tmp & 0xff; \
131 if ((vdi & D_FLAG) != 0) { \
132 /* decimal mode */ \
133 if (al < 0) \
134 a += (al < -10) ? 10 : -6; \
135 if (c == 0) \
136 a = (a - 0x60) & 0xff; \
137 } \
138 }
139
140#endif /* ACPU_NO_DECIMAL */
141
142#define zGetByte(addr) dGetByte((addr) & 0xff)
143
144#define PEEK dGetByte(pc)
145#define FETCH dGetByte(pc++)
146
147#define ABSOLUTE addr = FETCH; addr += FETCH << 8
148#define ABSOLUTE_X addr = FETCH; addr = (addr + (FETCH << 8) + x) & 0xffff
149#define ABSOLUTE_Y addr = FETCH; addr = (addr + (FETCH << 8) + y) & 0xffff
150#define ZPAGE addr = FETCH
151#define ZPAGE_X addr = (FETCH + x) & 0xff
152#define ZPAGE_Y addr = (FETCH + y) & 0xff
153#define INDIRECT_X addr = (FETCH + x) & 0xff; addr = dGetByte(addr) + (zGetByte(addr + 1) << 8)
154#define INDIRECT_Y addr = FETCH; addr = (dGetByte(addr) + (zGetByte(addr + 1) << 8) + y) & 0xffff
155#define NCYCLES_X if ((addr & 0xff) < x) ast _ cycle++
156#define NCYCLES_Y if ((addr & 0xff) < y) ast _ cycle++
157
158#define PL(dest) s = (s + 1) & 0xff; dest = dGetByte(0x0100 + s)
159#define PLP PL(vdi); nz = ((vdi & 0x80) << 1) + (~vdi & Z_FLAG); c = vdi & 1; vdi &= V_FLAG | D_FLAG | I_FLAG
160#define PH(data) dPutByte(0x0100 + s, data); s = (s - 1) & 0xff
161#define PHW(data) PH((data) >> 8); PH(TO_BYTE(data))
162#define PHP(bflag) PH(((nz | (nz >> 1)) & 0x80) + vdi + ((nz & 0xff) == 0 ? Z_FLAG : 0) + c + bflag)
163#define PHPB0 PHP(0x20) /* push flags with B flag clear (NMI, IRQ) */
164#define PHPB1 PHP(0x30) /* push flags with B flag set (PHP, BRK) */
165#define PHPC PHW(pc)
166
167#define LDA nz = a = GetByte(addr)
168#define LDA_ZP nz = a = dGetByte(addr)
169#define LDX nz = x = GetByte(addr)
170#define LDX_ZP nz = x = dGetByte(addr)
171#define LDY nz = y = GetByte(addr)
172#define LDY_ZP nz = y = dGetByte(addr)
173#define LAX nz = x = a = GetByte(addr)
174#define LAX_ZP nz = x = a = dGetByte(addr)
175#define STA PutByte(addr, a)
176#define STA_ZP dPutByte(addr, a)
177#define STX PutByte(addr, x)
178#define STX_ZP dPutByte(addr, x)
179#define STY PutByte(addr, y)
180#define STY_ZP dPutByte(addr, y)
181#define SAX data = a & x; PutByte(addr, data)
182#define SAX_ZP data = a & x; dPutByte(addr, data)
183#define CMP nz = GetByte(addr); c = (a >= nz) ? 1 : 0; nz = (a - nz) & 0xff
184#define CMP_ZP nz = dGetByte(addr); c = (a >= nz) ? 1 : 0; nz = (a - nz) & 0xff
185#define CPX nz = GetByte(addr); c = (x >= nz) ? 1 : 0; nz = (x - nz) & 0xff
186#define CPX_ZP nz = dGetByte(addr); c = (x >= nz) ? 1 : 0; nz = (x - nz) & 0xff
187#define CPY nz = GetByte(addr); c = (y >= nz) ? 1 : 0; nz = (y - nz) & 0xff
188#define CPY_ZP nz = dGetByte(addr); c = (y >= nz) ? 1 : 0; nz = (y - nz) & 0xff
189#define AND nz = a &= GetByte(addr)
190#define AND_ZP nz = a &= dGetByte(addr)
191#define ORA nz = a |= GetByte(addr)
192#define ORA_ZP nz = a |= dGetByte(addr)
193#define EOR nz = a ^= GetByte(addr)
194#define EOR_ZP nz = a ^= dGetByte(addr)
195#define ADC data = GetByte(addr); DO_ADC
196#define ADC_ZP data = dGetByte(addr); DO_ADC
197#define SBC data = GetByte(addr); DO_SBC
198#define SBC_ZP data = dGetByte(addr); DO_SBC
199
200#define ASL RMW_GetByte(nz, addr); c = nz >> 7; nz = (nz << 1) & 0xff; PutByte(addr, nz)
201#define ASL_ZP nz = dGetByte(addr); c = nz >> 7; nz = (nz << 1) & 0xff; dPutByte(addr, nz)
202#define ROL RMW_GetByte(nz, addr); nz = (nz << 1) + c; c = nz >> 8; nz &= 0xff; PutByte(addr, nz)
203#define ROL_ZP nz = dGetByte(addr); nz = (nz << 1) + c; c = nz >> 8; nz &= 0xff; dPutByte(addr, nz)
204#define LSR RMW_GetByte(nz, addr); c = nz & 1; nz >>= 1; PutByte(addr, nz)
205#define LSR_ZP nz = dGetByte(addr); c = nz & 1; nz >>= 1; dPutByte(addr, nz)
206#define ROR RMW_GetByte(nz, addr); nz += c << 8; c = nz & 1; nz >>= 1; PutByte(addr, nz)
207#define ROR_ZP nz = dGetByte(addr) + (c << 8); c = nz & 1; nz >>= 1; dPutByte(addr, nz)
208#define DEC RMW_GetByte(nz, addr); nz = (nz - 1) & 0xff; PutByte(addr, nz)
209#define DEC_ZP nz = dGetByte(addr); nz = (nz - 1) & 0xff; dPutByte(addr, nz)
210#define INC RMW_GetByte(nz, addr); nz = (nz + 1) & 0xff; PutByte(addr, nz)
211#define INC_ZP nz = dGetByte(addr); nz = (nz + 1) & 0xff; dPutByte(addr, nz)
212
213#define ASO ASL; nz = a |= nz
214#define ASO_ZP ASL_ZP; nz = a |= nz
215#define RLA ROL; nz = a &= nz
216#define RLA_ZP ROL_ZP; nz = a &= nz
217#define LSE LSR; nz = a ^= nz
218#define LSE_ZP LSR_ZP; nz = a ^= nz
219#define RRA ROR; data = nz; DO_ADC
220#define RRA_ZP ROR_ZP; data = nz; DO_ADC
221#define DCM DEC; c = (a >= nz) ? 1 : 0; nz = (a - nz) & 0xff
222#define DCM_ZP DEC_ZP; c = (a >= nz) ? 1 : 0; nz = (a - nz) & 0xff
223#define INS INC; data = nz; DO_SBC
224#define INS_ZP INC_ZP; data = nz; DO_SBC
225
226#define BRANCH(cond) \
227 if (cond) { \
228 addr = SBYTE(PEEK); \
229 pc++; \
230 addr += pc; \
231 if ((addr ^ pc) >> 8 != 0) \
232 ast _ cycle++; \
233 ast _ cycle++; \
234 pc = addr; \
235 break; \
236 } \
237 pc++; \
238 break
239
240#define CHECK_IRQ \
241 if ((vdi & I_FLAG) == 0 && ast _ irqst != 0xff) { \
242 PHPC; \
243 PHPB0; \
244 vdi |= I_FLAG; \
245 pc = dGetWord(0xfffe); \
246 ast _ cycle += 7; \
247 }
248
249/* Runs 6502 emulation for the specified number of Atari scanlines.
250 Each scanline is 114 cycles of which 9 is taken by ANTIC for memory refresh. */
251FUNC(void, Cpu_RunScanlines, (P(ASAP_State PTR, ast), P(int, scanlines)))
252{
253 /* copy registers from ASAP_State to local variables for improved performance */
254 V(int, pc);
255 V(int, nz);
256 V(int, a);
257 V(int, x);
258 V(int, y);
259 V(int, c);
260 V(int, s);
261 V(int, vdi);
262 V(int, next_event_cycle);
263 V(int, cycle_limit);
264 pc = ast _ cpu_pc;
265 nz = ast _ cpu_nz;
266 a = ast _ cpu_a;
267 x = ast _ cpu_x;
268 y = ast _ cpu_y;
269 c = ast _ cpu_c;
270 s = ast _ cpu_s;
271 vdi = ast _ cpu_vdi;
272 ast _ next_scanline_cycle = 114;
273 next_event_cycle = 114;
274 cycle_limit = 114 * scanlines;
275 if (next_event_cycle > ast _ timer1_cycle)
276 next_event_cycle = ast _ timer1_cycle;
277 if (next_event_cycle > ast _ timer2_cycle)
278 next_event_cycle = ast _ timer2_cycle;
279 if (next_event_cycle > ast _ timer4_cycle)
280 next_event_cycle = ast _ timer4_cycle;
281 ast _ nearest_event_cycle = next_event_cycle;
282 for (;;) {
283 V(int, cycle);
284 V(int, addr);
285 V(int, data);
286 cycle = ast _ cycle;
287 if (cycle >= ast _ nearest_event_cycle) {
288 if (cycle >= ast _ next_scanline_cycle) {
289 if (++ast _ scanline_number == (ast _ module_info->ntsc ? 262 : 312))
290 ast _ scanline_number = 0;
291 ast _ cycle = cycle += 9;
292 ast _ next_scanline_cycle += 114;
293 if (--scanlines <= 0)
294 break;
295 }
296 next_event_cycle = ast _ next_scanline_cycle;
297#define CHECK_TIMER_IRQ(ch) \
298 if (cycle >= ast _ timer##ch##_cycle) { \
299 ast _ irqst &= ~ch; \
300 ast _ timer##ch##_cycle = NEVER; \
301 } \
302 else if (next_event_cycle > ast _ timer##ch##_cycle) \
303 next_event_cycle = ast _ timer##ch##_cycle;
304 CHECK_TIMER_IRQ(1);
305 CHECK_TIMER_IRQ(2);
306 CHECK_TIMER_IRQ(4);
307 ast _ nearest_event_cycle = next_event_cycle;
308 CHECK_IRQ;
309 }
310#ifdef ASAPSCAN
311 if (cpu_trace != 0)
312 trace_cpu(ast, pc, a, x, y, s, nz, vdi, c);
313#endif
314 data = FETCH;
315 ast _ cycle += opcode_cycles[data];
316 switch (data) {
317 case 0x00: /* BRK */
318 pc++;
319 PHPC;
320 PHPB1;
321 vdi |= I_FLAG;
322 pc = dGetWord(0xfffe);
323 break;
324 case 0x01: /* ORA (ab,x) */
325 INDIRECT_X;
326 ORA;
327 break;
328 case 0x02: /* CIM [unofficial] */
329 case 0x12:
330 case 0x22:
331 case 0x32:
332 case 0x42:
333 case 0x52:
334 case 0x62:
335 case 0x72:
336 case 0x92:
337 case 0xb2:
338 case 0xd2:
339 case 0xf2:
340 ast _ scanline_number = (ast _ scanline_number + scanlines - 1) % (ast _ module_info->ntsc ? 262 : 312);
341 scanlines = 1;
342 ast _ cycle = cycle_limit;
343 break;
344#ifndef ACPU_NO_UNOFFICIAL
345 case 0x03: /* ASO (ab,x) [unofficial] */
346 INDIRECT_X;
347 ASO;
348 break;
349 case 0x04: /* NOP ab [unofficial] */
350 case 0x44:
351 case 0x64:
352 case 0x14: /* NOP ab,x [unofficial] */
353 case 0x34:
354 case 0x54:
355 case 0x74:
356 case 0xd4:
357 case 0xf4:
358 case 0x80: /* NOP #ab [unofficial] */
359 case 0x82:
360 case 0x89:
361 case 0xc2:
362 case 0xe2:
363 pc++;
364 break;
365 case 0x07: /* ASO ab [unofficial] */
366 ZPAGE;
367 ASO_ZP;
368 break;
369 case 0x0b: /* ANC #ab [unofficial] */
370 case 0x2b:
371 nz = a &= FETCH;
372 c = nz >> 7;
373 break;
374 case 0x0c: /* NOP abcd [unofficial] */
375 pc += 2;
376 break;
377 case 0x0f: /* ASO abcd [unofficial] */
378 ABSOLUTE;
379 ASO;
380 break;
381 case 0x13: /* ASO (ab),y [unofficial] */
382 INDIRECT_Y;
383 ASO;
384 break;
385 case 0x17: /* ASO ab,x [unofficial] */
386 ZPAGE_X;
387 ASO_ZP;
388 break;
389 case 0x1b: /* ASO abcd,y [unofficial] */
390 ABSOLUTE_Y;
391 ASO;
392 break;
393 case 0x1c: /* NOP abcd,x [unofficial] */
394 case 0x3c:
395 case 0x5c:
396 case 0x7c:
397 case 0xdc:
398 case 0xfc:
399 if (FETCH + x >= 0x100)
400 ast _ cycle++;
401 pc++;
402 break;
403 case 0x1f: /* ASO abcd,x [unofficial] */
404 ABSOLUTE_X;
405 ASO;
406 break;
407 case 0x23: /* RLA (ab,x) [unofficial] */
408 INDIRECT_X;
409 RLA;
410 break;
411 case 0x27: /* RLA ab [unofficial] */
412 ZPAGE;
413 RLA_ZP;
414 break;
415 case 0x2f: /* RLA abcd [unofficial] */
416 ABSOLUTE;
417 RLA;
418 break;
419 case 0x33: /* RLA (ab),y [unofficial] */
420 INDIRECT_Y;
421 RLA;
422 break;
423 case 0x37: /* RLA ab,x [unofficial] */
424 ZPAGE_X;
425 RLA_ZP;
426 break;
427 case 0x3b: /* RLA abcd,y [unofficial] */
428 ABSOLUTE_Y;
429 RLA;
430 break;
431 case 0x3f: /* RLA abcd,x [unofficial] */
432 ABSOLUTE_X;
433 RLA;
434 break;
435 case 0x43: /* LSE (ab,x) [unofficial] */
436 INDIRECT_X;
437 LSE;
438 break;
439 case 0x47: /* LSE ab [unofficial] */
440 ZPAGE;
441 LSE_ZP;
442 break;
443 case 0x4b: /* ALR #ab [unofficial] */
444 a &= FETCH;
445 c = a & 1;
446 nz = a >>= 1;
447 break;
448 case 0x4f: /* LSE abcd [unofficial] */
449 ABSOLUTE;
450 LSE;
451 break;
452 case 0x53: /* LSE (ab),y [unofficial] */
453 INDIRECT_Y;
454 LSE;
455 break;
456 case 0x57: /* LSE ab,x [unofficial] */
457 ZPAGE_X;
458 LSE_ZP;
459 break;
460 case 0x5b: /* LSE abcd,y [unofficial] */
461 ABSOLUTE_Y;
462 LSE;
463 break;
464 case 0x5f: /* LSE abcd,x [unofficial] */
465 ABSOLUTE_X;
466 LSE;
467 break;
468 case 0x63: /* RRA (ab,x) [unofficial] */
469 INDIRECT_X;
470 RRA;
471 break;
472 case 0x67: /* RRA ab [unofficial] */
473 ZPAGE;
474 RRA_ZP;
475 break;
476 case 0x6b: /* ARR #ab [unofficial] */
477 data = a & FETCH;
478 nz = a = (data >> 1) + (c << 7);
479 vdi = (vdi & (D_FLAG | I_FLAG)) + ((a ^ data) & V_FLAG);
480#ifdef ACPU_NO_DECIMAL
481 c = data >> 7;
482#else
483 if ((vdi & D_FLAG) == 0)
484 c = data >> 7;
485 else {
486 if ((data & 0xf) >= 5)
487 a = (a & 0xf0) + ((a + 6) & 0xf);
488 if (data >= 0x50) {
489 a = (a + 0x60) & 0xff;
490 c = 1;
491 }
492 else
493 c = 0;
494 }
495#endif
496 break;
497 case 0x6f: /* RRA abcd [unofficial] */
498 ABSOLUTE;
499 RRA;
500 break;
501 case 0x73: /* RRA (ab),y [unofficial] */
502 INDIRECT_Y;
503 RRA;
504 break;
505 case 0x77: /* RRA ab,x [unofficial] */
506 ZPAGE_X;
507 RRA_ZP;
508 break;
509 case 0x7b: /* RRA abcd,y [unofficial] */
510 ABSOLUTE_Y;
511 RRA;
512 break;
513 case 0x7f: /* RRA abcd,x [unofficial] */
514 ABSOLUTE_X;
515 RRA;
516 break;
517 case 0x83: /* SAX (ab,x) [unofficial] */
518 INDIRECT_X;
519 SAX;
520 break;
521 case 0x87: /* SAX ab [unofficial] */
522 ZPAGE;
523 SAX_ZP;
524 break;
525 case 0x8b: /* ANE #ab [unofficial] */
526 data = FETCH;
527 a &= x;
528 nz = a & data;
529 a &= data | 0xef;
530 break;
531 case 0x8f: /* SAX abcd [unofficial] */
532 ABSOLUTE;
533 SAX;
534 break;
535 case 0x93: /* SHA (ab),y [unofficial, unstable] */
536 ZPAGE;
537 data = zGetByte(addr + 1);
538 addr = (dGetByte(addr) + (data << 8) + y) & 0xffff;
539 data = a & x & (data + 1);
540 PutByte(addr, data);
541 break;
542 case 0x97: /* SAX ab,y [unofficial] */
543 ZPAGE_Y;
544 SAX_ZP;
545 break;
546 case 0x9b: /* SHS abcd,y [unofficial, unstable] */
547 /* S seems to be stable, only memory values vary */
548 addr = FETCH;
549 data = FETCH;
550 addr = (addr + (data << 8) + y) & 0xffff;
551 s = a & x;
552 data = s & (data + 1);
553 PutByte(addr, data);
554 break;
555 case 0x9c: /* SHY abcd,x [unofficial] */
556 addr = FETCH;
557 data = FETCH;
558 addr = (addr + (data << 8) + x) & 0xffff;
559 data = y & (data + 1);
560 PutByte(addr, data);
561 break;
562 case 0x9e: /* SHX abcd,y [unofficial] */
563 addr = FETCH;
564 data = FETCH;
565 addr = (addr + (data << 8) + y) & 0xffff;
566 data = x & (data + 1);
567 PutByte(addr, data);
568 break;
569 case 0x9f: /* SHA abcd,y [unofficial, unstable] */
570 addr = FETCH;
571 data = FETCH;
572 addr = (addr + (data << 8) + y) & 0xffff;
573 data = a & x & (data + 1);
574 PutByte(addr, data);
575 break;
576 case 0xa3: /* LAX (ab,x) [unofficial] */
577 INDIRECT_X;
578 LAX;
579 break;
580 case 0xa7: /* LAX ab [unofficial] */
581 ZPAGE;
582 LAX_ZP;
583 break;
584 case 0xab: /* ANX #ab [unofficial] */
585 nz = x = a &= FETCH;
586 break;
587 case 0xaf: /* LAX abcd [unofficial] */
588 ABSOLUTE;
589 LAX;
590 break;
591 case 0xb3: /* LAX (ab),y [unofficial] */
592 INDIRECT_Y;
593 NCYCLES_Y;
594 LAX;
595 break;
596 case 0xb7: /* LAX ab,y [unofficial] */
597 ZPAGE_Y;
598 LAX_ZP;
599 break;
600 case 0xbb: /* LAS abcd,y [unofficial] */
601 ABSOLUTE_Y;
602 NCYCLES_Y;
603 nz = x = a = s &= GetByte(addr);
604 break;
605 case 0xbf: /* LAX abcd,y [unofficial] */
606 ABSOLUTE_Y;
607 NCYCLES_Y;
608 LAX;
609 break;
610 case 0xc3: /* DCM (ab,x) [unofficial] */
611 INDIRECT_X;
612 DCM;
613 break;
614 case 0xc7: /* DCM ab [unofficial] */
615 ZPAGE;
616 DCM_ZP;
617 break;
618 case 0xcb: /* SBX #ab [unofficial] */
619 nz = FETCH;
620 x &= a;
621 c = (x >= nz) ? 1 : 0;
622 nz = x = (x - nz) & 0xff;
623 break;
624 case 0xcf: /* DCM abcd [unofficial] */
625 ABSOLUTE;
626 DCM;
627 break;
628 case 0xd3: /* DCM (ab),y [unofficial] */
629 INDIRECT_Y;
630 DCM;
631 break;
632 case 0xd7: /* DCM ab,x [unofficial] */
633 ZPAGE_X;
634 DCM_ZP;
635 break;
636 case 0xdb: /* DCM abcd,y [unofficial] */
637 ABSOLUTE_Y;
638 DCM;
639 break;
640 case 0xdf: /* DCM abcd,x [unofficial] */
641 ABSOLUTE_X;
642 DCM;
643 break;
644 case 0xe3: /* INS (ab,x) [unofficial] */
645 INDIRECT_X;
646 INS;
647 break;
648 case 0xe7: /* INS ab [unofficial] */
649 ZPAGE;
650 INS_ZP;
651 break;
652 case 0xef: /* INS abcd [unofficial] */
653 ABSOLUTE;
654 INS;
655 break;
656 case 0xf3: /* INS (ab),y [unofficial] */
657 INDIRECT_Y;
658 INS;
659 break;
660 case 0xf7: /* INS ab,x [unofficial] */
661 ZPAGE_X;
662 INS_ZP;
663 break;
664 case 0xfb: /* INS abcd,y [unofficial] */
665 ABSOLUTE_Y;
666 INS;
667 break;
668 case 0xff: /* INS abcd,x [unofficial] */
669 ABSOLUTE_X;
670 INS;
671 break;
672#endif /* ACPU_NO_UNOFFICIAL */
673 case 0x05: /* ORA ab */
674 ZPAGE;
675 ORA_ZP;
676 break;
677 case 0x06: /* ASL ab */
678 ZPAGE;
679 ASL_ZP;
680 break;
681 case 0x08: /* PHP */
682 PHPB1;
683 break;
684 case 0x09: /* ORA #ab */
685 nz = a |= FETCH;
686 break;
687 case 0x0a: /* ASL */
688 c = a >> 7;
689 nz = a = (a << 1) & 0xff;
690 break;
691 case 0x0d: /* ORA abcd */
692 ABSOLUTE;
693 ORA;
694 break;
695 case 0x0e: /* ASL abcd */
696 ABSOLUTE;
697 ASL;
698 break;
699 case 0x10: /* BPL */
700 BRANCH(nz < 0x80);
701 case 0x11: /* ORA (ab),y */
702 INDIRECT_Y;
703 NCYCLES_Y;
704 ORA;
705 break;
706 case 0x15: /* ORA ab,x */
707 ZPAGE_X;
708 ORA_ZP;
709 break;
710 case 0x16: /* ASL ab,x */
711 ZPAGE_X;
712 ASL_ZP;
713 break;
714 case 0x18: /* CLC */
715 c = 0;
716 break;
717 case 0x19: /* ORA abcd,y */
718 ABSOLUTE_Y;
719 NCYCLES_Y;
720 ORA;
721 break;
722 case 0x1d: /* ORA abcd,x */
723 ABSOLUTE_X;
724 NCYCLES_X;
725 ORA;
726 break;
727 case 0x1e: /* ASL abcd,x */
728 ABSOLUTE_X;
729 ASL;
730 break;
731 case 0x20: /* JSR abcd */
732 addr = FETCH;
733 PHPC;
734 pc = addr + (PEEK << 8);
735 break;
736 case 0x21: /* AND (ab,x) */
737 INDIRECT_X;
738 AND;
739 break;
740 case 0x24: /* BIT ab */
741 ZPAGE;
742 nz = dGetByte(addr);
743 vdi = (vdi & (D_FLAG | I_FLAG)) + (nz & V_FLAG);
744 nz = ((nz & 0x80) << 1) + (nz & a);
745 break;
746 case 0x25: /* AND ab */
747 ZPAGE;
748 AND_ZP;
749 break;
750 case 0x26: /* ROL ab */
751 ZPAGE;
752 ROL_ZP;
753 break;
754 case 0x28: /* PLP */
755 PLP;
756 CHECK_IRQ;
757 break;
758 case 0x29: /* AND #ab */
759 nz = a &= FETCH;
760 break;
761 case 0x2a: /* ROL */
762 a = (a << 1) + c;
763 c = a >> 8;
764 nz = a &= 0xff;
765 break;
766 case 0x2c: /* BIT abcd */
767 ABSOLUTE;
768 nz = GetByte(addr);
769 vdi = (vdi & (D_FLAG | I_FLAG)) + (nz & V_FLAG);
770 nz = ((nz & 0x80) << 1) + (nz & a);
771 break;
772 case 0x2d: /* AND abcd */
773 ABSOLUTE;
774 AND;
775 break;
776 case 0x2e: /* ROL abcd */
777 ABSOLUTE;
778 ROL;
779 break;
780 case 0x30: /* BMI */
781 BRANCH(nz >= 0x80);
782 case 0x31: /* AND (ab),y */
783 INDIRECT_Y;
784 NCYCLES_Y;
785 AND;
786 break;
787 case 0x35: /* AND ab,x */
788 ZPAGE_X;
789 AND_ZP;
790 break;
791 case 0x36: /* ROL ab,x */
792 ZPAGE_X;
793 ROL_ZP;
794 break;
795 case 0x38: /* SEC */
796 c = 1;
797 break;
798 case 0x39: /* AND abcd,y */
799 ABSOLUTE_Y;
800 NCYCLES_Y;
801 AND;
802 break;
803 case 0x3d: /* AND abcd,x */
804 ABSOLUTE_X;
805 NCYCLES_X;
806 AND;
807 break;
808 case 0x3e: /* ROL abcd,x */
809 ABSOLUTE_X;
810 ROL;
811 break;
812 case 0x40: /* RTI */
813 PLP;
814 PL(pc);
815 PL(addr);
816 pc += addr << 8;
817 CHECK_IRQ;
818 break;
819 case 0x41: /* EOR (ab,x) */
820 INDIRECT_X;
821 EOR;
822 break;
823 case 0x45: /* EOR ab */
824 ZPAGE;
825 EOR_ZP;
826 break;
827 case 0x46: /* LSR ab */
828 ZPAGE;
829 LSR_ZP;
830 break;
831 case 0x48: /* PHA */
832 PH(a);
833 break;
834 case 0x49: /* EOR #ab */
835 nz = a ^= FETCH;
836 break;
837 case 0x4a: /* LSR */
838 c = a & 1;
839 nz = a >>= 1;
840 break;
841 case 0x4c: /* JMP abcd */
842 addr = FETCH;
843 pc = addr + (PEEK << 8);
844 break;
845 case 0x4d: /* EOR abcd */
846 ABSOLUTE;
847 EOR;
848 break;
849 case 0x4e: /* LSR abcd */
850 ABSOLUTE;
851 LSR;
852 break;
853 case 0x50: /* BVC */
854 BRANCH((vdi & V_FLAG) == 0);
855 case 0x51: /* EOR (ab),y */
856 INDIRECT_Y;
857 NCYCLES_Y;
858 EOR;
859 break;
860 case 0x55: /* EOR ab,x */
861 ZPAGE_X;
862 EOR_ZP;
863 break;
864 case 0x56: /* LSR ab,x */
865 ZPAGE_X;
866 LSR_ZP;
867 break;
868 case 0x58: /* CLI */
869 vdi &= V_FLAG | D_FLAG;
870 CHECK_IRQ;
871 break;
872 case 0x59: /* EOR abcd,y */
873 ABSOLUTE_Y;
874 NCYCLES_Y;
875 EOR;
876 break;
877 case 0x5d: /* EOR abcd,x */
878 ABSOLUTE_X;
879 NCYCLES_X;
880 EOR;
881 break;
882 case 0x5e: /* LSR abcd,x */
883 ABSOLUTE_X;
884 LSR;
885 break;
886 case 0x60: /* RTS */
887 PL(pc);
888 PL(addr);
889 pc += (addr << 8) + 1;
890 break;
891 case 0x61: /* ADC (ab,x) */
892 INDIRECT_X;
893 ADC;
894 break;
895 case 0x65: /* ADC ab */
896 ZPAGE;
897 ADC_ZP;
898 break;
899 case 0x66: /* ROR ab */
900 ZPAGE;
901 ROR_ZP;
902 break;
903 case 0x68: /* PLA */
904 PL(a);
905 nz = a;
906 break;
907 case 0x69: /* ADC #ab */
908 data = FETCH;
909 DO_ADC;
910 break;
911 case 0x6a: /* ROR */
912 nz = (c << 7) + (a >> 1);
913 c = a & 1;
914 a = nz;
915 break;
916 case 0x6c: /* JMP (abcd) */
917 ABSOLUTE;
918 if ((addr & 0xff) == 0xff)
919 pc = (dGetByte(addr - 0xff) << 8) + dGetByte(addr);
920 else
921 pc = dGetWord(addr);
922 break;
923 case 0x6d: /* ADC abcd */
924 ABSOLUTE;
925 ADC;
926 break;
927 case 0x6e: /* ROR abcd */
928 ABSOLUTE;
929 ROR;
930 break;
931 case 0x70: /* BVS */
932 BRANCH((vdi & V_FLAG) != 0);
933 case 0x71: /* ADC (ab),y */
934 INDIRECT_Y;
935 NCYCLES_Y;
936 ADC;
937 break;
938 case 0x75: /* ADC ab,x */
939 ZPAGE_X;
940 ADC_ZP;
941 break;
942 case 0x76: /* ROR ab,x */
943 ZPAGE_X;
944 ROR_ZP;
945 break;
946 case 0x78: /* SEI */
947 vdi |= I_FLAG;
948 break;
949 case 0x79: /* ADC abcd,y */
950 ABSOLUTE_Y;
951 NCYCLES_Y;
952 ADC;
953 break;
954 case 0x7d: /* ADC abcd,x */
955 ABSOLUTE_X;
956 NCYCLES_X;
957 ADC;
958 break;
959 case 0x7e: /* ROR abcd,x */
960 ABSOLUTE_X;
961 ROR;
962 break;
963 case 0x81: /* STA (ab,x) */
964 INDIRECT_X;
965 STA;
966 break;
967 case 0x84: /* STY ab */
968 ZPAGE;
969 STY_ZP;
970 break;
971 case 0x85: /* STA ab */
972 ZPAGE;
973 STA_ZP;
974 break;
975 case 0x86: /* STX ab */
976 ZPAGE;
977 STX_ZP;
978 break;
979 case 0x88: /* DEY */
980 nz = y = (y - 1) & 0xff;
981 break;
982 case 0x8a: /* TXA */
983 nz = a = x;
984 break;
985 case 0x8c: /* STY abcd */
986 ABSOLUTE;
987 STY;
988 break;
989 case 0x8d: /* STA abcd */
990 ABSOLUTE;
991 STA;
992 break;
993 case 0x8e: /* STX abcd */
994 ABSOLUTE;
995 STX;
996 break;
997 case 0x90: /* BCC */
998 BRANCH(c == 0);
999 case 0x91: /* STA (ab),y */
1000 INDIRECT_Y;
1001 STA;
1002 break;
1003 case 0x94: /* STY ab,x */
1004 ZPAGE_X;
1005 STY_ZP;
1006 break;
1007 case 0x95: /* STA ab,x */
1008 ZPAGE_X;
1009 STA_ZP;
1010 break;
1011 case 0x96: /* STX ab,y */
1012 ZPAGE_Y;
1013 STX_ZP;
1014 break;
1015 case 0x98: /* TYA */
1016 nz = a = y;
1017 break;
1018 case 0x99: /* STA abcd,y */
1019 ABSOLUTE_Y;
1020 STA;
1021 break;
1022 case 0x9a: /* TXS */
1023 s = x;
1024 break;
1025 case 0x9d: /* STA abcd,x */
1026 ABSOLUTE_X;
1027 STA;
1028 break;
1029 case 0xa0: /* LDY #ab */
1030 nz = y = FETCH;
1031 break;
1032 case 0xa1: /* LDA (ab,x) */
1033 INDIRECT_X;
1034 LDA;
1035 break;
1036 case 0xa2: /* LDX #ab */
1037 nz = x = FETCH;
1038 break;
1039 case 0xa4: /* LDY ab */
1040 ZPAGE;
1041 LDY_ZP;
1042 break;
1043 case 0xa5: /* LDA ab */
1044 ZPAGE;
1045 LDA_ZP;
1046 break;
1047 case 0xa6: /* LDX ab */
1048 ZPAGE;
1049 LDX_ZP;
1050 break;
1051 case 0xa8: /* TAY */
1052 nz = y = a;
1053 break;
1054 case 0xa9: /* LDA #ab */
1055 nz = a = FETCH;
1056 break;
1057 case 0xaa: /* TAX */
1058 nz = x = a;
1059 break;
1060 case 0xac: /* LDY abcd */
1061 ABSOLUTE;
1062 LDY;
1063 break;
1064 case 0xad: /* LDA abcd */
1065 ABSOLUTE;
1066 LDA;
1067 break;
1068 case 0xae: /* LDX abcd */
1069 ABSOLUTE;
1070 LDX;
1071 break;
1072 case 0xb0: /* BCS */
1073 BRANCH(c != 0);
1074 case 0xb1: /* LDA (ab),y */
1075 INDIRECT_Y;
1076 NCYCLES_Y;
1077 LDA;
1078 break;
1079 case 0xb4: /* LDY ab,x */
1080 ZPAGE_X;
1081 LDY_ZP;
1082 break;
1083 case 0xb5: /* LDA ab,x */
1084 ZPAGE_X;
1085 LDA_ZP;
1086 break;
1087 case 0xb6: /* LDX ab,y */
1088 ZPAGE_Y;
1089 LDX_ZP;
1090 break;
1091 case 0xb8: /* CLV */
1092 vdi &= D_FLAG | I_FLAG;
1093 break;
1094 case 0xb9: /* LDA abcd,y */
1095 ABSOLUTE_Y;
1096 NCYCLES_Y;
1097 LDA;
1098 break;
1099 case 0xba: /* TSX */
1100 nz = x = s;
1101 break;
1102 case 0xbc: /* LDY abcd,x */
1103 ABSOLUTE_X;
1104 NCYCLES_X;
1105 LDY;
1106 break;
1107 case 0xbd: /* LDA abcd,x */
1108 ABSOLUTE_X;
1109 NCYCLES_X;
1110 LDA;
1111 break;
1112 case 0xbe: /* LDX abcd,y */
1113 ABSOLUTE_Y;
1114 NCYCLES_Y;
1115 LDX;
1116 break;
1117 case 0xc0: /* CPY #ab */
1118 nz = FETCH;
1119 c = (y >= nz) ? 1 : 0;
1120 nz = (y - nz) & 0xff;
1121 break;
1122 case 0xc1: /* CMP (ab,x) */
1123 INDIRECT_X;
1124 CMP;
1125 break;
1126 case 0xc4: /* CPY ab */
1127 ZPAGE;
1128 CPY_ZP;
1129 break;
1130 case 0xc5: /* CMP ab */
1131 ZPAGE;
1132 CMP_ZP;
1133 break;
1134 case 0xc6: /* DEC ab */
1135 ZPAGE;
1136 DEC_ZP;
1137 break;
1138 case 0xc8: /* INY */
1139 nz = y = (y + 1) & 0xff;
1140 break;
1141 case 0xc9: /* CMP #ab */
1142 nz = FETCH;
1143 c = (a >= nz) ? 1 : 0;
1144 nz = (a - nz) & 0xff;
1145 break;
1146 case 0xca: /* DEX */
1147 nz = x = (x - 1) & 0xff;
1148 break;
1149 case 0xcc: /* CPY abcd */
1150 ABSOLUTE;
1151 CPY;
1152 break;
1153 case 0xcd: /* CMP abcd */
1154 ABSOLUTE;
1155 CMP;
1156 break;
1157 case 0xce: /* DEC abcd */
1158 ABSOLUTE;
1159 DEC;
1160 break;
1161 case 0xd0: /* BNE */
1162 BRANCH((nz & 0xff) != 0);
1163 case 0xd1: /* CMP (ab),y */
1164 INDIRECT_Y;
1165 NCYCLES_Y;
1166 CMP;
1167 break;
1168 case 0xd5: /* CMP ab,x */
1169 ZPAGE_X;
1170 CMP_ZP;
1171 break;
1172 case 0xd6: /* DEC ab,x */
1173 ZPAGE_X;
1174 DEC_ZP;
1175 break;
1176 case 0xd8: /* CLD */
1177 vdi &= V_FLAG | I_FLAG;
1178 break;
1179 case 0xd9: /* CMP abcd,y */
1180 ABSOLUTE_Y;
1181 NCYCLES_Y;
1182 CMP;
1183 break;
1184 case 0xdd: /* CMP abcd,x */
1185 ABSOLUTE_X;
1186 NCYCLES_X;
1187 CMP;
1188 break;
1189 case 0xde: /* DEC abcd,x */
1190 ABSOLUTE_X;
1191 DEC;
1192 break;
1193 case 0xe0: /* CPX #ab */
1194 nz = FETCH;
1195 c = (x >= nz) ? 1 : 0;
1196 nz = (x - nz) & 0xff;
1197 break;
1198 case 0xe1: /* SBC (ab,x) */
1199 INDIRECT_X;
1200 SBC;
1201 break;
1202 case 0xe4: /* CPX ab */
1203 ZPAGE;
1204 CPX_ZP;
1205 break;
1206 case 0xe5: /* SBC ab */
1207 ZPAGE;
1208 SBC_ZP;
1209 break;
1210 case 0xe6: /* INC ab */
1211 ZPAGE;
1212 INC_ZP;
1213 break;
1214 case 0xe8: /* INX */
1215 nz = x = (x + 1) & 0xff;
1216 break;
1217 case 0xe9: /* SBC #ab */
1218 case 0xeb: /* SBC #ab [unofficial] */
1219 data = FETCH;
1220 DO_SBC;
1221 break;
1222 case 0xea: /* NOP */
1223 case 0x1a: /* NOP [unofficial] */
1224 case 0x3a:
1225 case 0x5a:
1226 case 0x7a:
1227 case 0xda:
1228 case 0xfa:
1229 break;
1230 case 0xec: /* CPX abcd */
1231 ABSOLUTE;
1232 CPX;
1233 break;
1234 case 0xed: /* SBC abcd */
1235 ABSOLUTE;
1236 SBC;
1237 break;
1238 case 0xee: /* INC abcd */
1239 ABSOLUTE;
1240 INC;
1241 break;
1242 case 0xf0: /* BEQ */
1243 BRANCH((nz & 0xff) == 0);
1244 case 0xf1: /* SBC (ab),y */
1245 INDIRECT_Y;
1246 NCYCLES_Y;
1247 SBC;
1248 break;
1249 case 0xf5: /* SBC ab,x */
1250 ZPAGE_X;
1251 SBC_ZP;
1252 break;
1253 case 0xf6: /* INC ab,x */
1254 ZPAGE_X;
1255 INC_ZP;
1256 break;
1257 case 0xf8: /* SED */
1258 vdi |= D_FLAG;
1259 break;
1260 case 0xf9: /* SBC abcd,y */
1261 ABSOLUTE_Y;
1262 NCYCLES_Y;
1263 SBC;
1264 break;
1265 case 0xfd: /* SBC abcd,x */
1266 ABSOLUTE_X;
1267 NCYCLES_X;
1268 SBC;
1269 break;
1270 case 0xfe: /* INC abcd,x */
1271 ABSOLUTE_X;
1272 INC;
1273 break;
1274 }
1275 }
1276 ast _ cpu_pc = pc;
1277 ast _ cpu_nz = nz;
1278 ast _ cpu_a = a;
1279 ast _ cpu_x = x;
1280 ast _ cpu_y = y;
1281 ast _ cpu_c = c;
1282 ast _ cpu_s = s;
1283 ast _ cpu_vdi = vdi;
1284 ast _ cycle -= cycle_limit;
1285 if (ast _ timer1_cycle != NEVER)
1286 ast _ timer1_cycle -= cycle_limit;
1287 if (ast _ timer2_cycle != NEVER)
1288 ast _ timer2_cycle -= cycle_limit;
1289 if (ast _ timer4_cycle != NEVER)
1290 ast _ timer4_cycle -= cycle_limit;
1291}
diff --git a/lib/rbcodec/codecs/libasap/anylang.h b/lib/rbcodec/codecs/libasap/anylang.h
new file mode 100644
index 0000000000..e56dfbae0e
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/anylang.h
@@ -0,0 +1,218 @@
1/*
2 * anylang.h - C/Java/C#/JavaScript/ActionScript abstraction layer
3 *
4 * Copyright (C) 2007-2010 Piotr Fusik
5 *
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
8 *
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _ANYLANG_H_
25#define _ANYLANG_H_
26
27#if defined(JAVA) || defined(CSHARP) || defined(JAVASCRIPT) || defined(ACTIONSCRIPT)
28
29#define FALSE false
30#define TRUE true
31#define NULL null
32#define _ .
33#define PRIVATE
34#define CONST
35#define OUT_STRING STRING
36
37#else
38
39#define C
40#include <string.h>
41
42#define PRIVATE static
43#define FUNC(type, name, pars) type name pars
44#define P(type, name) type name
45#define V(type, name) type name
46#define CONST const
47#define _ ->
48#define PTR *
49#define ADDRESSOF &
50#define CAST(type) (type)
51#define TO_INT(x) (int) (x)
52#define TO_BYTE(x) (byte) (x)
53#define BYTEARRAY byte *
54#define BOOLARRAY abool *
55#define VOIDPTR void *
56#define UBYTE(data) (data)
57#define SBYTE(data) (signed char) (data)
58#define CONST_ARRAY(type, name) static const type name[] = {
59#define END_CONST_ARRAY }
60#define ZERO_ARRAY(array) memset(array, 0, sizeof(array))
61#define COPY_ARRAY(dest, dest_offset, src, src_offset, len) \
62 memcpy(dest + dest_offset, src + src_offset, len)
63#define NEW_ARRAY(type, name, size) \
64 type name[size]
65#define INIT_ARRAY(array) memset(array, 0, sizeof(array))
66#define STRING const char *
67#define OUT_STRING char *
68#define CHARAT(s, i) (s)[i]
69#define CHARCODEAT(s, i) (s)[i]
70#define CHARCODE(c) (c)
71#define EQUAL_STRINGS(s1, s2) (strcmp(s1, s2) == 0)
72#define EMPTY_STRING(s) (s)[0] = '\0'
73#define SUBSTR(s, i) (s + i)
74#define BYTES_TO_STRING(dest, src, src_offset, len) \
75 do { memcpy(dest, src + src_offset, len); (dest)[len] = '\0'; } while (FALSE)
76#define SUBSTRING(dest, src, src_offset, len) \
77 do { memcpy(dest, src + src_offset, len); (dest)[len] = '\0'; } while (FALSE)
78
79#define RESOURCE const byte *
80#define GET_RESOURCE(name, ext) name##_##ext
81
82#endif /* defined(JAVA) || defined(CSHARP) || defined(JAVASCRIPT) || defined(ACTIONSCRIPT) */
83
84#ifdef JAVA
85
86#define abool boolean
87#define FUNC(type, name, pars) private static type name pars
88#define P(type, name) type name
89#define V(type, name) type name
90#define PTR
91#define ADDRESSOF
92#define CAST(type) (type)
93#define TO_INT(x) (int) (x)
94#define TO_BYTE(x) (byte) (x)
95#define BYTEARRAY byte[]
96#define BOOLARRAY boolean[]
97#define VOIDPTR byte[]
98#define UBYTE(data) ((data) & 0xff)
99#define SBYTE(data) (byte) (data)
100#define CONST_ARRAY(type, name) private static final type[] name = {
101#define END_CONST_ARRAY }
102#define sizeof(array) array.length
103#define ZERO_ARRAY(array) for (int ii = 0; ii < array.length; ii++) array[ii] = 0
104#define COPY_ARRAY(dest, dest_offset, src, src_offset, len) \
105 System.arraycopy(src, src_offset, dest, dest_offset, len)
106#define NEW_ARRAY(type, name, size) \
107 type[] name = new type[size]
108#define INIT_ARRAY(array)
109#define STRING String
110#define CHARAT(s, i) (s).charAt(i)
111#define CHARCODEAT(s, i) (s).charAt(i)
112#define CHARCODE(c) (c)
113#define strlen(s) (s).length()
114#define EQUAL_STRINGS(s1, s2) (s1).equals(s2)
115#define EMPTY_STRING(s) (s) = ""
116#define SUBSTR(s, i) (s).substring(i)
117#define BYTES_TO_STRING(dest, src, src_offset, len) \
118 (dest) = new String(src, src_offset, len)
119#define SUBSTRING(dest, src, src_offset, len) \
120 (dest) = (src).substring(src_offset, src_offset + len)
121
122#define RESOURCE byte[]
123#define GET_RESOURCE(name, ext) getResourceBytes(#name + "." + #ext)
124
125#elif defined(CSHARP)
126
127#define abool bool
128#define FUNC(type, name, pars) private static type name pars
129#define P(type, name) type name
130#define V(type, name) type name
131#define PTR
132#define ADDRESSOF
133#define CAST(type) (type)
134#define TO_INT(x) (int) (x)
135#define TO_BYTE(x) (byte) (x)
136#define BYTEARRAY byte[]
137#define BOOLARRAY bool[]
138#define VOIDPTR byte[]
139#define UBYTE(data) (data)
140#define SBYTE(data) (sbyte) (data)
141#define CONST_ARRAY(type, name) private static readonly type[] name = {
142#define END_CONST_ARRAY }
143#define sizeof(array) array.Length
144#define ZERO_ARRAY(array) Array.Clear(array, 0, array.Length)
145#define COPY_ARRAY(dest, dest_offset, src, src_offset, len) \
146 Array.Copy(src, src_offset, dest, dest_offset, len)
147#define NEW_ARRAY(type, name, size) \
148 type[] name = new type[size]
149#define INIT_ARRAY(array)
150#define STRING string
151#define CHARAT(s, i) (s)[i]
152#define CHARCODEAT(s, i) (s)[i]
153#define CHARCODE(c) (c)
154#define strlen(s) (s).Length
155#define EQUAL_STRINGS(s1, s2) ((s1) == (s2))
156#define EMPTY_STRING(s) (s) = string.Empty
157#define SUBSTR(s, i) (s).Substring(i)
158#define BYTES_TO_STRING(dest, src, src_offset, len) \
159 (dest) = System.Text.Encoding.UTF8.GetString(src, src_offset, len)
160#define SUBSTRING(dest, src, src_offset, len) \
161 (dest) = (src).Substring(src_offset, len)
162
163#define RESOURCE byte[]
164#define GET_RESOURCE(name, ext) name##_##ext
165
166#elif defined(JAVASCRIPT) || defined(ACTIONSCRIPT)
167
168#ifdef ACTIONSCRIPT
169#define abool Boolean
170#define char String
171#define STRING String
172#define BYTEARRAY ByteArray
173#define BOOLARRAY Array
174#define VOIDPTR ByteArray
175#define RESOURCE Array
176#define FUNC(type, name, pars) private static function name pars : type
177#define P(type, name) name : type
178#define V(type, name) var name : type
179#define TO_INT(x) int(x)
180#define CONST_ARRAY(type, name) private static const name : Array = [
181#else
182#define FUNC(type, name, pars) function name pars
183#define P(type, name) name
184#define V(type, name) var name
185#define TO_INT(x) Math.floor(x)
186#define CONST_ARRAY(type, name) var name = [
187#endif
188#define PTR
189#define ADDRESSOF
190#define CAST(type)
191#define TO_BYTE(x) ((x) & 0xff)
192#define UBYTE(data) (data)
193#define SBYTE(data) ((data) < 0x80 ? (data) : (data) - 256)
194#define END_CONST_ARRAY ]
195#define sizeof(array) array.length
196#define ZERO_ARRAY(array) for (V(int, ii) = 0; ii < array.length; ii++) array[ii] = 0
197#define COPY_ARRAY(dest, dest_offset, src, src_offset, len) \
198 for (V(int, ii) = 0; ii < len; ii++) dest[dest_offset + ii] = src[src_offset + ii]
199#define NEW_ARRAY(type, name, size) \
200 V(Array, name) = new Array(size)
201#define INIT_ARRAY(array) for (V(int, ii) = 0; ii < array.length; ii++) array[ii] = 0
202#define CHARAT(s, i) (s).charAt(i)
203#define CHARCODEAT(s, i) (s).charCodeAt(i)
204#define CHARCODE(c) (c).charCodeAt(0)
205#define strlen(s) (s).length
206#define EQUAL_STRINGS(s1, s2) ((s1) == (s2))
207#define EMPTY_STRING(s) s = ""
208#define SUBSTR(s, i) (s).substr(i)
209#define BYTES_TO_STRING(dest, src, src_offset, len) \
210 { dest = ""; for (V(int, ii) = 0; ii < len; ii++) dest += String.fromCharCode(src[src_offset + ii]); }
211#define SUBSTRING(dest, src, src_offset, len) \
212 dest = (src).substring(src_offset, src_offset + len)
213
214#define GET_RESOURCE(name, ext) name##_##ext
215
216#endif
217
218#endif /* _ANYLANG_H_ */
diff --git a/lib/rbcodec/codecs/libasap/apokeysnd.c b/lib/rbcodec/codecs/libasap/apokeysnd.c
new file mode 100644
index 0000000000..811e2f9b4a
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/apokeysnd.c
@@ -0,0 +1,599 @@
1/*
2 * apokeysnd.c - another POKEY sound emulator
3 *
4 * Copyright (C) 2007-2010 Piotr Fusik
5 *
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
8 *
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include "asap_internal.h"
25
26#define ULTRASOUND_CYCLES 112
27
28#define MUTE_FREQUENCY 1
29#define MUTE_INIT 2
30#define MUTE_USER 4
31
32CONST_ARRAY(byte, poly4_lookup)
33 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1
34END_CONST_ARRAY;
35CONST_ARRAY(byte, poly5_lookup)
36 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1,
37 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1
38END_CONST_ARRAY;
39
40PRIVATE FUNC(void, PokeySound_InitializeChip, (P(PokeyState PTR, pst)))
41{
42 pst _ audctl = 0;
43 pst _ init = FALSE;
44 pst _ poly_index = 15 * 31 * 131071;
45 pst _ div_cycles = 28;
46 pst _ mute1 = MUTE_FREQUENCY | MUTE_USER;
47 pst _ mute2 = MUTE_FREQUENCY | MUTE_USER;
48 pst _ mute3 = MUTE_FREQUENCY | MUTE_USER;
49 pst _ mute4 = MUTE_FREQUENCY | MUTE_USER;
50 pst _ audf1 = 0;
51 pst _ audf2 = 0;
52 pst _ audf3 = 0;
53 pst _ audf4 = 0;
54 pst _ audc1 = 0;
55 pst _ audc2 = 0;
56 pst _ audc3 = 0;
57 pst _ audc4 = 0;
58 pst _ tick_cycle1 = NEVER;
59 pst _ tick_cycle2 = NEVER;
60 pst _ tick_cycle3 = NEVER;
61 pst _ tick_cycle4 = NEVER;
62 pst _ period_cycles1 = 28;
63 pst _ period_cycles2 = 28;
64 pst _ period_cycles3 = 28;
65 pst _ period_cycles4 = 28;
66 pst _ reload_cycles1 = 28;
67 pst _ reload_cycles3 = 28;
68 pst _ out1 = 0;
69 pst _ out2 = 0;
70 pst _ out3 = 0;
71 pst _ out4 = 0;
72 pst _ delta1 = 0;
73 pst _ delta2 = 0;
74 pst _ delta3 = 0;
75 pst _ delta4 = 0;
76 pst _ skctl = 3;
77 ZERO_ARRAY(pst _ delta_buffer);
78}
79
80FUNC(void, PokeySound_Initialize, (P(ASAP_State PTR, ast)))
81{
82 V(int, i);
83 V(int, reg);
84 reg = 0x1ff;
85 for (i = 0; i < 511; i++) {
86 reg = ((((reg >> 5) ^ reg) & 1) << 8) + (reg >> 1);
87 ast _ poly9_lookup[i] = TO_BYTE(reg);
88 }
89 reg = 0x1ffff;
90 for (i = 0; i < 16385; i++) {
91 reg = ((((reg >> 5) ^ reg) & 0xff) << 9) + (reg >> 8);
92 ast _ poly17_lookup[i] = TO_BYTE(reg >> 1);
93 }
94 ast _ sample_offset = 0;
95 ast _ sample_index = 0;
96 ast _ samples = 0;
97 ast _ iir_acc_left = 0;
98 ast _ iir_acc_right = 0;
99 PokeySound_InitializeChip(ADDRESSOF ast _ base_pokey);
100 PokeySound_InitializeChip(ADDRESSOF ast _ extra_pokey);
101}
102
103#define DO_TICK(ch) \
104 if (pst _ init) { \
105 switch (pst _ audc##ch >> 4) { \
106 case 10: \
107 case 14: \
108 pst _ out##ch ^= 1; \
109 pst _ delta_buffer[CYCLE_TO_SAMPLE(cycle)] += pst _ delta##ch = -pst _ delta##ch; \
110 break; \
111 default: \
112 break; \
113 } \
114 } \
115 else { \
116 V(int, poly) = cycle + pst _ poly_index - (ch - 1); \
117 V(int, newout) = pst _ out##ch; \
118 switch (pst _ audc##ch >> 4) { \
119 case 0: \
120 if (poly5_lookup[poly % 31] != 0) { \
121 if ((pst _ audctl & 0x80) != 0) \
122 newout = ast _ poly9_lookup[poly % 511] & 1; \
123 else { \
124 poly %= 131071; \
125 newout = (ast _ poly17_lookup[poly >> 3] >> (poly & 7)) & 1; \
126 } \
127 } \
128 break; \
129 case 2: \
130 case 6: \
131 newout ^= poly5_lookup[poly % 31]; \
132 break; \
133 case 4: \
134 if (poly5_lookup[poly % 31] != 0) \
135 newout = poly4_lookup[poly % 15]; \
136 break; \
137 case 8: \
138 if ((pst _ audctl & 0x80) != 0) \
139 newout = ast _ poly9_lookup[poly % 511] & 1; \
140 else { \
141 poly %= 131071; \
142 newout = (ast _ poly17_lookup[poly >> 3] >> (poly & 7)) & 1; \
143 } \
144 break; \
145 case 10: \
146 case 14: \
147 newout ^= 1; \
148 break; \
149 case 12: \
150 newout = poly4_lookup[poly % 15]; \
151 break; \
152 default: \
153 break; \
154 } \
155 if (newout != pst _ out##ch) { \
156 pst _ out##ch = newout; \
157 pst _ delta_buffer[CYCLE_TO_SAMPLE(cycle)] += pst _ delta##ch = -pst _ delta##ch; \
158 } \
159 }
160
161/* Fills delta_buffer up to current_cycle basing on current AUDF/AUDC/AUDCTL values. */
162PRIVATE FUNC(void, PokeySound_GenerateUntilCycle, (P(ASAP_State PTR, ast), P(PokeyState PTR, pst), P(int, current_cycle)))
163{
164 for (;;) {
165 V(int, cycle) = current_cycle;
166 if (cycle > pst _ tick_cycle1)
167 cycle = pst _ tick_cycle1;
168 if (cycle > pst _ tick_cycle2)
169 cycle = pst _ tick_cycle2;
170 if (cycle > pst _ tick_cycle3)
171 cycle = pst _ tick_cycle3;
172 if (cycle > pst _ tick_cycle4)
173 cycle = pst _ tick_cycle4;
174 if (cycle == current_cycle)
175 break;
176 if (cycle == pst _ tick_cycle3) {
177 pst _ tick_cycle3 += pst _ period_cycles3;
178 if ((pst _ audctl & 4) != 0 && pst _ delta1 > 0 && pst _ mute1 == 0)
179 pst _ delta_buffer[CYCLE_TO_SAMPLE(cycle)] += pst _ delta1 = -pst _ delta1;
180 DO_TICK(3);
181 }
182 if (cycle == pst _ tick_cycle4) {
183 pst _ tick_cycle4 += pst _ period_cycles4;
184 if ((pst _ audctl & 8) != 0)
185 pst _ tick_cycle3 = cycle + pst _ reload_cycles3;
186 if ((pst _ audctl & 2) != 0 && pst _ delta2 > 0 && pst _ mute2 == 0)
187 pst _ delta_buffer[CYCLE_TO_SAMPLE(cycle)] += pst _ delta2 = -pst _ delta2;
188 DO_TICK(4);
189 }
190 if (cycle == pst _ tick_cycle1) {
191 pst _ tick_cycle1 += pst _ period_cycles1;
192 if ((pst _ skctl & 0x88) == 8) /* two-tone, sending 1 (i.e. timer1) */
193 pst _ tick_cycle2 = cycle + pst _ period_cycles2;
194 DO_TICK(1);
195 }
196 if (cycle == pst _ tick_cycle2) {
197 pst _ tick_cycle2 += pst _ period_cycles2;
198 if ((pst _ audctl & 0x10) != 0)
199 pst _ tick_cycle1 = cycle + pst _ reload_cycles1;
200 else if ((pst _ skctl & 8) != 0) /* two-tone */
201 pst _ tick_cycle1 = cycle + pst _ period_cycles1;
202 DO_TICK(2);
203 }
204 }
205}
206
207#ifdef APOKEYSND
208
209#define CURRENT_CYCLE 0
210#define CURRENT_SAMPLE 0
211#define DO_STORE(reg) \
212 if (data == pst _ reg) \
213 break; \
214 pst _ reg = data;
215
216#else
217
218#define CURRENT_CYCLE ast _ cycle
219#define CURRENT_SAMPLE CYCLE_TO_SAMPLE(ast _ cycle)
220#define DO_STORE(reg) \
221 if (data == pst _ reg) \
222 break; \
223 PokeySound_GenerateUntilCycle(ast, pst, ast _ cycle); \
224 pst _ reg = data;
225
226#endif /* APOKEYSND */
227
228#define MUTE_CHANNEL(ch, cond, mask) \
229 if (cond) { \
230 pst _ mute##ch |= mask; \
231 pst _ tick_cycle##ch = NEVER; \
232 } \
233 else { \
234 pst _ mute##ch &= ~mask; \
235 if (pst _ tick_cycle##ch == NEVER && pst _ mute##ch == 0) \
236 pst _ tick_cycle##ch = CURRENT_CYCLE; \
237 }
238
239#define DO_ULTRASOUND(ch) \
240 MUTE_CHANNEL(ch, pst _ period_cycles##ch <= ULTRASOUND_CYCLES && (pst _ audc##ch >> 4 == 10 || pst _ audc##ch >> 4 == 14), MUTE_FREQUENCY)
241
242#define DO_AUDC(ch) \
243 DO_STORE(audc##ch); \
244 if ((data & 0x10) != 0) { \
245 data = (data & 0xf) << DELTA_SHIFT_POKEY; \
246 if ((pst _ mute##ch & MUTE_USER) == 0) \
247 pst _ delta_buffer[CURRENT_SAMPLE] \
248 += pst _ delta##ch > 0 ? data - pst _ delta##ch : data; \
249 pst _ delta##ch = data; \
250 } \
251 else { \
252 data = (data & 0xf) << DELTA_SHIFT_POKEY; \
253 DO_ULTRASOUND(ch); \
254 if (pst _ delta##ch > 0) { \
255 if ((pst _ mute##ch & MUTE_USER) == 0) \
256 pst _ delta_buffer[CURRENT_SAMPLE] \
257 += data - pst _ delta##ch; \
258 pst _ delta##ch = data; \
259 } \
260 else \
261 pst _ delta##ch = -data; \
262 } \
263 break;
264
265#define DO_INIT(ch, cond) \
266 MUTE_CHANNEL(ch, pst _ init && cond, MUTE_INIT)
267
268FUNC(void, PokeySound_PutByte, (P(ASAP_State PTR, ast), P(int, addr), P(int, data)))
269{
270 V(PokeyState PTR, pst) = (addr & ast _ extra_pokey_mask) != 0
271 ? ADDRESSOF ast _ extra_pokey : ADDRESSOF ast _ base_pokey;
272 switch (addr & 0xf) {
273 case 0x00:
274 DO_STORE(audf1);
275 switch (pst _ audctl & 0x50) {
276 case 0x00:
277 pst _ period_cycles1 = pst _ div_cycles * (data + 1);
278 break;
279 case 0x10:
280 pst _ period_cycles2 = pst _ div_cycles * (data + 256 * pst _ audf2 + 1);
281 pst _ reload_cycles1 = pst _ div_cycles * (data + 1);
282 DO_ULTRASOUND(2);
283 break;
284 case 0x40:
285 pst _ period_cycles1 = data + 4;
286 break;
287 case 0x50:
288 pst _ period_cycles2 = data + 256 * pst _ audf2 + 7;
289 pst _ reload_cycles1 = data + 4;
290 DO_ULTRASOUND(2);
291 break;
292 }
293 DO_ULTRASOUND(1);
294 break;
295 case 0x01:
296 DO_AUDC(1)
297 case 0x02:
298 DO_STORE(audf2);
299 switch (pst _ audctl & 0x50) {
300 case 0x00:
301 case 0x40:
302 pst _ period_cycles2 = pst _ div_cycles * (data + 1);
303 break;
304 case 0x10:
305 pst _ period_cycles2 = pst _ div_cycles * (pst _ audf1 + 256 * data + 1);
306 break;
307 case 0x50:
308 pst _ period_cycles2 = pst _ audf1 + 256 * data + 7;
309 break;
310 }
311 DO_ULTRASOUND(2);
312 break;
313 case 0x03:
314 DO_AUDC(2)
315 case 0x04:
316 DO_STORE(audf3);
317 switch (pst _ audctl & 0x28) {
318 case 0x00:
319 pst _ period_cycles3 = pst _ div_cycles * (data + 1);
320 break;
321 case 0x08:
322 pst _ period_cycles4 = pst _ div_cycles * (data + 256 * pst _ audf4 + 1);
323 pst _ reload_cycles3 = pst _ div_cycles * (data + 1);
324 DO_ULTRASOUND(4);
325 break;
326 case 0x20:
327 pst _ period_cycles3 = data + 4;
328 break;
329 case 0x28:
330 pst _ period_cycles4 = data + 256 * pst _ audf4 + 7;
331 pst _ reload_cycles3 = data + 4;
332 DO_ULTRASOUND(4);
333 break;
334 }
335 DO_ULTRASOUND(3);
336 break;
337 case 0x05:
338 DO_AUDC(3)
339 case 0x06:
340 DO_STORE(audf4);
341 switch (pst _ audctl & 0x28) {
342 case 0x00:
343 case 0x20:
344 pst _ period_cycles4 = pst _ div_cycles * (data + 1);
345 break;
346 case 0x08:
347 pst _ period_cycles4 = pst _ div_cycles * (pst _ audf3 + 256 * data + 1);
348 break;
349 case 0x28:
350 pst _ period_cycles4 = pst _ audf3 + 256 * data + 7;
351 break;
352 }
353 DO_ULTRASOUND(4);
354 break;
355 case 0x07:
356 DO_AUDC(4)
357 case 0x08:
358 DO_STORE(audctl);
359 pst _ div_cycles = ((data & 1) != 0) ? 114 : 28;
360 /* TODO: tick_cycles */
361 switch (data & 0x50) {
362 case 0x00:
363 pst _ period_cycles1 = pst _ div_cycles * (pst _ audf1 + 1);
364 pst _ period_cycles2 = pst _ div_cycles * (pst _ audf2 + 1);
365 break;
366 case 0x10:
367 pst _ period_cycles1 = pst _ div_cycles * 256;
368 pst _ period_cycles2 = pst _ div_cycles * (pst _ audf1 + 256 * pst _ audf2 + 1);
369 pst _ reload_cycles1 = pst _ div_cycles * (pst _ audf1 + 1);
370 break;
371 case 0x40:
372 pst _ period_cycles1 = pst _ audf1 + 4;
373 pst _ period_cycles2 = pst _ div_cycles * (pst _ audf2 + 1);
374 break;
375 case 0x50:
376 pst _ period_cycles1 = 256;
377 pst _ period_cycles2 = pst _ audf1 + 256 * pst _ audf2 + 7;
378 pst _ reload_cycles1 = pst _ audf1 + 4;
379 break;
380 }
381 DO_ULTRASOUND(1);
382 DO_ULTRASOUND(2);
383 switch (data & 0x28) {
384 case 0x00:
385 pst _ period_cycles3 = pst _ div_cycles * (pst _ audf3 + 1);
386 pst _ period_cycles4 = pst _ div_cycles * (pst _ audf4 + 1);
387 break;
388 case 0x08:
389 pst _ period_cycles3 = pst _ div_cycles * 256;
390 pst _ period_cycles4 = pst _ div_cycles * (pst _ audf3 + 256 * pst _ audf4 + 1);
391 pst _ reload_cycles3 = pst _ div_cycles * (pst _ audf3 + 1);
392 break;
393 case 0x20:
394 pst _ period_cycles3 = pst _ audf3 + 4;
395 pst _ period_cycles4 = pst _ div_cycles * (pst _ audf4 + 1);
396 break;
397 case 0x28:
398 pst _ period_cycles3 = 256;
399 pst _ period_cycles4 = pst _ audf3 + 256 * pst _ audf4 + 7;
400 pst _ reload_cycles3 = pst _ audf3 + 4;
401 break;
402 }
403 DO_ULTRASOUND(3);
404 DO_ULTRASOUND(4);
405 DO_INIT(1, (data & 0x40) == 0);
406 DO_INIT(2, (data & 0x50) != 0x50);
407 DO_INIT(3, (data & 0x20) == 0);
408 DO_INIT(4, (data & 0x28) != 0x28);
409 break;
410 case 0x09:
411 /* TODO: STIMER */
412 break;
413 case 0x0f:
414 DO_STORE(skctl);
415 pst _ init = ((data & 3) == 0);
416 DO_INIT(1, (pst _ audctl & 0x40) == 0);
417 DO_INIT(2, (pst _ audctl & 0x50) != 0x50);
418 DO_INIT(3, (pst _ audctl & 0x20) == 0);
419 DO_INIT(4, (pst _ audctl & 0x28) != 0x28);
420 break;
421 default:
422 break;
423 }
424}
425
426FUNC(int, PokeySound_GetRandom, (P(ASAP_State PTR, ast), P(int, addr), P(int, cycle)))
427{
428 V(PokeyState PTR, pst) = (addr & ast _ extra_pokey_mask) != 0
429 ? ADDRESSOF ast _ extra_pokey : ADDRESSOF ast _ base_pokey;
430 V(int, i);
431 if (pst _ init)
432 return 0xff;
433 i = cycle + pst _ poly_index;
434 if ((pst _ audctl & 0x80) != 0)
435 return ast _ poly9_lookup[i % 511];
436 else {
437 V(int, j);
438 i %= 131071;
439 j = i >> 3;
440 i &= 7;
441 return ((ast _ poly17_lookup[j] >> i) + (ast _ poly17_lookup[j + 1] << (8 - i))) & 0xff;
442 }
443}
444
445PRIVATE FUNC(void, end_frame, (P(ASAP_State PTR, ast), P(PokeyState PTR, pst), P(int, cycle_limit)))
446{
447 V(int, m);
448 PokeySound_GenerateUntilCycle(ast, pst, cycle_limit);
449 pst _ poly_index += cycle_limit;
450 m = ((pst _ audctl & 0x80) != 0) ? 15 * 31 * 511 : 15 * 31 * 131071;
451 if (pst _ poly_index >= 2 * m)
452 pst _ poly_index -= m;
453 if (pst _ tick_cycle1 != NEVER)
454 pst _ tick_cycle1 -= cycle_limit;
455 if (pst _ tick_cycle2 != NEVER)
456 pst _ tick_cycle2 -= cycle_limit;
457 if (pst _ tick_cycle3 != NEVER)
458 pst _ tick_cycle3 -= cycle_limit;
459 if (pst _ tick_cycle4 != NEVER)
460 pst _ tick_cycle4 -= cycle_limit;
461}
462
463FUNC(void, PokeySound_StartFrame, (P(ASAP_State PTR, ast)))
464{
465 ZERO_ARRAY(ast _ base_pokey.delta_buffer);
466 if (ast _ extra_pokey_mask != 0)
467 ZERO_ARRAY(ast _ extra_pokey.delta_buffer);
468}
469
470FUNC(void, PokeySound_EndFrame, (P(ASAP_State PTR, ast), P(int, current_cycle)))
471{
472 V(int, clk) = ASAP_MAIN_CLOCK(ast);
473 end_frame(ast, ADDRESSOF ast _ base_pokey, current_cycle);
474 if (ast _ extra_pokey_mask != 0)
475 end_frame(ast, ADDRESSOF ast _ extra_pokey, current_cycle);
476 ast _ sample_offset += current_cycle * ASAP_SAMPLE_RATE;
477 ast _ sample_index = 0;
478 ast _ samples = TO_INT(ast _ sample_offset / clk);
479 ast _ sample_offset %= clk;
480}
481
482/* Fills buffer with samples from delta_buffer. */
483FUNC(int, PokeySound_Generate, (P(ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(int, buffer_offset), P(int, blocks), P(ASAP_SampleFormat, format)))
484{
485 V(int, i) = ast _ sample_index;
486 V(int, samples) = ast _ samples;
487 V(int, acc_left) = ast _ iir_acc_left;
488 V(int, acc_right) = ast _ iir_acc_right;
489 if (blocks < samples - i)
490 samples = i + blocks;
491 else
492 blocks = samples - i;
493 for (; i < samples; i++) {
494#ifdef ACTIONSCRIPT
495 acc_left += ast _ base_pokey.delta_buffer[i] - (acc_left * 3 >> 10);
496 var sample : Number = acc_left / 33553408;
497 buffer.writeFloat(sample);
498 if (ast.extra_pokey_mask != 0) {
499 acc_right += ast _ extra_pokey.delta_buffer[i] - (acc_right * 3 >> 10);
500 sample = acc_right / 33553408;
501 }
502 buffer.writeFloat(sample);
503#else
504 V(int, sample);
505 acc_left += ast _ base_pokey.delta_buffer[i] - (acc_left * 3 >> 10);
506 sample = acc_left >> 10;
507#define STORE_SAMPLE \
508 if (sample < -32767) \
509 sample = -32767; \
510 else if (sample > 32767) \
511 sample = 32767; \
512 switch (format) { \
513 case ASAP_FORMAT_U8: \
514 buffer[buffer_offset++] = CAST(byte) ((sample >> 8) + 128); \
515 break; \
516 case ASAP_FORMAT_S16_LE: \
517 buffer[buffer_offset++] = TO_BYTE(sample); \
518 buffer[buffer_offset++] = TO_BYTE(sample >> 8); \
519 break; \
520 case ASAP_FORMAT_S16_BE: \
521 buffer[buffer_offset++] = TO_BYTE(sample >> 8); \
522 buffer[buffer_offset++] = TO_BYTE(sample); \
523 break; \
524 }
525 STORE_SAMPLE;
526 if (ast _ extra_pokey_mask != 0) {
527 acc_right += ast _ extra_pokey.delta_buffer[i] - (acc_right * 3 >> 10);
528 sample = acc_right >> 10;
529 STORE_SAMPLE;
530 }
531#endif /* ACTIONSCRIPT */
532 }
533 if (i == ast _ samples) {
534 acc_left += ast _ base_pokey.delta_buffer[i];
535 acc_right += ast _ extra_pokey.delta_buffer[i];
536 }
537 ast _ sample_index = i;
538 ast _ iir_acc_left = acc_left;
539 ast _ iir_acc_right = acc_right;
540#ifdef APOKEYSND
541 return buffer_offset;
542#else
543 return blocks;
544#endif
545}
546
547FUNC(abool, PokeySound_IsSilent, (P(CONST PokeyState PTR, pst)))
548{
549 return ((pst _ audc1 | pst _ audc2 | pst _ audc3 | pst _ audc4) & 0xf) == 0;
550}
551
552FUNC(void, PokeySound_Mute, (P(CONST ASAP_State PTR, ast), P(PokeyState PTR, pst), P(int, mask)))
553{
554 MUTE_CHANNEL(1, (mask & 1) != 0, MUTE_USER);
555 MUTE_CHANNEL(2, (mask & 2) != 0, MUTE_USER);
556 MUTE_CHANNEL(3, (mask & 4) != 0, MUTE_USER);
557 MUTE_CHANNEL(4, (mask & 8) != 0, MUTE_USER);
558}
559
560#ifdef APOKEYSND
561
562static ASAP_State asap;
563
564__declspec(dllexport) void APokeySound_Initialize(abool stereo)
565{
566 asap.extra_pokey_mask = stereo ? 0x10 : 0;
567 PokeySound_Initialize(&asap);
568 PokeySound_Mute(&asap, &asap.base_pokey, 0);
569 PokeySound_Mute(&asap, &asap.extra_pokey, 0);
570 PokeySound_StartFrame(&asap);
571}
572
573__declspec(dllexport) void APokeySound_PutByte(int addr, int data)
574{
575 PokeySound_PutByte(&asap, addr, data);
576}
577
578__declspec(dllexport) int APokeySound_GetRandom(int addr, int cycle)
579{
580 return PokeySound_GetRandom(&asap, addr, cycle);
581}
582
583__declspec(dllexport) int APokeySound_Generate(int cycles, byte buffer[], ASAP_SampleFormat format)
584{
585 int len;
586 PokeySound_EndFrame(&asap, cycles);
587 len = PokeySound_Generate(&asap, buffer, 0, asap.samples, format);
588 PokeySound_StartFrame(&asap);
589 return len;
590}
591
592__declspec(dllexport) void APokeySound_About(const char **name, const char **author, const char **description)
593{
594 *name = "Another POKEY sound emulator, v" ASAP_VERSION;
595 *author = "Piotr Fusik, (C) " ASAP_YEARS;
596 *description = "Part of ASAP, http://asap.sourceforge.net";
597}
598
599#endif /* APOKEYSND */
diff --git a/lib/rbcodec/codecs/libasap/asap.c b/lib/rbcodec/codecs/libasap/asap.c
new file mode 100644
index 0000000000..1aeb843fa3
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/asap.c
@@ -0,0 +1,2273 @@
1/*
2 * asap.c - ASAP engine
3 *
4 * Copyright (C) 2005-2010 Piotr Fusik
5 *
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
8 *
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#include "asap_internal.h"
25
26static byte s_memory[65536];
27static ASAP_ModuleInfo s_module_info;
28
29#ifdef ASAP_ONLY_INFO
30
31#define GET_PLAYER(name) NULL
32
33#else
34
35#define GET_PLAYER(name) GET_RESOURCE(name, obx)
36
37FUNC(int, ASAP_GetByte, (P(ASAP_State PTR, ast), P(int, addr)))
38{
39 switch (addr & 0xff1f) {
40 case 0xd014:
41 return ast _ module_info->ntsc ? 0xf : 1;
42 case 0xd20a:
43 case 0xd21a:
44 return PokeySound_GetRandom(ast, addr, ast _ cycle);
45 case 0xd20e:
46 return ast _ irqst;
47 case 0xd21e:
48 if (ast _ extra_pokey_mask != 0) {
49 /* interrupts in the extra POKEY not emulated at the moment */
50 return 0xff;
51 }
52 return ast _ irqst;
53 case 0xd20c:
54 case 0xd21c:
55 case 0xd20f: /* just because some SAP files rely on this */
56 case 0xd21f:
57 return 0xff;
58 case 0xd40b:
59 case 0xd41b:
60 return ast _ scanline_number >> 1;
61 default:
62 return dGetByte(addr);
63 }
64}
65
66FUNC(void, ASAP_PutByte, (P(ASAP_State PTR, ast), P(int, addr), P(int, data)))
67{
68 if ((addr >> 8) == 0xd2) {
69 if ((addr & (ast _ extra_pokey_mask + 0xf)) == 0xe) {
70 ast _ irqst |= data ^ 0xff;
71#define SET_TIMER_IRQ(ch) \
72 if ((data & ast _ irqst & ch) != 0) { \
73 if (ast _ timer##ch##_cycle == NEVER) { \
74 V(int, t) = ast _ base_pokey.tick_cycle##ch; \
75 while (t < ast _ cycle) \
76 t += ast _ base_pokey.period_cycles##ch; \
77 ast _ timer##ch##_cycle = t; \
78 if (ast _ nearest_event_cycle > t) \
79 ast _ nearest_event_cycle = t; \
80 } \
81 } \
82 else \
83 ast _ timer##ch##_cycle = NEVER;
84 SET_TIMER_IRQ(1);
85 SET_TIMER_IRQ(2);
86 SET_TIMER_IRQ(4);
87 }
88 else
89 PokeySound_PutByte(ast, addr, data);
90 }
91 else if ((addr & 0xff0f) == 0xd40a) {
92 if (ast _ cycle <= ast _ next_scanline_cycle - 8)
93 ast _ cycle = ast _ next_scanline_cycle - 8;
94 else
95 ast _ cycle = ast _ next_scanline_cycle + 106;
96 }
97 else if ((addr & 0xff00) == ast _ module_info->covox_addr) {
98 V(PokeyState PTR, pst);
99 addr &= 3;
100 if (addr == 0 || addr == 3)
101 pst = ADDRESSOF ast _ base_pokey;
102 else
103 pst = ADDRESSOF ast _ extra_pokey;
104 pst _ delta_buffer[CYCLE_TO_SAMPLE(ast _ cycle)] += (data - UBYTE(ast _ covox[addr])) << DELTA_SHIFT_COVOX;
105 ast _ covox[addr] = CAST(byte) (data);
106 }
107 else if ((addr & 0xff1f) == 0xd01f) {
108 V(int, sample) = CYCLE_TO_SAMPLE(ast _ cycle);
109 V(int, delta);
110 data &= 8;
111 /* NOT data - ast _ consol; reverse to the POKEY sound */
112 delta = (ast _ consol - data) << DELTA_SHIFT_GTIA;
113 ast _ consol = data;
114 ast _ base_pokey.delta_buffer[sample] += delta;
115 ast _ extra_pokey.delta_buffer[sample] += delta;
116 }
117 else
118 dPutByte(addr, data);
119}
120
121#endif /* ASAP_ONLY_INFO */
122
123#define UWORD(array, index) (UBYTE(array[index]) + (UBYTE(array[(index) + 1]) << 8))
124
125#ifndef ASAP_ONLY_SAP
126
127#ifndef ASAP_ONLY_INFO
128
129#ifndef JAVA
130#include "players.h"
131#endif
132
133#define CMR_BASS_TABLE_OFFSET 0x70f
134
135CONST_ARRAY(byte, cmr_bass_table)
136 0x5C, 0x56, 0x50, 0x4D, 0x47, 0x44, 0x41, 0x3E,
137 0x38, 0x35, CAST(byte) (0x88), 0x7F, 0x79, 0x73, 0x6C, 0x67,
138 0x60, 0x5A, 0x55, 0x51, 0x4C, 0x48, 0x43, 0x3F,
139 0x3D, 0x39, 0x34, 0x33, 0x30, 0x2D, 0x2A, 0x28,
140 0x25, 0x24, 0x21, 0x1F, 0x1E
141END_CONST_ARRAY;
142
143#endif /* ASAP_ONLY_INFO */
144
145CONST_ARRAY(int, perframe2fastplay)
146 312, 312 / 2, 312 / 3, 312 / 4
147END_CONST_ARRAY;
148
149/* Loads native module (anything except SAP) and 6502 player routine. */
150PRIVATE FUNC(abool, load_native, (
151 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
152 P(CONST BYTEARRAY, module), P(int, module_len), P(RESOURCE, player)))
153{
154#ifndef ASAP_ONLY_INFO
155 V(int, player_last_byte);
156#endif
157 V(int, music_last_byte);
158 V(int, block_len);
159 if ((UBYTE(module[0]) != 0xff || UBYTE(module[1]) != 0xff)
160 && (module[0] != 0 || module[1] != 0)) /* some CMC and clones start with zeros */
161 return FALSE;
162 module_info _ music = UWORD(module, 2);
163#ifndef ASAP_ONLY_INFO
164 module_info _ player = UWORD(player, 2);
165 player_last_byte = UWORD(player, 4);
166 if (module_info _ music <= player_last_byte)
167 return FALSE;
168#endif
169 music_last_byte = UWORD(module, 4);
170 if (module_info _ music <= 0xd7ff && music_last_byte >= 0xd000)
171 return FALSE;
172 block_len = music_last_byte + 1 - module_info _ music;
173 if (6 + block_len != module_len) {
174 V(int, info_addr);
175 V(int, info_len);
176 if (module_info _ type != ASAP_TYPE_RMT || 11 + block_len > module_len)
177 return FALSE;
178 /* allow optional info for Raster Music Tracker */
179 info_addr = UWORD(module, 6 + block_len);
180 if (info_addr != module_info _ music + block_len)
181 return FALSE;
182 info_len = UWORD(module, 8 + block_len) + 1 - info_addr;
183 if (10 + block_len + info_len != module_len)
184 return FALSE;
185 }
186#ifndef ASAP_ONLY_INFO
187 if (ast != NULL) {
188 COPY_ARRAY(ast _ memory, module_info _ music, module, 6, block_len);
189 COPY_ARRAY(ast _ memory, module_info _ player, player, 6, player_last_byte + 1 - module_info _ player);
190 }
191#endif
192 return TRUE;
193}
194
195PRIVATE FUNC(void, set_song_duration, (P(ASAP_ModuleInfo PTR, module_info), P(int, player_calls)))
196{
197 module_info _ durations[module_info _ songs] = TO_INT(player_calls * module_info _ fastplay * 114000.0 / 1773447);
198 module_info _ songs++;
199}
200
201#define SEEN_THIS_CALL 1
202#define SEEN_BEFORE 2
203#define SEEN_REPEAT 3
204
205PRIVATE FUNC(void, parse_cmc_song, (P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module), P(int, pos)))
206{
207 V(int, tempo) = UBYTE(module[0x19]);
208 V(int, player_calls) = 0;
209 V(int, rep_start_pos) = 0;
210 V(int, rep_end_pos) = 0;
211 V(int, rep_times) = 0;
212 NEW_ARRAY(byte, seen, 0x55);
213 INIT_ARRAY(seen);
214 while (pos >= 0 && pos < 0x55) {
215 V(int, p1);
216 V(int, p2);
217 V(int, p3);
218 if (pos == rep_end_pos && rep_times > 0) {
219 for (p1 = 0; p1 < 0x55; p1++)
220 if (seen[p1] == SEEN_THIS_CALL || seen[p1] == SEEN_REPEAT)
221 seen[p1] = 0;
222 rep_times--;
223 pos = rep_start_pos;
224 }
225 if (seen[pos] != 0) {
226 if (seen[pos] != SEEN_THIS_CALL)
227 module_info _ loops[module_info _ songs] = TRUE;
228 break;
229 }
230 seen[pos] = SEEN_THIS_CALL;
231 p1 = UBYTE(module[0x206 + pos]);
232 p2 = UBYTE(module[0x25b + pos]);
233 p3 = UBYTE(module[0x2b0 + pos]);
234 if (p1 == 0xfe || p2 == 0xfe || p3 == 0xfe) {
235 pos++;
236 continue;
237 }
238 p1 >>= 4;
239 if (p1 == 8)
240 break;
241 if (p1 == 9) {
242 pos = p2;
243 continue;
244 }
245 if (p1 == 0xa) {
246 pos -= p2;
247 continue;
248 }
249 if (p1 == 0xb) {
250 pos += p2;
251 continue;
252 }
253 if (p1 == 0xc) {
254 tempo = p2;
255 pos++;
256 continue;
257 }
258 if (p1 == 0xd) {
259 pos++;
260 rep_start_pos = pos;
261 rep_end_pos = pos + p2;
262 rep_times = p3 - 1;
263 continue;
264 }
265 if (p1 == 0xe) {
266 module_info _ loops[module_info _ songs] = TRUE;
267 break;
268 }
269 p2 = rep_times > 0 ? SEEN_REPEAT : SEEN_BEFORE;
270 for (p1 = 0; p1 < 0x55; p1++)
271 if (seen[p1] == SEEN_THIS_CALL)
272 seen[p1] = CAST(byte) p2;
273 player_calls += tempo * (module_info _ type == ASAP_TYPE_CM3 ? 48 : 64);
274 pos++;
275 }
276 set_song_duration(module_info, player_calls);
277}
278
279PRIVATE FUNC(abool, parse_cmc, (
280 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
281 P(CONST BYTEARRAY, module), P(int, module_len), P(int, type), P(RESOURCE, player)))
282{
283 V(int, last_pos);
284 V(int, pos);
285 if (module_len < 0x306)
286 return FALSE;
287 module_info _ type = type;
288 if (!load_native(ast, module_info, module, module_len, player))
289 return FALSE;
290#ifndef ASAP_ONLY_INFO
291 if (ast != NULL && type == ASAP_TYPE_CMR)
292 COPY_ARRAY(ast _ memory, 0x500 + CMR_BASS_TABLE_OFFSET, cmr_bass_table, 0, sizeof(cmr_bass_table));
293#endif
294 last_pos = 0x54;
295 while (--last_pos >= 0) {
296 if (UBYTE(module[0x206 + last_pos]) < 0xb0
297 || UBYTE(module[0x25b + last_pos]) < 0x40
298 || UBYTE(module[0x2b0 + last_pos]) < 0x40)
299 break;
300 if (module_info _ channels == 2) {
301 if (UBYTE(module[0x306 + last_pos]) < 0xb0
302 || UBYTE(module[0x35b + last_pos]) < 0x40
303 || UBYTE(module[0x3b0 + last_pos]) < 0x40)
304 break;
305 }
306 }
307 module_info _ songs = 0;
308 parse_cmc_song(module_info, module, 0);
309 for (pos = 0; pos < last_pos && module_info _ songs < ASAP_SONGS_MAX; pos++)
310 if (UBYTE(module[0x206 + pos]) == 0x8f || UBYTE(module[0x206 + pos]) == 0xef)
311 parse_cmc_song(module_info, module, pos + 1);
312 return TRUE;
313}
314
315PRIVATE FUNC(abool, is_dlt_track_empty, (P(CONST BYTEARRAY, module), P(int, pos)))
316{
317 return UBYTE(module[0x2006 + pos]) >= 0x43
318 && UBYTE(module[0x2106 + pos]) >= 0x40
319 && UBYTE(module[0x2206 + pos]) >= 0x40
320 && UBYTE(module[0x2306 + pos]) >= 0x40;
321}
322
323PRIVATE FUNC(abool, is_dlt_pattern_end, (P(CONST BYTEARRAY, module), P(int, pos), P(int, i)))
324{
325 V(int, ch);
326 for (ch = 0; ch < 4; ch++) {
327 V(int, pattern) = UBYTE(module[0x2006 + (ch << 8) + pos]);
328 if (pattern < 64) {
329 V(int, offset) = 6 + (pattern << 7) + (i << 1);
330 if ((module[offset] & 0x80) == 0 && (module[offset + 1] & 0x80) != 0)
331 return TRUE;
332 }
333 }
334 return FALSE;
335}
336
337PRIVATE FUNC(void, parse_dlt_song, (
338 P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module),
339 P(BOOLARRAY, seen), P(int, pos)))
340{
341 V(int, player_calls) = 0;
342 V(abool, loop) = FALSE;
343 V(int, tempo) = 6;
344 while (pos < 128 && !seen[pos] && is_dlt_track_empty(module, pos))
345 seen[pos++] = TRUE;
346 module_info _ song_pos[module_info _ songs] = CAST(byte) pos;
347 while (pos < 128) {
348 V(int, p1);
349 if (seen[pos]) {
350 loop = TRUE;
351 break;
352 }
353 seen[pos] = TRUE;
354 p1 = module[0x2006 + pos];
355 if (p1 == 0x40 || is_dlt_track_empty(module, pos))
356 break;
357 if (p1 == 0x41)
358 pos = UBYTE(module[0x2086 + pos]);
359 else if (p1 == 0x42)
360 tempo = UBYTE(module[0x2086 + pos++]);
361 else {
362 V(int, i);
363 for (i = 0; i < 64 && !is_dlt_pattern_end(module, pos, i); i++)
364 player_calls += tempo;
365 pos++;
366 }
367 }
368 if (player_calls > 0) {
369 module_info _ loops[module_info _ songs] = loop;
370 set_song_duration(module_info, player_calls);
371 }
372}
373
374PRIVATE FUNC(abool, parse_dlt, (
375 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
376 P(CONST BYTEARRAY, module), P(int, module_len)))
377{
378 V(int, pos);
379 NEW_ARRAY(abool, seen, 128);
380 if (module_len == 0x2c06) {
381 if (ast != NULL)
382 ast _ memory[0x4c00] = 0;
383 }
384 else if (module_len != 0x2c07)
385 return FALSE;
386 module_info _ type = ASAP_TYPE_DLT;
387 if (!load_native(ast, module_info, module, module_len, GET_PLAYER(dlt))
388 || module_info _ music != 0x2000) {
389 return FALSE;
390 }
391 INIT_ARRAY(seen);
392 module_info _ songs = 0;
393 for (pos = 0; pos < 128 && module_info _ songs < ASAP_SONGS_MAX; pos++) {
394 if (!seen[pos])
395 parse_dlt_song(module_info, module, seen, pos);
396 }
397 return module_info _ songs > 0;
398}
399
400PRIVATE FUNC(void, parse_mpt_song, (
401 P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module),
402 P(BOOLARRAY, global_seen), P(int, song_len), P(int, pos)))
403{
404 V(int, addr_to_offset) = UWORD(module, 2) - 6;
405 V(int, tempo) = UBYTE(module[0x1cf]);
406 V(int, player_calls) = 0;
407 NEW_ARRAY(byte, seen, 256);
408 NEW_ARRAY(int, pattern_offset, 4);
409 NEW_ARRAY(int, blank_rows, 4);
410 NEW_ARRAY(int, blank_rows_counter, 4);
411 INIT_ARRAY(seen);
412 INIT_ARRAY(blank_rows);
413 while (pos < song_len) {
414 V(int, i);
415 V(int, ch);
416 V(int, pattern_rows);
417 if (seen[pos] != 0) {
418 if (seen[pos] != SEEN_THIS_CALL)
419 module_info _ loops[module_info _ songs] = TRUE;
420 break;
421 }
422 seen[pos] = SEEN_THIS_CALL;
423 global_seen[pos] = TRUE;
424 i = UBYTE(module[0x1d0 + pos * 2]);
425 if (i == 0xff) {
426 pos = UBYTE(module[0x1d1 + pos * 2]);
427 continue;
428 }
429 for (ch = 3; ch >= 0; ch--) {
430 i = UBYTE(module[0x1c6 + ch]) + (UBYTE(module[0x1ca + ch]) << 8) - addr_to_offset;
431 i = UBYTE(module[i + pos * 2]);
432 if (i >= 0x40)
433 break;
434 i <<= 1;
435 i = UWORD(module, 0x46 + i);
436 pattern_offset[ch] = i == 0 ? 0 : i - addr_to_offset;
437 blank_rows_counter[ch] = 0;
438 }
439 if (ch >= 0)
440 break;
441 for (i = 0; i < song_len; i++)
442 if (seen[i] == SEEN_THIS_CALL)
443 seen[i] = SEEN_BEFORE;
444 for (pattern_rows = UBYTE(module[0x1ce]); --pattern_rows >= 0; ) {
445 for (ch = 3; ch >= 0; ch--) {
446 if (pattern_offset[ch] == 0 || --blank_rows_counter[ch] >= 0)
447 continue;
448 for (;;) {
449 i = UBYTE(module[pattern_offset[ch]++]);
450 if (i < 0x40 || i == 0xfe)
451 break;
452 if (i < 0x80)
453 continue;
454 if (i < 0xc0) {
455 blank_rows[ch] = i - 0x80;
456 continue;
457 }
458 if (i < 0xd0)
459 continue;
460 if (i < 0xe0) {
461 tempo = i - 0xcf;
462 continue;
463 }
464 pattern_rows = 0;
465 }
466 blank_rows_counter[ch] = blank_rows[ch];
467 }
468 player_calls += tempo;
469 }
470 pos++;
471 }
472 if (player_calls > 0)
473 set_song_duration(module_info, player_calls);
474}
475
476PRIVATE FUNC(abool, parse_mpt, (
477 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
478 P(CONST BYTEARRAY, module), P(int, module_len)))
479{
480 V(int, track0_addr);
481 V(int, pos);
482 V(int, song_len);
483 /* seen[i] == TRUE if the track position i has been processed */
484 NEW_ARRAY(abool, global_seen, 256);
485 if (module_len < 0x1d0)
486 return FALSE;
487 module_info _ type = ASAP_TYPE_MPT;
488 if (!load_native(ast, module_info, module, module_len, GET_PLAYER(mpt)))
489 return FALSE;
490 track0_addr = UWORD(module, 2) + 0x1ca;
491 if (UBYTE(module[0x1c6]) + (UBYTE(module[0x1ca]) << 8) != track0_addr)
492 return FALSE;
493 /* Calculate the length of the first track. Address of the second track minus
494 address of the first track equals the length of the first track in bytes.
495 Divide by two to get number of track positions. */
496 song_len = (UBYTE(module[0x1c7]) + (UBYTE(module[0x1cb]) << 8) - track0_addr) >> 1;
497 if (song_len > 0xfe)
498 return FALSE;
499 INIT_ARRAY(global_seen);
500 module_info _ songs = 0;
501 for (pos = 0; pos < song_len && module_info _ songs < ASAP_SONGS_MAX; pos++) {
502 if (!global_seen[pos]) {
503 module_info _ song_pos[module_info _ songs] = CAST(byte) pos;
504 parse_mpt_song(module_info, module, global_seen, song_len, pos);
505 }
506 }
507 return module_info _ songs > 0;
508}
509
510CONST_ARRAY(byte, rmt_volume_silent)
511 16, 8, 4, 3, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1
512END_CONST_ARRAY;
513
514PRIVATE FUNC(int, rmt_instrument_frames, (
515 P(CONST BYTEARRAY, module), P(int, instrument),
516 P(int, volume), P(int, volume_frame), P(abool, extra_pokey)))
517{
518 V(int, addr_to_offset) = UWORD(module, 2) - 6;
519 V(int, per_frame) = module[0xc];
520 V(int, player_call);
521 V(int, player_calls);
522 V(int, index);
523 V(int, index_end);
524 V(int, index_loop);
525 V(int, volume_slide_depth);
526 V(int, volume_min);
527 V(int, volume_slide);
528 V(abool, silent_loop);
529 instrument = UWORD(module, 0xe) - addr_to_offset + (instrument << 1);
530 if (module[instrument + 1] == 0)
531 return 0;
532 instrument = UWORD(module, instrument) - addr_to_offset;
533 player_calls = player_call = volume_frame * per_frame;
534 index = UBYTE(module[instrument]) + 1 + player_call * 3;
535 index_end = UBYTE(module[instrument + 2]) + 3;
536 index_loop = UBYTE(module[instrument + 3]);
537 if (index_loop >= index_end)
538 return 0; /* error */
539 volume_slide_depth = UBYTE(module[instrument + 6]);
540 volume_min = UBYTE(module[instrument + 7]);
541 if (index >= index_end)
542 index = (index - index_end) % (index_end - index_loop) + index_loop;
543 else {
544 do {
545 V(int, vol) = module[instrument + index];
546 if (extra_pokey)
547 vol >>= 4;
548 if ((vol & 0xf) >= rmt_volume_silent[volume])
549 player_calls = player_call + 1;
550 player_call++;
551 index += 3;
552 } while (index < index_end);
553 }
554 if (volume_slide_depth == 0)
555 return player_calls / per_frame;
556 volume_slide = 128;
557 silent_loop = FALSE;
558 for (;;) {
559 V(int, vol);
560 if (index >= index_end) {
561 if (silent_loop)
562 break;
563 silent_loop = TRUE;
564 index = index_loop;
565 }
566 vol = module[instrument + index];
567 if (extra_pokey)
568 vol >>= 4;
569 if ((vol & 0xf) >= rmt_volume_silent[volume]) {
570 player_calls = player_call + 1;
571 silent_loop = FALSE;
572 }
573 player_call++;
574 index += 3;
575 volume_slide -= volume_slide_depth;
576 if (volume_slide < 0) {
577 volume_slide += 256;
578 if (--volume <= volume_min)
579 break;
580 }
581 }
582 return player_calls / per_frame;
583}
584
585PRIVATE FUNC(void, parse_rmt_song, (
586 P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module),
587 P(BOOLARRAY, global_seen), P(int, song_len), P(int, pos_shift), P(int, pos)))
588{
589 V(int, ch);
590 V(int, addr_to_offset) = UWORD(module, 2) - 6;
591 V(int, tempo) = UBYTE(module[0xb]);
592 V(int, frames) = 0;
593 V(int, song_offset) = UWORD(module, 0x14) - addr_to_offset;
594 V(int, pattern_lo_offset) = UWORD(module, 0x10) - addr_to_offset;
595 V(int, pattern_hi_offset) = UWORD(module, 0x12) - addr_to_offset;
596 V(int, instrument_frames);
597 NEW_ARRAY(byte, seen, 256);
598 NEW_ARRAY(int, pattern_begin, 8);
599 NEW_ARRAY(int, pattern_offset, 8);
600 NEW_ARRAY(int, blank_rows, 8);
601 NEW_ARRAY(int, instrument_no, 8);
602 NEW_ARRAY(int, instrument_frame, 8);
603 NEW_ARRAY(int, volume_value, 8);
604 NEW_ARRAY(int, volume_frame, 8);
605 INIT_ARRAY(seen);
606 INIT_ARRAY(instrument_no);
607 INIT_ARRAY(instrument_frame);
608 INIT_ARRAY(volume_value);
609 INIT_ARRAY(volume_frame);
610 while (pos < song_len) {
611 V(int, i);
612 V(int, pattern_rows);
613 if (seen[pos] != 0) {
614 if (seen[pos] != SEEN_THIS_CALL)
615 module_info _ loops[module_info _ songs] = TRUE;
616 break;
617 }
618 seen[pos] = SEEN_THIS_CALL;
619 global_seen[pos] = TRUE;
620 if (UBYTE(module[song_offset + (pos << pos_shift)]) == 0xfe) {
621 pos = UBYTE(module[song_offset + (pos << pos_shift) + 1]);
622 continue;
623 }
624 for (ch = 0; ch < 1 << pos_shift; ch++) {
625 i = UBYTE(module[song_offset + (pos << pos_shift) + ch]);
626 if (i == 0xff)
627 blank_rows[ch] = 256;
628 else {
629 pattern_offset[ch] = pattern_begin[ch] = UBYTE(module[pattern_lo_offset + i])
630 + (UBYTE(module[pattern_hi_offset + i]) << 8) - addr_to_offset;
631 blank_rows[ch] = 0;
632 }
633 }
634 for (i = 0; i < song_len; i++)
635 if (seen[i] == SEEN_THIS_CALL)
636 seen[i] = SEEN_BEFORE;
637 for (pattern_rows = UBYTE(module[0xa]); --pattern_rows >= 0; ) {
638 for (ch = 0; ch < 1 << pos_shift; ch++) {
639 if (--blank_rows[ch] > 0)
640 continue;
641 for (;;) {
642 i = UBYTE(module[pattern_offset[ch]++]);
643 if ((i & 0x3f) < 62) {
644 i += UBYTE(module[pattern_offset[ch]++]) << 8;
645 if ((i & 0x3f) != 61) {
646 instrument_no[ch] = i >> 10;
647 instrument_frame[ch] = frames;
648 }
649 volume_value[ch] = (i >> 6) & 0xf;
650 volume_frame[ch] = frames;
651 break;
652 }
653 if (i == 62) {
654 blank_rows[ch] = UBYTE(module[pattern_offset[ch]++]);
655 break;
656 }
657 if ((i & 0x3f) == 62) {
658 blank_rows[ch] = i >> 6;
659 break;
660 }
661 if ((i & 0xbf) == 63) {
662 tempo = UBYTE(module[pattern_offset[ch]++]);
663 continue;
664 }
665 if (i == 0xbf) {
666 pattern_offset[ch] = pattern_begin[ch] + UBYTE(module[pattern_offset[ch]]);
667 continue;
668 }
669 /* assert(i == 0xff); */
670 pattern_rows = -1;
671 break;
672 }
673 if (pattern_rows < 0)
674 break;
675 }
676 if (pattern_rows >= 0)
677 frames += tempo;
678 }
679 pos++;
680 }
681 instrument_frames = 0;
682 for (ch = 0; ch < 1 << pos_shift; ch++) {
683 V(int, frame) = instrument_frame[ch];
684 frame += rmt_instrument_frames(module, instrument_no[ch], volume_value[ch], volume_frame[ch] - frame, ch >= 4);
685 if (instrument_frames < frame)
686 instrument_frames = frame;
687 }
688 if (frames > instrument_frames) {
689 if (frames - instrument_frames > 100)
690 module_info _ loops[module_info _ songs] = FALSE;
691 frames = instrument_frames;
692 }
693 if (frames > 0)
694 set_song_duration(module_info, frames);
695}
696
697PRIVATE FUNC(abool, parse_rmt, (
698 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
699 P(CONST BYTEARRAY, module), P(int, module_len)))
700{
701 V(int, per_frame);
702 V(int, pos_shift);
703 V(int, song_len);
704 V(int, pos);
705 NEW_ARRAY(abool, global_seen, 256);
706 if (module_len < 0x30 || module[6] != CHARCODE('R') || module[7] != CHARCODE('M')
707 || module[8] != CHARCODE('T') || module[0xd] != 1)
708 return FALSE;
709 switch (CAST(char) module[9]) {
710 case CHARCODE('4'):
711 pos_shift = 2;
712 break;
713 case CHARCODE('8'):
714 module_info _ channels = 2;
715 pos_shift = 3;
716 break;
717 default:
718 return FALSE;
719 }
720 per_frame = module[0xc];
721 if (per_frame < 1 || per_frame > 4)
722 return FALSE;
723 module_info _ type = ASAP_TYPE_RMT;
724 if (!load_native(ast, module_info, module, module_len,
725 module_info _ channels == 2 ? GET_PLAYER(rmt8) : GET_PLAYER(rmt4)))
726 return FALSE;
727 song_len = UWORD(module, 4) + 1 - UWORD(module, 0x14);
728 if (pos_shift == 3 && (song_len & 4) != 0
729 && UBYTE(module[6 + UWORD(module, 4) - UWORD(module, 2) - 3]) == 0xfe)
730 song_len += 4;
731 song_len >>= pos_shift;
732 if (song_len >= 0x100)
733 return FALSE;
734 INIT_ARRAY(global_seen);
735 module_info _ songs = 0;
736 for (pos = 0; pos < song_len && module_info _ songs < ASAP_SONGS_MAX; pos++) {
737 if (!global_seen[pos]) {
738 module_info _ song_pos[module_info _ songs] = CAST(byte) pos;
739 parse_rmt_song(module_info, module, global_seen, song_len, pos_shift, pos);
740 }
741 }
742 /* must set fastplay after song durations calculations, so they assume 312 */
743 module_info _ fastplay = perframe2fastplay[per_frame - 1];
744 module_info _ player = 0x600;
745 return module_info _ songs > 0;
746}
747
748PRIVATE FUNC(void, parse_tmc_song, (
749 P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module), P(int, pos)))
750{
751 V(int, addr_to_offset) = UWORD(module, 2) - 6;
752 V(int, tempo) = UBYTE(module[0x24]) + 1;
753 V(int, frames) = 0;
754 NEW_ARRAY(int, pattern_offset, 8);
755 NEW_ARRAY(int, blank_rows, 8);
756 while (UBYTE(module[0x1a6 + 15 + pos]) < 0x80) {
757 V(int, ch);
758 V(int, pattern_rows);
759 for (ch = 7; ch >= 0; ch--) {
760 V(int, pat) = UBYTE(module[0x1a6 + 15 + pos - 2 * ch]);
761 pattern_offset[ch] = UBYTE(module[0xa6 + pat]) + (UBYTE(module[0x126 + pat]) << 8) - addr_to_offset;
762 blank_rows[ch] = 0;
763 }
764 for (pattern_rows = 64; --pattern_rows >= 0; ) {
765 for (ch = 7; ch >= 0; ch--) {
766 if (--blank_rows[ch] >= 0)
767 continue;
768 for (;;) {
769 V(int, i) = UBYTE(module[pattern_offset[ch]++]);
770 if (i < 0x40) {
771 pattern_offset[ch]++;
772 break;
773 }
774 if (i == 0x40) {
775 i = UBYTE(module[pattern_offset[ch]++]);
776 if ((i & 0x7f) == 0)
777 pattern_rows = 0;
778 else
779 tempo = (i & 0x7f) + 1;
780 if (i >= 0x80)
781 pattern_offset[ch]++;
782 break;
783 }
784 if (i < 0x80) {
785 i = module[pattern_offset[ch]++] & 0x7f;
786 if (i == 0)
787 pattern_rows = 0;
788 else
789 tempo = i + 1;
790 pattern_offset[ch]++;
791 break;
792 }
793 if (i < 0xc0)
794 continue;
795 blank_rows[ch] = i - 0xbf;
796 break;
797 }
798 }
799 frames += tempo;
800 }
801 pos += 16;
802 }
803 if (UBYTE(module[0x1a6 + 14 + pos]) < 0x80)
804 module_info _ loops[module_info _ songs] = TRUE;
805 set_song_duration(module_info, frames);
806}
807
808PRIVATE FUNC(abool, parse_tmc, (
809 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
810 P(CONST BYTEARRAY, module), P(int, module_len)))
811{
812 V(int, i);
813 V(int, last_pos);
814 if (module_len < 0x1d0)
815 return FALSE;
816 module_info _ type = ASAP_TYPE_TMC;
817 if (!load_native(ast, module_info, module, module_len, GET_PLAYER(tmc)))
818 return FALSE;
819 module_info _ channels = 2;
820 i = 0;
821 /* find first instrument */
822 while (module[0x66 + i] == 0) {
823 if (++i >= 64)
824 return FALSE; /* no instrument */
825 }
826 last_pos = (UBYTE(module[0x66 + i]) << 8) + UBYTE(module[0x26 + i])
827 - UWORD(module, 2) - 0x1b0;
828 if (0x1b5 + last_pos >= module_len)
829 return FALSE;
830 /* skip trailing jumps */
831 do {
832 if (last_pos <= 0)
833 return FALSE; /* no pattern to play */
834 last_pos -= 16;
835 } while (UBYTE(module[0x1b5 + last_pos]) >= 0x80);
836 module_info _ songs = 0;
837 parse_tmc_song(module_info, module, 0);
838 for (i = 0; i < last_pos && module_info _ songs < ASAP_SONGS_MAX; i += 16)
839 if (UBYTE(module[0x1b5 + i]) >= 0x80)
840 parse_tmc_song(module_info, module, i + 16);
841 /* must set fastplay after song durations calculations, so they assume 312 */
842 i = module[0x25];
843 if (i < 1 || i > 4)
844 return FALSE;
845 if (ast != NULL)
846 ast _ tmc_per_frame = module[0x25];
847 module_info _ fastplay = perframe2fastplay[i - 1];
848 return TRUE;
849}
850
851PRIVATE FUNC(void, parse_tm2_song, (
852 P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module), P(int, pos)))
853{
854 V(int, addr_to_offset) = UWORD(module, 2) - 6;
855 V(int, tempo) = UBYTE(module[0x24]) + 1;
856 V(int, player_calls) = 0;
857 NEW_ARRAY(int, pattern_offset, 8);
858 NEW_ARRAY(int, blank_rows, 8);
859 for (;;) {
860 V(int, ch);
861 V(int, pattern_rows) = UBYTE(module[0x386 + 16 + pos]);
862 if (pattern_rows == 0)
863 break;
864 if (pattern_rows >= 0x80) {
865 module_info _ loops[module_info _ songs] = TRUE;
866 break;
867 }
868 for (ch = 7; ch >= 0; ch--) {
869 V(int, pat) = UBYTE(module[0x386 + 15 + pos - 2 * ch]);
870 pattern_offset[ch] = UBYTE(module[0x106 + pat]) + (UBYTE(module[0x206 + pat]) << 8) - addr_to_offset;
871 blank_rows[ch] = 0;
872 }
873 while (--pattern_rows >= 0) {
874 for (ch = 7; ch >= 0; ch--) {
875 if (--blank_rows[ch] >= 0)
876 continue;
877 for (;;) {
878 V(int, i) = UBYTE(module[pattern_offset[ch]++]);
879 if (i == 0) {
880 pattern_offset[ch]++;
881 break;
882 }
883 if (i < 0x40) {
884 if (UBYTE(module[pattern_offset[ch]++]) >= 0x80)
885 pattern_offset[ch]++;
886 break;
887 }
888 if (i < 0x80) {
889 pattern_offset[ch]++;
890 break;
891 }
892 if (i == 0x80) {
893 blank_rows[ch] = UBYTE(module[pattern_offset[ch]++]);
894 break;
895 }
896 if (i < 0xc0)
897 break;
898 if (i < 0xd0) {
899 tempo = i - 0xbf;
900 continue;
901 }
902 if (i < 0xe0) {
903 pattern_offset[ch]++;
904 break;
905 }
906 if (i < 0xf0) {
907 pattern_offset[ch] += 2;
908 break;
909 }
910 if (i < 0xff) {
911 blank_rows[ch] = i - 0xf0;
912 break;
913 }
914 blank_rows[ch] = 64;
915 break;
916 }
917 }
918 player_calls += tempo;
919 }
920 pos += 17;
921 }
922 set_song_duration(module_info, player_calls);
923}
924
925PRIVATE FUNC(abool, parse_tm2, (
926 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
927 P(CONST BYTEARRAY, module), P(int, module_len)))
928{
929 V(int, i);
930 V(int, last_pos);
931 V(int, c);
932 if (module_len < 0x3a4)
933 return FALSE;
934 module_info _ type = ASAP_TYPE_TM2;
935 if (!load_native(ast, module_info, module, module_len, GET_PLAYER(tm2)))
936 return FALSE;
937 i = module[0x25];
938 if (i < 1 || i > 4)
939 return FALSE;
940 module_info _ fastplay = perframe2fastplay[i - 1];
941 module_info _ player = 0x500;
942 if (module[0x1f] != 0)
943 module_info _ channels = 2;
944 last_pos = 0xffff;
945 for (i = 0; i < 0x80; i++) {
946 V(int, instr_addr) = UBYTE(module[0x86 + i]) + (UBYTE(module[0x306 + i]) << 8);
947 if (instr_addr != 0 && instr_addr < last_pos)
948 last_pos = instr_addr;
949 }
950 for (i = 0; i < 0x100; i++) {
951 V(int, pattern_addr) = UBYTE(module[0x106 + i]) + (UBYTE(module[0x206 + i]) << 8);
952 if (pattern_addr != 0 && pattern_addr < last_pos)
953 last_pos = pattern_addr;
954 }
955 last_pos -= UWORD(module, 2) + 0x380;
956 if (0x386 + last_pos >= module_len)
957 return FALSE;
958 /* skip trailing stop/jump commands */
959 do {
960 if (last_pos <= 0)
961 return FALSE;
962 last_pos -= 17;
963 c = UBYTE(module[0x386 + 16 + last_pos]);
964 } while (c == 0 || c >= 0x80);
965 module_info _ songs = 0;
966 parse_tm2_song(module_info, module, 0);
967 for (i = 0; i < last_pos && module_info _ songs < ASAP_SONGS_MAX; i += 17) {
968 c = UBYTE(module[0x386 + 16 + i]);
969 if (c == 0 || c >= 0x80)
970 parse_tm2_song(module_info, module, i + 17);
971 }
972 return TRUE;
973}
974
975#endif /* ASAP_ONLY_SAP */
976
977PRIVATE FUNC(abool, has_string_at, (P(CONST BYTEARRAY, module), P(int, module_index), P(STRING, s)))
978{
979 V(int, i);
980 V(int, n) = strlen(s);
981 for (i = 0; i < n; i++)
982 if (module[module_index + i] != CHARCODEAT(s, i))
983 return FALSE;
984 return TRUE;
985}
986
987PRIVATE FUNC(STRING, parse_text, (P(OUT_STRING, dest), P(CONST BYTEARRAY, module), P(int, module_index)))
988{
989 V(int, i);
990 if (module[module_index] != CHARCODE('"'))
991 return NULL;
992 if (has_string_at(module, module_index + 1, "<?>\""))
993 return dest;
994 for (i = 0; ; i++) {
995 V(int, c) = module[module_index + 1 + i];
996 if (c == CHARCODE('"'))
997 break;
998 if (c < 32 || c >= 127)
999 return NULL;
1000 }
1001 BYTES_TO_STRING(dest, module, module_index + 1, i);
1002 return dest;
1003}
1004
1005PRIVATE FUNC(int, parse_dec, (P(CONST BYTEARRAY, module), P(int, module_index), P(int, maxval)))
1006{
1007 V(int, r);
1008 if (module[module_index] == 0xd)
1009 return -1;
1010 for (r = 0;;) {
1011 V(int, c) = module[module_index++];
1012 if (c == 0xd)
1013 break;
1014 if (c < CHARCODE('0') || c > CHARCODE('9'))
1015 return -1;
1016 r = 10 * r + c - 48;
1017 if (r > maxval)
1018 return -1;
1019 }
1020 return r;
1021}
1022
1023PRIVATE FUNC(int, parse_hex, (P(CONST BYTEARRAY, module), P(int, module_index)))
1024{
1025 V(int, r);
1026 if (module[module_index] == 0xd)
1027 return -1;
1028 for (r = 0;;) {
1029 V(int, c) = module[module_index++];
1030 if (c == 0xd)
1031 break;
1032 if (r > 0xfff)
1033 return -1;
1034 r <<= 4;
1035 if (c >= CHARCODE('0') && c <= CHARCODE('9'))
1036 r += c - CHARCODE('0');
1037 else if (c >= CHARCODE('A') && c <= CHARCODE('F'))
1038 r += c - CHARCODE('A') + 10;
1039 else if (c >= CHARCODE('a') && c <= CHARCODE('f'))
1040 r += c - CHARCODE('a') + 10;
1041 else
1042 return -1;
1043 }
1044 return r;
1045}
1046
1047FUNC(int, ASAP_ParseDuration, (P(STRING, s)))
1048{
1049 V(int, i) = 0;
1050 V(int, r);
1051 V(int, d);
1052 V(int, n) = strlen(s);
1053#define PARSE_DIGIT(maxdig, retifnot) \
1054 if (i >= n) \
1055 return retifnot; \
1056 d = CHARCODEAT(s, i) - 48; \
1057 if (d < 0 || d > maxdig) \
1058 return -1; \
1059 i++;
1060
1061 PARSE_DIGIT(9, -1);
1062 r = d;
1063 if (i < n) {
1064 d = CHARCODEAT(s, i) - 48;
1065 if (d >= 0 && d <= 9) {
1066 i++;
1067 r = 10 * r + d;
1068 }
1069 if (i < n && CHARAT(s, i) == ':') {
1070 i++;
1071 PARSE_DIGIT(5, -1);
1072 r = (6 * r + d) * 10;
1073 PARSE_DIGIT(9, -1);
1074 r += d;
1075 }
1076 }
1077 r *= 1000;
1078 if (i >= n)
1079 return r;
1080 if (CHARAT(s, i) != '.')
1081 return -1;
1082 i++;
1083 PARSE_DIGIT(9, -1);
1084 r += 100 * d;
1085 PARSE_DIGIT(9, r);
1086 r += 10 * d;
1087 PARSE_DIGIT(9, r);
1088 r += d;
1089 return r;
1090}
1091
1092PRIVATE FUNC(abool, parse_sap_header, (
1093 P(ASAP_ModuleInfo PTR, module_info), P(CONST BYTEARRAY, module), P(int, module_len)))
1094{
1095 V(int, module_index);
1096 V(int, type) = 0;
1097 V(int, duration_index) = 0;
1098 if (!has_string_at(module, 0, "SAP\r\n"))
1099 return FALSE;
1100 module_info _ fastplay = -1;
1101 module_index = 5;
1102 while (UBYTE(module[module_index]) != 0xff) {
1103 if (module_index + 8 >= module_len)
1104 return FALSE;
1105#define TAG_IS(s) has_string_at(module, module_index, s)
1106#ifdef C
1107#define SET_TEXT(v, i) if (parse_text(v, module, module_index + i) == NULL) return FALSE
1108#else
1109#define SET_TEXT(v, i) v = parse_text(v, module, module_index + i); if (v == NULL) return FALSE
1110#endif
1111#define SET_DEC(v, i, min, max) v = parse_dec(module, module_index + i, max); if (v < min) return FALSE
1112#define SET_HEX(v, i) v = parse_hex(module, module_index + i)
1113 if (TAG_IS("AUTHOR ")) {
1114 SET_TEXT(module_info _ author, 7);
1115 }
1116 else if (TAG_IS("NAME ")) {
1117 SET_TEXT(module_info _ name, 5);
1118 }
1119 else if (TAG_IS("DATE ")) {
1120 SET_TEXT(module_info _ date, 5);
1121 }
1122 else if (TAG_IS("SONGS ")) {
1123 SET_DEC(module_info _ songs, 6, 1, ASAP_SONGS_MAX);
1124 }
1125 else if (TAG_IS("DEFSONG ")) {
1126 SET_DEC(module_info _ default_song, 8, 0, ASAP_SONGS_MAX - 1);
1127 }
1128 else if (TAG_IS("STEREO\r"))
1129 module_info _ channels = 2;
1130 else if (TAG_IS("NTSC\r"))
1131 module_info _ ntsc = TRUE;
1132 else if (TAG_IS("TIME ")) {
1133 V(int, i);
1134#ifdef C
1135 char s[ASAP_DURATION_CHARS];
1136#else
1137 V(STRING, s);
1138#endif
1139 module_index += 5;
1140 for (i = 0; module[module_index + i] != 0xd; i++) { }
1141 if (i > 5 && has_string_at(module, module_index + i - 5, " LOOP")) {
1142 module_info _ loops[duration_index] = TRUE;
1143 i -= 5;
1144 }
1145#ifdef C
1146 if (i >= ASAP_DURATION_CHARS)
1147 return FALSE;
1148#endif
1149 BYTES_TO_STRING(s, module, module_index, i);
1150 i = ASAP_ParseDuration(s);
1151 if (i < 0 || duration_index >= ASAP_SONGS_MAX)
1152 return FALSE;
1153 module_info _ durations[duration_index++] = i;
1154 }
1155 else if (TAG_IS("TYPE "))
1156 type = module[module_index + 5];
1157 else if (TAG_IS("FASTPLAY ")) {
1158 SET_DEC(module_info _ fastplay, 9, 1, 312);
1159 }
1160 else if (TAG_IS("MUSIC ")) {
1161 SET_HEX(module_info _ music, 6);
1162 }
1163 else if (TAG_IS("INIT ")) {
1164 SET_HEX(module_info _ init, 5);
1165 }
1166 else if (TAG_IS("PLAYER ")) {
1167 SET_HEX(module_info _ player, 7);
1168 }
1169 else if (TAG_IS("COVOX ")) {
1170 SET_HEX(module_info _ covox_addr, 6);
1171 if (module_info _ covox_addr != 0xd600)
1172 return FALSE;
1173 module_info _ channels = 2;
1174 }
1175
1176 while (module[module_index++] != 0x0d) {
1177 if (module_index >= module_len)
1178 return FALSE;
1179 }
1180 if (module[module_index++] != 0x0a)
1181 return FALSE;
1182 }
1183 if (module_info _ default_song >= module_info _ songs)
1184 return FALSE;
1185 switch (type) {
1186 case CHARCODE('B'):
1187 if (module_info _ player < 0 || module_info _ init < 0)
1188 return FALSE;
1189 module_info _ type = ASAP_TYPE_SAP_B;
1190 break;
1191 case CHARCODE('C'):
1192 if (module_info _ player < 0 || module_info _ music < 0)
1193 return FALSE;
1194 module_info _ type = ASAP_TYPE_SAP_C;
1195 break;
1196 case CHARCODE('D'):
1197 if (module_info _ init < 0)
1198 return FALSE;
1199 module_info _ type = ASAP_TYPE_SAP_D;
1200 break;
1201 case CHARCODE('S'):
1202 if (module_info _ init < 0)
1203 return FALSE;
1204 module_info _ type = ASAP_TYPE_SAP_S;
1205 module_info _ fastplay = 78;
1206 break;
1207 default:
1208 return FALSE;
1209 }
1210 if (module_info _ fastplay < 0)
1211 module_info _ fastplay = module_info _ ntsc ? 262 : 312;
1212 else if (module_info _ ntsc && module_info _ fastplay > 262)
1213 return FALSE;
1214 if (UBYTE(module[module_index + 1]) != 0xff)
1215 return FALSE;
1216 module_info _ header_len = module_index;
1217 return TRUE;
1218}
1219
1220PRIVATE FUNC(abool, parse_sap, (
1221 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
1222 P(CONST BYTEARRAY, module), P(int, module_len)))
1223{
1224 V(int, module_index);
1225 if (!parse_sap_header(module_info, module, module_len))
1226 return FALSE;
1227 if (ast == NULL)
1228 return TRUE;
1229 ZERO_ARRAY(ast _ memory);
1230 module_index = module_info _ header_len + 2;
1231 while (module_index + 5 <= module_len) {
1232 V(int, start_addr) = UWORD(module, module_index);
1233 V(int, block_len) = UWORD(module, module_index + 2) + 1 - start_addr;
1234 if (block_len <= 0 || module_index + block_len > module_len)
1235 return FALSE;
1236 module_index += 4;
1237 COPY_ARRAY(ast _ memory, start_addr, module, module_index, block_len);
1238 module_index += block_len;
1239 if (module_index == module_len)
1240 return TRUE;
1241 if (module_index + 7 <= module_len
1242 && UBYTE(module[module_index]) == 0xff && UBYTE(module[module_index + 1]) == 0xff)
1243 module_index += 2;
1244 }
1245 return FALSE;
1246}
1247
1248#define ASAP_EXT(c1, c2, c3) ((CHARCODE(c1) + (CHARCODE(c2) << 8) + (CHARCODE(c3) << 16)) | 0x202020)
1249
1250PRIVATE FUNC(int, get_packed_ext, (P(STRING, filename)))
1251{
1252 V(int, i) = strlen(filename);
1253 V(int, ext) = 0;
1254 while (--i > 0) {
1255 V(char, c) = CHARAT(filename, i);
1256 if (c <= ' ' || c > 'z')
1257 return 0;
1258 if (c == '.')
1259 return ext | 0x202020;
1260 ext = (ext << 8) + CHARCODE(c);
1261 }
1262 return 0;
1263}
1264
1265PRIVATE FUNC(abool, is_our_ext, (P(int, ext)))
1266{
1267 switch (ext) {
1268 case ASAP_EXT('S', 'A', 'P'):
1269#ifndef ASAP_ONLY_SAP
1270 case ASAP_EXT('C', 'M', 'C'):
1271 case ASAP_EXT('C', 'M', '3'):
1272 case ASAP_EXT('C', 'M', 'R'):
1273 case ASAP_EXT('C', 'M', 'S'):
1274 case ASAP_EXT('D', 'M', 'C'):
1275 case ASAP_EXT('D', 'L', 'T'):
1276 case ASAP_EXT('M', 'P', 'T'):
1277 case ASAP_EXT('M', 'P', 'D'):
1278 case ASAP_EXT('R', 'M', 'T'):
1279 case ASAP_EXT('T', 'M', 'C'):
1280 case ASAP_EXT('T', 'M', '8'):
1281 case ASAP_EXT('T', 'M', '2'):
1282#endif
1283 return TRUE;
1284 default:
1285 return FALSE;
1286 }
1287}
1288
1289FUNC(abool, ASAP_IsOurFile, (P(STRING, filename)))
1290{
1291 V(int, ext) = get_packed_ext(filename);
1292 return is_our_ext(ext);
1293}
1294
1295FUNC(abool, ASAP_IsOurExt, (P(STRING, ext)))
1296{
1297 return strlen(ext) == 3
1298 && is_our_ext(ASAP_EXT(CHARAT(ext, 0), CHARAT(ext, 1), CHARAT(ext, 2)));
1299}
1300
1301PRIVATE FUNC(abool, parse_file, (
1302 P(ASAP_State PTR, ast), P(ASAP_ModuleInfo PTR, module_info),
1303 P(STRING, filename), P(CONST BYTEARRAY, module), P(int, module_len)))
1304{
1305 V(int, i);
1306 V(int, len) = strlen(filename);
1307 V(int, basename) = 0;
1308 V(int, ext) = -1;
1309 for (i = 0; i < len; i++) {
1310 V(char, c) = CHARAT(filename, i);
1311 if (c == '/' || c == '\\') {
1312 basename = i + 1;
1313 ext = -1;
1314 }
1315 else if (c == '.')
1316 ext = i;
1317 }
1318 if (ext < 0)
1319 return FALSE;
1320 EMPTY_STRING(module_info _ author);
1321 SUBSTRING(module_info _ name, filename, basename, ext - basename);
1322 EMPTY_STRING(module_info _ date);
1323 module_info _ channels = 1;
1324 module_info _ songs = 1;
1325 module_info _ default_song = 0;
1326 for (i = 0; i < ASAP_SONGS_MAX; i++) {
1327 module_info _ durations[i] = -1;
1328 module_info _ loops[i] = FALSE;
1329 }
1330 module_info _ ntsc = FALSE;
1331 module_info _ fastplay = 312;
1332 module_info _ music = -1;
1333 module_info _ init = -1;
1334 module_info _ player = -1;
1335 module_info _ covox_addr = -1;
1336 switch (get_packed_ext(filename)) {
1337 case ASAP_EXT('S', 'A', 'P'):
1338 return parse_sap(ast, module_info, module, module_len);
1339#ifndef ASAP_ONLY_SAP
1340 case ASAP_EXT('C', 'M', 'C'):
1341 return parse_cmc(ast, module_info, module, module_len, ASAP_TYPE_CMC, GET_PLAYER(cmc));
1342 case ASAP_EXT('C', 'M', '3'):
1343 return parse_cmc(ast, module_info, module, module_len, ASAP_TYPE_CM3, GET_PLAYER(cm3));
1344 case ASAP_EXT('C', 'M', 'R'):
1345 return parse_cmc(ast, module_info, module, module_len, ASAP_TYPE_CMR, GET_PLAYER(cmc));
1346 case ASAP_EXT('C', 'M', 'S'):
1347 module_info _ channels = 2;
1348 return parse_cmc(ast, module_info, module, module_len, ASAP_TYPE_CMS, GET_PLAYER(cms));
1349 case ASAP_EXT('D', 'M', 'C'):
1350 module_info _ fastplay = 156;
1351 return parse_cmc(ast, module_info, module, module_len, ASAP_TYPE_CMC, GET_PLAYER(cmc));
1352 case ASAP_EXT('D', 'L', 'T'):
1353 return parse_dlt(ast, module_info, module, module_len);
1354 case ASAP_EXT('M', 'P', 'T'):
1355 return parse_mpt(ast, module_info, module, module_len);
1356 case ASAP_EXT('M', 'P', 'D'):
1357 module_info _ fastplay = 156;
1358 return parse_mpt(ast, module_info, module, module_len);
1359 case ASAP_EXT('R', 'M', 'T'):
1360 return parse_rmt(ast, module_info, module, module_len);
1361 case ASAP_EXT('T', 'M', 'C'):
1362 case ASAP_EXT('T', 'M', '8'):
1363 return parse_tmc(ast, module_info, module, module_len);
1364 case ASAP_EXT('T', 'M', '2'):
1365 return parse_tm2(ast, module_info, module, module_len);
1366#endif
1367 default:
1368 return FALSE;
1369 }
1370}
1371
1372FUNC(abool, ASAP_GetModuleInfo, (
1373 P(ASAP_ModuleInfo PTR, module_info), P(STRING, filename),
1374 P(CONST BYTEARRAY, module), P(int, module_len)))
1375{
1376 return parse_file(NULL, module_info, filename, module, module_len);
1377}
1378
1379#ifndef ASAP_ONLY_INFO
1380
1381FUNC(abool, ASAP_Load, (
1382 P(ASAP_State PTR, ast), P(STRING, filename),
1383 P(CONST BYTEARRAY, module), P(int, module_len)))
1384{
1385 /* Set up ast */
1386 ast _ memory = s_memory;
1387 ast _ module_info = &s_module_info;
1388 ast _ silence_cycles = 0;
1389 return parse_file(ast, ast _ module_info, filename, module, module_len);
1390}
1391
1392FUNC(void, ASAP_DetectSilence, (P(ASAP_State PTR, ast), P(int, seconds)))
1393{
1394 ast _ silence_cycles = seconds * ASAP_MAIN_CLOCK(ast);
1395}
1396
1397PRIVATE FUNC(void, call_6502, (P(ASAP_State PTR, ast), P(int, addr), P(int, max_scanlines)))
1398{
1399 ast _ cpu_pc = addr;
1400 /* put a CIM at 0xd20a and a return address on stack */
1401 dPutByte(0xd20a, 0xd2);
1402 dPutByte(0x01fe, 0x09);
1403 dPutByte(0x01ff, 0xd2);
1404 ast _ cpu_s = 0xfd;
1405 Cpu_RunScanlines(ast, max_scanlines);
1406}
1407
1408/* 50 Atari frames for the initialization routine - some SAPs are self-extracting. */
1409#define SCANLINES_FOR_INIT (50 * 312)
1410
1411PRIVATE FUNC(void, call_6502_init, (P(ASAP_State PTR, ast), P(int, addr), P(int, a), P(int, x), P(int, y)))
1412{
1413 ast _ cpu_a = a & 0xff;
1414 ast _ cpu_x = x & 0xff;
1415 ast _ cpu_y = y & 0xff;
1416 call_6502(ast, addr, SCANLINES_FOR_INIT);
1417}
1418
1419FUNC(void, ASAP_PlaySong, (P(ASAP_State PTR, ast), P(int, song), P(int, duration)))
1420{
1421 ast _ current_song = song;
1422 ast _ current_duration = duration;
1423 ast _ blocks_played = 0;
1424 ast _ silence_cycles_counter = ast _ silence_cycles;
1425 ast _ extra_pokey_mask = ast _ module_info->channels > 1 ? 0x10 : 0;
1426 ast _ consol = 8;
1427 ast _ covox[0] = CAST(byte) 0x80;
1428 ast _ covox[1] = CAST(byte) 0x80;
1429 ast _ covox[2] = CAST(byte) 0x80;
1430 ast _ covox[3] = CAST(byte) 0x80;
1431 PokeySound_Initialize(ast);
1432 ast _ cycle = 0;
1433 ast _ cpu_nz = 0;
1434 ast _ cpu_c = 0;
1435 ast _ cpu_vdi = 0;
1436 ast _ scanline_number = 0;
1437 ast _ next_scanline_cycle = 0;
1438 ast _ timer1_cycle = NEVER;
1439 ast _ timer2_cycle = NEVER;
1440 ast _ timer4_cycle = NEVER;
1441 ast _ irqst = 0xff;
1442 switch (ast _ module_info->type) {
1443 case ASAP_TYPE_SAP_B:
1444 call_6502_init(ast, ast _ module_info->init, song, 0, 0);
1445 break;
1446 case ASAP_TYPE_SAP_C:
1447#ifndef ASAP_ONLY_SAP
1448 case ASAP_TYPE_CMC:
1449 case ASAP_TYPE_CM3:
1450 case ASAP_TYPE_CMR:
1451 case ASAP_TYPE_CMS:
1452#endif
1453 call_6502_init(ast, ast _ module_info->player + 3, 0x70, ast _ module_info->music, ast _ module_info->music >> 8);
1454 call_6502_init(ast, ast _ module_info->player + 3, 0x00, song, 0);
1455 break;
1456 case ASAP_TYPE_SAP_D:
1457 case ASAP_TYPE_SAP_S:
1458 ast _ cpu_a = song;
1459 ast _ cpu_x = 0x00;
1460 ast _ cpu_y = 0x00;
1461 ast _ cpu_s = 0xff;
1462 ast _ cpu_pc = ast _ module_info->init;
1463 break;
1464#ifndef ASAP_ONLY_SAP
1465 case ASAP_TYPE_DLT:
1466 call_6502_init(ast, ast _ module_info->player + 0x100, 0x00, 0x00, ast _ module_info->song_pos[song]);
1467 break;
1468 case ASAP_TYPE_MPT:
1469 call_6502_init(ast, ast _ module_info->player, 0x00, ast _ module_info->music >> 8, ast _ module_info->music);
1470 call_6502_init(ast, ast _ module_info->player, 0x02, ast _ module_info->song_pos[song], 0);
1471 break;
1472 case ASAP_TYPE_RMT:
1473 call_6502_init(ast, ast _ module_info->player, ast _ module_info->song_pos[song], ast _ module_info->music, ast _ module_info->music >> 8);
1474 break;
1475 case ASAP_TYPE_TMC:
1476 case ASAP_TYPE_TM2:
1477 call_6502_init(ast, ast _ module_info->player, 0x70, ast _ module_info->music >> 8, ast _ module_info->music);
1478 call_6502_init(ast, ast _ module_info->player, 0x00, song, 0);
1479 ast _ tmc_per_frame_counter = 1;
1480 break;
1481#endif
1482 }
1483 ASAP_MutePokeyChannels(ast, 0);
1484}
1485
1486FUNC(void, ASAP_MutePokeyChannels, (P(ASAP_State PTR, ast), P(int, mask)))
1487{
1488 PokeySound_Mute(ast, ADDRESSOF ast _ base_pokey, mask);
1489 PokeySound_Mute(ast, ADDRESSOF ast _ extra_pokey, mask >> 4);
1490}
1491
1492FUNC(abool, call_6502_player, (P(ASAP_State PTR, ast)))
1493{
1494 V(int, player) = ast _ module_info->player;
1495 PokeySound_StartFrame(ast);
1496 switch (ast _ module_info->type) {
1497 case ASAP_TYPE_SAP_B:
1498 call_6502(ast, player, ast _ module_info->fastplay);
1499 break;
1500 case ASAP_TYPE_SAP_C:
1501#ifndef ASAP_ONLY_SAP
1502 case ASAP_TYPE_CMC:
1503 case ASAP_TYPE_CM3:
1504 case ASAP_TYPE_CMR:
1505 case ASAP_TYPE_CMS:
1506#endif
1507 call_6502(ast, player + 6, ast _ module_info->fastplay);
1508 break;
1509 case ASAP_TYPE_SAP_D:
1510 if (player >= 0) {
1511 V(int, s)= ast _ cpu_s;
1512#define PUSH_ON_6502_STACK(x) dPutByte(0x100 + s, x); s = (s - 1) & 0xff
1513#define RETURN_FROM_PLAYER_ADDR 0xd200
1514 /* save 6502 state on 6502 stack */
1515 PUSH_ON_6502_STACK(ast _ cpu_pc >> 8);
1516 PUSH_ON_6502_STACK(ast _ cpu_pc & 0xff);
1517 PUSH_ON_6502_STACK(((ast _ cpu_nz | (ast _ cpu_nz >> 1)) & 0x80) + ast _ cpu_vdi + \
1518 ((ast _ cpu_nz & 0xff) == 0 ? Z_FLAG : 0) + ast _ cpu_c + 0x20);
1519 PUSH_ON_6502_STACK(ast _ cpu_a);
1520 PUSH_ON_6502_STACK(ast _ cpu_x);
1521 PUSH_ON_6502_STACK(ast _ cpu_y);
1522 /* RTS will jump to 6502 code that restores the state */
1523 PUSH_ON_6502_STACK((RETURN_FROM_PLAYER_ADDR - 1) >> 8);
1524 PUSH_ON_6502_STACK((RETURN_FROM_PLAYER_ADDR - 1) & 0xff);
1525 ast _ cpu_s = s;
1526 dPutByte(RETURN_FROM_PLAYER_ADDR, 0x68); /* PLA */
1527 dPutByte(RETURN_FROM_PLAYER_ADDR + 1, 0xa8); /* TAY */
1528 dPutByte(RETURN_FROM_PLAYER_ADDR + 2, 0x68); /* PLA */
1529 dPutByte(RETURN_FROM_PLAYER_ADDR + 3, 0xaa); /* TAX */
1530 dPutByte(RETURN_FROM_PLAYER_ADDR + 4, 0x68); /* PLA */
1531 dPutByte(RETURN_FROM_PLAYER_ADDR + 5, 0x40); /* RTI */
1532 ast _ cpu_pc = player;
1533 }
1534 Cpu_RunScanlines(ast, ast _ module_info->fastplay);
1535 break;
1536 case ASAP_TYPE_SAP_S:
1537 Cpu_RunScanlines(ast, ast _ module_info->fastplay);
1538 {
1539 V(int, i) = dGetByte(0x45) - 1;
1540 dPutByte(0x45, i);
1541 if (i == 0)
1542 dPutByte(0xb07b, dGetByte(0xb07b) + 1);
1543 }
1544 break;
1545#ifndef ASAP_ONLY_SAP
1546 case ASAP_TYPE_DLT:
1547 call_6502(ast, player + 0x103, ast _ module_info->fastplay);
1548 break;
1549 case ASAP_TYPE_MPT:
1550 case ASAP_TYPE_RMT:
1551 case ASAP_TYPE_TM2:
1552 call_6502(ast, player + 3, ast _ module_info->fastplay);
1553 break;
1554 case ASAP_TYPE_TMC:
1555 if (--ast _ tmc_per_frame_counter <= 0) {
1556 ast _ tmc_per_frame_counter = ast _ tmc_per_frame;
1557 call_6502(ast, player + 3, ast _ module_info->fastplay);
1558 }
1559 else
1560 call_6502(ast, player + 6, ast _ module_info->fastplay);
1561 break;
1562#endif
1563 }
1564 PokeySound_EndFrame(ast, ast _ module_info->fastplay * 114);
1565 if (ast _ silence_cycles > 0) {
1566 if (PokeySound_IsSilent(ADDRESSOF ast _ base_pokey)
1567 && PokeySound_IsSilent(ADDRESSOF ast _ extra_pokey)) {
1568 ast _ silence_cycles_counter -= ast _ module_info->fastplay * 114;
1569 if (ast _ silence_cycles_counter <= 0)
1570 return FALSE;
1571 }
1572 else
1573 ast _ silence_cycles_counter = ast _ silence_cycles;
1574 }
1575 return TRUE;
1576}
1577
1578FUNC(int, ASAP_GetPosition, (P(CONST ASAP_State PTR, ast)))
1579{
1580 return ast _ blocks_played * 10 / (ASAP_SAMPLE_RATE / 100);
1581}
1582
1583FUNC(int, milliseconds_to_blocks, (P(int, milliseconds)))
1584{
1585 return milliseconds * (ASAP_SAMPLE_RATE / 100) / 10;
1586}
1587
1588#ifndef ACTIONSCRIPT
1589
1590FUNC(void, ASAP_Seek, (P(ASAP_State PTR, ast), P(int, position)))
1591{
1592 V(int, block) = milliseconds_to_blocks(position);
1593 if (block < ast _ blocks_played)
1594 ASAP_PlaySong(ast, ast _ current_song, ast _ current_duration);
1595 while (ast _ blocks_played + ast _ samples - ast _ sample_index < block) {
1596 ast _ blocks_played += ast _ samples - ast _ sample_index;
1597 call_6502_player(ast);
1598 }
1599 ast _ sample_index += block - ast _ blocks_played;
1600 ast _ blocks_played = block;
1601}
1602
1603PRIVATE FUNC(void, serialize_int, (P(BYTEARRAY, buffer), P(int, offset), P(int, value)))
1604{
1605 buffer[offset] = TO_BYTE(value);
1606 buffer[offset + 1] = TO_BYTE(value >> 8);
1607 buffer[offset + 2] = TO_BYTE(value >> 16);
1608 buffer[offset + 3] = TO_BYTE(value >> 24);
1609}
1610
1611FUNC(void, ASAP_GetWavHeader, (
1612 P(CONST ASAP_State PTR, ast), P(BYTEARRAY, buffer), P(ASAP_SampleFormat, format)))
1613{
1614 V(int, use_16bit) = format != ASAP_FORMAT_U8 ? 1 : 0;
1615 V(int, block_size) = ast _ module_info->channels << use_16bit;
1616 V(int, bytes_per_second) = ASAP_SAMPLE_RATE * block_size;
1617 V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration);
1618 V(int, n_bytes) = (total_blocks - ast _ blocks_played) * block_size;
1619 buffer[0] = CAST(byte) CHARCODE('R');
1620 buffer[1] = CAST(byte) CHARCODE('I');
1621 buffer[2] = CAST(byte) CHARCODE('F');
1622 buffer[3] = CAST(byte) CHARCODE('F');
1623 serialize_int(buffer, 4, n_bytes + 36);
1624 buffer[8] = CAST(byte) CHARCODE('W');
1625 buffer[9] = CAST(byte) CHARCODE('A');
1626 buffer[10] = CAST(byte) CHARCODE('V');
1627 buffer[11] = CAST(byte) CHARCODE('E');
1628 buffer[12] = CAST(byte) CHARCODE('f');
1629 buffer[13] = CAST(byte) CHARCODE('m');
1630 buffer[14] = CAST(byte) CHARCODE('t');
1631 buffer[15] = CAST(byte) CHARCODE(' ');
1632 buffer[16] = 16;
1633 buffer[17] = 0;
1634 buffer[18] = 0;
1635 buffer[19] = 0;
1636 buffer[20] = 1;
1637 buffer[21] = 0;
1638 buffer[22] = CAST(byte) ast _ module_info->channels;
1639 buffer[23] = 0;
1640 serialize_int(buffer, 24, ASAP_SAMPLE_RATE);
1641 serialize_int(buffer, 28, bytes_per_second);
1642 buffer[32] = CAST(byte) block_size;
1643 buffer[33] = 0;
1644 buffer[34] = CAST(byte) (8 << use_16bit);
1645 buffer[35] = 0;
1646 buffer[36] = CAST(byte) CHARCODE('d');
1647 buffer[37] = CAST(byte) CHARCODE('a');
1648 buffer[38] = CAST(byte) CHARCODE('t');
1649 buffer[39] = CAST(byte) CHARCODE('a');
1650 serialize_int(buffer, 40, n_bytes);
1651}
1652
1653#endif /* ACTIONSCRIPT */
1654
1655PRIVATE FUNC(int, ASAP_GenerateAt, (P(ASAP_State PTR, ast), P(VOIDPTR, buffer), P(int, buffer_offset), P(int, buffer_len), P(ASAP_SampleFormat, format)))
1656{
1657 V(int, block_shift);
1658 V(int, buffer_blocks);
1659 V(int, block);
1660 if (ast _ silence_cycles > 0 && ast _ silence_cycles_counter <= 0)
1661 return 0;
1662#ifdef ACTIONSCRIPT
1663 block_shift = 0;
1664#else
1665 block_shift = (ast _ module_info->channels - 1) + (format != ASAP_FORMAT_U8 ? 1 : 0);
1666#endif
1667 buffer_blocks = buffer_len >> block_shift;
1668 if (ast _ current_duration > 0) {
1669 V(int, total_blocks) = milliseconds_to_blocks(ast _ current_duration);
1670 if (buffer_blocks > total_blocks - ast _ blocks_played)
1671 buffer_blocks = total_blocks - ast _ blocks_played;
1672 }
1673 block = 0;
1674 do {
1675 V(int, blocks) = PokeySound_Generate(ast, CAST(BYTEARRAY) buffer,
1676 buffer_offset + (block << block_shift), buffer_blocks - block, format);
1677 ast _ blocks_played += blocks;
1678 block += blocks;
1679 } while (block < buffer_blocks && call_6502_player(ast));
1680 return block << block_shift;
1681}
1682
1683FUNC(int, ASAP_Generate, (P(ASAP_State PTR, ast), P(VOIDPTR, buffer), P(int, buffer_len), P(ASAP_SampleFormat, format)))
1684{
1685 return ASAP_GenerateAt(ast, buffer, 0, buffer_len, format);
1686}
1687
1688#endif /* ASAP_ONLY_INFO */
1689
1690#ifdef C
1691
1692abool ASAP_CanSetModuleInfo(const char *filename)
1693{
1694 int ext = get_packed_ext(filename);
1695 return ext == ASAP_EXT('S', 'A', 'P');
1696}
1697
1698abool ASAP_ChangeExt(char *filename, const char *ext)
1699{
1700 char *dest = NULL;
1701 while (*filename != '\0') {
1702 if (*filename == '/' || *filename == '\\')
1703 dest = NULL;
1704 else if (*filename == '.')
1705 dest = filename + 1;
1706 filename++;
1707 }
1708 if (dest == NULL)
1709 return FALSE;
1710 strcpy(dest, ext);
1711 return TRUE;
1712}
1713
1714static byte *put_string(byte *dest, const char *str)
1715{
1716 while (*str != '\0')
1717 *dest++ = *str++;
1718 return dest;
1719}
1720
1721static byte *put_dec(byte *dest, int value)
1722{
1723 if (value >= 10) {
1724 dest = put_dec(dest, value / 10);
1725 value %= 10;
1726 }
1727 *dest++ = '0' + value;
1728 return dest;
1729}
1730
1731static byte *put_text_tag(byte *dest, const char *tag, const char *value)
1732{
1733 dest = put_string(dest, tag);
1734 *dest++ = '"';
1735 if (*value == '\0')
1736 value = "<?>";
1737 while (*value != '\0') {
1738 if (*value < ' ' || *value > 'z' || *value == '"' || *value == '`')
1739 return NULL;
1740 *dest++ = *value++;
1741 }
1742 *dest++ = '"';
1743 *dest++ = '\r';
1744 *dest++ = '\n';
1745 return dest;
1746}
1747
1748static byte *put_dec_tag(byte *dest, const char *tag, int value)
1749{
1750 dest = put_string(dest, tag);
1751 dest = put_dec(dest, value);
1752 *dest++ = '\r';
1753 *dest++ = '\n';
1754 return dest;
1755}
1756
1757static byte *start_sap_header(byte *dest, const ASAP_ModuleInfo *module_info)
1758{
1759 dest = put_string(dest, "SAP\r\n");
1760 dest = put_text_tag(dest, "AUTHOR ", module_info->author);
1761 if (dest == NULL)
1762 return NULL;
1763 dest = put_text_tag(dest, "NAME ", module_info->name);
1764 if (dest == NULL)
1765 return NULL;
1766 dest = put_text_tag(dest, "DATE ", module_info->date);
1767 if (dest == NULL)
1768 return NULL;
1769 if (module_info->songs > 1) {
1770 dest = put_dec_tag(dest, "SONGS ", module_info->songs);
1771 if (module_info->default_song > 0)
1772 dest = put_dec_tag(dest, "DEFSONG ", module_info->default_song);
1773 }
1774 if (module_info->channels > 1)
1775 dest = put_string(dest, "STEREO\r\n");
1776 return dest;
1777}
1778
1779static char *two_digits(char *s, int x)
1780{
1781 s[0] = '0' + x / 10;
1782 s[1] = '0' + x % 10;
1783 return s + 2;
1784}
1785
1786void ASAP_DurationToString(char *s, int duration)
1787{
1788 if (duration >= 0 && duration < 100 * 60 * 1000) {
1789 int seconds = duration / 1000;
1790 s = two_digits(s, seconds / 60);
1791 *s++ = ':';
1792 s = two_digits(s, seconds % 60);
1793 duration %= 1000;
1794 if (duration != 0) {
1795 *s++ = '.';
1796 s = two_digits(s, duration / 10);
1797 duration %= 10;
1798 if (duration != 0)
1799 *s++ = '0' + duration;
1800 }
1801 }
1802 *s = '\0';
1803}
1804
1805static byte *put_durations(byte *dest, const ASAP_ModuleInfo *module_info)
1806{
1807 int song;
1808 for (song = 0; song < module_info->songs; song++) {
1809 if (module_info->durations[song] < 0)
1810 break;
1811 dest = put_string(dest, "TIME ");
1812 ASAP_DurationToString((char *) dest, module_info->durations[song]);
1813 while (*dest != '\0')
1814 dest++;
1815 if (module_info->loops[song])
1816 dest = put_string(dest, " LOOP");
1817 *dest++ = '\r';
1818 *dest++ = '\n';
1819 }
1820 return dest;
1821}
1822
1823int ASAP_SetModuleInfo(const ASAP_ModuleInfo *module_info, const BYTEARRAY module, int module_len, BYTEARRAY out_module)
1824{
1825 byte *dest;
1826 int i;
1827 if (memcmp(module, "SAP\r\n", 5) != 0)
1828 return -1;
1829 dest = start_sap_header(out_module, module_info);
1830 if (dest == NULL)
1831 return -1;
1832 i = 5;
1833 while (i < module_len && module[i] != 0xff) {
1834 if (memcmp(module + i, "AUTHOR ", 7) == 0
1835 || memcmp(module + i, "NAME ", 5) == 0
1836 || memcmp(module + i, "DATE ", 5) == 0
1837 || memcmp(module + i, "SONGS ", 6) == 0
1838 || memcmp(module + i, "DEFSONG ", 8) == 0
1839 || memcmp(module + i, "STEREO\r", 7) == 0
1840 || memcmp(module + i, "TIME ", 5) == 0) {
1841 while (i < module_len && module[i++] != 0x0a);
1842 }
1843 else {
1844 int b;
1845 do {
1846 b = module[i++];
1847 *dest++ = b;
1848 } while (i < module_len && b != 0x0a);
1849 }
1850 }
1851 dest = put_durations(dest, module_info);
1852 module_len -= i;
1853 memcpy(dest, module + i, module_len);
1854 dest += module_len;
1855 return dest - out_module;
1856}
1857
1858#if !defined(ASAP_ONLY_SAP) && !defined(ASAP_ONLY_INFO)
1859
1860#define RMT_INIT 0x0c80
1861#define TM2_INIT 0x1080
1862
1863const char *ASAP_CanConvert(
1864 const char *filename, const ASAP_ModuleInfo *module_info,
1865 const BYTEARRAY module, int module_len)
1866{
1867 (void) filename;
1868 switch (module_info->type) {
1869 case ASAP_TYPE_SAP_B:
1870 if ((module_info->init == 0x3fb || module_info->init == 0x3f9) && module_info->player == 0x503)
1871 return "dlt";
1872 if (module_info->init == 0x4f3 || module_info->init == 0xf4f3 || module_info->init == 0x4ef)
1873 return module_info->fastplay == 156 ? "mpd" : "mpt";
1874 if (module_info->init == RMT_INIT)
1875 return "rmt";
1876 if ((module_info->init == 0x4f5 || module_info->init == 0xf4f5 || module_info->init == 0x4f2)
1877 || ((module_info->init == 0x4e7 || module_info->init == 0xf4e7 || module_info->init == 0x4e4) && module_info->fastplay == 156)
1878 || ((module_info->init == 0x4e5 || module_info->init == 0xf4e5 || module_info->init == 0x4e2) && (module_info->fastplay == 104 || module_info->fastplay == 78)))
1879 return "tmc";
1880 if (module_info->init == TM2_INIT)
1881 return "tm2";
1882 break;
1883 case ASAP_TYPE_SAP_C:
1884 if (module_info->player == 0x500 || module_info->player == 0xf500) {
1885 if (module_info->fastplay == 156)
1886 return "dmc";
1887 if (module_info->channels > 1)
1888 return "cms";
1889 if (module[module_len - 170] == 0x1e)
1890 return "cmr";
1891 if (module[module_len - 909] == 0x30)
1892 return "cm3";
1893 return "cmc";
1894 }
1895 break;
1896 case ASAP_TYPE_CMC:
1897 case ASAP_TYPE_CM3:
1898 case ASAP_TYPE_CMR:
1899 case ASAP_TYPE_CMS:
1900 case ASAP_TYPE_DLT:
1901 case ASAP_TYPE_MPT:
1902 case ASAP_TYPE_RMT:
1903 case ASAP_TYPE_TMC:
1904 case ASAP_TYPE_TM2:
1905 return "sap";
1906 default:
1907 break;
1908 }
1909 return NULL;
1910}
1911
1912static byte *put_hex_tag(byte *dest, const char *tag, int value)
1913{
1914 int i;
1915 if (value < 0)
1916 return dest;
1917 dest = put_string(dest, tag);
1918 for (i = 12; i >= 0; i -= 4) {
1919 int digit = (value >> i) & 0xf;
1920 *dest++ = (byte) (digit + (digit < 10 ? '0' : 'A' - 10));
1921 }
1922 *dest++ = '\r';
1923 *dest++ = '\n';
1924 return dest;
1925}
1926
1927static byte *put_sap_header(byte *dest, const ASAP_ModuleInfo *module_info, char type, int music, int init, int player)
1928{
1929 dest = start_sap_header(dest, module_info);
1930 if (dest == NULL)
1931 return NULL;
1932 dest = put_string(dest, "TYPE ");
1933 *dest++ = type;
1934 *dest++ = '\r';
1935 *dest++ = '\n';
1936 if (module_info->fastplay != 312)
1937 dest = put_dec_tag(dest, "FASTPLAY ", module_info->fastplay);
1938 dest = put_hex_tag(dest, "MUSIC ", music);
1939 dest = put_hex_tag(dest, "INIT ", init);
1940 dest = put_hex_tag(dest, "PLAYER ", player);
1941 dest = put_durations(dest, module_info);
1942 return dest;
1943}
1944
1945int ASAP_Convert(
1946 const char *filename, const ASAP_ModuleInfo *module_info,
1947 const BYTEARRAY module, int module_len, BYTEARRAY out_module)
1948{
1949 (void) filename;
1950 int out_len;
1951 byte *dest;
1952 int addr;
1953 int player;
1954 static const int tmc_player[4] = { 3, -9, -10, -10 };
1955 static const int tmc_init[4] = { -14, -16, -17, -17 };
1956 switch (module_info->type) {
1957 case ASAP_TYPE_SAP_B:
1958 case ASAP_TYPE_SAP_C:
1959 out_len = UWORD(module, module_info->header_len + 4) - UWORD(module, module_info->header_len + 2) + 7;
1960 if (out_len < 7 || module_info->header_len + out_len >= module_len)
1961 return -1;
1962 memcpy(out_module, module + module_info->header_len, out_len);
1963 return out_len;
1964 case ASAP_TYPE_CMC:
1965 case ASAP_TYPE_CM3:
1966 case ASAP_TYPE_CMR:
1967 case ASAP_TYPE_CMS:
1968 dest = put_sap_header(out_module, module_info, 'C', module_info->music, -1, module_info->player);
1969 if (dest == NULL)
1970 return -1;
1971 memcpy(dest, module, module_len);
1972 dest[0] = 0xff; /* some modules start with zeros */
1973 dest[1] = 0xff;
1974 dest += module_len;
1975 if (module_info->type == ASAP_TYPE_CM3) {
1976 memcpy(dest, cm3_obx + 2, sizeof(cm3_obx) - 2);
1977 dest += sizeof(cm3_obx) - 2;
1978 }
1979 else if (module_info->type == ASAP_TYPE_CMS) {
1980 memcpy(dest, cms_obx + 2, sizeof(cms_obx) - 2);
1981 dest += sizeof(cms_obx) - 2;
1982 }
1983 else {
1984 memcpy(dest, cmc_obx + 2, sizeof(cmc_obx) - 2);
1985 if (module_info->type == ASAP_TYPE_CMR)
1986 memcpy(dest + 4 + CMR_BASS_TABLE_OFFSET, cmr_bass_table, sizeof(cmr_bass_table));
1987 dest += sizeof(cmc_obx) - 2;
1988 }
1989 return dest - out_module;
1990 case ASAP_TYPE_DLT:
1991 if (module_info->songs != 1) {
1992 addr = module_info->player - 7 - module_info->songs;
1993 dest = put_sap_header(out_module, module_info, 'B', -1, module_info->player - 7, module_info->player + 0x103);
1994 }
1995 else {
1996 addr = module_info->player - 5;
1997 dest = put_sap_header(out_module, module_info, 'B', -1, addr, module_info->player + 0x103);
1998 }
1999 if (dest == NULL)
2000 return -1;
2001 memcpy(dest, module, module_len);
2002 if (module_len == 0x2c06) {
2003 dest[4] = 0;
2004 dest[5] = 0x4c;
2005 dest[0x2c06] = 0;
2006 }
2007 dest += 0x2c07;
2008 *dest++ = (byte) addr;
2009 *dest++ = (byte) (addr >> 8);
2010 *dest++ = dlt_obx[4];
2011 *dest++ = dlt_obx[5];
2012 if (module_info->songs != 1) {
2013 memcpy(dest, module_info->song_pos, module_info->songs);
2014 dest += module_info->songs;
2015 *dest++ = 0xaa; /* tax */
2016 *dest++ = 0xbc; /* ldy song2pos,x */
2017 *dest++ = (byte) addr;
2018 *dest++ = (byte) (addr >> 8);
2019 }
2020 else {
2021 *dest++ = 0xa0; /* ldy #0 */
2022 *dest++ = 0;
2023 }
2024 *dest++ = 0x4c; /* jmp init */
2025 *dest++ = (byte) module_info->player;
2026 *dest++ = (byte) ((module_info->player >> 8) + 1);
2027 memcpy(dest, dlt_obx + 6, sizeof(dlt_obx) - 6);
2028 dest += sizeof(dlt_obx) - 6;
2029 return dest - out_module;
2030 case ASAP_TYPE_MPT:
2031 if (module_info->songs != 1) {
2032 addr = module_info->player - 17 - module_info->songs;
2033 dest = put_sap_header(out_module, module_info, 'B', -1, module_info->player - 17, module_info->player + 3);
2034 }
2035 else {
2036 addr = module_info->player - 13;
2037 dest = put_sap_header(out_module, module_info, 'B', -1, addr, module_info->player + 3);
2038 }
2039 if (dest == NULL)
2040 return -1;
2041 memcpy(dest, module, module_len);
2042 dest += module_len;
2043 *dest++ = (byte) addr;
2044 *dest++ = (byte) (addr >> 8);
2045 *dest++ = mpt_obx[4];
2046 *dest++ = mpt_obx[5];
2047 if (module_info->songs != 1) {
2048 memcpy(dest, module_info->song_pos, module_info->songs);
2049 dest += module_info->songs;
2050 *dest++ = 0x48; /* pha */
2051 }
2052 *dest++ = 0xa0; /* ldy #<music */
2053 *dest++ = (byte) module_info->music;
2054 *dest++ = 0xa2; /* ldx #>music */
2055 *dest++ = (byte) (module_info->music >> 8);
2056 *dest++ = 0xa9; /* lda #0 */
2057 *dest++ = 0;
2058 *dest++ = 0x20; /* jsr player */
2059 *dest++ = (byte) module_info->player;
2060 *dest++ = (byte) (module_info->player >> 8);
2061 if (module_info->songs != 1) {
2062 *dest++ = 0x68; /* pla */
2063 *dest++ = 0xa8; /* tay */
2064 *dest++ = 0xbe; /* ldx song2pos,y */
2065 *dest++ = (byte) addr;
2066 *dest++ = (byte) (addr >> 8);
2067 }
2068 else {
2069 *dest++ = 0xa2; /* ldx #0 */
2070 *dest++ = 0;
2071 }
2072 *dest++ = 0xa9; /* lda #2 */
2073 *dest++ = 2;
2074 memcpy(dest, mpt_obx + 6, sizeof(mpt_obx) - 6);
2075 dest += sizeof(mpt_obx) - 6;
2076 return dest - out_module;
2077 case ASAP_TYPE_RMT:
2078 dest = put_sap_header(out_module, module_info, 'B', -1, RMT_INIT, module_info->player + 3);
2079 if (dest == NULL)
2080 return -1;
2081 memcpy(dest, module, module_len);
2082 dest += module_len;
2083 *dest++ = (byte) RMT_INIT;
2084 *dest++ = (byte) (RMT_INIT >> 8);
2085 if (module_info->songs != 1) {
2086 addr = RMT_INIT + 10 + module_info->songs;
2087 *dest++ = (byte) addr;
2088 *dest++ = (byte) (addr >> 8);
2089 *dest++ = 0xa8; /* tay */
2090 *dest++ = 0xb9; /* lda song2pos,y */
2091 *dest++ = (byte) (RMT_INIT + 11);
2092 *dest++ = (byte) ((RMT_INIT + 11) >> 8);
2093 }
2094 else {
2095 *dest++ = (byte) (RMT_INIT + 8);
2096 *dest++ = (byte) ((RMT_INIT + 8) >> 8);
2097 *dest++ = 0xa9; /* lda #0 */
2098 *dest++ = 0;
2099 }
2100 *dest++ = 0xa2; /* ldx #<music */
2101 *dest++ = (byte) module_info->music;
2102 *dest++ = 0xa0; /* ldy #>music */
2103 *dest++ = (byte) (module_info->music >> 8);
2104 *dest++ = 0x4c; /* jmp player */
2105 *dest++ = (byte) module_info->player;
2106 *dest++ = (byte) (module_info->player >> 8);
2107 if (module_info->songs != 1) {
2108 memcpy(dest, module_info->song_pos, module_info->songs);
2109 dest += module_info->songs;
2110 }
2111 if (module_info->channels == 1) {
2112 memcpy(dest, rmt4_obx + 2, sizeof(rmt4_obx) - 2);
2113 dest += sizeof(rmt4_obx) - 2;
2114 }
2115 else {
2116 memcpy(dest, rmt8_obx + 2, sizeof(rmt8_obx) - 2);
2117 dest += sizeof(rmt8_obx) - 2;
2118 }
2119 return dest - out_module;
2120 case ASAP_TYPE_TMC:
2121 player = module_info->player + tmc_player[module[0x25] - 1];
2122 addr = player + tmc_init[module[0x25] - 1];
2123 if (module_info->songs != 1)
2124 addr -= 3;
2125 dest = put_sap_header(out_module, module_info, 'B', -1, addr, player);
2126 if (dest == NULL)
2127 return -1;
2128 memcpy(dest, module, module_len);
2129 dest += module_len;
2130 *dest++ = (byte) addr;
2131 *dest++ = (byte) (addr >> 8);
2132 *dest++ = tmc_obx[4];
2133 *dest++ = tmc_obx[5];
2134 if (module_info->songs != 1)
2135 *dest++ = 0x48; /* pha */
2136 *dest++ = 0xa0; /* ldy #<music */
2137 *dest++ = (byte) module_info->music;
2138 *dest++ = 0xa2; /* ldx #>music */
2139 *dest++ = (byte) (module_info->music >> 8);
2140 *dest++ = 0xa9; /* lda #$70 */
2141 *dest++ = 0x70;
2142 *dest++ = 0x20; /* jsr player */
2143 *dest++ = (byte) module_info->player;
2144 *dest++ = (byte) (module_info->player >> 8);
2145 if (module_info->songs != 1) {
2146 *dest++ = 0x68; /* pla */
2147 *dest++ = 0xaa; /* tax */
2148 *dest++ = 0xa9; /* lda #0 */
2149 *dest++ = 0;
2150 }
2151 else {
2152 *dest++ = 0xa9; /* lda #$60 */
2153 *dest++ = 0x60;
2154 }
2155 switch (module[0x25]) {
2156 case 2:
2157 *dest++ = 0x06; /* asl 0 */
2158 *dest++ = 0;
2159 *dest++ = 0x4c; /* jmp player */
2160 *dest++ = (byte) module_info->player;
2161 *dest++ = (byte) (module_info->player >> 8);
2162 *dest++ = 0xa5; /* lda 0 */
2163 *dest++ = 0;
2164 *dest++ = 0xe6; /* inc 0 */
2165 *dest++ = 0;
2166 *dest++ = 0x4a; /* lsr @ */
2167 *dest++ = 0x90; /* bcc player+3 */
2168 *dest++ = 5;
2169 *dest++ = 0xb0; /* bcs player+6 */
2170 *dest++ = 6;
2171 break;
2172 case 3:
2173 case 4:
2174 *dest++ = 0xa0; /* ldy #1 */
2175 *dest++ = 1;
2176 *dest++ = 0x84; /* sty 0 */
2177 *dest++ = 0;
2178 *dest++ = 0xd0; /* bne player */
2179 *dest++ = 10;
2180 *dest++ = 0xc6; /* dec 0 */
2181 *dest++ = 0;
2182 *dest++ = 0xd0; /* bne player+6 */
2183 *dest++ = 12;
2184 *dest++ = 0xa0; /* ldy #3 */
2185 *dest++ = module[0x25];
2186 *dest++ = 0x84; /* sty 0 */
2187 *dest++ = 0;
2188 *dest++ = 0xd0; /* bne player+3 */
2189 *dest++ = 3;
2190 break;
2191 default:
2192 break;
2193 }
2194 memcpy(dest, tmc_obx + 6, sizeof(tmc_obx) - 6);
2195 dest += sizeof(tmc_obx) - 6;
2196 return dest - out_module;
2197 case ASAP_TYPE_TM2:
2198 dest = put_sap_header(out_module, module_info, 'B', -1, TM2_INIT, module_info->player + 3);
2199 if (dest == NULL)
2200 return -1;
2201 memcpy(dest, module, module_len);
2202 dest += module_len;
2203 *dest++ = (byte) TM2_INIT;
2204 *dest++ = (byte) (TM2_INIT >> 8);
2205 if (module_info->songs != 1) {
2206 *dest++ = (byte) (TM2_INIT + 16);
2207 *dest++ = (byte) ((TM2_INIT + 16) >> 8);
2208 *dest++ = 0x48; /* pha */
2209 }
2210 else {
2211 *dest++ = (byte) (TM2_INIT + 14);
2212 *dest++ = (byte) ((TM2_INIT + 14) >> 8);
2213 }
2214 *dest++ = 0xa0; /* ldy #<music */
2215 *dest++ = (byte) module_info->music;
2216 *dest++ = 0xa2; /* ldx #>music */
2217 *dest++ = (byte) (module_info->music >> 8);
2218 *dest++ = 0xa9; /* lda #$70 */
2219 *dest++ = 0x70;
2220 *dest++ = 0x20; /* jsr player */
2221 *dest++ = (byte) module_info->player;
2222 *dest++ = (byte) (module_info->player >> 8);
2223 if (module_info->songs != 1) {
2224 *dest++ = 0x68; /* pla */
2225 *dest++ = 0xaa; /* tax */
2226 *dest++ = 0xa9; /* lda #0 */
2227 *dest++ = 0;
2228 }
2229 else {
2230 *dest++ = 0xa9; /* lda #0 */
2231 *dest++ = 0;
2232 *dest++ = 0xaa; /* tax */
2233 }
2234 *dest++ = 0x4c; /* jmp player */
2235 *dest++ = (byte) module_info->player;
2236 *dest++ = (byte) (module_info->player >> 8);
2237 memcpy(dest, tm2_obx + 2, sizeof(tm2_obx) - 2);
2238 dest += sizeof(tm2_obx) - 2;
2239 return dest - out_module;
2240 default:
2241 return -1;
2242 }
2243}
2244
2245#endif /* !defined(ASAP_ONLY_SAP) && !defined(ASAP_ONLY_INFO) */
2246
2247static abool has_two_digits(const char *s)
2248{
2249 return s[0] >= '0' && s[0] <= '9' && s[1] >= '0' && s[1] <= '9';
2250}
2251
2252/* "DD/MM/YYYY", "MM/YYYY", "YYYY" -> "YYYY" */
2253abool ASAP_DateToYear(const char *date, char *year)
2254{
2255 if (!has_two_digits(date))
2256 return FALSE;
2257 if (date[2] == '/') {
2258 date += 3;
2259 if (!has_two_digits(date))
2260 return FALSE;
2261 if (date[2] == '/') {
2262 date += 3;
2263 if (!has_two_digits(date))
2264 return FALSE;
2265 }
2266 }
2267 if (!has_two_digits(date + 2) || date[4] != '\0')
2268 return FALSE;
2269 memcpy(year, date, 5);
2270 return TRUE;
2271}
2272
2273#endif /* C */
diff --git a/lib/rbcodec/codecs/libasap/asap.h b/lib/rbcodec/codecs/libasap/asap.h
new file mode 100644
index 0000000000..1cbf8d0100
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/asap.h
@@ -0,0 +1,328 @@
1/*
2 * asap.h - public interface of ASAP
3 *
4 * Copyright (C) 2005-2010 Piotr Fusik
5 *
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
8 *
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _ASAP_H_
25#define _ASAP_H_
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/* ASAP version. */
32#define ASAP_VERSION_MAJOR 2
33#define ASAP_VERSION_MINOR 1
34#define ASAP_VERSION_MICRO 2
35#define ASAP_VERSION "2.1.2"
36
37/* Short credits of the ASAP engine. */
38#define ASAP_YEARS "2005-2010"
39#define ASAP_CREDITS \
40 "Another Slight Atari Player (C) 2005-2010 Piotr Fusik\n" \
41 "CMC, MPT, TMC, TM2 players (C) 1994-2005 Marcin Lewandowski\n" \
42 "RMT player (C) 2002-2005 Radek Sterba\n" \
43 "DLT player (C) 2009 Marek Konopka\n" \
44 "CMS player (C) 1999 David Spilka\n"
45
46/* Short GPL notice.
47 Display after the credits. */
48#define ASAP_COPYRIGHT \
49 "This program is free software; you can redistribute it and/or modify\n" \
50 "it under the terms of the GNU General Public License as published\n" \
51 "by the Free Software Foundation; either version 2 of the License,\n" \
52 "or (at your option) any later version."
53
54/* Maximum length of AUTHOR, NAME and DATE tags including the terminator. */
55#define ASAP_INFO_CHARS 128
56
57/* Maximum length of a "mm:ss.xxx" string including the terminator. */
58#define ASAP_DURATION_CHARS 10
59
60/* Maximum length of a supported input file.
61 You can assume that files longer than this are not supported by ASAP. */
62#define ASAP_MODULE_MAX 65000
63
64/* Maximum number of songs in a file. */
65#define ASAP_SONGS_MAX 32
66
67/* Output sample rate. */
68#define ASAP_SAMPLE_RATE 44100
69
70/* WAV file header length. */
71#define ASAP_WAV_HEADER_BYTES 44
72
73/* Output formats. */
74typedef enum {
75 ASAP_FORMAT_U8 = 8, /* unsigned char */
76 ASAP_FORMAT_S16_LE = 16, /* signed short, little-endian */
77 ASAP_FORMAT_S16_BE = -16 /* signed short, big-endian */
78} ASAP_SampleFormat;
79
80/* Useful type definitions. */
81#ifndef FALSE
82#define FALSE 0
83#endif
84#ifndef TRUE
85#define TRUE 1
86#endif
87typedef int abool;
88typedef unsigned char byte;
89
90/* Information about a music file. */
91typedef struct {
92 char author[ASAP_INFO_CHARS]; /* author's name */
93 char name[ASAP_INFO_CHARS]; /* title */
94 char date[ASAP_INFO_CHARS]; /* creation date */
95 int channels; /* 1 for mono or 2 for stereo */
96 int songs; /* number of subsongs */
97 int default_song; /* 0-based index of the "main" subsong */
98 int durations[ASAP_SONGS_MAX]; /* lengths of songs, in milliseconds, -1 = indeterminate */
99 abool loops[ASAP_SONGS_MAX]; /* whether songs repeat or not */
100 /* the following technical information should not be used outside ASAP. */
101 abool ntsc;
102 int type;
103 int fastplay;
104 int music;
105 int init;
106 int player;
107 int covox_addr;
108 int header_len;
109 byte song_pos[ASAP_SONGS_MAX];
110} ASAP_ModuleInfo;
111
112/* POKEY state.
113 Not for use outside the ASAP engine. */
114typedef struct {
115 int audctl;
116 abool init;
117 int poly_index;
118 int div_cycles;
119 int mute1;
120 int mute2;
121 int mute3;
122 int mute4;
123 int audf1;
124 int audf2;
125 int audf3;
126 int audf4;
127 int audc1;
128 int audc2;
129 int audc3;
130 int audc4;
131 int tick_cycle1;
132 int tick_cycle2;
133 int tick_cycle3;
134 int tick_cycle4;
135 int period_cycles1;
136 int period_cycles2;
137 int period_cycles3;
138 int period_cycles4;
139 int reload_cycles1;
140 int reload_cycles3;
141 int out1;
142 int out2;
143 int out3;
144 int out4;
145 int delta1;
146 int delta2;
147 int delta3;
148 int delta4;
149 int skctl;
150 int delta_buffer[888];
151} PokeyState;
152
153/* Player state.
154 Only module_info is meant to be read outside the ASAP engine. */
155typedef struct {
156 int cycle;
157 int cpu_pc;
158 int cpu_a;
159 int cpu_x;
160 int cpu_y;
161 int cpu_s;
162 int cpu_nz;
163 int cpu_c;
164 int cpu_vdi;
165 int scanline_number;
166 int nearest_event_cycle;
167 int next_scanline_cycle;
168 int timer1_cycle;
169 int timer2_cycle;
170 int timer4_cycle;
171 int irqst;
172 int extra_pokey_mask;
173 int consol;
174 byte covox[4];
175 PokeyState base_pokey;
176 PokeyState extra_pokey;
177 int sample_offset;
178 int sample_index;
179 int samples;
180 int iir_acc_left;
181 int iir_acc_right;
182 ASAP_ModuleInfo *module_info;
183 int tmc_per_frame;
184 int tmc_per_frame_counter;
185 int current_song;
186 int current_duration;
187 int blocks_played;
188 int silence_cycles;
189 int silence_cycles_counter;
190 byte poly9_lookup[511];
191 byte poly17_lookup[16385];
192 byte *memory;
193} ASAP_State;
194
195/* Parses the string in the "mm:ss.xxx" format
196 and returns the number of milliseconds or -1 if an error occurs. */
197int ASAP_ParseDuration(const char *s);
198
199/* Converts number of milliseconds to a string in the "mm:ss.xxx" format. */
200void ASAP_DurationToString(char *s, int duration);
201
202/* Checks whether the extension of the passed filename is known to ASAP. */
203abool ASAP_IsOurFile(const char *filename);
204
205/* Checks whether the filename extension is known to ASAP. */
206abool ASAP_IsOurExt(const char *ext);
207
208/* Changes the filename extension, returns true on success. */
209abool ASAP_ChangeExt(char *filename, const char *ext);
210
211/* Gets information about a module.
212 "module_info" is the structure where the information is returned.
213 "filename" determines file format.
214 "module" is the music data (contents of the file).
215 "module_len" is the number of data bytes.
216 ASAP_GetModuleInfo() returns true on success. */
217abool ASAP_GetModuleInfo(ASAP_ModuleInfo *module_info, const char *filename,
218 const byte module[], int module_len);
219
220/* Extracts year from date. */
221abool ASAP_DateToYear(const char *date, char *year);
222
223/* Loads music data.
224 "ast" is the destination structure.
225 "filename" determines file format.
226 "module" is the music data (contents of the file).
227 "module_len" is the number of data bytes.
228 ASAP does not make copies of the passed pointers. You can overwrite
229 or free "filename" and "module" once this function returns.
230 ASAP_Load() returns true on success.
231 If false is returned, the structure is invalid and you cannot
232 call the following functions. */
233abool ASAP_Load(ASAP_State *ast, const char *filename,
234 const byte module[], int module_len);
235
236/* Enables silence detection.
237 Makes ASAP finish playing after the specified period of silence.
238 "ast" is ASAP state initialized by ASAP_Load().
239 "seconds" is the minimum length of silence that ends playback. */
240void ASAP_DetectSilence(ASAP_State *ast, int seconds);
241
242/* Prepares ASAP to play the specified song of the loaded module.
243 "ast" is ASAP state initialized by ASAP_Load().
244 "song" is a zero-based index which must be less than the "songs" field
245 of the ASAP_ModuleInfo structure.
246 "duration" is playback time in milliseconds - use durations[song]
247 unless you want to override it. -1 means indefinitely. */
248void ASAP_PlaySong(ASAP_State *ast, int song, int duration);
249
250/* Mutes the selected POKEY channels.
251 This is only useful for people who want to grab samples of individual
252 instruments.
253 "ast" is ASAP state after calling ASAP_PlaySong().
254 "mask" is a bit mask which selects POKEY channels to be muted.
255 Bits 0-3 control the base POKEY channels,
256 bits 4-7 control the extra POKEY channels. */
257void ASAP_MutePokeyChannels(ASAP_State *ast, int mask);
258
259/* Returns current position in milliseconds.
260 "ast" is ASAP state initialized by ASAP_PlaySong(). */
261int ASAP_GetPosition(const ASAP_State *ast);
262
263/* Rewinds the current song.
264 "ast" is ASAP state initialized by ASAP_PlaySong().
265 "position" is the requested absolute position in milliseconds. */
266void ASAP_Seek(ASAP_State *ast, int position);
267
268/* Fills the specified buffer with WAV file header.
269 "ast" is ASAP state initialized by ASAP_PlaySong() with a positive "duration".
270 "buffer" is buffer of ASAP_WAV_HEADER_BYTES bytes.
271 "format" is the format of samples. */
272void ASAP_GetWavHeader(const ASAP_State *ast, byte buffer[],
273 ASAP_SampleFormat format);
274
275/* Fills the specified buffer with generated samples.
276 "ast" is ASAP state initialized by ASAP_PlaySong().
277 "buffer" is the destination buffer.
278 "buffer_len" is the length of this buffer in bytes.
279 "format" is the format of samples.
280 ASAP_Generate() returns number of bytes actually written
281 (less than buffer_len if reached the end of the song).
282 Normally you use a buffer of a few kilobytes or less,
283 and call ASAP_Generate() in a loop or via a callback. */
284int ASAP_Generate(ASAP_State *ast, void *buffer, int buffer_len,
285 ASAP_SampleFormat format);
286
287/* Checks whether information in the specified file can be edited. */
288abool ASAP_CanSetModuleInfo(const char *filename);
289
290/* Updates the specified module with author, name, date, stereo
291 and song durations as specified in "module_info".
292 "module_info" contains the new module information.
293 "module" is the source file contents.
294 "module_len" is the source file length.
295 "out_module" is the destination buffer of size ASAP_MODULE_MAX.
296 ASAP_SetModuleInfo() returns the resulting file length (number of bytes
297 written to "out_module") or -1 if illegal characters were found. */
298int ASAP_SetModuleInfo(const ASAP_ModuleInfo *module_info, const byte module[],
299 int module_len, byte out_module[]);
300
301/* Checks whether the specified module can be converted to another format.
302 "filename" determines the source format.
303 "module_info" contains the information about the source module,
304 with possibly modified public fields.
305 "module" is the source file contents.
306 "module_len" is the source file length.
307 ASAP_CanConvert() returns the extension of the target format
308 or NULL if there's no possible conversion. */
309const char *ASAP_CanConvert(const char *filename, const ASAP_ModuleInfo *module_info,
310 const byte module[], int module_len);
311
312/* Converts the specified module to the format returned by ASAP_CanConvert().
313 "filename" determines the source format.
314 "module_info" contains the information about the source module,
315 with possibly modified public fields.
316 "module" is the source file contents.
317 "module_len" is the source file length.
318 "out_module" is the destination buffer of size ASAP_MODULE_MAX.
319 ASAP_Convert() returns the resulting file length (number of bytes
320 written to "out_module") or -1 on error. */
321int ASAP_Convert(const char *filename, const ASAP_ModuleInfo *module_info,
322 const byte module[], int module_len, byte out_module[]);
323
324#ifdef __cplusplus
325}
326#endif
327
328#endif
diff --git a/lib/rbcodec/codecs/libasap/asap_internal.h b/lib/rbcodec/codecs/libasap/asap_internal.h
new file mode 100644
index 0000000000..def444bc2f
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/asap_internal.h
@@ -0,0 +1,115 @@
1/*
2 * asap_internal.h - private interface of ASAP
3 *
4 * Copyright (C) 2005-2010 Piotr Fusik
5 *
6 * This file is part of ASAP (Another Slight Atari Player),
7 * see http://asap.sourceforge.net
8 *
9 * ASAP is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published
11 * by the Free Software Foundation; either version 2 of the License,
12 * or (at your option) any later version.
13 *
14 * ASAP is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ASAP; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _ASAP_INTERNAL_H_
25#define _ASAP_INTERNAL_H_
26
27#include "anylang.h"
28
29#ifndef C
30
31#define ASAP_SONGS_MAX 32
32#define ASAP_SAMPLE_RATE 44100
33
34#endif
35
36#ifdef JAVA
37
38#define ASAP_FORMAT_U8 8
39#define ASAP_FORMAT_S16_LE 16
40#define ASAP_FORMAT_S16_BE -16
41#define ASAP_SampleFormat int
42
43#elif defined(CSHARP) || defined(JAVASCRIPT)
44
45#define ASAP_FORMAT_U8 ASAP_SampleFormat.U8
46#define ASAP_FORMAT_S16_LE ASAP_SampleFormat.S16LE
47#define ASAP_FORMAT_S16_BE ASAP_SampleFormat.S16BE
48
49#elif defined(ACTIONSCRIPT)
50
51#define ASAP_SampleFormat int
52
53#else /* C */
54
55#include "asap.h"
56
57int ASAP_GetByte(ASAP_State *ast, int addr);
58void ASAP_PutByte(ASAP_State *ast, int addr, int data);
59
60void Cpu_RunScanlines(ASAP_State *ast, int scanlines);
61
62void PokeySound_Initialize(ASAP_State *ast);
63void PokeySound_StartFrame(ASAP_State *ast);
64void PokeySound_PutByte(ASAP_State *ast, int addr, int data);
65int PokeySound_GetRandom(ASAP_State *ast, int addr, int cycle);
66void PokeySound_EndFrame(ASAP_State *ast, int cycle_limit);
67int PokeySound_Generate(ASAP_State *ast, byte buffer[], int buffer_offset, int blocks, ASAP_SampleFormat format);
68abool PokeySound_IsSilent(const PokeyState *pst);
69void PokeySound_Mute(const ASAP_State *ast, PokeyState *pst, int mask);
70
71#ifdef ASAPSCAN
72abool call_6502_player(ASAP_State *ast);
73extern int cpu_trace;
74void trace_cpu(const ASAP_State *ast, int pc, int a, int x, int y, int s, int nz, int vdi, int c);
75#endif
76
77#endif /* C */
78
79#define V_FLAG 0x40
80#define D_FLAG 0x08
81#define I_FLAG 0x04
82#define Z_FLAG 0x02
83
84#define NEVER 0x800000
85
86#define DELTA_SHIFT_POKEY 20
87#define DELTA_SHIFT_GTIA 20
88#define DELTA_SHIFT_COVOX 17
89
90/* 6502 player types */
91#define ASAP_TYPE_SAP_B 1
92#define ASAP_TYPE_SAP_C 2
93#define ASAP_TYPE_SAP_D 3
94#define ASAP_TYPE_SAP_S 4
95#define ASAP_TYPE_CMC 5
96#define ASAP_TYPE_CM3 6
97#define ASAP_TYPE_CMR 7
98#define ASAP_TYPE_CMS 8
99#define ASAP_TYPE_DLT 9
100#define ASAP_TYPE_MPT 10
101#define ASAP_TYPE_RMT 11
102#define ASAP_TYPE_TMC 12
103#define ASAP_TYPE_TM2 13
104
105#define dGetByte(addr) UBYTE(ast _ memory[addr])
106#define dPutByte(addr, data) ast _ memory[addr] = CAST(byte) (data)
107#define dGetWord(addr) (dGetByte(addr) + (dGetByte((addr) + 1) << 8))
108#define GetByte(addr) (((addr) & 0xf900) == 0xd000 ? ASAP_GetByte(ast, addr) : dGetByte(addr))
109#define PutByte(addr, data) do { if (((addr) & 0xf900) == 0xd000) ASAP_PutByte(ast, addr, data); else dPutByte(addr, data); } while (FALSE)
110#define RMW_GetByte(dest, addr) do { if (((addr) >> 8) == 0xd2) { dest = ASAP_GetByte(ast, addr); ast _ cycle--; ASAP_PutByte(ast, addr, dest); ast _ cycle++; } else dest = dGetByte(addr); } while (FALSE)
111
112#define ASAP_MAIN_CLOCK(ast) ((ast) _ module_info->ntsc ? 1789772 : 1773447)
113#define CYCLE_TO_SAMPLE(cycle) TO_INT(((cycle) * ASAP_SAMPLE_RATE + ast _ sample_offset) / ASAP_MAIN_CLOCK(ast))
114
115#endif /* _ASAP_INTERNAL_H_ */
diff --git a/lib/rbcodec/codecs/libasap/libasap.make b/lib/rbcodec/codecs/libasap/libasap.make
new file mode 100644
index 0000000000..cbf461d4fb
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/libasap.make
@@ -0,0 +1,18 @@
1# __________ __ ___.
2# Open \______ \ ____ ____ | | _\_ |__ _______ ___
3# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
4# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
5# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
6# \/ \/ \/ \/ \/
7# $Id$
8#
9
10# libasap
11ASAPLIB := $(CODECDIR)/libasap.a
12ASAPLIB_SRC := $(call preprocess, $(RBCODECLIB_DIR)/codecs/libasap/SOURCES)
13ASAPLIB_OBJ := $(call c2obj, $(ASAPLIB_SRC))
14OTHER_SRC += $(ASAPLIB_SRC)
15
16$(ASAPLIB): $(ASAPLIB_OBJ)
17 $(SILENT)$(shell rm -f $@)
18 $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
diff --git a/lib/rbcodec/codecs/libasap/players.h b/lib/rbcodec/codecs/libasap/players.h
new file mode 100644
index 0000000000..fb90b0c76a
--- /dev/null
+++ b/lib/rbcodec/codecs/libasap/players.h
@@ -0,0 +1,1386 @@
1CONST_ARRAY(byte, cmc_obx)
2 255,255,0,5,220,12,76,15,11,76,120,5,76,203,7,0,
3 0,0,0,0,0,0,0,0,160,227,237,227,160,240,236,225,
4 249,229,242,160,246,160,178,174,177,160,0,0,0,0,0,0,
5 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,
6 255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
7 0,128,128,128,128,0,0,0,0,0,0,0,0,0,0,0,
8 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
9 0,0,0,0,0,0,0,0,0,0,0,0,0,0,141,110,
10 5,142,111,5,140,112,5,41,112,74,74,74,170,189,145,11,
11 141,169,5,189,146,11,141,170,5,169,3,141,15,210,216,165,
12 254,72,165,255,72,172,112,5,174,111,5,173,110,5,32,178,
13 5,104,133,255,104,133,254,96,173,118,5,133,254,173,119,5,
14 133,255,160,0,138,240,28,177,254,201,143,240,4,201,239,208,
15 12,202,208,9,200,192,84,176,9,152,170,16,6,200,192,84,
16 144,229,96,142,104,5,32,123,6,169,0,162,9,157,69,5,
17 202,16,250,141,103,5,169,1,141,113,5,169,255,141,106,5,
18 173,114,5,133,254,173,115,5,133,255,160,19,177,254,170,173,
19 118,5,133,254,173,119,5,133,255,172,104,5,177,254,201,207,
20 208,13,152,24,105,85,168,177,254,48,15,170,76,52,6,201,
21 143,240,7,201,239,240,3,136,16,226,142,108,5,142,109,5,
22 96,41,15,240,245,142,218,10,142,240,10,142,255,10,140,219,
23 10,140,241,10,140,0,11,96,142,114,5,134,254,140,115,5,
24 132,255,24,138,105,20,141,116,5,152,105,0,141,117,5,142,
25 118,5,200,200,140,119,5,160,19,177,254,141,108,5,141,109,
26 5,162,8,169,0,141,113,5,157,0,210,224,3,176,8,157,
27 9,5,169,255,157,57,5,202,16,233,169,128,162,3,157,75,
28 5,202,16,250,96,169,1,141,113,5,169,0,240,238,41,3,
29 201,3,240,240,224,64,176,236,192,26,176,232,170,169,128,157,
30 75,5,169,0,157,57,5,157,60,5,157,63,5,173,111,5,
31 157,12,5,173,112,5,10,10,10,133,254,24,173,114,5,105,
32 48,72,173,115,5,105,1,168,104,24,101,254,157,97,5,152,
33 105,0,157,100,5,24,173,114,5,105,148,133,254,173,115,5,
34 105,0,133,255,173,112,5,10,109,112,5,10,168,177,254,157,
35 79,5,200,177,254,157,82,5,41,7,141,110,5,200,177,254,
36 157,85,5,200,177,254,157,88,5,200,177,254,157,91,5,200,
37 177,254,157,94,5,160,0,173,110,5,201,3,208,2,160,2,
38 201,7,208,2,160,4,185,175,11,133,254,185,176,11,133,255,
39 189,85,5,74,74,74,74,24,109,111,5,141,111,5,141,194,
40 7,168,173,110,5,201,7,208,15,152,10,168,177,254,157,45,
41 5,200,140,111,5,76,131,7,177,254,157,45,5,189,85,5,
42 41,15,24,109,111,5,141,111,5,172,111,5,173,110,5,201,
43 5,8,177,254,40,240,8,221,45,5,208,3,56,233,1,157,
44 48,5,189,79,5,72,41,3,168,185,181,11,157,54,5,104,
45 74,74,74,74,160,62,201,15,240,16,160,55,201,14,240,10,
46 160,48,201,13,240,4,24,105,0,168,185,185,11,157,51,5,
47 96,216,165,252,72,165,253,72,165,254,72,165,255,72,173,113,
48 5,208,3,76,2,11,173,78,5,240,3,76,107,9,173,108,
49 5,205,109,5,240,3,76,88,9,173,103,5,240,3,76,220,
50 8,162,2,188,75,5,48,3,157,75,5,157,69,5,202,16,
51 242,173,118,5,133,252,173,119,5,133,253,172,104,5,132,254,
52 204,106,5,208,25,173,107,5,240,20,173,104,5,172,105,5,
53 140,104,5,206,107,5,208,232,141,104,5,168,16,226,162,0,
54 177,252,201,254,208,14,172,104,5,200,196,254,240,67,140,104,
55 5,76,26,8,157,66,5,24,152,105,85,168,232,224,3,144,
56 223,172,104,5,177,252,16,122,201,255,240,118,74,74,74,41,
57 14,170,189,161,11,141,126,8,189,162,11,141,127,8,173,67,
58 5,133,255,32,147,8,140,104,5,192,85,176,4,196,254,208,
59 143,164,254,140,104,5,76,2,11,32,148,6,160,255,96,48,
60 251,168,96,48,247,56,152,229,255,168,96,48,239,24,152,101,
61 255,168,96,48,231,141,108,5,141,109,5,200,96,48,221,173,
62 68,5,48,216,141,107,5,200,140,105,5,24,152,101,255,141,
63 106,5,96,136,48,10,177,252,201,143,240,4,201,239,208,243,
64 200,96,162,2,189,72,5,240,5,222,72,5,16,99,189,75,
65 5,208,94,188,66,5,192,64,176,87,173,116,5,133,252,173,
66 117,5,133,253,177,252,133,254,24,152,105,64,168,177,252,133,
67 255,37,254,201,255,240,58,188,69,5,177,254,41,192,208,12,
68 177,254,41,63,157,15,5,254,69,5,16,235,201,64,208,19,
69 177,254,41,63,141,111,5,189,15,5,141,112,5,32,188,6,
70 76,72,9,201,128,208,10,177,254,41,63,157,72,5,254,69,
71 5,202,16,144,174,103,5,232,138,41,63,141,103,5,206,109,
72 5,208,14,173,108,5,141,109,5,173,103,5,208,3,238,104,
73 5,172,48,5,173,82,5,41,7,201,5,240,4,201,6,208,
74 1,136,140,39,5,160,0,201,5,240,4,201,6,208,2,160,
75 2,201,7,208,2,160,40,140,44,5,162,2,189,82,5,41,
76 224,157,40,5,189,97,5,133,252,189,100,5,133,253,189,57,
77 5,201,255,240,54,201,15,208,32,189,63,5,240,45,222,63,
78 5,189,63,5,208,37,188,9,5,240,1,136,152,157,9,5,
79 189,88,5,157,63,5,76,229,9,189,57,5,74,168,177,252,
80 144,4,74,74,74,74,41,15,157,9,5,188,45,5,189,82,
81 5,41,7,201,1,208,31,136,152,200,221,48,5,8,169,1,
82 40,208,2,10,10,61,60,5,240,12,188,48,5,192,255,208,
83 5,169,0,157,9,5,152,157,36,5,169,1,141,110,5,189,
84 57,5,201,15,240,56,41,7,168,185,205,12,133,254,189,57,
85 5,41,8,8,138,40,24,240,2,105,3,168,185,91,5,37,
86 254,240,27,189,51,5,157,36,5,142,110,5,202,16,8,141,
87 39,5,169,0,141,44,5,232,189,54,5,157,40,5,189,57,
88 5,41,15,201,15,240,16,254,57,5,189,57,5,201,15,208,
89 6,189,88,5,157,63,5,189,75,5,16,10,189,9,5,208,
90 5,169,64,157,75,5,254,60,5,160,0,189,82,5,74,74,
91 74,74,144,1,136,74,144,1,200,24,152,125,45,5,157,45,
92 5,189,48,5,201,255,208,2,160,0,24,152,125,48,5,157,
93 48,5,202,48,3,76,150,9,173,40,5,141,43,5,173,82,
94 5,41,7,170,160,3,173,110,5,240,3,188,213,12,152,72,
95 185,185,12,8,41,127,170,152,41,3,10,168,189,36,5,153,
96 0,210,200,189,9,5,224,3,208,3,173,9,5,29,40,5,
97 40,16,2,169,0,153,0,210,104,168,136,41,3,208,207,160,
98 8,173,44,5,153,0,210,24,104,133,255,104,133,254,104,133,
99 253,104,133,252,96,104,170,240,78,201,2,240,6,104,104,202,
100 208,251,96,165,20,197,20,240,252,173,36,2,201,134,208,7,
101 173,37,2,201,11,240,230,173,36,2,141,143,11,173,37,2,
102 141,144,11,169,134,141,36,2,169,11,141,37,2,104,104,240,
103 3,56,233,1,141,93,11,104,168,104,170,169,112,32,120,5,
104 169,0,162,0,76,120,5,165,20,197,20,240,252,173,36,2,
105 201,134,208,174,173,37,2,201,11,208,167,173,143,11,141,36,
106 2,173,144,11,141,37,2,169,64,76,120,5,32,203,7,144,
107 3,32,117,11,76,255,255,178,5,221,5,168,6,59,6,123,
108 6,148,6,159,6,82,6,147,8,153,8,157,8,165,8,173,
109 8,183,8,205,8,185,11,250,11,59,12,128,160,32,64,255,
110 241,228,215,203,192,181,170,161,152,143,135,127,120,114,107,101,
111 95,90,85,80,75,71,67,63,60,56,53,50,47,44,42,39,
112 37,35,33,31,29,28,26,24,23,22,20,19,18,17,16,15,
113 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0,
114 0,0,0,0,242,233,218,206,191,182,170,161,152,143,137,128,
115 122,113,107,101,95,0,86,80,103,96,90,85,81,76,72,67,
116 63,61,57,52,51,57,45,42,40,37,36,33,31,30,0,0,
117 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
118 0,56,11,140,10,0,10,106,9,232,8,106,8,239,7,128,
119 7,8,7,174,6,70,6,230,5,149,5,65,5,246,4,176,
120 4,110,4,48,4,246,3,187,3,132,3,82,3,34,3,244,
121 2,200,2,160,2,122,2,85,2,52,2,20,2,245,1,216,
122 1,189,1,164,1,141,1,119,1,96,1,78,1,56,1,39,
123 1,21,1,6,1,247,0,232,0,219,0,207,0,195,0,184,
124 0,172,0,162,0,154,0,144,0,136,0,127,0,120,0,112,
125 0,106,0,100,0,94,0,87,0,82,0,50,0,10,0,0,
126 1,2,131,0,1,2,3,1,0,2,131,1,0,2,3,1,
127 2,128,3,128,64,32,16,8,4,2,1,3,3,3,3,7,
128 11,15,19
129END_CONST_ARRAY;
130CONST_ARRAY(byte, cm3_obx)
131 255,255,0,5,223,12,76,18,11,76,120,5,76,203,7,0,
132 0,0,0,0,0,0,0,0,160,227,237,227,160,240,236,225,
133 249,229,242,160,246,160,178,174,177,160,0,0,0,0,0,0,
134 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,
135 255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
136 0,128,128,128,128,0,0,0,0,0,0,0,0,0,0,0,
137 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
138 0,0,0,0,0,0,0,0,0,0,0,0,0,0,141,110,
139 5,142,111,5,140,112,5,41,112,74,74,74,170,189,148,11,
140 141,169,5,189,149,11,141,170,5,169,3,141,15,210,216,165,
141 254,72,165,255,72,172,112,5,174,111,5,173,110,5,32,178,
142 5,104,133,255,104,133,254,96,173,118,5,133,254,173,119,5,
143 133,255,160,0,138,240,28,177,254,201,143,240,4,201,239,208,
144 12,202,208,9,200,192,84,176,9,152,170,16,6,200,192,84,
145 144,229,96,142,104,5,32,123,6,169,0,162,9,157,69,5,
146 202,16,250,141,103,5,169,1,141,113,5,169,255,141,106,5,
147 173,114,5,133,254,173,115,5,133,255,160,19,177,254,170,173,
148 118,5,133,254,173,119,5,133,255,172,104,5,177,254,201,207,
149 208,13,152,24,105,85,168,177,254,48,15,170,76,52,6,201,
150 143,240,7,201,239,240,3,136,16,226,142,108,5,142,109,5,
151 96,41,15,240,245,142,221,10,142,243,10,142,2,11,140,222,
152 10,140,244,10,140,3,11,96,142,114,5,134,254,140,115,5,
153 132,255,24,138,105,20,141,116,5,152,105,0,141,117,5,142,
154 118,5,200,200,140,119,5,160,19,177,254,141,108,5,141,109,
155 5,162,8,169,0,141,113,5,157,0,210,224,3,176,8,157,
156 9,5,169,255,157,57,5,202,16,233,169,128,162,3,157,75,
157 5,202,16,250,96,169,1,141,113,5,169,0,240,238,41,3,
158 201,3,240,240,224,64,176,236,192,26,176,232,170,169,128,157,
159 75,5,169,0,157,57,5,157,60,5,157,63,5,173,111,5,
160 157,12,5,173,112,5,10,10,10,133,254,24,173,114,5,105,
161 48,72,173,115,5,105,1,168,104,24,101,254,157,97,5,152,
162 105,0,157,100,5,24,173,114,5,105,148,133,254,173,115,5,
163 105,0,133,255,173,112,5,10,109,112,5,10,168,177,254,157,
164 79,5,200,177,254,157,82,5,41,7,141,110,5,200,177,254,
165 157,85,5,200,177,254,157,88,5,200,177,254,157,91,5,200,
166 177,254,157,94,5,160,0,173,110,5,201,3,208,2,160,2,
167 201,7,208,2,160,4,185,178,11,133,254,185,179,11,133,255,
168 189,85,5,74,74,74,74,24,109,111,5,141,111,5,141,194,
169 7,168,173,110,5,201,7,208,15,152,10,168,177,254,157,45,
170 5,200,140,111,5,76,131,7,177,254,157,45,5,189,85,5,
171 41,15,24,109,111,5,141,111,5,172,111,5,173,110,5,201,
172 5,8,177,254,40,240,8,221,45,5,208,3,56,233,1,157,
173 48,5,189,79,5,72,41,3,168,185,184,11,157,54,5,104,
174 74,74,74,74,160,62,201,15,240,16,160,55,201,14,240,10,
175 160,48,201,13,240,4,24,105,0,168,185,188,11,157,51,5,
176 96,216,165,252,72,165,253,72,165,254,72,165,255,72,173,113,
177 5,208,3,76,5,11,173,78,5,240,3,76,110,9,173,108,
178 5,205,109,5,240,3,76,91,9,173,103,5,240,3,76,220,
179 8,162,2,188,75,5,48,3,157,75,5,157,69,5,202,16,
180 242,173,118,5,133,252,173,119,5,133,253,172,104,5,132,254,
181 204,106,5,208,25,173,107,5,240,20,173,104,5,172,105,5,
182 140,104,5,206,107,5,208,232,141,104,5,168,16,226,162,0,
183 177,252,201,254,208,14,172,104,5,200,196,254,240,67,140,104,
184 5,76,26,8,157,66,5,24,152,105,85,168,232,224,3,144,
185 223,172,104,5,177,252,16,122,201,255,240,118,74,74,74,41,
186 14,170,189,164,11,141,126,8,189,165,11,141,127,8,173,67,
187 5,133,255,32,147,8,140,104,5,192,85,176,4,196,254,208,
188 143,164,254,140,104,5,76,5,11,32,148,6,160,255,96,48,
189 251,168,96,48,247,56,152,229,255,168,96,48,239,24,152,101,
190 255,168,96,48,231,141,108,5,141,109,5,200,96,48,221,173,
191 68,5,48,216,141,107,5,200,140,105,5,24,152,101,255,141,
192 106,5,96,136,48,10,177,252,201,143,240,4,201,239,208,243,
193 200,96,162,2,189,72,5,240,5,222,72,5,16,99,189,75,
194 5,208,94,188,66,5,192,64,176,87,173,116,5,133,252,173,
195 117,5,133,253,177,252,133,254,24,152,105,64,168,177,252,133,
196 255,37,254,201,255,240,58,188,69,5,177,254,41,192,208,12,
197 177,254,41,63,157,15,5,254,69,5,16,235,201,64,208,19,
198 177,254,41,63,141,111,5,189,15,5,141,112,5,32,188,6,
199 76,72,9,201,128,208,10,177,254,41,63,157,72,5,254,69,
200 5,202,16,144,174,103,5,232,224,48,144,2,162,0,142,103,
201 5,206,109,5,208,14,173,108,5,141,109,5,173,103,5,208,
202 3,238,104,5,172,48,5,173,82,5,41,7,201,5,240,4,
203 201,6,208,1,136,140,39,5,160,0,201,5,240,4,201,6,
204 208,2,160,2,201,7,208,2,160,40,140,44,5,162,2,189,
205 82,5,41,224,157,40,5,189,97,5,133,252,189,100,5,133,
206 253,189,57,5,201,255,240,54,201,15,208,32,189,63,5,240,
207 45,222,63,5,189,63,5,208,37,188,9,5,240,1,136,152,
208 157,9,5,189,88,5,157,63,5,76,232,9,189,57,5,74,
209 168,177,252,144,4,74,74,74,74,41,15,157,9,5,188,45,
210 5,189,82,5,41,7,201,1,208,31,136,152,200,221,48,5,
211 8,169,1,40,208,2,10,10,61,60,5,240,12,188,48,5,
212 192,255,208,5,169,0,157,9,5,152,157,36,5,169,1,141,
213 110,5,189,57,5,201,15,240,56,41,7,168,185,208,12,133,
214 254,189,57,5,41,8,8,138,40,24,240,2,105,3,168,185,
215 91,5,37,254,240,27,189,51,5,157,36,5,142,110,5,202,
216 16,8,141,39,5,169,0,141,44,5,232,189,54,5,157,40,
217 5,189,57,5,41,15,201,15,240,16,254,57,5,189,57,5,
218 201,15,208,6,189,88,5,157,63,5,189,75,5,16,10,189,
219 9,5,208,5,169,64,157,75,5,254,60,5,160,0,189,82,
220 5,74,74,74,74,144,1,136,74,144,1,200,24,152,125,45,
221 5,157,45,5,189,48,5,201,255,208,2,160,0,24,152,125,
222 48,5,157,48,5,202,48,3,76,153,9,173,40,5,141,43,
223 5,173,82,5,41,7,170,160,3,173,110,5,240,3,188,216,
224 12,152,72,185,188,12,8,41,127,170,152,41,3,10,168,189,
225 36,5,153,0,210,200,189,9,5,224,3,208,3,173,9,5,
226 29,40,5,40,16,2,169,0,153,0,210,104,168,136,41,3,
227 208,207,160,8,173,44,5,153,0,210,24,104,133,255,104,133,
228 254,104,133,253,104,133,252,96,104,170,240,78,201,2,240,6,
229 104,104,202,208,251,96,165,20,197,20,240,252,173,36,2,201,
230 137,208,7,173,37,2,201,11,240,230,173,36,2,141,146,11,
231 173,37,2,141,147,11,169,137,141,36,2,169,11,141,37,2,
232 104,104,240,3,56,233,1,141,96,11,104,168,104,170,169,112,
233 32,120,5,169,0,162,0,76,120,5,165,20,197,20,240,252,
234 173,36,2,201,137,208,174,173,37,2,201,11,208,167,173,146,
235 11,141,36,2,173,147,11,141,37,2,169,64,76,120,5,32,
236 203,7,144,3,32,120,11,76,255,255,178,5,221,5,168,6,
237 59,6,123,6,148,6,159,6,82,6,147,8,153,8,157,8,
238 165,8,173,8,183,8,205,8,188,11,253,11,62,12,128,160,
239 32,64,255,241,228,215,203,192,181,170,161,152,143,135,127,120,
240 114,107,101,95,90,85,80,75,71,67,63,60,56,53,50,47,
241 44,42,39,37,35,33,31,29,28,26,24,23,22,20,19,18,
242 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,
243 1,0,0,0,0,0,0,242,233,218,206,191,182,170,161,152,
244 143,137,128,122,113,107,101,95,0,86,80,103,96,90,85,81,
245 76,72,67,63,61,57,52,51,57,45,42,40,37,36,33,31,
246 30,0,0,15,14,13,12,11,10,9,8,7,6,5,4,3,
247 2,1,0,0,56,11,140,10,0,10,106,9,232,8,106,8,
248 239,7,128,7,8,7,174,6,70,6,230,5,149,5,65,5,
249 246,4,176,4,110,4,48,4,246,3,187,3,132,3,82,3,
250 34,3,244,2,200,2,160,2,122,2,85,2,52,2,20,2,
251 245,1,216,1,189,1,164,1,141,1,119,1,96,1,78,1,
252 56,1,39,1,21,1,6,1,247,0,232,0,219,0,207,0,
253 195,0,184,0,172,0,162,0,154,0,144,0,136,0,127,0,
254 120,0,112,0,106,0,100,0,94,0,87,0,82,0,50,0,
255 10,0,0,1,2,131,0,1,2,3,1,0,2,131,1,0,
256 2,3,1,2,128,3,128,64,32,16,8,4,2,1,3,3,
257 3,3,7,11,15,19
258END_CONST_ARRAY;
259CONST_ARRAY(byte, cms_obx)
260 255,255,0,5,186,15,234,234,234,76,21,8,76,92,15,35,
261 5,169,5,173,5,184,5,0,0,0,0,0,0,0,0,0,
262 0,0,0,128,128,128,128,128,128,0,0,0,0,0,0,255,
263 255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,
264 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
265 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
266 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
267 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
268 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
269 0,0,0,0,0,0,0,0,0,0,130,0,0,6,6,0,
270 128,20,128,128,0,0,0,0,0,0,0,0,0,0,0,15,
271 15,0,0,0,0,0,0,0,0,255,0,0,0,0,0,0,
272 1,2,131,0,1,2,3,1,0,2,131,1,0,2,3,1,
273 2,128,3,128,64,32,16,8,4,2,1,75,8,118,8,133,
274 9,19,9,80,9,110,9,124,9,26,9,128,160,32,64,255,
275 241,228,215,203,192,181,170,161,152,143,135,127,120,114,107,101,
276 95,90,85,80,75,71,67,63,60,56,53,50,47,44,42,39,
277 37,35,33,31,29,28,26,24,23,22,20,19,18,17,16,15,
278 14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,0,
279 0,0,0,0,242,233,218,206,191,182,170,161,152,143,137,128,
280 122,113,107,101,95,0,86,80,103,96,90,85,81,76,72,67,
281 63,61,57,52,51,57,45,42,40,37,36,33,31,30,0,0,
282 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0,
283 0,56,11,140,10,0,10,106,9,232,8,106,8,239,7,128,
284 7,8,7,174,6,70,6,230,5,149,5,65,5,246,4,176,
285 4,110,4,48,4,246,3,187,3,132,3,82,3,34,3,244,
286 2,200,2,160,2,122,2,85,2,52,2,20,2,245,1,216,
287 1,189,1,164,1,141,1,119,1,96,1,78,1,56,1,39,
288 1,21,1,6,1,247,0,232,0,219,0,207,0,195,0,184,
289 0,172,0,162,0,154,0,144,0,136,0,127,0,120,0,112,
290 0,106,0,100,0,94,0,87,0,82,0,50,0,10,0,0,
291 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
292 0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,
293 0,0,0,1,1,1,1,1,1,1,1,2,2,2,2,0,
294 0,0,0,1,1,1,1,2,2,2,2,2,3,3,3,0,
295 0,1,1,1,2,2,2,2,2,3,3,3,3,4,4,0,
296 0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,0,
297 0,1,1,2,2,2,3,3,4,4,4,5,5,6,6,0,
298 0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,0,
299 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,0,
300 1,1,2,2,3,4,4,5,5,6,7,7,8,8,9,0,
301 1,1,2,3,3,4,5,5,6,7,7,8,9,9,10,0,
302 1,1,2,3,4,4,5,6,7,7,8,9,10,10,11,0,
303 1,2,2,3,4,5,6,7,8,9,9,10,11,11,12,0,
304 1,2,3,4,5,5,6,7,8,9,10,10,11,12,13,0,
305 1,2,3,4,5,6,7,7,8,9,10,11,12,13,14,0,
306 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,6,
307 12,12,12,18,12,28,12,38,12,50,12,79,12,233,5,42,
308 6,107,6,161,11,196,11,185,11,0,0,0,0,0,0,0,
309 0,0,0,3,3,3,3,7,11,15,19,141,143,5,142,144,
310 5,140,145,5,41,112,74,74,74,170,169,3,141,15,210,189,
311 213,5,141,73,8,189,214,5,141,74,8,169,3,141,31,210,
312 169,1,141,146,5,172,145,5,174,144,5,173,143,5,76,72,
313 8,173,147,5,133,252,173,148,5,133,253,160,0,138,240,28,
314 177,252,201,143,240,4,201,239,208,12,202,208,9,200,192,84,
315 176,9,152,170,16,6,200,192,84,144,229,96,142,149,5,169,
316 0,162,5,157,17,5,157,23,5,157,29,5,202,16,244,141,
317 150,5,141,157,5,160,255,140,159,5,173,153,5,133,252,173,
318 154,5,133,253,160,19,177,252,170,173,147,5,133,252,173,148,
319 5,133,253,172,149,5,152,72,169,15,141,169,5,141,170,5,
320 177,252,201,135,208,35,152,72,24,105,85,168,177,252,16,2,
321 169,15,41,15,141,169,5,152,24,105,85,168,177,252,16,3,
322 173,169,5,41,15,141,170,5,104,76,243,8,177,252,201,143,
323 240,7,201,239,240,3,136,16,199,104,168,177,252,201,207,208,
324 13,152,24,105,85,168,177,252,48,15,170,76,19,9,201,143,
325 240,7,201,239,240,3,136,16,226,142,151,5,142,152,5,96,
326 142,153,5,134,252,140,154,5,132,253,24,138,105,20,141,155,
327 5,152,105,0,141,156,5,24,138,105,0,141,147,5,152,105,
328 2,141,148,5,160,19,177,252,141,151,5,141,152,5,162,3,
329 142,31,210,142,15,210,169,0,141,146,5,160,8,169,0,153,
330 0,210,153,16,210,192,6,176,8,153,35,5,169,255,153,41,
331 5,136,16,233,169,128,162,5,157,29,5,202,16,250,141,157,
332 5,96,169,0,240,240,141,157,5,240,11,173,143,5,41,7,
333 170,169,128,157,29,5,172,145,5,173,144,5,141,143,5,140,
334 145,5,169,0,157,83,5,157,41,5,157,77,5,152,10,10,
335 10,133,254,24,173,153,5,105,48,72,173,154,5,105,1,168,
336 104,24,101,254,157,101,5,152,105,0,157,71,5,24,173,153,
337 5,105,148,133,252,173,154,5,105,0,133,253,173,145,5,10,
338 109,145,5,10,168,140,145,5,200,200,200,200,200,177,252,157,
339 113,5,136,177,252,157,107,5,136,177,252,157,119,5,136,136,
340 177,252,157,59,5,160,0,41,7,201,3,208,2,160,2,201,
341 7,208,2,160,4,185,247,7,133,254,185,248,7,133,255,172,
342 145,5,200,200,177,252,74,74,74,74,24,109,143,5,141,143,
343 5,141,159,10,168,189,59,5,41,7,201,7,208,15,152,10,
344 168,177,254,157,125,5,200,140,143,5,76,92,10,177,254,157,
345 125,5,172,145,5,200,200,177,252,41,15,24,109,143,5,141,
346 143,5,172,143,5,189,59,5,41,7,201,5,8,177,254,40,
347 240,8,221,125,5,208,3,56,233,1,157,89,5,172,145,5,
348 177,252,72,41,3,168,185,229,5,157,131,5,104,74,74,74,
349 74,160,62,201,15,240,16,160,55,201,14,240,10,160,48,201,
350 13,240,4,24,105,50,168,185,233,5,157,137,5,96,216,165,
351 252,72,165,253,72,165,254,72,165,255,72,173,146,5,208,3,
352 76,47,15,173,157,5,240,3,76,225,12,173,152,5,205,151,
353 5,176,3,76,206,12,173,150,5,240,3,76,158,11,162,5,
354 169,0,188,29,5,48,3,157,29,5,157,17,5,202,16,242,
355 173,147,5,133,252,173,148,5,133,253,172,149,5,140,161,5,
356 204,159,5,208,25,173,160,5,240,20,173,149,5,172,158,5,
357 140,149,5,206,160,5,208,232,141,149,5,168,16,226,162,0,
358 177,252,201,254,240,28,157,53,5,230,253,177,252,198,253,201,
359 254,240,15,157,56,5,24,152,105,85,168,232,224,3,144,224,
360 176,34,172,149,5,200,204,161,5,240,80,140,149,5,76,250,
361 10,104,41,14,170,189,253,7,141,135,11,189,254,7,141,136,
362 11,76,129,11,172,149,5,177,252,16,57,201,255,240,53,74,
363 74,74,72,41,1,240,218,104,41,14,170,189,233,7,141,135,
364 11,189,234,7,141,136,11,173,54,5,133,254,32,134,11,140,
365 149,5,192,85,176,5,204,161,5,208,179,172,161,5,140,149,
366 5,76,47,15,76,94,12,165,254,48,18,41,15,141,169,5,
367 173,55,5,16,3,173,169,5,41,15,141,170,5,200,96,165,
368 254,48,250,41,1,141,184,5,200,96,173,179,5,48,20,206,
369 180,5,208,51,169,50,141,180,5,206,179,5,208,41,206,179,
370 5,200,96,165,254,48,214,141,180,5,238,180,5,165,254,48,
371 204,141,180,5,238,180,5,173,55,5,141,179,5,16,5,169,
372 0,141,179,5,238,179,5,104,104,76,225,12,32,110,9,160,
373 255,96,165,254,48,249,168,96,165,254,48,243,56,152,229,254,
374 168,96,165,254,48,233,24,152,101,254,168,96,165,254,48,223,
375 141,151,5,141,152,5,200,96,165,254,48,211,173,55,5,48,
376 206,200,140,158,5,24,152,101,254,141,159,5,173,55,5,141,
377 160,5,192,84,96,136,48,10,177,252,201,143,240,4,201,239,
378 208,243,200,96,162,5,189,23,5,240,5,222,23,5,16,87,
379 189,29,5,208,82,188,53,5,201,64,176,75,173,155,5,133,
380 252,173,156,5,133,253,177,252,133,254,24,152,105,64,168,177,
381 252,133,255,188,17,5,177,254,41,192,208,12,177,254,41,63,
382 157,47,5,254,17,5,16,235,201,64,208,13,177,254,41,63,
383 188,47,5,32,150,9,76,190,12,201,128,208,10,177,254,41,
384 63,157,23,5,254,17,5,202,16,156,174,150,5,232,138,41,
385 63,141,150,5,206,152,5,208,14,173,151,5,141,152,5,173,
386 150,5,208,3,238,149,5,172,89,5,173,59,5,41,7,201,
387 5,240,4,201,6,208,1,136,140,162,5,160,0,201,5,240,
388 4,201,6,208,2,160,2,201,7,208,2,160,40,140,164,5,
389 172,92,5,173,62,5,41,7,201,5,240,4,201,6,208,1,
390 136,140,163,5,160,0,201,5,240,4,201,6,208,2,160,2,
391 201,7,208,2,160,40,140,165,5,162,5,189,59,5,41,224,
392 157,65,5,189,101,5,133,252,189,71,5,133,253,189,41,5,
393 201,255,240,55,201,15,208,33,189,77,5,240,46,222,77,5,
394 189,77,5,208,38,188,35,5,240,1,136,152,157,35,5,189,
395 119,5,157,77,5,136,76,133,13,189,41,5,74,168,177,252,
396 144,4,74,74,74,74,41,15,157,35,5,188,125,5,189,59,
397 5,41,7,201,1,208,31,136,152,200,221,89,5,8,169,1,
398 40,208,2,10,10,61,83,5,240,12,188,89,5,192,255,208,
399 5,169,0,157,35,5,152,157,95,5,169,1,141,168,5,189,
400 41,5,201,15,240,76,41,7,168,185,205,5,133,254,189,41,
401 5,41,8,8,138,40,24,240,2,105,6,168,185,107,5,37,
402 254,240,47,189,137,5,157,95,5,142,168,5,202,224,2,240,
403 15,224,255,208,22,141,162,5,169,0,141,164,5,76,5,14,
404 173,140,5,141,163,5,169,0,141,165,5,232,189,131,5,157,
405 65,5,189,41,5,41,15,201,15,240,18,254,41,5,189,41,
406 5,41,15,201,15,208,6,189,119,5,157,77,5,189,29,5,
407 16,10,189,35,5,208,5,169,64,157,29,5,254,83,5,160,
408 0,189,59,5,74,74,74,74,144,1,136,74,144,1,200,24,
409 152,125,125,5,157,125,5,189,89,5,201,255,208,2,160,0,
410 24,152,125,89,5,157,89,5,202,48,3,76,53,13,32,123,
411 15,173,65,5,141,166,5,173,68,5,141,167,5,173,59,5,
412 41,7,32,181,15,152,72,185,185,5,8,41,127,170,152,41,
413 3,10,168,224,3,208,3,76,196,14,189,173,5,208,39,189,
414 95,5,153,0,210,189,35,5,29,65,5,40,16,2,169,0,
415 153,1,210,104,168,136,41,3,240,3,76,127,14,173,164,5,
416 141,8,210,76,228,14,40,76,173,14,173,173,5,208,23,173,
417 162,5,153,0,210,173,35,5,13,166,5,40,16,2,169,0,
418 153,1,210,76,173,14,40,76,173,14,173,62,5,41,7,32,
419 181,15,152,72,185,185,5,8,41,127,170,152,41,3,10,168,
420 224,3,208,3,76,60,15,189,176,5,208,30,189,98,5,153,
421 16,210,189,38,5,29,68,5,40,16,2,169,0,153,17,210,
422 104,168,136,41,3,240,7,76,236,14,40,76,26,15,173,165,
423 5,141,24,210,24,104,133,255,104,133,254,104,133,253,104,133,
424 252,96,173,176,5,208,23,173,163,5,153,16,210,173,38,5,
425 13,167,5,40,16,2,169,0,153,17,210,76,26,15,40,76,
426 26,15,32,168,10,176,25,173,184,5,240,20,173,157,5,141,
427 183,5,169,1,141,157,5,32,168,10,173,183,5,141,157,5,
428 96,173,169,5,10,10,10,10,141,171,5,173,170,5,10,10,
429 10,10,141,172,5,162,2,134,200,173,171,5,29,35,5,170,
430 189,233,6,166,200,157,35,5,173,172,5,29,38,5,170,189,
431 233,6,166,200,157,38,5,202,16,221,96,168,185,13,8,168,
432 96
433END_CONST_ARRAY;
434CONST_ARRAY(byte, dlt_obx)
435 255,255,0,4,70,12,255,241,228,215,203,192,181,170,161,152,
436 143,135,127,121,114,107,101,95,90,85,80,75,71,67,63,60,
437 56,53,50,47,44,42,39,37,35,33,31,29,28,26,24,23,
438 22,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
439 5,4,255,241,228,215,242,233,218,206,191,182,170,161,152,143,
440 137,128,122,113,107,101,95,92,86,80,103,96,90,85,81,76,
441 72,67,63,61,57,52,51,48,45,42,40,37,36,33,31,30,
442 28,27,25,0,22,21,0,10,9,8,7,6,5,4,3,2,
443 1,0,242,233,218,206,242,233,218,206,191,182,170,161,152,143,
444 137,128,122,113,107,101,95,92,86,80,103,96,90,85,81,76,
445 72,67,63,61,57,52,51,48,45,42,40,37,36,33,31,30,
446 28,27,25,0,22,21,0,10,9,8,7,6,5,4,3,2,
447 1,0,242,233,218,206,255,241,228,216,202,192,181,171,162,153,
448 142,135,127,120,115,108,102,97,90,85,81,75,72,67,63,60,
449 57,52,51,48,45,42,40,37,36,33,31,30,28,27,25,23,
450 22,21,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
451 5,4,3,2,1,255,76,9,5,76,200,5,76,183,5,136,
452 140,54,3,169,126,141,53,3,162,6,142,51,3,162,1,142,
453 52,3,32,51,5,32,95,5,32,163,5,32,139,5,169,1,
454 141,50,3,169,3,141,15,210,96,162,0,160,32,142,48,3,
455 140,49,3,160,0,173,48,3,153,0,2,173,49,3,153,64,
456 2,173,48,3,24,105,128,141,48,3,144,3,238,49,3,200,
457 192,64,208,225,96,162,0,160,68,142,48,3,140,49,3,160,
458 0,173,48,3,153,128,2,173,49,3,153,160,2,173,48,3,
459 24,105,64,141,48,3,144,3,238,49,3,200,192,32,208,225,
460 96,173,0,76,41,1,74,106,106,168,162,0,185,128,4,157,
461 64,4,200,232,224,64,208,244,96,160,3,169,0,153,40,3,
462 153,32,3,153,36,3,153,44,3,136,16,241,96,169,0,141,
463 50,3,160,7,169,0,153,0,210,136,16,250,96,96,173,50,
464 3,240,250,173,40,3,13,41,3,13,42,3,13,43,3,141,
465 8,210,174,36,3,172,32,3,142,0,210,140,1,210,174,37,
466 3,172,33,3,142,2,210,140,3,210,174,38,3,172,34,3,
467 142,4,210,140,5,210,174,39,3,172,35,3,142,6,210,140,
468 7,210,206,52,3,208,74,173,51,3,141,52,3,238,53,3,
469 238,53,3,16,28,238,54,3,169,0,141,53,3,32,199,6,
470 173,4,3,13,5,3,13,6,3,13,7,3,208,3,76,183,
471 5,173,4,3,240,3,32,97,7,173,5,3,240,3,32,192,
472 7,173,6,3,240,3,32,31,8,173,7,3,240,3,32,126,
473 8,173,4,3,240,8,173,44,3,240,3,32,221,8,173,5,
474 3,240,8,173,45,3,240,3,32,206,9,173,6,3,240,8,
475 173,46,3,240,3,32,191,10,173,7,3,240,8,173,47,3,
476 240,3,32,131,11,96,192,67,144,14,169,0,141,4,3,141,
477 32,3,141,40,3,76,230,6,192,66,208,15,189,128,64,141,
478 51,3,141,52,3,238,54,3,76,199,6,192,65,208,9,189,
479 128,64,141,54,3,76,199,6,104,104,76,183,5,174,54,3,
480 188,0,64,192,64,176,191,189,128,64,141,24,3,185,0,2,
481 133,224,185,64,2,133,225,169,1,141,4,3,188,0,65,192,
482 64,176,78,189,128,65,141,25,3,185,0,2,133,226,185,64,
483 2,133,227,169,1,141,5,3,188,0,66,192,64,176,63,189,
484 128,66,141,26,3,185,0,2,133,228,185,64,2,133,229,169,
485 1,141,6,3,188,0,67,192,64,176,48,189,128,67,141,27,
486 3,185,0,2,133,230,185,64,2,133,231,169,1,141,7,3,
487 96,169,0,141,5,3,141,33,3,141,41,3,240,186,169,0,
488 141,6,3,141,34,3,141,42,3,240,201,169,0,141,7,3,
489 141,35,3,141,43,3,96,172,53,3,177,224,48,11,200,177,
490 224,48,1,96,104,104,76,31,6,24,109,24,3,41,127,141,
491 8,3,169,15,141,0,3,141,44,3,200,177,224,170,189,160,
492 2,133,233,133,241,133,249,189,128,2,133,232,73,16,133,240,
493 73,48,133,248,160,49,177,232,141,12,3,160,51,177,232,41,
494 127,141,16,3,169,0,141,20,3,141,28,3,160,48,177,232,
495 41,213,141,40,3,96,172,53,3,177,226,48,11,200,177,226,
496 48,1,96,104,104,76,31,6,24,109,25,3,41,127,141,9,
497 3,169,15,141,1,3,141,45,3,200,177,226,170,189,160,2,
498 133,235,133,243,133,251,189,128,2,133,234,73,16,133,242,73,
499 48,133,250,160,49,177,234,141,13,3,160,51,177,234,41,127,
500 141,17,3,169,0,141,21,3,141,29,3,160,48,177,234,41,
501 131,141,41,3,96,172,53,3,177,228,48,11,200,177,228,48,
502 1,96,104,104,76,31,6,24,109,26,3,41,127,141,10,3,
503 169,15,141,2,3,141,46,3,200,177,228,170,189,160,2,133,
504 237,133,245,133,253,189,128,2,133,236,73,16,133,244,73,48,
505 133,252,160,49,177,236,141,14,3,160,51,177,236,41,127,141,
506 18,3,169,0,141,22,3,141,30,3,160,48,177,236,41,169,
507 141,42,3,96,172,53,3,177,230,48,11,200,177,230,48,1,
508 96,104,104,76,31,6,24,109,27,3,41,127,141,11,3,169,
509 15,141,3,3,141,47,3,200,177,230,170,189,160,2,133,239,
510 133,247,133,255,189,128,2,133,238,73,16,133,246,73,48,133,
511 254,160,49,177,238,141,15,3,160,51,177,238,41,127,141,19,
512 3,169,0,141,23,3,141,31,3,160,48,177,238,41,129,141,
513 43,3,96,172,0,3,48,70,177,232,141,32,3,177,240,208,
514 9,32,108,9,206,0,3,76,79,9,201,1,240,39,201,3,
515 208,16,173,8,3,24,113,248,170,173,28,3,141,55,3,76,
516 24,9,173,28,3,24,113,248,141,55,3,174,8,3,32,150,
517 9,206,0,3,96,177,248,141,36,3,206,0,3,96,32,108,
518 9,160,49,177,232,240,30,206,12,3,240,3,76,79,9,173,
519 32,3,41,15,240,11,206,32,3,177,232,141,12,3,76,79,
520 9,141,44,3,96,173,28,3,24,160,50,113,232,141,28,3,
521 206,16,3,208,12,238,20,3,160,51,177,232,41,127,141,16,
522 3,96,173,20,3,41,3,24,105,52,168,177,232,170,160,51,
523 177,232,48,14,138,109,8,3,170,173,28,3,141,55,3,76,
524 150,9,138,109,28,3,141,55,3,174,8,3,189,0,4,24,
525 109,55,3,141,36,3,173,40,3,41,4,208,1,96,172,0,
526 3,177,240,208,21,138,24,160,0,113,248,170,189,0,4,24,
527 109,55,3,24,105,255,141,38,3,96,173,36,3,24,105,255,
528 141,38,3,96,172,1,3,48,70,177,234,141,33,3,177,242,
529 208,9,32,93,10,206,1,3,76,64,10,201,1,240,39,201,
530 3,208,16,173,9,3,24,113,250,170,173,29,3,141,55,3,
531 76,9,10,173,29,3,24,113,250,141,55,3,174,9,3,32,
532 135,10,206,1,3,96,177,250,141,37,3,206,1,3,96,32,
533 93,10,160,49,177,234,240,30,206,13,3,240,3,76,64,10,
534 173,33,3,41,15,240,11,206,33,3,177,234,141,13,3,76,
535 64,10,141,45,3,96,173,29,3,24,160,50,113,234,141,29,
536 3,206,17,3,208,12,238,21,3,160,51,177,234,41,127,141,
537 17,3,96,173,21,3,41,3,24,105,52,168,177,234,170,160,
538 51,177,234,48,14,138,109,9,3,170,173,29,3,141,55,3,
539 76,135,10,138,109,29,3,141,55,3,174,9,3,189,0,4,
540 24,109,55,3,141,37,3,173,41,3,41,2,208,1,96,172,
541 1,3,177,242,208,21,138,24,160,0,113,250,170,189,0,4,
542 24,109,55,3,24,105,255,141,39,3,96,173,37,3,24,105,
543 255,141,39,3,96,172,2,3,48,70,177,236,141,34,3,177,
544 244,208,9,32,78,11,206,2,3,76,49,11,201,1,240,39,
545 201,3,208,16,173,10,3,24,113,252,170,173,30,3,141,55,
546 3,76,250,10,173,30,3,24,113,252,141,55,3,174,10,3,
547 32,120,11,206,2,3,96,177,252,141,38,3,206,2,3,96,
548 32,78,11,160,49,177,236,240,30,206,14,3,240,3,76,49,
549 11,173,34,3,41,15,240,11,206,34,3,177,236,141,14,3,
550 76,49,11,141,46,3,96,173,30,3,24,160,50,113,236,141,
551 30,3,206,18,3,208,12,238,22,3,160,51,177,236,41,127,
552 141,18,3,96,173,22,3,41,3,24,105,52,168,177,236,170,
553 160,51,177,236,48,14,138,109,10,3,170,173,30,3,141,55,
554 3,76,120,11,138,109,30,3,141,55,3,174,10,3,189,0,
555 4,24,109,55,3,141,38,3,96,172,3,3,48,70,177,238,
556 141,35,3,177,246,208,9,32,18,12,206,3,3,76,245,11,
557 201,1,240,39,201,3,208,16,173,11,3,24,113,254,170,173,
558 31,3,141,55,3,76,190,11,173,31,3,24,113,254,141,55,
559 3,174,11,3,32,60,12,206,3,3,96,177,254,141,39,3,
560 206,3,3,96,32,18,12,160,49,177,238,240,30,206,15,3,
561 240,3,76,245,11,173,35,3,41,15,240,11,206,35,3,177,
562 238,141,15,3,76,245,11,141,47,3,96,173,31,3,24,160,
563 50,113,238,141,31,3,206,19,3,208,12,238,23,3,160,51,
564 177,238,41,127,141,19,3,96,173,23,3,41,3,24,105,52,
565 168,177,238,170,160,51,177,238,48,14,138,109,11,3,170,173,
566 31,3,141,55,3,76,60,12,138,109,31,3,141,55,3,174,
567 11,3,189,0,4,24,109,55,3,141,39,3,96
568END_CONST_ARRAY;
569CONST_ARRAY(byte, mpt_obx)
570 255,255,0,5,178,13,76,205,11,173,46,7,208,1,96,169,
571 0,141,28,14,238,29,14,173,23,14,205,187,13,144,80,206,
572 21,14,240,3,76,197,5,162,0,142,23,14,169,0,157,237,
573 13,157,245,13,189,179,13,133,236,189,183,13,133,237,172,22,
574 14,177,236,200,201,255,240,7,201,254,208,15,76,42,12,177,
575 236,48,249,10,168,140,22,14,76,59,5,157,233,13,177,236,
576 157,213,13,232,224,4,208,196,200,140,22,14,76,197,5,206,
577 21,14,16,87,173,188,13,141,21,14,162,3,222,245,13,16,
578 68,189,233,13,10,168,185,255,255,133,236,200,185,255,255,133,
579 237,5,236,240,48,189,237,13,141,31,14,32,62,7,172,31,
580 14,200,152,157,237,13,189,241,13,157,245,13,224,2,208,21,
581 189,197,13,73,15,10,10,10,10,105,69,141,161,13,169,10,
582 105,0,141,162,13,202,16,180,238,23,14,162,1,173,27,14,
583 201,2,240,2,162,3,173,27,14,201,2,208,5,236,25,14,
584 240,3,76,118,6,181,240,61,114,6,240,18,160,40,177,236,
585 24,125,225,13,32,117,9,56,125,1,14,157,203,13,202,16,
586 213,169,3,141,15,210,165,241,41,16,240,15,172,226,13,185,
587 198,9,141,201,13,185,5,10,141,202,13,173,201,13,141,0,
588 210,173,202,13,141,2,210,173,203,13,141,4,210,173,204,13,
589 141,6,210,173,193,13,162,255,172,27,14,192,1,208,5,174,
590 25,14,240,3,141,1,210,173,194,13,224,1,240,3,141,3,
591 210,192,2,240,20,173,195,13,224,2,240,3,141,5,210,173,
592 196,13,224,3,240,3,141,7,210,165,240,5,241,5,242,5,
593 243,13,28,14,141,8,210,96,4,2,0,0,189,217,13,133,
594 236,189,221,13,133,237,5,236,208,8,157,193,13,149,240,76,
595 248,5,180,244,192,32,240,66,177,236,56,253,197,13,44,58,
596 7,240,2,41,240,157,193,13,200,177,236,141,30,14,200,148,
597 244,41,7,240,60,168,185,126,9,141,203,6,185,133,9,141,
598 204,6,173,30,14,74,74,74,74,74,9,40,168,177,236,24,
599 32,255,255,169,0,149,240,76,248,5,189,9,14,240,18,222,
600 13,14,208,13,157,13,14,189,193,13,41,15,240,3,222,193,
601 13,160,35,177,236,149,240,189,17,14,24,105,37,168,41,3,
602 157,17,14,136,177,236,125,209,13,157,225,13,32,119,9,157,
603 201,13,189,5,14,240,6,222,5,14,76,223,5,189,189,13,
604 141,30,7,16,254,76,194,8,0,76,229,8,0,76,251,8,
605 0,76,21,9,0,76,37,9,0,76,56,9,0,76,66,9,
606 16,76,72,9,169,0,157,197,13,172,31,14,136,200,177,236,
607 201,254,208,4,140,31,14,96,201,224,144,8,173,187,13,141,
608 23,14,208,233,201,208,144,10,41,15,141,188,13,141,21,14,
609 16,219,201,192,144,9,41,15,73,15,157,197,13,16,206,201,
610 128,144,7,41,63,157,241,13,16,195,201,64,144,27,200,140,
611 31,14,41,31,157,229,13,10,168,185,255,255,157,217,13,200,
612 185,255,255,157,221,13,76,62,7,140,31,14,141,30,14,24,
613 125,213,13,157,209,13,173,27,14,240,66,201,2,240,58,189,
614 229,13,201,31,208,55,173,30,14,56,233,1,41,15,168,177,
615 254,133,253,152,9,16,168,177,254,133,248,160,1,5,253,208,
616 2,160,0,140,26,14,169,0,133,252,157,217,13,157,221,13,
617 138,10,141,24,14,142,25,14,96,224,2,176,99,189,217,13,
618 133,238,189,221,13,133,239,5,238,240,74,160,32,177,238,41,
619 15,157,249,13,177,238,41,112,74,74,157,189,13,200,177,238,
620 10,10,72,41,63,157,5,14,104,41,192,157,205,13,200,177,
621 238,157,9,14,157,13,14,169,0,149,244,157,17,14,157,253,
622 13,157,1,14,189,209,13,157,225,13,32,117,9,157,201,13,
623 236,25,14,240,1,96,160,255,140,25,14,200,140,26,14,96,
624 224,2,208,51,172,211,13,185,69,11,141,121,13,185,129,11,
625 141,127,13,169,0,133,249,133,250,173,231,13,41,15,168,177,
626 254,133,251,152,9,16,168,177,254,141,137,13,5,251,208,6,
627 141,121,13,141,127,13,96,173,232,13,41,15,168,177,254,133,
628 253,152,9,16,168,177,254,5,253,240,15,177,254,56,229,253,
629 133,248,169,0,133,252,169,141,208,2,169,173,141,97,13,141,
630 56,13,169,24,141,7,210,96,173,29,14,41,7,74,74,144,
631 18,208,24,189,249,13,24,157,1,14,125,201,13,157,201,13,
632 76,223,5,169,0,157,1,14,76,223,5,189,201,13,56,253,
633 249,13,157,201,13,56,169,0,253,249,13,157,1,14,76,223,
634 5,189,253,13,24,157,1,14,125,201,13,157,201,13,24,189,
635 253,13,125,249,13,157,253,13,76,223,5,189,225,13,56,253,
636 253,13,157,225,13,32,117,9,76,5,9,169,0,56,253,253,
637 13,157,1,14,189,201,13,56,253,253,13,76,5,9,189,225,
638 13,24,125,253,13,76,28,9,32,85,9,76,208,8,32,85,
639 9,24,125,225,13,32,155,9,76,223,5,188,253,13,189,249,
640 13,48,2,200,200,136,152,157,253,13,221,249,13,208,8,189,
641 249,13,73,255,157,249,13,189,253,13,96,41,63,29,205,13,
642 168,185,255,255,96,148,145,152,165,173,180,192,9,9,9,9,
643 9,9,9,64,0,32,0,125,201,13,157,201,13,96,125,209,
644 13,157,225,13,32,117,9,157,201,13,96,157,201,13,189,141,
645 9,16,12,157,201,13,169,128,208,5,157,201,13,169,1,13,
646 28,14,141,28,14,96,45,10,210,157,201,13,96,242,51,150,
647 226,56,140,0,106,232,106,239,128,8,174,70,230,149,65,246,
648 176,110,48,246,187,132,82,34,244,200,160,122,85,52,20,245,
649 216,189,164,141,119,96,78,56,39,21,6,247,232,219,207,195,
650 184,172,162,154,144,136,127,120,112,106,100,94,13,13,12,11,
651 11,10,10,9,8,8,7,7,7,6,6,5,5,5,4,4,
652 4,4,3,3,3,3,3,2,2,2,2,2,2,2,1,1,
653 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,
654 0,0,0,0,0,0,0,0,0,0,0,24,24,24,24,24,
655 24,24,24,24,24,24,24,24,24,24,24,22,22,23,23,23,
656 23,24,24,24,24,24,25,25,25,25,26,21,21,22,22,22,
657 23,23,24,24,24,25,25,26,26,26,27,20,21,21,22,22,
658 23,23,24,24,24,25,25,26,26,27,27,20,20,21,21,22,
659 22,23,23,24,25,25,26,26,27,27,28,19,20,20,21,22,
660 22,23,23,24,25,25,26,26,27,28,28,19,19,20,21,21,
661 22,23,23,24,25,25,26,27,27,28,29,18,19,20,20,21,
662 22,23,23,24,25,25,26,27,28,28,29,18,19,19,20,21,
663 22,22,23,24,25,26,26,27,28,29,29,18,18,19,20,21,
664 22,22,23,24,25,26,26,27,28,29,30,17,18,19,20,21,
665 22,22,23,24,25,26,26,27,28,29,30,17,18,19,20,21,
666 21,22,23,24,25,26,27,27,28,29,30,17,18,19,20,20,
667 21,22,23,24,25,26,27,28,28,29,30,17,18,19,19,20,
668 21,22,23,24,25,26,27,28,29,29,30,17,18,18,19,20,
669 21,22,23,24,25,26,27,28,29,30,30,16,17,18,19,20,
670 21,22,23,24,25,26,27,28,29,30,31,32,34,36,38,41,
671 43,46,48,51,55,58,61,65,69,73,77,82,87,92,97,103,
672 110,116,123,130,138,146,155,164,174,184,195,207,220,233,246,5,
673 21,37,55,73,93,113,135,159,184,210,237,11,42,75,110,147,
674 186,227,15,62,112,164,219,0,0,0,0,0,0,0,0,0,
675 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
676 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,
677 1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,
678 3,3,3,229,42,64,89,100,238,8,166,11,12,12,12,12,
679 12,13,13,142,50,7,140,54,7,41,7,168,185,189,11,141,
680 227,11,185,197,11,141,228,11,76,255,255,173,54,7,174,50,
681 7,141,148,7,141,155,7,142,149,7,142,156,7,24,105,64,
682 141,129,5,141,135,5,144,1,232,142,130,5,142,136,5,24,
683 105,128,141,124,9,144,1,232,142,125,9,232,141,31,12,142,
684 32,12,162,9,189,255,255,157,179,13,202,16,247,206,188,13,
685 169,0,141,46,7,162,98,157,189,13,202,16,250,162,8,157,
686 0,210,202,16,250,96,32,42,12,173,50,7,10,141,22,14,
687 173,187,13,141,23,14,169,1,141,21,14,141,46,7,96,173,
688 54,7,133,254,173,50,7,133,255,96,173,54,7,41,3,170,
689 173,50,7,32,198,7,173,26,14,240,238,14,54,7,32,190,
690 12,169,1,141,27,14,173,26,14,240,222,201,1,208,5,160,
691 0,238,26,14,177,252,174,24,14,74,74,74,74,9,16,141,
692 10,212,141,10,212,157,1,210,177,252,9,16,141,10,212,141,
693 10,212,157,1,210,200,208,206,230,253,165,253,197,248,208,198,
694 140,26,14,96,144,21,169,234,141,153,12,141,154,12,141,155,
695 12,141,166,12,141,167,12,141,168,12,96,169,141,141,153,12,
696 141,166,12,169,10,141,154,12,141,167,12,169,212,141,155,12,
697 141,168,12,96,169,0,141,26,14,173,50,7,74,32,190,12,
698 169,1,141,27,14,32,128,12,173,27,14,208,248,96,169,2,
699 141,27,14,141,25,14,169,24,141,7,210,169,17,133,250,169,
700 13,133,251,169,173,141,97,13,141,56,13,160,0,140,121,13,
701 140,127,13,174,11,212,177,252,74,74,74,74,9,16,141,7,
702 210,32,117,13,236,11,212,240,251,141,5,210,174,11,212,177,
703 252,230,252,208,16,230,253,198,248,208,10,169,173,141,97,13,
704 141,56,13,169,8,9,16,141,7,210,32,117,13,236,11,212,
705 240,251,141,5,210,173,27,14,208,185,96,24,165,249,105,0,
706 133,249,165,250,105,0,133,250,144,15,230,251,165,251,201,0,
707 208,7,140,121,13,140,127,13,96,177,250,36,249,48,4,74,
708 74,74,74,41,15,168,185,69,10,160,0,96,160,0,140,27,
709 14,140,26,14,136,140,25,14,96
710END_CONST_ARRAY;
711CONST_ARRAY(byte, rmt4_obx)
712 255,255,144,3,96,11,128,0,128,32,128,64,0,192,128,128,
713 128,160,0,192,64,192,0,1,5,11,21,0,1,255,255,1,
714 1,0,255,255,0,1,1,1,0,255,255,255,255,0,1,1,
715 0,0,0,0,0,0,242,51,150,226,56,140,0,106,232,106,
716 239,128,8,174,70,230,149,65,246,176,110,48,246,187,132,82,
717 34,244,200,160,122,85,52,20,245,216,189,164,141,119,96,78,
718 56,39,21,6,247,232,219,207,195,184,172,162,154,144,136,127,
719 120,112,106,100,94,0,191,182,170,161,152,143,137,128,242,230,
720 218,206,191,182,170,161,152,143,137,128,122,113,107,101,95,92,
721 86,80,77,71,68,62,60,56,53,50,47,45,42,40,37,35,
722 33,31,29,28,26,24,23,22,20,19,18,17,16,15,14,13,
723 12,11,10,9,8,7,255,241,228,216,202,192,181,171,162,153,
724 142,135,127,121,115,112,102,97,90,85,82,75,72,67,63,60,
725 57,55,51,48,45,42,40,37,36,33,31,30,28,27,25,23,
726 22,21,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
727 5,4,3,2,1,0,243,230,217,204,193,181,173,162,153,144,
728 136,128,121,114,108,102,96,91,85,81,76,72,68,64,60,57,
729 53,50,47,45,42,40,37,35,33,31,29,28,26,24,23,22,
730 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,
731 4,3,2,1,0,0,13,13,12,11,11,10,10,9,8,8,
732 7,7,7,6,6,5,5,5,4,4,4,4,3,3,3,3,
733 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,
734 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
735 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
736 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
737 1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,
738 1,1,2,2,2,2,0,0,0,1,1,1,1,1,2,2,
739 2,2,2,3,3,3,0,0,1,1,1,1,2,2,2,2,
740 3,3,3,3,4,4,0,0,1,1,1,2,2,2,3,3,
741 3,4,4,4,5,5,0,0,1,1,2,2,2,3,3,4,
742 4,4,5,5,6,6,0,0,1,1,2,2,3,3,4,4,
743 5,5,6,6,7,7,0,1,1,2,2,3,3,4,4,5,
744 5,6,6,7,7,8,0,1,1,2,2,3,4,4,5,5,
745 6,7,7,8,8,9,0,1,1,2,3,3,4,5,5,6,
746 7,7,8,9,9,10,0,1,1,2,3,4,4,5,6,7,
747 7,8,9,10,10,11,0,1,2,2,3,4,5,6,6,7,
748 8,9,10,10,11,12,0,1,2,3,3,4,5,6,7,8,
749 9,10,10,11,12,13,0,1,2,3,4,5,6,7,7,8,
750 9,10,11,12,13,14,0,1,2,3,4,5,6,7,8,9,
751 10,11,12,13,14,15,76,15,6,76,252,7,76,33,8,76,
752 88,6,76,43,11,134,211,132,212,72,160,168,169,0,153,127,
753 2,136,208,250,160,4,177,211,141,21,8,200,177,211,141,36,
754 3,200,177,211,141,5,8,141,38,3,160,8,177,211,153,195,
755 0,200,192,16,208,246,104,72,10,10,24,101,209,133,209,104,
756 8,41,192,10,42,42,40,101,210,133,210,32,110,6,169,0,
757 141,8,210,160,3,140,15,210,160,8,153,0,210,136,16,250,
758 173,5,8,96,162,0,142,39,3,138,168,177,209,201,254,176,
759 45,168,177,205,157,128,2,177,207,157,132,2,169,0,157,136,
760 2,169,1,157,140,2,169,128,157,180,2,232,224,4,208,217,
761 165,209,24,105,4,133,209,144,27,230,210,76,190,6,240,4,
762 169,0,240,223,160,2,177,209,170,200,177,209,133,210,134,209,
763 162,0,240,181,173,36,3,141,22,7,162,255,232,222,140,2,
764 208,69,189,128,2,133,211,189,132,2,133,212,188,136,2,254,
765 136,2,177,211,133,217,41,63,201,61,240,17,176,56,157,144,
766 2,157,16,3,200,177,211,74,41,126,157,180,2,169,1,157,
767 140,2,188,136,2,254,136,2,177,211,74,102,217,74,102,217,
768 165,217,41,240,157,148,2,224,3,208,177,169,255,141,36,3,
769 141,37,3,76,101,7,201,63,240,27,165,217,41,192,240,9,
770 10,42,42,157,140,2,76,17,7,200,177,211,157,140,2,254,
771 136,2,76,17,7,165,217,48,12,200,177,211,141,22,7,254,
772 136,2,76,214,6,201,255,240,9,200,177,211,157,136,2,76,
773 214,6,76,110,6,76,33,8,202,48,250,188,180,2,48,248,
774 177,203,157,184,2,133,215,200,177,203,157,188,2,133,216,169,
775 1,157,20,3,168,177,215,157,4,3,200,177,215,157,196,2,
776 200,177,215,157,200,2,200,177,215,157,240,2,41,63,157,8,
777 3,177,215,41,64,157,244,2,200,177,215,157,32,3,200,177,
778 215,157,208,2,200,177,215,157,216,2,200,177,215,157,220,2,
779 200,177,215,168,185,160,3,157,224,2,157,228,2,185,161,3,
780 157,232,2,160,10,177,215,157,236,2,169,128,157,212,2,157,
781 180,2,10,157,204,2,157,156,2,168,177,215,157,0,3,105,
782 0,157,192,2,169,12,157,252,2,168,177,215,157,248,2,76,
783 98,7,32,43,11,206,38,3,208,29,169,255,141,38,3,206,
784 37,3,208,19,238,39,3,173,39,3,201,255,240,3,76,190,
785 6,76,110,6,76,95,10,169,4,133,214,162,3,189,188,2,
786 240,242,133,212,189,184,2,133,211,188,192,2,177,211,133,217,
787 200,177,211,133,218,200,177,211,133,219,200,152,221,196,2,144,
788 10,240,8,169,128,157,204,2,189,200,2,157,192,2,165,217,
789 41,15,29,148,2,168,185,0,5,133,220,165,218,41,14,168,
790 185,144,3,133,213,165,220,25,145,3,157,28,3,189,220,2,
791 240,40,201,1,208,33,189,156,2,24,125,236,2,24,188,224,
792 2,121,165,3,157,156,2,200,152,221,232,2,208,3,189,228,
793 2,157,224,2,76,164,8,222,220,2,188,0,3,192,13,144,
794 60,189,8,3,16,49,152,221,252,2,208,8,189,4,3,157,
795 252,2,208,3,254,252,2,189,184,2,133,215,189,188,2,133,
796 216,188,252,2,177,215,188,244,2,240,4,24,125,248,2,157,
797 248,2,189,240,2,41,63,56,233,1,157,8,3,189,204,2,
798 16,31,189,148,2,240,26,221,216,2,240,21,144,19,168,189,
799 212,2,24,125,208,2,157,212,2,144,6,152,233,16,157,148,
800 2,169,0,133,221,165,218,157,12,3,41,112,74,74,141,28,
801 9,144,254,76,210,9,234,76,60,9,234,76,65,9,234,76,
802 75,9,234,76,87,9,234,76,102,9,234,76,169,9,234,76,
803 184,9,165,219,76,21,10,165,219,133,221,189,144,2,76,216,
804 9,189,144,2,24,101,219,157,144,2,76,216,9,189,156,2,
805 24,101,219,157,156,2,189,144,2,76,216,9,189,240,2,16,
806 12,188,144,2,177,213,24,125,248,2,76,135,9,189,144,2,
807 24,125,248,2,201,61,144,2,169,63,168,177,213,157,160,2,
808 164,219,208,3,157,164,2,152,74,74,74,74,157,168,2,157,
809 172,2,165,219,41,15,157,176,2,189,144,2,76,216,9,165,
810 219,24,125,20,3,157,20,3,189,144,2,76,216,9,165,219,
811 201,128,240,6,157,144,2,76,216,9,189,28,3,9,240,157,
812 28,3,189,144,2,76,216,9,189,144,2,24,101,219,188,240,
813 2,48,31,24,125,248,2,201,61,144,7,169,0,157,28,3,
814 169,63,157,16,3,168,177,213,24,125,156,2,24,101,221,76,
815 21,10,201,61,144,7,169,0,157,28,3,169,63,168,189,156,
816 2,24,125,248,2,24,113,213,24,101,221,157,24,3,189,172,
817 2,240,50,222,172,2,208,45,189,168,2,157,172,2,189,164,
818 2,221,160,2,240,31,176,13,125,176,2,176,18,221,160,2,
819 176,13,76,76,10,253,176,2,144,5,221,160,2,176,3,189,
820 160,2,157,164,2,165,218,41,1,240,10,189,164,2,24,125,
821 156,2,157,24,3,202,48,3,76,39,8,173,32,3,13,33,
822 3,13,34,3,13,35,3,170,142,44,11,173,12,3,16,33,
823 173,28,3,41,15,240,26,173,24,3,24,109,20,3,141,26,
824 3,173,30,3,41,16,208,5,169,0,141,30,3,138,9,4,
825 170,173,13,3,16,33,173,29,3,41,15,240,26,173,25,3,
826 24,109,21,3,141,27,3,173,31,3,41,16,208,5,169,0,
827 141,31,3,138,9,2,170,236,44,11,208,94,173,13,3,41,
828 14,201,6,208,38,173,29,3,41,15,240,31,172,17,3,185,
829 192,3,141,24,3,185,192,4,141,25,3,173,28,3,41,16,
830 208,5,169,0,141,28,3,138,9,80,170,173,15,3,41,14,
831 201,6,208,38,173,31,3,41,15,240,31,172,19,3,185,192,
832 3,141,26,3,185,192,4,141,27,3,173,30,3,41,16,208,
833 5,169,0,141,30,3,138,9,40,170,142,44,11,173,38,3,
834 96,160,255,173,24,3,174,28,3,141,0,210,142,1,210,173,
835 25,3,174,29,3,141,2,210,142,3,210,173,26,3,174,30,
836 3,141,4,210,142,5,210,173,27,3,174,31,3,141,6,210,
837 142,7,210,140,8,210,96
838END_CONST_ARRAY;
839CONST_ARRAY(byte, rmt8_obx)
840 255,255,144,3,108,12,128,0,128,32,128,64,0,192,128,128,
841 128,160,0,192,64,192,0,1,5,11,21,0,1,255,255,1,
842 1,0,255,255,0,1,1,1,0,255,255,255,255,0,1,1,
843 0,0,0,0,0,0,242,51,150,226,56,140,0,106,232,106,
844 239,128,8,174,70,230,149,65,246,176,110,48,246,187,132,82,
845 34,244,200,160,122,85,52,20,245,216,189,164,141,119,96,78,
846 56,39,21,6,247,232,219,207,195,184,172,162,154,144,136,127,
847 120,112,106,100,94,0,191,182,170,161,152,143,137,128,242,230,
848 218,206,191,182,170,161,152,143,137,128,122,113,107,101,95,92,
849 86,80,77,71,68,62,60,56,53,50,47,45,42,40,37,35,
850 33,31,29,28,26,24,23,22,20,19,18,17,16,15,14,13,
851 12,11,10,9,8,7,255,241,228,216,202,192,181,171,162,153,
852 142,135,127,121,115,112,102,97,90,85,82,75,72,67,63,60,
853 57,55,51,48,45,42,40,37,36,33,31,30,28,27,25,23,
854 22,21,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
855 5,4,3,2,1,0,243,230,217,204,193,181,173,162,153,144,
856 136,128,121,114,108,102,96,91,85,81,76,72,68,64,60,57,
857 53,50,47,45,42,40,37,35,33,31,29,28,26,24,23,22,
858 20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,
859 4,3,2,1,0,0,13,13,12,11,11,10,10,9,8,8,
860 7,7,7,6,6,5,5,5,4,4,4,4,3,3,3,3,
861 3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,
862 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,
863 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
864 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
865 1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,
866 1,1,2,2,2,2,0,0,0,1,1,1,1,1,2,2,
867 2,2,2,3,3,3,0,0,1,1,1,1,2,2,2,2,
868 3,3,3,3,4,4,0,0,1,1,1,2,2,2,3,3,
869 3,4,4,4,5,5,0,0,1,1,2,2,2,3,3,4,
870 4,4,5,5,6,6,0,0,1,1,2,2,3,3,4,4,
871 5,5,6,6,7,7,0,1,1,2,2,3,3,4,4,5,
872 5,6,6,7,7,8,0,1,1,2,2,3,4,4,5,5,
873 6,7,7,8,8,9,0,1,1,2,3,3,4,5,5,6,
874 7,7,8,9,9,10,0,1,1,2,3,4,4,5,6,7,
875 7,8,9,10,10,11,0,1,2,2,3,4,5,6,6,7,
876 8,9,10,10,11,12,0,1,2,3,3,4,5,6,7,8,
877 9,10,10,11,12,13,0,1,2,3,4,5,6,7,7,8,
878 9,10,11,12,13,14,0,1,2,3,4,5,6,7,8,9,
879 10,11,12,13,14,15,76,15,6,76,9,8,76,46,8,76,
880 92,6,76,2,12,134,211,132,212,72,160,0,152,153,0,2,
881 153,76,2,200,208,247,160,4,177,211,141,34,8,200,177,211,
882 141,72,3,200,177,211,141,18,8,141,74,3,160,8,177,211,
883 153,195,0,200,192,16,208,246,104,72,10,10,10,24,101,209,
884 133,209,104,8,41,224,10,42,42,42,40,101,210,133,210,32,
885 123,6,169,0,141,8,210,141,24,210,160,3,140,15,210,140,
886 31,210,160,8,153,0,210,153,16,210,136,16,247,173,18,8,
887 96,162,0,142,75,3,138,168,177,209,201,254,176,45,168,177,
888 205,157,0,2,177,207,157,8,2,169,0,157,16,2,169,1,
889 157,24,2,169,128,157,104,2,232,224,8,208,217,165,209,24,
890 105,8,133,209,144,27,230,210,76,203,6,240,4,169,0,240,
891 223,160,2,177,209,170,200,177,209,133,210,134,209,162,0,240,
892 181,173,72,3,141,35,7,162,255,232,222,24,2,208,69,189,
893 0,2,133,211,189,8,2,133,212,188,16,2,254,16,2,177,
894 211,133,217,41,63,201,61,240,17,176,56,157,32,2,157,32,
895 3,200,177,211,74,41,126,157,104,2,169,1,157,24,2,188,
896 16,2,254,16,2,177,211,74,102,217,74,102,217,165,217,41,
897 240,157,40,2,224,7,208,177,169,255,141,72,3,141,73,3,
898 76,114,7,201,63,240,27,165,217,41,192,240,9,10,42,42,
899 157,24,2,76,30,7,200,177,211,157,24,2,254,16,2,76,
900 30,7,165,217,48,12,200,177,211,141,35,7,254,16,2,76,
901 227,6,201,255,240,9,200,177,211,157,16,2,76,227,6,76,
902 123,6,76,46,8,202,48,250,188,104,2,48,248,177,203,157,
903 112,2,133,215,200,177,203,157,120,2,133,216,169,1,157,40,
904 3,168,177,215,157,8,3,200,177,215,157,136,2,200,177,215,
905 157,144,2,200,177,215,157,224,2,41,63,157,16,3,177,215,
906 41,64,157,232,2,200,177,215,157,64,3,200,177,215,157,160,
907 2,200,177,215,157,176,2,200,177,215,157,184,2,200,177,215,
908 168,185,160,3,157,192,2,157,200,2,185,161,3,157,208,2,
909 160,10,177,215,157,216,2,169,128,157,168,2,157,104,2,10,
910 157,152,2,157,56,2,168,177,215,157,0,3,105,0,157,128,
911 2,169,12,157,248,2,168,177,215,157,240,2,76,111,7,32,
912 2,12,206,74,3,208,29,169,255,141,74,3,206,73,3,208,
913 19,238,75,3,173,75,3,201,255,240,3,76,203,6,76,123,
914 6,76,116,10,169,4,133,214,162,7,189,120,2,240,242,133,
915 212,189,112,2,133,211,188,128,2,177,211,133,217,200,177,211,
916 133,218,200,177,211,133,219,200,152,221,136,2,144,10,240,8,
917 169,128,157,152,2,189,144,2,157,128,2,165,217,224,4,144,
918 4,74,74,74,74,41,15,29,40,2,168,185,0,5,133,220,
919 165,218,41,14,168,185,144,3,133,213,165,220,25,145,3,157,
920 56,3,189,184,2,240,40,201,1,208,33,189,56,2,24,125,
921 216,2,24,188,192,2,121,165,3,157,56,2,200,152,221,208,
922 2,208,3,189,200,2,157,192,2,76,185,8,222,184,2,188,
923 0,3,192,13,144,60,189,16,3,16,49,152,221,248,2,208,
924 8,189,8,3,157,248,2,208,3,254,248,2,189,112,2,133,
925 215,189,120,2,133,216,188,248,2,177,215,188,232,2,240,4,
926 24,125,240,2,157,240,2,189,224,2,41,63,56,233,1,157,
927 16,3,189,152,2,16,31,189,40,2,240,26,221,176,2,240,
928 21,144,19,168,189,168,2,24,125,160,2,157,168,2,144,6,
929 152,233,16,157,40,2,169,0,133,221,165,218,157,24,3,41,
930 112,74,74,141,49,9,144,254,76,231,9,234,76,81,9,234,
931 76,86,9,234,76,96,9,234,76,108,9,234,76,123,9,234,
932 76,190,9,234,76,205,9,165,219,76,42,10,165,219,133,221,
933 189,32,2,76,237,9,189,32,2,24,101,219,157,32,2,76,
934 237,9,189,56,2,24,101,219,157,56,2,189,32,2,76,237,
935 9,189,224,2,16,12,188,32,2,177,213,24,125,240,2,76,
936 156,9,189,32,2,24,125,240,2,201,61,144,2,169,63,168,
937 177,213,157,64,2,164,219,208,3,157,72,2,152,74,74,74,
938 74,157,80,2,157,88,2,165,219,41,15,157,96,2,189,32,
939 2,76,237,9,165,219,24,125,40,3,157,40,3,189,32,2,
940 76,237,9,165,219,201,128,240,6,157,32,2,76,237,9,189,
941 56,3,9,240,157,56,3,189,32,2,76,237,9,189,32,2,
942 24,101,219,188,224,2,48,31,24,125,240,2,201,61,144,7,
943 169,0,157,56,3,169,63,157,32,3,168,177,213,24,125,56,
944 2,24,101,221,76,42,10,201,61,144,7,169,0,157,56,3,
945 169,63,168,189,56,2,24,125,240,2,24,113,213,24,101,221,
946 157,48,3,189,88,2,240,50,222,88,2,208,45,189,80,2,
947 157,88,2,189,72,2,221,64,2,240,31,176,13,125,96,2,
948 176,18,221,64,2,176,13,76,97,10,253,96,2,144,5,221,
949 64,2,176,3,189,64,2,157,72,2,165,218,41,1,240,10,
950 189,72,2,24,125,56,2,157,48,3,202,48,3,76,52,8,
951 173,64,3,13,65,3,13,66,3,13,67,3,170,142,101,12,
952 173,24,3,16,33,173,56,3,41,15,240,26,173,48,3,24,
953 109,40,3,141,50,3,173,58,3,41,16,208,5,169,0,141,
954 58,3,138,9,4,170,173,25,3,16,33,173,57,3,41,15,
955 240,26,173,49,3,24,109,41,3,141,51,3,173,59,3,41,
956 16,208,5,169,0,141,59,3,138,9,2,170,236,101,12,208,
957 94,173,25,3,41,14,201,6,208,38,173,57,3,41,15,240,
958 31,172,33,3,185,192,3,141,48,3,185,192,4,141,49,3,
959 173,56,3,41,16,208,5,169,0,141,56,3,138,9,80,170,
960 173,27,3,41,14,201,6,208,38,173,59,3,41,15,240,31,
961 172,35,3,185,192,3,141,50,3,185,192,4,141,51,3,173,
962 58,3,41,16,208,5,169,0,141,58,3,138,9,40,170,142,
963 101,12,173,68,3,13,69,3,13,70,3,13,71,3,170,142,
964 3,12,173,28,3,16,33,173,60,3,41,15,240,26,173,52,
965 3,24,109,44,3,141,54,3,173,62,3,41,16,208,5,169,
966 0,141,62,3,138,9,4,170,173,29,3,16,33,173,61,3,
967 41,15,240,26,173,53,3,24,109,45,3,141,55,3,173,63,
968 3,41,16,208,5,169,0,141,63,3,138,9,2,170,236,3,
969 12,208,94,173,29,3,41,14,201,6,208,38,173,61,3,41,
970 15,240,31,172,37,3,185,192,3,141,52,3,185,192,4,141,
971 53,3,173,60,3,41,16,208,5,169,0,141,60,3,138,9,
972 80,170,173,31,3,41,14,201,6,208,38,173,63,3,41,15,
973 240,31,172,39,3,185,192,3,141,54,3,185,192,4,141,55,
974 3,173,62,3,41,16,208,5,169,0,141,62,3,138,9,40,
975 170,142,3,12,173,74,3,96,160,255,173,52,3,174,48,3,
976 141,16,210,142,0,210,173,60,3,174,56,3,141,17,210,142,
977 1,210,173,53,3,174,49,3,141,18,210,142,2,210,173,61,
978 3,174,57,3,141,19,210,142,3,210,173,54,3,174,50,3,
979 141,20,210,142,4,210,173,62,3,174,58,3,141,21,210,142,
980 5,210,173,55,3,174,51,3,141,22,210,142,6,210,173,63,
981 3,174,59,3,141,23,210,142,7,210,169,255,140,24,210,141,
982 8,210,96
983END_CONST_ARRAY;
984CONST_ARRAY(byte, tmc_obx)
985 255,255,0,5,104,15,76,206,13,76,208,8,76,239,9,15,
986 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
987 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
988 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
989 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
990 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,
991 1,1,0,0,0,0,1,1,1,1,1,1,1,1,2,2,
992 2,2,0,0,0,1,1,1,1,1,2,2,2,2,2,3,
993 3,3,0,0,1,1,1,1,2,2,2,2,3,3,3,3,
994 4,4,0,0,1,1,1,2,2,2,3,3,3,4,4,4,
995 5,5,0,0,1,1,2,2,2,3,3,4,4,4,5,5,
996 6,6,0,0,1,1,2,2,3,3,4,4,5,5,6,6,
997 7,7,0,1,1,2,2,3,3,4,4,5,5,6,6,7,
998 7,8,0,1,1,2,2,3,4,4,5,5,6,7,7,8,
999 8,9,0,1,1,2,3,3,4,5,5,6,7,7,8,9,
1000 9,10,0,1,1,2,3,4,4,5,6,7,7,8,9,10,
1001 10,11,0,1,2,2,3,4,5,6,6,7,8,9,10,10,
1002 11,12,0,1,2,3,3,4,5,6,7,8,9,10,10,11,
1003 12,13,0,1,2,3,4,5,6,7,7,8,9,10,11,12,
1004 13,14,0,1,2,3,4,5,6,7,8,9,10,11,12,13,
1005 14,15,0,241,228,215,203,192,181,170,161,152,143,135,127,120,
1006 114,107,101,95,90,85,80,75,71,67,63,60,56,53,50,47,
1007 44,42,39,37,35,33,31,29,28,26,24,23,22,20,19,18,
1008 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,
1009 1,0,0,242,230,218,206,191,182,170,161,152,143,137,128,122,
1010 113,107,101,95,92,86,80,77,71,68,62,60,56,53,50,47,
1011 45,42,40,37,35,33,31,29,28,26,24,23,22,20,19,18,
1012 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,
1013 1,0,0,255,241,228,216,202,192,181,171,162,153,142,135,127,
1014 121,115,112,102,97,90,85,82,75,72,67,63,60,57,55,51,
1015 48,45,42,40,37,36,33,31,30,28,27,25,23,22,21,19,
1016 18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,
1017 2,1,0,243,230,217,204,193,181,173,162,153,144,136,128,121,
1018 114,108,102,96,91,85,81,76,72,68,64,60,57,53,50,47,
1019 45,42,40,37,35,33,31,29,28,26,24,23,22,20,19,18,
1020 17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,
1021 1,0,0,242,51,150,226,56,140,0,106,232,106,239,128,8,
1022 174,70,230,149,65,246,176,110,48,246,187,132,82,34,244,200,
1023 160,122,85,52,20,245,216,189,164,141,119,96,78,56,39,21,
1024 6,247,232,219,207,195,184,172,162,154,144,136,127,120,112,106,
1025 100,94,0,13,13,12,11,11,10,10,9,8,8,7,7,7,
1026 6,6,5,5,5,4,4,4,4,3,3,3,3,3,2,2,
1027 2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,
1028 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1029 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1030 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1031 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1032 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1033 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1034 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1035 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1036 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1037 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1038 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1039 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1040 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1041 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1042 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1043 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1044 0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,5,
1045 6,7,0,1,2,3,4,2,0,0,4,2,0,0,0,16,
1046 0,8,0,16,0,8,173,183,8,240,94,173,182,8,201,64,
1047 144,90,206,181,8,240,3,76,239,9,162,7,169,0,157,196,
1048 7,157,204,7,202,16,247,141,182,8,170,160,15,177,254,16,
1049 32,136,177,254,16,3,76,95,14,134,252,10,10,38,252,10,
1050 38,252,10,38,252,105,0,133,254,165,252,105,0,133,255,144,
1051 218,157,212,7,136,177,254,157,220,7,232,136,16,207,24,165,
1052 254,105,16,133,254,144,2,230,255,76,239,9,206,181,8,16,
1053 248,238,182,8,173,180,8,141,181,8,162,7,222,204,7,48,
1054 3,76,233,9,188,212,7,185,255,255,133,252,185,255,255,133,
1055 253,188,196,7,177,252,208,6,32,109,13,76,230,9,201,64,
1056 176,18,125,220,7,157,228,7,32,109,13,188,42,5,32,188,
1057 14,76,230,9,208,34,200,254,196,7,177,252,16,7,133,251,
1058 32,109,13,165,251,41,127,208,7,169,64,141,182,8,208,76,
1059 141,180,8,141,181,8,208,68,201,128,176,43,41,63,125,220,
1060 7,157,228,7,200,254,196,7,177,252,41,127,208,7,169,64,
1061 141,182,8,208,6,141,180,8,141,181,8,32,109,13,188,42,
1062 5,32,188,14,76,230,9,201,192,176,12,41,63,157,42,5,
1063 200,254,196,7,76,94,9,41,63,157,204,7,254,196,7,202,
1064 48,3,76,70,9,162,7,189,188,7,240,33,32,46,11,189,
1065 50,5,61,192,8,240,22,160,71,177,252,24,125,34,5,157,
1066 36,5,168,185,60,6,56,125,100,8,157,246,7,202,16,215,
1067 14,9,5,14,9,5,14,9,5,14,9,5,232,134,252,134,
1068 253,162,7,138,168,185,252,7,208,12,188,184,8,185,4,8,
1069 208,4,138,168,169,0,133,250,152,157,26,5,185,244,7,157,
1070 18,5,185,50,5,133,251,5,253,133,253,165,251,61,192,8,
1071 240,6,185,246,7,157,20,5,165,251,61,200,8,240,18,185,
1072 34,5,41,63,168,200,132,252,185,123,7,157,18,5,76,137,
1073 10,164,252,240,10,185,59,7,157,18,5,169,0,133,252,165,
1074 250,13,9,5,168,185,60,5,188,26,5,25,236,7,157,10,
1075 5,224,4,208,9,165,253,141,59,5,169,0,133,253,202,16,
1076 130,78,9,5,78,9,5,78,9,5,78,9,5,165,253,162,
1077 3,142,31,210,142,15,210,174,22,5,172,18,5,142,16,210,
1078 140,0,210,174,14,5,172,10,5,142,17,210,140,1,210,174,
1079 23,5,172,19,5,142,18,210,140,2,210,174,15,5,172,11,
1080 5,142,19,210,140,3,210,174,24,5,172,20,5,142,20,210,
1081 140,4,210,174,16,5,172,12,5,142,21,210,140,5,210,174,
1082 25,5,172,21,5,142,22,210,140,6,210,174,17,5,172,13,
1083 5,142,23,210,140,7,210,141,58,5,174,59,5,142,24,210,
1084 141,8,210,96,189,28,8,133,252,189,36,8,133,253,188,44,
1085 8,192,63,240,123,254,44,8,254,44,8,254,44,8,177,252,
1086 41,240,157,236,7,177,252,41,15,56,253,12,8,16,2,169,
1087 0,157,252,7,200,177,252,41,15,56,253,20,8,16,2,169,
1088 0,157,4,8,177,252,41,240,240,116,16,11,160,73,177,252,
1089 188,44,8,136,136,16,2,169,0,157,50,5,177,252,41,112,
1090 240,99,74,74,141,154,11,169,0,157,100,8,200,177,252,144,
1091 254,234,234,234,234,76,56,13,234,76,53,13,234,76,60,13,
1092 234,76,74,13,234,76,84,13,234,76,95,13,234,76,81,13,
1093 189,52,8,240,18,222,68,8,208,13,157,68,8,189,252,7,
1094 41,15,240,3,222,252,7,189,60,8,240,18,222,76,8,208,
1095 13,157,76,8,189,4,8,41,15,240,3,222,4,8,160,72,
1096 177,252,157,50,5,189,148,8,24,105,63,168,177,252,125,228,
1097 7,157,34,5,168,185,60,6,157,244,7,222,164,8,16,51,
1098 189,156,8,157,164,8,189,172,8,240,24,24,125,148,8,157,
1099 148,8,240,7,221,140,8,208,26,169,254,24,105,1,157,172,
1100 8,208,16,254,148,8,189,140,8,221,148,8,176,5,169,0,
1101 157,148,8,189,116,8,240,4,222,116,8,96,189,108,8,133,
1102 250,189,92,8,133,251,32,105,12,222,132,8,16,16,165,250,
1103 157,108,8,165,251,157,92,8,189,124,8,157,132,8,96,189,
1104 84,8,141,112,12,16,254,76,167,12,234,76,144,12,234,76,
1105 174,12,234,76,180,12,234,76,190,12,234,76,210,12,234,76,
1106 226,12,234,76,244,12,165,250,230,250,41,3,74,144,15,208,
1107 71,165,251,157,100,8,24,125,244,7,157,244,7,96,169,0,
1108 157,100,8,96,32,29,13,76,157,12,32,29,13,24,125,34,
1109 5,76,84,13,165,250,157,100,8,24,125,244,7,157,244,7,
1110 165,250,24,101,251,133,250,96,189,34,5,56,229,250,157,34,
1111 5,168,185,60,6,76,199,12,189,244,7,56,229,251,157,244,
1112 7,56,169,0,229,251,157,100,8,96,189,132,8,208,174,165,
1113 251,16,16,189,4,8,240,165,189,252,7,201,15,240,158,254,
1114 252,7,96,189,252,7,240,149,189,4,8,201,15,240,142,254,
1115 4,8,96,164,250,165,251,48,2,200,200,136,152,133,250,197,
1116 251,208,6,165,251,73,255,133,251,152,96,125,244,7,157,244,
1117 7,96,188,228,7,121,60,6,157,244,7,152,157,34,5,96,
1118 45,10,210,157,244,7,96,125,228,7,157,34,5,168,185,60,
1119 6,157,244,7,96,157,34,5,168,189,244,7,121,60,6,157,
1120 244,7,96,200,254,196,7,177,252,74,74,74,74,157,12,8,
1121 177,252,41,15,157,20,8,96,32,95,14,160,15,169,0,133,
1122 254,169,0,133,255,138,240,46,177,254,16,1,202,24,165,254,
1123 105,16,133,254,144,239,230,255,176,235,32,95,14,169,0,133,
1124 252,138,10,10,38,252,10,38,252,10,38,252,105,0,133,254,
1125 165,252,105,0,133,255,169,64,141,182,8,169,1,141,181,8,
1126 141,183,8,96,201,16,144,176,201,32,144,206,201,48,176,3,
1127 76,174,14,201,64,176,9,138,41,15,240,3,141,180,8,96,
1128 201,80,144,113,201,96,176,6,169,0,141,183,8,96,201,112,
1129 144,248,169,1,141,181,8,169,64,141,182,8,132,252,134,253,
1130 160,30,177,252,141,180,8,165,252,24,105,32,141,194,14,144,
1131 1,232,142,195,14,24,105,64,141,202,14,144,1,232,142,203,
1132 14,24,105,64,141,82,9,144,1,232,142,83,9,24,105,128,
1133 141,87,9,144,1,232,142,88,9,24,105,128,133,254,141,16,
1134 9,141,136,13,141,183,13,144,1,232,134,255,142,22,9,142,
1135 140,13,142,189,13,160,7,169,0,141,183,8,153,0,210,153,
1136 16,210,153,10,5,153,252,7,153,4,8,153,50,5,153,188,
1137 7,136,16,232,141,8,210,141,24,210,141,58,5,141,59,5,
1138 96,157,252,7,157,4,8,157,50,5,189,228,7,157,34,5,
1139 96,152,73,240,74,74,74,74,157,12,8,152,41,15,73,15,
1140 157,20,8,96,41,7,133,252,138,166,252,41,63,240,226,157,
1141 228,7,169,0,157,188,7,185,255,255,157,28,8,133,252,185,
1142 255,255,157,36,8,133,253,5,252,240,182,160,74,177,252,157,
1143 52,8,157,68,8,200,177,252,157,60,8,157,76,8,200,177,
1144 252,41,112,74,74,157,84,8,177,252,41,15,157,92,8,177,
1145 252,16,11,189,92,8,73,255,24,105,1,157,92,8,200,177,
1146 252,157,116,8,200,177,252,41,63,157,124,8,157,132,8,200,
1147 177,252,41,128,240,2,169,1,157,172,8,177,252,41,112,74,
1148 74,74,74,157,140,8,208,3,157,172,8,177,252,41,15,157,
1149 156,8,157,164,8,136,177,252,41,192,24,125,228,7,157,228,
1150 7,157,34,5,168,185,60,6,157,244,7,169,0,157,44,8,
1151 157,100,8,157,108,8,157,148,8,169,1,157,188,7,96
1152END_CONST_ARRAY;
1153CONST_ARRAY(byte, tm2_obx)
1154 255,255,0,2,107,16,0,0,0,0,0,0,0,0,0,0,
1155 0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
1156 1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,
1157 1,1,2,2,2,2,0,0,0,1,1,1,1,1,2,2,
1158 2,2,2,3,3,3,0,0,1,1,1,1,2,2,2,2,
1159 3,3,3,3,4,4,0,0,1,1,1,2,2,2,3,3,
1160 3,4,4,4,5,5,0,0,1,1,2,2,2,3,3,4,
1161 4,4,5,5,6,6,0,0,1,1,2,2,3,3,4,4,
1162 5,5,6,6,7,7,0,1,1,2,2,3,3,4,4,5,
1163 5,6,6,7,7,8,0,1,1,2,2,3,4,4,5,5,
1164 6,7,7,8,8,9,0,1,1,2,3,3,4,5,5,6,
1165 7,7,8,9,9,10,0,1,1,2,3,4,4,5,6,7,
1166 7,8,9,10,10,11,0,1,2,2,3,4,5,6,6,7,
1167 8,9,10,10,11,12,0,1,2,3,3,4,5,6,7,8,
1168 9,10,10,11,12,13,0,1,2,3,4,5,6,7,7,8,
1169 9,10,11,12,13,14,0,1,2,3,4,5,6,7,8,9,
1170 10,11,12,13,14,15,0,241,228,215,203,192,181,170,161,152,
1171 143,135,127,120,114,107,101,95,90,85,80,75,71,67,63,60,
1172 56,53,50,47,44,42,39,37,35,33,31,29,28,26,24,23,
1173 22,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
1174 5,4,3,2,1,0,0,242,233,218,206,191,182,170,161,152,
1175 143,137,128,122,113,107,101,95,92,86,80,77,71,68,62,60,
1176 56,53,50,47,45,42,40,37,35,33,31,29,28,26,24,23,
1177 22,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
1178 5,4,3,2,1,0,0,255,241,228,216,202,192,181,171,162,
1179 153,142,135,127,121,115,112,102,97,90,85,82,75,72,67,63,
1180 60,57,55,51,48,45,42,40,37,36,33,31,30,28,27,25,
1181 23,22,21,19,18,17,16,15,14,13,12,11,10,9,8,7,
1182 6,5,4,3,2,1,0,243,230,217,204,193,181,173,162,153,
1183 144,136,128,121,114,108,102,96,91,85,81,76,72,68,64,60,
1184 57,53,50,47,45,42,40,37,35,33,31,29,28,26,24,23,
1185 22,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,
1186 5,4,3,2,1,0,226,56,140,0,106,232,106,239,128,8,
1187 174,70,230,149,65,246,176,110,48,246,187,132,82,34,244,200,
1188 160,122,85,52,20,245,216,189,164,141,119,96,78,56,39,21,
1189 6,247,232,219,207,195,184,172,162,154,144,136,127,120,112,106,
1190 100,94,87,82,50,10,0,242,51,150,226,56,140,0,106,232,
1191 106,239,128,8,174,70,230,149,65,246,176,110,48,246,187,132,
1192 82,34,244,200,160,122,85,52,20,245,216,189,164,141,119,96,
1193 78,56,39,21,6,247,232,219,207,195,184,172,162,154,144,136,
1194 127,120,112,106,100,94,11,11,10,10,9,8,8,7,7,7,
1195 6,6,5,5,5,4,4,4,4,3,3,3,3,3,2,2,
1196 2,2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,
1197 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1198 0,0,0,0,0,0,0,13,13,12,11,11,10,10,9,8,
1199 8,7,7,7,6,6,5,5,5,4,4,4,4,3,3,3,
1200 3,3,2,2,2,2,2,2,2,1,1,1,1,1,1,1,
1201 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,
1202 0,0,0,0,0,0,76,228,13,76,227,6,76,159,8,1,
1203 16,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1204 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1205 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1206 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1207 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1208 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1209 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1210 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1211 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1212 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1213 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1214 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1215 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1216 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1217 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1218 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1219 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1220 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1221 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1222 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1223 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1224 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1225 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1226 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
1227 0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,5,
1228 6,7,0,1,2,3,4,2,0,0,4,2,0,0,0,16,
1229 0,8,0,16,0,8,133,211,129,169,133,211,129,169,136,177,
1230 250,141,23,5,162,0,134,252,10,38,252,10,38,252,10,38,
1231 252,10,38,252,109,23,5,144,2,230,252,24,105,0,133,250,
1232 165,252,105,0,133,251,76,7,7,32,181,9,173,22,5,240,
1233 5,206,28,5,48,3,76,162,8,206,29,5,208,82,162,0,
1234 238,23,5,173,25,5,133,250,173,26,5,133,251,160,16,177,
1235 250,48,171,208,3,76,44,15,141,29,5,136,177,250,136,132,
1236 252,168,185,255,255,157,80,5,185,255,255,157,88,5,169,0,
1237 157,112,5,157,96,5,164,252,177,250,157,104,5,232,136,16,
1238 219,169,17,24,101,250,141,25,5,169,0,101,251,141,26,5,
1239 173,27,5,141,28,5,162,7,222,112,5,48,6,202,16,248,
1240 76,162,8,189,80,5,133,250,189,88,5,133,251,188,96,5,
1241 177,250,208,28,200,177,250,157,208,5,41,240,157,216,5,177,
1242 250,10,10,10,10,157,224,5,200,152,157,96,5,76,87,7,
1243 201,64,176,79,125,104,5,157,152,5,200,177,250,16,37,41,
1244 127,133,252,200,177,250,157,208,5,41,240,157,216,5,177,250,
1245 10,10,10,10,157,224,5,200,152,157,96,5,164,252,32,156,
1246 15,76,87,7,168,254,96,5,254,96,5,189,208,5,41,240,
1247 157,216,5,189,208,5,10,10,10,10,157,224,5,32,156,15,
1248 76,87,7,201,128,176,37,41,63,24,125,104,5,157,152,5,
1249 200,177,250,157,208,5,41,240,157,216,5,177,250,10,10,10,
1250 10,157,224,5,200,152,157,96,5,76,87,7,208,14,200,177,
1251 250,157,112,5,200,152,157,96,5,76,87,7,201,192,176,15,
1252 41,63,24,125,104,5,157,152,5,254,96,5,76,87,7,201,
1253 208,176,15,200,254,96,5,41,15,141,27,5,141,28,5,76,
1254 106,7,201,224,176,22,177,250,133,252,200,177,250,133,253,200,
1255 152,157,96,5,165,252,32,14,14,76,87,7,201,240,176,46,
1256 177,250,133,252,200,177,250,133,253,165,252,32,14,14,188,96,
1257 5,200,200,177,250,157,208,5,41,240,157,216,5,177,250,10,
1258 10,10,10,157,224,5,200,152,157,96,5,76,87,7,201,255,
1259 176,11,233,239,157,112,5,254,96,5,76,87,7,169,64,157,
1260 112,5,76,87,7,32,181,9,162,7,189,120,5,240,115,76,
1261 217,10,189,14,5,240,14,169,0,157,32,5,157,40,5,202,
1262 16,232,76,31,9,164,253,185,0,3,24,101,252,157,56,5,
1263 152,157,160,5,189,176,5,61,168,6,240,40,165,253,41,127,
1264 168,185,0,4,24,101,252,157,55,5,185,128,4,105,0,157,
1265 56,5,169,0,157,31,5,188,152,6,153,39,5,202,202,16,
1266 169,76,31,9,189,176,5,61,160,6,240,22,189,104,6,24,
1267 101,253,157,162,5,168,185,0,3,24,101,252,56,101,254,157,
1268 58,5,202,16,133,232,134,252,162,3,173,9,5,240,6,41,
1269 64,208,60,162,7,138,168,185,32,5,208,12,188,152,6,185,
1270 40,5,208,4,138,168,169,0,25,168,5,157,48,5,185,56,
1271 5,157,72,5,185,160,5,157,64,5,185,176,5,5,252,133,
1272 252,224,4,208,3,141,31,5,202,16,202,141,30,5,96,189,
1273 32,5,29,168,5,157,48,5,189,44,5,29,172,5,157,52,
1274 5,189,56,5,157,72,5,189,60,5,157,76,5,189,160,5,
1275 157,64,5,189,164,5,157,68,5,202,16,211,173,176,5,13,
1276 177,5,13,178,5,13,179,5,141,30,5,173,180,5,13,181,
1277 5,13,182,5,13,183,5,141,31,5,96,173,9,5,208,3,
1278 76,144,10,48,3,76,72,10,173,13,5,170,74,74,41,1,
1279 168,185,30,5,141,56,210,138,41,4,168,185,56,5,141,48,
1280 210,189,32,5,141,49,210,185,57,5,141,50,210,189,33,5,
1281 141,51,210,185,58,5,141,52,210,189,34,5,141,53,210,185,
1282 59,5,141,54,210,189,35,5,141,55,210,173,12,5,170,74,
1283 74,41,1,168,185,30,5,141,40,210,138,41,4,168,185,56,
1284 5,141,32,210,189,32,5,141,33,210,185,57,5,141,34,210,
1285 189,33,5,141,35,210,185,58,5,141,36,210,189,34,5,141,
1286 37,210,185,59,5,141,38,210,189,35,5,141,39,210,173,11,
1287 5,170,74,74,41,1,168,185,30,5,141,24,210,138,172,9,
1288 5,16,2,41,4,168,185,56,5,141,16,210,189,32,5,141,
1289 17,210,185,57,5,141,18,210,189,33,5,141,19,210,185,58,
1290 5,141,20,210,189,34,5,141,21,210,185,59,5,141,22,210,
1291 189,35,5,141,23,210,173,10,5,170,74,74,41,1,168,185,
1292 30,5,141,8,210,138,172,9,5,16,2,41,4,168,185,56,
1293 5,141,0,210,189,32,5,141,1,210,185,57,5,141,2,210,
1294 189,33,5,141,3,210,185,58,5,141,4,210,189,34,5,141,
1295 5,210,185,59,5,141,6,210,189,35,5,141,7,210,96,189,
1296 128,5,133,250,189,136,5,133,251,189,128,6,133,252,189,136,
1297 6,133,253,189,144,6,133,254,189,184,5,221,192,5,144,12,
1298 157,8,6,189,200,5,157,184,5,76,11,11,189,8,6,240,
1299 48,189,232,5,240,19,222,248,5,208,14,157,248,5,189,216,
1300 5,240,6,56,233,16,157,216,5,189,240,5,240,19,222,0,
1301 6,208,14,157,0,6,189,224,5,240,6,56,233,16,157,224,
1302 5,188,72,6,177,250,24,125,152,5,24,101,253,133,253,222,
1303 88,6,16,57,189,80,6,157,88,6,189,96,6,240,30,24,
1304 125,72,6,157,72,6,240,13,221,64,6,144,32,169,255,157,
1305 96,6,76,135,11,169,1,157,96,6,76,135,11,254,72,6,
1306 189,64,6,221,72,6,176,5,169,0,157,72,6,169,19,24,
1307 101,250,133,250,144,2,230,251,188,184,5,177,250,41,240,157,
1308 168,5,177,250,41,15,29,216,5,168,185,0,2,5,255,168,
1309 185,0,2,157,32,5,188,184,5,200,177,250,41,15,29,224,
1310 5,168,185,0,2,5,255,168,185,0,2,157,40,5,189,40,
1311 6,208,39,189,16,6,141,212,11,16,254,76,209,12,234,76,
1312 108,12,234,76,167,12,234,76,212,12,234,76,1,13,234,76,
1313 33,13,234,76,65,13,234,76,73,13,222,40,6,188,184,5,
1314 200,177,250,41,112,74,74,74,141,34,12,177,250,48,6,189,
1315 112,6,76,18,12,189,120,6,61,176,6,157,176,5,200,200,
1316 152,157,184,5,136,177,250,144,254,144,22,144,12,144,34,144,
1317 24,144,46,144,36,144,50,144,52,125,128,6,157,128,6,177,
1318 250,24,101,252,133,252,76,172,8,125,136,6,157,136,6,177,
1319 250,24,101,253,133,253,76,172,8,125,144,6,157,144,6,177,
1320 250,24,101,254,133,254,76,172,8,133,252,169,0,133,253,76,
1321 172,8,189,32,6,41,3,74,144,10,208,25,189,24,6,24,
1322 101,252,133,252,222,56,6,16,78,254,32,6,189,48,6,157,
1323 56,6,76,247,11,165,252,253,24,6,133,252,222,56,6,16,
1324 54,254,32,6,189,48,6,157,56,6,76,247,11,188,32,6,
1325 189,24,6,48,2,200,200,136,152,24,101,252,133,252,222,56,
1326 6,16,20,152,157,32,6,221,24,6,208,5,73,255,157,24,
1327 6,189,48,6,157,56,6,76,247,11,188,32,6,189,24,6,
1328 48,2,200,200,136,152,24,101,253,133,253,222,56,6,16,231,
1329 152,157,32,6,221,24,6,208,216,73,255,157,24,6,189,48,
1330 6,157,56,6,76,247,11,189,32,6,24,101,252,133,252,222,
1331 56,6,16,195,189,24,6,24,125,32,6,157,32,6,189,48,
1332 6,157,56,6,76,247,11,165,253,56,253,32,6,133,253,222,
1333 56,6,16,163,189,24,6,24,125,32,6,157,32,6,189,48,
1334 6,157,56,6,76,247,11,189,24,6,24,101,252,133,252,76,
1335 247,11,160,16,169,0,133,250,169,0,133,251,169,0,141,23,
1336 5,138,240,63,177,250,240,2,16,1,202,169,17,24,101,250,
1337 133,250,144,2,230,251,238,23,5,208,230,162,0,169,0,133,
1338 252,138,141,23,5,10,38,252,10,38,252,10,38,252,10,38,
1339 252,109,23,5,144,2,230,252,24,105,0,133,250,165,252,105,
1340 0,133,251,32,44,15,165,250,141,25,5,165,251,141,26,5,
1341 162,7,169,255,157,208,5,169,240,157,216,5,157,224,5,202,
1342 16,240,169,3,141,15,210,141,31,210,141,47,210,141,63,210,
1343 206,23,5,232,142,28,5,232,142,29,5,142,22,5,96,138,
1344 41,15,141,27,5,96,142,22,5,96,201,16,176,3,76,76,
1345 13,201,32,144,136,201,48,176,3,76,133,15,201,64,144,223,
1346 201,80,176,3,76,44,15,201,96,144,219,201,112,144,3,76,
1347 180,14,132,253,41,15,10,141,23,14,165,253,144,254,144,30,
1348 144,56,144,89,144,96,144,26,144,28,144,30,144,32,144,34,
1349 144,36,144,13,144,11,144,9,144,7,144,5,144,3,141,24,
1350 5,96,157,104,6,96,157,112,6,96,157,120,6,96,157,144,
1351 6,96,157,128,6,96,157,136,6,96,41,112,74,74,157,16,
1352 6,41,48,208,3,157,32,6,165,253,48,6,41,15,157,24,
1353 6,96,41,15,73,255,24,105,1,157,24,6,96,41,63,157,
1354 48,6,157,56,6,96,41,128,10,42,157,96,6,165,253,41,
1355 112,74,74,74,74,157,64,6,208,3,157,96,6,165,253,41,
1356 15,157,80,6,157,88,6,189,72,6,221,64,6,144,143,189,
1357 64,6,240,2,233,1,157,72,6,96,132,250,134,251,160,25,
1358 177,250,200,141,9,5,177,250,200,141,10,5,177,250,200,141,
1359 11,5,177,250,200,141,12,5,177,250,200,141,13,5,177,250,
1360 141,27,5,165,250,73,128,48,1,232,141,172,15,142,173,15,
1361 73,128,48,1,232,141,29,7,142,30,7,232,141,35,7,142,
1362 36,7,232,141,162,15,142,163,15,73,128,48,1,232,141,25,
1363 5,141,215,6,141,79,13,141,148,13,142,26,5,142,221,6,
1364 142,83,13,142,154,13,169,240,133,255,169,0,141,22,5,141,
1365 24,5,162,7,169,0,141,22,5,157,120,5,157,176,5,157,
1366 32,5,157,40,5,157,48,5,157,48,210,157,32,210,157,16,
1367 210,157,0,210,202,16,226,141,24,210,141,8,210,141,56,210,
1368 141,40,210,141,30,5,141,31,5,96,157,32,5,157,40,5,
1369 157,48,5,157,176,5,96,152,157,208,5,41,240,157,216,5,
1370 189,208,5,10,10,10,10,157,224,5,96,41,7,133,250,138,
1371 166,250,41,63,240,225,157,152,5,152,48,238,189,208,5,32,
1372 117,15,169,0,157,120,5,185,255,255,240,190,157,136,5,133,
1373 251,185,255,255,157,128,5,133,250,152,157,144,5,160,8,177,
1374 250,200,157,192,5,177,250,200,157,200,5,177,250,200,157,104,
1375 6,177,250,200,157,112,6,177,250,200,157,120,6,177,250,200,
1376 157,232,5,157,248,5,177,250,200,157,240,5,157,0,6,177,
1377 250,41,112,74,74,157,16,6,177,250,200,48,8,41,15,157,
1378 24,6,76,9,16,41,15,73,255,24,105,1,157,24,6,177,
1379 250,200,157,40,6,177,250,200,41,63,157,48,6,157,56,6,
1380 177,250,41,128,10,42,157,96,6,177,250,41,112,74,74,74,
1381 74,157,64,6,208,3,157,96,6,177,250,136,41,15,157,80,
1382 6,157,88,6,177,250,41,192,29,152,5,157,152,5,168,185,
1383 0,3,157,56,5,169,0,157,184,5,157,32,6,157,8,6,
1384 157,72,6,157,128,6,157,136,6,157,144,6,169,1,157,120,
1385 5,96
1386END_CONST_ARRAY;