commit dfbf66ea398ead2670cb30390fb8303dda2ca3ed
Author: Godzil If you use Windows or TI calculators you don't need to build GTC yourself as
+there are already precompiled versions available. If you use Unix-like operating systems (Linux, Mac OS X...) you will have to
+follow these instructions to build GTC yourself. You should need no special package apart from GNU make and a C/C++ compiler to
+build GTC. On Windows you will need Cygwin. Just type (replace By default GTC will be installed in The above instructions are designed to only recompile platform-dependent files
+and as such have minimal dependencies. If you want to modify precompiled data such as the precompiled headers you will
+need extra packages like Perl and possibly Ruby. The Makefiles follow these conventions: All Makefiles are designed to be safely used with parallel compilation.
+ The computer version of GTC has a number of options available on the command-line. They are all listed here. Please note that currently, these options are not available for the FlashApp version. To compile a file named This will create files named You can modify the behaviour of GTC with command-line options (or command-line switches). Their position on the command-line does not matter. For example, if you want to use the Or, equivalently: See below for a complete list of options. By default, By default, calculator executables are stored in the By default, It is in the philosophy of GTC to have default options as sensible as possible, so optimization options are kept to a bare minimum. Furthermore, optimizations are always enabled. This switch will make your program much smaller and very slightly faster, at the expense of a short loading time (usually less than half a second). However note that because it adds an unpacker to your program, it will make very small programs (less than 3-4 kilobytes) larger, so it should not be used in this case. It has the same effect as defining the It can be an interesting way to work around AMS's program size limit for AMS version 2.0x, because a program that exceeds the size limit when uncompressed can be compressed to a size below the limit. Not an option per se, but a way to indicate that all arguments after GTC is composed of three separate parts: the GTC compiler, the GTC IDE and the
+GTC standard library. You are free to use these parts separately or in
+combination. You can redistribute or modify GTC freely for non-commercial use, as long as
+you also redistribute the modified source and comply with the licenses of the
+components you choose to distribute: you cannot redistribute the GTC standard
+library if you fail to comply with the terms of the GNU General Public
+License, version 2 (GPL). In addition you may redistribute the GTC standard
+library under the terms of the GPL license, without restriction on commercial
+use. Excluding the standard library, the main author of GTC is Paul Froissart,
+however GTC would not have been possible without building upon the work of
+the following contributors. The GTC standard library is a simple recompilation of old versions of the TIGCC
+library, adapted for usage of a different calling convention. As such it is
+licensed under the terms of the GNU General Public License, with an
+exception allowing linking of the library with external programs, and
+redistribution of the linked programs notwithstanding the provisions of the
+GPL. The TIGCC library was written by Zeljko Juric, Thomas Nussbaumer, Sebastian
+Reichelt, Kevin Kofler and other contributors to the
+ TIGCC project. The GTC compiler is based on the 68000 and i386 C compiler III.1 by Christoph
+van Wuellen (1989-1991), itself based on the 68000 compiler by Matthew Brandt
+(1984-1986). The The code to import Some people provided significant help without contributing code to the project. Thanks to Olivier Armand for his FlashAppy patch: since TI has stopped signing
+Flash applications this is absolutely vital to GTC. Thanks to vince from the Ti-Fr team for his generous hosting. Thanks to all the testers who helped uncover bugs. You will find the latest versions and online documentation on the GTC website: Please use the feedback form to submit bugs or
+comments.
+ You will find GTC supports a number of extensions, designed to take advantage of the TI platform, or simply to maintain compatibility with existing programs. See Generalized Lvalues. Note however that weird constructs like See Compound Literals (Cast Constructors). There is some difference in the handling of static storage duration though, see Differences between GTC and TIGCC. See Designated Initializers, but in GTC this only works for array types. See Specifying Attributes of Functions, however not all of the specifiers are meaningful in GTC. It is sometimes convenient to include binary files directly into your program, for example when using sprites. The You can use The first declaration creates an array of 16 shorts containing the hexadecimal numbers provided.
+The second declaration creates an array of 16 shorts whose representation in memory will be the same as Note that for the sake of portability, GTC allows you to program in assembly, with a syntax very close to that of a68k. In fact, it is powerful enough to write full assembly programs using only GTC! You can insert assembly code at the global level, for example: This creates an assembly function named To use such a function in C code, you need to prototype it: This tells GTC that your function takes a You can also insert assembly code within a function. This has the advantage over global assembly functions to eliminate the overhead associated with a function call. This functions turns off the calculator when An You must separate different declarations either: The behaviour of GTC is indeed very close to that of The most notable difference is perhaps that, where After execution of Note the In this example, Because What's most interesting in all this is that the C library required no modification whatsoever to allow using ROM calls in such a way: ROM calls are not defined twice, and there isn't even a conditional statement acting differently inside This is an operator reserved to operands of instructions in The reason why this operator exists is simple: assembly and C each have different arithmetic rules. For example, if you have the following code: then, while in C So when you write: then, as you would expect from assembly code, This works with But GTC allows you to do much more: you may want to access information that requires access to the full typing system of C, not just the addresses of different objects.
+The way you can access this typing system is by the then GTC goes one step further, by automatically enclosing Here both The prefix This is not very useful in normal C code, but it can be useful in conjunction with other GTC extensions, mainly This could be because you do not have enough free RAM (more than 100kb is recommended), but if you have enough RAM it is probably because the function abc is too large to fit in the memory of the calculator. You will need to split into smaller functions to avoid the error. Another reason could be that you have a It all depends on what features your program uses. Here is a list of porting issues: Additionally, you may run into these little behaviour differences: This list may not be exhaustive, but I will be happy to hear about any problems you might have that are not mentioned in this list. You should not have much trouble compiling GTC programs with TIGCC as GTC was designed to introduce as few incompatibilities as possible. However, if you use low-level features like assembly you might run into some problems: The traditional (and popular) assembler for TI calculators. It is currently
+distributed as part of TIGCC.Building GTC
+Building the binaries
+./configure && make && sudo make installmake with make -j to take advantage of multiprocessor systems)./usr/local. If you want to install it in
+a different directory (for example if you don't have administrator rights), use
+the following command:./configure --prefix $HOME/my_directory && make installRebuilding a modified GTC
+Notes for developers
+
+make clean cleans up intermediary files, but not final files.
+make distclean cleans up intermediary files and any platform-dependent
+ files.
+make scratchclean cleans up everything that can be rebuilt. Note: use
+ with care, as if you don't have the right tools installed you are not going
+ to be able to rebuild GTC.
+GTC Command-line options
+
+
+
+
+
+
+
+
Basic usage
Invocation
+hello.c, open a command-line prompt in the folder where hello.c is stored, and type:
+gtc hello.c
+
+hello.89z, hello.9xz and hello.v2z (or only some of those, if your program is specific to a calculator model). You can now run them after sending them to your calculator or to an emulator.Adding options
+-o switch to create files named somename.89z, somename.9xz and somename.v2z, you can type:
+gtc hello.c -o somename
+
+
+gtc -o somename hello.c
+
+List of all options
Options affecting output
-o switch
+gtc hello.c foo.c bar.c results in an executable named hello.89z or hello.v2z. You can specify other names with this switch, for example gtc hello.c foo.c bar.c -o somename will instead create an executable named somename.89z or somename.v2z.--folder switch
+main folder. You can store them in the folder somefold with the switch --folder=somefold.--output switch
+gtc hello.c -o somename results in an executable named somename.89z; the name of the program on the calculator will thus be somename(). You can change this with the switch --output=myprog: gtc hello.c -o somename --output=myprog creates an executable named somename.89z containing a program whose name on the calculator will be myprog().Preprocessor options
Optimization options
+-exe switch
+EXE_OUT preprocessor symbol.Other options
-- separator
+-- are really filenames and not command-line switches.
+For example gtc -DHELLO hello.c -- foo.c -file-with-dashes-.c will compile the 3 files hello.c, foo.c and -file-with-dashes-.c, with the single option -DHELLO. Without -- the file -file-with-dashes-.c would have been understood as an (invalid) command-line option.
+Information
+
+
+Credits and licensing
+Standard library
+Compiler core
+Compression routines
+-exe mode is based on the PuCrunch algorithm written by Pasi Albert Ojala, and adapted for use on TI calculators by Thomas Nussbaumer.Object file import
+.o files is based on obj2ti written by Julien Muchembled and further modified by Sebastian Reichelt and Kevin Kofler.Thanks
+Contact
+GTC examples
+GTC Extensions
+
+
+
+
+
GNU extensions
+
+Generalized Lvalues
+(a,b)+=5 are rejected by GTC -- commas are not considered legal lvalues.Compound Literals (Cast Constructors)
+Designated Initializers
+Specifying Attributes of Functions
+GTC-specific extensions
incbin directive
+incbin directives allows you to do just that, without having to convert your data to a decimal or hexadecimal header (which can be memory-consuming on a TI).Using
incbin to declare a C array
+incbin to initialize the contents of a C array:
+// The following declares a sprite using normal C initializers
+short sprite1[] = {
+ 0xFFFF, 0x8008, 0x8008, 0xFFFF,
+ 0xFF00, 0x8800, 0x8800, 0x8800,
+ 0x00FF, 0x0088, 0x0088, 0x0088,
+ 0xFFFF, 0x8008, 0x8008, 0xFFFF,
+};
+
+// The following declares a sprite using
+incbin,
+// reading the contents from the file sprite.bin
+short sprite2[] = incbin "sprite.bin";
+sprite.bin.import_binary can be a useful
+alternative, although there are several caveats: you will have to manually
+declare the size of the array if sizeof is to be used, and you cannot use it
+to declare a static array inside a function.asm{} statement
+Inserting an
asm{} statement in the codeGlobal
asm{} statements
+
+asm {
+add_3_and_multiply_by_5:
+ add.w #3,d0
+ mulu #5,d0
+ rts
+};
+
+add_3_and_multiply_by_5 that takes an input argument in d0, adds 3 to it, multiplies it by 5, and returns the result in d0.
+short add_3_and_multiply_by_5(short x);
+
+short named x as an input, and outputs a short. Because of the calling convention, x will be placed in d0: see default calling convention for more information on where input arguments to assembly functions will be located.Inline
asm{} statements
+
+void do_something(char *command) {
+ if (!strcmp(command,"off"))
+ asm { trap #4 };
+ else
+ printf("unknown command!\n");
+}
+
+command is "off", by calling trap #4.Structure of an
asm{} statement
+asm{} statement is comprised of a set of declarations between the outer { and } braces.
+A declaration can be:
+moveq #123,d0 my_function: dc.w 123,456,789 or incbin "data.bin" ;) -- however you should absolutely avoid doing this outside #define, as the behaviour may change some day
+asm{} interpretation rules
+a68k. Like a68k, GTC tries to optimize instructions when it is possible, for example add.w #3,d0 will be optimized to addq.w #3,d0. Like a68k, you don't need to add a : after label names: however, while with a68k you can only do so if the label is placed on the first char of the line, with GTC you can do so any time as long as the label does not correspond to an assembly instruction.a68k uses specific commands like equ and equr to define macros, GTC simply uses the C preprocessor. This is very powerful, as it allows you to define constants just once and reuse them in C code. You can also use normal C conditionals like #if or #ifdef, making conditional compilation easier.
+You can also interface your code with C much more easily, for example you have access to the sizeof operator:
+int table[] = { 1,2,3,4 };
+
+asm {
+negate_table:
+ lea table,a0
+ moveq #sizeof(table)/2-1,d0
+\loop
+ neg.w (a0)+
+ dbra d0,\loop
+ rts
+};
+
+negate_table, table will be equal to { -1,-2,-3,-4 }.\ in \loop: this means that the label is local. However, this notion differs slightly from that of a68k: while the label is only valid between the surrounding two global labels in a68k, the label is valid throughout the asm{} statement in GTC. It is often more convenient, as this example shows:
+asm {
+\return_with_error
+ moveq #-1,d0
+ rts
+my_function:
+ addq.w #5,d0
+ bmi.s \return_with_error
+ tst.w d1
+ bmi.s \return_with_error
+ ... very long code (longer than 128 bytes) ...
+ rts
+};
+
+\return_with_error is placed before my_function because it allows the branches to \return_with_error to be short branches (bmi.s, 2 bytes) rather than long branches (bmi.w, 4 bytes). If GTC followed the rules of a68k, then it would require \return_with_error to be a global, which can be inconvenient if you have lots of these. Instead, it allows you to structurally divide your program in logical asm{} blocks.Extra features of
asm{} statements
+asm{} statements rely on the C compiler architecture of GTC, there are lots of nice features, for example:
+#define USE_KERNEL
+#include <std.h>
+asm {
+_main:
+ pea "Hello, world!"(pc)
+ jsr ST_helpMsg
+ addq.l #4,a7
+ rts
+};
+
+asm{} code and inside C code!
+This is possible because the assembler was able to interpret the C construct corresponding to ST_helpMsg.asm{} special operator: __c__
+asm{} statements.
+int table[] = { 1,2,3,4 };
+
+table+2 will designate the address of table[2] (the number 3), in assembly table+2 will designate the address of table[0] plus 2 bytes, which happens to be the address of table[1].
+asm {
+load_address:
+ lea table+2(pc),a0
+ rts
+};
+
+table+2 corresponds to the address given by assembly arithmetic rules.#define statements too:
+asm {
+load_address:
+#define my_item table+2
+ lea my_item(pc),a0
+ rts
+};
+
+__c__ operator: if you write
+asm {
+load_address:
+ lea __c__(table+2)(pc),a0
+ rts
+};
+
+table+2 will not be interpreted according to assembly rules, but according to C rules: that is, __c__(table+2) is the adress of table[2].#defines written as part of C code in the __c__ operator:
+int table[] = { 1,2,3,4 };
+#define third_item &table[2] // note: table+2 would give the same results
+
+int *c_load_address() {
+ return third_item;
+}
+
+asm {
+load_address:
+ lea third_item(pc),a0
+ rts
+};
+
+c_load_address() and load_address() do the same thing, without ever having to define third_item twice!@@ prefix
+@@ can be prepended to any identifier to prevent it from being expanded by the preprocessor.
+For example, @@MY_SYMBOL will expand to MY_SYMBOL even if MY_SYMBOL has been #defined to expand to 0x1234.asm{} statements and pre-compiled headers.Frequently Asked Questions
+Common issues
(on-calc) I keep getting errors such as "
not enough memory to compile function abc"
+#define with a large body, or a very
+large number of global declarations. This shouldn't be a problem for most
+programs, but if you think you are in this case, you can try to solve it with #undef or by creating a precompiled header.Differences between GTC and TIGCC
How can I port my program from TIGCC to GTC?
+
+long long support: GTC does not support them, if you use them you will have to rewrite your code to use two longs instead. In many cases it's very easy to port.
+asm() vs asm{}: the assembly syntax is different between GTC and TIGCC. However if you are familiar with a68k you will be able to use GTC's syntax in no time.
+float/double support: currently, GTC does not support floats. If your program uses floats, then unless you think you can get rid of them (e.g. if you are only using them for sines and cosines, you can use a pre-computed table instead), you're basically stuck and should definitely continue using TIGCC (unless you're willing to go down to the assembly level). Sorry.
+
+
+int *f(int *dest,int x) {
+ memcpy(dest,(int[4]){x,x+1,x+2},8);
+ return dest;
+}
+
+is not accepted by GTC because the array constructed is not constant (x is not known at compile time). But you can rewrite it to use a temporary array instead:
+
+int *f(int *dest,int x) {
+ int temp[4] = {x,x+1,x+2};
+ memcpy(dest,temp,8);
+ return dest;
+}
+
+regparm(2,1) convention, while TIGCC uses the stkparm convention. This is only a problem if you have written assembly functions yourself; in this case, you have to specify the calling convention you use in the prototype, e.g.:
+
+asm {
+upper_8_bits:
+ move.b 4(a7),d0
+ rts
+};
+char upper_8_bits(long x);
+
+would become
+
+asm {
+upper_8_bits:
+ move.b 4(a7),d0
+ rts
+};
+char upper_8_bits(long x) __attribute__((stkparm));
+
+How can I make sure my GTC program can be compiled with TIGCC too?
+
+asm {
+turn_calculator_off:
+ trap #4
+ rts
+};
+
+into this more portable program:
+
+#ifdef __GTC__
+/* assembly code using GTC's
+asm{} syntax */
+asm {
+turn_calculator_off:
+ trap #4
+ rts
+};
+#else
+/* assembly code using TIGCC's asm() syntax */
+asm("
+turn_calculator_off:
+ trap #4
+ rts
+");
+#endif
+regparm.
+Glossary
+
+a68k
+
GTC is a C compiler to create programs for the TI-89/TI-92+/V200 calculators. You can choose to run the compiler either on a computer (cross-compilation) or directly on a TI calculator (on-calc compilation). +You can download GTC here.
+Warning: the Windows version does not have a graphical interface yet, so +you should only use it if you know how to run programs from the command line.
+Please note this is preliminary documentation. Some important topics are +missing, and you may find broken links.
+General information:
+ +Getting started:
+General TI programming documentation:
+GTC-specific documentation:
++ GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details typeshow w'. + This is free software, and you are welcome to redistribute it + under certain conditions; typeshow c' for details. + +The hypothetical commandsshow w' andshow c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other thanshow w' andshow c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. +
Sorry, this entry has not been written yet!
You must first install FlashAppy on your calculator. Note that like all ROM +patches, you will not be able to send your modified calculator ROM image to +other calculators. Neither the authors of GTC nor the author of FlashAppy can +be held responsible for any damage that could occur during or after this +process. However, we are not aware of any case where a calculator was damaged +by FlashAppy.
+You only need to install FlashAppy once: you won't need to reinstall it after a +reset or after upgrading to a newer version of GTC. On the other hand if you +install an AMS update you will need to reinstall FlashAppy afterwards.
+Legal notice: the .89t/.9xt/.v2t and .89y/.9xy/.v2y files in the bin-89/92p/v200 directories are subject to the GNU General Public License, which grants you a number of rights. You may choose not to install them, but this will prevent you from using the TIGCC Library.
Once FlashAppy is installed, send all the files in the bin-89, bin-92p or bin-v200 directory (depending on the model) to your calculator, and archive
+them all.
Check that the GTC flashapp was properly transferred by entering the Var-Link +screen and pressing F7: you should see GTC appear in the list. Otherwise, the +transfer failed: make sure that FlashAppy is installed and that you have enough +Archive memory.
+To create a test source file, create a directory named source, create an
+empty text file inside that directory named hello with the TI text editor,
+and archive it with the Var-Link screen.
Now you can run the IDE by typing gtc\gtc_ide() and open the file named hello.
Type in the following code:
+
+#include <tigcclib.h>
+
+void _main() {
+ ST_helpMsg("Hello world!");
+}
+
+Now press the F5 key. This should bring up a compilation dialog, which should +close after a few seconds (if not, you may not have installed GTC properly: +make sure FlashAppy is correctly installed, that everything is archived, and +that you have enough RAM).
+Once the compilation is over you can exit the IDE and run your program by +typing
++outbin() ++
It should display the text Hello world! in the status line. If it worked,
+congratulations! You now have a working C compiler on your calculator.
Here is a small subset of the key commands supported by GTC IDE:
+Also, GTC IDE supports keyboard shortcuts that the standard text editor +doesn't: for example, you can press Shift-2nd-Right (press Shift and 2nd, +then press Right while still holding Shift and 2nd) to highlight the text from +the cursor to the end of the line. Likewise you can press Shift-2nd-Down to +highlight a whole screen of text, or Shift-Diamond-Down to select until the +end of the file. These shortcuts come in particularly handy when selecting +large amounts of text.
+main\outbin() to a kbdprgm like kbdprgm9 so that you can
+ quickly run a freshly compiled program by typing Diamond-9 in the Home
+ screen.
+zheader. You should not delete stdhead or keywords if you want to
+ compile programs designed for the TIGCC library.
+A calling convention specifies where arguments to a function are placed, and where the function places its return value. +You shouldn't worry about it, unless you are an assembly programmer trying to call assembly functions from C code or vice-versa.
+regparm)Unless otherwise specified, GTC uses the most efficient calling convention, regparm.
+Basically, it consists of placing as many arguments as possible into a small set of registers for maximum efficiency, and when they are all used, place the remaining arguments on the stack, which is less efficient.
More precisely, here is the specific algorithm for placing arguments:
+a, from left to right
+d0,d1,d2,a0,a1} are already used by other arguments
+a on the stack
+d0,d1,d2} unused and one of {a0,a1} unused
+a's type is a pointer
+a in the next free address register
+a in the next free data register
+a0,a1} is unused
+a in the next free address register
+a in the next free data register
+Here is how the placement of an argument is done:
+a in the next free data register:
+a in d0 if it is unused
+a in d1 if it is unused
+a in d2 a in the next free address register:
+a in a0 if it is unused
+a in a1 a on the stack:
+stkparm Here is the algorithm for placing the return value:
+a0 d0 struct or a union d0 (not the address!)
+Note that regparm requires the function to have a fixed number of arguments: otherwise, for variable-argument functions, no arguments are placed in registers, and the stkparm convention is used instead.
Note that TIGCC uses the same algorithm, as long as you specify the function attribute __attribute__((regparm(2,1))).
You can also use a different set of variables than d0-d2/a0-a1 thanks to the regparm function attribute, but it is not recommended.
stkparm)The stkparm convention is less efficient, but is useful because it is the one used internally by AMS. It is also much simpler to describe.
The arguments are pushed one after the other onto the stack, starting from the rightmost argument. chars and unsigned chars should be widened to an int before being pushed.
+
Warning: the Windows version does not have a graphical interface yet, so +you should only use it if you know how to run programs from the command line.
+Legal notice: the Include directory is subject to the GNU General Public License, which grants you a number of rights. You may choose not to install it, but it will prevent you from using the TIGCC Library.
To install GTC just extract gtc.exe and the Include directory to any
+directory. You should add that directory to your Windows path (Control Panel →
+System → Advanced → Environment Variables, and modify the PATH variable).
Now you can invoke gtc on the command-line, for more information see GTC
+Command-line options.
+
') { + getch(); + lastst = pointsto; + } else + lastst = minus; + break; + case '*': + getch(); + if (lastch == '=') { + getch(); + lastst = astimes; + } else + lastst = star; + break; + case '/': + getch(); + if (lastch == '=') { + getch(); + lastst = asdivide; + /*} else if (lastch == '*') { + getch(); + for (;;) { + if (lastch == '*') { + getch(); + if (lastch == '/') { + getch(); + goto restart; + } + } else getch(); + } + } else if (lastch == '/') { + getch(); + for (;;) { + if (lastch == '\n') { + getch(); + goto restart; + } else getch(); + }*/ + } else + lastst = divide; + break; + case '^': + getch(); + if (lastch == '=') { + getch(); + lastst = asuparrow; + } else + lastst = uparrow; + break; + case ';': + getch(); + lastst = semicolon; + break; + case ':': + getch(); + lastst = colon; + break; + case '=': + getch(); + if (lastch == '=') { + getch(); + lastst = eq; + } else + lastst = assign; + break; + case '>': + getch(); + if (lastch == '=') { + getch(); + lastst = geq; + } else if (lastch == '>') { + getch(); + if (lastch == '=') { + getch(); + lastst = asrshift; + } else + lastst = rshift; + } else + lastst = gt; + break; + case '<': + getch(); + if (lastch == '=') { + getch(); + lastst = leq; + } else if (lastch == '<') { + getch(); + if (lastch == '=') { + getch(); + lastst = aslshift; + } else + lastst = lshift; + } else + lastst = lt; + break; + case '\'': + getch(); + ival = getsch(0); /* get a string char */ + if (lastch != '\'') + error(ERR_SYNTAX); + else + getch(); + lastst = iconst; + break; + case '\"': + if (forbid!=sconst) { + getch_in_string=1; + getch(); + for (i = 0; ; ++i) { + if ((j = getsch(1)) IS_INVALID) + break; + if (i < MAX_STRLEN) + laststr[i] = j; + } + getch_in_string=0; + /* + * Attention: laststr may contain zeroes! + */ + if (i > MAX_STRLEN) { + i = MAX_STRLEN; + uwarn("string constant too long"); + } + lstrlen = i; + laststr[i] = 0; + } + lastst = sconst; + break; + case '!': + getch(); + if (lastch == '=') { + getch(); + lastst = neq; + } else + lastst = not; + break; + case '%': + getch(); + if (lastch == '=') { + getch(); + lastst = asmodop; + } else + lastst = modop; + break; + case '~': + getch(); + lastst = compl; + break; + case '.': + getch(); + if (isdigit(lastch)) { +#ifndef NOFLOAT + rval = 0; + getfrac(); +#endif + lastst = rconst; + if (lastch=='e' || lastch=='E') { + getch(); +#ifndef NOFLOAT + getexp(); +#endif + } + } else if (lastch=='.') { + getch(); + if (lastch!='.') error(ERR_SYNTAX); + getch(); + lastst = dots; + } else + lastst = dot; + break; + case ',': + getch(); + lastst = comma; + break; + case '&': + getch(); + if (lastch == '&') { + lastst = land; + getch(); + } else if (lastch == '=') { + lastst = asand; + getch(); + } else + lastst = and; + break; + case '|': + getch(); + if (lastch == '|') { + lastst = lor; + getch(); + } else if (lastch == '=') { + lastst = asor; + getch(); + } else + lastst = or; + break; + case '(': + getch(); +#ifdef ASM +#ifdef OLD_AMODE_INPUT + if (asm_xflag + && ((lastch=='p' && *lptr=='c') + || (lastch=='s' && *lptr=='p') + || (lastch=='a' && *lptr>='0' && *lptr<='7')) + && (lptr[1]==')' || lptr[1]==',')) + lastst = kw_offs_end; + else +#else + if (asm_xflag + && ((lastch=='p' && *lptr=='c') + || (lastch=='s' && *lptr=='p') + || (lastch=='a' && *lptr>='0' && *lptr<='7')) + && (lptr[1]==')' || lptr[1]==',')) + lastst_flag=1; + else lastst_flag=0; +#endif +#endif + lastst = openpa; + break; + case ')': + getch(); + lastst = closepa; + break; + case '[': + getch(); + lastst = openbr; + break; + case ']': + getch(); + lastst = closebr; + break; + case '{': + getch(); + lastst = begin; + break; + case '}': + getch(); + lastst = end; + break; + case '?': + getch(); + lastst = hook; + break; + case '#': + getch(); + // TODO: rewrite the following (disabled because not ANSI-compliant) + /*getsym(); + if (lastst==id) { + SYM *sp; + if (mac_sp!=&mac_stk[MAX_MAC_NUM] && + (sp = search(lastid, lastcrc, (HTABLE *)*mac_sp))) { + char c,*q=sp->value.s; char buf[MAX_STRLEN],*bp; int i; + lastst=sconst; + bp=buf; + *bp++='"'; + i=MAX_STRLEN-1-2; + do { + if (!(c=*q++)) break; + if (c=='"') { *bp++='\\'; *bp++='"'; } + else *bp++=c; + } while (i--); + *bp++='"'; + lptr-=bp-buf+1; + memcpy(lptr,buf,bp-buf); + getch(); + } else error(ERR_UNDEFINED); + } else if (lastst==lconst||lastst==iconst||lastst==uconst) { + char buf[MAX_STRLEN],*bp; + lastst=sconst; + bp=buf; + *bp++='"'; + sprintf(bp,"%ld",ival); + bp+=strlen(bp); + *bp++='"'; + lptr-=bp-buf+1; + memcpy(lptr,buf,bp-buf); + getch(); + } else error(ERR_IDEXPECT); + getsym();*/ +#ifdef ASM + if (asm_flag) { + lastst = sharp; + break; + } else { +#endif + error(ERR_ILLCHAR); + goto restart; /* get a real token */ +#ifdef ASM + } +#endif +/* if (lastst==iconst || lastst==lconst || lastst==uconst) { + lastst=sconst; + if (forbid!=lastst) sprintf(laststr,"%ld",ival); + else { + char b[20]; int n; + sprintf(b,"%ld",ival); + lptr-=1+(n=strlen(b)); + strncpy(lptr,b,n); + lptr[n]='"'; + } + } else error(ERR_INTEGER);*/ + break; +#ifdef ASM + case '\\': + if (asm_flag) { + if (forbid==(lastst=id)) return; + getch(); + if (getid((int)'\\')) goto restart; + } else { + getch(); + error(ERR_ILLCHAR); + goto restart; /* get a real token */ + } + break; +#endif + case '@': + getch(); + if (lastch=='@') { + getch(); + if (isbegidch(lastch)) { + if (forbid==(lastst=id)) return; + getrawid(); + break; + } + } + /* otherwise fall through */ + default: + getch(); + error(ERR_ILLCHAR); + goto restart; /* get a real token */ + } + if (lastst == id) { + searchkw(); +//#ifdef OLD_MACRO + if (lastst == kw_eval) { + struct enode *ep; + getsym(); + needpunc(openpa); + if (!expression(&ep)) error(ERR_EXPREXPECT); + if (lastst!=closepa) needpunc(closepa); + opt0(&ep); + if (ep->nodetype==en_icon) { + lastst=lconst; + ival=ep->v.i; +#ifndef NOFLOAT + } else if (ep->nodetype==en_fcon) { + lastst=rconst; + rval=ep->v.f; +#endif + } else error(ERR_CONSTEXPECT); + } +#ifdef ASM + else if (asm_flag && lastst == id) { + if (!lastid[2]) { + if (lastid[1]>='0' && lastid[1]<='7') { + lastreg=lastid[1]-'0'; // we don't care if we set lastreg even if + if (lastid[0]=='d') // lastst is an id + lastst=kw_dreg; // (for example 'z6' will set lastreg to 6) + else if (lastid[0]=='a') + lastst=kw_areg; + } else if (lastid[1]=='p' && lastid[0]=='s') + lastst=kw_areg,lastreg=7; + } + asm_searchkw(); + } +#endif +#if defined(PCH) && !defined(MEXP_SUPPORTS_PCH) + if (lastst==id && !(lastsp = search(lastid, lastcrc, &lsyms)) + && !(lastsp = search(lastid, lastcrc, &gsyms))) { +#if 0 + int n=pchnum; + while (n--) { + unsigned char *p0=pchdata[n],*tab=pchtab[n],*tabp,*p,c,*q; + TI_SHORT *extTab=(TI_SHORT *)(p0+w2s(pchhead[n]->ext_off)); + int z=PCH_HEAD_SIZE; + do { + p=p0+z; q=lastid; + while ((c=*p++) && c==*q++); + if (!c && !*q) { + tabp=&tab[(p[4]<<8)+p[5]]; + if (*tabp) /* really quit, because it would be a mess */ + goto pch_done; /* if we scanned other files for this ID ;) */ + if (pchload(p+6,tabp,p0,extTab)) goto restart; + else { + lastsp = gsearch(lastid, lastcrc); + goto pch_done; + } + } + if (c) while (*p++); + if (c0) goto restart; + else if (n<0) lastsp = gsearch(lastid, lastcrc); +#endif + } +#else + if (lastst==id && !(lastsp = search(lastid, lastcrc, &lsyms))) + lastsp = search(lastid, lastcrc, &gsyms); +#endif + } +/* if (global_flag) + if (lastst==id && !strcmp(lastid,"pos")) + bkpt();*/ +/* if (lineid==0x51) + bkpt();*/ +} + +int getcache(enum(e_sym) f) { + enum(e_sym) my_st=lastst; + int my_flag=lastst_flag; + int my_line=lineid,my_prev=prevlineid; + if (cached_sym!=-1) return (cached_sym==f); + cached_sym=-2; // tell getcache not to put anything into cache + forbid=f; + getsym(); + cached_sym=lastst; + cached_flag=lastst_flag; + cached_lineid=my_line; + lastst=my_st; + lastst_flag=my_flag; + lineid=my_line; + prevlineid=my_prev; + forbid=-1; + if (cached_sym==f) cached_sym=-1; + return (cached_sym==-1); +/* enum(e_sym) my_st=lastst,cached=cached_sym; + if ((int)cached_sym2 IS_VALID) return (cached_sym2==f); + cached_sym=-1; // prevent getsym from caching :) + forbid=f; + getsym(); + forbid=-1; + if ((int)cached IS_VALID) { + if ((int)cached_sym2 IS_VALID) fatal("CACHE"); + cached_sym2=lastst; + cached_sym=cached; + lastst=my_st; + if (cached_sym2==f) cached_sym2=-1; + return (cached_sym2==f); + } else { + cached_sym=lastst; + lastst=my_st; + if (cached_sym==f) cached_sym=-1; + return (cached_sym==f); + }*/ +} + +void needpunc(enum(e_sym) p) { + if (lastst == p) + getsym(); + else + uerr(ERR_PUNCT, + p==semicolon?';': + (p==begin?'{': + (p==end?'}': + (p==openpa?'(': + (p==closepa?')': + (p==hook?'?': + (p==comma?',': + (p==closebr?']':' ')))))))); +} + +extern unsigned char sizeof_flag; +extern unsigned char id_are_zero; +void do_compile() { + /* parser initialization */ + sizeof_flag=0; id_are_zero=0; + flags=flags_basegtc; +#ifdef SPEED_OPT + speed_opt_value = default_speed_opt_value; +#endif + /* lexical analyzer / preprocessor initialization */ + initsym(); + /* compilation itself */ + compile(); +} +#ifdef PCH +void closepch() { +#ifdef REQ_MGT + { + FILE *req_file=NULL; + int i,needs_req=0; + for (i=pchnum;i--;) + if (pchrequired[i] && strcmp(pchname[i],"stdhead")) + needs_req++; + if (needs_req) { + char buf[sizeof("[Req_v1]\n")+1]; + char temp[5000]; + *temp=0; + req_file=fopen(proj_file,"r"); + if (req_file) { + while (!feof(req_file)) { + fgets(buf,sizeof("[Req_v1]\n"),req_file); + strcat(temp,buf); + if (!strcmp(buf,"[Req_v1]\n")) { + needs_req=0; + break; + } + } + fclose(req_file); + } + req_file=fopen(proj_file,"w"); + if (!req_file) fatal("Could not open project file."); + fputs(temp,req_file); + if (needs_req) + fputs("[Req_v1]\n",req_file); + needs_req=1; + } +#endif + /* close PCH files */ + while (pchnum) { + pchnum--; +#ifdef REQ_MGT + if (pchrequired[pchnum] && needs_req) + fprintf(req_file,"%s\n",pchname[pchnum]); +#endif + fclose(pchfile[pchnum]); + } +#ifdef REQ_MGT + if (needs_req) + fclose(req_file); + } +#endif +} +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/gtdevcomm.c b/gtc/src/gtdevcomm.c new file mode 100644 index 0000000..286014f --- /dev/null +++ b/gtc/src/gtdevcomm.c @@ -0,0 +1,43 @@ +/* + * GTools C compiler + * ================= + * source file : + * (on-calc) communication with the GT-Dev IDE + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "GtDevComm.h" + +extern int has_error; + +char *in_file CGLOB,*out_file CGLOB; +Msg_Callback_t msg_process CGLOB; +Progr_Callback_t progr_process CGLOB; +#include "identity.h" +void _gtdevmain(void); +int Compile(char *in,char *out,Msg_Callback_t _msg_process,Progr_Callback_t _progr_process) { + void *old_a5=bssdata; + int res; + bssdata=malloc(BSS_SIZE); + if (!bssdata) return; + memset(bssdata,0,BSS_SIZE); + in_file=in; out_file=out; + msg_process=_msg_process; + progr_process=_progr_process; + _gtdevmain(); + bssdata=identity(bssdata); + if (!bssdata) + return 2; + res=has_error; + free(bssdata); + bssdata=old_a5; + return res; +} +// vim:ts=4:sw=4 diff --git a/gtc/src/gtdevcomm.h b/gtc/src/gtdevcomm.h new file mode 100644 index 0000000..2a201fb --- /dev/null +++ b/gtc/src/gtdevcomm.h @@ -0,0 +1,44 @@ +/* + * GTools C compiler + * ================= + * source file : + * (on-calc) communication with the GT-Dev IDE + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#ifndef __GTDEVCOMM_H +#define __GTDEVCOMM_H + +//#include "E:\Paul\89\Ti-GCC\Projects\GT-Dev\SecureCommDef.h" +#include "securecommdef.h" + +#define ET_FATAL -2 +#define ET_WARNING -1 +#define ET_ERROR 0 +#define ET_INTERNAL_WARNING 1 +#define ET_INTERNAL_FAILURE 2 +#define et_isinternal(x) ((x)>0) +#define et_iserror(x) !((x)&1) +#if __TIGCC_BETA__*100+__TIGCC_MINOR__>=94 +#define CALLBACK __ATTR_TIOS_CALLBACK__ +#else +#define CALLBACK +#endif +typedef void (CALLBACK*Msg_Callback_t)(char *message,int err_type,char *func,char *file,int line,int chr); +//typedef _Msg_Callback_t *Msg_Callback_t; +#define MAX_PROGRESS 65535 +typedef void (CALLBACK*Progr_Callback_t)(char *func,char *file,unsigned int fprogress); +//typedef _Progr_Callback_t *Progr_Callback_t; + +extern char *in_file,*out_file; +extern Msg_Callback_t msg_process; +extern Progr_Callback_t progr_process; +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/gtpack/gtpack.c b/gtc/src/gtpack/gtpack.c new file mode 100644 index 0000000..99530f8 --- /dev/null +++ b/gtc/src/gtpack/gtpack.c @@ -0,0 +1,2259 @@ +/****************************************************************************** +* +* A variant of ttpack designed to output XPak compressed data. +* +* ----------------------------------------------------------------------------- +* +* original project name: TIGCC Tools Suite +* file name: ttpack.c +* initial date: 14/08/2000 +* authors: albert@cs.tut.fi +* thomas.nussbaumer@gmx.net +* Paul Froissart +* description: packing program +* +* ----------------------------------------------------------------------------- +* +* based on code from Pasi 'Albert' Ojala, albert@cs.tut.fi +* +* heavily reduced to fit to the needs by thomas.nussbaumer@gmx.net +* +* modified to fit XPak's compression format +* +******************************************************************************/ + +#include+#include +#include +#include +#include +#include + +//#define ONCALC_PACKER_EMU +//#define EVEN_LZ // allow only LZ sequences with the same parity +//#define NEW_RANGE // LZhuf-like range coding +//#define X_STATS +#define NO_XVERBOSE +//#define ZRANGE +//#define ZRANGE_FAST + +#include "tt.h" // generic defines +#include "ttversion.h" // tigcc tools suite version info +#include "revtools.h" // used for id displaying +#include "ttunpack.h" // errorcodes definition +#include "packhead.h" // compressed header definition + +#define CVS_FILE_REVISION "$Revision: 1.4 $" + +#define FIXF_MACHMASK 0xff +#define FIXF_WRAP 256 +#define FIXF_DLZ 512 + + +#define F_VERBOSE (1<<0) +#define F_STATS (1<<1) +#define F_AUTO (1<<2) +#define F_NOOPT (1<<3) +#define F_AUTOEX (1<<4) +#define F_TEXTINPUT (1<<5) +#define F_TEXTOUTPUT (1<<6) +#define F_NORLE (1<<9) +#define F_ERROR (1<<15) + +#ifndef min +#define min(a,b) ((a 1..127 */ +#else +#define LRANGE 6144 /* packer() emulation */ +#endif +#ifdef NEW_RANGE +#undef LRANGE +#define LRANGE 4096 +#endif +#ifdef ZRANGE +#undef LRANGE +#define LRANGE 6144 +#endif +#define MAXLZLEN (2< 1..127 */ +#define DEFAULT_LZLEN LRANGE + + + +unsigned short *rle, *elr, *lzlen, *lzpos; +unsigned short *lzlen2, *lzpos2; +int *length, inlen; +unsigned char *indata, *mode, *newesc; +unsigned short *backSkip; + + +enum MODE { + LITERAL = 0, + LZ77 = 1, + RLE = 2, + DLZ = 3, + MMARK = 4 +}; + +int lzopt = 0; + + +int maxGamma = 7; +int reservedBytes = 2; +int escBits = 2; +int escMask = 0xc0; +int extraLZPosBits = 0; +int rleUsed = 31; + + +/* +//============================================================================= +// outputs usage information of this tool +//============================================================================= +void PrintUsage() { + fprintf(stderr, "Usage: ttpack [- ] \n" \ + " -hti treat input as hex textinput\n" \ + " -hto generate hex textoutput\n" \ + " -fdelta use delta-lz77 -- shortens some files\n" \ + " e force escape bits\n" \ + " r restrict lz search range\n" \ + " n no RLE/LZ length optimization\n" \ + " s full statistics\n" \ + " v verbose\n" \ + " p force extralzposbits\n" \ + " m max len 5..7 (2*2^5..2*2^7)\n"); +} +*/ + +/* +//============================================================================= +// the packing code +//============================================================================= +int SavePack(int flags,int type, unsigned char *data, int size, char *target, + int start, int escape, unsigned char *rleValues, + int endAddr, int extraLZPosBits,int memStart, int memEnd) +{ + FILE *fp = NULL; + + int i; + + if (!data) return 10; + if (!target) fp = stdout; + + if ((type & FIXF_MACHMASK) == 0) { + // Save without decompressor + + if (fp || (fp = fopen(target, "wb"))) { + PackedHeader cth; + RLEEntries re; + + cth.origsize_lo = inlen & 0xff; + cth.origsize_hi = (inlen >> 8); + #ifndef COMPACT + cth.magic1 = MAGIC_CHAR1; + cth.magic2 = MAGIC_CHAR2; + cth.compsize_lo = (size + rleUsed + sizeof(PackedHeader)) & 0xff; + cth.compsize_hi = (size + rleUsed + sizeof(PackedHeader)) >> 8; + #else + #ifndef OLD_HDR + memcpy(cth.magic,"GTPk",4); + cth.compsize_lo = (size + rleUsed + sizeof(PackedHeader)) & 0xff; + cth.compsize_hi = (size + rleUsed + sizeof(PackedHeader)) >> 8; + #endif + #endif + cth.esc1 = (escape >> (8-escBits)); + //cth.notused3 + //cth.notused4 + cth.esc2 = escBits; + #if !defined(COMPACT) || defined(OLD_HDR) + cth.gamma1 = maxGamma + 1; + cth.gamma2 = (1 << maxGamma); + #endif + cth.extralz = extraLZPosBits; + //cth.notused1 = 0xff; + //cth.notused2 = 0xff; + cth.rleentries = rleUsed; + + for(i=0; i >= 1; + + if (!bitMask) { +#ifndef NO_XVERBOSE + printf("[%02x]\n",(int)(unsigned char)outBuffer[outPointer]); +#endif + bitMask = 0x80; + outPointer++; + } +} + + + +int lenValue[256]; + +//-------------------------------------------- +// why not initializing value lenValue[0] ???? +//-------------------------------------------- +//============================================================================= +// +//============================================================================= +#if K_GAMMA-1 +void InitValueLen() { + int i,h; + + for (i=1; i<256; i++) { + int count = 0; + + if (i<2) count = 0; /* 1 */ + else if (i<4) count = 1; /* 2-3 */ + else if (i<8) count = 2; /* 4-7 */ + else if (i<16) count = 3; /* 8-15 */ + else if (i<32) count = 4; /* 16-31 */ + else if (i<64) count = 5; /* 32-63 */ + else if (i<128) count = 6; /* 64-127 */ + else if (i<256) count = 7; /* 128-255 */ + +// lenValue[i] = (count>>1)+count+2; + switch (count) { + case 0: h=1; break; + case 1: if (i==2) h=1; else h=2; break; + case 2: h=4; break; + case 3: h=5; break; + case 4: h=6; break; + case 5: h=7; break; + case 6: h=8; break; + case 7: h=9; break; + } + lenValue[i]=h+count; + } +} +#else +void InitValueLen() { + int i; + + // could be heavily optimized, but isn't necessary + for (i=1; i<256; i++) { + int count = 0; + + if (i<2) count = 0; /* 1 */ + else if (i<4) count = 1; /* 2-3 */ + else if (i<8) count = 2; /* 4-7 */ + else if (i<16) count = 3; /* 8-15 */ + else if (i<32) count = 4; /* 16-31 */ + else if (i<64) count = 5; /* 32-63 */ + else if (i<128) count = 6; /* 64-127 */ + else if (i<256) count = 7; /* 128-255 */ + + lenValue[i] = 2*count; + /*if (count 1) { + bits = (bits<<1) | (value & 1); /* is reversed compared to value */ + value >>= 1; + count++; + PutBit(1); + } + /*if (count same as value */ + bits >>= 1; + } +#endif +} + +#ifdef NEW_RANGE +unsigned char p_len[64] = { + 0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, + 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, + 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08 +}; + +unsigned char p_code[64] = { + 0x00, 0x20, 0x30, 0x40, 0x50, 0x58, 0x60, 0x68, + 0x70, 0x78, 0x80, 0x88, 0x90, 0x94, 0x98, 0x9C, + 0xA0, 0xA4, 0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC, + 0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE, + 0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE, + 0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE, + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF +}; +//============================================================================= +// +//============================================================================= +void PutRange(int c) { + int i; + + /* output upper 6 bits with encoding */ + i = c >> 6; + PutNBits((unsigned)p_code[i] >> (8-p_len[i]), p_len[i]); + + /* output lower 6 bits directly */ + PutNBits((c & 0x3f), 6); +} +#endif + +int gainedEscaped = 0; +int gainedRle = 0, gainedSRle = 0, gainedLRle = 0; +int gainedLz = 0, gainedRlecode = 0; +int gainedDLz = 0, timesDLz = 0; + +int timesEscaped = 0, timesNormal = 0; +int timesRle = 0, timesSRle = 0, timesLRle = 0; +int timesLz = 0; + +int lenStat[8][4]; + //0: + //1: + //2: SRLE + //3: RLE byte + //4: + +//============================================================================= +// +//============================================================================= +int OutputNormal(int *esc, unsigned char *data, int newesc) { + timesNormal++; + if ((data[0] & escMask) == *esc) { + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + PutBit(0); + PutBit(1); + PutBit(0); + + *esc = newesc; + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + PutNBits(data[0], 8-escBits); + + gainedEscaped += escBits + 3; + timesEscaped++; + return 1; + } + PutNBits(data[0], 8); + return 0; +} + + +//============================================================================= +// +//============================================================================= +void OutputEof(int *esc) { + /* EOF marker */ + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + PutValue(3); /* >2 */ + PutValue((2< >3)); + + gainedRlecode -= LenValue(32+(data>>3)) + 3; + + PutNBits(data, 3); + + lenStat[5][3]++; +} + + +unsigned char rleLen[256]; + + +//============================================================================= +// +//============================================================================= +void InitRleLen() { + int i; + + for (i=0; i<256; i++) rleLen[i] = LenValue(32 + 0) + 3; + for (i=1; i<32; i++) rleLen[rleValues[i]] = LenValue(i); +} + +#define LenRleByte(d) (rleLen[d]) + + +//============================================================================= +// +//============================================================================= +int LenRle(int len, int data) { + int out = 0; + + do { + if (len == 1) { + out += escBits + 3 + 8; + len = 0; + } + else if (len <= (1< >8)+1) + LenRleByte(data); + len -= tmp; + } + } while (len); + return out; +} + + +//============================================================================= +// +//============================================================================= +int OutputRle(int *esc, unsigned char *data, int rlelen) { + int len = rlelen, tmp; + + while (len) { + if (len >= 2 && len <= (1< = 3 || IsShortRleByte(*data))) { + /* Short RLE */ + if (len==2) lenStat[0][2]++; + else if (len<=4) lenStat[1][2]++; + else if (len<=8) lenStat[2][2]++; + else if (len<=16) lenStat[3][2]++; + else if (len<=32) lenStat[4][2]++; + else if (len<=64) lenStat[5][2]++; + else if (len<=128) lenStat[6][2]++; + else if (len<=256) lenStat[6][2]++; + + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + PutBit(0); + PutBit(1); + PutBit(1); + PutValue(len-1); + PutRleByte(*data); + + tmp = 8*len -escBits -3 -LenValue(len-1) -LenRleByte(*data); + gainedRle += tmp; + gainedSRle += tmp; + + timesRle++; + timesSRle++; + return 0; + } + if (len<3) { + while (len--) + OutputNormal(esc, data, *esc); + return 0; + } + + if (len <= maxrlelen) { + /* Run-length encoding */ + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + + PutBit(0); + PutBit(1); + PutBit(1); + + PutValue((1< >(8-maxGamma))); + + PutNBits((len-1), 8-maxGamma); + PutValue(((len-1)>>8) + 1); + PutRleByte(*data); + + tmp = 8*len -escBits -3 -maxGamma -8 -LenValue(((len-1)>>8)+1) + -LenRleByte(*data); + gainedRle += tmp; + gainedLRle += tmp; + + timesRle++; + timesLRle++; + return 0; + } + + /* Run-length encoding */ + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + + PutBit(0); + PutBit(1); + PutBit(1); + + PutValue((1< >(8-maxGamma))); + + PutNBits((maxrlelen-1) & 0xff, 8-maxGamma); + PutValue(((maxrlelen-1)>>8)+1); + PutRleByte(*data); + + tmp = 8*maxrlelen -escBits -3 -maxGamma -8 + -LenValue(((maxrlelen-1)>>8)+1) -LenRleByte(*data); + gainedRle += tmp; + gainedLRle += tmp; + timesRle++; + timesLRle++; + len -= maxrlelen; + data += maxrlelen; + } + return 0; +} + + +#ifdef ZRANGE +char zrlen[96]={ + 0, + 2,2,2,2, + 3,3,3,3, + 4,4,4,4,4,4,4,4, + 5,5,5,5,5,5,5,5, + 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, + 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 +}; +#define ZrLen(p) (zrlen[((p)-1)>>6]) +#endif + + +//============================================================================= +// +//============================================================================= +int LenLz(int lzlen, int lzpos) { +#ifdef EVEN_LZ + if (lzpos&1) return 100000; +#endif + if (lzlen==2) { +#if !defined(ZRANGE) || defined(ZRANGE_FAST) +#ifdef EVEN_LZ + if (lzpos <= 256) return escBits + 2 + 7; +#else + if (lzpos <= 256) return escBits + 2 + 8; +#endif + else return 100000; +#else + if (lzpos <= 64) return escBits + 2 + 7; + else if (lzpos <= 128) return escBits + 2 + 8; + else if (lzpos <= 256) return escBits + 2 + 9; + else return 100000; +#endif + } + +#ifdef ZRANGE + return escBits + 8 + ZrLen(lzpos) + LenValue(lzlen-1); +#else +#ifdef EVEN_LZ + return escBits + 7 + extraLZPosBits + +#else + return escBits + 8 + extraLZPosBits + +#endif + LenValue(((lzpos-1)>>(8+extraLZPosBits))+1) + + LenValue(lzlen-1); +#endif +} + +#ifdef X_STATS +#define XS_NUM (LRANGE/64+1) +int lzstats[16][XS_NUM]; +int lzstatlong[XS_NUM]; +#endif + +//============================================================================= +// +//============================================================================= +int OutputLz(int *esc, int lzlen, int lzpos, char *data, int curpos) { +#ifdef X_STATS + if (lzlen<=16) + lzstats[lzlen-1][(lzpos-1)>>6]++; + else + lzstatlong[(lzpos-1)>>6]++; +#endif + if (lzlen==2) lenStat[0][1]++; + else if (lzlen<=4) lenStat[1][1]++; + else if (lzlen<=8) lenStat[2][1]++; + else if (lzlen<=16) lenStat[3][1]++; + else if (lzlen<=32) lenStat[4][1]++; + else if (lzlen<=64) lenStat[5][1]++; + else if (lzlen<=128) lenStat[6][1]++; + else if (lzlen<=256) lenStat[7][1]++; + + if (lzlen >= 2 && lzlen <= maxlzlen) { + int tmp; + + PutNBits((*esc>>(8-escBits)), escBits); /* escBits>=0 */ + + tmp = ((lzpos-1)>>(8+extraLZPosBits))+2; + if (tmp==2) lenStat[0][0]++; + else if (tmp<=4) lenStat[1][0]++; + else if (tmp<=8) lenStat[2][0]++; + else if (tmp<=16) lenStat[3][0]++; + else if (tmp<=32) lenStat[4][0]++; + else if (tmp<=64) lenStat[5][0]++; + else if (tmp<=128) lenStat[6][0]++; + else if (tmp<=256) lenStat[6][0]++; + + if (lzlen==2) { + PutValue(lzlen-1); + PutBit(0); + if (lzpos > 256) fprintf(stderr,"Error at %d: lzpos too long (%d) for lzlen==2\n",curpos, lzpos); +#ifdef ZRANGE +#ifdef ZRANGE_FAST + PutNBits(((lzpos-1) & 0xff) ^ 0xff, 8); +#else + { + int x=lzpos-1; + switch (x>>6) { + case 0: PutNBits(x,7); break; // x=0b00****** => 0****** + case 1: PutNBits(x+64,8); break; // x=0b01****** => 10****** + case 2: PutNBits(x+256,9); break; // x=0b10****** => 110****** + case 3: PutNBits(x+256,9); break; // x=0b11****** => 111****** + } + } +#endif +#endif + } + else { +#ifdef ZRANGE + PutValue(lzlen-1); +/* PutNBits(0,ZrLen(lzpos)); + PutNBits(0,8);*/ + { + int x=~(lzpos-1),u=(x+64)>>8; + switch (ZrLen(lzpos)) { +/*u=0*/ case 0: PutNBits(x,8); break; +/*u=-1*/ case 2: PutNBits(0x1,2); PutNBits(x,8); break; +/*u=-2*/ case 3: PutNBits(0x0,2); PutNBits(x,8); PutNBits(0x0,1); break; +/*u=-4..-3*/ case 4: PutNBits(0x0,2); PutNBits(x,8); PutNBits(0x2+(u&1),2); break; +/*u=-6..-5*/ case 5: PutNBits(0x2,2); PutNBits(x,8); PutNBits(0x0+(u&1),3); break; +/*u=-12..-7*/ case 6: PutNBits(0x2,2); PutNBits(x,8); PutNBits(0x4+((u+(12&7))&7),4); break; +/*u=-24..-13*/ case 7: PutNBits(0x2,2); PutNBits(x,8); PutNBits(0x14+((u+(24&15))&15),5); break; + } + } +#else +#ifdef X_STATS + PutValue(lzlen-1); +// PutNBits(0,1+3); + PutNBits(0,3); +#else + PutValue(lzlen-1); +#ifndef NEW_RANGE + PutValue( ((lzpos-1) >> (8+extraLZPosBits)) +1); + PutNBits( ((lzpos-1) >> 8), extraLZPosBits); +#endif +#endif +#endif + } +// PutNBits(0xFF, 8); +#ifndef ZRANGE +#ifndef NEW_RANGE +#ifdef EVEN_LZ + PutNBits((((lzpos-1) & 0xff) ^ 0xff) >> 1, 7); + if (lzpos&1) fprintf(stderr, "Error: odd lzpos\n"); +#else + PutNBits(((lzpos-1) & 0xff) ^ 0xff, 8); +#endif +#else + PutRange(lzpos-1); +#endif +#endif + + gainedLz += 8*lzlen -LenLz(lzlen, lzpos); + timesLz++; + return 3; + } + fprintf(stderr, "Error: lzlen too short/long (%d)\n", lzlen); + return lzlen; +} + + + +/* Non-recursive version */ +/* NOTE! IMPORTANT! the "length" array length must be inlen+1 */ + +//============================================================================= +// +//============================================================================= +int OptimizeLength(int optimize) { + int i; + + length[inlen] = 0; /* one off the end, our 'target' */ + for (i=inlen-1; i>=0; i--) { + int r1 = 8 + length[i+1], r2, r3; + +/* if (i<=0x40b1 && !(i&((1<<0)-1))) + printf("");*/ + if (!lzlen[i] && !rle[i] && (!lzlen2 || !lzlen2[i])) { + length[i] = r1; + mode[i] = LITERAL; + continue; + } + + /* If rle>maxlzlen, skip to the start of the rle-maxlzlen.. */ + if (rle[i] > maxlzlen && elr[i] > 1) { + int z = elr[i]; + + i -= elr[i]; + + r2 = LenRle(rle[i], indata[i]) + length[i+ rle[i]]; + if (optimize) { + int ii, mini = rle[i], minv = r2; + + int bot = rle[i] - (1< =bot; ii--) { + int v = LenRle(ii, indata[i]) + length[i + ii]; + if (v < minv) { + minv = v; + mini = ii; + } + } + if (minv != r2) { + lzopt += r2 - minv; + rle[i] = mini; + r2 = minv; + } + } + length[i] = r2; + mode[i] = RLE; + + for (; z>=0; z--) { + length[i+z] = r2; + mode[i+z] = RLE; + } + continue; + } + r3 = r2 = r1 + 1000; /* r3 >= r2 > r1 */ + + if (rle[i]) { + r2 = LenRle(rle[i], indata[i]) + length[i+ rle[i]]; + + if (optimize) { + int ii, mini = rle[i], minv = r2; + + /* Check only the original length and all shorter + lengths that are power of two. + + Does not really miss many 'minimums' this way, + at least not globally.. + + Makes the assumption that the Elias Gamma Code is + used, i.e. values of the form 2^n are 'optimal' */ + ii = 2; + while (rle[i] > ii) { + int v = LenRle(ii, indata[i]) + length[i + ii]; + if (v < minv) { + minv = v; + mini = ii; + } + ii <<= 1; + } + if (minv != r2) { + lzopt += r2 - minv; + rle[i] = mini; + r2 = minv; + } + } + } + if (lzlen[i]) { + r3 = LenLz(lzlen[i], lzpos[i]) + length[i + lzlen[i]]; + + if (optimize && lzlen[i]>2) { + int ii, mini = lzlen[i], minv = r3; + int topLen = LenLz(lzlen[i], lzpos[i]) + - LenValue(lzlen[i]-1); + + /* Check only the original length and all shorter + lengths that are power of two. + + Does not really miss many 'minimums' this way, + at least not globally.. + + Makes the assumption that the Elias Gamma Code is + used, i.e. values of the form 2^n are 'optimal' */ + ii = 4; + while (lzlen[i] > ii) { + int v = topLen + LenValue(ii-1) + length[i + ii]; + if (v < minv) { + minv = v; + mini = ii; + } + ii <<= 1; + } + /* + Note: + 2-byte optimization checks are no longer done + with the rest, because the equation gives too long + code lengths for 2-byte matches if extraLzPosBits>0. + */ + /* Two-byte rescan/check */ + if (backSkip[i] && backSkip[i] <= 256) { +#ifdef EVEN_LZ + if (backSkip[i]&1) { + int j=backSkip[i]; + while (j && (j&1)) + j=backSkip[j]; + if (j && j<=256) { + int v = LenLz(2, j) + length[i + 2]; + + if (v < minv) { + minv = v; + mini = 2; + lzlen[i] = mini; + r3 = minv; + lzpos[i] = j; + } + } + } else { +#endif + /* There are previous occurrances (near enough) */ + int v = LenLz(2, (int)backSkip[i]) + length[i + 2]; + + if (v < minv) { + minv = v; + mini = 2; + lzlen[i] = mini; + r3 = minv; + lzpos[i] = (int)backSkip[i]; + } +#ifdef EVEN_LZ + } +#endif + } + if (minv != r3 && minv < r2) { + lzopt += r3 - minv; + lzlen[i] = mini; + r3 = minv; + } + } + } + + if (r2 <= r1) { + if (r2 <= r3) { + length[i] = r2; + mode[i] = RLE; + } + else { + length[i] = r3; + mode[i] = LZ77; + } + } + else { + if (r3 <= r1) { + length[i] = r3; + mode[i] = LZ77; + } + else { + length[i] = r1; + mode[i] = LITERAL; + } + } + if (lzlen2 && lzlen2[i] > 3) { + r3 = escBits + 2*maxGamma + 16 + LenValue(lzlen2[i]-1) + length[i + lzlen2[i]]; + //r3 = LenDLz(lzlen2[i], lzpos2[i]) + length[i + lzlen2[i]]; + if (r3 < length[i]) { + length[i] = r3; + mode[i] = DLZ; + } + } + } + return length[0]; +} + + +/* + The algorithm in the OptimizeEscape() works as follows: + 1) Only unpacked bytes are processed, they are marked + with MMARK. We proceed from the end to the beginning. + Variable A (old/new length) is updated. + 2) At each unpacked byte, one and only one possible + escape matches. A new escape code must be selected + for this case. The optimal selection is the one which + provides the shortest number of escapes to the end + of the file, + i.e. A[esc] = 1+min(A[0], A[1], .. A[states-1]). + For other states A[esc] = A[esc]; + If we change escape in this byte, the new escape is + the one with the smallest value in A. + 3) The starting escape is selected from the possibilities + and mode 0 is restored to all mode 3 locations. + + */ + +//============================================================================= +// +//============================================================================= +int OptimizeEscape(int *startEscape, int *nonNormal) { + int i, /*j,*/ states = (1< 256) { + fprintf(stderr, "Escape optimize: only 256 states (%d)!\n",states); + return 0; + } + + /* Mark those bytes that are actually outputted */ + for (i=0; i =0; i--) { + /* Using a table to skip non-normal bytes does not help.. */ + if (mode[i] == MMARK) { + int k = (indata[i] >> esc8); + + /* Change the tag values back to normal */ + mode[i] = LITERAL; + + /* + k are the matching bytes, + minv is the minimum value, + minp is the minimum index + */ + + newesc[i] = (minp << esc8); + a[k] = minv + 1; + b[k] = b[minp] + 1; + if (k==minp) { + /* Minimum changed -> need to find a new minimum */ + /* a[k] may still be the minimum */ + minv++; + for (k=states-1; k>=0; k--) { + if (a[k] < minv) { + minv = a[k]; + minp = k; + /* + There may be others, but the first one that + is smaller than the old minimum is equal to + any other new minimum. + */ + break; + } + } + } + } + } + + /* Select the best value for the initial escape */ + if (startEscape) { + i = inlen; /* make it big enough */ + for (j=states-1; j>=0; j--) { + if (a[j] <= i) { + *startEscape = (j << esc8); + i = a[j]; + } + } + } + if (nonNormal) + *nonNormal = other; + return b[startEscape ? (*startEscape>>esc8) : 0]; +#else + { + /* this fairly simple (but efficient) algo comes from GTPk */ + char esc_used[256]; + int esc_rem=states-1; + int lastesc=-1,escaped=0; + int k; + memset(esc_used,0,256); + for (i=0; i > esc8); + + mode[i] = LITERAL; + + if (!esc_used[k] && !esc_rem--) { + memset(esc_used,0,256); + esc_rem=states-1; + escaped++; + if (lastesc>=0) newesc[lastesc] = (k << esc8); + else if (startEscape) *startEscape = (k << esc8); + lastesc=i; + } else { + esc_used[k]=1; + } + } + } + for (k=0;;k++) { + if (!esc_used[k]) { + if (lastesc>=0) newesc[lastesc] = (k << esc8); + else if (startEscape) *startEscape = (k << esc8); + break; + } + } + newesc[0] = *startEscape; + if (nonNormal) + *nonNormal = other; + return escaped; + } +#endif +} + + +//============================================================================= +// Initialize the RLE byte code table according to all RLE's found so far O(n) +//============================================================================= +void InitRle(int flags) { + int p, mr, mv, i; + + for (i=1; i<32; i++) { + mr = -1; + mv = 0; + + for (p=0; p<256; p++) { + if (rleHist[p] > mv) { + mv = rleHist[p]; + mr = p; + } + } + if (mr>=0) { + rleValues[i] = mr; + rleHist[mr] = -1; + } else + break; + } + InitRleLen(); +} + + +//============================================================================= +// Initialize the RLE byte code table according to RLE's actually used O(n) +//============================================================================= +void OptimizeRle(int flags) { + int p, mr, mv, i; + + if ((flags & F_NORLE)) { + rleUsed = 0; + return; + } + if (flags & F_STATS) fprintf(stderr, "RLE Byte Code Re-Tune, RLE Ranks:\n"); + + for (p=0; p<256; p++) rleHist[p] = 0; + + for (p=0; p mv) { + mv = rleHist[p]; + mr = p; + } + } + if (mr>=0) { + rleValues[i] = mr; + if (flags & F_STATS) { + fprintf(stderr, " %2d.0x%02x %-3d ", i, mr, mv); + if (!((i - 1) % 6)) fprintf(stderr, "\n"); + } + rleHist[mr] = -1; + } + else { + break; + } + } + rleUsed = i-1; + if (rleUsed) + for (;i<32;i++) + rleValues[i]=rleValues[i-1]; + + if (flags & F_STATS) + if (((i - 1) % 6)!=1) fprintf(stderr, "\n"); + InitRleLen(); +} + + +int outlen; + +//============================================================================= +// +//============================================================================= +int PackLz77(int lzsz, int flags, int *startEscape,int endAddr, int memEnd, int type) +{ + int i, j, p, headerSize; + int escape; + unsigned char *hashValue; + unsigned char *a; + int k; + + unsigned short *lastPair; + + int rescan = 0; + +#ifndef NO_XVERBOSE + int vescape; +#endif + + + + if (lzsz < 0 || lzsz > lrange) { + fprintf(stderr, "LZ range must be from 0 to %d (was %d). Set to %d.\n", + lrange, lzsz, lrange); + lzsz = lrange; + } + if (lzsz > 65535) { + fprintf(stderr, + "LZ range must be from 0 to 65535 (was %d). Set to 65535.\n", + lzsz); + lzsz = 65535; + } + if (!lzsz) fprintf(stderr, "Warning: zero LZ range. Only RLE packing used.\n"); + + InitRleLen(); + length = (int *)calloc(sizeof(int), inlen + 1); + mode = (unsigned char *)calloc(sizeof(unsigned char), inlen); + rle = (unsigned short *)calloc(sizeof(unsigned short), inlen); + elr = (unsigned short *)calloc(sizeof(unsigned short), inlen); + lzlen = (unsigned short *)calloc(sizeof(unsigned short), inlen); + lzpos = (unsigned short *)calloc(sizeof(unsigned short), inlen); + if ((type & FIXF_DLZ)) { + lzlen2 = (unsigned short *)calloc(sizeof(unsigned short), inlen); + lzpos2 = (unsigned short *)calloc(sizeof(unsigned short), inlen); + } + else { + lzlen2 = lzpos2 = NULL; + } + newesc = (unsigned char *)calloc(sizeof(unsigned char), inlen); + backSkip = (unsigned short *)calloc(sizeof(unsigned short), inlen); + hashValue = (unsigned char *)malloc(inlen); + lastPair = (unsigned short *)calloc(sizeof(unsigned short), 256*256); + + /* error checking */ + if (!length || !mode || !rle || !elr || !lzlen || !lzpos || !newesc || + !lastPair || !backSkip + || ((type & FIXF_DLZ) && (!lzlen2 || !lzpos2)) + || !hashValue) + { + fprintf(stderr, "Memory allocation failed!\n"); + goto errorexit; + } + + i = 0; + j = 0; + a = indata + inlen; + for (p=inlen-1; p>=0; p--) { + k = j; + j = i; + i = *--a; /* Only one read per position */ + hashValue[p] = i*3 + j*5 + k*7; /* 7.95 % */ + } + + /* Detect all RLE and LZ77 jump possibilities */ + for (p=0; p =2) { + rleHist[indata[p]]++; + + for (i=rlelen-1; i>=0; i--) { + rle[p+i] = rlelen-i; + elr[p+i] = i; /* For RLE backward skipping */ + } + + } + } + + /* check LZ77 code */ + if (p+rle[p]+1 =0 && i>=bot) { + /* Got a 2-byte match at least */ + maxval = 2; + maxpos = p-i; + + /* + A..AB rlep # of A's, B is something else.. + + Search for bytes that are in p + (rlep-1), i.e. + the last rle byte ('A') and the non-matching one + ('B'). When found, check if the rle in the compare + position (i) is long enough (i.e. the same number + of A's at p and i-rlep+1). + + There are dramatically less matches for AB than for + AA, so we get a huge speedup with this approach. + We are still guaranteed to find the most recent + longest match there is. + */ + + i = (int)lastPair[(indata[p+(rlep-1)]<<8) | indata[p+rlep]] -1; + while (i>=bot /* && i>=rlep-1 */) { /* bot>=rlep-1, i>=bot ==> i>=rlep-1 */ + + /* Equal number of A's ? */ + if (!(rlep-1) || rle[i-(rlep-1)]==rlep) { /* 'head' matches */ + /* rlep==1 ==> (rlep-1)==0 */ + /* ivanova.run: 443517 rlep==1, + 709846 rle[i+1-rlep]==rlep */ + + /* + Check the hash values corresponding to the last + two bytes of the currently longest match and + the first new matching(?) byte. If the hash + values don't match, don't bother to check the + data itself. + */ + if ( + hashValue[i+maxval-rlep-1] == hashCompare + ) { + unsigned char *a = indata + i+2; /* match */ + unsigned char *b = indata + p+rlep-1+2;/* curpos */ + int topindex = inlen-(p+rlep-1); + + /* the 2 first bytes ARE the same.. */ + j = 2; + while (j < topindex && *a++==*b++) + j++; + + if (j + rlep-1 > maxval) { + int tmplen = j+rlep-1, tmppos = p-i+rlep-1; + + if (tmplen > maxlzlen) + tmplen = maxlzlen; + + /* Accept only versions that really are shorter */ + if (tmplen*8 - LenLz(tmplen, tmppos) > + maxval*8 - LenLz(maxval, maxpos)) { + maxval = tmplen; + maxpos = tmppos; + hashCompare = hashValue[p+maxval-2]; + } + if (maxval == maxlzlen) + break; + } + } + } + if (!backSkip[i]) + break; /* No previous occurrances (near enough) */ + i -= (int)backSkip[i]; + } + + /* + If there is 'A' in the previous position also, + RLE-like LZ77 is possible, although rarely + shorter than real RLE. + */ + if (p && rle[p-1] > maxval) { + maxval = rle[p-1] - 1; + maxpos = 1; + } + /* + Last, try to find as long as possible match + for the RLE part only. + */ + if (maxval < maxlzlen && rlep > maxval) { + bot = p - lzsz; + if (bot < 0) + bot = 0; + + /* Note: indata[p] == indata[p+1] */ + i = (int)lastPair[indata[p]*257] -1; + while (/* i>= rlep-2 &&*/ i>=bot) { + if (elr[i] + 2 > maxval) { + maxval = min(elr[i] + 2, rlep); + maxpos = p - i + (maxval-2); + if(maxval == rlep) + break; /* Got enough */ + } + i -= elr[i]; + if (!backSkip[i]) + break; /* No previous occurrances (near enough) */ + i -= (int)backSkip[i]; + } + } + if (p+maxval > inlen) { + fprintf(stderr,"Error @ %d, lzlen %d, pos %d - exceeds inlen\n",p, maxval, maxpos); + maxval = inlen - p; + } + if (maxpos<=256 || maxval > 2) { + if (maxpos < 0) fprintf(stderr, "Error @ %d, lzlen %d, pos %d\n",p, maxval, maxpos); + lzlen[p] = (maxval =0 && i>=bot) { + maxval = 2; + maxpos = p-i; + + /* + A..AB rlep # of A's, B is something else.. + + Search for bytes that are in p + (rlep-1), i.e. + the last rle byte ('A') and the non-matching one + ('B'). When found, check if the rle in the compare + position (i) is long enough (i.e. the same number + of A's at p and i-rlep+1). + + There are dramatically less matches for AB than for + AA, so we get a huge speedup with this approach. + We are still guaranteed to find the most recent + longest match there is. + */ + + i = (int)lastPair[(((indata[p+(rlep-1)] + rot) & 0xff)<<8) | + ((indata[p+rlep] + rot) & 0xff)] -1; + while (i>=bot /* && i>=rlep-1 */) { /* bot>=rlep-1, i>=bot ==> i>=rlep-1 */ + + /* Equal number of A's ? */ + if (!(rlep-1) || rle[i-(rlep-1)]==rlep) { /* 'head' matches */ + /* rlep==1 ==> (rlep-1)==0 */ + /* ivanova.run: 443517 rlep==1, + 709846 rle[i+1-rlep]==rlep */ + + /* + Check the hash values corresponding to the last + two bytes of the currently longest match and + the first new matching(?) byte. If the hash + values don't match, don't bother to check the + data itself. + */ + if (indata[i+maxval-rlep+1] == valueCompare) { + unsigned char *a = indata + i+2; /* match */ + unsigned char *b = indata + p+rlep-1+2;/* curpos */ + int topindex = inlen-(p+rlep-1); + + /* the 2 first bytes ARE the same.. */ + j = 2; + while (j < topindex && *a++==((*b++ + rot) & 0xff)) + j++; + + if (j + rlep-1 > maxval) { + int tmplen = j+rlep-1, tmppos = p-i+rlep-1; + + if (tmplen > maxlzlen) + tmplen = maxlzlen; + + /* Accept only versions that really are shorter */ + if (tmplen*8 - LenLz(tmplen, tmppos) > + maxval*8 - LenLz(maxval, maxpos)) { + maxval = tmplen; + maxpos = tmppos; + + valueCompare = (indata[p+maxval] + rot) & 0xff; + } + if (maxval == maxlzlen) + break; + } + } + } + if (!backSkip[i]) + break; /* No previous occurrances (near enough) */ + i -= (int)backSkip[i]; + } + + if (p+maxval > inlen) { + fprintf(stderr,"Error @ %d, lzlen %d, pos %d - exceeds inlen\n",p, maxval, maxpos); + maxval = inlen - p; + } + if (maxval > 3 && maxpos <= 256 && + (maxval > lzlen2[p] || + (maxval == lzlen2[p] && maxpos < lzpos2[p]))) { + if (maxpos < 0) + fprintf(stderr, "Error @ %d, lzlen %d, pos %d\n",p, maxval, maxpos); + lzlen2[p] = (maxval p || ptr > 0xffff) + ptr = 0; + + backSkip[p] = ptr; + lastPair[index] = p+1; + } + } + if ((flags & F_NORLE)) { + for (p=1; p lzlen[p]) { + lzlen[p] = (rle[p] >escBits) & 0xff; + + /* Find the optimum path for selected escape bits (no optimize) */ + OptimizeLength(0); + + /* Optimize the escape selections for this path & escBits */ + escaped = OptimizeEscape(&escape, &other); + + /* Compare value: bits lost for escaping -- bits lost for prefix */ + c = (escBits+3)*escaped + other*escBits; + if (flags & F_STATS) { + fprintf(stderr, " %d:%d", escBits, c); + fflush(stderr); /* for SAS/C */ + } + if (c < mv) { + mb = escBits; + mv = c; + } else { + /* minimum found */ + break; + } + if (escBits==4 && (flags & F_STATS)) fprintf(stderr, "\n"); + } + if (mb==1) { /* Minimum was 1, check 0 */ + int escaped; + + escBits = 0; + escMask = 0; + + /* Find the optimum path for selected escape bits (no optimize) */ + OptimizeLength(0); + /* Optimize the escape selections for this path & escBits */ + escaped = OptimizeEscape(&escape, NULL); + + if ((flags & F_STATS)) { + fprintf(stderr, " %d:%d", escBits, 3*escaped); + fflush(stderr); /* for SAS/C */ + } + if (3*escaped < mv) { + mb = 0; + /* mv = 3*escaped; */ + } + } + if ((flags & F_STATS)) fprintf(stderr, "\n"); + + if (flags & F_VERBOSE) fprintf(stderr, "Selected %d-bit escapes\n", mb); + escBits = mb; + escMask = (0xff00>>escBits) & 0xff; + } + + + if (!(flags & F_NOOPT)) { + if (flags & F_VERBOSE) { + fprintf(stderr, "Optimizing LZ77 and RLE lengths..."); + fflush(stderr); + } + } + + /* Find the optimum path (optimize) */ + OptimizeLength((flags & F_NOOPT)?0:1); + if (flags & F_STATS) { + if (!(flags & F_NOOPT)) fprintf(stderr, " gained %d units.\n", lzopt/8); + } + else { + //fprintf(stderr, "\n"); + } + + if (1 || (flags & F_AUTOEX)) { + long lzstat[5] = {0,0,0,0,0}, i, cur = 0, old = extraLZPosBits; + + if (flags & F_VERBOSE) { + fprintf(stderr, "Selecting LZPOS LO length.. "); + fflush(stderr); + } + + for (p=0; p > 8)+1 > (1< (1< (1<<(maxGamma-1))) { + if (rle[p] <= (1< 10) { + if (flags & F_VERBOSE) fprintf(stderr,"Note: Using option -m%d you may get better results.\n",maxGamma+1); + } + if (maxGamma > 5 && stat[0] + stat[1] + stat[3] < 4) { + if (flags & F_VERBOSE) fprintf(stderr,"Note: Using option -m%d you may get better results.\n",maxGamma-1); + } + } + + /* Optimize the escape selections */ + OptimizeEscape(&escape, NULL); + if (startEscape) *startEscape = escape; + OptimizeRle(flags); /* Retune the RLE selections */ + +#ifdef NO_XVERBOSE + if (flags & F_VERBOSE) { + int oldEscape = escape; + if (flags & F_VERBOSE) printf("normal RLE LZLEN LZPOS(absolute)\n\n"); + + for (p=0; p "); + j += lzlen2[p]; + } else + printf(" "); + if (lzpos2) { + if (flags & F_VERBOSE) printf(" %04x*%03d*+%02x", lzpos2[p], lzlen2[p],(indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + if (flags & F_VERBOSE) printf(" 001 %03d %03d %04x(%04x) %02x %s\n", + rle[p],lzlen[p],lzpos[p],p-lzpos[p],indata[p], + (mode[p] & MMARK)?"#":" "); + break; + case MMARK | LITERAL: + case LITERAL: + if (flags & F_VERBOSE) { + if (j==p) printf(">"); + else printf(" "); + + if (lzpos2) { + printf(" %04x %03d +%02x", lzpos2[p], lzlen2[p], + (indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + } + if (j==p) { + if (flags & F_VERBOSE) { + printf("*001* %03d %03d %04x(%04x) %02x %s %02x", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" ", newesc[p]); + } + if ((indata[p] & escMask) == escape) { + escape = newesc[p]; + if (flags & F_VERBOSE) printf(""); + } + if (flags & F_VERBOSE) printf("\n"); + j += 1; + } else { + if (flags & F_VERBOSE) printf("*001* %03d %03d %04x(%04x) %02x %s %02x\n", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" ", newesc[p]); + } + break; + case MMARK | LZ77: + case LZ77: + if (j==p) { + if (flags & F_VERBOSE) printf(">"); + j += lzlen[p]; + } else + if (flags & F_VERBOSE) printf(" "); + if (lzpos2) { + if (flags & F_VERBOSE) printf(" %04x %03d +%02x", lzpos2[p], lzlen2[p], + (indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + if (flags & F_VERBOSE) printf(" 001 %03d *%03d* %04x(%04x) %02x %s\n", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" "); + break; + case MMARK | RLE: + case RLE: + if (j==p) { + if (flags & F_VERBOSE) printf(">"); + j += rle[p]; + } else + if (flags & F_VERBOSE) printf(" "); + if (lzpos2) { + if (flags & F_VERBOSE) printf(" %04x %03d +%02x", lzpos2[p], lzlen2[p], + (indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + if (flags & F_VERBOSE) printf(" 001 *%03d* %03d %04x(%04x) %02x %s\n", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" "); + break; + default: + j++; + break; + } + mode[p] &= ~MMARK; + } + escape = oldEscape; + } +#endif + +#ifndef NO_XVERBOSE + if (flags & F_VERBOSE) { + for (p=0; p "); + j += lzlen2[p]; + } else + printf(" "); + if (lzpos2) { + if (flags & F_VERBOSE) printf(" %04x*%03d*+%02x", lzpos2[p], lzlen2[p],(indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + if (flags & F_VERBOSE) printf(" 001 %03d %03d %04x(%04x) %02x %s\n", + rle[p],lzlen[p],lzpos[p],p-lzpos[p],indata[p], + (mode[p] & MMARK)?"#":" "); + break; + case MMARK | LITERAL: + case LITERAL: + if (flags & F_VERBOSE) { + if (j==p) printf(">"); + else printf(" "); + + if (lzpos2) { + printf(" %04x %03d +%02x", lzpos2[p], lzlen2[p], + (indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + } + if (j==p) { + if (flags & F_VERBOSE) { + printf("*001* %03d %03d %04x(%04x) %02x %s %02x", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" ", newesc[p]); + } + if ((indata[p] & escMask) == vescape) { + vescape = newesc[p]; + if (flags & F_VERBOSE) printf(""); + } + if (flags & F_VERBOSE) printf("\n"); + j += 1; + } else { + if (flags & F_VERBOSE) printf("*001* %03d %03d %04x(%04x) %02x %s %02x\n", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" ", newesc[p]); + } + break; + case MMARK | LZ77: + case LZ77: + if (j==p) { + if (flags & F_VERBOSE) printf(">"); + j += lzlen[p]; + } else + if (flags & F_VERBOSE) printf(" "); + if (lzpos2) { + if (flags & F_VERBOSE) printf(" %04x %03d +%02x", lzpos2[p], lzlen2[p], + (indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + if (flags & F_VERBOSE) printf(" 001 %03d *%03d* %04x(%04x) %02x %s\n", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" "); + break; + case MMARK | RLE: + case RLE: + if (j==p) { + if (flags & F_VERBOSE) printf(">"); + j += rle[p]; + } else + if (flags & F_VERBOSE) printf(" "); + if (lzpos2) { + if (flags & F_VERBOSE) printf(" %04x %03d +%02x", lzpos2[p], lzlen2[p], + (indata[p] - indata[p-lzpos2[p]]) & 0xff); + } + if (flags & F_VERBOSE) printf(" 001 *%03d* %03d %04x(%04x) %02x %s\n", + rle[p], lzlen[p], lzpos[p], p-lzpos[p], indata[p], + (mode[p] & MMARK)?"#":" "); + break; + default: + j++; + break; + } + mode[p] &= ~MMARK; + } +#endif + switch (mode[p]) { + case LITERAL: /* normal */ + length[p] = outPointer; + + OutputNormal(&escape, indata+p, newesc[p]); + p++; + break; + + case DLZ: + for (i=0; i >(8-escBits)), escBits); + PutValue(lzlen2[p]-1); + PutValue((2< 2 && lzlen[p] > rle[p]) { + int bot = p - lzpos[p] + 1, i; + unsigned short rlep = rle[p]; + + if (!rlep) + rlep = 1; + if (bot < 0) + bot = 0; + bot += (rlep-1); + + i = p - (int)backSkip[p]; + while (i>=bot /* && i>=rlep-1 */) { + /* Equal number of A's ? */ + if (rlep==1 || rle[i-rlep+1]==rlep) { /* 'head' matches */ + unsigned char *a = indata + i+1; /* match */ + unsigned char *b = indata + p+rlep-1+1; /* curpos */ + int topindex = inlen-(p+rlep-1); + + j = 1; + while (j < topindex && *a++==*b++) + j++; + + if (j + rlep-1 >= lzlen[p]) { + int tmppos = p-i+rlep-1; +#ifdef EVEN_LZ + if (!(tmppos&1)) { +#endif + + rescan += + LenLz(lzlen[p], lzpos[p]) - + LenLz(lzlen[p], tmppos); +#ifdef EVEN_LZ + if (tmppos&1) + fprintf(stderr,"Error: misalign in tmppos\n"); +#endif + lzpos[p] = tmppos; + break; +#ifdef EVEN_LZ + } +#endif + } + } + if (!backSkip[i]) + break; /* No previous occurrances (near enough) */ + i -= (int)backSkip[i]; + } + } + + for (i=0; i = 'a' && c <= 'f') return c - 'a' + 10; + if (c >= '0' && c <= '9') return c - '0'; + return NO_HEX_CHARACTER; +} + + +//============================================================================= +// converts hex text into binary +//============================================================================= +int ConvertText2Bin(unsigned char* ib,int origlen) { + int pos; + int cnt = 0; + int searchforendofline = 0; + int len_after_convert = 0; + unsigned char val = 0; + unsigned char actual; + + len_after_convert = 0; + for (pos = 0; pos < origlen;pos++) { + if (searchforendofline) { + if (ib[pos] == '\n') searchforendofline = 0; + continue; + } + if (ib[pos] == '/') { + cnt = 0; + if (pos < origlen-1 && ib[pos+1] == '/') searchforendofline = 1; + continue; + } + + actual = hex2int(ib[pos]); + if (actual == NO_HEX_CHARACTER) { + cnt = 0; + continue; + } + if (cnt == 0) { + val = actual*16; + cnt++; + } + else { + val += actual; + cnt=0; + ib[len_after_convert++] = val; + } + } + return(len_after_convert); +} + +void *GTPackDo(void *buf,unsigned short *buflen) { + int startEscape; + char *ptr; + +// unsigned long timeused = clock(); + + lrange = LRANGE; + maxlzlen = MAXLZLEN; + maxrlelen = MAXRLELEN; + + InitValueLen(); + + indata = buf; + inlen = *buflen; + PackLz77(lrange, F_AUTO|F_AUTOEX, &startEscape, 1234, 12345, 0); + free(indata); + { + int i; + PackedHeader cth; + RLEEntries re; + + cth.origsize_lo = inlen & 0xff; + cth.origsize_hi = (inlen >> 8); + memcpy(cth.magic,"GTPk",4); + cth.compsize_lo = (outlen + rleUsed + sizeof(PackedHeader)) & 0xff; + cth.compsize_hi = (outlen + rleUsed + sizeof(PackedHeader)) >> 8; + cth.esc1 = (startEscape >> (8-escBits)); + cth.esc2 = escBits; + cth.extralz = extraLZPosBits; + cth.rleentries = rleUsed; + + for(i=0; i > (8-escBits) +// unsigned char notused3; +// unsigned char notused4; + unsigned char esc2; // escBits + unsigned char gamma1; // maxGamma + 1 + unsigned char gamma2; // (1< > (8-escBits) + unsigned char extralz; // extraLZPosBits + unsigned char rleentries; // rleUsed +} PackedHeader; +#endif + + +#define GetUnPackedSize(p) (unsigned int)((p)->origsize_lo | ((p)->origsize_hi << 8)) +#define IsPacked(p) ((p)->magic1 == MAGIC_CHAR1 && (p)->magic2 == MAGIC_CHAR2) + + +typedef struct { + unsigned char value[MAX_RLE_ENTRIES]; +} RLEEntries; + + +#endif + + +//############################################################################# +//###################### NO MORE FAKES BEYOND THIS LINE ####################### +//############################################################################# +// +//============================================================================= +// Revision History +//============================================================================= +// +// $Log: packhead.h,v $ +// Revision 1.4 2005/08/04 21:27:43 Paul Froissart +// adapted for XPak +// +// Revision 1.3 2000/08/20 15:24:28 Thomas Nussbaumer +// macros to get unpacked size and to check if packed added +// +// Revision 1.2 2000/08/16 23:08:55 Thomas Nussbaumer +// magic characters changed to TP ... t(igcc tools) p(acked file) +// +// Revision 1.1 2000/08/14 22:49:57 Thomas Nussbaumer +// initial version +// +// diff --git a/gtc/src/gtpack/revtools.h b/gtc/src/gtpack/revtools.h new file mode 100644 index 0000000..e0b5dea --- /dev/null +++ b/gtc/src/gtpack/revtools.h @@ -0,0 +1,108 @@ +/****************************************************************************** +* +* project name: TIGCC Tools Suite +* file name: revtools.h +* initial date: 23/08/2000 +* author: thomas.nussbaumer@gmx.net +* description: macros for automatic handling of version number output +* which is in sync with the CVS version number +* +* examine one of the pctools source codes to see how it works ;-) +* +* [NO CVS ID HERE BY INTENTION] +* +******************************************************************************/ + +//----------------------------------------------------------------------------- +// [Usage] +// +// (1) include this file into your tool +// +// +// (2) AFTER (!!) all includes put the following lines into your source code: +// +// #ifdef CVS_FILE_REVISION +// #undef CVS_FILE_REVISION +// #endif +// ---------------------------------------------------------------------------- +// DON'T EDIT THE NEXT REVISION BY HAND! THIS IS DONE AUTOMATICALLY BY THE +// CVS SYSTEM !!! +// ---------------------------------------------------------------------------- +// #define CVS_FILE_REVISION "$Revision$" +// +// It must be placed AFTER (!!) all includes otherwise the macros may be +// expanded wrong where you use them. For example: if you have added the above +// lines at the top of your file and include afterwards a file which does +// the same, the version of the included file will be used further due to the +// #undef CVS_FILE_REVISION. Everything clear? +// +// +// (3) to output the cvs revision number you can now to a simple: +// +// printf(CVSREV_PRINTPARAMS) +// +// if your file has, for example, the revision 1.3 the following string will +// be printed: v1.03 +// +// the prefix before the subversion is used to get equal-sized output strings +// for mainversions between 1 ... 9 and subversion between 1 .. 99 +// +// if your program leaves that range and you need to have equal-sized output +// strings you have to implement it by your own by using the +// CVSREV_MAIN and CVSREV_SUB macros which returns the main and sub versions +// as plain integers. if there is something wrong with your revision string +// CVSREV_MAIN and/or CVSREV_SUB will deliver 0, which is no valid CVS main +// or subversion number. +// +// i will suggest that you use the CVS system. its simple to handle, keeps +// track of your revisions and their history and with the smart macros below +// you haven't to worry anymore about the version output strings of your +// program. if you want a special version number you can force CVS at every +// time to give this version number to your program (0 is not allowed as +// main and subversion number - thats the only pity) +// +// within this tools suite every tool will use the automatic version handling +// but the tool suite version number itself will be handled "by hand". +// this number shouldn't change that quickly as with the tools. +// +//----------------------------------------------------------------------------- +#ifndef __REV_TOOLS_H__ +#define __REV_TOOLS_H__ +#include +#include +#include + +//----------------------------------------------------------------------------- +// just used internally +//----------------------------------------------------------------------------- +#define CVS_TRUNC_PREFIX ((strlen((CVS_FILE_REVISION))<=11) ? 0 : (CVS_FILE_REVISION+11)) +#define CVS_FIND_COMMA (strchr(CVS_TRUNC_PREFIX,'.')) +#define CVSREV_MAIN (int)(!(CVS_TRUNC_PREFIX) ? 0 : atoi(CVS_TRUNC_PREFIX)) +#define CVSREV_SUB (int)(!(CVS_TRUNC_PREFIX) ? 0 : (!(CVS_FIND_COMMA) ? 0 : atoi(CVS_FIND_COMMA+1))) + +//----------------------------------------------------------------------------- +// NOTE: THE FOLLOWING MACRO WILL ONLY HANDLE MAIN VERSION < 10 AT CONSTANT +// LENGTH !!! +// (subversions from 1 .. 99 are mapped to 01 .. 99) +// +// the following macro may be used to setup a printf(),sprintf() or fprintf() +// call +//----------------------------------------------------------------------------- +#define CVSREV_PRINTPARAMS "v%d.%02d",CVSREV_MAIN,CVSREV_SUB + + +#define PRINT_ID(name) fprintf(stderr,"\n");fprintf(stderr, name" ");\ + fprintf(stderr,CVSREV_PRINTPARAMS);\ + fprintf(stderr," - TIGCC Tools Suite v"TTV_MAIN TTV_SUB"\n" \ + "(c) thomas.nussbaumer@gmx.net " TTV_DATE"\n\n"); + + + + + + +#endif + +//############################################################################# +//###################### NO MORE FAKES BEYOND THIS LINE ####################### +//############################################################################# diff --git a/gtc/src/gtpack/tt.h b/gtc/src/gtpack/tt.h new file mode 100644 index 0000000..c29a180 --- /dev/null +++ b/gtc/src/gtpack/tt.h @@ -0,0 +1,48 @@ +/****************************************************************************** +* +* project name: TIGCC Tools Suite +* file name: tt.h +* initial date: 13/08/2000 +* author: thomas.nussbaumer@gmx.net +* description: generic definitions for TIGCC Tools Suite +* +* $Id: tt.h,v 1.3 2000/08/23 20:29:43 Thomas Nussbaumer Exp $ +* +******************************************************************************/ + +#ifndef __TT_H__ +#define __TT_H__ + +#define CALC_TI89 0 +#define CALC_TI92P 1 + +#define SIGNATURE_TI89 "**TI89**" +#define SIGNATURE_TI92P "**TI92P*" + +#define DEFAULT_FOLDER "main" + +#define DEFAULT_ITEMS_PER_LINE 10 + +#endif + +//############################################################################# +//###################### NO MORE FAKES BEYOND THIS LINE ####################### +//############################################################################# +// +//============================================================================= +// Revision History +//============================================================================= +// +// $Log: tt.h,v $ +// Revision 1.3 2000/08/23 20:29:43 Thomas Nussbaumer +// added a 'P' to the TI92p definitions +// +// Revision 1.2 2000/08/23 01:04:41 Thomas Nussbaumer +// corrected signature of TI92p +// +// Revision 1.1 2000/08/13 20:24:16 Thomas Nussbaumer +// initial version +// +// +// +// diff --git a/gtc/src/gtpack/ttunpack.h b/gtc/src/gtpack/ttunpack.h new file mode 100644 index 0000000..5dcc0bd --- /dev/null +++ b/gtc/src/gtpack/ttunpack.h @@ -0,0 +1,49 @@ +/****************************************************************************** +* +* project name: TIGCC Tools Suite +* file name: ttunpack.h +* initial date: 14/08/2000 +* author: thomas.nussbaumer@gmx.net +* description: defines of errorcodes of decompression routine and its +* declaration +* $Id: ttunpack.h,v 1.2 2000/08/20 15:26:21 Thomas Nussbaumer Exp $ +* +******************************************************************************/ + +#ifndef __TTUNPACK_H__ +#define __TTUNPACK_H__ + +#define K_GAMMA 1 +#define M_GAMMA 0 + +#define ERRPCK_OKAY 0 +#define ERRPCK_NOESCFOUND 248 +#define ERRPCK_ESCBITS 249 +#define ERRPCK_MAXGAMMA 250 +#define ERRPCK_EXTRALZP 251 +#define ERRPCK_NOMAGIC 252 +#define ERRPCK_OUTBUFOVERRUN 253 +#define ERRPCK_LZPOSUNDERRUN 254 + +int _tt_Decompress(unsigned char *src, unsigned char *dest); +#define UnPack _tt_Decompress + +#endif + + +//############################################################################# +//###################### NO MORE FAKES BEYOND THIS LINE ####################### +//############################################################################# +// +//============================================================================= +// Revision History +//============================================================================= +// +// $Log: ttunpack.h,v $ +// Revision 1.2 2000/08/20 15:26:21 Thomas Nussbaumer +// prefix of unpack routine (_tt_) corrected +// +// Revision 1.1 2000/08/14 22:49:57 Thomas Nussbaumer +// initial version +// +// diff --git a/gtc/src/gtpack/ttversion.h b/gtc/src/gtpack/ttversion.h new file mode 100644 index 0000000..404feba --- /dev/null +++ b/gtc/src/gtpack/ttversion.h @@ -0,0 +1,53 @@ +/****************************************************************************** +* +* project name: TIGCC Tools Suite +* file name: ttversion.h +* initial date: 13/08/2000 +* author: thomas.nussbaumer@gmx.net +* description: TIGCC Tools Suite version definitions +* +* $Id: ttversion.h,v 1.7 2000/10/01 14:59:22 Thomas Nussbaumer Exp $ +* +******************************************************************************/ + +#ifndef __TTVERSION_H__ +#define __TTVERSION_H__ + +#define TTV_MAIN "0.95" +#define TTV_SUB "" +#define TTV_DATE "01/10/2000" + +#endif + +//############################################################################# +//###################### NO MORE FAKES BEYOND THIS LINE ####################### +//############################################################################# +// +//============================================================================= +// Revision History +//============================================================================= +// +// $Log: ttversion.h,v $ +// Revision 1.7 2000/10/01 14:59:22 Thomas Nussbaumer +// generic commit +// +// Revision 1.6 2000/08/27 23:52:39 Thomas Nussbaumer +// forcing version to 0.41 +// +// Revision 1.5 2000/08/23 20:31:37 Thomas Nussbaumer +// next version step +// +// Revision 1.4 2000/08/23 01:05:59 Thomas Nussbaumer +// next version step +// +// Revision 1.3 2000/08/16 23:09:15 Thomas Nussbaumer +// version actualized to 0.15 +// +// Revision 1.2 2000/08/13 20:26:12 Thomas Nussbaumer +// version now 0.10 (preview release) +// +// Revision 1.1 2000/08/13 16:02:13 Thomas Nussbaumer +// initial version +// +// +// diff --git a/gtc/src/identity.h b/gtc/src/identity.h new file mode 100644 index 0000000..acf588a --- /dev/null +++ b/gtc/src/identity.h @@ -0,0 +1,22 @@ +/* + * GTools C compiler + * ================= + * source file : + * (on-calc) volatilizing a value + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#ifndef __IDENTITY +#define __IDENTITY +void *identity(void *x) { + return x; +} +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/init.c b/gtc/src/init.c new file mode 100644 index 0000000..bc8d03d --- /dev/null +++ b/gtc/src/init.c @@ -0,0 +1,434 @@ +/* + * GTools C compiler + * ================= + * source file : + * initialisations + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#define USE_MEMMGT +#include "cglbdec.h" + +long inittype(TYP *,TYP **); +static long initstruct(TYP *,TYP **), initarray(TYP *,TYP **), initunion(TYP *,TYP **); +static int initchar(), initshort(), initlong(), initpointer(); +#ifndef NOFLOAT +static int initfloat(); +#ifdef DOUBLE +static int initdouble(); +#endif +#endif +static struct enode *constexpr(); +extern TYP *copy_type(TYP *s); + +TYP *copy_type_global(TYP *tp) { + TYP *tp2; + temp_local++; + global_flag++; + tp2=copy_type(tp); + global_flag--; + temp_local--; + return tp2; +} + +void doinit(struct sym *sp, int align) { + nl(); + if (lastst != assign) + genstorage(sp, align); + else { + struct slit *strtab_old=strtab; + int glob = global_flag; + int no_locblk = !locblk; +/* if (lineid>=0x100) + bkpt();*/ + strtab = 0; + global_flag = 0; + tmp_use(); + temp_local++; + global_strings++; + dseg(); /* select data segment */ + put_align(align); +#ifndef AS + if (sp->storage_class == sc_static) + put_label((unsigned int) sp->value.i); + else + g_strlab(sp->name); +#else +#ifdef PC +#define gnu_hook(x,y) ((x)?(x):(y)) +#else +#define gnu_hook(x,y) ((x)?:(y)) +#endif + if (sp->storage_class == sc_static) { + extern int glblabel; + put_label(gnu_hook(sp->value.splab,sp->value.splab=nxtglabel())); + } else + put_label(splbl(sp)); +#endif + getsym(); + (void) inittype(sp->tp,&sp->tp); +/* if (strtab) + bkpt();*/ + if (strtab) + dumplits(); + global_strings--; + temp_local--; + tmp_free(); /* just in case, but shouldn't get used because of temp_local */ + if (no_locblk && locblk) + rel_local(); + global_flag = glob; + strtab = strtab_old; + } +} + +long inittype(TYP *tp,TYP **tpp) { + int brace_seen = 0; + long nbytes; + if (lastst == begin) { + brace_seen = 1; + getsym(); + } + switch (tp->type) { + case bt_char: + case bt_uchar: + nbytes = initchar(); + break; + case bt_short: + case bt_ushort: + nbytes = initshort(); + break; + case bt_pointer: + if (tp->val_flag) + nbytes = initarray(tp,tpp); + else { + nbytes = initpointer(); + } + break; + case bt_ulong: + case bt_long: + nbytes = initlong(); + break; +#ifndef NOFLOAT + case bt_float: + nbytes = initfloat(); + break; +#ifdef DOUBLE + case bt_double: + nbytes = initdouble(); + break; +#endif +#endif + case bt_struct: + nbytes = initstruct(tp,tpp); + break; + case bt_union: + nbytes = initunion(tp,tpp); + break; + default: + error(ERR_NOINIT); + nbytes = 0; + } + if (brace_seen) + needpunc(end); + return nbytes; +} + +/*void modf_btp(TYP *new_btp,TYP *tp) { + tp=copy_type(tp); + tp->btp=new_btp; + modf(tp,modfp); +}*/ + +extern unsigned int pos; +static long initarray(TYP *tp,TYP **tpp) { + long nbytes; + char *p; + int len; +#ifdef AS + unsigned int max_pos=pos; +#endif +// tmp_use(); + nbytes = 0; + if (lastst == sconst && (tp->btp->type == bt_char || + tp->btp->type == bt_uchar)) { + len = lstrlen; + nbytes = len; + p = laststr; + while (len--) + genbyte(*p++); + if (!tp->size) /* if tp->size!=0, then the padding stuff takes care of it */ + genbyte(0), nbytes++; + while (nbytes < tp->size) + genbyte(0), nbytes++; + getsym(); /* skip sconst */ + } else if (lastst == kw_incbin) { + FILE *fp; int size; +#ifndef PC + unsigned char type; +#endif +/* getsym(); + if (lastst!=sconst) + error(ERR_SYNTAX);*/ + skipspace(); + if (lastch!='"') + error(ERR_SYNTAX); + getch(); + getidstr(); + if (lastch!='"') + error(ERR_SYNTAX); + getch(); + getsym(); + fp=fopen(lastid,"rb"); + if (!fp) + uerr(ERR_CANTOPEN,lastid); +#ifdef PC + p=malloc(100000); + size=fread(p,1,100000,fp); +#else + p=*(char **)fp; + size=*(unsigned short *)p; + type=p[size+1]; + if (type==0xF3 || type==0xE0) size--; + else if (type==0xF8) { size--; do size--; while (p[size+1]); } +#endif + if (tp->size && size>tp->size) size=tp->size; + nbytes=size; + while (size--) genbyte(*p++); + while (nbytes size) { + genbyte(0); + nbytes++; + } + } else if (lastst == end) + goto pad; + else { + int i,additional,size; + for (i=0;;) { + additional=0; + if (lastst == openbr) { + getsym(); { + int j=intexpr(); + long diff=tp->btp->size*(j-i); + if (lastst == dots) { + getsym(); + additional=intexpr()-j; + } + if (lastst != closebr) error(ERR_SYNTAX); + else { + getsym(); + if (lastst == assign) getsym(); + if (i =0) { + nbytes += (size=inittype(tp->btp,NULL)); i++; +#ifdef AS + while (additional--) rewrite(size), nbytes+=size, i++; +#endif + } + #ifdef AS + if (pos>max_pos) max_pos=pos; + #endif + if (lastst == comma) + getsym(); + if (lastst == end || lastst == semicolon) { + pad: + #ifdef AS + if (pos size) { + genbyte(0); + nbytes++; + } + break; + } + if (tp->size > 0 && nbytes >= tp->size) + break; + } + } +#if 0 + if (tp->size == 0) + tp->size = nbytes; + if (nbytes > tp->size) + error(ERR_INITSIZE); +#else + if (tp->size && nbytes > tp->size) + error(ERR_INITSIZE); + if (tp->size != nbytes && tpp) + /* fix the symbol's size, unless tpp=0 (item of a struct/union or array) */ + tp = copy_type_global(tp), + *tpp = tp, + tp->size = nbytes; // we need this for the 'sizeof' operator... +#endif +// tmp_free(); + return nbytes; +} + +static long initunion(TYP *tp,TYP **tpp) { + struct sym *sp; + long nbytes; + + int brace_seen = 0; + if (lastst == begin) { + brace_seen = 1; + getsym(); + } + + sp = tp->lst.head; +/* + * Initialize the first branch + */ + if (sp == 0) + return 0; + nbytes = inittype(sp->tp,NULL); + while (nbytes < tp->size) { + genbyte(0); + nbytes++; + } + + if (tp->size != nbytes && tpp) + tp = copy_type_global(tp), + *tpp = tp, + tp->size = nbytes; // we need this for the 'sizeof' operator... + + if (brace_seen) + needpunc(end); +} + +static long initstruct(TYP *tp,TYP **tpp) { + struct sym *sp; + long nbytes; + nbytes = 0; + sp = tp->lst.head; /* start at top of symbol table */ + if (lastst != end) + while (sp != 0) { + while (nbytes < sp->value.i) { /* align properly */ + nbytes++; + genbyte(0); + } + nbytes += inittype(sp->tp,NULL); + if (lastst == comma) + getsym(); + if (lastst == end || lastst == semicolon) + break; + sp = sp->next; + } + while (nbytes < tp->size) { + genbyte(0); + nbytes++; + } + if (tp->size != nbytes && tpp) + tp = copy_type_global(tp), + *tpp = tp, + tp->size = nbytes; // we need this for the 'sizeof' operator... + + return tp->size; +} + +static int initchar() { + genbyte((int) intexpr()); + return 1; +} + +static int initshort() { + genword((int) intexpr()); + return 2; +} + +static int initlong() { +/* + * We allow longs to be initialized with pointers now. + * Thus, we call constexpr() instead of intexpr. + */ +#if 0 +/* + * This is more strict + */ + genlong(intexpr()); + return 4; +#endif + genptr(constexpr()); + return 4; +} + +#ifndef NOFLOAT +static int initfloat() { +#ifndef NOFLOAT + double floatexpr(); +#ifdef PC + genfloat(floatexpr()); +#else +#ifndef BCDFLT + genptr(floatexpr()); +#else + genfloat(floatexpr()); +#endif +#endif +#endif +#ifdef NOFLOAT + genptr(0l); +#endif + return 4; +} + +#ifdef DOUBLE +static int initdouble() { +#ifdef NOFLOAT + int i; + for (i=0; i< tp_double.size; i++) + genbyte(0); +#endif +#ifndef NOFLOAT + double floatexpr(); + gendouble(floatexpr()); +#endif + return tp_double.size; +} +#endif +#endif + +static int initpointer() { + genptr(constexpr()); + return 4; +} + +static struct enode *constexpr() { + struct enode *ep; + struct typ *tp; +/* if (lineid==0x1e0) + bkpt();*/ + tp=exprnc(&ep); + if (tp == 0) { + error(ERR_EXPREXPECT); + return 0; + } + opt0(&ep); + if (!tst_const(ep)) { + error(ERR_CONSTEXPECT); + return 0; + } + return ep; +} +// vim:ts=4:sw=4 diff --git a/gtc/src/intexpr.c b/gtc/src/intexpr.c new file mode 100644 index 0000000..a29da9a --- /dev/null +++ b/gtc/src/intexpr.c @@ -0,0 +1,96 @@ +/* + * GTools C compiler + * ================= + * source file : + * integer expression routines + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" +#ifndef NOFLOAT +#include "ffplib.h" +#endif + +#ifndef NOFLOAT +double floatexpr() { +/* floating point expression */ + struct enode *ep; + struct typ *tp; + + tp = exprnc(&ep); + if (tp == 0) { + error(ERR_FPCON); + return (double) 0; + } + + opt0(&ep); + + if (ep->nodetype == en_icon) +#ifdef PC + return (double) ep->v.i; +#else + return ffpltof(ep->v.i); +#endif + + if (ep->nodetype == en_fcon) + return ep->v.f; + + error (ERR_SYNTAX); + return (double) 0; +} +#endif /* !NOFLOAT */ + +long intexpr() { + struct enode *ep; + struct typ *tp; + long val; + + tmp_use(); + tp = exprnc(&ep); + if (tp == 0) { + error(ERR_INTEXPR); + return 0; + } + opt0(&ep); + + if (ep->nodetype != en_icon) { + error(ERR_SYNTAX); + return 0; + } + val=ep->v.i; + tmp_free(); + return val; +} + +#if 0 +long intexpr_notemp() { + struct enode *ep; + struct typ *tp; + + tp = exprnc(&ep); + if (tp == 0) { + error(ERR_INTEXPR); + return 0; + } + opt0(&ep); + + if (ep->nodetype != en_icon) { + error(ERR_SYNTAX); + return 0; + } + return ep->v.i; +} +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/memmgt.c b/gtc/src/memmgt.c new file mode 100644 index 0000000..856e335 --- /dev/null +++ b/gtc/src/memmgt.c @@ -0,0 +1,532 @@ +/* + * GTools C compiler + * ================= + * source file : + * memory management + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#define USE_MEMMGT +#include "cglbdec.h" + +int glbsize CGLOB, /* size left in current global block */ + locsize CGLOB, /* size left in current local block */ + tmpsize CGLOB, /* size left in current temp block */ + glbindx CGLOB, /* global index */ + locindx CGLOB, /* local index */ + tmpindx CGLOB; /* temp index */ + +int temp_mem CGLOB,temp_local CGLOB; +#ifdef MIN_TEMP_MEM +int min_temp_mem CGLOB; +#endif + +#ifdef PC +int glbmem CGLOB,locmem CGLOB; +#endif + +int max_mem CGLOB, /* statistics... */ + glo_mem CGLOB; + +struct blk *locblk CGLOB, /* pointer to local block list */ + *glbblk CGLOB, /* pointer to global block list */ + *tmpblk CGLOB; /* pointer to temporary block list */ + +#ifdef PC +//void *calloc(); +#endif +static void _err_attr error_memory() { + uerrc2("not enough memory to compile function '%s'",func_sp->name); +} +int *_xalloc(int siz) { + struct blk *bp; + char *rv; + if (temp_local) /* this is NOT perfect, but it's close to being so :) */ + goto glb_xalloc; +/* if (locmem>=50000) + bkpt();*/ +/* if (siz>=1000) + bkpt();*/ +#ifdef MIN_TEMP_MEM + if (temp_mem<=min_temp_mem) { +#else + if (!temp_mem) { +#endif + glb_xalloc: + if (global_flag) { + #ifdef PC + glbmem += siz; + #endif + if (glbsize >= siz) { + rv = &(glbblk->m[glbindx]); + glbsize -= siz; + glbindx += siz; +/* if ((long)rv==0x789388) + bkpt();*/ + return (int *) rv; + } else { + // bp = (struct blk *) calloc(1, (int) sizeof(struct blk)); + bp = (struct blk *) malloc(sizeof(struct blk)); + if (!bp) { +#ifdef PC + msg("not enough memory.\n"); + _exit(1); +#else + error_memory(); + fatal("Not enough global memory"); +#endif + } + memset(bp, 0, sizeof(struct blk)); + glo_mem++; + bp->next = glbblk; + glbblk = bp; + glbsize = BLKLEN - siz; + glbindx = siz; + return (int *) glbblk->m; + } + } else { /* not global */ + #ifdef PC + locmem += siz; + #endif + if (locsize >= siz) { + rv = &(locblk->m[locindx]); + locsize -= siz; + /*if ((long)rv==0x7f86bc) + bkpt();*/ + locindx += siz; + #ifdef PC + if (0x80000000&(long)rv) + fatal("A DIRTY HACK FAILED ON YOUR CONFIG. " + "LOOK AT OUT68K_AS.C TO SOLVE THE PROBLEM"); + #endif +/* if (func_sp) infunc("chk_curword") + if ((long)rv==0x7b4bf8) + bkpt();*/ +/* if ((long)rv==0x7e5cd0) + bkpt();*/ + return (int *) rv; + } else { + // bp = (struct blk *) calloc(1, (int) sizeof(struct blk)); + bp = (struct blk *) malloc(sizeof(struct blk)); + if (!bp) { +#ifdef PC + msg("not enough local memory.\n"); + _exit(1); +#else + error_memory(); + fatal("Not enough local memory"); +#endif + } + memset(bp, 0, sizeof(struct blk)); + bp->next = locblk; + locblk = bp; + locsize = BLKLEN - siz; + locindx = siz; + return (int *) locblk->m; + } + } + } else { + if (tmpsize >= siz) { + rv = &(tmpblk->m[tmpindx]); + tmpsize -= siz; + tmpindx += siz; + return (int *) rv; + } else { +// bp = (struct blk *) calloc(1, (int) sizeof(struct blk)); + bp = (struct blk *) malloc(sizeof(struct blk)); + if (!bp) { +#ifdef PC + msg("not enough temporary memory.\n"); + _exit(1); +#else + error_memory(); + fatal("Not enough temporary memory"); +#endif + } +/* if (bp==0x789364) + bkpt();*/ + memset(bp, 0, sizeof(struct blk)); + bp->next = tmpblk; + tmpblk = bp; + tmpsize = BLKLEN - siz; + tmpindx = siz; + return (int *) tmpblk->m; + } + } +} + +int blk_free(struct blk *bp1) { + int blkcnt = 0; + struct blk *bp2; + while (bp1) { + bp2 = bp1->next; + (void) free((char *) bp1); + blkcnt++; + bp1 = bp2; + } + return blkcnt; +} + +#ifdef DUAL_STACK +typedef struct _ds_block { + void *lo,*hi; + struct _ds_block *pop; + void *popstackptr; +} DS_BLOCK; +static DS_BLOCK *ds_current CGLOB; +void *dualstack CGLOB; +void *ds_currentlo CGLOB,*ds_currenthi CGLOB; + +#ifdef PC +int n_ds_allocations CGLOB; +#endif +void ds_allocatleast(unsigned int size) { + size+=DS_BSIZE; + DS_BLOCK *ds_new = malloc(sizeof(DS_BLOCK)+size); + ds_new->lo = (void *)(ds_new+1); + ds_new->hi = (void *)((char *)ds_new->lo+size); + ds_new->pop = ds_current; + ds_new->popstackptr = dualstack; + ds_current = ds_new; + ds_currentlo = ds_current->lo; + ds_currenthi = ds_current->hi; + dualstack = ds_currentlo; +#ifdef PC + n_ds_allocations++; +#endif +} +void ds_free(void) { + DS_BLOCK *ds_old = ds_current; + ds_current = ds_old->pop; + ds_currentlo = ds_current ? ds_current->lo : 0; + ds_currenthi = ds_current ? ds_current->hi : 0; + dualstack = ds_old->popstackptr; + free(ds_old); +} +void rel_dualstack(void) { + while (ds_current) + ds_free(); +#ifdef PC + //msg2(" performed %d dual-stack-related allocations\n",n_ds_allocations); +#endif +} +#endif + +#define VERBOSE +#ifdef GARBAGE_COLLECT +void d_enode(struct enode **node) { + struct enode *dest,*ep=*node; + if (!ep) return; + if (ep->nodetype==en_icon) { *node=mk_icon(ep->v.i); return; } + dest=xalloc((int)sizeof(struct enode), ENODE); + memcpy(dest,ep,sizeof(struct enode)); + *node=dest; + switch (ep->nodetype) { + case en_land: case en_lor: + case en_asand: case en_asor: case en_asxor: + case en_aslsh: case en_asrsh: + case en_asmul: case en_asmod: case en_asdiv: + case en_asadd: case en_assub: + case en_gt: case en_ge: + case en_lt: case en_le: + case en_eq: case en_ne: + case en_cond: case en_assign: + case en_and: case en_or: case en_xor: + case en_lsh: case en_rsh: + case en_mul: case en_mod: case en_div: + case en_add: case en_sub: + case en_fcall: case en_void: + d_enode(&ep->v.p[1]); + case en_deref: + case en_ainc: case en_adec: + case en_uminus: case en_not: case en_compl: + case en_ref: + case en_cast: /* hum hum */ + case en_fieldref: + d_enode(&ep->v.p[0]); + case en_tempref: + case en_autocon: + case en_labcon: + case en_nacon: + case en_fcon: + return; + case en_compound: + d_snode(&ep->v.st); + return; + default: + ierr(D_ENODE,1); + } +} + +void d_snode(struct snode **node) { + struct snode *dest,*block=*node; + if (!block) return; + dest=xalloc((int)sizeof(struct snode), SNODE); + memcpy(dest,block,sizeof(struct snode)); + *node=dest; + while (block != 0) { + switch (block->stype) { + case st_return: + case st_expr: + d_enode(&block->exp); + break; + case st_loop: + d_enode(&block->exp); + d_snode(&block->s1); + d_enode(&block->v2.e); + break; + case st_while: + case st_do: + d_enode(&block->exp); + d_snode(&block->s1); + break; + case st_for: + d_enode(&block->exp); + d_enode(&block->v1.e); + d_snode(&block->s1); + d_enode(&block->v2.e); + break; + case st_if: + d_enode(&block->exp); + d_snode(&block->s1); + d_snode(&block->v1.s); + break; + case st_switch: + d_enode(&block->exp); + d_snode(&block->v1.s); + break; + case st_case: + case st_default: + d_snode(&block->v1.s); + break; + case st_compound: + case st_label: + d_snode(&block->s1); + case st_goto: + case st_break: + case st_continue: + break; + case st_asm: + d_amode(&(struct amode *)block->v1.i); + break; + default: + ierr(D_SNODE,1); + } + block = block->next; + } +} + +void d_amode(struct amode **node) { + struct amode *dest,*mode=*node; + if (!mode) return; + dest=xalloc((int)sizeof(struct amode), AMODE); + memcpy(dest,mode,sizeof(struct amode)); + *node=dest; + d_enode(&dest->offset); +} +extern struct ocode *_peep_head; +void d_ocodes(void) { + struct ocode *dest=NULL,**node=&_peep_head,*instr; + while ((instr=*node)) { + instr->back=dest; + dest=xalloc((int)sizeof(struct ocode), OCODE); + memcpy(dest,instr,sizeof(struct ocode)); + *node=dest; + d_amode(&dest->oper1); + d_amode(&dest->oper2); + node=&dest->fwd; + } + *node=NULL; +} + +extern struct snode *dump_stmt; +void collect(int g) { + struct blk *blk=glbblk; + glbsize=glbindx=0; + glbblk=NIL_BLK; + alloc_dump(g); + // dump snodes & most enodes +// d_snode(&dump_stmt); + // dump ocodes & amodes & the rest of enodes +// d_ocodes(); + // dump most syms & most strs & typs & tables & the rest of syms & a few strs + d_table(&gsyms); d_table(>ags); d_table(&defsyms); + // dump slits & the rest of strs +// + // no dump is needed for cse's since it is a cooperative garbage-collection +} +#endif + +int _k_=0; +void tmp_use() { + temp_mem++; + _k_++; +} +void tmp_free() { + if (!--temp_mem && tmpblk) { +#ifdef PC + int n=0; +#endif +#ifndef LIFO_TMP_FREE + /* Maybe I'm wrong, but I think that this solution + * is quite bad for the TIOS heap manager... */ + struct blk *nxt; + while ((nxt=tmpblk->next)) + #ifdef PC + n++, + #endif + free(tmpblk),tmpblk=nxt; +#else + struct blk *nxt=tmpblk->next,*tofree; + while (nxt) + #ifdef PC + n++, + #endif + tofree=nxt, nxt=nxt->next, free(tofree); +#endif +#ifdef _DBG_SHOW_TEMPMEM + printf("*"); +#ifdef PC + printf("(%dk)",n*BLKLEN/1024); +// getchar(); +#endif +#endif + tmpsize = BLKLEN; + tmpindx = 0; + memset(tmpblk,0,BLKLEN); + /*blk_free(tmpblk); + tmpblk = 0; + tmpsize = 0;*/ + } +} + +void rel_local() { + unsigned int mem; +#ifndef AS +#define pos 0 +#else + extern unsigned int pos; +#endif +#ifdef PC +#ifdef GARBAGE_COLLECT + collect(0); +#endif +#ifdef LISTING + alloc_dump(0); +#endif +#endif + if ((mem=blk_free(locblk))+glo_mem+(2*pos)/BLKLEN > (unsigned int)max_mem) { + max_mem = mem+glo_mem+(2*pos)/BLKLEN; + /*if (max_mem>330/4) + bkpt();*/ + } +#ifndef AS +#undef pos +#endif +#ifdef PC + locmem = 0; +#endif + locblk = 0; + locsize = 0; +//#ifndef PC +#ifndef GTDEV +#ifdef PC + if (verbose) +#endif + msg2("%d kb\n", (int)(mem * BLKLEN/1024)); +#endif +//#endif +#ifdef VERBOSE +#ifdef LISTING +#if 0 + if (list_option) + msg2(" releasing %2d kb local tables.\n", + mem * BLKLEN/1024); +#endif +#endif +#endif +} + +void rel_global() { + int mem; + if ((mem=blk_free(glbblk)) > max_mem) + max_mem = mem; +#ifdef PC + glbmem = 0; +#endif + glo_mem = 0; + glbblk = 0; + glbsize = 0; + blk_free(tmpblk); + tmpblk = 0; + tmpsize = 0; +#ifdef PC +#ifdef LISTING + alloc_dump(1); +#endif +#endif +#ifdef VERBOSE +#ifdef LISTING + if (list_option) + msg2(" releasing %2d kb global tables.\n", + mem * BLKLEN/1024); +#endif +#ifdef DUAL_STACK + //if (ds_current) + // msg("oops, a dual stack remains\n"); + rel_dualstack(); +#endif +#ifndef GTDEV +#ifdef PC + if (verbose) { + msg2("Max memory request : %d kb\n", + (int)(max_mem * BLKLEN/1024)); + msg("\n"); + if (max_mem * BLKLEN/1024<150) + msg("On-calc portability : very good\n"); + else if (max_mem * BLKLEN/1024<230) + msg("On-calc portability : good\n"); + else if (max_mem * BLKLEN/1024<290) + msg("On-calc portability : questionable\n"); + else if (max_mem * BLKLEN/1024<360) + msg("On-calc portability : difficult without splitting\n"); + else + msg("On-calc portabilty : impossible without splitting\n"); + msg("\n"); + } +#endif +#endif +#endif + max_mem = 0; +} + +void clean_up() { + blk_free(tmpblk); + blk_free(locblk); + blk_free(glbblk); +#ifdef DUAL_STACK + //if (ds_current) + // msg("oops, a dual stack remains\n"); + rel_dualstack(); +#endif + temp_mem = 0; + glbblk = locblk = tmpblk = 0; +/*#ifdef OPTIMIZE_BSS + free(bssdata); +#endif*/ +} + +#undef VERBOSE +// vim:ts=4:sw=4 diff --git a/gtc/src/optimize.c b/gtc/src/optimize.c new file mode 100644 index 0000000..7de0d7a --- /dev/null +++ b/gtc/src/optimize.c @@ -0,0 +1,887 @@ +/* + * GTools C compiler + * ================= + * source file : + * optimization + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" + +static void fold_const(); + +void dooper(struct enode **node) { +/* + * dooper will execute a constant operation in a node and modify the node to + * be the result of the operation. + */ + struct enode *ep = *node; + enum(e_node) type = ep->nodetype; + +#define ep0 ep->v.p[0] +#define ep1 ep->v.p[1] +#define epi ep->v.i +#define epf ep->v.f +#define ulong unsigned long + + ep->nodetype = ep0->nodetype; + if (ep0->nodetype == en_fcon) { +#ifndef NOFLOAT + switch (type) { + case en_uminus: +#ifdef PC + epf = - ep0->v.f; +#else + epf = ep0->v.f; + if (epf) epf^=0x80; +#endif + break; + case en_not: + ep->nodetype = en_icon; + epi = (ep0->v.f) ? 0 : 1; + break; + case en_add: +#ifdef PC + epf = ep0->v.f + ep1->v.f; +#else + epf = ffpadd(ep0->v.f, ep1->v.f); +#endif + break; + case en_sub: +#ifdef PC + epf = ep0->v.f - ep1->v.f; +#else + epf = ffpsub(ep0->v.f, ep1->v.f); +#endif + break; + case en_mul: +#ifdef PC + epf = ep0->v.f * ep1->v.f; +#else + epf = ffpmul(ep0->v.f, ep1->v.f); +#endif + break; + case en_div: + if (ep1->v.f == 0) { + uwarn("division by zero"); + ep->nodetype = en_div; + } else { +#ifdef PC + epf = ep0->v.f / ep1->v.f; +#else + epf = ffpdiv(ep0->v.f, ep1->v.f); +#endif + } + break; + case en_eq: + ep->nodetype = en_icon; + epi = (ep0->v.f == ep1->v.f) ? 1 : 0; + break; + case en_ne: + ep->nodetype = en_icon; + epi = (ep0->v.f != ep1->v.f) ? 1 : 0; + break; + case en_land: + ep->nodetype = en_icon; + epi = (ep0->v.f && ep1->v.f) ? 1 : 0; + break; + case en_lor: + ep->nodetype = en_icon; + epi = (ep0->v.f || ep1->v.f) ? 1 : 0; + break; + case en_lt: + ep->nodetype = en_icon; +#ifdef PC + epi = (ep0->v.f < ep1->v.f) ? 1 : 0; +#else + epi = (ffpcmp_c(ep0->v.f, ep1->v.f) < 0) ? 1 : 0; +#endif + break; + case en_le: + ep->nodetype = en_icon; +#ifdef PC + epi = (ep0->v.f <= ep1->v.f) ? 1 : 0; +#else + epi = (ffpcmp_c(ep0->v.f, ep1->v.f) <= 0) ? 1 : 0; +#endif + break; + case en_gt: + ep->nodetype = en_icon; +#ifdef PC + epi = (ep0->v.f > ep1->v.f) ? 1 : 0; +#else + epi = (ffpcmp_c(ep0->v.f, ep1->v.f) > 0) ? 1 : 0; +#endif + break; + case en_ge: + ep->nodetype = en_icon; +#ifdef PC + epi = (ep0->v.f >= ep1->v.f) ? 1 : 0; +#else + epi = (ffpcmp_c(ep0->v.f, ep1->v.f) >= 0) ? 1 : 0; +#endif + break; + default: + ep->nodetype = type; + iwarn(DOOPER,1); + break; + } +#endif /* NOFLOAT */ + return; + } + /* + * Thus, ep0->nodetype is en_icon + * We have to distinguish unsigned long from the other cases + * + * Since we always store in ep->v.i, it is + * ASSUMED THAT (long) (ulong) ep->v.i == ep->v.i always + */ + if (ep0->etype == bt_ulong || ep0->etype == bt_pointer) { + switch (type) { + case en_uminus: + epi = - ep0->v.i; + break; + case en_not: + epi = ((ulong) ep0->v.i) ? 0 : 1; + break; + case en_compl: + epi = ~ (ulong) ep0->v.i; + epi = strip_icon(epi, ep->etype); + break; + case en_add: + epi = (ulong) ep0->v.i + (ulong) ep1->v.i; + break; + case en_sub: + epi = (ulong) ep0->v.i - (ulong) ep1->v.i; + break; + case en_mul: + epi = (ulong) ep0->v.i * (ulong) ep1->v.i; + break; + case en_div: + if ((ulong) ep1->v.i == 0) { + uwarn("division by zero"); + ep->nodetype = en_div; + } else { + epi = (ulong) ep0->v.i / (ulong) ep1->v.i; + } + break; + case en_mod: + if ((ulong) ep1->v.i == 0) { + uwarn("division by zero"); + ep->nodetype = en_mod; + } else { + epi = (ulong) ep0->v.i % (ulong) ep1->v.i; + } + break; + case en_and: + epi = (ulong) ep0->v.i & (ulong) ep1->v.i; + break; + case en_or: + epi = (ulong) ep0->v.i | (ulong) ep1->v.i; + break; + case en_xor: + epi = (ulong) ep0->v.i ^ (ulong) ep1->v.i; + break; + case en_eq: + epi = ((ulong) ep0->v.i == (ulong) ep1->v.i) ? 1 : 0; + break; + case en_ne: + epi = ((ulong) ep0->v.i != (ulong) ep1->v.i) ? 1 : 0; + break; + case en_land: + epi = ((ulong) ep0->v.i && (ulong) ep1->v.i) ? 1 : 0; + break; + case en_lor: + epi = ((ulong) ep0->v.i || (ulong) ep1->v.i) ? 1 : 0; + break; + case en_lt: + epi = ((ulong) ep0->v.i < (ulong) ep1->v.i) ? 1 : 0; + break; + case en_le: + epi = ((ulong) ep0->v.i <= (ulong) ep1->v.i) ? 1 : 0; + break; + case en_gt: + epi = ((ulong) ep0->v.i > (ulong) ep1->v.i) ? 1 : 0; + break; + case en_ge: + epi = ((ulong) ep0->v.i >= (ulong) ep1->v.i) ? 1 : 0; + break; + case en_lsh: +#ifdef MINIMAL_SIZES + epi = (ulong) ep0->v.i << (char) ep1->v.i; +#else + epi = (ulong) ep0->v.i << (ulong) ep1->v.i; +#endif + break; + case en_rsh: +#ifdef MINIMAL_SIZES + epi = (ulong) ep0->v.i >> (char) ep1->v.i; +#else + epi = (ulong) ep0->v.i >> (ulong) ep1->v.i; +#endif + break; + default: + ep->nodetype = type; + iwarn(DOOPER,2); + break; + } + } else { + switch (type) { + case en_uminus: + epi = - ep0->v.i; + break; + case en_not: + epi = (ep0->v.i) ? 0 : 1; + break; + case en_compl: + epi = ~ ep0->v.i; + epi = strip_icon(epi, type); + break; + case en_add: + epi = ep0->v.i + ep1->v.i; + break; + case en_sub: + epi = ep0->v.i - ep1->v.i; + break; + case en_mul: + epi = ep0->v.i * ep1->v.i; + break; + case en_div: + if (ep1->v.i == 0) { + uwarn("division by zero"); + ep->nodetype = en_div; + } else { + epi = ep0->v.i / ep1->v.i; + } + break; + case en_mod: + if (ep1->v.i == 0) { + uwarn("division by zero"); + ep->nodetype = en_mod; + } else { + epi = ep0->v.i % ep1->v.i; + } + break; + case en_and: + epi = ep0->v.i & ep1->v.i; + break; + case en_or: + epi = ep0->v.i | ep1->v.i; + break; + case en_xor: + epi = ep0->v.i ^ ep1->v.i; + break; + case en_eq: + epi = (ep0->v.i == ep1->v.i) ? 1 : 0; + break; + case en_ne: + epi = (ep0->v.i != ep1->v.i) ? 1 : 0; + break; + case en_land: + epi = (ep0->v.i && ep1->v.i) ? 1 : 0; + break; + case en_lor: + epi = (ep0->v.i || ep1->v.i) ? 1 : 0; + break; + case en_lt: + epi = (ep0->v.i < ep1->v.i) ? 1 : 0; + break; + case en_le: + epi = (ep0->v.i <= ep1->v.i) ? 1 : 0; + break; + case en_gt: + epi = (ep0->v.i > ep1->v.i) ? 1 : 0; + break; + case en_ge: + epi = (ep0->v.i >= ep1->v.i) ? 1 : 0; + break; + case en_lsh: +#ifdef MINIMAL_SIZES + epi = ep0->v.i << (char)ep1->v.i; +#else + epi = ep0->v.i << ep1->v.i; +#endif + break; + case en_rsh: +#ifdef MINIMAL_SIZES + epi = ep0->v.i >> (char)ep1->v.i; +#else + epi = ep0->v.i >> ep1->v.i; +#endif + break; + default: + ep->nodetype = type; + iwarn(DOOPER,3); + break; + } + } +#undef ep0 +#undef ep1 +#undef epi +#undef epf +#undef ulong +} + +int pwrof2(long i) { +/* + * return which power of two i is or -1. + */ + int p; + long q; + q = 2; + p = 1; + while (q > 0) { + if (q == i) + return p; + q <<= 1; + ++p; + } + return -1; +} + +long mod_mask(long i) { +/* + * make a mod mask for a power of two. + */ + long m; + m = 0; + while (i--) + m = (m << 1) | 1; + return m; +} + +void opt0(struct enode **node) { +/* + * opt0 - delete useless expressions and combine constants. + * + * opt0 will delete expressions such as x + 0, + * x - 0, + * x * 0, + * x * 1, + * 0 / x, + * x / 1, + * x % (1<<3), + * etc from the tree pointed to by node and combine obvious + * constant operations. It cannot combine name and label constants but will + * combine icon type nodes. + */ + struct enode *ep; + +#define ep0 ep->v.p[0] +#define ep1 ep->v.p[1] + + long val, sc; + enum(e_node) typ; + ep = *node; + if (ep == 0) + return; + typ = ep->nodetype; + switch (typ) { + case en_ref: + case en_fieldref: + case en_ainc: + case en_adec: + case en_deref: + opt0(&ep0); + break; + case en_uminus: + case en_compl: + opt0(&ep0); + /* + * This operation applied twice is a no-op + */ + if (ep0->nodetype == typ) { + *node = ep0->v.p[0]; + break; + } + if (ep0->nodetype == en_icon || ep0->nodetype == en_fcon) + dooper(node); + break; + case en_not: + opt0(&ep0); + if (ep0->nodetype == en_icon || ep0->nodetype == en_fcon) + dooper(node); + break; + case en_add: + case en_sub: + opt0(&ep0); + opt0(&ep1); + /* + * a + (-b) = a - b + * a - (-b) = a + b + * (-a) + b = b - a + */ + if (ep1->nodetype == en_uminus) { + ep1 = ep1->v.p[0]; + ep->nodetype = typ = (typ == en_add) ? en_sub : en_add; + } + if (ep0->nodetype == en_uminus && typ == en_add) { + ep0 = ep0->v.p[0]; + swap_nodes(ep); + ep->nodetype = typ = en_sub; + } + /* + * constant expressions + */ + if ((ep0->nodetype == en_icon && ep1->nodetype == en_icon) || + (ep0->nodetype == en_fcon && ep1->nodetype == en_fcon)) { + dooper(node); + break; + } + /*infunc("DrawNumberOfClock") + bkpt();*/ + /* the following would bug, as : + short my_array[2]={12,570}; + int i=2; + while (i--) printf("%d",my_array[i]); + wouldn't print 570 correctly... */ +#ifdef BUGGY_AND_ANYWAY_NOT_COMPAT_WITH_NO_OFFSET_AUTOCON + if (typ == en_add) { + if (ep1->nodetype == en_autocon) + swap_nodes(ep); + } +#endif + if (ep0->nodetype == en_icon) { + if (ep0->v.i == 0) { + if (typ == en_sub) { + ep0 = ep1; + ep->nodetype = typ = en_uminus; + } else + *node = ep1; + break; +#ifdef PREFER_POS_VALUES + } else if (ep0->nodetype==en_add && ep0->v.i<0) { + ep0->v.i=-ep0->v.i; + swap_nodes(ep); + ep->nodetype=en_sub; +#endif + } + } else if (ep1->nodetype == en_icon) { +#ifdef BUGGY_AND_ANYWAY_NOT_COMPAT_WITH_NO_OFFSET_AUTOCON + if (ep0->nodetype == en_autocon && typ == en_add) { + ep0->v.i += ep1->v.i; + *node = ep0; + break; + } +#endif + if (ep1->v.i == 0) { + *node = ep0; + break; +#ifdef PREFER_POS_VALUES + } else if (ep1->v.i<0) { + ep->nodetype^=1; + ep1->v.i=-ep1->v.i; +#endif + } + } + break; + case en_mul: + opt0(&ep0); + opt0(&ep1); + /* + * constant expressions + */ + if ((ep0->nodetype == en_icon && ep1->nodetype == en_icon) || + (ep0->nodetype == en_fcon && ep1->nodetype == en_fcon)) { + dooper(node); + break; + } + if (ep0->nodetype == en_icon) { + val = ep0->v.i; + if (val == 0) { + *node = ep0; + break; + } + if (val == 1) { + *node = ep1; + break; + } + sc = pwrof2(val); + if (sc IS_VALID) { + swap_nodes(ep); + ep1->v.i = sc; + ep->nodetype = en_lsh; + } + } else if (ep1->nodetype == en_icon) { + val = ep1->v.i; + if (val == 0) { + *node = ep1; + break; + } + if (val == 1) { + *node = ep0; + break; + } + sc = pwrof2(val); + if (sc IS_VALID) { + ep1->v.i = sc; + ep->nodetype = en_lsh; + } + } + break; + case en_div: + opt0(&ep0); + opt0(&ep1); + /* + * constant expressions + */ + if ((ep0->nodetype == en_icon && ep1->nodetype == en_icon) || + (ep0->nodetype == en_fcon && ep1->nodetype == en_fcon)) { + dooper(node); + break; + } + if (ep0->nodetype == en_icon) { + if (ep0->v.i == 0) { /* 0/x */ + *node = ep0; + break; + } + } else if (ep1->nodetype == en_icon) { + val = ep1->v.i; + if (val == 1) { /* x/1 */ + *node = ep0; + break; + } + sc = pwrof2(val); + if (sc IS_VALID) { + ep1->v.i = sc; + ep->nodetype = en_rsh; + } + } + break; + case en_mod: + opt0(&ep0); + opt0(&ep1); + /* + * constant expressions + */ + if ((ep0->nodetype == en_icon && ep1->nodetype == en_icon) || + (ep0->nodetype == en_fcon && ep1->nodetype == en_fcon)) { + dooper(node); + break; + } + if (ep1->nodetype == en_icon) { + sc = pwrof2(ep1->v.i); + if (sc IS_VALID) { + ep1->v.i = mod_mask(sc); + ep->nodetype = en_and; + } + } + break; + case en_land: + case en_lor: +#if 0 /* perhaps this isn't *that* useful... and ep0/ep1 are long to access */ + opt0(&ep0); + opt0(&ep1); + if ((ep0->nodetype == en_icon && ep1->nodetype == en_icon) || + (ep0->nodetype == en_fcon && ep1->nodetype == en_fcon)) + dooper(node); + else { + typ = (typ==en_lor); + if (ep0->nodetype == en_icon) { + if ((!ep0->v.i)!=typ) /* absorbing element */ + ep = ep0; + else /* "neutral" element */ + //ep = ep1; -> not quite, should be !!x + (void)0; + } else if (ep1->nodetype == en_icon) { + if ((!ep1->v.i)!=typ) /* absorbing element */ + ep->nodetype = en_void, ep1->v.i=typ; + else /* "neutral" element */ + //ep = ep0; -> not quite, should be !!x + (void)0; + } + } + break; +#else + /* FALL THROUGH */ +#endif + case en_and: + case en_or: + case en_xor: + case en_eq: + case en_ne: + case en_lt: + case en_le: + case en_gt: + case en_ge: + opt0(&ep0); + opt0(&ep1); + /* + * constant expressions + */ + if ((ep0->nodetype == en_icon && ep1->nodetype == en_icon) || + (ep0->nodetype == en_fcon && ep1->nodetype == en_fcon)) + dooper(node); + break; + case en_lsh: + case en_rsh: + opt0(&ep0); + opt0(&ep1); + if (ep0->nodetype == en_icon && ep1->nodetype == en_icon) { + dooper(node); + break; + } + /* + * optimize a << 0 and a >> 0 + */ + if (ep1->nodetype == en_icon && ep1->v.i == 0) + *node = ep0; + break; + case en_cond: + opt0(&ep0); + opt0(&ep1); + if (ep0->nodetype == en_icon) { + if (ep0->v.i) { + if (ep1->v.p[0]) *node=ep1->v.p[0]; + else *node=ep0; + } else + *node=ep1->v.p[1]; + } + break; + case en_asand: + case en_asor: + case en_asxor: + case en_asadd: + case en_assub: + case en_asmul: + case en_asdiv: + case en_asmod: + case en_asrsh: + case en_aslsh: + case en_fcall: + case en_void: + case en_assign: + opt0(&ep0); + opt0(&ep1); + break; + /* now handled in expr.c */ + case en_cast: + opt0(&ep0); + if (ep0->nodetype == en_icon) { +#ifndef NOFLOAT + if (ep->etype != bt_float +#ifdef DOUBLE + && ep->etype != bt_double +#endif + ) { +#endif + ierr(OPT0,1); +/* ep->nodetype = en_icon; + ep->v.i = ep0->v.i;*/ +#ifndef NOFLOAT + } else { +#ifdef XCON_DOESNT_SUPPORT_FLOATS +#error Fix me now :) +#endif + ep->nodetype = en_fcon; +#ifdef PC + ep->v.f = (double)ep0->v.i; +#else +#ifndef BCDFLT + ep->v.f = ffpltof(ep0->v.i); +#else + ep->v.f = (double)ep0->v.i; +#endif +#endif + } +#endif + } + /* perhaps BUGGY */ + else if ((ep0->nodetype == en_labcon || ep0->nodetype == en_nacon) + && ep->esize<=ep0->esize) { + ep0->etype = ep->etype; + ep0->esize = ep->esize; + ep=ep0; + *node=ep; + } +#ifndef NOFLOAT + else if (ep0->nodetype == en_fcon && bt_integral(ep->etype)) { + ep->nodetype = en_icon; +#ifdef PC + ep->v.i = (long)ep0->v.f; +#else + ep->v.i = ffpftol(ep0->v.f); +#endif + } +#endif + break; + /*case en_icon: + case en_fcon: + case en_labcon: + case en_nacon: + case en_autocon: + case en_tempref: + break; + default: + uwarn("Didn't optimize nodetype %d. Please send me your source code.",typ);*/ + } + +#undef ep0 +#undef ep1 +} + +static long xfold(struct enode *node) { +/* + * xfold will remove constant nodes and return the values to the calling + * routines. + */ + long i; + if (node == 0) + return 0; + switch (node->nodetype) { + case en_icon: + i = node->v.i; + node->v.i = 0; + return i; + case en_add: + return xfold(node->v.p[0]) + xfold(node->v.p[1]); + case en_sub: + return xfold(node->v.p[0]) - xfold(node->v.p[1]); + case en_mul: + if (node->v.p[0]->nodetype == en_icon) + return xfold(node->v.p[1]) * node->v.p[0]->v.i; + else if (node->v.p[1]->nodetype == en_icon) + return xfold(node->v.p[0]) * node->v.p[1]->v.i; + else { + fold_const(&node->v.p[0]); + fold_const(&node->v.p[1]); + return 0; + } + /* + * CVW: This seems wrong to me... case en_lsh: if( + * node->v.p[0]->nodetype == en_icon ) return xfold(node->v.p[1]) << + * node->v.p[0]->v.i; else if( node->v.p[1]->nodetype == en_icon ) + * return xfold(node->v.p[0]) << node->v.p[1]->v.i; else return 0; + */ + case en_uminus: + return -xfold(node->v.p[0]); + case en_lsh: + case en_rsh: + case en_div: + case en_mod: + case en_asadd: + case en_assub: + case en_asmul: + case en_asdiv: + case en_asmod: + case en_and: + case en_land: + case en_or: + case en_lor: + case en_xor: + case en_asand: + case en_asor: + case en_asxor: + case en_void: + case en_fcall: + case en_assign: + case en_eq: + case en_ne: + case en_lt: + case en_le: + case en_gt: + case en_ge: + fold_const(&node->v.p[0]); + fold_const(&node->v.p[1]); + return 0; + case en_ref: + case en_fieldref: + case en_compl: + case en_not: + case en_deref: + fold_const(&node->v.p[0]); + return 0; + /* + * This is not stricly legal: (long)(x+10) * 4l might not be the same + * as (long)(x) * 4l + 40l but it is the same as long as no overflows + * occur + */ + case en_cast: +#ifdef DONTDEF + return xfold(node->v.p[0]); +#endif + /* + * Well, sometimes I prefer purity to efficiency + * It is a matter of taste how you decide here.... + */ + fold_const(&node->v.p[0]); + return 0; + } + return 0; +} + +static void fold_const(struct enode **node) { +/* + * reorganize an expression for optimal constant grouping. + */ + struct enode *ep; + long i; + ep = *node; + if (ep == 0) + return; + if (ep->nodetype == en_add) { + if (ep->v.p[0]->nodetype == en_icon) { + ep->v.p[0]->v.i += xfold(ep->v.p[1]); + return; + } else if (ep->v.p[1]->nodetype == en_icon) { + ep->v.p[1]->v.i += xfold(ep->v.p[0]); + return; + } + } else if (ep->nodetype == en_sub) { + if (ep->v.p[0]->nodetype == en_icon) { + ep->v.p[0]->v.i -= xfold(ep->v.p[1]); + return; + } else if (ep->v.p[1]->nodetype == en_icon) { + ep->v.p[1]->v.i -= xfold(ep->v.p[0]); + return; + } + } + i = xfold(ep); + if (i != 0) { +/* + * strip_icon is in fact harmless here since this value is + * just added to *node + * consider in 16-bit mode: + * + * int day, year; + * day = 365 * (year - 1970); + * + * and look at the code, which is transformed to + * + * day = 365*year + 1846; + * + * which works if the multiplication returns the lower 16 bits of + * the result correctly. + */ + i = strip_icon(i, (*node)->etype); + ep = mk_icon(i); + ep->etype = (*node)->etype; + ep->esize = (*node)->esize; + ep = mk_node(en_add, *node, ep); + ep->etype = (*node)->etype; + ep->esize = (*node)->esize; + *node = ep; + } +} + +void opt4(struct enode **node) { +/* + * apply all constant optimizations. + */ + /* opt0(node); */ + fold_const(node); + opt0(node); +} +// vim:ts=4:sw=4 diff --git a/gtc/src/out68k_as.c b/gtc/src/out68k_as.c new file mode 100644 index 0000000..43f840c --- /dev/null +++ b/gtc/src/out68k_as.c @@ -0,0 +1,3017 @@ +/* + * GTools C compiler + * ================= + * source file : + * assembled binary output + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" + +#ifdef PC +void nl(void) { +} +#define nl() while (0) +#endif + +#ifdef SECURIZED_ALIGN +#define put_align(__a) while (0) +#else +#define put_align(__a) put_align2() +#endif + +#ifdef PC +#define tabs "\t" +#else +#define tabs " " +#endif + +#define N_TAB 64 +#define N_TAB_LOG 6 +typedef struct _ltab { + struct _ltab *nxt; + unsigned int t[N_TAB]; +} LTAB; +#define N_REF 8 +#define N_REF_LOG 3 +typedef struct _ref { + unsigned int r[N_REF]; + struct _ref *nxt; // very important to be afterwards : if nxt==NULL, then r[N_REF]==0 +} REF; +typedef struct _gtab { + struct _gtab *nxt; + unsigned int t[N_TAB]; + REF *r[N_TAB]; +} GTAB; + +typedef struct _rtype { + REF *r0,*r; +} RTYPE; +typedef struct _func { + RTYPE rt; + unsigned int f; + struct _func *nxt; +} FUNC; +typedef struct _xtab { + struct _xtab *nxt; + RTYPE *t[N_TAB]; +} XTAB; + +FILE *output CGLOB; +unsigned char *bin CGLOB; +struct slit *strtab CGLOB; +long lc_bss CGLOB; +xstatic int lc_stk CGLOB,uses_lc_stk CGLOB; +xstatic char odd CGLOB; // for put_align +xstatic int extlabel CGLOB; +int glblabel CGLOB; +struct ocode *scope_head CGLOB; +unsigned int pos CGLOB,bin_size CGLOB; +int nostub_mode CGLOB; +#ifdef EXE_OUT +int exestub_mode CGLOB; +#else +#define exestub_mode 0 +#endif +LTAB *loc_tab CGLOB; +GTAB *glb_tab CGLOB; +XTAB *ext_tab CGLOB; +LTAB *exp_tab CGLOB; // warning : the content is the exported label (but not the offset) +FUNC *rom_funcs CGLOB; +#ifdef RAM_CALLS +FUNC *ram_funcs CGLOB; +#endif +RTYPE reloc_tab CGLOBL,bss_tab CGLOBL; +HTABLE alsyms CGLOBL; +TABLE libsyms CGLOBL; // (FUNC *)sym->value.i + +#ifdef SIZE_STATS +xstatic unsigned int c_compiler_sz CGLOB; +#endif + +#ifdef MC680X0 +/* variable initialization */ +enum e_gt { + nogen, bytegen, wordgen, longgen, floatgen +}; +enum e_sg { + noseg, codeseg, dataseg +}; + + +char *outlate(); +#ifndef NOFLOAT +#ifdef PC +unsigned long double2ffp(); +#else +#define double2ffp(__x) (__x) +#endif +#endif +void wrt2(short x); +void set_label(int lab,unsigned int pos); +unsigned int lab_src(int n); +void put_label(int lab); +void put_align2(void); + +enum(e_gt) gentype; +enum(e_sg) curseg; +int outcol; + +#define BIN_STEP 128 + +void out_init() { +// fputs("gtc_compiled:\n", output); + curseg = noseg; + gentype = nogen; + outcol = 0; + lc_stk = 0; + odd = 0; + extlabel = -1; + glblabel = -32768; + scope_head = 0; + pos = 4; + hashinit(&alsyms); + reloc_tab.r = 0; + bss_tab.r = 0; + libsyms.tail = libsyms.head = 0; + rom_funcs = 0; +#ifdef RAM_CALLS + ram_funcs = 0; +#endif + loc_tab = 0; + glb_tab = 0; + ext_tab = 0; + nostub_mode = 0; +#ifdef EXE_OUT + exestub_mode = 0; +#endif + bin = malloc(bin_size = BIN_STEP); + pos = 4; + put_label(label("gtc_compiled")); +#ifdef SIZE_STATS + c_compiler_sz=0; +#endif +} + +char *unres_name(int lab) { + SYM *ttail; int crc=N_HASH;; + while (crc--) { + ttail=alsyms.h[crc].tail; + while (ttail) { + if ((short)ttail->value.splab==(short)lab) + return ttail->name; + ttail = ttail->prev; + } + } + return 0; +} +void scan_unresolved() { + GTAB *t=glb_tab; int l=0x8000; + while (t) { + REF **r=t->r; int n; + n=N_TAB; + while (n--) { + if (*r++) + uerrc2("unresolved symbol '%s'",unres_name(l)); + l++; + } + t=t->nxt; + } +} + +int eval_rt(RTYPE *r) { + int n=1; + REF *p=r->r0,*q=r->r; + while (p!=q) + n+=N_REF,p=p->nxt; + if (p) { + unsigned int *a=p->r; + while (*a++) n++; + } + return n; +} +unsigned int eval_functab(FUNC *f) { + int n=1; + while (f) + n+=1+eval_rt(&f->rt),f=f->nxt; + return n+n; +} +unsigned int eval_libs() { + int n=2; + SYM *sp=libsyms.head; + while (sp) + n+=10+eval_functab((FUNC *)sp->value.i),sp=sp->next; +// return 2; + return n; +} +unsigned int eval_export() { + int i=N_TAB,n=i; + int *a; + if (!exp_tab) + return 0; + a=exp_tab->t; + while (i--) + if (*a++) n=i; + return (1+N_TAB-n)<<1; +} + +#ifdef PC +xstatic unsigned char *hdr CGLOB,*hdrp CGLOB; +#else +xstatic unsigned short *hdr CGLOB,*hdrp CGLOB; +#endif +xstatic short hshift CGLOB; +#ifdef PC +void _wri(unsigned short x) { + unsigned char hi=(char)(x>>8),lo=(char)x; + *hdrp++=hi; + *hdrp++=lo; +} +void _ovwri(unsigned int i,unsigned short x) { + unsigned char hi=(char)(x>>8),lo=(char)x; + if (i&1) fatal("ODD OVWRI"); + hdr[i+0]=hi; + hdr[i+1]=lo; +} +void _orwri(unsigned int i,unsigned short x) { + unsigned char hi=(char)(x>>8),lo=(char)x; + if (i&1) fatal("ODD ORWRI"); + hdr[i+0]|=hi; + hdr[i+1]|=lo; +} +#define wri(x) (_wri((unsigned short)(x))) +#define ovwri(i,x) (_ovwri(i,(unsigned short)(x))) +#define orwri(i,x) (_orwri(i,(unsigned short)(x))) +#else +#define wri(x) (*hdrp++=x) +#define ovwri(i,x) (*(unsigned short *)((char *)hdr+i)=x) +#define orwri(i,x) (*(unsigned short *)((char *)hdr+i)|=x) +#endif +void write_rt(RTYPE *r) { + REF *p=r->r0; + while (p) { + unsigned int x,*a=p->r; int n; + if ((p=p->nxt)) { + n=N_REF; while (n--) wri((*a++)+hshift); + } else + while ((x=*a++)) wri(x+hshift); + } + wri(0); +} +void write_reloc( +#ifdef OBJ_OUT + int directly_to_bin +#else + #define directly_to_bin 0 +#endif + ) { + RTYPE *r=&reloc_tab; + REF *p=r->r0; + while (p) { + unsigned int x,*a=p->r; int n; + if ((p=p->nxt)) { + n=N_REF; while (n--) { + x=*a++; + directly_to_bin?wrt2(x+hshift+2):wri(x+hshift); + #ifdef PC + { short a=bin[x+2]<<8; + a+=bin[x+3]+hshift; /* logically, shouldn't overflow... */ + bin[x+2]=(unsigned char)(a>>8); + bin[x+3]=(unsigned char)(a); + } + #else + *(long *)(bin+x)+=hshift; + #endif + } + } else + while ((x=*a++)) { + #ifdef PC + { short a=bin[x+2]<<8; + a+=bin[x+3]+hshift; /* logically, shouldn't overflow... */ + bin[x+2]=(unsigned char)(a>>8); + bin[x+3]=(unsigned char)(a); + } + #else + *(long *)(bin+x)+=hshift; + #endif + directly_to_bin?wrt2(x+hshift+2):wri(x+hshift); + } + } + directly_to_bin?wrt2(0):wri(0); +} +#undef directly_to_bin +void write_functab(FUNC *f0) { + int n=0; FUNC *f=f0; + while (f) + n++,f=f->nxt; + wri(n-1); + f=f0; + while (f) + wri(f->f),write_rt(&f->rt),f=f->nxt; +} +void write_libs() { + int n=0; + SYM *sp=libsyms.head; +// wri(0); return; + while (sp) + n++,sp=sp->next; + wri(n); + sp=libsyms.head; + while (sp) { + memset(hdrp,0,8); + strcpy((char *)hdrp,sp->name); + hdrp+=8/sizeof(*hdrp); + wri(0); + sp=sp->next; + } + sp=libsyms.head; + while (sp) + write_functab((FUNC *)sp->value.i),sp=sp->next; +} +unsigned int qlab_src(int n); +void write_export(unsigned int l) { + int *a=exp_tab->t,x; + l=(l>>1)-1; + wri((short)l); + while (l--) { + if ((x=*a++)) + x=qlab_src(x)+hshift; + wri(x); + } +} + +#ifdef EXE_OUT +typedef struct { + short t; // type + unsigned short loc; // location, offset based on relocated output +} EXE_ITEM; +int +#ifdef PC +#ifdef _MSC_VER +__cdecl +#endif +#else +CALLBACK +#endif +exe_compare(const void *a,const void *b) { + return ((EXE_ITEM *)a)->loc-((EXE_ITEM *)b)->loc; +} +void *GTPackDo(void *buf,unsigned int *buflen); +#include "out68k_exe.h" +#endif + +readonly char pgm_init[0x1A]={0x61,0,0,0,'6','8','k','P'}; +readonly char lib_init[0x1A]={0x4E,0x75,0x4E,0x75,'6','8','k','L'}; +readonly char pgm_stub[0xA]={0x2F,0x38,0x00,0x34,0x66,0x02,0x50,(char)0x8F,0x4E,0x75}; +void wrt2(short x); +void wrt1(char x); +void out_close() { +#ifdef PC + int calctype_used[]={0,0,0}; + char *calc_symbols[]={"USE_TI89","USE_TI92PLUS","USE_V200"}; + int calc,specific=1,something; + for (something=0;!something;specific=0) + for (calc=0;calc<3;calc++) + if (!specific || search(calc_symbols[calc],-1,&defsyms)) + calctype_used[calc]++,something++; +#endif + if (bin) { + /* + * 0x1A+(2+10*nLibs+2*(nLibs+nLibCalls+nLibFuncs))+(2+2+2*(nRomFuncs+nRomCalls)) + * +2+2+(4+nBSS*2)+(2+nExport*2) + * +0xA+(nReloc+1)*2 + * = + * 0x1A+(2+10*nLibs+nLibs(eval(Lib)))+(2+eval(rom)) + * +2+2+(4+nBSS*2)+(2+nExport*2) + * +0xA+eval_rt(reloc_tab)*2 + * = + * 0x1A+(2+eval_libs())+(2+eval(rom)) + * +2+2+(4+nBSS*2)+(2+nExport*2) + * +0xA+eval_rt(reloc_tab)*2 + */ + SYM *mainsym; + unsigned int rom=eval_functab(rom_funcs)-2,lib=eval_export(); +#ifdef RAM_CALLS + unsigned int ram=eval_functab(ram_funcs)-2; +#else +#define ram 0 +#endif +#ifdef OBJ_OUT + int object=!!search("_GENERIC_ARCHIVE",-1,&defsyms); + if (!object) { +#endif + int nostub=search("_nostub",-1,&alsyms) || search("_nostub",-1,&gsyms) + || search("_nostub",-1,&defsyms) || nostub_mode; +#ifdef EXE_OUT + int exestub=!!search("EXE_OUT",-1,&defsyms); + if (exestub) nostub=0; +#else +#define exestub 0 +#endif + debug('+'); + if (nostub) { + if (ram || rom) fatal("RAM/ROM_CALL in _nostub"); + if (libsyms.head) fatal("Libraries in _nostub"); + if (bss_tab.r) fatal("BSS in _nostub"); + hshift=0; +#ifdef EXE_OUT + } else if (exestub) { + if (ram) fatal("RAM_CALL in EXE format"); + if (libsyms.head) fatal("Libraries in exe format"); +#endif + } else { + hdrp=hdr=malloc((hshift=0x1A-4+(eval_libs())+(rom?rom+4:2) + +(ram?ram+4:2)+(eval_rt(&reloc_tab)<<1)+(bss_tab.r?4+(eval_rt(&bss_tab)<<1):0) + +(lib)+(lib?0:0xA))+4); + if (!hdr) + fatal("memory"); + memcpy(hdr,lib?lib_init:pgm_init,0x1A); + hdrp+=0x1A/sizeof(*hdrp); + write_libs(); // import table + wri(rom); // ROM table + if (rom) write_functab(rom_funcs); + #ifdef RAM_CALLS + wri(ram); // RAM table + if (ram) write_functab(ram_funcs); + #else + wri(0); // no RAM table + #endif + #ifdef OBJ_OUT + write_reloc(0); // reloc table + #else + write_reloc(); // reloc table + #endif + if (bss_tab.r) { + ovwri(0x14,(char *)hdrp-(char *)hdr); // BSS table + wri(lc_bss>>16),wri(lc_bss); + write_rt(&bss_tab); + } + if (lib) { + ovwri(0x16,(char *)hdrp-(char *)hdr); // export table + write_export(lib); + } + if (!lib) { + ovwri(0x02,(char *)hdrp-(char *)hdr-2); // stub + memcpy(hdrp,pgm_stub,0xA); + hdrp+=0xA/sizeof(*hdrp); + } + #ifdef PC + if (hdrp!=hdr+(hshift+4)/sizeof(*hdrp)) + ierr(LINK_MISPL,1); + #endif + /* link with file */ + if ((mainsym=search("VERSION",-1,&defsyms))) { + + ovwri(0x10,1<<8); + } + } + mainsym=NULL; + if (!lib && ((!nostub && !exestub) || !search("NO_MAIN",-1,&defsyms))) { + if (!(mainsym=search("_main",-1,&alsyms)) && !(mainsym=search("__main",-1,&alsyms))) + fatal("_main not found"); + if (!nostub && !exestub) { + ovwri(0x0C,qlab_src(mainsym->value.splab)+hshift); + if (!!search("NO_SCREEN",-1,&defsyms)) + orwri(0x10,(1<<2)); + } + } + scan_unresolved(); + + /* finally, write the output to the file */ + if (nostub) { + if (!mainsym) + memmove(bin,bin+4,pos-4),pos-=4,hshift=-4; + else { + #ifdef PC + bin[0]=0x60,bin[1]=0x00; + bin[2]=(unsigned char)((qlab_src(mainsym->value.splab)-2)>>8); + bin[3]=(unsigned char)((qlab_src(mainsym->value.splab)-2)); + #else + *(short *)bin=0x6000; + *(short *)(bin+2)=qlab_src(mainsym->value.splab)-2; + #endif + hshift=0; + } + put_align2(); + wrt2(0); + { + RTYPE *r=&reloc_tab; + REF *p=r->r0; + while (p) { + unsigned int x,*a=p->r; int n; + if ((p=p->nxt)) { + n=N_REF; while (n--) { + #ifdef PC + { short z=bin[(x=*a++)+2+hshift]<<8; + z+=bin[x+3+hshift]+hshift; + wrt2(z); + } + #else + wrt2(*(unsigned short *)(bin+(x=*a++)+2+hshift)+hshift); + #endif + if (*(unsigned short *)(bin+x+hshift)!=0) + uerrc("invalid _nostub relocation"); + *(unsigned short *)(bin+x+2+hshift)=0; + wrt2((unsigned short)(x+hshift)); + } + } else + while ((x=*a++)) { + #ifdef PC + { short z=bin[x+2+hshift]<<8; + z+=bin[x+3+hshift]+hshift; + wrt2(z); + } + #else + wrt2(*(unsigned short *)(bin+x+2+hshift)+hshift); + #endif + if (*(unsigned short *)(bin+x+hshift)!=0) + uerrc("invalid _nostub relocation"); + *(unsigned short *)(bin+x+2+hshift)=0; + wrt2((unsigned short)(x+hshift)); + } + } + } + wrt1((char)0xF3); + rel_global(); + #ifndef PC + fwrite(bin,1,pos,output); + #endif +#ifdef EXE_OUT + } else if (exestub) { +#ifdef TWIN_COMPILE + if (twinc_necessary) { + rel_global(); + goto close_it; // don't lose time compressing... + } else { +#endif + #define EXE_END -1 + #define EXE_PROGRELOC 0 + #define EXE_BSSRELOC 1 + #define EXE_ROMRELOC 2 + #define EXE_ROMRELOC_NOJSR (0x100|EXE_ROMRELOC) + EXE_ITEM *exe_data=calloc(6000,sizeof(EXE_ITEM)); /* 12 kb */ + EXE_ITEM *exe_ptr=exe_data; + int exe_num; + if (!exe_data) + fatal("Memory"); + memmove(bin,bin+4,pos-4),pos-=4; + { + RTYPE *r=&reloc_tab; + REF *p=r->r0; + while (p) { + unsigned int x,*a=p->r; int n; + if ((p=p->nxt)) { + n=N_REF; while (n--) { + exe_ptr->t=EXE_PROGRELOC; + exe_ptr->loc=(*a++)-4; + exe_ptr++; + } + } else + while ((x=*a++)) { + exe_ptr->t=EXE_PROGRELOC; + exe_ptr->loc=x-4; + exe_ptr++; + } + } + } + { + FUNC *f=rom_funcs; + while (f) { + RTYPE *r=&f->rt; + REF *p=r->r0; + while (p) { + unsigned int x,*a=p->r; int n; + if ((p=p->nxt)) { + n=N_REF; while (n--) { + exe_ptr->t=EXE_ROMRELOC; + exe_ptr->loc=(*a++)-4; + if (*(long *)(bin+exe_ptr->loc)) + fatal("Invalid ROM_CALL"); + bin[exe_ptr->loc+2]=f->f>>8; + bin[exe_ptr->loc+3]=f->f&255; + if (bin[exe_ptr->loc-2]==0x4e + && bin[exe_ptr->loc-1]==0xb9) + exe_ptr->loc-=2; + else bin[exe_ptr->loc+2]|=0x80,exe_ptr->t=EXE_ROMRELOC_NOJSR; + exe_ptr++; + } + } else + while ((x=*a++)) { + exe_ptr->t=EXE_ROMRELOC; + exe_ptr->loc=x-4; + if (*(long *)(bin+exe_ptr->loc)) + fatal("Invalid ROM_CALL"); + bin[exe_ptr->loc+2]=f->f>>8; + bin[exe_ptr->loc+3]=f->f&255; + if (bin[exe_ptr->loc-2]==0x4e + && bin[exe_ptr->loc-1]==0xb9) + exe_ptr->loc-=2; + else bin[exe_ptr->loc+2]|=0x80,exe_ptr->t=EXE_ROMRELOC_NOJSR; + exe_ptr++; + } + } + f=f->nxt; + } + } + exe_ptr->t=-1; exe_ptr->loc=pos; exe_ptr++; + exe_num=exe_ptr-exe_data; + qsort(exe_data,exe_num,sizeof(EXE_ITEM),exe_compare); + { + long relocated_size; + unsigned short last_pos=0; unsigned char *ptr=bin,*out=bin; + char *reloc_ptr=(char *)exe_data,*last_esc=NULL; + int last_esc_num=0; + int i=exe_num; exe_ptr=exe_data; + while (i--) { + unsigned char *dest_ptr=bin+exe_ptr->loc; + unsigned short delta; short type; +#ifdef PC +#define g16(p) (p+=2,(p[-2]<<8)+p[-1]) +#define rd16(p) ((p[0]<<8)+p[1]) +#define w16(p,v) (*p++=(v)>>8,*p++=(v)&255,(void)0) +#else +#define g16(p) (*((int *)p)++) +#define rd16(p) (*((int *)p)) +#define w16(p,v) (g16(p)=(v)) +#endif + while (ptr =dest_ptr) break; + w16(out,rd16(ptr)+((char *)ptr-(char *)bin)); + ptr+=2; + } + } + delta=(exe_ptr->loc-last_pos)+2; + last_pos=exe_ptr->loc; + if ((delta&1)) + uerrc("invalid relocation offset"); + delta>>=1; + switch ((type=exe_ptr->t)) { // we *NEED* to save exe_ptr->t as it will be lost + case EXE_PROGRELOC: + if (g16(ptr)) + uerrc("invalid _nostub relocation"); + w16(out,rd16(ptr)-4); // parameters to w16 can't have side-fx... + ptr+=2; + last_pos+=4; + break; + case EXE_ROMRELOC: + ptr+=4; + w16(out,rd16(ptr)); // parameters to w16 can't have side-fx... + ptr+=2; + last_pos+=6; + break; + case EXE_ROMRELOC_NOJSR: + ptr+=2; + w16(out,rd16(ptr)); // parameters to w16 can't have side-fx... + ptr+=2; + last_pos+=4; + break; + } + if (delta<128) + *reloc_ptr++=delta&255; + else *reloc_ptr++=128|(delta>>8),*reloc_ptr++=delta&255; + if (!last_esc_num--) + last_esc=reloc_ptr,*reloc_ptr++=0,last_esc_num=3; + if (type IS_INVALID) { + *reloc_ptr++=0; + break; + } + (*last_esc)|=type<<(last_esc_num<<1); + exe_ptr++; + } + rel_global(); + exe_num=reloc_ptr-(char*)exe_data; + *reloc_ptr=0; /* (same remark as below...) */ + reloc_ptr=realloc(exe_data,exe_num+1); /* we don't know if we will need padding... */ + relocated_size=pos; + pos=out-bin; + bin=realloc(bin,pos); +#if 0 + { + unsigned int i; + for (i=0; i >8,header[3]=loader_offset&255; + *(long *)(header+4)=0; + } else { + #ifdef PC + const unsigned char header32[8]= + #else + memcpy(header,(char[]) + #endif + {0x41,0xFA,0x7F,0xF2,0x4E,0xE8,0x80,0x0C} + #ifdef PC + ; memcpy(header,header32, 8); + #else + , 8); + #endif + loader_offset+=(0x800C-2); + header[6]=loader_offset>>8,header[7]=loader_offset&255; + loader_offset-=(0x800C-2); // restore it for future use + } + bin=realloc(bin,8+12+pos+exe_num+(bss_tab.r?exeloadersize_bss:exeloadersize_nobss)); + if (!bin) + fatal("Memory"); + memmove(bin+8+12,bin,pos); + memcpy(bin,header,8); + exe_hdr[2]=pos>>8,exe_hdr[3]=pos&255; + exe_hdr[5]=(char)((relocated_size>>16)&255), + exe_hdr[6]=(char)((relocated_size>>8)&255), + exe_hdr[7]=(char)(relocated_size&255); + if (bss_tab.r) + fatal("BSS in exes are not implemented"); + memcpy(bin+8,exe_hdr,12); + memcpy(bin+8+12+pos,reloc_ptr,exe_num); + free(reloc_ptr); + memcpy(bin+8+12+pos+exe_num,bss_tab.r?exeloader_bss:exeloader_nobss, + bss_tab.r?exeloadersize_bss:exeloadersize_nobss); +#ifdef PC + if (verbose) { + msg2("RAM required during execution : %5u bytes\n",(unsigned int)relocated_size); + msg2("Memory required for EXE program : %5u bytes\n",8+12+pos+exe_num); + msg2("Memory required for EXE loader : %5u bytes\n",bss_tab.r?exeloadersize_bss:exeloadersize_nobss); + } +#endif + pos=8+12+pos+exe_num+(bss_tab.r?exeloadersize_bss:exeloadersize_nobss); + bin[pos-3]=(loader_offset+22+2)>>8,bin[pos-2]=(loader_offset+22+2)&255; +#ifdef PC + if (verbose) + msg2("Total program size : %5u bytes\n",pos); +#endif + } + } + #ifndef PC + fwrite(bin,1,pos,output); + #endif +#ifdef TWIN_COMPILE + } +#endif +#endif + } else { + rel_global(); + put_align2(); + wrt2(0); + wrt1((char)0xF3); + #ifdef PC + if (!(bin=realloc(bin,bin_size+=hshift))) + fatal("Memory"); + memmove(bin+hshift+4,bin+4,pos-4); + memcpy(bin,hdr,hshift+4); + pos+=hshift; + #else + fwrite(hdr,1,hshift+4,output); + fwrite(bin+4,1,pos-4,output); + #endif + free(hdr); + } +#ifdef OBJ_OUT + } else { + unsigned int len; + int j; + if (pos&1) + wrt1(0); + len=pos-4; + + /* reloc table */ + hshift=-4; + write_reloc(1); + + /* export table */ + j=N_HASH; + while (j--) { + SYM *sp = gsyms.h[j].head; + while (sp) { + if ((sp->storage_class == sc_external && sp->used) || + (sp->storage_class == sc_global && sp->value.splab)) { +#ifdef PC + if (!lab_src(sp->value.splab)) + fatal("UNDEF LABEL"); // should this happen ? +#endif + wrt2(lab_src(sp->value.splab)-2/*fix offset for object format*/); + } + sp = sp->next; + } + } + wrt2(0); + j=N_HASH; + while (j--) { + SYM *sp = gsyms.h[j].head; + while (sp) { + if ((sp->storage_class == sc_external && sp->used) || + (sp->storage_class == sc_global && sp->value.i != -1)) { + char *s=sp->name; + do + wrt1(*s); + while (*s++); + } + sp = sp->next; + } + } + if (pos&1) + wrt1(0); + + /* import table */ + { + GTAB *t=glb_tab; + while (t) { + REF **r=t->r; int m=N_TAB; + while (m--) { + REF *q; + if ((q=*r++)) { + while (q) { + unsigned int p,*a=q->r; + int n=N_REF; + while (n--) { + if (!(p=*a++)) + goto ref_done; + if (p&1) + fatal("Negative reloc in object output"); + // warning, this is a 16-bit reloc, but we have to store it as a 32-bit one + #define offs_convert(p) (p-2/*since 16->32 bit*/-4/*convert bin[] offsets to final object offsets*/) + if (!offs_convert(p)) + fatal("Word reloc at beginning"); + wrt2(offs_convert(p)); + #undef offs_convert + } + q=q->nxt; + } + ref_done: + wrt2(0); + } + } + t=t->nxt; + } + } + wrt2(0); + { + GTAB *t=glb_tab; int l=0x8000; + while (t) { + REF **r=t->r; int m=N_TAB; + while (m--) { + if (*r++) { + char *s=unres_name(l); + do + wrt1(*s); + while (*s++); + } + l++; + } + t=t->nxt; + } + } + if (pos&1) + wrt1(0); + wrt2(0); // leave space for future BSS extension + hdr=bin; // hack pawa =) + ovwri(0x0,pos-4); + ovwri(0x2,len+2); + #ifndef PC + wrt1(0); + wrt1('E'); + wrt1('X'); + wrt1('T'); + wrt1(0); + wrt1(0xF8); + fwrite(bin,1,pos,output); + #endif + } +#endif + #ifdef PC + { +#ifdef OBJ_OUT + if (!object) { +#endif + char *extensions[]={".89z",".9xz",".v2z"}; + for (calc=0;calc<3;calc++) { + if (calctype_used[calc]) { + unsigned int tifilelen; + extern char *calcfolder; + char *tifile=create_ti_file(calc,0x21,calcname,calcfolder,bin,pos,&tifilelen); + char *buffer; FILE *fp; + buffer=alloca(strlen(outputname)+strlen(extensions[calc])+1); + strcpy(buffer,outputname); + strcat(buffer,extensions[calc]); + if (!(fp=fopen(buffer,"wb"))) + fatal("Could not open output file."); + fwrite(tifile,1,tifilelen,fp); + free(tifile); + fclose(fp); + } + } +#ifdef OBJ_OUT + } else { + char buffer[100]; FILE *fp; + strcpy(buffer,calcname); + strcat(buffer,".ext"); + if (!(fp=fopen(buffer,"wb"))) + fatal("Could not open output file."); + fwrite(bin,1,pos,fp); + fclose(fp); + } +#endif + } + #endif + #ifdef TWIN_COMPILE + close_it: + #endif + free(bin); + bin=0; + } +} + +void bin_chk(unsigned int pos) { + while (bin_size >N_TAB_LOG; + LTAB *p=local(n)?loc_tab:(LTAB *)glb_tab,*o; + debugf("lab_set(%x,%x)\n",n,v); + global_flag+=n&0x8000; + if (!p) { + if (local(n)) + loc_tab=p=(LTAB *)xalloc(sizeof(LTAB),_TAB); + else glb_tab=(GTAB *)(p=(LTAB *)xalloc(sizeof(GTAB),_TAB)); + } + while (i--) + if (!(p=(o=p)->nxt)) + o->nxt=p=(LTAB *)xalloc(local(n)?sizeof(LTAB):sizeof(GTAB),_TAB); + global_flag&=0x7FFF; +#ifndef PC + n&=N_TAB-1; + p->t[n]=v; +#else + i=n&(N_TAB-1); + p->t[i]=v; +#endif +} + +#ifdef PC +/* that's what we use if we want the storage to be persistent, even if we call it from a + * temp_mem location + */ +void *xallocnt(int s,int m) { + void *p; + temp_local++; + p=xalloc(s,m); + temp_local--; + return p; +} +/* xallocnt in global mode */ +void *xallocntg(int s,int m) { + void *p; + global_flag++; + p=xallocnt(s,m); + global_flag--; + return p; +} +#else +#define xallocnt(s,m) _xallocnt(s) +void *_xallocnt(int s) { + void *p; + temp_local++; + p=xalloc(s,0); + temp_local--; + return p; +} +#define xallocntg(s,m) _xallocnt(s) +void *_xallocntg(int s) { + void *p; + global_flag++; + p=xallocnt(s,0); + global_flag--; + return p; +} +#endif +unsigned int lab_src(int n) { + int i=(n&0x7FFF)>>N_TAB_LOG; + LTAB *p=local(n)?loc_tab:(LTAB *)glb_tab,*o; + debugfq("lab_src(%x)",n); + global_flag+=n&0x8000; + if (!p) { + if (local(n)) + loc_tab=p=(LTAB *)xallocnt(sizeof(LTAB),_TAB); + else glb_tab=(GTAB *)(p=(LTAB *)xallocntg(sizeof(GTAB),_TAB)); + } + while (i--) + if (!(p=(o=p)->nxt)) + o->nxt=p=(LTAB *)(local(n)?xallocnt(sizeof(LTAB),_TAB):xallocntg(sizeof(GTAB),_TAB)); + global_flag&=0x7FFF; + n&=N_TAB-1; + debugf("=%x\n",p->t[n]); + return p->t[n]; +} + +RTYPE **xt_find(int n) { + int i=(n=(int)((short)~n))>>N_TAB_LOG; + XTAB *p=ext_tab,*o; + global_flag++; + if (!p) + ext_tab=p=(XTAB *)xalloc(sizeof(XTAB),_TAB); + while (i--) + if (!(p=(o=p)->nxt)) + o->nxt=p=(XTAB *)xalloc(sizeof(XTAB),_TAB); + global_flag--; + n&=N_TAB-1; + return &p->t[n]; +} + +int *exp_find(int n) { + int i=n>>N_TAB_LOG; + LTAB *p=exp_tab,*o; + global_flag++; + if (!p) + exp_tab=p=(LTAB *)xalloc(sizeof(LTAB),_TAB); + while (i--) + if (!(p=(o=p)->nxt)) + o->nxt=p=(LTAB *)xalloc(sizeof(LTAB),_TAB); + global_flag--; + n&=N_TAB-1; + return (int *)&p->t[n]; +} + +/*void loc_clear() { + LTAB *p=loc_tab,*o; + while (p) { + memset(p->t,0,sizeof(p->t)); + p=p->nxt; + } +}*/ + +unsigned int qlab_src(int n) { + int i=(n&0x7FFF)>>N_TAB_LOG; + LTAB *p=local(n)?loc_tab:(LTAB *)glb_tab; + n&=N_TAB-1; + while (i--) p=p->nxt; + return p->t[n]; +} + +REF *ref_add(REF *r,unsigned int v) { + unsigned int *a; + debugf("ref_add(%lx,%x)\n",r,v); + a=r->r; + while (*a++); + if (a>(unsigned int *)&r->nxt) { + global_flag++; + (r=r->nxt=(REF *)xalloc(sizeof(REF),_REF+REF_ADD))->r[0]=v; + global_flag--; + } else a[-1]=v; + return r; +} + +REF **glb_ref(int n) { + int i=(n&0x7FFF)>>N_TAB_LOG; + GTAB *p=glb_tab; + n&=N_TAB-1; + while (i--) + p=p->nxt; + return &p->r[n]; +} + +void lab_add_ref(int n,unsigned int r) { + int i=(n&0x7FFF)>>N_TAB_LOG; + GTAB *p=glb_tab; REF **ro; + debugf("lab_add_r(%x,%x)\n",n,r); +#ifndef PC +// asm("0: jbra 0b"); +#endif + if (local(n)) + uerrc2("local label not found: '%s'",unres_name(n)); + global_flag++; + n&=N_TAB-1; + while (i--) + p=p->nxt; + ro=&p->r[n]; + if (!*ro) + *ro=(REF *)xalloc(sizeof(REF),_REF+LAB_ADD_REF); + while ((*ro)->nxt) + ro=&(*ro)->nxt; + global_flag--; + ref_add(*ro,r); +} +void rt_add_ref(RTYPE *rt,unsigned int r) { // effectively appends reloc to reloc table + debugf("rt_add_r(%lx,%x)\n",rt,r); + if (!rt->r) { + global_flag++; + rt->r0=rt->r=(REF *)xalloc(sizeof(REF),_REF+RT_ADD_REF); + global_flag--; + } + rt->r=ref_add(rt->r,r); +} +FUNC *func_search(FUNC **f0,unsigned int f) { + while (*f0) + if ((*f0)->f==f) break; + else f0=&(*f0)->nxt; + if (*f0) return *f0; + global_flag++; + *f0=(FUNC *)xalloc(sizeof(FUNC),_RT); + global_flag--; + (*f0)->f=f; + return *f0; +} + +typedef struct gv_ret { + long i; + int ir,xr,tr; // Internal/eXternal/Total Relocation count +} GV; +int get_value(struct enode *ep,GV *r,unsigned int rp,int m) { + int lab; unsigned int p; + r->ir=0; r->xr=0; + gv_restart: + switch (ep->nodetype) { + case en_autocon: + case en_icon: +#ifndef NOFLOAT +#ifndef PC + case en_fcon: +#endif +#endif + r->i=ep->v.i; + r->tr=0; + break; +#ifndef NOFLOAT +#ifdef PC +#ifndef BCDFLT + case en_fcon: + r->i=double2ffp(ep->v.f); + r->tr=0; + break; +#endif +#endif +#endif + case en_labcon: + case en_nacon: + lab=ep->v.enlab; + r->tr=1; + if (global(lab)) { + r->ir=1; + if (!(p=lab_src(lab))) { + if (rp) + lab_add_ref(lab,(rp+2)+m); + r->i=0; + return 1; + } else + r->i=p; + } else { + if (m) uerrc("negative external reference"); + r->i=0,r->xr=1; + if (rp) { + RTYPE *rt=*xt_find(lab); + if (((long)rt)&0x80000000) { // DIRTY, but no hidden bug possible (cf xalloc) + r->i=((long)rt)&0x7FFFFFFF; // BSS ref + rt_add_ref(&bss_tab,rp); + } else rt_add_ref(rt,rp); // lib/ROM ref + } + return 1; + } + break; + case en_add: + case en_sub: + { + GV a,b; + int res=get_value(ep->v.p[0],&a,rp,m); + res|=get_value(ep->v.p[1],&b,rp,ep->nodetype==en_sub?1-m:m); + r->xr=a.xr+b.xr; + r->tr=a.tr+b.tr; + if (ep->nodetype==en_sub) { + if (b.xr) + uerrc("negative external reference"); + r->i=a.i-b.i,r->ir=a.ir-b.ir; + } else + r->i=a.i+b.i,r->ir=a.ir+b.ir; + return res; + } + break; + case en_uminus: + m=1-m; + ep=ep->v.p[0]; + goto gv_restart; + default: + uerrc("invalid expression"); + } + return 0; +} +int involved_lab(struct enode *ep) { + gv_restart: + switch (ep->nodetype) { + case en_autocon: + case en_icon: +#ifndef NOFLOAT +#ifdef PC + case en_fcon: +#endif +#endif + return -1; + case en_labcon: + case en_nacon: + return ep->v.enlab; + case en_add: + case en_sub: + return max(involved_lab(ep->v.p[0]),involved_lab(ep->v.p[1])); + case en_uminus: + ep=ep->v.p[0]; + goto gv_restart; + default: + uerrc("invalid expression"); + } + return -1; +} + +xstatic int rel CGLOB, is_long CGLOB; +long get_long(struct enode *ep,unsigned int rp) { + GV v; + get_value(ep,&v,rp,0); + if (v.ir) { + rt_add_ref(&reloc_tab,rp); + if (v.ir!=1) + uerr(ERRA_INVALIDREL); + } + rel=v.ir+v.xr; + return v.i; +} +short get_pcword(struct enode *ep,unsigned int rp) { + GV v; + int no_check=get_value(ep,&v,rp-2,0); + if (v.ir!=1 || v.xr) + uerr(ERRA_INVALIDREL); + if (!no_check) { + v.i -= rp; + if (v.i>32767L || v.i<-32768L) +#ifdef TWIN_COMPILE + { + if (!twinc_necessary) uwarn("twin compilation required"); + twinc_necessary=1; + *twinc_info++=involved_lab(ep); + *twinc_info++=rp; + } +#else + uerrc("PC-relative mode not allowed here"); +#endif +// v.i += rp; + return (short)v.i; + } else + return (short)v.i-(short)rp; +} +short get_word(struct enode *ep,unsigned int rp,int sign) { + GV v; + int no_check=get_value(ep,&v,rp-2,0); + if (v.ir || v.xr) + uerr(ERRA_INVALIDREL); + /* otherwise this would bug with myval&0xFFFF7FFF which is converted to and.w */ + if (!no_check && (v.i>(sign?32767L:65535L) || v.i<(sign?-32768L:-65535L))) +// if (!no_check && (v.i>(sign?32767L:65535L) || v.i<-32768L)) + uerrc("value can't fit in a word"); + return (short)v.i; +} +long get_offs(struct enode *ep,unsigned int rp) { + GV v; int l=0; + get_value(ep,&v,0,0); + if (v.ir || v.xr) + l=1; + if (v.i>32767L || v.i<-32768L) + l=1; + if ((is_long=l)) + return get_long(ep,rp); + else return get_word(ep,rp,1); +} +unsigned char get_byte(struct enode *ep) { + GV v; + get_value(ep,&v,0,0); + if (v.tr) + uerr(ERRA_INVALIDREL); + if ((unsigned long)(((unsigned long)v.i)+128)>255) + uerrc("value can't fit in a byte"); + return (unsigned char)v.i; +} +unsigned short get_quick(struct enode *ep) { + GV v; + get_value(ep,&v,0,0); + if (v.tr) + uerr(ERRA_INVALIDREL); + if ((unsigned long)(((unsigned long)v.i)-1)>=8) + uerrc("value can't fit in a quick constant"); + if (v.i==8) + v.i=0; + return (unsigned short)v.i; +} + +enum { + oi_move=1, + oi_moveq=oi_move+8, + oi_clr=oi_moveq+1, + oi_lea=oi_clr+1, + oi_add=oi_lea+1, + oi_addi=oi_add+4, + oi_addq=oi_addi+1, + oi_sub=oi_addq+1, + oi_subi=oi_sub+4, + oi_subq=oi_subi+1, + oi_muls=oi_subq+1, + oi_mulu=oi_muls+1, + oi_divs=oi_mulu+1, + oi_divu=oi_divs+1, + oi_and=oi_divu+1, + oi_andi=oi_and+3, + oi_or=oi_andi+1, + oi_ori=oi_or+3, + oi_eor=oi_ori+1, + oi_eori=oi_eor+2, + oi_lsl=oi_eori+1, + oi_lsr=oi_lsl+3, + oi_jmp=oi_lsr+3, + oi_jsr=oi_jmp+1, + oi_movem=oi_jsr+1, + oi_rts=oi_movem+3, + oi_bra=oi_rts+1, + oi_bsr=oi_bra+1, + oi_beq=oi_bsr+1, + oi_bne=oi_beq+1, + oi_bhs=oi_bne+1, + oi_bge=oi_bhs+1, + oi_bhi=oi_bge+1, + oi_bgt=oi_bhi+1, + oi_bls=oi_bgt+1, + oi_ble=oi_bls+1, + oi_blo=oi_ble+1, + oi_blt=oi_blo+1, + oi_tst=oi_blt+1, + oi_ext=oi_tst+1, + oi_swap=oi_ext+1, + oi_neg=oi_swap+1, + oi_not=oi_neg+1, + oi_cmp=oi_not+1, + oi_link=oi_cmp+5, + oi_unlk=oi_link+1, + oi_label=oi_unlk+1, + oi_pea=oi_label+0, + oi_cmpi=oi_pea+1, + oi_dbra=oi_cmpi+1, + oi_asr=oi_dbra+1, + oi_bset=oi_asr+3, + oi_bclr=oi_bset+4, + oi_bchg=oi_bclr+4, + _oi_asm=oi_bchg+4, + _oi_adj=_oi_asm+0, +#ifndef ASM + __oi_end=_oi_adj+0 +#endif +#ifdef ASM + /* ASM-only */ + oi_asl=_oi_adj+0, + oi_rol=oi_asl+3, + oi_ror=oi_rol+3, + oi_roxl=oi_ror+3, + oi_roxr=oi_roxl+3, + oi_btst=oi_roxr+3, + oi_exg=oi_btst+4, + oi_dc=oi_exg+4, + oi_ds=oi_dc+1, + oi_dcb=oi_ds+1, + oi_bvs=oi_dcb+1, + oi_bvc=oi_bvs+1, + oi_bpl=oi_bvc+1, + oi_bmi=oi_bpl+1, + oi_trap=oi_bmi+1, + oi_negx=oi_trap+1, + oi_addx=oi_negx+1, + oi_subx=oi_addx+2, + oi_chk=oi_subx+2, + oi_even=oi_chk+1, + oi_dbeq=oi_even+1, + oi_dbne=oi_dbeq+1, +#ifndef LIGHT_DBXX_AND_SXX + oi_dbhs=oi_dbne+1, + oi_dbge=oi_dbhs+1, + oi_dbhi=oi_dbge+1, + oi_dbgt=oi_dbhi+1, + oi_dbls=oi_dbgt+1, + oi_dble=oi_dbls+1, + oi_dblo=oi_dble+1, + oi_dblt=oi_dblo+1, + oi_dbvs=oi_dblt+1, + oi_dbvc=oi_dbvs+1, + oi_dbpl=oi_dbvc+1, + oi_dbmi=oi_dbpl+1, + oi_st=oi_dbmi+1, + oi_sf=oi_st+1, + oi_seq=oi_sf+1, + oi_sne=oi_seq+1, + oi_shs=oi_sne+1, + oi_sge=oi_shs+1, + oi_shi=oi_sge+1, + oi_sgt=oi_shi+1, + oi_sls=oi_sgt+1, + oi_sle=oi_sls+1, + oi_slo=oi_sle+1, + oi_slt=oi_slo+1, + oi_svs=oi_slt+1, + oi_svc=oi_svs+1, + oi_spl=oi_svc+1, + oi_smi=oi_spl+1, + oi_tas=oi_smi+1, + __oi_end=oi_tas+1 +#else + __oi_end=oi_dbne+1 +#endif +#endif +}; + +readonly unsigned char opi[_op_max+2]={ + oi_move, oi_moveq, oi_clr, oi_lea, oi_add, oi_addi, oi_addq, oi_sub, oi_subi, oi_subq, + oi_muls, oi_mulu, oi_divs, oi_divu, oi_and, oi_andi, oi_or, oi_ori, oi_eor, oi_eori, + oi_lsl, oi_lsr, oi_jmp, oi_jsr, oi_movem, + oi_rts, oi_bra, oi_bsr, oi_beq, oi_bne, oi_bhs, oi_bge, oi_bhi, + oi_bgt, oi_bls, oi_ble, oi_blo, oi_blt, oi_tst, oi_ext, oi_swap, oi_neg, oi_not, oi_cmp, + oi_link, oi_unlk, oi_label, oi_pea, oi_cmpi, oi_dbra, oi_asr, + oi_bset, oi_bclr, oi_bchg, _oi_asm, _oi_adj, +#ifdef ASM + /* ASM-only */ + oi_asl, oi_rol, oi_ror, oi_roxl, oi_roxr, oi_btst, oi_exg, oi_dc, oi_ds, oi_dcb, + oi_bvs, oi_bvc, oi_bpl, oi_bmi, oi_trap, oi_negx, oi_addx, oi_subx, oi_chk, oi_even, + oi_dbeq, oi_dbne, +#ifndef LIGHT_DBXX_AND_SXX + oi_dbhs, oi_dbge, oi_dbhi, oi_dbgt, oi_dbls, oi_dble, oi_dblo, oi_dblt,/* unsigned, signed */ + oi_dbvs, oi_dbvc, oi_dbpl, oi_dbmi, + oi_st, oi_sf, oi_seq, oi_sne, + oi_shs, oi_sge, oi_shi, oi_sgt, oi_sls, oi_sle, oi_slo, oi_slt, /* unsigned, signed */ + oi_svs, oi_svc, oi_spl, oi_smi, oi_tas, +#endif +#endif + __oi_end +}; + +typedef struct _opcode { + char impl,nargs,model,lenf; + unsigned short bo; + int a1,a2; +} OPCODE; +enum { + M_BASIC, M_BASICSWAPPED, M_BRANCH, M_DC, M_ALIGN +}; +enum { L_0=1<<0, L_1=1<<1, L_2=1<<2, L_4=1<<4 }; +enum { + A_DREG=0x1, + A_AREG=0x2, + A_MEM0=0x4, + A_MEM=0x84, + A_PCR=0x8, + A_IMM=0x10, + A_MASK1=0x20, + A_MASK2=0x40, + A_ADEC=0x80, + D_RAW2=0x0100, // |= %00000000 00000000 +WORD + D_RAW=0x0200, // |= %00000000 00000000 (+DAT) + D_LOW=0x0400, // |= %00000000 dddddddd + D_EA2=0x0800, // |= %0000nnnm mm000000 (+DAT) + D_SZ3=0x3000, // |= %00000000 0S000000 (argument-independent) + D_SZ2=0x1000, // |= %0000000S 00000000 (argument-independent) + D_SZ=0x2000, // |= %00000000 ss000000 (argument-independent) + D_Q=0x4000, // |= %0000qqq0 00000000 + D_EA=0x8000, // |= %00000000 00mmmnnn (+DAT) +}; +#define A_CCR A_MASK1 +#define A_SR A_MASK2 +#define A_USP A_MASK1 +/* we have to implement A_CCR and A_SR like that to avoid the use + * of a longword for flags... */ +#define A_SRC A_DREG|A_AREG|A_MEM|A_PCR|A_IMM +#define A_SRC2 A_DREG|A_MEM|A_PCR|A_IMM +#define A_DST A_DREG|A_AREG|A_MEM +#define A_DST2 A_DREG|A_MEM + +// for each enum(e_op) value : +readonly OPCODE ops[]={ + // op_label + {0}, + // op_move + {1,2,M_BASIC,L_2,0x3000,A_SRC|D_EA,A_DST|D_EA2}, // movea is in fact the same instruction + {1,2,M_BASIC,L_4,0x2000,A_SRC|D_EA,A_DST|D_EA2}, + {1,2,M_BASIC,L_1,0x1000,A_SRC2|D_EA,A_DST2|D_EA2}, // move.b does not accept aregs + {1,2,M_BASIC,L_2,0x44C0,A_SRC2|D_EA,A_CCR}, + {1,2,M_BASIC,L_2,0x46C0,A_SRC2|D_EA,A_SR}, + {1,2,M_BASIC,L_2,0x40C0,A_SR,A_DST2|D_EA}, + {1,2,M_BASIC,L_4,0x4E60,A_AREG|D_LOW,A_USP}, + {1,2,M_BASIC,L_4,0x4E68,A_USP,A_AREG|D_LOW}, + // op_moveq + {1,2,M_BASIC,L_0+L_4,0x7000,A_IMM|D_LOW,A_DREG|D_Q}, + // op_clr + {1,1,M_BASIC,L_1+L_2+L_4,0x4200,A_DST2|D_EA|D_SZ}, + // op_lea + {1,2,M_BASIC,L_0,0x41C0,A_MEM|A_PCR|D_EA,A_AREG|D_Q}, + // op_add + {1,2,M_BASIC,L_1+L_2+L_4,0xD000,A_SRC|D_EA|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0xD100,A_DREG|D_Q|D_SZ,A_MEM|D_EA}, + {1,2,M_BASIC, L_2+L_4,0xD0C0,A_SRC|D_EA|D_SZ2,A_AREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0x0600,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_addi + {1,2,M_BASIC,L_1+L_2+L_4,0x0600,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_addq + {1,2,M_BASIC,L_1+L_2+L_4,0x5000,A_IMM|D_Q|D_SZ,A_DST|D_EA}, + // op_sub + {1,2,M_BASIC,L_1+L_2+L_4,0x9000,A_SRC|D_EA|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0x9100,A_DREG|D_Q|D_SZ,A_MEM|D_EA}, + {1,2,M_BASIC, L_2+L_4,0x90C0,A_SRC|D_EA|D_SZ2,A_AREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0x0400,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_subi + {1,2,M_BASIC,L_1+L_2+L_4,0x0400,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_subq + {1,2,M_BASIC,L_1+L_2+L_4,0x5100,A_IMM|D_Q|D_SZ,A_DST|D_EA}, + // op_muls + {1,2,M_BASIC,L_2,0xC1C0,A_SRC2|D_EA,A_DREG|D_Q}, + // op_mulu + {1,2,M_BASIC,L_2,0xC0C0,A_SRC2|D_EA,A_DREG|D_Q}, + // op_divs + {1,2,M_BASIC,L_2,0x81C0,A_SRC2|D_EA,A_DREG|D_Q}, + // op_divu + {1,2,M_BASIC,L_2,0x80C0,A_SRC2|D_EA,A_DREG|D_Q}, + // op_and + {1,2,M_BASIC,L_1+L_2+L_4,0xC000,A_SRC2|D_EA|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0xC100,A_DREG|D_Q|D_SZ,A_MEM|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0x0200,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_andi + {1,2,M_BASIC,L_1+L_2+L_4,0x0200,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_or + {1,2,M_BASIC,L_1+L_2+L_4,0x8000,A_SRC2|D_EA|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0x8100,A_DREG|D_Q|D_SZ,A_MEM|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0x0000,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_ori + {1,2,M_BASIC,L_1+L_2+L_4,0x0000,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_eor + {1,2,M_BASIC,L_1+L_2+L_4,0xB100,A_DREG|D_Q|D_SZ,A_DST2|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0x0A00,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_eori + {1,2,M_BASIC,L_1+L_2+L_4,0x0A00,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_lsl + {1,2,M_BASIC,L_1+L_2+L_4,0xE108,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE128,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE3C0,A_MEM|D_EA}, + // op_lsr + {1,2,M_BASIC,L_1+L_2+L_4,0xE008,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE028,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE2C0,A_MEM|D_EA}, + // op_jmp + {1,1,M_BASIC,L_0,0x4EC0,A_MEM|A_PCR|D_EA}, + // op_jsr + {1,1,M_BASIC,L_0,0x4E80,A_MEM|A_PCR|D_EA}, + // op_movem - contains a little hack : default size is .l, so we separe L_4 from L_2. + // Uses M_BASICSWAPPED because when 'uses_link' is set, the link reg needs to be after + // the reg mask. + {1,2,M_BASIC,L_4,0x4880,A_MASK1|D_RAW|D_SZ3,A_MEM|D_EA}, /* LBUG : A_MEM&~POST_I */ + {1,2,M_BASIC,L_2,0x4880,A_MASK1|D_RAW|D_SZ3,A_MEM|D_EA}, /* LBUG : A_MEM&~POST_I */ + {1,2,M_BASICSWAPPED,L_2+L_4,0x4C80,A_MASK2|D_RAW,A_MEM0|D_EA|D_SZ3}, + // op_rts + {1,0,M_BASIC,L_0,0x4E75}, + // op_bra + {1,1,M_BRANCH,L_0+L_1+L_2,0x6000}, + // op_bsr + {1,1,M_BRANCH,L_0+L_1+L_2,0x6100}, + // op_beq + {1,1,M_BRANCH,L_0+L_1+L_2,0x6700}, + // op_bne + {1,1,M_BRANCH,L_0+L_1+L_2,0x6600}, + // op_bhs + {1,1,M_BRANCH,L_0+L_1+L_2,0x6400}, + // op_bge + {1,1,M_BRANCH,L_0+L_1+L_2,0x6C00}, + // op_bhi + {1,1,M_BRANCH,L_0+L_1+L_2,0x6200}, + // op_bgt + {1,1,M_BRANCH,L_0+L_1+L_2,0x6E00}, + // op_bls + {1,1,M_BRANCH,L_0+L_1+L_2,0x6300}, + // op_ble + {1,1,M_BRANCH,L_0+L_1+L_2,0x6F00}, + // op_blo + {1,1,M_BRANCH,L_0+L_1+L_2,0x6500}, + // op_blt + {1,1,M_BRANCH,L_0+L_1+L_2,0x6D00}, + // op_tst + {1,1,M_BASIC,L_1+L_2+L_4,0x4A00,A_DST2|D_EA|D_SZ}, + // op_ext + {1,1,M_BASIC,L_2+L_4,0x4880,A_DREG|D_EA|D_SZ3}, + // op_swap + {1,1,M_BASIC,L_4,0x4840,A_DREG|D_EA}, + // op_neg + {1,1,M_BASIC,L_1+L_2+L_4,0x4400,A_DST2|D_EA|D_SZ}, + // op_not + {1,1,M_BASIC,L_1+L_2+L_4,0x4600,A_DST2|D_EA|D_SZ}, + // op_cmp + {1,2,M_BASIC,L_1+L_2+L_4,0xB000,A_SRC2|D_EA|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC, L_2+L_4,0xB000,A_AREG|D_EA|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC, L_2+L_4,0xB0C0,A_SRC|D_EA|D_SZ2,A_AREG|D_Q}, +/* {1,2,M_BASIC, L_2 ,0xB100,A_SRC2|D_EA|D_SZ,A_AREG|D_Q}, + {1,2,M_BASIC, L_4,0xB1C0,A_SRC2|D_EA|D_SZ,A_AREG|D_Q},*/ + {1,2,M_BASIC,L_1+L_2+L_4,0x0C00,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xB108,A_MEM0|D_LOW|D_SZ,A_MEM0|D_Q}, // hum; other modes than A_AINC will generate an internal error (#8451/8452) + // op_link + {1,2,M_BASIC,L_2,0x4E50,A_AREG|D_LOW,A_IMM|D_RAW}, + // op_unlk + {1,1,M_BASIC,L_2,0x4E58,A_AREG|D_LOW}, + // op_pea + {1,1,M_BASIC,L_0,0x4840,A_MEM|A_PCR|D_EA}, + // op_cmpi + {1,2,M_BASIC,L_1+L_2+L_4,0x0C00,A_IMM|D_RAW|D_SZ,A_DST2|D_EA}, + // op_dbra + {1,2,M_BRANCH,L_2,0x51C8,A_DREG|D_LOW}, + // op_asr + {1,2,M_BASIC,L_1+L_2+L_4,0xE000,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE020,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE0C0,A_MEM|D_EA}, + // op_bset + {1,2,M_BASIC,L_0+L_1,0x08C0,A_IMM|D_RAW2,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x08C0,A_IMM|D_RAW2,A_DREG|D_EA}, + {1,2,M_BASIC,L_0+L_1,0x01C0,A_DREG|D_Q,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x01C0,A_DREG|D_Q,A_DREG|D_EA}, + // op_bclr + {1,2,M_BASIC,L_0+L_1,0x0880,A_IMM|D_RAW2,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x0880,A_IMM|D_RAW2,A_DREG|D_EA}, + {1,2,M_BASIC,L_0+L_1,0x0180,A_DREG|D_Q,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x0180,A_DREG|D_Q,A_DREG|D_EA}, + // op_bchg + {1,2,M_BASIC,L_0+L_1,0x0840,A_IMM|D_RAW2,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x0840,A_IMM|D_RAW2,A_DREG|D_EA}, + {1,2,M_BASIC,L_0+L_1,0x0140,A_DREG|D_Q,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x0140,A_DREG|D_Q,A_DREG|D_EA}, +#ifdef ASM + /* ASM-only */ + // op_asl + {1,2,M_BASIC,L_1+L_2+L_4,0xE100,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE120,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE1C0,A_MEM|D_EA}, + // op_rol + {1,2,M_BASIC,L_1+L_2+L_4,0xE118,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE138,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE7C0,A_MEM|D_EA}, + // op_ror + {1,2,M_BASIC,L_1+L_2+L_4,0xE018,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE038,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE6C0,A_MEM|D_EA}, + // op_roxl + {1,2,M_BASIC,L_1+L_2+L_4,0xE110,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE130,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE5C0,A_MEM|D_EA}, + // op_roxr + {1,2,M_BASIC,L_1+L_2+L_4,0xE010,A_IMM|D_Q|D_SZ,A_DREG|D_EA}, + {1,2,M_BASIC,L_1+L_2+L_4,0xE030,A_DREG|D_Q|D_SZ,A_DREG|D_EA}, + {1,1,M_BASIC,L_2,0xE4C0,A_MEM|D_EA}, + // op_btst + {1,2,M_BASIC,L_0+L_1,0x0800,A_IMM|D_RAW2,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x0800,A_IMM|D_RAW2,A_DREG|D_EA}, + {1,2,M_BASIC,L_0+L_1,0x0100,A_DREG|D_Q,A_MEM|D_EA}, + {1,2,M_BASIC,L_0+L_4,0x0100,A_DREG|D_Q,A_DREG|D_EA}, + // op_exg + {1,2,M_BASIC,L_0+L_4,0xC140,A_DREG|D_LOW,A_DREG|D_Q}, + {1,2,M_BASIC,L_0+L_4,0xC148,A_AREG|D_LOW,A_AREG|D_Q}, + {1,2,M_BASIC,L_0+L_4,0xC188,A_AREG|D_LOW,A_DREG|D_Q}, + {1,2,M_BASIC,L_0+L_4,0xC188,A_DREG|D_Q,A_AREG|D_LOW}, + // op_dc + {1,1,M_DC,0,-1}, + // op_ds + {1,1,M_DC,0,0}, + // op_dcb + {1,2,M_DC,0,1}, + // op_bvs + {1,1,M_BRANCH,L_0+L_1+L_2,0x6900}, + // op_bvc + {1,1,M_BRANCH,L_0+L_1+L_2,0x6800}, + // op_bpl + {1,1,M_BRANCH,L_0+L_1+L_2,0x6A00}, + // op_bmi + {1,1,M_BRANCH,L_0+L_1+L_2,0x6B00}, + // op_trap + {1,1,M_BASIC,L_0,0x4E40,A_IMM|D_LOW}, + // op_negx + {1,1,M_BASIC,L_1+L_2+L_4,0x4000,A_DST2|D_EA|D_SZ}, + // op_addx + {1,2,M_BASIC,L_1+L_2+L_4,0xD100,A_DREG|D_LOW|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0xD108,A_ADEC|D_LOW|D_SZ,A_ADEC|D_Q}, + // op_subx + {1,2,M_BASIC,L_1+L_2+L_4,0x9100,A_DREG|D_LOW|D_SZ,A_DREG|D_Q}, + {1,2,M_BASIC,L_1+L_2+L_4,0x9108,A_ADEC|D_LOW|D_SZ,A_ADEC|D_Q}, + // op_chk + {1,2,M_BASIC,L_2,0x4180,A_SRC2|D_EA,A_DREG|D_Q}, + // op_even + {1,0,M_ALIGN,L_0,2}, + // op_dbeq + {1,2,M_BRANCH,L_2,0x57C8,A_DREG|D_LOW}, + // op_dbne + {1,2,M_BRANCH,L_2,0x56C8,A_DREG|D_LOW}, +#ifndef LIGHT_DBXX_AND_SXX + // op_dbhs + {1,2,M_BRANCH,L_2,0x54C8,A_DREG|D_LOW}, + // op_dbge + {1,2,M_BRANCH,L_2,0x5CC8,A_DREG|D_LOW}, + // op_dbhi + {1,2,M_BRANCH,L_2,0x52C8,A_DREG|D_LOW}, + // op_dbgt + {1,2,M_BRANCH,L_2,0x5EC8,A_DREG|D_LOW}, + // op_dbls + {1,2,M_BRANCH,L_2,0x53C8,A_DREG|D_LOW}, + // op_dble + {1,2,M_BRANCH,L_2,0x5FC8,A_DREG|D_LOW}, + // op_dblo + {1,2,M_BRANCH,L_2,0x55C8,A_DREG|D_LOW}, + // op_dblt + {1,2,M_BRANCH,L_2,0x5DC8,A_DREG|D_LOW}, + // op_dbvs + {1,2,M_BRANCH,L_2,0x59C8,A_DREG|D_LOW}, + // op_dbvc + {1,2,M_BRANCH,L_2,0x58C8,A_DREG|D_LOW}, + // op_dbpl + {1,2,M_BRANCH,L_2,0x5AC8,A_DREG|D_LOW}, + // op_dbmi + {1,2,M_BRANCH,L_2,0x5BC8,A_DREG|D_LOW}, + // op_st + {1,1,M_BASIC,L_1,0x50C0,A_DST2|D_EA}, + // op_sf + {1,1,M_BASIC,L_1,0x51C0,A_DST2|D_EA}, + // op_seq + {1,1,M_BASIC,L_1,0x57C0,A_DST2|D_EA}, + // op_sne + {1,1,M_BASIC,L_1,0x56C0,A_DST2|D_EA}, + // op_shs + {1,1,M_BASIC,L_1,0x54C0,A_DST2|D_EA}, + // op_sge + {1,1,M_BASIC,L_1,0x5CC0,A_DST2|D_EA}, + // op_shi + {1,1,M_BASIC,L_1,0x52C0,A_DST2|D_EA}, + // op_sgt + {1,1,M_BASIC,L_1,0x5EC0,A_DST2|D_EA}, + // op_sls + {1,1,M_BASIC,L_1,0x53C0,A_DST2|D_EA}, + // op_sle + {1,1,M_BASIC,L_1,0x5FC0,A_DST2|D_EA}, + // op_slo + {1,1,M_BASIC,L_1,0x55C0,A_DST2|D_EA}, + // op_slt + {1,1,M_BASIC,L_1,0x5DC0,A_DST2|D_EA}, + // op_svs + {1,1,M_BASIC,L_1,0x59C0,A_DST2|D_EA}, + // op_svc + {1,1,M_BASIC,L_1,0x58C0,A_DST2|D_EA}, + // op_spl + {1,1,M_BASIC,L_1,0x5AC0,A_DST2|D_EA}, + // op_smi + {1,1,M_BASIC,L_1,0x5BC0,A_DST2|D_EA}, + // op_tas + {1,1,M_BASIC,L_1,0x4AC0,A_DST2|D_EA}, +#endif +#endif +}; + +void wrt4(long x) { + if (odd) fatal("ALIGN"); + bin_chk(pos+=4); +#ifdef PC + bin[pos-4]=(unsigned char)(x>>24); + bin[pos-3]=(unsigned char)(x>>16); + bin[pos-2]=(unsigned char)(x>>8); + bin[pos-1]=(unsigned char)(x); +#else + *(long *)(bin+pos-4)=x; +#endif +#ifdef PC + if ((pos^odd)&1) + fatal("INT/ODD"); +#endif +} +void wrt2(short x) { + if (odd) fatal("ALIGN"); + bin_chk(pos+=2); +#ifdef PC + bin[pos-2]=(unsigned char)(x>>8); + bin[pos-1]=(unsigned char)(x); +#else + *(short *)(bin+pos-2)=x; +#endif +#ifdef PC + if ((pos^odd)&1) + fatal("INT/ODD"); +#endif +} +void wrt1(char x) { + bin_chk(pos+=1); +#ifdef PC + bin[pos-1]=(unsigned char)(x); +#else + *(char *)(bin+pos-1)=x; +#endif + odd=~odd; +#ifdef PC + if ((pos^odd)&1) + fatal("INT/ODD"); +#endif +} +void fill(int n) { + if (odd) wrt1(0); + bin_chk(pos+=n); + memset(bin+pos-n,0,n); + odd = -(n&1); +} +void move_pos(long diff) { /* caution : only works in overwrite mode */ + odd^=-(diff&1); + pos+=diff; +} +void rewrite(long size) { + bin_chk(pos+=size); + memcpy(bin+(pos-size),bin+(pos-2*size),size); + odd^=-(size&1); +#ifdef PC + if ((pos^odd)&1) + fatal("INT/ODD"); +#endif +} + +readonly int sz_table[]={0,0,0,0,0,2,2,2,0,0,2,2,2,2,4,0,0,0}; + +readonly struct enode zero={en_icon,0,0,{0},0,0}; +readonly struct amode am_null={am_direct,(struct enode *)&zero,0,0,0,0}; +#define ip_lab (((struct lbls *)ip)->lab) +void pass1() { + struct ocode *ip=scope_head; + OPCODE *op; + unsigned int vpos=pos; + while (ip) { + int opt,sz,n,f; + struct amode *ap; + int c=opi[ip->opcode],nm=opi[ip->opcode+1]-c; + int orig_len=ip->length; + int argnum_ok=0; +/* if (ip->opcode==_op_adj) { + sz=0; opt=0; c=-1; + goto ok; + }*/ + err_cur_line=ip->line; + if (!nm) { + if (ip->opcode!=op_label) + fatal("P1: UNIMPL"); + { + if (!local(ip_lab) && lab_src(ip_lab)) { + char *name=unres_name(ip_lab); + while (ip && ip->opcode==op_label) ip=ip->fwd; + if (ip) err_cur_line=ip->line-1; + else err_assembly=0; + uerrc2("label '%s' redefined",name); + } + lab_set(ip_lab,vpos); + ip->opcode=0; + sz=0; + goto ok_lab; + } + } + nm--; do { + opt=0; + op=(OPCODE *)&ops[c]; + if ((!(n=op->nargs) && ip->oper1) || (n==1 && (!ip->oper1 || ip->oper2)) + || (n==2 && !ip->oper2)) + goto nxt; + argnum_ok++; + ip->length=orig_len; + switch (op->model) { + case M_BASICSWAPPED: /* caution : assumes that it is the sole M_BASICSWAPPED */ + ap=ip->oper1; /* and that it is placed at the very end... */ + ip->oper1=ip->oper2; + ip->oper2=ap; + /* FALLTHROUGH */ + case M_BASIC: + if (!((f=op->lenf) & (1< length))) { + if (!ip->length) { + if (!(f & (1<<2))) { + if (!(f & (1<<4))) + ip->length=1; + else ip->length=4; + } else ip->length=2; + } else goto nxt; + } + sz=2; + ap=ip->oper1; + f=op->a1; + while (n--) { + int m=ap->mode; + if (!(f& + (m length?(m==am_ainc?A_MEM0:A_ADEC):0) + ) + ) + : + (m offset->nodetype==en_labcon + || ap->offset->nodetype==en_nacon) && +#ifndef LARGE_MODEL + global(ap->offset->v.enlab) +#else + local(ap->offset->v.enlab) +#endif +#ifdef TWIN_COMPILE + && (!twinc_prev || + ((tclab=twinc_prev[0],tcoff=twinc_prev[1], + twinc_prev+=2, + tclab!=ap->offset->v.enlab||abs(tcoff-vpos)>=5000) + && (twinc_prev-=2,1))) +#endif + )) { + /*if (ap->offset->v.enlab==0xFFFF8032) + bkpt();*/ + m=am_pcrel; + } else { + get_offs(ap->offset,0); + if (is_long) + m=am_dirl; + else m=am_dirw; + } + ap = *(ap==ip->oper1 ? &ip->oper1 : &ip->oper2) = copy_addr(ap); + /* this is because the same operand might be either pcrel or + dirl, depending on the instruction/place of the operand */ + ap->mode=m; + } +#ifdef TWIN_COMPILE + } +#endif + if (f&D_RAW2) + sz+=2; + else if ((f&D_RAW) && m==am_immed) + sz+=(ip->length+1)&-2; + else if (!(f&(D_Q|D_LOW))) + sz+=(m==am_immed?(ip->length+1)&-2:sz_table[m]); + ap=ip->oper2; + f=op->a2; + } + break; + case M_BRANCH: + if (n==1) { // Bcc + if (ip->oper1->offset->nodetype!=en_labcon + && ip->oper1->offset->nodetype!=en_nacon) +// fatal("BRANCH"); + uerrc("invalid branch"); + n=ip->oper1->offset->v.enlab; + if (!global(n)) +// fatal("XT BRANCH"); + uerrc("invalid branch"); + if (ip->length==2) opt=0,sz=4; + else { + if ((f=lab_src(n))) { + f-=vpos; + opt=(f>129 || f<-126); // all branches are backwards so we needn't + // handle branches to next stmt in this pass + } else opt=1; + sz=2+(opt<<1); + } + } else { // DBcc + if ((ip->oper2->offset->nodetype!=en_labcon + && ip->oper2->offset->nodetype!=en_nacon) + || (ip->oper1->mode!=am_dreg)) +// fatal("DBRANCH"); + uerrc("invalid branch"); + n=ip->oper2->offset->v.enlab; + if (!global(n)) +// fatal("XT BRANCH"); + uerrc("invalid branch"); + sz=4; + } + break; +#ifdef ASM + case M_DC: + f=ip->length-2; + if (f<=0) f++; // f=log_2(ip->length) + if (ip->oper1->mode!=am_direct) +// fatal("DC"); + uerrc("invalid declaration"); + sz=1; + if (((short)op->bo)>=0) { + if (ip->oper1->offset->nodetype!=en_icon) + uerrc("invalid declaration"); + sz=ip->oper1->offset->v.i; + if (op->bo && ip->oper2->mode!=am_direct) + uerrc("invalid declaration"); + } + sz<<=f; + if (sz>=128) + uerrsys("too many elements in 'dc' instruction; use C arrays"); + break; + case M_ALIGN: + sz=0; + if (vpos&1) { + sz=1; + c=oi_dc; + ip->length=1; + ip->oper1=(struct amode *)&am_null; + } + break; + default: + fatal("P1"); + sz=0; + break; +#endif + } + goto ok; + nxt: + c++; + } while (nm--); + if (!argnum_ok) + uerrc2("instruction requires %d arguments",n); + uerrc("invalid address modes"); + return; +// fatal("P1: INVALID"); + ok: +#ifdef SIZE_STATS + if (!ip->opt) /* not from an asm() statement */ + c_compiler_sz+=sz; /* note this is approximative, but close to reality */ +#endif + ip->opt=opt; + ip->sz=sz; + ip->opcode=c; + ok_lab: + ip=ip->fwd; + vpos+=sz; + } +} + +void pass2() { + struct ocode *ip=scope_head; + unsigned int vpos=pos,opos=vpos,s; + OPCODE *op; + while (ip) { + if (ip->opcode>0) { + s=ip->sz; + if (ip->opt) { + op=(OPCODE *)&ops[ip->opcode]; + switch (op->model) { + case M_BASIC: case M_BASICSWAPPED: + break; + case M_BRANCH: { // this is necessarily a Bcc since ip->opt==1 + int n=ip->oper1->offset->v.enlab; + long f=qlab_src(n); + if (!f) break; // global label not found + if ((unsigned int)f>opos) // we HAVE TO compare with opos (since opos>=vpos) + f-=opos+2; // <- here, f is afterwards, so relative to old pos + else f-=vpos+2; + /* the case of the next stmt branch : + * PASS 1 : the label is unknown, so opt=1 and ip->sz=4 + * PASS 2 : qlab_src(n)-opos==4, so here, f==2 (rather than f==0) */ + if (f!=2 && f>=-128 && f<=127) + ip->sz=2; + else if (f>=-32768 && f<=32767) + ip->sz=4; + else err_cur_line=ip->line, uerrc("branch size can't fit in a word"); + } break; + } + } + opos+=s, vpos+=ip->sz; + } else if (!ip->opcode) {// op_label +/* if (vpos==0x2642) + printf("rjo");*/ + lab_set(ip_lab,vpos); + } +/* else { // _op_adj + + }*/ + ip=ip->fwd; + } +} + +int movem(short x) { + int n=0; + while (x) { + if (x<0) n++; + x+=x; + } + return n; +} + +void pass3() { + struct ocode *ip=scope_head; +#ifdef PC + unsigned int opos=pos; +#endif + OPCODE *op; + while (ip) { + int n,f; + struct amode *ap; + short code; + if (ip->opcode>0) { + err_cur_line=ip->line; + op=(OPCODE *)&ops[ip->opcode]; + n=op->nargs; + switch (op->model) { + case M_BASIC: case M_BASICSWAPPED: { + int ds=0,ds2=0; int len=ip->length; +#ifdef PC + long dc=0xdddddddd,dc2=0xdddddddd; +#else + long dc=dc,dc2=dc2; +#endif + unsigned int vpos=pos+2; + code=op->bo; + ap=ip->oper1; + f=op->a1; +#ifndef USE_LINK + if (n) + if (ap->preg==STACKPTR-8) { + if (ap->mode==am_ainc) { // for (a7)+,... + lc_stk-=len+(len&1); + } else if (ap->mode==am_adec) + lc_stk+=len+(len&1); // for clr -(a7) + } +#endif + while (n--) { + if ((f&D_SZ3)==D_SZ3) { + if (len==4) code|=0x40; + } else if (f&D_SZ) + code|=(len==2?0x40:(len==4?0x80:0x00)); + else if ((f&D_SZ2) && len==4) + code|=0x100; + if (f&D_EA) + switch (ap->mode) { + case am_areg: + case am_ind: + case am_ainc: + case am_adec: + code+=ap->mode<<3; + case am_dreg: + code+=ap->preg; + break; + case am_indx: +#ifndef USE_LINK + if (ap->preg==FRAMEPTR-8) { + if (uses_link) + ap->preg+=TRUE_FRAMEPTR-FRAMEPTR; + else { + ap->preg+=STACKPTR-FRAMEPTR; + ap->offset->v.i += lc_stk - (ap->offset->v.i>0 ? 4 : 0); + uses_lc_stk = 1; + } + } +#endif + code+=0x28+ap->preg; + ds=1; dc=get_word(ap->offset,vpos,1); + break; + case am_pcrel: + code+=0x3A; + ds=1; dc=get_pcword(ap->offset,vpos); // rel to vpos, not pos! + break; + case am_dirw: + code+=0x38; + ds=1; dc=get_word(ap->offset,vpos,1); + break; + case am_dirl: + code+=0x39; + ds=2; dc=get_long(ap->offset,vpos); + break; + case am_immed: + code+=0x3C; + ds=(1+len)>>1; + if (ds==1) dc=get_word(ap->offset,vpos,0); + else dc=get_long(ap->offset,vpos); + break; + case am_indx2: + code+=0x30+ap->preg; + ds=1; + dc=get_byte(ap->offset)+((short)ap->sreg<<12)+ + (ap->slen==4?0x0800:0x0000); + break; + case am_indx3: + code+=0x30+ap->preg; + ds=1; + dc=get_byte(ap->offset)+((short)ap->sreg<<12)+ + (ap->slen==4?0x8800:0x8000); + break; +#ifdef PC + default: + ierr(PASS3,1); +#endif + } + else if (f&D_EA2) + switch (ap->mode) { + case am_areg: + case am_ind: + case am_ainc: + case am_adec: + code+=ap->mode<<6; + case am_dreg: + code+=((short)ap->preg)<<9; + break; + case am_indx: +#ifndef USE_LINK + if (ap->preg==FRAMEPTR-8) { + if (uses_link) + ap->preg+=TRUE_FRAMEPTR-FRAMEPTR; + else { + ap->preg+=STACKPTR-FRAMEPTR; + ap->offset->v.i += lc_stk - (ap->offset->v.i>0 ? 4 : 0); + uses_lc_stk = 1; + } + } +#endif + code+=(0x28<<3)+((short)ap->preg<<9); + ds=1; dc=get_word(ap->offset,vpos,1); + break; +/* case am_pcrel: + code+=(0x38<<3)+(0x02<<9); + ds=1; dc=get_pcword(ap->offset,vpos); // rel to vpos, not pos! + break;*/ + case am_dirw: + code+=0x38<<3; + ds=1; dc=get_word(ap->offset,vpos,1); + break; + case am_dirl: + code+=(0x38<<3)+(0x01<<9); + ds=2; dc=get_long(ap->offset,vpos); + break; + case am_indx2: + code+=(0x30<<3)+(ap->preg<<9); + ds=1; + dc=get_byte(ap->offset)+((short)ap->sreg<<12)+ + (ap->slen==4?0x0800:0x0000); + break; + case am_indx3: + code+=(0x30<<3)+(ap->preg<<9); + ds=1; + dc=get_byte(ap->offset)+((short)ap->sreg<<12)+ + (ap->slen==4?0x8800:0x8000); + break; +#ifdef PC + default: + ierr(PASS3,2); +#endif + } + else if (f&D_Q) + switch (ap->mode) { + case am_areg: + case am_dreg: + case am_ainc: + case am_adec: + code+=((unsigned short)ap->preg)<<9; + break; + case am_immed: + code+=get_quick(ap->offset)<<9; + break; +#ifdef PC + default: + ierr(PASS3,3); +#endif + } + else if (f&D_LOW) + switch (ap->mode) { + case am_areg: + case am_dreg: + case am_adec: + case am_ainc: + code+=ap->preg; + break; + case am_immed: + code+=get_byte(ap->offset); + break; +#ifdef PC + default: + ierr(PASS3,4); +#endif + } + else if (f&D_RAW) + switch (ap->mode) { + case am_immed: + if (len==4) + ds=2,dc=get_long(ap->offset,vpos); + else + ds=1,dc=get_word(ap->offset,vpos,0); + break; + case am_mask1: + case am_mask2: + ds=1; dc=ap->offset->v.i; + break; +#ifdef PC + default: + ierr(PASS3,5); +#endif + } + else if (f&D_RAW2) + ds=1,dc=get_word(ap->offset,vpos,0); + ap=ip->oper2; + f=op->a2; + vpos+=ds<<1; + if (n) { + ds2=ds,dc2=dc,ds=0; +#ifndef USE_LINK + if (ap->preg==STACKPTR-8) { + if (ap->mode==am_adec) { // for ...,-(a7) + if (ip->oper1->mode==am_mask1) + lc_stk+=movem((short)ip->oper1->offset->v.i)<<(len>>1); + else lc_stk+=len+(len&1); + } + else if (ap->mode==am_ainc && ip->oper1->mode==am_mask2) + lc_stk-=movem((short)ip->oper1->offset->v.i)<<(len>>1); + } +#endif + } + } +#ifndef USE_LINK + if (code==0x4FEF // lea x(a7),a7 + || (code&0xF13F)==0x500F // addq.* #x,a7 + || (code&0xFEFF)==0xDEFC) // add.* #x,a7 + lc_stk-=ip->oper1->offset->v.i; + else if ((code&0xF13F)==0x510F // subq.* #x,a7 + || (code&0xFEFF)==0x9EFC) // sub.* #x,a7 + lc_stk+=ip->oper1->offset->v.i; + else if (((code&0xFFC0)==0x4840 && (code&0x0038/*!swap*/))) // pea + lc_stk+=4; +#endif + wrt2(code); + if (--ds2>=0) { + if (!ds2) wrt2((short)dc2); + else wrt4(dc2); + } + if (--ds>=0) { + if (!ds) wrt2((short)dc); + else wrt4(dc); + } + } break; + case M_BRANCH: { + unsigned int vpos=pos+2; + code=op->bo; + if (ip->oper2) // DBcc + n=ip->oper2->offset->v.enlab, code+=ip->oper1->preg; + else n=ip->oper1->offset->v.enlab; // Bcc + if ((f=qlab_src(n))) { + if (ip->sz==2) + wrt2(code|=(f-vpos)&0xFF); + else + wrt2(code),wrt2((short)(f-vpos)); + } else + wrt2(code),wrt2((short)-(short)vpos),lab_add_ref(n,vpos); + } break; + case M_DC: { + struct enode *ep=ip->oper1->offset; + n=1; + if (((short)op->bo)>=0) { + n=ip->oper1->offset->v.i; + if (op->bo) + ep=ip->oper2->offset; + else ep=(struct enode *)&zero; + } + f=ip->length-2; + while (n--) { + if (f<0) { + GV v; + get_value(ep,&v,0,0); + if (v.tr) + uerr(ERRA_INVALIDREL); + if (v.i>255 || v.i<-128) + uerrc("result can't fit in a byte"); + wrt1((char)v.i); + } else if (!f) wrt2(get_word(ep,pos,0)); + else wrt4(get_long(ep,pos)); + } + } break; + } +#ifdef PC + opos+=ip->sz; + if (pos!=opos) { +// printf("%d",oi_ds); + ierr(PASS3,6); + } +#endif + } +/* else if (ip->opcode) { // _op_adj + + }*/ + else if (!ip->opcode) { // op_label +//#ifdef PC +// if (pos!=qlab_src(ip_lab)) +// ierr(PASS3,7); +//#endif + if (pos!=qlab_src(ip_lab)) + uerrc2("label '%s' defined twice",unres_name(ip_lab)); + if (!local(ip_lab)) { + lab_set(ip_lab,0); // 'unset' it so there will be no error... + set_label(ip_lab,pos); + } + } + ip=ip->fwd; + } +} + +void scope_flush(void) { + err_assembly=1; + pass1(); + pass2(); + pass3(); + err_assembly=0; + if (uses_lc_stk && lc_stk) { + uwarn("stack displacement of %d: compiler bug?",(int)lc_stk); + iwarn(WARN_LC_STK,1); + } + scope_head = 0; + loc_tab = 0; +} + +void scope_init(void) { + if (scope_head) scope_flush(); + lc_stk = 0; + uses_lc_stk = 0; + nextlabel = 1; + loc_tab = 0; +} + +void local_clean(void) { /* remove local symbols from alsyms -- to be called just before rel_local */ + HTABLE *tab=&alsyms; + SYM *ttail,**prv; + struct htab *root; + int i; + if (!tab->hash) + ierr(TABLE_HASH,2); +#ifdef PC + if (tab->hash!=0x2489) + ierr(TABLE_HASH,1); +#endif + i=N_HASH; + while (i--) { + prv=&((root=&tab->h[i])->tail); + while ((ttail=*prv)) { + if (local(ttail->value.splab)) { +// *prv = ttail->prev; + if (ttail->next) ttail->next->prev = ttail->prev; + if (ttail->prev) ttail->prev->next = ttail->next; +// ttail->next = prv; + if (root->tail==ttail) root->tail=ttail->prev; + if (root->head==ttail) root->head=ttail->next; +/* if (!root->tail) + root->head=0;*/ + } + prv = &(ttail->prev); + } + } +} + +int label(char *s) { + int lab; SYM *sp; +/* if (!strcmp(s,"__L_plane") || !strcmp(s,"__D_plane")) + bkpt();*/ + if (!(sp=search(s,-1,&alsyms))) { + if (s[0]!='\\') + global_flag++; + sp=(SYM *)xalloc((int)sizeof(SYM),_SYM); + sp->name=strsave(s); + if (s[0]=='\\') + lab_src(sp->value.splab=lab=nxtlabel()); + else if (internal(s)) + lab_src(sp->value.splab=lab=nxtglabel()); + else + sp->value.splab=lab=extlabel--; + insert(sp,&alsyms); + if (s[0]!='\\') + global_flag--; + } else + lab=sp->value.splab; + debugf("label(%s)=%x\n",s,lab); +#ifdef PC +/* if (lab==0x806d) + bkpt();*/ + if (!*s) + return lab; +#endif + return lab; +} + +void set_label(int lab,unsigned int pos) { + /*if ((unsigned short)lab==0x8014) + bkpt();*/ + debugf("set_lab(%x,%x)\n",lab,pos); + if (lab_src(lab)) uerrc("label redefinition"); + if (global(lab)) { + lab_set(lab,pos); + if (!local(lab)) { + REF **rp,*r; + unsigned int p,*a; int n; + r=*(rp=glb_ref(lab)); + while (r) { + a=r->r; + n=N_REF; + while (n--) { + if (!(p=*a++)) + goto ref_done; +#ifdef PC + { int m=p&1; short a,olda; + p-=m; + a=(bin[p]<<8)+bin[p+1],olda=a; + if (m) { + if ((a-=pos)>0 && olda) fatal("PC RANGE 3"); + } else if ((a+=pos)<0 && olda) fatal("PC RANGE 2"); + bin[p]=(unsigned char)(a>>8); + bin[p+1]=(unsigned char)(a); + } +#else + if (p&1) { + short *z=(short *)(bin+(p&-2)); + if (*z && ((*z)-=pos)>0) + fatal("PC RANGE 3"); + else (*z)-=pos; + } else if ((*(short *)(bin+p)+=pos)<0 && *(short *)(bin+p)!=pos) + fatal("PC RANGE 2"); +#endif + } + r=r->nxt; + } + ref_done: + *rp=0; + } + } + else debugf(" --local\n"); +} + +void put_label(int lab) { +/* + * output a compiler generated label. + */ +#ifdef NO_OUT + return; +#endif + set_label(lab,pos); +} + +void g_strlab(char *s) { +/* + * generate a named label. + */ +#ifdef NO_OUT + return; +#endif + put_label(label(s)); +} + +void genbyte(int val) { +#ifdef NO_OUT + return; +#endif + wrt1((char)val); +} + +void genword(int val) { +#ifdef NO_OUT + return; +#endif + put_align2(); + wrt2((short)val); +} + +typedef struct _pc_bcd_s { + short exponent; + unsigned char mantissa[8]; +} _pc_bcd; +#ifndef NOFLOAT +void genfloat(double val) { +#ifndef BCDFLT + put_align2(); + wrt4(double2ffp(val)); +#else + BCD bcd; + double2bcd(val,&bcd); + wrt2(bcd.exponent); +#ifdef PC + { + int i; + for (i=0;i tp->size; +#ifdef NO_OUT + return; +#endif +#ifdef PC +#define no_bss (nostub_mode || forbid_bss) +#else +#define no_bss nostub_mode +#endif + if (align!=1) put_align2(); + size=(size+1)&-2; // round size + if (sp->value.splab) { + if (no_bss) { /* that's OK in _nostub mode :) */ + if (lab_src(sp->value.splab)) + return; + } else + uerrc2("BSS redeclaration of '%s' : use 'extern' for prototyping",sp->name); + } else if (no_bss) { + if (sp->storage_class==sc_static) + sp->value.splab=nxtglabel(); + else + sp->value.splab=label(sp->name); + } + if (no_bss) { + put_label(sp->value.splab); + fill(size); + } else { + *(long *)xt_find(sp->value.splab=extlabel--)=lc_bss|0x80000000; // DIRTY, but no hidden + lc_bss+=size; // bug possible + } // (cf xalloc) +#if 0 + remain = size % AL_DEFAULT; + if (remain != 0) + size = size + AL_DEFAULT - remain; + if (sp->storage_class == sc_static) { + fprintf(output, "L%ld:" tabs "ds.b %ld\n", sp->value.i, size); + lc_bss += sp->tp->size; + } else + fprintf(output, "L%d:" tabs "ds.b %ld\n", label(sp->name),size); +#endif +#undef no_bss +} + +void dumplits() { +/* + * dump the string literal pool. + */ + char *cp; + int len; +/* + * The ACK assembler may produce a .text section of an uneven length. + * This will eventually bomb the linker when it tries to relocate + * something in a following (.data) section, which then is misaligned + * as a whole in memory (perhaps this is just a bug in the linker). + * + * To avoid this (it can only happen if the string pool is the last + * thing dumped to the assembler file) we count the total number of + * bytes in the string pool and emit a zero filler byte if that + * number was uneven. + * This is perhaps an ugly hack, but in virtually all of the cases + * this filler byte is inserted anyway by the assembler when + * doing the alignment necessary for the next function body. + */ +// long count=0; + + while (strtab != 0) { + cseg(); + nl(); + put_label((unsigned int) strtab->label); + cp = strtab->str; + len = strtab->len; + //count += (len+1); + while (len--) + wrt1(*cp++); + wrt1(0); + strtab = strtab->next; + } + put_align2(); +} + + +void put_align2(void) { +/* align the following data to 2 */ + if (odd) wrt1(0); +} +/*put_align(align) + int align; +// align the following data +{ + switch (align) { + case 1: + break; + case 2: + if (odd) wrt1(0); + } +}*/ + +#ifdef LISTING +void put_external(char *s) { +/* put the definition of an external name in the ouput file */ + +} +void put_global(char *s) { +/* put the definition of a global name in the output file */ + +} +#endif + +/*cseg() +{ + if (curseg != codeseg) { + nl(); +#ifdef PC + fputs(tabs ".text\n", output); +#endif + curseg = codeseg; + } +}*/ +/*dseg() +{ + if (curseg != dataseg) { + nl(); +#ifdef PC + fputs(tabs ".data\n", output); +#endif + curseg = dataseg; + } +}*/ + +int radix16(char c) { + if (isdigit(c)) + return c - '0'; +/* if (c >= 'a' && c <= 'z') + return c - 'a' + 10;*/ + if (c >= 'A' && c <= 'Z') + return c - 'A' + 10; + return -1; +} +int hexatoi(char *s) { + int x=0; + if (strlen(s)>3) return -1; + while (*s) { + int y=radix16(*s++); + if (y<0) return -1; + x<<=4; x+=y; + } + return x; +} + +int internal(char *s) { + int n=0; + char c,old=0,*p; + if (*s == '.') + return 1; + p=s; + while ((c=*p++)) { + if (n==10) { + if ((( +#ifdef FLINE_RC + !fline_rc && +#endif + !strncmp(s,"_ROM_CALL_",10))) +#ifdef RAM_CALLS + || !strncmp(s,"_RAM_CALL_",10) +#endif + ) { + int f=hexatoi(p-1); + if (f<0) + goto cont; + *xt_find(extlabel)=&(func_search( +#ifdef RAM_CALLS + s[2]=='O' ? &rom_funcs : &ram_funcs +#else + &rom_funcs +#endif + ,f))->rt; + return 0; + } + } + if (n==export_pfx_len) { + if (!strncmp(s,export_pfx,n)) { + int f=hexatoi(p); + if (f<0) + goto cont3; + *exp_find(f)=glblabel; + return 1; + } + } + if (c=='_' && n && old=='_' && *p=='0') { + SYM *sp; + int f=hexatoi(p+1); + if (f<0) + goto cont2; + p[-2]=0; + if (!(sp=search(s,-1,(HTABLE *)&libsyms))) { + global_flag++; + sp=(SYM *)xalloc((int)sizeof(SYM),_SYM); + sp->name=strsave(s); + insert(sp,(HTABLE *)&libsyms); + global_flag--; + } + *xt_find(extlabel)=&(func_search((FUNC **)&sp->value.i,f))->rt; + p[-2]='_'; + return 0; + } + cont: + cont2: + cont3: + old=c; n++; + } + return 1; +} + +#ifdef PCH +unsigned char *_end_of(short *p) { /* works endian-independently */ + while (*p++); + return (unsigned char *)p; +} +unsigned char *_end_of2(short *p) { /* works endian-independently */ + while (*p++ || *p); + return (unsigned char *)(p+1); +} +#define end_of(p) _end_of((short *)(p)) +#define end_of2(p) _end_of2((short *)(p)) + + +#ifndef isidch +#ifdef PC +static int isidch(char c) { + return (c>='0'&&c<='9') || (c>='A'&&c<='Z') || (c>='a'&&c<='z') + || c == '_' || c == '$'; +} +#else +#define isidch(___c) ({register short __c=(___c); \ +(__c>='0'&&__c<='9') || (__c>='A'&&__c<='Z') || (__c>='a'&&__c<='z') || __c=='_' || __c=='$';}) +#endif +#endif + +int pchsearch(char *id,int mode); +#define lscan(x) pchsearch(x,PCHS_ADD) +#define lexpand(x) (x) +/*#define lscan (void)lexpand +void macro_expansion(char *in,char *inbound); +char lexp_buf[100]; +char *lexpand(char *s) { + char c,*p=lexp_buf; + strcpy(p,s); + macro_expansion(p,&lexp_buf[100]); + if (*p>='0' && *p<='9') + return s; + while ((c=*p++)) + if (!isidch(c)) return s; + return lexp_buf; +}*/ + +#ifdef PC +#define g16(p) (p+=2,(p[-2]<<8)+p[-1]) +#define r16(o) ((ext[o]<<8)+ext[o+1]) +#define align(strp) if ((strp-ext)&1) strp++ +#else +#define g16(p) (*((int *)p)++) +#define r16(o) (*(int *)(ext+o)) +#define align(strp) if (((short)((long)strp))&1) strp++ +#endif +void extscan(unsigned char *ext) { + int codeOff=r16(0); + unsigned char *offp=ext+codeOff,*strp; + /* reloc table */ + offp=end_of(offp); + /* export table */ + strp=end_of(offp); + while (g16(offp)) + while (*strp++); + align(strp); + /* import table */ + offp=strp; strp=end_of2(offp); + while (*(short *)offp) { + lscan(strp); + offp=end_of(offp); + while (*strp++); + } +} + +#undef off // for TI-GCC :D +#ifdef PC +#define add_offs(val,offs) do { \ + short a=bin[offs+0]<<8; \ + a+=bin[offs+1]; \ + a+=val; \ + bin[offs+0]=(unsigned char)(a>>8); \ + bin[offs+1]=(unsigned char)(a); \ + } while (0) +#else +#define add_offs(val,offs) (*(short *)(bin+offs)+=val) +#endif + +void extload(unsigned char *ext) { + int codeOff=r16(0); unsigned int wriOff; + SYM *sp; + if (odd) wrt1(0); +/*#ifdef PC + if (codeOff>=0x2000) + printf("gfio"); +#endif*/ + /* In the following case, either the .ext has already been loaded, either + * there is a conflict, in which case the error will arise at the end + * (what's more, it allows for overriding of the default functions) */ + sp=search(end_of(end_of(ext+codeOff)),-1,&alsyms); + if (sp && lab_src(sp->value.splab)) + return; + wriOff=pos-2; /* since offsets are based on ext::$00, not on ext::$02=code */ + bin_chk(pos+=codeOff-2); + memcpy(bin+pos-codeOff+2,ext+2,codeOff-2); + { + /* reloc table */ + unsigned short off; unsigned char *offp=ext+codeOff; + while ((off=g16(offp))) { + rt_add_ref(&reloc_tab,off+wriOff); + add_offs(wriOff+2,off+wriOff+2); + } + { + /* export table */ + unsigned char *strp=end_of(offp); + while ((off=g16(offp))) { + set_label(label(strp),off+wriOff); + while (*strp++); + } + align(strp); + /* import table */ + offp=strp; strp=end_of2(offp); + while (*(short *)offp) { + int n=label(lexpand(strp)); unsigned int p=lab_src(n); + while ((off=g16(offp))) { + off+=wriOff; + if (p) { +#ifdef PC + unsigned short a=bin[off+2]<<8; + a+=bin[off+3]; + a+=p; + bin[off+2]=(unsigned char)(a>>8); + bin[off+3]=(unsigned char)(a); +#else + *(short *)(bin+off+2)+=p; +#endif + /* if (ip->sz==2) + wrt2(code|=(f-vpos)&0xFF); + else wrt2(code),wrt2((short)(f-vpos));*/ + } else + lab_add_ref(n,off+2); + rt_add_ref(&reloc_tab,off); + } + while (*strp++); + } + } + } +} +#endif + +#endif /* MC680X0 */ +// vim:ts=4:sw=4 diff --git a/gtc/src/out68k_exe.h b/gtc/src/out68k_exe.h new file mode 100644 index 0000000..87e2a1c --- /dev/null +++ b/gtc/src/out68k_exe.h @@ -0,0 +1,71 @@ +/* + * GTools C compiler + * ================= + * source file : + * EXE loader + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#define exeloadersize_bss (-1) +readonly unsigned char exeloader_bss[1]; +#define exeloadersize_nobss sizeof(exeloader_nobss) +readonly unsigned char exeloader_nobss[]={ + 0x4f,0xef,0x00,0x30,0x4e,0x75,0x20,0x78,0x00,0xc8,0x0c,0xa0,0x54,0x8f,0x4e,0x75, + 0x66,0xf8,0x42,0x67,0x2f,0x08,0x48,0xe7,0x1f,0x3e,0x47,0xf9,0x00,0x00,0x00,0x00, + 0x7a,0xf2,0xda,0x8b,0x24,0x78,0x00,0xc8,0x76,0x00,0x36,0x2b,0x00,0x0c,0x2f,0x13, + 0x20,0x6a,0x02,0x48,0x4e,0x90,0x58,0x8f,0x3f,0x00,0x67,0xc4,0x20,0x6a,0x02,0x58, + 0x4e,0x90,0x3e,0x1f,0x28,0x48,0x22,0x4c,0xd3,0xd3,0x93,0xc3,0x2c,0x09,0x41,0xeb, + 0x00,0x08,0x4e,0xba,0x01,0x2c,0x20,0x46,0x22,0x4c,0x70,0x00,0x30,0x23,0x47,0xf3, + 0x08,0x0a,0x61,0x00,0x00,0x9e,0x3f,0x47,0x00,0x2c,0x48,0x54,0x3f,0x3c,0x00,0x0a, + 0x42,0xa7,0x20,0x6a,0x01,0xb0,0x4e,0x90,0x5c,0x8f,0x26,0x08,0x78,0x00,0x08,0x28, + 0x00,0x02,0x00,0x0a,0x67,0x10,0x3f,0x28,0x00,0x0c,0x20,0x6a,0x02,0x58,0x4e,0x90, + 0x54,0x8f,0xba,0x88,0x67,0x0a,0x20,0x6a,0x01,0xb4,0x4e,0x90,0x26,0x08,0x66,0xde, + 0x48,0xe7,0x1f,0x3e,0x48,0x7a,0x00,0x52,0x20,0x78,0x00,0xc8,0x0c,0xa0,0x00,0x00, + 0x03,0xe8,0x65,0x48,0x26,0x6f,0x00,0x2c,0x20,0x08,0xe1,0x98,0x6b,0x12,0x0c,0x57, + 0x00,0x04,0x64,0x38,0x26,0x7c,0x00,0x03,0xe0,0x00,0x58,0x57,0x58,0x6f,0x00,0x2c, + 0xef,0x98,0x72,0x70,0xc2,0x80,0x52,0x81,0x48,0x41,0xe3,0x99,0x24,0x17,0x2f,0x01, + 0x2f,0x01,0x4f,0xef,0xff,0xf4,0x4e,0x4c,0x46,0xfc,0x27,0x00,0x2f,0x02,0x42,0x67, + 0x76,0x0f,0x20,0x78,0x00,0xac,0x4e,0xd0,0x4f,0xef,0x00,0x14,0x4c,0xdf,0x7c,0xf9, + 0x4e,0x75,0x48,0xe7,0x18,0x1c,0x72,0x00,0x70,0x00,0x10,0x1b,0x67,0x00,0x00,0x6c, + 0x6a,0x06,0xd0,0x00,0xef,0x48,0x10,0x1b,0x55,0x40,0x65,0x2e,0x60,0x02,0x32,0xd8, + 0x38,0x10,0x76,0xc0,0x86,0x44,0x5c,0x43,0x67,0x0e,0xc8,0x7c,0xf0,0xff,0xb8,0x7c, + 0x60,0x00,0x57,0xc8,0xff,0xea,0x66,0x10,0x53,0x40,0x65,0x0c,0x32,0xd8,0x36,0x09, + 0x96,0x4c,0x97,0x50,0x51,0xc8,0xff,0xd8,0x32,0xd8,0x51,0xc9,0x00,0x06,0x58,0x41, + 0x14,0x1b,0x4a,0x13,0x67,0x24,0xd4,0x02,0x65,0x0e,0x42,0x59,0x32,0xd8,0x20,0x0c, + 0xd4,0x02,0xd1,0xa9,0xff,0xfc,0x60,0xa0,0xd4,0x02,0x30,0x18,0x6b,0x04,0x32,0xfc, + 0x4e,0xb9,0xe5,0x48,0x22,0xf2,0x00,0x00,0x60,0x8e,0x4c,0xdf,0x38,0x18,0x4e,0x75, + 0x48,0xe7,0x1f,0x3e,0x7a,0xff,0x42,0x05,0x47,0xfa,0x01,0x70,0x50,0x88,0x70,0x00, + 0x10,0x18,0x38,0x00,0x72,0x00,0x12,0x18,0x3c,0x41,0xd0,0x40,0x36,0x33,0x00,0x02, + 0x70,0x08,0x90,0x44,0x38,0x40,0x24,0x48,0x12,0x18,0xd2,0x41,0x4b,0xf3,0x10,0x02, + 0x70,0x00,0x10,0x18,0xd0,0xc0,0x7e,0x00,0x9e,0x44,0x6a,0x08,0x50,0x47,0x16,0x86, + 0x3c,0x13,0x1c,0x18,0x32,0x06,0xee,0x69,0xc2,0x43,0xb2,0x4e,0x67,0x14,0x9e,0x4c, + 0x6a,0x08,0x50,0x47,0x16,0x86,0x3c,0x13,0x1c,0x18,0x32,0x06,0xee,0x69,0x12,0xc1, + 0x60,0xd6,0x61,0x4e,0x4a,0x41,0x67,0x00,0x00,0x8e,0x30,0x02,0x61,0x44,0x0c,0x42, + 0x00,0xff,0x66,0x06,0x4c,0xdf,0x7c,0xf8,0x4e,0x75,0x53,0x42,0x12,0x12,0x67,0x08, + 0xe3,0x6a,0x61,0x60,0xc2,0x55,0x84,0x41,0x16,0x82,0x32,0x13,0x74,0xff,0xb3,0x42, + 0x61,0x58,0x14,0x01,0x47,0xf1,0x28,0x00,0x12,0xdb,0x51,0xc8,0xff,0xfc,0x47,0xfa, + 0x00,0xda,0x60,0x94,0x61,0x44,0x82,0x45,0x12,0xf1,0x10,0x00,0x12,0xf1,0x10,0x00, + 0x60,0x86,0x72,0xff,0x51,0xcf,0x00,0x0a,0x50,0x47,0x16,0x86,0x3c,0x13,0x1c,0x18, + 0x52,0x41,0x0f,0x06,0x57,0xcf,0xff,0xfa,0x66,0xee,0x9e,0x41,0x6a,0x08,0x50,0x47, + 0x16,0x86,0x3c,0x13,0x1c,0x18,0x34,0x06,0xee,0x6a,0x03,0xc2,0xd2,0x41,0xc4,0x73, + 0x10,0x04,0x4e,0x75,0x9e,0x41,0x6a,0x08,0x50,0x47,0x16,0x86,0x3c,0x13,0x1c,0x18, + 0x32,0x06,0xee,0x69,0x4e,0x75,0x51,0xcf,0x00,0x0a,0x50,0x47,0x16,0x86,0x3c,0x13, + 0x1c,0x18,0x0f,0x06,0x67,0x9e,0x51,0xcf,0x00,0x0a,0x50,0x47,0x16,0x86,0x3c,0x13, + 0x1c,0x18,0x0f,0x06,0x66,0x20,0x32,0x04,0x61,0xca,0xc2,0x43,0x30,0x0e,0x3c,0x41, + 0x32,0x0c,0xe3,0x68,0x61,0xbe,0x34,0x0c,0xd4,0x42,0xc2,0x73,0x20,0x02,0x80,0x41, + 0x12,0xc0,0x60,0x00,0xff,0x04,0x61,0x00,0xff,0x7a,0x30,0x02,0x0c,0x40,0x00,0x80, + 0x6d,0x10,0x72,0x01,0x61,0x9e,0x10,0x01,0x61,0x00,0xff,0x68,0x53,0x02,0xe1,0x4a, + 0x80,0x42,0x61,0x00,0xff,0x5e,0x04,0x42,0x00,0x20,0x6a,0x06,0x14,0x32,0x20,0x21, + 0x60,0x0e,0xe7,0x4a,0x72,0x03,0x61,0x00,0xff,0x7c,0x02,0x41,0x00,0x07,0x84,0x41, + 0x12,0xc2,0x51,0xc8,0xff,0xfc,0x60,0x00,0xfe,0xc0,0x00,0x00,0x00,0x00,0x00,0x01, + 0x00,0x03,0x00,0x07,0x00,0x0f,0x00,0x1f,0x00,0x3f,0x00,0x7f,0x00,0xff,0x01,0xff, + 0x03,0xff,0x07,0xff,0x0f,0xff,0x1f,0xff,0x3f,0xff,0x7f,0xff,0x00,0x00,0x00,0x0c, + 0x00,0x1c,0xf3, +}; diff --git a/gtc/src/pch.h b/gtc/src/pch.h new file mode 100644 index 0000000..977beb3 --- /dev/null +++ b/gtc/src/pch.h @@ -0,0 +1,53 @@ +/* + * GTools C compiler + * ================= + * source file : + * PCH management definitions + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#ifndef PCH_H +#define PCH_H + +typedef struct { + TI_LONG magic; + TI_SHORT h_off; // offset to .H section + TI_SHORT ext_off; // offset to .EXT table (int ext_table[nExt]) + TI_SHORT dic_off; // offset to dictionnary ((char[]) sPk_table[]) + TI_SHORT nID; +} PCH_HEAD; + +#define PCH_HEAD_SIZE 12 + +#define PCHID_MASK 0xFFF +#define PCHID_MACRO 0x8000 +#define PCHID_VAMAC 0x4000 +#define PCHID_PACKED 0x2000 + +#ifndef PC +char *__attribute__((stkparm)) sUnpack(char *in,char *out,char *dic); +#else +char *sUnpack(char *in,char *out,char *dic); +#endif + +/* GTC-only */ +extern FILE *pchfile[]; +extern char *pchdata[]; +extern char *pchtab[]; +extern char pchname[][15]; +extern char pchrequired[]; +extern int pchnum; +#define pchhead ((PCH_HEAD **)pchdata) + +/* PchMaker-only */ +extern int def_is_packed; + +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/peep68k.c b/gtc/src/peep68k.c new file mode 100644 index 0000000..4566ae1 --- /dev/null +++ b/gtc/src/peep68k.c @@ -0,0 +1,1291 @@ +/* + * GTools C compiler + * ================= + * source file : + * peephole optimizations + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#define NEWLAB +//#define NO_PEEP + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" +#ifndef NOFLOAT +#include "ffplib.h" +#endif + +#ifdef MC680X0 + +extern struct enode *regexp[REGEXP_SIZE]; +struct ocode *_peep_head CGLOB; +extern struct ocode *scope_head; +#ifdef SPEED_OPT +int speed_opt_value CGLOB; +#endif +#ifndef VCG +struct ocode *peep_head CGLOB; +#else +struct ocode *vcg_peep_head[VCG_MAX+1] CGLOBL; +struct ocode *vcg_peep_tail[VCG_MAX+1] CGLOBL; +int vcg_lvl CGLOB; +#define peep_head vcg_peep_head[vcg_lvl] +#define peep_tail vcg_peep_tail[vcg_lvl] +#endif +xstatic struct ocode *next_ip CGLOB; +xstatic struct ocode *last_param_pop CGLOB; + +#define getop1(__ip) (__ip->oper1->offset->v.i) +#define getoplab(__ip) (__ip->oper1->offset->v.enlab) +#define getop2(__ip) (__ip->oper2->offset->v.i) +#ifdef NEWLAB +#define getlab(__ip) (((struct lbls *)__ip)->lab) +#else +#define getlab(__ip) (__ip->oper1->offset->v.i) +#endif +/*static enum(e_op) revcond[] = { op_bne, op_beq, op_bge, op_bgt, op_ble, op_blt, + op_bls, op_blo, op_bhs, op_bhi };*/ +xstatic readonly enum(e_op) revcond[] = + { + op_bne, op_beq, op_blo, op_blt, op_bls, op_ble, op_bhi, op_bgt, op_bhs, op_bge + }; + +void add_peep(struct ocode *new_ocode); +void opt3(void); + +void g_code(enum(e_op) op, int len, struct amode *ap1, struct amode *ap2) { +/* + * generate a code sequence into the peep list. + */ + struct ocode *new_ocode; + new_ocode = (struct ocode *) xalloc((int) sizeof(struct ocode), OCODE+G_CODE); + new_ocode->opcode = op; + new_ocode->length = len; + if ((unsigned int)len>4 || len==3) + ierr(G_CODE,1); + new_ocode->oper1 = ap1; + new_ocode->oper2 = ap2; +#ifdef PC +/* if (op>=op_add && op<=op_subq && ap1->mode>am_areg && ap2->mode>am_areg + && ap1->mode!=am_immed) + fatal("INVALID INSTRUCTION"); + if ((long)new_ocode==0x7a6314) + bkpt();*/ +/* if (lineid==1157) + bkpt();*/ +#endif +#ifdef DB_POSSIBLE + new_ocode->line=lineid; +#endif + add_peep(new_ocode); +} + +void g_coder(enum(e_op) op, int len, struct amode *ap1, struct amode *ap2) { +/* + * generate a code sequence and put it in front of the list + */ + struct ocode *new_ocode; + new_ocode = (struct ocode *) xalloc((int) sizeof(struct ocode), OCODE+G_CODE); + new_ocode->opcode = op; + new_ocode->length = len; + new_ocode->oper1 = ap1; + new_ocode->oper2 = ap2; +#ifdef DB_POSSIBLE + new_ocode->line=lineid; +#endif + if (peep_head == 0) { + /* must use add_peep to take care of peep_tail */ + add_peep(new_ocode); + } else { + new_ocode->back = 0; + new_ocode->fwd = peep_head; + peep_head->back = new_ocode; + peep_head = new_ocode; + /* peep_tail does not change */ + } +} + +/* should be in add_peep(), but SConvert would put it in the text */ +/* segment, preventing it from being modified */ +#ifndef VCG +xstatic struct ocode *peep_tail CGLOB; +#endif + +void add_peep(struct ocode *new_ocode) { +/* + * add the ocode pointed to by new to the peep list. + */ + if (peep_head == 0) { + peep_head = peep_tail = new_ocode; + } else { + new_ocode->back = peep_tail; + peep_tail->fwd = new_ocode; + peep_tail = new_ocode; + } +#ifndef NOFLOAT + if (new_ocode->opcode==op_jsr && new_ocode->oper1->mode==en_nacon) { + struct enode *ep=new_ocode->oper1->offset; + char *s=ep->v.ensp; + if (!strcmp("iround",s) || !strcmp("uround",s) || !strcmp("ifloor",s)) { + int lab=nxtlabel(); +#ifdef AS + ep->v.enlab=label( +#endif + ep->v.ensp=strsave(s[0]=='i'?str(ffpftol):str(ffpftou)) +#ifdef AS + ) +#endif + ; + g_code(s[1]=='r'?op_bhs:op_bge, 1, mk_label(lab), NIL_AMODE); + g_code(s[1]=='r'?op_addq:op_subq, 4, mk_immed(1), + (struct amode *) xalloc((int) sizeof(struct amode), AMODE)); + #ifdef NO_CALLOC + #error Above line bugs. + #endif + g_label(lab); + } + } +#endif +} + +extern unsigned int pos; +void g_label(unsigned int labno) { +/* + * add a compiler-generated label to the peep list. + */ +#ifdef NEWLAB + struct lbls *new_ocode; +/* if (pos==0x25D2 && labno==1) + printf("ghio");*/ + new_ocode = (struct lbls *) xalloc((int) sizeof(struct lbls), OCODE+G_LABEL); + new_ocode->opcode = op_label; + new_ocode->lab = labno; + add_peep((struct ocode *)new_ocode); +#else + struct ocode *new_ocode; + new_ocode = (struct ocode *) xalloc((int) sizeof(struct ocode), OCODE+G_LABEL); + new_ocode->opcode = op_label; + new_ocode->oper1 = mk_immed((long) labno); + add_peep(new_ocode); +#endif +} + +void flush_peep() { +/* + * output all code and labels in the peep list. + */ +#ifndef AS + register struct ocode *ip; + register int line; +#endif +#ifdef SHOWSTEP + printf("\npeep"); +#endif + opt3(); /* do the peephole optimizations */ +#ifdef SHOWSTEP + printf(" ok "); + printf("\nflush"); +#endif + _peep_head=peep_head; +#ifndef AS + ip = peep_head; + line = -1; + if (DEBUG && func_sp) + fprintf(output,"; function '%s'\n",func_sp->name); + while (ip != 0) { + if (ip->opcode == op_label) + put_label((unsigned int) getlab(ip)); + else { + #ifdef DB_POSSIBLE + if (DEBUG && line!=ip->line) + fprintf(output,"; line %d\n",line=ip->line); + #endif + put_code(ip->opcode, ip->length, ip->oper1, ip->oper2); + } + ip = ip->fwd; + } + if (DEBUG) + fprintf(output,"; end of function\n"); +#else + scope_head = peep_head; +#endif + peep_head = 0; +#ifdef SHOWSTEP + printf(" ok "); +#endif +} + +static void peep_delete(struct ocode *ip) { +/* + * delete an instruction referenced by ip + */ + if (ip == 0) + ierr(PEEP_DELETE,1); + + if (ip->back) { + if ((ip->back->fwd = ip->fwd) != 0) + ip->fwd->back = ip->back; + next_ip = ip->back; + } else { + if ((peep_head = ip->fwd) != 0) + peep_head->back = 0; + next_ip = peep_head; + } +} + +static void peep_pea(struct ocode *ip) { +/* + * changes lea ,An + pea (An) to pea + * The value of An is not needed (An is scratch register) + * CAVEAT code generator modifier! + */ + struct ocode *prev; + if (ip->oper1->mode != am_ind) + return; + if ((prev = ip->back) == 0) + return; + if (prev->opcode == op_lea && prev->oper2->preg == ip->oper1->preg + && ip->oper1->preg <= MAX_ADDR) { + prev->opcode = op_pea; + prev->oper2 = 0; + peep_delete(ip); + } +} + +static void peep_lea(struct ocode *ip) { +/* + * changes lea ,An + move.l An,Am to lea ,Am + * -- the value of An is not needed (An scratch, Am typically tempref) + * and lea ,An + move.* (An),An to move.* ,An + * CAVEAT code generator modifier! + */ + struct ocode *next; + reg_t reg; + restart: + if ((next = ip->fwd) == 0 +#if defined(AS) && defined(ASM) + || next->opt +#endif + ) + return; + if (next->opcode == op_move && ip->oper2->preg <= MAX_ADDR && + next->oper1->mode == am_areg && next->oper1->preg == ip->oper2->preg + && next->oper2->mode == am_areg && next->oper2->preg > MAX_ADDR) { + ip->oper2 = next->oper2; + peep_delete(next); + goto restart; + } + /* lea ,An + move.* (An),An => move.* ,An */ + if (next->opcode == op_move && next->oper1->mode == am_ind) + if (((reg=next->oper1->preg) == ip->oper2->preg) && next->oper2->mode == am_areg && + (reg==next->oper2->preg)) { + ip->opcode = op_move; + ip->length = next->length; + peep_delete(next); + } +} + +static void peep_move(struct ocode *ip) { +/* + * peephole optimization for move instructions. + * makes quick immediates when possible (redundant for most assemblers). + * changes move #0 to clr except on address registers + * changes move #0 to address registers to sub An,An + * changes long moves to address registers to short when possible. + * changes move immediate/areg to stack to pea. + * changes move immediate to An to lea. + * deletes move , (The code generator does not know that this sets + * the flags, and it is necessary for peep_and + * to work correctly if ea is am_dreg) + */ + struct enode *ep; +#ifdef ADVANCED_MEMORY_MOVE + struct ocode *next; +#endif + + if (equal_address(ip->oper1, ip->oper2) && +/* + * move.w An,An changes the contents of An through sign extension + */ + (ip->oper1->mode != am_areg || ip->length != 2)) { + peep_delete(ip); + return; + } + if ((ip->oper1->mode == am_areg || ip->oper1->mode == am_immed) + && ip->oper2->mode == am_adec && ip->oper2->preg == 7 + && ip->length == 4) { + ip->opcode = op_pea; + ip->length = 0; + ip->oper1 = copy_addr(ip->oper1); + am_doderef(ip->oper1->mode); + ip->oper2 = 0; + return; + } +//#if 0 +#ifdef ADVANCED_TEMP_REGS +#ifndef INFINITE_REGISTERS + if (ip->oper1->mode==am_dreg && ip->oper1->preg<=MAX_DATA + && ip->oper2->mode==am_dreg) { + struct ocode *ip_save=ip; + reg_t a=ip->oper1->preg,b=ip->oper2->preg,s=ip->length; + struct amode *ap,*destap=ip->oper2; + /* BUGGY: we should check if da isn't used afterwards... + * Currently, g_assign does in such way that it returns Db + * rather than Da, so it should work fine in most cases, + * but it might fail eg with custom asm statements */ + ip=ip->back; + while (ip) { + switch (ip->opcode) { + case op_label: + case op_jsr: + case op_bxx: + case op_dbxx: + case op_dc: // this might mean op_jsr... + return; + case op_ext: + if (ip->oper1->mode==am_dreg && ip->oper1->preg==a) { + s=ip->length>>1; + break; + } + if ((ap=ip->oper1) && ap->mode==am_dreg && ap->preg==b) { +#ifdef PC + if (ip->length && ip->length<=s) + fatal("OP DISCARDED BY ASSIGNMENT"); + else +#endif + return; + } + break; + case op_clr: + ap=ip->oper1; + goto check_ok; + case op_move: + case op_moveq: + case op_lea: + ap=ip->oper2; + check_ok: + if (ap->mode==am_dreg && ap->preg==a) { + if (ip->length && ip->length oper1) && ((ap->mode==am_dreg && ap->preg==b) || + (ap->mode==am_indx2 && ap->sreg==b))) + return; + if ((ap=ip->oper2) && ap->mode==am_indx2 && ap->sreg==b) + return; + if ((ap=ip->oper2) && ap->mode==am_dreg && ap->preg==b) { +#ifdef PC + if (ip->length && ip->length<=s) + fatal("OP DISCARDED BY ASSIGNMENT"); + else +#endif + return; + } + } + ip=ip->back; + } + ierr(UNINIT_TEMP,1); + ok_atr: + next_ip=ip; + ip=ip_save; + while (ip!=next_ip) { + if (ip->oper1 && ip->oper1->mode==am_dreg && ip->oper1->preg==a) + ip->oper1=destap; + if (ip->oper2 && ip->oper2->mode==am_dreg && ip->oper2->preg==a) + ip->oper2=destap; + ip=ip->back; + } + if (ip->opcode==op_clr) + ip->oper1=destap; + else ip->oper2=destap; + return; + } +#endif +#endif +#ifdef ADVANCED_MEMORY_MOVE + /* try to use post-increment where possible */ + /* (might be improved to allow for interstitial instructions, but + beware of modifications of _any_ of _both_ indexing registers...) */ + if (ip->oper2->mode == am_indx && (next=ip->fwd) && next->opcode==op_move + && next->oper2->mode == am_indx && next->oper2->preg == ip->oper2->preg + && next->oper2->offset->v.i-ip->oper2->offset->v.i==ip->length) { + int reg=-1; +#ifndef INFINITE_REGISTERS + if (arsearch(0,ip)) + reg=8; + else if (arsearch(1,ip)) + reg=9; +#endif + if (reg IS_VALID) { + struct ocode *load = xalloc(sizeof(struct ocode),OCODE); + long offs; struct amode *ap; + load->opcode=op_lea; + load->oper1=ip->oper2; + load->oper2=mk_reg(reg); + load->line=ip->line; + load->back=ip->back; + load->fwd=ip; + load->back->fwd=load; + ip->back=load; + next=ip; + reg=ip->oper2->preg; + offs=ip->oper2->offset->v.i; + ap=mk_reg(reg); ap->mode=am_ainc; + do { + next->oper2=ap; + offs+=next->length; + next=next->fwd; + } while (next->opcode==op_move && next->oper2->preg==reg + && next->oper2->mode==am_indx + && next->oper2->offset->v.i==offs); + } + } +#endif + if (ip->oper1->mode != am_immed) + return; +#ifdef ADVANCED_MEMORY_MOVE + /* optimize contiguous -(an)/(an)+ assignments */ + restart_advmove: + if (am_is_increment(ip->oper2->mode) && ip->length<=2 && (next=ip->fwd) + && next->opcode==op_move && ip->oper1->offset->nodetype==en_icon + && next->oper1->mode == am_immed && next->oper2->mode==ip->oper2->mode + && next->length==ip->length + && next->oper1->offset->nodetype==en_icon) { + unsigned short a,b; /* very important *not* to be long's !!! */ + a=(unsigned short)ip->oper1->offset->v.i,b=(unsigned short)next->oper1->offset->v.i; + if (ip->oper2->mode==am_adec) + b=a,a=(unsigned short)next->oper1->offset->v.i; + ip->oper1=copy_addr(ip->oper1); + ip->oper1->offset = + mk_icon((ip->length==2?((long)a<<16)|b:(long)(unsigned short)((a<<8)|(unsigned char)b))); + ip->length<<=1; + peep_delete(next); + if (ip->back->opcode==op_move) { + next_ip=ip->back; + return; + } else goto restart_advmove; + /* + move.b #0,(a0)+ <- + move.b #0,(a0)+ + move.b #0,(a0)+ + move.b #0,(a0)+ + -> + move.w #0,(a0)+ <- + move.b #0,(a0)+ + move.b #0,(a0)+ + -> + clr.w (a0)+ + move.b #0,(a0)+ <- + move.b #0,(a0)+ + -> + clr.w (a0)+ <- + move.w #0,(a0)+ + -> + clr.w (a0)+ <- + move.w #0,(a0)+ + -> + move.l #0,(a0)+ <- + -> + clr.l (a0)+ <- + */ + } +#endif + + ep = ip->oper1->offset; + if (ip->oper2->mode == am_areg && ep->nodetype == en_icon) { + if (ep->v.i == 0) { + ip->length = 4; + ip->opcode = op_sub; + ip->oper1 = ip->oper2; + } else if (-32768 <= ep->v.i && ep->v.i <= 32767) + ip->length = 2; + return; + } + if (ip->oper2->mode == am_dreg && ep->nodetype == en_icon + && -128 <= ep->v.i && ep->v.i <= 127) { + ip->opcode = op_moveq; + ip->length = 0; + return; + } + if (ep->nodetype == en_icon && ep->v.i == 0) { + ip->opcode = op_clr; + ip->oper1 = ip->oper2; + ip->oper2 = 0; + return; + } + if (ip->oper2->mode == am_areg && ip->length == 4) { + next_ip = ip; + ip->opcode = op_lea; + ip->length = 0; + ip->oper1 = copy_addr(ip->oper1); + ip->oper1->mode = am_direct; + return; + } +} + +int equal_address(struct amode *ap1, struct amode *ap2) { +/* + * compare two address nodes and return true if they are equivalent. + */ + if (ap1 == 0 || ap2 == 0) + return 0; + if (ap1->mode != ap2->mode) + return 0; + switch (ap1->mode) { + case am_areg: + case am_dreg: + case am_ind: + return ap1->preg == ap2->preg; + case am_indx: + return ap1->preg == ap2->preg && + ap1->offset->nodetype == en_icon && + ap2->offset->nodetype == en_icon && + ap1->offset->v.i == ap2->offset->v.i; + case am_indx2: + case am_indx3: + return + ap1->preg == ap2->preg && + ap1->sreg == ap2->sreg && + ap1->slen == ap2->slen && + ap1->offset->nodetype == en_icon && + ap2->offset->nodetype == en_icon && + ap1->offset->v.i == ap2->offset->v.i; + } + return 0; +} + +static void peep_movem(struct ocode *ip) { +/* + * peephole optimization for movem instructions. movem instructions are used + * to save registers on the stack. if 1 or 2 registers are being saved we + * can convert the movem to move instructions. + */ + int i,mask,n,t,a,b=0; + struct ocode *root; + +#ifdef PC + a=1234; /* prevent a warning from being output - we can afford this on PC :) */ +#endif + + if (ip->oper1->mode == am_mask1) + mask = getop1(ip); + else mask = getop2(ip); + + t=1,n=2,i=16; + while (i--) { + if (mask & t) { + b=a,a=i; + if (--n<0) return; + } + t<<=1; + } + root=ip; + ip->opcode = op_move; + if ((i=1-n)) { + struct ocode *new_ocode = (struct ocode *) + xalloc((int) sizeof(struct ocode), OCODE); + new_ocode->opcode = op_move; + new_ocode->length = ip->length; + new_ocode->oper1 = copy_addr(ip->oper1); + new_ocode->oper2 = copy_addr(ip->oper2); +#ifdef DB_POSSIBLE + new_ocode->line=ip->line; +#endif + new_ocode->back = ip; + if ((new_ocode->fwd=ip->fwd)) + ip->fwd->back=new_ocode; + ip->fwd=new_ocode; + } + do { + if (ip->oper1->mode == am_mask1) { + if ((ip->oper1->preg = a) >= 8) { + ip->oper1->mode = am_areg; + ip->oper1->preg -= 8; +#ifdef INFINITE_REGISTERS + ip->oper1->preg += TAREGBASE-AREGBASE; +#endif + } else { + ip->oper1->mode = am_dreg; +#ifdef INFINITE_REGISTERS + ip->oper1->preg += TDREGBASE; +#endif + } + } else { + if ((ip->oper2->preg = 15 - a) >= 8) { + ip->oper2->mode = am_areg; + ip->oper2->preg -= 8; +#ifdef INFINITE_REGISTERS + ip->oper2->preg += TAREGBASE-AREGBASE; +#endif + } else { + ip->oper2->mode = am_dreg; +#ifdef INFINITE_REGISTERS + ip->oper2->preg += TDREGBASE; +#endif + } + } + ip=ip->fwd; + a=b; + } while (i--); + next_ip=root; /* optimize move.l An,-(a7) => pea (An) */ +} + +int drsearch(int r,struct ocode *ip) { + while ((ip=ip->fwd)) { + struct amode *ap=ip->oper1; + int n=0; + do { + switch (ap->mode) { + case am_dreg: + if (ap->preg==r) + return n && op_destroy(ip->opcode); + case am_areg: + case am_ind: case am_adec: case am_ainc: case am_indx: + case am_indx3: + break; + case am_indx2: + if (ap->sreg==r) + return 0; + break; + } + n++; + } while ((ap=ip->oper2)); + } + return 1; +} + +int arsearch(int r,struct ocode *ip) { + struct amode *ap; int n,z; +// printf("$%d",r); + z=0; + while ((ip=ip->fwd) && ip->opcode!=op_rts) { + if (ip->opcode==op_label) continue; +#ifdef INFINITE_REGISTERS + if (ip->opcode==_op_cleanup_for_external_call) continue; +#endif + z++; + ap=ip->oper1; + n=0; + do { + switch (ap->mode) { + case am_areg: + if (ap->preg==r) { +// printf("*%d ",z); + return n && op_destroy(ip->opcode); + } + case am_dreg: + break; + case am_indx3: + if (ap->sreg==r) { +// printf("-%d ",z); + return 0; + } + /* FALL THROUGH */ + case am_ind: case am_adec: case am_ainc: case am_indx: + case am_indx2: + if (ap->preg==r) { +// printf("-%d ",z); + return 0; + } + break; + } + n++; + } while ((ap=ip->oper2) && n==1); + } +// printf("/%d ",z); + return 1; +} + +static void peep_addsub(struct ocode *ip, enum (e_op) op) { +/* + * peephole optimization for add/sub instructions. +A* changes add/sub.* Rn,An; move (An),X to move 0(An,+/- Rn.*),X +A* changes add/sub.* Rn,An; move x(An),X to move x(An,+/- Rn.*),X +A* changes add/sub #x,An; move 0(An,Rn.*),X to move x(An,+/- Rn.*),X + * makes quick immediates out of small constants (redundant for most as's). + * change add/sub immediate to address registers to lea where possible +A* and try to avoid operand volatilizing when doing so + */ + struct enode *ep; + struct ocode *next=ip->fwd; +#ifdef ADV_OPT + int reg; + if (next +#ifdef AS + && !next->opt +#endif + && next->opcode==op_move + && ip->oper2->mode==am_areg && (reg=ip->oper2->preg)==next->oper1->preg + && arsearch(reg,next)) { + int sub=op-op_add,ok=0,sz=ip->length,sreg=ip->oper1->preg; + long offs=next->oper1->offset?getop1(next):0; +/* infunc("InitLevel") + bkpt();*/ + ok=next->oper1->mode; + if (ip->oper1->mode==am_dreg || ip->oper1->mode==am_areg) { + if (ok==am_ind) + offs=0; + else if (ok!=am_indx) + ok=0; + /* if we do the conversion, select am_indx2/3 appropriately */ + if (ok) + ok=ip->oper1->mode-am_dreg+am_indx2; + } else if (ip->oper1->mode==am_immed) { + sz=next->oper1->slen; + sreg=next->oper1->sreg; + offs=getop1(ip); + if (sub) offs=-offs; + sub=0; + if (ok==am_indx3) + sreg+=AREGBASE; + else if (ok!=am_indx3) + ok=0; + } else ok=0; + if (ok && offs>=-128 && offs<128) { + if (sub) ip->opcode=op_neg,ip->oper2=NULL; + else peep_delete(ip); + next->oper1=copy_addr(next->oper1); + next->oper1->mode=ok; + next->oper1->slen=sz; + next->oper1->sreg=sreg; + next->oper1->offset=mk_icon(offs); + return; + } + } +#endif + if (ip->oper2->preg == STACKPTR-AREGBASE && ip->length == 2) { /* alloca... */ + last_param_pop = NULL; + } + if (ip->oper1->mode == am_immed) { + ep = ip->oper1->offset; + if (ip->oper2->mode != am_areg) + ip->opcode = op+op_addi-op_add; + if (ep->nodetype != en_icon) + return; +#ifdef POP_OPT + if (ip->oper2->preg == STACKPTR-AREGBASE && + ip->oper2->mode == am_areg && ip->length == 4) { /* parameter popping */ + if (last_param_pop) + ep->v.i+=getop1(last_param_pop), peep_delete(last_param_pop); + last_param_pop = ip; + } +#endif +/* if (!ep->v.i) { // unnecessary + peep_delete(ip); + return; + }*/ + if (1 <= ep->v.i && ep->v.i <= 8) { + ip->opcode = op+op_addq-op_add; + return; + } + if (-8 <= ep->v.i && ep->v.i <= -1) { + ip->opcode = op==op_add?op_subq:op_addq; + ep->v.i = -ep->v.i; + return; + } + if (ip->oper2->mode == am_areg && isshort(ep)) { + ip->oper1 = copy_addr(ip->oper1); + ip->oper1->mode = am_indx; + ip->oper1->preg = ip->oper2->preg; + if (op==op_sub) ip->oper1->offset=mk_icon(-getop1(ip)); + ip->length = 0; + ip->opcode = op_lea; + next_ip = ip; +#ifdef ADV_OPT + if (ip->back && ip->back->opcode==op_move && ip->back->oper2->mode==am_areg + && ip->back->oper2->preg==ip->oper1->preg + && ip->back->oper1->mode==am_areg + && arsearch(ip->oper1->preg,ip)) + ip->oper1->preg=ip->back->oper1->preg, peep_delete(ip->back); +#endif + return; + } + } +} + +static void peep_and(struct ocode *ip) { +/* + * conversion of unsigned data types often yields statements like + * move.b source,d0 + andi.l #255,d0 + * which should be converted to + * clr.l d0 + move.b source,d0 + * deletes and #-1 + */ + struct ocode *prev; + int size; + long arg; + if (ip->oper1->mode != am_immed || + ip->oper1->offset->nodetype != en_icon) + return; + arg = getop1(ip); + /* + * and #-1 does only set flags, which the code generator does not know + */ + if (arg == -1) { + peep_delete(ip); + return; + } + if (ip->oper1->mode != am_immed || + (arg != 255 && arg != 65535)) + return; + + size = (arg == 255) ? 1 : 2; + + /* move.b,dn; and.* #$FF,dn condition que != x(An,Dn) */ + /* move.w ,dn; and.* #$FFFF,dn condition que != x(An,Dn) */ + if ((prev = ip->back) == 0 || prev->length != size + || prev->opcode != op_move + || ip->oper2->mode != am_dreg || prev->oper2->mode != am_dreg + || ip->oper2->preg != prev->oper2->preg + || (prev->oper1->mode == am_indx2 && + prev->oper1->sreg == prev->oper2->preg)) + return; + + prev->length = ip->length; + ip->length = size; + prev->opcode = op_clr; + ip->opcode = op_move; + ip->oper1 = prev->oper1; + prev->oper1 = prev->oper2; + prev->oper2 = 0; + + next_ip = prev; +} + +static void peep_clr(struct ocode *ip) { +/* + * removes consecutive clr-statements + * + */ + struct ocode *prev; + + if ((prev = ip->back) == 0 || prev->opcode != op_clr || + !equal_address(ip->oper1, prev->oper1)) + return; + + if (prev->length < ip->length) + prev->length = ip->length; + + peep_delete(ip); +} + +static void peep_cmp(struct ocode *ip) { +/* + * peephole optimization for compare instructions. + * changes compare #0 to tst + * + */ + struct enode *ep; + if (ip->oper1->mode != am_immed) + return; + ep = ip->oper1->offset; + if (ip->oper2->mode == am_areg) + /* cmpa.w extents the first argument automatically */ + { + if (isshort(ep)) + ip->length = 2; + return; + } + ip->opcode = op_cmpi; + if (ep->nodetype != en_icon || ep->v.i != 0) + return; + ip->oper1 = ip->oper2; + ip->oper2 = 0; + ip->opcode = op_tst; + next_ip = ip; +} + +static void peep_tst(struct ocode *ip) { +/* + * deletes a tst instruction if the flags are already set. + */ + struct ocode *prev,*next; + enum(e_op) op; + prev = ip->back; + if (prev == 0) + return; +/* + * All the following cases used to be checked with an obscure + * if-statement. There was an error in it that caused prev->oper2->mode + * to be referenced even if prev->opcode is op_clr. (This yields a NIL- + * pointer reference. + * I threw all this stuff away and replaced it by this case-statement. + * This is much more readable. + */ + switch (prev->opcode) { + case op_label: + case op_dc: + case _op_asm: + case _op_adj: +/* + * List all pseudo-instructions here. Of course, they do not do + * anything. + */ + return; + + case op_move: +/* + * A move TO an address register does not set the flags + */ + if (prev->oper2->mode == am_areg) + return; + case op_moveq: + case op_clr: + case op_ext: +/* + * All other move and clr instructions set the flags according to + * the moved operand, which is prev->oper1 + */ + if (equal_address(prev->oper1, ip->oper1)) + break; + if (equal_address(prev->oper2, ip->oper1)) + break; + return; + case op_btst: case op_bset: case op_bclr: case op_bchg: + case op_cmp: + /* these instructions affect the flags in a non-standard way */ + case op_swap:/*[longword test]*/ + /* FALL THROUGH */ + case op_exg: + /* these instructions don't affect the flags */ + return; + default: +/* + * All instructions that have a target set the flags according to the + * target (prev->oper2) + * Note that equal_address may be called with a NIL pointer -> OK for clr + */ + next = ip->fwd; + if (next && ((op=next->opcode)==op_beq || op==op_bne) + && !(next->fwd && (op=next->fwd->opcode)>=_op_bcond_min && op<=_op_bxx_max)) + if (equal_address(prev->oper2, ip->oper1)) + break; + return; + } +/* + * We come here if the flags are already set, thus the tst + * instruction can be deleted. + */ + if (ip->length==prev->length) + peep_delete(ip); +} + +static void peep_uctran(struct ocode *ip) { +/* + * peephole optimization for unconditional transfers. deletes instructions + * which have no path. applies to bra, jmp, and rts instructions. + */ + while (ip->fwd != 0 && ip->fwd->opcode != op_label) + peep_delete(ip->fwd); + next_ip=ip->fwd; +} + +static void peep_bxx(struct ocode *ip) { +/* + * optimizes conditional branch over a bra. + */ + struct ocode *next = ip->fwd; + if (next && next->opcode == op_bra) { + /* peep_uctran increases the 'hit' probability */ + peep_uctran(next); + while ((next = next->fwd) && next->opcode == op_label) + if (getoplab(ip) == getlab(next)) { + /* bxx \lab | bra \out | ... | \lab: + * => (peep_uctran) + * bxx \lab | bra \out | \lab: + * => + * byy \out | \lab: + */ + ip->fwd->opcode = revcond[(int)ip->opcode - (int)_op_bcond_min]; + ip=ip->fwd; + peep_delete(ip->back); + break; + } + } + if (ip->opcode==op_bhs && ip->back && ip->back->opcode==op_subq + && ip->back->oper1->offset->v.i==1 /* since oper1->mode is am_immed->en_icon */ + && ip->back->oper2->mode==am_dreg) + ip->opcode=op_dbra, + ip->oper2=ip->oper1, + ip->oper1=ip->back->oper2, + peep_delete(ip->back); +} + +static void peep_label(struct ocode *ip) { +/* + * if a label is followed by a branch to another label, the + * branch statement can be deleted when the label is moved + */ + struct ocode *prev, *next, *target; + long label; + last_param_pop = NULL; // reset function parameter popping optimization + prev = ip->back; + + if ((next = ip->fwd) == 0 || next->opcode != op_bra || next->oper1->offset->nodetype!=en_labcon) + return; + /* + * To make this fast, assume that the label number is really + * getoplab(next) + */ + label = getoplab(next); + if (label == getlab(ip)) + return; + target = peep_head; + /* + * look for the label + */ + while (target != 0) { + if (target->opcode == op_label + && getlab(target) == label) + break; + target = target->fwd; + } + /* we should have found it */ + if (target == 0) { +#ifdef VCG + if (vcg_lvl==VCG_MAX) +#endif + iwarn(PEEP_LABEL,1); + return; + } + /* move label */ + peep_delete(ip); + ip->fwd = target->fwd; + ip->back = target; + target->fwd = ip; + if (ip->fwd != 0) + ip->fwd->back = ip; + /* possibly remove branches */ + /* in fact, prev is always != 0 if peep_delete has succeeded */ + if (prev != 0) { + if (prev->opcode == op_bra || prev->opcode == op_jmp + || prev->opcode == op_rts) + peep_uctran(prev); + else if (prev->opcode == op_label) + next_ip=prev; /* so that peep_label will be called once again (this label + * might be aliased by other ones) */ + } +} + +void opt3(void) { +/* + * peephole optimizer. This routine calls the instruction specific + * optimization routines above for each instruction in the peep list. + */ +//#define NO_PEEP +#ifndef NO_PEEP + struct ocode *ip; + enum(e_op) instr; + next_ip = peep_head; + if (!opt_option) + return; + instr=-1; + last_param_pop = NULL; + while (next_ip != 0) { +/* if (ip->opcode==instr) + if (!(ip = ip->fwd)) break; + instr=ip->opcode;*/ + ip = next_ip; + next_ip = ip->fwd; +#ifdef AS + if (ip->opcode!=op_label && ip->opt) + continue; +#endif + switch (ip->opcode) { + case op_move: + peep_move(ip); + break; + case op_movem: + peep_movem(ip); + break; + case op_pea: + peep_pea(ip); + break; + case op_lea: + peep_lea(ip); + break; + case op_ext: { /* ext.l Dn ; add/sub Dn,Am (where Dn is a word) */ + struct ocode *nxt=ip->fwd; reg_t reg; + if (!nxt || (nxt->opcode!=op_add && nxt->opcode!=op_sub) +#if defined(AS) && defined(ASM) + || nxt->opt +#endif + || ip->length!=4 || nxt->oper1->mode!=am_dreg + || (reg=nxt->oper1->preg)!=ip->oper1->preg + || nxt->oper2->mode!=am_areg + || (reg>MAX_DATA && regexp[reg_t_to_regexp(reg)]->esize==4)) + break; + peep_delete(ip); + nxt->length=2; + } break; + case op_add: + case op_sub: + peep_addsub(ip,ip->opcode); + //peep_add/peep_sub(ip); + break; + case op_and: + peep_and(ip); + break; + case op_clr: + peep_clr(ip); + break; + case op_cmp: + peep_cmp(ip); + break; + case op_tst: + peep_tst(ip); + break; + case op_beq: + case op_bne: + case op_bgt: + case op_bge: + case op_blt: + case op_ble: + case op_blo: + case op_bls: + case op_bhi: + case op_bhs: + peep_bxx(ip); + /* FALL THROUGH */ + last_param_pop = NULL; // reset function parameter popping optimization + break; + case op_dbxx: + last_param_pop = NULL; // reset function parameter popping optimization + break; + case op_bra: + last_param_pop = NULL; // reset function parameter popping optimization + peep_uctran(ip); + /* delete branches to the following statement */ + { + struct ocode *p = ip->fwd; + long label = getoplab(ip); + while (p != 0 && p->opcode == op_label) { + if (getlab(p) == label) { + peep_delete(ip); + ip = 0; + break; + } + p = p->fwd; + } + } + if (!ip) + break; +#ifdef SPEED_OPT + if (next_ip && speed_opt_value>0) { /* then it's necessarily a label, due to peep_uctran */ + int i,lab=getoplab(ip); + struct ocode *p=peep_head,*s,*e; + do { + if (p->opcode==op_label && getlab(p)==lab) break; + } while ((p=p->fwd)); + if (!p) break; + s=p; + lab=getlab(next_ip); + i=speed_opt_value; + /* NOTE : we ought never stop copying on a 'bra', but rather go on */ + do { + if (!(p=p->fwd)) goto bad; + if (p->opcode==op_label) i++; /* don't count it as an instruction */ + else if (p->opcode>=_op_bcond_min && p->opcode<=_op_bxx_max + && getoplab(p)==lab) { + break; + } else if (p->opcode==op_bra || p->opcode==op_jmp || p->opcode==op_rts) + break; +#ifndef ALLOW_TWIN_STACK_OPS + else { + struct amode *ap=p->oper1; + if (ap && ap->mode==am_ainc && ap->preg==7) + goto bad; + ap=p->oper2; + if (ap && (ap->mode==am_areg || ap->mode==am_adec) && ap->preg==7) + goto bad; + } +#endif + } while (i--); + if (i>=0) { + struct ocode *prv,*nxt; + e=p; + p=s; + prv=ip->back; + next_ip=prv; + nxt=ip->fwd; + peep_delete(ip); + do { + p=p->fwd; + if (p->opcode!=op_label) { + struct ocode *n=(struct ocode *) + xalloc(sizeof(struct ocode), OCODE); + *n=*p; + if (p==e && p->opcode>op_bra) { /* we assume that op_jmp fwd,*nl; + int dlab; + if (pn->opcode==op_label) dlab=getlab(pn); + else { + dlab=nxtlabel(); + #ifdef NEWLAB + nl = (struct ocode *) xalloc((int) sizeof(struct lbls), OCODE); + nl->opcode = op_label; + ((struct lbls *)nl)->lab = dlab; + #else + nl = (struct ocode *) xalloc((int) sizeof(struct ocode), OCODE); + nl->opcode = op_label; + nl->oper1 = mk_immed((long)dlab); + #endif + p->fwd=nl; + nl->back=p; + nl->fwd=pn; + pn->back=nl; + } + n->opcode=revcond[p->opcode-_op_bcond_min]; + n->oper1=mk_label(dlab); + } + n->back=prv; + prv->fwd=n; + prv=n; + } + } while (p!=e); + prv->fwd=nxt; + nxt->back=prv; + next_ip=next_ip->fwd; + } + } +bad: +#endif + break; + case op_jmp: + case op_rts: + last_param_pop = NULL; // reset function parameter popping optimization + peep_uctran(ip); + break; + case op_label: + peep_label(ip); + break; + case _op_adj: + peep_delete(ip); + /* FALL THROUGH */ + case _op_asm: + last_param_pop = NULL; // reset function parameter popping optimization + break; + } + } +#endif +} +#ifdef VCG +#include "vcg.c" +#endif + +#endif /* MC680X0 */ +// vim:ts=4:sw=4 diff --git a/gtc/src/preproc.c b/gtc/src/preproc.c new file mode 100644 index 0000000..85e5871 --- /dev/null +++ b/gtc/src/preproc.c @@ -0,0 +1,572 @@ +/* + * GTools C compiler + * ================= + * source file : + * preprocessor + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#define USE_MEMMGT +#include "cglbdec.h" +#ifdef PCH +#include "pch.h" +#endif + +extern char *curname; +extern char *lptr; +char *inclname[10]; +FILE *inclfile[10]; +int inclifreldepth[10]; +int incldepth CGLOB; +#ifdef PCH +FILE *pchfile[20]; +char *pchdata[20] CGLOBL; +char *pchtab[20]; +#ifdef REQ_MGT +char pchname[20][15]; +char pchrequired[20]; +#endif +int pchnum CGLOB; +#endif +int inclline[10]; +int lineno CGLOB; +int lineid CGLOB; +int prevlineid CGLOB; +int flags CGLOB; +#ifdef PC +int verbose CGLOB; +#endif +#ifdef PC +int verbosity CGLOB; +#endif +int ifdepth CGLOB; +int ifreldepth CGLOB; +int ifcount[MAX_IF_DEPTH]; +int ifval[MAX_IF_DEPTH]; +int ifhas[MAX_IF_DEPTH]; +int ifskip CGLOB, ifsd CGLOB; + +HTABLE defsyms CGLOBL; + +extern int getline(int f); + +extern TYP *expression(); +extern unsigned char id_are_zero; + +int doinclude( +#ifdef PCH + int pch +#endif + ); + +extern enum(e_sym) forbid; +xstatic int pp_old_forbid CGLOB; +xstatic int pp_old_crc CGLOB; +xstatic char pp_old_id[MAX_ID_LEN+1]; + +/*static int mem_if=0,mem_def=0; +#define MEM_USE(x,s) mem_##x-=glbmem; s mem_##x+=glbmem;*/ + +int ppquit() { + if (pp_old_forbid IS_VALID) { + forbid=pp_old_forbid; + if (pp_old_forbid==id) memcpy(lastid,pp_old_id,MAX_ID_LEN+1), lastcrc=pp_old_crc; + } +#ifdef MACRO_PPDIR + if (*lptr) lptr=strchr(lptr,'\n')+1; + if (!*lptr) return getline(incldepth == 0); + else return 0; +#else + return getline(incldepth == 0); +#endif +} + +#if 0 +char *strend(char *s) { + while (*s++); + return s-1; +} +#endif + +int preprocess() { + if ((pp_old_forbid=forbid)==id) memcpy(pp_old_id,lastid,MAX_ID_LEN+1), pp_old_crc=lastcrc, + forbid=-1; + ++lptr; // skip '#' + lastch = ' '; + getch(); + getsym(); /* get first word on line */ + if(lastst != id && lastst != kw_if && lastst != kw_else) { + uerrc("preprocessor command expected"); + return ppquit(); + } +/* if (!strcmp(curname,"compat.h") && lineno>=23) + bkpt();*/ +/* if (!strcmp(curname,"messages.c") && lineno>=0) + bkpt();*/ + if (lastst == kw_if /*!strcmp(lastid,"if")*/ || !strcmp(lastid,"elif")) { + struct enode *ep; TYP *tp; enum(e_bt) typ; + int v=lastst==kw_if; + if (!v) ifskip=ifhas[ifdepth]; + if (ifskip) return doif(-1,v); +#ifndef MACRO_PPDIR + strcpy(lptr," ] "); // so that getsym() in the new expression will + getsym(); // not read any new line +#else + { + char *q=strchr(lptr,'\n'); + memmove(q+3,q,strlen(q)+1); + memcpy(q," ] ",3); + getsym(); + } +#endif + tmp_use(); + id_are_zero++; + tp=expression(&ep); + id_are_zero--; + if (!tp || lastst!=closebr) error(ERR_EXPREXPECT); + else if ((typ=tp->type)==bt_void || typ==bt_pointer) error(ERR_INTEGER); + else { + opt0(&ep); + if (ep->nodetype!=en_icon) error(ERR_CONSTEXPECT); + else { int w=doif(ep->v.i!=0,v); tmp_free(); return w; } + } + tmp_free(); + return ppquit(); + } else if (!strcmp(lastid,"ifdef") || !strcmp(lastid,"ifndef")) { + int v=lastid[2]!='d'; + if (ifskip) return doif(-1,1); + skipspace(); + if ((lastch>='A'&&lastch<='Z') || (lastch>='a'&&lastch<='z') + || lastch=='_' || lastch=='$') { + getidstr(); + return doif(v ^ !!search(lastid,lastcrc,&defsyms),1); + } else error(ERR_IDEXPECT); + return ppquit(); + } else if (lastst == kw_else/*!strcmp(lastid,"else")*/) { + if (!ifreldepth) uerrc("'#else' unexpected"); + else if (!ifskip || ifdepth<=ifsd) { + if (--ifcount[ifdepth]!=0) uerrc("'#else' unexpected"); + else ifskip = ifval[ifdepth]; + } + return ppquit(); + } else if (!strcmp(lastid,"endif")) { + if (!ifreldepth) uerrc("'#endif' unexpected"); + else { + ifdepth--, ifreldepth--; + if (ifdepth base); +#endif + progr_readtonow=0; +} +#endif +int doinclude( +#ifdef PCH + int pch +#endif + ) { + int rv; char c; + strcat(lptr," "); + skipspace(); + if ((c=lastch-'"') && c!='<'-'"') + goto incl_err; + getch(); + if (!((lastch>='A'&&lastch<='Z') || (lastch>='a'&&lastch<='z') + || lastch=='_' || lastch=='$' || lastch=='\\')) + goto incl_err; + getidstr(); /* get file to include, without extension */ +#ifdef PCH + if (!pch) { +#endif + inclline[incldepth] = lineno; + inclifreldepth[incldepth] = ifreldepth; +#ifdef GTDEV + inclread[incldepth] = progr_readtonow; + inclcoeff[incldepth] = progr_coeff; +#endif + inclname[incldepth] = curname; + inclfile[incldepth++] = input; /* push current input file */ + restart_h: + input = xfopen(lastid,"r",c); + if (!input) { + char *tigcclib_aliases = "all\0alloc\0args\0asmtypes\0assert\0bascmd\0basfunc\0basop\0cert\0compat\0ctype\0default\0dialogs\0dll\0error\0estack\0events\0files\0flash\0float\0gdraw\0graph\0graphing\0gray\0homescr\0intr\0kbd\0limits\0link\0math\0mem\0menus\0nostub\0peekpoke\0printf\0romsymb\0rsa\0setjmp\0sprites\0statline\0stdarg\0stddef\0stdio\0stdlib\0string\0system\0textedit\0timath\0unknown\0values\0vat\0version\0wingraph\0"; + while (*tigcclib_aliases) + if ( + #ifdef PC + !strncmp(lastid,tigcclib_aliases,strlen(tigcclib_aliases)) && !strcmp(lastid+strlen(tigcclib_aliases),".h") + #else + !strcmp(lastid,tigcclib_aliases) + #endif + ) { + #ifdef PC + strcpy(lastid,"tigcclib.h"); + #else + strcpy(lastid,"tigcclib"); + #endif + goto restart_h; + } else { + while (*tigcclib_aliases++); + } +// input = inclfile[--incldepth]; + uerr(ERR_CANTOPEN,lastid); +// _exit(18); + } + ifreldepth = 0; +#ifdef GTDEV + progr_initforcurfile(); +#endif + global_flag++; + curname = strsave(lastid); + global_flag--; +#ifdef PCH + } else { + char b[30]; +#ifdef REQ_MGT + int i=pchnum; + while (i--) + if (!strcmp(lastid,pchname[i])) + goto done; +#endif +#ifdef PC + sprintf(b,"%s.pch",lastid); +#else + sprintf(b,"zheader\\%s",lastid); +#endif + if (!(pchfile[pchnum] = xfopen(b, "rb", c))) { + if (pch<0) + goto done; + uerr(ERR_CANTOPEN,b); +// _exit(18); + } +#ifdef REQ_MGT + strcpy(pchname[pchnum],lastid); + pchrequired[pchnum]=0; +#endif +#ifdef PC + pchdata[pchnum] = malloc(150000); + fread(pchdata[pchnum],1,150000,pchfile[pchnum]); + if (w2ul(pchhead[pchnum]->magic)!= + ((long)'P'<<24)+((long)'C'<<16)+((long)'H'<<8) + || !(pchtab[pchnum] = malloc(w2us(pchhead[pchnum]->nID)))) { + fclose(pchfile[pchnum]); + goto incl_err; + } +#define w2s(x) ((short)w2us(x)) +#else + if (w2ul(((PCH_HEAD *)(pchdata[pchnum] = *(char **)(pchfile[pchnum])))->magic)!= + ((long)'P'<<24)+((long)'C'<<16)+((long)'H'<<8) + || !(pchtab[pchnum] = malloc((short)pchhead[pchnum]->nID))) { + fclose(pchfile[pchnum]); + goto incl_err; + } +#define w2s(x) ((short)(x)) +#endif + memset(pchtab[pchnum],0,w2s(pchhead[pchnum]->nID)); + pchnum++; + } +#endif +done: + if (lastch=='.') getch(),getidstr(); + c=c?'>':'"'; + if (lastch!=c) + uerr(ERR_PUNCT,c); + rv = getline(incldepth == 1); +#ifdef PCH + if (!pch) +#endif + lineno = 1; /* dont list include files */ + return rv; +incl_err: + error(ERR_INCLFILE); + return ppquit(); +} + +char *litlate(char *s); +extern int getch_noppdir; +int dodefine(int mode) { // 1: #define, -1 : #macro, 0 : #undef + SYM *sp,*ds; + int n=0,flags=0; +/* getsym();*/ + skipspace(); + if ((lastch>='A'&&lastch<='Z') || (lastch>='a'&&lastch<='z') + || lastch=='_' || lastch=='$') { + getidstr(); /* get past #define */ + } else { + error(ERR_DEFINE); + return ppquit(); + } + if (!mode) { + if (!symremove(lastid,&defsyms)) /* if we didn't unload anything, let's */ + pchsearch(lastid,PCHS_UNLOAD); /* try and unload the symbol */ + return ppquit(); + } +#ifdef AS + if (!strcmp(lastid,"NOSTUB")) + nostub_mode=1; +#endif +#ifdef ASM + if (asm_isreserved()) + flags|=PPSYM_ASM_KEYWORD; + if (asm_flag) + flags|=PPSYM_DEFINED_IN_ASM; +#endif + ++global_flag; /* always do #define as globals */ + sp = (SYM *)xalloc((int)sizeof(SYM), _SYM+DODEFINE); + sp->name = strsave(lastid); + sp->storage_class = sc_define; + if (lastch=='(') { + TABLE *tp; +/* if (lineid==0x1A) + bkpt();*/ + sp->tp=(TYP *)(tp=(TABLE *)xalloc((int)sizeof(TABLE), _TABLE+DODEFINE)); +#ifdef NO_CALLOC + tp->hash=0; + tp->head=tp->tail=NULL; +#endif + getsym(); + getsym(); + if (lastst!=closepa) { + while (1) { + SYM *arg; + n++; + if (lastst!=id) error(ERR_IDEXPECT); + else { + arg=(SYM *)xalloc((int)sizeof(SYM), _SYM+DODEFINE); + arg->name=strsave(lastid); +#ifdef NO_CALLOC + arg->tp=NULL; +#endif + insert(arg,(HTABLE *)tp); + } + getsym(); + if (lastst!=comma) break; + getsym(); + } + if (lastst==dots) { sp->storage_class = sc_vamac; getsym(); } + if (lastst!=closepa) needpunc(closepa); + } + if (!isspace(lastch)) // undo last getch()... + lptr--; +#ifdef NO_CALLOC + } else { + sp->tp=NULL; +#endif + } +#ifdef MACRO_PPDIR + if (mode<0) { + char *s=(char *)alloca(500),*p=s; + int n=499; + getch_noppdir++; + do { + if (getch()<0) error(ERR_DEFINE); + *p++=(/*lastch=='\n'?'\r':*/lastch); + } while (n-- && (lastch!='#' || *lptr!='e' || strncmp(lptr+1,"ndm",3))); + getch_noppdir--; + if (n<=0) error(ERR_DEFINE); + p-=2; // remove '\n' '#' + *p++=0; + n = p-s; + p = (char *)xalloc(n, STR); + memcpy(p,s,n); + sp->value.s=p; + } else +#endif + if (strlen(lptr)>1500) + uerrsys("definition too long (1500 characters max)"); + if (!(sp->value.s = litlate(lptr))) + uerrc("unbalanced quotes in #define"); +#ifdef FLINE_RC + if (!strcmp(sp->name,"USE_FLINE_ROM_CALLS")) + fline_rc=1; +#endif + if ((ds=search(sp->name,-1,&defsyms))) { + if (strcmp(sp->value.s,ds->value.s)) + uwarn("redefinition of macro '%s'",sp->name); + symremove(sp->name,&defsyms); + } + insert(sp,&defsyms); + sp->used=n+flags; + --global_flag; + return ppquit(); +} + +// x = result of the test (1 : true, 0 : false, -1 : ignore all branches) +// c = is it a #if ? (rather than a #elif) +int doif(int x,int c) { + if ((ifreldepth+=c,ifdepth+=c)>MAX_IF_DEPTH) uerrc("too many imbricated '#if's"); + else if (!ifreldepth) uerrc("'#elif' unexpected"); + else if (!ifskip || ifdepth<=ifsd) { + ifsd=ifdepth; + if (c) + ifhas[ifdepth] = x; + else + ifhas[ifdepth] |= x; + ifskip = (ifval[ifdepth] = x) - (ifcount[ifdepth] = 1); + } + if (x<0) { + ifhas[ifdepth] = x; + ifskip = x; + } + return ppquit(); +} +// vim:ts=4:sw=4 diff --git a/gtc/src/protos.h b/gtc/src/protos.h new file mode 100644 index 0000000..96601cc --- /dev/null +++ b/gtc/src/protos.h @@ -0,0 +1,329 @@ +// Auto-generated file, do not edit! + +#ifndef PROTOS_H_ +#define PROTOS_H_ + +enum OptionModes; +enum e_am; +enum e_bt; +enum e_node; +enum e_op; +enum e_sc; +enum e_sym; +struct _regsimg; +struct _stackimg; +struct amode; +struct bcd; +struct blk; +struct cse; +struct enode; +struct hstab; +struct ocode; +struct snode; +struct stab; +struct sym; +struct typ; + +struct typ *shiftop(struct enode **node); +void local_clean(void); /* remove local symbols from alsyms -- to be called just before rel_local */ +void g_label(unsigned int labno); +struct snode *casestmt(void); +void compile(void); +void dump_endnode(); +int blk_free(struct blk *bp1); +int complexity(struct enode *ep); +void check_table(struct hstab *table); +struct typ *nameref(struct enode **node); +int en_dir_cost(struct enode *ep); +void extscan(unsigned char *ext); +void genstorage(struct sym *sp, int align); +void freeregs(struct _regsimg *img); /* used by g_fcall */ +struct amode *mk_immed(long i); +char *litlate(char *s); +struct snode *forstmt(void); +struct amode *g_xmul(struct enode *node, int flags, enum(e_op) op); +struct enode *mk_icon(long i); +void getsym(); +struct typ *equalops(struct enode **node); +void genfunc(struct snode *stmt); +struct typ *copy_type(struct typ *s); +void repcse(struct snode *block); +int internal(char *s); +void genbyte(int val); +struct typ *bitor(struct enode **node); +void fill(int n); +void scan(struct snode *block); +struct snode *retstmt(void); +void out_init(); +void _scr_main(); +void add_code(enum(e_op) op, int len, struct amode *ap1, struct amode *ap2, int line); +char *create_ti_file(int calc,int tigl_type,char *name,char *folder,char *content,unsigned long content_size,unsigned long *ti_file_size); +long intexpr(); +int bitwise_reduction(unsigned long x,int *size); +void double2bcd(double d,struct bcd *bcd); +struct amode *g_aslogic(struct enode *node, int flags, enum(e_op) op); +long auto_init(long offs,struct typ *typ,struct typ **tpp,int brace_level,int offmod,int stroff); +void initstack(); +void falsejp(struct enode *node, unsigned int lab); +int getch(); +int doif(int x,int c); +void temp_inv(void); +long inittype(struct typ *tp,struct typ **tpp); +void do_warning(char *s, ...); +struct typ *forcefit(struct enode **node1, struct typ *tp1, struct enode **node2, struct typ *tp2); +void collect(int g); +int movem(short x); +void g_code(enum(e_op) op, int len, struct amode *ap1, struct amode *ap2); +struct enode *parmlist(struct sym *f); +int isbyte(struct enode *node); +void clean_up(); +void getrawid(); +struct typ *deref(struct enode **node, struct typ *tp); +long strip_icon(long i, enum(e_bt) type); +void genword(int val); +int getid(int c); +void d_snode(struct snode **node); +struct snode *exprstmt(void); +struct typ *relation(struct enode **node); +int integral(struct typ *tp); +void g_bitmancode(enum(e_op) op,int size,struct amode *ap1,struct amode *ap2); +struct amode *g_offset(struct amode *ap, int off); +struct amode *as_fcall(struct enode *node, int flags, char *libname); +struct snode *contstmt(void); +int vcg_init(); +long push_param(struct enode *ep); +int label(char *s); +struct amode *get_asmparam(); +struct amode *g_fderef(struct enode *node, struct amode *ap0, int flags); +int req_all_aregs(struct enode *plist,int rp_dn,int rp_an); +void genstmt(struct snode *stmt); +int vcg_cost(); +void useregs(struct _regsimg *img); /* used by g_fcall */ +char *strend(char *s); +TI_SHORT process_attr(); +void dump_genfunc(struct snode *stmt); +void getidstr(); +int stringlit(char *s, int len); +void ds_free(void); +void scope_init(void); +void verbose_print_include(char *filename); +void tmp_use(); +struct sym *symremove(char *na, struct hstab *tab); +struct sym *search(char *na, int crc, struct hstab *tab); +void add_label(int lab); +void dump_startline(); +struct typ *cond_deref(struct enode **node, struct typ *tp); +struct amode *temp_addr(void); +struct amode *g_cast2(struct enode *ep, enum(e_bt) typ2, int flags); +void get_offset(struct amode *ap); +void scanexpr(struct enode *node, int duse); +void progr_initforcurfile(); +void move_pos(long diff); /* caution : only works in overwrite mode */ +void dump_newnode(char *name); +void fatal(char *message); +int arsearch(int r,struct ocode *ip); +void usestack(struct _stackimg *img); /* used by g_expr::en_compound */ +struct typ *bitand(struct enode **node); +FILE *xfopen(char *f,char *m,int sys); +int tst_const(struct enode *node); +long mod_mask(long i); +struct amode *mk_strlab(char *s); +void concat(struct stab *dest,struct stab *src); +struct amode *temp_data(void); +void rel_dualstack(void); +int pwrof2(long i); +void hashinit(struct hstab *t); +int eq_type(struct typ *tp1, struct typ *tp2); +void dodecl(enum(e_sc) defclass); +struct snode *gotostmt(void); +void g_coder(enum(e_op) op, int len, struct amode *ap1, struct amode *ap2); +struct typ *expression(struct enode **node); +struct snode *breakstmt(void); +int has_autocon(struct enode *ep); +struct snode *dostmt(void); +char *strsave(char *s); +void opt_compare(struct enode *node); +struct amode *g_asmod(struct enode *node, int flags); +int hexatoi(char *s); +struct ocode *new_code(int s); +void d_amode(struct amode **node); +int getline(int listflag); +void call_library(char *lib_name); +unsigned long _w2ul(TI_LONG *x); +int asm_isreserved(); +void dooper(struct enode **node); +short count_dn_an(struct enode *plist,int rp_dn,int rp_an); +struct amode *g_compound(struct snode *st, int flags); +void repexpr(struct enode *node); +void initpch(); +void genfloat(double val); +void asm_searchkw(); +struct amode *g_deref(struct enode *node, enum(e_bt) type, int flags, long size); +int free_data(void); +int indir_num(struct typ *tp); +int _getline(int listflag,char *base); +struct typ *asnop(struct enode **node); +struct amode *g_fcall(struct enode *node, int flags); +void warn_usr(char *s,...); +int tst_ushort(struct enode *node); +void scope_flush(void); +void rewrite(long size); +struct amode *g_aincdec(struct enode *node, int flags, enum(e_op) op); +void funcbottom(void); +struct typ *bitxor(struct enode **node); +struct amode *g_addsub(struct enode *node, int flags, enum(e_op) op); +struct snode *statement(void); +void searchkw(void); +void opt0(struct enode **node); +void decl(struct hstab *table); /* table is used only for enum members */ +struct amode *g_index(struct enode *node); +void g_strlab(char *s); +struct enode *copynode(struct enode *node); +void expand_do(char *q,int len,char *in,char *inbound,int need_ds_update); +unsigned int getconst(enum(e_sym) s,enum(e_sym) e); +void opt1(struct snode *block); +long intexpr_notemp(); +int getasm_main(); +unsigned short _w2us(TI_SHORT *x); +struct amode *g_div(struct enode *node, int flags); +struct amode *mk_offset(struct enode *node); +unsigned long desire(struct cse *csp); +int equalnode(struct enode *node1, struct enode *node2); +void funcbody(struct sym *sp, char *names[], int nparms); +struct amode *g_commute(void *func,struct enode *node,int flags,enum(e_op) op,int dummy/*void *reversal*/); +void add_peep(struct ocode *new_ocode); +struct snode *ifstmt(void); +void locate(void); +void allocate(void); +size_t option_parse(size_t listc,char **listv,enum(OptionModes) ex_mode); +void opt3(void); +long auto_pad(long offs,int len,int offmod); +struct amode *g_asxor(struct enode *node, int flags); +void truejp(struct enode *node, unsigned int lab); +void opt4(struct enode **node); +void macro_expansion(char *in,char *inbound,int need_ds_update); +void insert(struct sym *sp,struct hstab *table); +void dumplits(); +struct amode *g_asdiv(struct enode *node, int flags); +struct amode *g_mod(struct enode *node, int flags); +struct amode *copy_addr(struct amode *ap); +int equal_address(struct amode *ap1, struct amode *ap2); +void gendouble(double val); +struct typ *commaop(struct enode **node); +void swap_nodes(struct enode *node); +int preprocess(); +void dump_addstr(char *name,char *v); +struct amode *g_alloca(struct enode *node); +struct snode *whilestmt(void); +struct amode *mk_rmask(unsigned int mask); +struct amode *mk_reg(int r); +void do_compile(); +void bitwise_optimize(struct enode *ep,long mode); +void out_close(); +unsigned int getconst2(enum(e_sym) e); +struct amode *func_result(int flags, long bytes); +struct amode *g_cast(struct amode *ap, enum(e_bt) typ1, enum(e_bt) typ2, int flags); +struct amode *g_asmul(struct enode *node, int flags); +int start_block(int m); // used in block() (func.c) +void error(int n); +void ds_allocatleast(unsigned int size); +struct typ *forceft2(struct enode **node1, struct typ *tp1, struct enode **node2, struct typ *tp2); +char *type_str(struct typ *tp); +struct amode *mk_label(unsigned int lab); +struct snode *loopstmt(void); +void asm_getsym(); +void d_ocodes(void); +void extload(unsigned char *ext); +void initsym(); +struct amode *g_shift(struct enode *node, int flags, enum(e_op) op); +void block(struct sym *sp); /* CAUTION : always requires a compound_done() after call */ +struct amode *g_ybin(struct enode *node, int flags, enum(e_op) op); +struct sym *gsearch(char *na,int crc); +int cast_ok(struct typ *tp1, struct typ *tp2, int need_physically_compatible); +void needpunc(enum(e_sym) p); +struct amode *mk_scratch(long size); +void dump_genstmt(struct snode *stmt); +void d_enode(struct enode **node); +int ap_hasbeenpushed(struct amode *ap); +struct amode *g_unary(struct enode *node, int flags, enum(e_op) op); +void append(struct sym **ptr_sp, struct hstab *table); +void checkstack(void); +void rel_global(); +void option_parse_all(enum(OptionModes) ex_mode); +int pchload(char *name,char *data,unsigned int flags,unsigned char *tabp, unsigned char *p0,TI_SHORT *extTab); +void my_fclose(FILE *f); +struct typ *andop(struct enode **node); +struct amode *g_expr(struct enode *node, int flags); +struct amode *g_assign(struct enode *node, int flags); +void rel_local(); +struct sym *mk_int(char *name); +struct snode *asmstmt(void); +unsigned long double2ffp(double d); +void decl1(void); +struct typ *orop(struct enode **node); +int alignment(struct typ *tp); +struct amode *g_asshift(struct enode *node, int flags, enum(e_op) op); +void closepch(); +void castback(long offset, struct typ *tp1, struct typ *tp2); +void dump_addreg(char *name,int v); +double floatexpr(); +void freeop(struct amode *ap); +void err_usr(int m,...); +struct typ *cast_op(struct enode **ep, struct typ *tp1, struct typ *tp2); +struct amode *g_asadd(struct enode *node, int flags, enum(e_op) op); +int tst_short(struct enode *node); +struct typ *mk_type(enum(e_bt) bt, int siz); +struct enode *mk_node(enum(e_node) nt, struct enode *v1, struct enode *v2); +void _repexpr(struct enode **ep); +struct typ *binlog(struct enode **node, struct typ *(*xfunc)(), enum(e_node) nt, enum(e_sym) sy); +struct amode *func_result2(int flags, long bytes, int reg); +struct typ *force_cast_op(struct enode **ep, struct typ *tp1, struct typ *tp2); +void _exit(int code); +struct amode *g_mul(struct enode *node, int flags); +void tmp_free(); +struct snode *switchstmt(void); +void g_pop(int reg, enum(e_am) rmode, int number); +struct snode *compound(int no_init); +int isshort(struct enode *node); +void flush_peep(); +void put_label(int lab); +int not_lvalue(struct enode *node); +struct amode *mk_smask(unsigned int mask); +int datalit(char *s, int len); +void verbose_print_searchdirs(); +void structassign(struct amode *ap1, struct amode *ap2, long size, int mode); +int pchsearch(char *id,int mode); /* returns 0 if not PCH, 1 if PCH/def, -1 if PCH/init */ +struct snode *labelstmt(void); +int getsch(int flag); +struct amode *g_xbin(struct enode *node, int flags, enum(e_op) op); +void genfuncbegin(void); +int crcN(char *na); +struct typ *binop(struct enode **node, struct typ *(*xfunc)(), enum(e_node) nt, enum (e_sym) sy); +void bsort(struct cse **list); +int macro_expand(char *id,int crc/* may equal -1 */,char *in,char *oldin,char *inbound,int need_ds_update); +void g_push(int reg, enum(e_am) rmode, int number); +int checkcases(struct snode *head); +struct amode *g_hook(struct enode *node, int flags); +void insert_macros(char *p); +struct typ *exprnc(struct enode **node); +void genptr(struct enode *node); +int *_xalloc(int siz); +int castbegin(enum(e_sym) st); +void skipspace(); +int ppquit(); +void dump_addint(char *name,int v); +void validate(struct amode *ap); +int radix36(char c); +struct amode *mk_legal(struct amode *ap, int flags, long size); +struct typ *copy_type_global(struct typ *tp); +void freestack(struct _stackimg *img); /* used by g_expr::en_compound */ +char *fill_calcvar(char *buffer, char *input); +int getcache(enum(e_sym) f); +int vcg_done(); +void put_align2(void); +int dodefine(int mode); // 1: #define, -1 : #macro, 0 : #undef +int drsearch(int r,struct ocode *ip); +struct typ *conditional(struct enode **node); +void doinit(struct sym *sp, int align); + +#endif diff --git a/gtc/src/reg68k.c b/gtc/src/reg68k.c new file mode 100644 index 0000000..7a1434b --- /dev/null +++ b/gtc/src/reg68k.c @@ -0,0 +1,446 @@ +/* + * GTools C compiler + * ================= + * source file : + * register allocation + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" + +/* + * Register allocation (for the expression evaluation) + * This modules handles the management of scratch registers. + * It keeps track of the allocated registers and of the stack + */ + +#ifdef MC680X0 + +xstatic int next_data CGLOB, next_addr CGLOB; + +#ifndef INFINITE_REGISTERS +xstatic char dreg_in_use[MAX_DATA + 1] CGLOBL; +xstatic char areg_in_use[MAX_ADDR + 1] CGLOBL; + +xstatic struct reg_struct reg_stack[MAX_REG_STACK + 1] CGLOBL, + reg_alloc[MAX_REG_STACK + 1] CGLOBL; + +xstatic int reg_stack_ptr CGLOB; +xstatic int reg_alloc_ptr CGLOB; +#endif + +void g_push(int reg, enum(e_am) rmode, int number) { +#ifndef INFINITE_REGISTERS +/* + * this routine generates code to push a register onto the stack + */ + struct amode *ap; + ap = (struct amode *) xalloc((int) sizeof(struct amode), AMODE+G_PUSH); + ap->preg = reg; + ap->mode = rmode; + g_code(op_move, 4, ap, push_am); + reg_stack[reg_stack_ptr].mode = rmode; + reg_stack[reg_stack_ptr].reg = reg; + reg_stack[reg_stack_ptr].flag = number; + if (reg_alloc[number].flag) + ierr(G_PUSH,1); + reg_alloc[number].flag = 1; + /* check on stack overflow */ + if (++reg_stack_ptr > MAX_REG_STACK) + ierr(G_PUSH,2); +#else + fatal("GPUSH/infinite"); +#endif +} + +void g_pop(int reg, enum(e_am) rmode, int number) { +#ifndef INFINITE_REGISTERS +/* + * generate code to pop a register from the stack. + */ + struct amode *ap; + + /* check on stack underflow */ + if (reg_stack_ptr-- == 0) + ierr(G_POP,1); + /* check if the desired register really is on stack */ + if (reg_stack[reg_stack_ptr].flag != number) + ierr(G_POP,2); + /* check if the register which is restored is really void */ + if (rmode == am_dreg) { + if (dreg_in_use[reg] >= 0) + ierr(G_POP,3); + dreg_in_use[reg] = number; + } else { + if (areg_in_use[reg] >= 0) + ierr(G_POP,4); + areg_in_use[reg] = number; + } + ap = (struct amode *) xalloc((int) sizeof(struct amode), AMODE+G_PUSH); + ap->mode = rmode; + ap->preg = reg; + g_code(op_move, 4, pop_am, ap); + /* clear the push_flag */ + reg_alloc[number].flag = 0; +#endif +} + +void initstack() { +/* + * this routine should be called before each expression is evaluated to make + * sure the stack is balanced and all of the registers are marked free. + * This is also a good place to free all 'pseudo' registers in the + * stack frame by setting act_scratch to zero + */ +#ifndef INFINITE_REGISTERS + int i; + next_data = 0; + next_addr = 0; + for (i = 0; i <= MAX_DATA; i++) + dreg_in_use[i] = -1; + for (i = 0; i <= MAX_ADDR; i++) + areg_in_use[i] = -1; + reg_stack_ptr = 0; + reg_alloc_ptr = 0; +#else + next_data = FIRSTREG; + next_addr = FIRSTREG; +#endif + act_scratch = 0; +} + +//#if 0 +#ifndef __HAVE_STACK_IMAGE +#define __HAVE_STACK_IMAGE +typedef struct _stackimg { + int next_data,next_addr; +#ifndef INFINITE_REGISTERS + int reg_alloc_ptr,reg_stack_ptr; + char dreg_in_use[MAX_DATA+1]; + char areg_in_use[MAX_ADDR+1]; + struct reg_struct reg_stack[MAX_REG_STACK+1],reg_alloc[MAX_REG_STACK+1]; + int act_scratch; +#endif +} STACK_IMAGE; +#endif +void usestack(STACK_IMAGE *img) { /* used by g_expr::en_compound */ + img->next_data = next_data; + img->next_addr = next_addr; +#ifndef INFINITE_REGISTERS + img->act_scratch = act_scratch; + img->reg_alloc_ptr = reg_alloc_ptr; + img->reg_stack_ptr = reg_stack_ptr; + memcpy(img->dreg_in_use, dreg_in_use, MAX_DATA+1); + memcpy(img->areg_in_use, areg_in_use, MAX_ADDR+1); + memcpy(img->reg_stack, reg_stack, sizeof(struct reg_struct)*(MAX_REG_STACK+1)); + memcpy(img->reg_alloc, reg_alloc, sizeof(struct reg_struct)*(MAX_REG_STACK+1)); +#endif +} +void freestack(STACK_IMAGE *img) { /* used by g_expr::en_compound */ + next_data = img->next_data; + next_addr = img->next_addr; +#ifndef INFINITE_REGISTERS + act_scratch = img->act_scratch; + reg_alloc_ptr = img->reg_alloc_ptr; + reg_stack_ptr = img->reg_stack_ptr; + memcpy(dreg_in_use, img->dreg_in_use, MAX_DATA+1); + memcpy(areg_in_use, img->areg_in_use, MAX_ADDR+1); + memcpy(reg_stack, img->reg_stack, sizeof(struct reg_struct)*(MAX_REG_STACK+1)); + memcpy(reg_alloc, img->reg_alloc, sizeof(struct reg_struct)*(MAX_REG_STACK+1)); +#endif +} +//#endif + +#ifdef REGPARM +#ifndef __HAVE_REGS_IMAGE +#define __HAVE_REGS_IMAGE +typedef struct _regsimg { +#ifndef INFINITE_REGISTERS + int reg_alloc_ptr,reg_stack_ptr; + int next_data,next_addr; +#endif +} REGS_IMAGE; +#endif +void useregs(REGS_IMAGE *img) { /* used by g_fcall */ +#ifndef INFINITE_REGISTERS + img->reg_alloc_ptr = reg_alloc_ptr; + img->reg_stack_ptr = reg_stack_ptr; + img->next_data = next_data; + img->next_addr = next_addr; + next_data = 0; + next_addr = 0; +#endif +} +void freeregs(REGS_IMAGE *img) { /* used by g_fcall */ +#ifndef INFINITE_REGISTERS + int i; + for (i = 0; i <= MAX_DATA; i++) + dreg_in_use[i] = -1; + for (i = 0; i <= MAX_ADDR; i++) + areg_in_use[i] = -1; + reg_alloc_ptr = img->reg_alloc_ptr; + reg_stack_ptr = img->reg_stack_ptr; + next_data = img->next_data; + next_addr = img->next_addr; +#endif +} +#endif + +#ifdef PC +void checkstack(void) { +#ifndef INFINITE_REGISTERS +/* + * this routines checks if all allocated registers were freed + */ + int i; + for (i=0; i<= MAX_DATA; i++) + if (dreg_in_use[i] != -1) + ierr(CHECKSTACK,1); + for (i=0; i<= MAX_ADDR; i++) + if (areg_in_use[i] != -1) + ierr(CHECKSTACK,2); + if (reg_stack_ptr != 0) + ierr(CHECKSTACK,5); + if (reg_alloc_ptr != 0) + ierr(CHECKSTACK,6); +#endif + if (next_data != FIRSTREG) + ierr(CHECKSTACK,3); + if (next_addr != FIRSTREG) + ierr(CHECKSTACK,4); +} +#endif + +int ap_hasbeenpushed(struct amode *ap) { +#ifndef INFINITE_REGISTERS + return reg_alloc[(int)(ap)->deep].flag; +#else + return 0; +#endif +} + +void validate(struct amode *ap) { +#ifndef INFINITE_REGISTERS +/* + * validate will make sure that if a register within an address mode has been + * pushed onto the stack that it is popped back at this time. + */ + switch (ap->mode) { + case am_dreg: + if (ap->preg <= MAX_DATA && reg_alloc[(int)ap->deep].flag) { + g_pop(ap->preg, am_dreg, (int) ap->deep); + } + break; + case am_indx2: + if (ap->sreg <= MAX_DATA && reg_alloc[(int)ap->deep].flag) { + g_pop(ap->sreg, am_dreg, (int) ap->deep); + } + goto common; + case am_indx3: + if (ap->sreg <= MAX_ADDR && reg_alloc[(int)ap->deep].flag) { + g_pop(ap->sreg, am_areg, (int) ap->deep); + } + goto common; + case am_areg: + case am_ind: + case am_indx: + case am_ainc: + case am_adec: +common: + if (ap->preg <= MAX_ADDR && reg_alloc[(int)ap->deep].flag) { + g_pop(ap->preg, am_areg, (int) ap->deep); + } + break; + } +#endif +} + +struct amode *temp_data(void) { +/* + * allocate a temporary data register and return it's addressing mode. + */ + struct amode *ap; + ap = (struct amode *) xalloc((int) sizeof(struct amode), AMODE+TEMP_DATA); +#ifndef INFINITE_REGISTERS + if (dreg_in_use[next_data] >= 0) + /* + * The next available register is already in use. it must be pushed + */ + g_push(next_data, am_dreg, dreg_in_use[next_data]); + dreg_in_use[next_data] = reg_alloc_ptr; +#endif + ap->mode = am_dreg; + ap->preg = next_data; +#ifndef INFINITE_REGISTERS + ap->deep = reg_alloc_ptr; + reg_alloc[reg_alloc_ptr].reg = next_data; + reg_alloc[reg_alloc_ptr].mode = am_dreg; + reg_alloc[reg_alloc_ptr].flag = 0; + if (next_data++ == MAX_DATA) + next_data = 0; /* wrap around */ + if (reg_alloc_ptr++ == MAX_REG_STACK) + ierr(TEMP_DATA,1); +#else + next_data++; +#endif + return ap; +} + +struct amode *temp_addr(void) { +/* + * allocate a temporary addr register and return it's addressing mode. + */ + struct amode *ap; + ap = (struct amode *) xalloc((int) sizeof(struct amode), AMODE+TEMP_ADDR); +#ifndef INFINITE_REGISTERS + if (areg_in_use[next_addr] >= 0) + /* + * The next available register is already in use. it must be pushed + */ + g_push(next_addr, am_areg, areg_in_use[next_addr]); + areg_in_use[next_addr] = reg_alloc_ptr; +#endif + ap->mode = am_areg; + ap->preg = next_addr; +#ifndef INFINITE_REGISTERS + ap->deep = reg_alloc_ptr; + reg_alloc[reg_alloc_ptr].reg = next_addr; + reg_alloc[reg_alloc_ptr].mode = am_areg; + reg_alloc[reg_alloc_ptr].flag = 0; + if (next_addr++ == MAX_ADDR) + next_addr = 0; /* wrap around */ + if (reg_alloc_ptr++ == MAX_REG_STACK) + ierr(TEMP_ADDR,1); +#else + next_addr++; +#endif + return ap; +} + +int free_data(void) { +/* + * returns TRUE if a data register is available at ,,no cost'' (no push). + * Used to determine e.g. wether cmp.w #0,An or move.l An,Dm is better + */ +#ifndef INFINITE_REGISTERS + return (dreg_in_use[next_data] < 0); +#else + return 1; +#endif +} + +void freeop(struct amode *ap) { +/* + * release any temporary registers used in an addressing mode. + */ + int number; + if (ap == 0) + /* This can happen freeing a NOVALUE result */ + return; + switch (ap->mode) { + case am_dreg: + if (ap->preg <= MAX_DATA) { + if (next_data-- == 0) + next_data = MAX_DATA; +#ifndef INFINITE_REGISTERS + number = dreg_in_use[(int)ap->preg]; + dreg_in_use[(int)ap->preg] = -1; +#endif + break; + } + return; + case am_indx2: + if (ap->sreg <= MAX_DATA) { + if (next_data-- == 0) + next_data = MAX_DATA; +#ifndef INFINITE_REGISTERS + number = dreg_in_use[(int)ap->sreg]; + dreg_in_use[(int)ap->sreg] = -1; +#endif + break; + } + goto common; + case am_indx3: + if (ap->sreg <= MAX_ADDR) { + if (next_addr-- == 0) + next_addr = MAX_ADDR; +#ifndef INFINITE_REGISTERS + number = areg_in_use[(int)ap->sreg]; + areg_in_use[(int)ap->sreg] = -1; +#endif + break; + } + goto common; + case am_areg: + case am_ind: + case am_indx: + case am_ainc: + case am_adec: +common: + if (ap->preg <= MAX_ADDR) { + if (next_addr-- == 0) + next_addr = MAX_ADDR; +#ifndef INFINITE_REGISTERS + number = areg_in_use[(int)ap->preg]; + areg_in_use[(int)ap->preg] = -1; +#endif + break; + } + return; + default: + return; + } +#ifndef INFINITE_REGISTERS + /* some consistency checks */ + if (number != ap->deep) + ierr(FREEOP,1); + /* we should only free the most recently allocated register */ + if (reg_alloc_ptr-- == 0) + ierr(FREEOP,2); + if (reg_alloc_ptr != number) + ierr(FREEOP,3); + /* the just freed register should not be on stack */ + if (reg_alloc[number].flag) + ierr(FREEOP,4); +#endif +} + +void temp_inv(void) { +#ifndef INFINITE_REGISTERS +/* + * push any used temporary registers. + * This is necessary across function calls + * The reason for this hacking is actually that temp_inv should dump + * the registers in the correct order, + * the least recently allocated register first. + * the most recently allocated register last. + */ + int i; + + for (i = 0; i < reg_alloc_ptr; i++) + if (reg_alloc[i].flag == 0) { + g_push(reg_alloc[i].reg, reg_alloc[i].mode, i); + /* mark the register void */ + if (reg_alloc[i].mode == am_dreg) + dreg_in_use[reg_alloc[i].reg] = -1; + else + areg_in_use[reg_alloc[i].reg] = -1; + } +#else + g_code(_op_cleanup_for_external_call, 0, NIL_AMODE, NIL_AMODE); +#endif +} +#endif /* MC680X0 */ +// vim:ts=4:sw=4 diff --git a/gtc/src/searchkw.c b/gtc/src/searchkw.c new file mode 100644 index 0000000..c5c3222 --- /dev/null +++ b/gtc/src/searchkw.c @@ -0,0 +1,182 @@ +/* + * GTools C compiler + * ================= + * source file : + * keyword searching + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" + +xstatic readonly struct kwblk { + char *word; + enum(e_sym) stype; +#ifndef PC + int pad; +#endif +} keywords[] = { + { + "__asm__", kw_asm + }, { + "__attribute__", kw_attr + }, { + "__builtin_constant_p", kwb_constant_p + }, { + "__c__", kw_c + }, { + "__count__", kw_count + }, { + "__eval__", kw_eval + }, { + "__loop__", kw_loop + }, { + "__softcast__", kw_softcast + }, { + "__until__", kw_until + }, { + "alloca", kw_alloca + }, { + "asm", kw_asm + }, { + "auto", kw_auto + }, { + "break", kw_break + }, { + "case", kw_case + }, { + "char", kw_char + }, { + "const", kw_const + }, { + "continue", kw_continue + }, { + "default", kw_default + }, { + "defined", kw_defined + }, { + "do", kw_do + }, { + "double", kw_double + }, { + "else", kw_else + }, { + "enum", kw_enum + }, { + "extern", kw_extern + }, { + "float", kw_float + }, { + "for", kw_for + }, { + "goto", kw_goto + }, { + "if", kw_if + }, { + "incbin", kw_incbin + }, { + "int", kw_int + }, { + "long", kw_long + }, { + "loop", kw_loop + }, { + "register", kw_register + }, { + "return", kw_return + }, { + "short", kw_short + }, { + "signed", kw_signed + }, { + "sizeof", kw_sizeof + }, { + "static", kw_static + }, { + "struct", kw_struct + }, { + "switch", kw_switch + }, { + "typedef", kw_typedef + }, { + "typeof", kw_typeof + }, { + "union", kw_union + }, { + "unsigned", kw_unsigned + }, { + "until", kw_until + }, { + "void", kw_void + }, { + "volatile", kw_volatile + }, { + "while", kw_while +/* }, { + 0, 0*/ + } +}; + +#define kw_N 48 + +/* + * Dichotomic search allows a max of 6 comparisons instead of 50... + */ +void searchkw(void) { + char *s1,*s2,c; + const struct kwblk *kwbp; + int a=0,b=kw_N-1,m; +#ifdef PC + if (sizeof(keywords)/sizeof(struct kwblk)!=kw_N) + fatal("BUILD ERROR: INVALID KEYWORDS #"); +#endif + while (a<=b) { + m=(a+b)>>1; + kwbp=&keywords[m]; + s1=lastid; + s2=kwbp->word; + do { + if (!(c=*s2++)) { + if (!*s1) + lastst = kwbp->stype; + if (is_lang_ext(lastst) && lastid[0]!='_' && !(flags&X_LANG_EXT)) + lastst = id; + if (*s1!='u') // the only case when a kw is the beginning of another one + return; // is 'do' vs 'double' + } + } while (*s1++==c); + if (s1[-1] word != 0) { + s1 = lastid; + s2 = kwbp->word; + kwbp++; + do { + if (!(c=*s2++)) { + if (!*s1++) + lastst = (--kwbp)->stype; + return; + } + } while (*s1++==c); + } +}*/ +// vim:ts=4:sw=4 diff --git a/gtc/src/securecommdef.h b/gtc/src/securecommdef.h new file mode 100644 index 0000000..795d204 --- /dev/null +++ b/gtc/src/securecommdef.h @@ -0,0 +1,23 @@ +/* + * GTools C compiler + * ================= + * source file : + * (on-calc) GT-Dev header file + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#ifndef __SECURECOMMDEF_H +#define __SECURECOMMDEF_H +typedef struct { + long dummy; + void *sft[]; +} SecureTab; +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/stmt.c b/gtc/src/stmt.c new file mode 100644 index 0000000..4292c1e --- /dev/null +++ b/gtc/src/stmt.c @@ -0,0 +1,952 @@ +/* + * GTools C compiler + * ================= + * source file : + * statement handling + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" +#ifdef PC +#ifdef SHORT_INT +#undef int +#endif +#include +#ifdef SHORT_INT +#define int short +#endif +#endif + +struct enode *init_node CGLOB; + +TYP *lastexpr_tp CGLOB; +int lastexpr_size CGLOB, lastexpr_type CGLOB; + +/* + * the statement module handles all of the possible c statements and builds a + * parse tree of the statements. + * + * each routine returns a pointer to a statement parse node which reflects the + * statement just parsed. + */ + + +int start_block(int m) { // used in block() (func.c) + if (m) { + needpunc(begin); + return 1; // we don't care about the result in this case + } else + return lastst==begin; +} + +unsigned int getconst(enum(e_sym) s,enum(e_sym) e) { + struct enode *en; + getsym(); + if (lastst != s) + error(ERR_EXPREXPECT); + else { + getsym(); + if (exprnc(&en) == 0) + error(ERR_EXPREXPECT); + needpunc(e); + opt0(&en); + if (en->nodetype != en_icon) + error(ERR_CONSTEXPECT); + else if ((unsigned long)en->v.i>=65536) + error(ERR_OUTRANGE); + else return en->v.i; + } + return 0; // make the compiler happy +} +unsigned int getconst2(enum(e_sym) e) { + struct enode *en; + if (exprnc(&en) == 0) + error(ERR_EXPREXPECT); + needpunc(e); + opt0(&en); + if (en->nodetype != en_icon) + error(ERR_CONSTEXPECT); + else if ((unsigned long)en->v.i>=65536) + error(ERR_OUTRANGE); + else return en->v.i; + return 0; // make the compiler happy +} + +struct snode *whilestmt(void) { +/* + * whilestmt parses the c while statement. + */ + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_while; + snp->count = 3; + getsym(); + if (lastst != openpa) + error(ERR_EXPREXPECT); + else { + getsym(); + if (expression(&(snp->exp)) == 0) + error(ERR_EXPREXPECT); +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + needpunc(closepa); + if (lastst == kw_count) snp->count=getconst(openpa,closepa); + snp->s1 = statement(); + } + return snp; +} + +struct snode *asmstmt(); +#if !defined(AS) && !defined(ASM) +struct snode *asmstmt(void) { +/* + * asmstmt parses the gtc c asm statement. + */ + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_asm; + snp->count = 1; + getsym(); + if (lastst != openpa) + error(ERR_EXPREXPECT); + else { + getsym(); + if (lastst != sconst) + error(ERR_SYNTAX); + snp->v1.i = (long)strsave(laststr); + getsym(); + if (lastst == colon) { + getsym(); + uwarn("only asm(\"...\") is supported yet"); + error(ERR_SYNTAX); + } + needpunc(closepa); + needpunc(semicolon); + } +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + return snp; +} +#endif + +//struct enode lp_one = { en_icon, bt_ushort, 2, {1L}, 0, 0}; +xstatic struct enode *lp_one CGLOB; +struct snode *loopstmt(void) { +/* + * loopstmt parses the gtc c loop statement. + */ + struct snode *snp; TYP *tp; + struct enode *exp; + int has_count; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_loop; + snp->count = 3; + has_count = 0; + getsym(); + if (lastst != openpa) + error(ERR_EXPREXPECT); + else { + getsym(); + if (lastst != id) + error(ERR_IDEXPECT); + if (!nameref(&(snp->v1.e))) error(ERR_EXPREXPECT); + if (lastst != assign) + error(ERR_SYNTAX); + getsym(); + if (!(tp=expression(&(snp->exp)))) + error(ERR_EXPREXPECT); + cast_op(&(snp->exp),tp,(TYP *)&tp_ushort); +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + needpunc(closepa); + if (lastst == kw_count) { snp->count=getconst(openpa,closepa); has_count=1; } + opt0(&(snp->exp)); + if (snp->exp->nodetype==en_icon) { + unsigned int c=snp->exp->v.i; + if (has_count) { + if (c!=snp->count) + uwarn("loop has an effective count of %u whereas %u precised", + c,snp->count); + } else snp->count=c; + } + lp_one = mk_icon(1L); + lp_one->etype = bt_ushort; lp_one->esize = 2; + snp->exp = exp = mk_node(en_sub,snp->exp,lp_one); + exp->etype = bt_ushort; exp->esize = 2; + opt4(&(snp->exp)); + snp->exp = exp = mk_node(en_assign,snp->v1.e,snp->exp); + exp->etype = bt_ushort; exp->esize = 2; + snp->s1 = statement(); + if (lastst == kw_until) { + getsym(); + if (!expression(&(snp->v2.e))) error(ERR_EXPREXPECT); + } else snp->v2.e=NULL; + } + return snp; +} + +struct snode *dostmt(void) { +/* + * dostmt parses the c do-while construct. + */ + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_do; + snp->count = 3; + getsym(); + snp->s1 = statement(); +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + if (lastst != kw_while) + error(ERR_WHILEXPECT); + else { + getsym(); + if (lastst != openpa) + error(ERR_EXPREXPECT); + else { + getsym(); + if (expression(&(snp->exp)) == 0) + error(ERR_EXPREXPECT); + needpunc(closepa); + if (lastst == kw_count) snp->count=getconst(openpa,closepa); + } + if (lastst != end) + needpunc(semicolon); + } + return snp; +} + +struct snode *forstmt(void) { + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_for; + snp->count = 3; + getsym(); + needpunc(openpa); + /*if (*/expression(&(snp->exp))/* == 0) + snp->exp = 0*/; + needpunc(semicolon); + /*if (*/expression(&(snp->v1.e))/* == 0) + snp->v1.e = 0*/; + needpunc(semicolon); + /*if (*/expression(&(snp->v2.e))/* == 0) + snp->v2.e = 0*/; +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + needpunc(closepa); + if (lastst == kw_count) snp->count=getconst(openpa,closepa); + snp->s1 = statement(); + return snp; +} + +struct snode *ifstmt(void) { +/* + * ifstmt parses the c if statement and an else clause if one is present. + */ + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_if; + snp->count=32768; + getsym(); + if (lastst != openpa) + error(ERR_EXPREXPECT); + else { + getsym(); + if (expression(&(snp->exp)) == 0) + error(ERR_EXPREXPECT); +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + needpunc(closepa); + if (lastst == kw_count) { + unsigned int i=getconst(openpa,comma),j=getconst2(closepa); + snp->count=((unsigned long)i<<16)/(i+j); + } + snp->s1 = statement(); + if (lastst == kw_else) { + getsym(); + snp->v1.s = statement(); + } else { +#ifdef NO_CALLOC + snp->v1.s = 0; +#endif + } + } + return snp; +} + +/* + * consider the following piece of code: + * + * switch (i) { + * case 1: + * if (j) { + * ..... + * } else + * case 2: + * .... + * } + * + * case statements may be deep inside, so we need a global variable + * last_case to link them + */ +xstatic struct snode *last_case CGLOB; /* last case statement within this switch */ + +struct snode *casestmt(void) { +/* + * cases are returned as seperate statements. for normal cases label is the + * case value and v1.i is zero. for the default case v1.i is nonzero. + */ + struct snode *snp,*snp0; + snp0 = snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); +#ifdef NO_CALLOC + snp->s1 = NIL_SNODE; +#endif + if (lastst == kw_case) { + long v; + getsym(); + snp->stype = st_case; + snp->v2.i = v = intexpr(); + if (lastst == dots) { // TODO : make only one 'case' label + long max; + getsym(); + if ((max = intexpr()) < v) error(ERR_CASERANGE); + else while (v != max) { + last_case = last_case->s1 = snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + last_case->v1.s = snp; +#ifdef NO_CALLOC + snp->s1 = NIL_SNODE; +#endif + snp->stype = st_case; + snp->v2.i = ++v; + } + } + } else { + /* lastst is kw_default */ + getsym(); + /* CVW: statement type needed for analyze etc. */ + snp->stype = st_default; + } + last_case = last_case->s1 = snp; + needpunc(colon); + if (lastst != end) + snp->v1.s = statement(); + return snp0; +} + +int checkcases(struct snode *head) { +/* + * checkcases will check to see if any duplicate cases exist in the case list + * pointed to by head. + */ + struct snode *top, *cur; + cur = top = head; + while (top != 0) { + cur = top->s1; + while (cur != 0) { + if (cur->stype != st_default && top->stype != st_default + && cur->v2.i == top->v2.i) { + uwarn("duplicate case label for value %ld", cur->v2.i); + return 1; + } + if (cur->stype == st_default && top->stype == st_default) { + uwarn("duplicate default label"); + return 1; + } + cur = cur->s1; + } + top = top->s1; + } + return 0; +} + +struct snode *switchstmt(void) { + struct snode *snp; + struct snode *local_last_case; + local_last_case = last_case; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + last_case = snp; +#ifdef NO_CALLOC + snp->s1 = 0; +#endif + snp->stype = st_switch; + getsym(); + needpunc(openpa); + if ((expression(&(snp->exp))) == 0) + error(ERR_EXPREXPECT); +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + needpunc(closepa); + needpunc(begin); + snp->v1.s = compound(1); + if (checkcases(snp->s1)) + error(ERR_DUPCASE); + last_case = local_last_case; + return snp; +} + +struct snode *retstmt(void) { + struct snode *snp; + TYP *tp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_return; + getsym(); + tp = expression(&(snp->exp)); + if (snp->exp != 0) + (void) cast_op(&(snp->exp), tp, ret_type); + if (lastst != end) + needpunc(semicolon); +#ifdef DB_POSSIBLE + snp->line=prevlineid; +#endif + return snp; +} + +struct snode *breakstmt(void) { + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_break; + getsym(); + if (lastst != end) + needpunc(semicolon); +#ifdef DB_POSSIBLE + snp->line=prevlineid; +#endif + return snp; +} + +struct snode *contstmt(void) { + struct snode *snp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_continue; + getsym(); + if (lastst != end) + needpunc(semicolon); +#ifdef DB_POSSIBLE + snp->line=prevlineid; +#endif + return snp; +} + +struct snode *exprstmt(void) { +/* + * exprstmt is called whenever a statement does not begin with a keyword. the + * statement should be an expression. + */ + struct snode *snp; + debug('u'); + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_expr; +/* + * I have a problem here. + * If expression() fails on the first character and does not do a getsym(), + * there may be an infinite loop since we will continue coming up here. + * Since the compiler will stop after MAX_ERROR_COUNT calls to error(), + * this might not be THAT much of a problem. + */ + if (!(lastexpr_tp=expression(&(snp->exp)))) + error(ERR_EXPREXPECT); + else { + lastexpr_type=snp->exp->etype; + lastexpr_size=snp->exp->esize; + } + debug('v'); + if (lastst != end) + needpunc(semicolon); +#ifdef DB_POSSIBLE + snp->line=prevlineid; +#endif + debug('w'); + return snp; +} + +#ifdef AUTOINIT_PAD +//long auto_init(long offs,TYP *typ,int brace_level,int offmod); +long auto_pad(long offs,int len,int offmod) { + long nbytes=0; + while (len>0) { + int size; + if ((offs+offmod)&1) + size=1; + else if (len<=2) + size=len; + else if (len==3) + size=2; + else size=4; + + { + struct enode *ep1,*ep2=mk_icon(0L),*ep3; + ep2->esize = size; /* don't care about the etype, it's set to char */ + + ep1 = mk_node(en_autocon, NIL_ENODE, NIL_ENODE); + ep1->v.i = offs; + ep1->etype = bt_pointer; + ep1->esize = 4; + + ep3 = mk_icon((long)offmod); + ep3->etype = bt_long; + ep3->esize = 4; + + ep1 = mk_node(en_add, ep1, ep3); + ep1->etype = bt_pointer; + ep1->esize = 4; + + ep1 = mk_node(en_ref, ep1, NIL_ENODE); + ep1->esize = size; /* don't care about the etype, it's set to char */ + + ep1 = mk_node(en_assign, ep1, ep2); + ep1->esize = size; /* don't care about the etype, it's set to char */ + + if (init_node == 0) { + init_node = ep1; + } else { + init_node = mk_node(en_void, init_node, ep1); + } + } + + len-=size; + nbytes+=size; + offmod+=size; + } + return nbytes; +} +#endif + +long auto_init(long offs,TYP *typ,TYP **tpp,int brace_level,int offmod,int stroff) { +/* + * generated assignment statements for initialization of auto and register + * variables. The initialization is generated like comma operators so a + * single statement does all the initializations + */ + struct enode *ep1, *ep2; + struct typ *tp; + int brace_seen = 0; + long nbytes = 0; + +auto_init_restart: + if (lastst == begin) { + brace_level++; + brace_seen++; + getsym(); + } + if (typ->type==bt_struct && brace_level) { + struct sym *sp; + sp = typ->lst.head; /* start at top of symbol table */ + while (sp != 0) { +/* infunc("DrawPacmanLogoAndHandleMenu") + bkpt();*/ + nbytes+=auto_init(offs,sp->tp,NULL,brace_level,(int)(offmod+sp->value.i),-1); + if (lastst == comma) + getsym(); + if (lastst == end || lastst == semicolon) + break; + sp = sp->next; + } +#ifdef AUTOINIT_PAD + nbytes+=auto_pad(offs,(int)(typ->size-nbytes),offmod+nbytes); /* negative args are OK for auto_pad */ +#endif + } else if (typ->type==bt_union) { + typ = (typ->lst.head)->tp; + goto auto_init_restart; + } else if (typ->val_flag) { +// if (!brace_level) error(ERR_SYNTAX); + if (lastst != end) { + int stroff=-1; + if (lastst == sconst && !brace_seen) + stroff=0; + while (1) { + nbytes+=auto_init(offs,typ->btp,NULL,brace_level,(int)(offmod+nbytes),stroff); + if (stroff>=0) { + stroff++; + if (stroff>lstrlen || (stroff==lstrlen && typ->size)) { + getsym(); + break; + } + } else { + if (lastst == comma) + getsym(); + if (lastst == end || lastst == semicolon) break; + } + } + } + if (typ->size && nbytes > typ->size) + error(ERR_INITSIZE); + if (nbytes != typ->size && tpp) { + /* fix the symbol's size, unless tpp=0 (item of a struct/union or array) */ + typ = copy_type(typ); + *tpp = typ; + typ->size = nbytes; + } +#ifdef AUTOINIT_PAD + nbytes+=auto_pad(offs,(int)(typ->size-nbytes),offmod+nbytes); /* negative args are OK for auto_pad */ +#endif + } else { + if (stroff<0) { + if (!(tp = exprnc(&ep2))) + error(ERR_ILLINIT); + } else + ep2=mk_icon(stroff type); + +/* if (offs==0xfffffe4e) + bkpt();*/ + + ep1 = mk_node(en_autocon, NIL_ENODE, NIL_ENODE); + ep1->v.i = offs; +/* ep1->etype = typ->type; // this is a ridiculous bug that I spent hours finding... + ep1->esize = typ->size; */ + ep1->etype = bt_pointer; + ep1->esize = 4; + + if (offmod) { + struct enode *ep3 = mk_icon((long)offmod); + ep3->etype = bt_long; + ep3->esize = 4; + + ep1 = mk_node(en_add, ep1, ep3); + ep1->etype = bt_pointer; + ep1->esize = 4; + } + + ep1 = mk_node(en_ref, ep1, NIL_ENODE); + ep1->etype = typ->type; + ep1->esize = typ->size; + + ep1 = mk_node(en_assign, ep1, ep2); + ep1->etype = typ->type; + ep1->esize = typ->size; + +#ifdef MID_DECL_IN_EXPR + if (middle_decl) + md_expr = ep1, md_type = typ; + #error fix needed around here... + else { +#endif + if (init_node == 0) { + init_node = ep1; + } else { + init_node = mk_node(en_void, init_node, ep1); + } +#ifdef MID_DECL_IN_EXPR + } +#endif + } + while (brace_seen--) + needpunc(end); + return nbytes; +} + +struct snode *compound(int no_init) { +/* + * compound processes a block of statements and forms a linked list of the + * statements within the block. + * + * compound expects the input pointer to already be past the begin symbol of the + * block. + * + * If no_init is true, auto initializations are not desirable + */ + struct snode *head, *tail, *snp; +// struct sym *local_tail, *local_tagtail; + HTABLE old_lsyms,old_ltags; +// hashinit(&symtab); +/* local_tail = lsyms.tail; + local_tagtail = ltags.tail;*/ + memcpy(&old_lsyms,&lsyms,sizeof(HTABLE)); + memcpy(&old_ltags,<ags,sizeof(HTABLE)); + dodecl(sc_auto); + if (init_node == 0) { + head = tail = 0; + } else { + if (no_init>0) { + uwarn("auto initialization not reached"); + } + head = tail = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + head->stype = st_expr; + head->exp = init_node; +#ifdef NO_CALLOC + head->next = 0; +#endif +#ifdef DB_POSSIBLE + head->line = prevlineid; +#endif + } + init_node = 0; + while (lastst != end) { + if (head == 0) + head = tail = statement(); + else { + tail->next = statement(); + if (tail->next != 0) + tail = tail->next; + } + } + if (no_init>=0) + getsym(); +#ifdef LISTING + if (list_option) { +/* if (local_tail != lsyms.tail) { + if (local_tail != 0) + symtab.head = local_tail->next; + else + symtab.head = lsyms.head; + symtab.tail = lsyms.tail; + fprintf(list, "\n*** local symbol table ***\n\n"); + list_table(&symtab, 0); + fprintf(list, "\n"); + }*/ + fprintf(list, "\n*** local symbol table ***\n\n"); + list_table(&lsyms, 0); + fprintf(list, "\n"); +/* if (local_tagtail != ltags.tail) { + if (local_tagtail != 0) + symtab.head = local_tagtail->next; + else + symtab.head = ltags.head; + symtab.tail = ltags.tail; + fprintf(list, "\n*** local structures and unions ***\n\n"); + list_table(&symtab, 0); + fprintf(list, "\n"); + }*/ + fprintf(list, "\n*** local structures and unions ***\n\n"); + list_table(<ags, 0); + fprintf(list, "\n"); + } +#endif +/* if (local_tagtail != 0) { + ltags.tail = local_tagtail; + ltags.tail->next = 0; + } else { + ltags.head = 0; + ltags.tail = 0; + } + + + if (local_tail != 0) { + lsyms.tail = local_tail; + lsyms.tail->next = 0; + } else { + lsyms.head = 0; + lsyms.tail = 0; + }*/ + memcpy(&lsyms,&old_lsyms,sizeof(HTABLE)); + memcpy(<ags,&old_ltags,sizeof(HTABLE)); + + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_compound; + snp->s1 = head; +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + return snp; +} + +extern unsigned int pos; +struct snode *labelstmt(void) { +/* + * labelstmt processes a label that appears before a statement as a seperate + * statement. + */ + struct snode *snp; + struct sym *sp; + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + /*if (pos>=0x25C2) + printf("jiotrh");*/ + snp->stype = st_label; + if ((sp = search(lastid, lastcrc, &labsyms)) == 0) { + sp = (struct sym *) xalloc((int) sizeof(struct sym), _SYM); + sp->name = strsave(lastid); + sp->storage_class = sc_label; +#ifdef NO_CALLOC + sp->tp = 0; +#endif + sp->value.i = nxtlabel(); + append(&sp, &labsyms); + } else { + if (sp->storage_class != sc_ulabel) + error(ERR_LABEL); + else + sp->storage_class = sc_label; + } + getsym(); /* get past id */ + needpunc(colon); + if (sp->storage_class == sc_label) { + snp->v2.i = sp->value.i; + if (lastst != end) + snp->s1 = statement(); + return snp; + } + return 0; +} + +struct snode *gotostmt(void) { +/* + * gotostmt processes the goto statement and puts undefined labels into the + * symbol table. + */ + struct snode *snp; + struct sym *sp; + getsym(); + if (lastst != id) { + error(ERR_IDEXPECT); + return 0; + } + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + if ((sp = search(lastid, lastcrc, &labsyms)) == 0) { + sp = (struct sym *) xalloc((int) sizeof(struct sym), _SYM); + sp->name = strsave(lastid); + sp->value.i = nxtlabel(); + sp->storage_class = sc_ulabel; +#ifdef NO_CALLOC + sp->tp = 0; +#endif + append(&sp, &labsyms); + } +#ifdef DB_POSSIBLE + snp->line=lineid; +#endif + getsym(); /* get past label name */ + if (lastst != end) + needpunc(semicolon); + if (sp->storage_class != sc_label && sp->storage_class != sc_ulabel) + error(ERR_LABEL); + else { + snp->stype = st_goto; + snp->v2.i = sp->value.i; + snp->next = 0; + return snp; + } + return 0; +} + +struct snode *statement(void) { +/* + * statement figures out which of the statement processors should be called + * and transfers control to the proper routine. + */ + struct snode *snp; +/* if (lineid==0x20A) + bkpt();*/ + switch (lastst) { + case semicolon: + getsym(); + snp = 0; + break; + case kw_char: case kw_short: case kw_unsigned: case kw_long: + case kw_struct: case kw_union: case kw_enum: case kw_void: + case kw_float: case kw_double: case kw_int: case kw_typeof: + case kw_signed: case kw_const: case kw_volatile: + case kw_register: case kw_auto: + case kw_static: case kw_typedef: case kw_extern: +middle_decl: + if (!(flags & X_MID_DECL)) goto default_decl; +#ifdef OLD_MID_DECL + snp = compound(0); + if ((int)cached_sym IS_VALID) fatal("CACHE"); // will never happen since no caching is + // performed when lastst==begin +/* cached_sym2 = cached_sym;*/ + cached_sym = lastst; cached_lineid = lineid; + lastst = end; + break; +#else +#ifdef MID_DECL + /* the following is much cleaner than the old mid_decl handler */ + dodecl(sc_auto); + if (init_node) { + snp = (struct snode *) xalloc((int) sizeof(struct snode), SNODE); + snp->stype = st_expr; + snp->exp = init_node; +#ifdef DB_POSSIBLE + snp->line = prevlineid; +#endif + init_node = 0; // compound resets after calling rather than before... + } // I find it pretty weird :) (maybe it should be changed?) + else snp = 0; + break; +#endif +#endif + case begin: + getsym(); + snp = compound(0); + break; + case kw_if: + snp = ifstmt(); + break; + case kw_while: + snp = whilestmt(); + break; + case kw_for: + snp = forstmt(); + break; + case kw_return: + snp = retstmt(); + break; + case kw_break: + snp = breakstmt(); + break; + case kw_goto: + snp = gotostmt(); + break; + case kw_continue: + snp = contstmt(); + break; + case kw_do: + snp = dostmt(); + break; + case kw_switch: + snp = switchstmt(); + break; + case kw_case: + case kw_default: + snp = casestmt(); + break; + case kw_loop: + snp = loopstmt(); + break; + case kw_count: + snp = NULL; + error(ERR_EXPREXPECT); + break; + case kw_asm: + snp = asmstmt(); + break; + case id: + if (!getcache(id) && cached_sym==colon) { + snp = labelstmt(); + break; + } +#if defined(OLD_MID_DECL) || defined(MID_DECL) + if (lastsp && lastsp->storage_class == sc_typedef) + goto middle_decl; +#endif +default_decl: + /* else fall through to process expression */ + default: + snp = exprstmt(); + break; + } + if (snp != 0) + snp->next = 0; + return snp; +} +// vim:ts=4:sw=4 diff --git a/gtc/src/sunpack.c b/gtc/src/sunpack.c new file mode 100644 index 0000000..2ca460e --- /dev/null +++ b/gtc/src/sunpack.c @@ -0,0 +1,91 @@ +/* + * GTools C compiler + * ================= + * source file : + * precompiled header string unpacking + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#ifdef PC +#include + +char *sUnpack(char *in,char *out,char *dic) { + char c; char *out0=out; + while ((c=*in++)) { + if ((char)c>=0) *out++=c; + else { + if (c==(char)0x80) *out++=*in++; + else if (c==(char)0xFF) { + + } else { + char *dp=dic; + c-=(char)0x81; + while (c--) { + while (*dp++); + } + strcpy(out,dp); + while (*out++); out--; + } + } + } + *out++=0; + return out0; +} +#else +char *__attribute__((stkparm)) sUnpack(char *in,char *out,char *dic); +asm( +" xdef sUnpack\n" +"sUnpack:\n" +"/* bra.s sUnpack*/\n" +" move.l 4(%sp),%a0\n" +" move.l 8(%sp),%a1\n" +" moveq #126,%d1\n" +" moveq #0,%d0\n" +" move.b (%a0)+,%d0\n" +" beq su_quit\n" +" bmi su_special\n" +"su_copy_lp:\n" +" move.b %d0,(%a1)+\n" +"su_next:\n" +" move.b (%a0)+,%d0\n" +" bgt su_copy_lp\n" +" beq su_quit\n" +"su_special:\n" +" subq.b #1,%d0\n" +" bmi su_not_escape\n" +" move.b (%a0)+,(%a1)+\n" +" bra su_next\n" +"su_not_escape:\n" +" addq.b #2,%d0\n" +" bmi su_not_romcall\n" +" \n" +"su_not_romcall:\n" +" add.b %d1,%d0\n" +" move.l %a0,%d2\n" +" move.l 12(%sp),%a0\n" +" dbf %d0,su_search_loop\n" +" bra su_search_done\n" +"su_search_loop:\n" +" tst.b (%a0)+\n" +" bne su_search_loop\n" +" dbf %d0,su_search_loop\n" +"su_search_done:\n" +" move.b (%a0)+,(%a1)+\n" +" bne su_search_done\n" +" subq.w #1,%a1\n" +" move.l %d2,%a0\n" +" moveq #0,%d0\n" +" bra su_next\n" +"su_quit:\n" +" move.b %d0,(%a1)+\n" +" move.l 8(%sp),%a0\n" +" rts"); +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/symbol.c b/gtc/src/symbol.c new file mode 100644 index 0000000..97b8400 --- /dev/null +++ b/gtc/src/symbol.c @@ -0,0 +1,343 @@ +/* + * GTools C compiler + * ================= + * source file : + * symbol handling (insertion & search) + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" +#ifdef PCH +#include "pch.h" +#endif + +#ifdef EXE_OUT +#ifndef AS +int exestub_mode CGLOB; +#endif +#endif + +HTABLE gsyms CGLOBL, gtags CGLOBL, lsyms CGLOBL, labsyms CGLOBL, ltags CGLOBL; + +void concat(TABLE *dest,TABLE *src) { + SYM *sp=src->tail,*sp2; + while (sp) { + sp2=(SYM *)xalloc((int)sizeof(SYM), _SYM+SYMBOL); + *sp2=*sp; + insert(sp2,(HTABLE *)dest); + sp=sp->prev; + } +} + +void hashinit(HTABLE *t) { + t->hash=0x2489; + memset(t->h,0,sizeof(t->h)); +} + +void insert(SYM *sp,HTABLE *table) { +/* if (!strcmp(sp->name,"wrong_calc")) + uwarn("def!");*/ + if (!table->hash) { + if (!search(sp->name,0,table)) { + TABLE *tab=(TABLE *)table; + if (!tab->head) { + tab->head = tab->tail = sp; + sp->prev = 0; + sp->used = 0; + } else { + tab->tail->next = sp; + sp->prev = tab->tail; + tab->tail = sp; + sp->used = 0; + tab->tail = sp; + } + sp->next = 0; + } + else uerr(ERR_DUPSYM,sp->name); + } else { + int crc=crcN(sp->name); +#ifdef EXE_OUT + if (table==&defsyms && sp->name[0]=='E' && !strcmp(sp->name,"EXE_OUT")) + exestub_mode=1; +#endif + if (!search(sp->name,crc,table)) { + struct htab *tab=&table->h[crc]; + if (!tab->head) { + tab->head = tab->tail = sp; + sp->prev = 0; + sp->used = 0; + } else { + tab->tail->next = sp; + sp->prev = tab->tail; + tab->tail = sp; + sp->used = 0; + tab->tail = sp; + } + sp->next = 0; + } + else uerr(ERR_DUPSYM,sp->name); + } +} + +struct sym *symremove(char *na, HTABLE *tab) { + SYM *ttail,**prv; + struct htab *root; + char *s1,*s2,c; + if (!tab->hash) + ierr(TABLE_HASH,2); +#ifdef PC + if (tab->hash!=0x2489) + ierr(TABLE_HASH,1); +#endif + prv=&((root=&tab->h[crcN(na)])->tail); + while ((ttail=*prv)) { + s1 = ttail->name; + s2 = na; + while (*s1++==(c=*s2++)) { + if (!c) { +// *prv = ttail->prev; + if (ttail->next) ttail->next->prev = ttail->prev; + if (ttail->prev) ttail->prev->next = ttail->next; +// ttail->next = prv; + if (root->tail==ttail) root->tail=ttail->prev; + if (root->head==ttail) root->head=ttail->next; +/* if (!root->tail) + root->head=0;*/ + return ttail; + } + } + prv = &(ttail->prev); + } + return 0; +} + +#ifdef PC +int crcN(char *na) { + unsigned long crc=-1; int n; + unsigned char c; + c=*na++; + do { + crc^=c; + n=crc&7; + crc=(crc>>n)+(crc<<(32-n)); + } while ((c=*na++)); + crc^=crc>>16; + crc^=crc>>8; + return crc & (N_HASH-1); +} +#else +int crcN(char *na); +asm("crcN:\n" +" move.l 4(%sp),%a0\n" +" moveq #-1,%d0\n" +" move.b (%a0)+,%d1\n" +"crcN_loop:\n" +" eor.b %d1,%d0\n" +" moveq #7,%d1\n" +" and.w %d0,%d1\n" +" ror.l %d1,%d0\n" +" move.b (%a0)+,%d1\n" +" bne crcN_loop\n" +" move.w %d0,%d1\n" +" swap %d0\n" +" eor.w %d1,%d0\n" +" move.w %d0,-(%sp)\n" +" move.b (%sp)+,%d1\n" +" eor.b %d1,%d0\n" +" and.w #" N_HASH_AND ",%d0\n" +" rts"); +#endif + +/*#ifdef PC*/ +struct sym *search(char *na, int crc, HTABLE *tab) { + char *s1,*s2,c; + if (!tab->hash) { + SYM *ttail=((TABLE *)tab)->tail; + while (ttail) { + s1 = ttail->name; + s2 = na; + while (*s1++==(c=*s2++)) { + if (!c) return ttail; + } + ttail = ttail->prev; + } + return 0; + } else { + SYM *ttail; +#ifdef PC + if (tab->hash!=0x2489) + ierr(TABLE_HASH,1); +#endif + if (crc<0) crc=crcN(na); + ttail=tab->h[crc].tail; + while (ttail) { + s1 = ttail->name; + s2 = na; + while (*s1++==(c=*s2++)) { + if (!c) return ttail; + } + ttail = ttail->prev; + } + return 0; + } +} +/*#else +asm("search: + move.l %a2,-(%sp) + move.l 8(%sp),%d1 + move.l %d1,%a1 + tst.b (%a1) +0: beq 0b + move.l 12(%sp),%a0 + move.l %a0,%d0 + beq search_end +search_lp: + move.l (%a0)+,%a2 + move.l %d1,%a1 + cmpm.b (%a1)+,(%a2)+ + bne search_nxt +search_lp2: + move.b (%a1)+,%d0 + beq search_fnd + cmp.b (%a2)+,%d0 + beq search_lp2 +search_nxt: + move.l (%a0)+,%a0 + move.l %a0,%d0 + bne search_lp +search_end: + move.l (%sp)+,%a2 + rts +search_fnd: + tst.b (%a2)+ + bne search_nxt + subq.l #4,%a0 + move.l (%sp)+,%a2 + rts"); +#endif*/ + +struct sym *gsearch(char *na,int crc) { + struct sym *sp; + if (!(sp = search(na, crc, &lsyms))) + sp = search(na, crc, &gsyms); + return sp; +} + +void append(struct sym **ptr_sp, HTABLE *table) { + struct sym *sp1, *sp = *ptr_sp; + if (table == &gsyms && (sp1 = search(sp->name, -1, table)) != 0) { + /* + * The global symbol table has only one level, this means that we + * only check if the new declaration is compatible with the old one + */ + + if (!eq_type(sp->tp, sp1->tp)) + uerr(ERR_REDECL,sp->name); + /* + * The new storage class depends on the old and on the new one. + */ + if (sp->storage_class == sp1->storage_class) { + if (sp->storage_class == sc_global) { + /* + * This hack sets sp->used to -1 so that decl.c knows to + * suppress storage allocation + */ + uwarn("global redeclaration of '%s'", sp->name); + sp1->used = -1; + } + *ptr_sp = sp1; /* caller uses old entry */ + return; + } + /* + * since we use compiler generated label for static data, we must + * retain sc_static + */ + if (sp1->storage_class == sc_static) { + *ptr_sp = sp1; /* caller uses old entry */ + return; + } + /* + * if the new storage class is global, we must update sp1 to generate + * the .globl directive at the very end and perhaps the size (e.g. + * for arrays) + */ + if (sp->storage_class == sc_global) { + sp1->storage_class = sc_global; + sp1->tp = sp->tp; + *ptr_sp = sp1; /* caller uses old entry */ + return; + } + /* + * if the new storage class is static, set it to global (since we may + * have used the ,real' name and cannot use compiler generated names + * for this symbol from now on) and set sp->value.i to -1 to prevent + * it from being exported via .globl directives + */ + if (sp->storage_class == sc_static) { + sp1->storage_class = sc_global; + sp1->value.i = -1; + *ptr_sp = sp1; /* caller uses old entry */ + return; + } + /* + * last case: global declaration followed by external decl.: just do + * nothing + */ + *ptr_sp = sp1; /* caller uses old entry */ + return; + } +/* if (table->head == 0) { + // The table is empty so far... + table->head = table->tail = sp; + sp->next = sp->prev = 0; + sp->used = 0; + } else { + table->tail->next = sp; + sp->prev = table->tail; + table->tail = sp; + sp->next = 0; + sp->used = 0; + }*/ + if (!table->hash) { + TABLE *tab=(TABLE *)table; + if (!tab->head) { + tab->head = tab->tail = sp; + sp->prev = 0; + sp->used = 0; + } else { + tab->tail->next = sp; + sp->prev = tab->tail; + tab->tail = sp; + sp->used = 0; + tab->tail = sp; + } + sp->next = 0; + } else { + struct htab *tab=&table->h[crcN(sp->name)]; + if (!tab->head) { + tab->head = tab->tail = sp; + sp->prev = 0; + sp->used = 0; + } else { + tab->tail->next = sp; + sp->prev = tab->tail; + tab->tail = sp; + sp->used = 0; + tab->tail = sp; + } + sp->next = 0; + } +} +// vim:ts=4:sw=4 diff --git a/gtc/src/trees.c b/gtc/src/trees.c new file mode 100644 index 0000000..c2f0ce8 --- /dev/null +++ b/gtc/src/trees.c @@ -0,0 +1,247 @@ +/* + * GTools C compiler + * ================= + * source file : + * tree dumping + * + * Copyright 2001-2004 Paul Froissart. + * Credits to Christoph van Wuellen and Matthew Brandt. + * All commercial rights reserved. + * + * This compiler may be redistributed as long there is no + * commercial interest. The compiler must not be redistributed + * without its full sources. This notice must stay intact. + */ + +#include "define.h" +_FILE(__FILE__) +#include "c.h" +#include "expr.h" +#include "gen.h" +#include "cglbdec.h" + +typedef struct dump { +} DUMP; +char *dump_node_stack[MAX_DUMP_NODE_STACK]; +int dump_node_stack_depth; +int dump_attribute_phase; + +#define dump_put printf +void dump_startline() { + int i; + for (i=0;i \n"); + dump_startline(); + dump_put("<%s",name); + dump_node_stack[dump_node_stack_depth++] = name; + dump_attribute_phase = 1; +} +void dump_addstr(char *name,char *v) { + assert(dump_attribute_phase); + dump_put(" %s='%s'",name,v); +} +void dump_addint(char *name,int v) { + char b[100]; + sprintf(b,"%d",v); + dump_addstr(name,b); +} +void dump_addreg(char *name,int v) { + assert(dump_attribute_phase); + if (v>=RESULT && v =PRESULT && v \n"); + else + dump_startline(), dump_put("%s>",dump_node_stack[dump_node_stack_depth]); + dump_attribute_phase = 0; +} + +void dump_genstmt(struct snode *stmt) { + while (stmt != 0) { + switch (stmt->type) { + case st_compound: + dump_genstmt(stmt->s1); + break; + case st_label: + dump_newnode("st_label"); + dump_addint("id",stmt->v2.i); + dump_endnode(); + dump_genstmt(stmt->s1); + break; + case st_goto: + dump_newnode("st_goto"); + dump_addint("id",stmt->v2.i); + dump_endnode(); + break; + case st_break: + dump_newnode("st_break"); + dump_endnode(); + break; + case st_continue: + dump_newnode("st_continue"); + dump_endnode(); + break; + case st_expr: + dump_newnode("st_expr"); + dump_expr(stmt->exp); + dump_endnode(); + break; + case st_return: + if (!stmt->exp || ret_type->type==bt_void) { + dump_newnode("st_return"); + dump_endnode(); + break; + } + switch (ret_type->type) { + case bt_struct: + case bt_union: +#ifdef BCDFLT + case bt_float: +#ifdef DOUBLE + case bt_double: +#endif +#endif +#ifdef SHORT_STRUCT_PASSING + if (ret_type->size<=4) { + if (stmt->exp->nodetype!=en_ref) + ierr(DUMP,1); + dump_newnode("st_return"); + dump_newnode("expr"); + dump_addreg("target",mk_reg(RESULT)); + dump_newnode("e_deref"); + dump_addint("esize",ret_type->size); + dump_expr(stmt->exp->v.p[0]); + dump_endnode(); + dump_endnode(); + dump_endnode(); + break; + } +#endif + assert(0); + dump_newnode("st_return"); + dump_newnode("expr"); + dump_addstr("target","__tmp_structreturn"); + dump_expr(stmt->exp); + dump_newnode(""); + dump_newnode(""); + break; +#ifndef BCDFLT + case bt_float: +#ifdef DOUBLE + case bt_double: +#endif +#endif + case bt_char: case bt_uchar: + case bt_short: case bt_ushort: + case bt_long: case bt_ulong: + case bt_pointer: + dump_newnode("st_return"); + dump_newnode("expr"); + dump_addreg("target",ret_type->type==bt_pointer?mk_reg(PRESULT):mk_reg(RESULT)); + dump_expr(stmt->exp); + dump_endnode(); + dump_endnode(); + break; + default: + ierr(DUMP,1); + } + break; + case st_if: + dump_newnode("st_if"); + dump_newnode("condition"); + dump_expr(stmt->exp); + dump_endnode(); + dump_newnode("true"); + dump_genstmt(stmt->s1); + dump_endnode(); + dump_newnode("false"); + dump_genstmt(stmt->v1.s); + dump_endnode(); + dump_endnode(); + break; + case st_asm: + dump_newnode("st_asm"); + dump_newnode("TODO"); + //dump_asm((struct ocode *)stmt->v1.i); + dump_endnode(); + dump_endnode(); + break; + case st_while: + dump_newnode("st_while"); + if (stmt->exp) { + dump_newnode("condition"); + dump_expr(stmt->exp); + dump_endnode(); + } + dump_newnode("body"); + dump_genstmt(stmt->s1); + dump_newnode("st_labelcontinue"); + dump_endnode(); + dump_endnode(); + dump_endnode(); + break; + case st_do: + dump_newnode(stmt->exp ? "st_do" : "st_while"); + dump_newnode("body"); + dump_genstmt(stmt->s1); + dump_endnode(); + if (stmt->exp) { + dump_newnode("condition"); + dump_expr(stmt->exp); + dump_endnode(); + } + dump_endnode(); + break; + case st_for: + if (stmt->exp) { + dump_newnode("st_expr"); + dump_expr(stmt->exp); + dump_endnode(); + } + dump_newnode("st_while"); + dump_newnode("condition"); + dump_expr(stmt->v1.e); + dump_endnode(); + dump_newnode("body"); + dump_genstmt(stmt->s1); + if (stmt->v2.e) { + dump_newnode("st_expr"); + dump_expr(stmt->v2.e); + dump_endnode(); + } + dump_endnode(); + dump_endnode(); + break; + case st_switch: + default: + ierr(DUMP,2); + } + stmt = stmt->next; + } +} + +void dump_genfunc(struct snode *stmt) { + opt1(stmt); + dump_newnode("function"); + dump_newnode("returns"); + dump_type(ret_type); + dump_endnode(); + dump_newnode("code"); + dump_genstmt(stmt); + dump_genreturn(NIL_SNODE); + dump_endnode(); + dump_endnode(); +} diff --git a/gtc/src/vcg.c b/gtc/src/vcg.c new file mode 100644 index 0000000..3547009 --- /dev/null +++ b/gtc/src/vcg.c @@ -0,0 +1,98 @@ +#ifdef VCG +#ifdef PC +#define MAXINT 0x7FFFFFFF +#endif +#ifndef __HAVE_STACK_IMAGE +#define __HAVE_STACK_IMAGE +typedef struct _stackimg { + int next_data,next_addr; +#ifndef INFINITE_REGISTERS + int reg_alloc_ptr,reg_stack_ptr; + char dreg_in_use[MAX_DATA+1]; + char areg_in_use[MAX_ADDR+1]; + struct reg_struct reg_stack[MAX_REG_STACK+1],reg_alloc[MAX_REG_STACK+1]; + int act_scratch; +#endif +} STACK_IMAGE; +#endif +STACK_IMAGE vcg_img[VCG_MAX+1]; +int vcg_nxl[VCG_MAX+1]; +int vcg_aborted[VCG_MAX+1]; +int vcg_init() { + if (--vcg_lvl<0) { + vcg_lvl++; + return 0; + } +// tmp_use(); + usestack(&vcg_img[vcg_lvl]); + vcg_peep_head[vcg_lvl]=0; + vcg_aborted[vcg_lvl]=0; + vcg_nxl[vcg_lvl]=nextlabel; + g_code(op_label,0,0,0); + return 1; +// vcg_on++; +// vcg_cost[vcg_lvl]=0; +} +int en_dir_cost(struct enode *ep) { + switch (ep->nodetype) { + case en_icon: + return (ep->v.i>=-32768 && ep->v.i<32767)?1:2; + case en_labcon: + case en_nacon: + return 1; + case en_add: + case en_sub: + return max(en_dir_cost(ep->v.p[0]),en_dir_cost(ep->v.p[1])); + } +} +int cost_tab[] = { + 0,0,0,0,0,1,1,1,-MAXINT-1,2,1,1,1,1,2,0,0 +}; +int vcg_cost() { + int cost=0; + if (!vcg_aborted[vcg_lvl]) { + struct ocode *ip; + opt3(); + ip = peep_head; + while (ip != 0) { + #define am_cost(x) (x?(x->mode==am_direct?en_dir_cost(x->offset):cost_tab[x->mode]):0) + cost++; + switch (ip->opcode) { + case op_label: + case op_even: + cost--; + break; + case op_moveq: + case op_addq: case op_subq: + case op_lsl: case op_lsr: case op_asl: case op_asr: + case op_rol: case op_ror: case op_roxl: case op_roxr: + case op_trap: + cost+=am_cost(ip->oper2); + break; + case op_bxx: + /* what should we do here? */ + break; + case op_dbxx: + cost++; + break; + default: + cost+=am_cost(ip->oper1)+am_cost(ip->oper2); + break; + } + if (cost<0) cost+=(-MAXINT-1)+((ip->length+1)>>1); + ip = ip->fwd; + } + // vcg_on--; + // tmp_free(); + } else cost=12345; + return cost; +} +int vcg_done() { + freestack(&vcg_img[vcg_lvl]); + nextlabel=vcg_nxl[vcg_lvl]; + int cost=vcg_cost(); + vcg_lvl++; + return cost; +} +#endif +// vim:ts=4:sw=4 diff --git a/gtc/src/version.h b/gtc/src/version.h new file mode 100644 index 0000000..40dbaa1 --- /dev/null +++ b/gtc/src/version.h @@ -0,0 +1,8 @@ +#ifndef VERSION_H_ +#define VERSION_H_ + +#define GTC_MAJOR 0 +#define GTC_MINOR 902 +#define GTC_VERSION "0.90.2" + +#endif diff --git a/h/Makefile b/h/Makefile new file mode 100644 index 0000000..03c8f46 --- /dev/null +++ b/h/Makefile @@ -0,0 +1,24 @@ +BIN=../bin +STRIP = perl script/strip.pl +TXT89 = $(BIN)/txt89t + +all: src/*.h + $(RM) *.89t + $(RM) processed/*.89t + $(RM) -r stripped + mkdir stripped + sh -c 'for f in src/*.h; do $(STRIP) "$$f" > "stripped/$${f#src/}"; done' + $(TXT89) --compact -f gtchdr stripped/*.h + mv *.89t processed + $(RM) -r stripped + touch all + +clean: +distclean: clean +scratchclean: distclean + $(RM) processed/*.89t all + +include ../config.mk +install: all + mkdir -p $(prefix)/share/gtc/include + install -m 644 src/*.h $(prefix)/share/gtc/include diff --git a/h/all b/h/all new file mode 100644 index 0000000..e69de29 diff --git a/h/legacy/README b/h/legacy/README new file mode 100644 index 0000000..23ccd55 --- /dev/null +++ b/h/legacy/README @@ -0,0 +1 @@ +These files are deprecated, but I'm leaving them here for reference purposes. diff --git a/h/legacy/ezgen b/h/legacy/ezgen new file mode 100644 index 0000000..93fddff --- /dev/null +++ b/h/legacy/ezgen @@ -0,0 +1,67 @@ + #include "inclgen" + #include "genle" + #ifdef RESOURCE + FILE *resf=0; + #ifdef RES_TYPE + RES_TYPE *data=0; + #else + void *data=0; + #endif + #endif + DSCREEN *scr1=0,*scr2=0,*sc=0; + #ifdef DISP_SCR + DSCREEN *sd=0; + #endif + + int curscr=0; + void gl_main(); + void gl_upd() { + if (!curscr) { + gl_set_dscreen_int( + #ifdef DISP_SCR + sd= + #endif + scr1); + gl_set_dscreen_function(sc=scr2); + } else { + gl_set_dscreen_int( + #ifdef DISP_SCR + sd= + #endif + scr2); + gl_set_dscreen_function(sc=scr1); + } + curscr=~curscr; + } + int gl_load() { + int hd; + gl_init(); + gl_init_dscreen(&scr1, &hd); + if (!hd) goto nohd; + gl_push_hd(hd); + gl_init_dscreen(&scr2, &hd); + if (!hd) goto nohd; + gl_push_hd(hd); + gl_upd(); + #ifdef RESOURCE + resf=fopen(RESOURCE,"rb"); + if (!resf) goto nohd; + (void *)data=*(void **)resf; + #ifdef GFX_RES + gl_set_spr_xy(0,0); + gl_set_spr_tile(data); + #endif + #endif + return 1; + nohd: + return 0; + } + void _main() { + if (gl_load()) gl_main(); + #ifdef RESOURCE + if (resf) fclose(resf); + #endif + gl_wait_no_key(); + gl_free_hd(); + gl_quit(); + } diff --git a/h/legacy/ezgensc b/h/legacy/ezgensc new file mode 100644 index 0000000..fb9ad39 --- /dev/null +++ b/h/legacy/ezgensc @@ -0,0 +1,42 @@ + #include "inclgen" + #include "genle" + #include "sccomm" + #include "scliba" + #ifdef RESOURCE + FILE *resf; + #endif + + void gl_main(); + int gl_load() { + GLB + int hd; + gl_init(); + gl_init_dscreen(&g scr1, &hd); + if (!hd) goto nohd; + gl_push_hd(hd); + gl_init_dscreen(&g scr2, &hd); + if (!hd) goto nohd; + gl_push_hd(hd); + gl_upd(); + #ifdef RESOURCE + resf=fopen(RESOURCE,"rb"); + if (!resf) goto nohd; + (void *)g data=*(void **)resf; + #ifdef GFX_RES + gl_set_spr_xy(0,0); + gl_set_spr_tile(g data); + #endif + #endif + return 1; + nohd: + return 0; + } + void _main() { + if (gl_load()) gl_main(); + #ifdef RESOURCE + if (resf) fclose(resf); + #endif + gl_wait_no_key(); + gl_free_hd(); + gl_quit(); + } diff --git a/h/legacy/genle b/h/legacy/genle new file mode 100644 index 0000000..c59cdc6 --- /dev/null +++ b/h/legacy/genle @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/h/legacy/inclgen b/h/legacy/inclgen new file mode 100644 index 0000000..9e42b25 --- /dev/null +++ b/h/legacy/inclgen @@ -0,0 +1,4 @@ +#define USE_KERNEL +#include +#define X 160 +#define Y 100 diff --git a/h/legacy/include b/h/legacy/include new file mode 100644 index 0000000..27bda51 --- /dev/null +++ b/h/legacy/include @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/h/processed/COPYING b/h/processed/COPYING new file mode 100644 index 0000000..2ba72d5 --- /dev/null +++ b/h/processed/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/h/processed/assert.89t b/h/processed/assert.89t new file mode 100644 index 0000000..e64b549 Binary files /dev/null and b/h/processed/assert.89t differ diff --git a/h/processed/compat.89t b/h/processed/compat.89t new file mode 100644 index 0000000..99f0700 Binary files /dev/null and b/h/processed/compat.89t differ diff --git a/h/processed/default.89t b/h/processed/default.89t new file mode 100644 index 0000000..4966a1f Binary files /dev/null and b/h/processed/default.89t differ diff --git a/h/processed/doors.89t b/h/processed/doors.89t new file mode 100644 index 0000000..c79f0db Binary files /dev/null and b/h/processed/doors.89t differ diff --git a/h/processed/extgraph.89t b/h/processed/extgraph.89t new file mode 100644 index 0000000..1ea9709 Binary files /dev/null and b/h/processed/extgraph.89t differ diff --git a/h/processed/gen.89t b/h/processed/gen.89t new file mode 100644 index 0000000..7baf2e8 Binary files /dev/null and b/h/processed/gen.89t differ diff --git a/h/processed/nostub.89t b/h/processed/nostub.89t new file mode 100644 index 0000000..2897f15 Binary files /dev/null and b/h/processed/nostub.89t differ diff --git a/h/processed/patch.89t b/h/processed/patch.89t new file mode 100644 index 0000000..094e1d4 Binary files /dev/null and b/h/processed/patch.89t differ diff --git a/h/processed/std.89t b/h/processed/std.89t new file mode 100644 index 0000000..13d9c73 Binary files /dev/null and b/h/processed/std.89t differ diff --git a/h/processed/tigcclib.89t b/h/processed/tigcclib.89t new file mode 100644 index 0000000..1b1a777 Binary files /dev/null and b/h/processed/tigcclib.89t differ diff --git a/h/processed/ttunpack.89t b/h/processed/ttunpack.89t new file mode 100644 index 0000000..742d096 Binary files /dev/null and b/h/processed/ttunpack.89t differ diff --git a/h/processed/xupak.89t b/h/processed/xupak.89t new file mode 100644 index 0000000..131ce3a Binary files /dev/null and b/h/processed/xupak.89t differ diff --git a/h/script/strip.pl b/h/script/strip.pl new file mode 100644 index 0000000..3d35551 --- /dev/null +++ b/h/script/strip.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl + +my $multicomment=0; + +while (<>) { + chomp; + if (!$multicomment) { + s|//.*$| |g; + s|/\*.*?\*/| |g; + if (m|/\*|) { + s|/\*.*$| |g; + $multicomment=1; + } + } elsif (m|\*/|) { + s|^.*?\*/| |g; + $multicomment=0; + } else { + $_=''; + } + s|^\s+||g; + s|\s+$||g; + s|\s+| |g; + s|^(\#define \w+) |\1\t|g; + s|(\W) (.)|\1\2|g; + s|(.) (\W)|\1\2|g; + s:(? + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/h/src/assert.h b/h/src/assert.h new file mode 100644 index 0000000..14bac7e --- /dev/null +++ b/h/src/assert.h @@ -0,0 +1,5 @@ +#ifndef NDEBUG +#define assert(p) ((p)?(void)0:__assertion_failed(#p,__FILE__,__LINE__)) +#else +#define assert(p) ((void)0) +#endif diff --git a/h/src/compat.h b/h/src/compat.h new file mode 100644 index 0000000..c482067 --- /dev/null +++ b/h/src/compat.h @@ -0,0 +1,66 @@ +#ifdef DOORS + #define _CALCULATOR _ram_call(0,const unsigned char*) +#endif + +#if defined(DOORS) && !defined(_ONE_CALC_ONLY) + #define LCD_WIDTH _ram_call(1,unsigned long) + #define LCD_HEIGHT _ram_call(2,unsigned long) + #define LCD_LINE_BYTES _ram_call(4,unsigned long) + #define KEY_LEFT _ram_call(5,unsigned long) + #define KEY_RIGHT _ram_call(6,unsigned long) + #define KEY_UP _ram_call(7,unsigned long) + #define KEY_DOWN _ram_call(8,unsigned long) + #define KEY_UPRIGHT _ram_call(9,unsigned long) + #define KEY_DOWNLEFT _ram_call(A,unsigned long) + #define KEY_DIAMOND _ram_call(B,unsigned long) + #define KEY_SHIFT _ram_call(D,unsigned long) + #define CALCULATOR (_CALCULATOR[0]) + #define HW_VERSION (_CALCULATOR[1]) +#else + #if defined (_TI89_ONLY) + #define ROM_base ((void*)(((unsigned long)__jmp_tbl)&0xE00000)) + #define CALCULATOR 0 + #else +#if defined (_TI92PLUS_ONLY) + #define ROM_base ((void*)0x400000) + #define CALCULATOR 1 + #else +#if defined (_V200_ONLY) + #define ROM_base ((void*)(((unsigned long)__jmp_tbl)&0xE00000)) + #define CALCULATOR 3 + #else + #ifdef DOORS + #define ROM_base _ram_call (3, const void*) + #else + #define ROM_base ((void*)(((unsigned long)__jmp_tbl)&0xE00000)) + #endif + #ifdef NO_CALC_DETECT + #ifdef USE_V200 + #define CALCULATOR (ROM_base==(void*)0x400000?1:(((unsigned char*)(_rom_call_addr(2F)))[2]>=200?3:0)) + #else + #define CALCULATOR (ROM_base==(void*)0x400000) + #endif + #else + extern const short __calculator; + #ifdef USE_TI89 + #define CALCULATOR (__calculator) + #else + #define CALCULATOR (__calculator==3?3:1) + #endif + #endif +#endif +#endif + #endif + #define KEY_DIAMOND (CALCULATOR?8192U:16384U) + #define KEY_DOWN (CALCULATOR?344:340) + #define KEY_DOWNLEFT (CALCULATOR?345:342) + #define KEY_LEFT (CALCULATOR?337:338) + #define KEY_OFF2 (CALCULATOR?8459U:16651U) + #define KEY_RIGHT (CALCULATOR?340:344) + #define KEY_SHIFT (CALCULATOR?16384U:8192U) + #define KEY_UP (CALCULATOR?338:337) + #define KEY_UPRIGHT (CALCULATOR?342:345) + #define LCD_HEIGHT (CALCULATOR?128:100) + #define LCD_LINE_BYTES (CALCULATOR?30:20) + #define LCD_WIDTH (CALCULATOR?240:160) +#endif diff --git a/h/src/default.h b/h/src/default.h new file mode 100644 index 0000000..2ce67b6 --- /dev/null +++ b/h/src/default.h @@ -0,0 +1,132 @@ +#ifndef __DEFAULT +#define __DEFAULT + +#ifdef USE_TI92P +#define USE_TI92PLUS +#endif +#if !defined (USE_TI89) && !defined (USE_TI92PLUS) && !defined (USE_V200) +#define USE_TI89 +#define USE_TI92PLUS +#define USE_V200 +#elif defined(USE_TI89) && !defined (USE_TI92PLUS) && !defined (USE_V200) +#define _TI89_ONLY +#define _ONE_CALC_ONLY +#elif !defined(USE_TI89) && defined (USE_TI92PLUS) && !defined (USE_V200) +#define _TI92PLUS_ONLY +#define _ONE_CALC_ONLY +#elif !defined(USE_TI89) && !defined (USE_TI92PLUS) && defined (USE_V200) +#define _V200_ONLY +#define _ONE_CALC_ONLY +#endif +#if defined (USE_TI89) && defined (USE_TI92PLUS) && defined (USE_V200) +#define _SUPPORT_ALL_CALCS +#endif + +#ifdef DOORS +#define USE_KERNEL +#endif + +#if defined(EXECUTE_IN_GHOST_SPACE) && defined(USE_KERNEL) +#error EXECUTE_IN_GHOST_SPACE does not work in kernel mode yet +#endif + +#if !defined (NO_CALC_DETECT) && (!defined (USE_KERNEL) || !defined (_SUPPORT_ALL_CALCS)) +#define _NEED_CALC_DETECT +#ifdef _ONE_CALC_ONLY +#ifdef USE_TI89 +#define _CALC_NUM 0 +#endif +#ifdef USE_TI92PLUS +#define _CALC_NUM 1 +#endif +#ifdef USE_V200 +#define _CALC_NUM 3 +#endif +#else +#ifndef _SUPPORT_ALL_CALCS +#ifndef USE_TI89 +#define _CALC_NUM 0 +#endif +#ifndef USE_TI92PLUS +#define _CALC_NUM 1 +#endif +#ifndef USE_V200 +#define _CALC_NUM 3 +#endif +#endif +#endif +#endif +#if !defined (_ONE_CALC_ONLY) && !defined (USE_KERNEL) +#define _NEED_CALC_VAR +#endif + +#define __ATTR_STD__ __attribute__((__stkparm__)) +#define __ATTR_STD_NORETURN__ __attribute__((__stkparm__,__noreturn__)) +#define CALLBACK __ATTR_STD__ +#define __ATTR_TIOS__ __ATTR_STD__ +#define __ATTR_TIOS_NORETURN__ __ATTR_STD_NORETURN__ +#define __ATTR_TIOS_CALLBACK__ CALLBACK +#define __ATTR_GCC__ +#define __ATTR_LIB_C__ __attribute__((__regparm__(1))) +#define __ATTR_LIB_ASM__ __ATTR_STD__ +#define __ATTR_LIB_ASM_NORETURN__ __ATTR_STD_NORETURN__ +#define __ATTR_LIB_CALLBACK_C__ CALLBACK +#define __ATTR_LIB_CALLBACK_ASM__ CALLBACK + +#define __jmp_tbl (*(void***)0xC8) +//#define _rom_call(type,args,index) (*((type(*__ATTR_TIOS__)args)(_rom_call_addr_concat(0x##index,_ROM_CALL_##index)))) +//#define _rom_call_addr(index) _rom_call_addr_concat(0x##index,_ROM_CALL_##index) +//#define _rom_call_addr_concat(intindex,romindex) (__jmp_tbl[intindex]) +#define _rom_call(t,a,i) (*((t(*__ATTR_TIOS__)a)(__jmp_tbl[0x##i]))) +#define _rom_call_addr(i) (__jmp_tbl[0x##i]) +#define offsetof(t,m) ((unsigned long)&(((t*)0)->m)) +#define OFFSETOF offsetof +#define import_binary(f,i) asm { i: incbin f }; + +#ifdef _GENERIC_ARCHIVE +#undef OPTIMIZE_ROM_CALLS +#undef USE_FLINE_ROM_CALLS +#undef USE_INTERNAL_FLINE_EMULATOR +#endif + +#ifndef MIN_AMS +#define MIN_AMS 101 +#endif + +#ifdef USE_FLINE_ROM_CALLS +#if !defined (USE_FLINE_EMULATOR) && !defined (USE_INTERNAL_FLINE_EMULATOR) +#if MIN_AMS<204 +#error You need to define USE_[INTERNAL_]FLINE_EMULATOR +#endif +#endif +//#error _INCLUDE_PATCH(fline_rom_calls); +#endif + +#define TIOS_entries (*(unsigned long*)(__jmp_tbl-1)) + +#ifdef DOORS +#define AMS_1xx ((ROM_VERSION&0x0F00)==0x100) +#define AMS_2xx ((ROM_VERSION&0x0F00)==0x200) +#else +#define AMS_1xx (TIOS_entries<1000) +#define AMS_2xx (TIOS_entries>1000) +#endif + +typedef short *__pshort; +typedef unsigned short *__pushort; +typedef long *__plong; +typedef unsigned long *__pulong; + +//extern float __BC()__ATTR_LIB_ASM__; +//#define _tios_float_1(f,x,t) ({typedef float(*__temp__type__)(short,t)__ATTR_LIB_ASM__;((__temp__type__)__BC)(4*0x##f,x);}) +//#define _tios_float_2(f,x,y,t1,t2) ({typedef //float(*__temp__type__)(short,t1,t2)__ATTR_LIB_ASM__;((__temp__type__)__BC)(4*0x##f,x,y);}) + +#if !defined (NOSTUB) && !defined (DOORS) +#ifdef USE_KERNEL +#include +#else +#include +#endif +#endif + +#endif diff --git a/h/src/doors.h b/h/src/doors.h new file mode 100644 index 0000000..b1ff7ab --- /dev/null +++ b/h/src/doors.h @@ -0,0 +1,47 @@ +#ifndef DOORS +#define DOORS + +#ifdef NOSTUB + +#error "doors.h" must not be included in "nostub" mode! +#undef DOORS + +#else + +#ifdef EXE_OUT +#error As of now, you cannot generate EXEs in kernel mode. +#endif + +#include + +//#undef _rom_call_addr_concat +//#define _rom_call_addr_concat(intindex,romindex) (&romindex) +#undef _rom_call +#undef _rom_call_addr +#define _rom_call(t,a,i) (*((t(*__ATTR_TIOS__)a)(&_ROM_CALL_##i))) +#define _rom_call_addr(i) (&_ROM_CALL_##i) + +#define _main() __main() + +/* Begin Auto-Generated Part */ +#define _ram_call(i,t) ((t)(&_RAM_CALL_##i)) +#define _ram_call_addr(i) (&_RAM_CALL_##i) +/* End Auto-Generated Part */ + +#ifdef RETURN_VALUE +#define _NEED_COMPLEX_MAIN +#endif + +#ifndef NO_EXIT_SUPPORT +#define _NEED_COMPLEX_MAIN +#endif + +#if defined (_NEED_COMPLEX_MAIN) || defined (_NEED_AMS_CHECK) || defined (_NEED_CALC_DETECT) +#define NO_VSIMPLE_MAIN +#endif + +#if defined(ENABLE_ERROR_RETURN) && defined(_NEED_COMPLEX_MAIN) +#define SPECIAL_ERROR_RETURN +#endif +#endif +#endif diff --git a/h/src/extgraph.h b/h/src/extgraph.h new file mode 100644 index 0000000..1405f23 --- /dev/null +++ b/h/src/extgraph.h @@ -0,0 +1 @@ +#header \ No newline at end of file diff --git a/h/src/gen.h b/h/src/gen.h new file mode 100644 index 0000000..2c48c3e --- /dev/null +++ b/h/src/gen.h @@ -0,0 +1 @@ +#header diff --git a/h/src/nostub.h b/h/src/nostub.h new file mode 100644 index 0000000..bf5a027 --- /dev/null +++ b/h/src/nostub.h @@ -0,0 +1,36 @@ +#ifndef NOSTUB +#define NOSTUB + +#ifdef DOORS +#error "nostub.h" must not be included in "Doors" mode! +#undef NOSTUB +#else +#include + +#if defined(USE_FLINE_ROM_CALLS) || defined(EXE_OUT) +//#undef _rom_call_addr_concat +//#define _rom_call_addr_concat(intindex,romindex) (&romindex) +//#undef _rom_call_addr +//#define _rom_call_addr(index) (__jmp_tbl[0x##index]) +#undef _rom_call +#define _rom_call(t,a,i) (*((t(*__ATTR_TIOS__)a)(&_ROM_CALL_##i))) +#undef OPTIMIZE_ROM_CALLS +#endif + +#ifdef OPTIMIZE_ROM_CALLS +//#error OPTIMIZE_ROM_CALLS isn't supported yet +#endif + +/* Various conditional compilations are defined below, to make an extra */ +/* support code as small as possible. If no RETURN_VALUE and SAVE_SCREEN */ +/* options are defined, the code overload is only two extra bytes! */ + +#if defined(SAVE_SCREEN) || defined(RETURN_VALUE) || !defined(NO_EXIT_SUPPORT) || defined(ENABLE_ERROR_RETURN) +#define _NEED_COMPLEX_MAIN +#endif + +#define _main() __main() +#define _nostub _main + +#endif +#endif diff --git a/h/src/patch.h b/h/src/patch.h new file mode 100644 index 0000000..5ea85c1 --- /dev/null +++ b/h/src/patch.h @@ -0,0 +1,420 @@ +#ifndef _GENERIC_ARCHIVE +#ifdef RETURN_VALUE +#define __str(x) #x +#define __xstr(x) __str(x) +#define __var(x) x##1 +#define __xvar(x) __var(x) +#if !__xvar(RETURN_VALUE) +#define RETURN_VARIABLE +#define __VN __RV+(sizeof(__xstr(RETURN_VALUE))) +extern char __RV[]; +#endif +#endif +#undef RETURN_VARIABLE ///// bug in GTC!!!!!!! + +#ifdef EXE_OUT +#define _NEED_COMPLEX_MAIN +#endif + +#ifdef ENABLE_ERROR_RETURN +#define SPECIAL_ERROR_RETURN +#endif +asm { +#ifdef NO_VSIMPLE_MAIN +#define NO_MAIN +_main: +#define _main __main +#else +#ifdef NOSTUB +#define NO_MAIN +_nostub: +#endif +#endif +#ifdef EXE_OUT +// [params : d3=optional SYM_ENTRY* to twin ; a2=ROM_CALL table] + move.l d3,-(a7) + beq \no_twin_delete +#if 0 + move.l d3,-(a7) + moveq #0,d7 // we only need the current HSym as DelTwin will make it alright +\loop + addq.w #2,d7 + subq.l #2,d3 + move.l d3,(a7) + jsr _ROM_CALL_23A /* HeapPtrToHandle */ + move.w d0,(a7) + beq \loop + move.l (a7)+,d3 + move.w d7,d3 +#else +//#ifdef FULL_EXE +// // note that in fact the latter won't work, since SymDelTwin won't delete anything... +// move.l d3,a0 +// move.w 12(a0),d3 +// clr.w 12(a0) // hack so that SymDelTwin won't free the handle +//#else + // will work as long as we don't *need* to return a locked handle (TSR...) + // -> maybe should use full version for programs that need ghost space execution? +//#endif +#endif + jsr _ROM_CALL_280 /* SymDelTwin */ +#if 0 + move.l d3,(a7) // save the HSym +#else +//#ifdef FULL_EXE +// clr.l (a7) // for HeapRealloc +// move.w d3,-(a7) // save the HANDLE +// jsr _ROM_CALL_9F /* HeapUnlock */ +// jsr _ROM_CALL_9D /* HeapRealloc */ +//#endif +#endif +\no_twin_delete +#endif +#ifdef EXECUTE_IN_GHOST_SPACE + //-------------------------------------------------------------------------- + // get the HW parm block using the algorithm suggested by Julien Muchembled + //-------------------------------------------------------------------------- + move.l 0xc8,d0 + and.l #0xE00000,d0 // get the ROM base + move.l d0,a0 + move.l 260(a0),a1 // get pointer to the hardware param block + add.l #0x10000,a0 + cmp.l a0,a1 // check if the HW parameter block is near enough + bhs \is_hw1or2 // if it is too far, it is HW1 + cmpi.w #22,(a1) // check if the parameter block contains HW ver + bls \is_hw1or2 // if it is too small, it is HW1 + + //-------------------------------------------------------------------------- + // check for VTI (trick suggested by Julien Muchembled) + //-------------------------------------------------------------------------- + trap #12 // enter supervisor mode. returns old (sr) in d0.w + move.w #0x3000,sr // set a non-existing flag in sr (but keep s-flag) + move.w sr,d1 // get sr content and check for non-existing flag + move.w d0,sr // restore old sr content + btst.l #12,d1 // this non-existing flag can only be set on the VTI + bne \is_hw1or2 // flag set -> VTI -> treat as HW1 + + //-------------------------------------------------------------------------- + // check for HW3 + //-------------------------------------------------------------------------- + cmp.l #3,22(a1) // check the hardware version + bcs \is_hw1or2 // <3 -> proceed + + //-------------------------------------------------------------------------- + // now check for an appropriate ROM patch (HW3Patch?) + //-------------------------------------------------------------------------- + move.l 0xc8,a0 + move.l 0xc0*4(a0),a1 // abuse EX_stoBCD + tst.w 92(a1) // check for HW3Patch (ROM resident) + beq \ghost_done // if it is installed, we're done + cmp.l #0x100,0xac // check for HW3Patch (RAM resident) + beq \ghost_done // if it is installed, we're done + + //-------------------------------------------------------------------------- + // now we have a problem: we are on unpatched HW3 -> can't proceed + //-------------------------------------------------------------------------- + pea __hw3patch_required(pc) + bra \msg_exit + +\is_hw1or2 + #ifndef EXE_OUT + lea gtc_compiled,a0 + move.l a0,d0 + cmp.l #0x40000,d0 + bcc.s \ghost_done + bset.l #18,d0 + moveq #0,d1 + move.w -2(a0),d1 + add.l d0,d1 + subq.l #1,d1 + move.l d1,-(sp) + move.l d0,-(sp) + move.l 0xC8,a0 + move.l 1384(a0),a0 + jsr (a0) + addq.l #8,sp + move.l 0xC8,a0 + cmp.l #1000,-4(a0) + bcc.s \ghost_install + pea \ghost_done(pc) + bset.b #2,1(sp) + rts +\ghost_install: + movem.l a2-a6/d3-d7,-(sp) + lea -20(sp),sp + move.l #0x3E000,a3 + move.l a0,d0 + and.l #0x600000,d0 + add.l #0x20000,d0 + move.l d0,12(sp) + move.l d0,16(sp) + trap #12 + move.w #0x2700,sr + moveq #0xF,d3 + pea \ghost_cont(pc) + bset.b #2,1(sp) + clr.w -(sp) + move.l 0xAC,a0 + jmp (a0) +\ghost_cont + lea 20(sp),sp + movem.l (sp)+,a2-a6/d3-d7 + #endif +\ghost_done +#endif +#if defined(_NEED_CALC_DETECT) || (defined(SAVE_SCREEN) && !defined(USE_KERNEL)) + move.l 0xC8,a0 +#endif +#ifdef _NEED_CALC_DETECT + moveq #1,d0 + move.l a0,d1 + and.l #0x400000,d1 + bne \calc_d0 + clr.w d0 + move.l 0x2F*4(a0),a1 + cmp.b #200,2(a1) + blt \calc_d0 + moveq #3,d0 +\calc_d0 +#ifdef _NEED_CALC_VAR + lea __calculator(pc),a1 + move.w d0,(a1) +#endif +#ifndef _SUPPORT_ALL_CALCS +#if _CALC_NUM + subq.w #_CALC_NUM,d0 +#elif !defined(_NEED_CALC_VAR) + tst.w d0 +#endif +#ifdef _ONE_CALC_ONLY + beq \calc_ok +#else + bne \calc_ok +#endif + pea __wrong_calc(pc) + bra \msg_exit +#endif +\calc_ok +#endif +#ifndef _NEED_COMPLEX_MAIN + #ifdef NOSTUB + bra __main + #else + #ifdef NO_VSIMPLE_MAIN + bra __main + #endif + #endif +#else + #ifdef NOSTUB + #ifdef SAVE_SCREEN + pea (a2) + lea -3840(sp),sp + pea 3840 + pea 0x4C00 + pea 8(sp) + move.l 0x26A*4(a0),a2 + jsr (a2) /* memcpy */ + #endif + #ifndef NO_EXIT_SUPPORT + movem.l d3-d7/a2-a6,-(sp) + #endif + #endif + #ifdef USE_INTERNAL_FLINE_EMULATOR + move.l 0x2C,-(sp) + lea \fline_handler(pc),a1 + lea 0x600000,a0 + and.w #~4,(a0) + move.l a1,0x2C + or.w #4,(a0) + #endif + #ifdef SPECIAL_ERROR_RETURN + lea -60(sp),sp + pea (sp) + move.l 0xC8,a0 + move.l 0x154*4(a0),a0 /* ER_catch */ + jsr (a0) + tst.w d0 + bne \error_returned + #endif + #ifdef NOSTUB + jsr __main + #else + jsr __main + #endif + #if defined(ENABLE_ERROR_RETURN) + move.l 0xC8,a0 + move.l 0x155*4(a0),a0 /* ER_success */ + jsr (a0) + clr.w d0 +\error_returned + lea \error_num(pc),a0 + move.w d0,(a0) + lea 64(sp),sp + #endif + #ifdef USE_INTERNAL_FLINE_EMULATOR + lea 0x600000,a0 + and.w #~4,(a0) + move.l (sp)+,0x2C + or.w #4,(a0) + #endif + #ifdef NOSTUB + #ifndef NO_EXIT_SUPPORT + movem.l (sp)+,d3-d7/a2-a6 + #endif + #ifdef SAVE_SCREEN + pea 3840 + pea 16(sp) + pea 0x4C00 + jsr (a2) + lea 3864(sp),sp + move.l (sp)+,a2 + #endif + #endif + #ifdef SPECIAL_ERROR_RETURN + lea \error_num(pc),a0 + tst.w (a0) + beq \no_error + or.w #0xA000,(a0) + /* for AMS 1, to unlock the prgm hd */ + move.l 0xC8,a2 + cmp.l #1000,-4(a2) + bcc \ams1_err_ok + pea gtc_compiled-2(pc) + move.l 0x23A*4(a2),a0 /* HeapPtrToHandle */ + jsr (a0) + tst.w d0 + beq \ams1_err_ok + move.w d0,-(sp) + move.l 0x9F*4(a2),a0 /* HeapUnlock */ + jsr (a0) +\ams1_err_ok +\error_num: + dc.w 0 +\no_error + #endif +#ifdef EXE_OUT +\program_rts +#if 0 + move.l (a7),d0 + beq \no_twin_create + clr.l -(a7) + jsr _ROM_CALL_166 /* EM_twinSymFromExtMem */ + addq.l #4,a7 +\no_twin_create + addq.l #4,a7 +#else +#ifdef FULL_EXE + tst.w (a7) + beq \no_twin_free + jsr _ROM_CALL_97 /* HeapFree */ + addq.l #2,a7 +\no_twin_free +#endif + addq.l #4,a7 +#endif +#ifdef BSS_SUPPORT + pea __bss_start + jsr _ROM_CALL_A3 /* tios::HeapFreePtr */ + addq.l #4,a7 +#endif + movem.l (a7)+,d3-d7/a2-a6 + move.l 0xC8,a0 + move.l 0x97*4(a0),a0 /* tios::HeapFree */ + jmp (a0) // note : we can't use a _ROM_CALL here, as we need a jmp + #ifdef RETURN_VALUE + #error Not compatible yet. + #endif +#else + #ifndef RETURN_VALUE + rts + #else + #ifdef NOSTUB + #ifndef RETURN_VARIABLE + move.l (sp)+,a0 + cmpi.w #0x21EE,(a0) + bne.s \A2 + addq.l #2,a0 +\A2: + jmp 4(a0) + #else + move.l 0xC8,a0 + move.l 1060(a0),a1 + move.l (a1),-(sp) + move.l #0x40000000,-(sp) + pea __VN(pc) + move.l 0x86*4(a0),a0 + jsr (a0) /* VarStore */ + lea 12(sp),sp + rts + #endif + #else + #ifndef RETURN_VARIABLE + move.l _ROM_CALL_109,_RAM_CALL_00F + rts + #else + move.l _ROM_CALL_109,-(sp) + move.l #0x40000000,-(sp) + pea __VN(pc) + jsr _ROM_CALL_86 + lea 12(sp),sp + rts + #endif + #endif + #endif +/* #ifdef ENABLE_ERROR_RETURN +\error_num: +// move.w #0,#8 + dc.w 0 + #endif*/ +#endif +#endif +#ifdef USE_INTERNAL_FLINE_EMULATOR +\fline_handler: + move.w (sp)+,d0 + move.l (sp)+,a0 + move.w d0,sr + move.w (a0)+,d0 + and.w #0x7FF,d0 + lsl.w #2,d0 + move.l 0xC8,a1 + pea (a0) + move.l 0(a1,d0.w),a0 + jmp (a0) +#endif +#if (defined(_NEED_CALC_DETECT)&&!defined(_SUPPORT_ALL_CALCS)) || defined(EXECUTE_IN_GHOST_SPACE) +\msg_exit: + move.l 0xE6*4(a0),a0 /* ST_helpMsg */ + jsr (a0) + addq.l #4,a7 +#ifdef EXE_OUT + bra \program_rts +#else +#ifdef NOSTUB + rts +#else + jmp _ROM_CALL_51 /* ngetchx */ +#endif +#endif +#endif +#if defined(_NEED_CALC_DETECT) && defined(_NEED_CALC_VAR) + even +__calculator: + dc.w -1 +#endif +#ifndef NO_EXIT_SUPPORT +__save__sp__: + dc.l 0 +#endif + even +}; + +#if (defined(_NEED_CALC_DETECT)&&!defined(_SUPPORT_ALL_CALCS)) +char __wrong_calc[]="Wrong calculator model"; +#endif +#ifdef EXECUTE_IN_GHOST_SPACE +char __hw3patch_required[]="HW3Patch required"; +#endif +#ifdef RETURN_VARIABLE +char __RV[]="\0" __xstr(RETURN_VALUE); +#endif +#endif diff --git a/h/src/std.h b/h/src/std.h new file mode 100644 index 0000000..2fe1388 --- /dev/null +++ b/h/src/std.h @@ -0,0 +1,4 @@ +#ifndef EXIT_SUPPORT +#define NO_EXIT_SUPPORT +#endif +#include diff --git a/h/src/tigcclib.h b/h/src/tigcclib.h new file mode 100644 index 0000000..ed10eb2 --- /dev/null +++ b/h/src/tigcclib.h @@ -0,0 +1,17 @@ +#ifndef __TIGCCLIB +#define __TIGCCLIB +#define inline +#include +#header +#include +#include +#ifndef __SECONDARY_FILE__ +#include +#endif +#headeropt +#headeropt +#headeropt +#headeropt +#headeropt +#headeropt +#endif diff --git a/h/src/ttunpack.h b/h/src/ttunpack.h new file mode 100644 index 0000000..c23edb9 --- /dev/null +++ b/h/src/ttunpack.h @@ -0,0 +1,81 @@ +typedef struct { + unsigned char osize_lo; // original size lowbyte + unsigned char osize_hi; // original size highbyte + unsigned char magic1; // must be equal to TTUNPACK_MAGIC1 + unsigned char magic2; // must be equal to TTUNPACK_MAGIC2 + unsigned char csize_lo; // compressed size lowbyte + unsigned char csize_hi; // compressed size lowbyte + unsigned char esc1; // escape >> (8-escBits) + unsigned char notused3; + unsigned char notused4; + unsigned char esc2; // escBits + unsigned char gamma1; // maxGamma + 1 + unsigned char gamma2; // (1< osize_lo | (((TTUNPACK_HEADER*)(_p_))->osize_hi << 8))) +#define ttunpack_valid(_p_) (((TTUNPACK_HEADER*)(_p_))->magic1 == TTUNPACK_MAGIC1 && ((TTUNPACK_HEADER*)(_p_))->magic2 == TTUNPACK_MAGIC2) + +#define TTUNPACK_OKAY 0 +#define TTUNPACK_NOESCFOUND 248 +#define TTUNPACK_ESCBITS 249 +#define TTUNPACK_MAXGAMMA 250 +#define TTUNPACK_EXTRALZP 251 +#define TTUNPACK_NOMAGIC 252 +#define TTUNPACK_OUTBUFOVERRUN 253 +#define TTUNPACK_LZPOSUNDERRUN 254 + +#define ttunpack_decompress ((unsigned short(*)(unsigned char*,unsigned char*))__ttunpack_decompress) +unsigned short __ttunpack_decompress[] = { +0x48e7,0x7ffa,0x4fef,0xffe8,0x206f,0x0050,0x0c28,0x0054,0x0002,0x6608, +0x0c28,0x0050,0x0003,0x6708,0x303c,0x00fc,0x6000,0x0264,0x4286,0x1c28, +0x0006,0x4247,0x1e28,0x0009,0x4245,0x1a28,0x000a,0x5345,0x4240,0x1028, +0x000c,0x3c40,0x7201,0xeb69,0x3f41,0x000e,0x7002,0xeb68,0x3f40,0x000c, +0x7208,0x9245,0x3f41,0x000a,0x7008,0x9047,0x3840,0x303c,0x00f9,0x0c47, +0x0008,0x6200,0x021e,0x4240,0x1028,0x000b,0xb06f,0x000e,0x660c,0x0c45, +0x0004,0x6306,0x0c45,0x0007,0x6308,0x303c,0x00fa,0x6000,0x01fe,0x7204, +0xb24e,0x6408,0x303c,0x00fb,0x6000,0x01f0,0x43e8,0x000f,0x2f49,0x0010, +0x266f,0x0054,0x43fa,0x01ea,0x2f49,0x0006,0x226f,0x0010,0x4280,0x1011, +0x41f0,0x0810,0x226f,0x0006,0x2288,0x41fa,0x01d4,0x2f48,0x0002,0x30bc, +0x0080,0x3606,0x4a47,0x670c,0x3f07,0x41fa,0x0274,0x4e90,0x3600,0x548f, +0x3043,0xbc88,0x6600,0x018c,0x3f05,0x45fa,0x021a,0x4e92,0x3800,0x426f, +0x0002,0x548f,0x0c44,0x0001,0x6754,0x3f05,0x4e92,0x3600,0x5343,0x302f, +0x000e,0x5540,0x548f,0xb043,0x6618,0x0c44,0x0003,0x6300,0x0170,0x45fa, +0x017e,0x4e92,0x3f40,0x0000,0x4e92,0x6000,0x0120,0x300e,0x6710,0x3f0e, +0x41fa,0x021a,0x4e90,0x320e,0xe36b,0x8640,0x548f,0x41fa,0x015a,0x4e90, +0x0a40,0x00ff,0x3203,0xe149,0x8240,0x6000,0x00fe,0x226f,0x0006,0x2051, +0x4240,0x1010,0x206f,0x0002,0x3210,0xc041,0x6700,0x00ca,0xe219,0x6402, +0x5291,0x3081,0x2051,0x4240,0x1010,0xc041,0x6630,0x3001,0xe218,0x6402, +0x5291,0x226f,0x0002,0x3280,0x3f07,0x45fa,0x01c0,0x4e92,0x3600,0x3f0c, +0x4e92,0x320c,0x48c1,0xe3ae,0x8c00,0x16c6,0x4286,0x3c03,0x588f,0x6000, +0xff26,0x3001,0xe218,0x6402,0x5291,0x206f,0x0002,0x3080,0x3f05,0x4e92, +0x3600,0x548f,0xb66f,0x000e,0x6522,0x3f2f,0x000a,0x41fa,0x0180,0x4e90, +0x966f,0x0010,0x322f,0x000c,0xe36b,0x8640,0x3f05,0x4e92,0x5340,0xe148, +0x8640,0x588f,0x3f05,0x4e92,0x3800,0x548f,0x0c44,0x001f,0x6210,0x4280, +0x3004,0x206f,0x0010,0x1230,0x0800,0x4881,0x6016,0x3f3c,0x0003,0x41fa, +0x0140,0x4e90,0x3204,0x0641,0xffe0,0xe749,0x8240,0x548f,0x4242,0xb642, +0x6500,0xfeac,0x16c1,0x5242,0xb642,0x64f8,0x6000,0xfea0,0x3001,0x226f, +0x0006,0xe218,0x6402,0x5291,0x206f,0x0002,0x3080,0x41fa,0x0056,0x4e90, +0x3200,0x0a41,0x00ff,0x4242,0xb842,0x6500,0xfe7a,0x4280,0x3001,0x204b, +0x91c0,0x102f,0x0001,0xd028,0xffff,0x16c0,0x5242,0xb842,0x64e8,0x6000, +0xfe5e,0x3f0c,0x41fa,0x00d6,0x4e90,0x320c,0xe36b,0x8600,0x16c3,0x548f, +0x6000,0xfe48,0x4240,0x4fef,0x0018,0x4cdf,0x5ffe,0x4e75,0x0000,0x0000, +0x0000,0x41fa,0xfff8,0x2250,0x4240,0x1019,0x2089,0x323a,0xfff0,0x0c01, +0x0080,0x6602,0x4e75,0xe148,0x1011,0x0c01,0x0008,0x6212,0x6630,0x0240, +0x0fff,0xe848,0x4e75,0x0240,0x7fff,0xee48,0x4e75,0x0c01,0x0020,0x62f2, +0x6508,0x0240,0x3fff,0xec48,0x4e75,0x0240,0x1fff,0xea48,0x4e75,0x0240, +0x07ff,0xe648,0x4e75,0x0c01,0x0002,0x62f2,0x6608,0x0240,0x03ff,0xe448, +0x4e75,0x0240,0x01ff,0xe248,0x4e75,0x2f03,0x4281,0x302f,0x0008,0x207a, +0xff84,0x343a,0xff84,0xb041,0x6312,0x3602,0xc610,0xe21a,0x6402,0x5288, +0x4a03,0x6704,0x5241,0x60ea,0x2608,0x41fa,0xff64,0x2083,0x41fa,0xff62, +0x3082,0x2043,0x7601,0xe36b,0x3f01,0x6108,0x544f,0x8043,0x261f,0x4e75, +0x4240,0x322f,0x0004,0x6730,0x207a,0xff3e,0x2243,0x343a,0xff3c,0x5341, +0xe348,0x3602,0xc610,0x6702,0x5200,0xe21a,0x6402,0x5288,0x51c9,0xffee, +0x2609,0x43fa,0xff20,0x3282,0x43fa,0xff16,0x2288,0x2243,0x4e75}; diff --git a/h/src/xupak.h b/h/src/xupak.h new file mode 100644 index 0000000..5471afe --- /dev/null +++ b/h/src/xupak.h @@ -0,0 +1,12 @@ +typedef struct { + int magic[2]; + unsigned int upksize,pksize; + char escbits,esc0; + char lzx,rlenum; + char rlec[0]; +} XPAK_HDR; +#define XPAK_MAGIC1 (('G'<<8)+'T') +#define XPAK_MAGIC2 (('P'<<8)+'k') +#define xpak_ismagic(m) (m[0]==XPAK_MAGIC1 && m[1]==XPAK_MAGIC2) +#define xpak_setmagic(m) (void)(m[0]=XPAK_MAGIC1,m[1]=XPAK_MAGIC2) +#header diff --git a/pch/Makefile b/pch/Makefile new file mode 100644 index 0000000..fc6256b --- /dev/null +++ b/pch/Makefile @@ -0,0 +1,81 @@ +# - no, it's not a true makefile... +# - yes, it's a .bat quick-and-dirtily converted to a makefile +# :-b + +BIN=$(shell pwd)/../bin +MERGE=perl script/merge.pl +PCHMK=$(BIN)/pchmaker +DAT89=$(BIN)/dat89y -e HDR +O2EXT=$(BIN)/obj2ti -x + +PCHFILES = stdhead.pch keywords.pch estack.pch estackle.pch events.pch homescr.pch tiosdlg.pch wingraph.pch xupaki.pch #gen.pch extgraph.pch +TIPCHFILES = $(patsubst %.pch,%.89y,$(PCHFILES)) + +all: src/* srcdata/* subprojects/xupaki.pch + $(RM) lex.txt *.pchsource + cp src/lex.txt src/*.pchsource . + $(MAKE) $(TIPCHFILES) $(PCHFILES) + $(RM) lex.txt pchlog.txt *.pchsource + touch all +stdhead.pchsource: src/* + $(MERGE) src/stdhead-light.pchmerge +tiosdlg.pchsource: src/* + $(MERGE) src/tiosdlg-merge.pchmerge +keywords.pch: keywords.pchsource extfiles + $(PCHMK) $< +stdhead.pch: stdhead.pchsource extfiles + $(PCHMK) $< +estackle.pch: estackle.pchsource stdhead.pch extfiles + $(PCHMK) -istdhead.def $< +estack.pch: estack.pchsource stdhead.pch estackle.pch extfiles + $(PCHMK) -istdhead.def -iestackle.def $< +events.pch: events.pchsource stdhead.pch extfiles + $(PCHMK) -istdhead.def $< +homescr.pch: homescr.pchsource stdhead.pch extfiles + $(PCHMK) -istdhead.def $< +tiosdlg.pch: tiosdlg.pchsource stdhead.pch extfiles + $(PCHMK) -istdhead.def $< +wingraph.pch: wingraph.pchsource stdhead.pch extfiles + $(PCHMK) -istdhead.def $< +#gen.pch: srcdata/gen.pch +# cp $< $@ +#extgraph.pch: srcdata/extgraph.pch +# cp $< $@ +xupaki.pch: subprojects/xupaki.pch + cp $< $@ +%.89y: %.pch + $(DAT89) -f zheader $< + +clean: + $(RM) lex.txt pchlog.txt *.pchsource + $(RM) extfiles + $(RM) -r a2ext + +distclean: clean + +scratchclean: distclean + $(RM) *.pch *.89y *.def subprojects/*.pch all + +include ../config.mk +install: all + mkdir -p $(prefix)/share/gtc/include + install -m 644 *.pch $(prefix)/share/gtc/include + +try-import-tigcc-archive: + mv -f src/tigcc-archive/tigcc.a srcdata/tigcc.a&&rm -f src/tigcc-archive/*.o||true + +srcdata/tigcc.a: try-import-tigcc-archive + +extfiles: srcdata/* + $(RM) -r a2ext + mkdir a2ext + sh -c 'cd a2ext && ar x ../srcdata/tigcc.a' + cp srcdata/export.dat srcdata/*.ext srcdata/*.ref a2ext + $(MAKE) -C a2ext -f ../ext.mk O2EXT="$(O2EXT)" + touch extfiles + +subprojects/xupaki.pch: subprojects/xupaki/xupaki.pchsource subprojects/xupaki/unpack2.o + $(RM) -r subprojects/xupaki/a2ext + mkdir subprojects/xupaki/a2ext + sh -c 'cd subprojects/xupaki/a2ext && cp ../export.dat ../*.o . && for i in *.o; do $(O2EXT) "$$i"; done' + sh -c 'cd subprojects/xupaki && $(PCHMK) xupaki.pchsource && rm -f pchlog.txt xupaki.def && mv xupaki.pch ..' diff --git a/pch/all b/pch/all new file mode 100644 index 0000000..e69de29 diff --git a/pch/deflt.txt b/pch/deflt.txt new file mode 100644 index 0000000..47b5b94 --- /dev/null +++ b/pch/deflt.txt @@ -0,0 +1,345 @@ +#var .text +#var tigcc_compiled. +#var .data +#var qsort +#var .text +#var tigcc_compiled. +#var .data +#var fseek +#var .text +#var tigcc_compiled. +#var .data +#var fputc +#var .text +#var tigcc_compiled. +#var .data +#var fgetc +#var .text +#var tigcc_compiled. +#var .data +#var fwrite +#var .text +#var tigcc_compiled. +#var .data +#var fread +#var .text +#var tigcc_compiled. +#var .data +#var fgets +#var .text +#var tigcc_compiled. +#var .data +#var rename +#var .text +#var tigcc_compiled. +#var .data +#var unlink +#var .text +#var tigcc_compiled. +#var buff.0 +#var .data +#var tmpnam +#var .text +#var tigcc_compiled. +#var .data +#var fsetbufsize +#var .text +#var tigcc_compiled. +#var .data +#var bsearch +#var .text +#var tigcc_compiled. +#var .data +#var Sprite8 +#var .text +#var tigcc_compiled. +#var .data +#var Sprite16 +#var .text +#var tigcc_compiled. +#var .data +#var Sprite32 +#var .text +#var tigcc_compiled. +#var .data +#var __get_HS_pushEmptyFIFONode +#var .text +#var tigcc_compiled. +#var .data +#var HomeStorePair +#var .text +#var tigcc_compiled. +#var .data +#var LoadDLL +#var __DLL_body_ptr +#var __DLL_interface_ptr +#var UnloadDLL +#var .text +#var tigcc_compiled. +#var .data +#var __gray_version +#var .text +#var .data +#var bzero +#var .text +#var .data +#var bcopy +#var .text +#var .data +#var __mulsi3 +#var .text +#var tigcc_compiled. +#var .data +#var atoi +#var .text +#var .data +#var __divsi3 +#var .text +#var .data +#var __udivsi3 +#var .text +#var .data +#var __modsi3 +#var .text +#var .data +#var __umodsi3 +#var .text +#var .data +#var __div_entry +#var .text +#var .data +#var __muldi3 +#var .text +#var .data +#var __ashldi3 +#var .text +#var .data +#var __ashrdi3 +#var .text +#var .data +#var __lshrdi3 +#var .text +#var .data +#var __divdi3 +#var .text +#var tigcc_compiled. +#var .data +#var atol +#var .text +#var .data +#var __udivdi3 +#var .text +#var .data +#var __moddi3 +#var .text +#var .data +#var __umoddi3 +#var .text +#var .data +#var __addbf3 +#var .text +#var .data +#var __subbf3 +#var .text +#var .data +#var __mulbf3 +#var .text +#var .data +#var __negbf2 +#var .text +#var .data +#var __divbf3 +#var .text +#var .data +#var __floatsibf +#var .text +#var .data +#var __fixbfsi +#var __fixunsbfsi +#var .text +#var tigcc_compiled. +#var .data +#var strtol +#var .text +#var .data +#var __cmpbf2 +#var __nebf2 +#var __eqbf2 +#var __gebf2 +#var __ltbf2 +#var __gtbf2 +#var __lebf2 +#var .text +#var .data +#var __fp_entry +#var .text +#var .data +#var __fp_entry_1 +#var __fp_call +#var .text +#var .data +#var __BC +#var .text +#var .data +#var rand +#var __randseed +#var .text +#var __gray_check_hw_version +#var __gray_init_mem +#var __gray_init_handler +#var __gray_patches_for_hw1 +#var __gray_hw2type_detected +#var __gray_size_to_allocate +#var __gray_size_to_add +#var __gray_int1_handler_hw1 +#var __gray_skipcount +#var __gray_proceed_old +#var __gray_store +#var __gray_dummy1 +#var __gray_phase +#var __gray_init_return +#var __gray_used_mem +#var __gray_int1_handler_hw2 +#var __gray_startagain +#var __gray_copy_first_or_sec +#var __gray_to_oldint +#var __gray_copy_next_third +#var __gray_perform_copying +#var __gray_update_index +#var __gray_init_hw1_handler +#var __gray_cpy_d_plane +#var __gray_init_proceed +#var __gray_clr_l_plane +#var __gray_ok +#var __gray_off_out +#var __gray_hw1_cleanup +#var __gray_dark2lcd +#var __gray_continue_cleanup +#var .data +#var GrayOn +#var GrayOff +#var __D_plane +#var __L_plane +#var __gray_handle +#var __gray_hw_type +#var __switch_cnt +#var __gray_old_int1_hw1 +#var __gray_old_int1_hw2 +#var __gray_sync_n_count +#var __gray_plane_index +#var __gray_dbl_offset +#var __L_plane2 +#var __D_plane2 +#var .text +#var .data +#var realloc +#var .text +#var .data +#var calloc +#var .text +#var .data +#var clrscr +#var .text +#var .data +#var printf +#var .text +#var tigcc_compiled. +#var .data +#var strtoul +#var .text +#var .data +#var fprintf +#var .text +#var .data +#var fputchar +#var .text +#var .data +#var puts +#var .text +#var .data +#var strputchar +#var .text +#var .data +#var fputs +#var .text +#var .data +#var atof +#var .text +#var .data +#var push_shortint +#var .text +#var .data +#var push_longint +#var .text +#var .data +#var push_longlongint +#var .text +#var .data +#var NoCallBack +#var .text +#var tigcc_compiled. +#var .data +#var fopen +#var .text +#var .data +#var kbd_queue +#var .text +#var .data +#var OSVRegisterTimer +#var .text +#var .data +#var OSVFreeTimer +#var .text +#var .data +#var EV_getAppID +#var .text +#var .data +#var enter_ghost_space +#var .text +#var .data +#var __exit +#var .text +#var .data +#var atexit +#var .text +#var .data +#var __assertion_failed +#var .text +#var .data +#var _rowread +#var .text +#var .data +#var _extalnum_list +#var .text +#var tigcc_compiled. +#var .data +#var fclose +#var .text +#var .data +#var _extpunct_list +#var .text +#var .data +#var HomeStore +#var .text +#var .data +#var __dummy_handler__ +#var .text +#var .data +#var malloc_throw +#var HeapAllocPtrThrow +#var .text +#var .data +#var calloc_throw +#var .text +#var .data +#var realloc_throw +#var .text +#var .data +#var HeapReallocThrow +#var .text +#var LoadDLLThrow +#var .data +#var .text +#var tigcc_compiled. +#var .data +#var ftell diff --git a/pch/estack.89y b/pch/estack.89y new file mode 100644 index 0000000..2003e70 Binary files /dev/null and b/pch/estack.89y differ diff --git a/pch/estack.def b/pch/estack.def new file mode 100644 index 0000000..f7afa31 --- /dev/null +++ b/pch/estack.def @@ -0,0 +1,533 @@ + +ABS_TAG +ACOSH_TAG +ACOS_TAG +ADDELT_TAG +ADD_TAG +ANDPIC_ITAG +AND_TAG +ANGLE_TAG +ANS_TAG +APPEND_TAG +APPROX_TAG +ARB_INT_TAG +ARB_REAL_TAG +ARCHIVE_ITAG +ARCLEN_TAG +ASINH_TAG +ASIN_TAG +ATANH_TAG +ATAN_TAG +AUGMENT_TAG +AVGRC_TAG +BIN_TAG +BLDDATA_ITAG +CEILING_TAG +CFACTOR_TAG +CHAR_TAG +CIRCLE_ITAG +CLRDRAW_ITAG +CLRERR_ITAG +CLRGRAPH_ITAG +CLRHOME_ITAG +CLRIO_ITAG +CLRTABLE_ITAG +COLDIM_TAG +COLNORM_TAG +COMDENOM_TAG +COMMA_TAG +COMMENT_TAG +COMPLEX_ANGLE_TAG +COMPLEX_TAG +CONJ_TAG +COPYVAR_ITAG +CORR_TAG +COSH_TAG +COS_TAG +CROSSP_TAG +CSOLVE_TAG +CUBICREG_ITAG +CUMSUM_TAG +CUSTMOFF_ITAG +CUSTMON_ITAG +CUSTOM_ITAG +CYCLEPIC_ITAG +CYCLE_ITAG +CZEROS_TAG +DASH_TAG +DD_TAG +DEFINE_ITAG +DELFOLD_ITAG +DELTA_TBL_TAG +DELTA_TMPCNV_TAG +DELTA_X_TAG +DELTA_Y_TAG +DELVAR_ITAG +DESOLVE_TAG +DET_TAG +DET_TOL_TAG +DIAG_TAG +DIALOG_ITAG +DIFFERENTIATE_TAG +DIFTOL_TAG +DIM_TAG +DISPG_ITAG +DISPHOME_ITAG +DISPTBL_ITAG +DISP_ITAG +DIVELT_TAG +DIV_TAG +DMS_TAG +DOTP_TAG +DRAWFUNC_ITAG +DRAWINV_ITAG +DRAWPARM_ITAG +DRAWPOL_ITAG +DRAWSLP_ITAG +DROPDOWN_ITAG +DRWCTOUR_ITAG +DTIME_TAG +EIGVC_TAG +EIGVL_TAG +ELSEIF_ITAG +ELSE_ITAG +ELSE_TRY_ITAG +ENDCUSTM_ITAG +ENDDLOG_ITAG +ENDFOR_ITAG +ENDFUNC_ITAG +ENDIF_ITAG +ENDLOOP_ITAG +ENDPRGM_ITAG +ENDSTACK_TAG +ENDTBAR_ITAG +ENDTRY_ITAG +ENDWHILE_ITAG +ENTRY_TAG +EQ_TAG +ERRORNUM_TAG +ERROR_MSG_TAG +ESTEP_TAG +EXACT_TAG +EXEC_ITAG +EXIT_ITAG +EXP2LIST_TAG +EXPAND_TAG +EXPF_TAG +EXPR2DMS_TAG +EXPREG_ITAG +EXPR_TAG +EXP_TAG +EXT_INSTR_TAG +EXT_SYSTEM_TAG +EXT_TAG +EYE_PHI_TAG +EYE_PSI_TAG +EYE_THETA_TAG +FACTORIAL_TAG +FACTOR_TAG +FDASH_TAG +FILL_ITAG +FLDPIC_TAG +FLDRES_TAG +FLOOR_TAG +FMAX_TAG +FMIN_TAG +FNOFF_ITAG +FNON_ITAG +FORMAT_TAG +FOR_ITAG +FPART_TAG +FUNC_ITAG +GCD_TAG +GETCALC_ITAG +GETCONFG_TAG +GETDENOM_TAG +GETFOLD_TAG +GETKEY_TAG +GETMODE_TAG +GETNUM_TAG +GETTYPE_TAG +GETUNITS_TAG +GET_ITAG +GE_TAG +GOTO_ITAG +GRAPH_ITAG +GT_TAG +HEX_TAG +IDENTITY_TAG +IFTHEN_ITAG +IF_ITAG +IMAG_TAG +IM_TAG +INDIR_TAG +INFINITY_TAG +INPUTSTR_ITAG +INPUT_ITAG +INSTRING_TAG +INT2BIN_TAG +INT2DEC_TAG +INT2HEX_TAG +INTDIV_TAG +INTEGRATE_TAG +INT_TAG +IPART_TAG +ISPRIME_TAG +ISTORE_TAG +ITAN_TAG +ITEM_ITAG +LBL_ITAG +LCM_TAG +LEFT_TAG +LE_TAG +LIMIT_TAG +LINEHORZ_ITAG +LINETAN_ITAG +LINEVERT_ITAG +LINE_ITAG +LINREG_ITAG +LIST2MAT_TAG +LIST_END_TAG +LIST_START_TAG +LNREG_ITAG +LN_TAG +LOCALVAR_TAG +LOCAL_ITAG +LOCK_ITAG +LOGB_TAG +LOGISTIC_ITAG +LOG_TAG +LOOP_ITAG +LT_TAG +LU_ITAG +MAT2LIST_TAG +MAT_END_TAG +MAT_START_TAG +MAXX_TAG +MAXY_TAG +MAX_TAG +MEAN_TAG +MEDIAN_TAG +MEDMED_ITAG +MEDSTAT_TAG +MEDX1_TAG +MEDX2_TAG +MEDX3_TAG +MEDY1_TAG +MEDY2_TAG +MEDY3_TAG +MID_TAG +MINUS_TAG +MINX_TAG +MINY_TAG +MIN_TAG +MOD_TAG +MOVEVAR_ITAG +MROWADD_TAG +MROW_TAG +MULELT_TAG +MUL_TAG +NCONTOUR_TAG +NCR_TAG +NCURVES_TAG +NC_TAG +NDERIV_TAG +NEGFRAC_TAG +NEGINFINITY_TAG +NEWDATA_ITAG +NEWFOLD_ITAG +NEWLINE_TAG +NEWLIST_TAG +NEWMAT_TAG +NEWPIC_ITAG +NEWPLOT_ITAG +NEWPROB_ITAG +NEXTEXPR_TAG +NE_TAG +NINT_TAG +NMAX_TAG +NMIN_TAG +NORM_TAG +NOTHING_TAG +NOT_TAG +NPR_TAG +NSOLVE_TAG +NSTAT_TAG +OK_TAG +ONEVAR_ITAG +ORD_TAG +OR_TAG +OUTPUT_ITAG +P2PR_TAG +P2PTHETA_TAG +P2RX_TAG +P2RY_TAG +PARENTH_END_TAG +PARENTH_START_TAG +PART_TAG +PASSERR_ITAG +PAUSE_ITAG +PERCENT_TAG +PI_PRODUCT_TAG +PI_TAG +PLOTSOFF_ITAG +PLOTSON_ITAG +PLOTSTEP_TAG +PLOTSTRT_TAG +PN1_TAG +PN2_TAG +PN_INFINITY_TAG +POLCPLX_TAG +POLYEVAL_TAG +POPUP_ITAG +POSFRAC_TAG +POWELT_TAG +POWERREG_ITAG +POW_TAG +PRGM_ITAG +PRINTOBJ_ITAG +PRODUCT_TAG +PROMPT_ITAG +PROPFRAC_TAG +PTCHG_ITAG +PTOFF_ITAG +PTON_ITAG +PTTEST_TAG +PTTEXT_ITAG +PXLCHG_ITAG +PXLCRCL_ITAG +PXLHORZ_ITAG +PXLLINE_ITAG +PXLOFF_ITAG +PXLON_ITAG +PXLTEST_TAG +PXLTEXT_ITAG +PXLVERT_ITAG +Q1_TAG +Q3_TAG +QR_ITAG +QUADREG_ITAG +QUARTREG_ITAG +QUOTE_TAG +R2_TAG +RACOS_TAG +RADIANS_TAG +RANDMAT_TAG +RANDNORM_TAG +RANDPOLY_TAG +RANDSEED_ITAG +RAND_TAG +RASIN_TAG +RATAN_TAG +RCLGDB_ITAG +RCLPIC_ITAG +RC_TAG +REAL_TAG +REF_TAG +REF_TOL_TAG +REGCOEF_TAG +REGEQ_TAG +REMAIN_TAG +RENAME_ITAG +REQUEST_ITAG +RETURN_ITAG +RIGHT_TAG +ROTATE_TAG +ROUND_TAG +ROWADD_TAG +ROWDIM_TAG +ROWNORM_TAG +ROWSWAP_TAG +RPLCPIC_ITAG +RREF_TAG +RREF_TOL_TAG +SEED1_TAG +SEED2_TAG +SEMICOLON_TAG +SENDCALC_ITAG +SENDCHAT_ITAG +SEND_ITAG +SEQ_TAG +SETFOLD_TAG +SETGRAPH_TAG +SETMODE_TAG +SETTABLE_TAG +SETUNITS_TAG +SHADE_ITAG +SHIFT_TAG +SHOWSTAT_ITAG +SIGMA_SUM_TAG +SIGMA_X2_TAG +SIGMA_XY_TAG +SIGMA_X_TAG +SIGMA_Y2_TAG +SIGMA_Y_TAG +SIGN_TAG +SIMULT_TAG +SIMULT_TOL_TAG +SINCOS_TAG +SINGLE_QUOTE_TAG +SINH_TAG +SINREG_ITAG +SIN_TAG +SMLSIGMA_X_TAG +SMLSIGMA_Y_TAG +SOLVE_TAG +SORTA_ITAG +SORTD_ITAG +SQRT_TAG +START_TAG +STDDEV_TAG +STOGDB_ITAG +STOPIC_ITAG +STOP_ITAG +STORE_TAG +STRING_TAG +STYLE_ITAG +SUBELT_TAG +SUBMAT_TAG +SUBSCRIPT_TAG +SUB_TAG +SUM_TAG +SWITCH_TAG +SX_TAG +SYSDATA_TAG +SYSMATH_TAG +SY_TAG +T0_TAG +TABLE_ITAG +TANH_TAG +TAN_TAG +TAYLOR_TAG +TBLINPUT_TAG +TBLSTART_TAG +TCOLLECT_TAG +TC_TAG +TEXPAND_TAG +TEXT_ITAG +THEN_ITAG +THETA_C_TAG +THETA_MAX_TAG +THETA_MIN_TAG +THETA_STEP_TAG +TITLE_ITAG +TMAX_TAG +TMIN_TAG +TMPCNV_TAG +TOOLBAR_ITAG +TPLOT_TAG +TRACE_ITAG +TRANSPOSE_TAG +TRY_ITAG +TSTEP_TAG +TWOVAR_ITAG +UNARCHIV_ITAG +UNITCONV_TAG +UNITV_TAG +UNLOCK_ITAG +VARIANCE_TAG +VARIANCE_TWOARG_TAG +VAR_A_TAG +VAR_B_TAG +VAR_C_TAG +VAR_D_TAG +VAR_E_TAG +VAR_F_TAG +VAR_G_TAG +VAR_H_TAG +VAR_I_TAG +VAR_J_TAG +VAR_K_TAG +VAR_L_TAG +VAR_M_TAG +VAR_NAME_TAG +VAR_N_TAG +VAR_O_TAG +VAR_P_TAG +VAR_Q_TAG +VAR_R_TAG +VAR_S_TAG +VAR_T_TAG +VAR_U_TAG +VAR_V_TAG +VAR_W_TAG +VAR_X_TAG +VAR_Y_TAG +VAR_Z_TAG +VEC2CYLIND_TAG +VEC2POLAR_TAG +VEC2RECT_TAG +VEC2SPHERE_TAG +VEC_CYLIND_TAG +VEC_POLAR_TAG +VEC_SPHERE_TAG +V_AUGMENT_TAG +WHEN_TAG +WHILE_ITAG +WITH_TAG +XC_TAG +XFACT_TAG +XGRID_TAG +XMAX_TAG +XMIN_TAG +XORPIC_ITAG +XOR_TAG +XRES_TAG +XSCL_TAG +X_BAR_TAG +YC_TAG +YFACT_TAG +YGRID_TAG +YMAX_TAG +YMIN_TAG +YSCL_TAG +Y_BAR_TAG +ZC_TAG +ZEROS_TAG +ZEYE_PHI_TAG +ZEYE_PSI_TAG +ZEYE_THETA_TAG +ZFACT_TAG +ZMAX_TAG +ZMIN_TAG +ZNMAX_TAG +ZNMIN_TAG +ZOOMBOX_ITAG +ZOOMDATA_ITAG +ZOOMDEC_ITAG +ZOOMFIT_ITAG +ZOOMINT_ITAG +ZOOMIN_ITAG +ZOOMOUT_ITAG +ZOOMPREV_ITAG +ZOOMRCL_ITAG +ZOOMSQR_ITAG +ZOOMSTD_ITAG +ZOOMSTO_ITAG +ZOOMTRIG_ITAG +ZPLTSTEP_TAG +ZPLTSTRT_TAG +ZSCL_TAG +ZT0DE_TAG +ZTMAXDE_TAG +ZTMAX_TAG +ZTMIN_TAG +ZTPLOTDE_TAG +ZTSTEPDE_TAG +ZTSTEP_TAG +ZXGRID_TAG +ZXMAX_TAG +ZXMIN_TAG +ZXRES_TAG +ZXSCL_TAG +ZYGRID_TAG +ZYMAX_TAG +ZYMIN_TAG +ZYSCL_TAG +ZZMAX_TAG +ZZMIN_TAG +ZZSCL_TAG +Z_THETA_MAX_TAG +Z_THETA_MIN_TAG +Z_THETA_STEP_TAG +_VAR_Q_TAG diff --git a/pch/estack.pch b/pch/estack.pch new file mode 100644 index 0000000..58fdc4e Binary files /dev/null and b/pch/estack.pch differ diff --git a/pch/estackle.89y b/pch/estackle.89y new file mode 100644 index 0000000..214255f Binary files /dev/null and b/pch/estackle.89y differ diff --git a/pch/estackle.def b/pch/estackle.def new file mode 100644 index 0000000..c08f827 --- /dev/null +++ b/pch/estackle.def @@ -0,0 +1,124 @@ + +CESI_Callback_t +ESI_Callback_Int_t +ESI_Callback_t +ESTACK +GetValue +HS_popEStack +HToESI +NG_RPNToText +NG_approxESI +NG_execute +NG_graphESI +NG_rationalESI +NG_tokenize +NULL_INDEX +Parms2D +Parse1DExpr +Parse2DExpr +Parse2DMultiExpr +Print2DExpr +TSF_ALLOW_RESERVED +TSF_FULLY_QUALIFIED +TSF_PASS_ERRORS +TokenizeSymName +__push_internal_simplify__type__ +_push_zstr +_push_zstr_const +all_tail +any_tail +are_expressions_identical +bottom_estack +can_be_approxed +check_estack_size +compare_Floats +compare_complex_magnitudes +compare_expressions +delete_between +delete_expression +deleted_between +deleted_expression +did_push_cnvrt_Float_to_integer +display_statements +estack_number_to_Float +estack_to_short +estack_to_ushort +factor_base_index +factor_exponent_index +gcd_exact_whole_Floats +get_key_ptr +im_index +index_below_display_expression_aux +index_main_var +index_numeric_term +index_of_lead_base_of_lead_term +is_Float_exact_whole_number +is_advanced_tag +is_antisymmetric +is_complex0 +is_complex_number +is_free_of_tag +is_independent_of +is_independent_of_de_seq_vars +is_independent_of_elements +is_independent_of_tail +is_matrix +is_monomial +is_monomial_in_kernel +is_narrowly_independent_of +is_square_matrix +is_symmetric +is_tail_independent_of +is_valid_smap_aggregate +last_element_index +lead_base_index +lead_exponent_index +lead_factor_index +lead_term_index +likely_approx_to_complex_number +likely_approx_to_number +main_gen_var_index +map_tail +map_tail_Int +map_unary_over_comparison +min_quantum +move_between_to_top +moved_between_to_top +next_expression_index +norm1_complex_Float +numeric_factor_index +push_ANSI_string +push_END_TAG +push_Float +push_Float_to_nonneg_int +push_Float_to_rat +push_LIST_TAG +push_between +push_cnvrt_integer_if_whole_nmb +push_expr2_quantum +push_expr_quantum +push_expression +push_internal_simplify +push_longint +push_longlongint +push_next_arb_int +push_next_arb_real +push_next_internal_var +push_offset_array +push_overflow_to_infinity +push_parse_text +push_quantum +push_quantum_pair +push_reversed_tail +push_round_Float +push_shortint +push_transpose_aux +push_zstr +re_index +reductum_index +remaining_element_count +remaining_factors_index +reset_control_flags +reset_estack_size +should_and_did_push_approx_arg2 +signum_Float diff --git a/pch/estackle.pch b/pch/estackle.pch new file mode 100644 index 0000000..62404ff Binary files /dev/null and b/pch/estackle.pch differ diff --git a/pch/events.89y b/pch/events.89y new file mode 100644 index 0000000..0b1d047 Binary files /dev/null and b/pch/events.89y differ diff --git a/pch/events.def b/pch/events.def new file mode 100644 index 0000000..e0957b2 --- /dev/null +++ b/pch/events.def @@ -0,0 +1,124 @@ + +ABT_dialog +ACTIVITY_BUSY +ACTIVITY_IDLE +ACTIVITY_NORMAL +ACTIVITY_PAUSED +AP_CURRENT +AP_NULL +AP_RUNNING +AP_START_CURRENT +AP_START_ERROR +AP_START_NEW +AP_START_OPEN +CAT_dialog +CM_ACTIVATE +CM_BLINK +CM_CLR +CM_DEACTIVATE +CM_DEFAULTS +CM_DEL +CM_ENDTASK +CM_FOCUS +CM_GEOMETRY +CM_HSTRING +CM_IDLE +CM_INIT +CM_INSERT +CM_KEYPRESS +CM_MENU_ABOUT +CM_MENU_CLEAR +CM_MENU_COPY +CM_MENU_CUT +CM_MENU_FIND +CM_MENU_FORMAT +CM_MENU_NEW +CM_MENU_OPEN +CM_MENU_PASTE +CM_MENU_SAVE +CM_MODE_CHANGE +CM_RECALL +CM_STARTTASK +CM_START_CURRENT +CM_STORE +CM_STRING +CM_SWITCH_GRAPH +CM_UNFOCUS +CM_WPAINT +EVENT +EVENT_HANDLER +EV_captureEvents +EV_centralDispatcher +EV_clearPasteString +EV_defaultHandler +EV_eventLoop +EV_getAppID +EV_getSplitRect +EV_getc +EV_hook +EV_notifySwitchGraph +EV_paintOneWindow +EV_paintWindows +EV_registerMenu +EV_restorePainting +EV_sendEvent +EV_sendEventSide +EV_sendString +EV_setCmdCheck +EV_setCmdState +EV_setFKeyState +EV_startApp +EV_startSide +EV_startTask +EV_suspendPainting +EV_switch +MO_OPTIONS +MO_currentOptions +MO_defaults +MO_digestOptions +MO_isMultigraphTask +MO_modeDialog +MO_notifyModeChange +MO_sendQuit +ModeSettings +PAINTING_ENABLED +PAINTING_SUSPENDED +SDT_ALL +SDT_ASM +SDT_DATA +SDT_EXPR +SDT_FIG +SDT_FUNC +SDT_GDB +SDT_LIST +SDT_MAC +SDT_MAT +SDT_OTH +SDT_PIC +SDT_PRGM +SDT_STR +SDT_SYS +SDT_TEXT +WF_ACTIVE +WF_DIRTY +WF_DONT_REALLOC +WF_DUP_ON +WF_DUP_SCR +WF_NOBOLD +WF_NOBORDER +WF_ROUNDEDBORDER +WF_SAVE_SCR +WF_STEAL_MEM +WF_SYS_ALLOC +WF_TITLE +WF_TRY_SAVE_SCR +WF_TTY +WF_VIRTUAL +WF_VISIBLE +__AP_START_ERROR_1 +__AP_START_ERROR_2 +__AP_START_NEW_1 +__AP_START_NEW_2 +__AP_START_OPEN_1 +__AP_START_OPEN_2 +handleRclKey diff --git a/pch/events.pch b/pch/events.pch new file mode 100644 index 0000000..446139c Binary files /dev/null and b/pch/events.pch differ diff --git a/pch/ext.mk b/pch/ext.mk new file mode 100644 index 0000000..5c632fa --- /dev/null +++ b/pch/ext.mk @@ -0,0 +1,5 @@ +all: $(patsubst %.o,%.ext,$(wildcard *.o)) +# grep fl54.ext G-rayO-n.ref +# mv -f gray096b7.ext fl54.ext +%.ext: %.o + $(O2EXT) "$<" diff --git a/pch/homescr.89y b/pch/homescr.89y new file mode 100644 index 0000000..7fe5a7f Binary files /dev/null and b/pch/homescr.89y differ diff --git a/pch/homescr.def b/pch/homescr.def new file mode 100644 index 0000000..e36722b --- /dev/null +++ b/pch/homescr.def @@ -0,0 +1,20 @@ + +FIFO_ELEMENT +FIFO_NODE +HS_chopFIFO +HS_countFIFO +HS_deleteFIFONode +HS_freeAll +HS_freeFIFONode +HS_getAns +HS_getEntry +HS_getFIFONode +HS_newFIFONode +HS_popEStack +HS_pushEmptyFIFONode +HS_pushFIFONode +HomeExecute +HomePushEStack +HomeStore +HomeStorePair +__HS_pushEmptyFIFONode__type__ diff --git a/pch/homescr.pch b/pch/homescr.pch new file mode 100644 index 0000000..d1bc129 Binary files /dev/null and b/pch/homescr.pch differ diff --git a/pch/keywords.89y b/pch/keywords.89y new file mode 100644 index 0000000..49e8cf5 Binary files /dev/null and b/pch/keywords.89y differ diff --git a/pch/keywords.def b/pch/keywords.def new file mode 100644 index 0000000..29acff7 --- /dev/null +++ b/pch/keywords.def @@ -0,0 +1,43 @@ + +#define +#elif +#else +#endif +#endm +#if +#ifdef +#ifndef +#include +#macro +#pragma +#pragma lang +#undef +__attribute__ +alloca +asm +break +case +char +const +continue +default +defined +extern +goto +incbin +int +long +regparm +return +short +sizeof +static +stkparm +struct +switch +typedef +typedef struct +union +unsigned +void +volatile diff --git a/pch/keywords.pch b/pch/keywords.pch new file mode 100644 index 0000000..e8f8592 Binary files /dev/null and b/pch/keywords.pch differ diff --git a/pch/script/merge.pl b/pch/script/merge.pl new file mode 100644 index 0000000..4638689 --- /dev/null +++ b/pch/script/merge.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +$out=<>; +$out=~s/\r//g; +chomp $out; +-e $out and die "file already exists, cowardly exiting"; +open OUT,">",$out or die "failed to write file"; +$param=<>; +$param=~s/\r//g; +chomp $param; +die "extended merges aren't supported" if $param!=''; +while (<>) { + chomp; + s/\r//g; + open FILE,"<",$_ or die "failed to open file"; + print OUT while ; + close FILE; +} +close OUT; diff --git a/pch/src/COPYING b/pch/src/COPYING new file mode 100644 index 0000000..2ba72d5 --- /dev/null +++ b/pch/src/COPYING @@ -0,0 +1,340 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) 19yy + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/pch/src/alloc.pchsource b/pch/src/alloc.pchsource new file mode 100644 index 0000000..cc42f3d --- /dev/null +++ b/pch/src/alloc.pchsource @@ -0,0 +1,40 @@ +#var H_NULL D(0) +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var HANDLE typedef unsigned short HANDLE; +#var size_t typedef unsigned long size_t; +#var calloc void *calloc(short,short)__ATTR_LIB_ASM__; +#var calloc_throw void *calloc_throw(short,short)__ATTR_LIB_ASM__; +#var free D(_rom_call(void,(void*),A3)) +#var FreeHandles D(_rom_call(short,(void),23B)) +#var HeapAlloc D(_rom_call(HANDLE,(long),90)) +#var HeapAllocESTACK D(_rom_call(HANDLE,(long),91)) +#var HeapAllocHigh D(_rom_call(HANDLE,(long),92)) +#var HeapAllocHighThrow D(_rom_call(HANDLE,(long),94)) +#var HeapAllocPtr D(_rom_call(void*,(long),A2)) +#var HeapAllocPtrThrow void *HeapAllocPtrThrow(long)__ATTR_TIOS__; +#var HeapAllocThrow D(_rom_call(HANDLE,(long),93)) +#var HeapAvail D(_rom_call(unsigned long,(void),8F)) +#var HeapCompress D(_rom_call(void,(void),95)) +#var HeapDeref D(_rom_call(void*,(HANDLE),96)) +#var HeapEnd D(_rom_call(void*,(void),A1)) +#var HeapFree D(_rom_call(void,(HANDLE),97)) +#var HeapFreeIndir D(_rom_call(void,(void*),98)) +#var HeapFreePtr D(_rom_call(void,(void*),A3)) +#var HeapGetHandle D(_rom_call(HANDLE,(void),239)) +#var HeapGetLock D(_rom_call(short,(HANDLE),9B)) +#var HeapLock D(_rom_call(HANDLE,(HANDLE),9A)) +#var HeapMax D(_rom_call(unsigned long,(void),9C)) +#var HeapMoveHigh D(_rom_call(HANDLE,(HANDLE),A0)) +#var HeapPtrToHandle D(_rom_call(HANDLE,(void*),23A)) +#var HeapRealloc D(_rom_call(HANDLE,(HANDLE,long),9D)) +#var HeapReallocThrow HANDLE HeapReallocThrow(HANDLE,long)__ATTR_TIOS__; +#var HeapSize D(_rom_call(unsigned short,(HANDLE),9E)) +#var HeapUnlock D(_rom_call(HANDLE,(HANDLE),9F)) +#var HLock D(_rom_call(void*,(HANDLE),99)) +#var malloc D(_rom_call(void*,(long),A2)) +#var malloc_throw void *malloc_throw(long)__ATTR_TIOS__; +#var realloc void *realloc(void*,long)__ATTR_LIB_ASM__; +#var realloc_throw void *realloc_throw(void*,long)__ATTR_LIB_ASM__; diff --git a/pch/src/ams2-basfunc.pchsource b/pch/src/ams2-basfunc.pchsource new file mode 100644 index 0000000..51cf2bf --- /dev/null +++ b/pch/src/ams2-basfunc.pchsource @@ -0,0 +1,111 @@ +#var push_approx D(_rom_call(void,(CESI),4F7)) +#var push_augment D(_rom_call(void,(CESI,CESI),496)) +#var push_char D(_rom_call(void,(CESI),497)) +#var push_coldim D(_rom_call(void,(CESI),498)) +#var push_colnorm D(_rom_call(void,(CESI),499)) +#var push_cross_product D(_rom_call(void,(CESI,CESI),4CE)) +#var push_cumsum D(_rom_call(void,(CESI),49A)) +#var push_determinant D(_rom_call(void,(CESI,CESI),49D)) +#var push_diag D(_rom_call(void,(CESI),49E)) +#var push_dimension D(_rom_call(void,(CESI),49F)) +#var push_dotproduct D(_rom_call(void,(CESI,CESI),4A3)) +#var push_eigvc D(_rom_call(void,(CESI),4CF)) +#var push_eigvl D(_rom_call(void,(CESI),4D0)) +#var push_identity_mat D(_rom_call(void,(CESI),4A4)) +#var push_left D(_rom_call(void,(CESI,CESI),4A5)) +#var push_list_to_mat D(_rom_call(void,(CESI,CESI),4A6)) +#var push_mat_to_list D(_rom_call(void,(CESI),4A8)) +#var push_matnorm D(_rom_call(void,(CESI),4A7)) +#var push_mean D(_rom_call(void,(CESI),4A9)) +#var push_median D(_rom_call(void,(CESI),4AA)) +#var push_mid D(_rom_call(void,(CESI,CESI,CESI),4AB)) +#var push_mrow D(_rom_call(void,(CESI,CESI,CESI),4AC)) +#var push_mrowadd D(_rom_call(void,(CESI,CESI,CESI,CESI),4AD)) +#var push_newlist D(_rom_call(void,(CESI),4AE)) +#var push_newmat D(_rom_call(void,(CESI,CESI),4AF)) +#var push_ord D(_rom_call(void,(CESI),4B0)) +#var push_prodlist D(_rom_call(void,(CESI),4B2)) +#var push_randmat D(_rom_call(void,(CESI,CESI),4B4)) +#var push_randnorm D(_rom_call(void,(CESI,CESI),4B5)) +#var push_red_row_ech D(_rom_call(void,(CESI,CESI),4B6)) +#var push_right D(_rom_call(void,(CESI,CESI),4B7)) +#var push_rotate D(_rom_call(void,(CESI,CESI),4B8)) +#var push_round D(_rom_call(void,(CESI,CESI),4B9)) +#var push_row_echelon D(_rom_call(void,(CESI,CESI),4BE)) +#var push_rowadd D(_rom_call(void,(CESI,CESI,CESI),4BA)) +#var push_rowdim D(_rom_call(void,(CESI),4BB)) +#var push_rownorm D(_rom_call(void,(CESI),4BC)) +#var push_rowswap D(_rom_call(void,(CESI,CESI,CESI),4BD)) +#var push_sequence D(_rom_call(void,(CESI,CESI,CESI,CESI,CESI),4BF)) +#var push_shift D(_rom_call(void,(CESI,CESI),4C0)) +#var push_simult D(_rom_call(void,(CESI,CESI,CESI),4C1)) +#var push_stddev D(_rom_call(void,(CESI),4C3)) +#var push_submat D(_rom_call(void,(CESI,CESI,CESI,CESI,CESI),4C4)) +#var push_sumlist D(_rom_call(void,(CESI),4C5)) +#var push_unitv D(_rom_call(void,(CESI),4C8)) +#var push_variance D(_rom_call(void,(CESI),4C9)) +#var did_push_anti_deriv D(_rom_call(short,(CESI,CESI,short),5B1)) +#var did_push_series D(_rom_call(short,(CESI,CESI,CESI,CESI,short),588)) +#var push_1st_derivative D(_rom_call(void,(CESI,CESI),5AE)) +#var push_abs D(_rom_call(void,(CESI),543)) +#var push_acos D(_rom_call(void,(CESI),537)) +#var push_acosh D(_rom_call(void,(CESI),53E)) +#var push_asin D(_rom_call(void,(CESI),536)) +#var push_asinh D(_rom_call(void,(CESI),53D)) +#var push_atan D(_rom_call(void,(CESI),538)) +#var push_atanh D(_rom_call(void,(CESI),53F)) +#var push_ceiling D(_rom_call(void,(CESI),54B)) +#var push_comb D(_rom_call(void,(CESI,CESI),542)) +#var push_comdenom D(_rom_call(void,(CESI,CESI),59B)) +#var push_conj D(_rom_call(void,(CESI),547)) +#var push_cos D(_rom_call(void,(CESI),533)) +#var push_cosh D(_rom_call(void,(CESI),53B)) +#var push_csolve D(_rom_call(void,(CESI,CESI),585)) +#var push_czeros D(_rom_call(void,(CESI,CESI),587)) +#var push_def_int D(_rom_call(void,(CESI,CESI,CESI,CESI),5B2)) +#var push_denominator D(_rom_call(void,(CESI),55B)) +#var push_desolve D(_rom_call(void,(CESI),58B)) +#var push_exp D(_rom_call(void,(CESI),52E)) +#var push_expand D(_rom_call(void,(CESI,CESI,short),59A)) +#var push_extended_prod D(_rom_call(void,(CESI,CESI,CESI,CESI),5B5)) +#var push_factor D(_rom_call(void,(CESI,CESI,short),59C)) +#var push_floor D(_rom_call(void,(CESI),54A)) +#var push_fractional_part D(_rom_call(void,(CESI),54E)) +#var push_gcd_numbers D(_rom_call(void,(CESI,CESI),514)) +#var push_im D(_rom_call(void,(CESI),546)) +#var push_integer_gcd D(_rom_call(void,(CESI,CESI),551)) +#var push_integer_lcm D(_rom_call(void,(CESI,CESI),552)) +#var push_integer_part D(_rom_call(void,(CESI),54D)) +#var push_integer_quotient D(_rom_call(void,(CESI,CESI),54F)) +#var push_integer_remainder D(_rom_call(void,(CESI,CESI),550)) +#var push_is_prime D(_rom_call(void,(CESI),515)) +#var push_lim D(_rom_call(void,(CESI,CESI,CESI,CESI),5AD)) +#var push_ln D(_rom_call(void,(CESI),52F)) +#var push_log10 D(_rom_call(void,(CESI),530)) +#var push_max1 D(_rom_call(void,(CESI),554)) +#var push_max2 D(_rom_call(void,(CESI,CESI),599)) +#var push_max D(_rom_call(void,(CESI,CESI),58A)) +#var push_min1 D(_rom_call(void,(CESI),553)) +#var push_min2 D(_rom_call(void,(CESI,CESI),598)) +#var push_min D(_rom_call(void,(CESI,CESI),589)) +#var push_mod D(_rom_call(void,(CESI,CESI),54C)) +#var push_nint D(_rom_call(void,(CESI,CESI,CESI,CESI),5B3)) +#var push_nsolve D(_rom_call(void,(CESI,CESI),583)) +#var push_nth_derivative D(_rom_call(void,(CESI,CESI,CESI),5AF)) +#var push_numerator D(_rom_call(void,(CESI),55A)) +#var push_perm D(_rom_call(void,(CESI,CESI),541)) +#var push_phase D(_rom_call(void,(CESI),548)) +#var push_r_cis D(_rom_call(void,(CESI,CESI),549)) +#var push_re D(_rom_call(void,(CESI),545)) +#var push_rec_to_angle D(_rom_call(void,(CESI,CESI),539)) +#var push_sign D(_rom_call(void,(CESI),544)) +#var push_sin2 D(_rom_call(void,(CESI,CESI),531)) +#var push_sin D(_rom_call(void,(CESI),532)) +#var push_sinh D(_rom_call(void,(CESI),53A)) +#var push_solve D(_rom_call(void,(CESI,CESI),584)) +#var push_sqrt D(_rom_call(void,(CESI),52B)) +#var push_summation D(_rom_call(void,(CESI,CESI,CESI,CESI),5B4)) +#var push_tan D(_rom_call(void,(CESI),534)) +#var push_tanh D(_rom_call(void,(CESI),53C)) +#var push_when D(_rom_call(void,(CESI),57D)) +#var push_zeros D(_rom_call(void,(CESI,CESI),586)) diff --git a/pch/src/ams2-basop.pchsource b/pch/src/ams2-basop.pchsource new file mode 100644 index 0000000..0288548 --- /dev/null +++ b/pch/src/ams2-basop.pchsource @@ -0,0 +1,30 @@ +#var push_assignment D(_rom_call(void,(CESI),4DD)) +#var push_dot_add D(_rom_call(void,(CESI,CESI),4A0)) +#var push_dot_div D(_rom_call(void,(CESI,CESI),4CD)) +#var push_dot_mult D(_rom_call(void,(CESI,CESI),4A1)) +#var push_dot_sub D(_rom_call(void,(CESI,CESI),4A2)) +#var push_radians D(_rom_call(void,(CESI),4B3)) +#var push_substitute_no_simplify D(_rom_call(void,(CESI,CESI,CESI),489)) +#var push_and D(_rom_call(void,(CESI,CESI),5AB)) +#var push_arg_minus_1 D(_rom_call(void,(CESI),520)) +#var push_arg_plus_1 D(_rom_call(void,(CESI),51F)) +#var push_difference D(_rom_call(void,(CESI,CESI),51A)) +#var push_dot_exponentiate D(_rom_call(void,(CESI,CESI),596)) +#var push_equals D(_rom_call(void,(CESI,CESI),5A3)) +#var push_exponentiate D(_rom_call(void,(CESI,CESI),595)) +#var push_factorial D(_rom_call(void,(CESI),540)) +#var push_greater_than D(_rom_call(void,(CESI,CESI),5A5)) +#var push_greater_than_or_equals D(_rom_call(void,(CESI,CESI),5A7)) +#var push_less_than D(_rom_call(void,(CESI,CESI),5A6)) +#var push_less_than_or_equals D(_rom_call(void,(CESI,CESI),5A8)) +#var push_negate D(_rom_call(void,(CESI),524)) +#var push_not D(_rom_call(void,(CESI),5AA)) +#var push_not_equals D(_rom_call(void,(CESI,CESI),5A4)) +#var push_or D(_rom_call(void,(CESI,CESI),5AC)) +#var push_percent D(_rom_call(void,(CESI),555)) +#var push_product D(_rom_call(void,(CESI,CESI),521)) +#var push_ratio D(_rom_call(void,(CESI,CESI),526)) +#var push_square D(_rom_call(void,(CESI),52C)) +#var push_sum D(_rom_call(void,(CESI,CESI),594)) +#var push_substitute_simplify D(_rom_call(void,(CESI,CESI,CESI),5B9)) +#var push_substitute_using_such_that D(_rom_call(void,(CESI,CESI,CESI),5BE)) diff --git a/pch/src/ams2-kbd.pchsource b/pch/src/ams2-kbd.pchsource new file mode 100644 index 0000000..30fe5db --- /dev/null +++ b/pch/src/ams2-kbd.pchsource @@ -0,0 +1,6 @@ +#var alphaLockOff D(_rom_call(void,(unsigned char*),482)) +#var alphaLockOn D(_rom_call(void,(unsigned char*),481)) +#var GetAlphaStatus D(_rom_call(unsigned char,(void),164)) +#var KeyYesOrNo D(_rom_call(short,(short),3EB)) +#var restoreAlphaLock D(_rom_call(void,(unsigned char*),483)) +#var SetAlphaStatus D(_rom_call(void,(char),163)) diff --git a/pch/src/ams2-menus.pchsource b/pch/src/ams2-menus.pchsource new file mode 100644 index 0000000..373d01f --- /dev/null +++ b/pch/src/ams2-menus.pchsource @@ -0,0 +1,10 @@ +#var DynMenuAdd D(_rom_call(HANDLE,(HANDLE,short,const void*,short,short),3F1)) +#var DynMenuChange D(_rom_call(HANDLE,(HANDLE,short,const void*,short),3F0)) +#var MenuFlags D(_rom_call(short,(HANDLE),3F4)) +#var MenuItemDef D(_rom_call(void*,(HANDLE,short,__pushort),3F3)) +#var MenuLoad D(_rom_call(HANDLE,(const void*,short),3F2)) +#var MenuOff D(_rom_call(void,(HANDLE),419)) +#var PopupBegin D(_rom_call(HANDLE,(HANDLE,short),3F5)) +#var PopupBeginDo D(_rom_call(short,(HANDLE,short,short,short),3F6)) +#var QMenuTopSelect D(_rom_call(unsigned short,(HANDLE),41A)) +#var FKeyI_H D(_rom_call(short,(HANDLE,short),592)) diff --git a/pch/src/args-le.pchsource b/pch/src/args-le.pchsource new file mode 100644 index 0000000..a1cdd63 --- /dev/null +++ b/pch/src/args-le.pchsource @@ -0,0 +1,48 @@ + +#var NULL D(((void*)0)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var ESI typedef ESQ*ESI; +#var EStackIndex D(ESI) +#var Quantum D(ESQ) +#var SYM_STR typedef CESI SYM_STR; +#var POSINT_TAG D(31) +#var NEGINT_TAG D(32) +#var FLOAT_TAG D(35) +#var BCD_TAG D(35) +#var UNDEF_TAG D(42) +#var FALSE_TAG D(43) +#var TRUE_TAG D(44) +#var STR_TAG D(45) +#var LIST_TAG D(217) +#var USERFUNC_TAG D(218) +#var MATRIX_TAG D(219) +#var FUNC_TAG D(220) +#var DATA_TAG D(221) +#var GDB_TAG D(222) +#var PIC_TAG D(223) +#var TEXT_TAG D(224) +#var FIG_TAG D(225) +#var MAC_TAG D(226) +#var END_TAG D(229) +#var ASM_TAG D(243) +#var OTH_TAG D(248) + +#var ti_float typedef float ti_float; +#var top_estack D((*((ESI*)(_rom_call_addr(109))))) +#var ArgCount() D((RemainingArgCnt(top_estack))) +#var EX_getArg D(_rom_call(ESI,(short),BE)) +#var EX_getBCD D(_rom_call(short,(short,float*),BF)) +#var GetArgType(p) D((*(CESI)(p))) +#var GetFloatArg(p) D(({float __f;(ESI)(p)-=10;_rom_call(void*,(),26A)(&__f,(ESI)(p)+1,9L);((char*)&__f)[9]=0;__f;})) +#var GetIntArg(p) D(({register unsigned short __n=*(--(ESI)(p));register unsigned long __s=0;while(__n--)__s=(__s<<8)+*(--(unsigned char*)(p));(ESI)(p)--;__s;})) +#var GetLongLongArg(p) D(({register unsigned short __n=*(--(ESI)(p));register unsigned long long __s=0;while(__n--)__s=(__s<<8)+*(--(unsigned char*)(p));(ESI)(p)--;__s;})) +#var GetStrnArg(p) D(({(ESI)(p)-=2;while(*(ESI)(p)--);(const char*)((ESI)(p)+2);})) +#var GetSymstrArg(p) D(({register ESI __t=(ESI)(p);(ESI)(p)-=2;while(*(ESI)(p)--);(const char*)(__t-1);})) +#var InitArgPtr(p) D(((void)((p)=top_estack))) +#var SkipArg(p) D(((void)((p)=_rom_call(ESI,(ESI),10A)(p)))) +#var RemainingArgCnt D(_rom_call(unsigned short,(CESI),3C3)) diff --git a/pch/src/args.pchsource b/pch/src/args.pchsource new file mode 100644 index 0000000..d4f9861 --- /dev/null +++ b/pch/src/args.pchsource @@ -0,0 +1,263 @@ + +#var NULL D(((void*)0)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var ESI typedef ESQ*ESI; +#var EStackIndex D(ESI) +#var Quantum D(ESQ) +#var SYM_STR typedef CESI SYM_STR; +#var VAR_NAME_TAG D(0) +#var _VAR_Q_TAG D(1) +#var VAR_R_TAG D(2) +#var VAR_S_TAG D(3) +#var VAR_T_TAG D(4) +#var VAR_U_TAG D(5) +#var VAR_V_TAG D(6) +#var VAR_W_TAG D(7) +#var VAR_X_TAG D(8) +#var VAR_Y_TAG D(9) +#var VAR_Z_TAG D(10) +#var VAR_A_TAG D(11) +#var VAR_B_TAG D(12) +#var VAR_C_TAG D(13) +#var VAR_D_TAG D(14) +#var VAR_E_TAG D(15) +#var VAR_F_TAG D(16) +#var VAR_G_TAG D(17) +#var VAR_H_TAG D(18) +#var VAR_I_TAG D(19) +#var VAR_J_TAG D(20) +#var VAR_K_TAG D(21) +#var VAR_L_TAG D(22) +#var VAR_M_TAG D(23) +#var VAR_N_TAG D(24) +#var VAR_O_TAG D(25) +#var VAR_P_TAG D(26) +#var VAR_Q_TAG D(27) +#var EXT_SYSTEM_TAG D(28) +#var ARB_REAL_TAG D(29) +#var ARB_INT_TAG D(30) +#var POSINT_TAG D(31) +#var NEGINT_TAG D(32) +#var POSFRAC_TAG D(33) +#var NEGFRAC_TAG D(34) +#var FLOAT_TAG D(35) +#var BCD_TAG D(35) +#var PI_TAG D(36) +#var EXP_TAG D(37) +#var IM_TAG D(38) +#var NEGINFINITY_TAG D(39) +#var INFINITY_TAG D(40) +#var PN_INFINITY_TAG D(41) +#var UNDEF_TAG D(42) +#var FALSE_TAG D(43) +#var TRUE_TAG D(44) +#var STR_TAG D(45) +#var NOTHING_TAG D(46) +#var ACOSH_TAG D(47) +#var ASINH_TAG D(48) +#var ATANH_TAG D(49) +#var COSH_TAG D(53) +#var SINH_TAG D(54) +#var TANH_TAG D(55) +#var ACOS_TAG D(59) +#var ASIN_TAG D(60) +#var ATAN_TAG D(61) +#var RACOS_TAG D(65) +#var RASIN_TAG D(66) +#var RATAN_TAG D(67) +#var COS_TAG D(68) +#var SIN_TAG D(69) +#var TAN_TAG D(70) +#var ITAN_TAG D(74) +#var ABS_TAG D(75) +#var ANGLE_TAG D(76) +#var CEILING_TAG D(77) +#var FLOOR_TAG D(78) +#var INT_TAG D(79) +#var SIGN_TAG D(80) +#var SQRT_TAG D(81) +#var EXPF_TAG D(82) +#var LN_TAG D(83) +#var LOG_TAG D(84) +#var FPART_TAG D(85) +#var IPART_TAG D(86) +#var CONJ_TAG D(87) +#var IMAG_TAG D(88) +#var REAL_TAG D(89) +#var APPROX_TAG D(90) +#var TEXPAND_TAG D(91) +#var TCOLLECT_TAG D(92) +#var GETDENOM_TAG D(93) +#var GETNUM_TAG D(94) +#var CUMSUM_TAG D(96) +#var DET_TAG D(97) +#var COLNORM_TAG D(98) +#var ROWNORM_TAG D(99) +#var NORM_TAG D(100) +#var MEAN_TAG D(101) +#var MEDIAN_TAG D(102) +#var PRODUCT_TAG D(103) +#var STDDEV_TAG D(104) +#var SUM_TAG D(105) +#var VARIANCE_TAG D(106) +#var UNITV_TAG D(107) +#var DIM_TAG D(108) +#var MAT2LIST_TAG D(109) +#var NEWLIST_TAG D(110) +#var RREF_TAG D(111) +#var REF_TAG D(112) +#var IDENTITY_TAG D(113) +#var DIAG_TAG D(114) +#var COLDIM_TAG D(115) +#var ROWDIM_TAG D(116) +#var TRANSPOSE_TAG D(117) +#var FACTORIAL_TAG D(118) +#var PERCENT_TAG D(119) +#var RADIANS_TAG D(120) +#var NOT_TAG D(121) +#var MINUS_TAG D(122) +#var VEC_POLAR_TAG D(123) +#var VEC_CYLIND_TAG D(124) +#var VEC_SPHERE_TAG D(125) +#var START_TAG D(126) +#var ISTORE_TAG D(127) +#var STORE_TAG D(128) +#var WITH_TAG D(129) +#var XOR_TAG D(130) +#var OR_TAG D(131) +#var AND_TAG D(132) +#var LT_TAG D(133) +#var LE_TAG D(134) +#var EQ_TAG D(135) +#var GE_TAG D(136) +#var GT_TAG D(137) +#var NE_TAG D(138) +#var ADD_TAG D(139) +#var ADDELT_TAG D(140) +#var SUB_TAG D(141) +#var SUBELT_TAG D(142) +#var MUL_TAG D(143) +#var MULELT_TAG D(144) +#var DIV_TAG D(145) + +#var DIVELT_TAG D(146) +#var POW_TAG D(147) +#var POWELT_TAG D(148) +#var SINCOS_TAG D(149) +#var SOLVE_TAG D(150) +#var CSOLVE_TAG D(151) +#var NSOLVE_TAG D(152) +#var ZEROS_TAG D(153) +#var CZEROS_TAG D(154) +#var FMIN_TAG D(155) +#var FMAX_TAG D(156) +#var COMPLEX_TAG D(157) +#var POLYEVAL_TAG D(158) +#var RANDPOLY_TAG D(159) +#var CROSSP_TAG D(160) +#var DOTP_TAG D(161) +#var GCD_TAG D(162) +#var LCM_TAG D(163) +#var MOD_TAG D(164) +#var INTDIV_TAG D(165) +#var REMAIN_TAG D(166) +#var NCR_TAG D(167) +#var NPR_TAG D(168) +#var P2RX_TAG D(169) +#var P2RY_TAG D(170) +#var P2PTHETA_TAG D(171) +#var P2PR_TAG D(172) +#var AUGMENT_TAG D(173) +#var NEWMAT_TAG D(174) +#var RANDMAT_TAG D(175) +#var SIMULT_TAG D(176) +#var PART_TAG D(177) +#var EXP2LIST_TAG D(178) +#var RANDNORM_TAG D(179) +#var MROW_TAG D(180) +#var ROWADD_TAG D(181) +#var ROWSWAP_TAG D(182) +#var ARCLEN_TAG D(183) +#var NINT_TAG D(184) +#var PI_PRODUCT_TAG D(185) +#var SIGMA_SUM_TAG D(186) +#var MROWADD_TAG D(187) +#var ANS_TAG D(188) +#var ENTRY_TAG D(189) +#var EXACT_TAG D(190) +#var LOGB_TAG D(191) +#var COMDENOM_TAG D(192) +#var EXPAND_TAG D(193) +#var FACTOR_TAG D(194) +#var CFACTOR_TAG D(195) +#var INTEGRATE_TAG D(196) +#var DIFFERENTIATE_TAG D(197) +#var AVGRC_TAG D(198) +#var NDERIV_TAG D(199) +#var TAYLOR_TAG D(200) +#var LIMIT_TAG D(201) +#var PROPFRAC_TAG D(202) +#var WHEN_TAG D(203) +#var ROUND_TAG D(204) +#var DMS_TAG D(205) +#var LEFT_TAG D(206) +#var RIGHT_TAG D(207) +#var MID_TAG D(208) +#var SHIFT_TAG D(209) +#var SEQ_TAG D(210) +#var LIST2MAT_TAG D(211) +#var SUBMAT_TAG D(212) +#var SUBSCRIPT_TAG D(213) +#var RAND_TAG D(214) +#var MIN_TAG D(215) +#var MAX_TAG D(216) +#var LIST_TAG D(217) +#var USERFUNC_TAG D(218) +#var MATRIX_TAG D(219) +#var FUNC_TAG D(220) +#var DATA_TAG D(221) +#var GDB_TAG D(222) +#var PIC_TAG D(223) +#var TEXT_TAG D(224) +#var FIG_TAG D(225) +#var MAC_TAG D(226) +#var EXT_TAG D(227) +#var EXT_INSTR_TAG D(228) +#var END_TAG D(229) +#var COMMENT_TAG D(230) +#var NEXTEXPR_TAG D(231) +#var NEWLINE_TAG D(232) +#var ENDSTACK_TAG D(233) +#var PN1_TAG D(234) +#var PN2_TAG D(235) +#var ERROR_MSG_TAG D(236) +#var EIGVC_TAG D(237) +#var EIGVL_TAG D(238) +#var DASH_TAG D(239) +#var LOCALVAR_TAG D(240) +#var DESOLVE_TAG D(241) +#var FDASH_TAG D(242) +#var ASM_TAG D(243) +#var ISPRIME_TAG D(244) +#var OTH_TAG D(248) +#var ROTATE_TAG D(249) + +#var ti_float typedef float ti_float; +#var top_estack D((*((ESI*)(_rom_call_addr(109))))) +#var ArgCount() D((RemainingArgCnt(top_estack))) +#var EX_getArg D(_rom_call(ESI,(short),BE)) +#var EX_getBCD D(_rom_call(short,(short,float*),BF)) +#var GetArgType(p) D((*(CESI)(p))) +#var GetFloatArg(p) D(({float __f;(ESI)(p)-=10;_rom_call(void*,(),26A)(&__f,(ESI)(p)+1,9L);((char*)&__f)[9]=0;__f;})) +#var GetIntArg(p) D(({register unsigned short __n=*(--(ESI)(p));register unsigned long __s=0;while(__n--)__s=(__s<<8)+*(--(unsigned char*)(p));(ESI)(p)--;__s;})) +#var GetLongLongArg(p) D(({register unsigned short __n=*(--(ESI)(p));register unsigned long long __s=0;while(__n--)__s=(__s<<8)+*(--(unsigned char*)(p));(ESI)(p)--;__s;})) +#var GetStrnArg(p) D(({(ESI)(p)-=2;while(*(ESI)(p)--);(const char*)((ESI)(p)+2);})) +#var GetSymstrArg(p) D(({register ESI __t=(ESI)(p);(ESI)(p)-=2;while(*(ESI)(p)--);(const char*)(__t-1);})) +#var InitArgPtr(p) D(((void)((p)=top_estack))) +#var SkipArg(p) D(((void)((p)=_rom_call(ESI,(ESI),10A)(p)))) +#var RemainingArgCnt D(_rom_call(unsigned short,(CESI),3C3)) diff --git a/pch/src/asmtypes.pchsource b/pch/src/asmtypes.pchsource new file mode 100644 index 0000000..2baffd0 --- /dev/null +++ b/pch/src/asmtypes.pchsource @@ -0,0 +1,20 @@ + +#var BOOL typedef unsigned short BOOL; +#var BYTE typedef unsigned char BYTE; +#var DWORD typedef unsigned long DWORD; +#var SBYTE typedef signed char SBYTE; +#var SCHAR typedef signed char SCHAR; +#var SDWORD typedef signed long SDWORD; +#var SINT typedef signed int SINT; +#var SLONG typedef signed long SLONG; +#var SSHORT typedef signed short SSHORT; +#var SWORD typedef signed short SWORD; +#var UBYTE typedef unsigned char UBYTE; +#var UCHAR typedef unsigned char UCHAR; +#var UDWORD typedef unsigned long UDWORD; +#var UINT typedef unsigned int UINT; +#var ULONG typedef unsigned long ULONG; +#var USHORT typedef unsigned short USHORT; +#var UWORD typedef unsigned short UWORD; +#var WORD typedef unsigned short WORD; + diff --git a/pch/src/assert.pchsource b/pch/src/assert.pchsource new file mode 100644 index 0000000..055a945 --- /dev/null +++ b/pch/src/assert.pchsource @@ -0,0 +1 @@ +#var __assertion_failed void __assertion_failed(const char*,const char*,short)__ATTR_LIB_ASM_NORETURN__; diff --git a/pch/src/bascmd.pchsource b/pch/src/bascmd.pchsource new file mode 100644 index 0000000..0cd4179 --- /dev/null +++ b/pch/src/bascmd.pchsource @@ -0,0 +1,135 @@ + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var ESI typedef ESQ*ESI; +#var EStackIndex D(ESI) +#var Quantum D(ESQ) +#var SYM_STR typedef CESI SYM_STR; +#var cmd_andpic D(_rom_call(void,(SYM_STR,CESI,CESI),32A)) +#var cmd_blddata D(_rom_call(void,(ESI),32B)) +#var cmd_circle D(_rom_call(void,(CESI,CESI,CESI,CESI),32C)) +#var cmd_clrdraw D(_rom_call(void,(void),32D)) +#var cmd_clrerr D(_rom_call(void,(void),32E)) +#var cmd_clrgraph D(_rom_call(void,(void),32F)) +#var cmd_clrhome D(_rom_call(void,(void),330)) +#var cmd_clrio D(_rom_call(void,(void),331)) +#var cmd_clrtable D(_rom_call(void,(void),332)) +#var cmd_copyvar D(_rom_call(void,(SYM_STR,SYM_STR),333)) +#var cmd_cubicreg D(_rom_call(void,(ESI),334)) +#var cmd_custmoff D(_rom_call(void,(void),335)) +#var cmd_custmon D(_rom_call(void,(void),336)) +#var cmd_custom D(_rom_call(void,(void),337)) +#var cmd_cycle D(_rom_call(void,(void),338)) +#var cmd_cyclepic D(_rom_call(void,(CESI,CESI,CESI,CESI,CESI),339)) +#var cmd_delfold D(_rom_call(void,(CESI),33A)) +#var cmd_delvar D(_rom_call(void,(CESI),33B)) +#var cmd_dialog D(_rom_call(void,(void),33C)) +#var cmd_disp D(_rom_call(void,(CESI),33D)) +#var cmd_dispg D(_rom_call(void,(void),33E)) +#var cmd_disphome D(_rom_call(void,(void),33F)) +#var cmd_disptbl D(_rom_call(void,(void),340)) +#var cmd_drawfunc D(_rom_call(void,(CESI),341)) +#var cmd_drawinv D(_rom_call(void,(CESI),342)) +#var cmd_drawparm D(_rom_call(void,(CESI),343)) +#var cmd_drawpol D(_rom_call(void,(CESI),344)) +#var cmd_else D(_rom_call(void,(void),345)) +#var cmd_endfor D(_rom_call(void,(void),346)) +#var cmd_endloop D(_rom_call(void,(void),347)) +#var cmd_endtry D(_rom_call(void,(void),348)) +#var cmd_endwhile D(_rom_call(void,(void),349)) +#var cmd_exit D(_rom_call(void,(void),34A)) +#var cmd_expreg D(_rom_call(void,(ESI),34B)) +#var cmd_fill D(_rom_call(void,(CESI,SYM_STR),34C)) +#var cmd_fnoff D(_rom_call(void,(CESI),34D)) +#var cmd_fnon D(_rom_call(void,(CESI),34E)) +#var cmd_for D(_rom_call(void,(SYM_STR,CESI,CESI,CESI),34F)) +#var cmd_get D(_rom_call(void,(SYM_STR),350)) +#var cmd_getcalc D(_rom_call(void,(SYM_STR),351)) +#var cmd_goto D(_rom_call(void,(SYM_STR),352)) +#var cmd_graph D(_rom_call(void,(CESI),353)) +#var cmd_if D(_rom_call(void,(CESI),354)) +#var cmd_ifthen D(_rom_call(void,(CESI),355)) +#var cmd_input D(_rom_call(void,(CESI),356)) +#var cmd_inputstr D(_rom_call(void,(ESI),357)) +#var cmd_line D(_rom_call(void,(CESI,CESI,CESI,CESI,CESI),358)) +#var cmd_linehorz D(_rom_call(void,(CESI,CESI),359)) +#var cmd_linetan D(_rom_call(void,(CESI,CESI),35A)) +#var cmd_linevert D(_rom_call(void,(CESI,CESI),35B)) +#var cmd_linreg D(_rom_call(void,(ESI),35C)) +#var cmd_lnreg D(_rom_call(void,(ESI),35D)) +#var cmd_local D(_rom_call(void,(CESI),35E)) +#var cmd_lock D(_rom_call(void,(CESI),35F)) +#var cmd_logistic D(_rom_call(void,(ESI),360)) +#var cmd_medmed D(_rom_call(void,(ESI),361)) +#var cmd_movevar D(_rom_call(void,(SYM_STR,SYM_STR,SYM_STR),362)) +#var cmd_newdata D(_rom_call(void,(CESI),363)) +#var cmd_newfold D(_rom_call(void,(SYM_STR),364)) +#var cmd_newpic D(_rom_call(void,(ESI,SYM_STR,ESI,ESI),365)) +#var cmd_newplot D(_rom_call(void,(ESI),366)) +#var cmd_newprob D(_rom_call(void,(void),367)) +#var cmd_onevar D(_rom_call(void,(ESI),368)) +#var cmd_output D(_rom_call(void,(CESI,CESI,CESI),369)) +#var cmd_passerr D(_rom_call(void,(void),36A)) +#var cmd_pause D(_rom_call(void,(CESI),36B)) +#var cmd_plotsoff D(_rom_call(void,(CESI),36C)) +#var cmd_plotson D(_rom_call(void,(CESI),36D)) +#var cmd_popup D(_rom_call(void,(ESI,ESI),36E)) +#var cmd_powerreg D(_rom_call(void,(ESI),36F)) +#var cmd_printobj D(_rom_call(void,(SYM_STR),370)) +#var cmd_prompt D(_rom_call(void,(CESI),371)) +#var cmd_ptchg D(_rom_call(void,(CESI,CESI),372)) +#var cmd_ptoff D(_rom_call(void,(CESI,CESI),373)) +#var cmd_pton D(_rom_call(void,(CESI,CESI),374)) +#var cmd_pttext D(_rom_call(void,(CESI,CESI,CESI),375)) +#var cmd_pxlchg D(_rom_call(void,(CESI,CESI),376)) +#var cmd_pxlcircle D(_rom_call(void,(CESI,CESI,CESI,CESI),377)) +#var cmd_pxlhorz D(_rom_call(void,(CESI,CESI),378)) +#var cmd_pxlline D(_rom_call(void,(CESI,CESI,CESI,CESI,CESI),379)) +#var cmd_pxloff D(_rom_call(void,(CESI,CESI),37A)) +#var cmd_pxlon D(_rom_call(void,(CESI,CESI),37B)) +#var cmd_pxltext D(_rom_call(void,(CESI,CESI,CESI),37C)) +#var cmd_pxlvert D(_rom_call(void,(CESI,CESI),37D)) +#var cmd_quadreg D(_rom_call(void,(ESI),37E)) +#var cmd_quartreg D(_rom_call(void,(ESI),37F)) +#var cmd_randseed D(_rom_call(void,(CESI),380)) +#var cmd_rclgdb D(_rom_call(void,(SYM_STR),381)) +#var cmd_rclpic D(_rom_call(void,(SYM_STR,CESI,CESI),382)) +#var cmd_rename D(_rom_call(void,(SYM_STR,SYM_STR),383)) +#var cmd_request D(_rom_call(void,(CESI,SYM_STR),384)) +#var cmd_return D(_rom_call(void,(CESI),385)) +#var cmd_rplcpic D(_rom_call(void,(SYM_STR,CESI,CESI),386)) +#var cmd_send D(_rom_call(void,(CESI),387)) +#var cmd_sendcalc D(_rom_call(void,(SYM_STR),388)) +#var cmd_sendchat D(_rom_call(void,(SYM_STR),389)) +#var cmd_shade D(_rom_call(void,(ESI),38A)) +#var cmd_showstat D(_rom_call(void,(void),38B)) +#var cmd_sinreg D(_rom_call(void,(ESI),38C)) +#var cmd_slpline D(_rom_call(void,(CESI,CESI,CESI),38D)) +#var cmd_sorta D(_rom_call(void,(ESI),38E)) +#var cmd_sortd D(_rom_call(void,(ESI),38F)) +#var cmd_stogdb D(_rom_call(void,(SYM_STR),390)) +#var cmd_stopic D(_rom_call(void,(ESI),391)) +#var cmd_style D(_rom_call(void,(CESI,CESI),392)) +#var cmd_table D(_rom_call(void,(ESI),393)) +#var cmd_text D(_rom_call(void,(CESI),394)) +#var cmd_toolbar D(_rom_call(void,(void),395)) +#var cmd_trace D(_rom_call(void,(void),396)) +#var cmd_try D(_rom_call(void,(void),397)) +#var cmd_twovar D(_rom_call(void,(ESI),398)) +#var cmd_unlock D(_rom_call(void,(CESI),399)) +#var cmd_while D(_rom_call(void,(CESI),39A)) +#var cmd_xorpic D(_rom_call(void,(SYM_STR,CESI,CESI),39B)) +#var cmd_zoombox D(_rom_call(void,(void),39C)) +#var cmd_zoomdata D(_rom_call(void,(void),39D)) +#var cmd_zoomdec D(_rom_call(void,(void),39E)) +#var cmd_zoomfit D(_rom_call(void,(void),39F)) +#var cmd_zoomin D(_rom_call(void,(void),3A0)) +#var cmd_zoomint D(_rom_call(void,(void),3A1)) +#var cmd_zoomout D(_rom_call(void,(void),3A2)) +#var cmd_zoomprev D(_rom_call(void,(void),3A3)) +#var cmd_zoomrcl D(_rom_call(void,(void),3A4)) +#var cmd_zoomsqr D(_rom_call(void,(void),3A5)) +#var cmd_zoomstd D(_rom_call(void,(void),3A6)) +#var cmd_zoomsto D(_rom_call(void,(void),3A7)) +#var cmd_zoomtrig D(_rom_call(void,(void),3A8)) + diff --git a/pch/src/basfunc.pchsource b/pch/src/basfunc.pchsource new file mode 100644 index 0000000..c3c2dea --- /dev/null +++ b/pch/src/basfunc.pchsource @@ -0,0 +1,28 @@ + +#var NULL_INDEX D(((CESI)0)) +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var ESI typedef ESQ*ESI; +#var EStackIndex D(ESI) +#var Quantum D(ESQ) +#var SYM_STR typedef CESI SYM_STR; +#var push_getfold D(_rom_call(void,(void),317)) +#var push_getkey D(_rom_call(void,(void),316)) +#var push_getmode D(_rom_call(void,(CESI),318)) +#var push_gettype D(_rom_call(void,(CESI),319)) +#var push_instring D(_rom_call(void,(CESI,CESI,CESI),31A)) +#var push_part D(_rom_call(void,(),31C)) +#var push_pttest D(_rom_call(void,(CESI,CESI),31D)) +#var push_pxltest D(_rom_call(void,(CESI,CESI),31E)) +#var push_rand D(_rom_call(void,(CESI),31F)) +#var push_randpoly D(_rom_call(void,(CESI,CESI),320)) +#var push_setfold D(_rom_call(void,(CESI),321)) +#var push_setgraph D(_rom_call(void,(CESI,CESI),322)) +#var push_setmode D(_rom_call(void,(CESI,CESI),323)) +#var push_settable D(_rom_call(void,(CESI,CESI),324)) +#var push_str_to_expr D(_rom_call(void,(CESI),325)) +#var push_string D(_rom_call(void,(CESI),326)) +#var push_switch D(_rom_call(void,(CESI),327)) + +#var push_subst_no_simp D(push_substitute_no_simplify) +#var push_nSolve D(push_nsolve) diff --git a/pch/src/basop.pchsource b/pch/src/basop.pchsource new file mode 100644 index 0000000..caf673a --- /dev/null +++ b/pch/src/basop.pchsource @@ -0,0 +1,17 @@ + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var ESI typedef ESQ*ESI; +#var EStackIndex D(ESI) +#var Quantum D(ESQ) +#var SYM_STR typedef CESI SYM_STR; +#var did_push_to_polar D(_rom_call(short,(),313)) +#var push_degrees D(_rom_call(void,(CESI,CESI,CESI),314)) +#var push_indir_name D(_rom_call(void,(CESI),2B2)) +#var push_list_plus D(_rom_call(void,(CESI,CESI),3BD)) +#var push_list_times D(_rom_call(void,(CESI,CESI),3BE)) +#var push_matrix_product D(_rom_call(void,(CESI,CESI),3C5)) +#var push_pow D(_rom_call(void,(CESI,CESI),30F)) +#var push_to_cylin D(_rom_call(void,(),328)) +#var push_to_sphere D(_rom_call(void,(),329)) + diff --git a/pch/src/cert.pchsource b/pch/src/cert.pchsource new file mode 100644 index 0000000..8ce43d0 --- /dev/null +++ b/pch/src/cert.pchsource @@ -0,0 +1,27 @@ + +#var H_NULL D(0) +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var CERT_FIELD typedef struct{unsigned short Field;unsigned short HdrLen;unsigned long Len;void*Data;}CERT_FIELD; +#var CFILE typedef struct{void*Start,*Pos,*End;short EOFVal;}CFILE; +#var HANDLE typedef unsigned short HANDLE; +#var size_t typedef unsigned long size_t; +#var ceof D(_rom_call(short,(CFILE*),128)) +#var cfindfield D(_rom_call(short,(CFILE*,short,CERT_FIELD*),12A)) +#var cgetc D(_rom_call(unsigned char,(CFILE*),12B)) +#var cgetcertrevno D(_rom_call(short,(__plong),2A0)) +#var cgetflen D(_rom_call(unsigned long,(CFILE*,short),12D)) +#var cgetfnl D(_rom_call(long,(CERT_FIELD*),12E)) +#var cgetnl D(_rom_call(long,(CFILE*),12F)) +#var cgetns D(_rom_call(short,(CFILE*),130)) +#var cgetsn D(_rom_call(void,(char*),2A1)) +#var copen D(_rom_call(void,(CFILE*,char*,long),132)) +#var copensub D(_rom_call(void,(CFILE*,CERT_FIELD*),133)) +#var cputhdr D(_rom_call(short,(CFILE*,short,short),134)) +#var cputnl D(_rom_call(void,(CFILE*,long),135)) +#var cputns D(_rom_call(void,(CFILE*,short),136)) +#var cread D(_rom_call(short,(CFILE*,CERT_FIELD*),137)) +#var ctell D(_rom_call(unsigned long,(CFILE*),138)) +#var cwrite D(_rom_call(short,(CFILE*,CERT_FIELD*),139)) diff --git a/pch/src/compat-x.pchsource b/pch/src/compat-x.pchsource new file mode 100644 index 0000000..2ae033e --- /dev/null +++ b/pch/src/compat-x.pchsource @@ -0,0 +1,89 @@ +#var _RR(a,b,c,d) D((CALCULATOR?a:b),(CALCULATOR?c:d)) +#var _RS(a,b) D((CALCULATOR?a:b)) +#var RR_0 D(_RR(9,4,5,0)) +#var RR_1 D(_RR(1,4,5,1)) +#var RR_2 D(_RR(1,3,6,1)) +#var RR_3 D(_RR(1,2,7,1)) +#var RR_4 D(_RR(2,4,5,2)) +#var RR_5 D(_RR(2,3,6,2)) +#var RR_6 D(2,_RS(7,2)) +#var RR_7 D(_RR(3,4,5,3)) +#var RR_8 D(3,_RS(6,3)) +#var RR_9 D(_RR(3,2,7,3)) +#var RR_2ND D(0,_RS(0,4)) +#var RR_A D(_RR(9,15,2,15)) +#var RR_ALPHA D(_RR(15,0,15,7)) +#var RR_APPS D(_RR(7,5,6,0)) +#var RR_B D(_RR(5,15,1,15)) +#var RR_BCKSPC D(_RR(8,2,0,6)) +#var RR_C D(_RR(3,15,1,15)) +#var RR_CATALOG D(_RR(15,3,15,6)) +#var RR_CLEAR D(_RR(7,1,5,6)) +#var RR_COMMA D(_RR(4,2,7,4)) +#var RR_COS D(_RR(5,15,6,15)) +#var RR_D D(_RR(2,15,2,15)) +#var RR_DIAMOND D(0,_RS(1,6)) +#var RR_DIVIDE D(_RR(5,1,0,4)) +#var RR_DOT D(_RR(9,3,6,0)) +#var RR_DOWN D(0,_RS(7,2)) +#var RR_E D(_RR(2,15,3,15)) +#var RR_EE D(_RR(15,5,15,2)) +#var RR_ENTER1 D(_RR(9,1,1,0)) +#var RR_ENTER2 D(_RR(6,1,6,0)) +#var RR_ENTER D(RR_ENTER1) +#var RR_EQUALS D(15,15) +#var RR_ESC D(_RR(8,6,6,0)) +#var RR_F1 D(_RR(6,5,4,7)) +#var RR_F2 D(4,_RS(4,7)) +#var RR_F3 D(_RR(2,3,4,7)) +#var RR_F4 D(_RR(9,2,4,7)) +#var RR_F5 D(_RR(7,1,4,7)) +#var RR_F6 D(_RR(5,15,4,15)) +#var RR_F7 D(_RR(3,15,4,15)) +#var RR_F8 D(_RR(1,15,4,15)) +#var RR_F D(_RR(3,15,2,15)) +#var RR_G D(_RR(4,15,2,15)) +#var RR_H D(_RR(5,15,2,15)) +#var RR_HAND D(_RR(0,15,3,15)) +#var RR_HOME D(_RR(15,5,15,6)) +#var RR_I D(_RR(7,15,3,15)) +#var RR_J D(_RR(6,15,2,15)) +#var RR_K D(_RR(7,15,2,15)) +#var RR_L D(_RR(8,15,2,15)) +#var RR_LEFT D(0,_RS(4,1)) +#var RR_LN D(_RR(6,15,5,15)) +#var RR_M D(_RR(7,15,1,15)) +#var RR_MINUS D(_RR(9,1,0,2)) +#var RR_MODE D(_RR(8,4,5,6)) +#var RR_MULTIPLY D(_RR(7,1,7,3)) +#var RR_N D(_RR(6,15,1,15)) +#var RR_NEGATE D(_RR(9,2,7,0)) +#var RR_NO_KEY D(15) +#var RR_O D(_RR(8,15,3,15)) +#var RR_P D(_RR(6,15,7,15)) +#var RR_PAREN_CLOSE D(_RR(4,3,6,4)) +#var RR_PAREN_OPEN D(4,_RS(5,4)) +#var RR_PLUS D(_RR(8,1,4,1)) +#var RR_POWER D(_RR(6,1,0,5)) +#var RR_Q D(_RR(9,15,3,15)) +#var RR_R D(_RR(3,15,3,15)) +#var RR_RIGHT D(0,_RS(6,3)) +#var RR_S D(_RR(1,15,2,15)) +#var RR_SHIFT D(0,_RS(2,5)) +#var RR_SIN D(_RR(5,15,5,15)) +#var RR_SPACE D(_RR(4,15,0,15)) +#var RR_STORE D(_RR(3,5,0,1)) +#var RR_T D(_RR(4,2,3,5)) +#var RR_TAN D(_RR(5,15,7,15)) +#var RR_THETA D(_RR(8,15,1,15)) +#var RR_U D(_RR(6,15,3,15)) +#var RR_UP D(0,_RS(5,0)) +#var RR_V D(_RR(4,15,1,15)) +#var RR_W D(_RR(1,15,3,15)) +#var RR_WITH D(_RR(15,5,15,3)) +#var RR_X D(_RR(2,5,1,5)) +#var RR_Y D(_RR(5,4,3,5)) +#var RR_Z D(_RR(1,3,1,5)) +#var TI89 D((CALCULATOR==0)) +#var TI92PLUS D((CALCULATOR==1)) +#var V200 D((CALCULATOR==3)) diff --git a/pch/src/compat.pchsource b/pch/src/compat.pchsource new file mode 100644 index 0000000..85d5387 --- /dev/null +++ b/pch/src/compat.pchsource @@ -0,0 +1,87 @@ +#var RR_0 D((CALCULATOR?9:4),(CALCULATOR?5:0)) +#var RR_1 D((CALCULATOR?1:4),(CALCULATOR?5:1)) +#var RR_2 D((CALCULATOR?1:3),(CALCULATOR?6:1)) +#var RR_3 D((CALCULATOR?1:2),(CALCULATOR?7:1)) +#var RR_4 D((CALCULATOR?2:4),(CALCULATOR?5:2)) +#var RR_5 D((CALCULATOR?2:3),(CALCULATOR?6:2)) +#var RR_6 D(2,(CALCULATOR?7:2)) +#var RR_7 D((CALCULATOR?3:4),(CALCULATOR?5:3)) +#var RR_8 D(3,(CALCULATOR?6:3)) +#var RR_9 D((CALCULATOR?3:2),(CALCULATOR?7:3)) +#var RR_2ND D(0,(CALCULATOR?0:4)) +#var RR_A D((CALCULATOR?9:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_ALPHA D((CALCULATOR?RR_NO_KEY:0),(CALCULATOR?RR_NO_KEY:7)) +#var RR_APPS D((CALCULATOR?7:5),(CALCULATOR?6:0)) +#var RR_B D((CALCULATOR?5:RR_NO_KEY),(CALCULATOR?1:RR_NO_KEY)) +#var RR_BCKSPC D((CALCULATOR?8:2),(CALCULATOR?0:6)) +#var RR_C D((CALCULATOR?3:RR_NO_KEY),(CALCULATOR?1:RR_NO_KEY)) +#var RR_CATALOG D((CALCULATOR?RR_NO_KEY:3),(CALCULATOR?RR_NO_KEY:6)) +#var RR_CLEAR D((CALCULATOR?7:1),(CALCULATOR?5:6)) +#var RR_COMMA D((CALCULATOR?4:2),(CALCULATOR?7:4)) +#var RR_COS D((CALCULATOR?5:RR_NO_KEY),(CALCULATOR?6:RR_NO_KEY)) +#var RR_D D((CALCULATOR?2:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_DIAMOND D(0,(CALCULATOR?1:6)) +#var RR_DIVIDE D((CALCULATOR?5:1),(CALCULATOR?0:4)) +#var RR_DOT D((CALCULATOR?9:3),(CALCULATOR?6:0)) +#var RR_DOWN D(0,(CALCULATOR?7:2)) +#var RR_E D((CALCULATOR?2:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_EE D((CALCULATOR?RR_NO_KEY:5),(CALCULATOR?RR_NO_KEY:2)) +#var RR_ENTER1 D((CALCULATOR?9:1),(CALCULATOR?1:0)) +#var RR_ENTER2 D((CALCULATOR?6:1),(CALCULATOR?6:0)) +#var RR_ENTER D(RR_ENTER1) +#var RR_EQUALS D(RR_NO_KEY,RR_NO_KEY) +#var RR_ESC D((CALCULATOR?8:6),(CALCULATOR?6:0)) +#var RR_F1 D((CALCULATOR?6:5),(CALCULATOR?4:7)) +#var RR_F2 D(4,(CALCULATOR?4:7)) +#var RR_F3 D((CALCULATOR?2:3),(CALCULATOR?4:7)) +#var RR_F4 D((CALCULATOR?9:2),(CALCULATOR?4:7)) +#var RR_F5 D((CALCULATOR?7:1),(CALCULATOR?4:7)) +#var RR_F6 D((CALCULATOR?5:RR_NO_KEY),(CALCULATOR?4:RR_NO_KEY)) +#var RR_F7 D((CALCULATOR?3:RR_NO_KEY),(CALCULATOR?4:RR_NO_KEY)) +#var RR_F8 D((CALCULATOR?1:RR_NO_KEY),(CALCULATOR?4:RR_NO_KEY)) +#var RR_F D((CALCULATOR?3:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_G D((CALCULATOR?4:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_H D((CALCULATOR?5:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_HAND D((CALCULATOR?0:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_HOME D((CALCULATOR?RR_NO_KEY:5),(CALCULATOR?RR_NO_KEY:6)) +#var RR_I D((CALCULATOR?7:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_J D((CALCULATOR?6:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_K D((CALCULATOR?7:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_L D((CALCULATOR?8:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_LEFT D(0,(CALCULATOR?4:1)) +#var RR_LN D((CALCULATOR?6:RR_NO_KEY),(CALCULATOR?5:RR_NO_KEY)) +#var RR_M D((CALCULATOR?7:RR_NO_KEY),(CALCULATOR?1:RR_NO_KEY)) +#var RR_MINUS D((CALCULATOR?9:1),(CALCULATOR?0:2)) +#var RR_MODE D((CALCULATOR?8:4),(CALCULATOR?5:6)) +#var RR_MULTIPLY D((CALCULATOR?7:1),(CALCULATOR?7:3)) +#var RR_N D((CALCULATOR?6:RR_NO_KEY),(CALCULATOR?1:RR_NO_KEY)) +#var RR_NEGATE D((CALCULATOR?9:2),(CALCULATOR?7:0)) +#var RR_NO_KEY D(0xF) +#var RR_O D((CALCULATOR?8:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_P D((CALCULATOR?6:RR_NO_KEY),(CALCULATOR?7:RR_NO_KEY)) +#var RR_PAREN_CLOSE D((CALCULATOR?4:3),(CALCULATOR?6:4)) +#var RR_PAREN_OPEN D(4,(CALCULATOR?5:4)) +#var RR_PLUS D((CALCULATOR?8:1),(CALCULATOR?4:1)) +#var RR_POWER D((CALCULATOR?6:1),(CALCULATOR?0:5)) +#var RR_Q D((CALCULATOR?9:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_R D((CALCULATOR?3:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_RIGHT D(0,(CALCULATOR?6:3)) +#var RR_S D((CALCULATOR?1:RR_NO_KEY),(CALCULATOR?2:RR_NO_KEY)) +#var RR_SHIFT D(0,(CALCULATOR?2:5)) +#var RR_SIN D((CALCULATOR?5:RR_NO_KEY),(CALCULATOR?5:RR_NO_KEY)) +#var RR_SPACE D((CALCULATOR?4:RR_NO_KEY),(CALCULATOR?0:RR_NO_KEY)) +#var RR_STORE D((CALCULATOR?3:5),(CALCULATOR?0:1)) +#var RR_T D((CALCULATOR?4:2),(CALCULATOR?3:5)) +#var RR_TAN D((CALCULATOR?5:RR_NO_KEY),(CALCULATOR?7:RR_NO_KEY)) +#var RR_THETA D((CALCULATOR?8:RR_NO_KEY),(CALCULATOR?1:RR_NO_KEY)) +#var RR_U D((CALCULATOR?6:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_UP D(0,(CALCULATOR?5:0)) +#var RR_V D((CALCULATOR?4:RR_NO_KEY),(CALCULATOR?1:RR_NO_KEY)) +#var RR_W D((CALCULATOR?1:RR_NO_KEY),(CALCULATOR?3:RR_NO_KEY)) +#var RR_WITH D((CALCULATOR?RR_NO_KEY:5),(CALCULATOR?RR_NO_KEY:3)) +#var RR_X D((CALCULATOR?2:5),(CALCULATOR?1:5)) +#var RR_Y D((CALCULATOR?5:4),(CALCULATOR?3:5)) +#var RR_Z D((CALCULATOR?1:3),(CALCULATOR?1:5)) +#var TI89 D((CALCULATOR==0)) +#var TI92PLUS D((CALCULATOR==1)) +#var V200 D((CALCULATOR==3)) diff --git a/pch/src/compiler-internals.pchsource b/pch/src/compiler-internals.pchsource new file mode 100644 index 0000000..da4564f --- /dev/null +++ b/pch/src/compiler-internals.pchsource @@ -0,0 +1,10 @@ +#var __mulsi3 +#var __divsi3 +#var __modsi3 +#var __udivsi3 +#var __umodsi3 +#var __div_entry + +#var __mulsi3_rp +#var __mulsi3ui2_rp +#var __mulsi3si2_rp diff --git a/pch/src/ctype.pchsource b/pch/src/ctype.pchsource new file mode 100644 index 0000000..01dd536 --- /dev/null +++ b/pch/src/ctype.pchsource @@ -0,0 +1,30 @@ + +#var _tolower(c) D(((c)+'a'-'A')) char _extalnum_list[]; char _extpunct_list[]; +#var _toupper(c) D(((c)+'A'-'a')) +#var isalnum(c) D(({register short __c=(c);(__c>='0'&&__c<='9')||(__c>='A'&&__c<='Z')||(__c>='a'&&__c<='z');})) +#var isalpha(c) D(({register short __c=(c);(__c>='A'&&__c<='Z')||(__c>='a'&&__c<='z');})) +#var isascii(c) D(((unsigned short)(c)<128)) +#var iscntrl(c) D(((unsigned short)(c)<14)) +#var isdigit(c) D(({register short __c=(c);__c>='0'&&__c<='9';})) +#var isextalnum(c) D(({register short __c=(c);(unsigned short)__c<256&&_extalnum_list[__c>>3]&(1<<(__c&7));})) +#var isextlower(c) D(({register short __c=(c);(__c>='a'&&__c<='z')||(__c>=224&&__c<=254&&__c!=247);})) +#var isextpunct(c) D(({register short __c=(c);(unsigned short)__c<256&&_extpunct_list[__c>>3]&(1<<(__c&7));})) +#var isextupper(c) D(({register short __c=(c);(__c>='A'&&__c<='Z')||(__c>=192&&__c<=222&&__c!=215);})) +#var isfrgn(c) D(({register short __c=(c);(__c>=128&&__c<148)||(__c==181||__c>=192)&&(__c<=255&&__c!=215&&__c!=247);)}) +#var isfrgnalnum(c) D(({register short __c=(c);(__c>=128&&__c<=148&&__c!=140)||__c==181||(__c>=192&&__c<=255&&__c!=215&&__c!=247);})) +#var isfrgnlower(c) D(({register short __c=(c);__c>=224&&__c<=254&&__c!=247;})) +#var isfrgnupper(c) D(({register short __c=(c);__c>=192&&__c<=222&&__c!=215;})) +#var isgraph(c) D(({register short __c=(c);__c==11||(__c>13&&__c<256&&__c!=32);})) +#var isGreek(c) D(({register short __c=(c);(__c>=128&&__c<=148)||__c==181;})) +#var islower(c) D(({register short __c=(c);__c>='a'&&__c<='z';})) +#var isprint(c) D(({register short __c=(c);__c==11||(__c>13&&__c<256);})) +#var ispunct(c) D(({register short __c=(c);__c>=33&&__c<=127&&!((__c>='0'&&__c<='9')||(__c>='A'&&__c<='Z')||(__c>='a'&&__c<='z'));})) +#var isspace(c) D(({register short __c=(c);(__c>=9&&__c<=13)||__c==32;})) +#var isupper(c) D(({register short __c=(c);__c>='A'&&__c<='Z';})) +#var isxdigit(c) D(({register short __c=(c);(__c>='0'&&__c<='9')||(__c>='A'&&__c<='F')||(__c>='a'&&__c<='f');})) +#var toascii(c) D(((c)&0x7F)) +#var toextlower(c) D(({register short __c=(c);((__c>='A'&&__c<='Z')||(__c>=192&&__c<=222&&__c!=215))?(__c+'a'-'A'):__c;})) +#var toextupper(c) D(({register short __c=(c);((__c>='a'&&__c<='z')||(__c>=224&&__c<=254&&__c!=247))?(__c+'A'-'a'):__c;})) +#var tolower(c) D(({register short __c=(c);(__c>='A'&&__c<='Z')?(__c+'a'-'A'):__c;})) +#var toupper(c) D(({register short __c=(c);(__c>='a'&&__c<='z')?(__c+'A'-'a'):__c;})) + diff --git a/pch/src/dialogs.pchsource b/pch/src/dialogs.pchsource new file mode 100644 index 0000000..8b6cb3f --- /dev/null +++ b/pch/src/dialogs.pchsource @@ -0,0 +1,38 @@ +#var DialogAddScroll(h,x,y,w,g,f,t,p,u,m) D(DialogAdd(h,0,x,y,3,(short)w,(short)g,(short)f,(short)t,(short)p,(short)u,(short)m)) + + +#var CENTER D((-1)) +#var H_NULL D(0) +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var BT_NONE D(0) +#var BT_OK D(1) +#var BT_SAVE D(2) +#var BT_YES D(3) +#var BT_CANCEL D(4) +#var BT_NO D(5) +#var BT_GOTO D(6) + +#var DialogNew_t typedef CALLBACK short(*DialogNew_t)(short x,long y); +#var ESQ typedef unsigned char ESQ; +#var HANDLE typedef unsigned short HANDLE; +#var HSym typedef struct{HANDLE folder;unsigned short offset;}HSym; +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var Dialog D(_rom_call(short,(void*,short,short,char*,__pshort),30)) +#var DialogAdd D(_rom_call(HANDLE,(HANDLE,short,short,short,short,...),33)) +#var DialogAddPulldown(h,x,y,t,p,i) D(DialogAdd(h,2,x,y,14,(const char*)(t),(short)(p),(short)(i))) +#var DialogAddRequest(h,x,y,t,o,m,w) D(DialogAdd(h,0,x,y,2,(const char*)(t),(short)(o),(short)(m),(short)(w))) +#var DialogAddText(h,x,y,t) D(DialogAdd(h,0,x,y,7,(const char*)(t))) +#var DialogAddTitle(h,t,l,r) D(DialogAdd(h,0,0,0,8,(const char*)(t),(short)(l),(short)(r))) +#var DialogDo D(_rom_call(short,(HANDLE,short,short,char*,__pshort),32)) +#var DialogNew D(_rom_call(HANDLE,(short,short,DialogNew_t),34)) +#var DialogNewSimple(w,h) D(DialogNew(w,h,NoCallBack)) +#var DlgMessage D(_rom_call(short,(const char*,const char*,short,short),1B4)) +#var NoCallBack short NoCallBack(short,long)__ATTR_TIOS_CALLBACK__; +#var VarNew D(_rom_call(HSym,(const ESQ*,...),28E)) +#var VarOpen D(_rom_call(HSym,(const ESQ*,...),28C)) +#var VarSaveAs D(_rom_call(HSym,(const ESQ*,const char*,...),28D)) diff --git a/pch/src/dll.pchsource b/pch/src/dll.pchsource new file mode 100644 index 0000000..dfe5f17 --- /dev/null +++ b/pch/src/dll.pchsource @@ -0,0 +1,26 @@ +#var __DLL_SIGNATURE D(0x444C4C20) +#var __DLL_interface_struct typedef struct{unsigned long Signature,ID;unsigned short major,minor;void*jump_table[];}__DLL_interface_struct; + +#var DLL_OK D(0) +#var DLL_NOTINGHOSTSPACE D(1) +#var DLL_NOTFOUND D(2) +#var DLL_LOCKFAILED D(3) +#var DLL_OUTOFMEM D(4) +#var DLL_ALREADYLOADED D(5) +#var DLL_WRONGVERSION D(6) + +#sys __DLL_interface_ptr extern __DLL_interface_struct*__DLL_interface_ptr; +#sys __DLL_body_ptr extern void*__DLL_body_ptr; +#var _DLL_call(type,args,index) D((*(type(*)args)_DLL_entry(index))) +#var _DLL_call_attr(type,args,attr,index) D((*(type(*attr)args)_DLL_entry(index))) +#var _DLL_entry(index) D((__DLL_interface_ptr->jump_table[index])) +#var _DLL_glbvar(type,index) D((*(_DLL_reference(type,index)))) +#var _DLL_reference(type,index) D(((type*const)_DLL_entry(index))) +#var LoadDLL short LoadDLL(const char*,long,short,short)__ATTR_LIB_C__; +#var LoadDLLThrow void LoadDLLThrow(const char*,long,short,short)__ATTR_LIB_C__; +#var UnloadDLL void UnloadDLL(void)__ATTR_LIB_C__; +#var DLL_EXPORTS D(,{) +#var DLL_ID D(__DLL_interface_struct __DLL_interface={__DLL_SIGNATURE,) +#var DLL_IMPLEMENTATION D(,(void*)-1L}};) +#var DLL_INTERFACE #define _nostub_dll +#var DLL_VERSION D(,) diff --git a/pch/src/error-le.pchsource b/pch/src/error-le.pchsource new file mode 100644 index 0000000..c01d5ee --- /dev/null +++ b/pch/src/error-le.pchsource @@ -0,0 +1,37 @@ + +#var FALSE D(0) +#var TRUE D(1) + +#var ERROR_FRAME typedef struct ErrorFrameStruct{unsigned long A2,A3,A4,A5,A6,A7;unsigned long D3,D4,D5,D6,D7;unsigned long NG_control;char*RetIndex;unsigned long PC;struct ErrorFrameStruct*Link;}ERROR_FRAME[1]; +#var ER_OK D(0) +#var ER_OKAY D(0) +#var ER_EXIT D(1) +#var ER_STOP D(2) +#var ER_OFF D(3) +#var ER_PRGM_STOP D(4) +#var ER_NO_MSG D(9) +#var ER_ARGUMENT D(40) +#var ER_BREAK D(180) +#var ER_MEMORY D(670) +#var ER_MEMORY_EXHAUSTION D(670) +#var ER_ESTACK_OVERFLOW D(670) +#var ER_STACK_VIO D(673) +#var ER_SYNTAX D(910) +#var ER_TOO_FEW_ARGS D(930) +#var ER_TOO_MANY_ARGS D(940) + +#var ER_catch D(_rom_call(short,(void*),154)) +#var ER_success D(_rom_call(void,(void),155)) +#var ER_throw(err_no) D(asm volatile{dc.w 0xA000+(err_no)}) +#var ER_throwVar D((*({typedef void(*__temp__type__)(short)__ATTR_TIOS_NORETURN__;(__temp__type__)(_rom_call_addr(153));}))) +#var ERD_dialog D(_rom_call(short,(short,short),151)) +#var ERD_process D(_rom_call(void,(short),152)) +#var ENDFINAL D(}if(errCode)PASS;}) +#var ENDTRY D(;_ONERR_=0;}}) +#var FINALLY D(ER_success();}{) +#var ONERR D(ER_success();}else{register short _ONERR_=1;) +#var PASS D((ER_throwVar(errCode))) +#var TRY D({ERROR_FRAME __errFrame;unsigned short errCode;errCode=ER_catch(__errFrame);if(!errCode){) +#var find_error_message D(_rom_call(const char*,(short),2C1)) + +#var ER_THROW(n) D(ER_throw(n)) diff --git a/pch/src/error.pchsource b/pch/src/error.pchsource new file mode 100644 index 0000000..b704758 --- /dev/null +++ b/pch/src/error.pchsource @@ -0,0 +1,209 @@ + + +#var FALSE D(0) +#var TRUE D(1) + +#var ERROR_FRAME typedef struct ErrorFrameStruct{unsigned long A2,A3,A4,A5,A6,A7;unsigned long D3,D4,D5,D6,D7;unsigned long NG_control;char*RetIndex;unsigned long PC;struct ErrorFrameStruct*Link;}ERROR_FRAME[1]; +#var ER_OK D(0) +#var ER_OKAY D(0) +#var ER_EXIT D(1) +#var ER_STOP D(2) +#var ER_OFF D(3) +#var ER_PRGM_STOP D(4) +#var ER_NO_MSG D(9) +#var ER_FUNC_DID_NOT_RETURN_VALUE D(10) +#var ER_TEST_NOT_TRUE_OR_FALSE D(20) +#var ER_ARG_CANNOT_BE_FOLDER D(30) +#var ER_ARGUMENT D(40) +#var ER_ARG_MISMATCH D(50) +#var ER_EXPECTED_BOOL_OR_AGG D(60) +#var ER_ARG_MUST_BE_DECIMAL D(70) +#var ER_ARG_MUST_BE_LABEL D(80) +#var ER_ARGUMENT_MUST_BE_LIST D(90) +#var ER_ARG_MUST_BE_MATRIX D(100) +#var ER_ARG_MUST_BE_PIC D(110) +#var ER_ARG_MUST_BE_PIC_OR_STR D(120) +#var ER_ARG_MUST_BE_STRING D(130) +#var ER_EXPECTED_VAR D(140) +#var ER_ARG_MUST_BE_EMPTY_FOLDER D(150) +#var ER_EXPECTED_ALGEBRAIC D(160) +#var ER_ASAP_TOO_LONG D(161) +#var ER_ATTRIBUTE_NOT_FOUND D(163) +#var ER_BATT_LOW D(165) +#var ER_BOUND D(170) +#var ER_BREAK D(180) +#var ER_CHECKSUM D(185) +#var ER_CIRCULAR_DEFINITION D(190) +#var ER_INVALID_SUCH_THAT D(200) +#var ER_DATATYPE D(210) +#var ER_DEPENDENT_LIMIT D(220) +#var ER_DIFF_EQ_SETUP D(225) +#var ER_DIMENSION D(230) +#var ER_NOT_ENOUGH_ELEMENTS D(230) +#var ER_NON_CONFORMING_LISTS D(240) +#var ER_DIVBY0 D(250) +#var ER_DOMAIN D(260) +#var ER_DUPLICATE_VAR_NAME D(270) +#var ER_ELSEIF_WITHOUT_IF D(280) +#var ER_ELSE_WITHOUT_IF D(280) +#var ER_ENDTRY_WITHOUT_ELSE D(290) +#var ER_EXCESSIVE_ITERATION D(295) +#var ER_EXPECTED_2OR3_ELEMENTS D(300) +#var ER_EXPIRED D(305) +#var ER_APP_EXT_NOT_FOUND D(307) +#var ER_APP_NOT_FOUND D(308) +#var ER_INVALID_NSOLVE_ARG1 D(310) +#var ER_INVALID_SOLVE_ARG1 D(320) +#var ER_FOLDER D(330) +#var ER_FUNCS_IN_DIFF_EQ D(335) +#var ER_INCONSISTENT_UNITS D(345) +#var ER_INVALID_SUBSCRIPT D(350) +#var ER_INVALID_INDIR_STRING D(360) +#var ER_INDIR_STRING_NOT_VARNAME D(360) +#var ER_INDIR_STRING_NOT_FUNNAME D(360) +#var ER_INVALID_ANS D(380) +#var ER_ILLEGAL_ASSIGNMENT D(390) +#var ER_ILLEGAL_ASSIGNMENT_VALUE D(400) +#var ER_INVALID_AXES D(405) +#var ER_ILLEGAL_COMMAND D(410) +#var ER_INVALID_FOLDER_NAME D(420) +#var ER_GRAPH_MODE D(430) +#var ER_INVALID_GUESS D(435) +#var ER_INVALID_IMPLIED_MULT D(440) +#var ER_ILLEGAL_IN_FUNC D(450) +#var ER_ILLEGAL_IN_CUSTOM D(460) +#var ER_ILLEGAL_IN_DIALOG D(470) +#var ER_ILLEGAL_IN_TOOLBAR D(480) +#var ER_CANNOT_EXIT_FROM_TRY D(490) +#var ER_CANNOT_CYCLE_FROM_TRY D(490) +#var ER_CANNOT_GOTO_FROM_TRY D(490) +#var ER_CANNOT_GOTO_INTO_TRY D(490) +#var ER_INVALID_LABEL D(500) +#var ER_INVALID_LIST_OR_MATRIX D(510) +#var ER_INVAL_OUTSIDE_TB_CM D(520) +#var ER_INVAL_OUTSIDE_DG_TB_CM D(530) +#var ER_INVALID_OUTSIDE_DIALOG D(540) +#var ER_MUST_BE_IN_PRGM_OR_FUNC D(550) +#var ER_CYCLE_NOT_IN_LOOP D(560) +#var ER_EXIT_NOT_IN_LOOP D(560) +#var ER_INVALID_PATHNAME D(570) +#var ER_INVALID_POLAR_COMPLEX D(575) +#var ER_ILLEGAL_PRGM_REF D(580) +#var ER_INVALID_SYNTAX_BLOCK D(590) +#var ER_INVALID_TABLE D(600) + +#var ER_INVALID_USE_OF_UNITS D(605) +#var ER_INVALID_LOCAL_DECLARATION D(610) +#var ER_EXPECTED_VAR_OR_FUNC D(620) +#var ER_INVALID_VAR_REF D(630) +#var ER_INVALID_VECTOR_SYNTAX D(640) +#var ER_LINK_IO D(650) +#var ER_MAT_NOT_DIAGONALIZABLE D(665) +#var ER_MEMORY D(670) +#var ER_MEMORY_EXHAUSTION D(670) +#var ER_ESTACK_OVERFLOW D(670) +#var ER_STACK_VIO D(673) +#var ER_EXPECTED_LPAR D(680) +#var ER_EXPECTED_RPAR D(690) +#var ER_EXPECTED_DOUBLE_QUOTE D(700) +#var ER_EXPECTED_RIGHT_BRACKET D(710) +#var ER_EXPECTED_RIGHT_BRACE D(720) +#var ER_INVALID_BLOCK_STRUCTURE D(730) +#var ER_MISSING_THEN D(740) +#var ER_NOT_FUNC_OR_PRGM D(750) +#var ER_NO_FUNCS_SEL D(765) +#var ER_NO_SOLUTION D(780) +#var ER_NON_ALGEBRAIC_VARIABLE D(790) +#var ER_UNREAL_RESULT D(800) +#var ER_EXPECTED_REAL D(800) +#var ER_MEMORY_DML D(810) +#var ER_RATIONAL_NUMERIC_OVERFLOW D(830) +#var ER_OVERFLOW D(830) +#var ER_STAT_PLOT D(840) +#var ER_PRGM_NOT_FOUND D(850) +#var ER_RECURSION_TOO_DEEP D(860) +#var ER_RESERVED D(870) +#var ER_SYS_FUNC D(870) +#var ER_ROM_ROUTINE_NOT_AVAILABLE D(875) +#var ER_SEQUENCE_SETUP D(880) +#var ER_SIGNATURE_ERR D(885) +#var ER_SINGULARMAT D(890) +#var ER_SLOPE_FIELD_FUNCS D(895) +#var ER_WEIGHTS_SUM_NOT_POS D(900) +#var ER_LISTS_CONTAIN_NEG D(900) +#var ER_LISTS_NOT2DISCREET D(900) +#var ER_EMPTY_GROUP_NOT_VALID D(900) +#var ER_SYNTAX D(910) +#var ER_UNEXPECTED_CHARACTER D(910) +#var ER_EXPECTED_EQUAL D(910) +#var ER_EXPECTED_FACTOR D(910) +#var ER_TOO_FEW_ARGS D(930) +#var ER_TOO_MANY_ARGS D(940) +#var ER_TOO_MANY_SUBSCRIPTS D(950) +#var ER_TOO_MANY_UNDEFINED D(955) +#var ER_UNDEFINED_VAR D(960) +#var ER_UNLICENSED D(965) +#var ER_GRAPH_FUNC_IN_USE D(970) +#var ER_PROG_OR_FUNC_IN_USE D(970) +#var ER_VAR_IN_USE D(970) +#var ER_LOCKED D(980) +#var ER_PROTECTED D(980) +#var ER_NAME_TOO_LONG D(990) +#var ER_RANGE D(1000) +#var ER_ZOOM D(1010) +#var ER_ILLEGAL_TAG D(1020) +#var ER_UNKNOWN_TAG D(1020) +#var ER_DIVISION_BUG D(1020) +#var ER_MEM_VIO D(1030) +#var ER_FP_TEST_FAIL D(4094) +#var EXPECTED_BOOL_OR_AGG_ERROR D(60) +#var EXPECTED_VAR_ERROR D(140) +#var EXPECTED_ALGEBRAIC_ERROR D(160) +#var INVALID_SUCH_THAT_ERROR D(200) +#var NON_CONFORMING_LISTS_ERROR D(240) +#var EXPECTED_2OR3_ELEMENTS_ERROR D(300) +#var INVALID_NSOLVE_ARG1_ERROR D(310) +#var INVALID_SOLVE_ARG1_ERROR D(320) +#var INVALID_PATHNAME_ERROR D(570) +#var EXPECTED_VAR_OR_FUNC_ERROR D(620) +#var MEMORY_EXHAUSTION_ERROR D(670) +#var ESTACK_OVERFLOW_ERROR D(670) +#var EXPECTED_LPAR_ERROR D(680) +#var EXPECTED_RPAR_ERROR D(690) +#var EXPECTED_DOUBLE_QUOTE_ERROR D(700) +#var EXPECTED_RIGHT_BRACKET_ERROR D(710) +#var EXPECTED_RIGHT_BRACE_ERROR D(720) +#var UNREAL_RESULT_ERROR D(800) +#var EXPECTED_REAL_ERROR D(800) +#var RATIONAL_NUMERIC_OVERFLOW_ERROR D(830) + +#var RECURSION_TOO_DEEP_ERROR D(860) +#var SYNTAX_ERROR D(910) +#var UNEXPECTED_CHARACTER_ERROR D(910) +#var EXPECTED_EQUAL_ERROR D(910) +#var EXPECTED_FACTOR_ERROR D(910) +#var TOO_FEW_ARGS_ERROR D(930) +#var TOO_MANY_ARGS_ERROR D(940) +#var TOO_MANY_SUBSCRIPTS_ERROR D(950) +#var TOO_MANY_UNDEFINED_ERROR D(955) +#var GRAPH_FUNC_IN_USE_ERROR D(970) +#var NAME_TOO_LONG_ERROR D(990) +#var ILLEGAL_TAG_ERROR D(1020) +#var UNKNOWN_TAG_ERROR D(1020) +#var DIVISION_BUG_ERROR D(1020) + +#var ER_catch D(_rom_call(short,(void*),154)) +#var ER_success D(_rom_call(void,(void),155)) +#var ER_throw(err_no) D(asm volatile{dc.w 0xA000+(err_no)}) +#var ER_throwVar D((*({typedef void(*__temp__type__)(short)__ATTR_TIOS_NORETURN__;(__temp__type__)(_rom_call_addr(153));}))) +#var ERD_dialog D(_rom_call(short,(short,short),151)) +#var ERD_process D(_rom_call(void,(short),152)) +#var ENDFINAL D(}if(errCode)PASS;}) +#var ENDTRY D(;_ONERR_=0;}}) +#var FINALLY D(ER_success();}{) +#var ONERR D(ER_success();}else{register short _ONERR_=1;) +#var PASS D((ER_throwVar(errCode))) +#var TRY D({ERROR_FRAME __errFrame;unsigned short errCode;errCode=ER_catch(__errFrame);if(!errCode){) +#var find_error_message D(_rom_call(const char*,(short),2C1)) + +#var ER_THROW(n) D(ER_throw(n)) diff --git a/pch/src/estack.pchsource b/pch/src/estack.pchsource new file mode 100644 index 0000000..08b93a4 --- /dev/null +++ b/pch/src/estack.pchsource @@ -0,0 +1,704 @@ +#var _push_zstr(s) D(({register const char*__p=(s);register long __l=_rom_call(long,(const char*),27E)(__p);char __s[__l+2];__s[0]=0;push_expr_quantum(_rom_call(char*,(char*,const char*),26C)(__s+1,__p)+__l,STR_TAG);})) +#var _push_zstr_const(s) D((push_expr_quantum(SYMSTR(s),STR_TAG))) + + +#var H_NULL D(0) +#var NULL_INDEX D(((CESI)0)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var CESI_Callback_t typedef CALLBACK unsigned short(*CESI_Callback_t)(CESI); +#var ESI typedef ESQ*ESI; +#var ESI_Callback_Int_t typedef CALLBACK unsigned short(*ESI_Callback_Int_t)(ESI,unsigned short); +#var ESI_Callback_t typedef CALLBACK void(*ESI_Callback_t)(ESI); +#var EStackIndex D(ESI) +#var INDIR_TAG D(1) +#var GETKEY_TAG D(2) +#var GETFOLD_TAG D(3) +#var SWITCH_TAG D(4) +#var UNITCONV_TAG D(5) +#var ORD_TAG D(6) +#var EXPR_TAG D(7) +#var CHAR_TAG D(8) +#var STRING_TAG D(9) +#var GETTYPE_TAG D(10) +#var GETMODE_TAG D(11) +#var SETFOLD_TAG D(12) +#var PTTEST_TAG D(13) +#var PXLTEST_TAG D(14) +#var SETGRAPH_TAG D(15) +#var SETTABLE_TAG D(16) +#var SETMODE_TAG D(17) +#var FORMAT_TAG D(18) +#var INSTRING_TAG D(19) +#var APPEND_TAG D(20) +#var DD_TAG D(21) +#var EXPR2DMS_TAG D(22) +#var VEC2RECT_TAG D(23) +#var VEC2POLAR_TAG D(24) +#var VEC2CYLIND_TAG D(25) +#var VEC2SPHERE_TAG D(26) +#var PARENTH_START_TAG D(27) +#var PARENTH_END_TAG D(28) +#var MAT_START_TAG D(29) +#var MAT_END_TAG D(30) +#var LIST_START_TAG D(31) +#var LIST_END_TAG D(32) +#var COMMA_TAG D(33) +#var SEMICOLON_TAG D(34) +#var COMPLEX_ANGLE_TAG D(35) +#var SINGLE_QUOTE_TAG D(36) +#var QUOTE_TAG D(37) +#var POLCPLX_TAG D(38) +#var TMPCNV_TAG D(39) +#var DELTA_TMPCNV_TAG D(40) +#var GETUNITS_TAG D(41) +#var SETUNITS_TAG D(42) +#var BIN_TAG D(43) +#var HEX_TAG D(44) +#var INT2BIN_TAG D(45) +#var INT2DEC_TAG D(46) +#var INT2HEX_TAG D(47) +#var DET_TOL_TAG D(48) +#var REF_TOL_TAG D(49) +#var RREF_TOL_TAG D(50) +#var SIMULT_TOL_TAG D(51) +#var GETCONFG_TAG D(52) +#var V_AUGMENT_TAG D(53) +#var VARIANCE_TWOARG_TAG D(58) + +#var HANDLE typedef unsigned short HANDLE; +#var CLRDRAW_ITAG D(1) +#var CLRGRAPH_ITAG D(2) +#var CLRHOME_ITAG D(3) +#var CLRIO_ITAG D(4) +#var CLRTABLE_ITAG D(5) +#var CUSTOM_ITAG D(6) +#var CYCLE_ITAG D(7) +#var DIALOG_ITAG D(8) +#var DISPG_ITAG D(9) +#var DISPTBL_ITAG D(10) +#var ELSE_ITAG D(11) +#var ENDCUSTM_ITAG D(12) +#var ENDDLOG_ITAG D(13) +#var ENDFOR_ITAG D(14) +#var ENDFUNC_ITAG D(15) +#var ENDIF_ITAG D(16) +#var ENDLOOP_ITAG D(17) +#var ENDPRGM_ITAG D(18) +#var ENDTBAR_ITAG D(19) +#var ENDTRY_ITAG D(20) +#var ENDWHILE_ITAG D(21) +#var EXIT_ITAG D(22) +#var FUNC_ITAG D(23) +#var LOOP_ITAG D(24) +#var PRGM_ITAG D(25) +#var SHOWSTAT_ITAG D(26) +#var STOP_ITAG D(27) +#var THEN_ITAG D(28) +#var TOOLBAR_ITAG D(29) +#var TRACE_ITAG D(30) +#var TRY_ITAG D(31) +#var ZOOMBOX_ITAG D(32) +#var ZOOMDATA_ITAG D(33) +#var ZOOMDEC_ITAG D(34) +#var ZOOMFIT_ITAG D(35) +#var ZOOMIN_ITAG D(36) +#var ZOOMINT_ITAG D(37) +#var ZOOMOUT_ITAG D(38) +#var ZOOMPREV_ITAG D(39) +#var ZOOMRCL_ITAG D(40) +#var ZOOMSQR_ITAG D(41) +#var ZOOMSTD_ITAG D(42) +#var ZOOMSTO_ITAG D(43) +#var ZOOMTRIG_ITAG D(44) +#var DRAWFUNC_ITAG D(45) +#var DRAWINV_ITAG D(46) +#var GOTO_ITAG D(47) +#var LBL_ITAG D(48) +#var GET_ITAG D(49) +#var SEND_ITAG D(50) +#var GETCALC_ITAG D(51) +#var SENDCALC_ITAG D(52) +#var NEWFOLD_ITAG D(53) +#var PRINTOBJ_ITAG D(54) +#var RCLGDB_ITAG D(55) +#var STOGDB_ITAG D(56) +#var ELSEIF_ITAG D(57) +#var IF_ITAG D(58) +#var IFTHEN_ITAG D(59) +#var RANDSEED_ITAG D(60) +#var WHILE_ITAG D(61) +#var LINETAN_ITAG D(62) +#var COPYVAR_ITAG D(63) +#var RENAME_ITAG D(64) +#var STYLE_ITAG D(65) +#var FILL_ITAG D(66) +#var REQUEST_ITAG D(67) +#var POPUP_ITAG D(68) +#var PTCHG_ITAG D(69) +#var PTOFF_ITAG D(70) +#var PTON_ITAG D(71) +#var PXLCHG_ITAG D(72) +#var PXLOFF_ITAG D(73) +#var PXLON_ITAG D(74) +#var MOVEVAR_ITAG D(75) +#var DROPDOWN_ITAG D(76) +#var OUTPUT_ITAG D(77) +#var PTTEXT_ITAG D(78) +#var PXLTEXT_ITAG D(79) +#var DRAWSLP_ITAG D(80) +#var PAUSE_ITAG D(81) +#var RETURN_ITAG D(82) +#var INPUT_ITAG D(83) +#var PLOTSOFF_ITAG D(84) +#var PLOTSON_ITAG D(85) +#var TITLE_ITAG D(86) +#var ITEM_ITAG D(87) +#var INPUTSTR_ITAG D(88) +#var LINEHORZ_ITAG D(89) +#var LINEVERT_ITAG D(90) +#var PXLHORZ_ITAG D(91) +#var PXLVERT_ITAG D(92) +#var ANDPIC_ITAG D(93) +#var RCLPIC_ITAG D(94) +#var RPLCPIC_ITAG D(95) +#var XORPIC_ITAG D(96) +#var DRAWPOL_ITAG D(97) +#var TEXT_ITAG D(98) +#var ONEVAR_ITAG D(99) +#var STOPIC_ITAG D(100) +#var GRAPH_ITAG D(101) +#var TABLE_ITAG D(102) +#var NEWPIC_ITAG D(103) +#var DRAWPARM_ITAG D(104) +#var CYCLEPIC_ITAG D(105) +#var CUBICREG_ITAG D(106) +#var EXPREG_ITAG D(107) +#var LINREG_ITAG D(108) +#var LNREG_ITAG D(109) +#var MEDMED_ITAG D(110) +#var POWERREG_ITAG D(111) +#var QUADREG_ITAG D(112) +#var QUARTREG_ITAG D(113) +#var TWOVAR_ITAG D(114) +#var SHADE_ITAG D(115) +#var FOR_ITAG D(116) +#var CIRCLE_ITAG D(117) +#var PXLCRCL_ITAG D(118) +#var NEWPLOT_ITAG D(119) +#var LINE_ITAG D(120) + +#var PXLLINE_ITAG D(121) +#var DISP_ITAG D(122) +#var FNOFF_ITAG D(123) +#var FNON_ITAG D(124) +#var LOCAL_ITAG D(125) +#var DELFOLD_ITAG D(126) +#var DELVAR_ITAG D(127) +#var LOCK_ITAG D(128) +#var PROMPT_ITAG D(129) +#var SORTA_ITAG D(130) +#var SORTD_ITAG D(131) +#var UNLOCK_ITAG D(132) +#var NEWDATA_ITAG D(133) +#var DEFINE_ITAG D(134) +#var ELSE_TRY_ITAG D(135) +#var CLRERR_ITAG D(136) +#var PASSERR_ITAG D(137) +#var DISPHOME_ITAG D(138) +#var EXEC_ITAG D(139) +#var ARCHIVE_ITAG D(140) +#var UNARCHIV_ITAG D(141) +#var LU_ITAG D(142) +#var QR_ITAG D(143) +#var BLDDATA_ITAG D(144) +#var DRWCTOUR_ITAG D(145) +#var NEWPROB_ITAG D(146) +#var SINREG_ITAG D(147) +#var LOGISTIC_ITAG D(148) +#var CUSTMON_ITAG D(149) +#var CUSTMOFF_ITAG D(150) +#var SENDCHAT_ITAG D(151) + +#var MULTI_EXPR typedef struct{unsigned short Size;ESQ Expr[];}MULTI_EXPR; +#var Quantum D(ESQ) +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var SYM_STR typedef CESI SYM_STR; +#var X_BAR_TAG D(1) +#var Y_BAR_TAG D(2) +#var SIGMA_X_TAG D(3) +#var SIGMA_X2_TAG D(4) +#var SIGMA_Y_TAG D(5) +#var SIGMA_Y2_TAG D(6) +#var SIGMA_XY_TAG D(7) +#var SX_TAG D(8) +#var SY_TAG D(9) +#var SMLSIGMA_X_TAG D(10) +#var SMLSIGMA_Y_TAG D(11) +#var NSTAT_TAG D(12) +#var MINX_TAG D(13) +#var MINY_TAG D(14) +#var Q1_TAG D(15) +#var MEDSTAT_TAG D(16) +#var Q3_TAG D(17) +#var MAXX_TAG D(18) +#var MAXY_TAG D(19) +#var CORR_TAG D(20) +#var R2_TAG D(21) +#var MEDX1_TAG D(22) +#var MEDX2_TAG D(23) +#var MEDX3_TAG D(24) +#var MEDY1_TAG D(25) +#var MEDY2_TAG D(26) +#var MEDY3_TAG D(27) +#var XC_TAG D(28) +#var YC_TAG D(29) +#var ZC_TAG D(30) +#var TC_TAG D(31) +#var RC_TAG D(32) +#var THETA_C_TAG D(33) +#var NC_TAG D(34) +#var XFACT_TAG D(35) +#var YFACT_TAG D(36) +#var ZFACT_TAG D(37) +#var XMIN_TAG D(38) +#var XMAX_TAG D(39) +#var XSCL_TAG D(40) +#var YMIN_TAG D(41) +#var YMAX_TAG D(42) +#var YSCL_TAG D(43) +#var DELTA_X_TAG D(44) +#var DELTA_Y_TAG D(45) +#var XRES_TAG D(46) +#var XGRID_TAG D(47) +#var YGRID_TAG D(48) +#var ZMIN_TAG D(49) +#var ZMAX_TAG D(50) +#var ZSCL_TAG D(51) +#var EYE_THETA_TAG D(52) +#var EYE_PHI_TAG D(53) +#var THETA_MIN_TAG D(54) +#var THETA_MAX_TAG D(55) +#var THETA_STEP_TAG D(56) +#var TMIN_TAG D(57) +#var TMAX_TAG D(58) +#var TSTEP_TAG D(59) +#var NMIN_TAG D(60) +#var NMAX_TAG D(61) +#var PLOTSTRT_TAG D(62) +#var PLOTSTEP_TAG D(63) +#var ZXMIN_TAG D(64) +#var ZXMAX_TAG D(65) +#var ZXSCL_TAG D(66) +#var ZYMIN_TAG D(67) +#var ZYMAX_TAG D(68) +#var ZYSCL_TAG D(69) +#var ZXRES_TAG D(70) +#var Z_THETA_MIN_TAG D(71) +#var Z_THETA_MAX_TAG D(72) +#var Z_THETA_STEP_TAG D(73) +#var ZTMIN_TAG D(74) +#var ZTMAX_TAG D(75) +#var ZTSTEP_TAG D(76) +#var ZXGRID_TAG D(77) +#var ZYGRID_TAG D(78) +#var ZZMIN_TAG D(79) +#var ZZMAX_TAG D(80) +#var ZZSCL_TAG D(81) +#var ZEYE_THETA_TAG D(82) +#var ZEYE_PHI_TAG D(83) +#var ZNMIN_TAG D(84) +#var ZNMAX_TAG D(85) +#var ZPLTSTEP_TAG D(86) +#var ZPLTSTRT_TAG D(87) +#var SEED1_TAG D(88) +#var SEED2_TAG D(89) +#var OK_TAG D(90) +#var ERRORNUM_TAG D(91) +#var SYSMATH_TAG D(92) +#var SYSDATA_TAG D(93) +#var REGEQ_TAG D(94) +#var REGCOEF_TAG D(95) +#var TBLINPUT_TAG D(96) +#var TBLSTART_TAG D(97) +#var DELTA_TBL_TAG D(98) +#var FLDPIC_TAG D(99) +#var EYE_PSI_TAG D(100) +#var TPLOT_TAG D(101) +#var DIFTOL_TAG D(102) +#var ZEYE_PSI_TAG D(103) +#var T0_TAG D(104) +#var DTIME_TAG D(105) +#var NCURVES_TAG D(106) +#var FLDRES_TAG D(107) +#var ESTEP_TAG D(108) +#var ZT0DE_TAG D(109) +#var ZTMAXDE_TAG D(110) +#var ZTSTEPDE_TAG D(111) +#var ZTPLOTDE_TAG D(112) +#var NCONTOUR_TAG D(113) + +#var VAR_NAME_TAG D(0) +#var _VAR_Q_TAG D(1) +#var VAR_R_TAG D(2) +#var VAR_S_TAG D(3) +#var VAR_T_TAG D(4) +#var VAR_U_TAG D(5) +#var VAR_V_TAG D(6) +#var VAR_W_TAG D(7) +#var VAR_X_TAG D(8) +#var VAR_Y_TAG D(9) +#var VAR_Z_TAG D(10) +#var VAR_A_TAG D(11) +#var VAR_B_TAG D(12) +#var VAR_C_TAG D(13) +#var VAR_D_TAG D(14) +#var VAR_E_TAG D(15) +#var VAR_F_TAG D(16) +#var VAR_G_TAG D(17) +#var VAR_H_TAG D(18) +#var VAR_I_TAG D(19) +#var VAR_J_TAG D(20) +#var VAR_K_TAG D(21) +#var VAR_L_TAG D(22) +#var VAR_M_TAG D(23) +#var VAR_N_TAG D(24) +#var VAR_O_TAG D(25) +#var VAR_P_TAG D(26) +#var VAR_Q_TAG D(27) +#var EXT_SYSTEM_TAG D(28) +#var ARB_REAL_TAG D(29) +#var ARB_INT_TAG D(30) +#var POSINT_TAG D(31) +#var NEGINT_TAG D(32) +#var POSFRAC_TAG D(33) +#var NEGFRAC_TAG D(34) +#var FLOAT_TAG D(35) +#var BCD_TAG D(35) +#var PI_TAG D(36) +#var EXP_TAG D(37) +#var IM_TAG D(38) +#var NEGINFINITY_TAG D(39) +#var INFINITY_TAG D(40) +#var PN_INFINITY_TAG D(41) +#var UNDEF_TAG D(42) +#var FALSE_TAG D(43) +#var TRUE_TAG D(44) +#var STR_TAG D(45) +#var NOTHING_TAG D(46) +#var ACOSH_TAG D(47) +#var ASINH_TAG D(48) +#var ATANH_TAG D(49) +#var COSH_TAG D(53) +#var SINH_TAG D(54) +#var TANH_TAG D(55) +#var ACOS_TAG D(59) +#var ASIN_TAG D(60) +#var ATAN_TAG D(61) +#var RACOS_TAG D(65) +#var RASIN_TAG D(66) +#var RATAN_TAG D(67) +#var COS_TAG D(68) +#var SIN_TAG D(69) +#var TAN_TAG D(70) +#var ITAN_TAG D(74) +#var ABS_TAG D(75) +#var ANGLE_TAG D(76) +#var CEILING_TAG D(77) +#var FLOOR_TAG D(78) +#var INT_TAG D(79) +#var SIGN_TAG D(80) +#var SQRT_TAG D(81) +#var EXPF_TAG D(82) +#var LN_TAG D(83) +#var LOG_TAG D(84) +#var FPART_TAG D(85) +#var IPART_TAG D(86) +#var CONJ_TAG D(87) +#var IMAG_TAG D(88) +#var REAL_TAG D(89) +#var APPROX_TAG D(90) +#var TEXPAND_TAG D(91) +#var TCOLLECT_TAG D(92) +#var GETDENOM_TAG D(93) +#var GETNUM_TAG D(94) +#var CUMSUM_TAG D(96) +#var DET_TAG D(97) +#var COLNORM_TAG D(98) +#var ROWNORM_TAG D(99) +#var NORM_TAG D(100) +#var MEAN_TAG D(101) +#var MEDIAN_TAG D(102) +#var PRODUCT_TAG D(103) +#var STDDEV_TAG D(104) +#var SUM_TAG D(105) +#var VARIANCE_TAG D(106) +#var UNITV_TAG D(107) +#var DIM_TAG D(108) +#var MAT2LIST_TAG D(109) +#var NEWLIST_TAG D(110) +#var RREF_TAG D(111) +#var REF_TAG D(112) +#var IDENTITY_TAG D(113) +#var DIAG_TAG D(114) +#var COLDIM_TAG D(115) +#var ROWDIM_TAG D(116) +#var TRANSPOSE_TAG D(117) +#var FACTORIAL_TAG D(118) +#var PERCENT_TAG D(119) +#var RADIANS_TAG D(120) +#var NOT_TAG D(121) +#var MINUS_TAG D(122) +#var VEC_POLAR_TAG D(123) +#var VEC_CYLIND_TAG D(124) +#var VEC_SPHERE_TAG D(125) +#var START_TAG D(126) +#var ISTORE_TAG D(127) +#var STORE_TAG D(128) +#var WITH_TAG D(129) +#var XOR_TAG D(130) +#var OR_TAG D(131) +#var AND_TAG D(132) +#var LT_TAG D(133) +#var LE_TAG D(134) +#var EQ_TAG D(135) +#var GE_TAG D(136) +#var GT_TAG D(137) +#var NE_TAG D(138) +#var ADD_TAG D(139) +#var ADDELT_TAG D(140) +#var SUB_TAG D(141) +#var SUBELT_TAG D(142) +#var MUL_TAG D(143) +#var MULELT_TAG D(144) +#var DIV_TAG D(145) + +#var DIVELT_TAG D(146) +#var POW_TAG D(147) +#var POWELT_TAG D(148) +#var SINCOS_TAG D(149) +#var SOLVE_TAG D(150) +#var CSOLVE_TAG D(151) +#var NSOLVE_TAG D(152) +#var ZEROS_TAG D(153) +#var CZEROS_TAG D(154) +#var FMIN_TAG D(155) +#var FMAX_TAG D(156) +#var COMPLEX_TAG D(157) +#var POLYEVAL_TAG D(158) +#var RANDPOLY_TAG D(159) +#var CROSSP_TAG D(160) +#var DOTP_TAG D(161) +#var GCD_TAG D(162) +#var LCM_TAG D(163) +#var MOD_TAG D(164) +#var INTDIV_TAG D(165) +#var REMAIN_TAG D(166) +#var NCR_TAG D(167) +#var NPR_TAG D(168) +#var P2RX_TAG D(169) +#var P2RY_TAG D(170) +#var P2PTHETA_TAG D(171) +#var P2PR_TAG D(172) +#var AUGMENT_TAG D(173) +#var NEWMAT_TAG D(174) +#var RANDMAT_TAG D(175) +#var SIMULT_TAG D(176) +#var PART_TAG D(177) +#var EXP2LIST_TAG D(178) +#var RANDNORM_TAG D(179) +#var MROW_TAG D(180) +#var ROWADD_TAG D(181) +#var ROWSWAP_TAG D(182) +#var ARCLEN_TAG D(183) +#var NINT_TAG D(184) +#var PI_PRODUCT_TAG D(185) +#var SIGMA_SUM_TAG D(186) +#var MROWADD_TAG D(187) +#var ANS_TAG D(188) +#var ENTRY_TAG D(189) +#var EXACT_TAG D(190) +#var LOGB_TAG D(191) +#var COMDENOM_TAG D(192) +#var EXPAND_TAG D(193) +#var FACTOR_TAG D(194) +#var CFACTOR_TAG D(195) +#var INTEGRATE_TAG D(196) +#var DIFFERENTIATE_TAG D(197) +#var AVGRC_TAG D(198) +#var NDERIV_TAG D(199) +#var TAYLOR_TAG D(200) +#var LIMIT_TAG D(201) +#var PROPFRAC_TAG D(202) +#var WHEN_TAG D(203) +#var ROUND_TAG D(204) +#var DMS_TAG D(205) +#var LEFT_TAG D(206) +#var RIGHT_TAG D(207) +#var MID_TAG D(208) +#var SHIFT_TAG D(209) +#var SEQ_TAG D(210) +#var LIST2MAT_TAG D(211) +#var SUBMAT_TAG D(212) +#var SUBSCRIPT_TAG D(213) +#var RAND_TAG D(214) +#var MIN_TAG D(215) +#var MAX_TAG D(216) +#var LIST_TAG D(217) +#var USERFUNC_TAG D(218) +#var MATRIX_TAG D(219) +#var FUNC_TAG D(220) +#var DATA_TAG D(221) +#var GDB_TAG D(222) +#var PIC_TAG D(223) +#var TEXT_TAG D(224) +#var FIG_TAG D(225) +#var MAC_TAG D(226) +#var EXT_TAG D(227) +#var EXT_INSTR_TAG D(228) +#var END_TAG D(229) +#var COMMENT_TAG D(230) +#var NEXTEXPR_TAG D(231) +#var NEWLINE_TAG D(232) +#var ENDSTACK_TAG D(233) +#var PN1_TAG D(234) +#var PN2_TAG D(235) +#var ERROR_MSG_TAG D(236) +#var EIGVC_TAG D(237) +#var EIGVL_TAG D(238) +#var DASH_TAG D(239) +#var LOCALVAR_TAG D(240) +#var DESOLVE_TAG D(241) +#var FDASH_TAG D(242) +#var ASM_TAG D(243) +#var ISPRIME_TAG D(244) +#var OTH_TAG D(248) +#var ROTATE_TAG D(249) + +#var ti_float typedef float ti_float; +#var TSF_FULLY_QUALIFIED D(1) +#var TSF_ALLOW_RESERVED D(2) +#var TSF_PASS_ERRORS D(4) + +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var bottom_estack D((*(AMS_1xx?(CESI*)(&top_estack-2):(CESI*)(_rom_call_addr(432))))) +#var top_estack D((*((ESI*)(_rom_call_addr(109))))) +#var display_statements D(_rom_call(HANDLE,(CESI,short,short),4E)) +#var ESTACK(idx) D((*(idx))) +#var HS_popEStack D(_rom_call(HANDLE,(void),244)) +#var HToESI D(_rom_call(ESI,(HANDLE),247)) +#var next_expression_index D(_rom_call(ESI,(ESI),10A)) +#var NG_approxESI D(_rom_call(void,(CESI),25C)) +#var NG_execute D(_rom_call(void,(HANDLE,short),25D)) +#var NG_graphESI D(_rom_call(void,(CESI,HANDLE),25E)) +#var NG_rationalESI D(_rom_call(void,(CESI),25F)) +#var NG_RPNToText D(_rom_call(HANDLE,(HANDLE,short,short),25B)) +#var NG_tokenize D(_rom_call(short,(HANDLE,__pushort,__pushort),260)) +#var Parms2D D(_rom_call(void,(CESI,__pshort,__pshort,__pshort),4D)) +#var Parse1DExpr D(_rom_call(HANDLE,(CESI,short,short),4F)) +#var Parse2DExpr D(_rom_call(ESI,(CESI,short),4A)) +#var Parse2DMultiExpr D(_rom_call(ESI,(HANDLE,short),4B)) +#var Print2DExpr D(_rom_call(void,(CESI,WINDOW*,short,short),4C)) +#var push_END_TAG D(_rom_call(void,(void),263)) +#var push_LIST_TAG D(_rom_call(void,(void),264)) +#var push_quantum(tag) D((MIN_AMS<101?(void)(*(++top_estack)=tag):_rom_call(void,(ESQ),2EE)(tag))) +#var TokenizeSymName D(_rom_call(ESI,(const char*,short),80)) +#var all_tail D(_rom_call(short,(CESI_Callback_t,ESI),3B5)) +#var any_tail D(_rom_call(short,(CESI_Callback_t,ESI),3B6)) +#var are_expressions_identical D(_rom_call(short,(CESI,CESI),2BF)) +#var can_be_approxed D(_rom_call(short,(CESI,short),2F5)) +#var check_estack_size D(_rom_call(void,(short),2C2)) +#var compare_complex_magnitudes D(_rom_call(short,(CESI,CESI),2F6)) +#var compare_expressions D(_rom_call(short,(CESI,CESI),2C0)) +#var compare_Floats D(_rom_call(long,(CESI,CESI),2F7)) +#var delete_between D(_rom_call(void,(ESI,ESI),2C3)) +#var delete_expression D(_rom_call(void,(ESI),2C5)) +#var deleted_between D(_rom_call(unsigned short,(ESI,ESI),2C4)) +#var deleted_expression D(_rom_call(unsigned short,(ESI),2C6)) +#var did_push_cnvrt_Float_to_integer D(_rom_call(short,(CESI),2F8)) +#var estack_number_to_Float(x) D(_tios_float_1(2F9,x,CESI)) +#var estack_to_short D(_rom_call(short,(CESI,__pshort),2C7)) +#var estack_to_ushort D(_rom_call(short,(CESI,__pushort),2C8)) +#var factor_base_index D(_rom_call(ESI,(CESI),2C9)) +#var factor_exponent_index D(_rom_call(ESI,(CESI),2CA)) +#var gcd_exact_whole_Floats(x,y) D(_tios_float_2(2FC,x,y,CESI,CESI)) +#var get_key_ptr D(_rom_call(char*,(ESQ,ESQ),2B7)) +#var GetValue D(_rom_call(long,(CESI,long,long),2CB)) +#var im_index D(_rom_call(ESI,(CESI),2CC)) +#var index_below_display_expression_aux D(_rom_call(ESI,(CESI),2B6)) +#var index_main_var D(_rom_call(ESI,(CESI),2CF)) +#var index_numeric_term D(_rom_call(ESI,(CESI),2CD)) +#var index_of_lead_base_of_lead_term D(_rom_call(ESI,(CESI),2CE)) +#var is_advanced_tag D(_rom_call(short,(ESQ),2D0)) +#var is_antisymmetric D(_rom_call(short,(CESI,CESI),2D1)) +#var is_complex0 D(_rom_call(short,(CESI),2D3)) +#var is_complex_number D(_rom_call(short,(CESI),2D2)) +#var is_Float_exact_whole_number D(_rom_call(short,(CESI),2FE)) +#var is_free_of_tag D(_rom_call(short,(CESI,ESQ),2D4)) +#var is_independent_of D(_rom_call(short,(CESI,CESI),2D5)) +#var is_independent_of_de_seq_vars D(_rom_call(short,(CESI),2D6)) +#var is_independent_of_elements D(_rom_call(short,(CESI,CESI),2D8)) +#var is_independent_of_tail D(_rom_call(short,(CESI,CESI),2D7)) +#var is_matrix D(_rom_call(short,(CESI),3B7)) +#var is_monomial D(_rom_call(short,(CESI),2D9)) +#var is_monomial_in_kernel D(_rom_call(short,(CESI),2DA)) +#var is_narrowly_independent_of D(_rom_call(short,(CESI,CESI),2DB)) +#var is_square_matrix D(_rom_call(short,(CESI),3B8)) +#var is_symmetric D(_rom_call(short,(CESI,CESI),2DC)) +#var is_tail_independent_of D(_rom_call(short,(CESI,CESI),2DD)) +#var is_valid_smap_aggregate D(_rom_call(short,(CESI),3B9)) +#var last_element_index D(_rom_call(ESI,(CESI),3BA)) +#var lead_base_index D(_rom_call(ESI,(CESI),2DE)) +#var lead_exponent_index D(_rom_call(ESI,(CESI),2DF)) +#var lead_factor_index D(_rom_call(ESI,(CESI),2E0)) +#var lead_term_index D(_rom_call(ESI,(CESI),2E1)) +#var likely_approx_to_complex_number D(_rom_call(short,(CESI),307)) +#var likely_approx_to_number D(_rom_call(short,(CESI),308)) +#var main_gen_var_index D(_rom_call(ESI,(CESI),2E2)) +#var map_tail D(_rom_call(void,(ESI_Callback_t,ESI),3BB)) +#var map_tail_Int D(_rom_call(short,(ESI_Callback_Int_t,ESI,short),3BC)) +#var map_unary_over_comparison D(_rom_call(void,(ESI_Callback_t,ESI),2E3)) +#var min_quantum D(_rom_call(ESQ,(ESQ,ESQ),2E4)) +#var move_between_to_top D(_rom_call(void,(ESI,ESI),2E5)) +#var moved_between_to_top D(_rom_call(unsigned short,(ESI,ESI),2E6)) +#var norm1_complex_Float(x) D(_tios_float_1(309,x,CESI)) +#var numeric_factor_index D(_rom_call(ESI,(CESI),2E7)) +#var push_ANSI_string D(push_zstr) +#var push_between D(_rom_call(void,(void*,void*),2E8)) +#var push_cnvrt_integer_if_whole_nmb D(_rom_call(void,(CESI),30D)) +#var push_expr_quantum D(_rom_call(void,(CESI,ESQ),2E9)) +#var push_expr2_quantum D(_rom_call(void,(CESI,CESI,ESQ),2EA)) +#var push_expression(ptr) D((MIN_AMS<200?({push_expr_quantum(ptr,NOTHING_TAG);(void)(--top_estack);}):_rom_call(void,(CESI),44D)(ptr))) +#var push_Float D(_rom_call(void,(float),30A)) +#var push_Float_to_nonneg_int D(_rom_call(void,(float),30B)) +#var push_Float_to_rat D(_rom_call(void,(CESI),30C)) +#var push_internal_simplify D((*(__push_internal_simplify__type__)(AMS_1xx?(*((void**)((char*)_rom_call_addr(385)+22))):_rom_call(void,(CESI),4F8)))) +#var push_longint void push_longint(long)__ATTR_LIB_ASM__; +#var push_longlongint void push_longlongint(long long)__ATTR_LIB_ASM__; +#var push_next_arb_int D(_rom_call(void,(void),2EB)) +#var push_next_arb_real D(_rom_call(void,(void),2EC)) +#var push_next_internal_var D(_rom_call(void,(ESQ),2ED)) +#var push_offset_array D(_rom_call(unsigned short,(CESI,__pushort*),3C4)) +#var push_overflow_to_infinity D(_rom_call(void,(ESQ),30E)) +#var push_parse_text D(_rom_call(short,(const char*),3CA)) +#var push_quantum_pair D(_rom_call(void,(ESQ,ESQ),2EF)) +#var push_reversed_tail D(_rom_call(void,(CESI),3BF)) +#var push_round_Float D(_rom_call(void,(CESI),310)) +#var push_shortint void push_shortint(short)__ATTR_LIB_ASM__; +#var push_transpose_aux D(_rom_call(void,(CESI,short),3C1)) +#var push_zstr(s) D((MIN_AMS<200?_push_zstr(s):_rom_call(void,(const char*),48A)(s))) +#var re_index D(_rom_call(ESI,(CESI),2F2)) +#var reductum_index D(_rom_call(ESI,(CESI),2F0)) +#var remaining_element_count D(_rom_call(unsigned short,(CESI),3C3)) +#var remaining_factors_index D(_rom_call(ESI,(CESI),2F1)) +#var reset_control_flags D(_rom_call(void,(void),2F4)) +#var reset_estack_size D(_rom_call(void,(short),2F3)) +#var should_and_did_push_approx_arg2 D(_rom_call(short,(CESI,CESI),311)) +#var signum_Float D(_rom_call(long,(CESI),312)) + +#var __push_internal_simplify__type__ typedef void(*__push_internal_simplify__type__)(CESI)__ATTR_TIOS__; diff --git a/pch/src/estackle.pchsource b/pch/src/estackle.pchsource new file mode 100644 index 0000000..3c969e5 --- /dev/null +++ b/pch/src/estackle.pchsource @@ -0,0 +1,167 @@ +#var _push_zstr(s) D(({const char*__p=(s);long __l=_rom_call(long,(const char*),27E)(__p);char *__s=alloca(__l+2);__s[0]=0;push_expr_quantum(_rom_call(char*,(char*,const char*),26C)(__s+1,__p)+__l,STR_TAG);})) +#var _push_zstr_const(s) D((push_expr_quantum(SYMSTR(s),STR_TAG))) + + +#var H_NULL D(0) +#var NULL_INDEX D(((CESI)0)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var CESI_Callback_t typedef CALLBACK unsigned short(*CESI_Callback_t)(CESI); +#var ESI typedef ESQ*ESI; +#var ESI_Callback_Int_t typedef CALLBACK unsigned short(*ESI_Callback_Int_t)(ESI,unsigned short); +#var ESI_Callback_t typedef CALLBACK void(*ESI_Callback_t)(ESI); +#var EStackIndex D(ESI) + +#var MULTI_EXPR typedef struct{unsigned short Size;ESQ Expr[];}MULTI_EXPR; +#var Quantum D(ESQ) +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var SYM_STR typedef CESI SYM_STR; +#var POSINT_TAG D(31) +#var NEGINT_TAG D(32) +#var FLOAT_TAG D(35) +#var BCD_TAG D(35) +#var UNDEF_TAG D(42) +#var FALSE_TAG D(43) +#var TRUE_TAG D(44) +#var STR_TAG D(45) +#var LIST_TAG D(217) +#var USERFUNC_TAG D(218) +#var MATRIX_TAG D(219) +#var FUNC_TAG D(220) +#var DATA_TAG D(221) +#var GDB_TAG D(222) +#var PIC_TAG D(223) +#var TEXT_TAG D(224) +#var FIG_TAG D(225) +#var MAC_TAG D(226) +#var END_TAG D(229) +#var ASM_TAG D(243) +#var OTH_TAG D(248) + +#var ti_float typedef float ti_float; +#var TSF_FULLY_QUALIFIED D(1) +#var TSF_ALLOW_RESERVED D(2) +#var TSF_PASS_ERRORS D(4) + +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var bottom_estack D((*(AMS_1xx?(CESI*)(&top_estack-2):(CESI*)(_rom_call_addr(432))))) +#var top_estack D((*((ESI*)(_rom_call_addr(109))))) +#var display_statements D(_rom_call(HANDLE,(CESI,short,short),4E)) +#var ESTACK(idx) D((*(idx))) +#var HS_popEStack D(_rom_call(HANDLE,(void),244)) +#var HToESI D(_rom_call(ESI,(HANDLE),247)) +#var next_expression_index D(_rom_call(ESI,(ESI),10A)) +#var NG_approxESI D(_rom_call(void,(CESI),25C)) +#var NG_execute D(_rom_call(void,(HANDLE,short),25D)) +#var NG_graphESI D(_rom_call(void,(CESI,HANDLE),25E)) +#var NG_rationalESI D(_rom_call(void,(CESI),25F)) +#var NG_RPNToText D(_rom_call(HANDLE,(HANDLE,short,short),25B)) +#var NG_tokenize D(_rom_call(short,(HANDLE,__pushort,__pushort),260)) +#var Parms2D D(_rom_call(void,(CESI,__pshort,__pshort,__pshort),4D)) +#var Parse1DExpr D(_rom_call(HANDLE,(CESI,short,short),4F)) +#var Parse2DExpr D(_rom_call(ESI,(CESI,short),4A)) +#var Parse2DMultiExpr D(_rom_call(ESI,(HANDLE,short),4B)) +#var Print2DExpr D(_rom_call(void,(CESI,WINDOW*,short,short),4C)) +#var push_END_TAG D(_rom_call(void,(void),263)) +#var push_LIST_TAG D(_rom_call(void,(void),264)) +#var push_quantum(tag) D((MIN_AMS<101?(void)(*(++top_estack)=tag):_rom_call(void,(ESQ),2EE)(tag))) +#var TokenizeSymName D(_rom_call(ESI,(const char*,short),80)) +#var all_tail D(_rom_call(short,(CESI_Callback_t,ESI),3B5)) +#var any_tail D(_rom_call(short,(CESI_Callback_t,ESI),3B6)) +#var are_expressions_identical D(_rom_call(short,(CESI,CESI),2BF)) +#var can_be_approxed D(_rom_call(short,(CESI,short),2F5)) +#var check_estack_size D(_rom_call(void,(short),2C2)) +#var compare_complex_magnitudes D(_rom_call(short,(CESI,CESI),2F6)) +#var compare_expressions D(_rom_call(short,(CESI,CESI),2C0)) +#var compare_Floats D(_rom_call(long,(CESI,CESI),2F7)) +#var delete_between D(_rom_call(void,(ESI,ESI),2C3)) +#var delete_expression D(_rom_call(void,(ESI),2C5)) +#var deleted_between D(_rom_call(unsigned short,(ESI,ESI),2C4)) +#var deleted_expression D(_rom_call(unsigned short,(ESI),2C6)) +#var did_push_cnvrt_Float_to_integer D(_rom_call(short,(CESI),2F8)) +#var estack_number_to_Float(x) D(_tios_float_1(2F9,x,CESI)) +#var estack_to_short D(_rom_call(short,(CESI,__pshort),2C7)) +#var estack_to_ushort D(_rom_call(short,(CESI,__pushort),2C8)) +#var factor_base_index D(_rom_call(ESI,(CESI),2C9)) +#var factor_exponent_index D(_rom_call(ESI,(CESI),2CA)) +#var gcd_exact_whole_Floats(x,y) D(_tios_float_2(2FC,x,y,CESI,CESI)) +#var get_key_ptr D(_rom_call(char*,(ESQ,ESQ),2B7)) +#var GetValue D(_rom_call(long,(CESI,long,long),2CB)) +#var im_index D(_rom_call(ESI,(CESI),2CC)) +#var index_below_display_expression_aux D(_rom_call(ESI,(CESI),2B6)) +#var index_main_var D(_rom_call(ESI,(CESI),2CF)) +#var index_numeric_term D(_rom_call(ESI,(CESI),2CD)) +#var index_of_lead_base_of_lead_term D(_rom_call(ESI,(CESI),2CE)) +#var is_advanced_tag D(_rom_call(short,(ESQ),2D0)) +#var is_antisymmetric D(_rom_call(short,(CESI,CESI),2D1)) +#var is_complex0 D(_rom_call(short,(CESI),2D3)) +#var is_complex_number D(_rom_call(short,(CESI),2D2)) +#var is_Float_exact_whole_number D(_rom_call(short,(CESI),2FE)) +#var is_free_of_tag D(_rom_call(short,(CESI,ESQ),2D4)) +#var is_independent_of D(_rom_call(short,(CESI,CESI),2D5)) +#var is_independent_of_de_seq_vars D(_rom_call(short,(CESI),2D6)) +#var is_independent_of_elements D(_rom_call(short,(CESI,CESI),2D8)) +#var is_independent_of_tail D(_rom_call(short,(CESI,CESI),2D7)) +#var is_matrix D(_rom_call(short,(CESI),3B7)) +#var is_monomial D(_rom_call(short,(CESI),2D9)) +#var is_monomial_in_kernel D(_rom_call(short,(CESI),2DA)) +#var is_narrowly_independent_of D(_rom_call(short,(CESI,CESI),2DB)) +#var is_square_matrix D(_rom_call(short,(CESI),3B8)) +#var is_symmetric D(_rom_call(short,(CESI,CESI),2DC)) +#var is_tail_independent_of D(_rom_call(short,(CESI,CESI),2DD)) +#var is_valid_smap_aggregate D(_rom_call(short,(CESI),3B9)) +#var last_element_index D(_rom_call(ESI,(CESI),3BA)) +#var lead_base_index D(_rom_call(ESI,(CESI),2DE)) +#var lead_exponent_index D(_rom_call(ESI,(CESI),2DF)) +#var lead_factor_index D(_rom_call(ESI,(CESI),2E0)) +#var lead_term_index D(_rom_call(ESI,(CESI),2E1)) +#var likely_approx_to_complex_number D(_rom_call(short,(CESI),307)) +#var likely_approx_to_number D(_rom_call(short,(CESI),308)) +#var main_gen_var_index D(_rom_call(ESI,(CESI),2E2)) +#var map_tail D(_rom_call(void,(ESI_Callback_t,ESI),3BB)) +#var map_tail_Int D(_rom_call(short,(ESI_Callback_Int_t,ESI,short),3BC)) +#var map_unary_over_comparison D(_rom_call(void,(ESI_Callback_t,ESI),2E3)) +#var min_quantum D(_rom_call(ESQ,(ESQ,ESQ),2E4)) +#var move_between_to_top D(_rom_call(void,(ESI,ESI),2E5)) +#var moved_between_to_top D(_rom_call(unsigned short,(ESI,ESI),2E6)) +#var norm1_complex_Float(x) D(_tios_float_1(309,x,CESI)) +#var numeric_factor_index D(_rom_call(ESI,(CESI),2E7)) +#var push_ANSI_string D(push_zstr) +#var push_between D(_rom_call(void,(void*,void*),2E8)) +#var push_cnvrt_integer_if_whole_nmb D(_rom_call(void,(CESI),30D)) +#var push_expr_quantum D(_rom_call(void,(CESI,ESQ),2E9)) +#var push_expr2_quantum D(_rom_call(void,(CESI,CESI,ESQ),2EA)) +#var push_expression(ptr) D((MIN_AMS<200?({push_expr_quantum(ptr,NOTHING_TAG);(void)(--top_estack);}):_rom_call(void,(CESI),44D)(ptr))) +#var push_Float D(_rom_call(void,(float),30A)) +#var push_Float_to_nonneg_int D(_rom_call(void,(float),30B)) +#var push_Float_to_rat D(_rom_call(void,(CESI),30C)) +#var push_internal_simplify D((*(__push_internal_simplify__type__)(AMS_1xx?(*((void**)((char*)_rom_call_addr(385)+22))):_rom_call(void,(CESI),4F8)))) +#var push_longint void push_longint(long)__ATTR_LIB_ASM__; +#var push_longlongint void push_longlongint(long long)__ATTR_LIB_ASM__; +#var push_next_arb_int D(_rom_call(void,(void),2EB)) +#var push_next_arb_real D(_rom_call(void,(void),2EC)) +#var push_next_internal_var D(_rom_call(void,(ESQ),2ED)) +#var push_offset_array D(_rom_call(unsigned short,(CESI,__pushort*),3C4)) +#var push_overflow_to_infinity D(_rom_call(void,(ESQ),30E)) +#var push_parse_text D(_rom_call(short,(const char*),3CA)) +#var push_quantum_pair D(_rom_call(void,(ESQ,ESQ),2EF)) +#var push_reversed_tail D(_rom_call(void,(CESI),3BF)) +#var push_round_Float D(_rom_call(void,(CESI),310)) +#var push_shortint void push_shortint(short)__ATTR_LIB_ASM__; +#var push_transpose_aux D(_rom_call(void,(CESI,short),3C1)) +#var push_zstr(s) D((MIN_AMS<200?_push_zstr(s):_rom_call(void,(const char*),48A)(s))) +#var re_index D(_rom_call(ESI,(CESI),2F2)) +#var reductum_index D(_rom_call(ESI,(CESI),2F0)) +#var remaining_element_count D(_rom_call(unsigned short,(CESI),3C3)) +#var remaining_factors_index D(_rom_call(ESI,(CESI),2F1)) +#var reset_control_flags D(_rom_call(void,(void),2F4)) +#var reset_estack_size D(_rom_call(void,(short),2F3)) +#var should_and_did_push_approx_arg2 D(_rom_call(short,(CESI,CESI),311)) +#var signum_Float D(_rom_call(long,(CESI),312)) + +#var __push_internal_simplify__type__ typedef void(*__push_internal_simplify__type__)(CESI)__ATTR_TIOS__; diff --git a/pch/src/events.pchsource b/pch/src/events.pchsource new file mode 100644 index 0000000..8b02468 --- /dev/null +++ b/pch/src/events.pchsource @@ -0,0 +1,142 @@ + +#var ModeSettings D(((MO_OPTIONS*const)(long)*(short*)((char*)MO_currentOptions+6))) +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var HANDLE typedef unsigned short HANDLE; +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var WIN_RECT typedef struct{short x0,y0,x1,y1;}WIN_RECT; +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var EVENT typedef struct EventStruct{unsigned short Type;unsigned short RunningApp;unsigned short Side;unsigned short StatusFlags;union{WINDOW*w;WIN_RECT*r;char*pasteText;HANDLE hPasteText;struct{unsigned short Mod;unsigned short Code;}Key;}extra;unsigned char StartType;}EVENT; +#var EVENT_HANDLER typedef void(*EVENT_HANDLER)(EVENT*)CALLBACK; +#var CM_IDLE D(1792) +#var CM_INIT D(1793) +#var CM_STARTTASK D(1794) +#var CM_ACTIVATE D(1795) +#var CM_FOCUS D(1796) +#var CM_UNFOCUS D(1797) +#var CM_DEACTIVATE D(1798) +#var CM_ENDTASK D(1799) +#var CM_START_CURRENT D(1800) +#var CM_DEFAULTS D(1803) +#var CM_KEYPRESS D(1808) +#var CM_MENU_CUT D(1824) +#var CM_MENU_COPY D(1825) +#var CM_MENU_PASTE D(1826) +#var CM_STRING D(1827) +#var CM_HSTRING D(1828) +#var CM_DEL D(1829) +#var CM_CLR D(1830) +#var CM_MENU_CLEAR D(1831) +#var CM_MENU_FIND D(1832) +#var CM_INSERT D(1840) +#var CM_BLINK D(1856) +#var CM_STORE D(1872) +#var CM_RECALL D(1873) +#var CM_WPAINT D(1888) +#var CM_MENU_OPEN D(1904) +#var CM_MENU_SAVE D(1905) +#var CM_MENU_NEW D(1906) +#var CM_MENU_FORMAT D(1907) +#var CM_MENU_ABOUT D(1908) +#var CM_MODE_CHANGE D(1920) +#var CM_SWITCH_GRAPH D(1921) +#var CM_GEOMETRY D(1984) + +#var MO_OPTIONS typedef struct{unsigned short CurrentFolder;unsigned short SplitScreen;unsigned short NumGraphs;unsigned short Graph1;unsigned short Graph2;unsigned short Split1App;unsigned short Split2App;unsigned short SplitRatio;unsigned short Angle;unsigned short ExactApprox;unsigned short Fix;unsigned short Exp;unsigned short Vector;unsigned short Complex;unsigned short Pretty;unsigned short Base;unsigned short UnitSystem;unsigned short CustomUnits;}MO_OPTIONS; +#var PAINTING_ENABLED D(0) +#var PAINTING_SUSPENDED D(2) + +#var ACTIVITY_IDLE D(0) +#var ACTIVITY_BUSY D(1) +#var ACTIVITY_PAUSED D(2) +#var ACTIVITY_NORMAL D(3) + +#var AP_NULL D(-3) +#var AP_RUNNING D(-2) +#var AP_CURRENT D(-1) + +#var AP_START_CURRENT D(0) +#var __AP_START_NEW_2 D(1) +#var __AP_START_OPEN_2 D(2) +#var __AP_START_ERROR_2 D(3) +#var __AP_START_NEW_1 D(16) +#var __AP_START_OPEN_1 D(32) +#var __AP_START_ERROR_1 D(48) + +#var SDT_EXPR D(0) +#var SDT_LIST D(1) +#var SDT_MAT D(2) +#var SDT_FUNC D(3) +#var SDT_PRGM D(4) +#var SDT_PIC D(5) +#var SDT_STR D(6) +#var SDT_TEXT D(7) +#var SDT_GDB D(8) +#var SDT_DATA D(9) +#var SDT_FIG D(10) +#var SDT_MAC D(11) +#var SDT_OTH D(12) +#var SDT_SYS D(13) +#var SDT_ALL D(14) +#var SDT_ASM D(15) + +#var WF_SYS_ALLOC D(1) +#var WF_STEAL_MEM D(2) +#var WF_DONT_REALLOC D(4) +#var WF_ROUNDEDBORDER D(8) +#var WF_SAVE_SCR D(16) +#var WF_DUP_SCR D(32) +#var WF_TTY D(64) +#var WF_ACTIVE D(128) +#var WF_NOBORDER D(256) +#var WF_NOBOLD D(512) +#var WF_DUP_ON D(1024) +#var WF_VIRTUAL D(2048) +#var WF_TITLE D(4096) +#var WF_DIRTY D(8192) +#var WF_TRY_SAVE_SCR D(16400) +#var WF_VISIBLE D(-32768) + +#var EV_hook D((*((EVENT_HANDLER*)(_rom_call_addr(2A3))))) +#var ABT_dialog D(_rom_call(void,(void),10D)) +#var CAT_dialog D(_rom_call(void,(void),125)) +#var EV_captureEvents D(_rom_call(EVENT_HANDLER,(EVENT_HANDLER),C6)) +#var EV_centralDispatcher D(_rom_call(void,(void),156)) +#var EV_clearPasteString D(_rom_call(void,(void),C7)) +#var EV_defaultHandler D(_rom_call(void,(EVENT*),157)) +#var EV_eventLoop D(_rom_call(void,(void),158)) +#var EV_getAppID short EV_getAppID(const char*)__ATTR_LIB_ASM__; +#var EV_getc D(_rom_call(unsigned short,(short,EVENT*),C8)) +#var EV_getSplitRect D(_rom_call(WIN_RECT*,(short),C9)) +#var EV_notifySwitchGraph D(_rom_call(void,(void),CA)) +#var EV_paintOneWindow D(_rom_call(short,(void),CB)) +#var EV_paintWindows D(_rom_call(void,(void),CC)) +#var EV_registerMenu D(_rom_call(void,(void*),159)) +#var EV_restorePainting D(_rom_call(short,(short),CD)) +#var EV_sendEvent D(_rom_call(void,(short,EVENT*),CE)) +#var EV_sendEventSide D(_rom_call(void,(short,EVENT*,short),CF)) +#var EV_sendString D(_rom_call(void,(short),D0)) +#var EV_setCmdCheck D(_rom_call(void,(short,short),D1)) +#var EV_setCmdState D(_rom_call(void,(short,short),D2)) +#var EV_setFKeyState D(_rom_call(void,(short,short,short),D3)) +#var EV_startApp D(_rom_call(void,(short,short),D4)) +#var EV_startSide D(_rom_call(void,(__pshort,short,short),D5)) +#var EV_startTask D(_rom_call(void,(short),D6)) +#var EV_suspendPainting D(_rom_call(short,(void),D7)) +#var EV_switch D(_rom_call(void,(void),D8)) +#var handleRclKey D(_rom_call(void,(short),14F)) +#var MO_currentOptions D(_rom_call(void,(void),D9)) +#var MO_defaults D(_rom_call(void,(void),DA)) +#var MO_digestOptions D(_rom_call(void,(short),DB)) +#var MO_isMultigraphTask D(_rom_call(short,(short),DC)) +#var MO_modeDialog D(_rom_call(void,(void),DD)) +#var MO_notifyModeChange D(_rom_call(void,(short),DE)) +#var MO_sendQuit D(_rom_call(void,(short,short),DF)) + + +#var AP_START_NEW D((AMS_1xx?__AP_START_NEW_1:__AP_START_NEW_2)) +#var AP_START_OPEN D((AMS_1xx?__AP_START_OPEN_1:__AP_START_OPEN_2)) +#var AP_START_ERROR D((AMS_1xx?__AP_START_ERROR_1:__AP_START_ERROR_2)) diff --git a/pch/src/flash.pchsource b/pch/src/flash.pchsource new file mode 100644 index 0000000..27a7b37 --- /dev/null +++ b/pch/src/flash.pchsource @@ -0,0 +1,24 @@ +#var __EM_findEmptySlot D(_rom_call(void*,(long,short),15F)) + + +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var HANDLE typedef unsigned short HANDLE; +#var HARDWARE_PARM_BLOCK typedef struct{unsigned short len;unsigned long hardwareID;unsigned long hardwareRevision;unsigned long bootMajor;unsigned long bootRevision;unsigned long bootBuild;unsigned long gateArray;unsigned long physDisplayBitsWide;unsigned long physDisplayBitsTall;unsigned long LCDBitsWide;unsigned long LCDBitsTall;}HARDWARE_PARM_BLOCK; +#var size_t typedef unsigned long size_t; +#var EM_abandon D(_rom_call(void,(HANDLE),15B)) +#var EM_blockVerifyErase D(_rom_call(short,(void*),15D)) +#var EM_findEmptySlot(s) D((__EM_findEmptySlot((s),0))) +#var EM_GC D(_rom_call(short,(short),160)) +#var EM_survey D(_rom_call(void,(__pulong,__pulong,__pulong,__pulong,__pulong,__pulong),165)) +#var EM_write D(_rom_call(void,(const void*,void*,long),167)) +#var FL_addCert D(_rom_call(unsigned short,(void*,long),169)) +#var FL_download D(_rom_call(void,(long),16A)) +#var FL_getCert D(_rom_call(void,(HANDLE*,__pulong,short),16C)) +#var FL_getHardwareParmBlock() D((TIOS_entries<0x3CC?(const void*)"\0\x6\0\0\0\x1":_rom_call(const void*,(void),16B)())) +#var FL_getVerNum D(_rom_call(unsigned short,(void),16D)) +#var FL_write D(_rom_call(void,(const void*,void*,long),171)) +#var GetAMSSize unsigned long GetAMSSize(void); + diff --git a/pch/src/float.pchsource b/pch/src/float.pchsource new file mode 100644 index 0000000..241ddb5 --- /dev/null +++ b/pch/src/float.pchsource @@ -0,0 +1,41 @@ + +#var DBL_DIG D(16) +#var DBL_EPSILON D((1e-15)) +#var DBL_MANT_BITS D(64) +#var DBL_MANT_DIG D(16) +#var DBL_MAX D((9.999999999999999e999)) +#var DBL_MAX_10_EXP D(999) +#var DBL_MAX_2_EXP D(3321) +#var DBL_MAX_EXP D(999) +#var DBL_MIN D((1e-999)) +#var DBL_MIN_10_EXP D((-999)) +#var DBL_MIN_2_EXP D((-3318)) +#var DBL_MIN_EXP D((-999)) +#var FLT_DIG D(16) +#var FLT_EPSILON D((1e-15)) +#var FLT_MANT_BITS D(64) +#var FLT_MANT_DIG D(16) +#var FLT_MAX D((9.999999999999999e999)) +#var FLT_MAX_10_EXP D(999) +#var FLT_MAX_2_EXP D(3321) +#var FLT_MAX_EXP D(999) +#var FLT_MIN D((1e-999)) +#var FLT_MIN_10_EXP D((-999)) +#var FLT_MIN_2_EXP D((-3318)) +#var FLT_MIN_EXP D((-999)) +#var FLT_NORMALIZE D(1) +#var FLT_RADIX D(10) +#var FLT_ROUNDS D(1) +#var LDBL_DIG D(16) +#var LDBL_EPSILON D((1e-15)) +#var LDBL_MANT_BITS D(64) +#var LDBL_MANT_DIG D(16) +#var LDBL_MAX D((9.999999999999999e999)) +#var LDBL_MAX_10_EXP D(999) +#var LDBL_MAX_2_EXP D(3321) +#var LDBL_MAX_EXP D(999) +#var LDBL_MIN D((1e-999)) +#var LDBL_MIN_10_EXP D((-999)) +#var LDBL_MIN_2_EXP D((-3318)) +#var LDBL_MIN_EXP D((-999)) + diff --git a/pch/src/gdraw.pchsource b/pch/src/gdraw.pchsource new file mode 100644 index 0000000..8c41d57 --- /dev/null +++ b/pch/src/gdraw.pchsource @@ -0,0 +1,17 @@ + +#var GR_FUNC D(1) +#var GR_PAR D(2) +#var GR_POL D(3) +#var GR_SEQ D(4) +#var GR_3D D(5) +#var GR_DE D(6) + +#var GD_Circle D(_rom_call(void,(void),176)) +#var GD_Contour D(_rom_call(void,(void),17D)) +#var GD_Eraser D(_rom_call(void,(void),17A)) +#var GD_HVLine D(_rom_call(void,(short),178)) +#var GD_Line D(_rom_call(void,(void),177)) +#var GD_Pen D(_rom_call(void,(void),179)) +#var GD_Select D(_rom_call(void,(void),17C)) +#var GD_Text D(_rom_call(void,(void),17B)) + diff --git a/pch/src/graph.pchsource b/pch/src/graph.pchsource new file mode 100644 index 0000000..e686dac --- /dev/null +++ b/pch/src/graph.pchsource @@ -0,0 +1,87 @@ + +#var BITMAP_HDR_SIZE D(4) +#var LCD_MEM D(((void*)0x4C00)) +#var LCD_SIZE D(3840) +#var A_REVERSE D(0) +#var A_NORMAL D(1) +#var A_XOR D(2) +#var A_SHADED D(3) +#var A_REPLACE D(4) +#var A_OR D(5) +#var A_AND D(6) +#var A_THICK1 D(7) +#var A_SHADE_V D(8) +#var A_SHADE_H D(9) +#var A_SHADE_NS D(10) +#var A_SHADE_PS D(11) + +#var BITMAP typedef struct{unsigned short NumRows,NumCols;unsigned char Data[];}BITMAP; +#var FALSE D(0) +#var TRUE D(1) + +#var B_NORMAL D(16) +#var B_ROUNDED D(32) +#var B_DOUBLE D(64) +#var B_CUT D(128) + +#var F_4x6 D(0) +#var F_6x8 D(1) +#var F_8x10 D(2) + +#var ICON typedef struct{unsigned short i[16];}ICON; +#var LCD_BUFFER typedef char LCD_BUFFER[LCD_SIZE]; +#var MULTI_LINE typedef struct{unsigned char Count;struct{unsigned char Attr,x0,y0,x1,y1;}Data[];}MULTI_LINE; +#var pICON typedef unsigned short*pICON; +#var SCR_COORDS typedef unsigned char SCR_COORDS; +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var WIN_COORDS typedef short WIN_COORDS; +#var WIN_RECT typedef struct{short x0,y0,x1,y1;}WIN_RECT; +#var ScrRect D(((SCR_RECT*const)(_rom_call_addr(2F)))) +#var BitmapGet D(_rom_call(void,(const SCR_RECT*,void*),185)) +#var BitmapInit D(_rom_call(void,(const SCR_RECT*,void*),186)) +#var BitmapPut D(_rom_call(void,(short,short,const void*,const SCR_RECT*,short),187)) +#var BitmapSize D(_rom_call(unsigned short,(const SCR_RECT*),188)) +#var ClrScr D(_rom_call(void,(void),19E)) +#var ClearScreen D(ClrScr) +#var DisplayOff() D((pokeIO_bclr(0x600015,0))) +#var DisplayOn() D((pokeIO_bset(0x600015,0))) +#var DrawChar D(_rom_call(void,(short,short,char,short),1A4)) +#var DrawClipChar D(_rom_call(void,(short,short,short,const SCR_RECT*,short),191)) +#var DrawClipEllipse D(_rom_call(void,(short,short,short,short,const SCR_RECT*,short),192)) +#var DrawClipLine D(_rom_call(void,(const WIN_RECT*,const SCR_RECT*,short),193)) +#var DrawClipPix D(_rom_call(void,(short,short),194)) +#var DrawClipRect D(_rom_call(void,(const WIN_RECT*,const SCR_RECT*,short),195)) +#var DrawFkey D(_rom_call(void,(short,short,short,short),1A5)) +#var DrawIcon D(_rom_call(void,(short,short,const void*,short),1A6)) +#var DrawLine D(_rom_call(void,(short,short,short,short,short),1A7)) +#var DrawMultiLines D(_rom_call(void,(short,short,const void*),196)) +#var DrawPix D(_rom_call(void,(short,short,short),1A8)) +#var DrawStr D(_rom_call(void,(short,short,const char*,short),1A9)) +#var DrawStrXY D(DrawStr) +#var DrawStrWidth D(_rom_call(short,(const char*,short),197)) +#var DrawTo D(_rom_call(void,(short,short),19C)) +#var FillLines2 D(_rom_call(void,(const WIN_RECT*,const WIN_RECT*,const SCR_RECT*,short),199)) +#var FillTriangle D(_rom_call(void,(short,short,short,short,short,short,const SCR_RECT*,short),198)) +#var FontCharWidth D(_rom_call(short,(short),190)) +#var FontGetSys D(_rom_call(unsigned char,(void),18E)) +#var FontSetSys D(_rom_call(unsigned char,(short),18F)) +#var GetPix D(_rom_call(short,(short,short),19F)) +#var LCD_restore(b) D(((void)(_rom_call(void,(),26A)(LCD_MEM,(const void*)(b),(long)LCD_SIZE)))) +#var LCD_save(b) D(((void)(_rom_call(void,(),26A)((void*)(b),LCD_MEM,(long)LCD_SIZE)))) +#var LineTo D(_rom_call(void,(short,short),19C)) +#var MakeWinRect D(_rom_call(WIN_RECT*,(short,short,short,short),2C)) +#var MoveTo D(_rom_call(void,(short,short),19D)) +#var PortRestore D(_rom_call(void,(void),1A3)) +#var PortSet D(_rom_call(void,(void*,short,short),1A2)) +#var QScrRectOverlap D(_rom_call(short,(const SCR_RECT*,const SCR_RECT*),18D)) +#var RestoreScrState D(_rom_call(void,(const void*),1A1)) +#var SaveScrState D(_rom_call(void,(void*),1A0)) +#var ScrRectFill D(_rom_call(void,(const SCR_RECT*,const SCR_RECT*,short),189)) +#var ScrRectOverlap D(_rom_call(short,(const SCR_RECT*,const SCR_RECT*,SCR_RECT*),18A)) +#var ScrRectScroll D(_rom_call(void,(const SCR_RECT*,const SCR_RECT*,short,short),18B)) +#var ScrRectShift D(_rom_call(void,(const SCR_RECT*,const SCR_RECT*,short,short),18C)) +#var ScrToHome D(_rom_call(SCR_RECT*,(SCR_RECT*),2E)) +#var ScrToWin D(_rom_call(WIN_RECT*,(const SCR_RECT*),2D)) +#var SetCurAttr D(_rom_call(short,(short),19A)) +#var SetCurClip D(_rom_call(void,(const SCR_RECT*),19B)) diff --git a/pch/src/gray.pchsource b/pch/src/gray.pchsource new file mode 100644 index 0000000..d2835ad --- /dev/null +++ b/pch/src/gray.pchsource @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + +#var __L_plane extern void* __L_plane; +#var __D_plane extern void* __D_plane; +#var __L_plane2 extern void* __L_plane2; +#var __D_plane2 extern void* __D_plane2; + +#var __gray_hw_type extern short __gray_hw_type; +#var __gray_dbl_offset extern unsigned short __gray_dbl_offset; +#var __switch_cnt extern volatile unsigned long __switch_cnt; +#var __gray_old_int1_hw1 extern volatile void *__gray_old_int1_hw1; +#var __gray_old_int1_hw2 extern volatile void *__gray_old_int1_hw2; +#var __gray_version extern const char __gray_version[]; + + + + + + +#var GRAYDBUFFER_SIZE D(7688) +#var FALSE D(0) +#var TRUE D(1) + +#var GRAY_OFF D(0) +#var GRAY_ON D(1) +#var GRAY_HW1 D(1) +#var GRAY_HW2 D(1) + +#var LIGHT_PLANE D(0) +#var DARK_PLANE D(1) + +#var _DEREF_INT_HANDLER typedef struct{short foo;}_DEREF_INT_HANDLER; +#var INT_HANDLER typedef _DEREF_INT_HANDLER *INT_HANDLER; +#var GrayAdjust(x) D(((void)(*(volatile unsigned char*)0x600013=128-(signed char)(x)))) +#var GrayCheckRunning() D((!!__gray_handle)) +#var __gray_handle extern unsigned short __gray_handle; +#var IsGrayMode D(GrayCheckRunning) +#var GrayDBufCleanup() D(((void)(__gray_dbl_offset=0,__D_plane2=__D_plane,__L_plane2=__L_plane))) +#var GrayDBufGetActiveIdx() D((!!__gray_dbl_offset)) +#var GrayDBufGetActivePlane(x) D((GrayDBufGetPlane(GrayDBufGetActiveIdx(),x))) +#var GrayDBufGetHiddenIdx() D((!__gray_dbl_offset)) +#var GrayDBufGetHiddenPlane(x) D((GrayDBufGetPlane(GrayDBufGetHiddenIdx(),x))) +#var GrayDBufGetPlane(i,x) D(((i)?((x)?__D_plane2:__L_plane2):GrayGetPlane(x))) +#var GrayDBufInit(p) D(({void*aptr=(void*)((((long)p)+7)&0xfffffff8L);__gray_dbl_offset=0;__D_plane2=aptr;(void)(__L_plane2=aptr+3840);})) +#var GrayDBufSetActiveAMSPlane(x) D(GrayDBufSetAMSPlane(GrayDBufGetActiveIdx(),x)) +#var GrayDBufSetActiveIdx(i) D(((void)(__gray_dbl_offset=((i)?8:0)))) +#var GrayDBufSetActiveIdxSync(i) D(((void)(GrayWaitNSwitches(1),GrayDBufSetActiveIdx(i)))) +#var GrayDBufSetAMSPlane(i,x) D((_rom_call(void,(void*,long),1A2)(GrayDBufGetPlane(i,x),0xEF007F))) +#var GrayDBufSetHiddenAMSPlane(x) D(GrayDBufSetAMSPlane(GrayDBufGetHiddenIdx(),x)) +#var GrayDBufToggle() D(((void)(__gray_dbl_offset=(__gray_dbl_offset?0:8)))) +#var GrayDBufToggleSync() D((GrayWaitNSwitches(1),GrayDBufToggle())) +#var GrayGetInt1Handler() D(((INT_HANDLER)(__gray_hw_type?__gray_old_int1_hw2:__gray_old_int1_hw1))) +#var GetGrayInt1Handler D(GrayGetInt1Handler) +#var GrayGetPlane(x) D(((x)?__D_plane:__L_plane)) +#var GetPlane D(GrayGetPlane) +#var GrayGetSwitchCount() D((__switch_cnt)) +#var GetGraySwitchCount D(GrayGetSwitchCount) +#var GrayGetVersionString() D(((const char*)__gray_version)) +#var GrayMode(x) D(((x)?GrayOn():(GrayOff(),(short)1))) +#var GrayOff void GrayOff(void)__ATTR_LIB_ASM__; +#var GrayOn short GrayOn(void)__ATTR_LIB_ASM__; +#var GraySetAMSPlane(x) D((_rom_call(void,(void*,long),1A2)(GrayGetPlane(x),0xEF007F))) +#var SetPlane D(GraySetAMSPlane) +#var GraySetInt1Handler(p) D(((void)(__gray_hw_type?((INT_HANDLER)__gray_old_int1_hw2=(p)):((INT_HANDLER)__gray_old_int1_hw1=(p))))) +#var SetGrayInt1Handler D(GraySetInt1Handler) +#var GraySetSwitchCount(val) D((__switch_cnt=(val))) +#var SetGraySwitchCount D(GraySetSwitchCount) +#var GrayWaitNSwitches(n) D(({unsigned long __w=__switch_cnt+(n);while(__switch_cnt<__w);})) + + +#var _GrayIsRealHW2() D((__gray_hw_type)) diff --git a/pch/src/gtc.pchsource b/pch/src/gtc.pchsource new file mode 100644 index 0000000..b67eece --- /dev/null +++ b/pch/src/gtc.pchsource @@ -0,0 +1,5 @@ +#var _RC_INDEX_romcall(t,a,i) D(0x##i) +#var _RC_INDEX_romcall_addr(i) D(0x##i) +#var _ROMCALL_INDEX(name) D(_RC_INDEX##name) +#var ROMCALL_INDEX(name) D(_ROMCALL_INDEX(name)) +#var ROMCALL_OFFSET(name) D((_ROMCALL_INDEX(name)*4)) diff --git a/pch/src/homescr.pchsource b/pch/src/homescr.pchsource new file mode 100644 index 0000000..d1b5a9c --- /dev/null +++ b/pch/src/homescr.pchsource @@ -0,0 +1,29 @@ +#var __HS_pushEmptyFIFONode__type__ typedef void(*__HS_pushEmptyFIFONode__type__)(short)__ATTR_TIOS__; + + + +#var H_NULL D(0) +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var HANDLE typedef unsigned short HANDLE; +#var MULTI_EXPR typedef struct{unsigned short Size;ESQ Expr[];}MULTI_EXPR; +#var FIFO_ELEMENT typedef struct{short ScreenLeft;long ScreenBottom;long XStart;unsigned short Width;unsigned short Height;short Top;HANDLE Expr;short TooLong;short PrettyPrint;unsigned short Exp;unsigned short Fix;}FIFO_ELEMENT; +#var FIFO_NODE typedef struct{FIFO_ELEMENT Entry;FIFO_ELEMENT Ans;HANDLE Prev;HANDLE Next;}FIFO_NODE; +#var HomeExecute D(_rom_call(void,(const char*,short),10E)) +#var HomePushEStack D(_rom_call(void,(void),10F)) +#var HomeStore void HomeStore(void)__ATTR_LIB_ASM__; +#var HomeStorePair void HomeStorePair(HANDLE,HANDLE)__ATTR_LIB_C__; +#var HS_chopFIFO D(_rom_call(void,(void),23C)) +#var HS_countFIFO D(_rom_call(unsigned short,(void),23D)) +#var HS_deleteFIFONode D(_rom_call(HANDLE,(HANDLE),23E)) +#var HS_freeAll D(_rom_call(void,(void),23F)) +#var HS_freeFIFONode D(_rom_call(void,(HANDLE),240)) +#var HS_getAns D(_rom_call(HANDLE,(short),241)) +#var HS_getEntry D(_rom_call(HANDLE,(short),242)) +#var HS_getFIFONode D(_rom_call(HANDLE,(short),243)) +#var HS_newFIFONode D(_rom_call(HANDLE,(void),245)) +#var HS_popEStack D(_rom_call(HANDLE,(void),244)) +#var HS_pushEmptyFIFONode D((*(__get_HS_pushEmptyFIFONode()))) __HS_pushEmptyFIFONode__type__ __get_HS_pushEmptyFIFONode(void)__ATTR_LIB_C__; +#var HS_pushFIFONode D(_rom_call(void,(HANDLE),246)) diff --git a/pch/src/intr.pchsource b/pch/src/intr.pchsource new file mode 100644 index 0000000..0ef942c --- /dev/null +++ b/pch/src/intr.pchsource @@ -0,0 +1,73 @@ + + + +#var AUTO_INT_COUNT D((LAST_AUTO_INT-FIRST_AUTO_INT+1)) +#var FIRST_AUTO_INT D(1) +#var FIRST_TRAP D(0) +#var LAST_AUTO_INT D(7) +#var LAST_TRAP D(15) +#var TRAP_COUNT D((LAST_TRAP-FIRST_TRAP+1)) +#var AutoInts D(IntVecs) +#var FALSE D(0) +#var TRUE D(1) + +#var _DEREF_INT_HANDLER typedef struct{short foo;}_DEREF_INT_HANDLER; +#var INT_HANDLER typedef _DEREF_INT_HANDLER *INT_HANDLER; +#var AUTO_INT_1 D(100) +#var AUTO_INT_2 D(104) +#var AUTO_INT_3 D(108) +#var AUTO_INT_4 D(112) +#var AUTO_INT_5 D(116) +#var AUTO_INT_6 D(120) +#var AUTO_INT_7 D(124) +#var TRAP_0 D(128) +#var TRAP_1 D(132) +#var TRAP_2 D(136) +#var TRAP_3 D(140) +#var TRAP_4 D(144) +#var TRAP_5 D(148) +#var TRAP_6 D(152) +#var TRAP_7 D(156) +#var TRAP_8 D(160) +#var TRAP_9 D(164) +#var TRAP_10 D(168) +#var TRAP_11 D(172) +#var TRAP_12 D(176) +#var TRAP_13 D(180) +#var TRAP_14 D(184) +#var TRAP_15 D(188) +#var INT_VEC_RESET D(4) +#var INT_VEC_BUS_ERROR D(8) +#var INT_VEC_ADDRESS_ERROR D(12) +#var INT_VEC_ILLEGAL_INSTRUCTION D(16) +#var INT_VEC_ZERO_DIVIDE D(20) +#var INT_VEC_CHK_INS D(24) +#var INT_VEC_TRAPV_INS D(28) +#var INT_VEC_PRIVILEGE_VIOLATION D(32) +#var INT_VEC_TRACE D(36) +#var INT_VEC_LINE_1010 D(40) +#var INT_VEC_LINE_1111 D(44) +#var INT_VEC_UNINITIALIZED_INT D(60) +#var INT_VEC_SPURIOUS_INT D(96) +#var INT_VEC_KEY_PRESS D(104) +#var INT_VEC_LINK D(112) +#var INT_VEC_ON_KEY_PRESS D(120) +#var INT_VEC_STACK_OVERFLOW D(124) +#var INT_VEC_INT_MASK D(132) +#var INT_VEC_MANUAL_RESET D(136) +#var INT_VEC_OFF D(144) +#var INT_VEC_SELF_TEST D(168) +#var INT_VEC_ARCHIVE D(172) +#var INT_VEC_ER_THROW D(188) + +#var AUTO_INT(IntNo) D(((long)(IntNo)*4+0x60)) +#var DisableAutoInt3() D((pokeIO_bclr(0x600015,2))) +#var DUMMY_HANDLER D(((INT_HANDLER)(__dummy_handler__))) +#var __dummy_handler__ void __dummy_handler__(); +#var EnableAutoInt3() D((pokeIO_bset(0x600015,2))) +#var ExecuteHandler void _(INT_HANDLER h)__ATTR_TIOS__;asm{ExecuteHandler:move.l 4(a7),a0;move.w sr,-(a7);jmp (a0)}; +#var GetIntVec(i) D((*(INT_HANDLER*)(i))) +#var SetIntVec(i,h) D(((void)(pokeIO_bclr(0x600001,2),*(INT_HANDLER*)(i)=(h),pokeIO_bset(0x600001,2)))) +#var TRAP(TrapNo) D(((long)(TrapNo)*4+0x80)) +#var DEFINE_INT_HANDLER(name) D(extern _DEREF_INT_HANDLER name[]; asm{name: move.w #0x2700,sr;movem.l d0-d7/a0-a6,-(sp);move.l 0xC8,a5;jsr __##name##_body__;movem.l (sp)+,d0-d7/a0-a6;rte}; void __##name##_body__(void)) + diff --git a/pch/src/kbd.pchsource b/pch/src/kbd.pchsource new file mode 100644 index 0000000..881c7ac --- /dev/null +++ b/pch/src/kbd.pchsource @@ -0,0 +1,66 @@ +#var __keytest(row,col) D((!!(_rowread_inverted(1<<(row))&(1<<(col))))) + +#var __keytest_optimized(row,col) D((!!((__current_row==row?__current_rowread_result:(__current_row=row,__current_rowread_result=_rowread_inverted(1<<(row))))&(1<<(col))))) + + +#var NULL D(((void*)0)) +#var ARROW_UP D(1) +#var ARROW_LEFT D(2) +#var ARROW_DOWN D(3) +#var ARROW_RIGHT D(4) + +#var FALSE D(0) +#var TRUE D(1) + +#var KEY_F1 D(268) +#var KEY_F2 D(269) +#var KEY_F3 D(270) +#var KEY_F4 D(271) +#var KEY_F5 D(272) +#var KEY_F6 D(273) +#var KEY_F7 D(274) +#var KEY_F8 D(275) +#var KEY_ESC D(264) +#var KEY_QUIT D(4360) +#var KEY_APPS D(265) +#var KEY_SWITCH D(4361) +#var KEY_MODE D(266) +#var KEY_BACKSPACE D(257) +#var KEY_INS D(4353) +#var KEY_CLEAR D(263) +#var KEY_VARLNK D(4141) +#var KEY_CHAR D(4139) +#var KEY_ENTER D(13) +#var KEY_ENTRY D(4109) +#var KEY_STO D(258) +#var KEY_RCL D(4354) +#var KEY_SIGN D(173) +#var KEY_MATH D(4149) +#var KEY_MEM D(4150) +#var KEY_ON D(267) +#var KEY_OFF D(4363) + +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var STAT_2ND D(1) +#var STAT_DIAMOND D(2) +#var STAT_SHIFT D(3) +#var STAT_HAND D(4) + +#var OSFastArrows D((*(AMS_1xx?((unsigned char*)(unsigned long)(*((unsigned short*)(_rom_call_addr(51))+0x80))):((unsigned char*)(_rom_call_addr(15C)))))) +#var _keytest(rowcol...) D((__keytest(rowcol))) +#var _keytest_optimized(rowcol...) D((__keytest_optimized(rowcol))) +#var _rowread unsigned short _rowread(short)__ATTR_LIB_ASM__; +#var _rowread_internal(row) D((~(_rowread(row)))) +#var _rowread_inverted(row) D((_rowread(~((short)(row))))) +#var GKeyDown D(_rom_call(short,(void),17F)) +#var GKeyFlush D(_rom_call(void,(void),180)) +#var GKeyIn D(_rom_call(short,(SCR_RECT*,short),17E)) +#var kbhit D(_rom_call(short,(void),52)) +#var ngetchx D(_rom_call(short,(void),51)) +#var OSGetStatKeys D(_rom_call(short,(void),299)) +#var OSInitBetweenKeyDelay(rate) D(({short __oldRate=_OSInitBetweenKeyDelay(48);(__oldRate*48-1)/_OSInitBetweenKeyDelay((rate))+1;})) +#var _OSInitBetweenKeyDelay D(_rom_call(short,(short),249)) +#var OSInitKeyInitDelay D(_rom_call(short,(short),248)) +#var pushkey D(_rom_call(void,(short),50)) +#var BEGIN_KEYTEST D({register short __current_row=RR_NO_KEY;register unsigned short __current_rowread_result=0;) +#var END_KEYTEST D(}) diff --git a/pch/src/keywords.pchsource b/pch/src/keywords.pchsource new file mode 100644 index 0000000..599c33f --- /dev/null +++ b/pch/src/keywords.pchsource @@ -0,0 +1,42 @@ +#var #define +#var #undef +#var #macro +#var #endm +#var #include +#var #pragma +#var #pragma.lang +#var #if +#var #ifndef +#var #ifdef +#var #endif +#var #elif +#var #else +#var defined +#var void +#var short +#var int +#var char +#var long +#var unsigned +#var const +#var extern +#var volatile +#var static +#var struct +#var union +#var asm +#var incbin +#var sizeof +#var typedef +#var typedef.struct +#var return +#var break +#var continue +#var goto +#var case +#var default +#var switch +#var __attribute__ +#var regparm +#var stkparm +#var alloca diff --git a/pch/src/lex.txt b/pch/src/lex.txt new file mode 100644 index 0000000..7b555fc --- /dev/null +++ b/pch/src/lex.txt @@ -0,0 +1,74 @@ + *) +*) +*, +int x +int y +int z +int a +int b +int c +register +unsigned +signed +volatile +void _( +int _( +short _( +BOOL _( +long _( + *_( +*_( +const +void,( +char,( +int,( +short,( +long,( +float,( +void +char +int +short +long +float +typedef struct +typedef +Gray +_RR( +,15 +,( +), +({ +}) +_rom_call( +_rom_call_addr( +FILE* +__ATTR_LIB_ASM__ +__ATTR_LIB_C__ +__ATTR_TIOS__ +__ATTR_ + __ +__ + * +0x +0xFFF +CALCULATOR +SCR_RECT +WIN_RECT +@@move +move +.l +.w +.b +999 +_rowread +__gray_ +HANDLE +HSym +SYM_ENTRY +SYM_STR +ESI +c>= +c<= +c== +addr \ No newline at end of file diff --git a/pch/src/limits.pchsource b/pch/src/limits.pchsource new file mode 100644 index 0000000..1989d3f --- /dev/null +++ b/pch/src/limits.pchsource @@ -0,0 +1,18 @@ +#var CHAR_MAX D(255) +#var CHAR_MIN D(0) + +#var INT_MAX D(0x7FFF) +#var INT_MIN D(((int)0x8000)) +#var UINT_MAX D(0xFFFFU) + +#var CHAR_BIT D(8) +#var LONG_MAX D(0x7FFFFFFFL) +#var LONG_MIN D(((long)0x80000000L)) +#var SCHAR_MAX D(127) +#var SCHAR_MIN D((-128)) +#var SHRT_MAX D(0x7FFF) +#var SHRT_MIN D(((short)0x8000)) +#var UCHAR_MAX D(255) +#var ULONG_MAX D(0xFFFFFFFFUL) +#var USHRT_MAX D(0xFFFFU) + diff --git a/pch/src/link.pchsource b/pch/src/link.pchsource new file mode 100644 index 0000000..e427943 --- /dev/null +++ b/pch/src/link.pchsource @@ -0,0 +1,36 @@ + +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var ESI typedef ESQ*ESI; +#var LIO_CTX typedef struct{unsigned short hVar;union{const void*pVar;struct{unsigned short FindFlags;unsigned short NameSym;}DirVars;}extra;const char*VarName;unsigned short VarSize;unsigned short Index;unsigned short Unknown;unsigned char VarType;unsigned char VarCompat;}LIO_CTX; +#var size_t typedef unsigned long size_t; +#var SYM_STR typedef CESI SYM_STR; +#var flush_link D(_rom_call(void,(void),24D)) +#var getcalc D(_rom_call(void,(SYM_STR),54)) +#var LIO_Get D(_rom_call(unsigned short,(LIO_CTX*),57)) +#var LIO_GetMultiple D(_rom_call(short,(LIO_CTX*),59)) +#var LIO_Receive D(_rom_call(unsigned short,(LIO_CTX*,short,short),58)) +#var LIO_RecvData D(_rom_call(unsigned short,(void*,long,long),5B)) +#var LIO_Send D(_rom_call(unsigned short,(LIO_CTX*,short),56)) +#var LIO_SendData D(_rom_call(unsigned short,(const void*,long),5A)) +#var LIO_SendProduct D(_rom_call(unsigned short,(LIO_CTX*,short),253)) +#var OSCheckSilentLink D(_rom_call(short,(void),24A)) +#var OSLinkClose D(_rom_call(void,(void),24E)) +#var OSLinkCmd D(_rom_call(void,(short),24B)) +#var OSLinkOpen D(_rom_call(void,(void),24D)) +#var OSLinkReset D(_rom_call(void,(void),24C)) +#var OSLinkTxQueueActive D(_rom_call(short,(void),252)) +#var OSLinkTxQueueInquire D(_rom_call(unsigned short,(void),251)) +#var OSReadLinkBlock D(_rom_call(unsigned short,(char*,short),24F)) +#var OSWriteLinkBlock D(_rom_call(short,(const char*,short),250)) +#var receive D(_rom_call(unsigned short,(char*,short),24F)) +#var reset_link D(_rom_call(void,(void),24C)) +#var sendcalc D(_rom_call(unsigned short,(SYM_STR,short,short,unsigned char*),55)) +#var transmit D(_rom_call(short,(const char*,short),250)) +#var tx_free D(_rom_call(unsigned short,(void),252)) + + diff --git a/pch/src/math.pchsource b/pch/src/math.pchsource new file mode 100644 index 0000000..d015b9b --- /dev/null +++ b/pch/src/math.pchsource @@ -0,0 +1,67 @@ + +#var HALF_PI D((1.570796326794897)) +#var NAN D((*(float*)&(bcd){0x7FFF,0xAA00000000000000})) +#var NEGATIVE_INF D((*(float*)&(bcd){0xFFFF,0xAA00BB0000000000})) +#var NEGATIVE_ZERO D((*(float*)&(bcd){0x8000,0})) +#var PI D((3.141592653589793)) +#var POSITIVE_INF D((*(float*)&(bcd){0x7FFF,0xAA00BB0000000000})) +#var POSITIVE_ZERO D((*(float*)&(bcd){0,0})) +#var UNSIGNED_INF D((*(float*)&(bcd){0x7FFF,0xAA00CC0000000000})) +#var UNSIGNED_ZERO D((0.0)) +#var ZERO D((0.0)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var FALSE D(0) +#var TRUE D(1) + +#var abs(x) D(({typeof(x) __x = (x); __x >= 0 ? __x : -__x;})) +#var acos(x) D(_tios_float_1(F5,x,float)) +#var acosh(x) D(_tios_float_1(288,x,float)) +#var asin(x) D(_tios_float_1(F6,x,float)) +#var asinh(x) D(_tios_float_1(287,x,float)) +#var atan2(x,y) D(_tios_float_2(F8,x,y,float,float)) +#var atan(x) D(_tios_float_1(F7,x,float)) +#var atanh(x) D(_tios_float_1(289,x,float)) +#var cacos D(_rom_call(void,(float,float,float*,float*),13A)) +#var cacosh D(_rom_call(void,(float,float,float*,float*),13D)) +#var casin D(_rom_call(void,(float,float,float*,float*),13B)) +#var casinh D(_rom_call(void,(float,float,float*,float*),13E)) +#var catan D(_rom_call(void,(float,float,float*,float*),13C)) +#var catanh D(_rom_call(void,(float,float,float*,float*),13F)) +#var ccos D(_rom_call(void,(float,float,float*,float*),140)) +#var ccosh D(_rom_call(void,(float,float,float*,float*),143)) +#var ceil(x) D(_tios_float_1(105,x,float)) +#var cexp D(_rom_call(void,(float,float,float*,float*),149)) +#var cln D(_rom_call(void,(float,float,float*,float*),147)) +#var clog10 D(_rom_call(void,(float,float,float*,float*),148)) +#var cos(x) D(_tios_float_1(F9,x,float)) +#var cosh(x) D(_tios_float_1(FC,x,float)) +#var csin D(_rom_call(void,(float,float,float*,float*),141)) +#var csinh D(_rom_call(void,(float,float,float*,float*),144)) +#var csqrt D(_rom_call(void,(float,float,float*,float*),146)) +#var ctan D(_rom_call(void,(float,float,float*,float*),142)) +#var ctanh D(_rom_call(void,(float,float,float*,float*),145)) +#var exp(x) D(_tios_float_1(FF,x,float)) +#var fabs(x) D(_tios_float_1(106,x,float)) +#var floor(x) D(_tios_float_1(107,x,float)) +#var fmod(x,y) D(_tios_float_2(108,x,y,float,float)) +#var hypot(x,y) D(({float __x=(x),__y=(y);sqrt(fadd(fmul((__x),(__x)),fmul((__y),(__y))));})) +#var ldexp10(x,e) D(({float __f=x;((bcd*)&__f)->exponent+=e;__f;})) +#var log(x) D(_tios_float_1(100,x,float)) +#var log10(x) D(_tios_float_1(101,x,float)) +#var modf(x,y) D(_tios_float_2(102,x,y,float,float*)) +#var pow(x,y) D(_tios_float_2(103,x,y,float,float)) +#var sin(x) D(_tios_float_1(FA,x,float)) +#var sinh(x) D(_tios_float_1(FD,x,float)) +#var sqrt(x) D(_tios_float_1(104,x,float)) +#var tan(x) D(_tios_float_1(FB,x,float)) +#var tanh(x) D(_tios_float_1(FE,x,float)) +#var atof float atof(const char*)__ATTR_LIB_ASM__; +#var frexp10(x,y) D(_tios_float_2(2FB,x,y,float,__pshort)) +#var is_inf D(_rom_call(short,(float),2FF)) +#var is_nan D(_rom_call(short,(float),306)) +#var is_nzero D(_rom_call(short,(float),300)) +#var is_pzero D(_rom_call(short,(float),301)) +#var is_sinf D(_rom_call(short,(float),302)) +#var is_transfinite D(_rom_call(short,(float),303)) +#var is_uinf_or_nan D(_rom_call(short,(float),304)) +#var is_uzero D(_rom_call(short,(float),305)) diff --git a/pch/src/mem.pchsource b/pch/src/mem.pchsource new file mode 100644 index 0000000..ce6a5dd --- /dev/null +++ b/pch/src/mem.pchsource @@ -0,0 +1,9 @@ + +#var NULL D(((void*)0)) +#var size_t typedef unsigned long size_t; +#var _memset D(_rom_call(void*,(void*,short,long),27B)) +#var memchr D(_rom_call(void*,(const void*,short,long),273)) +#var memcmp D(_rom_call(short,(const void*,const void*,long),270)) +#var memcpy D(_rom_call(void*,(void*,const void*,long),26A)) +#var memmove D(_rom_call(void*,(void*,const void*,long),26B)) +#var memset D(_rom_call(void*,(void*,short,long),27C)) diff --git a/pch/src/menus.pchsource b/pch/src/menus.pchsource new file mode 100644 index 0000000..ac39eba --- /dev/null +++ b/pch/src/menus.pchsource @@ -0,0 +1,105 @@ +#var CENTER D((-1)) +#var H_NULL D(0) +#var NULL D(((void*)0)) +#var BITMAP typedef struct{unsigned short NumRows,NumCols;unsigned char Data[];}BITMAP; +#var FALSE D(0) +#var TRUE D(1) + +#var KEY_F1 D(268) +#var KEY_F2 D(269) +#var KEY_F3 D(270) +#var KEY_F4 D(271) +#var KEY_F5 D(272) +#var KEY_F6 D(273) +#var KEY_F7 D(274) +#var KEY_F8 D(275) +#var KEY_ESC D(264) +#var KEY_QUIT D(4360) +#var KEY_APPS D(265) +#var KEY_SWITCH D(4361) +#var KEY_MODE D(266) +#var KEY_BACKSPACE D(257) +#var KEY_INS D(4353) +#var KEY_CLEAR D(263) +#var KEY_VARLNK D(4141) +#var KEY_CHAR D(4139) +#var KEY_ENTER D(13) +#var KEY_ENTRY D(4109) +#var KEY_STO D(258) +#var KEY_RCL D(4354) +#var KEY_SIGN D(173) +#var KEY_MATH D(4149) +#var KEY_MEM D(4150) +#var KEY_ON D(267) +#var KEY_OFF D(4363) + +#var DMF_TEXT D(1) +#var DMF_ICON D(2) +#var DMF_BITMAP D(4) +#var DMF_CHILD_SUB D(4096) +#var DMF_CHILD D(8192) +#var DMF_TOP_SUB D(16384) +#var DMF_TOP D(-32768) + +#var HANDLE typedef unsigned short HANDLE; +#var ICON typedef struct{unsigned short i[16];}ICON; +#var MT_TEXT D(-32768) +#var MT_XREF D(-28672) +#var MT_ICON D(-24576) +#var MT_CASCADE D(16384) + +#var MBF_WITHICON D(1) +#var MBF_REDEF D(2) +#var MBF_SYS_ALLOC D(4) +#var MBF_MAX_MENU_WIDTH D(8) +#var MBF_STRIKEOUT D(16) +#var MBF_HMENU D(32) +#var MBF_NO_DRAWTOP D(64) + +#var MC_CHECK D(0) +#var MC_UNCHECK D(1) +#var MC_STATUS D(2) +#var MC_FLIP D(3) + +#var MF_POPUP D(1) +#var MF_TOOLBOX D(2) +#var MF_NONSEQ D(4) +#var MF_ICON_TITLE D(8) +#var MF_TEXT_TITLE D(16) +#var MF_NO_NUMS D(32) +#var MF_NO_UNAMED D(64) +#var MF_DYN_POPUP D(128) +#var MF_ALT_ICONS D(256) +#var MF_BITMAP_TITLE D(512) +#var MF_ERROR D(2048) +#var MF_ICONS_OVERLAP D(4096) +#var MF_TITLE D(536) + +#var M_NOITEM D(0) +#var M_NOTMENUKEY D(-2) + +#var pICON typedef unsigned short*pICON; +#var VCFP_ALL D(1) +#var VCFP_SKIP_CURDIR D(2) + +#var MenuAddIcon D(_rom_call(HANDLE,(HANDLE,short,const void*,short,short),42)) +#var MenuAddText D(_rom_call(HANDLE,(HANDLE,short,const char*,short,short),41)) +#var MenuBegin D(_rom_call(HANDLE,(const void*,short,short,short,...),36)) +#var MenuCheck D(_rom_call(short,(HANDLE,short,short),37)) +#var MenuEnd D(_rom_call(void,(HANDLE),38)) +#var MenuGetTopRedef D(_rom_call(short,(HANDLE,short),40)) +#var MenuKey D(_rom_call(short,(HANDLE,short),39)) +#var MenuNew D(_rom_call(HANDLE,(short,short,short),43)) +#var MenuOn D(_rom_call(void,(HANDLE),3A)) +#var MenuPopup D(_rom_call(unsigned short,(const void*,short,short,short),3B)) +#var MenuSubStat D(_rom_call(void,(HANDLE,short,short),3C)) +#var MenuTopRedef D(_rom_call(void,(HANDLE,short,short),3F)) +#var MenuTopSelect D(_rom_call(void,(HANDLE,short),3E)) +#var MenuTopStat D(_rom_call(void,(HANDLE,short,short),3D)) +#var MenuUpdate D(_rom_call(void,(void),49)) +#var PopupAddText D(_rom_call(HANDLE,(HANDLE,short,const char*,short),44)) +#var PopupClear D(_rom_call(HANDLE,(HANDLE),46)) +#var PopupDo D(_rom_call(short,(HANDLE,short,short,short),47)) +#var PopupNew D(_rom_call(HANDLE,(const char*,short),45)) +#var PopupText D(_rom_call(const char*,(HANDLE,short),48)) +#var VarCreateFolderPopup D(_rom_call(HANDLE,(__pushort,short),28F)) diff --git a/pch/src/pchlog.pchsource b/pch/src/pchlog.pchsource new file mode 100644 index 0000000..245b297 --- /dev/null +++ b/pch/src/pchlog.pchsource @@ -0,0 +1,236 @@ +DialogAdd(h,0,x,y,3)w)g)f)t)p)u)m) +(-1) +0 +((0) +0 +1 +0 +1 +2 +3 +4 +5 +6 + + + + + + + +,,p30) +,,,,,...33) +DialogAdd(h,2,x,y,14(t()(p()(i)) +DialogAdd(h,0,x,y,2(t()(o()(m()(w)) +DialogAdd(h,0,x,y,7(t)) +DialogAdd(h,0,0,0,8(t()(l()(r)) +,,,p32) +,,DialogNew_t34) +DialogNew(w,h,NoCallBack) +,1B4) + +ESQ...28E) +ESQ...28C) +ESQ...28D) +(-1) +0 +((0) + +0 +1 +268 +269 +270 +271 +272 +273 +274 +275 +264 +4360 +265 +4361 +266 +257 +4353 +263 +4141 +4139 +13 +4109 +258 +4354 +173 +4149 +4150 +267 +4363 +1 +2 +4 +4096 +8192 +16384 +-32768 + + +-32768 +-28672 +-24576 +16384 +1 +2 +4 +8 +16 +32 +64 +0 +1 +2 +3 +1 +2 +4 +8 +16 +32 +64 +128 +256 +512 +2048 +4096 +536 +0 +-2 + +1 +2 +,,,42) +,,,41) +,,,...36) +,,37) +38) +,40) +,39) +,,43) +3A) +,,3B) +,,3C) +,,3F) +,3E) +,,3D) +49) +,,44) +46) +,,,47) +45) +(,48) +pu,28F) +4 +((0) +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 + +0 +1 +16 +32 +64 +128 +0 +1 +2 +3 +4 +5 +6 +0 +1 +2 + + + + + + + + + +1 +2 +4 +8 +16 +32 +64 +128 +256 +512 +1024 +2048 +4096 +8192 +16400 +-32768 +((WINDOW*const)((((0)))+1)) +(*((WINDOW*(0)))) +WINDOW,35) +WINDOW,27) +(,,,2C) +(,2A) +(,29) +WINDOW,1) +WINDOW2) +WINDOW4) +WINDOW,3) +WINDOW,5) +WINDOW,6) +WINDOW,,7) +WINDOW,8) +WINDOWA) +WINDOW,,,9) +WINDOW,B) +WINDOW,C) +WINDOW,D) +WINDOWE) +WINDOW,,,F) +(()0) +WINDOW10) +WINDOW11) +WINDOW,,,,,,12) +WINDOW13) +WINDOWp,p14) +WINDOW,292) +WINDOW) +WINDOW,16) +WINDOW,17) +WINDOW,18) +WINDOW,1A) +WINDOW,19) +WINDOW,1B) +WINDOW,1D) +WINDOW,1C) +WINDOW,...1E) +WINDOW,1F) +WINDOW,20) +WINDOW21) +WINDOW,...22) +WINDOW23) +WINDOW24) +()((w)->CursorX=xw)->CursorY=y) +()((w)->Flags|=WF_VISIBLE) +WINDOW,25) +WINDOW,,,26) +WINDOW,291) diff --git a/pch/src/peekpoke.pchsource b/pch/src/peekpoke.pchsource new file mode 100644 index 0000000..5862830 --- /dev/null +++ b/pch/src/peekpoke.pchsource @@ -0,0 +1,21 @@ + +#var peek(addr) D((*((unsigned char*)(long)(addr)))) +#var peek_bit(addr,bit) D((!!(*((unsigned char*)(long)(addr))&(1<<(bit))))) +#var peek_l(addr) D((*((unsigned long*)(long)(addr)))) +#var peek_w(addr) D((*((unsigned short*)(long)(addr)))) +#var peekIO(port) D((*((volatile unsigned char*)(long)(port)))) +#var peekIO_bit(port,bit) D((!!(*((volatile unsigned char*)(long)(port))&(1<<(bit))))) +#var peekIO_w(port) D((*((volatile unsigned short*)(long)(port)))) +#var poke(addr,val) D((void)(*((unsigned char*)(long)(addr))=(val))) +#var poke_bclr(addr,bit) D((void)(*(unsigned char *)(addr)&=~(1<<(bit)))) +#var poke_bset(addr,bit) D((void)(*(unsigned char *)(addr)|=(1<<(bit)))) +#var poke_l(addr,val) D((void)(*((unsigned long*)(long)(addr))=(val))) +#var poke_w(addr,val) D((void)(*((unsigned short*)(long)(addr))=(val))) +#var pokeIO(port,val) D((void)(*((volatile unsigned char*)(long)(port))=(val))) +#var pokeIO_bclr(addr,bit) D((void)(*(volatile unsigned char *)(addr)&=~(1<<(bit)))) +#var pokeIO_bset(addr,bit) D((void)(*(volatile unsigned char *)(addr)|=(1<<(bit)))) +#var pokeIO_w(port,val) D((void)(*((volatile unsigned short*)(long)(port))=(val))) +#var speek(addr) D((*((signed char*)(long)(addr)))) +#var speek_l(addr) D((*((signed long*)(long)(addr)))) +#var speek_w(addr) D((*((signed short*)(long)(addr)))) + diff --git a/pch/src/rsa.pchsource b/pch/src/rsa.pchsource new file mode 100644 index 0000000..fa18da9 --- /dev/null +++ b/pch/src/rsa.pchsource @@ -0,0 +1,12 @@ + +#var BN typedef struct{unsigned char Len;unsigned char Data[];}BN; +#var MD5_CTX typedef struct{unsigned long state[4];unsigned long count[2];unsigned char buffer[64];}MD5_CTX; +#var BN_power17Mod D(_rom_call(void,(BN*,const BN*,const BN*),122)) +#var BN_powerMod D(_rom_call(void,(BN*,const BN*,const BN*,const BN*),123)) +#var BN_prodMod D(_rom_call(void,(BN*,const BN*,const BN*),124)) +#var cdecrypt D(_rom_call(void,(BN*,char*,long,BN*),127)) +#var MD5Done D(_rom_call(void,(BN*,MD5_CTX*),257)) +#var MD5Final D(_rom_call(void,(unsigned char*,MD5_CTX*),256)) +#var MD5Init D(_rom_call(void,(MD5_CTX*),254)) +#var MD5Update D(_rom_call(void,(MD5_CTX*,unsigned char*,short),255)) + diff --git a/pch/src/setjmp.pchsource b/pch/src/setjmp.pchsource new file mode 100644 index 0000000..729d08d --- /dev/null +++ b/pch/src/setjmp.pchsource @@ -0,0 +1,5 @@ + +#var JMP_BUF typedef struct{unsigned long D2,D3,D4,D5,D6,D7;unsigned long A2,A3,A4,A5,A6,A7;unsigned long PC;}JMP_BUF[1]; +#var longjmp D(_rom_call(void,(void*,short),267)) +#var setjmp D(_rom_call(short,(void*),266)) +#var jmp_buf D(JMP_BUF) diff --git a/pch/src/sprites.pchsource b/pch/src/sprites.pchsource new file mode 100644 index 0000000..fee6b53 --- /dev/null +++ b/pch/src/sprites.pchsource @@ -0,0 +1,9 @@ + +#var SPRT_XOR D(0) +#var SPRT_OR D(1) +#var SPRT_AND D(2) + +#var Sprite8 void Sprite8(short,short,short,unsigned char*,void*,short)__ATTR_LIB_C__; +#var Sprite16 void Sprite16(short,short,short,__pushort,void*,short)__ATTR_LIB_C__; +#var Sprite32 void Sprite32(short,short,short,__pulong,void*,short)__ATTR_LIB_C__; + diff --git a/pch/src/statline-vle.pchsource b/pch/src/statline-vle.pchsource new file mode 100644 index 0000000..6a54fde --- /dev/null +++ b/pch/src/statline-vle.pchsource @@ -0,0 +1,15 @@ + +#var FALSE D(0) +#var TRUE D(1) + +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; + +#var WIN_RECT typedef struct{short x0,y0,x1,y1;}WIN_RECT; +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var ST_busy D(_rom_call(void,(short),E2)) +#var ST_eraseHelp D(_rom_call(short,(void),E3)) +#var ST_folder D(_rom_call(void,(const char*),E4)) +#var ST_helpMsg D(_rom_call(void,(const char*),E6)) +#var ST_refDsp D(_rom_call(void,(short),EB)) +#var ST_showHelp D(_rom_call(void,(const char*),E6)) diff --git a/pch/src/statline.pchsource b/pch/src/statline.pchsource new file mode 100644 index 0000000..8cba281 --- /dev/null +++ b/pch/src/statline.pchsource @@ -0,0 +1,56 @@ + +#var FALSE D(0) +#var TRUE D(1) + +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var ACTIVITY_IDLE D(0) +#var ACTIVITY_BUSY D(1) +#var ACTIVITY_PAUSED D(2) +#var ACTIVITY_NORMAL D(3) + +#var ST_IDLE D(0) +#var ST_BUSY D(1) +#var ST_PAUSE D(2) +#var ST_CLEAR D(3) +#var ST_NORMAL D(3) +#var ST_NOTHING D(0) +#var ST_BATT D(1) +#var ST_BATT_DARK D(2) +#var ST_BATT_OK D(0) +#var ST_BATT_LOW D(1) +#var ST_BATT_REPLACE D(2) +#var ST_RAD D(0) +#var ST_DEG D(1) +#var ST_FUNC D(0) +#var ST_PAR D(2) +#var ST_POL D(3) +#var ST_SEQ D(4) +#var ST_3D D(5) +#var ST_DE D(6) +#var ST_NONE D(0) +#var ST_2ND D(1) +#var ST_SHIFT D(2) +#var ST_DIAMOND D(4) +#var ST_ALPHA D(8) +#var ST_SH_A_LOCK D(16) +#var ST_A_LOCK D(32) +#var ST_AUTO D(0) +#var ST_EXACT D(1) +#var ST_APPROX D(2) + +#var WIN_RECT typedef struct{short x0,y0,x1,y1;}WIN_RECT; +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var ST_angle D(_rom_call(void,(short),E0)) +#var ST_batt D(_rom_call(void,(short),E1)) +#var ST_busy D(_rom_call(void,(short),E2)) +#var ST_eraseHelp D(_rom_call(short,(void),E3)) +#var ST_folder D(_rom_call(void,(const char*),E4)) +#var ST_graph D(_rom_call(void,(short),E5)) +#var ST_helpMsg D(_rom_call(void,(const char*),E6)) +#var ST_modKey D(_rom_call(void,(short),E7)) +#var ST_precision D(_rom_call(void,(short),E8)) +#var ST_readOnly D(_rom_call(void,(short),E9)) +#var ST_refDsp D(_rom_call(void,(short),EB)) +#var ST_showHelp D(_rom_call(void,(const char*),E6)) +#var ST_stack D(_rom_call(void,(short,short),EA)) diff --git a/pch/src/stdarg.pchsource b/pch/src/stdarg.pchsource new file mode 100644 index 0000000..d5ba350 --- /dev/null +++ b/pch/src/stdarg.pchsource @@ -0,0 +1,6 @@ + +#var va_list typedef void*va_list; +#var va_arg(ap,type) D((*(type*)(((*(char**)&(ap))+=((sizeof(type)+1)&0xFFFE))-(((sizeof(type)+1)&0xFFFE))))) +#var va_end(ap) D(((void)0)) +#var va_start(ap,parmN) D(((void)((ap)=(va_list)((char*)(&parmN)+((sizeof(parmN)+1)&0xFFFE))))) + diff --git a/pch/src/stdhead-ams2.pchmerge b/pch/src/stdhead-ams2.pchmerge new file mode 100644 index 0000000..11c9cc8 --- /dev/null +++ b/pch/src/stdhead-ams2.pchmerge @@ -0,0 +1,6 @@ +ams2.pchsource + +ams2-basfunc.pchsource +ams2-basop.pchsource +ams2-kbd.pchsource +ams2-menus.pchsource diff --git a/pch/src/stdhead-light.pchmerge b/pch/src/stdhead-light.pchmerge new file mode 100644 index 0000000..f7d7935 --- /dev/null +++ b/pch/src/stdhead-light.pchmerge @@ -0,0 +1,31 @@ +stdhead.pchsource + +compiler-internals.pchsource +alloc.pchsource +args-le.pchsource +asmtypes.pchsource +assert.pchsource +compat-x.pchsource +ctype.pchsource +error-le.pchsource +flash.pchsource +float.pchsource +graph.pchsource +gray.pchsource +intr.pchsource +kbd.pchsource +limits.pchsource +link.pchsource +mem.pchsource +peekpoke.pchsource +setjmp.pchsource +sprites.pchsource +statline-vle.pchsource +stdarg.pchsource +stdio.pchsource +stdlib.pchsource +string.pchsource +system.pchsource +values.pchsource +vat-le.pchsource +version.pchsource diff --git a/pch/src/stdhead.pchmerge b/pch/src/stdhead.pchmerge new file mode 100644 index 0000000..6435eb6 --- /dev/null +++ b/pch/src/stdhead.pchmerge @@ -0,0 +1,41 @@ +stdhead.pchsource + +compiler-internals.pchsource +gtc.pchsource +alloc.pchsource +args-le.pchsource +asmtypes.pchsource +assert.pchsource +cert.pchsource +compat-x.pchsource +ctype.pchsource +dialogs.pchsource +dll.pchsource +error-le.pchsource +events.pchsource +flash.pchsource +float.pchsource +gdraw.pchsource +graph.pchsource +gray.pchsource +homescr.pchsource +intr.pchsource +kbd.pchsource +limits.pchsource +link.pchsource +mem.pchsource +peekpoke.pchsource +rsa.pchsource +setjmp.pchsource +sprites.pchsource +statline.pchsource +stdarg.pchsource +stdio.pchsource +stdlib.pchsource +string.pchsource +system.pchsource +textedit.pchsource +values.pchsource +vat-le.pchsource +version.pchsource +wingraph.pchsource diff --git a/pch/src/stdio.pchsource b/pch/src/stdio.pchsource new file mode 100644 index 0000000..7fbbe7f --- /dev/null +++ b/pch/src/stdio.pchsource @@ -0,0 +1,69 @@ +#var vcbprintf_callback_t typedef void(*vcbprintf_callback_t)(char,void**)__ATTR_TIOS_CALLBACK__; +#var __vcbprintf__type__ typedef void(*__vcbprintf__type__)(vcbprintf_callback_t,void**,const char*,void*)__ATTR_TIOS__; + + +#var EOF D((-1)) +#var NULL D(((void*)0)) +#var TMP_MAX D(152587890625) +#var FILE typedef struct{char*fpos;void*base;unsigned short handle;short flags;short unget;unsigned long alloc;unsigned short buffincrement;}FILE; +#var _F_READ D(1) +#var _F_WRIT D(2) +#var _F_RDWR D(3) +#var _F_ERR D(16) +#var _F_EOF D(32) +#var _F_BIN D(64) + +#var fpos_t typedef unsigned long fpos_t; +#var SEEK_SET D(0) +#var SEEK_CUR D(1) +#var SEEK_END D(2) + +#var size_t typedef unsigned long size_t; +#var va_list typedef void*va_list; +#var vcbprintf_Callback_t D(vcbprintf_callback_t) +#var clearerr(f) D(((void)(((f)->flags)&=~(_F_EOF|_F_ERR)))) +#var clrscr void clrscr(void)__ATTR_LIB_ASM__; +#var fclose short fclose(FILE*)__ATTR_LIB_C__; +#var feof(f) D((((f)->flags)&_F_EOF)) +#var ferror(f) D((((f)->flags)&_F_ERR)) +#var fflush(f) D(((f)->unget=0)) +#var fgetc short fgetc(FILE*)__ATTR_LIB_C__; +#var fgetchar() D(({register short __c=_rom_call(short,(void),51)();fputchar((__c=='\r')?'\n':__c);})) +#var fgetpos(f,p) D(((*(p)=ftell(f))==EOF)) +#var fgets char *fgets(char*,short,FILE*)__ATTR_LIB_C__; +#var fopen FILE *fopen(const char*,const char*)__ATTR_LIB_C__; +#var fprintf short fprintf(FILE*,const char*,...)__ATTR_TIOS__; +#var fputc short fputc(short,FILE*)__ATTR_TIOS_CALLBACK__; +#var fputchar short fputchar(short)__ATTR_TIOS_CALLBACK__; +#var fputs short fputs(const char*,FILE*)__ATTR_LIB_ASM__; +#var fread unsigned short fread(void*,short,short,FILE*)__ATTR_LIB_C__; +#var freopen(n,m,f) D((fclose(f),(f)=fopen((n),(m)),(f))) +#var fseek short fseek(FILE*,long,short)__ATTR_LIB_C__; +#var fsetbufsize void fsetbufsize(short,FILE*)__ATTR_LIB_C__; +#var fsetpos(f,p) D(fseek((f),*(p),SEEK_SET)) +#var ftell long ftell(const FILE*)__ATTR_LIB_C__; +#var fwrite unsigned short fwrite(const void*,short,short,FILE*)__ATTR_LIB_C__; +#var getc D(fgetc) +#var getchar D(fgetchar) +#var gets(s) D(({register short __c;register char*__p=s;while((*__p++=fputchar(((__c=_rom_call(short,(void),51)())=='\r')?'\n':__c))!='\n');__p[-1]=0;s;})) +#var printf void printf(const char*,...)__ATTR_TIOS__; +#var printf_xy(x,y,f...) D(({char __s[200];_rom_call(short,(char*,const char*,...),53)(__s ,##f);_rom_call(void,(short,short,const char*,short),1A9)(x,y,__s,4);})) +#var putc D(fputc) +#var putchar D(fputchar) +#var puts void puts(const char*)__ATTR_LIB_ASM__; +#var remove D(unlink) +#var rename short rename(const char*,const char*)__ATTR_LIB_C__; +#var rewind(f) D(((void)(fseek((f),0,SEEK_SET),(f)->flags&=~_F_ERR))) +#var sprintf D(_rom_call(short,(char*,const char*,...),53)) +#var strerror D(_rom_call(char*,(short),27D)) +#var strputchar void strputchar(char,void**)__ATTR_TIOS_CALLBACK__; +#var tmpnam char *tmpnam(char*)__ATTR_LIB_C__; +#var ungetc(c,f) D(((f)->unget=((c)|0x8000))) +#var unlink short unlink(const char*)__ATTR_LIB_C__; +#var vcbprintf D(({register long __a=32+(long)(_rom_call_addr(53));(__vcbprintf__type__)(__a+*(short*)__a);})) +#var vfprintf(s,f,a) D(vcbprintf((vcbprintf_callback_t)fputc,(void**)(s),(f),(a))) +#var vprintf(f,a) D(vcbprintf((vcbprintf_callback_t)fputchar,NULL,(f),(a))) +#var vsprintf(b,f,a) D(((void)({void*__p=(b);vcbprintf((vcbprintf_callback_t)strputchar,&__p,(f),(a));*(char*)__p=0;}))) + + +#var __FERROR(f) D(({(f)->flags|=_F_ERR; return EOF;})) diff --git a/pch/src/stdlib.pchsource b/pch/src/stdlib.pchsource new file mode 100644 index 0000000..a162bc6 --- /dev/null +++ b/pch/src/stdlib.pchsource @@ -0,0 +1,35 @@ +#var ldiv(n,d) D(({ldiv_t __r;long __n=(n),__d=(d);asm("move.l 0xC8,%%a5;move.l %2,%%d1;move.l %3,%%d0;move.l (%%a5,2720),%%a0;jsr (%%a0);move.l %%d1,%0;move.l %2,%%d1;move.l %3,%%d0;move.l (%%a5,2724),%%a0;jsr (%%a0);move.l %%d1,%1" : "=g"(__r.quot),"=g"(__r.rem) : "g"(__n),"g"(__d) : "a0","a1","a5","d0","d1","d2");__r;})) + +#var NULL D(((void*)0)) +#var RAND_MAX D(32767) +#var atexit_t typedef CALLBACK void(*atexit_t)(void); +#var compare_t typedef CALLBACK short(*compare_t)(const void*elem1,const void*elem2); +#var div_t typedef struct{short quot,rem;}div_t; +#var ldiv_t typedef struct{long quot,rem;}ldiv_t; +#var size_t typedef unsigned long size_t; +#var abort() D((_rom_call(void,(const char*),E6)("ABNORMAL PROGRAM TERMINATION"),exit(0))) +#var abs(x) D(({typeof(x) __x = (x); __x >= 0 ? __x : -__x;})) +#var atexit short atexit(atexit_t)__ATTR_LIB_ASM__; +#var atoi short atoi(const char*)__ATTR_LIB_C__; +#var atol long atol(const char*)__ATTR_LIB_C__; +#var bsearch void *bsearch(const void*,const void*,short,short,compare_t)__ATTR_LIB_C__; +#var calloc void *calloc(short,short)__ATTR_LIB_ASM__; +#var div(n,d) D(({short __n=(n),__d=(d);div_t __r;__r.quot=__n/__d;__r.rem=__n%__d;__r;})) +#var exit(n) D(({(n)?_rom_call(void,(short),152)(n):0;__exit();})) +#var __exit volatile void __exit(void)__ATTR_LIB_ASM_NORETURN__; +#var fabs(x) D(_tios_float_1(106,x,float)) +#var free D(_rom_call(void,(void*),A3)) +#var malloc D(_rom_call(void*,(long),A2)) +#var max(a,b) D(({typeof(a) __a = (a); typeof(b) __b = (b); (__a > __b) ? __a : __b;})) +#var min(a,b) D(({typeof(a) __a = (a); typeof(b) __b = (b); (__a < __b) ? __a : __b;})) +#var qsort void qsort(void*,short,short,compare_t)__ATTR_LIB_C__; +#var rand short rand(void)__ATTR_LIB_ASM__; +#var random(x) D(((short)((long)(unsigned short)rand()*(unsigned short)(x)/32768))) +#var randomize() D(srand(*(volatile char*)0x600017)) +#var realloc void *realloc(void*,long)__ATTR_LIB_ASM__; +#var __randseed extern long __randseed; +#var srand(x) D((__randseed=(x))) +#var strtol long strtol(const char*,char**,short)__ATTR_LIB_C__; +#var strtoul unsigned long strtoul(const char*,char**,short)__ATTR_LIB_C__; +#var atof float atof(const char*)__ATTR_LIB_ASM__; + diff --git a/pch/src/string.pchsource b/pch/src/string.pchsource new file mode 100644 index 0000000..9ef95c2 --- /dev/null +++ b/pch/src/string.pchsource @@ -0,0 +1,26 @@ + +#var NULL D(((void*)0)) +#var size_t typedef unsigned long size_t; +#var _memset D(_rom_call(void*,(void*,short,long),27B)) +#var cmpstri D(_rom_call(short,(const unsigned char*,const unsigned char*),16F)) +#var memchr D(_rom_call(void*,(const void*,short,long),273)) +#var memcmp D(_rom_call(short,(const void*,const void*,long),270)) +#var memcpy D(_rom_call(void*,(void*,const void*,long),26A)) +#var memmove D(_rom_call(void*,(void*,const void*,long),26B)) +#var memset D(_rom_call(void*,(void*,short,long),27C)) +#var sprintf D(_rom_call(short,(char*,const char*,...),53)) +#var strcat D(_rom_call(char*,(char*,const char*),26E)) +#var strchr D(_rom_call(char*,(const char*,short),274)) +#var strcmp D(_rom_call(short,(const unsigned char*,const unsigned char*),271)) +#var strcpy D(_rom_call(char*,(char*,const char*),26C)) +#var strcspn D(_rom_call(unsigned long,(const char*,const char*),275)) +#var strerror D(_rom_call(char*,(short),27D)) +#var strlen D(_rom_call(unsigned long,(const char*),27E)) +#var strncat D(_rom_call(char*,(char*,const char*,long),26F)) +#var strncmp D(_rom_call(short,(const unsigned char*,const unsigned char*,long),272)) +#var strncpy D(_rom_call(char*,(char*,const char*,long),26D)) +#var strpbrk D(_rom_call(char*,(const char*,const char*),276)) +#var strrchr D(_rom_call(char*,(const char*,short),277)) +#var strspn D(_rom_call(unsigned long,(const char*,const char*),278)) +#var strstr D(_rom_call(char*,(const char*,const char*),279)) +#var strtok D(_rom_call(char*,(char*,const char*),27A)) diff --git a/pch/src/system.pchsource b/pch/src/system.pchsource new file mode 100644 index 0000000..fb76054 --- /dev/null +++ b/pch/src/system.pchsource @@ -0,0 +1,63 @@ + +#var FALSE D(0) +#var TRUE D(1) +#var Bool enum Bool {}; + +#var DEF_QUEUE typedef struct{unsigned short Head;unsigned short Tail;unsigned short Size;unsigned short Used;unsigned short Buffer[];}DEF_QUEUE; +#var HANDLE typedef unsigned short HANDLE; +#var QUEUE(n) D(struct{unsigned short Head,Tail,Size,Used,Buffer[n/2];}) +#var Timer_Callback_t typedef CALLBACK void(*Timer_Callback_t)(void); +#var BATT_TIMER D(1) +#var APD_TIMER D(2) +#var LIO_TIMER D(3) +#var CURSOR_TIMER D(4) +#var MISC_TIMER D(5) +#var USER_TIMER D(6) + +#var AB_prodid D(_rom_call(void,(char*),29D)) +#var AB_prodname D(_rom_call(void,(char*),29E)) +#var AB_serno D(_rom_call(short,(char*),29F)) +#var ASM_call(x) D(({asm volatile{movem.l d0-d7/a0-a6,-(sp)};ASM_fastcall(x);asm volatile{movem.l (sp)+,d0-d7/a0-a6};})) +#var ASM_fastcall(x) D((((void(*)())(x))())) +#var CB_fetchTEXT D(_rom_call(short,(HANDLE*,__pulong),C2)) +#var CB_replaceTEXT D(_rom_call(short,(char*,long,short),C1)) +#var CU_restore D(_rom_call(void,(short),C3)) +#var CU_start D(_rom_call(short,(void),C4)) +#var CU_stop D(_rom_call(short,(void),C5)) + +#var EX_patch D(_rom_call(void,(void*,void*),15A)) +#var HelpKeys D(_rom_call(void,(void),181)) +#var idle D(_rom_call(void,(void),29B)) +#var kbd_queue void *kbd_queue(void)__ATTR_LIB_ASM__; +#var NeedStack D(_rom_call(void,(short),A4)) +#var off D(_rom_call(void,(void),29A)) +#var OSCheckBreak D(_rom_call(short,(void),EC)) +#var OSClearBreak D(_rom_call(void,(void),ED)) +#var OSContrastDn() D(({asm{move.l d3,-(a7);move.l d4,-(a7)};_rom_call(void,(void),297) ();asm{move.l (a7)+,d4;move.l (a7)+,d3};})) +#var OSContrastUp() D(({asm{move.l d3,-(a7);move.l d4,-(a7)};_rom_call(void,(void),296) ();asm{move.l (a7)+,d4;move.l (a7)+,d3};})) +#var OSDisableBreak D(_rom_call(void,(void),EF)) +#var OSEnableBreak D(_rom_call(void,(void),EE)) +#var OSFreeTimer D(_rom_call(short,(short),F1)) +#var OSRegisterTimer D(_rom_call(short,(short,long),F0)) +#var OSReset D(_rom_call(void,(void),294)) +#var OSSetSR D(_rom_call(short,(short),29C)) +#var OSTimerCurVal D(_rom_call(unsigned long,(short),F2)) +#var OSTimerExpired D(_rom_call(short,(short),F3)) +#var OSTimerRestart D(_rom_call(unsigned long,(short),F4)) +#var OSVFreeTimer short OSVFreeTimer(short)__ATTR_LIB_ASM__; +#var OSVRegisterTimer short OSVRegisterTimer(short,long,Timer_Callback_t)__ATTR_LIB_ASM__; +#var QModeKey D(_rom_call(short,(short),182)) +#var QSysKey D(_rom_call(short,(short),183)) +#var SumStoChkMem D(_rom_call(short,(void),295)) +#var WordInList D(_rom_call(short,(short,__pushort),184)) +#var XR_stringPtr(strno) D((AMS_1xx?_rom_call(const char*,(short),293)(strno):_rom_call(const char*,(long),293)(strno))) +#var OSdequeue D(_rom_call(short,(__pushort,void*),3AA)) +#var OSenqueue D(_rom_call(short,(short,void*),3A9)) +#var OSqclear D(_rom_call(void,(void*),3AD)) +#var OSqhead D(_rom_call(unsigned short,(__pushort,void*),3AC)) +#var OSqinquire D(_rom_call(short,(__pushort,void*),3AB)) +#var ReleaseDate D(((const char*const)(_rom_call_addr(43F)))) +#var ReleaseVersion D(((const char*const)(_rom_call_addr(440)))) + + +#var enter_ghost_space() D(({extern unsigned long *__save__sp__;enter_ghost_space();(*__save__sp__)|=0x40000;})) void @@enter_ghost_space(void)__ATTR_LIB_ASM__; diff --git a/pch/src/textedit.pchsource b/pch/src/textedit.pchsource new file mode 100644 index 0000000..ae58a4c --- /dev/null +++ b/pch/src/textedit.pchsource @@ -0,0 +1,29 @@ + +#var FALSE D(0) +#var TRUE D(1) + +#var HANDLE typedef unsigned short HANDLE; +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var WIN_RECT typedef struct{short x0,y0,x1,y1;}WIN_RECT; +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var EVENT typedef struct EventStruct{unsigned short Type;unsigned short RunningApp;unsigned short Side;unsigned short StatusFlags;union{WINDOW*w;WIN_RECT*r;char*pasteText;HANDLE hPasteText;struct{unsigned short Mod;unsigned short Code;}Key;}extra;unsigned char StartType;}EVENT; +#var size_t typedef unsigned long size_t; +#var TEXT_EDIT typedef struct TextEditStruct{WINDOW*Parent;unsigned short ReadOnly;WIN_RECT Rect;unsigned short BufSize;unsigned short CurSize;unsigned short CursorOffset;unsigned short StartOffset;unsigned short PreChars;unsigned short CharWidth;unsigned short CharHeight;unsigned short LineNum;unsigned short CursorX;unsigned short Flags;union{HANDLE h;const char*p;}Text;}TEXT_EDIT; +#var TE_checkSlack D(_rom_call(void,(TEXT_EDIT*),A6)) +#var TE_close D(_rom_call(void,(TEXT_EDIT*),A5)) +#var TE_empty D(_rom_call(void,(TEXT_EDIT*),A7)) +#var TE_focus D(_rom_call(short,(TEXT_EDIT*),A8)) +#var TE_handleEvent D(_rom_call(short,(TEXT_EDIT*,EVENT*),A9)) +#var TE_indicateReadOnly D(_rom_call(void,(TEXT_EDIT*),AA)) +#var TE_isBlank D(_rom_call(short,(TEXT_EDIT*),AB)) +#var TE_open D(_rom_call(short,(TEXT_EDIT*,WINDOW*,WIN_RECT*,HANDLE,short,short,short),AC)) +#var TE_openFixed D(_rom_call(short,(TEXT_EDIT*,WINDOW*,WIN_RECT*,char*,short,short),AD)) +#var TE_pasteText D(_rom_call(void,(TEXT_EDIT*,const char*,long),AE)) +#var TE_reopen D(_rom_call(void,(TEXT_EDIT*,short),AF)) +#var TE_reopenPlain D(_rom_call(void,(TEXT_EDIT*,short),B0)) +#var TE_select D(_rom_call(void,(TEXT_EDIT*,short,short),B1)) +#var TE_shrinkWrap D(_rom_call(HANDLE,(TEXT_EDIT*),B2)) +#var TE_unfocus D(_rom_call(short,(TEXT_EDIT*),B3)) +#var TE_updateCommand D(_rom_call(void,(TEXT_EDIT*,char),B4)) + diff --git a/pch/src/tigcc-archive/COMPILING b/pch/src/tigcc-archive/COMPILING new file mode 100644 index 0000000..0d45516 --- /dev/null +++ b/pch/src/tigcc-archive/COMPILING @@ -0,0 +1,13 @@ +You can recompile this on a TIGCC system by patching the system +include file and replacing the line: + #define __ATTR_LIB_C__ __attribute__((__regparm__(4))) +with the lines + #ifdef REGPARM1_STDLIB + #define __ATTR_LIB_C__ __attribute__((__regparm__(1))) + #define CONFIRM_REGPARM1_ENABLED + #else + #define __ATTR_LIB_C__ __attribute__((__regparm__(4))) + #endif + +This has been tested with TIGCC 0.94SP4. Newer versions will likely require +adaptation of this source code and/or toolchain. diff --git a/pch/src/tigcc-archive/License.txt b/pch/src/tigcc-archive/License.txt new file mode 100644 index 0000000..98ae2cc --- /dev/null +++ b/pch/src/tigcc-archive/License.txt @@ -0,0 +1,27 @@ +TIGCC Library Routines +Copyright (C) 2000-2001 Zeljko Juric, Thomas Nussbaumer, and + Kevin Kofler + +This file is part of TIGCC. + +TIGCC is free software; you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation; either version 2, or (at your option) any +later version. + +In addition to the permissions in the GNU General Public License, the +TIGCC Team gives you unlimited permission to link the compiled +versions of these files with other programs, and to distribute +those programs without any restriction coming from the use of this +file. (The General Public License restrictions do apply in other +respects; for example, they cover modification of the files, and +distribution when not linked into another program.) + +These files are distributed in the hope that they will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, write to the Free Software +Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. diff --git a/pch/src/tigcc-archive/addbf.s b/pch/src/tigcc-archive/addbf.s new file mode 100644 index 0000000..41b63a9 --- /dev/null +++ b/pch/src/tigcc-archive/addbf.s @@ -0,0 +1,6 @@ +.data + .xdef __addbf3 + .even +__addbf3: + clr.l %d0 + bra __fp_entry diff --git a/pch/src/tigcc-archive/ashldi.s b/pch/src/tigcc-archive/ashldi.s new file mode 100644 index 0000000..bde9a77 --- /dev/null +++ b/pch/src/tigcc-archive/ashldi.s @@ -0,0 +1,24 @@ +|ashldi3 routine copyright (C) 2002, Kevin Kofler + +.data + xdef __ashldi3 + .even +__ashldi3: + tst.w 12(%a7) + bne.s .L__ashldi3_return0 + move.l 4(%a7),%d0 + move.l 8(%a7),%d1 + move.w 14(%a7),%d2 + beq.s .L__ashldi3_returnn + subq.w #1,%d2 +.L__ashldi3_loop: + add.l %d1,%d1 + addx.l %d0,%d0 + dbra.w %d2,.L__ashldi3_loop +.L__ashldi3_returnn: + rts + +.L__ashldi3_return0: + moveq.l #0,%d0 + moveq.l #0,%d1 + rts diff --git a/pch/src/tigcc-archive/ashrdi.s b/pch/src/tigcc-archive/ashrdi.s new file mode 100644 index 0000000..b7a52e1 --- /dev/null +++ b/pch/src/tigcc-archive/ashrdi.s @@ -0,0 +1,31 @@ +|ashrdi3 routine copyright (C) 2002, Kevin Kofler + +.data + xdef __ashrdi3 + .even +__ashrdi3: + tst.w 12(%a7) + bne.s .L__ashrdi3_return0 + move.l 4(%a7),%d0 + move.l 8(%a7),%d1 + move.w 14(%a7),%d2 + beq.s .L__ashrdi3_returnn + subq.w #1,%d2 +.L__ashrdi3_loop: + asr.l #1,%d0 + roxr.l #1,%d1 + dbra.w %d2,.L__ashrdi3_loop +.L__ashrdi3_returnn: + rts + +.L__ashrdi3_return0: + tst.b 4(%a7) + blt.s .L__ashrdi3_return_neg1 + moveq.l #0,%d0 + moveq.l #0,%d1 + rts + +.L__ashrdi3_return_neg1: + moveq.l #-1,%d0 + moveq.l #-1,%d1 + rts diff --git a/pch/src/tigcc-archive/assert.s b/pch/src/tigcc-archive/assert.s new file mode 100644 index 0000000..8f557e5 --- /dev/null +++ b/pch/src/tigcc-archive/assert.s @@ -0,0 +1,59 @@ +.data + .xdef __assertion_failed + .even +__assertion_failed: + link.w %a6,#-1044 + move.l 0xC8,%a2 + move.w 16(%a6),(%sp) + move.l 12(%a6),-(%sp) + move.l 8(%a6),-(%sp) + pea .L__assert_fmt + lea -1000(%a6),%a4 + move.l %a4,-(%sp) + move.l 332(%a2),%a0 + jsr (%a0) + move.l 188(%a2),%a0 + clr.l %d0 + move.b 2(%a0),%d0 + swap %d0 + move.b 3(%a0),%d0 + add.l #0xFFF5FFF1,%d0 + move.l %d0,(%sp) + move.l #0xA000A,-(%sp) + move.l 176(%a2),%a0 + jsr (%a0) + pea .L__assert_ttl + move.w #0x1058,-(%sp) + move.l %a0,-(%sp) + pea -1042(%a6) + move.l 120(%a2),%a0 + jsr (%a0) + move.l 4(%a2),%a0 + jsr (%a0) + clr.w 4(%sp) + move.l 76(%a2),%a0 + jsr (%a0) + move.l %a4,4(%sp) + move.l 148(%a2),%a0 + jsr (%a0) + move.l #0x10008,4(%sp) + move.l 212(%a2),%a0 + jsr (%a0) +.L__assert_wkey: + move.l 324(%a2),%a0 + jsr (%a0) + cmp.w #13,%d0 + jbne .L__assert_wkey + move.l 44(%a2),%a0 + jsr (%a0) + movea.l __save__sp__:l,%a7 + rts +.L__assert_ttl: + .ascii "ASSERTION FAILED" + .word 0 +.L__assert_fmt: + .byte 10 + .ascii " Condition: %s" + .byte 10,10 + .ascii " File: %s Line: %d" + .word 0 diff --git a/pch/src/tigcc-archive/atexit.s b/pch/src/tigcc-archive/atexit.s new file mode 100644 index 0000000..66b66c1 --- /dev/null +++ b/pch/src/tigcc-archive/atexit.s @@ -0,0 +1,107 @@ +|atexit function copyright (C) 2002, Kevin Kofler +|requires new exit support (__save__sp__) +|Many thanks to Patrick Plissier and Stephan Effelsberg for ideas on how to +|implement this. Stephan Effelsberg's C implementation inspired this mostly, +|but I have changed it so that exit and atexit will not be included if not +|used. There is only a small 20-byte exit support needed. + +.data + +.equ __malloc,0xa2 |HeapAllocPtr +.equ __free,0xa3 |HeapFreePtr +.equ __num_regs,10 |number of registers saved by the exit support + + .xdef atexit +atexit: +|find the return address: + movea.l __save__sp__:l,%a0 |stack pointer before restoring the registers + |(NOT PC-relative because of programs >32 KB) +|The return address is now at (a0). + +|check if the return address is .L__atexit__new__return + cmpi.l #.L__atexit__new__return:l,(%a0) + beq.s .L__atexit__return__address__ok |if it is, skip ahead +|Else: +|- move the current return address to .L__atexit__return+2 + move.l (%a0),.L__atexit__return+2 +|- change the return address to .L__atexit__new__return + move.l #.L__atexit__new__return:l,(%a0) + clr.l .L__atexit__num__funcs |initialize the number of atexit functions to 0 + +|allocate a handle for the functions + pea.l 4:w + movea.l 0xc8,%a0 + move.l (__malloc*4,%a0),%a0 + jsr (%a0) |a0=malloc(4); + addq.l #4,%a7 + bra.s .L__atexit__handle__allocated + +.L__atexit__return__address__ok: +|reallocate the handle for the functions + move.l (.L__atexit__num__funcs,%PC),%d0 + lsl.l #2,%d0 + addq.l #4,%d0 + move.l %d0,-(%a7) + move.l (.L__atexit__ptr__funcs,%PC),-(%a7) + jsr realloc |a0=realloc(.L__atexit__ptr__funcs,.L__atexit__num__funcs*4+4); + addq.l #8,%a7 + +.L__atexit__handle__allocated: +|If a0 is NULL, there was not enough memory, so we return an error code. + moveq #0,%d0 + cmpa.l %d0,%a0 |if (!a0) + seq.b %d0 + beq.s .L__atexit__rts |return 255; + + move.l %a0,.L__atexit__ptr__funcs |save a0 to .L__atexit__ptr__funcs +|Now we store the function given as an argument into the allocated memory. + move.l (.L__atexit__num__funcs,%PC),%d1 + lsl.l #2,%d1 + move.l (4,%a7),(0,%a0,%d1:l) |.L__atexit__ptr__funcs[.L__atexit__num__funcs]=4(a7); + +|And there is 1 more atexit function now: + addq.l #1,.L__atexit__num__funcs + +.L__atexit__rts: + rts + +|This will be executed when the _main function or the exit function tries to +|return: +.L__atexit__new__return: + move.l (.L__atexit__num__funcs,%PC),%d0 |if there are no functions to call, return + beq.s .L__atexit__no__funcs |immediately + +| movem.l %a2/%a5/%d3,-(%a7) +|no need to save and restore the registers, the exit support will do it for us + movea.l 0xc8,%a5 + movea.l (.L__atexit__ptr__funcs,%PC),%a2 + move.l %d0,%d3 |save d0 to d3 + lsl.l #2,%d0 |point a2 to the address of the last function + 4 + add.l %d0,%a2 |that is, .L__atexit__ptr__funcs[.L__atexit__num__funcs] + + subq.l #1,%d3 |subtract 1 from the number of functions for the dbra loop + +|call all atexit functions now +.L__atexit__loop: + movea.l -(%a2),%a0 + jsr (%a0) + dbra.w %d3,.L__atexit__loop + +|a2 now points to the beginning of the allocated memory for the pointers +|free this memory + pea.l (%a2) + move.l (__free*4,%a5),%a0 + jsr (%a0) |free(.L__atexit__ptr__funcs); + addq.l #4,%a7 + +| movem.l (%a7)+,%a2/%a5/%d3 +|no need to save and restore the registers, the exit support will do it for us +.L__atexit__no__funcs: + +|This will return to the actual return address (which will be patched in +|instead of the 0 by the first call to atexit). +.L__atexit__return: jmp.l 0:l + +|data: +.L__atexit__ptr__funcs: .long 0 |pointer to the atexit functions +.L__atexit__num__funcs: .long 0 |number of atexit functions diff --git a/pch/src/tigcc-archive/atof.s b/pch/src/tigcc-archive/atof.s new file mode 100644 index 0000000..8089e6c --- /dev/null +++ b/pch/src/tigcc-archive/atof.s @@ -0,0 +1,44 @@ +.data + .xdef atof + .even +atof: + link.w %a6,#-80 + movem.l %d3-%d7/%a2-%a5,-(%sp) + move.l 0xC8,%a4 + move.l 1060(%a4),%a3 + move.l (%a3),%d4 + pea -80(%a6) + move.l 1360(%a4),%a0 + jsr (%a0) /* ER_catch */ + tst.w %d0 + jbeq .L__atof_1 + move.l #0x7FFFAA00,%d0 + clr.l %d1 + clr.w %d2 + jbra .L__atof_3 +.L__atof_1: + move.l 8(%a6),(%sp) + move.l 3880(%a4),%a0 + jsr (%a0) /* push_parse_text */ + move.l (%a3),%a0 + move.b (%a0),%d5 + cmpi.b #0x7A,%d5 + bne.s .L__atof_2 + subq #1,%a0 +.L__atof_2: + move.l %a0,(%sp) + move.l 3044(%a4),%a0 + jsr (%a0) /* estack_number_to_Float */ + move.l %d4,(%a3) + move.l 1364(%a4),%a0 + jsr (%a0) /* ER_success */ + move.l (%a6,-10),%d0 + move.l (%a6,-6),%d1 + move.w (%a6,-2),%d2 + cmpi.b #0x7A,%d5 + bne.s .L__atof_3 + bset #31,%d0 +.L__atof_3: + movem.l -116(%a6),%d3-%d7/%a2-%a5 + unlk %a6 + rts diff --git a/pch/src/tigcc-archive/atoi.c b/pch/src/tigcc-archive/atoi.c new file mode 100644 index 0000000..bceb36d --- /dev/null +++ b/pch/src/tigcc-archive/atoi.c @@ -0,0 +1,16 @@ +#include +#include + +#ifndef CONFIRM_REGPARM1_ENABLED +#error You need to patch as described in the 'COMPILING' file. +#endif + +__ATTR_LIB_C__ short atoi(const char *s) +{ + unsigned short c,value=0,neg=0; + while(*s==' ') ++s; + if(*s=='-'||*(const unsigned char*)s==0xAD) ++s,neg=-1; + else if(*s=='+') ++s; + while(isdigit(c=*(const unsigned char*)s++)) value=10*value+c-'0'; + return neg?-value:value; +} diff --git a/pch/src/tigcc-archive/atol.c b/pch/src/tigcc-archive/atol.c new file mode 100644 index 0000000..07854d6 --- /dev/null +++ b/pch/src/tigcc-archive/atol.c @@ -0,0 +1,13 @@ +#include +#include + +__ATTR_LIB_C__ long atol(const char *s) +{ + unsigned short c,neg=0; + long value=0; + while(*s==' ') ++s; + if(*s=='-'||*(const unsigned char*)s==0xAD) ++s,neg=-1; + else if(*s=='+') ++s; + while(isdigit(c=*(const unsigned char*)s++)) value=(value<<3)+(value<<1)+c-'0'; + return neg?-value:value; +} diff --git a/pch/src/tigcc-archive/bc.s b/pch/src/tigcc-archive/bc.s new file mode 100644 index 0000000..9994c35 --- /dev/null +++ b/pch/src/tigcc-archive/bc.s @@ -0,0 +1,19 @@ +.data + .xdef __BC + .even +__BC: + link %a6,#-10 + move.l (%a6,26),-(%sp) + move.l (%a6,22),-(%sp) + move.l (%a6,18),-(%sp) + move.l (%a6,14),-(%sp) + move.l (%a6,10),-(%sp) + move.w (%a6,8),%d0 + move.l 0xC8,%a0 + move.l (%a0,%d0.w),%a0 + jsr (%a0) + move.l (%a6,-10),%d0 + move.l (%a6,-6),%d1 + move.w (%a6,-2),%d2 + unlk %a6 + rts diff --git a/pch/src/tigcc-archive/bcopy.s b/pch/src/tigcc-archive/bcopy.s new file mode 100644 index 0000000..7004348 --- /dev/null +++ b/pch/src/tigcc-archive/bcopy.s @@ -0,0 +1,13 @@ +.data + .xdef bcopy + .even +bcopy: + move.w (12,%sp),-(%sp) + clr.w -(%sp) + move.l (8,%sp),-(%sp) + move.l (16,%sp),-(%sp) + movea.l 0xC8,%a0 + movea.l (%a0,0x26A*4),%a0 + jsr (%a0) /* memcpy */ + lea (%sp,12),%sp + rts diff --git a/pch/src/tigcc-archive/bsearch.c b/pch/src/tigcc-archive/bsearch.c new file mode 100644 index 0000000..df480a8 --- /dev/null +++ b/pch/src/tigcc-archive/bsearch.c @@ -0,0 +1,19 @@ +#include + +// Do not use register a5; callback function might need it. +register long __tbl asm ("a5"); + +__ATTR_LIB_C__ void *bsearch(const void *key, const void *bptr, short n, short w, compare_t cmp_func) +{ + unsigned short left=0,right=n-1,index; + short rcmp; + void *rptr; + do + { + index=(left+right)>>1; + if((rcmp=cmp_func(key,rptr=(char*)bptr+(long)index*(unsigned short)w))>0) left=index+1; + else if(rcmp<0) right=index-1; + else return rptr; + } while(left<=right); + return 0; +} diff --git a/pch/src/tigcc-archive/bzero.s b/pch/src/tigcc-archive/bzero.s new file mode 100644 index 0000000..b2c0c13 --- /dev/null +++ b/pch/src/tigcc-archive/bzero.s @@ -0,0 +1,12 @@ +.data + .xdef bzero + .even +bzero: + move.w (8,%sp),-(%sp) + clr.l -(%sp) + move.l (10,%sp),-(%sp) + movea.l 0xC8,%a0 + movea.l (%a0,0x27C*4),%a0 + jsr (%a0) /* memset */ + lea (%sp,10),%sp + rts diff --git a/pch/src/tigcc-archive/calloc.s b/pch/src/tigcc-archive/calloc.s new file mode 100644 index 0000000..d51a4ff --- /dev/null +++ b/pch/src/tigcc-archive/calloc.s @@ -0,0 +1,24 @@ +.data + .xdef calloc + .even +calloc: + link.w %a6,#0 + move.w 8(%a6),%d0 + mulu.w 10(%a6),%d0 + move.l %d0,-(%sp) + move.l 0xC8,%a0 + move.l 648(%a0),%a0 + jsr (%a0) + move.l %a0,%d0 + jbeq .L__calloc_1 + clr.w -(%sp) + move.l %a0,-(%sp) + move.l 0xC8,%a0 + move.l 2544(%a0),%a0 + jsr (%a0) + jbra .L__calloc_2 +.L__calloc_1: + move.l #0,%a0 +.L__calloc_2: + unlk %a6 + rts diff --git a/pch/src/tigcc-archive/calloc_throw.s b/pch/src/tigcc-archive/calloc_throw.s new file mode 100644 index 0000000..916b836 --- /dev/null +++ b/pch/src/tigcc-archive/calloc_throw.s @@ -0,0 +1,12 @@ +.data + .even + .xdef calloc_throw +calloc_throw: + lea.l .L__finished+2,%a0 + move.l (%sp)+,(%a0) + jbsr calloc + move.l %a0,%d0 + jbne .L__finished + .word 0xA000+670 +.L__finished: + jmp.l 0:l diff --git a/pch/src/tigcc-archive/clrscr.s b/pch/src/tigcc-archive/clrscr.s new file mode 100644 index 0000000..e61ca4e --- /dev/null +++ b/pch/src/tigcc-archive/clrscr.s @@ -0,0 +1,12 @@ +.data + .xdef clrscr + .even +clrscr: + move.l 0xC8,%a0 + move.l (%a0,0x674),%a0 + clr.l -(%sp) + jsr (%a0) + addq.l #4,%sp + move.l 0xC8,%a0 + move.l (%a0,0x678),%a0 + jmp (%a0) diff --git a/pch/src/tigcc-archive/cmpbf.s b/pch/src/tigcc-archive/cmpbf.s new file mode 100644 index 0000000..90d76f1 --- /dev/null +++ b/pch/src/tigcc-archive/cmpbf.s @@ -0,0 +1,12 @@ +.data + .xdef __cmpbf2,__nebf2,__eqbf2,__gebf2,__ltbf2,__gtbf2,__lebf2 + .even +__cmpbf2: +__nebf2: +__eqbf2: +__gebf2: +__ltbf2: +__gtbf2: +__lebf2: + moveq.l #20,%d0 + bra __fp_entry_1 diff --git a/pch/src/tigcc-archive/contrastdn.s b/pch/src/tigcc-archive/contrastdn.s new file mode 100644 index 0000000..74a9df3 --- /dev/null +++ b/pch/src/tigcc-archive/contrastdn.s @@ -0,0 +1,10 @@ +.data + .xdef OSContrastDn + .even +OSContrastDn: + movem.l %d3-%d4,-(%sp) + move.l 0xC8,%a0 + move.l (%a0,2652),%a0 + jsr (%a0) + movem.l (%sp)+,%d3-%d4 + rts diff --git a/pch/src/tigcc-archive/contrastup.s b/pch/src/tigcc-archive/contrastup.s new file mode 100644 index 0000000..73aaf06 --- /dev/null +++ b/pch/src/tigcc-archive/contrastup.s @@ -0,0 +1,10 @@ +.data + .xdef OSContrastUp + .even +OSContrastUp: + movem.l %d3-%d4,-(%sp) + move.l 0xC8,%a0 + move.l (%a0,2648),%a0 + jsr (%a0) + movem.l (%sp)+,%d3-%d4 + rts diff --git a/pch/src/tigcc-archive/divbf.s b/pch/src/tigcc-archive/divbf.s new file mode 100644 index 0000000..51ee2da --- /dev/null +++ b/pch/src/tigcc-archive/divbf.s @@ -0,0 +1,6 @@ +.data + .xdef __divbf3 + .even +__divbf3: + moveq.l #12,%d0 + bra __fp_entry diff --git a/pch/src/tigcc-archive/divdi.s b/pch/src/tigcc-archive/divdi.s new file mode 100644 index 0000000..91de237 --- /dev/null +++ b/pch/src/tigcc-archive/divdi.s @@ -0,0 +1,37 @@ +|divdi3 routine copyright (C) 2002, Kevin Kofler +|WARNING: Division by 0 will be handled the same way as in the unsigned variant. +| For my __udivdi3, this means: +| A division by 0 will not cause an exception, but just crash in an +| infinite loop! +|ANOTHER WARNING: This will ONLY work with an __udivdi3 which does NOT destroy a1! +| Mine works of course. + +.data + xdef __divdi3 + .even +__divdi3: + tst.b 4(%a7) + blt.s .L__divdi3_numer_negative + tst.b 12(%a7) + blt.s .L__divdi3_denom_negative +.L__divdi3_udivdi3: + jbra __udivdi3 + +.L__divdi3_numer_negative: + neg.l 8(%a7) + negx.l 4(%a7) + tst.b 12(%a7) + bge.s .L__divdi3_denom_positive + neg.l 16(%a7) + negx.l 12(%a7) + bra.s .L__divdi3_udivdi3 + +.L__divdi3_denom_negative: + neg.l 16(%a7) + negx.l 12(%a7) +.L__divdi3_denom_positive: + move.l (%a7)+,%a1 + bsr.s .L__divdi3_udivdi3 + neg.l %d1 + negx.l %d0 + jmp (%a1) diff --git a/pch/src/tigcc-archive/diventry.s b/pch/src/tigcc-archive/diventry.s new file mode 100644 index 0000000..4140663 --- /dev/null +++ b/pch/src/tigcc-archive/diventry.s @@ -0,0 +1,11 @@ +.data + .xdef __div_entry + .even +__div_entry: + move.l (4,%sp),%d1 + move.l (8,%sp),%d0 + movea.l 0xC8,%a0 + movea.l (%a0,%d2.w),%a0 + jsr (%a0) + move.l %d1,%d0 + rts diff --git a/pch/src/tigcc-archive/divsi.s b/pch/src/tigcc-archive/divsi.s new file mode 100644 index 0000000..df82ae1 --- /dev/null +++ b/pch/src/tigcc-archive/divsi.s @@ -0,0 +1,6 @@ +.data + .xdef __divsi3 + .even +__divsi3: + move.w #0x2A8*4,%d2 /* _ds32s32 */ + jra __div_entry diff --git a/pch/src/tigcc-archive/dll.c b/pch/src/tigcc-archive/dll.c new file mode 100644 index 0000000..d26b097 --- /dev/null +++ b/pch/src/tigcc-archive/dll.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include + +/* These functions are in the same file, so that they + can access their global variables in a pc-relative + fashion. */ + +__ATTR_LIB_C__ short LoadDLL(const char *DLL_name, long ID, short major, short minor) +{ + SYM_ENTRY *entry; + HANDLE h; + unsigned char *bptr,*sptr; + unsigned short len,offset=0,wrongver=0; + unsigned long pc; + unsigned long signature[]={__DLL_SIGNATURE,ID}; + asm volatile("bsr 0f; 0:move.l (%%sp)+,%0":"=g"(pc)); + if(pc<0x40000) return DLL_NOTINGHOSTSPACE; + if(__DLL_body_ptr) return DLL_ALREADYLOADED; + entry=SymFindFirst(NULL,2); + do + { + if(!strcmp(entry->name,DLL_name)&&entry->handle&&!entry->flags.bits.twin + &&(entry->flags.bits.archived||!HeapGetLock(entry->handle))) + { + len=peek_w(bptr=HeapDeref(entry->handle))+2; + if(!memcmp(bptr+len-5,"DLL\x00\xF8",5)) + { + offset=0; + for(sptr=bptr+2;(sptr major + ||(unsigned short)minor>((__DLL_interface_struct*)sptr)->minor) + wrongver=1; + else + offset=sptr-bptr,wrongver=0; + } + if(offset) break; + } + } + } while((entry=SymFindNext())); + if(wrongver) return DLL_WRONGVERSION; + if(!entry) return DLL_NOTFOUND; + if(!HeapLock(h=entry->handle)) return DLL_LOCKFAILED; + if(!(__DLL_body_ptr=malloc(len=peek_w(bptr=HeapDeref(h)+2)+2))) + { + HeapUnlock(h); + return DLL_OUTOFMEM; + } + memcpy(__DLL_body_ptr,bptr,len); + EX_patch((char*)__DLL_body_ptr+0x40000+2,(char*)__DLL_body_ptr+0x40000+len-1); + __DLL_interface_ptr=(__DLL_interface_struct*)((char*)__DLL_body_ptr+offset-2); + HeapUnlock(h); + return DLL_OK; +} + +__ATTR_LIB_C__ void UnloadDLL(void) +{ + if(!__DLL_body_ptr) return; + free(__DLL_body_ptr); + __DLL_body_ptr=0; + __DLL_interface_ptr=0; +} + +__DLL_interface_struct *__DLL_interface_ptr=0; +void *__DLL_body_ptr=0; diff --git a/pch/src/tigcc-archive/dummyhandler.s b/pch/src/tigcc-archive/dummyhandler.s new file mode 100644 index 0000000..d0be223 --- /dev/null +++ b/pch/src/tigcc-archive/dummyhandler.s @@ -0,0 +1,5 @@ +.data + .even + .xdef __dummy_handler__ +__dummy_handler__: + rte diff --git a/pch/src/tigcc-archive/enter_ghost_space.s b/pch/src/tigcc-archive/enter_ghost_space.s new file mode 100644 index 0000000..b0fbf12 --- /dev/null +++ b/pch/src/tigcc-archive/enter_ghost_space.s @@ -0,0 +1,36 @@ +.data + .xdef enter_ghost_space + .even +enter_ghost_space: + bsr.w .L__ghost_space_0 +.L__ghost_space_0: + move.l (%sp)+,%d0 + cmpi.l #0x40000,%d0 + bcc.s .L__ghost_space_2 + movea.l 0xC8,%a0 + cmpi.l #1000,(%a0,-4) + bcs.s .L__ghost_space_2 + movem.l %a2-%a6/%d3-%d7,-(%sp) + lea (%sp,-20),%sp + move.l #0x3E000,%a3 + move.l %a0,%d0 + andi.l #0x600000,%d0 + addi.l #0x20000,%d0 + move.l %d0,(%sp,12) + move.l %d0,(%sp,16) + trap #0xC + move.w #0x2700,%sr + move.l #0xF,%d3 + pea .L__ghost_space_1(%pc) + bset.b #2,(%sp,1) + clr.w -(%sp) + move.l 0xAC,%a0 + jmp (%a0) +.L__ghost_space_1: + lea (%sp,20),%sp + movem.l (%sp)+,%a2-%a6/%d3-%d7 +.L__ghost_space_2: + move.l (%sp)+,%d0 + bset.l #18,%d0 + movea.l %d0,%a0 + jmp (%a0) diff --git a/pch/src/tigcc-archive/exit.s b/pch/src/tigcc-archive/exit.s new file mode 100644 index 0000000..71d8297 --- /dev/null +++ b/pch/src/tigcc-archive/exit.s @@ -0,0 +1,10 @@ +|exit function copyright (C) 2002, Kevin Kofler +|requires new exit support (__save__sp__) +|Thanks to Patrick Plissier for the code. I have just changed it from a patch +|to an archive function, so it won't be there when not needed. + +.data + .xdef __exit +__exit: + movea.l __save__sp__:l,%a7 |(NOT PC-relative because of programs >32 KB) + rts diff --git a/pch/src/tigcc-archive/fclose.c b/pch/src/tigcc-archive/fclose.c new file mode 100644 index 0000000..8a74d39 --- /dev/null +++ b/pch/src/tigcc-archive/fclose.c @@ -0,0 +1,16 @@ +#include +#include + +__ATTR_LIB_C__ short fclose(FILE *f) +{ + short s; + + if(!f) return EOF; + s=(f->flags&_F_ERR)?EOF:0; + + HeapRealloc(f->handle,(*(unsigned short*)(f->base))+2); + HeapUnlock(f->handle); + free(f); + + return s; +} diff --git a/pch/src/tigcc-archive/fgetc.c b/pch/src/tigcc-archive/fgetc.c new file mode 100644 index 0000000..1e2288d --- /dev/null +++ b/pch/src/tigcc-archive/fgetc.c @@ -0,0 +1,18 @@ +#include +#include + +__ATTR_LIB_C__ short fgetc(FILE *f) +{ + short c,tmode=!(f->flags&_F_BIN); + if(f->flags&_F_ERR) return EOF; + if(!(f->flags&_F_READ)) __FERROR(f); + if((c=f->unget)<0) + { + f->unget=0; return c&0xFF; + } + if(feof(f)) return EOF; + c=peek(f->fpos++); + if(c=='\r'&&tmode) fgetc(f); + if(f->base+peek_w(f->base)+(tmode?0:2)==f->fpos) f->flags|=_F_EOF; + return c; +} diff --git a/pch/src/tigcc-archive/fgets.c b/pch/src/tigcc-archive/fgets.c new file mode 100644 index 0000000..926d38d --- /dev/null +++ b/pch/src/tigcc-archive/fgets.c @@ -0,0 +1,14 @@ +#include + +__ATTR_LIB_C__ char *fgets(char *s, short n, FILE *fp) +{ + short c=EOF; + char *cs=s; + while(--n>0&&(c=fgetc(fp))!=EOF) + { + if(c=='\r'&&!(fp->flags&_F_BIN)) c='\n'; + if ((*cs++=c)=='\n') break; + } + *cs=0; + return ((c==EOF&&cs==s)?0:s); +} diff --git a/pch/src/tigcc-archive/fixbf.s b/pch/src/tigcc-archive/fixbf.s new file mode 100644 index 0000000..1ee5a1a --- /dev/null +++ b/pch/src/tigcc-archive/fixbf.s @@ -0,0 +1,7 @@ +.data + .xdef __fixbfsi,__fixunsbfsi + .even +__fixbfsi: +__fixunsbfsi: + moveq.l #24,%d0 + bra __fp_entry_1 diff --git a/pch/src/tigcc-archive/floatbf.s b/pch/src/tigcc-archive/floatbf.s new file mode 100644 index 0000000..ee5e792 --- /dev/null +++ b/pch/src/tigcc-archive/floatbf.s @@ -0,0 +1,6 @@ +.data + .xdef __floatsibf + .even +__floatsibf: + moveq.l #28,%d0 + bra __fp_entry diff --git a/pch/src/tigcc-archive/fopen.c b/pch/src/tigcc-archive/fopen.c new file mode 100644 index 0000000..740d249 --- /dev/null +++ b/pch/src/tigcc-archive/fopen.c @@ -0,0 +1,68 @@ +#include +#include + +__ATTR_LIB_C__ FILE *fopen(const char *name, const char *mode) +{ + char str[50],*fpos,*epos,*base=0,*sptr=str,chmode=mode[0]; + short bmode=(mode[1]=='b'|| mode[2]=='b'),flags=0,ferr; + SYM_ENTRY *sym_entry; + FILE *f; + + *sptr=0; while((*++sptr=*name++)); + + if((sym_entry=DerefSym(SymFind(sptr)))) + if(sym_entry->flags.flags_n&0x8218 && strpbrk(mode,"wa+")) + return 0; + + if(!(f=malloc(sizeof(FILE)))) return 0; + + if(chmode=='r'|| chmode=='a') + { + flags=_F_READ; + if(!sym_entry) + if(chmode=='r') + { + free(f); + return 0; + } + else chmode='w'; + else + { + base=HLock(f->handle=sym_entry->handle); + f->alloc=HeapSize(f->handle); + } + } + if(chmode=='w') + { + SCR_STATE scr_state; + flags=_F_WRIT; + SaveScrState(&scr_state); + ferr=!(sym_entry=DerefSym(SymAdd(sptr))); + RestoreScrState(&scr_state); + if(!ferr) ferr=!(f->handle=sym_entry->handle=HeapAlloc(128)); + if(ferr) + { + SymDel(sptr); + free(f); + return 0; + } + + f->buffincrement=f->alloc=128; + + base=HLock(f->handle); + if(bmode) poke_w(base,0); + else + { + poke_l(base,0x00050001); + poke_l(base+4,0x2000E000); + } + } + epos=base+peek_w(base)+(bmode?2:0); + if(chmode=='a') flags=_F_WRIT,fpos=epos; + else fpos=base+(bmode?2:5); + if(epos==fpos) flags|=_F_EOF; + if(mode[1]=='+'||mode[2]=='+') flags|=_F_RDWR; + if(bmode) flags|=_F_BIN; + f->flags=flags; f->base=base; f->fpos=fpos; f->unget=0; + return f; +} diff --git a/pch/src/tigcc-archive/fpcall.s b/pch/src/tigcc-archive/fpcall.s new file mode 100644 index 0000000..bab4d28 --- /dev/null +++ b/pch/src/tigcc-archive/fpcall.s @@ -0,0 +1,17 @@ +.data + .xdef __fp_entry_1,__fp_call + .even +__fp_entry_1: + lea (%sp,24),%a1 +__fp_call: + add.w #728,%d0 + move.l -(%a1),-(%sp) + move.l -(%a1),-(%sp) + move.l -(%a1),-(%sp) + move.l -(%a1),-(%sp) + move.l -(%a1),-(%sp) + move.l 0xC8,%a0 + move.l (%a0,%d0.w),%a0 + jsr (%a0) + lea (%sp,20),%sp + rts diff --git a/pch/src/tigcc-archive/fpentry.s b/pch/src/tigcc-archive/fpentry.s new file mode 100644 index 0000000..1303710 --- /dev/null +++ b/pch/src/tigcc-archive/fpentry.s @@ -0,0 +1,11 @@ +.data + .xdef __fp_entry + .even +__fp_entry: + link %a6,#-10 + lea (%a6,28),%a1 + bsr __fp_call + movem.l (%a6,-10),%d0-%d1 + move.w (%a6,-2),%d2 + unlk %a6 + rts diff --git a/pch/src/tigcc-archive/fprintf.s b/pch/src/tigcc-archive/fprintf.s new file mode 100644 index 0000000..187d894 --- /dev/null +++ b/pch/src/tigcc-archive/fprintf.s @@ -0,0 +1,17 @@ +| Warning: This routine has the attribute __ATTR_TIOS__! + +.data + .xdef fprintf + .even +fprintf: + movea.l 0xC8,%a0 + movea.l (%a0,0x14C),%a0 /* vcbprintf */ + lea (%a0,32),%a0 + movea.w (%a0),%a1 + pea (%sp,12) + move.l (%sp,12),-(%sp) + move.l (%sp,12),-(%sp) + pea fputc + jsr (%a0.l,%a1) + lea (%sp,16),%sp + rts diff --git a/pch/src/tigcc-archive/fputc.c b/pch/src/tigcc-archive/fputc.c new file mode 100644 index 0000000..e54f4d3 --- /dev/null +++ b/pch/src/tigcc-archive/fputc.c @@ -0,0 +1,33 @@ +#include +#include +#include + +__ATTR_TIOS_CALLBACK__ short fputc(short c, FILE *f) +{ + short tmode=!(f->flags&_F_BIN); + char *base=f->base,*oldbase=base; + if(f->flags&_F_ERR) return EOF; + if(!(f->flags&_F_WRIT)) __FERROR(f); + if(peek_w(base)+10>f->alloc) + { + HeapUnlock(f->handle); + if(!HeapRealloc(f->handle,f->alloc+=f->buffincrement)) __FERROR(f); + base=f->base=HLock(f->handle); + f->fpos+=base-oldbase; + oldbase=base; + } + if(feof(f)) (*(short*)base)++; + if(c=='\n'&&tmode) c='\r'; + poke(f->fpos++,c); + if(c=='\r'&&tmode) fputc(' ',f); + if(base+peek_w(base)+(tmode?0:2)==f->fpos) + { + f->flags|=_F_EOF; + if(tmode) + { + poke(f->fpos,0); + poke(f->fpos+1,0xE0); + } + } + return c; +} diff --git a/pch/src/tigcc-archive/fputchar.s b/pch/src/tigcc-archive/fputchar.s new file mode 100644 index 0000000..2f7b199 --- /dev/null +++ b/pch/src/tigcc-archive/fputchar.s @@ -0,0 +1,68 @@ +| Warning: This routine has the attribute __ATTR_TIOS_CALLBACK__! + +.data + .xdef fputchar + .even +fputchar: + link.w %a6,#-20 + movem.l %d3-%d7/%a2-%a5,-(%sp) + clr.w %d0 + move.b (%a6,9),%d6 + move.l 0xC8,%a5 + move.l (%a5,1592),%a0 + jsr (%a0) + move.w %d0,%d4 + lsl.w #1,%d4 + addq.w #6,%d4 + move.l (%a5,188),%a3 + pea (%a6,-18) + move.l (%a5,1664),%a0 + jsr (%a0) + move.w (%a6,-8),%d5 + move.w (%a6,-6),%d3 + move.w %d6,-(%sp) + move.l (%a5,1600),%a0 + jsr (%a0) + move.w %d0,%d7 + cmp.b #10,%d6 + jbeq .L__fputchar_1 + move.w %d5,%d0 + add.w %d7,%d0 + clr.w %d1 + move.b (%a3,2),%d1 + cmp.w %d0,%d1 + jbge .L__fputchar_2 +.L__fputchar_1: + clr.w %d5 + add.w %d4,%d3 +.L__fputchar_2: + move.w %d3,%d0 + add.w %d4,%d0 + clr.w %d1 + move.b (%a3,3),%d1 + cmp.w %d0,%d1 + jbge .L__fputchar_3 + clr.w (%sp) + move.w %d4,-(%sp) + move.l %a3,-(%sp) + move.l %a3,-(%sp) + move.l (%a5,1580),%a0 + jsr (%a0) + sub.w %d4,%d3 +.L__fputchar_3: + move.w #4,(%sp) + move.w %d6,-(%sp) + move.w %d3,-(%sp) + move.w %d5,-(%sp) + cmp.b #10,%d6 + jbeq .L__fputchar_4 + move.l (%a5,1680),%a0 + jsr (%a0) + add.w %d7,(%sp) +.L__fputchar_4: + move.l (%a5,1652),%a0 + jsr (%a0) + move.w %d6,%d0 + movm.l -56(%a6),%d3-%d7/%a2-%a5 + unlk %a6 + rts diff --git a/pch/src/tigcc-archive/fputs.s b/pch/src/tigcc-archive/fputs.s new file mode 100644 index 0000000..9e5b75d --- /dev/null +++ b/pch/src/tigcc-archive/fputs.s @@ -0,0 +1,15 @@ +.data + .xdef fputs + .even +.L__fputs_1: + move.l %a0,(%sp,4) + move.l (%sp,8),-(%sp) + move.w %d1,-(%sp) + jsr fputc + addq.l #6,%sp +fputs: + move.l (%sp,4),%a0 + clr.w %d1 + move.b (%a0)+,%d1 + jbne .L__fputs_1 + rts diff --git a/pch/src/tigcc-archive/fread.c b/pch/src/tigcc-archive/fread.c new file mode 100644 index 0000000..0190bb0 --- /dev/null +++ b/pch/src/tigcc-archive/fread.c @@ -0,0 +1,17 @@ +#include + +__ATTR_LIB_C__ unsigned short fread(void *ptr, short size, short n, FILE *f) +{ + unsigned short i,j; + short c,saveflags=f->flags; + f->flags|=_F_BIN; + for(i=0;i<(unsigned short)n;i++) + for(j=0;j<(unsigned short)size;j++) + { + if((c=fgetc(f))<0) goto exit; + *(unsigned char*)ptr++=c; + } +exit: + f->flags=saveflags; + return i; +} diff --git a/pch/src/tigcc-archive/freetimer.s b/pch/src/tigcc-archive/freetimer.s new file mode 100644 index 0000000..4745c2b --- /dev/null +++ b/pch/src/tigcc-archive/freetimer.s @@ -0,0 +1,24 @@ +.data + .xdef OSVFreeTimer + .even +OSVFreeTimer: + move.w (%sp,4),%d0 + subq.w #1,%d0 + cmpi.w #2,%d0 + bcc.s .L__timer_ffai + muls.w #12,%d0 + move.l 0x74,%a0 + cmp.l #132133782,(%a0,-4) + bne.s .L__timer_fok + move.l #-1,-32(%a0,%d0.w) + move.l (%a0,-32),%d0 + and.l (%a0,-20),%d0 + addq.l #1,%d0 + bne.s .L__timer_fok + move.l (%a0,-8),0x40074 +.L__timer_fok: + moveq #1,%d0 + rts +.L__timer_ffai: + clr.w %d0 + rts diff --git a/pch/src/tigcc-archive/fseek.c b/pch/src/tigcc-archive/fseek.c new file mode 100644 index 0000000..c18e26b --- /dev/null +++ b/pch/src/tigcc-archive/fseek.c @@ -0,0 +1,17 @@ +#include +#include + +__ATTR_LIB_C__ short fseek(FILE *f, long offset, short wh) +{ + short bmode=f->flags&_F_BIN; + char *start=(char*)f->base+(bmode?2:5); + char *end=(char*)f->base+peek_w(f->base)+(bmode?2:0); + char *pos=((wh==SEEK_SET)?start:((wh==SEEK_CUR)?(f->fpos):end))+offset; + if(f->flags&_F_ERR) return EOF; + if(pos end||(unsigned short)wh>SEEK_END) __FERROR(f); + f->fpos=pos; + f->unget=0; + if(pos==end) f->flags|=_F_EOF; + else f->flags&=~_F_EOF; + return 0; +} diff --git a/pch/src/tigcc-archive/fsetbufsize.c b/pch/src/tigcc-archive/fsetbufsize.c new file mode 100644 index 0000000..7d2d9bd --- /dev/null +++ b/pch/src/tigcc-archive/fsetbufsize.c @@ -0,0 +1,7 @@ +#include + +__ATTR_LIB_C__ void fsetbufsize(short newsize, FILE *f) +{ + if(newsize && f) + f->buffincrement=newsize; +} diff --git a/pch/src/tigcc-archive/ftell.c b/pch/src/tigcc-archive/ftell.c new file mode 100644 index 0000000..371a928 --- /dev/null +++ b/pch/src/tigcc-archive/ftell.c @@ -0,0 +1,7 @@ +#include + +__ATTR_LIB_C__ long ftell(const FILE *f) +{ + if(f->flags&_F_ERR) return EOF; + return f->fpos-(char*)f->base-((f->flags&_F_BIN)?2:5); +} diff --git a/pch/src/tigcc-archive/fwrite.c b/pch/src/tigcc-archive/fwrite.c new file mode 100644 index 0000000..5124bab --- /dev/null +++ b/pch/src/tigcc-archive/fwrite.c @@ -0,0 +1,14 @@ +#include + +__ATTR_LIB_C__ unsigned short fwrite(const void *ptr, short size, short n, FILE *f) +{ + unsigned short i,j; + short saveflags=f->flags; + f->flags|=_F_BIN; + for(i=0;i<(unsigned short)n;i++) + for(j=0;j<(unsigned short)size;j++) + if(fputc(*(unsigned char*)ptr++,f)<0) goto exit; +exit: + f->flags=saveflags; + return i; +} diff --git a/pch/src/tigcc-archive/getappid.s b/pch/src/tigcc-archive/getappid.s new file mode 100644 index 0000000..20fd0a1 --- /dev/null +++ b/pch/src/tigcc-archive/getappid.s @@ -0,0 +1,57 @@ +.data + .xdef EV_getAppID + .even +EV_getAppID: + link.w %a6,#0 + movem.l %d3-%d4/%a2-%a3,-(%sp) + move.l 8(%a6),%d4 + lea .L__appid_tb(%pc),%a2 + moveq.l #9,%d3 + move.l 0xC8,%a3 + cmp.l #1000,-4(%a3) + jbls .L__appid_lp + move.l %d4,-(%sp) + move.l 4432(%a3),%a0 + jsr (%a0) + tst.w %d0 + jbne .L__appid_end + moveq.l #-1,%d0 + jbra .L__appid_end +.L__appid_lp: + move.l %a2,-(%sp) + move.l %d4,-(%sp) + move.l 2500(%a3),%a0 + jsr (%a0) + addq.l #8,%sp + tst.w %d0 + jbeq .L__appid_fnd +.L__appid_skp: + tst.b (%a2)+ + dbne %d3,.L__appid_lp + jbne .L__appid_skp +.L__appid_fnd: + move.w %d3,%d0 + move.l %a3,%d1 + and.l #0x600000,%d1 + cmp.l #0x400000,%d1 + jbne .L__appid_end + cmp.w #6,%d0 + jble .L__appid_end + addq.w #1,%d0 +.L__appid_end: + movem.l -16(%a6),%d3-%d4/%a2-%a3 + unlk %a6 + rts +.data + .even +.L__appid_tb: + .asciz "TISLFTST" + .asciz "TIINSLVR" + .asciz "TITEXTED" + .asciz "TIPRGMED" + .asciz "TIDMED" + .asciz "TITABLED" + .asciz "TIGRAPH" + .asciz "TIWINDED" + .asciz "TIEQUED" + .asciz "TIHOME" diff --git a/pch/src/tigcc-archive/gray.s b/pch/src/tigcc-archive/gray.s new file mode 100644 index 0000000..6369811 --- /dev/null +++ b/pch/src/tigcc-archive/gray.s @@ -0,0 +1,675 @@ +|****************************************************************************** +| +| project name: GrayScale-Support for TIGCC +| author: thomas.nussbaumer@gmx.net +| Julien Muchembled (original implementation for UniversalOS) +| +| +| compatible with HW1/HW2 on all AMS versions up to 2.05 +| +|****************************************************************************** + +|------------------------------------------------------------------------------ +| uncomment the following global to simulate HW2 on the VTI +| (this will not use port 70001D, therefore it flickers extremely; additionally +| the complete HW detection is bypassed and always reports HW2) +|------------------------------------------------------------------------------ +|.globl ALWAYS_HW2_TESTING + + + .xdef GrayOn,GrayOff,__D_plane,__L_plane,__gray_handle,__gray_hw_type + .xdef __switch_cnt,__gray_old_int1_hw1,__gray_old_int1_hw2 + .xdef __gray_sync_n_count,__gray_plane_index + .xdef __gray_dbl_offset,__L_plane2,__D_plane2 + +.even +|============================================================================== +| EXPORTED: GrayOn function (turn grayscales on) - trashes d1/a0/a1 +|============================================================================== +GrayOn: + move.w (__gray_handle,%pc),%d0 | if __gray_handle is not 0 we have + bne __gray_return_immediately | already allocated memory -> out here + move.l %a5,-(%sp) | we have more than 2 ROM_CALLs + move.l 0xc8.w,%a5 | so we should optimize + lea (__switch_cnt,%pc),%a0 | reset plane switch counter to 0 + clr.l (%a0) + bsr.s __gray_check_hw_version | evaluate HW version and store it + lea (__gray_hw_type,%pc),%a0 + move.w %d0,(%a0) + bsr __gray_init_mem | allocate and initialize memory + move.l (%sp)+,%a5 + move.w (__gray_handle,%pc),%d0 + bne __gray_init_handler | jump to interrupt handler setup if + | memory was allocated correctly + |moveq #0x0,%d0 | otherwise return 0 (GrayOn failed) + rts +|============================================================================== +| checks for HW version (VTI is treated as HW1, because port 0x70001D is not +| emulated by the VTI and this would cause NEVER switch +| planes behaviour if we would use the HW2 support) +| +| returns 0 in d0.w for HW1 and 1 for HW2 +| +| IMPORTANT NOTE: This function patches 2 locations in the code of the +| grayscale support depending on the HW version. Patching the +| locations for both types IS necessary, because if a program +| is transfered from one calc to another one the default values +| got already overwritten (if program was not archived) +|============================================================================== +__gray_check_hw_version: +.ifdef ALWAYS_HW2_TESTING + bra.s __always_hw2_proceed +.endif + move.l %a5,%d0 + and.l #0xE00000,%d0 | get the ROM base + move.l %d0,%a0 + moveq #0,%d0 + move.l 260(%a0),%a1 | get pointer to the hardware param block + add.l #0x10000,%a0 + cmp.l %a0,%a1 | check if the HW parameter block is near + bcc.s __gray_patches_for_hw1 | if it is too far, it is HW1 + cmp.w #22,(%a1) | check if the parameter block contains HW + bls.s __gray_patches_for_hw1 | if it is too small, it is HW1 + cmp.l #1,22(%a1) | check the hardware version + beq.s __gray_patches_for_hw1 | if not 1, it is HW2 (or an unknown HW) + |-------------------------------------------------------------------------- + | check for VTI (trick suggested by Julien Muchembled) + | optimized by Lionel Debroux + |-------------------------------------------------------------------------- + trap #12 | enter supervisor mode. returns old (%sr) in %d0.w + move.w #0x3000,%sr | set a non-existing flag in %sr (but keep s-flag !!) + move.w %d0,%d1 | save %d0.w content in %d1 + move.w %sr,%d0 | get %sr content and check for non-existing flag + move.w %d1,%sr | restore old %sr. + lsl.w #3,%d0 + bpl.s __gray_hw2type_detected | flag not set -> no VTI + |-------------------------------------------------------------------------- + | HW1 detected + |-------------------------------------------------------------------------- + moveq #0,%d0 + |-------------------------------------------------------------------------- + | patches code for HW1 version + | + | necessary memory == 1 plane + 8 Bytes == 3848 + | + | the additionally 8 bytes are necessary for rounding later to a multiple + | of 8 + |-------------------------------------------------------------------------- +__gray_patches_for_hw1: + lea (__gray_size_to_allocate,%pc),%a0 + move.w #0x0f08,(%a0) + clr.w (__gray_size_to_add-__gray_size_to_allocate,%a0) + rts + |-------------------------------------------------------------------------- + | HW2 detected + |-------------------------------------------------------------------------- +__gray_hw2type_detected: +.ifdef ALWAYS_HW2_TESTING +__always_hw2_proceed: +.endif + moveq #1,%d0 + |-------------------------------------------------------------------------- + | patches code for HW2 version + | + | necessary memory == 2 planes + 8 Bytes == 7688 + | + | the additionally 8 bytes are necessary for rounding later to a multiple + | of 8 + |-------------------------------------------------------------------------- + lea (__gray_size_to_allocate,%pc),%a0 + move.w #0x1e08,(%a0) + move.w #0xf00,(__gray_size_to_add - __gray_size_to_allocate,%a0) + rts +__gray_hw_type: | stores HW type (0==HW1 or VTI 1==HW2) + .word 0 +|============================================================================== +| Interrupt 1 handler for HW1 +|============================================================================== +__gray_int1_handler_hw1: + movem.l %d0/%a0,-(%a7) + |-------------------------------------------------------------------------- + | Load skip counter and increment it (count = (count+1)&0x3). Skip any + | further operation if count is 1, 2 or 3. This means that every 4th call + | of the INT1 handler is a candidate for a plane switch + |-------------------------------------------------------------------------- + lea (__gray_skipcount,%pc),%a0 + addq.b #1,(%a0) + andi.b #0x3,(%a0)+ | IMPORTANT: a0 points now to __gray_phase! + bne.s __gray_proceed_old + |-------------------------------------------------------------------------- + | to evaluate which plane we use counter __gray_phase. This counter + | performs the following counting 8->4->0->8. + | 0 will use D_plane pointer + | 4 will use L_plane pointer + | (8 will be skipped, so it stays at D_plane) + |-------------------------------------------------------------------------- + move.w (%a0),%d0 + subq.w #4,%d0 | subtract 4 from phase counter + bcc.s __gray_store | not negative -> don't reset + moveq #0x8,%d0 | reset phase counter to 8 +__gray_store: + move.w %d0,(%a0) | store new phase counter value + cmp.b #8,%d0 + beq.s __gray_proceed_old | for value 8 we do nothing (dark plane + | stays active) + lea (__D_plane,%pc),%a0 + |-------------------------------------------------------------------------- + | doublebuffer extension ... add content of __gray_dbl_offset to %d0 + |-------------------------------------------------------------------------- + add.w (__gray_dbl_offset-__D_plane,%a0),%d0 + suba.w %d0,%a0 + move.l (%a0),%d0 | load the address of this plane + lsr.l #3,%d0 | reduce to address / 8 + move.w %d0,0x600010 | set new plane startaddress + lea (__switch_cnt,%pc),%a0 | increment switch count + addq.l #1,(%a0) +__gray_proceed_old: + movem.l (%a7)+,%d0/%a0 + |-------------------------------------------------------------------------- + | JUMP to previous installed interrupt handler + |-------------------------------------------------------------------------- + .word 0x4ef9 | "JMP address" opcode +__gray_old_int1_hw1: + .long 0x00000000 | address of old int1 gots stored here +__gray_dummy1: | NOT used yet (just for alignment) + .byte 0x00 +|------------------------------------------------------------------------------ +| __gray_skipcount is a one byte counter which performs the following counting: +| 3 -> 0 -> 1 -> 2 -> 3 +|------------------------------------------------------------------------------ +__gray_skipcount: + .byte 0x03 +__gray_phase: + .word 0x04 | performs: 4->0->8->4 +__switch_cnt: + .long 0x00000000 +|============================================================================== +| INTERNAL: allocates memory +| +| modifies: __gray_handle +| __gray_used_mem +| __L_plane +| +| Note: __D_plane will not be changed by this function! (will be set by +| __gray_init_handler) +|============================================================================== +__gray_init_mem: + |-------------------------------------------------------------------------- + | HeapAllocHigh(HW1=3848 bytes or HW2=7688 bytes) + |-------------------------------------------------------------------------- + movea.l (0x92*4,%a5),%a0 /* HeapAllocHigh */ + .word 0x4878 | opcode of "PEA #value" +__gray_size_to_allocate: | the size gets patched !! + .word 0x1e08 + jsr (%a0) + addq.w #4,%a7 + lea (__gray_handle,%pc),%a0 + move.w %d0,(%a0)+ | store handle in handle variable + beq.s __gray_init_return | alloc failed (handle=0) -> out here + clr.w (%a0) | clears __gray_dbl_offset + |-------------------------------------------------------------------------- + | HeapDeref(__gray_handle) + |-------------------------------------------------------------------------- + move.w %d0,-(%a7) + movea.l (0x96*4,%a5),%a0 /* HeapDeref */ + jsr (%a0) + addq.l #2,%a7 + |-------------------------------------------------------------------------- + | align memory address to next 8-byte boundary and store address in + | __gray_used_mem + | + | for HW1: __L_plane gets set to the same address as __gray_used_mem + | for HW2: __L_plane gets set to __gray_used_mem + 0xf00 + |-------------------------------------------------------------------------- + move.l %a0,%d0 + addq.l #7,%d0 + andi.b #0xF8,%d0 + lea (__gray_used_mem,%pc),%a0 + move.l %d0,(%a0) + .word 0x0680 | opcode of "ADDI.L #value,%a0" + .word 0x0000 +__gray_size_to_add: + .word 0x0F00 | gets patched (HW1:0 HW2:0x0f00) + move.l %d0,(__L_plane - __gray_used_mem,%a0) +__gray_init_return: + rts + +|------------------------------------------------------------------------------ +| handle to allocated memory used by grayscale +|------------------------------------------------------------------------------ +__gray_handle: + .word 0 + +|------------------------------------------------------------------------------ +| DOUBLEBUFFER extension +|------------------------------------------------------------------------------ +__gray_dbl_offset: | has to be directly AFTER __gray_handle!! + .word 0 +__L_plane2: + .long 0x0 +__D_plane2: + .long 0x0 + +|------------------------------------------------------------------------------ +| pointer to light plane +| HW1: same as __gray_used_mem +| HW2: __gray_used_mem + 0xf00 +|------------------------------------------------------------------------------ +__L_plane: + .long 0x00004c00 +|------------------------------------------------------------------------------ +| pointer to dark plane (set by __gray_init_handler) +| HW1: 0x4c00 +| HW2: same as __gray_used_mem +|------------------------------------------------------------------------------ +__D_plane: + .long 0x00004c00 +|------------------------------------------------------------------------------ +| pointer to allocated memory ALIGNED to 8-byte boundary +|------------------------------------------------------------------------------ +__gray_used_mem: + .long 0x00004c00 +|------------------------------------------------------------------------------ +| This variable is very hard to describe. Indeed this isn't one variable, +| but two variables combined in one. +| +| Description will be added later .... +|------------------------------------------------------------------------------ +__gray_sync_n_count: + .word 0x0000 +|------------------------------------------------------------------------------ +| holds the index of the plane which should be drawn next (NOTE: this label +| is never addressed directly, but indirectly from label __gray_sync_n_count. +| So don't move it do somewhere else!) +|------------------------------------------------------------------------------ +__gray_plane_index: + .word 0x0000 +|============================================================================== +| Interrupt 1 handler for HW2 +| +| port 70001D (bit 7) is used to synchronized to the LCD hardware. Here are the +| docs of this port (taken from Johan Eilert's j89hw.txt) +| +| $70001D RW ($06) +| :7 Toggles every FS (every time the LCD restarts at line 0) +| :6-4 - +| :3 Battery checker bit B (? ???) +| :2 ? (set) +| :1 Screen enable (clear this bit to shut down LCD) +| :0 Battery checker bit A (? enable $600000:2) +| (AMS:) The battery checker bits must both be set (AB=11) prior to +| checking the voltage level with $600000:2. Then, after use, bit B +| must be cleared (AB=10) while the battery trig hardware settles to +| the "rest" voltage value (%111). Finally, both bits should be +| cleared. +|============================================================================== +__gray_int1_handler_hw2: + move.w %sr,-(%a7) | save content of status register on stack + move.w #0x2700,%sr | disable ALL interrupts (no one should + | interrupt us ...) + movem.l %d0-%d7/%a0-%a6,-(%a7) +__gray_startagain: + moveq #0x0,%d1 + lea (__gray_sync_n_count,%pc),%a0 + move.w (%a0),%d0 + bne.s __gray_copy_first_or_sec | there is a third of the plane left to + | copy -> do it now! + move.l (%a0),%d0 +.ifdef ALWAYS_HW2_TESTING + move.b %d0,%d1 + eor.b #0x80,%d1 +.else + move.b 0x70001D,%d1 | get flipping bit + eor.b %d0,%d1 + bpl __gray_to_oldint | not flipped yet -> proceed to previous + | installed int handler +.endif + eor.l %d1,(%a0) | store new flip "bit" and reset the + | work left status + + |-------------------------------------------------------------------------- + | NOTE: if we detect a pageflip we start our copying work with the lowest + | third. this way it will not interfere with the LCD hardware refresh + | + | The 3 thirds are copied in the following order: + | + | last third -> first third -> second third + |-------------------------------------------------------------------------- + move.w #0xA00,%d0 +__gray_copy_next_third: + addq.w #1,(%a0)+ + bra.s __gray_perform_copying +__gray_copy_first_or_sec: + |-------------------------------------------------------------------------- + | if __gray_sync_n_count == 1 -> copy first third of screen + | otherwise -> set __gray_sync_n_count to 0 and copy second third of screen + |-------------------------------------------------------------------------- + subq.w #1,%d0 + beq.s __gray_copy_next_third + clr.w (%a0)+ + move.w #0x500,%d0 | setup to copy second third of screen +__gray_perform_copying: + move.b (%a0),%d1 | fetch index of plane to draw next + beq __gray_update_index | skip index 0 -> stay at darkplane + + |-------------------------------------------------------------------------- + | If we'll come here we will copy 1 third of the screen from a specific + | plane to the video buffer at 0x4c00. Register D0 holds the offset of + | which third should be copied and register D1 contains the "index" of the + | "source" plane + | + | index = 0 -> darkplane (skipped, will not come here!) + | index = 4 -> darkplane + | index = 8 -> lightplane + | + | Due to the fact that the indices are cycled from 8 down to 0 the skipped + | index 0 causes the darkplane to stay active twice as long as the light + | plane. + | + | The copying is performed in a kind of "hardcore" style by using 13 + | registers. This way 52 Bytes are copied with a single instruction. + |-------------------------------------------------------------------------- + + |-------------------------------------------------------------------------- + | doublebuffer extension ... add content of __gray_dbl_offset to %d0 + |-------------------------------------------------------------------------- + add.w (__gray_dbl_offset,%pc),%d1 + neg.w %d1 + movea.l (__gray_used_mem,%pc,%d1.w),%a0 + + lea 0x4C00.w,%a1 + adda.w %d0,%a0 + adda.w %d0,%a1 + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x34,%a1) | size of this instruction: 6 bytes + movem.l (%a0)+,%d0-%d7/%a2-%a6 | size of this instruction: 4 bytes + movem.l %d0-%d7/%a2-%a6,(0x68,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x9C,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0xD0,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x104,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x138,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x16C,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x1A0,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x1D4,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x208,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x23C,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x270,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x2A4,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x2D8,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x30C,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x340,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x374,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x3A8,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x3DC,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x410,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x444,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x478,%a1) + movem.l (%a0)+,%d0-%d7/%a2-%a6 + movem.l %d0-%d7/%a2-%a6,(0x4AC,%a1) + movem.l (%a0)+,%d0-%d7 + movem.l %d0-%d7,(0x4E0,%a1) + + |-------------------------------------------------------------------------- + | evaluate if there is still a third of the screen to copy or if we + | should proceed to the next plane + |-------------------------------------------------------------------------- +__gray_update_index: + lea (__gray_sync_n_count,%pc),%a0 + move.w (%a0)+,%d0 + beq __gray_startagain | no third left to copy -> check again + | the pageflip bit if yet a pageflip + | had occured + subq.w #1,%d0 + bne.s __gray_to_oldint | if there is "copy work" left -> + | don't modify the plane to display + + lea (__switch_cnt,%pc),%a1 | increment switch count here, because + addq.l #1,(%a1) | a complete page was drawn if we come here + + subq.b #4,(%a0) | cycle __gray_plane_index by decrementing + bcc.s __gray_to_oldint | it and wrap around to 8 if negative. + move.b #0x8,(%a0) +__gray_to_oldint: + movem.l (%a7)+,%d0-%d7/%a0-%a6 + move.w (%a7)+,%sr | restore content of status register + |-------------------------------------------------------------------------- + | JUMP to previous installed interrupt handler + |-------------------------------------------------------------------------- + .word 0x4ef9 | opcode of "JMP address" instruction +__gray_old_int1_hw2: + .long 0x00000000 +|============================================================================== +| INTERNAL: initialize grayscale handler +|============================================================================== +__gray_init_handler: + lea (__L_plane,%pc),%a0 + move.w #0x3BF,%d1 + move.w (__gray_hw_type,%pc),%d0 + beq.s __gray_init_hw1_handler + + |-------------------------------------------------------------------------- + | HW2 specific initializations: + | + | (1) set __D_plane to __gray_used_mem + | (2) copy content of 0x4c00 to darkplane + | (3) "backup" old INT1 handler in __gray_old_int1_hw2 (the address part + | of a JUMP address instruction at the end of the HW2 int handler) + | (4) install our own INT1 HW2 handler + |-------------------------------------------------------------------------- + movea.l (__gray_used_mem,%pc),%a1 + move.l %a1,(0x4,%a0) | set __D_plane + lea 0x4C00.w,%a0 + move.w %d1,%d0 +__gray_cpy_d_plane: + move.l (%a0)+,(%a1)+ + dbf %d0, __gray_cpy_d_plane + lea (__gray_int1_handler_hw2,%pc),%a0 + + | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + | the following command should be unnecessary; I commented it out (TOM) + | (__L_plane should be already set by __gray_init_mem) + | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + |move.l %a1,(__L_plane - __gray_int1_handler_hw2,%a0) + + move.l 0x64,(__gray_old_int1_hw2 - __gray_int1_handler_hw2,%a0) + bra.s __gray_init_proceed + |-------------------------------------------------------------------------- + | HW1 specific initializations: + | + | (1) "backup" old INT1 handler in __gray_old_int1_hw1 (the address part + | of a JUMP address instruction at the end of the HW1 int handler) + | (2) install our own INT1 HW1 handler + |-------------------------------------------------------------------------- +__gray_init_hw1_handler: + move.l (%a0),%a1 + lea (__gray_int1_handler_hw1,%pc),%a0 + move.l 0x64,(__gray_old_int1_hw1 - __gray_int1_handler_hw1,%a0) +__gray_init_proceed: + move.l %a0,%d2 + lea 0x600001,%a0 + moveq.l #2,%d0 + bclr.b %d0,(%a0) + move.l %d2,0x64:w + bset.b %d0,(%a0) +__gray_clr_l_plane: + |-------------------------------------------------------------------------- + | clear light plane (done for both HW types) + |-------------------------------------------------------------------------- + clr.l (%a1)+ + dbf %d1, __gray_clr_l_plane + |-------------------------------------------------------------------------- + | PortSet(__D_plane,239,127) + |-------------------------------------------------------------------------- + move.l #0xEF007F,-(%a7) + move.l (__D_plane,%pc),-(%a7) + movea.l 0xC8,%a0 + movea.l (0x1A2*4,%a0),%a1 /* PortSet */ + jsr (%a1) + addq.w #8,%a7 +__gray_ok: + lea (__L_plane,%pc),%a0 + lea (__L_plane2,%pc),%a1 + move.l (%a0)+,(%a1)+ | copy __L_plane to __L_plane2 + move.l (%a0)+,(%a1)+ | copy __D_plane to __D_plane2 +__gray_return_immediately: + moveq #0x1,%d0 + rts +|============================================================================== +| EXPORTED: GrayOff function (turn grayscales off) +| NOTE: ALWAYS returns 1 !! +|============================================================================== +GrayOff: + lea (__gray_handle,%pc),%a0 + tst.w (%a0) + beq __gray_return_immediately | no handle? -> nothing to do + move.w (%a0),-(%a7) + clr.l (%a0) | 0->handle AND(!!) 0->__gray_dbl_offset + lea 0x600001,%a0 + move.w (__gray_hw_type,%pc),%d0 + beq.s __gray_hw1_cleanup + |-------------------------------------------------------------------------- + | cleanup for HW2 calcs + |-------------------------------------------------------------------------- + moveq.l #2,%d0 + bclr.b %d0,(%a0) + move.l (__gray_old_int1_hw2,%pc),0x64:w | restore old INT1 handler + bset.b %d0,(%a0) + movea.l (__D_plane,%pc),%a1 + lea 0x4C00.w,%a0 + move.w #0x3BF,%d0 | copy content of darkplane to 0x4c00 +__gray_dark2lcd: + move.l (%a1)+,(%a0)+ + dbf %d0, __gray_dark2lcd + bra.s __gray_continue_cleanup + |-------------------------------------------------------------------------- + | cleanup for HW1 calcs (on HW1 0x4c00 is used as darkplane. We haven't to + | set it) + |-------------------------------------------------------------------------- +__gray_hw1_cleanup: + move.w #0x980,(0x600010-0x600001,%a0) | restore used plane to 0x4c00 + move.l (__gray_old_int1_hw1,%pc),0x40064 | restore old INT1 handler + | (We can use 0x40064 here because it is HW1 only.) + +__gray_continue_cleanup: + lea (__L_plane,%pc),%a0 | restore plane pointers to 0x4c00 for sure + lea 0x4C00.w,%a1 + move.l %a1,(%a0)+ + move.l %a1,(%a0)+ + move.l %a1,(%a0) + |-------------------------------------------------------------------------- + | HeapFree(__gray_handle) + |-------------------------------------------------------------------------- + movea.l 0xc8,%a0 + movea.l (0x97*4,%a0),%a0 /* HeapFree */ + jsr (%a0) + addq.l #2,%a7 + |-------------------------------------------------------------------------- + | PortRestore() + |-------------------------------------------------------------------------- + movea.l 0xc8,%a0 + movea.l (0x1A3*4,%a0),%a0 /* PortRestore */ + jsr (%a0) + lea (__gray_sync_n_count,%pc),%a0 + clr.l (%a0) +__gray_off_out: + jbra __gray_ok + +| ############################################################################# +| Revision History +| ############################################################################# +| +| Revision 3.17 2006/10/30 07:24:15 Kevin Kofler +| Bumped version to 3.55. +| Size optimization by Martial Demolins (use moveq instead of bclr/bset #imm). +| +| Revision 3.16 2005/10/09 01:48:20 Kevin Kofler +| Bumped version to 3.54. +| Size optimization by Jesse Frey (register saving, ROM_CALL optimization), +| spelling/typo fixes by Kevin Kofler. +| +| Revision 3.15 2005/08/22 20:23:40 Kevin Kofler +| Bumped version to 3.53. +| Fixed calls to GrayOn with grayscale already enabled. +| +| Revision 3.14 2005/07/02 02:56:36 Kevin Kofler +| Bumped version to 3.52. +| +| Revision 3.13 2005/06/11 05:58:27 Kevin Kofler +| Removed commented-out junk. +| Remove Id and Log tags. +| +| Revision 3.12 2005/06/07 16:51:00 Lionel Debroux +| Optimized the routine for size: saved 40 bytes. +| +| Revision 3.11 2004/02/25 03:49:03 Kevin Kofler +| Don't use 0x40000 to set interrupts on code path that affect HW3. +| Use 0xE00000 as ROM_base mask instead of 0x600000. +| Bumped version to 3.51. +| +| Revision 3.10 2002/04/05 11:34:23 tnussb +| (1) Resets now __D_plane2,__L_plane2 and __gray_dbl_offset at end of GrayOn() +| to make sure nothing happens if doublebuffer macros get called without +| setting a buffer first. Nevertheless NO program should call one of the +| doublebuffer macros without setting a buffer previously. +| (2) Some further size optimizations. Now the size is exactly as long as +| without before the integration of doublebuffering. Quite smart, isn't it? +| More functionality, some minor drawbacks fixed and no increase in size ... +| (3) Changed return value of GrayOff() function to void. +| +| Revision 3.9 2002/04/04 18:50:36 tnussb +| first working version of internal doublebuffer support (not checked on +| real calcs yet, but on the VTI) +| +| Revision 3.8 2002/04/04 16:39:05 tnussb +| Debug version checked in previously. This one is the correct one. +| +| Revision 3.7 2002/04/04 16:35:20 tnussb +| (1) documentation of HW2 interrupt handler heavily extended +| (2) HW2: plane switch counting fixed (was incremented too often previously) +| (3) global ALWAYS_HW2_TESTING added which can be used to force the use of +| HW2 grayscales. Now the HW2 grayscales can be tested on the VTI if +| this global is defined. Of course this will flicker extremely, because +| the VTI doesn't simulate port 70001D, but its still better than no +| testing possibility. +| (4) don't trashes %sr on HW2 anymore (restores previous setting) +| (5) This version was tested on a real HW1 and a real HW2 calc. It works. +| (Thanx to Sebastian Reichelt and stoopid guy) +| +| Revision 3.6 2002/04/04 11:58:19 tnussb +| (1) size optimizations +| (2) unnecessary cleanup removed from GrayOff() +| (3) interrupt handler for HW1 rewritten (uses now plane pointer directly) +| (4) "heavily" documented +| +| Revision 3.5 2002/04/04 11:54:39 tnussb +| (1) exports __gray_old_int1_hw1 and __gray_old_int1_hw2. this way it is +| possible to modify them after grayscales are turned on +| (2) comments changed to GNU Assembler style +| [NOTE: CVS time and date doesn't fit to real implementation data] +| +| Revision 3.0 2002/04/04 11:50:56 tnussb +| grayscale support used for TIGCC up to version v0.93 +| [NOTE: CVS time and date doesn't fit to real implementation data] +| diff --git a/pch/src/tigcc-archive/grayversion.c b/pch/src/tigcc-archive/grayversion.c new file mode 100644 index 0000000..bc04501 --- /dev/null +++ b/pch/src/tigcc-archive/grayversion.c @@ -0,0 +1 @@ +volatile char __gray_version[] = "[TIGCCLIB GraySupport v3.50 "__DATE__" "__TIME__"]"; diff --git a/pch/src/tigcc-archive/homestore.s b/pch/src/tigcc-archive/homestore.s new file mode 100644 index 0000000..34c4a11 --- /dev/null +++ b/pch/src/tigcc-archive/homestore.s @@ -0,0 +1,22 @@ +| Workaround for HomePushEStack which does not redraw the Home screen +| Copyright (C) Samuel Stearley, 2002 + +.data + .even + .xdef HomeStore +HomeStore: + move.l %a3,-(%sp) + move.l 0xC8,%a1 + move.l 0x2A3*4(%a1),%a3 + move.l (%a3),-(%sp) + lea .L__NewHook,%a0 + move.l %a0,(%a3) + move.l 0x10F*4(%a1),%a0 /* HomePushEStack */ + jsr (%a0) + move.l (%sp)+,(%a3) + move.l (%sp)+,%a3 + rts +.L__NewHook: + move.l 4(%sp),%a0 + move.w #0x700,(%a0) + rts diff --git a/pch/src/tigcc-archive/homestorepair.c b/pch/src/tigcc-archive/homestorepair.c new file mode 100644 index 0000000..c35e18a --- /dev/null +++ b/pch/src/tigcc-archive/homestorepair.c @@ -0,0 +1,25 @@ +#include +#include +#include + +__ATTR_LIB_C__ void HomeStorePair(HANDLE Entry, HANDLE Ans) +{ + HANDLE hNode; + TRY + hNode = HS_newFIFONode (); + ONERR + HeapFree (Entry); + if (Ans != Entry) + HeapFree (Ans); + PASS; + ENDTRY + TRY + FIFO_NODE *Node = HeapDeref (hNode); + Node->Entry.Expr = Entry; + Node->Ans.Expr = Ans; + HS_pushEmptyFIFONode (hNode); + ONERR + HS_freeFIFONode (hNode); + PASS; + ENDTRY +} diff --git a/pch/src/tigcc-archive/hrealloc_throw.s b/pch/src/tigcc-archive/hrealloc_throw.s new file mode 100644 index 0000000..7015036 --- /dev/null +++ b/pch/src/tigcc-archive/hrealloc_throw.s @@ -0,0 +1,17 @@ +| Warning: This routine has the attribute __ATTR_TIOS__! +| It is a simple wrapper for a TIOS function. + +.data + .even + .xdef HeapReallocThrow +HeapReallocThrow: + lea.l .L__finished+2,%a0 + move.l (%sp)+,(%a0) + move.l 0xC8,%a0 + move.l (%a0,0x9D*4),%a0 /* HeapRealloc */ + jsr (%a0) + tst.w %d0 + jbne .L__finished + .word 0xA000+670 +.L__finished: + jmp.l 0:l diff --git a/pch/src/tigcc-archive/isextalnum.s b/pch/src/tigcc-archive/isextalnum.s new file mode 100644 index 0000000..608853a --- /dev/null +++ b/pch/src/tigcc-archive/isextalnum.s @@ -0,0 +1,5 @@ +.data + .even + .xdef _extalnum_list +_extalnum_list: + .long 0, 65283, -16777337, -16777465, -1106176, 8192, -32769, -32769 diff --git a/pch/src/tigcc-archive/isextpunct.s b/pch/src/tigcc-archive/isextpunct.s new file mode 100644 index 0000000..653a8bb --- /dev/null +++ b/pch/src/tigcc-archive/isextpunct.s @@ -0,0 +1,5 @@ +.data + .even + .xdef _extpunct_list +_extpunct_list: + .long 12648447, -16842500, 16777336, 16777464, 1106175, -8193, 32768, 32768 diff --git a/pch/src/tigcc-archive/kbd_queue.s b/pch/src/tigcc-archive/kbd_queue.s new file mode 100644 index 0000000..2597a21 --- /dev/null +++ b/pch/src/tigcc-archive/kbd_queue.s @@ -0,0 +1,7 @@ +.data + .xdef kbd_queue + .even +kbd_queue: + moveq.l #6,%d0 + trap #9 + rts diff --git a/pch/src/tigcc-archive/loaddll_throw.s b/pch/src/tigcc-archive/loaddll_throw.s new file mode 100644 index 0000000..7346e94 --- /dev/null +++ b/pch/src/tigcc-archive/loaddll_throw.s @@ -0,0 +1,14 @@ +| Warning: This routine has the attribute __ATTR_LIB_C__! +| It is a simple wrapper for a C function. + + .even + .xdef LoadDLLThrow +LoadDLLThrow: + lea.l .L__finished+2,%a0 + move.l (%sp)+,(%a0) + jbsr LoadDLL + tst.w %d0 + jbeq .L__finished + .word 0xA000+850 +.L__finished: + jmp.l 0:l diff --git a/pch/src/tigcc-archive/lshrdi.s b/pch/src/tigcc-archive/lshrdi.s new file mode 100644 index 0000000..8fc3a30 --- /dev/null +++ b/pch/src/tigcc-archive/lshrdi.s @@ -0,0 +1,24 @@ +|lshrdi3 routine copyright (C) 2002, Kevin Kofler + +.data + xdef __lshrdi3 + .even +__lshrdi3: + tst.w 12(%a7) + bne.s .L__lshrdi3_return0 + move.l 4(%a7),%d0 + move.l 8(%a7),%d1 + move.w 14(%a7),%d2 + beq.s .L__lshrdi3_returnn + subq.w #1,%d2 +.L__lshrdi3_loop: + lsr.l #1,%d0 + roxr.l #1,%d1 + dbra.w %d2,.L__lshrdi3_loop +.L__lshrdi3_returnn: + rts + +.L__lshrdi3_return0: + moveq.l #0,%d0 + moveq.l #0,%d1 + rts diff --git a/pch/src/tigcc-archive/malloc_throw.s b/pch/src/tigcc-archive/malloc_throw.s new file mode 100644 index 0000000..99fd656 --- /dev/null +++ b/pch/src/tigcc-archive/malloc_throw.s @@ -0,0 +1,18 @@ +| Warning: This routine has the attribute __ATTR_TIOS__! +| It is a simple wrapper for a TIOS function. + +.data + .even + .xdef malloc_throw,HeapAllocPtrThrow +malloc_throw: +HeapAllocPtrThrow: + lea.l .L__finished+2,%a0 + move.l (%sp)+,(%a0) + move.l 0xC8,%a0 + move.l (%a0,0xA2*4),%a0 /* HeapAllocPtr */ + jsr (%a0) + move.l %a0,%d0 + jbne .L__finished + .word 0xA000+670 +.L__finished: + jmp.l 0:l diff --git a/pch/src/tigcc-archive/moddi.s b/pch/src/tigcc-archive/moddi.s new file mode 100644 index 0000000..3df288e --- /dev/null +++ b/pch/src/tigcc-archive/moddi.s @@ -0,0 +1,30 @@ +|moddi3 routine copyright (C) 2002, Kevin Kofler +|WARNING: Division by 0 will be handled the same way as in the unsigned variant. +| For my __umoddi3, this means: +| A division by 0 will not cause an exception, but just crash in an +| infinite loop! + +.data + xdef __moddi3 + .even +__moddi3: + tst.b 12(%a7) + bge.s .L__moddi3_denom_positive + neg.l 16(%a7) + negx.l 12(%a7) +.L__moddi3_denom_positive: + tst.b 4(%a7) + blt.s .L__moddi3_numer_negative +.L__moddi3_umoddi3: + jbra __umoddi3 + +.L__moddi3_numer_negative: + neg.l 8(%a7) + negx.l 4(%a7) + lea.l (.L__moddi3_return_jump+2,%PC),%a0 + move.l (%a7)+,(%a0) + bsr.s .L__moddi3_umoddi3 + neg.l %d1 + negx.l %d0 +.L__moddi3_return_jump: + jmp.l 0:l diff --git a/pch/src/tigcc-archive/modsi.s b/pch/src/tigcc-archive/modsi.s new file mode 100644 index 0000000..0e5681b --- /dev/null +++ b/pch/src/tigcc-archive/modsi.s @@ -0,0 +1,6 @@ +.data + .xdef __modsi3 + .even +__modsi3: + move.w #0x2A9*4,%d2 /* _ms32s32 */ + jra __div_entry diff --git a/pch/src/tigcc-archive/mulbf.s b/pch/src/tigcc-archive/mulbf.s new file mode 100644 index 0000000..6d94350 --- /dev/null +++ b/pch/src/tigcc-archive/mulbf.s @@ -0,0 +1,6 @@ +.data + .xdef __mulbf3 + .even +__mulbf3: + moveq.l #8,%d0 + bra __fp_entry diff --git a/pch/src/tigcc-archive/muldi.s b/pch/src/tigcc-archive/muldi.s new file mode 100644 index 0000000..3dbbbac --- /dev/null +++ b/pch/src/tigcc-archive/muldi.s @@ -0,0 +1,58 @@ +|muldi3 routine copyright (C) 2002, Kevin Kofler + +.data + .xdef __muldi3 + .even +__muldi3: + move.w 18(%a7),%d0 + mulu 4(%a7),%d0 + move.w 16(%a7),%d2 + mulu 6(%a7),%d2 + add.w %d2,%d0 + move.w 14(%a7),%d2 + mulu 8(%a7),%d2 + add.w %d2,%d0 + move.w 12(%a7),%d2 + mulu 10(%a7),%d2 + add.w %d2,%d0 + swap %d0 + clr.w %d0 + + move.w 18(%a7),%d2 + mulu 6(%a7),%d2 + add.l %d2,%d0 + move.w 16(%a7),%d2 + mulu 8(%a7),%d2 + add.l %d2,%d0 + move.w 14(%a7),%d2 + mulu 10(%a7),%d2 + add.l %d2,%d0 + + move.w 18(%a7),%d1 + mulu 8(%a7),%d1 + swap %d1 + add.w %d1,%d0 + clr.w %d1 + swap %d0 + addx.w %d1,%d0 + swap %d0 + + move.w 16(%a7),%d2 + mulu 10(%a7),%d2 + swap %d2 + add.w %d2,%d0 + clr.w %d2 + swap %d0 + addx.w %d2,%d0 + swap %d0 + add.l %d2,%d1 + moveq.l #0,%d2 + addx.l %d2,%d0 + + move.w 18(%a7),%d2 + mulu 10(%a7),%d2 + add.l %d2,%d1 + moveq.l #0,%d2 + addx.l %d2,%d0 + + rts diff --git a/pch/src/tigcc-archive/mulsi.s b/pch/src/tigcc-archive/mulsi.s new file mode 100644 index 0000000..f38f06c --- /dev/null +++ b/pch/src/tigcc-archive/mulsi.s @@ -0,0 +1,17 @@ +.data + .xdef __mulsi3 + .even +__mulsi3: + move.l (4,%sp),%d1 + move.l (8,%sp),%d2 + move.l %d2,%d0 + mulu %d1,%d0 + swap %d2 + mulu %d1,%d2 + swap %d1 + mulu (10,%sp),%d1 + add.w %d1,%d2 + swap %d2 + clr.w %d2 + add.l %d2,%d0 + rts diff --git a/pch/src/tigcc-archive/negbf.s b/pch/src/tigcc-archive/negbf.s new file mode 100644 index 0000000..ce9246e --- /dev/null +++ b/pch/src/tigcc-archive/negbf.s @@ -0,0 +1,6 @@ +.data + .xdef __negbf2 + .even +__negbf2: + moveq.l #16,%d0 + bra __fp_entry diff --git a/pch/src/tigcc-archive/nocallback.s b/pch/src/tigcc-archive/nocallback.s new file mode 100644 index 0000000..13aa4d3 --- /dev/null +++ b/pch/src/tigcc-archive/nocallback.s @@ -0,0 +1,8 @@ +| Warning: This routine has the attribute __ATTR_TIOS_CALLBACK__! + +.data + .xdef NoCallBack + .even +NoCallBack: + moveq.l #1,%d0 + rts diff --git a/pch/src/tigcc-archive/printf.s b/pch/src/tigcc-archive/printf.s new file mode 100644 index 0000000..75fa37b --- /dev/null +++ b/pch/src/tigcc-archive/printf.s @@ -0,0 +1,17 @@ +| Warning: This routine has the attribute __ATTR_TIOS__! + +.data + .xdef printf + .even +printf: + movea.l 0xC8,%a0 + movea.l (%a0,0x14C),%a0 /* vcbprintf */ + lea (%a0,32),%a0 + movea.w (%a0),%a1 + pea (%sp,8) + move.l (%sp,8),-(%sp) + clr.l -(%sp) + pea fputchar + jsr (%a0.l,%a1) + lea (%sp,16),%sp + rts diff --git a/pch/src/tigcc-archive/push_longint.s b/pch/src/tigcc-archive/push_longint.s new file mode 100644 index 0000000..0be4332 --- /dev/null +++ b/pch/src/tigcc-archive/push_longint.s @@ -0,0 +1,43 @@ +.data + .xdef push_longint + .even +push_longint: +| Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack. +| Only two are needed, but this is smaller than subtracting and adding. + movem.l %d2-%d6/%a5,-(%sp) +| Put address of push_quantum into %a5. + move.l 0xC8,%a5 + move.l (%a5,3000),%a5 /* push_quantum */ +| %d4: Number of bytes. + clr.w %d4 +| Put POSINT_TAG in %d6. + moveq.l #31,%d6 +| Move parameter to %d3. + move.l 28(%sp),%d3 +| If it is zero, the value should be zero bytes long. + jbeq .L__finished +| If negative, put NEGINT_TAG in %d6 and negate it. + jbge .L__mainloop + moveq.l #32,%d6 + neg.l %d3 +.L__mainloop: +| Push rightmost quantum of the value. + move.w %d3,(%sp) + jsr (%a5) +| Add 1 to the number of bytes. + addq.w #1,%d4 +| Shift the value to the right by one quantum. + lsr.l #8,%d3 +| Finished if remaining value is zero. + jbne .L__mainloop +.L__finished: +| Push number of bytes. + move.w %d4,(%sp) + jsr (%a5) +| Push tag. + move.w %d6,(%sp) + jsr (%a5) +| See above. +| There is no problem in "restoring" %d2, since it may be trashed. + movem.l (%sp)+,%d2-%d6/%a5 + rts diff --git a/pch/src/tigcc-archive/push_longlongint.s b/pch/src/tigcc-archive/push_longlongint.s new file mode 100644 index 0000000..4599a0c --- /dev/null +++ b/pch/src/tigcc-archive/push_longlongint.s @@ -0,0 +1,50 @@ +.data + .xdef push_longlongint + .even +push_longlongint: +| Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack. +| Only two are needed, but this is smaller than subtracting and adding. + movem.l %d2-%d7/%a5,-(%sp) +| Put address of push_quantum into %a5. + move.l 0xC8,%a5 + move.l (%a5,3000),%a5 /* push_quantum */ +| %d7: Number of bytes. + clr.w %d7 +| Put POSINT_TAG in %d6. + moveq.l #31,%d6 +| Move parameter to %d3/%d4. + movem.l 32(%sp),%d3-%d4 +| If negative, put NEGINT_TAG in %d6 and negate it. +| We only need to look at %d3 because of how numbers are stored. + tst.l %d3 + jbge .L__mainloop + moveq.l #32,%d6 + neg.l %d4 + negx.l %d3 +.L__mainloop: +| Finished if remaining value is zero. + move.l %d3,%d0 + or.l %d4,%d0 + jbeq .L__finished +| Push rightmost quantum of the value. + move.w %d4,(%sp) + jsr (%a5) +| Add 1 to the number of bytes. + addq.w #1,%d7 +| Shift the value to the right by one quantum. + move.b %d3,%d4 + lsr.l #8,%d3 + ror.l #8,%d4 +| Always repeat the loop at this point. + jbra .L__mainloop +.L__finished: +| Push number of bytes. + move.w %d7,(%sp) + jsr (%a5) +| Push tag. + move.w %d6,(%sp) + jsr (%a5) +| See above. +| There is no problem in "restoring" %d2, since it may be trashed. + movem.l (%sp)+,%d2-%d7/%a5 + rts diff --git a/pch/src/tigcc-archive/push_shortint.s b/pch/src/tigcc-archive/push_shortint.s new file mode 100644 index 0000000..3a6e5d4 --- /dev/null +++ b/pch/src/tigcc-archive/push_shortint.s @@ -0,0 +1,43 @@ +.data + .xdef push_shortint + .even +push_shortint: +| Saving %d2 as well is a really dirty trick to reserve four extra bytes on the stack. +| Only two are needed, but this is smaller than subtracting and adding. + movem.l %d2-%d6/%a5,-(%sp) +| Put address of push_quantum into %a5. + move.l 0xC8,%a5 + move.l (%a5,3000),%a5 /* push_quantum */ +| %d4: Number of bytes. + clr.w %d4 +| Put POSINT_TAG in %d6. + moveq.l #31,%d6 +| Move parameter to %d3. + move.w 28(%sp),%d3 +| If it is zero, the value should be zero bytes long. + jbeq .L__finished +| If negative, put NEGINT_TAG in %d6 and negate it. + jbge .L__mainloop + moveq.l #32,%d6 + neg.w %d3 +.L__mainloop: +| Push rightmost quantum of the value. + move.w %d3,(%sp) + jsr (%a5) +| Add 1 to the number of bytes. + addq.w #1,%d4 +| Shift the value to the right by one quantum. + lsr.w #8,%d3 +| Finished if remaining value is zero. + jbne .L__mainloop +.L__finished: +| Push number of bytes. + move.w %d4,(%sp) + jsr (%a5) +| Push tag. + move.w %d6,(%sp) + jsr (%a5) +| See above. +| There is no problem in "restoring" %d2, since it may be trashed. + movem.l (%sp)+,%d2-%d6/%a5 + rts diff --git a/pch/src/tigcc-archive/pushfifonode.c b/pch/src/tigcc-archive/pushfifonode.c new file mode 100644 index 0000000..827e910 --- /dev/null +++ b/pch/src/tigcc-archive/pushfifonode.c @@ -0,0 +1,16 @@ +#include +#include + +__ATTR_LIB_C__ __HS_pushEmptyFIFONode__type__ __get_HS_pushEmptyFIFONode(void) +{ + short *Ptr = (void*)HomePushEStack, *EndPtr = Ptr + 0x80; + for (; (unsigned long)Ptr < (unsigned long)EndPtr; Ptr++) + if (*Ptr == 0x4EBA) /* bsr */ + { + Ptr++; + void *Addr = (char*)Ptr + *Ptr; + if (Addr != HS_newFIFONode) + return Addr; + } + ER_throw (410); +} diff --git a/pch/src/tigcc-archive/puts.s b/pch/src/tigcc-archive/puts.s new file mode 100644 index 0000000..e0e59c4 --- /dev/null +++ b/pch/src/tigcc-archive/puts.s @@ -0,0 +1,13 @@ +.data + .xdef puts + .even +.L__puts_1: + move.l %a0,(%sp,4) + move.w %d0,-(%sp) + jsr fputchar + addq.l #2,%sp +puts: + move.l (%sp,4),%a0 + move.b (%a0)+,%d0 + jbne .L__puts_1 + rts diff --git a/pch/src/tigcc-archive/qsort.c b/pch/src/tigcc-archive/qsort.c new file mode 100644 index 0000000..4857fdc --- /dev/null +++ b/pch/src/tigcc-archive/qsort.c @@ -0,0 +1,22 @@ +#include + +// Do not use register a5; callback function might need it. +register long __tbl asm ("a5"); + +__ATTR_LIB_C__ void qsort(void *list, short num_items, short size, compare_t cmp_func) +{ + unsigned short gap,byte_gap,i,j; + char *p,*a,*b,temp; + for (gap=((unsigned short)num_items)>>1; gap>0; gap>>=1) // Yes, this is not a quicksort, + { // but works fast enough... + byte_gap=gap*(unsigned short)size; + for(i=byte_gap; i<((unsigned short)num_items)*(unsigned short)size; i+=size) + for(p=(char*)list+i-byte_gap; p>=(char*)list; p-= byte_gap) + { + a=p; b=p+byte_gap; + if(cmp_func(a,b)<=0) break; + for(j=size;j;j--) + temp=*a, *a++=*b, *b++=temp; + } + } +} diff --git a/pch/src/tigcc-archive/rand.s b/pch/src/tigcc-archive/rand.s new file mode 100644 index 0000000..80a15d4 --- /dev/null +++ b/pch/src/tigcc-archive/rand.s @@ -0,0 +1,26 @@ +.data + .xdef rand,__randseed + .even +rand: + lea __randseed(%pc),%a0 + move.l #0x41C64E6D,%d2 + move.l (%a0),%d1 + move.l %d2,%d0 + mulu %d1,%d0 + swap %d2 + mulu %d1,%d2 + swap %d1 + mulu #0x4E6D,%d1 + add.w %d1,%d2 + swap %d2 + clr.w %d2 + add.l %d2,%d0 + add.l #12345,%d0 + move.l %d0,(%a0) + lsr.l #8,%d0 + and.w #32767,%d0 + rts +.data + .even +__randseed: + .long 1 diff --git a/pch/src/tigcc-archive/realloc.s b/pch/src/tigcc-archive/realloc.s new file mode 100644 index 0000000..07a62ed --- /dev/null +++ b/pch/src/tigcc-archive/realloc.s @@ -0,0 +1,38 @@ +.data + .xdef realloc + .even +realloc: + link.w %a6,#0 + movm.l %d3/%a2-%a3,-(%sp) + move.l 0xC8,%a2 + move.l 12(%a6),%a3 /* new size */ + tst.l 8(%a6) /* address==0? */ + jbeq .L__realloc_0 + move.l 8(%a6),%a0 /* address */ + move.w -2(%a0),%d3 /* handle */ + move.w %d3,-(%sp) + move.l 636(%a2),%a0 /* HeapUnlock */ + jsr (%a0) + pea 2(%a3) /* reallocate a block of size+2 bytes */ + move.w %d3,-(%sp) + move.l 628(%a2),%a0 /* HeapRealloc */ + jsr (%a0) + tst.w %d0 + jbne .L__realloc_1 + move.l 604(%a2),%a0 /* HeapFree */ + jsr (%a0) + sub.l %a0,%a0 + jbra .L__realloc_2 +.L__realloc_0: + pea (%a3) + move.l 648(%a2),%a0 /* HeapAllocPtr */ + jsr (%a0) + jbra .L__realloc_2 +.L__realloc_1: + move.l 612(%a2),%a0 /* HLock */ + jsr (%a0) + addq.l #2,%a0 /* skip the handle */ +.L__realloc_2: + movm.l -12(%a6),%d3/%a2-%a3 + unlk %a6 + rts diff --git a/pch/src/tigcc-archive/realloc_throw.s b/pch/src/tigcc-archive/realloc_throw.s new file mode 100644 index 0000000..d625a4d --- /dev/null +++ b/pch/src/tigcc-archive/realloc_throw.s @@ -0,0 +1,12 @@ +.data + .even + .xdef realloc_throw +realloc_throw: + lea.l .L__finished+2,%a0 + move.l (%sp)+,(%a0) + jbsr realloc + move.l %a0,%d0 + jbne .L__finished + .word 0xA000+670 +.L__finished: + jmp.l 0:l diff --git a/pch/src/tigcc-archive/registertimer.s b/pch/src/tigcc-archive/registertimer.s new file mode 100644 index 0000000..25e93a5 --- /dev/null +++ b/pch/src/tigcc-archive/registertimer.s @@ -0,0 +1,56 @@ +.data + .xdef OSVRegisterTimer + .even +OSVRegisterTimer: + move.w (%sp,4),%d0 + subq.w #1,%d0 + cmpi.w #2,%d0 + bcc.s .L__timer_rfai + muls.w #12,%d0 + move.l 0x74,%a0 + cmpi.l #132133782,(%a0,-4) + beq.s .L__timer_rins + lea .L__timer_told(%pc),%a1 + move.l %a0,(%a1) + lea .L__timer_rti5(%pc),%a0 +.L__timer_rins: + lea -32(%a0,%d0.w),%a1 + cmpi.l #-1,(%a1) + bne.s .L__timer_rfai + move.l (%sp,6),(%a1) + move.l (%sp,6),(%a1,4) + move.l (%sp,10),(%a1,8) + move.l %a0,0x40074 + moveq #1,%d0 + rts +.L__timer_rfai: + clr.w %d0 + rts +.data + .even +.L__timer_ttab: + .long -1,0,0,-1,0,0 +.L__timer_told: + .long 0 + .long 132133782 /* magic */ +.data + .even +.L__timer_rti5: + move.w #0x2700,%sr + movem.l %d0-%d7/%a0-%a6,-(%sp) + lea .L__timer_ttab(%pc),%a4 + moveq #1,%d4 +.L__timer_i5lp: + cmpi.l #-1,(%a4) + beq.s .L__timer_i5sk + subq.l #1,(%a4,4) + bne.s .L__timer_i5sk + move.l (%a4),(%a4,4) + move.l (%a4,8),%a0 + jsr (%a0) +.L__timer_i5sk: + lea (%a4,12),%a4 + dbra %d4,.L__timer_i5lp + movem.l (%sp)+,%d0-%d7/%a0-%a6 + move.l .L__timer_told(%pc),-(%sp) + rts diff --git a/pch/src/tigcc-archive/rename.c b/pch/src/tigcc-archive/rename.c new file mode 100644 index 0000000..7624bfb --- /dev/null +++ b/pch/src/tigcc-archive/rename.c @@ -0,0 +1,10 @@ +#include +#include + +__ATTR_LIB_C__ short rename(const char *old, const char *new) +{ + char sym[100],*sptrold=sym,*sptrnew; + *sptrold=0; while((*++sptrold=*old++)); + sptrnew=sptrold; while((*++sptrnew=*new++)); + return SymMove(sptrold,sptrnew)-1; +} diff --git a/pch/src/tigcc-archive/rowread.s b/pch/src/tigcc-archive/rowread.s new file mode 100644 index 0000000..e7440da --- /dev/null +++ b/pch/src/tigcc-archive/rowread.s @@ -0,0 +1,16 @@ +.data + .xdef _rowread +_rowread: +| Write the mask to the port + move.w (%sp,4),0x600018 +| Wait for a few milliseconds until the I/O can return a valid value + move.w #24,%d0 +0: + dbra %d0,0b +| Read the port and write it to %d0 (return value register) + move.b 0x60001B,%d0 +| Invert the byte + not.b %d0 + and.w #0xFF,%d0 +| Return + rts diff --git a/pch/src/tigcc-archive/sprite16.c b/pch/src/tigcc-archive/sprite16.c new file mode 100644 index 0000000..5db2853 --- /dev/null +++ b/pch/src/tigcc-archive/sprite16.c @@ -0,0 +1,18 @@ +#include + +__ATTR_LIB_C__ void Sprite16(short x, short y, short h, unsigned short *sprite, void *buff, short mode) +{ + long addr=(long)buff+30*y+((x>>3)&0xfffe),d1; + unsigned short cnt=16-(x&15),data; + for(;h--;addr+=30) + { + data=*sprite++; + if(mode==SPRT_AND) *(long*)addr&=~((long)~data< + +__ATTR_LIB_C__ void Sprite32(short x, short y, short h, unsigned long *sprite, void *buff, short mode) +{ + long addr=(long)buff+30*y+((x>>3)&0xfffe); + unsigned long data,d1,d2; + short cnt=x&15,ccnt=32-cnt; + for(;h--;addr+=30) + { + data=*sprite++; + if(mode==SPRT_AND) + { + data=~data; + *(long*)addr&=~(data>>cnt),*(long*)(addr+4)&=~(data< >cnt; d2=data< + +__ATTR_LIB_C__ void Sprite8(short x, short y, short h, unsigned char *sprite, void *buff, short mode) +{ + long addr=(long)buff+30*y+((x>>3)&0xfffe),d1; + unsigned short cnt=24-(x&15),data; + for(;h--;addr+=30) + { + data=*sprite++; + if(mode==SPRT_AND) *(long*)addr&=~((long)(~data&0xff)< +#include + +__ATTR_LIB_C__ long strtol(const char *nptr, char **endptr, short base) +{ + const unsigned char *s=nptr; + unsigned long acc,cutoff,cb; + unsigned short c,cutlim,neg=0; + short any; + do {c=*s++;} while (c==' '); + if(c=='-'||c==0xAD) neg=1, c=*s++; + else if (c=='+') c=*s++; + if((base==0||base==16)&&c=='0'&&(*s=='x'||*s=='X')) + { + c=s[1]; s+=2; base=16; + } + if(base==0) base=c=='0'?8:10; + cb=neg?0x80000000:0x7FFFFFFF; + asm volatile("\n" + " move.l %3,%%d1\n" + " move.l %2,%%d0\n" + " move.l 0xC8,%%a0\n" + " move.l (%%a0,2728),%%a0\n" + " jsr (%%a0)\n" + " move.l %%d1,%0\n" + " move.l %3,%%d1\n" + " move.l %2,%%d0\n" + " move.l 0xC8,%%a0\n" + " move.l (%%a0,2732),%%a0\n" + " jsr (%%a0)\n" + " move.w %%d1,%1":"=g"(cutoff),"=g"(cutlim):"g"((unsigned long)base), + "g"(cb):"a0","a1","d0","d1","d2"); + for(acc=0,any=0;;c=*s++) + { + if(isdigit(c)) c-='0'; + else if(isalpha(c)) c-=isupper(c)?'A'-10:'a'-10; + else break; + if (c>=(unsigned short)base) break; + if (any<0||acc>cutoff||(acc==cutoff&&c>cutlim)) any=-1; + else + { + any=1; + asm volatile("\n" + " move.l %1,%%d0\n" + " mulu %2,%%d0\n" + " move.l %1,%%d1\n" + " swap %%d1\n" + " mulu %2,%%d1\n" + " swap %%d1\n" + " clr.w %%d1\n" + " add.l %%d1,%%d0\n" + " move.l %%d0,%0":"=g"(acc):"g"(acc),"g"(base):"d0","d1","d2"); + acc+=c; + } + } + if (any<0) acc=neg?0x80000000:0x7FFFFFFF; + else if(neg) acc=-acc; + if(endptr!=0) *endptr=(char*)(any?(char*)s-1:nptr); + return (acc); +} diff --git a/pch/src/tigcc-archive/strtoul.c b/pch/src/tigcc-archive/strtoul.c new file mode 100644 index 0000000..dd32f67 --- /dev/null +++ b/pch/src/tigcc-archive/strtoul.c @@ -0,0 +1,57 @@ +#include +#include + +__ATTR_LIB_C__ unsigned long strtoul(const char *nptr, char **endptr, short base) +{ + const unsigned char *s=nptr; + unsigned long acc,cutoff; + unsigned short c,cutlim; + short any; + do {c=*s++;} while (c==' '); + if (c=='+') c=*s++; + if((base==0||base==16)&&c=='0'&&(*s=='x'||*s=='X')) + { + c=s[1]; s+=2; base=16; + } + if(base==0) base=c=='0'?8:10; + asm volatile("\n" + " move.l #-1,%%d1\n" + " move.l %2,%%d0\n" + " move.l 0xC8,%%a0\n" + " move.l (%%a0,2728),%%a0\n" + " jsr (%%a0)\n" + " move.l %%d1,%0\n" + " move.l #-1,%%d1\n" + " move.l %2,%%d0\n" + " move.l 0xC8,%%a0\n" + " move.l (%%a0,2732),%%a0\n" + " jsr (%%a0)\n" + " move.w %%d1,%1":"=g"(cutoff),"=g"(cutlim):"g"((unsigned long)base): + "a0","a1","d0","d1","d2"); + for(acc=0,any=0;;c=*s++) + { + if(isdigit(c)) c-='0'; + else if(isalpha(c)) c-=isupper(c)?'A'-10:'a'-10; + else break; + if(c>=(unsigned short)base) break; + if(any<0||acc>cutoff||(acc==cutoff&&c>cutlim)) any=-1; + else + { + any=1; + asm volatile("\n" + " move.l %1,%%d0\n" + " mulu %2,%%d0\n" + " move.l %1,%%d1\n" + " swap %%d1\n" + " mulu %2,%%d1\n" + " swap %%d1\n" + " clr.w %%d1\n" + " add.l %%d1,%%d0\n" + " move.l %%d0,%0":"=g"(acc):"g"(acc),"g"(base):"d0","d1","d2"); + acc+=c; + } + } + if(any<0) acc=0xFFFFFFFF; + if(endptr!=0) *endptr=(char*)(any?(char*)s-1:nptr); + return(acc); +} diff --git a/pch/src/tigcc-archive/subbf.s b/pch/src/tigcc-archive/subbf.s new file mode 100644 index 0000000..304a197 --- /dev/null +++ b/pch/src/tigcc-archive/subbf.s @@ -0,0 +1,6 @@ +.data + .xdef __subbf3 + .even +__subbf3: + moveq.l #4,%d0 + bra __fp_entry diff --git a/pch/src/tigcc-archive/tigcc.tpr b/pch/src/tigcc-archive/tigcc.tpr new file mode 100644 index 0000000..73e6b50 --- /dev/null +++ b/pch/src/tigcc-archive/tigcc.tpr @@ -0,0 +1,147 @@ +[Settings] +Archive=1 +Pack=0 +Packed Variable= +Project Name=TIGCCLib +GCC Switches=-Os -Wall -W -Wwrite-strings -fomit-frame-pointer -D_GENERIC_ARCHIVE -DREGPARM1_STDLIB +Assembler Switches=-g -t +Linker Switches= +GNU Linker Switches= +BSR Patch=1 +Debug Info=0 +Standard Library=0 +Command Line= +Post-Build Process= +GNU Assembler Switches= +Flash OS=0 +Fargo=0 +Use Data Variable=0 +Data Variable= +Copy Data Variable=1 +Copy Data Variable if Archived=1 +Initialize BSS=1 +Optimize NOPs=1 +Optimize Returns=1 +Optimize Branches=1 +Optimize Moves=1 +Optimize Tests=1 +Optimize Calculations=1 +Remove Unused Sections=1 +Cut Unused Ranges=1 +Reorder Sections=1 +Merge Constants=1 +Binary Output=0 + + +[Library Options] +Use TI-89=0 +Use TI-92 Plus=0 +Use V200=0 +Optimize Calc Consts=0 +Use Kernel=0 +Use PreOS=0 +Minimum AMS Version Defined=0 +Minimum AMS Version=1.00 +Unofficial OS Support=0 +Reloc Format=Unknown +ROM Call Format=Unknown +BSS Ref Format=Unknown +Data Ref Format=Unknown +Use F-Line Jumps=0 +Use 4-Byte F-Line Jumps=0 +Optimize ROM Calls=0 +Use Internal F-Line Emulator=0 +Use Return Value=0 +Enable Error Return=0 +Save Screen=0 +[File Editing] +Open File=C:\Cygwin\home\Paul\gtc-clean\gtc\pch\src\tigcc-archive\sprite16.c +[Included Files] +C File 1=qsort.c +C File 2=bsearch.c +C File 3=atoi.c +C File 4=atol.c +C File 5=strtol.c +C File 6=strtoul.c +C File 7=fopen.c +C File 8=fclose.c +C File 9=ftell.c +C File 10=fseek.c +C File 11=fputc.c +C File 12=fgetc.c +C File 13=fwrite.c +C File 14=fread.c +C File 15=fgets.c +C File 16=rename.c +C File 17=unlink.c +C File 18=tmpnam.c +C File 19=fsetbufsize.c +C File 20=sprite8.c +C File 21=sprite16.c +C File 22=sprite32.c +C File 23=pushfifonode.c +C File 24=homestorepair.c +C File 25=dll.c +C File 26=grayversion.c +GNU Assembler File 1=bzero.s +GNU Assembler File 2=bcopy.s +GNU Assembler File 3=mulsi.s +GNU Assembler File 4=divsi.s +GNU Assembler File 5=udivsi.s +GNU Assembler File 6=modsi.s +GNU Assembler File 7=umodsi.s +GNU Assembler File 8=diventry.s +GNU Assembler File 9=muldi.s +GNU Assembler File 10=ashldi.s +GNU Assembler File 11=ashrdi.s +GNU Assembler File 12=lshrdi.s +GNU Assembler File 13=divdi.s +GNU Assembler File 14=udivdi.s +GNU Assembler File 15=moddi.s +GNU Assembler File 16=umoddi.s +GNU Assembler File 17=addbf.s +GNU Assembler File 18=subbf.s +GNU Assembler File 19=mulbf.s +GNU Assembler File 20=divbf.s +GNU Assembler File 21=negbf.s +GNU Assembler File 22=floatbf.s +GNU Assembler File 23=fixbf.s +GNU Assembler File 24=cmpbf.s +GNU Assembler File 25=fpentry.s +GNU Assembler File 26=fpcall.s +GNU Assembler File 27=bc.s +GNU Assembler File 28=gray.s +GNU Assembler File 29=rand.s +GNU Assembler File 30=realloc.s +GNU Assembler File 31=calloc.s +GNU Assembler File 32=clrscr.s +GNU Assembler File 33=printf.s +GNU Assembler File 34=fprintf.s +GNU Assembler File 35=fputchar.s +GNU Assembler File 36=puts.s +GNU Assembler File 37=strputchar.s +GNU Assembler File 38=fputs.s +GNU Assembler File 39=atof.s +GNU Assembler File 40=push_shortint.s +GNU Assembler File 41=push_longint.s +GNU Assembler File 42=push_longlongint.s +GNU Assembler File 43=nocallback.s +GNU Assembler File 44=kbd_queue.s +GNU Assembler File 45=registertimer.s +GNU Assembler File 46=freetimer.s +GNU Assembler File 47=getappid.s +GNU Assembler File 48=enter_ghost_space.s +GNU Assembler File 49=exit.s +GNU Assembler File 50=atexit.s +GNU Assembler File 51=assert.s +GNU Assembler File 52=rowread.s +GNU Assembler File 53=isextalnum.s +GNU Assembler File 54=isextpunct.s +GNU Assembler File 55=homestore.s +GNU Assembler File 56=dummyhandler.s +GNU Assembler File 57=malloc_throw.s +GNU Assembler File 58=calloc_throw.s +GNU Assembler File 59=realloc_throw.s +GNU Assembler File 60=hrealloc_throw.s +GNU Assembler File 61=loaddll_throw.s +Text File 1=License.txt diff --git a/pch/src/tigcc-archive/tmpnam.c b/pch/src/tigcc-archive/tmpnam.c new file mode 100644 index 0000000..14ea380 --- /dev/null +++ b/pch/src/tigcc-archive/tmpnam.c @@ -0,0 +1,23 @@ +#include +#include +#include +#include + +//tmpnam implementation by Greg Dietsche +//email: gforce@calc.org +//webpage: http://gforce.calc.org/ + +__ATTR_LIB_C__ char *tmpnam(char *s) +{ + static char buff[10]={0}; //"\0 "; + register char *bptr=buff; + register short i; + + do { + for(i=1;i<9;i++) + bptr[i]=((rand()%25)+97); + } while(SymFind(bptr+9).offset); + + if(s) return strcpy(s,bptr+1); + else return bptr+1; +} diff --git a/pch/src/tigcc-archive/udivdi.s b/pch/src/tigcc-archive/udivdi.s new file mode 100644 index 0000000..f5c1588 --- /dev/null +++ b/pch/src/tigcc-archive/udivdi.s @@ -0,0 +1,43 @@ +|udivdi3 routine copyright (C) 2002, Kevin Kofler +|WARNING: A division by 0 will not cause an exception, but just crash in an +| infinite loop! + +.data + xdef __udivdi3 + .even +__udivdi3: + movem.l %d3-%d6,-(%a7) + move.l 20(%a7),%d4 + move.l 24(%a7),%d5 + move.l 28(%a7),%d2 + move.l 32(%a7),%d3 + moveq.l #0,%d0 + moveq.l #0,%d1 + + moveq.l #-1,%d6 +.L__udivdi3_shl: + addq.w #1,%d6 + add.l %d3,%d3 + addx.l %d2,%d2 + bcc.s .L__udivdi3_shl + roxr.l #1,%d2 + roxr.l #1,%d3 + +.L__udivdi3_shr: + add.l %d1,%d1 + addx.l %d0,%d0 + cmp.l %d2,%d4 + bne.s .L__udivdi3_cmp + cmp.l %d3,%d5 +.L__udivdi3_cmp: + bcs.s .L__udivdi3_skip + sub.l %d3,%d5 + subx.l %d2,%d4 + addq.l #1,%d1 +.L__udivdi3_skip: + lsr.l #1,%d2 + roxr.l #1,%d3 + dbra.w %d6,.L__udivdi3_shr + + movem.l (%a7)+,%d3-%d6 + rts diff --git a/pch/src/tigcc-archive/udivsi.s b/pch/src/tigcc-archive/udivsi.s new file mode 100644 index 0000000..260c27d --- /dev/null +++ b/pch/src/tigcc-archive/udivsi.s @@ -0,0 +1,6 @@ +.data + .xdef __udivsi3 + .even +__udivsi3: + move.w #0x2AA*4,%d2 /* _du32u32 */ + jra __div_entry diff --git a/pch/src/tigcc-archive/umoddi.s b/pch/src/tigcc-archive/umoddi.s new file mode 100644 index 0000000..57e71ed --- /dev/null +++ b/pch/src/tigcc-archive/umoddi.s @@ -0,0 +1,40 @@ +|umoddi3 routine copyright (C) 2002, Kevin Kofler +|WARNING: A division by 0 will not cause an exception, but just crash in an +| infinite loop! + +.data + xdef __umoddi3 + .even +__umoddi3: + movea.l %d3,%a0 + move.l 4(%a7),%d0 + move.l 8(%a7),%d1 + move.l 12(%a7),%d2 + move.l 16(%a7),%d3 + + movea.l %d4,%a1 + moveq.l #-1,%d4 +.L__umoddi3_shl: + addq.w #1,%d4 + add.l %d3,%d3 + addx.l %d2,%d2 + bcc.s .L__umoddi3_shl + roxr.l #1,%d2 + roxr.l #1,%d3 + +.L__umoddi3_shr: + cmp.l %d2,%d0 + bne.s .L__umoddi3_cmp + cmp.l %d3,%d1 +.L__umoddi3_cmp: + bcs.s .L__umoddi3_skip + sub.l %d3,%d1 + subx.l %d2,%d0 +.L__umoddi3_skip: + lsr.l #1,%d2 + roxr.l #1,%d3 + dbra.w %d4,.L__umoddi3_shr + + move.l %a1,%d4 + move.l %a0,%d3 + rts diff --git a/pch/src/tigcc-archive/umodsi.s b/pch/src/tigcc-archive/umodsi.s new file mode 100644 index 0000000..0a29b11 --- /dev/null +++ b/pch/src/tigcc-archive/umodsi.s @@ -0,0 +1,6 @@ +.data + .xdef __umodsi3 + .even +__umodsi3: + move.w #0x2AB*4,%d2 /* _mu32u32 */ + jra __div_entry diff --git a/pch/src/tigcc-archive/unlink.c b/pch/src/tigcc-archive/unlink.c new file mode 100644 index 0000000..9893009 --- /dev/null +++ b/pch/src/tigcc-archive/unlink.c @@ -0,0 +1,9 @@ +#include +#include + +__ATTR_LIB_C__ short unlink(const char *fname) +{ + char sym[50],*sptr=sym; + *sptr=0; while((*++sptr=*fname++)); + return SymDel(sptr)-1; +} diff --git a/pch/src/timath.pchsource b/pch/src/timath.pchsource new file mode 100644 index 0000000..e4a65d9 --- /dev/null +++ b/pch/src/timath.pchsource @@ -0,0 +1,116 @@ + +#var FIVE D((5.0)) +#var FOUR D((4.0)) +#var HALF D((0.5)) +#var HALF_PI D((1.570796326794897)) +#var MINUS_ONE D((-1.0)) +#var NAN D((*(float*)&(bcd){0x7FFF,0xAA00000000000000})) +#var NEGATIVE_INF D((*(float*)&(bcd){0xFFFF,0xAA00BB0000000000})) +#var NEGATIVE_ZERO D((*(float*)&(bcd){0x8000,0})) +#var ONE D((1.0)) +#var PI D((3.141592653589793)) +#var POSITIVE_INF D((*(float*)&(bcd){0x7FFF,0xAA00BB0000000000})) +#var POSITIVE_ZERO D((*(float*)&(bcd){0,0})) +#var TEN D((10.0)) +#var THREE D((3.0)) +#var TWO D((2.0)) +#var UNSIGNED_INF D((*(float*)&(bcd){0x7FFF,0xAA00CC0000000000})) +#var UNSIGNED_ZERO D((0.0)) +#var ZERO D((0.0)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var FALSE D(0) +#var TRUE D(1) + +#var ti_float typedef float ti_float; +#var abs(x) D(({typeof(x) __x = (x); __x >= 0 ? __x : -__x;})) +#var acos(x) D(_tios_float_1(F5,x,float)) +#var acosh(x) D(_tios_float_1(288,x,float)) +#var asin(x) D(_tios_float_1(F6,x,float)) +#var asinh(x) D(_tios_float_1(287,x,float)) +#var atan2(x,y) D(_tios_float_2(F8,x,y,float,float)) +#var atan(x) D(_tios_float_1(F7,x,float)) +#var atanh(x) D(_tios_float_1(289,x,float)) +#var bcd_to_float(a) D(({bcd __a=(a);*(float*)&__a;})) +#var bcd_var(a) D((*(bcd*)&(a))) +#var bcdadd(x,y) D(({bcd __x=(x),__y=(y);float __z=fadd(*(float*)&__x,*(float*)&__y);*(bcd*)&__z;})) +#var bcdbcd(x) D(({float __x=flt(x);*(bcd*)&__x;})) +#var bcdcmp(x,y) D(({bcd __x=(x),__y=(y);fcmp(*(float*)&__x,*(float*)&__y);})) +#var bcddiv(x,y) D(({bcd __x=(x),__y=(y);float __z=fdiv(*(float*)&__x,*(float*)&__y);*(bcd*)&__z;})) +#var bcdlong(x) D(({bcd __x=(x);trunc(*(float*)&__x);})) +#var bcdmul(x,y) D(({bcd __x=(x),__y=(y);float __z=fmul(*(float*)&__x,*(float*)&__y);*(bcd*)&__z;})) +#var bcdneg(x) D(({bcd __x=(x);float __y=fneg(*(float*)&__x);*(bcd*)&__y;})) +#var bcdsub(x,y) D(({bcd __x=(x),__y=(y);float __z=fsub(*(float*)&__x,*(float*)&__y);*(bcd*)&__z;})) +#var cacos D(_rom_call(void,(float,float,float*,float*),13A)) +#var cacosh D(_rom_call(void,(float,float,float*,float*),13D)) +#var casin D(_rom_call(void,(float,float,float*,float*),13B)) +#var casinh D(_rom_call(void,(float,float,float*,float*),13E)) +#var catan D(_rom_call(void,(float,float,float*,float*),13C)) +#var catanh D(_rom_call(void,(float,float,float*,float*),13F)) +#var ccos D(_rom_call(void,(float,float,float*,float*),140)) +#var ccosh D(_rom_call(void,(float,float,float*,float*),143)) +#var ceil(x) D(_tios_float_1(105,x,float)) +#var cexp D(_rom_call(void,(float,float,float*,float*),149)) +#var cln D(_rom_call(void,(float,float,float*,float*),147)) +#var clog10 D(_rom_call(void,(float,float,float*,float*),148)) +#var cos(x) D(_tios_float_1(F9,x,float)) +#var cosh(x) D(_tios_float_1(FC,x,float)) +#var csin D(_rom_call(void,(float,float,float*,float*),141)) +#var csinh D(_rom_call(void,(float,float,float*,float*),144)) +#var csqrt D(_rom_call(void,(float,float,float*,float*),146)) +#var ctan D(_rom_call(void,(float,float,float*,float*),142)) +#var ctanh D(_rom_call(void,(float,float,float*,float*),145)) +#var exp(x) D(_tios_float_1(FF,x,float)) +#var fabs(x) D(_tios_float_1(106,x,float)) +#var fadd(x,y) D(_tios_float_2(B6,x,y,float,float)) +#var fcmp D(_rom_call(long,(float,float),BB)) +#var fdiv(x,y) D(_tios_float_2(B9,x,y,float,float)) +#var FEXP(x,y) D((*(float*)&(bcd){0x4000+y,0x##x##LL<<4*(17-sizeof(#x))})) +#var FEXP_NEG(x,y) D((*(float*)&(bcd){0xC000+y,0x##x##LL<<4*(17-sizeof(#x))})) +#var float_to_bcd(a) D(({float __a=(a);*(bcd*)&__a;})) +#var floor(x) D(_tios_float_1(107,x,float)) +#var flt(x) D(_tios_float_1(BD,x,long)) +#var FLT(x,y...) D(((sizeof(#y)==1)?x##.0:x##.##y)) +#var FLT_NEG(x,y...) D(((sizeof(#y)==1)?-x##.0:-x##.##y)) +#var fmod(x,y) D(_tios_float_2(108,x,y,float,float)) +#var fmul(x,y) D(_tios_float_2(B8,x,y,float,float)) +#var fneg(x) D(_tios_float_1(BA,x,float)) +#var fpisanint D(_rom_call(short,(unsigned long long*,short),172)) +#var fpisodd D(_rom_call(short,(unsigned long long*,short),173)) +#var fsub(x,y) D(_tios_float_2(B7,x,y,float,float)) +#var hypot(x,y) D(({float __x=(x),__y=(y);sqrt(fadd(fmul((__x),(__x)),fmul((__y),(__y))));})) +#var init_float() D(((void)0)) +#var itrig D(_rom_call(void,(short,short,float*,float*),28A)) +#var ldexp10(x,e) D(({float __f=x;((bcd*)&__f)->exponent+=e;__f;})) +#var log(x) D(_tios_float_1(100,x,float)) +#var log10(x) D(_tios_float_1(101,x,float)) +#var modf(x,y) D(_tios_float_2(102,x,y,float,float*)) +#var pow(x,y) D(_tios_float_2(103,x,y,float,float)) +#var round12(x) D(_tios_float_1(174,x,float)) +#var round12_err(x,y) D(_tios_float_2(227,x,y,float,short)) +#var round14(x) D(_tios_float_1(175,x,float)) +#var sin(x) D(_tios_float_1(FA,x,float)) +#var sincos D(_rom_call(void,(float,short,float*,float*),286)) +#var sinh(x) D(_tios_float_1(FD,x,float)) +#var sqrt(x) D(_tios_float_1(104,x,float)) +#var tan(x) D(_tios_float_1(FB,x,float)) +#var tanh(x) D(_tios_float_1(FE,x,float)) +#var trig D(_rom_call(void,(short,short,const float*,float*,float*,float*),28B)) +#var trunc D(_rom_call(long,(float),BC)) +#var atof float atof(const char*)__ATTR_LIB_ASM__; +#var float_class D(_rom_call(short,(float),2FA)) +#var frexp10(x,y) D(_tios_float_2(2FB,x,y,float,__pshort)) +#var is_float_infinity D(_rom_call(short,(float),2FF)) +#var is_float_negative_zero D(_rom_call(short,(float),300)) +#var is_float_positive_zero D(_rom_call(short,(float),301)) +#var is_float_signed_infinity D(_rom_call(short,(float),302)) +#var is_float_transfinite D(_rom_call(short,(float),303)) +#var is_float_unsigned_inf_or_nan D(_rom_call(short,(float),304)) +#var is_float_unsigned_zero D(_rom_call(short,(float),305)) +#var is_inf D(_rom_call(short,(float),2FF)) +#var is_nan D(_rom_call(short,(float),306)) +#var is_nzero D(_rom_call(short,(float),300)) +#var is_pzero D(_rom_call(short,(float),301)) +#var is_sinf D(_rom_call(short,(float),302)) +#var is_transfinite D(_rom_call(short,(float),303)) +#var is_uinf_or_nan D(_rom_call(short,(float),304)) +#var is_uzero D(_rom_call(short,(float),305)) diff --git a/pch/src/tiosdlg-merge.pchmerge b/pch/src/tiosdlg-merge.pchmerge new file mode 100644 index 0000000..268f44d --- /dev/null +++ b/pch/src/tiosdlg-merge.pchmerge @@ -0,0 +1,6 @@ +tiosdlg.pchsource + +dialogs.pchsource +menus.pchsource +wingraph.pchsource +textedit.pchsource diff --git a/pch/src/values.pchsource b/pch/src/values.pchsource new file mode 100644 index 0000000..be1bdd7 --- /dev/null +++ b/pch/src/values.pchsource @@ -0,0 +1,30 @@ +#var MAXINT D(0x7FFF) +#var HIBITI D(0x8000) + + +#var _DEXPLEN D(15) +#var _EXPBASE D(10) +#var _FEXPLEN D(15) +#var _IEEE D(0) +#var BITSPERBYTE D(8) +#var DMAXEXP D(999) +#var DMAXPOWTWO D(3321) +#var DMINEXP D((-999)) +#var DSIGNIF D(64) +#var FMAXEXP D(999) +#var FMAXPOWTWO D(3321) +#var FMINEXP D((-999)) +#var FSIGNIF D(56) +#var HIBITL D(0x80000000L) +#var HIBITS D(0x8000) +#var LN_MAXDOUBLE D((2303.58509299)) +#var LN_MINDOUBLE D((-2300.2825079)) +#var MAXDOUBLE D((9.999999999999999e999)) +#var MAXFLOAT D((9.999999999999999e999)) +#var MAXLONG D(0x7FFFFFFFL) +#var MAXSHORT D(0x7FFF) +#var MINDOUBLE D((1e-999)) +#var MINFLOAT D((1e-999)) +#var bcd typedef struct{unsigned short exponent;unsigned long long mantissa;}bcd; +#var ti_float typedef float ti_float; + diff --git a/pch/src/vat-le.pchsource b/pch/src/vat-le.pchsource new file mode 100644 index 0000000..e7c6c9a --- /dev/null +++ b/pch/src/vat-le.pchsource @@ -0,0 +1,124 @@ +#var SYMSTR_CONST(s) D(((SYM_STR)(("\0"s)+sizeof(s)))) +#var VATSTR D(SYMSTR) + +#var __Folder_Del D(_rom_call(short,(const char*,short),66)) + + +#var H_NULL D(0) +#var HS_NULL D(((HSym){0,0})) +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var CF_NONE D(0) +#var CF_CONVERT D(1) +#var CF_ENHANCED D(2) +#var CF_NEW D(3) + +#var ESI typedef ESQ*ESI; + +#var FO_SINGLE_FOLDER D(1) +#var FO_RECURSE D(2) +#var FO_SKIP_TEMPS D(4) +#var FO_NOTEMPS D(4) +#var FO_RETURN_TWINS D(8) +#var FO_CKTWINS D(8) +#var FO_RETURN_FOLDER D(16) +#var FO_SKIP_COLLAPSE D(32) + +#var FOP_UNLOCK D(0) +#var FOP_LOCK D(1) +#var FOP_ALL_FOLDERS D(128) + +#var MAIN_FOLDER D(2) +#var FOLDER_TABLE D(3) +#var NOT_FOUND D(4) +#var BAD_FOLDER D(5) + +#var HANDLE typedef unsigned short HANDLE; +#var HSym typedef struct{HANDLE folder;unsigned short offset;}HSym; +#var HSYM D(HSym) +#var MULTI_EXPR typedef struct{unsigned short Size;ESQ Expr[];}MULTI_EXPR; +#var SYM_ENTRY typedef struct{char name[8];unsigned short compat;union{unsigned short flags_n;struct{unsigned short busy:1,local:1,flag1_5:1,flag1_4:1,collapsed:1,twin:1,archived:1,in_view:1;unsigned short folder:1,overwritten:1,checked:1,hidden:1,locked:1,statvar:1,graph_ref_1:1,graph_ref_0:1;}bits;}flags;HANDLE handle;}SYM_ENTRY; +#var SYM_STR typedef CESI SYM_STR; +#var SF_GREF1 D(1) +#var SF_GREF2 D(2) +#var SF_STATVAR D(4) +#var SF_LOCKED D(8) +#var SF_HIDDEN D(16) +#var SF_OPEN D(16) +#var SF_CHECKED D(32) +#var SF_OVERWRITTEN D(64) +#var SF_FOLDER D(128) +#var SF_INVIEW D(256) +#var SF_ARCHIVED D(512) +#var SF_TWIN D(1024) +#var SF_COLLAPSED D(2048) +#var SF_LOCAL D(16384) +#var SF_BUSY D(-32768) + +#var $(s) D(SYMSTR_CONST(#s)) +#var AddSymToFolder D(_rom_call(HSym,(SYM_STR,SYM_STR),70)) +#var checkCurrent D(_rom_call(HSym,(SYM_STR,ESQ),121)) +#var CheckLinkLockFlag D(_rom_call(void,(const SYM_ENTRY*),7F)) +#var CheckReservedName D(_rom_call(short,(SYM_STR),8B)) +#var CheckSysFunc D(_rom_call(short,(const char*,__pushort),89)) +#var ClearUserDef D(_rom_call(void,(HANDLE),7E)) +#var DerefSym D(_rom_call(SYM_ENTRY*,(HSym),79)) +#var EM_moveSymFromExtMem D(_rom_call(short,(SYM_STR,HSym),161)) +#var EM_moveSymToExtMem D(_rom_call(short,(SYM_STR,HSym),162)) +#var EM_twinSymFromExtMem D(_rom_call(HSym,(SYM_STR,HSym),166)) +#var EX_stoBCD D(_rom_call(void,(unsigned char*,float*),C0)) +#var FindSymInFolder D(_rom_call(HSym,(SYM_STR,const char*),71)) +#var FolderAdd D(_rom_call(HANDLE,(SYM_STR),64)) +#var FolderAddTemp D(_rom_call(const char*,(void),73)) +#var FolderClear(c) D(__Folder_Del((c),1)) +#var FolderCount D(_rom_call(unsigned short,(const SYM_ENTRY*),6B)) +#var FolderCur D(_rom_call(short,(SYM_STR,short),65)) +#var FolderCurTemp D(_rom_call(short,(SYM_STR),72)) +#var FolderDel(c) D(__Folder_Del((c),0)) +#var FolderDelAllTemp D(_rom_call(void,(short),75)) +#var FolderDelTemp D(_rom_call(void,(void),74)) +#var FolderFind D(_rom_call(short,(SYM_STR),67)) +#var FolderGetCur D(_rom_call(void,(char*),68)) +#var FolderOp D(_rom_call(short,(SYM_STR,short),69)) +#var FolderRename D(_rom_call(short,(const char*,const char*),6A)) +#var HSymDel D(_rom_call(short,(HSym),5F)) +#var HSYMtoName D(_rom_call(short,(HSym,char*),7A)) +#var IsMainFolderStr D(_rom_call(short,(const char*),77)) +#var MakeHSym D(_rom_call(HSym,(HANDLE,const SYM_ENTRY*),282)) +#var partial_len D(_rom_call(unsigned long,(const char*,unsigned char*),11C)) +#var QSysProtected D(_rom_call(short,(ESQ),88)) +#var ResetSymFlags D(_rom_call(void,(short),8E)) +#var StrToTokN D(_rom_call(ESI,(const char*,unsigned char*),7B)) +#var SymAdd D(_rom_call(HSym,(SYM_STR),5C)) +#var SymAddMain D(_rom_call(HSym,(SYM_STR),5D)) +#var SymAddTwin D(_rom_call(HSym,(SYM_STR),27F)) +#var SymCmp D(_rom_call(short,(const char*,const char*),81)) +#var SymCpy0 D(_rom_call(void,(char*,const char*),83)) +#var SymCpy D(_rom_call(void,(char*,const char*),82)) +#var SymDel D(_rom_call(short,(SYM_STR),5E)) +#var SymDelTwin D(_rom_call(short,(SYM_ENTRY*),280)) +#var SymFind D(_rom_call(HSym,(SYM_STR),60)) +#var SymFindFirst D(_rom_call(SYM_ENTRY*,(SYM_STR,short),6C)) +#var SymFindFolderName D(_rom_call(char*,(void),6F)) +#var SymFindHome D(_rom_call(HSym,(SYM_STR),62)) +#var SymFindMain D(_rom_call(HSym,(SYM_STR),61)) +#var SymFindNext D(_rom_call(SYM_ENTRY*,(void),6D)) +#var SymFindPrev D(_rom_call(SYM_ENTRY*,(void),6E)) +#var SymFindPtr D(_rom_call(SYM_ENTRY*,(SYM_STR,short),283)) +#var SymMove D(_rom_call(short,(const char*,const char*),63)) +#var SYMSTR(s) D(({register unsigned short __slen=_rom_call(unsigned long,(const char*),27E)(s);ESI __tempstr=alloca(__slen+2);__tempstr[0]=0;_rom_call(void*,(void*,const void*,long),26A)(__tempstr+1,(s),__slen+1);__tempstr+__slen+1;})) +#var SymSysVar D(_rom_call(short,(const char*),8C)) +#var TempFolderName D(_rom_call(SYM_STR,(short),76)) +#var TokToStrN D(_rom_call(short,(unsigned char*,SYM_STR),7C)) +#var ValidateSymName D(_rom_call(short,(const char*),84)) +#var VarRecall D(_rom_call(HSym,(SYM_STR,short),85)) +#var VarStore D(_rom_call(HSym,(SYM_STR,short,short,...),86)) + +#var SymFindFoldername D(SymFindFolderName) + +#var OpenFile void *OpenFile(const char *)__ATTR_LIB_C__; +#var CloseFile void CloseFile(const char *)__ATTR_LIB_C__; diff --git a/pch/src/vat.pchsource b/pch/src/vat.pchsource new file mode 100644 index 0000000..0aa644a --- /dev/null +++ b/pch/src/vat.pchsource @@ -0,0 +1,141 @@ +#var SYMSTR_CONST(s) D(((SYM_STR)(("\0"s)+sizeof(s)))) +#var VATSTR D(SYMSTR) + +#var __Folder_Del D(_rom_call(short,(const char*,short),66)) + + +#var H_NULL D(0) +#var HS_NULL D(((HSym){0,0})) +#var NULL D(((void*)0)) +#var FALSE D(0) +#var TRUE D(1) + +#var ESQ typedef unsigned char ESQ; +#var CESI typedef const ESQ*CESI; +#var CF_NONE D(0) +#var CF_CONVERT D(1) +#var CF_ENHANCED D(2) +#var CF_NEW D(3) + +#var ESI typedef ESQ*ESI; +#var SEQ_INITC D(7) +#var DE_INITC D(8) +#var DE_FLDPIC D(9) +#var SOLVER_SYS_VARS D(10) +#var UNIT_VAR D(11) +#var C_COL D(12) +#var R_REGEQ D(13) +#var R_SYSVAR D(14) + +#var FO_SINGLE_FOLDER D(1) +#var FO_RECURSE D(2) +#var FO_SKIP_TEMPS D(4) +#var FO_NOTEMPS D(4) +#var FO_RETURN_TWINS D(8) +#var FO_CKTWINS D(8) +#var FO_RETURN_FOLDER D(16) +#var FO_SKIP_COLLAPSE D(32) + +#var FOP_UNLOCK D(0) +#var FOP_LOCK D(1) +#var FOP_ALL_FOLDERS D(128) + +#var MAIN_FOLDER D(2) +#var FOLDER_TABLE D(3) +#var NOT_FOUND D(4) +#var BAD_FOLDER D(5) + +#var HANDLE typedef unsigned short HANDLE; +#var HSym typedef struct{HANDLE folder;unsigned short offset;}HSym; +#var HSYM D(HSym) +#var MULTI_EXPR typedef struct{unsigned short Size;ESQ Expr[];}MULTI_EXPR; +#var SYM_ENTRY typedef struct{char name[8];unsigned short compat;union{unsigned short flags_n;struct{unsigned short busy:1,local:1,flag1_5:1,flag1_4:1,collapsed:1,twin:1,archived:1,in_view:1;unsigned short folder:1,overwritten:1,checked:1,hidden:1,locked:1,statvar:1,graph_ref_1:1,graph_ref_0:1;}bits;}flags;HANDLE handle;}SYM_ENTRY; +#var SYM_STR typedef CESI SYM_STR; +#var SF_GREF1 D(1) +#var SF_GREF2 D(2) +#var SF_STATVAR D(4) +#var SF_LOCKED D(8) +#var SF_HIDDEN D(16) +#var SF_OPEN D(16) +#var SF_CHECKED D(32) +#var SF_OVERWRITTEN D(64) +#var SF_FOLDER D(128) +#var SF_INVIEW D(256) +#var SF_ARCHIVED D(512) +#var SF_TWIN D(1024) +#var SF_COLLAPSED D(2048) +#var SF_LOCAL D(16384) +#var SF_BUSY D(-32768) + +#var VR_NO_SYS_VARS D(1) +#var VR_FUNC_NAME D(2) +#var VR_LINK D(4) + +#var STOF_ESI D(16384) +#var STOF_ELEMENT D(16385) +#var STOF_NONE D(16386) +#var STOF_HESI D(16387) + +#var $(s) D(SYMSTR_CONST(#s)) +#var AddSymToFolder D(_rom_call(HSym,(SYM_STR,SYM_STR),70)) +#var checkCurrent D(_rom_call(HSym,(SYM_STR,ESQ),121)) +#var CheckLinkLockFlag D(_rom_call(void,(const SYM_ENTRY*),7F)) +#var CheckReservedName D(_rom_call(short,(SYM_STR),8B)) +#var CheckSysFunc D(_rom_call(short,(const char*,__pushort),89)) +#var ClearUserDef D(_rom_call(void,(HANDLE),7E)) +#var DerefSym D(_rom_call(SYM_ENTRY*,(HSym),79)) +#var EM_moveSymFromExtMem D(_rom_call(short,(SYM_STR,HSym),161)) +#var EM_moveSymToExtMem D(_rom_call(short,(SYM_STR,HSym),162)) +#var EM_twinSymFromExtMem D(_rom_call(HSym,(SYM_STR,HSym),166)) +#var EX_stoBCD D(_rom_call(void,(unsigned char*,float*),C0)) +#var FindSymInFolder D(_rom_call(HSym,(SYM_STR,const char*),71)) +#var FolderAdd D(_rom_call(HANDLE,(SYM_STR),64)) +#var FolderAddTemp D(_rom_call(const char*,(void),73)) +#var FolderClear(c) D(__Folder_Del((c),1)) +#var FolderCount D(_rom_call(unsigned short,(const SYM_ENTRY*),6B)) +#var FolderCur D(_rom_call(short,(SYM_STR,short),65)) +#var FolderCurTemp D(_rom_call(short,(SYM_STR),72)) +#var FolderDel(c) D(__Folder_Del((c),0)) +#var FolderDelAllTemp D(_rom_call(void,(short),75)) +#var FolderDelTemp D(_rom_call(void,(void),74)) +#var FolderFind D(_rom_call(short,(SYM_STR),67)) +#var FolderGetCur D(_rom_call(void,(char*),68)) +#var FolderOp D(_rom_call(short,(SYM_STR,short),69)) +#var FolderRename D(_rom_call(short,(const char*,const char*),6A)) +#var HSymDel D(_rom_call(short,(HSym),5F)) +#var HSYMtoName D(_rom_call(short,(HSym,char*),7A)) +#var IsMainFolderStr D(_rom_call(short,(const char*),77)) +#var MakeHSym D(_rom_call(HSym,(HANDLE,const SYM_ENTRY*),282)) +#var partial_len D(_rom_call(unsigned long,(const char*,unsigned char*),11C)) +#var QSysProtected D(_rom_call(short,(ESQ),88)) +#var ResetSymFlags D(_rom_call(void,(short),8E)) +#var StrToTokN D(_rom_call(ESI,(const char*,unsigned char*),7B)) +#var SymAdd D(_rom_call(HSym,(SYM_STR),5C)) +#var SymAddMain D(_rom_call(HSym,(SYM_STR),5D)) +#var SymAddTwin D(_rom_call(HSym,(SYM_STR),27F)) +#var SymCmp D(_rom_call(short,(const char*,const char*),81)) +#var SymCpy0 D(_rom_call(void,(char*,const char*),83)) +#var SymCpy D(_rom_call(void,(char*,const char*),82)) +#var SymDel D(_rom_call(short,(SYM_STR),5E)) +#var SymDelTwin D(_rom_call(short,(SYM_ENTRY*),280)) +#var SymFind D(_rom_call(HSym,(SYM_STR),60)) +#var SymFindFirst D(_rom_call(SYM_ENTRY*,(SYM_STR,short),6C)) +#var SymFindFolderName D(_rom_call(char*,(void),6F)) +#var SymFindHome D(_rom_call(HSym,(SYM_STR),62)) +#var SymFindMain D(_rom_call(HSym,(SYM_STR),61)) +#var SymFindNext D(_rom_call(SYM_ENTRY*,(void),6D)) +#var SymFindPrev D(_rom_call(SYM_ENTRY*,(void),6E)) +#var SymFindPtr D(_rom_call(SYM_ENTRY*,(SYM_STR,short),283)) +#var SymMove D(_rom_call(short,(const char*,const char*),63)) +#var SYMSTR(s) D(({register unsigned short __slen=_rom_call(unsigned long,(const char*),27E)(s);ESI __tempstr=alloca(__slen+2);__tempstr[0]=0;_rom_call(void*,(void*,const void*,long),26A)(__tempstr+1,(s),__slen+1);__tempstr+__slen+1;})) +#var SymSysVar D(_rom_call(short,(const char*),8C)) +#var TempFolderName D(_rom_call(SYM_STR,(short),76)) +#var TokToStrN D(_rom_call(short,(unsigned char*,SYM_STR),7C)) +#var ValidateSymName D(_rom_call(short,(const char*),84)) +#var VarRecall D(_rom_call(HSym,(SYM_STR,short),85)) +#var VarStore D(_rom_call(HSym,(SYM_STR,short,short,...),86)) + +#var SymFindFoldername D(SymFindFolderName) + +#var OpenFile void *OpenFile(const char *)__ATTR_LIB_C__; +#var CloseFile void CloseFile(const char *)__ATTR_LIB_C__; diff --git a/pch/src/version.pchsource b/pch/src/version.pchsource new file mode 100644 index 0000000..eeda5be --- /dev/null +++ b/pch/src/version.pchsource @@ -0,0 +1,6 @@ + +#var __TIGCCLIB__ D(2) +#var __TIGCCLIB_MINOR__ D(50) +#var __TIGCCLIB_SP__ D(0) +#var __TIGCCLIB_VERSION__ D(250) +#var __TIGCCLIB_VERSION_STRING__ D("LIB2.5") diff --git a/pch/src/wingraph.pchsource b/pch/src/wingraph.pchsource new file mode 100644 index 0000000..99cab56 --- /dev/null +++ b/pch/src/wingraph.pchsource @@ -0,0 +1,113 @@ + +#var BITMAP_HDR_SIZE D(4) +#var NULL D(((void*)0)) +#var A_REVERSE D(0) +#var A_NORMAL D(1) +#var A_XOR D(2) +#var A_SHADED D(3) +#var A_REPLACE D(4) +#var A_OR D(5) +#var A_AND D(6) +#var A_THICK1 D(7) +#var A_SHADE_V D(8) +#var A_SHADE_H D(9) +#var A_SHADE_NS D(10) +#var A_SHADE_PS D(11) + +#var BITMAP typedef struct{unsigned short NumRows,NumCols;unsigned char Data[];}BITMAP; +#var FALSE D(0) +#var TRUE D(1) + +#var B_NORMAL D(16) +#var B_ROUNDED D(32) +#var B_DOUBLE D(64) +#var B_CUT D(128) + +#var BT_NONE D(0) +#var BT_OK D(1) +#var BT_SAVE D(2) +#var BT_YES D(3) +#var BT_CANCEL D(4) +#var BT_NO D(5) +#var BT_GOTO D(6) + +#var F_4x6 D(0) +#var F_6x8 D(1) +#var F_8x10 D(2) + +#var HANDLE typedef unsigned short HANDLE; +#var ICON typedef struct{unsigned short i[16];}ICON; +#var pICON typedef unsigned short*pICON; +#var SCR_COORDS typedef unsigned char SCR_COORDS; +#var SCR_RECT typedef union{struct{unsigned char x0,y0,x1,y1;}xy;unsigned long l;}SCR_RECT; +#var SCR_STATE typedef struct{void*ScrAddr;unsigned char XMax,YMax;short CurFont,CurAttr,CurX,CurY;SCR_RECT CurClip;}SCR_STATE; +#var WIN_COORDS typedef short WIN_COORDS; +#var WIN_RECT typedef struct{short x0,y0,x1,y1;}WIN_RECT; +#var WINDOW typedef struct WindowStruct{unsigned short Flags;unsigned char CurFont;unsigned char CurAttr;unsigned char Background;short TaskId;short CurX,CurY;short CursorX,CursorY;SCR_RECT Client;SCR_RECT Window;SCR_RECT Clip;SCR_RECT Port;unsigned short DupScr;struct WindowStruct*Next;char*Title;SCR_STATE savedScrState;unsigned char Reserved[16];}WINDOW; +#var WF_SYS_ALLOC D(1) +#var WF_STEAL_MEM D(2) +#var WF_DONT_REALLOC D(4) +#var WF_ROUNDEDBORDER D(8) +#var WF_SAVE_SCR D(16) +#var WF_DUP_SCR D(32) +#var WF_TTY D(64) +#var WF_ACTIVE D(128) +#var WF_NOBORDER D(256) +#var WF_NOBOLD D(512) +#var WF_DUP_ON D(1024) +#var WF_VIRTUAL D(2048) +#var WF_TITLE D(4096) +#var WF_DIRTY D(8192) +#var WF_TRY_SAVE_SCR D(16400) +#var WF_VISIBLE D(-32768) + +#var DeskTop D(((WINDOW*const)(((long*)(_rom_call_addr(0)))+1))) +#var FirstWindow D((*((WINDOW**)(_rom_call_addr(0))))) +#var DrawStaticButton D(_rom_call(void,(WINDOW*,short,short),35)) +#var DrawWinBorder D(_rom_call(void,(WINDOW*,SCR_RECT*),27)) +#var MakeWinRect D(_rom_call(WIN_RECT*,(short,short,short,short),2C)) +#var RectWinToScr D(_rom_call(SCR_RECT*,(const SCR_RECT*,const WIN_RECT*,SCR_RECT*),2A)) +#var RectWinToWin D(_rom_call(WIN_RECT*,(const SCR_RECT*,WIN_RECT*),29)) +#var WinActivate D(_rom_call(void,(WINDOW*),1)) +#var WinAttr D(_rom_call(short,(WINDOW*,short),2)) +#var WinBackground D(_rom_call(void,(WINDOW*,short),4)) +#var WinBackupToScr D(_rom_call(void,(WINDOW*),3)) +#var WinBegin D(_rom_call(void,(WINDOW*),5)) +#var WinBitmapGet D(_rom_call(short,(WINDOW*,const WIN_RECT*,void*),6)) +#var WinBitmapPut D(_rom_call(void,(WINDOW*,short,short,void*,short),7)) +#var WinBitmapSize D(_rom_call(unsigned short,(WINDOW*,const WIN_RECT*),8)) +#var WinChar D(_rom_call(void,(WINDOW*,char),A)) +#var WinCharXY D(_rom_call(void,(WINDOW*,short,short,char,short),9)) +#var WinClose D(_rom_call(void,(WINDOW*),B)) +#var WinClr D(_rom_call(void,(WINDOW*),C)) +#var WinDeactivate D(_rom_call(void,(WINDOW*),D)) +#var WinDupStat D(_rom_call(short,(WINDOW*,short),E)) +#var WinEllipse D(_rom_call(void,(WINDOW*,short,short,short,short),F)) +#var WinEnd(w) D(((void)0)) +#var WinFill D(_rom_call(void,(WINDOW*,const WIN_RECT*,short),10)) +#var WinFillLines2 D(_rom_call(void,(WINDOW*,const WIN_RECT*,const WIN_RECT*,short),11)) +#var WinFillTriangle D(_rom_call(void,(WINDOW*,short,short,short,short,short,short,short),12)) +#var WinFont D(_rom_call(void,(WINDOW*,short),13)) +#var WinGetCursor D(_rom_call(void,(WINDOW*,__pshort,__pshort),14)) +#var WinHeight D(_rom_call(short,(WINDOW*),292)) +#var WinHide D(_rom_call(void,(WINDOW*),15)) +#var WinHome D(_rom_call(void,(WINDOW*),16)) +#var WinLine D(_rom_call(void,(WINDOW*,const WIN_RECT*),17)) +#var WinLineNC D(_rom_call(void,(WINDOW*,const WIN_RECT*),18)) +#var WinLineRel D(_rom_call(void,(WINDOW*,short,short),1A)) +#var WinLineTo D(_rom_call(void,(WINDOW*,short,short),19)) +#var WinMoveCursor D(_rom_call(void,(WINDOW*,short,short),1B)) +#var WinMoveRel D(_rom_call(void,(WINDOW*,short,short),1D)) +#var WinMoveTo D(_rom_call(void,(WINDOW*,short,short),1C)) +#var WinOpen D(_rom_call(short,(WINDOW*,const WIN_RECT*,short,...),1E)) +#var WinPixGet D(_rom_call(short,(WINDOW*,short,short),1F)) +#var WinPixSet D(_rom_call(void,(WINDOW*,short,short),20)) +#var WinRect D(_rom_call(void,(WINDOW*,const WIN_RECT*,short),21)) +#var WinReOpen D(_rom_call(short,(WINDOW*,const WIN_RECT*,short,...),22)) +#var WinScrollH D(_rom_call(void,(WINDOW*,const WIN_RECT*,short),23)) +#var WinScrollV D(_rom_call(void,(WINDOW*,const WIN_RECT*,short),24)) +#var WinSetCursor(w,x,y) D((void)((w)->CursorX=x,(w)->CursorY=y)) +#var WinShow(w) D((void)((w)->Flags|=WF_VISIBLE)) +#var WinStr D(_rom_call(void,(WINDOW*,const char*),25)) +#var WinStrXY D(_rom_call(void,(WINDOW*,short,short,const char*),26)) +#var WinWidth D(_rom_call(short,(WINDOW*),291)) diff --git a/pch/srcdata/C-loseF-ile.ref b/pch/srcdata/C-loseF-ile.ref new file mode 100644 index 0000000..265eb7d --- /dev/null +++ b/pch/srcdata/C-loseF-ile.ref @@ -0,0 +1 @@ +OPENFILE.ext \ No newline at end of file diff --git a/pch/srcdata/CI1.ext b/pch/srcdata/CI1.ext new file mode 100644 index 0000000..9004868 Binary files /dev/null and b/pch/srcdata/CI1.ext differ diff --git a/pch/srcdata/CI2.ext b/pch/srcdata/CI2.ext new file mode 100644 index 0000000..825863f Binary files /dev/null and b/pch/srcdata/CI2.ext differ diff --git a/pch/srcdata/CI3.ext b/pch/srcdata/CI3.ext new file mode 100644 index 0000000..f1d70df Binary files /dev/null and b/pch/srcdata/CI3.ext differ diff --git a/pch/srcdata/O-penF-ile.ref b/pch/srcdata/O-penF-ile.ref new file mode 100644 index 0000000..265eb7d --- /dev/null +++ b/pch/srcdata/O-penF-ile.ref @@ -0,0 +1 @@ +OPENFILE.ext \ No newline at end of file diff --git a/pch/srcdata/OpenFile.ext b/pch/srcdata/OpenFile.ext new file mode 100644 index 0000000..aef7472 Binary files /dev/null and b/pch/srcdata/OpenFile.ext differ diff --git a/pch/srcdata/__mulsi3_rp.ref b/pch/srcdata/__mulsi3_rp.ref new file mode 100644 index 0000000..28ad806 --- /dev/null +++ b/pch/srcdata/__mulsi3_rp.ref @@ -0,0 +1 @@ +CI1.ext \ No newline at end of file diff --git a/pch/srcdata/__mulsi3si2_rp.ref b/pch/srcdata/__mulsi3si2_rp.ref new file mode 100644 index 0000000..3d259f9 --- /dev/null +++ b/pch/srcdata/__mulsi3si2_rp.ref @@ -0,0 +1 @@ +CI2.ext \ No newline at end of file diff --git a/pch/srcdata/__mulsi3ui2_rp.ref b/pch/srcdata/__mulsi3ui2_rp.ref new file mode 100644 index 0000000..1fc0bc7 --- /dev/null +++ b/pch/srcdata/__mulsi3ui2_rp.ref @@ -0,0 +1 @@ +CI3.ext \ No newline at end of file diff --git a/pch/srcdata/export.dat b/pch/srcdata/export.dat new file mode 100644 index 0000000..974c38f Binary files /dev/null and b/pch/srcdata/export.dat differ diff --git a/pch/srcdata/tigcc.a b/pch/srcdata/tigcc.a new file mode 100644 index 0000000..b524a3a Binary files /dev/null and b/pch/srcdata/tigcc.a differ diff --git a/pch/stdhead.89y b/pch/stdhead.89y new file mode 100644 index 0000000..3116411 Binary files /dev/null and b/pch/stdhead.89y differ diff --git a/pch/stdhead.def b/pch/stdhead.def new file mode 100644 index 0000000..d353aca --- /dev/null +++ b/pch/stdhead.def @@ -0,0 +1,939 @@ + +$ +AB_prodid +AB_prodname +AB_serno +APD_TIMER +ARROW_DOWN +ARROW_LEFT +ARROW_RIGHT +ARROW_UP +ASM_TAG +ASM_call +ASM_fastcall +AUTO_INT +AUTO_INT_1 +AUTO_INT_2 +AUTO_INT_3 +AUTO_INT_4 +AUTO_INT_5 +AUTO_INT_6 +AUTO_INT_7 +AUTO_INT_COUNT +A_AND +A_NORMAL +A_OR +A_REPLACE +A_REVERSE +A_SHADED +A_SHADE_H +A_SHADE_NS +A_SHADE_PS +A_SHADE_V +A_THICK1 +A_XOR +AddSymToFolder +ArgCount +AutoInts +BAD_FOLDER +BATT_TIMER +BCD_TAG +BEGIN_KEYTEST +BITMAP +BITMAP_HDR_SIZE +BITSPERBYTE +BOOL +BYTE +B_CUT +B_DOUBLE +B_NORMAL +B_ROUNDED +BitmapGet +BitmapInit +BitmapPut +BitmapSize +Bool +CB_fetchTEXT +CB_replaceTEXT +CESI +CF_CONVERT +CF_ENHANCED +CF_NEW +CF_NONE +CHAR_BIT +CHAR_MAX +CHAR_MIN +CURSOR_TIMER +CU_restore +CU_start +CU_stop +CheckLinkLockFlag +CheckReservedName +CheckSysFunc +ClearScreen +ClearUserDef +CloseFile +ClrScr +DARK_PLANE +DATA_TAG +DBL_DIG +DBL_EPSILON +DBL_MANT_BITS +DBL_MANT_DIG +DBL_MAX +DBL_MAX_10_EXP +DBL_MAX_2_EXP +DBL_MAX_EXP +DBL_MIN +DBL_MIN_10_EXP +DBL_MIN_2_EXP +DBL_MIN_EXP +DEFINE_INT_HANDLER +DEF_QUEUE +DMAXEXP +DMAXPOWTWO +DMINEXP +DSIGNIF +DUMMY_HANDLER +DWORD +DerefSym +DisableAutoInt3 +DisplayOff +DisplayOn +DrawChar +DrawClipChar +DrawClipEllipse +DrawClipLine +DrawClipPix +DrawClipRect +DrawFkey +DrawIcon +DrawLine +DrawMultiLines +DrawPix +DrawStr +DrawStrWidth +DrawStrXY +DrawTo +EM_GC +EM_abandon +EM_blockVerifyErase +EM_findEmptySlot +EM_moveSymFromExtMem +EM_moveSymToExtMem +EM_survey +EM_twinSymFromExtMem +EM_write +ENDFINAL +ENDTRY +END_KEYTEST +END_TAG +EOF +ERD_dialog +ERD_process +ERROR_FRAME +ER_ARGUMENT +ER_BREAK +ER_ESTACK_OVERFLOW +ER_EXIT +ER_MEMORY +ER_MEMORY_EXHAUSTION +ER_NO_MSG +ER_OFF +ER_OK +ER_OKAY +ER_PRGM_STOP +ER_STACK_VIO +ER_STOP +ER_SYNTAX +ER_THROW +ER_TOO_FEW_ARGS +ER_TOO_MANY_ARGS +ER_catch +ER_success +ER_throw +ER_throwVar +ESI +ESQ +EStackIndex +EX_getArg +EX_getBCD +EX_patch +EX_stoBCD +EnableAutoInt3 +ExecuteHandler +FALSE +FALSE_TAG +FIG_TAG +FILE +FINALLY +FIRST_AUTO_INT +FIRST_TRAP +FLOAT_TAG +FLT_DIG +FLT_EPSILON +FLT_MANT_BITS +FLT_MANT_DIG +FLT_MAX +FLT_MAX_10_EXP +FLT_MAX_2_EXP +FLT_MAX_EXP +FLT_MIN +FLT_MIN_10_EXP +FLT_MIN_2_EXP +FLT_MIN_EXP +FLT_NORMALIZE +FLT_RADIX +FLT_ROUNDS +FL_addCert +FL_download +FL_getCert +FL_getHardwareParmBlock +FL_getVerNum +FL_write +FMAXEXP +FMAXPOWTWO +FMINEXP +FOLDER_TABLE +FOP_ALL_FOLDERS +FOP_LOCK +FOP_UNLOCK +FO_CKTWINS +FO_NOTEMPS +FO_RECURSE +FO_RETURN_FOLDER +FO_RETURN_TWINS +FO_SINGLE_FOLDER +FO_SKIP_COLLAPSE +FO_SKIP_TEMPS +FSIGNIF +FUNC_TAG +F_4x6 +F_6x8 +F_8x10 +FillLines2 +FillTriangle +FindSymInFolder +FolderAdd +FolderAddTemp +FolderClear +FolderCount +FolderCur +FolderCurTemp +FolderDel +FolderDelAllTemp +FolderDelTemp +FolderFind +FolderGetCur +FolderOp +FolderRename +FontCharWidth +FontGetSys +FontSetSys +FreeHandles +GDB_TAG +GKeyDown +GKeyFlush +GKeyIn +GRAYDBUFFER_SIZE +GRAY_HW1 +GRAY_HW2 +GRAY_OFF +GRAY_ON +GetAMSSize +GetArgType +GetFloatArg +GetGrayInt1Handler +GetGraySwitchCount +GetIntArg +GetIntVec +GetLongLongArg +GetPix +GetPlane +GetStrnArg +GetSymstrArg +GrayAdjust +GrayCheckRunning +GrayDBufCleanup +GrayDBufGetActiveIdx +GrayDBufGetActivePlane +GrayDBufGetHiddenIdx +GrayDBufGetHiddenPlane +GrayDBufGetPlane +GrayDBufInit +GrayDBufSetAMSPlane +GrayDBufSetActiveAMSPlane +GrayDBufSetActiveIdx +GrayDBufSetActiveIdxSync +GrayDBufSetHiddenAMSPlane +GrayDBufToggle +GrayDBufToggleSync +GrayGetInt1Handler +GrayGetPlane +GrayGetSwitchCount +GrayGetVersionString +GrayMode +GrayOff +GrayOn +GraySetAMSPlane +GraySetInt1Handler +GraySetSwitchCount +GrayWaitNSwitches +HANDLE +HARDWARE_PARM_BLOCK +HIBITI +HIBITL +HIBITS +HLock +HSYM +HSYMtoName +HS_NULL +HSym +HSymDel +H_NULL +HeapAlloc +HeapAllocESTACK +HeapAllocHigh +HeapAllocHighThrow +HeapAllocPtr +HeapAllocPtrThrow +HeapAllocThrow +HeapAvail +HeapCompress +HeapDeref +HeapEnd +HeapFree +HeapFreeIndir +HeapFreePtr +HeapGetHandle +HeapGetLock +HeapLock +HeapMax +HeapMoveHigh +HeapPtrToHandle +HeapRealloc +HeapReallocThrow +HeapSize +HeapUnlock +HelpKeys +ICON +INT_HANDLER +INT_MAX +INT_MIN +INT_VEC_ADDRESS_ERROR +INT_VEC_ARCHIVE +INT_VEC_BUS_ERROR +INT_VEC_CHK_INS +INT_VEC_ER_THROW +INT_VEC_ILLEGAL_INSTRUCTION +INT_VEC_INT_MASK +INT_VEC_KEY_PRESS +INT_VEC_LINE_1010 +INT_VEC_LINE_1111 +INT_VEC_LINK +INT_VEC_MANUAL_RESET +INT_VEC_OFF +INT_VEC_ON_KEY_PRESS +INT_VEC_PRIVILEGE_VIOLATION +INT_VEC_RESET +INT_VEC_SELF_TEST +INT_VEC_SPURIOUS_INT +INT_VEC_STACK_OVERFLOW +INT_VEC_TRACE +INT_VEC_TRAPV_INS +INT_VEC_UNINITIALIZED_INT +INT_VEC_ZERO_DIVIDE +InitArgPtr +IsGrayMode +IsMainFolderStr +JMP_BUF +KEY_APPS +KEY_BACKSPACE +KEY_CHAR +KEY_CLEAR +KEY_ENTER +KEY_ENTRY +KEY_ESC +KEY_F1 +KEY_F2 +KEY_F3 +KEY_F4 +KEY_F5 +KEY_F6 +KEY_F7 +KEY_F8 +KEY_INS +KEY_MATH +KEY_MEM +KEY_MODE +KEY_OFF +KEY_ON +KEY_QUIT +KEY_RCL +KEY_SIGN +KEY_STO +KEY_SWITCH +KEY_VARLNK +LAST_AUTO_INT +LAST_TRAP +LCD_BUFFER +LCD_MEM +LCD_SIZE +LCD_restore +LCD_save +LDBL_DIG +LDBL_EPSILON +LDBL_MANT_BITS +LDBL_MANT_DIG +LDBL_MAX +LDBL_MAX_10_EXP +LDBL_MAX_2_EXP +LDBL_MAX_EXP +LDBL_MIN +LDBL_MIN_10_EXP +LDBL_MIN_2_EXP +LDBL_MIN_EXP +LIGHT_PLANE +LIO_CTX +LIO_Get +LIO_GetMultiple +LIO_Receive +LIO_RecvData +LIO_Send +LIO_SendData +LIO_SendProduct +LIO_TIMER +LIST_TAG +LN_MAXDOUBLE +LN_MINDOUBLE +LONG_MAX +LONG_MIN +LineTo +MAC_TAG +MAIN_FOLDER +MATRIX_TAG +MAXDOUBLE +MAXFLOAT +MAXINT +MAXLONG +MAXSHORT +MINDOUBLE +MINFLOAT +MISC_TIMER +MULTI_EXPR +MULTI_LINE +MakeHSym +MakeWinRect +MoveTo +NEGINT_TAG +NOT_FOUND +NULL +NeedStack +ONERR +OSCheckBreak +OSCheckSilentLink +OSClearBreak +OSContrastDn +OSContrastUp +OSDisableBreak +OSEnableBreak +OSFastArrows +OSFreeTimer +OSGetStatKeys +OSInitBetweenKeyDelay +OSInitKeyInitDelay +OSLinkClose +OSLinkCmd +OSLinkOpen +OSLinkReset +OSLinkTxQueueActive +OSLinkTxQueueInquire +OSReadLinkBlock +OSRegisterTimer +OSReset +OSSetSR +OSTimerCurVal +OSTimerExpired +OSTimerRestart +OSVFreeTimer +OSVRegisterTimer +OSWriteLinkBlock +OSdequeue +OSenqueue +OSqclear +OSqhead +OSqinquire +OTH_TAG +OpenFile +PASS +PIC_TAG +POSINT_TAG +PortRestore +PortSet +QModeKey +QScrRectOverlap +QSysKey +QSysProtected +QUEUE +Quantum +RAND_MAX +RR_0 +RR_1 +RR_2 +RR_2ND +RR_3 +RR_4 +RR_5 +RR_6 +RR_7 +RR_8 +RR_9 +RR_A +RR_ALPHA +RR_APPS +RR_B +RR_BCKSPC +RR_C +RR_CATALOG +RR_CLEAR +RR_COMMA +RR_COS +RR_D +RR_DIAMOND +RR_DIVIDE +RR_DOT +RR_DOWN +RR_E +RR_EE +RR_ENTER +RR_ENTER1 +RR_ENTER2 +RR_EQUALS +RR_ESC +RR_F +RR_F1 +RR_F2 +RR_F3 +RR_F4 +RR_F5 +RR_F6 +RR_F7 +RR_F8 +RR_G +RR_H +RR_HAND +RR_HOME +RR_I +RR_J +RR_K +RR_L +RR_LEFT +RR_LN +RR_M +RR_MINUS +RR_MODE +RR_MULTIPLY +RR_N +RR_NEGATE +RR_NO_KEY +RR_O +RR_P +RR_PAREN_CLOSE +RR_PAREN_OPEN +RR_PLUS +RR_POWER +RR_Q +RR_R +RR_RIGHT +RR_S +RR_SHIFT +RR_SIN +RR_SPACE +RR_STORE +RR_T +RR_TAN +RR_THETA +RR_U +RR_UP +RR_V +RR_W +RR_WITH +RR_X +RR_Y +RR_Z +ReleaseDate +ReleaseVersion +RemainingArgCnt +ResetSymFlags +RestoreScrState +SBYTE +SCHAR +SCHAR_MAX +SCHAR_MIN +SCR_COORDS +SCR_RECT +SCR_STATE +SDWORD +SEEK_CUR +SEEK_END +SEEK_SET +SF_ARCHIVED +SF_BUSY +SF_CHECKED +SF_COLLAPSED +SF_FOLDER +SF_GREF1 +SF_GREF2 +SF_HIDDEN +SF_INVIEW +SF_LOCAL +SF_LOCKED +SF_OPEN +SF_OVERWRITTEN +SF_STATVAR +SF_TWIN +SHRT_MAX +SHRT_MIN +SINT +SLONG +SPRT_AND +SPRT_OR +SPRT_XOR +SSHORT +STAT_2ND +STAT_DIAMOND +STAT_HAND +STAT_SHIFT +STR_TAG +ST_busy +ST_eraseHelp +ST_folder +ST_helpMsg +ST_refDsp +ST_showHelp +SWORD +SYMSTR +SYMSTR_CONST +SYM_ENTRY +SYM_STR +SaveScrState +ScrRect +ScrRectFill +ScrRectOverlap +ScrRectScroll +ScrRectShift +ScrToHome +ScrToWin +SetCurAttr +SetCurClip +SetGrayInt1Handler +SetGraySwitchCount +SetIntVec +SetPlane +SkipArg +Sprite16 +Sprite32 +Sprite8 +StrToTokN +SumStoChkMem +SymAdd +SymAddMain +SymAddTwin +SymCmp +SymCpy +SymCpy0 +SymDel +SymDelTwin +SymFind +SymFindFirst +SymFindFolderName +SymFindFoldername +SymFindHome +SymFindMain +SymFindNext +SymFindPrev +SymFindPtr +SymMove +SymSysVar +TEXT_TAG +TI89 +TI92PLUS +TMP_MAX +TRAP +TRAP_0 +TRAP_1 +TRAP_10 +TRAP_11 +TRAP_12 +TRAP_13 +TRAP_14 +TRAP_15 +TRAP_2 +TRAP_3 +TRAP_4 +TRAP_5 +TRAP_6 +TRAP_7 +TRAP_8 +TRAP_9 +TRAP_COUNT +TRUE +TRUE_TAG +TRY +TempFolderName +Timer_Callback_t +TokToStrN +UBYTE +UCHAR +UCHAR_MAX +UDWORD +UINT +UINT_MAX +ULONG +ULONG_MAX +UNDEF_TAG +USERFUNC_TAG +USER_TIMER +USHORT +USHRT_MAX +UWORD +V200 +VATSTR +ValidateSymName +VarRecall +VarStore +WINDOW +WIN_COORDS +WIN_RECT +WORD +WordInList +XR_stringPtr +_DEREF_INT_HANDLER +_DEXPLEN +_EXPBASE +_FEXPLEN +_F_BIN +_F_EOF +_F_ERR +_F_RDWR +_F_READ +_F_WRIT +_GrayIsRealHW2 +_IEEE +_OSInitBetweenKeyDelay +_RR +_RS +__D_plane +__D_plane2 +__EM_findEmptySlot +__FERROR +__Folder_Del +__L_plane +__L_plane2 +__TIGCCLIB_MINOR__ +__TIGCCLIB_SP__ +__TIGCCLIB_VERSION_STRING__ +__TIGCCLIB_VERSION__ +__TIGCCLIB__ +__assertion_failed +__div_entry +__divsi3 +__dummy_handler__ +__exit +__gray_dbl_offset +__gray_handle +__gray_hw_type +__gray_old_int1_hw1 +__gray_old_int1_hw2 +__gray_version +__keytest +__keytest_optimized +__modsi3 +__mulsi3 +__mulsi3_rp +__mulsi3si2_rp +__mulsi3ui2_rp +__randseed +__switch_cnt +__udivsi3 +__umodsi3 +__vcbprintf__type__ +_keytest +_keytest_optimized +_memset +_rowread +_rowread_internal +_rowread_inverted +_tolower +_toupper +abort +abs +atexit +atexit_t +atof +atoi +atol +bcd +bsearch +calloc +calloc_throw +checkCurrent +clearerr +clrscr +cmpstri +compare_t +div +div_t +enter_ghost_space +exit +fabs +fclose +feof +ferror +fflush +fgetc +fgetchar +fgetpos +fgets +find_error_message +flush_link +fopen +fpos_t +fprintf +fputc +fputchar +fputs +fread +free +freopen +fseek +fsetbufsize +fsetpos +ftell +fwrite +getc +getcalc +getchar +gets +idle +isGreek +isalnum +isalpha +isascii +iscntrl +isdigit +isextalnum +isextlower +isextpunct +isextupper +isfrgn +isfrgnalnum +isfrgnlower +isfrgnupper +isgraph +islower +isprint +ispunct +isspace +isupper +isxdigit +jmp_buf +kbd_queue +kbhit +ldiv +ldiv_t +longjmp +malloc +malloc_throw +max +memchr +memcmp +memcpy +memmove +memset +min +ngetchx +off +pICON +partial_len +peek +peekIO +peekIO_bit +peekIO_w +peek_bit +peek_l +peek_w +poke +pokeIO +pokeIO_bclr +pokeIO_bset +pokeIO_w +poke_bclr +poke_bset +poke_l +poke_w +printf +printf_xy +pushkey +putc +putchar +puts +qsort +rand +random +randomize +realloc +realloc_throw +receive +remove +rename +reset_link +rewind +sendcalc +setjmp +size_t +speek +speek_l +speek_w +sprintf +srand +strcat +strchr +strcmp +strcpy +strcspn +strerror +strlen +strncat +strncmp +strncpy +strpbrk +strputchar +strrchr +strspn +strstr +strtok +strtol +strtoul +ti_float +tmpnam +toascii +toextlower +toextupper +tolower +top_estack +toupper +transmit +tx_free +ungetc +unlink +va_arg +va_end +va_list +va_start +vcbprintf +vcbprintf_Callback_t +vcbprintf_callback_t +vfprintf +vprintf +vsprintf diff --git a/pch/stdhead.pch b/pch/stdhead.pch new file mode 100644 index 0000000..f9d8bd8 Binary files /dev/null and b/pch/stdhead.pch differ diff --git a/pch/subprojects/xupaki.pch b/pch/subprojects/xupaki.pch new file mode 100644 index 0000000..3770445 Binary files /dev/null and b/pch/subprojects/xupaki.pch differ diff --git a/pch/subprojects/xupaki/Unpack2.o b/pch/subprojects/xupaki/Unpack2.o new file mode 100644 index 0000000..ea83c4f Binary files /dev/null and b/pch/subprojects/xupaki/Unpack2.o differ diff --git a/pch/subprojects/xupaki/a2ext/U-npack.ref b/pch/subprojects/xupaki/a2ext/U-npack.ref new file mode 100644 index 0000000..00a1cf2 --- /dev/null +++ b/pch/subprojects/xupaki/a2ext/U-npack.ref @@ -0,0 +1 @@ +Unpack2.ext \ No newline at end of file diff --git a/pch/subprojects/xupaki/a2ext/Unpack2.ext b/pch/subprojects/xupaki/a2ext/Unpack2.ext new file mode 100644 index 0000000..2f9cc8e Binary files /dev/null and b/pch/subprojects/xupaki/a2ext/Unpack2.ext differ diff --git a/pch/subprojects/xupaki/a2ext/Unpack2.o b/pch/subprojects/xupaki/a2ext/Unpack2.o new file mode 100644 index 0000000..ea83c4f Binary files /dev/null and b/pch/subprojects/xupaki/a2ext/Unpack2.o differ diff --git a/pch/subprojects/xupaki/a2ext/deflt.txt b/pch/subprojects/xupaki/a2ext/deflt.txt new file mode 100644 index 0000000..f4d0c81 --- /dev/null +++ b/pch/subprojects/xupaki/a2ext/deflt.txt @@ -0,0 +1 @@ +#var Unpack diff --git a/pch/subprojects/xupaki/a2ext/export.dat b/pch/subprojects/xupaki/a2ext/export.dat new file mode 100644 index 0000000..a42c4b2 Binary files /dev/null and b/pch/subprojects/xupaki/a2ext/export.dat differ diff --git a/pch/subprojects/xupaki/export.dat b/pch/subprojects/xupaki/export.dat new file mode 100644 index 0000000..a42c4b2 Binary files /dev/null and b/pch/subprojects/xupaki/export.dat differ diff --git a/pch/subprojects/xupaki/xupaki.pchsource b/pch/subprojects/xupaki/xupaki.pchsource new file mode 100644 index 0000000..2c18e5b --- /dev/null +++ b/pch/subprojects/xupaki/xupaki.pchsource @@ -0,0 +1 @@ +#var Unpack char __attribute__((__stkparm__)) Unpack(void *src,void *dst); diff --git a/pch/tiosdlg.89y b/pch/tiosdlg.89y new file mode 100644 index 0000000..0f8297d Binary files /dev/null and b/pch/tiosdlg.89y differ diff --git a/pch/tiosdlg.def b/pch/tiosdlg.def new file mode 100644 index 0000000..8926991 --- /dev/null +++ b/pch/tiosdlg.def @@ -0,0 +1,168 @@ + +BT_CANCEL +BT_GOTO +BT_NO +BT_NONE +BT_OK +BT_SAVE +BT_YES +CENTER +DMF_BITMAP +DMF_CHILD +DMF_CHILD_SUB +DMF_ICON +DMF_TEXT +DMF_TOP +DMF_TOP_SUB +DeskTop +Dialog +DialogAdd +DialogAddPulldown +DialogAddRequest +DialogAddScroll +DialogAddText +DialogAddTitle +DialogDo +DialogNew +DialogNewSimple +DialogNew_t +DlgMessage +DrawStaticButton +DrawWinBorder +EVENT +FirstWindow +MBF_HMENU +MBF_MAX_MENU_WIDTH +MBF_NO_DRAWTOP +MBF_REDEF +MBF_STRIKEOUT +MBF_SYS_ALLOC +MBF_WITHICON +MC_CHECK +MC_FLIP +MC_STATUS +MC_UNCHECK +MF_ALT_ICONS +MF_BITMAP_TITLE +MF_DYN_POPUP +MF_ERROR +MF_ICONS_OVERLAP +MF_ICON_TITLE +MF_NONSEQ +MF_NO_NUMS +MF_NO_UNAMED +MF_POPUP +MF_TEXT_TITLE +MF_TITLE +MF_TOOLBOX +MT_CASCADE +MT_ICON +MT_TEXT +MT_XREF +M_NOITEM +M_NOTMENUKEY +MenuAddIcon +MenuAddText +MenuBegin +MenuCheck +MenuEnd +MenuGetTopRedef +MenuKey +MenuNew +MenuOn +MenuPopup +MenuSubStat +MenuTopRedef +MenuTopSelect +MenuTopStat +MenuUpdate +NoCallBack +PopupAddText +PopupClear +PopupDo +PopupNew +PopupText +RectWinToScr +RectWinToWin +TEXT_EDIT +TE_checkSlack +TE_close +TE_empty +TE_focus +TE_handleEvent +TE_indicateReadOnly +TE_isBlank +TE_open +TE_openFixed +TE_pasteText +TE_reopen +TE_reopenPlain +TE_select +TE_shrinkWrap +TE_unfocus +TE_updateCommand +VCFP_ALL +VCFP_SKIP_CURDIR +VarCreateFolderPopup +VarNew +VarOpen +VarSaveAs +WF_ACTIVE +WF_DIRTY +WF_DONT_REALLOC +WF_DUP_ON +WF_DUP_SCR +WF_NOBOLD +WF_NOBORDER +WF_ROUNDEDBORDER +WF_SAVE_SCR +WF_STEAL_MEM +WF_SYS_ALLOC +WF_TITLE +WF_TRY_SAVE_SCR +WF_TTY +WF_VIRTUAL +WF_VISIBLE +WinActivate +WinAttr +WinBackground +WinBackupToScr +WinBegin +WinBitmapGet +WinBitmapPut +WinBitmapSize +WinChar +WinCharXY +WinClose +WinClr +WinDeactivate +WinDupStat +WinEllipse +WinEnd +WinFill +WinFillLines2 +WinFillTriangle +WinFont +WinGetCursor +WinHeight +WinHide +WinHome +WinLine +WinLineNC +WinLineRel +WinLineTo +WinMoveCursor +WinMoveRel +WinMoveTo +WinOpen +WinPixGet +WinPixSet +WinReOpen +WinRect +WinScrollH +WinScrollV +WinSetCursor +WinShow +WinStr +WinStrXY +WinWidth diff --git a/pch/tiosdlg.pch b/pch/tiosdlg.pch new file mode 100644 index 0000000..bb74195 Binary files /dev/null and b/pch/tiosdlg.pch differ diff --git a/pch/wingraph.89y b/pch/wingraph.89y new file mode 100644 index 0000000..f3015ad Binary files /dev/null and b/pch/wingraph.89y differ diff --git a/pch/wingraph.def b/pch/wingraph.def new file mode 100644 index 0000000..ac5c506 --- /dev/null +++ b/pch/wingraph.def @@ -0,0 +1,73 @@ + +BT_CANCEL +BT_GOTO +BT_NO +BT_NONE +BT_OK +BT_SAVE +BT_YES +DeskTop +DrawStaticButton +DrawWinBorder +FirstWindow +RectWinToScr +RectWinToWin +WF_ACTIVE +WF_DIRTY +WF_DONT_REALLOC +WF_DUP_ON +WF_DUP_SCR +WF_NOBOLD +WF_NOBORDER +WF_ROUNDEDBORDER +WF_SAVE_SCR +WF_STEAL_MEM +WF_SYS_ALLOC +WF_TITLE +WF_TRY_SAVE_SCR +WF_TTY +WF_VIRTUAL +WF_VISIBLE +WinActivate +WinAttr +WinBackground +WinBackupToScr +WinBegin +WinBitmapGet +WinBitmapPut +WinBitmapSize +WinChar +WinCharXY +WinClose +WinClr +WinDeactivate +WinDupStat +WinEllipse +WinEnd +WinFill +WinFillLines2 +WinFillTriangle +WinFont +WinGetCursor +WinHeight +WinHide +WinHome +WinLine +WinLineNC +WinLineRel +WinLineTo +WinMoveCursor +WinMoveRel +WinMoveTo +WinOpen +WinPixGet +WinPixSet +WinReOpen +WinRect +WinScrollH +WinScrollV +WinSetCursor +WinShow +WinStr +WinStrXY +WinWidth diff --git a/pch/wingraph.pch b/pch/wingraph.pch new file mode 100644 index 0000000..06ab363 Binary files /dev/null and b/pch/wingraph.pch differ diff --git a/pch/xupaki.89y b/pch/xupaki.89y new file mode 100644 index 0000000..8c2dcdd Binary files /dev/null and b/pch/xupaki.89y differ diff --git a/pch/xupaki.pch b/pch/xupaki.pch new file mode 100644 index 0000000..3770445 Binary files /dev/null and b/pch/xupaki.pch differ diff --git a/platform.mk b/platform.mk new file mode 100644 index 0000000..285257c --- /dev/null +++ b/platform.mk @@ -0,0 +1,2 @@ +PLATFORM := $(shell uname) +BIN_SUFFIX := $(if $(patsubst CYGWIN%,,$(patsubst MINGW%,,$(PLATFORM))),,.exe) diff --git a/readme.html b/readme.html new file mode 100644 index 0000000..c5a7205 --- /dev/null +++ b/readme.html @@ -0,0 +1,11 @@ + + + + Readme + + + + +You can access the documentation here.
+ + diff --git a/ti68k/Makefile b/ti68k/Makefile new file mode 100644 index 0000000..4031056 --- /dev/null +++ b/ti68k/Makefile @@ -0,0 +1,51 @@ +all: +ifndef CALCULATOR +%: make89-% make9x-% makev2-% + @# dummy command, otherwise make ignores the rule +make89-%: + $(MAKE) $(patsubst make89-%,%,$@) CALCULATOR=89 +make9x-%: + $(MAKE) $(patsubst make9x-%,%,$@) CALCULATOR=9x +makev2-%: + $(MAKE) $(patsubst makev2-%,%,$@) CALCULATOR=v2 +else +PRETTY_CALCULATOR=$(if $(subst 89,,$(CALCULATOR)),$(if $(subst 9x,,$(CALCULATOR)),v200,92p),89) +DIR = bin-$(PRETTY_CALCULATOR) +MK = mkinfo-$(PRETTY_CALCULATOR)- + +all: ide h pch flashapp +ide: $(MK)ide +h: $(MK)h +pch: $(MK)pch +flashapp: $(MK)flashapp + +clean: +distclean: clean +scratchclean: distclean + $(RM) $(MK)* + $(RM) -r $(DIR) + +$(MK)h : ../h/processed/* +$(MK)pch : ../pch/* +$(MK)h : filedir = ../h/processed +$(MK)pch : filedir = ../pch +$(MK)h : fileext = t +$(MK)pch : fileext = y +$(MK)h $(MK)pch: files = $(wildcard $(filedir)/*.89$(fileext)) +$(MK)h $(MK)pch: + mkdir -p $(DIR) + $(foreach file,$(files),cp $(file) $(patsubst $(filedir)/%.89$(fileext),$(DIR)/%.$(CALCULATOR)$(fileext),$(file));) + touch $@ +$(MK)ide: ide/bin/* + mkdir -p $(DIR) + cp ide/bin/gtc-ide.$(CALCULATOR)z $(DIR) + touch $@ + +$(MK)flashapp: srcdata/flashapp/* +$(MK)flashapp: tifs_calc = $(if $(subst 89,,$(CALCULATOR)),92p,89) +$(MK)flashapp: tifs_ext = $(if $(subst 89,,$(CALCULATOR)),9xk,89k) +$(MK)flashapp: + mkdir -p $(DIR) + cp srcdata/flashapp/gtc-$(tifs_calc).$(tifs_ext) $(DIR)/gtc.$(CALCULATOR)k + touch $@ +endif diff --git a/ti68k/bin-89/assert.89t b/ti68k/bin-89/assert.89t new file mode 100644 index 0000000..e64b549 Binary files /dev/null and b/ti68k/bin-89/assert.89t differ diff --git a/ti68k/bin-89/compat.89t b/ti68k/bin-89/compat.89t new file mode 100644 index 0000000..99f0700 Binary files /dev/null and b/ti68k/bin-89/compat.89t differ diff --git a/ti68k/bin-89/default.89t b/ti68k/bin-89/default.89t new file mode 100644 index 0000000..4966a1f Binary files /dev/null and b/ti68k/bin-89/default.89t differ diff --git a/ti68k/bin-89/doors.89t b/ti68k/bin-89/doors.89t new file mode 100644 index 0000000..c79f0db Binary files /dev/null and b/ti68k/bin-89/doors.89t differ diff --git a/ti68k/bin-89/estack.89y b/ti68k/bin-89/estack.89y new file mode 100644 index 0000000..2003e70 Binary files /dev/null and b/ti68k/bin-89/estack.89y differ diff --git a/ti68k/bin-89/estackle.89y b/ti68k/bin-89/estackle.89y new file mode 100644 index 0000000..214255f Binary files /dev/null and b/ti68k/bin-89/estackle.89y differ diff --git a/ti68k/bin-89/events.89y b/ti68k/bin-89/events.89y new file mode 100644 index 0000000..0b1d047 Binary files /dev/null and b/ti68k/bin-89/events.89y differ diff --git a/ti68k/bin-89/extgraph.89t b/ti68k/bin-89/extgraph.89t new file mode 100644 index 0000000..1ea9709 Binary files /dev/null and b/ti68k/bin-89/extgraph.89t differ diff --git a/ti68k/bin-89/gen.89t b/ti68k/bin-89/gen.89t new file mode 100644 index 0000000..7baf2e8 Binary files /dev/null and b/ti68k/bin-89/gen.89t differ diff --git a/ti68k/bin-89/gtc-ide.89z b/ti68k/bin-89/gtc-ide.89z new file mode 100644 index 0000000..51d058d Binary files /dev/null and b/ti68k/bin-89/gtc-ide.89z differ diff --git a/ti68k/bin-89/gtc.89k b/ti68k/bin-89/gtc.89k new file mode 100644 index 0000000..b3d9a9e Binary files /dev/null and b/ti68k/bin-89/gtc.89k differ diff --git a/ti68k/bin-89/homescr.89y b/ti68k/bin-89/homescr.89y new file mode 100644 index 0000000..7fe5a7f Binary files /dev/null and b/ti68k/bin-89/homescr.89y differ diff --git a/ti68k/bin-89/keywords.89y b/ti68k/bin-89/keywords.89y new file mode 100644 index 0000000..49e8cf5 Binary files /dev/null and b/ti68k/bin-89/keywords.89y differ diff --git a/ti68k/bin-89/nostub.89t b/ti68k/bin-89/nostub.89t new file mode 100644 index 0000000..2897f15 Binary files /dev/null and b/ti68k/bin-89/nostub.89t differ diff --git a/ti68k/bin-89/patch.89t b/ti68k/bin-89/patch.89t new file mode 100644 index 0000000..094e1d4 Binary files /dev/null and b/ti68k/bin-89/patch.89t differ diff --git a/ti68k/bin-89/std.89t b/ti68k/bin-89/std.89t new file mode 100644 index 0000000..13d9c73 Binary files /dev/null and b/ti68k/bin-89/std.89t differ diff --git a/ti68k/bin-89/stdhead.89y b/ti68k/bin-89/stdhead.89y new file mode 100644 index 0000000..3116411 Binary files /dev/null and b/ti68k/bin-89/stdhead.89y differ diff --git a/ti68k/bin-89/tigcclib.89t b/ti68k/bin-89/tigcclib.89t new file mode 100644 index 0000000..1b1a777 Binary files /dev/null and b/ti68k/bin-89/tigcclib.89t differ diff --git a/ti68k/bin-89/tiosdlg.89y b/ti68k/bin-89/tiosdlg.89y new file mode 100644 index 0000000..0f8297d Binary files /dev/null and b/ti68k/bin-89/tiosdlg.89y differ diff --git a/ti68k/bin-89/ttunpack.89t b/ti68k/bin-89/ttunpack.89t new file mode 100644 index 0000000..742d096 Binary files /dev/null and b/ti68k/bin-89/ttunpack.89t differ diff --git a/ti68k/bin-89/wingraph.89y b/ti68k/bin-89/wingraph.89y new file mode 100644 index 0000000..f3015ad Binary files /dev/null and b/ti68k/bin-89/wingraph.89y differ diff --git a/ti68k/bin-89/xupak.89t b/ti68k/bin-89/xupak.89t new file mode 100644 index 0000000..131ce3a Binary files /dev/null and b/ti68k/bin-89/xupak.89t differ diff --git a/ti68k/bin-89/xupaki.89y b/ti68k/bin-89/xupaki.89y new file mode 100644 index 0000000..8c2dcdd Binary files /dev/null and b/ti68k/bin-89/xupaki.89y differ diff --git a/ti68k/bin-92p/assert.9xt b/ti68k/bin-92p/assert.9xt new file mode 100644 index 0000000..e64b549 Binary files /dev/null and b/ti68k/bin-92p/assert.9xt differ diff --git a/ti68k/bin-92p/compat.9xt b/ti68k/bin-92p/compat.9xt new file mode 100644 index 0000000..99f0700 Binary files /dev/null and b/ti68k/bin-92p/compat.9xt differ diff --git a/ti68k/bin-92p/default.9xt b/ti68k/bin-92p/default.9xt new file mode 100644 index 0000000..4966a1f Binary files /dev/null and b/ti68k/bin-92p/default.9xt differ diff --git a/ti68k/bin-92p/doors.9xt b/ti68k/bin-92p/doors.9xt new file mode 100644 index 0000000..c79f0db Binary files /dev/null and b/ti68k/bin-92p/doors.9xt differ diff --git a/ti68k/bin-92p/estack.9xy b/ti68k/bin-92p/estack.9xy new file mode 100644 index 0000000..2003e70 Binary files /dev/null and b/ti68k/bin-92p/estack.9xy differ diff --git a/ti68k/bin-92p/estackle.9xy b/ti68k/bin-92p/estackle.9xy new file mode 100644 index 0000000..214255f Binary files /dev/null and b/ti68k/bin-92p/estackle.9xy differ diff --git a/ti68k/bin-92p/events.9xy b/ti68k/bin-92p/events.9xy new file mode 100644 index 0000000..0b1d047 Binary files /dev/null and b/ti68k/bin-92p/events.9xy differ diff --git a/ti68k/bin-92p/extgraph.9xt b/ti68k/bin-92p/extgraph.9xt new file mode 100644 index 0000000..1ea9709 Binary files /dev/null and b/ti68k/bin-92p/extgraph.9xt differ diff --git a/ti68k/bin-92p/gen.9xt b/ti68k/bin-92p/gen.9xt new file mode 100644 index 0000000..7baf2e8 Binary files /dev/null and b/ti68k/bin-92p/gen.9xt differ diff --git a/ti68k/bin-92p/gtc-ide.9xz b/ti68k/bin-92p/gtc-ide.9xz new file mode 100644 index 0000000..dc8859c Binary files /dev/null and b/ti68k/bin-92p/gtc-ide.9xz differ diff --git a/ti68k/bin-92p/gtc.9xk b/ti68k/bin-92p/gtc.9xk new file mode 100644 index 0000000..fca265c Binary files /dev/null and b/ti68k/bin-92p/gtc.9xk differ diff --git a/ti68k/bin-92p/homescr.9xy b/ti68k/bin-92p/homescr.9xy new file mode 100644 index 0000000..7fe5a7f Binary files /dev/null and b/ti68k/bin-92p/homescr.9xy differ diff --git a/ti68k/bin-92p/keywords.9xy b/ti68k/bin-92p/keywords.9xy new file mode 100644 index 0000000..49e8cf5 Binary files /dev/null and b/ti68k/bin-92p/keywords.9xy differ diff --git a/ti68k/bin-92p/nostub.9xt b/ti68k/bin-92p/nostub.9xt new file mode 100644 index 0000000..2897f15 Binary files /dev/null and b/ti68k/bin-92p/nostub.9xt differ diff --git a/ti68k/bin-92p/patch.9xt b/ti68k/bin-92p/patch.9xt new file mode 100644 index 0000000..094e1d4 Binary files /dev/null and b/ti68k/bin-92p/patch.9xt differ diff --git a/ti68k/bin-92p/std.9xt b/ti68k/bin-92p/std.9xt new file mode 100644 index 0000000..13d9c73 Binary files /dev/null and b/ti68k/bin-92p/std.9xt differ diff --git a/ti68k/bin-92p/stdhead.9xy b/ti68k/bin-92p/stdhead.9xy new file mode 100644 index 0000000..3116411 Binary files /dev/null and b/ti68k/bin-92p/stdhead.9xy differ diff --git a/ti68k/bin-92p/tigcclib.9xt b/ti68k/bin-92p/tigcclib.9xt new file mode 100644 index 0000000..1b1a777 Binary files /dev/null and b/ti68k/bin-92p/tigcclib.9xt differ diff --git a/ti68k/bin-92p/tiosdlg.9xy b/ti68k/bin-92p/tiosdlg.9xy new file mode 100644 index 0000000..0f8297d Binary files /dev/null and b/ti68k/bin-92p/tiosdlg.9xy differ diff --git a/ti68k/bin-92p/ttunpack.9xt b/ti68k/bin-92p/ttunpack.9xt new file mode 100644 index 0000000..742d096 Binary files /dev/null and b/ti68k/bin-92p/ttunpack.9xt differ diff --git a/ti68k/bin-92p/wingraph.9xy b/ti68k/bin-92p/wingraph.9xy new file mode 100644 index 0000000..f3015ad Binary files /dev/null and b/ti68k/bin-92p/wingraph.9xy differ diff --git a/ti68k/bin-92p/xupak.9xt b/ti68k/bin-92p/xupak.9xt new file mode 100644 index 0000000..131ce3a Binary files /dev/null and b/ti68k/bin-92p/xupak.9xt differ diff --git a/ti68k/bin-92p/xupaki.9xy b/ti68k/bin-92p/xupaki.9xy new file mode 100644 index 0000000..8c2dcdd Binary files /dev/null and b/ti68k/bin-92p/xupaki.9xy differ diff --git a/ti68k/bin-v200/assert.v2t b/ti68k/bin-v200/assert.v2t new file mode 100644 index 0000000..e64b549 Binary files /dev/null and b/ti68k/bin-v200/assert.v2t differ diff --git a/ti68k/bin-v200/compat.v2t b/ti68k/bin-v200/compat.v2t new file mode 100644 index 0000000..99f0700 Binary files /dev/null and b/ti68k/bin-v200/compat.v2t differ diff --git a/ti68k/bin-v200/default.v2t b/ti68k/bin-v200/default.v2t new file mode 100644 index 0000000..4966a1f Binary files /dev/null and b/ti68k/bin-v200/default.v2t differ diff --git a/ti68k/bin-v200/doors.v2t b/ti68k/bin-v200/doors.v2t new file mode 100644 index 0000000..c79f0db Binary files /dev/null and b/ti68k/bin-v200/doors.v2t differ diff --git a/ti68k/bin-v200/estack.v2y b/ti68k/bin-v200/estack.v2y new file mode 100644 index 0000000..2003e70 Binary files /dev/null and b/ti68k/bin-v200/estack.v2y differ diff --git a/ti68k/bin-v200/estackle.v2y b/ti68k/bin-v200/estackle.v2y new file mode 100644 index 0000000..214255f Binary files /dev/null and b/ti68k/bin-v200/estackle.v2y differ diff --git a/ti68k/bin-v200/events.v2y b/ti68k/bin-v200/events.v2y new file mode 100644 index 0000000..0b1d047 Binary files /dev/null and b/ti68k/bin-v200/events.v2y differ diff --git a/ti68k/bin-v200/extgraph.v2t b/ti68k/bin-v200/extgraph.v2t new file mode 100644 index 0000000..1ea9709 Binary files /dev/null and b/ti68k/bin-v200/extgraph.v2t differ diff --git a/ti68k/bin-v200/gen.v2t b/ti68k/bin-v200/gen.v2t new file mode 100644 index 0000000..7baf2e8 Binary files /dev/null and b/ti68k/bin-v200/gen.v2t differ diff --git a/ti68k/bin-v200/gtc-ide.v2z b/ti68k/bin-v200/gtc-ide.v2z new file mode 100644 index 0000000..dc8859c Binary files /dev/null and b/ti68k/bin-v200/gtc-ide.v2z differ diff --git a/ti68k/bin-v200/gtc.v2k b/ti68k/bin-v200/gtc.v2k new file mode 100644 index 0000000..fca265c Binary files /dev/null and b/ti68k/bin-v200/gtc.v2k differ diff --git a/ti68k/bin-v200/homescr.v2y b/ti68k/bin-v200/homescr.v2y new file mode 100644 index 0000000..7fe5a7f Binary files /dev/null and b/ti68k/bin-v200/homescr.v2y differ diff --git a/ti68k/bin-v200/keywords.v2y b/ti68k/bin-v200/keywords.v2y new file mode 100644 index 0000000..49e8cf5 Binary files /dev/null and b/ti68k/bin-v200/keywords.v2y differ diff --git a/ti68k/bin-v200/nostub.v2t b/ti68k/bin-v200/nostub.v2t new file mode 100644 index 0000000..2897f15 Binary files /dev/null and b/ti68k/bin-v200/nostub.v2t differ diff --git a/ti68k/bin-v200/patch.v2t b/ti68k/bin-v200/patch.v2t new file mode 100644 index 0000000..094e1d4 Binary files /dev/null and b/ti68k/bin-v200/patch.v2t differ diff --git a/ti68k/bin-v200/std.v2t b/ti68k/bin-v200/std.v2t new file mode 100644 index 0000000..13d9c73 Binary files /dev/null and b/ti68k/bin-v200/std.v2t differ diff --git a/ti68k/bin-v200/stdhead.v2y b/ti68k/bin-v200/stdhead.v2y new file mode 100644 index 0000000..3116411 Binary files /dev/null and b/ti68k/bin-v200/stdhead.v2y differ diff --git a/ti68k/bin-v200/tigcclib.v2t b/ti68k/bin-v200/tigcclib.v2t new file mode 100644 index 0000000..1b1a777 Binary files /dev/null and b/ti68k/bin-v200/tigcclib.v2t differ diff --git a/ti68k/bin-v200/tiosdlg.v2y b/ti68k/bin-v200/tiosdlg.v2y new file mode 100644 index 0000000..0f8297d Binary files /dev/null and b/ti68k/bin-v200/tiosdlg.v2y differ diff --git a/ti68k/bin-v200/ttunpack.v2t b/ti68k/bin-v200/ttunpack.v2t new file mode 100644 index 0000000..742d096 Binary files /dev/null and b/ti68k/bin-v200/ttunpack.v2t differ diff --git a/ti68k/bin-v200/wingraph.v2y b/ti68k/bin-v200/wingraph.v2y new file mode 100644 index 0000000..f3015ad Binary files /dev/null and b/ti68k/bin-v200/wingraph.v2y differ diff --git a/ti68k/bin-v200/xupak.v2t b/ti68k/bin-v200/xupak.v2t new file mode 100644 index 0000000..131ce3a Binary files /dev/null and b/ti68k/bin-v200/xupak.v2t differ diff --git a/ti68k/bin-v200/xupaki.v2y b/ti68k/bin-v200/xupaki.v2y new file mode 100644 index 0000000..8c2dcdd Binary files /dev/null and b/ti68k/bin-v200/xupaki.v2y differ diff --git a/ti68k/ide/Makefile b/ti68k/ide/Makefile new file mode 100644 index 0000000..b511bab --- /dev/null +++ b/ti68k/ide/Makefile @@ -0,0 +1,55 @@ +# You will have to define environment variables corresponding to your system. + +ifdef GTCROOT +TIGCC = $(GTCROOT)/tigcc_for_ide/tigcc +LIBS = '$(shell $(TOTIGCCPATH) $(GTCROOT)/tigcc_for_ide/extgraph.a)' +endif +ifdef EXTGRAPH +LIBS = $(EXTGRAPH) +endif +ifndef NOT_CYGWIN +TOTIGCCPATH = cygpath -aw +INCLUDES = -I'$(shell $(TOTIGCCPATH) $(GTCROOT)/base_dir)' -I'$(shell $(TOTIGCCPATH) .)' +endif +ifndef TIGCC +TIGCC = tigcc +endif + +SWITCHES = -W -Wall -Wno-unused -O2 -fno-strict-aliasing -mregparm=3 -DFORCE_SMALL_FONT + + +all: bin/gtc-ide.89z bin/gtc-ide.9xz bin/gtc-ide.v2z + +superscratchclean: + rm -f bin/* + +bin/gtc-ide.89z : calc = _89 +bin/gtc-ide.89z : ext = 89 +bin/gtc-ide.9xz : calc = _92 +bin/gtc-ide.9xz : ext = 9x +bin/gtc-ide.v2z : calc = _92 +bin/gtc-ide.v2z : ext = v2 + +bin/gtc-ide.89z bin/gtc-ide.9xz bin/gtc-ide.v2z: *.c *.h + -mkdir tmp.ide$(ext) + cp main.c sunpack.c tmp.ide$(ext) + cd tmp.ide$(ext) && $(TIGCC) $(INCLUDES) $(SWITCHES) -D$(calc) -o gtc_ide main.c sunpack.c $(LIBS) + cp tmp.ide$(ext)/gtc_ide.$(ext)z bin/gtc-ide.$(ext)z + rm -rf tmp.ide$(ext) + + +pedrom: bin/gtc-ide-pedrom.89z bin/gtc-ide-pedrom.9xz bin/gtc-ide-pedrom.v2z + +bin/gtc-ide-pedrom.89z : calc = _89 +bin/gtc-ide-pedrom.89z : ext = 89 +bin/gtc-ide-pedrom.9xz : calc = _92 +bin/gtc-ide-pedrom.9xz : ext = 9x +bin/gtc-ide-pedrom.v2z : calc = _92 +bin/gtc-ide-pedrom.v2z : ext = v2 + +bin/gtc-ide-pedrom.89z bin/gtc-ide-pedrom.9xz bin/gtc-ide-pedrom.v2z: *.c *.h + -mkdir tmp.idepedrom$(ext) + cp main.c sunpack.c tmp.idepedrom$(ext) + cd tmp.idepedrom$(ext) && $(TIGCC) -DPEDROM $(INCLUDES) $(SWITCHES) -D$(calc) -o gtc_ide main.c sunpack.c $(LIBS) + cp tmp.idepedrom$(ext)/gtc_ide.$(ext)z bin/gtc-ide-pedrom.$(ext)z + rm -rf tmp.idepedrom$(ext) diff --git a/ti68k/ide/autoint_fix.h b/ti68k/ide/autoint_fix.h new file mode 100644 index 0000000..def94be --- /dev/null +++ b/ti68k/ide/autoint_fix.h @@ -0,0 +1,92 @@ +#ifndef OSKeyScan +#define OSKeyScan _rom_call(void,(void),298) +#endif + +#ifndef OLD_NONTITANIUM_METHOD +void *autoint_fix=0,*autoint_previous=0; +#define MAX_BLOCK1 150 +#define MAX_BLOCK2 500 +int autoint_fix_block[(MAX_BLOCK1+MAX_BLOCK2)/2]; +// !!! DIRTY HACK !!! +// -- but speeds up a whole lot :) +// !!! CAUTION : not tested on AMS3 !!! +void FixAutoint() { +#ifndef PEDROM + autoint_fix=0; + void *v1=GetIntVec(AUTO_INT_1); + autoint_previous=v1; + if (v1>=(void *)0x200000l) { + void *v2=(void *)OSKeyScan; + int l2=(void *)off - v2; + if ((unsigned int)l2>=MAX_BLOCK2) return; + int pos=0; + do { + pos+=2; + if (*(int *)(v1+pos)==0x4e75 || *(int *)(v1+pos)==0x4e73) return; + } while (*(void **)(v1+pos)!=v2); + pos+=4+6; // leave some room for the jmp + if (pos>=MAX_BLOCK1) return; + autoint_fix=autoint_fix_block; + memcpy(autoint_fix,v1,pos); + memcpy(autoint_fix+pos,v2,l2); + *(void **)(autoint_fix+pos-10)=autoint_fix+pos; + *(int *)(autoint_fix+pos-6)=0x4ef9; // jmp abs.l + *(void **)(autoint_fix+pos-4)=v1+pos-6; + int *z=autoint_fix+pos; + while (*z++!=0x58 && l2--); + if (l2>0) *--z=0x10; + SetIntVec(AUTO_INT_1,autoint_fix); + } +#endif +} +void RestoreAutoint() { +#ifndef PEDROM + if (autoint_fix) + SetIntVec(AUTO_INT_1,autoint_previous),autoint_fix=0; +#endif +} +#else +#define IntVec (*(void **)0x40064l) +void *autoint_fix=0,*autoint_previous=0; +// !!! DIRTY HACK !!! +// -- but speeds up a whole lot :) +// !!! CAUTION : not Titanium-compliant !!! +void FixAutoint() { +#ifndef PEDROM + autoint_fix=0; + void *v1=IntVec; + autoint_previous=v1; + if (v1>=(void *)0x200000l) { + void *v2=(void *)OSKeyScan; + int l2=(void *)off - v2; + if ((unsigned int)l2>=500) return; + int pos=0; + do { + pos+=2; + if (*(int *)(v1+pos)==0x4e75) return; + } while (*(void **)(v1+pos)!=v2); + pos+=4+6; // leave some room for the jmp + if (pos>=150) return; + autoint_fix=malloc(pos+l2); + if (!autoint_fix) return; + autoint_fix+=0x40000; // switch to ghost space + memcpy(autoint_fix,v1,pos); + memcpy(autoint_fix+pos,v2,l2); + *(void **)(autoint_fix+pos-10)=autoint_fix+pos; + *(int *)(autoint_fix+pos-6)=0x4ef9; // jmp abs.l + *(void **)(autoint_fix+pos-4)=v1+pos-6; + int *z=autoint_fix+pos; + while (*z++!=0x58 && l2--); + if (l2>0) *--z=0x10; + IntVec=autoint_fix; + } +#endif +} +void RestoreAutoint() { +#ifndef PEDROM + if (autoint_fix) + IntVec=autoint_previous,free(autoint_fix); +#endif +} +#undef IntVec +#endif diff --git a/ti68k/ide/axplore.h b/ti68k/ide/axplore.h new file mode 100644 index 0000000..7071a25 --- /dev/null +++ b/ti68k/ide/axplore.h @@ -0,0 +1,223 @@ +//void *Port=0; +#define DrawSStr(x,y,s) DStr((x)>>2,y,s) +/*void DrawSStr(int x,int y,char *s) { + DStr(x>>2,y,s); +}*/ + +typedef struct { + int i,t; + void *d; +} XP_S; +typedef struct { + XP_S *s; + int sh,sel,msel; +} XP_C; + +int XpMove(XP_C *xc,int n) { + XP_S *xs=xc->s+xc->sel,*lp=xc->s; + int d=(n>=0?1:-1); + while (n || xs->i<=0) { + if (!xs->i) return lp-xc->s; + if (xs->i>0) n-=d,lp=xs; + xs+=d; + } + return xs-xc->s; +} +char XpSprite[8*5]={ + 0,0,0,0,0,0,0,0, + 0b0110000, + 0b1001100, + 0b1110010, + 0b1001110, + 0b1000010, + 0b0111100, + 0,0, + 0b0000000, + 0b0110000, + 0b1001110, + 0b1000010, + 0b1000010, + 0b0111100, + 0,0, + 0b0000000, + 0b1111100, + 0b1000110, + 0b1000010, + 0b1000010, + 0b1111110, + 0,0, + 0b0000000, + 0b1111100, + 0b1000110, + 0b1011010, + 0b1000010, + 0b1111110, + 0,0, +}; + +/* [IFT_TEXT] 4, + [IFT_RES] 5, + [IFT_C] 6, + [IFT_H] 7, + [IFT_PRGM] 8, + [IFT_FUNC] 8, + [IFT_XFUNC]8, + [IFT_PACK] 9, + [IFT_EXPR] 10,*/ + +#define XP_X1 24 +#define XP_X2 136 +#define XP_N 8 +#define XP_H 6 +/*#define XP_Y1 14 +#define XP_Y2 (XP_Y1+8*XP_N)*/ +void XpDisp(XP_C *xc,int y) { + XP_S *xs=xc->s+xc->sh; + int r=xc->sel-xc->sh,n=XP_N; + if (xc->sh) DrawChar(XP_X1+1,y,UPARR,A_NORMAL); + do { + if (!xs->i) return; + if (xs->i>0) { + int x=XP_X1+2-8+6+(xs->i<<3); + Sprite8(x,y,8,XpSprite+(xs->t<<3),Port,A_NORMAL); + DrawSStr(x+8,y,(char *)xs->d); + if (!r) { + SCR_RECT sr={{XP_X1,y,XP_X2-1,y+XP_H-1}}; + ScrRectFill(&sr,ScrRect,A_XOR); + } + y+=XP_H; + n--; + } + xs++; r--; + } while (n || xs->i<=0); + DrawChar(XP_X1+1,y-XP_H,DNARR,A_XOR); +} + +void XpNeg(XP_C *xc) { + XP_S *xs=xc->s+xc->sel; + int z,z0=xs->i,d=0x8000|(0x8000u>>z0); + xs++; + z=xs->i; + if (z<0) d=~d; + while ((z>0?xs->i:-xs->i)>z0) { + if (z>0) xs->i|=d; + else { + xs->i&=d; + if (xs->i-8>0) xs->i|=0x8000; + } + xs++; + } +} + +typedef int (*__attribute__((stkparm)) XPLOOP_CB)(XP_C *xc,int key,void *ctx); +enum { XPLCB_CONT=0, XPLCB_QUIT=-1, XPLCB_BREAK=1, XPLCB_OPENDIR=2 }; +#define DEFINE_XPLOOP_CB(n) int __attribute__((stkparm)) n(XP_C *xc,int key,void *ctx) +DEFINE_XPLOOP_CB(std_callback) { + return XPLCB_CONT; +} +DEFINE_XPLOOP_CB(onlyfiles_callback) { + return key==KEY_ENTER && xc->s[xc->sel].t==2 ? XPLCB_OPENDIR : XPLCB_CONT; +} +XP_S *XpLoop(XP_C *xc,int y,XPLOOP_CB callback,void *ctx) { + int k,z; + if (!xc->s->i) return 0; + if (!callback) callback=std_callback; + DrawFrame(XP_X1-1,y-1,XP_X2,y+XP_H*XP_N); + do { + int cb_ret; + SCR_RECT sr={{XP_X1,y,XP_X2-1,y+XP_H*XP_N-1}}; + //LCD_save(Port); + ScrRectFill2(&sr,A_REVERSE); + //asm("0: bra 0b"); + XpDisp(xc,y); + callback(xc,0,ctx); + k=WaitLoop(NULL); + if ((cb_ret=callback(xc,k,ctx))) k=0; + if (cb_ret==XPLCB_OPENDIR) k=KEY_RIGHT; + #define xps_sel (xc->s[xc->sel]) + if (k==KEY_UP) xc->sel=XpMove(xc,-1); + else if (k==KEY_DOWN) xc->sel=XpMove(xc,1); + else if (k==(KEY_2ND|KEY_UP)) xc->sel=XpMove(xc,1-XP_N); + else if (k==(KEY_2ND|KEY_DOWN)) xc->sel=XpMove(xc,XP_N-1); + else if (k==KEY_LEFT) { + if ((z=xps_sel.i)>=2) + do xc->sel=XpMove(xc,-1); while ((unsigned)xps_sel.i>=(unsigned)z); + else if (xps_sel.t==1) + xps_sel.t=2,XpNeg(xc); + } else if (k==KEY_RIGHT && xps_sel.t==2) + xps_sel.t=1,XpNeg(xc); + else if (k==KEY_ENTER) + return &xps_sel; + z=xc->sel; + if (xc->sh>z) xc->sh=z; + if (xc->sh<(z=XpMove(xc,1-XP_N))) xc->sh=z; + } while (k!=KEY_ESC); + return NULL; +} + +long XpFatSub(XP_S *xs,char *acc,char *cfold) { + SYM_ENTRY *e=SymFindFirst(NULL,FO_RECURSE|FO_SKIP_TEMPS); + int n=0,n2=0,f=1; + while (e) { + long i=0x00010002; + if (!(e->flags.flags_n&SF_FOLDER)) { + CESI p=HeapDeref(e->handle); + if (p[1+*(unsigned int *)p]!=TEXT_TAG) goto nxt; + i=(f>=0?0xC0020003:0x00020003); +/* if (p[4]=='P') { + char *q=strchr(p+5,'\r'); + if (q) { + n2+=((q-(char *)p)-5)+1; + if (acc) strncpy(acc,p+5,(q-(char *)p)-5),e=(SYM_ENTRY *)acc,acc+=((q-(char *)p)-5),*acc++=0; + } + }*/ + f++; + } else { + if (!f) { + n--; + if (xs) xs--; + } + f=0; + if (!strcmp(e->name,cfold)) + f=0x8000,i--; + } + if (xs) { + *(long *)&xs->i=i; + xs->d=(void *)e->name; + xs++; + } + n++; + nxt: + e=SymFindNext(); + } + if (!f) { + n--; + if (xs) xs--; + } + if (xs) xs->i=0; + return n+((long)n2<<16); +} +XP_C *XpLoadFat(char *cfold) { + long r=XpFatSub(NULL,NULL,cfold); + int n=(int)r,n2=(int)(r>>16); + XP_C *xc=malloc(sizeof(XP_C)+(n+2)*sizeof(XP_S)+n2); + XP_S *xs; + if (!xc) return xc; + xs=(XP_S *)(xc+1); + xs->i=0; xs++; xc->s=xs; + XpFatSub(xs,(char *)(xs+(n+1)),cfold); + xc->sh=0; xc->sel=0; xc->msel=n-1; + return xc; +} +XP_C *XpLoadList(char **list,int n) { + XP_C *xc=malloc(sizeof(XP_C)+(n+2)*sizeof(XP_S)); + XP_S *xs; + if (!xc) return xc; + xs=(XP_S *)(xc+1); + xs->i=0; xs++; xc->s=xs; + xc->sh=0; xc->sel=0; xc->msel=n-1; + while (n--) + xs->i=1,xs->t=0,xs->d=*list++,xs++; + xs->i=0; + return xc; +} diff --git a/ti68k/ide/bin/gtc-ide.89z b/ti68k/ide/bin/gtc-ide.89z new file mode 100644 index 0000000..51d058d Binary files /dev/null and b/ti68k/ide/bin/gtc-ide.89z differ diff --git a/ti68k/ide/bin/gtc-ide.9xz b/ti68k/ide/bin/gtc-ide.9xz new file mode 100644 index 0000000..dc8859c Binary files /dev/null and b/ti68k/ide/bin/gtc-ide.9xz differ diff --git a/ti68k/ide/bin/gtc-ide.v2z b/ti68k/ide/bin/gtc-ide.v2z new file mode 100644 index 0000000..dc8859c Binary files /dev/null and b/ti68k/ide/bin/gtc-ide.v2z differ diff --git a/ti68k/ide/dialogs.h b/ti68k/ide/dialogs.h new file mode 100644 index 0000000..d90618a --- /dev/null +++ b/ti68k/ide/dialogs.h @@ -0,0 +1,332 @@ +#if 0 +void SearchDlg(int replace,int key) { + int r; + if ((r=DialogProcess(key))) + switch (r) { + case DLG_OK: + ResetSearch(); + if (!DoSearch(replace)) + return 0; + break; + } + return 1; +} +#endif + +#include "aXplore.h" + +void boxProcess(EDIT_LINE *e,int key) { + if (key==KEY_BACKSPACE) delEditLine(e,1); + else if (key>=14 && key<=255) { if (insEditLine(e,1)) getEditLinePos(e)[-1]=(char)key; } + else if (key==KEY_LEFT) ScrollUp(&e->scr); + else if (key==KEY_RIGHT) ScrollDn(&e->scr); +} +int checkProcess(int v,int a,int key) { + if (key==KEY_LEFT || key==KEY_RIGHT) + return v^a; + return v; +} + +/* Search dialog box : +Text to find [...] +Replace with [...] +[*] Whole word only +[*] Case-sensitive matching/Match case +[*] Search all files +[*] Create search results form +[*] Regular expression +*/ +#define SDLG_BUF_SIZE 128 +#define SDLG_LEFT_MARGIN 14 +#define SDLG_NUM_OPTS 3 +void boxDisp(EDIT_LINE *e, + char *s,int x,int y,int sel,int blink,char *buf,char *inittext,int x0,int x1,int init) { + if (init) { + newEditLine(e,buf,SDLG_BUF_SIZE,x0,x1-1,y+1); + insEditLine(e,strlen(inittext)); + strcpy(buf,inittext); + } + VariableDStr(x,y+1,s); + updEditLine(e); + drawEditLine(e,sel,blink); +} + +enum { SDLG_WW=0x1, SDLG_CS=0x2, SDLG_SA=0x4, SDLG_ALL=0x40, SDLG_REPL=0x80, }; +char text_find[SDLG_BUF_SIZE],text_repl[SDLG_BUF_SIZE]; +int search_attr=0; +int search_coord=0; +int SearchDlg(int rep) { + WIN_RECT win; + int key; + int n_it=1+rep+SDLG_NUM_OPTS,sel_it=0,blink=0; + int a=search_attr,s; + char buf_find[SDLG_BUF_SIZE],buf_repl[SDLG_BUF_SIZE]; + EDIT_LINE box_find,box_repl; + int init=1,x,y; + PushScr(); + while (1) { + dialog((rep?"Replace text":"Find text"),120,8+(rep?8:0)+6*SDLG_NUM_OPTS,B_MOVEAROUND|B_ROUNDED,&win); + x=physical_to_virtual(win.x0); y=win.y0; + boxDisp(&box_find,"Text to find:",x,y,sel_it-0,blink, + buf_find,text_find,x+SDLG_LEFT_MARGIN,win.x1>>2,init), y+=8; + if (rep) + boxDisp(&box_repl,"Replace with:",x,y,sel_it-1,blink, + buf_repl,text_repl,x+SDLG_LEFT_MARGIN,win.x1>>2,init), y+=8; + s=sel_it-rep-1; + drawCheckBox("Whole word only", a,SDLG_WW,x,y,s-0), y+=6; + drawCheckBox("Case-sensitive", a,SDLG_CS,x,y,s-1), y+=6; + drawCheckBox("Search all files",a,SDLG_SA,x,y,s-2), y+=6; + init=0; + key=WaitLoop(&blink); + if (!key) continue; + blink=0; + if (key==KEY_UP && sel_it) sel_it--; + else if (key==KEY_DOWN && sel_it='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9') || c=='_' || c=='$') +int DoSearch() { + int a=search_attr,f=0; + if (*text_find) { + char *p=tptr+curpos,*q=text_find; + char v=*q++,v2=(!(a&SDLG_CS) && isalpha(v)?v^0x20:v),c,d; + int n,need_nonidch=(a&SDLG_WW?is_c_idch(v):0); + while (*p) { + if ((*p==v && (p++,1)) || *p++==v2) { + char *s=p; + if (need_nonidch && is_c_idch(p[-2])) continue; + if (a&SDLG_CS) { + while ((c=*q++)) + if (*p++!=c) goto not_here; + } else { + while ((c=*q++)) + if ((d=*p++)!=c) { + if ((d^=c)!=0x20) goto not_here; + c|=d; + if (!(c>='a' && c<='z')) goto not_here; + } + } + if ((a&SDLG_WW) && is_c_idch(p[-1]) && is_c_idch(*p)) goto not_here; + // we have a match :) + f++; + sel1=cpos=(s-tptr)-1; + sel2=curpos=selpos=cpos+strlen(text_find); + if (a&SDLG_REPL) { + sel_del(); // this is legal because we updated sel1 & sel2 + insert(n=strlen(text_repl)); + selpos=cpos; + cpos=selpos-n; + memcpy(tptr+cpos,text_repl,n); + } + if (!(a&SDLG_ALL)) return 1; + not_here: + p=s; + q=text_find+1; + } + } + } + if (f) return -1; + PushScr(); + SimpleDlg("Find text","\nText not found!\n",B_CENTER,W_NORMAL); + PopScr(); + return 0; +} + +char wzTitle[40]; +char *wzStepPtr=0; +#define wzStep (*wzStepPtr) +int wzSuccess=0; +int wzText(char *prompt,char *dest,int n) { + WIN_RECT win; + int key; + int blink=0; + EDIT_LINE box; + int init=1,x,y; + char buf[n+1]; + wzStep++; + PushScr(); + while (1) { + dialog(wzTitle,120,12,B_CENTER|B_ROUNDED,&win); + x=win.x0>>2; y=win.y0+2; + boxDisp(&box,prompt,x,y,0,blink, + buf,dest,x+strlen(prompt)+1,win.x1>>2,init), y+=8; + init=0; + key=WaitLoop(&blink); + if (!key) continue; + blink=0; + boxProcess(&box,key); + if (key==KEY_ENTER) { + strcpy(dest,buf); + PopScr(); + return 1; + } else if (key==KEY_ESC) { + wzStep-=2; + PopScr(); + return 0; + } + } +} +int wzTextClr(char *prompt,char *dest,int n) { + dest[0]=0; + return wzText(prompt,dest,n); +} +int wzChoice(char *prompt,char **choice,int choicen,int *dest) { + wzStep++; + XP_C *xc=XpLoadList(choice,choicen); + int h=8; + WIN_RECT win; + PushScr(); + dialog(wzTitle,120,h+XP_H*XP_N,B_CENTER|B_ROUNDED,&win); + VariableDStr(physical_to_virtual(win.x0),win.y0,prompt); + xc->sel=*dest; + if (!XpLoop(xc,win.y0+h,NULL,NULL)) { + PopScr(); + wzStep-=2; + free(xc); + return 0; + } else { + PopScr(); + *dest=xc->sel; + free(xc); + return 1; + } +} +int wzChoiceDeflt(char *prompt,char **choice,int choicen,int *dest,int v) { + *dest=v; + return wzChoice(prompt,choice,choicen,dest); +} +void wzStart(char *title,char *numSteps) { + strcpy(wzTitle,title); + strcat(wzTitle," - Step "); + wzStepPtr=wzTitle+strlen(wzTitle); + strcat(wzTitle,"x of "); + strcat(wzTitle,numSteps); + wzSuccess=0; + wzStep='0'; +} +void wzDone(char *text) { + wzSuccess=1; + wzTitle[strlen(wzTitle)-sizeof("- Step x of y")]='\0'; +// asm("0:bra 0b"); + PushScr(); + SimpleDlg(wzTitle,text,B_CENTER,W_NORMAL|ICO_INFO); + PopScr(); +} +#define wzList(a...) ((char *[]){a}),sizeof((char *[]){a})/sizeof(char *) +#define wzErr(m) ({SimpleDlg(wzTitle,m,B_CENTER,W_NORMAL|ICO_ERROR);continue;}) + +#if 0 +typedef struct { + int t,id,x,y; + union { + TEXT txt; + SCROLL sc; + char *s; + } d; +} DLG_ITEM; +typedef struct { + SCROLL sel; + char *title; + int w,h,a; // width, height, attr + DLG_ITEM i[]; +} DLG; + +int DialogProcess(int key) { + DLG *d=cur_dlg; + DLG_ITEM *i; + int s; + if (key==KEY_UP) + ScrollUp(&d->sel); + else if (key==KEY_DOWN) + ScrollDn(&d->sel); + else if (key==KEY_ENTER) + return DLG_OK; + else if (key==KEY_ESC) + return DLG_ESC; + ScrollUpdNoWrap(&d->sel); + s=d->sel.sel; + i=&d->i[s]; + if (i->t<=0) + return DialogProcess(key); + switch (i->t) { + case DT_TBOX: + cur_text=i->d.txt; + return KeyProcess(key,TM_DIALOG); + case DT_MLTBOX: + cur_text=i->d.txt; + return KeyProcess(key,TM_DIALOG|TM_MULTILINE); + case DT_CBOX: + case DT_DROPDOWN: + if (key==KEY_LEFT) + ScrollUp(&i->d.sc); + else if (key==KEY_RIGHT) + ScrollDn(&i->d.sc); + ScrollUpd(&i->d.sc); + break; + case DT_TEXT: + break; + } + return 0; +} + +void DialogDisp() { + DLG *d=cur_dlg; + int n=cur_dlg->sel.n; + DLG_ITEM *i=d->i; + dialog(d->title,d->w,d->h,d->a); + while (n--) { + switch (i->t) { + case DT_TEXT: + VariableDStr(i->x,i->y,i->d.s); + break; + } + i++; + } +} + +enum { +#define DL_SKIP(x) -(x) + DL_END=0, + +}; +int DialogLoadSub(int *p,DLG_ITEM *i,int x0) { + int n=0,x=x0,y=0,z; + while (*p) { + switch ((z=*p++)) { + case DL_TEXT: + if (i) { + i->t=DT_TEXT; + i->id=*p++; + i->x=x; i->y=y; + i->d.s=p; + while (*p++); + } else { p++; while (*p++); } + n++; + y+=char_height+1; + break; + default: // DL_SKIP(-z) + p-=z; + break; + } + } +} +void DialogLoad(int *p) { +} +#endif diff --git a/ti68k/ide/display.h b/ti68k/ide/display.h new file mode 100644 index 0000000..b07521a --- /dev/null +++ b/ti68k/ide/display.h @@ -0,0 +1,652 @@ +// Displaying routines +void *Port=0; +int ycur=0; +#ifdef FORCE_SMALL_FONT +#define char_width 4 +#define virtual_char_width 1 +#define char_height 6 +#define physical_to_virtual(px) ((px)>>2) +#define virtual_to_physical(vx) ((vx)<<2) +typedef char CHAR[char_height]; +#else +int small_font = -1; +int char_width = 0; +int virtual_char_width = 0; +int char_height = 0; +enum { FONT_MEDIUM = 0, FONT_SMALL = 1 }; +void set_font(int font) { + small_font = font; + char_width = font==FONT_MEDIUM ? 6 : 4; + virtual_char_width = font==FONT_MEDIUM ? 6 : 1; + char_height = font==FONT_MEDIUM ? 8 : 6; +} +int physical_to_virtual(int px) { + if (small_font) + return px>>2; + return px; +} +int virtual_to_physical(int vx) { + if (small_font) + return vx<<2; + return vx; +} +#endif + +#ifdef __GTC__ +void SmallDChar(int x,int y,char c) __attribute__((__regparm__(3,0))); +void SmallDCharS(int x,int y,char c) __attribute__((__regparm__(3,0))); +void SmallDCharX(int x,int y,char c) __attribute__((__regparm__(3,0))); +#define xregparm(g,d,a) __attribute__((regparm(d,a))) +#else +void __attribute__((__regparm__(3))) SmallDChar(int x,int y,char c); +void __attribute__((__regparm__(3))) SmallDCharS(int x,int y,char c); +void __attribute__((__regparm__(3))) SmallDCharX(int x,int y,char c); +#define xregparm(g,d,a) __attribute__((regparm(g))) +#endif +#ifdef __GTC__ +#define SECTION_FONT +asm { + even +SmallDCharX: + and.w #0xFF,d2 + add.w d2,d2 + move.w d2,a1 + add.w d2,d2 + add.w a1,d2 + lea font(pc),a1 + add.w d2,a1 + add.w d1,d1 + move.w d1,d2 + lsl.w #4,d1 + sub.w d2,d1 + moveq #0x0000000F,d2 + asr.w #1,d0 + bcs.s \X_ok_d2 + moveq #0xFFFFFFF0,d2 +\X_ok_d2: + move.l Port,a0 + add.w d1,d0 + add.w d0,a0 + move.b (a1)+,d0 + and.b d2,d0 + eor.b d0,(a0) + move.b (a1)+,d0 + and.b d2,d0 + eor.b d0,30(a0) + move.b (a1)+,d0 + and.b d2,d0 + eor.b d0,60(a0) + move.b (a1)+,d0 + and.b d2,d0 + eor.b d0,90(a0) + move.b (a1)+,d0 + and.b d2,d0 + eor.b d0,120(a0) + move.b (a1),d0 + and.b d2,d0 + eor.b d0,150(a0) + rts + even +SmallDCharS: + move.l Port,a0 + and.w #0xFF,d2 + add.w d2,d2 + move.w d2,a1 + add.w d2,d2 + add.w a1,d2 + lea font(pc),a1 + add.w d2,a1 + add.w d1,d1 + move.w d1,d2 + lsl.w #4,d1 + sub.w d2,d1 + moveq #0x0000000F,d2 + asr.w #1,d0 + bcs.s \S_ok_d2 + moveq #0xFFFFFFF0,d2 +\S_ok_d2: + add.w d1,d0 + add.w d0,a0 + move.b (a1)+,d0 + not.b d0 + and.b d2,d0 + or.b d0,(a0) + move.b (a1)+,d0 + not.b d0 + and.b d2,d0 + or.b d0,30(a0) + move.b (a1)+,d0 + not.b d0 + and.b d2,d0 + or.b d0,60(a0) + move.b (a1)+,d0 + not.b d0 + and.b d2,d0 + or.b d0,90(a0) + move.b (a1)+,d0 + not.b d0 + and.b d2,d0 + or.b d0,120(a0) + move.b (a1),d0 + not.b d0 + and.b d2,d0 + or.b d0,150(a0) + rts + even +SmallDChar: + and.w #0xFF,d2 + add.w d2,d2 + move.w d2,a1 + add.w d2,d2 + add.w a1,d2 + lea font(pc),a1 + add.w d2,a1 + add.w d1,d1 + move.w d1,d2 + lsl.w #4,d1 + sub.w d2,d1 + moveq #0x0000000F,d2 + asr.w #1,d0 + bcs.s \ok_d2 + moveq #0xFFFFFFF0,d2 +\ok_d2: + move.l Port,a0 + add.w d1,d0 + add.w d0,a0 + move.b (a1)+,d0 + and.b d2,d0 + or.b d0,(a0) + move.b (a1)+,d0 + and.b d2,d0 + or.b d0,30(a0) + move.b (a1)+,d0 + and.b d2,d0 + or.b d0,60(a0) + move.b (a1)+,d0 + and.b d2,d0 + or.b d0,90(a0) + move.b (a1)+,d0 + and.b d2,d0 + or.b d0,120(a0) + move.b (a1),d0 + and.b d2,d0 + or.b d0,150(a0) + rts +} +#else +#define ASM_SECTION_FONT //".section fontmanip" +#define SECTION_FONT //__attribute__((section("fontmanip"))) +asm(ASM_SECTION_FONT " + .even + .globl SmallDCharX +SmallDCharX: + and.w #0xFF,%d2 + add.w %d2,%d2 + move.w %d2,%a1 + add.w %d2,%d2 + add.w #262,%d2 /* to be able to use PC-relative font */ + add.w %a1,%d2 + lea font-262(%pc,%d2.w),%a1 /* this offset should be 2 (0 doesn't seem to work) */ + add.w %d1,%d1 + move.w %d1,%d2 + lsl.w #4,%d1 + sub.w %d2,%d1 + moveq #0x0000000F,%d2 + asr.w #1,%d0 + bcs.s DChX_ok_d2 + moveq #0xFFFFFFF0,%d2 +DChX_ok_d2: + move.l Port,%a0 + add.w %d1,%d0 + add.w %d0,%a0 + move.b (%a1)+,%d0 + and.b %d2,%d0 + eor.b %d0,(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + eor.b %d0,30(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + eor.b %d0,60(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + eor.b %d0,90(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + eor.b %d0,120(%a0) + move.b (%a1),%d0 + and.b %d2,%d0 + eor.b %d0,150(%a0) + rts + .even + .globl SmallDCharS +SmallDCharS: + move.l Port,%a0 + and.w #0xFF,%d2 + addq.w #8,%d2 /* to be able to use PC-relative font */ + add.w %d2,%d2 + move.w %d2,%a1 + add.w %d2,%d2 + add.w %a1,%d2 + lea font-48(%pc,%d2.w),%a1 + add.w %d1,%d1 + move.w %d1,%d2 + lsl.w #4,%d1 + sub.w %d2,%d1 + moveq #0x0000000F,%d2 + asr.w #1,%d0 + bcs.s DChS_ok_d2 + moveq #0xFFFFFFF0,%d2 +DChS_ok_d2: + add.w %d1,%d0 + add.w %d0,%a0 + move.b (%a1)+,%d0 + not.b %d0 + and.b %d2,%d0 + or.b %d0,(%a0) + move.b (%a1)+,%d0 + not.b %d0 + and.b %d2,%d0 + or.b %d0,30(%a0) + move.b (%a1)+,%d0 + not.b %d0 + and.b %d2,%d0 + or.b %d0,60(%a0) + move.b (%a1)+,%d0 + not.b %d0 + and.b %d2,%d0 + or.b %d0,90(%a0) + move.b (%a1)+,%d0 + not.b %d0 + and.b %d2,%d0 + or.b %d0,120(%a0) + move.b (%a1),%d0 + not.b %d0 + and.b %d2,%d0 + or.b %d0,150(%a0) + rts + .even + .globl SmallDChar +SmallDChar: + and.w #0xFF,%d2 + add.w %d2,%d2 + move.w %d2,%a1 + add.w %d2,%d2 + add.w %a1,%d2 + lea font(%pc,%d2.w),%a1 + add.w %d1,%d1 + move.w %d1,%d2 + lsl.w #4,%d1 + sub.w %d2,%d1 + moveq #0x0000000F,%d2 + asr.w #1,%d0 + bcs.s DCh_ok_d2 + moveq #0xFFFFFFF0,%d2 +DCh_ok_d2: + move.l Port,%a0 + add.w %d1,%d0 + add.w %d0,%a0 + move.b (%a1)+,%d0 + and.b %d2,%d0 + or.b %d0,(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + or.b %d0,30(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + or.b %d0,60(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + or.b %d0,90(%a0) + move.b (%a1)+,%d0 + and.b %d2,%d0 + or.b %d0,120(%a0) + move.b (%a1),%d0 + and.b %d2,%d0 + or.b %d0,150(%a0) + rts +"); +#endif + +const unsigned short SECTION_FONT font[]={ + #include "font.h" +}; +#define DOTS "\xA0\x01" +#define DOTS1 '\xA0' +#define DOTS2 '\x01' +#define UPARR '\x13' +#define DNARR '\x14' +char icons[]={ + 0b11111100, + 0b11111100, + 0b11000100, + 0b10110100, + 0b10110100, + 0b11000100, + 0b11111100, + + 0b11111100, + 0b11001100, + 0b10110100, + 0b10000100, + 0b10110100, + 0b10110100, + 0b11111100, + + 0b00000000, + 0b00000000, + 0b00111000, + 0b01001000, + 0b01001000, + 0b00111000, + 0b00000000, +#ifdef _89 + 0b00000000, + 0b00100000, + 0b01110000, + 0b11111000, + 0b01110000, + 0b00100000, + 0b00000000, + + 0b00000000, + 0b00100000, + 0b01110000, + 0b11111000, + 0b01110000, + 0b01110000, + 0b00000000, +#else + 0b00000000, + 0b00100000, + 0b01110000, + 0b11111000, + 0b01110000, + 0b01110000, + 0b00000000, + + 0b00000000, + 0b00100000, + 0b01110000, + 0b11111000, + 0b01110000, + 0b00100000, + 0b00000000, +#endif + 0b00000000, + 0b00110000, + 0b01001000, + 0b00010000, + 0b00100000, + 0b01111000, + 0b00000000, +}; + +/*void __attribute__((__regparm__(3))) SmallDChar(int x,int y,char c) { + char *p=((CHAR *)font)[c&255],*s=Port+(x>>1)+y*30; + int m; + if (x&1) m=0x0F; + else m=0xF0; + s[30*0]|=(*p++)&m; + s[30*1]|=(*p++)&m; + s[30*2]|=(*p++)&m; + s[30*3]|=(*p++)&m; + s[30*4]|=(*p++)&m; + s[30*5]|=(*p++)&m; +} +void __attribute__((__regparm__(3))) SmallDCharS(int x,int y,char c) { + char *p=((CHAR *)font)[c&255],*s=Port+(x>>1)+y*30; + int m; + if (x&1) m=0x0F; + else m=0xF0; + s[30*0]|=(~*p++)&m; + s[30*1]|=(~*p++)&m; + s[30*2]|=(~*p++)&m; + s[30*3]|=(~*p++)&m; + s[30*4]|=(~*p++)&m; + s[30*5]|=(~*p++)&m; +} +*/ + +void xregparm(2,2,1) SmallDStr(int x,int y,char *s) { + while (*s) + SmallDChar(x,y,*s++),x++; +} +void xregparm(3,3,1) SmallDStrS(int x,int y,char *s,int w) { + SmallDChar(x-1,y,0); + while (*s) + SmallDCharS(x,y,*s++),x++,w--; + while (--w>0) + SmallDCharS(x,y,' '),x++; +} +void xregparm(3,3,1) SmallDStrC(int x,int y,char *s,int w) { + while (*s) { + if (--w<0) return; + SmallDChar(x,y,*s++),x++; + } + while (--w>0) + SmallDChar(x,y,' '),x++; +} +void xregparm(3,3,1) SmallDStrCS(int x,int y,char *s,int w) { + SmallDChar(x-1,y,0); + while (*s) { + if (--w<0) return; + SmallDCharS(x,y,*s++),x++; + } + while (--w>0) + SmallDCharS(x,y,' '),x++; +} +#ifdef FORCE_SMALL_FONT +#define VariableDStr SmallDStr +#define VariableDStrS SmallDStrS +#define VariableDStrC SmallDStrC +#define VariableDStrCS SmallDStrCS +#define VariableDChar SmallDChar +#define VariableDCharS SmallDCharS +#define DChar SmallDChar +#define DCharS SmallDCharS +#define DCharX SmallDCharX +#define DStr SmallDStr +#define DStrS SmallDStrS +#else +void xregparm(2,2,1) MediumDStr(int x,int y,char *s) { + while (*s) + MediumDChar(x,y,*s++),x++; +} +void xregparm(3,3,1) MediumDStrS(int x,int y,char *s,int w) { + MediumDChar(x-1,y,0); + while (*s) + MediumDCharS(x,y,*s++),x++,w--; + while (--w>0) + MediumDCharS(x,y,' '),x++; +} +void xregparm(3,3,1) MediumDStrC(int x,int y,char *s,int w) { + while (*s) { + if (--w<0) return; + MediumDChar(x,y,*s++),x++; + } + while (--w>0) + MediumDChar(x,y,' '),x++; +} +void xregparm(3,3,1) MediumDStrCS(int x,int y,char *s,int w) { + MediumDChar(x-1,y,0); + while (*s) { + if (--w<0) return; + MediumDCharS(x,y,*s++),x++; + } + while (--w>0) + MediumDCharS(x,y,' '),x++; +} +void xregparm(2,2,1) VariableDStr(int x,int y,char *s) { + if (small_font) + SmallDStr(x,y,s); + MediumDStr(x,y,s); +} +void xregparm(3,3,1) VariableDStrS(int x,int y,char *s,int w) { + if (small_font) + SmallDStrS(x,y,s,w); + MediumDStrS(x,y,s,w); +} +void xregparm(3,3,1) VariableDStrC(int x,int y,char *s,int w) { + if (small_font) + SmallDStrC(x,y,s,w); + MediumDStrC(x,y,s,w); +} +void xregparm(3,3,1) VariableDStrCS(int x,int y,char *s,int w) { + if (small_font) + SmallDStrCS(x,y,s,w); + MediumDStrCS(x,y,s,w); +} +#endif + +void ScrRectFill2(SCR_RECT *scr,int attr) { + int y=scr->xy.y0,n=scr->xy.y1-y; + int x0=scr->xy.x0,x1=scr->xy.x1; + do { + FastDrawHLine(Port,x0,x1,y,attr); y++; + } while (n--); +} +void DrawFrame(int x0,int y0,int x1,int y1) { + FastDrawHLine(Port,x0+1,x1-1,y0,A_NORMAL); + FastDrawHLine(Port,x0+1,x1-1,y1,A_NORMAL); + FastDrawLine(Port,x0,y0+1,x0,y1-1,A_NORMAL); + FastDrawLine(Port,x1,y0+1,x1,y1-1,A_NORMAL); +} + +#define B_MOVEAROUND 0 +#define B_CENTER 0x8000 +int disp_box(int x1,int x2,int height,int attr,WIN_RECT *win) { + WIN_RECT wbox; SCR_RECT box; + if (attr&B_ROUNDED) height+=2; + wbox.x0=virtual_to_physical(x1)-3; wbox.x1=virtual_to_physical(x2)+1; + if (ycur+6+height+4>=_89_92(100-8,128-8) || (attr&B_CENTER) || ycur>=_89_92((100-8)/2,(128-8)/2)) { + wbox.y0=ycur-height-4, wbox.y1=ycur-1; + if (wbox.y0<0 || (attr&B_CENTER)) + wbox.y0=_89_92((100-8)/2-2,(128-8)/2-2)-height/2,wbox.y1=wbox.y0+height+3; + } else + wbox.y0=ycur+6, wbox.y1=ycur+5+height+4; + box.xy.x0=wbox.x0; + box.xy.x1=wbox.x1; + box.xy.y0=wbox.y0; + box.xy.y1=wbox.y1; + ScrRectFill2(&box,A_REVERSE); + DrawClipRect(&wbox,ScrRect,A_NORMAL|attr); + if (win) *win=wbox; + return box.xy.y0+2; +} + +void dialog(char *title,int width,int height,int attr,WIN_RECT *w) { + WIN_RECT win; + int h=height,x0=(X-width)/2,x1=x0+width,y0; + if (title) h+=8; + x0 = physical_to_virtual(x0); + x1 = physical_to_virtual(x1-1)+1; + y0 = disp_box(x0,x1,h,attr,&win); + x0 = virtual_to_physical(x0); + x1 = virtual_to_physical(x1); + if (title) { + SmallDStr((X/4)/2-strlen(title)/2,y0,title); + FastDrawHLine(Port,x0-2,x1,y0+6,A_NORMAL); + y0+=8; + } + if (w) w->x0=x0,w->x1=x1,w->y0=y0,w->y1=y0+height; /* I doubt that w->y1 will ever be used, but... */ +} + +enum { + W_NORMAL=0, + W_NOKEY=0x10, + W_ALLOW_F1=0x10<<1, W_ALLOW_F2=0x10<<2, W_ALLOW_F3=0x10<<3, W_ALLOW_F4=0x10<<4, W_ALLOW_F5=0x10<<5, +}; +int SimpleDlg(char *title,char *text,int attr,int wattr); + +#define SDLG_BUF_SIZE 128 +extern char text_find[SDLG_BUF_SIZE],text_repl[SDLG_BUF_SIZE]; +extern int search_attr; +int SearchDlg(int rep); +int DoSearch(); +void FindDlg() { +/* while (!kbhit()) + dialog("Find text",100,40,B_ROUNDED,NULL), LCD_restore(Port); + ngetchx();*/ + SearchDlg(1); +} + +LCD_BUFFER *scr_stk[8],**scr_sptr=0; +#define NOT_MEMORY 2 +void PushScr() { + LCD_BUFFER *p=malloc(LCD_SIZE); + *scr_sptr++=p; + if (p) memcpy(p,Port,LCD_SIZE); +} +void PopScr() { + LCD_BUFFER *p=*--scr_sptr; + if (p) { + memcpy(Port,p,LCD_SIZE); + free(p); + } +} + +/*void TestDisp() { + void *PortSave=Port; + Port=LCD_MEM; + while (!kbhit()) { + int c='a'; + memset(Port,0,30*92); + while (c<='z') { + int y=90; + do { + int x=40; + while (x--) DChar(x,y,c); + } while ((y-=6)>=0); + c++; + } + } + Port=PortSave; +}*/ + +#ifdef _89 +long MenuBar[5*8]={ + 0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFE, + 0x80000000,0x80000000,0x80000000,0x80000000,0x80000001, + 0x90000000,0xB0000000,0xB0000000,0xA0000000,0xB8000001, + 0xB0000000,0x88000000,0x88000000,0xA8000000,0xA0000001, + 0x90000000,0x90000000,0x90000000,0xB8000000,0xB0000001, + 0x90000000,0xA0000000,0x88000000,0x88000000,0x88000001, + 0xB8000000,0xB8000000,0xB0000000,0x88000000,0xB0000001, + 0x80000000,0x80000000,0x80000000,0x80000000,0x80000001, +}; +#define NMENU 5 +#else +long MenuBar[8*8]={ + 0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFF,0x7FFFFFFE,0, + 0x80000000,0x80000000,0x80000000,0x80000000,0x80000000,0x80000000,0x80000001,0, + 0x90000000,0xB0000000,0xB0000000,0xB0000000,0xB0000000,0xA0000000,0xB8000001,0, + 0xB0000000,0x88000000,0x88000000,0x88000000,0x88000000,0xA8000000,0xA0000001,0, + 0x90000000,0x90000000,0x90000000,0x90000000,0x90000000,0xB8000000,0xB0000001,0, + 0x90000000,0xA0000000,0x88000000,0x88000000,0x88000000,0x88000000,0x88000001,0, + 0xB8000000,0xB8000000,0xB0000000,0xB0000000,0xB0000000,0x88000000,0xB0000001,0, + 0x80000000,0x80000000,0x80000000,0x80000000,0x80000000,0x80000000,0x80000001,0, +}; +//#error Adapt 'MenuBar' to the 92+ +#define NMENU 7 +#endif +void PutLine(void *src,int y) { + memcpy(Port+30*y,src,30); +} +char **MenuContents=0; +void DrawMenuBar() { + void *p=MenuBar; + int y; + for (y=Y-8;y 1 && tptr[pos-2]!=NEWLINE) pos--; + cur=pos; + while (cur 1 && tptr[pos-2]!=NEWLINE) pos--; + return pos; +} +char * __attribute__((__regparm__(1))) nonwhite(char *p) { + while (isspace(*p)) p++; + return p; +} +unsigned int down(unsigned int pos,int xd) { + char c,*p=tptr+pos; + int d=WIDTH,n=0; + while ((c=*p++)) { + if (--d<=0) return p-1-tptr; + if (c==NEWLINE) { + if (n || xd>d) return p-1-tptr; + p++; + n++; d=xd; + } + } + return p-1-tptr; +} +unsigned int up(unsigned int pos,int xd) { + char c,*p=tptr+pos; + int d=WIDTH-1,w,z; + while ((c=*--p),p>tptr) { + if (--d<=0 && p[-1]!=NEWLINE) return p-tptr; + if (c==NEWLINE) + goto loop2; + } + return 1; +loop2: + if (p==tptr+1) + return 1; + w=-1; z=0; + while ((c=*--p),p>tptr) { + w++; + if (c==NEWLINE) { + w--; + break; + } + } + if (p==tptr) w++; + while (w>=WIDTH-1) + w-=WIDTH-1, z+=WIDTH-1; + if (w>=xd-1) w=xd-1; + return w+z+(p==tptr?1:2+(p-tptr)); +} +/*void scroll(int d) { + +}*/ +int need_go_down() { + char c,*p=tptr+spos; + int x=1,y=2,d=curpos+1-spos; +#ifdef TITLEBAR + y=8; +#endif + if (is_nl) x=0; + while ((c=*p++)) { + if (!--d) return 0; + if (c==NEWLINE) { + x=0; if ((y+=6)>=YMAX) return 1; + } else if (++x>=WIDTH) { + x=1; + if ((y+=6)>=YMAX) return 1; + } + } + return --d; +} +unsigned int go_down() { + char c,*p=tptr+spos; + int x=1,y=0,d=curpos+1-spos; + if (is_nl) x=0; + while ((c=*p++)) { + if (!--d) return 0; + if (c==NEWLINE) { + x=0; if (++y>=(NLINES+1)/2) return p-1-tptr; + } else if (++x>=WIDTH) { + x=1; + if (++y>=(NLINES+1)/2) return p-1-tptr; + } + } +#ifndef NDEBUG + if (--d) msg="GO_DOWN"; +#endif + return 0; +} +void view_cursor() { + if (is_nl) spos++; + while (curpos =0) +int get_zone(unsigned int pos) { + int z=0; + char *lb=tptr+linebegin(pos),*nwlb=nonwhite(lb); +// char pline=(lb>tptr+1?lb[-2]:0); +// unsigned int accol[20],accoldeep=0; + if (*nwlb=='#') z|=CF_PREPROC; + if (nwlb==tptr+pos) z|=CF_DECL; + if (nwlb==lb) z|=CF_GLOBAL; + return z; +} +#ifdef TITLEBAR +char curFileName[8+1],curFileExt[4+1],curFileFullName[17+1]; +int numOpenFiles=0,curFileNum=0; +int CompUnderWay=0; +/* 89 title bar : + * [--------------------------------------] + * [GT-Dev - 12345678.text Compiling..] + * [GT-Dev - 12345678.prgm 10/12] + * [--------------------------------------] + */ +#define TBAR_HEIGHT 7 +void TBarDisp() { + char b[100]; + memset(Port,0,30*TBAR_HEIGHT); + sprintf(b,"GT-Dev - %s.%s",curFileName,curFileExt); + SmallDStr(1,1,b); + sprintf(b,"%d/%d",curFileNum+1,numOpenFiles); + if (CompUnderWay) sprintf(b,"Compiling"DOTS); + SmallDStr(_89_92(39,59)-strlen(b),1,b); + ScrRectFill2(&(SCR_RECT){{0,0,239,TBAR_HEIGHT-1}},A_XOR); + DrawPix(0,0,A_XOR); + DrawPix(0,TBAR_HEIGHT-1,A_XOR); + DrawPix(_89_92(159,239),0,A_XOR); + DrawPix(_89_92(159,239),TBAR_HEIGHT-1,A_XOR); +} +#endif +void display(int z) { + char c,*p=tptr+spos; + int x=1,y=2,d=curpos+1-spos; +#ifdef TITLEBAR + TBarDisp(); + y=TBAR_HEIGHT+1; +#endif + unsigned int j=spos-1; + int newline=is_nl; +#ifndef RELEASE + xcur=-1; +#endif + while ((c=*p++)) { + if (!--d) { xcur=x,ycur=y; + if (!z) FastDrawLine(Port,virtual_to_physical(x)-1,y,virtual_to_physical(x)-1,y+char_height-2,A_XOR) + /*FastDrawVLine(Port,virtual_to_physical(x)-1,y,y+4,A_XOR)*/; } + j++; + if (newline) { + VariableDChar(0,y,':'), newline=0; + continue; + } + if (c==NEWLINE) { + if (j>=sel1 && j >=1; + p=Port+(y*30+x); + n=6; while (n--) { + int i=30-x; + while (i--) *p++=0xFF; + p+=x; + } + } + x=1; if ((y+=6)>=YMAX) return; + newline=1; + } else { + if ((j>=sel1 && j =WIDTH) { + x=1; + if ((y+=6)>=YMAX) return; + } + } + } + if (!--d) { xcur=x,ycur=y; if (!z) FastDrawLine(Port,virtual_to_physical(x)-1,y,virtual_to_physical(x)-1,y+char_height-2,A_XOR); } +} +int last_act=0; +void sel_del() { + int n=sel2-sel1; + if (!n) { + selpos=0; + return; + } + curpos=sel1; + view_cursor(); /* otherwise spos might be in the middle of a line */ + memmove(tptr+sel1,tptr+sel2,size+1+1-sel2); + size-=n; curpos=cpos=sel1; selpos=0; +} +void insert(int n) { + size+=n; + if (size+2+1+1>hsize) + HeapUnlock(hd), HeapRealloc(hd,2+(hsize=size+100+2+1+1)), tptr=4+HLock(hd); + memmove(tptr+cpos+n,tptr+cpos,size-n+1+1-cpos); + cpos+=n; + last_act=1; +} +void text_enclose(char *l,char *r) { + int n=sel2-sel1; + int a=strlen(l),b=strlen(r); + unsigned int cps; + if (!n) insert(a+b),cpos-=b,memcpy(tptr+(cpos-a),l,a),memcpy(tptr+cpos,r,b); + else { + cps=cpos; + cpos=sel1; + insert(a); sel2+=a; + memcpy(tptr+sel1,l,a); sel1+=a; + cpos=sel2; + insert(b); + sel2-=b; + memcpy(tptr+sel2+1,r,b); + cpos=cps+a; + selpos+=a; + } +} +#define isidch(x) ({char __x=(x); \ + (__x>='0' && __x<='9') || (__x>='A' && __x<='Z') || (__x>='a' && __x<='z') || __x=='_' \ + || __x=='$' || __x=='#';}) +#define isnum(x) ({char __x=(x); __x>='0' && __x<='9';}) +int chk_curword(char *curword,unsigned int pos,int store_cwpos) { + char w[MAX_CURWORD+2],*p=tptr+pos; + int res; + if (!sel1) { + while (isidch(*--p) && p>tptr); + p++; + if (p==tptr || p[-1]==NEWLINE) p++; /* since we may have the sequence : #NEWLINE "C" ... */ + while (isnum(*p)) p++; + if (store_cwpos) { + cwpos=p-tptr; + if (cwpos>pos) goto invalid; /* may appear with numbers, for example : 123|456 */ + } /* (note : if store_cwpos==0, then it isn't a number :] ) */ + memcpy(w,p,MAX_CURWORD+2); + p=w; + p[MAX_CURWORD+1]=0; + while (isidch(*p++)); + p[-1]=0; + if (p==&w[MAX_CURWORD+2]) goto invalid; + res=strcmp(curword,w); + if (res) memcpy(curword,w,MAX_CURWORD+1); + return res; + } +invalid: + if (store_cwpos) cwpos=0; + res=curword[0]; + curword[0]=0; + return res; +} + +FILE *pchfile[MAX_OPEN_PCH]; +char *pchdata[MAX_OPEN_PCH]; +#undef pchhead +#define pchhead ((PCH_HEAD **)pchdata) +int pchnum = 0; +int add_pch(char *name) { + if (pchnum>=MAX_OPEN_PCH) + return 0; + char b[30]; + sprintf(b,"zheader\\%s",name); + if (!(pchfile[pchnum] = fopen(b, "rb"))) return 0; +#ifdef PC + pchdata[pchnum] = malloc(MAX_PCHDATA_SIZE); + fread(pchdata[pchnum],1,MAX_PCHDATA_SIZE,pchfile[pchnum]); + if (((PCH_HEAD *)pchdata[pchnum])->magic!= + ((long)'P'<<0)+((long)'C'<<8)+((long)'H'<<16)) + return 0; +#else + if (((PCH_HEAD *)(pchdata[pchnum] = *(char **)(pchfile[pchnum])))->magic!= + ((long)'P'<<24)+((long)'C'<<16)+((long)'H'<<8)) { + fclose(pchfile[pchnum]); + return 0; + } +#endif + pchnum++; + return 1; +} +void add_all_pch() { + /* first add standard headers: if MAX_CATALOG_ENTRIES is reached then we still have those */ + add_pch("keywords"); + add_pch("stdhead"); + SYM_ENTRY *se = SymFindFirst($(zheader), FO_SINGLE_FOLDER); + while (se) + add_pch(se->name), se = SymFindNext(); +} +void close_pch(void) { + while (pchnum) { + pchnum--; +#ifdef PC + free(pchdata[pchnum]); +#endif + fclose(pchfile[pchnum]); + } +} +#define MAX_MATCH 16 +int nmatch=0; +char *match[MAX_MATCH]={0}; +//char *str="SSORT"; +void ssort(char **match,int n) { + char **zsp=&match[n-1]; + while (zsp>match) { + #define cs (*csp) + char **csp=match,*ms=cs,**msp=csp; + /* ms=max string */ + /* cs=current string */ + do { + csp++; + if (strcmp(ms,cs)<0) msp=csp,ms=cs; + } while (csp dic_off; + if (*proto) + return sUnpack(proto,sUnpackBuf,p0); + if (args) { + char *d=sUnpackBuf; + *d++='_'; + *d++='('; + p=args; + while (*p) { + while ((*d++=*p++)); + d--; + } + strcpy(d,") = \xA0\x01"); + } else if (*defn) { + char *d=sUnpackBuf; + if (flags&PCHID_PACKED) sUnpack(defn,d,p0); + else strcpy(d,defn); + } else return ""; + return sUnpackBuf; + } +#else +/*char *PchRCB_editMsg(char *name,char *args,char *defn,char *proto,char *param) {*/ +PU_HANDLER (editMsg) { + char *d=sUnpackBuf; + if (*proto) { + strcpy(d,proto); + return d; + } + if (*args) + sprintf(d,"_%s;",args); + else if (*defn) { + if (!strncmp(defn,"_rom_call(",10)) { + char *s=defn+10; + d=write_until(d,&s,','); + if (d[-1]!='*') *d++=' '; + *d++='_'; + d=write_until(d,&s,','); + *d++=';'; + *d=0; + } else + strcpy(d,defn); + } else + return ""; + return sUnpackBuf; +} +#endif +SCROLL ac_s={0,0,0,0}; +//char *str="PCH_SEARCH"; +#define PUSH(x) asm("move.w %0,-(%%sp)"::"r" ((int)x)) +#define POP(x) asm("move.w (%%sp)+,%d0":"=d" (z)) +/* --- CAUTION : */ +/* USAGE OF PUSH AND POP MAKES IT VERY COMPILER-DEPENDENT */ +/* (for example, stack frames are necessary) */ +char *pch_search(char *curword,int ac_test,int MM,char **match) { /* match may be NULL if ac_test is 0 */ + /* >>> !!! the routine does NOT reset nmatch !!! <<< */ + int n=pchnum,nm=MM; char **mp=match; + #define search ac_test + /*int search; + search=(strlen(curword)<3)?0:ac_test; + if (ac_test) nmatch=0;*/ + while (n--) { + unsigned char *p0=pchdata[n],*p,c,*q; int z=PCH_HEAD_SIZE; + PUSH(0); + do { + p=p0+z; q=curword; + while ((c=*q++) && c==*p++); + if (!c) { + if (!*p) { + /* p+=1+2*3; + while (*p++); + return sUnpack(p,sUnpackBuf,p0+((PCH_HEAD *)p0)->dic_off);*/ +#ifdef NO_PCH_UTIL + return pch_help(p0+z,p0); +#else + return PchUnpack(editMsg,p0+z,p0); +#endif + } else if (search) { + *mp++=p0+z; + if (!--nm) search=0; + else { + while (*p++); + z=(p[2]<<8)|p[3]; + if (z) PUSH(z); + goto cont; + } + } else p++; + } + if ((c=p[-1])) while (*p++); + if (c =6?6:nmatch)),B_NORMAL,NULL); + ac_s.n=nmatch; ac_s.h=h; + ScrollUpd(&ac_s); + cs=&match[n=ac_s.scr]; + while (h--) { + if (!has_sel || n!=ac_s.sel) DStr(5,y,*cs++); + else DChar(3,y,0),DCharS(4,y,' '),DStrS(5,y,*cs++,35+1-5); + y+=6; n++; + } + if (ScrollHasUpArrow(&ac_s)) DCharX(4,y-6*6,UPARR); + if (ScrollHasDnArrow(&ac_s)) DCharX(4,y-6*1,DNARR); +} +void ac_do() { + char *s; int l=strlen(curword),n; + /* it's reasonable to assume that 'ac_disp' has already been called :) */ + ScrollUpd(&ac_s); + s=match[ac_s.sel]; + cpos=cwpos+l; selpos=0; + insert(n=strlen(s)-l); + memcpy(&tptr[cpos-n],s+l,n); +} + +#define SEQ(x) x "\0" +char charmap[]= + SEQ("'") + SEQ("_") + SEQ(";") + SEQ(":") + SEQ("\"") + SEQ("\\") + SEQ("<") + SEQ(">") + SEQ("!") + SEQ("&") + SEQ("@") + SEQ("<=") + SEQ(">=") + SEQ("!=") + SEQ(" // ") + SEQ("#") + SEQ(" ") + SEQ("int ") + SEQ("long ") + SEQ("char ") + SEQ("unsigned ") + SEQ("void ") + SEQ(""); +#define KEY_UMINUS 173 +#define KEY_STO 22 +/*#define KEY_CONVERT 18*/ +#define KEY_HOME 0x115 +#define KEY_CATALOG 0x116 +#define KEY_APPS 0x109 +#define KEY_2ND 4096 +#define KEY_DMD 16384 +#define KEY_SHF 8192 +int key89[]={ +#define pair(k) 337+k,340+k + pair(0),pair(KEY_2ND),pair(KEY_DMD),pair(KEY_SHF),pair(KEY_SHF+KEY_2ND),pair(KEY_SHF+KEY_DMD), +#undef pair +#define pair(k) 338+k,344+k + pair(0),pair(KEY_2ND),pair(KEY_SHF),pair(KEY_SHF+KEY_2ND), +#undef pair + KEY_BACKSPACE,16384+KEY_BACKSPACE, /* BACKSPACE/DELETE */ + KEY_DMD+4096,KEY_DMD+8192,KEY_DMD+KEY_ESC, /* CUT/COPY/PASTE */ + KEY_DMD, /* for DIAMOND+# (kbdprgm#) */ + KEY_CATALOG, /* CATALOG */ + KEY_F8,KEY_DMD+KEY_F3, /* find/replace */ + KEY_HOME, /* HOME */ + KEY_2ND+'+', /* CHAR */ + #ifdef EVHOOK + // Forbidden keys + KEY_2ND+'6',KEY_2ND+'3',KEY_2ND+'-',KEY_2ND+KEY_ENTER, /* MEM/UNITS/VAR-LINK/ENTRY */ + KEY_2ND+KEY_HOME,KEY_DMD+'|', /* CUSTOM/HELPKEYS */ + KEY_DMD+',',KEY_DMD+KEY_UMINUS, /* SYSDATA/HOMEDATA */ + 0, + #endif + // Special keys + KEY_2ND+'=',KEY_DMD+KEY_MODE,KEY_2ND+'9', + KEY_2ND+'4',KEY_2ND+'1',KEY_2ND+'2',KEY_2ND+'0', + KEY_2ND+'.',KEY_DMD+'/',KEY_DMD+'*',KEY_DMD+KEY_STO, + KEY_DMD+'0',KEY_DMD+'.',KEY_DMD+'=',KEY_DMD+')', + KEY_DMD+',',KEY_UMINUS, + 18/*KEY_2ND+KEY_MODE*/,151/*KEY_2ND+KEY_CATALOG*/,KEY_2ND+KEY_APPS, /* int/long/char */ + KEY_DMD+KEY_CATALOG,KEY_DMD+KEY_APPS, /* unsigned/void */ + 0 +}; +#undef KEY_DMD +#undef KEY_SHF +#define KEY_DMD 8192 +#define KEY_SHF 16384 +#ifdef PEDROM +#define KA_MOD 32 +#else +#define KA_MOD 0 +#endif +int key92[]={ +#define pair(k) 338+k,344+k + pair(0),pair(KEY_2ND),pair(KEY_DMD),pair(KEY_SHF),pair(KEY_SHF+KEY_2ND),pair(KEY_SHF+KEY_DMD), +#undef pair +#define pair(k) 337+k,340+k + pair(0),pair(KEY_2ND),pair(KEY_SHF),pair(KEY_SHF+KEY_2ND), +#undef pair + KEY_BACKSPACE,8192+KEY_BACKSPACE, /* BACKSPACE/DELETE */ + KEY_DMD+KA_MOD+'X',KEY_DMD+KA_MOD+'C',KEY_DMD+KA_MOD+'V', /* CUT/COPY/PASTE */ + KEY_DMD, /* DIAMOND+# (kbdprgm#) */ + KEY_2ND+'2', /* CATALOG */ + KEY_2ND+KEY_F3,KEY_DMD+KEY_F3, /* find/replace */ + KEY_DMD+KA_MOD+'Q', /* HOME */ + KEY_2ND+'+', /* CHAR */ + #ifdef EVHOOK + // Forbidden keys + #error missing for 92 + #endif + // Special keys + KEY_2ND+KA_MOD+'B',KEY_2ND+KA_MOD+'P',KEY_2ND+KA_MOD+'M', + KEY_2ND+136/*key_theta*/,KEY_2ND+KA_MOD+'L',KEY_2ND+'=',KEY_2ND+'0', + KEY_2ND+'.',KEY_2ND+KA_MOD+'H',KEY_2ND+KA_MOD+'W',KEY_2ND+KA_MOD+'R', + KEY_DMD+'0',KEY_DMD+'.',KEY_DMD+'=',KEY_2ND+KA_MOD+'X', + KEY_2ND+KA_MOD+'T',1, + 1,1,1, // -> disable + 1,1, // -> disable +// 18/*KEY_2ND+KEY_MODE*/,151/*KEY_2ND+KEY_CATALOG*/,KEY_2ND+KEY_APPS, /* int/long/char */ +// KEY_DMD+KEY_CATALOG,KEY_DMD+KEY_APPS, /* unsigned/void */ + 0 +}; +#undef KEY_DMD +#undef KEY_SHF +#define KEY_DMD q89(16384,8192) +#define KEY_SHF q89(8192,16384) + + +void DrawStatus() { + int x=64; char *p=icons; + if (MenuContents && !(ST_flagsL & (x-1))) { DrawMenuBar(); return; } + char *q0=Port+_89_92((100-7)*30,(128-7)*30),*q; + memset(q0-30,0xFF,30); + memset(q0,0,30*7); + DStr(2,LCD_HEIGHT-6,msg); + while ((x>>=1)) { + if (ST_flagsL & x) { + int n=7; + q=q0; + while (n--) *q=*p++, q+=30; + } else + p+=7; + } +} +char msgBuf[58+1]; /* max string length on 92/V200 is 240/4-2=58 */ +int *get_keylist() { + return _89_92(key89,key92); +} +char *Catalog(); +char CharDlg(); +int cKID=200,cBKD=35; +void Off() { + off(); + OSInitKeyInitDelay(cKID); + OSInitBetweenKeyDelay(cBKD); +} +char **catmatch=0; int catnum=0; +void FreeMem() { + if (catmatch) free(catmatch),catmatch=0; +} + +int ac_on=0,ac_disp=0; diff --git a/ti68k/ide/editor.h b/ti68k/ide/editor.h new file mode 100644 index 0000000..b45acd9 --- /dev/null +++ b/ti68k/ide/editor.h @@ -0,0 +1,227 @@ +// Text Editor +#include "Workspace.h" +int onopen_gotoline=-1; +char *onopen_gotofile=NULL; +//void Edit(SYM_STR sym_text,char *text_name) { +void Edit(char *text_path) { + if (!(Port=malloc(LCD_SIZE))) + return; + PortSet(Port,239,127); + onopen_gotoline=-1; + +editor_reopen: + if (onopen_gotofile!=NULL) + text_path = onopen_gotofile, onopen_gotofile = NULL; + char sym_buf[1+8+1+8+1]; + *sym_buf = 0; + strncpy(sym_buf+1,text_path,sizeof(sym_buf)-1); + SYM_STR sym_text = sym_buf+1; + while (*sym_text) sym_text++; + char *text_name = strrchr(text_path,'\\'); + if (!text_name) + text_name = text_path; + +editor_reopen_samefile: { + int key,k,n,z=0; + void *ptr; int *kp; + unsigned int ST_f; + #ifdef HD2 + #define hdx hd2 + HANDLE hd2; + #else + #define hdx hd + #endif + int CU_state,KID,BKD,EDH_proc; + HSym hs; int arch=0; + if (!(hs=SymFind(sym_text)).folder) + goto editor_quit; + hdx=DerefSym(hs)->handle; + NLINES=(LCD_HEIGHT-10)/6; + YMAX=2+6*NLINES; +#ifdef TITLEBAR + NLINES--; +#endif + hs=SymFind(sym_text); // because malloc may cause garbage collection (shouldn't change HSym, but...) + if (DerefSym(hs)->flags.bits.archived) + arch=1 + #ifndef HD2 + , EM_moveSymFromExtMem(sym_text,HS_NULL), hdx=DerefSym(hs)->handle + #endif + ; + #ifdef HD2 + hsize=*(unsigned int *)HeapDeref(hdx); + hd=HeapAlloc(2+hsize); + if (!hd) return; + ptr=HLock(hd); + memcpy(ptr,HeapDeref(hdx),2+hsize); + #else + ptr=HLock(hd); + #endif + tptr=ptr+4; + spos=0; selpos=0; sel1=0; sel2=0; + curpos=cpos=((unsigned int *)ptr)[1]; + if (onopen_gotoline>=0) { + cpos=1; + while (--onopen_gotoline) + while (tptr[cpos]) { + if (tptr[cpos]==NEWLINE) { + cpos+=2; + break; + } + cpos++; + } + //cpos=down(cpos,0); + curpos=cpos; + onopen_gotoline=-1; + } +/* tptr=" test-123123123123123123123123123123123123123\n \n \n OK :)" + "\n \n \n end\n \n \n of\n \n \n file" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" + "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";*/ +/* tptr=" test-123123123123123123123123123123123123123\n \n \n \n \n OK :)" + "\n \n \n \n \n end\n \n \n \n \n of\n \n \n \n \n file\0\0\0\0\0\0\0";*/ + size=strlen(tptr); hsize=*((unsigned int *)ptr); + if (!cpos || cpos>size) + cpos=1; + InitSearch(); +// is_nl=1; + CU_state=CU_start(); + scr_sptr=scr_stk; +#ifndef PEDROM + KID=OSInitKeyInitDelay(cKID); + BKD=OSInitBetweenKeyDelay(cBKD); +#endif + view_cursor(); + msg="Welcome to GTC IDE !"; + curword[0]=0; + pchnum=0; + last_act=0; ac_on=0; ac_disp=0; + add_all_pch(); + //add_pch("std"); + //add_pch("stdhead"); + //add_pch("gen"); + //add_pch("extgraph"); + //add_pch("graphx"); + //add_pch("keywords"); + OSTimerRestart(APD_TIMER); + { +#if 0 + char *p=(char *)sym_text; + while (*--p); + strcpy(curFileFullName,p+1); +#else + strcpy(curFileFullName,text_path); +#endif + } + strcpy(curFileName,text_name); + strcpy(curFileExt,GetFTString(hdx)); + strtolower(curFileExt); +// WspNew(); +// WspNew(); + editor_exit_requested=0; // as the init in the loop is not sufficient... + do { + unsigned int par1s=par1; + memset(Port,0,LCD_SIZE); + par1=0; par2=0; + if (!sel1) { + unsigned int pos=cpos; + int deep=0; + while (pos>1 && tptr[pos-2]!=NEWLINE) { + pos--; + if (tptr[pos]==')') deep--; + if (tptr[pos]=='(' && (++deep)>0) { par1=pos; break; } + } + if (par1) { + while (tptr[pos] && tptr[pos]!=NEWLINE) { + pos++; + if (tptr[pos]=='(') deep++; + if (tptr[pos]==')' && (--deep)<=0) { par2=pos; break; } + } + if (!par2) par1=0; + } + } + if (chk_curword(curword,cpos,1) || (!curword[0] && par1!=par1s)) { +// char *tp; + nmatch=0; + if (curword[0] && (msg=pch_search(curword,strlen(curword)>=2,MAX_MATCH,match))) + msg=msg; + else if (chk_curword(parword,par1,0) && (msg=pch_search(parword,0,0,NULL))) msg=msg; + else msg=0; + if (msg) { msg=memcpy(msgBuf,msg,58); msg[58]=0; } + ac_disp=nmatch?last_act:0; + ac_on=0; + } + display(z); + if (ac_disp) ac_display(ac_on); +#ifndef RELEASE + if (xcur<0) msg="Cursor not encountered", xcur=1; + if (!curpos || tptr[curpos-1]==NEWLINE) msg="Invalid curpos"; +#endif + DrawStatus(); + LCD_restore(Port); + in_loop: + ST_f=ST_flagsL; + while (!(key=kbhit()) && !OSTimerExpired(CURSOR_TIMER) + && !OSTimerExpired(APD_TIMER) && ST_f==ST_flagsL) + idle(); + if (ST_f!=ST_flagsL) { + DrawStatus(); + LCD_restore(Port); + goto in_loop; + } else if (OSTimerExpired(APD_TIMER)) { + Off(); + OSTimerRestart(APD_TIMER); + continue; + } + OSTimerRestart(CURSOR_TIMER); + z=~z; + if (!key) continue; + OSTimerRestart(APD_TIMER); + last_act=0; + key=ngetchx(); + editor_exit_requested=0; + KeyProcess(key,TM_MULTILINE); + z=0; + } while (key!=KEY_ESC && !editor_exit_requested); + close_pch(); +#ifndef PEDROM + OSInitKeyInitDelay(KID); + OSInitBetweenKeyDelay(BKD); +#endif + if (!CU_state) CU_stop(); + ((unsigned int *)tptr)[-1]=cpos; + ((unsigned int *)tptr)[-2]=size+2+1+1; + FreeMem(); + #ifdef HD2 + if (memcmp(tptr,2+2+HeapDeref(hdx),size+1+1)) { + SimpleDlg(NULL,"\n Saving file"DOTS" \n",B_CENTER,W_NOKEY); + LCD_restore(Port); + hs=SymFind(sym_text); + if (arch) + EM_moveSymFromExtMem(sym_text,HS_NULL), hdx=DerefSym(hs)->handle; + HeapFree(hdx); + HeapUnlock(hd); + HeapRealloc(hd,size+2+2+1+1); + hs=SymFind(sym_text); + DerefSym(hs)->handle=hd; + if (arch) + if (!EM_moveSymToExtMem(sym_text,HS_NULL)) + ST_helpMsg("!!! MEMORY !!!"),ngetchx(); + } else HeapUnlock(hd), HeapFree(hd); + #else + HeapUnlock(hd); + HeapRealloc(hd,size+2+2+1+1); + if (arch) + EM_moveSymToExtMem(sym_text,HS_NULL); + #endif + if (editor_exit_requested==EDEX_COMPILE) { + SimpleDlg(NULL,"\n Compiling project"DOTS" \n",B_CENTER,W_NOKEY); + LCD_restore(Port); + Compile(curFileFullName,PLUGIN_GTC); + goto editor_reopen; + } + } +editor_quit: + PortRestore(); + free(Port); +} diff --git a/ti68k/ide/editui.h b/ti68k/ide/editui.h new file mode 100644 index 0000000..6063722 --- /dev/null +++ b/ti68k/ide/editui.h @@ -0,0 +1,551 @@ +// Text editing User Interface routines + +/* Common routines */ +int repeated=0; // was the last key repeated? +int WaitLoop(int *blink) { + int key=0; // this is necessary when blinking + unsigned int ST_f; + DrawStatus(); + LCD_restore(Port); + in_loop: + ST_f=ST_flagsL; + while (OSdequeue(&key,kbdq) && (!blink || !OSTimerExpired(CURSOR_TIMER)) + && !OSTimerExpired(APD_TIMER) && ST_f==ST_flagsL) + idle(); + if (!key) { // to avoid a potential race condition that would 'forget' that keypress + if (ST_f!=ST_flagsL) { + DrawStatus(); + LCD_restore(Port); + goto in_loop; + } else if (OSTimerExpired(APD_TIMER)) { + Off(); + OSTimerRestart(APD_TIMER); + goto in_loop; + } + } + OSTimerRestart(CURSOR_TIMER); + if (blink) *blink=~(*blink); +#ifndef DONT_USE_KBDQ + if (key) OSTimerRestart(APD_TIMER); + repeated=key&0x0800; + return key&0xF7FF; +#else + if (!key) return 0; + OSTimerRestart(APD_TIMER); + return ngetchx(); +#endif +} +typedef struct { + char *buf; + int sz; + int x0,y,w; + WIN_RECT win; + SCROLL scr; +} EDIT_LINE; +void newEditLine(EDIT_LINE *e,char *buf,int sz,int x0,int x1,int y) { + int w=x1-x0; + e->buf=buf; buf[0]=0; e->sz=sz; + e->x0=x0; e->y=y; e->w=w; + e->win.x0=virtual_to_physical(x0)-2; + e->win.x1=virtual_to_physical(x1)+1; + e->win.y0=y-2; + e->win.y1=y+char_height+2; + e->scr.n=1; e->scr.h=0; + ScrollInit(&e->scr); +} +int insEditLine(EDIT_LINE *e,int n) { + if (e->scr.n+n<=e->sz) { + memmove(e->buf+e->scr.sel+n,e->buf+e->scr.sel,e->scr.n-e->scr.sel); + e->scr.n+=n; + e->scr.sel+=n; + return 1; + } + return 0; +} +#define getEditLinePos(e) ((e)->buf+(e)->scr.sel) +int delEditLine(EDIT_LINE *e,int n) { + if (e->scr.sel>=n) { + e->scr.n-=n; + e->scr.sel-=n; + memmove(e->buf+e->scr.sel,e->buf+e->scr.sel+n,e->scr.n-e->scr.sel); + return 1; + } + return 0; +} +void updEditLine(EDIT_LINE *e) { /* to be called when buffer content changes */ + int l=strlen(e->buf); + e->scr.n=l+1; + if (l>e->w) l=e->w; + e->scr.h=l+1; +} +void DrawVLine(void *p,int x,int y1,int y2,int a) { + FastDrawLine(p,x,y1,x,y2,a); +} +void drawEditLine(EDIT_LINE *e,int inactive,int blink) { +// asm("0:jbra 0b"); + updEditLine(e); + ScrollUpdNoWrapDots(&e->scr); + VariableDStrC(e->x0,e->y,e->buf+e->scr.scr,e->w); + if (inactive) return; + DrawClipRect(&e->win,ScrRect,A_NORMAL); + if (!blink) DrawVLine(Port,((e->x0-e->scr.scr+e->scr.sel)<<2)-1,e->y,e->y+char_height-2,A_XOR); +} +void drawCheckBox(char *s,int v,int f,int x,int y,int inactive) { + if (!inactive) VariableDStr(x,y,"[ ]"); + VariableDChar(x+virtual_char_width,y,(v&f)?3:2); + VariableDStr(x+3*virtual_char_width,y,s); +} + +typedef long DLG_ICON[8]; +DLG_ICON DlgIcons[4]={ + {0x03000480,0x08400860,0x13201330,0x23102318,0x4308430C,0x80048306,0x8306400E,0x3FFC1FF8}, + {0x07801FE0,0x3FF077B8,0x631CF03C,0xF87EF87E,0xF03E631E,0x77BC3FFC,0x1FF80FF0,0x03C00000}, + {0x0FC03030,0x4308430C,0x80048706,0x83068306,0x430E478C,0x301C1E38,0x073000B0,0x00700030}, + {0x0FC03030,0x47884CCC,0x8CC48186,0x83068006,0x430E430C,0x301C1E38,0x073000B0,0x00700030}, +}; +enum { ICO_WARN=0x8, ICO_ERROR=0x9, ICO_INFO=0xA, ICO_QUEST=0xB, ICO_MASK=0xF, ICO_RMASK=0x7 }; + +void DrawText(char *p,int x,int y,int w,int h0,int hM,int *wp,int *hp,int draw) { + /* NB: x&y only needed in draw */ + char c,*word=p; int cx=x,cy=y-h0,yM=y+hM; + if (cy=yM) return; else if (cy==y) draw=-draw; } +// else if (c==' ') + else { + if (draw>0) DChar(cx,cy,c); + cx++; if (!draw && *wp =w) { cx=x,cy+=6,(*hp)+=6; if (cy>=yM) return; else if (cy==y) draw=-draw; } + } + } +} +void dialog(char *title,int width,int height,int attr,WIN_RECT *w); +#define MAX_TEXT_LINENUM 0x1000 +#define MAXH 10 +asm("identity: rts"); +int __attribute__((regparm)) identity(int x); +int SimpleDlg(char *title,char *text,int attr,int wattr) { + int dummy1,dummy2; WIN_RECT win; + int w=116/4,h=6,rh; + int h0=0,xsh=0,key; + if (wattr&ICO_MASK) w-=5; + DrawText(text,0,0,w,0,MAX_TEXT_LINENUM,&w,&h,0); + rh=h; + if (h>MAXH*6) h=MAXH*6,xsh=2; + if (wattr&ICO_MASK) xsh+=5; + if (!(wattr&W_NOKEY)) PushScr(); + while (1) { + dialog(title,(w+xsh)<<2,h,attr|B_ROUNDED,&win); + DrawText(text,(win.x0>>2)+xsh,win.y0,w,h0,h,&dummy1,&dummy2,1); + if (wattr&ICO_MASK) { + // 'identity 'fixes TIGCC bug :p + Sprite16(((win.x0>>2)+xsh-5)<<2,win.y0,16,(short *)(DlgIcons[identity(wattr&ICO_RMASK)]),Port,A_OR); + } + if (h0) DChar(win.x0>>2,win.y0,UPARR); + if (h0+MAXH*6 >2,win.y0+(MAXH-1)*6,DNARR); + if (wattr&W_NOKEY) return 0; + key=WaitLoop(NULL); + if (key==KEY_UP && h0) h0-=6; + else if (key==KEY_DOWN && h0+MAXH*6 =KEY_F1 && key<=KEY_F5 && (wattr&(0x10<<(key-KEY_F0)))) return key-KEY_F0; + } +} +int YesNoDlg(char *title,char *text) { + char ntext[300]; + strcpy(ntext,text); + strcat(ntext,"\n\n [ENTER]=Yes\n [ESC] =No"); + return SimpleDlg(title,ntext,B_CENTER,W_NORMAL|ICO_QUEST); +} +#ifdef NEED_DEBUG_MSG +void debug_msg(char *s) { + char b[200]; + sprintf(b,"\n %s \n",s); + SimpleDlg("Debug",b,B_CENTER,W_NORMAL|ICO_INFO); +} +#endif + + +/* CHAR LIST */ +char CharDlg() { + static int sel=32; + while (1) { + int scr=(sel>=128); + int c=scr?128:0,maxc=c+128; int y,key; WIN_RECT w; + char title[]="Char list - Page x"; + title[sizeof("Char list - Page x")-2]='1'+scr; + dialog(title,(16+1)*8,6*8/* =48 */,B_CENTER|B_NORMAL,&w); + y=w.y0; + DChar(w.x0>>2,y+(scr?0:6*(8-1)),(scr?UPARR:DNARR)); + while (c >2)+3,n=16; + while (n--) { + if (c>=16) { + if (c==sel) + DCharS(x,y,c),DChar(x-1,y,0); + else DChar(x,y,c); + } + c++,x+=2; + } + y+=6; + } + if (!(key=WaitLoop(NULL))) continue; + if (key==KEY_ESC) break; + else if (key==KEY_LEFT) sel--; + else if (key==KEY_RIGHT) sel++; + else if (key==KEY_UP) sel-=16; + else if (key==KEY_DOWN) sel+=16; + else if (key==KEY_ENTER) + return sel; + if (sel<16) sel+=256-16; + if (sel>=256) sel-=256-16; + } + return 0; +} + + +/* CATALOG */ +/*int __attribute__((__regparm__(2))) cat_ins(char *p,char **match,int n) { + char *s1,*s2,c; + int a=0,b=n-1,m; + while (a<=b) { + m=(a+b)>>1; + s1=p; + s2=match[m]; + do { + if (!(c=*s2++) && !*s1) + return n; + } while (*s1++==c); + if (s1[-1] >1; + s1=p; + s2=mp[m]; +/* asm volatile( + "comp_loop:" + "move.b (%1)+,%%d0;" + "beq.s check_dup;" + "check_dup_false:" + "move.b (%2)+,%%d1;" + "eor.b %%d1,%%d0;" + "and.b %5,%%d0;" + "beq.s comp_loop;" + "bpl.s change_a;" + "change_b:" + "subq.w #1,%6;" + "move.w %6,%4;" + "bra ok_comp;" + "check_dup:" + "tst.b (%2);" + "bne check_dup_false;" + "bra cont_lbl;" + "change_a:" + "subq.w #1,%6;" + "move.w %6,%3;" + "ok_comp:" + : "+&a" (s1),"+&a" (s2), "+g" (a), "+g" (b) + : "d" ((char)0xDF), "d" (m) + : "d0","d1");*/ + do { + if (!(c=*s2++) && !*s1) { + if (!(c=strcmp(mp[m],p))) + goto cont; + c+=OR_VAL; // very important to be '+' !!! + break; + } + c|=OR_VAL; + } while ((*s1++|OR_VAL)==c); + if ((s1[-1]|OR_VAL) =0 + dual_memmove4_plus4((long *)mp,(long *)&mdata[b],nm-b); + *mp=p; mdata[b]=p0; + if (++nm>=MM) return nm-1; + } +/* if (*p && (nm=cat_ins(p,match,nm))>=MM) + return 0;*/ +// asm volatile("cont_lbl: ziorjieog"); + cont: + while (*p++); + z=(p[2]<<8)|p[3]; + if (z) PUSH(z); + z=(*p++)<<8; z+=*p; + if (!z) POP(z); + } while (z); + } + return nm-1; +} + +/*int cat_prep(int MM,char **match) { + int nm_old=nmatch,n; + pch_search("",1,MM,match); + n=nmatch; + nmatch=nm_old; + return n; +}*/ +void cat_list(SCROLL *s,char **match,int x,int w,int y) { + int i,h; char **cs; + ScrollUpd(s); + cs=&match[i=s->scr]; + h=s->h; + while (h--) { + if (i!=s->sel) DStr(x,y,*cs++); + else DStrS(x,y,*cs++,w); + y+=6; i++; + } +} +#define SEARCH_FUNC(name,TYPE,comp,conv) void cat_##name##_search(SCROLL *s,char **match,TYPE c) { \ + char **p=&match[s->sel]; int sel=s->sel; \ + c=conv(c); \ + if (comp(c,*p)<0) p=match,sel=0; \ + while (comp(c,*p)>0) p++,sel++; \ + if (sel>=s->n) sel=s->n-1; \ + if (s->sel!=sel) s->scr=s->n-s->h/* (max value for s->scr) */,s->sel=sel; \ +} +#define toindiff(x) ((x)|0x20) +int strcmpindiff(char *a,char *b) { + char c; + do { + c=*a++; + if (toindiff(c)-toindiff(*b++)) + return toindiff(c)-toindiff(b[-1]); + } while (c); + return 0; +} +#define letter_comp(ch,s) ((ch)-toindiff(*(s))) +SEARCH_FUNC(letter,char,letter_comp,toindiff) +#define identity(x) (x) +SEARCH_FUNC(str,char *,strcmpindiff,identity) + +//char str[]="CATALOG"; +int flags(char *p) { + while (*p++); + return ((char *)p)[2*3-2]<<8; +} +#ifdef NO_PCH_UTIL + //char pchUnpackBuf[500]; + char *pch_unpack(char *p,char *p0) { + char *name=p,*args=NULL,*defn,*proto; + int flags; + while (*p++); + p+=2*3; + if ((flags=((char *)p)[-2]<<8)&PCHID_MACRO) { + args=p; + while (*p) + while (*p++); + p++; + } + defn=p; + while (*p++); + proto=p; + p0+=((PCH_HEAD *)p0)->dic_off; + if (*proto) + return sUnpack(proto,sUnpackBuf,p0); + if (args) { + char *d=sUnpackBuf; + *d++='_'; + *d++='('; + p=args; + while (*p) { + while ((*d++=*p++)); + d--; + } + strcpy(d,") = " DOTS); + } else if (*defn) { + char *d=sUnpackBuf; + strcpy(d,"_ = "); d+=4; + if (flags&PCHID_PACKED) sUnpack(defn,d,p0); + else strcpy(d,defn); + } else return "[no prototype]"; + return sUnpackBuf; + } + char *pch_unpack2(char *p,char *p0) { + char *name=p,*args=NULL,*defn,*proto; + int flags; char *d; + while (*p++); + p+=2*3; + if ((flags=((char *)p)[-2]<<8)&PCHID_MACRO) { + args=p; + while (*p) + while (*p++); + p++; + } + defn=p; + while (*p++); + proto=p; + p0+=((PCH_HEAD *)p0)->dic_off; + if (*proto) + return sUnpack(proto,sUnpackBuf,p0); + d=sUnpackBuf; + d+=sprintf(d," > Implementation :\n"); + if (args || *defn) { + d+=sprintf(d,"#define %s",name); + if (args) { + *d++='('; + p=args; + while (*p) { + while ((*d++=*p++)); + d--; + } + *d++=')'; + } + *d++=' '; + if (flags&PCHID_PACKED) sUnpack(defn,d,p0); + else strcpy(d,defn); + while (*d++); d--; + } + if (*proto) { + *d++='\n'; + sUnpack(proto,d,p0); + } + return sUnpackBuf; + } +#else +PU_HANDLER (catHelp) { + char *d=sUnpackBuf; + d+=sprintf(d," > Implementation :\n"); + if (*args || *defn) { + d+=sprintf(d,"#define %s%s %s",name,args,defn); + if (*trueproto) *d++='\n'; + } + if (*trueproto) + d+=sprintf(d,"%s",trueproto); + return sUnpackBuf; +} +PU_HANDLER (catMsg) { + char *d=sUnpackBuf; + if (*proto) { + strcpy(d,proto); + return d; + } + if (*args) + sprintf(d,"_%s = "DOTS,args); + else if (*defn) + sprintf(d,"_ = %s",defn); + else + return "[no prototype]"; + return d; +} +#endif +char cat_retbuf[80]; +char *Catalog() { + int n; char *ret=NULL; + char **match,**mdata; + if (!catmatch) { + if (!(catmatch=match=malloc(MAX_CATALOG_ENTRIES*4*2))) return ret; + mdata=match+MAX_CATALOG_ENTRIES; + SimpleDlg(NULL,"\n Loading catalog"DOTS" \n",B_CENTER,W_NOKEY); + LCD_restore(Port); + catnum=n=cat_prep(MAX_CATALOG_ENTRIES,match,mdata); + } else n=catnum,match=catmatch,mdata=match+MAX_CATALOG_ENTRIES; + #ifndef PEDROM + unsigned char alphaState; + alphaLockOn(&alphaState); + #endif + if (n) { + int key,height; SCROLL s; char title[100]; WIN_RECT win; + int last_sel=-1; + EDIT_LINE search; + sprintf(title,"Catalog - %d entries",n); + s.h=min(_89_92(12,16),n); s.n=n; ScrollInit(&s); + if (curword[0]) + cat_str_search(&s,match,curword); + // true_h = s.h*6 + 8(title) + 4(border) + 8(search line) + height=s.h*6; + while (1) { + dialog(title,128,height,B_ROUNDED|B_CENTER,&win); + cat_list(&s,match,win.x0>>2,((win.x1-win.x0)>>2)+1,win.y0); + if (s.sel!=last_sel) +#ifdef NO_PCH_UTIL + last_sel=s.sel, memcpy(msgBuf,pch_unpack(match[s.sel],mdata[s.sel]),58), msg=msgBuf, msgBuf[58]=0; +#else + last_sel=s.sel, memcpy(msgBuf,PchUnpack(catMsg,match[s.sel],mdata[s.sel]),58), + msg=msgBuf, msgBuf[58]=0; +#endif + if (!(key=WaitLoop(NULL))) continue; + if (key==KEY_ESC) break; + else if (key==KEY_ENTER) { + strcpy(ret=cat_retbuf,match[s.sel]); break; + } else if (key==KEY_UP) + repeated=0, ScrollUp(&s); + else if (key==KEY_DOWN) + repeated=0, ScrollDn(&s); + else if (key==KEY_2ND+KEY_UP) + ScrollChgWrapOnlyAtEnd(&s,-s.h); + else if (key==KEY_2ND+KEY_DOWN) + ScrollChgWrapOnlyAtEnd(&s,s.h); + else if (key==KEY_DMD+KEY_UP) + s.sel=0; + else if (key==KEY_DMD+KEY_DOWN) + s.sel=-1; + else if (key>=32 && key<=255 && isidch(key)) + cat_letter_search(&s,match,key); + else if (key==KEY_F1) +#ifdef NO_PCH_UTIL + SimpleDlg("Help",pch_unpack2(match[s.sel],mdata[s.sel]),B_CENTER,W_NORMAL); +#else + SimpleDlg("Help",PchUnpack(catHelp,match[s.sel],mdata[s.sel]),B_CENTER,W_NORMAL); +#endif + if (repeated) // happens only if the key was repeated AND 'repeated' wasn't cleared + ScrollUpdNoWrap(&s); + } + } + #ifndef PEDROM + SetAlphaStatus(alphaState); + #endif + return ret; +} + +#include "Dialogs.h" diff --git a/ti68k/ide/files.h b/ti68k/ide/files.h new file mode 100644 index 0000000..e64732a --- /dev/null +++ b/ti68k/ide/files.h @@ -0,0 +1,98 @@ +// Files misc mgt routines + +// internal filetypes... +enum { + IFT_INVALID=0, + IFT_OTH, IFT_TEXT, IFT_RES, IFT_C, IFT_H, IFT_PRGM, IFT_FUNC, IFT_XFUNC, + IFT_PACK /* (?) */, IFT_EXPR, +}; +// remark : currently IFT_XFUNC and IFT_PACK are never generated... +int IFTIcons[]={ + [IFT_INVALID] 0, + [IFT_OTH] 3, + [IFT_TEXT] 4, + [IFT_RES] 5, + [IFT_C] 6, + [IFT_H] 7, + [IFT_PRGM] 8, + [IFT_FUNC] 8, + [IFT_XFUNC]8, + [IFT_PACK] 9, + [IFT_EXPR] 10, +}; + +HANDLE FindFile(char *f) { + HSym hs; + if (!(hs=SymFind(SYMSTR(f))).folder) + return H_NULL; + SYM_ENTRY *se=DerefSym(hs); + return se->handle; +} +int GetIFT(HANDLE h) { + ESI tagptr=HToESI(h); + switch (*tagptr) { + case OTH_TAG: + tagptr--; + while (*--tagptr); + tagptr++; + switch (*tagptr) { + case 'C': + if (!strcmp(tagptr,"C")) return IFT_C; + break; + case 'H': + if (!strcmp(tagptr,"H")) return IFT_H; + break; + case 'R': + if (!strcmp(tagptr,"RES")) return IFT_RES; + break; + } + return IFT_OTH; + case TEXT_TAG: + return IFT_TEXT; + case USERFUNC_TAG: + return IFT_PRGM; + } + return IFT_EXPR; +} +char *GetFTString(HANDLE h) { +#ifndef PEDROM + ESI tagptr=HToESI(h); + if (*tagptr==OTH_TAG) { + tagptr--; + while (*--tagptr); + tagptr++; + return tagptr; + } + return DataTypeNames(*tagptr); +#else + return "???"; +#endif +} + +XP_C *XpLoadItems(int filter) { + WITEM *wi=wsp->items; + int n=wsp->nitems; + XP_C *xc=malloc(sizeof(XP_C)+(n+2)*sizeof(XP_S)); + XP_S *xs; + if (!xc) return xc; + xs=(XP_S *)(xc+1); + xs->i=0; xs++; xc->s=xs; + xc->sh=0; xc->sel=0; xc->msel=n-1; + while (n--) { + if (wi->d.type==WI_FOLD) { + *(long *)&xs->i=0x00010002; + xs->d=wi->d.title; + } else { + int t=GetIFT(FindFile(wi->f.name)); + if (filter&(1< i=0xC002; + xs->t=IFTIcons[t]; + xs->d=wi->f.name; + } + xs++; + skipit: + wi++; + } + xs->i=0; + return xc; +} diff --git a/ti68k/ide/font.bin b/ti68k/ide/font.bin new file mode 100644 index 0000000..026f4e1 Binary files /dev/null and b/ti68k/ide/font.bin differ diff --git a/ti68k/ide/font.h b/ti68k/ide/font.h new file mode 100644 index 0000000..a914f8f --- /dev/null +++ b/ti68k/ide/font.h @@ -0,0 +1,66 @@ +#define __UNAVAILABLE_CHAR__ 0x33DD,0xBBFF,0xBBFF + + 0x1111,0x1111,0x1111, 0x0000,0x0000,0x8800, 0x00EE,0xAAEE,0x0000, 0x00EE,0xEEEE,0x0000, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, 0x0044,0xEE00,0x0000, + 0x0000,0xEE44,0x0000, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + 0x0000,0x0000,0x0000, 0x4444,0x4400,0x4400, 0xAAAA,0x0000,0x0000, 0xAAEE,0xAAEE,0xAA00, + 0x66CC,0xEE66,0xCC00, 0x8822,0x4488,0x2200, 0x44AA,0x44AA,0x6600, 0x4444,0x0000,0x0000, + 0x2244,0x4444,0x2200, 0x8844,0x4444,0x8800, 0x00AA,0x44AA,0x0000, 0x0044,0xEE44,0x0000, + 0x0000,0x0044,0x8800, 0x0000,0xEE00,0x0000, 0x0000,0x0000,0x4400, 0x2222,0x4488,0x8800, + 0x44AA,0xAAAA,0x4400, 0x44CC,0x4444,0xEE00, 0xCC22,0x4488,0xEE00, 0xCC22,0x4422,0xCC00, + 0x88AA,0xEE22,0x2200, 0xEE88,0xCC22,0xCC00, 0x6688,0xEEAA,0xEE00, 0xEE22,0x4488,0x8800, + 0xEEAA,0xEEAA,0xEE00, 0xEEAA,0xEE22,0xCC00, 0x0044,0x0044,0x0000, 0x0044,0x0044,0x8800, + 0x2244,0x8844,0x2200, 0x00EE,0x00EE,0x0000, 0x8844,0x2244,0x8800, 0xCC22,0x4400,0x4400, + 0xCC22,0xAAAA,0x4400, 0x44AA,0xEEAA,0xAA00, 0xCCAA,0xCCAA,0xCC00, 0x6688,0x8888,0x6600, + 0xCCAA,0xAAAA,0xCC00, 0xEE88,0xCC88,0xEE00, 0xEE88,0xCC88,0x8800, 0x6688,0xAAAA,0x6600, + 0xAAAA,0xEEAA,0xAA00, 0xEE44,0x4444,0xEE00, 0x2222,0x22AA,0x4400, 0xAAAA,0xCCAA,0xAA00, + 0x8888,0x8888,0xEE00, 0xAAEE,0xAAAA,0xAA00, 0xCCAA,0xAAAA,0xAA00, 0xEEAA,0xAAAA,0xEE00, + 0xCCAA,0xCC88,0x8800, 0x44AA,0xAAEE,0x6600, 0xCCAA,0xCCAA,0xAA00, 0x6688,0x4422,0xCC00, + 0xEE44,0x4444,0x4400, 0xAAAA,0xAAAA,0xEE00, 0xAAAA,0xAA44,0x4400, 0xAAAA,0xAAEE,0xAA00, + 0xAAAA,0x44AA,0xAA00, 0xAAAA,0x4444,0x4400, 0xEE22,0x4488,0xEE00, 0x6644,0x4444,0x6600, + 0x8888,0x4422,0x2200, 0xCC44,0x4444,0xCC00, 0x44AA,0x0000,0x0000, 0x0000,0x0000,0x00EE, + 0x8844,0x0000,0x0000, 0x0066,0xAAAA,0x6600, 0x88CC,0xAAAA,0xCC00, 0x0066,0x8888,0x6600, + 0x2266,0xAAAA,0x6600, 0x0044,0xAACC,0x6600, 0x6688,0xCC88,0x8800, 0x0066,0xAA66,0x22CC, + 0x88CC,0xAAAA,0xAA00, 0x4400,0x4444,0x4400, 0x2200,0x2222,0xAA44, 0x8888,0xAACC,0xAA00, + 0xCC44,0x4444,0x4400, 0x00AA,0xEEAA,0xAA00, 0x00CC,0xAAAA,0xAA00, 0x0044,0xAAAA,0x4400, + 0x00CC,0xAAAA,0xCC88, 0x0066,0xAAAA,0x6622, 0x00AA,0xCC88,0x8800, 0x0066,0xCC22,0xCC00, + 0x88EE,0x8888,0x6600, 0x00AA,0xAAAA,0x6600, 0x00AA,0xAAAA,0x4400, 0x00AA,0xAAEE,0xAA00, + 0x00AA,0x4444,0xAA00, 0x00AA,0xAAAA,0x4488, 0x00EE,0x4488,0xEE00, 0x6644,0x8844,0x6600, + 0x4444,0x4444,0x4400, 0xCC44,0x2244,0xCC00, 0x66CC,0x0000,0x0000, 0x0044,0xEEEE,0x4400, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + 0x00EE,0xAAAA,0xAA00, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + 0x2244,0xEE00,0xEE00, 0x22EE,0x44EE,0x8800, 0x8844,0xEE00,0xEE00, __UNAVAILABLE_CHAR__, + 0x0000,0x0000,0xAA00, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + 0x44AA,0x4400,0x0000, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, + __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, __UNAVAILABLE_CHAR__, diff --git a/ti68k/ide/gtdev-apphdr.h b/ti68k/ide/gtdev-apphdr.h new file mode 100644 index 0000000..612327a --- /dev/null +++ b/ti68k/ide/gtdev-apphdr.h @@ -0,0 +1,122 @@ +#define OO_APP_MAGIC (377180989U) +#define OO_HANDLE (0xFF000000u) +#define OO_SYSTEM_FRAME OO_HANDLE +#define MAKE_OO_HANDLE(h) ((h) | OO_HANDLE) +#define OO_GET_HANDLE(h) ((h) & ~OO_HANDLE) +#define IS_OO_HANDLE(h) ((h) > OO_HANDLE) +typedef enum {OO_RW=0, OO_RO=1, + OO_SEQ=0, OO_KEYED=2} OO_Flags; +typedef struct +{ + ULONG key; + void *value; +} OO_Attr; +#define pFrame _pFrameX +typedef ULONG pFrame; +typedef int AppID; +typedef struct SFrameHdr +{ + pFrame parent; + pFrame prototype; + OO_Flags flags; + ULONG first; + ULONG count; +} OO_Hdr; +typedef struct SFrame +{ + OO_Hdr head; + union + { + void *value[65000]; + OO_Attr pair[65000]; + } attr; +} Frame; +typedef void (* const OO_MethodPtr)(void); +#define STRING_FRAME(name, parent, proto, first, count) \ +const OO_Hdr name = \ +{ \ + (pFrame)parent, \ + (pFrame)proto, \ + OO_RO | OO_SEQ, \ + first, \ + count \ +}; \ +static const char * const name##Attr[count] = \ +{ +#define FRAME(name, parent, proto, first, count) \ +const OO_Hdr name = \ +{ \ + (pFrame)parent, \ + (pFrame)proto, \ + OO_RO | OO_KEYED, \ + first, \ + count \ +}; \ +static const OO_Attr name##Attr[count] = \ +{ +#define ATTR(selector, val) {selector, (void *)(val)}, +#define STRING_ATTR(sel, s) {OO_FIRST_STRING+(sel), s}, +#define ENDFRAME }; +#define MAX_APPLET_NAME_SIZE (8) +typedef struct SAppHdr +{ + ULONG magic; + UCHAR name[MAX_APPLET_NAME_SIZE]; + BYTE zeros[24]; + USHORT flags; + ULONG dataLen; + ULONG codeOffset; + ULONG initDataOffset; + ULONG initDataLen; + ULONG optlen; +} AppHdr; +typedef enum {APPHDR_LOCALIZER=0x0001} APPHDR_FLAGS; +typedef void (* APP_EXT_FUNC)(void); +typedef struct SAppExtension +{ + unsigned long name; + unsigned long help; + unsigned short index; +} APP_EXTENSION; +typedef struct SAppExtEntry +{ + APP_EXT_FUNC extension; + unsigned short flags; +} APP_EXT_ENTRY; +enum {APP_EXT_PROGRAM=0x0000, APP_EXT_FUNCTION=0x0001}; +typedef enum +{ + ACB_BUILTIN =0x0001, + ACB_INSTALLED =0x0002, + ACB_LOCALIZER =0x0004, + ACB_LOCK =0x0008, + ACB_JT_VERSION=0x0010, + ACB_SELECTED =0x0020, + ACB_COLLAPSE =0x0800, + ACB_BG =0x1000, + ACB_COMPRESS =0x4000, + ACB_DELETE =0x8000 +} ACB_Flags; +typedef struct SACB +{ + USHORT flags; + AppID myID; + AppID next; + AppID prev; + ULONG publicstorage; + AppHdr const *appHeader; + BYTE const *certhdr; + pFrame appData; +} ACB; +#define MY_ACB(p) ((ACB*)((BYTE*)&(p)-OFFSETOF(ACB,appData))) +#define MY_APP_ID(p) (MY_ACB(p)->myID) +#define OO_FIRST_STRING 2048 +#define OO_FIRST_APP_STRING 2048 +#define OO_APPSTRING (OO_FIRST_STRING+OO_FIRST_APP_STRING) +#define OO_FIRST_APP_ATTR 0x10000 +typedef enum {APP_NONE=0, + APP_INTERACTIVE=1, + APP_CON=2, + APP_ACCESS_SYSVARS=4, + APP_BACKGROUND=8} + APP_Flags; diff --git a/ti68k/ide/gtdev-plugins.h b/ti68k/ide/gtdev-plugins.h new file mode 100644 index 0000000..712f95d --- /dev/null +++ b/ti68k/ide/gtdev-plugins.h @@ -0,0 +1,58 @@ +#define PLUGIN_GTBASIC 0 +#define PLUGIN_GTC 1 +#define PluginName(x) ((x)?"GTC":"GTDEVBAS") + +#define ET_FATAL -2 +#define ET_WARNING -1 +#define ET_ERROR 0 +#define ET_INTERNAL_WARNING 1 +#define ET_INTERNAL_FAILURE 2 +#define et_isinternal(x) ((x)>0) +typedef void CALLBACK (*Msg_Callback_t)(char *message,int err_type,char *func,char *file,int line,int chr); +#define MAX_PROGRESS 65535 +typedef void CALLBACK (*Progr_Callback_t)(char *func,char *file,unsigned int fprogress); +#define GTC_Compile ((int(*CALLBACK)(char *in,char *out,Msg_Callback_t msg_process, \ + Progr_Callback_t progr_process)) st->sft[0]) + +void CALLBACK message_cb(char *message,int err_type,char *func,char *file,int line,int chr); +void CALLBACK progr_cb(char *func,char *file,unsigned int fprogress); + +//#define DEBUG_COMPILE +#ifdef DEBUG_COMPILE +#define NEED_DEBUG_MSG +void debug_msg(char *s); +#endif + +int Compile(char *in_file,int plugin) { +//#ifdef DEBUG_COMPILE +// debug_msg("Compile step#1"); +//#endif + SecureTab *st=GetAppSecureTable(PluginName(plugin)); + if (!st) return 0; +//#ifdef DEBUG_COMPILE +// debug_msg("Compile step#2"); +//#endif + int res=-1; + if (plugin==PLUGIN_GTC) { +#ifdef COMPILE_ONLY + ST_helpMsg("Compiling..."); +#endif +//#ifdef DEBUG_COMPILE +// debug_msg("Compile step#3"); +//#endif + res=GTC_Compile(in_file,"main\\outbin",message_cb,progr_cb); +//#ifdef DEBUG_COMPILE +// { +// char b[100]; +// sprintf(b,"\n Compile step#4: r=%d \n",res); +// debug_msg(b); +// } +//#endif +#ifdef COMPILE_ONLY + if (!res) ST_helpMsg("Compile successful!"); + else if (res==1) ST_helpMsg("error"); + else if (res==2) ST_helpMsg("couldn't open"); +#endif + } + return res; +} diff --git a/ti68k/ide/gtdev-securecomm.h b/ti68k/ide/gtdev-securecomm.h new file mode 100644 index 0000000..4078a35 --- /dev/null +++ b/ti68k/ide/gtdev-securecomm.h @@ -0,0 +1,28 @@ +#ifdef USE_ABSOLUTE_PATHS +#include "E:\Paul\89\Ti-GCC\Projects\GT-Dev\SecureCommDef.h" +#else +#include "securecommdef.h" +#endif + +#ifndef PEDROM +SecureTab *GetAppSecureTable(char *name) { + int appid=EV_getAppID(name); + void *tmp; + AppHdr *hdr; + if (appid<=0) return NULL; + tmp=HeapDeref(appid); + (const AppHdr *)hdr=((ACB *)tmp)->appHeader; + if (hdr->magic!=OO_APP_MAGIC || strcmp(hdr->name,name)) + return NULL; + return *(SecureTab **)(((void *)hdr)+hdr->codeOffset); +} +#else +SecureTab *GetAppSecureTable(char *name) { + long *ptr=ROM_base+0x30000; + #define MK_TAG2(a,b) (((long)(a)<<8)+(b)) + #define MK_TAG(a,b,c,d) MK_TAG2(MK_TAG2(MK_TAG2(a,b),c),d) + if (*ptr++!=MK_TAG('G','T','C','.') || *ptr++!=MK_TAG('t','a','g',' ')) + return NULL; + return *(SecureTab **)ptr; +} +#endif diff --git a/ti68k/ide/handlers.h b/ti68k/ide/handlers.h new file mode 100644 index 0000000..33ff968 --- /dev/null +++ b/ti68k/ide/handlers.h @@ -0,0 +1,224 @@ +// Keyboard Handlers + +enum { + TM_MULTILINE=0x1, TM_DIALOG=0x2, +}; +void KeyProcess(int key,int tmode) { + int *kp; + int k,n; +#ifdef EVHOOK + int EDH_proc=0; + keyproc: +#endif + kp=get_keylist(); + /* UP/DOWN mode=0/2nd/Dmd/Shift/2nd+Shift/Dmd+Shift */ + if (key==*kp++) { + if (ac_disp) { ac_on=1; ScrollUp(&ac_s); } + else if (tmode&TM_MULTILINE) cpos=up(curpos,xcur),tab_chk_r(cpos),selpos=0; +/* else if (tmode&TM_DIALOG) + DialogMsg(DLG_UP);*/ + } else if (key==*kp++) { + if (ac_disp) { if (ac_on) ScrollDn(&ac_s); else ac_on=1; } + else if (tmode&TM_MULTILINE) cpos=down(curpos,xcur),tab_chk_r(cpos),selpos=0; +/* else if (tmode&TM_DIALOG) + DialogMsg(DLG_DN);*/ + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + n=NLINES; cpos=curpos; while (n--) cpos=up(cpos,xcur); + tab_chk_l(cpos); selpos=0; + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + n=NLINES; cpos=curpos; while (n--) cpos=down(cpos,xcur); + tab_chk_l(cpos); selpos=0; + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + cpos=1; tab_chk_l(cpos); selpos=0; + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + cpos=curpos; while (tptr[cpos]) cpos=down(cpos,xcur); + tab_chk_l(cpos); selpos=0; + } else if (key==*kp++) selpos=up(curpos,xcur),tab_chk_r(selpos); + else if (key==*kp++) selpos=down(curpos,xcur),tab_chk_r(selpos); + else if (key==*kp++ && (tmode&TM_MULTILINE)) { + n=NLINES; selpos=curpos; while (n--) selpos=up(selpos,xcur); + tab_chk_l(selpos); + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + n=NLINES; selpos=curpos; while (n--) selpos=down(selpos,xcur); + tab_chk_l(selpos); + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + selpos=1; tab_chk_l(selpos); + } else if (key==*kp++ && (tmode&TM_MULTILINE)) { + selpos=curpos; while (tptr[selpos]) selpos=down(selpos,xcur); + tab_chk_l(selpos); + } + /* LEFT/RIGHT mode=0/2nd/Shift/2nd+Shift */ + else if (key==*kp++) { + if (sel1) cpos=sel1, selpos=0; + else if (curpos>1) { + cpos=curpos; + cpos--; if (tptr[cpos-1]==NEWLINE) cpos--; + selpos=0; tab_chk_l(cpos); + } + } else if (key==*kp++) { + if (sel2) cpos=sel2; + else if (cpos