├── LICENSE
├── assembler.js
├── es5-shim.js
├── index.html
└── style.css
/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 |
--------------------------------------------------------------------------------
/assembler.js:
--------------------------------------------------------------------------------
1 | /*
2 | * 6502 assembler and simulator in Javascript
3 | * (C)2006-2010 Stian Soreng - www.6502asm.com
4 | *
5 | * Adapted by Nick Morgan
6 | * https://github.com/skilldrick/6502js
7 | *
8 | * Released under the GNU General Public License
9 | * see http://gnu.org/licenses/gpl.html
10 | */
11 |
12 |
13 | function SimulatorWidget(node) {
14 | var $node = $(node);
15 | var ui = UI();
16 | var display = Display();
17 | var memory = Memory();
18 | var labels = Labels();
19 | var simulator = Simulator();
20 | var assembler = Assembler();
21 |
22 | function initialize() {
23 | stripText();
24 | ui.initialize();
25 | display.initialize();
26 | simulator.reset();
27 |
28 | $node.find('.assembleButton').click(function () {
29 | assembler.assembleCode();
30 | });
31 | $node.find('.runButton').click(simulator.runBinary);
32 | $node.find('.runButton').click(simulator.stopDebugger);
33 | $node.find('.resetButton').click(simulator.reset);
34 | $node.find('.hexdumpButton').click(assembler.hexdump);
35 | $node.find('.disassembleButton').click(assembler.disassemble);
36 | $node.find('.debug').change(function () {
37 | var debug = $(this).is(':checked');
38 | if (debug) {
39 | ui.debugOn();
40 | simulator.enableDebugger();
41 | } else {
42 | ui.debugOff();
43 | simulator.stopDebugger();
44 | }
45 | });
46 | $node.find('.monitoring').change(function () {
47 | ui.toggleMonitor();
48 | simulator.toggleMonitor();
49 | });
50 | $node.find('.stepButton').click(simulator.debugExec);
51 | $node.find('.gotoButton').click(simulator.gotoAddr);
52 | $node.find('.notesButton').click(ui.showNotes);
53 | $node.find('.code').keypress(simulator.stop);
54 | $node.find('.code').keypress(ui.initialize);
55 | $(document).keypress(memory.storeKeypress);
56 | }
57 |
58 | function stripText() {
59 | //Remove leading and trailing space in textarea
60 | var text = $node.find('.code').val();
61 | text = text.replace(/^\n+/, '').replace(/\s+$/, '');
62 | $node.find('.code').val(text);
63 | }
64 |
65 | function UI() {
66 | var currentState;
67 |
68 | var start = {
69 | assemble: true,
70 | run: [false, 'Run'],
71 | reset: false,
72 | hexdump: false,
73 | disassemble: false,
74 | debug: [false, false]
75 | };
76 | var assembled = {
77 | assemble: false,
78 | run: [true, 'Run'],
79 | reset: true,
80 | hexdump: true,
81 | disassemble: true,
82 | debug: [true, false]
83 | };
84 | var running = {
85 | assemble: false,
86 | run: [true, 'Stop'],
87 | reset: true,
88 | hexdump: false,
89 | disassemble: false,
90 | debug: [true, false]
91 | };
92 | var debugging = {
93 | assemble: false,
94 | reset: true,
95 | hexdump: true,
96 | disassemble: true,
97 | debug: [true, true]
98 | };
99 | var postDebugging = {
100 | assemble: false,
101 | reset: true,
102 | hexdump: true,
103 | disassemble: true,
104 | debug: [true, false]
105 | };
106 |
107 |
108 | function setState(state) {
109 | $node.find('.assembleButton').attr('disabled', !state.assemble);
110 | if (state.run) {
111 | $node.find('.runButton').attr('disabled', !state.run[0]);
112 | $node.find('.runButton').val(state.run[1]);
113 | }
114 | $node.find('.resetButton').attr('disabled', !state.reset);
115 | $node.find('.hexdumpButton').attr('disabled', !state.hexdump);
116 | $node.find('.disassembleButton').attr('disabled', !state.disassemble);
117 | $node.find('.debug').attr('disabled', !state.debug[0]);
118 | $node.find('.debug').attr('checked', state.debug[1]);
119 | $node.find('.stepButton').attr('disabled', !state.debug[1]);
120 | $node.find('.gotoButton').attr('disabled', !state.debug[1]);
121 | currentState = state;
122 | }
123 |
124 | function initialize() {
125 | setState(start);
126 | }
127 |
128 | function play() {
129 | setState(running);
130 | }
131 |
132 | function stop() {
133 | setState(assembled);
134 | }
135 |
136 | function debugOn() {
137 | setState(debugging);
138 | }
139 |
140 | function debugOff() {
141 | setState(postDebugging);
142 | }
143 |
144 | function assembleSuccess() {
145 | setState(assembled);
146 | }
147 |
148 | function toggleMonitor() {
149 | $node.find('.monitor').toggle();
150 | }
151 |
152 | function showNotes() {
153 | $node.find('.messages code').html($node.find('.notes').html());
154 | }
155 |
156 | return {
157 | initialize: initialize,
158 | play: play,
159 | stop: stop,
160 | assembleSuccess: assembleSuccess,
161 | debugOn: debugOn,
162 | debugOff: debugOff,
163 | toggleMonitor: toggleMonitor,
164 | showNotes: showNotes
165 | };
166 | }
167 |
168 |
169 | function Display() {
170 | var displayArray = [];
171 | var palette = [
172 | "#000000", "#ffffff", "#880000", "#aaffee",
173 | "#cc44cc", "#00cc55", "#0000aa", "#eeee77",
174 | "#dd8855", "#664400", "#ff7777", "#333333",
175 | "#777777", "#aaff66", "#0088ff", "#bbbbbb"
176 | ];
177 | var ctx;
178 | var width;
179 | var height;
180 | var pixelSize;
181 | var numX = 32;
182 | var numY = 32;
183 |
184 | function initialize() {
185 | var canvas = $node.find('.screen')[0];
186 | width = canvas.width;
187 | height = canvas.height;
188 | pixelSize = width / numX;
189 | ctx = canvas.getContext('2d');
190 | reset();
191 | }
192 |
193 | function reset() {
194 | ctx.fillStyle = "black";
195 | ctx.fillRect(0, 0, width, height);
196 | }
197 |
198 | function updatePixel(addr) {
199 | ctx.fillStyle = palette[memory.get(addr) & 0x0f];
200 | var y = Math.floor((addr - 0x200) / 32);
201 | var x = (addr - 0x200) % 32;
202 | ctx.fillRect(x * pixelSize, y * pixelSize, pixelSize, pixelSize);
203 | }
204 |
205 | return {
206 | initialize: initialize,
207 | reset: reset,
208 | updatePixel: updatePixel
209 | };
210 | }
211 |
212 | function Memory() {
213 | var memArray = new Array(0x600);
214 |
215 | function set(addr, val) {
216 | return memArray[addr] = val;
217 | }
218 |
219 | function get(addr) {
220 | return memArray[addr];
221 | }
222 |
223 | function getWord(addr) {
224 | return get(addr) + (get(addr + 1) << 8);
225 | }
226 |
227 | // storeByte() - Poke a byte, don't touch any registers
228 |
229 | function storeByte(addr, value) {
230 | set(addr, value & 0xff);
231 | if ((addr >= 0x200) && (addr <= 0x5ff)) {
232 | display.updatePixel(addr);
233 | }
234 | }
235 |
236 | // storeKeypress() - Store keycode in ZP $ff
237 | function storeKeypress(e) {
238 | value = e.which;
239 | memory.storeByte(0xff, value);
240 | }
241 |
242 | function format(start, length) {
243 | var html = '';
244 | var n;
245 |
246 | for (var x = 0; x < length; x++) {
247 | if ((x & 15) === 0) {
248 | if (x > 0) { html += "\n"; }
249 | n = (start + x);
250 | html += num2hex(((n >> 8) & 0xff));
251 | html += num2hex((n & 0xff));
252 | html += ": ";
253 | }
254 | html += num2hex(memory.get(start + x));
255 | html += " ";
256 | }
257 | return html;
258 | }
259 |
260 | return {
261 | set: set,
262 | get: get,
263 | getWord: getWord,
264 | storeByte: storeByte,
265 | storeKeypress: storeKeypress,
266 | format: format
267 | };
268 | }
269 |
270 | function Simulator() {
271 | var regA = 0;
272 | var regX = 0;
273 | var regY = 0;
274 | var regP = 0;
275 | var regPC = 0x600;
276 | var regSP = 0xff;
277 | var codeRunning = false;
278 | var debug = false;
279 | var monitoring = false;
280 | var executeId;
281 |
282 | //set zero and negative processor flags based on result
283 | function setNVflags(value) {
284 | if (value) {
285 | regP &= 0xfd;
286 | } else {
287 | regP |= 0x02;
288 | }
289 | if (value & 0x80) {
290 | regP |= 0x80;
291 | } else {
292 | regP &= 0x7f;
293 | }
294 | }
295 |
296 | function setCarryFlagFromBit0(value) {
297 | regP = (regP & 0xfe) | (value & 1);
298 | }
299 |
300 | function setCarryFlagFromBit7(value) {
301 | regP = (regP & 0xfe) | ((value >> 7) & 1);
302 | }
303 |
304 | function setNVflagsForRegA() {
305 | setNVflags(regA);
306 | }
307 |
308 | function setNVflagsForRegX() {
309 | setNVflags(regX);
310 | }
311 |
312 | function setNVflagsForRegY() {
313 | setNVflags(regY);
314 | }
315 |
316 | var ORA = setNVflagsForRegA;
317 | var AND = setNVflagsForRegA;
318 | var EOR = setNVflagsForRegA;
319 | var ASL = setNVflags;
320 | var LSR = setNVflags;
321 | var ROL = setNVflags;
322 | var ROR = setNVflags;
323 | var LDA = setNVflagsForRegA;
324 | var LDX = setNVflagsForRegX;
325 | var LDY = setNVflagsForRegY;
326 |
327 | function BIT(value) {
328 | if (value & 0x80) {
329 | regP |= 0x80;
330 | } else {
331 | regP &= 0x7f;
332 | }
333 | if (value & 0x40) {
334 | regP |= 0x40;
335 | } else {
336 | regP &= ~0x40;
337 | }
338 | if (regA & value) {
339 | regP &= 0xfd;
340 | } else {
341 | regP |= 0x02;
342 | }
343 | }
344 |
345 | function CLC() {
346 | regP &= 0xfe;
347 | }
348 |
349 | function SEC() {
350 | regP |= 1;
351 | }
352 |
353 |
354 | function CLV() {
355 | regP &= 0xbf;
356 | }
357 |
358 | function setOverflow() {
359 | regP |= 0x40;
360 | }
361 |
362 | function DEC(addr) {
363 | var value = memory.get(addr);
364 | value--;
365 | value &= 0xff;
366 | memory.storeByte(addr, value);
367 | setNVflags(value);
368 | }
369 |
370 | function INC(addr) {
371 | var value = memory.get(addr);
372 | value++;
373 | value &= 0xff;
374 | memory.storeByte(addr, value);
375 | setNVflags(value);
376 | }
377 |
378 | function jumpBranch(offset) {
379 | if (offset > 0x7f) {
380 | regPC = (regPC - (0x100 - offset));
381 | } else {
382 | regPC = (regPC + offset);
383 | }
384 | }
385 |
386 | function overflowSet() {
387 | return regP & 0x40;
388 | }
389 |
390 | function decimalMode() {
391 | return regP & 8;
392 | }
393 |
394 | function carrySet() {
395 | return regP & 1;
396 | }
397 |
398 | function negativeSet() {
399 | return regP & 0x80;
400 | }
401 |
402 | function zeroSet() {
403 | return regP & 0x02;
404 | }
405 |
406 | function doCompare(reg, val) {
407 | if (reg >= val) {
408 | SEC();
409 | } else {
410 | CLC();
411 | }
412 | val = (reg - val);
413 | setNVflags(val);
414 | }
415 |
416 | function testSBC(value) {
417 | var tmp, w;
418 | if ((regA ^ value) & 0x80) {
419 | setOverflow();
420 | } else {
421 | CLV();
422 | }
423 |
424 | if (decimalMode()) {
425 | tmp = 0xf + (regA & 0xf) - (value & 0xf) + carrySet();
426 | if (tmp < 0x10) {
427 | w = 0;
428 | tmp -= 6;
429 | } else {
430 | w = 0x10;
431 | tmp -= 0x10;
432 | }
433 | w += 0xf0 + (regA & 0xf0) - (value & 0xf0);
434 | if (w < 0x100) {
435 | CLC();
436 | if (overflowSet() && w < 0x80) { CLV(); }
437 | w -= 0x60;
438 | } else {
439 | SEC();
440 | if (overflowSet() && w >= 0x180) { CLV(); }
441 | }
442 | w += tmp;
443 | } else {
444 | w = 0xff + regA - value + carrySet();
445 | if (w < 0x100) {
446 | CLC();
447 | if (overflowSet() && w < 0x80) { CLV(); }
448 | } else {
449 | SEC();
450 | if (overflowSet() && w >= 0x180) { CLV(); }
451 | }
452 | }
453 | regA = w & 0xff;
454 | setNVflagsForRegA();
455 | }
456 |
457 | function testADC(value) {
458 | var tmp;
459 | if ((regA ^ value) & 0x80) {
460 | CLV();
461 | } else {
462 | setOverflow();
463 | }
464 |
465 | if (decimalMode()) {
466 | tmp = (regA & 0xf) + (value & 0xf) + carrySet();
467 | if (tmp >= 10) {
468 | tmp = 0x10 | ((tmp + 6) & 0xf);
469 | }
470 | tmp += (regA & 0xf0) + (value & 0xf0);
471 | if (tmp >= 160) {
472 | SEC();
473 | if (overflowSet() && tmp >= 0x180) { CLV(); }
474 | tmp += 0x60;
475 | } else {
476 | CLC();
477 | if (overflowSet() && tmp < 0x80) { CLV(); }
478 | }
479 | } else {
480 | tmp = regA + value + carrySet();
481 | if (tmp >= 0x100) {
482 | SEC();
483 | if (overflowSet() && tmp >= 0x180) { CLV(); }
484 | } else {
485 | CLC();
486 | if (overflowSet() && tmp < 0x80) { CLV(); }
487 | }
488 | }
489 | regA = tmp & 0xff;
490 | setNVflagsForRegA();
491 | }
492 |
493 | var instructions = {
494 | i00: function () {
495 | codeRunning = false;
496 | //BRK
497 | },
498 |
499 | i01: function () {
500 | var zp = (popByte() + regX) & 0xff;
501 | var addr = memory.getWord(zp);
502 | var value = memory.get(addr);
503 | regA |= value;
504 | ORA();
505 | },
506 |
507 | i05: function () {
508 | var zp = popByte();
509 | regA |= memory.get(zp);
510 | ORA();
511 | },
512 |
513 | i06: function () {
514 | var zp = popByte();
515 | var value = memory.get(zp);
516 | setCarryFlagFromBit7(value);
517 | value = value << 1;
518 | memory.storeByte(zp, value);
519 | ASL(value);
520 | },
521 |
522 | i08: function () {
523 | stackPush(regP | 0x30);
524 | //PHP
525 | },
526 |
527 | i09: function () {
528 | regA |= popByte();
529 | ORA();
530 | },
531 |
532 | i0a: function () {
533 | setCarryFlagFromBit7(regA);
534 | regA = (regA << 1) & 0xff;
535 | ASL(regA);
536 | },
537 |
538 | i0d: function () {
539 | regA |= memory.get(popWord());
540 | ORA();
541 | },
542 |
543 | i0e: function () {
544 | var addr = popWord();
545 | var value = memory.get(addr);
546 | setCarryFlagFromBit7(value);
547 | value = value << 1;
548 | memory.storeByte(addr, value);
549 | ASL(value);
550 | },
551 |
552 | i10: function () {
553 | var offset = popByte();
554 | if (!negativeSet()) { jumpBranch(offset); }
555 | //BPL
556 | },
557 |
558 | i11: function () {
559 | var zp = popByte();
560 | var value = memory.getWord(zp) + regY;
561 | regA |= memory.get(value);
562 | ORA();
563 | },
564 |
565 | i15: function () {
566 | var addr = (popByte() + regX) & 0xff;
567 | regA |= memory.get(addr);
568 | ORA();
569 | },
570 |
571 | i16: function () {
572 | var addr = (popByte() + regX) & 0xff;
573 | var value = memory.get(addr);
574 | setCarryFlagFromBit7(value);
575 | value = value << 1;
576 | memory.storeByte(addr, value);
577 | ASL(value);
578 | },
579 |
580 | i18: function () {
581 | CLC();
582 | },
583 |
584 | i19: function () {
585 | var addr = popWord() + regY;
586 | regA |= memory.get(addr);
587 | ORA();
588 | },
589 |
590 | i1d: function () {
591 | var addr = popWord() + regX;
592 | regA |= memory.get(addr);
593 | ORA();
594 | },
595 |
596 | i1e: function () {
597 | var addr = popWord() + regX;
598 | var value = memory.get(addr);
599 | setCarryFlagFromBit7(value);
600 | value = value << 1;
601 | memory.storeByte(addr, value);
602 | ASL(value);
603 | },
604 |
605 | i20: function () {
606 | var addr = popWord();
607 | var currAddr = regPC - 1;
608 | stackPush(((currAddr >> 8) & 0xff));
609 | stackPush((currAddr & 0xff));
610 | regPC = addr;
611 | //JSR
612 | },
613 |
614 | i21: function () {
615 | var zp = (popByte() + regX) & 0xff;
616 | var addr = memory.getWord(zp);
617 | var value = memory.get(addr);
618 | regA &= value;
619 | AND();
620 | },
621 |
622 | i24: function () {
623 | var zp = popByte();
624 | var value = memory.get(zp);
625 | BIT(value);
626 | },
627 |
628 | i25: function () {
629 | var zp = popByte();
630 | regA &= memory.get(zp);
631 | AND();
632 | },
633 |
634 | i26: function () {
635 | var sf = carrySet();
636 | var addr = popByte();
637 | var value = memory.get(addr);
638 | setCarryFlagFromBit7(value);
639 | value = value << 1;
640 | value |= sf;
641 | memory.storeByte(addr, value);
642 | ROL(value);
643 | },
644 |
645 | i28: function () {
646 | regP = stackPop() | 0x30; // There is no B bit!
647 | //PLP
648 | },
649 |
650 | i29: function () {
651 | regA &= popByte();
652 | AND();
653 | },
654 |
655 | i2a: function () {
656 | var sf = carrySet();
657 | setCarryFlagFromBit7(regA);
658 | regA = (regA << 1) & 0xff;
659 | regA |= sf;
660 | ROL(regA);
661 | },
662 |
663 | i2c: function () {
664 | var value = memory.get(popWord());
665 | BIT(value);
666 | },
667 |
668 | i2d: function () {
669 | var value = memory.get(popWord());
670 | regA &= value;
671 | AND();
672 | },
673 |
674 | i2e: function () {
675 | var sf = carrySet();
676 | var addr = popWord();
677 | var value = memory.get(addr);
678 | setCarryFlagFromBit7(value);
679 | value = value << 1;
680 | value |= sf;
681 | memory.storeByte(addr, value);
682 | ROL(value);
683 | },
684 |
685 | i30: function () {
686 | var offset = popByte();
687 | if (negativeSet()) { jumpBranch(offset); }
688 | //BMI
689 | },
690 |
691 | i31: function () {
692 | var zp = popByte();
693 | var value = memory.getWord(zp) + regY;
694 | regA &= memory.get(value);
695 | AND();
696 | },
697 |
698 | i35: function () {
699 | var addr = (popByte() + regX) & 0xff;
700 | regA &= memory.get(addr);
701 | AND();
702 | },
703 |
704 | i36: function () {
705 | var sf = carrySet();
706 | var addr = (popByte() + regX) & 0xff;
707 | var value = memory.get(addr);
708 | setCarryFlagFromBit7(value);
709 | value = value << 1;
710 | value |= sf;
711 | memory.storeByte(addr, value);
712 | ROL(value);
713 | },
714 |
715 | i38: function () {
716 | SEC();
717 | },
718 |
719 | i39: function () {
720 | var addr = popWord() + regY;
721 | var value = memory.get(addr);
722 | regA &= value;
723 | AND();
724 | },
725 |
726 | i3d: function () {
727 | var addr = popWord() + regX;
728 | var value = memory.get(addr);
729 | regA &= value;
730 | AND();
731 | },
732 |
733 | i3e: function () {
734 | var sf = carrySet();
735 | var addr = popWord() + regX;
736 | var value = memory.get(addr);
737 | setCarryFlagFromBit7(value);
738 | value = value << 1;
739 | value |= sf;
740 | memory.storeByte(addr, value);
741 | ROL(value);
742 | },
743 |
744 | i40: function () {
745 | regP = stackPop() | 0x30; // There is no B bit!
746 | regPC = stackPop() | (stackPop() << 8);
747 | //RTI
748 | },
749 |
750 | i41: function () {
751 | var zp = (popByte() + regX) & 0xff;
752 | var value = memory.getWord(zp);
753 | regA ^= memory.get(value);
754 | EOR();
755 | },
756 |
757 | i45: function () {
758 | var addr = popByte() & 0xff;
759 | var value = memory.get(addr);
760 | regA ^= value;
761 | EOR();
762 | },
763 |
764 | i46: function () {
765 | var addr = popByte() & 0xff;
766 | var value = memory.get(addr);
767 | setCarryFlagFromBit0(value);
768 | value = value >> 1;
769 | memory.storeByte(addr, value);
770 | LSR(value);
771 | },
772 |
773 | i48: function () {
774 | stackPush(regA);
775 | //PHA
776 | },
777 |
778 | i49: function () {
779 | regA ^= popByte();
780 | EOR();
781 | },
782 |
783 | i4a: function () {
784 | setCarryFlagFromBit0(regA);
785 | regA = regA >> 1;
786 | LSR(regA);
787 | },
788 |
789 | i4c: function () {
790 | regPC = popWord();
791 | //JMP
792 | },
793 |
794 | i4d: function () {
795 | var addr = popWord();
796 | var value = memory.get(addr);
797 | regA ^= value;
798 | EOR();
799 | },
800 |
801 | i4e: function () {
802 | var addr = popWord();
803 | var value = memory.get(addr);
804 | setCarryFlagFromBit0(value);
805 | value = value >> 1;
806 | memory.storeByte(addr, value);
807 | LSR(value);
808 | },
809 |
810 | i50: function () {
811 | var offset = popByte();
812 | if (!overflowSet()) { jumpBranch(offset); }
813 | //BVC
814 | },
815 |
816 | i51: function () {
817 | var zp = popByte();
818 | var value = memory.getWord(zp) + regY;
819 | regA ^= memory.get(value);
820 | EOR();
821 | },
822 |
823 | i55: function () {
824 | var addr = (popByte() + regX) & 0xff;
825 | regA ^= memory.get(addr);
826 | EOR();
827 | },
828 |
829 | i56: function () {
830 | var addr = (popByte() + regX) & 0xff;
831 | var value = memory.get(addr);
832 | setCarryFlagFromBit0(value);
833 | value = value >> 1;
834 | memory.storeByte(addr, value);
835 | LSR(value);
836 | },
837 |
838 | i58: function () {
839 | regP &= ~0x04;
840 | throw new Error("Interrupts not implemented");
841 | //CLI
842 | },
843 |
844 | i59: function () {
845 | var addr = popWord() + regY;
846 | var value = memory.get(addr);
847 | regA ^= value;
848 | EOR();
849 | },
850 |
851 | i5d: function () {
852 | var addr = popWord() + regX;
853 | var value = memory.get(addr);
854 | regA ^= value;
855 | EOR();
856 | },
857 |
858 | i5e: function () {
859 | var addr = popWord() + regX;
860 | var value = memory.get(addr);
861 | setCarryFlagFromBit0(value);
862 | value = value >> 1;
863 | memory.storeByte(addr, value);
864 | LSR(value);
865 | },
866 |
867 | i60: function () {
868 | regPC = (stackPop() | (stackPop() << 8)) + 1;
869 | //RTS
870 | },
871 |
872 | i61: function () {
873 | var zp = (popByte() + regX) & 0xff;
874 | var addr = memory.getWord(zp);
875 | var value = memory.get(addr);
876 | testADC(value);
877 | //ADC
878 | },
879 |
880 | i65: function () {
881 | var addr = popByte();
882 | var value = memory.get(addr);
883 | testADC(value);
884 | //ADC
885 | },
886 |
887 | i66: function () {
888 | var sf = carrySet();
889 | var addr = popByte();
890 | var value = memory.get(addr);
891 | setCarryFlagFromBit0(value);
892 | value = value >> 1;
893 | if (sf) { value |= 0x80; }
894 | memory.storeByte(addr, value);
895 | ROR(value);
896 | },
897 |
898 | i68: function () {
899 | regA = stackPop();
900 | setNVflagsForRegA();
901 | //PLA
902 | },
903 |
904 | i69: function () {
905 | var value = popByte();
906 | testADC(value);
907 | //ADC
908 | },
909 |
910 | i6a: function () {
911 | var sf = carrySet();
912 | setCarryFlagFromBit0(regA);
913 | regA = regA >> 1;
914 | if (sf) { regA |= 0x80; }
915 | ROR(regA);
916 | },
917 |
918 | i6c: function () {
919 | regPC = memory.getWord(popWord());
920 | //JMP
921 | },
922 |
923 | i6d: function () {
924 | var addr = popWord();
925 | var value = memory.get(addr);
926 | testADC(value);
927 | //ADC
928 | },
929 |
930 | i6e: function () {
931 | var sf = carrySet();
932 | var addr = popWord();
933 | var value = memory.get(addr);
934 | setCarryFlagFromBit0(value);
935 | value = value >> 1;
936 | if (sf) { value |= 0x80; }
937 | memory.storeByte(addr, value);
938 | ROR(value);
939 | },
940 |
941 | i70: function () {
942 | var offset = popByte();
943 | if (overflowSet()) { jumpBranch(offset); }
944 | //BVS
945 | },
946 |
947 | i71: function () {
948 | var zp = popByte();
949 | var addr = memory.getWord(zp);
950 | var value = memory.get(addr + regY);
951 | testADC(value);
952 | //ADC
953 | },
954 |
955 | i75: function () {
956 | var addr = (popByte() + regX) & 0xff;
957 | var value = memory.get(addr);
958 | testADC(value);
959 | //ADC
960 | },
961 |
962 | i76: function () {
963 | var sf = carrySet();
964 | var addr = (popByte() + regX) & 0xff;
965 | var value = memory.get(addr);
966 | setCarryFlagFromBit0(value);
967 | value = value >> 1;
968 | if (sf) { value |= 0x80; }
969 | memory.storeByte(addr, value);
970 | ROR(value);
971 | },
972 |
973 | i78: function () {
974 | regP |= 0x04;
975 | throw new Error("Interrupts not implemented");
976 | //SEI
977 | },
978 |
979 | i79: function () {
980 | var addr = popWord();
981 | var value = memory.get(addr + regY);
982 | testADC(value);
983 | //ADC
984 | },
985 |
986 | i7d: function () {
987 | var addr = popWord();
988 | var value = memory.get(addr + regX);
989 | testADC(value);
990 | //ADC
991 | },
992 |
993 | i7e: function () {
994 | var sf = carrySet();
995 | var addr = popWord() + regX;
996 | var value = memory.get(addr);
997 | setCarryFlagFromBit0(value);
998 | value = value >> 1;
999 | if (sf) { value |= 0x80; }
1000 | memory.storeByte(addr, value);
1001 | ROR(value);
1002 | },
1003 |
1004 | i81: function () {
1005 | var zp = (popByte() + regX) & 0xff;
1006 | var addr = memory.getWord(zp);
1007 | memory.storeByte(addr, regA);
1008 | //STA
1009 | },
1010 |
1011 | i84: function () {
1012 | memory.storeByte(popByte(), regY);
1013 | //STY
1014 | },
1015 |
1016 | i85: function () {
1017 | memory.storeByte(popByte(), regA);
1018 | //STA
1019 | },
1020 |
1021 | i86: function () {
1022 | memory.storeByte(popByte(), regX);
1023 | //STX
1024 | },
1025 |
1026 | i88: function () {
1027 | regY = (regY - 1) & 0xff;
1028 | setNVflagsForRegY();
1029 | //DEY
1030 | },
1031 |
1032 | i8a: function () {
1033 | regA = regX & 0xff;
1034 | setNVflagsForRegA();
1035 | //TXA
1036 | },
1037 |
1038 | i8c: function () {
1039 | memory.storeByte(popWord(), regY);
1040 | //STY
1041 | },
1042 |
1043 | i8d: function () {
1044 | memory.storeByte(popWord(), regA);
1045 | //STA
1046 | },
1047 |
1048 | i8e: function () {
1049 | memory.storeByte(popWord(), regX);
1050 | //STX
1051 | },
1052 |
1053 | i90: function () {
1054 | var offset = popByte();
1055 | if (!carrySet()) { jumpBranch(offset); }
1056 | //BCC
1057 | },
1058 |
1059 | i91: function () {
1060 | var zp = popByte();
1061 | var addr = memory.getWord(zp) + regY;
1062 | memory.storeByte(addr, regA);
1063 | //STA
1064 | },
1065 |
1066 | i94: function () {
1067 | memory.storeByte((popByte() + regX) & 0xff, regY);
1068 | //STY
1069 | },
1070 |
1071 | i95: function () {
1072 | memory.storeByte((popByte() + regX) & 0xff, regA);
1073 | //STA
1074 | },
1075 |
1076 | i96: function () {
1077 | memory.storeByte((popByte() + regY) & 0xff, regX);
1078 | //STX
1079 | },
1080 |
1081 | i98: function () {
1082 | regA = regY & 0xff;
1083 | setNVflagsForRegA();
1084 | //TYA
1085 | },
1086 |
1087 | i99: function () {
1088 | memory.storeByte(popWord() + regY, regA);
1089 | //STA
1090 | },
1091 |
1092 | i9a: function () {
1093 | regSP = regX & 0xff;
1094 | //TXS
1095 | },
1096 |
1097 | i9d: function () {
1098 | var addr = popWord();
1099 | memory.storeByte(addr + regX, regA);
1100 | //STA
1101 | },
1102 |
1103 | ia0: function () {
1104 | regY = popByte();
1105 | LDY();
1106 | },
1107 |
1108 | ia1: function () {
1109 | var zp = (popByte() + regX) & 0xff;
1110 | var addr = memory.getWord(zp);
1111 | regA = memory.get(addr);
1112 | LDA();
1113 | },
1114 |
1115 | ia2: function () {
1116 | regX = popByte();
1117 | LDX();
1118 | },
1119 |
1120 | ia4: function () {
1121 | regY = memory.get(popByte());
1122 | LDY();
1123 | },
1124 |
1125 | ia5: function () {
1126 | regA = memory.get(popByte());
1127 | LDA();
1128 | },
1129 |
1130 | ia6: function () {
1131 | regX = memory.get(popByte());
1132 | LDX();
1133 | },
1134 |
1135 | ia8: function () {
1136 | regY = regA & 0xff;
1137 | setNVflagsForRegY();
1138 | //TAY
1139 | },
1140 |
1141 | ia9: function () {
1142 | regA = popByte();
1143 | LDA();
1144 | },
1145 |
1146 | iaa: function () {
1147 | regX = regA & 0xff;
1148 | setNVflagsForRegX();
1149 | //TAX
1150 | },
1151 |
1152 | iac: function () {
1153 | regY = memory.get(popWord());
1154 | LDY();
1155 | },
1156 |
1157 | iad: function () {
1158 | regA = memory.get(popWord());
1159 | LDA();
1160 | },
1161 |
1162 | iae: function () {
1163 | regX = memory.get(popWord());
1164 | LDX();
1165 | },
1166 |
1167 | ib0: function () {
1168 | var offset = popByte();
1169 | if (carrySet()) { jumpBranch(offset); }
1170 | //BCS
1171 | },
1172 |
1173 | ib1: function () {
1174 | var zp = popByte();
1175 | var addr = memory.getWord(zp) + regY;
1176 | regA = memory.get(addr);
1177 | LDA();
1178 | },
1179 |
1180 | ib4: function () {
1181 | regY = memory.get((popByte() + regX) & 0xff);
1182 | LDY();
1183 | },
1184 |
1185 | ib5: function () {
1186 | regA = memory.get((popByte() + regX) & 0xff);
1187 | LDA();
1188 | },
1189 |
1190 | ib6: function () {
1191 | regX = memory.get((popByte() + regY) & 0xff);
1192 | LDX();
1193 | },
1194 |
1195 | ib8: function () {
1196 | CLV();
1197 | },
1198 |
1199 | ib9: function () {
1200 | var addr = popWord() + regY;
1201 | regA = memory.get(addr);
1202 | LDA();
1203 | },
1204 |
1205 | iba: function () {
1206 | regX = regSP & 0xff;
1207 | LDX();
1208 | //TSX
1209 | },
1210 |
1211 | ibc: function () {
1212 | var addr = popWord() + regX;
1213 | regY = memory.get(addr);
1214 | LDY();
1215 | },
1216 |
1217 | ibd: function () {
1218 | var addr = popWord() + regX;
1219 | regA = memory.get(addr);
1220 | LDA();
1221 | },
1222 |
1223 | ibe: function () {
1224 | var addr = popWord() + regY;
1225 | regX = memory.get(addr);
1226 | LDX();
1227 | },
1228 |
1229 | ic0: function () {
1230 | var value = popByte();
1231 | doCompare(regY, value);
1232 | //CPY
1233 | },
1234 |
1235 | ic1: function () {
1236 | var zp = (popByte() + regX) & 0xff;
1237 | var addr = memory.getWord(zp);
1238 | var value = memory.get(addr);
1239 | doCompare(regA, value);
1240 | //CPA
1241 | },
1242 |
1243 | ic4: function () {
1244 | var value = memory.get(popByte());
1245 | doCompare(regY, value);
1246 | //CPY
1247 | },
1248 |
1249 | ic5: function () {
1250 | var value = memory.get(popByte());
1251 | doCompare(regA, value);
1252 | //CPA
1253 | },
1254 |
1255 | ic6: function () {
1256 | var zp = popByte();
1257 | DEC(zp);
1258 | },
1259 |
1260 | ic8: function () {
1261 | regY = (regY + 1) & 0xff;
1262 | setNVflagsForRegY();
1263 | //INY
1264 | },
1265 |
1266 | ic9: function () {
1267 | var value = popByte();
1268 | doCompare(regA, value);
1269 | //CMP
1270 | },
1271 |
1272 | ica: function () {
1273 | regX = (regX - 1) & 0xff;
1274 | setNVflagsForRegX();
1275 | //DEX
1276 | },
1277 |
1278 | icc: function () {
1279 | var value = memory.get(popWord());
1280 | doCompare(regY, value);
1281 | //CPY
1282 | },
1283 |
1284 | icd: function () {
1285 | var value = memory.get(popWord());
1286 | doCompare(regA, value);
1287 | //CPA
1288 | },
1289 |
1290 | ice: function () {
1291 | var addr = popWord();
1292 | DEC(addr);
1293 | },
1294 |
1295 | id0: function () {
1296 | var offset = popByte();
1297 | if (!zeroSet()) { jumpBranch(offset); }
1298 | //BNE
1299 | },
1300 |
1301 | id1: function () {
1302 | var zp = popByte();
1303 | var addr = memory.getWord(zp) + regY;
1304 | var value = memory.get(addr);
1305 | doCompare(regA, value);
1306 | //CMP
1307 | },
1308 |
1309 | id5: function () {
1310 | var value = memory.get((popByte() + regX) & 0xff);
1311 | doCompare(regA, value);
1312 | //CMP
1313 | },
1314 |
1315 | id6: function () {
1316 | var addr = (popByte() + regX) & 0xff;
1317 | DEC(addr);
1318 | },
1319 |
1320 | id8: function () {
1321 | regP &= 0xf7;
1322 | //CLD
1323 | },
1324 |
1325 | id9: function () {
1326 | var addr = popWord() + regY;
1327 | var value = memory.get(addr);
1328 | doCompare(regA, value);
1329 | //CMP
1330 | },
1331 |
1332 | idd: function () {
1333 | var addr = popWord() + regX;
1334 | var value = memory.get(addr);
1335 | doCompare(regA, value);
1336 | //CMP
1337 | },
1338 |
1339 | ide: function () {
1340 | var addr = popWord() + regX;
1341 | DEC(addr);
1342 | },
1343 |
1344 | ie0: function () {
1345 | var value = popByte();
1346 | doCompare(regX, value);
1347 | //CPX
1348 | },
1349 |
1350 | ie1: function () {
1351 | var zp = (popByte() + regX) & 0xff;
1352 | var addr = memory.getWord(zp);
1353 | var value = memory.get(addr);
1354 | testSBC(value);
1355 | //SBC
1356 | },
1357 |
1358 | ie4: function () {
1359 | var value = memory.get(popByte());
1360 | doCompare(regX, value);
1361 | //CPX
1362 | },
1363 |
1364 | ie5: function () {
1365 | var addr = popByte();
1366 | var value = memory.get(addr);
1367 | testSBC(value);
1368 | //SBC
1369 | },
1370 |
1371 | ie6: function () {
1372 | var zp = popByte();
1373 | INC(zp);
1374 | },
1375 |
1376 | ie8: function () {
1377 | regX = (regX + 1) & 0xff;
1378 | setNVflagsForRegX();
1379 | //INX
1380 | },
1381 |
1382 | ie9: function () {
1383 | var value = popByte();
1384 | testSBC(value);
1385 | //SBC
1386 | },
1387 |
1388 | iea: function () {
1389 | //NOP
1390 | },
1391 |
1392 | iec: function () {
1393 | var value = memory.get(popWord());
1394 | doCompare(regX, value);
1395 | //CPX
1396 | },
1397 |
1398 | ied: function () {
1399 | var addr = popWord();
1400 | var value = memory.get(addr);
1401 | testSBC(value);
1402 | //SBC
1403 | },
1404 |
1405 | iee: function () {
1406 | var addr = popWord();
1407 | INC(addr);
1408 | },
1409 |
1410 | if0: function () {
1411 | var offset = popByte();
1412 | if (zeroSet()) { jumpBranch(offset); }
1413 | //BEQ
1414 | },
1415 |
1416 | if1: function () {
1417 | var zp = popByte();
1418 | var addr = memory.getWord(zp);
1419 | var value = memory.get(addr + regY);
1420 | testSBC(value);
1421 | //SBC
1422 | },
1423 |
1424 | if5: function () {
1425 | var addr = (popByte() + regX) & 0xff;
1426 | var value = memory.get(addr);
1427 | testSBC(value);
1428 | //SBC
1429 | },
1430 |
1431 | if6: function () {
1432 | var addr = (popByte() + regX) & 0xff;
1433 | INC(addr);
1434 | },
1435 |
1436 | if8: function () {
1437 | regP |= 8;
1438 | //SED
1439 | },
1440 |
1441 | if9: function () {
1442 | var addr = popWord();
1443 | var value = memory.get(addr + regY);
1444 | testSBC(value);
1445 | //SBC
1446 | },
1447 |
1448 | ifd: function () {
1449 | var addr = popWord();
1450 | var value = memory.get(addr + regX);
1451 | testSBC(value);
1452 | //SBC
1453 | },
1454 |
1455 | ife: function () {
1456 | var addr = popWord() + regX;
1457 | INC(addr);
1458 | },
1459 |
1460 | ierr: function () {
1461 | message("Address $" + addr2hex(regPC) + " - unknown opcode");
1462 | codeRunning = false;
1463 | }
1464 | };
1465 |
1466 | function stackPush(value) {
1467 | memory.set((regSP & 0xff) + 0x100, value & 0xff);
1468 | regSP--;
1469 | if (regSP < 0) {
1470 | regSP &= 0xff;
1471 | message("6502 Stack filled! Wrapping...");
1472 | }
1473 | }
1474 |
1475 | function stackPop() {
1476 | var value;
1477 | regSP++;
1478 | if (regSP >= 0x100) {
1479 | regSP &= 0xff;
1480 | message("6502 Stack emptied! Wrapping...");
1481 | }
1482 | value = memory.get(regSP + 0x100);
1483 | return value;
1484 | }
1485 |
1486 | // popByte() - Pops a byte
1487 | function popByte() {
1488 | return(memory.get(regPC++) & 0xff);
1489 | }
1490 |
1491 | // popWord() - Pops a word using popByte() twice
1492 | function popWord() {
1493 | return popByte() + (popByte() << 8);
1494 | }
1495 |
1496 | // runBinary() - Executes the assembled code
1497 | function runBinary() {
1498 | if (codeRunning) {
1499 | // Switch OFF everything
1500 | stop();
1501 | ui.stop();
1502 | } else {
1503 | ui.play();
1504 | codeRunning = true;
1505 | executeId = setInterval(multiExecute, 15);
1506 | }
1507 | }
1508 |
1509 | function multiExecute() {
1510 | if (!debug) {
1511 | // use a prime number of iterations to avoid aliasing effects
1512 |
1513 | for (var w = 0; w < 97; w++) {
1514 | execute();
1515 | }
1516 | }
1517 | updateDebugInfo();
1518 | }
1519 |
1520 |
1521 | function executeNextInstruction() {
1522 | var instructionName = popByte().toString(16).toLowerCase();
1523 | if (instructionName.length === 1) {
1524 | instructionName = '0' + instructionName;
1525 | }
1526 | var instruction = instructions['i' + instructionName];
1527 |
1528 | if (instruction) {
1529 | instruction();
1530 | } else {
1531 | instructions.ierr();
1532 | }
1533 | }
1534 |
1535 | // execute() - Executes one instruction.
1536 | // This is the main part of the CPU simulator.
1537 | function execute(debugging) {
1538 | if (!codeRunning && !debugging) { return; }
1539 |
1540 | setRandomByte();
1541 | executeNextInstruction();
1542 |
1543 | if ((regPC === 0) || (!codeRunning && !debugging)) {
1544 | stop();
1545 | message("Program end at PC=$" + addr2hex(regPC - 1));
1546 | ui.stop();
1547 | }
1548 | }
1549 |
1550 | function setRandomByte() {
1551 | memory.set(0xfe, Math.floor(Math.random() * 256));
1552 | }
1553 |
1554 | function updateMonitor() {
1555 | if (monitoring) {
1556 | var start = parseInt($node.find('.start').val(), 16);
1557 | var length = parseInt($node.find('.length').val(), 16);
1558 | if (start >= 0 && length > 0) {
1559 | $node.find('.monitor code').html(memory.format(start, length));
1560 | }
1561 | }
1562 | }
1563 |
1564 | // debugExec() - Execute one instruction and print values
1565 | function debugExec() {
1566 | //if (codeRunning) {
1567 | execute(true);
1568 | //}
1569 | updateDebugInfo();
1570 | }
1571 |
1572 | function updateDebugInfo() {
1573 | var html = "A=$" + num2hex(regA) + " X=$" + num2hex(regX) + " Y=$" + num2hex(regY) + " ";
1574 | html += "SP=$" + num2hex(regSP) + " PC=$" + addr2hex(regPC);
1575 | html += " ";
1576 | html += "NV-BDIZC ";
1577 | for (var i = 7; i >=0; i--) {
1578 | html += regP >> i & 1;
1579 | }
1580 | $node.find('.minidebugger').html(html);
1581 | updateMonitor();
1582 | }
1583 |
1584 | // gotoAddr() - Set PC to address (or address of label)
1585 | function gotoAddr() {
1586 | var inp = prompt("Enter address or label", "");
1587 | var addr = 0;
1588 | if (labels.find(inp)) {
1589 | addr = labels.getPC(inp);
1590 | } else {
1591 | if (inp.match(/^0x[0-9a-f]{1,4}$/i)) {
1592 | inp = inp.replace(/^0x/, "");
1593 | addr = parseInt(inp, 16);
1594 | } else if (inp.match(/^\$[0-9a-f]{1,4}$/i)) {
1595 | inp = inp.replace(/^\$/, "");
1596 | addr = parseInt(inp, 16);
1597 | }
1598 | }
1599 | if (addr === 0) {
1600 | message("Unable to find/parse given address/label");
1601 | } else {
1602 | regPC = addr;
1603 | }
1604 | updateDebugInfo();
1605 | }
1606 |
1607 |
1608 | function stopDebugger() {
1609 | debug = false;
1610 | }
1611 |
1612 | function enableDebugger() {
1613 | debug = true;
1614 | if (codeRunning) {
1615 | updateDebugInfo();
1616 | }
1617 | }
1618 |
1619 | // reset() - Reset CPU and memory.
1620 | function reset() {
1621 | display.reset();
1622 | for (var i = 0; i < 0x600; i++) { // clear ZP, stack and screen
1623 | memory.set(i, 0x00);
1624 | }
1625 | regA = regX = regY = 0;
1626 | regPC = 0x600;
1627 | regSP = 0xff;
1628 | regP = 0x30;
1629 | updateDebugInfo();
1630 | }
1631 |
1632 | function stop() {
1633 | codeRunning = false;
1634 | clearInterval(executeId);
1635 | }
1636 |
1637 | function toggleMonitor() {
1638 | monitoring = !monitoring;
1639 | }
1640 |
1641 | return {
1642 | runBinary: runBinary,
1643 | enableDebugger: enableDebugger,
1644 | stopDebugger: stopDebugger,
1645 | debugExec: debugExec,
1646 | gotoAddr: gotoAddr,
1647 | reset: reset,
1648 | stop: stop,
1649 | toggleMonitor: toggleMonitor
1650 | };
1651 | }
1652 |
1653 |
1654 | function Labels() {
1655 | var labelIndex = [];
1656 |
1657 | function indexLines(lines) {
1658 | for (var i = 0; i < lines.length; i++) {
1659 | if (!indexLine(lines[i])) {
1660 | message("**Label already defined at line " + (i + 1) + ":** " + lines[i]);
1661 | return false;
1662 | }
1663 | }
1664 | return true;
1665 | }
1666 |
1667 | // indexLine(line) - extract label if line contains one and calculate position in memory.
1668 | // Return false if label alread exists.
1669 | function indexLine(input) {
1670 | // remove comments
1671 | input = input.replace(/^(.*?);.*/, "$1");
1672 |
1673 | // trim line
1674 | input = input.replace(/^\s+/, "");
1675 | input = input.replace(/\s+$/, "");
1676 |
1677 | // Figure out how many bytes this instruction takes
1678 | var currentPC = assembler.getCurrentPC();
1679 | assembler.assembleLine(input); //TODO: find a better way for Labels to have access to assembler
1680 |
1681 | // Find command or label
1682 | if (input.match(/^\w+:/)) {
1683 | var label = input.replace(/(^\w+):.*$/, "$1");
1684 | return push(label + "|" + currentPC);
1685 | }
1686 | return true;
1687 | }
1688 |
1689 | // push() - Push label to array. Return false if label already exists.
1690 | function push(name) {
1691 | if (find(name)) {
1692 | return false;
1693 | }
1694 | labelIndex.push(name + "|");
1695 | return true;
1696 | }
1697 |
1698 | // find() - Returns true if label exists.
1699 | function find(name) {
1700 | var nameAndAddr;
1701 | for (var i = 0; i < labelIndex.length; i++) {
1702 | nameAndAddr = labelIndex[i].split("|");
1703 | if (name === nameAndAddr[0]) {
1704 | return true;
1705 | }
1706 | }
1707 | return false;
1708 | }
1709 |
1710 | // setPC() - Associates label with address
1711 | function setPC(name, addr) {
1712 | var nameAndAddr;
1713 | for (var i = 0; i < labelIndex.length; i++) {
1714 | nameAndAddr = labelIndex[i].split("|");
1715 | if (name === nameAndAddr[0]) {
1716 | labelIndex[i] = name + "|" + addr;
1717 | return true;
1718 | }
1719 | }
1720 | return false;
1721 | }
1722 |
1723 | // getPC() - Get address associated with label
1724 | function getPC(name) {
1725 | var nameAndAddr;
1726 | for (var i = 0; i < labelIndex.length; i++) {
1727 | nameAndAddr = labelIndex[i].split("|");
1728 | if (name === nameAndAddr[0]) {
1729 | return (nameAndAddr[1]);
1730 | }
1731 | }
1732 | return -1;
1733 | }
1734 |
1735 | function displayMessage() {
1736 | var str = "Found " + labelIndex.length + " label";
1737 | if (labelIndex.length !== 1) {
1738 | str += "s";
1739 | }
1740 | message(str + ".");
1741 | }
1742 |
1743 | function reset() {
1744 | labelIndex = [];
1745 | }
1746 |
1747 | return {
1748 | indexLines: indexLines,
1749 | find: find,
1750 | getPC: getPC,
1751 | displayMessage: displayMessage,
1752 | reset: reset
1753 | };
1754 | }
1755 |
1756 |
1757 | function Assembler() {
1758 | var defaultCodePC;
1759 | var codeLen;
1760 | var codeAssembledOK = false;
1761 |
1762 | var Opcodes = [
1763 | /* Name, Imm, ZP, ZPX, ZPY, ABS, ABSX, ABSY, IND, INDX, INDY, SNGL, BRA */
1764 | ["ADC", 0x69, 0x65, 0x75, null, 0x6d, 0x7d, 0x79, null, 0x61, 0x71, null, null],
1765 | ["AND", 0x29, 0x25, 0x35, null, 0x2d, 0x3d, 0x39, null, 0x21, 0x31, null, null],
1766 | ["ASL", null, 0x06, 0x16, null, 0x0e, 0x1e, null, null, null, null, 0x0a, null],
1767 | ["BIT", null, 0x24, null, null, 0x2c, null, null, null, null, null, null, null],
1768 | ["BPL", null, null, null, null, null, null, null, null, null, null, null, 0x10],
1769 | ["BMI", null, null, null, null, null, null, null, null, null, null, null, 0x30],
1770 | ["BVC", null, null, null, null, null, null, null, null, null, null, null, 0x50],
1771 | ["BVS", null, null, null, null, null, null, null, null, null, null, null, 0x70],
1772 | ["BCC", null, null, null, null, null, null, null, null, null, null, null, 0x90],
1773 | ["BCS", null, null, null, null, null, null, null, null, null, null, null, 0xb0],
1774 | ["BNE", null, null, null, null, null, null, null, null, null, null, null, 0xd0],
1775 | ["BEQ", null, null, null, null, null, null, null, null, null, null, null, 0xf0],
1776 | ["BRK", null, null, null, null, null, null, null, null, null, null, 0x00, null],
1777 | ["CMP", 0xc9, 0xc5, 0xd5, null, 0xcd, 0xdd, 0xd9, null, 0xc1, 0xd1, null, null],
1778 | ["CPX", 0xe0, 0xe4, null, null, 0xec, null, null, null, null, null, null, null],
1779 | ["CPY", 0xc0, 0xc4, null, null, 0xcc, null, null, null, null, null, null, null],
1780 | ["DEC", null, 0xc6, 0xd6, null, 0xce, 0xde, null, null, null, null, null, null],
1781 | ["EOR", 0x49, 0x45, 0x55, null, 0x4d, 0x5d, 0x59, null, 0x41, 0x51, null, null],
1782 | ["CLC", null, null, null, null, null, null, null, null, null, null, 0x18, null],
1783 | ["SEC", null, null, null, null, null, null, null, null, null, null, 0x38, null],
1784 | ["CLI", null, null, null, null, null, null, null, null, null, null, 0x58, null],
1785 | ["SEI", null, null, null, null, null, null, null, null, null, null, 0x78, null],
1786 | ["CLV", null, null, null, null, null, null, null, null, null, null, 0xb8, null],
1787 | ["CLD", null, null, null, null, null, null, null, null, null, null, 0xd8, null],
1788 | ["SED", null, null, null, null, null, null, null, null, null, null, 0xf8, null],
1789 | ["INC", null, 0xe6, 0xf6, null, 0xee, 0xfe, null, null, null, null, null, null],
1790 | ["JMP", null, null, null, null, 0x4c, null, null, 0x6c, null, null, null, null],
1791 | ["JSR", null, null, null, null, 0x20, null, null, null, null, null, null, null],
1792 | ["LDA", 0xa9, 0xa5, 0xb5, null, 0xad, 0xbd, 0xb9, null, 0xa1, 0xb1, null, null],
1793 | ["LDX", 0xa2, 0xa6, null, 0xb6, 0xae, null, 0xbe, null, null, null, null, null],
1794 | ["LDY", 0xa0, 0xa4, 0xb4, null, 0xac, 0xbc, null, null, null, null, null, null],
1795 | ["LSR", null, 0x46, 0x56, null, 0x4e, 0x5e, null, null, null, null, 0x4a, null],
1796 | ["NOP", null, null, null, null, null, null, null, null, null, null, 0xea, null],
1797 | ["ORA", 0x09, 0x05, 0x15, null, 0x0d, 0x1d, 0x19, null, 0x01, 0x11, null, null],
1798 | ["TAX", null, null, null, null, null, null, null, null, null, null, 0xaa, null],
1799 | ["TXA", null, null, null, null, null, null, null, null, null, null, 0x8a, null],
1800 | ["DEX", null, null, null, null, null, null, null, null, null, null, 0xca, null],
1801 | ["INX", null, null, null, null, null, null, null, null, null, null, 0xe8, null],
1802 | ["TAY", null, null, null, null, null, null, null, null, null, null, 0xa8, null],
1803 | ["TYA", null, null, null, null, null, null, null, null, null, null, 0x98, null],
1804 | ["DEY", null, null, null, null, null, null, null, null, null, null, 0x88, null],
1805 | ["INY", null, null, null, null, null, null, null, null, null, null, 0xc8, null],
1806 | ["ROR", null, 0x66, 0x76, null, 0x6e, 0x7e, null, null, null, null, 0x6a, null],
1807 | ["ROL", null, 0x26, 0x36, null, 0x2e, 0x3e, null, null, null, null, 0x2a, null],
1808 | ["RTI", null, null, null, null, null, null, null, null, null, null, 0x40, null],
1809 | ["RTS", null, null, null, null, null, null, null, null, null, null, 0x60, null],
1810 | ["SBC", 0xe9, 0xe5, 0xf5, null, 0xed, 0xfd, 0xf9, null, 0xe1, 0xf1, null, null],
1811 | ["STA", null, 0x85, 0x95, null, 0x8d, 0x9d, 0x99, null, 0x81, 0x91, null, null],
1812 | ["TXS", null, null, null, null, null, null, null, null, null, null, 0x9a, null],
1813 | ["TSX", null, null, null, null, null, null, null, null, null, null, 0xba, null],
1814 | ["PHA", null, null, null, null, null, null, null, null, null, null, 0x48, null],
1815 | ["PLA", null, null, null, null, null, null, null, null, null, null, 0x68, null],
1816 | ["PHP", null, null, null, null, null, null, null, null, null, null, 0x08, null],
1817 | ["PLP", null, null, null, null, null, null, null, null, null, null, 0x28, null],
1818 | ["STX", null, 0x86, null, 0x96, 0x8e, null, null, null, null, null, null, null],
1819 | ["STY", null, 0x84, 0x94, null, 0x8c, null, null, null, null, null, null, null],
1820 | ["---", null, null, null, null, null, null, null, null, null, null, null, null]
1821 | ];
1822 |
1823 | // assembleCode()
1824 | // "assembles" the code into memory
1825 | function assembleCode() {
1826 | simulator.reset();
1827 | labels.reset();
1828 | defaultCodePC = 0x600;
1829 | $node.find('.messages code').empty();
1830 |
1831 | var code = $node.find('.code').val();
1832 | code += "\n\n";
1833 | var lines = code.split("\n");
1834 | codeAssembledOK = true;
1835 |
1836 | message("Indexing labels..");
1837 |
1838 | defaultCodePC = 0x600;
1839 |
1840 | if (!labels.indexLines(lines)) {
1841 | return false;
1842 | }
1843 |
1844 | labels.displayMessage();
1845 |
1846 | defaultCodePC = 0x600;
1847 | message("Assembling code ...");
1848 |
1849 | codeLen = 0;
1850 | for (var i = 0; i < lines.length; i++) {
1851 | if (!assembleLine(lines[i], i)) {
1852 | codeAssembledOK = false;
1853 | break;
1854 | }
1855 | }
1856 |
1857 | if (codeLen === 0) {
1858 | codeAssembledOK = false;
1859 | message("No code to run.");
1860 | }
1861 |
1862 | if (codeAssembledOK) {
1863 | ui.assembleSuccess();
1864 | memory.set(defaultCodePC, 0x00); //set a null byte at the end of the code
1865 | } else {
1866 | var str = lines[i].replace("<", "<").replace(">", ">");
1867 | message("**Syntax error line " + (i + 1) + ": " + str + "**");
1868 | ui.initialize();
1869 | return;
1870 | }
1871 |
1872 | message("Code assembled successfully, " + codeLen + " bytes.");
1873 | }
1874 |
1875 | // assembleLine()
1876 | //
1877 | // assembles one line of code. Returns true if it assembled successfully,
1878 | // false otherwise.
1879 | function assembleLine(input, lineno) {
1880 | var label, command, param, addr;
1881 |
1882 | // remove comments
1883 |
1884 | input = input.replace(/^(.*?);.*/, "$1");
1885 |
1886 | // trim line
1887 |
1888 | input = input.replace(/^\s+/, "");
1889 | input = input.replace(/\s+$/, "");
1890 |
1891 | // Find command or label
1892 |
1893 | if (input.match(/^\w+:/)) {
1894 | label = input.replace(/(^\w+):.*$/, "$1");
1895 | if (input.match(/^\w+:[\s]*\w+.*$/)) {
1896 | input = input.replace(/^\w+:[\s]*(.*)$/, "$1");
1897 | command = input.replace(/^(\w+).*$/, "$1");
1898 | } else {
1899 | command = "";
1900 | }
1901 | } else {
1902 | command = input.replace(/^(\w+).*$/, "$1");
1903 | }
1904 |
1905 | // Blank line? Return.
1906 |
1907 | if (command === "") {
1908 | return true;
1909 | }
1910 |
1911 | command = command.toUpperCase();
1912 |
1913 | if (input.match(/^\*\s*=\s*\$?[0-9a-f]*$/)) {
1914 | // equ spotted
1915 | param = input.replace(/^\s*\*\s*=\s*/, "");
1916 | if (param[0] === "$") {
1917 | param = param.replace(/^\$/, "");
1918 | addr = parseInt(param, 16);
1919 | } else {
1920 | addr = parseInt(param, 10);
1921 | }
1922 | if ((addr < 0) || (addr > 0xffff)) {
1923 | message("Unable to relocate code outside 64k memory");
1924 | return false;
1925 | }
1926 | defaultCodePC = addr;
1927 | return true;
1928 | }
1929 |
1930 | if (input.match(/^\w+\s+.*?$/)) {
1931 | param = input.replace(/^\w+\s+(.*?)/, "$1");
1932 | } else {
1933 | if (input.match(/^\w+$/)) {
1934 | param = "";
1935 | } else {
1936 | return false;
1937 | }
1938 | }
1939 |
1940 | param = param.replace(/[ ]/g, "");
1941 |
1942 | if (command === "DCB") {
1943 | return DCB(param);
1944 | }
1945 |
1946 |
1947 | for (var o = 0; o < Opcodes.length; o++) {
1948 | if (Opcodes[o][0] === command) {
1949 | if (checkSingle(param, Opcodes[o][11])) { return true; }
1950 | if (checkImmediate(param, Opcodes[o][1])) { return true; }
1951 | if (checkZeroPage(param, Opcodes[o][2])) { return true; }
1952 | if (checkZeroPageX(param, Opcodes[o][3])) { return true; }
1953 | if (checkZeroPageY(param, Opcodes[o][4])) { return true; }
1954 | if (checkAbsoluteX(param, Opcodes[o][6])) { return true; }
1955 | if (checkAbsoluteY(param, Opcodes[o][7])) { return true; }
1956 | if (checkIndirect(param, Opcodes[o][8])) { return true; }
1957 | if (checkIndirectX(param, Opcodes[o][9])) { return true; }
1958 | if (checkIndirectY(param, Opcodes[o][10])) { return true; }
1959 | if (checkAbsolute(param, Opcodes[o][5])) { return true; }
1960 | if (checkBranch(param, Opcodes[o][12])) { return true; }
1961 | }
1962 | }
1963 | return false; // Unknown opcode
1964 | }
1965 |
1966 | function DCB(param) {
1967 | var values, number, str, ch;
1968 | values = param.split(",");
1969 | if (values.length === 0) { return false; }
1970 | for (var v = 0; v < values.length; v++) {
1971 | str = values[v];
1972 | if (str) {
1973 | ch = str.substring(0, 1);
1974 | if (ch === "$") {
1975 | number = parseInt(str.replace(/^\$/, ""), 16);
1976 | pushByte(number);
1977 | } else if (ch >= "0" && ch <= "9") {
1978 | number = parseInt(str, 10);
1979 | pushByte(number);
1980 | } else {
1981 | return false;
1982 | }
1983 | }
1984 | }
1985 | return true;
1986 | }
1987 |
1988 | // checkBranch() - Commom branch function for all branches (BCC, BCS, BEQ, BNE..)
1989 | function checkBranch(param, opcode) {
1990 | var addr;
1991 | if (opcode === null) { return false; }
1992 |
1993 | addr = -1;
1994 | if (param.match(/\w+/)) {
1995 | addr = labels.getPC(param);
1996 | }
1997 | if (addr === -1) { pushWord(0x00); return false; }
1998 | pushByte(opcode);
1999 | if (addr < (defaultCodePC - 0x600)) { // Backwards?
2000 | pushByte((0xff - ((defaultCodePC - 0x600) - addr)) & 0xff);
2001 | return true;
2002 | }
2003 | pushByte((addr - (defaultCodePC - 0x600) - 1) & 0xff);
2004 | return true;
2005 | }
2006 |
2007 | // checkImmediate() - Check if param is immediate and push value
2008 | function checkImmediate(param, opcode) {
2009 | var value, label, hilo, addr;
2010 | if (opcode === null) { return false; }
2011 | if (param.match(/^#\$[0-9a-f]{1,2}$/i)) {
2012 | pushByte(opcode);
2013 | value = parseInt(param.replace(/^#\$/, ""), 16);
2014 | if (value < 0 || value > 255) { return false; }
2015 | pushByte(value);
2016 | return true;
2017 | }
2018 | if (param.match(/^#\%[0-1]{1,8}$/i)) {
2019 | pushByte(opcode);
2020 | value = parseInt(param.replace(/^#\%/, ""), 2);
2021 | if (value < 0 || value > 255) { return false; }
2022 | pushByte(value);
2023 | return true;
2024 | }
2025 | if (param.match(/^#[0-9]{1,3}$/i)) {
2026 | pushByte(opcode);
2027 | value = parseInt(param.replace(/^#/, ""), 10);
2028 | if (value < 0 || value > 255) { return false; }
2029 | pushByte(value);
2030 | return true;
2031 | }
2032 | // Label lo/hi
2033 | if (param.match(/^#[<>]\w+$/)) {
2034 | label = param.replace(/^#[<>](\w+)$/, "$1");
2035 | hilo = param.replace(/^#([<>]).*$/, "$1");
2036 | pushByte(opcode);
2037 | if (labels.find(label)) {
2038 | addr = labels.getPC(label);
2039 | switch(hilo) {
2040 | case ">":
2041 | pushByte((addr >> 8) & 0xff);
2042 | return true;
2043 | case "<":
2044 | pushByte(addr & 0xff);
2045 | return true;
2046 | default:
2047 | return false;
2048 | }
2049 | } else {
2050 | pushByte(0x00);
2051 | return true;
2052 | }
2053 | }
2054 | return false;
2055 | }
2056 |
2057 | // checkIndirect() - Check if param is indirect and push value
2058 | function checkIndirect(param, opcode) {
2059 | var value;
2060 | if (opcode === null) { return false; }
2061 | if (param.match(/^\(\$[0-9a-f]{4}\)$/i)) {
2062 | pushByte(opcode);
2063 | value = param.replace(/^\(\$([0-9a-f]{4}).*$/i, "$1");
2064 | if (value < 0 || value > 0xffff) { return false; }
2065 | pushWord(parseInt(value, 16));
2066 | return true;
2067 | }
2068 | return false;
2069 | }
2070 |
2071 | // checkIndirectX() - Check if param is indirect X and push value
2072 | function checkIndirectX(param, opcode) {
2073 | var value;
2074 | if (opcode === null) { return false; }
2075 | if (param.match(/^\(\$[0-9a-f]{1,2},X\)$/i)) {
2076 | pushByte(opcode);
2077 | value = param.replace(/^\(\$([0-9a-f]{1,2}).*$/i, "$1");
2078 | if (value < 0 || value > 255) { return false; }
2079 | pushByte(parseInt(value, 16));
2080 | return true;
2081 | }
2082 | return false;
2083 | }
2084 |
2085 | // checkIndirectY() - Check if param is indirect Y and push value
2086 | function checkIndirectY(param, opcode) {
2087 | var value;
2088 | if (opcode === null) { return false; }
2089 | if (param.match(/^\(\$[0-9a-f]{1,2}\),Y$/i)) {
2090 | pushByte(opcode);
2091 | value = param.replace(/^\([\$]([0-9a-f]{1,2}).*$/i, "$1");
2092 | if (value < 0 || value > 255) { return false; }
2093 | pushByte(parseInt(value, 16));
2094 | return true;
2095 | }
2096 | return false;
2097 | }
2098 |
2099 | // checkSingle() - Single-byte opcodes
2100 | function checkSingle(param, opcode) {
2101 | if (opcode === null) { return false; }
2102 | // Accumulator instructions are counted as single-byte opcodes
2103 | if (param !== "" && param !== "A") { return false; }
2104 | pushByte(opcode);
2105 | return true;
2106 | }
2107 |
2108 | // checkZeroPage() - Check if param is ZP and push value
2109 | function checkZeroPage(param, opcode) {
2110 | var value;
2111 | if (opcode === null) { return false; }
2112 | if (param.match(/^\$[0-9a-f]{1,2}$/i)) {
2113 | pushByte(opcode);
2114 | value = parseInt(param.replace(/^\$/, ""), 16);
2115 | if (value < 0 || value > 255) { return false; }
2116 | pushByte(value);
2117 | return true;
2118 | }
2119 | if (param.match(/^[0-9]{1,3}$/i)) {
2120 | value = parseInt(param, 10);
2121 | if (value < 0 || value > 255) { return false; }
2122 | pushByte(opcode);
2123 | pushByte(value);
2124 | return true;
2125 | }
2126 | return false;
2127 | }
2128 |
2129 | // checkAbsoluteX() - Check if param is ABSX and push value
2130 | function checkAbsoluteX(param, opcode) {
2131 | var number, value, addr;
2132 | if (opcode === null) { return false; }
2133 | if (param.match(/^\$[0-9a-f]{3,4},X$/i)) {
2134 | pushByte(opcode);
2135 | number = param.replace(/^\$([0-9a-f]*),X/i, "$1");
2136 | value = parseInt(number, 16);
2137 | if (value < 0 || value > 0xffff) { return false; }
2138 | pushWord(value);
2139 | return true;
2140 | }
2141 |
2142 | if (param.match(/^\w+,X$/i)) {
2143 | param = param.replace(/,X$/i, "");
2144 | pushByte(opcode);
2145 | if (labels.find(param)) {
2146 | addr = labels.getPC(param);
2147 | if (addr < 0 || addr > 0xffff) { return false; }
2148 | pushWord(addr);
2149 | return true;
2150 | } else {
2151 | pushWord(0x1234);
2152 | return true;
2153 | }
2154 | }
2155 |
2156 | return false;
2157 | }
2158 |
2159 | // checkAbsoluteY() - Check if param is ABSY and push value
2160 | function checkAbsoluteY(param, opcode) {
2161 | var number, value, addr;
2162 | if (opcode === null) { return false; }
2163 | if (param.match(/^\$[0-9a-f]{3,4},Y$/i)) {
2164 | pushByte(opcode);
2165 | number = param.replace(/^\$([0-9a-f]*),Y/i, "$1");
2166 | value = parseInt(number, 16);
2167 | if (value < 0 || value > 0xffff) { return false; }
2168 | pushWord(value);
2169 | return true;
2170 | }
2171 |
2172 | // it could be a label too..
2173 |
2174 | if (param.match(/^\w+,Y$/i)) {
2175 | param = param.replace(/,Y$/i, "");
2176 | pushByte(opcode);
2177 | if (labels.find(param)) {
2178 | addr = labels.getPC(param);
2179 | if (addr < 0 || addr > 0xffff) { return false; }
2180 | pushWord(addr);
2181 | return true;
2182 | } else {
2183 | pushWord(0x1234);
2184 | return true;
2185 | }
2186 | }
2187 | return false;
2188 | }
2189 |
2190 | // checkZeroPageX() - Check if param is ZPX and push value
2191 | function checkZeroPageX(param, opcode) {
2192 | var number, value;
2193 | if (opcode === null) { return false; }
2194 | if (param.match(/^\$[0-9a-f]{1,2},X/i)) {
2195 | pushByte(opcode);
2196 | number = param.replace(/^\$([0-9a-f]{1,2}),X/i, "$1");
2197 | value = parseInt(number, 16);
2198 | if (value < 0 || value > 255) { return false; }
2199 | pushByte(value);
2200 | return true;
2201 | }
2202 | if (param.match(/^[0-9]{1,3},X/i)) {
2203 | pushByte(opcode);
2204 | number = param.replace(/^([0-9]{1,3}),X/i, "$1");
2205 | value = parseInt(number, 10);
2206 | if (value < 0 || value > 255) { return false; }
2207 | pushByte(value);
2208 | return true;
2209 | }
2210 | return false;
2211 | }
2212 |
2213 | function checkZeroPageY(param, opcode) {
2214 | var number, value;
2215 | if (opcode === null) { return false; }
2216 | if (param.match(/^\$[0-9a-f]{1,2},Y/i)) {
2217 | pushByte(opcode);
2218 | number = param.replace(/^\$([0-9a-f]{1,2}),Y/i, "$1");
2219 | value = parseInt(number, 16);
2220 | if (value < 0 || value > 255) { return false; }
2221 | pushByte(value);
2222 | return true;
2223 | }
2224 | if (param.match(/^[0-9]{1,3},Y/i)) {
2225 | pushByte(opcode);
2226 | number = param.replace(/^([0-9]{1,3}),Y/i, "$1");
2227 | value = parseInt(number, 10);
2228 | if (value < 0 || value > 255) { return false; }
2229 | pushByte(value);
2230 | return true;
2231 | }
2232 | return false;
2233 | }
2234 |
2235 | // checkAbsolute() - Check if param is ABS and push value
2236 | function checkAbsolute(param, opcode) {
2237 | var value, number, addr;
2238 | if (opcode === null) { return false; }
2239 | pushByte(opcode);
2240 | if (param.match(/^\$[0-9a-f]{3,4}$/i)) {
2241 | value = parseInt(param.replace(/^\$/, ""), 16);
2242 | if (value < 0 || value > 0xffff) { return false; }
2243 | pushWord(value);
2244 | return true;
2245 | }
2246 | if (param.match(/^[0-9]{1,5}$/i)) { // Thanks, Matt!
2247 | value = parseInt(param, 10);
2248 | if (value < 0 || value > 0xffff) { return false; }
2249 | pushWord(value);
2250 | return(true);
2251 | }
2252 | // it could be a label too..
2253 | if (param.match(/^\w+$/)) {
2254 | if (labels.find(param)) {
2255 | addr = (labels.getPC(param));
2256 | if (addr < 0 || addr > 0xffff) { return false; }
2257 | pushWord(addr);
2258 | return true;
2259 | } else {
2260 | pushWord(0x1234);
2261 | return true;
2262 | }
2263 | }
2264 | return false;
2265 | }
2266 |
2267 | // pushByte() - Push byte to memory
2268 | function pushByte(value) {
2269 | memory.set(defaultCodePC, value & 0xff);
2270 | defaultCodePC++;
2271 | codeLen++;
2272 | }
2273 |
2274 | // pushWord() - Push a word using pushByte twice
2275 | function pushWord(value) {
2276 | pushByte(value & 0xff);
2277 | pushByte((value >> 8) & 0xff);
2278 | }
2279 |
2280 | function openPopup(content, title) {
2281 | var w = window.open('', title, 'width=500,height=300,resizable=yes,scrollbars=yes,toolbar=no,location=no,menubar=no,status=no');
2282 |
2283 | var html = "";
2284 | html += "";
2285 | html += "" + title + "";
2286 | html += "
";
2287 |
2288 | html += content;
2289 |
2290 | html += "