├── BLANK_EN.DSF
├── BLANK_ES.DSF
├── LICENSE
├── README
└── src
├── DSF.l
├── UCTLExtern.pas
├── UCodeGeneration.pas
├── UCondacts.pas
├── UConnections.pas
├── UConstants.pas
├── UInclude.pas
├── UJSONExport.pas
├── ULabelList.pas
├── ULexLib.pas
├── ULexTokens.pas
├── UMessageList.pas
├── UObjects.pas
├── UProcess.pas
├── UProcessCondactList.pas
├── USintactic.pas
├── USymbolList.pas
├── UTokenList.pas
├── UVocabularyTree.pas
├── daadmaker.pas
├── drb.php
├── drf.pas
├── file2pas.pas
├── lexer.pas
├── lexer.pas_
└── mcrf.pas
/BLANK_EN.DSF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Utodev/DRC/c5665282bd66c3ee7424acd53fb92cce8a5ff37b/BLANK_EN.DSF
--------------------------------------------------------------------------------
/BLANK_ES.DSF:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Utodev/DRC/c5665282bd66c3ee7424acd53fb92cce8a5ff37b/BLANK_ES.DSF
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | DAAD Reborn Compiler (DRC) is a replacement of DAAD compiler (DC), running in modern OS (Windows, Linux MacOS).
2 |
3 | It also included a modern replacement of MCRF for Amstrad CPC, and DAADMAKER, a tool to build DAAD tapes and disks for ZX Spectrum.
4 |
5 | Please find usage and build instructions, download links in the DRC Wiki: https://github.com/daad-adventure-writer/DRC/wiki
6 |
7 | Download at
8 |
9 | http://www.ngpaws.com/downloads/DAAD/DRC/
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/src/DSF.l:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Utodev/DRC/c5665282bd66c3ee7424acd53fb92cce8a5ff37b/src/DSF.l
--------------------------------------------------------------------------------
/src/UCTLExtern.pas:
--------------------------------------------------------------------------------
1 | UNIT UCTLExtern;
2 |
3 | INTERFACE
4 |
5 | TYPE TCTLExternList = ARRAY OF AnsiString;
6 | VAR CTLExternList: TCTLExternList;
7 |
8 | PROCEDURE AddCTL_Extern(VAR ACTLExternList: TCTLExternList; FileName:AnsiString;ExternType: String);
9 |
10 | IMPLEMENTATION
11 |
12 | PROCEDURE AddCTL_Extern(VAR ACTLExternList: TCTLExternList; FileName:AnsiString;ExternType: String);
13 | BEGIN
14 | SetLength(ACTLExternList, Length(ACTLExternList) + 1);
15 | ACTLExternList[Length(ACTLExternList)-1] := FileName + '|' + ExternType;
16 | END;
17 |
18 | END.
19 |
--------------------------------------------------------------------------------
/src/UCodeGeneration.pas:
--------------------------------------------------------------------------------
1 | UNIT UCodeGeneration;
2 |
3 | {$MODE OBJFPC}
4 |
5 | INTERFACE
6 |
7 |
8 | PROCEDURE GenerateOutput(OutputFilename: String; Target: String);
9 |
10 |
11 |
12 | IMPLEMENTATION
13 |
14 | USES UJSONExport;
15 |
16 |
17 |
18 | PROCEDURE GenerateOutput(OutputFilename: String; Target: String);
19 | BEGIN
20 | GenerateJSON(OutputFileName);
21 | END;
22 | END.
23 |
--------------------------------------------------------------------------------
/src/UCondacts.pas:
--------------------------------------------------------------------------------
1 | UNIT UCondacts;
2 | {$MODE OBJFPC}
3 |
4 | INTERFACE
5 |
6 | USES UConstants;
7 |
8 | type TParamType = (none, locno, objno, flagno, sysno, mesno, procno, value, locno_, percent,
9 | vocabularyVerb, vocabularyNoun, vocabularyPrep, vocabularyAdverb, vocabularyAdjective,
10 | skip, string_,mesno2,
11 | window, // 0-7
12 | bitno // 0-15
13 | );
14 |
15 | TYPE TCondact = record
16 | NumParams : Byte;
17 | Condact : String;
18 | Type1: TParamType;
19 | Type2: TParamType;
20 | Type3: TParamType;
21 | CanBeJump : Boolean; // If true, its a condition that can be converted into Maluva JUMP
22 | end;
23 |
24 |
25 | CONST Condacts : ARRAY[0..NUM_CONDACTS+NUM_FAKE_CONDACTS - 1] OF TCondact = (
26 | (NumParams:1;Condact:'AT' ;Type1: locno; Type2: none; Type3: none; CanBeJump: true), // 0
27 | (NumParams:1;Condact:'NOTAT' ;Type1: locno; Type2: none; Type3: none; CanBeJump: true), // 1
28 | (NumParams:1;Condact:'ATGT' ;Type1: locno; Type2: none; Type3: none; CanBeJump: true), // 2
29 | (NumParams:1;Condact:'ATLT' ;Type1: locno; Type2:none; Type3: none; CanBeJump: true), // 3
30 | (NumParams:1;Condact:'PRESENT';Type1: objno; Type2: none; Type3: none; CanBeJump: true), // 4
31 | (NumParams:1;Condact:'ABSENT' ;Type1: objno; Type2: none; Type3: none; CanBeJump: true), // 5
32 | (NumParams:1;Condact:'WORN' ;Type1: objno; Type2: none; Type3: none; CanBeJump: true), // 6
33 | (NumParams:1;Condact:'NOTWORN';Type1: objno; Type2: none; Type3: none; CanBeJump: true), // 7
34 | (NumParams:1;Condact:'CARRIED';Type1: objno; Type2: none; Type3: none; CanBeJump: true), // 8
35 | (NumParams:1;Condact:'NOTCARR';Type1: objno; Type2: none; Type3: none; CanBeJump: true), // 9
36 | (NumParams:1;Condact:'CHANCE' ;Type1: percent; Type2: none; Type3: none; CanBeJump: true), // 10
37 | (NumParams:1;Condact:'ZERO' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: true), // 11
38 | (NumParams:1;Condact:'NOTZERO';Type1: flagno; Type2: none; Type3: none; CanBeJump: true), // 12
39 | (NumParams:2;Condact:'EQ' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: true), // 13
40 | (NumParams:2;Condact:'GT' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: true), // 14
41 | (NumParams:2;Condact:'LT' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: true), // 15
42 | (NumParams:1;Condact:'ADJECT1';Type1: vocabularyAdjective; Type2: none; Type3: none; CanBeJump: true), // 16
43 | (NumParams:1;Condact:'ADVERB' ;Type1: vocabularyAdverb; Type2: none; Type3: none; CanBeJump: true), // 17
44 | (NumParams:2;Condact:'SFX' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 18
45 | (NumParams:1;Condact:'DESC' ;Type1: locno; Type2: none; Type3: none; CanBeJump: false), // 19
46 | (NumParams:0;Condact:'QUIT' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 20
47 | (NumParams:0;Condact:'END' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 21
48 | (NumParams:0;Condact:'DONE' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 22
49 | (NumParams:0;Condact:'OK' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 23
50 | (NumParams:0;Condact:'ANYKEY' ;Type1: none; Type2: none ; Type3: none; CanBeJump: false), // 24
51 | (NumParams:1;Condact:'SAVE' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 25
52 | (NumParams:1;Condact:'LOAD' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 26
53 | (NumParams:1;Condact:'DPRINT' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 27
54 | (NumParams:1;Condact:'DISPLAY';Type1: value; Type2: none; Type3: none; CanBeJump: false), // 28
55 | (NumParams:0;Condact:'CLS' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 29
56 | (NumParams:0;Condact:'DROPALL';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 30
57 | (NumParams:0;Condact:'AUTOG' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 31
58 | (NumParams:0;Condact:'AUTOD' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 32
59 | (NumParams:0;Condact:'AUTOW' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 33
60 | (NumParams:0;Condact:'AUTOR' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 34
61 | (NumParams:1;Condact:'PAUSE' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 35
62 | (NumParams:2;Condact:'SYNONYM';Type1: vocabularyVerb; Type2: vocabularyNoun; Type3: none; CanBeJump: false), // 36
63 | (NumParams:1;Condact:'GOTO' ;Type1: locno; Type2: none; Type3: none; CanBeJump: false), // 37
64 | (NumParams:1;Condact:'MESSAGE';Type1: mesno; Type2: none; Type3: none; CanBeJump: false), // 38
65 | (NumParams:1;Condact:'REMOVE' ;Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 39
66 | (NumParams:1;Condact:'GET' ;Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 40
67 | (NumParams:1;Condact:'DROP' ;Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 41
68 | (NumParams:1;Condact:'WEAR' ;Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 42
69 | (NumParams:1;Condact:'DESTROY';Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 43
70 | (NumParams:1;Condact:'CREATE' ;Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 44
71 | (NumParams:2;Condact:'SWAP' ;Type1: objno; Type2: objno; Type3: none; CanBeJump: false), // 45
72 | (NumParams:2;Condact:'PLACE' ;Type1: objno; Type2: locno_; Type3: none; CanBeJump: false), // 46
73 | (NumParams:1;Condact:'SET' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 47
74 | (NumParams:1;Condact:'CLEAR' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 48
75 | (NumParams:2;Condact:'PLUS' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: false), // 49
76 | (NumParams:2;Condact:'MINUS' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: false), // 50
77 | (NumParams:2;Condact:'LET' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: false), // 51
78 | (NumParams:0;Condact:'NEWLINE';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 52
79 | (NumParams:1;Condact:'PRINT' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 53
80 | (NumParams:1;Condact:'SYSMESS';Type1: sysno; Type2: none; Type3: none; CanBeJump: false), // 54
81 | (NumParams:2;Condact:'ISAT' ;Type1: objno; Type2: locno_; Type3: none; CanBeJump: true), // 55
82 | (NumParams:1;Condact:'SETCO' ;Type1: objno; Type2: none; Type3: none; CanBeJump: false), // 56
83 | (NumParams:0;Condact:'SPACE' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 57
84 | (NumParams:1;Condact:'HASAT' ;Type1: value; Type2: none; Type3: none; CanBeJump: true), // 58
85 | (NumParams:1;Condact:'HASNAT' ;Type1: value; Type2: none; Type3: none; CanBeJump: true), // 59
86 | (NumParams:0;Condact:'LISTOBJ';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 60
87 | (NumParams:2;Condact:'EXTERN' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 61
88 | (NumParams:0;Condact:'RAMSAVE';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 62
89 | (NumParams:1;Condact:'RAMLOAD';Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 63
90 | (NumParams:2;Condact:'BEEP' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 64
91 | (NumParams:1;Condact:'PAPER' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 65
92 | (NumParams:1;Condact:'INK' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 66
93 | (NumParams:1;Condact:'BORDER' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 67
94 | (NumParams:1;Condact:'PREP' ;Type1: vocabularyPrep; Type2: none; Type3: none; CanBeJump: true), // 68
95 | (NumParams:1;Condact:'NOUN2' ;Type1: vocabularyNoun; Type2: none; Type3: none; CanBeJump: true), // 69
96 | (NumParams:1;Condact:'ADJECT2';Type1: vocabularyAdjective; Type2: none; Type3: none; CanBeJump: true), // 70
97 | (NumParams:2;Condact:'ADD' ;Type1: flagno; Type2: flagno; Type3: none; CanBeJump: false), // 71
98 | (NumParams:2;Condact:'SUB' ;Type1: flagno; Type2: flagno; Type3: none; CanBeJump: false), // 72
99 | (NumParams:1;Condact:'PARSE' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 73
100 | (NumParams:1;Condact:'LISTAT' ;Type1: locno_; Type2: none; Type3: none; CanBeJump: false), // 74
101 | (NumParams:1;Condact:'PROCESS';Type1: procno; Type2: none; Type3: none; CanBeJump: false), // 75
102 | (NumParams:2;Condact:'SAME' ;Type1: flagno; Type2: flagno; Type3: none; CanBeJump: true), // 76
103 | (NumParams:1;Condact:'MES' ;Type1: mesno; Type2: none; Type3: none; CanBeJump: false), // 77
104 | (NumParams:1;Condact:'WINDOW' ;Type1: window; Type2: none; Type3: none; CanBeJump: false), // 78
105 | (NumParams:2;Condact:'NOTEQ' ;Type1: flagno; Type2: value; Type3: none; CanBeJump: true), // 79
106 | (NumParams:2;Condact:'NOTSAME';Type1: flagno; Type2: flagno; Type3: none; CanBeJump: true), // 80
107 | (NumParams:1;Condact:'MODE' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 81
108 | (NumParams:2;Condact:'WINAT' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 82
109 | (NumParams:2;Condact:'TIME' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 83
110 | (NumParams:1;Condact:'PICTURE';Type1: value; Type2: none; Type3: none; CanBeJump: false), // 84
111 | (NumParams:1;Condact:'DOALL' ;Type1: locno_; Type2: none; Type3: none; CanBeJump: false), // 85
112 | (NumParams:2;Condact:'MOUSE' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 86
113 | (NumParams:2;Condact:'GFX' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 87
114 | (NumParams:2;Condact:'ISNOTAT';Type1: objno; Type2: locno_; Type3: none; CanBeJump: true), // 88
115 | (NumParams:2;Condact:'WEIGH' ;Type1: objno; Type2: flagno; Type3: none; CanBeJump: false), // 89
116 | (NumParams:2;Condact:'PUTIN' ;Type1: objno; Type2: locno; Type3: none; CanBeJump: false), // 90
117 | (NumParams:2;Condact:'TAKEOUT';Type1: objno; Type2: locno; Type3: none; CanBeJump: false), // 91
118 | (NumParams:0;Condact:'NEWTEXT';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 92
119 | (NumParams:2;Condact:'ABILITY';Type1: value; Type2: value; Type3: none; CanBeJump: false), // 93
120 | (NumParams:1;Condact:'WEIGHT' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 94
121 | (NumParams:1;Condact:'RANDOM' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 95
122 | (NumParams:2;Condact:'INPUT' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 96
123 | (NumParams:0;Condact:'SAVEAT' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 97
124 | (NumParams:0;Condact:'BACKAT' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 98
125 | (NumParams:2;Condact:'PRINTAT';Type1: value; Type2: value; Type3: none; CanBeJump: false), // 99
126 | (NumParams:0;Condact:'WHATO' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 100
127 | (NumParams:2;Condact:'CALL' ;Type1: value; Type2: value; Type3: none; CanBeJump: false), // 101
128 | (NumParams:1;Condact:'PUTO' ;Type1: locno_; Type2: none; Type3: none; CanBeJump: false), // 102 ;: revisart
129 | (NumParams:0;Condact:'NOTDONE';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 103
130 | (NumParams:1;Condact:'AUTOP' ;Type1: locno; Type2: none; Type3: none; CanBeJump: false), // 104
131 | (NumParams:1;Condact:'AUTOT' ;Type1: locno; Type2: none; Type3: none; CanBeJump: false), // 105
132 | (NumParams:1;Condact:'MOVE' ;Type1: flagno; Type2: none; Type3: none; CanBeJump: false), // 106
133 | (NumParams:2;Condact:'WINSIZE';Type1: value; Type2: value; Type3: none; CanBeJump: false), // 107
134 | (NumParams:0;Condact:'REDO' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 108
135 | (NumParams:0;Condact:'CENTRE' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 109
136 | (NumParams:1;Condact:'EXIT' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 110
137 | (NumParams:0;Condact:'INKEY' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 111
138 | (NumParams:2;Condact:'BIGGER' ;Type1: flagno; Type2: flagno; Type3: none; CanBeJump: true), // 112
139 | (NumParams:2;Condact:'SMALLER';Type1: flagno; Type2: flagno; Type3: none; CanBeJump: true), // 113
140 | (NumParams:0;Condact:'ISDONE' ;Type1: none; Type2: none; Type3: none; CanBeJump: true), // 114
141 | (NumParams:0;Condact:'ISNDONE';Type1: none; Type2: none; Type3: none; CanBeJump: true), // 115
142 | (NumParams:1;Condact:'SKIP' ;Type1: skip; Type2: none; Type3: none; CanBeJump: false), // 116
143 | (NumParams:0;Condact:'RESTART';Type1: none; Type2: none; Type3: none; CanBeJump: false), // 117
144 | (NumParams:1;Condact:'TAB' ;Type1: value; Type2: none; Type3: none; CanBeJump: false), // 118
145 | (NumParams:2;Condact:'COPYOF' ;Type1: objno; Type2: flagno; Type3: none; CanBeJump: false), // 119
146 | (NumParams:0;Condact:'dumb' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 120 // In V3, this is PREFIX for prefixed condacts
147 | (NumParams:2;Condact:'COPYOO' ;Type1: objno; Type2: objno; Type3: none; CanBeJump: false), // 121
148 | (NumParams:0;Condact:'dumb' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 122 // In V3, this is SETP2
149 | (NumParams:2;Condact:'COPYFO' ;Type1: flagno; Type2: objno; Type3: none; CanBeJump: false), // 123
150 | (NumParams:0;Condact:'dumb' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 124 // In V3, this is SETP2
151 | (NumParams:2;Condact:'COPYFF' ;Type1: flagno; Type2: flagno; Type3: none; CanBeJump: false), // 125
152 | (NumParams:2;Condact:'COPYBF' ;Type1: flagno; Type2: flagno; Type3: none; CanBeJump: false), // 126
153 | (NumParams:0;Condact:'RESET' ;Type1: none; Type2: none; Type3: none; CanBeJump: false), // 127
154 |
155 | // Additional fake condacts
156 | (Numparams:1;Condact:'XMES';Type1: string_; Type2: none; Type3: none; CanBeJump: false), //128
157 | (Numparams:1;Condact:'XMESSAGE';Type1: string_; Type2: none; Type3: none; CanBeJump: false), //129
158 | (Numparams:1;Condact:'XPICTURE';Type1: value; Type2: none; Type3: none; CanBeJump: false), //130
159 | (Numparams:1;Condact:'XSAVE';Type1: value; Type2: none; Type3: none; CanBeJump: false), //131
160 | (Numparams:1;Condact:'XLOAD';Type1: value; Type2: none; Type3: none; CanBeJump: false), //132
161 | (Numparams:1;Condact:'XPART';Type1: value; Type2: none; Type3: none; CanBeJump: false), //133
162 | (Numparams:1;Condact:'XPLAY';Type1: string_; Type2: none; Type3: none; CanBeJump: false), //134
163 | (Numparams:2;Condact:'XBEEP';Type1: value; Type2: value; Type3: none; CanBeJump: false), // 135
164 | (Numparams:1;Condact:'XSPLITSCR';Type1: value; Type2: none; Type3: none; CanBeJump: false), //136
165 | (Numparams:0;Condact:'XUNDONE';Type1: none; Type2: none; Type3: none; CanBeJump: false), //137
166 | (Numparams:0;Condact:'XNEXTCLS';Type1: none; Type2: none; Type3: none; CanBeJump: false), //138
167 | (Numparams:0;Condact:'XNEXTRST';Type1: none; Type2: none; Type3: none; CanBeJump: false), //139
168 | (Numparams:1;Condact:'XSPEED';Type1: value; Type2: none; Type3: none; CanBeJump: false), //140
169 | (Numparams:1;Condact:'PENDINGSKIP';Type1: value;Type2:none; Type3: none; CanBeJump: false), //141 This one is used internally by the compiler only
170 | (Numparams:1;Condact:'XDATA';Type1: string_; Type2: none; Type3: none; CanBeJump: false) //142
171 | );
172 |
173 | CONST PrefixCondacts : ARRAY[0..NUM_PREFIX_CONDACTS-1] OF TCondact = (
174 | (Numparams:2;Condact:'BSET';Type1: flagno; Type2: bitno; Type3: none; CanBeJump: false), //0 BSET flagno bitno
175 | (Numparams:2;Condact:'BCLEAR';Type1: flagno; Type2: bitno; Type3: none; CanBeJump: false), //1 BCLEAR flagno bitno
176 | (Numparams:2;Condact:'BTOGGLE';Type1: flagno; Type2: bitno; Type3: none; CanBeJump: false), //2 BTOGGLE flagno bitno
177 | (Numparams:2;Condact:'BZERO';Type1: flagno; Type2: bitno; Type3: none; CanBeJump: false), //3 BZERO flagno bitno
178 | (Numparams:2;Condact:'BNOTZERO';Type1: flagno; Type2: bitno; Type3: none; CanBeJump: false), //4 BNOTZERO flagno bitno
179 | (Numparams:1;Condact:'SELECT';Type1: flagno; Type2: none; Type3: none; CanBeJump: false), //5 SELECT flagno
180 | (Numparams:2;Condact:'OPTION';Type1: value; Type2:string_; Type3: none; CanBeJump: false), //6 OPTION value "option"
181 | (Numparams:0;Condact:'CHOICE';Type1: none; Type2: none; Type3: none; CanBeJump: false), //7 CHOICE
182 | (Numparams:1;Condact:'TOGGLECON';Type1: string_; Type2: none; Type3: none; CanBeJump: false), //8 TOGGLECON verb
183 | (Numparams:1;Condact:'MES2';Type1: mesno2; Type2: none; Type3: none; CanBeJump: false) //9 MES2 mesno, internal condact, not documented nor usable from DSF file
184 |
185 |
186 | );
187 |
188 | (* Returns the condact index in the codacts table, or -1 if not found*)
189 | FUNCTION GetCondact(Condact : String): Integer;
190 |
191 | (* Returns number of condacts for a given condact code *)
192 | FUNCTION GetNumParams(Opcode: Longint): Byte;
193 |
194 | (* Performs semantic check for parameters *)
195 | FUNCTION SemanticCheck(Opcode: Longint; ParamNum: Byte; ParamValue: Byte;ParamAsString: AnsiString): AnsiString;
196 |
197 |
198 | IMPLEMENTATION
199 |
200 | USES SysUtils, UMessageList, UVocabularyTree;
201 |
202 | FUNCTION GetCondact(Condact : String): Integer;
203 | VAR i : integer;
204 | found : boolean;
205 | BEGIN
206 | IF (UpperCase(Condact)=FAKE_DEBUG_CONDACT_TEXT) THEN
207 | BEGIN
208 | Result := FAKE_DEBUG_CONDACT_CODE;
209 | END
210 | ELSE
211 | BEGIN
212 | i := 0;
213 | found := false;
214 | while (i < NUM_CONDACTS+NUM_FAKE_CONDACTS) AND (NOT found) DO
215 | BEGIN
216 | if (AnsiUpperCase(Condact) = AnsiUpperCase(Condacts[i].Condact)) THEN
217 | BEGIN
218 | Result := i;
219 | found := true;
220 | END;
221 | Inc(i);
222 | END;
223 |
224 | IF (NOT FOUND) AND (V3CODE) THEN // Search for Prefixed Condacts
225 | BEGIN
226 | i := 0;
227 | while (i < NUM_PREFIX_CONDACTS) AND (NOT found) DO
228 | BEGIN
229 | if (AnsiUpperCase(Condact) = AnsiUpperCase(PrefixCondacts[i].Condact)) THEN
230 | BEGIN
231 | Result := i + 512; // returns the condact id + 512
232 | found := true;
233 | END;
234 | Inc(i);
235 | END;
236 | END;
237 | IF NOT FOUND THEN Result := -1;
238 | END;
239 | END;
240 |
241 | FUNCTION GetNumParams(Opcode: Longint): Byte;
242 | BEGIN
243 | IF Opcode = FAKE_DEBUG_CONDACT_CODE THEN Result :=0
244 | ELSE IF (((Opcode AND 512) = 512) AND V3CODE) THEN Result := PrefixCondacts[Opcode - 512].NumParams
245 | ELSE Result := Condacts[Opcode].NumParams;
246 | END;
247 |
248 | FUNCTION GetParamType(Opcode:Longint; ParamNum: Byte): TParamType;
249 | BEGIN
250 | IF (((Opcode AND 512) = 512) AND V3CODE) THEN
251 | BEGIN
252 | if (ParamNum = 1) THEN Result := PrefixCondacts[Opcode-512].Type1
253 | ELSE if (ParamNum = 2) THEN Result := PrefixCondacts[Opcode - 512].Type2
254 | ELSE Result := PrefixCondacts[Opcode-512].Type3;
255 | END
256 | ELSE
257 | BEGIN
258 | if (ParamNum = 1) THEN Result := Condacts[Opcode].Type1
259 | ELSE if (ParamNum = 2) THEN Result := Condacts[Opcode].Type2
260 | ELSE Result := Condacts[Opcode].Type3;
261 | END;
262 | END;
263 |
264 | FUNCTION SemanticVocabularyCheck(VocType: TVocType; AWord: AnsiString):AnsiString;
265 | VAR AVocabularyTree: TPVocabularyTree;
266 | BEGIN
267 | IF Aword='_' THEN Result := ''
268 | ELSE
269 | BEGIN
270 | if (Length(AWord)>5) THEN AWord := Copy(Aword, 1, 5);
271 | Aword := AnsiUpperCase(AWord);
272 | AVocabularyTree := GetVocabulary(VocabularyTree,AWord,VocType);
273 | IF AVocabularyTree = nil THEN Result:='Word not defined in vocabulary or it has an unexpected word type : ' + AWord
274 | ELSE Result := '';
275 | END;
276 | END;
277 |
278 |
279 | FUNCTION SemanticCheck(Opcode: Longint; ParamNum: Byte; ParamValue: Byte; ParamAsString: AnsiString): AnsiString;
280 | VAR ExpectedType : TParamType;
281 | BEGIN
282 | ExpectedType := GetParamType(Opcode, ParamNum);
283 | Result := '';
284 | CASE ExpectedType OF
285 | locno: IF ParamValue >= LTXCount THEN Result := 'Location ' + IntToStr(ParamValue) + ' does not exist';
286 | objno: IF ParamValue >= OTXCount THEN Result := 'Object ' + IntToStr(ParamValue) + ' does not exist';
287 | flagno: Result := '';
288 | sysno: IF ParamValue >= STXCount THEN Result := 'System message ' + IntToStr(ParamValue) + ' does not exist';
289 | mesno: IF ParamValue >= MTXCount THEN Result := 'Message ' + IntToStr(ParamValue) + ' does not exist';
290 | mesno2: IF ParamValue >= MTX2Count THEN Result := 'Message ' + IntToStr(ParamValue) + ' does not exist';
291 | procno: Result := ''; // For the time being we don't check procno as there could be forward references
292 | value: Result := '';
293 | locno_: IF (ParamValue >= LTXCount) AND (ParamValue< 252) THEN Result := 'Location ' + IntToStr(ParamValue) + ' does not exist';
294 | percent: IF (ParamValue >= 100) OR (ParamValue=0) THEN Result := 'Invalid percent value, must be in the 1-99 range';
295 | vocabularyVerb : BEGIN
296 | Result := SemanticVocabularyCheck(VOC_VERB, ParamAsString);
297 | if (Result<>'') then Result := SemanticVocabularyCheck(VOC_NOUN, ParamAsString); // Only SYNONYN has a vocabularyVerb parameter, and in that case, it can also be a convertible noun. Semantically we only check if it's a noun, if it's convertible is checked elsewhere
298 | END;
299 | vocabularyNoun : Result := SemanticVocabularyCheck(VOC_NOUN, ParamAsString);
300 | vocabularyPrep : Result := SemanticVocabularyCheck(VOC_PREPOSITION, ParamAsString);
301 | vocabularyAdjective : Result := SemanticVocabularyCheck(VOC_ADJECT, ParamAsString);
302 | vocabularyAdverb : Result := SemanticVocabularyCheck(VOC_ADVERB, ParamAsString);
303 | skip: Result := '';
304 | string_ : Result := '';
305 | window : IF ParamValue > 7 THEN Result := 'Invalid window number, must be in the 0-7 range';
306 | ELSE Result := '';
307 | END; //case
308 | END;
309 |
310 |
311 | END.
312 |
--------------------------------------------------------------------------------
/src/UConnections.pas:
--------------------------------------------------------------------------------
1 | UNIT UConnections;
2 | {$MODE OBJFPC}
3 |
4 | INTERFACE
5 |
6 |
7 | TYPE TPConnectionList = ^TConnectionList;
8 |
9 | TConnectionList = RECORD
10 | FromLoc: Longint;
11 | ToLoc : Longint;
12 | Direction : Longint;
13 | Blockable : boolean;
14 | Blocked : boolean;
15 | Next : TPConnectionList;
16 | BlockedOrdinal : Longint;
17 | END;
18 |
19 | VAR Connections : TPConnectionList;
20 | BlockableCount : Byte;
21 |
22 | PROCEDURE AddConnection(VAR AConnectionList:TPConnectionList; AFromLoc, AToLoc, ADirection: Longint; ABlockable: boolean; ABlocked: boolean);
23 | FUNCTION FindConnection(AConnectionList:TPConnectionList; AFromLoc, AToLoc, ADirection: Longint; ABlockable, ABlocked: Boolean; Strict: boolean=true):boolean;
24 | FUNCTION getConnectionOrdinalFromString(AString: String): Longint;
25 |
26 | IMPLEMENTATION
27 |
28 | USES UMessageList, UVocabularyTree, sysutils, uConstants;
29 |
30 | PROCEDURE AddConnection(VAR AConnectionList:TPConnectionList; AFromLoc, AToLoc, ADirection: Longint; ABlockable: boolean; ABlocked: boolean);
31 | BEGIN
32 | IF AConnectionList <> nil THEN AddConnection(AConnectionList^.Next, AFromLoc, AToLoc, ADirection, ABlockable, ABlocked)
33 | ELSE
34 | BEGIN
35 | New(AConnectionList);
36 | AConnectionList^.FromLoc := AFromLoc;
37 | AConnectionList^.ToLoc := AToLoc;
38 | AConnectionList^.Direction := ADirection;
39 | AConnectionList^.Blockable := ABlockable;
40 | AConnectionList^.Blocked := ABlocked;
41 | if (ABlockable) THEN AConnectionList^.BlockedOrdinal := BlockableCount ELSE AConnectionList^.BlockedOrdinal := -1;
42 | if (ABlockable) THEN BlockableCount := BlockableCount + 1;
43 | AConnectionList^.Next := nil;
44 | END
45 | END;
46 |
47 |
48 | FUNCTION FindConnection(AConnectionList:TPConnectionList; AFromLoc, AToLoc, ADirection: Longint; ABlockable, ABlocked: Boolean; Strict: boolean=true):boolean;
49 | BEGIN
50 | IF AConnectionList = nil THEN Result := false
51 | ELSE
52 | IF (AConnectionList^.ToLoc = AToLoc)
53 | AND (AConnectionList^.FromLoc = AFromLoc)
54 | AND (AConnectionList^.Direction=ADirection)
55 | AND (AConnectionList^.Blockable = ABlockable)
56 | AND ((AConnectionList^.Blocked = ABlocked) OR (NOT Strict))
57 | THEN Result := true
58 | ELSE Result := FindConnection(AConnectionList^.Next, AFromLoc, AToLoc, ADirection, ABlockable, ABlocked, Strict);
59 | END;
60 |
61 | FUNCTION getConnectionOrdinalFromString(AString: String): Longint;
62 | var p1, p2, p3: string;
63 | SpaceCount: Byte;
64 | PreservedString: String;
65 | FromLoc, ToLoc, Direction: Longint;
66 | AuxVocabularyTree : TPVocabularyTree;
67 | AuxConnections : TPConnectionList;
68 | BEGIN
69 | PreservedString := AString;
70 | SpaceCount := 0;
71 |
72 | // Check if three parameters are present
73 | WHILE ((pos(' ', AString) > 0) AND (SpaceCount<=2)) DO
74 | BEGIN
75 | delete(AString, 1, pos(' ', AString));
76 | SpaceCount := SpaceCount + 1;
77 | END;
78 | if (SpaceCount > 2) THEN // If more than 3, fails
79 | BEGIN
80 | Result := MAXLONGINT;
81 | Exit;
82 | END;
83 |
84 | // Extract the three parameters
85 | p1 := copy(PreservedString, 1, pos(' ', PreservedString)-1);
86 | delete(PreservedString, 1, pos(' ', PreservedString));
87 | p2 := copy(PreservedString, 1, pos(' ', PreservedString)-1);
88 | delete(PreservedString, 1, pos(' ', PreservedString));
89 | p3 := PreservedString;
90 |
91 | // Convert the first and third parameters to integers
92 | TRY
93 | FromLoc := StrToInt(p1);
94 | EXCEPT
95 | ON E : EConvertError do
96 | BEGIN
97 | Result := MAXLONGINT; // If the conversion fails, return MAXLONGINT (failure signal)
98 | Exit;
99 | END;
100 | END;
101 | if (FromLoc<0) OR (FromLoc>LTXCount) THEN
102 | BEGIN
103 | Result := MAXLONGINT; // If the location is out of range, return MAXLONGINT (failure signal)
104 | Exit;
105 | END;
106 |
107 | TRY
108 | ToLoc := StrToInt(p3);
109 | EXCEPT
110 | ON E : EConvertError do
111 | BEGIN
112 | Result := MAXLONGINT;// If the conversion fails, return MAXLONGINT (failure signal)
113 | Exit;
114 | END;
115 | END;
116 | if (ToLoc<0) OR (ToLoc>LTXCount) THEN
117 | BEGIN
118 | Result := MAXLONGINT;// If the location is out of range, return MAXLONGINT (failure signal)
119 | Exit;
120 | END;
121 |
122 | // Convert the second parameter to a direction using the vocabulary table
123 | p2 := Copy(p2,1,VOCABULARY_LENGTH);
124 | AuxVocabularyTree := GetVocabulary(VocabularyTree, p2, VOC_ANY);
125 | IF (AuxVocabularyTree=nil) THEN
126 | BEGIN
127 | Result := MAXLONGINT; // If not found, fails
128 | Exit;
129 | END;
130 | IF (NOT (AuxVocabularyTree^.VocType IN [VOC_VERB,VOC_NOUN]) OR ((AuxVocabularyTree^.VocType = VOC_NOUN) AND (AuxVocabularyTree^.Value>MAX_CONVERTIBLE_NAME)) ) THEN
131 | BEGIN
132 | Result := MAXLONGINT; // If found, but not a verb or a convertible noun, fails
133 | Exit;
134 | END;
135 | // Get the Direction value
136 | Direction := AuxVocabularyTree^.Value;
137 |
138 |
139 |
140 | // Search for the connection to get the ordinal
141 | AuxConnections := Connections;
142 | WHILE (AuxConnections<>nil) AND ((AuxConnections^.FromLoc<>FromLoc) OR (AuxConnections^.ToLoc<>ToLoc) OR (AuxConnections^.Direction<>Direction)) DO AuxConnections := AuxConnections^.Next;
143 | IF (AuxConnections<>nil) THEN Result := AuxConnections^.BlockedOrdinal // And return ordinal if found
144 | ELSE Result := MAXLONGINT; // or fail if not
145 | END;
146 |
147 | BEGIN
148 | BlockableCount := 0;
149 | END.
--------------------------------------------------------------------------------
/src/UConstants.pas:
--------------------------------------------------------------------------------
1 | UNIT UConstants;
2 | {$MODE OBJFPC}
3 |
4 | INTERFACE
5 |
6 | CONST version_hi = 0;
7 | version_lo = 35;
8 |
9 | LOC_CARRIED = 254;
10 | LOC_WORN = 253;
11 | LOC_NOT_CREATED = 252;
12 | LOC_HERE = 255;
13 | NO_WORD = 255;
14 | MAX_FLAG_VALUE = 255;
15 | VOCABULARY_LENGTH = 5;
16 | MAX_DIRECTION_VOCABULARY = 13;
17 | MAX_CONVERTIBLE_NAME = 39;
18 | MAX_PROCESSES = 255;
19 | MAX_CONDACT_PARAMS =3;
20 | MAX_V3_DIRECTION = 127;
21 | MAX_BLOCKABLE_CONNECTIONS = 128;
22 | MAX_OBJECTS_V2 = 256;
23 | MAX_OBJECTS_V3 = 120;
24 |
25 | MAX_MESSAGES_PER_TABLE = 255;
26 | MAX_WEIGHT = 63;
27 |
28 | MAX_PARAMETER_RANGE = 255;
29 |
30 | MAX_LABELS = 1024;
31 |
32 | NUM_CONDACTS =128;
33 | NUM_FAKE_CONDACTS = 15;
34 | NUM_PREFIX_CONDACTS = 10;
35 |
36 |
37 | MESSAGE_OPCODE = 38;
38 | MES_OPCODE =77;
39 | SYSMESS_OPCODE = 54;
40 | XMES_OPCODE = 128;
41 | XMESSAGE_OPCODE = 129;
42 | XPICTURE_OPCODE = 130;
43 | PICTURE_OPCODE=84;
44 | XSAVE_OPCODE = 131;
45 | SAVE_OPCODE = 25;
46 | XLOAD_OPCODE = 132;
47 | LOAD_OPCODE = 26;
48 | XPLAY_OPCODE = 134;
49 | XBEEP_OPCODE = 135;
50 | XSPLITSCR_OPCODE = 136;
51 | XUNDONE_OPCODE=137;
52 | XNEXTCLS_OPCODE=138;
53 | XNEXTRST_OPCODE=139;
54 | XSPEED_OPCODE=140;
55 | XDATA_OPCODE=142;
56 | BEEP_OPCODE = 64;
57 |
58 | DESC_OPCODE = 19;
59 | SKIP_OPCODE = 116;
60 | PENDINGSKIP_OPCODE = 141;
61 |
62 | SYNONYM_OPCODE = 36;
63 | PREP_OPCODE = 68;
64 | NOUN2_OPCODE = 69;
65 | ADJECT1_OPCODE = 16;
66 | ADVERB_OPCODE = 17;
67 | ADJECT2_OPCODE = 70;
68 | MES2_OPCODE = 512 + 9;
69 | FAKE_DEBUG_CONDACT_CODE = 220; // the fake DEBUG Condact
70 | FAKE_DEBUG_CONDACT_TEXT = 'DEBUG';
71 |
72 | FAKE_USERPTR_CONDACT_CODE = 256;
73 |
74 | TOGGLECON_OPCODE = 520;
75 |
76 | // Compile options
77 | VAR ForceNormalMessages : Boolean;
78 | ForceXMessages : Boolean;
79 | NoSemantic : Boolean;
80 | SemanticWarnings : Boolean;
81 | Verbose: Boolean;
82 | CheckMaluva: Boolean;
83 | V3CODE : Boolean;
84 | MAX_PARAM_ACCEPTING_INDIRECTION: Byte;
85 | replace_xcondacts: Boolean;
86 |
87 | IMPLEMENTATION
88 |
89 | BEGIN
90 | ForceNormalMessages := false;
91 | NoSemantic := false;
92 | SemanticWarnings := false;
93 | Verbose := false;
94 | CheckMaluva := true;
95 | V3CODE := false;
96 | MAX_PARAM_ACCEPTING_INDIRECTION := 1;
97 | replace_xcondacts := false;
98 | END.
99 |
--------------------------------------------------------------------------------
/src/UInclude.pas:
--------------------------------------------------------------------------------
1 | UNIT UInclude;
2 |
3 | {$MODE OBJFPC}
4 |
5 |
6 |
7 | INTERFACE
8 |
9 | TYPE TIncludeData = record
10 | OriginalLine: longint;
11 | originalFileName: AnsiString;
12 | end;
13 |
14 | VAR IncludeList: array of TIncludeData;
15 |
16 |
17 | (* Adds a new line *)
18 | PROCEDURE AddLine(AMainLine: Longint; IncludeData: TIncludeData);
19 |
20 | FUNCTION GetIncludeData(AMainLine: Longint): TIncludeData;
21 |
22 | (* Returns the value of a Symbol or MAXLONGINT if it does not exist) *)
23 |
24 | IMPLEMENTATION
25 |
26 | PROCEDURE AddLine(AMainLine: Longint; IncludeData: TIncludeData);
27 | BEGIN
28 | SetLength(IncludeList, AMainLine);
29 | IncludeList[AMainLine-1] := IncludeData;
30 | END;
31 |
32 | FUNCTION GetIncludeData(AMainLine: Longint): TIncludeData;
33 | BEGIN
34 | Result := IncludeList[AMainLine-1];
35 | END;
36 |
37 |
38 | END.
--------------------------------------------------------------------------------
/src/UJSONExport.pas:
--------------------------------------------------------------------------------
1 | UNIT UJSONExport;
2 |
3 | {$I+}
4 |
5 | INTERFACE
6 |
7 | PROCEDURE GenerateJSON(OutputFileName: string);
8 |
9 | IMPLEMENTATION
10 |
11 |
12 | USES sysutils, UConstants, UVocabularyTree, UMessageList, UConnections, UObjects, UProcess, UProcessCondactList, UCTLExtern, USymbolList, strutils, UCondacts, USintactic;
13 |
14 |
15 | VAR Indent : Byte;
16 |
17 | FUNCTION tabs(): AnsiString;
18 | VAR AuxStr : AnsiString;
19 | i : integer;
20 | BEGIN
21 | AuxStr:='';
22 | for i := 1 to indent do AuxStr := AuxStr + #9; // tab
23 | tabs := AuxStr;
24 | END;
25 |
26 | FUNCTION getSymbolsJSON(SymbolList:TPSymbolList): AnsiString;
27 | BEGIN
28 | IF (SymbolList = nil) THEN getSymbolsJSON := ''
29 | ELSE getSymbolsJSON := getSymbolsJSON(SymbolList^.Next) + tabs() + tabs() + '{"symbol":"' + SymbolList^.Symbol +'", "Value":' + IntToStr(SymbolList^.Value) +'},'#10;
30 | END;
31 |
32 | FUNCTION getVocabularyJSON(VocabularyTree:TPVocabularyTree): AnsiString;
33 | BEGIN
34 | IF (VocabularyTree = nil) THEN getVocabularyJSON := ''
35 | ELSE getVocabularyJSON := getVocabularyJSON(VocabularyTree^.Left) + tabs() + tabs() + '{"VocWord":"' + VocabularyTree^.VocWord +'", "Value":' + IntToStr(VocabularyTree^.Value) +',"VocType":'+ IntToStr(Ord(VocabularyTree^.VocType)) +' },'#10 + getVocabularyJSON(VocabularyTree^.Right);
36 | END;
37 |
38 | FUNCTION FixDoubleQuotes(Str: AnsiString):AnsiString;
39 | BEGIN
40 | Str := AnsiReplaceStr(Str, '"','\"');
41 | Str := AnsiReplaceStr(Str, '\\"','\"');
42 | FixDoubleQuotes := Str;
43 | END;
44 |
45 | FUNCTION ConvertChars(Str: AnsiString):AnsiString;
46 | var i: integer;
47 | strOut : AnsiString;
48 | BEGIN
49 | // First replace international chars. Please notice AnsiReplaceStr(Str, 'á', '\u0015') doesn't work. Probably a bug of the fpc compiler library.
50 | // That is the reason why all replacements are done the way you see below, which is a little complicated. Codes in the CASE statement are the
51 | // ISO 8559-1 LATIN1 code for each of the characters. The replacement values are the ASCII codes DAAD uses for the Spanish characters (first
52 | // part) and the #gX#t combination we use for the new international characters.
53 | strOut := '';
54 | for i := 1 to Length(Str) DO
55 | BEGIN
56 | CASE (Ord(Str[i])) OF
57 | // Old spanish chars
58 | 170: strOut := strOut + '\u0010'; //ª - 16
59 | 161: strOut := strOut + '\u0011'; //¡ - 17
60 | 191: strOut := strOut + '\u0012'; //¿ - 18
61 | 171: strOut := strOut + '\u0013'; //<< - 19
62 | 187: strOut := strOut + '\u0014'; //<< - 20
63 | 225: strOut := strOut + '\u0015'; //á - 21
64 | 233: strOut := strOut + '\u0016'; //é - 22
65 | 237: strOut := strOut + '\u0017'; //í - 23
66 | 243: strOut := strOut + '\u0018'; //ó - 24
67 | 250: strOut := strOut + '\u0019'; //ú - 26
68 | 241: strOut := strOut + '\u001A'; //ñ - 27
69 | 209: strOut := strOut + '\u001B'; //Ñ - 28
70 | 231: strOut := strOut + '\u001C'; //ç - 28
71 | 199: strOut := strOut + '\u001D'; //Ç - 29
72 | 252: strOut := strOut + '\u001E'; //ü - 30
73 | 220: strOut := strOut + '\u001F'; //Ü - 31
74 | // New international chars - Upercase Vowels with acuté tilde
75 | 193: strOut := strOut + '#g\u007B#t'; //Á - 251
76 | 201: strOut := strOut + '#g\u007C#t'; //É - 252
77 | 205: strOut := strOut + '#g\u007D#t'; //Í - 253
78 | 211: strOut := strOut + '#g\u007E#t'; //Ó - 254
79 | 218: strOut := strOut + '#g\u007F#t'; //Ú - 255
80 | // New international chars - Lowercase accented vowels
81 | 224: strOut := strOut + '#g\u0010#t'; //à - 16
82 | 227: strOut := strOut + '#g\u0011#t'; //ã - 17
83 | 228: strOut := strOut + '#g\u0012#t'; //ä - 18
84 | 226: strOut := strOut + '#g\u0013#t'; //â - 19
85 | 232: strOut := strOut + '#g\u0014#t'; //è - 20
86 | 235: strOut := strOut + '#g\u0015#t'; //ë - 21
87 | 234: strOut := strOut + '#g\u0016#t'; //ê - 22
88 | 236: strOut := strOut + '#g\u0017#t'; //ì - 23
89 | 239: strOut := strOut + '#g\u0018#t'; //ï - 24
90 | 238: strOut := strOut + '#g\u0019#t'; //î - 26
91 | 242: strOut := strOut + '#g\u001A#t'; //ò - 27
92 | 245: strOut := strOut + '#g\u001B#t'; //õ - 28
93 | 246: strOut := strOut + '#g\u001C#t'; //ö - 28
94 | 244: strOut := strOut + '#g\u001D#t'; //ô - 29
95 | 249: strOut := strOut + '#g\u001E#t'; //ù - 30
96 | 251: strOut := strOut + '#g\u001F#t'; //û - 31
97 | // New international chars - Uppercase accented vowels
98 | 192: strOut := strOut + '#g\u0020#t'; //À - 32
99 | 195: strOut := strOut + '#g\u0021#t'; //Ã - 33
100 | 196: strOut := strOut + '#g\u0022#t'; //Ä - 34
101 | 194: strOut := strOut + '#g\u0023#t'; //Â - 35
102 | 200: strOut := strOut + '#g\u0024#t'; //È - 36
103 | 203: strOut := strOut + '#g\u0025#t'; //Ë - 37
104 | 202: strOut := strOut + '#g\u0026#t'; //Ê - 38
105 | 204: strOut := strOut + '#g\u0027#t'; //Ì - 30
106 | 207: strOut := strOut + '#g\u0028#t'; //Ï - 40
107 | 206: strOut := strOut + '#g\u0029#t'; //Î - 41
108 | 210: strOut := strOut + '#g\u002A#t'; //Ò - 42
109 | 213: strOut := strOut + '#g\u002B#t'; //Õ - 43
110 | 214: strOut := strOut + '#g\u002C#t'; //Ö - 44
111 | 212: strOut := strOut + '#g\u002D#t'; //Ô - 45
112 | 217: strOut := strOut + '#g\u002E#t'; //Ù - 46
113 | 219: strOut := strOut + '#g\u002F#t'; //Û - 47
114 |
115 |
116 | // New international chars - other chars
117 | 223: strOut := strOut + '\u007F'; //ß - Low Charset 127
118 |
119 | 253: strOut := strOut + '#g\u003A#t'; //ý - 58
120 | 221: strOut := strOut + '#g\u003B#t'; //Ý - 59
121 | 254: strOut := strOut + '#g\u003C#t'; //þ - 60
122 | 222: strOut := strOut + '#g\u003D#t'; //Þ - 61
123 | 229: strOut := strOut + '#g\u003E#t'; //å - 62
124 | 197: strOut := strOut + '#g\u003F#t'; //Å - 63
125 |
126 | 240: strOut := strOut + '#g\u005B#t'; //ð - 93
127 | 208: strOut := strOut + '#g\u005C#t'; //Ð - 94
128 | 248: strOut := strOut + '#g\u005D#t'; //ø - 95
129 | 216: strOut := strOut + '#g\u005E#t'; //Ø - 96
130 |
131 |
132 | ELSE StrOut := strOut + Str[i];
133 | END;
134 | END;
135 |
136 | // Give specific support for #e as the euro sign €
137 | StrOut := AnsiReplaceStr(StrOut, '#e', '#g\u0060#t'); //€ - 98
138 |
139 | // Now replace escape sequences
140 | StrOut := AnsiReplaceStr(StrOut, '#g', '\u000e');
141 | StrOut := AnsiReplaceStr(StrOut, '#t', '\u000f');
142 | StrOut := AnsiReplaceStr(StrOut, '#b', '\u000b');
143 | StrOut := AnsiReplaceStr(StrOut, '#s', ' ');
144 | StrOut := AnsiReplaceStr(StrOut, '#f', '\u007f');
145 | StrOut := AnsiReplaceStr(StrOut, '#k', '\u000c');
146 | StrOut := AnsiReplaceStr(StrOut, '#n', '\u000d');
147 | StrOut := AnsiReplaceStr(StrOut, '#r', '\u000d');
148 | StrOut := AnsiReplaceStr(StrOut, '\n', '\u000d');
149 | StrOut := AnsiReplaceStr(StrOut, '\r', '\u000d');
150 | // Add #A to #P to replacements array
151 | for i := ord('A') to ord('P') DO StrOut := AnsiReplaceStr(StrOut, '#' + chr(i), '\u00' + IntToHex(i +$10 - ord('A'),2));
152 |
153 | ConvertChars := StrOut;
154 | END;
155 |
156 | PROCEDURE GenerateJSON(OutputFileName: string);
157 | VAR JSON : Text;
158 | TempObjectList : TPObjectList;
159 | Aux,i,j : Word;
160 | MessageListsArray : array [0..6] of TPMessageList;
161 | MessageListsnames : array [0..6] of String;
162 | TempMessageList : TPMessageList;
163 | TempEntriesList : TPProcessEntryList;
164 | TempCondactList : TPProcessCondactList;
165 | TempConnectionList : TPConnectionList;
166 | AuxAnsiString :AnsiString;
167 | VerbStr, NounStr : String;
168 | VerbPtr, NounPtr : TPVocabularyTree;
169 |
170 | BEGIN
171 | Indent := 0;
172 | Assign(JSON, OutputFileName);
173 | Rewrite(JSON);
174 | WriteLn(JSON,tabs(),'{');
175 | // Settings
176 | WriteLn(JSON,tabs(),'"settings":');
177 | INC(Indent);
178 | WriteLn(JSON,tabs(),'[');
179 | WriteLn(JSON,tabs(),'{"classic_mode":', byte(ClassicMode), ', "debug_mode":', byte(DebugMode) , ', "v3code":', byte(v3code) , ', "maluva_used":', byte(MaluvaUsed OR NOT CheckMaluva) , '}');
180 | WriteLn(JSON,tabs(),'],');
181 | DEC(Indent);
182 | // Symbols
183 | WriteLn(JSON,tabs(),'"symbols":');
184 | INC(Indent);
185 | WriteLn(JSON,tabs(),'[');
186 | AuxAnsiString := getSymbolsJSON(SymbolList);
187 | SetLength(AuxAnsiString, Length(AuxAnsiString) - 2);
188 | WriteLn(JSON, AuxAnsiString);
189 | WriteLn(JSON,tabs(),'],');
190 | DEC(Indent);
191 | // Externs
192 | WriteLn(JSON,tabs(),'"externs":');
193 | INC(Indent);
194 | WriteLn(JSON,tabs(),'[');
195 | IF Length(CTLExternList)> 0 THEN
196 | FOR i := 0 to Length(CTLExternList)-1 DO
197 | BEGIN
198 | Write(JSON, tabs(), '{"FilePath":"',CTLExternList[i] , '"}');
199 | if (i<>Length(CTLExternList)-1) THEN WriteLN(JSON, ',') ELSE WriteLN(JSON);
200 | END;
201 | WriteLn(JSON,tabs(),'],');
202 | DEC(Indent);
203 | // Vocabulary
204 | WriteLn(JSON,tabs(),'"vocabulary":');
205 | INC(Indent);
206 | WriteLn(JSON,tabs(),'[');
207 | AuxAnsiString := getVocabularyJSON(VocabularyTree);
208 | SetLength(AuxAnsiString, Length(AuxAnsiString) - 2);
209 | WriteLn(JSON, AuxAnsiString);
210 | WriteLn(JSON,tabs(),'],');
211 | DEC(Indent);
212 | // Objects
213 | WriteLn(JSON,tabs(),'"object_data":');
214 | INC(Indent);
215 | WriteLn(JSON,tabs(),'[');
216 | TempObjectList := ObjectList;
217 | WHILE TempObjectList<>nil DO
218 | BEGIN
219 | WriteLn(JSON,tabs(),'{');
220 | INC(Indent);
221 | WriteLn(JSON,tabs(),'"Value":', TempObjectList^.Value,',');
222 | WriteLn(JSON,tabs(),'"Noun":', TempObjectList^.Noun,',');
223 | WriteLn(JSON,tabs(),'"Adjective":', TempObjectList^.Adjective,',');
224 | IF TempObjectList^.Container THEN Aux := 1 ELSE Aux := 0;
225 | WriteLn(JSON,tabs(),'"Container":', Aux,',');
226 | IF TempObjectList^.Wearable THEN Aux := 1 ELSE Aux := 0;
227 | WriteLn(JSON,tabs(),'"Wearable":', Aux,',');
228 | WriteLn(JSON,tabs(),'"Flags":', TempObjectList^.Flags,',');
229 | WriteLn(JSON,tabs(),'"Weight":', TempObjectList^.Weight,',');
230 | WriteLn(JSON,tabs(),'"InitialyAt":', TempObjectList^.InitialyAt);
231 | DEC(Indent);
232 | Write(JSON, tabs(), '}');
233 | if (TempObjectList^.Next <> nil) THEN WriteLn(JSON,',') ELSE WriteLn(JSON);
234 | TempObjectList := TempObjectList^.Next;
235 | END;
236 | WriteLn(JSON,tabs(),'],');
237 | DEC(Indent);
238 | // Connections
239 |
240 | TempConnectionList := Connections;
241 | WriteLn(JSON,tabs(),'"connections":');
242 | INC(Indent);
243 | WriteLn(JSON,tabs(),'[');
244 | WHILE TempConnectionList<>nil DO
245 | BEGIN
246 | WriteLn(JSON,tabs(),'{');
247 | INC(Indent);
248 | WriteLn(JSON,tabs(),'"FromLoc":', TempConnectionList^.FromLoc,',');
249 | WriteLn(JSON,tabs(),'"ToLoc":', TempConnectionList^.ToLoc,',');
250 | WriteLn(JSON,tabs(),'"Direction":', TempConnectionList^.Direction,',');
251 | WriteLn(JSON,tabs(),'"Blockable":', Byte(TempConnectionList^.Blockable),',');
252 | Write(JSON,tabs(),'"Blocked":', Byte(TempConnectionList^.Blocked));
253 | if (TempConnectionList^.BlockedOrdinal<>-1) THEN WriteLn(JSON, ','#13,tabs(),'"Ordinal":', TempConnectionList^.BlockedOrdinal) ELSE WriteLn(JSON, #13);
254 | DEC(Indent);
255 | Write(JSON, tabs(), '}');
256 | if (TempConnectionList^.Next <> nil) THEN WriteLn(JSON,',') ELSE WriteLn(JSON);
257 | TempConnectionList := TempConnectionList^.Next;
258 | END;
259 | WriteLn(JSON,tabs(),'],');
260 | DEC(Indent);
261 |
262 |
263 | // Texts
264 | MessageListsArray[0]:=MTX;
265 | MessageListsArray[1]:=STX;
266 | MessageListsArray[2]:=LTX;
267 | MessageListsArray[3]:=OTX;
268 | MessageListsArray[4]:=XTX;
269 | MessageListsArray[5]:=OtherTX;
270 | MessageListsArray[6]:=MTX2;
271 |
272 | MessageListsnames[0]:='messages';
273 | MessageListsnames[1]:='sysmess';
274 | MessageListsnames[2]:='locations';
275 | MessageListsnames[3]:='objects';
276 | MessageListsnames[4]:='xmessages';
277 | MessageListsnames[5]:='other_strings';
278 | MessageListsnames[6]:='messages2';
279 |
280 | for i := 0 to 6 DO
281 | BEGIN
282 | TempMessageList := MessageListsArray[i];
283 | WriteLn(JSON,tabs(),'"',MessageListsnames[i],'":');
284 | INC(Indent);
285 | WriteLn(JSON,tabs(),'[');
286 | WHILE TempMessageList<>nil DO
287 | BEGIN
288 | WriteLn(JSON,tabs(),'{');
289 | INC(Indent);
290 | WriteLn(JSON,tabs(),'"Value":', TempMessageList^.MessageID,',');
291 | WriteLn(JSON,tabs(),'"Text":"', ConvertChars(FixDoubleQuotes(TempMessageList^.Text)),'"');
292 | DEC(Indent);
293 | Write(JSON, tabs(), '}');
294 | if (TempMessageList^.Next <> nil) THEN WriteLn(JSON,',') ELSE WriteLn(JSON);
295 | TempMessageList := TempMessageList^.Next;
296 | END;
297 | WriteLn(JSON,tabs(),'],');
298 | DEC(Indent);
299 | END;
300 | // Processes
301 | WriteLn(JSON,tabs(),'"processes":');
302 | INC(Indent);
303 | WriteLn(JSON,tabs(),'[');
304 |
305 | FOR i := 0 to LastProcess DO // each process
306 | BEGIN
307 | WriteLn(JSON,tabs(),'{');
308 | INC(Indent);
309 | WriteLn(JSON,tabs(),'"Value":', Processes[i].Value,',');
310 | WriteLn(JSON,tabs(),'"entries":');
311 | INC(Indent);
312 | WriteLn(JSON,tabs(),'[');
313 | TempEntriesList := Processes[i].Entries;
314 | WHILE TempEntriesList<> nil DO // Each entry
315 | BEGIN
316 | WriteLn(JSON,tabs(),'{');
317 | INC(Indent);
318 | IF (TempEntriesList^.Verb = 255) THEN VerbStr := '_' ELSE
319 | BEGIN
320 | VerbPtr := GetVocabularyByNumber(VocabularyTree,TempEntriesList^.Verb, VOC_VERB);
321 | IF (VerbPtr = nil) AND (TempEntriesList^.Verb <= MAX_CONVERTIBLE_NAME) THEN VerbPtr := GetVocabularyByNumber(VocabularyTree,TempEntriesList^.Verb, VOC_NOUN);
322 | IF VerbPtr = nil then VerbStr := '?' ELSE VerbStr := VerbPtr^.VocWord;
323 | END;
324 | IF (TempEntriesList^.Noun = 255) THEN NounStr := '_' ELSE
325 | BEGIN
326 | NounPtr := GetVocabularyByNumber(VocabularyTree,TempEntriesList^.Noun, VOC_NOUN);
327 | IF NounPtr = nil then NounStr := '?' ELSE NounStr := NounPtr^.VocWord;
328 | END;
329 | WriteLn(JSON,tabs(),'"Entry":"', VerbStr,' ',NounStr,'",');
330 | WriteLn(JSON,tabs(),'"Verb":', TempEntriesList^.Verb,',');
331 | WriteLn(JSON,tabs(),'"Noun":', TempEntriesList^.Noun,',');
332 | TempCondactList := TempEntriesList^.Condacts;
333 | WriteLn(JSON,tabs(),'"condacts":');
334 | INC(Indent);
335 | WriteLn(JSON,tabs(),'[');
336 | WHILE TempCondactList<> nil DO // Each condact
337 | BEGIN
338 | WriteLn(JSON,tabs(),'{');
339 | INC(Indent);
340 | WriteLn(JSON,tabs(),'"Opcode":', TempCondactList^.Opcode,',');
341 | IF (TempCondactList^.isDB) THEN WriteLn(JSON,tabs(),'"Condact":"#DB/#INCBIN",')
342 | ELSE IF (TempCondactList^.Opcode = FAKE_USERPTR_CONDACT_CODE) THEN WriteLn(JSON,tabs(),'"Condact":"#USERPTR",')
343 | ELSE IF (TempCondactList^.Opcode = FAKE_DEBUG_CONDACT_CODE) THEN WriteLn(JSON,tabs(),'"Condact":"DEBUG",')
344 | ELSE IF ((TempCondactList^.Opcode AND 512) = 512) THEN WriteLn(JSON,tabs(),'"Condact":"', PrefixCondacts[TempCondactList^.Opcode - 512].Condact,'",')
345 | ELSE WriteLn(JSON,tabs(),'"Condact":"', Condacts[TempCondactList^.Opcode].Condact,'",');
346 |
347 | IF TempCondactList^.NumParams>0 THEN
348 | BEGIN
349 | FOR j:=0 to TempCondactList^.NumParams - 1 DO
350 | BEGIN
351 | IF TempCondactList^.Params[j].Indirection THEN Aux := 1 ELSE Aux := 0;
352 | WriteLn(JSON,tabs(),'"Indirection',j+1,'":', Aux,',');
353 | END;
354 | FOR J := 0 to TempCondactList^.NumParams - 1 DO WriteLn(JSON,tabs(),'"Param',j+1,'":', TempCondactList^.Params[j].Value,',');
355 | END;
356 | WriteLn(JSON,tabs(),'"NumParams":', TempCondactList^.NumParams);
357 |
358 |
359 | DEC(Indent);
360 | Write(JSON, tabs(), '}');
361 | if (TempCondactList^.Next <> nil) THEN WriteLn(JSON,',') ELSE WriteLn(JSON);
362 | TempCondactList:=TempCondactList^.Next;
363 | END;
364 | WriteLn(JSON,tabs(),']');
365 | DEC(Indent);
366 | DEC(Indent);
367 | Write(JSON, tabs(), '}');
368 | if (TempEntriesList^.Next <> nil) THEN WriteLn(JSON,',') ELSE WriteLn(JSON);
369 | TempEntriesList := TempEntriesList^.Next;
370 | END;
371 | WriteLn(JSON,tabs(),']');
372 | DEC(Indent);
373 | DEC(Indent);
374 | Write(JSON, tabs(), '}');
375 | if (i < LastProcess ) THEN WriteLn(JSON,',') ELSE WriteLn(JSON);
376 | END;
377 |
378 |
379 |
380 | WriteLn(JSON,tabs(),']');
381 | DEC(Indent);
382 |
383 |
384 | WriteLn(JSON,tabs(),'}');
385 | Close(JSON);
386 | Writeln(OutputFileName + ' generated.')
387 | END;
388 |
389 |
390 | END.
391 |
392 |
--------------------------------------------------------------------------------
/src/ULabelList.pas:
--------------------------------------------------------------------------------
1 | UNIT ULabelList;
2 |
3 | {$MODE OBJFPC}
4 |
5 | INTERFACE
6 |
7 | USES UConstants;
8 |
9 |
10 | TYPE TLabelData = record
11 | SkipLabel: AnsiString;
12 | Process: Word;
13 | Entry: Longint;
14 | IsForward : Boolean;
15 | Condact: Integer; // Condact number in the entry, if a SKIP label then -1, otherwise the number of Condact just after, so label befor first condact = 0
16 | end;
17 |
18 | VAR LabelList : array[0..MAX_LABELS-1] of TLabelData;
19 | VAR NextFreeLabelSlot : Longint;
20 |
21 | (* Adds a new Label and returns index if succcesful, otherwise (basically cause label already exists) returns false *)
22 | (* IsForward lets the system know the label is being added from a SKIP, so the Process/Entry values are false *)
23 | FUNCTION AddLabel(ALabel: AnsiString; AProcess: Longint; AEntry : Longint; IsForward: Boolean; ACondact: Integer):longint;
24 |
25 | (* Returns TLabelData value for the requested label, if it exists returns the Array index as function value , otherwise returns -1 and TLabelData returned is not valid *)
26 | FUNCTION GetLabelData(ALabel: AnsiString; var ALabelData:TLabelData): Longint;
27 |
28 | IMPLEMENTATION
29 |
30 | uses sysutils;
31 |
32 | FUNCTION AddLabel(ALabel: AnsiString; AProcess: Longint; AEntry : Longint; IsForward: Boolean; ACondact: Integer):longint;
33 | VAR i: Longint;
34 | BEGIN
35 | Result := -1;
36 | FOR i:= 0 to NextFreeLabelSlot - 1 DO
37 | IF(LabelList[i].SkipLabel = ALabel) THEN
38 | BEGIN
39 | IF (LabelList[i].IsForward and NOT IsForward) THEN // Time to update the data with real value
40 | BEGIN
41 | LabelList[i].Process := AProcess;
42 | LabelList[i].Entry := AEntry;
43 | LabelList[i].IsForward := false;
44 | LabelList[i].condact := ACondact;
45 | Result := i; Exit;
46 | END;
47 |
48 | IF (LabelList[i].IsForward and IsForward) THEN // One more forward reference
49 | BEGIN
50 | Result := i; Exit;
51 | END;
52 |
53 | Result := - 1; // Repeated non forward declaration
54 | Exit;
55 | END;
56 |
57 | // If we got here, the label is new
58 |
59 | // Let's first check if there is room for another one
60 | IF (NextFreeLabelSlot = MAX_LABELS) THEN
61 | BEGIN
62 | Result := i; Exit; // Too many labels
63 | END;
64 |
65 | // let's add a new one
66 |
67 | LabelList[NextFreeLabelSlot].SkipLabel := ALabel;
68 | LabelList[NextFreeLabelSlot].Process := AProcess;
69 | LabelList[NextFreeLabelSlot].Entry := AEntry;
70 | LabelList[NextFreeLabelSlot].IsForward := IsForward;
71 | LabelList[NextFreeLabelSlot].Condact := ACondact;
72 | Result := NextFreeLabelSlot;
73 | Inc(NextFreeLabelSlot);
74 | END;
75 |
76 | FUNCTION GetLabelData(ALabel: AnsiString; var ALabelData:TLabelData): Longint;
77 | VAR i : Longint;
78 | BEGIN
79 | Result := -1;
80 | FOR i := 0 to NextFreeLabelSlot -1 DO
81 | IF (LabelList[i].SkipLabel = ALabel) AND (NOT LabelList[i].IsForward) THEN
82 | BEGIN
83 | ALabelData.Process := LabelList[i].Process;
84 | ALabelData.Entry := LabelList[i].Entry;
85 | ALabelData.SkipLabel := ALabel;
86 | ALabelData.Condact := LabelList[i].Condact;
87 | ALabelData.isForward := LabelList[i].IsForward;
88 | Result := i;
89 | END;
90 | END;
91 |
92 | BEGIN
93 | NextFreeLabelSlot := 0;
94 | END.
--------------------------------------------------------------------------------
/src/ULexLib.pas:
--------------------------------------------------------------------------------
1 | {$I-}
2 |
3 | unit ULexLib;
4 |
5 | (* Standard Lex library unit for TP Lex Version 3.0.
6 | 2-11-91 AG *)
7 |
8 | (*
9 | Update by Uto Dev (utodev@gmail.com) in 2019 to provide support for AnsiStrings.
10 | The following text is here just for SEO reasons, hoping it can be easily found
11 | by others in my situation: AnsiString, Plex, long tokens, LongString, fpc,
12 | free pascal *)
13 |
14 | interface
15 |
16 | (* The Lex library unit supplies a collection of variables and routines
17 | needed by the lexical analyzer routine yylex and application programs
18 | using Lex-generated lexical analyzers. It also provides access to the
19 | input/output streams used by the lexical analyzer and the text of the
20 | matched string, and provides some utility functions which may be used
21 | in actions.
22 | This `standard' version of the LexLib unit is used to implement lexical
23 | analyzers which read from and write to MS-DOS files (using standard input
24 | and output, by default). It is suitable for many standard applications
25 | for lexical analyzers, such as text conversion tools or compilers.
26 | However, you may create your own version of the LexLib unit, tailored to
27 | your target applications. In particular, you may wish to provide another
28 | set of I/O functions, e.g., if you want to read from or write to memory
29 | instead to files, or want to use different file types. *)
30 |
31 | (* Variables:
32 | The variable yytext contains the current match, yyleng its length.
33 | The variable yyline contains the current input line, and yylineno and
34 | yycolno denote the current input position (line, column). These values
35 | are often used in giving error diagnostics (however, they will only be
36 | meaningful if there is no rescanning across line ends).
37 | The variables yyinput and yyoutput are the text files which are used
38 | by the lexical analyzer. By default, they are assigned to standard
39 | input and output, but you may change these assignments to fit your
40 | target application (use the Turbo Pascal standard routines assign,
41 | reset, and rewrite for this purpose). *)
42 |
43 | var
44 |
45 | yyinput, yyoutput : Text; (* input and output file *)
46 | yyline : AnsiString; (* current input line *)
47 | yylineno, yycolno : Integer; (* current input position *)
48 | yytext : AnsiString; (* matched text (should be considered r/o) *)
49 | yyleng : Word; (* length of matched text *)
50 |
51 | (* I/O routines:
52 | The following routines get_char, unget_char and put_char are used to
53 | implement access to the input and output files. Since \n (newline) for
54 | Lex means line end, the I/O routines have to translate MS-DOS line ends
55 | (carriage-return/line-feed) into newline characters and vice versa. Input
56 | is buffered to allow rescanning text (via unput_char).
57 | The input buffer holds the text of the line to be scanned. When the input
58 | buffer empties, a new line is obtained from the input stream. Characters
59 | can be returned to the input buffer by calls to unget_char. At end-of-
60 | file a null character is returned.
61 | The input routines also keep track of the input position and set the
62 | yyline, yylineno, yycolno variables accordingly.
63 | Since the rest of the Lex library only depends on these three routines
64 | (there are no direct references to the yyinput and yyoutput files or
65 | to the input buffer), you can easily replace get_char, unget_char and
66 | put_char by another suitable set of routines, e.g. if you want to read
67 | from/write to memory, etc. *)
68 |
69 | function get_char : Char;
70 | (* obtain one character from the input file (null character at end-of-
71 | file) *)
72 |
73 | procedure unget_char ( c : Char );
74 | (* return one character to the input file to be reread in subsequent calls
75 | to get_char *)
76 |
77 | procedure put_char ( c : Char );
78 | (* write one character to the output file *)
79 |
80 | (* Utility routines: *)
81 |
82 | procedure echo;
83 | (* echoes the current match to the output stream *)
84 |
85 | procedure yymore;
86 | (* append the next match to the current one *)
87 |
88 | procedure yyless ( n : Integer );
89 | (* truncate yytext to size n and return the remaining characters to the
90 | input stream *)
91 |
92 | procedure reject;
93 | (* reject the current match and execute the next one *)
94 |
95 | (* reject does not actually cause the input to be rescanned; instead,
96 | internal state information is used to find the next match. Hence
97 | you should not try to modify the input stream or the yytext variable
98 | when rejecting a match. *)
99 |
100 | procedure return ( n : Integer );
101 | procedure returnc ( c : Char );
102 | (* sets the return value of yylex *)
103 |
104 | procedure start ( state : Integer );
105 | (* puts the lexical analyzer in the given start state; state=0 denotes
106 | the default start state, other values are user-defined *)
107 |
108 | (* yywrap:
109 | The yywrap function is called by yylex at end-of-file (unless you have
110 | specified a rule matching end-of-file). You may redefine this routine
111 | in your Lex program to do application-dependent processing at end of
112 | file. In particular, yywrap may arrange for more input and return false
113 | in which case the yylex routine resumes lexical analysis. *)
114 |
115 | type
116 | yywrap_t = function (): Boolean;
117 | var
118 | yywrap: yywrap_t;
119 | (* The default yywrap routine supplied here closes input and output files
120 | and returns true (causing yylex to terminate). *)
121 |
122 | (* The following are the internal data structures and routines used by the
123 | lexical analyzer routine yylex; they should not be used directly. *)
124 |
125 | var
126 |
127 | yystate : Integer; (* current state of lexical analyzer *)
128 | yyactchar : Char; (* current character *)
129 | yylastchar : Char; (* last matched character (#0 if none) *)
130 | yyrule : Integer; (* matched rule *)
131 | yyreject : Boolean; (* current match rejected? *)
132 | yydone : Boolean; (* yylex return value set? *)
133 | yyretval : Integer; (* yylex return value *)
134 |
135 | procedure yynew;
136 | (* starts next match; initializes state information of the lexical
137 | analyzer *)
138 |
139 | procedure yyscan;
140 | (* gets next character from the input stream and updates yytext and
141 | yyactchar accordingly *)
142 |
143 | procedure yymark ( n : Integer );
144 | (* marks position for rule no. n *)
145 |
146 | procedure yymatch ( n : Integer );
147 | (* declares a match for rule number n *)
148 |
149 | function yyfind ( var n : Integer ) : Boolean;
150 | (* finds the last match and the corresponding marked position and adjusts
151 | the matched string accordingly; returns:
152 | - true if a rule has been matched, false otherwise
153 | - n: the number of the matched rule *)
154 |
155 | function yydefault : Boolean;
156 | (* executes the default action (copy character); returns true unless
157 | at end-of-file *)
158 |
159 | procedure yyclear;
160 | (* reinitializes state information after lexical analysis has been
161 | finished *)
162 |
163 | implementation
164 |
165 | procedure fatal ( msg : String );
166 | (* writes a fatal error message and halts program *)
167 | begin
168 | writeln('LexLib: ', msg);
169 | halt(1);
170 | end(*fatal*);
171 |
172 | (* I/O routines: *)
173 |
174 | const nl = #10; (* newline character *)
175 |
176 | const max_chars = 8192;
177 |
178 | var
179 |
180 | bufptr : Integer;
181 | buf : array [1..max_chars] of Char;
182 |
183 | function get_char : Char;
184 | var i : Integer;
185 | tmpStr : String;
186 | begin
187 | if (bufptr=0) and not eof(yyinput) then
188 | begin
189 | readln(yyinput, yyline);
190 | inc(yylineno);
191 | yycolno := 1;
192 | buf[1] := nl;
193 | for i := 1 to length(yyline) do
194 | begin
195 | tmpStr := copy(yyline,length(yyline)-i+1,1);
196 | buf[i+1] := tmpStr[1];
197 | end;
198 | inc(bufptr, length(yyline)+1);
199 | end;
200 | if bufptr>0 then
201 | begin
202 | get_char := buf[bufptr];
203 | dec(bufptr);
204 | inc(yycolno);
205 | end
206 | else
207 | get_char := #0;
208 | end(*get_char*);
209 |
210 | procedure unget_char ( c : Char );
211 | begin
212 | if bufptr=max_chars then fatal('input buffer overflow');
213 | inc(bufptr);
214 | dec(yycolno);
215 | buf[bufptr] := c;
216 | end(*unget_char*);
217 |
218 | procedure put_char ( c : Char );
219 | begin
220 | if c=#0 then
221 | { ignore }
222 | else if c=nl then
223 | writeln(yyoutput)
224 | else
225 | write(yyoutput, c)
226 | end(*put_char*);
227 |
228 | (* Variables:
229 | Some state information is maintained to keep track with calls to yymore,
230 | yyless, reject, start and yymatch/yymark, and to initialize state
231 | information used by the lexical analyzer.
232 | - yystext: contains the initial contents of the yytext variable; this
233 | will be the empty string, unless yymore is called which sets yystext
234 | to the current yytext
235 | - yysstate: start state of lexical analyzer (set to 0 during
236 | initialization, and modified in calls to the start routine)
237 | - yylstate: line state information (1 if at beginning of line, 0
238 | otherwise)
239 | - yystack: stack containing matched rules; yymatches contains the number of
240 | matches
241 | - yypos: for each rule the last marked position (yymark); zeroed when rule
242 | has already been considered
243 | - yysleng: copy of the original yyleng used to restore state information
244 | when reject is used *)
245 |
246 | const
247 |
248 | max_matches = 1024;
249 | max_rules = 256;
250 |
251 | var
252 |
253 | yystext : AnsiString;
254 | yysstate, yylstate : Integer;
255 | yymatches : Integer;
256 | yystack : array [1..max_matches] of Integer;
257 | yypos : array [1..max_rules] of Integer;
258 | yysleng : Word;
259 |
260 | (* Utilities: *)
261 |
262 | procedure echo;
263 | var i : Integer;
264 | tmpStr: String;
265 | begin
266 | for i := 1 to yyleng do
267 | begin
268 | tmpStr:=Copy(yytext, i, 1);
269 | put_char(tmpStr[1])
270 | end;
271 | end(*echo*);
272 |
273 | procedure yymore;
274 | begin
275 | yystext := yytext;
276 | end(*yymore*);
277 |
278 | procedure yyless ( n : Integer );
279 | var i : Integer;
280 | tmpStr: String;
281 | begin
282 | for i := yyleng downto n+1 do
283 | begin
284 | tmpStr:=Copy(yytext, i, 1);
285 | unget_char(tmpStr[1]);
286 | end;
287 | //yyleng := n;
288 | yytext := Copy(yytext, 1, n);
289 | end(*yyless*);
290 |
291 | procedure reject;
292 | var i : Integer;
293 | begin
294 | yyreject := true;
295 | for i := yyleng+1 to yysleng do
296 | yytext := yytext+get_char;
297 | yyleng := length(yytext);
298 | dec(yymatches);
299 | end(*reject*);
300 |
301 | procedure return ( n : Integer );
302 | begin
303 | yyretval := n;
304 | yydone := true;
305 | end(*return*);
306 |
307 | procedure returnc ( c : Char );
308 | begin
309 | yyretval := ord(c);
310 | yydone := true;
311 | end(*returnc*);
312 |
313 | procedure start ( state : Integer );
314 | begin
315 | yysstate := state;
316 | end(*start*);
317 |
318 | (* yywrap: *)
319 |
320 | function lexlib_yywrap : Boolean;
321 | begin
322 | close(yyinput);
323 | close(yyoutput);
324 | lexlib_yywrap := true;
325 | end(*yywrap*);
326 |
327 | (* Internal routines: *)
328 |
329 | procedure yynew;
330 | begin
331 | if yylastchar<>#0 then
332 | if yylastchar=nl then
333 | yylstate := 1
334 | else
335 | yylstate := 0;
336 | yystate := yysstate+yylstate;
337 | yytext := yystext;
338 | yyleng := length(yytext);
339 | yystext := '';
340 | yymatches := 0;
341 | yydone := false;
342 | end(*yynew*);
343 |
344 | procedure yyscan;
345 | begin
346 | if yyleng=max_chars then fatal('Lexer overflow, this usually means a line in your source file is too long');
347 | yyactchar := get_char;
348 | yytext := yytext + yyactchar;
349 | yyleng := length(yytext);
350 | end(*yyscan*);
351 |
352 | procedure yymark ( n : Integer );
353 | begin
354 | if n>max_rules then fatal('too many rules');
355 | yypos[n] := yyleng;
356 | end(*yymark*);
357 |
358 | procedure yymatch ( n : Integer );
359 | begin
360 | inc(yymatches);
361 | if yymatches>max_matches then fatal('match stack overflow');
362 | yystack[yymatches] := n;
363 | end(*yymatch*);
364 |
365 | function yyfind ( var n : Integer ) : Boolean;
366 | var tmpStr: String;
367 | begin
368 | yyreject := false;
369 | while (yymatches>0) and (yypos[yystack[yymatches]]=0) do
370 | dec(yymatches);
371 | if yymatches>0 then
372 | begin
373 | yysleng := yyleng;
374 | n := yystack[yymatches];
375 | yyless(yypos[n]);
376 | yypos[n] := 0;
377 | if yyleng>0 then
378 | begin
379 | tmpStr := copy(yytext, yyleng, 1);
380 | yylastchar := tmpStr[1]
381 | end
382 | else
383 | yylastchar := #0;
384 | yyfind := true;
385 | end
386 | else
387 | begin
388 | yyless(0);
389 | yylastchar := #0;
390 | yyfind := false;
391 | end
392 | end(*yyfind*);
393 |
394 | function yydefault : Boolean;
395 | begin
396 | yyreject := false;
397 | yyactchar := get_char;
398 | if yyactchar<>#0 then
399 | begin
400 | put_char(yyactchar);
401 | yydefault := true;
402 | end
403 | else
404 | begin
405 | yylstate := 1;
406 | yydefault := false;
407 | end;
408 | yylastchar := yyactchar;
409 | end(*yydefault*);
410 |
411 | procedure yyclear;
412 | begin
413 | bufptr := 0;
414 | yysstate := 0;
415 | yylstate := 1;
416 | yylastchar := #0;
417 | yytext := '';
418 | yyleng := 0;
419 | yystext := '';
420 | end(*yyclear*);
421 |
422 | begin
423 | yywrap := @lexlib_yywrap;
424 | assign(yyinput, '');
425 | assign(yyoutput, '');
426 | reset(yyinput); rewrite(yyoutput);
427 | yylineno := 0;
428 | yyclear;
429 | end(*LexLib*).
--------------------------------------------------------------------------------
/src/ULexTokens.pas:
--------------------------------------------------------------------------------
1 | UNIT ULexTokens;
2 |
3 | {$MODE OBJFPC}
4 |
5 | INTERFACE
6 |
7 | const T_SECTION_CON = 257;
8 | const T_SECTION_CTL = 258;
9 | const T_SECTION_STX = 259;
10 | const T_SECTION_MTX = 260;
11 | const T_SECTION_LTX = 261;
12 | const T_SECTION_OTX = 262;
13 | const T_SECTION_OBJ = 263;
14 | const T_SECTION_VOC = 264;
15 | const T_SECTION_PRO = 265;
16 | const T_DEFINE = 266;
17 | const T_STRING = 267;
18 | const T_UNDERSCORE = 268;
19 | const T_LIST_ENTRY = 269;
20 | const T_COMMENT = 270;
21 | const T_IDENTIFIER = 271;
22 | const T_INDIRECT = 272;
23 | const T_NUMBER = 273;
24 | const T_IFDEF = 274;
25 | const T_IFNDEF = 275;
26 | const T_ENDIF = 276;
27 | const T_SECTION_END = 277;
28 | const T_DB=278;
29 | const T_INCBIN=279;
30 | const T_EXTERN=280;
31 | const T_CLASSIC=281;
32 | const T_ELSE=282;
33 | const T_DW=283;
34 | const T_ECHO=284;
35 | const T_USERPTR=285;
36 | const T_INT=286;
37 | const T_SFX=287;
38 | const T_NOTHING=288;
39 | const T_HEX=289;
40 | const T_DEBUG=290;
41 | const T_PROCESS_ENTRY_SIGN=291;
42 | const T_LABEL = 292;
43 |
44 | IMPLEMENTATION
45 | END.
--------------------------------------------------------------------------------
/src/UMessageList.pas:
--------------------------------------------------------------------------------
1 | UNIT UMessageList;
2 |
3 | {$MODE OBJFPC}
4 |
5 | INTERFACE
6 |
7 | TYPE TPMessageList = ^TMessageList;
8 |
9 | TMessageList = record
10 | MessageID: Longint;
11 | Text : AnsiString ;
12 | Next : TPMessageList;
13 | end;
14 |
15 | var MTX, STX, LTX, OTX, XTX, MTX2, OtherTX : TPMessageList; // XTX is the message table for fake condact XMESSAGE
16 |
17 | MTX2Count, MTXCount, STXCount, LTXCount, OTXCount, XTXCount, OtherTXCount : Longint;
18 |
19 | FUNCTION insertMessageFromProcess(Var Opcode: Longint; AText : AnsiString; ClassicMode: Boolean ): Longint;
20 |
21 | FUNCTION insertMessageFromProcessIntoSpecificList(VAR AMessageList: TPMessageList; Var AText : AnsiString ): Longint;
22 |
23 | PROCEDURE AddMessage(VAR AMessageList:TPMessageList; AMessageID: Longint; AText: AnsiString);
24 |
25 | IMPLEMENTATION
26 |
27 |
28 | Uses UConstants;
29 |
30 | PROCEDURE AddMessage(VAR AMessageList:TPMessageList; AMessageID: Longint; AText: AnsiString);
31 | BEGIN
32 | IF AMessageList <> nil THEN AddMessage(AMessageList^.Next, AMessageID, AText)
33 | ELSE
34 | BEGIN
35 | New(AMessageList);
36 | AMessageList^.MessageID := AMessageID;
37 | AMessageList^.Text := AText;
38 | AMessageList^.Next := nil;
39 | END
40 | END;
41 |
42 |
43 | FUNCTION insertMessageFromProcessIntoSpecificList(VAR AMessageList: TPMessageList; Var AText : AnsiString ): Longint;
44 | VAR TmpMessageList : TPMessageList;
45 | LastMessageID : longint;
46 | BEGIN
47 | IF (AMessageList = nil) THEN
48 | BEGIN
49 | AddMessage(AMessageList, 0, AText);
50 | Result := 0;
51 | END
52 | ELSE
53 | BEGIN
54 | TmpMessageList := AMessageList;
55 | WHILE (TmpMessageList <> nil) DO
56 | BEGIN
57 | IF (AText = TmpMessageList^.Text) THEN
58 | BEGIN
59 | Result := TmpMessageList^.MessageID;
60 | exit;
61 | END;
62 | LastMessageID := TmpMessageList^.MessageID;
63 | TmpMessageList := TmpMessageList^.next;
64 | END;
65 | IF AMessageList <> XTX THEN // XTX has no limit by default
66 | IF LastMessageID = MAX_MESSAGES_PER_TABLE-1 THEN
67 | BEGIN
68 | Result := MAXLONGINT; // Return MAXLONGINT to signal error
69 | exit;
70 | END;
71 | AddMessage(AMessageList, LastMessageID + 1, AText);
72 | Result := LastMessageID + 1;
73 | END;
74 | END;
75 |
76 | FUNCTION insertMessageFromProcess(Var Opcode: Longint; AText : AnsiString; ClassicMode: Boolean ): Longint;
77 | VAR MessageID : Longint;
78 | BEGIN
79 | // First try to do it with the proper message list
80 | IF Opcode = SYSMESS_OPCODE THEN MessageID := insertMessageFromProcessIntoSpecificList(STX, AText)
81 | ELSE MessageID := insertMessageFromProcessIntoSpecificList(MTX, AText);
82 | if (MessageID nil THEN AddObject(AObjectList^.Next, AValue, ANoun, AnAdjective, AWeight, AnInitiallyAt, SomeFlags, AContainer, AWearable)
33 | ELSE
34 | BEGIN
35 | New(AObjectList);
36 | AObjectList^.Value := AValue;
37 | AObjectList^.InitialyAt := AnInitiallyAt;
38 | AObjectList^.Weight := AWeight;
39 | AObjectList^.Container := AContainer;
40 | AObjectList^.Wearable := AWearable;
41 | AObjectList^.Flags := SomeFlags;
42 | AObjectList^.Noun := ANoun;
43 | AObjectList^.Adjective := AnAdjective;
44 | AObjectList^.Next := nil;
45 | if (AnInitiallyAt = LOC_CARRIED) then Inc(CarriedObjects);
46 | if (AnInitiallyAt = LOC_WORN) then Inc(WornObjects);
47 | END
48 | END;
49 |
50 |
51 | FUNCTION FindObject(AObjectList:TPObjectList; ANoun, AnAdjective : Longint):boolean;
52 | BEGIN
53 | IF AObjectList = nil THEN Result := false
54 | ELSE
55 | IF (AObjectList^.Noun = ANoun) AND (AObjectList^.Adjective = AnAdjective) THEN Result := true
56 | ELSE Result := FindObject(AObjectList^.Next, ANoun, AnAdjective);
57 | END;
58 |
59 | BEGIN
60 | CarriedObjects := 0;
61 | WornObjects := 0;
62 | END.
--------------------------------------------------------------------------------
/src/UProcess.pas:
--------------------------------------------------------------------------------
1 | UNIT UProcess;
2 | {$MODE OBJFPC}
3 |
4 | INTERFACE
5 |
6 |
7 | USES UProcessCondactList, UConstants;
8 |
9 |
10 | TYPE TPProcessEntryList = ^TProcessEntryList;
11 |
12 | TProcessEntryList = RECORD
13 | Verb, Noun : Longint;
14 | SkipLabel: AnsiString;
15 | Condacts : TPProcessCondactList;
16 | Next : TPProcessEntryList;
17 | END;
18 |
19 | TProcess = RECORD
20 | Value : Longint;
21 | Entries : TPProcessEntryList
22 | END;
23 |
24 | VAR Processes : ARRAY [0..MAX_PROCESSES] OF TProcess;
25 | LastProcess : Longint;
26 |
27 | PROCEDURE InitializeProcesses();
28 |
29 | PROCEDURE AddProcessEntry(VAR AProcessEntryList:TPProcessEntryList; AVerb, ANoun : Longint; ACondacts : TPProcessCondactList);
30 |
31 | IMPLEMENTATION
32 |
33 | PROCEDURE InitializeProcesses();
34 | VAR i : integer;
35 | BEGIN
36 | FOR i:= 0 to MAX_PROCESSES DO
37 | BEGIN
38 | Processes[i].Value := i;
39 | Processes[i].Entries := nil;
40 | END;
41 | END;
42 |
43 | PROCEDURE AddProcessEntry(VAR AProcessEntryList:TPProcessEntryList; AVerb, ANoun : Longint; ACondacts : TPProcessCondactList);
44 | BEGIN
45 | IF AProcessEntryList <> nil THEN AddProcessEntry(AProcessEntryList^.Next, AVerb, ANoun, ACondacts)
46 | ELSE
47 | BEGIN
48 | New(AProcessEntryList);
49 | AProcessEntryList^.Verb := Averb;
50 | AProcessEntryList^.Noun := ANoun;
51 | AProcessEntryList^.Condacts := ACondacts;
52 | AProcessEntryList^.Next := nil;
53 | END
54 | END;
55 |
56 | END.
57 |
--------------------------------------------------------------------------------
/src/UProcessCondactList.pas:
--------------------------------------------------------------------------------
1 | UNIT UProcessCondactList;
2 | {$MODE OBJFPC}
3 |
4 | INTERFACE
5 |
6 | USES UConstants;
7 |
8 |
9 |
10 | TYPE TParam = RECORD
11 | Value : Longint;
12 | Indirection : boolean;
13 | END;
14 |
15 | TCondactParams = ARRAY [0 .. MAX_CONDACT_PARAMS - 1] OF TParam;
16 |
17 |
18 | TPProcessCondactList = ^TProcessCondactList;
19 |
20 | TProcessCondactList = RECORD
21 | Opcode: Longint;
22 | IsDB : boolean; // Fake condact coming from a #DB pseudo-opcode
23 | NumParams : Byte;
24 | Params : TCondactParams;
25 | Next : TPProcessCondactList;
26 | END;
27 |
28 |
29 | PROCEDURE AddProcessCondact(VAR AProcessCondactList:TPProcessCondactList; AOpcode: Longint; ANumParams: Byte; SomeParams: TCondactParams; IsDB: boolean);
30 |
31 | IMPLEMENTATION
32 |
33 | PROCEDURE AddProcessCondact(VAR AProcessCondactList:TPProcessCondactList; AOpcode: Longint; ANumParams: Byte; SomeParams: TCondactParams; IsDB: boolean);
34 | VAR i : integer;
35 | BEGIN
36 | IF AProcessCondactList <> nil THEN AddProcessCondact(AProcessCondactList^.Next, AOpcode, ANumParams, SomeParams, IsDB)
37 | ELSE
38 | BEGIN
39 | New(AProcessCondactList);
40 | AProcessCondactList^.Opcode := AOpcode;
41 | AProcessCondactList^.NumParams := ANumParams;
42 | AProcessCondactList^.IsDB := IsDB;
43 |
44 | FOR i:=0 TO MAX_CONDACT_PARAMS - 1 DO
45 | BEGIN
46 | AProcessCondactList^.Params[i].Value := SomeParams[i].Value;
47 | AProcessCondactList^.Params[i].Indirection := SomeParams[i].Indirection;
48 | END;
49 | AProcessCondactList^.Next := nil;
50 | END
51 | END;
52 |
53 |
54 |
55 | END.
--------------------------------------------------------------------------------
/src/USymbolList.pas:
--------------------------------------------------------------------------------
1 | UNIT USymbolList;
2 |
3 | {$MODE OBJFPC}
4 |
5 |
6 | INTERFACE
7 |
8 |
9 | TYPE TPSymbolList = ^TSymbolList;
10 |
11 | TSymbolList = record
12 | Symbol: AnsiString;
13 | Value: Longint;
14 | Next : TPSymbolList;
15 | end;
16 |
17 | VAR SymbolList : TPSymbolList;
18 |
19 | (* Adds a new symbol and returns true if succcesful, otherwise (basically cause symbol already exists) returns false *)
20 | FUNCTION AddSymbol(VAR ASymbolList: TPSymbolList; ASymbol: AnsiString; AValue : Longint):boolean;
21 |
22 | (* Returns the value of a Symbol or MAXLONGINT if it does not exist) *)
23 | FUNCTION GetSymbolValue(ASymbolList: TPSymbolList; ASymbol: AnsiString): Longint;
24 |
25 | IMPLEMENTATION
26 |
27 | uses sysutils, UConstants;
28 |
29 | FUNCTION AddSymbol(VAR ASymbolList: TPSymbolList; ASymbol: AnsiString; AValue : Longint):boolean;
30 | BEGIN
31 | ASymbol := AnsiUpperCase(ASymbol);
32 | if (ASymbolList = nil) THEN
33 | BEGIN
34 | New(ASymbolList);
35 | ASymbolList^.Symbol := ASymbol;
36 | ASymbolList^.Value := AValue;
37 | ASymbolList^.Next := nil;
38 | Result := true;
39 | IF Verbose AND (Copy(ASymbol, 1, 4)<>'_VOC') then WriteLn('Added Symbol: ', ASymbol, '=', Avalue);
40 | END
41 | ELSE
42 | BEGIN
43 | IF ASymbolList^.Symbol = AnsiUpperCase(ASymbol) THEN Result := false // Symbol duplicated
44 | ELSE Result := AddSymbol(ASymbolList^.Next, ASymbol, AValue);
45 | END;
46 | END;
47 |
48 | FUNCTION GetSymbolValue(ASymbolList: TPSymbolList; ASymbol: AnsiString): Longint;
49 | BEGIN
50 | ASymbol := AnsiUpperCase(ASymbol);
51 | IF (ASymbolList = nil) THEN Result:= MAXLONGINT
52 | ELSE IF ASymbolList^.Symbol = ASymbol THEN Result := ASymbolList^.Value
53 | ELSE Result := GetSymbolValue(ASymbolList^.Next, ASymbol);
54 | END;
55 |
56 | END.
--------------------------------------------------------------------------------
/src/UTokenList.pas:
--------------------------------------------------------------------------------
1 | UNIT UTokenList;
2 |
3 | {$MODE OBJFPC}
4 |
5 | INTERFACE
6 |
7 | TYPE TPTokenList = ^TTokenList;
8 |
9 | TTokenList = record
10 | TokenID: Word;
11 | Text : AnsiString ;
12 | IntVal : longint;
13 | lineno: Longint;
14 | colno : Word;
15 | Next : TPTokenList;
16 | Previous : TPTokenList;
17 | end;
18 |
19 | var TokenList : TPTokenList;
20 |
21 |
22 |
23 | PROCEDURE AddToken(VAR ATokenList:TPTokenList; ATokenID: Word; AText: AnsiString; AIntVal:longint; yylineno: longint; yycolno: word; APrevTokenList:TPTokenList=nil);
24 | FUNCTION normalize(S: AnsiString) :AnsiString;
25 | IMPLEMENTATION
26 | uses sysutils;
27 |
28 | FUNCTION normalize(S: AnsiString) :AnsiString;
29 | var i : integer;
30 |
31 | BEGIN
32 | Result :='';
33 | for i := 1 to length(S) DO
34 | BEGIN
35 | if (ord(s[i])>127) THEN Result := Result + '#' + IntToStr(ord(S[i])) ELSE Result := Result + S[i];
36 | END;
37 | END;
38 |
39 | PROCEDURE AddToken(VAR ATokenList:TPTokenList; ATokenID: Word; AText: AnsiString; AIntVal:longint; yylineno: longint; yycolno: word; APrevTokenList:TPTokenList=nil);
40 | BEGIN
41 | IF ATokenList <> nil THEN AddToken(ATokenList^.Next, ATokenID, AText, AIntVal, yylineno, yycolno, ATokenList)
42 | ELSE
43 | BEGIN
44 | New(ATokenList);
45 | ATokenList^.TokenID := ATokenID;
46 | ATokenList^.Text := AText;
47 | ATokenList^.IntVal := AIntVal;
48 | ATokenList^.lineno := yylineno;
49 | AtokenList^.colno := yycolno - 1;
50 | ATokenList^.Next := nil;
51 | ATokenList^.Previous := APrevTokenList;
52 | END
53 | END;
54 |
55 |
56 | END.
--------------------------------------------------------------------------------
/src/UVocabularyTree.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Utodev/DRC/c5665282bd66c3ee7424acd53fb92cce8a5ff37b/src/UVocabularyTree.pas
--------------------------------------------------------------------------------
/src/daadmaker.pas:
--------------------------------------------------------------------------------
1 | program daadmaker;
2 |
3 | uses sysutils,strutils;
4 |
5 | type TTapHeader = packed record
6 | BlockType : byte;
7 | BlockContent : byte;
8 | Filename : array[1..10] of char;
9 | LengthOfDataBlock: word;
10 | Parameter1: word;
11 | Parameter2: word;
12 | Checksum : byte;
13 | end;
14 |
15 | TTapHeaderRAW = packed array[0..18] of byte;
16 |
17 | TBigBuffer = array[0..65535] of byte;
18 |
19 | CONST SDGTMP = 'SDG.TMP';
20 |
21 | //This next two arrays are actually a TAP file, including a basic loader which includes or not a loading screen. It can be replaced by adding a second tap file in command line
22 | CONST BasicLoader : array[0..73] of byte =
23 | (19, 0, 0, 0, 68, 65, 65, 68, 32, 32, 32, 32, 32, 32, 49, 0, 10, 0, 49, 0, 10, 51, 0, 255, 0, 10, 10, 0, 253, 176, 34, 50, 52, 53, 55, 53, 34, 13, 0, 20,
24 | 16, 0, 32, 239, 34, 34, 175, 58, 239, 34, 34, 175, 58, 239, 34, 34, 175, 13, 0, 30, 11, 0, 249, 192, 176, 34, 50, 52, 53, 55, 54, 34, 13, 68);
25 |
26 | CONST BasicLoaderWithSCR : array[0..112] of byte =
27 | (19, 0, 0, 0, 68, 65, 65, 68, 32, 32, 32, 32, 32, 32, 88, 0, 10, 0, 88, 0, 10, 90, 0, 255, 0, 10, 27, 0, 253, 176, 34, 50, 52, 53, 55, 53, 34, 58, 244, 176,
28 | 34, 50, 51, 55, 51, 57, 34, 44, 176, 34, 49, 49, 49, 34, 13, 0, 20, 21, 0, 239, 34, 34, 175, 58, 32, 239, 34, 34, 175, 58, 239, 34, 34, 175, 58, 239, 34, 34, 175, 13,
29 | 0, 30, 28, 0, 244, 176, 34, 50, 51, 55, 51, 57, 34, 44, 176, 34, 50, 52, 52, 34, 58, 249, 192, 176, 34, 50, 52, 53, 55, 54, 34, 13, 62);
30 |
31 | // This is the default SDF file, in case is not provided, can always be replaced with another
32 | CONST EmptyGraphics : array[0..2088] of byte =
33 | (7, 215, 247, 216, 247, 255, 255, 7, 0, 0, 12, 42, 255, 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,
34 | 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,
35 | 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,
36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 80, 48, 0, 112, 0, 0, 32, 0, 32, 32, 32, 32, 32, 0, 32, 0, 32,
37 | 64, 136, 136, 112, 0, 0, 0, 40, 80, 160, 80, 40, 0, 0, 0, 160, 80, 40, 80, 160, 0, 32, 64, 0, 104, 152, 152, 104, 0, 16, 32, 112, 136, 248, 128, 120, 0, 16, 32, 0,
38 | 96, 32, 32, 112, 0, 16, 32, 0, 112, 136, 136, 112, 0, 16, 32, 0, 136, 136, 136, 112, 0, 40, 80, 0, 176, 200, 136, 136, 0, 40, 80, 136, 200, 168, 152, 136, 0, 0, 112, 136,
39 | 128, 136, 112, 32, 64, 112, 136, 128, 128, 136, 112, 32, 64, 0, 80, 0, 136, 136, 136, 112, 0, 80, 0, 136, 136, 136, 136, 112, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 32, 32,
40 | 32, 32, 0, 32, 0, 80, 80, 0, 0, 0, 0, 0, 0, 80, 248, 80, 80, 80, 248, 80, 0, 32, 248, 160, 248, 40, 248, 32, 0, 200, 200, 16, 32, 64, 152, 152, 0, 32, 80, 32,
41 | 96, 152, 144, 104, 0, 32, 64, 0, 0, 0, 0, 0, 0, 8, 16, 16, 16, 16, 16, 8, 0, 64, 32, 32, 32, 32, 32, 64, 0, 168, 168, 112, 248, 112, 168, 168, 0, 0, 32, 32,
42 | 248, 32, 32, 0, 0, 0, 0, 0, 0, 0, 16, 16, 32, 0, 0, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 48, 0, 8, 8, 16, 32, 64, 128, 128, 0, 112, 152, 152,
43 | 168, 200, 200, 112, 0, 32, 96, 32, 32, 32, 32, 112, 0, 112, 136, 8, 112, 128, 128, 248, 0, 112, 136, 8, 48, 8, 136, 112, 0, 16, 48, 80, 144, 248, 16, 16, 0, 248, 128, 128,
44 | 240, 8, 136, 112, 0, 112, 136, 128, 240, 136, 136, 112, 0, 248, 8, 8, 16, 16, 32, 32, 0, 112, 136, 136, 112, 136, 136, 112, 0, 112, 136, 136, 120, 8, 136, 112, 0, 0, 0, 32,
45 | 0, 0, 32, 0, 0, 0, 0, 32, 0, 0, 32, 32, 64, 0, 8, 16, 32, 32, 16, 8, 0, 0, 0, 0, 120, 0, 120, 0, 0, 0, 64, 32, 16, 16, 32, 64, 0, 112, 136, 136,
46 | 16, 32, 0, 32, 0, 0, 112, 136, 168, 184, 128, 112, 0, 112, 136, 136, 248, 136, 136, 136, 0, 240, 136, 136, 240, 136, 136, 240, 0, 112, 136, 128, 128, 128, 136, 112, 0, 240, 136, 136,
47 | 136, 136, 136, 240, 0, 248, 128, 128, 240, 128, 128, 248, 0, 248, 128, 128, 240, 128, 128, 128, 0, 112, 136, 128, 128, 152, 136, 112, 0, 136, 136, 136, 248, 136, 136, 136, 0, 112, 32, 32,
48 | 32, 32, 32, 112, 0, 8, 8, 8, 8, 8, 136, 112, 0, 136, 144, 160, 192, 160, 144, 136, 0, 128, 128, 128, 128, 128, 128, 248, 0, 136, 216, 168, 136, 136, 136, 136, 0, 136, 136, 200,
49 | 168, 152, 136, 136, 0, 112, 136, 136, 136, 136, 136, 112, 0, 240, 136, 136, 240, 128, 128, 128, 0, 112, 136, 136, 136, 168, 152, 120, 0, 240, 136, 136, 240, 144, 136, 136, 0, 112, 136, 128,
50 | 112, 8, 136, 112, 0, 248, 32, 32, 32, 32, 32, 32, 0, 136, 136, 136, 136, 136, 136, 112, 0, 136, 136, 136, 136, 136, 80, 32, 0, 136, 136, 136, 136, 168, 168, 80, 0, 136, 136, 80,
51 | 32, 80, 136, 136, 0, 136, 136, 80, 32, 32, 32, 32, 0, 248, 8, 16, 32, 64, 128, 248, 0, 56, 32, 32, 32, 32, 32, 56, 0, 128, 128, 64, 32, 16, 8, 8, 0, 112, 16, 16,
52 | 16, 16, 16, 112, 0, 32, 112, 168, 32, 32, 32, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 72, 64, 240, 64, 64, 248, 0, 0, 0, 104, 152, 136, 152, 104, 0, 128, 128, 176,
53 | 200, 136, 200, 176, 0, 0, 0, 112, 136, 128, 136, 112, 0, 8, 8, 104, 152, 136, 152, 104, 0, 0, 0, 112, 136, 240, 128, 120, 0, 48, 72, 64, 96, 64, 64, 64, 0, 0, 0, 112,
54 | 136, 136, 120, 8, 112, 128, 128, 176, 200, 136, 136, 136, 0, 32, 0, 96, 32, 32, 32, 112, 0, 16, 0, 16, 16, 16, 144, 96, 0, 128, 128, 128, 160, 192, 160, 144, 0, 64, 64, 64,
55 | 64, 64, 64, 48, 0, 0, 0, 208, 168, 168, 168, 168, 0, 0, 0, 176, 200, 136, 136, 136, 0, 0, 0, 112, 136, 136, 136, 112, 0, 0, 0, 176, 200, 136, 240, 128, 128, 0, 0, 104,
56 | 152, 136, 120, 8, 12, 0, 0, 176, 64, 64, 64, 64, 0, 0, 0, 112, 128, 112, 8, 240, 0, 0, 64, 224, 64, 64, 64, 48, 0, 0, 0, 136, 136, 136, 136, 112, 0, 0, 0, 136,
57 | 136, 80, 80, 32, 0, 0, 0, 136, 168, 168, 168, 80, 0, 0, 0, 136, 80, 32, 80, 136, 0, 0, 0, 136, 136, 152, 104, 8, 112, 0, 0, 248, 16, 32, 64, 248, 0, 24, 32, 32,
58 | 64, 32, 32, 24, 0, 16, 16, 16, 16, 16, 16, 16, 0, 96, 16, 16, 8, 16, 16, 96, 0, 0, 40, 80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 196, 170, 174,
59 | 202, 38, 85, 117, 86, 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,
60 | 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,
61 | 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,
62 | 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,
63 | 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,
64 | 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,
65 | 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,
66 | 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,
67 | 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,
68 | 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,
69 | 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,
70 | 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,
71 | 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,
72 | 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,
73 | 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,
74 | 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,
75 | 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,
76 | 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,
77 | 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,
78 | 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,
79 | 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,
80 | 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,
81 | 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,
82 | 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,
83 | 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,
84 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 2, 3, 4, 5, 6, 1, 205, 152, 215, 247, 216, 247, 222, 247, 227, 247,
85 | 228, 247, 228, 255, 255, 255, 1, 0, 0);
86 |
87 | CONST version_hi = 0;
88 | version_lo = 5;
89 |
90 | var Buffer: TBigBuffer;
91 | TAPFilename, DDBFilename, SDGFilename, INTFilename, SCRFilename, LoaderFilename, CHRFilename : string;
92 | FileTAP, FileDDB, FileSDG, FileSCR, FileINT, FileLoader, FileCHR : file;
93 | SDGAddress : word;
94 | GameName : ShortString;
95 | AuxStr : ShortString;
96 | i : integer;
97 |
98 | procedure SYNTAX();
99 | begin
100 | WriteLn('DAADMAKER ' , version_hi, '.', version_lo);
101 | Writeln('Creates ZX Spectrum TAP files from DAAD DDB file and database');
102 | Writeln('Syntax:');
103 | WriteLn('daadmaker [SDG file] [SCR file] [CHR file] [loader file]');
104 | WriteLn();
105 | WriteLn(' : output TAP file');
106 | WriteLn(' : ZX Spectrum interpreter file');
107 | WriteLn(' : input DDB file');
108 | WriteLn('[SDG file] : input SDG file (optional)');
109 | WriteLn('[SCR file] : input SCR file (optional)');
110 | WriteLn('[CHR file] : input CHR file (optional)');
111 | WriteLn('[loader file] : alternative basic loader, already in tap format (optional)');
112 | WriteLn();
113 | WriteLn('Please notice parameters after third one will be identified by file extension, depending on if it''s SDG, SCR, CHR or TAP. A CHR file is a 2048 bytes file with the definition of a charset (o bytes per character, 256 characters).');
114 | halt(1);
115 | end;
116 |
117 | function ExtractFileNameWithoutExt(Filenametouse:ShortString):ShortString;
118 | begin
119 | ExtractFileNameWithoutExt := extractfilename(copy(Filenametouse,1,rpos(ExtractFileExt(Filenametouse),Filenametouse)-1));
120 | end;
121 |
122 | procedure Error(S:String);
123 | begin
124 | WriteLn('Error: ',S,'.');
125 | halt(2);
126 | end;
127 |
128 |
129 | procedure SaveBlockFromBuffer(Blockname: ShortString; var Foutput: file; var buffer: TBigBuffer; Offset: Word; size: word; Address: word);
130 | var header: TTapHeader;
131 | blockLength : word;
132 | i : word;
133 | checksum : byte;
134 | aByte : byte;
135 | begin
136 | // Save the header
137 | BlockLength:=19;
138 | Blockwrite(Foutput, BlockLength,2);
139 | header.BlockType := 0; // it's a header
140 | header.BlockContent := 3; // it's CODE block
141 | for i := 1 to 10 do header.filename[i] := Blockname[i];
142 | header.LengthOfDataBlock := size;
143 | header.Parameter1 := Address; // Load address
144 | header.Parameter2 := 32768; // All code blocks have this as Param2
145 | //Calculate the checksum of header
146 | checksum := 0;
147 | for i:= 0 to 17 do checksum := checksum XOR (TTapHeaderRAW(header))[i];
148 | header.checksum := checksum;
149 | BlockWrite(Foutput, header, 19);
150 | // Save the data
151 | BlockLength := Size+2;
152 | Blockwrite(Foutput, BlockLength,2);
153 | aByte := $FF; // It's data block
154 | Blockwrite(Foutput, aByte,1);
155 | Blockwrite(Foutput, buffer, size);
156 | checksum := $FF; // The flag is included in checksum, so we start with the FF flag
157 | for i:= 0 to Size -1 do checksum := checksum xor buffer[i];
158 | Blockwrite(Foutput, checksum,1);
159 |
160 | end;
161 |
162 | procedure SaveBlockFromFile(Blockname: ShortString; var Foutput: file;var Finput: file; Address: word);
163 | VAR P3Str: ShortString;
164 | i: integer;
165 | hasPlus3Header: boolean;
166 | Start, Length: Word;
167 | begin
168 | Blockread(Finput, Buffer, filesize(Finput));
169 |
170 | // Check and skip PLUS3 header if present
171 | P3Str := 'PLUS3DOS';
172 | Start := 0;
173 | Length := filesize(Finput);
174 | hasPlus3Header := true;
175 | for i:= 1 to 8 DO
176 | if char(Buffer[i-1]) <> P3STR[i] then hasPlus3Header := false;
177 | if hasPlus3Header then
178 | begin
179 | Start := 128;
180 | Length := Length - 128;
181 | end;
182 | // Save block
183 | SaveBlockFromBuffer(Blockname,Foutput, Buffer, Start, Length, Address);
184 | end;
185 |
186 | procedure SaveLoader(var Foutput: file; GameName : String; withScreen: boolean );
187 | var checksum : byte;
188 | headerSize : word;
189 | begin
190 | if (withScreen) then begin
191 | headerSize := sizeof(BasicLoaderWithSCR);
192 | Move(BasicLoaderWithSCR, Buffer, headerSize);
193 | end
194 | else begin
195 | headerSize := sizeof(BasicLoader);
196 | Move(BasicLoader, Buffer, headerSize);
197 | end;
198 | for i := 1 to 10 do Buffer[i+3] := Ord(GameName[i]);
199 | checksum := 0;
200 | for i:= 3 to 19 do checksum := checksum xor Buffer[i];
201 | Buffer[20] := checksum;
202 | BlockWrite(Foutput, buffer, headerSize);
203 | end;
204 |
205 |
206 | begin
207 | if (ParamCount<3) then Syntax();
208 | TAPFilename := ParamStr(1);
209 | INTFilename := ParamStr(2);
210 | DDBFilename := ParamStr(3);
211 |
212 | if not FileExists(DDBFilename) then Error('DDB file not found');
213 | if not FileExists(INTFilename) then Error('Interpreter file not found');
214 | SDGFilename := '';
215 | SCRFilename := '';
216 | LoaderFilename := '';
217 | CHRFilename := '';
218 | for i := 4 to ParamCount() do
219 | begin
220 | AuxStr := ParamStr(i);
221 | if not FileExists(AuxStr) then Error(AuxStr + ' not found');
222 | if UpperCase(ExtractFileExt(AuxStr)) = '.SCR' then SCRFilename := AuxStr else
223 | if UpperCase(ExtractFileExt(AuxStr)) = '.TAP' then LoaderFilename := AuxStr else
224 | if UpperCase(ExtractFileExt(AuxStr)) = '.CHR' then CHRFilename := AuxStr else
225 | if UpperCase(ExtractFileExt(AuxStr)) = '.SDG' then SDGFilename := AuxStr else Error('Invalid extension '+UpperCase(ExtractFileExt(AuxStr))+', must be either SCR, TAP or SDG');
226 | end;
227 |
228 | if SDGFilename = '' then
229 | begin // No SDG file, create a fake one
230 | SDGFilename := SDGTMP;
231 | Assign(FileSDG, SDGFilename);
232 | Rewrite(FileSDG, 1);
233 | BlockWrite(FileSDG, EmptyGraphics, sizeof(EmptyGraphics));
234 | Close(FileSDG);
235 | end;
236 |
237 | GameName := UpperCase(ExtractFileNameWithoutExt(TAPFilename)) + ' ';
238 | if (length(GameName)>10) then GameName := Copy(GameName, 1, 10);
239 |
240 | Assign(FileTAP, TAPFilename);
241 | Rewrite(FileTAP,1);
242 | Assign(FileDDB, DDBFilename);
243 | Reset(FileDDB,1);
244 | Assign(FileSDG, SDGFilename);
245 | Reset(FileSDG,1);
246 | Assign(FileINT, INTFilename);
247 | Reset(FileINT, 1);
248 | IF CHRFilename<>'' THEN
249 | BEGIN
250 | Assign(FileCHR, CHRFilename);
251 | Reset(FileCHR, 1);
252 | END;
253 |
254 | // Export the basic loader. There are three options: custom one, loader without SCREEN$ and loader with SCREEN$
255 | IF LoaderFilename<>''then // Custom loader
256 | begin
257 | Assign(FileLoader, LoaderFilename);
258 | Reset(FileLoader, 1);
259 | Blockread(FileLoader, Buffer, filesize(FileLoader));
260 | BlockWrite(FileTap, Buffer, filesize(FileLoader));
261 | Close(FileLoader);
262 | end
263 | else
264 | begin
265 | if (SCRFilename='') then SaveLoader(FileTAP, GameName, false) // Loader without SCREEN$
266 | else SaveLoader(FileTAP, GameName, true); // Loader with SCREEN$
267 | end;
268 | IF (SCRFilename<>'') then
269 | begin
270 | //Save SCREEN$
271 | Assign(FileSCR, SCRFilename);
272 | Reset(FileSCR,1);
273 | if (filesize(FileSCR)<>6912) THEN Error('Invalid SCREEN$ file, size must be 6912 bytes');
274 | GameName[10] := 'S';
275 | SaveBlockFromFile(GameName,FileTAP, FileSCR, 16384);
276 | Close(FileSCR);
277 | end;
278 | // Save the interpreter
279 | GameName[10] := 'I';
280 | SaveBlockFromFile(GameName,FileTAP, FileINT, 24576);
281 | if (filesize(fileDDB)+ $8400 > $FFFF) then Error('DDB exceedes RAM size');
282 | // Save the DDB
283 | GameName[10] := 'D';
284 | SaveBlockFromFile(GameName,FileTAP, FileDDB, $8400);
285 | // Save the SDG
286 | SDGAddress := $FFFF - filesize(FileSDG) +1;
287 | if (filesize(fileDDB)+ $8400 > SDGAddress) then Error('DDB + SDG exceed RAM size');
288 | GameName[10] := 'G';
289 | Blockread(FileSDG, Buffer, filesize(FileSDG));
290 | IF CHRFilename<>'' THEN
291 | BEGIN
292 | IF (FileSize(FileCHR)<>2048) AND (FileSize(FileCHR)<>2048+128) THEN Error('Invalid CHR file. Must be 2048 bytes long.');
293 | IF (FileSize(FileCHR)=2048+128) THEN Seek(FileCHR, 128);
294 | Blockread(FileCHR,Buffer[FileSize(FileSDG)-2076], 2048);
295 | END;
296 | SaveBlockFromBuffer(Gamename, FileTAP, Buffer, 0, filesize(FileSDG), SDGAddress);
297 |
298 |
299 | Close(FileTap);
300 | Close(FileINT);
301 | Close(FileDDB);
302 | Close(FileSDG);
303 | IF CHRFilename<>'' THEN Close(FileCHR);
304 | IF (SDGFilename=SDGTMP) then Erase(FileSDG);
305 | WriteLn('File ', TAPFilename, ' created.');
306 | end.
307 |
--------------------------------------------------------------------------------
/src/drf.pas:
--------------------------------------------------------------------------------
1 | // (C) Uto 2019 - This code is released under the GPL v3 license
2 |
3 | PROGRAM DRC;
4 | {$MODE OBJFPC}
5 | {$I-}
6 |
7 |
8 | uses strutils, sysutils, ULexTokens, ULexLib, UTokenList, USintactic, UConstants, USymbolList, UCodeGeneration, UCondacts, UInclude, Dateutils;
9 |
10 |
11 | PROCEDURE SYNTAX();
12 | VAR AppName :String;
13 | BEGIN
14 | AppName := ChangeFileExt(ExtractFileName(ParamStr(0)),'');
15 | WriteLn('Syntax: ', AppName, ' [subtarget] [output.json] [options] [additional symbols]');
16 | WriteLn();
17 | WriteLn('file.DSF is a DAAD', ' ', version_hi, '.', version_lo, ' source file.');
18 | WriteLn();
19 | WriteLn(' is the target machine, one of this list: ZX, CPC, C64, CP4, MSX, MSX2, PCW, PC, AMIGA, ST or HTML. The target machine will be added as if there were a ''#define '' in the code, so you can make the code depend on target platform. Just to clarify, CP4 stands for Commodore Plus/4');
20 | WriteLn();
21 | WriteLn('[subtarget] is an parameter only required when the target is ZX, MSX2 or PC. Will define the internal variable COLS, which can later be used in DAAD processes.');
22 | Writeln('For MSX2 values are a compound value of video mode (from mode 5 to 12, except 9 and 11) and the with of the charset im pixels, which can be 6 or 8. Example: 5_8, 10_8, 12_6, 7_6, etc.');
23 | WriteLn('For PC values can be VGA256, VGA, EGA, CGA or TEXT.');
24 | WriteLn('For ZX the values can be PLUS3, ESXDOS, UNO or NEXT.');
25 | WriteLn('Please notice subtarget for ZX is only relevant if you use Maluva, if you don''t use it or you don''t know what it is, choose any of the targets, i.e. plus3');
26 | WriteLn();
27 | WriteLn('[output.json] is optional file name for output json file, if missing, '+AppName+' will just use same name of input file, but with .json extension.');
28 | WriteLn();
29 | WriteLn('[options] may be or more of the following:');
30 | WriteLn(' -verbose: verbose output');
31 | WriteLn(' -no-semantic: DRF won''t make a semantic analysis so condacts like MESSAGE x where message #x does not exist will be ignored.');
32 | WriteLn(' -semantic-warnings: DRF will just show semantic errors as warnings, but won''t stop compilation');
33 | WriteLn(' -force-normal-messages: all xmessages will be treated as normal messages');
34 | WriteLn(' -force-x-messages: all user messages will be created as xmessages. Does not affect those written in the MTX table.');
35 | WriteLn(' -check-maluva-disabled: the compiler won''t check if Maluva was included when finding Maluva condacts.');
36 | WriteLn(' -replace-xcondacts: replace XSAVE, XPICTURE, XLOAD and XLOAD condacts with the original ones if the target does not support them. This does not affect XMES and XMESSAGE.');
37 | WriteLn(' -v3: compile for DAAD version 3.');
38 | WriteLn();
39 | WriteLn('[additional symbols] is an optional comma separated list of other symbols that would be created, so for instance if that parameter is "p3", then #ifdef "p3" will be true, and if that parameter is "p3,p4" then also #ifdef "p4" would be true.');
40 | Halt(1);
41 | END;
42 |
43 | PROCEDURE yyerror(Msg : String);
44 | BEGIN
45 | WriteLn(yylineno,':',yycolno, ': ', msg,'.');
46 | END;
47 |
48 | PROCEDURE ParamError(Msg : String);
49 | BEGIN
50 | WriteLn(Msg, '.');
51 | Halt(2);
52 | END;
53 |
54 | PROCEDURE PreparseError(Msg: String; CurrentLine: longint);
55 | BEGIN
56 | WriteLn(Currentline,':0: ', Msg,'.');
57 | Halt(2);
58 | END;
59 |
60 | FUNCTION getMSX2ColsBySubtarget(SubTarget:AnsiString):Byte;
61 | BEGIN
62 | IF Subtarget = '5_6' THEN Result := 42 ELSE
63 | IF Subtarget = '5_8' THEN Result := 32 ELSE
64 | IF Subtarget = '6_6' THEN Result := 85 ELSE
65 | IF Subtarget = '6_8' THEN Result := 64 ELSE
66 | IF Subtarget = '7_6' THEN Result := 85 ELSE
67 | IF Subtarget = '7_8' THEN Result := 64 ELSE
68 | IF Subtarget = '8_6' THEN Result := 42 ELSE
69 | IF Subtarget = '8_8' THEN Result := 32 ELSE
70 | IF Subtarget = '10_6' THEN Result := 42 ELSE
71 | IF Subtarget = '10_8' THEN Result := 32 ELSE
72 | IF Subtarget = '12_6' THEN Result := 42 ELSE
73 | IF Subtarget = '12_8' THEN Result := 32
74 | ELSE Result :=42; // Conservative
75 | END;
76 |
77 | FUNCTION getPCColsBySubtarget(SubTarget:AnsiString):Byte;
78 | BEGIN
79 | IF Subtarget = 'TEXT' THEN Result := 80
80 | ELSE IF Subtarget = 'VGA256' THEN Result := 40
81 | ELSE Result :=53; // Conservative
82 | END;
83 |
84 | FUNCTION CheckEND(Filename: String):Boolean;
85 | VAR T: TEXT;
86 | S: WideString;
87 | Found : Boolean;
88 | BEGIN
89 | Assign(T, Filename);
90 | Reset(T);
91 | Found := false;
92 | WHILE (NOT EOF(T)) AND (NOT Found)
93 | DO
94 | BEGIN
95 | ReadLn(T, S);
96 | S := Trim(S);
97 | IF (S='/END') THEN Found := True;
98 | END;
99 | Close(T);
100 | Result := Found;
101 | END;
102 |
103 |
104 | FUNCTION getColsByTarget(Target:String;SubTarget:AnsiString):Byte;
105 | BEGIN
106 | IF Target = 'PC' THEN Result := getPCColsBySubtarget(SubTarget) ELSE
107 | IF Target = 'ZX' THEN Result := 42 ELSE
108 | IF Target = 'C64' THEN Result := 40 ELSE
109 | IF Target = 'CP4' THEN Result := 40 ELSE
110 | IF Target = 'CPC' THEN Result := 40 ELSE
111 | IF Target = 'HTML' THEN Result := 40 ELSE
112 | IF Target = 'MSX' THEN Result := 42 ELSE
113 | IF Target = 'MSX2' THEN Result := getMSX2ColsBySubtarget(SubTarget) ELSE
114 | IF Target = 'ST' THEN Result := 53 ELSE
115 | IF Target = 'AMIGA' THEN Result := 53 ELSE
116 | IF Target = 'PCW' THEN Result := 90
117 | ELSE Result :=42; // Conservative
118 | END;
119 |
120 | FUNCTION GetRowsByTarget(Target:String):Byte;
121 | BEGIN
122 | IF Target = 'PCW' THEN Result := 32 ELSE
123 | IF Target = 'MSX2' THEN Result := 26 ELSE Result := 25;
124 | END;
125 |
126 | FUNCTION targetUsesDstringsGraphics(Target:AnsiString): Boolean;
127 | BEGIN
128 | Result := (Target='ZX') OR (Target='CPC') OR (Target='C64') OR (Target='CP4') OR (Target='MSX');
129 | END;
130 |
131 | // Global vars
132 |
133 | VAR Target, SubTarget: AnsiString;
134 | OutputFileName, InputFileName : String;
135 | AdditionalSymbols : String;
136 | AuxString : String;
137 | AppName : String;
138 | NextParam : Byte;
139 |
140 | {$i lexer.pas}
141 |
142 | // Replaces includes and makes some fixes, also starts the reference between tempfile lines and include files and lines
143 | PROCEDURE Preparse(InputFileName, TempFileName:AnsiString);
144 | VAR InputFile, IncludeFile, TempFile : Text;
145 | Line: AnsiString;
146 | IncludeFileName : AnsiString;
147 | TempLine, PreserveCurrentLine, CurrentLine : Longint;
148 | IncludeData : TIncludeData;
149 |
150 | BEGIN
151 | AssignFile(InputFile, InputFileName);
152 | Reset(InputFile);
153 | AssignFile(TempFile, TempFileName);
154 | Rewrite(TempFile);
155 | CurrentLine := 0;
156 | TempLine := 0;
157 | while not eof(InputFile) do
158 | begin
159 | ReadLn(InputFile, Line);
160 | CurrentLine := CurrentLine + 1;
161 | if (Copy(Line, 1, 8)='#include') then
162 | begin
163 | IncludeFileName := Copy(Line,10,MaxInt);
164 | if (pos(';', IncludeFileName)>0) THEN IncludeFileName := Copy(IncludeFileName, 1, Pos(';',IncludeFileName)-1);
165 | IncludeFileName := Trim(IncludeFileName);
166 | if (not FileExists(IncludeFileName)) then PreparseError('Include file "'+IncludeFileName+'" not found', CurrentLine );
167 | if Verbose THEN Writeln('Including ', IncludeFileName, '...');
168 | AssignFile(IncludeFile, IncludeFileName);
169 | Reset(IncludeFile);
170 | PreserveCurrentLine := CurrentLine;
171 | CurrentLine := 0;
172 | WHILE NOT EOF(IncludeFile) do
173 | begin
174 | ReadLn(IncludeFile, Line);
175 | CurrentLine := CurrentLine + 1;
176 | if (Copy(Line, 1, 8)='#include') then PreparseError('Nested includes are not allowed', CurrentLine);
177 | WriteLn(TempFile, Line);
178 | TempLine := TempLine + 1;
179 | IncludeData.originalFileName := IncludeFileName;
180 | IncludeData.OriginalLine := CurrentLine;
181 | AddLine(TempLine, IncludeData);
182 | end;
183 | Close(IncludeFile);
184 | CurrentLine := PreserveCurrentLine;
185 | end
186 | else
187 | begin
188 | WriteLn(TempFile, Line);
189 | TempLine := TempLine + 1;
190 | IncludeData.originalFileName := InputFileName;
191 | IncludeData.OriginalLine := CurrentLine;
192 | AddLine(TempLine, IncludeData);
193 | end;
194 | end;
195 | Close(InputFile);
196 | Close(TempFile);
197 | END;
198 |
199 |
200 | PROCEDURE CompileForTarget(Target: AnsiString; Subtarget: AnsiString; OutputFileName: String; AdditionalSymbols: String);
201 | var machine : AnsiString;
202 | cols: byte;
203 | i :byte;
204 | TempFileName: AnsiString;
205 | BEGIN
206 | IF Verbose THEN
207 | BEGIN
208 | Write('Target: ', target);
209 | IF SubTarget<>'' THEN Write(' | Subtarget:', subtarget);
210 | WriteLn;
211 | END;
212 | Writeln('Reading ' + InputFileName);
213 | TempFileName := ChangeFileExt(InputFileName, '.___');
214 | Preparse(InputFileName, TempFileName);
215 | AssignFile(yyinput, TempFileName);
216 | Reset(yyinput);
217 | TokenList := nil;
218 | // This is a fake token we add, although it will be never loaded. Everytime Scan() is called, it goes to "next" so first time this fake one will be skipped.
219 | AddToken(TokenList, T_NOTHING, '', 0, 0, 0);
220 | // Parses whole file into TokenList
221 | yylex();
222 | // Create some useful built-in symbols
223 | // The target
224 | AddSymbol(SymbolList, Target, 1);
225 | if (SubTarget<>'') THEN
226 | BEGIN
227 | AddSymbol(SymbolList, 'MODE_'+Subtarget, 1);
228 | AddSymbol(SymbolList, Subtarget, 1);
229 | END;
230 | machine :=AnsiUpperCase(Target);
231 | // The target superset BIT8 or BIT16
232 | if (machine='ZX') OR (machine='CPC') OR (machine='PCW') OR (machine='MSX') OR (machine='C64') OR (machine='CP4') or (MACHINE='MSX2') THEN AddSymbol(SymbolList, 'BIT8', 1);
233 | if (machine='PC') OR (machine='AMIGA') OR (machine='ST') THEN AddSymbol(SymbolList, 'BIT16', 1);
234 | // Please notice HTML target adds neither BIT8 nor BIT16 symbols.
235 | // add COLS Symbol
236 | cols := getColsByTarget(Target, SubTarget);
237 | if (cols<>0) THEN AddSymbol(SymbolList, 'COLS', cols);
238 | // add ROWS Symbol
239 | AddSymbol(SymbolList, 'ROWS', GetRowsByTarget(Target));
240 | // Add Dstrings Symbol
241 | if (targetUsesDstringsGraphics(Target)) THEN AddSymbol(SymbolList, 'DSTRINGS', 1);
242 | // Add common Symbols
243 | AddSymbol(SymbolList, 'CARRIED', LOC_CARRIED);
244 | AddSymbol(SymbolList, 'NOT_CREATED', LOC_NOT_CREATED);
245 | AddSymbol(SymbolList, 'NON_CREATED', LOC_NOT_CREATED);
246 | AddSymbol(SymbolList, 'WORN', LOC_WORN);
247 | AddSymbol(SymbolList, 'HERE', LOC_HERE);
248 | AddSymbol(SymbolList, 'HERE', LOC_HERE);
249 | // The current date symbols
250 | AddSymbol(SymbolList, 'YEARHIGH', YearOf(Now) DIV 100);
251 | AddSymbol(SymbolList, 'YEARLOW', YearOf(Now) MOD 100);
252 | AddSymbol(SymbolList, 'MONTH', MonthOf(Now) MOD 100);
253 | AddSymbol(SymbolList, 'DAY', DayOf(Now) MOD 100);
254 | // The SFX commands symbols
255 | AddSymbol(SymbolList, 'PLAYSFX', 1);
256 | AddSymbol(SymbolList, 'PLAYSFXL', 2);
257 | AddSymbol(SymbolList, 'PLAYSFXF', 3);
258 | AddSymbol(SymbolList, 'PLAYSFXFL', 4);
259 | AddSymbol(SymbolList, 'STOPSFX', 5);
260 | AddSymbol(SymbolList, 'PLAYDRO', 6);
261 | AddSymbol(SymbolList, 'PLAYDROL', 7);
262 | AddSymbol(SymbolList, 'STOPDRO', 8);
263 | AddSymbol(SymbolList, 'PLAYFLI', 9);
264 | AddSymbol(SymbolList, 'PLAYFLIL', 10);
265 |
266 | // THe MOUSE command symbols
267 | AddSymbol(SymbolList, 'RESETMS', 0);
268 | AddSymbol(SymbolList, 'SHOWMS', 1);
269 | AddSymbol(SymbolList, 'HIDEMS', 2);
270 | AddSymbol(SymbolList, 'GETMS', 3);
271 | AddSymbol(SymbolList, 'GETFINEMS', 4);
272 | AddSymbol(SymbolList, 'POINTERMS', 5);
273 | AddSymbol(SymbolList, 'DELTAXMS', 6);
274 | AddSymbol(SymbolList, 'DELTAYMS', 7);
275 |
276 |
277 | // Add additionalSymbols if present
278 | i := 1;
279 | REPEAT
280 | AuxString := ExtractWord(i, AdditionalSymbols, [',']);
281 | if (AuxString<>'') THEN
282 | BEGIN
283 | AddSymbol(SymbolList, AuxString, i);
284 | END;
285 | Inc(i);
286 | UNTIL AuxString='';
287 | WriteLn('Checking Syntax...');
288 | Sintactic(target, subtarget);
289 | WriteLn('Updating forward references...');
290 | FixForwardLabels(); // Fix SKIP condacts with forward labels and local labels too
291 | Write('Generating ',OutputFileName,' [Classic mode O');
292 | if (ClassicMode) THEN WriteLn('N]') ELSE WriteLn('FF]');
293 | GenerateOutput(OutputFileName, Target);
294 | DeleteFile(TempFileName);
295 | END;
296 |
297 | FUNCTION isValidSubTarget(Target, Subtarget: AnsiString): Boolean;
298 | BEGIN
299 | if Target='MSX2' THEN Result := (Subtarget = '5_6') OR (Subtarget = '5_8') OR (Subtarget = '6_6') OR (Subtarget = '6_8') OR (Subtarget = '7_6') OR (Subtarget = '7_8') OR (Subtarget = '8_6') OR (Subtarget = '8_8') OR (Subtarget = '10_6') OR (Subtarget = '10_8') OR (Subtarget = '12_6') OR (Subtarget = '12_8');;
300 | if Target='PC' THEN Result := (Subtarget = 'VGA256') OR (Subtarget = 'VGA') OR (Subtarget = 'EGA') OR (Subtarget = 'CGA') OR (Subtarget = 'TEXT');
301 | if Target='ZX' THEN Result := (Subtarget = 'PLUS3') OR (Subtarget = 'ESXDOS') OR (Subtarget = 'NEXT') OR (Subtarget = 'UNO');
302 | END;
303 |
304 |
305 | // MAIN
306 | BEGIN
307 | AppName := ChangeFileExt(ExtractFileName(ParamStr(0)),'');
308 | Write('DAAD Reborn Compiler Frontend', ' ', version_hi, '.', version_lo, ' (C) Uto 2018');
309 | if (CurrentYear()<>2018) THEN Write('-', CurrentYear());
310 | WriteLn();
311 | // Check Parameters
312 | IF (ParamCount()<2) THEN SYNTAX();
313 | Target := UpperCase(ParamStr(1));
314 | NextParam := 2;
315 | SubTarget := '';
316 | IF (Target='MSX2') OR (Target='PC') OR (Target='ZX') THEN
317 | BEGIN
318 | SubTarget := UpperCase(ParamStr(NextParam));
319 | if (NOT isValidSubTarget(Target,Subtarget)) THEN ParamError('"' + Subtarget + '" is not a valid subtarget for target "' + Target + '". Please specify a valid subtarget. Call DRF without parameters for more information.');
320 | Inc(NextParam);
321 | END;
322 | InputFileName := ParamStr(NextParam);
323 | IF (NOT FileExists(InputFileName)) THEN ParamError('Input file not found: "'+InputFileName+'"');
324 | Inc(NextParam);
325 | IF ParamCount>= NextParam THEN AuxString := ParamStr(NextParam);
326 | IF Pos('.',AuxString) <> 0 THEN
327 | BEGIN
328 | OutputFileName := AuxString;
329 | Inc(NextParam);
330 | END
331 | ELSE
332 | BEGIN
333 | OutputFileName := ChangeFileExt(InputFileName, '.json');
334 | END;
335 | AdditionalSymbols := '';
336 | WHILE ParamCount>= NextParam DO
337 | BEGIN
338 | AuxString := ParamStr(NextParam);
339 | if (copy(AuxString, 1,1)<>'-') THEN AdditionalSymbols := AuxString // If next parameter starts by '--' it's an option, otherwise it's a symbol list
340 | ELSE
341 | BEGIN
342 | IF AuxString = '-verbose' THEN
343 | BEGIN
344 | Verbose := true;
345 | WriteLn('Verbose mode ON');
346 | END ELSE
347 | IF AuxString = '-no-semantic' THEN
348 | BEGIN
349 | NoSemantic := true;
350 | if Verbose THEN WriteLn('Warning: DRF won''t make semantic analysis');
351 | END ELSE
352 | IF AuxString = '-semantic-warnings' THEN
353 | BEGIN
354 | SemanticWarnings := true;
355 | if Verbose THEN WriteLn('Warning: Semantic analysys errors will just generate warnings');
356 | END
357 | ELSE
358 | IF AuxString = '-force-normal-messages' THEN
359 | BEGIN
360 | ForceNormalMessages := true;
361 | if Verbose THEN WriteLn('Warning: Forced Normal Messages');
362 | END
363 | ELSE
364 | IF AuxString = '-force-x-messages' THEN
365 | BEGIN
366 | ForceXMessages := true;
367 | if Verbose THEN WriteLn('Warning: Forced XMessages');
368 | END
369 | ELSE
370 | IF AuxString = '-check-maluva-disabled' THEN
371 | BEGIN
372 | CheckMaluva := false;
373 | if Verbose THEN WriteLn('Warning: Forced XMessages');
374 | END
375 | ELSE
376 | IF AuxString = '-v3' THEN
377 | BEGIN
378 | V3CODE := true;
379 | MAX_PARAM_ACCEPTING_INDIRECTION := 2;
380 | if Verbose THEN WriteLn('Warning: Generating code for DAAD V3');
381 | END
382 | ELSE
383 | IF AuxString = '-replace-xcondacts' THEN
384 | BEGIN
385 | replace_xcondacts := true;
386 | if Verbose THEN WriteLn('Warning: Replacing Xcondacts');
387 | END
388 | ELSE ParamError('Invalid option: ' + AuxString);
389 | END;
390 | Inc(NextParam);
391 | END;
392 |
393 | IF NoSemantic AND SemanticWarnings THEN ParamError('You can''t avoid semantic checking and at the same time expect semantic warnings.');
394 | IF ForceNormalMessages and ForceXMessages THEN ParamError('You can''t force XMesages and normal messages at the same time.');
395 |
396 | //LoadPlugins();
397 | IF NOT CheckEND(InputFileName) THEN ParamError('Input file has no /END section. Please make sure /END it''s in main file, not in #include files, if any.');
398 | CompileForTarget(Target, SubTarget, OutputFileName, AdditionalSymbols);
399 | END.
400 |
401 |
402 |
--------------------------------------------------------------------------------
/src/file2pas.pas:
--------------------------------------------------------------------------------
1 | var f:file;
2 | B: byte;
3 | W :Word;
4 | i :longint;
5 |
6 |
7 | begin
8 | Assign(F, paramStr(1));
9 | Reset(F,1);
10 | W :=FileSize(F);
11 | Write('CONST F=array[0..', w-1,'] of byte = '#10'(');
12 | i:=0;
13 | While not eof (F) DO
14 | begin
15 | BlockRead(F,B,1);
16 | Write(B);
17 | if (i<>W-1) then Write(', ');
18 | if (i MOD 40 =39) then Writeln;
19 | i := i+ 1;
20 | end;
21 | WriteLn(');');
22 | Close(f);
23 |
24 | end.
--------------------------------------------------------------------------------
/src/lexer.pas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Utodev/DRC/c5665282bd66c3ee7424acd53fb92cce8a5ff37b/src/lexer.pas
--------------------------------------------------------------------------------
/src/lexer.pas_:
--------------------------------------------------------------------------------
1 |
2 | (* lexical analyzer template (TP Lex V3.0), V1.0 3-2-91 AG *)
3 |
4 | (* global definitions: *)
5 | //This is the Lex (TPLex) lex file, the tokenizer
6 |
7 |
8 |
9 |
10 |
11 | function yylex : Integer;
12 |
13 | procedure yyaction ( yyruleno : Integer );
14 | (* local definitions: *)
15 | begin
16 | (* actions: *)
17 | case yyruleno of
18 | 1:
19 | BEGIN AddToken(TokenList, T_SECTION_CTL, yytext, MaxLongInt, yylineno, yycolno); END;
20 | 2:
21 | BEGIN AddToken(TokenList, T_SECTION_STX, yytext, MaxLongInt, yylineno, yycolno); END;
22 | 3:
23 | BEGIN AddToken(TokenList, T_SECTION_CON, yytext, MaxLongInt, yylineno, yycolno); END;
24 | 4:
25 | BEGIN AddToken(TokenList, T_SECTION_MTX, yytext, MaxLongInt, yylineno, yycolno); END;
26 | 5:
27 | BEGIN AddToken(TokenList, T_SECTION_LTX, yytext, MaxLongInt, yylineno, yycolno); END;
28 | 6:
29 | BEGIN AddToken(TokenList, T_SECTION_OTX, yytext, MaxLongInt, yylineno, yycolno); END;
30 | 7:
31 | BEGIN AddToken(TokenList, T_SECTION_OBJ, yytext, MaxLongInt, yylineno, yycolno); END;
32 | 8:
33 | BEGIN AddToken(TokenList, T_SECTION_VOC, yytext, MaxLongInt, yylineno, yycolno); END;
34 | 9:
35 | BEGIN AddToken(TokenList, T_SECTION_PRO, yytext, MaxLongInt, yylineno, yycolno); END;
36 | 10:
37 | BEGIN AddToken(TokenList, T_SECTION_END, yytext, MaxLongInt, yylineno, yycolno); END;
38 | 11:
39 | BEGIN AddToken(TokenList, T_DEFINE, yytext, MaxLongInt, yylineno, yycolno); END;
40 | 12:
41 | BEGIN AddToken(TokenList, T_IFDEF, yytext, MaxLongInt, yylineno, yycolno); END;
42 | 13:
43 | BEGIN AddToken(TokenList, T_IFNDEF, yytext, MaxLongInt, yylineno, yycolno); END;
44 | 14:
45 | BEGIN AddToken(TokenList, T_ENDIF, yytext, MaxLongInt, yylineno, yycolno); END;
46 | 15:
47 | BEGIN AddToken(TokenList, T_DB, yytext, MaxLongInt, yylineno, yycolno); END;
48 | 16:
49 | BEGIN AddToken(TokenList, T_EXTERN, yytext, MaxLongInt, yylineno, yycolno); END;
50 | 17:
51 | BEGIN AddToken(TokenList, T_INCBIN, yytext, MaxLongInt, yylineno, yycolno); END;
52 | 18:
53 | BEGIN AddToken(TokenList, T_CLASSIC, yytext, MaxLongInt, yylineno, yycolno); END;
54 | 19:
55 | BEGIN AddToken(TokenList, T_STRING, yytext, MaxLongInt, yylineno, yycolno); END;
56 | 20:
57 | BEGIN AddToken(TokenList, T_STRING, yytext, MaxLongInt, yylineno, yycolno); END;
58 | 21:
59 | BEGIN AddToken(TokenList, T_UNDERSCORE, yytext, MaxLongInt, yylineno, yycolno); END;
60 | 22:
61 | BEGIN AddToken(TokenList, T_LIST_ENTRY, yytext, StrToInt(Copy(yytext,2,Length(yytext)-1)), yylineno, yycolno); END;
62 | 23:
63 | BEGIN END;
64 | 24:
65 | BEGIN AddToken(TokenList, T_NUMBER, yytext, StrToInt(yytext), yylineno, yycolno); END;
66 | 25:
67 | BEGIN AddToken(TokenList, T_IDENTIFIER, yytext, MaxLongInt, yylineno, yycolno); END;
68 | 26:
69 | BEGIN AddToken(TokenList, T_INDIRECT, yytext, MaxLongInt, yylineno, yycolno); END;
70 | 27:
71 | BEGIN END;
72 | 28:
73 | BEGIN yyerror('Unexpected character'); Halt(1); END;
74 | end;
75 | end(*yyaction*);
76 |
77 | (* DFA table: *)
78 |
79 | type YYTRec = record
80 | cc : set of Char;
81 | s : Integer;
82 | end;
83 |
84 | const
85 |
86 | yynmarks = 46;
87 | yynmatches = 46;
88 | yyntrans = 121;
89 | yynstates = 92;
90 |
91 | yyk : array [1..yynmarks] of Integer = (
92 | { 0: }
93 | { 1: }
94 | { 2: }
95 | 28,
96 | { 3: }
97 | 28,
98 | { 4: }
99 | 28,
100 | { 5: }
101 | 28,
102 | { 6: }
103 | 21,
104 | 25,
105 | 28,
106 | { 7: }
107 | 28,
108 | { 8: }
109 | 28,
110 | { 9: }
111 | 24,
112 | 25,
113 | 28,
114 | { 10: }
115 | 25,
116 | 28,
117 | { 11: }
118 | 26,
119 | 28,
120 | { 12: }
121 | 27,
122 | { 13: }
123 | 27,
124 | 28,
125 | { 14: }
126 | 28,
127 | { 15: }
128 | { 16: }
129 | { 17: }
130 | { 18: }
131 | { 19: }
132 | { 20: }
133 | { 21: }
134 | { 22: }
135 | { 23: }
136 | 22,
137 | { 24: }
138 | { 25: }
139 | { 26: }
140 | { 27: }
141 | { 28: }
142 | { 29: }
143 | 19,
144 | { 30: }
145 | { 31: }
146 | { 32: }
147 | 25,
148 | { 33: }
149 | { 34: }
150 | 23,
151 | { 35: }
152 | 24,
153 | { 36: }
154 | 24,
155 | 25,
156 | { 37: }
157 | { 38: }
158 | { 39: }
159 | { 40: }
160 | { 41: }
161 | { 42: }
162 | { 43: }
163 | { 44: }
164 | { 45: }
165 | { 46: }
166 | { 47: }
167 | { 48: }
168 | 15,
169 | { 49: }
170 | { 50: }
171 | { 51: }
172 | { 52: }
173 | { 53: }
174 | { 54: }
175 | 20,
176 | { 55: }
177 | 1,
178 | { 56: }
179 | 3,
180 | { 57: }
181 | 2,
182 | { 58: }
183 | 4,
184 | { 59: }
185 | 5,
186 | { 60: }
187 | 6,
188 | { 61: }
189 | 7,
190 | { 62: }
191 | 8,
192 | { 63: }
193 | 9,
194 | { 64: }
195 | 10,
196 | { 65: }
197 | { 66: }
198 | { 67: }
199 | { 68: }
200 | { 69: }
201 | { 70: }
202 | { 71: }
203 | { 72: }
204 | { 73: }
205 | { 74: }
206 | { 75: }
207 | { 76: }
208 | { 77: }
209 | { 78: }
210 | { 79: }
211 | { 80: }
212 | 12,
213 | { 81: }
214 | { 82: }
215 | { 83: }
216 | 14,
217 | { 84: }
218 | { 85: }
219 | { 86: }
220 | 11,
221 | { 87: }
222 | 13,
223 | { 88: }
224 | 17,
225 | { 89: }
226 | 16,
227 | { 90: }
228 | { 91: }
229 | 18
230 | );
231 |
232 | yym : array [1..yynmatches] of Integer = (
233 | { 0: }
234 | { 1: }
235 | { 2: }
236 | 28,
237 | { 3: }
238 | 28,
239 | { 4: }
240 | 28,
241 | { 5: }
242 | 28,
243 | { 6: }
244 | 21,
245 | 25,
246 | 28,
247 | { 7: }
248 | 28,
249 | { 8: }
250 | 28,
251 | { 9: }
252 | 24,
253 | 25,
254 | 28,
255 | { 10: }
256 | 25,
257 | 28,
258 | { 11: }
259 | 26,
260 | 28,
261 | { 12: }
262 | 27,
263 | { 13: }
264 | 27,
265 | 28,
266 | { 14: }
267 | 28,
268 | { 15: }
269 | { 16: }
270 | { 17: }
271 | { 18: }
272 | { 19: }
273 | { 20: }
274 | { 21: }
275 | { 22: }
276 | { 23: }
277 | 22,
278 | { 24: }
279 | { 25: }
280 | { 26: }
281 | { 27: }
282 | { 28: }
283 | { 29: }
284 | 19,
285 | { 30: }
286 | { 31: }
287 | { 32: }
288 | 25,
289 | { 33: }
290 | { 34: }
291 | 23,
292 | { 35: }
293 | 24,
294 | { 36: }
295 | 24,
296 | 25,
297 | { 37: }
298 | { 38: }
299 | { 39: }
300 | { 40: }
301 | { 41: }
302 | { 42: }
303 | { 43: }
304 | { 44: }
305 | { 45: }
306 | { 46: }
307 | { 47: }
308 | { 48: }
309 | 15,
310 | { 49: }
311 | { 50: }
312 | { 51: }
313 | { 52: }
314 | { 53: }
315 | { 54: }
316 | 20,
317 | { 55: }
318 | 1,
319 | { 56: }
320 | 3,
321 | { 57: }
322 | 2,
323 | { 58: }
324 | 4,
325 | { 59: }
326 | 5,
327 | { 60: }
328 | 6,
329 | { 61: }
330 | 7,
331 | { 62: }
332 | 8,
333 | { 63: }
334 | 9,
335 | { 64: }
336 | 10,
337 | { 65: }
338 | { 66: }
339 | { 67: }
340 | { 68: }
341 | { 69: }
342 | { 70: }
343 | { 71: }
344 | { 72: }
345 | { 73: }
346 | { 74: }
347 | { 75: }
348 | { 76: }
349 | { 77: }
350 | { 78: }
351 | { 79: }
352 | { 80: }
353 | 12,
354 | { 81: }
355 | { 82: }
356 | { 83: }
357 | 14,
358 | { 84: }
359 | { 85: }
360 | { 86: }
361 | 11,
362 | { 87: }
363 | 13,
364 | { 88: }
365 | 17,
366 | { 89: }
367 | 16,
368 | { 90: }
369 | { 91: }
370 | 18
371 | );
372 |
373 | yyt : array [1..yyntrans] of YYTrec = (
374 | { 0: }
375 | ( cc: [ #1..#8,#11..#31,'!','$'..'&','('..'+','.',
376 | ':','<'..'?','['..'^','`','{'..#255 ]; s: 14),
377 | ( cc: [ #9,' ' ]; s: 13),
378 | ( cc: [ #10 ]; s: 12),
379 | ( cc: [ '"' ]; s: 4),
380 | ( cc: [ '#' ]; s: 3),
381 | ( cc: [ '''' ]; s: 5),
382 | ( cc: [ ',','A'..'Z','a'..'z' ]; s: 10),
383 | ( cc: [ '-' ]; s: 8),
384 | ( cc: [ '/' ]; s: 2),
385 | ( cc: [ '0'..'9' ]; s: 9),
386 | ( cc: [ ';' ]; s: 7),
387 | ( cc: [ '@' ]; s: 11),
388 | ( cc: [ '_' ]; s: 6),
389 | { 1: }
390 | ( cc: [ #1..#8,#11..#31,'!','$'..'&','('..'+','.',
391 | ':','<'..'?','['..'^','`','{'..#255 ]; s: 14),
392 | ( cc: [ #9,' ' ]; s: 13),
393 | ( cc: [ #10 ]; s: 12),
394 | ( cc: [ '"' ]; s: 4),
395 | ( cc: [ '#' ]; s: 3),
396 | ( cc: [ '''' ]; s: 5),
397 | ( cc: [ ',','A'..'Z','a'..'z' ]; s: 10),
398 | ( cc: [ '-' ]; s: 8),
399 | ( cc: [ '/' ]; s: 2),
400 | ( cc: [ '0'..'9' ]; s: 9),
401 | ( cc: [ ';' ]; s: 7),
402 | ( cc: [ '@' ]; s: 11),
403 | ( cc: [ '_' ]; s: 6),
404 | { 2: }
405 | ( cc: [ '0'..'9' ]; s: 23),
406 | ( cc: [ 'C' ]; s: 15),
407 | ( cc: [ 'E' ]; s: 22),
408 | ( cc: [ 'L' ]; s: 18),
409 | ( cc: [ 'M' ]; s: 17),
410 | ( cc: [ 'O' ]; s: 19),
411 | ( cc: [ 'P' ]; s: 21),
412 | ( cc: [ 'S' ]; s: 16),
413 | ( cc: [ 'V' ]; s: 20),
414 | { 3: }
415 | ( cc: [ 'c' ]; s: 27),
416 | ( cc: [ 'd' ]; s: 24),
417 | ( cc: [ 'e' ]; s: 26),
418 | ( cc: [ 'i' ]; s: 25),
419 | { 4: }
420 | ( cc: [ #1..#9,#11..'!','#'..#255 ]; s: 28),
421 | ( cc: [ '"' ]; s: 29),
422 | { 5: }
423 | ( cc: [ #1..#9,#11..'&','('..#255 ]; s: 30),
424 | ( cc: [ '''' ]; s: 31),
425 | { 6: }
426 | ( cc: [ ',','0'..'9','A'..'Z','_','a'..'z' ]; s: 32),
427 | { 7: }
428 | ( cc: [ #1..#9,#11..#255 ]; s: 33),
429 | ( cc: [ #10 ]; s: 34),
430 | { 8: }
431 | ( cc: [ '0'..'9' ]; s: 35),
432 | { 9: }
433 | ( cc: [ ',','A'..'Z','_','a'..'z' ]; s: 32),
434 | ( cc: [ '0'..'9' ]; s: 36),
435 | { 10: }
436 | ( cc: [ ',','0'..'9','A'..'Z','_','a'..'z' ]; s: 32),
437 | { 11: }
438 | { 12: }
439 | { 13: }
440 | { 14: }
441 | { 15: }
442 | ( cc: [ 'O' ]; s: 38),
443 | ( cc: [ 'T' ]; s: 37),
444 | { 16: }
445 | ( cc: [ 'T' ]; s: 39),
446 | { 17: }
447 | ( cc: [ 'T' ]; s: 40),
448 | { 18: }
449 | ( cc: [ 'T' ]; s: 41),
450 | { 19: }
451 | ( cc: [ 'B' ]; s: 43),
452 | ( cc: [ 'T' ]; s: 42),
453 | { 20: }
454 | ( cc: [ 'O' ]; s: 44),
455 | { 21: }
456 | ( cc: [ 'R' ]; s: 45),
457 | { 22: }
458 | ( cc: [ 'N' ]; s: 46),
459 | { 23: }
460 | ( cc: [ '0'..'9' ]; s: 23),
461 | { 24: }
462 | ( cc: [ 'b' ]; s: 48),
463 | ( cc: [ 'e' ]; s: 47),
464 | { 25: }
465 | ( cc: [ 'f' ]; s: 49),
466 | ( cc: [ 'n' ]; s: 50),
467 | { 26: }
468 | ( cc: [ 'n' ]; s: 51),
469 | ( cc: [ 'x' ]; s: 52),
470 | { 27: }
471 | ( cc: [ 'l' ]; s: 53),
472 | { 28: }
473 | ( cc: [ #1..#9,#11..'!','#'..#255 ]; s: 28),
474 | ( cc: [ '"' ]; s: 29),
475 | { 29: }
476 | ( cc: [ #1..#9,#11..'!','#'..#255 ]; s: 28),
477 | ( cc: [ '"' ]; s: 29),
478 | { 30: }
479 | ( cc: [ #1..#9,#11..'&','('..#255 ]; s: 30),
480 | ( cc: [ '''' ]; s: 31),
481 | { 31: }
482 | ( cc: [ #1..#9,#11..'&','('..#255 ]; s: 30),
483 | ( cc: [ '''' ]; s: 54),
484 | { 32: }
485 | ( cc: [ ',','0'..'9','A'..'Z','_','a'..'z' ]; s: 32),
486 | { 33: }
487 | ( cc: [ #1..#9,#11..#255 ]; s: 33),
488 | ( cc: [ #10 ]; s: 34),
489 | { 34: }
490 | { 35: }
491 | ( cc: [ '0'..'9' ]; s: 35),
492 | { 36: }
493 | ( cc: [ ',','A'..'Z','_','a'..'z' ]; s: 32),
494 | ( cc: [ '0'..'9' ]; s: 36),
495 | { 37: }
496 | ( cc: [ 'L' ]; s: 55),
497 | { 38: }
498 | ( cc: [ 'N' ]; s: 56),
499 | { 39: }
500 | ( cc: [ 'X' ]; s: 57),
501 | { 40: }
502 | ( cc: [ 'X' ]; s: 58),
503 | { 41: }
504 | ( cc: [ 'X' ]; s: 59),
505 | { 42: }
506 | ( cc: [ 'X' ]; s: 60),
507 | { 43: }
508 | ( cc: [ 'J' ]; s: 61),
509 | { 44: }
510 | ( cc: [ 'C' ]; s: 62),
511 | { 45: }
512 | ( cc: [ 'O' ]; s: 63),
513 | { 46: }
514 | ( cc: [ 'D' ]; s: 64),
515 | { 47: }
516 | ( cc: [ 'f' ]; s: 65),
517 | { 48: }
518 | { 49: }
519 | ( cc: [ 'd' ]; s: 66),
520 | ( cc: [ 'n' ]; s: 67),
521 | { 50: }
522 | ( cc: [ 'c' ]; s: 68),
523 | { 51: }
524 | ( cc: [ 'd' ]; s: 69),
525 | { 52: }
526 | ( cc: [ 't' ]; s: 70),
527 | { 53: }
528 | ( cc: [ 'a' ]; s: 71),
529 | { 54: }
530 | ( cc: [ #1..#9,#11..'&','('..#255 ]; s: 30),
531 | ( cc: [ '''' ]; s: 54),
532 | { 55: }
533 | { 56: }
534 | { 57: }
535 | { 58: }
536 | { 59: }
537 | { 60: }
538 | { 61: }
539 | { 62: }
540 | { 63: }
541 | { 64: }
542 | { 65: }
543 | ( cc: [ 'i' ]; s: 72),
544 | { 66: }
545 | ( cc: [ 'e' ]; s: 73),
546 | { 67: }
547 | ( cc: [ 'd' ]; s: 74),
548 | { 68: }
549 | ( cc: [ 'b' ]; s: 75),
550 | { 69: }
551 | ( cc: [ 'i' ]; s: 76),
552 | { 70: }
553 | ( cc: [ 'e' ]; s: 77),
554 | { 71: }
555 | ( cc: [ 's' ]; s: 78),
556 | { 72: }
557 | ( cc: [ 'n' ]; s: 79),
558 | { 73: }
559 | ( cc: [ 'f' ]; s: 80),
560 | { 74: }
561 | ( cc: [ 'e' ]; s: 81),
562 | { 75: }
563 | ( cc: [ 'i' ]; s: 82),
564 | { 76: }
565 | ( cc: [ 'f' ]; s: 83),
566 | { 77: }
567 | ( cc: [ 'r' ]; s: 84),
568 | { 78: }
569 | ( cc: [ 's' ]; s: 85),
570 | { 79: }
571 | ( cc: [ 'e' ]; s: 86),
572 | { 80: }
573 | { 81: }
574 | ( cc: [ 'f' ]; s: 87),
575 | { 82: }
576 | ( cc: [ 'n' ]; s: 88),
577 | { 83: }
578 | { 84: }
579 | ( cc: [ 'n' ]; s: 89),
580 | { 85: }
581 | ( cc: [ 'i' ]; s: 90),
582 | { 86: }
583 | { 87: }
584 | { 88: }
585 | { 89: }
586 | { 90: }
587 | ( cc: [ 'c' ]; s: 91)
588 | { 91: }
589 | );
590 |
591 | yykl : array [0..yynstates-1] of Integer = (
592 | { 0: } 1,
593 | { 1: } 1,
594 | { 2: } 1,
595 | { 3: } 2,
596 | { 4: } 3,
597 | { 5: } 4,
598 | { 6: } 5,
599 | { 7: } 8,
600 | { 8: } 9,
601 | { 9: } 10,
602 | { 10: } 13,
603 | { 11: } 15,
604 | { 12: } 17,
605 | { 13: } 18,
606 | { 14: } 20,
607 | { 15: } 21,
608 | { 16: } 21,
609 | { 17: } 21,
610 | { 18: } 21,
611 | { 19: } 21,
612 | { 20: } 21,
613 | { 21: } 21,
614 | { 22: } 21,
615 | { 23: } 21,
616 | { 24: } 22,
617 | { 25: } 22,
618 | { 26: } 22,
619 | { 27: } 22,
620 | { 28: } 22,
621 | { 29: } 22,
622 | { 30: } 23,
623 | { 31: } 23,
624 | { 32: } 23,
625 | { 33: } 24,
626 | { 34: } 24,
627 | { 35: } 25,
628 | { 36: } 26,
629 | { 37: } 28,
630 | { 38: } 28,
631 | { 39: } 28,
632 | { 40: } 28,
633 | { 41: } 28,
634 | { 42: } 28,
635 | { 43: } 28,
636 | { 44: } 28,
637 | { 45: } 28,
638 | { 46: } 28,
639 | { 47: } 28,
640 | { 48: } 28,
641 | { 49: } 29,
642 | { 50: } 29,
643 | { 51: } 29,
644 | { 52: } 29,
645 | { 53: } 29,
646 | { 54: } 29,
647 | { 55: } 30,
648 | { 56: } 31,
649 | { 57: } 32,
650 | { 58: } 33,
651 | { 59: } 34,
652 | { 60: } 35,
653 | { 61: } 36,
654 | { 62: } 37,
655 | { 63: } 38,
656 | { 64: } 39,
657 | { 65: } 40,
658 | { 66: } 40,
659 | { 67: } 40,
660 | { 68: } 40,
661 | { 69: } 40,
662 | { 70: } 40,
663 | { 71: } 40,
664 | { 72: } 40,
665 | { 73: } 40,
666 | { 74: } 40,
667 | { 75: } 40,
668 | { 76: } 40,
669 | { 77: } 40,
670 | { 78: } 40,
671 | { 79: } 40,
672 | { 80: } 40,
673 | { 81: } 41,
674 | { 82: } 41,
675 | { 83: } 41,
676 | { 84: } 42,
677 | { 85: } 42,
678 | { 86: } 42,
679 | { 87: } 43,
680 | { 88: } 44,
681 | { 89: } 45,
682 | { 90: } 46,
683 | { 91: } 46
684 | );
685 |
686 | yykh : array [0..yynstates-1] of Integer = (
687 | { 0: } 0,
688 | { 1: } 0,
689 | { 2: } 1,
690 | { 3: } 2,
691 | { 4: } 3,
692 | { 5: } 4,
693 | { 6: } 7,
694 | { 7: } 8,
695 | { 8: } 9,
696 | { 9: } 12,
697 | { 10: } 14,
698 | { 11: } 16,
699 | { 12: } 17,
700 | { 13: } 19,
701 | { 14: } 20,
702 | { 15: } 20,
703 | { 16: } 20,
704 | { 17: } 20,
705 | { 18: } 20,
706 | { 19: } 20,
707 | { 20: } 20,
708 | { 21: } 20,
709 | { 22: } 20,
710 | { 23: } 21,
711 | { 24: } 21,
712 | { 25: } 21,
713 | { 26: } 21,
714 | { 27: } 21,
715 | { 28: } 21,
716 | { 29: } 22,
717 | { 30: } 22,
718 | { 31: } 22,
719 | { 32: } 23,
720 | { 33: } 23,
721 | { 34: } 24,
722 | { 35: } 25,
723 | { 36: } 27,
724 | { 37: } 27,
725 | { 38: } 27,
726 | { 39: } 27,
727 | { 40: } 27,
728 | { 41: } 27,
729 | { 42: } 27,
730 | { 43: } 27,
731 | { 44: } 27,
732 | { 45: } 27,
733 | { 46: } 27,
734 | { 47: } 27,
735 | { 48: } 28,
736 | { 49: } 28,
737 | { 50: } 28,
738 | { 51: } 28,
739 | { 52: } 28,
740 | { 53: } 28,
741 | { 54: } 29,
742 | { 55: } 30,
743 | { 56: } 31,
744 | { 57: } 32,
745 | { 58: } 33,
746 | { 59: } 34,
747 | { 60: } 35,
748 | { 61: } 36,
749 | { 62: } 37,
750 | { 63: } 38,
751 | { 64: } 39,
752 | { 65: } 39,
753 | { 66: } 39,
754 | { 67: } 39,
755 | { 68: } 39,
756 | { 69: } 39,
757 | { 70: } 39,
758 | { 71: } 39,
759 | { 72: } 39,
760 | { 73: } 39,
761 | { 74: } 39,
762 | { 75: } 39,
763 | { 76: } 39,
764 | { 77: } 39,
765 | { 78: } 39,
766 | { 79: } 39,
767 | { 80: } 40,
768 | { 81: } 40,
769 | { 82: } 40,
770 | { 83: } 41,
771 | { 84: } 41,
772 | { 85: } 41,
773 | { 86: } 42,
774 | { 87: } 43,
775 | { 88: } 44,
776 | { 89: } 45,
777 | { 90: } 45,
778 | { 91: } 46
779 | );
780 |
781 | yyml : array [0..yynstates-1] of Integer = (
782 | { 0: } 1,
783 | { 1: } 1,
784 | { 2: } 1,
785 | { 3: } 2,
786 | { 4: } 3,
787 | { 5: } 4,
788 | { 6: } 5,
789 | { 7: } 8,
790 | { 8: } 9,
791 | { 9: } 10,
792 | { 10: } 13,
793 | { 11: } 15,
794 | { 12: } 17,
795 | { 13: } 18,
796 | { 14: } 20,
797 | { 15: } 21,
798 | { 16: } 21,
799 | { 17: } 21,
800 | { 18: } 21,
801 | { 19: } 21,
802 | { 20: } 21,
803 | { 21: } 21,
804 | { 22: } 21,
805 | { 23: } 21,
806 | { 24: } 22,
807 | { 25: } 22,
808 | { 26: } 22,
809 | { 27: } 22,
810 | { 28: } 22,
811 | { 29: } 22,
812 | { 30: } 23,
813 | { 31: } 23,
814 | { 32: } 23,
815 | { 33: } 24,
816 | { 34: } 24,
817 | { 35: } 25,
818 | { 36: } 26,
819 | { 37: } 28,
820 | { 38: } 28,
821 | { 39: } 28,
822 | { 40: } 28,
823 | { 41: } 28,
824 | { 42: } 28,
825 | { 43: } 28,
826 | { 44: } 28,
827 | { 45: } 28,
828 | { 46: } 28,
829 | { 47: } 28,
830 | { 48: } 28,
831 | { 49: } 29,
832 | { 50: } 29,
833 | { 51: } 29,
834 | { 52: } 29,
835 | { 53: } 29,
836 | { 54: } 29,
837 | { 55: } 30,
838 | { 56: } 31,
839 | { 57: } 32,
840 | { 58: } 33,
841 | { 59: } 34,
842 | { 60: } 35,
843 | { 61: } 36,
844 | { 62: } 37,
845 | { 63: } 38,
846 | { 64: } 39,
847 | { 65: } 40,
848 | { 66: } 40,
849 | { 67: } 40,
850 | { 68: } 40,
851 | { 69: } 40,
852 | { 70: } 40,
853 | { 71: } 40,
854 | { 72: } 40,
855 | { 73: } 40,
856 | { 74: } 40,
857 | { 75: } 40,
858 | { 76: } 40,
859 | { 77: } 40,
860 | { 78: } 40,
861 | { 79: } 40,
862 | { 80: } 40,
863 | { 81: } 41,
864 | { 82: } 41,
865 | { 83: } 41,
866 | { 84: } 42,
867 | { 85: } 42,
868 | { 86: } 42,
869 | { 87: } 43,
870 | { 88: } 44,
871 | { 89: } 45,
872 | { 90: } 46,
873 | { 91: } 46
874 | );
875 |
876 | yymh : array [0..yynstates-1] of Integer = (
877 | { 0: } 0,
878 | { 1: } 0,
879 | { 2: } 1,
880 | { 3: } 2,
881 | { 4: } 3,
882 | { 5: } 4,
883 | { 6: } 7,
884 | { 7: } 8,
885 | { 8: } 9,
886 | { 9: } 12,
887 | { 10: } 14,
888 | { 11: } 16,
889 | { 12: } 17,
890 | { 13: } 19,
891 | { 14: } 20,
892 | { 15: } 20,
893 | { 16: } 20,
894 | { 17: } 20,
895 | { 18: } 20,
896 | { 19: } 20,
897 | { 20: } 20,
898 | { 21: } 20,
899 | { 22: } 20,
900 | { 23: } 21,
901 | { 24: } 21,
902 | { 25: } 21,
903 | { 26: } 21,
904 | { 27: } 21,
905 | { 28: } 21,
906 | { 29: } 22,
907 | { 30: } 22,
908 | { 31: } 22,
909 | { 32: } 23,
910 | { 33: } 23,
911 | { 34: } 24,
912 | { 35: } 25,
913 | { 36: } 27,
914 | { 37: } 27,
915 | { 38: } 27,
916 | { 39: } 27,
917 | { 40: } 27,
918 | { 41: } 27,
919 | { 42: } 27,
920 | { 43: } 27,
921 | { 44: } 27,
922 | { 45: } 27,
923 | { 46: } 27,
924 | { 47: } 27,
925 | { 48: } 28,
926 | { 49: } 28,
927 | { 50: } 28,
928 | { 51: } 28,
929 | { 52: } 28,
930 | { 53: } 28,
931 | { 54: } 29,
932 | { 55: } 30,
933 | { 56: } 31,
934 | { 57: } 32,
935 | { 58: } 33,
936 | { 59: } 34,
937 | { 60: } 35,
938 | { 61: } 36,
939 | { 62: } 37,
940 | { 63: } 38,
941 | { 64: } 39,
942 | { 65: } 39,
943 | { 66: } 39,
944 | { 67: } 39,
945 | { 68: } 39,
946 | { 69: } 39,
947 | { 70: } 39,
948 | { 71: } 39,
949 | { 72: } 39,
950 | { 73: } 39,
951 | { 74: } 39,
952 | { 75: } 39,
953 | { 76: } 39,
954 | { 77: } 39,
955 | { 78: } 39,
956 | { 79: } 39,
957 | { 80: } 40,
958 | { 81: } 40,
959 | { 82: } 40,
960 | { 83: } 41,
961 | { 84: } 41,
962 | { 85: } 41,
963 | { 86: } 42,
964 | { 87: } 43,
965 | { 88: } 44,
966 | { 89: } 45,
967 | { 90: } 45,
968 | { 91: } 46
969 | );
970 |
971 | yytl : array [0..yynstates-1] of Integer = (
972 | { 0: } 1,
973 | { 1: } 14,
974 | { 2: } 27,
975 | { 3: } 36,
976 | { 4: } 40,
977 | { 5: } 42,
978 | { 6: } 44,
979 | { 7: } 45,
980 | { 8: } 47,
981 | { 9: } 48,
982 | { 10: } 50,
983 | { 11: } 51,
984 | { 12: } 51,
985 | { 13: } 51,
986 | { 14: } 51,
987 | { 15: } 51,
988 | { 16: } 53,
989 | { 17: } 54,
990 | { 18: } 55,
991 | { 19: } 56,
992 | { 20: } 58,
993 | { 21: } 59,
994 | { 22: } 60,
995 | { 23: } 61,
996 | { 24: } 62,
997 | { 25: } 64,
998 | { 26: } 66,
999 | { 27: } 68,
1000 | { 28: } 69,
1001 | { 29: } 71,
1002 | { 30: } 73,
1003 | { 31: } 75,
1004 | { 32: } 77,
1005 | { 33: } 78,
1006 | { 34: } 80,
1007 | { 35: } 80,
1008 | { 36: } 81,
1009 | { 37: } 83,
1010 | { 38: } 84,
1011 | { 39: } 85,
1012 | { 40: } 86,
1013 | { 41: } 87,
1014 | { 42: } 88,
1015 | { 43: } 89,
1016 | { 44: } 90,
1017 | { 45: } 91,
1018 | { 46: } 92,
1019 | { 47: } 93,
1020 | { 48: } 94,
1021 | { 49: } 94,
1022 | { 50: } 96,
1023 | { 51: } 97,
1024 | { 52: } 98,
1025 | { 53: } 99,
1026 | { 54: } 100,
1027 | { 55: } 102,
1028 | { 56: } 102,
1029 | { 57: } 102,
1030 | { 58: } 102,
1031 | { 59: } 102,
1032 | { 60: } 102,
1033 | { 61: } 102,
1034 | { 62: } 102,
1035 | { 63: } 102,
1036 | { 64: } 102,
1037 | { 65: } 102,
1038 | { 66: } 103,
1039 | { 67: } 104,
1040 | { 68: } 105,
1041 | { 69: } 106,
1042 | { 70: } 107,
1043 | { 71: } 108,
1044 | { 72: } 109,
1045 | { 73: } 110,
1046 | { 74: } 111,
1047 | { 75: } 112,
1048 | { 76: } 113,
1049 | { 77: } 114,
1050 | { 78: } 115,
1051 | { 79: } 116,
1052 | { 80: } 117,
1053 | { 81: } 117,
1054 | { 82: } 118,
1055 | { 83: } 119,
1056 | { 84: } 119,
1057 | { 85: } 120,
1058 | { 86: } 121,
1059 | { 87: } 121,
1060 | { 88: } 121,
1061 | { 89: } 121,
1062 | { 90: } 121,
1063 | { 91: } 122
1064 | );
1065 |
1066 | yyth : array [0..yynstates-1] of Integer = (
1067 | { 0: } 13,
1068 | { 1: } 26,
1069 | { 2: } 35,
1070 | { 3: } 39,
1071 | { 4: } 41,
1072 | { 5: } 43,
1073 | { 6: } 44,
1074 | { 7: } 46,
1075 | { 8: } 47,
1076 | { 9: } 49,
1077 | { 10: } 50,
1078 | { 11: } 50,
1079 | { 12: } 50,
1080 | { 13: } 50,
1081 | { 14: } 50,
1082 | { 15: } 52,
1083 | { 16: } 53,
1084 | { 17: } 54,
1085 | { 18: } 55,
1086 | { 19: } 57,
1087 | { 20: } 58,
1088 | { 21: } 59,
1089 | { 22: } 60,
1090 | { 23: } 61,
1091 | { 24: } 63,
1092 | { 25: } 65,
1093 | { 26: } 67,
1094 | { 27: } 68,
1095 | { 28: } 70,
1096 | { 29: } 72,
1097 | { 30: } 74,
1098 | { 31: } 76,
1099 | { 32: } 77,
1100 | { 33: } 79,
1101 | { 34: } 79,
1102 | { 35: } 80,
1103 | { 36: } 82,
1104 | { 37: } 83,
1105 | { 38: } 84,
1106 | { 39: } 85,
1107 | { 40: } 86,
1108 | { 41: } 87,
1109 | { 42: } 88,
1110 | { 43: } 89,
1111 | { 44: } 90,
1112 | { 45: } 91,
1113 | { 46: } 92,
1114 | { 47: } 93,
1115 | { 48: } 93,
1116 | { 49: } 95,
1117 | { 50: } 96,
1118 | { 51: } 97,
1119 | { 52: } 98,
1120 | { 53: } 99,
1121 | { 54: } 101,
1122 | { 55: } 101,
1123 | { 56: } 101,
1124 | { 57: } 101,
1125 | { 58: } 101,
1126 | { 59: } 101,
1127 | { 60: } 101,
1128 | { 61: } 101,
1129 | { 62: } 101,
1130 | { 63: } 101,
1131 | { 64: } 101,
1132 | { 65: } 102,
1133 | { 66: } 103,
1134 | { 67: } 104,
1135 | { 68: } 105,
1136 | { 69: } 106,
1137 | { 70: } 107,
1138 | { 71: } 108,
1139 | { 72: } 109,
1140 | { 73: } 110,
1141 | { 74: } 111,
1142 | { 75: } 112,
1143 | { 76: } 113,
1144 | { 77: } 114,
1145 | { 78: } 115,
1146 | { 79: } 116,
1147 | { 80: } 116,
1148 | { 81: } 117,
1149 | { 82: } 118,
1150 | { 83: } 118,
1151 | { 84: } 119,
1152 | { 85: } 120,
1153 | { 86: } 120,
1154 | { 87: } 120,
1155 | { 88: } 120,
1156 | { 89: } 120,
1157 | { 90: } 121,
1158 | { 91: } 121
1159 | );
1160 |
1161 |
1162 | var yyn : Integer;
1163 |
1164 | label start, scan, action;
1165 |
1166 | begin
1167 |
1168 | start:
1169 |
1170 | (* initialize: *)
1171 |
1172 | yynew;
1173 |
1174 | scan:
1175 |
1176 | (* mark positions and matches: *)
1177 |
1178 | for yyn := yykl[yystate] to yykh[yystate] do yymark(yyk[yyn]);
1179 | for yyn := yymh[yystate] downto yyml[yystate] do yymatch(yym[yyn]);
1180 |
1181 | if yytl[yystate]>yyth[yystate] then goto action; (* dead state *)
1182 |
1183 | (* get next character: *)
1184 |
1185 | yyscan;
1186 |
1187 | (* determine action: *)
1188 |
1189 | yyn := yytl[yystate];
1190 | while (yyn<=yyth[yystate]) and not (yyactchar in yyt[yyn].cc) do inc(yyn);
1191 | if yyn>yyth[yystate] then goto action;
1192 | (* no transition on yyactchar in this state *)
1193 |
1194 | (* switch to new state: *)
1195 |
1196 | yystate := yyt[yyn].s;
1197 |
1198 | goto scan;
1199 |
1200 | action:
1201 |
1202 | (* execute action: *)
1203 |
1204 | if yyfind(yyrule) then
1205 | begin
1206 | yyaction(yyrule);
1207 | if yyreject then goto action;
1208 | end
1209 | else if not yydefault and yywrap() then
1210 | begin
1211 | yyclear;
1212 | return(0);
1213 | end;
1214 |
1215 | if not yydone then goto start;
1216 |
1217 | yylex := yyretval;
1218 |
1219 | end(*yylex*);
1220 |
1221 |
1222 |
--------------------------------------------------------------------------------
/src/mcrf.pas:
--------------------------------------------------------------------------------
1 | PROGRAM MCRF;
2 |
3 | // This code is made by Uto, but strongly based on original Hisoft C code made my Tim Gilberts and maybe Graeme Yeandle.
4 |
5 | // Creates a run file for the Amstrad CPC system. This combines the required interpreter with a given database and graphics
6 | // database (all of which have a CPC header), also adds a CPC header to result file.
7 |
8 | {$MODE OBJFPC}
9 |
10 | USES sysutils, strutils;
11 |
12 |
13 | CONST DUMMY_HEADER : array[0..127] of byte = ($00 , $47 , $49 , $4C , $42 , $45 , $52 , $54 , $53 , $42 , $49 , $4E , $00 , $00 , $00 , $00 , $00 , $00 , $02 , $00 , $00 , $40 , $08 , $00 , $45 , $1D , $79 , $24 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $45 , $1D , $00 , $E0 , $04 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00 , $00);
14 | CONST VERSION=03; (* Increased from original 01 for non CP/M version *)
15 | CONST FILEV=00;
16 | CONST PATHLEN=64;
17 | CONST IPSSIZE=128;
18 | CONST DBADD=$2880;
19 | CONST INTAT=$0840;
20 | CONST SPARE=$0020;
21 |
22 | TYPE cpcHeaderType = ARRAY[0..127] of Byte;
23 |
24 | VAR OutputFile, InputFile : FILE;
25 | cpcHeader: cpcHeaderType;
26 | c: integer;
27 | Buffer1Byte: Byte;
28 | FileLength : Word;
29 | GraphicsLength : Word;
30 | RealDDBLength: Word;
31 | RealInterpreterLength: Word;
32 | CharsetOffset : Word;
33 |
34 |
35 | FUNCTION ReadHeaderWord(index: byte): Word;
36 | BEGIN
37 | Result := cpcHeader[index] + 256 * cpcHeader[index+1];
38 | END;
39 |
40 | PROCEDURE WriteHeaderWord(index: Byte; val: Word);
41 | BEGIN
42 | cpcHeader[index] := val MOD 256;
43 | cpcHeader[index+1] := val DIV 256;
44 | END;
45 |
46 | PROCEDURE Error(S:String);
47 | BEGIN
48 | Writeln(S + '.');
49 | Writeln();
50 | Halt(2);
51 | END;
52 |
53 |
54 | PROCEDURE SetHeader(LoadAddress, FileLength: Word; fullfileName:String; RunAddres: Word);
55 | VAR AuxStr: String;
56 | j : byte;
57 | checksum: word;
58 | BEGIN
59 |
60 | WriteLn('Load address :', LoadAddress);
61 | WriteLn('Run address :', RunAddres);
62 | Writeln('File size :', FileLength);
63 |
64 |
65 | WriteHeaderWord(21, LoadAddress);
66 | WriteHeaderWord(26, RunAddres);
67 | WriteHeaderWord(24, FileLength);
68 | cpcHeader[66] := 0;
69 | WriteHeaderWord(64, FileLength); // together with previous line, 24 bits file length, just a copy
70 |
71 |
72 | // Get file name
73 | AuxStr := ExtractFileName(UpperCase(fullfileName));
74 | AuxStr := ChangeFileExt(AuxStr,'');
75 | IF Length(AuxStr) > 8 THEN Error('Output file name too long, maximum 11 characters');
76 | AuxStr := PadRight(AuxStr,8);
77 | Move(AuxStr[1], cpcHeader[1],8);
78 | Writeln('File name :', AuxStr);
79 |
80 |
81 | // Get file extension
82 | AuxStr := ExtractFileExt(UpperCase(fullfileName));
83 | AuxStr := Copy(AuxStr, 2, 100);
84 | AuxStr := PadRight(AuxStr,3);
85 | IF Length(AuxStr) > 3 THEN Error('Output file name extension too long, maximum 3 characters');
86 | Move(AuxStr[1], cpcHeader[9],3);
87 | Writeln('File extension :', AuxStr);
88 |
89 | // Calculate checksum
90 | checksum := 0;
91 | FOR j:= 0 TO 66 DO checksum := checksum + cpcHeader[j];
92 | WriteHeaderWord(67, checksum);
93 | Writeln('Checksum :', checksum);
94 | end;
95 |
96 |
97 | PROCEDURE Syntax();
98 | BEGIN
99 | Writeln();
100 | WriteLn('SYNTAX: MCRF [font file]');
101 | Writeln();
102 | Writeln('Example: MCRF MYGAME.BIN INT.Z80 MYGAME.DDB MYGAME.GRA');
103 | Writeln('Example: MCRF MYGAME.BIN INT.Z80 MYGAME.DDB MYGAME.GRA PAW1.CHR');
104 | Writeln();
105 | Writeln('Important: The graphics file should have an AMSDOS header. The DDB (text database) and the interpreter files may have it or not, MCRF will auto-detect it.');
106 | WriteLn('CHR files are raw definition of 8x8 characters, 256 total, so it should be a 256 x 8 bytes file (2048). If an Amsdos header is present, it will be ignored.');
107 | Halt(1);
108 | END;
109 |
110 | BEGIN
111 | WriteLn('Make CPC run file on PC. VERSION ', VERSION, ' FILE VERSION ', FILEV);
112 | WriteLn('(c) 1989-2018 Infinite Imaginations.');
113 | WriteLn('Original code for CP/M written by T.J.Gilberts using Hisoft C.');
114 | WriteLn('Rebuilt in pascal by Uto in 2018');
115 |
116 | IF NOT(ParamCount() IN [4,5]) THEN Syntax();
117 |
118 | AssignFile(OutputFile, ParamStr(1));
119 | TRY
120 | Rewrite(OutputFile, 1);
121 | EXCEPT
122 | on E: Exception DO Error('Invalid output file.');
123 | END;
124 |
125 | WriteLn(ParamStr(1), ' open for output');
126 |
127 | AssignFile(InputFile, ParamStr(2)); // The interpreter
128 | TRY
129 | Reset(InputFile, 1);
130 | EXCEPT
131 | on E: Exception DO Error('Interpreter file not found or invalid.');
132 | END;
133 |
134 | Write('Interpreter length is ');
135 | Blockread(InputFile, cpcHeader, 128); (* Get CPC header *)
136 | IF (FileSize(InputFile) = (ReadHeaderWord(24) + 128) ) THEN
137 | BEGIN
138 | RealInterpreterLength := ReadHeaderWord(24); // has AMSDOS header
139 | BlockWrite(OutputFile, cpcHeader, 128); (* Make dummy CPC header *)
140 | END
141 | ELSE
142 | BEGIN
143 | RealInterpreterLength := FileSize(InputFile); // doesn't have AMSDOS header
144 | FOR c:=0 TO 127 DO (* Make dummy CPC header *)
145 | BEGIN
146 | Buffer1Byte := DUMMY_HEADER[c];
147 | BlockWrite(OutputFile, Buffer1Byte, 1);
148 | END;
149 | Seek(InputFile, 0); // Rewind
150 | END;
151 |
152 | WriteLn(RealInterpreterLength, ' bytes.');
153 |
154 | FOR c:=1 TO RealInterpreterLength DO
155 | BEGIN
156 | Blockread(InputFile, Buffer1Byte, 1);
157 | BlockWrite(OutputFile, Buffer1Byte, 1);
158 | END;
159 | CloseFile(InputFile);
160 |
161 | IF ((DBADD-INTAT)> RealInterpreterLength) THEN
162 | BEGIN
163 | WriteLn('Padding to db position using ',DBADD - INTAT - RealInterpreterLength,' bytes.');
164 | Buffer1Byte := 0;
165 | FOR c:= 1 TO DBADD - INTAT - RealInterpreterLength DO
166 | BlockWrite(OutputFile, Buffer1Byte, 1);
167 | END;
168 |
169 |
170 | AssignFile(InputFile, ParamStr(3)); // The DDB file
171 | TRY
172 | Reset(InputFile, 1);
173 | EXCEPT
174 | on E: Exception DO Error('Text database file not found or invalid.');
175 | END;
176 |
177 | Write('Text database file length is ');
178 | Blockread(InputFile, cpcHeader, 128); (* Get CPC header *)
179 | IF (FileSize(InputFile) = (ReadHeaderWord(24) + 128) ) THEN RealDDBLength := ReadHeaderWord(24) // has AMSDOS header
180 | ELSE
181 | BEGIN // Get from spare
182 | RealDDBLength := FileSize(InputFile);
183 | Seek(InputFile, 0); // Rewind
184 | END;
185 | WriteLn(RealDDBLength, ' bytes.');
186 | FOR c:=1 TO RealDDBLength DO
187 | BEGIN
188 | Blockread(InputFile, Buffer1Byte, 1);
189 | BlockWrite(OutputFile, Buffer1Byte, 1);
190 | END;
191 |
192 |
193 | FileLength := DBADD - INTAT + RealDDBLength;
194 | CloseFile(InputFile);
195 |
196 | CharsetOffset := Filepos(OutputFile);
197 |
198 | AssignFile(InputFile, ParamStr(4)); // The graphics database
199 | TRY
200 | Reset(InputFile, 1);
201 | EXCEPT
202 | on E: Exception DO Error('Graphics database file not found or invalid.');
203 | END;
204 |
205 | Write('Graphics database file length is ');
206 | Blockread(InputFile, cpcHeader, 128); (* Get CPC header *)
207 | WriteLn(ReadHeaderWord(24), ' bytes.');
208 | FOR c:=1 TO ReadHeaderWord(24) DO
209 | BEGIN
210 | Blockread(InputFile, Buffer1Byte, 1);
211 | BlockWrite(OutputFile, Buffer1Byte, 1);
212 | END;
213 | CloseFile(InputFile);
214 |
215 | IF (ParamCount>4) THEN
216 | BEGIN
217 | AssignFile(InputFile, ParamStr(5)); // The font file
218 | TRY
219 | Reset(InputFile, 1);
220 | EXCEPT
221 | on E: Exception DO Error('Font file not found or invalid.');
222 | END;
223 | //Seek(OutputFile, FileSize(OutputFile)-128);
224 | Seek(OutputFile, CharsetOffset +48);
225 | WriteLn('Loading font file.');
226 | IF (fileSize(InputFile)<>2048) AND (fileSize(InputFile)<>2048+128) THEN Error('Invalid size of font file.');
227 | IF fileSize(InputFile)=2048+128 THEN Seek(InputFile, 128);
228 | FOR C:=1 TO 2048 DO
229 | BEGIN
230 | BlockRead(InputFile, Buffer1Byte, 1);
231 | BlockWrite(OutputFile, Buffer1Byte, 1);
232 | END;
233 | CloseFile(InputFile);
234 | END;
235 |
236 | GraphicsLength := ReadHeaderWord(24);
237 | FileLength := FileLength + GraphicsLength;
238 |
239 | Writeln('Creating valid CPC header block');
240 | Writeln('-------------------------------');
241 | SetHeader(INTAT,FileLength,ParamStr(1),INTAT);
242 | Seek(OutputFile,0); (* Rewind file to overwrite CPC interp header *)
243 | BlockWrite(OutputFile,cpcHeader,128); (* Make CPC header valid *)
244 | Seek(OutputFile,3+128); (* Move on to patch length of graphic data *)
245 | BlockWrite(OutputFile, GraphicsLength, 2);
246 | CloseFile(OutputFile);
247 | Writeln('Graphics length:', GraphicsLength);
248 | Writeln('-------------------------------');
249 | WriteLn('Complete. Files closed.');
250 |
251 | END.
--------------------------------------------------------------------------------